aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraxc <axc@yandex-team.ru>2022-02-10 16:47:35 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:35 +0300
commit1f5217043ad70f25dc35e75b3bd261a1e23d045e (patch)
tree11bf68c1fa5272d3d3446cbd5a0ff96ed9d75788
parent69505a07cbb096113e85aa02e7d136cac4aa826c (diff)
downloadydb-1f5217043ad70f25dc35e75b3bd261a1e23d045e.tar.gz
Restoring authorship annotation for <axc@yandex-team.ru>. Commit 1 of 2.
-rwxr-xr-xbuild/ymake_conf.py6
-rw-r--r--contrib/libs/libidn/idna.c106
-rw-r--r--contrib/libs/pire/pire/platform.h176
-rw-r--r--contrib/libs/pire/pire/re_lexer.cpp426
-rw-r--r--contrib/libs/pire/pire/re_parser.y212
-rw-r--r--contrib/tools/bison/bison/data/README140
-rw-r--r--contrib/tools/bison/bison/data/bison.m42126
-rw-r--r--contrib/tools/bison/bison/data/c++-skel.m452
-rw-r--r--contrib/tools/bison/bison/data/c++.m41088
-rw-r--r--contrib/tools/bison/bison/data/c-like.m4130
-rw-r--r--contrib/tools/bison/bison/data/c-skel.m452
-rw-r--r--contrib/tools/bison/bison/data/c.m41678
-rw-r--r--contrib/tools/bison/bison/data/glr.c5126
-rw-r--r--contrib/tools/bison/bison/data/glr.cc690
-rw-r--r--contrib/tools/bison/bison/data/java-skel.m452
-rw-r--r--contrib/tools/bison/bison/data/java.m4684
-rw-r--r--contrib/tools/bison/bison/data/lalr1.cc2322
-rw-r--r--contrib/tools/bison/bison/data/lalr1.java2130
-rw-r--r--contrib/tools/bison/bison/data/local.mk90
-rw-r--r--contrib/tools/bison/bison/data/location.cc670
-rw-r--r--contrib/tools/bison/bison/data/m4sugar/foreach.m4724
-rw-r--r--contrib/tools/bison/bison/data/m4sugar/m4sugar.m46614
-rw-r--r--contrib/tools/bison/bison/data/stack.hh308
-rw-r--r--contrib/tools/bison/bison/data/variant.hh724
-rw-r--r--contrib/tools/bison/bison/data/xslt/bison.xsl210
-rw-r--r--contrib/tools/bison/bison/data/xslt/xml2dot.xsl794
-rw-r--r--contrib/tools/bison/bison/data/xslt/xml2text.xsl1138
-rw-r--r--contrib/tools/bison/bison/data/xslt/xml2xhtml.xsl1490
-rw-r--r--contrib/tools/bison/bison/data/yacc.c3830
-rw-r--r--contrib/tools/bison/bison/src/AnnotationList.c1616
-rw-r--r--contrib/tools/bison/bison/src/AnnotationList.h364
-rw-r--r--contrib/tools/bison/bison/src/InadequacyList.c158
-rw-r--r--contrib/tools/bison/bison/src/InadequacyList.h312
-rw-r--r--contrib/tools/bison/bison/src/LR0.c750
-rw-r--r--contrib/tools/bison/bison/src/LR0.h56
-rw-r--r--contrib/tools/bison/bison/src/Sbitset.c160
-rw-r--r--contrib/tools/bison/bison/src/Sbitset.h184
-rw-r--r--contrib/tools/bison/bison/src/assoc.c100
-rw-r--r--contrib/tools/bison/bison/src/assoc.h70
-rw-r--r--contrib/tools/bison/bison/src/closure.c492
-rw-r--r--contrib/tools/bison/bison/src/closure.h114
-rw-r--r--contrib/tools/bison/bison/src/complain.c758
-rw-r--r--contrib/tools/bison/bison/src/complain.h288
-rw-r--r--contrib/tools/bison/bison/src/conflicts.c1258
-rw-r--r--contrib/tools/bison/bison/src/conflicts.h94
-rw-r--r--contrib/tools/bison/bison/src/derives.c240
-rw-r--r--contrib/tools/bison/bison/src/derives.h70
-rw-r--r--contrib/tools/bison/bison/src/files.c828
-rw-r--r--contrib/tools/bison/bison/src/files.h144
-rw-r--r--contrib/tools/bison/bison/src/flex-scanner.h180
-rw-r--r--contrib/tools/bison/bison/src/getargs.c1482
-rw-r--r--contrib/tools/bison/bison/src/getargs.h282
-rw-r--r--contrib/tools/bison/bison/src/gram.c620
-rw-r--r--contrib/tools/bison/bison/src/gram.h546
-rw-r--r--contrib/tools/bison/bison/src/graphviz.c436
-rw-r--r--contrib/tools/bison/bison/src/graphviz.h142
-rw-r--r--contrib/tools/bison/bison/src/ielr.c2400
-rw-r--r--contrib/tools/bison/bison/src/ielr.h92
-rw-r--r--contrib/tools/bison/bison/src/lalr.c1000
-rw-r--r--contrib/tools/bison/bison/src/lalr.h212
-rw-r--r--contrib/tools/bison/bison/src/local.mk246
-rw-r--r--contrib/tools/bison/bison/src/location.c464
-rw-r--r--contrib/tools/bison/bison/src/location.h262
-rw-r--r--contrib/tools/bison/bison/src/main.c452
-rw-r--r--contrib/tools/bison/bison/src/muscle-tab.c1550
-rw-r--r--contrib/tools/bison/bison/src/muscle-tab.h434
-rw-r--r--contrib/tools/bison/bison/src/named-ref.c92
-rw-r--r--contrib/tools/bison/bison/src/named-ref.h92
-rw-r--r--contrib/tools/bison/bison/src/nullable.c284
-rw-r--r--contrib/tools/bison/bison/src/nullable.h64
-rw-r--r--contrib/tools/bison/bison/src/output.c1462
-rw-r--r--contrib/tools/bison/bison/src/output.h60
-rw-r--r--contrib/tools/bison/bison/src/parse-gram.c6210
-rw-r--r--contrib/tools/bison/bison/src/parse-gram.h380
-rw-r--r--contrib/tools/bison/bison/src/parse-gram.y1744
-rw-r--r--contrib/tools/bison/bison/src/print-xml.c1088
-rw-r--r--contrib/tools/bison/bison/src/print-xml.h60
-rw-r--r--contrib/tools/bison/bison/src/print.c1058
-rw-r--r--contrib/tools/bison/bison/src/print.h50
-rw-r--r--contrib/tools/bison/bison/src/print_graph.c386
-rw-r--r--contrib/tools/bison/bison/src/print_graph.h50
-rw-r--r--contrib/tools/bison/bison/src/reader.c1592
-rw-r--r--contrib/tools/bison/bison/src/reader.h146
-rw-r--r--contrib/tools/bison/bison/src/reduce.c932
-rw-r--r--contrib/tools/bison/bison/src/reduce.h64
-rw-r--r--contrib/tools/bison/bison/src/relation.c366
-rw-r--r--contrib/tools/bison/bison/src/relation.h98
-rw-r--r--contrib/tools/bison/bison/src/scan-code-c.c6
-rw-r--r--contrib/tools/bison/bison/src/scan-code.c5968
-rw-r--r--contrib/tools/bison/bison/src/scan-code.h392
-rw-r--r--contrib/tools/bison/bison/src/scan-code.l1730
-rw-r--r--contrib/tools/bison/bison/src/scan-gram-c.c6
-rw-r--r--contrib/tools/bison/bison/src/scan-gram.c8024
-rw-r--r--contrib/tools/bison/bison/src/scan-gram.h76
-rw-r--r--contrib/tools/bison/bison/src/scan-gram.l2028
-rw-r--r--contrib/tools/bison/bison/src/scan-skel-c.c6
-rw-r--r--contrib/tools/bison/bison/src/scan-skel.c4854
-rw-r--r--contrib/tools/bison/bison/src/scan-skel.c.saved4806
-rw-r--r--contrib/tools/bison/bison/src/scan-skel.h54
-rw-r--r--contrib/tools/bison/bison/src/scan-skel.l542
-rw-r--r--contrib/tools/bison/bison/src/state.c932
-rw-r--r--contrib/tools/bison/bison/src/state.h548
-rw-r--r--contrib/tools/bison/bison/src/symlist.c478
-rw-r--r--contrib/tools/bison/bison/src/symlist.h266
-rw-r--r--contrib/tools/bison/bison/src/symtab.c2354
-rw-r--r--contrib/tools/bison/bison/src/symtab.h676
-rw-r--r--contrib/tools/bison/bison/src/system.h522
-rw-r--r--contrib/tools/bison/bison/src/tables.c1726
-rw-r--r--contrib/tools/bison/bison/src/tables.h282
-rw-r--r--contrib/tools/bison/bison/src/uniqstr.c368
-rw-r--r--contrib/tools/bison/bison/src/uniqstr.h206
-rw-r--r--contrib/tools/bison/bison/ya.make90
-rw-r--r--contrib/tools/bison/gnulib/platform/posix/config.h3366
-rw-r--r--contrib/tools/bison/gnulib/platform/posix/configmake.h6
-rw-r--r--contrib/tools/bison/gnulib/platform/posix/fcntl.h1318
-rw-r--r--contrib/tools/bison/gnulib/platform/posix/getopt.h530
-rw-r--r--contrib/tools/bison/gnulib/platform/posix/time.h1120
-rw-r--r--contrib/tools/bison/gnulib/platform/posix/unused-parameter.h40
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/alloca.h128
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/config.h3400
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/configmake.h2
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/fcntl.h1314
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/getopt.h530
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/langinfo.h956
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/locale.h1052
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/math.h5182
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/sched.h116
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/signal.h1542
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/spawn.h2386
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/stdbool.h266
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled502
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/sys/stat.h2084
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/sys/time.h1050
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/sys/wait.h862
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/unistd.h3574
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/unitypes.h94
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/uniwidth.h146
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/unused-parameter.h40
-rw-r--r--contrib/tools/bison/gnulib/src/abitset.c1656
-rw-r--r--contrib/tools/bison/gnulib/src/abitset.h58
-rw-r--r--contrib/tools/bison/gnulib/src/argmatch.c554
-rw-r--r--contrib/tools/bison/gnulib/src/argmatch.h222
-rw-r--r--contrib/tools/bison/gnulib/src/asnprintf.c68
-rw-r--r--contrib/tools/bison/gnulib/src/basename-lgpl.c150
-rw-r--r--contrib/tools/bison/gnulib/src/basename.c116
-rw-r--r--contrib/tools/bison/gnulib/src/bbitset.h608
-rw-r--r--contrib/tools/bison/gnulib/src/binary-io.c6
-rw-r--r--contrib/tools/bison/gnulib/src/binary-io.h150
-rw-r--r--contrib/tools/bison/gnulib/src/bison-system.h522
-rw-r--r--contrib/tools/bison/gnulib/src/bitrotate.c6
-rw-r--r--contrib/tools/bison/gnulib/src/bitrotate.h266
-rw-r--r--contrib/tools/bison/gnulib/src/bitset.c1010
-rw-r--r--contrib/tools/bison/gnulib/src/bitset.h786
-rw-r--r--contrib/tools/bison/gnulib/src/bitset_stats.c1456
-rw-r--r--contrib/tools/bison/gnulib/src/bitset_stats.h66
-rw-r--r--contrib/tools/bison/gnulib/src/bitsetv-print.c142
-rw-r--r--contrib/tools/bison/gnulib/src/bitsetv-print.h56
-rw-r--r--contrib/tools/bison/gnulib/src/bitsetv.c338
-rw-r--r--contrib/tools/bison/gnulib/src/bitsetv.h120
-rw-r--r--contrib/tools/bison/gnulib/src/btowc.c78
-rw-r--r--contrib/tools/bison/gnulib/src/c-ctype.c790
-rw-r--r--contrib/tools/bison/gnulib/src/c-ctype.h590
-rw-r--r--contrib/tools/bison/gnulib/src/c-stack.c660
-rw-r--r--contrib/tools/bison/gnulib/src/c-stack.h88
-rw-r--r--contrib/tools/bison/gnulib/src/c-strcase.h112
-rw-r--r--contrib/tools/bison/gnulib/src/c-strcasecmp.c108
-rw-r--r--contrib/tools/bison/gnulib/src/c-strcaseeq.h368
-rw-r--r--contrib/tools/bison/gnulib/src/c-strncasecmp.c108
-rw-r--r--contrib/tools/bison/gnulib/src/calloc.c146
-rw-r--r--contrib/tools/bison/gnulib/src/canonicalize-lgpl.c820
-rw-r--r--contrib/tools/bison/gnulib/src/clean-temp.c1584
-rw-r--r--contrib/tools/bison/gnulib/src/clean-temp.h284
-rw-r--r--contrib/tools/bison/gnulib/src/cloexec.c166
-rw-r--r--contrib/tools/bison/gnulib/src/cloexec.h76
-rw-r--r--contrib/tools/bison/gnulib/src/close-stream.c156
-rw-r--r--contrib/tools/bison/gnulib/src/close-stream.h4
-rw-r--r--contrib/tools/bison/gnulib/src/close.c138
-rw-r--r--contrib/tools/bison/gnulib/src/closein.c222
-rw-r--r--contrib/tools/bison/gnulib/src/closein.h64
-rw-r--r--contrib/tools/bison/gnulib/src/closeout.c248
-rw-r--r--contrib/tools/bison/gnulib/src/closeout.h72
-rw-r--r--contrib/tools/bison/gnulib/src/concat-filename.c144
-rw-r--r--contrib/tools/bison/gnulib/src/concat-filename.h82
-rw-r--r--contrib/tools/bison/gnulib/src/dirname-lgpl.c172
-rw-r--r--contrib/tools/bison/gnulib/src/dirname.c76
-rw-r--r--contrib/tools/bison/gnulib/src/dirname.h92
-rw-r--r--contrib/tools/bison/gnulib/src/dosname.h106
-rw-r--r--contrib/tools/bison/gnulib/src/dup-safer-flag.c76
-rw-r--r--contrib/tools/bison/gnulib/src/dup-safer.c68
-rw-r--r--contrib/tools/bison/gnulib/src/dup2.c320
-rw-r--r--contrib/tools/bison/gnulib/src/ebitset.c2722
-rw-r--r--contrib/tools/bison/gnulib/src/ebitset.h62
-rw-r--r--contrib/tools/bison/gnulib/src/error.c806
-rw-r--r--contrib/tools/bison/gnulib/src/error.h130
-rw-r--r--contrib/tools/bison/gnulib/src/execute.c556
-rw-r--r--contrib/tools/bison/gnulib/src/execute.h88
-rw-r--r--contrib/tools/bison/gnulib/src/exitfail.c48
-rw-r--r--contrib/tools/bison/gnulib/src/exitfail.h36
-rw-r--r--contrib/tools/bison/gnulib/src/fatal-signal.c572
-rw-r--r--contrib/tools/bison/gnulib/src/fatal-signal.h152
-rw-r--r--contrib/tools/bison/gnulib/src/fclose.c220
-rw-r--r--contrib/tools/bison/gnulib/src/fcntl.c622
-rw-r--r--contrib/tools/bison/gnulib/src/fd-hook.c232
-rw-r--r--contrib/tools/bison/gnulib/src/fd-hook.h238
-rw-r--r--contrib/tools/bison/gnulib/src/fd-safer-flag.c104
-rw-r--r--contrib/tools/bison/gnulib/src/fd-safer.c98
-rw-r--r--contrib/tools/bison/gnulib/src/fflush.c448
-rw-r--r--contrib/tools/bison/gnulib/src/filename.h108
-rw-r--r--contrib/tools/bison/gnulib/src/filenamecat-lgpl.c176
-rw-r--r--contrib/tools/bison/gnulib/src/filenamecat.c82
-rw-r--r--contrib/tools/bison/gnulib/src/filenamecat.h54
-rw-r--r--contrib/tools/bison/gnulib/src/float+.h294
-rw-r--r--contrib/tools/bison/gnulib/src/float.c66
-rw-r--r--contrib/tools/bison/gnulib/src/fopen-safer.c126
-rw-r--r--contrib/tools/bison/gnulib/src/fopen.c220
-rw-r--r--contrib/tools/bison/gnulib/src/fpending.c60
-rw-r--r--contrib/tools/bison/gnulib/src/fpending.h58
-rw-r--r--contrib/tools/bison/gnulib/src/fprintf.c154
-rw-r--r--contrib/tools/bison/gnulib/src/fpucw.h216
-rw-r--r--contrib/tools/bison/gnulib/src/fpurge.c290
-rw-r--r--contrib/tools/bison/gnulib/src/freadahead.c186
-rw-r--r--contrib/tools/bison/gnulib/src/freadahead.h94
-rw-r--r--contrib/tools/bison/gnulib/src/freading.c148
-rw-r--r--contrib/tools/bison/gnulib/src/freading.h106
-rw-r--r--contrib/tools/bison/gnulib/src/frexp.c336
-rw-r--r--contrib/tools/bison/gnulib/src/fseek.c60
-rw-r--r--contrib/tools/bison/gnulib/src/fseeko.c318
-rw-r--r--contrib/tools/bison/gnulib/src/fseterr.c158
-rw-r--r--contrib/tools/bison/gnulib/src/fseterr.h90
-rw-r--r--contrib/tools/bison/gnulib/src/fstat.c176
-rw-r--r--contrib/tools/bison/gnulib/src/ftello.c170
-rw-r--r--contrib/tools/bison/gnulib/src/get-errno.c84
-rw-r--r--contrib/tools/bison/gnulib/src/get-errno.h38
-rw-r--r--contrib/tools/bison/gnulib/src/getdtablesize.c180
-rw-r--r--contrib/tools/bison/gnulib/src/getopt.c2486
-rw-r--r--contrib/tools/bison/gnulib/src/getopt1.c340
-rw-r--r--contrib/tools/bison/gnulib/src/getopt_int.h270
-rw-r--r--contrib/tools/bison/gnulib/src/gettext.h576
-rw-r--r--contrib/tools/bison/gnulib/src/gettimeofday.c308
-rw-r--r--contrib/tools/bison/gnulib/src/gl_anyhash_list1.h54
-rw-r--r--contrib/tools/bison/gnulib/src/gl_anyhash_list2.h276
-rw-r--r--contrib/tools/bison/gnulib/src/gl_anylinked_list1.h96
-rw-r--r--contrib/tools/bison/gnulib/src/gl_anylinked_list2.h2390
-rw-r--r--contrib/tools/bison/gnulib/src/gl_anytree_oset.h594
-rw-r--r--contrib/tools/bison/gnulib/src/gl_avltree_oset.c1166
-rw-r--r--contrib/tools/bison/gnulib/src/gl_avltree_oset.h68
-rw-r--r--contrib/tools/bison/gnulib/src/gl_linkedhash_list.c248
-rw-r--r--contrib/tools/bison/gnulib/src/gl_linkedhash_list.h68
-rw-r--r--contrib/tools/bison/gnulib/src/gl_list.c6
-rw-r--r--contrib/tools/bison/gnulib/src/gl_list.h1682
-rw-r--r--contrib/tools/bison/gnulib/src/gl_oset.c6
-rw-r--r--contrib/tools/bison/gnulib/src/gl_oset.h586
-rw-r--r--contrib/tools/bison/gnulib/src/gl_xlist.c6
-rw-r--r--contrib/tools/bison/gnulib/src/gl_xlist.h354
-rw-r--r--contrib/tools/bison/gnulib/src/gl_xoset.c6
-rw-r--r--contrib/tools/bison/gnulib/src/gl_xoset.h148
-rw-r--r--contrib/tools/bison/gnulib/src/glthread/lock.c2114
-rw-r--r--contrib/tools/bison/gnulib/src/glthread/lock.h1854
-rw-r--r--contrib/tools/bison/gnulib/src/glthread/threadlib.c146
-rw-r--r--contrib/tools/bison/gnulib/src/glthread/tls.c122
-rw-r--r--contrib/tools/bison/gnulib/src/glthread/tls.h598
-rw-r--r--contrib/tools/bison/gnulib/src/hash.c2466
-rw-r--r--contrib/tools/bison/gnulib/src/hash.h214
-rw-r--r--contrib/tools/bison/gnulib/src/ignore-value.h96
-rw-r--r--contrib/tools/bison/gnulib/src/intprops.h638
-rw-r--r--contrib/tools/bison/gnulib/src/isnan.c354
-rw-r--r--contrib/tools/bison/gnulib/src/isnand-nolibm.h66
-rw-r--r--contrib/tools/bison/gnulib/src/isnand.c38
-rw-r--r--contrib/tools/bison/gnulib/src/isnanf-nolibm.h78
-rw-r--r--contrib/tools/bison/gnulib/src/isnanf.c40
-rw-r--r--contrib/tools/bison/gnulib/src/isnanl-nolibm.h64
-rw-r--r--contrib/tools/bison/gnulib/src/isnanl.c40
-rw-r--r--contrib/tools/bison/gnulib/src/itold.c56
-rw-r--r--contrib/tools/bison/gnulib/src/lbitset.c2802
-rw-r--r--contrib/tools/bison/gnulib/src/lbitset.h62
-rw-r--r--contrib/tools/bison/gnulib/src/ldexpl.c178
-rw-r--r--contrib/tools/bison/gnulib/src/libiberty.h72
-rw-r--r--contrib/tools/bison/gnulib/src/localcharset.c1116
-rw-r--r--contrib/tools/bison/gnulib/src/localcharset.h80
-rw-r--r--contrib/tools/bison/gnulib/src/localeconv.c206
-rw-r--r--contrib/tools/bison/gnulib/src/lseek.c134
-rw-r--r--contrib/tools/bison/gnulib/src/lstat.c194
-rw-r--r--contrib/tools/bison/gnulib/src/malloc.c112
-rw-r--r--contrib/tools/bison/gnulib/src/malloca.c298
-rw-r--r--contrib/tools/bison/gnulib/src/malloca.h264
-rw-r--r--contrib/tools/bison/gnulib/src/math.c6
-rw-r--r--contrib/tools/bison/gnulib/src/mbrtowc.c804
-rw-r--r--contrib/tools/bison/gnulib/src/mbswidth.c384
-rw-r--r--contrib/tools/bison/gnulib/src/mbswidth.h120
-rw-r--r--contrib/tools/bison/gnulib/src/mbtowc-impl.h88
-rw-r--r--contrib/tools/bison/gnulib/src/mbtowc.c52
-rw-r--r--contrib/tools/bison/gnulib/src/memchr.c344
-rw-r--r--contrib/tools/bison/gnulib/src/memchr2.c338
-rw-r--r--contrib/tools/bison/gnulib/src/memchr2.h64
-rw-r--r--contrib/tools/bison/gnulib/src/mkdtemp.c78
-rw-r--r--contrib/tools/bison/gnulib/src/mkstemp-safer.c124
-rw-r--r--contrib/tools/bison/gnulib/src/mkstemp.c100
-rw-r--r--contrib/tools/bison/gnulib/src/msvc-inval.c258
-rw-r--r--contrib/tools/bison/gnulib/src/msvc-inval.h444
-rw-r--r--contrib/tools/bison/gnulib/src/msvc-nothrow.c98
-rw-r--r--contrib/tools/bison/gnulib/src/msvc-nothrow.h86
-rw-r--r--contrib/tools/bison/gnulib/src/nl_langinfo.c542
-rw-r--r--contrib/tools/bison/gnulib/src/obstack.c814
-rw-r--r--contrib/tools/bison/gnulib/src/obstack.h1028
-rw-r--r--contrib/tools/bison/gnulib/src/obstack_printf.c182
-rw-r--r--contrib/tools/bison/gnulib/src/open.c362
-rw-r--r--contrib/tools/bison/gnulib/src/pathmax.h166
-rw-r--r--contrib/tools/bison/gnulib/src/perror.c62
-rw-r--r--contrib/tools/bison/gnulib/src/pipe-safer.c112
-rw-r--r--contrib/tools/bison/gnulib/src/pipe2-safer.c104
-rw-r--r--contrib/tools/bison/gnulib/src/pipe2.c336
-rw-r--r--contrib/tools/bison/gnulib/src/printf-args.c374
-rw-r--r--contrib/tools/bison/gnulib/src/printf-args.h316
-rw-r--r--contrib/tools/bison/gnulib/src/printf-frexp.c380
-rw-r--r--contrib/tools/bison/gnulib/src/printf-frexp.h46
-rw-r--r--contrib/tools/bison/gnulib/src/printf-frexpl.c74
-rw-r--r--contrib/tools/bison/gnulib/src/printf-frexpl.h46
-rw-r--r--contrib/tools/bison/gnulib/src/printf-parse.c1276
-rw-r--r--contrib/tools/bison/gnulib/src/printf-parse.h386
-rw-r--r--contrib/tools/bison/gnulib/src/printf.c80
-rw-r--r--contrib/tools/bison/gnulib/src/progname.c184
-rw-r--r--contrib/tools/bison/gnulib/src/progname.h124
-rw-r--r--contrib/tools/bison/gnulib/src/quote.h92
-rw-r--r--contrib/tools/bison/gnulib/src/quotearg.c1936
-rw-r--r--contrib/tools/bison/gnulib/src/quotearg.h782
-rw-r--r--contrib/tools/bison/gnulib/src/raise.c158
-rw-r--r--contrib/tools/bison/gnulib/src/rawmemchr.c272
-rw-r--r--contrib/tools/bison/gnulib/src/readlink.c148
-rw-r--r--contrib/tools/bison/gnulib/src/realloc.c158
-rw-r--r--contrib/tools/bison/gnulib/src/regcomp.c7844
-rw-r--r--contrib/tools/bison/gnulib/src/regex.c162
-rw-r--r--contrib/tools/bison/gnulib/src/regex.h1334
-rw-r--r--contrib/tools/bison/gnulib/src/regex_internal.c3482
-rw-r--r--contrib/tools/bison/gnulib/src/regex_internal.h1816
-rw-r--r--contrib/tools/bison/gnulib/src/regexec.c8820
-rw-r--r--contrib/tools/bison/gnulib/src/rename.c946
-rw-r--r--contrib/tools/bison/gnulib/src/rmdir.c106
-rw-r--r--contrib/tools/bison/gnulib/src/same-inode.h66
-rw-r--r--contrib/tools/bison/gnulib/src/secure_getenv.c82
-rw-r--r--contrib/tools/bison/gnulib/src/sig-handler.c6
-rw-r--r--contrib/tools/bison/gnulib/src/sig-handler.h108
-rw-r--r--contrib/tools/bison/gnulib/src/sigaction.c408
-rw-r--r--contrib/tools/bison/gnulib/src/siglist.h264
-rw-r--r--contrib/tools/bison/gnulib/src/signbitd.c128
-rw-r--r--contrib/tools/bison/gnulib/src/signbitf.c128
-rw-r--r--contrib/tools/bison/gnulib/src/signbitl.c128
-rw-r--r--contrib/tools/bison/gnulib/src/sigprocmask.c698
-rw-r--r--contrib/tools/bison/gnulib/src/size_max.h60
-rw-r--r--contrib/tools/bison/gnulib/src/snprintf.c142
-rw-r--r--contrib/tools/bison/gnulib/src/spawn-pipe.c904
-rw-r--r--contrib/tools/bison/gnulib/src/spawn-pipe.h294
-rw-r--r--contrib/tools/bison/gnulib/src/spawn_faction_addclose.c138
-rw-r--r--contrib/tools/bison/gnulib/src/spawn_faction_adddup2.c140
-rw-r--r--contrib/tools/bison/gnulib/src/spawn_faction_addopen.c146
-rw-r--r--contrib/tools/bison/gnulib/src/spawn_faction_destroy.c62
-rw-r--r--contrib/tools/bison/gnulib/src/spawn_faction_init.c112
-rw-r--r--contrib/tools/bison/gnulib/src/spawn_int.h124
-rw-r--r--contrib/tools/bison/gnulib/src/spawnattr_destroy.c56
-rw-r--r--contrib/tools/bison/gnulib/src/spawnattr_init.c66
-rw-r--r--contrib/tools/bison/gnulib/src/spawnattr_setflags.c90
-rw-r--r--contrib/tools/bison/gnulib/src/spawnattr_setsigmask.c66
-rw-r--r--contrib/tools/bison/gnulib/src/spawni.c746
-rw-r--r--contrib/tools/bison/gnulib/src/spawnp.c66
-rw-r--r--contrib/tools/bison/gnulib/src/sprintf.c160
-rw-r--r--contrib/tools/bison/gnulib/src/stat.c276
-rw-r--r--contrib/tools/bison/gnulib/src/stdio--.h82
-rw-r--r--contrib/tools/bison/gnulib/src/stdio-impl.h224
-rw-r--r--contrib/tools/bison/gnulib/src/stdio-safer.h72
-rw-r--r--contrib/tools/bison/gnulib/src/stdio-write.c396
-rw-r--r--contrib/tools/bison/gnulib/src/stdlib--.h72
-rw-r--r--contrib/tools/bison/gnulib/src/stdlib-safer.h64
-rw-r--r--contrib/tools/bison/gnulib/src/stpcpy.c92
-rw-r--r--contrib/tools/bison/gnulib/src/str-two-way.h904
-rw-r--r--contrib/tools/bison/gnulib/src/strchrnul.c282
-rw-r--r--contrib/tools/bison/gnulib/src/strdup.c108
-rw-r--r--contrib/tools/bison/gnulib/src/streq.h352
-rw-r--r--contrib/tools/bison/gnulib/src/stripslash.c90
-rw-r--r--contrib/tools/bison/gnulib/src/strndup.c72
-rw-r--r--contrib/tools/bison/gnulib/src/strnlen.c60
-rw-r--r--contrib/tools/bison/gnulib/src/strsignal.c400
-rw-r--r--contrib/tools/bison/gnulib/src/strstr.c164
-rw-r--r--contrib/tools/bison/gnulib/src/strtol.c856
-rw-r--r--contrib/tools/bison/gnulib/src/strtoul.c38
-rw-r--r--contrib/tools/bison/gnulib/src/strverscmp.c262
-rw-r--r--contrib/tools/bison/gnulib/src/tempname.c610
-rw-r--r--contrib/tools/bison/gnulib/src/tempname.h100
-rw-r--r--contrib/tools/bison/gnulib/src/timevar.c1130
-rw-r--r--contrib/tools/bison/gnulib/src/timevar.def122
-rw-r--r--contrib/tools/bison/gnulib/src/timevar.h184
-rw-r--r--contrib/tools/bison/gnulib/src/tmpdir.c316
-rw-r--r--contrib/tools/bison/gnulib/src/tmpdir.h52
-rw-r--r--contrib/tools/bison/gnulib/src/unistd--.h64
-rw-r--r--contrib/tools/bison/gnulib/src/unistd-safer.h62
-rw-r--r--contrib/tools/bison/gnulib/src/unistd.c6
-rw-r--r--contrib/tools/bison/gnulib/src/uniwidth/cjk.h74
-rw-r--r--contrib/tools/bison/gnulib/src/uniwidth/width.c736
-rw-r--r--contrib/tools/bison/gnulib/src/unlocked-io.h272
-rw-r--r--contrib/tools/bison/gnulib/src/unsetenv.c254
-rw-r--r--contrib/tools/bison/gnulib/src/vasnprintf.c11210
-rw-r--r--contrib/tools/bison/gnulib/src/vasnprintf.h158
-rw-r--r--contrib/tools/bison/gnulib/src/vasprintf.c100
-rw-r--r--contrib/tools/bison/gnulib/src/vbitset.c2280
-rw-r--r--contrib/tools/bison/gnulib/src/vbitset.h58
-rw-r--r--contrib/tools/bison/gnulib/src/verify.h510
-rw-r--r--contrib/tools/bison/gnulib/src/verror.c154
-rw-r--r--contrib/tools/bison/gnulib/src/verror.h108
-rw-r--r--contrib/tools/bison/gnulib/src/version-etc-fsf.c60
-rw-r--r--contrib/tools/bison/gnulib/src/version-etc.c516
-rw-r--r--contrib/tools/bison/gnulib/src/version-etc.h156
-rw-r--r--contrib/tools/bison/gnulib/src/vfprintf.c148
-rw-r--r--contrib/tools/bison/gnulib/src/vsprintf.c154
-rw-r--r--contrib/tools/bison/gnulib/src/w32spawn.h444
-rw-r--r--contrib/tools/bison/gnulib/src/wait-process.c722
-rw-r--r--contrib/tools/bison/gnulib/src/wait-process.h148
-rw-r--r--contrib/tools/bison/gnulib/src/waitpid.c60
-rw-r--r--contrib/tools/bison/gnulib/src/wcrtomb.c106
-rw-r--r--contrib/tools/bison/gnulib/src/wctype-h.c8
-rw-r--r--contrib/tools/bison/gnulib/src/wcwidth.c100
-rw-r--r--contrib/tools/bison/gnulib/src/xalloc-die.c82
-rw-r--r--contrib/tools/bison/gnulib/src/xalloc-oversized.h76
-rw-r--r--contrib/tools/bison/gnulib/src/xalloc.h526
-rw-r--r--contrib/tools/bison/gnulib/src/xasprintf.c68
-rw-r--r--contrib/tools/bison/gnulib/src/xconcat-filename.c82
-rw-r--r--contrib/tools/bison/gnulib/src/xmalloc.c244
-rw-r--r--contrib/tools/bison/gnulib/src/xmalloca.c76
-rw-r--r--contrib/tools/bison/gnulib/src/xmalloca.h128
-rw-r--r--contrib/tools/bison/gnulib/src/xmemdup0.c88
-rw-r--r--contrib/tools/bison/gnulib/src/xmemdup0.h82
-rw-r--r--contrib/tools/bison/gnulib/src/xprintf.c158
-rw-r--r--contrib/tools/bison/gnulib/src/xprintf.h90
-rw-r--r--contrib/tools/bison/gnulib/src/xsize.c6
-rw-r--r--contrib/tools/bison/gnulib/src/xsize.h234
-rw-r--r--contrib/tools/bison/gnulib/src/xstrndup.c72
-rw-r--r--contrib/tools/bison/gnulib/src/xstrndup.h46
-rw-r--r--contrib/tools/bison/gnulib/src/xvasprintf.c220
-rw-r--r--contrib/tools/bison/gnulib/src/xvasprintf.h110
-rw-r--r--contrib/tools/bison/gnulib/ya.make264
-rw-r--r--contrib/tools/bison/m4/src/Makefile.am58
-rw-r--r--contrib/tools/bison/m4/src/builtin.c4514
-rw-r--r--contrib/tools/bison/m4/src/cpp.cpp6
-rw-r--r--contrib/tools/bison/m4/src/debug.c884
-rw-r--r--contrib/tools/bison/m4/src/eval.c1710
-rw-r--r--contrib/tools/bison/m4/src/format.c788
-rw-r--r--contrib/tools/bison/m4/src/freeze.c796
-rw-r--r--contrib/tools/bison/m4/src/input.c2310
-rw-r--r--contrib/tools/bison/m4/src/m4.c1380
-rw-r--r--contrib/tools/bison/m4/src/m4.h982
-rw-r--r--contrib/tools/bison/m4/src/macro.c782
-rw-r--r--contrib/tools/bison/m4/src/output.c2034
-rw-r--r--contrib/tools/bison/m4/src/path.c410
-rw-r--r--contrib/tools/bison/m4/src/symtab.c796
-rw-r--r--contrib/tools/bison/m4/ya.make42
-rw-r--r--contrib/tools/bison/ya.make2
-rw-r--r--library/cpp/containers/comptrie/comptrie_trie.h6
-rw-r--r--library/cpp/mime/types/mime.cpp2
-rw-r--r--tools/ya.make2
-rw-r--r--util/datetime/systime.cpp2
-rw-r--r--util/generic/bitmap.h14
-rw-r--r--util/generic/ptr.h42
-rw-r--r--util/generic/ptr_ut.cpp22
-rw-r--r--util/generic/singleton.h4
-rw-r--r--util/generic/strbase.h42
-rw-r--r--util/str_stl.h6
-rw-r--r--util/string/cast.cpp16
-rw-r--r--util/string/split.h6
-rw-r--r--util/string/split_ut.cpp12
466 files changed, 140728 insertions, 140728 deletions
diff --git a/build/ymake_conf.py b/build/ymake_conf.py
index 30219eb85e..e792fd3d34 100755
--- a/build/ymake_conf.py
+++ b/build/ymake_conf.py
@@ -605,7 +605,7 @@ class Build(object):
type_ = detector.type
else:
detector = None
-
+
if type_ == 'msvc':
return MSVCToolchainOptions(self, detector)
else:
@@ -613,7 +613,7 @@ class Build(object):
def _print_other_settings(self, compiler):
host = self.host
-
+
emit('USE_LOCAL_TOOLS', 'no' if self.ignore_local_files else 'yes')
ragel = Ragel()
@@ -623,7 +623,7 @@ class Build(object):
perl = Perl()
perl.configure_local()
perl.print_variables('LOCAL_')
-
+
swiftc = SwiftCompiler(self)
swiftc.configure()
swiftc.print_compiler()
diff --git a/contrib/libs/libidn/idna.c b/contrib/libs/libidn/idna.c
index af3f24d58e..222a6aaed5 100644
--- a/contrib/libs/libidn/idna.c
+++ b/contrib/libs/libidn/idna.c
@@ -33,43 +33,43 @@
#define DOTP(c) ((c) == 0x002E || (c) == 0x3002 || \
(c) == 0xFF0E || (c) == 0xFF61)
-#ifdef WITH_VALGRIND
-
-static size_t STRLEN(const char *s) {
- size_t ret = 0;
- while (*s++)
- ++ret;
- return ret;
-}
-
-static char* STRCPY(char* destination, const char* source) {
- char *p = destination;
- while (*source)
- *p++ = *source++;
- *p = 0;
- return destination;
-}
-
-static char* STRCAT(char* destination, const char* source) {
- char *p = destination;
- while (*p)
- ++p;
-
- while (*source)
- *p++ = *source++;
- *p = 0;
-
- return destination;
-}
-
-#else //WITH_VALGRIND
-
-# define STRLEN(s) strlen(s)
-# define STRCAT(d, s) strcat(d, s)
-# define STRCPY(d, s) strcpy(d, s)
-
-#endif
+#ifdef WITH_VALGRIND
+
+static size_t STRLEN(const char *s) {
+ size_t ret = 0;
+ while (*s++)
+ ++ret;
+ return ret;
+}
+
+static char* STRCPY(char* destination, const char* source) {
+ char *p = destination;
+ while (*source)
+ *p++ = *source++;
+ *p = 0;
+ return destination;
+}
+
+static char* STRCAT(char* destination, const char* source) {
+ char *p = destination;
+ while (*p)
+ ++p;
+
+ while (*source)
+ *p++ = *source++;
+ *p = 0;
+
+ return destination;
+}
+
+#else //WITH_VALGRIND
+
+# define STRLEN(s) strlen(s)
+# define STRCAT(d, s) strcat(d, s)
+# define STRCPY(d, s) strcpy(d, s)
+#endif
+
/* Core functions */
/**
@@ -150,7 +150,7 @@ idna_to_ascii_4i (const uint32_t * in, size_t inlen, char *out, int flags)
if (p == NULL)
return IDNA_MALLOC_ERROR;
- len = STRLEN (p);
+ len = STRLEN (p);
do
{
char *newp;
@@ -251,7 +251,7 @@ step3:
int match;
match = 1;
- for (i = 0; match && i < STRLEN (IDNA_ACE_PREFIX); i++)
+ for (i = 0; match && i < STRLEN (IDNA_ACE_PREFIX); i++)
if (((uint32_t) IDNA_ACE_PREFIX[i] & 0xFF) != src[i])
match = 0;
if (match)
@@ -270,19 +270,19 @@ step3:
src[len] = '\0';
outlen = IDNA_LABEL_MAX_LENGTH - STRLEN (IDNA_ACE_PREFIX);
rc = punycode_encode (len, src, NULL,
- &outlen, &out[STRLEN (IDNA_ACE_PREFIX)]);
+ &outlen, &out[STRLEN (IDNA_ACE_PREFIX)]);
if (rc != PUNYCODE_SUCCESS)
{
free (src);
return IDNA_PUNYCODE_ERROR;
}
- out[STRLEN (IDNA_ACE_PREFIX) + outlen] = '\0';
+ out[STRLEN (IDNA_ACE_PREFIX) + outlen] = '\0';
/*
* 7. Prepend the ACE prefix.
*/
- memcpy (out, IDNA_ACE_PREFIX, STRLEN (IDNA_ACE_PREFIX));
+ memcpy (out, IDNA_ACE_PREFIX, STRLEN (IDNA_ACE_PREFIX));
/*
* 8. Verify that the number of code points is in the range 1 to IDNA_LABEL_MAX_LENGTH
@@ -304,7 +304,7 @@ idna_to_unicode_internal (char *utf8in,
{
int rc;
char tmpout[IDNA_LABEL_MAX_LENGTH + 1];
- size_t utf8len = STRLEN (utf8in) + 1;
+ size_t utf8len = STRLEN (utf8in) + 1;
size_t addlen = 0;
/*
@@ -369,8 +369,8 @@ step3:
/* 4. Remove the ACE prefix.
*/
- memmove (utf8in, &utf8in[STRLEN (IDNA_ACE_PREFIX)],
- STRLEN (utf8in) - STRLEN (IDNA_ACE_PREFIX) + 1);
+ memmove (utf8in, &utf8in[STRLEN (IDNA_ACE_PREFIX)],
+ STRLEN (utf8in) - STRLEN (IDNA_ACE_PREFIX) + 1);
/* 5. Decode the sequence using the decoding algorithm in [PUNYCODE]
* and fail if there is an error. Save a copy of the result of
@@ -379,7 +379,7 @@ step3:
(*outlen)--; /* reserve one for the zero */
- rc = punycode_decode (STRLEN (utf8in), utf8in, outlen, out, NULL);
+ rc = punycode_decode (STRLEN (utf8in), utf8in, outlen, out, NULL);
if (rc != PUNYCODE_SUCCESS)
{
free (utf8in);
@@ -402,7 +402,7 @@ step3:
* step 3, using a case-insensitive ASCII comparison.
*/
- if (strcasecmp (utf8in, tmpout + STRLEN (IDNA_ACE_PREFIX)) != 0)
+ if (strcasecmp (utf8in, tmpout + STRLEN (IDNA_ACE_PREFIX)) != 0)
{
free (utf8in);
return IDNA_ROUNDTRIP_VERIFY_ERROR;
@@ -510,7 +510,7 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
*output = malloc (1);
if (!*output)
return IDNA_MALLOC_ERROR;
- STRCPY (*output, "");
+ STRCPY (*output, "");
return IDNA_SUCCESS;
}
@@ -520,7 +520,7 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
*output = malloc (2);
if (!*output)
return IDNA_MALLOC_ERROR;
- STRCPY (*output, ".");
+ STRCPY (*output, ".");
return IDNA_SUCCESS;
}
@@ -549,22 +549,22 @@ idna_to_ascii_4z (const uint32_t * input, char **output, int flags)
if (out)
{
- char *newp = realloc (out, STRLEN (out) + 1 + STRLEN (buf) + 1);
+ char *newp = realloc (out, STRLEN (out) + 1 + STRLEN (buf) + 1);
if (!newp)
{
free (out);
return IDNA_MALLOC_ERROR;
}
out = newp;
- STRCAT (out, ".");
- STRCAT (out, buf);
+ STRCAT (out, ".");
+ STRCAT (out, buf);
}
else
{
- out = (char *) malloc (STRLEN (buf) + 1);
+ out = (char *) malloc (STRLEN (buf) + 1);
if (!out)
return IDNA_MALLOC_ERROR;
- STRCPY (out, buf);
+ STRCPY (out, buf);
}
start = end + 1;
diff --git a/contrib/libs/pire/pire/platform.h b/contrib/libs/pire/pire/platform.h
index 54ded6b387..69680ad88f 100644
--- a/contrib/libs/pire/pire/platform.h
+++ b/contrib/libs/pire/pire/platform.h
@@ -74,19 +74,19 @@ typedef i32 ssize_t;
inline int snprintf(char *str, size_t size, const char *format, ...)
{
- va_list argptr;
- va_start(argptr, format);
- int i = _vsnprintf(str, size-1, format, argptr);
- va_end(argptr);
-
- // A workaround for some bug
- if (i < 0) {
- str[size - 1] = '\x00';
- i = (int)size;
- } else if (i < (int)size) {
- str[i] = '\x00';
- }
- return i;
+ va_list argptr;
+ va_start(argptr, format);
+ int i = _vsnprintf(str, size-1, format, argptr);
+ va_end(argptr);
+
+ // A workaround for some bug
+ if (i < 0) {
+ str[size - 1] = '\x00';
+ i = (int)size;
+ } else if (i < (int)size) {
+ str[i] = '\x00';
+ }
+ return i;
}
}
@@ -95,40 +95,40 @@ inline int snprintf(char *str, size_t size, const char *format, ...)
namespace Pire {
namespace Impl {
-// A portable way to define a constant like `(size_t)0101010101010101ull' without any warnings.
-template<unsigned Pos, unsigned char Byte>
-struct DoGenerateConst {
- static const size_t Value = DoGenerateConst<Pos-1, Byte>::Value << 8 | (size_t) Byte;
-};
-
-template<unsigned char Byte>
-struct DoGenerateConst<0, Byte> {
- static const size_t Value = 0;
-};
-
-template<unsigned char Byte>
-struct GenerateConst {
- static const size_t Value = DoGenerateConst<sizeof(size_t), Byte>::Value;
-};
-
-
+// A portable way to define a constant like `(size_t)0101010101010101ull' without any warnings.
+template<unsigned Pos, unsigned char Byte>
+struct DoGenerateConst {
+ static const size_t Value = DoGenerateConst<Pos-1, Byte>::Value << 8 | (size_t) Byte;
+};
+
+template<unsigned char Byte>
+struct DoGenerateConst<0, Byte> {
+ static const size_t Value = 0;
+};
+
+template<unsigned char Byte>
+struct GenerateConst {
+ static const size_t Value = DoGenerateConst<sizeof(size_t), Byte>::Value;
+};
+
+
// Common implementation of mask comparison logic suitable for
// any instruction set
struct BasicInstructionSet {
- typedef size_t Vector;
+ typedef size_t Vector;
- // Check bytes in the chunk against bytes in the mask
- static inline Vector CheckBytes(Vector mask, Vector chunk)
- {
- const size_t mask0x01 = GenerateConst<0x01>::Value;
- const size_t mask0x80 = GenerateConst<0x80>::Value;
- size_t mc = chunk ^ mask;
- return ((mc - mask0x01) & ~mc & mask0x80);
- }
+ // Check bytes in the chunk against bytes in the mask
+ static inline Vector CheckBytes(Vector mask, Vector chunk)
+ {
+ const size_t mask0x01 = GenerateConst<0x01>::Value;
+ const size_t mask0x80 = GenerateConst<0x80>::Value;
+ size_t mc = chunk ^ mask;
+ return ((mc - mask0x01) & ~mc & mask0x80);
+ }
- static inline Vector Or(Vector mask1, Vector mask2) { return (mask1 | mask2); }
+ static inline Vector Or(Vector mask1, Vector mask2) { return (mask1 | mask2); }
- static inline bool IsAnySet(Vector mask) { return (mask != 0); }
+ static inline bool IsAnySet(Vector mask) { return (mask != 0); }
};
}}
@@ -141,22 +141,22 @@ namespace Impl {
// SSE2-optimized mask comparison logic
struct AvailSSE2 {
- typedef __m128i Vector;
-
- static inline Vector CheckBytes(Vector mask, Vector chunk)
- {
- return _mm_cmpeq_epi8(mask, chunk);
- }
-
- static inline Vector Or(Vector mask1, Vector mask2)
- {
- return _mm_or_si128(mask1, mask2);
- }
-
- static inline bool IsAnySet(Vector mask)
- {
- return _mm_movemask_epi8(mask);
- }
+ typedef __m128i Vector;
+
+ static inline Vector CheckBytes(Vector mask, Vector chunk)
+ {
+ return _mm_cmpeq_epi8(mask, chunk);
+ }
+
+ static inline Vector Or(Vector mask1, Vector mask2)
+ {
+ return _mm_or_si128(mask1, mask2);
+ }
+
+ static inline bool IsAnySet(Vector mask)
+ {
+ return _mm_movemask_epi8(mask);
+ }
};
typedef AvailSSE2 AvailInstructionSet;
@@ -173,27 +173,27 @@ namespace Impl {
// MMX-optimized mask comparison logic
struct AvailMMX {
- typedef __m64 Vector;
-
- static inline Vector CheckBytes(Vector mask, Vector chunk)
- {
- return _mm_cmpeq_pi8(mask, chunk);
- }
-
- static inline Vector Or(Vector mask1, Vector mask2)
- {
- return _mm_or_si64(mask1, mask2);
- }
-
- static inline bool IsAnySet(Vector mask)
- {
- union {
- Vector mmxMask;
- ui64 ui64Mask;
- };
- mmxMask = mask;
- return ui64Mask;
- }
+ typedef __m64 Vector;
+
+ static inline Vector CheckBytes(Vector mask, Vector chunk)
+ {
+ return _mm_cmpeq_pi8(mask, chunk);
+ }
+
+ static inline Vector Or(Vector mask1, Vector mask2)
+ {
+ return _mm_or_si64(mask1, mask2);
+ }
+
+ static inline bool IsAnySet(Vector mask)
+ {
+ union {
+ Vector mmxMask;
+ ui64 ui64Mask;
+ };
+ mmxMask = mask;
+ return ui64Mask;
+ }
};
typedef AvailMMX AvailInstructionSet;
@@ -234,25 +234,25 @@ template <size_t Size> struct MaxWordSizeHelper;
// Maximum size of SSE register is 128 bit on x86 and x86_64
template <>
struct MaxWordSizeHelper<16> {
- struct MaxSizeWord {
- char val[16];
- };
+ struct MaxSizeWord {
+ char val[16];
+ };
};
typedef MaxWordSizeHelper<16>::MaxSizeWord MaxSizeWord;
// MaxSizeWord size should be a multiple of size_t size and a multipe of Word size
PIRE_STATIC_ASSERT(
- (sizeof(MaxSizeWord) % sizeof(size_t) == 0) &&
- (sizeof(MaxSizeWord) % sizeof(Word) == 0));
+ (sizeof(MaxSizeWord) % sizeof(size_t) == 0) &&
+ (sizeof(MaxSizeWord) % sizeof(Word) == 0));
inline size_t FillSizeT(char c)
{
- size_t w = c;
- w &= 0x0ff;
- for (size_t i = 8; i != sizeof(size_t)*8; i <<= 1)
- w = (w << i) | w;
- return w;
+ size_t w = c;
+ w &= 0x0ff;
+ for (size_t i = 8; i != sizeof(size_t)*8; i <<= 1)
+ w = (w << i) | w;
+ return w;
}
}}
diff --git a/contrib/libs/pire/pire/re_lexer.cpp b/contrib/libs/pire/pire/re_lexer.cpp
index 132fbeb039..afb194e437 100644
--- a/contrib/libs/pire/pire/re_lexer.cpp
+++ b/contrib/libs/pire/pire/re_lexer.cpp
@@ -29,15 +29,15 @@
#include <contrib/libs/pire/pire/stub/singleton.h>
#include "fsm.h"
-#include "re_lexer.h"
-#include "re_parser.h"
+#include "re_lexer.h"
+#include "re_parser.h"
#include "read_unicode.h"
namespace Pire {
namespace Impl {
- int yre_parse(Pire::Lexer& lexer);
+ int yre_parse(Pire::Lexer& lexer);
}
Term Term::Character(wchar32 c) { Term::CharacterRange cr; cr.first.insert(Term::String(1, c)); cr.second = false; return Term(TokenTypes::Letters, cr); }
@@ -50,51 +50,51 @@ Lexer::~Lexer() = default;
wchar32 Lexer::GetChar()
{
- if (m_input.empty())
- return End;
- else if (m_input.front() == '\\') {
- m_input.pop_front();
- if (m_input.empty())
- Error("Regexp must not end with a backslash");
- wchar32 ch = m_input.front();
- m_input.pop_front();
- return Control | ch;
- } else {
- wchar32 ch = m_input.front();
- m_input.pop_front();
- return ch;
- }
+ if (m_input.empty())
+ return End;
+ else if (m_input.front() == '\\') {
+ m_input.pop_front();
+ if (m_input.empty())
+ Error("Regexp must not end with a backslash");
+ wchar32 ch = m_input.front();
+ m_input.pop_front();
+ return Control | ch;
+ } else {
+ wchar32 ch = m_input.front();
+ m_input.pop_front();
+ return ch;
+ }
}
wchar32 Lexer::PeekChar()
{
- if (m_input.empty())
- return End;
- else
- return m_input.front();
+ if (m_input.empty())
+ return End;
+ else
+ return m_input.front();
}
void Lexer::UngetChar(wchar32 c)
{
- if (c != End)
- m_input.push_front(c);
+ if (c != End)
+ m_input.push_front(c);
}
namespace {
class CompareFeaturesByPriority: public ybinary_function<const Feature::Ptr&, const Feature::Ptr&, bool> {
- public:
+ public:
bool operator()(const Feature::Ptr& a, const Feature::Ptr& b) const
- {
- return a->Priority() < b->Priority();
- }
- };
+ {
+ return a->Priority() < b->Priority();
+ }
+ };
}
Lexer& Lexer::AddFeature(Feature::Ptr& feature)
{
- feature->m_lexer = this;
+ feature->m_lexer = this;
m_features.insert(LowerBound(m_features.begin(), m_features.end(), feature, CompareFeaturesByPriority()), std::move(feature));
- return *this;
+ return *this;
}
Lexer& Lexer::AddFeature(Feature::Ptr&& feature)
@@ -106,107 +106,107 @@ Lexer& Lexer::AddFeature(Feature::Ptr&& feature)
Term Lexer::DoLex()
{
- static const char* controls = "|().*+?^$\\";
- for (;;) {
- UngetChar(GetChar());
- wchar32 ch = PeekChar();
- if (ch == End)
- return Term(TokenTypes::End);
+ static const char* controls = "|().*+?^$\\";
+ for (;;) {
+ UngetChar(GetChar());
+ wchar32 ch = PeekChar();
+ if (ch == End)
+ return Term(TokenTypes::End);
for (auto&& i : m_features) {
if (i->Accepts(ch)) {
Term ret = i->Lex();
- if (ret.Type())
- return ret;
- }
- }
- ch = GetChar();
-
- if (ch == '|')
- return Term(TokenTypes::Or);
- else if (ch == '(') {
- return Term(TokenTypes::Open);
- } else if (ch == ')')
- return Term(TokenTypes::Close);
- else if (ch == '.')
- return Term::Dot();
- else if (ch == '*')
- return Term::Repetition(0, Inf);
- else if (ch == '+')
- return Term::Repetition(1, Inf);
- else if (ch == '?')
- return Term::Repetition(0, 1);
- else if (ch == '^')
- return Term::BeginMark();
- else if (ch == '$')
- return Term::EndMark();
- else if ((ch & ControlMask) == Control && strchr(controls, ch & ~ControlMask))
- return Term::Character(ch & ~ControlMask);
- else
- return Term::Character(ch);
- }
+ if (ret.Type())
+ return ret;
+ }
+ }
+ ch = GetChar();
+
+ if (ch == '|')
+ return Term(TokenTypes::Or);
+ else if (ch == '(') {
+ return Term(TokenTypes::Open);
+ } else if (ch == ')')
+ return Term(TokenTypes::Close);
+ else if (ch == '.')
+ return Term::Dot();
+ else if (ch == '*')
+ return Term::Repetition(0, Inf);
+ else if (ch == '+')
+ return Term::Repetition(1, Inf);
+ else if (ch == '?')
+ return Term::Repetition(0, 1);
+ else if (ch == '^')
+ return Term::BeginMark();
+ else if (ch == '$')
+ return Term::EndMark();
+ else if ((ch & ControlMask) == Control && strchr(controls, ch & ~ControlMask))
+ return Term::Character(ch & ~ControlMask);
+ else
+ return Term::Character(ch);
+ }
}
Term Lexer::Lex()
{
- Term t = DoLex();
+ Term t = DoLex();
for (auto i = m_features.rbegin(), ie = m_features.rend(); i != ie; ++i)
- (*i)->Alter(t);
+ (*i)->Alter(t);
- if (t.Value().IsA<Term::CharacterRange>()) {
+ if (t.Value().IsA<Term::CharacterRange>()) {
const auto& chars = t.Value().As<Term::CharacterRange>();
- //std::cerr << "lex: type " << t.type() << "; chars = { " << join(chars.first.begin(), chars.first.end(), ", ") << " }" << std::endl;
+ //std::cerr << "lex: type " << t.type() << "; chars = { " << join(chars.first.begin(), chars.first.end(), ", ") << " }" << std::endl;
for (auto&& i : chars.first)
for (auto&& j : i)
if ((j & ControlMask) == Control)
- Error("Control character in tokens sequence");
- }
-
- int type = t.Type();
- if (type == TokenTypes::Letters)
- type = YRE_LETTERS;
- else if (type == TokenTypes::Count)
- type = YRE_COUNT;
- else if (type == TokenTypes::Dot)
- type = YRE_DOT;
- else if (type == TokenTypes::Open)
- type = '(';
- else if (type == TokenTypes::Close)
- type = ')';
- else if (type == TokenTypes::Or)
- type = '|';
- else if (type == TokenTypes::And)
- type = YRE_AND;
- else if (type == TokenTypes::Not)
- type = YRE_NOT;
- else if (type == TokenTypes::BeginMark)
- type = '^';
- else if (type == TokenTypes::EndMark)
- type = '$';
- else if (type == TokenTypes::End)
- type = 0;
- return Term(type, t.Value());
+ Error("Control character in tokens sequence");
+ }
+
+ int type = t.Type();
+ if (type == TokenTypes::Letters)
+ type = YRE_LETTERS;
+ else if (type == TokenTypes::Count)
+ type = YRE_COUNT;
+ else if (type == TokenTypes::Dot)
+ type = YRE_DOT;
+ else if (type == TokenTypes::Open)
+ type = '(';
+ else if (type == TokenTypes::Close)
+ type = ')';
+ else if (type == TokenTypes::Or)
+ type = '|';
+ else if (type == TokenTypes::And)
+ type = YRE_AND;
+ else if (type == TokenTypes::Not)
+ type = YRE_NOT;
+ else if (type == TokenTypes::BeginMark)
+ type = '^';
+ else if (type == TokenTypes::EndMark)
+ type = '$';
+ else if (type == TokenTypes::End)
+ type = 0;
+ return Term(type, t.Value());
}
void Lexer::Parenthesized(Fsm& fsm)
{
for (auto i = m_features.rbegin(), ie = m_features.rend(); i != ie; ++i)
- (*i)->Parenthesized(fsm);
+ (*i)->Parenthesized(fsm);
}
wchar32 Feature::CorrectChar(wchar32 c, const char* controls)
{
- bool ctrl = (strchr(controls, c & 0xFF) != 0);
- if ((c & ControlMask) == Control && ctrl)
- return c & ~ControlMask;
- if (c <= 0xFF && ctrl)
- return c | Control;
- return c;
+ bool ctrl = (strchr(controls, c & 0xFF) != 0);
+ if ((c & ControlMask) == Control && ctrl)
+ return c & ~ControlMask;
+ if (c <= 0xFF && ctrl)
+ return c | Control;
+ return c;
}
namespace {
class EnableUnicodeSequencesImpl : public UnicodeReader {
- public:
+ public:
bool Accepts(wchar32 c) const {
return c == (Control | 'x');
}
@@ -218,27 +218,27 @@ namespace {
class CharacterRangeReader: public UnicodeReader {
public:
- bool Accepts(wchar32 c) const { return c == '[' || c == (Control | '[') || c == (Control | ']'); }
-
- Term Lex()
- {
- static const char* controls = "^[]-\\";
- static const char* controls2 = "*+{}()$?.&~";
- wchar32 ch = CorrectChar(GetChar(), controls);
- if (ch == '[' || ch == ']')
- return Term::Character(ch);
-
- Term::CharacterRange cs;
- ch = CorrectChar(GetChar(), controls);
- if (ch == (Control | '^')) {
- cs.second = true;
- ch = CorrectChar(GetChar(), controls);
- }
+ bool Accepts(wchar32 c) const { return c == '[' || c == (Control | '[') || c == (Control | ']'); }
+
+ Term Lex()
+ {
+ static const char* controls = "^[]-\\";
+ static const char* controls2 = "*+{}()$?.&~";
+ wchar32 ch = CorrectChar(GetChar(), controls);
+ if (ch == '[' || ch == ']')
+ return Term::Character(ch);
+
+ Term::CharacterRange cs;
+ ch = CorrectChar(GetChar(), controls);
+ if (ch == (Control | '^')) {
+ cs.second = true;
+ ch = CorrectChar(GetChar(), controls);
+ }
bool firstUnicode;
wchar32 unicodeSymbol = 0;
- for (; ch != End && ch != (Control | ']'); ch = CorrectChar(GetChar(), controls)) {
+ for (; ch != End && ch != (Control | ']'); ch = CorrectChar(GetChar(), controls)) {
if (ch == (Control | 'x')) {
UngetChar(ch);
firstUnicode = true;
@@ -248,7 +248,7 @@ namespace {
}
if (((ch & ControlMask) != Control || firstUnicode) && CorrectChar(PeekChar(), controls) == (Control | '-')) {
- GetChar();
+ GetChar();
wchar32 current = GetChar();
bool secondUnicode = (current == (Control | 'x'));
@@ -265,104 +265,104 @@ namespace {
}
for (ch = begin; ch <= end; ++ch) {
- cs.first.insert(Term::String(1, ch));
+ cs.first.insert(Term::String(1, ch));
}
} else if (ch == (Control | '-')) {
- cs.first.insert(Term::String(1, '-'));
+ cs.first.insert(Term::String(1, '-'));
}
else if ((ch & ControlMask) == Control && (strchr(controls2, ch & ~ControlMask) || strchr(controls, ch & ~ControlMask))) {
- cs.first.insert(Term::String(1, ch & ~ControlMask));
+ cs.first.insert(Term::String(1, ch & ~ControlMask));
}
else if ((ch & ControlMask) != Control || !strchr(controls, ch & ~ControlMask)) {
cs.first.insert(Term::String(1, (firstUnicode) ? unicodeSymbol : ch));
} else {
- Error("Wrong character in range");
+ Error("Wrong character in range");
}
- }
- if (ch == End)
- Error("Unexpected end of pattern");
-
- return Term(TokenTypes::Letters, cs);
- }
- };
-
- class RepetitionCountReader: public Feature {
- public:
- bool Accepts(wchar32 c) const { return c == '{' || c == (Control | '{') || c == (Control | '}'); }
-
- Term Lex()
- {
- wchar32 ch = GetChar();
- if (ch == (Control | '{') || ch == (Control | '}'))
- return Term::Character(ch & ~ControlMask);
- ch = GetChar();
- int lower = 0, upper = 0;
-
- if (!is_digit(ch))
- Error("Wrong repetition count");
-
- for (; is_digit(ch); ch = GetChar())
- lower = lower * 10 + (ch - '0');
- if (ch == '}')
- return Term::Repetition(lower, lower);
- else if (ch != ',')
- Error("Wrong repetition count");
-
- ch = GetChar();
- if (ch == '}')
- return Term::Repetition(lower, Inf);
- else if (!is_digit(ch))
- Error("Wrong repetition count");
- for (; is_digit(ch); ch = GetChar())
- upper = upper * 10 + (ch - '0');
-
- if (ch != '}')
- Error("Wrong repetition count");
- return Term::Repetition(lower, upper);
- }
- };
-
- class CaseInsensitiveImpl: public Feature {
- public:
- void Alter(Term& t)
- {
- if (t.Value().IsA<Term::CharacterRange>()) {
- typedef Term::CharacterRange::first_type CharSet;
- const CharSet& old = t.Value().As<Term::CharacterRange>().first;
- CharSet altered;
+ }
+ if (ch == End)
+ Error("Unexpected end of pattern");
+
+ return Term(TokenTypes::Letters, cs);
+ }
+ };
+
+ class RepetitionCountReader: public Feature {
+ public:
+ bool Accepts(wchar32 c) const { return c == '{' || c == (Control | '{') || c == (Control | '}'); }
+
+ Term Lex()
+ {
+ wchar32 ch = GetChar();
+ if (ch == (Control | '{') || ch == (Control | '}'))
+ return Term::Character(ch & ~ControlMask);
+ ch = GetChar();
+ int lower = 0, upper = 0;
+
+ if (!is_digit(ch))
+ Error("Wrong repetition count");
+
+ for (; is_digit(ch); ch = GetChar())
+ lower = lower * 10 + (ch - '0');
+ if (ch == '}')
+ return Term::Repetition(lower, lower);
+ else if (ch != ',')
+ Error("Wrong repetition count");
+
+ ch = GetChar();
+ if (ch == '}')
+ return Term::Repetition(lower, Inf);
+ else if (!is_digit(ch))
+ Error("Wrong repetition count");
+ for (; is_digit(ch); ch = GetChar())
+ upper = upper * 10 + (ch - '0');
+
+ if (ch != '}')
+ Error("Wrong repetition count");
+ return Term::Repetition(lower, upper);
+ }
+ };
+
+ class CaseInsensitiveImpl: public Feature {
+ public:
+ void Alter(Term& t)
+ {
+ if (t.Value().IsA<Term::CharacterRange>()) {
+ typedef Term::CharacterRange::first_type CharSet;
+ const CharSet& old = t.Value().As<Term::CharacterRange>().first;
+ CharSet altered;
for (auto&& i : old) {
if (i.size() == 1) {
altered.insert(Term::String(1, to_upper(i[0])));
altered.insert(Term::String(1, to_lower(i[0])));
- } else
+ } else
altered.insert(i);
- }
- t = Term(t.Type(), Term::CharacterRange(altered, t.Value().As<Term::CharacterRange>().second));
- }
- }
- };
- class AndNotSupportImpl: public Feature {
- public:
- bool Accepts(wchar32 c) const
- {
- return c == '&' || c == '~' || c == (Control | '&') || c == (Control | '~');
- }
-
- Term Lex()
- {
- wchar32 ch = GetChar();
- if (ch == (Control | '&') || ch == (Control | '~'))
- return Term::Character(ch & ~ControlMask);
- else if (ch == '&')
- return Term(TokenTypes::And);
- else if (ch == '~')
- return Term(TokenTypes::Not);
- else {
- Error("Pire::AndNotSupport::Lex(): strange input character");
- return Term(0); // Make compiler happy
- }
- }
- };
+ }
+ t = Term(t.Type(), Term::CharacterRange(altered, t.Value().As<Term::CharacterRange>().second));
+ }
+ }
+ };
+ class AndNotSupportImpl: public Feature {
+ public:
+ bool Accepts(wchar32 c) const
+ {
+ return c == '&' || c == '~' || c == (Control | '&') || c == (Control | '~');
+ }
+
+ Term Lex()
+ {
+ wchar32 ch = GetChar();
+ if (ch == (Control | '&') || ch == (Control | '~'))
+ return Term::Character(ch & ~ControlMask);
+ else if (ch == '&')
+ return Term(TokenTypes::And);
+ else if (ch == '~')
+ return Term(TokenTypes::Not);
+ else {
+ Error("Pire::AndNotSupport::Lex(): strange input character");
+ return Term(0); // Make compiler happy
+ }
+ }
+ };
}
namespace Features {
@@ -375,18 +375,18 @@ void Lexer::InstallDefaultFeatures()
{
AddFeature(Feature::Ptr(new CharacterRangeReader));
AddFeature(Feature::Ptr(new RepetitionCountReader));
- AddFeature(Features::CharClasses());
+ AddFeature(Features::CharClasses());
AddFeature(Feature::Ptr(new EnableUnicodeSequencesImpl));
}
Fsm Lexer::Parse()
{
- if (!Impl::yre_parse(*this))
- return m_retval.As<Fsm>();
- else {
- Error("Syntax error in regexp");
- return Fsm(); // Make compiler happy
- }
+ if (!Impl::yre_parse(*this))
+ return m_retval.As<Fsm>();
+ else {
+ Error("Syntax error in regexp");
+ return Fsm(); // Make compiler happy
+ }
}
}
diff --git a/contrib/libs/pire/pire/re_parser.y b/contrib/libs/pire/pire/re_parser.y
index dbad88e287..39de0a92f0 100644
--- a/contrib/libs/pire/pire/re_parser.y
+++ b/contrib/libs/pire/pire/re_parser.y
@@ -52,16 +52,16 @@ using Pire::Fsm;
using Pire::Encoding;
int yylex(YYSTYPE*, Lexer&);
-void yyerror(Pire::Lexer&, const char*);
+void yyerror(Pire::Lexer&, const char*);
Fsm& ConvertToFSM(const Encoding& encoding, Any* any);
void AppendRange(const Encoding& encoding, Fsm& a, const Term::CharacterRange& cr);
%}
-%parse-param { Pire::Lexer& rlex }
-%lex-param { Pire::Lexer& rlex }
-%pure-parser
+%parse-param { Pire::Lexer& rlex }
+%lex-param { Pire::Lexer& rlex }
+%pure-parser
// Terminal declarations
%term YRE_LETTERS
@@ -75,83 +75,83 @@ void AppendRange(const Encoding& encoding, Fsm& a, const Term::CharacterRange& c
%%
regexp
- : alternative
- {
- ConvertToFSM(rlex.Encoding(), $1);
- DoSwap(rlex.Retval(), *$1);
- delete $1;
+ : alternative
+ {
+ ConvertToFSM(rlex.Encoding(), $1);
+ DoSwap(rlex.Retval(), *$1);
+ delete $1;
$$ = nullptr;
- }
- ;
+ }
+ ;
alternative
- : conjunction
+ : conjunction
| alternative '|' conjunction { ConvertToFSM(rlex.Encoding(), ($$ = $1)) |= ConvertToFSM(rlex.Encoding(), $3); delete $2; delete $3; }
- ;
+ ;
conjunction
- : negation
+ : negation
| conjunction YRE_AND negation { ConvertToFSM(rlex.Encoding(), ($$ = $1)) &= ConvertToFSM(rlex.Encoding(), $3); delete $2; delete $3; }
- ;
+ ;
negation
- : concatenation
+ : concatenation
| YRE_NOT concatenation { ConvertToFSM(rlex.Encoding(), ($$ = $2)).Complement(); delete $1; }
- ;
+ ;
concatenation
- : { $$ = new Any(Fsm()); }
- | concatenation iteration
- {
- Fsm& a = ConvertToFSM(rlex.Encoding(), ($$ = $1));
- if ($2->IsA<Term::CharacterRange>() && !$2->As<Term::CharacterRange>().second)
- AppendRange(rlex.Encoding(), a, $2->As<Term::CharacterRange>());
- else if ($2->IsA<Term::DotTag>())
- rlex.Encoding().AppendDot(a);
- else
- a += ConvertToFSM(rlex.Encoding(), $2);
- delete $2;
- }
- ;
+ : { $$ = new Any(Fsm()); }
+ | concatenation iteration
+ {
+ Fsm& a = ConvertToFSM(rlex.Encoding(), ($$ = $1));
+ if ($2->IsA<Term::CharacterRange>() && !$2->As<Term::CharacterRange>().second)
+ AppendRange(rlex.Encoding(), a, $2->As<Term::CharacterRange>());
+ else if ($2->IsA<Term::DotTag>())
+ rlex.Encoding().AppendDot(a);
+ else
+ a += ConvertToFSM(rlex.Encoding(), $2);
+ delete $2;
+ }
+ ;
iteration
- : term
- | term YRE_COUNT
- {
- Fsm& orig = ConvertToFSM(rlex.Encoding(), $1);
- $$ = new Any(orig);
- Fsm& cur = $$->As<Fsm>();
- const Term::RepetitionCount& repc = $2->As<Term::RepetitionCount>();
-
-
- if (repc.first == 0 && repc.second == 1) {
- Fsm empty;
- cur |= empty;
- } else if (repc.first == 0 && repc.second == Inf) {
- cur.Iterate();
- } else if (repc.first == 1 && repc.second == Inf) {
- cur += *cur;
- } else {
- cur *= repc.first;
- if (repc.second == Inf) {
- cur += *orig;
- } else if (repc.second != repc.first) {
- cur += (orig | Fsm()) * (repc.second - repc.first);
- }
- }
+ : term
+ | term YRE_COUNT
+ {
+ Fsm& orig = ConvertToFSM(rlex.Encoding(), $1);
+ $$ = new Any(orig);
+ Fsm& cur = $$->As<Fsm>();
+ const Term::RepetitionCount& repc = $2->As<Term::RepetitionCount>();
+
+
+ if (repc.first == 0 && repc.second == 1) {
+ Fsm empty;
+ cur |= empty;
+ } else if (repc.first == 0 && repc.second == Inf) {
+ cur.Iterate();
+ } else if (repc.first == 1 && repc.second == Inf) {
+ cur += *cur;
+ } else {
+ cur *= repc.first;
+ if (repc.second == Inf) {
+ cur += *orig;
+ } else if (repc.second != repc.first) {
+ cur += (orig | Fsm()) * (repc.second - repc.first);
+ }
+ }
rlex.Parenthesized($$->As<Fsm>());
- delete $1;
- delete $2;
- }
- ;
+ delete $1;
+ delete $2;
+ }
+ ;
term
- : YRE_LETTERS
- | YRE_DOT
- | '^'
- | '$'
+ : YRE_LETTERS
+ | YRE_DOT
+ | '^'
+ | '$'
| '(' alternative ')' { $$ = $2; rlex.Parenthesized($$->As<Fsm>()); delete $1; delete $3; }
- ;
+ ;
%%
@@ -181,60 +181,60 @@ void AppendRange(const Encoding& encoding, Fsm& a, const Term::CharacterRange& c
TVector<ystring> strings;
for (auto&& i : cr.first) {
- ystring s;
+ ystring s;
for (auto&& j : i) {
ystring c = encoding.ToLocal(j);
- if (c.empty()) {
- s.clear();
- break;
- } else
+ if (c.empty()) {
+ s.clear();
+ break;
+ } else
s += encoding.ToLocal(j);
- }
- if (!s.empty())
- strings.push_back(s);
- }
- if (strings.empty())
- // Strings accepted by this FSM are not representable in the current encoding.
- // Hence, FSM will accept nothing, and we simply can clear it.
- a = Fsm::MakeFalse();
- else
- a.AppendStrings(strings);
+ }
+ if (!s.empty())
+ strings.push_back(s);
+ }
+ if (strings.empty())
+ // Strings accepted by this FSM are not representable in the current encoding.
+ // Hence, FSM will accept nothing, and we simply can clear it.
+ a = Fsm::MakeFalse();
+ else
+ a.AppendStrings(strings);
}
Fsm& ConvertToFSM(const Encoding& encoding, Any* any)
{
- if (any->IsA<Fsm>())
- return any->As<Fsm>();
-
- Any ret = Fsm();
- Fsm& a = ret.As<Fsm>();
-
- if (any->IsA<Term::DotTag>()) {
- encoding.AppendDot(a);
- } else if (any->IsA<Term::BeginTag>()) {
- a.AppendSpecial(BeginMark);
- } else if (any->IsA<Term::EndTag>()) {
- a.AppendSpecial(EndMark);
- } else {
- Term::CharacterRange cr = any->As<Term::CharacterRange>();
- AppendRange(encoding, a, cr);
- if (cr.second) {
- Fsm x;
- encoding.AppendDot(x);
- x.Complement();
- a |= x;
- a.Complement();
- a.RemoveDeadEnds();
- }
- }
- any->Swap(ret);
- return a;
+ if (any->IsA<Fsm>())
+ return any->As<Fsm>();
+
+ Any ret = Fsm();
+ Fsm& a = ret.As<Fsm>();
+
+ if (any->IsA<Term::DotTag>()) {
+ encoding.AppendDot(a);
+ } else if (any->IsA<Term::BeginTag>()) {
+ a.AppendSpecial(BeginMark);
+ } else if (any->IsA<Term::EndTag>()) {
+ a.AppendSpecial(EndMark);
+ } else {
+ Term::CharacterRange cr = any->As<Term::CharacterRange>();
+ AppendRange(encoding, a, cr);
+ if (cr.second) {
+ Fsm x;
+ encoding.AppendDot(x);
+ x.Complement();
+ a |= x;
+ a.Complement();
+ a.RemoveDeadEnds();
+ }
+ }
+ any->Swap(ret);
+ return a;
}
}
namespace Pire {
- namespace Impl {
+ namespace Impl {
int yre_parse(Pire::Lexer& rlex)
{
int rc = yyparse(rlex);
@@ -243,5 +243,5 @@ namespace Pire {
throw Error(rlex.GetError());
return rc;
}
- }
+ }
}
diff --git a/contrib/tools/bison/bison/data/README b/contrib/tools/bison/bison/data/README
index 842c004186..65c7d20c22 100644
--- a/contrib/tools/bison/bison/data/README
+++ b/contrib/tools/bison/bison/data/README
@@ -1,70 +1,70 @@
--*- outline -*-
-
-This directory contains data needed by Bison.
-
-* Skeletons
-Bison skeletons: the general shapes of the different parser kinds,
-that are specialized for specific grammars by the bison program.
-
-Currently, the supported skeletons are:
-
-- yacc.c
- It used to be named bison.simple: it corresponds to C Yacc
- compatible LALR(1) parsers.
-
-- lalr1.cc
- Produces a C++ parser class.
-
-- lalr1.java
- Produces a Java parser class.
-
-- glr.c
- A Generalized LR C parser based on Bison's LALR(1) tables.
-
-- glr.cc
- A Generalized LR C++ parser. Actually a C++ wrapper around glr.c.
-
-These skeletons are the only ones supported by the Bison team.
-Because the interface between skeletons and the bison program is not
-finished, *we are not bound to it*. In particular, Bison is not
-mature enough for us to consider that "foreign skeletons" are
-supported.
-
-* m4sugar
-This directory contains M4sugar, sort of an extended library for M4,
-which is used by Bison to instantiate the skeletons.
-
-* xslt
-This directory contains XSLT programs that transform Bison's XML output
-into various formats.
-
-- bison.xsl
- A library of routines used by the other XSLT programs.
-
-- xml2dot.xsl
- Conversion into GraphViz's dot format.
-
-- xml2text.xsl
- Conversion into text.
-
-- xml2xhtml.xsl
- Conversion into XHTML.
-
------
-
-Copyright (C) 2002, 2008-2013 Free Software Foundation, Inc.
-
-This file is part of GNU Bison.
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
+-*- outline -*-
+
+This directory contains data needed by Bison.
+
+* Skeletons
+Bison skeletons: the general shapes of the different parser kinds,
+that are specialized for specific grammars by the bison program.
+
+Currently, the supported skeletons are:
+
+- yacc.c
+ It used to be named bison.simple: it corresponds to C Yacc
+ compatible LALR(1) parsers.
+
+- lalr1.cc
+ Produces a C++ parser class.
+
+- lalr1.java
+ Produces a Java parser class.
+
+- glr.c
+ A Generalized LR C parser based on Bison's LALR(1) tables.
+
+- glr.cc
+ A Generalized LR C++ parser. Actually a C++ wrapper around glr.c.
+
+These skeletons are the only ones supported by the Bison team.
+Because the interface between skeletons and the bison program is not
+finished, *we are not bound to it*. In particular, Bison is not
+mature enough for us to consider that "foreign skeletons" are
+supported.
+
+* m4sugar
+This directory contains M4sugar, sort of an extended library for M4,
+which is used by Bison to instantiate the skeletons.
+
+* xslt
+This directory contains XSLT programs that transform Bison's XML output
+into various formats.
+
+- bison.xsl
+ A library of routines used by the other XSLT programs.
+
+- xml2dot.xsl
+ Conversion into GraphViz's dot format.
+
+- xml2text.xsl
+ Conversion into text.
+
+- xml2xhtml.xsl
+ Conversion into XHTML.
+
+-----
+
+Copyright (C) 2002, 2008-2013 Free Software Foundation, Inc.
+
+This file is part of GNU Bison.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/contrib/tools/bison/bison/data/bison.m4 b/contrib/tools/bison/bison/data/bison.m4
index ca27159c87..671083ae11 100644
--- a/contrib/tools/bison/bison/data/bison.m4
+++ b/contrib/tools/bison/bison/data/bison.m4
@@ -1,1063 +1,1063 @@
- -*- Autoconf -*-
-
-# Language-independent M4 Macros for Bison.
-
-# Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-## ---------------- ##
-## Identification. ##
-## ---------------- ##
-
-# b4_copyright(TITLE, [YEARS])
-# ----------------------------
-# If YEARS are not defined, use b4_copyright_years.
-m4_define([b4_copyright],
-[b4_comment([A Bison parser, made by GNU Bison b4_version.])
-
-b4_comment([$1
-
-]m4_dquote(m4_text_wrap([Copyright (C)
-]m4_ifval([$2], [[$2]], [m4_defn([b4_copyright_years])])[
-Free Software Foundation, Inc.]))[
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.])
-
-b4_comment([As a special exception, you may create a larger work that contains
-part or all of the Bison parser skeleton and distribute that work
-under terms of your choice, so long as that work isn't itself a
-parser generator using the skeleton or a modified version thereof
-as a parser skeleton. Alternatively, if you modify or redistribute
-the parser skeleton itself, you may (at your option) remove this
-special exception, which will cause the skeleton and the resulting
-Bison output files to be licensed under the GNU General Public
-License without this special exception.
-
-This special exception was added by the Free Software Foundation in
-version 2.2 of Bison.])])
-
-
-## -------- ##
-## Output. ##
-## -------- ##
-
-# b4_output_begin(FILE)
-# ---------------------
-# Enable output, i.e., send to diversion 0, expand after "#", and
-# generate the tag to output into FILE. Must be followed by EOL.
-m4_define([b4_output_begin],
-[m4_changecom()
-m4_divert_push(0)dnl
-@output(m4_unquote([$1])@)@dnl
-])
-
-
-# b4_output_end()
-# ---------------
-# Output nothing, restore # as comment character (no expansions after #).
-m4_define([b4_output_end],
-[m4_divert_pop(0)
-m4_changecom([#])
-])
-
-
-# b4_divert_kill(CODE)
-# --------------------
-# Expand CODE for its side effects, discard its output.
-m4_define([b4_divert_kill],
-[m4_divert_text([KILL], [$1])])
-
-
-# b4_define_silent(MACRO, CODE)
-# -----------------------------
-# Same as m4_define, but throw away the expansion of CODE.
-m4_define([b4_define_silent],
-[m4_define([$1], [b4_divert_kill([$2])])])
-
-
-## ---------------- ##
-## Error handling. ##
-## ---------------- ##
-
-# The following error handling macros print error directives that should not
-# become arguments of other macro invocations since they would likely then be
-# mangled. Thus, they print to stdout directly.
-
-# b4_cat(TEXT)
-# ------------
-# Write TEXT to stdout. Precede the final newline with an @ so that it's
-# escaped. For example:
-#
-# b4_cat([[@complain(invalid input@)]])
-m4_define([b4_cat],
-[m4_syscmd([cat <<'_m4eof'
-]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@
-_m4eof
-])dnl
-m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
-
-# b4_error(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
-# -------------------------------------------------------
-# Write @KIND(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
-#
-# For example:
-#
-# b4_error([[complain]], [[input.y:2.3]], [[input.y:5.4]],
-# [[invalid %s]], [[foo]])
-m4_define([b4_error],
-[b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl
-[m4_if([$#], [4], [],
- [m4_foreach([b4_arg],
- m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))),
- [[@,]b4_arg])])[@)]])])
-
-# b4_warn(FORMAT, [ARG1], [ARG2], ...)
-# ------------------------------------
-# Write @warn(FORMAT@,ARG1@,ARG2@,...@) to stdout.
-#
-# For example:
-#
-# b4_warn([[invalid value for '%s': %s]], [[foo]], [[3]])
-#
-# As a simple test suite, this:
-#
-# m4_divert(-1)
-# m4_define([asdf], [ASDF])
-# m4_define([fsa], [FSA])
-# m4_define([fdsa], [FDSA])
-# b4_warn_at([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
-# b4_warn_at([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
-# b4_warn_at()
-# b4_warn_at(1)
-# b4_warn_at(1, 2)
-#
-# Should produce this without newlines:
-#
-# @warn_at([asdf), asdf]@,@,@,[fsa), fsa]@,[fdsa), fdsa]@)
-# @warn(asdf), asdf@,@,@,fsa), fsa@,fdsa), fdsa@)
-# @warn(@)
-# @warn(1@)
-# @warn(1@,2@)
-m4_define([b4_warn],
-[b4_error([[warn]], [], [], $@)])
-
-# b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
-# ---------------------------------------------------
-# Write @warn(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
-#
-# For example:
-#
-# b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]])
-m4_define([b4_warn_at],
-[b4_error([[warn]], $@)])
-
-# b4_complain(FORMAT, [ARG1], [ARG2], ...)
-# ----------------------------------------
-# Bounce to b4_complain_at.
-#
-# See b4_warn example.
-m4_define([b4_complain],
-[b4_error([[complain]], [], [], $@)])
-
-# b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
-# -------------------------------------------------------
-# Write @complain(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
-#
-# See b4_warn_at example.
-m4_define([b4_complain_at],
-[b4_error([[complain]], $@)])
-
-# b4_fatal(FORMAT, [ARG1], [ARG2], ...)
-# -------------------------------------
-# Bounce to b4_fatal_at.
-#
-# See b4_warn example.
-m4_define([b4_fatal],
-[b4_error([[fatal]], [], [], $@)dnl
-m4_exit(1)])
-
-# b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
-# ----------------------------------------------------
-# Write @fatal(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
-#
-# See b4_warn_at example.
-m4_define([b4_fatal_at],
-[b4_error([[fatal]], $@)dnl
-m4_exit(1)])
-
-
-## ------------ ##
-## Data Types. ##
-## ------------ ##
-
-# b4_ints_in(INT1, INT2, LOW, HIGH)
-# ---------------------------------
-# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
-m4_define([b4_ints_in],
-[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
-
-
-# b4_subtract(LHS, RHS)
-# ---------------------
-# Evaluate LHS - RHS if they are integer literals, otherwise expand
-# to (LHS) - (RHS).
-m4_define([b4_subtract],
-[m4_bmatch([$1$2], [^[0123456789]*$],
- [m4_eval([$1 - $2])],
- [($1) - ($2)])])
-
-# b4_join(ARG1, ...)
-# _b4_join(ARG1, ...)
-# -------------------
-# Join with comma, skipping empty arguments.
-# b4_join calls itself recursively until it sees the first non-empty
-# argument, then calls _b4_join which prepends each non-empty argument
-# with a comma.
-m4_define([b4_join],
-[m4_if([$#$1],
- [1], [],
- [m4_ifval([$1],
- [$1[]_$0(m4_shift($@))],
- [$0(m4_shift($@))])])])
-
-# _b4_join(ARGS1, ...)
-# --------------------
-m4_define([_b4_join],
-[m4_if([$#$1],
- [1], [],
- [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])])
-
-
-
-
-# b4_integral_parser_tables_map(MACRO)
-# -------------------------------------
-# Map MACRO on all the integral tables. MACRO is expected to have
-# the signature MACRO(TABLE-NAME, CONTENT, COMMENT).
-m4_define([b4_integral_parser_tables_map],
-[$1([pact], [b4_pact],
- [[YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
-STATE-NUM.]])
-
-$1([defact], [b4_defact],
- [[YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
-Performed when YYTABLE does not specify something else to do. Zero
-means the default is an error.]])
-
-$1([pgoto], [b4_pgoto], [[YYPGOTO[NTERM-NUM].]])
-
-$1([defgoto], [b4_defgoto], [[YYDEFGOTO[NTERM-NUM].]])
-
-$1([table], [b4_table],
- [[YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
-positive, shift that token. If negative, reduce the rule whose
-number is the opposite. If YYTABLE_NINF, syntax error.]])
-
-$1([check], [b4_check])
-
-$1([stos], [b4_stos],
- [[YYSTOS[STATE-NUM] -- The (internal number of the) accessing
-symbol of state STATE-NUM.]])
-
-$1([r1], [b4_r1],
- [[YYR1[YYN] -- Symbol number of symbol that rule YYN derives.]])
-
-$1([r2], [b4_r2],
- [[YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.]])
-])
-
-
-# b4_parser_tables_declare
-# b4_parser_tables_define
-# ------------------------
-# Define/declare the (deterministic) parser tables.
-m4_define([b4_parser_tables_declare],
-[b4_integral_parser_tables_map([b4_integral_parser_table_declare])])
-
-m4_define([b4_parser_tables_define],
-[b4_integral_parser_tables_map([b4_integral_parser_table_define])])
-
-
-
-## ------------------ ##
-## Decoding options. ##
-## ------------------ ##
-
-# b4_flag_if(FLAG, IF-TRUE, IF-FALSE)
-# -----------------------------------
-# Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail.
-m4_define([b4_flag_if],
-[m4_case(b4_$1_flag,
- [0], [$3],
- [1], [$2],
- [m4_fatal([invalid $1 value: ]b4_$1_flag)])])
-
-
-# b4_define_flag_if(FLAG)
-# -----------------------
-# Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the
-# value of the Boolean FLAG.
-m4_define([b4_define_flag_if],
-[_b4_define_flag_if($[1], $[2], [$1])])
-
-# _b4_define_flag_if($1, $2, FLAG)
-# --------------------------------
-# Work around the impossibility to define macros inside macros,
-# because issuing '[$1]' is not possible in M4. GNU M4 should provide
-# $$1 a la M5/TeX.
-m4_define([_b4_define_flag_if],
-[m4_if([$1$2], $[1]$[2], [],
- [m4_fatal([$0: Invalid arguments: $@])])dnl
-m4_define([b4_$3_if],
- [b4_flag_if([$3], [$1], [$2])])])
-
-
-# b4_FLAG_if(IF-TRUE, IF-FALSE)
-# -----------------------------
-# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
-b4_define_flag_if([defines]) # Whether headers are requested.
-b4_define_flag_if([glr]) # Whether a GLR parser is requested.
-b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
-b4_define_flag_if([token_table]) # Whether yytoken_table is demanded.
-b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
-
-
-## --------- ##
-## Symbols. ##
-## --------- ##
-
-# In order to unify the handling of the various aspects of symbols
-# (tag, type_name, whether terminal, etc.), bison.exe defines one
-# macro per (token, field), where field can has_id, id, etc.: see
-# src/output.c:prepare_symbols_definitions().
-#
-# The various FIELDS are:
-#
-# - has_id: 0 or 1.
-# Whether the symbol has an id.
-# - id: string
-# If has_id, the id. Guaranteed to be usable as a C identifier.
-# Prefixed by api.token.prefix if defined.
-# - tag: string.
-# A representat of the symbol. Can be 'foo', 'foo.id', '"foo"' etc.
-# - user_number: integer
-# The assigned (external) number as used by yylex.
-# - is_token: 0 or 1
-# Whether this is a terminal symbol.
-# - number: integer
-# The internalized number (used after yytranslate).
-# - has_type: 0, 1
-# Whether has a semantic value.
-# - type_tag: string
-# When api.value.type=union, the generated name for the union member.
-# yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc.
-# - type
-# If it has a semantic value, its type tag, or, if variant are used,
-# its type.
-# In the case of api.value.type=union, type is the real type (e.g. int).
-# - has_printer: 0, 1
-# - printer: string
-# - printer_file: string
-# - printer_line: integer
-# If the symbol has a printer, everything about it.
-# - has_destructor, destructor, destructor_file, destructor_line
-# Likewise.
-#
-# The following macros provide access to these values.
-
-# b4_symbol_(NUM, FIELD)
-# ----------------------
-# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
-# undefined.
-m4_define([b4_symbol_],
-[m4_indir([b4_symbol($1, $2)])])
-
-
-# b4_symbol(NUM, FIELD)
-# ---------------------
-# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
-# undefined. If FIELD = id, prepend the token prefix.
-m4_define([b4_symbol],
-[m4_case([$2],
- [id], [m4_do([b4_percent_define_get([api.token.prefix])],
- [b4_symbol_([$1], [id])])],
- [b4_symbol_($@)])])
-
-
-# b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
-# -------------------------------------------
-# If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
-# Otherwise an error.
-m4_define([b4_symbol_if],
-[m4_case(b4_symbol([$1], [$2]),
- [1], [$3],
- [0], [$4],
- [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
-
-
-# b4_symbol_tag_comment(SYMBOL-NUM)
-# ---------------------------------
-# Issue a comment giving the tag of symbol NUM.
-m4_define([b4_symbol_tag_comment],
-[b4_comment([b4_symbol([$1], [tag])])
-])
-
-
-# b4_symbol_action_location(SYMBOL-NUM, KIND)
-# -------------------------------------------
-# Report the location of the KIND action as FILE:LINE.
-m4_define([b4_symbol_action_location],
-[b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])])
-
-
-# b4_symbol_action(SYMBOL-NUM, KIND)
-# ----------------------------------
-# Run the action KIND (destructor or printer) for SYMBOL-NUM.
-# Same as in C, but using references instead of pointers.
-m4_define([b4_symbol_action],
-[b4_symbol_if([$1], [has_$2],
-[b4_dollar_pushdef([(*yyvaluep)],
- b4_symbol_if([$1], [has_type],
- [m4_dquote(b4_symbol([$1], [type]))]),
- [(*yylocationp)])dnl
- b4_symbol_case_([$1])[]dnl
-b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
- b4_symbol([$1], [$2])
-b4_syncline([@oline@], [@ofile@])
- break;
-
-b4_dollar_popdef[]dnl
-])])
-
-
-# b4_symbol_destructor(SYMBOL-NUM)
-# b4_symbol_printer(SYMBOL-NUM)
-# --------------------------------
-m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
-m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
-
-
-# b4_symbol_actions(KIND, [TYPE = yytype])
-# ----------------------------------------
-# Emit the symbol actions for KIND ("printer" or "destructor").
-# Dispatch on TYPE.
-m4_define([b4_symbol_actions],
-[m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl
-m4_ifval(m4_defn([b4_actions_]),
-[switch (m4_default([$2], [yytype]))
- {
- m4_defn([b4_actions_])
- default:
- break;
- }dnl
-],
-[YYUSE (m4_default([$2], [yytype]));])dnl
-m4_popdef([b4_actions_])dnl
-])
-
-# b4_symbol_case_(SYMBOL-NUM)
-# ---------------------------
-# Issue a "case NUM" for SYMBOL-NUM.
-m4_define([b4_symbol_case_],
-[case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])])
-])
-
-
-# b4_symbol_foreach(MACRO)
-# ------------------------
-# Invoke MACRO(SYMBOL-NUM) for each SYMBOL-NUM.
-m4_define([b4_symbol_foreach],
- [m4_map([$1], m4_defn([b4_symbol_numbers]))])
-
-# b4_symbol_map(MACRO)
-# --------------------
-# Return a list (possibly empty elements) of MACRO invoked for each
-# SYMBOL-NUM.
-m4_define([b4_symbol_map],
-[m4_map_args_sep([$1(], [)], [,], b4_symbol_numbers)])
-
-
-# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
-# -------------------------------------------
-# Whether NUM denotes a token that has an exported definition (i.e.,
-# shows in enum yytokentype).
-m4_define([b4_token_visible_if],
-[b4_symbol_if([$1], [is_token],
- [b4_symbol_if([$1], [has_id], [$2], [$3])],
- [$3])])
-
-# b4_token_has_definition(NUM)
-# ----------------------------
-# 1 if NUM is visible, nothing otherwise.
-m4_define([b4_token_has_definition],
-[b4_token_visible_if([$1], [1])])
-
-# b4_any_token_visible_if([IF-TRUE], [IF-FALSE])
-# ----------------------------------------------
-# Whether there is a token that needs to be defined.
-m4_define([b4_any_token_visible_if],
-[m4_ifval(b4_symbol_foreach([b4_token_has_definition]),
- [$1], [$2])])
-
-
-# b4_token_format(FORMAT, NUM)
-# ----------------------------
-m4_define([b4_token_format],
-[b4_token_visible_if([$2],
-[m4_quote(m4_format([$1],
- [b4_symbol([$2], [id])],
- [b4_symbol([$2], [user_number])]))])])
-
-
-## ------- ##
-## Types. ##
-## ------- ##
-
-# b4_type_action_(NUMS)
-# ---------------------
-# Run actions for the symbol NUMS that all have the same type-name.
-# Skip NUMS that have no type-name.
-#
-# To specify the action to run, define b4_dollar_dollar(NUMBER,
-# TAG, TYPE).
-m4_define([b4_type_action_],
-[b4_symbol_if([$1], [has_type],
-[m4_map([ b4_symbol_case_], [$@])[]dnl
- b4_dollar_dollar([b4_symbol([$1], [number])],
- [b4_symbol([$1], [tag])],
- [b4_symbol([$1], [type])]);
- break;
-
-])])
-
-# b4_type_foreach(MACRO)
-# ----------------------
-# Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set.
-m4_define([b4_type_foreach],
- [m4_map([$1], m4_defn([b4_type_names]))])
-
-
-
-## ----------- ##
-## Synclines. ##
-## ----------- ##
-
-# b4_basename(NAME)
-# -----------------
-# Similar to POSIX basename; the differences don't matter here.
-# Beware that NAME is not evaluated.
-m4_define([b4_basename],
-[m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])])
-
-
-# b4_syncline(LINE, FILE)
-# -----------------------
-m4_define([b4_syncline],
-[b4_flag_if([synclines],
-[b4_sync_start([$1], [$2]) b4_sync_end([__line__],
- [b4_basename(m4_quote(__file__))])[]dnl
-])])
-
-# b4_sync_start(LINE, FILE)
-# -----------------------
-# Syncline for the new place. Typically a directive for the compiler.
-m4_define([b4_sync_start], [b4_comment([$2:$1])])
-
-# b4_sync_end(LINE, FILE)
-# -----------------------
-# Syncline for the current place, which ends. Typically a comment
-# left for the reader.
-m4_define([b4_sync_end], [b4_comment([$2:$1])])
-
-
-# b4_user_code(USER-CODE)
-# -----------------------
-# Emit code from the user, ending it with synclines.
-m4_define([b4_user_code],
-[$1
-b4_syncline([@oline@], [@ofile@])])
-
-
-# b4_define_user_code(MACRO)
-# --------------------------
-# From b4_MACRO, build b4_user_MACRO that includes the synclines.
-m4_define([b4_define_user_code],
-[m4_define([b4_user_$1],
-[b4_user_code([b4_$1])])])
-
-
-# b4_user_actions
-# b4_user_initial_action
-# b4_user_post_prologue
-# b4_user_pre_prologue
-# b4_user_union_members
-# ----------------------
-# Macros that issue user code, ending with synclines.
-b4_define_user_code([actions])
-b4_define_user_code([initial_action])
-b4_define_user_code([post_prologue])
-b4_define_user_code([pre_prologue])
-b4_define_user_code([union_members])
-
-
-# b4_check_user_names(WHAT, USER-LIST, BISON-NAMESPACE)
-# -----------------------------------------------------
-# Complain if any name of type WHAT is used by the user (as recorded in
-# USER-LIST) but is not used by Bison (as recorded by macros in the
-# namespace BISON-NAMESPACE).
-#
-# USER-LIST must expand to a list specifying all user occurrences of all names
-# of type WHAT. Each item in the list must be a triplet specifying one
-# occurrence: name, start boundary, and end boundary. Empty string names are
-# fine. An empty list is fine.
-#
-# For example, to define b4_foo_user_names to be used for USER-LIST with three
-# name occurrences and with correct quoting:
-#
-# m4_define([b4_foo_user_names],
-# [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]],
-# [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
-# [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
-#
-# The macro BISON-NAMESPACE(bar) must be defined iff the name bar of type WHAT
-# is used by Bison (in the front-end or in the skeleton). Empty string names
-# are fine, but it would be ugly for Bison to actually use one.
-#
-# For example, to use b4_foo_bison_names for BISON-NAMESPACE and define that
-# the names bar and baz are used by Bison:
-#
-# m4_define([b4_foo_bison_names(bar)])
-# m4_define([b4_foo_bison_names(baz)])
-#
-# To invoke b4_check_user_names with TYPE foo, with USER-LIST
-# b4_foo_user_names, with BISON-NAMESPACE b4_foo_bison_names, and with correct
-# quoting:
-#
-# b4_check_user_names([[foo]], [b4_foo_user_names],
-# [[b4_foo_bison_names]])
-m4_define([b4_check_user_names],
-[m4_foreach([b4_occurrence], $2,
-[m4_pushdef([b4_occurrence], b4_occurrence)dnl
-m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
-m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
-m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
-m4_ifndef($3[(]m4_quote(b4_user_name)[)],
- [b4_complain_at([b4_start], [b4_end],
- [[%s '%s' is not used]],
- [$1], [b4_user_name])])[]dnl
-m4_popdef([b4_occurrence])dnl
-m4_popdef([b4_user_name])dnl
-m4_popdef([b4_start])dnl
-m4_popdef([b4_end])dnl
-])])
-
-
-
-## --------------------- ##
-## b4_percent_define_*. ##
-## --------------------- ##
-
-
-# b4_percent_define_use(VARIABLE)
-# -------------------------------
-# Declare that VARIABLE was used.
-m4_define([b4_percent_define_use],
-[m4_define([b4_percent_define_bison_variables(]$1[)])dnl
-])
-
-# b4_percent_define_get(VARIABLE, [DEFAULT])
-# ------------------------------------------
-# Mimic muscle_percent_define_get in ../src/muscle-tab.h. That is, if
-# the %define variable VARIABLE is defined, emit its value. Contrary
-# to its C counterpart, return DEFAULT otherwise. Also, record
-# Bison's usage of VARIABLE by defining
-# b4_percent_define_bison_variables(VARIABLE).
-#
-# For example:
-#
-# b4_percent_define_get([[foo]])
-m4_define([b4_percent_define_get],
-[b4_percent_define_use([$1])dnl
-b4_percent_define_ifdef_([$1],
- [m4_indir([b4_percent_define(]$1[)])],
- [$2])])
-
-# b4_percent_define_get_loc(VARIABLE)
-# -----------------------------------
-# Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly. That is,
-# if the %define variable VARIABLE is undefined, complain fatally since that's
-# a Bison or skeleton error. Otherwise, return its definition location in a
-# form approriate for the first two arguments of b4_warn_at, b4_complain_at, or
-# b4_fatal_at. Don't record this as a Bison usage of VARIABLE as there's no
-# reason to suspect that the user-supplied value has yet influenced the output.
-#
-# For example:
-#
-# b4_complain_at(b4_percent_define_get_loc([[foo]]), [[invalid foo]])
-m4_define([b4_percent_define_get_loc],
-[m4_ifdef([b4_percent_define_loc(]$1[)],
- [m4_pushdef([b4_loc], m4_indir([b4_percent_define_loc(]$1[)]))dnl
-b4_loc[]dnl
-m4_popdef([b4_loc])],
- [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
-
-# b4_percent_define_get_kind(VARIABLE)
-# ------------------------------------
-# Get the kind (code, keyword, string) of VARIABLE, i.e., how its
-# value was defined (braces, not delimiters, quotes).
-#
-# If the %define variable VARIABLE is undefined, complain fatally
-# since that's a Bison or skeleton error. Don't record this as a
-# Bison usage of VARIABLE as there's no reason to suspect that the
-# user-supplied value has yet influenced the output.
-m4_define([b4_percent_define_get_kind],
-[m4_ifdef([b4_percent_define_kind(]$1[)],
- [m4_indir([b4_percent_define_kind(]$1[)])],
- [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
-
-# b4_percent_define_get_syncline(VARIABLE)
-# ----------------------------------------
-# Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly.
-# That is, if the %define variable VARIABLE is undefined, complain fatally
-# since that's a Bison or skeleton error. Otherwise, return its definition
-# location as a b4_syncline invocation. Don't record this as a Bison usage of
-# VARIABLE as there's no reason to suspect that the user-supplied value has yet
-# influenced the output.
-#
-# For example:
-#
-# b4_percent_define_get_syncline([[foo]])
-m4_define([b4_percent_define_get_syncline],
-[m4_ifdef([b4_percent_define_syncline(]$1[)],
- [m4_indir([b4_percent_define_syncline(]$1[)])],
- [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
-
-# b4_percent_define_ifdef_(VARIABLE, IF-TRUE, [IF-FALSE])
-# ------------------------------------------------------
-# If the %define variable VARIABLE is defined, expand IF-TRUE, else expand
-# IF-FALSE. Don't record usage of VARIABLE.
-#
-# For example:
-#
-# b4_percent_define_ifdef_([[foo]], [[it's defined]], [[it's undefined]])
-m4_define([b4_percent_define_ifdef_],
-[m4_ifdef([b4_percent_define(]$1[)],
- [$2],
- [$3])])
-
-# b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
-# ------------------------------------------------------
-# Mimic muscle_percent_define_ifdef in ../src/muscle-tab.h exactly. That is,
-# if the %define variable VARIABLE is defined, expand IF-TRUE, else expand
-# IF-FALSE. Also, record Bison's usage of VARIABLE by defining
-# b4_percent_define_bison_variables(VARIABLE).
-#
-# For example:
-#
-# b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]])
-m4_define([b4_percent_define_ifdef],
-[b4_percent_define_ifdef_([$1],
- [b4_percent_define_use([$1])$2],
- [$3])])
-
-
-## --------- ##
-## Options. ##
-## --------- ##
-
-
-# b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE])
-# --------------------------------------------------------
-# Mimic muscle_percent_define_flag_if in ../src/muscle-tab.h exactly. That is,
-# if the %define variable VARIABLE is defined to "" or "true", expand IF-TRUE.
-# If it is defined to "false", expand IF-FALSE. Complain if it is undefined
-# (a Bison or skeleton error since the default value should have been set
-# already) or defined to any other value (possibly a user error). Also, record
-# Bison's usage of VARIABLE by defining
-# b4_percent_define_bison_variables(VARIABLE).
-#
-# For example:
-#
-# b4_percent_define_flag_if([[foo]], [[it's true]], [[it's false]])
-m4_define([b4_percent_define_flag_if],
-[b4_percent_define_ifdef([$1],
- [m4_case(b4_percent_define_get([$1]),
- [], [$2], [true], [$2], [false], [$3],
- [m4_expand_once([b4_complain_at(b4_percent_define_get_loc([$1]),
- [[invalid value for %%define Boolean variable '%s']],
- [$1])],
- [[b4_percent_define_flag_if($1)]])])],
- [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
-
-
-# b4_percent_define_default(VARIABLE, DEFAULT, [KIND = keyword])
-# --------------------------------------------------------------
-# Mimic muscle_percent_define_default in ../src/muscle-tab.h exactly. That is,
-# if the %define variable VARIABLE is undefined, set its value to DEFAULT.
-# Don't record this as a Bison usage of VARIABLE as there's no reason to
-# suspect that the value has yet influenced the output.
-#
-# For example:
-#
-# b4_percent_define_default([[foo]], [[default value]])
-m4_define([b4_percent_define_default],
-[b4_percent_define_ifdef_([$1], [],
- [m4_define([b4_percent_define(]$1[)], [$2])dnl
- m4_define([b4_percent_define_kind(]$1[)],
- [m4_default([$3], [keyword])])dnl
- m4_define([b4_percent_define_loc(]$1[)],
- [[[[<skeleton default value>:-1.-1]],
- [[<skeleton default value>:-1.-1]]]])dnl
- m4_define([b4_percent_define_syncline(]$1[)], [[]])])])
-
-
-# b4_percent_define_if_define(NAME, [VARIABLE = NAME])
-# ----------------------------------------------------
-# Define b4_NAME_if that executes its $1 or $2 depending whether
-# VARIABLE was %defined. The characters '.' and `-' in VARIABLE are mapped
-# to '_'.
-m4_define([b4_percent_define_if_define_],
-[m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
- [b4_percent_define_flag_if(m4_default([$2], [$1]),
- [$3], [$4])])])
-m4_define([b4_percent_define_if_define],
-[b4_percent_define_default([m4_default([$2], [$1])], [[false]])
-b4_percent_define_if_define_([$1], [$2], $[1], $[2])])
-
-
-# b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain])
-# ---------------------------------------------------------------------
-m4_define([b4_percent_define_check_kind],
-[b4_percent_define_ifdef_([$1],
- [m4_if(b4_percent_define_get_kind([$1]), [$2], [],
- [b4_error([m4_default([$3], [complain])],
- b4_percent_define_get_loc([$1]),
- [m4_case([$2],
- [code], [[%%define variable '%s' requires '{...}' values]],
- [keyword], [[%%define variable '%s' requires keyword values]],
- [string], [[%%define variable '%s' requires '"..."' values]])],
- [$1])])])dnl
-])
-
-
-# b4_percent_define_check_values(VALUES)
-# --------------------------------------
-# Mimic muscle_percent_define_check_values in ../src/muscle-tab.h exactly
-# except that the VALUES structure is more appropriate for M4. That is, VALUES
-# is a list of sublists of strings. For each sublist, the first string is the
-# name of a %define variable, and all remaining strings in that sublist are the
-# valid values for that variable. Complain if such a variable is undefined (a
-# Bison error since the default value should have been set already) or defined
-# to any other value (possibly a user error). Don't record this as a Bison
-# usage of the variable as there's no reason to suspect that the value has yet
-# influenced the output.
-#
-# For example:
-#
-# b4_percent_define_check_values([[[[foo]], [[foo-value1]], [[foo-value2]]]],
-# [[[[bar]], [[bar-value1]]]])
-m4_define([b4_percent_define_check_values],
-[m4_foreach([b4_sublist], m4_quote($@),
- [_b4_percent_define_check_values(b4_sublist)])])
-
-m4_define([_b4_percent_define_check_values],
-[b4_percent_define_ifdef_([$1],
- [b4_percent_define_check_kind(]$1[, [keyword], [deprecated])dnl
- m4_pushdef([b4_good_value], [0])dnl
- m4_if($#, 1, [],
- [m4_foreach([b4_value], m4_dquote(m4_shift($@)),
- [m4_if(m4_indir([b4_percent_define(]$1[)]), b4_value,
- [m4_define([b4_good_value], [1])])])])dnl
- m4_if(b4_good_value, [0],
- [b4_complain_at(b4_percent_define_get_loc([$1]),
- [[invalid value for %%define variable '%s': '%s']],
- [$1],
- m4_dquote(m4_indir([b4_percent_define(]$1[)])))
- m4_foreach([b4_value], m4_dquote(m4_shift($@)),
- [b4_error([[note]], b4_percent_define_get_loc([$1]), []
- [[accepted value: '%s']],
- m4_dquote(b4_value))])])dnl
- m4_popdef([b4_good_value])],
- [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
-
-# b4_percent_code_get([QUALIFIER])
-# --------------------------------
-# If any %code blocks for QUALIFIER are defined, emit them beginning with a
-# comment and ending with synclines and a newline. If QUALIFIER is not
-# specified or empty, do this for the unqualified %code blocks. Also, record
-# Bison's usage of QUALIFIER (if specified) by defining
-# b4_percent_code_bison_qualifiers(QUALIFIER).
-#
-# For example, to emit any unqualified %code blocks followed by any %code
-# blocks for the qualifier foo:
-#
-# b4_percent_code_get
-# b4_percent_code_get([[foo]])
-m4_define([b4_percent_code_get],
-[m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl
-m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
-m4_ifdef(b4_macro_name,
-[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
- [["%code ]$1["]])[ blocks.]])
-b4_user_code([m4_indir(b4_macro_name)])
-])dnl
-m4_popdef([b4_macro_name])])
-
-# b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE])
-# -----------------------------------------------------
-# If any %code blocks for QUALIFIER (or unqualified %code blocks if
-# QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE.
-# Also, record Bison's usage of QUALIFIER (if specified) by defining
-# b4_percent_code_bison_qualifiers(QUALIFIER).
-m4_define([b4_percent_code_ifdef],
-[m4_ifdef([b4_percent_code(]$1[)],
- [m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])$2],
- [$3])])
-
-
-## ------------------ ##
-## Common variables. ##
-## ------------------ ##
-
-
-# b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
-# b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT])
-# b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT])
-# ----------------------------------------------
-b4_percent_define_if_define([token_ctor], [api.token.constructor])
-b4_percent_define_if_define([locations]) # Whether locations are tracked.
-b4_percent_define_if_define([parse.assert])
-b4_percent_define_if_define([parse.trace])
-
-
-# b4_bison_locations_if([IF-TRUE])
-# --------------------------------
-# Expand IF-TRUE if using locations, and using the default location
-# type.
-m4_define([b4_bison_locations_if],
-[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
-
-
-# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT])
-# ------------------------------------------------------
-# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and
-# b4_error_verbose_flag.
-b4_percent_define_default([[parse.error]], [[simple]])
-b4_percent_define_check_values([[[[parse.error]],
- [[simple]], [[verbose]]]])
-m4_define([b4_error_verbose_flag],
- [m4_case(b4_percent_define_get([[parse.error]]),
- [simple], [[0]],
- [verbose], [[1]])])
-b4_define_flag_if([error_verbose])
-
-# yytoken_table is needed to support verbose errors.
-b4_error_verbose_if([m4_define([b4_token_table_flag], [1])])
-
-
-# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
-# ----------------------------------------------
-b4_percent_define_if_define([variant])
-m4_define([b4_variant_flag], [[0]])
-b4_percent_define_ifdef([[api.value.type]],
- [m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword],
- [m4_case(b4_percent_define_get([[api.value.type]]), [variant],
- [m4_define([b4_variant_flag], [[1]])])])])
-b4_define_flag_if([variant])
-
-
-## ----------------------------------------------------------- ##
-## After processing the skeletons, check that all the user's ##
-## %define variables and %code qualifiers were used by Bison. ##
-## ----------------------------------------------------------- ##
-
-m4_define([b4_check_user_names_wrap],
-[m4_ifdef([b4_percent_]$1[_user_]$2[s],
- [b4_check_user_names([[%]$1 $2],
- [b4_percent_]$1[_user_]$2[s],
- [[b4_percent_]$1[_bison_]$2[s]])])])
-
-m4_wrap_lifo([
-b4_check_user_names_wrap([[define]], [[variable]])
-b4_check_user_names_wrap([[code]], [[qualifier]])
-])
-
-
-## ---------------- ##
-## Default values. ##
-## ---------------- ##
-
-# m4_define_default([b4_lex_param], []) dnl breaks other skeletons
-m4_define_default([b4_pre_prologue], [])
-m4_define_default([b4_post_prologue], [])
-m4_define_default([b4_epilogue], [])
-m4_define_default([b4_parse_param], [])
-
-# The initial column and line.
-m4_define_default([b4_location_initial_column], [1])
-m4_define_default([b4_location_initial_line], [1])
-
-
-## --------------- ##
-## Sanity checks. ##
-## --------------- ##
-
-# api.location.prefix={...} (Java and C++).
-b4_percent_define_check_kind([api.location.type], [code], [deprecated])
-
-# api.position.prefix={...} (Java).
-b4_percent_define_check_kind([api.position.type], [code], [deprecated])
-
-# api.prefix >< %name-prefix.
-b4_percent_define_check_kind([api.prefix], [code], [deprecated])
-b4_percent_define_ifdef([api.prefix],
-[m4_ifdef([b4_prefix],
-[b4_complain_at(b4_percent_define_get_loc([api.prefix]),
- [['%s' and '%s' cannot be used together]],
- [%name-prefix],
- [%define api.prefix])])])
-
-# api.token.prefix={...}
-# Make it a warning for those who used betas of Bison 3.0.
-b4_percent_define_check_kind([api.token.prefix], [code], [deprecated])
-
-# api.value.type >< %union.
-b4_percent_define_ifdef([api.value.type],
-[m4_ifdef([b4_union_members],
-[b4_complain_at(b4_percent_define_get_loc([api.value.type]),
- [['%s' and '%s' cannot be used together]],
- [%union],
- [%define api.value.type])])])
-
-# api.value.type=union >< %yacc.
-b4_percent_define_ifdef([api.value.type],
-[m4_if(b4_percent_define_get([api.value.type]), [union],
-[b4_yacc_if(dnl
-[b4_complain_at(b4_percent_define_get_loc([api.value.type]),
- [['%s' and '%s' cannot be used together]],
- [%yacc],
- [%define api.value.type "union"])])])])
+ -*- Autoconf -*-
+
+# Language-independent M4 Macros for Bison.
+
+# Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+## ---------------- ##
+## Identification. ##
+## ---------------- ##
+
+# b4_copyright(TITLE, [YEARS])
+# ----------------------------
+# If YEARS are not defined, use b4_copyright_years.
+m4_define([b4_copyright],
+[b4_comment([A Bison parser, made by GNU Bison b4_version.])
+
+b4_comment([$1
+
+]m4_dquote(m4_text_wrap([Copyright (C)
+]m4_ifval([$2], [[$2]], [m4_defn([b4_copyright_years])])[
+Free Software Foundation, Inc.]))[
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.])
+
+b4_comment([As a special exception, you may create a larger work that contains
+part or all of the Bison parser skeleton and distribute that work
+under terms of your choice, so long as that work isn't itself a
+parser generator using the skeleton or a modified version thereof
+as a parser skeleton. Alternatively, if you modify or redistribute
+the parser skeleton itself, you may (at your option) remove this
+special exception, which will cause the skeleton and the resulting
+Bison output files to be licensed under the GNU General Public
+License without this special exception.
+
+This special exception was added by the Free Software Foundation in
+version 2.2 of Bison.])])
+
+
+## -------- ##
+## Output. ##
+## -------- ##
+
+# b4_output_begin(FILE)
+# ---------------------
+# Enable output, i.e., send to diversion 0, expand after "#", and
+# generate the tag to output into FILE. Must be followed by EOL.
+m4_define([b4_output_begin],
+[m4_changecom()
+m4_divert_push(0)dnl
+@output(m4_unquote([$1])@)@dnl
+])
+
+
+# b4_output_end()
+# ---------------
+# Output nothing, restore # as comment character (no expansions after #).
+m4_define([b4_output_end],
+[m4_divert_pop(0)
+m4_changecom([#])
+])
+
+
+# b4_divert_kill(CODE)
+# --------------------
+# Expand CODE for its side effects, discard its output.
+m4_define([b4_divert_kill],
+[m4_divert_text([KILL], [$1])])
+
+
+# b4_define_silent(MACRO, CODE)
+# -----------------------------
+# Same as m4_define, but throw away the expansion of CODE.
+m4_define([b4_define_silent],
+[m4_define([$1], [b4_divert_kill([$2])])])
+
+
+## ---------------- ##
+## Error handling. ##
+## ---------------- ##
+
+# The following error handling macros print error directives that should not
+# become arguments of other macro invocations since they would likely then be
+# mangled. Thus, they print to stdout directly.
+
+# b4_cat(TEXT)
+# ------------
+# Write TEXT to stdout. Precede the final newline with an @ so that it's
+# escaped. For example:
+#
+# b4_cat([[@complain(invalid input@)]])
+m4_define([b4_cat],
+[m4_syscmd([cat <<'_m4eof'
+]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@
+_m4eof
+])dnl
+m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
+
+# b4_error(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------------------------
+# Write @KIND(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# For example:
+#
+# b4_error([[complain]], [[input.y:2.3]], [[input.y:5.4]],
+# [[invalid %s]], [[foo]])
+m4_define([b4_error],
+[b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl
+[m4_if([$#], [4], [],
+ [m4_foreach([b4_arg],
+ m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))),
+ [[@,]b4_arg])])[@)]])])
+
+# b4_warn(FORMAT, [ARG1], [ARG2], ...)
+# ------------------------------------
+# Write @warn(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# For example:
+#
+# b4_warn([[invalid value for '%s': %s]], [[foo]], [[3]])
+#
+# As a simple test suite, this:
+#
+# m4_divert(-1)
+# m4_define([asdf], [ASDF])
+# m4_define([fsa], [FSA])
+# m4_define([fdsa], [FDSA])
+# b4_warn_at([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
+# b4_warn_at([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
+# b4_warn_at()
+# b4_warn_at(1)
+# b4_warn_at(1, 2)
+#
+# Should produce this without newlines:
+#
+# @warn_at([asdf), asdf]@,@,@,[fsa), fsa]@,[fdsa), fdsa]@)
+# @warn(asdf), asdf@,@,@,fsa), fsa@,fdsa), fdsa@)
+# @warn(@)
+# @warn(1@)
+# @warn(1@,2@)
+m4_define([b4_warn],
+[b4_error([[warn]], [], [], $@)])
+
+# b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
+# ---------------------------------------------------
+# Write @warn(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# For example:
+#
+# b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]])
+m4_define([b4_warn_at],
+[b4_error([[warn]], $@)])
+
+# b4_complain(FORMAT, [ARG1], [ARG2], ...)
+# ----------------------------------------
+# Bounce to b4_complain_at.
+#
+# See b4_warn example.
+m4_define([b4_complain],
+[b4_error([[complain]], [], [], $@)])
+
+# b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------------------------
+# Write @complain(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# See b4_warn_at example.
+m4_define([b4_complain_at],
+[b4_error([[complain]], $@)])
+
+# b4_fatal(FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------
+# Bounce to b4_fatal_at.
+#
+# See b4_warn example.
+m4_define([b4_fatal],
+[b4_error([[fatal]], [], [], $@)dnl
+m4_exit(1)])
+
+# b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
+# ----------------------------------------------------
+# Write @fatal(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
+#
+# See b4_warn_at example.
+m4_define([b4_fatal_at],
+[b4_error([[fatal]], $@)dnl
+m4_exit(1)])
+
+
+## ------------ ##
+## Data Types. ##
+## ------------ ##
+
+# b4_ints_in(INT1, INT2, LOW, HIGH)
+# ---------------------------------
+# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
+m4_define([b4_ints_in],
+[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
+
+
+# b4_subtract(LHS, RHS)
+# ---------------------
+# Evaluate LHS - RHS if they are integer literals, otherwise expand
+# to (LHS) - (RHS).
+m4_define([b4_subtract],
+[m4_bmatch([$1$2], [^[0123456789]*$],
+ [m4_eval([$1 - $2])],
+ [($1) - ($2)])])
+
+# b4_join(ARG1, ...)
+# _b4_join(ARG1, ...)
+# -------------------
+# Join with comma, skipping empty arguments.
+# b4_join calls itself recursively until it sees the first non-empty
+# argument, then calls _b4_join which prepends each non-empty argument
+# with a comma.
+m4_define([b4_join],
+[m4_if([$#$1],
+ [1], [],
+ [m4_ifval([$1],
+ [$1[]_$0(m4_shift($@))],
+ [$0(m4_shift($@))])])])
+
+# _b4_join(ARGS1, ...)
+# --------------------
+m4_define([_b4_join],
+[m4_if([$#$1],
+ [1], [],
+ [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])])
+
+
+
+
+# b4_integral_parser_tables_map(MACRO)
+# -------------------------------------
+# Map MACRO on all the integral tables. MACRO is expected to have
+# the signature MACRO(TABLE-NAME, CONTENT, COMMENT).
+m4_define([b4_integral_parser_tables_map],
+[$1([pact], [b4_pact],
+ [[YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+STATE-NUM.]])
+
+$1([defact], [b4_defact],
+ [[YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
+Performed when YYTABLE does not specify something else to do. Zero
+means the default is an error.]])
+
+$1([pgoto], [b4_pgoto], [[YYPGOTO[NTERM-NUM].]])
+
+$1([defgoto], [b4_defgoto], [[YYDEFGOTO[NTERM-NUM].]])
+
+$1([table], [b4_table],
+ [[YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
+positive, shift that token. If negative, reduce the rule whose
+number is the opposite. If YYTABLE_NINF, syntax error.]])
+
+$1([check], [b4_check])
+
+$1([stos], [b4_stos],
+ [[YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+symbol of state STATE-NUM.]])
+
+$1([r1], [b4_r1],
+ [[YYR1[YYN] -- Symbol number of symbol that rule YYN derives.]])
+
+$1([r2], [b4_r2],
+ [[YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.]])
+])
+
+
+# b4_parser_tables_declare
+# b4_parser_tables_define
+# ------------------------
+# Define/declare the (deterministic) parser tables.
+m4_define([b4_parser_tables_declare],
+[b4_integral_parser_tables_map([b4_integral_parser_table_declare])])
+
+m4_define([b4_parser_tables_define],
+[b4_integral_parser_tables_map([b4_integral_parser_table_define])])
+
+
+
+## ------------------ ##
+## Decoding options. ##
+## ------------------ ##
+
+# b4_flag_if(FLAG, IF-TRUE, IF-FALSE)
+# -----------------------------------
+# Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail.
+m4_define([b4_flag_if],
+[m4_case(b4_$1_flag,
+ [0], [$3],
+ [1], [$2],
+ [m4_fatal([invalid $1 value: ]b4_$1_flag)])])
+
+
+# b4_define_flag_if(FLAG)
+# -----------------------
+# Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the
+# value of the Boolean FLAG.
+m4_define([b4_define_flag_if],
+[_b4_define_flag_if($[1], $[2], [$1])])
+
+# _b4_define_flag_if($1, $2, FLAG)
+# --------------------------------
+# Work around the impossibility to define macros inside macros,
+# because issuing '[$1]' is not possible in M4. GNU M4 should provide
+# $$1 a la M5/TeX.
+m4_define([_b4_define_flag_if],
+[m4_if([$1$2], $[1]$[2], [],
+ [m4_fatal([$0: Invalid arguments: $@])])dnl
+m4_define([b4_$3_if],
+ [b4_flag_if([$3], [$1], [$2])])])
+
+
+# b4_FLAG_if(IF-TRUE, IF-FALSE)
+# -----------------------------
+# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
+b4_define_flag_if([defines]) # Whether headers are requested.
+b4_define_flag_if([glr]) # Whether a GLR parser is requested.
+b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
+b4_define_flag_if([token_table]) # Whether yytoken_table is demanded.
+b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
+
+
+## --------- ##
+## Symbols. ##
+## --------- ##
+
+# In order to unify the handling of the various aspects of symbols
+# (tag, type_name, whether terminal, etc.), bison.exe defines one
+# macro per (token, field), where field can has_id, id, etc.: see
+# src/output.c:prepare_symbols_definitions().
+#
+# The various FIELDS are:
+#
+# - has_id: 0 or 1.
+# Whether the symbol has an id.
+# - id: string
+# If has_id, the id. Guaranteed to be usable as a C identifier.
+# Prefixed by api.token.prefix if defined.
+# - tag: string.
+# A representat of the symbol. Can be 'foo', 'foo.id', '"foo"' etc.
+# - user_number: integer
+# The assigned (external) number as used by yylex.
+# - is_token: 0 or 1
+# Whether this is a terminal symbol.
+# - number: integer
+# The internalized number (used after yytranslate).
+# - has_type: 0, 1
+# Whether has a semantic value.
+# - type_tag: string
+# When api.value.type=union, the generated name for the union member.
+# yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc.
+# - type
+# If it has a semantic value, its type tag, or, if variant are used,
+# its type.
+# In the case of api.value.type=union, type is the real type (e.g. int).
+# - has_printer: 0, 1
+# - printer: string
+# - printer_file: string
+# - printer_line: integer
+# If the symbol has a printer, everything about it.
+# - has_destructor, destructor, destructor_file, destructor_line
+# Likewise.
+#
+# The following macros provide access to these values.
+
+# b4_symbol_(NUM, FIELD)
+# ----------------------
+# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
+# undefined.
+m4_define([b4_symbol_],
+[m4_indir([b4_symbol($1, $2)])])
+
+
+# b4_symbol(NUM, FIELD)
+# ---------------------
+# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
+# undefined. If FIELD = id, prepend the token prefix.
+m4_define([b4_symbol],
+[m4_case([$2],
+ [id], [m4_do([b4_percent_define_get([api.token.prefix])],
+ [b4_symbol_([$1], [id])])],
+ [b4_symbol_($@)])])
+
+
+# b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
+# -------------------------------------------
+# If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
+# Otherwise an error.
+m4_define([b4_symbol_if],
+[m4_case(b4_symbol([$1], [$2]),
+ [1], [$3],
+ [0], [$4],
+ [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
+
+
+# b4_symbol_tag_comment(SYMBOL-NUM)
+# ---------------------------------
+# Issue a comment giving the tag of symbol NUM.
+m4_define([b4_symbol_tag_comment],
+[b4_comment([b4_symbol([$1], [tag])])
+])
+
+
+# b4_symbol_action_location(SYMBOL-NUM, KIND)
+# -------------------------------------------
+# Report the location of the KIND action as FILE:LINE.
+m4_define([b4_symbol_action_location],
+[b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])])
+
+
+# b4_symbol_action(SYMBOL-NUM, KIND)
+# ----------------------------------
+# Run the action KIND (destructor or printer) for SYMBOL-NUM.
+# Same as in C, but using references instead of pointers.
+m4_define([b4_symbol_action],
+[b4_symbol_if([$1], [has_$2],
+[b4_dollar_pushdef([(*yyvaluep)],
+ b4_symbol_if([$1], [has_type],
+ [m4_dquote(b4_symbol([$1], [type]))]),
+ [(*yylocationp)])dnl
+ b4_symbol_case_([$1])[]dnl
+b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
+ b4_symbol([$1], [$2])
+b4_syncline([@oline@], [@ofile@])
+ break;
+
+b4_dollar_popdef[]dnl
+])])
+
+
+# b4_symbol_destructor(SYMBOL-NUM)
+# b4_symbol_printer(SYMBOL-NUM)
+# --------------------------------
+m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
+m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
+
+
+# b4_symbol_actions(KIND, [TYPE = yytype])
+# ----------------------------------------
+# Emit the symbol actions for KIND ("printer" or "destructor").
+# Dispatch on TYPE.
+m4_define([b4_symbol_actions],
+[m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl
+m4_ifval(m4_defn([b4_actions_]),
+[switch (m4_default([$2], [yytype]))
+ {
+ m4_defn([b4_actions_])
+ default:
+ break;
+ }dnl
+],
+[YYUSE (m4_default([$2], [yytype]));])dnl
+m4_popdef([b4_actions_])dnl
+])
+
+# b4_symbol_case_(SYMBOL-NUM)
+# ---------------------------
+# Issue a "case NUM" for SYMBOL-NUM.
+m4_define([b4_symbol_case_],
+[case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])])
+])
+
+
+# b4_symbol_foreach(MACRO)
+# ------------------------
+# Invoke MACRO(SYMBOL-NUM) for each SYMBOL-NUM.
+m4_define([b4_symbol_foreach],
+ [m4_map([$1], m4_defn([b4_symbol_numbers]))])
+
+# b4_symbol_map(MACRO)
+# --------------------
+# Return a list (possibly empty elements) of MACRO invoked for each
+# SYMBOL-NUM.
+m4_define([b4_symbol_map],
+[m4_map_args_sep([$1(], [)], [,], b4_symbol_numbers)])
+
+
+# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
+# -------------------------------------------
+# Whether NUM denotes a token that has an exported definition (i.e.,
+# shows in enum yytokentype).
+m4_define([b4_token_visible_if],
+[b4_symbol_if([$1], [is_token],
+ [b4_symbol_if([$1], [has_id], [$2], [$3])],
+ [$3])])
+
+# b4_token_has_definition(NUM)
+# ----------------------------
+# 1 if NUM is visible, nothing otherwise.
+m4_define([b4_token_has_definition],
+[b4_token_visible_if([$1], [1])])
+
+# b4_any_token_visible_if([IF-TRUE], [IF-FALSE])
+# ----------------------------------------------
+# Whether there is a token that needs to be defined.
+m4_define([b4_any_token_visible_if],
+[m4_ifval(b4_symbol_foreach([b4_token_has_definition]),
+ [$1], [$2])])
+
+
+# b4_token_format(FORMAT, NUM)
+# ----------------------------
+m4_define([b4_token_format],
+[b4_token_visible_if([$2],
+[m4_quote(m4_format([$1],
+ [b4_symbol([$2], [id])],
+ [b4_symbol([$2], [user_number])]))])])
+
+
+## ------- ##
+## Types. ##
+## ------- ##
+
+# b4_type_action_(NUMS)
+# ---------------------
+# Run actions for the symbol NUMS that all have the same type-name.
+# Skip NUMS that have no type-name.
+#
+# To specify the action to run, define b4_dollar_dollar(NUMBER,
+# TAG, TYPE).
+m4_define([b4_type_action_],
+[b4_symbol_if([$1], [has_type],
+[m4_map([ b4_symbol_case_], [$@])[]dnl
+ b4_dollar_dollar([b4_symbol([$1], [number])],
+ [b4_symbol([$1], [tag])],
+ [b4_symbol([$1], [type])]);
+ break;
+
+])])
+
+# b4_type_foreach(MACRO)
+# ----------------------
+# Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set.
+m4_define([b4_type_foreach],
+ [m4_map([$1], m4_defn([b4_type_names]))])
+
+
+
+## ----------- ##
+## Synclines. ##
+## ----------- ##
+
+# b4_basename(NAME)
+# -----------------
+# Similar to POSIX basename; the differences don't matter here.
+# Beware that NAME is not evaluated.
+m4_define([b4_basename],
+[m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])])
+
+
+# b4_syncline(LINE, FILE)
+# -----------------------
+m4_define([b4_syncline],
+[b4_flag_if([synclines],
+[b4_sync_start([$1], [$2]) b4_sync_end([__line__],
+ [b4_basename(m4_quote(__file__))])[]dnl
+])])
+
+# b4_sync_start(LINE, FILE)
+# -----------------------
+# Syncline for the new place. Typically a directive for the compiler.
+m4_define([b4_sync_start], [b4_comment([$2:$1])])
+
+# b4_sync_end(LINE, FILE)
+# -----------------------
+# Syncline for the current place, which ends. Typically a comment
+# left for the reader.
+m4_define([b4_sync_end], [b4_comment([$2:$1])])
+
+
+# b4_user_code(USER-CODE)
+# -----------------------
+# Emit code from the user, ending it with synclines.
+m4_define([b4_user_code],
+[$1
+b4_syncline([@oline@], [@ofile@])])
+
+
+# b4_define_user_code(MACRO)
+# --------------------------
+# From b4_MACRO, build b4_user_MACRO that includes the synclines.
+m4_define([b4_define_user_code],
+[m4_define([b4_user_$1],
+[b4_user_code([b4_$1])])])
+
+
+# b4_user_actions
+# b4_user_initial_action
+# b4_user_post_prologue
+# b4_user_pre_prologue
+# b4_user_union_members
+# ----------------------
+# Macros that issue user code, ending with synclines.
+b4_define_user_code([actions])
+b4_define_user_code([initial_action])
+b4_define_user_code([post_prologue])
+b4_define_user_code([pre_prologue])
+b4_define_user_code([union_members])
+
+
+# b4_check_user_names(WHAT, USER-LIST, BISON-NAMESPACE)
+# -----------------------------------------------------
+# Complain if any name of type WHAT is used by the user (as recorded in
+# USER-LIST) but is not used by Bison (as recorded by macros in the
+# namespace BISON-NAMESPACE).
+#
+# USER-LIST must expand to a list specifying all user occurrences of all names
+# of type WHAT. Each item in the list must be a triplet specifying one
+# occurrence: name, start boundary, and end boundary. Empty string names are
+# fine. An empty list is fine.
+#
+# For example, to define b4_foo_user_names to be used for USER-LIST with three
+# name occurrences and with correct quoting:
+#
+# m4_define([b4_foo_user_names],
+# [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]],
+# [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
+# [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
+#
+# The macro BISON-NAMESPACE(bar) must be defined iff the name bar of type WHAT
+# is used by Bison (in the front-end or in the skeleton). Empty string names
+# are fine, but it would be ugly for Bison to actually use one.
+#
+# For example, to use b4_foo_bison_names for BISON-NAMESPACE and define that
+# the names bar and baz are used by Bison:
+#
+# m4_define([b4_foo_bison_names(bar)])
+# m4_define([b4_foo_bison_names(baz)])
+#
+# To invoke b4_check_user_names with TYPE foo, with USER-LIST
+# b4_foo_user_names, with BISON-NAMESPACE b4_foo_bison_names, and with correct
+# quoting:
+#
+# b4_check_user_names([[foo]], [b4_foo_user_names],
+# [[b4_foo_bison_names]])
+m4_define([b4_check_user_names],
+[m4_foreach([b4_occurrence], $2,
+[m4_pushdef([b4_occurrence], b4_occurrence)dnl
+m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
+m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
+m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
+m4_ifndef($3[(]m4_quote(b4_user_name)[)],
+ [b4_complain_at([b4_start], [b4_end],
+ [[%s '%s' is not used]],
+ [$1], [b4_user_name])])[]dnl
+m4_popdef([b4_occurrence])dnl
+m4_popdef([b4_user_name])dnl
+m4_popdef([b4_start])dnl
+m4_popdef([b4_end])dnl
+])])
+
+
+
+## --------------------- ##
+## b4_percent_define_*. ##
+## --------------------- ##
+
+
+# b4_percent_define_use(VARIABLE)
+# -------------------------------
+# Declare that VARIABLE was used.
+m4_define([b4_percent_define_use],
+[m4_define([b4_percent_define_bison_variables(]$1[)])dnl
+])
+
+# b4_percent_define_get(VARIABLE, [DEFAULT])
+# ------------------------------------------
+# Mimic muscle_percent_define_get in ../src/muscle-tab.h. That is, if
+# the %define variable VARIABLE is defined, emit its value. Contrary
+# to its C counterpart, return DEFAULT otherwise. Also, record
+# Bison's usage of VARIABLE by defining
+# b4_percent_define_bison_variables(VARIABLE).
+#
+# For example:
+#
+# b4_percent_define_get([[foo]])
+m4_define([b4_percent_define_get],
+[b4_percent_define_use([$1])dnl
+b4_percent_define_ifdef_([$1],
+ [m4_indir([b4_percent_define(]$1[)])],
+ [$2])])
+
+# b4_percent_define_get_loc(VARIABLE)
+# -----------------------------------
+# Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly. That is,
+# if the %define variable VARIABLE is undefined, complain fatally since that's
+# a Bison or skeleton error. Otherwise, return its definition location in a
+# form approriate for the first two arguments of b4_warn_at, b4_complain_at, or
+# b4_fatal_at. Don't record this as a Bison usage of VARIABLE as there's no
+# reason to suspect that the user-supplied value has yet influenced the output.
+#
+# For example:
+#
+# b4_complain_at(b4_percent_define_get_loc([[foo]]), [[invalid foo]])
+m4_define([b4_percent_define_get_loc],
+[m4_ifdef([b4_percent_define_loc(]$1[)],
+ [m4_pushdef([b4_loc], m4_indir([b4_percent_define_loc(]$1[)]))dnl
+b4_loc[]dnl
+m4_popdef([b4_loc])],
+ [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
+
+# b4_percent_define_get_kind(VARIABLE)
+# ------------------------------------
+# Get the kind (code, keyword, string) of VARIABLE, i.e., how its
+# value was defined (braces, not delimiters, quotes).
+#
+# If the %define variable VARIABLE is undefined, complain fatally
+# since that's a Bison or skeleton error. Don't record this as a
+# Bison usage of VARIABLE as there's no reason to suspect that the
+# user-supplied value has yet influenced the output.
+m4_define([b4_percent_define_get_kind],
+[m4_ifdef([b4_percent_define_kind(]$1[)],
+ [m4_indir([b4_percent_define_kind(]$1[)])],
+ [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
+
+# b4_percent_define_get_syncline(VARIABLE)
+# ----------------------------------------
+# Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly.
+# That is, if the %define variable VARIABLE is undefined, complain fatally
+# since that's a Bison or skeleton error. Otherwise, return its definition
+# location as a b4_syncline invocation. Don't record this as a Bison usage of
+# VARIABLE as there's no reason to suspect that the user-supplied value has yet
+# influenced the output.
+#
+# For example:
+#
+# b4_percent_define_get_syncline([[foo]])
+m4_define([b4_percent_define_get_syncline],
+[m4_ifdef([b4_percent_define_syncline(]$1[)],
+ [m4_indir([b4_percent_define_syncline(]$1[)])],
+ [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
+
+# b4_percent_define_ifdef_(VARIABLE, IF-TRUE, [IF-FALSE])
+# ------------------------------------------------------
+# If the %define variable VARIABLE is defined, expand IF-TRUE, else expand
+# IF-FALSE. Don't record usage of VARIABLE.
+#
+# For example:
+#
+# b4_percent_define_ifdef_([[foo]], [[it's defined]], [[it's undefined]])
+m4_define([b4_percent_define_ifdef_],
+[m4_ifdef([b4_percent_define(]$1[)],
+ [$2],
+ [$3])])
+
+# b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
+# ------------------------------------------------------
+# Mimic muscle_percent_define_ifdef in ../src/muscle-tab.h exactly. That is,
+# if the %define variable VARIABLE is defined, expand IF-TRUE, else expand
+# IF-FALSE. Also, record Bison's usage of VARIABLE by defining
+# b4_percent_define_bison_variables(VARIABLE).
+#
+# For example:
+#
+# b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]])
+m4_define([b4_percent_define_ifdef],
+[b4_percent_define_ifdef_([$1],
+ [b4_percent_define_use([$1])$2],
+ [$3])])
+
+
+## --------- ##
+## Options. ##
+## --------- ##
+
+
+# b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE])
+# --------------------------------------------------------
+# Mimic muscle_percent_define_flag_if in ../src/muscle-tab.h exactly. That is,
+# if the %define variable VARIABLE is defined to "" or "true", expand IF-TRUE.
+# If it is defined to "false", expand IF-FALSE. Complain if it is undefined
+# (a Bison or skeleton error since the default value should have been set
+# already) or defined to any other value (possibly a user error). Also, record
+# Bison's usage of VARIABLE by defining
+# b4_percent_define_bison_variables(VARIABLE).
+#
+# For example:
+#
+# b4_percent_define_flag_if([[foo]], [[it's true]], [[it's false]])
+m4_define([b4_percent_define_flag_if],
+[b4_percent_define_ifdef([$1],
+ [m4_case(b4_percent_define_get([$1]),
+ [], [$2], [true], [$2], [false], [$3],
+ [m4_expand_once([b4_complain_at(b4_percent_define_get_loc([$1]),
+ [[invalid value for %%define Boolean variable '%s']],
+ [$1])],
+ [[b4_percent_define_flag_if($1)]])])],
+ [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
+
+
+# b4_percent_define_default(VARIABLE, DEFAULT, [KIND = keyword])
+# --------------------------------------------------------------
+# Mimic muscle_percent_define_default in ../src/muscle-tab.h exactly. That is,
+# if the %define variable VARIABLE is undefined, set its value to DEFAULT.
+# Don't record this as a Bison usage of VARIABLE as there's no reason to
+# suspect that the value has yet influenced the output.
+#
+# For example:
+#
+# b4_percent_define_default([[foo]], [[default value]])
+m4_define([b4_percent_define_default],
+[b4_percent_define_ifdef_([$1], [],
+ [m4_define([b4_percent_define(]$1[)], [$2])dnl
+ m4_define([b4_percent_define_kind(]$1[)],
+ [m4_default([$3], [keyword])])dnl
+ m4_define([b4_percent_define_loc(]$1[)],
+ [[[[<skeleton default value>:-1.-1]],
+ [[<skeleton default value>:-1.-1]]]])dnl
+ m4_define([b4_percent_define_syncline(]$1[)], [[]])])])
+
+
+# b4_percent_define_if_define(NAME, [VARIABLE = NAME])
+# ----------------------------------------------------
+# Define b4_NAME_if that executes its $1 or $2 depending whether
+# VARIABLE was %defined. The characters '.' and `-' in VARIABLE are mapped
+# to '_'.
+m4_define([b4_percent_define_if_define_],
+[m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
+ [b4_percent_define_flag_if(m4_default([$2], [$1]),
+ [$3], [$4])])])
+m4_define([b4_percent_define_if_define],
+[b4_percent_define_default([m4_default([$2], [$1])], [[false]])
+b4_percent_define_if_define_([$1], [$2], $[1], $[2])])
+
+
+# b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain])
+# ---------------------------------------------------------------------
+m4_define([b4_percent_define_check_kind],
+[b4_percent_define_ifdef_([$1],
+ [m4_if(b4_percent_define_get_kind([$1]), [$2], [],
+ [b4_error([m4_default([$3], [complain])],
+ b4_percent_define_get_loc([$1]),
+ [m4_case([$2],
+ [code], [[%%define variable '%s' requires '{...}' values]],
+ [keyword], [[%%define variable '%s' requires keyword values]],
+ [string], [[%%define variable '%s' requires '"..."' values]])],
+ [$1])])])dnl
+])
+
+
+# b4_percent_define_check_values(VALUES)
+# --------------------------------------
+# Mimic muscle_percent_define_check_values in ../src/muscle-tab.h exactly
+# except that the VALUES structure is more appropriate for M4. That is, VALUES
+# is a list of sublists of strings. For each sublist, the first string is the
+# name of a %define variable, and all remaining strings in that sublist are the
+# valid values for that variable. Complain if such a variable is undefined (a
+# Bison error since the default value should have been set already) or defined
+# to any other value (possibly a user error). Don't record this as a Bison
+# usage of the variable as there's no reason to suspect that the value has yet
+# influenced the output.
+#
+# For example:
+#
+# b4_percent_define_check_values([[[[foo]], [[foo-value1]], [[foo-value2]]]],
+# [[[[bar]], [[bar-value1]]]])
+m4_define([b4_percent_define_check_values],
+[m4_foreach([b4_sublist], m4_quote($@),
+ [_b4_percent_define_check_values(b4_sublist)])])
+
+m4_define([_b4_percent_define_check_values],
+[b4_percent_define_ifdef_([$1],
+ [b4_percent_define_check_kind(]$1[, [keyword], [deprecated])dnl
+ m4_pushdef([b4_good_value], [0])dnl
+ m4_if($#, 1, [],
+ [m4_foreach([b4_value], m4_dquote(m4_shift($@)),
+ [m4_if(m4_indir([b4_percent_define(]$1[)]), b4_value,
+ [m4_define([b4_good_value], [1])])])])dnl
+ m4_if(b4_good_value, [0],
+ [b4_complain_at(b4_percent_define_get_loc([$1]),
+ [[invalid value for %%define variable '%s': '%s']],
+ [$1],
+ m4_dquote(m4_indir([b4_percent_define(]$1[)])))
+ m4_foreach([b4_value], m4_dquote(m4_shift($@)),
+ [b4_error([[note]], b4_percent_define_get_loc([$1]), []
+ [[accepted value: '%s']],
+ m4_dquote(b4_value))])])dnl
+ m4_popdef([b4_good_value])],
+ [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
+
+# b4_percent_code_get([QUALIFIER])
+# --------------------------------
+# If any %code blocks for QUALIFIER are defined, emit them beginning with a
+# comment and ending with synclines and a newline. If QUALIFIER is not
+# specified or empty, do this for the unqualified %code blocks. Also, record
+# Bison's usage of QUALIFIER (if specified) by defining
+# b4_percent_code_bison_qualifiers(QUALIFIER).
+#
+# For example, to emit any unqualified %code blocks followed by any %code
+# blocks for the qualifier foo:
+#
+# b4_percent_code_get
+# b4_percent_code_get([[foo]])
+m4_define([b4_percent_code_get],
+[m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl
+m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
+m4_ifdef(b4_macro_name,
+[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
+ [["%code ]$1["]])[ blocks.]])
+b4_user_code([m4_indir(b4_macro_name)])
+])dnl
+m4_popdef([b4_macro_name])])
+
+# b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------
+# If any %code blocks for QUALIFIER (or unqualified %code blocks if
+# QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE.
+# Also, record Bison's usage of QUALIFIER (if specified) by defining
+# b4_percent_code_bison_qualifiers(QUALIFIER).
+m4_define([b4_percent_code_ifdef],
+[m4_ifdef([b4_percent_code(]$1[)],
+ [m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])$2],
+ [$3])])
+
+
+## ------------------ ##
+## Common variables. ##
+## ------------------ ##
+
+
+# b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
+# b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT])
+# b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT])
+# ----------------------------------------------
+b4_percent_define_if_define([token_ctor], [api.token.constructor])
+b4_percent_define_if_define([locations]) # Whether locations are tracked.
+b4_percent_define_if_define([parse.assert])
+b4_percent_define_if_define([parse.trace])
+
+
+# b4_bison_locations_if([IF-TRUE])
+# --------------------------------
+# Expand IF-TRUE if using locations, and using the default location
+# type.
+m4_define([b4_bison_locations_if],
+[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
+
+
+# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT])
+# ------------------------------------------------------
+# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and
+# b4_error_verbose_flag.
+b4_percent_define_default([[parse.error]], [[simple]])
+b4_percent_define_check_values([[[[parse.error]],
+ [[simple]], [[verbose]]]])
+m4_define([b4_error_verbose_flag],
+ [m4_case(b4_percent_define_get([[parse.error]]),
+ [simple], [[0]],
+ [verbose], [[1]])])
+b4_define_flag_if([error_verbose])
+
+# yytoken_table is needed to support verbose errors.
+b4_error_verbose_if([m4_define([b4_token_table_flag], [1])])
+
+
+# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
+# ----------------------------------------------
+b4_percent_define_if_define([variant])
+m4_define([b4_variant_flag], [[0]])
+b4_percent_define_ifdef([[api.value.type]],
+ [m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword],
+ [m4_case(b4_percent_define_get([[api.value.type]]), [variant],
+ [m4_define([b4_variant_flag], [[1]])])])])
+b4_define_flag_if([variant])
+
+
+## ----------------------------------------------------------- ##
+## After processing the skeletons, check that all the user's ##
+## %define variables and %code qualifiers were used by Bison. ##
+## ----------------------------------------------------------- ##
+
+m4_define([b4_check_user_names_wrap],
+[m4_ifdef([b4_percent_]$1[_user_]$2[s],
+ [b4_check_user_names([[%]$1 $2],
+ [b4_percent_]$1[_user_]$2[s],
+ [[b4_percent_]$1[_bison_]$2[s]])])])
+
+m4_wrap_lifo([
+b4_check_user_names_wrap([[define]], [[variable]])
+b4_check_user_names_wrap([[code]], [[qualifier]])
+])
+
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# m4_define_default([b4_lex_param], []) dnl breaks other skeletons
+m4_define_default([b4_pre_prologue], [])
+m4_define_default([b4_post_prologue], [])
+m4_define_default([b4_epilogue], [])
+m4_define_default([b4_parse_param], [])
+
+# The initial column and line.
+m4_define_default([b4_location_initial_column], [1])
+m4_define_default([b4_location_initial_line], [1])
+
+
+## --------------- ##
+## Sanity checks. ##
+## --------------- ##
+
+# api.location.prefix={...} (Java and C++).
+b4_percent_define_check_kind([api.location.type], [code], [deprecated])
+
+# api.position.prefix={...} (Java).
+b4_percent_define_check_kind([api.position.type], [code], [deprecated])
+
+# api.prefix >< %name-prefix.
+b4_percent_define_check_kind([api.prefix], [code], [deprecated])
+b4_percent_define_ifdef([api.prefix],
+[m4_ifdef([b4_prefix],
+[b4_complain_at(b4_percent_define_get_loc([api.prefix]),
+ [['%s' and '%s' cannot be used together]],
+ [%name-prefix],
+ [%define api.prefix])])])
+
+# api.token.prefix={...}
+# Make it a warning for those who used betas of Bison 3.0.
+b4_percent_define_check_kind([api.token.prefix], [code], [deprecated])
+
+# api.value.type >< %union.
+b4_percent_define_ifdef([api.value.type],
+[m4_ifdef([b4_union_members],
+[b4_complain_at(b4_percent_define_get_loc([api.value.type]),
+ [['%s' and '%s' cannot be used together]],
+ [%union],
+ [%define api.value.type])])])
+
+# api.value.type=union >< %yacc.
+b4_percent_define_ifdef([api.value.type],
+[m4_if(b4_percent_define_get([api.value.type]), [union],
+[b4_yacc_if(dnl
+[b4_complain_at(b4_percent_define_get_loc([api.value.type]),
+ [['%s' and '%s' cannot be used together]],
+ [%yacc],
+ [%define api.value.type "union"])])])])
diff --git a/contrib/tools/bison/bison/data/c++-skel.m4 b/contrib/tools/bison/bison/data/c++-skel.m4
index 06597a8bff..cc46512e4e 100644
--- a/contrib/tools/bison/bison/data/c++-skel.m4
+++ b/contrib/tools/bison/bison/data/c++-skel.m4
@@ -1,26 +1,26 @@
- -*- Autoconf -*-
-
-# C++ skeleton dispatching for Bison.
-
-# Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])])
-b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])])
-
-m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.cc]])
-m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
-
-m4_include(b4_used_skeleton)
+ -*- Autoconf -*-
+
+# C++ skeleton dispatching for Bison.
+
+# Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])])
+b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])])
+
+m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.cc]])
+m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
+
+m4_include(b4_used_skeleton)
diff --git a/contrib/tools/bison/bison/data/c++.m4 b/contrib/tools/bison/bison/data/c++.m4
index be12c0a2fe..91b8e13026 100644
--- a/contrib/tools/bison/bison/data/c++.m4
+++ b/contrib/tools/bison/bison/data/c++.m4
@@ -1,544 +1,544 @@
- -*- Autoconf -*-
-
-# C++ skeleton for Bison
-
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-m4_include(b4_pkgdatadir/[c.m4])
-
-# b4_comment(TEXT, [PREFIX])
-# --------------------------
-# Put TEXT in comment. Prefix all the output lines with PREFIX.
-m4_define([b4_comment],
-[b4_comment_([$1], [$2// ], [$2// ])])
-
-## -------- ##
-## Checks. ##
-## -------- ##
-
-b4_percent_define_check_kind([api.namespace], [code], [deprecated])
-b4_percent_define_check_kind([parser_class_name], [code], [deprecated])
-
-## ---------------- ##
-## Default values. ##
-## ---------------- ##
-
-b4_percent_define_default([[parser_class_name]], [[parser]])
-
-# Don't do that so that we remember whether we're using a user
-# request, or the default value.
-#
-# b4_percent_define_default([[api.location.type]], [[location]])
-
-b4_percent_define_default([[filename_type]], [[std::string]])
-# Make it a warning for those who used betas of Bison 3.0.
-b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix]))
-
-b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
-b4_percent_define_default([[define_location_comparison]],
- [m4_if(b4_percent_define_get([[filename_type]]),
- [std::string], [[true]], [[false]])])
-
-
-
-## ----------- ##
-## Namespace. ##
-## ----------- ##
-
-m4_define([b4_namespace_ref], [b4_percent_define_get([[api.namespace]])])
-
-
-# Don't permit an empty b4_namespace_ref. Any '::parser::foo' appended to it
-# would compile as an absolute reference with 'parser' in the global namespace.
-# b4_namespace_open would open an anonymous namespace and thus establish
-# internal linkage. This would compile. However, it's cryptic, and internal
-# linkage for the parser would be specified in all translation units that
-# include the header, which is always generated. If we ever need to permit
-# internal linkage somehow, surely we can find a cleaner approach.
-m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [],
-[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
- [[namespace reference is empty]])])
-
-# Instead of assuming the C++ compiler will do it, Bison should reject any
-# invalid b4_namepsace_ref that would be converted to a valid
-# b4_namespace_open. The problem is that Bison doesn't always output
-# b4_namespace_ref to uncommented code but should reserve the ability to do so
-# in future releases without risking breaking any existing user grammars.
-# Specifically, don't allow empty names as b4_namespace_open would just convert
-# those into anonymous namespaces, and that might tempt some users.
-m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [],
-[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
- [[namespace reference has consecutive "::"]])])
-m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
-[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
- [[namespace reference has a trailing "::"]])])
-
-m4_define([b4_namespace_open],
-[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])
-[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
- [^\(.\)[ ]*::], [\1])),
- [::], [ { namespace ])[ {]])])
-
-m4_define([b4_namespace_close],
-[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])
-m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
- [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*],
- [\1])),
- [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
-
-
-# b4_token_enums
-# --------------
-# Output the definition of the tokens as enums.
-m4_define([b4_token_enums],
-[[enum yytokentype
- {
- ]m4_join([,
- ],
- b4_symbol_map([b4_token_enum]))[
- };]dnl
-])
-
-
-
-
-## ----------------- ##
-## Semantic Values. ##
-## ----------------- ##
-
-
-
-# b4_value_type_declare
-# ---------------------
-# Declare semantic_type.
-m4_define([b4_value_type_declare],
-[b4_value_type_setup[]dnl
-[ /// Symbol semantic values.
-]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
-[code],
-[[ typedef ]b4_percent_define_get([[api.value.type]])[ semantic_type;]],
-[m4_bmatch(b4_percent_define_get([[api.value.type]]),
-[union\|union-directive],
-[[ union semantic_type
- {
- ]b4_user_union_members[
- };]])])dnl
-])
-
-
-# b4_public_types_declare
-# -----------------------
-# Define the public types: token, semantic value, location, and so forth.
-# Depending on %define token_lex, may be output in the header or source file.
-m4_define([b4_public_types_declare],
-[[#ifndef ]b4_api_PREFIX[STYPE
-]b4_value_type_declare[
-#else
- typedef ]b4_api_PREFIX[STYPE semantic_type;
-#endif]b4_locations_if([
- /// Symbol locations.
- typedef b4_percent_define_get([[api.location.type]],
- [[location]]) location_type;])[
-
- /// Syntax errors thrown from user actions.
- struct syntax_error : std::runtime_error
- {
- syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m);]b4_locations_if([
- location_type location;])[
- };
-
- /// Tokens.
- struct token
- {
- ]b4_token_enums[
- };
-
- /// (External) token type, as returned by yylex.
- typedef token::yytokentype token_type;
-
- /// Internal symbol number.
- typedef int symbol_number_type;
-
- /// Internal symbol number for tokens (subsumed by symbol_number_type).
- typedef ]b4_int_type_for([b4_translate])[ token_number_type;
-
- /// A complete symbol.
- ///
- /// Expects its Base type to provide access to the symbol type
- /// via type_get().
- ///
- /// Provide access to semantic value]b4_locations_if([ and location])[.
- template <typename Base>
- struct basic_symbol : Base
- {
- /// Alias to Base.
- typedef Base super_type;
-
- /// Default constructor.
- basic_symbol ();
-
- /// Copy constructor.
- basic_symbol (const basic_symbol& other);
-]b4_variant_if([[
- /// Constructor for valueless symbols, and symbols from each type.
-]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[
- /// Constructor for valueless symbols.
- basic_symbol (typename Base::kind_type t]b4_locations_if([,
- const location_type& l])[);]])[
-
- /// Constructor for symbols with semantic value.
- basic_symbol (typename Base::kind_type t,
- const semantic_type& v]b4_locations_if([,
- const location_type& l])[);
-
- ~basic_symbol ();
-
- /// Destructive move, \a s is emptied into this.
- void move (basic_symbol& s);
-
- /// The semantic value.
- semantic_type value;]b4_locations_if([
-
- /// The location.
- location_type location;])[
-
- private:
- /// Assignment operator.
- basic_symbol& operator= (const basic_symbol& other);
- };
-
- /// Type access provider for token (enum) based symbols.
- struct by_type
- {
- /// Default constructor.
- by_type ();
-
- /// Copy constructor.
- by_type (const by_type& other);
-
- /// The symbol type as needed by the constructor.
- typedef token_type kind_type;
-
- /// Constructor from (external) token numbers.
- by_type (kind_type t);
-
- /// Steal the symbol type from \a that.
- void move (by_type& that);
-
- /// The (internal) type number (corresponding to \a type).
- /// -1 when this symbol is empty.
- symbol_number_type type_get () const;
-
- /// The token.
- token_type token () const;
-
- enum { empty = 0 };
-
- /// The symbol type.
- /// -1 when this symbol is empty.
- token_number_type type;
- };
-
- /// "External" symbols: returned by the scanner.
- typedef basic_symbol<by_type> symbol_type;
-
-]b4_symbol_constructor_declare])
-
-
-# b4_public_types_define
-# ----------------------
-# Provide the implementation needed by the public types.
-m4_define([b4_public_types_define],
-[[ inline
- ]b4_parser_class_name[::syntax_error::syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m)
- : std::runtime_error (m)]b4_locations_if([
- , location (l)])[
- {}
-
- // basic_symbol.
- template <typename Base>
- inline
- ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol ()
- : value ()
- {}
-
- template <typename Base>
- inline
- ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
- : Base (other)
- , value ()]b4_locations_if([
- , location (other.location)])[
- {
- ]b4_variant_if([b4_symbol_variant([other.type_get ()], [value], [copy],
- [other.value])],
- [value = other.value;])[
- }
-
-
- template <typename Base>
- inline
- ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
- [typename Base::kind_type t],
- [const semantic_type& v],
- b4_locations_if([const location_type& l]))[)
- : Base (t)
- , value (]b4_variant_if([], [v])[)]b4_locations_if([
- , location (l)])[
- {]b4_variant_if([[
- (void) v;
- ]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[}
-
-]b4_variant_if([[
- // Implementation of basic_symbol constructor for each type.
-]b4_type_foreach([b4_basic_symbol_constructor_define])], [[
- /// Constructor for valueless symbols.
- template <typename Base>
- inline
- ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
- [typename Base::kind_type t],
- b4_locations_if([const location_type& l]))[)
- : Base (t)
- , value ()]b4_locations_if([
- , location (l)])[
- {}]])[
-
- template <typename Base>
- inline
- ]b4_parser_class_name[::basic_symbol<Base>::~basic_symbol ()
- {]b4_variant_if([[
- // User destructor.
- symbol_number_type yytype = this->type_get ();
- switch (yytype)
- {
-]b4_symbol_foreach([b4_symbol_destructor])dnl
-[ default:
- break;
- }
-
- // Type destructor.
- ]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[
- }
-
- template <typename Base>
- inline
- void
- ]b4_parser_class_name[::basic_symbol<Base>::move (basic_symbol& s)
- {
- super_type::move(s);
- ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move],
- [s.value])],
- [value = s.value;])[]b4_locations_if([
- location = s.location;])[
- }
-
- // by_type.
- inline
- ]b4_parser_class_name[::by_type::by_type ()
- : type (empty)
- {}
-
- inline
- ]b4_parser_class_name[::by_type::by_type (const by_type& other)
- : type (other.type)
- {}
-
- inline
- ]b4_parser_class_name[::by_type::by_type (token_type t)
- : type (yytranslate_ (t))
- {}
-
- inline
- void
- ]b4_parser_class_name[::by_type::move (by_type& that)
- {
- type = that.type;
- that.type = empty;
- }
-
- inline
- int
- ]b4_parser_class_name[::by_type::type_get () const
- {
- return type;
- }
-]b4_token_ctor_if([[
- inline
- ]b4_parser_class_name[::token_type
- ]b4_parser_class_name[::by_type::token () const
- {
- // YYTOKNUM[NUM] -- (External) token number corresponding to the
- // (internal) symbol number NUM (which must be that of a token). */
- static
- const ]b4_int_type_for([b4_toknum])[
- yytoken_number_[] =
- {
- ]b4_toknum[
- };
- return static_cast<token_type> (yytoken_number_[type]);
- }
-]])[]dnl
-b4_symbol_constructor_define])
-
-
-# b4_symbol_constructor_declare
-# b4_symbol_constructor_define
-# -----------------------------
-# Declare/define symbol constructors for all the value types.
-# Use at class-level. Redefined in variant.hh.
-m4_define([b4_symbol_constructor_declare], [])
-m4_define([b4_symbol_constructor_define], [])
-
-
-# b4_yytranslate_define
-# ---------------------
-# Define yytranslate_. Sometimes used in the header file,
-# sometimes in the cc file.
-m4_define([b4_yytranslate_define],
-[[ // Symbol number corresponding to token number t.
- inline
- ]b4_parser_class_name[::token_number_type
- ]b4_parser_class_name[::yytranslate_ (]b4_token_ctor_if([token_type],
- [int])[ t)
- {
- static
- const token_number_type
- translate_table[] =
- {
-]b4_translate[
- };
- const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
- const token_number_type undef_token_ = ]b4_undef_token_number[;
-
- if (static_cast<int>(t) <= yyeof_)
- return yyeof_;
- else if (static_cast<unsigned int> (t) <= user_token_number_max_)
- return translate_table[t];
- else
- return undef_token_;
- }
-]])
-
-
-# b4_lhs_value([TYPE])
-# --------------------
-# Expansion of $<TYPE>$.
-m4_define([b4_lhs_value],
-[b4_symbol_value([yyval], [$1])])
-
-
-# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
-# --------------------------------------
-# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
-# symbols on RHS.
-m4_define([b4_rhs_value],
-[b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])])
-
-
-# b4_lhs_location()
-# -----------------
-# Expansion of @$.
-m4_define([b4_lhs_location],
-[(yyloc)])
-
-
-# b4_rhs_location(RULE-LENGTH, NUM)
-# ---------------------------------
-# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
-# on RHS.
-m4_define([b4_rhs_location],
-[(yylocation_stack_@{($1) - ($2)@})])
-
-
-# b4_parse_param_decl
-# -------------------
-# Extra formal arguments of the constructor.
-# Change the parameter names from "foo" into "foo_yyarg", so that
-# there is no collision bw the user chosen attribute name, and the
-# argument name in the constructor.
-m4_define([b4_parse_param_decl],
-[m4_ifset([b4_parse_param],
- [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
-
-m4_define([b4_parse_param_decl_1],
-[$1_yyarg])
-
-
-
-# b4_parse_param_cons
-# -------------------
-# Extra initialisations of the constructor.
-m4_define([b4_parse_param_cons],
- [m4_ifset([b4_parse_param],
- [
- b4_cc_constructor_calls(b4_parse_param)])])
-m4_define([b4_cc_constructor_calls],
- [m4_map_sep([b4_cc_constructor_call], [,
- ], [$@])])
-m4_define([b4_cc_constructor_call],
- [$2 ($2_yyarg)])
-
-# b4_parse_param_vars
-# -------------------
-# Extra instance variables.
-m4_define([b4_parse_param_vars],
- [m4_ifset([b4_parse_param],
- [
- // User arguments.
-b4_cc_var_decls(b4_parse_param)])])
-m4_define([b4_cc_var_decls],
- [m4_map_sep([b4_cc_var_decl], [
-], [$@])])
-m4_define([b4_cc_var_decl],
- [ $1;])
-
-
-## ---------##
-## Values. ##
-## ---------##
-
-# b4_yylloc_default_define
-# ------------------------
-# Define YYLLOC_DEFAULT.
-m4_define([b4_yylloc_default_define],
-[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
-# ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).begin = YYRHSLOC (Rhs, 1).begin; \
- (Current).end = YYRHSLOC (Rhs, N).end; \
- } \
- else \
- { \
- (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
- } \
- while (/*CONSTCOND*/ false)
-# endif
-]])
-
-## -------- ##
-## Checks. ##
-## -------- ##
-
-b4_token_ctor_if([b4_variant_if([],
- [b4_fatal_at(b4_percent_define_get_loc(api.token.constructor),
- [cannot use '%s' without '%s'],
- [%define api.token.constructor],
- [%define api.value.type variant]))])])
+ -*- Autoconf -*-
+
+# C++ skeleton for Bison
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include(b4_pkgdatadir/[c.m4])
+
+# b4_comment(TEXT, [PREFIX])
+# --------------------------
+# Put TEXT in comment. Prefix all the output lines with PREFIX.
+m4_define([b4_comment],
+[b4_comment_([$1], [$2// ], [$2// ])])
+
+## -------- ##
+## Checks. ##
+## -------- ##
+
+b4_percent_define_check_kind([api.namespace], [code], [deprecated])
+b4_percent_define_check_kind([parser_class_name], [code], [deprecated])
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+b4_percent_define_default([[parser_class_name]], [[parser]])
+
+# Don't do that so that we remember whether we're using a user
+# request, or the default value.
+#
+# b4_percent_define_default([[api.location.type]], [[location]])
+
+b4_percent_define_default([[filename_type]], [[std::string]])
+# Make it a warning for those who used betas of Bison 3.0.
+b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix]))
+
+b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
+b4_percent_define_default([[define_location_comparison]],
+ [m4_if(b4_percent_define_get([[filename_type]]),
+ [std::string], [[true]], [[false]])])
+
+
+
+## ----------- ##
+## Namespace. ##
+## ----------- ##
+
+m4_define([b4_namespace_ref], [b4_percent_define_get([[api.namespace]])])
+
+
+# Don't permit an empty b4_namespace_ref. Any '::parser::foo' appended to it
+# would compile as an absolute reference with 'parser' in the global namespace.
+# b4_namespace_open would open an anonymous namespace and thus establish
+# internal linkage. This would compile. However, it's cryptic, and internal
+# linkage for the parser would be specified in all translation units that
+# include the header, which is always generated. If we ever need to permit
+# internal linkage somehow, surely we can find a cleaner approach.
+m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [],
+[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
+ [[namespace reference is empty]])])
+
+# Instead of assuming the C++ compiler will do it, Bison should reject any
+# invalid b4_namepsace_ref that would be converted to a valid
+# b4_namespace_open. The problem is that Bison doesn't always output
+# b4_namespace_ref to uncommented code but should reserve the ability to do so
+# in future releases without risking breaking any existing user grammars.
+# Specifically, don't allow empty names as b4_namespace_open would just convert
+# those into anonymous namespaces, and that might tempt some users.
+m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [],
+[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
+ [[namespace reference has consecutive "::"]])])
+m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
+[b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
+ [[namespace reference has a trailing "::"]])])
+
+m4_define([b4_namespace_open],
+[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])
+[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
+ [^\(.\)[ ]*::], [\1])),
+ [::], [ { namespace ])[ {]])])
+
+m4_define([b4_namespace_close],
+[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])
+m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
+ [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*],
+ [\1])),
+ [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
+
+
+# b4_token_enums
+# --------------
+# Output the definition of the tokens as enums.
+m4_define([b4_token_enums],
+[[enum yytokentype
+ {
+ ]m4_join([,
+ ],
+ b4_symbol_map([b4_token_enum]))[
+ };]dnl
+])
+
+
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+
+# b4_value_type_declare
+# ---------------------
+# Declare semantic_type.
+m4_define([b4_value_type_declare],
+[b4_value_type_setup[]dnl
+[ /// Symbol semantic values.
+]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
+[code],
+[[ typedef ]b4_percent_define_get([[api.value.type]])[ semantic_type;]],
+[m4_bmatch(b4_percent_define_get([[api.value.type]]),
+[union\|union-directive],
+[[ union semantic_type
+ {
+ ]b4_user_union_members[
+ };]])])dnl
+])
+
+
+# b4_public_types_declare
+# -----------------------
+# Define the public types: token, semantic value, location, and so forth.
+# Depending on %define token_lex, may be output in the header or source file.
+m4_define([b4_public_types_declare],
+[[#ifndef ]b4_api_PREFIX[STYPE
+]b4_value_type_declare[
+#else
+ typedef ]b4_api_PREFIX[STYPE semantic_type;
+#endif]b4_locations_if([
+ /// Symbol locations.
+ typedef b4_percent_define_get([[api.location.type]],
+ [[location]]) location_type;])[
+
+ /// Syntax errors thrown from user actions.
+ struct syntax_error : std::runtime_error
+ {
+ syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m);]b4_locations_if([
+ location_type location;])[
+ };
+
+ /// Tokens.
+ struct token
+ {
+ ]b4_token_enums[
+ };
+
+ /// (External) token type, as returned by yylex.
+ typedef token::yytokentype token_type;
+
+ /// Internal symbol number.
+ typedef int symbol_number_type;
+
+ /// Internal symbol number for tokens (subsumed by symbol_number_type).
+ typedef ]b4_int_type_for([b4_translate])[ token_number_type;
+
+ /// A complete symbol.
+ ///
+ /// Expects its Base type to provide access to the symbol type
+ /// via type_get().
+ ///
+ /// Provide access to semantic value]b4_locations_if([ and location])[.
+ template <typename Base>
+ struct basic_symbol : Base
+ {
+ /// Alias to Base.
+ typedef Base super_type;
+
+ /// Default constructor.
+ basic_symbol ();
+
+ /// Copy constructor.
+ basic_symbol (const basic_symbol& other);
+]b4_variant_if([[
+ /// Constructor for valueless symbols, and symbols from each type.
+]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[
+ /// Constructor for valueless symbols.
+ basic_symbol (typename Base::kind_type t]b4_locations_if([,
+ const location_type& l])[);]])[
+
+ /// Constructor for symbols with semantic value.
+ basic_symbol (typename Base::kind_type t,
+ const semantic_type& v]b4_locations_if([,
+ const location_type& l])[);
+
+ ~basic_symbol ();
+
+ /// Destructive move, \a s is emptied into this.
+ void move (basic_symbol& s);
+
+ /// The semantic value.
+ semantic_type value;]b4_locations_if([
+
+ /// The location.
+ location_type location;])[
+
+ private:
+ /// Assignment operator.
+ basic_symbol& operator= (const basic_symbol& other);
+ };
+
+ /// Type access provider for token (enum) based symbols.
+ struct by_type
+ {
+ /// Default constructor.
+ by_type ();
+
+ /// Copy constructor.
+ by_type (const by_type& other);
+
+ /// The symbol type as needed by the constructor.
+ typedef token_type kind_type;
+
+ /// Constructor from (external) token numbers.
+ by_type (kind_type t);
+
+ /// Steal the symbol type from \a that.
+ void move (by_type& that);
+
+ /// The (internal) type number (corresponding to \a type).
+ /// -1 when this symbol is empty.
+ symbol_number_type type_get () const;
+
+ /// The token.
+ token_type token () const;
+
+ enum { empty = 0 };
+
+ /// The symbol type.
+ /// -1 when this symbol is empty.
+ token_number_type type;
+ };
+
+ /// "External" symbols: returned by the scanner.
+ typedef basic_symbol<by_type> symbol_type;
+
+]b4_symbol_constructor_declare])
+
+
+# b4_public_types_define
+# ----------------------
+# Provide the implementation needed by the public types.
+m4_define([b4_public_types_define],
+[[ inline
+ ]b4_parser_class_name[::syntax_error::syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m)
+ : std::runtime_error (m)]b4_locations_if([
+ , location (l)])[
+ {}
+
+ // basic_symbol.
+ template <typename Base>
+ inline
+ ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol ()
+ : value ()
+ {}
+
+ template <typename Base>
+ inline
+ ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
+ : Base (other)
+ , value ()]b4_locations_if([
+ , location (other.location)])[
+ {
+ ]b4_variant_if([b4_symbol_variant([other.type_get ()], [value], [copy],
+ [other.value])],
+ [value = other.value;])[
+ }
+
+
+ template <typename Base>
+ inline
+ ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
+ [typename Base::kind_type t],
+ [const semantic_type& v],
+ b4_locations_if([const location_type& l]))[)
+ : Base (t)
+ , value (]b4_variant_if([], [v])[)]b4_locations_if([
+ , location (l)])[
+ {]b4_variant_if([[
+ (void) v;
+ ]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[}
+
+]b4_variant_if([[
+ // Implementation of basic_symbol constructor for each type.
+]b4_type_foreach([b4_basic_symbol_constructor_define])], [[
+ /// Constructor for valueless symbols.
+ template <typename Base>
+ inline
+ ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
+ [typename Base::kind_type t],
+ b4_locations_if([const location_type& l]))[)
+ : Base (t)
+ , value ()]b4_locations_if([
+ , location (l)])[
+ {}]])[
+
+ template <typename Base>
+ inline
+ ]b4_parser_class_name[::basic_symbol<Base>::~basic_symbol ()
+ {]b4_variant_if([[
+ // User destructor.
+ symbol_number_type yytype = this->type_get ();
+ switch (yytype)
+ {
+]b4_symbol_foreach([b4_symbol_destructor])dnl
+[ default:
+ break;
+ }
+
+ // Type destructor.
+ ]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[
+ }
+
+ template <typename Base>
+ inline
+ void
+ ]b4_parser_class_name[::basic_symbol<Base>::move (basic_symbol& s)
+ {
+ super_type::move(s);
+ ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move],
+ [s.value])],
+ [value = s.value;])[]b4_locations_if([
+ location = s.location;])[
+ }
+
+ // by_type.
+ inline
+ ]b4_parser_class_name[::by_type::by_type ()
+ : type (empty)
+ {}
+
+ inline
+ ]b4_parser_class_name[::by_type::by_type (const by_type& other)
+ : type (other.type)
+ {}
+
+ inline
+ ]b4_parser_class_name[::by_type::by_type (token_type t)
+ : type (yytranslate_ (t))
+ {}
+
+ inline
+ void
+ ]b4_parser_class_name[::by_type::move (by_type& that)
+ {
+ type = that.type;
+ that.type = empty;
+ }
+
+ inline
+ int
+ ]b4_parser_class_name[::by_type::type_get () const
+ {
+ return type;
+ }
+]b4_token_ctor_if([[
+ inline
+ ]b4_parser_class_name[::token_type
+ ]b4_parser_class_name[::by_type::token () const
+ {
+ // YYTOKNUM[NUM] -- (External) token number corresponding to the
+ // (internal) symbol number NUM (which must be that of a token). */
+ static
+ const ]b4_int_type_for([b4_toknum])[
+ yytoken_number_[] =
+ {
+ ]b4_toknum[
+ };
+ return static_cast<token_type> (yytoken_number_[type]);
+ }
+]])[]dnl
+b4_symbol_constructor_define])
+
+
+# b4_symbol_constructor_declare
+# b4_symbol_constructor_define
+# -----------------------------
+# Declare/define symbol constructors for all the value types.
+# Use at class-level. Redefined in variant.hh.
+m4_define([b4_symbol_constructor_declare], [])
+m4_define([b4_symbol_constructor_define], [])
+
+
+# b4_yytranslate_define
+# ---------------------
+# Define yytranslate_. Sometimes used in the header file,
+# sometimes in the cc file.
+m4_define([b4_yytranslate_define],
+[[ // Symbol number corresponding to token number t.
+ inline
+ ]b4_parser_class_name[::token_number_type
+ ]b4_parser_class_name[::yytranslate_ (]b4_token_ctor_if([token_type],
+ [int])[ t)
+ {
+ static
+ const token_number_type
+ translate_table[] =
+ {
+]b4_translate[
+ };
+ const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
+ const token_number_type undef_token_ = ]b4_undef_token_number[;
+
+ if (static_cast<int>(t) <= yyeof_)
+ return yyeof_;
+ else if (static_cast<unsigned int> (t) <= user_token_number_max_)
+ return translate_table[t];
+ else
+ return undef_token_;
+ }
+]])
+
+
+# b4_lhs_value([TYPE])
+# --------------------
+# Expansion of $<TYPE>$.
+m4_define([b4_lhs_value],
+[b4_symbol_value([yyval], [$1])])
+
+
+# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
+# --------------------------------------
+# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
+# symbols on RHS.
+m4_define([b4_rhs_value],
+[b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])])
+
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+[(yyloc)])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+[(yylocation_stack_@{($1) - ($2)@})])
+
+
+# b4_parse_param_decl
+# -------------------
+# Extra formal arguments of the constructor.
+# Change the parameter names from "foo" into "foo_yyarg", so that
+# there is no collision bw the user chosen attribute name, and the
+# argument name in the constructor.
+m4_define([b4_parse_param_decl],
+[m4_ifset([b4_parse_param],
+ [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
+
+m4_define([b4_parse_param_decl_1],
+[$1_yyarg])
+
+
+
+# b4_parse_param_cons
+# -------------------
+# Extra initialisations of the constructor.
+m4_define([b4_parse_param_cons],
+ [m4_ifset([b4_parse_param],
+ [
+ b4_cc_constructor_calls(b4_parse_param)])])
+m4_define([b4_cc_constructor_calls],
+ [m4_map_sep([b4_cc_constructor_call], [,
+ ], [$@])])
+m4_define([b4_cc_constructor_call],
+ [$2 ($2_yyarg)])
+
+# b4_parse_param_vars
+# -------------------
+# Extra instance variables.
+m4_define([b4_parse_param_vars],
+ [m4_ifset([b4_parse_param],
+ [
+ // User arguments.
+b4_cc_var_decls(b4_parse_param)])])
+m4_define([b4_cc_var_decls],
+ [m4_map_sep([b4_cc_var_decl], [
+], [$@])])
+m4_define([b4_cc_var_decl],
+ [ $1;])
+
+
+## ---------##
+## Values. ##
+## ---------##
+
+# b4_yylloc_default_define
+# ------------------------
+# Define YYLLOC_DEFAULT.
+m4_define([b4_yylloc_default_define],
+[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+# ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (N) \
+ { \
+ (Current).begin = YYRHSLOC (Rhs, 1).begin; \
+ (Current).end = YYRHSLOC (Rhs, N).end; \
+ } \
+ else \
+ { \
+ (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
+ } \
+ while (/*CONSTCOND*/ false)
+# endif
+]])
+
+## -------- ##
+## Checks. ##
+## -------- ##
+
+b4_token_ctor_if([b4_variant_if([],
+ [b4_fatal_at(b4_percent_define_get_loc(api.token.constructor),
+ [cannot use '%s' without '%s'],
+ [%define api.token.constructor],
+ [%define api.value.type variant]))])])
diff --git a/contrib/tools/bison/bison/data/c-like.m4 b/contrib/tools/bison/bison/data/c-like.m4
index eb06de2a4d..088cce94dd 100644
--- a/contrib/tools/bison/bison/data/c-like.m4
+++ b/contrib/tools/bison/bison/data/c-like.m4
@@ -1,65 +1,65 @@
- -*- Autoconf -*-
-
-# Common code for C-like languages (C, C++, Java, etc.)
-
-# Copyright (C) 2012-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# b4_comment_(TEXT, OPEN, CONTINUE, END)
-# --------------------------------------
-# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines.
-# Avoid adding indentation to the first line, as the indentation comes
-# from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]).
-#
-# Prefix all the output lines with PREFIX.
-m4_define([b4_comment_],
-[$2[]m4_bpatsubst(m4_expand([[$1]]), [
-\(.\)], [
-$3\1])$4])
-
-
-# b4_comment(TEXT, [PREFIX])
-# --------------------------
-# Put TEXT in comment. Prefix all the output lines with PREFIX.
-m4_define([b4_comment],
-[b4_comment_([$1], [$2/* ], [$2 ], [ */])])
-
-
-
-
-# b4_dollar_dollar_(VALUE, FIELD, DEFAULT-FIELD)
-# ----------------------------------------------
-# If FIELD (or DEFAULT-FIELD) is non-null, return "VALUE.FIELD",
-# otherwise just VALUE. Be sure to pass "(VALUE)" is VALUE is a
-# pointer.
-m4_define([b4_dollar_dollar_],
-[b4_symbol_value([$1],
- m4_if([$2], [[]],
- [[$3]], [[$2]]))])
-
-# b4_dollar_pushdef(VALUE-POINTER, DEFAULT-FIELD, LOCATION)
-# b4_dollar_popdef
-# ---------------------------------------------------------
-# Define b4_dollar_dollar for VALUE and DEFAULT-FIELD,
-# and b4_at_dollar for LOCATION.
-m4_define([b4_dollar_pushdef],
-[m4_pushdef([b4_dollar_dollar],
- [b4_dollar_dollar_([$1], m4_dquote($][1), [$2])])dnl
-m4_pushdef([b4_at_dollar], [$3])dnl
-])
-m4_define([b4_dollar_popdef],
-[m4_popdef([b4_at_dollar])dnl
-m4_popdef([b4_dollar_dollar])dnl
-])
+ -*- Autoconf -*-
+
+# Common code for C-like languages (C, C++, Java, etc.)
+
+# Copyright (C) 2012-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# b4_comment_(TEXT, OPEN, CONTINUE, END)
+# --------------------------------------
+# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines.
+# Avoid adding indentation to the first line, as the indentation comes
+# from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]).
+#
+# Prefix all the output lines with PREFIX.
+m4_define([b4_comment_],
+[$2[]m4_bpatsubst(m4_expand([[$1]]), [
+\(.\)], [
+$3\1])$4])
+
+
+# b4_comment(TEXT, [PREFIX])
+# --------------------------
+# Put TEXT in comment. Prefix all the output lines with PREFIX.
+m4_define([b4_comment],
+[b4_comment_([$1], [$2/* ], [$2 ], [ */])])
+
+
+
+
+# b4_dollar_dollar_(VALUE, FIELD, DEFAULT-FIELD)
+# ----------------------------------------------
+# If FIELD (or DEFAULT-FIELD) is non-null, return "VALUE.FIELD",
+# otherwise just VALUE. Be sure to pass "(VALUE)" is VALUE is a
+# pointer.
+m4_define([b4_dollar_dollar_],
+[b4_symbol_value([$1],
+ m4_if([$2], [[]],
+ [[$3]], [[$2]]))])
+
+# b4_dollar_pushdef(VALUE-POINTER, DEFAULT-FIELD, LOCATION)
+# b4_dollar_popdef
+# ---------------------------------------------------------
+# Define b4_dollar_dollar for VALUE and DEFAULT-FIELD,
+# and b4_at_dollar for LOCATION.
+m4_define([b4_dollar_pushdef],
+[m4_pushdef([b4_dollar_dollar],
+ [b4_dollar_dollar_([$1], m4_dquote($][1), [$2])])dnl
+m4_pushdef([b4_at_dollar], [$3])dnl
+])
+m4_define([b4_dollar_popdef],
+[m4_popdef([b4_at_dollar])dnl
+m4_popdef([b4_dollar_dollar])dnl
+])
diff --git a/contrib/tools/bison/bison/data/c-skel.m4 b/contrib/tools/bison/bison/data/c-skel.m4
index 36904aaf7b..89cb5c755c 100644
--- a/contrib/tools/bison/bison/data/c-skel.m4
+++ b/contrib/tools/bison/bison/data/c-skel.m4
@@ -1,26 +1,26 @@
- -*- Autoconf -*-
-
-# C skeleton dispatching for Bison.
-
-# Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])])
-b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])])
-
-m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[yacc.c]])
-m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
-
-m4_include(b4_used_skeleton)
+ -*- Autoconf -*-
+
+# C skeleton dispatching for Bison.
+
+# Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])])
+b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])])
+
+m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[yacc.c]])
+m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
+
+m4_include(b4_used_skeleton)
diff --git a/contrib/tools/bison/bison/data/c.m4 b/contrib/tools/bison/bison/data/c.m4
index b1b4394871..eec079557a 100644
--- a/contrib/tools/bison/bison/data/c.m4
+++ b/contrib/tools/bison/bison/data/c.m4
@@ -1,839 +1,839 @@
- -*- Autoconf -*-
-
-# C M4 Macros for Bison.
-
-# Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-m4_include(b4_pkgdatadir/[c-like.m4])
-
-# b4_tocpp(STRING)
-# ----------------
-# Convert STRING into a valid C macro name.
-m4_define([b4_tocpp],
-[m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))])
-
-
-# b4_cpp_guard(FILE)
-# ------------------
-# A valid C macro name to use as a CPP header guard for FILE.
-m4_define([b4_cpp_guard],
-[[YY_]b4_tocpp(m4_defn([b4_prefix])/[$1])[_INCLUDED]])
-
-
-# b4_cpp_guard_open(FILE)
-# b4_cpp_guard_close(FILE)
-# ------------------------
-# If FILE does not expand to nothing, open/close CPP inclusion guards for FILE.
-m4_define([b4_cpp_guard_open],
-[m4_ifval(m4_quote($1),
-[#ifndef b4_cpp_guard([$1])
-# define b4_cpp_guard([$1])])])
-
-m4_define([b4_cpp_guard_close],
-[m4_ifval(m4_quote($1),
-[#endif b4_comment([!b4_cpp_guard([$1])])])])
-
-
-## ---------------- ##
-## Identification. ##
-## ---------------- ##
-
-# b4_identification
-# -----------------
-# Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or
-# b4_pull_flag if they use the values of the %define variables api.pure or
-# api.push-pull.
-m4_define([b4_identification],
-[[/* Identify Bison output. */
-#define YYBISON 1
-
-/* Bison version. */
-#define YYBISON_VERSION "]b4_version["
-
-/* Skeleton name. */
-#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
-
-/* Pure parsers. */
-#define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[
-
-/* Push parsers. */
-#define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[
-
-/* Pull parsers. */
-#define YYPULL ]b4_pull_flag])[
-]])
-
-
-## ---------------- ##
-## Default values. ##
-## ---------------- ##
-
-# b4_api_prefix, b4_api_PREFIX
-# ----------------------------
-# Corresponds to %define api.prefix
-b4_percent_define_default([[api.prefix]], [[yy]])
-m4_define([b4_api_prefix],
-[b4_percent_define_get([[api.prefix]])])
-m4_define([b4_api_PREFIX],
-[m4_toupper(b4_api_prefix)])
-
-
-# b4_prefix
-# ---------
-# If the %name-prefix is not given, it is api.prefix.
-m4_define_default([b4_prefix], [b4_api_prefix])
-
-# If the %union is not named, its name is YYSTYPE.
-m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE])
-
-
-## ------------------------ ##
-## Pure/impure interfaces. ##
-## ------------------------ ##
-
-# b4_lex_formals
-# --------------
-# All the yylex formal arguments.
-# b4_lex_param arrives quoted twice, but we want to keep only one level.
-m4_define([b4_lex_formals],
-[b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl
-b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl
-m4_ifdef([b4_lex_param], [, ]b4_lex_param)])
-
-
-# b4_lex
-# ------
-# Call yylex.
-m4_define([b4_lex],
-[b4_function_call([yylex], [int], b4_lex_formals)])
-
-
-# b4_user_args
-# ------------
-m4_define([b4_user_args],
-[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
-
-
-# b4_parse_param
-# --------------
-# If defined, b4_parse_param arrives double quoted, but below we prefer
-# it to be single quoted.
-m4_define([b4_parse_param],
-b4_parse_param)
-
-
-# b4_parse_param_for(DECL, FORMAL, BODY)
-# ---------------------------------------
-# Iterate over the user parameters, binding the declaration to DECL,
-# the formal name to FORMAL, and evaluating the BODY.
-m4_define([b4_parse_param_for],
-[m4_foreach([$1_$2], m4_defn([b4_parse_param]),
-[m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl
-m4_pushdef([$2], m4_shift($1_$2))dnl
-$3[]dnl
-m4_popdef([$2])dnl
-m4_popdef([$1])dnl
-])])
-
-# b4_parse_param_use([VAL], [LOC])
-# --------------------------------
-# 'YYUSE' VAL, LOC if locations are enabled, and all the parse-params.
-m4_define([b4_parse_param_use],
-[m4_ifvaln([$1], [ YYUSE ([$1]);])dnl
-b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl
-b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
-])dnl
-])
-
-
-## ------------ ##
-## Data Types. ##
-## ------------ ##
-
-# b4_int_type(MIN, MAX)
-# ---------------------
-# Return the smallest int type able to handle numbers ranging from
-# MIN to MAX (included).
-m4_define([b4_int_type],
-[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
- b4_ints_in($@, [-128], [127]), [1], [signed char],
-
- b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
- b4_ints_in($@, [-32768], [32767]), [1], [short int],
-
- m4_eval([0 <= $1]), [1], [unsigned int],
-
- [int])])
-
-
-# b4_int_type_for(NAME)
-# ---------------------
-# Return the smallest int type able to handle numbers ranging from
-# 'NAME_min' to 'NAME_max' (included).
-m4_define([b4_int_type_for],
-[b4_int_type($1_min, $1_max)])
-
-
-# b4_table_value_equals(TABLE, VALUE, LITERAL)
-# --------------------------------------------
-# Without inducing a comparison warning from the compiler, check if the
-# literal value LITERAL equals VALUE from table TABLE, which must have
-# TABLE_min and TABLE_max defined.
-m4_define([b4_table_value_equals],
-[m4_if(m4_eval($3 < m4_indir([b4_]$1[_min])
- || m4_indir([b4_]$1[_max]) < $3), [1],
- [[0]],
- [(!!(($2) == ($3)))])])
-
-
-## ----------------- ##
-## Compiler issues. ##
-## ----------------- ##
-
-# b4_attribute_define
-# -------------------
-# Provide portability for __attribute__.
-m4_define([b4_attribute_define],
-[#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if (! defined __GNUC__ || __GNUC__ < 2 \
- || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
-# define __attribute__(Spec) /* empty */
-# endif
-#endif
-
-/* Suppress unused-variable warnings by "using" E. */
-#if ! defined lint || defined __GNUC__
-# define YYUSE(E) ((void) (E))
-#else
-# define YYUSE(E) /* empty */
-#endif
-
-#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
-/* Suppress an incorrect diagnostic about yylval being uninitialized. */
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
- _Pragma ("GCC diagnostic push") \
- _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
- _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
- _Pragma ("GCC diagnostic pop")
-#else
-# define YY_INITIAL_VALUE(Value) Value
-#endif
-#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END
-#endif
-#ifndef YY_INITIAL_VALUE
-# define YY_INITIAL_VALUE(Value) /* Nothing. */
-#endif
-])
-
-
-## ---------##
-## Values. ##
-## ---------##
-
-
-# b4_null_define
-# --------------
-# Portability issues: define a YY_NULL appropriate for the current
-# language (C, C++98, or C++11).
-m4_define([b4_null_define],
-[# ifndef YY_NULL
-# if defined __cplusplus && 201103L <= __cplusplus
-# define YY_NULL nullptr
-# else
-# define YY_NULL 0
-# endif
-# endif[]dnl
-])
-
-
-# b4_null
-# -------
-# Return a null pointer constant.
-m4_define([b4_null], [YY_NULL])
-
-# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
-# -------------------------------------------------------------
-# Define "yy<TABLE-NAME>" whose contents is CONTENT.
-m4_define([b4_integral_parser_table_define],
-[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl
-static const b4_int_type_for([$2]) yy$1[[]] =
-{
- $2
-};dnl
-])
-
-
-## ------------------------- ##
-## Assigning token numbers. ##
-## ------------------------- ##
-
-# b4_token_define(TOKEN-NUM)
-# --------------------------
-# Output the definition of this token as #define.
-m4_define([b4_token_define],
-[b4_token_format([#define %s %s], [$1])])
-
-# b4_token_defines
-# ----------------
-# Output the definition of the tokens.
-m4_define([b4_token_defines],
-[b4_any_token_visible_if([/* Tokens. */
-m4_join([
-], b4_symbol_map([b4_token_define]))
-])])
-
-
-# b4_token_enum(TOKEN-NUM)
-# ------------------------
-# Output the definition of this token as an enum.
-m4_define([b4_token_enum],
-[b4_token_format([%s = %s], [$1])])
-
-
-# b4_token_enums
-# --------------
-# Output the definition of the tokens (if there are) as enums.
-m4_define([b4_token_enums],
-[b4_any_token_visible_if([[/* Token type. */
-#ifndef ]b4_api_PREFIX[TOKENTYPE
-# define ]b4_api_PREFIX[TOKENTYPE
- enum ]b4_api_prefix[tokentype
- {
- ]m4_join([,
- ],
- b4_symbol_map([b4_token_enum]))[
- };
-#endif
-]])])
-
-
-# b4_token_enums_defines
-# ----------------------
-# Output the definition of the tokens (if there are any) as enums and,
-# if POSIX Yacc is enabled, as #defines.
-m4_define([b4_token_enums_defines],
-[b4_token_enums[]b4_yacc_if([b4_token_defines])])
-
-
-## ----------------- ##
-## Semantic Values. ##
-## ----------------- ##
-
-
-# b4_symbol_value(VAL, [TYPE])
-# ----------------------------
-# Given a semantic value VAL ($$, $1 etc.), extract its value of type
-# TYPE if TYPE is given, otherwise just return VAL. The result can be
-# used safetly, it is put in parens to avoid nasty precedence issues.
-# TYPE is *not* put in braces, provide some if needed.
-m4_define([b4_symbol_value],
-[($1[]m4_ifval([$2], [.$2]))])
-
-
-
-## ---------------------- ##
-## Defining C functions. ##
-## ---------------------- ##
-
-
-# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
-# -----------------------------------------------------------
-# Declare the function NAME in C.
-m4_define([b4_function_define],
-[$2
-$1 (b4_formals(m4_shift2($@)))[]dnl
-])
-
-
-# b4_formals([DECL1, NAME1], ...)
-# -------------------------------
-# The formal arguments of a C function definition.
-m4_define([b4_formals],
-[m4_if([$#], [0], [void],
- [$#$1], [1], [void],
- [m4_map_sep([b4_formal], [, ], [$@])])])
-
-m4_define([b4_formal],
-[$1])
-
-
-
-## ----------------------- ##
-## Declaring C functions. ##
-## ----------------------- ##
-
-
-# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
-# ------------------------------------------------------------
-# Declare the function NAME.
-m4_define([b4_function_declare],
-[$2 $1 (b4_formals(m4_shift2($@)));[]dnl
-])
-
-
-
-
-## --------------------- ##
-## Calling C functions. ##
-## --------------------- ##
-
-
-# b4_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
-# -----------------------------------------------------------
-# Call the function NAME with arguments NAME1, NAME2 etc.
-m4_define([b4_function_call],
-[$1 (b4_args(m4_shift2($@)))[]dnl
-])
-
-
-# b4_args([DECL1, NAME1], ...)
-# ----------------------------
-# Output the arguments NAME1, NAME2...
-m4_define([b4_args],
-[m4_map_sep([b4_arg], [, ], [$@])])
-
-m4_define([b4_arg],
-[$2])
-
-
-## ----------- ##
-## Synclines. ##
-## ----------- ##
-
-# b4_sync_start(LINE, FILE)
-# -------------------------
-m4_define([b4_sync_start], [[#]line $1 $2])
-
-
-## -------------- ##
-## User actions. ##
-## -------------- ##
-
-# b4_case(LABEL, STATEMENTS)
-# --------------------------
-m4_define([b4_case],
-[ case $1:
-$2
-b4_syncline([@oline@], [@ofile@])
- break;])
-
-
-# b4_predicate_case(LABEL, CONDITIONS)
-# ------------------------------------
-m4_define([b4_predicate_case],
-[ case $1:
- if (! ($2)) YYERROR;
-b4_syncline([@oline@], [@ofile@])
- break;])
-
-
-# b4_yydestruct_define
-# --------------------
-# Define the "yydestruct" function.
-m4_define_default([b4_yydestruct_define],
-[[/*-----------------------------------------------.
-| Release the memory associated to this symbol. |
-`-----------------------------------------------*/
-
-]b4_function_define([yydestruct],
- [static void],
- [[const char *yymsg], [yymsg]],
- [[int yytype], [yytype]],
- [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
-b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
-m4_ifset([b4_parse_param], [, b4_parse_param]))[
-{
-]b4_parse_param_use([yyvaluep], [yylocationp])dnl
-[ if (!yymsg)
- yymsg = "Deleting";
- YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
-
- YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
- ]b4_symbol_actions([destructor])[
- YY_IGNORE_MAYBE_UNINITIALIZED_END
-}]dnl
-])
-
-
-# b4_yy_symbol_print_define
-# -------------------------
-# Define the "yy_symbol_print" function.
-m4_define_default([b4_yy_symbol_print_define],
-[[
-/*----------------------------------------.
-| Print this symbol's value on YYOUTPUT. |
-`----------------------------------------*/
-
-]b4_function_define([yy_symbol_value_print],
- [static void],
- [[FILE *yyoutput], [yyoutput]],
- [[int yytype], [yytype]],
- [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
-b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
-m4_ifset([b4_parse_param], [, b4_parse_param]))[
-{
- FILE *yyo = yyoutput;
-]b4_parse_param_use([yyo], [yylocationp])dnl
-[ if (!yyvaluep)
- return;]
-dnl glr.c does not feature yytoknum.
-m4_if(b4_skeleton, ["yacc.c"],
-[[# ifdef YYPRINT
- if (yytype < YYNTOKENS)
- YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
-# endif
-]])dnl
- b4_symbol_actions([printer])[
-}
-
-
-/*--------------------------------.
-| Print this symbol on YYOUTPUT. |
-`--------------------------------*/
-
-]b4_function_define([yy_symbol_print],
- [static void],
- [[FILE *yyoutput], [yyoutput]],
- [[int yytype], [yytype]],
- [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
-b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
-m4_ifset([b4_parse_param], [, b4_parse_param]))[
-{
- YYFPRINTF (yyoutput, "%s %s (",
- yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
-
-]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
- YYFPRINTF (yyoutput, ": ");
-])dnl
-[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
-b4_locations_if([, yylocationp])[]b4_user_args[);
- YYFPRINTF (yyoutput, ")");
-}]dnl
-])
-
-
-## ---------------- ##
-## api.value.type. ##
-## ---------------- ##
-
-
-# ---------------------- #
-# api.value.type=union. #
-# ---------------------- #
-
-# b4_symbol_type_register(SYMBOL-NUM)
-# -----------------------------------
-# Symbol SYMBOL-NUM has a type (for variant) instead of a type-tag.
-# Extend the definition of %union's body with a field of that type,
-# and extend the symbol's "type" field to point to the field name,
-# instead of the type name.
-m4_define([b4_symbol_type_register],
-[m4_define([b4_symbol($1, type_tag)],
- [b4_symbol_if([$1], [has_id],
- [b4_symbol([$1], [id])],
- [yytype_[]b4_symbol([$1], [number])])])dnl
-m4_append([b4_user_union_members],
-m4_expand([
- b4_symbol_tag_comment([$1])dnl
- b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]))
-])
-
-
-# b4_type_define_tag(SYMBOL1-NUM, ...)
-# ------------------------------------
-# For the batch of symbols SYMBOL1-NUM... (which all have the same
-# type), enhance the %union definition for each of them, and set
-# there "type" field to the field tag name, instead of the type name.
-m4_define([b4_type_define_tag],
-[b4_symbol_if([$1], [has_type],
- [m4_map([b4_symbol_type_register], [$@])])
-])
-
-
-# b4_symbol_value_union(VAL, [TYPE])
-# ----------------------------------
-# Same of b4_symbol_value, but when api.value.type=union.
-m4_define([b4_symbol_value_union],
-[m4_ifval([$2],
- [(*($2*)(&$1))],
- [$1])])
-])
-
-
-# b4_value_type_setup_union
-# -------------------------
-# Setup support for api.value.type=union. Symbols are defined with a
-# type instead of a union member name: build the corresponding union,
-# and give the symbols their tag.
-m4_define([b4_value_type_setup_union],
-[m4_define([b4_union_members])
-b4_type_foreach([b4_type_define_tag])
-m4_copy_force([b4_symbol_value_union], [b4_symbol_value])
-])
-
-
-# ---------------- #
-# api.value.type. #
-# ---------------- #
-
-
-# b4_value_type_setup_variant
-# ---------------------------
-# Setup support for api.value.type=variant. By default, fail, specialized
-# by other skeletons.
-m4_define([b4_value_type_setup_variant],
-[b4_complain_at(b4_percent_define_get_loc([[api.value.type]]),
- [['%s' does not support '%s']],
- [b4_skeleton],
- [%define api.value.type variant])])
-
-
-# _b4_value_type_setup_keyword
-# ----------------------------
-# api.value.type is defined with a keyword/string syntax. Check if
-# that is properly defined, and prepare its use.
-m4_define([_b4_value_type_setup_keyword],
-[b4_percent_define_check_values([[[[api.value.type]],
- [[none]],
- [[union]],
- [[union-directive]],
- [[variant]],
- [[yystype]]]])dnl
-m4_case(b4_percent_define_get([[api.value.type]]),
- [union], [b4_value_type_setup_union],
- [variant], [b4_value_type_setup_variant])])
-
-
-# b4_value_type_setup
-# -------------------
-# Check if api.value.type is properly defined, and possibly prepare
-# its use.
-b4_define_silent([b4_value_type_setup],
-[# Define default value.
-b4_percent_define_ifdef([[api.value.type]], [],
-[# %union => api.value.type=union-directive
-m4_ifdef([b4_union_members],
-[m4_define([b4_percent_define_kind(api.value.type)], [keyword])
-m4_define([b4_percent_define(api.value.type)], [union-directive])],
-[# no tag seen => api.value.type={int}
-m4_if(b4_tag_seen_flag, 0,
-[m4_define([b4_percent_define_kind(api.value.type)], [code])
-m4_define([b4_percent_define(api.value.type)], [int])],
-[# otherwise api.value.type=yystype
-m4_define([b4_percent_define_kind(api.value.type)], [keyword])
-m4_define([b4_percent_define(api.value.type)], [yystype])])])])
-
-# Set up.
-m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
- [keyword\|string], [_b4_value_type_setup_keyword])
-])
-
-
-## -------------- ##
-## Declarations. ##
-## -------------- ##
-
-
-# b4_value_type_define
-# --------------------
-m4_define([b4_value_type_define],
-[b4_value_type_setup[]dnl
-/* Value type. */
-m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
-[code],
-[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
-typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE;
-# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
-# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
-#endif
-]],
-[m4_bmatch(b4_percent_define_get([[api.value.type]]),
-[union\|union-directive],
-[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
-typedef union ]b4_union_name[ ]b4_api_PREFIX[STYPE;
-union ]b4_union_name[
-{
-]b4_user_union_members[
-};
-# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
-# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
-#endif
-]])])])
-
-
-# b4_location_type_define
-# -----------------------
-m4_define([b4_location_type_define],
-[[/* Location type. */
-#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED
-typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE;
-struct ]b4_api_PREFIX[LTYPE
-{
- int first_line;
- int first_column;
- int last_line;
- int last_column;
-};
-# define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1
-# define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1
-#endif
-]])
-
-
-# b4_declare_yylstype
-# -------------------
-# Declarations that might either go into the header (if --defines) or
-# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
-m4_define([b4_declare_yylstype],
-[b4_value_type_define[]b4_locations_if([
-b4_location_type_define])
-
-b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval;
-]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
-])
-
-
-# b4_YYDEBUG_define
-# -----------------
-m4_define([b4_YYDEBUG_define],
-[[/* Debug traces. */
-]m4_if(b4_api_prefix, [yy],
-[[#ifndef YYDEBUG
-# define YYDEBUG ]b4_parse_trace_if([1], [0])[
-#endif]],
-[[#ifndef ]b4_api_PREFIX[DEBUG
-# if defined YYDEBUG
-#if YYDEBUG
-# define ]b4_api_PREFIX[DEBUG 1
-# else
-# define ]b4_api_PREFIX[DEBUG 0
-# endif
-# else /* ! defined YYDEBUG */
-# define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[
-# endif /* ! defined YYDEBUG */
-#endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl
-])
-
-# b4_declare_yydebug
-# ------------------
-m4_define([b4_declare_yydebug],
-[b4_YYDEBUG_define[
-#if ]b4_api_PREFIX[DEBUG
-extern int ]b4_prefix[debug;
-#endif][]dnl
-])
-
-# b4_yylloc_default_define
-# ------------------------
-# Define YYLLOC_DEFAULT.
-m4_define([b4_yylloc_default_define],
-[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
- while (0)
-#endif
-]])
-
-# b4_yy_location_print_define
-# ---------------------------
-# Define YY_LOCATION_PRINT.
-m4_define([b4_yy_location_print_define],
-[b4_locations_if([[
-/* YY_LOCATION_PRINT -- Print the location on the stream.
- This macro was not mandated originally: define only if we know
- we won't break user code: when these are the locations we know. */
-
-#ifndef YY_LOCATION_PRINT
-# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
-
-/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
-
-__attribute__((__unused__))
-]b4_function_define([yy_location_print_],
- [static unsigned],
- [[FILE *yyo], [yyo]],
- [[YYLTYPE const * const yylocp], [yylocp]])[
-{
- unsigned res = 0;
- int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
- if (0 <= yylocp->first_line)
- {
- res += YYFPRINTF (yyo, "%d", yylocp->first_line);
- if (0 <= yylocp->first_column)
- res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
- }
- if (0 <= yylocp->last_line)
- {
- if (yylocp->first_line < yylocp->last_line)
- {
- res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
- if (0 <= end_col)
- res += YYFPRINTF (yyo, ".%d", end_col);
- }
- else if (0 <= end_col && yylocp->first_column < end_col)
- res += YYFPRINTF (yyo, "-%d", end_col);
- }
- return res;
- }
-
-# define YY_LOCATION_PRINT(File, Loc) \
- yy_location_print_ (File, &(Loc))
-
-# else
-# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-# endif
-#endif]],
-[[/* This macro is provided for backward compatibility. */
-#ifndef YY_LOCATION_PRINT
-# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-#endif]])
-])
-
-# b4_yyloc_default
-# ----------------
-# Expand to a possible default value for yylloc.
-m4_define([b4_yyloc_default],
-[[
-# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
- = { ]m4_join([, ],
- m4_defn([b4_location_initial_line]),
- m4_defn([b4_location_initial_column]),
- m4_defn([b4_location_initial_line]),
- m4_defn([b4_location_initial_column]))[ }
-# endif
-]])
+ -*- Autoconf -*-
+
+# C M4 Macros for Bison.
+
+# Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include(b4_pkgdatadir/[c-like.m4])
+
+# b4_tocpp(STRING)
+# ----------------
+# Convert STRING into a valid C macro name.
+m4_define([b4_tocpp],
+[m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))])
+
+
+# b4_cpp_guard(FILE)
+# ------------------
+# A valid C macro name to use as a CPP header guard for FILE.
+m4_define([b4_cpp_guard],
+[[YY_]b4_tocpp(m4_defn([b4_prefix])/[$1])[_INCLUDED]])
+
+
+# b4_cpp_guard_open(FILE)
+# b4_cpp_guard_close(FILE)
+# ------------------------
+# If FILE does not expand to nothing, open/close CPP inclusion guards for FILE.
+m4_define([b4_cpp_guard_open],
+[m4_ifval(m4_quote($1),
+[#ifndef b4_cpp_guard([$1])
+# define b4_cpp_guard([$1])])])
+
+m4_define([b4_cpp_guard_close],
+[m4_ifval(m4_quote($1),
+[#endif b4_comment([!b4_cpp_guard([$1])])])])
+
+
+## ---------------- ##
+## Identification. ##
+## ---------------- ##
+
+# b4_identification
+# -----------------
+# Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or
+# b4_pull_flag if they use the values of the %define variables api.pure or
+# api.push-pull.
+m4_define([b4_identification],
+[[/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "]b4_version["
+
+/* Skeleton name. */
+#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
+
+/* Pure parsers. */
+#define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[
+
+/* Push parsers. */
+#define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[
+
+/* Pull parsers. */
+#define YYPULL ]b4_pull_flag])[
+]])
+
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# b4_api_prefix, b4_api_PREFIX
+# ----------------------------
+# Corresponds to %define api.prefix
+b4_percent_define_default([[api.prefix]], [[yy]])
+m4_define([b4_api_prefix],
+[b4_percent_define_get([[api.prefix]])])
+m4_define([b4_api_PREFIX],
+[m4_toupper(b4_api_prefix)])
+
+
+# b4_prefix
+# ---------
+# If the %name-prefix is not given, it is api.prefix.
+m4_define_default([b4_prefix], [b4_api_prefix])
+
+# If the %union is not named, its name is YYSTYPE.
+m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE])
+
+
+## ------------------------ ##
+## Pure/impure interfaces. ##
+## ------------------------ ##
+
+# b4_lex_formals
+# --------------
+# All the yylex formal arguments.
+# b4_lex_param arrives quoted twice, but we want to keep only one level.
+m4_define([b4_lex_formals],
+[b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl
+b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl
+m4_ifdef([b4_lex_param], [, ]b4_lex_param)])
+
+
+# b4_lex
+# ------
+# Call yylex.
+m4_define([b4_lex],
+[b4_function_call([yylex], [int], b4_lex_formals)])
+
+
+# b4_user_args
+# ------------
+m4_define([b4_user_args],
+[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
+
+
+# b4_parse_param
+# --------------
+# If defined, b4_parse_param arrives double quoted, but below we prefer
+# it to be single quoted.
+m4_define([b4_parse_param],
+b4_parse_param)
+
+
+# b4_parse_param_for(DECL, FORMAL, BODY)
+# ---------------------------------------
+# Iterate over the user parameters, binding the declaration to DECL,
+# the formal name to FORMAL, and evaluating the BODY.
+m4_define([b4_parse_param_for],
+[m4_foreach([$1_$2], m4_defn([b4_parse_param]),
+[m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl
+m4_pushdef([$2], m4_shift($1_$2))dnl
+$3[]dnl
+m4_popdef([$2])dnl
+m4_popdef([$1])dnl
+])])
+
+# b4_parse_param_use([VAL], [LOC])
+# --------------------------------
+# 'YYUSE' VAL, LOC if locations are enabled, and all the parse-params.
+m4_define([b4_parse_param_use],
+[m4_ifvaln([$1], [ YYUSE ([$1]);])dnl
+b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl
+b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
+])dnl
+])
+
+
+## ------------ ##
+## Data Types. ##
+## ------------ ##
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included).
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
+ b4_ints_in($@, [-128], [127]), [1], [signed char],
+
+ b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
+ b4_ints_in($@, [-32768], [32767]), [1], [short int],
+
+ m4_eval([0 <= $1]), [1], [unsigned int],
+
+ [int])])
+
+
+# b4_int_type_for(NAME)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# 'NAME_min' to 'NAME_max' (included).
+m4_define([b4_int_type_for],
+[b4_int_type($1_min, $1_max)])
+
+
+# b4_table_value_equals(TABLE, VALUE, LITERAL)
+# --------------------------------------------
+# Without inducing a comparison warning from the compiler, check if the
+# literal value LITERAL equals VALUE from table TABLE, which must have
+# TABLE_min and TABLE_max defined.
+m4_define([b4_table_value_equals],
+[m4_if(m4_eval($3 < m4_indir([b4_]$1[_min])
+ || m4_indir([b4_]$1[_max]) < $3), [1],
+ [[0]],
+ [(!!(($2) == ($3)))])])
+
+
+## ----------------- ##
+## Compiler issues. ##
+## ----------------- ##
+
+# b4_attribute_define
+# -------------------
+# Provide portability for __attribute__.
+m4_define([b4_attribute_define],
+[#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if (! defined __GNUC__ || __GNUC__ < 2 \
+ || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
+# define __attribute__(Spec) /* empty */
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(E) ((void) (E))
+#else
+# define YYUSE(E) /* empty */
+#endif
+
+#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
+/* Suppress an incorrect diagnostic about yylval being uninitialized. */
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define YY_INITIAL_VALUE(Value) Value
+#endif
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+])
+
+
+## ---------##
+## Values. ##
+## ---------##
+
+
+# b4_null_define
+# --------------
+# Portability issues: define a YY_NULL appropriate for the current
+# language (C, C++98, or C++11).
+m4_define([b4_null_define],
+[# ifndef YY_NULL
+# if defined __cplusplus && 201103L <= __cplusplus
+# define YY_NULL nullptr
+# else
+# define YY_NULL 0
+# endif
+# endif[]dnl
+])
+
+
+# b4_null
+# -------
+# Return a null pointer constant.
+m4_define([b4_null], [YY_NULL])
+
+# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
+# -------------------------------------------------------------
+# Define "yy<TABLE-NAME>" whose contents is CONTENT.
+m4_define([b4_integral_parser_table_define],
+[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl
+static const b4_int_type_for([$2]) yy$1[[]] =
+{
+ $2
+};dnl
+])
+
+
+## ------------------------- ##
+## Assigning token numbers. ##
+## ------------------------- ##
+
+# b4_token_define(TOKEN-NUM)
+# --------------------------
+# Output the definition of this token as #define.
+m4_define([b4_token_define],
+[b4_token_format([#define %s %s], [$1])])
+
+# b4_token_defines
+# ----------------
+# Output the definition of the tokens.
+m4_define([b4_token_defines],
+[b4_any_token_visible_if([/* Tokens. */
+m4_join([
+], b4_symbol_map([b4_token_define]))
+])])
+
+
+# b4_token_enum(TOKEN-NUM)
+# ------------------------
+# Output the definition of this token as an enum.
+m4_define([b4_token_enum],
+[b4_token_format([%s = %s], [$1])])
+
+
+# b4_token_enums
+# --------------
+# Output the definition of the tokens (if there are) as enums.
+m4_define([b4_token_enums],
+[b4_any_token_visible_if([[/* Token type. */
+#ifndef ]b4_api_PREFIX[TOKENTYPE
+# define ]b4_api_PREFIX[TOKENTYPE
+ enum ]b4_api_prefix[tokentype
+ {
+ ]m4_join([,
+ ],
+ b4_symbol_map([b4_token_enum]))[
+ };
+#endif
+]])])
+
+
+# b4_token_enums_defines
+# ----------------------
+# Output the definition of the tokens (if there are any) as enums and,
+# if POSIX Yacc is enabled, as #defines.
+m4_define([b4_token_enums_defines],
+[b4_token_enums[]b4_yacc_if([b4_token_defines])])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+# b4_symbol_value(VAL, [TYPE])
+# ----------------------------
+# Given a semantic value VAL ($$, $1 etc.), extract its value of type
+# TYPE if TYPE is given, otherwise just return VAL. The result can be
+# used safetly, it is put in parens to avoid nasty precedence issues.
+# TYPE is *not* put in braces, provide some if needed.
+m4_define([b4_symbol_value],
+[($1[]m4_ifval([$2], [.$2]))])
+
+
+
+## ---------------------- ##
+## Defining C functions. ##
+## ---------------------- ##
+
+
+# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# -----------------------------------------------------------
+# Declare the function NAME in C.
+m4_define([b4_function_define],
+[$2
+$1 (b4_formals(m4_shift2($@)))[]dnl
+])
+
+
+# b4_formals([DECL1, NAME1], ...)
+# -------------------------------
+# The formal arguments of a C function definition.
+m4_define([b4_formals],
+[m4_if([$#], [0], [void],
+ [$#$1], [1], [void],
+ [m4_map_sep([b4_formal], [, ], [$@])])])
+
+m4_define([b4_formal],
+[$1])
+
+
+
+## ----------------------- ##
+## Declaring C functions. ##
+## ----------------------- ##
+
+
+# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# ------------------------------------------------------------
+# Declare the function NAME.
+m4_define([b4_function_declare],
+[$2 $1 (b4_formals(m4_shift2($@)));[]dnl
+])
+
+
+
+
+## --------------------- ##
+## Calling C functions. ##
+## --------------------- ##
+
+
+# b4_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# -----------------------------------------------------------
+# Call the function NAME with arguments NAME1, NAME2 etc.
+m4_define([b4_function_call],
+[$1 (b4_args(m4_shift2($@)))[]dnl
+])
+
+
+# b4_args([DECL1, NAME1], ...)
+# ----------------------------
+# Output the arguments NAME1, NAME2...
+m4_define([b4_args],
+[m4_map_sep([b4_arg], [, ], [$@])])
+
+m4_define([b4_arg],
+[$2])
+
+
+## ----------- ##
+## Synclines. ##
+## ----------- ##
+
+# b4_sync_start(LINE, FILE)
+# -------------------------
+m4_define([b4_sync_start], [[#]line $1 $2])
+
+
+## -------------- ##
+## User actions. ##
+## -------------- ##
+
+# b4_case(LABEL, STATEMENTS)
+# --------------------------
+m4_define([b4_case],
+[ case $1:
+$2
+b4_syncline([@oline@], [@ofile@])
+ break;])
+
+
+# b4_predicate_case(LABEL, CONDITIONS)
+# ------------------------------------
+m4_define([b4_predicate_case],
+[ case $1:
+ if (! ($2)) YYERROR;
+b4_syncline([@oline@], [@ofile@])
+ break;])
+
+
+# b4_yydestruct_define
+# --------------------
+# Define the "yydestruct" function.
+m4_define_default([b4_yydestruct_define],
+[[/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+]b4_function_define([yydestruct],
+ [static void],
+ [[const char *yymsg], [yymsg]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
+b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
+{
+]b4_parse_param_use([yyvaluep], [yylocationp])dnl
+[ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ ]b4_symbol_actions([destructor])[
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}]dnl
+])
+
+
+# b4_yy_symbol_print_define
+# -------------------------
+# Define the "yy_symbol_print" function.
+m4_define_default([b4_yy_symbol_print_define],
+[[
+/*----------------------------------------.
+| Print this symbol's value on YYOUTPUT. |
+`----------------------------------------*/
+
+]b4_function_define([yy_symbol_value_print],
+ [static void],
+ [[FILE *yyoutput], [yyoutput]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
+b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
+{
+ FILE *yyo = yyoutput;
+]b4_parse_param_use([yyo], [yylocationp])dnl
+[ if (!yyvaluep)
+ return;]
+dnl glr.c does not feature yytoknum.
+m4_if(b4_skeleton, ["yacc.c"],
+[[# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# endif
+]])dnl
+ b4_symbol_actions([printer])[
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+]b4_function_define([yy_symbol_print],
+ [static void],
+ [[FILE *yyoutput], [yyoutput]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
+b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
+{
+ YYFPRINTF (yyoutput, "%s %s (",
+ yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
+
+]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
+ YYFPRINTF (yyoutput, ": ");
+])dnl
+[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
+b4_locations_if([, yylocationp])[]b4_user_args[);
+ YYFPRINTF (yyoutput, ")");
+}]dnl
+])
+
+
+## ---------------- ##
+## api.value.type. ##
+## ---------------- ##
+
+
+# ---------------------- #
+# api.value.type=union. #
+# ---------------------- #
+
+# b4_symbol_type_register(SYMBOL-NUM)
+# -----------------------------------
+# Symbol SYMBOL-NUM has a type (for variant) instead of a type-tag.
+# Extend the definition of %union's body with a field of that type,
+# and extend the symbol's "type" field to point to the field name,
+# instead of the type name.
+m4_define([b4_symbol_type_register],
+[m4_define([b4_symbol($1, type_tag)],
+ [b4_symbol_if([$1], [has_id],
+ [b4_symbol([$1], [id])],
+ [yytype_[]b4_symbol([$1], [number])])])dnl
+m4_append([b4_user_union_members],
+m4_expand([
+ b4_symbol_tag_comment([$1])dnl
+ b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]))
+])
+
+
+# b4_type_define_tag(SYMBOL1-NUM, ...)
+# ------------------------------------
+# For the batch of symbols SYMBOL1-NUM... (which all have the same
+# type), enhance the %union definition for each of them, and set
+# there "type" field to the field tag name, instead of the type name.
+m4_define([b4_type_define_tag],
+[b4_symbol_if([$1], [has_type],
+ [m4_map([b4_symbol_type_register], [$@])])
+])
+
+
+# b4_symbol_value_union(VAL, [TYPE])
+# ----------------------------------
+# Same of b4_symbol_value, but when api.value.type=union.
+m4_define([b4_symbol_value_union],
+[m4_ifval([$2],
+ [(*($2*)(&$1))],
+ [$1])])
+])
+
+
+# b4_value_type_setup_union
+# -------------------------
+# Setup support for api.value.type=union. Symbols are defined with a
+# type instead of a union member name: build the corresponding union,
+# and give the symbols their tag.
+m4_define([b4_value_type_setup_union],
+[m4_define([b4_union_members])
+b4_type_foreach([b4_type_define_tag])
+m4_copy_force([b4_symbol_value_union], [b4_symbol_value])
+])
+
+
+# ---------------- #
+# api.value.type. #
+# ---------------- #
+
+
+# b4_value_type_setup_variant
+# ---------------------------
+# Setup support for api.value.type=variant. By default, fail, specialized
+# by other skeletons.
+m4_define([b4_value_type_setup_variant],
+[b4_complain_at(b4_percent_define_get_loc([[api.value.type]]),
+ [['%s' does not support '%s']],
+ [b4_skeleton],
+ [%define api.value.type variant])])
+
+
+# _b4_value_type_setup_keyword
+# ----------------------------
+# api.value.type is defined with a keyword/string syntax. Check if
+# that is properly defined, and prepare its use.
+m4_define([_b4_value_type_setup_keyword],
+[b4_percent_define_check_values([[[[api.value.type]],
+ [[none]],
+ [[union]],
+ [[union-directive]],
+ [[variant]],
+ [[yystype]]]])dnl
+m4_case(b4_percent_define_get([[api.value.type]]),
+ [union], [b4_value_type_setup_union],
+ [variant], [b4_value_type_setup_variant])])
+
+
+# b4_value_type_setup
+# -------------------
+# Check if api.value.type is properly defined, and possibly prepare
+# its use.
+b4_define_silent([b4_value_type_setup],
+[# Define default value.
+b4_percent_define_ifdef([[api.value.type]], [],
+[# %union => api.value.type=union-directive
+m4_ifdef([b4_union_members],
+[m4_define([b4_percent_define_kind(api.value.type)], [keyword])
+m4_define([b4_percent_define(api.value.type)], [union-directive])],
+[# no tag seen => api.value.type={int}
+m4_if(b4_tag_seen_flag, 0,
+[m4_define([b4_percent_define_kind(api.value.type)], [code])
+m4_define([b4_percent_define(api.value.type)], [int])],
+[# otherwise api.value.type=yystype
+m4_define([b4_percent_define_kind(api.value.type)], [keyword])
+m4_define([b4_percent_define(api.value.type)], [yystype])])])])
+
+# Set up.
+m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
+ [keyword\|string], [_b4_value_type_setup_keyword])
+])
+
+
+## -------------- ##
+## Declarations. ##
+## -------------- ##
+
+
+# b4_value_type_define
+# --------------------
+m4_define([b4_value_type_define],
+[b4_value_type_setup[]dnl
+/* Value type. */
+m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
+[code],
+[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
+typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE;
+# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
+# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
+#endif
+]],
+[m4_bmatch(b4_percent_define_get([[api.value.type]]),
+[union\|union-directive],
+[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
+typedef union ]b4_union_name[ ]b4_api_PREFIX[STYPE;
+union ]b4_union_name[
+{
+]b4_user_union_members[
+};
+# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
+# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
+#endif
+]])])])
+
+
+# b4_location_type_define
+# -----------------------
+m4_define([b4_location_type_define],
+[[/* Location type. */
+#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED
+typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE;
+struct ]b4_api_PREFIX[LTYPE
+{
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+};
+# define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1
+# define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1
+#endif
+]])
+
+
+# b4_declare_yylstype
+# -------------------
+# Declarations that might either go into the header (if --defines) or
+# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
+m4_define([b4_declare_yylstype],
+[b4_value_type_define[]b4_locations_if([
+b4_location_type_define])
+
+b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval;
+]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
+])
+
+
+# b4_YYDEBUG_define
+# -----------------
+m4_define([b4_YYDEBUG_define],
+[[/* Debug traces. */
+]m4_if(b4_api_prefix, [yy],
+[[#ifndef YYDEBUG
+# define YYDEBUG ]b4_parse_trace_if([1], [0])[
+#endif]],
+[[#ifndef ]b4_api_PREFIX[DEBUG
+# if defined YYDEBUG
+#if YYDEBUG
+# define ]b4_api_PREFIX[DEBUG 1
+# else
+# define ]b4_api_PREFIX[DEBUG 0
+# endif
+# else /* ! defined YYDEBUG */
+# define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[
+# endif /* ! defined YYDEBUG */
+#endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl
+])
+
+# b4_declare_yydebug
+# ------------------
+m4_define([b4_declare_yydebug],
+[b4_YYDEBUG_define[
+#if ]b4_api_PREFIX[DEBUG
+extern int ]b4_prefix[debug;
+#endif][]dnl
+])
+
+# b4_yylloc_default_define
+# ------------------------
+# Define YYLLOC_DEFAULT.
+m4_define([b4_yylloc_default_define],
+[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (N) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (0)
+#endif
+]])
+
+# b4_yy_location_print_define
+# ---------------------------
+# Define YY_LOCATION_PRINT.
+m4_define([b4_yy_location_print_define],
+[b4_locations_if([[
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+ This macro was not mandated originally: define only if we know
+ we won't break user code: when these are the locations we know. */
+
+#ifndef YY_LOCATION_PRINT
+# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
+
+/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
+
+__attribute__((__unused__))
+]b4_function_define([yy_location_print_],
+ [static unsigned],
+ [[FILE *yyo], [yyo]],
+ [[YYLTYPE const * const yylocp], [yylocp]])[
+{
+ unsigned res = 0;
+ int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
+ if (0 <= yylocp->first_line)
+ {
+ res += YYFPRINTF (yyo, "%d", yylocp->first_line);
+ if (0 <= yylocp->first_column)
+ res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
+ }
+ if (0 <= yylocp->last_line)
+ {
+ if (yylocp->first_line < yylocp->last_line)
+ {
+ res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
+ if (0 <= end_col)
+ res += YYFPRINTF (yyo, ".%d", end_col);
+ }
+ else if (0 <= end_col && yylocp->first_column < end_col)
+ res += YYFPRINTF (yyo, "-%d", end_col);
+ }
+ return res;
+ }
+
+# define YY_LOCATION_PRINT(File, Loc) \
+ yy_location_print_ (File, &(Loc))
+
+# else
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif]],
+[[/* This macro is provided for backward compatibility. */
+#ifndef YY_LOCATION_PRINT
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+#endif]])
+])
+
+# b4_yyloc_default
+# ----------------
+# Expand to a possible default value for yylloc.
+m4_define([b4_yyloc_default],
+[[
+# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
+ = { ]m4_join([, ],
+ m4_defn([b4_location_initial_line]),
+ m4_defn([b4_location_initial_column]),
+ m4_defn([b4_location_initial_line]),
+ m4_defn([b4_location_initial_column]))[ }
+# endif
+]])
diff --git a/contrib/tools/bison/bison/data/glr.c b/contrib/tools/bison/bison/data/glr.c
index ff70890f33..a8dc5bc2d3 100644
--- a/contrib/tools/bison/bison/data/glr.c
+++ b/contrib/tools/bison/bison/data/glr.c
@@ -1,2563 +1,2563 @@
- -*- C -*-
-
-# GLR skeleton for Bison
-
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-# If we are loaded by glr.cc, do not override c++.m4 definitions by
-# those of c.m4.
-m4_if(b4_skeleton, ["glr.c"],
- [m4_include(b4_pkgdatadir/[c.m4])])
-
-## ---------------- ##
-## Default values. ##
-## ---------------- ##
-
-# Stack parameters.
-m4_define_default([b4_stack_depth_max], [10000])
-m4_define_default([b4_stack_depth_init], [200])
-
-
-
-## ------------------------ ##
-## Pure/impure interfaces. ##
-## ------------------------ ##
-
-b4_define_flag_if([pure])
-# If glr.cc is including this file and thus has already set b4_pure_flag,
-# do not change the value of b4_pure_flag, and do not record a use of api.pure.
-m4_ifndef([b4_pure_flag],
-[b4_percent_define_default([[api.pure]], [[false]])
- m4_define([b4_pure_flag],
- [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])])
-
-# b4_user_formals
-# ---------------
-# The possible parse-params formal arguments preceded by a comma.
-#
-# This is not shared with yacc.c in c.m4 because GLR relies on ISO C
-# formal argument declarations.
-m4_define([b4_user_formals],
-[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
-
-
-# b4_yyerror_args
-# ---------------
-# Optional effective arguments passed to yyerror: user args plus yylloc, and
-# a trailing comma.
-m4_define([b4_yyerror_args],
-[b4_pure_if([b4_locations_if([yylocp, ])])dnl
-m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
-
-
-# b4_lyyerror_args
-# ----------------
-# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
-m4_define([b4_lyyerror_args],
-[b4_pure_if([b4_locations_if([&yylloc, ])])dnl
-m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
-
-
-# b4_pure_args
-# ------------
-# Same as b4_yyerror_args, but with a leading comma.
-m4_define([b4_pure_args],
-[b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args])
-
-
-# b4_lpure_args
-# -------------
-# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
-m4_define([b4_lpure_args],
-[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args])
-
-
-
-# b4_pure_formals
-# ---------------
-# Arguments passed to yyerror: user formals plus yylocp with leading comma.
-m4_define([b4_pure_formals],
-[b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals])
-
-
-# b4_locuser_formals(LOC = yylocp)
-# --------------------------------
-m4_define([b4_locuser_formals],
-[b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals])
-
-
-# b4_locuser_args(LOC = yylocp)
-# -----------------------------
-m4_define([b4_locuser_args],
-[b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args])
-
-
-
-## ----------------- ##
-## Semantic Values. ##
-## ----------------- ##
-
-
-# b4_lhs_value([TYPE])
-# --------------------
-# Expansion of $<TYPE>$.
-m4_define([b4_lhs_value],
-[b4_symbol_value([(*yyvalp)], [$1])])
-
-
-# b4_rhs_data(RULE-LENGTH, NUM)
-# -----------------------------
-# Expand to the semantic stack place that contains value and location
-# of symbol number NUM in a rule of length RULE-LENGTH.
-m4_define([b4_rhs_data],
-[((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate])
-
-
-# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
-# --------------------------------------
-# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
-# symbols on RHS.
-m4_define([b4_rhs_value],
-[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])])
-
-
-
-## ----------- ##
-## Locations. ##
-## ----------- ##
-
-# b4_lhs_location()
-# -----------------
-# Expansion of @$.
-m4_define([b4_lhs_location],
-[(*yylocp)])
-
-
-# b4_rhs_location(RULE-LENGTH, NUM)
-# ---------------------------------
-# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
-# on RHS.
-m4_define([b4_rhs_location],
-[(b4_rhs_data([$1], [$2]).yyloc)])
-
-
-## -------------- ##
-## Declarations. ##
-## -------------- ##
-
-# b4_shared_declarations
-# ----------------------
-# Declaration that might either go into the header (if --defines)
-# or open coded in the parser body. glr.cc has its own definition.
-m4_if(b4_skeleton, ["glr.c"],
-[m4_define([b4_shared_declarations],
-[b4_declare_yydebug[
-]b4_percent_code_get([[requires]])[
-]b4_token_enums[
-]b4_declare_yylstype[
-]b4_function_declare(b4_prefix[parse], [int], b4_parse_param)[
-]b4_percent_code_get([[provides]])[]dnl
-])
-])
-
-## -------------- ##
-## Output files. ##
-## -------------- ##
-
-b4_output_begin([b4_parser_file_name])
-b4_copyright([Skeleton implementation for Bison GLR parsers in C],
- [2002-2013])[
-
-/* C GLR parser skeleton written by Paul Hilfinger. */
-
-]b4_identification
-
-b4_percent_code_get([[top]])[
-]m4_if(b4_api_prefix, [yy], [],
-[[/* Substitute the type names. */
-#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
-#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
-]m4_if(b4_prefix, [yy], [],
-[[/* Substitute the variable and function names. */
-#define yyparse ]b4_prefix[parse
-#define yylex ]b4_prefix[lex
-#define yyerror ]b4_prefix[error
-#define yydebug ]b4_prefix[debug
-]]b4_pure_if([], [[
-#define yylval ]b4_prefix[lval
-#define yychar ]b4_prefix[char
-#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
-#define yylloc ]b4_prefix[lloc]])]))[
-
-/* First part of user declarations. */
-]b4_user_pre_prologue[
-
-]b4_null_define[
-
-]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
- [b4_shared_declarations])[
-
-/* Enabling verbose error messages. */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
-#endif
-
-/* Default (constant) value used for initialization for null
- right-hand sides. Unlike the standard yacc.c template, here we set
- the default value of $$ to a zeroed-out value. Since the default
- value is undefined, this behavior is technically correct. */
-static YYSTYPE yyval_default;]b4_locations_if([[
-static YYLTYPE yyloc_default][]b4_yyloc_default;])[
-
-/* Copy the second part of user declarations. */
-]b4_user_post_prologue
-b4_percent_code_get[]dnl
-
-[#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
-# if ENABLE_NLS
-# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
-# endif
-# endif
-# ifndef YY_
-# define YY_(Msgid) Msgid
-# endif
-#endif
-
-#ifndef YYFREE
-# define YYFREE free
-#endif
-#ifndef YYMALLOC
-# define YYMALLOC malloc
-#endif
-#ifndef YYREALLOC
-# define YYREALLOC realloc
-#endif
-
-#define YYSIZEMAX ((size_t) -1)
-
-#ifdef __cplusplus
- typedef bool yybool;
-#else
- typedef unsigned char yybool;
-#endif
-#define yytrue 1
-#define yyfalse 0
-
-#ifndef YYSETJMP
-# include <setjmp.h>
-# define YYJMP_BUF jmp_buf
-# define YYSETJMP(Env) setjmp (Env)
-/* Pacify clang. */
-# define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
-#endif
-
-]b4_attribute_define[
-
-#ifndef YYASSERT
-# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
-#endif
-
-/* YYFINAL -- State number of the termination state. */
-#define YYFINAL ]b4_final_state_number[
-/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST ]b4_last[
-
-/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS ]b4_tokens_number[
-/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS ]b4_nterms_number[
-/* YYNRULES -- Number of rules. */
-#define YYNRULES ]b4_rules_number[
-/* YYNRULES -- Number of states. */
-#define YYNSTATES ]b4_states_number[
-/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
-#define YYMAXRHS ]b4_r2_max[
-/* YYMAXLEFT -- Maximum number of symbols to the left of a handle
- accessed by $0, $-1, etc., in any rule. */
-#define YYMAXLEFT ]b4_max_left_semantic_context[
-
-/* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
-#define YYUNDEFTOK ]b4_undef_token_number[
-#define YYMAXUTOK ]b4_user_token_number_max[
-
-#define YYTRANSLATE(YYX) \
- ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-
-/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
-static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
-{
- ]b4_translate[
-};
-
-#if ]b4_api_PREFIX[DEBUG
-/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
-static const ]b4_int_type_for([b4_rline])[ yyrline[] =
-{
- ]b4_rline[
-};
-#endif
-
-#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
-/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
-{
- ]b4_tname[
-};
-#endif
-
-#define YYPACT_NINF ]b4_pact_ninf[
-#define YYTABLE_NINF ]b4_table_ninf[
-
-]b4_parser_tables_define[
-
-/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
-static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
-{
- ]b4_dprec[
-};
-
-/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
-static const ]b4_int_type_for([b4_merger])[ yymerger[] =
-{
- ]b4_merger[
-};
-
-/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
- in the case of predicates. */
-static const yybool yyimmediate[] =
-{
- ]b4_immediate[
-};
-
-/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
- list of conflicting reductions corresponding to action entry for
- state STATE-NUM in yytable. 0 means no conflicts. The list in
- yyconfl is terminated by a rule number of 0. */
-static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
-{
- ]b4_conflict_list_heads[
-};
-
-/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
- 0, pointed into by YYCONFLP. */
-]dnl Do not use b4_int_type_for here, since there are places where
-dnl pointers onto yyconfl are taken, whose type is "short int *".
-dnl We probably ought to introduce a type for confl.
-[static const short int yyconfl[] =
-{
- ]b4_conflicting_rules[
-};
-
-/* Error token number */
-#define YYTERROR 1
-
-]b4_locations_if([[
-]b4_yylloc_default_define[
-# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
-]])[
-
-]b4_pure_if(
-[
-#undef yynerrs
-#define yynerrs (yystackp->yyerrcnt)
-#undef yychar
-#define yychar (yystackp->yyrawchar)
-#undef yylval
-#define yylval (yystackp->yyval)
-#undef yylloc
-#define yylloc (yystackp->yyloc)
-m4_if(b4_prefix[], [yy], [],
-[#define b4_prefix[]nerrs yynerrs
-#define b4_prefix[]char yychar
-#define b4_prefix[]lval yylval
-#define b4_prefix[]lloc yylloc])],
-[YYSTYPE yylval;]b4_locations_if([[
-YYLTYPE yylloc;]])[
-
-int yynerrs;
-int yychar;])[
-
-static const int YYEOF = 0;
-static const int YYEMPTY = -2;
-
-typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
-
-#define YYCHK(YYE) \
- do { \
- YYRESULTTAG yychk_flag = YYE; \
- if (yychk_flag != yyok) \
- return yychk_flag; \
- } while (0)
-
-#if ]b4_api_PREFIX[DEBUG
-
-# ifndef YYFPRINTF
-# define YYFPRINTF fprintf
-# endif
-
-]b4_yy_location_print_define[
-
-# define YYDPRINTF(Args) \
- do { \
- if (yydebug) \
- YYFPRINTF Args; \
- } while (0)
-
-]b4_yy_symbol_print_define[
-
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
- do { \
- if (yydebug) \
- { \
- YYFPRINTF (stderr, "%s ", Title); \
- yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
- YYFPRINTF (stderr, "\n"); \
- } \
- } while (0)
-
-/* Nonzero means print parse trace. It is left uninitialized so that
- multiple parsers can coexist. */
-int yydebug;
-
-struct yyGLRStack;
-static void yypstack (struct yyGLRStack* yystackp, size_t yyk)
- __attribute__ ((__unused__));
-static void yypdumpstack (struct yyGLRStack* yystackp)
- __attribute__ ((__unused__));
-
-#else /* !]b4_api_PREFIX[DEBUG */
-
-# define YYDPRINTF(Args)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
-
-#endif /* !]b4_api_PREFIX[DEBUG */
-
-/* YYINITDEPTH -- initial size of the parser's stacks. */
-#ifndef YYINITDEPTH
-# define YYINITDEPTH ]b4_stack_depth_init[
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
- if the built-in stack extension method is used).
-
- Do not make this value too large; the results are undefined if
- SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
- evaluated with infinite-precision integer arithmetic. */
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH ]b4_stack_depth_max[
-#endif
-
-/* Minimum number of free items on the stack allowed after an
- allocation. This is to allow allocation and initialization
- to be completed by functions that call yyexpandGLRStack before the
- stack is expanded, thus insuring that all necessary pointers get
- properly redirected to new data. */
-#define YYHEADROOM 2
-
-#ifndef YYSTACKEXPANDABLE
-# define YYSTACKEXPANDABLE 1
-#endif
-
-#if YYSTACKEXPANDABLE
-# define YY_RESERVE_GLRSTACK(Yystack) \
- do { \
- if (Yystack->yyspaceLeft < YYHEADROOM) \
- yyexpandGLRStack (Yystack); \
- } while (0)
-#else
-# define YY_RESERVE_GLRSTACK(Yystack) \
- do { \
- if (Yystack->yyspaceLeft < YYHEADROOM) \
- yyMemoryExhausted (Yystack); \
- } while (0)
-#endif
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystpcpy
-# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
-# define yystpcpy stpcpy
-# else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
- YYDEST. */
-static char *
-yystpcpy (char *yydest, const char *yysrc)
-{
- char *yyd = yydest;
- const char *yys = yysrc;
-
- while ((*yyd++ = *yys++) != '\0')
- continue;
-
- return yyd - 1;
-}
-# endif
-# endif
-
-# ifndef yytnamerr
-/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
- quotes and backslashes, so that it's suitable for yyerror. The
- heuristic is that double-quoting is unnecessary unless the string
- contains an apostrophe, a comma, or backslash (other than
- backslash-backslash). YYSTR is taken from yytname. If YYRES is
- null, do not copy; instead, return the length of what the result
- would have been. */
-static size_t
-yytnamerr (char *yyres, const char *yystr)
-{
- if (*yystr == '"')
- {
- size_t yyn = 0;
- char const *yyp = yystr;
-
- for (;;)
- switch (*++yyp)
- {
- case '\'':
- case ',':
- goto do_not_strip_quotes;
-
- case '\\':
- if (*++yyp != '\\')
- goto do_not_strip_quotes;
- /* Fall through. */
- default:
- if (yyres)
- yyres[yyn] = *yyp;
- yyn++;
- break;
-
- case '"':
- if (yyres)
- yyres[yyn] = '\0';
- return yyn;
- }
- do_not_strip_quotes: ;
- }
-
- if (! yyres)
- return strlen (yystr);
-
- return yystpcpy (yyres, yystr) - yyres;
-}
-# endif
-
-#endif /* !YYERROR_VERBOSE */
-
-/** State numbers, as in LALR(1) machine */
-typedef int yyStateNum;
-
-/** Rule numbers, as in LALR(1) machine */
-typedef int yyRuleNum;
-
-/** Grammar symbol */
-typedef int yySymbol;
-
-/** Item references, as in LALR(1) machine */
-typedef short int yyItemNum;
-
-typedef struct yyGLRState yyGLRState;
-typedef struct yyGLRStateSet yyGLRStateSet;
-typedef struct yySemanticOption yySemanticOption;
-typedef union yyGLRStackItem yyGLRStackItem;
-typedef struct yyGLRStack yyGLRStack;
-
-struct yyGLRState {
- /** Type tag: always true. */
- yybool yyisState;
- /** Type tag for yysemantics. If true, yysval applies, otherwise
- * yyfirstVal applies. */
- yybool yyresolved;
- /** Number of corresponding LALR(1) machine state. */
- yyStateNum yylrState;
- /** Preceding state in this stack */
- yyGLRState* yypred;
- /** Source position of the last token produced by my symbol */
- size_t yyposn;
- union {
- /** First in a chain of alternative reductions producing the
- * non-terminal corresponding to this state, threaded through
- * yynext. */
- yySemanticOption* yyfirstVal;
- /** Semantic value for this state. */
- YYSTYPE yysval;
- } yysemantics;]b4_locations_if([[
- /** Source location for this state. */
- YYLTYPE yyloc;]])[
-};
-
-struct yyGLRStateSet {
- yyGLRState** yystates;
- /** During nondeterministic operation, yylookaheadNeeds tracks which
- * stacks have actually needed the current lookahead. During deterministic
- * operation, yylookaheadNeeds[0] is not maintained since it would merely
- * duplicate yychar != YYEMPTY. */
- yybool* yylookaheadNeeds;
- size_t yysize, yycapacity;
-};
-
-struct yySemanticOption {
- /** Type tag: always false. */
- yybool yyisState;
- /** Rule number for this reduction */
- yyRuleNum yyrule;
- /** The last RHS state in the list of states to be reduced. */
- yyGLRState* yystate;
- /** The lookahead for this reduction. */
- int yyrawchar;
- YYSTYPE yyval;]b4_locations_if([[
- YYLTYPE yyloc;]])[
- /** Next sibling in chain of options. To facilitate merging,
- * options are chained in decreasing order by address. */
- yySemanticOption* yynext;
-};
-
-/** Type of the items in the GLR stack. The yyisState field
- * indicates which item of the union is valid. */
-union yyGLRStackItem {
- yyGLRState yystate;
- yySemanticOption yyoption;
-};
-
-struct yyGLRStack {
- int yyerrState;
-]b4_locations_if([[ /* To compute the location of the error token. */
- yyGLRStackItem yyerror_range[3];]])[
-]b4_pure_if(
-[
- int yyerrcnt;
- int yyrawchar;
- YYSTYPE yyval;]b4_locations_if([[
- YYLTYPE yyloc;]])[
-])[
- YYJMP_BUF yyexception_buffer;
- yyGLRStackItem* yyitems;
- yyGLRStackItem* yynextFree;
- size_t yyspaceLeft;
- yyGLRState* yysplitPoint;
- yyGLRState* yylastDeleted;
- yyGLRStateSet yytops;
-};
-
-#if YYSTACKEXPANDABLE
-static void yyexpandGLRStack (yyGLRStack* yystackp);
-#endif
-
-static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
- __attribute__ ((__noreturn__));
-static void
-yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
-{
- if (yymsg != YY_NULL)
- yyerror (]b4_yyerror_args[yymsg);
- YYLONGJMP (yystackp->yyexception_buffer, 1);
-}
-
-static void yyMemoryExhausted (yyGLRStack* yystackp)
- __attribute__ ((__noreturn__));
-static void
-yyMemoryExhausted (yyGLRStack* yystackp)
-{
- YYLONGJMP (yystackp->yyexception_buffer, 2);
-}
-
-#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
-/** A printable representation of TOKEN. */
-static inline const char*
-yytokenName (yySymbol yytoken)
-{
- if (yytoken == YYEMPTY)
- return "";
-
- return yytname[yytoken];
-}
-#endif
-
-/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
- * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
- * containing the pointer to the next state in the chain. */
-static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
-static void
-yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
-{
- int i;
- yyGLRState *s = yyvsp[yylow0].yystate.yypred;
- for (i = yylow0-1; i >= yylow1; i -= 1)
- {
-#if ]b4_api_PREFIX[DEBUG
- yyvsp[i].yystate.yylrState = s->yylrState;
-#endif
- yyvsp[i].yystate.yyresolved = s->yyresolved;
- if (s->yyresolved)
- yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
- else
- /* The effect of using yysval or yyloc (in an immediate rule) is
- * undefined. */
- yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULL;]b4_locations_if([[
- yyvsp[i].yystate.yyloc = s->yyloc;]])[
- s = yyvsp[i].yystate.yypred = s->yypred;
- }
-}
-
-/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
- * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
- * For convenience, always return YYLOW1. */
-static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
- __attribute__ ((__unused__));
-static inline int
-yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
-{
- if (!yynormal && yylow1 < *yylow)
- {
- yyfillin (yyvsp, *yylow, yylow1);
- *yylow = yylow1;
- }
- return yylow1;
-}
-
-/** Perform user action for rule number YYN, with RHS length YYRHSLEN,
- * and top stack item YYVSP. YYLVALP points to place to put semantic
- * value ($$), and yylocp points to place for location information
- * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
- * yyerr for YYERROR, yyabort for YYABORT. */
-static YYRESULTTAG
-yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
- yyGLRStack* yystackp,
- YYSTYPE* yyvalp]b4_locuser_formals[)
-{
- yybool yynormal __attribute__ ((__unused__)) =
- (yystackp->yysplitPoint == YY_NULL);
- int yylow;
-]b4_parse_param_use([yyvalp], [yylocp])dnl
-[ YYUSE (yyrhslen);
-# undef yyerrok
-# define yyerrok (yystackp->yyerrState = 0)
-# undef YYACCEPT
-# define YYACCEPT return yyaccept
-# undef YYABORT
-# define YYABORT return yyabort
-# undef YYERROR
-# define YYERROR return yyerrok, yyerr
-# undef YYRECOVERING
-# define YYRECOVERING() (yystackp->yyerrState != 0)
-# undef yyclearin
-# define yyclearin (yychar = YYEMPTY)
-# undef YYFILL
-# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
-# undef YYBACKUP
-# define YYBACKUP(Token, Value) \
- return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
- yyerrok, yyerr
-
- yylow = 1;
- if (yyrhslen == 0)
- *yyvalp = yyval_default;
- else
- *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
- YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
- yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
-]])[
- switch (yyn)
- {
- ]b4_user_actions[
- default: break;
- }
-
- return yyok;
-# undef yyerrok
-# undef YYABORT
-# undef YYACCEPT
-# undef YYERROR
-# undef YYBACKUP
-# undef yyclearin
-# undef YYRECOVERING
-}
-
-
-static void
-yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
-{
- YYUSE (yy0);
- YYUSE (yy1);
-
- switch (yyn)
- {
-]b4_mergers[
- default: break;
- }
-}
-
- /* Bison grammar-table manipulation. */
-
-]b4_yydestruct_define[
-
-/** Number of symbols composing the right hand side of rule #RULE. */
-static inline int
-yyrhsLength (yyRuleNum yyrule)
-{
- return yyr2[yyrule];
-}
-
-static void
-yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
-{
- if (yys->yyresolved)
- yydestruct (yymsg, yystos[yys->yylrState],
- &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
- else
- {
-#if ]b4_api_PREFIX[DEBUG
- if (yydebug)
- {
- if (yys->yysemantics.yyfirstVal)
- YYFPRINTF (stderr, "%s unresolved ", yymsg);
- else
- YYFPRINTF (stderr, "%s incomplete ", yymsg);
- yy_symbol_print (stderr, yystos[yys->yylrState],
- YY_NULL]b4_locuser_args([&yys->yyloc])[);
- YYFPRINTF (stderr, "\n");
- }
-#endif
-
- if (yys->yysemantics.yyfirstVal)
- {
- yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
- yyGLRState *yyrh;
- int yyn;
- for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
- yyn > 0;
- yyrh = yyrh->yypred, yyn -= 1)
- yydestroyGLRState (yymsg, yyrh]b4_user_args[);
- }
- }
-}
-
-/** Left-hand-side symbol for rule #YYRULE. */
-static inline yySymbol
-yylhsNonterm (yyRuleNum yyrule)
-{
- return yyr1[yyrule];
-}
-
-#define yypact_value_is_default(Yystate) \
- ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
-
-/** True iff LR state YYSTATE has only a default reduction (regardless
- * of token). */
-static inline yybool
-yyisDefaultedState (yyStateNum yystate)
-{
- return yypact_value_is_default (yypact[yystate]);
-}
-
-/** The default reduction for YYSTATE, assuming it has one. */
-static inline yyRuleNum
-yydefaultAction (yyStateNum yystate)
-{
- return yydefact[yystate];
-}
-
-#define yytable_value_is_error(Yytable_value) \
- ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
-
-/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
- * Result R means
- * R < 0: Reduce on rule -R.
- * R = 0: Error.
- * R > 0: Shift to state R.
- * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
- * of conflicting reductions.
- */
-static inline void
-yygetLRActions (yyStateNum yystate, int yytoken,
- int* yyaction, const short int** yyconflicts)
-{
- int yyindex = yypact[yystate] + yytoken;
- if (yypact_value_is_default (yypact[yystate])
- || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
- {
- *yyaction = -yydefact[yystate];
- *yyconflicts = yyconfl;
- }
- else if (! yytable_value_is_error (yytable[yyindex]))
- {
- *yyaction = yytable[yyindex];
- *yyconflicts = yyconfl + yyconflp[yyindex];
- }
- else
- {
- *yyaction = 0;
- *yyconflicts = yyconfl + yyconflp[yyindex];
- }
-}
-
-static inline yyStateNum
-yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
-{
- int yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
- if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
- return yytable[yyr];
- else
- return yydefgoto[yylhs - YYNTOKENS];
-}
-
-static inline yybool
-yyisShiftAction (int yyaction)
-{
- return 0 < yyaction;
-}
-
-static inline yybool
-yyisErrorAction (int yyaction)
-{
- return yyaction == 0;
-}
-
- /* GLRStates */
-
-/** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
- * if YYISSTATE, and otherwise a semantic option. Callers should call
- * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
- * headroom. */
-
-static inline yyGLRStackItem*
-yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
-{
- yyGLRStackItem* yynewItem = yystackp->yynextFree;
- yystackp->yyspaceLeft -= 1;
- yystackp->yynextFree += 1;
- yynewItem->yystate.yyisState = yyisState;
- return yynewItem;
-}
-
-/** Add a new semantic action that will execute the action for rule
- * YYRULE on the semantic values in YYRHS to the list of
- * alternative actions for YYSTATE. Assumes that YYRHS comes from
- * stack #YYK of *YYSTACKP. */
-static void
-yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
- yyGLRState* yyrhs, yyRuleNum yyrule)
-{
- yySemanticOption* yynewOption =
- &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
- yynewOption->yystate = yyrhs;
- yynewOption->yyrule = yyrule;
- if (yystackp->yytops.yylookaheadNeeds[yyk])
- {
- yynewOption->yyrawchar = yychar;
- yynewOption->yyval = yylval;]b4_locations_if([
- yynewOption->yyloc = yylloc;])[
- }
- else
- yynewOption->yyrawchar = YYEMPTY;
- yynewOption->yynext = yystate->yysemantics.yyfirstVal;
- yystate->yysemantics.yyfirstVal = yynewOption;
-
- YY_RESERVE_GLRSTACK (yystackp);
-}
-
- /* GLRStacks */
-
-/** Initialize YYSET to a singleton set containing an empty stack. */
-static yybool
-yyinitStateSet (yyGLRStateSet* yyset)
-{
- yyset->yysize = 1;
- yyset->yycapacity = 16;
- yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
- if (! yyset->yystates)
- return yyfalse;
- yyset->yystates[0] = YY_NULL;
- yyset->yylookaheadNeeds =
- (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
- if (! yyset->yylookaheadNeeds)
- {
- YYFREE (yyset->yystates);
- return yyfalse;
- }
- return yytrue;
-}
-
-static void yyfreeStateSet (yyGLRStateSet* yyset)
-{
- YYFREE (yyset->yystates);
- YYFREE (yyset->yylookaheadNeeds);
-}
-
-/** Initialize *YYSTACKP to a single empty stack, with total maximum
- * capacity for all stacks of YYSIZE. */
-static yybool
-yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
-{
- yystackp->yyerrState = 0;
- yynerrs = 0;
- yystackp->yyspaceLeft = yysize;
- yystackp->yyitems =
- (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
- if (!yystackp->yyitems)
- return yyfalse;
- yystackp->yynextFree = yystackp->yyitems;
- yystackp->yysplitPoint = YY_NULL;
- yystackp->yylastDeleted = YY_NULL;
- return yyinitStateSet (&yystackp->yytops);
-}
-
-
-#if YYSTACKEXPANDABLE
-# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
- &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
-
-/** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
- stack from outside should be considered invalid after this call.
- We always expand when there are 1 or fewer items left AFTER an
- allocation, so that we can avoid having external pointers exist
- across an allocation. */
-static void
-yyexpandGLRStack (yyGLRStack* yystackp)
-{
- yyGLRStackItem* yynewItems;
- yyGLRStackItem* yyp0, *yyp1;
- size_t yynewSize;
- size_t yyn;
- size_t yysize = yystackp->yynextFree - yystackp->yyitems;
- if (YYMAXDEPTH - YYHEADROOM < yysize)
- yyMemoryExhausted (yystackp);
- yynewSize = 2*yysize;
- if (YYMAXDEPTH < yynewSize)
- yynewSize = YYMAXDEPTH;
- yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
- if (! yynewItems)
- yyMemoryExhausted (yystackp);
- for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
- 0 < yyn;
- yyn -= 1, yyp0 += 1, yyp1 += 1)
- {
- *yyp1 = *yyp0;
- if (*(yybool *) yyp0)
- {
- yyGLRState* yys0 = &yyp0->yystate;
- yyGLRState* yys1 = &yyp1->yystate;
- if (yys0->yypred != YY_NULL)
- yys1->yypred =
- YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
- if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL)
- yys1->yysemantics.yyfirstVal =
- YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
- }
- else
- {
- yySemanticOption* yyv0 = &yyp0->yyoption;
- yySemanticOption* yyv1 = &yyp1->yyoption;
- if (yyv0->yystate != YY_NULL)
- yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
- if (yyv0->yynext != YY_NULL)
- yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
- }
- }
- if (yystackp->yysplitPoint != YY_NULL)
- yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
- yystackp->yysplitPoint, yystate);
-
- for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
- if (yystackp->yytops.yystates[yyn] != YY_NULL)
- yystackp->yytops.yystates[yyn] =
- YYRELOC (yystackp->yyitems, yynewItems,
- yystackp->yytops.yystates[yyn], yystate);
- YYFREE (yystackp->yyitems);
- yystackp->yyitems = yynewItems;
- yystackp->yynextFree = yynewItems + yysize;
- yystackp->yyspaceLeft = yynewSize - yysize;
-}
-#endif
-
-static void
-yyfreeGLRStack (yyGLRStack* yystackp)
-{
- YYFREE (yystackp->yyitems);
- yyfreeStateSet (&yystackp->yytops);
-}
-
-/** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
- * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
- * YYS. */
-static inline void
-yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
-{
- if (yystackp->yysplitPoint != YY_NULL && yystackp->yysplitPoint > yys)
- yystackp->yysplitPoint = yys;
-}
-
-/** Invalidate stack #YYK in *YYSTACKP. */
-static inline void
-yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
-{
- if (yystackp->yytops.yystates[yyk] != YY_NULL)
- yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
- yystackp->yytops.yystates[yyk] = YY_NULL;
-}
-
-/** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
- only be done once after a deletion, and only when all other stacks have
- been deleted. */
-static void
-yyundeleteLastStack (yyGLRStack* yystackp)
-{
- if (yystackp->yylastDeleted == YY_NULL || yystackp->yytops.yysize != 0)
- return;
- yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
- yystackp->yytops.yysize = 1;
- YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
- yystackp->yylastDeleted = YY_NULL;
-}
-
-static inline void
-yyremoveDeletes (yyGLRStack* yystackp)
-{
- size_t yyi, yyj;
- yyi = yyj = 0;
- while (yyj < yystackp->yytops.yysize)
- {
- if (yystackp->yytops.yystates[yyi] == YY_NULL)
- {
- if (yyi == yyj)
- {
- YYDPRINTF ((stderr, "Removing dead stacks.\n"));
- }
- yystackp->yytops.yysize -= 1;
- }
- else
- {
- yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
- /* In the current implementation, it's unnecessary to copy
- yystackp->yytops.yylookaheadNeeds[yyi] since, after
- yyremoveDeletes returns, the parser immediately either enters
- deterministic operation or shifts a token. However, it doesn't
- hurt, and the code might evolve to need it. */
- yystackp->yytops.yylookaheadNeeds[yyj] =
- yystackp->yytops.yylookaheadNeeds[yyi];
- if (yyj != yyi)
- {
- YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
- (unsigned long int) yyi, (unsigned long int) yyj));
- }
- yyj += 1;
- }
- yyi += 1;
- }
-}
-
-/** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
- * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
- * value *YYVALP and source location *YYLOCP. */
-static inline void
-yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
- size_t yyposn,
- YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
-{
- yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
-
- yynewState->yylrState = yylrState;
- yynewState->yyposn = yyposn;
- yynewState->yyresolved = yytrue;
- yynewState->yypred = yystackp->yytops.yystates[yyk];
- yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
- yynewState->yyloc = *yylocp;])[
- yystackp->yytops.yystates[yyk] = yynewState;
-
- YY_RESERVE_GLRSTACK (yystackp);
-}
-
-/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
- * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
- * semantic value of YYRHS under the action for YYRULE. */
-static inline void
-yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
- size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
-{
- yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
-
- yynewState->yylrState = yylrState;
- yynewState->yyposn = yyposn;
- yynewState->yyresolved = yyfalse;
- yynewState->yypred = yystackp->yytops.yystates[yyk];
- yynewState->yysemantics.yyfirstVal = YY_NULL;
- yystackp->yytops.yystates[yyk] = yynewState;
-
- /* Invokes YY_RESERVE_GLRSTACK. */
- yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
-}
-
-#if !]b4_api_PREFIX[DEBUG
-# define YY_REDUCE_PRINT(Args)
-#else
-# define YY_REDUCE_PRINT(Args) \
-do { \
- if (yydebug) \
- yy_reduce_print Args; \
-} while (0)
-
-/*----------------------------------------------------------------------.
-| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
-`----------------------------------------------------------------------*/
-
-static inline void
-yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
- yyRuleNum yyrule]b4_user_formals[)
-{
- int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
- int yylow = 1;])[
- int yyi;
- YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
- (unsigned long int) yyk, yyrule - 1,
- (unsigned long int) yyrline[yyrule]);
- if (! yynormal)
- yyfillin (yyvsp, 1, -yynrhs);
- /* The symbols being reduced. */
- for (yyi = 0; yyi < yynrhs; yyi++)
- {
- YYFPRINTF (stderr, " $%d = ", yyi + 1);
- yy_symbol_print (stderr,
- yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
- &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval
- ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
- b4_user_args[);
- if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
- YYFPRINTF (stderr, " (unresolved)");
- YYFPRINTF (stderr, "\n");
- }
-}
-#endif
-
-/** Pop the symbols consumed by reduction #YYRULE from the top of stack
- * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
- * semantic values. Assumes that all ambiguities in semantic values
- * have been previously resolved. Set *YYVALP to the resulting value,
- * and *YYLOCP to the computed location (if any). Return value is as
- * for userAction. */
-static inline YYRESULTTAG
-yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
- YYSTYPE* yyvalp]b4_locuser_formals[)
-{
- int yynrhs = yyrhsLength (yyrule);
-
- if (yystackp->yysplitPoint == YY_NULL)
- {
- /* Standard special case: single stack. */
- yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
- YYASSERT (yyk == 0);
- yystackp->yynextFree -= yynrhs;
- yystackp->yyspaceLeft += yynrhs;
- yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
- YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[));
- return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
- yyvalp]b4_locuser_args[);
- }
- else
- {
- int yyi;
- yyGLRState* yys;
- yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
- yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
- = yystackp->yytops.yystates[yyk];]b4_locations_if([[
- if (yynrhs == 0)
- /* Set default location. */
- yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
- for (yyi = 0; yyi < yynrhs; yyi += 1)
- {
- yys = yys->yypred;
- YYASSERT (yys);
- }
- yyupdateSplit (yystackp, yys);
- yystackp->yytops.yystates[yyk] = yys;
- YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
- return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
- yystackp, yyvalp]b4_locuser_args[);
- }
-}
-
-/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
- * and push back on the resulting nonterminal symbol. Perform the
- * semantic action associated with YYRULE and store its value with the
- * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
- * unambiguous. Otherwise, store the deferred semantic action with
- * the new state. If the new state would have an identical input
- * position, LR state, and predecessor to an existing state on the stack,
- * it is identified with that existing state, eliminating stack #YYK from
- * *YYSTACKP. In this case, the semantic value is
- * added to the options for the existing state's semantic value.
- */
-static inline YYRESULTTAG
-yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
- yybool yyforceEval]b4_user_formals[)
-{
- size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
-
- if (yyforceEval || yystackp->yysplitPoint == YY_NULL)
- {
- YYRESULTTAG yyflag;
- YYSTYPE yysval;]b4_locations_if([
- YYLTYPE yyloc;])[
-
- yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[);
- if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULL)
- {
- YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
- (unsigned long int) yyk, yyrule - 1));
- }
- if (yyflag != yyok)
- return yyflag;
- YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
- yyglrShift (yystackp, yyk,
- yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
- yylhsNonterm (yyrule)),
- yyposn, &yysval]b4_locations_if([, &yyloc])[);
- }
- else
- {
- size_t yyi;
- int yyn;
- yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
- yyStateNum yynewLRState;
-
- for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
- 0 < yyn; yyn -= 1)
- {
- yys = yys->yypred;
- YYASSERT (yys);
- }
- yyupdateSplit (yystackp, yys);
- yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
- YYDPRINTF ((stderr,
- "Reduced stack %lu by rule #%d; action deferred. "
- "Now in state %d.\n",
- (unsigned long int) yyk, yyrule - 1, yynewLRState));
- for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
- if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL)
- {
- yyGLRState *yysplit = yystackp->yysplitPoint;
- yyGLRState *yyp = yystackp->yytops.yystates[yyi];
- while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
- {
- if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
- {
- yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
- yymarkStackDeleted (yystackp, yyk);
- YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
- (unsigned long int) yyk,
- (unsigned long int) yyi));
- return yyok;
- }
- yyp = yyp->yypred;
- }
- }
- yystackp->yytops.yystates[yyk] = yys;
- yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
- }
- return yyok;
-}
-
-static size_t
-yysplitStack (yyGLRStack* yystackp, size_t yyk)
-{
- if (yystackp->yysplitPoint == YY_NULL)
- {
- YYASSERT (yyk == 0);
- yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
- }
- if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
- {
- yyGLRState** yynewStates;
- yybool* yynewLookaheadNeeds;
-
- yynewStates = YY_NULL;
-
- if (yystackp->yytops.yycapacity
- > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
- yyMemoryExhausted (yystackp);
- yystackp->yytops.yycapacity *= 2;
-
- yynewStates =
- (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
- (yystackp->yytops.yycapacity
- * sizeof yynewStates[0]));
- if (yynewStates == YY_NULL)
- yyMemoryExhausted (yystackp);
- yystackp->yytops.yystates = yynewStates;
-
- yynewLookaheadNeeds =
- (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
- (yystackp->yytops.yycapacity
- * sizeof yynewLookaheadNeeds[0]));
- if (yynewLookaheadNeeds == YY_NULL)
- yyMemoryExhausted (yystackp);
- yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
- }
- yystackp->yytops.yystates[yystackp->yytops.yysize]
- = yystackp->yytops.yystates[yyk];
- yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
- = yystackp->yytops.yylookaheadNeeds[yyk];
- yystackp->yytops.yysize += 1;
- return yystackp->yytops.yysize-1;
-}
-
-/** True iff YYY0 and YYY1 represent identical options at the top level.
- * That is, they represent the same rule applied to RHS symbols
- * that produce the same terminal symbols. */
-static yybool
-yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
-{
- if (yyy0->yyrule == yyy1->yyrule)
- {
- yyGLRState *yys0, *yys1;
- int yyn;
- for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
- yyn = yyrhsLength (yyy0->yyrule);
- yyn > 0;
- yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
- if (yys0->yyposn != yys1->yyposn)
- return yyfalse;
- return yytrue;
- }
- else
- return yyfalse;
-}
-
-/** Assuming identicalOptions (YYY0,YYY1), destructively merge the
- * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
-static void
-yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
-{
- yyGLRState *yys0, *yys1;
- int yyn;
- for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
- yyn = yyrhsLength (yyy0->yyrule);
- yyn > 0;
- yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
- {
- if (yys0 == yys1)
- break;
- else if (yys0->yyresolved)
- {
- yys1->yyresolved = yytrue;
- yys1->yysemantics.yysval = yys0->yysemantics.yysval;
- }
- else if (yys1->yyresolved)
- {
- yys0->yyresolved = yytrue;
- yys0->yysemantics.yysval = yys1->yysemantics.yysval;
- }
- else
- {
- yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
- yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
- while (yytrue)
- {
- if (yyz1 == *yyz0p || yyz1 == YY_NULL)
- break;
- else if (*yyz0p == YY_NULL)
- {
- *yyz0p = yyz1;
- break;
- }
- else if (*yyz0p < yyz1)
- {
- yySemanticOption* yyz = *yyz0p;
- *yyz0p = yyz1;
- yyz1 = yyz1->yynext;
- (*yyz0p)->yynext = yyz;
- }
- yyz0p = &(*yyz0p)->yynext;
- }
- yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
- }
- }
-}
-
-/** Y0 and Y1 represent two possible actions to take in a given
- * parsing state; return 0 if no combination is possible,
- * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
-static int
-yypreference (yySemanticOption* y0, yySemanticOption* y1)
-{
- yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
- int p0 = yydprec[r0], p1 = yydprec[r1];
-
- if (p0 == p1)
- {
- if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
- return 0;
- else
- return 1;
- }
- if (p0 == 0 || p1 == 0)
- return 0;
- if (p0 < p1)
- return 3;
- if (p1 < p0)
- return 2;
- return 0;
-}
-
-static YYRESULTTAG yyresolveValue (yyGLRState* yys,
- yyGLRStack* yystackp]b4_user_formals[);
-
-
-/** Resolve the previous YYN states starting at and including state YYS
- * on *YYSTACKP. If result != yyok, some states may have been left
- * unresolved possibly with empty semantic option chains. Regardless
- * of whether result = yyok, each state has been left with consistent
- * data so that yydestroyGLRState can be invoked if necessary. */
-static YYRESULTTAG
-yyresolveStates (yyGLRState* yys, int yyn,
- yyGLRStack* yystackp]b4_user_formals[)
-{
- if (0 < yyn)
- {
- YYASSERT (yys->yypred);
- YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
- if (! yys->yyresolved)
- YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
- }
- return yyok;
-}
-
-/** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
- * user action, and return the semantic value and location in *YYVALP
- * and *YYLOCP. Regardless of whether result = yyok, all RHS states
- * have been destroyed (assuming the user action destroys all RHS
- * semantic values if invoked). */
-static YYRESULTTAG
-yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
- YYSTYPE* yyvalp]b4_locuser_formals[)
-{
- yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
- int yynrhs = yyrhsLength (yyopt->yyrule);
- YYRESULTTAG yyflag =
- yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
- if (yyflag != yyok)
- {
- yyGLRState *yys;
- for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
- yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
- return yyflag;
- }
-
- yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[
- if (yynrhs == 0)
- /* Set default location. */
- yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
- {
- int yychar_current = yychar;
- YYSTYPE yylval_current = yylval;]b4_locations_if([
- YYLTYPE yylloc_current = yylloc;])[
- yychar = yyopt->yyrawchar;
- yylval = yyopt->yyval;]b4_locations_if([
- yylloc = yyopt->yyloc;])[
- yyflag = yyuserAction (yyopt->yyrule, yynrhs,
- yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
- yystackp, yyvalp]b4_locuser_args[);
- yychar = yychar_current;
- yylval = yylval_current;]b4_locations_if([
- yylloc = yylloc_current;])[
- }
- return yyflag;
-}
-
-#if ]b4_api_PREFIX[DEBUG
-static void
-yyreportTree (yySemanticOption* yyx, int yyindent)
-{
- int yynrhs = yyrhsLength (yyx->yyrule);
- int yyi;
- yyGLRState* yys;
- yyGLRState* yystates[1 + YYMAXRHS];
- yyGLRState yyleftmost_state;
-
- for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
- yystates[yyi] = yys;
- if (yys == YY_NULL)
- {
- yyleftmost_state.yyposn = 0;
- yystates[0] = &yyleftmost_state;
- }
- else
- yystates[0] = yys;
-
- if (yyx->yystate->yyposn < yys->yyposn + 1)
- YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
- yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
- yyx->yyrule - 1);
- else
- YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
- yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
- yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
- (unsigned long int) yyx->yystate->yyposn);
- for (yyi = 1; yyi <= yynrhs; yyi += 1)
- {
- if (yystates[yyi]->yyresolved)
- {
- if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
- YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
- yytokenName (yystos[yystates[yyi]->yylrState]));
- else
- YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
- yytokenName (yystos[yystates[yyi]->yylrState]),
- (unsigned long int) (yystates[yyi-1]->yyposn + 1),
- (unsigned long int) yystates[yyi]->yyposn);
- }
- else
- yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
- }
-}
-#endif
-
-static YYRESULTTAG
-yyreportAmbiguity (yySemanticOption* yyx0,
- yySemanticOption* yyx1]b4_pure_formals[)
-{
- YYUSE (yyx0);
- YYUSE (yyx1);
-
-#if ]b4_api_PREFIX[DEBUG
- YYFPRINTF (stderr, "Ambiguity detected.\n");
- YYFPRINTF (stderr, "Option 1,\n");
- yyreportTree (yyx0, 2);
- YYFPRINTF (stderr, "\nOption 2,\n");
- yyreportTree (yyx1, 2);
- YYFPRINTF (stderr, "\n");
-#endif
-
- yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
- return yyabort;
-}]b4_locations_if([[
-
-/** Resolve the locations for each of the YYN1 states in *YYSTACKP,
- * ending at YYS1. Has no effect on previously resolved states.
- * The first semantic option of a state is always chosen. */
-static void
-yyresolveLocations (yyGLRState* yys1, int yyn1,
- yyGLRStack *yystackp]b4_user_formals[)
-{
- if (0 < yyn1)
- {
- yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
- if (!yys1->yyresolved)
- {
- yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
- int yynrhs;
- yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
- YYASSERT (yyoption != YY_NULL);
- yynrhs = yyrhsLength (yyoption->yyrule);
- if (yynrhs > 0)
- {
- yyGLRState *yys;
- int yyn;
- yyresolveLocations (yyoption->yystate, yynrhs,
- yystackp]b4_user_args[);
- for (yys = yyoption->yystate, yyn = yynrhs;
- yyn > 0;
- yys = yys->yypred, yyn -= 1)
- yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
- }
- else
- {
- /* Both yyresolveAction and yyresolveLocations traverse the GSS
- in reverse rightmost order. It is only necessary to invoke
- yyresolveLocations on a subforest for which yyresolveAction
- would have been invoked next had an ambiguity not been
- detected. Thus the location of the previous state (but not
- necessarily the previous state itself) is guaranteed to be
- resolved already. */
- yyGLRState *yyprevious = yyoption->yystate;
- yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
- }
- {
- int yychar_current = yychar;
- YYSTYPE yylval_current = yylval;
- YYLTYPE yylloc_current = yylloc;
- yychar = yyoption->yyrawchar;
- yylval = yyoption->yyval;
- yylloc = yyoption->yyloc;
- YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
- yychar = yychar_current;
- yylval = yylval_current;
- yylloc = yylloc_current;
- }
- }
- }
-}]])[
-
-/** Resolve the ambiguity represented in state YYS in *YYSTACKP,
- * perform the indicated actions, and set the semantic value of YYS.
- * If result != yyok, the chain of semantic options in YYS has been
- * cleared instead or it has been left unmodified except that
- * redundant options may have been removed. Regardless of whether
- * result = yyok, YYS has been left with consistent data so that
- * yydestroyGLRState can be invoked if necessary. */
-static YYRESULTTAG
-yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
-{
- yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
- yySemanticOption* yybest = yyoptionList;
- yySemanticOption** yypp;
- yybool yymerge = yyfalse;
- YYSTYPE yysval;
- YYRESULTTAG yyflag;]b4_locations_if([
- YYLTYPE *yylocp = &yys->yyloc;])[
-
- for (yypp = &yyoptionList->yynext; *yypp != YY_NULL; )
- {
- yySemanticOption* yyp = *yypp;
-
- if (yyidenticalOptions (yybest, yyp))
- {
- yymergeOptionSets (yybest, yyp);
- *yypp = yyp->yynext;
- }
- else
- {
- switch (yypreference (yybest, yyp))
- {
- case 0:]b4_locations_if([[
- yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[
- return yyreportAmbiguity (yybest, yyp]b4_pure_args[);
- break;
- case 1:
- yymerge = yytrue;
- break;
- case 2:
- break;
- case 3:
- yybest = yyp;
- yymerge = yyfalse;
- break;
- default:
- /* This cannot happen so it is not worth a YYASSERT (yyfalse),
- but some compilers complain if the default case is
- omitted. */
- break;
- }
- yypp = &yyp->yynext;
- }
- }
-
- if (yymerge)
- {
- yySemanticOption* yyp;
- int yyprec = yydprec[yybest->yyrule];
- yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
- if (yyflag == yyok)
- for (yyp = yybest->yynext; yyp != YY_NULL; yyp = yyp->yynext)
- {
- if (yyprec == yydprec[yyp->yyrule])
- {
- YYSTYPE yysval_other;]b4_locations_if([
- YYLTYPE yydummy;])[
- yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
- if (yyflag != yyok)
- {
- yydestruct ("Cleanup: discarding incompletely merged value for",
- yystos[yys->yylrState],
- &yysval]b4_locuser_args[);
- break;
- }
- yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
- }
- }
- }
- else
- yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
-
- if (yyflag == yyok)
- {
- yys->yyresolved = yytrue;
- yys->yysemantics.yysval = yysval;
- }
- else
- yys->yysemantics.yyfirstVal = YY_NULL;
- return yyflag;
-}
-
-static YYRESULTTAG
-yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
-{
- if (yystackp->yysplitPoint != YY_NULL)
- {
- yyGLRState* yys;
- int yyn;
-
- for (yyn = 0, yys = yystackp->yytops.yystates[0];
- yys != yystackp->yysplitPoint;
- yys = yys->yypred, yyn += 1)
- continue;
- YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
- ]b4_user_args[));
- }
- return yyok;
-}
-
-static void
-yycompressStack (yyGLRStack* yystackp)
-{
- yyGLRState* yyp, *yyq, *yyr;
-
- if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULL)
- return;
-
- for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULL;
- yyp != yystackp->yysplitPoint;
- yyr = yyp, yyp = yyq, yyq = yyp->yypred)
- yyp->yypred = yyr;
-
- yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
- yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
- yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
- yystackp->yysplitPoint = YY_NULL;
- yystackp->yylastDeleted = YY_NULL;
-
- while (yyr != YY_NULL)
- {
- yystackp->yynextFree->yystate = *yyr;
- yyr = yyr->yypred;
- yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
- yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
- yystackp->yynextFree += 1;
- yystackp->yyspaceLeft -= 1;
- }
-}
-
-static YYRESULTTAG
-yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
- size_t yyposn]b4_pure_formals[)
-{
- while (yystackp->yytops.yystates[yyk] != YY_NULL)
- {
- yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
- YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
- (unsigned long int) yyk, yystate));
-
- YYASSERT (yystate != YYFINAL);
-
- if (yyisDefaultedState (yystate))
- {
- YYRESULTTAG yyflag;
- yyRuleNum yyrule = yydefaultAction (yystate);
- if (yyrule == 0)
- {
- YYDPRINTF ((stderr, "Stack %lu dies.\n",
- (unsigned long int) yyk));
- yymarkStackDeleted (yystackp, yyk);
- return yyok;
- }
- yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[);
- if (yyflag == yyerr)
- {
- YYDPRINTF ((stderr,
- "Stack %lu dies "
- "(predicate failure or explicit user error).\n",
- (unsigned long int) yyk));
- yymarkStackDeleted (yystackp, yyk);
- return yyok;
- }
- if (yyflag != yyok)
- return yyflag;
- }
- else
- {
- yySymbol yytoken;
- int yyaction;
- const short int* yyconflicts;
-
- yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
- if (yychar == YYEMPTY)
- {
- YYDPRINTF ((stderr, "Reading a token: "));
- yychar = ]b4_lex[;
- }
-
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
-
- yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
-
- while (*yyconflicts != 0)
- {
- YYRESULTTAG yyflag;
- size_t yynewStack = yysplitStack (yystackp, yyk);
- YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
- (unsigned long int) yynewStack,
- (unsigned long int) yyk));
- yyflag = yyglrReduce (yystackp, yynewStack,
- *yyconflicts,
- yyimmediate[*yyconflicts]]b4_user_args[);
- if (yyflag == yyok)
- YYCHK (yyprocessOneStack (yystackp, yynewStack,
- yyposn]b4_pure_args[));
- else if (yyflag == yyerr)
- {
- YYDPRINTF ((stderr, "Stack %lu dies.\n",
- (unsigned long int) yynewStack));
- yymarkStackDeleted (yystackp, yynewStack);
- }
- else
- return yyflag;
- yyconflicts += 1;
- }
-
- if (yyisShiftAction (yyaction))
- break;
- else if (yyisErrorAction (yyaction))
- {
- YYDPRINTF ((stderr, "Stack %lu dies.\n",
- (unsigned long int) yyk));
- yymarkStackDeleted (yystackp, yyk);
- break;
- }
- else
- {
- YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction,
- yyimmediate[-yyaction]]b4_user_args[);
- if (yyflag == yyerr)
- {
- YYDPRINTF ((stderr,
- "Stack %lu dies "
- "(predicate failure or explicit user error).\n",
- (unsigned long int) yyk));
- yymarkStackDeleted (yystackp, yyk);
- break;
- }
- else if (yyflag != yyok)
- return yyflag;
- }
- }
- }
- return yyok;
-}
-
-static void
-yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
-{
- if (yystackp->yyerrState != 0)
- return;
-#if ! YYERROR_VERBOSE
- yyerror (]b4_lyyerror_args[YY_("syntax error"));
-#else
- {
- yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
- size_t yysize0 = yytnamerr (YY_NULL, yytokenName (yytoken));
- size_t yysize = yysize0;
- yybool yysize_overflow = yyfalse;
- char* yymsg = YY_NULL;
- enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
- /* Internationalized format string. */
- const char *yyformat = YY_NULL;
- /* Arguments of yyformat. */
- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
- /* Number of reported tokens (one for the "unexpected", one per
- "expected"). */
- int yycount = 0;
-
- /* There are many possibilities here to consider:
- - If this state is a consistent state with a default action, then
- the only way this function was invoked is if the default action
- is an error action. In that case, don't check for expected
- tokens because there are none.
- - The only way there can be no lookahead present (in yychar) is if
- this state is a consistent state with a default action. Thus,
- detecting the absence of a lookahead is sufficient to determine
- that there is no unexpected or expected token to report. In that
- case, just report a simple "syntax error".
- - Don't assume there isn't a lookahead just because this state is a
- consistent state with a default action. There might have been a
- previous inconsistent state, consistent state with a non-default
- action, or user semantic action that manipulated yychar.
- - Of course, the expected token list depends on states to have
- correct lookahead information, and it depends on the parser not
- to perform extra reductions after fetching a lookahead from the
- scanner and before detecting a syntax error. Thus, state merging
- (from LALR or IELR) and default reductions corrupt the expected
- token list. However, the list is correct for canonical LR with
- one exception: it will still contain any token that will not be
- accepted due to an error action in a later state.
- */
- if (yytoken != YYEMPTY)
- {
- int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
- yyarg[yycount++] = yytokenName (yytoken);
- if (!yypact_value_is_default (yyn))
- {
- /* Start YYX at -YYN if negative to avoid negative indexes in
- YYCHECK. In other words, skip the first -YYN actions for this
- state because they are default actions. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = YYLAST - yyn + 1;
- int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
- int yyx;
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
- && !yytable_value_is_error (yytable[yyx + yyn]))
- {
- if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
- {
- yycount = 1;
- yysize = yysize0;
- break;
- }
- yyarg[yycount++] = yytokenName (yyx);
- {
- size_t yysz = yysize + yytnamerr (YY_NULL, yytokenName (yyx));
- yysize_overflow |= yysz < yysize;
- yysize = yysz;
- }
- }
- }
- }
-
- switch (yycount)
- {
-#define YYCASE_(N, S) \
- case N: \
- yyformat = S; \
- break
- YYCASE_(0, YY_("syntax error"));
- YYCASE_(1, YY_("syntax error, unexpected %s"));
- YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
- YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
- YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
- YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
-#undef YYCASE_
- }
-
- {
- size_t yysz = yysize + strlen (yyformat);
- yysize_overflow |= yysz < yysize;
- yysize = yysz;
- }
-
- if (!yysize_overflow)
- yymsg = (char *) YYMALLOC (yysize);
-
- if (yymsg)
- {
- char *yyp = yymsg;
- int yyi = 0;
- while ((*yyp = *yyformat))
- {
- if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
- {
- yyp += yytnamerr (yyp, yyarg[yyi++]);
- yyformat += 2;
- }
- else
- {
- yyp++;
- yyformat++;
- }
- }
- yyerror (]b4_lyyerror_args[yymsg);
- YYFREE (yymsg);
- }
- else
- {
- yyerror (]b4_lyyerror_args[YY_("syntax error"));
- yyMemoryExhausted (yystackp);
- }
- }
-#endif /* YYERROR_VERBOSE */
- yynerrs += 1;
-}
-
-/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
- yylval, and yylloc are the syntactic category, semantic value, and location
- of the lookahead. */
-static void
-yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
-{
- size_t yyk;
- int yyj;
-
- if (yystackp->yyerrState == 3)
- /* We just shifted the error token and (perhaps) took some
- reductions. Skip tokens until we can proceed. */
- while (yytrue)
- {
- yySymbol yytoken;
- if (yychar == YYEOF)
- yyFail (yystackp][]b4_lpure_args[, YY_NULL);
- if (yychar != YYEMPTY)
- {]b4_locations_if([[
- /* We throw away the lookahead, but the error range
- of the shifted error token must take it into account. */
- yyGLRState *yys = yystackp->yytops.yystates[0];
- yyGLRStackItem yyerror_range[3];
- yyerror_range[1].yystate.yyloc = yys->yyloc;
- yyerror_range[2].yystate.yyloc = yylloc;
- YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
- yytoken = YYTRANSLATE (yychar);
- yydestruct ("Error: discarding",
- yytoken, &yylval]b4_locuser_args([&yylloc])[);
- }
- YYDPRINTF ((stderr, "Reading a token: "));
- yychar = ]b4_lex[;
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
- yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
- if (yypact_value_is_default (yyj))
- return;
- yyj += yytoken;
- if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
- {
- if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
- return;
- }
- else if (! yytable_value_is_error (yytable[yyj]))
- return;
- }
-
- /* Reduce to one stack. */
- for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
- if (yystackp->yytops.yystates[yyk] != YY_NULL)
- break;
- if (yyk >= yystackp->yytops.yysize)
- yyFail (yystackp][]b4_lpure_args[, YY_NULL);
- for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
- yymarkStackDeleted (yystackp, yyk);
- yyremoveDeletes (yystackp);
- yycompressStack (yystackp);
-
- /* Now pop stack until we find a state that shifts the error token. */
- yystackp->yyerrState = 3;
- while (yystackp->yytops.yystates[0] != YY_NULL)
- {
- yyGLRState *yys = yystackp->yytops.yystates[0];
- yyj = yypact[yys->yylrState];
- if (! yypact_value_is_default (yyj))
- {
- yyj += YYTERROR;
- if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
- && yyisShiftAction (yytable[yyj]))
- {
- /* Shift the error token. */]b4_locations_if([[
- /* First adjust its location.*/
- YYLTYPE yyerrloc;
- yystackp->yyerror_range[2].yystate.yyloc = yylloc;
- YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
- YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
- &yylval, &yyerrloc);
- yyglrShift (yystackp, 0, yytable[yyj],
- yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
- yys = yystackp->yytops.yystates[0];
- break;
- }
- }]b4_locations_if([[
- yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
- if (yys->yypred != YY_NULL)
- yydestroyGLRState ("Error: popping", yys]b4_user_args[);
- yystackp->yytops.yystates[0] = yys->yypred;
- yystackp->yynextFree -= 1;
- yystackp->yyspaceLeft += 1;
- }
- if (yystackp->yytops.yystates[0] == YY_NULL)
- yyFail (yystackp][]b4_lpure_args[, YY_NULL);
-}
-
-#define YYCHK1(YYE) \
- do { \
- switch (YYE) { \
- case yyok: \
- break; \
- case yyabort: \
- goto yyabortlab; \
- case yyaccept: \
- goto yyacceptlab; \
- case yyerr: \
- goto yyuser_error; \
- default: \
- goto yybuglab; \
- } \
- } while (0)
-
-/*----------.
-| yyparse. |
-`----------*/
-
-]b4_function_define([yyparse], [int], b4_parse_param)[
-{
- int yyresult;
- yyGLRStack yystack;
- yyGLRStack* const yystackp = &yystack;
- size_t yyposn;
-
- YYDPRINTF ((stderr, "Starting parse\n"));
-
- yychar = YYEMPTY;
- yylval = yyval_default;]b4_locations_if([
- yylloc = yyloc_default;])[
-]m4_ifdef([b4_initial_action], [
-b4_dollar_pushdef([yylval], [], [yylloc])dnl
- /* User initialization code. */
- b4_user_initial_action
-b4_dollar_popdef])[]dnl
-[
- if (! yyinitGLRStack (yystackp, YYINITDEPTH))
- goto yyexhaustedlab;
- switch (YYSETJMP (yystack.yyexception_buffer))
- {
- case 0: break;
- case 1: goto yyabortlab;
- case 2: goto yyexhaustedlab;
- default: goto yybuglab;
- }
- yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[);
- yyposn = 0;
-
- while (yytrue)
- {
- /* For efficiency, we have two loops, the first of which is
- specialized to deterministic operation (single stack, no
- potential ambiguity). */
- /* Standard mode */
- while (yytrue)
- {
- yyRuleNum yyrule;
- int yyaction;
- const short int* yyconflicts;
-
- yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
- YYDPRINTF ((stderr, "Entering state %d\n", yystate));
- if (yystate == YYFINAL)
- goto yyacceptlab;
- if (yyisDefaultedState (yystate))
- {
- yyrule = yydefaultAction (yystate);
- if (yyrule == 0)
- {
-]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
- yyreportSyntaxError (&yystack]b4_user_args[);
- goto yyuser_error;
- }
- YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
- }
- else
- {
- yySymbol yytoken;
- if (yychar == YYEMPTY)
- {
- YYDPRINTF ((stderr, "Reading a token: "));
- yychar = ]b4_lex[;
- }
-
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
-
- yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
- if (*yyconflicts != 0)
- break;
- if (yyisShiftAction (yyaction))
- {
- YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
- yychar = YYEMPTY;
- yyposn += 1;
- yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
- if (0 < yystack.yyerrState)
- yystack.yyerrState -= 1;
- }
- else if (yyisErrorAction (yyaction))
- {
-]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
- yyreportSyntaxError (&yystack]b4_user_args[);
- goto yyuser_error;
- }
- else
- YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
- }
- }
-
- while (yytrue)
- {
- yySymbol yytoken_to_shift;
- size_t yys;
-
- for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
- yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
-
- /* yyprocessOneStack returns one of three things:
-
- - An error flag. If the caller is yyprocessOneStack, it
- immediately returns as well. When the caller is finally
- yyparse, it jumps to an error label via YYCHK1.
-
- - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
- (&yystack, yys), which sets the top state of yys to NULL. Thus,
- yyparse's following invocation of yyremoveDeletes will remove
- the stack.
-
- - yyok, when ready to shift a token.
-
- Except in the first case, yyparse will invoke yyremoveDeletes and
- then shift the next token onto all remaining stacks. This
- synchronization of the shift (that is, after all preceding
- reductions on all stacks) helps prevent double destructor calls
- on yylval in the event of memory exhaustion. */
-
- for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
- YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
- yyremoveDeletes (&yystack);
- if (yystack.yytops.yysize == 0)
- {
- yyundeleteLastStack (&yystack);
- if (yystack.yytops.yysize == 0)
- yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
- YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
- YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
-]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
- yyreportSyntaxError (&yystack]b4_user_args[);
- goto yyuser_error;
- }
-
- /* If any yyglrShift call fails, it will fail after shifting. Thus,
- a copy of yylval will already be on stack 0 in the event of a
- failure in the following loop. Thus, yychar is set to YYEMPTY
- before the loop to make sure the user destructor for yylval isn't
- called twice. */
- yytoken_to_shift = YYTRANSLATE (yychar);
- yychar = YYEMPTY;
- yyposn += 1;
- for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
- {
- int yyaction;
- const short int* yyconflicts;
- yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
- yygetLRActions (yystate, yytoken_to_shift, &yyaction,
- &yyconflicts);
- /* Note that yyconflicts were handled by yyprocessOneStack. */
- YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
- YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
- yyglrShift (&yystack, yys, yyaction, yyposn,
- &yylval]b4_locations_if([, &yylloc])[);
- YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
- (unsigned long int) yys,
- yystack.yytops.yystates[yys]->yylrState));
- }
-
- if (yystack.yytops.yysize == 1)
- {
- YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
- YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
- yycompressStack (&yystack);
- break;
- }
- }
- continue;
- yyuser_error:
- yyrecoverSyntaxError (&yystack]b4_user_args[);
- yyposn = yystack.yytops.yystates[0]->yyposn;
- }
-
- yyacceptlab:
- yyresult = 0;
- goto yyreturn;
-
- yybuglab:
- YYASSERT (yyfalse);
- goto yyabortlab;
-
- yyabortlab:
- yyresult = 1;
- goto yyreturn;
-
- yyexhaustedlab:
- yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
- yyresult = 2;
- goto yyreturn;
-
- yyreturn:
- if (yychar != YYEMPTY)
- yydestruct ("Cleanup: discarding lookahead",
- YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
-
- /* If the stack is well-formed, pop the stack until it is empty,
- destroying its entries as we go. But free the stack regardless
- of whether it is well-formed. */
- if (yystack.yyitems)
- {
- yyGLRState** yystates = yystack.yytops.yystates;
- if (yystates)
- {
- size_t yysize = yystack.yytops.yysize;
- size_t yyk;
- for (yyk = 0; yyk < yysize; yyk += 1)
- if (yystates[yyk])
- {
- while (yystates[yyk])
- {
- yyGLRState *yys = yystates[yyk];
-]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
-)[ if (yys->yypred != YY_NULL)
- yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
- yystates[yyk] = yys->yypred;
- yystack.yynextFree -= 1;
- yystack.yyspaceLeft += 1;
- }
- break;
- }
- }
- yyfreeGLRStack (&yystack);
- }
-
- return yyresult;
-}
-
-/* DEBUGGING ONLY */
-#if ]b4_api_PREFIX[DEBUG
-static void
-yy_yypstack (yyGLRState* yys)
-{
- if (yys->yypred)
- {
- yy_yypstack (yys->yypred);
- YYFPRINTF (stderr, " -> ");
- }
- YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
- (unsigned long int) yys->yyposn);
-}
-
-static void
-yypstates (yyGLRState* yyst)
-{
- if (yyst == YY_NULL)
- YYFPRINTF (stderr, "<null>");
- else
- yy_yypstack (yyst);
- YYFPRINTF (stderr, "\n");
-}
-
-static void
-yypstack (yyGLRStack* yystackp, size_t yyk)
-{
- yypstates (yystackp->yytops.yystates[yyk]);
-}
-
-#define YYINDEX(YYX) \
- ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
-
-
-static void
-yypdumpstack (yyGLRStack* yystackp)
-{
- yyGLRStackItem* yyp;
- size_t yyi;
- for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
- {
- YYFPRINTF (stderr, "%3lu. ",
- (unsigned long int) (yyp - yystackp->yyitems));
- if (*(yybool *) yyp)
- {
- YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
- yyp->yystate.yyresolved, yyp->yystate.yylrState,
- (unsigned long int) yyp->yystate.yyposn,
- (long int) YYINDEX (yyp->yystate.yypred));
- if (! yyp->yystate.yyresolved)
- YYFPRINTF (stderr, ", firstVal: %ld",
- (long int) YYINDEX (yyp->yystate
- .yysemantics.yyfirstVal));
- }
- else
- {
- YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
- yyp->yyoption.yyrule - 1,
- (long int) YYINDEX (yyp->yyoption.yystate),
- (long int) YYINDEX (yyp->yyoption.yynext));
- }
- YYFPRINTF (stderr, "\n");
- }
- YYFPRINTF (stderr, "Tops:");
- for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
- YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
- (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
- YYFPRINTF (stderr, "\n");
-}
-#endif
-
-#undef yylval
-#undef yychar
-#undef yynerrs]b4_locations_if([
-#undef yylloc])
-
-m4_if(b4_prefix, [yy], [],
-[[/* Substitute the variable and function names. */
-#define yyparse ]b4_prefix[parse
-#define yylex ]b4_prefix[lex
-#define yyerror ]b4_prefix[error
-#define yylval ]b4_prefix[lval
-#define yychar ]b4_prefix[char
-#define yydebug ]b4_prefix[debug
-#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
-#define yylloc ]b4_prefix[lloc]])])[
-
-]b4_epilogue[]dnl
-b4_output_end()
-
-# glr.cc produces its own header.
-m4_if(b4_skeleton, ["glr.c"],
-[b4_defines_if(
-[b4_output_begin([b4_spec_defines_file])
-b4_copyright([Skeleton interface for Bison GLR parsers in C],
- [2002-2013])[
-
-]b4_cpp_guard_open([b4_spec_defines_file])[
-]b4_shared_declarations[
-]b4_cpp_guard_close([b4_spec_defines_file])[
-]b4_output_end()
-])])
+ -*- C -*-
+
+# GLR skeleton for Bison
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# If we are loaded by glr.cc, do not override c++.m4 definitions by
+# those of c.m4.
+m4_if(b4_skeleton, ["glr.c"],
+ [m4_include(b4_pkgdatadir/[c.m4])])
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# Stack parameters.
+m4_define_default([b4_stack_depth_max], [10000])
+m4_define_default([b4_stack_depth_init], [200])
+
+
+
+## ------------------------ ##
+## Pure/impure interfaces. ##
+## ------------------------ ##
+
+b4_define_flag_if([pure])
+# If glr.cc is including this file and thus has already set b4_pure_flag,
+# do not change the value of b4_pure_flag, and do not record a use of api.pure.
+m4_ifndef([b4_pure_flag],
+[b4_percent_define_default([[api.pure]], [[false]])
+ m4_define([b4_pure_flag],
+ [b4_percent_define_flag_if([[api.pure]], [[1]], [[0]])])])
+
+# b4_user_formals
+# ---------------
+# The possible parse-params formal arguments preceded by a comma.
+#
+# This is not shared with yacc.c in c.m4 because GLR relies on ISO C
+# formal argument declarations.
+m4_define([b4_user_formals],
+[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
+
+
+# b4_yyerror_args
+# ---------------
+# Optional effective arguments passed to yyerror: user args plus yylloc, and
+# a trailing comma.
+m4_define([b4_yyerror_args],
+[b4_pure_if([b4_locations_if([yylocp, ])])dnl
+m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
+
+
+# b4_lyyerror_args
+# ----------------
+# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
+m4_define([b4_lyyerror_args],
+[b4_pure_if([b4_locations_if([&yylloc, ])])dnl
+m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
+
+
+# b4_pure_args
+# ------------
+# Same as b4_yyerror_args, but with a leading comma.
+m4_define([b4_pure_args],
+[b4_pure_if([b4_locations_if([, yylocp])])[]b4_user_args])
+
+
+# b4_lpure_args
+# -------------
+# Same as above, but on the lookahead, hence &yylloc instead of yylocp.
+m4_define([b4_lpure_args],
+[b4_pure_if([b4_locations_if([, &yylloc])])[]b4_user_args])
+
+
+
+# b4_pure_formals
+# ---------------
+# Arguments passed to yyerror: user formals plus yylocp with leading comma.
+m4_define([b4_pure_formals],
+[b4_pure_if([b4_locations_if([, YYLTYPE *yylocp])])[]b4_user_formals])
+
+
+# b4_locuser_formals(LOC = yylocp)
+# --------------------------------
+m4_define([b4_locuser_formals],
+[b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals])
+
+
+# b4_locuser_args(LOC = yylocp)
+# -----------------------------
+m4_define([b4_locuser_args],
+[b4_locations_if([, m4_default([$1], [yylocp])])[]b4_user_args])
+
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+# b4_lhs_value([TYPE])
+# --------------------
+# Expansion of $<TYPE>$.
+m4_define([b4_lhs_value],
+[b4_symbol_value([(*yyvalp)], [$1])])
+
+
+# b4_rhs_data(RULE-LENGTH, NUM)
+# -----------------------------
+# Expand to the semantic stack place that contains value and location
+# of symbol number NUM in a rule of length RULE-LENGTH.
+m4_define([b4_rhs_data],
+[((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate])
+
+
+# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
+# --------------------------------------
+# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
+# symbols on RHS.
+m4_define([b4_rhs_value],
+[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])])
+
+
+
+## ----------- ##
+## Locations. ##
+## ----------- ##
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+[(*yylocp)])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+[(b4_rhs_data([$1], [$2]).yyloc)])
+
+
+## -------------- ##
+## Declarations. ##
+## -------------- ##
+
+# b4_shared_declarations
+# ----------------------
+# Declaration that might either go into the header (if --defines)
+# or open coded in the parser body. glr.cc has its own definition.
+m4_if(b4_skeleton, ["glr.c"],
+[m4_define([b4_shared_declarations],
+[b4_declare_yydebug[
+]b4_percent_code_get([[requires]])[
+]b4_token_enums[
+]b4_declare_yylstype[
+]b4_function_declare(b4_prefix[parse], [int], b4_parse_param)[
+]b4_percent_code_get([[provides]])[]dnl
+])
+])
+
+## -------------- ##
+## Output files. ##
+## -------------- ##
+
+b4_output_begin([b4_parser_file_name])
+b4_copyright([Skeleton implementation for Bison GLR parsers in C],
+ [2002-2013])[
+
+/* C GLR parser skeleton written by Paul Hilfinger. */
+
+]b4_identification
+
+b4_percent_code_get([[top]])[
+]m4_if(b4_api_prefix, [yy], [],
+[[/* Substitute the type names. */
+#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
+#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
+]m4_if(b4_prefix, [yy], [],
+[[/* Substitute the variable and function names. */
+#define yyparse ]b4_prefix[parse
+#define yylex ]b4_prefix[lex
+#define yyerror ]b4_prefix[error
+#define yydebug ]b4_prefix[debug
+]]b4_pure_if([], [[
+#define yylval ]b4_prefix[lval
+#define yychar ]b4_prefix[char
+#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
+#define yylloc ]b4_prefix[lloc]])]))[
+
+/* First part of user declarations. */
+]b4_user_pre_prologue[
+
+]b4_null_define[
+
+]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
+ [b4_shared_declarations])[
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
+#endif
+
+/* Default (constant) value used for initialization for null
+ right-hand sides. Unlike the standard yacc.c template, here we set
+ the default value of $$ to a zeroed-out value. Since the default
+ value is undefined, this behavior is technically correct. */
+static YYSTYPE yyval_default;]b4_locations_if([[
+static YYLTYPE yyloc_default][]b4_yyloc_default;])[
+
+/* Copy the second part of user declarations. */
+]b4_user_post_prologue
+b4_percent_code_get[]dnl
+
+[#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(Msgid) Msgid
+# endif
+#endif
+
+#ifndef YYFREE
+# define YYFREE free
+#endif
+#ifndef YYMALLOC
+# define YYMALLOC malloc
+#endif
+#ifndef YYREALLOC
+# define YYREALLOC realloc
+#endif
+
+#define YYSIZEMAX ((size_t) -1)
+
+#ifdef __cplusplus
+ typedef bool yybool;
+#else
+ typedef unsigned char yybool;
+#endif
+#define yytrue 1
+#define yyfalse 0
+
+#ifndef YYSETJMP
+# include <setjmp.h>
+# define YYJMP_BUF jmp_buf
+# define YYSETJMP(Env) setjmp (Env)
+/* Pacify clang. */
+# define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0))
+#endif
+
+]b4_attribute_define[
+
+#ifndef YYASSERT
+# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
+#endif
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL ]b4_final_state_number[
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST ]b4_last[
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS ]b4_tokens_number[
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS ]b4_nterms_number[
+/* YYNRULES -- Number of rules. */
+#define YYNRULES ]b4_rules_number[
+/* YYNRULES -- Number of states. */
+#define YYNSTATES ]b4_states_number[
+/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
+#define YYMAXRHS ]b4_r2_max[
+/* YYMAXLEFT -- Maximum number of symbols to the left of a handle
+ accessed by $0, $-1, etc., in any rule. */
+#define YYMAXLEFT ]b4_max_left_semantic_context[
+
+/* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
+#define YYUNDEFTOK ]b4_undef_token_number[
+#define YYMAXUTOK ]b4_user_token_number_max[
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
+{
+ ]b4_translate[
+};
+
+#if ]b4_api_PREFIX[DEBUG
+/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
+static const ]b4_int_type_for([b4_rline])[ yyrline[] =
+{
+ ]b4_rline[
+};
+#endif
+
+#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ ]b4_tname[
+};
+#endif
+
+#define YYPACT_NINF ]b4_pact_ninf[
+#define YYTABLE_NINF ]b4_table_ninf[
+
+]b4_parser_tables_define[
+
+/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
+static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
+{
+ ]b4_dprec[
+};
+
+/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
+static const ]b4_int_type_for([b4_merger])[ yymerger[] =
+{
+ ]b4_merger[
+};
+
+/* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as
+ in the case of predicates. */
+static const yybool yyimmediate[] =
+{
+ ]b4_immediate[
+};
+
+/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
+ list of conflicting reductions corresponding to action entry for
+ state STATE-NUM in yytable. 0 means no conflicts. The list in
+ yyconfl is terminated by a rule number of 0. */
+static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
+{
+ ]b4_conflict_list_heads[
+};
+
+/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
+ 0, pointed into by YYCONFLP. */
+]dnl Do not use b4_int_type_for here, since there are places where
+dnl pointers onto yyconfl are taken, whose type is "short int *".
+dnl We probably ought to introduce a type for confl.
+[static const short int yyconfl[] =
+{
+ ]b4_conflicting_rules[
+};
+
+/* Error token number */
+#define YYTERROR 1
+
+]b4_locations_if([[
+]b4_yylloc_default_define[
+# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
+]])[
+
+]b4_pure_if(
+[
+#undef yynerrs
+#define yynerrs (yystackp->yyerrcnt)
+#undef yychar
+#define yychar (yystackp->yyrawchar)
+#undef yylval
+#define yylval (yystackp->yyval)
+#undef yylloc
+#define yylloc (yystackp->yyloc)
+m4_if(b4_prefix[], [yy], [],
+[#define b4_prefix[]nerrs yynerrs
+#define b4_prefix[]char yychar
+#define b4_prefix[]lval yylval
+#define b4_prefix[]lloc yylloc])],
+[YYSTYPE yylval;]b4_locations_if([[
+YYLTYPE yylloc;]])[
+
+int yynerrs;
+int yychar;])[
+
+static const int YYEOF = 0;
+static const int YYEMPTY = -2;
+
+typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
+
+#define YYCHK(YYE) \
+ do { \
+ YYRESULTTAG yychk_flag = YYE; \
+ if (yychk_flag != yyok) \
+ return yychk_flag; \
+ } while (0)
+
+#if ]b4_api_PREFIX[DEBUG
+
+# ifndef YYFPRINTF
+# define YYFPRINTF fprintf
+# endif
+
+]b4_yy_location_print_define[
+
+# define YYDPRINTF(Args) \
+ do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+ } while (0)
+
+]b4_yy_symbol_print_define[
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+ do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, Type, Value]b4_locuser_args([Location])[); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+ } while (0)
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+
+struct yyGLRStack;
+static void yypstack (struct yyGLRStack* yystackp, size_t yyk)
+ __attribute__ ((__unused__));
+static void yypdumpstack (struct yyGLRStack* yystackp)
+ __attribute__ ((__unused__));
+
+#else /* !]b4_api_PREFIX[DEBUG */
+
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+
+#endif /* !]b4_api_PREFIX[DEBUG */
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH ]b4_stack_depth_init[
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH ]b4_stack_depth_max[
+#endif
+
+/* Minimum number of free items on the stack allowed after an
+ allocation. This is to allow allocation and initialization
+ to be completed by functions that call yyexpandGLRStack before the
+ stack is expanded, thus insuring that all necessary pointers get
+ properly redirected to new data. */
+#define YYHEADROOM 2
+
+#ifndef YYSTACKEXPANDABLE
+# define YYSTACKEXPANDABLE 1
+#endif
+
+#if YYSTACKEXPANDABLE
+# define YY_RESERVE_GLRSTACK(Yystack) \
+ do { \
+ if (Yystack->yyspaceLeft < YYHEADROOM) \
+ yyexpandGLRStack (Yystack); \
+ } while (0)
+#else
+# define YY_RESERVE_GLRSTACK(Yystack) \
+ do { \
+ if (Yystack->yyspaceLeft < YYHEADROOM) \
+ yyMemoryExhausted (Yystack); \
+ } while (0)
+#endif
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static size_t
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ size_t yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return strlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+#endif /* !YYERROR_VERBOSE */
+
+/** State numbers, as in LALR(1) machine */
+typedef int yyStateNum;
+
+/** Rule numbers, as in LALR(1) machine */
+typedef int yyRuleNum;
+
+/** Grammar symbol */
+typedef int yySymbol;
+
+/** Item references, as in LALR(1) machine */
+typedef short int yyItemNum;
+
+typedef struct yyGLRState yyGLRState;
+typedef struct yyGLRStateSet yyGLRStateSet;
+typedef struct yySemanticOption yySemanticOption;
+typedef union yyGLRStackItem yyGLRStackItem;
+typedef struct yyGLRStack yyGLRStack;
+
+struct yyGLRState {
+ /** Type tag: always true. */
+ yybool yyisState;
+ /** Type tag for yysemantics. If true, yysval applies, otherwise
+ * yyfirstVal applies. */
+ yybool yyresolved;
+ /** Number of corresponding LALR(1) machine state. */
+ yyStateNum yylrState;
+ /** Preceding state in this stack */
+ yyGLRState* yypred;
+ /** Source position of the last token produced by my symbol */
+ size_t yyposn;
+ union {
+ /** First in a chain of alternative reductions producing the
+ * non-terminal corresponding to this state, threaded through
+ * yynext. */
+ yySemanticOption* yyfirstVal;
+ /** Semantic value for this state. */
+ YYSTYPE yysval;
+ } yysemantics;]b4_locations_if([[
+ /** Source location for this state. */
+ YYLTYPE yyloc;]])[
+};
+
+struct yyGLRStateSet {
+ yyGLRState** yystates;
+ /** During nondeterministic operation, yylookaheadNeeds tracks which
+ * stacks have actually needed the current lookahead. During deterministic
+ * operation, yylookaheadNeeds[0] is not maintained since it would merely
+ * duplicate yychar != YYEMPTY. */
+ yybool* yylookaheadNeeds;
+ size_t yysize, yycapacity;
+};
+
+struct yySemanticOption {
+ /** Type tag: always false. */
+ yybool yyisState;
+ /** Rule number for this reduction */
+ yyRuleNum yyrule;
+ /** The last RHS state in the list of states to be reduced. */
+ yyGLRState* yystate;
+ /** The lookahead for this reduction. */
+ int yyrawchar;
+ YYSTYPE yyval;]b4_locations_if([[
+ YYLTYPE yyloc;]])[
+ /** Next sibling in chain of options. To facilitate merging,
+ * options are chained in decreasing order by address. */
+ yySemanticOption* yynext;
+};
+
+/** Type of the items in the GLR stack. The yyisState field
+ * indicates which item of the union is valid. */
+union yyGLRStackItem {
+ yyGLRState yystate;
+ yySemanticOption yyoption;
+};
+
+struct yyGLRStack {
+ int yyerrState;
+]b4_locations_if([[ /* To compute the location of the error token. */
+ yyGLRStackItem yyerror_range[3];]])[
+]b4_pure_if(
+[
+ int yyerrcnt;
+ int yyrawchar;
+ YYSTYPE yyval;]b4_locations_if([[
+ YYLTYPE yyloc;]])[
+])[
+ YYJMP_BUF yyexception_buffer;
+ yyGLRStackItem* yyitems;
+ yyGLRStackItem* yynextFree;
+ size_t yyspaceLeft;
+ yyGLRState* yysplitPoint;
+ yyGLRState* yylastDeleted;
+ yyGLRStateSet yytops;
+};
+
+#if YYSTACKEXPANDABLE
+static void yyexpandGLRStack (yyGLRStack* yystackp);
+#endif
+
+static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
+ __attribute__ ((__noreturn__));
+static void
+yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
+{
+ if (yymsg != YY_NULL)
+ yyerror (]b4_yyerror_args[yymsg);
+ YYLONGJMP (yystackp->yyexception_buffer, 1);
+}
+
+static void yyMemoryExhausted (yyGLRStack* yystackp)
+ __attribute__ ((__noreturn__));
+static void
+yyMemoryExhausted (yyGLRStack* yystackp)
+{
+ YYLONGJMP (yystackp->yyexception_buffer, 2);
+}
+
+#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE
+/** A printable representation of TOKEN. */
+static inline const char*
+yytokenName (yySymbol yytoken)
+{
+ if (yytoken == YYEMPTY)
+ return "";
+
+ return yytname[yytoken];
+}
+#endif
+
+/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
+ * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
+ * containing the pointer to the next state in the chain. */
+static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
+static void
+yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
+{
+ int i;
+ yyGLRState *s = yyvsp[yylow0].yystate.yypred;
+ for (i = yylow0-1; i >= yylow1; i -= 1)
+ {
+#if ]b4_api_PREFIX[DEBUG
+ yyvsp[i].yystate.yylrState = s->yylrState;
+#endif
+ yyvsp[i].yystate.yyresolved = s->yyresolved;
+ if (s->yyresolved)
+ yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval;
+ else
+ /* The effect of using yysval or yyloc (in an immediate rule) is
+ * undefined. */
+ yyvsp[i].yystate.yysemantics.yyfirstVal = YY_NULL;]b4_locations_if([[
+ yyvsp[i].yystate.yyloc = s->yyloc;]])[
+ s = yyvsp[i].yystate.yypred = s->yypred;
+ }
+}
+
+/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in
+ * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
+ * For convenience, always return YYLOW1. */
+static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
+ __attribute__ ((__unused__));
+static inline int
+yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
+{
+ if (!yynormal && yylow1 < *yylow)
+ {
+ yyfillin (yyvsp, *yylow, yylow1);
+ *yylow = yylow1;
+ }
+ return yylow1;
+}
+
+/** Perform user action for rule number YYN, with RHS length YYRHSLEN,
+ * and top stack item YYVSP. YYLVALP points to place to put semantic
+ * value ($$), and yylocp points to place for location information
+ * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
+ * yyerr for YYERROR, yyabort for YYABORT. */
+static YYRESULTTAG
+yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
+ yyGLRStack* yystackp,
+ YYSTYPE* yyvalp]b4_locuser_formals[)
+{
+ yybool yynormal __attribute__ ((__unused__)) =
+ (yystackp->yysplitPoint == YY_NULL);
+ int yylow;
+]b4_parse_param_use([yyvalp], [yylocp])dnl
+[ YYUSE (yyrhslen);
+# undef yyerrok
+# define yyerrok (yystackp->yyerrState = 0)
+# undef YYACCEPT
+# define YYACCEPT return yyaccept
+# undef YYABORT
+# define YYABORT return yyabort
+# undef YYERROR
+# define YYERROR return yyerrok, yyerr
+# undef YYRECOVERING
+# define YYRECOVERING() (yystackp->yyerrState != 0)
+# undef yyclearin
+# define yyclearin (yychar = YYEMPTY)
+# undef YYFILL
+# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
+# undef YYBACKUP
+# define YYBACKUP(Token, Value) \
+ return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
+ yyerrok, yyerr
+
+ yylow = 1;
+ if (yyrhslen == 0)
+ *yyvalp = yyval_default;
+ else
+ *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
+ YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen);
+ yystackp->yyerror_range[1].yystate.yyloc = *yylocp;
+]])[
+ switch (yyn)
+ {
+ ]b4_user_actions[
+ default: break;
+ }
+
+ return yyok;
+# undef yyerrok
+# undef YYABORT
+# undef YYACCEPT
+# undef YYERROR
+# undef YYBACKUP
+# undef yyclearin
+# undef YYRECOVERING
+}
+
+
+static void
+yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
+{
+ YYUSE (yy0);
+ YYUSE (yy1);
+
+ switch (yyn)
+ {
+]b4_mergers[
+ default: break;
+ }
+}
+
+ /* Bison grammar-table manipulation. */
+
+]b4_yydestruct_define[
+
+/** Number of symbols composing the right hand side of rule #RULE. */
+static inline int
+yyrhsLength (yyRuleNum yyrule)
+{
+ return yyr2[yyrule];
+}
+
+static void
+yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
+{
+ if (yys->yyresolved)
+ yydestruct (yymsg, yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_locuser_args([&yys->yyloc])[);
+ else
+ {
+#if ]b4_api_PREFIX[DEBUG
+ if (yydebug)
+ {
+ if (yys->yysemantics.yyfirstVal)
+ YYFPRINTF (stderr, "%s unresolved ", yymsg);
+ else
+ YYFPRINTF (stderr, "%s incomplete ", yymsg);
+ yy_symbol_print (stderr, yystos[yys->yylrState],
+ YY_NULL]b4_locuser_args([&yys->yyloc])[);
+ YYFPRINTF (stderr, "\n");
+ }
+#endif
+
+ if (yys->yysemantics.yyfirstVal)
+ {
+ yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
+ yyGLRState *yyrh;
+ int yyn;
+ for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
+ yyn > 0;
+ yyrh = yyrh->yypred, yyn -= 1)
+ yydestroyGLRState (yymsg, yyrh]b4_user_args[);
+ }
+ }
+}
+
+/** Left-hand-side symbol for rule #YYRULE. */
+static inline yySymbol
+yylhsNonterm (yyRuleNum yyrule)
+{
+ return yyr1[yyrule];
+}
+
+#define yypact_value_is_default(Yystate) \
+ ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
+
+/** True iff LR state YYSTATE has only a default reduction (regardless
+ * of token). */
+static inline yybool
+yyisDefaultedState (yyStateNum yystate)
+{
+ return yypact_value_is_default (yypact[yystate]);
+}
+
+/** The default reduction for YYSTATE, assuming it has one. */
+static inline yyRuleNum
+yydefaultAction (yyStateNum yystate)
+{
+ return yydefact[yystate];
+}
+
+#define yytable_value_is_error(Yytable_value) \
+ ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
+
+/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
+ * Result R means
+ * R < 0: Reduce on rule -R.
+ * R = 0: Error.
+ * R > 0: Shift to state R.
+ * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
+ * of conflicting reductions.
+ */
+static inline void
+yygetLRActions (yyStateNum yystate, int yytoken,
+ int* yyaction, const short int** yyconflicts)
+{
+ int yyindex = yypact[yystate] + yytoken;
+ if (yypact_value_is_default (yypact[yystate])
+ || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
+ {
+ *yyaction = -yydefact[yystate];
+ *yyconflicts = yyconfl;
+ }
+ else if (! yytable_value_is_error (yytable[yyindex]))
+ {
+ *yyaction = yytable[yyindex];
+ *yyconflicts = yyconfl + yyconflp[yyindex];
+ }
+ else
+ {
+ *yyaction = 0;
+ *yyconflicts = yyconfl + yyconflp[yyindex];
+ }
+}
+
+static inline yyStateNum
+yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
+{
+ int yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
+ if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
+ return yytable[yyr];
+ else
+ return yydefgoto[yylhs - YYNTOKENS];
+}
+
+static inline yybool
+yyisShiftAction (int yyaction)
+{
+ return 0 < yyaction;
+}
+
+static inline yybool
+yyisErrorAction (int yyaction)
+{
+ return yyaction == 0;
+}
+
+ /* GLRStates */
+
+/** Return a fresh GLRStackItem in YYSTACKP. The item is an LR state
+ * if YYISSTATE, and otherwise a semantic option. Callers should call
+ * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient
+ * headroom. */
+
+static inline yyGLRStackItem*
+yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState)
+{
+ yyGLRStackItem* yynewItem = yystackp->yynextFree;
+ yystackp->yyspaceLeft -= 1;
+ yystackp->yynextFree += 1;
+ yynewItem->yystate.yyisState = yyisState;
+ return yynewItem;
+}
+
+/** Add a new semantic action that will execute the action for rule
+ * YYRULE on the semantic values in YYRHS to the list of
+ * alternative actions for YYSTATE. Assumes that YYRHS comes from
+ * stack #YYK of *YYSTACKP. */
+static void
+yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate,
+ yyGLRState* yyrhs, yyRuleNum yyrule)
+{
+ yySemanticOption* yynewOption =
+ &yynewGLRStackItem (yystackp, yyfalse)->yyoption;
+ yynewOption->yystate = yyrhs;
+ yynewOption->yyrule = yyrule;
+ if (yystackp->yytops.yylookaheadNeeds[yyk])
+ {
+ yynewOption->yyrawchar = yychar;
+ yynewOption->yyval = yylval;]b4_locations_if([
+ yynewOption->yyloc = yylloc;])[
+ }
+ else
+ yynewOption->yyrawchar = YYEMPTY;
+ yynewOption->yynext = yystate->yysemantics.yyfirstVal;
+ yystate->yysemantics.yyfirstVal = yynewOption;
+
+ YY_RESERVE_GLRSTACK (yystackp);
+}
+
+ /* GLRStacks */
+
+/** Initialize YYSET to a singleton set containing an empty stack. */
+static yybool
+yyinitStateSet (yyGLRStateSet* yyset)
+{
+ yyset->yysize = 1;
+ yyset->yycapacity = 16;
+ yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]);
+ if (! yyset->yystates)
+ return yyfalse;
+ yyset->yystates[0] = YY_NULL;
+ yyset->yylookaheadNeeds =
+ (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]);
+ if (! yyset->yylookaheadNeeds)
+ {
+ YYFREE (yyset->yystates);
+ return yyfalse;
+ }
+ return yytrue;
+}
+
+static void yyfreeStateSet (yyGLRStateSet* yyset)
+{
+ YYFREE (yyset->yystates);
+ YYFREE (yyset->yylookaheadNeeds);
+}
+
+/** Initialize *YYSTACKP to a single empty stack, with total maximum
+ * capacity for all stacks of YYSIZE. */
+static yybool
+yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
+{
+ yystackp->yyerrState = 0;
+ yynerrs = 0;
+ yystackp->yyspaceLeft = yysize;
+ yystackp->yyitems =
+ (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]);
+ if (!yystackp->yyitems)
+ return yyfalse;
+ yystackp->yynextFree = yystackp->yyitems;
+ yystackp->yysplitPoint = YY_NULL;
+ yystackp->yylastDeleted = YY_NULL;
+ return yyinitStateSet (&yystackp->yytops);
+}
+
+
+#if YYSTACKEXPANDABLE
+# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
+ &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE
+
+/** If *YYSTACKP is expandable, extend it. WARNING: Pointers into the
+ stack from outside should be considered invalid after this call.
+ We always expand when there are 1 or fewer items left AFTER an
+ allocation, so that we can avoid having external pointers exist
+ across an allocation. */
+static void
+yyexpandGLRStack (yyGLRStack* yystackp)
+{
+ yyGLRStackItem* yynewItems;
+ yyGLRStackItem* yyp0, *yyp1;
+ size_t yynewSize;
+ size_t yyn;
+ size_t yysize = yystackp->yynextFree - yystackp->yyitems;
+ if (YYMAXDEPTH - YYHEADROOM < yysize)
+ yyMemoryExhausted (yystackp);
+ yynewSize = 2*yysize;
+ if (YYMAXDEPTH < yynewSize)
+ yynewSize = YYMAXDEPTH;
+ yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]);
+ if (! yynewItems)
+ yyMemoryExhausted (yystackp);
+ for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize;
+ 0 < yyn;
+ yyn -= 1, yyp0 += 1, yyp1 += 1)
+ {
+ *yyp1 = *yyp0;
+ if (*(yybool *) yyp0)
+ {
+ yyGLRState* yys0 = &yyp0->yystate;
+ yyGLRState* yys1 = &yyp1->yystate;
+ if (yys0->yypred != YY_NULL)
+ yys1->yypred =
+ YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
+ if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != YY_NULL)
+ yys1->yysemantics.yyfirstVal =
+ YYRELOC (yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
+ }
+ else
+ {
+ yySemanticOption* yyv0 = &yyp0->yyoption;
+ yySemanticOption* yyv1 = &yyp1->yyoption;
+ if (yyv0->yystate != YY_NULL)
+ yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate);
+ if (yyv0->yynext != YY_NULL)
+ yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption);
+ }
+ }
+ if (yystackp->yysplitPoint != YY_NULL)
+ yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems,
+ yystackp->yysplitPoint, yystate);
+
+ for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1)
+ if (yystackp->yytops.yystates[yyn] != YY_NULL)
+ yystackp->yytops.yystates[yyn] =
+ YYRELOC (yystackp->yyitems, yynewItems,
+ yystackp->yytops.yystates[yyn], yystate);
+ YYFREE (yystackp->yyitems);
+ yystackp->yyitems = yynewItems;
+ yystackp->yynextFree = yynewItems + yysize;
+ yystackp->yyspaceLeft = yynewSize - yysize;
+}
+#endif
+
+static void
+yyfreeGLRStack (yyGLRStack* yystackp)
+{
+ YYFREE (yystackp->yyitems);
+ yyfreeStateSet (&yystackp->yytops);
+}
+
+/** Assuming that YYS is a GLRState somewhere on *YYSTACKP, update the
+ * splitpoint of *YYSTACKP, if needed, so that it is at least as deep as
+ * YYS. */
+static inline void
+yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
+{
+ if (yystackp->yysplitPoint != YY_NULL && yystackp->yysplitPoint > yys)
+ yystackp->yysplitPoint = yys;
+}
+
+/** Invalidate stack #YYK in *YYSTACKP. */
+static inline void
+yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
+{
+ if (yystackp->yytops.yystates[yyk] != YY_NULL)
+ yystackp->yylastDeleted = yystackp->yytops.yystates[yyk];
+ yystackp->yytops.yystates[yyk] = YY_NULL;
+}
+
+/** Undelete the last stack in *YYSTACKP that was marked as deleted. Can
+ only be done once after a deletion, and only when all other stacks have
+ been deleted. */
+static void
+yyundeleteLastStack (yyGLRStack* yystackp)
+{
+ if (yystackp->yylastDeleted == YY_NULL || yystackp->yytops.yysize != 0)
+ return;
+ yystackp->yytops.yystates[0] = yystackp->yylastDeleted;
+ yystackp->yytops.yysize = 1;
+ YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
+ yystackp->yylastDeleted = YY_NULL;
+}
+
+static inline void
+yyremoveDeletes (yyGLRStack* yystackp)
+{
+ size_t yyi, yyj;
+ yyi = yyj = 0;
+ while (yyj < yystackp->yytops.yysize)
+ {
+ if (yystackp->yytops.yystates[yyi] == YY_NULL)
+ {
+ if (yyi == yyj)
+ {
+ YYDPRINTF ((stderr, "Removing dead stacks.\n"));
+ }
+ yystackp->yytops.yysize -= 1;
+ }
+ else
+ {
+ yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi];
+ /* In the current implementation, it's unnecessary to copy
+ yystackp->yytops.yylookaheadNeeds[yyi] since, after
+ yyremoveDeletes returns, the parser immediately either enters
+ deterministic operation or shifts a token. However, it doesn't
+ hurt, and the code might evolve to need it. */
+ yystackp->yytops.yylookaheadNeeds[yyj] =
+ yystackp->yytops.yylookaheadNeeds[yyi];
+ if (yyj != yyi)
+ {
+ YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n",
+ (unsigned long int) yyi, (unsigned long int) yyj));
+ }
+ yyj += 1;
+ }
+ yyi += 1;
+ }
+}
+
+/** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR
+ * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic
+ * value *YYVALP and source location *YYLOCP. */
+static inline void
+yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
+ size_t yyposn,
+ YYSTYPE* yyvalp]b4_locations_if([, YYLTYPE* yylocp])[)
+{
+ yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
+
+ yynewState->yylrState = yylrState;
+ yynewState->yyposn = yyposn;
+ yynewState->yyresolved = yytrue;
+ yynewState->yypred = yystackp->yytops.yystates[yyk];
+ yynewState->yysemantics.yysval = *yyvalp;]b4_locations_if([
+ yynewState->yyloc = *yylocp;])[
+ yystackp->yytops.yystates[yyk] = yynewState;
+
+ YY_RESERVE_GLRSTACK (yystackp);
+}
+
+/** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR
+ * state YYLRSTATE, at input position YYPOSN, with the (unresolved)
+ * semantic value of YYRHS under the action for YYRULE. */
+static inline void
+yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
+ size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
+{
+ yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate;
+
+ yynewState->yylrState = yylrState;
+ yynewState->yyposn = yyposn;
+ yynewState->yyresolved = yyfalse;
+ yynewState->yypred = yystackp->yytops.yystates[yyk];
+ yynewState->yysemantics.yyfirstVal = YY_NULL;
+ yystackp->yytops.yystates[yyk] = yynewState;
+
+ /* Invokes YY_RESERVE_GLRSTACK. */
+ yyaddDeferredAction (yystackp, yyk, yynewState, yyrhs, yyrule);
+}
+
+#if !]b4_api_PREFIX[DEBUG
+# define YY_REDUCE_PRINT(Args)
+#else
+# define YY_REDUCE_PRINT(Args) \
+do { \
+ if (yydebug) \
+ yy_reduce_print Args; \
+} while (0)
+
+/*----------------------------------------------------------------------.
+| Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. |
+`----------------------------------------------------------------------*/
+
+static inline void
+yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
+ yyRuleNum yyrule]b4_user_formals[)
+{
+ int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
+ int yylow = 1;])[
+ int yyi;
+ YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n",
+ (unsigned long int) yyk, yyrule - 1,
+ (unsigned long int) yyrline[yyrule]);
+ if (! yynormal)
+ yyfillin (yyvsp, 1, -yynrhs);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr,
+ yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
+ &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval
+ ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
+ b4_user_args[);
+ if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
+ YYFPRINTF (stderr, " (unresolved)");
+ YYFPRINTF (stderr, "\n");
+ }
+}
+#endif
+
+/** Pop the symbols consumed by reduction #YYRULE from the top of stack
+ * #YYK of *YYSTACKP, and perform the appropriate semantic action on their
+ * semantic values. Assumes that all ambiguities in semantic values
+ * have been previously resolved. Set *YYVALP to the resulting value,
+ * and *YYLOCP to the computed location (if any). Return value is as
+ * for userAction. */
+static inline YYRESULTTAG
+yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
+ YYSTYPE* yyvalp]b4_locuser_formals[)
+{
+ int yynrhs = yyrhsLength (yyrule);
+
+ if (yystackp->yysplitPoint == YY_NULL)
+ {
+ /* Standard special case: single stack. */
+ yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
+ YYASSERT (yyk == 0);
+ yystackp->yynextFree -= yynrhs;
+ yystackp->yyspaceLeft += yynrhs;
+ yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
+ YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[));
+ return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
+ yyvalp]b4_locuser_args[);
+ }
+ else
+ {
+ int yyi;
+ yyGLRState* yys;
+ yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
+ yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
+ = yystackp->yytops.yystates[yyk];]b4_locations_if([[
+ if (yynrhs == 0)
+ /* Set default location. */
+ yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
+ for (yyi = 0; yyi < yynrhs; yyi += 1)
+ {
+ yys = yys->yypred;
+ YYASSERT (yys);
+ }
+ yyupdateSplit (yystackp, yys);
+ yystackp->yytops.yystates[yyk] = yys;
+ YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
+ return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
+ yystackp, yyvalp]b4_locuser_args[);
+ }
+}
+
+/** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE,
+ * and push back on the resulting nonterminal symbol. Perform the
+ * semantic action associated with YYRULE and store its value with the
+ * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently
+ * unambiguous. Otherwise, store the deferred semantic action with
+ * the new state. If the new state would have an identical input
+ * position, LR state, and predecessor to an existing state on the stack,
+ * it is identified with that existing state, eliminating stack #YYK from
+ * *YYSTACKP. In this case, the semantic value is
+ * added to the options for the existing state's semantic value.
+ */
+static inline YYRESULTTAG
+yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
+ yybool yyforceEval]b4_user_formals[)
+{
+ size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn;
+
+ if (yyforceEval || yystackp->yysplitPoint == YY_NULL)
+ {
+ YYRESULTTAG yyflag;
+ YYSTYPE yysval;]b4_locations_if([
+ YYLTYPE yyloc;])[
+
+ yyflag = yydoAction (yystackp, yyk, yyrule, &yysval]b4_locuser_args([&yyloc])[);
+ if (yyflag == yyerr && yystackp->yysplitPoint != YY_NULL)
+ {
+ YYDPRINTF ((stderr, "Parse on stack %lu rejected by rule #%d.\n",
+ (unsigned long int) yyk, yyrule - 1));
+ }
+ if (yyflag != yyok)
+ return yyflag;
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc);
+ yyglrShift (yystackp, yyk,
+ yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState,
+ yylhsNonterm (yyrule)),
+ yyposn, &yysval]b4_locations_if([, &yyloc])[);
+ }
+ else
+ {
+ size_t yyi;
+ int yyn;
+ yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk];
+ yyStateNum yynewLRState;
+
+ for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
+ 0 < yyn; yyn -= 1)
+ {
+ yys = yys->yypred;
+ YYASSERT (yys);
+ }
+ yyupdateSplit (yystackp, yys);
+ yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
+ YYDPRINTF ((stderr,
+ "Reduced stack %lu by rule #%d; action deferred. "
+ "Now in state %d.\n",
+ (unsigned long int) yyk, yyrule - 1, yynewLRState));
+ for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
+ if (yyi != yyk && yystackp->yytops.yystates[yyi] != YY_NULL)
+ {
+ yyGLRState *yysplit = yystackp->yysplitPoint;
+ yyGLRState *yyp = yystackp->yytops.yystates[yyi];
+ while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
+ {
+ if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
+ {
+ yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule);
+ yymarkStackDeleted (yystackp, yyk);
+ YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n",
+ (unsigned long int) yyk,
+ (unsigned long int) yyi));
+ return yyok;
+ }
+ yyp = yyp->yypred;
+ }
+ }
+ yystackp->yytops.yystates[yyk] = yys;
+ yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule);
+ }
+ return yyok;
+}
+
+static size_t
+yysplitStack (yyGLRStack* yystackp, size_t yyk)
+{
+ if (yystackp->yysplitPoint == YY_NULL)
+ {
+ YYASSERT (yyk == 0);
+ yystackp->yysplitPoint = yystackp->yytops.yystates[yyk];
+ }
+ if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
+ {
+ yyGLRState** yynewStates;
+ yybool* yynewLookaheadNeeds;
+
+ yynewStates = YY_NULL;
+
+ if (yystackp->yytops.yycapacity
+ > (YYSIZEMAX / (2 * sizeof yynewStates[0])))
+ yyMemoryExhausted (yystackp);
+ yystackp->yytops.yycapacity *= 2;
+
+ yynewStates =
+ (yyGLRState**) YYREALLOC (yystackp->yytops.yystates,
+ (yystackp->yytops.yycapacity
+ * sizeof yynewStates[0]));
+ if (yynewStates == YY_NULL)
+ yyMemoryExhausted (yystackp);
+ yystackp->yytops.yystates = yynewStates;
+
+ yynewLookaheadNeeds =
+ (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds,
+ (yystackp->yytops.yycapacity
+ * sizeof yynewLookaheadNeeds[0]));
+ if (yynewLookaheadNeeds == YY_NULL)
+ yyMemoryExhausted (yystackp);
+ yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds;
+ }
+ yystackp->yytops.yystates[yystackp->yytops.yysize]
+ = yystackp->yytops.yystates[yyk];
+ yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize]
+ = yystackp->yytops.yylookaheadNeeds[yyk];
+ yystackp->yytops.yysize += 1;
+ return yystackp->yytops.yysize-1;
+}
+
+/** True iff YYY0 and YYY1 represent identical options at the top level.
+ * That is, they represent the same rule applied to RHS symbols
+ * that produce the same terminal symbols. */
+static yybool
+yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
+{
+ if (yyy0->yyrule == yyy1->yyrule)
+ {
+ yyGLRState *yys0, *yys1;
+ int yyn;
+ for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
+ yyn = yyrhsLength (yyy0->yyrule);
+ yyn > 0;
+ yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
+ if (yys0->yyposn != yys1->yyposn)
+ return yyfalse;
+ return yytrue;
+ }
+ else
+ return yyfalse;
+}
+
+/** Assuming identicalOptions (YYY0,YYY1), destructively merge the
+ * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */
+static void
+yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
+{
+ yyGLRState *yys0, *yys1;
+ int yyn;
+ for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
+ yyn = yyrhsLength (yyy0->yyrule);
+ yyn > 0;
+ yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
+ {
+ if (yys0 == yys1)
+ break;
+ else if (yys0->yyresolved)
+ {
+ yys1->yyresolved = yytrue;
+ yys1->yysemantics.yysval = yys0->yysemantics.yysval;
+ }
+ else if (yys1->yyresolved)
+ {
+ yys0->yyresolved = yytrue;
+ yys0->yysemantics.yysval = yys1->yysemantics.yysval;
+ }
+ else
+ {
+ yySemanticOption** yyz0p = &yys0->yysemantics.yyfirstVal;
+ yySemanticOption* yyz1 = yys1->yysemantics.yyfirstVal;
+ while (yytrue)
+ {
+ if (yyz1 == *yyz0p || yyz1 == YY_NULL)
+ break;
+ else if (*yyz0p == YY_NULL)
+ {
+ *yyz0p = yyz1;
+ break;
+ }
+ else if (*yyz0p < yyz1)
+ {
+ yySemanticOption* yyz = *yyz0p;
+ *yyz0p = yyz1;
+ yyz1 = yyz1->yynext;
+ (*yyz0p)->yynext = yyz;
+ }
+ yyz0p = &(*yyz0p)->yynext;
+ }
+ yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal;
+ }
+ }
+}
+
+/** Y0 and Y1 represent two possible actions to take in a given
+ * parsing state; return 0 if no combination is possible,
+ * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
+static int
+yypreference (yySemanticOption* y0, yySemanticOption* y1)
+{
+ yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
+ int p0 = yydprec[r0], p1 = yydprec[r1];
+
+ if (p0 == p1)
+ {
+ if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
+ return 0;
+ else
+ return 1;
+ }
+ if (p0 == 0 || p1 == 0)
+ return 0;
+ if (p0 < p1)
+ return 3;
+ if (p1 < p0)
+ return 2;
+ return 0;
+}
+
+static YYRESULTTAG yyresolveValue (yyGLRState* yys,
+ yyGLRStack* yystackp]b4_user_formals[);
+
+
+/** Resolve the previous YYN states starting at and including state YYS
+ * on *YYSTACKP. If result != yyok, some states may have been left
+ * unresolved possibly with empty semantic option chains. Regardless
+ * of whether result = yyok, each state has been left with consistent
+ * data so that yydestroyGLRState can be invoked if necessary. */
+static YYRESULTTAG
+yyresolveStates (yyGLRState* yys, int yyn,
+ yyGLRStack* yystackp]b4_user_formals[)
+{
+ if (0 < yyn)
+ {
+ YYASSERT (yys->yypred);
+ YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp]b4_user_args[));
+ if (! yys->yyresolved)
+ YYCHK (yyresolveValue (yys, yystackp]b4_user_args[));
+ }
+ return yyok;
+}
+
+/** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its
+ * user action, and return the semantic value and location in *YYVALP
+ * and *YYLOCP. Regardless of whether result = yyok, all RHS states
+ * have been destroyed (assuming the user action destroys all RHS
+ * semantic values if invoked). */
+static YYRESULTTAG
+yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp,
+ YYSTYPE* yyvalp]b4_locuser_formals[)
+{
+ yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
+ int yynrhs = yyrhsLength (yyopt->yyrule);
+ YYRESULTTAG yyflag =
+ yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[);
+ if (yyflag != yyok)
+ {
+ yyGLRState *yys;
+ for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1)
+ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
+ return yyflag;
+ }
+
+ yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_locations_if([[
+ if (yynrhs == 0)
+ /* Set default location. */
+ yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
+ {
+ int yychar_current = yychar;
+ YYSTYPE yylval_current = yylval;]b4_locations_if([
+ YYLTYPE yylloc_current = yylloc;])[
+ yychar = yyopt->yyrawchar;
+ yylval = yyopt->yyval;]b4_locations_if([
+ yylloc = yyopt->yyloc;])[
+ yyflag = yyuserAction (yyopt->yyrule, yynrhs,
+ yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
+ yystackp, yyvalp]b4_locuser_args[);
+ yychar = yychar_current;
+ yylval = yylval_current;]b4_locations_if([
+ yylloc = yylloc_current;])[
+ }
+ return yyflag;
+}
+
+#if ]b4_api_PREFIX[DEBUG
+static void
+yyreportTree (yySemanticOption* yyx, int yyindent)
+{
+ int yynrhs = yyrhsLength (yyx->yyrule);
+ int yyi;
+ yyGLRState* yys;
+ yyGLRState* yystates[1 + YYMAXRHS];
+ yyGLRState yyleftmost_state;
+
+ for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
+ yystates[yyi] = yys;
+ if (yys == YY_NULL)
+ {
+ yyleftmost_state.yyposn = 0;
+ yystates[0] = &yyleftmost_state;
+ }
+ else
+ yystates[0] = yys;
+
+ if (yyx->yystate->yyposn < yys->yyposn + 1)
+ YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
+ yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
+ yyx->yyrule - 1);
+ else
+ YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n",
+ yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
+ yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1),
+ (unsigned long int) yyx->yystate->yyposn);
+ for (yyi = 1; yyi <= yynrhs; yyi += 1)
+ {
+ if (yystates[yyi]->yyresolved)
+ {
+ if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
+ YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
+ yytokenName (yystos[yystates[yyi]->yylrState]));
+ else
+ YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "",
+ yytokenName (yystos[yystates[yyi]->yylrState]),
+ (unsigned long int) (yystates[yyi-1]->yyposn + 1),
+ (unsigned long int) yystates[yyi]->yyposn);
+ }
+ else
+ yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
+ }
+}
+#endif
+
+static YYRESULTTAG
+yyreportAmbiguity (yySemanticOption* yyx0,
+ yySemanticOption* yyx1]b4_pure_formals[)
+{
+ YYUSE (yyx0);
+ YYUSE (yyx1);
+
+#if ]b4_api_PREFIX[DEBUG
+ YYFPRINTF (stderr, "Ambiguity detected.\n");
+ YYFPRINTF (stderr, "Option 1,\n");
+ yyreportTree (yyx0, 2);
+ YYFPRINTF (stderr, "\nOption 2,\n");
+ yyreportTree (yyx1, 2);
+ YYFPRINTF (stderr, "\n");
+#endif
+
+ yyerror (]b4_yyerror_args[YY_("syntax is ambiguous"));
+ return yyabort;
+}]b4_locations_if([[
+
+/** Resolve the locations for each of the YYN1 states in *YYSTACKP,
+ * ending at YYS1. Has no effect on previously resolved states.
+ * The first semantic option of a state is always chosen. */
+static void
+yyresolveLocations (yyGLRState* yys1, int yyn1,
+ yyGLRStack *yystackp]b4_user_formals[)
+{
+ if (0 < yyn1)
+ {
+ yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[);
+ if (!yys1->yyresolved)
+ {
+ yyGLRStackItem yyrhsloc[1 + YYMAXRHS];
+ int yynrhs;
+ yySemanticOption *yyoption = yys1->yysemantics.yyfirstVal;
+ YYASSERT (yyoption != YY_NULL);
+ yynrhs = yyrhsLength (yyoption->yyrule);
+ if (yynrhs > 0)
+ {
+ yyGLRState *yys;
+ int yyn;
+ yyresolveLocations (yyoption->yystate, yynrhs,
+ yystackp]b4_user_args[);
+ for (yys = yyoption->yystate, yyn = yynrhs;
+ yyn > 0;
+ yys = yys->yypred, yyn -= 1)
+ yyrhsloc[yyn].yystate.yyloc = yys->yyloc;
+ }
+ else
+ {
+ /* Both yyresolveAction and yyresolveLocations traverse the GSS
+ in reverse rightmost order. It is only necessary to invoke
+ yyresolveLocations on a subforest for which yyresolveAction
+ would have been invoked next had an ambiguity not been
+ detected. Thus the location of the previous state (but not
+ necessarily the previous state itself) is guaranteed to be
+ resolved already. */
+ yyGLRState *yyprevious = yyoption->yystate;
+ yyrhsloc[0].yystate.yyloc = yyprevious->yyloc;
+ }
+ {
+ int yychar_current = yychar;
+ YYSTYPE yylval_current = yylval;
+ YYLTYPE yylloc_current = yylloc;
+ yychar = yyoption->yyrawchar;
+ yylval = yyoption->yyval;
+ yylloc = yyoption->yyloc;
+ YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs);
+ yychar = yychar_current;
+ yylval = yylval_current;
+ yylloc = yylloc_current;
+ }
+ }
+ }
+}]])[
+
+/** Resolve the ambiguity represented in state YYS in *YYSTACKP,
+ * perform the indicated actions, and set the semantic value of YYS.
+ * If result != yyok, the chain of semantic options in YYS has been
+ * cleared instead or it has been left unmodified except that
+ * redundant options may have been removed. Regardless of whether
+ * result = yyok, YYS has been left with consistent data so that
+ * yydestroyGLRState can be invoked if necessary. */
+static YYRESULTTAG
+yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[)
+{
+ yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal;
+ yySemanticOption* yybest = yyoptionList;
+ yySemanticOption** yypp;
+ yybool yymerge = yyfalse;
+ YYSTYPE yysval;
+ YYRESULTTAG yyflag;]b4_locations_if([
+ YYLTYPE *yylocp = &yys->yyloc;])[
+
+ for (yypp = &yyoptionList->yynext; *yypp != YY_NULL; )
+ {
+ yySemanticOption* yyp = *yypp;
+
+ if (yyidenticalOptions (yybest, yyp))
+ {
+ yymergeOptionSets (yybest, yyp);
+ *yypp = yyp->yynext;
+ }
+ else
+ {
+ switch (yypreference (yybest, yyp))
+ {
+ case 0:]b4_locations_if([[
+ yyresolveLocations (yys, 1, yystackp]b4_user_args[);]])[
+ return yyreportAmbiguity (yybest, yyp]b4_pure_args[);
+ break;
+ case 1:
+ yymerge = yytrue;
+ break;
+ case 2:
+ break;
+ case 3:
+ yybest = yyp;
+ yymerge = yyfalse;
+ break;
+ default:
+ /* This cannot happen so it is not worth a YYASSERT (yyfalse),
+ but some compilers complain if the default case is
+ omitted. */
+ break;
+ }
+ yypp = &yyp->yynext;
+ }
+ }
+
+ if (yymerge)
+ {
+ yySemanticOption* yyp;
+ int yyprec = yydprec[yybest->yyrule];
+ yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args[);
+ if (yyflag == yyok)
+ for (yyp = yybest->yynext; yyp != YY_NULL; yyp = yyp->yynext)
+ {
+ if (yyprec == yydprec[yyp->yyrule])
+ {
+ YYSTYPE yysval_other;]b4_locations_if([
+ YYLTYPE yydummy;])[
+ yyflag = yyresolveAction (yyp, yystackp, &yysval_other]b4_locuser_args([&yydummy])[);
+ if (yyflag != yyok)
+ {
+ yydestruct ("Cleanup: discarding incompletely merged value for",
+ yystos[yys->yylrState],
+ &yysval]b4_locuser_args[);
+ break;
+ }
+ yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other);
+ }
+ }
+ }
+ else
+ yyflag = yyresolveAction (yybest, yystackp, &yysval]b4_locuser_args([yylocp])[);
+
+ if (yyflag == yyok)
+ {
+ yys->yyresolved = yytrue;
+ yys->yysemantics.yysval = yysval;
+ }
+ else
+ yys->yysemantics.yyfirstVal = YY_NULL;
+ return yyflag;
+}
+
+static YYRESULTTAG
+yyresolveStack (yyGLRStack* yystackp]b4_user_formals[)
+{
+ if (yystackp->yysplitPoint != YY_NULL)
+ {
+ yyGLRState* yys;
+ int yyn;
+
+ for (yyn = 0, yys = yystackp->yytops.yystates[0];
+ yys != yystackp->yysplitPoint;
+ yys = yys->yypred, yyn += 1)
+ continue;
+ YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp
+ ]b4_user_args[));
+ }
+ return yyok;
+}
+
+static void
+yycompressStack (yyGLRStack* yystackp)
+{
+ yyGLRState* yyp, *yyq, *yyr;
+
+ if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == YY_NULL)
+ return;
+
+ for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = YY_NULL;
+ yyp != yystackp->yysplitPoint;
+ yyr = yyp, yyp = yyq, yyq = yyp->yypred)
+ yyp->yypred = yyr;
+
+ yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
+ yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
+ yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
+ yystackp->yysplitPoint = YY_NULL;
+ yystackp->yylastDeleted = YY_NULL;
+
+ while (yyr != YY_NULL)
+ {
+ yystackp->yynextFree->yystate = *yyr;
+ yyr = yyr->yypred;
+ yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate;
+ yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate;
+ yystackp->yynextFree += 1;
+ yystackp->yyspaceLeft -= 1;
+ }
+}
+
+static YYRESULTTAG
+yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
+ size_t yyposn]b4_pure_formals[)
+{
+ while (yystackp->yytops.yystates[yyk] != YY_NULL)
+ {
+ yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState;
+ YYDPRINTF ((stderr, "Stack %lu Entering state %d\n",
+ (unsigned long int) yyk, yystate));
+
+ YYASSERT (yystate != YYFINAL);
+
+ if (yyisDefaultedState (yystate))
+ {
+ YYRESULTTAG yyflag;
+ yyRuleNum yyrule = yydefaultAction (yystate);
+ if (yyrule == 0)
+ {
+ YYDPRINTF ((stderr, "Stack %lu dies.\n",
+ (unsigned long int) yyk));
+ yymarkStackDeleted (yystackp, yyk);
+ return yyok;
+ }
+ yyflag = yyglrReduce (yystackp, yyk, yyrule, yyimmediate[yyrule]]b4_user_args[);
+ if (yyflag == yyerr)
+ {
+ YYDPRINTF ((stderr,
+ "Stack %lu dies "
+ "(predicate failure or explicit user error).\n",
+ (unsigned long int) yyk));
+ yymarkStackDeleted (yystackp, yyk);
+ return yyok;
+ }
+ if (yyflag != yyok)
+ return yyflag;
+ }
+ else
+ {
+ yySymbol yytoken;
+ int yyaction;
+ const short int* yyconflicts;
+
+ yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = ]b4_lex[;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
+
+ while (*yyconflicts != 0)
+ {
+ YYRESULTTAG yyflag;
+ size_t yynewStack = yysplitStack (yystackp, yyk);
+ YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n",
+ (unsigned long int) yynewStack,
+ (unsigned long int) yyk));
+ yyflag = yyglrReduce (yystackp, yynewStack,
+ *yyconflicts,
+ yyimmediate[*yyconflicts]]b4_user_args[);
+ if (yyflag == yyok)
+ YYCHK (yyprocessOneStack (yystackp, yynewStack,
+ yyposn]b4_pure_args[));
+ else if (yyflag == yyerr)
+ {
+ YYDPRINTF ((stderr, "Stack %lu dies.\n",
+ (unsigned long int) yynewStack));
+ yymarkStackDeleted (yystackp, yynewStack);
+ }
+ else
+ return yyflag;
+ yyconflicts += 1;
+ }
+
+ if (yyisShiftAction (yyaction))
+ break;
+ else if (yyisErrorAction (yyaction))
+ {
+ YYDPRINTF ((stderr, "Stack %lu dies.\n",
+ (unsigned long int) yyk));
+ yymarkStackDeleted (yystackp, yyk);
+ break;
+ }
+ else
+ {
+ YYRESULTTAG yyflag = yyglrReduce (yystackp, yyk, -yyaction,
+ yyimmediate[-yyaction]]b4_user_args[);
+ if (yyflag == yyerr)
+ {
+ YYDPRINTF ((stderr,
+ "Stack %lu dies "
+ "(predicate failure or explicit user error).\n",
+ (unsigned long int) yyk));
+ yymarkStackDeleted (yystackp, yyk);
+ break;
+ }
+ else if (yyflag != yyok)
+ return yyflag;
+ }
+ }
+ }
+ return yyok;
+}
+
+static void
+yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
+{
+ if (yystackp->yyerrState != 0)
+ return;
+#if ! YYERROR_VERBOSE
+ yyerror (]b4_lyyerror_args[YY_("syntax error"));
+#else
+ {
+ yySymbol yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
+ size_t yysize0 = yytnamerr (YY_NULL, yytokenName (yytoken));
+ size_t yysize = yysize0;
+ yybool yysize_overflow = yyfalse;
+ char* yymsg = YY_NULL;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ /* Internationalized format string. */
+ const char *yyformat = YY_NULL;
+ /* Arguments of yyformat. */
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ /* Number of reported tokens (one for the "unexpected", one per
+ "expected"). */
+ int yycount = 0;
+
+ /* There are many possibilities here to consider:
+ - If this state is a consistent state with a default action, then
+ the only way this function was invoked is if the default action
+ is an error action. In that case, don't check for expected
+ tokens because there are none.
+ - The only way there can be no lookahead present (in yychar) is if
+ this state is a consistent state with a default action. Thus,
+ detecting the absence of a lookahead is sufficient to determine
+ that there is no unexpected or expected token to report. In that
+ case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this state is a
+ consistent state with a default action. There might have been a
+ previous inconsistent state, consistent state with a non-default
+ action, or user semantic action that manipulated yychar.
+ - Of course, the expected token list depends on states to have
+ correct lookahead information, and it depends on the parser not
+ to perform extra reductions after fetching a lookahead from the
+ scanner and before detecting a syntax error. Thus, state merging
+ (from LALR or IELR) and default reductions corrupt the expected
+ token list. However, the list is correct for canonical LR with
+ one exception: it will still contain any token that will not be
+ accepted due to an error action in a later state.
+ */
+ if (yytoken != YYEMPTY)
+ {
+ int yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
+ yyarg[yycount++] = yytokenName (yytoken);
+ if (!yypact_value_is_default (yyn))
+ {
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. In other words, skip the first -YYN actions for this
+ state because they are default actions. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
+ int yyx;
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
+ && !yytable_value_is_error (yytable[yyx + yyn]))
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ break;
+ }
+ yyarg[yycount++] = yytokenName (yyx);
+ {
+ size_t yysz = yysize + yytnamerr (YY_NULL, yytokenName (yyx));
+ yysize_overflow |= yysz < yysize;
+ yysize = yysz;
+ }
+ }
+ }
+ }
+
+ switch (yycount)
+ {
+#define YYCASE_(N, S) \
+ case N: \
+ yyformat = S; \
+ break
+ YYCASE_(0, YY_("syntax error"));
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+#undef YYCASE_
+ }
+
+ {
+ size_t yysz = yysize + strlen (yyformat);
+ yysize_overflow |= yysz < yysize;
+ yysize = yysz;
+ }
+
+ if (!yysize_overflow)
+ yymsg = (char *) YYMALLOC (yysize);
+
+ if (yymsg)
+ {
+ char *yyp = yymsg;
+ int yyi = 0;
+ while ((*yyp = *yyformat))
+ {
+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyformat += 2;
+ }
+ else
+ {
+ yyp++;
+ yyformat++;
+ }
+ }
+ yyerror (]b4_lyyerror_args[yymsg);
+ YYFREE (yymsg);
+ }
+ else
+ {
+ yyerror (]b4_lyyerror_args[YY_("syntax error"));
+ yyMemoryExhausted (yystackp);
+ }
+ }
+#endif /* YYERROR_VERBOSE */
+ yynerrs += 1;
+}
+
+/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
+ yylval, and yylloc are the syntactic category, semantic value, and location
+ of the lookahead. */
+static void
+yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
+{
+ size_t yyk;
+ int yyj;
+
+ if (yystackp->yyerrState == 3)
+ /* We just shifted the error token and (perhaps) took some
+ reductions. Skip tokens until we can proceed. */
+ while (yytrue)
+ {
+ yySymbol yytoken;
+ if (yychar == YYEOF)
+ yyFail (yystackp][]b4_lpure_args[, YY_NULL);
+ if (yychar != YYEMPTY)
+ {]b4_locations_if([[
+ /* We throw away the lookahead, but the error range
+ of the shifted error token must take it into account. */
+ yyGLRState *yys = yystackp->yytops.yystates[0];
+ yyGLRStackItem yyerror_range[3];
+ yyerror_range[1].yystate.yyloc = yys->yyloc;
+ yyerror_range[2].yystate.yyloc = yylloc;
+ YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[
+ yytoken = YYTRANSLATE (yychar);
+ yydestruct ("Error: discarding",
+ yytoken, &yylval]b4_locuser_args([&yylloc])[);
+ }
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = ]b4_lex[;
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+ yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
+ if (yypact_value_is_default (yyj))
+ return;
+ yyj += yytoken;
+ if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
+ {
+ if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
+ return;
+ }
+ else if (! yytable_value_is_error (yytable[yyj]))
+ return;
+ }
+
+ /* Reduce to one stack. */
+ for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1)
+ if (yystackp->yytops.yystates[yyk] != YY_NULL)
+ break;
+ if (yyk >= yystackp->yytops.yysize)
+ yyFail (yystackp][]b4_lpure_args[, YY_NULL);
+ for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1)
+ yymarkStackDeleted (yystackp, yyk);
+ yyremoveDeletes (yystackp);
+ yycompressStack (yystackp);
+
+ /* Now pop stack until we find a state that shifts the error token. */
+ yystackp->yyerrState = 3;
+ while (yystackp->yytops.yystates[0] != YY_NULL)
+ {
+ yyGLRState *yys = yystackp->yytops.yystates[0];
+ yyj = yypact[yys->yylrState];
+ if (! yypact_value_is_default (yyj))
+ {
+ yyj += YYTERROR;
+ if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
+ && yyisShiftAction (yytable[yyj]))
+ {
+ /* Shift the error token. */]b4_locations_if([[
+ /* First adjust its location.*/
+ YYLTYPE yyerrloc;
+ yystackp->yyerror_range[2].yystate.yyloc = yylloc;
+ YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
+ YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
+ &yylval, &yyerrloc);
+ yyglrShift (yystackp, 0, yytable[yyj],
+ yys->yyposn, &yylval]b4_locations_if([, &yyerrloc])[);
+ yys = yystackp->yytops.yystates[0];
+ break;
+ }
+ }]b4_locations_if([[
+ yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
+ if (yys->yypred != YY_NULL)
+ yydestroyGLRState ("Error: popping", yys]b4_user_args[);
+ yystackp->yytops.yystates[0] = yys->yypred;
+ yystackp->yynextFree -= 1;
+ yystackp->yyspaceLeft += 1;
+ }
+ if (yystackp->yytops.yystates[0] == YY_NULL)
+ yyFail (yystackp][]b4_lpure_args[, YY_NULL);
+}
+
+#define YYCHK1(YYE) \
+ do { \
+ switch (YYE) { \
+ case yyok: \
+ break; \
+ case yyabort: \
+ goto yyabortlab; \
+ case yyaccept: \
+ goto yyacceptlab; \
+ case yyerr: \
+ goto yyuser_error; \
+ default: \
+ goto yybuglab; \
+ } \
+ } while (0)
+
+/*----------.
+| yyparse. |
+`----------*/
+
+]b4_function_define([yyparse], [int], b4_parse_param)[
+{
+ int yyresult;
+ yyGLRStack yystack;
+ yyGLRStack* const yystackp = &yystack;
+ size_t yyposn;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yychar = YYEMPTY;
+ yylval = yyval_default;]b4_locations_if([
+ yylloc = yyloc_default;])[
+]m4_ifdef([b4_initial_action], [
+b4_dollar_pushdef([yylval], [], [yylloc])dnl
+ /* User initialization code. */
+ b4_user_initial_action
+b4_dollar_popdef])[]dnl
+[
+ if (! yyinitGLRStack (yystackp, YYINITDEPTH))
+ goto yyexhaustedlab;
+ switch (YYSETJMP (yystack.yyexception_buffer))
+ {
+ case 0: break;
+ case 1: goto yyabortlab;
+ case 2: goto yyexhaustedlab;
+ default: goto yybuglab;
+ }
+ yyglrShift (&yystack, 0, 0, 0, &yylval]b4_locations_if([, &yylloc])[);
+ yyposn = 0;
+
+ while (yytrue)
+ {
+ /* For efficiency, we have two loops, the first of which is
+ specialized to deterministic operation (single stack, no
+ potential ambiguity). */
+ /* Standard mode */
+ while (yytrue)
+ {
+ yyRuleNum yyrule;
+ int yyaction;
+ const short int* yyconflicts;
+
+ yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+ if (yystate == YYFINAL)
+ goto yyacceptlab;
+ if (yyisDefaultedState (yystate))
+ {
+ yyrule = yydefaultAction (yystate);
+ if (yyrule == 0)
+ {
+]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
+ yyreportSyntaxError (&yystack]b4_user_args[);
+ goto yyuser_error;
+ }
+ YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue]b4_user_args[));
+ }
+ else
+ {
+ yySymbol yytoken;
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = ]b4_lex[;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
+ if (*yyconflicts != 0)
+ break;
+ if (yyisShiftAction (yyaction))
+ {
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+ yychar = YYEMPTY;
+ yyposn += 1;
+ yyglrShift (&yystack, 0, yyaction, yyposn, &yylval]b4_locations_if([, &yylloc])[);
+ if (0 < yystack.yyerrState)
+ yystack.yyerrState -= 1;
+ }
+ else if (yyisErrorAction (yyaction))
+ {
+]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
+ yyreportSyntaxError (&yystack]b4_user_args[);
+ goto yyuser_error;
+ }
+ else
+ YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue]b4_user_args[));
+ }
+ }
+
+ while (yytrue)
+ {
+ yySymbol yytoken_to_shift;
+ size_t yys;
+
+ for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
+ yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
+
+ /* yyprocessOneStack returns one of three things:
+
+ - An error flag. If the caller is yyprocessOneStack, it
+ immediately returns as well. When the caller is finally
+ yyparse, it jumps to an error label via YYCHK1.
+
+ - yyok, but yyprocessOneStack has invoked yymarkStackDeleted
+ (&yystack, yys), which sets the top state of yys to NULL. Thus,
+ yyparse's following invocation of yyremoveDeletes will remove
+ the stack.
+
+ - yyok, when ready to shift a token.
+
+ Except in the first case, yyparse will invoke yyremoveDeletes and
+ then shift the next token onto all remaining stacks. This
+ synchronization of the shift (that is, after all preceding
+ reductions on all stacks) helps prevent double destructor calls
+ on yylval in the event of memory exhaustion. */
+
+ for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
+ YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn]b4_lpure_args[));
+ yyremoveDeletes (&yystack);
+ if (yystack.yytops.yysize == 0)
+ {
+ yyundeleteLastStack (&yystack);
+ if (yystack.yytops.yysize == 0)
+ yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
+ YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
+ YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
+]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
+ yyreportSyntaxError (&yystack]b4_user_args[);
+ goto yyuser_error;
+ }
+
+ /* If any yyglrShift call fails, it will fail after shifting. Thus,
+ a copy of yylval will already be on stack 0 in the event of a
+ failure in the following loop. Thus, yychar is set to YYEMPTY
+ before the loop to make sure the user destructor for yylval isn't
+ called twice. */
+ yytoken_to_shift = YYTRANSLATE (yychar);
+ yychar = YYEMPTY;
+ yyposn += 1;
+ for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
+ {
+ int yyaction;
+ const short int* yyconflicts;
+ yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
+ yygetLRActions (yystate, yytoken_to_shift, &yyaction,
+ &yyconflicts);
+ /* Note that yyconflicts were handled by yyprocessOneStack. */
+ YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys));
+ YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
+ yyglrShift (&yystack, yys, yyaction, yyposn,
+ &yylval]b4_locations_if([, &yylloc])[);
+ YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
+ (unsigned long int) yys,
+ yystack.yytops.yystates[yys]->yylrState));
+ }
+
+ if (yystack.yytops.yysize == 1)
+ {
+ YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
+ YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
+ yycompressStack (&yystack);
+ break;
+ }
+ }
+ continue;
+ yyuser_error:
+ yyrecoverSyntaxError (&yystack]b4_user_args[);
+ yyposn = yystack.yytops.yystates[0]->yyposn;
+ }
+
+ yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+ yybuglab:
+ YYASSERT (yyfalse);
+ goto yyabortlab;
+
+ yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+ yyexhaustedlab:
+ yyerror (]b4_lyyerror_args[YY_("memory exhausted"));
+ yyresult = 2;
+ goto yyreturn;
+
+ yyreturn:
+ if (yychar != YYEMPTY)
+ yydestruct ("Cleanup: discarding lookahead",
+ YYTRANSLATE (yychar), &yylval]b4_locuser_args([&yylloc])[);
+
+ /* If the stack is well-formed, pop the stack until it is empty,
+ destroying its entries as we go. But free the stack regardless
+ of whether it is well-formed. */
+ if (yystack.yyitems)
+ {
+ yyGLRState** yystates = yystack.yytops.yystates;
+ if (yystates)
+ {
+ size_t yysize = yystack.yytops.yysize;
+ size_t yyk;
+ for (yyk = 0; yyk < yysize; yyk += 1)
+ if (yystates[yyk])
+ {
+ while (yystates[yyk])
+ {
+ yyGLRState *yys = yystates[yyk];
+]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
+)[ if (yys->yypred != YY_NULL)
+ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
+ yystates[yyk] = yys->yypred;
+ yystack.yynextFree -= 1;
+ yystack.yyspaceLeft += 1;
+ }
+ break;
+ }
+ }
+ yyfreeGLRStack (&yystack);
+ }
+
+ return yyresult;
+}
+
+/* DEBUGGING ONLY */
+#if ]b4_api_PREFIX[DEBUG
+static void
+yy_yypstack (yyGLRState* yys)
+{
+ if (yys->yypred)
+ {
+ yy_yypstack (yys->yypred);
+ YYFPRINTF (stderr, " -> ");
+ }
+ YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
+ (unsigned long int) yys->yyposn);
+}
+
+static void
+yypstates (yyGLRState* yyst)
+{
+ if (yyst == YY_NULL)
+ YYFPRINTF (stderr, "<null>");
+ else
+ yy_yypstack (yyst);
+ YYFPRINTF (stderr, "\n");
+}
+
+static void
+yypstack (yyGLRStack* yystackp, size_t yyk)
+{
+ yypstates (yystackp->yytops.yystates[yyk]);
+}
+
+#define YYINDEX(YYX) \
+ ((YYX) == YY_NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems)
+
+
+static void
+yypdumpstack (yyGLRStack* yystackp)
+{
+ yyGLRStackItem* yyp;
+ size_t yyi;
+ for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
+ {
+ YYFPRINTF (stderr, "%3lu. ",
+ (unsigned long int) (yyp - yystackp->yyitems));
+ if (*(yybool *) yyp)
+ {
+ YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
+ yyp->yystate.yyresolved, yyp->yystate.yylrState,
+ (unsigned long int) yyp->yystate.yyposn,
+ (long int) YYINDEX (yyp->yystate.yypred));
+ if (! yyp->yystate.yyresolved)
+ YYFPRINTF (stderr, ", firstVal: %ld",
+ (long int) YYINDEX (yyp->yystate
+ .yysemantics.yyfirstVal));
+ }
+ else
+ {
+ YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
+ yyp->yyoption.yyrule - 1,
+ (long int) YYINDEX (yyp->yyoption.yystate),
+ (long int) YYINDEX (yyp->yyoption.yynext));
+ }
+ YYFPRINTF (stderr, "\n");
+ }
+ YYFPRINTF (stderr, "Tops:");
+ for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
+ YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
+ (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
+ YYFPRINTF (stderr, "\n");
+}
+#endif
+
+#undef yylval
+#undef yychar
+#undef yynerrs]b4_locations_if([
+#undef yylloc])
+
+m4_if(b4_prefix, [yy], [],
+[[/* Substitute the variable and function names. */
+#define yyparse ]b4_prefix[parse
+#define yylex ]b4_prefix[lex
+#define yyerror ]b4_prefix[error
+#define yylval ]b4_prefix[lval
+#define yychar ]b4_prefix[char
+#define yydebug ]b4_prefix[debug
+#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
+#define yylloc ]b4_prefix[lloc]])])[
+
+]b4_epilogue[]dnl
+b4_output_end()
+
+# glr.cc produces its own header.
+m4_if(b4_skeleton, ["glr.c"],
+[b4_defines_if(
+[b4_output_begin([b4_spec_defines_file])
+b4_copyright([Skeleton interface for Bison GLR parsers in C],
+ [2002-2013])[
+
+]b4_cpp_guard_open([b4_spec_defines_file])[
+]b4_shared_declarations[
+]b4_cpp_guard_close([b4_spec_defines_file])[
+]b4_output_end()
+])])
diff --git a/contrib/tools/bison/bison/data/glr.cc b/contrib/tools/bison/bison/data/glr.cc
index e57308bd82..66a2dbee0d 100644
--- a/contrib/tools/bison/bison/data/glr.cc
+++ b/contrib/tools/bison/bison/data/glr.cc
@@ -1,345 +1,345 @@
-# C++ GLR skeleton for Bison
-
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-# This skeleton produces a C++ class that encapsulates a C glr parser.
-# This is in order to reduce the maintenance burden. The glr.c
-# skeleton is clean and pure enough so that there are no real
-# problems. The C++ interface is the same as that of lalr1.cc. In
-# fact, glr.c can replace yacc.c without the user noticing any
-# difference, and similarly for glr.cc replacing lalr1.cc.
-#
-# The passing of parse-params
-#
-# The additional arguments are stored as members of the parser
-# object, yyparser. The C routines need to carry yyparser
-# throughout the C parser; that's easy: make yyparser an
-# additional parse-param. But because the C++ skeleton needs to
-# know the "real" original parse-param, we save them
-# (b4_parse_param_orig). Note that b4_parse_param is overquoted
-# (and c.m4 strips one level of quotes). This is a PITA, and
-# explains why there are so many levels of quotes.
-#
-# The locations
-#
-# We use location.cc just like lalr1.cc, but because glr.c stores
-# the locations in a union, the position and location classes
-# must not have a constructor. Therefore, contrary to lalr1.cc, we
-# must not define "b4_location_constructors". As a consequence the
-# user must initialize the first positions (in particular the
-# filename member).
-
-# We require a pure interface.
-m4_define([b4_pure_flag], [1])
-
-m4_include(b4_pkgdatadir/[c++.m4])
-b4_bison_locations_if([m4_include(b4_pkgdatadir/[location.cc])])
-
-m4_define([b4_parser_class_name],
- [b4_percent_define_get([[parser_class_name]])])
-
-# Save the parse parameters.
-m4_define([b4_parse_param_orig], m4_defn([b4_parse_param]))
-
-# b4_parse_param_wrap
-# -------------------
-# New ones.
-m4_ifset([b4_parse_param],
-[m4_define([b4_parse_param_wrap],
- [[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]],]
-m4_defn([b4_parse_param]))],
-[m4_define([b4_parse_param_wrap],
- [[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]]])
-])
-
-
-# b4_yy_symbol_print_define
-# -------------------------
-# Bypass the default implementation to generate the "yy_symbol_print"
-# and "yy_symbol_value_print" functions.
-m4_define([b4_yy_symbol_print_define],
-[[
-/*--------------------.
-| Print this symbol. |
-`--------------------*/
-
-]b4_function_define([yy_symbol_print],
- [static void],
- [[FILE *], []],
- [[int yytype], [yytype]],
- [[const ]b4_namespace_ref::b4_parser_class_name[::semantic_type *yyvaluep],
- [yyvaluep]][]dnl
-b4_locations_if([,
- [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
- [yylocationp]]]),
- b4_parse_param)[
-{
-]b4_parse_param_use[]dnl
-[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[);
-}
-]])[
-
-# Hijack the initial action to initialize the locations.
-]b4_bison_locations_if([m4_define([b4_initial_action],
-[yylloc.initialize ();]m4_ifdef([b4_initial_action], [
-m4_defn([b4_initial_action])]))])[
-
-# Hijack the post prologue to insert early definition of YYLLOC_DEFAULT
-# and declaration of yyerror.
-]m4_append([b4_post_prologue],
-[b4_syncline([@oline@], [@ofile@])[
-]b4_yylloc_default_define[
-#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
-]b4_function_declare([yyerror],
- [static void],b4_locations_if([
- [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
- [yylocationp]],])
- b4_parse_param,
- [[const char* msg], [msg]])])
-
-
-#undef yynerrs
-#undef yychar
-#undef yylval]b4_locations_if([
-#undef yylloc])
-
-m4_if(b4_prefix, [yy], [],
-[[/* Substitute the variable and function names. */
-#define yyparse ]b4_prefix[parse
-#define yylex ]b4_prefix[lex
-#define yyerror ]b4_prefix[error
-#define yydebug ]b4_prefix[debug
-]]b4_pure_if([], [[
-#define yylval ]b4_prefix[lval
-#define yychar ]b4_prefix[char
-#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
-#define yylloc ]b4_prefix[lloc]])]))
-
-# Hijack the epilogue to define implementations (yyerror, parser member
-# functions etc.).
-m4_append([b4_epilogue],
-[b4_syncline([@oline@], [@ofile@])[
-
-/*------------------.
-| Report an error. |
-`------------------*/
-
-]b4_function_define([yyerror],
- [static void],b4_locations_if([
- [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
- [yylocationp]],])
- b4_parse_param,
- [[const char* msg], [msg]])[
-{
-]b4_parse_param_use[]dnl
-[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
-}
-
-
-]b4_namespace_open[
-]dnl In this section, the parse params are the original parse_params.
-m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
-[ /// Build a parser object.
- ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
- :])[
-#if ]b4_api_PREFIX[DEBUG
- ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
-#endif]b4_parse_param_cons[
- {
- }
-
- ]b4_parser_class_name::~b4_parser_class_name[ ()
- {
- }
-
- int
- ]b4_parser_class_name[::parse ()
- {
- return ::yyparse (*this]b4_user_args[);
- }
-
-#if ]b4_api_PREFIX[DEBUG
- /*--------------------.
- | Print this symbol. |
- `--------------------*/
-
- inline void
- ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
- const semantic_type* yyvaluep]b4_locations_if([[,
- const location_type* yylocationp]])[)
- {]b4_locations_if([[
- YYUSE (yylocationp);]])[
- YYUSE (yyvaluep);
- std::ostream& yyoutput = debug_stream ();
- std::ostream& yyo = yyoutput;
- YYUSE (yyo);
- ]b4_symbol_actions([printer])[
- }
-
-
- void
- ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
- const semantic_type* yyvaluep]b4_locations_if([[,
- const location_type* yylocationp]])[)
- {
- *yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
- << ' ' << yytname[yytype] << " ("]b4_locations_if([[
- << *yylocationp << ": "]])[;
- yy_symbol_value_print_ (yytype, yyvaluep]b4_locations_if([[, yylocationp]])[);
- *yycdebug_ << ')';
- }
-
- std::ostream&
- ]b4_parser_class_name[::debug_stream () const
- {
- return *yycdebug_;
- }
-
- void
- ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
- {
- yycdebug_ = &o;
- }
-
-
- ]b4_parser_class_name[::debug_level_type
- ]b4_parser_class_name[::debug_level () const
- {
- return yydebug;
- }
-
- void
- ]b4_parser_class_name[::set_debug_level (debug_level_type l)
- {
- // Actually, it is yydebug which is really used.
- yydebug = l;
- }
-
-#endif
-]m4_popdef([b4_parse_param])dnl
-b4_namespace_close
-])
-
-# b4_shared_declarations
-# ----------------------
-# Declaration that might either go into the header (if --defines)
-# or open coded in the parser body.
-m4_define([b4_shared_declarations],
-[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
-b4_percent_code_get([[requires]])[
-
-#include <stdexcept>
-#include <string>
-#include <iostream>]b4_defines_if([
-b4_bison_locations_if([[#include "location.hh"]])])[
-
-]b4_YYDEBUG_define[
-
-]b4_namespace_open[
-]b4_defines_if([],
-[b4_bison_locations_if([b4_position_define
-b4_location_define])])[
-
- /// A Bison parser.
- class ]b4_parser_class_name[
- {
- public:
-]b4_public_types_declare[
-
- /// Build a parser object.
- ]b4_parser_class_name[ (]b4_parse_param_decl[);
- virtual ~]b4_parser_class_name[ ();
-
- /// Parse.
- /// \returns 0 iff parsing succeeded.
- virtual int parse ();
-
- /// The current debugging stream.
- std::ostream& debug_stream () const;
- /// Set the current debugging stream.
- void set_debug_stream (std::ostream &);
-
- /// Type for debugging levels.
- typedef int debug_level_type;
- /// The current debugging level.
- debug_level_type debug_level () const;
- /// Set the current debugging level.
- void set_debug_level (debug_level_type l);
-
- public:
- /// Report a syntax error.]b4_locations_if([[
- /// \param loc where the syntax error is found.]])[
- /// \param msg a description of the syntax error.
- virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
-
-# if ]b4_api_PREFIX[DEBUG
- public:
- /// \brief Report a symbol value on the debug stream.
- /// \param yytype The token type.
- /// \param yyvaluep Its semantic value.]b4_locations_if([[
- /// \param yylocationp Its location.]])[
- virtual void yy_symbol_value_print_ (int yytype,
- const semantic_type* yyvaluep]b4_locations_if([[,
- const location_type* yylocationp]])[);
- /// \brief Report a symbol on the debug stream.
- /// \param yytype The token type.
- /// \param yyvaluep Its semantic value.]b4_locations_if([[
- /// \param yylocationp Its location.]])[
- virtual void yy_symbol_print_ (int yytype,
- const semantic_type* yyvaluep]b4_locations_if([[,
- const location_type* yylocationp]])[);
- private:
- // Debugging.
- std::ostream* yycdebug_;
-#endif
-
-]b4_parse_param_vars[
- };
-
-]dnl Redirections for glr.c.
-b4_percent_define_flag_if([[global_tokens_and_yystype]],
-[b4_token_defines])
-[
-#ifndef ]b4_api_PREFIX[STYPE
-# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type
-#endif
-#ifndef ]b4_api_PREFIX[LTYPE
-# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class_name[::location_type
-#endif
-
-]b4_namespace_close[
-]b4_percent_code_get([[provides]])[
-]m4_popdef([b4_parse_param])dnl
-])
-
-b4_defines_if(
-[b4_output_begin([b4_spec_defines_file])
-b4_copyright([Skeleton interface for Bison GLR parsers in C++],
- [2002-2013])[
-
-// C++ GLR parser skeleton written by Akim Demaille.
-
-]b4_cpp_guard_open([b4_spec_defines_file])[
-]b4_shared_declarations[
-]b4_cpp_guard_close([b4_spec_defines_file])[
-]b4_output_end()])
-
-# Let glr.c (and b4_shared_declarations) believe that the user
-# arguments include the parser itself.
-m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_wrap]))
-m4_include(b4_pkgdatadir/[glr.c])
-m4_popdef([b4_parse_param])
+# C++ GLR skeleton for Bison
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This skeleton produces a C++ class that encapsulates a C glr parser.
+# This is in order to reduce the maintenance burden. The glr.c
+# skeleton is clean and pure enough so that there are no real
+# problems. The C++ interface is the same as that of lalr1.cc. In
+# fact, glr.c can replace yacc.c without the user noticing any
+# difference, and similarly for glr.cc replacing lalr1.cc.
+#
+# The passing of parse-params
+#
+# The additional arguments are stored as members of the parser
+# object, yyparser. The C routines need to carry yyparser
+# throughout the C parser; that's easy: make yyparser an
+# additional parse-param. But because the C++ skeleton needs to
+# know the "real" original parse-param, we save them
+# (b4_parse_param_orig). Note that b4_parse_param is overquoted
+# (and c.m4 strips one level of quotes). This is a PITA, and
+# explains why there are so many levels of quotes.
+#
+# The locations
+#
+# We use location.cc just like lalr1.cc, but because glr.c stores
+# the locations in a union, the position and location classes
+# must not have a constructor. Therefore, contrary to lalr1.cc, we
+# must not define "b4_location_constructors". As a consequence the
+# user must initialize the first positions (in particular the
+# filename member).
+
+# We require a pure interface.
+m4_define([b4_pure_flag], [1])
+
+m4_include(b4_pkgdatadir/[c++.m4])
+b4_bison_locations_if([m4_include(b4_pkgdatadir/[location.cc])])
+
+m4_define([b4_parser_class_name],
+ [b4_percent_define_get([[parser_class_name]])])
+
+# Save the parse parameters.
+m4_define([b4_parse_param_orig], m4_defn([b4_parse_param]))
+
+# b4_parse_param_wrap
+# -------------------
+# New ones.
+m4_ifset([b4_parse_param],
+[m4_define([b4_parse_param_wrap],
+ [[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]],]
+m4_defn([b4_parse_param]))],
+[m4_define([b4_parse_param_wrap],
+ [[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]]])
+])
+
+
+# b4_yy_symbol_print_define
+# -------------------------
+# Bypass the default implementation to generate the "yy_symbol_print"
+# and "yy_symbol_value_print" functions.
+m4_define([b4_yy_symbol_print_define],
+[[
+/*--------------------.
+| Print this symbol. |
+`--------------------*/
+
+]b4_function_define([yy_symbol_print],
+ [static void],
+ [[FILE *], []],
+ [[int yytype], [yytype]],
+ [[const ]b4_namespace_ref::b4_parser_class_name[::semantic_type *yyvaluep],
+ [yyvaluep]][]dnl
+b4_locations_if([,
+ [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
+ [yylocationp]]]),
+ b4_parse_param)[
+{
+]b4_parse_param_use[]dnl
+[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[);
+}
+]])[
+
+# Hijack the initial action to initialize the locations.
+]b4_bison_locations_if([m4_define([b4_initial_action],
+[yylloc.initialize ();]m4_ifdef([b4_initial_action], [
+m4_defn([b4_initial_action])]))])[
+
+# Hijack the post prologue to insert early definition of YYLLOC_DEFAULT
+# and declaration of yyerror.
+]m4_append([b4_post_prologue],
+[b4_syncline([@oline@], [@ofile@])[
+]b4_yylloc_default_define[
+#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
+]b4_function_declare([yyerror],
+ [static void],b4_locations_if([
+ [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
+ [yylocationp]],])
+ b4_parse_param,
+ [[const char* msg], [msg]])])
+
+
+#undef yynerrs
+#undef yychar
+#undef yylval]b4_locations_if([
+#undef yylloc])
+
+m4_if(b4_prefix, [yy], [],
+[[/* Substitute the variable and function names. */
+#define yyparse ]b4_prefix[parse
+#define yylex ]b4_prefix[lex
+#define yyerror ]b4_prefix[error
+#define yydebug ]b4_prefix[debug
+]]b4_pure_if([], [[
+#define yylval ]b4_prefix[lval
+#define yychar ]b4_prefix[char
+#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
+#define yylloc ]b4_prefix[lloc]])]))
+
+# Hijack the epilogue to define implementations (yyerror, parser member
+# functions etc.).
+m4_append([b4_epilogue],
+[b4_syncline([@oline@], [@ofile@])[
+
+/*------------------.
+| Report an error. |
+`------------------*/
+
+]b4_function_define([yyerror],
+ [static void],b4_locations_if([
+ [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp],
+ [yylocationp]],])
+ b4_parse_param,
+ [[const char* msg], [msg]])[
+{
+]b4_parse_param_use[]dnl
+[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
+}
+
+
+]b4_namespace_open[
+]dnl In this section, the parse params are the original parse_params.
+m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
+[ /// Build a parser object.
+ ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
+ :])[
+#if ]b4_api_PREFIX[DEBUG
+ ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
+#endif]b4_parse_param_cons[
+ {
+ }
+
+ ]b4_parser_class_name::~b4_parser_class_name[ ()
+ {
+ }
+
+ int
+ ]b4_parser_class_name[::parse ()
+ {
+ return ::yyparse (*this]b4_user_args[);
+ }
+
+#if ]b4_api_PREFIX[DEBUG
+ /*--------------------.
+ | Print this symbol. |
+ `--------------------*/
+
+ inline void
+ ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
+ const semantic_type* yyvaluep]b4_locations_if([[,
+ const location_type* yylocationp]])[)
+ {]b4_locations_if([[
+ YYUSE (yylocationp);]])[
+ YYUSE (yyvaluep);
+ std::ostream& yyoutput = debug_stream ();
+ std::ostream& yyo = yyoutput;
+ YYUSE (yyo);
+ ]b4_symbol_actions([printer])[
+ }
+
+
+ void
+ ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
+ const semantic_type* yyvaluep]b4_locations_if([[,
+ const location_type* yylocationp]])[)
+ {
+ *yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
+ << ' ' << yytname[yytype] << " ("]b4_locations_if([[
+ << *yylocationp << ": "]])[;
+ yy_symbol_value_print_ (yytype, yyvaluep]b4_locations_if([[, yylocationp]])[);
+ *yycdebug_ << ')';
+ }
+
+ std::ostream&
+ ]b4_parser_class_name[::debug_stream () const
+ {
+ return *yycdebug_;
+ }
+
+ void
+ ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
+ {
+ yycdebug_ = &o;
+ }
+
+
+ ]b4_parser_class_name[::debug_level_type
+ ]b4_parser_class_name[::debug_level () const
+ {
+ return yydebug;
+ }
+
+ void
+ ]b4_parser_class_name[::set_debug_level (debug_level_type l)
+ {
+ // Actually, it is yydebug which is really used.
+ yydebug = l;
+ }
+
+#endif
+]m4_popdef([b4_parse_param])dnl
+b4_namespace_close
+])
+
+# b4_shared_declarations
+# ----------------------
+# Declaration that might either go into the header (if --defines)
+# or open coded in the parser body.
+m4_define([b4_shared_declarations],
+[m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
+b4_percent_code_get([[requires]])[
+
+#include <stdexcept>
+#include <string>
+#include <iostream>]b4_defines_if([
+b4_bison_locations_if([[#include "location.hh"]])])[
+
+]b4_YYDEBUG_define[
+
+]b4_namespace_open[
+]b4_defines_if([],
+[b4_bison_locations_if([b4_position_define
+b4_location_define])])[
+
+ /// A Bison parser.
+ class ]b4_parser_class_name[
+ {
+ public:
+]b4_public_types_declare[
+
+ /// Build a parser object.
+ ]b4_parser_class_name[ (]b4_parse_param_decl[);
+ virtual ~]b4_parser_class_name[ ();
+
+ /// Parse.
+ /// \returns 0 iff parsing succeeded.
+ virtual int parse ();
+
+ /// The current debugging stream.
+ std::ostream& debug_stream () const;
+ /// Set the current debugging stream.
+ void set_debug_stream (std::ostream &);
+
+ /// Type for debugging levels.
+ typedef int debug_level_type;
+ /// The current debugging level.
+ debug_level_type debug_level () const;
+ /// Set the current debugging level.
+ void set_debug_level (debug_level_type l);
+
+ public:
+ /// Report a syntax error.]b4_locations_if([[
+ /// \param loc where the syntax error is found.]])[
+ /// \param msg a description of the syntax error.
+ virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
+
+# if ]b4_api_PREFIX[DEBUG
+ public:
+ /// \brief Report a symbol value on the debug stream.
+ /// \param yytype The token type.
+ /// \param yyvaluep Its semantic value.]b4_locations_if([[
+ /// \param yylocationp Its location.]])[
+ virtual void yy_symbol_value_print_ (int yytype,
+ const semantic_type* yyvaluep]b4_locations_if([[,
+ const location_type* yylocationp]])[);
+ /// \brief Report a symbol on the debug stream.
+ /// \param yytype The token type.
+ /// \param yyvaluep Its semantic value.]b4_locations_if([[
+ /// \param yylocationp Its location.]])[
+ virtual void yy_symbol_print_ (int yytype,
+ const semantic_type* yyvaluep]b4_locations_if([[,
+ const location_type* yylocationp]])[);
+ private:
+ // Debugging.
+ std::ostream* yycdebug_;
+#endif
+
+]b4_parse_param_vars[
+ };
+
+]dnl Redirections for glr.c.
+b4_percent_define_flag_if([[global_tokens_and_yystype]],
+[b4_token_defines])
+[
+#ifndef ]b4_api_PREFIX[STYPE
+# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type
+#endif
+#ifndef ]b4_api_PREFIX[LTYPE
+# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class_name[::location_type
+#endif
+
+]b4_namespace_close[
+]b4_percent_code_get([[provides]])[
+]m4_popdef([b4_parse_param])dnl
+])
+
+b4_defines_if(
+[b4_output_begin([b4_spec_defines_file])
+b4_copyright([Skeleton interface for Bison GLR parsers in C++],
+ [2002-2013])[
+
+// C++ GLR parser skeleton written by Akim Demaille.
+
+]b4_cpp_guard_open([b4_spec_defines_file])[
+]b4_shared_declarations[
+]b4_cpp_guard_close([b4_spec_defines_file])[
+]b4_output_end()])
+
+# Let glr.c (and b4_shared_declarations) believe that the user
+# arguments include the parser itself.
+m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_wrap]))
+m4_include(b4_pkgdatadir/[glr.c])
+m4_popdef([b4_parse_param])
diff --git a/contrib/tools/bison/bison/data/java-skel.m4 b/contrib/tools/bison/bison/data/java-skel.m4
index 384a6370dd..1b7ac12d76 100644
--- a/contrib/tools/bison/bison/data/java-skel.m4
+++ b/contrib/tools/bison/bison/data/java-skel.m4
@@ -1,26 +1,26 @@
- -*- Autoconf -*-
-
-# Java skeleton dispatching for Bison.
-
-# Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-b4_glr_if( [b4_complain([%%glr-parser not supported for Java])])
-b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])])
-
-m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.java]])
-m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
-
-m4_include(b4_used_skeleton)
+ -*- Autoconf -*-
+
+# Java skeleton dispatching for Bison.
+
+# Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+b4_glr_if( [b4_complain([%%glr-parser not supported for Java])])
+b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])])
+
+m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.java]])
+m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"])
+
+m4_include(b4_used_skeleton)
diff --git a/contrib/tools/bison/bison/data/java.m4 b/contrib/tools/bison/bison/data/java.m4
index f985f977f1..58c545798b 100644
--- a/contrib/tools/bison/bison/data/java.m4
+++ b/contrib/tools/bison/bison/data/java.m4
@@ -1,342 +1,342 @@
- -*- Autoconf -*-
-
-# Java language support for Bison
-
-# Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-m4_include(b4_pkgdatadir/[c-like.m4])
-
-
-# b4_list2(LIST1, LIST2)
-# ----------------------
-# Join two lists with a comma if necessary.
-m4_define([b4_list2],
- [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
-
-
-# b4_percent_define_get3(DEF, PRE, POST, NOT)
-# -------------------------------------------
-# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed,
-# otherwise NOT.
-m4_define([b4_percent_define_get3],
- [m4_ifval(m4_quote(b4_percent_define_get([$1])),
- [$2[]b4_percent_define_get([$1])[]$3], [$4])])
-
-
-
-# b4_flag_value(BOOLEAN-FLAG)
-# ---------------------------
-m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
-
-
-# b4_public_if(TRUE, FALSE)
-# -------------------------
-b4_percent_define_default([[public]], [[false]])
-m4_define([b4_public_if],
-[b4_percent_define_flag_if([public], [$1], [$2])])
-
-
-# b4_abstract_if(TRUE, FALSE)
-# ---------------------------
-b4_percent_define_default([[abstract]], [[false]])
-m4_define([b4_abstract_if],
-[b4_percent_define_flag_if([abstract], [$1], [$2])])
-
-
-# b4_final_if(TRUE, FALSE)
-# ---------------------------
-b4_percent_define_default([[final]], [[false]])
-m4_define([b4_final_if],
-[b4_percent_define_flag_if([final], [$1], [$2])])
-
-
-# b4_strictfp_if(TRUE, FALSE)
-# ---------------------------
-b4_percent_define_default([[strictfp]], [[false]])
-m4_define([b4_strictfp_if],
-[b4_percent_define_flag_if([strictfp], [$1], [$2])])
-
-
-# b4_lexer_if(TRUE, FALSE)
-# ------------------------
-m4_define([b4_lexer_if],
-[b4_percent_code_ifdef([[lexer]], [$1], [$2])])
-
-
-# b4_identification
-# -----------------
-m4_define([b4_identification],
-[ /** Version number for the Bison executable that generated this parser. */
- public static final String bisonVersion = "b4_version";
-
- /** Name of the skeleton that generated this parser. */
- public static final String bisonSkeleton = b4_skeleton;
-])
-
-
-## ------------ ##
-## Data types. ##
-## ------------ ##
-
-# b4_int_type(MIN, MAX)
-# ---------------------
-# Return the smallest int type able to handle numbers ranging from
-# MIN to MAX (included).
-m4_define([b4_int_type],
-[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
- b4_ints_in($@, [-32768], [32767]), [1], [short],
- [int])])
-
-# b4_int_type_for(NAME)
-# ---------------------
-# Return the smallest int type able to handle numbers ranging from
-# 'NAME_min' to 'NAME_max' (included).
-m4_define([b4_int_type_for],
-[b4_int_type($1_min, $1_max)])
-
-# b4_null
-# -------
-m4_define([b4_null], [null])
-
-
-# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
-# -------------------------------------------------------
-m4_define([b4_typed_parser_table_define],
-[m4_ifval([$4], [b4_comment([$4])
- ])dnl
-[private static final ]$1[ yy$2_[] = yy$2_init();
- private static final ]$1[[] yy$2_init()
- {
- return new ]$1[[]
- {
- ]$3[
- };
- }]])
-
-
-# b4_integral_parser_table_define(NAME, DATA, COMMENT)
-#-----------------------------------------------------
-m4_define([b4_integral_parser_table_define],
-[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])])
-
-
-## ------------------------- ##
-## Assigning token numbers. ##
-## ------------------------- ##
-
-# b4_token_enum(TOKEN-NUM)
-# ------------------------
-# Output the definition of this token as an enum.
-m4_define([b4_token_enum],
-[b4_token_format([ /** Token number, to be returned by the scanner. */
- static final int %s = %s;
-], [$1])])
-
-# b4_token_enums
-# --------------
-# Output the definition of the tokens (if there are) as enums.
-m4_define([b4_token_enums],
-[b4_any_token_visible_if([/* Tokens. */
-b4_symbol_foreach([b4_token_enum])])])
-
-# b4-case(ID, CODE)
-# -----------------
-# We need to fool Java's stupid unreachable code detection.
-m4_define([b4_case], [ case $1:
- if (yyn == $1)
- $2;
- break;
- ])
-
-# b4_predicate_case(LABEL, CONDITIONS)
-# ------------------------------------
-m4_define([b4_predicate_case], [ case $1:
- if (! ($2)) YYERROR;
- break;
- ])
-
-
-## -------- ##
-## Checks. ##
-## -------- ##
-
-b4_percent_define_check_kind([[api.value.type]], [code], [deprecated])
-
-b4_percent_define_check_kind([[annotations]], [code], [deprecated])
-b4_percent_define_check_kind([[extends]], [code], [deprecated])
-b4_percent_define_check_kind([[implements]], [code], [deprecated])
-b4_percent_define_check_kind([[init_throws]], [code], [deprecated])
-b4_percent_define_check_kind([[lex_throws]], [code], [deprecated])
-b4_percent_define_check_kind([[parser_class_name]], [code], [deprecated])
-b4_percent_define_check_kind([[throws]], [code], [deprecated])
-
-
-
-## ---------------- ##
-## Default values. ##
-## ---------------- ##
-
-m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
-b4_percent_define_default([[api.value.type]], [[Object]])
-
-# %name-prefix
-m4_define_default([b4_prefix], [[YY]])
-
-b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])
-m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
-
-b4_percent_define_default([[lex_throws]], [[java.io.IOException]])
-m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
-
-b4_percent_define_default([[throws]], [])
-m4_define([b4_throws], [b4_percent_define_get([[throws]])])
-
-b4_percent_define_default([[init_throws]], [])
-m4_define([b4_init_throws], [b4_percent_define_get([[init_throws]])])
-
-b4_percent_define_default([[api.location.type]], [Location])
-m4_define([b4_location_type], [b4_percent_define_get([[api.location.type]])])
-
-b4_percent_define_default([[api.position.type]], [Position])
-m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])])
-
-
-## ----------------- ##
-## Semantic Values. ##
-## ----------------- ##
-
-
-# b4_lhs_value([TYPE])
-# --------------------
-# Expansion of $<TYPE>$.
-m4_define([b4_lhs_value], [yyval])
-
-
-# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
-# --------------------------------------
-# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
-# symbols on RHS.
-#
-# In this simple implementation, %token and %type have class names
-# between the angle brackets.
-m4_define([b4_rhs_value],
-[(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
-
-# b4_lhs_location()
-# -----------------
-# Expansion of @$.
-m4_define([b4_lhs_location],
-[(yyloc)])
-
-
-# b4_rhs_location(RULE-LENGTH, NUM)
-# ---------------------------------
-# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
-# on RHS.
-m4_define([b4_rhs_location],
-[yystack.locationAt ($1-($2))])
-
-
-# b4_lex_param
-# b4_parse_param
-# --------------
-# If defined, b4_lex_param arrives double quoted, but below we prefer
-# it to be single quoted. Same for b4_parse_param.
-
-# TODO: should be in bison.m4
-m4_define_default([b4_lex_param], [[]])
-m4_define([b4_lex_param], b4_lex_param)
-m4_define([b4_parse_param], b4_parse_param)
-
-# b4_lex_param_decl
-# -----------------
-# Extra formal arguments of the constructor.
-m4_define([b4_lex_param_decl],
-[m4_ifset([b4_lex_param],
- [b4_remove_comma([$1],
- b4_param_decls(b4_lex_param))],
- [$1])])
-
-m4_define([b4_param_decls],
- [m4_map([b4_param_decl], [$@])])
-m4_define([b4_param_decl], [, $1])
-
-m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
-
-
-
-# b4_parse_param_decl
-# -------------------
-# Extra formal arguments of the constructor.
-m4_define([b4_parse_param_decl],
-[m4_ifset([b4_parse_param],
- [b4_remove_comma([$1],
- b4_param_decls(b4_parse_param))],
- [$1])])
-
-
-
-# b4_lex_param_call
-# -----------------
-# Delegating the lexer parameters to the lexer constructor.
-m4_define([b4_lex_param_call],
- [m4_ifset([b4_lex_param],
- [b4_remove_comma([$1],
- b4_param_calls(b4_lex_param))],
- [$1])])
-m4_define([b4_param_calls],
- [m4_map([b4_param_call], [$@])])
-m4_define([b4_param_call], [, $2])
-
-
-
-# b4_parse_param_cons
-# -------------------
-# Extra initialisations of the constructor.
-m4_define([b4_parse_param_cons],
- [m4_ifset([b4_parse_param],
- [b4_constructor_calls(b4_parse_param)])])
-
-m4_define([b4_constructor_calls],
- [m4_map([b4_constructor_call], [$@])])
-m4_define([b4_constructor_call],
- [this.$2 = $2;
- ])
-
-
-
-# b4_parse_param_vars
-# -------------------
-# Extra instance variables.
-m4_define([b4_parse_param_vars],
- [m4_ifset([b4_parse_param],
- [
- /* User arguments. */
-b4_var_decls(b4_parse_param)])])
-
-m4_define([b4_var_decls],
- [m4_map_sep([b4_var_decl], [
-], [$@])])
-m4_define([b4_var_decl],
- [ protected final $1;])
-
-
-
-# b4_maybe_throws(THROWS)
-# -----------------------
-# Expand to either an empty string or "throws THROWS".
-m4_define([b4_maybe_throws],
- [m4_ifval($1, [throws $1])])
+ -*- Autoconf -*-
+
+# Java language support for Bison
+
+# Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include(b4_pkgdatadir/[c-like.m4])
+
+
+# b4_list2(LIST1, LIST2)
+# ----------------------
+# Join two lists with a comma if necessary.
+m4_define([b4_list2],
+ [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
+
+
+# b4_percent_define_get3(DEF, PRE, POST, NOT)
+# -------------------------------------------
+# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed,
+# otherwise NOT.
+m4_define([b4_percent_define_get3],
+ [m4_ifval(m4_quote(b4_percent_define_get([$1])),
+ [$2[]b4_percent_define_get([$1])[]$3], [$4])])
+
+
+
+# b4_flag_value(BOOLEAN-FLAG)
+# ---------------------------
+m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
+
+
+# b4_public_if(TRUE, FALSE)
+# -------------------------
+b4_percent_define_default([[public]], [[false]])
+m4_define([b4_public_if],
+[b4_percent_define_flag_if([public], [$1], [$2])])
+
+
+# b4_abstract_if(TRUE, FALSE)
+# ---------------------------
+b4_percent_define_default([[abstract]], [[false]])
+m4_define([b4_abstract_if],
+[b4_percent_define_flag_if([abstract], [$1], [$2])])
+
+
+# b4_final_if(TRUE, FALSE)
+# ---------------------------
+b4_percent_define_default([[final]], [[false]])
+m4_define([b4_final_if],
+[b4_percent_define_flag_if([final], [$1], [$2])])
+
+
+# b4_strictfp_if(TRUE, FALSE)
+# ---------------------------
+b4_percent_define_default([[strictfp]], [[false]])
+m4_define([b4_strictfp_if],
+[b4_percent_define_flag_if([strictfp], [$1], [$2])])
+
+
+# b4_lexer_if(TRUE, FALSE)
+# ------------------------
+m4_define([b4_lexer_if],
+[b4_percent_code_ifdef([[lexer]], [$1], [$2])])
+
+
+# b4_identification
+# -----------------
+m4_define([b4_identification],
+[ /** Version number for the Bison executable that generated this parser. */
+ public static final String bisonVersion = "b4_version";
+
+ /** Name of the skeleton that generated this parser. */
+ public static final String bisonSkeleton = b4_skeleton;
+])
+
+
+## ------------ ##
+## Data types. ##
+## ------------ ##
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included).
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
+ b4_ints_in($@, [-32768], [32767]), [1], [short],
+ [int])])
+
+# b4_int_type_for(NAME)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# 'NAME_min' to 'NAME_max' (included).
+m4_define([b4_int_type_for],
+[b4_int_type($1_min, $1_max)])
+
+# b4_null
+# -------
+m4_define([b4_null], [null])
+
+
+# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
+# -------------------------------------------------------
+m4_define([b4_typed_parser_table_define],
+[m4_ifval([$4], [b4_comment([$4])
+ ])dnl
+[private static final ]$1[ yy$2_[] = yy$2_init();
+ private static final ]$1[[] yy$2_init()
+ {
+ return new ]$1[[]
+ {
+ ]$3[
+ };
+ }]])
+
+
+# b4_integral_parser_table_define(NAME, DATA, COMMENT)
+#-----------------------------------------------------
+m4_define([b4_integral_parser_table_define],
+[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])])
+
+
+## ------------------------- ##
+## Assigning token numbers. ##
+## ------------------------- ##
+
+# b4_token_enum(TOKEN-NUM)
+# ------------------------
+# Output the definition of this token as an enum.
+m4_define([b4_token_enum],
+[b4_token_format([ /** Token number, to be returned by the scanner. */
+ static final int %s = %s;
+], [$1])])
+
+# b4_token_enums
+# --------------
+# Output the definition of the tokens (if there are) as enums.
+m4_define([b4_token_enums],
+[b4_any_token_visible_if([/* Tokens. */
+b4_symbol_foreach([b4_token_enum])])])
+
+# b4-case(ID, CODE)
+# -----------------
+# We need to fool Java's stupid unreachable code detection.
+m4_define([b4_case], [ case $1:
+ if (yyn == $1)
+ $2;
+ break;
+ ])
+
+# b4_predicate_case(LABEL, CONDITIONS)
+# ------------------------------------
+m4_define([b4_predicate_case], [ case $1:
+ if (! ($2)) YYERROR;
+ break;
+ ])
+
+
+## -------- ##
+## Checks. ##
+## -------- ##
+
+b4_percent_define_check_kind([[api.value.type]], [code], [deprecated])
+
+b4_percent_define_check_kind([[annotations]], [code], [deprecated])
+b4_percent_define_check_kind([[extends]], [code], [deprecated])
+b4_percent_define_check_kind([[implements]], [code], [deprecated])
+b4_percent_define_check_kind([[init_throws]], [code], [deprecated])
+b4_percent_define_check_kind([[lex_throws]], [code], [deprecated])
+b4_percent_define_check_kind([[parser_class_name]], [code], [deprecated])
+b4_percent_define_check_kind([[throws]], [code], [deprecated])
+
+
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
+b4_percent_define_default([[api.value.type]], [[Object]])
+
+# %name-prefix
+m4_define_default([b4_prefix], [[YY]])
+
+b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])
+m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
+
+b4_percent_define_default([[lex_throws]], [[java.io.IOException]])
+m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
+
+b4_percent_define_default([[throws]], [])
+m4_define([b4_throws], [b4_percent_define_get([[throws]])])
+
+b4_percent_define_default([[init_throws]], [])
+m4_define([b4_init_throws], [b4_percent_define_get([[init_throws]])])
+
+b4_percent_define_default([[api.location.type]], [Location])
+m4_define([b4_location_type], [b4_percent_define_get([[api.location.type]])])
+
+b4_percent_define_default([[api.position.type]], [Position])
+m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+# b4_lhs_value([TYPE])
+# --------------------
+# Expansion of $<TYPE>$.
+m4_define([b4_lhs_value], [yyval])
+
+
+# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
+# --------------------------------------
+# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
+# symbols on RHS.
+#
+# In this simple implementation, %token and %type have class names
+# between the angle brackets.
+m4_define([b4_rhs_value],
+[(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+[(yyloc)])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+[yystack.locationAt ($1-($2))])
+
+
+# b4_lex_param
+# b4_parse_param
+# --------------
+# If defined, b4_lex_param arrives double quoted, but below we prefer
+# it to be single quoted. Same for b4_parse_param.
+
+# TODO: should be in bison.m4
+m4_define_default([b4_lex_param], [[]])
+m4_define([b4_lex_param], b4_lex_param)
+m4_define([b4_parse_param], b4_parse_param)
+
+# b4_lex_param_decl
+# -----------------
+# Extra formal arguments of the constructor.
+m4_define([b4_lex_param_decl],
+[m4_ifset([b4_lex_param],
+ [b4_remove_comma([$1],
+ b4_param_decls(b4_lex_param))],
+ [$1])])
+
+m4_define([b4_param_decls],
+ [m4_map([b4_param_decl], [$@])])
+m4_define([b4_param_decl], [, $1])
+
+m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
+
+
+
+# b4_parse_param_decl
+# -------------------
+# Extra formal arguments of the constructor.
+m4_define([b4_parse_param_decl],
+[m4_ifset([b4_parse_param],
+ [b4_remove_comma([$1],
+ b4_param_decls(b4_parse_param))],
+ [$1])])
+
+
+
+# b4_lex_param_call
+# -----------------
+# Delegating the lexer parameters to the lexer constructor.
+m4_define([b4_lex_param_call],
+ [m4_ifset([b4_lex_param],
+ [b4_remove_comma([$1],
+ b4_param_calls(b4_lex_param))],
+ [$1])])
+m4_define([b4_param_calls],
+ [m4_map([b4_param_call], [$@])])
+m4_define([b4_param_call], [, $2])
+
+
+
+# b4_parse_param_cons
+# -------------------
+# Extra initialisations of the constructor.
+m4_define([b4_parse_param_cons],
+ [m4_ifset([b4_parse_param],
+ [b4_constructor_calls(b4_parse_param)])])
+
+m4_define([b4_constructor_calls],
+ [m4_map([b4_constructor_call], [$@])])
+m4_define([b4_constructor_call],
+ [this.$2 = $2;
+ ])
+
+
+
+# b4_parse_param_vars
+# -------------------
+# Extra instance variables.
+m4_define([b4_parse_param_vars],
+ [m4_ifset([b4_parse_param],
+ [
+ /* User arguments. */
+b4_var_decls(b4_parse_param)])])
+
+m4_define([b4_var_decls],
+ [m4_map_sep([b4_var_decl], [
+], [$@])])
+m4_define([b4_var_decl],
+ [ protected final $1;])
+
+
+
+# b4_maybe_throws(THROWS)
+# -----------------------
+# Expand to either an empty string or "throws THROWS".
+m4_define([b4_maybe_throws],
+ [m4_ifval($1, [throws $1])])
diff --git a/contrib/tools/bison/bison/data/lalr1.cc b/contrib/tools/bison/bison/data/lalr1.cc
index f4f51c78c7..c88eebea23 100644
--- a/contrib/tools/bison/bison/data/lalr1.cc
+++ b/contrib/tools/bison/bison/data/lalr1.cc
@@ -1,571 +1,571 @@
-# C++ skeleton for Bison
-
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-m4_include(b4_pkgdatadir/[c++.m4])
-
-# api.value.type=variant is valid.
-m4_define([b4_value_type_setup_variant])
-
-# b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
-# --------------------------------------------------------------
-# Declare "parser::yy<TABLE-NAME>_" whose contents is CONTENT.
-m4_define([b4_integral_parser_table_declare],
-[m4_ifval([$3], [b4_comment([$3], [ ])
-])dnl
- static const b4_int_type_for([$2]) yy$1_[[]];dnl
-])
-
-# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
-# -------------------------------------------------------------
-# Define "parser::yy<TABLE-NAME>_" whose contents is CONTENT.
-m4_define([b4_integral_parser_table_define],
-[ const b4_int_type_for([$2])
- b4_parser_class_name::yy$1_[[]] =
- {
- $2
- };dnl
-])
-
-# b4_symbol_value_template(VAL, [TYPE])
-# -------------------------------------
-# Same as b4_symbol_value, but used in a template method. It makes
-# a difference when using variants. Note that b4_value_type_setup_union
-# overrides b4_symbol_value, so we must override it again.
-m4_copy([b4_symbol_value], [b4_symbol_value_template])
-m4_append([b4_value_type_setup_union],
- [m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])])
-
-# b4_lhs_value([TYPE])
-# --------------------
-# Expansion of $<TYPE>$.
-m4_define([b4_lhs_value],
- [b4_symbol_value([yylhs.value], [$1])])
-
-
-# b4_lhs_location()
-# -----------------
-# Expansion of @$.
-m4_define([b4_lhs_location],
- [yylhs.location])
-
-
-# b4_rhs_data(RULE-LENGTH, NUM)
-# -----------------------------
-# Return the data corresponding to the symbol #NUM, where the current
-# rule has RULE-LENGTH symbols on RHS.
-m4_define([b4_rhs_data],
- [yystack_@{b4_subtract($@)@}])
-
-
-# b4_rhs_state(RULE-LENGTH, NUM)
-# ------------------------------
-# The state corresponding to the symbol #NUM, where the current
-# rule has RULE-LENGTH symbols on RHS.
-m4_define([b4_rhs_state],
- [b4_rhs_data([$1], [$2]).state])
-
-
-# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
-# --------------------------------------
-# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
-# symbols on RHS.
-m4_define([b4_rhs_value],
- [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
-
-
-# b4_rhs_location(RULE-LENGTH, NUM)
-# ---------------------------------
-# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
-# on RHS.
-m4_define([b4_rhs_location],
- [b4_rhs_data([$1], [$2]).location])
-
-
-# b4_symbol_action(SYMBOL-NUM, KIND)
-# ----------------------------------
-# Run the action KIND (destructor or printer) for SYMBOL-NUM.
-# Same as in C, but using references instead of pointers.
-m4_define([b4_symbol_action],
-[b4_symbol_if([$1], [has_$2],
-[m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
-b4_dollar_pushdef([yysym.value],
- b4_symbol_if([$1], [has_type],
- [m4_dquote(b4_symbol([$1], [type]))]),
- [yysym.location])dnl
- b4_symbol_case_([$1])
-b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
- b4_symbol([$1], [$2])
-b4_syncline([@oline@], [@ofile@])
- break;
-
-m4_popdef([b4_symbol_value])[]dnl
-b4_dollar_popdef[]dnl
-])])
-
-
-# b4_lex
-# ------
-# Call yylex.
-m4_define([b4_lex],
-[b4_token_ctor_if(
-[b4_function_call([yylex],
- [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
-[b4_function_call([yylex], [int],
- [b4_api_PREFIX[STYPE*], [&yyla.value]][]dnl
-b4_locations_if([, [[location*], [&yyla.location]]])dnl
-m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
-
-
-m4_pushdef([b4_copyright_years],
- [2002-2013])
-
-m4_define([b4_parser_class_name],
- [b4_percent_define_get([[parser_class_name]])])
-
-b4_bison_locations_if([# Backward compatibility.
- m4_define([b4_location_constructors])
- m4_include(b4_pkgdatadir/[location.cc])])
-m4_include(b4_pkgdatadir/[stack.hh])
-b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
-
-# b4_shared_declarations
-# ----------------------
-# Declaration that might either go into the header (if --defines)
-# or open coded in the parser body.
-m4_define([b4_shared_declarations],
-[b4_percent_code_get([[requires]])[
-]b4_parse_assert_if([# include <cassert>])[
-# include <vector>
-# include <iostream>
-# include <stdexcept>
-# include <string>]b4_defines_if([[
-# include "stack.hh"
-]b4_bison_locations_if([[# include "location.hh"]])])[
-]b4_variant_if([b4_variant_includes])[
-
-]b4_YYDEBUG_define[
-
-]b4_namespace_open[
-
-]b4_defines_if([],
-[b4_stack_define
-b4_bison_locations_if([b4_position_define
-b4_location_define])])[
-
-]b4_variant_if([b4_variant_define])[
-
- /// A Bison parser.
- class ]b4_parser_class_name[
- {
- public:
-]b4_public_types_declare[
- /// Build a parser object.
- ]b4_parser_class_name[ (]b4_parse_param_decl[);
- virtual ~]b4_parser_class_name[ ();
-
- /// Parse.
- /// \returns 0 iff parsing succeeded.
- virtual int parse ();
-
-#if ]b4_api_PREFIX[DEBUG
- /// The current debugging stream.
- std::ostream& debug_stream () const;
- /// Set the current debugging stream.
- void set_debug_stream (std::ostream &);
-
- /// Type for debugging levels.
- typedef int debug_level_type;
- /// The current debugging level.
- debug_level_type debug_level () const;
- /// Set the current debugging level.
- void set_debug_level (debug_level_type l);
-#endif
-
- /// Report a syntax error.]b4_locations_if([[
- /// \param loc where the syntax error is found.]])[
- /// \param msg a description of the syntax error.
- virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
-
- /// Report a syntax error.
- void error (const syntax_error& err);
-
- private:
- /// This class is not copyable.
- ]b4_parser_class_name[ (const ]b4_parser_class_name[&);
- ]b4_parser_class_name[& operator= (const ]b4_parser_class_name[&);
-
- /// State numbers.
- typedef int state_type;
-
- /// Generate an error message.
- /// \param yystate the state where the error occurred.
- /// \param yytoken the lookahead token type, or yyempty_.
- virtual std::string yysyntax_error_ (state_type yystate,
- symbol_number_type yytoken) const;
-
- /// Compute post-reduction state.
- /// \param yystate the current state
- /// \param yylhs the nonterminal to push on the stack
- state_type yy_lr_goto_state_ (state_type yystate, int yylhs);
-
- /// Whether the given \c yypact_ value indicates a defaulted state.
- /// \param yyvalue the value to check
- static bool yy_pact_value_is_default_ (int yyvalue);
-
- /// Whether the given \c yytable_ value indicates a syntax error.
- /// \param yyvalue the value to check
- static bool yy_table_value_is_error_ (int yyvalue);
-
- static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
- static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
-
- /// Convert a scanner token number \a t to a symbol number.
- static token_number_type yytranslate_ (]b4_token_ctor_if([token_type], [int])[ t);
-
- // Tables.
-]b4_parser_tables_declare[]b4_error_verbose_if([
-
- /// Convert the symbol name \a n to a form suitable for a diagnostic.
- static std::string yytnamerr_ (const char *n);])[
-
-]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
- /// For a symbol, its name in clear.
- static const char* const yytname_[];
-]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
-]b4_integral_parser_table_declare([rline], [b4_rline],
- [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
- /// Report on the debug stream that the rule \a r is going to be reduced.
- virtual void yy_reduce_print_ (int r);
- /// Print the state stack on the debug stream.
- virtual void yystack_print_ ();
-
- // Debugging.
- int yydebug_;
- std::ostream* yycdebug_;
-
- /// \brief Display a symbol type, value and location.
- /// \param yyo The output stream.
- /// \param yysym The symbol.
- template <typename Base>
- void yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const;
-#endif
-
- /// \brief Reclaim the memory associated to a symbol.
- /// \param yymsg Why this token is reclaimed.
- /// If null, print nothing.
- /// \param s The symbol.
- template <typename Base>
- void yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const;
-
- private:
- /// Type access provider for state based symbols.
- struct by_state
- {
- /// Default constructor.
- by_state ();
-
- /// The symbol type as needed by the constructor.
- typedef state_type kind_type;
-
- /// Constructor.
- by_state (kind_type s);
-
- /// Copy constructor.
- by_state (const by_state& other);
-
- /// Steal the symbol type from \a that.
- void move (by_state& that);
-
- /// The (internal) type number (corresponding to \a state).
- /// "empty" when empty.
- symbol_number_type type_get () const;
-
- enum { empty = 0 };
-
- /// The state.
- state_type state;
- };
-
- /// "Internal" symbol: element of the stack.
- struct stack_symbol_type : basic_symbol<by_state>
- {
- /// Superclass.
- typedef basic_symbol<by_state> super_type;
- /// Construct an empty symbol.
- stack_symbol_type ();
+# C++ skeleton for Bison
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include(b4_pkgdatadir/[c++.m4])
+
+# api.value.type=variant is valid.
+m4_define([b4_value_type_setup_variant])
+
+# b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
+# --------------------------------------------------------------
+# Declare "parser::yy<TABLE-NAME>_" whose contents is CONTENT.
+m4_define([b4_integral_parser_table_declare],
+[m4_ifval([$3], [b4_comment([$3], [ ])
+])dnl
+ static const b4_int_type_for([$2]) yy$1_[[]];dnl
+])
+
+# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
+# -------------------------------------------------------------
+# Define "parser::yy<TABLE-NAME>_" whose contents is CONTENT.
+m4_define([b4_integral_parser_table_define],
+[ const b4_int_type_for([$2])
+ b4_parser_class_name::yy$1_[[]] =
+ {
+ $2
+ };dnl
+])
+
+# b4_symbol_value_template(VAL, [TYPE])
+# -------------------------------------
+# Same as b4_symbol_value, but used in a template method. It makes
+# a difference when using variants. Note that b4_value_type_setup_union
+# overrides b4_symbol_value, so we must override it again.
+m4_copy([b4_symbol_value], [b4_symbol_value_template])
+m4_append([b4_value_type_setup_union],
+ [m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])])
+
+# b4_lhs_value([TYPE])
+# --------------------
+# Expansion of $<TYPE>$.
+m4_define([b4_lhs_value],
+ [b4_symbol_value([yylhs.value], [$1])])
+
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+ [yylhs.location])
+
+
+# b4_rhs_data(RULE-LENGTH, NUM)
+# -----------------------------
+# Return the data corresponding to the symbol #NUM, where the current
+# rule has RULE-LENGTH symbols on RHS.
+m4_define([b4_rhs_data],
+ [yystack_@{b4_subtract($@)@}])
+
+
+# b4_rhs_state(RULE-LENGTH, NUM)
+# ------------------------------
+# The state corresponding to the symbol #NUM, where the current
+# rule has RULE-LENGTH symbols on RHS.
+m4_define([b4_rhs_state],
+ [b4_rhs_data([$1], [$2]).state])
+
+
+# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
+# --------------------------------------
+# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
+# symbols on RHS.
+m4_define([b4_rhs_value],
+ [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+ [b4_rhs_data([$1], [$2]).location])
+
+
+# b4_symbol_action(SYMBOL-NUM, KIND)
+# ----------------------------------
+# Run the action KIND (destructor or printer) for SYMBOL-NUM.
+# Same as in C, but using references instead of pointers.
+m4_define([b4_symbol_action],
+[b4_symbol_if([$1], [has_$2],
+[m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl
+b4_dollar_pushdef([yysym.value],
+ b4_symbol_if([$1], [has_type],
+ [m4_dquote(b4_symbol([$1], [type]))]),
+ [yysym.location])dnl
+ b4_symbol_case_([$1])
+b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
+ b4_symbol([$1], [$2])
+b4_syncline([@oline@], [@ofile@])
+ break;
+
+m4_popdef([b4_symbol_value])[]dnl
+b4_dollar_popdef[]dnl
+])])
+
+
+# b4_lex
+# ------
+# Call yylex.
+m4_define([b4_lex],
+[b4_token_ctor_if(
+[b4_function_call([yylex],
+ [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))],
+[b4_function_call([yylex], [int],
+ [b4_api_PREFIX[STYPE*], [&yyla.value]][]dnl
+b4_locations_if([, [[location*], [&yyla.location]]])dnl
+m4_ifdef([b4_lex_param], [, ]b4_lex_param))])])
+
+
+m4_pushdef([b4_copyright_years],
+ [2002-2013])
+
+m4_define([b4_parser_class_name],
+ [b4_percent_define_get([[parser_class_name]])])
+
+b4_bison_locations_if([# Backward compatibility.
+ m4_define([b4_location_constructors])
+ m4_include(b4_pkgdatadir/[location.cc])])
+m4_include(b4_pkgdatadir/[stack.hh])
+b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
+
+# b4_shared_declarations
+# ----------------------
+# Declaration that might either go into the header (if --defines)
+# or open coded in the parser body.
+m4_define([b4_shared_declarations],
+[b4_percent_code_get([[requires]])[
+]b4_parse_assert_if([# include <cassert>])[
+# include <vector>
+# include <iostream>
+# include <stdexcept>
+# include <string>]b4_defines_if([[
+# include "stack.hh"
+]b4_bison_locations_if([[# include "location.hh"]])])[
+]b4_variant_if([b4_variant_includes])[
+
+]b4_YYDEBUG_define[
+
+]b4_namespace_open[
+
+]b4_defines_if([],
+[b4_stack_define
+b4_bison_locations_if([b4_position_define
+b4_location_define])])[
+
+]b4_variant_if([b4_variant_define])[
+
+ /// A Bison parser.
+ class ]b4_parser_class_name[
+ {
+ public:
+]b4_public_types_declare[
+ /// Build a parser object.
+ ]b4_parser_class_name[ (]b4_parse_param_decl[);
+ virtual ~]b4_parser_class_name[ ();
+
+ /// Parse.
+ /// \returns 0 iff parsing succeeded.
+ virtual int parse ();
+
+#if ]b4_api_PREFIX[DEBUG
+ /// The current debugging stream.
+ std::ostream& debug_stream () const;
+ /// Set the current debugging stream.
+ void set_debug_stream (std::ostream &);
+
+ /// Type for debugging levels.
+ typedef int debug_level_type;
+ /// The current debugging level.
+ debug_level_type debug_level () const;
+ /// Set the current debugging level.
+ void set_debug_level (debug_level_type l);
+#endif
+
+ /// Report a syntax error.]b4_locations_if([[
+ /// \param loc where the syntax error is found.]])[
+ /// \param msg a description of the syntax error.
+ virtual void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg);
+
+ /// Report a syntax error.
+ void error (const syntax_error& err);
+
+ private:
+ /// This class is not copyable.
+ ]b4_parser_class_name[ (const ]b4_parser_class_name[&);
+ ]b4_parser_class_name[& operator= (const ]b4_parser_class_name[&);
+
+ /// State numbers.
+ typedef int state_type;
+
+ /// Generate an error message.
+ /// \param yystate the state where the error occurred.
+ /// \param yytoken the lookahead token type, or yyempty_.
+ virtual std::string yysyntax_error_ (state_type yystate,
+ symbol_number_type yytoken) const;
+
+ /// Compute post-reduction state.
+ /// \param yystate the current state
+ /// \param yylhs the nonterminal to push on the stack
+ state_type yy_lr_goto_state_ (state_type yystate, int yylhs);
+
+ /// Whether the given \c yypact_ value indicates a defaulted state.
+ /// \param yyvalue the value to check
+ static bool yy_pact_value_is_default_ (int yyvalue);
+
+ /// Whether the given \c yytable_ value indicates a syntax error.
+ /// \param yyvalue the value to check
+ static bool yy_table_value_is_error_ (int yyvalue);
+
+ static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
+ static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
+
+ /// Convert a scanner token number \a t to a symbol number.
+ static token_number_type yytranslate_ (]b4_token_ctor_if([token_type], [int])[ t);
+
+ // Tables.
+]b4_parser_tables_declare[]b4_error_verbose_if([
+
+ /// Convert the symbol name \a n to a form suitable for a diagnostic.
+ static std::string yytnamerr_ (const char *n);])[
+
+]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
+ /// For a symbol, its name in clear.
+ static const char* const yytname_[];
+]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
+]b4_integral_parser_table_declare([rline], [b4_rline],
+ [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
+ /// Report on the debug stream that the rule \a r is going to be reduced.
+ virtual void yy_reduce_print_ (int r);
+ /// Print the state stack on the debug stream.
+ virtual void yystack_print_ ();
+
+ // Debugging.
+ int yydebug_;
+ std::ostream* yycdebug_;
+
+ /// \brief Display a symbol type, value and location.
+ /// \param yyo The output stream.
+ /// \param yysym The symbol.
+ template <typename Base>
+ void yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const;
+#endif
+
+ /// \brief Reclaim the memory associated to a symbol.
+ /// \param yymsg Why this token is reclaimed.
+ /// If null, print nothing.
+ /// \param s The symbol.
+ template <typename Base>
+ void yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const;
+
+ private:
+ /// Type access provider for state based symbols.
+ struct by_state
+ {
+ /// Default constructor.
+ by_state ();
+
+ /// The symbol type as needed by the constructor.
+ typedef state_type kind_type;
+
+ /// Constructor.
+ by_state (kind_type s);
+
+ /// Copy constructor.
+ by_state (const by_state& other);
+
+ /// Steal the symbol type from \a that.
+ void move (by_state& that);
+
+ /// The (internal) type number (corresponding to \a state).
+ /// "empty" when empty.
+ symbol_number_type type_get () const;
+
+ enum { empty = 0 };
+
+ /// The state.
+ state_type state;
+ };
+
+ /// "Internal" symbol: element of the stack.
+ struct stack_symbol_type : basic_symbol<by_state>
+ {
+ /// Superclass.
+ typedef basic_symbol<by_state> super_type;
+ /// Construct an empty symbol.
+ stack_symbol_type ();
/// Copy construct.
stack_symbol_type (const stack_symbol_type& that);
- /// Steal the contents from \a sym to build this.
- stack_symbol_type (state_type s, symbol_type& sym);
- /// Assignment, needed by push_back.
- stack_symbol_type& operator= (const stack_symbol_type& that);
- };
-
- /// Stack type.
- typedef stack<stack_symbol_type> stack_type;
-
- /// The stack.
- stack_type yystack_;
-
- /// Push a new state on the stack.
- /// \param m a debug message to display
- /// if null, no trace is output.
- /// \param s the symbol
- /// \warning the contents of \a s.value is stolen.
- void yypush_ (const char* m, stack_symbol_type& s);
-
- /// Push a new look ahead token on the state on the stack.
- /// \param m a debug message to display
- /// if null, no trace is output.
- /// \param s the state
- /// \param sym the symbol (for its value and location).
- /// \warning the contents of \a s.value is stolen.
- void yypush_ (const char* m, state_type s, symbol_type& sym);
-
- /// Pop \a n symbols the three stacks.
- void yypop_ (unsigned int n = 1);
-
- // Constants.
- enum
- {
- yyeof_ = 0,
- yylast_ = ]b4_last[, //< Last index in yytable_.
- yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
- yyempty_ = -2,
- yyfinal_ = ]b4_final_state_number[, //< Termination state number.
- yyterror_ = 1,
- yyerrcode_ = 256,
- yyntokens_ = ]b4_tokens_number[ //< Number of tokens.
- };
-
-]b4_parse_param_vars[
- };
-
-]b4_token_ctor_if([b4_yytranslate_define
-b4_public_types_define])[
-]b4_namespace_close[
-
-]b4_percent_define_flag_if([[global_tokens_and_yystype]],
-[b4_token_defines
-
-#ifndef ]b4_api_PREFIX[STYPE
- // Redirection for backward compatibility.
-# define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class_name::semantic_type
-#endif
-])[
-]b4_percent_code_get([[provides]])[
-]])
-
-b4_defines_if(
-[b4_output_begin([b4_spec_defines_file])
-b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
-[
-/**
- ** \file ]b4_spec_defines_file[
- ** Define the ]b4_namespace_ref[::parser class.
- */
-
-// C++ LALR(1) parser skeleton written by Akim Demaille.
-
-]b4_cpp_guard_open([b4_spec_defines_file])[
-]b4_shared_declarations[
-]b4_cpp_guard_close([b4_spec_defines_file])
-b4_output_end()
-])
-
-
-b4_output_begin([b4_parser_file_name])
-b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
-b4_percent_code_get([[top]])[]dnl
-m4_if(b4_prefix, [yy], [],
-[
-// Take the name prefix into account.
-#define yylex b4_prefix[]lex])[
-
-// First part of user declarations.
-]b4_user_pre_prologue[
-
-]b4_null_define[
-
-]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
- [b4_shared_declarations])[
-
-// User implementation prologue.
-]b4_user_post_prologue[
-]b4_percent_code_get[
-
-#ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
-# if ENABLE_NLS
-# include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE.
-# define YY_(msgid) dgettext ("bison-runtime", msgid)
-# endif
-# endif
-# ifndef YY_
-# define YY_(msgid) msgid
-# endif
-#endif
-
-]b4_locations_if([dnl
-[#define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
-]b4_yylloc_default_define])[
-
-// Suppress unused-variable warnings by "using" E.
-#define YYUSE(E) ((void) (E))
-
-// Enable debugging if requested.
-#if ]b4_api_PREFIX[DEBUG
-
-// A pseudo ostream that takes yydebug_ into account.
-# define YYCDEBUG if (yydebug_) (*yycdebug_)
-
-# define YY_SYMBOL_PRINT(Title, Symbol) \
- do { \
- if (yydebug_) \
- { \
- *yycdebug_ << Title << ' '; \
- yy_print_ (*yycdebug_, Symbol); \
- *yycdebug_ << std::endl; \
- } \
- } while (false)
-
-# define YY_REDUCE_PRINT(Rule) \
- do { \
- if (yydebug_) \
- yy_reduce_print_ (Rule); \
- } while (false)
-
-# define YY_STACK_PRINT() \
- do { \
- if (yydebug_) \
- yystack_print_ (); \
- } while (false)
-
-#else // !]b4_api_PREFIX[DEBUG
-
-# define YYCDEBUG if (false) std::cerr
-# define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol)
-# define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
-# define YY_STACK_PRINT() static_cast<void>(0)
-
-#endif // !]b4_api_PREFIX[DEBUG
-
-#define yyerrok (yyerrstatus_ = 0)
-#define yyclearin (yyempty = true)
-
-#define YYACCEPT goto yyacceptlab
-#define YYABORT goto yyabortlab
-#define YYERROR goto yyerrorlab
-#define YYRECOVERING() (!!yyerrstatus_)
-
-]b4_namespace_open[]b4_error_verbose_if([[
-
- /* Return YYSTR after stripping away unnecessary quotes and
- backslashes, so that it's suitable for yyerror. The heuristic is
- that double-quoting is unnecessary unless the string contains an
- apostrophe, a comma, or backslash (other than backslash-backslash).
- YYSTR is taken from yytname. */
- std::string
- ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
- {
- if (*yystr == '"')
- {
- std::string yyr = "";
- char const *yyp = yystr;
-
- for (;;)
- switch (*++yyp)
- {
- case '\'':
- case ',':
- goto do_not_strip_quotes;
-
- case '\\':
- if (*++yyp != '\\')
- goto do_not_strip_quotes;
- // Fall through.
- default:
- yyr += *yyp;
- break;
-
- case '"':
- return yyr;
- }
- do_not_strip_quotes: ;
- }
-
- return yystr;
- }
-]])[
-
- /// Build a parser object.
- ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
- :])[
-#if ]b4_api_PREFIX[DEBUG
- ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
- yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
-#endif]b4_parse_param_cons[
- {}
-
- ]b4_parser_class_name::~b4_parser_class_name[ ()
- {}
-
-
- /*---------------.
- | Symbol types. |
- `---------------*/
-
-]b4_token_ctor_if([], [b4_public_types_define])[
-
- // by_state.
- inline
- ]b4_parser_class_name[::by_state::by_state ()
- : state (empty)
- {}
-
- inline
- ]b4_parser_class_name[::by_state::by_state (const by_state& other)
- : state (other.state)
- {}
-
- inline
- void
- ]b4_parser_class_name[::by_state::move (by_state& that)
- {
- state = that.state;
- that.state = empty;
- }
-
- inline
- ]b4_parser_class_name[::by_state::by_state (state_type s)
- : state (s)
- {}
-
- inline
- ]b4_parser_class_name[::symbol_number_type
- ]b4_parser_class_name[::by_state::type_get () const
- {
- return state == empty ? 0 : yystos_[state];
- }
-
- inline
- ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
- {}
-
+ /// Steal the contents from \a sym to build this.
+ stack_symbol_type (state_type s, symbol_type& sym);
+ /// Assignment, needed by push_back.
+ stack_symbol_type& operator= (const stack_symbol_type& that);
+ };
+
+ /// Stack type.
+ typedef stack<stack_symbol_type> stack_type;
+
+ /// The stack.
+ stack_type yystack_;
+
+ /// Push a new state on the stack.
+ /// \param m a debug message to display
+ /// if null, no trace is output.
+ /// \param s the symbol
+ /// \warning the contents of \a s.value is stolen.
+ void yypush_ (const char* m, stack_symbol_type& s);
+
+ /// Push a new look ahead token on the state on the stack.
+ /// \param m a debug message to display
+ /// if null, no trace is output.
+ /// \param s the state
+ /// \param sym the symbol (for its value and location).
+ /// \warning the contents of \a s.value is stolen.
+ void yypush_ (const char* m, state_type s, symbol_type& sym);
+
+ /// Pop \a n symbols the three stacks.
+ void yypop_ (unsigned int n = 1);
+
+ // Constants.
+ enum
+ {
+ yyeof_ = 0,
+ yylast_ = ]b4_last[, //< Last index in yytable_.
+ yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
+ yyempty_ = -2,
+ yyfinal_ = ]b4_final_state_number[, //< Termination state number.
+ yyterror_ = 1,
+ yyerrcode_ = 256,
+ yyntokens_ = ]b4_tokens_number[ //< Number of tokens.
+ };
+
+]b4_parse_param_vars[
+ };
+
+]b4_token_ctor_if([b4_yytranslate_define
+b4_public_types_define])[
+]b4_namespace_close[
+
+]b4_percent_define_flag_if([[global_tokens_and_yystype]],
+[b4_token_defines
+
+#ifndef ]b4_api_PREFIX[STYPE
+ // Redirection for backward compatibility.
+# define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class_name::semantic_type
+#endif
+])[
+]b4_percent_code_get([[provides]])[
+]])
+
+b4_defines_if(
+[b4_output_begin([b4_spec_defines_file])
+b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
+[
+/**
+ ** \file ]b4_spec_defines_file[
+ ** Define the ]b4_namespace_ref[::parser class.
+ */
+
+// C++ LALR(1) parser skeleton written by Akim Demaille.
+
+]b4_cpp_guard_open([b4_spec_defines_file])[
+]b4_shared_declarations[
+]b4_cpp_guard_close([b4_spec_defines_file])
+b4_output_end()
+])
+
+
+b4_output_begin([b4_parser_file_name])
+b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
+b4_percent_code_get([[top]])[]dnl
+m4_if(b4_prefix, [yy], [],
+[
+// Take the name prefix into account.
+#define yylex b4_prefix[]lex])[
+
+// First part of user declarations.
+]b4_user_pre_prologue[
+
+]b4_null_define[
+
+]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
+ [b4_shared_declarations])[
+
+// User implementation prologue.
+]b4_user_post_prologue[
+]b4_percent_code_get[
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE.
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+]b4_locations_if([dnl
+[#define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
+]b4_yylloc_default_define])[
+
+// Suppress unused-variable warnings by "using" E.
+#define YYUSE(E) ((void) (E))
+
+// Enable debugging if requested.
+#if ]b4_api_PREFIX[DEBUG
+
+// A pseudo ostream that takes yydebug_ into account.
+# define YYCDEBUG if (yydebug_) (*yycdebug_)
+
+# define YY_SYMBOL_PRINT(Title, Symbol) \
+ do { \
+ if (yydebug_) \
+ { \
+ *yycdebug_ << Title << ' '; \
+ yy_print_ (*yycdebug_, Symbol); \
+ *yycdebug_ << std::endl; \
+ } \
+ } while (false)
+
+# define YY_REDUCE_PRINT(Rule) \
+ do { \
+ if (yydebug_) \
+ yy_reduce_print_ (Rule); \
+ } while (false)
+
+# define YY_STACK_PRINT() \
+ do { \
+ if (yydebug_) \
+ yystack_print_ (); \
+ } while (false)
+
+#else // !]b4_api_PREFIX[DEBUG
+
+# define YYCDEBUG if (false) std::cerr
+# define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol)
+# define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
+# define YY_STACK_PRINT() static_cast<void>(0)
+
+#endif // !]b4_api_PREFIX[DEBUG
+
+#define yyerrok (yyerrstatus_ = 0)
+#define yyclearin (yyempty = true)
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+#define YYRECOVERING() (!!yyerrstatus_)
+
+]b4_namespace_open[]b4_error_verbose_if([[
+
+ /* Return YYSTR after stripping away unnecessary quotes and
+ backslashes, so that it's suitable for yyerror. The heuristic is
+ that double-quoting is unnecessary unless the string contains an
+ apostrophe, a comma, or backslash (other than backslash-backslash).
+ YYSTR is taken from yytname. */
+ std::string
+ ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
+ {
+ if (*yystr == '"')
+ {
+ std::string yyr = "";
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ // Fall through.
+ default:
+ yyr += *yyp;
+ break;
+
+ case '"':
+ return yyr;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ return yystr;
+ }
+]])[
+
+ /// Build a parser object.
+ ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
+ :])[
+#if ]b4_api_PREFIX[DEBUG
+ ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
+ yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
+#endif]b4_parse_param_cons[
+ {}
+
+ ]b4_parser_class_name::~b4_parser_class_name[ ()
+ {}
+
+
+ /*---------------.
+ | Symbol types. |
+ `---------------*/
+
+]b4_token_ctor_if([], [b4_public_types_define])[
+
+ // by_state.
+ inline
+ ]b4_parser_class_name[::by_state::by_state ()
+ : state (empty)
+ {}
+
+ inline
+ ]b4_parser_class_name[::by_state::by_state (const by_state& other)
+ : state (other.state)
+ {}
+
+ inline
+ void
+ ]b4_parser_class_name[::by_state::move (by_state& that)
+ {
+ state = that.state;
+ that.state = empty;
+ }
+
+ inline
+ ]b4_parser_class_name[::by_state::by_state (state_type s)
+ : state (s)
+ {}
+
+ inline
+ ]b4_parser_class_name[::symbol_number_type
+ ]b4_parser_class_name[::by_state::type_get () const
+ {
+ return state == empty ? 0 : yystos_[state];
+ }
+
+ inline
+ ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
+ {}
+
]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (const stack_symbol_type& that)
: super_type (that.state]b4_locations_if([, that.location])[)
{
@@ -573,598 +573,598 @@ m4_if(b4_prefix, [yy], [],
[value], [copy], [that.value])],
[[value = that.value;]])[
}
-
- inline
- ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that)
- : super_type (s]b4_locations_if([, that.location])[)
- {
- ]b4_variant_if([b4_symbol_variant([that.type_get ()],
- [value], [move], [that.value])],
- [[value = that.value;]])[
- // that is emptied.
- that.type = empty;
- }
-
- inline
- ]b4_parser_class_name[::stack_symbol_type&
- ]b4_parser_class_name[::stack_symbol_type::operator= (const stack_symbol_type& that)
- {
- state = that.state;
- ]b4_variant_if([b4_symbol_variant([that.type_get ()],
- [value], [copy], [that.value])],
- [[value = that.value;]])[]b4_locations_if([
- location = that.location;])[
- return *this;
- }
-
-
- template <typename Base>
- inline
- void
- ]b4_parser_class_name[::yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const
- {
- if (yymsg)
- YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [
-
- // User destructor.
- b4_symbol_actions([destructor], [yysym.type_get ()])])[
- }
-
-#if ]b4_api_PREFIX[DEBUG
- template <typename Base>
- void
- ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
- const basic_symbol<Base>& yysym) const
- {
- std::ostream& yyoutput = yyo;
- YYUSE (yyoutput);
- symbol_number_type yytype = yysym.type_get ();
- yyo << (yytype < yyntokens_ ? "token" : "nterm")
- << ' ' << yytname_[yytype] << " ("]b4_locations_if([
- << yysym.location << ": "])[;
- ]b4_symbol_actions([printer])[
- yyo << ')';
- }
-#endif
-
- inline
- void
- ]b4_parser_class_name[::yypush_ (const char* m, state_type s, symbol_type& sym)
- {
- stack_symbol_type t (s, sym);
- yypush_ (m, t);
- }
-
- inline
- void
- ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
- {
- if (m)
- YY_SYMBOL_PRINT (m, s);
- yystack_.push (s);
- }
-
- inline
- void
- ]b4_parser_class_name[::yypop_ (unsigned int n)
- {
- yystack_.pop (n);
- }
-
-#if ]b4_api_PREFIX[DEBUG
- std::ostream&
- ]b4_parser_class_name[::debug_stream () const
- {
- return *yycdebug_;
- }
-
- void
- ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
- {
- yycdebug_ = &o;
- }
-
-
- ]b4_parser_class_name[::debug_level_type
- ]b4_parser_class_name[::debug_level () const
- {
- return yydebug_;
- }
-
- void
- ]b4_parser_class_name[::set_debug_level (debug_level_type l)
- {
- yydebug_ = l;
- }
-#endif // ]b4_api_PREFIX[DEBUG
-
- inline ]b4_parser_class_name[::state_type
- ]b4_parser_class_name[::yy_lr_goto_state_ (state_type yystate, int yylhs)
- {
- int yyr = yypgoto_[yylhs - yyntokens_] + yystate;
- if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
- return yytable_[yyr];
- else
- return yydefgoto_[yylhs - yyntokens_];
- }
-
- inline bool
- ]b4_parser_class_name[::yy_pact_value_is_default_ (int yyvalue)
- {
- return yyvalue == yypact_ninf_;
- }
-
- inline bool
- ]b4_parser_class_name[::yy_table_value_is_error_ (int yyvalue)
- {
- return yyvalue == yytable_ninf_;
- }
-
- int
- ]b4_parser_class_name[::parse ()
- {
- /// Whether yyla contains a lookahead.
- bool yyempty = true;
-
- // State.
- int yyn;
- int yylen = 0;
-
- // Error handling.
- int yynerrs_ = 0;
- int yyerrstatus_ = 0;
-
- /// The lookahead symbol.
- symbol_type yyla;]b4_locations_if([[
-
- /// The locations where the error started and ended.
- stack_symbol_type yyerror_range[3];]])[
-
- /// $$ and @@$.
- stack_symbol_type yylhs;
-
- /// The return value of parse ().
- int yyresult;
-
- // FIXME: This shoud be completely indented. It is not yet to
- // avoid gratuitous conflicts when merging into the master branch.
- try
- {
- YYCDEBUG << "Starting parse" << std::endl;
-
-]m4_ifdef([b4_initial_action], [
-b4_dollar_pushdef([yyla.value], [], [yyla.location])dnl
- // User initialization code.
- b4_user_initial_action
-b4_dollar_popdef])[]dnl
-
- [ /* Initialize the stack. The initial state will be set in
- yynewstate, since the latter expects the semantical and the
- location values to have been already stored, initialize these
- stacks with a primary value. */
- yystack_.clear ();
- yypush_ (YY_NULL, 0, yyla);
-
- // A new symbol was pushed on the stack.
- yynewstate:
- YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;
-
- // Accept?
- if (yystack_[0].state == yyfinal_)
- goto yyacceptlab;
-
- goto yybackup;
-
- // Backup.
- yybackup:
-
- // Try to take a decision without lookahead.
- yyn = yypact_[yystack_[0].state];
- if (yy_pact_value_is_default_ (yyn))
- goto yydefault;
-
- // Read a lookahead token.
- if (yyempty)
- {
- YYCDEBUG << "Reading a token: ";
- try
- {]b4_token_ctor_if([[
- symbol_type yylookahead (]b4_lex[);
- yyla.move (yylookahead);]], [[
- yyla.type = yytranslate_ (]b4_lex[);]])[
- }
- catch (const syntax_error& yyexc)
- {
- error (yyexc);
- goto yyerrlab1;
- }
- yyempty = false;
- }
- YY_SYMBOL_PRINT ("Next token is", yyla);
-
- /* If the proper action on seeing token YYLA.TYPE is to reduce or
- to detect an error, take that action. */
- yyn += yyla.type_get ();
- if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
- goto yydefault;
-
- // Reduce or error.
- yyn = yytable_[yyn];
- if (yyn <= 0)
- {
- if (yy_table_value_is_error_ (yyn))
- goto yyerrlab;
- yyn = -yyn;
- goto yyreduce;
- }
-
- // Discard the token being shifted.
- yyempty = true;
-
- // Count tokens shifted since error; after three, turn off error status.
- if (yyerrstatus_)
- --yyerrstatus_;
-
- // Shift the lookahead token.
- yypush_ ("Shifting", yyn, yyla);
- goto yynewstate;
-
- /*-----------------------------------------------------------.
- | yydefault -- do the default action for the current state. |
- `-----------------------------------------------------------*/
- yydefault:
- yyn = yydefact_[yystack_[0].state];
- if (yyn == 0)
- goto yyerrlab;
- goto yyreduce;
-
- /*-----------------------------.
- | yyreduce -- Do a reduction. |
- `-----------------------------*/
- yyreduce:
- yylen = yyr2_[yyn];
- yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([
- /* Variants are always initialized to an empty instance of the
- correct type. The default $$=$1 action is NOT applied when using
- variants. */
- b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])],[
- /* If YYLEN is nonzero, implement the default value of the action:
- '$$ = $1'. Otherwise, use the top of the stack.
-
- Otherwise, the following line sets YYLHS.VALUE to garbage.
- This behavior is undocumented and Bison
- users should not rely upon it. */
- if (yylen)
- yylhs.value = yystack_@{yylen - 1@}.value;
- else
- yylhs.value = yystack_@{0@}.value;])[
-]b4_locations_if([dnl
-[
- // Compute the default @@$.
- {
- slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
- YYLLOC_DEFAULT (yylhs.location, slice, yylen);
- }]])[
-
- // Perform the reduction.
- YY_REDUCE_PRINT (yyn);
- try
- {
- switch (yyn)
- {
-]b4_user_actions[
- default:
- break;
- }
- }
- catch (const syntax_error& yyexc)
- {
- error (yyexc);
- YYERROR;
- }
- YY_SYMBOL_PRINT ("-> $$ =", yylhs);
- yypop_ (yylen);
- yylen = 0;
- YY_STACK_PRINT ();
-
- // Shift the result of the reduction.
- yypush_ (YY_NULL, yylhs);
- goto yynewstate;
-
- /*--------------------------------------.
- | yyerrlab -- here on detecting error. |
- `--------------------------------------*/
- yyerrlab:
- // If not already recovering from an error, report this error.
- if (!yyerrstatus_)
- {
- ++yynerrs_;
- error (]b4_join(b4_locations_if([yyla.location]),
- [[yysyntax_error_ (yystack_[0].state,
- yyempty ? yyempty_ : yyla.type_get ())]])[);
- }
-
-]b4_locations_if([[
- yyerror_range[1].location = yyla.location;]])[
- if (yyerrstatus_ == 3)
- {
- /* If just tried and failed to reuse lookahead token after an
- error, discard it. */
-
- // Return failure if at end of input.
- if (yyla.type_get () == yyeof_)
- YYABORT;
- else if (!yyempty)
- {
- yy_destroy_ ("Error: discarding", yyla);
- yyempty = true;
- }
- }
-
- // Else will try to reuse lookahead token after shifting the error token.
- goto yyerrlab1;
-
-
- /*---------------------------------------------------.
- | yyerrorlab -- error raised explicitly by YYERROR. |
- `---------------------------------------------------*/
- yyerrorlab:
-
- /* Pacify compilers like GCC when the user code never invokes
- YYERROR and the label yyerrorlab therefore never appears in user
- code. */
- if (false)
- goto yyerrorlab;]b4_locations_if([[
- yyerror_range[1].location = yystack_[yylen - 1].location;]])b4_variant_if([[
- /* $$ was initialized before running the user action. */
- YY_SYMBOL_PRINT ("Error: discarding", yylhs);
- yylhs.~stack_symbol_type();]])[
- /* Do not reclaim the symbols of the rule whose action triggered
- this YYERROR. */
- yypop_ (yylen);
- yylen = 0;
- goto yyerrlab1;
-
- /*-------------------------------------------------------------.
- | yyerrlab1 -- common code for both syntax error and YYERROR. |
- `-------------------------------------------------------------*/
- yyerrlab1:
- yyerrstatus_ = 3; // Each real token shifted decrements this.
- {
- stack_symbol_type error_token;
- for (;;)
- {
- yyn = yypact_[yystack_[0].state];
- if (!yy_pact_value_is_default_ (yyn))
- {
- yyn += yyterror_;
- if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
- {
- yyn = yytable_[yyn];
- if (0 < yyn)
- break;
- }
- }
-
- // Pop the current state because it cannot handle the error token.
- if (yystack_.size () == 1)
- YYABORT;
-]b4_locations_if([[
- yyerror_range[1].location = yystack_[0].location;]])[
- yy_destroy_ ("Error: popping", yystack_[0]);
- yypop_ ();
- YY_STACK_PRINT ();
- }
-]b4_locations_if([[
- yyerror_range[2].location = yyla.location;
- YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[
-
- // Shift the error token.
- error_token.state = yyn;
- yypush_ ("Shifting", error_token);
- }
- goto yynewstate;
-
- // Accept.
- yyacceptlab:
- yyresult = 0;
- goto yyreturn;
-
- // Abort.
- yyabortlab:
- yyresult = 1;
- goto yyreturn;
-
- yyreturn:
- if (!yyempty)
- yy_destroy_ ("Cleanup: discarding lookahead", yyla);
-
- /* Do not reclaim the symbols of the rule whose action triggered
- this YYABORT or YYACCEPT. */
- yypop_ (yylen);
- while (1 < yystack_.size ())
- {
- yy_destroy_ ("Cleanup: popping", yystack_[0]);
- yypop_ ();
- }
-
- return yyresult;
- }
- catch (...)
- {
- YYCDEBUG << "Exception caught: cleaning lookahead and stack"
- << std::endl;
- // Do not try to display the values of the reclaimed symbols,
- // as their printer might throw an exception.
- if (!yyempty)
- yy_destroy_ (YY_NULL, yyla);
-
- while (1 < yystack_.size ())
- {
- yy_destroy_ (YY_NULL, yystack_[0]);
- yypop_ ();
- }
- throw;
- }
- }
-
- void
- ]b4_parser_class_name[::error (const syntax_error& yyexc)
- {
- error (]b4_join(b4_locations_if([yyexc.location]),
- [[yyexc.what()]])[);
- }
-
- // Generate an error message.
- std::string
- ]b4_parser_class_name[::yysyntax_error_ (]dnl
-b4_error_verbose_if([state_type yystate, symbol_number_type yytoken],
- [state_type, symbol_number_type])[) const
- {]b4_error_verbose_if([[
- std::string yyres;
- // Number of reported tokens (one for the "unexpected", one per
- // "expected").
- size_t yycount = 0;
- // Its maximum.
- enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
- // Arguments of yyformat.
- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
-
- /* There are many possibilities here to consider:
- - If this state is a consistent state with a default action, then
- the only way this function was invoked is if the default action
- is an error action. In that case, don't check for expected
- tokens because there are none.
- - The only way there can be no lookahead present (in yytoken) is
- if this state is a consistent state with a default action.
- Thus, detecting the absence of a lookahead is sufficient to
- determine that there is no unexpected or expected token to
- report. In that case, just report a simple "syntax error".
- - Don't assume there isn't a lookahead just because this state is
- a consistent state with a default action. There might have
- been a previous inconsistent state, consistent state with a
- non-default action, or user semantic action that manipulated
- yyla. (However, yyla is currently not documented for users.)
- - Of course, the expected token list depends on states to have
- correct lookahead information, and it depends on the parser not
- to perform extra reductions after fetching a lookahead from the
- scanner and before detecting a syntax error. Thus, state
- merging (from LALR or IELR) and default reductions corrupt the
- expected token list. However, the list is correct for
- canonical LR with one exception: it will still contain any
- token that will not be accepted due to an error action in a
- later state.
- */
- if (yytoken != yyempty_)
- {
- yyarg[yycount++] = yytname_[yytoken];
- int yyn = yypact_[yystate];
- if (!yy_pact_value_is_default_ (yyn))
- {
- /* Start YYX at -YYN if negative to avoid negative indexes in
- YYCHECK. In other words, skip the first -YYN actions for
- this state because they are default actions. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
- // Stay within bounds of both yycheck and yytname.
- int yychecklim = yylast_ - yyn + 1;
- int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
- for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
- && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
- {
- if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
- {
- yycount = 1;
- break;
- }
- else
- yyarg[yycount++] = yytname_[yyx];
- }
- }
- }
-
- char const* yyformat = YY_NULL;
- switch (yycount)
- {
-#define YYCASE_(N, S) \
- case N: \
- yyformat = S; \
- break
- YYCASE_(0, YY_("syntax error"));
- YYCASE_(1, YY_("syntax error, unexpected %s"));
- YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
- YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
- YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
- YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
-#undef YYCASE_
- }
-
- // Argument number.
- size_t yyi = 0;
- for (char const* yyp = yyformat; *yyp; ++yyp)
- if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
- {
- yyres += yytnamerr_ (yyarg[yyi++]);
- ++yyp;
- }
- else
- yyres += *yyp;
- return yyres;]], [[
- return YY_("syntax error");]])[
- }
-
-
- const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
-
- const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
-
-]b4_parser_tables_define[
-
-]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
- // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- // First, the terminals, then, starting at \a yyntokens_, nonterminals.
- const char*
- const ]b4_parser_class_name[::yytname_[] =
- {
- ]b4_tname[
- };
-
-]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
-]b4_integral_parser_table_define([rline], [b4_rline])[
-
- // Print the state stack on the debug stream.
- void
- ]b4_parser_class_name[::yystack_print_ ()
- {
- *yycdebug_ << "Stack now";
- for (stack_type::const_iterator
- i = yystack_.begin (),
- i_end = yystack_.end ();
- i != i_end; ++i)
- *yycdebug_ << ' ' << i->state;
- *yycdebug_ << std::endl;
- }
-
- // Report on the debug stream that the rule \a yyrule is going to be reduced.
- void
- ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
- {
- unsigned int yylno = yyrline_[yyrule];
- int yynrhs = yyr2_[yyrule];
- // Print the symbols being reduced, and their result.
- *yycdebug_ << "Reducing stack by rule " << yyrule - 1
- << " (line " << yylno << "):" << std::endl;
- // The symbols being reduced.
- for (int yyi = 0; yyi < yynrhs; yyi++)
- YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
- ]b4_rhs_data(yynrhs, yyi + 1)[);
- }
-#endif // ]b4_api_PREFIX[DEBUG
-
-]b4_token_ctor_if([], [b4_yytranslate_define])[
-]b4_namespace_close[
-]b4_epilogue[]dnl
-b4_output_end()
-
-
-m4_popdef([b4_copyright_years])dnl
+
+ inline
+ ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that)
+ : super_type (s]b4_locations_if([, that.location])[)
+ {
+ ]b4_variant_if([b4_symbol_variant([that.type_get ()],
+ [value], [move], [that.value])],
+ [[value = that.value;]])[
+ // that is emptied.
+ that.type = empty;
+ }
+
+ inline
+ ]b4_parser_class_name[::stack_symbol_type&
+ ]b4_parser_class_name[::stack_symbol_type::operator= (const stack_symbol_type& that)
+ {
+ state = that.state;
+ ]b4_variant_if([b4_symbol_variant([that.type_get ()],
+ [value], [copy], [that.value])],
+ [[value = that.value;]])[]b4_locations_if([
+ location = that.location;])[
+ return *this;
+ }
+
+
+ template <typename Base>
+ inline
+ void
+ ]b4_parser_class_name[::yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const
+ {
+ if (yymsg)
+ YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [
+
+ // User destructor.
+ b4_symbol_actions([destructor], [yysym.type_get ()])])[
+ }
+
+#if ]b4_api_PREFIX[DEBUG
+ template <typename Base>
+ void
+ ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
+ const basic_symbol<Base>& yysym) const
+ {
+ std::ostream& yyoutput = yyo;
+ YYUSE (yyoutput);
+ symbol_number_type yytype = yysym.type_get ();
+ yyo << (yytype < yyntokens_ ? "token" : "nterm")
+ << ' ' << yytname_[yytype] << " ("]b4_locations_if([
+ << yysym.location << ": "])[;
+ ]b4_symbol_actions([printer])[
+ yyo << ')';
+ }
+#endif
+
+ inline
+ void
+ ]b4_parser_class_name[::yypush_ (const char* m, state_type s, symbol_type& sym)
+ {
+ stack_symbol_type t (s, sym);
+ yypush_ (m, t);
+ }
+
+ inline
+ void
+ ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
+ {
+ if (m)
+ YY_SYMBOL_PRINT (m, s);
+ yystack_.push (s);
+ }
+
+ inline
+ void
+ ]b4_parser_class_name[::yypop_ (unsigned int n)
+ {
+ yystack_.pop (n);
+ }
+
+#if ]b4_api_PREFIX[DEBUG
+ std::ostream&
+ ]b4_parser_class_name[::debug_stream () const
+ {
+ return *yycdebug_;
+ }
+
+ void
+ ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
+ {
+ yycdebug_ = &o;
+ }
+
+
+ ]b4_parser_class_name[::debug_level_type
+ ]b4_parser_class_name[::debug_level () const
+ {
+ return yydebug_;
+ }
+
+ void
+ ]b4_parser_class_name[::set_debug_level (debug_level_type l)
+ {
+ yydebug_ = l;
+ }
+#endif // ]b4_api_PREFIX[DEBUG
+
+ inline ]b4_parser_class_name[::state_type
+ ]b4_parser_class_name[::yy_lr_goto_state_ (state_type yystate, int yylhs)
+ {
+ int yyr = yypgoto_[yylhs - yyntokens_] + yystate;
+ if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
+ return yytable_[yyr];
+ else
+ return yydefgoto_[yylhs - yyntokens_];
+ }
+
+ inline bool
+ ]b4_parser_class_name[::yy_pact_value_is_default_ (int yyvalue)
+ {
+ return yyvalue == yypact_ninf_;
+ }
+
+ inline bool
+ ]b4_parser_class_name[::yy_table_value_is_error_ (int yyvalue)
+ {
+ return yyvalue == yytable_ninf_;
+ }
+
+ int
+ ]b4_parser_class_name[::parse ()
+ {
+ /// Whether yyla contains a lookahead.
+ bool yyempty = true;
+
+ // State.
+ int yyn;
+ int yylen = 0;
+
+ // Error handling.
+ int yynerrs_ = 0;
+ int yyerrstatus_ = 0;
+
+ /// The lookahead symbol.
+ symbol_type yyla;]b4_locations_if([[
+
+ /// The locations where the error started and ended.
+ stack_symbol_type yyerror_range[3];]])[
+
+ /// $$ and @@$.
+ stack_symbol_type yylhs;
+
+ /// The return value of parse ().
+ int yyresult;
+
+ // FIXME: This shoud be completely indented. It is not yet to
+ // avoid gratuitous conflicts when merging into the master branch.
+ try
+ {
+ YYCDEBUG << "Starting parse" << std::endl;
+
+]m4_ifdef([b4_initial_action], [
+b4_dollar_pushdef([yyla.value], [], [yyla.location])dnl
+ // User initialization code.
+ b4_user_initial_action
+b4_dollar_popdef])[]dnl
+
+ [ /* Initialize the stack. The initial state will be set in
+ yynewstate, since the latter expects the semantical and the
+ location values to have been already stored, initialize these
+ stacks with a primary value. */
+ yystack_.clear ();
+ yypush_ (YY_NULL, 0, yyla);
+
+ // A new symbol was pushed on the stack.
+ yynewstate:
+ YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;
+
+ // Accept?
+ if (yystack_[0].state == yyfinal_)
+ goto yyacceptlab;
+
+ goto yybackup;
+
+ // Backup.
+ yybackup:
+
+ // Try to take a decision without lookahead.
+ yyn = yypact_[yystack_[0].state];
+ if (yy_pact_value_is_default_ (yyn))
+ goto yydefault;
+
+ // Read a lookahead token.
+ if (yyempty)
+ {
+ YYCDEBUG << "Reading a token: ";
+ try
+ {]b4_token_ctor_if([[
+ symbol_type yylookahead (]b4_lex[);
+ yyla.move (yylookahead);]], [[
+ yyla.type = yytranslate_ (]b4_lex[);]])[
+ }
+ catch (const syntax_error& yyexc)
+ {
+ error (yyexc);
+ goto yyerrlab1;
+ }
+ yyempty = false;
+ }
+ YY_SYMBOL_PRINT ("Next token is", yyla);
+
+ /* If the proper action on seeing token YYLA.TYPE is to reduce or
+ to detect an error, take that action. */
+ yyn += yyla.type_get ();
+ if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
+ goto yydefault;
+
+ // Reduce or error.
+ yyn = yytable_[yyn];
+ if (yyn <= 0)
+ {
+ if (yy_table_value_is_error_ (yyn))
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ // Discard the token being shifted.
+ yyempty = true;
+
+ // Count tokens shifted since error; after three, turn off error status.
+ if (yyerrstatus_)
+ --yyerrstatus_;
+
+ // Shift the lookahead token.
+ yypush_ ("Shifting", yyn, yyla);
+ goto yynewstate;
+
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state. |
+ `-----------------------------------------------------------*/
+ yydefault:
+ yyn = yydefact_[yystack_[0].state];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+ /*-----------------------------.
+ | yyreduce -- Do a reduction. |
+ `-----------------------------*/
+ yyreduce:
+ yylen = yyr2_[yyn];
+ yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);]b4_variant_if([
+ /* Variants are always initialized to an empty instance of the
+ correct type. The default $$=$1 action is NOT applied when using
+ variants. */
+ b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])],[
+ /* If YYLEN is nonzero, implement the default value of the action:
+ '$$ = $1'. Otherwise, use the top of the stack.
+
+ Otherwise, the following line sets YYLHS.VALUE to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. */
+ if (yylen)
+ yylhs.value = yystack_@{yylen - 1@}.value;
+ else
+ yylhs.value = yystack_@{0@}.value;])[
+]b4_locations_if([dnl
+[
+ // Compute the default @@$.
+ {
+ slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
+ YYLLOC_DEFAULT (yylhs.location, slice, yylen);
+ }]])[
+
+ // Perform the reduction.
+ YY_REDUCE_PRINT (yyn);
+ try
+ {
+ switch (yyn)
+ {
+]b4_user_actions[
+ default:
+ break;
+ }
+ }
+ catch (const syntax_error& yyexc)
+ {
+ error (yyexc);
+ YYERROR;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yylhs);
+ yypop_ (yylen);
+ yylen = 0;
+ YY_STACK_PRINT ();
+
+ // Shift the result of the reduction.
+ yypush_ (YY_NULL, yylhs);
+ goto yynewstate;
+
+ /*--------------------------------------.
+ | yyerrlab -- here on detecting error. |
+ `--------------------------------------*/
+ yyerrlab:
+ // If not already recovering from an error, report this error.
+ if (!yyerrstatus_)
+ {
+ ++yynerrs_;
+ error (]b4_join(b4_locations_if([yyla.location]),
+ [[yysyntax_error_ (yystack_[0].state,
+ yyempty ? yyempty_ : yyla.type_get ())]])[);
+ }
+
+]b4_locations_if([[
+ yyerror_range[1].location = yyla.location;]])[
+ if (yyerrstatus_ == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ // Return failure if at end of input.
+ if (yyla.type_get () == yyeof_)
+ YYABORT;
+ else if (!yyempty)
+ {
+ yy_destroy_ ("Error: discarding", yyla);
+ yyempty = true;
+ }
+ }
+
+ // Else will try to reuse lookahead token after shifting the error token.
+ goto yyerrlab1;
+
+
+ /*---------------------------------------------------.
+ | yyerrorlab -- error raised explicitly by YYERROR. |
+ `---------------------------------------------------*/
+ yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (false)
+ goto yyerrorlab;]b4_locations_if([[
+ yyerror_range[1].location = yystack_[yylen - 1].location;]])b4_variant_if([[
+ /* $$ was initialized before running the user action. */
+ YY_SYMBOL_PRINT ("Error: discarding", yylhs);
+ yylhs.~stack_symbol_type();]])[
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYERROR. */
+ yypop_ (yylen);
+ yylen = 0;
+ goto yyerrlab1;
+
+ /*-------------------------------------------------------------.
+ | yyerrlab1 -- common code for both syntax error and YYERROR. |
+ `-------------------------------------------------------------*/
+ yyerrlab1:
+ yyerrstatus_ = 3; // Each real token shifted decrements this.
+ {
+ stack_symbol_type error_token;
+ for (;;)
+ {
+ yyn = yypact_[yystack_[0].state];
+ if (!yy_pact_value_is_default_ (yyn))
+ {
+ yyn += yyterror_;
+ if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
+ {
+ yyn = yytable_[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ // Pop the current state because it cannot handle the error token.
+ if (yystack_.size () == 1)
+ YYABORT;
+]b4_locations_if([[
+ yyerror_range[1].location = yystack_[0].location;]])[
+ yy_destroy_ ("Error: popping", yystack_[0]);
+ yypop_ ();
+ YY_STACK_PRINT ();
+ }
+]b4_locations_if([[
+ yyerror_range[2].location = yyla.location;
+ YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[
+
+ // Shift the error token.
+ error_token.state = yyn;
+ yypush_ ("Shifting", error_token);
+ }
+ goto yynewstate;
+
+ // Accept.
+ yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+ // Abort.
+ yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+ yyreturn:
+ if (!yyempty)
+ yy_destroy_ ("Cleanup: discarding lookahead", yyla);
+
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYABORT or YYACCEPT. */
+ yypop_ (yylen);
+ while (1 < yystack_.size ())
+ {
+ yy_destroy_ ("Cleanup: popping", yystack_[0]);
+ yypop_ ();
+ }
+
+ return yyresult;
+ }
+ catch (...)
+ {
+ YYCDEBUG << "Exception caught: cleaning lookahead and stack"
+ << std::endl;
+ // Do not try to display the values of the reclaimed symbols,
+ // as their printer might throw an exception.
+ if (!yyempty)
+ yy_destroy_ (YY_NULL, yyla);
+
+ while (1 < yystack_.size ())
+ {
+ yy_destroy_ (YY_NULL, yystack_[0]);
+ yypop_ ();
+ }
+ throw;
+ }
+ }
+
+ void
+ ]b4_parser_class_name[::error (const syntax_error& yyexc)
+ {
+ error (]b4_join(b4_locations_if([yyexc.location]),
+ [[yyexc.what()]])[);
+ }
+
+ // Generate an error message.
+ std::string
+ ]b4_parser_class_name[::yysyntax_error_ (]dnl
+b4_error_verbose_if([state_type yystate, symbol_number_type yytoken],
+ [state_type, symbol_number_type])[) const
+ {]b4_error_verbose_if([[
+ std::string yyres;
+ // Number of reported tokens (one for the "unexpected", one per
+ // "expected").
+ size_t yycount = 0;
+ // Its maximum.
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ // Arguments of yyformat.
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+
+ /* There are many possibilities here to consider:
+ - If this state is a consistent state with a default action, then
+ the only way this function was invoked is if the default action
+ is an error action. In that case, don't check for expected
+ tokens because there are none.
+ - The only way there can be no lookahead present (in yytoken) is
+ if this state is a consistent state with a default action.
+ Thus, detecting the absence of a lookahead is sufficient to
+ determine that there is no unexpected or expected token to
+ report. In that case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this state is
+ a consistent state with a default action. There might have
+ been a previous inconsistent state, consistent state with a
+ non-default action, or user semantic action that manipulated
+ yyla. (However, yyla is currently not documented for users.)
+ - Of course, the expected token list depends on states to have
+ correct lookahead information, and it depends on the parser not
+ to perform extra reductions after fetching a lookahead from the
+ scanner and before detecting a syntax error. Thus, state
+ merging (from LALR or IELR) and default reductions corrupt the
+ expected token list. However, the list is correct for
+ canonical LR with one exception: it will still contain any
+ token that will not be accepted due to an error action in a
+ later state.
+ */
+ if (yytoken != yyempty_)
+ {
+ yyarg[yycount++] = yytname_[yytoken];
+ int yyn = yypact_[yystate];
+ if (!yy_pact_value_is_default_ (yyn))
+ {
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. In other words, skip the first -YYN actions for
+ this state because they are default actions. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+ // Stay within bounds of both yycheck and yytname.
+ int yychecklim = yylast_ - yyn + 1;
+ int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
+ for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
+ && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ break;
+ }
+ else
+ yyarg[yycount++] = yytname_[yyx];
+ }
+ }
+ }
+
+ char const* yyformat = YY_NULL;
+ switch (yycount)
+ {
+#define YYCASE_(N, S) \
+ case N: \
+ yyformat = S; \
+ break
+ YYCASE_(0, YY_("syntax error"));
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+#undef YYCASE_
+ }
+
+ // Argument number.
+ size_t yyi = 0;
+ for (char const* yyp = yyformat; *yyp; ++yyp)
+ if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
+ {
+ yyres += yytnamerr_ (yyarg[yyi++]);
+ ++yyp;
+ }
+ else
+ yyres += *yyp;
+ return yyres;]], [[
+ return YY_("syntax error");]])[
+ }
+
+
+ const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
+
+ const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
+
+]b4_parser_tables_define[
+
+]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
+ // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ // First, the terminals, then, starting at \a yyntokens_, nonterminals.
+ const char*
+ const ]b4_parser_class_name[::yytname_[] =
+ {
+ ]b4_tname[
+ };
+
+]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
+]b4_integral_parser_table_define([rline], [b4_rline])[
+
+ // Print the state stack on the debug stream.
+ void
+ ]b4_parser_class_name[::yystack_print_ ()
+ {
+ *yycdebug_ << "Stack now";
+ for (stack_type::const_iterator
+ i = yystack_.begin (),
+ i_end = yystack_.end ();
+ i != i_end; ++i)
+ *yycdebug_ << ' ' << i->state;
+ *yycdebug_ << std::endl;
+ }
+
+ // Report on the debug stream that the rule \a yyrule is going to be reduced.
+ void
+ ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
+ {
+ unsigned int yylno = yyrline_[yyrule];
+ int yynrhs = yyr2_[yyrule];
+ // Print the symbols being reduced, and their result.
+ *yycdebug_ << "Reducing stack by rule " << yyrule - 1
+ << " (line " << yylno << "):" << std::endl;
+ // The symbols being reduced.
+ for (int yyi = 0; yyi < yynrhs; yyi++)
+ YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
+ ]b4_rhs_data(yynrhs, yyi + 1)[);
+ }
+#endif // ]b4_api_PREFIX[DEBUG
+
+]b4_token_ctor_if([], [b4_yytranslate_define])[
+]b4_namespace_close[
+]b4_epilogue[]dnl
+b4_output_end()
+
+
+m4_popdef([b4_copyright_years])dnl
diff --git a/contrib/tools/bison/bison/data/lalr1.java b/contrib/tools/bison/bison/data/lalr1.java
index d137ed814b..a475919d07 100644
--- a/contrib/tools/bison/bison/data/lalr1.java
+++ b/contrib/tools/bison/bison/data/lalr1.java
@@ -1,1065 +1,1065 @@
-# Java skeleton for Bison -*- autoconf -*-
-
-# Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-m4_include(b4_pkgdatadir/[java.m4])
-
-b4_defines_if([b4_fatal([%s: %%defines does not make sense in Java],
- [b4_skeleton])])
-
-# We do not depend on %debug in Java, but pacify warnings about
-# non-used flags.
-b4_parse_trace_if([0], [0])
-
-m4_define([b4_symbol_no_destructor_assert],
-[b4_symbol_if([$1], [has_destructor],
- [b4_fatal([%s: %s: %%destructor does not make sense in Java],
- [b4_skeleton],
- [b4_symbol_action_location([$1], [destructor])])])])
-b4_symbol_foreach([b4_symbol_no_destructor_assert])
-
-# Setup some macros for api.push-pull.
-b4_percent_define_default([[api.push-pull]], [[pull]])
-b4_percent_define_check_values([[[[api.push-pull]],
- [[pull]], [[push]], [[both]]]])
-
-# Define m4 conditional macros that encode the value
-# of the api.push-pull flag.
-b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]])
-b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]])
-m4_case(b4_percent_define_get([[api.push-pull]]),
- [pull], [m4_define([b4_push_flag], [[0]])],
- [push], [m4_define([b4_pull_flag], [[0]])])
-
-# Define a macro to be true when api.push-pull has the value "both".
-m4_define([b4_both_if],[b4_push_if([b4_pull_if([$1],[$2])],[$2])])
-
-# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing
-# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the
-# behavior of Bison at all when push parsing is already requested.
-b4_define_flag_if([use_push_for_pull])
-b4_use_push_for_pull_if([
- b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])],
- [m4_define([b4_push_flag], [[1]])])])
-
-# Define a macro to encapsulate the parse state variables.
-# This allows them to be defined either in parse() when doing
-# pull parsing, or as class instance variable when doing push parsing.
-m4_define([b4_define_state],[[
- /* Lookahead and lookahead in internal form. */
- int yychar = yyempty_;
- int yytoken = 0;
-
- /* State. */
- int yyn = 0;
- int yylen = 0;
- int yystate = 0;
- YYStack yystack = new YYStack ();
- int label = YYNEWSTATE;
-
- /* Error handling. */
- int yynerrs_ = 0;
- ]b4_locations_if([/* The location where the error started. */
- b4_location_type yyerrloc = null;
-
- /* Location. */
- b4_location_type yylloc = new b4_location_type (null, null);])[
-
- /* Semantic value of the lookahead. */
- ]b4_yystype[ yylval = null;
-]])
-
-b4_output_begin([b4_parser_file_name])
-b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
- [2007-2013])
-
-b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
-])[/* First part of user declarations. */
-]b4_user_pre_prologue
-b4_user_post_prologue
-b4_percent_code_get([[imports]])
-[/**
- * A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
- *
- * @@author LALR (1) parser skeleton written by Paolo Bonzini.
- */
-]b4_percent_define_get3([annotations], [], [ ])dnl
-b4_public_if([public ])dnl
-b4_abstract_if([abstract ])dnl
-b4_final_if([final ])dnl
-b4_strictfp_if([strictfp ])dnl
-[class ]b4_parser_class_name[]dnl
-b4_percent_define_get3([extends], [ extends ])dnl
-b4_percent_define_get3([implements], [ implements ])[
-{
- ]b4_identification[
-]b4_error_verbose_if([[
- /**
- * True if verbose error messages are enabled.
- */
- private boolean yyErrorVerbose = true;
-
- /**
- * Return whether verbose error messages are enabled.
- */
- public final boolean getErrorVerbose() { return yyErrorVerbose; }
-
- /**
- * Set the verbosity of error messages.
- * @@param verbose True to request verbose error messages.
- */
- public final void setErrorVerbose(boolean verbose)
- { yyErrorVerbose = verbose; }
-]])
-
-b4_locations_if([[
- /**
- * A class defining a pair of positions. Positions, defined by the
- * <code>]b4_position_type[</code> class, denote a point in the input.
- * Locations represent a part of the input through the beginning
- * and ending positions.
- */
- public class ]b4_location_type[ {
- /**
- * The first, inclusive, position in the range.
- */
- public ]b4_position_type[ begin;
-
- /**
- * The first position beyond the range.
- */
- public ]b4_position_type[ end;
-
- /**
- * Create a <code>]b4_location_type[</code> denoting an empty range located at
- * a given point.
- * @@param loc The position at which the range is anchored.
- */
- public ]b4_location_type[ (]b4_position_type[ loc) {
- this.begin = this.end = loc;
- }
-
- /**
- * Create a <code>]b4_location_type[</code> from the endpoints of the range.
- * @@param begin The first position included in the range.
- * @@param end The first position beyond the range.
- */
- public ]b4_location_type[ (]b4_position_type[ begin, ]b4_position_type[ end) {
- this.begin = begin;
- this.end = end;
- }
-
- /**
- * Print a representation of the location. For this to be correct,
- * <code>]b4_position_type[</code> should override the <code>equals</code>
- * method.
- */
- public String toString () {
- if (begin.equals (end))
- return begin.toString ();
- else
- return begin.toString () + "-" + end.toString ();
- }
- }
-
-]])
-
- b4_locations_if([[
- private ]b4_location_type[ yylloc (YYStack rhs, int n)
- {
- if (n > 0)
- return new ]b4_location_type[ (rhs.locationAt (n-1).begin, rhs.locationAt (0).end);
- else
- return new ]b4_location_type[ (rhs.locationAt (0).end);
- }]])[
-
- /**
- * Communication interface between the scanner and the Bison-generated
- * parser <tt>]b4_parser_class_name[</tt>.
- */
- public interface Lexer {
- /** Token returned by the scanner to signal the end of its input. */
- public static final int EOF = 0;
-
-]b4_token_enums[
-
- ]b4_locations_if([[/**
- * Method to retrieve the beginning position of the last scanned token.
- * @@return the position at which the last scanned token starts.
- */
- ]b4_position_type[ getStartPos ();
-
- /**
- * Method to retrieve the ending position of the last scanned token.
- * @@return the first position beyond the last scanned token.
- */
- ]b4_position_type[ getEndPos ();]])[
-
- /**
- * Method to retrieve the semantic value of the last scanned token.
- * @@return the semantic value of the last scanned token.
- */
- ]b4_yystype[ getLVal ();
-
- /**
- * Entry point for the scanner. Returns the token identifier corresponding
- * to the next token and prepares to return the semantic value
- * ]b4_locations_if([and beginning/ending positions ])[of the token.
- * @@return the token identifier corresponding to the next token.
- */
- int yylex () ]b4_maybe_throws([b4_lex_throws])[;
-
- /**
- * Entry point for error reporting. Emits an error
- * ]b4_locations_if([referring to the given location ])[in a user-defined way.
- *
- * ]b4_locations_if([[@@param loc The location of the element to which the
- * error message is related]])[
- * @@param msg The string for the error message.
- */
- void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);]
- }
-
- b4_lexer_if([[private class YYLexer implements Lexer {
-]b4_percent_code_get([[lexer]])[
- }
-
- ]])[/**
- * The object doing lexical analysis for us.
- */
- private Lexer yylexer;
- ]
- b4_parse_param_vars
-
-b4_lexer_if([[
- /**
- * Instantiates the Bison-generated parser.
- */
- public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) ]b4_maybe_throws([b4_init_throws])[
- {
- ]b4_percent_code_get([[init]])[
- this.yylexer = new YYLexer(]b4_lex_param_call[);
- ]b4_parse_param_cons[
- }
-]])
-
- /**
- * Instantiates the Bison-generated parser.
- * @@param yylexer The scanner that will supply tokens to the parser.
- */
- b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ (]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[
- {
- ]b4_percent_code_get([[init]])[
- this.yylexer = yylexer;
- ]b4_parse_param_cons[
- }
-
- private java.io.PrintStream yyDebugStream = System.err;
-
- /**
- * Return the <tt>PrintStream</tt> on which the debugging output is
- * printed.
- */
- public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
-
- /**
- * Set the <tt>PrintStream</tt> on which the debug output is printed.
- * @@param s The stream that is used for debugging output.
- */
- public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; }
-
- private int yydebug = 0;
-
- /**
- * Answer the verbosity of the debugging output; 0 means that all kinds of
- * output from the parser are suppressed.
- */
- public final int getDebugLevel() { return yydebug; }
-
- /**
- * Set the verbosity of the debugging output; 0 means that all kinds of
- * output from the parser are suppressed.
- * @@param level The verbosity level for debugging output.
- */
- public final void setDebugLevel(int level) { yydebug = level; }
-
- /**
- * Print an error message via the lexer.
- *]b4_locations_if([[ Use a <code>null</code> location.]])[
- * @@param msg The error message.
- */
- public final void yyerror (String msg)
- {
- yylexer.yyerror (]b4_locations_if([[(]b4_location_type[)null, ]])[msg);
- }
-]b4_locations_if([[
- /**
- * Print an error message via the lexer.
- * @@param loc The location associated with the message.
- * @@param msg The error message.
- */
- public final void yyerror (]b4_location_type[ loc, String msg)
- {
- yylexer.yyerror (loc, msg);
- }
-
- /**
- * Print an error message via the lexer.
- * @@param pos The position associated with the message.
- * @@param msg The error message.
- */
- public final void yyerror (]b4_position_type[ pos, String msg)
- {
- yylexer.yyerror (new ]b4_location_type[ (pos), msg);
- }]])
-
- [protected final void yycdebug (String s) {
- if (yydebug > 0)
- yyDebugStream.println (s);
- }
-
- private final class YYStack {
- private int[] stateStack = new int[16];
- ]b4_locations_if([[private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[
- private ]b4_yystype[[] valueStack = new ]b4_yystype[[16];
-
- public int size = 16;
- public int height = -1;
-
- public final void push (int state, ]b4_yystype[ value]dnl
- b4_locations_if([, ]b4_location_type[ loc])[) {
- height++;
- if (size == height)
- {
- int[] newStateStack = new int[size * 2];
- System.arraycopy (stateStack, 0, newStateStack, 0, height);
- stateStack = newStateStack;
- ]b4_locations_if([[
- ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
- System.arraycopy (locStack, 0, newLocStack, 0, height);
- locStack = newLocStack;]])
-
- b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
- System.arraycopy (valueStack, 0, newValueStack, 0, height);
- valueStack = newValueStack;
-
- size *= 2;
- }
-
- stateStack[height] = state;
- ]b4_locations_if([[locStack[height] = loc;]])[
- valueStack[height] = value;
- }
-
- public final void pop () {
- pop (1);
- }
-
- public final void pop (int num) {
- // Avoid memory leaks... garbage collection is a white lie!
- if (num > 0) {
- java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);
- ]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
- }
- height -= num;
- }
-
- public final int stateAt (int i) {
- return stateStack[height - i];
- }
-
- ]b4_locations_if([[public final ]b4_location_type[ locationAt (int i) {
- return locStack[height - i];
- }
-
- ]])[public final ]b4_yystype[ valueAt (int i) {
- return valueStack[height - i];
- }
-
- // Print the state stack on the debug stream.
- public void print (java.io.PrintStream out)
- {
- out.print ("Stack now");
-
- for (int i = 0; i <= height; i++)
- {
- out.print (' ');
- out.print (stateStack[i]);
- }
- out.println ();
- }
- }
-
- /**
- * Returned by a Bison action in order to stop the parsing process and
- * return success (<tt>true</tt>).
- */
- public static final int YYACCEPT = 0;
-
- /**
- * Returned by a Bison action in order to stop the parsing process and
- * return failure (<tt>false</tt>).
- */
- public static final int YYABORT = 1;
-
-]b4_push_if([
- /**
- * Returned by a Bison action in order to request a new token.
- */
- public static final int YYPUSH_MORE = 4;])[
-
- /**
- * Returned by a Bison action in order to start error recovery without
- * printing an error message.
- */
- public static final int YYERROR = 2;
-
- /**
- * Internal return codes that are not supported for user semantic
- * actions.
- */
- private static final int YYERRLAB = 3;
- private static final int YYNEWSTATE = 4;
- private static final int YYDEFAULT = 5;
- private static final int YYREDUCE = 6;
- private static final int YYERRLAB1 = 7;
- private static final int YYRETURN = 8;
-]b4_push_if([[ private static final int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[
-
- private int yyerrstatus_ = 0;
-
-]b4_push_if([dnl
-b4_define_state])[
- /**
- * Return whether error recovery is being done. In this state, the parser
- * reads token until it reaches a known state, and then restarts normal
- * operation.
- */
- public final boolean recovering ()
- {
- return yyerrstatus_ == 0;
- }
-
- private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[
- {
- ]b4_yystype[ yyval;
- ]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
-
- /* If YYLEN is nonzero, implement the default value of the action:
- '$$ = $1'. Otherwise, use the top of the stack.
-
- Otherwise, the following line sets YYVAL to garbage.
- This behavior is undocumented and Bison
- users should not rely upon it. */
- if (yylen > 0)
- yyval = yystack.valueAt (yylen - 1);
- else
- yyval = yystack.valueAt (0);
-
- yy_reduce_print (yyn, yystack);
-
- switch (yyn)
- {
- ]b4_user_actions[
- default: break;
- }
-
- yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);
-
- yystack.pop (yylen);
- yylen = 0;
-
- /* Shift the result of the reduction. */
- yyn = yyr1_[yyn];
- int yystate = yypgoto_[yyn - yyntokens_] + yystack.stateAt (0);
- if (0 <= yystate && yystate <= yylast_
- && yycheck_[yystate] == yystack.stateAt (0))
- yystate = yytable_[yystate];
- else
- yystate = yydefgoto_[yyn - yyntokens_];
-
- yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
- return YYNEWSTATE;
- }
-
-]b4_error_verbose_if([[
- /* Return YYSTR after stripping away unnecessary quotes and
- backslashes, so that it's suitable for yyerror. The heuristic is
- that double-quoting is unnecessary unless the string contains an
- apostrophe, a comma, or backslash (other than backslash-backslash).
- YYSTR is taken from yytname. */
- private final String yytnamerr_ (String yystr)
- {
- if (yystr.charAt (0) == '"')
- {
- StringBuffer yyr = new StringBuffer ();
- strip_quotes: for (int i = 1; i < yystr.length (); i++)
- switch (yystr.charAt (i))
- {
- case '\'':
- case ',':
- break strip_quotes;
-
- case '\\':
- if (yystr.charAt(++i) != '\\')
- break strip_quotes;
- /* Fall through. */
- default:
- yyr.append (yystr.charAt (i));
- break;
-
- case '"':
- return yyr.toString ();
- }
- }
- else if (yystr.equals ("$end"))
- return "end of input";
-
- return yystr;
- }
-]])[
-
- /*--------------------------------.
- | Print this symbol on YYOUTPUT. |
- `--------------------------------*/
-
- private void yy_symbol_print (String s, int yytype,
- ]b4_yystype[ yyvaluep]dnl
- b4_locations_if([, Object yylocationp])[)
- {
- if (yydebug > 0)
- yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
- + yytname_[yytype] + " ("]b4_locations_if([
- + yylocationp + ": "])[
- + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
- }
-
-]b4_push_if([],[[
- /**
- * Parse input from the scanner that was specified at object construction
- * time. Return whether the end of the input was reached successfully.
- *
- * @@return <tt>true</tt> if the parsing succeeds. Note that this does not
- * imply that there were no syntax errors.
- */
- public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[
-]b4_push_if([
- /**
- * Push Parse input from external lexer
- *
- * @@param yylextoken current token
- * @@param yylexval current lval
-]b4_locations_if([ * @@param yylexloc current position])[
- *
- * @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
- */
- public int push_parse (int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))
- b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[
- {
- ]b4_locations_if([/* @@$. */
- b4_location_type yyloc;])[
-]b4_push_if([],[[
-]b4_define_state[
- yycdebug ("Starting parse\n");
- yyerrstatus_ = 0;
-
- /* Initialize the stack. */
- yystack.push (yystate, yylval ]b4_locations_if([, yylloc])[);
-]m4_ifdef([b4_initial_action], [
-b4_dollar_pushdef([yylval], [], [yylloc])dnl
- /* User initialization code. */
- b4_user_initial_action
-b4_dollar_popdef[]dnl
-])[
-]])[
-]b4_push_if([[
- if (!this.push_parse_initialized)
- {
- push_parse_initialize ();
-]m4_ifdef([b4_initial_action], [
-b4_dollar_pushdef([yylval], [], [yylloc])dnl
- /* User initialization code. */
- b4_user_initial_action
-b4_dollar_popdef[]dnl
-])[
- yycdebug ("Starting parse\n");
- yyerrstatus_ = 0;
- } else
- label = YYGETTOKEN;
-
- boolean push_token_consumed = true;
-]])[
- for (;;)
- switch (label)
- {
- /* New state. Unlike in the C/C++ skeletons, the state is already
- pushed when we come here. */
- case YYNEWSTATE:
- yycdebug ("Entering state " + yystate + "\n");
- if (yydebug > 0)
- yystack.print (yyDebugStream);
-
- /* Accept? */
- if (yystate == yyfinal_)
- ]b4_push_if([{label = YYACCEPT; break;}],
- [return true;])[
-
- /* Take a decision. First try without lookahead. */
- yyn = yypact_[yystate];
- if (yy_pact_value_is_default_ (yyn))
- {
- label = YYDEFAULT;
- break;
- }
-]b4_push_if([ /* Fall Through */
-
- case YYGETTOKEN:])[
- /* Read a lookahead token. */
- if (yychar == yyempty_)
- {
-]b4_push_if([[
- if (!push_token_consumed)
- return YYPUSH_MORE;
- yycdebug ("Reading a token: ");
- yychar = yylextoken;
- yylval = yylexval;]b4_locations_if([
- yylloc = yylexloc;])[
- push_token_consumed = false;]])[
-]b4_push_if([],[[
- yycdebug ("Reading a token: ");
- yychar = yylexer.yylex ();
- yylval = yylexer.getLVal ();]b4_locations_if([
- yylloc = new b4_location_type (yylexer.getStartPos (),
- yylexer.getEndPos ());])[
-]])[
- }
-
- /* Convert token to internal form. */
- if (yychar <= Lexer.EOF)
- {
- yychar = yytoken = Lexer.EOF;
- yycdebug ("Now at end of input.\n");
- }
- else
- {
- yytoken = yytranslate_ (yychar);
- yy_symbol_print ("Next token is", yytoken,
- yylval]b4_locations_if([, yylloc])[);
- }
-
- /* If the proper action on seeing token YYTOKEN is to reduce or to
- detect an error, take that action. */
- yyn += yytoken;
- if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
- label = YYDEFAULT;
-
- /* <= 0 means reduce or error. */
- else if ((yyn = yytable_[yyn]) <= 0)
- {
- if (yy_table_value_is_error_ (yyn))
- label = YYERRLAB;
- else
- {
- yyn = -yyn;
- label = YYREDUCE;
- }
- }
-
- else
- {
- /* Shift the lookahead token. */
- yy_symbol_print ("Shifting", yytoken,
- yylval]b4_locations_if([, yylloc])[);
-
- /* Discard the token being shifted. */
- yychar = yyempty_;
-
- /* Count tokens shifted since error; after three, turn off error
- status. */
- if (yyerrstatus_ > 0)
- --yyerrstatus_;
-
- yystate = yyn;
- yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
- label = YYNEWSTATE;
- }
- break;
-
- /*-----------------------------------------------------------.
- | yydefault -- do the default action for the current state. |
- `-----------------------------------------------------------*/
- case YYDEFAULT:
- yyn = yydefact_[yystate];
- if (yyn == 0)
- label = YYERRLAB;
- else
- label = YYREDUCE;
- break;
-
- /*-----------------------------.
- | yyreduce -- Do a reduction. |
- `-----------------------------*/
- case YYREDUCE:
- yylen = yyr2_[yyn];
- label = yyaction (yyn, yystack, yylen);
- yystate = yystack.stateAt (0);
- break;
-
- /*------------------------------------.
- | yyerrlab -- here on detecting error |
- `------------------------------------*/
- case YYERRLAB:
- /* If not already recovering from an error, report this error. */
- if (yyerrstatus_ == 0)
- {
- ++yynerrs_;
- if (yychar == yyempty_)
- yytoken = yyempty_;
- yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
- }
-
- ]b4_locations_if([yyerrloc = yylloc;])[
- if (yyerrstatus_ == 3)
- {
- /* If just tried and failed to reuse lookahead token after an
- error, discard it. */
-
- if (yychar <= Lexer.EOF)
- {
- /* Return failure if at end of input. */
- if (yychar == Lexer.EOF)
- ]b4_push_if([{label = YYABORT; break;}],[return false;])[
- }
- else
- yychar = yyempty_;
- }
-
- /* Else will try to reuse lookahead token after shifting the error
- token. */
- label = YYERRLAB1;
- break;
-
- /*-------------------------------------------------.
- | errorlab -- error raised explicitly by YYERROR. |
- `-------------------------------------------------*/
- case YYERROR:
-
- ]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
- /* Do not reclaim the symbols of the rule which action triggered
- this YYERROR. */
- yystack.pop (yylen);
- yylen = 0;
- yystate = yystack.stateAt (0);
- label = YYERRLAB1;
- break;
-
- /*-------------------------------------------------------------.
- | yyerrlab1 -- common code for both syntax error and YYERROR. |
- `-------------------------------------------------------------*/
- case YYERRLAB1:
- yyerrstatus_ = 3; /* Each real token shifted decrements this. */
-
- for (;;)
- {
- yyn = yypact_[yystate];
- if (!yy_pact_value_is_default_ (yyn))
- {
- yyn += yyterror_;
- if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
- {
- yyn = yytable_[yyn];
- if (0 < yyn)
- break;
- }
- }
-
- /* Pop the current state because it cannot handle the
- * error token. */
- if (yystack.height == 0)
- ]b4_push_if([{label = YYABORT; break;}],[return false;])[
-
- ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
- yystack.pop ();
- yystate = yystack.stateAt (0);
- if (yydebug > 0)
- yystack.print (yyDebugStream);
- }
-
- if (label == YYABORT)
- /* Leave the switch. */
- break;
-
-]b4_locations_if([
- /* Muck with the stack to setup for yylloc. */
- yystack.push (0, null, yylloc);
- yystack.push (0, null, yyerrloc);
- yyloc = yylloc (yystack, 2);
- yystack.pop (2);])[
-
- /* Shift the error token. */
- yy_symbol_print ("Shifting", yystos_[yyn],
- yylval]b4_locations_if([, yyloc])[);
-
- yystate = yyn;
- yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
- label = YYNEWSTATE;
- break;
-
- /* Accept. */
- case YYACCEPT:
- ]b4_push_if([this.push_parse_initialized = false; return YYACCEPT;],
- [return true;])[
-
- /* Abort. */
- case YYABORT:
- ]b4_push_if([this.push_parse_initialized = false; return YYABORT;],
- [return false;])[
- }
-}
-]b4_push_if([[
- boolean push_parse_initialized = false;
-
- /**
- * (Re-)Initialize the state of the push parser.
- */
- public void push_parse_initialize()
- {
- /* Lookahead and lookahead in internal form. */
- this.yychar = yyempty_;
- this.yytoken = 0;
-
- /* State. */
- this.yyn = 0;
- this.yylen = 0;
- this.yystate = 0;
- this.yystack = new YYStack ();
- this.label = YYNEWSTATE;
-
- /* Error handling. */
- this.yynerrs_ = 0;
- ]b4_locations_if([/* The location where the error started. */
- this.yyerrloc = null;
- this.yylloc = new b4_location_type (null, null);])[
-
- /* Semantic value of the lookahead. */
- this.yylval = null;
-
- yystack.push (this.yystate, this.yylval]b4_locations_if([, this.yylloc])[);
-
- this.push_parse_initialized = true;
-
- }
-]b4_locations_if([
- /**
- * Push parse given input from an external lexer.
- *
- * @@param yylextoken current token
- * @@param yylexval current lval
- * @@param yyylexpos current position
- *
- * @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
- */
- public int push_parse (int yylextoken, b4_yystype yylexval, b4_position_type yylexpos)
- b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])
- {
- return push_parse (yylextoken, yylexval, new b4_location_type (yylexpos));
- }
-])[]])
-
-b4_both_if([[
- /**
- * Parse input from the scanner that was specified at object construction
- * time. Return whether the end of the input was reached successfully.
- * This version of parse () is defined only when api.push-push=both.
- *
- * @@return <tt>true</tt> if the parsing succeeds. Note that this does not
- * imply that there were no syntax errors.
- */
- public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
- {
- if (yylexer == null)
- throw new NullPointerException("Null Lexer");
- int status;
- do {
- int token = yylexer.yylex();
- ]b4_yystype[ lval = yylexer.getLVal();
-]b4_locations_if([dnl
- b4_location_type yyloc = new b4_location_type (yylexer.getStartPos (),
- yylexer.getEndPos ());])[
- ]b4_locations_if([status = push_parse(token,lval,yyloc);],[
- status = push_parse(token,lval);])[
- } while (status == YYPUSH_MORE);
- return (status == YYACCEPT);
- }
-]])[
-
- // Generate an error message.
- private String yysyntax_error (int yystate, int tok)
- {]b4_error_verbose_if([[
- if (yyErrorVerbose)
- {
- /* There are many possibilities here to consider:
- - If this state is a consistent state with a default action,
- then the only way this function was invoked is if the
- default action is an error action. In that case, don't
- check for expected tokens because there are none.
- - The only way there can be no lookahead present (in tok) is
- if this state is a consistent state with a default action.
- Thus, detecting the absence of a lookahead is sufficient to
- determine that there is no unexpected or expected token to
- report. In that case, just report a simple "syntax error".
- - Don't assume there isn't a lookahead just because this
- state is a consistent state with a default action. There
- might have been a previous inconsistent state, consistent
- state with a non-default action, or user semantic action
- that manipulated yychar. (However, yychar is currently out
- of scope during semantic actions.)
- - Of course, the expected token list depends on states to
- have correct lookahead information, and it depends on the
- parser not to perform extra reductions after fetching a
- lookahead from the scanner and before detecting a syntax
- error. Thus, state merging (from LALR or IELR) and default
- reductions corrupt the expected token list. However, the
- list is correct for canonical LR with one exception: it
- will still contain any token that will not be accepted due
- to an error action in a later state.
- */
- if (tok != yyempty_)
- {
- /* FIXME: This method of building the message is not compatible
- with internationalization. */
- StringBuffer res =
- new StringBuffer ("syntax error, unexpected ");
- res.append (yytnamerr_ (yytname_[tok]));
- int yyn = yypact_[yystate];
- if (!yy_pact_value_is_default_ (yyn))
- {
- /* Start YYX at -YYN if negative to avoid negative
- indexes in YYCHECK. In other words, skip the first
- -YYN actions for this state because they are default
- actions. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = yylast_ - yyn + 1;
- int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
- int count = 0;
- for (int x = yyxbegin; x < yyxend; ++x)
- if (yycheck_[x + yyn] == x && x != yyterror_
- && !yy_table_value_is_error_ (yytable_[x + yyn]))
- ++count;
- if (count < 5)
- {
- count = 0;
- for (int x = yyxbegin; x < yyxend; ++x)
- if (yycheck_[x + yyn] == x && x != yyterror_
- && !yy_table_value_is_error_ (yytable_[x + yyn]))
- {
- res.append (count++ == 0 ? ", expecting " : " or ");
- res.append (yytnamerr_ (yytname_[x]));
- }
- }
- }
- return res.toString ();
- }
- }
-]])[
- return "syntax error";
- }
-
- /**
- * Whether the given <code>yypact_</code> value indicates a defaulted state.
- * @@param yyvalue the value to check
- */
- private static boolean yy_pact_value_is_default_ (int yyvalue)
- {
- return yyvalue == yypact_ninf_;
- }
-
- /**
- * Whether the given <code>yytable_</code>
- * value indicates a syntax error.
- * @@param yyvalue the value to check
- */
- private static boolean yy_table_value_is_error_ (int yyvalue)
- {
- return yyvalue == yytable_ninf_;
- }
-
- private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
- private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
-
- ]b4_parser_tables_define[
- ]b4_integral_parser_table_define([token_number], [b4_toknum],
- [[YYTOKEN_NUMBER[YYLEX-NUM] -- Internal symbol number corresponding
- to YYLEX-NUM.]])[
-
- /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at \a yyntokens_, nonterminals. */
- ]b4_typed_parser_table_define([String], [tname], [b4_tname])[
-
- ]b4_integral_parser_table_define([rline], [b4_rline],
- [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
-
-
- // Report on the debug stream that the rule yyrule is going to be reduced.
- private void yy_reduce_print (int yyrule, YYStack yystack)
- {
- if (yydebug == 0)
- return;
-
- int yylno = yyrline_[yyrule];
- int yynrhs = yyr2_[yyrule];
- /* Print the symbols being reduced, and their result. */
- yycdebug ("Reducing stack by rule " + (yyrule - 1)
- + " (line " + yylno + "), ");
-
- /* The symbols being reduced. */
- for (int yyi = 0; yyi < yynrhs; yyi++)
- yy_symbol_print (" $" + (yyi + 1) + " =",
- yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
- ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
- b4_rhs_location(yynrhs, yyi + 1)])[);
- }
-
- /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
- ]b4_integral_parser_table_define([translate_table], [b4_translate])[
-
- private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
- {
- if (t >= 0 && t <= yyuser_token_number_max_)
- return yytranslate_table_[t];
- else
- return yyundef_token_;
- }
-
- private static final int yylast_ = ]b4_last[;
- private static final int yynnts_ = ]b4_nterms_number[;
- private static final int yyempty_ = -2;
- private static final int yyfinal_ = ]b4_final_state_number[;
- private static final int yyterror_ = 1;
- private static final int yyerrcode_ = 256;
- private static final int yyntokens_ = ]b4_tokens_number[;
-
- private static final int yyuser_token_number_max_ = ]b4_user_token_number_max[;
- private static final int yyundef_token_ = ]b4_undef_token_number[;
-
-]/* User implementation code. */
-b4_percent_code_get[]dnl
-
-}
-
-b4_epilogue[]dnl
-b4_output_end()
+# Java skeleton for Bison -*- autoconf -*-
+
+# Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include(b4_pkgdatadir/[java.m4])
+
+b4_defines_if([b4_fatal([%s: %%defines does not make sense in Java],
+ [b4_skeleton])])
+
+# We do not depend on %debug in Java, but pacify warnings about
+# non-used flags.
+b4_parse_trace_if([0], [0])
+
+m4_define([b4_symbol_no_destructor_assert],
+[b4_symbol_if([$1], [has_destructor],
+ [b4_fatal([%s: %s: %%destructor does not make sense in Java],
+ [b4_skeleton],
+ [b4_symbol_action_location([$1], [destructor])])])])
+b4_symbol_foreach([b4_symbol_no_destructor_assert])
+
+# Setup some macros for api.push-pull.
+b4_percent_define_default([[api.push-pull]], [[pull]])
+b4_percent_define_check_values([[[[api.push-pull]],
+ [[pull]], [[push]], [[both]]]])
+
+# Define m4 conditional macros that encode the value
+# of the api.push-pull flag.
+b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]])
+b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]])
+m4_case(b4_percent_define_get([[api.push-pull]]),
+ [pull], [m4_define([b4_push_flag], [[0]])],
+ [push], [m4_define([b4_pull_flag], [[0]])])
+
+# Define a macro to be true when api.push-pull has the value "both".
+m4_define([b4_both_if],[b4_push_if([b4_pull_if([$1],[$2])],[$2])])
+
+# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing
+# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the
+# behavior of Bison at all when push parsing is already requested.
+b4_define_flag_if([use_push_for_pull])
+b4_use_push_for_pull_if([
+ b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])],
+ [m4_define([b4_push_flag], [[1]])])])
+
+# Define a macro to encapsulate the parse state variables.
+# This allows them to be defined either in parse() when doing
+# pull parsing, or as class instance variable when doing push parsing.
+m4_define([b4_define_state],[[
+ /* Lookahead and lookahead in internal form. */
+ int yychar = yyempty_;
+ int yytoken = 0;
+
+ /* State. */
+ int yyn = 0;
+ int yylen = 0;
+ int yystate = 0;
+ YYStack yystack = new YYStack ();
+ int label = YYNEWSTATE;
+
+ /* Error handling. */
+ int yynerrs_ = 0;
+ ]b4_locations_if([/* The location where the error started. */
+ b4_location_type yyerrloc = null;
+
+ /* Location. */
+ b4_location_type yylloc = new b4_location_type (null, null);])[
+
+ /* Semantic value of the lookahead. */
+ ]b4_yystype[ yylval = null;
+]])
+
+b4_output_begin([b4_parser_file_name])
+b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
+ [2007-2013])
+
+b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
+])[/* First part of user declarations. */
+]b4_user_pre_prologue
+b4_user_post_prologue
+b4_percent_code_get([[imports]])
+[/**
+ * A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
+ *
+ * @@author LALR (1) parser skeleton written by Paolo Bonzini.
+ */
+]b4_percent_define_get3([annotations], [], [ ])dnl
+b4_public_if([public ])dnl
+b4_abstract_if([abstract ])dnl
+b4_final_if([final ])dnl
+b4_strictfp_if([strictfp ])dnl
+[class ]b4_parser_class_name[]dnl
+b4_percent_define_get3([extends], [ extends ])dnl
+b4_percent_define_get3([implements], [ implements ])[
+{
+ ]b4_identification[
+]b4_error_verbose_if([[
+ /**
+ * True if verbose error messages are enabled.
+ */
+ private boolean yyErrorVerbose = true;
+
+ /**
+ * Return whether verbose error messages are enabled.
+ */
+ public final boolean getErrorVerbose() { return yyErrorVerbose; }
+
+ /**
+ * Set the verbosity of error messages.
+ * @@param verbose True to request verbose error messages.
+ */
+ public final void setErrorVerbose(boolean verbose)
+ { yyErrorVerbose = verbose; }
+]])
+
+b4_locations_if([[
+ /**
+ * A class defining a pair of positions. Positions, defined by the
+ * <code>]b4_position_type[</code> class, denote a point in the input.
+ * Locations represent a part of the input through the beginning
+ * and ending positions.
+ */
+ public class ]b4_location_type[ {
+ /**
+ * The first, inclusive, position in the range.
+ */
+ public ]b4_position_type[ begin;
+
+ /**
+ * The first position beyond the range.
+ */
+ public ]b4_position_type[ end;
+
+ /**
+ * Create a <code>]b4_location_type[</code> denoting an empty range located at
+ * a given point.
+ * @@param loc The position at which the range is anchored.
+ */
+ public ]b4_location_type[ (]b4_position_type[ loc) {
+ this.begin = this.end = loc;
+ }
+
+ /**
+ * Create a <code>]b4_location_type[</code> from the endpoints of the range.
+ * @@param begin The first position included in the range.
+ * @@param end The first position beyond the range.
+ */
+ public ]b4_location_type[ (]b4_position_type[ begin, ]b4_position_type[ end) {
+ this.begin = begin;
+ this.end = end;
+ }
+
+ /**
+ * Print a representation of the location. For this to be correct,
+ * <code>]b4_position_type[</code> should override the <code>equals</code>
+ * method.
+ */
+ public String toString () {
+ if (begin.equals (end))
+ return begin.toString ();
+ else
+ return begin.toString () + "-" + end.toString ();
+ }
+ }
+
+]])
+
+ b4_locations_if([[
+ private ]b4_location_type[ yylloc (YYStack rhs, int n)
+ {
+ if (n > 0)
+ return new ]b4_location_type[ (rhs.locationAt (n-1).begin, rhs.locationAt (0).end);
+ else
+ return new ]b4_location_type[ (rhs.locationAt (0).end);
+ }]])[
+
+ /**
+ * Communication interface between the scanner and the Bison-generated
+ * parser <tt>]b4_parser_class_name[</tt>.
+ */
+ public interface Lexer {
+ /** Token returned by the scanner to signal the end of its input. */
+ public static final int EOF = 0;
+
+]b4_token_enums[
+
+ ]b4_locations_if([[/**
+ * Method to retrieve the beginning position of the last scanned token.
+ * @@return the position at which the last scanned token starts.
+ */
+ ]b4_position_type[ getStartPos ();
+
+ /**
+ * Method to retrieve the ending position of the last scanned token.
+ * @@return the first position beyond the last scanned token.
+ */
+ ]b4_position_type[ getEndPos ();]])[
+
+ /**
+ * Method to retrieve the semantic value of the last scanned token.
+ * @@return the semantic value of the last scanned token.
+ */
+ ]b4_yystype[ getLVal ();
+
+ /**
+ * Entry point for the scanner. Returns the token identifier corresponding
+ * to the next token and prepares to return the semantic value
+ * ]b4_locations_if([and beginning/ending positions ])[of the token.
+ * @@return the token identifier corresponding to the next token.
+ */
+ int yylex () ]b4_maybe_throws([b4_lex_throws])[;
+
+ /**
+ * Entry point for error reporting. Emits an error
+ * ]b4_locations_if([referring to the given location ])[in a user-defined way.
+ *
+ * ]b4_locations_if([[@@param loc The location of the element to which the
+ * error message is related]])[
+ * @@param msg The string for the error message.
+ */
+ void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);]
+ }
+
+ b4_lexer_if([[private class YYLexer implements Lexer {
+]b4_percent_code_get([[lexer]])[
+ }
+
+ ]])[/**
+ * The object doing lexical analysis for us.
+ */
+ private Lexer yylexer;
+ ]
+ b4_parse_param_vars
+
+b4_lexer_if([[
+ /**
+ * Instantiates the Bison-generated parser.
+ */
+ public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) ]b4_maybe_throws([b4_init_throws])[
+ {
+ ]b4_percent_code_get([[init]])[
+ this.yylexer = new YYLexer(]b4_lex_param_call[);
+ ]b4_parse_param_cons[
+ }
+]])
+
+ /**
+ * Instantiates the Bison-generated parser.
+ * @@param yylexer The scanner that will supply tokens to the parser.
+ */
+ b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ (]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[
+ {
+ ]b4_percent_code_get([[init]])[
+ this.yylexer = yylexer;
+ ]b4_parse_param_cons[
+ }
+
+ private java.io.PrintStream yyDebugStream = System.err;
+
+ /**
+ * Return the <tt>PrintStream</tt> on which the debugging output is
+ * printed.
+ */
+ public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
+
+ /**
+ * Set the <tt>PrintStream</tt> on which the debug output is printed.
+ * @@param s The stream that is used for debugging output.
+ */
+ public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; }
+
+ private int yydebug = 0;
+
+ /**
+ * Answer the verbosity of the debugging output; 0 means that all kinds of
+ * output from the parser are suppressed.
+ */
+ public final int getDebugLevel() { return yydebug; }
+
+ /**
+ * Set the verbosity of the debugging output; 0 means that all kinds of
+ * output from the parser are suppressed.
+ * @@param level The verbosity level for debugging output.
+ */
+ public final void setDebugLevel(int level) { yydebug = level; }
+
+ /**
+ * Print an error message via the lexer.
+ *]b4_locations_if([[ Use a <code>null</code> location.]])[
+ * @@param msg The error message.
+ */
+ public final void yyerror (String msg)
+ {
+ yylexer.yyerror (]b4_locations_if([[(]b4_location_type[)null, ]])[msg);
+ }
+]b4_locations_if([[
+ /**
+ * Print an error message via the lexer.
+ * @@param loc The location associated with the message.
+ * @@param msg The error message.
+ */
+ public final void yyerror (]b4_location_type[ loc, String msg)
+ {
+ yylexer.yyerror (loc, msg);
+ }
+
+ /**
+ * Print an error message via the lexer.
+ * @@param pos The position associated with the message.
+ * @@param msg The error message.
+ */
+ public final void yyerror (]b4_position_type[ pos, String msg)
+ {
+ yylexer.yyerror (new ]b4_location_type[ (pos), msg);
+ }]])
+
+ [protected final void yycdebug (String s) {
+ if (yydebug > 0)
+ yyDebugStream.println (s);
+ }
+
+ private final class YYStack {
+ private int[] stateStack = new int[16];
+ ]b4_locations_if([[private ]b4_location_type[[] locStack = new ]b4_location_type[[16];]])[
+ private ]b4_yystype[[] valueStack = new ]b4_yystype[[16];
+
+ public int size = 16;
+ public int height = -1;
+
+ public final void push (int state, ]b4_yystype[ value]dnl
+ b4_locations_if([, ]b4_location_type[ loc])[) {
+ height++;
+ if (size == height)
+ {
+ int[] newStateStack = new int[size * 2];
+ System.arraycopy (stateStack, 0, newStateStack, 0, height);
+ stateStack = newStateStack;
+ ]b4_locations_if([[
+ ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
+ System.arraycopy (locStack, 0, newLocStack, 0, height);
+ locStack = newLocStack;]])
+
+ b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
+ System.arraycopy (valueStack, 0, newValueStack, 0, height);
+ valueStack = newValueStack;
+
+ size *= 2;
+ }
+
+ stateStack[height] = state;
+ ]b4_locations_if([[locStack[height] = loc;]])[
+ valueStack[height] = value;
+ }
+
+ public final void pop () {
+ pop (1);
+ }
+
+ public final void pop (int num) {
+ // Avoid memory leaks... garbage collection is a white lie!
+ if (num > 0) {
+ java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);
+ ]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
+ }
+ height -= num;
+ }
+
+ public final int stateAt (int i) {
+ return stateStack[height - i];
+ }
+
+ ]b4_locations_if([[public final ]b4_location_type[ locationAt (int i) {
+ return locStack[height - i];
+ }
+
+ ]])[public final ]b4_yystype[ valueAt (int i) {
+ return valueStack[height - i];
+ }
+
+ // Print the state stack on the debug stream.
+ public void print (java.io.PrintStream out)
+ {
+ out.print ("Stack now");
+
+ for (int i = 0; i <= height; i++)
+ {
+ out.print (' ');
+ out.print (stateStack[i]);
+ }
+ out.println ();
+ }
+ }
+
+ /**
+ * Returned by a Bison action in order to stop the parsing process and
+ * return success (<tt>true</tt>).
+ */
+ public static final int YYACCEPT = 0;
+
+ /**
+ * Returned by a Bison action in order to stop the parsing process and
+ * return failure (<tt>false</tt>).
+ */
+ public static final int YYABORT = 1;
+
+]b4_push_if([
+ /**
+ * Returned by a Bison action in order to request a new token.
+ */
+ public static final int YYPUSH_MORE = 4;])[
+
+ /**
+ * Returned by a Bison action in order to start error recovery without
+ * printing an error message.
+ */
+ public static final int YYERROR = 2;
+
+ /**
+ * Internal return codes that are not supported for user semantic
+ * actions.
+ */
+ private static final int YYERRLAB = 3;
+ private static final int YYNEWSTATE = 4;
+ private static final int YYDEFAULT = 5;
+ private static final int YYREDUCE = 6;
+ private static final int YYERRLAB1 = 7;
+ private static final int YYRETURN = 8;
+]b4_push_if([[ private static final int YYGETTOKEN = 9; /* Signify that a new token is expected when doing push-parsing. */]])[
+
+ private int yyerrstatus_ = 0;
+
+]b4_push_if([dnl
+b4_define_state])[
+ /**
+ * Return whether error recovery is being done. In this state, the parser
+ * reads token until it reaches a known state, and then restarts normal
+ * operation.
+ */
+ public final boolean recovering ()
+ {
+ return yyerrstatus_ == 0;
+ }
+
+ private int yyaction (int yyn, YYStack yystack, int yylen) ]b4_maybe_throws([b4_throws])[
+ {
+ ]b4_yystype[ yyval;
+ ]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ '$$ = $1'. Otherwise, use the top of the stack.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. */
+ if (yylen > 0)
+ yyval = yystack.valueAt (yylen - 1);
+ else
+ yyval = yystack.valueAt (0);
+
+ yy_reduce_print (yyn, yystack);
+
+ switch (yyn)
+ {
+ ]b4_user_actions[
+ default: break;
+ }
+
+ yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);
+
+ yystack.pop (yylen);
+ yylen = 0;
+
+ /* Shift the result of the reduction. */
+ yyn = yyr1_[yyn];
+ int yystate = yypgoto_[yyn - yyntokens_] + yystack.stateAt (0);
+ if (0 <= yystate && yystate <= yylast_
+ && yycheck_[yystate] == yystack.stateAt (0))
+ yystate = yytable_[yystate];
+ else
+ yystate = yydefgoto_[yyn - yyntokens_];
+
+ yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
+ return YYNEWSTATE;
+ }
+
+]b4_error_verbose_if([[
+ /* Return YYSTR after stripping away unnecessary quotes and
+ backslashes, so that it's suitable for yyerror. The heuristic is
+ that double-quoting is unnecessary unless the string contains an
+ apostrophe, a comma, or backslash (other than backslash-backslash).
+ YYSTR is taken from yytname. */
+ private final String yytnamerr_ (String yystr)
+ {
+ if (yystr.charAt (0) == '"')
+ {
+ StringBuffer yyr = new StringBuffer ();
+ strip_quotes: for (int i = 1; i < yystr.length (); i++)
+ switch (yystr.charAt (i))
+ {
+ case '\'':
+ case ',':
+ break strip_quotes;
+
+ case '\\':
+ if (yystr.charAt(++i) != '\\')
+ break strip_quotes;
+ /* Fall through. */
+ default:
+ yyr.append (yystr.charAt (i));
+ break;
+
+ case '"':
+ return yyr.toString ();
+ }
+ }
+ else if (yystr.equals ("$end"))
+ return "end of input";
+
+ return yystr;
+ }
+]])[
+
+ /*--------------------------------.
+ | Print this symbol on YYOUTPUT. |
+ `--------------------------------*/
+
+ private void yy_symbol_print (String s, int yytype,
+ ]b4_yystype[ yyvaluep]dnl
+ b4_locations_if([, Object yylocationp])[)
+ {
+ if (yydebug > 0)
+ yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
+ + yytname_[yytype] + " ("]b4_locations_if([
+ + yylocationp + ": "])[
+ + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
+ }
+
+]b4_push_if([],[[
+ /**
+ * Parse input from the scanner that was specified at object construction
+ * time. Return whether the end of the input was reached successfully.
+ *
+ * @@return <tt>true</tt> if the parsing succeeds. Note that this does not
+ * imply that there were no syntax errors.
+ */
+ public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[]])[
+]b4_push_if([
+ /**
+ * Push Parse input from external lexer
+ *
+ * @@param yylextoken current token
+ * @@param yylexval current lval
+]b4_locations_if([ * @@param yylexloc current position])[
+ *
+ * @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
+ */
+ public int push_parse (int yylextoken, b4_yystype yylexval[]b4_locations_if([, b4_location_type yylexloc]))
+ b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])])[
+ {
+ ]b4_locations_if([/* @@$. */
+ b4_location_type yyloc;])[
+]b4_push_if([],[[
+]b4_define_state[
+ yycdebug ("Starting parse\n");
+ yyerrstatus_ = 0;
+
+ /* Initialize the stack. */
+ yystack.push (yystate, yylval ]b4_locations_if([, yylloc])[);
+]m4_ifdef([b4_initial_action], [
+b4_dollar_pushdef([yylval], [], [yylloc])dnl
+ /* User initialization code. */
+ b4_user_initial_action
+b4_dollar_popdef[]dnl
+])[
+]])[
+]b4_push_if([[
+ if (!this.push_parse_initialized)
+ {
+ push_parse_initialize ();
+]m4_ifdef([b4_initial_action], [
+b4_dollar_pushdef([yylval], [], [yylloc])dnl
+ /* User initialization code. */
+ b4_user_initial_action
+b4_dollar_popdef[]dnl
+])[
+ yycdebug ("Starting parse\n");
+ yyerrstatus_ = 0;
+ } else
+ label = YYGETTOKEN;
+
+ boolean push_token_consumed = true;
+]])[
+ for (;;)
+ switch (label)
+ {
+ /* New state. Unlike in the C/C++ skeletons, the state is already
+ pushed when we come here. */
+ case YYNEWSTATE:
+ yycdebug ("Entering state " + yystate + "\n");
+ if (yydebug > 0)
+ yystack.print (yyDebugStream);
+
+ /* Accept? */
+ if (yystate == yyfinal_)
+ ]b4_push_if([{label = YYACCEPT; break;}],
+ [return true;])[
+
+ /* Take a decision. First try without lookahead. */
+ yyn = yypact_[yystate];
+ if (yy_pact_value_is_default_ (yyn))
+ {
+ label = YYDEFAULT;
+ break;
+ }
+]b4_push_if([ /* Fall Through */
+
+ case YYGETTOKEN:])[
+ /* Read a lookahead token. */
+ if (yychar == yyempty_)
+ {
+]b4_push_if([[
+ if (!push_token_consumed)
+ return YYPUSH_MORE;
+ yycdebug ("Reading a token: ");
+ yychar = yylextoken;
+ yylval = yylexval;]b4_locations_if([
+ yylloc = yylexloc;])[
+ push_token_consumed = false;]])[
+]b4_push_if([],[[
+ yycdebug ("Reading a token: ");
+ yychar = yylexer.yylex ();
+ yylval = yylexer.getLVal ();]b4_locations_if([
+ yylloc = new b4_location_type (yylexer.getStartPos (),
+ yylexer.getEndPos ());])[
+]])[
+ }
+
+ /* Convert token to internal form. */
+ if (yychar <= Lexer.EOF)
+ {
+ yychar = yytoken = Lexer.EOF;
+ yycdebug ("Now at end of input.\n");
+ }
+ else
+ {
+ yytoken = yytranslate_ (yychar);
+ yy_symbol_print ("Next token is", yytoken,
+ yylval]b4_locations_if([, yylloc])[);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
+ label = YYDEFAULT;
+
+ /* <= 0 means reduce or error. */
+ else if ((yyn = yytable_[yyn]) <= 0)
+ {
+ if (yy_table_value_is_error_ (yyn))
+ label = YYERRLAB;
+ else
+ {
+ yyn = -yyn;
+ label = YYREDUCE;
+ }
+ }
+
+ else
+ {
+ /* Shift the lookahead token. */
+ yy_symbol_print ("Shifting", yytoken,
+ yylval]b4_locations_if([, yylloc])[);
+
+ /* Discard the token being shifted. */
+ yychar = yyempty_;
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus_ > 0)
+ --yyerrstatus_;
+
+ yystate = yyn;
+ yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
+ label = YYNEWSTATE;
+ }
+ break;
+
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state. |
+ `-----------------------------------------------------------*/
+ case YYDEFAULT:
+ yyn = yydefact_[yystate];
+ if (yyn == 0)
+ label = YYERRLAB;
+ else
+ label = YYREDUCE;
+ break;
+
+ /*-----------------------------.
+ | yyreduce -- Do a reduction. |
+ `-----------------------------*/
+ case YYREDUCE:
+ yylen = yyr2_[yyn];
+ label = yyaction (yyn, yystack, yylen);
+ yystate = yystack.stateAt (0);
+ break;
+
+ /*------------------------------------.
+ | yyerrlab -- here on detecting error |
+ `------------------------------------*/
+ case YYERRLAB:
+ /* If not already recovering from an error, report this error. */
+ if (yyerrstatus_ == 0)
+ {
+ ++yynerrs_;
+ if (yychar == yyempty_)
+ yytoken = yyempty_;
+ yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
+ }
+
+ ]b4_locations_if([yyerrloc = yylloc;])[
+ if (yyerrstatus_ == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= Lexer.EOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == Lexer.EOF)
+ ]b4_push_if([{label = YYABORT; break;}],[return false;])[
+ }
+ else
+ yychar = yyempty_;
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ label = YYERRLAB1;
+ break;
+
+ /*-------------------------------------------------.
+ | errorlab -- error raised explicitly by YYERROR. |
+ `-------------------------------------------------*/
+ case YYERROR:
+
+ ]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ yystack.pop (yylen);
+ yylen = 0;
+ yystate = yystack.stateAt (0);
+ label = YYERRLAB1;
+ break;
+
+ /*-------------------------------------------------------------.
+ | yyerrlab1 -- common code for both syntax error and YYERROR. |
+ `-------------------------------------------------------------*/
+ case YYERRLAB1:
+ yyerrstatus_ = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact_[yystate];
+ if (!yy_pact_value_is_default_ (yyn))
+ {
+ yyn += yyterror_;
+ if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
+ {
+ yyn = yytable_[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the
+ * error token. */
+ if (yystack.height == 0)
+ ]b4_push_if([{label = YYABORT; break;}],[return false;])[
+
+ ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
+ yystack.pop ();
+ yystate = yystack.stateAt (0);
+ if (yydebug > 0)
+ yystack.print (yyDebugStream);
+ }
+
+ if (label == YYABORT)
+ /* Leave the switch. */
+ break;
+
+]b4_locations_if([
+ /* Muck with the stack to setup for yylloc. */
+ yystack.push (0, null, yylloc);
+ yystack.push (0, null, yyerrloc);
+ yyloc = yylloc (yystack, 2);
+ yystack.pop (2);])[
+
+ /* Shift the error token. */
+ yy_symbol_print ("Shifting", yystos_[yyn],
+ yylval]b4_locations_if([, yyloc])[);
+
+ yystate = yyn;
+ yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
+ label = YYNEWSTATE;
+ break;
+
+ /* Accept. */
+ case YYACCEPT:
+ ]b4_push_if([this.push_parse_initialized = false; return YYACCEPT;],
+ [return true;])[
+
+ /* Abort. */
+ case YYABORT:
+ ]b4_push_if([this.push_parse_initialized = false; return YYABORT;],
+ [return false;])[
+ }
+}
+]b4_push_if([[
+ boolean push_parse_initialized = false;
+
+ /**
+ * (Re-)Initialize the state of the push parser.
+ */
+ public void push_parse_initialize()
+ {
+ /* Lookahead and lookahead in internal form. */
+ this.yychar = yyempty_;
+ this.yytoken = 0;
+
+ /* State. */
+ this.yyn = 0;
+ this.yylen = 0;
+ this.yystate = 0;
+ this.yystack = new YYStack ();
+ this.label = YYNEWSTATE;
+
+ /* Error handling. */
+ this.yynerrs_ = 0;
+ ]b4_locations_if([/* The location where the error started. */
+ this.yyerrloc = null;
+ this.yylloc = new b4_location_type (null, null);])[
+
+ /* Semantic value of the lookahead. */
+ this.yylval = null;
+
+ yystack.push (this.yystate, this.yylval]b4_locations_if([, this.yylloc])[);
+
+ this.push_parse_initialized = true;
+
+ }
+]b4_locations_if([
+ /**
+ * Push parse given input from an external lexer.
+ *
+ * @@param yylextoken current token
+ * @@param yylexval current lval
+ * @@param yyylexpos current position
+ *
+ * @@return <tt>YYACCEPT, YYABORT, YYPUSH_MORE</tt>
+ */
+ public int push_parse (int yylextoken, b4_yystype yylexval, b4_position_type yylexpos)
+ b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])
+ {
+ return push_parse (yylextoken, yylexval, new b4_location_type (yylexpos));
+ }
+])[]])
+
+b4_both_if([[
+ /**
+ * Parse input from the scanner that was specified at object construction
+ * time. Return whether the end of the input was reached successfully.
+ * This version of parse () is defined only when api.push-push=both.
+ *
+ * @@return <tt>true</tt> if the parsing succeeds. Note that this does not
+ * imply that there were no syntax errors.
+ */
+ public boolean parse () ]b4_maybe_throws([b4_list2([b4_lex_throws], [b4_throws])])[
+ {
+ if (yylexer == null)
+ throw new NullPointerException("Null Lexer");
+ int status;
+ do {
+ int token = yylexer.yylex();
+ ]b4_yystype[ lval = yylexer.getLVal();
+]b4_locations_if([dnl
+ b4_location_type yyloc = new b4_location_type (yylexer.getStartPos (),
+ yylexer.getEndPos ());])[
+ ]b4_locations_if([status = push_parse(token,lval,yyloc);],[
+ status = push_parse(token,lval);])[
+ } while (status == YYPUSH_MORE);
+ return (status == YYACCEPT);
+ }
+]])[
+
+ // Generate an error message.
+ private String yysyntax_error (int yystate, int tok)
+ {]b4_error_verbose_if([[
+ if (yyErrorVerbose)
+ {
+ /* There are many possibilities here to consider:
+ - If this state is a consistent state with a default action,
+ then the only way this function was invoked is if the
+ default action is an error action. In that case, don't
+ check for expected tokens because there are none.
+ - The only way there can be no lookahead present (in tok) is
+ if this state is a consistent state with a default action.
+ Thus, detecting the absence of a lookahead is sufficient to
+ determine that there is no unexpected or expected token to
+ report. In that case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this
+ state is a consistent state with a default action. There
+ might have been a previous inconsistent state, consistent
+ state with a non-default action, or user semantic action
+ that manipulated yychar. (However, yychar is currently out
+ of scope during semantic actions.)
+ - Of course, the expected token list depends on states to
+ have correct lookahead information, and it depends on the
+ parser not to perform extra reductions after fetching a
+ lookahead from the scanner and before detecting a syntax
+ error. Thus, state merging (from LALR or IELR) and default
+ reductions corrupt the expected token list. However, the
+ list is correct for canonical LR with one exception: it
+ will still contain any token that will not be accepted due
+ to an error action in a later state.
+ */
+ if (tok != yyempty_)
+ {
+ /* FIXME: This method of building the message is not compatible
+ with internationalization. */
+ StringBuffer res =
+ new StringBuffer ("syntax error, unexpected ");
+ res.append (yytnamerr_ (yytname_[tok]));
+ int yyn = yypact_[yystate];
+ if (!yy_pact_value_is_default_ (yyn))
+ {
+ /* Start YYX at -YYN if negative to avoid negative
+ indexes in YYCHECK. In other words, skip the first
+ -YYN actions for this state because they are default
+ actions. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = yylast_ - yyn + 1;
+ int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
+ int count = 0;
+ for (int x = yyxbegin; x < yyxend; ++x)
+ if (yycheck_[x + yyn] == x && x != yyterror_
+ && !yy_table_value_is_error_ (yytable_[x + yyn]))
+ ++count;
+ if (count < 5)
+ {
+ count = 0;
+ for (int x = yyxbegin; x < yyxend; ++x)
+ if (yycheck_[x + yyn] == x && x != yyterror_
+ && !yy_table_value_is_error_ (yytable_[x + yyn]))
+ {
+ res.append (count++ == 0 ? ", expecting " : " or ");
+ res.append (yytnamerr_ (yytname_[x]));
+ }
+ }
+ }
+ return res.toString ();
+ }
+ }
+]])[
+ return "syntax error";
+ }
+
+ /**
+ * Whether the given <code>yypact_</code> value indicates a defaulted state.
+ * @@param yyvalue the value to check
+ */
+ private static boolean yy_pact_value_is_default_ (int yyvalue)
+ {
+ return yyvalue == yypact_ninf_;
+ }
+
+ /**
+ * Whether the given <code>yytable_</code>
+ * value indicates a syntax error.
+ * @@param yyvalue the value to check
+ */
+ private static boolean yy_table_value_is_error_ (int yyvalue)
+ {
+ return yyvalue == yytable_ninf_;
+ }
+
+ private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
+ private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
+
+ ]b4_parser_tables_define[
+ ]b4_integral_parser_table_define([token_number], [b4_toknum],
+ [[YYTOKEN_NUMBER[YYLEX-NUM] -- Internal symbol number corresponding
+ to YYLEX-NUM.]])[
+
+ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at \a yyntokens_, nonterminals. */
+ ]b4_typed_parser_table_define([String], [tname], [b4_tname])[
+
+ ]b4_integral_parser_table_define([rline], [b4_rline],
+ [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
+
+
+ // Report on the debug stream that the rule yyrule is going to be reduced.
+ private void yy_reduce_print (int yyrule, YYStack yystack)
+ {
+ if (yydebug == 0)
+ return;
+
+ int yylno = yyrline_[yyrule];
+ int yynrhs = yyr2_[yyrule];
+ /* Print the symbols being reduced, and their result. */
+ yycdebug ("Reducing stack by rule " + (yyrule - 1)
+ + " (line " + yylno + "), ");
+
+ /* The symbols being reduced. */
+ for (int yyi = 0; yyi < yynrhs; yyi++)
+ yy_symbol_print (" $" + (yyi + 1) + " =",
+ yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
+ ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
+ b4_rhs_location(yynrhs, yyi + 1)])[);
+ }
+
+ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+ ]b4_integral_parser_table_define([translate_table], [b4_translate])[
+
+ private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
+ {
+ if (t >= 0 && t <= yyuser_token_number_max_)
+ return yytranslate_table_[t];
+ else
+ return yyundef_token_;
+ }
+
+ private static final int yylast_ = ]b4_last[;
+ private static final int yynnts_ = ]b4_nterms_number[;
+ private static final int yyempty_ = -2;
+ private static final int yyfinal_ = ]b4_final_state_number[;
+ private static final int yyterror_ = 1;
+ private static final int yyerrcode_ = 256;
+ private static final int yyntokens_ = ]b4_tokens_number[;
+
+ private static final int yyuser_token_number_max_ = ]b4_user_token_number_max[;
+ private static final int yyundef_token_ = ]b4_undef_token_number[;
+
+]/* User implementation code. */
+b4_percent_code_get[]dnl
+
+}
+
+b4_epilogue[]dnl
+b4_output_end()
diff --git a/contrib/tools/bison/bison/data/local.mk b/contrib/tools/bison/bison/data/local.mk
index b8290522f2..cdf09b68de 100644
--- a/contrib/tools/bison/bison/data/local.mk
+++ b/contrib/tools/bison/bison/data/local.mk
@@ -1,45 +1,45 @@
-## Copyright (C) 2002, 2005-2013 Free Software Foundation, Inc.
-
-## This program is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-dist_pkgdata_DATA = \
- data/README \
- data/bison.m4 \
- data/c++-skel.m4 \
- data/c++.m4 \
- data/c-like.m4 \
- data/c-skel.m4 \
- data/c.m4 \
- data/glr.c \
- data/glr.cc \
- data/java-skel.m4 \
- data/java.m4 \
- data/lalr1.cc \
- data/lalr1.java \
- data/location.cc \
- data/stack.hh \
- data/variant.hh \
- data/yacc.c
-
-m4sugardir = $(pkgdatadir)/m4sugar
-dist_m4sugar_DATA = \
- data/m4sugar/foreach.m4 \
- data/m4sugar/m4sugar.m4
-
-xsltdir = $(pkgdatadir)/xslt
-dist_xslt_DATA = \
- data/xslt/bison.xsl \
- data/xslt/xml2dot.xsl \
- data/xslt/xml2text.xsl \
- data/xslt/xml2xhtml.xsl
+## Copyright (C) 2002, 2005-2013 Free Software Foundation, Inc.
+
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+dist_pkgdata_DATA = \
+ data/README \
+ data/bison.m4 \
+ data/c++-skel.m4 \
+ data/c++.m4 \
+ data/c-like.m4 \
+ data/c-skel.m4 \
+ data/c.m4 \
+ data/glr.c \
+ data/glr.cc \
+ data/java-skel.m4 \
+ data/java.m4 \
+ data/lalr1.cc \
+ data/lalr1.java \
+ data/location.cc \
+ data/stack.hh \
+ data/variant.hh \
+ data/yacc.c
+
+m4sugardir = $(pkgdatadir)/m4sugar
+dist_m4sugar_DATA = \
+ data/m4sugar/foreach.m4 \
+ data/m4sugar/m4sugar.m4
+
+xsltdir = $(pkgdatadir)/xslt
+dist_xslt_DATA = \
+ data/xslt/bison.xsl \
+ data/xslt/xml2dot.xsl \
+ data/xslt/xml2text.xsl \
+ data/xslt/xml2xhtml.xsl
diff --git a/contrib/tools/bison/bison/data/location.cc b/contrib/tools/bison/bison/data/location.cc
index 9a60f2503f..e98077b074 100644
--- a/contrib/tools/bison/bison/data/location.cc
+++ b/contrib/tools/bison/bison/data/location.cc
@@ -1,335 +1,335 @@
-# C++ skeleton for Bison
-
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-m4_pushdef([b4_copyright_years],
- [2002-2013])
-
-# b4_position_define
-# ------------------
-# Define class position.
-m4_define([b4_position_define],
-[[ /// Abstract a position.
- class position
- {
- public:]m4_ifdef([b4_location_constructors], [[
- /// Construct a position.
- explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULL,
- unsigned int l = ]b4_location_initial_line[u,
- unsigned int c = ]b4_location_initial_column[u)
- : filename (f)
- , line (l)
- , column (c)
- {
- }
-
-]])[
- /// Initialization.
- void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULL,
- unsigned int l = ]b4_location_initial_line[u,
- unsigned int c = ]b4_location_initial_column[u)
- {
- filename = fn;
- line = l;
- column = c;
- }
-
- /** \name Line and Column related manipulators
- ** \{ */
- /// (line related) Advance to the COUNT next lines.
- void lines (int count = 1)
- {
- if (count)
- {
- column = ]b4_location_initial_column[u;
- line = add_ (line, count, ]b4_location_initial_line[);
- }
- }
-
- /// (column related) Advance to the COUNT next columns.
- void columns (int count = 1)
- {
- column = add_ (column, count, ]b4_location_initial_column[);
- }
- /** \} */
-
- /// File name to which this position refers.
- ]b4_percent_define_get([[filename_type]])[* filename;
- /// Current line number.
- unsigned int line;
- /// Current column number.
- unsigned int column;
-
- private:
- /// Compute max(min, lhs+rhs) (provided min <= lhs).
- static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
- {
- return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
- ? rhs + lhs
- : min);
- }
- };
-
- /// Add and assign a position.
- inline position&
- operator+= (position& res, int width)
- {
- res.columns (width);
- return res;
- }
-
- /// Add two position objects.
- inline position
- operator+ (position res, int width)
- {
- return res += width;
- }
-
- /// Add and assign a position.
- inline position&
- operator-= (position& res, int width)
- {
- return res += -width;
- }
-
- /// Add two position objects.
- inline position
- operator- (position res, int width)
- {
- return res -= width;
- }
-]b4_percent_define_flag_if([[define_location_comparison]], [[
- /// Compare two position objects.
- inline bool
- operator== (const position& pos1, const position& pos2)
- {
- return (pos1.line == pos2.line
- && pos1.column == pos2.column
- && (pos1.filename == pos2.filename
- || (pos1.filename && pos2.filename
- && *pos1.filename == *pos2.filename)));
- }
-
- /// Compare two position objects.
- inline bool
- operator!= (const position& pos1, const position& pos2)
- {
- return !(pos1 == pos2);
- }
-]])[
- /** \brief Intercept output stream redirection.
- ** \param ostr the destination output stream
- ** \param pos a reference to the position to redirect
- */
- template <typename YYChar>
- inline std::basic_ostream<YYChar>&
- operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
- {
- if (pos.filename)
- ostr << *pos.filename << ':';
- return ostr << pos.line << '.' << pos.column;
- }
-]])
-
-
-# b4_location_define
-# ------------------
-m4_define([b4_location_define],
-[[ /// Abstract a location.
- class location
- {
- public:
-]m4_ifdef([b4_location_constructors], [
- /// Construct a location from \a b to \a e.
- location (const position& b, const position& e)
- : begin (b)
- , end (e)
- {
- }
-
- /// Construct a 0-width location in \a p.
- explicit location (const position& p = position ())
- : begin (p)
- , end (p)
- {
- }
-
- /// Construct a 0-width location in \a f, \a l, \a c.
- explicit location (]b4_percent_define_get([[filename_type]])[* f,
- unsigned int l = ]b4_location_initial_line[u,
- unsigned int c = ]b4_location_initial_column[u)
- : begin (f, l, c)
- , end (f, l, c)
- {
- }
-
-])[
- /// Initialization.
- void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULL,
- unsigned int l = ]b4_location_initial_line[u,
- unsigned int c = ]b4_location_initial_column[u)
- {
- begin.initialize (f, l, c);
- end = begin;
- }
-
- /** \name Line and Column related manipulators
- ** \{ */
- public:
- /// Reset initial location to final location.
- void step ()
- {
- begin = end;
- }
-
- /// Extend the current location to the COUNT next columns.
- void columns (int count = 1)
- {
- end += count;
- }
-
- /// Extend the current location to the COUNT next lines.
- void lines (int count = 1)
- {
- end.lines (count);
- }
- /** \} */
-
-
- public:
- /// Beginning of the located region.
- position begin;
- /// End of the located region.
- position end;
- };
-
- /// Join two location objects to create a location.
- inline location operator+ (location res, const location& end)
- {
- res.end = end.end;
- return res;
- }
-
- /// Change end position in place.
- inline location& operator+= (location& res, int width)
- {
- res.columns (width);
- return res;
- }
-
- /// Change end position.
- inline location operator+ (location res, int width)
- {
- return res += width;
- }
-
- /// Change end position in place.
- inline location& operator-= (location& res, int width)
- {
- return res += -width;
- }
-
- /// Change end position.
- inline location operator- (const location& begin, int width)
- {
- return begin + -width;
- }
-]b4_percent_define_flag_if([[define_location_comparison]], [[
- /// Compare two location objects.
- inline bool
- operator== (const location& loc1, const location& loc2)
- {
- return loc1.begin == loc2.begin && loc1.end == loc2.end;
- }
-
- /// Compare two location objects.
- inline bool
- operator!= (const location& loc1, const location& loc2)
- {
- return !(loc1 == loc2);
- }
-]])[
- /** \brief Intercept output stream redirection.
- ** \param ostr the destination output stream
- ** \param loc a reference to the location to redirect
- **
- ** Avoid duplicate information.
- */
- template <typename YYChar>
- inline std::basic_ostream<YYChar>&
- operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
- {
- unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
- ostr << loc.begin// << "(" << loc.end << ") "
-;
- if (loc.end.filename
- && (!loc.begin.filename
- || *loc.begin.filename != *loc.end.filename))
- ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
- else if (loc.begin.line < loc.end.line)
- ostr << '-' << loc.end.line << '.' << end_col;
- else if (loc.begin.column < end_col)
- ostr << '-' << end_col;
- return ostr;
- }
-]])
-
-
-b4_defines_if([
-b4_output_begin([b4_dir_prefix[]position.hh])
-b4_copyright([Positions for Bison parsers in C++])[
-
-/**
- ** \file ]b4_dir_prefix[position.hh
- ** Define the ]b4_namespace_ref[::position class.
- */
-
-]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[
-
-# include <algorithm> // std::max
-# include <iostream>
-# include <string>
-
-]b4_null_define[
-
-]b4_namespace_open[
-]b4_position_define[
-]b4_namespace_close[
-]b4_cpp_guard_close([b4_dir_prefix[]position.hh])
-b4_output_end()
-
-
-b4_output_begin([b4_dir_prefix[]location.hh])
-b4_copyright([Locations for Bison parsers in C++])[
-
-/**
- ** \file ]b4_dir_prefix[location.hh
- ** Define the ]b4_namespace_ref[::location class.
- */
-
-]b4_cpp_guard_open([b4_dir_prefix[]location.hh])[
-
-# include "position.hh"
-
-]b4_namespace_open[
-]b4_location_define[
-]b4_namespace_close[
-]b4_cpp_guard_close([b4_dir_prefix[]location.hh])
-b4_output_end()
-])
-
-
-m4_popdef([b4_copyright_years])
+# C++ skeleton for Bison
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([b4_copyright_years],
+ [2002-2013])
+
+# b4_position_define
+# ------------------
+# Define class position.
+m4_define([b4_position_define],
+[[ /// Abstract a position.
+ class position
+ {
+ public:]m4_ifdef([b4_location_constructors], [[
+ /// Construct a position.
+ explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULL,
+ unsigned int l = ]b4_location_initial_line[u,
+ unsigned int c = ]b4_location_initial_column[u)
+ : filename (f)
+ , line (l)
+ , column (c)
+ {
+ }
+
+]])[
+ /// Initialization.
+ void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULL,
+ unsigned int l = ]b4_location_initial_line[u,
+ unsigned int c = ]b4_location_initial_column[u)
+ {
+ filename = fn;
+ line = l;
+ column = c;
+ }
+
+ /** \name Line and Column related manipulators
+ ** \{ */
+ /// (line related) Advance to the COUNT next lines.
+ void lines (int count = 1)
+ {
+ if (count)
+ {
+ column = ]b4_location_initial_column[u;
+ line = add_ (line, count, ]b4_location_initial_line[);
+ }
+ }
+
+ /// (column related) Advance to the COUNT next columns.
+ void columns (int count = 1)
+ {
+ column = add_ (column, count, ]b4_location_initial_column[);
+ }
+ /** \} */
+
+ /// File name to which this position refers.
+ ]b4_percent_define_get([[filename_type]])[* filename;
+ /// Current line number.
+ unsigned int line;
+ /// Current column number.
+ unsigned int column;
+
+ private:
+ /// Compute max(min, lhs+rhs) (provided min <= lhs).
+ static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
+ {
+ return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
+ ? rhs + lhs
+ : min);
+ }
+ };
+
+ /// Add and assign a position.
+ inline position&
+ operator+= (position& res, int width)
+ {
+ res.columns (width);
+ return res;
+ }
+
+ /// Add two position objects.
+ inline position
+ operator+ (position res, int width)
+ {
+ return res += width;
+ }
+
+ /// Add and assign a position.
+ inline position&
+ operator-= (position& res, int width)
+ {
+ return res += -width;
+ }
+
+ /// Add two position objects.
+ inline position
+ operator- (position res, int width)
+ {
+ return res -= width;
+ }
+]b4_percent_define_flag_if([[define_location_comparison]], [[
+ /// Compare two position objects.
+ inline bool
+ operator== (const position& pos1, const position& pos2)
+ {
+ return (pos1.line == pos2.line
+ && pos1.column == pos2.column
+ && (pos1.filename == pos2.filename
+ || (pos1.filename && pos2.filename
+ && *pos1.filename == *pos2.filename)));
+ }
+
+ /// Compare two position objects.
+ inline bool
+ operator!= (const position& pos1, const position& pos2)
+ {
+ return !(pos1 == pos2);
+ }
+]])[
+ /** \brief Intercept output stream redirection.
+ ** \param ostr the destination output stream
+ ** \param pos a reference to the position to redirect
+ */
+ template <typename YYChar>
+ inline std::basic_ostream<YYChar>&
+ operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
+ {
+ if (pos.filename)
+ ostr << *pos.filename << ':';
+ return ostr << pos.line << '.' << pos.column;
+ }
+]])
+
+
+# b4_location_define
+# ------------------
+m4_define([b4_location_define],
+[[ /// Abstract a location.
+ class location
+ {
+ public:
+]m4_ifdef([b4_location_constructors], [
+ /// Construct a location from \a b to \a e.
+ location (const position& b, const position& e)
+ : begin (b)
+ , end (e)
+ {
+ }
+
+ /// Construct a 0-width location in \a p.
+ explicit location (const position& p = position ())
+ : begin (p)
+ , end (p)
+ {
+ }
+
+ /// Construct a 0-width location in \a f, \a l, \a c.
+ explicit location (]b4_percent_define_get([[filename_type]])[* f,
+ unsigned int l = ]b4_location_initial_line[u,
+ unsigned int c = ]b4_location_initial_column[u)
+ : begin (f, l, c)
+ , end (f, l, c)
+ {
+ }
+
+])[
+ /// Initialization.
+ void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULL,
+ unsigned int l = ]b4_location_initial_line[u,
+ unsigned int c = ]b4_location_initial_column[u)
+ {
+ begin.initialize (f, l, c);
+ end = begin;
+ }
+
+ /** \name Line and Column related manipulators
+ ** \{ */
+ public:
+ /// Reset initial location to final location.
+ void step ()
+ {
+ begin = end;
+ }
+
+ /// Extend the current location to the COUNT next columns.
+ void columns (int count = 1)
+ {
+ end += count;
+ }
+
+ /// Extend the current location to the COUNT next lines.
+ void lines (int count = 1)
+ {
+ end.lines (count);
+ }
+ /** \} */
+
+
+ public:
+ /// Beginning of the located region.
+ position begin;
+ /// End of the located region.
+ position end;
+ };
+
+ /// Join two location objects to create a location.
+ inline location operator+ (location res, const location& end)
+ {
+ res.end = end.end;
+ return res;
+ }
+
+ /// Change end position in place.
+ inline location& operator+= (location& res, int width)
+ {
+ res.columns (width);
+ return res;
+ }
+
+ /// Change end position.
+ inline location operator+ (location res, int width)
+ {
+ return res += width;
+ }
+
+ /// Change end position in place.
+ inline location& operator-= (location& res, int width)
+ {
+ return res += -width;
+ }
+
+ /// Change end position.
+ inline location operator- (const location& begin, int width)
+ {
+ return begin + -width;
+ }
+]b4_percent_define_flag_if([[define_location_comparison]], [[
+ /// Compare two location objects.
+ inline bool
+ operator== (const location& loc1, const location& loc2)
+ {
+ return loc1.begin == loc2.begin && loc1.end == loc2.end;
+ }
+
+ /// Compare two location objects.
+ inline bool
+ operator!= (const location& loc1, const location& loc2)
+ {
+ return !(loc1 == loc2);
+ }
+]])[
+ /** \brief Intercept output stream redirection.
+ ** \param ostr the destination output stream
+ ** \param loc a reference to the location to redirect
+ **
+ ** Avoid duplicate information.
+ */
+ template <typename YYChar>
+ inline std::basic_ostream<YYChar>&
+ operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
+ {
+ unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
+ ostr << loc.begin// << "(" << loc.end << ") "
+;
+ if (loc.end.filename
+ && (!loc.begin.filename
+ || *loc.begin.filename != *loc.end.filename))
+ ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
+ else if (loc.begin.line < loc.end.line)
+ ostr << '-' << loc.end.line << '.' << end_col;
+ else if (loc.begin.column < end_col)
+ ostr << '-' << end_col;
+ return ostr;
+ }
+]])
+
+
+b4_defines_if([
+b4_output_begin([b4_dir_prefix[]position.hh])
+b4_copyright([Positions for Bison parsers in C++])[
+
+/**
+ ** \file ]b4_dir_prefix[position.hh
+ ** Define the ]b4_namespace_ref[::position class.
+ */
+
+]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[
+
+# include <algorithm> // std::max
+# include <iostream>
+# include <string>
+
+]b4_null_define[
+
+]b4_namespace_open[
+]b4_position_define[
+]b4_namespace_close[
+]b4_cpp_guard_close([b4_dir_prefix[]position.hh])
+b4_output_end()
+
+
+b4_output_begin([b4_dir_prefix[]location.hh])
+b4_copyright([Locations for Bison parsers in C++])[
+
+/**
+ ** \file ]b4_dir_prefix[location.hh
+ ** Define the ]b4_namespace_ref[::location class.
+ */
+
+]b4_cpp_guard_open([b4_dir_prefix[]location.hh])[
+
+# include "position.hh"
+
+]b4_namespace_open[
+]b4_location_define[
+]b4_namespace_close[
+]b4_cpp_guard_close([b4_dir_prefix[]location.hh])
+b4_output_end()
+])
+
+
+m4_popdef([b4_copyright_years])
diff --git a/contrib/tools/bison/bison/data/m4sugar/foreach.m4 b/contrib/tools/bison/bison/data/m4sugar/foreach.m4
index f6a6394472..81048664e2 100644
--- a/contrib/tools/bison/bison/data/m4sugar/foreach.m4
+++ b/contrib/tools/bison/bison/data/m4sugar/foreach.m4
@@ -1,362 +1,362 @@
-# -*- Autoconf -*-
-# This file is part of Autoconf.
-# foreach-based replacements for recursive functions.
-# Speeds up GNU M4 1.4.x by avoiding quadratic $@ recursion, but penalizes
-# GNU M4 1.6 by requiring more memory and macro expansions.
-#
-# Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
-# This file is part of Autoconf. This program is free
-# software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# Under Section 7 of GPL version 3, you are granted additional
-# permissions described in the Autoconf Configure Script Exception,
-# version 3.0, as published by the Free Software Foundation.
-#
-# You should have received a copy of the GNU General Public License
-# and a copy of the Autoconf Configure Script Exception along with
-# this program; see the files COPYINGv3 and COPYING.EXCEPTION
-# respectively. If not, see <http://www.gnu.org/licenses/>.
-
-# Written by Eric Blake.
-
-# In M4 1.4.x, every byte of $@ is rescanned. This means that an
-# algorithm on n arguments that recurses with one less argument each
-# iteration will scan n * (n + 1) / 2 arguments, for O(n^2) time. In
-# M4 1.6, this was fixed so that $@ is only scanned once, then
-# back-references are made to information stored about the scan.
-# Thus, n iterations need only scan n arguments, for O(n) time.
-# Additionally, in M4 1.4.x, recursive algorithms did not clean up
-# memory very well, requiring O(n^2) memory rather than O(n) for n
-# iterations.
-#
-# This file is designed to overcome the quadratic nature of $@
-# recursion by writing a variant of m4_foreach that uses m4_for rather
-# than $@ recursion to operate on the list. This involves more macro
-# expansions, but avoids the need to rescan a quadratic number of
-# arguments, making these replacements very attractive for M4 1.4.x.
-# On the other hand, in any version of M4, expanding additional macros
-# costs additional time; therefore, in M4 1.6, where $@ recursion uses
-# fewer macros, these replacements actually pessimize performance.
-# Additionally, the use of $10 to mean the tenth argument violates
-# POSIX; although all versions of m4 1.4.x support this meaning, a
-# future m4 version may switch to take it as the first argument
-# concatenated with a literal 0, so the implementations in this file
-# are not future-proof. Thus, this file is conditionally included as
-# part of m4_init(), only when it is detected that M4 probably has
-# quadratic behavior (ie. it lacks the macro __m4_version__).
-#
-# Please keep this file in sync with m4sugar.m4.
-
-# _m4_foreach(PRE, POST, IGNORED, ARG...)
-# ---------------------------------------
-# Form the common basis of the m4_foreach and m4_map macros. For each
-# ARG, expand PRE[ARG]POST[]. The IGNORED argument makes recursion
-# easier, and must be supplied rather than implicit.
-#
-# This version minimizes the number of times that $@ is evaluated by
-# using m4_for to generate a boilerplate into _m4_f then passing $@ to
-# that temporary macro. Thus, the recursion is done in m4_for without
-# reparsing any user input, and is not quadratic. For an idea of how
-# this works, note that m4_foreach(i,[1,2],[i]) calls
-# _m4_foreach([m4_define([i],],[)i],[],[1],[2])
-# which defines _m4_f:
-# $1[$4]$2[]$1[$5]$2[]_m4_popdef([_m4_f])
-# then calls _m4_f([m4_define([i],],[)i],[],[1],[2]) for a net result:
-# m4_define([i],[1])i[]m4_define([i],[2])i[]_m4_popdef([_m4_f]).
-m4_define([_m4_foreach],
-[m4_if([$#], [3], [],
- [m4_pushdef([_m4_f], _m4_for([4], [$#], [1],
- [$0_([1], [2],], [)])[_m4_popdef([_m4_f])])_m4_f($@)])])
-
-m4_define([_m4_foreach_],
-[[$$1[$$3]$$2[]]])
-
-# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
-# -----------------------------------------------------------
-# Find the first VAL that SWITCH matches, and expand the corresponding
-# IF-VAL. If there are no matches, expand DEFAULT.
-#
-# Use m4_for to create a temporary macro in terms of a boilerplate
-# m4_if with final cleanup. If $# is even, we have DEFAULT; if it is
-# odd, then rounding the last $# up in the temporary macro is
-# harmless. For example, both m4_case(1,2,3,4,5) and
-# m4_case(1,2,3,4,5,6) result in the intermediate _m4_case being
-# m4_if([$1],[$2],[$3],[$1],[$4],[$5],_m4_popdef([_m4_case])[$6])
-m4_define([m4_case],
-[m4_if(m4_eval([$# <= 2]), [1], [$2],
-[m4_pushdef([_$0], [m4_if(]_m4_for([2], m4_eval([($# - 1) / 2 * 2]), [2],
- [_$0_(], [)])[_m4_popdef(
- [_$0])]m4_dquote($m4_eval([($# + 1) & ~1]))[)])_$0($@)])])
-
-m4_define([_m4_case_],
-[$0_([1], [$1], m4_incr([$1]))])
-
-m4_define([_m4_case__],
-[[[$$1],[$$2],[$$3],]])
-
-# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
-# -----------------------------------------------------
-# m4 equivalent of
-#
-# if (SWITCH =~ RE1)
-# VAL1;
-# elif (SWITCH =~ RE2)
-# VAL2;
-# elif ...
-# ...
-# else
-# DEFAULT
-#
-# We build the temporary macro _m4_b:
-# m4_define([_m4_b], _m4_defn([_m4_bmatch]))_m4_b([$1], [$2], [$3])...
-# _m4_b([$1], [$m-1], [$m])_m4_b([], [], [$m+1]_m4_popdef([_m4_b]))
-# then invoke m4_unquote(_m4_b($@)), for concatenation with later text.
-m4_define([m4_bmatch],
-[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
- [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
- [$#], 2, [$2],
- [m4_pushdef([_m4_b], [m4_define([_m4_b],
- _m4_defn([_$0]))]_m4_for([3], m4_eval([($# + 1) / 2 * 2 - 1]),
- [2], [_$0_(], [)])[_m4_b([], [],]m4_dquote([$]m4_eval(
- [($# + 1) / 2 * 2]))[_m4_popdef([_m4_b]))])m4_unquote(_m4_b($@))])])
-
-m4_define([_m4_bmatch],
-[m4_if(m4_bregexp([$1], [$2]), [-1], [], [[$3]m4_define([$0])])])
-
-m4_define([_m4_bmatch_],
-[$0_([1], m4_decr([$1]), [$1])])
-
-m4_define([_m4_bmatch__],
-[[_m4_b([$$1], [$$2], [$$3])]])
-
-
-# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT])
-# -------------------------------------------------------------------
-# Similar to m4_if, except that each TEST is expanded when encountered.
-# If the expansion of TESTn matches the string VALn, the result is IF-VALn.
-# The result is DEFAULT if no tests passed. This macro allows
-# short-circuiting of expensive tests, where it pays to arrange quick
-# filter tests to run first.
-#
-# m4_cond already guarantees either 3*n or 3*n + 1 arguments, 1 <= n.
-# We only have to speed up _m4_cond, by building the temporary _m4_c:
-# m4_define([_m4_c], _m4_defn([m4_unquote]))_m4_c([m4_if(($1), [($2)],
-# [[$3]m4_define([_m4_c])])])_m4_c([m4_if(($4), [($5)],
-# [[$6]m4_define([_m4_c])])])..._m4_c([m4_if(($m-2), [($m-1)],
-# [[$m]m4_define([_m4_c])])])_m4_c([[$m+1]]_m4_popdef([_m4_c]))
-# We invoke m4_unquote(_m4_c($@)), for concatenation with later text.
-m4_define([_m4_cond],
-[m4_pushdef([_m4_c], [m4_define([_m4_c],
- _m4_defn([m4_unquote]))]_m4_for([2], m4_eval([$# / 3 * 3 - 1]), [3],
- [$0_(], [)])[_m4_c(]m4_dquote(m4_dquote(
- [$]m4_eval([$# / 3 * 3 + 1])))[_m4_popdef([_m4_c]))])m4_unquote(_m4_c($@))])
-
-m4_define([_m4_cond_],
-[$0_(m4_decr([$1]), [$1], m4_incr([$1]))])
-
-m4_define([_m4_cond__],
-[[_m4_c([m4_if(($$1), [($$2)], [[$$3]m4_define([_m4_c])])])]])
-
-# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
-# ----------------------------------------------------
-# m4 equivalent of
-#
-# $_ = STRING;
-# s/RE1/SUBST1/g;
-# s/RE2/SUBST2/g;
-# ...
-#
-# m4_bpatsubsts already validated an odd number of arguments; we only
-# need to speed up _m4_bpatsubsts. To avoid nesting, we build the
-# temporary _m4_p:
-# m4_define([_m4_p], [$1])m4_define([_m4_p],
-# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$2], [$3]))m4_define([_m4_p],
-# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$4], [$5]))m4_define([_m4_p],...
-# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$m-1], [$m]))m4_unquote(
-# _m4_defn([_m4_p])_m4_popdef([_m4_p]))
-m4_define([_m4_bpatsubsts],
-[m4_pushdef([_m4_p], [m4_define([_m4_p],
- ]m4_dquote([$]1)[)]_m4_for([3], [$#], [2], [$0_(],
- [)])[m4_unquote(_m4_defn([_m4_p])_m4_popdef([_m4_p]))])_m4_p($@)])
-
-m4_define([_m4_bpatsubsts_],
-[$0_(m4_decr([$1]), [$1])])
-
-m4_define([_m4_bpatsubsts__],
-[[m4_define([_m4_p],
-m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$$1], [$$2]))]])
-
-# m4_shiftn(N, ...)
-# -----------------
-# Returns ... shifted N times. Useful for recursive "varargs" constructs.
-#
-# m4_shiftn already validated arguments; we only need to speed up
-# _m4_shiftn. If N is 3, then we build the temporary _m4_s, defined as
-# ,[$5],[$6],...,[$m]_m4_popdef([_m4_s])
-# before calling m4_shift(_m4_s($@)).
-m4_define([_m4_shiftn],
-[m4_if(m4_incr([$1]), [$#], [], [m4_pushdef([_m4_s],
- _m4_for(m4_eval([$1 + 2]), [$#], [1],
- [[,]m4_dquote($], [)])[_m4_popdef([_m4_s])])m4_shift(_m4_s($@))])])
-
-# m4_do(STRING, ...)
-# ------------------
-# This macro invokes all its arguments (in sequence, of course). It is
-# useful for making your macros more structured and readable by dropping
-# unnecessary dnl's and have the macros indented properly.
-#
-# Here, we use the temporary macro _m4_do, defined as
-# $1[]$2[]...[]$n[]_m4_popdef([_m4_do])
-m4_define([m4_do],
-[m4_if([$#], [0], [],
- [m4_pushdef([_$0], _m4_for([1], [$#], [1],
- [$], [[[]]])[_m4_popdef([_$0])])_$0($@)])])
-
-# m4_dquote_elt(ARGS)
-# -------------------
-# Return ARGS as an unquoted list of double-quoted arguments.
-#
-# _m4_foreach to the rescue.
-m4_define([m4_dquote_elt],
-[m4_if([$#], [0], [], [[[$1]]_m4_foreach([,m4_dquote(], [)], $@)])])
-
-# m4_reverse(ARGS)
-# ----------------
-# Output ARGS in reverse order.
-#
-# Invoke _m4_r($@) with the temporary _m4_r built as
-# [$m], [$m-1], ..., [$2], [$1]_m4_popdef([_m4_r])
-m4_define([m4_reverse],
-[m4_if([$#], [0], [], [$#], [1], [[$1]],
-[m4_pushdef([_m4_r], [[$$#]]_m4_for(m4_decr([$#]), [1], [-1],
- [[, ]m4_dquote($], [)])[_m4_popdef([_m4_r])])_m4_r($@)])])
-
-
-# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
-# -------------------------------------------------------------
-# Perform a pairwise grouping of consecutive ARGs, by expanding
-# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the
-# final argument is expanded with END-EXPR([ARGn]).
-#
-# Build the temporary macro _m4_map_args_pair, with the $2([$m+1])
-# only output if $# is odd:
-# $1([$3], [$4])[]$1([$5], [$6])[]...$1([$m-1],
-# [$m])[]m4_default([$2], [$1])([$m+1])[]_m4_popdef([_m4_map_args_pair])
-m4_define([m4_map_args_pair],
-[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
- [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
- [$#], [2], [],
- [$#], [3], [m4_default([$2], [$1])([$3])[]],
- [m4_pushdef([_$0], _m4_for([3],
- m4_eval([$# / 2 * 2 - 1]), [2], [_$0_(], [)])_$0_end(
- [1], [2], [$#])[_m4_popdef([_$0])])_$0($@)])])
-
-m4_define([_m4_map_args_pair_],
-[$0_([1], [$1], m4_incr([$1]))])
-
-m4_define([_m4_map_args_pair__],
-[[$$1([$$2], [$$3])[]]])
-
-m4_define([_m4_map_args_pair_end],
-[m4_if(m4_eval([$3 & 1]), [1], [[m4_default([$$2], [$$1])([$$3])[]]])])
-
-# m4_join(SEP, ARG1, ARG2...)
-# ---------------------------
-# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG
-# is the empty string. No expansion is performed on SEP or ARGs.
-#
-# Use a self-modifying separator, since we don't know how many
-# arguments might be skipped before a separator is first printed, but
-# be careful if the separator contains $. _m4_foreach to the rescue.
-m4_define([m4_join],
-[m4_pushdef([_m4_sep], [m4_define([_m4_sep], _m4_defn([m4_echo]))])]dnl
-[_m4_foreach([_$0([$1],], [)], $@)_m4_popdef([_m4_sep])])
-
-m4_define([_m4_join],
-[m4_if([$2], [], [], [_m4_sep([$1])[$2]])])
-
-# m4_joinall(SEP, ARG1, ARG2...)
-# ------------------------------
-# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP.
-# No expansion is performed on SEP or ARGs.
-#
-# A bit easier than m4_join. _m4_foreach to the rescue.
-m4_define([m4_joinall],
-[[$2]m4_if(m4_eval([$# <= 2]), [1], [],
- [_m4_foreach([$1], [], m4_shift($@))])])
-
-# m4_list_cmp(A, B)
-# -----------------
-# Compare the two lists of integer expressions A and B.
-#
-# m4_list_cmp takes care of any side effects; we only override
-# _m4_list_cmp_raw, where we can safely expand lists multiple times.
-# First, insert padding so that both lists are the same length; the
-# trailing +0 is necessary to handle a missing list. Next, create a
-# temporary macro to perform pairwise comparisons until an inequality
-# is found. For example, m4_list_cmp([1], [1,2]) creates _m4_cmp as
-# m4_if(m4_eval([($1) != ($3)]), [1], [m4_cmp([$1], [$3])],
-# m4_eval([($2) != ($4)]), [1], [m4_cmp([$2], [$4])],
-# [0]_m4_popdef([_m4_cmp]))
-# then calls _m4_cmp([1+0], [0*2], [1], [2+0])
-m4_define([_m4_list_cmp_raw],
-[m4_if([$1], [$2], 0,
- [_m4_list_cmp($1+0_m4_list_pad(m4_count($1), m4_count($2)),
- $2+0_m4_list_pad(m4_count($2), m4_count($1)))])])
-
-m4_define([_m4_list_pad],
-[m4_if(m4_eval($1 < $2), [1],
- [_m4_for(m4_incr([$1]), [$2], [1], [,0*])])])
-
-m4_define([_m4_list_cmp],
-[m4_pushdef([_m4_cmp], [m4_if(]_m4_for(
- [1], m4_eval([$# >> 1]), [1], [$0_(], [,]m4_eval([$# >> 1])[)])[
- [0]_m4_popdef([_m4_cmp]))])_m4_cmp($@)])
-
-m4_define([_m4_list_cmp_],
-[$0_([$1], m4_eval([$1 + $2]))])
-
-m4_define([_m4_list_cmp__],
-[[m4_eval([($$1) != ($$2)]), [1], [m4_cmp([$$1], [$$2])],
-]])
-
-# m4_max(EXPR, ...)
-# m4_min(EXPR, ...)
-# -----------------
-# Return the decimal value of the maximum (or minimum) in a series of
-# integer expressions.
-#
-# _m4_foreach to the rescue; we only need to replace _m4_minmax. Here,
-# we need a temporary macro to track the best answer so far, so that
-# the foreach expression is tractable.
-m4_define([_m4_minmax],
-[m4_pushdef([_m4_best], m4_eval([$2]))_m4_foreach(
- [m4_define([_m4_best], $1(_m4_best,], [))], m4_shift($@))]dnl
-[_m4_best[]_m4_popdef([_m4_best])])
-
-# m4_set_add_all(SET, VALUE...)
-# -----------------------------
-# Add each VALUE into SET. This is O(n) in the number of VALUEs, and
-# can be faster than calling m4_set_add for each VALUE.
-#
-# _m4_foreach to the rescue. If no deletions have occurred, then
-# avoid the speed penalty of m4_set_add.
-m4_define([m4_set_add_all],
-[m4_if([$#], [0], [], [$#], [1], [],
- [m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1])
- + m4_len(_m4_foreach(m4_ifdef([_m4_set_cleanup($1)],
- [[m4_set_add]], [[_$0]])[([$1],], [)], $@))))])])
-
-m4_define([_m4_set_add_all],
-[m4_ifdef([_m4_set([$1],$2)], [],
- [m4_define([_m4_set([$1],$2)],
- [1])m4_pushdef([_m4_set([$1])], [$2])-])])
+# -*- Autoconf -*-
+# This file is part of Autoconf.
+# foreach-based replacements for recursive functions.
+# Speeds up GNU M4 1.4.x by avoiding quadratic $@ recursion, but penalizes
+# GNU M4 1.6 by requiring more memory and macro expansions.
+#
+# Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+# This file is part of Autoconf. This program is free
+# software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the Autoconf Configure Script Exception,
+# version 3.0, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License
+# and a copy of the Autoconf Configure Script Exception along with
+# this program; see the files COPYINGv3 and COPYING.EXCEPTION
+# respectively. If not, see <http://www.gnu.org/licenses/>.
+
+# Written by Eric Blake.
+
+# In M4 1.4.x, every byte of $@ is rescanned. This means that an
+# algorithm on n arguments that recurses with one less argument each
+# iteration will scan n * (n + 1) / 2 arguments, for O(n^2) time. In
+# M4 1.6, this was fixed so that $@ is only scanned once, then
+# back-references are made to information stored about the scan.
+# Thus, n iterations need only scan n arguments, for O(n) time.
+# Additionally, in M4 1.4.x, recursive algorithms did not clean up
+# memory very well, requiring O(n^2) memory rather than O(n) for n
+# iterations.
+#
+# This file is designed to overcome the quadratic nature of $@
+# recursion by writing a variant of m4_foreach that uses m4_for rather
+# than $@ recursion to operate on the list. This involves more macro
+# expansions, but avoids the need to rescan a quadratic number of
+# arguments, making these replacements very attractive for M4 1.4.x.
+# On the other hand, in any version of M4, expanding additional macros
+# costs additional time; therefore, in M4 1.6, where $@ recursion uses
+# fewer macros, these replacements actually pessimize performance.
+# Additionally, the use of $10 to mean the tenth argument violates
+# POSIX; although all versions of m4 1.4.x support this meaning, a
+# future m4 version may switch to take it as the first argument
+# concatenated with a literal 0, so the implementations in this file
+# are not future-proof. Thus, this file is conditionally included as
+# part of m4_init(), only when it is detected that M4 probably has
+# quadratic behavior (ie. it lacks the macro __m4_version__).
+#
+# Please keep this file in sync with m4sugar.m4.
+
+# _m4_foreach(PRE, POST, IGNORED, ARG...)
+# ---------------------------------------
+# Form the common basis of the m4_foreach and m4_map macros. For each
+# ARG, expand PRE[ARG]POST[]. The IGNORED argument makes recursion
+# easier, and must be supplied rather than implicit.
+#
+# This version minimizes the number of times that $@ is evaluated by
+# using m4_for to generate a boilerplate into _m4_f then passing $@ to
+# that temporary macro. Thus, the recursion is done in m4_for without
+# reparsing any user input, and is not quadratic. For an idea of how
+# this works, note that m4_foreach(i,[1,2],[i]) calls
+# _m4_foreach([m4_define([i],],[)i],[],[1],[2])
+# which defines _m4_f:
+# $1[$4]$2[]$1[$5]$2[]_m4_popdef([_m4_f])
+# then calls _m4_f([m4_define([i],],[)i],[],[1],[2]) for a net result:
+# m4_define([i],[1])i[]m4_define([i],[2])i[]_m4_popdef([_m4_f]).
+m4_define([_m4_foreach],
+[m4_if([$#], [3], [],
+ [m4_pushdef([_m4_f], _m4_for([4], [$#], [1],
+ [$0_([1], [2],], [)])[_m4_popdef([_m4_f])])_m4_f($@)])])
+
+m4_define([_m4_foreach_],
+[[$$1[$$3]$$2[]]])
+
+# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
+# -----------------------------------------------------------
+# Find the first VAL that SWITCH matches, and expand the corresponding
+# IF-VAL. If there are no matches, expand DEFAULT.
+#
+# Use m4_for to create a temporary macro in terms of a boilerplate
+# m4_if with final cleanup. If $# is even, we have DEFAULT; if it is
+# odd, then rounding the last $# up in the temporary macro is
+# harmless. For example, both m4_case(1,2,3,4,5) and
+# m4_case(1,2,3,4,5,6) result in the intermediate _m4_case being
+# m4_if([$1],[$2],[$3],[$1],[$4],[$5],_m4_popdef([_m4_case])[$6])
+m4_define([m4_case],
+[m4_if(m4_eval([$# <= 2]), [1], [$2],
+[m4_pushdef([_$0], [m4_if(]_m4_for([2], m4_eval([($# - 1) / 2 * 2]), [2],
+ [_$0_(], [)])[_m4_popdef(
+ [_$0])]m4_dquote($m4_eval([($# + 1) & ~1]))[)])_$0($@)])])
+
+m4_define([_m4_case_],
+[$0_([1], [$1], m4_incr([$1]))])
+
+m4_define([_m4_case__],
+[[[$$1],[$$2],[$$3],]])
+
+# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
+# -----------------------------------------------------
+# m4 equivalent of
+#
+# if (SWITCH =~ RE1)
+# VAL1;
+# elif (SWITCH =~ RE2)
+# VAL2;
+# elif ...
+# ...
+# else
+# DEFAULT
+#
+# We build the temporary macro _m4_b:
+# m4_define([_m4_b], _m4_defn([_m4_bmatch]))_m4_b([$1], [$2], [$3])...
+# _m4_b([$1], [$m-1], [$m])_m4_b([], [], [$m+1]_m4_popdef([_m4_b]))
+# then invoke m4_unquote(_m4_b($@)), for concatenation with later text.
+m4_define([m4_bmatch],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+ [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], 2, [$2],
+ [m4_pushdef([_m4_b], [m4_define([_m4_b],
+ _m4_defn([_$0]))]_m4_for([3], m4_eval([($# + 1) / 2 * 2 - 1]),
+ [2], [_$0_(], [)])[_m4_b([], [],]m4_dquote([$]m4_eval(
+ [($# + 1) / 2 * 2]))[_m4_popdef([_m4_b]))])m4_unquote(_m4_b($@))])])
+
+m4_define([_m4_bmatch],
+[m4_if(m4_bregexp([$1], [$2]), [-1], [], [[$3]m4_define([$0])])])
+
+m4_define([_m4_bmatch_],
+[$0_([1], m4_decr([$1]), [$1])])
+
+m4_define([_m4_bmatch__],
+[[_m4_b([$$1], [$$2], [$$3])]])
+
+
+# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT])
+# -------------------------------------------------------------------
+# Similar to m4_if, except that each TEST is expanded when encountered.
+# If the expansion of TESTn matches the string VALn, the result is IF-VALn.
+# The result is DEFAULT if no tests passed. This macro allows
+# short-circuiting of expensive tests, where it pays to arrange quick
+# filter tests to run first.
+#
+# m4_cond already guarantees either 3*n or 3*n + 1 arguments, 1 <= n.
+# We only have to speed up _m4_cond, by building the temporary _m4_c:
+# m4_define([_m4_c], _m4_defn([m4_unquote]))_m4_c([m4_if(($1), [($2)],
+# [[$3]m4_define([_m4_c])])])_m4_c([m4_if(($4), [($5)],
+# [[$6]m4_define([_m4_c])])])..._m4_c([m4_if(($m-2), [($m-1)],
+# [[$m]m4_define([_m4_c])])])_m4_c([[$m+1]]_m4_popdef([_m4_c]))
+# We invoke m4_unquote(_m4_c($@)), for concatenation with later text.
+m4_define([_m4_cond],
+[m4_pushdef([_m4_c], [m4_define([_m4_c],
+ _m4_defn([m4_unquote]))]_m4_for([2], m4_eval([$# / 3 * 3 - 1]), [3],
+ [$0_(], [)])[_m4_c(]m4_dquote(m4_dquote(
+ [$]m4_eval([$# / 3 * 3 + 1])))[_m4_popdef([_m4_c]))])m4_unquote(_m4_c($@))])
+
+m4_define([_m4_cond_],
+[$0_(m4_decr([$1]), [$1], m4_incr([$1]))])
+
+m4_define([_m4_cond__],
+[[_m4_c([m4_if(($$1), [($$2)], [[$$3]m4_define([_m4_c])])])]])
+
+# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
+# ----------------------------------------------------
+# m4 equivalent of
+#
+# $_ = STRING;
+# s/RE1/SUBST1/g;
+# s/RE2/SUBST2/g;
+# ...
+#
+# m4_bpatsubsts already validated an odd number of arguments; we only
+# need to speed up _m4_bpatsubsts. To avoid nesting, we build the
+# temporary _m4_p:
+# m4_define([_m4_p], [$1])m4_define([_m4_p],
+# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$2], [$3]))m4_define([_m4_p],
+# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$4], [$5]))m4_define([_m4_p],...
+# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$m-1], [$m]))m4_unquote(
+# _m4_defn([_m4_p])_m4_popdef([_m4_p]))
+m4_define([_m4_bpatsubsts],
+[m4_pushdef([_m4_p], [m4_define([_m4_p],
+ ]m4_dquote([$]1)[)]_m4_for([3], [$#], [2], [$0_(],
+ [)])[m4_unquote(_m4_defn([_m4_p])_m4_popdef([_m4_p]))])_m4_p($@)])
+
+m4_define([_m4_bpatsubsts_],
+[$0_(m4_decr([$1]), [$1])])
+
+m4_define([_m4_bpatsubsts__],
+[[m4_define([_m4_p],
+m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$$1], [$$2]))]])
+
+# m4_shiftn(N, ...)
+# -----------------
+# Returns ... shifted N times. Useful for recursive "varargs" constructs.
+#
+# m4_shiftn already validated arguments; we only need to speed up
+# _m4_shiftn. If N is 3, then we build the temporary _m4_s, defined as
+# ,[$5],[$6],...,[$m]_m4_popdef([_m4_s])
+# before calling m4_shift(_m4_s($@)).
+m4_define([_m4_shiftn],
+[m4_if(m4_incr([$1]), [$#], [], [m4_pushdef([_m4_s],
+ _m4_for(m4_eval([$1 + 2]), [$#], [1],
+ [[,]m4_dquote($], [)])[_m4_popdef([_m4_s])])m4_shift(_m4_s($@))])])
+
+# m4_do(STRING, ...)
+# ------------------
+# This macro invokes all its arguments (in sequence, of course). It is
+# useful for making your macros more structured and readable by dropping
+# unnecessary dnl's and have the macros indented properly.
+#
+# Here, we use the temporary macro _m4_do, defined as
+# $1[]$2[]...[]$n[]_m4_popdef([_m4_do])
+m4_define([m4_do],
+[m4_if([$#], [0], [],
+ [m4_pushdef([_$0], _m4_for([1], [$#], [1],
+ [$], [[[]]])[_m4_popdef([_$0])])_$0($@)])])
+
+# m4_dquote_elt(ARGS)
+# -------------------
+# Return ARGS as an unquoted list of double-quoted arguments.
+#
+# _m4_foreach to the rescue.
+m4_define([m4_dquote_elt],
+[m4_if([$#], [0], [], [[[$1]]_m4_foreach([,m4_dquote(], [)], $@)])])
+
+# m4_reverse(ARGS)
+# ----------------
+# Output ARGS in reverse order.
+#
+# Invoke _m4_r($@) with the temporary _m4_r built as
+# [$m], [$m-1], ..., [$2], [$1]_m4_popdef([_m4_r])
+m4_define([m4_reverse],
+[m4_if([$#], [0], [], [$#], [1], [[$1]],
+[m4_pushdef([_m4_r], [[$$#]]_m4_for(m4_decr([$#]), [1], [-1],
+ [[, ]m4_dquote($], [)])[_m4_popdef([_m4_r])])_m4_r($@)])])
+
+
+# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
+# -------------------------------------------------------------
+# Perform a pairwise grouping of consecutive ARGs, by expanding
+# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the
+# final argument is expanded with END-EXPR([ARGn]).
+#
+# Build the temporary macro _m4_map_args_pair, with the $2([$m+1])
+# only output if $# is odd:
+# $1([$3], [$4])[]$1([$5], [$6])[]...$1([$m-1],
+# [$m])[]m4_default([$2], [$1])([$m+1])[]_m4_popdef([_m4_map_args_pair])
+m4_define([m4_map_args_pair],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], [2], [],
+ [$#], [3], [m4_default([$2], [$1])([$3])[]],
+ [m4_pushdef([_$0], _m4_for([3],
+ m4_eval([$# / 2 * 2 - 1]), [2], [_$0_(], [)])_$0_end(
+ [1], [2], [$#])[_m4_popdef([_$0])])_$0($@)])])
+
+m4_define([_m4_map_args_pair_],
+[$0_([1], [$1], m4_incr([$1]))])
+
+m4_define([_m4_map_args_pair__],
+[[$$1([$$2], [$$3])[]]])
+
+m4_define([_m4_map_args_pair_end],
+[m4_if(m4_eval([$3 & 1]), [1], [[m4_default([$$2], [$$1])([$$3])[]]])])
+
+# m4_join(SEP, ARG1, ARG2...)
+# ---------------------------
+# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG
+# is the empty string. No expansion is performed on SEP or ARGs.
+#
+# Use a self-modifying separator, since we don't know how many
+# arguments might be skipped before a separator is first printed, but
+# be careful if the separator contains $. _m4_foreach to the rescue.
+m4_define([m4_join],
+[m4_pushdef([_m4_sep], [m4_define([_m4_sep], _m4_defn([m4_echo]))])]dnl
+[_m4_foreach([_$0([$1],], [)], $@)_m4_popdef([_m4_sep])])
+
+m4_define([_m4_join],
+[m4_if([$2], [], [], [_m4_sep([$1])[$2]])])
+
+# m4_joinall(SEP, ARG1, ARG2...)
+# ------------------------------
+# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP.
+# No expansion is performed on SEP or ARGs.
+#
+# A bit easier than m4_join. _m4_foreach to the rescue.
+m4_define([m4_joinall],
+[[$2]m4_if(m4_eval([$# <= 2]), [1], [],
+ [_m4_foreach([$1], [], m4_shift($@))])])
+
+# m4_list_cmp(A, B)
+# -----------------
+# Compare the two lists of integer expressions A and B.
+#
+# m4_list_cmp takes care of any side effects; we only override
+# _m4_list_cmp_raw, where we can safely expand lists multiple times.
+# First, insert padding so that both lists are the same length; the
+# trailing +0 is necessary to handle a missing list. Next, create a
+# temporary macro to perform pairwise comparisons until an inequality
+# is found. For example, m4_list_cmp([1], [1,2]) creates _m4_cmp as
+# m4_if(m4_eval([($1) != ($3)]), [1], [m4_cmp([$1], [$3])],
+# m4_eval([($2) != ($4)]), [1], [m4_cmp([$2], [$4])],
+# [0]_m4_popdef([_m4_cmp]))
+# then calls _m4_cmp([1+0], [0*2], [1], [2+0])
+m4_define([_m4_list_cmp_raw],
+[m4_if([$1], [$2], 0,
+ [_m4_list_cmp($1+0_m4_list_pad(m4_count($1), m4_count($2)),
+ $2+0_m4_list_pad(m4_count($2), m4_count($1)))])])
+
+m4_define([_m4_list_pad],
+[m4_if(m4_eval($1 < $2), [1],
+ [_m4_for(m4_incr([$1]), [$2], [1], [,0*])])])
+
+m4_define([_m4_list_cmp],
+[m4_pushdef([_m4_cmp], [m4_if(]_m4_for(
+ [1], m4_eval([$# >> 1]), [1], [$0_(], [,]m4_eval([$# >> 1])[)])[
+ [0]_m4_popdef([_m4_cmp]))])_m4_cmp($@)])
+
+m4_define([_m4_list_cmp_],
+[$0_([$1], m4_eval([$1 + $2]))])
+
+m4_define([_m4_list_cmp__],
+[[m4_eval([($$1) != ($$2)]), [1], [m4_cmp([$$1], [$$2])],
+]])
+
+# m4_max(EXPR, ...)
+# m4_min(EXPR, ...)
+# -----------------
+# Return the decimal value of the maximum (or minimum) in a series of
+# integer expressions.
+#
+# _m4_foreach to the rescue; we only need to replace _m4_minmax. Here,
+# we need a temporary macro to track the best answer so far, so that
+# the foreach expression is tractable.
+m4_define([_m4_minmax],
+[m4_pushdef([_m4_best], m4_eval([$2]))_m4_foreach(
+ [m4_define([_m4_best], $1(_m4_best,], [))], m4_shift($@))]dnl
+[_m4_best[]_m4_popdef([_m4_best])])
+
+# m4_set_add_all(SET, VALUE...)
+# -----------------------------
+# Add each VALUE into SET. This is O(n) in the number of VALUEs, and
+# can be faster than calling m4_set_add for each VALUE.
+#
+# _m4_foreach to the rescue. If no deletions have occurred, then
+# avoid the speed penalty of m4_set_add.
+m4_define([m4_set_add_all],
+[m4_if([$#], [0], [], [$#], [1], [],
+ [m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1])
+ + m4_len(_m4_foreach(m4_ifdef([_m4_set_cleanup($1)],
+ [[m4_set_add]], [[_$0]])[([$1],], [)], $@))))])])
+
+m4_define([_m4_set_add_all],
+[m4_ifdef([_m4_set([$1],$2)], [],
+ [m4_define([_m4_set([$1],$2)],
+ [1])m4_pushdef([_m4_set([$1])], [$2])-])])
diff --git a/contrib/tools/bison/bison/data/m4sugar/m4sugar.m4 b/contrib/tools/bison/bison/data/m4sugar/m4sugar.m4
index b732abc789..99fcbe9fce 100644
--- a/contrib/tools/bison/bison/data/m4sugar/m4sugar.m4
+++ b/contrib/tools/bison/bison/data/m4sugar/m4sugar.m4
@@ -1,3307 +1,3307 @@
-divert(-1)# -*- Autoconf -*-
-# This file is part of Autoconf.
-# Base M4 layer.
-# Requires GNU M4.
-#
-# Copyright (C) 1999-2013 Free Software Foundation, Inc.
-
-# This file is part of Autoconf. This program is free
-# software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the
-# Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# Under Section 7 of GPL version 3, you are granted additional
-# permissions described in the Autoconf Configure Script Exception,
-# version 3.0, as published by the Free Software Foundation.
-#
-# You should have received a copy of the GNU General Public License
-# and a copy of the Autoconf Configure Script Exception along with
-# this program; see the files COPYINGv3 and COPYING.EXCEPTION
-# respectively. If not, see <http://www.gnu.org/licenses/>.
-
-# Written by Akim Demaille.
-
-# Set the quotes, whatever the current quoting system.
-changequote()
-changequote([, ])
-
-# Some old m4's don't support m4exit. But they provide
-# equivalent functionality by core dumping because of the
-# long macros we define.
-ifdef([__gnu__], ,
-[errprint(M4sugar requires GNU M4. Install it before installing M4sugar or
-set the M4 environment variable to its absolute file name.)
-m4exit(2)])
-
-
-## ------------------------------- ##
-## 1. Simulate --prefix-builtins. ##
-## ------------------------------- ##
-
-# m4_define
-# m4_defn
-# m4_undefine
-define([m4_define], defn([define]))
-define([m4_defn], defn([defn]))
-define([m4_undefine], defn([undefine]))
-
-m4_undefine([define])
-m4_undefine([defn])
-m4_undefine([undefine])
-
-
-# m4_copy(SRC, DST)
-# -----------------
-# Define DST as the definition of SRC.
-# What's the difference between:
-# 1. m4_copy([from], [to])
-# 2. m4_define([to], [from($@)])
-# Well, obviously 1 is more expensive in space. Maybe 2 is more expensive
-# in time, but because of the space cost of 1, it's not that obvious.
-# Nevertheless, one huge difference is the handling of `$0'. If `from'
-# uses `$0', then with 1, `to''s `$0' is `to', while it is `from' in 2.
-# The user would certainly prefer to see `to'.
-#
-# This definition is in effect during m4sugar initialization, when
-# there are no pushdef stacks; later on, we redefine it to something
-# more powerful for all other clients to use.
-m4_define([m4_copy],
-[m4_define([$2], m4_defn([$1]))])
-
-
-# m4_rename(SRC, DST)
-# -------------------
-# Rename the macro SRC to DST.
-m4_define([m4_rename],
-[m4_copy([$1], [$2])m4_undefine([$1])])
-
-
-# m4_rename_m4(MACRO-NAME)
-# ------------------------
-# Rename MACRO-NAME to m4_MACRO-NAME.
-m4_define([m4_rename_m4],
-[m4_rename([$1], [m4_$1])])
-
-
-# m4_copy_unm4(m4_MACRO-NAME)
-# ---------------------------
-# Copy m4_MACRO-NAME to MACRO-NAME.
-m4_define([m4_copy_unm4],
-[m4_copy([$1], m4_bpatsubst([$1], [^m4_\(.*\)], [[\1]]))])
-
-
-# Some m4 internals have names colliding with tokens we might use.
-# Rename them a` la `m4 --prefix-builtins'. Conditionals first, since
-# some subsequent renames are conditional.
-m4_rename_m4([ifdef])
-m4_rename([ifelse], [m4_if])
-
-m4_rename_m4([builtin])
-m4_rename_m4([changecom])
-m4_rename_m4([changequote])
-m4_ifdef([changeword],dnl conditionally available in 1.4.x
-[m4_undefine([changeword])])
-m4_rename_m4([debugfile])
-m4_rename_m4([debugmode])
-m4_rename_m4([decr])
-m4_rename_m4([divnum])
-m4_rename_m4([dumpdef])
-m4_rename_m4([errprint])
-m4_rename_m4([esyscmd])
-m4_rename_m4([eval])
-m4_rename_m4([format])
-m4_undefine([include])
-m4_rename_m4([incr])
-m4_rename_m4([index])
-m4_rename_m4([indir])
-m4_rename_m4([len])
-m4_rename([m4exit], [m4_exit])
-m4_undefine([m4wrap])
-m4_ifdef([mkstemp],dnl added in M4 1.4.8
-[m4_rename_m4([mkstemp])
-m4_copy([m4_mkstemp], [m4_maketemp])
-m4_undefine([maketemp])],
-[m4_rename_m4([maketemp])
-m4_copy([m4_maketemp], [m4_mkstemp])])
-m4_rename([patsubst], [m4_bpatsubst])
-m4_rename_m4([popdef])
-m4_rename_m4([pushdef])
-m4_rename([regexp], [m4_bregexp])
-m4_rename_m4([shift])
-m4_undefine([sinclude])
-m4_rename_m4([substr])
-m4_ifdef([symbols],dnl present only in alpha-quality 1.4o
-[m4_rename_m4([symbols])])
-m4_rename_m4([syscmd])
-m4_rename_m4([sysval])
-m4_rename_m4([traceoff])
-m4_rename_m4([traceon])
-m4_rename_m4([translit])
-
-# _m4_defn(ARG)
-# -------------
-# _m4_defn is for internal use only - it bypasses the wrapper, so it
-# must only be used on one argument at a time, and only on macros
-# known to be defined. Make sure this still works if the user renames
-# m4_defn but not _m4_defn.
-m4_copy([m4_defn], [_m4_defn])
-
-# _m4_divert_raw(NUM)
-# -------------------
-# _m4_divert_raw is for internal use only. Use this instead of
-# m4_builtin([divert], NUM), so that tracing diversion flow is easier.
-m4_rename([divert], [_m4_divert_raw])
-
-# _m4_popdef(ARG...)
-# ------------------
-# _m4_popdef is for internal use only - it bypasses the wrapper, so it
-# must only be used on macros known to be defined. Make sure this
-# still works if the user renames m4_popdef but not _m4_popdef.
-m4_copy([m4_popdef], [_m4_popdef])
-
-# _m4_undefine(ARG...)
-# --------------------
-# _m4_undefine is for internal use only - it bypasses the wrapper, so
-# it must only be used on macros known to be defined. Make sure this
-# still works if the user renames m4_undefine but not _m4_undefine.
-m4_copy([m4_undefine], [_m4_undefine])
-
-# _m4_undivert(NUM...)
-# --------------------
-# _m4_undivert is for internal use only, and should always be given
-# arguments. Use this instead of m4_builtin([undivert], NUM...), so
-# that tracing diversion flow is easier.
-m4_rename([undivert], [_m4_undivert])
-
-
-## ------------------- ##
-## 2. Error messages. ##
-## ------------------- ##
-
-
-# m4_location
-# -----------
-# Output the current file, colon, and the current line number.
-m4_define([m4_location],
-[__file__:__line__])
-
-
-# m4_errprintn(MSG)
-# -----------------
-# Same as `errprint', but with the missing end of line.
-m4_define([m4_errprintn],
-[m4_errprint([$1
-])])
-
-
-# m4_warning(MSG)
-# ---------------
-# Warn the user.
-m4_define([m4_warning],
-[m4_errprintn(m4_location[: warning: $1])])
-
-
-# m4_fatal(MSG, [EXIT-STATUS])
-# ----------------------------
-# Fatal the user. :)
-m4_define([m4_fatal],
-[m4_errprintn(m4_location[: error: $1]
-m4_expansion_stack)m4_exit(m4_if([$2],, 1, [$2]))])
-
-
-# m4_assert(EXPRESSION, [EXIT-STATUS = 1])
-# ----------------------------------------
-# This macro ensures that EXPRESSION evaluates to true, and exits if
-# EXPRESSION evaluates to false.
-m4_define([m4_assert],
-[m4_if(m4_eval([$1]), 0,
- [m4_fatal([assert failed: $1], [$2])])])
-
-
-
-## ------------- ##
-## 3. Warnings. ##
-## ------------- ##
-
-
-# _m4_warn(CATEGORY, MESSAGE, [STACK-TRACE])
-# ------------------------------------------
-# Report a MESSAGE to the user if the CATEGORY of warnings is enabled.
-# This is for traces only.
-# If present, STACK-TRACE is a \n-separated list of "LOCATION: MESSAGE",
-# where the last line (and no other) ends with "the top level".
-#
-# Within m4, the macro is a no-op. This macro really matters
-# when autom4te post-processes the trace output.
-m4_define([_m4_warn], [])
-
-
-# m4_warn(CATEGORY, MESSAGE)
-# --------------------------
-# Report a MESSAGE to the user if the CATEGORY of warnings is enabled.
-m4_define([m4_warn],
-[_m4_warn([$1], [$2],
-m4_ifdef([_m4_expansion_stack], [m4_expansion_stack]))])
-
-
-
-## ------------------- ##
-## 4. File inclusion. ##
-## ------------------- ##
-
-
-# We also want to neutralize include (and sinclude for symmetry),
-# but we want to extend them slightly: warn when a file is included
-# several times. This is, in general, a dangerous operation, because
-# too many people forget to quote the first argument of m4_define.
-#
-# For instance in the following case:
-# m4_define(foo, [bar])
-# then a second reading will turn into
-# m4_define(bar, [bar])
-# which is certainly not what was meant.
-
-# m4_include_unique(FILE)
-# -----------------------
-# Declare that the FILE was loading; and warn if it has already
-# been included.
-m4_define([m4_include_unique],
-[m4_ifdef([m4_include($1)],
- [m4_warn([syntax], [file `$1' included several times])])dnl
-m4_define([m4_include($1)])])
-
-
-# m4_include(FILE)
-# ----------------
-# Like the builtin include, but warns against multiple inclusions.
-m4_define([m4_include],
-[m4_include_unique([$1])dnl
-m4_builtin([include], [$1])])
-
-
-# m4_sinclude(FILE)
-# -----------------
-# Like the builtin sinclude, but warns against multiple inclusions.
-m4_define([m4_sinclude],
-[m4_include_unique([$1])dnl
-m4_builtin([sinclude], [$1])])
-
-
-
-## ------------------------------------ ##
-## 5. Additional branching constructs. ##
-## ------------------------------------ ##
-
-# Both `m4_ifval' and `m4_ifset' tests against the empty string. The
-# difference is that `m4_ifset' is specialized on macros.
-#
-# In case of arguments of macros, eg. $1, it makes little difference.
-# In the case of a macro `FOO', you don't want to check `m4_ifval(FOO,
-# TRUE)', because if `FOO' expands with commas, there is a shifting of
-# the arguments. So you want to run `m4_ifval([FOO])', but then you just
-# compare the *string* `FOO' against `', which, of course fails.
-#
-# So you want the variation `m4_ifset' that expects a macro name as $1.
-# If this macro is both defined and defined to a non empty value, then
-# it runs TRUE, etc.
-
-
-# m4_ifblank(COND, [IF-BLANK], [IF-TEXT])
-# m4_ifnblank(COND, [IF-TEXT], [IF-BLANK])
-# ----------------------------------------
-# If COND is empty, or consists only of blanks (space, tab, newline),
-# then expand IF-BLANK, otherwise expand IF-TEXT. This differs from
-# m4_ifval only if COND has just whitespace, but it helps optimize in
-# spite of users who mistakenly leave trailing space after what they
-# thought was an empty argument:
-# macro(
-# []
-# )
-#
-# Writing one macro in terms of the other causes extra overhead, so
-# we inline both definitions.
-m4_define([m4_ifblank],
-[m4_if(m4_translit([[$1]], [ ][ ][
-]), [], [$2], [$3])])
-
-m4_define([m4_ifnblank],
-[m4_if(m4_translit([[$1]], [ ][ ][
-]), [], [$3], [$2])])
-
-
-# m4_ifval(COND, [IF-TRUE], [IF-FALSE])
-# -------------------------------------
-# If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
-# Comparable to m4_ifdef.
-m4_define([m4_ifval],
-[m4_if([$1], [], [$3], [$2])])
-
-
-# m4_n(TEXT)
-# ----------
-# If TEXT is not empty, return TEXT and a new line, otherwise nothing.
-m4_define([m4_n],
-[m4_if([$1],
- [], [],
- [$1
-])])
-
-
-# m4_ifvaln(COND, [IF-TRUE], [IF-FALSE])
-# --------------------------------------
-# Same as `m4_ifval', but add an extra newline to IF-TRUE or IF-FALSE
-# unless that argument is empty.
-m4_define([m4_ifvaln],
-[m4_if([$1],
- [], [m4_n([$3])],
- [m4_n([$2])])])
-
-
-# m4_ifset(MACRO, [IF-TRUE], [IF-FALSE])
-# --------------------------------------
-# If MACRO has no definition, or of its definition is the empty string,
-# expand IF-FALSE, otherwise IF-TRUE.
-m4_define([m4_ifset],
-[m4_ifdef([$1],
- [m4_ifval(_m4_defn([$1]), [$2], [$3])],
- [$3])])
-
-
-# m4_ifndef(NAME, [IF-NOT-DEFINED], [IF-DEFINED])
-# -----------------------------------------------
-m4_define([m4_ifndef],
-[m4_ifdef([$1], [$3], [$2])])
-
-
-# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
-# -----------------------------------------------------------
-# m4 equivalent of
-# switch (SWITCH)
-# {
-# case VAL1:
-# IF-VAL1;
-# break;
-# case VAL2:
-# IF-VAL2;
-# break;
-# ...
-# default:
-# DEFAULT;
-# break;
-# }.
-# All the values are optional, and the macro is robust to active
-# symbols properly quoted.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_case],
-[m4_if([$#], 0, [],
- [$#], 1, [],
- [$#], 2, [$2],
- [$1], [$2], [$3],
- [$0([$1], m4_shift3($@))])])
-
-
-# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
-# -----------------------------------------------------
-# m4 equivalent of
-#
-# if (SWITCH =~ RE1)
-# VAL1;
-# elif (SWITCH =~ RE2)
-# VAL2;
-# elif ...
-# ...
-# else
-# DEFAULT
-#
-# All the values are optional, and the macro is robust to active symbols
-# properly quoted.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_bmatch],
-[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
- [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
- [$#], 2, [$2],
- [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shift3($@))],
- [$3])])])
-
-# m4_argn(N, ARGS...)
-# -------------------
-# Extract argument N (greater than 0) from ARGS. Example:
-# m4_define([b], [B])
-# m4_argn([2], [a], [b], [c]) => b
-#
-# Rather than using m4_car(m4_shiftn([$1], $@)), we exploit the fact that
-# GNU m4 can directly reference any argument, through an indirect macro.
-m4_define([m4_argn],
-[m4_assert([0 < $1])]dnl
-[m4_pushdef([_$0], [_m4_popdef([_$0])]m4_dquote([$]m4_incr([$1])))_$0($@)])
-
-
-# m4_car(ARGS...)
-# m4_cdr(ARGS...)
-# ---------------
-# Manipulate m4 lists. m4_car returns the first argument. m4_cdr
-# bundles all but the first argument into a quoted list. These two
-# macros are generally used with list arguments, with quoting removed
-# to break the list into multiple m4 ARGS.
-m4_define([m4_car], [[$1]])
-m4_define([m4_cdr],
-[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
- [$#], 1, [],
- [m4_dquote(m4_shift($@))])])
-
-# _m4_cdr(ARGS...)
-# ----------------
-# Like m4_cdr, except include a leading comma unless only one argument
-# remains. Why? Because comparing a large list against [] is more
-# expensive in expansion time than comparing the number of arguments; so
-# _m4_cdr can be used to reduce the number of arguments when it is time
-# to end recursion.
-m4_define([_m4_cdr],
-[m4_if([$#], 1, [],
- [, m4_dquote(m4_shift($@))])])
-
-
-
-# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT])
-# -------------------------------------------------------------------
-# Similar to m4_if, except that each TEST is expanded when encountered.
-# If the expansion of TESTn matches the string VALn, the result is IF-VALn.
-# The result is DEFAULT if no tests passed. This macro allows
-# short-circuiting of expensive tests, where it pays to arrange quick
-# filter tests to run first.
-#
-# For an example, consider a previous implementation of _AS_QUOTE_IFELSE:
-#
-# m4_if(m4_index([$1], [\]), [-1], [$2],
-# m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2],
-# m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2],
-# m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3],
-# m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3],
-# [$2])
-#
-# Here, m4_index is computed 5 times, and m4_eval 4, even if $1 contains
-# no backslash. It is more efficient to do:
-#
-# m4_cond([m4_index([$1], [\])], [-1], [$2],
-# [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],
-# [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],
-# [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],
-# [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],
-# [$2])
-#
-# In the common case of $1 with no backslash, only one m4_index expansion
-# occurs, and m4_eval is avoided altogether.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_cond],
-[m4_if([$#], [0], [m4_fatal([$0: cannot be called without arguments])],
- [$#], [1], [$1],
- m4_eval([$# % 3]), [2], [m4_fatal([$0: missing an argument])],
- [_$0($@)])])
-
-m4_define([_m4_cond],
-[m4_if(($1), [($2)], [$3],
- [$#], [3], [],
- [$#], [4], [$4],
- [$0(m4_shift3($@))])])
-
-
-## ---------------------------------------- ##
-## 6. Enhanced version of some primitives. ##
-## ---------------------------------------- ##
-
-# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
-# ----------------------------------------------------
-# m4 equivalent of
-#
-# $_ = STRING;
-# s/RE1/SUBST1/g;
-# s/RE2/SUBST2/g;
-# ...
-#
-# All the values are optional, and the macro is robust to active symbols
-# properly quoted.
-#
-# I would have liked to name this macro `m4_bpatsubst', unfortunately,
-# due to quotation problems, I need to double quote $1 below, therefore
-# the anchors are broken :( I can't let users be trapped by that.
-#
-# Recall that m4_shift3 always results in an argument. Hence, we need
-# to distinguish between a final deletion vs. ending recursion.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_bpatsubsts],
-[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
- [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
- [$#], 2, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2]))],
- [$#], 3, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2], [$3]))],
- [_$0($@m4_if(m4_eval($# & 1), 0, [,]))])])
-m4_define([_m4_bpatsubsts],
-[m4_if([$#], 2, [$1],
- [$0(m4_builtin([patsubst], [[$1]], [$2], [$3]),
- m4_shift3($@))])])
-
-
-# m4_copy(SRC, DST)
-# -----------------
-# Define the pushdef stack DST as a copy of the pushdef stack SRC;
-# give an error if DST is already defined. This is particularly nice
-# for copying self-modifying pushdef stacks, where the top definition
-# includes one-shot initialization that is later popped to the normal
-# definition. This version intentionally does nothing if SRC is
-# undefined.
-#
-# Some macros simply can't be renamed with this method: namely, anything
-# involved in the implementation of m4_stack_foreach_sep.
-m4_define([m4_copy],
-[m4_ifdef([$2], [m4_fatal([$0: won't overwrite defined macro: $2])],
- [m4_stack_foreach_sep([$1], [m4_pushdef([$2],], [)])])]dnl
-[m4_ifdef([m4_location($1)], [m4_define([m4_location($2)], m4_location)])])
-
-
-# m4_copy_force(SRC, DST)
-# m4_rename_force(SRC, DST)
-# -------------------------
-# Like m4_copy/m4_rename, except blindly overwrite any existing DST.
-# Note that m4_copy_force tolerates undefined SRC, while m4_rename_force
-# does not.
-m4_define([m4_copy_force],
-[m4_ifdef([$2], [_m4_undefine([$2])])m4_copy($@)])
-
-m4_define([m4_rename_force],
-[m4_ifdef([$2], [_m4_undefine([$2])])m4_rename($@)])
-
-
-# m4_define_default(MACRO, VALUE)
-# -------------------------------
-# If MACRO is undefined, set it to VALUE.
-m4_define([m4_define_default],
-[m4_ifndef([$1], [m4_define($@)])])
-
-
-# m4_default(EXP1, EXP2)
-# m4_default_nblank(EXP1, EXP2)
-# -----------------------------
-# Returns EXP1 if not empty/blank, otherwise EXP2. Expand the result.
-#
-# m4_default is called on hot paths, so inline the contents of m4_ifval,
-# for one less round of expansion.
-m4_define([m4_default],
-[m4_if([$1], [], [$2], [$1])])
-
-m4_define([m4_default_nblank],
-[m4_ifblank([$1], [$2], [$1])])
-
-
-# m4_default_quoted(EXP1, EXP2)
-# m4_default_nblank_quoted(EXP1, EXP2)
-# ------------------------------------
-# Returns EXP1 if non empty/blank, otherwise EXP2. Leave the result quoted.
-#
-# For comparison:
-# m4_define([active], [ACTIVE])
-# m4_default([active], [default]) => ACTIVE
-# m4_default([], [active]) => ACTIVE
-# -m4_default([ ], [active])- => - -
-# -m4_default_nblank([ ], [active])- => -ACTIVE-
-# m4_default_quoted([active], [default]) => active
-# m4_default_quoted([], [active]) => active
-# -m4_default_quoted([ ], [active])- => - -
-# -m4_default_nblank_quoted([ ], [active])- => -active-
-#
-# m4_default macro is called on hot paths, so inline the contents of m4_ifval,
-# for one less round of expansion.
-m4_define([m4_default_quoted],
-[m4_if([$1], [], [[$2]], [[$1]])])
-
-m4_define([m4_default_nblank_quoted],
-[m4_ifblank([$1], [[$2]], [[$1]])])
-
-
-# m4_defn(NAME)
-# -------------
-# Like the original, except guarantee a warning when using something which is
-# undefined (unlike M4 1.4.x). This replacement is not a full-featured
-# replacement: if any of the defined macros contain unbalanced quoting, but
-# when pasted together result in a well-quoted string, then only native m4
-# support is able to get it correct. But that's where quadrigraphs come in
-# handy, if you really need unbalanced quotes inside your macros.
-#
-# This macro is called frequently, so minimize the amount of additional
-# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
-# (added in M4 1.6), then let m4 do the job for us (see m4_init).
-m4_define([m4_defn],
-[m4_if([$#], [0], [[$0]],
- [$#], [1], [m4_ifdef([$1], [_m4_defn([$1])],
- [m4_fatal([$0: undefined macro: $1])])],
- [m4_map_args([$0], $@)])])
-
-
-# m4_dumpdef(NAME...)
-# -------------------
-# In m4 1.4.x, dumpdef writes to the current debugfile, rather than
-# stderr. This in turn royally confuses autom4te; so we follow the
-# lead of newer m4 and always dump to stderr. Unlike the original,
-# this version requires an argument, since there is no convenient way
-# in m4 1.4.x to grab the names of all defined macros. Newer m4
-# always dumps to stderr, regardless of the current debugfile; it also
-# provides m4symbols as a way to grab all current macro names. But
-# dumpdefs is not frequently called, so we don't need to worry about
-# conditionally using these newer features. Also, this version
-# doesn't sort multiple arguments.
-#
-# If we detect m4 1.6 or newer, then provide an alternate definition,
-# installed during m4_init, that allows builtins through.
-# Unfortunately, there is no nice way in m4 1.4.x to dump builtins.
-m4_define([m4_dumpdef],
-[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
- [$#], [1], [m4_ifdef([$1], [m4_errprintn(
- [$1: ]m4_dquote(_m4_defn([$1])))], [m4_fatal([$0: undefined macro: $1])])],
- [m4_map_args([$0], $@)])])
-
-m4_define([_m4_dumpdef],
-[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
- [$#], [1], [m4_builtin([dumpdef], [$1])],
- [m4_map_args_sep([m4_builtin([dumpdef],], [)], [], $@)])])
-
-
-# m4_dumpdefs(NAME...)
-# --------------------
-# Similar to `m4_dumpdef(NAME)', but if NAME was m4_pushdef'ed, display its
-# value stack (most recent displayed first). Also, this version silently
-# ignores undefined macros, rather than erroring out.
-#
-# This macro cheats, because it relies on the current definition of NAME
-# while the second argument of m4_stack_foreach_lifo is evaluated (which
-# would be undefined according to the API).
-m4_define([m4_dumpdefs],
-[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
- [$#], [1], [m4_stack_foreach_lifo([$1], [m4_dumpdef([$1])m4_ignore])],
- [m4_map_args([$0], $@)])])
-
-# m4_esyscmd_s(COMMAND)
-# ---------------------
-# Like m4_esyscmd, except strip any trailing newlines, thus behaving
-# more like shell command substitution.
-m4_define([m4_esyscmd_s],
-[m4_chomp_all(m4_esyscmd([$1]))])
-
-
-# m4_popdef(NAME)
-# ---------------
-# Like the original, except guarantee a warning when using something which is
-# undefined (unlike M4 1.4.x).
-#
-# This macro is called frequently, so minimize the amount of additional
-# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
-# (added in M4 1.6), then let m4 do the job for us (see m4_init).
-m4_define([m4_popdef],
-[m4_if([$#], [0], [[$0]],
- [$#], [1], [m4_ifdef([$1], [_m4_popdef([$1])],
- [m4_fatal([$0: undefined macro: $1])])],
- [m4_map_args([$0], $@)])])
-
-
-# m4_shiftn(N, ...)
-# -----------------
-# Returns ... shifted N times. Useful for recursive "varargs" constructs.
-#
-# Autoconf does not use this macro, because it is inherently slower than
-# calling the common cases of m4_shift2 or m4_shift3 directly. But it
-# might as well be fast for other clients, such as Libtool. One way to
-# do this is to expand $@ only once in _m4_shiftn (otherwise, for long
-# lists, the expansion of m4_if takes twice as much memory as what the
-# list itself occupies, only to throw away the unused branch). The end
-# result is strictly equivalent to
-# m4_if([$1], 1, [m4_shift(,m4_shift(m4_shift($@)))],
-# [_m4_shiftn(m4_decr([$1]), m4_shift(m4_shift($@)))])
-# but with the final `m4_shift(m4_shift($@)))' shared between the two
-# paths. The first leg uses a no-op m4_shift(,$@) to balance out the ().
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_shiftn],
-[m4_assert(0 < $1 && $1 < $#)_$0($@)])
-
-m4_define([_m4_shiftn],
-[m4_if([$1], 1, [m4_shift(],
- [$0(m4_decr([$1])]), m4_shift(m4_shift($@)))])
-
-# m4_shift2(...)
-# m4_shift3(...)
-# --------------
-# Returns ... shifted twice, and three times. Faster than m4_shiftn.
-m4_define([m4_shift2], [m4_shift(m4_shift($@))])
-m4_define([m4_shift3], [m4_shift(m4_shift(m4_shift($@)))])
-
-# _m4_shift2(...)
-# _m4_shift3(...)
-# ---------------
-# Like m4_shift2 or m4_shift3, except include a leading comma unless shifting
-# consumes all arguments. Why? Because in recursion, it is nice to
-# distinguish between 1 element left and 0 elements left, based on how many
-# arguments this shift expands to.
-m4_define([_m4_shift2],
-[m4_if([$#], [2], [],
- [, m4_shift(m4_shift($@))])])
-m4_define([_m4_shift3],
-[m4_if([$#], [3], [],
- [, m4_shift(m4_shift(m4_shift($@)))])])
-
-
-# m4_undefine(NAME)
-# -----------------
-# Like the original, except guarantee a warning when using something which is
-# undefined (unlike M4 1.4.x).
-#
-# This macro is called frequently, so minimize the amount of additional
-# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
-# (added in M4 1.6), then let m4 do the job for us (see m4_init).
-m4_define([m4_undefine],
-[m4_if([$#], [0], [[$0]],
- [$#], [1], [m4_ifdef([$1], [_m4_undefine([$1])],
- [m4_fatal([$0: undefined macro: $1])])],
- [m4_map_args([$0], $@)])])
-
-# _m4_wrap(PRE, POST)
-# -------------------
-# Helper macro for m4_wrap and m4_wrap_lifo. Allows nested calls to
-# m4_wrap within wrapped text. Use _m4_defn and _m4_popdef for speed.
-m4_define([_m4_wrap],
-[m4_ifdef([$0_text],
- [m4_define([$0_text], [$1]_m4_defn([$0_text])[$2])],
- [m4_builtin([m4wrap], [m4_unquote(
- _m4_defn([$0_text])_m4_popdef([$0_text]))])m4_define([$0_text], [$1$2])])])
-
-# m4_wrap(TEXT)
-# -------------
-# Append TEXT to the list of hooks to be executed at the end of input.
-# Whereas the order of the original may be LIFO in the underlying m4,
-# this version is always FIFO.
-m4_define([m4_wrap],
-[_m4_wrap([], [$1[]])])
-
-# m4_wrap_lifo(TEXT)
-# ------------------
-# Prepend TEXT to the list of hooks to be executed at the end of input.
-# Whereas the order of m4_wrap may be FIFO in the underlying m4, this
-# version is always LIFO.
-m4_define([m4_wrap_lifo],
-[_m4_wrap([$1[]])])
-
-## ------------------------- ##
-## 7. Quoting manipulation. ##
-## ------------------------- ##
-
-
-# m4_apply(MACRO, LIST)
-# ---------------------
-# Invoke MACRO, with arguments provided from the quoted list of
-# comma-separated quoted arguments. If LIST is empty, invoke MACRO
-# without arguments. The expansion will not be concatenated with
-# subsequent text.
-m4_define([m4_apply],
-[m4_if([$2], [], [$1], [$1($2)])[]])
-
-# _m4_apply(MACRO, LIST)
-# ----------------------
-# Like m4_apply, except do nothing if LIST is empty.
-m4_define([_m4_apply],
-[m4_if([$2], [], [], [$1($2)[]])])
-
-
-# m4_count(ARGS)
-# --------------
-# Return a count of how many ARGS are present.
-m4_define([m4_count], [$#])
-
-
-# m4_curry(MACRO, ARG...)
-# -----------------------
-# Perform argument currying. The expansion of this macro is another
-# macro that takes exactly one argument, appends it to the end of the
-# original ARG list, then invokes MACRO. For example:
-# m4_curry([m4_curry], [m4_reverse], [1])([2])([3]) => 3, 2, 1
-# Not quite as practical as m4_incr, but you could also do:
-# m4_define([add], [m4_eval(([$1]) + ([$2]))])
-# m4_define([add_one], [m4_curry([add], [1])])
-# add_one()([2]) => 3
-m4_define([m4_curry], [$1(m4_shift($@,)_$0])
-m4_define([_m4_curry], [[$1])])
-
-
-# m4_do(STRING, ...)
-# ------------------
-# This macro invokes all its arguments (in sequence, of course). It is
-# useful for making your macros more structured and readable by dropping
-# unnecessary dnl's and have the macros indented properly. No concatenation
-# occurs after a STRING; use m4_unquote(m4_join(,STRING)) for that.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_do],
-[m4_if([$#], 0, [],
- [$#], 1, [$1[]],
- [$1[]$0(m4_shift($@))])])
-
-
-# m4_dquote(ARGS)
-# ---------------
-# Return ARGS as a quoted list of quoted arguments.
-m4_define([m4_dquote], [[$@]])
-
-
-# m4_dquote_elt(ARGS)
-# -------------------
-# Return ARGS as an unquoted list of double-quoted arguments.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_dquote_elt],
-[m4_if([$#], [0], [],
- [$#], [1], [[[$1]]],
- [[[$1]],$0(m4_shift($@))])])
-
-
-# m4_echo(ARGS)
-# -------------
-# Return the ARGS, with the same level of quoting. Whitespace after
-# unquoted commas are consumed.
-m4_define([m4_echo], [$@])
-
-
-# m4_expand(ARG)
-# _m4_expand(ARG)
-# ---------------
-# Return the expansion of ARG as a single string. Unlike
-# m4_quote($1), this preserves whitespace following single-quoted
-# commas that appear within ARG. It also deals with shell case
-# statements.
-#
-# m4_define([active], [ACT, IVE])
-# m4_define([active2], [[ACT, IVE]])
-# m4_quote(active, active2)
-# => ACT,IVE,ACT, IVE
-# m4_expand([active, active2])
-# => ACT, IVE, ACT, IVE
-#
-# Unfortunately, due to limitations in m4, ARG must expand to
-# something with balanced quotes (use quadrigraphs to get around
-# this), and should not contain the unlikely delimiters -=<{( or
-# )}>=-. It is possible to have unbalanced quoted `(' or `)', as well
-# as unbalanced unquoted `)'. m4_expand can handle unterminated
-# comments or dnl on the final line, at the expense of speed; it also
-# aids in detecting attempts to incorrectly change the current
-# diversion inside ARG. Meanwhile, _m4_expand is faster but must be
-# given a terminated expansion, and has no safety checks for
-# mis-diverted text.
-#
-# Exploit that extra unquoted () will group unquoted commas and the
-# following whitespace. m4_bpatsubst can't handle newlines inside $1,
-# and m4_substr strips quoting. So we (ab)use m4_changequote, using
-# temporary quotes to remove the delimiters that conveniently included
-# the unquoted () that were added prior to the changequote.
-#
-# Thanks to shell case statements, too many people are prone to pass
-# underquoted `)', so we try to detect that by passing a marker as a
-# fourth argument; if the marker is not present, then we assume that
-# we encountered an early `)', and re-expand the first argument, but
-# this time with one more `(' in the second argument and in the
-# open-quote delimiter. We must also ignore the slop from the
-# previous try. The final macro is thus half line-noise, half art.
-m4_define([m4_expand],
-[m4_pushdef([m4_divert], _m4_defn([_m4_divert_unsafe]))]dnl
-[m4_pushdef([m4_divert_push], _m4_defn([_m4_divert_unsafe]))]dnl
-[m4_chomp(_$0([$1
-]))_m4_popdef([m4_divert], [m4_divert_push])])
-
-m4_define([_m4_expand], [$0_([$1], [(], -=<{($1)}>=-, [}>=-])])
-
-m4_define([_m4_expand_],
-[m4_if([$4], [}>=-],
- [m4_changequote([-=<{$2], [)}>=-])$3m4_changequote([, ])],
- [$0([$1], [($2], -=<{($2$1)}>=-, [}>=-])m4_ignore$2])])
-
-
-# m4_ignore(ARGS)
-# ---------------
-# Expands to nothing. Useful for conditionally ignoring an arbitrary
-# number of arguments (see _m4_list_cmp for an example).
-m4_define([m4_ignore])
-
-
-# m4_make_list(ARGS)
-# ------------------
-# Similar to m4_dquote, this creates a quoted list of quoted ARGS. This
-# version is less efficient than m4_dquote, but separates each argument
-# with a comma and newline, rather than just comma, for readability.
-# When developing an m4sugar algorithm, you could temporarily use
-# m4_pushdef([m4_dquote],m4_defn([m4_make_list]))
-# around your code to make debugging easier.
-m4_define([m4_make_list], [m4_join([,
-], m4_dquote_elt($@))])
-
-
-# m4_noquote(STRING)
-# ------------------
-# Return the result of ignoring all quotes in STRING and invoking the
-# macros it contains. Among other things, this is useful for enabling
-# macro invocations inside strings with [] blocks (for instance regexps
-# and help-strings). On the other hand, since all quotes are disabled,
-# any macro expanded during this time that relies on nested [] quoting
-# will likely crash and burn. This macro is seldom useful; consider
-# m4_unquote or m4_expand instead.
-m4_define([m4_noquote],
-[m4_changequote([-=<{(],[)}>=-])$1-=<{()}>=-m4_changequote([,])])
-
-
-# m4_quote(ARGS)
-# --------------
-# Return ARGS as a single argument. Any whitespace after unquoted commas
-# is stripped. There is always output, even when there were no arguments.
-#
-# It is important to realize the difference between `m4_quote(exp)' and
-# `[exp]': in the first case you obtain the quoted *result* of the
-# expansion of EXP, while in the latter you just obtain the string
-# `exp'.
-m4_define([m4_quote], [[$*]])
-
-
-# _m4_quote(ARGS)
-# ---------------
-# Like m4_quote, except that when there are no arguments, there is no
-# output. For conditional scenarios (such as passing _m4_quote as the
-# macro name in m4_mapall), this feature can be used to distinguish between
-# one argument of the empty string vs. no arguments. However, in the
-# normal case with arguments present, this is less efficient than m4_quote.
-m4_define([_m4_quote],
-[m4_if([$#], [0], [], [[$*]])])
-
-
-# m4_reverse(ARGS)
-# ----------------
-# Output ARGS in reverse order.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_reverse],
-[m4_if([$#], [0], [], [$#], [1], [[$1]],
- [$0(m4_shift($@)), [$1]])])
-
-
-# m4_unquote(ARGS)
-# ----------------
-# Remove one layer of quotes from each ARG, performing one level of
-# expansion. For one argument, m4_unquote([arg]) is more efficient than
-# m4_do([arg]), but for multiple arguments, the difference is that
-# m4_unquote separates arguments with commas while m4_do concatenates.
-# Follow this macro with [] if concatenation with subsequent text is
-# undesired.
-m4_define([m4_unquote], [$*])
-
-
-## -------------------------- ##
-## 8. Implementing m4 loops. ##
-## -------------------------- ##
-
-
-# m4_for(VARIABLE, FIRST, LAST, [STEP = +/-1], EXPRESSION)
-# --------------------------------------------------------
-# Expand EXPRESSION defining VARIABLE to FROM, FROM + 1, ..., TO with
-# increments of STEP. Both limits are included, and bounds are
-# checked for consistency. The algorithm is robust to indirect
-# VARIABLE names. Changing VARIABLE inside EXPRESSION will not impact
-# the number of iterations.
-#
-# Uses _m4_defn for speed, and avoid dnl in the macro body. Factor
-# the _m4_for call so that EXPRESSION is only parsed once.
-m4_define([m4_for],
-[m4_pushdef([$1], m4_eval([$2]))]dnl
-[m4_cond([m4_eval(([$3]) > ([$2]))], 1,
- [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4],
- 1)))m4_assert(_m4_step > 0)_$0(_m4_defn([$1]),
- m4_eval((([$3]) - ([$2])) / _m4_step * _m4_step + ([$2])), _m4_step,],
- [m4_eval(([$3]) < ([$2]))], 1,
- [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4],
- -1)))m4_assert(_m4_step < 0)_$0(_m4_defn([$1]),
- m4_eval((([$2]) - ([$3])) / -(_m4_step) * _m4_step + ([$2])), _m4_step,],
- [m4_pushdef([_m4_step])_$0(_m4_defn([$1]), _m4_defn([$1]), 0,])]dnl
-[[m4_define([$1],], [)$5])m4_popdef([_m4_step], [$1])])
-
-# _m4_for(COUNT, LAST, STEP, PRE, POST)
-# -------------------------------------
-# Core of the loop, no consistency checks, all arguments are plain
-# numbers. Expand PRE[COUNT]POST, then alter COUNT by STEP and
-# iterate if COUNT is not LAST.
-m4_define([_m4_for],
-[$4[$1]$5[]m4_if([$1], [$2], [],
- [$0(m4_eval([$1 + $3]), [$2], [$3], [$4], [$5])])])
-
-
-# Implementing `foreach' loops in m4 is much more tricky than it may
-# seem. For example, the old M4 1.4.4 manual had an incorrect example,
-# which looked like this (when translated to m4sugar):
-#
-# | # foreach(VAR, (LIST), STMT)
-# | m4_define([foreach],
-# | [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])])
-# | m4_define([_arg1], [$1])
-# | m4_define([_foreach],
-# | [m4_if([$2], [()], ,
-# | [m4_define([$1], _arg1$2)$3[]_foreach([$1], (m4_shift$2), [$3])])])
-#
-# But then if you run
-#
-# | m4_define(a, 1)
-# | m4_define(b, 2)
-# | m4_define(c, 3)
-# | foreach([f], [([a], [(b], [c)])], [echo f
-# | ])
-#
-# it gives
-#
-# => echo 1
-# => echo (2,3)
-#
-# which is not what is expected.
-#
-# Of course the problem is that many quotes are missing. So you add
-# plenty of quotes at random places, until you reach the expected
-# result. Alternatively, if you are a quoting wizard, you directly
-# reach the following implementation (but if you really did, then
-# apply to the maintenance of m4sugar!).
-#
-# | # foreach(VAR, (LIST), STMT)
-# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
-# | m4_define([_arg1], [[$1]])
-# | m4_define([_foreach],
-# | [m4_if($2, [()], ,
-# | [m4_define([$1], [_arg1$2])$3[]_foreach([$1], [(m4_shift$2)], [$3])])])
-#
-# which this time answers
-#
-# => echo a
-# => echo (b
-# => echo c)
-#
-# Bingo!
-#
-# Well, not quite.
-#
-# With a better look, you realize that the parens are more a pain than
-# a help: since anyway you need to quote properly the list, you end up
-# with always using an outermost pair of parens and an outermost pair
-# of quotes. Rejecting the parens both eases the implementation, and
-# simplifies the use:
-#
-# | # foreach(VAR, (LIST), STMT)
-# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
-# | m4_define([_arg1], [$1])
-# | m4_define([_foreach],
-# | [m4_if($2, [], ,
-# | [m4_define([$1], [_arg1($2)])$3[]_foreach([$1], [m4_shift($2)], [$3])])])
-#
-#
-# Now, just replace the `$2' with `m4_quote($2)' in the outer `m4_if'
-# to improve robustness, and you come up with a nice implementation
-# that doesn't require extra parentheses in the user's LIST.
-#
-# But wait - now the algorithm is quadratic, because every recursion of
-# the algorithm keeps the entire LIST and merely adds another m4_shift to
-# the quoted text. If the user has a lot of elements in LIST, you can
-# bring the system to its knees with the memory m4 then requires, or trip
-# the m4 --nesting-limit recursion factor. The only way to avoid
-# quadratic growth is ensure m4_shift is expanded prior to the recursion.
-# Hence the design below.
-#
-# The M4 manual now includes a chapter devoted to this issue, with
-# the lessons learned from m4sugar. And still, this design is only
-# optimal for M4 1.6; see foreach.m4 for yet more comments on why
-# M4 1.4.x uses yet another implementation.
-
-
-# m4_foreach(VARIABLE, LIST, EXPRESSION)
-# --------------------------------------
-#
-# Expand EXPRESSION assigning each value of the LIST to VARIABLE.
-# LIST should have the form `item_1, item_2, ..., item_n', i.e. the
-# whole list must *quoted*. Quote members too if you don't want them
-# to be expanded.
-#
-# This macro is robust to active symbols:
-# | m4_define(active, [ACT, IVE])
-# | m4_foreach(Var, [active, active], [-Var-])
-# => -ACT--IVE--ACT--IVE-
-#
-# | m4_foreach(Var, [[active], [active]], [-Var-])
-# => -ACT, IVE--ACT, IVE-
-#
-# | m4_foreach(Var, [[[active]], [[active]]], [-Var-])
-# => -active--active-
-#
-# This macro is called frequently, so avoid extra expansions such as
-# m4_ifval and dnl. Also, since $2 might be quite large, try to use it
-# as little as possible in _m4_foreach; each extra use requires that much
-# more memory for expansion. So, rather than directly compare $2 against
-# [] and use m4_car/m4_cdr for recursion, we instead unbox the list (which
-# requires swapping the argument order in the helper), insert an ignored
-# third argument, and use m4_shift3 to detect when recursion is complete,
-# at which point this looks very much like m4_map_args.
-m4_define([m4_foreach],
-[m4_if([$2], [], [],
- [m4_pushdef([$1])_$0([m4_define([$1],], [)$3], [],
- $2)m4_popdef([$1])])])
-
-# _m4_foreach(PRE, POST, IGNORED, ARG...)
-# ---------------------------------------
-# Form the common basis of the m4_foreach and m4_map macros. For each
-# ARG, expand PRE[ARG]POST[]. The IGNORED argument makes recursion
-# easier, and must be supplied rather than implicit.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([_m4_foreach],
-[m4_if([$#], [3], [],
- [$1[$4]$2[]$0([$1], [$2], m4_shift3($@))])])
-
-
-# m4_foreach_w(VARIABLE, LIST, EXPRESSION)
-# ----------------------------------------
-# Like m4_foreach, but the list is whitespace separated. Depending on
-# EXPRESSION, it may be more efficient to use m4_map_args_w.
-#
-# This macro is robust to active symbols:
-# m4_foreach_w([Var], [ active
-# b act\
-# ive ], [-Var-])end
-# => -active--b--active-end
-#
-# This used to use a slower implementation based on m4_foreach:
-# m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])
-m4_define([m4_foreach_w],
-[m4_pushdef([$1])m4_map_args_w([$2],
- [m4_define([$1],], [)$3])m4_popdef([$1])])
-
-
-# m4_map(MACRO, LIST)
-# m4_mapall(MACRO, LIST)
-# ----------------------
-# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements of
-# LIST. $1, $2... must in turn be lists, appropriate for m4_apply.
-# If LIST contains an empty sublist, m4_map skips the expansion of
-# MACRO, while m4_mapall expands MACRO with no arguments.
-#
-# Since LIST may be quite large, we want to minimize how often it
-# appears in the expansion. Rather than use m4_car/m4_cdr iteration,
-# we unbox the list, and use _m4_foreach for iteration. For m4_map,
-# an empty list behaves like an empty sublist and gets ignored; for
-# m4_mapall, we must special-case the empty list.
-m4_define([m4_map],
-[_m4_foreach([_m4_apply([$1],], [)], [], $2)])
-
-m4_define([m4_mapall],
-[m4_if([$2], [], [],
- [_m4_foreach([m4_apply([$1],], [)], [], $2)])])
-
-
-# m4_map_sep(MACRO, [SEPARATOR], LIST)
-# m4_mapall_sep(MACRO, [SEPARATOR], LIST)
-# ---------------------------------------
-# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1,
-# $2... $N are the elements of LIST, and are in turn lists appropriate
-# for m4_apply. SEPARATOR is expanded, in order to allow the creation
-# of a list of arguments by using a single-quoted comma as the
-# separator. For each empty sublist, m4_map_sep skips the expansion
-# of MACRO and SEPARATOR, while m4_mapall_sep expands MACRO with no
-# arguments.
-#
-# For m4_mapall_sep, merely expand the first iteration without the
-# separator, then include separator as part of subsequent recursion;
-# but avoid extra expansion of LIST's side-effects via a helper macro.
-# For m4_map_sep, things are trickier - we don't know if the first
-# list element is an empty sublist, so we must define a self-modifying
-# helper macro and use that as the separator instead.
-m4_define([m4_map_sep],
-[m4_pushdef([m4_Sep], [m4_define([m4_Sep], _m4_defn([m4_unquote]))])]dnl
-[_m4_foreach([_m4_apply([m4_Sep([$2])[]$1],], [)], [], $3)m4_popdef([m4_Sep])])
-
-m4_define([m4_mapall_sep],
-[m4_if([$3], [], [], [_$0([$1], [$2], $3)])])
-
-m4_define([_m4_mapall_sep],
-[m4_apply([$1], [$3])_m4_foreach([m4_apply([$2[]$1],], [)], m4_shift2($@))])
-
-# m4_map_args(EXPRESSION, ARG...)
-# -------------------------------
-# Expand EXPRESSION([ARG]) for each argument. More efficient than
-# m4_foreach([var], [ARG...], [EXPRESSION(m4_defn([var]))])
-# Shorthand for m4_map_args_sep([EXPRESSION(], [)], [], ARG...).
-m4_define([m4_map_args],
-[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
- [$#], [1], [],
- [$#], [2], [$1([$2])[]],
- [_m4_foreach([$1(], [)], $@)])])
-
-
-# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
-# -------------------------------------------------------------
-# Perform a pairwise grouping of consecutive ARGs, by expanding
-# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the
-# final argument is expanded with END-EXPR([ARGn]).
-#
-# For example:
-# m4_define([show], [($*)m4_newline])dnl
-# m4_map_args_pair([show], [], [a], [b], [c], [d], [e])dnl
-# => (a,b)
-# => (c,d)
-# => (e)
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_map_args_pair],
-[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
- [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
- [$#], [2], [],
- [$#], [3], [m4_default([$2], [$1])([$3])[]],
- [$#], [4], [$1([$3], [$4])[]],
- [$1([$3], [$4])[]$0([$1], [$2], m4_shift(m4_shift3($@)))])])
-
-
-# m4_map_args_sep([PRE], [POST], [SEP], ARG...)
-# ---------------------------------------------
-# Expand PRE[ARG]POST for each argument, with SEP between arguments.
-m4_define([m4_map_args_sep],
-[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
- [$#], [1], [],
- [$#], [2], [],
- [$#], [3], [],
- [$#], [4], [$1[$4]$2[]],
- [$1[$4]$2[]_m4_foreach([$3[]$1], [$2], m4_shift3($@))])])
-
-
-# m4_map_args_w(STRING, [PRE], [POST], [SEP])
-# -------------------------------------------
-# Perform the expansion of PRE[word]POST[] for each word in STRING
-# separated by whitespace. More efficient than:
-# m4_foreach_w([var], [STRING], [PRE[]m4_defn([var])POST])
-# Additionally, expand SEP between words.
-#
-# As long as we have to use m4_bpatsubst to split the string, we might
-# as well make it also apply PRE and POST; this avoids iteration
-# altogether. But we must be careful of any \ in PRE or POST.
-# _m4_strip returns a quoted string, but that's okay, since it also
-# supplies an empty leading and trailing argument due to our
-# intentional whitespace around STRING. We use m4_substr to strip the
-# empty elements and remove the extra layer of quoting.
-m4_define([m4_map_args_w],
-[_$0(_m4_split([ ]m4_flatten([$1])[ ], [[ ]+],
- m4_if(m4_index([$2$3$4], [\]), [-1], [[$3[]$4[]$2]],
- [m4_bpatsubst([[$3[]$4[]$2]], [\\], [\\\\])])),
- m4_len([[]$3[]$4]), m4_len([$4[]$2[]]))])
-
-m4_define([_m4_map_args_w],
-[m4_substr([$1], [$2], m4_eval(m4_len([$1]) - [$2] - [$3]))])
-
-
-# m4_stack_foreach(MACRO, FUNC)
-# m4_stack_foreach_lifo(MACRO, FUNC)
-# ----------------------------------
-# Pass each stacked definition of MACRO to the one-argument macro FUNC.
-# m4_stack_foreach proceeds in FIFO order, while m4_stack_foreach_lifo
-# processes the topmost definitions first. In addition, FUNC should
-# not push or pop definitions of MACRO, and should not expect anything about
-# the active definition of MACRO (it will not be the topmost, and may not
-# be the one passed to FUNC either).
-#
-# Some macros simply can't be examined with this method: namely,
-# anything involved in the implementation of _m4_stack_reverse.
-m4_define([m4_stack_foreach],
-[_m4_stack_reverse([$1], [m4_tmp-$1])]dnl
-[_m4_stack_reverse([m4_tmp-$1], [$1], [$2(_m4_defn([m4_tmp-$1]))])])
-
-m4_define([m4_stack_foreach_lifo],
-[_m4_stack_reverse([$1], [m4_tmp-$1], [$2(_m4_defn([m4_tmp-$1]))])]dnl
-[_m4_stack_reverse([m4_tmp-$1], [$1])])
-
-# m4_stack_foreach_sep(MACRO, [PRE], [POST], [SEP])
-# m4_stack_foreach_sep_lifo(MACRO, [PRE], [POST], [SEP])
-# ------------------------------------------------------
-# Similar to m4_stack_foreach and m4_stack_foreach_lifo, in that every
-# definition of a pushdef stack will be visited. But rather than
-# passing the definition as a single argument to a macro, this variant
-# expands the concatenation of PRE[]definition[]POST, and expands SEP
-# between consecutive expansions. Note that m4_stack_foreach([a], [b])
-# is equivalent to m4_stack_foreach_sep([a], [b(], [)]).
-m4_define([m4_stack_foreach_sep],
-[_m4_stack_reverse([$1], [m4_tmp-$1])]dnl
-[_m4_stack_reverse([m4_tmp-$1], [$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4[]])])
-
-m4_define([m4_stack_foreach_sep_lifo],
-[_m4_stack_reverse([$1], [m4_tmp-$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4[]])]dnl
-[_m4_stack_reverse([m4_tmp-$1], [$1])])
-
-
-# _m4_stack_reverse(OLD, NEW, [ACTION], [SEP])
-# --------------------------------------------
-# A recursive worker for pushdef stack manipulation. Destructively
-# copy the OLD stack into the NEW, and expanding ACTION for each
-# iteration. After the first iteration, SEP is promoted to the front
-# of ACTION (note that SEP should include a trailing [] if it is to
-# avoid interfering with ACTION). The current definition is examined
-# after the NEW has been pushed but before OLD has been popped; this
-# order is important, as ACTION is permitted to operate on either
-# _m4_defn([OLD]) or _m4_defn([NEW]). Since the operation is
-# destructive, this macro is generally used twice, with a temporary
-# macro name holding the swapped copy.
-m4_define([_m4_stack_reverse],
-[m4_ifdef([$1], [m4_pushdef([$2],
- _m4_defn([$1]))$3[]_m4_popdef([$1])$0([$1], [$2], [$4$3])])])
-
-
-
-## --------------------------- ##
-## 9. More diversion support. ##
-## --------------------------- ##
-
-
-# m4_cleardivert(DIVERSION-NAME...)
-# ---------------------------------
-# Discard any text in DIVERSION-NAME.
-#
-# This works even inside m4_expand.
-m4_define([m4_cleardivert],
-[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
- [_m4_divert_raw([-1])m4_undivert($@)_m4_divert_raw(
- _m4_divert(_m4_defn([_m4_divert_diversion]), [-]))])])
-
-
-# _m4_divert(DIVERSION-NAME or NUMBER, [NOWARN])
-# ----------------------------------------------
-# If DIVERSION-NAME is the name of a diversion, return its number,
-# otherwise if it is a NUMBER return it. Issue a warning about
-# the use of a number instead of a name, unless NOWARN is provided.
-m4_define([_m4_divert],
-[m4_ifdef([_m4_divert($1)],
- [m4_indir([_m4_divert($1)])],
- [m4_if([$2], [], [m4_warn([syntax],
- [prefer named diversions])])$1])])
-
-# KILL is only used to suppress output.
-m4_define([_m4_divert(KILL)], -1)
-
-# The empty diversion name is a synonym for 0.
-m4_define([_m4_divert()], 0)
-
-
-# m4_divert_stack
-# ---------------
-# Print the diversion stack, if it's nonempty. The caller is
-# responsible for any leading or trailing newline.
-m4_define([m4_divert_stack],
-[m4_stack_foreach_sep_lifo([_m4_divert_stack], [], [], [
-])])
-
-
-# m4_divert_stack_push(MACRO-NAME, DIVERSION-NAME)
-# ------------------------------------------------
-# Form an entry of the diversion stack from caller MACRO-NAME and
-# entering DIVERSION-NAME and push it.
-m4_define([m4_divert_stack_push],
-[m4_pushdef([_m4_divert_stack], m4_location[: $1: $2])])
-
-
-# m4_divert(DIVERSION-NAME)
-# -------------------------
-# Change the diversion stream to DIVERSION-NAME.
-m4_define([m4_divert],
-[m4_popdef([_m4_divert_stack])]dnl
-[m4_define([_m4_divert_diversion], [$1])]dnl
-[m4_divert_stack_push([$0], [$1])]dnl
-[_m4_divert_raw(_m4_divert([$1]))])
-
-
-# m4_divert_push(DIVERSION-NAME, [NOWARN])
-# ----------------------------------------
-# Change the diversion stream to DIVERSION-NAME, while stacking old values.
-# For internal use only: if NOWARN is not empty, DIVERSION-NAME can be a
-# number instead of a name.
-m4_define([m4_divert_push],
-[m4_divert_stack_push([$0], [$1])]dnl
-[m4_pushdef([_m4_divert_diversion], [$1])]dnl
-[_m4_divert_raw(_m4_divert([$1], [$2]))])
-
-
-# m4_divert_pop([DIVERSION-NAME])
-# -------------------------------
-# Change the diversion stream to its previous value, unstacking it.
-# If specified, verify we left DIVERSION-NAME.
-# When we pop the last value from the stack, we divert to -1.
-m4_define([m4_divert_pop],
-[m4_if([$1], [], [],
- [$1], _m4_defn([_m4_divert_diversion]), [],
- [m4_fatal([$0($1): diversion mismatch:
-]m4_divert_stack)])]dnl
-[_m4_popdef([_m4_divert_stack], [_m4_divert_diversion])]dnl
-[m4_ifdef([_m4_divert_diversion], [],
- [m4_fatal([too many m4_divert_pop])])]dnl
-[_m4_divert_raw(_m4_divert(_m4_defn([_m4_divert_diversion]), [-]))])
-
-
-# m4_divert_text(DIVERSION-NAME, CONTENT)
-# ---------------------------------------
-# Output CONTENT into DIVERSION-NAME (which may be a number actually).
-# An end of line is appended for free to CONTENT.
-m4_define([m4_divert_text],
-[m4_divert_push([$1])$2
-m4_divert_pop([$1])])
-
-
-# m4_divert_once(DIVERSION-NAME, CONTENT)
-# ---------------------------------------
-# Output CONTENT into DIVERSION-NAME once, if not already there.
-# An end of line is appended for free to CONTENT.
-m4_define([m4_divert_once],
-[m4_expand_once([m4_divert_text([$1], [$2])])])
-
-
-# _m4_divert_unsafe(DIVERSION-NAME)
-# ---------------------------------
-# Issue a warning that the attempt to change the current diversion to
-# DIVERSION-NAME is unsafe, because this macro is being expanded
-# during argument collection of m4_expand.
-m4_define([_m4_divert_unsafe],
-[m4_fatal([$0: cannot change diversion to `$1' inside m4_expand])])
-
-
-# m4_undivert(DIVERSION-NAME...)
-# ------------------------------
-# Undivert DIVERSION-NAME. Unlike the M4 version, this requires at
-# least one DIVERSION-NAME; also, due to support for named diversions,
-# this should not be used to undivert files.
-m4_define([m4_undivert],
-[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
- [$#], [1], [_m4_undivert(_m4_divert([$1]))],
- [m4_map_args([$0], $@)])])
-
-
-## --------------------------------------------- ##
-## 10. Defining macros with bells and whistles. ##
-## --------------------------------------------- ##
-
-# `m4_defun' is basically `m4_define' but it equips the macro with the
-# needed machinery for `m4_require'. A macro must be m4_defun'd if
-# either it is m4_require'd, or it m4_require's.
-#
-# Two things deserve attention and are detailed below:
-# 1. Implementation of m4_require
-# 2. Keeping track of the expansion stack
-#
-# 1. Implementation of m4_require
-# ===============================
-#
-# Of course m4_defun calls m4_provide, so that a macro which has
-# been expanded is not expanded again when m4_require'd, but the
-# difficult part is the proper expansion of macros when they are
-# m4_require'd.
-#
-# The implementation is based on three ideas, (i) using diversions to
-# prepare the expansion of the macro and its dependencies (by Franc,ois
-# Pinard), (ii) expand the most recently m4_require'd macros _after_
-# the previous macros (by Axel Thimm), and (iii) track instances of
-# provide before require (by Eric Blake).
-#
-#
-# The first idea: why use diversions?
-# -----------------------------------
-#
-# When a macro requires another, the other macro is expanded in new
-# diversion, GROW. When the outer macro is fully expanded, we first
-# undivert the most nested diversions (GROW - 1...), and finally
-# undivert GROW. To understand why we need several diversions,
-# consider the following example:
-#
-# | m4_defun([TEST1], [Test...m4_require([TEST2])1])
-# | m4_defun([TEST2], [Test...m4_require([TEST3])2])
-# | m4_defun([TEST3], [Test...3])
-#
-# Because m4_require is not required to be first in the outer macros, we
-# must keep the expansions of the various levels of m4_require separated.
-# Right before executing the epilogue of TEST1, we have:
-#
-# GROW - 2: Test...3
-# GROW - 1: Test...2
-# GROW: Test...1
-# BODY:
-#
-# Finally the epilogue of TEST1 undiverts GROW - 2, GROW - 1, and
-# GROW into the regular flow, BODY.
-#
-# GROW - 2:
-# GROW - 1:
-# GROW:
-# BODY: Test...3; Test...2; Test...1
-#
-# (The semicolons are here for clarification, but of course are not
-# emitted.) This is what Autoconf 2.0 (I think) to 2.13 (I'm sure)
-# implement.
-#
-#
-# The second idea: first required first out
-# -----------------------------------------
-#
-# The natural implementation of the idea above is buggy and produces
-# very surprising results in some situations. Let's consider the
-# following example to explain the bug:
-#
-# | m4_defun([TEST1], [m4_require([TEST2a])m4_require([TEST2b])])
-# | m4_defun([TEST2a], [])
-# | m4_defun([TEST2b], [m4_require([TEST3])])
-# | m4_defun([TEST3], [m4_require([TEST2a])])
-# |
-# | AC_INIT
-# | TEST1
-#
-# The dependencies between the macros are:
-#
-# 3 --- 2b
-# / \ is m4_require'd by
-# / \ left -------------------- right
-# 2a ------------ 1
-#
-# If you strictly apply the rules given in the previous section you get:
-#
-# GROW - 2: TEST3
-# GROW - 1: TEST2a; TEST2b
-# GROW: TEST1
-# BODY:
-#
-# (TEST2a, although required by TEST3 is not expanded in GROW - 3
-# because is has already been expanded before in GROW - 1, so it has
-# been AC_PROVIDE'd, so it is not expanded again) so when you undivert
-# the stack of diversions, you get:
-#
-# GROW - 2:
-# GROW - 1:
-# GROW:
-# BODY: TEST3; TEST2a; TEST2b; TEST1
-#
-# i.e., TEST2a is expanded after TEST3 although the latter required the
-# former.
-#
-# Starting from 2.50, we use an implementation provided by Axel Thimm.
-# The idea is simple: the order in which macros are emitted must be the
-# same as the one in which macros are expanded. (The bug above can
-# indeed be described as: a macro has been m4_provide'd before its
-# dependent, but it is emitted after: the lack of correlation between
-# emission and expansion order is guilty).
-#
-# How to do that? You keep the stack of diversions to elaborate the
-# macros, but each time a macro is fully expanded, emit it immediately.
-#
-# In the example above, when TEST2a is expanded, but it's epilogue is
-# not run yet, you have:
-#
-# GROW - 2:
-# GROW - 1: TEST2a
-# GROW: Elaboration of TEST1
-# BODY:
-#
-# The epilogue of TEST2a emits it immediately:
-#
-# GROW - 2:
-# GROW - 1:
-# GROW: Elaboration of TEST1
-# BODY: TEST2a
-#
-# TEST2b then requires TEST3, so right before the epilogue of TEST3, you
-# have:
-#
-# GROW - 2: TEST3
-# GROW - 1: Elaboration of TEST2b
-# GROW: Elaboration of TEST1
-# BODY: TEST2a
-#
-# The epilogue of TEST3 emits it:
-#
-# GROW - 2:
-# GROW - 1: Elaboration of TEST2b
-# GROW: Elaboration of TEST1
-# BODY: TEST2a; TEST3
-#
-# TEST2b is now completely expanded, and emitted:
-#
-# GROW - 2:
-# GROW - 1:
-# GROW: Elaboration of TEST1
-# BODY: TEST2a; TEST3; TEST2b
-#
-# and finally, TEST1 is finished and emitted:
-#
-# GROW - 2:
-# GROW - 1:
-# GROW:
-# BODY: TEST2a; TEST3; TEST2b: TEST1
-#
-# The idea is simple, but the implementation is a bit involved. If
-# you are like me, you will want to see the actual functioning of this
-# implementation to be convinced. The next section gives the full
-# details.
-#
-#
-# The Axel Thimm implementation at work
-# -------------------------------------
-#
-# We consider the macros above, and this configure.ac:
-#
-# AC_INIT
-# TEST1
-#
-# You should keep the definitions of _m4_defun_pro, _m4_defun_epi, and
-# m4_require at hand to follow the steps.
-#
-# This implementation tries not to assume that the current diversion is
-# BODY, so as soon as a macro (m4_defun'd) is expanded, we first
-# record the current diversion under the name _m4_divert_dump (denoted
-# DUMP below for short). This introduces an important difference with
-# the previous versions of Autoconf: you cannot use m4_require if you
-# are not inside an m4_defun'd macro, and especially, you cannot
-# m4_require directly from the top level.
-#
-# We have not tried to simulate the old behavior (better yet, we
-# diagnose it), because it is too dangerous: a macro m4_require'd from
-# the top level is expanded before the body of `configure', i.e., before
-# any other test was run. I let you imagine the result of requiring
-# AC_STDC_HEADERS for instance, before AC_PROG_CC was actually run....
-#
-# After AC_INIT was run, the current diversion is BODY.
-# * AC_INIT was run
-# DUMP: undefined
-# diversion stack: BODY |-
-#
-# * TEST1 is expanded
-# The prologue of TEST1 sets _m4_divert_dump, which is the diversion
-# where the current elaboration will be dumped, to the current
-# diversion. It also m4_divert_push to GROW, where the full
-# expansion of TEST1 and its dependencies will be elaborated.
-# DUMP: BODY
-# BODY: empty
-# diversions: GROW, BODY |-
-#
-# * TEST1 requires TEST2a
-# _m4_require_call m4_divert_pushes another temporary diversion,
-# GROW - 1, and expands TEST2a in there.
-# DUMP: BODY
-# BODY: empty
-# GROW - 1: TEST2a
-# diversions: GROW - 1, GROW, BODY |-
-# Then the content of the temporary diversion is moved to DUMP and the
-# temporary diversion is popped.
-# DUMP: BODY
-# BODY: TEST2a
-# diversions: GROW, BODY |-
-#
-# * TEST1 requires TEST2b
-# Again, _m4_require_call pushes GROW - 1 and heads to expand TEST2b.
-# DUMP: BODY
-# BODY: TEST2a
-# diversions: GROW - 1, GROW, BODY |-
-#
-# * TEST2b requires TEST3
-# _m4_require_call pushes GROW - 2 and expands TEST3 here.
-# (TEST3 requires TEST2a, but TEST2a has already been m4_provide'd, so
-# nothing happens.)
-# DUMP: BODY
-# BODY: TEST2a
-# GROW - 2: TEST3
-# diversions: GROW - 2, GROW - 1, GROW, BODY |-
-# Then the diversion is appended to DUMP, and popped.
-# DUMP: BODY
-# BODY: TEST2a; TEST3
-# diversions: GROW - 1, GROW, BODY |-
-#
-# * TEST1 requires TEST2b (contd.)
-# The content of TEST2b is expanded...
-# DUMP: BODY
-# BODY: TEST2a; TEST3
-# GROW - 1: TEST2b,
-# diversions: GROW - 1, GROW, BODY |-
-# ... and moved to DUMP.
-# DUMP: BODY
-# BODY: TEST2a; TEST3; TEST2b
-# diversions: GROW, BODY |-
-#
-# * TEST1 is expanded: epilogue
-# TEST1's own content is in GROW...
-# DUMP: BODY
-# BODY: TEST2a; TEST3; TEST2b
-# GROW: TEST1
-# diversions: BODY |-
-# ... and it's epilogue moves it to DUMP and then undefines DUMP.
-# DUMP: undefined
-# BODY: TEST2a; TEST3; TEST2b; TEST1
-# diversions: BODY |-
-#
-#
-# The third idea: track macros provided before they were required
-# ---------------------------------------------------------------
-#
-# Using just the first two ideas, Autoconf 2.50 through 2.63 still had
-# a subtle bug for more than seven years. Let's consider the
-# following example to explain the bug:
-#
-# | m4_defun([TEST1], [1])
-# | m4_defun([TEST2], [2[]m4_require([TEST1])])
-# | m4_defun([TEST3], [3 TEST1 m4_require([TEST2])])
-# | TEST3
-#
-# After the prologue of TEST3, we are collecting text in GROW with the
-# intent of dumping it in BODY during the epilogue. Next, we
-# encounter the direct invocation of TEST1, which provides the macro
-# in place in GROW. From there, we encounter a requirement for TEST2,
-# which must be collected in a new diversion. While expanding TEST2,
-# we encounter a requirement for TEST1, but since it has already been
-# expanded, the Axel Thimm algorithm states that we can treat it as a
-# no-op. But that would lead to an end result of `2 3 1', meaning
-# that we have once again output a macro (TEST2) prior to its
-# requirements (TEST1).
-#
-# The problem can only occur if a single defun'd macro first provides,
-# then later indirectly requires, the same macro. Note that directly
-# expanding then requiring a macro is okay: because the dependency was
-# met, the require phase can be a no-op. For that matter, the outer
-# macro can even require two helpers, where the first helper expands
-# the macro, and the second helper indirectly requires the macro.
-# Out-of-order expansion is only present if the inner macro is
-# required by something that will be hoisted in front of where the
-# direct expansion occurred. In other words, we must be careful not
-# to warn on:
-#
-# | m4_defun([TEST4], [4])
-# | m4_defun([TEST5], [5 TEST4 m4_require([TEST4])])
-# | TEST5 => 5 4
-#
-# or even the more complex:
-#
-# | m4_defun([TEST6], [6])
-# | m4_defun([TEST7], [7 TEST6])
-# | m4_defun([TEST8], [8 m4_require([TEST6])])
-# | m4_defun([TEST9], [9 m4_require([TEST8])])
-# | m4_defun([TEST10], [10 m4_require([TEST7]) m4_require([TEST9])])
-# | TEST10 => 7 6 8 9 10
-#
-# So, to detect whether a require was direct or indirect, m4_defun and
-# m4_require track the name of the macro that caused a diversion to be
-# created (using the stack _m4_diverting, coupled with an O(1) lookup
-# _m4_diverting([NAME])), and m4_provide stores the name associated
-# with the diversion at which a macro was provided. A require call is
-# direct if it occurs within the same diversion where the macro was
-# provided, or if the diversion associated with the providing context
-# has been collected.
-#
-# The implementation of the warning involves tracking the set of
-# macros which have been provided since the start of the outermost
-# defun'd macro (the set is named _m4_provide). When starting an
-# outermost macro, the set is emptied; when a macro is provided, it is
-# added to the set; when require expands the body of a macro, it is
-# removed from the set; and when a macro is indirectly required, the
-# set is checked. If a macro is in the set, then it has been provided
-# before it was required, and we satisfy dependencies by expanding the
-# macro as if it had never been provided; in the example given above,
-# this means we now output `1 2 3 1'. Meanwhile, a warning is issued
-# to inform the user that her macros trigger the bug in older autoconf
-# versions, and that her output file now contains redundant contents
-# (and possibly new problems, if the repeated macro was not
-# idempotent). Meanwhile, macros defined by m4_defun_once instead of
-# m4_defun are idempotent, avoiding any warning or duplicate output.
-#
-#
-# 2. Keeping track of the expansion stack
-# =======================================
-#
-# When M4 expansion goes wrong it is often extremely hard to find the
-# path amongst macros that drove to the failure. What is needed is
-# the stack of macro `calls'. One could imagine that GNU M4 would
-# maintain a stack of macro expansions, unfortunately it doesn't, so
-# we do it by hand. This is of course extremely costly, but the help
-# this stack provides is worth it. Nevertheless to limit the
-# performance penalty this is implemented only for m4_defun'd macros,
-# not for define'd macros.
-#
-# Each time we enter an m4_defun'd macros, we add a definition in
-# _m4_expansion_stack, and when we exit the macro, we remove it (thanks
-# to pushdef/popdef). m4_stack_foreach is used to print the expansion
-# stack in the rare cases when it's needed.
-#
-# In addition, we want to detect circular m4_require dependencies.
-# Each time we expand a macro FOO we define _m4_expanding(FOO); and
-# m4_require(BAR) simply checks whether _m4_expanding(BAR) is defined.
-
-
-# m4_expansion_stack
-# ------------------
-# Expands to the entire contents of the expansion stack. The caller
-# must supply a trailing newline. This macro always prints a
-# location; check whether _m4_expansion_stack is defined to filter out
-# the case when no defun'd macro is in force.
-m4_define([m4_expansion_stack],
-[m4_stack_foreach_sep_lifo([_$0], [_$0_entry(], [)
-])m4_location[: the top level]])
-
-# _m4_expansion_stack_entry(MACRO)
-# --------------------------------
-# Format an entry for MACRO found on the expansion stack.
-m4_define([_m4_expansion_stack_entry],
-[_m4_defn([m4_location($1)])[: $1 is expanded from...]])
-
-# m4_expansion_stack_push(MACRO)
-# ------------------------------
-# Form an entry of the expansion stack on entry to MACRO and push it.
-m4_define([m4_expansion_stack_push],
-[m4_pushdef([_m4_expansion_stack], [$1])])
-
-
-# _m4_divert(GROW)
-# ----------------
-# This diversion is used by the m4_defun/m4_require machinery. It is
-# important to keep room before GROW because for each nested
-# AC_REQUIRE we use an additional diversion (i.e., two m4_require's
-# will use GROW - 2. More than 3 levels has never seemed to be
-# needed.)
-#
-# ...
-# - GROW - 2
-# m4_require'd code, 2 level deep
-# - GROW - 1
-# m4_require'd code, 1 level deep
-# - GROW
-# m4_defun'd macros are elaborated here.
-
-m4_define([_m4_divert(GROW)], 10000)
-
-
-# _m4_defun_pro(MACRO-NAME)
-# -------------------------
-# The prologue for Autoconf macros.
-#
-# This is called frequently, so minimize the number of macro invocations
-# by avoiding dnl and m4_defn overhead.
-m4_define([_m4_defun_pro],
-[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_pro_outer([$1])])]dnl
-[m4_expansion_stack_push([$1])m4_pushdef([_m4_expanding($1)])])
-
-m4_define([_m4_defun_pro_outer],
-[m4_set_delete([_m4_provide])]dnl
-[m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl
-[m4_pushdef([_m4_divert_dump], m4_divnum)m4_divert_push([GROW])])
-
-# _m4_defun_epi(MACRO-NAME)
-# -------------------------
-# The Epilogue for Autoconf macros. MACRO-NAME only helps tracing
-# the PRO/EPI pairs.
-#
-# This is called frequently, so minimize the number of macro invocations
-# by avoiding dnl and m4_popdef overhead.
-m4_define([_m4_defun_epi],
-[_m4_popdef([_m4_expanding($1)], [_m4_expansion_stack])]dnl
-[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_epi_outer([$1])])]dnl
-[m4_provide([$1])])
-
-m4_define([_m4_defun_epi_outer],
-[_m4_popdef([_m4_divert_dump], [_m4_diverting([$1])], [_m4_diverting])]dnl
-[m4_divert_pop([GROW])m4_undivert([GROW])])
-
-
-# _m4_divert_dump
-# ---------------
-# If blank, we are outside of any defun'd macro. Otherwise, expands
-# to the diversion number (not name) where require'd macros should be
-# moved once completed.
-m4_define([_m4_divert_dump])
-
-
-# m4_divert_require(DIVERSION, NAME-TO-CHECK, [BODY-TO-EXPAND])
-# -------------------------------------------------------------
-# Same as m4_require, but BODY-TO-EXPAND goes into the named DIVERSION;
-# requirements still go in the current diversion though.
-#
-m4_define([m4_divert_require],
-[m4_ifdef([_m4_expanding($2)],
- [m4_fatal([$0: circular dependency of $2])])]dnl
-[m4_if(_m4_divert_dump, [],
- [m4_fatal([$0($2): cannot be used outside of an m4_defun'd macro])])]dnl
-[m4_provide_if([$2], [],
- [_m4_require_call([$2], [$3], _m4_divert([$1], [-]))])])
-
-
-# m4_defun(NAME, EXPANSION, [MACRO = m4_define])
-# ----------------------------------------------
-# Define a macro NAME which automatically provides itself. Add
-# machinery so the macro automatically switches expansion to the
-# diversion stack if it is not already using it, prior to EXPANSION.
-# In this case, once finished, it will bring back all the code
-# accumulated in the diversion stack. This, combined with m4_require,
-# achieves the topological ordering of macros. We don't use this
-# macro to define some frequently called macros that are not involved
-# in ordering constraints, to save m4 processing.
-#
-# MACRO is an undocumented argument; when set to m4_pushdef, and NAME
-# is already defined, the new definition is added to the pushdef
-# stack, rather than overwriting the current definition. It can thus
-# be used to write self-modifying macros, which pop themselves to a
-# previously m4_define'd definition so that subsequent use of the
-# macro is faster.
-m4_define([m4_defun],
-[m4_define([m4_location($1)], m4_location)]dnl
-[m4_default([$3], [m4_define])([$1],
- [_m4_defun_pro(]m4_dquote($[0])[)$2[]_m4_defun_epi(]m4_dquote($[0])[)])])
-
-
-# m4_defun_init(NAME, INIT, COMMON)
-# ---------------------------------
-# Like m4_defun, but split EXPANSION into two portions: INIT which is
-# done only the first time NAME is invoked, and COMMON which is
-# expanded every time.
-#
-# For now, the COMMON definition is always m4_define'd, giving an even
-# lighter-weight definition. m4_defun allows self-providing, but once
-# a macro is provided, m4_require no longer cares if it is m4_define'd
-# or m4_defun'd. m4_defun also provides location tracking to identify
-# dependency bugs, but once the INIT has been expanded, we know there
-# are no dependency bugs. However, if a future use needs COMMON to be
-# m4_defun'd, we can add a parameter, similar to the third parameter
-# to m4_defun.
-m4_define([m4_defun_init],
-[m4_define([$1], [$3[]])m4_defun([$1],
- [$2[]_m4_popdef(]m4_dquote($[0])[)m4_indir(]m4_dquote($[0])dnl
-[m4_if(]m4_dquote($[#])[, [0], [], ]m4_dquote([,$]@)[))], [m4_pushdef])])
-
-
-# m4_defun_once(NAME, EXPANSION)
-# ------------------------------
-# Like m4_defun, but guarantee that EXPANSION only happens once
-# (thereafter, using NAME is a no-op).
-#
-# If _m4_divert_dump is empty, we are called at the top level;
-# otherwise, we must ensure that we are required in front of the
-# current defun'd macro. Use a helper macro so that EXPANSION need
-# only occur once in the definition of NAME, since it might be large.
-m4_define([m4_defun_once],
-[m4_define([m4_location($1)], m4_location)]dnl
-[m4_define([$1], [_m4_defun_once([$1], [$2], m4_if(_m4_divert_dump, [],
- [[_m4_defun_pro([$1])m4_unquote(], [)_m4_defun_epi([$1])]],
-m4_ifdef([_m4_diverting([$1])], [-]), [-], [[m4_unquote(], [)]],
- [[_m4_require_call([$1],], [, _m4_divert_dump)]]))])])
-
-m4_define([_m4_defun_once],
-[m4_pushdef([$1])$3[$2[]m4_provide([$1])]$4])
-
-
-# m4_pattern_forbid(ERE, [WHY])
-# -----------------------------
-# Declare that no token matching the forbidden extended regular
-# expression ERE should be seen in the output unless...
-m4_define([m4_pattern_forbid], [])
-
-
-# m4_pattern_allow(ERE)
-# ---------------------
-# ... that token also matches the allowed extended regular expression ERE.
-# Both used via traces.
-m4_define([m4_pattern_allow], [])
-
-
-## --------------------------------- ##
-## 11. Dependencies between macros. ##
-## --------------------------------- ##
-
-
-# m4_before(THIS-MACRO-NAME, CALLED-MACRO-NAME)
-# ---------------------------------------------
-# Issue a warning if CALLED-MACRO-NAME was called before THIS-MACRO-NAME.
-m4_define([m4_before],
-[m4_provide_if([$2],
- [m4_warn([syntax], [$2 was called before $1])])])
-
-
-# m4_require(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])
-# -----------------------------------------------------------
-# If NAME-TO-CHECK has never been expanded (actually, if it is not
-# m4_provide'd), expand BODY-TO-EXPAND *before* the current macro
-# expansion; follow the expansion with a newline. Once expanded, emit
-# it in _m4_divert_dump. Keep track of the m4_require chain in
-# _m4_expansion_stack.
-#
-# The normal cases are:
-#
-# - NAME-TO-CHECK == BODY-TO-EXPAND
-# Which you can use for regular macros with or without arguments, e.g.,
-# m4_require([AC_PROG_CC], [AC_PROG_CC])
-# m4_require([AC_CHECK_HEADERS(threads.h)], [AC_CHECK_HEADERS(threads.h)])
-# which is just the same as
-# m4_require([AC_PROG_CC])
-# m4_require([AC_CHECK_HEADERS(threads.h)])
-#
-# - BODY-TO-EXPAND == m4_indir([NAME-TO-CHECK])
-# In the case of macros with irregular names. For instance:
-# m4_require([AC_LANG_COMPILER(C)], [indir([AC_LANG_COMPILER(C)])])
-# which means `if the macro named `AC_LANG_COMPILER(C)' (the parens are
-# part of the name, it is not an argument) has not been run, then
-# call it.'
-# Had you used
-# m4_require([AC_LANG_COMPILER(C)], [AC_LANG_COMPILER(C)])
-# then m4_require would have tried to expand `AC_LANG_COMPILER(C)', i.e.,
-# call the macro `AC_LANG_COMPILER' with `C' as argument.
-#
-# You could argue that `AC_LANG_COMPILER', when it receives an argument
-# such as `C' should dispatch the call to `AC_LANG_COMPILER(C)'. But this
-# `extension' prevents `AC_LANG_COMPILER' from having actual arguments that
-# it passes to `AC_LANG_COMPILER(C)'.
-#
-# This is called frequently, so minimize the number of macro invocations
-# by avoiding dnl and other overhead on the common path.
-m4_define([m4_require],
-[m4_ifdef([_m4_expanding($1)],
- [m4_fatal([$0: circular dependency of $1])])]dnl
-[m4_if(_m4_divert_dump, [],
- [m4_fatal([$0($1): cannot be used outside of an ]dnl
-m4_if([$0], [m4_require], [[m4_defun]], [[AC_DEFUN]])['d macro])])]dnl
-[m4_provide_if([$1], [m4_set_contains([_m4_provide], [$1],
- [_m4_require_check([$1], _m4_defn([m4_provide($1)]), [$0])], [m4_ignore])],
- [_m4_require_call])([$1], [$2], _m4_divert_dump)])
-
-
-# _m4_require_call(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK],
-# DIVERSION-NUMBER)
-# -----------------------------------------------------------------
-# If m4_require decides to expand the body, it calls this macro. The
-# expansion is placed in DIVERSION-NUMBER.
-#
-# This is called frequently, so minimize the number of macro invocations
-# by avoiding dnl and other overhead on the common path.
-# The use of a witness macro protecting the warning allows aclocal
-# to silence any warnings when probing for what macros are required
-# and must therefore be located, when using the Autoconf-without-aclocal-m4
-# autom4te language. For more background, see:
-# https://lists.gnu.org/archive/html/automake-patches/2012-11/msg00035.html
-m4_define([_m4_require_call],
-[m4_pushdef([_m4_divert_grow], m4_decr(_m4_divert_grow))]dnl
-[m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl
-[m4_divert_push(_m4_divert_grow, [-])]dnl
-[m4_if([$2], [], [$1], [$2])
-m4_provide_if([$1], [m4_set_remove([_m4_provide], [$1])],
- [m4_ifndef([m4_require_silent_probe],
- [m4_warn([syntax], [$1 is m4_require'd but not m4_defun'd])])])]dnl
-[_m4_divert_raw($3)_m4_undivert(_m4_divert_grow)]dnl
-[m4_divert_pop(_m4_divert_grow)_m4_popdef([_m4_divert_grow],
-[_m4_diverting([$1])], [_m4_diverting])])
-
-
-# _m4_require_check(NAME-TO-CHECK, OWNER, CALLER)
-# -----------------------------------------------
-# NAME-TO-CHECK has been identified as previously expanded in the
-# diversion owned by OWNER. If this is a problem, warn on behalf of
-# CALLER and return _m4_require_call; otherwise return m4_ignore.
-m4_define([_m4_require_check],
-[m4_if(_m4_defn([_m4_diverting]), [$2], [m4_ignore],
- m4_ifdef([_m4_diverting([$2])], [-]), [-], [m4_warn([syntax],
- [$3: `$1' was expanded before it was required
-http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required])_m4_require_call],
- [m4_ignore])])
-
-
-# _m4_divert_grow
-# ---------------
-# The counter for _m4_require_call.
-m4_define([_m4_divert_grow], _m4_divert([GROW]))
-
-
-# m4_expand_once(TEXT, [WITNESS = TEXT])
-# --------------------------------------
-# If TEXT has never been expanded, expand it *here*. Use WITNESS as
-# as a memory that TEXT has already been expanded.
-m4_define([m4_expand_once],
-[m4_provide_if(m4_default_quoted([$2], [$1]),
- [],
- [m4_provide(m4_default_quoted([$2], [$1]))[]$1])])
-
-
-# m4_provide(MACRO-NAME)
-# ----------------------
-m4_define([m4_provide],
-[m4_ifdef([m4_provide($1)], [],
-[m4_set_add([_m4_provide], [$1], [m4_define([m4_provide($1)],
- m4_ifdef([_m4_diverting], [_m4_defn([_m4_diverting])]))])])])
-
-
-# m4_provide_if(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
-# -------------------------------------------------------
-# If MACRO-NAME is provided do IF-PROVIDED, else IF-NOT-PROVIDED.
-# The purpose of this macro is to provide the user with a means to
-# check macros which are provided without letting her know how the
-# information is coded.
-m4_define([m4_provide_if],
-[m4_ifdef([m4_provide($1)],
- [$2], [$3])])
-
-
-## --------------------- ##
-## 12. Text processing. ##
-## --------------------- ##
-
-
-# m4_cr_letters
-# m4_cr_LETTERS
-# m4_cr_Letters
-# -------------
-m4_define([m4_cr_letters], [abcdefghijklmnopqrstuvwxyz])
-m4_define([m4_cr_LETTERS], [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
-m4_define([m4_cr_Letters],
-m4_defn([m4_cr_letters])dnl
-m4_defn([m4_cr_LETTERS])dnl
-)
-
-
-# m4_cr_digits
-# ------------
-m4_define([m4_cr_digits], [0123456789])
-
-
-# m4_cr_alnum
-# -----------
-m4_define([m4_cr_alnum],
-m4_defn([m4_cr_Letters])dnl
-m4_defn([m4_cr_digits])dnl
-)
-
-
-# m4_cr_symbols1
-# m4_cr_symbols2
-# --------------
-m4_define([m4_cr_symbols1],
-m4_defn([m4_cr_Letters])dnl
-_)
-
-m4_define([m4_cr_symbols2],
-m4_defn([m4_cr_symbols1])dnl
-m4_defn([m4_cr_digits])dnl
-)
-
-# m4_cr_all
-# ---------
-# The character range representing everything, with `-' as the last
-# character, since it is special to m4_translit. Use with care, because
-# it contains characters special to M4 (fortunately, both ASCII and EBCDIC
-# have [] in order, so m4_defn([m4_cr_all]) remains a valid string). It
-# also contains characters special to terminals, so it should never be
-# displayed in an error message. Also, attempts to map [ and ] to other
-# characters via m4_translit must deal with the fact that m4_translit does
-# not add quotes to the output.
-#
-# In EBCDIC, $ is immediately followed by *, which leads to problems
-# if m4_cr_all is inlined into a macro definition; so swap them.
-#
-# It is mainly useful in generating inverted character range maps, for use
-# in places where m4_translit is faster than an equivalent m4_bpatsubst;
-# the regex `[^a-z]' is equivalent to:
-# m4_translit(m4_dquote(m4_defn([m4_cr_all])), [a-z])
-m4_define([m4_cr_all],
-m4_translit(m4_dquote(m4_format(m4_dquote(m4_for(
- ,1,255,,[[%c]]))m4_for([i],1,255,,[,i]))), [$*-], [*$])-)
-
-
-# _m4_define_cr_not(CATEGORY)
-# ---------------------------
-# Define m4_cr_not_CATEGORY as the inverse of m4_cr_CATEGORY.
-m4_define([_m4_define_cr_not],
-[m4_define([m4_cr_not_$1],
- m4_translit(m4_dquote(m4_defn([m4_cr_all])),
- m4_defn([m4_cr_$1])))])
-
-
-# m4_cr_not_letters
-# m4_cr_not_LETTERS
-# m4_cr_not_Letters
-# m4_cr_not_digits
-# m4_cr_not_alnum
-# m4_cr_not_symbols1
-# m4_cr_not_symbols2
-# ------------------
-# Inverse character sets
-_m4_define_cr_not([letters])
-_m4_define_cr_not([LETTERS])
-_m4_define_cr_not([Letters])
-_m4_define_cr_not([digits])
-_m4_define_cr_not([alnum])
-_m4_define_cr_not([symbols1])
-_m4_define_cr_not([symbols2])
-
-
-# m4_newline([STRING])
-# --------------------
-# Expands to a newline, possibly followed by STRING. Exists mostly for
-# formatting reasons.
-m4_define([m4_newline], [
-$1])
-
-
-# m4_re_escape(STRING)
-# --------------------
-# Escape RE active characters in STRING.
-m4_define([m4_re_escape],
-[m4_bpatsubst([$1],
- [[][*+.?\^$]], [\\\&])])
-
-
-# m4_re_string
-# ------------
-# Regexp for `[a-zA-Z_0-9]*'
-# m4_dquote provides literal [] for the character class.
-m4_define([m4_re_string],
-m4_dquote(m4_defn([m4_cr_symbols2]))dnl
-[*]dnl
-)
-
-
-# m4_re_word
-# ----------
-# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*'
-m4_define([m4_re_word],
-m4_dquote(m4_defn([m4_cr_symbols1]))dnl
-m4_defn([m4_re_string])dnl
-)
-
-
-# m4_tolower(STRING)
-# m4_toupper(STRING)
-# ------------------
-# These macros convert STRING to lowercase or uppercase.
-#
-# Rather than expand the m4_defn each time, we inline them up front.
-m4_define([m4_tolower],
-[m4_translit([[$1]], ]m4_dquote(m4_defn([m4_cr_LETTERS]))[,
- ]m4_dquote(m4_defn([m4_cr_letters]))[)])
-m4_define([m4_toupper],
-[m4_translit([[$1]], ]m4_dquote(m4_defn([m4_cr_letters]))[,
- ]m4_dquote(m4_defn([m4_cr_LETTERS]))[)])
-
-
-# m4_split(STRING, [REGEXP])
-# --------------------------
-# Split STRING into an m4 list of quoted elements. The elements are
-# quoted with [ and ]. Beginning spaces and end spaces *are kept*.
-# Use m4_strip to remove them.
-#
-# REGEXP specifies where to split. Default is [\t ]+.
-#
-# If STRING is empty, the result is an empty list.
-#
-# Pay attention to the m4_changequotes. When m4 reads the definition of
-# m4_split, it still has quotes set to [ and ]. Luckily, these are matched
-# in the macro body, so the definition is stored correctly. Use the same
-# alternate quotes as m4_noquote; it must be unlikely to appear in $1.
-#
-# Also, notice that $1 is quoted twice, since we want the result to
-# be quoted. Then you should understand that the argument of
-# patsubst is -=<{(STRING)}>=- (i.e., with additional -=<{( and )}>=-).
-#
-# This macro is safe on active symbols, i.e.:
-# m4_define(active, ACTIVE)
-# m4_split([active active ])end
-# => [active], [active], []end
-#
-# Optimize on regex of ` ' (space), since m4_foreach_w already guarantees
-# that the list contains single space separators, and a common case is
-# splitting a single-element list. This macro is called frequently,
-# so avoid unnecessary dnl inside the definition.
-m4_define([m4_split],
-[m4_if([$1], [], [],
- [$2], [ ], [m4_if(m4_index([$1], [ ]), [-1], [[[$1]]],
- [_$0([$1], [$2], [, ])])],
- [$2], [], [_$0([$1], [[ ]+], [, ])],
- [_$0([$1], [$2], [, ])])])
-
-m4_define([_m4_split],
-[m4_changequote([-=<{(],[)}>=-])]dnl
-[[m4_bpatsubst(-=<{(-=<{($1)}>=-)}>=-, -=<{($2)}>=-,
- -=<{(]$3[)}>=-)]m4_changequote([, ])])
-
-
-# m4_chomp(STRING)
-# m4_chomp_all(STRING)
-# --------------------
-# Return STRING quoted, but without a trailing newline. m4_chomp
-# removes at most one newline, while m4_chomp_all removes all
-# consecutive trailing newlines. Embedded newlines are not touched,
-# and a trailing backslash-newline leaves just a trailing backslash.
-#
-# m4_bregexp is slower than m4_index, and we don't always want to
-# remove all newlines; hence the two variants. We massage characters
-# to give a nicer pattern to match, particularly since m4_bregexp is
-# line-oriented. Both versions must guarantee a match, to avoid bugs
-# with precision -1 in m4_format in older m4.
-m4_define([m4_chomp],
-[m4_format([[%.*s]], m4_index(m4_translit([[$1]], [
-/.], [/ ])[./.], [/.]), [$1])])
-
-m4_define([m4_chomp_all],
-[m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [
-/], [/ ]), [/*$]), [$1])])
-
-
-# m4_flatten(STRING)
-# ------------------
-# If STRING contains end of lines, replace them with spaces. If there
-# are backslashed end of lines, remove them. This macro is safe with
-# active symbols.
-# m4_define(active, ACTIVE)
-# m4_flatten([active
-# act\
-# ive])end
-# => active activeend
-#
-# In m4, m4_bpatsubst is expensive, so first check for a newline.
-m4_define([m4_flatten],
-[m4_if(m4_index([$1], [
-]), [-1], [[$1]],
- [m4_translit(m4_bpatsubst([[[$1]]], [\\
-]), [
-], [ ])])])
-
-
-# m4_strip(STRING)
-# ----------------
-# Expands into STRING with tabs and spaces singled out into a single
-# space, and removing leading and trailing spaces.
-#
-# This macro is robust to active symbols.
-# m4_define(active, ACTIVE)
-# m4_strip([ active <tab> <tab>active ])end
-# => active activeend
-#
-# First, notice that we guarantee trailing space. Why? Because regular
-# expressions are greedy, and `.* ?' would always group the space into the
-# .* portion. The algorithm is simpler by avoiding `?' at the end. The
-# algorithm correctly strips everything if STRING is just ` '.
-#
-# Then notice the second pattern: it is in charge of removing the
-# leading/trailing spaces. Why not just `[^ ]'? Because they are
-# applied to over-quoted strings, i.e. more or less [STRING], due
-# to the limitations of m4_bpatsubsts. So the leading space in STRING
-# is the *second* character; equally for the trailing space.
-m4_define([m4_strip],
-[m4_bpatsubsts([$1 ],
- [[ ]+], [ ],
- [^. ?\(.*\) .$], [[[\1]]])])
-
-
-# m4_normalize(STRING)
-# --------------------
-# Apply m4_flatten and m4_strip to STRING.
-#
-# The argument is quoted, so that the macro is robust to active symbols:
-#
-# m4_define(active, ACTIVE)
-# m4_normalize([ act\
-# ive
-# active ])end
-# => active activeend
-
-m4_define([m4_normalize],
-[m4_strip(m4_flatten([$1]))])
-
-
-
-# m4_join(SEP, ARG1, ARG2...)
-# ---------------------------
-# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG
-# is the empty string. No expansion is performed on SEP or ARGs.
-#
-# Since the number of arguments to join can be arbitrarily long, we
-# want to avoid having more than one $@ in the macro definition;
-# otherwise, the expansion would require twice the memory of the already
-# long list. Hence, m4_join merely looks for the first non-empty element,
-# and outputs just that element; while _m4_join looks for all non-empty
-# elements, and outputs them following a separator. The final trick to
-# note is that we decide between recursing with $0 or _$0 based on the
-# nested m4_if ending with `_'.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_join],
-[m4_if([$#], [1], [],
- [$#], [2], [[$2]],
- [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift2($@))])])
-m4_define([_m4_join],
-[m4_if([$#$2], [2], [],
- [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])])
-
-# m4_joinall(SEP, ARG1, ARG2...)
-# ------------------------------
-# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP.
-# No expansion is performed on SEP or ARGs.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_joinall], [[$2]_$0([$1], m4_shift($@))])
-m4_define([_m4_joinall],
-[m4_if([$#], [2], [], [[$1$3]$0([$1], m4_shift2($@))])])
-
-# m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX...)
-# --------------------------------------------------------
-# Produce the pairwise combination of every element in the quoted,
-# comma-separated PREFIX-LIST with every element from the SUFFIX arguments.
-# Each pair is joined with INFIX, and pairs are separated by SEPARATOR.
-# No expansion occurs on SEPARATOR, INFIX, or elements of either list.
-#
-# For example:
-# m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
-# => a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
-#
-# This definition is a bit hairy; the thing to realize is that we want
-# to construct m4_map_args_sep([[prefix$3]], [], [[$1]], m4_shift3($@))
-# as the inner loop, using each prefix generated by the outer loop,
-# and without recalculating m4_shift3 every outer iteration.
-m4_define([m4_combine],
-[m4_if([$2], [], [], m4_eval([$# > 3]), [1],
-[m4_map_args_sep([m4_map_args_sep(m4_dquote(], [)[[$3]], [], [[$1]],]]]dnl
-[m4_dquote(m4_dquote(m4_shift3($@)))[[)], [[$1]], $2)])])
-
-
-# m4_append(MACRO-NAME, STRING, [SEPARATOR])
-# ------------------------------------------
-# Redefine MACRO-NAME to hold its former content plus `SEPARATOR`'STRING'
-# at the end. It is valid to use this macro with MACRO-NAME undefined,
-# in which case no SEPARATOR is added. Be aware that the criterion is
-# `not being defined', and not `not being empty'.
-#
-# Note that neither STRING nor SEPARATOR are expanded here; rather, when
-# you expand MACRO-NAME, they will be expanded at that point in time.
-#
-# This macro is robust to active symbols. It can be used to grow
-# strings.
-#
-# | m4_define(active, ACTIVE)dnl
-# | m4_append([sentence], [This is an])dnl
-# | m4_append([sentence], [ active ])dnl
-# | m4_append([sentence], [symbol.])dnl
-# | sentence
-# | m4_undefine([active])dnl
-# | sentence
-# => This is an ACTIVE symbol.
-# => This is an active symbol.
-#
-# It can be used to define hooks.
-#
-# | m4_define(active, ACTIVE)dnl
-# | m4_append([hooks], [m4_define([act1], [act2])])dnl
-# | m4_append([hooks], [m4_define([act2], [active])])dnl
-# | m4_undefine([active])dnl
-# | act1
-# | hooks
-# | act1
-# => act1
-# =>
-# => active
-#
-# It can also be used to create lists, although this particular usage was
-# broken prior to autoconf 2.62.
-# | m4_append([list], [one], [, ])dnl
-# | m4_append([list], [two], [, ])dnl
-# | m4_append([list], [three], [, ])dnl
-# | list
-# | m4_dquote(list)
-# => one, two, three
-# => [one],[two],[three]
-#
-# Note that m4_append can benefit from amortized O(n) m4 behavior, if
-# the underlying m4 implementation is smart enough to avoid copying existing
-# contents when enlarging a macro's definition into any pre-allocated storage
-# (m4 1.4.x unfortunately does not implement this optimization). We do
-# not implement m4_prepend, since it is inherently O(n^2) (pre-allocated
-# storage only occurs at the end of a macro, so the existing contents must
-# always be moved).
-#
-# Use _m4_defn for speed.
-m4_define([m4_append],
-[m4_define([$1], m4_ifdef([$1], [_m4_defn([$1])[$3]])[$2])])
-
-
-# m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR], [IF-UNIQ], [IF-DUP])
-# --------------------------------------------------------------------
-# Like `m4_append', but append only if not yet present. Additionally,
-# expand IF-UNIQ if STRING was appended, or IF-DUP if STRING was already
-# present. Also, warn if SEPARATOR is not empty and occurs within STRING,
-# as the algorithm no longer guarantees uniqueness.
-#
-# Note that while m4_append can be O(n) (depending on the quality of the
-# underlying M4 implementation), m4_append_uniq is inherently O(n^2)
-# because each append operation searches the entire string.
-m4_define([m4_append_uniq],
-[m4_ifval([$3], [m4_if(m4_index([$2], [$3]), [-1], [],
- [m4_warn([syntax],
- [$0: `$2' contains `$3'])])])_$0($@)])
-m4_define([_m4_append_uniq],
-[m4_ifdef([$1],
- [m4_if(m4_index([$3]_m4_defn([$1])[$3], [$3$2$3]), [-1],
- [m4_append([$1], [$2], [$3])$4], [$5])],
- [m4_define([$1], [$2])$4])])
-
-# m4_append_uniq_w(MACRO-NAME, STRINGS)
-# -------------------------------------
-# For each of the words in the whitespace separated list STRINGS, append
-# only the unique strings to the definition of MACRO-NAME.
-#
-# Use _m4_defn for speed.
-m4_define([m4_append_uniq_w],
-[m4_map_args_w([$2], [_m4_append_uniq([$1],], [, [ ])])])
-
-
-# m4_escape(STRING)
-# -----------------
-# Output quoted STRING, but with embedded #, $, [ and ] turned into
-# quadrigraphs.
-#
-# It is faster to check if STRING is already good using m4_translit
-# than to blindly perform four m4_bpatsubst.
-#
-# Because the translit is stripping quotes, it must also neutralize
-# anything that might be in a macro name, as well as comments, commas,
-# and parentheses. All the problem characters are unified so that a
-# single m4_index can scan the result.
-#
-# Rather than expand m4_defn every time m4_escape is expanded, we
-# inline its expansion up front.
-m4_define([m4_escape],
-[m4_if(m4_index(m4_translit([$1],
- [[]#,()]]m4_dquote(m4_defn([m4_cr_symbols2]))[, [$$$]), [$]),
- [-1], [m4_echo], [_$0])([$1])])
-
-m4_define([_m4_escape],
-[m4_changequote([-=<{(],[)}>=-])]dnl
-[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(
- -=<{(-=<{(-=<{(-=<{(-=<{($1)}>=-)}>=-)}>=-)}>=-)}>=-,
- -=<{(#)}>=-, -=<{(@%:@)}>=-),
- -=<{(\[)}>=-, -=<{(@<:@)}>=-),
- -=<{(\])}>=-, -=<{(@:>@)}>=-),
- -=<{(\$)}>=-, -=<{(@S|@)}>=-)m4_changequote([,])])
-
-
-# m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
-# -------------------------------------------------------
-# Expands into STRING wrapped to hold in WIDTH columns (default = 79).
-# If PREFIX is given, each line is prefixed with it. If FIRST-PREFIX is
-# specified, then the first line is prefixed with it. As a special case,
-# if the length of FIRST-PREFIX is greater than that of PREFIX, then
-# FIRST-PREFIX will be left alone on the first line.
-#
-# No expansion occurs on the contents STRING, PREFIX, or FIRST-PREFIX,
-# although quadrigraphs are correctly recognized. More precisely,
-# you may redefine m4_qlen to recognize whatever escape sequences that
-# you will post-process.
-#
-# Typical outputs are:
-#
-# m4_text_wrap([Short string */], [ ], [/* ], 20)
-# => /* Short string */
-#
-# m4_text_wrap([Much longer string */], [ ], [/* ], 20)
-# => /* Much longer
-# => string */
-#
-# m4_text_wrap([Short doc.], [ ], [ --short ], 30)
-# => --short Short doc.
-#
-# m4_text_wrap([Short doc.], [ ], [ --too-wide ], 30)
-# => --too-wide
-# => Short doc.
-#
-# m4_text_wrap([Super long documentation.], [ ], [ --too-wide ], 30)
-# => --too-wide
-# => Super long
-# => documentation.
-#
-# FIXME: there is no checking of a longer PREFIX than WIDTH, but do
-# we really want to bother with people trying each single corner
-# of a software?
-#
-# This macro does not leave a trailing space behind the last word of a line,
-# which complicates it a bit. The algorithm is otherwise stupid and simple:
-# all the words are preceded by m4_Separator which is defined to empty for
-# the first word, and then ` ' (single space) for all the others.
-#
-# The algorithm uses a helper that uses $2 through $4 directly, rather than
-# using local variables, to avoid m4_defn overhead, or expansion swallowing
-# any $. It also bypasses m4_popdef overhead with _m4_popdef since no user
-# macro expansion occurs in the meantime. Also, the definition is written
-# with m4_do, to avoid time wasted on dnl during expansion (since this is
-# already a time-consuming macro).
-m4_define([m4_text_wrap],
-[_$0(m4_escape([$1]), [$2], m4_default_quoted([$3], [$2]),
- m4_default_quoted([$4], [79]))])
-
-m4_define([_m4_text_wrap],
-m4_do(dnl set up local variables, to avoid repeated calculations
-[[m4_pushdef([m4_Indent], m4_qlen([$2]))]],
-[[m4_pushdef([m4_Cursor], m4_qlen([$3]))]],
-[[m4_pushdef([m4_Separator], [m4_define([m4_Separator], [ ])])]],
-dnl expand the first prefix, then check its length vs. regular prefix
-dnl same length: nothing special
-dnl prefix1 longer: output on line by itself, and reset cursor
-dnl prefix1 shorter: pad to length of prefix, and reset cursor
-[[[$3]m4_cond([m4_Cursor], m4_Indent, [],
- [m4_eval(m4_Cursor > m4_Indent)], [1], [
-[$2]m4_define([m4_Cursor], m4_Indent)],
- [m4_format([%*s], m4_max([0],
- m4_eval(m4_Indent - m4_Cursor)), [])m4_define([m4_Cursor], m4_Indent)])]],
-dnl now, for each word, compute the cursor after the word is output, then
-dnl check if the cursor would exceed the wrap column
-dnl if so, reset cursor, and insert newline and prefix
-dnl if not, insert the separator (usually a space)
-dnl either way, insert the word
-[[m4_map_args_w([$1], [$0_word(], [, [$2], [$4])])]],
-dnl finally, clean up the local variables
-[[_m4_popdef([m4_Separator], [m4_Cursor], [m4_Indent])]]))
-
-m4_define([_m4_text_wrap_word],
-[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_qlen([$1]) + 1))]dnl
-[m4_if(m4_eval(m4_Cursor > ([$3])),
- [1], [m4_define([m4_Cursor], m4_eval(m4_Indent + m4_qlen([$1]) + 1))
-[$2]],
- [m4_Separator[]])[$1]])
-
-# m4_text_box(MESSAGE, [FRAME-CHARACTER = `-'])
-# ---------------------------------------------
-# Turn MESSAGE into:
-# ## ------- ##
-# ## MESSAGE ##
-# ## ------- ##
-# using FRAME-CHARACTER in the border.
-#
-# Quadrigraphs are correctly recognized. More precisely, you may
-# redefine m4_qlen to recognize whatever escape sequences that you
-# will post-process.
-m4_define([m4_text_box],
-[m4_pushdef([m4_Border],
- m4_translit(m4_format([[[%*s]]], m4_decr(m4_qlen(_m4_expand([$1
-]))), []), [ ], m4_default_quoted([$2], [-])))]dnl
-[[##] _m4_defn([m4_Border]) [##]
-[##] $1 [##]
-[##] _m4_defn([m4_Border]) [##]_m4_popdef([m4_Border])])
-
-
-# m4_qlen(STRING)
-# ---------------
-# Expands to the length of STRING after autom4te converts all quadrigraphs.
-#
-# If you use some other means of post-processing m4 output rather than
-# autom4te, then you may redefine this macro to recognize whatever
-# escape sequences your post-processor will handle. For that matter,
-# m4_define([m4_qlen], m4_defn([m4_len])) is sufficient if you don't
-# do any post-processing.
-#
-# Avoid bpatsubsts for the common case of no quadrigraphs. Cache
-# results, as configure scripts tend to ask about lengths of common
-# strings like `/*' and `*/' rather frequently. Minimize the number
-# of times that $1 occurs in m4_qlen, so there is less text to parse
-# on a cache hit.
-m4_define([m4_qlen],
-[m4_ifdef([$0-$1], [_m4_defn([$0-]], [_$0(])[$1])])
-m4_define([_m4_qlen],
-[m4_define([m4_qlen-$1],
-m4_if(m4_index([$1], [@]), [-1], [m4_len([$1])],
- [m4_len(m4_bpatsubst([[$1]],
- [@\(\(<:\|:>\|S|\|%:\|\{:\|:\}\)\(@\)\|&t@\)],
- [\3]))]))_m4_defn([m4_qlen-$1])])
-
-# m4_copyright_condense(TEXT)
-# ---------------------------
-# Condense the copyright notice in TEXT to only display the final
-# year, wrapping the results to fit in 80 columns.
-m4_define([m4_copyright_condense],
-[m4_text_wrap(m4_bpatsubst(m4_flatten([[$1]]),
-[(C)[- ,0-9]*\([1-9][0-9][0-9][0-9]\)], [(C) \1]))])
-
-## ----------------------- ##
-## 13. Number processing. ##
-## ----------------------- ##
-
-# m4_cmp(A, B)
-# ------------
-# Compare two integer expressions.
-# A < B -> -1
-# A = B -> 0
-# A > B -> 1
-m4_define([m4_cmp],
-[m4_eval((([$1]) > ([$2])) - (([$1]) < ([$2])))])
-
-
-# m4_list_cmp(A, B)
-# -----------------
-#
-# Compare the two lists of integer expressions A and B. For instance:
-# m4_list_cmp([1, 0], [1]) -> 0
-# m4_list_cmp([1, 0], [1, 0]) -> 0
-# m4_list_cmp([1, 2], [1, 0]) -> 1
-# m4_list_cmp([1, 2, 3], [1, 2]) -> 1
-# m4_list_cmp([1, 2, -3], [1, 2]) -> -1
-# m4_list_cmp([1, 0], [1, 2]) -> -1
-# m4_list_cmp([1], [1, 2]) -> -1
-# m4_define([xa], [oops])dnl
-# m4_list_cmp([[0xa]], [5+5]) -> 0
-#
-# Rather than face the overhead of m4_case, we use a helper function whose
-# expansion includes the name of the macro to invoke on the tail, either
-# m4_ignore or m4_unquote. This is particularly useful when comparing
-# long lists, since less text is being expanded for deciding when to end
-# recursion. The recursion is between a pair of macros that alternate
-# which list is trimmed by one element; this is more efficient than
-# calling m4_cdr on both lists from a single macro. Guarantee exactly
-# one expansion of both lists' side effects.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_list_cmp],
-[_$0_raw(m4_dquote($1), m4_dquote($2))])
-
-m4_define([_m4_list_cmp_raw],
-[m4_if([$1], [$2], [0], [_m4_list_cmp_1([$1], $2)])])
-
-m4_define([_m4_list_cmp],
-[m4_if([$1], [], [0m4_ignore], [$2], [0], [m4_unquote], [$2m4_ignore])])
-
-m4_define([_m4_list_cmp_1],
-[_m4_list_cmp_2([$2], [m4_shift2($@)], $1)])
-
-m4_define([_m4_list_cmp_2],
-[_m4_list_cmp([$1$3], m4_cmp([$3+0], [$1+0]))(
- [_m4_list_cmp_1(m4_dquote(m4_shift3($@)), $2)])])
-
-# m4_max(EXPR, ...)
-# m4_min(EXPR, ...)
-# -----------------
-# Return the decimal value of the maximum (or minimum) in a series of
-# integer expressions.
-#
-# M4 1.4.x doesn't provide ?:. Hence this huge m4_eval. Avoid m4_eval
-# if both arguments are identical, but be aware of m4_max(0xa, 10) (hence
-# the use of <=, not just <, in the second multiply).
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_max],
-[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
- [$#], [1], [m4_eval([$1])],
- [$#$1], [2$2], [m4_eval([$1])],
- [$#], [2], [_$0($@)],
- [_m4_minmax([_$0], $@)])])
-
-m4_define([_m4_max],
-[m4_eval((([$1]) > ([$2])) * ([$1]) + (([$1]) <= ([$2])) * ([$2]))])
-
-m4_define([m4_min],
-[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
- [$#], [1], [m4_eval([$1])],
- [$#$1], [2$2], [m4_eval([$1])],
- [$#], [2], [_$0($@)],
- [_m4_minmax([_$0], $@)])])
-
-m4_define([_m4_min],
-[m4_eval((([$1]) < ([$2])) * ([$1]) + (([$1]) >= ([$2])) * ([$2]))])
-
-# _m4_minmax(METHOD, ARG1, ARG2...)
-# ---------------------------------
-# Common recursion code for m4_max and m4_min. METHOD must be _m4_max
-# or _m4_min, and there must be at least two arguments to combine.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([_m4_minmax],
-[m4_if([$#], [3], [$1([$2], [$3])],
- [$0([$1], $1([$2], [$3]), m4_shift3($@))])])
-
-
-# m4_sign(A)
-# ----------
-# The sign of the integer expression A.
-m4_define([m4_sign],
-[m4_eval((([$1]) > 0) - (([$1]) < 0))])
-
-
-
-## ------------------------ ##
-## 14. Version processing. ##
-## ------------------------ ##
-
-
-# m4_version_unletter(VERSION)
-# ----------------------------
-# Normalize beta version numbers with letters to numeric expressions, which
-# can then be handed to m4_eval for the purpose of comparison.
-#
-# Nl -> (N+1).-1.(l#)
-#
-# for example:
-# [2.14a] -> [0,2,14+1,-1,[0r36:a]] -> 2.15.-1.10
-# [2.14b] -> [0,2,15+1,-1,[0r36:b]] -> 2.15.-1.11
-# [2.61aa.b] -> [0,2.61,1,-1,[0r36:aa],+1,-1,[0r36:b]] -> 2.62.-1.370.1.-1.11
-# [08] -> [0,[0r10:0]8] -> 8
-#
-# This macro expects reasonable version numbers, but can handle double
-# letters and does not expand any macros. Original version strings can
-# use both `.' and `-' separators.
-#
-# Inline constant expansions, to avoid m4_defn overhead.
-# _m4_version_unletter is the real workhorse used by m4_version_compare,
-# but since [0r36:a] and commas are less readable than 10 and dots, we
-# provide a wrapper for human use.
-m4_define([m4_version_unletter],
-[m4_substr(m4_map_args([.m4_eval], m4_unquote(_$0([$1]))), [3])])
-m4_define([_m4_version_unletter],
-[m4_bpatsubst(m4_bpatsubst(m4_translit([[[[0,$1]]]], [.-], [,,]),]dnl
-m4_dquote(m4_dquote(m4_defn([m4_cr_Letters])))[[+],
- [+1,-1,[0r36:\&]]), [,0], [,[0r10:0]])])
-
-
-# m4_version_compare(VERSION-1, VERSION-2)
-# ----------------------------------------
-# Compare the two version numbers and expand into
-# -1 if VERSION-1 < VERSION-2
-# 0 if =
-# 1 if >
-#
-# Since _m4_version_unletter does not output side effects, we can
-# safely bypass the overhead of m4_version_cmp.
-m4_define([m4_version_compare],
-[_m4_list_cmp_raw(_m4_version_unletter([$1]), _m4_version_unletter([$2]))])
-
-
-# m4_PACKAGE_NAME
-# m4_PACKAGE_TARNAME
-# m4_PACKAGE_VERSION
-# m4_PACKAGE_STRING
-# m4_PACKAGE_BUGREPORT
-# --------------------
-# If m4sugar/version.m4 is present, then define version strings. This
-# file is optional, provided by Autoconf but absent in Bison.
-m4_sinclude([m4sugar/version.m4])
-
-
-# m4_version_prereq(VERSION, [IF-OK], [IF-NOT = FAIL])
-# ----------------------------------------------------
-# Check this Autoconf version against VERSION.
-m4_define([m4_version_prereq],
-m4_ifdef([m4_PACKAGE_VERSION],
-[[m4_if(m4_version_compare(]m4_dquote(m4_defn([m4_PACKAGE_VERSION]))[, [$1]),
- [-1],
- [m4_default([$3],
- [m4_fatal([Autoconf version $1 or higher is required],
- [63])])],
- [$2])]],
-[[m4_fatal([m4sugar/version.m4 not found])]]))
-
-
-## ------------------ ##
-## 15. Set handling. ##
-## ------------------ ##
-
-# Autoconf likes to create arbitrarily large sets; for example, as of
-# this writing, the configure.ac for coreutils tracks a set of more
-# than 400 AC_SUBST. How do we track all of these set members,
-# without introducing duplicates? We could use m4_append_uniq, with
-# the set NAME residing in the contents of the macro NAME.
-# Unfortunately, m4_append_uniq is quadratic for set creation, because
-# it costs O(n) to search the string for each of O(n) insertions; not
-# to mention that with m4 1.4.x, even using m4_append is slow, costing
-# O(n) rather than O(1) per insertion. Other set operations, not used
-# by Autoconf but still possible by manipulation of the definition
-# tracked in macro NAME, include O(n) deletion of one element and O(n)
-# computation of set size. Because the set is exposed to the user via
-# the definition of a single macro, we cannot cache any data about the
-# set without risking the cache being invalidated by the user
-# redefining NAME.
-#
-# Can we do better? Yes, because m4 gives us an O(1) search function
-# for free: ifdef. Additionally, even m4 1.4.x gives us an O(1)
-# insert operation for free: pushdef. But to use these, we must
-# represent the set via a group of macros; to keep the set consistent,
-# we must hide the set so that the user can only manipulate it through
-# accessor macros. The contents of the set are maintained through two
-# access points; _m4_set([name]) is a pushdef stack of values in the
-# set, useful for O(n) traversal of the set contents; while the
-# existence of _m4_set([name],value) with no particular value is
-# useful for O(1) querying of set membership. And since the user
-# cannot externally manipulate the set, we are free to add additional
-# caching macros for other performance improvements. Deletion can be
-# O(1) per element rather than O(n), by reworking the definition of
-# _m4_set([name],value) to be 0 or 1 based on current membership, and
-# adding _m4_set_cleanup(name) to defer the O(n) cleanup of
-# _m4_set([name]) until we have another reason to do an O(n)
-# traversal. The existence of _m4_set_cleanup(name) can then be used
-# elsewhere to determine if we must dereference _m4_set([name],value),
-# or assume that definition implies set membership. Finally, size can
-# be tracked in an O(1) fashion with _m4_set_size(name).
-#
-# The quoting in _m4_set([name],value) is chosen so that there is no
-# ambiguity with a set whose name contains a comma, and so that we can
-# supply the value via _m4_defn([_m4_set([name])]) without needing any
-# quote manipulation.
-
-# m4_set_add(SET, VALUE, [IF-UNIQ], [IF-DUP])
-# -------------------------------------------
-# Add VALUE as an element of SET. Expand IF-UNIQ on the first
-# addition, and IF-DUP if it is already in the set. Addition of one
-# element is O(1), such that overall set creation is O(n).
-#
-# We do not want to add a duplicate for a previously deleted but
-# unpruned element, but it is just as easy to check existence directly
-# as it is to query _m4_set_cleanup($1).
-m4_define([m4_set_add],
-[m4_ifdef([_m4_set([$1],$2)],
- [m4_if(m4_indir([_m4_set([$1],$2)]), [0],
- [m4_define([_m4_set([$1],$2)],
- [1])_m4_set_size([$1], [m4_incr])$3], [$4])],
- [m4_define([_m4_set([$1],$2)],
- [1])m4_pushdef([_m4_set([$1])],
- [$2])_m4_set_size([$1], [m4_incr])$3])])
-
-# m4_set_add_all(SET, VALUE...)
-# -----------------------------
-# Add each VALUE into SET. This is O(n) in the number of VALUEs, and
-# can be faster than calling m4_set_add for each VALUE.
-#
-# Implement two recursion helpers; the check variant is slower but
-# handles the case where an element has previously been removed but
-# not pruned. The recursion helpers ignore their second argument, so
-# that we can use the faster m4_shift2 and 2 arguments, rather than
-# _m4_shift2 and one argument, as the signal to end recursion.
-#
-# Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_set_add_all],
-[m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1])
- + m4_len(m4_ifdef([_m4_set_cleanup($1)], [_$0_check], [_$0])([$1], $@))))])
-
-m4_define([_m4_set_add_all],
-[m4_if([$#], [2], [],
- [m4_ifdef([_m4_set([$1],$3)], [],
- [m4_define([_m4_set([$1],$3)], [1])m4_pushdef([_m4_set([$1])],
- [$3])-])$0([$1], m4_shift2($@))])])
-
-m4_define([_m4_set_add_all_check],
-[m4_if([$#], [2], [],
- [m4_set_add([$1], [$3])$0([$1], m4_shift2($@))])])
-
-# m4_set_contains(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
-# ------------------------------------------------------
-# Expand IF-PRESENT if SET contains VALUE, otherwise expand IF-ABSENT.
-# This is always O(1).
-m4_define([m4_set_contains],
-[m4_ifdef([_m4_set_cleanup($1)],
- [m4_if(m4_ifdef([_m4_set([$1],$2)],
- [m4_indir([_m4_set([$1],$2)])], [0]), [1], [$3], [$4])],
- [m4_ifdef([_m4_set([$1],$2)], [$3], [$4])])])
-
-# m4_set_contents(SET, [SEP])
-# ---------------------------
-# Expand to a single string containing all the elements in SET,
-# separated by SEP, without modifying SET. No provision is made for
-# disambiguating set elements that contain non-empty SEP as a
-# sub-string, or for recognizing a set that contains only the empty
-# string. Order of the output is not guaranteed. If any elements
-# have been previously removed from the set, this action will prune
-# the unused memory. This is O(n) in the size of the set before
-# pruning.
-#
-# Use _m4_popdef for speed. The existence of _m4_set_cleanup($1)
-# determines which version of _1 helper we use.
-m4_define([m4_set_contents],
-[m4_set_map_sep([$1], [], [], [[$2]])])
-
-# _m4_set_contents_1(SET)
-# _m4_set_contents_1c(SET)
-# _m4_set_contents_2(SET, [PRE], [POST], [SEP])
-# ---------------------------------------------
-# Expand to a list of quoted elements currently in the set, each
-# surrounded by PRE and POST, and moving SEP in front of PRE on
-# recursion. To avoid nesting limit restrictions, the algorithm must
-# be broken into two parts; _1 destructively copies the stack in
-# reverse into _m4_set_($1), producing no output; then _2
-# destructively copies _m4_set_($1) back into the stack in reverse.
-# If no elements were deleted, then this visits the set in the order
-# that elements were inserted. Behavior is undefined if PRE/POST/SEP
-# tries to recursively list or modify SET in any way other than
-# calling m4_set_remove on the current element. Use _1 if all entries
-# in the stack are guaranteed to be in the set, and _1c to prune
-# removed entries. Uses _m4_defn and _m4_popdef for speed.
-m4_define([_m4_set_contents_1],
-[_m4_stack_reverse([_m4_set([$1])], [_m4_set_($1)])])
-
-m4_define([_m4_set_contents_1c],
-[m4_ifdef([_m4_set([$1])],
- [m4_set_contains([$1], _m4_defn([_m4_set([$1])]),
- [m4_pushdef([_m4_set_($1)], _m4_defn([_m4_set([$1])]))],
- [_m4_popdef([_m4_set([$1],]_m4_defn(
- [_m4_set([$1])])[)])])_m4_popdef([_m4_set([$1])])$0([$1])],
- [_m4_popdef([_m4_set_cleanup($1)])])])
-
-m4_define([_m4_set_contents_2],
-[_m4_stack_reverse([_m4_set_($1)], [_m4_set([$1])],
- [$2[]_m4_defn([_m4_set_($1)])$3], [$4[]])])
-
-# m4_set_delete(SET)
-# ------------------
-# Delete all elements in SET, and reclaim any memory occupied by the
-# set. This is O(n) in the set size.
-#
-# Use _m4_defn and _m4_popdef for speed.
-m4_define([m4_set_delete],
-[m4_ifdef([_m4_set([$1])],
- [_m4_popdef([_m4_set([$1],]_m4_defn([_m4_set([$1])])[)],
- [_m4_set([$1])])$0([$1])],
- [m4_ifdef([_m4_set_cleanup($1)],
- [_m4_popdef([_m4_set_cleanup($1)])])m4_ifdef(
- [_m4_set_size($1)],
- [_m4_popdef([_m4_set_size($1)])])])])
-
-# m4_set_difference(SET1, SET2)
-# -----------------------------
-# Produce a LIST of quoted elements that occur in SET1 but not SET2.
-# Output a comma prior to any elements, to distinguish the empty
-# string from no elements. This can be directly used as a series of
-# arguments, such as for m4_join, or wrapped inside quotes for use in
-# m4_foreach. Order of the output is not guaranteed.
-#
-# Short-circuit the idempotence relation.
-m4_define([m4_set_difference],
-[m4_if([$1], [$2], [], [m4_set_map_sep([$1], [_$0([$2],], [)])])])
-
-m4_define([_m4_set_difference],
-[m4_set_contains([$1], [$2], [], [,[$2]])])
-
-# m4_set_dump(SET, [SEP])
-# -----------------------
-# Expand to a single string containing all the elements in SET,
-# separated by SEP, then delete SET. In general, if you only need to
-# list the contents once, this is faster than m4_set_contents. No
-# provision is made for disambiguating set elements that contain
-# non-empty SEP as a sub-string. Order of the output is not
-# guaranteed. This is O(n) in the size of the set before pruning.
-#
-# Use _m4_popdef for speed. Use existence of _m4_set_cleanup($1) to
-# decide if more expensive recursion is needed.
-m4_define([m4_set_dump],
-[m4_ifdef([_m4_set_size($1)],
- [_m4_popdef([_m4_set_size($1)])])m4_ifdef([_m4_set_cleanup($1)],
- [_$0_check], [_$0])([$1], [], [$2])])
-
-# _m4_set_dump(SET, [SEP], [PREP])
-# _m4_set_dump_check(SET, [SEP], [PREP])
-# --------------------------------------
-# Print SEP and the current element, then delete the element and
-# recurse with empty SEP changed to PREP. The check variant checks
-# whether the element has been previously removed. Use _m4_defn and
-# _m4_popdef for speed.
-m4_define([_m4_set_dump],
-[m4_ifdef([_m4_set([$1])],
- [[$2]_m4_defn([_m4_set([$1])])_m4_popdef([_m4_set([$1],]_m4_defn(
- [_m4_set([$1])])[)], [_m4_set([$1])])$0([$1], [$2$3])])])
-
-m4_define([_m4_set_dump_check],
-[m4_ifdef([_m4_set([$1])],
- [m4_set_contains([$1], _m4_defn([_m4_set([$1])]),
- [[$2]_m4_defn([_m4_set([$1])])])_m4_popdef(
- [_m4_set([$1],]_m4_defn([_m4_set([$1])])[)],
- [_m4_set([$1])])$0([$1], [$2$3])],
- [_m4_popdef([_m4_set_cleanup($1)])])])
-
-# m4_set_empty(SET, [IF-EMPTY], [IF-ELEMENTS])
-# --------------------------------------------
-# Expand IF-EMPTY if SET has no elements, otherwise IF-ELEMENTS.
-m4_define([m4_set_empty],
-[m4_ifdef([_m4_set_size($1)],
- [m4_if(m4_indir([_m4_set_size($1)]), [0], [$2], [$3])], [$2])])
-
-# m4_set_foreach(SET, VAR, ACTION)
-# --------------------------------
-# For each element of SET, define VAR to the element and expand
-# ACTION. ACTION should not recursively list SET's contents, add
-# elements to SET, nor delete any element from SET except the one
-# currently in VAR. The order that the elements are visited in is not
-# guaranteed. This is faster than the corresponding m4_foreach([VAR],
-# m4_indir([m4_dquote]m4_set_listc([SET])), [ACTION])
-m4_define([m4_set_foreach],
-[m4_pushdef([$2])m4_set_map_sep([$1], [m4_define([$2],], [)$3])])
-
-# m4_set_intersection(SET1, SET2)
-# -------------------------------
-# Produce a LIST of quoted elements that occur in both SET1 or SET2.
-# Output a comma prior to any elements, to distinguish the empty
-# string from no elements. This can be directly used as a series of
-# arguments, such as for m4_join, or wrapped inside quotes for use in
-# m4_foreach. Order of the output is not guaranteed.
-#
-# Iterate over the smaller set, and short-circuit the idempotence
-# relation.
-m4_define([m4_set_intersection],
-[m4_if([$1], [$2], [m4_set_listc([$1])],
- m4_eval(m4_set_size([$2]) < m4_set_size([$1])), [1], [$0([$2], [$1])],
- [m4_set_map_sep([$1], [_$0([$2],], [)])])])
-
-m4_define([_m4_set_intersection],
-[m4_set_contains([$1], [$2], [,[$2]])])
-
-# m4_set_list(SET)
-# m4_set_listc(SET)
-# -----------------
-# Produce a LIST of quoted elements of SET. This can be directly used
-# as a series of arguments, such as for m4_join or m4_set_add_all, or
-# wrapped inside quotes for use in m4_foreach or m4_map. With
-# m4_set_list, there is no way to distinguish an empty set from a set
-# containing only the empty string; with m4_set_listc, a leading comma
-# is output if there are any elements.
-m4_define([m4_set_list],
-[m4_set_map_sep([$1], [], [], [,])])
-
-m4_define([m4_set_listc],
-[m4_set_map_sep([$1], [,])])
-
-# m4_set_map(SET, ACTION)
-# -----------------------
-# For each element of SET, expand ACTION with a single argument of the
-# current element. ACTION should not recursively list SET's contents,
-# add elements to SET, nor delete any element from SET except the one
-# passed as an argument. The order that the elements are visited in
-# is not guaranteed. This is faster than either of the corresponding
-# m4_map_args([ACTION]m4_set_listc([SET]))
-# m4_set_foreach([SET], [VAR], [ACTION(m4_defn([VAR]))])
-m4_define([m4_set_map],
-[m4_set_map_sep([$1], [$2(], [)])])
-
-# m4_set_map_sep(SET, [PRE], [POST], [SEP])
-# -----------------------------------------
-# For each element of SET, expand PRE[value]POST[], and expand SEP
-# between elements.
-m4_define([m4_set_map_sep],
-[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c],
- [_m4_set_contents_1])([$1])_m4_set_contents_2($@)])
-
-# m4_set_remove(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
-# ----------------------------------------------------
-# If VALUE is an element of SET, delete it and expand IF-PRESENT.
-# Otherwise expand IF-ABSENT. Deleting a single value is O(1),
-# although it leaves memory occupied until the next O(n) traversal of
-# the set which will compact the set.
-#
-# Optimize if the element being removed is the most recently added,
-# since defining _m4_set_cleanup($1) slows down so many other macros.
-# In particular, this plays well with m4_set_foreach and m4_set_map.
-m4_define([m4_set_remove],
-[m4_set_contains([$1], [$2], [_m4_set_size([$1],
- [m4_decr])m4_if(_m4_defn([_m4_set([$1])]), [$2],
- [_m4_popdef([_m4_set([$1],$2)], [_m4_set([$1])])],
- [m4_define([_m4_set_cleanup($1)])m4_define(
- [_m4_set([$1],$2)], [0])])$3], [$4])])
-
-# m4_set_size(SET)
-# ----------------
-# Expand to the number of elements currently in SET. This operation
-# is O(1), and thus more efficient than m4_count(m4_set_list([SET])).
-m4_define([m4_set_size],
-[m4_ifdef([_m4_set_size($1)], [m4_indir([_m4_set_size($1)])], [0])])
-
-# _m4_set_size(SET, ACTION)
-# -------------------------
-# ACTION must be either m4_incr or m4_decr, and the size of SET is
-# changed accordingly. If the set is empty, ACTION must not be
-# m4_decr.
-m4_define([_m4_set_size],
-[m4_define([_m4_set_size($1)],
- m4_ifdef([_m4_set_size($1)], [$2(m4_indir([_m4_set_size($1)]))],
- [1]))])
-
-# m4_set_union(SET1, SET2)
-# ------------------------
-# Produce a LIST of double quoted elements that occur in either SET1
-# or SET2, without duplicates. Output a comma prior to any elements,
-# to distinguish the empty string from no elements. This can be
-# directly used as a series of arguments, such as for m4_join, or
-# wrapped inside quotes for use in m4_foreach. Order of the output is
-# not guaranteed.
-#
-# We can rely on the fact that m4_set_listc prunes SET1, so we don't
-# need to check _m4_set([$1],element) for 0. Short-circuit the
-# idempotence relation.
-m4_define([m4_set_union],
-[m4_set_listc([$1])m4_if([$1], [$2], [],
- [m4_set_map_sep([$2], [_$0([$1],], [)])])])
-
-m4_define([_m4_set_union],
-[m4_ifdef([_m4_set([$1],$2)], [], [,[$2]])])
-
-
-## ------------------- ##
-## 16. File handling. ##
-## ------------------- ##
-
-
-# It is a real pity that M4 comes with no macros to bind a diversion
-# to a file. So we have to deal without, which makes us a lot more
-# fragile than we should.
-
-
-# m4_file_append(FILE-NAME, CONTENT)
-# ----------------------------------
-m4_define([m4_file_append],
-[m4_syscmd([cat >>$1 <<_m4eof
-$2
-_m4eof
-])
-m4_if(m4_sysval, [0], [],
- [m4_fatal([$0: cannot write: $1])])])
-
-
-
-## ------------------------ ##
-## 17. Setting M4sugar up. ##
-## ------------------------ ##
-
-# _m4_divert_diversion should be defined.
-m4_divert_push([KILL])
-
-# m4_init
-# -------
-# Initialize the m4sugar language.
-m4_define([m4_init],
-[# All the M4sugar macros start with `m4_', except `dnl' kept as is
-# for sake of simplicity.
-m4_pattern_forbid([^_?m4_])
-m4_pattern_forbid([^dnl$])
-
-# If __m4_version__ is defined, we assume that we are being run by M4
-# 1.6 or newer, thus $@ recursion is linear, and debugmode(+do)
-# is available for faster checks of dereferencing undefined macros
-# and forcing dumpdef to print to stderr regardless of debugfile.
-# But if it is missing, we assume we are being run by M4 1.4.x, that
-# $@ recursion is quadratic, and that we need foreach-based
-# replacement macros. Also, m4 prior to 1.4.8 loses track of location
-# during m4wrap text; __line__ should never be 0.
-#
-# Use the raw builtin to avoid tripping up include tracing.
-# Meanwhile, avoid m4_copy, since it temporarily undefines m4_defn.
-m4_ifdef([__m4_version__],
-[m4_debugmode([+do])
-m4_define([m4_defn], _m4_defn([_m4_defn]))
-m4_define([m4_dumpdef], _m4_defn([_m4_dumpdef]))
-m4_define([m4_popdef], _m4_defn([_m4_popdef]))
-m4_define([m4_undefine], _m4_defn([_m4_undefine]))],
-[m4_builtin([include], [m4sugar/foreach.m4])
-m4_wrap_lifo([m4_if(__line__, [0], [m4_pushdef([m4_location],
-]]m4_dquote(m4_dquote(m4_dquote(__file__:__line__)))[[)])])])
-
-# Rewrite the first entry of the diversion stack.
-m4_divert([KILL])
-
-# Check the divert push/pop perfect balance.
-# Some users are prone to also use m4_wrap to register last-minute
-# m4_divert_text; so after our diversion cleanups, we restore
-# KILL as the bottom of the diversion stack.
-m4_wrap([m4_popdef([_m4_divert_diversion])m4_ifdef(
- [_m4_divert_diversion], [m4_fatal([$0: unbalanced m4_divert_push:
-]m4_divert_stack)])_m4_popdef([_m4_divert_stack])m4_divert_push([KILL])])
-])
+divert(-1)# -*- Autoconf -*-
+# This file is part of Autoconf.
+# Base M4 layer.
+# Requires GNU M4.
+#
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+# This file is part of Autoconf. This program is free
+# software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the Autoconf Configure Script Exception,
+# version 3.0, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License
+# and a copy of the Autoconf Configure Script Exception along with
+# this program; see the files COPYINGv3 and COPYING.EXCEPTION
+# respectively. If not, see <http://www.gnu.org/licenses/>.
+
+# Written by Akim Demaille.
+
+# Set the quotes, whatever the current quoting system.
+changequote()
+changequote([, ])
+
+# Some old m4's don't support m4exit. But they provide
+# equivalent functionality by core dumping because of the
+# long macros we define.
+ifdef([__gnu__], ,
+[errprint(M4sugar requires GNU M4. Install it before installing M4sugar or
+set the M4 environment variable to its absolute file name.)
+m4exit(2)])
+
+
+## ------------------------------- ##
+## 1. Simulate --prefix-builtins. ##
+## ------------------------------- ##
+
+# m4_define
+# m4_defn
+# m4_undefine
+define([m4_define], defn([define]))
+define([m4_defn], defn([defn]))
+define([m4_undefine], defn([undefine]))
+
+m4_undefine([define])
+m4_undefine([defn])
+m4_undefine([undefine])
+
+
+# m4_copy(SRC, DST)
+# -----------------
+# Define DST as the definition of SRC.
+# What's the difference between:
+# 1. m4_copy([from], [to])
+# 2. m4_define([to], [from($@)])
+# Well, obviously 1 is more expensive in space. Maybe 2 is more expensive
+# in time, but because of the space cost of 1, it's not that obvious.
+# Nevertheless, one huge difference is the handling of `$0'. If `from'
+# uses `$0', then with 1, `to''s `$0' is `to', while it is `from' in 2.
+# The user would certainly prefer to see `to'.
+#
+# This definition is in effect during m4sugar initialization, when
+# there are no pushdef stacks; later on, we redefine it to something
+# more powerful for all other clients to use.
+m4_define([m4_copy],
+[m4_define([$2], m4_defn([$1]))])
+
+
+# m4_rename(SRC, DST)
+# -------------------
+# Rename the macro SRC to DST.
+m4_define([m4_rename],
+[m4_copy([$1], [$2])m4_undefine([$1])])
+
+
+# m4_rename_m4(MACRO-NAME)
+# ------------------------
+# Rename MACRO-NAME to m4_MACRO-NAME.
+m4_define([m4_rename_m4],
+[m4_rename([$1], [m4_$1])])
+
+
+# m4_copy_unm4(m4_MACRO-NAME)
+# ---------------------------
+# Copy m4_MACRO-NAME to MACRO-NAME.
+m4_define([m4_copy_unm4],
+[m4_copy([$1], m4_bpatsubst([$1], [^m4_\(.*\)], [[\1]]))])
+
+
+# Some m4 internals have names colliding with tokens we might use.
+# Rename them a` la `m4 --prefix-builtins'. Conditionals first, since
+# some subsequent renames are conditional.
+m4_rename_m4([ifdef])
+m4_rename([ifelse], [m4_if])
+
+m4_rename_m4([builtin])
+m4_rename_m4([changecom])
+m4_rename_m4([changequote])
+m4_ifdef([changeword],dnl conditionally available in 1.4.x
+[m4_undefine([changeword])])
+m4_rename_m4([debugfile])
+m4_rename_m4([debugmode])
+m4_rename_m4([decr])
+m4_rename_m4([divnum])
+m4_rename_m4([dumpdef])
+m4_rename_m4([errprint])
+m4_rename_m4([esyscmd])
+m4_rename_m4([eval])
+m4_rename_m4([format])
+m4_undefine([include])
+m4_rename_m4([incr])
+m4_rename_m4([index])
+m4_rename_m4([indir])
+m4_rename_m4([len])
+m4_rename([m4exit], [m4_exit])
+m4_undefine([m4wrap])
+m4_ifdef([mkstemp],dnl added in M4 1.4.8
+[m4_rename_m4([mkstemp])
+m4_copy([m4_mkstemp], [m4_maketemp])
+m4_undefine([maketemp])],
+[m4_rename_m4([maketemp])
+m4_copy([m4_maketemp], [m4_mkstemp])])
+m4_rename([patsubst], [m4_bpatsubst])
+m4_rename_m4([popdef])
+m4_rename_m4([pushdef])
+m4_rename([regexp], [m4_bregexp])
+m4_rename_m4([shift])
+m4_undefine([sinclude])
+m4_rename_m4([substr])
+m4_ifdef([symbols],dnl present only in alpha-quality 1.4o
+[m4_rename_m4([symbols])])
+m4_rename_m4([syscmd])
+m4_rename_m4([sysval])
+m4_rename_m4([traceoff])
+m4_rename_m4([traceon])
+m4_rename_m4([translit])
+
+# _m4_defn(ARG)
+# -------------
+# _m4_defn is for internal use only - it bypasses the wrapper, so it
+# must only be used on one argument at a time, and only on macros
+# known to be defined. Make sure this still works if the user renames
+# m4_defn but not _m4_defn.
+m4_copy([m4_defn], [_m4_defn])
+
+# _m4_divert_raw(NUM)
+# -------------------
+# _m4_divert_raw is for internal use only. Use this instead of
+# m4_builtin([divert], NUM), so that tracing diversion flow is easier.
+m4_rename([divert], [_m4_divert_raw])
+
+# _m4_popdef(ARG...)
+# ------------------
+# _m4_popdef is for internal use only - it bypasses the wrapper, so it
+# must only be used on macros known to be defined. Make sure this
+# still works if the user renames m4_popdef but not _m4_popdef.
+m4_copy([m4_popdef], [_m4_popdef])
+
+# _m4_undefine(ARG...)
+# --------------------
+# _m4_undefine is for internal use only - it bypasses the wrapper, so
+# it must only be used on macros known to be defined. Make sure this
+# still works if the user renames m4_undefine but not _m4_undefine.
+m4_copy([m4_undefine], [_m4_undefine])
+
+# _m4_undivert(NUM...)
+# --------------------
+# _m4_undivert is for internal use only, and should always be given
+# arguments. Use this instead of m4_builtin([undivert], NUM...), so
+# that tracing diversion flow is easier.
+m4_rename([undivert], [_m4_undivert])
+
+
+## ------------------- ##
+## 2. Error messages. ##
+## ------------------- ##
+
+
+# m4_location
+# -----------
+# Output the current file, colon, and the current line number.
+m4_define([m4_location],
+[__file__:__line__])
+
+
+# m4_errprintn(MSG)
+# -----------------
+# Same as `errprint', but with the missing end of line.
+m4_define([m4_errprintn],
+[m4_errprint([$1
+])])
+
+
+# m4_warning(MSG)
+# ---------------
+# Warn the user.
+m4_define([m4_warning],
+[m4_errprintn(m4_location[: warning: $1])])
+
+
+# m4_fatal(MSG, [EXIT-STATUS])
+# ----------------------------
+# Fatal the user. :)
+m4_define([m4_fatal],
+[m4_errprintn(m4_location[: error: $1]
+m4_expansion_stack)m4_exit(m4_if([$2],, 1, [$2]))])
+
+
+# m4_assert(EXPRESSION, [EXIT-STATUS = 1])
+# ----------------------------------------
+# This macro ensures that EXPRESSION evaluates to true, and exits if
+# EXPRESSION evaluates to false.
+m4_define([m4_assert],
+[m4_if(m4_eval([$1]), 0,
+ [m4_fatal([assert failed: $1], [$2])])])
+
+
+
+## ------------- ##
+## 3. Warnings. ##
+## ------------- ##
+
+
+# _m4_warn(CATEGORY, MESSAGE, [STACK-TRACE])
+# ------------------------------------------
+# Report a MESSAGE to the user if the CATEGORY of warnings is enabled.
+# This is for traces only.
+# If present, STACK-TRACE is a \n-separated list of "LOCATION: MESSAGE",
+# where the last line (and no other) ends with "the top level".
+#
+# Within m4, the macro is a no-op. This macro really matters
+# when autom4te post-processes the trace output.
+m4_define([_m4_warn], [])
+
+
+# m4_warn(CATEGORY, MESSAGE)
+# --------------------------
+# Report a MESSAGE to the user if the CATEGORY of warnings is enabled.
+m4_define([m4_warn],
+[_m4_warn([$1], [$2],
+m4_ifdef([_m4_expansion_stack], [m4_expansion_stack]))])
+
+
+
+## ------------------- ##
+## 4. File inclusion. ##
+## ------------------- ##
+
+
+# We also want to neutralize include (and sinclude for symmetry),
+# but we want to extend them slightly: warn when a file is included
+# several times. This is, in general, a dangerous operation, because
+# too many people forget to quote the first argument of m4_define.
+#
+# For instance in the following case:
+# m4_define(foo, [bar])
+# then a second reading will turn into
+# m4_define(bar, [bar])
+# which is certainly not what was meant.
+
+# m4_include_unique(FILE)
+# -----------------------
+# Declare that the FILE was loading; and warn if it has already
+# been included.
+m4_define([m4_include_unique],
+[m4_ifdef([m4_include($1)],
+ [m4_warn([syntax], [file `$1' included several times])])dnl
+m4_define([m4_include($1)])])
+
+
+# m4_include(FILE)
+# ----------------
+# Like the builtin include, but warns against multiple inclusions.
+m4_define([m4_include],
+[m4_include_unique([$1])dnl
+m4_builtin([include], [$1])])
+
+
+# m4_sinclude(FILE)
+# -----------------
+# Like the builtin sinclude, but warns against multiple inclusions.
+m4_define([m4_sinclude],
+[m4_include_unique([$1])dnl
+m4_builtin([sinclude], [$1])])
+
+
+
+## ------------------------------------ ##
+## 5. Additional branching constructs. ##
+## ------------------------------------ ##
+
+# Both `m4_ifval' and `m4_ifset' tests against the empty string. The
+# difference is that `m4_ifset' is specialized on macros.
+#
+# In case of arguments of macros, eg. $1, it makes little difference.
+# In the case of a macro `FOO', you don't want to check `m4_ifval(FOO,
+# TRUE)', because if `FOO' expands with commas, there is a shifting of
+# the arguments. So you want to run `m4_ifval([FOO])', but then you just
+# compare the *string* `FOO' against `', which, of course fails.
+#
+# So you want the variation `m4_ifset' that expects a macro name as $1.
+# If this macro is both defined and defined to a non empty value, then
+# it runs TRUE, etc.
+
+
+# m4_ifblank(COND, [IF-BLANK], [IF-TEXT])
+# m4_ifnblank(COND, [IF-TEXT], [IF-BLANK])
+# ----------------------------------------
+# If COND is empty, or consists only of blanks (space, tab, newline),
+# then expand IF-BLANK, otherwise expand IF-TEXT. This differs from
+# m4_ifval only if COND has just whitespace, but it helps optimize in
+# spite of users who mistakenly leave trailing space after what they
+# thought was an empty argument:
+# macro(
+# []
+# )
+#
+# Writing one macro in terms of the other causes extra overhead, so
+# we inline both definitions.
+m4_define([m4_ifblank],
+[m4_if(m4_translit([[$1]], [ ][ ][
+]), [], [$2], [$3])])
+
+m4_define([m4_ifnblank],
+[m4_if(m4_translit([[$1]], [ ][ ][
+]), [], [$3], [$2])])
+
+
+# m4_ifval(COND, [IF-TRUE], [IF-FALSE])
+# -------------------------------------
+# If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
+# Comparable to m4_ifdef.
+m4_define([m4_ifval],
+[m4_if([$1], [], [$3], [$2])])
+
+
+# m4_n(TEXT)
+# ----------
+# If TEXT is not empty, return TEXT and a new line, otherwise nothing.
+m4_define([m4_n],
+[m4_if([$1],
+ [], [],
+ [$1
+])])
+
+
+# m4_ifvaln(COND, [IF-TRUE], [IF-FALSE])
+# --------------------------------------
+# Same as `m4_ifval', but add an extra newline to IF-TRUE or IF-FALSE
+# unless that argument is empty.
+m4_define([m4_ifvaln],
+[m4_if([$1],
+ [], [m4_n([$3])],
+ [m4_n([$2])])])
+
+
+# m4_ifset(MACRO, [IF-TRUE], [IF-FALSE])
+# --------------------------------------
+# If MACRO has no definition, or of its definition is the empty string,
+# expand IF-FALSE, otherwise IF-TRUE.
+m4_define([m4_ifset],
+[m4_ifdef([$1],
+ [m4_ifval(_m4_defn([$1]), [$2], [$3])],
+ [$3])])
+
+
+# m4_ifndef(NAME, [IF-NOT-DEFINED], [IF-DEFINED])
+# -----------------------------------------------
+m4_define([m4_ifndef],
+[m4_ifdef([$1], [$3], [$2])])
+
+
+# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
+# -----------------------------------------------------------
+# m4 equivalent of
+# switch (SWITCH)
+# {
+# case VAL1:
+# IF-VAL1;
+# break;
+# case VAL2:
+# IF-VAL2;
+# break;
+# ...
+# default:
+# DEFAULT;
+# break;
+# }.
+# All the values are optional, and the macro is robust to active
+# symbols properly quoted.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_case],
+[m4_if([$#], 0, [],
+ [$#], 1, [],
+ [$#], 2, [$2],
+ [$1], [$2], [$3],
+ [$0([$1], m4_shift3($@))])])
+
+
+# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
+# -----------------------------------------------------
+# m4 equivalent of
+#
+# if (SWITCH =~ RE1)
+# VAL1;
+# elif (SWITCH =~ RE2)
+# VAL2;
+# elif ...
+# ...
+# else
+# DEFAULT
+#
+# All the values are optional, and the macro is robust to active symbols
+# properly quoted.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_bmatch],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+ [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], 2, [$2],
+ [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shift3($@))],
+ [$3])])])
+
+# m4_argn(N, ARGS...)
+# -------------------
+# Extract argument N (greater than 0) from ARGS. Example:
+# m4_define([b], [B])
+# m4_argn([2], [a], [b], [c]) => b
+#
+# Rather than using m4_car(m4_shiftn([$1], $@)), we exploit the fact that
+# GNU m4 can directly reference any argument, through an indirect macro.
+m4_define([m4_argn],
+[m4_assert([0 < $1])]dnl
+[m4_pushdef([_$0], [_m4_popdef([_$0])]m4_dquote([$]m4_incr([$1])))_$0($@)])
+
+
+# m4_car(ARGS...)
+# m4_cdr(ARGS...)
+# ---------------
+# Manipulate m4 lists. m4_car returns the first argument. m4_cdr
+# bundles all but the first argument into a quoted list. These two
+# macros are generally used with list arguments, with quoting removed
+# to break the list into multiple m4 ARGS.
+m4_define([m4_car], [[$1]])
+m4_define([m4_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+ [$#], 1, [],
+ [m4_dquote(m4_shift($@))])])
+
+# _m4_cdr(ARGS...)
+# ----------------
+# Like m4_cdr, except include a leading comma unless only one argument
+# remains. Why? Because comparing a large list against [] is more
+# expensive in expansion time than comparing the number of arguments; so
+# _m4_cdr can be used to reduce the number of arguments when it is time
+# to end recursion.
+m4_define([_m4_cdr],
+[m4_if([$#], 1, [],
+ [, m4_dquote(m4_shift($@))])])
+
+
+
+# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT])
+# -------------------------------------------------------------------
+# Similar to m4_if, except that each TEST is expanded when encountered.
+# If the expansion of TESTn matches the string VALn, the result is IF-VALn.
+# The result is DEFAULT if no tests passed. This macro allows
+# short-circuiting of expensive tests, where it pays to arrange quick
+# filter tests to run first.
+#
+# For an example, consider a previous implementation of _AS_QUOTE_IFELSE:
+#
+# m4_if(m4_index([$1], [\]), [-1], [$2],
+# m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2],
+# m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2],
+# m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3],
+# m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3],
+# [$2])
+#
+# Here, m4_index is computed 5 times, and m4_eval 4, even if $1 contains
+# no backslash. It is more efficient to do:
+#
+# m4_cond([m4_index([$1], [\])], [-1], [$2],
+# [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],
+# [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],
+# [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],
+# [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],
+# [$2])
+#
+# In the common case of $1 with no backslash, only one m4_index expansion
+# occurs, and m4_eval is avoided altogether.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_cond],
+[m4_if([$#], [0], [m4_fatal([$0: cannot be called without arguments])],
+ [$#], [1], [$1],
+ m4_eval([$# % 3]), [2], [m4_fatal([$0: missing an argument])],
+ [_$0($@)])])
+
+m4_define([_m4_cond],
+[m4_if(($1), [($2)], [$3],
+ [$#], [3], [],
+ [$#], [4], [$4],
+ [$0(m4_shift3($@))])])
+
+
+## ---------------------------------------- ##
+## 6. Enhanced version of some primitives. ##
+## ---------------------------------------- ##
+
+# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
+# ----------------------------------------------------
+# m4 equivalent of
+#
+# $_ = STRING;
+# s/RE1/SUBST1/g;
+# s/RE2/SUBST2/g;
+# ...
+#
+# All the values are optional, and the macro is robust to active symbols
+# properly quoted.
+#
+# I would have liked to name this macro `m4_bpatsubst', unfortunately,
+# due to quotation problems, I need to double quote $1 below, therefore
+# the anchors are broken :( I can't let users be trapped by that.
+#
+# Recall that m4_shift3 always results in an argument. Hence, we need
+# to distinguish between a final deletion vs. ending recursion.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_bpatsubsts],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+ [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], 2, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2]))],
+ [$#], 3, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2], [$3]))],
+ [_$0($@m4_if(m4_eval($# & 1), 0, [,]))])])
+m4_define([_m4_bpatsubsts],
+[m4_if([$#], 2, [$1],
+ [$0(m4_builtin([patsubst], [[$1]], [$2], [$3]),
+ m4_shift3($@))])])
+
+
+# m4_copy(SRC, DST)
+# -----------------
+# Define the pushdef stack DST as a copy of the pushdef stack SRC;
+# give an error if DST is already defined. This is particularly nice
+# for copying self-modifying pushdef stacks, where the top definition
+# includes one-shot initialization that is later popped to the normal
+# definition. This version intentionally does nothing if SRC is
+# undefined.
+#
+# Some macros simply can't be renamed with this method: namely, anything
+# involved in the implementation of m4_stack_foreach_sep.
+m4_define([m4_copy],
+[m4_ifdef([$2], [m4_fatal([$0: won't overwrite defined macro: $2])],
+ [m4_stack_foreach_sep([$1], [m4_pushdef([$2],], [)])])]dnl
+[m4_ifdef([m4_location($1)], [m4_define([m4_location($2)], m4_location)])])
+
+
+# m4_copy_force(SRC, DST)
+# m4_rename_force(SRC, DST)
+# -------------------------
+# Like m4_copy/m4_rename, except blindly overwrite any existing DST.
+# Note that m4_copy_force tolerates undefined SRC, while m4_rename_force
+# does not.
+m4_define([m4_copy_force],
+[m4_ifdef([$2], [_m4_undefine([$2])])m4_copy($@)])
+
+m4_define([m4_rename_force],
+[m4_ifdef([$2], [_m4_undefine([$2])])m4_rename($@)])
+
+
+# m4_define_default(MACRO, VALUE)
+# -------------------------------
+# If MACRO is undefined, set it to VALUE.
+m4_define([m4_define_default],
+[m4_ifndef([$1], [m4_define($@)])])
+
+
+# m4_default(EXP1, EXP2)
+# m4_default_nblank(EXP1, EXP2)
+# -----------------------------
+# Returns EXP1 if not empty/blank, otherwise EXP2. Expand the result.
+#
+# m4_default is called on hot paths, so inline the contents of m4_ifval,
+# for one less round of expansion.
+m4_define([m4_default],
+[m4_if([$1], [], [$2], [$1])])
+
+m4_define([m4_default_nblank],
+[m4_ifblank([$1], [$2], [$1])])
+
+
+# m4_default_quoted(EXP1, EXP2)
+# m4_default_nblank_quoted(EXP1, EXP2)
+# ------------------------------------
+# Returns EXP1 if non empty/blank, otherwise EXP2. Leave the result quoted.
+#
+# For comparison:
+# m4_define([active], [ACTIVE])
+# m4_default([active], [default]) => ACTIVE
+# m4_default([], [active]) => ACTIVE
+# -m4_default([ ], [active])- => - -
+# -m4_default_nblank([ ], [active])- => -ACTIVE-
+# m4_default_quoted([active], [default]) => active
+# m4_default_quoted([], [active]) => active
+# -m4_default_quoted([ ], [active])- => - -
+# -m4_default_nblank_quoted([ ], [active])- => -active-
+#
+# m4_default macro is called on hot paths, so inline the contents of m4_ifval,
+# for one less round of expansion.
+m4_define([m4_default_quoted],
+[m4_if([$1], [], [[$2]], [[$1]])])
+
+m4_define([m4_default_nblank_quoted],
+[m4_ifblank([$1], [[$2]], [[$1]])])
+
+
+# m4_defn(NAME)
+# -------------
+# Like the original, except guarantee a warning when using something which is
+# undefined (unlike M4 1.4.x). This replacement is not a full-featured
+# replacement: if any of the defined macros contain unbalanced quoting, but
+# when pasted together result in a well-quoted string, then only native m4
+# support is able to get it correct. But that's where quadrigraphs come in
+# handy, if you really need unbalanced quotes inside your macros.
+#
+# This macro is called frequently, so minimize the amount of additional
+# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
+# (added in M4 1.6), then let m4 do the job for us (see m4_init).
+m4_define([m4_defn],
+[m4_if([$#], [0], [[$0]],
+ [$#], [1], [m4_ifdef([$1], [_m4_defn([$1])],
+ [m4_fatal([$0: undefined macro: $1])])],
+ [m4_map_args([$0], $@)])])
+
+
+# m4_dumpdef(NAME...)
+# -------------------
+# In m4 1.4.x, dumpdef writes to the current debugfile, rather than
+# stderr. This in turn royally confuses autom4te; so we follow the
+# lead of newer m4 and always dump to stderr. Unlike the original,
+# this version requires an argument, since there is no convenient way
+# in m4 1.4.x to grab the names of all defined macros. Newer m4
+# always dumps to stderr, regardless of the current debugfile; it also
+# provides m4symbols as a way to grab all current macro names. But
+# dumpdefs is not frequently called, so we don't need to worry about
+# conditionally using these newer features. Also, this version
+# doesn't sort multiple arguments.
+#
+# If we detect m4 1.6 or newer, then provide an alternate definition,
+# installed during m4_init, that allows builtins through.
+# Unfortunately, there is no nice way in m4 1.4.x to dump builtins.
+m4_define([m4_dumpdef],
+[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
+ [$#], [1], [m4_ifdef([$1], [m4_errprintn(
+ [$1: ]m4_dquote(_m4_defn([$1])))], [m4_fatal([$0: undefined macro: $1])])],
+ [m4_map_args([$0], $@)])])
+
+m4_define([_m4_dumpdef],
+[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
+ [$#], [1], [m4_builtin([dumpdef], [$1])],
+ [m4_map_args_sep([m4_builtin([dumpdef],], [)], [], $@)])])
+
+
+# m4_dumpdefs(NAME...)
+# --------------------
+# Similar to `m4_dumpdef(NAME)', but if NAME was m4_pushdef'ed, display its
+# value stack (most recent displayed first). Also, this version silently
+# ignores undefined macros, rather than erroring out.
+#
+# This macro cheats, because it relies on the current definition of NAME
+# while the second argument of m4_stack_foreach_lifo is evaluated (which
+# would be undefined according to the API).
+m4_define([m4_dumpdefs],
+[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
+ [$#], [1], [m4_stack_foreach_lifo([$1], [m4_dumpdef([$1])m4_ignore])],
+ [m4_map_args([$0], $@)])])
+
+# m4_esyscmd_s(COMMAND)
+# ---------------------
+# Like m4_esyscmd, except strip any trailing newlines, thus behaving
+# more like shell command substitution.
+m4_define([m4_esyscmd_s],
+[m4_chomp_all(m4_esyscmd([$1]))])
+
+
+# m4_popdef(NAME)
+# ---------------
+# Like the original, except guarantee a warning when using something which is
+# undefined (unlike M4 1.4.x).
+#
+# This macro is called frequently, so minimize the amount of additional
+# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
+# (added in M4 1.6), then let m4 do the job for us (see m4_init).
+m4_define([m4_popdef],
+[m4_if([$#], [0], [[$0]],
+ [$#], [1], [m4_ifdef([$1], [_m4_popdef([$1])],
+ [m4_fatal([$0: undefined macro: $1])])],
+ [m4_map_args([$0], $@)])])
+
+
+# m4_shiftn(N, ...)
+# -----------------
+# Returns ... shifted N times. Useful for recursive "varargs" constructs.
+#
+# Autoconf does not use this macro, because it is inherently slower than
+# calling the common cases of m4_shift2 or m4_shift3 directly. But it
+# might as well be fast for other clients, such as Libtool. One way to
+# do this is to expand $@ only once in _m4_shiftn (otherwise, for long
+# lists, the expansion of m4_if takes twice as much memory as what the
+# list itself occupies, only to throw away the unused branch). The end
+# result is strictly equivalent to
+# m4_if([$1], 1, [m4_shift(,m4_shift(m4_shift($@)))],
+# [_m4_shiftn(m4_decr([$1]), m4_shift(m4_shift($@)))])
+# but with the final `m4_shift(m4_shift($@)))' shared between the two
+# paths. The first leg uses a no-op m4_shift(,$@) to balance out the ().
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_shiftn],
+[m4_assert(0 < $1 && $1 < $#)_$0($@)])
+
+m4_define([_m4_shiftn],
+[m4_if([$1], 1, [m4_shift(],
+ [$0(m4_decr([$1])]), m4_shift(m4_shift($@)))])
+
+# m4_shift2(...)
+# m4_shift3(...)
+# --------------
+# Returns ... shifted twice, and three times. Faster than m4_shiftn.
+m4_define([m4_shift2], [m4_shift(m4_shift($@))])
+m4_define([m4_shift3], [m4_shift(m4_shift(m4_shift($@)))])
+
+# _m4_shift2(...)
+# _m4_shift3(...)
+# ---------------
+# Like m4_shift2 or m4_shift3, except include a leading comma unless shifting
+# consumes all arguments. Why? Because in recursion, it is nice to
+# distinguish between 1 element left and 0 elements left, based on how many
+# arguments this shift expands to.
+m4_define([_m4_shift2],
+[m4_if([$#], [2], [],
+ [, m4_shift(m4_shift($@))])])
+m4_define([_m4_shift3],
+[m4_if([$#], [3], [],
+ [, m4_shift(m4_shift(m4_shift($@)))])])
+
+
+# m4_undefine(NAME)
+# -----------------
+# Like the original, except guarantee a warning when using something which is
+# undefined (unlike M4 1.4.x).
+#
+# This macro is called frequently, so minimize the amount of additional
+# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
+# (added in M4 1.6), then let m4 do the job for us (see m4_init).
+m4_define([m4_undefine],
+[m4_if([$#], [0], [[$0]],
+ [$#], [1], [m4_ifdef([$1], [_m4_undefine([$1])],
+ [m4_fatal([$0: undefined macro: $1])])],
+ [m4_map_args([$0], $@)])])
+
+# _m4_wrap(PRE, POST)
+# -------------------
+# Helper macro for m4_wrap and m4_wrap_lifo. Allows nested calls to
+# m4_wrap within wrapped text. Use _m4_defn and _m4_popdef for speed.
+m4_define([_m4_wrap],
+[m4_ifdef([$0_text],
+ [m4_define([$0_text], [$1]_m4_defn([$0_text])[$2])],
+ [m4_builtin([m4wrap], [m4_unquote(
+ _m4_defn([$0_text])_m4_popdef([$0_text]))])m4_define([$0_text], [$1$2])])])
+
+# m4_wrap(TEXT)
+# -------------
+# Append TEXT to the list of hooks to be executed at the end of input.
+# Whereas the order of the original may be LIFO in the underlying m4,
+# this version is always FIFO.
+m4_define([m4_wrap],
+[_m4_wrap([], [$1[]])])
+
+# m4_wrap_lifo(TEXT)
+# ------------------
+# Prepend TEXT to the list of hooks to be executed at the end of input.
+# Whereas the order of m4_wrap may be FIFO in the underlying m4, this
+# version is always LIFO.
+m4_define([m4_wrap_lifo],
+[_m4_wrap([$1[]])])
+
+## ------------------------- ##
+## 7. Quoting manipulation. ##
+## ------------------------- ##
+
+
+# m4_apply(MACRO, LIST)
+# ---------------------
+# Invoke MACRO, with arguments provided from the quoted list of
+# comma-separated quoted arguments. If LIST is empty, invoke MACRO
+# without arguments. The expansion will not be concatenated with
+# subsequent text.
+m4_define([m4_apply],
+[m4_if([$2], [], [$1], [$1($2)])[]])
+
+# _m4_apply(MACRO, LIST)
+# ----------------------
+# Like m4_apply, except do nothing if LIST is empty.
+m4_define([_m4_apply],
+[m4_if([$2], [], [], [$1($2)[]])])
+
+
+# m4_count(ARGS)
+# --------------
+# Return a count of how many ARGS are present.
+m4_define([m4_count], [$#])
+
+
+# m4_curry(MACRO, ARG...)
+# -----------------------
+# Perform argument currying. The expansion of this macro is another
+# macro that takes exactly one argument, appends it to the end of the
+# original ARG list, then invokes MACRO. For example:
+# m4_curry([m4_curry], [m4_reverse], [1])([2])([3]) => 3, 2, 1
+# Not quite as practical as m4_incr, but you could also do:
+# m4_define([add], [m4_eval(([$1]) + ([$2]))])
+# m4_define([add_one], [m4_curry([add], [1])])
+# add_one()([2]) => 3
+m4_define([m4_curry], [$1(m4_shift($@,)_$0])
+m4_define([_m4_curry], [[$1])])
+
+
+# m4_do(STRING, ...)
+# ------------------
+# This macro invokes all its arguments (in sequence, of course). It is
+# useful for making your macros more structured and readable by dropping
+# unnecessary dnl's and have the macros indented properly. No concatenation
+# occurs after a STRING; use m4_unquote(m4_join(,STRING)) for that.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_do],
+[m4_if([$#], 0, [],
+ [$#], 1, [$1[]],
+ [$1[]$0(m4_shift($@))])])
+
+
+# m4_dquote(ARGS)
+# ---------------
+# Return ARGS as a quoted list of quoted arguments.
+m4_define([m4_dquote], [[$@]])
+
+
+# m4_dquote_elt(ARGS)
+# -------------------
+# Return ARGS as an unquoted list of double-quoted arguments.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_dquote_elt],
+[m4_if([$#], [0], [],
+ [$#], [1], [[[$1]]],
+ [[[$1]],$0(m4_shift($@))])])
+
+
+# m4_echo(ARGS)
+# -------------
+# Return the ARGS, with the same level of quoting. Whitespace after
+# unquoted commas are consumed.
+m4_define([m4_echo], [$@])
+
+
+# m4_expand(ARG)
+# _m4_expand(ARG)
+# ---------------
+# Return the expansion of ARG as a single string. Unlike
+# m4_quote($1), this preserves whitespace following single-quoted
+# commas that appear within ARG. It also deals with shell case
+# statements.
+#
+# m4_define([active], [ACT, IVE])
+# m4_define([active2], [[ACT, IVE]])
+# m4_quote(active, active2)
+# => ACT,IVE,ACT, IVE
+# m4_expand([active, active2])
+# => ACT, IVE, ACT, IVE
+#
+# Unfortunately, due to limitations in m4, ARG must expand to
+# something with balanced quotes (use quadrigraphs to get around
+# this), and should not contain the unlikely delimiters -=<{( or
+# )}>=-. It is possible to have unbalanced quoted `(' or `)', as well
+# as unbalanced unquoted `)'. m4_expand can handle unterminated
+# comments or dnl on the final line, at the expense of speed; it also
+# aids in detecting attempts to incorrectly change the current
+# diversion inside ARG. Meanwhile, _m4_expand is faster but must be
+# given a terminated expansion, and has no safety checks for
+# mis-diverted text.
+#
+# Exploit that extra unquoted () will group unquoted commas and the
+# following whitespace. m4_bpatsubst can't handle newlines inside $1,
+# and m4_substr strips quoting. So we (ab)use m4_changequote, using
+# temporary quotes to remove the delimiters that conveniently included
+# the unquoted () that were added prior to the changequote.
+#
+# Thanks to shell case statements, too many people are prone to pass
+# underquoted `)', so we try to detect that by passing a marker as a
+# fourth argument; if the marker is not present, then we assume that
+# we encountered an early `)', and re-expand the first argument, but
+# this time with one more `(' in the second argument and in the
+# open-quote delimiter. We must also ignore the slop from the
+# previous try. The final macro is thus half line-noise, half art.
+m4_define([m4_expand],
+[m4_pushdef([m4_divert], _m4_defn([_m4_divert_unsafe]))]dnl
+[m4_pushdef([m4_divert_push], _m4_defn([_m4_divert_unsafe]))]dnl
+[m4_chomp(_$0([$1
+]))_m4_popdef([m4_divert], [m4_divert_push])])
+
+m4_define([_m4_expand], [$0_([$1], [(], -=<{($1)}>=-, [}>=-])])
+
+m4_define([_m4_expand_],
+[m4_if([$4], [}>=-],
+ [m4_changequote([-=<{$2], [)}>=-])$3m4_changequote([, ])],
+ [$0([$1], [($2], -=<{($2$1)}>=-, [}>=-])m4_ignore$2])])
+
+
+# m4_ignore(ARGS)
+# ---------------
+# Expands to nothing. Useful for conditionally ignoring an arbitrary
+# number of arguments (see _m4_list_cmp for an example).
+m4_define([m4_ignore])
+
+
+# m4_make_list(ARGS)
+# ------------------
+# Similar to m4_dquote, this creates a quoted list of quoted ARGS. This
+# version is less efficient than m4_dquote, but separates each argument
+# with a comma and newline, rather than just comma, for readability.
+# When developing an m4sugar algorithm, you could temporarily use
+# m4_pushdef([m4_dquote],m4_defn([m4_make_list]))
+# around your code to make debugging easier.
+m4_define([m4_make_list], [m4_join([,
+], m4_dquote_elt($@))])
+
+
+# m4_noquote(STRING)
+# ------------------
+# Return the result of ignoring all quotes in STRING and invoking the
+# macros it contains. Among other things, this is useful for enabling
+# macro invocations inside strings with [] blocks (for instance regexps
+# and help-strings). On the other hand, since all quotes are disabled,
+# any macro expanded during this time that relies on nested [] quoting
+# will likely crash and burn. This macro is seldom useful; consider
+# m4_unquote or m4_expand instead.
+m4_define([m4_noquote],
+[m4_changequote([-=<{(],[)}>=-])$1-=<{()}>=-m4_changequote([,])])
+
+
+# m4_quote(ARGS)
+# --------------
+# Return ARGS as a single argument. Any whitespace after unquoted commas
+# is stripped. There is always output, even when there were no arguments.
+#
+# It is important to realize the difference between `m4_quote(exp)' and
+# `[exp]': in the first case you obtain the quoted *result* of the
+# expansion of EXP, while in the latter you just obtain the string
+# `exp'.
+m4_define([m4_quote], [[$*]])
+
+
+# _m4_quote(ARGS)
+# ---------------
+# Like m4_quote, except that when there are no arguments, there is no
+# output. For conditional scenarios (such as passing _m4_quote as the
+# macro name in m4_mapall), this feature can be used to distinguish between
+# one argument of the empty string vs. no arguments. However, in the
+# normal case with arguments present, this is less efficient than m4_quote.
+m4_define([_m4_quote],
+[m4_if([$#], [0], [], [[$*]])])
+
+
+# m4_reverse(ARGS)
+# ----------------
+# Output ARGS in reverse order.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_reverse],
+[m4_if([$#], [0], [], [$#], [1], [[$1]],
+ [$0(m4_shift($@)), [$1]])])
+
+
+# m4_unquote(ARGS)
+# ----------------
+# Remove one layer of quotes from each ARG, performing one level of
+# expansion. For one argument, m4_unquote([arg]) is more efficient than
+# m4_do([arg]), but for multiple arguments, the difference is that
+# m4_unquote separates arguments with commas while m4_do concatenates.
+# Follow this macro with [] if concatenation with subsequent text is
+# undesired.
+m4_define([m4_unquote], [$*])
+
+
+## -------------------------- ##
+## 8. Implementing m4 loops. ##
+## -------------------------- ##
+
+
+# m4_for(VARIABLE, FIRST, LAST, [STEP = +/-1], EXPRESSION)
+# --------------------------------------------------------
+# Expand EXPRESSION defining VARIABLE to FROM, FROM + 1, ..., TO with
+# increments of STEP. Both limits are included, and bounds are
+# checked for consistency. The algorithm is robust to indirect
+# VARIABLE names. Changing VARIABLE inside EXPRESSION will not impact
+# the number of iterations.
+#
+# Uses _m4_defn for speed, and avoid dnl in the macro body. Factor
+# the _m4_for call so that EXPRESSION is only parsed once.
+m4_define([m4_for],
+[m4_pushdef([$1], m4_eval([$2]))]dnl
+[m4_cond([m4_eval(([$3]) > ([$2]))], 1,
+ [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4],
+ 1)))m4_assert(_m4_step > 0)_$0(_m4_defn([$1]),
+ m4_eval((([$3]) - ([$2])) / _m4_step * _m4_step + ([$2])), _m4_step,],
+ [m4_eval(([$3]) < ([$2]))], 1,
+ [m4_pushdef([_m4_step], m4_eval(m4_default_quoted([$4],
+ -1)))m4_assert(_m4_step < 0)_$0(_m4_defn([$1]),
+ m4_eval((([$2]) - ([$3])) / -(_m4_step) * _m4_step + ([$2])), _m4_step,],
+ [m4_pushdef([_m4_step])_$0(_m4_defn([$1]), _m4_defn([$1]), 0,])]dnl
+[[m4_define([$1],], [)$5])m4_popdef([_m4_step], [$1])])
+
+# _m4_for(COUNT, LAST, STEP, PRE, POST)
+# -------------------------------------
+# Core of the loop, no consistency checks, all arguments are plain
+# numbers. Expand PRE[COUNT]POST, then alter COUNT by STEP and
+# iterate if COUNT is not LAST.
+m4_define([_m4_for],
+[$4[$1]$5[]m4_if([$1], [$2], [],
+ [$0(m4_eval([$1 + $3]), [$2], [$3], [$4], [$5])])])
+
+
+# Implementing `foreach' loops in m4 is much more tricky than it may
+# seem. For example, the old M4 1.4.4 manual had an incorrect example,
+# which looked like this (when translated to m4sugar):
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach],
+# | [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])])
+# | m4_define([_arg1], [$1])
+# | m4_define([_foreach],
+# | [m4_if([$2], [()], ,
+# | [m4_define([$1], _arg1$2)$3[]_foreach([$1], (m4_shift$2), [$3])])])
+#
+# But then if you run
+#
+# | m4_define(a, 1)
+# | m4_define(b, 2)
+# | m4_define(c, 3)
+# | foreach([f], [([a], [(b], [c)])], [echo f
+# | ])
+#
+# it gives
+#
+# => echo 1
+# => echo (2,3)
+#
+# which is not what is expected.
+#
+# Of course the problem is that many quotes are missing. So you add
+# plenty of quotes at random places, until you reach the expected
+# result. Alternatively, if you are a quoting wizard, you directly
+# reach the following implementation (but if you really did, then
+# apply to the maintenance of m4sugar!).
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
+# | m4_define([_arg1], [[$1]])
+# | m4_define([_foreach],
+# | [m4_if($2, [()], ,
+# | [m4_define([$1], [_arg1$2])$3[]_foreach([$1], [(m4_shift$2)], [$3])])])
+#
+# which this time answers
+#
+# => echo a
+# => echo (b
+# => echo c)
+#
+# Bingo!
+#
+# Well, not quite.
+#
+# With a better look, you realize that the parens are more a pain than
+# a help: since anyway you need to quote properly the list, you end up
+# with always using an outermost pair of parens and an outermost pair
+# of quotes. Rejecting the parens both eases the implementation, and
+# simplifies the use:
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
+# | m4_define([_arg1], [$1])
+# | m4_define([_foreach],
+# | [m4_if($2, [], ,
+# | [m4_define([$1], [_arg1($2)])$3[]_foreach([$1], [m4_shift($2)], [$3])])])
+#
+#
+# Now, just replace the `$2' with `m4_quote($2)' in the outer `m4_if'
+# to improve robustness, and you come up with a nice implementation
+# that doesn't require extra parentheses in the user's LIST.
+#
+# But wait - now the algorithm is quadratic, because every recursion of
+# the algorithm keeps the entire LIST and merely adds another m4_shift to
+# the quoted text. If the user has a lot of elements in LIST, you can
+# bring the system to its knees with the memory m4 then requires, or trip
+# the m4 --nesting-limit recursion factor. The only way to avoid
+# quadratic growth is ensure m4_shift is expanded prior to the recursion.
+# Hence the design below.
+#
+# The M4 manual now includes a chapter devoted to this issue, with
+# the lessons learned from m4sugar. And still, this design is only
+# optimal for M4 1.6; see foreach.m4 for yet more comments on why
+# M4 1.4.x uses yet another implementation.
+
+
+# m4_foreach(VARIABLE, LIST, EXPRESSION)
+# --------------------------------------
+#
+# Expand EXPRESSION assigning each value of the LIST to VARIABLE.
+# LIST should have the form `item_1, item_2, ..., item_n', i.e. the
+# whole list must *quoted*. Quote members too if you don't want them
+# to be expanded.
+#
+# This macro is robust to active symbols:
+# | m4_define(active, [ACT, IVE])
+# | m4_foreach(Var, [active, active], [-Var-])
+# => -ACT--IVE--ACT--IVE-
+#
+# | m4_foreach(Var, [[active], [active]], [-Var-])
+# => -ACT, IVE--ACT, IVE-
+#
+# | m4_foreach(Var, [[[active]], [[active]]], [-Var-])
+# => -active--active-
+#
+# This macro is called frequently, so avoid extra expansions such as
+# m4_ifval and dnl. Also, since $2 might be quite large, try to use it
+# as little as possible in _m4_foreach; each extra use requires that much
+# more memory for expansion. So, rather than directly compare $2 against
+# [] and use m4_car/m4_cdr for recursion, we instead unbox the list (which
+# requires swapping the argument order in the helper), insert an ignored
+# third argument, and use m4_shift3 to detect when recursion is complete,
+# at which point this looks very much like m4_map_args.
+m4_define([m4_foreach],
+[m4_if([$2], [], [],
+ [m4_pushdef([$1])_$0([m4_define([$1],], [)$3], [],
+ $2)m4_popdef([$1])])])
+
+# _m4_foreach(PRE, POST, IGNORED, ARG...)
+# ---------------------------------------
+# Form the common basis of the m4_foreach and m4_map macros. For each
+# ARG, expand PRE[ARG]POST[]. The IGNORED argument makes recursion
+# easier, and must be supplied rather than implicit.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([_m4_foreach],
+[m4_if([$#], [3], [],
+ [$1[$4]$2[]$0([$1], [$2], m4_shift3($@))])])
+
+
+# m4_foreach_w(VARIABLE, LIST, EXPRESSION)
+# ----------------------------------------
+# Like m4_foreach, but the list is whitespace separated. Depending on
+# EXPRESSION, it may be more efficient to use m4_map_args_w.
+#
+# This macro is robust to active symbols:
+# m4_foreach_w([Var], [ active
+# b act\
+# ive ], [-Var-])end
+# => -active--b--active-end
+#
+# This used to use a slower implementation based on m4_foreach:
+# m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])
+m4_define([m4_foreach_w],
+[m4_pushdef([$1])m4_map_args_w([$2],
+ [m4_define([$1],], [)$3])m4_popdef([$1])])
+
+
+# m4_map(MACRO, LIST)
+# m4_mapall(MACRO, LIST)
+# ----------------------
+# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements of
+# LIST. $1, $2... must in turn be lists, appropriate for m4_apply.
+# If LIST contains an empty sublist, m4_map skips the expansion of
+# MACRO, while m4_mapall expands MACRO with no arguments.
+#
+# Since LIST may be quite large, we want to minimize how often it
+# appears in the expansion. Rather than use m4_car/m4_cdr iteration,
+# we unbox the list, and use _m4_foreach for iteration. For m4_map,
+# an empty list behaves like an empty sublist and gets ignored; for
+# m4_mapall, we must special-case the empty list.
+m4_define([m4_map],
+[_m4_foreach([_m4_apply([$1],], [)], [], $2)])
+
+m4_define([m4_mapall],
+[m4_if([$2], [], [],
+ [_m4_foreach([m4_apply([$1],], [)], [], $2)])])
+
+
+# m4_map_sep(MACRO, [SEPARATOR], LIST)
+# m4_mapall_sep(MACRO, [SEPARATOR], LIST)
+# ---------------------------------------
+# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1,
+# $2... $N are the elements of LIST, and are in turn lists appropriate
+# for m4_apply. SEPARATOR is expanded, in order to allow the creation
+# of a list of arguments by using a single-quoted comma as the
+# separator. For each empty sublist, m4_map_sep skips the expansion
+# of MACRO and SEPARATOR, while m4_mapall_sep expands MACRO with no
+# arguments.
+#
+# For m4_mapall_sep, merely expand the first iteration without the
+# separator, then include separator as part of subsequent recursion;
+# but avoid extra expansion of LIST's side-effects via a helper macro.
+# For m4_map_sep, things are trickier - we don't know if the first
+# list element is an empty sublist, so we must define a self-modifying
+# helper macro and use that as the separator instead.
+m4_define([m4_map_sep],
+[m4_pushdef([m4_Sep], [m4_define([m4_Sep], _m4_defn([m4_unquote]))])]dnl
+[_m4_foreach([_m4_apply([m4_Sep([$2])[]$1],], [)], [], $3)m4_popdef([m4_Sep])])
+
+m4_define([m4_mapall_sep],
+[m4_if([$3], [], [], [_$0([$1], [$2], $3)])])
+
+m4_define([_m4_mapall_sep],
+[m4_apply([$1], [$3])_m4_foreach([m4_apply([$2[]$1],], [)], m4_shift2($@))])
+
+# m4_map_args(EXPRESSION, ARG...)
+# -------------------------------
+# Expand EXPRESSION([ARG]) for each argument. More efficient than
+# m4_foreach([var], [ARG...], [EXPRESSION(m4_defn([var]))])
+# Shorthand for m4_map_args_sep([EXPRESSION(], [)], [], ARG...).
+m4_define([m4_map_args],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [],
+ [$#], [2], [$1([$2])[]],
+ [_m4_foreach([$1(], [)], $@)])])
+
+
+# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
+# -------------------------------------------------------------
+# Perform a pairwise grouping of consecutive ARGs, by expanding
+# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the
+# final argument is expanded with END-EXPR([ARGn]).
+#
+# For example:
+# m4_define([show], [($*)m4_newline])dnl
+# m4_map_args_pair([show], [], [a], [b], [c], [d], [e])dnl
+# => (a,b)
+# => (c,d)
+# => (e)
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_map_args_pair],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], [2], [],
+ [$#], [3], [m4_default([$2], [$1])([$3])[]],
+ [$#], [4], [$1([$3], [$4])[]],
+ [$1([$3], [$4])[]$0([$1], [$2], m4_shift(m4_shift3($@)))])])
+
+
+# m4_map_args_sep([PRE], [POST], [SEP], ARG...)
+# ---------------------------------------------
+# Expand PRE[ARG]POST for each argument, with SEP between arguments.
+m4_define([m4_map_args_sep],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [],
+ [$#], [2], [],
+ [$#], [3], [],
+ [$#], [4], [$1[$4]$2[]],
+ [$1[$4]$2[]_m4_foreach([$3[]$1], [$2], m4_shift3($@))])])
+
+
+# m4_map_args_w(STRING, [PRE], [POST], [SEP])
+# -------------------------------------------
+# Perform the expansion of PRE[word]POST[] for each word in STRING
+# separated by whitespace. More efficient than:
+# m4_foreach_w([var], [STRING], [PRE[]m4_defn([var])POST])
+# Additionally, expand SEP between words.
+#
+# As long as we have to use m4_bpatsubst to split the string, we might
+# as well make it also apply PRE and POST; this avoids iteration
+# altogether. But we must be careful of any \ in PRE or POST.
+# _m4_strip returns a quoted string, but that's okay, since it also
+# supplies an empty leading and trailing argument due to our
+# intentional whitespace around STRING. We use m4_substr to strip the
+# empty elements and remove the extra layer of quoting.
+m4_define([m4_map_args_w],
+[_$0(_m4_split([ ]m4_flatten([$1])[ ], [[ ]+],
+ m4_if(m4_index([$2$3$4], [\]), [-1], [[$3[]$4[]$2]],
+ [m4_bpatsubst([[$3[]$4[]$2]], [\\], [\\\\])])),
+ m4_len([[]$3[]$4]), m4_len([$4[]$2[]]))])
+
+m4_define([_m4_map_args_w],
+[m4_substr([$1], [$2], m4_eval(m4_len([$1]) - [$2] - [$3]))])
+
+
+# m4_stack_foreach(MACRO, FUNC)
+# m4_stack_foreach_lifo(MACRO, FUNC)
+# ----------------------------------
+# Pass each stacked definition of MACRO to the one-argument macro FUNC.
+# m4_stack_foreach proceeds in FIFO order, while m4_stack_foreach_lifo
+# processes the topmost definitions first. In addition, FUNC should
+# not push or pop definitions of MACRO, and should not expect anything about
+# the active definition of MACRO (it will not be the topmost, and may not
+# be the one passed to FUNC either).
+#
+# Some macros simply can't be examined with this method: namely,
+# anything involved in the implementation of _m4_stack_reverse.
+m4_define([m4_stack_foreach],
+[_m4_stack_reverse([$1], [m4_tmp-$1])]dnl
+[_m4_stack_reverse([m4_tmp-$1], [$1], [$2(_m4_defn([m4_tmp-$1]))])])
+
+m4_define([m4_stack_foreach_lifo],
+[_m4_stack_reverse([$1], [m4_tmp-$1], [$2(_m4_defn([m4_tmp-$1]))])]dnl
+[_m4_stack_reverse([m4_tmp-$1], [$1])])
+
+# m4_stack_foreach_sep(MACRO, [PRE], [POST], [SEP])
+# m4_stack_foreach_sep_lifo(MACRO, [PRE], [POST], [SEP])
+# ------------------------------------------------------
+# Similar to m4_stack_foreach and m4_stack_foreach_lifo, in that every
+# definition of a pushdef stack will be visited. But rather than
+# passing the definition as a single argument to a macro, this variant
+# expands the concatenation of PRE[]definition[]POST, and expands SEP
+# between consecutive expansions. Note that m4_stack_foreach([a], [b])
+# is equivalent to m4_stack_foreach_sep([a], [b(], [)]).
+m4_define([m4_stack_foreach_sep],
+[_m4_stack_reverse([$1], [m4_tmp-$1])]dnl
+[_m4_stack_reverse([m4_tmp-$1], [$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4[]])])
+
+m4_define([m4_stack_foreach_sep_lifo],
+[_m4_stack_reverse([$1], [m4_tmp-$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4[]])]dnl
+[_m4_stack_reverse([m4_tmp-$1], [$1])])
+
+
+# _m4_stack_reverse(OLD, NEW, [ACTION], [SEP])
+# --------------------------------------------
+# A recursive worker for pushdef stack manipulation. Destructively
+# copy the OLD stack into the NEW, and expanding ACTION for each
+# iteration. After the first iteration, SEP is promoted to the front
+# of ACTION (note that SEP should include a trailing [] if it is to
+# avoid interfering with ACTION). The current definition is examined
+# after the NEW has been pushed but before OLD has been popped; this
+# order is important, as ACTION is permitted to operate on either
+# _m4_defn([OLD]) or _m4_defn([NEW]). Since the operation is
+# destructive, this macro is generally used twice, with a temporary
+# macro name holding the swapped copy.
+m4_define([_m4_stack_reverse],
+[m4_ifdef([$1], [m4_pushdef([$2],
+ _m4_defn([$1]))$3[]_m4_popdef([$1])$0([$1], [$2], [$4$3])])])
+
+
+
+## --------------------------- ##
+## 9. More diversion support. ##
+## --------------------------- ##
+
+
+# m4_cleardivert(DIVERSION-NAME...)
+# ---------------------------------
+# Discard any text in DIVERSION-NAME.
+#
+# This works even inside m4_expand.
+m4_define([m4_cleardivert],
+[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
+ [_m4_divert_raw([-1])m4_undivert($@)_m4_divert_raw(
+ _m4_divert(_m4_defn([_m4_divert_diversion]), [-]))])])
+
+
+# _m4_divert(DIVERSION-NAME or NUMBER, [NOWARN])
+# ----------------------------------------------
+# If DIVERSION-NAME is the name of a diversion, return its number,
+# otherwise if it is a NUMBER return it. Issue a warning about
+# the use of a number instead of a name, unless NOWARN is provided.
+m4_define([_m4_divert],
+[m4_ifdef([_m4_divert($1)],
+ [m4_indir([_m4_divert($1)])],
+ [m4_if([$2], [], [m4_warn([syntax],
+ [prefer named diversions])])$1])])
+
+# KILL is only used to suppress output.
+m4_define([_m4_divert(KILL)], -1)
+
+# The empty diversion name is a synonym for 0.
+m4_define([_m4_divert()], 0)
+
+
+# m4_divert_stack
+# ---------------
+# Print the diversion stack, if it's nonempty. The caller is
+# responsible for any leading or trailing newline.
+m4_define([m4_divert_stack],
+[m4_stack_foreach_sep_lifo([_m4_divert_stack], [], [], [
+])])
+
+
+# m4_divert_stack_push(MACRO-NAME, DIVERSION-NAME)
+# ------------------------------------------------
+# Form an entry of the diversion stack from caller MACRO-NAME and
+# entering DIVERSION-NAME and push it.
+m4_define([m4_divert_stack_push],
+[m4_pushdef([_m4_divert_stack], m4_location[: $1: $2])])
+
+
+# m4_divert(DIVERSION-NAME)
+# -------------------------
+# Change the diversion stream to DIVERSION-NAME.
+m4_define([m4_divert],
+[m4_popdef([_m4_divert_stack])]dnl
+[m4_define([_m4_divert_diversion], [$1])]dnl
+[m4_divert_stack_push([$0], [$1])]dnl
+[_m4_divert_raw(_m4_divert([$1]))])
+
+
+# m4_divert_push(DIVERSION-NAME, [NOWARN])
+# ----------------------------------------
+# Change the diversion stream to DIVERSION-NAME, while stacking old values.
+# For internal use only: if NOWARN is not empty, DIVERSION-NAME can be a
+# number instead of a name.
+m4_define([m4_divert_push],
+[m4_divert_stack_push([$0], [$1])]dnl
+[m4_pushdef([_m4_divert_diversion], [$1])]dnl
+[_m4_divert_raw(_m4_divert([$1], [$2]))])
+
+
+# m4_divert_pop([DIVERSION-NAME])
+# -------------------------------
+# Change the diversion stream to its previous value, unstacking it.
+# If specified, verify we left DIVERSION-NAME.
+# When we pop the last value from the stack, we divert to -1.
+m4_define([m4_divert_pop],
+[m4_if([$1], [], [],
+ [$1], _m4_defn([_m4_divert_diversion]), [],
+ [m4_fatal([$0($1): diversion mismatch:
+]m4_divert_stack)])]dnl
+[_m4_popdef([_m4_divert_stack], [_m4_divert_diversion])]dnl
+[m4_ifdef([_m4_divert_diversion], [],
+ [m4_fatal([too many m4_divert_pop])])]dnl
+[_m4_divert_raw(_m4_divert(_m4_defn([_m4_divert_diversion]), [-]))])
+
+
+# m4_divert_text(DIVERSION-NAME, CONTENT)
+# ---------------------------------------
+# Output CONTENT into DIVERSION-NAME (which may be a number actually).
+# An end of line is appended for free to CONTENT.
+m4_define([m4_divert_text],
+[m4_divert_push([$1])$2
+m4_divert_pop([$1])])
+
+
+# m4_divert_once(DIVERSION-NAME, CONTENT)
+# ---------------------------------------
+# Output CONTENT into DIVERSION-NAME once, if not already there.
+# An end of line is appended for free to CONTENT.
+m4_define([m4_divert_once],
+[m4_expand_once([m4_divert_text([$1], [$2])])])
+
+
+# _m4_divert_unsafe(DIVERSION-NAME)
+# ---------------------------------
+# Issue a warning that the attempt to change the current diversion to
+# DIVERSION-NAME is unsafe, because this macro is being expanded
+# during argument collection of m4_expand.
+m4_define([_m4_divert_unsafe],
+[m4_fatal([$0: cannot change diversion to `$1' inside m4_expand])])
+
+
+# m4_undivert(DIVERSION-NAME...)
+# ------------------------------
+# Undivert DIVERSION-NAME. Unlike the M4 version, this requires at
+# least one DIVERSION-NAME; also, due to support for named diversions,
+# this should not be used to undivert files.
+m4_define([m4_undivert],
+[m4_if([$#], [0], [m4_fatal([$0: missing argument])],
+ [$#], [1], [_m4_undivert(_m4_divert([$1]))],
+ [m4_map_args([$0], $@)])])
+
+
+## --------------------------------------------- ##
+## 10. Defining macros with bells and whistles. ##
+## --------------------------------------------- ##
+
+# `m4_defun' is basically `m4_define' but it equips the macro with the
+# needed machinery for `m4_require'. A macro must be m4_defun'd if
+# either it is m4_require'd, or it m4_require's.
+#
+# Two things deserve attention and are detailed below:
+# 1. Implementation of m4_require
+# 2. Keeping track of the expansion stack
+#
+# 1. Implementation of m4_require
+# ===============================
+#
+# Of course m4_defun calls m4_provide, so that a macro which has
+# been expanded is not expanded again when m4_require'd, but the
+# difficult part is the proper expansion of macros when they are
+# m4_require'd.
+#
+# The implementation is based on three ideas, (i) using diversions to
+# prepare the expansion of the macro and its dependencies (by Franc,ois
+# Pinard), (ii) expand the most recently m4_require'd macros _after_
+# the previous macros (by Axel Thimm), and (iii) track instances of
+# provide before require (by Eric Blake).
+#
+#
+# The first idea: why use diversions?
+# -----------------------------------
+#
+# When a macro requires another, the other macro is expanded in new
+# diversion, GROW. When the outer macro is fully expanded, we first
+# undivert the most nested diversions (GROW - 1...), and finally
+# undivert GROW. To understand why we need several diversions,
+# consider the following example:
+#
+# | m4_defun([TEST1], [Test...m4_require([TEST2])1])
+# | m4_defun([TEST2], [Test...m4_require([TEST3])2])
+# | m4_defun([TEST3], [Test...3])
+#
+# Because m4_require is not required to be first in the outer macros, we
+# must keep the expansions of the various levels of m4_require separated.
+# Right before executing the epilogue of TEST1, we have:
+#
+# GROW - 2: Test...3
+# GROW - 1: Test...2
+# GROW: Test...1
+# BODY:
+#
+# Finally the epilogue of TEST1 undiverts GROW - 2, GROW - 1, and
+# GROW into the regular flow, BODY.
+#
+# GROW - 2:
+# GROW - 1:
+# GROW:
+# BODY: Test...3; Test...2; Test...1
+#
+# (The semicolons are here for clarification, but of course are not
+# emitted.) This is what Autoconf 2.0 (I think) to 2.13 (I'm sure)
+# implement.
+#
+#
+# The second idea: first required first out
+# -----------------------------------------
+#
+# The natural implementation of the idea above is buggy and produces
+# very surprising results in some situations. Let's consider the
+# following example to explain the bug:
+#
+# | m4_defun([TEST1], [m4_require([TEST2a])m4_require([TEST2b])])
+# | m4_defun([TEST2a], [])
+# | m4_defun([TEST2b], [m4_require([TEST3])])
+# | m4_defun([TEST3], [m4_require([TEST2a])])
+# |
+# | AC_INIT
+# | TEST1
+#
+# The dependencies between the macros are:
+#
+# 3 --- 2b
+# / \ is m4_require'd by
+# / \ left -------------------- right
+# 2a ------------ 1
+#
+# If you strictly apply the rules given in the previous section you get:
+#
+# GROW - 2: TEST3
+# GROW - 1: TEST2a; TEST2b
+# GROW: TEST1
+# BODY:
+#
+# (TEST2a, although required by TEST3 is not expanded in GROW - 3
+# because is has already been expanded before in GROW - 1, so it has
+# been AC_PROVIDE'd, so it is not expanded again) so when you undivert
+# the stack of diversions, you get:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW:
+# BODY: TEST3; TEST2a; TEST2b; TEST1
+#
+# i.e., TEST2a is expanded after TEST3 although the latter required the
+# former.
+#
+# Starting from 2.50, we use an implementation provided by Axel Thimm.
+# The idea is simple: the order in which macros are emitted must be the
+# same as the one in which macros are expanded. (The bug above can
+# indeed be described as: a macro has been m4_provide'd before its
+# dependent, but it is emitted after: the lack of correlation between
+# emission and expansion order is guilty).
+#
+# How to do that? You keep the stack of diversions to elaborate the
+# macros, but each time a macro is fully expanded, emit it immediately.
+#
+# In the example above, when TEST2a is expanded, but it's epilogue is
+# not run yet, you have:
+#
+# GROW - 2:
+# GROW - 1: TEST2a
+# GROW: Elaboration of TEST1
+# BODY:
+#
+# The epilogue of TEST2a emits it immediately:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW: Elaboration of TEST1
+# BODY: TEST2a
+#
+# TEST2b then requires TEST3, so right before the epilogue of TEST3, you
+# have:
+#
+# GROW - 2: TEST3
+# GROW - 1: Elaboration of TEST2b
+# GROW: Elaboration of TEST1
+# BODY: TEST2a
+#
+# The epilogue of TEST3 emits it:
+#
+# GROW - 2:
+# GROW - 1: Elaboration of TEST2b
+# GROW: Elaboration of TEST1
+# BODY: TEST2a; TEST3
+#
+# TEST2b is now completely expanded, and emitted:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW: Elaboration of TEST1
+# BODY: TEST2a; TEST3; TEST2b
+#
+# and finally, TEST1 is finished and emitted:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW:
+# BODY: TEST2a; TEST3; TEST2b: TEST1
+#
+# The idea is simple, but the implementation is a bit involved. If
+# you are like me, you will want to see the actual functioning of this
+# implementation to be convinced. The next section gives the full
+# details.
+#
+#
+# The Axel Thimm implementation at work
+# -------------------------------------
+#
+# We consider the macros above, and this configure.ac:
+#
+# AC_INIT
+# TEST1
+#
+# You should keep the definitions of _m4_defun_pro, _m4_defun_epi, and
+# m4_require at hand to follow the steps.
+#
+# This implementation tries not to assume that the current diversion is
+# BODY, so as soon as a macro (m4_defun'd) is expanded, we first
+# record the current diversion under the name _m4_divert_dump (denoted
+# DUMP below for short). This introduces an important difference with
+# the previous versions of Autoconf: you cannot use m4_require if you
+# are not inside an m4_defun'd macro, and especially, you cannot
+# m4_require directly from the top level.
+#
+# We have not tried to simulate the old behavior (better yet, we
+# diagnose it), because it is too dangerous: a macro m4_require'd from
+# the top level is expanded before the body of `configure', i.e., before
+# any other test was run. I let you imagine the result of requiring
+# AC_STDC_HEADERS for instance, before AC_PROG_CC was actually run....
+#
+# After AC_INIT was run, the current diversion is BODY.
+# * AC_INIT was run
+# DUMP: undefined
+# diversion stack: BODY |-
+#
+# * TEST1 is expanded
+# The prologue of TEST1 sets _m4_divert_dump, which is the diversion
+# where the current elaboration will be dumped, to the current
+# diversion. It also m4_divert_push to GROW, where the full
+# expansion of TEST1 and its dependencies will be elaborated.
+# DUMP: BODY
+# BODY: empty
+# diversions: GROW, BODY |-
+#
+# * TEST1 requires TEST2a
+# _m4_require_call m4_divert_pushes another temporary diversion,
+# GROW - 1, and expands TEST2a in there.
+# DUMP: BODY
+# BODY: empty
+# GROW - 1: TEST2a
+# diversions: GROW - 1, GROW, BODY |-
+# Then the content of the temporary diversion is moved to DUMP and the
+# temporary diversion is popped.
+# DUMP: BODY
+# BODY: TEST2a
+# diversions: GROW, BODY |-
+#
+# * TEST1 requires TEST2b
+# Again, _m4_require_call pushes GROW - 1 and heads to expand TEST2b.
+# DUMP: BODY
+# BODY: TEST2a
+# diversions: GROW - 1, GROW, BODY |-
+#
+# * TEST2b requires TEST3
+# _m4_require_call pushes GROW - 2 and expands TEST3 here.
+# (TEST3 requires TEST2a, but TEST2a has already been m4_provide'd, so
+# nothing happens.)
+# DUMP: BODY
+# BODY: TEST2a
+# GROW - 2: TEST3
+# diversions: GROW - 2, GROW - 1, GROW, BODY |-
+# Then the diversion is appended to DUMP, and popped.
+# DUMP: BODY
+# BODY: TEST2a; TEST3
+# diversions: GROW - 1, GROW, BODY |-
+#
+# * TEST1 requires TEST2b (contd.)
+# The content of TEST2b is expanded...
+# DUMP: BODY
+# BODY: TEST2a; TEST3
+# GROW - 1: TEST2b,
+# diversions: GROW - 1, GROW, BODY |-
+# ... and moved to DUMP.
+# DUMP: BODY
+# BODY: TEST2a; TEST3; TEST2b
+# diversions: GROW, BODY |-
+#
+# * TEST1 is expanded: epilogue
+# TEST1's own content is in GROW...
+# DUMP: BODY
+# BODY: TEST2a; TEST3; TEST2b
+# GROW: TEST1
+# diversions: BODY |-
+# ... and it's epilogue moves it to DUMP and then undefines DUMP.
+# DUMP: undefined
+# BODY: TEST2a; TEST3; TEST2b; TEST1
+# diversions: BODY |-
+#
+#
+# The third idea: track macros provided before they were required
+# ---------------------------------------------------------------
+#
+# Using just the first two ideas, Autoconf 2.50 through 2.63 still had
+# a subtle bug for more than seven years. Let's consider the
+# following example to explain the bug:
+#
+# | m4_defun([TEST1], [1])
+# | m4_defun([TEST2], [2[]m4_require([TEST1])])
+# | m4_defun([TEST3], [3 TEST1 m4_require([TEST2])])
+# | TEST3
+#
+# After the prologue of TEST3, we are collecting text in GROW with the
+# intent of dumping it in BODY during the epilogue. Next, we
+# encounter the direct invocation of TEST1, which provides the macro
+# in place in GROW. From there, we encounter a requirement for TEST2,
+# which must be collected in a new diversion. While expanding TEST2,
+# we encounter a requirement for TEST1, but since it has already been
+# expanded, the Axel Thimm algorithm states that we can treat it as a
+# no-op. But that would lead to an end result of `2 3 1', meaning
+# that we have once again output a macro (TEST2) prior to its
+# requirements (TEST1).
+#
+# The problem can only occur if a single defun'd macro first provides,
+# then later indirectly requires, the same macro. Note that directly
+# expanding then requiring a macro is okay: because the dependency was
+# met, the require phase can be a no-op. For that matter, the outer
+# macro can even require two helpers, where the first helper expands
+# the macro, and the second helper indirectly requires the macro.
+# Out-of-order expansion is only present if the inner macro is
+# required by something that will be hoisted in front of where the
+# direct expansion occurred. In other words, we must be careful not
+# to warn on:
+#
+# | m4_defun([TEST4], [4])
+# | m4_defun([TEST5], [5 TEST4 m4_require([TEST4])])
+# | TEST5 => 5 4
+#
+# or even the more complex:
+#
+# | m4_defun([TEST6], [6])
+# | m4_defun([TEST7], [7 TEST6])
+# | m4_defun([TEST8], [8 m4_require([TEST6])])
+# | m4_defun([TEST9], [9 m4_require([TEST8])])
+# | m4_defun([TEST10], [10 m4_require([TEST7]) m4_require([TEST9])])
+# | TEST10 => 7 6 8 9 10
+#
+# So, to detect whether a require was direct or indirect, m4_defun and
+# m4_require track the name of the macro that caused a diversion to be
+# created (using the stack _m4_diverting, coupled with an O(1) lookup
+# _m4_diverting([NAME])), and m4_provide stores the name associated
+# with the diversion at which a macro was provided. A require call is
+# direct if it occurs within the same diversion where the macro was
+# provided, or if the diversion associated with the providing context
+# has been collected.
+#
+# The implementation of the warning involves tracking the set of
+# macros which have been provided since the start of the outermost
+# defun'd macro (the set is named _m4_provide). When starting an
+# outermost macro, the set is emptied; when a macro is provided, it is
+# added to the set; when require expands the body of a macro, it is
+# removed from the set; and when a macro is indirectly required, the
+# set is checked. If a macro is in the set, then it has been provided
+# before it was required, and we satisfy dependencies by expanding the
+# macro as if it had never been provided; in the example given above,
+# this means we now output `1 2 3 1'. Meanwhile, a warning is issued
+# to inform the user that her macros trigger the bug in older autoconf
+# versions, and that her output file now contains redundant contents
+# (and possibly new problems, if the repeated macro was not
+# idempotent). Meanwhile, macros defined by m4_defun_once instead of
+# m4_defun are idempotent, avoiding any warning or duplicate output.
+#
+#
+# 2. Keeping track of the expansion stack
+# =======================================
+#
+# When M4 expansion goes wrong it is often extremely hard to find the
+# path amongst macros that drove to the failure. What is needed is
+# the stack of macro `calls'. One could imagine that GNU M4 would
+# maintain a stack of macro expansions, unfortunately it doesn't, so
+# we do it by hand. This is of course extremely costly, but the help
+# this stack provides is worth it. Nevertheless to limit the
+# performance penalty this is implemented only for m4_defun'd macros,
+# not for define'd macros.
+#
+# Each time we enter an m4_defun'd macros, we add a definition in
+# _m4_expansion_stack, and when we exit the macro, we remove it (thanks
+# to pushdef/popdef). m4_stack_foreach is used to print the expansion
+# stack in the rare cases when it's needed.
+#
+# In addition, we want to detect circular m4_require dependencies.
+# Each time we expand a macro FOO we define _m4_expanding(FOO); and
+# m4_require(BAR) simply checks whether _m4_expanding(BAR) is defined.
+
+
+# m4_expansion_stack
+# ------------------
+# Expands to the entire contents of the expansion stack. The caller
+# must supply a trailing newline. This macro always prints a
+# location; check whether _m4_expansion_stack is defined to filter out
+# the case when no defun'd macro is in force.
+m4_define([m4_expansion_stack],
+[m4_stack_foreach_sep_lifo([_$0], [_$0_entry(], [)
+])m4_location[: the top level]])
+
+# _m4_expansion_stack_entry(MACRO)
+# --------------------------------
+# Format an entry for MACRO found on the expansion stack.
+m4_define([_m4_expansion_stack_entry],
+[_m4_defn([m4_location($1)])[: $1 is expanded from...]])
+
+# m4_expansion_stack_push(MACRO)
+# ------------------------------
+# Form an entry of the expansion stack on entry to MACRO and push it.
+m4_define([m4_expansion_stack_push],
+[m4_pushdef([_m4_expansion_stack], [$1])])
+
+
+# _m4_divert(GROW)
+# ----------------
+# This diversion is used by the m4_defun/m4_require machinery. It is
+# important to keep room before GROW because for each nested
+# AC_REQUIRE we use an additional diversion (i.e., two m4_require's
+# will use GROW - 2. More than 3 levels has never seemed to be
+# needed.)
+#
+# ...
+# - GROW - 2
+# m4_require'd code, 2 level deep
+# - GROW - 1
+# m4_require'd code, 1 level deep
+# - GROW
+# m4_defun'd macros are elaborated here.
+
+m4_define([_m4_divert(GROW)], 10000)
+
+
+# _m4_defun_pro(MACRO-NAME)
+# -------------------------
+# The prologue for Autoconf macros.
+#
+# This is called frequently, so minimize the number of macro invocations
+# by avoiding dnl and m4_defn overhead.
+m4_define([_m4_defun_pro],
+[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_pro_outer([$1])])]dnl
+[m4_expansion_stack_push([$1])m4_pushdef([_m4_expanding($1)])])
+
+m4_define([_m4_defun_pro_outer],
+[m4_set_delete([_m4_provide])]dnl
+[m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl
+[m4_pushdef([_m4_divert_dump], m4_divnum)m4_divert_push([GROW])])
+
+# _m4_defun_epi(MACRO-NAME)
+# -------------------------
+# The Epilogue for Autoconf macros. MACRO-NAME only helps tracing
+# the PRO/EPI pairs.
+#
+# This is called frequently, so minimize the number of macro invocations
+# by avoiding dnl and m4_popdef overhead.
+m4_define([_m4_defun_epi],
+[_m4_popdef([_m4_expanding($1)], [_m4_expansion_stack])]dnl
+[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_epi_outer([$1])])]dnl
+[m4_provide([$1])])
+
+m4_define([_m4_defun_epi_outer],
+[_m4_popdef([_m4_divert_dump], [_m4_diverting([$1])], [_m4_diverting])]dnl
+[m4_divert_pop([GROW])m4_undivert([GROW])])
+
+
+# _m4_divert_dump
+# ---------------
+# If blank, we are outside of any defun'd macro. Otherwise, expands
+# to the diversion number (not name) where require'd macros should be
+# moved once completed.
+m4_define([_m4_divert_dump])
+
+
+# m4_divert_require(DIVERSION, NAME-TO-CHECK, [BODY-TO-EXPAND])
+# -------------------------------------------------------------
+# Same as m4_require, but BODY-TO-EXPAND goes into the named DIVERSION;
+# requirements still go in the current diversion though.
+#
+m4_define([m4_divert_require],
+[m4_ifdef([_m4_expanding($2)],
+ [m4_fatal([$0: circular dependency of $2])])]dnl
+[m4_if(_m4_divert_dump, [],
+ [m4_fatal([$0($2): cannot be used outside of an m4_defun'd macro])])]dnl
+[m4_provide_if([$2], [],
+ [_m4_require_call([$2], [$3], _m4_divert([$1], [-]))])])
+
+
+# m4_defun(NAME, EXPANSION, [MACRO = m4_define])
+# ----------------------------------------------
+# Define a macro NAME which automatically provides itself. Add
+# machinery so the macro automatically switches expansion to the
+# diversion stack if it is not already using it, prior to EXPANSION.
+# In this case, once finished, it will bring back all the code
+# accumulated in the diversion stack. This, combined with m4_require,
+# achieves the topological ordering of macros. We don't use this
+# macro to define some frequently called macros that are not involved
+# in ordering constraints, to save m4 processing.
+#
+# MACRO is an undocumented argument; when set to m4_pushdef, and NAME
+# is already defined, the new definition is added to the pushdef
+# stack, rather than overwriting the current definition. It can thus
+# be used to write self-modifying macros, which pop themselves to a
+# previously m4_define'd definition so that subsequent use of the
+# macro is faster.
+m4_define([m4_defun],
+[m4_define([m4_location($1)], m4_location)]dnl
+[m4_default([$3], [m4_define])([$1],
+ [_m4_defun_pro(]m4_dquote($[0])[)$2[]_m4_defun_epi(]m4_dquote($[0])[)])])
+
+
+# m4_defun_init(NAME, INIT, COMMON)
+# ---------------------------------
+# Like m4_defun, but split EXPANSION into two portions: INIT which is
+# done only the first time NAME is invoked, and COMMON which is
+# expanded every time.
+#
+# For now, the COMMON definition is always m4_define'd, giving an even
+# lighter-weight definition. m4_defun allows self-providing, but once
+# a macro is provided, m4_require no longer cares if it is m4_define'd
+# or m4_defun'd. m4_defun also provides location tracking to identify
+# dependency bugs, but once the INIT has been expanded, we know there
+# are no dependency bugs. However, if a future use needs COMMON to be
+# m4_defun'd, we can add a parameter, similar to the third parameter
+# to m4_defun.
+m4_define([m4_defun_init],
+[m4_define([$1], [$3[]])m4_defun([$1],
+ [$2[]_m4_popdef(]m4_dquote($[0])[)m4_indir(]m4_dquote($[0])dnl
+[m4_if(]m4_dquote($[#])[, [0], [], ]m4_dquote([,$]@)[))], [m4_pushdef])])
+
+
+# m4_defun_once(NAME, EXPANSION)
+# ------------------------------
+# Like m4_defun, but guarantee that EXPANSION only happens once
+# (thereafter, using NAME is a no-op).
+#
+# If _m4_divert_dump is empty, we are called at the top level;
+# otherwise, we must ensure that we are required in front of the
+# current defun'd macro. Use a helper macro so that EXPANSION need
+# only occur once in the definition of NAME, since it might be large.
+m4_define([m4_defun_once],
+[m4_define([m4_location($1)], m4_location)]dnl
+[m4_define([$1], [_m4_defun_once([$1], [$2], m4_if(_m4_divert_dump, [],
+ [[_m4_defun_pro([$1])m4_unquote(], [)_m4_defun_epi([$1])]],
+m4_ifdef([_m4_diverting([$1])], [-]), [-], [[m4_unquote(], [)]],
+ [[_m4_require_call([$1],], [, _m4_divert_dump)]]))])])
+
+m4_define([_m4_defun_once],
+[m4_pushdef([$1])$3[$2[]m4_provide([$1])]$4])
+
+
+# m4_pattern_forbid(ERE, [WHY])
+# -----------------------------
+# Declare that no token matching the forbidden extended regular
+# expression ERE should be seen in the output unless...
+m4_define([m4_pattern_forbid], [])
+
+
+# m4_pattern_allow(ERE)
+# ---------------------
+# ... that token also matches the allowed extended regular expression ERE.
+# Both used via traces.
+m4_define([m4_pattern_allow], [])
+
+
+## --------------------------------- ##
+## 11. Dependencies between macros. ##
+## --------------------------------- ##
+
+
+# m4_before(THIS-MACRO-NAME, CALLED-MACRO-NAME)
+# ---------------------------------------------
+# Issue a warning if CALLED-MACRO-NAME was called before THIS-MACRO-NAME.
+m4_define([m4_before],
+[m4_provide_if([$2],
+ [m4_warn([syntax], [$2 was called before $1])])])
+
+
+# m4_require(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])
+# -----------------------------------------------------------
+# If NAME-TO-CHECK has never been expanded (actually, if it is not
+# m4_provide'd), expand BODY-TO-EXPAND *before* the current macro
+# expansion; follow the expansion with a newline. Once expanded, emit
+# it in _m4_divert_dump. Keep track of the m4_require chain in
+# _m4_expansion_stack.
+#
+# The normal cases are:
+#
+# - NAME-TO-CHECK == BODY-TO-EXPAND
+# Which you can use for regular macros with or without arguments, e.g.,
+# m4_require([AC_PROG_CC], [AC_PROG_CC])
+# m4_require([AC_CHECK_HEADERS(threads.h)], [AC_CHECK_HEADERS(threads.h)])
+# which is just the same as
+# m4_require([AC_PROG_CC])
+# m4_require([AC_CHECK_HEADERS(threads.h)])
+#
+# - BODY-TO-EXPAND == m4_indir([NAME-TO-CHECK])
+# In the case of macros with irregular names. For instance:
+# m4_require([AC_LANG_COMPILER(C)], [indir([AC_LANG_COMPILER(C)])])
+# which means `if the macro named `AC_LANG_COMPILER(C)' (the parens are
+# part of the name, it is not an argument) has not been run, then
+# call it.'
+# Had you used
+# m4_require([AC_LANG_COMPILER(C)], [AC_LANG_COMPILER(C)])
+# then m4_require would have tried to expand `AC_LANG_COMPILER(C)', i.e.,
+# call the macro `AC_LANG_COMPILER' with `C' as argument.
+#
+# You could argue that `AC_LANG_COMPILER', when it receives an argument
+# such as `C' should dispatch the call to `AC_LANG_COMPILER(C)'. But this
+# `extension' prevents `AC_LANG_COMPILER' from having actual arguments that
+# it passes to `AC_LANG_COMPILER(C)'.
+#
+# This is called frequently, so minimize the number of macro invocations
+# by avoiding dnl and other overhead on the common path.
+m4_define([m4_require],
+[m4_ifdef([_m4_expanding($1)],
+ [m4_fatal([$0: circular dependency of $1])])]dnl
+[m4_if(_m4_divert_dump, [],
+ [m4_fatal([$0($1): cannot be used outside of an ]dnl
+m4_if([$0], [m4_require], [[m4_defun]], [[AC_DEFUN]])['d macro])])]dnl
+[m4_provide_if([$1], [m4_set_contains([_m4_provide], [$1],
+ [_m4_require_check([$1], _m4_defn([m4_provide($1)]), [$0])], [m4_ignore])],
+ [_m4_require_call])([$1], [$2], _m4_divert_dump)])
+
+
+# _m4_require_call(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK],
+# DIVERSION-NUMBER)
+# -----------------------------------------------------------------
+# If m4_require decides to expand the body, it calls this macro. The
+# expansion is placed in DIVERSION-NUMBER.
+#
+# This is called frequently, so minimize the number of macro invocations
+# by avoiding dnl and other overhead on the common path.
+# The use of a witness macro protecting the warning allows aclocal
+# to silence any warnings when probing for what macros are required
+# and must therefore be located, when using the Autoconf-without-aclocal-m4
+# autom4te language. For more background, see:
+# https://lists.gnu.org/archive/html/automake-patches/2012-11/msg00035.html
+m4_define([_m4_require_call],
+[m4_pushdef([_m4_divert_grow], m4_decr(_m4_divert_grow))]dnl
+[m4_pushdef([_m4_diverting([$1])])m4_pushdef([_m4_diverting], [$1])]dnl
+[m4_divert_push(_m4_divert_grow, [-])]dnl
+[m4_if([$2], [], [$1], [$2])
+m4_provide_if([$1], [m4_set_remove([_m4_provide], [$1])],
+ [m4_ifndef([m4_require_silent_probe],
+ [m4_warn([syntax], [$1 is m4_require'd but not m4_defun'd])])])]dnl
+[_m4_divert_raw($3)_m4_undivert(_m4_divert_grow)]dnl
+[m4_divert_pop(_m4_divert_grow)_m4_popdef([_m4_divert_grow],
+[_m4_diverting([$1])], [_m4_diverting])])
+
+
+# _m4_require_check(NAME-TO-CHECK, OWNER, CALLER)
+# -----------------------------------------------
+# NAME-TO-CHECK has been identified as previously expanded in the
+# diversion owned by OWNER. If this is a problem, warn on behalf of
+# CALLER and return _m4_require_call; otherwise return m4_ignore.
+m4_define([_m4_require_check],
+[m4_if(_m4_defn([_m4_diverting]), [$2], [m4_ignore],
+ m4_ifdef([_m4_diverting([$2])], [-]), [-], [m4_warn([syntax],
+ [$3: `$1' was expanded before it was required
+http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required])_m4_require_call],
+ [m4_ignore])])
+
+
+# _m4_divert_grow
+# ---------------
+# The counter for _m4_require_call.
+m4_define([_m4_divert_grow], _m4_divert([GROW]))
+
+
+# m4_expand_once(TEXT, [WITNESS = TEXT])
+# --------------------------------------
+# If TEXT has never been expanded, expand it *here*. Use WITNESS as
+# as a memory that TEXT has already been expanded.
+m4_define([m4_expand_once],
+[m4_provide_if(m4_default_quoted([$2], [$1]),
+ [],
+ [m4_provide(m4_default_quoted([$2], [$1]))[]$1])])
+
+
+# m4_provide(MACRO-NAME)
+# ----------------------
+m4_define([m4_provide],
+[m4_ifdef([m4_provide($1)], [],
+[m4_set_add([_m4_provide], [$1], [m4_define([m4_provide($1)],
+ m4_ifdef([_m4_diverting], [_m4_defn([_m4_diverting])]))])])])
+
+
+# m4_provide_if(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
+# -------------------------------------------------------
+# If MACRO-NAME is provided do IF-PROVIDED, else IF-NOT-PROVIDED.
+# The purpose of this macro is to provide the user with a means to
+# check macros which are provided without letting her know how the
+# information is coded.
+m4_define([m4_provide_if],
+[m4_ifdef([m4_provide($1)],
+ [$2], [$3])])
+
+
+## --------------------- ##
+## 12. Text processing. ##
+## --------------------- ##
+
+
+# m4_cr_letters
+# m4_cr_LETTERS
+# m4_cr_Letters
+# -------------
+m4_define([m4_cr_letters], [abcdefghijklmnopqrstuvwxyz])
+m4_define([m4_cr_LETTERS], [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
+m4_define([m4_cr_Letters],
+m4_defn([m4_cr_letters])dnl
+m4_defn([m4_cr_LETTERS])dnl
+)
+
+
+# m4_cr_digits
+# ------------
+m4_define([m4_cr_digits], [0123456789])
+
+
+# m4_cr_alnum
+# -----------
+m4_define([m4_cr_alnum],
+m4_defn([m4_cr_Letters])dnl
+m4_defn([m4_cr_digits])dnl
+)
+
+
+# m4_cr_symbols1
+# m4_cr_symbols2
+# --------------
+m4_define([m4_cr_symbols1],
+m4_defn([m4_cr_Letters])dnl
+_)
+
+m4_define([m4_cr_symbols2],
+m4_defn([m4_cr_symbols1])dnl
+m4_defn([m4_cr_digits])dnl
+)
+
+# m4_cr_all
+# ---------
+# The character range representing everything, with `-' as the last
+# character, since it is special to m4_translit. Use with care, because
+# it contains characters special to M4 (fortunately, both ASCII and EBCDIC
+# have [] in order, so m4_defn([m4_cr_all]) remains a valid string). It
+# also contains characters special to terminals, so it should never be
+# displayed in an error message. Also, attempts to map [ and ] to other
+# characters via m4_translit must deal with the fact that m4_translit does
+# not add quotes to the output.
+#
+# In EBCDIC, $ is immediately followed by *, which leads to problems
+# if m4_cr_all is inlined into a macro definition; so swap them.
+#
+# It is mainly useful in generating inverted character range maps, for use
+# in places where m4_translit is faster than an equivalent m4_bpatsubst;
+# the regex `[^a-z]' is equivalent to:
+# m4_translit(m4_dquote(m4_defn([m4_cr_all])), [a-z])
+m4_define([m4_cr_all],
+m4_translit(m4_dquote(m4_format(m4_dquote(m4_for(
+ ,1,255,,[[%c]]))m4_for([i],1,255,,[,i]))), [$*-], [*$])-)
+
+
+# _m4_define_cr_not(CATEGORY)
+# ---------------------------
+# Define m4_cr_not_CATEGORY as the inverse of m4_cr_CATEGORY.
+m4_define([_m4_define_cr_not],
+[m4_define([m4_cr_not_$1],
+ m4_translit(m4_dquote(m4_defn([m4_cr_all])),
+ m4_defn([m4_cr_$1])))])
+
+
+# m4_cr_not_letters
+# m4_cr_not_LETTERS
+# m4_cr_not_Letters
+# m4_cr_not_digits
+# m4_cr_not_alnum
+# m4_cr_not_symbols1
+# m4_cr_not_symbols2
+# ------------------
+# Inverse character sets
+_m4_define_cr_not([letters])
+_m4_define_cr_not([LETTERS])
+_m4_define_cr_not([Letters])
+_m4_define_cr_not([digits])
+_m4_define_cr_not([alnum])
+_m4_define_cr_not([symbols1])
+_m4_define_cr_not([symbols2])
+
+
+# m4_newline([STRING])
+# --------------------
+# Expands to a newline, possibly followed by STRING. Exists mostly for
+# formatting reasons.
+m4_define([m4_newline], [
+$1])
+
+
+# m4_re_escape(STRING)
+# --------------------
+# Escape RE active characters in STRING.
+m4_define([m4_re_escape],
+[m4_bpatsubst([$1],
+ [[][*+.?\^$]], [\\\&])])
+
+
+# m4_re_string
+# ------------
+# Regexp for `[a-zA-Z_0-9]*'
+# m4_dquote provides literal [] for the character class.
+m4_define([m4_re_string],
+m4_dquote(m4_defn([m4_cr_symbols2]))dnl
+[*]dnl
+)
+
+
+# m4_re_word
+# ----------
+# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*'
+m4_define([m4_re_word],
+m4_dquote(m4_defn([m4_cr_symbols1]))dnl
+m4_defn([m4_re_string])dnl
+)
+
+
+# m4_tolower(STRING)
+# m4_toupper(STRING)
+# ------------------
+# These macros convert STRING to lowercase or uppercase.
+#
+# Rather than expand the m4_defn each time, we inline them up front.
+m4_define([m4_tolower],
+[m4_translit([[$1]], ]m4_dquote(m4_defn([m4_cr_LETTERS]))[,
+ ]m4_dquote(m4_defn([m4_cr_letters]))[)])
+m4_define([m4_toupper],
+[m4_translit([[$1]], ]m4_dquote(m4_defn([m4_cr_letters]))[,
+ ]m4_dquote(m4_defn([m4_cr_LETTERS]))[)])
+
+
+# m4_split(STRING, [REGEXP])
+# --------------------------
+# Split STRING into an m4 list of quoted elements. The elements are
+# quoted with [ and ]. Beginning spaces and end spaces *are kept*.
+# Use m4_strip to remove them.
+#
+# REGEXP specifies where to split. Default is [\t ]+.
+#
+# If STRING is empty, the result is an empty list.
+#
+# Pay attention to the m4_changequotes. When m4 reads the definition of
+# m4_split, it still has quotes set to [ and ]. Luckily, these are matched
+# in the macro body, so the definition is stored correctly. Use the same
+# alternate quotes as m4_noquote; it must be unlikely to appear in $1.
+#
+# Also, notice that $1 is quoted twice, since we want the result to
+# be quoted. Then you should understand that the argument of
+# patsubst is -=<{(STRING)}>=- (i.e., with additional -=<{( and )}>=-).
+#
+# This macro is safe on active symbols, i.e.:
+# m4_define(active, ACTIVE)
+# m4_split([active active ])end
+# => [active], [active], []end
+#
+# Optimize on regex of ` ' (space), since m4_foreach_w already guarantees
+# that the list contains single space separators, and a common case is
+# splitting a single-element list. This macro is called frequently,
+# so avoid unnecessary dnl inside the definition.
+m4_define([m4_split],
+[m4_if([$1], [], [],
+ [$2], [ ], [m4_if(m4_index([$1], [ ]), [-1], [[[$1]]],
+ [_$0([$1], [$2], [, ])])],
+ [$2], [], [_$0([$1], [[ ]+], [, ])],
+ [_$0([$1], [$2], [, ])])])
+
+m4_define([_m4_split],
+[m4_changequote([-=<{(],[)}>=-])]dnl
+[[m4_bpatsubst(-=<{(-=<{($1)}>=-)}>=-, -=<{($2)}>=-,
+ -=<{(]$3[)}>=-)]m4_changequote([, ])])
+
+
+# m4_chomp(STRING)
+# m4_chomp_all(STRING)
+# --------------------
+# Return STRING quoted, but without a trailing newline. m4_chomp
+# removes at most one newline, while m4_chomp_all removes all
+# consecutive trailing newlines. Embedded newlines are not touched,
+# and a trailing backslash-newline leaves just a trailing backslash.
+#
+# m4_bregexp is slower than m4_index, and we don't always want to
+# remove all newlines; hence the two variants. We massage characters
+# to give a nicer pattern to match, particularly since m4_bregexp is
+# line-oriented. Both versions must guarantee a match, to avoid bugs
+# with precision -1 in m4_format in older m4.
+m4_define([m4_chomp],
+[m4_format([[%.*s]], m4_index(m4_translit([[$1]], [
+/.], [/ ])[./.], [/.]), [$1])])
+
+m4_define([m4_chomp_all],
+[m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [
+/], [/ ]), [/*$]), [$1])])
+
+
+# m4_flatten(STRING)
+# ------------------
+# If STRING contains end of lines, replace them with spaces. If there
+# are backslashed end of lines, remove them. This macro is safe with
+# active symbols.
+# m4_define(active, ACTIVE)
+# m4_flatten([active
+# act\
+# ive])end
+# => active activeend
+#
+# In m4, m4_bpatsubst is expensive, so first check for a newline.
+m4_define([m4_flatten],
+[m4_if(m4_index([$1], [
+]), [-1], [[$1]],
+ [m4_translit(m4_bpatsubst([[[$1]]], [\\
+]), [
+], [ ])])])
+
+
+# m4_strip(STRING)
+# ----------------
+# Expands into STRING with tabs and spaces singled out into a single
+# space, and removing leading and trailing spaces.
+#
+# This macro is robust to active symbols.
+# m4_define(active, ACTIVE)
+# m4_strip([ active <tab> <tab>active ])end
+# => active activeend
+#
+# First, notice that we guarantee trailing space. Why? Because regular
+# expressions are greedy, and `.* ?' would always group the space into the
+# .* portion. The algorithm is simpler by avoiding `?' at the end. The
+# algorithm correctly strips everything if STRING is just ` '.
+#
+# Then notice the second pattern: it is in charge of removing the
+# leading/trailing spaces. Why not just `[^ ]'? Because they are
+# applied to over-quoted strings, i.e. more or less [STRING], due
+# to the limitations of m4_bpatsubsts. So the leading space in STRING
+# is the *second* character; equally for the trailing space.
+m4_define([m4_strip],
+[m4_bpatsubsts([$1 ],
+ [[ ]+], [ ],
+ [^. ?\(.*\) .$], [[[\1]]])])
+
+
+# m4_normalize(STRING)
+# --------------------
+# Apply m4_flatten and m4_strip to STRING.
+#
+# The argument is quoted, so that the macro is robust to active symbols:
+#
+# m4_define(active, ACTIVE)
+# m4_normalize([ act\
+# ive
+# active ])end
+# => active activeend
+
+m4_define([m4_normalize],
+[m4_strip(m4_flatten([$1]))])
+
+
+
+# m4_join(SEP, ARG1, ARG2...)
+# ---------------------------
+# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG
+# is the empty string. No expansion is performed on SEP or ARGs.
+#
+# Since the number of arguments to join can be arbitrarily long, we
+# want to avoid having more than one $@ in the macro definition;
+# otherwise, the expansion would require twice the memory of the already
+# long list. Hence, m4_join merely looks for the first non-empty element,
+# and outputs just that element; while _m4_join looks for all non-empty
+# elements, and outputs them following a separator. The final trick to
+# note is that we decide between recursing with $0 or _$0 based on the
+# nested m4_if ending with `_'.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_join],
+[m4_if([$#], [1], [],
+ [$#], [2], [[$2]],
+ [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift2($@))])])
+m4_define([_m4_join],
+[m4_if([$#$2], [2], [],
+ [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])])
+
+# m4_joinall(SEP, ARG1, ARG2...)
+# ------------------------------
+# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP.
+# No expansion is performed on SEP or ARGs.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_joinall], [[$2]_$0([$1], m4_shift($@))])
+m4_define([_m4_joinall],
+[m4_if([$#], [2], [], [[$1$3]$0([$1], m4_shift2($@))])])
+
+# m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX...)
+# --------------------------------------------------------
+# Produce the pairwise combination of every element in the quoted,
+# comma-separated PREFIX-LIST with every element from the SUFFIX arguments.
+# Each pair is joined with INFIX, and pairs are separated by SEPARATOR.
+# No expansion occurs on SEPARATOR, INFIX, or elements of either list.
+#
+# For example:
+# m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
+# => a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
+#
+# This definition is a bit hairy; the thing to realize is that we want
+# to construct m4_map_args_sep([[prefix$3]], [], [[$1]], m4_shift3($@))
+# as the inner loop, using each prefix generated by the outer loop,
+# and without recalculating m4_shift3 every outer iteration.
+m4_define([m4_combine],
+[m4_if([$2], [], [], m4_eval([$# > 3]), [1],
+[m4_map_args_sep([m4_map_args_sep(m4_dquote(], [)[[$3]], [], [[$1]],]]]dnl
+[m4_dquote(m4_dquote(m4_shift3($@)))[[)], [[$1]], $2)])])
+
+
+# m4_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR`'STRING'
+# at the end. It is valid to use this macro with MACRO-NAME undefined,
+# in which case no SEPARATOR is added. Be aware that the criterion is
+# `not being defined', and not `not being empty'.
+#
+# Note that neither STRING nor SEPARATOR are expanded here; rather, when
+# you expand MACRO-NAME, they will be expanded at that point in time.
+#
+# This macro is robust to active symbols. It can be used to grow
+# strings.
+#
+# | m4_define(active, ACTIVE)dnl
+# | m4_append([sentence], [This is an])dnl
+# | m4_append([sentence], [ active ])dnl
+# | m4_append([sentence], [symbol.])dnl
+# | sentence
+# | m4_undefine([active])dnl
+# | sentence
+# => This is an ACTIVE symbol.
+# => This is an active symbol.
+#
+# It can be used to define hooks.
+#
+# | m4_define(active, ACTIVE)dnl
+# | m4_append([hooks], [m4_define([act1], [act2])])dnl
+# | m4_append([hooks], [m4_define([act2], [active])])dnl
+# | m4_undefine([active])dnl
+# | act1
+# | hooks
+# | act1
+# => act1
+# =>
+# => active
+#
+# It can also be used to create lists, although this particular usage was
+# broken prior to autoconf 2.62.
+# | m4_append([list], [one], [, ])dnl
+# | m4_append([list], [two], [, ])dnl
+# | m4_append([list], [three], [, ])dnl
+# | list
+# | m4_dquote(list)
+# => one, two, three
+# => [one],[two],[three]
+#
+# Note that m4_append can benefit from amortized O(n) m4 behavior, if
+# the underlying m4 implementation is smart enough to avoid copying existing
+# contents when enlarging a macro's definition into any pre-allocated storage
+# (m4 1.4.x unfortunately does not implement this optimization). We do
+# not implement m4_prepend, since it is inherently O(n^2) (pre-allocated
+# storage only occurs at the end of a macro, so the existing contents must
+# always be moved).
+#
+# Use _m4_defn for speed.
+m4_define([m4_append],
+[m4_define([$1], m4_ifdef([$1], [_m4_defn([$1])[$3]])[$2])])
+
+
+# m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR], [IF-UNIQ], [IF-DUP])
+# --------------------------------------------------------------------
+# Like `m4_append', but append only if not yet present. Additionally,
+# expand IF-UNIQ if STRING was appended, or IF-DUP if STRING was already
+# present. Also, warn if SEPARATOR is not empty and occurs within STRING,
+# as the algorithm no longer guarantees uniqueness.
+#
+# Note that while m4_append can be O(n) (depending on the quality of the
+# underlying M4 implementation), m4_append_uniq is inherently O(n^2)
+# because each append operation searches the entire string.
+m4_define([m4_append_uniq],
+[m4_ifval([$3], [m4_if(m4_index([$2], [$3]), [-1], [],
+ [m4_warn([syntax],
+ [$0: `$2' contains `$3'])])])_$0($@)])
+m4_define([_m4_append_uniq],
+[m4_ifdef([$1],
+ [m4_if(m4_index([$3]_m4_defn([$1])[$3], [$3$2$3]), [-1],
+ [m4_append([$1], [$2], [$3])$4], [$5])],
+ [m4_define([$1], [$2])$4])])
+
+# m4_append_uniq_w(MACRO-NAME, STRINGS)
+# -------------------------------------
+# For each of the words in the whitespace separated list STRINGS, append
+# only the unique strings to the definition of MACRO-NAME.
+#
+# Use _m4_defn for speed.
+m4_define([m4_append_uniq_w],
+[m4_map_args_w([$2], [_m4_append_uniq([$1],], [, [ ])])])
+
+
+# m4_escape(STRING)
+# -----------------
+# Output quoted STRING, but with embedded #, $, [ and ] turned into
+# quadrigraphs.
+#
+# It is faster to check if STRING is already good using m4_translit
+# than to blindly perform four m4_bpatsubst.
+#
+# Because the translit is stripping quotes, it must also neutralize
+# anything that might be in a macro name, as well as comments, commas,
+# and parentheses. All the problem characters are unified so that a
+# single m4_index can scan the result.
+#
+# Rather than expand m4_defn every time m4_escape is expanded, we
+# inline its expansion up front.
+m4_define([m4_escape],
+[m4_if(m4_index(m4_translit([$1],
+ [[]#,()]]m4_dquote(m4_defn([m4_cr_symbols2]))[, [$$$]), [$]),
+ [-1], [m4_echo], [_$0])([$1])])
+
+m4_define([_m4_escape],
+[m4_changequote([-=<{(],[)}>=-])]dnl
+[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(
+ -=<{(-=<{(-=<{(-=<{(-=<{($1)}>=-)}>=-)}>=-)}>=-)}>=-,
+ -=<{(#)}>=-, -=<{(@%:@)}>=-),
+ -=<{(\[)}>=-, -=<{(@<:@)}>=-),
+ -=<{(\])}>=-, -=<{(@:>@)}>=-),
+ -=<{(\$)}>=-, -=<{(@S|@)}>=-)m4_changequote([,])])
+
+
+# m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
+# -------------------------------------------------------
+# Expands into STRING wrapped to hold in WIDTH columns (default = 79).
+# If PREFIX is given, each line is prefixed with it. If FIRST-PREFIX is
+# specified, then the first line is prefixed with it. As a special case,
+# if the length of FIRST-PREFIX is greater than that of PREFIX, then
+# FIRST-PREFIX will be left alone on the first line.
+#
+# No expansion occurs on the contents STRING, PREFIX, or FIRST-PREFIX,
+# although quadrigraphs are correctly recognized. More precisely,
+# you may redefine m4_qlen to recognize whatever escape sequences that
+# you will post-process.
+#
+# Typical outputs are:
+#
+# m4_text_wrap([Short string */], [ ], [/* ], 20)
+# => /* Short string */
+#
+# m4_text_wrap([Much longer string */], [ ], [/* ], 20)
+# => /* Much longer
+# => string */
+#
+# m4_text_wrap([Short doc.], [ ], [ --short ], 30)
+# => --short Short doc.
+#
+# m4_text_wrap([Short doc.], [ ], [ --too-wide ], 30)
+# => --too-wide
+# => Short doc.
+#
+# m4_text_wrap([Super long documentation.], [ ], [ --too-wide ], 30)
+# => --too-wide
+# => Super long
+# => documentation.
+#
+# FIXME: there is no checking of a longer PREFIX than WIDTH, but do
+# we really want to bother with people trying each single corner
+# of a software?
+#
+# This macro does not leave a trailing space behind the last word of a line,
+# which complicates it a bit. The algorithm is otherwise stupid and simple:
+# all the words are preceded by m4_Separator which is defined to empty for
+# the first word, and then ` ' (single space) for all the others.
+#
+# The algorithm uses a helper that uses $2 through $4 directly, rather than
+# using local variables, to avoid m4_defn overhead, or expansion swallowing
+# any $. It also bypasses m4_popdef overhead with _m4_popdef since no user
+# macro expansion occurs in the meantime. Also, the definition is written
+# with m4_do, to avoid time wasted on dnl during expansion (since this is
+# already a time-consuming macro).
+m4_define([m4_text_wrap],
+[_$0(m4_escape([$1]), [$2], m4_default_quoted([$3], [$2]),
+ m4_default_quoted([$4], [79]))])
+
+m4_define([_m4_text_wrap],
+m4_do(dnl set up local variables, to avoid repeated calculations
+[[m4_pushdef([m4_Indent], m4_qlen([$2]))]],
+[[m4_pushdef([m4_Cursor], m4_qlen([$3]))]],
+[[m4_pushdef([m4_Separator], [m4_define([m4_Separator], [ ])])]],
+dnl expand the first prefix, then check its length vs. regular prefix
+dnl same length: nothing special
+dnl prefix1 longer: output on line by itself, and reset cursor
+dnl prefix1 shorter: pad to length of prefix, and reset cursor
+[[[$3]m4_cond([m4_Cursor], m4_Indent, [],
+ [m4_eval(m4_Cursor > m4_Indent)], [1], [
+[$2]m4_define([m4_Cursor], m4_Indent)],
+ [m4_format([%*s], m4_max([0],
+ m4_eval(m4_Indent - m4_Cursor)), [])m4_define([m4_Cursor], m4_Indent)])]],
+dnl now, for each word, compute the cursor after the word is output, then
+dnl check if the cursor would exceed the wrap column
+dnl if so, reset cursor, and insert newline and prefix
+dnl if not, insert the separator (usually a space)
+dnl either way, insert the word
+[[m4_map_args_w([$1], [$0_word(], [, [$2], [$4])])]],
+dnl finally, clean up the local variables
+[[_m4_popdef([m4_Separator], [m4_Cursor], [m4_Indent])]]))
+
+m4_define([_m4_text_wrap_word],
+[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_qlen([$1]) + 1))]dnl
+[m4_if(m4_eval(m4_Cursor > ([$3])),
+ [1], [m4_define([m4_Cursor], m4_eval(m4_Indent + m4_qlen([$1]) + 1))
+[$2]],
+ [m4_Separator[]])[$1]])
+
+# m4_text_box(MESSAGE, [FRAME-CHARACTER = `-'])
+# ---------------------------------------------
+# Turn MESSAGE into:
+# ## ------- ##
+# ## MESSAGE ##
+# ## ------- ##
+# using FRAME-CHARACTER in the border.
+#
+# Quadrigraphs are correctly recognized. More precisely, you may
+# redefine m4_qlen to recognize whatever escape sequences that you
+# will post-process.
+m4_define([m4_text_box],
+[m4_pushdef([m4_Border],
+ m4_translit(m4_format([[[%*s]]], m4_decr(m4_qlen(_m4_expand([$1
+]))), []), [ ], m4_default_quoted([$2], [-])))]dnl
+[[##] _m4_defn([m4_Border]) [##]
+[##] $1 [##]
+[##] _m4_defn([m4_Border]) [##]_m4_popdef([m4_Border])])
+
+
+# m4_qlen(STRING)
+# ---------------
+# Expands to the length of STRING after autom4te converts all quadrigraphs.
+#
+# If you use some other means of post-processing m4 output rather than
+# autom4te, then you may redefine this macro to recognize whatever
+# escape sequences your post-processor will handle. For that matter,
+# m4_define([m4_qlen], m4_defn([m4_len])) is sufficient if you don't
+# do any post-processing.
+#
+# Avoid bpatsubsts for the common case of no quadrigraphs. Cache
+# results, as configure scripts tend to ask about lengths of common
+# strings like `/*' and `*/' rather frequently. Minimize the number
+# of times that $1 occurs in m4_qlen, so there is less text to parse
+# on a cache hit.
+m4_define([m4_qlen],
+[m4_ifdef([$0-$1], [_m4_defn([$0-]], [_$0(])[$1])])
+m4_define([_m4_qlen],
+[m4_define([m4_qlen-$1],
+m4_if(m4_index([$1], [@]), [-1], [m4_len([$1])],
+ [m4_len(m4_bpatsubst([[$1]],
+ [@\(\(<:\|:>\|S|\|%:\|\{:\|:\}\)\(@\)\|&t@\)],
+ [\3]))]))_m4_defn([m4_qlen-$1])])
+
+# m4_copyright_condense(TEXT)
+# ---------------------------
+# Condense the copyright notice in TEXT to only display the final
+# year, wrapping the results to fit in 80 columns.
+m4_define([m4_copyright_condense],
+[m4_text_wrap(m4_bpatsubst(m4_flatten([[$1]]),
+[(C)[- ,0-9]*\([1-9][0-9][0-9][0-9]\)], [(C) \1]))])
+
+## ----------------------- ##
+## 13. Number processing. ##
+## ----------------------- ##
+
+# m4_cmp(A, B)
+# ------------
+# Compare two integer expressions.
+# A < B -> -1
+# A = B -> 0
+# A > B -> 1
+m4_define([m4_cmp],
+[m4_eval((([$1]) > ([$2])) - (([$1]) < ([$2])))])
+
+
+# m4_list_cmp(A, B)
+# -----------------
+#
+# Compare the two lists of integer expressions A and B. For instance:
+# m4_list_cmp([1, 0], [1]) -> 0
+# m4_list_cmp([1, 0], [1, 0]) -> 0
+# m4_list_cmp([1, 2], [1, 0]) -> 1
+# m4_list_cmp([1, 2, 3], [1, 2]) -> 1
+# m4_list_cmp([1, 2, -3], [1, 2]) -> -1
+# m4_list_cmp([1, 0], [1, 2]) -> -1
+# m4_list_cmp([1], [1, 2]) -> -1
+# m4_define([xa], [oops])dnl
+# m4_list_cmp([[0xa]], [5+5]) -> 0
+#
+# Rather than face the overhead of m4_case, we use a helper function whose
+# expansion includes the name of the macro to invoke on the tail, either
+# m4_ignore or m4_unquote. This is particularly useful when comparing
+# long lists, since less text is being expanded for deciding when to end
+# recursion. The recursion is between a pair of macros that alternate
+# which list is trimmed by one element; this is more efficient than
+# calling m4_cdr on both lists from a single macro. Guarantee exactly
+# one expansion of both lists' side effects.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_list_cmp],
+[_$0_raw(m4_dquote($1), m4_dquote($2))])
+
+m4_define([_m4_list_cmp_raw],
+[m4_if([$1], [$2], [0], [_m4_list_cmp_1([$1], $2)])])
+
+m4_define([_m4_list_cmp],
+[m4_if([$1], [], [0m4_ignore], [$2], [0], [m4_unquote], [$2m4_ignore])])
+
+m4_define([_m4_list_cmp_1],
+[_m4_list_cmp_2([$2], [m4_shift2($@)], $1)])
+
+m4_define([_m4_list_cmp_2],
+[_m4_list_cmp([$1$3], m4_cmp([$3+0], [$1+0]))(
+ [_m4_list_cmp_1(m4_dquote(m4_shift3($@)), $2)])])
+
+# m4_max(EXPR, ...)
+# m4_min(EXPR, ...)
+# -----------------
+# Return the decimal value of the maximum (or minimum) in a series of
+# integer expressions.
+#
+# M4 1.4.x doesn't provide ?:. Hence this huge m4_eval. Avoid m4_eval
+# if both arguments are identical, but be aware of m4_max(0xa, 10) (hence
+# the use of <=, not just <, in the second multiply).
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_max],
+[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
+ [$#], [1], [m4_eval([$1])],
+ [$#$1], [2$2], [m4_eval([$1])],
+ [$#], [2], [_$0($@)],
+ [_m4_minmax([_$0], $@)])])
+
+m4_define([_m4_max],
+[m4_eval((([$1]) > ([$2])) * ([$1]) + (([$1]) <= ([$2])) * ([$2]))])
+
+m4_define([m4_min],
+[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
+ [$#], [1], [m4_eval([$1])],
+ [$#$1], [2$2], [m4_eval([$1])],
+ [$#], [2], [_$0($@)],
+ [_m4_minmax([_$0], $@)])])
+
+m4_define([_m4_min],
+[m4_eval((([$1]) < ([$2])) * ([$1]) + (([$1]) >= ([$2])) * ([$2]))])
+
+# _m4_minmax(METHOD, ARG1, ARG2...)
+# ---------------------------------
+# Common recursion code for m4_max and m4_min. METHOD must be _m4_max
+# or _m4_min, and there must be at least two arguments to combine.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([_m4_minmax],
+[m4_if([$#], [3], [$1([$2], [$3])],
+ [$0([$1], $1([$2], [$3]), m4_shift3($@))])])
+
+
+# m4_sign(A)
+# ----------
+# The sign of the integer expression A.
+m4_define([m4_sign],
+[m4_eval((([$1]) > 0) - (([$1]) < 0))])
+
+
+
+## ------------------------ ##
+## 14. Version processing. ##
+## ------------------------ ##
+
+
+# m4_version_unletter(VERSION)
+# ----------------------------
+# Normalize beta version numbers with letters to numeric expressions, which
+# can then be handed to m4_eval for the purpose of comparison.
+#
+# Nl -> (N+1).-1.(l#)
+#
+# for example:
+# [2.14a] -> [0,2,14+1,-1,[0r36:a]] -> 2.15.-1.10
+# [2.14b] -> [0,2,15+1,-1,[0r36:b]] -> 2.15.-1.11
+# [2.61aa.b] -> [0,2.61,1,-1,[0r36:aa],+1,-1,[0r36:b]] -> 2.62.-1.370.1.-1.11
+# [08] -> [0,[0r10:0]8] -> 8
+#
+# This macro expects reasonable version numbers, but can handle double
+# letters and does not expand any macros. Original version strings can
+# use both `.' and `-' separators.
+#
+# Inline constant expansions, to avoid m4_defn overhead.
+# _m4_version_unletter is the real workhorse used by m4_version_compare,
+# but since [0r36:a] and commas are less readable than 10 and dots, we
+# provide a wrapper for human use.
+m4_define([m4_version_unletter],
+[m4_substr(m4_map_args([.m4_eval], m4_unquote(_$0([$1]))), [3])])
+m4_define([_m4_version_unletter],
+[m4_bpatsubst(m4_bpatsubst(m4_translit([[[[0,$1]]]], [.-], [,,]),]dnl
+m4_dquote(m4_dquote(m4_defn([m4_cr_Letters])))[[+],
+ [+1,-1,[0r36:\&]]), [,0], [,[0r10:0]])])
+
+
+# m4_version_compare(VERSION-1, VERSION-2)
+# ----------------------------------------
+# Compare the two version numbers and expand into
+# -1 if VERSION-1 < VERSION-2
+# 0 if =
+# 1 if >
+#
+# Since _m4_version_unletter does not output side effects, we can
+# safely bypass the overhead of m4_version_cmp.
+m4_define([m4_version_compare],
+[_m4_list_cmp_raw(_m4_version_unletter([$1]), _m4_version_unletter([$2]))])
+
+
+# m4_PACKAGE_NAME
+# m4_PACKAGE_TARNAME
+# m4_PACKAGE_VERSION
+# m4_PACKAGE_STRING
+# m4_PACKAGE_BUGREPORT
+# --------------------
+# If m4sugar/version.m4 is present, then define version strings. This
+# file is optional, provided by Autoconf but absent in Bison.
+m4_sinclude([m4sugar/version.m4])
+
+
+# m4_version_prereq(VERSION, [IF-OK], [IF-NOT = FAIL])
+# ----------------------------------------------------
+# Check this Autoconf version against VERSION.
+m4_define([m4_version_prereq],
+m4_ifdef([m4_PACKAGE_VERSION],
+[[m4_if(m4_version_compare(]m4_dquote(m4_defn([m4_PACKAGE_VERSION]))[, [$1]),
+ [-1],
+ [m4_default([$3],
+ [m4_fatal([Autoconf version $1 or higher is required],
+ [63])])],
+ [$2])]],
+[[m4_fatal([m4sugar/version.m4 not found])]]))
+
+
+## ------------------ ##
+## 15. Set handling. ##
+## ------------------ ##
+
+# Autoconf likes to create arbitrarily large sets; for example, as of
+# this writing, the configure.ac for coreutils tracks a set of more
+# than 400 AC_SUBST. How do we track all of these set members,
+# without introducing duplicates? We could use m4_append_uniq, with
+# the set NAME residing in the contents of the macro NAME.
+# Unfortunately, m4_append_uniq is quadratic for set creation, because
+# it costs O(n) to search the string for each of O(n) insertions; not
+# to mention that with m4 1.4.x, even using m4_append is slow, costing
+# O(n) rather than O(1) per insertion. Other set operations, not used
+# by Autoconf but still possible by manipulation of the definition
+# tracked in macro NAME, include O(n) deletion of one element and O(n)
+# computation of set size. Because the set is exposed to the user via
+# the definition of a single macro, we cannot cache any data about the
+# set without risking the cache being invalidated by the user
+# redefining NAME.
+#
+# Can we do better? Yes, because m4 gives us an O(1) search function
+# for free: ifdef. Additionally, even m4 1.4.x gives us an O(1)
+# insert operation for free: pushdef. But to use these, we must
+# represent the set via a group of macros; to keep the set consistent,
+# we must hide the set so that the user can only manipulate it through
+# accessor macros. The contents of the set are maintained through two
+# access points; _m4_set([name]) is a pushdef stack of values in the
+# set, useful for O(n) traversal of the set contents; while the
+# existence of _m4_set([name],value) with no particular value is
+# useful for O(1) querying of set membership. And since the user
+# cannot externally manipulate the set, we are free to add additional
+# caching macros for other performance improvements. Deletion can be
+# O(1) per element rather than O(n), by reworking the definition of
+# _m4_set([name],value) to be 0 or 1 based on current membership, and
+# adding _m4_set_cleanup(name) to defer the O(n) cleanup of
+# _m4_set([name]) until we have another reason to do an O(n)
+# traversal. The existence of _m4_set_cleanup(name) can then be used
+# elsewhere to determine if we must dereference _m4_set([name],value),
+# or assume that definition implies set membership. Finally, size can
+# be tracked in an O(1) fashion with _m4_set_size(name).
+#
+# The quoting in _m4_set([name],value) is chosen so that there is no
+# ambiguity with a set whose name contains a comma, and so that we can
+# supply the value via _m4_defn([_m4_set([name])]) without needing any
+# quote manipulation.
+
+# m4_set_add(SET, VALUE, [IF-UNIQ], [IF-DUP])
+# -------------------------------------------
+# Add VALUE as an element of SET. Expand IF-UNIQ on the first
+# addition, and IF-DUP if it is already in the set. Addition of one
+# element is O(1), such that overall set creation is O(n).
+#
+# We do not want to add a duplicate for a previously deleted but
+# unpruned element, but it is just as easy to check existence directly
+# as it is to query _m4_set_cleanup($1).
+m4_define([m4_set_add],
+[m4_ifdef([_m4_set([$1],$2)],
+ [m4_if(m4_indir([_m4_set([$1],$2)]), [0],
+ [m4_define([_m4_set([$1],$2)],
+ [1])_m4_set_size([$1], [m4_incr])$3], [$4])],
+ [m4_define([_m4_set([$1],$2)],
+ [1])m4_pushdef([_m4_set([$1])],
+ [$2])_m4_set_size([$1], [m4_incr])$3])])
+
+# m4_set_add_all(SET, VALUE...)
+# -----------------------------
+# Add each VALUE into SET. This is O(n) in the number of VALUEs, and
+# can be faster than calling m4_set_add for each VALUE.
+#
+# Implement two recursion helpers; the check variant is slower but
+# handles the case where an element has previously been removed but
+# not pruned. The recursion helpers ignore their second argument, so
+# that we can use the faster m4_shift2 and 2 arguments, rather than
+# _m4_shift2 and one argument, as the signal to end recursion.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_set_add_all],
+[m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1])
+ + m4_len(m4_ifdef([_m4_set_cleanup($1)], [_$0_check], [_$0])([$1], $@))))])
+
+m4_define([_m4_set_add_all],
+[m4_if([$#], [2], [],
+ [m4_ifdef([_m4_set([$1],$3)], [],
+ [m4_define([_m4_set([$1],$3)], [1])m4_pushdef([_m4_set([$1])],
+ [$3])-])$0([$1], m4_shift2($@))])])
+
+m4_define([_m4_set_add_all_check],
+[m4_if([$#], [2], [],
+ [m4_set_add([$1], [$3])$0([$1], m4_shift2($@))])])
+
+# m4_set_contains(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
+# ------------------------------------------------------
+# Expand IF-PRESENT if SET contains VALUE, otherwise expand IF-ABSENT.
+# This is always O(1).
+m4_define([m4_set_contains],
+[m4_ifdef([_m4_set_cleanup($1)],
+ [m4_if(m4_ifdef([_m4_set([$1],$2)],
+ [m4_indir([_m4_set([$1],$2)])], [0]), [1], [$3], [$4])],
+ [m4_ifdef([_m4_set([$1],$2)], [$3], [$4])])])
+
+# m4_set_contents(SET, [SEP])
+# ---------------------------
+# Expand to a single string containing all the elements in SET,
+# separated by SEP, without modifying SET. No provision is made for
+# disambiguating set elements that contain non-empty SEP as a
+# sub-string, or for recognizing a set that contains only the empty
+# string. Order of the output is not guaranteed. If any elements
+# have been previously removed from the set, this action will prune
+# the unused memory. This is O(n) in the size of the set before
+# pruning.
+#
+# Use _m4_popdef for speed. The existence of _m4_set_cleanup($1)
+# determines which version of _1 helper we use.
+m4_define([m4_set_contents],
+[m4_set_map_sep([$1], [], [], [[$2]])])
+
+# _m4_set_contents_1(SET)
+# _m4_set_contents_1c(SET)
+# _m4_set_contents_2(SET, [PRE], [POST], [SEP])
+# ---------------------------------------------
+# Expand to a list of quoted elements currently in the set, each
+# surrounded by PRE and POST, and moving SEP in front of PRE on
+# recursion. To avoid nesting limit restrictions, the algorithm must
+# be broken into two parts; _1 destructively copies the stack in
+# reverse into _m4_set_($1), producing no output; then _2
+# destructively copies _m4_set_($1) back into the stack in reverse.
+# If no elements were deleted, then this visits the set in the order
+# that elements were inserted. Behavior is undefined if PRE/POST/SEP
+# tries to recursively list or modify SET in any way other than
+# calling m4_set_remove on the current element. Use _1 if all entries
+# in the stack are guaranteed to be in the set, and _1c to prune
+# removed entries. Uses _m4_defn and _m4_popdef for speed.
+m4_define([_m4_set_contents_1],
+[_m4_stack_reverse([_m4_set([$1])], [_m4_set_($1)])])
+
+m4_define([_m4_set_contents_1c],
+[m4_ifdef([_m4_set([$1])],
+ [m4_set_contains([$1], _m4_defn([_m4_set([$1])]),
+ [m4_pushdef([_m4_set_($1)], _m4_defn([_m4_set([$1])]))],
+ [_m4_popdef([_m4_set([$1],]_m4_defn(
+ [_m4_set([$1])])[)])])_m4_popdef([_m4_set([$1])])$0([$1])],
+ [_m4_popdef([_m4_set_cleanup($1)])])])
+
+m4_define([_m4_set_contents_2],
+[_m4_stack_reverse([_m4_set_($1)], [_m4_set([$1])],
+ [$2[]_m4_defn([_m4_set_($1)])$3], [$4[]])])
+
+# m4_set_delete(SET)
+# ------------------
+# Delete all elements in SET, and reclaim any memory occupied by the
+# set. This is O(n) in the set size.
+#
+# Use _m4_defn and _m4_popdef for speed.
+m4_define([m4_set_delete],
+[m4_ifdef([_m4_set([$1])],
+ [_m4_popdef([_m4_set([$1],]_m4_defn([_m4_set([$1])])[)],
+ [_m4_set([$1])])$0([$1])],
+ [m4_ifdef([_m4_set_cleanup($1)],
+ [_m4_popdef([_m4_set_cleanup($1)])])m4_ifdef(
+ [_m4_set_size($1)],
+ [_m4_popdef([_m4_set_size($1)])])])])
+
+# m4_set_difference(SET1, SET2)
+# -----------------------------
+# Produce a LIST of quoted elements that occur in SET1 but not SET2.
+# Output a comma prior to any elements, to distinguish the empty
+# string from no elements. This can be directly used as a series of
+# arguments, such as for m4_join, or wrapped inside quotes for use in
+# m4_foreach. Order of the output is not guaranteed.
+#
+# Short-circuit the idempotence relation.
+m4_define([m4_set_difference],
+[m4_if([$1], [$2], [], [m4_set_map_sep([$1], [_$0([$2],], [)])])])
+
+m4_define([_m4_set_difference],
+[m4_set_contains([$1], [$2], [], [,[$2]])])
+
+# m4_set_dump(SET, [SEP])
+# -----------------------
+# Expand to a single string containing all the elements in SET,
+# separated by SEP, then delete SET. In general, if you only need to
+# list the contents once, this is faster than m4_set_contents. No
+# provision is made for disambiguating set elements that contain
+# non-empty SEP as a sub-string. Order of the output is not
+# guaranteed. This is O(n) in the size of the set before pruning.
+#
+# Use _m4_popdef for speed. Use existence of _m4_set_cleanup($1) to
+# decide if more expensive recursion is needed.
+m4_define([m4_set_dump],
+[m4_ifdef([_m4_set_size($1)],
+ [_m4_popdef([_m4_set_size($1)])])m4_ifdef([_m4_set_cleanup($1)],
+ [_$0_check], [_$0])([$1], [], [$2])])
+
+# _m4_set_dump(SET, [SEP], [PREP])
+# _m4_set_dump_check(SET, [SEP], [PREP])
+# --------------------------------------
+# Print SEP and the current element, then delete the element and
+# recurse with empty SEP changed to PREP. The check variant checks
+# whether the element has been previously removed. Use _m4_defn and
+# _m4_popdef for speed.
+m4_define([_m4_set_dump],
+[m4_ifdef([_m4_set([$1])],
+ [[$2]_m4_defn([_m4_set([$1])])_m4_popdef([_m4_set([$1],]_m4_defn(
+ [_m4_set([$1])])[)], [_m4_set([$1])])$0([$1], [$2$3])])])
+
+m4_define([_m4_set_dump_check],
+[m4_ifdef([_m4_set([$1])],
+ [m4_set_contains([$1], _m4_defn([_m4_set([$1])]),
+ [[$2]_m4_defn([_m4_set([$1])])])_m4_popdef(
+ [_m4_set([$1],]_m4_defn([_m4_set([$1])])[)],
+ [_m4_set([$1])])$0([$1], [$2$3])],
+ [_m4_popdef([_m4_set_cleanup($1)])])])
+
+# m4_set_empty(SET, [IF-EMPTY], [IF-ELEMENTS])
+# --------------------------------------------
+# Expand IF-EMPTY if SET has no elements, otherwise IF-ELEMENTS.
+m4_define([m4_set_empty],
+[m4_ifdef([_m4_set_size($1)],
+ [m4_if(m4_indir([_m4_set_size($1)]), [0], [$2], [$3])], [$2])])
+
+# m4_set_foreach(SET, VAR, ACTION)
+# --------------------------------
+# For each element of SET, define VAR to the element and expand
+# ACTION. ACTION should not recursively list SET's contents, add
+# elements to SET, nor delete any element from SET except the one
+# currently in VAR. The order that the elements are visited in is not
+# guaranteed. This is faster than the corresponding m4_foreach([VAR],
+# m4_indir([m4_dquote]m4_set_listc([SET])), [ACTION])
+m4_define([m4_set_foreach],
+[m4_pushdef([$2])m4_set_map_sep([$1], [m4_define([$2],], [)$3])])
+
+# m4_set_intersection(SET1, SET2)
+# -------------------------------
+# Produce a LIST of quoted elements that occur in both SET1 or SET2.
+# Output a comma prior to any elements, to distinguish the empty
+# string from no elements. This can be directly used as a series of
+# arguments, such as for m4_join, or wrapped inside quotes for use in
+# m4_foreach. Order of the output is not guaranteed.
+#
+# Iterate over the smaller set, and short-circuit the idempotence
+# relation.
+m4_define([m4_set_intersection],
+[m4_if([$1], [$2], [m4_set_listc([$1])],
+ m4_eval(m4_set_size([$2]) < m4_set_size([$1])), [1], [$0([$2], [$1])],
+ [m4_set_map_sep([$1], [_$0([$2],], [)])])])
+
+m4_define([_m4_set_intersection],
+[m4_set_contains([$1], [$2], [,[$2]])])
+
+# m4_set_list(SET)
+# m4_set_listc(SET)
+# -----------------
+# Produce a LIST of quoted elements of SET. This can be directly used
+# as a series of arguments, such as for m4_join or m4_set_add_all, or
+# wrapped inside quotes for use in m4_foreach or m4_map. With
+# m4_set_list, there is no way to distinguish an empty set from a set
+# containing only the empty string; with m4_set_listc, a leading comma
+# is output if there are any elements.
+m4_define([m4_set_list],
+[m4_set_map_sep([$1], [], [], [,])])
+
+m4_define([m4_set_listc],
+[m4_set_map_sep([$1], [,])])
+
+# m4_set_map(SET, ACTION)
+# -----------------------
+# For each element of SET, expand ACTION with a single argument of the
+# current element. ACTION should not recursively list SET's contents,
+# add elements to SET, nor delete any element from SET except the one
+# passed as an argument. The order that the elements are visited in
+# is not guaranteed. This is faster than either of the corresponding
+# m4_map_args([ACTION]m4_set_listc([SET]))
+# m4_set_foreach([SET], [VAR], [ACTION(m4_defn([VAR]))])
+m4_define([m4_set_map],
+[m4_set_map_sep([$1], [$2(], [)])])
+
+# m4_set_map_sep(SET, [PRE], [POST], [SEP])
+# -----------------------------------------
+# For each element of SET, expand PRE[value]POST[], and expand SEP
+# between elements.
+m4_define([m4_set_map_sep],
+[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c],
+ [_m4_set_contents_1])([$1])_m4_set_contents_2($@)])
+
+# m4_set_remove(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
+# ----------------------------------------------------
+# If VALUE is an element of SET, delete it and expand IF-PRESENT.
+# Otherwise expand IF-ABSENT. Deleting a single value is O(1),
+# although it leaves memory occupied until the next O(n) traversal of
+# the set which will compact the set.
+#
+# Optimize if the element being removed is the most recently added,
+# since defining _m4_set_cleanup($1) slows down so many other macros.
+# In particular, this plays well with m4_set_foreach and m4_set_map.
+m4_define([m4_set_remove],
+[m4_set_contains([$1], [$2], [_m4_set_size([$1],
+ [m4_decr])m4_if(_m4_defn([_m4_set([$1])]), [$2],
+ [_m4_popdef([_m4_set([$1],$2)], [_m4_set([$1])])],
+ [m4_define([_m4_set_cleanup($1)])m4_define(
+ [_m4_set([$1],$2)], [0])])$3], [$4])])
+
+# m4_set_size(SET)
+# ----------------
+# Expand to the number of elements currently in SET. This operation
+# is O(1), and thus more efficient than m4_count(m4_set_list([SET])).
+m4_define([m4_set_size],
+[m4_ifdef([_m4_set_size($1)], [m4_indir([_m4_set_size($1)])], [0])])
+
+# _m4_set_size(SET, ACTION)
+# -------------------------
+# ACTION must be either m4_incr or m4_decr, and the size of SET is
+# changed accordingly. If the set is empty, ACTION must not be
+# m4_decr.
+m4_define([_m4_set_size],
+[m4_define([_m4_set_size($1)],
+ m4_ifdef([_m4_set_size($1)], [$2(m4_indir([_m4_set_size($1)]))],
+ [1]))])
+
+# m4_set_union(SET1, SET2)
+# ------------------------
+# Produce a LIST of double quoted elements that occur in either SET1
+# or SET2, without duplicates. Output a comma prior to any elements,
+# to distinguish the empty string from no elements. This can be
+# directly used as a series of arguments, such as for m4_join, or
+# wrapped inside quotes for use in m4_foreach. Order of the output is
+# not guaranteed.
+#
+# We can rely on the fact that m4_set_listc prunes SET1, so we don't
+# need to check _m4_set([$1],element) for 0. Short-circuit the
+# idempotence relation.
+m4_define([m4_set_union],
+[m4_set_listc([$1])m4_if([$1], [$2], [],
+ [m4_set_map_sep([$2], [_$0([$1],], [)])])])
+
+m4_define([_m4_set_union],
+[m4_ifdef([_m4_set([$1],$2)], [], [,[$2]])])
+
+
+## ------------------- ##
+## 16. File handling. ##
+## ------------------- ##
+
+
+# It is a real pity that M4 comes with no macros to bind a diversion
+# to a file. So we have to deal without, which makes us a lot more
+# fragile than we should.
+
+
+# m4_file_append(FILE-NAME, CONTENT)
+# ----------------------------------
+m4_define([m4_file_append],
+[m4_syscmd([cat >>$1 <<_m4eof
+$2
+_m4eof
+])
+m4_if(m4_sysval, [0], [],
+ [m4_fatal([$0: cannot write: $1])])])
+
+
+
+## ------------------------ ##
+## 17. Setting M4sugar up. ##
+## ------------------------ ##
+
+# _m4_divert_diversion should be defined.
+m4_divert_push([KILL])
+
+# m4_init
+# -------
+# Initialize the m4sugar language.
+m4_define([m4_init],
+[# All the M4sugar macros start with `m4_', except `dnl' kept as is
+# for sake of simplicity.
+m4_pattern_forbid([^_?m4_])
+m4_pattern_forbid([^dnl$])
+
+# If __m4_version__ is defined, we assume that we are being run by M4
+# 1.6 or newer, thus $@ recursion is linear, and debugmode(+do)
+# is available for faster checks of dereferencing undefined macros
+# and forcing dumpdef to print to stderr regardless of debugfile.
+# But if it is missing, we assume we are being run by M4 1.4.x, that
+# $@ recursion is quadratic, and that we need foreach-based
+# replacement macros. Also, m4 prior to 1.4.8 loses track of location
+# during m4wrap text; __line__ should never be 0.
+#
+# Use the raw builtin to avoid tripping up include tracing.
+# Meanwhile, avoid m4_copy, since it temporarily undefines m4_defn.
+m4_ifdef([__m4_version__],
+[m4_debugmode([+do])
+m4_define([m4_defn], _m4_defn([_m4_defn]))
+m4_define([m4_dumpdef], _m4_defn([_m4_dumpdef]))
+m4_define([m4_popdef], _m4_defn([_m4_popdef]))
+m4_define([m4_undefine], _m4_defn([_m4_undefine]))],
+[m4_builtin([include], [m4sugar/foreach.m4])
+m4_wrap_lifo([m4_if(__line__, [0], [m4_pushdef([m4_location],
+]]m4_dquote(m4_dquote(m4_dquote(__file__:__line__)))[[)])])])
+
+# Rewrite the first entry of the diversion stack.
+m4_divert([KILL])
+
+# Check the divert push/pop perfect balance.
+# Some users are prone to also use m4_wrap to register last-minute
+# m4_divert_text; so after our diversion cleanups, we restore
+# KILL as the bottom of the diversion stack.
+m4_wrap([m4_popdef([_m4_divert_diversion])m4_ifdef(
+ [_m4_divert_diversion], [m4_fatal([$0: unbalanced m4_divert_push:
+]m4_divert_stack)])_m4_popdef([_m4_divert_stack])m4_divert_push([KILL])])
+])
diff --git a/contrib/tools/bison/bison/data/stack.hh b/contrib/tools/bison/bison/data/stack.hh
index aa64d63d84..4c2f7cf377 100644
--- a/contrib/tools/bison/bison/data/stack.hh
+++ b/contrib/tools/bison/bison/data/stack.hh
@@ -1,154 +1,154 @@
-# C++ skeleton for Bison
-
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-m4_pushdef([b4_copyright_years],
- [2002-2013])
-
-# b4_stack_define
-# ---------------
-m4_define([b4_stack_define],
-[[ template <class T, class S = std::vector<T> >
- class stack
- {
- public:
- // Hide our reversed order.
- typedef typename S::reverse_iterator iterator;
- typedef typename S::const_reverse_iterator const_iterator;
-
- stack ()
- : seq_ ()
- {
- }
-
- stack (unsigned int n)
- : seq_ (n)
- {
- }
-
- inline
- T&
- operator[] (unsigned int i)
- {
- return seq_[seq_.size () - 1 - i];
- }
-
- inline
- const T&
- operator[] (unsigned int i) const
- {
- return seq_[seq_.size () - 1 - i];
- }
-
- /// Steal the contents of \a t.
- ///
- /// Close to move-semantics.
- inline
- void
- push (T& t)
- {
- seq_.push_back (T());
- operator[](0).move (t);
- }
-
- inline
- void
- pop (unsigned int n = 1)
- {
- for (; n; --n)
- seq_.pop_back ();
- }
-
- void
- clear ()
- {
- seq_.clear ();
- }
-
- inline
- typename S::size_type
- size () const
- {
- return seq_.size ();
- }
-
- inline
- const_iterator
- begin () const
- {
- return seq_.rbegin ();
- }
-
- inline
- const_iterator
- end () const
- {
- return seq_.rend ();
- }
-
- private:
- stack (const stack&);
- stack& operator= (const stack&);
- /// The wrapped container.
- S seq_;
- };
-
- /// Present a slice of the top of a stack.
- template <class T, class S = stack<T> >
- class slice
- {
- public:
- slice (const S& stack, unsigned int range)
- : stack_ (stack)
- , range_ (range)
- {
- }
-
- inline
- const T&
- operator [] (unsigned int i) const
- {
- return stack_[range_ - i];
- }
-
- private:
- const S& stack_;
- unsigned int range_;
- };
-]])
-
-b4_defines_if(
-[b4_output_begin([b4_dir_prefix[]stack.hh])
-b4_copyright([Stack handling for Bison parsers in C++])[
-
-/**
- ** \file ]b4_dir_prefix[stack.hh
- ** Define the ]b4_namespace_ref[::stack class.
- */
-
-]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
-
-# include <vector>
-
-]b4_namespace_open[
-]b4_stack_define[
-]b4_namespace_close[
-
-]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
-b4_output_end()
-])
-
-m4_popdef([b4_copyright_years])
+# C++ skeleton for Bison
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([b4_copyright_years],
+ [2002-2013])
+
+# b4_stack_define
+# ---------------
+m4_define([b4_stack_define],
+[[ template <class T, class S = std::vector<T> >
+ class stack
+ {
+ public:
+ // Hide our reversed order.
+ typedef typename S::reverse_iterator iterator;
+ typedef typename S::const_reverse_iterator const_iterator;
+
+ stack ()
+ : seq_ ()
+ {
+ }
+
+ stack (unsigned int n)
+ : seq_ (n)
+ {
+ }
+
+ inline
+ T&
+ operator[] (unsigned int i)
+ {
+ return seq_[seq_.size () - 1 - i];
+ }
+
+ inline
+ const T&
+ operator[] (unsigned int i) const
+ {
+ return seq_[seq_.size () - 1 - i];
+ }
+
+ /// Steal the contents of \a t.
+ ///
+ /// Close to move-semantics.
+ inline
+ void
+ push (T& t)
+ {
+ seq_.push_back (T());
+ operator[](0).move (t);
+ }
+
+ inline
+ void
+ pop (unsigned int n = 1)
+ {
+ for (; n; --n)
+ seq_.pop_back ();
+ }
+
+ void
+ clear ()
+ {
+ seq_.clear ();
+ }
+
+ inline
+ typename S::size_type
+ size () const
+ {
+ return seq_.size ();
+ }
+
+ inline
+ const_iterator
+ begin () const
+ {
+ return seq_.rbegin ();
+ }
+
+ inline
+ const_iterator
+ end () const
+ {
+ return seq_.rend ();
+ }
+
+ private:
+ stack (const stack&);
+ stack& operator= (const stack&);
+ /// The wrapped container.
+ S seq_;
+ };
+
+ /// Present a slice of the top of a stack.
+ template <class T, class S = stack<T> >
+ class slice
+ {
+ public:
+ slice (const S& stack, unsigned int range)
+ : stack_ (stack)
+ , range_ (range)
+ {
+ }
+
+ inline
+ const T&
+ operator [] (unsigned int i) const
+ {
+ return stack_[range_ - i];
+ }
+
+ private:
+ const S& stack_;
+ unsigned int range_;
+ };
+]])
+
+b4_defines_if(
+[b4_output_begin([b4_dir_prefix[]stack.hh])
+b4_copyright([Stack handling for Bison parsers in C++])[
+
+/**
+ ** \file ]b4_dir_prefix[stack.hh
+ ** Define the ]b4_namespace_ref[::stack class.
+ */
+
+]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[
+
+# include <vector>
+
+]b4_namespace_open[
+]b4_stack_define[
+]b4_namespace_close[
+
+]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
+b4_output_end()
+])
+
+m4_popdef([b4_copyright_years])
diff --git a/contrib/tools/bison/bison/data/variant.hh b/contrib/tools/bison/bison/data/variant.hh
index ac4f7a7850..44a2634708 100644
--- a/contrib/tools/bison/bison/data/variant.hh
+++ b/contrib/tools/bison/bison/data/variant.hh
@@ -1,362 +1,362 @@
-# C++ skeleton for Bison
-
-# Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-## --------- ##
-## variant. ##
-## --------- ##
-
-# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
-# ------------------------------------------------
-# Run some ACTION ("build", or "destroy") on YYVAL of symbol type
-# YYTYPE.
-m4_define([b4_symbol_variant],
-[m4_pushdef([b4_dollar_dollar],
- [$2.$3< $][3 > (m4_shift3($@))])dnl
- switch ($1)
- {
-b4_type_foreach([b4_type_action_])[]dnl
- default:
- break;
- }
-m4_popdef([b4_dollar_dollar])dnl
-])
-
-
-# _b4_char_sizeof_counter
-# -----------------------
-# A counter used by _b4_char_sizeof_dummy to create fresh symbols.
-m4_define([_b4_char_sizeof_counter],
-[0])
-
-# _b4_char_sizeof_dummy
-# ---------------------
-# At each call return a new C++ identifier.
-m4_define([_b4_char_sizeof_dummy],
-[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
-dummy[]_b4_char_sizeof_counter])
-
-
-# b4_char_sizeof(SYMBOL-NUMS)
-# ---------------------------
-# To be mapped on the list of type names to produce:
-#
-# char dummy1[sizeof(type_name_1)];
-# char dummy2[sizeof(type_name_2)];
-#
-# for defined type names.
-m4_define([b4_char_sizeof],
-[b4_symbol_if([$1], [has_type],
-[
-m4_map([ b4_symbol_tag_comment], [$@])dnl
- char _b4_char_sizeof_dummy@{sizeof(b4_symbol([$1], [type]))@};
-])])
-
-
-# b4_variant_includes
-# -------------------
-# The needed includes for variants support.
-m4_define([b4_variant_includes],
-[b4_parse_assert_if([[#include <typeinfo>]])[
-#ifndef YYASSERT
-# include <cassert>
-# define YYASSERT assert
-#endif
-]])
-
-# b4_variant_define
-# -----------------
-# Define "variant".
-m4_define([b4_variant_define],
-[[ /// A char[S] buffer to store and retrieve objects.
- ///
- /// Sort of a variant, but does not keep track of the nature
- /// of the stored data, since that knowledge is available
- /// via the current state.
- template <size_t S>
- struct variant
- {
- /// Type of *this.
- typedef variant<S> self_type;
-
- /// Empty construction.
- variant ()]b4_parse_assert_if([
- : yytname_ (YY_NULL)])[
- {}
-
- /// Construct and fill.
- template <typename T>
- variant (const T& t)]b4_parse_assert_if([
- : yytname_ (typeid (T).name ())])[
- {
- YYASSERT (sizeof (T) <= S);
- new (yyas_<T> ()) T (t);
- }
-
- /// Destruction, allowed only if empty.
- ~variant ()
- {]b4_parse_assert_if([
- YYASSERT (!yytname_);
- ])[}
-
- /// Instantiate an empty \a T in here.
- template <typename T>
- T&
- build ()
- {]b4_parse_assert_if([
- YYASSERT (!yytname_);
- YYASSERT (sizeof (T) <= S);
- yytname_ = typeid (T).name ();])[
- return *new (yyas_<T> ()) T;
- }
-
- /// Instantiate a \a T in here from \a t.
- template <typename T>
- T&
- build (const T& t)
- {]b4_parse_assert_if([
- YYASSERT (!yytname_);
- YYASSERT (sizeof (T) <= S);
- yytname_ = typeid (T).name ();])[
- return *new (yyas_<T> ()) T (t);
- }
-
- /// Accessor to a built \a T.
- template <typename T>
- T&
- as ()
- {]b4_parse_assert_if([
- YYASSERT (yytname_ == typeid (T).name ());
- YYASSERT (sizeof (T) <= S);])[
- return *yyas_<T> ();
- }
-
- /// Const accessor to a built \a T (for %printer).
- template <typename T>
- const T&
- as () const
- {]b4_parse_assert_if([
- YYASSERT (yytname_ == typeid (T).name ());
- YYASSERT (sizeof (T) <= S);])[
- return *yyas_<T> ();
- }
-
- /// Swap the content with \a other, of same type.
- ///
- /// Both variants must be built beforehand, because swapping the actual
- /// data requires reading it (with as()), and this is not possible on
- /// unconstructed variants: it would require some dynamic testing, which
- /// should not be the variant's responsability.
- /// Swapping between built and (possibly) non-built is done with
- /// variant::move ().
- template <typename T>
- void
- swap (self_type& other)
- {]b4_parse_assert_if([
- YYASSERT (yytname_);
- YYASSERT (yytname_ == other.yytname_);])[
- std::swap (as<T> (), other.as<T> ());
- }
-
- /// Move the content of \a other to this.
- ///
- /// Destroys \a other.
- template <typename T>
- void
- move (self_type& other)
- {]b4_parse_assert_if([
- YYASSERT (!yytname_);])[
- build<T> ();
- swap<T> (other);
- other.destroy<T> ();
- }
-
- /// Copy the content of \a other to this.
- template <typename T>
- void
- copy (const self_type& other)
- {
- build<T> (other.as<T> ());
- }
-
- /// Destroy the stored \a T.
- template <typename T>
- void
- destroy ()
- {
- as<T> ().~T ();]b4_parse_assert_if([
- yytname_ = YY_NULL;])[
- }
-
- private:
- /// Prohibit blind copies.
- self_type& operator=(const self_type&);
- variant (const self_type&);
-
- /// Accessor to raw memory as \a T.
- template <typename T>
- T*
- yyas_ ()
- {
- void *yyp = yybuffer_.yyraw;
- return static_cast<T*> (yyp);
- }
-
- /// Const accessor to raw memory as \a T.
- template <typename T>
- const T*
- yyas_ () const
- {
- const void *yyp = yybuffer_.yyraw;
- return static_cast<const T*> (yyp);
- }
-
- union
- {
- /// Strongest alignment constraints.
- long double yyalign_me;
- /// A buffer large enough to store any of the semantic values.
- char yyraw[S];
- } yybuffer_;]b4_parse_assert_if([
-
- /// Whether the content is built: if defined, the name of the stored type.
- const char *yytname_;])[
- };
-]])
-
-
-## -------------------------- ##
-## Adjustments for variants. ##
-## -------------------------- ##
-
-
-# b4_value_type_declare
-# ---------------------
-# Declare semantic_type.
-m4_define([b4_value_type_declare],
-[[ /// An auxiliary type to compute the largest semantic type.
- union union_type
- {]b4_type_foreach([b4_char_sizeof])[};
-
- /// Symbol semantic values.
- typedef variant<sizeof(union_type)> semantic_type;][]dnl
-])
-
-
-# How the semantic value is extracted when using variants.
-
-# b4_symbol_value(VAL, [TYPE])
-# ----------------------------
-m4_define([b4_symbol_value],
-[m4_ifval([$2],
- [$1.as< $2 > ()],
- [$1])])
-
-# b4_symbol_value_template(VAL, [TYPE])
-# -------------------------------------
-# Same as b4_symbol_value, but used in a template method.
-m4_define([b4_symbol_value_template],
-[m4_ifval([$2],
- [$1.template as< $2 > ()],
- [$1])])
-
-
-
-## ------------- ##
-## make_SYMBOL. ##
-## ------------- ##
-
-
-# b4_symbol_constructor_declare_(SYMBOL-NUMBER)
-# ---------------------------------------------
-# Declare the overloaded version of make_symbol for the (common) type of
-# these SYMBOL-NUMBERS. Use at class-level.
-m4_define([b4_symbol_constructor_declare_],
-[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
-[ static inline
- symbol_type
- make_[]b4_symbol_([$1], [id]) (dnl
-b4_join(b4_symbol_if([$1], [has_type],
- [const b4_symbol([$1], [type])& v]),
- b4_locations_if([const location_type& l])));
-
-])])])
-
-
-# b4_symbol_constructor_declare
-# -----------------------------
-# Declare symbol constructors for all the value types.
-# Use at class-level.
-m4_define([b4_symbol_constructor_declare],
-[ // Symbol constructors declarations.
-b4_symbol_foreach([b4_symbol_constructor_declare_])])
-
-
-
-# b4_symbol_constructor_define_(SYMBOL-NUMBER)
-# --------------------------------------------
-# Define symbol constructor for this SYMBOL-NUMBER.
-m4_define([b4_symbol_constructor_define_],
-[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
-[ b4_parser_class_name::symbol_type
- b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
-b4_join(b4_symbol_if([$1], [has_type],
- [const b4_symbol([$1], [type])& v]),
- b4_locations_if([const location_type& l])))
- {
- return symbol_type (b4_join([token::b4_symbol([$1], [id])],
- b4_symbol_if([$1], [has_type], [v]),
- b4_locations_if([l])));
-
- }
-
-])])])
-
-
-# b4_basic_symbol_constructor_declare
-# -----------------------------------
-# Generate a constructor declaration for basic_symbol from given type.
-m4_define([b4_basic_symbol_constructor_declare],
-[[
- basic_symbol (]b4_join(
- [typename Base::kind_type t],
- b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[ v]),
- b4_locations_if([const location_type& l]))[);
-]])
-
-# b4_basic_symbol_constructor_define
-# ----------------------------------
-# Generate a constructor implementation for basic_symbol from given type.
-m4_define([b4_basic_symbol_constructor_define],
-[[
- template <typename Base>
- ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
- [typename Base::kind_type t],
- b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[ v]),
- b4_locations_if([const location_type& l]))[)
- : Base (t)
- , value (]b4_symbol_if([$1], [has_type], [v])[)]b4_locations_if([
- , location (l)])[
- {}
-]])
-
-# b4_symbol_constructor_define
-# ----------------------------
-# Define the overloaded versions of make_symbol for all the value types.
-m4_define([b4_symbol_constructor_define],
-[ // Implementation of make_symbol for each symbol type.
-b4_symbol_foreach([b4_symbol_constructor_define_])])
+# C++ skeleton for Bison
+
+# Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+## --------- ##
+## variant. ##
+## --------- ##
+
+# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
+# ------------------------------------------------
+# Run some ACTION ("build", or "destroy") on YYVAL of symbol type
+# YYTYPE.
+m4_define([b4_symbol_variant],
+[m4_pushdef([b4_dollar_dollar],
+ [$2.$3< $][3 > (m4_shift3($@))])dnl
+ switch ($1)
+ {
+b4_type_foreach([b4_type_action_])[]dnl
+ default:
+ break;
+ }
+m4_popdef([b4_dollar_dollar])dnl
+])
+
+
+# _b4_char_sizeof_counter
+# -----------------------
+# A counter used by _b4_char_sizeof_dummy to create fresh symbols.
+m4_define([_b4_char_sizeof_counter],
+[0])
+
+# _b4_char_sizeof_dummy
+# ---------------------
+# At each call return a new C++ identifier.
+m4_define([_b4_char_sizeof_dummy],
+[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
+dummy[]_b4_char_sizeof_counter])
+
+
+# b4_char_sizeof(SYMBOL-NUMS)
+# ---------------------------
+# To be mapped on the list of type names to produce:
+#
+# char dummy1[sizeof(type_name_1)];
+# char dummy2[sizeof(type_name_2)];
+#
+# for defined type names.
+m4_define([b4_char_sizeof],
+[b4_symbol_if([$1], [has_type],
+[
+m4_map([ b4_symbol_tag_comment], [$@])dnl
+ char _b4_char_sizeof_dummy@{sizeof(b4_symbol([$1], [type]))@};
+])])
+
+
+# b4_variant_includes
+# -------------------
+# The needed includes for variants support.
+m4_define([b4_variant_includes],
+[b4_parse_assert_if([[#include <typeinfo>]])[
+#ifndef YYASSERT
+# include <cassert>
+# define YYASSERT assert
+#endif
+]])
+
+# b4_variant_define
+# -----------------
+# Define "variant".
+m4_define([b4_variant_define],
+[[ /// A char[S] buffer to store and retrieve objects.
+ ///
+ /// Sort of a variant, but does not keep track of the nature
+ /// of the stored data, since that knowledge is available
+ /// via the current state.
+ template <size_t S>
+ struct variant
+ {
+ /// Type of *this.
+ typedef variant<S> self_type;
+
+ /// Empty construction.
+ variant ()]b4_parse_assert_if([
+ : yytname_ (YY_NULL)])[
+ {}
+
+ /// Construct and fill.
+ template <typename T>
+ variant (const T& t)]b4_parse_assert_if([
+ : yytname_ (typeid (T).name ())])[
+ {
+ YYASSERT (sizeof (T) <= S);
+ new (yyas_<T> ()) T (t);
+ }
+
+ /// Destruction, allowed only if empty.
+ ~variant ()
+ {]b4_parse_assert_if([
+ YYASSERT (!yytname_);
+ ])[}
+
+ /// Instantiate an empty \a T in here.
+ template <typename T>
+ T&
+ build ()
+ {]b4_parse_assert_if([
+ YYASSERT (!yytname_);
+ YYASSERT (sizeof (T) <= S);
+ yytname_ = typeid (T).name ();])[
+ return *new (yyas_<T> ()) T;
+ }
+
+ /// Instantiate a \a T in here from \a t.
+ template <typename T>
+ T&
+ build (const T& t)
+ {]b4_parse_assert_if([
+ YYASSERT (!yytname_);
+ YYASSERT (sizeof (T) <= S);
+ yytname_ = typeid (T).name ();])[
+ return *new (yyas_<T> ()) T (t);
+ }
+
+ /// Accessor to a built \a T.
+ template <typename T>
+ T&
+ as ()
+ {]b4_parse_assert_if([
+ YYASSERT (yytname_ == typeid (T).name ());
+ YYASSERT (sizeof (T) <= S);])[
+ return *yyas_<T> ();
+ }
+
+ /// Const accessor to a built \a T (for %printer).
+ template <typename T>
+ const T&
+ as () const
+ {]b4_parse_assert_if([
+ YYASSERT (yytname_ == typeid (T).name ());
+ YYASSERT (sizeof (T) <= S);])[
+ return *yyas_<T> ();
+ }
+
+ /// Swap the content with \a other, of same type.
+ ///
+ /// Both variants must be built beforehand, because swapping the actual
+ /// data requires reading it (with as()), and this is not possible on
+ /// unconstructed variants: it would require some dynamic testing, which
+ /// should not be the variant's responsability.
+ /// Swapping between built and (possibly) non-built is done with
+ /// variant::move ().
+ template <typename T>
+ void
+ swap (self_type& other)
+ {]b4_parse_assert_if([
+ YYASSERT (yytname_);
+ YYASSERT (yytname_ == other.yytname_);])[
+ std::swap (as<T> (), other.as<T> ());
+ }
+
+ /// Move the content of \a other to this.
+ ///
+ /// Destroys \a other.
+ template <typename T>
+ void
+ move (self_type& other)
+ {]b4_parse_assert_if([
+ YYASSERT (!yytname_);])[
+ build<T> ();
+ swap<T> (other);
+ other.destroy<T> ();
+ }
+
+ /// Copy the content of \a other to this.
+ template <typename T>
+ void
+ copy (const self_type& other)
+ {
+ build<T> (other.as<T> ());
+ }
+
+ /// Destroy the stored \a T.
+ template <typename T>
+ void
+ destroy ()
+ {
+ as<T> ().~T ();]b4_parse_assert_if([
+ yytname_ = YY_NULL;])[
+ }
+
+ private:
+ /// Prohibit blind copies.
+ self_type& operator=(const self_type&);
+ variant (const self_type&);
+
+ /// Accessor to raw memory as \a T.
+ template <typename T>
+ T*
+ yyas_ ()
+ {
+ void *yyp = yybuffer_.yyraw;
+ return static_cast<T*> (yyp);
+ }
+
+ /// Const accessor to raw memory as \a T.
+ template <typename T>
+ const T*
+ yyas_ () const
+ {
+ const void *yyp = yybuffer_.yyraw;
+ return static_cast<const T*> (yyp);
+ }
+
+ union
+ {
+ /// Strongest alignment constraints.
+ long double yyalign_me;
+ /// A buffer large enough to store any of the semantic values.
+ char yyraw[S];
+ } yybuffer_;]b4_parse_assert_if([
+
+ /// Whether the content is built: if defined, the name of the stored type.
+ const char *yytname_;])[
+ };
+]])
+
+
+## -------------------------- ##
+## Adjustments for variants. ##
+## -------------------------- ##
+
+
+# b4_value_type_declare
+# ---------------------
+# Declare semantic_type.
+m4_define([b4_value_type_declare],
+[[ /// An auxiliary type to compute the largest semantic type.
+ union union_type
+ {]b4_type_foreach([b4_char_sizeof])[};
+
+ /// Symbol semantic values.
+ typedef variant<sizeof(union_type)> semantic_type;][]dnl
+])
+
+
+# How the semantic value is extracted when using variants.
+
+# b4_symbol_value(VAL, [TYPE])
+# ----------------------------
+m4_define([b4_symbol_value],
+[m4_ifval([$2],
+ [$1.as< $2 > ()],
+ [$1])])
+
+# b4_symbol_value_template(VAL, [TYPE])
+# -------------------------------------
+# Same as b4_symbol_value, but used in a template method.
+m4_define([b4_symbol_value_template],
+[m4_ifval([$2],
+ [$1.template as< $2 > ()],
+ [$1])])
+
+
+
+## ------------- ##
+## make_SYMBOL. ##
+## ------------- ##
+
+
+# b4_symbol_constructor_declare_(SYMBOL-NUMBER)
+# ---------------------------------------------
+# Declare the overloaded version of make_symbol for the (common) type of
+# these SYMBOL-NUMBERS. Use at class-level.
+m4_define([b4_symbol_constructor_declare_],
+[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
+[ static inline
+ symbol_type
+ make_[]b4_symbol_([$1], [id]) (dnl
+b4_join(b4_symbol_if([$1], [has_type],
+ [const b4_symbol([$1], [type])& v]),
+ b4_locations_if([const location_type& l])));
+
+])])])
+
+
+# b4_symbol_constructor_declare
+# -----------------------------
+# Declare symbol constructors for all the value types.
+# Use at class-level.
+m4_define([b4_symbol_constructor_declare],
+[ // Symbol constructors declarations.
+b4_symbol_foreach([b4_symbol_constructor_declare_])])
+
+
+
+# b4_symbol_constructor_define_(SYMBOL-NUMBER)
+# --------------------------------------------
+# Define symbol constructor for this SYMBOL-NUMBER.
+m4_define([b4_symbol_constructor_define_],
+[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
+[ b4_parser_class_name::symbol_type
+ b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
+b4_join(b4_symbol_if([$1], [has_type],
+ [const b4_symbol([$1], [type])& v]),
+ b4_locations_if([const location_type& l])))
+ {
+ return symbol_type (b4_join([token::b4_symbol([$1], [id])],
+ b4_symbol_if([$1], [has_type], [v]),
+ b4_locations_if([l])));
+
+ }
+
+])])])
+
+
+# b4_basic_symbol_constructor_declare
+# -----------------------------------
+# Generate a constructor declaration for basic_symbol from given type.
+m4_define([b4_basic_symbol_constructor_declare],
+[[
+ basic_symbol (]b4_join(
+ [typename Base::kind_type t],
+ b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[ v]),
+ b4_locations_if([const location_type& l]))[);
+]])
+
+# b4_basic_symbol_constructor_define
+# ----------------------------------
+# Generate a constructor implementation for basic_symbol from given type.
+m4_define([b4_basic_symbol_constructor_define],
+[[
+ template <typename Base>
+ ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
+ [typename Base::kind_type t],
+ b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[ v]),
+ b4_locations_if([const location_type& l]))[)
+ : Base (t)
+ , value (]b4_symbol_if([$1], [has_type], [v])[)]b4_locations_if([
+ , location (l)])[
+ {}
+]])
+
+# b4_symbol_constructor_define
+# ----------------------------
+# Define the overloaded versions of make_symbol for all the value types.
+m4_define([b4_symbol_constructor_define],
+[ // Implementation of make_symbol for each symbol type.
+b4_symbol_foreach([b4_symbol_constructor_define_])])
diff --git a/contrib/tools/bison/bison/data/xslt/bison.xsl b/contrib/tools/bison/bison/data/xslt/bison.xsl
index 10e3305bd7..41a1fcbc5f 100644
--- a/contrib/tools/bison/bison/data/xslt/bison.xsl
+++ b/contrib/tools/bison/bison/data/xslt/bison.xsl
@@ -1,105 +1,105 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- bison.xsl - common templates for Bison XSLT.
-
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- -->
-
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:bison="http://www.gnu.org/software/bison/">
-
-<xsl:key
- name="bison:symbolByName"
- match="/bison-xml-report/grammar/nonterminals/nonterminal"
- use="@name"
-/>
-<xsl:key
- name="bison:symbolByName"
- match="/bison-xml-report/grammar/terminals/terminal"
- use="@name"
-/>
-<xsl:key
- name="bison:ruleByNumber"
- match="/bison-xml-report/grammar/rules/rule"
- use="@number"
-/>
-<xsl:key
- name="bison:ruleByLhs"
- match="/bison-xml-report/grammar/rules/rule[
- @usefulness != 'useless-in-grammar']"
- use="lhs"
-/>
-<xsl:key
- name="bison:ruleByRhs"
- match="/bison-xml-report/grammar/rules/rule[
- @usefulness != 'useless-in-grammar']"
- use="rhs/symbol"
-/>
-
-<!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
-<xsl:template match="state" mode="bison:count-conflicts">
- <xsl:variable name="transitions" select="actions/transitions"/>
- <xsl:variable name="reductions" select="actions/reductions"/>
- <xsl:variable
- name="terminals"
- select="
- $transitions/transition[@type='shift']/@symbol
- | $reductions/reduction/@symbol
- "
- />
- <xsl:variable name="conflict-data">
- <xsl:for-each select="$terminals">
- <xsl:variable name="name" select="."/>
- <xsl:if test="generate-id($terminals[. = $name][1]) = generate-id(.)">
- <xsl:variable
- name="shift-count"
- select="count($transitions/transition[@symbol=$name])"
- />
- <xsl:variable
- name="reduce-count"
- select="count($reductions/reduction[@symbol=$name])"
- />
- <xsl:if test="$shift-count > 0 and $reduce-count > 0">
- <xsl:text>s</xsl:text>
- </xsl:if>
- <xsl:if test="$reduce-count > 1">
- <xsl:text>r</xsl:text>
- </xsl:if>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
- <xsl:value-of select="string-length(translate($conflict-data, 'r', ''))"/>
- <xsl:text>,</xsl:text>
- <xsl:value-of select="string-length(translate($conflict-data, 's', ''))"/>
-</xsl:template>
-
-<xsl:template name="space">
- <xsl:param name="repeat">0</xsl:param>
- <xsl:param name="fill" select="' '"/>
- <xsl:if test="number($repeat) &gt;= 1">
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$repeat - 1"/>
- <xsl:with-param name="fill" select="$fill"/>
- </xsl:call-template>
- <xsl:value-of select="$fill"/>
- </xsl:if>
-</xsl:template>
-
-</xsl:stylesheet>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ bison.xsl - common templates for Bison XSLT.
+
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:bison="http://www.gnu.org/software/bison/">
+
+<xsl:key
+ name="bison:symbolByName"
+ match="/bison-xml-report/grammar/nonterminals/nonterminal"
+ use="@name"
+/>
+<xsl:key
+ name="bison:symbolByName"
+ match="/bison-xml-report/grammar/terminals/terminal"
+ use="@name"
+/>
+<xsl:key
+ name="bison:ruleByNumber"
+ match="/bison-xml-report/grammar/rules/rule"
+ use="@number"
+/>
+<xsl:key
+ name="bison:ruleByLhs"
+ match="/bison-xml-report/grammar/rules/rule[
+ @usefulness != 'useless-in-grammar']"
+ use="lhs"
+/>
+<xsl:key
+ name="bison:ruleByRhs"
+ match="/bison-xml-report/grammar/rules/rule[
+ @usefulness != 'useless-in-grammar']"
+ use="rhs/symbol"
+/>
+
+<!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
+<xsl:template match="state" mode="bison:count-conflicts">
+ <xsl:variable name="transitions" select="actions/transitions"/>
+ <xsl:variable name="reductions" select="actions/reductions"/>
+ <xsl:variable
+ name="terminals"
+ select="
+ $transitions/transition[@type='shift']/@symbol
+ | $reductions/reduction/@symbol
+ "
+ />
+ <xsl:variable name="conflict-data">
+ <xsl:for-each select="$terminals">
+ <xsl:variable name="name" select="."/>
+ <xsl:if test="generate-id($terminals[. = $name][1]) = generate-id(.)">
+ <xsl:variable
+ name="shift-count"
+ select="count($transitions/transition[@symbol=$name])"
+ />
+ <xsl:variable
+ name="reduce-count"
+ select="count($reductions/reduction[@symbol=$name])"
+ />
+ <xsl:if test="$shift-count > 0 and $reduce-count > 0">
+ <xsl:text>s</xsl:text>
+ </xsl:if>
+ <xsl:if test="$reduce-count > 1">
+ <xsl:text>r</xsl:text>
+ </xsl:if>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:value-of select="string-length(translate($conflict-data, 'r', ''))"/>
+ <xsl:text>,</xsl:text>
+ <xsl:value-of select="string-length(translate($conflict-data, 's', ''))"/>
+</xsl:template>
+
+<xsl:template name="space">
+ <xsl:param name="repeat">0</xsl:param>
+ <xsl:param name="fill" select="' '"/>
+ <xsl:if test="number($repeat) &gt;= 1">
+ <xsl:call-template name="space">
+ <xsl:with-param name="repeat" select="$repeat - 1"/>
+ <xsl:with-param name="fill" select="$fill"/>
+ </xsl:call-template>
+ <xsl:value-of select="$fill"/>
+ </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/contrib/tools/bison/bison/data/xslt/xml2dot.xsl b/contrib/tools/bison/bison/data/xslt/xml2dot.xsl
index 93bec59989..f95c56769e 100644
--- a/contrib/tools/bison/bison/data/xslt/xml2dot.xsl
+++ b/contrib/tools/bison/bison/data/xslt/xml2dot.xsl
@@ -1,397 +1,397 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- xml2dot.xsl - transform Bison XML Report into DOT.
-
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- Written by Wojciech Polak <polak@gnu.org>.
- -->
-
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:bison="http://www.gnu.org/software/bison/">
-
-<xsl:import href="bison.xsl"/>
-<xsl:output method="text" encoding="UTF-8" indent="no"/>
-
-<xsl:template match="/">
- <xsl:apply-templates select="bison-xml-report"/>
-</xsl:template>
-
-<xsl:template match="bison-xml-report">
- <xsl:text>// Generated by GNU Bison </xsl:text>
- <xsl:value-of select="@version"/>
- <xsl:text>.&#10;</xsl:text>
- <xsl:text>// Report bugs to &lt;</xsl:text>
- <xsl:value-of select="@bug-report"/>
- <xsl:text>&gt;.&#10;</xsl:text>
- <xsl:text>// Home page: &lt;</xsl:text>
- <xsl:value-of select="@url"/>
- <xsl:text>&gt;.&#10;&#10;</xsl:text>
- <xsl:apply-templates select="automaton">
- <xsl:with-param name="filename" select="filename"/>
- </xsl:apply-templates>
-</xsl:template>
-
-<xsl:template match="automaton">
- <xsl:param name="filename"/>
- <xsl:text>digraph "</xsl:text>
- <xsl:call-template name="escape">
- <xsl:with-param name="subject" select="$filename"/>
- </xsl:call-template>
- <xsl:text>"&#10;{
- node [fontname = courier, shape = box, colorscheme = paired6]
- edge [fontname = courier]
-
-</xsl:text>
- <xsl:apply-templates select="state"/>
- <xsl:text>}&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="automaton/state">
- <xsl:call-template name="output-node">
- <xsl:with-param name="number" select="@number"/>
- <xsl:with-param name="label">
- <xsl:apply-templates select="itemset/item"/>
- </xsl:with-param>
- </xsl:call-template>
- <xsl:apply-templates select="actions/transitions"/>
- <xsl:apply-templates select="actions/reductions">
- <xsl:with-param name="staten">
- <xsl:value-of select="@number"/>
- </xsl:with-param>
- </xsl:apply-templates>
-</xsl:template>
-
-<xsl:template match="actions/reductions">
- <xsl:param name="staten"/>
- <xsl:for-each select='reduction'>
- <!-- These variables are needed because the current context can't be
- refered to directly in XPath expressions. -->
- <xsl:variable name="rul">
- <xsl:value-of select="@rule"/>
- </xsl:variable>
- <xsl:variable name="ena">
- <xsl:value-of select="@enabled"/>
- </xsl:variable>
- <!-- The foreach's body is protected by this, so that we are actually
- going to iterate once per reduction rule, and not per lookahead. -->
- <xsl:if test='not(preceding-sibling::*[@rule=$rul and @enabled=$ena])'>
- <xsl:variable name="rule">
- <xsl:choose>
- <!-- The acceptation state is refered to as 'accept' in the XML, but
- just as '0' in the DOT. -->
- <xsl:when test="@rule='accept'">
- <xsl:text>0</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@rule"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <!-- The edge's beginning -->
- <xsl:call-template name="reduction-edge-start">
- <xsl:with-param name="state" select="$staten"/>
- <xsl:with-param name="rule" select="$rule"/>
- <xsl:with-param name="enabled" select="@enabled"/>
- </xsl:call-template>
-
- <!-- The edge's tokens -->
- <!-- Don't show labels for the default action. In other cases, there will
- always be at least one token, so 'label="[]"' will not occur. -->
- <xsl:if test='$rule!=0 and not(../reduction[@enabled=$ena and @rule=$rule and @symbol="$default"])'>
- <xsl:text>label="[</xsl:text>
- <xsl:for-each select='../reduction[@enabled=$ena and @rule=$rule]'>
- <xsl:call-template name="escape">
- <xsl:with-param name="subject" select="@symbol"/>
- </xsl:call-template>
- <xsl:if test="position() != last ()">
- <xsl:text>, </xsl:text>
- </xsl:if>
- </xsl:for-each>
- <xsl:text>]", </xsl:text>
- </xsl:if>
-
- <!-- The edge's end -->
- <xsl:text>style=solid]&#10;</xsl:text>
-
- <!-- The diamond representing the reduction -->
- <xsl:call-template name="reduction-node">
- <xsl:with-param name="state" select="$staten"/>
- <xsl:with-param name="rule" select="$rule"/>
- <xsl:with-param name="color">
- <xsl:choose>
- <xsl:when test='@enabled="true"'>
- <xsl:text>3</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>5</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:if>
- </xsl:for-each>
-</xsl:template>
-
-<xsl:template match="actions/transitions">
- <xsl:apply-templates select="transition"/>
-</xsl:template>
-
-<xsl:template match="item">
- <xsl:param name="prev-rule-number"
- select="preceding-sibling::item[1]/@rule-number"/>
- <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)">
- <xsl:with-param name="point" select="@point"/>
- <xsl:with-param name="num" select="@rule-number"/>
- <xsl:with-param name="prev-lhs"
- select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
- />
- </xsl:apply-templates>
- <xsl:apply-templates select="lookaheads"/>
-</xsl:template>
-
-<xsl:template match="rule">
- <xsl:param name="point"/>
- <xsl:param name="num"/>
- <xsl:param name="prev-lhs"/>
- <xsl:text>&#10;</xsl:text>
- <xsl:choose>
- <xsl:when test="$num &lt; 10">
- <xsl:text> </xsl:text>
- </xsl:when>
- <xsl:when test="$num &lt; 100">
- <xsl:text> </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text></xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:value-of select="$num"/>
- <xsl:text> </xsl:text>
- <xsl:choose>
- <xsl:when test="$prev-lhs = lhs[text()]">
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="'|'"/>
- <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="lhs"/>
- <xsl:text>:</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="$point = 0">
- <xsl:text> .</xsl:text>
- </xsl:if>
- <xsl:for-each select="rhs/symbol|rhs/empty">
- <xsl:apply-templates select="."/>
- <xsl:if test="$point = position()">
- <xsl:text> .</xsl:text>
- </xsl:if>
- </xsl:for-each>
-</xsl:template>
-
-<xsl:template match="symbol">
- <xsl:text> </xsl:text>
- <xsl:value-of select="."/>
-</xsl:template>
-
-<xsl:template match="empty"/>
-
-<xsl:template match="lookaheads">
- <xsl:text> [</xsl:text>
- <xsl:apply-templates select="symbol"/>
- <xsl:text>]</xsl:text>
-</xsl:template>
-
-<xsl:template match="lookaheads/symbol">
- <xsl:value-of select="."/>
- <xsl:if test="position() != last()">
- <xsl:text>, </xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template name="reduction-edge-start">
- <xsl:param name="state"/>
- <xsl:param name="rule"/>
- <xsl:param name="enabled"/>
-
- <xsl:text> </xsl:text>
- <xsl:value-of select="$state"/>
- <xsl:text> -> "</xsl:text>
- <xsl:value-of select="$state"/>
- <xsl:text>R</xsl:text>
- <xsl:value-of select="$rule"/>
- <xsl:if test='$enabled = "false"'>
- <xsl:text>d</xsl:text>
- </xsl:if>
- <xsl:text>" [</xsl:text>
-</xsl:template>
-
-<xsl:template name="reduction-node">
- <xsl:param name="state"/>
- <xsl:param name="rule"/>
- <xsl:param name="color"/>
-
- <xsl:text> "</xsl:text>
- <xsl:value-of select="$state"/>
- <xsl:text>R</xsl:text>
- <xsl:value-of select="$rule"/>
- <xsl:if test="$color = 5">
- <xsl:text>d</xsl:text>
- </xsl:if>
- <xsl:text>" [label="</xsl:text>
- <xsl:choose>
- <xsl:when test="$rule = 0">
- <xsl:text>Acc", fillcolor=1</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>R</xsl:text>
- <xsl:value-of select="$rule"/>
- <xsl:text>", fillcolor=</xsl:text>
- <xsl:value-of select="$color"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:text>, shape=diamond, style=filled]&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="transition">
- <xsl:call-template name="output-edge">
- <xsl:with-param name="src" select="../../../@number"/>
- <xsl:with-param name="dst" select="@state"/>
- <xsl:with-param name="style">
- <xsl:choose>
- <xsl:when test="@symbol = 'error'">
- <xsl:text>dotted</xsl:text>
- </xsl:when>
- <xsl:when test="@type = 'shift'">
- <xsl:text>solid</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>dashed</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:with-param>
- <xsl:with-param name="label">
- <xsl:if test="not(@symbol = 'error')">
- <xsl:value-of select="@symbol"/>
- </xsl:if>
- </xsl:with-param>
- </xsl:call-template>
-</xsl:template>
-
-<xsl:template name="output-node">
- <xsl:param name="number"/>
- <xsl:param name="label"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="$number"/>
- <xsl:text> [label="</xsl:text>
- <xsl:text>State </xsl:text>
- <xsl:value-of select="$number"/>
- <xsl:text>\n</xsl:text>
- <xsl:call-template name="escape">
- <xsl:with-param name="subject" select="$label"/>
- </xsl:call-template>
- <xsl:text>\l"]&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template name="output-edge">
- <xsl:param name="src"/>
- <xsl:param name="dst"/>
- <xsl:param name="style"/>
- <xsl:param name="label"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="$src"/>
- <xsl:text> -> </xsl:text>
- <xsl:value-of select="$dst"/>
- <xsl:text> [style=</xsl:text>
- <xsl:value-of select="$style"/>
- <xsl:if test="$label and $label != ''">
- <xsl:text> label="</xsl:text>
- <xsl:call-template name="escape">
- <xsl:with-param name="subject" select="$label"/>
- </xsl:call-template>
- <xsl:text>"</xsl:text>
- </xsl:if>
- <xsl:text>]&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template name="escape">
- <xsl:param name="subject"/> <!-- required -->
- <xsl:call-template name="string-replace">
- <xsl:with-param name="subject">
- <xsl:call-template name="string-replace">
- <xsl:with-param name="subject">
- <xsl:call-template name="string-replace">
- <xsl:with-param name="subject" select="$subject"/>
- <xsl:with-param name="search" select="'\'"/>
- <xsl:with-param name="replace" select="'\\'"/>
- </xsl:call-template>
- </xsl:with-param>
- <xsl:with-param name="search" select="'&quot;'"/>
- <xsl:with-param name="replace" select="'\&quot;'"/>
- </xsl:call-template>
- </xsl:with-param>
- <xsl:with-param name="search" select="'&#10;'"/>
- <xsl:with-param name="replace" select="'\l'"/>
- </xsl:call-template>
-</xsl:template>
-
-<xsl:template name="string-replace">
- <xsl:param name="subject"/>
- <xsl:param name="search"/>
- <xsl:param name="replace"/>
- <xsl:choose>
- <xsl:when test="contains($subject, $search)">
- <xsl:variable name="before" select="substring-before($subject, $search)"/>
- <xsl:variable name="after" select="substring-after($subject, $search)"/>
- <xsl:value-of select="$before"/>
- <xsl:value-of select="$replace"/>
- <xsl:call-template name="string-replace">
- <xsl:with-param name="subject" select="$after"/>
- <xsl:with-param name="search" select="$search"/>
- <xsl:with-param name="replace" select="$replace"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$subject"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="lpad">
- <xsl:param name="str" select="''"/>
- <xsl:param name="pad" select="0"/>
- <xsl:variable name="diff" select="$pad - string-length($str)" />
- <xsl:choose>
- <xsl:when test="$diff &lt; 0">
- <xsl:value-of select="$str"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$diff"/>
- </xsl:call-template>
- <xsl:value-of select="$str"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-</xsl:stylesheet>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ xml2dot.xsl - transform Bison XML Report into DOT.
+
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Written by Wojciech Polak <polak@gnu.org>.
+ -->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:bison="http://www.gnu.org/software/bison/">
+
+<xsl:import href="bison.xsl"/>
+<xsl:output method="text" encoding="UTF-8" indent="no"/>
+
+<xsl:template match="/">
+ <xsl:apply-templates select="bison-xml-report"/>
+</xsl:template>
+
+<xsl:template match="bison-xml-report">
+ <xsl:text>// Generated by GNU Bison </xsl:text>
+ <xsl:value-of select="@version"/>
+ <xsl:text>.&#10;</xsl:text>
+ <xsl:text>// Report bugs to &lt;</xsl:text>
+ <xsl:value-of select="@bug-report"/>
+ <xsl:text>&gt;.&#10;</xsl:text>
+ <xsl:text>// Home page: &lt;</xsl:text>
+ <xsl:value-of select="@url"/>
+ <xsl:text>&gt;.&#10;&#10;</xsl:text>
+ <xsl:apply-templates select="automaton">
+ <xsl:with-param name="filename" select="filename"/>
+ </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="automaton">
+ <xsl:param name="filename"/>
+ <xsl:text>digraph "</xsl:text>
+ <xsl:call-template name="escape">
+ <xsl:with-param name="subject" select="$filename"/>
+ </xsl:call-template>
+ <xsl:text>"&#10;{
+ node [fontname = courier, shape = box, colorscheme = paired6]
+ edge [fontname = courier]
+
+</xsl:text>
+ <xsl:apply-templates select="state"/>
+ <xsl:text>}&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="automaton/state">
+ <xsl:call-template name="output-node">
+ <xsl:with-param name="number" select="@number"/>
+ <xsl:with-param name="label">
+ <xsl:apply-templates select="itemset/item"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ <xsl:apply-templates select="actions/transitions"/>
+ <xsl:apply-templates select="actions/reductions">
+ <xsl:with-param name="staten">
+ <xsl:value-of select="@number"/>
+ </xsl:with-param>
+ </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="actions/reductions">
+ <xsl:param name="staten"/>
+ <xsl:for-each select='reduction'>
+ <!-- These variables are needed because the current context can't be
+ refered to directly in XPath expressions. -->
+ <xsl:variable name="rul">
+ <xsl:value-of select="@rule"/>
+ </xsl:variable>
+ <xsl:variable name="ena">
+ <xsl:value-of select="@enabled"/>
+ </xsl:variable>
+ <!-- The foreach's body is protected by this, so that we are actually
+ going to iterate once per reduction rule, and not per lookahead. -->
+ <xsl:if test='not(preceding-sibling::*[@rule=$rul and @enabled=$ena])'>
+ <xsl:variable name="rule">
+ <xsl:choose>
+ <!-- The acceptation state is refered to as 'accept' in the XML, but
+ just as '0' in the DOT. -->
+ <xsl:when test="@rule='accept'">
+ <xsl:text>0</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@rule"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- The edge's beginning -->
+ <xsl:call-template name="reduction-edge-start">
+ <xsl:with-param name="state" select="$staten"/>
+ <xsl:with-param name="rule" select="$rule"/>
+ <xsl:with-param name="enabled" select="@enabled"/>
+ </xsl:call-template>
+
+ <!-- The edge's tokens -->
+ <!-- Don't show labels for the default action. In other cases, there will
+ always be at least one token, so 'label="[]"' will not occur. -->
+ <xsl:if test='$rule!=0 and not(../reduction[@enabled=$ena and @rule=$rule and @symbol="$default"])'>
+ <xsl:text>label="[</xsl:text>
+ <xsl:for-each select='../reduction[@enabled=$ena and @rule=$rule]'>
+ <xsl:call-template name="escape">
+ <xsl:with-param name="subject" select="@symbol"/>
+ </xsl:call-template>
+ <xsl:if test="position() != last ()">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:text>]", </xsl:text>
+ </xsl:if>
+
+ <!-- The edge's end -->
+ <xsl:text>style=solid]&#10;</xsl:text>
+
+ <!-- The diamond representing the reduction -->
+ <xsl:call-template name="reduction-node">
+ <xsl:with-param name="state" select="$staten"/>
+ <xsl:with-param name="rule" select="$rule"/>
+ <xsl:with-param name="color">
+ <xsl:choose>
+ <xsl:when test='@enabled="true"'>
+ <xsl:text>3</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>5</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="actions/transitions">
+ <xsl:apply-templates select="transition"/>
+</xsl:template>
+
+<xsl:template match="item">
+ <xsl:param name="prev-rule-number"
+ select="preceding-sibling::item[1]/@rule-number"/>
+ <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)">
+ <xsl:with-param name="point" select="@point"/>
+ <xsl:with-param name="num" select="@rule-number"/>
+ <xsl:with-param name="prev-lhs"
+ select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
+ />
+ </xsl:apply-templates>
+ <xsl:apply-templates select="lookaheads"/>
+</xsl:template>
+
+<xsl:template match="rule">
+ <xsl:param name="point"/>
+ <xsl:param name="num"/>
+ <xsl:param name="prev-lhs"/>
+ <xsl:text>&#10;</xsl:text>
+ <xsl:choose>
+ <xsl:when test="$num &lt; 10">
+ <xsl:text> </xsl:text>
+ </xsl:when>
+ <xsl:when test="$num &lt; 100">
+ <xsl:text> </xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text></xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:value-of select="$num"/>
+ <xsl:text> </xsl:text>
+ <xsl:choose>
+ <xsl:when test="$prev-lhs = lhs[text()]">
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="'|'"/>
+ <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="lhs"/>
+ <xsl:text>:</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:if test="$point = 0">
+ <xsl:text> .</xsl:text>
+ </xsl:if>
+ <xsl:for-each select="rhs/symbol|rhs/empty">
+ <xsl:apply-templates select="."/>
+ <xsl:if test="$point = position()">
+ <xsl:text> .</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="symbol">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="."/>
+</xsl:template>
+
+<xsl:template match="empty"/>
+
+<xsl:template match="lookaheads">
+ <xsl:text> [</xsl:text>
+ <xsl:apply-templates select="symbol"/>
+ <xsl:text>]</xsl:text>
+</xsl:template>
+
+<xsl:template match="lookaheads/symbol">
+ <xsl:value-of select="."/>
+ <xsl:if test="position() != last()">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="reduction-edge-start">
+ <xsl:param name="state"/>
+ <xsl:param name="rule"/>
+ <xsl:param name="enabled"/>
+
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$state"/>
+ <xsl:text> -> "</xsl:text>
+ <xsl:value-of select="$state"/>
+ <xsl:text>R</xsl:text>
+ <xsl:value-of select="$rule"/>
+ <xsl:if test='$enabled = "false"'>
+ <xsl:text>d</xsl:text>
+ </xsl:if>
+ <xsl:text>" [</xsl:text>
+</xsl:template>
+
+<xsl:template name="reduction-node">
+ <xsl:param name="state"/>
+ <xsl:param name="rule"/>
+ <xsl:param name="color"/>
+
+ <xsl:text> "</xsl:text>
+ <xsl:value-of select="$state"/>
+ <xsl:text>R</xsl:text>
+ <xsl:value-of select="$rule"/>
+ <xsl:if test="$color = 5">
+ <xsl:text>d</xsl:text>
+ </xsl:if>
+ <xsl:text>" [label="</xsl:text>
+ <xsl:choose>
+ <xsl:when test="$rule = 0">
+ <xsl:text>Acc", fillcolor=1</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>R</xsl:text>
+ <xsl:value-of select="$rule"/>
+ <xsl:text>", fillcolor=</xsl:text>
+ <xsl:value-of select="$color"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text>, shape=diamond, style=filled]&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="transition">
+ <xsl:call-template name="output-edge">
+ <xsl:with-param name="src" select="../../../@number"/>
+ <xsl:with-param name="dst" select="@state"/>
+ <xsl:with-param name="style">
+ <xsl:choose>
+ <xsl:when test="@symbol = 'error'">
+ <xsl:text>dotted</xsl:text>
+ </xsl:when>
+ <xsl:when test="@type = 'shift'">
+ <xsl:text>solid</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>dashed</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ <xsl:with-param name="label">
+ <xsl:if test="not(@symbol = 'error')">
+ <xsl:value-of select="@symbol"/>
+ </xsl:if>
+ </xsl:with-param>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="output-node">
+ <xsl:param name="number"/>
+ <xsl:param name="label"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$number"/>
+ <xsl:text> [label="</xsl:text>
+ <xsl:text>State </xsl:text>
+ <xsl:value-of select="$number"/>
+ <xsl:text>\n</xsl:text>
+ <xsl:call-template name="escape">
+ <xsl:with-param name="subject" select="$label"/>
+ </xsl:call-template>
+ <xsl:text>\l"]&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template name="output-edge">
+ <xsl:param name="src"/>
+ <xsl:param name="dst"/>
+ <xsl:param name="style"/>
+ <xsl:param name="label"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$src"/>
+ <xsl:text> -> </xsl:text>
+ <xsl:value-of select="$dst"/>
+ <xsl:text> [style=</xsl:text>
+ <xsl:value-of select="$style"/>
+ <xsl:if test="$label and $label != ''">
+ <xsl:text> label="</xsl:text>
+ <xsl:call-template name="escape">
+ <xsl:with-param name="subject" select="$label"/>
+ </xsl:call-template>
+ <xsl:text>"</xsl:text>
+ </xsl:if>
+ <xsl:text>]&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template name="escape">
+ <xsl:param name="subject"/> <!-- required -->
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject">
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject">
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject" select="$subject"/>
+ <xsl:with-param name="search" select="'\'"/>
+ <xsl:with-param name="replace" select="'\\'"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ <xsl:with-param name="search" select="'&quot;'"/>
+ <xsl:with-param name="replace" select="'\&quot;'"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ <xsl:with-param name="search" select="'&#10;'"/>
+ <xsl:with-param name="replace" select="'\l'"/>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="string-replace">
+ <xsl:param name="subject"/>
+ <xsl:param name="search"/>
+ <xsl:param name="replace"/>
+ <xsl:choose>
+ <xsl:when test="contains($subject, $search)">
+ <xsl:variable name="before" select="substring-before($subject, $search)"/>
+ <xsl:variable name="after" select="substring-after($subject, $search)"/>
+ <xsl:value-of select="$before"/>
+ <xsl:value-of select="$replace"/>
+ <xsl:call-template name="string-replace">
+ <xsl:with-param name="subject" select="$after"/>
+ <xsl:with-param name="search" select="$search"/>
+ <xsl:with-param name="replace" select="$replace"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$subject"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="lpad">
+ <xsl:param name="str" select="''"/>
+ <xsl:param name="pad" select="0"/>
+ <xsl:variable name="diff" select="$pad - string-length($str)" />
+ <xsl:choose>
+ <xsl:when test="$diff &lt; 0">
+ <xsl:value-of select="$str"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="space">
+ <xsl:with-param name="repeat" select="$diff"/>
+ </xsl:call-template>
+ <xsl:value-of select="$str"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/contrib/tools/bison/bison/data/xslt/xml2text.xsl b/contrib/tools/bison/bison/data/xslt/xml2text.xsl
index 2626f566b1..34fc8e8b6e 100644
--- a/contrib/tools/bison/bison/data/xslt/xml2text.xsl
+++ b/contrib/tools/bison/bison/data/xslt/xml2text.xsl
@@ -1,569 +1,569 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- xml2text.xsl - transform Bison XML Report into plain text.
-
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- Written by Wojciech Polak <polak@gnu.org>.
- -->
-
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:bison="http://www.gnu.org/software/bison/">
-
-<xsl:import href="bison.xsl"/>
-<xsl:output method="text" encoding="UTF-8" indent="no"/>
-
-<xsl:template match="/">
- <xsl:apply-templates select="bison-xml-report"/>
-</xsl:template>
-
-<xsl:template match="bison-xml-report">
- <xsl:apply-templates select="grammar" mode="reductions"/>
- <xsl:apply-templates select="grammar" mode="useless-in-parser"/>
- <xsl:apply-templates select="automaton" mode="conflicts"/>
- <xsl:apply-templates select="grammar"/>
- <xsl:apply-templates select="automaton"/>
-</xsl:template>
-
-<xsl:template match="grammar" mode="reductions">
- <xsl:apply-templates select="nonterminals" mode="useless-in-grammar"/>
- <xsl:apply-templates select="terminals" mode="unused-in-grammar"/>
- <xsl:apply-templates select="rules" mode="useless-in-grammar"/>
-</xsl:template>
-
-<xsl:template match="nonterminals" mode="useless-in-grammar">
- <xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
- <xsl:text>Nonterminals useless in grammar&#10;&#10;</xsl:text>
- <xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
- <xsl:text> </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>&#10;</xsl:text>
- </xsl:for-each>
- <xsl:text>&#10;&#10;</xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="terminals" mode="unused-in-grammar">
- <xsl:if test="terminal[@usefulness='unused-in-grammar']">
- <xsl:text>Terminals unused in grammar&#10;&#10;</xsl:text>
- <xsl:for-each select="terminal[@usefulness='unused-in-grammar']">
- <xsl:sort select="@symbol-number" data-type="number"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>&#10;</xsl:text>
- </xsl:for-each>
- <xsl:text>&#10;&#10;</xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="rules" mode="useless-in-grammar">
- <xsl:variable name="set" select="rule[@usefulness='useless-in-grammar']"/>
- <xsl:if test="$set">
- <xsl:text>Rules useless in grammar&#10;</xsl:text>
- <xsl:call-template name="style-rule-set">
- <xsl:with-param name="rule-set" select="$set"/>
- </xsl:call-template>
- <xsl:text>&#10;&#10;</xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="grammar" mode="useless-in-parser">
- <xsl:variable
- name="set" select="rules/rule[@usefulness='useless-in-parser']"
- />
- <xsl:if test="$set">
- <xsl:text>Rules useless in parser due to conflicts&#10;</xsl:text>
- <xsl:call-template name="style-rule-set">
- <xsl:with-param name="rule-set" select="$set"/>
- </xsl:call-template>
- <xsl:text>&#10;&#10;</xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="grammar">
- <xsl:text>Grammar&#10;</xsl:text>
- <xsl:call-template name="style-rule-set">
- <xsl:with-param
- name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
- />
- </xsl:call-template>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:apply-templates select="terminals"/>
- <xsl:apply-templates select="nonterminals"/>
-</xsl:template>
-
-<xsl:template name="style-rule-set">
- <xsl:param name="rule-set"/>
- <xsl:for-each select="$rule-set">
- <xsl:apply-templates select=".">
- <xsl:with-param name="pad" select="'3'"/>
- <xsl:with-param name="prev-lhs">
- <xsl:if test="position()>1">
- <xsl:variable name="position" select="position()"/>
- <xsl:value-of select="$rule-set[$position - 1]/lhs"/>
- </xsl:if>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:for-each>
-</xsl:template>
-
-<xsl:template match="grammar/terminals">
- <xsl:text>Terminals, with rules where they appear&#10;&#10;</xsl:text>
- <xsl:apply-templates select="terminal"/>
- <xsl:text>&#10;&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="grammar/nonterminals">
- <xsl:text>Nonterminals, with rules where they appear&#10;&#10;</xsl:text>
- <xsl:apply-templates select="nonterminal[@usefulness!='useless-in-grammar']"/>
-</xsl:template>
-
-<xsl:template match="terminal">
- <xsl:value-of select="@name"/>
- <xsl:call-template name="line-wrap">
- <xsl:with-param name="first-line-length">
- <xsl:choose>
- <xsl:when test="string-length(@name) &gt; 66">0</xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="66 - string-length(@name)" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:with-param>
- <xsl:with-param name="line-length" select="66" />
- <xsl:with-param name="text">
- <xsl:value-of select="concat(' (', @token-number, ')')"/>
- <xsl:for-each select="key('bison:ruleByRhs', @name)">
- <xsl:value-of select="concat(' ', @number)"/>
- </xsl:for-each>
- </xsl:with-param>
- </xsl:call-template>
-</xsl:template>
-
-<xsl:template match="nonterminal">
- <xsl:value-of select="@name"/>
- <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
- <xsl:text>&#10;</xsl:text>
- <xsl:variable name="output">
- <xsl:call-template name="line-wrap">
- <xsl:with-param name="line-length" select="66" />
- <xsl:with-param name="text">
- <xsl:text> </xsl:text>
- <xsl:if test="key('bison:ruleByLhs', @name)">
- <xsl:text>on@left:</xsl:text>
- <xsl:for-each select="key('bison:ruleByLhs', @name)">
- <xsl:value-of select="concat(' ', @number)"/>
- </xsl:for-each>
- </xsl:if>
- <xsl:if test="key('bison:ruleByRhs', @name)">
- <xsl:if test="key('bison:ruleByLhs', @name)">
- <xsl:text>, </xsl:text>
- </xsl:if>
- <xsl:text>on@right:</xsl:text>
- <xsl:for-each select="key('bison:ruleByRhs', @name)">
- <xsl:value-of select="concat(' ', @number)"/>
- </xsl:for-each>
- </xsl:if>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:variable>
- <xsl:value-of select="translate($output, '@', ' ')" />
-</xsl:template>
-
-<xsl:template match="automaton" mode="conflicts">
- <xsl:variable name="conflict-report">
- <xsl:apply-templates select="state" mode="conflicts"/>
- </xsl:variable>
- <xsl:if test="string-length($conflict-report) != 0">
- <xsl:value-of select="$conflict-report"/>
- <xsl:text>&#10;&#10;</xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="state" mode="conflicts">
- <xsl:variable name="conflict-counts">
- <xsl:apply-templates select="." mode="bison:count-conflicts" />
- </xsl:variable>
- <xsl:variable
- name="sr-count" select="substring-before($conflict-counts, ',')"
- />
- <xsl:variable
- name="rr-count" select="substring-after($conflict-counts, ',')"
- />
- <xsl:if test="$sr-count > 0 or $rr-count > 0">
- <xsl:value-of select="concat('State ', @number, ' conflicts:')"/>
- <xsl:if test="$sr-count > 0">
- <xsl:value-of select="concat(' ', $sr-count, ' shift/reduce')"/>
- <xsl:if test="$rr-count > 0">
- <xsl:value-of select="(',')"/>
- </xsl:if>
- </xsl:if>
- <xsl:if test="$rr-count > 0">
- <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
- </xsl:if>
- <xsl:value-of select="'&#10;'"/>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="automaton">
- <xsl:apply-templates select="state">
- <xsl:with-param name="pad" select="'3'"/>
- </xsl:apply-templates>
-</xsl:template>
-
-<xsl:template match="automaton/state">
- <xsl:param name="pad"/>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:text>State </xsl:text>
- <xsl:value-of select="@number"/>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:apply-templates select="itemset/item">
- <xsl:with-param name="pad" select="$pad"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="actions/transitions">
- <xsl:with-param name="type" select="'shift'"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="actions/errors"/>
- <xsl:apply-templates select="actions/reductions"/>
- <xsl:apply-templates select="actions/transitions">
- <xsl:with-param name="type" select="'goto'"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="solved-conflicts"/>
-</xsl:template>
-
-<xsl:template match="actions/transitions">
- <xsl:param name="type"/>
- <xsl:if test="transition[@type = $type]">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="transition[@type = $type]">
- <xsl:with-param name="pad">
- <xsl:call-template name="max-width-symbol">
- <xsl:with-param name="node" select="transition[@type = $type]"/>
- </xsl:call-template>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="actions/errors">
- <xsl:if test="error">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="error">
- <xsl:with-param name="pad">
- <xsl:call-template name="max-width-symbol">
- <xsl:with-param name="node" select="error"/>
- </xsl:call-template>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="actions/reductions">
- <xsl:if test="reduction">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="reduction">
- <xsl:with-param name="pad">
- <xsl:call-template name="max-width-symbol">
- <xsl:with-param name="node" select="reduction"/>
- </xsl:call-template>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="item">
- <xsl:param name="pad"/>
- <xsl:param name="prev-rule-number"
- select="preceding-sibling::item[1]/@rule-number"/>
- <xsl:apply-templates
- select="key('bison:ruleByNumber', current()/@rule-number)"
- >
- <xsl:with-param name="itemset" select="'true'"/>
- <xsl:with-param name="pad" select="$pad"/>
- <xsl:with-param
- name="prev-lhs"
- select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
- />
- <xsl:with-param name="point" select="@point"/>
- <xsl:with-param name="lookaheads">
- <xsl:apply-templates select="lookaheads"/>
- </xsl:with-param>
- </xsl:apply-templates>
-</xsl:template>
-
-<xsl:template match="rule">
- <xsl:param name="itemset"/>
- <xsl:param name="pad"/>
- <xsl:param name="prev-lhs"/>
- <xsl:param name="point"/>
- <xsl:param name="lookaheads"/>
-
- <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
- <xsl:text>&#10;</xsl:text>
- </xsl:if>
-
- <xsl:text> </xsl:text>
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="string(@number)"/>
- <xsl:with-param name="pad" select="number($pad)"/>
- </xsl:call-template>
- <xsl:text> </xsl:text>
-
- <!-- LHS -->
- <xsl:choose>
- <xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]">
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="'|'"/>
- <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="'|'"/>
- <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="lhs"/>
- <xsl:text>:</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
-
- <!-- RHS -->
- <xsl:for-each select="rhs/*">
- <xsl:if test="position() = $point + 1">
- <xsl:text> .</xsl:text>
- </xsl:if>
- <xsl:if test="$itemset = 'true' and name(.) != 'empty'">
- <xsl:apply-templates select="."/>
- </xsl:if>
- <xsl:if test="$itemset != 'true'">
- <xsl:apply-templates select="."/>
- </xsl:if>
- <xsl:if test="position() = last() and position() = $point">
- <xsl:text> .</xsl:text>
- </xsl:if>
- </xsl:for-each>
- <xsl:if test="$lookaheads">
- <xsl:value-of select="$lookaheads"/>
- </xsl:if>
-
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="symbol">
- <xsl:text> </xsl:text>
- <xsl:value-of select="."/>
-</xsl:template>
-
-<xsl:template match="empty">
- <xsl:text> %empty</xsl:text>
-</xsl:template>
-
-<xsl:template match="lookaheads">
- <xsl:text> [</xsl:text>
- <xsl:apply-templates select="symbol"/>
- <xsl:text>]</xsl:text>
-</xsl:template>
-
-<xsl:template match="lookaheads/symbol">
- <xsl:value-of select="."/>
- <xsl:if test="position() != last()">
- <xsl:text>, </xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="transition">
- <xsl:param name="pad"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="rpad">
- <xsl:with-param name="str" select="string(@symbol)"/>
- <xsl:with-param name="pad" select="number($pad) + 2"/>
- </xsl:call-template>
- <xsl:choose>
- <xsl:when test="@type = 'shift'">
- <xsl:text>shift, and go to state </xsl:text>
- <xsl:value-of select="@state"/>
- </xsl:when>
- <xsl:when test="@type = 'goto'">
- <xsl:text>go to state </xsl:text>
- <xsl:value-of select="@state"/>
- </xsl:when>
- </xsl:choose>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="error">
- <xsl:param name="pad"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="rpad">
- <xsl:with-param name="str" select="string(@symbol)"/>
- <xsl:with-param name="pad" select="number($pad) + 2"/>
- </xsl:call-template>
- <xsl:text>error</xsl:text>
- <xsl:text> (</xsl:text>
- <xsl:value-of select="text()"/>
- <xsl:text>)</xsl:text>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="reduction">
- <xsl:param name="pad"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="rpad">
- <xsl:with-param name="str" select="string(@symbol)"/>
- <xsl:with-param name="pad" select="number($pad) + 2"/>
- </xsl:call-template>
- <xsl:if test="@enabled = 'false'">
- <xsl:text>[</xsl:text>
- </xsl:if>
- <xsl:choose>
- <xsl:when test="@rule = 'accept'">
- <xsl:text>accept</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>reduce using rule </xsl:text>
- <xsl:value-of select="@rule"/>
- <xsl:text> (</xsl:text>
- <xsl:value-of
- select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/>
- <xsl:text>)</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="@enabled = 'false'">
- <xsl:text>]</xsl:text>
- </xsl:if>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="solved-conflicts">
- <xsl:if test="resolution">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="resolution"/>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="resolution">
- <xsl:text> Conflict between rule </xsl:text>
- <xsl:value-of select="@rule"/>
- <xsl:text> and token </xsl:text>
- <xsl:value-of select="@symbol"/>
- <xsl:text> resolved as </xsl:text>
- <xsl:if test="@type = 'error'">
- <xsl:text>an </xsl:text>
- </xsl:if>
- <xsl:value-of select="@type"/>
- <xsl:text> (</xsl:text>
- <xsl:value-of select="."/>
- <xsl:text>).&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template name="max-width-symbol">
- <xsl:param name="node"/>
- <xsl:variable name="longest">
- <xsl:for-each select="$node">
- <xsl:sort data-type="number" select="string-length(@symbol)"
- order="descending"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="string-length(@symbol)"/>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
- <xsl:value-of select="$longest"/>
-</xsl:template>
-
-<xsl:template name="lpad">
- <xsl:param name="str" select="''"/>
- <xsl:param name="pad" select="0"/>
- <xsl:variable name="diff" select="$pad - string-length($str)" />
- <xsl:choose>
- <xsl:when test="$diff &lt; 0">
- <xsl:value-of select="$str"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$diff"/>
- </xsl:call-template>
- <xsl:value-of select="$str"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="rpad">
- <xsl:param name="str" select="''"/>
- <xsl:param name="pad" select="0"/>
- <xsl:variable name="diff" select="$pad - string-length($str)"/>
- <xsl:choose>
- <xsl:when test="$diff &lt; 0">
- <xsl:value-of select="$str"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$str"/>
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$diff"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="line-wrap">
- <xsl:param name="line-length"/> <!-- required -->
- <xsl:param name="first-line-length" select="$line-length"/>
- <xsl:param name="text"/> <!-- required -->
- <xsl:choose>
- <xsl:when test="normalize-space($text) = ''" />
- <xsl:when test="string-length($text) &lt;= $first-line-length">
- <xsl:value-of select="concat($text, '&#10;')" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="break-pos">
- <xsl:call-template name="ws-search">
- <xsl:with-param name="text" select="$text" />
- <xsl:with-param name="start" select="$first-line-length+1" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:value-of select="substring($text, 1, $break-pos - 1)" />
- <xsl:text>&#10;</xsl:text>
- <xsl:call-template name="line-wrap">
- <xsl:with-param name="line-length" select="$line-length" />
- <xsl:with-param
- name="text" select="concat(' ', substring($text, $break-pos+1))"
- />
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="ws-search">
- <xsl:param name="text"/> <!-- required -->
- <xsl:param name="start"/> <!-- required -->
- <xsl:variable name="search-text" select="substring($text, $start)" />
- <xsl:choose>
- <xsl:when test="not(contains($search-text, ' '))">
- <xsl:value-of select="string-length($text)+1" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of
- select="$start + string-length(substring-before($search-text, ' '))"
- />
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-</xsl:stylesheet>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ xml2text.xsl - transform Bison XML Report into plain text.
+
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Written by Wojciech Polak <polak@gnu.org>.
+ -->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:bison="http://www.gnu.org/software/bison/">
+
+<xsl:import href="bison.xsl"/>
+<xsl:output method="text" encoding="UTF-8" indent="no"/>
+
+<xsl:template match="/">
+ <xsl:apply-templates select="bison-xml-report"/>
+</xsl:template>
+
+<xsl:template match="bison-xml-report">
+ <xsl:apply-templates select="grammar" mode="reductions"/>
+ <xsl:apply-templates select="grammar" mode="useless-in-parser"/>
+ <xsl:apply-templates select="automaton" mode="conflicts"/>
+ <xsl:apply-templates select="grammar"/>
+ <xsl:apply-templates select="automaton"/>
+</xsl:template>
+
+<xsl:template match="grammar" mode="reductions">
+ <xsl:apply-templates select="nonterminals" mode="useless-in-grammar"/>
+ <xsl:apply-templates select="terminals" mode="unused-in-grammar"/>
+ <xsl:apply-templates select="rules" mode="useless-in-grammar"/>
+</xsl:template>
+
+<xsl:template match="nonterminals" mode="useless-in-grammar">
+ <xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
+ <xsl:text>Nonterminals useless in grammar&#10;&#10;</xsl:text>
+ <xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>&#10;</xsl:text>
+ </xsl:for-each>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="terminals" mode="unused-in-grammar">
+ <xsl:if test="terminal[@usefulness='unused-in-grammar']">
+ <xsl:text>Terminals unused in grammar&#10;&#10;</xsl:text>
+ <xsl:for-each select="terminal[@usefulness='unused-in-grammar']">
+ <xsl:sort select="@symbol-number" data-type="number"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>&#10;</xsl:text>
+ </xsl:for-each>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="rules" mode="useless-in-grammar">
+ <xsl:variable name="set" select="rule[@usefulness='useless-in-grammar']"/>
+ <xsl:if test="$set">
+ <xsl:text>Rules useless in grammar&#10;</xsl:text>
+ <xsl:call-template name="style-rule-set">
+ <xsl:with-param name="rule-set" select="$set"/>
+ </xsl:call-template>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="grammar" mode="useless-in-parser">
+ <xsl:variable
+ name="set" select="rules/rule[@usefulness='useless-in-parser']"
+ />
+ <xsl:if test="$set">
+ <xsl:text>Rules useless in parser due to conflicts&#10;</xsl:text>
+ <xsl:call-template name="style-rule-set">
+ <xsl:with-param name="rule-set" select="$set"/>
+ </xsl:call-template>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="grammar">
+ <xsl:text>Grammar&#10;</xsl:text>
+ <xsl:call-template name="style-rule-set">
+ <xsl:with-param
+ name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
+ />
+ </xsl:call-template>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:apply-templates select="terminals"/>
+ <xsl:apply-templates select="nonterminals"/>
+</xsl:template>
+
+<xsl:template name="style-rule-set">
+ <xsl:param name="rule-set"/>
+ <xsl:for-each select="$rule-set">
+ <xsl:apply-templates select=".">
+ <xsl:with-param name="pad" select="'3'"/>
+ <xsl:with-param name="prev-lhs">
+ <xsl:if test="position()>1">
+ <xsl:variable name="position" select="position()"/>
+ <xsl:value-of select="$rule-set[$position - 1]/lhs"/>
+ </xsl:if>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="grammar/terminals">
+ <xsl:text>Terminals, with rules where they appear&#10;&#10;</xsl:text>
+ <xsl:apply-templates select="terminal"/>
+ <xsl:text>&#10;&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="grammar/nonterminals">
+ <xsl:text>Nonterminals, with rules where they appear&#10;&#10;</xsl:text>
+ <xsl:apply-templates select="nonterminal[@usefulness!='useless-in-grammar']"/>
+</xsl:template>
+
+<xsl:template match="terminal">
+ <xsl:value-of select="@name"/>
+ <xsl:call-template name="line-wrap">
+ <xsl:with-param name="first-line-length">
+ <xsl:choose>
+ <xsl:when test="string-length(@name) &gt; 66">0</xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="66 - string-length(@name)" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ <xsl:with-param name="line-length" select="66" />
+ <xsl:with-param name="text">
+ <xsl:value-of select="concat(' (', @token-number, ')')"/>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
+ </xsl:with-param>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="nonterminal">
+ <xsl:value-of select="@name"/>
+ <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
+ <xsl:text>&#10;</xsl:text>
+ <xsl:variable name="output">
+ <xsl:call-template name="line-wrap">
+ <xsl:with-param name="line-length" select="66" />
+ <xsl:with-param name="text">
+ <xsl:text> </xsl:text>
+ <xsl:if test="key('bison:ruleByLhs', @name)">
+ <xsl:text>on@left:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByLhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:if test="key('bison:ruleByRhs', @name)">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+ <xsl:text>on@right:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
+ </xsl:if>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:value-of select="translate($output, '@', ' ')" />
+</xsl:template>
+
+<xsl:template match="automaton" mode="conflicts">
+ <xsl:variable name="conflict-report">
+ <xsl:apply-templates select="state" mode="conflicts"/>
+ </xsl:variable>
+ <xsl:if test="string-length($conflict-report) != 0">
+ <xsl:value-of select="$conflict-report"/>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="state" mode="conflicts">
+ <xsl:variable name="conflict-counts">
+ <xsl:apply-templates select="." mode="bison:count-conflicts" />
+ </xsl:variable>
+ <xsl:variable
+ name="sr-count" select="substring-before($conflict-counts, ',')"
+ />
+ <xsl:variable
+ name="rr-count" select="substring-after($conflict-counts, ',')"
+ />
+ <xsl:if test="$sr-count > 0 or $rr-count > 0">
+ <xsl:value-of select="concat('State ', @number, ' conflicts:')"/>
+ <xsl:if test="$sr-count > 0">
+ <xsl:value-of select="concat(' ', $sr-count, ' shift/reduce')"/>
+ <xsl:if test="$rr-count > 0">
+ <xsl:value-of select="(',')"/>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="$rr-count > 0">
+ <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
+ </xsl:if>
+ <xsl:value-of select="'&#10;'"/>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="automaton">
+ <xsl:apply-templates select="state">
+ <xsl:with-param name="pad" select="'3'"/>
+ </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="automaton/state">
+ <xsl:param name="pad"/>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:text>State </xsl:text>
+ <xsl:value-of select="@number"/>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:apply-templates select="itemset/item">
+ <xsl:with-param name="pad" select="$pad"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="actions/transitions">
+ <xsl:with-param name="type" select="'shift'"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="actions/errors"/>
+ <xsl:apply-templates select="actions/reductions"/>
+ <xsl:apply-templates select="actions/transitions">
+ <xsl:with-param name="type" select="'goto'"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="solved-conflicts"/>
+</xsl:template>
+
+<xsl:template match="actions/transitions">
+ <xsl:param name="type"/>
+ <xsl:if test="transition[@type = $type]">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="transition[@type = $type]">
+ <xsl:with-param name="pad">
+ <xsl:call-template name="max-width-symbol">
+ <xsl:with-param name="node" select="transition[@type = $type]"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="actions/errors">
+ <xsl:if test="error">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="error">
+ <xsl:with-param name="pad">
+ <xsl:call-template name="max-width-symbol">
+ <xsl:with-param name="node" select="error"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="actions/reductions">
+ <xsl:if test="reduction">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="reduction">
+ <xsl:with-param name="pad">
+ <xsl:call-template name="max-width-symbol">
+ <xsl:with-param name="node" select="reduction"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="item">
+ <xsl:param name="pad"/>
+ <xsl:param name="prev-rule-number"
+ select="preceding-sibling::item[1]/@rule-number"/>
+ <xsl:apply-templates
+ select="key('bison:ruleByNumber', current()/@rule-number)"
+ >
+ <xsl:with-param name="itemset" select="'true'"/>
+ <xsl:with-param name="pad" select="$pad"/>
+ <xsl:with-param
+ name="prev-lhs"
+ select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
+ />
+ <xsl:with-param name="point" select="@point"/>
+ <xsl:with-param name="lookaheads">
+ <xsl:apply-templates select="lookaheads"/>
+ </xsl:with-param>
+ </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="rule">
+ <xsl:param name="itemset"/>
+ <xsl:param name="pad"/>
+ <xsl:param name="prev-lhs"/>
+ <xsl:param name="point"/>
+ <xsl:param name="lookaheads"/>
+
+ <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
+ <xsl:text>&#10;</xsl:text>
+ </xsl:if>
+
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="string(@number)"/>
+ <xsl:with-param name="pad" select="number($pad)"/>
+ </xsl:call-template>
+ <xsl:text> </xsl:text>
+
+ <!-- LHS -->
+ <xsl:choose>
+ <xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]">
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="'|'"/>
+ <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="'|'"/>
+ <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="lhs"/>
+ <xsl:text>:</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <!-- RHS -->
+ <xsl:for-each select="rhs/*">
+ <xsl:if test="position() = $point + 1">
+ <xsl:text> .</xsl:text>
+ </xsl:if>
+ <xsl:if test="$itemset = 'true' and name(.) != 'empty'">
+ <xsl:apply-templates select="."/>
+ </xsl:if>
+ <xsl:if test="$itemset != 'true'">
+ <xsl:apply-templates select="."/>
+ </xsl:if>
+ <xsl:if test="position() = last() and position() = $point">
+ <xsl:text> .</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:if test="$lookaheads">
+ <xsl:value-of select="$lookaheads"/>
+ </xsl:if>
+
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="symbol">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="."/>
+</xsl:template>
+
+<xsl:template match="empty">
+ <xsl:text> %empty</xsl:text>
+</xsl:template>
+
+<xsl:template match="lookaheads">
+ <xsl:text> [</xsl:text>
+ <xsl:apply-templates select="symbol"/>
+ <xsl:text>]</xsl:text>
+</xsl:template>
+
+<xsl:template match="lookaheads/symbol">
+ <xsl:value-of select="."/>
+ <xsl:if test="position() != last()">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="transition">
+ <xsl:param name="pad"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="rpad">
+ <xsl:with-param name="str" select="string(@symbol)"/>
+ <xsl:with-param name="pad" select="number($pad) + 2"/>
+ </xsl:call-template>
+ <xsl:choose>
+ <xsl:when test="@type = 'shift'">
+ <xsl:text>shift, and go to state </xsl:text>
+ <xsl:value-of select="@state"/>
+ </xsl:when>
+ <xsl:when test="@type = 'goto'">
+ <xsl:text>go to state </xsl:text>
+ <xsl:value-of select="@state"/>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="error">
+ <xsl:param name="pad"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="rpad">
+ <xsl:with-param name="str" select="string(@symbol)"/>
+ <xsl:with-param name="pad" select="number($pad) + 2"/>
+ </xsl:call-template>
+ <xsl:text>error</xsl:text>
+ <xsl:text> (</xsl:text>
+ <xsl:value-of select="text()"/>
+ <xsl:text>)</xsl:text>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="reduction">
+ <xsl:param name="pad"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="rpad">
+ <xsl:with-param name="str" select="string(@symbol)"/>
+ <xsl:with-param name="pad" select="number($pad) + 2"/>
+ </xsl:call-template>
+ <xsl:if test="@enabled = 'false'">
+ <xsl:text>[</xsl:text>
+ </xsl:if>
+ <xsl:choose>
+ <xsl:when test="@rule = 'accept'">
+ <xsl:text>accept</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>reduce using rule </xsl:text>
+ <xsl:value-of select="@rule"/>
+ <xsl:text> (</xsl:text>
+ <xsl:value-of
+ select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/>
+ <xsl:text>)</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:if test="@enabled = 'false'">
+ <xsl:text>]</xsl:text>
+ </xsl:if>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="solved-conflicts">
+ <xsl:if test="resolution">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="resolution"/>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="resolution">
+ <xsl:text> Conflict between rule </xsl:text>
+ <xsl:value-of select="@rule"/>
+ <xsl:text> and token </xsl:text>
+ <xsl:value-of select="@symbol"/>
+ <xsl:text> resolved as </xsl:text>
+ <xsl:if test="@type = 'error'">
+ <xsl:text>an </xsl:text>
+ </xsl:if>
+ <xsl:value-of select="@type"/>
+ <xsl:text> (</xsl:text>
+ <xsl:value-of select="."/>
+ <xsl:text>).&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template name="max-width-symbol">
+ <xsl:param name="node"/>
+ <xsl:variable name="longest">
+ <xsl:for-each select="$node">
+ <xsl:sort data-type="number" select="string-length(@symbol)"
+ order="descending"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="string-length(@symbol)"/>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:value-of select="$longest"/>
+</xsl:template>
+
+<xsl:template name="lpad">
+ <xsl:param name="str" select="''"/>
+ <xsl:param name="pad" select="0"/>
+ <xsl:variable name="diff" select="$pad - string-length($str)" />
+ <xsl:choose>
+ <xsl:when test="$diff &lt; 0">
+ <xsl:value-of select="$str"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="space">
+ <xsl:with-param name="repeat" select="$diff"/>
+ </xsl:call-template>
+ <xsl:value-of select="$str"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="rpad">
+ <xsl:param name="str" select="''"/>
+ <xsl:param name="pad" select="0"/>
+ <xsl:variable name="diff" select="$pad - string-length($str)"/>
+ <xsl:choose>
+ <xsl:when test="$diff &lt; 0">
+ <xsl:value-of select="$str"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$str"/>
+ <xsl:call-template name="space">
+ <xsl:with-param name="repeat" select="$diff"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="line-wrap">
+ <xsl:param name="line-length"/> <!-- required -->
+ <xsl:param name="first-line-length" select="$line-length"/>
+ <xsl:param name="text"/> <!-- required -->
+ <xsl:choose>
+ <xsl:when test="normalize-space($text) = ''" />
+ <xsl:when test="string-length($text) &lt;= $first-line-length">
+ <xsl:value-of select="concat($text, '&#10;')" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="break-pos">
+ <xsl:call-template name="ws-search">
+ <xsl:with-param name="text" select="$text" />
+ <xsl:with-param name="start" select="$first-line-length+1" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:value-of select="substring($text, 1, $break-pos - 1)" />
+ <xsl:text>&#10;</xsl:text>
+ <xsl:call-template name="line-wrap">
+ <xsl:with-param name="line-length" select="$line-length" />
+ <xsl:with-param
+ name="text" select="concat(' ', substring($text, $break-pos+1))"
+ />
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="ws-search">
+ <xsl:param name="text"/> <!-- required -->
+ <xsl:param name="start"/> <!-- required -->
+ <xsl:variable name="search-text" select="substring($text, $start)" />
+ <xsl:choose>
+ <xsl:when test="not(contains($search-text, ' '))">
+ <xsl:value-of select="string-length($text)+1" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of
+ select="$start + string-length(substring-before($search-text, ' '))"
+ />
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/contrib/tools/bison/bison/data/xslt/xml2xhtml.xsl b/contrib/tools/bison/bison/data/xslt/xml2xhtml.xsl
index d2cfed4ccd..0ac591e159 100644
--- a/contrib/tools/bison/bison/data/xslt/xml2xhtml.xsl
+++ b/contrib/tools/bison/bison/data/xslt/xml2xhtml.xsl
@@ -1,745 +1,745 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- xml2html.xsl - transform Bison XML Report into XHTML.
-
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- Written by Wojciech Polak <polak@gnu.org>.
- -->
-
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns="http://www.w3.org/1999/xhtml"
- xmlns:bison="http://www.gnu.org/software/bison/">
-
-<xsl:import href="bison.xsl"/>
-
-<xsl:output method="xml" encoding="UTF-8"
- doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
- doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
- indent="yes"/>
-
-<xsl:template match="/">
- <html>
- <head>
- <title>
- <xsl:value-of select="bison-xml-report/filename"/>
- <xsl:text> - GNU Bison XML Automaton Report</xsl:text>
- </title>
- <style type="text/css"><![CDATA[
- body {
- font-family: "Nimbus Sans L", Arial, sans-serif;
- font-size: 9pt;
- }
- a:link {
- color: #1f00ff;
- text-decoration: none;
- }
- a:visited {
- color: #1f00ff;
- text-decoration: none;
- }
- a:hover {
- color: red;
- }
- #menu a {
- text-decoration: underline;
- }
- .i {
- font-style: italic;
- }
- .pre {
- font-family: monospace;
- white-space: pre;
- }
- ol.decimal {
- list-style-type: decimal;
- }
- ol.lower-alpha {
- list-style-type: lower-alpha;
- }
- .point {
- color: #cc0000;
- }
- #footer {
- margin-top: 3.5em;
- font-size: 7pt;
- }
- ]]></style>
- </head>
- <body>
- <xsl:apply-templates select="bison-xml-report"/>
- <xsl:text>&#10;&#10;</xsl:text>
- <div id="footer"><hr />This document was generated using
- <a href="http://www.gnu.org/software/bison/" title="GNU Bison">
- GNU Bison <xsl:value-of select="/bison-xml-report/@version"/></a>
- XML Automaton Report.<br />
- <!-- default copying notice -->
- Verbatim copying and distribution of this entire page is
- permitted in any medium, provided this notice is preserved.</div>
- </body>
- </html>
-</xsl:template>
-
-<xsl:template match="bison-xml-report">
- <h1>GNU Bison XML Automaton Report</h1>
- <p>
- input grammar: <span class="i"><xsl:value-of select="filename"/></span>
- </p>
-
- <xsl:text>&#10;&#10;</xsl:text>
- <h3>Table of Contents</h3>
- <ul id="menu">
- <li>
- <a href="#reductions">Reductions</a>
- <ul class="lower-alpha">
- <li><a href="#nonterminals_useless_in_grammar">Nonterminals useless in grammar</a></li>
- <li><a href="#terminals_unused_in_grammar">Terminals unused in grammar</a></li>
- <li><a href="#rules_useless_in_grammar">Rules useless in grammar</a></li>
- <xsl:if test="grammar/rules/rule[@usefulness='useless-in-parser']">
- <li><a href="#rules_useless_in_parser">Rules useless in parser due to conflicts</a></li>
- </xsl:if>
- </ul>
- </li>
- <li><a href="#conflicts">Conflicts</a></li>
- <li>
- <a href="#grammar">Grammar</a>
- <ul class="lower-alpha">
- <li><a href="#grammar">Itemset</a></li>
- <li><a href="#terminals">Terminal symbols</a></li>
- <li><a href="#nonterminals">Nonterminal symbols</a></li>
- </ul>
- </li>
- <li><a href="#automaton">Automaton</a></li>
- </ul>
- <xsl:apply-templates select="grammar" mode="reductions"/>
- <xsl:apply-templates select="grammar" mode="useless-in-parser"/>
- <xsl:apply-templates select="automaton" mode="conflicts"/>
- <xsl:apply-templates select="grammar"/>
- <xsl:apply-templates select="automaton"/>
-</xsl:template>
-
-<xsl:template match="grammar" mode="reductions">
- <h2>
- <a name="reductions"/>
- <xsl:text> Reductions</xsl:text>
- </h2>
- <xsl:apply-templates select="nonterminals" mode="useless-in-grammar"/>
- <xsl:apply-templates select="terminals" mode="unused-in-grammar"/>
- <xsl:apply-templates select="rules" mode="useless-in-grammar"/>
-</xsl:template>
-
-<xsl:template match="nonterminals" mode="useless-in-grammar">
- <h3>
- <a name="nonterminals_useless_in_grammar"/>
- <xsl:text> Nonterminals useless in grammar</xsl:text>
- </h3>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
- <p class="pre">
- <xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
- <xsl:text> </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>&#10;</xsl:text>
- </xsl:for-each>
- <xsl:text>&#10;&#10;</xsl:text>
- </p>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="terminals" mode="unused-in-grammar">
- <h3>
- <a name="terminals_unused_in_grammar"/>
- <xsl:text> Terminals unused in grammar</xsl:text>
- </h3>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:if test="terminal[@usefulness='unused-in-grammar']">
- <p class="pre">
- <xsl:for-each select="terminal[@usefulness='unused-in-grammar']">
- <xsl:sort select="@symbol-number" data-type="number"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>&#10;</xsl:text>
- </xsl:for-each>
- <xsl:text>&#10;&#10;</xsl:text>
- </p>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="rules" mode="useless-in-grammar">
- <h3>
- <a name="rules_useless_in_grammar"/>
- <xsl:text> Rules useless in grammar</xsl:text>
- </h3>
- <xsl:text>&#10;</xsl:text>
- <xsl:variable name="set" select="rule[@usefulness='useless-in-grammar']"/>
- <xsl:if test="$set">
- <p class="pre">
- <xsl:call-template name="style-rule-set">
- <xsl:with-param name="rule-set" select="$set"/>
- </xsl:call-template>
- <xsl:text>&#10;&#10;</xsl:text>
- </p>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="grammar" mode="useless-in-parser">
- <xsl:variable
- name="set" select="rules/rule[@usefulness='useless-in-parser']"
- />
- <xsl:if test="$set">
- <h2>
- <a name="rules_useless_in_parser"/>
- <xsl:text> Rules useless in parser due to conflicts</xsl:text>
- </h2>
- <xsl:text>&#10;</xsl:text>
- <p class="pre">
- <xsl:call-template name="style-rule-set">
- <xsl:with-param name="rule-set" select="$set"/>
- </xsl:call-template>
- </p>
- <xsl:text>&#10;&#10;</xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="grammar">
- <h2>
- <a name="grammar"/>
- <xsl:text> Grammar</xsl:text>
- </h2>
- <xsl:text>&#10;</xsl:text>
- <p class="pre">
- <xsl:call-template name="style-rule-set">
- <xsl:with-param
- name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
- />
- </xsl:call-template>
- </p>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:apply-templates select="terminals"/>
- <xsl:apply-templates select="nonterminals"/>
-</xsl:template>
-
-<xsl:template name="style-rule-set">
- <xsl:param name="rule-set"/>
- <xsl:for-each select="$rule-set">
- <xsl:apply-templates select=".">
- <xsl:with-param name="pad" select="'3'"/>
- <xsl:with-param name="prev-lhs">
- <xsl:if test="position()>1">
- <xsl:variable name="position" select="position()"/>
- <xsl:value-of select="$rule-set[$position - 1]/lhs"/>
- </xsl:if>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:for-each>
-</xsl:template>
-
-<xsl:template match="automaton" mode="conflicts">
- <h2>
- <a name="conflicts"/>
- <xsl:text> Conflicts</xsl:text>
- </h2>
- <xsl:text>&#10;&#10;</xsl:text>
- <xsl:variable name="conflict-report">
- <xsl:apply-templates select="state" mode="conflicts"/>
- </xsl:variable>
- <xsl:if test="string-length($conflict-report) != 0">
- <p class="pre">
- <xsl:copy-of select="$conflict-report"/>
- <xsl:text>&#10;&#10;</xsl:text>
- </p>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="state" mode="conflicts">
- <xsl:variable name="conflict-counts">
- <xsl:apply-templates select="." mode="bison:count-conflicts" />
- </xsl:variable>
- <xsl:variable
- name="sr-count" select="substring-before($conflict-counts, ',')"
- />
- <xsl:variable
- name="rr-count" select="substring-after($conflict-counts, ',')"
- />
- <xsl:if test="$sr-count > 0 or $rr-count > 0">
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#state_', @number)"/>
- </xsl:attribute>
- <xsl:value-of select="concat('State ', @number)"/>
- </a>
- <xsl:text> conflicts:</xsl:text>
- <xsl:if test="$sr-count > 0">
- <xsl:value-of select="concat(' ', $sr-count, ' shift/reduce')"/>
- <xsl:if test="$rr-count > 0">
- <xsl:value-of select="(',')"/>
- </xsl:if>
- </xsl:if>
- <xsl:if test="$rr-count > 0">
- <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
- </xsl:if>
- <xsl:value-of select="'&#10;'"/>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="grammar/terminals">
- <h3>
- <a name="terminals"/>
- <xsl:text> Terminals, with rules where they appear</xsl:text>
- </h3>
- <xsl:text>&#10;&#10;</xsl:text>
- <p class="pre">
- <xsl:apply-templates select="terminal"/>
- </p>
- <xsl:text>&#10;&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="grammar/nonterminals">
- <h3>
- <a name="nonterminals"/>
- <xsl:text> Nonterminals, with rules where they appear</xsl:text>
- </h3>
- <xsl:text>&#10;&#10;</xsl:text>
- <p class="pre">
- <xsl:apply-templates
- select="nonterminal[@usefulness!='useless-in-grammar']"
- />
- </p>
-</xsl:template>
-
-<xsl:template match="terminal">
- <b><xsl:value-of select="@name"/></b>
- <xsl:value-of select="concat(' (', @token-number, ')')"/>
- <xsl:for-each select="key('bison:ruleByRhs', @name)">
- <xsl:apply-templates select="." mode="number-link"/>
- </xsl:for-each>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="nonterminal">
- <b><xsl:value-of select="@name"/></b>
- <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
- <xsl:text>&#10; </xsl:text>
- <xsl:if test="key('bison:ruleByLhs', @name)">
- <xsl:text>on left:</xsl:text>
- <xsl:for-each select="key('bison:ruleByLhs', @name)">
- <xsl:apply-templates select="." mode="number-link"/>
- </xsl:for-each>
- </xsl:if>
- <xsl:if test="key('bison:ruleByRhs', @name)">
- <xsl:if test="key('bison:ruleByLhs', @name)">
- <xsl:text>&#10; </xsl:text>
- </xsl:if>
- <xsl:text>on right:</xsl:text>
- <xsl:for-each select="key('bison:ruleByRhs', @name)">
- <xsl:apply-templates select="." mode="number-link"/>
- </xsl:for-each>
- </xsl:if>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="rule" mode="number-link">
- <xsl:text> </xsl:text>
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', @number)"/>
- </xsl:attribute>
- <xsl:value-of select="@number"/>
- </a>
-</xsl:template>
-
-<xsl:template match="automaton">
- <h2>
- <a name="automaton"/>
- <xsl:text> Automaton</xsl:text>
- </h2>
- <xsl:apply-templates select="state">
- <xsl:with-param name="pad" select="'3'"/>
- </xsl:apply-templates>
-</xsl:template>
-
-<xsl:template match="automaton/state">
- <xsl:param name="pad"/>
- <xsl:text>&#10;&#10;</xsl:text>
- <h3>
- <a>
- <xsl:attribute name="name">
- <xsl:value-of select="concat('state_', @number)"/>
- </xsl:attribute>
- </a>
- <xsl:text>state </xsl:text>
- <xsl:value-of select="@number"/>
- </h3>
- <xsl:text>&#10;&#10;</xsl:text>
- <p class="pre">
- <xsl:apply-templates select="itemset/item">
- <xsl:with-param name="pad" select="$pad"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="actions/transitions">
- <xsl:with-param name="type" select="'shift'"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="actions/errors"/>
- <xsl:apply-templates select="actions/reductions"/>
- <xsl:apply-templates select="actions/transitions">
- <xsl:with-param name="type" select="'goto'"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="solved-conflicts"/>
- </p>
-</xsl:template>
-
-<xsl:template match="actions/transitions">
- <xsl:param name="type"/>
- <xsl:if test="transition[@type = $type]">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="transition[@type = $type]">
- <xsl:with-param name="pad">
- <xsl:call-template name="max-width-symbol">
- <xsl:with-param name="node" select="transition[@type = $type]"/>
- </xsl:call-template>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="actions/errors">
- <xsl:if test="error">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="error">
- <xsl:with-param name="pad">
- <xsl:call-template name="max-width-symbol">
- <xsl:with-param name="node" select="error"/>
- </xsl:call-template>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="actions/reductions">
- <xsl:if test="reduction">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="reduction">
- <xsl:with-param name="pad">
- <xsl:call-template name="max-width-symbol">
- <xsl:with-param name="node" select="reduction"/>
- </xsl:call-template>
- </xsl:with-param>
- </xsl:apply-templates>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="item">
- <xsl:param name="pad"/>
- <xsl:param name="prev-rule-number"
- select="preceding-sibling::item[1]/@rule-number"/>
- <xsl:apply-templates
- select="key('bison:ruleByNumber', current()/@rule-number)"
- >
- <xsl:with-param name="itemset" select="'true'"/>
- <xsl:with-param name="pad" select="$pad"/>
- <xsl:with-param name="prev-lhs"
- select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
- />
- <xsl:with-param name="point" select="@point"/>
- <xsl:with-param name="lookaheads">
- <xsl:apply-templates select="lookaheads"/>
- </xsl:with-param>
- </xsl:apply-templates>
-</xsl:template>
-
-<xsl:template match="rule">
- <xsl:param name="itemset"/>
- <xsl:param name="pad"/>
- <xsl:param name="prev-lhs"/>
- <xsl:param name="point"/>
- <xsl:param name="lookaheads"/>
-
- <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
- <xsl:text>&#10;</xsl:text>
- </xsl:if>
-
- <xsl:if test="$itemset != 'true'">
- <a>
- <xsl:attribute name="name">
- <xsl:value-of select="concat('rule_', @number)"/>
- </xsl:attribute>
- </a>
- </xsl:if>
- <xsl:text> </xsl:text>
-
- <xsl:choose>
- <xsl:when test="$itemset = 'true'">
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', @number)"/>
- </xsl:attribute>
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="string(@number)"/>
- <xsl:with-param name="pad" select="number($pad)"/>
- </xsl:call-template>
- </a>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="string(@number)"/>
- <xsl:with-param name="pad" select="number($pad)"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:text> </xsl:text>
-
- <!-- LHS -->
- <xsl:choose>
- <xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]">
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="'|'"/>
- <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
- <xsl:call-template name="lpad">
- <xsl:with-param name="str" select="'|'"/>
- <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <span class="i">
- <xsl:value-of select="lhs"/>
- </span>
- <xsl:text> &#8594;</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
-
- <!-- RHS -->
- <xsl:for-each select="rhs/*">
- <xsl:if test="position() = $point + 1">
- <xsl:text> </xsl:text>
- <span class="point">.</span>
- </xsl:if>
- <xsl:if test="$itemset = 'true' and name(.) != 'empty'">
- <xsl:apply-templates select="."/>
- </xsl:if>
- <xsl:if test="$itemset != 'true'">
- <xsl:apply-templates select="."/>
- </xsl:if>
- <xsl:if test="position() = last() and position() = $point">
- <xsl:text> </xsl:text>
- <span class="point">.</span>
- </xsl:if>
- </xsl:for-each>
- <xsl:if test="$lookaheads">
- <xsl:value-of select="$lookaheads"/>
- </xsl:if>
-
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="symbol">
- <xsl:text> </xsl:text>
- <xsl:choose>
- <xsl:when test="name(key('bison:symbolByName', .)) = 'nonterminal'">
- <span class="i"><xsl:value-of select="."/></span>
- </xsl:when>
- <xsl:otherwise>
- <b><xsl:value-of select="."/></b>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template match="empty">
- <xsl:text> &#949;</xsl:text>
-</xsl:template>
-
-<xsl:template match="lookaheads">
- <xsl:text> [</xsl:text>
- <xsl:apply-templates select="symbol"/>
- <xsl:text>]</xsl:text>
-</xsl:template>
-
-<xsl:template match="lookaheads/symbol">
- <xsl:value-of select="."/>
- <xsl:if test="position() != last()">
- <xsl:text>, </xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="transition">
- <xsl:param name="pad"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="rpad">
- <xsl:with-param name="str" select="string(@symbol)"/>
- <xsl:with-param name="pad" select="number($pad) + 2"/>
- </xsl:call-template>
- <xsl:choose>
- <xsl:when test="@type = 'shift'">
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#state_', @state)"/>
- </xsl:attribute>
- <xsl:value-of select="concat('shift, and go to state ', @state)"/>
- </a>
- </xsl:when>
- <xsl:when test="@type = 'goto'">
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#state_', @state)"/>
- </xsl:attribute>
- <xsl:value-of select="concat('go to state ', @state)"/>
- </a>
- </xsl:when>
- </xsl:choose>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="error">
- <xsl:param name="pad"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="rpad">
- <xsl:with-param name="str" select="string(@symbol)"/>
- <xsl:with-param name="pad" select="number($pad) + 2"/>
- </xsl:call-template>
- <xsl:text>error</xsl:text>
- <xsl:text> (</xsl:text>
- <xsl:value-of select="text()"/>
- <xsl:text>)</xsl:text>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="reduction">
- <xsl:param name="pad"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="rpad">
- <xsl:with-param name="str" select="string(@symbol)"/>
- <xsl:with-param name="pad" select="number($pad) + 2"/>
- </xsl:call-template>
- <xsl:if test="@enabled = 'false'">
- <xsl:text>[</xsl:text>
- </xsl:if>
- <xsl:choose>
- <xsl:when test="@rule = 'accept'">
- <xsl:text>accept</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', @rule)"/>
- </xsl:attribute>
- <xsl:value-of select="concat('reduce using rule ', @rule)"/>
- </a>
- <xsl:text> (</xsl:text>
- <xsl:value-of
- select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
- />
- <xsl:text>)</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="@enabled = 'false'">
- <xsl:text>]</xsl:text>
- </xsl:if>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template match="solved-conflicts">
- <xsl:if test="resolution">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="resolution"/>
- </xsl:if>
-</xsl:template>
-
-<xsl:template match="resolution">
- <xsl:text> Conflict between </xsl:text>
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', @rule)"/>
- </xsl:attribute>
- <xsl:value-of select="concat('rule ',@rule)"/>
- </a>
- <xsl:text> and token </xsl:text>
- <xsl:value-of select="@symbol"/>
- <xsl:text> resolved as </xsl:text>
- <xsl:if test="@type = 'error'">
- <xsl:text>an </xsl:text>
- </xsl:if>
- <xsl:value-of select="@type"/>
- <xsl:text> (</xsl:text>
- <xsl:value-of select="."/>
- <xsl:text>).&#10;</xsl:text>
-</xsl:template>
-
-<xsl:template name="max-width-symbol">
- <xsl:param name="node"/>
- <xsl:variable name="longest">
- <xsl:for-each select="$node">
- <xsl:sort data-type="number" select="string-length(@symbol)"
- order="descending"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="string-length(@symbol)"/>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
- <xsl:value-of select="$longest"/>
-</xsl:template>
-
-<xsl:template name="lpad">
- <xsl:param name="str" select="''"/>
- <xsl:param name="pad" select="0"/>
- <xsl:variable name="diff" select="$pad - string-length($str)" />
- <xsl:choose>
- <xsl:when test="$diff &lt; 0">
- <xsl:value-of select="$str"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$diff"/>
- </xsl:call-template>
- <xsl:value-of select="$str"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="rpad">
- <xsl:param name="str" select="''"/>
- <xsl:param name="pad" select="0"/>
- <xsl:variable name="diff" select="$pad - string-length($str)"/>
- <xsl:choose>
- <xsl:when test="$diff &lt; 0">
- <xsl:value-of select="$str"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$str"/>
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$diff"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="space">
- <xsl:param name="repeat">0</xsl:param>
- <xsl:param name="fill" select="' '"/>
- <xsl:if test="number($repeat) &gt;= 1">
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$repeat - 1"/>
- <xsl:with-param name="fill" select="$fill"/>
- </xsl:call-template>
- <xsl:value-of select="$fill"/>
- </xsl:if>
-</xsl:template>
-
-</xsl:stylesheet>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ xml2html.xsl - transform Bison XML Report into XHTML.
+
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Written by Wojciech Polak <polak@gnu.org>.
+ -->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:bison="http://www.gnu.org/software/bison/">
+
+<xsl:import href="bison.xsl"/>
+
+<xsl:output method="xml" encoding="UTF-8"
+ doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
+ doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
+ indent="yes"/>
+
+<xsl:template match="/">
+ <html>
+ <head>
+ <title>
+ <xsl:value-of select="bison-xml-report/filename"/>
+ <xsl:text> - GNU Bison XML Automaton Report</xsl:text>
+ </title>
+ <style type="text/css"><![CDATA[
+ body {
+ font-family: "Nimbus Sans L", Arial, sans-serif;
+ font-size: 9pt;
+ }
+ a:link {
+ color: #1f00ff;
+ text-decoration: none;
+ }
+ a:visited {
+ color: #1f00ff;
+ text-decoration: none;
+ }
+ a:hover {
+ color: red;
+ }
+ #menu a {
+ text-decoration: underline;
+ }
+ .i {
+ font-style: italic;
+ }
+ .pre {
+ font-family: monospace;
+ white-space: pre;
+ }
+ ol.decimal {
+ list-style-type: decimal;
+ }
+ ol.lower-alpha {
+ list-style-type: lower-alpha;
+ }
+ .point {
+ color: #cc0000;
+ }
+ #footer {
+ margin-top: 3.5em;
+ font-size: 7pt;
+ }
+ ]]></style>
+ </head>
+ <body>
+ <xsl:apply-templates select="bison-xml-report"/>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <div id="footer"><hr />This document was generated using
+ <a href="http://www.gnu.org/software/bison/" title="GNU Bison">
+ GNU Bison <xsl:value-of select="/bison-xml-report/@version"/></a>
+ XML Automaton Report.<br />
+ <!-- default copying notice -->
+ Verbatim copying and distribution of this entire page is
+ permitted in any medium, provided this notice is preserved.</div>
+ </body>
+ </html>
+</xsl:template>
+
+<xsl:template match="bison-xml-report">
+ <h1>GNU Bison XML Automaton Report</h1>
+ <p>
+ input grammar: <span class="i"><xsl:value-of select="filename"/></span>
+ </p>
+
+ <xsl:text>&#10;&#10;</xsl:text>
+ <h3>Table of Contents</h3>
+ <ul id="menu">
+ <li>
+ <a href="#reductions">Reductions</a>
+ <ul class="lower-alpha">
+ <li><a href="#nonterminals_useless_in_grammar">Nonterminals useless in grammar</a></li>
+ <li><a href="#terminals_unused_in_grammar">Terminals unused in grammar</a></li>
+ <li><a href="#rules_useless_in_grammar">Rules useless in grammar</a></li>
+ <xsl:if test="grammar/rules/rule[@usefulness='useless-in-parser']">
+ <li><a href="#rules_useless_in_parser">Rules useless in parser due to conflicts</a></li>
+ </xsl:if>
+ </ul>
+ </li>
+ <li><a href="#conflicts">Conflicts</a></li>
+ <li>
+ <a href="#grammar">Grammar</a>
+ <ul class="lower-alpha">
+ <li><a href="#grammar">Itemset</a></li>
+ <li><a href="#terminals">Terminal symbols</a></li>
+ <li><a href="#nonterminals">Nonterminal symbols</a></li>
+ </ul>
+ </li>
+ <li><a href="#automaton">Automaton</a></li>
+ </ul>
+ <xsl:apply-templates select="grammar" mode="reductions"/>
+ <xsl:apply-templates select="grammar" mode="useless-in-parser"/>
+ <xsl:apply-templates select="automaton" mode="conflicts"/>
+ <xsl:apply-templates select="grammar"/>
+ <xsl:apply-templates select="automaton"/>
+</xsl:template>
+
+<xsl:template match="grammar" mode="reductions">
+ <h2>
+ <a name="reductions"/>
+ <xsl:text> Reductions</xsl:text>
+ </h2>
+ <xsl:apply-templates select="nonterminals" mode="useless-in-grammar"/>
+ <xsl:apply-templates select="terminals" mode="unused-in-grammar"/>
+ <xsl:apply-templates select="rules" mode="useless-in-grammar"/>
+</xsl:template>
+
+<xsl:template match="nonterminals" mode="useless-in-grammar">
+ <h3>
+ <a name="nonterminals_useless_in_grammar"/>
+ <xsl:text> Nonterminals useless in grammar</xsl:text>
+ </h3>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
+ <p class="pre">
+ <xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>&#10;</xsl:text>
+ </xsl:for-each>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </p>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="terminals" mode="unused-in-grammar">
+ <h3>
+ <a name="terminals_unused_in_grammar"/>
+ <xsl:text> Terminals unused in grammar</xsl:text>
+ </h3>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:if test="terminal[@usefulness='unused-in-grammar']">
+ <p class="pre">
+ <xsl:for-each select="terminal[@usefulness='unused-in-grammar']">
+ <xsl:sort select="@symbol-number" data-type="number"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text>&#10;</xsl:text>
+ </xsl:for-each>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </p>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="rules" mode="useless-in-grammar">
+ <h3>
+ <a name="rules_useless_in_grammar"/>
+ <xsl:text> Rules useless in grammar</xsl:text>
+ </h3>
+ <xsl:text>&#10;</xsl:text>
+ <xsl:variable name="set" select="rule[@usefulness='useless-in-grammar']"/>
+ <xsl:if test="$set">
+ <p class="pre">
+ <xsl:call-template name="style-rule-set">
+ <xsl:with-param name="rule-set" select="$set"/>
+ </xsl:call-template>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </p>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="grammar" mode="useless-in-parser">
+ <xsl:variable
+ name="set" select="rules/rule[@usefulness='useless-in-parser']"
+ />
+ <xsl:if test="$set">
+ <h2>
+ <a name="rules_useless_in_parser"/>
+ <xsl:text> Rules useless in parser due to conflicts</xsl:text>
+ </h2>
+ <xsl:text>&#10;</xsl:text>
+ <p class="pre">
+ <xsl:call-template name="style-rule-set">
+ <xsl:with-param name="rule-set" select="$set"/>
+ </xsl:call-template>
+ </p>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="grammar">
+ <h2>
+ <a name="grammar"/>
+ <xsl:text> Grammar</xsl:text>
+ </h2>
+ <xsl:text>&#10;</xsl:text>
+ <p class="pre">
+ <xsl:call-template name="style-rule-set">
+ <xsl:with-param
+ name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
+ />
+ </xsl:call-template>
+ </p>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:apply-templates select="terminals"/>
+ <xsl:apply-templates select="nonterminals"/>
+</xsl:template>
+
+<xsl:template name="style-rule-set">
+ <xsl:param name="rule-set"/>
+ <xsl:for-each select="$rule-set">
+ <xsl:apply-templates select=".">
+ <xsl:with-param name="pad" select="'3'"/>
+ <xsl:with-param name="prev-lhs">
+ <xsl:if test="position()>1">
+ <xsl:variable name="position" select="position()"/>
+ <xsl:value-of select="$rule-set[$position - 1]/lhs"/>
+ </xsl:if>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="automaton" mode="conflicts">
+ <h2>
+ <a name="conflicts"/>
+ <xsl:text> Conflicts</xsl:text>
+ </h2>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:variable name="conflict-report">
+ <xsl:apply-templates select="state" mode="conflicts"/>
+ </xsl:variable>
+ <xsl:if test="string-length($conflict-report) != 0">
+ <p class="pre">
+ <xsl:copy-of select="$conflict-report"/>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </p>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="state" mode="conflicts">
+ <xsl:variable name="conflict-counts">
+ <xsl:apply-templates select="." mode="bison:count-conflicts" />
+ </xsl:variable>
+ <xsl:variable
+ name="sr-count" select="substring-before($conflict-counts, ',')"
+ />
+ <xsl:variable
+ name="rr-count" select="substring-after($conflict-counts, ',')"
+ />
+ <xsl:if test="$sr-count > 0 or $rr-count > 0">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#state_', @number)"/>
+ </xsl:attribute>
+ <xsl:value-of select="concat('State ', @number)"/>
+ </a>
+ <xsl:text> conflicts:</xsl:text>
+ <xsl:if test="$sr-count > 0">
+ <xsl:value-of select="concat(' ', $sr-count, ' shift/reduce')"/>
+ <xsl:if test="$rr-count > 0">
+ <xsl:value-of select="(',')"/>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="$rr-count > 0">
+ <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
+ </xsl:if>
+ <xsl:value-of select="'&#10;'"/>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="grammar/terminals">
+ <h3>
+ <a name="terminals"/>
+ <xsl:text> Terminals, with rules where they appear</xsl:text>
+ </h3>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <p class="pre">
+ <xsl:apply-templates select="terminal"/>
+ </p>
+ <xsl:text>&#10;&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="grammar/nonterminals">
+ <h3>
+ <a name="nonterminals"/>
+ <xsl:text> Nonterminals, with rules where they appear</xsl:text>
+ </h3>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <p class="pre">
+ <xsl:apply-templates
+ select="nonterminal[@usefulness!='useless-in-grammar']"
+ />
+ </p>
+</xsl:template>
+
+<xsl:template match="terminal">
+ <b><xsl:value-of select="@name"/></b>
+ <xsl:value-of select="concat(' (', @token-number, ')')"/>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="nonterminal">
+ <b><xsl:value-of select="@name"/></b>
+ <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
+ <xsl:text>&#10; </xsl:text>
+ <xsl:if test="key('bison:ruleByLhs', @name)">
+ <xsl:text>on left:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByLhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:if test="key('bison:ruleByRhs', @name)">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
+ <xsl:text>&#10; </xsl:text>
+ </xsl:if>
+ <xsl:text>on right:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="rule" mode="number-link">
+ <xsl:text> </xsl:text>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#rule_', @number)"/>
+ </xsl:attribute>
+ <xsl:value-of select="@number"/>
+ </a>
+</xsl:template>
+
+<xsl:template match="automaton">
+ <h2>
+ <a name="automaton"/>
+ <xsl:text> Automaton</xsl:text>
+ </h2>
+ <xsl:apply-templates select="state">
+ <xsl:with-param name="pad" select="'3'"/>
+ </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="automaton/state">
+ <xsl:param name="pad"/>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <h3>
+ <a>
+ <xsl:attribute name="name">
+ <xsl:value-of select="concat('state_', @number)"/>
+ </xsl:attribute>
+ </a>
+ <xsl:text>state </xsl:text>
+ <xsl:value-of select="@number"/>
+ </h3>
+ <xsl:text>&#10;&#10;</xsl:text>
+ <p class="pre">
+ <xsl:apply-templates select="itemset/item">
+ <xsl:with-param name="pad" select="$pad"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="actions/transitions">
+ <xsl:with-param name="type" select="'shift'"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="actions/errors"/>
+ <xsl:apply-templates select="actions/reductions"/>
+ <xsl:apply-templates select="actions/transitions">
+ <xsl:with-param name="type" select="'goto'"/>
+ </xsl:apply-templates>
+ <xsl:apply-templates select="solved-conflicts"/>
+ </p>
+</xsl:template>
+
+<xsl:template match="actions/transitions">
+ <xsl:param name="type"/>
+ <xsl:if test="transition[@type = $type]">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="transition[@type = $type]">
+ <xsl:with-param name="pad">
+ <xsl:call-template name="max-width-symbol">
+ <xsl:with-param name="node" select="transition[@type = $type]"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="actions/errors">
+ <xsl:if test="error">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="error">
+ <xsl:with-param name="pad">
+ <xsl:call-template name="max-width-symbol">
+ <xsl:with-param name="node" select="error"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="actions/reductions">
+ <xsl:if test="reduction">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="reduction">
+ <xsl:with-param name="pad">
+ <xsl:call-template name="max-width-symbol">
+ <xsl:with-param name="node" select="reduction"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:apply-templates>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="item">
+ <xsl:param name="pad"/>
+ <xsl:param name="prev-rule-number"
+ select="preceding-sibling::item[1]/@rule-number"/>
+ <xsl:apply-templates
+ select="key('bison:ruleByNumber', current()/@rule-number)"
+ >
+ <xsl:with-param name="itemset" select="'true'"/>
+ <xsl:with-param name="pad" select="$pad"/>
+ <xsl:with-param name="prev-lhs"
+ select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
+ />
+ <xsl:with-param name="point" select="@point"/>
+ <xsl:with-param name="lookaheads">
+ <xsl:apply-templates select="lookaheads"/>
+ </xsl:with-param>
+ </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="rule">
+ <xsl:param name="itemset"/>
+ <xsl:param name="pad"/>
+ <xsl:param name="prev-lhs"/>
+ <xsl:param name="point"/>
+ <xsl:param name="lookaheads"/>
+
+ <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
+ <xsl:text>&#10;</xsl:text>
+ </xsl:if>
+
+ <xsl:if test="$itemset != 'true'">
+ <a>
+ <xsl:attribute name="name">
+ <xsl:value-of select="concat('rule_', @number)"/>
+ </xsl:attribute>
+ </a>
+ </xsl:if>
+ <xsl:text> </xsl:text>
+
+ <xsl:choose>
+ <xsl:when test="$itemset = 'true'">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#rule_', @number)"/>
+ </xsl:attribute>
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="string(@number)"/>
+ <xsl:with-param name="pad" select="number($pad)"/>
+ </xsl:call-template>
+ </a>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="string(@number)"/>
+ <xsl:with-param name="pad" select="number($pad)"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> </xsl:text>
+
+ <!-- LHS -->
+ <xsl:choose>
+ <xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]">
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="'|'"/>
+ <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="'|'"/>
+ <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <span class="i">
+ <xsl:value-of select="lhs"/>
+ </span>
+ <xsl:text> &#8594;</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <!-- RHS -->
+ <xsl:for-each select="rhs/*">
+ <xsl:if test="position() = $point + 1">
+ <xsl:text> </xsl:text>
+ <span class="point">.</span>
+ </xsl:if>
+ <xsl:if test="$itemset = 'true' and name(.) != 'empty'">
+ <xsl:apply-templates select="."/>
+ </xsl:if>
+ <xsl:if test="$itemset != 'true'">
+ <xsl:apply-templates select="."/>
+ </xsl:if>
+ <xsl:if test="position() = last() and position() = $point">
+ <xsl:text> </xsl:text>
+ <span class="point">.</span>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:if test="$lookaheads">
+ <xsl:value-of select="$lookaheads"/>
+ </xsl:if>
+
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="symbol">
+ <xsl:text> </xsl:text>
+ <xsl:choose>
+ <xsl:when test="name(key('bison:symbolByName', .)) = 'nonterminal'">
+ <span class="i"><xsl:value-of select="."/></span>
+ </xsl:when>
+ <xsl:otherwise>
+ <b><xsl:value-of select="."/></b>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="empty">
+ <xsl:text> &#949;</xsl:text>
+</xsl:template>
+
+<xsl:template match="lookaheads">
+ <xsl:text> [</xsl:text>
+ <xsl:apply-templates select="symbol"/>
+ <xsl:text>]</xsl:text>
+</xsl:template>
+
+<xsl:template match="lookaheads/symbol">
+ <xsl:value-of select="."/>
+ <xsl:if test="position() != last()">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="transition">
+ <xsl:param name="pad"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="rpad">
+ <xsl:with-param name="str" select="string(@symbol)"/>
+ <xsl:with-param name="pad" select="number($pad) + 2"/>
+ </xsl:call-template>
+ <xsl:choose>
+ <xsl:when test="@type = 'shift'">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#state_', @state)"/>
+ </xsl:attribute>
+ <xsl:value-of select="concat('shift, and go to state ', @state)"/>
+ </a>
+ </xsl:when>
+ <xsl:when test="@type = 'goto'">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#state_', @state)"/>
+ </xsl:attribute>
+ <xsl:value-of select="concat('go to state ', @state)"/>
+ </a>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="error">
+ <xsl:param name="pad"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="rpad">
+ <xsl:with-param name="str" select="string(@symbol)"/>
+ <xsl:with-param name="pad" select="number($pad) + 2"/>
+ </xsl:call-template>
+ <xsl:text>error</xsl:text>
+ <xsl:text> (</xsl:text>
+ <xsl:value-of select="text()"/>
+ <xsl:text>)</xsl:text>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="reduction">
+ <xsl:param name="pad"/>
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="rpad">
+ <xsl:with-param name="str" select="string(@symbol)"/>
+ <xsl:with-param name="pad" select="number($pad) + 2"/>
+ </xsl:call-template>
+ <xsl:if test="@enabled = 'false'">
+ <xsl:text>[</xsl:text>
+ </xsl:if>
+ <xsl:choose>
+ <xsl:when test="@rule = 'accept'">
+ <xsl:text>accept</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#rule_', @rule)"/>
+ </xsl:attribute>
+ <xsl:value-of select="concat('reduce using rule ', @rule)"/>
+ </a>
+ <xsl:text> (</xsl:text>
+ <xsl:value-of
+ select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
+ />
+ <xsl:text>)</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:if test="@enabled = 'false'">
+ <xsl:text>]</xsl:text>
+ </xsl:if>
+ <xsl:text>&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="solved-conflicts">
+ <xsl:if test="resolution">
+ <xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates select="resolution"/>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="resolution">
+ <xsl:text> Conflict between </xsl:text>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#rule_', @rule)"/>
+ </xsl:attribute>
+ <xsl:value-of select="concat('rule ',@rule)"/>
+ </a>
+ <xsl:text> and token </xsl:text>
+ <xsl:value-of select="@symbol"/>
+ <xsl:text> resolved as </xsl:text>
+ <xsl:if test="@type = 'error'">
+ <xsl:text>an </xsl:text>
+ </xsl:if>
+ <xsl:value-of select="@type"/>
+ <xsl:text> (</xsl:text>
+ <xsl:value-of select="."/>
+ <xsl:text>).&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template name="max-width-symbol">
+ <xsl:param name="node"/>
+ <xsl:variable name="longest">
+ <xsl:for-each select="$node">
+ <xsl:sort data-type="number" select="string-length(@symbol)"
+ order="descending"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="string-length(@symbol)"/>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:value-of select="$longest"/>
+</xsl:template>
+
+<xsl:template name="lpad">
+ <xsl:param name="str" select="''"/>
+ <xsl:param name="pad" select="0"/>
+ <xsl:variable name="diff" select="$pad - string-length($str)" />
+ <xsl:choose>
+ <xsl:when test="$diff &lt; 0">
+ <xsl:value-of select="$str"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="space">
+ <xsl:with-param name="repeat" select="$diff"/>
+ </xsl:call-template>
+ <xsl:value-of select="$str"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="rpad">
+ <xsl:param name="str" select="''"/>
+ <xsl:param name="pad" select="0"/>
+ <xsl:variable name="diff" select="$pad - string-length($str)"/>
+ <xsl:choose>
+ <xsl:when test="$diff &lt; 0">
+ <xsl:value-of select="$str"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$str"/>
+ <xsl:call-template name="space">
+ <xsl:with-param name="repeat" select="$diff"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="space">
+ <xsl:param name="repeat">0</xsl:param>
+ <xsl:param name="fill" select="' '"/>
+ <xsl:if test="number($repeat) &gt;= 1">
+ <xsl:call-template name="space">
+ <xsl:with-param name="repeat" select="$repeat - 1"/>
+ <xsl:with-param name="fill" select="$fill"/>
+ </xsl:call-template>
+ <xsl:value-of select="$fill"/>
+ </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/contrib/tools/bison/bison/data/yacc.c b/contrib/tools/bison/bison/data/yacc.c
index c18a9350cf..b75ba7bf6a 100644
--- a/contrib/tools/bison/bison/data/yacc.c
+++ b/contrib/tools/bison/bison/data/yacc.c
@@ -1,1921 +1,1921 @@
- -*- C -*-
-# Yacc compatible skeleton for Bison
-
-# Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation,
-# Inc.
-
-m4_pushdef([b4_copyright_years],
- [1984, 1989-1990, 2000-2013])
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Check the value of %define api.push-pull.
-b4_percent_define_default([[api.push-pull]], [[pull]])
-b4_percent_define_check_values([[[[api.push-pull]],
- [[pull]], [[push]], [[both]]]])
-b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]])
-b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]])
-m4_case(b4_percent_define_get([[api.push-pull]]),
- [pull], [m4_define([b4_push_flag], [[0]])],
- [push], [m4_define([b4_pull_flag], [[0]])])
-
-# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing
-# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the
-# behavior of Bison at all when push parsing is already requested.
-b4_define_flag_if([use_push_for_pull])
-b4_use_push_for_pull_if([
- b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])],
- [m4_define([b4_push_flag], [[1]])])])
-
-# Check the value of %define parse.lac and friends, where LAC stands for
-# lookahead correction.
-b4_percent_define_default([[parse.lac]], [[none]])
-b4_percent_define_default([[parse.lac.es-capacity-initial]], [[20]])
-b4_percent_define_default([[parse.lac.memory-trace]], [[failures]])
-b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]],
- [[[[parse.lac.memory-trace]],
- [[failures]], [[full]]]])
-b4_define_flag_if([lac])
-m4_define([b4_lac_flag],
- [m4_if(b4_percent_define_get([[parse.lac]]),
- [none], [[0]], [[1]])])
-
-m4_include(b4_pkgdatadir/[c.m4])
-
-## ---------------- ##
-## Default values. ##
-## ---------------- ##
-
-# Stack parameters.
-m4_define_default([b4_stack_depth_max], [10000])
-m4_define_default([b4_stack_depth_init], [200])
-
-
-## ------------------------ ##
-## Pure/impure interfaces. ##
-## ------------------------ ##
-
-b4_percent_define_default([[api.pure]], [[false]])
-b4_percent_define_check_values([[[[api.pure]],
- [[false]], [[true]], [[]], [[full]]]])
-
-m4_define([b4_pure_flag], [[0]])
-m4_case(b4_percent_define_get([[api.pure]]),
- [false], [m4_define([b4_pure_flag], [[0]])],
- [true], [m4_define([b4_pure_flag], [[1]])],
- [], [m4_define([b4_pure_flag], [[1]])],
- [full], [m4_define([b4_pure_flag], [[2]])])
-
-m4_define([b4_pure_if],
-[m4_case(b4_pure_flag,
- [0], [$2],
- [1], [$1],
- [2], [$1])])
- [m4_fatal([invalid api.pure value: ]$1)])])
-
-# b4_yyerror_arg_loc_if(ARG)
-# --------------------------
-# Expand ARG iff yyerror is to be given a location as argument.
-m4_define([b4_yyerror_arg_loc_if],
-[b4_locations_if([m4_case(b4_pure_flag,
- [1], [m4_ifset([b4_parse_param], [$1])],
- [2], [$1])])])
-
-# b4_yyerror_args
-# ---------------
-# Arguments passed to yyerror: user args plus yylloc.
-m4_define([b4_yyerror_args],
-[b4_yyerror_arg_loc_if([&yylloc, ])dnl
-m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
-
-
-
-## ------------ ##
-## Data Types. ##
-## ------------ ##
-
-# b4_int_type(MIN, MAX)
-# ---------------------
-# Return the smallest int type able to handle numbers ranging from
-# MIN to MAX (included). Overwrite the version from c.m4, which
-# uses only C89 types, so that the user can override the shorter
-# types, and so that pre-C89 compilers are handled correctly.
-m4_define([b4_int_type],
-[m4_if(b4_ints_in($@, [0], [255]), [1], [yytype_uint8],
- b4_ints_in($@, [-128], [127]), [1], [yytype_int8],
-
- b4_ints_in($@, [0], [65535]), [1], [yytype_uint16],
- b4_ints_in($@, [-32768], [32767]), [1], [yytype_int16],
-
- m4_eval([0 <= $1]), [1], [unsigned int],
-
- [int])])
-
-
-## ----------------- ##
-## Semantic Values. ##
-## ----------------- ##
-
-
-# b4_lhs_value([TYPE])
-# --------------------
-# Expansion of $<TYPE>$.
-m4_define([b4_lhs_value],
-[b4_symbol_value(yyval, [$1])])
-
-
-# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
-# --------------------------------------
-# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
-# symbols on RHS.
-m4_define([b4_rhs_value],
- [b4_symbol_value([yyvsp@{b4_subtract([$2], [$1])@}], [$3])])
-
-
-## ----------- ##
-## Locations. ##
-## ----------- ##
-
-# b4_lhs_location()
-# -----------------
-# Expansion of @$.
-m4_define([b4_lhs_location],
-[(yyloc)])
-
-
-# b4_rhs_location(RULE-LENGTH, NUM)
-# ---------------------------------
-# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
-# on RHS.
-m4_define([b4_rhs_location],
- [(yylsp@{b4_subtract([$2], [$1])@})])
-
-
-## -------------- ##
-## Declarations. ##
-## -------------- ##
-
-# b4_declare_scanner_communication_variables
-# ------------------------------------------
-# Declare the variables that are global, or local to YYPARSE if
-# pure-parser.
-m4_define([b4_declare_scanner_communication_variables], [[
-/* The lookahead symbol. */
-int yychar;
-
-]b4_pure_if([[
-/* The semantic value of the lookahead symbol. */
-/* Default value used for initialization, for pacifying older GCCs
- or non-GCC compilers. */
-YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
-YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);]b4_locations_if([[
-
-/* Location data for the lookahead symbol. */
-static YYLTYPE yyloc_default]b4_yyloc_default[;
-YYLTYPE yylloc = yyloc_default;]])],
-[[/* The semantic value of the lookahead symbol. */
-YYSTYPE yylval;]b4_locations_if([[
-/* Location data for the lookahead symbol. */
-YYLTYPE yylloc]b4_yyloc_default[;]])[
-/* Number of syntax errors so far. */
-int yynerrs;]])])
-
-
-# b4_declare_parser_state_variables
-# ---------------------------------
-# Declare all the variables that are needed to maintain the parser state
-# between calls to yypush_parse.
-m4_define([b4_declare_parser_state_variables], [b4_pure_if([[
- /* Number of syntax errors so far. */
- int yynerrs;
-]])[
- int yystate;
- /* Number of tokens to shift before error messages enabled. */
- int yyerrstatus;
-
- /* The stacks and their tools:
- 'yyss': related to states.
- 'yyvs': related to semantic values.]b4_locations_if([[
- 'yyls': related to locations.]])[
-
- Refer to the stacks through separate pointers, to allow yyoverflow
- to reallocate them elsewhere. */
-
- /* The state stack. */
- yytype_int16 yyssa[YYINITDEPTH];
- yytype_int16 *yyss;
- yytype_int16 *yyssp;
-
- /* The semantic value stack. */
- YYSTYPE yyvsa[YYINITDEPTH];
- YYSTYPE *yyvs;
- YYSTYPE *yyvsp;]b4_locations_if([[
-
- /* The location stack. */
- YYLTYPE yylsa[YYINITDEPTH];
- YYLTYPE *yyls;
- YYLTYPE *yylsp;
-
- /* The locations where the error started and ended. */
- YYLTYPE yyerror_range[3];]])[
-
- YYSIZE_T yystacksize;]b4_lac_if([[
-
- yytype_int16 yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@};
- yytype_int16 *yyes;
- YYSIZE_T yyes_capacity;]])])
-
-
-# b4_declare_yyparse_push_
-# ------------------------
-# Declaration of yyparse (and dependencies) when using the push parser
-# (including in pull mode).
-m4_define([b4_declare_yyparse_push_],
-[[#ifndef YYPUSH_MORE_DEFINED
-# define YYPUSH_MORE_DEFINED
-enum { YYPUSH_MORE = 4 };
-#endif
-
-typedef struct ]b4_prefix[pstate ]b4_prefix[pstate;
-
-]b4_pull_if([b4_function_declare([b4_prefix[parse]], [[int]], b4_parse_param)
-])b4_function_declare([b4_prefix[push_parse]], [[int]],
- [[b4_prefix[pstate *ps]], [[ps]]]b4_pure_if([,
- [[[int pushed_char]], [[pushed_char]]],
- [[b4_api_PREFIX[STYPE const *pushed_val]], [[pushed_val]]]b4_locations_if([,
- [[b4_api_PREFIX[LTYPE *pushed_loc]], [[pushed_loc]]]])])m4_ifset([b4_parse_param], [,
- b4_parse_param]))
-b4_pull_if([b4_function_declare([b4_prefix[pull_parse]], [[int]],
- [[b4_prefix[pstate *ps]], [[ps]]]m4_ifset([b4_parse_param], [,
- b4_parse_param]))])
-b4_function_declare([b4_prefix[pstate_new]], [b4_prefix[pstate *]],
- [[[void]], []])
-b4_function_declare([b4_prefix[pstate_delete]], [[void]],
- [[b4_prefix[pstate *ps]], [[ps]]])dnl
-])
-
-# b4_declare_yyparse_
-# -------------------
-# When not the push parser.
-m4_define([b4_declare_yyparse_],
-[b4_function_declare(b4_prefix[parse], [int], b4_parse_param)])
-
-
-# b4_declare_yyparse
-# ------------------
-m4_define([b4_declare_yyparse],
-[b4_push_if([b4_declare_yyparse_push_],
- [b4_declare_yyparse_])[]dnl
-])
-
-
-# b4_shared_declarations
-# ----------------------
-# Declaration that might either go into the header (if --defines)
-# or open coded in the parser body.
-m4_define([b4_shared_declarations],
-[b4_cpp_guard_open([b4_spec_defines_file])[
-]b4_declare_yydebug[
-]b4_percent_code_get([[requires]])[
-]b4_token_enums_defines[
-]b4_declare_yylstype[
-]b4_declare_yyparse[
-]b4_percent_code_get([[provides]])[
-]b4_cpp_guard_close([b4_spec_defines_file])[]dnl
-])
-
-## -------------- ##
-## Output files. ##
-## -------------- ##
-
-b4_output_begin([b4_parser_file_name])
-b4_copyright([Bison implementation for Yacc-like parsers in C])[
-
-/* C LALR(1) parser skeleton written by Richard Stallman, by
- simplifying the original so-called "semantic" parser. */
-
-/* All symbols defined below should begin with yy or YY, to avoid
- infringing on user name space. This should be done even for local
- variables, as they might otherwise be expanded by user macros.
- There are some unavoidable exceptions within include files to
- define necessary library symbols; they are noted "INFRINGES ON
- USER NAME SPACE" below. */
-
-]b4_identification
-b4_percent_code_get([[top]])[]dnl
-m4_if(b4_api_prefix, [yy], [],
-[[/* Substitute the type names. */
-#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
-#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
-]m4_if(b4_prefix, [yy], [],
-[[/* Substitute the variable and function names. */]b4_pull_if([[
-#define yyparse ]b4_prefix[parse]])b4_push_if([[
-#define yypush_parse ]b4_prefix[push_parse]b4_pull_if([[
-#define yypull_parse ]b4_prefix[pull_parse]])[
-#define yypstate_new ]b4_prefix[pstate_new
-#define yypstate_delete ]b4_prefix[pstate_delete
-#define yypstate ]b4_prefix[pstate]])[
-#define yylex ]b4_prefix[lex
-#define yyerror ]b4_prefix[error
-#define yydebug ]b4_prefix[debug
-#define yynerrs ]b4_prefix[nerrs
-]]b4_pure_if([], [[
-#define yylval ]b4_prefix[lval
-#define yychar ]b4_prefix[char]b4_locations_if([[
-#define yylloc ]b4_prefix[lloc]])]))[
-
-/* Copy the first part of user declarations. */
-]b4_user_pre_prologue[
-
-]b4_null_define[
-
-/* Enabling verbose error messages. */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
-#endif
-
-]m4_ifval(m4_quote(b4_spec_defines_file),
-[[/* In a future release of Bison, this section will be replaced
- by #include "@basename(]b4_spec_defines_file[@)". */
-]])dnl
-b4_shared_declarations[
-
-/* Copy the second part of user declarations. */
-]b4_user_post_prologue
-b4_percent_code_get[]dnl
-
-[#ifdef short
-# undef short
-#endif
-
-#ifdef YYTYPE_UINT8
-typedef YYTYPE_UINT8 yytype_uint8;
-#else
-typedef unsigned char yytype_uint8;
-#endif
-
-#ifdef YYTYPE_INT8
-typedef YYTYPE_INT8 yytype_int8;
-#else
-typedef signed char yytype_int8;
-#endif
-
-#ifdef YYTYPE_UINT16
-typedef YYTYPE_UINT16 yytype_uint16;
-#else
-typedef unsigned short int yytype_uint16;
-#endif
-
-#ifdef YYTYPE_INT16
-typedef YYTYPE_INT16 yytype_int16;
-#else
-typedef short int yytype_int16;
-#endif
-
-#ifndef YYSIZE_T
-# ifdef __SIZE_TYPE__
-# define YYSIZE_T __SIZE_TYPE__
-# elif defined size_t
-# define YYSIZE_T size_t
-# elif ! defined YYSIZE_T
-# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
-# else
-# define YYSIZE_T unsigned int
-# endif
-#endif
-
-#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
-
-#ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
-# if ENABLE_NLS
-# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
-# endif
-# endif
-# ifndef YY_
-# define YY_(Msgid) Msgid
-# endif
-#endif
-
-]b4_attribute_define[
-
-#if ]b4_lac_if([[1]], [[! defined yyoverflow || YYERROR_VERBOSE]])[
-
-/* The parser invokes alloca or malloc; define the necessary symbols. */]dnl
-b4_push_if([], [b4_lac_if([], [[
-
-# ifdef YYSTACK_USE_ALLOCA
-# if YYSTACK_USE_ALLOCA
-# ifdef __GNUC__
-# define YYSTACK_ALLOC __builtin_alloca
-# elif defined __BUILTIN_VA_ARG_INCR
-# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
-# elif defined _AIX
-# define YYSTACK_ALLOC __alloca
-# elif defined _MSC_VER
-# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
-# define alloca _alloca
-# else
-# define YYSTACK_ALLOC alloca
-# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
-# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
- /* Use EXIT_SUCCESS as a witness for stdlib.h. */
-# ifndef EXIT_SUCCESS
-# define EXIT_SUCCESS 0
-# endif
-# endif
-# endif
-# endif
-# endif]])])[
-
-# ifdef YYSTACK_ALLOC
- /* Pacify GCC's 'empty if-body' warning. */
-# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
-# ifndef YYSTACK_ALLOC_MAXIMUM
- /* The OS might guarantee only one guard page at the bottom of the stack,
- and a page size can be as small as 4096 bytes. So we cannot safely
- invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
- to allow for a few compiler-allocated temporary stack slots. */
-# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
-# endif
-# else
-# define YYSTACK_ALLOC YYMALLOC
-# define YYSTACK_FREE YYFREE
-# ifndef YYSTACK_ALLOC_MAXIMUM
-# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
-# endif
-# if (defined __cplusplus && ! defined EXIT_SUCCESS \
- && ! ((defined YYMALLOC || defined malloc) \
- && (defined YYFREE || defined free)))
-# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-# ifndef EXIT_SUCCESS
-# define EXIT_SUCCESS 0
-# endif
-# endif
-# ifndef YYMALLOC
-# define YYMALLOC malloc
-# if ! defined malloc && ! defined EXIT_SUCCESS
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
-# endif
-# endif
-# ifndef YYFREE
-# define YYFREE free
-# if ! defined free && ! defined EXIT_SUCCESS
-void free (void *); /* INFRINGES ON USER NAME SPACE */
-# endif
-# endif
-# endif]b4_lac_if([[
-# define YYCOPY_NEEDED 1]])[
-#endif]b4_lac_if([], [[ /* ! defined yyoverflow || YYERROR_VERBOSE */]])[
-
-
-#if (! defined yyoverflow \
- && (! defined __cplusplus \
- || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
- && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL)))
-
-/* A type that is properly aligned for any stack member. */
-union yyalloc
-{
- yytype_int16 yyss_alloc;
- YYSTYPE yyvs_alloc;]b4_locations_if([
- YYLTYPE yyls_alloc;])[
-};
-
-/* The size of the maximum gap between one aligned stack and the next. */
-# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
-
-/* The size of an array large to enough to hold all stacks, each with
- N elements. */
-]b4_locations_if(
-[# define YYSTACK_BYTES(N) \
- ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
- + 2 * YYSTACK_GAP_MAXIMUM)],
-[# define YYSTACK_BYTES(N) \
- ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
- + YYSTACK_GAP_MAXIMUM)])[
-
-# define YYCOPY_NEEDED 1
-
-/* Relocate STACK from its old location to the new one. The
- local variables YYSIZE and YYSTACKSIZE give the old and new number of
- elements in the stack, and YYPTR gives the new location of the
- stack. Advance YYPTR to a properly aligned location for the next
- stack. */
-# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
- do \
- { \
- YYSIZE_T yynewbytes; \
- YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
- Stack = &yyptr->Stack_alloc; \
- yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
- yyptr += yynewbytes / sizeof (*yyptr); \
- } \
- while (0)
-
-#endif
-
-#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
-/* Copy COUNT objects from SRC to DST. The source and destination do
- not overlap. */
-# ifndef YYCOPY
-# if defined __GNUC__ && 1 < __GNUC__
-# define YYCOPY(Dst, Src, Count) \
- __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
-# else
-# define YYCOPY(Dst, Src, Count) \
- do \
- { \
- YYSIZE_T yyi; \
- for (yyi = 0; yyi < (Count); yyi++) \
- (Dst)[yyi] = (Src)[yyi]; \
- } \
- while (0)
-# endif
-# endif
-#endif /* !YYCOPY_NEEDED */
-
-/* YYFINAL -- State number of the termination state. */
-#define YYFINAL ]b4_final_state_number[
-/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST ]b4_last[
-
-/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS ]b4_tokens_number[
-/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS ]b4_nterms_number[
-/* YYNRULES -- Number of rules. */
-#define YYNRULES ]b4_rules_number[
-/* YYNSTATES -- Number of states. */
-#define YYNSTATES ]b4_states_number[
-
-/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
- by yylex, with out-of-bounds checking. */
-#define YYUNDEFTOK ]b4_undef_token_number[
-#define YYMAXUTOK ]b4_user_token_number_max[
-
-#define YYTRANSLATE(YYX) \
- ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-
-/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
- as returned by yylex, without out-of-bounds checking. */
-static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
-{
- ]b4_translate[
-};
-
-#if ]b4_api_PREFIX[DEBUG
-]b4_integral_parser_table_define([rline], [b4_rline],
- [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
-#endif
-
-#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
-/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
-{
- ]b4_tname[
-};
-#endif
-
-# ifdef YYPRINT
-/* YYTOKNUM[NUM] -- (External) token number corresponding to the
- (internal) symbol number NUM (which must be that of a token). */
-static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
-{
- ]b4_toknum[
-};
-# endif
-
-#define YYPACT_NINF ]b4_pact_ninf[
-
-#define yypact_value_is_default(Yystate) \
- ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
-
-#define YYTABLE_NINF ]b4_table_ninf[
-
-#define yytable_value_is_error(Yytable_value) \
- ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
-
-]b4_parser_tables_define[
-
-#define yyerrok (yyerrstatus = 0)
-#define yyclearin (yychar = YYEMPTY)
-#define YYEMPTY (-2)
-#define YYEOF 0
-
-#define YYACCEPT goto yyacceptlab
-#define YYABORT goto yyabortlab
-#define YYERROR goto yyerrorlab
-
-
-#define YYRECOVERING() (!!yyerrstatus)
-
-#define YYBACKUP(Token, Value) \
-do \
- if (yychar == YYEMPTY) \
- { \
- yychar = (Token); \
- yylval = (Value); \
- YYPOPSTACK (yylen); \
- yystate = *yyssp; \]b4_lac_if([[
- YY_LAC_DISCARD ("YYBACKUP"); \]])[
- goto yybackup; \
- } \
- else \
- { \
- yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")); \
- YYERROR; \
- } \
-while (0)
-
-/* Error token number */
-#define YYTERROR 1
-#define YYERRCODE 256
-
-]b4_locations_if([[
-]b4_yylloc_default_define[
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-]])[
-
-/* Enable debugging if requested. */
-#if ]b4_api_PREFIX[DEBUG
-
-# ifndef YYFPRINTF
-# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
-# define YYFPRINTF fprintf
-# endif
-
-# define YYDPRINTF(Args) \
-do { \
- if (yydebug) \
- YYFPRINTF Args; \
-} while (0)
-
-]b4_yy_location_print_define[
-
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
-do { \
- if (yydebug) \
- { \
- YYFPRINTF (stderr, "%s ", Title); \
- yy_symbol_print (stderr, \
- Type, Value]b4_locations_if([, Location])[]b4_user_args[); \
- YYFPRINTF (stderr, "\n"); \
- } \
-} while (0)
-
-]b4_yy_symbol_print_define[
-
-/*------------------------------------------------------------------.
-| yy_stack_print -- Print the state stack from its BOTTOM up to its |
-| TOP (included). |
-`------------------------------------------------------------------*/
-
-]b4_function_define([yy_stack_print], [static void],
- [[yytype_int16 *yybottom], [yybottom]],
- [[yytype_int16 *yytop], [yytop]])[
-{
- YYFPRINTF (stderr, "Stack now");
- for (; yybottom <= yytop; yybottom++)
- {
- int yybot = *yybottom;
- YYFPRINTF (stderr, " %d", yybot);
- }
- YYFPRINTF (stderr, "\n");
-}
-
-# define YY_STACK_PRINT(Bottom, Top) \
-do { \
- if (yydebug) \
- yy_stack_print ((Bottom), (Top)); \
-} while (0)
-
-
-/*------------------------------------------------.
-| Report that the YYRULE is going to be reduced. |
-`------------------------------------------------*/
-
-]b4_function_define([yy_reduce_print], [static void],
- [[yytype_int16 *yyssp], [yyssp]],
- [[YYSTYPE *yyvsp], [yyvsp]],
- b4_locations_if([[[YYLTYPE *yylsp], [yylsp]],
- ])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [,
- b4_parse_param]))[
-{
- unsigned long int yylno = yyrline[yyrule];
- int yynrhs = yyr2[yyrule];
- int yyi;
- YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
- yyrule - 1, yylno);
- /* The symbols being reduced. */
- for (yyi = 0; yyi < yynrhs; yyi++)
- {
- YYFPRINTF (stderr, " $%d = ", yyi + 1);
- yy_symbol_print (stderr,
- yystos[yyssp[yyi + 1 - yynrhs]],
- &]b4_rhs_value(yynrhs, yyi + 1)[
- ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
- b4_user_args[);
- YYFPRINTF (stderr, "\n");
- }
-}
-
-# define YY_REDUCE_PRINT(Rule) \
-do { \
- if (yydebug) \
- yy_reduce_print (yyssp, yyvsp, ]b4_locations_if([yylsp, ])[Rule]b4_user_args[); \
-} while (0)
-
-/* Nonzero means print parse trace. It is left uninitialized so that
- multiple parsers can coexist. */
-int yydebug;
-#else /* !]b4_api_PREFIX[DEBUG */
-# define YYDPRINTF(Args)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
-# define YY_STACK_PRINT(Bottom, Top)
-# define YY_REDUCE_PRINT(Rule)
-#endif /* !]b4_api_PREFIX[DEBUG */
-
-
-/* YYINITDEPTH -- initial size of the parser's stacks. */
-#ifndef YYINITDEPTH
-# define YYINITDEPTH ]b4_stack_depth_init[
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
- if the built-in stack extension method is used).
-
- Do not make this value too large; the results are undefined if
- YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
- evaluated with infinite-precision integer arithmetic. */
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH ]b4_stack_depth_max[
-#endif]b4_lac_if([[
-
-
-/* Given a state stack such that *YYBOTTOM is its bottom, such that
- *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty
- stack, and such that *YYCAPACITY is the maximum number of elements it
- can hold without a reallocation, make sure there is enough room to
- store YYADD more elements. If not, allocate a new stack using
- YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM,
- *YYTOP, and *YYCAPACITY to reflect the new capacity and memory
- location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack
- using YYSTACK_FREE. Return 0 if successful or if no reallocation is
- required. Return 1 if memory is exhausted. */
-static int
-yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
-#if ]b4_api_PREFIX[DEBUG
- char const *yydebug_prefix,
- char const *yydebug_suffix,
-#endif
- yytype_int16 **yybottom,
- yytype_int16 *yybottom_no_free,
- yytype_int16 **yytop, yytype_int16 *yytop_empty)
-{
- YYSIZE_T yysize_old =
- *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
- YYSIZE_T yysize_new = yysize_old + yyadd;
- if (*yycapacity < yysize_new)
- {
- YYSIZE_T yyalloc = 2 * yysize_new;
- yytype_int16 *yybottom_new;
- /* Use YYMAXDEPTH for maximum stack size given that the stack
- should never need to grow larger than the main state stack
- needs to grow without LAC. */
- if (YYMAXDEPTH < yysize_new)
- {
- YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix,
- yydebug_suffix));
- return 1;
- }
- if (YYMAXDEPTH < yyalloc)
- yyalloc = YYMAXDEPTH;
- yybottom_new =
- (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new);
- if (!yybottom_new)
- {
- YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
- yydebug_suffix));
- return 1;
- }
- if (*yytop != yytop_empty)
- {
- YYCOPY (yybottom_new, *yybottom, yysize_old);
- *yytop = yybottom_new + (yysize_old - 1);
- }
- if (*yybottom != yybottom_no_free)
- YYSTACK_FREE (*yybottom);
- *yybottom = yybottom_new;
- *yycapacity = yyalloc;]m4_if(b4_percent_define_get([[parse.lac.memory-trace]]),
- [full], [[
- YYDPRINTF ((stderr, "%srealloc to %lu%s", yydebug_prefix,
- (unsigned long int) yyalloc, yydebug_suffix));]])[
- }
- return 0;
-}
-
-/* Establish the initial context for the current lookahead if no initial
- context is currently established.
-
- We define a context as a snapshot of the parser stacks. We define
- the initial context for a lookahead as the context in which the
- parser initially examines that lookahead in order to select a
- syntactic action. Thus, if the lookahead eventually proves
- syntactically unacceptable (possibly in a later context reached via a
- series of reductions), the initial context can be used to determine
- the exact set of tokens that would be syntactically acceptable in the
- lookahead's place. Moreover, it is the context after which any
- further semantic actions would be erroneous because they would be
- determined by a syntactically unacceptable token.
-
- YY_LAC_ESTABLISH should be invoked when a reduction is about to be
- performed in an inconsistent state (which, for the purposes of LAC,
- includes consistent states that don't know they're consistent because
- their default reductions have been disabled). Iff there is a
- lookahead token, it should also be invoked before reporting a syntax
- error. This latter case is for the sake of the debugging output.
-
- For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as
- follows. If no initial context is currently established for the
- current lookahead, then check if that lookahead can eventually be
- shifted if syntactic actions continue from the current context.
- Report a syntax error if it cannot. */
-#define YY_LAC_ESTABLISH \
-do { \
- if (!yy_lac_established) \
- { \
- YYDPRINTF ((stderr, \
- "LAC: initial context established for %s\n", \
- yytname[yytoken])); \
- yy_lac_established = 1; \
- { \
- int yy_lac_status = \
- yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken); \
- if (yy_lac_status == 2) \
- goto yyexhaustedlab; \
- if (yy_lac_status == 1) \
- goto yyerrlab; \
- } \
- } \
-} while (0)
-
-/* Discard any previous initial lookahead context because of Event,
- which may be a lookahead change or an invalidation of the currently
- established initial context for the current lookahead.
-
- The most common example of a lookahead change is a shift. An example
- of both cases is syntax error recovery. That is, a syntax error
- occurs when the lookahead is syntactically erroneous for the
- currently established initial context, so error recovery manipulates
- the parser stacks to try to find a new initial context in which the
- current lookahead is syntactically acceptable. If it fails to find
- such a context, it discards the lookahead. */
-#if ]b4_api_PREFIX[DEBUG
-# define YY_LAC_DISCARD(Event) \
-do { \
- if (yy_lac_established) \
- { \
- if (yydebug) \
- YYFPRINTF (stderr, "LAC: initial context discarded due to " \
- Event "\n"); \
- yy_lac_established = 0; \
- } \
-} while (0)
-#else
-# define YY_LAC_DISCARD(Event) yy_lac_established = 0
-#endif
-
-/* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can
- eventually (after perhaps some reductions) be shifted, return 1 if
- not, or return 2 if memory is exhausted. As preconditions and
- postconditions: *YYES_CAPACITY is the allocated size of the array to
- which *YYES points, and either *YYES = YYESA or *YYES points to an
- array allocated with YYSTACK_ALLOC. yy_lac may overwrite the
- contents of either array, alter *YYES and *YYES_CAPACITY, and free
- any old *YYES other than YYESA. */
-static int
-yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
- YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
-{
- yytype_int16 *yyes_prev = yyssp;
- yytype_int16 *yyesp = yyes_prev;
- YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken]));
- if (yytoken == YYUNDEFTOK)
- {
- YYDPRINTF ((stderr, " Always Err\n"));
- return 1;
- }
- while (1)
- {
- int yyrule = yypact[*yyesp];
- if (yypact_value_is_default (yyrule)
- || (yyrule += yytoken) < 0 || YYLAST < yyrule
- || yycheck[yyrule] != yytoken)
- {
- yyrule = yydefact[*yyesp];
- if (yyrule == 0)
- {
- YYDPRINTF ((stderr, " Err\n"));
- return 1;
- }
- }
- else
- {
- yyrule = yytable[yyrule];
- if (yytable_value_is_error (yyrule))
- {
- YYDPRINTF ((stderr, " Err\n"));
- return 1;
- }
- if (0 < yyrule)
- {
- YYDPRINTF ((stderr, " S%d\n", yyrule));
- return 0;
- }
- yyrule = -yyrule;
- }
- {
- YYSIZE_T yylen = yyr2[yyrule];
- YYDPRINTF ((stderr, " R%d", yyrule - 1));
- if (yyesp != yyes_prev)
- {
- YYSIZE_T yysize = yyesp - *yyes + 1;
- if (yylen < yysize)
- {
- yyesp -= yylen;
- yylen = 0;
- }
- else
- {
- yylen -= yysize;
- yyesp = yyes_prev;
- }
- }
- if (yylen)
- yyesp = yyes_prev -= yylen;
- }
- {
- int yystate;
- {
- int yylhs = yyr1[yyrule] - YYNTOKENS;
- yystate = yypgoto[yylhs] + *yyesp;
- if (yystate < 0 || YYLAST < yystate
- || yycheck[yystate] != *yyesp)
- yystate = yydefgoto[yylhs];
- else
- yystate = yytable[yystate];
- }
- if (yyesp == yyes_prev)
- {
- yyesp = *yyes;
- *yyesp = yystate;
- }
- else
- {
- if (yy_lac_stack_realloc (yyes_capacity, 1,
-#if ]b4_api_PREFIX[DEBUG
- " (", ")",
-#endif
- yyes, yyesa, &yyesp, yyes_prev))
- {
- YYDPRINTF ((stderr, "\n"));
- return 2;
- }
- *++yyesp = yystate;
- }
- YYDPRINTF ((stderr, " G%d", yystate));
- }
- }
-}]])[
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystrlen
-# if defined __GLIBC__ && defined _STRING_H
-# define yystrlen strlen
-# else
-/* Return the length of YYSTR. */
-]b4_function_define([yystrlen], [static YYSIZE_T],
- [[const char *yystr], [yystr]])[
-{
- YYSIZE_T yylen;
- for (yylen = 0; yystr[yylen]; yylen++)
- continue;
- return yylen;
-}
-# endif
-# endif
-
-# ifndef yystpcpy
-# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
-# define yystpcpy stpcpy
-# else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
- YYDEST. */
-]b4_function_define([yystpcpy], [static char *],
- [[char *yydest], [yydest]], [[const char *yysrc], [yysrc]])[
-{
- char *yyd = yydest;
- const char *yys = yysrc;
-
- while ((*yyd++ = *yys++) != '\0')
- continue;
-
- return yyd - 1;
-}
-# endif
-# endif
-
-# ifndef yytnamerr
-/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
- quotes and backslashes, so that it's suitable for yyerror. The
- heuristic is that double-quoting is unnecessary unless the string
- contains an apostrophe, a comma, or backslash (other than
- backslash-backslash). YYSTR is taken from yytname. If YYRES is
- null, do not copy; instead, return the length of what the result
- would have been. */
+ -*- C -*-
+# Yacc compatible skeleton for Bison
+
+# Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation,
+# Inc.
+
+m4_pushdef([b4_copyright_years],
+ [1984, 1989-1990, 2000-2013])
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Check the value of %define api.push-pull.
+b4_percent_define_default([[api.push-pull]], [[pull]])
+b4_percent_define_check_values([[[[api.push-pull]],
+ [[pull]], [[push]], [[both]]]])
+b4_define_flag_if([pull]) m4_define([b4_pull_flag], [[1]])
+b4_define_flag_if([push]) m4_define([b4_push_flag], [[1]])
+m4_case(b4_percent_define_get([[api.push-pull]]),
+ [pull], [m4_define([b4_push_flag], [[0]])],
+ [push], [m4_define([b4_pull_flag], [[0]])])
+
+# Handle BISON_USE_PUSH_FOR_PULL for the test suite. So that push parsing
+# tests function as written, do not let BISON_USE_PUSH_FOR_PULL modify the
+# behavior of Bison at all when push parsing is already requested.
+b4_define_flag_if([use_push_for_pull])
+b4_use_push_for_pull_if([
+ b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])],
+ [m4_define([b4_push_flag], [[1]])])])
+
+# Check the value of %define parse.lac and friends, where LAC stands for
+# lookahead correction.
+b4_percent_define_default([[parse.lac]], [[none]])
+b4_percent_define_default([[parse.lac.es-capacity-initial]], [[20]])
+b4_percent_define_default([[parse.lac.memory-trace]], [[failures]])
+b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]],
+ [[[[parse.lac.memory-trace]],
+ [[failures]], [[full]]]])
+b4_define_flag_if([lac])
+m4_define([b4_lac_flag],
+ [m4_if(b4_percent_define_get([[parse.lac]]),
+ [none], [[0]], [[1]])])
+
+m4_include(b4_pkgdatadir/[c.m4])
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# Stack parameters.
+m4_define_default([b4_stack_depth_max], [10000])
+m4_define_default([b4_stack_depth_init], [200])
+
+
+## ------------------------ ##
+## Pure/impure interfaces. ##
+## ------------------------ ##
+
+b4_percent_define_default([[api.pure]], [[false]])
+b4_percent_define_check_values([[[[api.pure]],
+ [[false]], [[true]], [[]], [[full]]]])
+
+m4_define([b4_pure_flag], [[0]])
+m4_case(b4_percent_define_get([[api.pure]]),
+ [false], [m4_define([b4_pure_flag], [[0]])],
+ [true], [m4_define([b4_pure_flag], [[1]])],
+ [], [m4_define([b4_pure_flag], [[1]])],
+ [full], [m4_define([b4_pure_flag], [[2]])])
+
+m4_define([b4_pure_if],
+[m4_case(b4_pure_flag,
+ [0], [$2],
+ [1], [$1],
+ [2], [$1])])
+ [m4_fatal([invalid api.pure value: ]$1)])])
+
+# b4_yyerror_arg_loc_if(ARG)
+# --------------------------
+# Expand ARG iff yyerror is to be given a location as argument.
+m4_define([b4_yyerror_arg_loc_if],
+[b4_locations_if([m4_case(b4_pure_flag,
+ [1], [m4_ifset([b4_parse_param], [$1])],
+ [2], [$1])])])
+
+# b4_yyerror_args
+# ---------------
+# Arguments passed to yyerror: user args plus yylloc.
+m4_define([b4_yyerror_args],
+[b4_yyerror_arg_loc_if([&yylloc, ])dnl
+m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])])
+
+
+
+## ------------ ##
+## Data Types. ##
+## ------------ ##
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included). Overwrite the version from c.m4, which
+# uses only C89 types, so that the user can override the shorter
+# types, and so that pre-C89 compilers are handled correctly.
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@, [0], [255]), [1], [yytype_uint8],
+ b4_ints_in($@, [-128], [127]), [1], [yytype_int8],
+
+ b4_ints_in($@, [0], [65535]), [1], [yytype_uint16],
+ b4_ints_in($@, [-32768], [32767]), [1], [yytype_int16],
+
+ m4_eval([0 <= $1]), [1], [unsigned int],
+
+ [int])])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+# b4_lhs_value([TYPE])
+# --------------------
+# Expansion of $<TYPE>$.
+m4_define([b4_lhs_value],
+[b4_symbol_value(yyval, [$1])])
+
+
+# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
+# --------------------------------------
+# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
+# symbols on RHS.
+m4_define([b4_rhs_value],
+ [b4_symbol_value([yyvsp@{b4_subtract([$2], [$1])@}], [$3])])
+
+
+## ----------- ##
+## Locations. ##
+## ----------- ##
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+[(yyloc)])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+ [(yylsp@{b4_subtract([$2], [$1])@})])
+
+
+## -------------- ##
+## Declarations. ##
+## -------------- ##
+
+# b4_declare_scanner_communication_variables
+# ------------------------------------------
+# Declare the variables that are global, or local to YYPARSE if
+# pure-parser.
+m4_define([b4_declare_scanner_communication_variables], [[
+/* The lookahead symbol. */
+int yychar;
+
+]b4_pure_if([[
+/* The semantic value of the lookahead symbol. */
+/* Default value used for initialization, for pacifying older GCCs
+ or non-GCC compilers. */
+YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
+YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);]b4_locations_if([[
+
+/* Location data for the lookahead symbol. */
+static YYLTYPE yyloc_default]b4_yyloc_default[;
+YYLTYPE yylloc = yyloc_default;]])],
+[[/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;]b4_locations_if([[
+/* Location data for the lookahead symbol. */
+YYLTYPE yylloc]b4_yyloc_default[;]])[
+/* Number of syntax errors so far. */
+int yynerrs;]])])
+
+
+# b4_declare_parser_state_variables
+# ---------------------------------
+# Declare all the variables that are needed to maintain the parser state
+# between calls to yypush_parse.
+m4_define([b4_declare_parser_state_variables], [b4_pure_if([[
+ /* Number of syntax errors so far. */
+ int yynerrs;
+]])[
+ int yystate;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+
+ /* The stacks and their tools:
+ 'yyss': related to states.
+ 'yyvs': related to semantic values.]b4_locations_if([[
+ 'yyls': related to locations.]])[
+
+ Refer to the stacks through separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs;
+ YYSTYPE *yyvsp;]b4_locations_if([[
+
+ /* The location stack. */
+ YYLTYPE yylsa[YYINITDEPTH];
+ YYLTYPE *yyls;
+ YYLTYPE *yylsp;
+
+ /* The locations where the error started and ended. */
+ YYLTYPE yyerror_range[3];]])[
+
+ YYSIZE_T yystacksize;]b4_lac_if([[
+
+ yytype_int16 yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@};
+ yytype_int16 *yyes;
+ YYSIZE_T yyes_capacity;]])])
+
+
+# b4_declare_yyparse_push_
+# ------------------------
+# Declaration of yyparse (and dependencies) when using the push parser
+# (including in pull mode).
+m4_define([b4_declare_yyparse_push_],
+[[#ifndef YYPUSH_MORE_DEFINED
+# define YYPUSH_MORE_DEFINED
+enum { YYPUSH_MORE = 4 };
+#endif
+
+typedef struct ]b4_prefix[pstate ]b4_prefix[pstate;
+
+]b4_pull_if([b4_function_declare([b4_prefix[parse]], [[int]], b4_parse_param)
+])b4_function_declare([b4_prefix[push_parse]], [[int]],
+ [[b4_prefix[pstate *ps]], [[ps]]]b4_pure_if([,
+ [[[int pushed_char]], [[pushed_char]]],
+ [[b4_api_PREFIX[STYPE const *pushed_val]], [[pushed_val]]]b4_locations_if([,
+ [[b4_api_PREFIX[LTYPE *pushed_loc]], [[pushed_loc]]]])])m4_ifset([b4_parse_param], [,
+ b4_parse_param]))
+b4_pull_if([b4_function_declare([b4_prefix[pull_parse]], [[int]],
+ [[b4_prefix[pstate *ps]], [[ps]]]m4_ifset([b4_parse_param], [,
+ b4_parse_param]))])
+b4_function_declare([b4_prefix[pstate_new]], [b4_prefix[pstate *]],
+ [[[void]], []])
+b4_function_declare([b4_prefix[pstate_delete]], [[void]],
+ [[b4_prefix[pstate *ps]], [[ps]]])dnl
+])
+
+# b4_declare_yyparse_
+# -------------------
+# When not the push parser.
+m4_define([b4_declare_yyparse_],
+[b4_function_declare(b4_prefix[parse], [int], b4_parse_param)])
+
+
+# b4_declare_yyparse
+# ------------------
+m4_define([b4_declare_yyparse],
+[b4_push_if([b4_declare_yyparse_push_],
+ [b4_declare_yyparse_])[]dnl
+])
+
+
+# b4_shared_declarations
+# ----------------------
+# Declaration that might either go into the header (if --defines)
+# or open coded in the parser body.
+m4_define([b4_shared_declarations],
+[b4_cpp_guard_open([b4_spec_defines_file])[
+]b4_declare_yydebug[
+]b4_percent_code_get([[requires]])[
+]b4_token_enums_defines[
+]b4_declare_yylstype[
+]b4_declare_yyparse[
+]b4_percent_code_get([[provides]])[
+]b4_cpp_guard_close([b4_spec_defines_file])[]dnl
+])
+
+## -------------- ##
+## Output files. ##
+## -------------- ##
+
+b4_output_begin([b4_parser_file_name])
+b4_copyright([Bison implementation for Yacc-like parsers in C])[
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+]b4_identification
+b4_percent_code_get([[top]])[]dnl
+m4_if(b4_api_prefix, [yy], [],
+[[/* Substitute the type names. */
+#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
+#define YYLTYPE ]b4_api_PREFIX[LTYPE]])])[
+]m4_if(b4_prefix, [yy], [],
+[[/* Substitute the variable and function names. */]b4_pull_if([[
+#define yyparse ]b4_prefix[parse]])b4_push_if([[
+#define yypush_parse ]b4_prefix[push_parse]b4_pull_if([[
+#define yypull_parse ]b4_prefix[pull_parse]])[
+#define yypstate_new ]b4_prefix[pstate_new
+#define yypstate_delete ]b4_prefix[pstate_delete
+#define yypstate ]b4_prefix[pstate]])[
+#define yylex ]b4_prefix[lex
+#define yyerror ]b4_prefix[error
+#define yydebug ]b4_prefix[debug
+#define yynerrs ]b4_prefix[nerrs
+]]b4_pure_if([], [[
+#define yylval ]b4_prefix[lval
+#define yychar ]b4_prefix[char]b4_locations_if([[
+#define yylloc ]b4_prefix[lloc]])]))[
+
+/* Copy the first part of user declarations. */
+]b4_user_pre_prologue[
+
+]b4_null_define[
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[
+#endif
+
+]m4_ifval(m4_quote(b4_spec_defines_file),
+[[/* In a future release of Bison, this section will be replaced
+ by #include "@basename(]b4_spec_defines_file[@)". */
+]])dnl
+b4_shared_declarations[
+
+/* Copy the second part of user declarations. */
+]b4_user_post_prologue
+b4_percent_code_get[]dnl
+
+[#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#else
+typedef signed char yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(Msgid) Msgid
+# endif
+#endif
+
+]b4_attribute_define[
+
+#if ]b4_lac_if([[1]], [[! defined yyoverflow || YYERROR_VERBOSE]])[
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */]dnl
+b4_push_if([], [b4_lac_if([], [[
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+ /* Use EXIT_SUCCESS as a witness for stdlib.h. */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# endif
+# endif
+# endif]])])[
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's 'empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined EXIT_SUCCESS \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined EXIT_SUCCESS
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined EXIT_SUCCESS
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif]b4_lac_if([[
+# define YYCOPY_NEEDED 1]])[
+#endif]b4_lac_if([], [[ /* ! defined yyoverflow || YYERROR_VERBOSE */]])[
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (]b4_locations_if([[defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL \
+ && ]])[defined ]b4_api_PREFIX[STYPE_IS_TRIVIAL && ]b4_api_PREFIX[STYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss_alloc;
+ YYSTYPE yyvs_alloc;]b4_locations_if([
+ YYLTYPE yyls_alloc;])[
+};
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+]b4_locations_if(
+[# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
+ + 2 * YYSTACK_GAP_MAXIMUM)],
+[# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)])[
+
+# define YYCOPY_NEEDED 1
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
+ Stack = &yyptr->Stack_alloc; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (0)
+
+#endif
+
+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
+/* Copy COUNT objects from SRC to DST. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(Dst, Src, Count) \
+ __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
+# else
+# define YYCOPY(Dst, Src, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (Dst)[yyi] = (Src)[yyi]; \
+ } \
+ while (0)
+# endif
+# endif
+#endif /* !YYCOPY_NEEDED */
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL ]b4_final_state_number[
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST ]b4_last[
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS ]b4_tokens_number[
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS ]b4_nterms_number[
+/* YYNRULES -- Number of rules. */
+#define YYNRULES ]b4_rules_number[
+/* YYNSTATES -- Number of states. */
+#define YYNSTATES ]b4_states_number[
+
+/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
+ by yylex, with out-of-bounds checking. */
+#define YYUNDEFTOK ]b4_undef_token_number[
+#define YYMAXUTOK ]b4_user_token_number_max[
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex, without out-of-bounds checking. */
+static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
+{
+ ]b4_translate[
+};
+
+#if ]b4_api_PREFIX[DEBUG
+]b4_integral_parser_table_define([rline], [b4_rline],
+ [[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
+#endif
+
+#if ]b4_api_PREFIX[DEBUG || YYERROR_VERBOSE || ]b4_token_table_flag[
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ ]b4_tname[
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[NUM] -- (External) token number corresponding to the
+ (internal) symbol number NUM (which must be that of a token). */
+static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
+{
+ ]b4_toknum[
+};
+# endif
+
+#define YYPACT_NINF ]b4_pact_ninf[
+
+#define yypact_value_is_default(Yystate) \
+ ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[
+
+#define YYTABLE_NINF ]b4_table_ninf[
+
+#define yytable_value_is_error(Yytable_value) \
+ ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
+
+]b4_parser_tables_define[
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ YYPOPSTACK (yylen); \
+ yystate = *yyssp; \]b4_lac_if([[
+ YY_LAC_DISCARD ("YYBACKUP"); \]])[
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (0)
+
+/* Error token number */
+#define YYTERROR 1
+#define YYERRCODE 256
+
+]b4_locations_if([[
+]b4_yylloc_default_define[
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+]])[
+
+/* Enable debugging if requested. */
+#if ]b4_api_PREFIX[DEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (0)
+
+]b4_yy_location_print_define[
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value]b4_locations_if([, Location])[]b4_user_args[); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (0)
+
+]b4_yy_symbol_print_define[
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+]b4_function_define([yy_stack_print], [static void],
+ [[yytype_int16 *yybottom], [yybottom]],
+ [[yytype_int16 *yytop], [yytop]])[
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; yybottom <= yytop; yybottom++)
+ {
+ int yybot = *yybottom;
+ YYFPRINTF (stderr, " %d", yybot);
+ }
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+]b4_function_define([yy_reduce_print], [static void],
+ [[yytype_int16 *yyssp], [yyssp]],
+ [[YYSTYPE *yyvsp], [yyvsp]],
+ b4_locations_if([[[YYLTYPE *yylsp], [yylsp]],
+ ])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [,
+ b4_parse_param]))[
+{
+ unsigned long int yylno = yyrline[yyrule];
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr,
+ yystos[yyssp[yyi + 1 - yynrhs]],
+ &]b4_rhs_value(yynrhs, yyi + 1)[
+ ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
+ b4_user_args[);
+ YYFPRINTF (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyssp, yyvsp, ]b4_locations_if([yylsp, ])[Rule]b4_user_args[); \
+} while (0)
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !]b4_api_PREFIX[DEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !]b4_api_PREFIX[DEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH ]b4_stack_depth_init[
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH ]b4_stack_depth_max[
+#endif]b4_lac_if([[
+
+
+/* Given a state stack such that *YYBOTTOM is its bottom, such that
+ *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty
+ stack, and such that *YYCAPACITY is the maximum number of elements it
+ can hold without a reallocation, make sure there is enough room to
+ store YYADD more elements. If not, allocate a new stack using
+ YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM,
+ *YYTOP, and *YYCAPACITY to reflect the new capacity and memory
+ location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack
+ using YYSTACK_FREE. Return 0 if successful or if no reallocation is
+ required. Return 1 if memory is exhausted. */
+static int
+yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
+#if ]b4_api_PREFIX[DEBUG
+ char const *yydebug_prefix,
+ char const *yydebug_suffix,
+#endif
+ yytype_int16 **yybottom,
+ yytype_int16 *yybottom_no_free,
+ yytype_int16 **yytop, yytype_int16 *yytop_empty)
+{
+ YYSIZE_T yysize_old =
+ *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
+ YYSIZE_T yysize_new = yysize_old + yyadd;
+ if (*yycapacity < yysize_new)
+ {
+ YYSIZE_T yyalloc = 2 * yysize_new;
+ yytype_int16 *yybottom_new;
+ /* Use YYMAXDEPTH for maximum stack size given that the stack
+ should never need to grow larger than the main state stack
+ needs to grow without LAC. */
+ if (YYMAXDEPTH < yysize_new)
+ {
+ YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix,
+ yydebug_suffix));
+ return 1;
+ }
+ if (YYMAXDEPTH < yyalloc)
+ yyalloc = YYMAXDEPTH;
+ yybottom_new =
+ (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new);
+ if (!yybottom_new)
+ {
+ YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
+ yydebug_suffix));
+ return 1;
+ }
+ if (*yytop != yytop_empty)
+ {
+ YYCOPY (yybottom_new, *yybottom, yysize_old);
+ *yytop = yybottom_new + (yysize_old - 1);
+ }
+ if (*yybottom != yybottom_no_free)
+ YYSTACK_FREE (*yybottom);
+ *yybottom = yybottom_new;
+ *yycapacity = yyalloc;]m4_if(b4_percent_define_get([[parse.lac.memory-trace]]),
+ [full], [[
+ YYDPRINTF ((stderr, "%srealloc to %lu%s", yydebug_prefix,
+ (unsigned long int) yyalloc, yydebug_suffix));]])[
+ }
+ return 0;
+}
+
+/* Establish the initial context for the current lookahead if no initial
+ context is currently established.
+
+ We define a context as a snapshot of the parser stacks. We define
+ the initial context for a lookahead as the context in which the
+ parser initially examines that lookahead in order to select a
+ syntactic action. Thus, if the lookahead eventually proves
+ syntactically unacceptable (possibly in a later context reached via a
+ series of reductions), the initial context can be used to determine
+ the exact set of tokens that would be syntactically acceptable in the
+ lookahead's place. Moreover, it is the context after which any
+ further semantic actions would be erroneous because they would be
+ determined by a syntactically unacceptable token.
+
+ YY_LAC_ESTABLISH should be invoked when a reduction is about to be
+ performed in an inconsistent state (which, for the purposes of LAC,
+ includes consistent states that don't know they're consistent because
+ their default reductions have been disabled). Iff there is a
+ lookahead token, it should also be invoked before reporting a syntax
+ error. This latter case is for the sake of the debugging output.
+
+ For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as
+ follows. If no initial context is currently established for the
+ current lookahead, then check if that lookahead can eventually be
+ shifted if syntactic actions continue from the current context.
+ Report a syntax error if it cannot. */
+#define YY_LAC_ESTABLISH \
+do { \
+ if (!yy_lac_established) \
+ { \
+ YYDPRINTF ((stderr, \
+ "LAC: initial context established for %s\n", \
+ yytname[yytoken])); \
+ yy_lac_established = 1; \
+ { \
+ int yy_lac_status = \
+ yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken); \
+ if (yy_lac_status == 2) \
+ goto yyexhaustedlab; \
+ if (yy_lac_status == 1) \
+ goto yyerrlab; \
+ } \
+ } \
+} while (0)
+
+/* Discard any previous initial lookahead context because of Event,
+ which may be a lookahead change or an invalidation of the currently
+ established initial context for the current lookahead.
+
+ The most common example of a lookahead change is a shift. An example
+ of both cases is syntax error recovery. That is, a syntax error
+ occurs when the lookahead is syntactically erroneous for the
+ currently established initial context, so error recovery manipulates
+ the parser stacks to try to find a new initial context in which the
+ current lookahead is syntactically acceptable. If it fails to find
+ such a context, it discards the lookahead. */
+#if ]b4_api_PREFIX[DEBUG
+# define YY_LAC_DISCARD(Event) \
+do { \
+ if (yy_lac_established) \
+ { \
+ if (yydebug) \
+ YYFPRINTF (stderr, "LAC: initial context discarded due to " \
+ Event "\n"); \
+ yy_lac_established = 0; \
+ } \
+} while (0)
+#else
+# define YY_LAC_DISCARD(Event) yy_lac_established = 0
+#endif
+
+/* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can
+ eventually (after perhaps some reductions) be shifted, return 1 if
+ not, or return 2 if memory is exhausted. As preconditions and
+ postconditions: *YYES_CAPACITY is the allocated size of the array to
+ which *YYES points, and either *YYES = YYESA or *YYES points to an
+ array allocated with YYSTACK_ALLOC. yy_lac may overwrite the
+ contents of either array, alter *YYES and *YYES_CAPACITY, and free
+ any old *YYES other than YYESA. */
+static int
+yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
+ YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
+{
+ yytype_int16 *yyes_prev = yyssp;
+ yytype_int16 *yyesp = yyes_prev;
+ YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken]));
+ if (yytoken == YYUNDEFTOK)
+ {
+ YYDPRINTF ((stderr, " Always Err\n"));
+ return 1;
+ }
+ while (1)
+ {
+ int yyrule = yypact[*yyesp];
+ if (yypact_value_is_default (yyrule)
+ || (yyrule += yytoken) < 0 || YYLAST < yyrule
+ || yycheck[yyrule] != yytoken)
+ {
+ yyrule = yydefact[*yyesp];
+ if (yyrule == 0)
+ {
+ YYDPRINTF ((stderr, " Err\n"));
+ return 1;
+ }
+ }
+ else
+ {
+ yyrule = yytable[yyrule];
+ if (yytable_value_is_error (yyrule))
+ {
+ YYDPRINTF ((stderr, " Err\n"));
+ return 1;
+ }
+ if (0 < yyrule)
+ {
+ YYDPRINTF ((stderr, " S%d\n", yyrule));
+ return 0;
+ }
+ yyrule = -yyrule;
+ }
+ {
+ YYSIZE_T yylen = yyr2[yyrule];
+ YYDPRINTF ((stderr, " R%d", yyrule - 1));
+ if (yyesp != yyes_prev)
+ {
+ YYSIZE_T yysize = yyesp - *yyes + 1;
+ if (yylen < yysize)
+ {
+ yyesp -= yylen;
+ yylen = 0;
+ }
+ else
+ {
+ yylen -= yysize;
+ yyesp = yyes_prev;
+ }
+ }
+ if (yylen)
+ yyesp = yyes_prev -= yylen;
+ }
+ {
+ int yystate;
+ {
+ int yylhs = yyr1[yyrule] - YYNTOKENS;
+ yystate = yypgoto[yylhs] + *yyesp;
+ if (yystate < 0 || YYLAST < yystate
+ || yycheck[yystate] != *yyesp)
+ yystate = yydefgoto[yylhs];
+ else
+ yystate = yytable[yystate];
+ }
+ if (yyesp == yyes_prev)
+ {
+ yyesp = *yyes;
+ *yyesp = yystate;
+ }
+ else
+ {
+ if (yy_lac_stack_realloc (yyes_capacity, 1,
+#if ]b4_api_PREFIX[DEBUG
+ " (", ")",
+#endif
+ yyes, yyesa, &yyesp, yyes_prev))
+ {
+ YYDPRINTF ((stderr, "\n"));
+ return 2;
+ }
+ *++yyesp = yystate;
+ }
+ YYDPRINTF ((stderr, " G%d", yystate));
+ }
+ }
+}]])[
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+]b4_function_define([yystrlen], [static YYSIZE_T],
+ [[const char *yystr], [yystr]])[
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+]b4_function_define([yystpcpy], [static char *],
+ [[char *yydest], [yydest]], [[const char *yysrc], [yysrc]])[
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
#ifdef __cplusplus
# define BISON_FALLTHROUGH [[fallthrough]]
#else
# define BISON_FALLTHROUGH
#endif
-static YYSIZE_T
-yytnamerr (char *yyres, const char *yystr)
-{
- if (*yystr == '"')
- {
- YYSIZE_T yyn = 0;
- char const *yyp = yystr;
-
- for (;;)
- switch (*++yyp)
- {
- case '\'':
- case ',':
- goto do_not_strip_quotes;
-
- case '\\':
- if (*++yyp != '\\')
- goto do_not_strip_quotes;
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
BISON_FALLTHROUGH;
- default:
- if (yyres)
- yyres[yyn] = *yyp;
- yyn++;
- break;
-
- case '"':
- if (yyres)
- yyres[yyn] = '\0';
- return yyn;
- }
- do_not_strip_quotes: ;
- }
-
- if (! yyres)
- return yystrlen (yystr);
-
- return yystpcpy (yyres, yystr) - yyres;
-}
-# endif
-
-/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
- about the unexpected token YYTOKEN for the state stack whose top is
- YYSSP.]b4_lac_if([[ In order to see if a particular token T is a
- valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).]])[
-
- Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
- not large enough to hold the message. In that case, also set
- *YYMSG_ALLOC to the required number of bytes. Return 2 if the
- required number of bytes is too large to store]b4_lac_if([[ or if
- yy_lac returned 2]])[. */
-static int
-yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
- ]b4_lac_if([[yytype_int16 *yyesa, yytype_int16 **yyes,
- YYSIZE_T *yyes_capacity, ]])[yytype_int16 *yyssp, int yytoken)
-{
- YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
- YYSIZE_T yysize = yysize0;
- enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
- /* Internationalized format string. */
- const char *yyformat = YY_NULL;
- /* Arguments of yyformat. */
- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
- /* Number of reported tokens (one for the "unexpected", one per
- "expected"). */
- int yycount = 0;
-
- /* There are many possibilities here to consider:
- - If this state is a consistent state with a default action, then
- the only way this function was invoked is if the default action
- is an error action. In that case, don't check for expected
- tokens because there are none.
- - The only way there can be no lookahead present (in yychar) is if
- this state is a consistent state with a default action. Thus,
- detecting the absence of a lookahead is sufficient to determine
- that there is no unexpected or expected token to report. In that
- case, just report a simple "syntax error".
- - Don't assume there isn't a lookahead just because this state is a
- consistent state with a default action. There might have been a
- previous inconsistent state, consistent state with a non-default
- action, or user semantic action that manipulated yychar.]b4_lac_if([[
- In the first two cases, it might appear that the current syntax
- error should have been detected in the previous state when yy_lac
- was invoked. However, at that time, there might have been a
- different syntax error that discarded a different initial context
- during error recovery, leaving behind the current lookahead.]], [[
- - Of course, the expected token list depends on states to have
- correct lookahead information, and it depends on the parser not
- to perform extra reductions after fetching a lookahead from the
- scanner and before detecting a syntax error. Thus, state merging
- (from LALR or IELR) and default reductions corrupt the expected
- token list. However, the list is correct for canonical LR with
- one exception: it will still contain any token that will not be
- accepted due to an error action in a later state.]])[
- */
- if (yytoken != YYEMPTY)
- {
- int yyn = yypact[*yyssp];]b4_lac_if([[
- YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[
- yyarg[yycount++] = yytname[yytoken];
- if (!yypact_value_is_default (yyn))
- {]b4_lac_if([], [[
- /* Start YYX at -YYN if negative to avoid negative indexes in
- YYCHECK. In other words, skip the first -YYN actions for
- this state because they are default actions. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = YYLAST - yyn + 1;
- int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;]])[
- int yyx;]b4_lac_if([[
-
- for (yyx = 0; yyx < YYNTOKENS; ++yyx)
- if (yyx != YYTERROR && yyx != YYUNDEFTOK)
- {
- {
- int yy_lac_status = yy_lac (yyesa, yyes, yyes_capacity,
- yyssp, yyx);
- if (yy_lac_status == 2)
- return 2;
- if (yy_lac_status == 1)
- continue;
- }]], [[
-
- for (yyx = yyxbegin; yyx < yyxend; ++yyx)
- if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
- && !yytable_value_is_error (yytable[yyx + yyn]))
- {]])[
- if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
- {
- yycount = 1;
- yysize = yysize0;
- break;
- }
- yyarg[yycount++] = yytname[yyx];
- {
- YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
- if (! (yysize <= yysize1
- && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
- }
- }
- }]b4_lac_if([[
-# if ]b4_api_PREFIX[DEBUG
- else if (yydebug)
- YYFPRINTF (stderr, "No expected tokens.\n");
-# endif]])[
- }
-
- switch (yycount)
- {
-# define YYCASE_(N, S) \
- case N: \
- yyformat = S; \
- break
- YYCASE_(0, YY_("syntax error"));
- YYCASE_(1, YY_("syntax error, unexpected %s"));
- YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
- YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
- YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
- YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
-# undef YYCASE_
- }
-
- {
- YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
- if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
- }
-
- if (*yymsg_alloc < yysize)
- {
- *yymsg_alloc = 2 * yysize;
- if (! (yysize <= *yymsg_alloc
- && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
- *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
- return 1;
- }
-
- /* Avoid sprintf, as that infringes on the user's name space.
- Don't have undefined behavior even if the translation
- produced a string with the wrong number of "%s"s. */
- {
- char *yyp = *yymsg;
- int yyi = 0;
- while ((*yyp = *yyformat) != '\0')
- if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
- {
- yyp += yytnamerr (yyp, yyarg[yyi++]);
- yyformat += 2;
- }
- else
- {
- yyp++;
- yyformat++;
- }
- }
- return 0;
-}
-#endif /* YYERROR_VERBOSE */
-
-]b4_yydestruct_define[
-
-]b4_pure_if([], [
-
-b4_declare_scanner_communication_variables])[]b4_push_if([[
-
-struct yypstate
- {]b4_declare_parser_state_variables[
- /* Used to determine if this is the first time this instance has
- been used. */
- int yynew;
- };]b4_pure_if([], [[
-
-static char yypstate_allocated = 0;]])b4_pull_if([
-
-b4_function_define([[yyparse]], [[int]], b4_parse_param)[
-{
- return yypull_parse (YY_NULL]m4_ifset([b4_parse_param],
- [[, ]b4_args(b4_parse_param)])[);
-}
-
-]b4_function_define([[yypull_parse]], [[int]],
- [[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
- b4_parse_param]))[
-{
- int yystatus;
- yypstate *yyps_local;]b4_pure_if([[
- int yychar;
- YYSTYPE yylval;]b4_locations_if([[
- static YYLTYPE yyloc_default][]b4_yyloc_default[;
- YYLTYPE yylloc = yyloc_default;]])])[
- if (yyps)
- yyps_local = yyps;
- else
- {
- yyps_local = yypstate_new ();
- if (!yyps_local)
- {]b4_pure_if([[
- yyerror (]b4_yyerror_args[YY_("memory exhausted"));]], [[
- if (!yypstate_allocated)
- yyerror (]b4_yyerror_args[YY_("memory exhausted"));]])[
- return 2;
- }
- }
- do {
- yychar = ]b4_lex[;
- yystatus =
- yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[);
- } while (yystatus == YYPUSH_MORE);
- if (!yyps)
- yypstate_delete (yyps_local);
- return yystatus;
-}]])[
-
-/* Initialize the parser data structure. */
-]b4_function_define([[yypstate_new]], [[yypstate *]])[
-{
- yypstate *yyps;]b4_pure_if([], [[
- if (yypstate_allocated)
- return YY_NULL;]])[
- yyps = (yypstate *) malloc (sizeof *yyps);
- if (!yyps)
- return YY_NULL;
- yyps->yynew = 1;]b4_pure_if([], [[
- yypstate_allocated = 1;]])[
- return yyps;
-}
-
-]b4_function_define([[yypstate_delete]], [[void]],
- [[[yypstate *yyps]], [[yyps]]])[
-{
-#ifndef yyoverflow
- /* If the stack was reallocated but the parse did not complete, then the
- stack still needs to be freed. */
- if (!yyps->yynew && yyps->yyss != yyps->yyssa)
- YYSTACK_FREE (yyps->yyss);
-#endif]b4_lac_if([[
- if (!yyps->yynew && yyps->yyes != yyps->yyesa)
- YYSTACK_FREE (yyps->yyes);]])[
- free (yyps);]b4_pure_if([], [[
- yypstate_allocated = 0;]])[
-}
-]b4_pure_if([[
-#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs]])[
-#define yystate yyps->yystate
-#define yyerrstatus yyps->yyerrstatus
-#define yyssa yyps->yyssa
-#define yyss yyps->yyss
-#define yyssp yyps->yyssp
-#define yyvsa yyps->yyvsa
-#define yyvs yyps->yyvs
-#define yyvsp yyps->yyvsp]b4_locations_if([[
-#define yylsa yyps->yylsa
-#define yyls yyps->yyls
-#define yylsp yyps->yylsp
-#define yyerror_range yyps->yyerror_range]])[
-#define yystacksize yyps->yystacksize]b4_lac_if([[
-#define yyesa yyps->yyesa
-#define yyes yyps->yyes
-#define yyes_capacity yyps->yyes_capacity]])[
-
-
-/*---------------.
-| yypush_parse. |
-`---------------*/
-
-]b4_function_define([[yypush_parse]], [[int]],
- [[[yypstate *yyps]], [[yyps]]]b4_pure_if([,
- [[[int yypushed_char]], [[yypushed_char]]],
- [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
- [[[YYLTYPE *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
- b4_parse_param]))], [[
-
-
-/*----------.
-| yyparse. |
-`----------*/
-
-]b4_function_define([yyparse], [int], b4_parse_param)])[
-{]b4_pure_if([b4_declare_scanner_communication_variables
-])b4_push_if([b4_pure_if([], [[
- int yypushed_char = yychar;
- YYSTYPE yypushed_val = yylval;]b4_locations_if([[
- YYLTYPE yypushed_loc = yylloc;]])
-])],
- [b4_declare_parser_state_variables
-])b4_lac_if([[
- int yy_lac_established = 0;]])[
- int yyn;
- int yyresult;
- /* Lookahead token as an internal (translated) token number. */
- int yytoken = 0;
- /* The variables used to return semantic value and location from the
- action routines. */
- YYSTYPE yyval;]b4_locations_if([[
- YYLTYPE yyloc;]])[
-
-#if YYERROR_VERBOSE
- /* Buffer for error messages, and its allocated size. */
- char yymsgbuf[128];
- char *yymsg = yymsgbuf;
- YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
-#endif
-
-#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[)
-
- /* The number of symbols on the RHS of the reduced rule.
- Keep to zero when no symbol should be popped. */
- int yylen = 0;]b4_push_if([[
-
- if (!yyps->yynew)
- {
- yyn = yypact[yystate];
- goto yyread_pushed_token;
- }]])[
-
- yyssp = yyss = yyssa;
- yyvsp = yyvs = yyvsa;]b4_locations_if([[
- yylsp = yyls = yylsa;]])[
- yystacksize = YYINITDEPTH;]b4_lac_if([[
-
- yyes = yyesa;
- yyes_capacity = sizeof yyesa / sizeof *yyes;
- if (YYMAXDEPTH < yyes_capacity)
- yyes_capacity = YYMAXDEPTH;]])[
-
- YYDPRINTF ((stderr, "Starting parse\n"));
-
- yystate = 0;
- yyerrstatus = 0;
- yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
-]m4_ifdef([b4_initial_action], [
-b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [],
- [b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl
-/* User initialization code. */
-b4_user_initial_action
-b4_dollar_popdef[]dnl
-m4_ifdef([b4_dollar_dollar_used],[[ yyvsp[0] = yylval;
-]])])dnl
-b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])[;
-]])dnl
-[ goto yysetstate;
-
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate. |
-`------------------------------------------------------------*/
- yynewstate:
- /* In all cases, when you get here, the value and location stacks
- have just been pushed. So pushing a state here evens the stacks. */
- yyssp++;
-
- yysetstate:
- *yyssp = yystate;
-
- if (yyss + yystacksize - 1 <= yyssp)
- {
- /* Get the current used size of the three stacks, in elements. */
- YYSIZE_T yysize = yyssp - yyss + 1;
-
-#ifdef yyoverflow
- {
- /* Give user a chance to reallocate the stack. Use copies of
- these so that the &'s don't force the real ones into
- memory. */
- YYSTYPE *yyvs1 = yyvs;
- yytype_int16 *yyss1 = yyss;]b4_locations_if([
- YYLTYPE *yyls1 = yyls;])[
-
- /* Each stack pointer address is followed by the size of the
- data in use in that stack, in bytes. This used to be a
- conditional around just the two extra args, but that might
- be undefined if yyoverflow is a macro. */
- yyoverflow (YY_("memory exhausted"),
- &yyss1, yysize * sizeof (*yyssp),
- &yyvs1, yysize * sizeof (*yyvsp),]b4_locations_if([
- &yyls1, yysize * sizeof (*yylsp),])[
- &yystacksize);
-]b4_locations_if([
- yyls = yyls1;])[
- yyss = yyss1;
- yyvs = yyvs1;
- }
-#else /* no yyoverflow */
-# ifndef YYSTACK_RELOCATE
- goto yyexhaustedlab;
-# else
- /* Extend the stack our own way. */
- if (YYMAXDEPTH <= yystacksize)
- goto yyexhaustedlab;
- yystacksize *= 2;
- if (YYMAXDEPTH < yystacksize)
- yystacksize = YYMAXDEPTH;
-
- {
- yytype_int16 *yyss1 = yyss;
- union yyalloc *yyptr =
- (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
- if (! yyptr)
- goto yyexhaustedlab;
- YYSTACK_RELOCATE (yyss_alloc, yyss);
- YYSTACK_RELOCATE (yyvs_alloc, yyvs);]b4_locations_if([
- YYSTACK_RELOCATE (yyls_alloc, yyls);])[
-# undef YYSTACK_RELOCATE
- if (yyss1 != yyssa)
- YYSTACK_FREE (yyss1);
- }
-# endif
-#endif /* no yyoverflow */
-
- yyssp = yyss + yysize - 1;
- yyvsp = yyvs + yysize - 1;]b4_locations_if([
- yylsp = yyls + yysize - 1;])[
-
- YYDPRINTF ((stderr, "Stack size increased to %lu\n",
- (unsigned long int) yystacksize));
-
- if (yyss + yystacksize - 1 <= yyssp)
- YYABORT;
- }
-
- YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-
- if (yystate == YYFINAL)
- YYACCEPT;
-
- goto yybackup;
-
-/*-----------.
-| yybackup. |
-`-----------*/
-yybackup:
-
- /* Do appropriate processing given the current state. Read a
- lookahead token if we need one and don't already have one. */
-
- /* First try to decide what to do without reference to lookahead token. */
- yyn = yypact[yystate];
- if (yypact_value_is_default (yyn))
- goto yydefault;
-
- /* Not known => get a lookahead token if don't already have one. */
-
- /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
- if (yychar == YYEMPTY)
- {]b4_push_if([[
- if (!yyps->yynew)
- {]b4_use_push_for_pull_if([], [[
- YYDPRINTF ((stderr, "Return for a new token:\n"));]])[
- yyresult = YYPUSH_MORE;
- goto yypushreturn;
- }
- yyps->yynew = 0;]b4_pure_if([], [[
- /* Restoring the pushed token is only necessary for the first
- yypush_parse invocation since subsequent invocations don't overwrite
- it before jumping to yyread_pushed_token. */
- yychar = yypushed_char;
- yylval = yypushed_val;]b4_locations_if([[
- yylloc = yypushed_loc;]])])[
-yyread_pushed_token:]])[
- YYDPRINTF ((stderr, "Reading a token: "));]b4_push_if([b4_pure_if([[
- yychar = yypushed_char;
- if (yypushed_val)
- yylval = *yypushed_val;]b4_locations_if([[
- if (yypushed_loc)
- yylloc = *yypushed_loc;]])])], [[
- yychar = ]b4_lex[;]])[
- }
-
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
-
- /* If the proper action on seeing token YYTOKEN is to reduce or to
- detect an error, take that action. */
- yyn += yytoken;
- if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)]b4_lac_if([[
- {
- YY_LAC_ESTABLISH;
- goto yydefault;
- }]], [[
- goto yydefault;]])[
- yyn = yytable[yyn];
- if (yyn <= 0)
- {
- if (yytable_value_is_error (yyn))
- goto yyerrlab;]b4_lac_if([[
- YY_LAC_ESTABLISH;]])[
- yyn = -yyn;
- goto yyreduce;
- }
-
- /* Count tokens shifted since error; after three, turn off error
- status. */
- if (yyerrstatus)
- yyerrstatus--;
-
- /* Shift the lookahead token. */
- YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-
- /* Discard the shifted token. */
- yychar = YYEMPTY;]b4_lac_if([[
- YY_LAC_DISCARD ("shift");]])[
-
- yystate = yyn;
- YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
- *++yyvsp = yylval;
- YY_IGNORE_MAYBE_UNINITIALIZED_END
-]b4_locations_if([ *++yylsp = yylloc;])[
- goto yynewstate;
-
-
-/*-----------------------------------------------------------.
-| yydefault -- do the default action for the current state. |
-`-----------------------------------------------------------*/
-yydefault:
- yyn = yydefact[yystate];
- if (yyn == 0)
- goto yyerrlab;
- goto yyreduce;
-
-
-/*-----------------------------.
-| yyreduce -- Do a reduction. |
-`-----------------------------*/
-yyreduce:
- /* yyn is the number of a rule to reduce with. */
- yylen = yyr2[yyn];
-
- /* If YYLEN is nonzero, implement the default value of the action:
- '$$ = $1'.
-
- Otherwise, the following line sets YYVAL to garbage.
- This behavior is undocumented and Bison
- users should not rely upon it. Assigning to YYVAL
- unconditionally makes the parser a bit smaller, and it avoids a
- GCC warning that YYVAL may be used uninitialized. */
- yyval = yyvsp[1-yylen];
-
-]b4_locations_if(
-[[ /* Default location. */
- YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);]])[
- YY_REDUCE_PRINT (yyn);]b4_lac_if([[
- {
- int yychar_backup = yychar;
- switch (yyn)
- {
- ]b4_user_actions[
- default: break;
- }
- if (yychar_backup != yychar)
- YY_LAC_DISCARD ("yychar change");
- }]], [[
- switch (yyn)
- {
- ]b4_user_actions[
- default: break;
- }]])[
- /* User semantic actions sometimes alter yychar, and that requires
- that yytoken be updated with the new translation. We take the
- approach of translating immediately before every use of yytoken.
- One alternative is translating here after every semantic action,
- but that translation would be missed if the semantic action invokes
- YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
- if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
- incorrect destructor might then be invoked immediately. In the
- case of YYERROR or YYBACKUP, subsequent parser actions might lead
- to an incorrect destructor call or verbose syntax error message
- before the lookahead is translated. */
- YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
-
- YYPOPSTACK (yylen);
- yylen = 0;
- YY_STACK_PRINT (yyss, yyssp);
-
- *++yyvsp = yyval;]b4_locations_if([
- *++yylsp = yyloc;])[
-
- /* Now 'shift' the result of the reduction. Determine what state
- that goes to, based on the state we popped back to and the rule
- number reduced by. */
-
- yyn = yyr1[yyn];
-
- yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
- if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
- yystate = yytable[yystate];
- else
- yystate = yydefgoto[yyn - YYNTOKENS];
-
- goto yynewstate;
-
-
-/*--------------------------------------.
-| yyerrlab -- here on detecting error. |
-`--------------------------------------*/
-yyerrlab:
- /* Make sure we have latest lookahead translation. See comments at
- user semantic actions for why this is necessary. */
- yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
-
- /* If not already recovering from an error, report this error. */
- if (!yyerrstatus)
- {
- ++yynerrs;
-#if ! YYERROR_VERBOSE
- yyerror (]b4_yyerror_args[YY_("syntax error"));
-#else
-# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \]b4_lac_if([[
- yyesa, &yyes, &yyes_capacity, \]])[
- yyssp, yytoken)
- {
- char const *yymsgp = YY_("syntax error");
- int yysyntax_error_status;]b4_lac_if([[
- if (yychar != YYEMPTY)
- YY_LAC_ESTABLISH;]])[
- yysyntax_error_status = YYSYNTAX_ERROR;
- if (yysyntax_error_status == 0)
- yymsgp = yymsg;
- else if (yysyntax_error_status == 1)
- {
- if (yymsg != yymsgbuf)
- YYSTACK_FREE (yymsg);
- yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
- if (!yymsg)
- {
- yymsg = yymsgbuf;
- yymsg_alloc = sizeof yymsgbuf;
- yysyntax_error_status = 2;
- }
- else
- {
- yysyntax_error_status = YYSYNTAX_ERROR;
- yymsgp = yymsg;
- }
- }
- yyerror (]b4_yyerror_args[yymsgp);
- if (yysyntax_error_status == 2)
- goto yyexhaustedlab;
- }
-# undef YYSYNTAX_ERROR
-#endif
- }
-
-]b4_locations_if([[ yyerror_range[1] = yylloc;]])[
-
- if (yyerrstatus == 3)
- {
- /* If just tried and failed to reuse lookahead token after an
- error, discard it. */
-
- if (yychar <= YYEOF)
- {
- /* Return failure if at end of input. */
- if (yychar == YYEOF)
- YYABORT;
- }
- else
- {
- yydestruct ("Error: discarding",
- yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
- yychar = YYEMPTY;
- }
- }
-
- /* Else will try to reuse lookahead token after shifting the error
- token. */
- goto yyerrlab1;
-
-
-/*---------------------------------------------------.
-| yyerrorlab -- error raised explicitly by YYERROR. |
-`---------------------------------------------------*/
-yyerrorlab:
-
- /* Pacify compilers like GCC when the user code never invokes
- YYERROR and the label yyerrorlab therefore never appears in user
- code. */
- if (/*CONSTCOND*/ 0)
- goto yyerrorlab;
-
-]b4_locations_if([[ yyerror_range[1] = yylsp[1-yylen];
-]])[ /* Do not reclaim the symbols of the rule whose action triggered
- this YYERROR. */
- YYPOPSTACK (yylen);
- yylen = 0;
- YY_STACK_PRINT (yyss, yyssp);
- yystate = *yyssp;
- goto yyerrlab1;
-
-
-/*-------------------------------------------------------------.
-| yyerrlab1 -- common code for both syntax error and YYERROR. |
-`-------------------------------------------------------------*/
-yyerrlab1:
- yyerrstatus = 3; /* Each real token shifted decrements this. */
-
- for (;;)
- {
- yyn = yypact[yystate];
- if (!yypact_value_is_default (yyn))
- {
- yyn += YYTERROR;
- if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
- {
- yyn = yytable[yyn];
- if (0 < yyn)
- break;
- }
- }
-
- /* Pop the current state because it cannot handle the error token. */
- if (yyssp == yyss)
- YYABORT;
-
-]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[
- yydestruct ("Error: popping",
- yystos[yystate], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[);
- YYPOPSTACK (1);
- yystate = *yyssp;
- YY_STACK_PRINT (yyss, yyssp);
- }]b4_lac_if([[
-
- /* If the stack popping above didn't lose the initial context for the
- current lookahead token, the shift below will for sure. */
- YY_LAC_DISCARD ("error recovery");]])[
-
- YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
- *++yyvsp = yylval;
- YY_IGNORE_MAYBE_UNINITIALIZED_END
-]b4_locations_if([[
- yyerror_range[2] = yylloc;
- /* Using YYLLOC is tempting, but would change the location of
- the lookahead. YYLOC is available though. */
- YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
- *++yylsp = yyloc;]])[
-
- /* Shift the error token. */
- YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
-
- yystate = yyn;
- goto yynewstate;
-
-
-/*-------------------------------------.
-| yyacceptlab -- YYACCEPT comes here. |
-`-------------------------------------*/
-yyacceptlab:
- yyresult = 0;
- goto yyreturn;
-
-/*-----------------------------------.
-| yyabortlab -- YYABORT comes here. |
-`-----------------------------------*/
-yyabortlab:
- yyresult = 1;
- goto yyreturn;
-
-#if ]b4_lac_if([[1]], [[!defined yyoverflow || YYERROR_VERBOSE]])[
-/*-------------------------------------------------.
-| yyexhaustedlab -- memory exhaustion comes here. |
-`-------------------------------------------------*/
-yyexhaustedlab:
- yyerror (]b4_yyerror_args[YY_("memory exhausted"));
- yyresult = 2;
- /* Fall through. */
-#endif
-
-yyreturn:
- if (yychar != YYEMPTY)
- {
- /* Make sure we have latest lookahead translation. See comments at
- user semantic actions for why this is necessary. */
- yytoken = YYTRANSLATE (yychar);
- yydestruct ("Cleanup: discarding lookahead",
- yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
- }
- /* Do not reclaim the symbols of the rule whose action triggered
- this YYABORT or YYACCEPT. */
- YYPOPSTACK (yylen);
- YY_STACK_PRINT (yyss, yyssp);
- while (yyssp != yyss)
- {
- yydestruct ("Cleanup: popping",
- yystos[*yyssp], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[);
- YYPOPSTACK (1);
- }
-#ifndef yyoverflow
- if (yyss != yyssa)
- YYSTACK_FREE (yyss);
-#endif]b4_lac_if([[
- if (yyes != yyesa)
- YYSTACK_FREE (yyes);]])b4_push_if([[
- yyps->yynew = 1;
-
-yypushreturn:]])[
-#if YYERROR_VERBOSE
- if (yymsg != yymsgbuf)
- YYSTACK_FREE (yymsg);
-#endif
- return yyresult;
-}
-]b4_epilogue[]dnl
-b4_output_end()
-
-b4_defines_if(
-[b4_output_begin([b4_spec_defines_file])[
-]b4_copyright([Bison interface for Yacc-like parsers in C])[
-
-]b4_shared_declarations[
-]b4_output_end()
-])# b4_defines_if
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
+ about the unexpected token YYTOKEN for the state stack whose top is
+ YYSSP.]b4_lac_if([[ In order to see if a particular token T is a
+ valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).]])[
+
+ Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
+ not large enough to hold the message. In that case, also set
+ *YYMSG_ALLOC to the required number of bytes. Return 2 if the
+ required number of bytes is too large to store]b4_lac_if([[ or if
+ yy_lac returned 2]])[. */
+static int
+yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
+ ]b4_lac_if([[yytype_int16 *yyesa, yytype_int16 **yyes,
+ YYSIZE_T *yyes_capacity, ]])[yytype_int16 *yyssp, int yytoken)
+{
+ YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
+ YYSIZE_T yysize = yysize0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ /* Internationalized format string. */
+ const char *yyformat = YY_NULL;
+ /* Arguments of yyformat. */
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ /* Number of reported tokens (one for the "unexpected", one per
+ "expected"). */
+ int yycount = 0;
+
+ /* There are many possibilities here to consider:
+ - If this state is a consistent state with a default action, then
+ the only way this function was invoked is if the default action
+ is an error action. In that case, don't check for expected
+ tokens because there are none.
+ - The only way there can be no lookahead present (in yychar) is if
+ this state is a consistent state with a default action. Thus,
+ detecting the absence of a lookahead is sufficient to determine
+ that there is no unexpected or expected token to report. In that
+ case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this state is a
+ consistent state with a default action. There might have been a
+ previous inconsistent state, consistent state with a non-default
+ action, or user semantic action that manipulated yychar.]b4_lac_if([[
+ In the first two cases, it might appear that the current syntax
+ error should have been detected in the previous state when yy_lac
+ was invoked. However, at that time, there might have been a
+ different syntax error that discarded a different initial context
+ during error recovery, leaving behind the current lookahead.]], [[
+ - Of course, the expected token list depends on states to have
+ correct lookahead information, and it depends on the parser not
+ to perform extra reductions after fetching a lookahead from the
+ scanner and before detecting a syntax error. Thus, state merging
+ (from LALR or IELR) and default reductions corrupt the expected
+ token list. However, the list is correct for canonical LR with
+ one exception: it will still contain any token that will not be
+ accepted due to an error action in a later state.]])[
+ */
+ if (yytoken != YYEMPTY)
+ {
+ int yyn = yypact[*yyssp];]b4_lac_if([[
+ YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[
+ yyarg[yycount++] = yytname[yytoken];
+ if (!yypact_value_is_default (yyn))
+ {]b4_lac_if([], [[
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. In other words, skip the first -YYN actions for
+ this state because they are default actions. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = YYLAST - yyn + 1;
+ int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;]])[
+ int yyx;]b4_lac_if([[
+
+ for (yyx = 0; yyx < YYNTOKENS; ++yyx)
+ if (yyx != YYTERROR && yyx != YYUNDEFTOK)
+ {
+ {
+ int yy_lac_status = yy_lac (yyesa, yyes, yyes_capacity,
+ yyssp, yyx);
+ if (yy_lac_status == 2)
+ return 2;
+ if (yy_lac_status == 1)
+ continue;
+ }]], [[
+
+ for (yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
+ && !yytable_value_is_error (yytable[yyx + yyn]))
+ {]])[
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ {
+ YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
+ if (! (yysize <= yysize1
+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
+ }
+ }]b4_lac_if([[
+# if ]b4_api_PREFIX[DEBUG
+ else if (yydebug)
+ YYFPRINTF (stderr, "No expected tokens.\n");
+# endif]])[
+ }
+
+ switch (yycount)
+ {
+# define YYCASE_(N, S) \
+ case N: \
+ yyformat = S; \
+ break
+ YYCASE_(0, YY_("syntax error"));
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+# undef YYCASE_
+ }
+
+ {
+ YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
+
+ if (*yymsg_alloc < yysize)
+ {
+ *yymsg_alloc = 2 * yysize;
+ if (! (yysize <= *yymsg_alloc
+ && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
+ *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
+ return 1;
+ }
+
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ {
+ char *yyp = *yymsg;
+ int yyi = 0;
+ while ((*yyp = *yyformat) != '\0')
+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyformat += 2;
+ }
+ else
+ {
+ yyp++;
+ yyformat++;
+ }
+ }
+ return 0;
+}
+#endif /* YYERROR_VERBOSE */
+
+]b4_yydestruct_define[
+
+]b4_pure_if([], [
+
+b4_declare_scanner_communication_variables])[]b4_push_if([[
+
+struct yypstate
+ {]b4_declare_parser_state_variables[
+ /* Used to determine if this is the first time this instance has
+ been used. */
+ int yynew;
+ };]b4_pure_if([], [[
+
+static char yypstate_allocated = 0;]])b4_pull_if([
+
+b4_function_define([[yyparse]], [[int]], b4_parse_param)[
+{
+ return yypull_parse (YY_NULL]m4_ifset([b4_parse_param],
+ [[, ]b4_args(b4_parse_param)])[);
+}
+
+]b4_function_define([[yypull_parse]], [[int]],
+ [[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [,
+ b4_parse_param]))[
+{
+ int yystatus;
+ yypstate *yyps_local;]b4_pure_if([[
+ int yychar;
+ YYSTYPE yylval;]b4_locations_if([[
+ static YYLTYPE yyloc_default][]b4_yyloc_default[;
+ YYLTYPE yylloc = yyloc_default;]])])[
+ if (yyps)
+ yyps_local = yyps;
+ else
+ {
+ yyps_local = yypstate_new ();
+ if (!yyps_local)
+ {]b4_pure_if([[
+ yyerror (]b4_yyerror_args[YY_("memory exhausted"));]], [[
+ if (!yypstate_allocated)
+ yyerror (]b4_yyerror_args[YY_("memory exhausted"));]])[
+ return 2;
+ }
+ }
+ do {
+ yychar = ]b4_lex[;
+ yystatus =
+ yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[);
+ } while (yystatus == YYPUSH_MORE);
+ if (!yyps)
+ yypstate_delete (yyps_local);
+ return yystatus;
+}]])[
+
+/* Initialize the parser data structure. */
+]b4_function_define([[yypstate_new]], [[yypstate *]])[
+{
+ yypstate *yyps;]b4_pure_if([], [[
+ if (yypstate_allocated)
+ return YY_NULL;]])[
+ yyps = (yypstate *) malloc (sizeof *yyps);
+ if (!yyps)
+ return YY_NULL;
+ yyps->yynew = 1;]b4_pure_if([], [[
+ yypstate_allocated = 1;]])[
+ return yyps;
+}
+
+]b4_function_define([[yypstate_delete]], [[void]],
+ [[[yypstate *yyps]], [[yyps]]])[
+{
+#ifndef yyoverflow
+ /* If the stack was reallocated but the parse did not complete, then the
+ stack still needs to be freed. */
+ if (!yyps->yynew && yyps->yyss != yyps->yyssa)
+ YYSTACK_FREE (yyps->yyss);
+#endif]b4_lac_if([[
+ if (!yyps->yynew && yyps->yyes != yyps->yyesa)
+ YYSTACK_FREE (yyps->yyes);]])[
+ free (yyps);]b4_pure_if([], [[
+ yypstate_allocated = 0;]])[
+}
+]b4_pure_if([[
+#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs]])[
+#define yystate yyps->yystate
+#define yyerrstatus yyps->yyerrstatus
+#define yyssa yyps->yyssa
+#define yyss yyps->yyss
+#define yyssp yyps->yyssp
+#define yyvsa yyps->yyvsa
+#define yyvs yyps->yyvs
+#define yyvsp yyps->yyvsp]b4_locations_if([[
+#define yylsa yyps->yylsa
+#define yyls yyps->yyls
+#define yylsp yyps->yylsp
+#define yyerror_range yyps->yyerror_range]])[
+#define yystacksize yyps->yystacksize]b4_lac_if([[
+#define yyesa yyps->yyesa
+#define yyes yyps->yyes
+#define yyes_capacity yyps->yyes_capacity]])[
+
+
+/*---------------.
+| yypush_parse. |
+`---------------*/
+
+]b4_function_define([[yypush_parse]], [[int]],
+ [[[yypstate *yyps]], [[yyps]]]b4_pure_if([,
+ [[[int yypushed_char]], [[yypushed_char]]],
+ [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
+ [[[YYLTYPE *yypushed_loc]], [[yypushed_loc]]]])])m4_ifset([b4_parse_param], [,
+ b4_parse_param]))], [[
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+]b4_function_define([yyparse], [int], b4_parse_param)])[
+{]b4_pure_if([b4_declare_scanner_communication_variables
+])b4_push_if([b4_pure_if([], [[
+ int yypushed_char = yychar;
+ YYSTYPE yypushed_val = yylval;]b4_locations_if([[
+ YYLTYPE yypushed_loc = yylloc;]])
+])],
+ [b4_declare_parser_state_variables
+])b4_lac_if([[
+ int yy_lac_established = 0;]])[
+ int yyn;
+ int yyresult;
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken = 0;
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;]b4_locations_if([[
+ YYLTYPE yyloc;]])[
+
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[)
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;]b4_push_if([[
+
+ if (!yyps->yynew)
+ {
+ yyn = yypact[yystate];
+ goto yyread_pushed_token;
+ }]])[
+
+ yyssp = yyss = yyssa;
+ yyvsp = yyvs = yyvsa;]b4_locations_if([[
+ yylsp = yyls = yylsa;]])[
+ yystacksize = YYINITDEPTH;]b4_lac_if([[
+
+ yyes = yyesa;
+ yyes_capacity = sizeof yyesa / sizeof *yyes;
+ if (YYMAXDEPTH < yyes_capacity)
+ yyes_capacity = YYMAXDEPTH;]])[
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+]m4_ifdef([b4_initial_action], [
+b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [],
+ [b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl
+/* User initialization code. */
+b4_user_initial_action
+b4_dollar_popdef[]dnl
+m4_ifdef([b4_dollar_dollar_used],[[ yyvsp[0] = yylval;
+]])])dnl
+b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])[;
+]])dnl
+[ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;]b4_locations_if([
+ YYLTYPE *yyls1 = yyls;])[
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),]b4_locations_if([
+ &yyls1, yysize * sizeof (*yylsp),])[
+ &yystacksize);
+]b4_locations_if([
+ yyls = yyls1;])[
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss_alloc, yyss);
+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);]b4_locations_if([
+ YYSTACK_RELOCATE (yyls_alloc, yyls);])[
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;]b4_locations_if([
+ yylsp = yyls + yysize - 1;])[
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ if (yystate == YYFINAL)
+ YYACCEPT;
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ lookahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to lookahead token. */
+ yyn = yypact[yystate];
+ if (yypact_value_is_default (yyn))
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
+ if (yychar == YYEMPTY)
+ {]b4_push_if([[
+ if (!yyps->yynew)
+ {]b4_use_push_for_pull_if([], [[
+ YYDPRINTF ((stderr, "Return for a new token:\n"));]])[
+ yyresult = YYPUSH_MORE;
+ goto yypushreturn;
+ }
+ yyps->yynew = 0;]b4_pure_if([], [[
+ /* Restoring the pushed token is only necessary for the first
+ yypush_parse invocation since subsequent invocations don't overwrite
+ it before jumping to yyread_pushed_token. */
+ yychar = yypushed_char;
+ yylval = yypushed_val;]b4_locations_if([[
+ yylloc = yypushed_loc;]])])[
+yyread_pushed_token:]])[
+ YYDPRINTF ((stderr, "Reading a token: "));]b4_push_if([b4_pure_if([[
+ yychar = yypushed_char;
+ if (yypushed_val)
+ yylval = *yypushed_val;]b4_locations_if([[
+ if (yypushed_loc)
+ yylloc = *yypushed_loc;]])])], [[
+ yychar = ]b4_lex[;]])[
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)]b4_lac_if([[
+ {
+ YY_LAC_ESTABLISH;
+ goto yydefault;
+ }]], [[
+ goto yydefault;]])[
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yytable_value_is_error (yyn))
+ goto yyerrlab;]b4_lac_if([[
+ YY_LAC_ESTABLISH;]])[
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the lookahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token. */
+ yychar = YYEMPTY;]b4_lac_if([[
+ YY_LAC_DISCARD ("shift");]])[
+
+ yystate = yyn;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+]b4_locations_if([ *++yylsp = yylloc;])[
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ '$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+]b4_locations_if(
+[[ /* Default location. */
+ YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);]])[
+ YY_REDUCE_PRINT (yyn);]b4_lac_if([[
+ {
+ int yychar_backup = yychar;
+ switch (yyn)
+ {
+ ]b4_user_actions[
+ default: break;
+ }
+ if (yychar_backup != yychar)
+ YY_LAC_DISCARD ("yychar change");
+ }]], [[
+ switch (yyn)
+ {
+ ]b4_user_actions[
+ default: break;
+ }]])[
+ /* User semantic actions sometimes alter yychar, and that requires
+ that yytoken be updated with the new translation. We take the
+ approach of translating immediately before every use of yytoken.
+ One alternative is translating here after every semantic action,
+ but that translation would be missed if the semantic action invokes
+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
+ incorrect destructor might then be invoked immediately. In the
+ case of YYERROR or YYBACKUP, subsequent parser actions might lead
+ to an incorrect destructor call or verbose syntax error message
+ before the lookahead is translated. */
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;]b4_locations_if([
+ *++yylsp = yyloc;])[
+
+ /* Now 'shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*--------------------------------------.
+| yyerrlab -- here on detecting error. |
+`--------------------------------------*/
+yyerrlab:
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
+
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (]b4_yyerror_args[YY_("syntax error"));
+#else
+# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \]b4_lac_if([[
+ yyesa, &yyes, &yyes_capacity, \]])[
+ yyssp, yytoken)
+ {
+ char const *yymsgp = YY_("syntax error");
+ int yysyntax_error_status;]b4_lac_if([[
+ if (yychar != YYEMPTY)
+ YY_LAC_ESTABLISH;]])[
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ if (yysyntax_error_status == 0)
+ yymsgp = yymsg;
+ else if (yysyntax_error_status == 1)
+ {
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
+ if (!yymsg)
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ yysyntax_error_status = 2;
+ }
+ else
+ {
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ yymsgp = yymsg;
+ }
+ }
+ yyerror (]b4_yyerror_args[yymsgp);
+ if (yysyntax_error_status == 2)
+ goto yyexhaustedlab;
+ }
+# undef YYSYNTAX_ERROR
+#endif
+ }
+
+]b4_locations_if([[ yyerror_range[1] = yylloc;]])[
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+]b4_locations_if([[ yyerror_range[1] = yylsp[1-yylen];
+]])[ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (!yypact_value_is_default (yyn))
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+]b4_locations_if([[ yyerror_range[1] = *yylsp;]])[
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }]b4_lac_if([[
+
+ /* If the stack popping above didn't lose the initial context for the
+ current lookahead token, the shift below will for sure. */
+ YY_LAC_DISCARD ("error recovery");]])[
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+]b4_locations_if([[
+ yyerror_range[2] = yylloc;
+ /* Using YYLLOC is tempting, but would change the location of
+ the lookahead. YYLOC is available though. */
+ YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
+ *++yylsp = yyloc;]])[
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#if ]b4_lac_if([[1]], [[!defined yyoverflow || YYERROR_VERBOSE]])[
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (]b4_yyerror_args[YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEMPTY)
+ {
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = YYTRANSLATE (yychar);
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
+ }
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif]b4_lac_if([[
+ if (yyes != yyesa)
+ YYSTACK_FREE (yyes);]])b4_push_if([[
+ yyps->yynew = 1;
+
+yypushreturn:]])[
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ return yyresult;
+}
+]b4_epilogue[]dnl
+b4_output_end()
+
+b4_defines_if(
+[b4_output_begin([b4_spec_defines_file])[
+]b4_copyright([Bison interface for Yacc-like parsers in C])[
+
+]b4_shared_declarations[
+]b4_output_end()
+])# b4_defines_if
diff --git a/contrib/tools/bison/bison/src/AnnotationList.c b/contrib/tools/bison/bison/src/AnnotationList.c
index b5781766a4..915339e1f3 100644
--- a/contrib/tools/bison/bison/src/AnnotationList.c
+++ b/contrib/tools/bison/bison/src/AnnotationList.c
@@ -1,808 +1,808 @@
-/* IELR's inadequacy annotation list.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "AnnotationList.h"
-#include "lalr.h"
-#include "ielr.h"
-
-/**
- * \pre
- * - <tt>annotations_obstackp != NULL</tt>.
- * \post
- * - \c result is a new \c AnnotationList with one node whose:
- * - \c inadequacyNode member is \c NULL.
- * - \c contributions member is allocated with \c contribution_count
- * uninitialized elements.
- * - All memory was allocated on \c annotations_obstackp.
- */
-static AnnotationList*
-AnnotationList__alloc_on_obstack (ContributionIndex contribution_count,
- struct obstack *annotations_obstackp)
-{
- AnnotationList *result;
- size_t contributions_size =
- contribution_count * sizeof result->contributions[0];
- result = obstack_alloc (annotations_obstackp,
- offsetof (AnnotationList, contributions)
- + contributions_size);
- result->next = NULL;
- result->inadequacyNode = NULL;
- return result;
-}
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - <tt>0 <= ci < self->inadequacyNode->contributionCount</tt>.
- * \post
- * - \c result = true iff contribution \c ci in \c self represents an
- * "always" contribution.
- */
-static bool
-AnnotationList__isContributionAlways (AnnotationList const *self,
- ContributionIndex ci)
-{
- aver (0 <= ci && ci < self->inadequacyNode->contributionCount);
- return self->contributions[ci] == NULL;
-}
-
-/**
- * \pre
- * - \c self is a single node.
- * - \c self annotates the same state as every other node in \c list, and
- * that state has \c nitems kernel items.
- * \post
- * - If the list \c list already contains an identical annotation to \c self,
- * \c self was discarded, \c result is false, and the caller is responsible
- * for the memory of \c self.
- * - Otherwise, \c list now contains the node \c self, \c result is true, and
- * \c list assumes responsibility for the memory of \c self.
- * - The sort in \c list is:
- * - Sort in reverse order on the unique ID of the associated
- * inadequacy node. Because these IDs are assigned in ascending
- * order, this should mean that the insertion position within an
- * annotation list is usually near the beginning with other
- * annotations associated with the same inadequacy.
- * - Next, sort on the first contribution that is different as follows:
- * - Sort an always-contribution before a never-contribution before a
- * potential-contribution.
- * - Two always-contributions are identical.
- * - Two never-contributions are identical.
- * - For two potential-contributions, sort on the contributions' kernel
- * item bitsets interpreted as binary numbers.
- * - The sorting has a few effects:
- * - It accelerates elimination of identical annotations during insertion.
- * - It determines how the output of \c AnnotationList__debug is sorted.
- * - Other than that, it's probably not important.
- */
-static bool
-AnnotationList__insertInto (AnnotationList *self, AnnotationList **list,
- size_t nitems)
-{
- AnnotationList **node;
- for (node = list; *node; node = &(*node)->next)
- {
- int cmp = 0;
- ContributionIndex ci;
- if (self->inadequacyNode->id < (*node)->inadequacyNode->id)
- cmp = 1;
- else if ((*node)->inadequacyNode->id < self->inadequacyNode->id)
- cmp = -1;
- else
- for (ci = 0;
- cmp == 0 && ci < self->inadequacyNode->contributionCount;
- ++ci)
- {
- if (AnnotationList__isContributionAlways (self, ci))
- {
- if (!AnnotationList__isContributionAlways (*node, ci))
- cmp = -1;
- }
- else if (AnnotationList__isContributionAlways (*node, ci))
- cmp = 1;
- else
- {
- size_t item;
- for (item = 0; cmp == 0 && item < nitems; ++item)
- {
- if (!Sbitset__test (self->contributions[ci], item))
- {
- if (Sbitset__test ((*node)->contributions[ci], item))
- cmp = -1;
- }
- else if (!Sbitset__test ((*node)->contributions[ci], item))
- cmp = 1;
- }
- }
- }
- if (cmp < 0)
- {
- self->next = *node;
- *node = self;
- break;
- }
- else if (cmp == 0)
- {
- self = NULL;
- break;
- }
- }
- if (!*node)
- *node = self;
- return self != NULL;
-}
-
-static bitset
-AnnotationList__compute_shift_tokens (transitions *trans)
-{
- bitset shift_tokens = bitset_create (ntokens, BITSET_FIXED);
- int i;
- FOR_EACH_SHIFT (trans, i)
- bitset_set (shift_tokens, TRANSITION_SYMBOL (trans, i));
- return shift_tokens;
-}
-
-static bitset
-AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
- reductions *reds)
-{
- bitset conflicted_tokens = bitset_create (ntokens, BITSET_FIXED);
- bitset conflicted_tokens_rule = bitset_create (ntokens, BITSET_FIXED);
- bitset tokens = bitset_create (ntokens, BITSET_FIXED);
- int i;
-
- bitset_copy (tokens, shift_tokens);
- for (i = 0; i < reds->num; ++i)
- {
- bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]);
- bitset_or (conflicted_tokens,
- conflicted_tokens, conflicted_tokens_rule);
- bitset_or (tokens, tokens, reds->lookahead_tokens[i]);
- /* Check that rules are sorted on rule number or the next step in
- AnnotationList__compute_from_inadequacies will misbehave. */
- aver (i == 0 || reds->rules[i-1] < reds->rules[i]);
- }
-
- bitset_free (tokens);
- bitset_free (conflicted_tokens_rule);
-
- return conflicted_tokens;
-}
-
-static bool
-AnnotationList__compute_lhs_contributions (state *s, rule *the_rule,
- symbol_number conflicted_token,
- bitsetv follow_kernel_items,
- bitsetv always_follows,
- state ***predecessors,
- bitset **item_lookahead_sets,
- Sbitset *items,
- struct obstack
- *annotations_obstackp)
-{
- goto_number lhs_goto = map_goto (s->number, the_rule->lhs->number);
- if (bitset_test (always_follows[lhs_goto], conflicted_token))
- return true;
- *items = Sbitset__new_on_obstack (s->nitems, annotations_obstackp);
- {
- bitset_iterator biter_item;
- bitset_bindex item;
- BITSET_FOR_EACH (biter_item, follow_kernel_items[lhs_goto], item, 0)
- if (ielr_item_has_lookahead (s, 0, item, conflicted_token,
- predecessors, item_lookahead_sets))
- Sbitset__set (*items, item);
- }
- return false;
-}
-
-static void
-AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
- bitsetv follow_kernel_items,
- bitsetv always_follows,
- state ***predecessors,
- bitset **item_lookahead_sets,
- AnnotationList
- **annotation_lists,
- AnnotationIndex
- *annotation_counts,
- struct obstack
- *annotations_obstackp)
-{
- state **predecessor;
- bitset *lookaheads;
- for (predecessor = predecessors[s->number]; *predecessor; ++predecessor)
- {
- AnnotationList *annotation_node =
- AnnotationList__alloc_on_obstack (
- self->inadequacyNode->contributionCount, annotations_obstackp);
- bool potential_contribution = false;
- annotation_node->inadequacyNode = self->inadequacyNode;
- lookaheads = NULL;
- {
- ContributionIndex ci;
- for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
- {
- symbol_number contribution_token =
- InadequacyList__getContributionToken (self->inadequacyNode, ci)
- ->number;
- if (AnnotationList__isContributionAlways (self, ci))
- {
- annotation_node->contributions[ci] = NULL;
- continue;
- }
- annotation_node->contributions[ci] =
- Sbitset__new_on_obstack ((*predecessor)->nitems,
- annotations_obstackp);
- {
- size_t predecessor_item = 0;
- Sbitset sbiter_item;
- Sbitset__Index self_item;
- SBITSET__FOR_EACH (self->contributions[ci], s->nitems,
- sbiter_item, self_item)
- {
- /* If this kernel item is the beginning of a RHS, it must be
- the kernel item in the start state, and so it has an empty
- lookahead set. Thus, it can't contribute to inadequacies,
- and so it should never have been identified as a
- contribution. If, instead, this kernel item is the
- successor of the start state's kernel item, the lookahead
- set is still empty, and so it also should never have been
- identified as a contribution. This situation is fortunate
- because we want to avoid the - 2 below in both cases. */
- aver (s->items[self_item] > 1);
- /* If this kernel item is next to the beginning of the RHS,
- then check all of the predecessor's goto follows for the
- LHS. */
- if (item_number_is_rule_number (ritem[s->items[self_item]
- - 2]))
- {
- Sbitset items;
- unsigned int rulei;
- for (rulei = s->items[self_item];
- !item_number_is_rule_number (ritem[rulei]);
- ++rulei)
- ;
- if (AnnotationList__compute_lhs_contributions (
- *predecessor,
- &rules[item_number_as_rule_number (ritem[rulei])],
- contribution_token,
- follow_kernel_items, always_follows, predecessors,
- item_lookahead_sets, &items, annotations_obstackp))
- {
- obstack_free (annotations_obstackp,
- annotation_node->contributions[ci]);
- annotation_node->contributions[ci] = NULL;
- break;
- }
- else
- {
- Sbitset__or (annotation_node->contributions[ci],
- annotation_node->contributions[ci],
- items, (*predecessor)->nitems);
- obstack_free (annotations_obstackp, items);
- }
- }
- /* If this kernel item is later in the RHS, then check the
- predecessor item's lookahead set. */
- else
- {
- /* We don't have to start the predecessor item search at
- the beginning every time because items from both
- states are sorted by their indices in ritem. */
- for (;
- predecessor_item < (*predecessor)->nitems;
- ++predecessor_item)
- if ((*predecessor)->items[predecessor_item]
- == s->items[self_item] - 1)
- break;
- aver (predecessor_item != (*predecessor)->nitems);
- if (ielr_item_has_lookahead (*predecessor, 0,
- predecessor_item,
- contribution_token,
- predecessors,
- item_lookahead_sets))
- Sbitset__set (annotation_node->contributions[ci],
- predecessor_item);
- }
- }
- }
- if (annotation_node->contributions[ci])
- {
- Sbitset biter;
- Sbitset__Index i;
- SBITSET__FOR_EACH (annotation_node->contributions[ci],
- (*predecessor)->nitems, biter, i)
- {
- potential_contribution = true;
- if (!lookaheads)
- {
- size_t j;
- lookaheads = xnmalloc ((*predecessor)->nitems,
- sizeof *lookaheads);
- for (j = 0; j < (*predecessor)->nitems; ++j)
- lookaheads[j] = NULL;
- }
- if (!lookaheads[i])
- lookaheads[i] = bitset_create (ntokens, BITSET_FIXED);
- bitset_set (lookaheads[i], contribution_token);
- }
- }
- }
- }
-
- /* If the predecessor has any contributions besides just "always" and
- "never" contributions:
- - If the dominant contribution is split-stable, the annotation could
- not affect merging on this predecessor state or its eventual
- predecessor states. Moreover, all contributions that affect
- whether the dominant contribution remains dominant must be "always"
- or "never" contributions in order for the dominant contribution to
- be split-stable. Thus, the dominant contribution computation result
- in eventual successor states will not be affected by lookaheads
- tracked for this predecessor state. (Also, as in the isocore
- compatibility test, we depend on the fact that isocores with equal
- dominant contributions will have the same dominant contribution when
- merged. Otherwise, we might have to worry that the presence of a
- potential contribution might somehow be the culprit of that behavior
- and thus need to be tracked regardless of the split stability of the
- dominant contribution.) Thus, go ahead and discard the annotation
- to save space now plus time during state splitting.
- - Otherwise, record the annotation, and compute any resulting
- annotations needed on predecessor states. */
- if (potential_contribution)
- {
- if (ContributionIndex__none
- != AnnotationList__computeDominantContribution (
- annotation_node, (*predecessor)->nitems, lookaheads, true))
- {
- obstack_free (annotations_obstackp, annotation_node);
- annotation_node = NULL;
- }
- {
- size_t i;
- for (i = 0; i < (*predecessor)->nitems; ++i)
- if (lookaheads[i])
- bitset_free (lookaheads[i]);
- free (lookaheads);
- }
- if (annotation_node)
- {
- if (AnnotationList__insertInto (annotation_node,
- &annotation_lists[(*predecessor)
- ->number],
- (*predecessor)->nitems))
- {
- ++annotation_counts[(*predecessor)->number];
- AnnotationList__computePredecessorAnnotations (
- annotation_node, *predecessor,
- follow_kernel_items, always_follows, predecessors,
- item_lookahead_sets, annotation_lists, annotation_counts,
- annotations_obstackp);
- }
- else
- obstack_free (annotations_obstackp, annotation_node);
- }
- }
- else
- obstack_free (annotations_obstackp, annotation_node);
- }
-}
-
-void
-AnnotationList__compute_from_inadequacies (
- state *s, bitsetv follow_kernel_items, bitsetv always_follows,
- state ***predecessors, bitset **item_lookahead_sets,
- InadequacyList **inadequacy_lists, AnnotationList **annotation_lists,
- AnnotationIndex *annotation_counts,
- ContributionIndex *max_contributionsp,
- struct obstack *annotations_obstackp,
- InadequacyListNodeCount *inadequacy_list_node_count)
-{
- bitsetv all_lookaheads;
- bitset shift_tokens;
- bitset conflicted_tokens;
- bitset_iterator biter_conflict;
- bitset_bindex conflicted_token;
-
- /* Return an empty list if s->lookahead_tokens = NULL. */
- if (s->consistent)
- return;
-
- all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED);
- bitsetv_ones (all_lookaheads);
- shift_tokens = AnnotationList__compute_shift_tokens (s->transitions);
- conflicted_tokens =
- AnnotationList__compute_conflicted_tokens (shift_tokens, s->reductions);
-
- /* Add an inadequacy annotation for each conflicted_token. */
- BITSET_FOR_EACH (biter_conflict, conflicted_tokens, conflicted_token, 0)
- {
- AnnotationList *annotation_node;
- /* FIXME: Would a BITSET_FRUGAL or BITEST_SPARSE be more efficient? Now
- or convert it inside InadequacyList__new_conflict? */
- bitset actions = bitset_create (s->reductions->num + 1, BITSET_FIXED);
- ContributionIndex contribution_count = 0;
- bool potential_contribution = false;
-
- /* Allocate the annotation node. */
- {
- int rule_i;
- for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
- if (bitset_test (s->reductions->lookahead_tokens[rule_i],
- conflicted_token))
- ++contribution_count;
- if (bitset_test (shift_tokens, conflicted_token))
- ++contribution_count;
- annotation_node =
- AnnotationList__alloc_on_obstack (contribution_count,
- annotations_obstackp);
- }
-
- /* Add a contribution for each reduction that has conflicted_token as a
- lookahead. */
- {
- ContributionIndex ci = 0;
- int item_i = 0;
- int rule_i;
- for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
- {
- rule *the_rule = s->reductions->rules[rule_i];
- if (bitset_test (s->reductions->lookahead_tokens[rule_i],
- conflicted_token))
- {
- bitset_set (actions, rule_i);
- /* If this reduction is on a kernel item, just add it. */
- if (!item_number_is_rule_number (the_rule->rhs[0]))
- {
- annotation_node->contributions[ci] =
- Sbitset__new_on_obstack (s->nitems,
- annotations_obstackp);
- /* Catch item_i up to rule_i. This works because both are
- sorted on rule number. */
- while (!item_number_is_rule_number (
- ritem[s->items[item_i]])
- || item_number_as_rule_number (
- ritem[s->items[item_i]])
- != the_rule->number)
- {
- ++item_i;
- aver (item_i < s->nitems);
- }
- Sbitset__set (annotation_node->contributions[ci], item_i);
- }
- /* Otherwise, add the kernel items whose lookahead sets
- contribute the conflicted token to this reduction's
- lookahead set. */
- else if (AnnotationList__compute_lhs_contributions (
- s, the_rule, conflicted_token, follow_kernel_items,
- always_follows, predecessors, item_lookahead_sets,
- &annotation_node->contributions[ci],
- annotations_obstackp))
- {
- annotation_node->contributions[ci++] = NULL;
- continue;
- }
- /* The lookahead token has to come from somewhere. */
- aver (!Sbitset__isEmpty (annotation_node->contributions[ci],
- s->nitems));
- ++ci;
- potential_contribution = true;
- }
- }
- }
-
- /* If there are any contributions besides just "always" contributions:
- - If there's also a shift contribution, record it.
- - If the dominant contribution is split-stable, then the annotation
- could not affect merging, so go ahead and discard the annotation and
- the inadequacy to save space now plus time during state splitting.
- - Otherwise, record the annotation and the inadequacy, and compute any
- resulting annotations needed on predecessor states. */
- if (potential_contribution)
- {
- if (bitset_test (shift_tokens, conflicted_token))
- {
- bitset_set (actions, s->reductions->num);
- annotation_node->contributions[contribution_count - 1] = NULL;
- }
- {
- InadequacyList *conflict_node =
- InadequacyList__new_conflict (
- s, symbols[conflicted_token], actions,
- inadequacy_list_node_count);
- actions = NULL;
- annotation_node->inadequacyNode = conflict_node;
- if (ContributionIndex__none
- != AnnotationList__computeDominantContribution (
- annotation_node, s->nitems, all_lookaheads, true))
- {
- obstack_free (annotations_obstackp, annotation_node);
- InadequacyList__delete (conflict_node);
- }
- else
- {
- InadequacyList__prependTo (conflict_node,
- &inadequacy_lists[s->number]);
- aver (AnnotationList__insertInto (
- annotation_node, &annotation_lists[s->number],
- s->nitems));
- /* This aver makes sure the
- AnnotationList__computeDominantContribution check above
- does discard annotations in the simplest case of a S/R
- conflict with no token precedence. */
- aver (!bitset_test (shift_tokens, conflicted_token)
- || symbols[conflicted_token]->prec);
- ++annotation_counts[s->number];
- if (contribution_count > *max_contributionsp)
- *max_contributionsp = contribution_count;
- AnnotationList__computePredecessorAnnotations (
- annotation_node, s,
- follow_kernel_items, always_follows, predecessors,
- item_lookahead_sets, annotation_lists, annotation_counts,
- annotations_obstackp);
- }
- }
- }
- else
- {
- bitset_free (actions);
- obstack_free (annotations_obstackp, annotation_node);
- }
- }
-
- bitsetv_free (all_lookaheads);
- bitset_free (shift_tokens);
- bitset_free (conflicted_tokens);
-}
-
-void
-AnnotationList__debug (AnnotationList const *self, size_t nitems, int spaces)
-{
- AnnotationList const *a;
- AnnotationIndex ai;
- for (a = self, ai = 0; a; a = a->next, ++ai)
- {
- {
- int j;
- for (j = 0; j < spaces; ++j)
- putc (' ', stderr);
- }
- fprintf (stderr, "Annotation %d (manifesting state %d):\n",
- ai, a->inadequacyNode->manifestingState->number);
- {
- ContributionIndex ci;
- bitset_bindex rulei = 0; /* init suppresses compiler warning */
- rulei = bitset_first (a->inadequacyNode->inadequacy.conflict.actions);
- for (ci = 0; ci < a->inadequacyNode->contributionCount; ++ci)
- {
- symbol_number token =
- InadequacyList__getContributionToken (a->inadequacyNode, ci)
- ->number;
- {
- int j;
- for (j = 0; j < spaces+2; ++j)
- putc (' ', stderr);
- }
- if (ci == InadequacyList__getShiftContributionIndex (
- a->inadequacyNode))
- fprintf (stderr, "Contributes shift of token %d.\n", token);
- else
- {
- fprintf (stderr, "Contributes token %d", token);
- aver (rulei != BITSET_BINDEX_MAX);
- fprintf (stderr, " as lookahead, rule number %d",
- a->inadequacyNode->manifestingState
- ->reductions->rules[rulei]->number);
- rulei =
- bitset_next (a->inadequacyNode->inadequacy.conflict.actions,
- rulei+1);
- if (AnnotationList__isContributionAlways (a, ci))
- fprintf (stderr, " always.");
- else
- {
- fprintf (stderr, ", items: ");
- Sbitset__fprint (a->contributions[ci], nitems, stderr);
- }
- fprintf (stderr, "\n");
- }
- }
- }
- }
-}
-
-void
-AnnotationList__computeLookaheadFilter (AnnotationList const *self,
- size_t nitems,
- bitsetv lookahead_filter)
-{
- bitsetv_zero (lookahead_filter);
- for (; self; self = self->next)
- {
- ContributionIndex ci;
- for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
- if (!AnnotationList__isContributionAlways (self, ci))
- {
- Sbitset__Index item;
- Sbitset biter;
- symbol_number token =
- InadequacyList__getContributionToken (self->inadequacyNode, ci)
- ->number;
- SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
- bitset_set (lookahead_filter[item], token);
- }
- }
-}
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - \c nitems is the number of kernel items in the LR(0) state that \c self
- * annotates.
- * - \c lookaheads describes the lookahead sets on the kernel items of some
- * isocore of the LR(0) state that \c self annotates. Either:
- * - <tt>lookaheads = NULL</tt> only if the lookahead set on every kernel
- * item is empty.
- * - For any <tt>0 <= i < nitems</tt>, <tt>lookaheads[i]</tt> is either:
- * - \c NULL only if the lookahead set on kernel item \c i is empty.
- * - The (possibly empty) lookahead set on kernel item \c i.
- * - <tt>0 <= ci < self->inadequacyNode->contributionCount</tt>.
- * \post
- * - \c result = true iff contribution \c ci in \c self is made by the state
- * described by \c lookaheads.
- */
-static bool
-AnnotationList__stateMakesContribution (AnnotationList const *self,
- size_t nitems, ContributionIndex ci,
- bitset *lookaheads)
-{
- if (AnnotationList__isContributionAlways (self, ci))
- return true;
- if (!lookaheads)
- return false;
- {
- symbol_number token =
- InadequacyList__getContributionToken (self->inadequacyNode, ci)->number;
- Sbitset__Index item;
- Sbitset biter;
- SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
- if (lookaheads[item] && bitset_test (lookaheads[item], token))
- return true;
- }
- return false;
-}
-
-ContributionIndex
-AnnotationList__computeDominantContribution (AnnotationList const *self,
- size_t nitems, bitset *lookaheads,
- bool require_split_stable)
-{
- symbol *token;
- ContributionIndex const ci_shift =
- InadequacyList__getShiftContributionIndex (self->inadequacyNode);
-
- token = self->inadequacyNode->inadequacy.conflict.token;
-
- /* S/R conflict. */
- if (ci_shift != ContributionIndex__none)
- {
- bool find_stable_domination_over_shift = false;
- bool find_stable_error_action_domination = false;
- {
- ContributionIndex ci;
- int actioni;
- ContributionIndex ci_rr_dominator = ContributionIndex__none;
- int shift_precedence = token->prec;
-
- /* If the token has no precedence set, shift is always chosen. */
- if (!shift_precedence)
- return ci_shift;
-
- /* Figure out which reductions contribute, which of those would
- dominate in a R/R comparison, and whether any reduction dominates
- the shift so that the R/R comparison is actually needed. */
- for (ci = 0, actioni = bitset_first (self->inadequacyNode->inadequacy
- .conflict.actions);
- ci < self->inadequacyNode->contributionCount;
- ++ci, actioni = bitset_next (self->inadequacyNode->inadequacy
- .conflict.actions, actioni+1))
- {
- int reduce_precedence = 0;
- if (ci == ci_shift)
- continue;
- {
- rule *r = self->inadequacyNode->manifestingState
- ->reductions->rules[actioni];
- if (r->prec)
- reduce_precedence = r->prec->prec;
- }
- /* If there's no need to check whether this reduction actually
- contributes because the shift eliminates it from the R/R
- comparison anyway, continue to the next reduction. */
- if (reduce_precedence
- && (reduce_precedence < shift_precedence
- || (reduce_precedence == shift_precedence
- && token->assoc == right_assoc)))
- continue;
- if (!AnnotationList__stateMakesContribution (self, nitems, ci,
- lookaheads))
- continue;
- /* This uneliminated reduction contributes, so see if it can cause
- an error action. */
- if (reduce_precedence == shift_precedence
- && token->assoc == non_assoc)
- {
- /* It's not possible to find split-stable domination over
- shift after a potential %nonassoc. */
- if (find_stable_domination_over_shift)
- return ContributionIndex__none;
- if (!require_split_stable
- || AnnotationList__isContributionAlways (self, ci))
- return ContributionIndex__error_action;
- find_stable_error_action_domination = true;
- }
- /* Consider this uneliminated contributing reduction in the R/R
- comparison. */
- if (ci_rr_dominator == ContributionIndex__none)
- ci_rr_dominator = ci;
- /* If precedence is set for this uneliminated contributing
- reduction, it dominates the shift, so try to figure out which
- reduction dominates the R/R comparison. */
- if (reduce_precedence)
- {
- /* It's not possible to find split-stable error action
- domination after a potential reduction. */
- if (find_stable_error_action_domination)
- return ContributionIndex__none;
- if (!require_split_stable)
- return ci_rr_dominator;
- if (!AnnotationList__isContributionAlways (self,
- ci_rr_dominator))
- return ContributionIndex__none;
- if (AnnotationList__isContributionAlways (self, ci))
- return ci_rr_dominator;
- find_stable_domination_over_shift = true;
- }
- }
- }
- if (find_stable_domination_over_shift
- || find_stable_error_action_domination)
- return ContributionIndex__none;
- /* No reduce or error action domination found, so shift dominates. */
- return ci_shift;
- }
-
- /* R/R conflict, so the reduction with the lowest rule number dominates.
- Fortunately, contributions are sorted by rule number. */
- {
- ContributionIndex ci;
- for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
- if (AnnotationList__stateMakesContribution (self, nitems, ci,
- lookaheads))
- {
- if (require_split_stable
- && !AnnotationList__isContributionAlways (self, ci))
- return ContributionIndex__none;
- return ci;
- }
- }
- return ContributionIndex__none;
-}
+/* IELR's inadequacy annotation list.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "AnnotationList.h"
+#include "lalr.h"
+#include "ielr.h"
+
+/**
+ * \pre
+ * - <tt>annotations_obstackp != NULL</tt>.
+ * \post
+ * - \c result is a new \c AnnotationList with one node whose:
+ * - \c inadequacyNode member is \c NULL.
+ * - \c contributions member is allocated with \c contribution_count
+ * uninitialized elements.
+ * - All memory was allocated on \c annotations_obstackp.
+ */
+static AnnotationList*
+AnnotationList__alloc_on_obstack (ContributionIndex contribution_count,
+ struct obstack *annotations_obstackp)
+{
+ AnnotationList *result;
+ size_t contributions_size =
+ contribution_count * sizeof result->contributions[0];
+ result = obstack_alloc (annotations_obstackp,
+ offsetof (AnnotationList, contributions)
+ + contributions_size);
+ result->next = NULL;
+ result->inadequacyNode = NULL;
+ return result;
+}
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>0 <= ci < self->inadequacyNode->contributionCount</tt>.
+ * \post
+ * - \c result = true iff contribution \c ci in \c self represents an
+ * "always" contribution.
+ */
+static bool
+AnnotationList__isContributionAlways (AnnotationList const *self,
+ ContributionIndex ci)
+{
+ aver (0 <= ci && ci < self->inadequacyNode->contributionCount);
+ return self->contributions[ci] == NULL;
+}
+
+/**
+ * \pre
+ * - \c self is a single node.
+ * - \c self annotates the same state as every other node in \c list, and
+ * that state has \c nitems kernel items.
+ * \post
+ * - If the list \c list already contains an identical annotation to \c self,
+ * \c self was discarded, \c result is false, and the caller is responsible
+ * for the memory of \c self.
+ * - Otherwise, \c list now contains the node \c self, \c result is true, and
+ * \c list assumes responsibility for the memory of \c self.
+ * - The sort in \c list is:
+ * - Sort in reverse order on the unique ID of the associated
+ * inadequacy node. Because these IDs are assigned in ascending
+ * order, this should mean that the insertion position within an
+ * annotation list is usually near the beginning with other
+ * annotations associated with the same inadequacy.
+ * - Next, sort on the first contribution that is different as follows:
+ * - Sort an always-contribution before a never-contribution before a
+ * potential-contribution.
+ * - Two always-contributions are identical.
+ * - Two never-contributions are identical.
+ * - For two potential-contributions, sort on the contributions' kernel
+ * item bitsets interpreted as binary numbers.
+ * - The sorting has a few effects:
+ * - It accelerates elimination of identical annotations during insertion.
+ * - It determines how the output of \c AnnotationList__debug is sorted.
+ * - Other than that, it's probably not important.
+ */
+static bool
+AnnotationList__insertInto (AnnotationList *self, AnnotationList **list,
+ size_t nitems)
+{
+ AnnotationList **node;
+ for (node = list; *node; node = &(*node)->next)
+ {
+ int cmp = 0;
+ ContributionIndex ci;
+ if (self->inadequacyNode->id < (*node)->inadequacyNode->id)
+ cmp = 1;
+ else if ((*node)->inadequacyNode->id < self->inadequacyNode->id)
+ cmp = -1;
+ else
+ for (ci = 0;
+ cmp == 0 && ci < self->inadequacyNode->contributionCount;
+ ++ci)
+ {
+ if (AnnotationList__isContributionAlways (self, ci))
+ {
+ if (!AnnotationList__isContributionAlways (*node, ci))
+ cmp = -1;
+ }
+ else if (AnnotationList__isContributionAlways (*node, ci))
+ cmp = 1;
+ else
+ {
+ size_t item;
+ for (item = 0; cmp == 0 && item < nitems; ++item)
+ {
+ if (!Sbitset__test (self->contributions[ci], item))
+ {
+ if (Sbitset__test ((*node)->contributions[ci], item))
+ cmp = -1;
+ }
+ else if (!Sbitset__test ((*node)->contributions[ci], item))
+ cmp = 1;
+ }
+ }
+ }
+ if (cmp < 0)
+ {
+ self->next = *node;
+ *node = self;
+ break;
+ }
+ else if (cmp == 0)
+ {
+ self = NULL;
+ break;
+ }
+ }
+ if (!*node)
+ *node = self;
+ return self != NULL;
+}
+
+static bitset
+AnnotationList__compute_shift_tokens (transitions *trans)
+{
+ bitset shift_tokens = bitset_create (ntokens, BITSET_FIXED);
+ int i;
+ FOR_EACH_SHIFT (trans, i)
+ bitset_set (shift_tokens, TRANSITION_SYMBOL (trans, i));
+ return shift_tokens;
+}
+
+static bitset
+AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
+ reductions *reds)
+{
+ bitset conflicted_tokens = bitset_create (ntokens, BITSET_FIXED);
+ bitset conflicted_tokens_rule = bitset_create (ntokens, BITSET_FIXED);
+ bitset tokens = bitset_create (ntokens, BITSET_FIXED);
+ int i;
+
+ bitset_copy (tokens, shift_tokens);
+ for (i = 0; i < reds->num; ++i)
+ {
+ bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]);
+ bitset_or (conflicted_tokens,
+ conflicted_tokens, conflicted_tokens_rule);
+ bitset_or (tokens, tokens, reds->lookahead_tokens[i]);
+ /* Check that rules are sorted on rule number or the next step in
+ AnnotationList__compute_from_inadequacies will misbehave. */
+ aver (i == 0 || reds->rules[i-1] < reds->rules[i]);
+ }
+
+ bitset_free (tokens);
+ bitset_free (conflicted_tokens_rule);
+
+ return conflicted_tokens;
+}
+
+static bool
+AnnotationList__compute_lhs_contributions (state *s, rule *the_rule,
+ symbol_number conflicted_token,
+ bitsetv follow_kernel_items,
+ bitsetv always_follows,
+ state ***predecessors,
+ bitset **item_lookahead_sets,
+ Sbitset *items,
+ struct obstack
+ *annotations_obstackp)
+{
+ goto_number lhs_goto = map_goto (s->number, the_rule->lhs->number);
+ if (bitset_test (always_follows[lhs_goto], conflicted_token))
+ return true;
+ *items = Sbitset__new_on_obstack (s->nitems, annotations_obstackp);
+ {
+ bitset_iterator biter_item;
+ bitset_bindex item;
+ BITSET_FOR_EACH (biter_item, follow_kernel_items[lhs_goto], item, 0)
+ if (ielr_item_has_lookahead (s, 0, item, conflicted_token,
+ predecessors, item_lookahead_sets))
+ Sbitset__set (*items, item);
+ }
+ return false;
+}
+
+static void
+AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
+ bitsetv follow_kernel_items,
+ bitsetv always_follows,
+ state ***predecessors,
+ bitset **item_lookahead_sets,
+ AnnotationList
+ **annotation_lists,
+ AnnotationIndex
+ *annotation_counts,
+ struct obstack
+ *annotations_obstackp)
+{
+ state **predecessor;
+ bitset *lookaheads;
+ for (predecessor = predecessors[s->number]; *predecessor; ++predecessor)
+ {
+ AnnotationList *annotation_node =
+ AnnotationList__alloc_on_obstack (
+ self->inadequacyNode->contributionCount, annotations_obstackp);
+ bool potential_contribution = false;
+ annotation_node->inadequacyNode = self->inadequacyNode;
+ lookaheads = NULL;
+ {
+ ContributionIndex ci;
+ for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
+ {
+ symbol_number contribution_token =
+ InadequacyList__getContributionToken (self->inadequacyNode, ci)
+ ->number;
+ if (AnnotationList__isContributionAlways (self, ci))
+ {
+ annotation_node->contributions[ci] = NULL;
+ continue;
+ }
+ annotation_node->contributions[ci] =
+ Sbitset__new_on_obstack ((*predecessor)->nitems,
+ annotations_obstackp);
+ {
+ size_t predecessor_item = 0;
+ Sbitset sbiter_item;
+ Sbitset__Index self_item;
+ SBITSET__FOR_EACH (self->contributions[ci], s->nitems,
+ sbiter_item, self_item)
+ {
+ /* If this kernel item is the beginning of a RHS, it must be
+ the kernel item in the start state, and so it has an empty
+ lookahead set. Thus, it can't contribute to inadequacies,
+ and so it should never have been identified as a
+ contribution. If, instead, this kernel item is the
+ successor of the start state's kernel item, the lookahead
+ set is still empty, and so it also should never have been
+ identified as a contribution. This situation is fortunate
+ because we want to avoid the - 2 below in both cases. */
+ aver (s->items[self_item] > 1);
+ /* If this kernel item is next to the beginning of the RHS,
+ then check all of the predecessor's goto follows for the
+ LHS. */
+ if (item_number_is_rule_number (ritem[s->items[self_item]
+ - 2]))
+ {
+ Sbitset items;
+ unsigned int rulei;
+ for (rulei = s->items[self_item];
+ !item_number_is_rule_number (ritem[rulei]);
+ ++rulei)
+ ;
+ if (AnnotationList__compute_lhs_contributions (
+ *predecessor,
+ &rules[item_number_as_rule_number (ritem[rulei])],
+ contribution_token,
+ follow_kernel_items, always_follows, predecessors,
+ item_lookahead_sets, &items, annotations_obstackp))
+ {
+ obstack_free (annotations_obstackp,
+ annotation_node->contributions[ci]);
+ annotation_node->contributions[ci] = NULL;
+ break;
+ }
+ else
+ {
+ Sbitset__or (annotation_node->contributions[ci],
+ annotation_node->contributions[ci],
+ items, (*predecessor)->nitems);
+ obstack_free (annotations_obstackp, items);
+ }
+ }
+ /* If this kernel item is later in the RHS, then check the
+ predecessor item's lookahead set. */
+ else
+ {
+ /* We don't have to start the predecessor item search at
+ the beginning every time because items from both
+ states are sorted by their indices in ritem. */
+ for (;
+ predecessor_item < (*predecessor)->nitems;
+ ++predecessor_item)
+ if ((*predecessor)->items[predecessor_item]
+ == s->items[self_item] - 1)
+ break;
+ aver (predecessor_item != (*predecessor)->nitems);
+ if (ielr_item_has_lookahead (*predecessor, 0,
+ predecessor_item,
+ contribution_token,
+ predecessors,
+ item_lookahead_sets))
+ Sbitset__set (annotation_node->contributions[ci],
+ predecessor_item);
+ }
+ }
+ }
+ if (annotation_node->contributions[ci])
+ {
+ Sbitset biter;
+ Sbitset__Index i;
+ SBITSET__FOR_EACH (annotation_node->contributions[ci],
+ (*predecessor)->nitems, biter, i)
+ {
+ potential_contribution = true;
+ if (!lookaheads)
+ {
+ size_t j;
+ lookaheads = xnmalloc ((*predecessor)->nitems,
+ sizeof *lookaheads);
+ for (j = 0; j < (*predecessor)->nitems; ++j)
+ lookaheads[j] = NULL;
+ }
+ if (!lookaheads[i])
+ lookaheads[i] = bitset_create (ntokens, BITSET_FIXED);
+ bitset_set (lookaheads[i], contribution_token);
+ }
+ }
+ }
+ }
+
+ /* If the predecessor has any contributions besides just "always" and
+ "never" contributions:
+ - If the dominant contribution is split-stable, the annotation could
+ not affect merging on this predecessor state or its eventual
+ predecessor states. Moreover, all contributions that affect
+ whether the dominant contribution remains dominant must be "always"
+ or "never" contributions in order for the dominant contribution to
+ be split-stable. Thus, the dominant contribution computation result
+ in eventual successor states will not be affected by lookaheads
+ tracked for this predecessor state. (Also, as in the isocore
+ compatibility test, we depend on the fact that isocores with equal
+ dominant contributions will have the same dominant contribution when
+ merged. Otherwise, we might have to worry that the presence of a
+ potential contribution might somehow be the culprit of that behavior
+ and thus need to be tracked regardless of the split stability of the
+ dominant contribution.) Thus, go ahead and discard the annotation
+ to save space now plus time during state splitting.
+ - Otherwise, record the annotation, and compute any resulting
+ annotations needed on predecessor states. */
+ if (potential_contribution)
+ {
+ if (ContributionIndex__none
+ != AnnotationList__computeDominantContribution (
+ annotation_node, (*predecessor)->nitems, lookaheads, true))
+ {
+ obstack_free (annotations_obstackp, annotation_node);
+ annotation_node = NULL;
+ }
+ {
+ size_t i;
+ for (i = 0; i < (*predecessor)->nitems; ++i)
+ if (lookaheads[i])
+ bitset_free (lookaheads[i]);
+ free (lookaheads);
+ }
+ if (annotation_node)
+ {
+ if (AnnotationList__insertInto (annotation_node,
+ &annotation_lists[(*predecessor)
+ ->number],
+ (*predecessor)->nitems))
+ {
+ ++annotation_counts[(*predecessor)->number];
+ AnnotationList__computePredecessorAnnotations (
+ annotation_node, *predecessor,
+ follow_kernel_items, always_follows, predecessors,
+ item_lookahead_sets, annotation_lists, annotation_counts,
+ annotations_obstackp);
+ }
+ else
+ obstack_free (annotations_obstackp, annotation_node);
+ }
+ }
+ else
+ obstack_free (annotations_obstackp, annotation_node);
+ }
+}
+
+void
+AnnotationList__compute_from_inadequacies (
+ state *s, bitsetv follow_kernel_items, bitsetv always_follows,
+ state ***predecessors, bitset **item_lookahead_sets,
+ InadequacyList **inadequacy_lists, AnnotationList **annotation_lists,
+ AnnotationIndex *annotation_counts,
+ ContributionIndex *max_contributionsp,
+ struct obstack *annotations_obstackp,
+ InadequacyListNodeCount *inadequacy_list_node_count)
+{
+ bitsetv all_lookaheads;
+ bitset shift_tokens;
+ bitset conflicted_tokens;
+ bitset_iterator biter_conflict;
+ bitset_bindex conflicted_token;
+
+ /* Return an empty list if s->lookahead_tokens = NULL. */
+ if (s->consistent)
+ return;
+
+ all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED);
+ bitsetv_ones (all_lookaheads);
+ shift_tokens = AnnotationList__compute_shift_tokens (s->transitions);
+ conflicted_tokens =
+ AnnotationList__compute_conflicted_tokens (shift_tokens, s->reductions);
+
+ /* Add an inadequacy annotation for each conflicted_token. */
+ BITSET_FOR_EACH (biter_conflict, conflicted_tokens, conflicted_token, 0)
+ {
+ AnnotationList *annotation_node;
+ /* FIXME: Would a BITSET_FRUGAL or BITEST_SPARSE be more efficient? Now
+ or convert it inside InadequacyList__new_conflict? */
+ bitset actions = bitset_create (s->reductions->num + 1, BITSET_FIXED);
+ ContributionIndex contribution_count = 0;
+ bool potential_contribution = false;
+
+ /* Allocate the annotation node. */
+ {
+ int rule_i;
+ for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
+ if (bitset_test (s->reductions->lookahead_tokens[rule_i],
+ conflicted_token))
+ ++contribution_count;
+ if (bitset_test (shift_tokens, conflicted_token))
+ ++contribution_count;
+ annotation_node =
+ AnnotationList__alloc_on_obstack (contribution_count,
+ annotations_obstackp);
+ }
+
+ /* Add a contribution for each reduction that has conflicted_token as a
+ lookahead. */
+ {
+ ContributionIndex ci = 0;
+ int item_i = 0;
+ int rule_i;
+ for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
+ {
+ rule *the_rule = s->reductions->rules[rule_i];
+ if (bitset_test (s->reductions->lookahead_tokens[rule_i],
+ conflicted_token))
+ {
+ bitset_set (actions, rule_i);
+ /* If this reduction is on a kernel item, just add it. */
+ if (!item_number_is_rule_number (the_rule->rhs[0]))
+ {
+ annotation_node->contributions[ci] =
+ Sbitset__new_on_obstack (s->nitems,
+ annotations_obstackp);
+ /* Catch item_i up to rule_i. This works because both are
+ sorted on rule number. */
+ while (!item_number_is_rule_number (
+ ritem[s->items[item_i]])
+ || item_number_as_rule_number (
+ ritem[s->items[item_i]])
+ != the_rule->number)
+ {
+ ++item_i;
+ aver (item_i < s->nitems);
+ }
+ Sbitset__set (annotation_node->contributions[ci], item_i);
+ }
+ /* Otherwise, add the kernel items whose lookahead sets
+ contribute the conflicted token to this reduction's
+ lookahead set. */
+ else if (AnnotationList__compute_lhs_contributions (
+ s, the_rule, conflicted_token, follow_kernel_items,
+ always_follows, predecessors, item_lookahead_sets,
+ &annotation_node->contributions[ci],
+ annotations_obstackp))
+ {
+ annotation_node->contributions[ci++] = NULL;
+ continue;
+ }
+ /* The lookahead token has to come from somewhere. */
+ aver (!Sbitset__isEmpty (annotation_node->contributions[ci],
+ s->nitems));
+ ++ci;
+ potential_contribution = true;
+ }
+ }
+ }
+
+ /* If there are any contributions besides just "always" contributions:
+ - If there's also a shift contribution, record it.
+ - If the dominant contribution is split-stable, then the annotation
+ could not affect merging, so go ahead and discard the annotation and
+ the inadequacy to save space now plus time during state splitting.
+ - Otherwise, record the annotation and the inadequacy, and compute any
+ resulting annotations needed on predecessor states. */
+ if (potential_contribution)
+ {
+ if (bitset_test (shift_tokens, conflicted_token))
+ {
+ bitset_set (actions, s->reductions->num);
+ annotation_node->contributions[contribution_count - 1] = NULL;
+ }
+ {
+ InadequacyList *conflict_node =
+ InadequacyList__new_conflict (
+ s, symbols[conflicted_token], actions,
+ inadequacy_list_node_count);
+ actions = NULL;
+ annotation_node->inadequacyNode = conflict_node;
+ if (ContributionIndex__none
+ != AnnotationList__computeDominantContribution (
+ annotation_node, s->nitems, all_lookaheads, true))
+ {
+ obstack_free (annotations_obstackp, annotation_node);
+ InadequacyList__delete (conflict_node);
+ }
+ else
+ {
+ InadequacyList__prependTo (conflict_node,
+ &inadequacy_lists[s->number]);
+ aver (AnnotationList__insertInto (
+ annotation_node, &annotation_lists[s->number],
+ s->nitems));
+ /* This aver makes sure the
+ AnnotationList__computeDominantContribution check above
+ does discard annotations in the simplest case of a S/R
+ conflict with no token precedence. */
+ aver (!bitset_test (shift_tokens, conflicted_token)
+ || symbols[conflicted_token]->prec);
+ ++annotation_counts[s->number];
+ if (contribution_count > *max_contributionsp)
+ *max_contributionsp = contribution_count;
+ AnnotationList__computePredecessorAnnotations (
+ annotation_node, s,
+ follow_kernel_items, always_follows, predecessors,
+ item_lookahead_sets, annotation_lists, annotation_counts,
+ annotations_obstackp);
+ }
+ }
+ }
+ else
+ {
+ bitset_free (actions);
+ obstack_free (annotations_obstackp, annotation_node);
+ }
+ }
+
+ bitsetv_free (all_lookaheads);
+ bitset_free (shift_tokens);
+ bitset_free (conflicted_tokens);
+}
+
+void
+AnnotationList__debug (AnnotationList const *self, size_t nitems, int spaces)
+{
+ AnnotationList const *a;
+ AnnotationIndex ai;
+ for (a = self, ai = 0; a; a = a->next, ++ai)
+ {
+ {
+ int j;
+ for (j = 0; j < spaces; ++j)
+ putc (' ', stderr);
+ }
+ fprintf (stderr, "Annotation %d (manifesting state %d):\n",
+ ai, a->inadequacyNode->manifestingState->number);
+ {
+ ContributionIndex ci;
+ bitset_bindex rulei = 0; /* init suppresses compiler warning */
+ rulei = bitset_first (a->inadequacyNode->inadequacy.conflict.actions);
+ for (ci = 0; ci < a->inadequacyNode->contributionCount; ++ci)
+ {
+ symbol_number token =
+ InadequacyList__getContributionToken (a->inadequacyNode, ci)
+ ->number;
+ {
+ int j;
+ for (j = 0; j < spaces+2; ++j)
+ putc (' ', stderr);
+ }
+ if (ci == InadequacyList__getShiftContributionIndex (
+ a->inadequacyNode))
+ fprintf (stderr, "Contributes shift of token %d.\n", token);
+ else
+ {
+ fprintf (stderr, "Contributes token %d", token);
+ aver (rulei != BITSET_BINDEX_MAX);
+ fprintf (stderr, " as lookahead, rule number %d",
+ a->inadequacyNode->manifestingState
+ ->reductions->rules[rulei]->number);
+ rulei =
+ bitset_next (a->inadequacyNode->inadequacy.conflict.actions,
+ rulei+1);
+ if (AnnotationList__isContributionAlways (a, ci))
+ fprintf (stderr, " always.");
+ else
+ {
+ fprintf (stderr, ", items: ");
+ Sbitset__fprint (a->contributions[ci], nitems, stderr);
+ }
+ fprintf (stderr, "\n");
+ }
+ }
+ }
+ }
+}
+
+void
+AnnotationList__computeLookaheadFilter (AnnotationList const *self,
+ size_t nitems,
+ bitsetv lookahead_filter)
+{
+ bitsetv_zero (lookahead_filter);
+ for (; self; self = self->next)
+ {
+ ContributionIndex ci;
+ for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
+ if (!AnnotationList__isContributionAlways (self, ci))
+ {
+ Sbitset__Index item;
+ Sbitset biter;
+ symbol_number token =
+ InadequacyList__getContributionToken (self->inadequacyNode, ci)
+ ->number;
+ SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
+ bitset_set (lookahead_filter[item], token);
+ }
+ }
+}
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - \c nitems is the number of kernel items in the LR(0) state that \c self
+ * annotates.
+ * - \c lookaheads describes the lookahead sets on the kernel items of some
+ * isocore of the LR(0) state that \c self annotates. Either:
+ * - <tt>lookaheads = NULL</tt> only if the lookahead set on every kernel
+ * item is empty.
+ * - For any <tt>0 <= i < nitems</tt>, <tt>lookaheads[i]</tt> is either:
+ * - \c NULL only if the lookahead set on kernel item \c i is empty.
+ * - The (possibly empty) lookahead set on kernel item \c i.
+ * - <tt>0 <= ci < self->inadequacyNode->contributionCount</tt>.
+ * \post
+ * - \c result = true iff contribution \c ci in \c self is made by the state
+ * described by \c lookaheads.
+ */
+static bool
+AnnotationList__stateMakesContribution (AnnotationList const *self,
+ size_t nitems, ContributionIndex ci,
+ bitset *lookaheads)
+{
+ if (AnnotationList__isContributionAlways (self, ci))
+ return true;
+ if (!lookaheads)
+ return false;
+ {
+ symbol_number token =
+ InadequacyList__getContributionToken (self->inadequacyNode, ci)->number;
+ Sbitset__Index item;
+ Sbitset biter;
+ SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
+ if (lookaheads[item] && bitset_test (lookaheads[item], token))
+ return true;
+ }
+ return false;
+}
+
+ContributionIndex
+AnnotationList__computeDominantContribution (AnnotationList const *self,
+ size_t nitems, bitset *lookaheads,
+ bool require_split_stable)
+{
+ symbol *token;
+ ContributionIndex const ci_shift =
+ InadequacyList__getShiftContributionIndex (self->inadequacyNode);
+
+ token = self->inadequacyNode->inadequacy.conflict.token;
+
+ /* S/R conflict. */
+ if (ci_shift != ContributionIndex__none)
+ {
+ bool find_stable_domination_over_shift = false;
+ bool find_stable_error_action_domination = false;
+ {
+ ContributionIndex ci;
+ int actioni;
+ ContributionIndex ci_rr_dominator = ContributionIndex__none;
+ int shift_precedence = token->prec;
+
+ /* If the token has no precedence set, shift is always chosen. */
+ if (!shift_precedence)
+ return ci_shift;
+
+ /* Figure out which reductions contribute, which of those would
+ dominate in a R/R comparison, and whether any reduction dominates
+ the shift so that the R/R comparison is actually needed. */
+ for (ci = 0, actioni = bitset_first (self->inadequacyNode->inadequacy
+ .conflict.actions);
+ ci < self->inadequacyNode->contributionCount;
+ ++ci, actioni = bitset_next (self->inadequacyNode->inadequacy
+ .conflict.actions, actioni+1))
+ {
+ int reduce_precedence = 0;
+ if (ci == ci_shift)
+ continue;
+ {
+ rule *r = self->inadequacyNode->manifestingState
+ ->reductions->rules[actioni];
+ if (r->prec)
+ reduce_precedence = r->prec->prec;
+ }
+ /* If there's no need to check whether this reduction actually
+ contributes because the shift eliminates it from the R/R
+ comparison anyway, continue to the next reduction. */
+ if (reduce_precedence
+ && (reduce_precedence < shift_precedence
+ || (reduce_precedence == shift_precedence
+ && token->assoc == right_assoc)))
+ continue;
+ if (!AnnotationList__stateMakesContribution (self, nitems, ci,
+ lookaheads))
+ continue;
+ /* This uneliminated reduction contributes, so see if it can cause
+ an error action. */
+ if (reduce_precedence == shift_precedence
+ && token->assoc == non_assoc)
+ {
+ /* It's not possible to find split-stable domination over
+ shift after a potential %nonassoc. */
+ if (find_stable_domination_over_shift)
+ return ContributionIndex__none;
+ if (!require_split_stable
+ || AnnotationList__isContributionAlways (self, ci))
+ return ContributionIndex__error_action;
+ find_stable_error_action_domination = true;
+ }
+ /* Consider this uneliminated contributing reduction in the R/R
+ comparison. */
+ if (ci_rr_dominator == ContributionIndex__none)
+ ci_rr_dominator = ci;
+ /* If precedence is set for this uneliminated contributing
+ reduction, it dominates the shift, so try to figure out which
+ reduction dominates the R/R comparison. */
+ if (reduce_precedence)
+ {
+ /* It's not possible to find split-stable error action
+ domination after a potential reduction. */
+ if (find_stable_error_action_domination)
+ return ContributionIndex__none;
+ if (!require_split_stable)
+ return ci_rr_dominator;
+ if (!AnnotationList__isContributionAlways (self,
+ ci_rr_dominator))
+ return ContributionIndex__none;
+ if (AnnotationList__isContributionAlways (self, ci))
+ return ci_rr_dominator;
+ find_stable_domination_over_shift = true;
+ }
+ }
+ }
+ if (find_stable_domination_over_shift
+ || find_stable_error_action_domination)
+ return ContributionIndex__none;
+ /* No reduce or error action domination found, so shift dominates. */
+ return ci_shift;
+ }
+
+ /* R/R conflict, so the reduction with the lowest rule number dominates.
+ Fortunately, contributions are sorted by rule number. */
+ {
+ ContributionIndex ci;
+ for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
+ if (AnnotationList__stateMakesContribution (self, nitems, ci,
+ lookaheads))
+ {
+ if (require_split_stable
+ && !AnnotationList__isContributionAlways (self, ci))
+ return ContributionIndex__none;
+ return ci;
+ }
+ }
+ return ContributionIndex__none;
+}
diff --git a/contrib/tools/bison/bison/src/AnnotationList.h b/contrib/tools/bison/bison/src/AnnotationList.h
index 5abaa2e79b..dfcdb52489 100644
--- a/contrib/tools/bison/bison/src/AnnotationList.h
+++ b/contrib/tools/bison/bison/src/AnnotationList.h
@@ -1,182 +1,182 @@
-/* IELR's inadequacy annotation list.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef ANNOTATION_LIST_H_
-# define ANNOTATION_LIST_H_
-
-# include <bitsetv.h>
-# include "Sbitset.h"
-# include "InadequacyList.h"
-# include "state.h"
-
-typedef unsigned int AnnotationIndex;
-
-/**
- * A node in a list of annotations on a particular LR(0) state. Each
- * annotation records how isocores of that LR(0) state might contribute to an
- * individual inadequacy, which might manifest in a different state. Don't
- * break encapsulation by modifying the fields directly. Use the provided
- * interface functions.
- */
-typedef struct AnnotationList
-{
- /** The next node in the list or \c NULL if none. */
- struct AnnotationList *next;
- /** The \c InadequacyList node describing how this inadequacy manifests. */
- InadequacyList *inadequacyNode;
- /**
- * List of how the "always", "never", and potential contributions of the
- * inadequacy might be made by isocores of the annotated LR(0) state:
- * - The number of rows is the number of contributions. That is,
- * <tt>AnnotationList::inadequacyNode->contributionCount</tt>.
- * - The token associated with contribution \c i is
- * <tt>InadequacyList__getContributionToken (AnnotationList::inadequacyNode, i)</tt>.
- * - Iff <tt>AnnotationList::contributions[i] = NULL</tt>, contribution
- * \c i is an "always" contribution. That is, for every isocore of the
- * annotated LR(0) state, its core or the core of one its eventual
- * successors will definitely make this contribution to the inadequacy.
- * It may contribute by either:
- * - Creating a shift of contribution <tt>i</tt>'s token in the state
- * that can manifest the inadequacy.
- * - Propagating that token to the lookahead set of contribution
- * <tt>i</tt>'s reduction in the state that can manifest the
- * inadequacy.
- * - Otherwise:
- * - The number of columns in <tt>AnnotationList::contributions[i]</tt>
- * is the number of kernel items in any isocore of the annotated LR(0)
- * state.
- * - Iff <tt>AnnotationList::contributions[i]</tt> is empty, contribution
- * \c i is a "never" contribution. That is, no isocore of the
- * annotated LR(0) state can make this contribution to the inadequacy.
- * - Otherwise, for each bit \c j that is set in
- * <tt>AnnotationList::contributions[i]</tt>, if the token associated
- * with contribution \c i is present in the lookahead set of kernel
- * item \c j of an isocore of the annotated LR(0) state, that isocore
- * will make contribution \c i to the inadequacy by propagating the
- * contribution's token to the lookahead set of the contribution's
- * reduction in the state that can manifest the inadequacy.
- */
- Sbitset contributions[1];
-} AnnotationList;
-
-/**
- * \pre
- * - <tt>s != NULL</tt>.
- * - \c follow_kernel_items, \c always_follows, and \c predecessors were
- * computed by \c ielr_compute_auxiliary_tables.
- * - The size of each of \c annotation_lists and \c annotation_counts is
- * \c ::nstates.
- * - If no \c InadequacyList nodes are currently allocated for the
- * parser tables to which \c s belongs, then it is best if
- * <tt>*inadequacy_list_node_count</tt> is zero to avoid overflow.
- * Otherwise, <tt>*inadequacy_list_node_count</tt> has not been
- * modified by any function except
- * \c AnnotationList__compute_from_inadequacies since the invocation
- * of \c AnnotationList__compute_from_inadequacies that constructed
- * the first of the \c InadequacyList nodes currently allocated for
- * those parser tables.
- * \post
- * - <tt>inadequacy_lists[s->number]</tt> now describes all inadequacies that
- * manifest in \c s.
- * - For every state <tt>states[i]</tt>, <tt>annotation_lists[i]</tt> now
- * contains all annotations associated with all inadequacies that manifest
- * in \c s.
- * - <tt>annotation_counts[i]</tt> was incremented by the number of new
- * annotations added to <tt>states[i]</tt>.
- * - <tt>*max_contributionsp</tt> is the higher of:
- * - The maximum number of contributions computed per annotation.
- * - <tt>*max_contributionsp \@pre</tt>.
- * - All memory for all new annotations was allocated on
- * \c annotations_obstackp.
- */
-void
-AnnotationList__compute_from_inadequacies (
- state *s, bitsetv follow_kernel_items, bitsetv always_follows,
- state ***predecessors, bitset **item_lookahead_sets,
- InadequacyList **inadequacy_lists, AnnotationList **annotation_lists,
- AnnotationIndex *annotation_counts,
- ContributionIndex *max_contributionsp,
- struct obstack *annotations_obstackp,
- InadequacyListNodeCount *inadequacy_list_node_count);
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - \c nitems is the number of kernel items in the LR(0) state that every
- * node in the list \c self annotates.
- * \post
- * - A textual representation of all nodes in the list \c self was printed to
- * stderr. \c spaces spaces were printed before each line of the text.
- */
-void AnnotationList__debug (AnnotationList const *self, size_t nitems,
- int spaces);
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - \c nitems is the number of kernel items in the LR(0) state that \c self
- * annotates.
- * - The number of rows in \c lookahead_filter is at least \c nitems, and the
- * number of columns is \c ::ntokens.
- * \post
- * - <tt>lookahead_filter[i][j]</tt> is set iff some annotation in the list
- * \c self lists token \c j in kernel item \c i as a contributor.
- */
-void AnnotationList__computeLookaheadFilter (AnnotationList const *self,
- size_t nitems,
- bitsetv lookahead_filter);
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - \c nitems is the number of kernel items in the LR(0) state that \c self
- * annotates.
- * - \c lookaheads describes the lookahead sets on the kernel items of some
- * isocore of the LR(0) state that \c self annotates. Either:
- * - <tt>lookaheads = NULL</tt> only if the lookahead set on every kernel
- * item is empty.
- * - For any <tt>0 <= i < nitems</tt>, <tt>lookaheads[i]</tt> is either:
- * - \c NULL only if the lookahead set on kernel item \c i is empty.
- * - The (possibly empty) lookahead set on kernel item \c i.
- * \post
- * - If <tt>require_split_stable = false</tt>, \c result = either:
- * - \c ContributionIndex__none iff the state described by \c lookaheads
- * makes none of the contributions in \c self.
- * - The index of the dominating contribution in \c self that is made by
- * that state.
- * - \c ContributionIndex__error_action to indicate that the inadequacy
- * manifests as a conflict and that a syntax error action (because of a
- * %nonassoc) dominates instead.
- * - Otherwise, \c result is the same as if <tt>require_split_stable =
- * false</tt> except that it is also \c ContributionIndex__none if there
- * are contributions made by the state but the dominating contribution is
- * not split-stable. By split-stable, we mean that the dominating
- * contribution cannot change due to loss of one or more potential
- * contributions due to loss of lookaheads due to splitting of the state.
- * - After determining which contributions are actually made by the state,
- * the algorithm for determining which contribution dominates in the
- * conflict is intended to choose exactly the same action as conflicts.c
- * would choose... no matter how crazy conflicts.c's choice is.
- */
-ContributionIndex
-AnnotationList__computeDominantContribution (AnnotationList const *self,
- size_t nitems, bitset *lookaheads,
- bool require_split_stable);
-
-#endif /* !ANNOTATION_LIST_H_ */
+/* IELR's inadequacy annotation list.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef ANNOTATION_LIST_H_
+# define ANNOTATION_LIST_H_
+
+# include <bitsetv.h>
+# include "Sbitset.h"
+# include "InadequacyList.h"
+# include "state.h"
+
+typedef unsigned int AnnotationIndex;
+
+/**
+ * A node in a list of annotations on a particular LR(0) state. Each
+ * annotation records how isocores of that LR(0) state might contribute to an
+ * individual inadequacy, which might manifest in a different state. Don't
+ * break encapsulation by modifying the fields directly. Use the provided
+ * interface functions.
+ */
+typedef struct AnnotationList
+{
+ /** The next node in the list or \c NULL if none. */
+ struct AnnotationList *next;
+ /** The \c InadequacyList node describing how this inadequacy manifests. */
+ InadequacyList *inadequacyNode;
+ /**
+ * List of how the "always", "never", and potential contributions of the
+ * inadequacy might be made by isocores of the annotated LR(0) state:
+ * - The number of rows is the number of contributions. That is,
+ * <tt>AnnotationList::inadequacyNode->contributionCount</tt>.
+ * - The token associated with contribution \c i is
+ * <tt>InadequacyList__getContributionToken (AnnotationList::inadequacyNode, i)</tt>.
+ * - Iff <tt>AnnotationList::contributions[i] = NULL</tt>, contribution
+ * \c i is an "always" contribution. That is, for every isocore of the
+ * annotated LR(0) state, its core or the core of one its eventual
+ * successors will definitely make this contribution to the inadequacy.
+ * It may contribute by either:
+ * - Creating a shift of contribution <tt>i</tt>'s token in the state
+ * that can manifest the inadequacy.
+ * - Propagating that token to the lookahead set of contribution
+ * <tt>i</tt>'s reduction in the state that can manifest the
+ * inadequacy.
+ * - Otherwise:
+ * - The number of columns in <tt>AnnotationList::contributions[i]</tt>
+ * is the number of kernel items in any isocore of the annotated LR(0)
+ * state.
+ * - Iff <tt>AnnotationList::contributions[i]</tt> is empty, contribution
+ * \c i is a "never" contribution. That is, no isocore of the
+ * annotated LR(0) state can make this contribution to the inadequacy.
+ * - Otherwise, for each bit \c j that is set in
+ * <tt>AnnotationList::contributions[i]</tt>, if the token associated
+ * with contribution \c i is present in the lookahead set of kernel
+ * item \c j of an isocore of the annotated LR(0) state, that isocore
+ * will make contribution \c i to the inadequacy by propagating the
+ * contribution's token to the lookahead set of the contribution's
+ * reduction in the state that can manifest the inadequacy.
+ */
+ Sbitset contributions[1];
+} AnnotationList;
+
+/**
+ * \pre
+ * - <tt>s != NULL</tt>.
+ * - \c follow_kernel_items, \c always_follows, and \c predecessors were
+ * computed by \c ielr_compute_auxiliary_tables.
+ * - The size of each of \c annotation_lists and \c annotation_counts is
+ * \c ::nstates.
+ * - If no \c InadequacyList nodes are currently allocated for the
+ * parser tables to which \c s belongs, then it is best if
+ * <tt>*inadequacy_list_node_count</tt> is zero to avoid overflow.
+ * Otherwise, <tt>*inadequacy_list_node_count</tt> has not been
+ * modified by any function except
+ * \c AnnotationList__compute_from_inadequacies since the invocation
+ * of \c AnnotationList__compute_from_inadequacies that constructed
+ * the first of the \c InadequacyList nodes currently allocated for
+ * those parser tables.
+ * \post
+ * - <tt>inadequacy_lists[s->number]</tt> now describes all inadequacies that
+ * manifest in \c s.
+ * - For every state <tt>states[i]</tt>, <tt>annotation_lists[i]</tt> now
+ * contains all annotations associated with all inadequacies that manifest
+ * in \c s.
+ * - <tt>annotation_counts[i]</tt> was incremented by the number of new
+ * annotations added to <tt>states[i]</tt>.
+ * - <tt>*max_contributionsp</tt> is the higher of:
+ * - The maximum number of contributions computed per annotation.
+ * - <tt>*max_contributionsp \@pre</tt>.
+ * - All memory for all new annotations was allocated on
+ * \c annotations_obstackp.
+ */
+void
+AnnotationList__compute_from_inadequacies (
+ state *s, bitsetv follow_kernel_items, bitsetv always_follows,
+ state ***predecessors, bitset **item_lookahead_sets,
+ InadequacyList **inadequacy_lists, AnnotationList **annotation_lists,
+ AnnotationIndex *annotation_counts,
+ ContributionIndex *max_contributionsp,
+ struct obstack *annotations_obstackp,
+ InadequacyListNodeCount *inadequacy_list_node_count);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - \c nitems is the number of kernel items in the LR(0) state that every
+ * node in the list \c self annotates.
+ * \post
+ * - A textual representation of all nodes in the list \c self was printed to
+ * stderr. \c spaces spaces were printed before each line of the text.
+ */
+void AnnotationList__debug (AnnotationList const *self, size_t nitems,
+ int spaces);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - \c nitems is the number of kernel items in the LR(0) state that \c self
+ * annotates.
+ * - The number of rows in \c lookahead_filter is at least \c nitems, and the
+ * number of columns is \c ::ntokens.
+ * \post
+ * - <tt>lookahead_filter[i][j]</tt> is set iff some annotation in the list
+ * \c self lists token \c j in kernel item \c i as a contributor.
+ */
+void AnnotationList__computeLookaheadFilter (AnnotationList const *self,
+ size_t nitems,
+ bitsetv lookahead_filter);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - \c nitems is the number of kernel items in the LR(0) state that \c self
+ * annotates.
+ * - \c lookaheads describes the lookahead sets on the kernel items of some
+ * isocore of the LR(0) state that \c self annotates. Either:
+ * - <tt>lookaheads = NULL</tt> only if the lookahead set on every kernel
+ * item is empty.
+ * - For any <tt>0 <= i < nitems</tt>, <tt>lookaheads[i]</tt> is either:
+ * - \c NULL only if the lookahead set on kernel item \c i is empty.
+ * - The (possibly empty) lookahead set on kernel item \c i.
+ * \post
+ * - If <tt>require_split_stable = false</tt>, \c result = either:
+ * - \c ContributionIndex__none iff the state described by \c lookaheads
+ * makes none of the contributions in \c self.
+ * - The index of the dominating contribution in \c self that is made by
+ * that state.
+ * - \c ContributionIndex__error_action to indicate that the inadequacy
+ * manifests as a conflict and that a syntax error action (because of a
+ * %nonassoc) dominates instead.
+ * - Otherwise, \c result is the same as if <tt>require_split_stable =
+ * false</tt> except that it is also \c ContributionIndex__none if there
+ * are contributions made by the state but the dominating contribution is
+ * not split-stable. By split-stable, we mean that the dominating
+ * contribution cannot change due to loss of one or more potential
+ * contributions due to loss of lookaheads due to splitting of the state.
+ * - After determining which contributions are actually made by the state,
+ * the algorithm for determining which contribution dominates in the
+ * conflict is intended to choose exactly the same action as conflicts.c
+ * would choose... no matter how crazy conflicts.c's choice is.
+ */
+ContributionIndex
+AnnotationList__computeDominantContribution (AnnotationList const *self,
+ size_t nitems, bitset *lookaheads,
+ bool require_split_stable);
+
+#endif /* !ANNOTATION_LIST_H_ */
diff --git a/contrib/tools/bison/bison/src/InadequacyList.c b/contrib/tools/bison/bison/src/InadequacyList.c
index 9510b40d91..55ced6886a 100644
--- a/contrib/tools/bison/bison/src/InadequacyList.c
+++ b/contrib/tools/bison/bison/src/InadequacyList.c
@@ -1,79 +1,79 @@
-/* IELR's inadequacy list.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "InadequacyList.h"
-
-ContributionIndex const ContributionIndex__none = -1;
-ContributionIndex const ContributionIndex__error_action = -2;
-
-InadequacyList *
-InadequacyList__new_conflict (state *manifesting_state, symbol *token,
- bitset actions,
- InadequacyListNodeCount *node_count)
-{
- InadequacyList *result = xmalloc (sizeof *result);
- result->id = (*node_count)++;
- aver (*node_count != 0);
- result->next = NULL;
- result->manifestingState = manifesting_state;
- result->contributionCount = bitset_count (actions);
- result->inadequacy.conflict.token = token;
- result->inadequacy.conflict.actions = actions;
- return result;
-}
-
-void
-InadequacyList__delete (InadequacyList *self)
-{
- while (self)
- {
- InadequacyList *node = self;
- self = self->next;
- bitset_free (node->inadequacy.conflict.actions);
- free (node);
- }
-}
-
-ContributionIndex
-InadequacyList__getShiftContributionIndex (InadequacyList const *self)
-{
- if (!bitset_test (self->inadequacy.conflict.actions,
- self->manifestingState->reductions->num))
- return ContributionIndex__none;
- return self->contributionCount - 1;
-}
-
-symbol *
-InadequacyList__getContributionToken (InadequacyList const *self,
- ContributionIndex i)
-{
- aver (0 <= i && i < self->contributionCount);
- return self->inadequacy.conflict.token;
-}
-
-void
-InadequacyList__prependTo (InadequacyList *self, InadequacyList **list)
-{
- InadequacyList *head_old = *list;
- *list = self;
- self->next = head_old;
-}
+/* IELR's inadequacy list.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "InadequacyList.h"
+
+ContributionIndex const ContributionIndex__none = -1;
+ContributionIndex const ContributionIndex__error_action = -2;
+
+InadequacyList *
+InadequacyList__new_conflict (state *manifesting_state, symbol *token,
+ bitset actions,
+ InadequacyListNodeCount *node_count)
+{
+ InadequacyList *result = xmalloc (sizeof *result);
+ result->id = (*node_count)++;
+ aver (*node_count != 0);
+ result->next = NULL;
+ result->manifestingState = manifesting_state;
+ result->contributionCount = bitset_count (actions);
+ result->inadequacy.conflict.token = token;
+ result->inadequacy.conflict.actions = actions;
+ return result;
+}
+
+void
+InadequacyList__delete (InadequacyList *self)
+{
+ while (self)
+ {
+ InadequacyList *node = self;
+ self = self->next;
+ bitset_free (node->inadequacy.conflict.actions);
+ free (node);
+ }
+}
+
+ContributionIndex
+InadequacyList__getShiftContributionIndex (InadequacyList const *self)
+{
+ if (!bitset_test (self->inadequacy.conflict.actions,
+ self->manifestingState->reductions->num))
+ return ContributionIndex__none;
+ return self->contributionCount - 1;
+}
+
+symbol *
+InadequacyList__getContributionToken (InadequacyList const *self,
+ ContributionIndex i)
+{
+ aver (0 <= i && i < self->contributionCount);
+ return self->inadequacy.conflict.token;
+}
+
+void
+InadequacyList__prependTo (InadequacyList *self, InadequacyList **list)
+{
+ InadequacyList *head_old = *list;
+ *list = self;
+ self->next = head_old;
+}
diff --git a/contrib/tools/bison/bison/src/InadequacyList.h b/contrib/tools/bison/bison/src/InadequacyList.h
index d293b9b6c6..01a10fc129 100644
--- a/contrib/tools/bison/bison/src/InadequacyList.h
+++ b/contrib/tools/bison/bison/src/InadequacyList.h
@@ -1,156 +1,156 @@
-/* IELR's inadequacy list.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef INADEQUACY_LIST_H_
-# define INADEQUACY_LIST_H_
-
-# include <bitset.h>
-# include "gram.h"
-# include "state.h"
-# include "symtab.h"
-
-/**
- * A unique ID assigned to every \c InadequacyList node.
- *
- * This must remain unsigned so that the overflow check in
- * \c InadequacyList__new_conflict works properly.
- */
-typedef unsigned long long int InadequacyListNodeCount;
-
-/**
- * For a conflict, each rule in the grammar can have at most one contributing
- * reduction except that rule 0 cannot have any because the reduction on rule 0
- * cannot have lookaheads. For a conflict, exactly one shift can contribute.
- * Thus the number of rules in the grammar is an upper bound on the number of
- * possible contributions to any conflict. The maximum number of possible
- * items in a state is also an upper bound, but the \c nitems member of \c
- * state is currently a \c size_t and thus, if changed, risks becoming out of
- * sync with this type. Whatever the type, it must support negatives for sake
- * of the special values below.
- */
-typedef rule_number ContributionIndex;
-
-/* Special \c ContributionIndex used to indicate null result when looking for a
- contribution. */
-extern ContributionIndex const ContributionIndex__none;
-
-/* Special \c ContributionIndex used by
- \c AnnotationList__computeDominantContribution to signal when the action
- chosen in a conflict is a syntax error because of a %nonassoc. */
-extern ContributionIndex const ContributionIndex__error_action;
-
-/**
- * The description of a conflict. Don't break encapsulation by modifying the
- * fields directly. Use the provided interface functions for
- * \c InadequacyList.
- */
-typedef struct {
- /** The \c token passed to \c InadequacyList__new_conflict. */
- symbol *token;
- /** The \c actions passed to \c InadequacyList__new_conflict. */
- bitset actions;
-} Conflict;
-
-/**
- * A node in a list that describes all the inadequacies that manifest in a
- * particular state. Don't break encapsulation by modifying the fields
- * directly. Use the provided interface functions.
- */
-typedef struct InadequacyList {
- struct InadequacyList *next;
- InadequacyListNodeCount id;
- state *manifestingState;
- ContributionIndex contributionCount;
- union {
- Conflict conflict;
- } inadequacy;
-} InadequacyList;
-
-/**
- * \pre
- * - <tt>manifesting_state != NULL</tt>.
- * - \c token is a token.
- * - The size of \c actions is
- * <tt>manifesting_state->reductions->num + 1</tt>.
- * - If the set of all \c InadequacyList nodes with which the new
- * \c InadequacyList node might be compared is currently empty, then
- * it is best if <tt>*node_count</tt> is zero so that the node count
- * does not eventually overflow. However, if that set is not
- * currently empty, then <tt>*node_count</tt> has not been modified
- * by any function except \c InadequacyList__new_conflict since the
- * invocation of \c InadequacyList__new_conflict that constructed
- * the first existing member of that set.
- * \post
- * - \c result is a new \c InadequacyList with one node indicating that, in
- * \c manifesting_state, the following actions are in conflict on \c token:
- * - Shift iff
- * <tt>bitset_test (actions, manifesting_state->reductions->num)</tt>.
- * - For any \c i such that
- * <tt>0 <= i < manifesting_state->reductions->num</tt>, the reduction
- * for the rule <tt>manifesting_state->reductions->rules[i]</tt> iff
- * <tt>actions[i]</tt> is set.
- * - Given any node \c n from the set of all existing
- * \c InadequacyList nodes with which \c result might be compared
- * such that <tt>n != result</tt>, then <tt>n->id < result->id</tt>.
- * - \c result assumes responsibility for the memory of \c actions.
- */
-InadequacyList *InadequacyList__new_conflict (
- state *manifesting_state, symbol *token, bitset actions,
- InadequacyListNodeCount *node_count);
-
-/**
- * \post
- * - All memory associated with all nodes in the list \c self was freed.
- */
-void InadequacyList__delete (InadequacyList *self);
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * \post
- * - \c result = either:
- * - \c ContributionIndex__none iff there is no shift contribution in
- * \c self (perhaps because \c self isn't a conflict).
- * - The index of the shift contribution, otherwise.
- */
-ContributionIndex
-InadequacyList__getShiftContributionIndex (InadequacyList const *self);
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - <tt>0 <= i < self->contributionCount</tt>.
- * \post
- * - \c result = the token associated with contribution \c i in the
- * inadequacy described by the node \c self.
- */
-symbol *InadequacyList__getContributionToken (InadequacyList const *self,
- ContributionIndex i);
-
-/**
- * \pre
- * - \c self is a single node.
- * - <tt>list != NULL</tt>.
- * \post
- * - \c list now contains \c self as its first node.
- * - \c list assumes responsibility for the memory of \c self.
- */
-void InadequacyList__prependTo (InadequacyList *self, InadequacyList **list);
-
-#endif /* !INADEQUACY_LIST_H_ */
+/* IELR's inadequacy list.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef INADEQUACY_LIST_H_
+# define INADEQUACY_LIST_H_
+
+# include <bitset.h>
+# include "gram.h"
+# include "state.h"
+# include "symtab.h"
+
+/**
+ * A unique ID assigned to every \c InadequacyList node.
+ *
+ * This must remain unsigned so that the overflow check in
+ * \c InadequacyList__new_conflict works properly.
+ */
+typedef unsigned long long int InadequacyListNodeCount;
+
+/**
+ * For a conflict, each rule in the grammar can have at most one contributing
+ * reduction except that rule 0 cannot have any because the reduction on rule 0
+ * cannot have lookaheads. For a conflict, exactly one shift can contribute.
+ * Thus the number of rules in the grammar is an upper bound on the number of
+ * possible contributions to any conflict. The maximum number of possible
+ * items in a state is also an upper bound, but the \c nitems member of \c
+ * state is currently a \c size_t and thus, if changed, risks becoming out of
+ * sync with this type. Whatever the type, it must support negatives for sake
+ * of the special values below.
+ */
+typedef rule_number ContributionIndex;
+
+/* Special \c ContributionIndex used to indicate null result when looking for a
+ contribution. */
+extern ContributionIndex const ContributionIndex__none;
+
+/* Special \c ContributionIndex used by
+ \c AnnotationList__computeDominantContribution to signal when the action
+ chosen in a conflict is a syntax error because of a %nonassoc. */
+extern ContributionIndex const ContributionIndex__error_action;
+
+/**
+ * The description of a conflict. Don't break encapsulation by modifying the
+ * fields directly. Use the provided interface functions for
+ * \c InadequacyList.
+ */
+typedef struct {
+ /** The \c token passed to \c InadequacyList__new_conflict. */
+ symbol *token;
+ /** The \c actions passed to \c InadequacyList__new_conflict. */
+ bitset actions;
+} Conflict;
+
+/**
+ * A node in a list that describes all the inadequacies that manifest in a
+ * particular state. Don't break encapsulation by modifying the fields
+ * directly. Use the provided interface functions.
+ */
+typedef struct InadequacyList {
+ struct InadequacyList *next;
+ InadequacyListNodeCount id;
+ state *manifestingState;
+ ContributionIndex contributionCount;
+ union {
+ Conflict conflict;
+ } inadequacy;
+} InadequacyList;
+
+/**
+ * \pre
+ * - <tt>manifesting_state != NULL</tt>.
+ * - \c token is a token.
+ * - The size of \c actions is
+ * <tt>manifesting_state->reductions->num + 1</tt>.
+ * - If the set of all \c InadequacyList nodes with which the new
+ * \c InadequacyList node might be compared is currently empty, then
+ * it is best if <tt>*node_count</tt> is zero so that the node count
+ * does not eventually overflow. However, if that set is not
+ * currently empty, then <tt>*node_count</tt> has not been modified
+ * by any function except \c InadequacyList__new_conflict since the
+ * invocation of \c InadequacyList__new_conflict that constructed
+ * the first existing member of that set.
+ * \post
+ * - \c result is a new \c InadequacyList with one node indicating that, in
+ * \c manifesting_state, the following actions are in conflict on \c token:
+ * - Shift iff
+ * <tt>bitset_test (actions, manifesting_state->reductions->num)</tt>.
+ * - For any \c i such that
+ * <tt>0 <= i < manifesting_state->reductions->num</tt>, the reduction
+ * for the rule <tt>manifesting_state->reductions->rules[i]</tt> iff
+ * <tt>actions[i]</tt> is set.
+ * - Given any node \c n from the set of all existing
+ * \c InadequacyList nodes with which \c result might be compared
+ * such that <tt>n != result</tt>, then <tt>n->id < result->id</tt>.
+ * - \c result assumes responsibility for the memory of \c actions.
+ */
+InadequacyList *InadequacyList__new_conflict (
+ state *manifesting_state, symbol *token, bitset actions,
+ InadequacyListNodeCount *node_count);
+
+/**
+ * \post
+ * - All memory associated with all nodes in the list \c self was freed.
+ */
+void InadequacyList__delete (InadequacyList *self);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * \post
+ * - \c result = either:
+ * - \c ContributionIndex__none iff there is no shift contribution in
+ * \c self (perhaps because \c self isn't a conflict).
+ * - The index of the shift contribution, otherwise.
+ */
+ContributionIndex
+InadequacyList__getShiftContributionIndex (InadequacyList const *self);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>0 <= i < self->contributionCount</tt>.
+ * \post
+ * - \c result = the token associated with contribution \c i in the
+ * inadequacy described by the node \c self.
+ */
+symbol *InadequacyList__getContributionToken (InadequacyList const *self,
+ ContributionIndex i);
+
+/**
+ * \pre
+ * - \c self is a single node.
+ * - <tt>list != NULL</tt>.
+ * \post
+ * - \c list now contains \c self as its first node.
+ * - \c list assumes responsibility for the memory of \c self.
+ */
+void InadequacyList__prependTo (InadequacyList *self, InadequacyList **list);
+
+#endif /* !INADEQUACY_LIST_H_ */
diff --git a/contrib/tools/bison/bison/src/LR0.c b/contrib/tools/bison/bison/src/LR0.c
index f6a9537e4c..9aacabaf03 100644
--- a/contrib/tools/bison/bison/src/LR0.c
+++ b/contrib/tools/bison/bison/src/LR0.c
@@ -1,375 +1,375 @@
-/* Generate the LR(0) parser states for Bison.
-
- Copyright (C) 1984, 1986, 1989, 2000-2002, 2004-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/* See comments in state.h for the data structures that represent it.
- The entry point is generate_states. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitset.h>
-
-#include "LR0.h"
-#include "closure.h"
-#include "complain.h"
-#include "getargs.h"
-#include "gram.h"
-#include "lalr.h"
-#include "reader.h"
-#include "reduce.h"
-#include "state.h"
-#include "symtab.h"
-
-typedef struct state_list
-{
- struct state_list *next;
- state *state;
-} state_list;
-
-static state_list *first_state = NULL;
-static state_list *last_state = NULL;
-
-
-/*------------------------------------------------------------------.
-| A state was just discovered from another state. Queue it for |
-| later examination, in order to find its transitions. Return it. |
-`------------------------------------------------------------------*/
-
-static state *
-state_list_append (symbol_number sym, size_t core_size, item_number *core)
-{
- state_list *node = xmalloc (sizeof *node);
- state *s = state_new (sym, core_size, core);
-
- if (trace_flag & trace_automaton)
- fprintf (stderr, "state_list_append (state = %d, symbol = %d (%s))\n",
- nstates, sym, symbols[sym]->tag);
-
- node->next = NULL;
- node->state = s;
-
- if (!first_state)
- first_state = node;
- if (last_state)
- last_state->next = node;
- last_state = node;
-
- return s;
-}
-
-static int nshifts;
-static symbol_number *shift_symbol;
-
-static rule **redset;
-static state **shiftset;
-
-static item_number **kernel_base;
-static int *kernel_size;
-static item_number *kernel_items;
-
-
-static void
-allocate_itemsets (void)
-{
- symbol_number i;
- rule_number r;
- item_number *rhsp;
-
- /* Count the number of occurrences of all the symbols in RITEMS.
- Note that useless productions (hence useless nonterminals) are
- browsed too, hence we need to allocate room for _all_ the
- symbols. */
- size_t count = 0;
- size_t *symbol_count = xcalloc (nsyms + nuseless_nonterminals,
- sizeof *symbol_count);
-
- for (r = 0; r < nrules; ++r)
- for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
- {
- count++;
- symbol_count[*rhsp]++;
- }
-
- /* See comments before new_itemsets. All the vectors of items
- live inside KERNEL_ITEMS. The number of active items after
- some symbol S cannot be more than the number of times that S
- appears as an item, which is SYMBOL_COUNT[S].
- We allocate that much space for each symbol. */
-
- kernel_base = xnmalloc (nsyms, sizeof *kernel_base);
- kernel_items = xnmalloc (count, sizeof *kernel_items);
-
- count = 0;
- for (i = 0; i < nsyms; i++)
- {
- kernel_base[i] = kernel_items + count;
- count += symbol_count[i];
- }
-
- free (symbol_count);
- kernel_size = xnmalloc (nsyms, sizeof *kernel_size);
-}
-
-
-static void
-allocate_storage (void)
-{
- allocate_itemsets ();
-
- shiftset = xnmalloc (nsyms, sizeof *shiftset);
- redset = xnmalloc (nrules, sizeof *redset);
- state_hash_new ();
- shift_symbol = xnmalloc (nsyms, sizeof *shift_symbol);
-}
-
-
-static void
-free_storage (void)
-{
- free (shift_symbol);
- free (redset);
- free (shiftset);
- free (kernel_base);
- free (kernel_size);
- free (kernel_items);
- state_hash_free ();
-}
-
-
-
-
-/*---------------------------------------------------------------.
-| Find which symbols can be shifted in S, and for each one |
-| record which items would be active after that shift. Uses the |
-| contents of itemset. |
-| |
-| shift_symbol is set to a vector of the symbols that can be |
-| shifted. For each symbol in the grammar, kernel_base[symbol] |
-| points to a vector of item numbers activated if that symbol is |
-| shifted, and kernel_size[symbol] is their numbers. |
-| |
-| itemset is sorted on item index in ritem, which is sorted on |
-| rule number. Compute each kernel_base[symbol] with the same |
-| sort. |
-`---------------------------------------------------------------*/
-
-static void
-new_itemsets (state *s)
-{
- size_t i;
-
- if (trace_flag & trace_automaton)
- fprintf (stderr, "Entering new_itemsets, state = %d\n", s->number);
-
- memset (kernel_size, 0, nsyms * sizeof *kernel_size);
-
- nshifts = 0;
-
- for (i = 0; i < nitemset; ++i)
- if (item_number_is_symbol_number (ritem[itemset[i]]))
- {
- symbol_number sym = item_number_as_symbol_number (ritem[itemset[i]]);
- if (!kernel_size[sym])
- {
- shift_symbol[nshifts] = sym;
- nshifts++;
- }
-
- kernel_base[sym][kernel_size[sym]] = itemset[i] + 1;
- kernel_size[sym]++;
- }
-}
-
-
-
-/*--------------------------------------------------------------.
-| Find the state we would get to (from the current state) by |
-| shifting SYM. Create a new state if no equivalent one exists |
-| already. Used by append_states. |
-`--------------------------------------------------------------*/
-
-static state *
-get_state (symbol_number sym, size_t core_size, item_number *core)
-{
- state *s;
-
- if (trace_flag & trace_automaton)
- fprintf (stderr, "Entering get_state, symbol = %d (%s)\n",
- sym, symbols[sym]->tag);
-
- s = state_hash_lookup (core_size, core);
- if (!s)
- s = state_list_append (sym, core_size, core);
-
- if (trace_flag & trace_automaton)
- fprintf (stderr, "Exiting get_state => %d\n", s->number);
-
- return s;
-}
-
-/*---------------------------------------------------------------.
-| Use the information computed by new_itemsets to find the state |
-| numbers reached by each shift transition from S. |
-| |
-| SHIFTSET is set up as a vector of those states. |
-`---------------------------------------------------------------*/
-
-static void
-append_states (state *s)
-{
- int i;
-
- if (trace_flag & trace_automaton)
- fprintf (stderr, "Entering append_states, state = %d\n", s->number);
-
- /* First sort shift_symbol into increasing order. */
-
- for (i = 1; i < nshifts; i++)
- {
- symbol_number sym = shift_symbol[i];
- int j;
- for (j = i; 0 < j && sym < shift_symbol[j - 1]; j--)
- shift_symbol[j] = shift_symbol[j - 1];
- shift_symbol[j] = sym;
- }
-
- for (i = 0; i < nshifts; i++)
- {
- symbol_number sym = shift_symbol[i];
- shiftset[i] = get_state (sym, kernel_size[sym], kernel_base[sym]);
- }
-}
-
-
-/*----------------------------------------------------------------.
-| Find which rules can be used for reduction transitions from the |
-| current state and make a reductions structure for the state to |
-| record their rule numbers. |
-`----------------------------------------------------------------*/
-
-static void
-save_reductions (state *s)
-{
- int count = 0;
- size_t i;
-
- /* Find and count the active items that represent ends of rules. */
- for (i = 0; i < nitemset; ++i)
- {
- item_number item = ritem[itemset[i]];
- if (item_number_is_rule_number (item))
- {
- rule_number r = item_number_as_rule_number (item);
- redset[count++] = &rules[r];
- if (r == 0)
- {
- /* This is "reduce 0", i.e., accept. */
- aver (!final_state);
- final_state = s;
- }
- }
- }
-
- /* Make a reductions structure and copy the data into it. */
- state_reductions_set (s, count, redset);
-}
-
-
-/*---------------.
-| Build STATES. |
-`---------------*/
-
-static void
-set_states (void)
-{
- states = xcalloc (nstates, sizeof *states);
-
- while (first_state)
- {
- state_list *this = first_state;
-
- /* Pessimization, but simplification of the code: make sure all
- the states have valid transitions and reductions members,
- even if reduced to 0. It is too soon for errs, which are
- computed later, but set_conflicts. */
- state *s = this->state;
- if (!s->transitions)
- state_transitions_set (s, 0, 0);
- if (!s->reductions)
- state_reductions_set (s, 0, 0);
-
- states[s->number] = s;
-
- first_state = this->next;
- free (this);
- }
- first_state = NULL;
- last_state = NULL;
-}
-
-
-/*-------------------------------------------------------------------.
-| Compute the LR(0) parser states (see state.h for details) from the |
-| grammar. |
-`-------------------------------------------------------------------*/
-
-void
-generate_states (void)
-{
- item_number initial_core = 0;
- state_list *list = NULL;
- allocate_storage ();
- new_closure (nritems);
-
- /* Create the initial state. The 0 at the lhs is the index of the
- item of this initial rule. */
- state_list_append (0, 1, &initial_core);
-
- /* States are queued when they are created; process them all. */
- for (list = first_state; list; list = list->next)
- {
- state *s = list->state;
- if (trace_flag & trace_automaton)
- fprintf (stderr, "Processing state %d (reached by %s)\n",
- s->number,
- symbols[s->accessing_symbol]->tag);
- /* Set up itemset for the transitions out of this state. itemset gets a
- vector of all the items that could be accepted next. */
- closure (s->items, s->nitems);
- /* Record the reductions allowed out of this state. */
- save_reductions (s);
- /* Find the itemsets of the states that shifts can reach. */
- new_itemsets (s);
- /* Find or create the core structures for those states. */
- append_states (s);
-
- /* Create the shifts structures for the shifts to those states,
- now that the state numbers transitioning to are known. */
- state_transitions_set (s, nshifts, shiftset);
- }
-
- /* discard various storage */
- free_closure ();
- free_storage ();
-
- /* Set up STATES. */
- set_states ();
-}
+/* Generate the LR(0) parser states for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 2000-2002, 2004-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+/* See comments in state.h for the data structures that represent it.
+ The entry point is generate_states. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitset.h>
+
+#include "LR0.h"
+#include "closure.h"
+#include "complain.h"
+#include "getargs.h"
+#include "gram.h"
+#include "lalr.h"
+#include "reader.h"
+#include "reduce.h"
+#include "state.h"
+#include "symtab.h"
+
+typedef struct state_list
+{
+ struct state_list *next;
+ state *state;
+} state_list;
+
+static state_list *first_state = NULL;
+static state_list *last_state = NULL;
+
+
+/*------------------------------------------------------------------.
+| A state was just discovered from another state. Queue it for |
+| later examination, in order to find its transitions. Return it. |
+`------------------------------------------------------------------*/
+
+static state *
+state_list_append (symbol_number sym, size_t core_size, item_number *core)
+{
+ state_list *node = xmalloc (sizeof *node);
+ state *s = state_new (sym, core_size, core);
+
+ if (trace_flag & trace_automaton)
+ fprintf (stderr, "state_list_append (state = %d, symbol = %d (%s))\n",
+ nstates, sym, symbols[sym]->tag);
+
+ node->next = NULL;
+ node->state = s;
+
+ if (!first_state)
+ first_state = node;
+ if (last_state)
+ last_state->next = node;
+ last_state = node;
+
+ return s;
+}
+
+static int nshifts;
+static symbol_number *shift_symbol;
+
+static rule **redset;
+static state **shiftset;
+
+static item_number **kernel_base;
+static int *kernel_size;
+static item_number *kernel_items;
+
+
+static void
+allocate_itemsets (void)
+{
+ symbol_number i;
+ rule_number r;
+ item_number *rhsp;
+
+ /* Count the number of occurrences of all the symbols in RITEMS.
+ Note that useless productions (hence useless nonterminals) are
+ browsed too, hence we need to allocate room for _all_ the
+ symbols. */
+ size_t count = 0;
+ size_t *symbol_count = xcalloc (nsyms + nuseless_nonterminals,
+ sizeof *symbol_count);
+
+ for (r = 0; r < nrules; ++r)
+ for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
+ {
+ count++;
+ symbol_count[*rhsp]++;
+ }
+
+ /* See comments before new_itemsets. All the vectors of items
+ live inside KERNEL_ITEMS. The number of active items after
+ some symbol S cannot be more than the number of times that S
+ appears as an item, which is SYMBOL_COUNT[S].
+ We allocate that much space for each symbol. */
+
+ kernel_base = xnmalloc (nsyms, sizeof *kernel_base);
+ kernel_items = xnmalloc (count, sizeof *kernel_items);
+
+ count = 0;
+ for (i = 0; i < nsyms; i++)
+ {
+ kernel_base[i] = kernel_items + count;
+ count += symbol_count[i];
+ }
+
+ free (symbol_count);
+ kernel_size = xnmalloc (nsyms, sizeof *kernel_size);
+}
+
+
+static void
+allocate_storage (void)
+{
+ allocate_itemsets ();
+
+ shiftset = xnmalloc (nsyms, sizeof *shiftset);
+ redset = xnmalloc (nrules, sizeof *redset);
+ state_hash_new ();
+ shift_symbol = xnmalloc (nsyms, sizeof *shift_symbol);
+}
+
+
+static void
+free_storage (void)
+{
+ free (shift_symbol);
+ free (redset);
+ free (shiftset);
+ free (kernel_base);
+ free (kernel_size);
+ free (kernel_items);
+ state_hash_free ();
+}
+
+
+
+
+/*---------------------------------------------------------------.
+| Find which symbols can be shifted in S, and for each one |
+| record which items would be active after that shift. Uses the |
+| contents of itemset. |
+| |
+| shift_symbol is set to a vector of the symbols that can be |
+| shifted. For each symbol in the grammar, kernel_base[symbol] |
+| points to a vector of item numbers activated if that symbol is |
+| shifted, and kernel_size[symbol] is their numbers. |
+| |
+| itemset is sorted on item index in ritem, which is sorted on |
+| rule number. Compute each kernel_base[symbol] with the same |
+| sort. |
+`---------------------------------------------------------------*/
+
+static void
+new_itemsets (state *s)
+{
+ size_t i;
+
+ if (trace_flag & trace_automaton)
+ fprintf (stderr, "Entering new_itemsets, state = %d\n", s->number);
+
+ memset (kernel_size, 0, nsyms * sizeof *kernel_size);
+
+ nshifts = 0;
+
+ for (i = 0; i < nitemset; ++i)
+ if (item_number_is_symbol_number (ritem[itemset[i]]))
+ {
+ symbol_number sym = item_number_as_symbol_number (ritem[itemset[i]]);
+ if (!kernel_size[sym])
+ {
+ shift_symbol[nshifts] = sym;
+ nshifts++;
+ }
+
+ kernel_base[sym][kernel_size[sym]] = itemset[i] + 1;
+ kernel_size[sym]++;
+ }
+}
+
+
+
+/*--------------------------------------------------------------.
+| Find the state we would get to (from the current state) by |
+| shifting SYM. Create a new state if no equivalent one exists |
+| already. Used by append_states. |
+`--------------------------------------------------------------*/
+
+static state *
+get_state (symbol_number sym, size_t core_size, item_number *core)
+{
+ state *s;
+
+ if (trace_flag & trace_automaton)
+ fprintf (stderr, "Entering get_state, symbol = %d (%s)\n",
+ sym, symbols[sym]->tag);
+
+ s = state_hash_lookup (core_size, core);
+ if (!s)
+ s = state_list_append (sym, core_size, core);
+
+ if (trace_flag & trace_automaton)
+ fprintf (stderr, "Exiting get_state => %d\n", s->number);
+
+ return s;
+}
+
+/*---------------------------------------------------------------.
+| Use the information computed by new_itemsets to find the state |
+| numbers reached by each shift transition from S. |
+| |
+| SHIFTSET is set up as a vector of those states. |
+`---------------------------------------------------------------*/
+
+static void
+append_states (state *s)
+{
+ int i;
+
+ if (trace_flag & trace_automaton)
+ fprintf (stderr, "Entering append_states, state = %d\n", s->number);
+
+ /* First sort shift_symbol into increasing order. */
+
+ for (i = 1; i < nshifts; i++)
+ {
+ symbol_number sym = shift_symbol[i];
+ int j;
+ for (j = i; 0 < j && sym < shift_symbol[j - 1]; j--)
+ shift_symbol[j] = shift_symbol[j - 1];
+ shift_symbol[j] = sym;
+ }
+
+ for (i = 0; i < nshifts; i++)
+ {
+ symbol_number sym = shift_symbol[i];
+ shiftset[i] = get_state (sym, kernel_size[sym], kernel_base[sym]);
+ }
+}
+
+
+/*----------------------------------------------------------------.
+| Find which rules can be used for reduction transitions from the |
+| current state and make a reductions structure for the state to |
+| record their rule numbers. |
+`----------------------------------------------------------------*/
+
+static void
+save_reductions (state *s)
+{
+ int count = 0;
+ size_t i;
+
+ /* Find and count the active items that represent ends of rules. */
+ for (i = 0; i < nitemset; ++i)
+ {
+ item_number item = ritem[itemset[i]];
+ if (item_number_is_rule_number (item))
+ {
+ rule_number r = item_number_as_rule_number (item);
+ redset[count++] = &rules[r];
+ if (r == 0)
+ {
+ /* This is "reduce 0", i.e., accept. */
+ aver (!final_state);
+ final_state = s;
+ }
+ }
+ }
+
+ /* Make a reductions structure and copy the data into it. */
+ state_reductions_set (s, count, redset);
+}
+
+
+/*---------------.
+| Build STATES. |
+`---------------*/
+
+static void
+set_states (void)
+{
+ states = xcalloc (nstates, sizeof *states);
+
+ while (first_state)
+ {
+ state_list *this = first_state;
+
+ /* Pessimization, but simplification of the code: make sure all
+ the states have valid transitions and reductions members,
+ even if reduced to 0. It is too soon for errs, which are
+ computed later, but set_conflicts. */
+ state *s = this->state;
+ if (!s->transitions)
+ state_transitions_set (s, 0, 0);
+ if (!s->reductions)
+ state_reductions_set (s, 0, 0);
+
+ states[s->number] = s;
+
+ first_state = this->next;
+ free (this);
+ }
+ first_state = NULL;
+ last_state = NULL;
+}
+
+
+/*-------------------------------------------------------------------.
+| Compute the LR(0) parser states (see state.h for details) from the |
+| grammar. |
+`-------------------------------------------------------------------*/
+
+void
+generate_states (void)
+{
+ item_number initial_core = 0;
+ state_list *list = NULL;
+ allocate_storage ();
+ new_closure (nritems);
+
+ /* Create the initial state. The 0 at the lhs is the index of the
+ item of this initial rule. */
+ state_list_append (0, 1, &initial_core);
+
+ /* States are queued when they are created; process them all. */
+ for (list = first_state; list; list = list->next)
+ {
+ state *s = list->state;
+ if (trace_flag & trace_automaton)
+ fprintf (stderr, "Processing state %d (reached by %s)\n",
+ s->number,
+ symbols[s->accessing_symbol]->tag);
+ /* Set up itemset for the transitions out of this state. itemset gets a
+ vector of all the items that could be accepted next. */
+ closure (s->items, s->nitems);
+ /* Record the reductions allowed out of this state. */
+ save_reductions (s);
+ /* Find the itemsets of the states that shifts can reach. */
+ new_itemsets (s);
+ /* Find or create the core structures for those states. */
+ append_states (s);
+
+ /* Create the shifts structures for the shifts to those states,
+ now that the state numbers transitioning to are known. */
+ state_transitions_set (s, nshifts, shiftset);
+ }
+
+ /* discard various storage */
+ free_closure ();
+ free_storage ();
+
+ /* Set up STATES. */
+ set_states ();
+}
diff --git a/contrib/tools/bison/bison/src/LR0.h b/contrib/tools/bison/bison/src/LR0.h
index 976bcb26ee..acd65b8e27 100644
--- a/contrib/tools/bison/bison/src/LR0.h
+++ b/contrib/tools/bison/bison/src/LR0.h
@@ -1,28 +1,28 @@
-/* Generate the LR(0) parser states for Bison.
-
- Copyright (C) 1984, 1986, 1989, 2000-2002, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef LR0_H_
-# define LR0_H_
-
-# include "state.h"
-
-void generate_states (void);
-
-#endif /* !LR0_H_ */
+/* Generate the LR(0) parser states for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 2000-2002, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LR0_H_
+# define LR0_H_
+
+# include "state.h"
+
+void generate_states (void);
+
+#endif /* !LR0_H_ */
diff --git a/contrib/tools/bison/bison/src/Sbitset.c b/contrib/tools/bison/bison/src/Sbitset.c
index bb278b55db..fc88d6cc80 100644
--- a/contrib/tools/bison/bison/src/Sbitset.c
+++ b/contrib/tools/bison/bison/src/Sbitset.c
@@ -1,80 +1,80 @@
-/* A simple, memory-efficient bitset implementation.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "Sbitset.h"
-
-Sbitset
-Sbitset__new (Sbitset__Index nbits)
-{
- /* Some functions, like Sbitset__last_byte_mask, will fail if nbits = 0. */
- aver (nbits);
- return xcalloc (1, Sbitset__nbytes (nbits));
-}
-
-Sbitset
-Sbitset__new_on_obstack (Sbitset__Index nbits, struct obstack *obstackp)
-{
- Sbitset result;
- Sbitset ptr;
- Sbitset end;
- aver (nbits);
- result = obstack_alloc (obstackp, Sbitset__nbytes (nbits));
- for (ptr = result, end = result + Sbitset__nbytes (nbits); ptr < end; ++ptr)
- *ptr = 0;
- return result;
-}
-
-void
-Sbitset__delete (Sbitset self)
-{
- free (self);
-}
-
-bool
-Sbitset__isEmpty (Sbitset self, Sbitset__Index nbits)
-{
- Sbitset last = self + Sbitset__nbytes (nbits) - 1;
- for (; self < last; ++self)
- if (*self != 0)
- return false;
- return ((*last) & Sbitset__last_byte_mask (nbits)) == 0;
-}
-
-void
-Sbitset__fprint (Sbitset self, Sbitset__Index nbits, FILE *file)
-{
- Sbitset__Index i;
- Sbitset itr;
- bool first = true;
- fprintf (file,
- "nbits = %" SBITSET__INDEX__CONVERSION_SPEC ", set = {",
- nbits);
- SBITSET__FOR_EACH (self, nbits, itr, i)
- {
- if (first)
- first = false;
- else
- fprintf (file, ",");
- fprintf (file, " %" SBITSET__INDEX__CONVERSION_SPEC, i);
- }
- fprintf (file, " }");
-}
+/* A simple, memory-efficient bitset implementation.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "Sbitset.h"
+
+Sbitset
+Sbitset__new (Sbitset__Index nbits)
+{
+ /* Some functions, like Sbitset__last_byte_mask, will fail if nbits = 0. */
+ aver (nbits);
+ return xcalloc (1, Sbitset__nbytes (nbits));
+}
+
+Sbitset
+Sbitset__new_on_obstack (Sbitset__Index nbits, struct obstack *obstackp)
+{
+ Sbitset result;
+ Sbitset ptr;
+ Sbitset end;
+ aver (nbits);
+ result = obstack_alloc (obstackp, Sbitset__nbytes (nbits));
+ for (ptr = result, end = result + Sbitset__nbytes (nbits); ptr < end; ++ptr)
+ *ptr = 0;
+ return result;
+}
+
+void
+Sbitset__delete (Sbitset self)
+{
+ free (self);
+}
+
+bool
+Sbitset__isEmpty (Sbitset self, Sbitset__Index nbits)
+{
+ Sbitset last = self + Sbitset__nbytes (nbits) - 1;
+ for (; self < last; ++self)
+ if (*self != 0)
+ return false;
+ return ((*last) & Sbitset__last_byte_mask (nbits)) == 0;
+}
+
+void
+Sbitset__fprint (Sbitset self, Sbitset__Index nbits, FILE *file)
+{
+ Sbitset__Index i;
+ Sbitset itr;
+ bool first = true;
+ fprintf (file,
+ "nbits = %" SBITSET__INDEX__CONVERSION_SPEC ", set = {",
+ nbits);
+ SBITSET__FOR_EACH (self, nbits, itr, i)
+ {
+ if (first)
+ first = false;
+ else
+ fprintf (file, ",");
+ fprintf (file, " %" SBITSET__INDEX__CONVERSION_SPEC, i);
+ }
+ fprintf (file, " }");
+}
diff --git a/contrib/tools/bison/bison/src/Sbitset.h b/contrib/tools/bison/bison/src/Sbitset.h
index bcb329ad39..98297c3921 100644
--- a/contrib/tools/bison/bison/src/Sbitset.h
+++ b/contrib/tools/bison/bison/src/Sbitset.h
@@ -1,92 +1,92 @@
-/* A simple, memory-efficient bitset implementation.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SBITSET_H_
-# define SBITSET_H_
-
-typedef unsigned char *Sbitset;
-typedef size_t Sbitset__Index;
-# define SBITSET__INDEX__CONVERSION_SPEC "zu"
-
-# define Sbitset__nbytes(NBITS) \
- (((NBITS) + CHAR_BIT - 1) / CHAR_BIT)
-# define Sbitset__byteAddress(SELF, INDEX) \
- (((SELF) + (INDEX) / CHAR_BIT))
-# define Sbitset__bit_mask(INDEX) \
- (1 << (CHAR_BIT - 1 - (INDEX) % CHAR_BIT))
-# define Sbitset__last_byte_mask(NBITS) \
- (UCHAR_MAX << (CHAR_BIT - 1 - ((NBITS) - 1) % CHAR_BIT))
-
-/* nbits must not be 0. */
-Sbitset Sbitset__new (Sbitset__Index nbits);
-Sbitset Sbitset__new_on_obstack (Sbitset__Index nbits,
- struct obstack *obstackp);
-void Sbitset__delete (Sbitset self);
-
-# define Sbitset__test(SELF, INDEX) \
- ((*Sbitset__byteAddress ((SELF), (INDEX)) & Sbitset__bit_mask (INDEX)) != 0)
-
-bool Sbitset__isEmpty (Sbitset self, Sbitset__Index nbits);
-
-void Sbitset__fprint (Sbitset self, Sbitset__Index nbits, FILE *file);
-
-# define Sbitset__set(SELF, INDEX) \
- do { \
- *Sbitset__byteAddress ((SELF), (INDEX)) = \
- *Sbitset__byteAddress ((SELF), (INDEX)) | Sbitset__bit_mask (INDEX); \
- } while (0)
-
-# define Sbitset__reset(SELF, INDEX) \
- do { \
- *Sbitset__byteAddress ((SELF), (INDEX)) = \
- *Sbitset__byteAddress ((SELF), (INDEX)) & ~Sbitset__bit_mask (INDEX); \
- } while (0)
-
-/* NBITS is the size of the bitset. More than NBITS bits might be reset. */
-# define Sbitset__zero(SELF, NBITS) \
- do { \
- memset (SELF, 0, Sbitset__nbytes (NBITS)); \
- } while (0)
-
-/* NBITS is the size of the bitset. More than NBITS bits might be set. */
-# define Sbitset__ones(SELF, NBITS) \
- do { \
- memset (SELF, UCHAR_MAX, Sbitset__nbytes (NBITS)); \
- } while (0)
-
-/* NBITS is the size of every bitset. More than NBITS bits might be set. */
-# define Sbitset__or(SELF, OTHER1, OTHER2, NBITS) \
- do { \
- Sbitset ptr_self = (SELF); \
- Sbitset ptr_other1 = (OTHER1); \
- Sbitset ptr_other2 = (OTHER2); \
- Sbitset end_self = ptr_self + Sbitset__nbytes (NBITS); \
- for (; ptr_self < end_self; ++ptr_self, ++ptr_other1, ++ptr_other2) \
- *ptr_self = *ptr_other1 | *ptr_other2; \
- } while (0)
-
-# define SBITSET__FOR_EACH(SELF, NBITS, ITER, INDEX) \
- for ((ITER) = (SELF); (ITER) < (SELF) + Sbitset__nbytes (NBITS); ++(ITER)) \
- if (*(ITER) != 0) \
- for ((INDEX) = ((ITER)-(SELF))*CHAR_BIT; \
- (INDEX) < (NBITS) && (SELF)+(INDEX)/CHAR_BIT < (ITER)+1; \
- ++(INDEX)) \
- if (((*ITER) & Sbitset__bit_mask (INDEX)) != 0)
-
-#endif /* !SBITSET_H_ */
+/* A simple, memory-efficient bitset implementation.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SBITSET_H_
+# define SBITSET_H_
+
+typedef unsigned char *Sbitset;
+typedef size_t Sbitset__Index;
+# define SBITSET__INDEX__CONVERSION_SPEC "zu"
+
+# define Sbitset__nbytes(NBITS) \
+ (((NBITS) + CHAR_BIT - 1) / CHAR_BIT)
+# define Sbitset__byteAddress(SELF, INDEX) \
+ (((SELF) + (INDEX) / CHAR_BIT))
+# define Sbitset__bit_mask(INDEX) \
+ (1 << (CHAR_BIT - 1 - (INDEX) % CHAR_BIT))
+# define Sbitset__last_byte_mask(NBITS) \
+ (UCHAR_MAX << (CHAR_BIT - 1 - ((NBITS) - 1) % CHAR_BIT))
+
+/* nbits must not be 0. */
+Sbitset Sbitset__new (Sbitset__Index nbits);
+Sbitset Sbitset__new_on_obstack (Sbitset__Index nbits,
+ struct obstack *obstackp);
+void Sbitset__delete (Sbitset self);
+
+# define Sbitset__test(SELF, INDEX) \
+ ((*Sbitset__byteAddress ((SELF), (INDEX)) & Sbitset__bit_mask (INDEX)) != 0)
+
+bool Sbitset__isEmpty (Sbitset self, Sbitset__Index nbits);
+
+void Sbitset__fprint (Sbitset self, Sbitset__Index nbits, FILE *file);
+
+# define Sbitset__set(SELF, INDEX) \
+ do { \
+ *Sbitset__byteAddress ((SELF), (INDEX)) = \
+ *Sbitset__byteAddress ((SELF), (INDEX)) | Sbitset__bit_mask (INDEX); \
+ } while (0)
+
+# define Sbitset__reset(SELF, INDEX) \
+ do { \
+ *Sbitset__byteAddress ((SELF), (INDEX)) = \
+ *Sbitset__byteAddress ((SELF), (INDEX)) & ~Sbitset__bit_mask (INDEX); \
+ } while (0)
+
+/* NBITS is the size of the bitset. More than NBITS bits might be reset. */
+# define Sbitset__zero(SELF, NBITS) \
+ do { \
+ memset (SELF, 0, Sbitset__nbytes (NBITS)); \
+ } while (0)
+
+/* NBITS is the size of the bitset. More than NBITS bits might be set. */
+# define Sbitset__ones(SELF, NBITS) \
+ do { \
+ memset (SELF, UCHAR_MAX, Sbitset__nbytes (NBITS)); \
+ } while (0)
+
+/* NBITS is the size of every bitset. More than NBITS bits might be set. */
+# define Sbitset__or(SELF, OTHER1, OTHER2, NBITS) \
+ do { \
+ Sbitset ptr_self = (SELF); \
+ Sbitset ptr_other1 = (OTHER1); \
+ Sbitset ptr_other2 = (OTHER2); \
+ Sbitset end_self = ptr_self + Sbitset__nbytes (NBITS); \
+ for (; ptr_self < end_self; ++ptr_self, ++ptr_other1, ++ptr_other2) \
+ *ptr_self = *ptr_other1 | *ptr_other2; \
+ } while (0)
+
+# define SBITSET__FOR_EACH(SELF, NBITS, ITER, INDEX) \
+ for ((ITER) = (SELF); (ITER) < (SELF) + Sbitset__nbytes (NBITS); ++(ITER)) \
+ if (*(ITER) != 0) \
+ for ((INDEX) = ((ITER)-(SELF))*CHAR_BIT; \
+ (INDEX) < (NBITS) && (SELF)+(INDEX)/CHAR_BIT < (ITER)+1; \
+ ++(INDEX)) \
+ if (((*ITER) & Sbitset__bit_mask (INDEX)) != 0)
+
+#endif /* !SBITSET_H_ */
diff --git a/contrib/tools/bison/bison/src/assoc.c b/contrib/tools/bison/bison/src/assoc.c
index d2eec31574..f80b8e9ddb 100644
--- a/contrib/tools/bison/bison/src/assoc.c
+++ b/contrib/tools/bison/bison/src/assoc.c
@@ -1,50 +1,50 @@
-/* Associativity information.
-
- Copyright (C) 2002, 2005-2006, 2008-2013 Free Software Foundation,
- Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "assoc.h"
-
-
-const char *
-assoc_to_string (assoc a)
-{
- switch (a)
- {
- default:
- abort ();
-
- case undef_assoc:
- return "undefined associativity";
-
- case right_assoc:
- return "%right";
-
- case left_assoc:
- return "%left";
-
- case non_assoc:
- return "%nonassoc";
-
- case precedence_assoc:
- return "%precedence";
- }
-}
+/* Associativity information.
+
+ Copyright (C) 2002, 2005-2006, 2008-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "assoc.h"
+
+
+const char *
+assoc_to_string (assoc a)
+{
+ switch (a)
+ {
+ default:
+ abort ();
+
+ case undef_assoc:
+ return "undefined associativity";
+
+ case right_assoc:
+ return "%right";
+
+ case left_assoc:
+ return "%left";
+
+ case non_assoc:
+ return "%nonassoc";
+
+ case precedence_assoc:
+ return "%precedence";
+ }
+}
diff --git a/contrib/tools/bison/bison/src/assoc.h b/contrib/tools/bison/bison/src/assoc.h
index b9475b5d12..3e2dcf76ea 100644
--- a/contrib/tools/bison/bison/src/assoc.h
+++ b/contrib/tools/bison/bison/src/assoc.h
@@ -1,35 +1,35 @@
-/* Associativity information.
-
- Copyright (C) 2002, 2006, 2008-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef ASSOC_H_
-# define ASSOC_H_
-
-/* Associativity values for tokens and rules. */
-typedef enum
-{
- undef_assoc, /** Not defined. */
- right_assoc, /** %right */
- left_assoc, /** %left */
- non_assoc, /** %nonassoc */
- precedence_assoc /** %precedence */
-} assoc;
-
-char const *assoc_to_string (assoc a);
-
-#endif /* !ASSOC_H_ */
+/* Associativity information.
+
+ Copyright (C) 2002, 2006, 2008-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef ASSOC_H_
+# define ASSOC_H_
+
+/* Associativity values for tokens and rules. */
+typedef enum
+{
+ undef_assoc, /** Not defined. */
+ right_assoc, /** %right */
+ left_assoc, /** %left */
+ non_assoc, /** %nonassoc */
+ precedence_assoc /** %precedence */
+} assoc;
+
+char const *assoc_to_string (assoc a);
+
+#endif /* !ASSOC_H_ */
diff --git a/contrib/tools/bison/bison/src/closure.c b/contrib/tools/bison/bison/src/closure.c
index 45e8311022..d372bdac47 100644
--- a/contrib/tools/bison/bison/src/closure.c
+++ b/contrib/tools/bison/bison/src/closure.c
@@ -1,246 +1,246 @@
-/* Closures for Bison
-
- Copyright (C) 1984, 1989, 2000-2002, 2004-2005, 2007, 2009-2013 Free
- Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitset.h>
-#include <bitsetv-print.h>
-#include <bitsetv.h>
-
-#include "closure.h"
-#include "derives.h"
-#include "getargs.h"
-#include "gram.h"
-#include "reader.h"
-#include "symtab.h"
-
-/* NITEMSET is the size of the array ITEMSET. */
-item_number *itemset;
-size_t nitemset;
-
-static bitset ruleset;
-
-/* internal data. See comments before set_fderives and set_firsts. */
-static bitsetv fderives = NULL;
-static bitsetv firsts = NULL;
-
-/* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */
-#define FDERIVES(Var) fderives[(Var) - ntokens]
-#define FIRSTS(Var) firsts[(Var) - ntokens]
-
-
-/*-----------------.
-| Debugging code. |
-`-----------------*/
-
-static void
-print_closure (char const *title, item_number const *array, size_t size)
-{
- size_t i;
- fprintf (stderr, "Closure: %s\n", title);
- for (i = 0; i < size; ++i)
- {
- item_number *rp;
- fprintf (stderr, " %2d: .", array[i]);
- for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
- fprintf (stderr, " %s", symbols[*rp]->tag);
- fprintf (stderr, " (rule %d)\n", -*rp - 1);
- }
- fputs ("\n\n", stderr);
-}
-
-
-static void
-print_firsts (void)
-{
- symbol_number i, j;
-
- fprintf (stderr, "FIRSTS\n");
- for (i = ntokens; i < nsyms; i++)
- {
- bitset_iterator iter;
- fprintf (stderr, " %s firsts\n", symbols[i]->tag);
- BITSET_FOR_EACH (iter, FIRSTS (i), j, 0)
- fprintf (stderr, " %s\n", symbols[j + ntokens]->tag);
- }
- fprintf (stderr, "\n\n");
-}
-
-
-static void
-print_fderives (void)
-{
- int i;
- rule_number r;
-
- fprintf (stderr, "FDERIVES\n");
- for (i = ntokens; i < nsyms; i++)
- {
- bitset_iterator iter;
- fprintf (stderr, " %s derives\n", symbols[i]->tag);
- BITSET_FOR_EACH (iter, FDERIVES (i), r, 0)
- {
- fprintf (stderr, " %3d ", r);
- rule_rhs_print (&rules[r], stderr);
- fprintf (stderr, "\n");
- }
- }
- fprintf (stderr, "\n\n");
-}
-
-/*------------------------------------------------------------------.
-| Set FIRSTS to be an NVARS array of NVARS bitsets indicating which |
-| items can represent the beginning of the input corresponding to |
-| which other items. |
-| |
-| For example, if some rule expands symbol 5 into the sequence of |
-| symbols 8 3 20, the symbol 8 can be the beginning of the data for |
-| symbol 5, so the bit [8 - ntokens] in first[5 - ntokens] (= FIRST |
-| (5)) is set. |
-`------------------------------------------------------------------*/
-
-static void
-set_firsts (void)
-{
- symbol_number i, j;
-
- firsts = bitsetv_create (nvars, nvars, BITSET_FIXED);
-
- for (i = ntokens; i < nsyms; i++)
- for (j = 0; derives[i - ntokens][j]; ++j)
- {
- item_number sym = derives[i - ntokens][j]->rhs[0];
- if (ISVAR (sym))
- bitset_set (FIRSTS (i), sym - ntokens);
- }
-
- if (trace_flag & trace_sets)
- bitsetv_matrix_dump (stderr, "RTC: Firsts Input", firsts);
- bitsetv_reflexive_transitive_closure (firsts);
- if (trace_flag & trace_sets)
- bitsetv_matrix_dump (stderr, "RTC: Firsts Output", firsts);
-
- if (trace_flag & trace_sets)
- print_firsts ();
-}
-
-/*-------------------------------------------------------------------.
-| Set FDERIVES to an NVARS by NRULES matrix of bits indicating which |
-| rules can help derive the beginning of the data for each |
-| nonterminal. |
-| |
-| For example, if symbol 5 can be derived as the sequence of symbols |
-| 8 3 20, and one of the rules for deriving symbol 8 is rule 4, then |
-| the [5 - NTOKENS, 4] bit in FDERIVES is set. |
-`-------------------------------------------------------------------*/
-
-static void
-set_fderives (void)
-{
- symbol_number i, j;
- rule_number k;
-
- fderives = bitsetv_create (nvars, nrules, BITSET_FIXED);
-
- set_firsts ();
-
- for (i = ntokens; i < nsyms; ++i)
- for (j = ntokens; j < nsyms; ++j)
- if (bitset_test (FIRSTS (i), j - ntokens))
- for (k = 0; derives[j - ntokens][k]; ++k)
- bitset_set (FDERIVES (i), derives[j - ntokens][k]->number);
-
- if (trace_flag & trace_sets)
- print_fderives ();
-
- bitsetv_free (firsts);
-}
-
-
-
-void
-new_closure (unsigned int n)
-{
- itemset = xnmalloc (n, sizeof *itemset);
-
- ruleset = bitset_create (nrules, BITSET_FIXED);
-
- set_fderives ();
-}
-
-
-
-void
-closure (item_number const *core, size_t n)
-{
- /* Index over CORE. */
- size_t c;
-
- /* A bit index over RULESET. */
- rule_number ruleno;
-
- bitset_iterator iter;
-
- if (trace_flag & trace_sets)
- print_closure ("input", core, n);
-
- bitset_zero (ruleset);
-
- for (c = 0; c < n; ++c)
- if (ISVAR (ritem[core[c]]))
- bitset_or (ruleset, ruleset, FDERIVES (ritem[core[c]]));
-
- /* core is sorted on item index in ritem, which is sorted on rule number.
- Compute itemset with the same sort. */
- nitemset = 0;
- c = 0;
- BITSET_FOR_EACH (iter, ruleset, ruleno, 0)
- {
- item_number itemno = rules[ruleno].rhs - ritem;
- while (c < n && core[c] < itemno)
- {
- itemset[nitemset] = core[c];
- nitemset++;
- c++;
- }
- itemset[nitemset] = itemno;
- nitemset++;
- };
-
- while (c < n)
- {
- itemset[nitemset] = core[c];
- nitemset++;
- c++;
- }
-
- if (trace_flag & trace_sets)
- print_closure ("output", itemset, nitemset);
-}
-
-
-void
-free_closure (void)
-{
- free (itemset);
- bitset_free (ruleset);
- bitsetv_free (fderives);
-}
+/* Closures for Bison
+
+ Copyright (C) 1984, 1989, 2000-2002, 2004-2005, 2007, 2009-2013 Free
+ Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitset.h>
+#include <bitsetv-print.h>
+#include <bitsetv.h>
+
+#include "closure.h"
+#include "derives.h"
+#include "getargs.h"
+#include "gram.h"
+#include "reader.h"
+#include "symtab.h"
+
+/* NITEMSET is the size of the array ITEMSET. */
+item_number *itemset;
+size_t nitemset;
+
+static bitset ruleset;
+
+/* internal data. See comments before set_fderives and set_firsts. */
+static bitsetv fderives = NULL;
+static bitsetv firsts = NULL;
+
+/* Retrieve the FDERIVES/FIRSTS sets of the nonterminals numbered Var. */
+#define FDERIVES(Var) fderives[(Var) - ntokens]
+#define FIRSTS(Var) firsts[(Var) - ntokens]
+
+
+/*-----------------.
+| Debugging code. |
+`-----------------*/
+
+static void
+print_closure (char const *title, item_number const *array, size_t size)
+{
+ size_t i;
+ fprintf (stderr, "Closure: %s\n", title);
+ for (i = 0; i < size; ++i)
+ {
+ item_number *rp;
+ fprintf (stderr, " %2d: .", array[i]);
+ for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
+ fprintf (stderr, " %s", symbols[*rp]->tag);
+ fprintf (stderr, " (rule %d)\n", -*rp - 1);
+ }
+ fputs ("\n\n", stderr);
+}
+
+
+static void
+print_firsts (void)
+{
+ symbol_number i, j;
+
+ fprintf (stderr, "FIRSTS\n");
+ for (i = ntokens; i < nsyms; i++)
+ {
+ bitset_iterator iter;
+ fprintf (stderr, " %s firsts\n", symbols[i]->tag);
+ BITSET_FOR_EACH (iter, FIRSTS (i), j, 0)
+ fprintf (stderr, " %s\n", symbols[j + ntokens]->tag);
+ }
+ fprintf (stderr, "\n\n");
+}
+
+
+static void
+print_fderives (void)
+{
+ int i;
+ rule_number r;
+
+ fprintf (stderr, "FDERIVES\n");
+ for (i = ntokens; i < nsyms; i++)
+ {
+ bitset_iterator iter;
+ fprintf (stderr, " %s derives\n", symbols[i]->tag);
+ BITSET_FOR_EACH (iter, FDERIVES (i), r, 0)
+ {
+ fprintf (stderr, " %3d ", r);
+ rule_rhs_print (&rules[r], stderr);
+ fprintf (stderr, "\n");
+ }
+ }
+ fprintf (stderr, "\n\n");
+}
+
+/*------------------------------------------------------------------.
+| Set FIRSTS to be an NVARS array of NVARS bitsets indicating which |
+| items can represent the beginning of the input corresponding to |
+| which other items. |
+| |
+| For example, if some rule expands symbol 5 into the sequence of |
+| symbols 8 3 20, the symbol 8 can be the beginning of the data for |
+| symbol 5, so the bit [8 - ntokens] in first[5 - ntokens] (= FIRST |
+| (5)) is set. |
+`------------------------------------------------------------------*/
+
+static void
+set_firsts (void)
+{
+ symbol_number i, j;
+
+ firsts = bitsetv_create (nvars, nvars, BITSET_FIXED);
+
+ for (i = ntokens; i < nsyms; i++)
+ for (j = 0; derives[i - ntokens][j]; ++j)
+ {
+ item_number sym = derives[i - ntokens][j]->rhs[0];
+ if (ISVAR (sym))
+ bitset_set (FIRSTS (i), sym - ntokens);
+ }
+
+ if (trace_flag & trace_sets)
+ bitsetv_matrix_dump (stderr, "RTC: Firsts Input", firsts);
+ bitsetv_reflexive_transitive_closure (firsts);
+ if (trace_flag & trace_sets)
+ bitsetv_matrix_dump (stderr, "RTC: Firsts Output", firsts);
+
+ if (trace_flag & trace_sets)
+ print_firsts ();
+}
+
+/*-------------------------------------------------------------------.
+| Set FDERIVES to an NVARS by NRULES matrix of bits indicating which |
+| rules can help derive the beginning of the data for each |
+| nonterminal. |
+| |
+| For example, if symbol 5 can be derived as the sequence of symbols |
+| 8 3 20, and one of the rules for deriving symbol 8 is rule 4, then |
+| the [5 - NTOKENS, 4] bit in FDERIVES is set. |
+`-------------------------------------------------------------------*/
+
+static void
+set_fderives (void)
+{
+ symbol_number i, j;
+ rule_number k;
+
+ fderives = bitsetv_create (nvars, nrules, BITSET_FIXED);
+
+ set_firsts ();
+
+ for (i = ntokens; i < nsyms; ++i)
+ for (j = ntokens; j < nsyms; ++j)
+ if (bitset_test (FIRSTS (i), j - ntokens))
+ for (k = 0; derives[j - ntokens][k]; ++k)
+ bitset_set (FDERIVES (i), derives[j - ntokens][k]->number);
+
+ if (trace_flag & trace_sets)
+ print_fderives ();
+
+ bitsetv_free (firsts);
+}
+
+
+
+void
+new_closure (unsigned int n)
+{
+ itemset = xnmalloc (n, sizeof *itemset);
+
+ ruleset = bitset_create (nrules, BITSET_FIXED);
+
+ set_fderives ();
+}
+
+
+
+void
+closure (item_number const *core, size_t n)
+{
+ /* Index over CORE. */
+ size_t c;
+
+ /* A bit index over RULESET. */
+ rule_number ruleno;
+
+ bitset_iterator iter;
+
+ if (trace_flag & trace_sets)
+ print_closure ("input", core, n);
+
+ bitset_zero (ruleset);
+
+ for (c = 0; c < n; ++c)
+ if (ISVAR (ritem[core[c]]))
+ bitset_or (ruleset, ruleset, FDERIVES (ritem[core[c]]));
+
+ /* core is sorted on item index in ritem, which is sorted on rule number.
+ Compute itemset with the same sort. */
+ nitemset = 0;
+ c = 0;
+ BITSET_FOR_EACH (iter, ruleset, ruleno, 0)
+ {
+ item_number itemno = rules[ruleno].rhs - ritem;
+ while (c < n && core[c] < itemno)
+ {
+ itemset[nitemset] = core[c];
+ nitemset++;
+ c++;
+ }
+ itemset[nitemset] = itemno;
+ nitemset++;
+ };
+
+ while (c < n)
+ {
+ itemset[nitemset] = core[c];
+ nitemset++;
+ c++;
+ }
+
+ if (trace_flag & trace_sets)
+ print_closure ("output", itemset, nitemset);
+}
+
+
+void
+free_closure (void)
+{
+ free (itemset);
+ bitset_free (ruleset);
+ bitsetv_free (fderives);
+}
diff --git a/contrib/tools/bison/bison/src/closure.h b/contrib/tools/bison/bison/src/closure.h
index ad4a3ba96b..d9fb44a212 100644
--- a/contrib/tools/bison/bison/src/closure.h
+++ b/contrib/tools/bison/bison/src/closure.h
@@ -1,57 +1,57 @@
-/* Subroutines for bison
-
- Copyright (C) 1984, 1989, 2000-2002, 2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef CLOSURE_H_
-# define CLOSURE_H_
-
-# include "gram.h"
-
-/* Allocates the itemset and ruleset vectors, and precomputes useful
- data so that closure can be called. n is the number of elements to
- allocate for itemset. */
-
-void new_closure (unsigned int n);
-
-
-/* Given the kernel (aka core) of a state (a sorted vector of item numbers
- ITEMS, of length N), set up RULESET and ITEMSET to indicate what
- rules could be run and which items could be accepted when those
- items are the active ones.
-
- RULESET contains a bit for each rule. CLOSURE sets the bits for
- all rules which could potentially describe the next input to be
- read.
-
- ITEMSET is a sorted vector of item numbers; NITEMSET is its size
- (actually, points to just beyond the end of the part of it that is
- significant). CLOSURE places there the indices of all items which
- represent units of input that could arrive next. */
-
-void closure (item_number const *items, size_t n);
-
-
-/* Frees ITEMSET, RULESET and internal data. */
-
-void free_closure (void);
-
-extern item_number *itemset;
-extern size_t nitemset;
-
-#endif /* !CLOSURE_H_ */
+/* Subroutines for bison
+
+ Copyright (C) 1984, 1989, 2000-2002, 2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef CLOSURE_H_
+# define CLOSURE_H_
+
+# include "gram.h"
+
+/* Allocates the itemset and ruleset vectors, and precomputes useful
+ data so that closure can be called. n is the number of elements to
+ allocate for itemset. */
+
+void new_closure (unsigned int n);
+
+
+/* Given the kernel (aka core) of a state (a sorted vector of item numbers
+ ITEMS, of length N), set up RULESET and ITEMSET to indicate what
+ rules could be run and which items could be accepted when those
+ items are the active ones.
+
+ RULESET contains a bit for each rule. CLOSURE sets the bits for
+ all rules which could potentially describe the next input to be
+ read.
+
+ ITEMSET is a sorted vector of item numbers; NITEMSET is its size
+ (actually, points to just beyond the end of the part of it that is
+ significant). CLOSURE places there the indices of all items which
+ represent units of input that could arrive next. */
+
+void closure (item_number const *items, size_t n);
+
+
+/* Frees ITEMSET, RULESET and internal data. */
+
+void free_closure (void);
+
+extern item_number *itemset;
+extern size_t nitemset;
+
+#endif /* !CLOSURE_H_ */
diff --git a/contrib/tools/bison/bison/src/complain.c b/contrib/tools/bison/bison/src/complain.c
index fdc4b5426b..5d5c58db32 100644
--- a/contrib/tools/bison/bison/src/complain.c
+++ b/contrib/tools/bison/bison/src/complain.c
@@ -1,379 +1,379 @@
-/* Declaration for error-reporting function for Bison.
-
- Copyright (C) 2000-2002, 2004-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Based on error.c and error.h,
- written by David MacKenzie <djm@gnu.ai.mit.edu>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <argmatch.h>
-#include <stdarg.h>
-#include <progname.h>
-
-#include "complain.h"
-#include "files.h"
-#include "getargs.h"
-#include "quote.h"
-
-err_status complaint_status = status_none;
-
-bool warnings_are_errors = false;
-
-/** Diagnostics severity. */
-typedef enum
- {
- severity_disabled = 0,
- severity_unset = 1,
- severity_warning = 2,
- severity_error = 3,
- severity_fatal = 4
- } severity;
-
-
-/** For each warning type, its severity. */
-static severity warnings_flag[warnings_size];
-
-static unsigned *indent_ptr = 0;
-
-/*------------------------.
-| --warnings's handling. |
-`------------------------*/
-
-static const char * const warnings_args[] =
-{
- "none",
- "midrule-values",
- "yacc",
- "conflicts-sr",
- "conflicts-rr",
- "deprecated",
- "empty-rule",
- "precedence",
- "other",
- "all",
- "error",
- "everything",
- 0
-};
-
-static const int warnings_types[] =
-{
- Wnone,
- Wmidrule_values,
- Wyacc,
- Wconflicts_sr,
- Wconflicts_rr,
- Wdeprecated,
- Wempty_rule,
- Wprecedence,
- Wother,
- Wall,
- Werror,
- Weverything
-};
-
-ARGMATCH_VERIFY (warnings_args, warnings_types);
-
-void
-warning_argmatch (char const *arg, size_t no, size_t err)
-{
- int value = XARGMATCH ("--warning", arg + no + err,
- warnings_args, warnings_types);
-
- /* -Wnone == -Wno-everything, and -Wno-none == -Weverything. */
- if (!value)
- {
- value = Weverything;
- no = !no;
- }
-
- if (no)
- {
- size_t b;
- for (b = 0; b < warnings_size; ++b)
- if (value & 1 << b)
- {
- if (err)
- {
- /* -Wno-error=foo: if foo enabled as an error,
- make it a warning. */
- if (warnings_flag[b] == severity_error)
- warnings_flag[b] = severity_warning;
- }
- else
- /* -Wno-foo. */
- warnings_flag[b] = severity_disabled;
- }
- }
- else
- {
- size_t b;
- for (b = 0; b < warnings_size; ++b)
- if (value & 1 << b)
- /* -Wfoo and -Werror=foo. */
- warnings_flag[b] = err ? severity_error : severity_warning;
- }
-}
-
-/** Decode a comma-separated list of arguments from -W.
- *
- * \param args comma separated list of effective subarguments to decode.
- * If 0, then activate all the flags.
- */
-
-void
-warnings_argmatch (char *args)
-{
- if (args)
- for (args = strtok (args, ","); args; args = strtok (NULL, ","))
- if (STREQ (args, "error"))
- warnings_are_errors = true;
- else if (STREQ (args, "no-error"))
- {
- warnings_are_errors = false;
- warning_argmatch ("no-error=everything", 3, 6);
- }
- else
- {
- size_t no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
- size_t err = STRPREFIX_LIT ("error=", args + no) ? 6 : 0;
-
- warning_argmatch (args, no, err);
- }
- else
- warning_argmatch ("all", 0, 0);
-}
-
-
-/*-----------.
-| complain. |
-`-----------*/
-
-void
-complain_init (void)
-{
- warnings warnings_default =
- Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother;
-
- size_t b;
- for (b = 0; b < warnings_size; ++b)
- warnings_flag[b] = (1 << b & warnings_default
- ? severity_warning
- : severity_unset);
-}
-
-static severity
-warning_severity (warnings flags)
-{
- if (flags & fatal)
- return severity_fatal;
- else if (flags & complaint)
- return severity_error;
- else
- {
- severity res = severity_disabled;
- size_t b;
- for (b = 0; b < warnings_size; ++b)
- if (flags & 1 << b)
- res = res < warnings_flag[b] ? warnings_flag[b] : res;
- if (res == severity_warning && warnings_are_errors)
- res = severity_error;
- return res;
- }
-}
-
-bool
-warning_is_unset (warnings flags)
-{
- size_t b;
- for (b = 0; b < warnings_size; ++b)
- if (flags & 1 << b && warnings_flag[b] != severity_unset)
- return false;
- return true;
-}
-
-/** Display a "[-Wyacc]" like message on \a f. */
-
-static void
-warnings_print_categories (warnings warn_flags, FILE *f)
-{
- /* Display only the first match, the second is "-Wall". */
- size_t i;
- for (i = 0; warnings_args[i]; ++i)
- if (warn_flags & warnings_types[i])
- {
- severity s = warning_severity (warnings_types[i]);
- fprintf (f, " [-W%s%s]",
- s == severity_error ? "error=" : "",
- warnings_args[i]);
- return;
- }
-}
-
-/** Report an error message.
- *
- * \param loc the location, defaulting to the current file,
- * or the program name.
- * \param flags the category for this message.
- * \param prefix put before the message (e.g., "warning").
- * \param message the error message, a printf format string. Iff it
- * ends with ": ", then no trailing newline is printed,
- * and the caller should print the remaining
- * newline-terminated message to stderr.
- * \param args the arguments of the format string.
- */
-static
-void
-error_message (const location *loc, warnings flags, const char *prefix,
- const char *message, va_list args)
-{
- unsigned pos = 0;
-
- if (loc)
- pos += location_print (*loc, stderr);
- else
- pos += fprintf (stderr, "%s", current_file ? current_file : program_name);
- pos += fprintf (stderr, ": ");
-
- if (indent_ptr)
- {
- if (*indent_ptr)
- prefix = NULL;
- if (!*indent_ptr)
- *indent_ptr = pos;
- else if (*indent_ptr > pos)
- fprintf (stderr, "%*s", *indent_ptr - pos, "");
- indent_ptr = 0;
- }
-
- if (prefix)
- fprintf (stderr, "%s: ", prefix);
-
- vfprintf (stderr, message, args);
- if (! (flags & silent))
- warnings_print_categories (flags, stderr);
- {
- size_t l = strlen (message);
- if (l < 2 || message[l - 2] != ':' || message[l - 1] != ' ')
- {
- putc ('\n', stderr);
- fflush (stderr);
- if (loc && feature_flag & feature_caret && !(flags & no_caret))
- location_caret (*loc, stderr);
- }
- }
- fflush (stderr);
-}
-
-/** Raise a complaint. That can be a fatal error, an error or just a
- warning. */
-
-static void
-complains (const location *loc, warnings flags, const char *message,
- va_list args)
-{
- severity s = warning_severity (flags);
- if ((flags & complaint) && complaint_status < status_complaint)
- complaint_status = status_complaint;
-
- if (severity_warning <= s)
- {
- const char* prefix =
- s == severity_fatal ? _("fatal error")
- : s == severity_error ? _("error")
- : _("warning");
- if (severity_error <= s && ! complaint_status)
- complaint_status = status_warning_as_error;
- error_message (loc, flags, prefix, message, args);
- }
-
- if (flags & fatal)
- exit (EXIT_FAILURE);
-}
-
-void
-complain (location const *loc, warnings flags, const char *message, ...)
-{
- va_list args;
- va_start (args, message);
- complains (loc, flags, message, args);
- va_end (args);
-}
-
-void
-complain_indent (location const *loc, warnings flags, unsigned *indent,
- const char *message, ...)
-{
- va_list args;
- indent_ptr = indent;
- va_start (args, message);
- complains (loc, flags, message, args);
- va_end (args);
-}
-
-void
-complain_args (location const *loc, warnings w, unsigned *indent,
- int argc, char *argv[])
-{
- switch (argc)
- {
- case 1:
- complain_indent (loc, w, indent, "%s", _(argv[0]));
- break;
- case 2:
- complain_indent (loc, w, indent, _(argv[0]), argv[1]);
- break;
- case 3:
- complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2]);
- break;
- case 4:
- complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2], argv[3]);
- break;
- case 5:
- complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2], argv[3],
- argv[4]);
- break;
- default:
- complain (loc, fatal, "too many arguments for complains");
- break;
- }
-}
-
-void
-deprecated_directive (location const *loc, char const *old, char const *upd)
-{
- if (feature_flag & feature_caret)
- complain (loc, Wdeprecated,
- _("deprecated directive, use %s"),
- quote_n (1, upd));
- else
- complain (loc, Wdeprecated,
- _("deprecated directive: %s, use %s"),
- quote (old), quote_n (1, upd));
-}
-
-void
-duplicate_directive (char const *directive,
- location first, location second)
-{
- unsigned i = 0;
- complain (&second, complaint, _("only one %s allowed per rule"), directive);
- i += SUB_INDENT;
- complain_indent (&first, complaint, &i, _("previous declaration"));
-}
+/* Declaration for error-reporting function for Bison.
+
+ Copyright (C) 2000-2002, 2004-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Based on error.c and error.h,
+ written by David MacKenzie <djm@gnu.ai.mit.edu>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <argmatch.h>
+#include <stdarg.h>
+#include <progname.h>
+
+#include "complain.h"
+#include "files.h"
+#include "getargs.h"
+#include "quote.h"
+
+err_status complaint_status = status_none;
+
+bool warnings_are_errors = false;
+
+/** Diagnostics severity. */
+typedef enum
+ {
+ severity_disabled = 0,
+ severity_unset = 1,
+ severity_warning = 2,
+ severity_error = 3,
+ severity_fatal = 4
+ } severity;
+
+
+/** For each warning type, its severity. */
+static severity warnings_flag[warnings_size];
+
+static unsigned *indent_ptr = 0;
+
+/*------------------------.
+| --warnings's handling. |
+`------------------------*/
+
+static const char * const warnings_args[] =
+{
+ "none",
+ "midrule-values",
+ "yacc",
+ "conflicts-sr",
+ "conflicts-rr",
+ "deprecated",
+ "empty-rule",
+ "precedence",
+ "other",
+ "all",
+ "error",
+ "everything",
+ 0
+};
+
+static const int warnings_types[] =
+{
+ Wnone,
+ Wmidrule_values,
+ Wyacc,
+ Wconflicts_sr,
+ Wconflicts_rr,
+ Wdeprecated,
+ Wempty_rule,
+ Wprecedence,
+ Wother,
+ Wall,
+ Werror,
+ Weverything
+};
+
+ARGMATCH_VERIFY (warnings_args, warnings_types);
+
+void
+warning_argmatch (char const *arg, size_t no, size_t err)
+{
+ int value = XARGMATCH ("--warning", arg + no + err,
+ warnings_args, warnings_types);
+
+ /* -Wnone == -Wno-everything, and -Wno-none == -Weverything. */
+ if (!value)
+ {
+ value = Weverything;
+ no = !no;
+ }
+
+ if (no)
+ {
+ size_t b;
+ for (b = 0; b < warnings_size; ++b)
+ if (value & 1 << b)
+ {
+ if (err)
+ {
+ /* -Wno-error=foo: if foo enabled as an error,
+ make it a warning. */
+ if (warnings_flag[b] == severity_error)
+ warnings_flag[b] = severity_warning;
+ }
+ else
+ /* -Wno-foo. */
+ warnings_flag[b] = severity_disabled;
+ }
+ }
+ else
+ {
+ size_t b;
+ for (b = 0; b < warnings_size; ++b)
+ if (value & 1 << b)
+ /* -Wfoo and -Werror=foo. */
+ warnings_flag[b] = err ? severity_error : severity_warning;
+ }
+}
+
+/** Decode a comma-separated list of arguments from -W.
+ *
+ * \param args comma separated list of effective subarguments to decode.
+ * If 0, then activate all the flags.
+ */
+
+void
+warnings_argmatch (char *args)
+{
+ if (args)
+ for (args = strtok (args, ","); args; args = strtok (NULL, ","))
+ if (STREQ (args, "error"))
+ warnings_are_errors = true;
+ else if (STREQ (args, "no-error"))
+ {
+ warnings_are_errors = false;
+ warning_argmatch ("no-error=everything", 3, 6);
+ }
+ else
+ {
+ size_t no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
+ size_t err = STRPREFIX_LIT ("error=", args + no) ? 6 : 0;
+
+ warning_argmatch (args, no, err);
+ }
+ else
+ warning_argmatch ("all", 0, 0);
+}
+
+
+/*-----------.
+| complain. |
+`-----------*/
+
+void
+complain_init (void)
+{
+ warnings warnings_default =
+ Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother;
+
+ size_t b;
+ for (b = 0; b < warnings_size; ++b)
+ warnings_flag[b] = (1 << b & warnings_default
+ ? severity_warning
+ : severity_unset);
+}
+
+static severity
+warning_severity (warnings flags)
+{
+ if (flags & fatal)
+ return severity_fatal;
+ else if (flags & complaint)
+ return severity_error;
+ else
+ {
+ severity res = severity_disabled;
+ size_t b;
+ for (b = 0; b < warnings_size; ++b)
+ if (flags & 1 << b)
+ res = res < warnings_flag[b] ? warnings_flag[b] : res;
+ if (res == severity_warning && warnings_are_errors)
+ res = severity_error;
+ return res;
+ }
+}
+
+bool
+warning_is_unset (warnings flags)
+{
+ size_t b;
+ for (b = 0; b < warnings_size; ++b)
+ if (flags & 1 << b && warnings_flag[b] != severity_unset)
+ return false;
+ return true;
+}
+
+/** Display a "[-Wyacc]" like message on \a f. */
+
+static void
+warnings_print_categories (warnings warn_flags, FILE *f)
+{
+ /* Display only the first match, the second is "-Wall". */
+ size_t i;
+ for (i = 0; warnings_args[i]; ++i)
+ if (warn_flags & warnings_types[i])
+ {
+ severity s = warning_severity (warnings_types[i]);
+ fprintf (f, " [-W%s%s]",
+ s == severity_error ? "error=" : "",
+ warnings_args[i]);
+ return;
+ }
+}
+
+/** Report an error message.
+ *
+ * \param loc the location, defaulting to the current file,
+ * or the program name.
+ * \param flags the category for this message.
+ * \param prefix put before the message (e.g., "warning").
+ * \param message the error message, a printf format string. Iff it
+ * ends with ": ", then no trailing newline is printed,
+ * and the caller should print the remaining
+ * newline-terminated message to stderr.
+ * \param args the arguments of the format string.
+ */
+static
+void
+error_message (const location *loc, warnings flags, const char *prefix,
+ const char *message, va_list args)
+{
+ unsigned pos = 0;
+
+ if (loc)
+ pos += location_print (*loc, stderr);
+ else
+ pos += fprintf (stderr, "%s", current_file ? current_file : program_name);
+ pos += fprintf (stderr, ": ");
+
+ if (indent_ptr)
+ {
+ if (*indent_ptr)
+ prefix = NULL;
+ if (!*indent_ptr)
+ *indent_ptr = pos;
+ else if (*indent_ptr > pos)
+ fprintf (stderr, "%*s", *indent_ptr - pos, "");
+ indent_ptr = 0;
+ }
+
+ if (prefix)
+ fprintf (stderr, "%s: ", prefix);
+
+ vfprintf (stderr, message, args);
+ if (! (flags & silent))
+ warnings_print_categories (flags, stderr);
+ {
+ size_t l = strlen (message);
+ if (l < 2 || message[l - 2] != ':' || message[l - 1] != ' ')
+ {
+ putc ('\n', stderr);
+ fflush (stderr);
+ if (loc && feature_flag & feature_caret && !(flags & no_caret))
+ location_caret (*loc, stderr);
+ }
+ }
+ fflush (stderr);
+}
+
+/** Raise a complaint. That can be a fatal error, an error or just a
+ warning. */
+
+static void
+complains (const location *loc, warnings flags, const char *message,
+ va_list args)
+{
+ severity s = warning_severity (flags);
+ if ((flags & complaint) && complaint_status < status_complaint)
+ complaint_status = status_complaint;
+
+ if (severity_warning <= s)
+ {
+ const char* prefix =
+ s == severity_fatal ? _("fatal error")
+ : s == severity_error ? _("error")
+ : _("warning");
+ if (severity_error <= s && ! complaint_status)
+ complaint_status = status_warning_as_error;
+ error_message (loc, flags, prefix, message, args);
+ }
+
+ if (flags & fatal)
+ exit (EXIT_FAILURE);
+}
+
+void
+complain (location const *loc, warnings flags, const char *message, ...)
+{
+ va_list args;
+ va_start (args, message);
+ complains (loc, flags, message, args);
+ va_end (args);
+}
+
+void
+complain_indent (location const *loc, warnings flags, unsigned *indent,
+ const char *message, ...)
+{
+ va_list args;
+ indent_ptr = indent;
+ va_start (args, message);
+ complains (loc, flags, message, args);
+ va_end (args);
+}
+
+void
+complain_args (location const *loc, warnings w, unsigned *indent,
+ int argc, char *argv[])
+{
+ switch (argc)
+ {
+ case 1:
+ complain_indent (loc, w, indent, "%s", _(argv[0]));
+ break;
+ case 2:
+ complain_indent (loc, w, indent, _(argv[0]), argv[1]);
+ break;
+ case 3:
+ complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2]);
+ break;
+ case 4:
+ complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2], argv[3]);
+ break;
+ case 5:
+ complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2], argv[3],
+ argv[4]);
+ break;
+ default:
+ complain (loc, fatal, "too many arguments for complains");
+ break;
+ }
+}
+
+void
+deprecated_directive (location const *loc, char const *old, char const *upd)
+{
+ if (feature_flag & feature_caret)
+ complain (loc, Wdeprecated,
+ _("deprecated directive, use %s"),
+ quote_n (1, upd));
+ else
+ complain (loc, Wdeprecated,
+ _("deprecated directive: %s, use %s"),
+ quote (old), quote_n (1, upd));
+}
+
+void
+duplicate_directive (char const *directive,
+ location first, location second)
+{
+ unsigned i = 0;
+ complain (&second, complaint, _("only one %s allowed per rule"), directive);
+ i += SUB_INDENT;
+ complain_indent (&first, complaint, &i, _("previous declaration"));
+}
diff --git a/contrib/tools/bison/bison/src/complain.h b/contrib/tools/bison/bison/src/complain.h
index 0d81503df7..c25e08cdf5 100644
--- a/contrib/tools/bison/bison/src/complain.h
+++ b/contrib/tools/bison/bison/src/complain.h
@@ -1,144 +1,144 @@
-/* Declaration for error-reporting function for Bison.
-
- Copyright (C) 2000-2002, 2006, 2009-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef COMPLAIN_H_
-# define COMPLAIN_H_ 1
-
-# include "location.h"
-
-/* Sub-messages indent. */
-# define SUB_INDENT (4)
-
-/*-------------.
-| --warnings. |
-`-------------*/
-
-/** The bits assigned to each warning type. */
-typedef enum
- {
- warning_midrule_values, /**< Unset or unused midrule values. */
- warning_yacc, /**< POSIXME. */
- warning_conflicts_sr, /**< S/R conflicts. */
- warning_conflicts_rr, /**< R/R conflicts. */
- warning_empty_rule, /**< Implicitly empty rules. */
- warning_deprecated, /**< Obsolete constructs. */
- warning_precedence, /**< Useless precedence and associativity. */
- warning_other, /**< All other warnings. */
-
- warnings_size /**< The number of warnings. Must be last. */
- } warning_bit;
-
-/** Whether -Werror was set. */
-extern bool warnings_are_errors;
-
-/** Decode a single argument from -W.
- *
- * \param arg the subarguments to decode.
- * If null, then activate all the flags.
- * \param no length of the potential "no-" prefix.
- * Can be 0 or 3. If 3, negate the action of the subargument.
- * \param err length of a potential "error=".
- * Can be 0 or 6. If 6, treat the subargument as a CATEGORY.
- *
- * If VALUE != 0 then KEY sets flags and no-KEY clears them.
- * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
- * flags from \c all. Thus no-none = all and no-all = none.
- */
-void warning_argmatch (char const *arg, size_t no, size_t err);
-
-/** Decode a comma-separated list of arguments from -W.
- *
- * \param args comma separated list of effective subarguments to decode.
- * If 0, then activate all the flags.
- */
-void warnings_argmatch (char *args);
-
-
-/*-----------.
-| complain. |
-`-----------*/
-
-/** Initialize this module. */
-void complain_init (void);
-
-typedef enum
- {
- /**< Issue no warnings. */
- Wnone = 0,
-
- Wmidrule_values = 1 << warning_midrule_values,
- Wyacc = 1 << warning_yacc,
- Wconflicts_sr = 1 << warning_conflicts_sr,
- Wconflicts_rr = 1 << warning_conflicts_rr,
- Wdeprecated = 1 << warning_deprecated,
- Wempty_rule = 1 << warning_empty_rule,
- Wprecedence = 1 << warning_precedence,
- Wother = 1 << warning_other,
-
- Werror = 1 << 10, /** This bit is no longer used. */
-
- complaint = 1 << 11, /**< All complaints. */
- fatal = 1 << 12, /**< All fatal errors. */
- silent = 1 << 13, /**< Do not display the warning type. */
- no_caret = 1 << 14, /**< Do not display caret location. */
-
- /**< All above warnings. */
- Weverything = ~complaint & ~fatal & ~silent,
- Wall = Weverything & ~Wyacc
- } warnings;
-
-/** Whether the warnings of \a flags are all unset.
- (Never enabled, never disabled). */
-bool warning_is_unset (warnings flags);
-
-/** Make a complaint, with maybe a location. */
-void complain (location const *loc, warnings flags, char const *message, ...)
- __attribute__ ((__format__ (__printf__, 3, 4)));
-
-/** Likewise, but with an \a argc/argv interface. */
-void complain_args (location const *loc, warnings w, unsigned *indent,
- int argc, char *arg[]);
-
-/** Make a complaint with location and some indentation. */
-void complain_indent (location const *loc, warnings flags, unsigned *indent,
- char const *message, ...)
- __attribute__ ((__format__ (__printf__, 4, 5)));
-
-
-/** Report an obsolete syntax, suggest the updated one. */
-void deprecated_directive (location const *loc,
- char const *obsolete, char const *updated);
-
-/** Report a repeated directive for a rule. */
-void duplicate_directive (char const *directive,
- location first, location second);
-
-/** Warnings treated as errors shouldn't stop the execution as regular errors
- should (because due to their nature, it is safe to go on). Thus, there are
- three possible execution statuses. */
-typedef enum
- {
- status_none,
- status_warning_as_error,
- status_complaint
- } err_status;
-
-/** Whether an error was reported. */
-extern err_status complaint_status;
-
-#endif /* !COMPLAIN_H_ */
+/* Declaration for error-reporting function for Bison.
+
+ Copyright (C) 2000-2002, 2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef COMPLAIN_H_
+# define COMPLAIN_H_ 1
+
+# include "location.h"
+
+/* Sub-messages indent. */
+# define SUB_INDENT (4)
+
+/*-------------.
+| --warnings. |
+`-------------*/
+
+/** The bits assigned to each warning type. */
+typedef enum
+ {
+ warning_midrule_values, /**< Unset or unused midrule values. */
+ warning_yacc, /**< POSIXME. */
+ warning_conflicts_sr, /**< S/R conflicts. */
+ warning_conflicts_rr, /**< R/R conflicts. */
+ warning_empty_rule, /**< Implicitly empty rules. */
+ warning_deprecated, /**< Obsolete constructs. */
+ warning_precedence, /**< Useless precedence and associativity. */
+ warning_other, /**< All other warnings. */
+
+ warnings_size /**< The number of warnings. Must be last. */
+ } warning_bit;
+
+/** Whether -Werror was set. */
+extern bool warnings_are_errors;
+
+/** Decode a single argument from -W.
+ *
+ * \param arg the subarguments to decode.
+ * If null, then activate all the flags.
+ * \param no length of the potential "no-" prefix.
+ * Can be 0 or 3. If 3, negate the action of the subargument.
+ * \param err length of a potential "error=".
+ * Can be 0 or 6. If 6, treat the subargument as a CATEGORY.
+ *
+ * If VALUE != 0 then KEY sets flags and no-KEY clears them.
+ * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
+ * flags from \c all. Thus no-none = all and no-all = none.
+ */
+void warning_argmatch (char const *arg, size_t no, size_t err);
+
+/** Decode a comma-separated list of arguments from -W.
+ *
+ * \param args comma separated list of effective subarguments to decode.
+ * If 0, then activate all the flags.
+ */
+void warnings_argmatch (char *args);
+
+
+/*-----------.
+| complain. |
+`-----------*/
+
+/** Initialize this module. */
+void complain_init (void);
+
+typedef enum
+ {
+ /**< Issue no warnings. */
+ Wnone = 0,
+
+ Wmidrule_values = 1 << warning_midrule_values,
+ Wyacc = 1 << warning_yacc,
+ Wconflicts_sr = 1 << warning_conflicts_sr,
+ Wconflicts_rr = 1 << warning_conflicts_rr,
+ Wdeprecated = 1 << warning_deprecated,
+ Wempty_rule = 1 << warning_empty_rule,
+ Wprecedence = 1 << warning_precedence,
+ Wother = 1 << warning_other,
+
+ Werror = 1 << 10, /** This bit is no longer used. */
+
+ complaint = 1 << 11, /**< All complaints. */
+ fatal = 1 << 12, /**< All fatal errors. */
+ silent = 1 << 13, /**< Do not display the warning type. */
+ no_caret = 1 << 14, /**< Do not display caret location. */
+
+ /**< All above warnings. */
+ Weverything = ~complaint & ~fatal & ~silent,
+ Wall = Weverything & ~Wyacc
+ } warnings;
+
+/** Whether the warnings of \a flags are all unset.
+ (Never enabled, never disabled). */
+bool warning_is_unset (warnings flags);
+
+/** Make a complaint, with maybe a location. */
+void complain (location const *loc, warnings flags, char const *message, ...)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+
+/** Likewise, but with an \a argc/argv interface. */
+void complain_args (location const *loc, warnings w, unsigned *indent,
+ int argc, char *arg[]);
+
+/** Make a complaint with location and some indentation. */
+void complain_indent (location const *loc, warnings flags, unsigned *indent,
+ char const *message, ...)
+ __attribute__ ((__format__ (__printf__, 4, 5)));
+
+
+/** Report an obsolete syntax, suggest the updated one. */
+void deprecated_directive (location const *loc,
+ char const *obsolete, char const *updated);
+
+/** Report a repeated directive for a rule. */
+void duplicate_directive (char const *directive,
+ location first, location second);
+
+/** Warnings treated as errors shouldn't stop the execution as regular errors
+ should (because due to their nature, it is safe to go on). Thus, there are
+ three possible execution statuses. */
+typedef enum
+ {
+ status_none,
+ status_warning_as_error,
+ status_complaint
+ } err_status;
+
+/** Whether an error was reported. */
+extern err_status complaint_status;
+
+#endif /* !COMPLAIN_H_ */
diff --git a/contrib/tools/bison/bison/src/conflicts.c b/contrib/tools/bison/bison/src/conflicts.c
index 1840473620..07a9f84d1c 100644
--- a/contrib/tools/bison/bison/src/conflicts.c
+++ b/contrib/tools/bison/bison/src/conflicts.c
@@ -1,629 +1,629 @@
-/* Find and resolve or report lookahead conflicts for bison,
-
- Copyright (C) 1984, 1989, 1992, 2000-2013 Free Software Foundation,
- Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitset.h>
-
-#include "LR0.h"
-#include "complain.h"
-#include "conflicts.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "lalr.h"
-#include "print-xml.h"
-#include "reader.h"
-#include "state.h"
-#include "symtab.h"
-
-/* -1 stands for not specified. */
-int expected_sr_conflicts = -1;
-int expected_rr_conflicts = -1;
-static char *conflicts;
-static struct obstack solved_conflicts_obstack;
-static struct obstack solved_conflicts_xml_obstack;
-
-static bitset shift_set;
-static bitset lookahead_set;
-
-
-
-enum conflict_resolution
- {
- shift_resolution,
- reduce_resolution,
- left_resolution,
- right_resolution,
- nonassoc_resolution
- };
-
-
-/*----------------------------------------------------------------.
-| Explain how an SR conflict between TOKEN and RULE was resolved: |
-| RESOLUTION. |
-`----------------------------------------------------------------*/
-
-static inline void
-log_resolution (rule *r, symbol_number token,
- enum conflict_resolution resolution)
-{
- if (report_flag & report_solved_conflicts)
- {
- /* The description of the resolution. */
- switch (resolution)
- {
- case shift_resolution:
- case right_resolution:
- obstack_printf (&solved_conflicts_obstack,
- _(" Conflict between rule %d and token %s"
- " resolved as shift"),
- r->number,
- symbols[token]->tag);
- break;
-
- case reduce_resolution:
- case left_resolution:
- obstack_printf (&solved_conflicts_obstack,
- _(" Conflict between rule %d and token %s"
- " resolved as reduce"),
- r->number,
- symbols[token]->tag);
- break;
-
- case nonassoc_resolution:
- obstack_printf (&solved_conflicts_obstack,
- _(" Conflict between rule %d and token %s"
- " resolved as an error"),
- r->number,
- symbols[token]->tag);
- break;
- }
-
- /* The reason. */
- switch (resolution)
- {
- case shift_resolution:
- obstack_printf (&solved_conflicts_obstack,
- " (%s < %s)",
- r->prec->tag,
- symbols[token]->tag);
- break;
-
- case reduce_resolution:
- obstack_printf (&solved_conflicts_obstack,
- " (%s < %s)",
- symbols[token]->tag,
- r->prec->tag);
- break;
-
- case left_resolution:
- obstack_printf (&solved_conflicts_obstack,
- " (%%left %s)",
- symbols[token]->tag);
- break;
-
- case right_resolution:
- obstack_printf (&solved_conflicts_obstack,
- " (%%right %s)",
- symbols[token]->tag);
- break;
-
- case nonassoc_resolution:
- obstack_printf (&solved_conflicts_obstack,
- " (%%nonassoc %s)",
- symbols[token]->tag);
- break;
- }
-
- obstack_sgrow (&solved_conflicts_obstack, ".\n");
- }
-
- /* XML report */
- if (xml_flag)
- {
- /* The description of the resolution. */
- switch (resolution)
- {
- case shift_resolution:
- case right_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- " <resolution rule=\"%d\" symbol=\"%s\""
- " type=\"shift\">",
- r->number,
- xml_escape (symbols[token]->tag));
- break;
-
- case reduce_resolution:
- case left_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- " <resolution rule=\"%d\" symbol=\"%s\""
- " type=\"reduce\">",
- r->number,
- xml_escape (symbols[token]->tag));
- break;
-
- case nonassoc_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- " <resolution rule=\"%d\" symbol=\"%s\""
- " type=\"error\">",
- r->number,
- xml_escape (symbols[token]->tag));
- break;
- }
-
- /* The reason. */
- switch (resolution)
- {
- case shift_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- "%s &lt; %s",
- xml_escape_n (0, r->prec->tag),
- xml_escape_n (1, symbols[token]->tag));
- break;
-
- case reduce_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- "%s &lt; %s",
- xml_escape_n (0, symbols[token]->tag),
- xml_escape_n (1, r->prec->tag));
- break;
-
- case left_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- "%%left %s",
- xml_escape (symbols[token]->tag));
- break;
-
- case right_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- "%%right %s",
- xml_escape (symbols[token]->tag));
- break;
-
- case nonassoc_resolution:
- obstack_printf (&solved_conflicts_xml_obstack,
- "%%nonassoc %s",
- xml_escape (symbols[token]->tag));
- break;
- }
-
- obstack_sgrow (&solved_conflicts_xml_obstack, "</resolution>\n");
- }
-}
-
-
-/*------------------------------------------------------------------.
-| Turn off the shift recorded for the specified token in the |
-| specified state. Used when we resolve a shift-reduce conflict in |
-| favor of the reduction or as an error (%nonassoc). |
-`------------------------------------------------------------------*/
-
-static void
-flush_shift (state *s, int token)
-{
- transitions *trans = s->transitions;
- int i;
-
- bitset_reset (lookahead_set, token);
- for (i = 0; i < trans->num; i++)
- if (!TRANSITION_IS_DISABLED (trans, i)
- && TRANSITION_SYMBOL (trans, i) == token)
- TRANSITION_DISABLE (trans, i);
-}
-
-
-/*--------------------------------------------------------------------.
-| Turn off the reduce recorded for the specified token in the |
-| specified lookahead set. Used when we resolve a shift-reduce |
-| conflict in favor of the shift or as an error (%nonassoc). |
-`--------------------------------------------------------------------*/
-
-static void
-flush_reduce (bitset lookahead_tokens, int token)
-{
- bitset_reset (lookahead_tokens, token);
-}
-
-
-/*------------------------------------------------------------------.
-| Attempt to resolve shift-reduce conflict for one rule by means of |
-| precedence declarations. It has already been checked that the |
-| rule has a precedence. A conflict is resolved by modifying the |
-| shift or reduce tables so that there is no longer a conflict. |
-| |
-| RULENO is the number of the lookahead bitset to consider. |
-| |
-| ERRORS and NERRS can be used to store discovered explicit |
-| errors. |
-`------------------------------------------------------------------*/
-
-static void
-resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
-{
- symbol_number i;
- reductions *reds = s->reductions;
- /* Find the rule to reduce by to get precedence of reduction. */
- rule *redrule = reds->rules[ruleno];
- int redprec = redrule->prec->prec;
- bitset lookahead_tokens = reds->lookahead_tokens[ruleno];
-
- for (i = 0; i < ntokens; i++)
- if (bitset_test (lookahead_tokens, i)
- && bitset_test (lookahead_set, i)
- && symbols[i]->prec)
- {
- /* Shift-reduce conflict occurs for token number i
- and it has a precedence.
- The precedence of shifting is that of token i. */
- if (symbols[i]->prec < redprec)
- {
- register_precedence (redrule->prec->number, i);
- log_resolution (redrule, i, reduce_resolution);
- flush_shift (s, i);
- }
- else if (symbols[i]->prec > redprec)
- {
- register_precedence (i, redrule->prec->number);
- log_resolution (redrule, i, shift_resolution);
- flush_reduce (lookahead_tokens, i);
- }
- else
- /* Matching precedence levels.
- For non-defined associativity, keep both: unexpected
- associativity conflict.
- For left associativity, keep only the reduction.
- For right associativity, keep only the shift.
- For nonassociativity, keep neither. */
-
- switch (symbols[i]->assoc)
- {
- case undef_assoc:
- abort ();
-
- case precedence_assoc:
- break;
-
- case right_assoc:
- register_assoc (i, redrule->prec->number);
- log_resolution (redrule, i, right_resolution);
- flush_reduce (lookahead_tokens, i);
- break;
-
- case left_assoc:
- register_assoc (i, redrule->prec->number);
- log_resolution (redrule, i, left_resolution);
- flush_shift (s, i);
- break;
-
- case non_assoc:
- register_assoc (i, redrule->prec->number);
- log_resolution (redrule, i, nonassoc_resolution);
- flush_shift (s, i);
- flush_reduce (lookahead_tokens, i);
- /* Record an explicit error for this token. */
- errors[(*nerrs)++] = symbols[i];
- break;
- }
- }
-}
-
-
-/*-------------------------------------------------------------------.
-| Solve the S/R conflicts of state S using the |
-| precedence/associativity, and flag it inconsistent if it still has |
-| conflicts. ERRORS can be used as storage to compute the list of |
-| lookahead tokens on which S raises a syntax error (%nonassoc). |
-`-------------------------------------------------------------------*/
-
-static void
-set_conflicts (state *s, symbol **errors)
-{
- int i;
- transitions *trans = s->transitions;
- reductions *reds = s->reductions;
- int nerrs = 0;
-
- if (s->consistent)
- return;
-
- bitset_zero (lookahead_set);
-
- FOR_EACH_SHIFT (trans, i)
- bitset_set (lookahead_set, TRANSITION_SYMBOL (trans, i));
-
- /* Loop over all rules which require lookahead in this state. First
- check for shift-reduce conflict, and try to resolve using
- precedence. */
- for (i = 0; i < reds->num; ++i)
- if (reds->rules[i]->prec && reds->rules[i]->prec->prec
- && !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
- resolve_sr_conflict (s, i, errors, &nerrs);
-
- if (nerrs)
- {
- /* Some tokens have been explicitly made errors. Allocate a
- permanent errs structure for this state, to record them. */
- state_errs_set (s, nerrs, errors);
- }
- if (obstack_object_size (&solved_conflicts_obstack))
- s->solved_conflicts = obstack_finish0 (&solved_conflicts_obstack);
- if (obstack_object_size (&solved_conflicts_xml_obstack))
- s->solved_conflicts_xml = obstack_finish0 (&solved_conflicts_xml_obstack);
-
- /* Loop over all rules which require lookahead in this state. Check
- for conflicts not resolved above. */
- for (i = 0; i < reds->num; ++i)
- {
- if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
- conflicts[s->number] = 1;
- bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
- }
-}
-
-
-/*----------------------------------------------------------------.
-| Solve all the S/R conflicts using the precedence/associativity, |
-| and flag as inconsistent the states that still have conflicts. |
-`----------------------------------------------------------------*/
-
-void
-conflicts_solve (void)
-{
- state_number i;
- /* List of lookahead tokens on which we explicitly raise a syntax error. */
- symbol **errors = xnmalloc (ntokens + 1, sizeof *errors);
-
- conflicts = xcalloc (nstates, sizeof *conflicts);
- shift_set = bitset_create (ntokens, BITSET_FIXED);
- lookahead_set = bitset_create (ntokens, BITSET_FIXED);
- obstack_init (&solved_conflicts_obstack);
- obstack_init (&solved_conflicts_xml_obstack);
-
- for (i = 0; i < nstates; i++)
- {
- set_conflicts (states[i], errors);
-
- /* For uniformity of the code, make sure all the states have a valid
- 'errs' member. */
- if (!states[i]->errs)
- states[i]->errs = errs_new (0, 0);
- }
-
- free (errors);
-}
-
-
-void
-conflicts_update_state_numbers (state_number old_to_new[],
- state_number nstates_old)
-{
- state_number i;
- for (i = 0; i < nstates_old; ++i)
- if (old_to_new[i] != nstates_old)
- conflicts[old_to_new[i]] = conflicts[i];
-}
-
-
-/*---------------------------------------------.
-| Count the number of shift/reduce conflicts. |
-`---------------------------------------------*/
-
-static size_t
-count_state_sr_conflicts (state *s)
-{
- int i;
- transitions *trans = s->transitions;
- reductions *reds = s->reductions;
-
- if (!trans)
- return 0;
-
- bitset_zero (lookahead_set);
- bitset_zero (shift_set);
-
- FOR_EACH_SHIFT (trans, i)
- bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
-
- for (i = 0; i < reds->num; ++i)
- bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
-
- bitset_and (lookahead_set, lookahead_set, shift_set);
-
- return bitset_count (lookahead_set);
-}
-
-/*---------------------------------------------.
-| The total number of shift/reduce conflicts. |
-`---------------------------------------------*/
-
-static size_t
-count_sr_conflicts (void)
-{
- size_t res = 0;
- state_number i;
-
- /* Conflicts by state. */
- for (i = 0; i < nstates; i++)
- if (conflicts[i])
- res += count_state_sr_conflicts (states[i]);
- return res;
-}
-
-
-
-/*----------------------------------------------------------------.
-| Count the number of reduce/reduce conflicts. If ONE_PER_TOKEN, |
-| count one conflict for each token that has any reduce/reduce |
-| conflicts. Otherwise, count one conflict for each pair of |
-| conflicting reductions. |
-`----------------------------------------------------------------*/
-
-static size_t
-count_state_rr_conflicts (state *s, bool one_per_token)
-{
- int i;
- reductions *reds = s->reductions;
- size_t res = 0;
-
- for (i = 0; i < ntokens; i++)
- {
- int count = 0;
- int j;
- for (j = 0; j < reds->num; ++j)
- count += bitset_test (reds->lookahead_tokens[j], i);
- if (count >= 2)
- res += one_per_token ? 1 : count-1;
- }
-
- return res;
-}
-
-static size_t
-count_rr_conflicts (bool one_per_token)
-{
- size_t res = 0;
- state_number i;
-
- /* Conflicts by state. */
- for (i = 0; i < nstates; i++)
- if (conflicts[i])
- res += count_state_rr_conflicts (states[i], one_per_token);
- return res;
-}
-
-
-/*-----------------------------------------------------------.
-| Output the detailed description of states with conflicts. |
-`-----------------------------------------------------------*/
-
-void
-conflicts_output (FILE *out)
-{
- bool printed_sth = false;
- state_number i;
- for (i = 0; i < nstates; i++)
- {
- state *s = states[i];
- if (conflicts[i])
- {
- int src = count_state_sr_conflicts (s);
- int rrc = count_state_rr_conflicts (s, true);
- fprintf (out, _("State %d "), i);
- if (src && rrc)
- fprintf (out,
- _("conflicts: %d shift/reduce, %d reduce/reduce\n"),
- src, rrc);
- else if (src)
- fprintf (out, _("conflicts: %d shift/reduce\n"), src);
- else if (rrc)
- fprintf (out, _("conflicts: %d reduce/reduce\n"), rrc);
- printed_sth = true;
- }
- }
- if (printed_sth)
- fputs ("\n\n", out);
-}
-
-/*--------------------------------------------------------.
-| Total the number of S/R and R/R conflicts. Unlike the |
-| code in conflicts_output, however, count EACH pair of |
-| reductions for the same state and lookahead as one |
-| conflict. |
-`--------------------------------------------------------*/
-
-int
-conflicts_total_count (void)
-{
- return count_sr_conflicts () + count_rr_conflicts (false);
-}
-
-
-/*------------------------------------------.
-| Reporting the total number of conflicts. |
-`------------------------------------------*/
-
-void
-conflicts_print (void)
-{
- if (! glr_parser && expected_rr_conflicts != -1)
- {
- complain (NULL, Wother, _("%%expect-rr applies only to GLR parsers"));
- expected_rr_conflicts = -1;
- }
-
- /* Screams for factoring, but almost useless because of the
- different strings to translate. */
- {
- int total = count_sr_conflicts ();
- /* If %expect is not used, but %expect-rr is, then expect 0 sr. */
- int expected =
- (expected_sr_conflicts == -1 && expected_rr_conflicts != -1)
- ? 0
- : expected_sr_conflicts;
- if (expected != -1)
- {
- if (expected != total)
- complain (NULL, complaint,
- _("shift/reduce conflicts: %d found, %d expected"),
- total, expected);
- }
- else if (total)
- complain (NULL, Wconflicts_sr,
- ngettext ("%d shift/reduce conflict",
- "%d shift/reduce conflicts",
- total),
- total);
- }
-
- {
- int total = count_rr_conflicts (true);
- /* If %expect-rr is not used, but %expect is, then expect 0 rr. */
- int expected =
- (expected_rr_conflicts == -1 && expected_sr_conflicts != -1)
- ? 0
- : expected_rr_conflicts;
- if (expected != -1)
- {
- if (expected != total)
- complain (NULL, complaint,
- _("reduce/reduce conflicts: %d found, %d expected"),
- total, expected);
- }
- else if (total)
- complain (NULL, Wconflicts_rr,
- ngettext ("%d reduce/reduce conflict",
- "%d reduce/reduce conflicts",
- total),
- total);
- }
-}
-
-
-void
-conflicts_free (void)
-{
- free (conflicts);
- bitset_free (shift_set);
- bitset_free (lookahead_set);
- obstack_free (&solved_conflicts_obstack, NULL);
- obstack_free (&solved_conflicts_xml_obstack, NULL);
-}
+/* Find and resolve or report lookahead conflicts for bison,
+
+ Copyright (C) 1984, 1989, 1992, 2000-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitset.h>
+
+#include "LR0.h"
+#include "complain.h"
+#include "conflicts.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "lalr.h"
+#include "print-xml.h"
+#include "reader.h"
+#include "state.h"
+#include "symtab.h"
+
+/* -1 stands for not specified. */
+int expected_sr_conflicts = -1;
+int expected_rr_conflicts = -1;
+static char *conflicts;
+static struct obstack solved_conflicts_obstack;
+static struct obstack solved_conflicts_xml_obstack;
+
+static bitset shift_set;
+static bitset lookahead_set;
+
+
+
+enum conflict_resolution
+ {
+ shift_resolution,
+ reduce_resolution,
+ left_resolution,
+ right_resolution,
+ nonassoc_resolution
+ };
+
+
+/*----------------------------------------------------------------.
+| Explain how an SR conflict between TOKEN and RULE was resolved: |
+| RESOLUTION. |
+`----------------------------------------------------------------*/
+
+static inline void
+log_resolution (rule *r, symbol_number token,
+ enum conflict_resolution resolution)
+{
+ if (report_flag & report_solved_conflicts)
+ {
+ /* The description of the resolution. */
+ switch (resolution)
+ {
+ case shift_resolution:
+ case right_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ _(" Conflict between rule %d and token %s"
+ " resolved as shift"),
+ r->number,
+ symbols[token]->tag);
+ break;
+
+ case reduce_resolution:
+ case left_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ _(" Conflict between rule %d and token %s"
+ " resolved as reduce"),
+ r->number,
+ symbols[token]->tag);
+ break;
+
+ case nonassoc_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ _(" Conflict between rule %d and token %s"
+ " resolved as an error"),
+ r->number,
+ symbols[token]->tag);
+ break;
+ }
+
+ /* The reason. */
+ switch (resolution)
+ {
+ case shift_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ " (%s < %s)",
+ r->prec->tag,
+ symbols[token]->tag);
+ break;
+
+ case reduce_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ " (%s < %s)",
+ symbols[token]->tag,
+ r->prec->tag);
+ break;
+
+ case left_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ " (%%left %s)",
+ symbols[token]->tag);
+ break;
+
+ case right_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ " (%%right %s)",
+ symbols[token]->tag);
+ break;
+
+ case nonassoc_resolution:
+ obstack_printf (&solved_conflicts_obstack,
+ " (%%nonassoc %s)",
+ symbols[token]->tag);
+ break;
+ }
+
+ obstack_sgrow (&solved_conflicts_obstack, ".\n");
+ }
+
+ /* XML report */
+ if (xml_flag)
+ {
+ /* The description of the resolution. */
+ switch (resolution)
+ {
+ case shift_resolution:
+ case right_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ " <resolution rule=\"%d\" symbol=\"%s\""
+ " type=\"shift\">",
+ r->number,
+ xml_escape (symbols[token]->tag));
+ break;
+
+ case reduce_resolution:
+ case left_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ " <resolution rule=\"%d\" symbol=\"%s\""
+ " type=\"reduce\">",
+ r->number,
+ xml_escape (symbols[token]->tag));
+ break;
+
+ case nonassoc_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ " <resolution rule=\"%d\" symbol=\"%s\""
+ " type=\"error\">",
+ r->number,
+ xml_escape (symbols[token]->tag));
+ break;
+ }
+
+ /* The reason. */
+ switch (resolution)
+ {
+ case shift_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ "%s &lt; %s",
+ xml_escape_n (0, r->prec->tag),
+ xml_escape_n (1, symbols[token]->tag));
+ break;
+
+ case reduce_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ "%s &lt; %s",
+ xml_escape_n (0, symbols[token]->tag),
+ xml_escape_n (1, r->prec->tag));
+ break;
+
+ case left_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ "%%left %s",
+ xml_escape (symbols[token]->tag));
+ break;
+
+ case right_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ "%%right %s",
+ xml_escape (symbols[token]->tag));
+ break;
+
+ case nonassoc_resolution:
+ obstack_printf (&solved_conflicts_xml_obstack,
+ "%%nonassoc %s",
+ xml_escape (symbols[token]->tag));
+ break;
+ }
+
+ obstack_sgrow (&solved_conflicts_xml_obstack, "</resolution>\n");
+ }
+}
+
+
+/*------------------------------------------------------------------.
+| Turn off the shift recorded for the specified token in the |
+| specified state. Used when we resolve a shift-reduce conflict in |
+| favor of the reduction or as an error (%nonassoc). |
+`------------------------------------------------------------------*/
+
+static void
+flush_shift (state *s, int token)
+{
+ transitions *trans = s->transitions;
+ int i;
+
+ bitset_reset (lookahead_set, token);
+ for (i = 0; i < trans->num; i++)
+ if (!TRANSITION_IS_DISABLED (trans, i)
+ && TRANSITION_SYMBOL (trans, i) == token)
+ TRANSITION_DISABLE (trans, i);
+}
+
+
+/*--------------------------------------------------------------------.
+| Turn off the reduce recorded for the specified token in the |
+| specified lookahead set. Used when we resolve a shift-reduce |
+| conflict in favor of the shift or as an error (%nonassoc). |
+`--------------------------------------------------------------------*/
+
+static void
+flush_reduce (bitset lookahead_tokens, int token)
+{
+ bitset_reset (lookahead_tokens, token);
+}
+
+
+/*------------------------------------------------------------------.
+| Attempt to resolve shift-reduce conflict for one rule by means of |
+| precedence declarations. It has already been checked that the |
+| rule has a precedence. A conflict is resolved by modifying the |
+| shift or reduce tables so that there is no longer a conflict. |
+| |
+| RULENO is the number of the lookahead bitset to consider. |
+| |
+| ERRORS and NERRS can be used to store discovered explicit |
+| errors. |
+`------------------------------------------------------------------*/
+
+static void
+resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
+{
+ symbol_number i;
+ reductions *reds = s->reductions;
+ /* Find the rule to reduce by to get precedence of reduction. */
+ rule *redrule = reds->rules[ruleno];
+ int redprec = redrule->prec->prec;
+ bitset lookahead_tokens = reds->lookahead_tokens[ruleno];
+
+ for (i = 0; i < ntokens; i++)
+ if (bitset_test (lookahead_tokens, i)
+ && bitset_test (lookahead_set, i)
+ && symbols[i]->prec)
+ {
+ /* Shift-reduce conflict occurs for token number i
+ and it has a precedence.
+ The precedence of shifting is that of token i. */
+ if (symbols[i]->prec < redprec)
+ {
+ register_precedence (redrule->prec->number, i);
+ log_resolution (redrule, i, reduce_resolution);
+ flush_shift (s, i);
+ }
+ else if (symbols[i]->prec > redprec)
+ {
+ register_precedence (i, redrule->prec->number);
+ log_resolution (redrule, i, shift_resolution);
+ flush_reduce (lookahead_tokens, i);
+ }
+ else
+ /* Matching precedence levels.
+ For non-defined associativity, keep both: unexpected
+ associativity conflict.
+ For left associativity, keep only the reduction.
+ For right associativity, keep only the shift.
+ For nonassociativity, keep neither. */
+
+ switch (symbols[i]->assoc)
+ {
+ case undef_assoc:
+ abort ();
+
+ case precedence_assoc:
+ break;
+
+ case right_assoc:
+ register_assoc (i, redrule->prec->number);
+ log_resolution (redrule, i, right_resolution);
+ flush_reduce (lookahead_tokens, i);
+ break;
+
+ case left_assoc:
+ register_assoc (i, redrule->prec->number);
+ log_resolution (redrule, i, left_resolution);
+ flush_shift (s, i);
+ break;
+
+ case non_assoc:
+ register_assoc (i, redrule->prec->number);
+ log_resolution (redrule, i, nonassoc_resolution);
+ flush_shift (s, i);
+ flush_reduce (lookahead_tokens, i);
+ /* Record an explicit error for this token. */
+ errors[(*nerrs)++] = symbols[i];
+ break;
+ }
+ }
+}
+
+
+/*-------------------------------------------------------------------.
+| Solve the S/R conflicts of state S using the |
+| precedence/associativity, and flag it inconsistent if it still has |
+| conflicts. ERRORS can be used as storage to compute the list of |
+| lookahead tokens on which S raises a syntax error (%nonassoc). |
+`-------------------------------------------------------------------*/
+
+static void
+set_conflicts (state *s, symbol **errors)
+{
+ int i;
+ transitions *trans = s->transitions;
+ reductions *reds = s->reductions;
+ int nerrs = 0;
+
+ if (s->consistent)
+ return;
+
+ bitset_zero (lookahead_set);
+
+ FOR_EACH_SHIFT (trans, i)
+ bitset_set (lookahead_set, TRANSITION_SYMBOL (trans, i));
+
+ /* Loop over all rules which require lookahead in this state. First
+ check for shift-reduce conflict, and try to resolve using
+ precedence. */
+ for (i = 0; i < reds->num; ++i)
+ if (reds->rules[i]->prec && reds->rules[i]->prec->prec
+ && !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
+ resolve_sr_conflict (s, i, errors, &nerrs);
+
+ if (nerrs)
+ {
+ /* Some tokens have been explicitly made errors. Allocate a
+ permanent errs structure for this state, to record them. */
+ state_errs_set (s, nerrs, errors);
+ }
+ if (obstack_object_size (&solved_conflicts_obstack))
+ s->solved_conflicts = obstack_finish0 (&solved_conflicts_obstack);
+ if (obstack_object_size (&solved_conflicts_xml_obstack))
+ s->solved_conflicts_xml = obstack_finish0 (&solved_conflicts_xml_obstack);
+
+ /* Loop over all rules which require lookahead in this state. Check
+ for conflicts not resolved above. */
+ for (i = 0; i < reds->num; ++i)
+ {
+ if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
+ conflicts[s->number] = 1;
+ bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
+ }
+}
+
+
+/*----------------------------------------------------------------.
+| Solve all the S/R conflicts using the precedence/associativity, |
+| and flag as inconsistent the states that still have conflicts. |
+`----------------------------------------------------------------*/
+
+void
+conflicts_solve (void)
+{
+ state_number i;
+ /* List of lookahead tokens on which we explicitly raise a syntax error. */
+ symbol **errors = xnmalloc (ntokens + 1, sizeof *errors);
+
+ conflicts = xcalloc (nstates, sizeof *conflicts);
+ shift_set = bitset_create (ntokens, BITSET_FIXED);
+ lookahead_set = bitset_create (ntokens, BITSET_FIXED);
+ obstack_init (&solved_conflicts_obstack);
+ obstack_init (&solved_conflicts_xml_obstack);
+
+ for (i = 0; i < nstates; i++)
+ {
+ set_conflicts (states[i], errors);
+
+ /* For uniformity of the code, make sure all the states have a valid
+ 'errs' member. */
+ if (!states[i]->errs)
+ states[i]->errs = errs_new (0, 0);
+ }
+
+ free (errors);
+}
+
+
+void
+conflicts_update_state_numbers (state_number old_to_new[],
+ state_number nstates_old)
+{
+ state_number i;
+ for (i = 0; i < nstates_old; ++i)
+ if (old_to_new[i] != nstates_old)
+ conflicts[old_to_new[i]] = conflicts[i];
+}
+
+
+/*---------------------------------------------.
+| Count the number of shift/reduce conflicts. |
+`---------------------------------------------*/
+
+static size_t
+count_state_sr_conflicts (state *s)
+{
+ int i;
+ transitions *trans = s->transitions;
+ reductions *reds = s->reductions;
+
+ if (!trans)
+ return 0;
+
+ bitset_zero (lookahead_set);
+ bitset_zero (shift_set);
+
+ FOR_EACH_SHIFT (trans, i)
+ bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
+
+ for (i = 0; i < reds->num; ++i)
+ bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
+
+ bitset_and (lookahead_set, lookahead_set, shift_set);
+
+ return bitset_count (lookahead_set);
+}
+
+/*---------------------------------------------.
+| The total number of shift/reduce conflicts. |
+`---------------------------------------------*/
+
+static size_t
+count_sr_conflicts (void)
+{
+ size_t res = 0;
+ state_number i;
+
+ /* Conflicts by state. */
+ for (i = 0; i < nstates; i++)
+ if (conflicts[i])
+ res += count_state_sr_conflicts (states[i]);
+ return res;
+}
+
+
+
+/*----------------------------------------------------------------.
+| Count the number of reduce/reduce conflicts. If ONE_PER_TOKEN, |
+| count one conflict for each token that has any reduce/reduce |
+| conflicts. Otherwise, count one conflict for each pair of |
+| conflicting reductions. |
+`----------------------------------------------------------------*/
+
+static size_t
+count_state_rr_conflicts (state *s, bool one_per_token)
+{
+ int i;
+ reductions *reds = s->reductions;
+ size_t res = 0;
+
+ for (i = 0; i < ntokens; i++)
+ {
+ int count = 0;
+ int j;
+ for (j = 0; j < reds->num; ++j)
+ count += bitset_test (reds->lookahead_tokens[j], i);
+ if (count >= 2)
+ res += one_per_token ? 1 : count-1;
+ }
+
+ return res;
+}
+
+static size_t
+count_rr_conflicts (bool one_per_token)
+{
+ size_t res = 0;
+ state_number i;
+
+ /* Conflicts by state. */
+ for (i = 0; i < nstates; i++)
+ if (conflicts[i])
+ res += count_state_rr_conflicts (states[i], one_per_token);
+ return res;
+}
+
+
+/*-----------------------------------------------------------.
+| Output the detailed description of states with conflicts. |
+`-----------------------------------------------------------*/
+
+void
+conflicts_output (FILE *out)
+{
+ bool printed_sth = false;
+ state_number i;
+ for (i = 0; i < nstates; i++)
+ {
+ state *s = states[i];
+ if (conflicts[i])
+ {
+ int src = count_state_sr_conflicts (s);
+ int rrc = count_state_rr_conflicts (s, true);
+ fprintf (out, _("State %d "), i);
+ if (src && rrc)
+ fprintf (out,
+ _("conflicts: %d shift/reduce, %d reduce/reduce\n"),
+ src, rrc);
+ else if (src)
+ fprintf (out, _("conflicts: %d shift/reduce\n"), src);
+ else if (rrc)
+ fprintf (out, _("conflicts: %d reduce/reduce\n"), rrc);
+ printed_sth = true;
+ }
+ }
+ if (printed_sth)
+ fputs ("\n\n", out);
+}
+
+/*--------------------------------------------------------.
+| Total the number of S/R and R/R conflicts. Unlike the |
+| code in conflicts_output, however, count EACH pair of |
+| reductions for the same state and lookahead as one |
+| conflict. |
+`--------------------------------------------------------*/
+
+int
+conflicts_total_count (void)
+{
+ return count_sr_conflicts () + count_rr_conflicts (false);
+}
+
+
+/*------------------------------------------.
+| Reporting the total number of conflicts. |
+`------------------------------------------*/
+
+void
+conflicts_print (void)
+{
+ if (! glr_parser && expected_rr_conflicts != -1)
+ {
+ complain (NULL, Wother, _("%%expect-rr applies only to GLR parsers"));
+ expected_rr_conflicts = -1;
+ }
+
+ /* Screams for factoring, but almost useless because of the
+ different strings to translate. */
+ {
+ int total = count_sr_conflicts ();
+ /* If %expect is not used, but %expect-rr is, then expect 0 sr. */
+ int expected =
+ (expected_sr_conflicts == -1 && expected_rr_conflicts != -1)
+ ? 0
+ : expected_sr_conflicts;
+ if (expected != -1)
+ {
+ if (expected != total)
+ complain (NULL, complaint,
+ _("shift/reduce conflicts: %d found, %d expected"),
+ total, expected);
+ }
+ else if (total)
+ complain (NULL, Wconflicts_sr,
+ ngettext ("%d shift/reduce conflict",
+ "%d shift/reduce conflicts",
+ total),
+ total);
+ }
+
+ {
+ int total = count_rr_conflicts (true);
+ /* If %expect-rr is not used, but %expect is, then expect 0 rr. */
+ int expected =
+ (expected_rr_conflicts == -1 && expected_sr_conflicts != -1)
+ ? 0
+ : expected_rr_conflicts;
+ if (expected != -1)
+ {
+ if (expected != total)
+ complain (NULL, complaint,
+ _("reduce/reduce conflicts: %d found, %d expected"),
+ total, expected);
+ }
+ else if (total)
+ complain (NULL, Wconflicts_rr,
+ ngettext ("%d reduce/reduce conflict",
+ "%d reduce/reduce conflicts",
+ total),
+ total);
+ }
+}
+
+
+void
+conflicts_free (void)
+{
+ free (conflicts);
+ bitset_free (shift_set);
+ bitset_free (lookahead_set);
+ obstack_free (&solved_conflicts_obstack, NULL);
+ obstack_free (&solved_conflicts_xml_obstack, NULL);
+}
diff --git a/contrib/tools/bison/bison/src/conflicts.h b/contrib/tools/bison/bison/src/conflicts.h
index 5df5787162..4219dd73e0 100644
--- a/contrib/tools/bison/bison/src/conflicts.h
+++ b/contrib/tools/bison/bison/src/conflicts.h
@@ -1,47 +1,47 @@
-/* Find and resolve or report lookahead conflicts for bison,
-
- Copyright (C) 2000-2002, 2004, 2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef CONFLICTS_H_
-# define CONFLICTS_H_
-# include "state.h"
-
-void conflicts_solve (void);
-
-/**
- * Update state numbers recorded in internal arrays such that:
- * - \c nstates_old is the old number of states.
- * - Where \c i is the old state number, <tt>old_to_new[i]</tt> is either:
- * - \c nstates_old if state \c i is removed because it is unreachable.
- * - The new state number.
- * - The highest new state number is the number of remaining states - 1.
- * - The numerical order of the remaining states has not changed.
- */
-void conflicts_update_state_numbers (state_number old_to_new[],
- state_number nstates_old);
-
-void conflicts_print (void);
-int conflicts_total_count (void);
-void conflicts_output (FILE *out);
-void conflicts_free (void);
-
-/* Were there conflicts? */
-extern int expected_sr_conflicts;
-extern int expected_rr_conflicts;
-#endif /* !CONFLICTS_H_ */
+/* Find and resolve or report lookahead conflicts for bison,
+
+ Copyright (C) 2000-2002, 2004, 2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef CONFLICTS_H_
+# define CONFLICTS_H_
+# include "state.h"
+
+void conflicts_solve (void);
+
+/**
+ * Update state numbers recorded in internal arrays such that:
+ * - \c nstates_old is the old number of states.
+ * - Where \c i is the old state number, <tt>old_to_new[i]</tt> is either:
+ * - \c nstates_old if state \c i is removed because it is unreachable.
+ * - The new state number.
+ * - The highest new state number is the number of remaining states - 1.
+ * - The numerical order of the remaining states has not changed.
+ */
+void conflicts_update_state_numbers (state_number old_to_new[],
+ state_number nstates_old);
+
+void conflicts_print (void);
+int conflicts_total_count (void);
+void conflicts_output (FILE *out);
+void conflicts_free (void);
+
+/* Were there conflicts? */
+extern int expected_sr_conflicts;
+extern int expected_rr_conflicts;
+#endif /* !CONFLICTS_H_ */
diff --git a/contrib/tools/bison/bison/src/derives.c b/contrib/tools/bison/bison/src/derives.c
index c834f0b0d0..72905b3128 100644
--- a/contrib/tools/bison/bison/src/derives.c
+++ b/contrib/tools/bison/bison/src/derives.c
@@ -1,120 +1,120 @@
-/* Match rules with nonterminals for bison,
-
- Copyright (C) 1984, 1989, 2000-2003, 2005, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "getargs.h"
-
-#include "derives.h"
-#include "gram.h"
-#include "reader.h"
-#include "symtab.h"
-
-/* Linked list of rule numbers. */
-typedef struct rule_list
-{
- struct rule_list *next;
- rule *value;
-} rule_list;
-
-rule ***derives;
-
-static void
-print_derives (void)
-{
- int i;
-
- fputs ("DERIVES\n", stderr);
-
- for (i = ntokens; i < nsyms; i++)
- {
- rule **rp;
- fprintf (stderr, " %s derives\n", symbols[i]->tag);
- for (rp = derives[i - ntokens]; *rp; ++rp)
- {
- fprintf (stderr, " %3d ", (*rp)->user_number);
- rule_rhs_print (*rp, stderr);
- fprintf (stderr, "\n");
- }
- }
-
- fputs ("\n\n", stderr);
-}
-
-
-void
-derives_compute (void)
-{
- symbol_number i;
- rule_number r;
- rule **q;
-
- /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
- whose LHS is NTERM. */
- rule_list **dset = xcalloc (nvars, sizeof *dset);
-
- /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
- Instead of performing NRULES allocations for each, have an array
- indexed by rule numbers. */
- rule_list *delts = xnmalloc (nrules, sizeof *delts);
-
- for (r = nrules - 1; r >= 0; --r)
- {
- symbol_number lhs = rules[r].lhs->number;
- rule_list *p = &delts[r];
- /* A new LHS is found. */
- p->next = dset[lhs - ntokens];
- p->value = &rules[r];
- dset[lhs - ntokens] = p;
- }
-
- /* DSET contains what we need under the form of a linked list. Make
- it a single array. */
-
- derives = xnmalloc (nvars, sizeof *derives);
- q = xnmalloc (nvars + nrules, sizeof *q);
-
- for (i = ntokens; i < nsyms; i++)
- {
- rule_list *p = dset[i - ntokens];
- derives[i - ntokens] = q;
- while (p)
- {
- *q++ = p->value;
- p = p->next;
- }
- *q++ = NULL;
- }
-
- if (trace_flag & trace_sets)
- print_derives ();
-
- free (dset);
- free (delts);
-}
-
-
-void
-derives_free (void)
-{
- free (derives[0]);
- free (derives);
-}
+/* Match rules with nonterminals for bison,
+
+ Copyright (C) 1984, 1989, 2000-2003, 2005, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "getargs.h"
+
+#include "derives.h"
+#include "gram.h"
+#include "reader.h"
+#include "symtab.h"
+
+/* Linked list of rule numbers. */
+typedef struct rule_list
+{
+ struct rule_list *next;
+ rule *value;
+} rule_list;
+
+rule ***derives;
+
+static void
+print_derives (void)
+{
+ int i;
+
+ fputs ("DERIVES\n", stderr);
+
+ for (i = ntokens; i < nsyms; i++)
+ {
+ rule **rp;
+ fprintf (stderr, " %s derives\n", symbols[i]->tag);
+ for (rp = derives[i - ntokens]; *rp; ++rp)
+ {
+ fprintf (stderr, " %3d ", (*rp)->user_number);
+ rule_rhs_print (*rp, stderr);
+ fprintf (stderr, "\n");
+ }
+ }
+
+ fputs ("\n\n", stderr);
+}
+
+
+void
+derives_compute (void)
+{
+ symbol_number i;
+ rule_number r;
+ rule **q;
+
+ /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
+ whose LHS is NTERM. */
+ rule_list **dset = xcalloc (nvars, sizeof *dset);
+
+ /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
+ Instead of performing NRULES allocations for each, have an array
+ indexed by rule numbers. */
+ rule_list *delts = xnmalloc (nrules, sizeof *delts);
+
+ for (r = nrules - 1; r >= 0; --r)
+ {
+ symbol_number lhs = rules[r].lhs->number;
+ rule_list *p = &delts[r];
+ /* A new LHS is found. */
+ p->next = dset[lhs - ntokens];
+ p->value = &rules[r];
+ dset[lhs - ntokens] = p;
+ }
+
+ /* DSET contains what we need under the form of a linked list. Make
+ it a single array. */
+
+ derives = xnmalloc (nvars, sizeof *derives);
+ q = xnmalloc (nvars + nrules, sizeof *q);
+
+ for (i = ntokens; i < nsyms; i++)
+ {
+ rule_list *p = dset[i - ntokens];
+ derives[i - ntokens] = q;
+ while (p)
+ {
+ *q++ = p->value;
+ p = p->next;
+ }
+ *q++ = NULL;
+ }
+
+ if (trace_flag & trace_sets)
+ print_derives ();
+
+ free (dset);
+ free (delts);
+}
+
+
+void
+derives_free (void)
+{
+ free (derives[0]);
+ free (derives);
+}
diff --git a/contrib/tools/bison/bison/src/derives.h b/contrib/tools/bison/bison/src/derives.h
index ea8dff7231..68b4213b1e 100644
--- a/contrib/tools/bison/bison/src/derives.h
+++ b/contrib/tools/bison/bison/src/derives.h
@@ -1,35 +1,35 @@
-/* Match rules with nonterminals for bison,
-
- Copyright (C) 1984, 1989, 2000-2002, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef DERIVES_H_
-# define DERIVES_H_
-
-# include "gram.h"
-
-/* DERIVES[SYMBOL - NTOKENS] points to a vector of the rules that
- SYMBOL derives, terminated with NULL. */
-extern rule ***derives;
-
-/* Compute DERIVES. */
-
-void derives_compute (void);
-void derives_free (void);
-
-#endif /* !DERIVES_H_ */
+/* Match rules with nonterminals for bison,
+
+ Copyright (C) 1984, 1989, 2000-2002, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef DERIVES_H_
+# define DERIVES_H_
+
+# include "gram.h"
+
+/* DERIVES[SYMBOL - NTOKENS] points to a vector of the rules that
+ SYMBOL derives, terminated with NULL. */
+extern rule ***derives;
+
+/* Compute DERIVES. */
+
+void derives_compute (void);
+void derives_free (void);
+
+#endif /* !DERIVES_H_ */
diff --git a/contrib/tools/bison/bison/src/files.c b/contrib/tools/bison/bison/src/files.c
index 3b219229bc..2cb276c8dc 100644
--- a/contrib/tools/bison/bison/src/files.c
+++ b/contrib/tools/bison/bison/src/files.c
@@ -1,420 +1,420 @@
-/* Open and close files for Bison.
-
- Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <error.h>
-#include <dirname.h>
-#include <get-errno.h>
-#include <quote.h>
-#include <quotearg.h>
-#include <stdio-safer.h>
-#include <xstrndup.h>
+/* Open and close files for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <error.h>
+#include <dirname.h>
+#include <get-errno.h>
+#include <quote.h>
+#include <quotearg.h>
+#include <stdio-safer.h>
+#include <xstrndup.h>
#include <stdlib.h>
#include <string.h>
-
-#include "complain.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-
-/* Initializing some values below (such SPEC_NAME_PREFIX to 'yy') is
- tempting, but don't do that: for the time being our handling of the
- %directive vs --option leaves precedence to the options by deciding
- that if a %directive sets a variable which is really set (i.e., not
- NULL), then the %directive is ignored. As a result, %name-prefix,
- for instance, will not be honored. */
-
-char const *spec_outfile = NULL; /* for -o. */
-char const *spec_file_prefix = NULL; /* for -b. */
-char const *spec_name_prefix = NULL; /* for -p. */
-char *spec_verbose_file = NULL; /* for --verbose. */
-char *spec_graph_file = NULL; /* for -g. */
-char *spec_xml_file = NULL; /* for -x. */
-char *spec_defines_file = NULL; /* for --defines. */
-char *parser_file_name;
-
-/* All computed output file names. */
-static char **file_names = NULL;
-static int file_names_count = 0;
-
-uniqstr grammar_file = NULL;
-uniqstr current_file = NULL;
-
-/* If --output=dir/foo.c was specified,
- DIR_PREFIX is 'dir/' and ALL_BUT_EXT and ALL_BUT_TAB_EXT are 'dir/foo'.
-
- If --output=dir/foo.tab.c was specified, DIR_PREFIX is 'dir/',
- ALL_BUT_EXT is 'dir/foo.tab', and ALL_BUT_TAB_EXT is 'dir/foo'.
-
- If --output was not specified but --file-prefix=dir/foo was specified,
- ALL_BUT_EXT = 'foo.tab' and ALL_BUT_TAB_EXT = 'foo'.
-
- If neither --output nor --file was specified but the input grammar
- is name dir/foo.y, ALL_BUT_EXT and ALL_BUT_TAB_EXT are 'foo'.
-
- If neither --output nor --file was specified, DIR_PREFIX is the
- empty string (meaning the current directory); otherwise it is
- 'dir/'. */
-
-char *all_but_ext;
-static char *all_but_tab_ext;
-char *dir_prefix;
-
-/* C source file extension (the parser source). */
-static char *src_extension = NULL;
-/* Header file extension (if option '`-d'' is specified). */
-static char *header_extension = NULL;
-
-/*-----------------------------------------------------------------.
-| Return a newly allocated string composed of the concatenation of |
-| STR1, and STR2. |
-`-----------------------------------------------------------------*/
-
+
+#include "complain.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+
+/* Initializing some values below (such SPEC_NAME_PREFIX to 'yy') is
+ tempting, but don't do that: for the time being our handling of the
+ %directive vs --option leaves precedence to the options by deciding
+ that if a %directive sets a variable which is really set (i.e., not
+ NULL), then the %directive is ignored. As a result, %name-prefix,
+ for instance, will not be honored. */
+
+char const *spec_outfile = NULL; /* for -o. */
+char const *spec_file_prefix = NULL; /* for -b. */
+char const *spec_name_prefix = NULL; /* for -p. */
+char *spec_verbose_file = NULL; /* for --verbose. */
+char *spec_graph_file = NULL; /* for -g. */
+char *spec_xml_file = NULL; /* for -x. */
+char *spec_defines_file = NULL; /* for --defines. */
+char *parser_file_name;
+
+/* All computed output file names. */
+static char **file_names = NULL;
+static int file_names_count = 0;
+
+uniqstr grammar_file = NULL;
+uniqstr current_file = NULL;
+
+/* If --output=dir/foo.c was specified,
+ DIR_PREFIX is 'dir/' and ALL_BUT_EXT and ALL_BUT_TAB_EXT are 'dir/foo'.
+
+ If --output=dir/foo.tab.c was specified, DIR_PREFIX is 'dir/',
+ ALL_BUT_EXT is 'dir/foo.tab', and ALL_BUT_TAB_EXT is 'dir/foo'.
+
+ If --output was not specified but --file-prefix=dir/foo was specified,
+ ALL_BUT_EXT = 'foo.tab' and ALL_BUT_TAB_EXT = 'foo'.
+
+ If neither --output nor --file was specified but the input grammar
+ is name dir/foo.y, ALL_BUT_EXT and ALL_BUT_TAB_EXT are 'foo'.
+
+ If neither --output nor --file was specified, DIR_PREFIX is the
+ empty string (meaning the current directory); otherwise it is
+ 'dir/'. */
+
+char *all_but_ext;
+static char *all_but_tab_ext;
+char *dir_prefix;
+
+/* C source file extension (the parser source). */
+static char *src_extension = NULL;
+/* Header file extension (if option '`-d'' is specified). */
+static char *header_extension = NULL;
+
+/*-----------------------------------------------------------------.
+| Return a newly allocated string composed of the concatenation of |
+| STR1, and STR2. |
+`-----------------------------------------------------------------*/
+
#if defined _win_ || defined _WIN64 || defined _WIN32 || defined __WIN32__
char *stpcpy(char *dst, const char *src);
#endif
-static char *
-concat2 (char const *str1, char const *str2)
-{
- size_t len = strlen (str1) + strlen (str2);
- char *res = xmalloc (len + 1);
- char *cp;
- cp = stpcpy (res, str1);
- cp = stpcpy (cp, str2);
- return res;
-}
-
-/*-----------------------------------------------------------------.
-| Try to open file NAME with mode MODE, and print an error message |
-| if fails. |
-`-----------------------------------------------------------------*/
-
-FILE *
-xfopen (const char *name, const char *mode)
-{
- FILE *ptr;
-
- ptr = fopen_safer (name, mode);
- if (!ptr)
- error (EXIT_FAILURE, get_errno (),
- _("%s: cannot open"), quotearg_colon (name));
-
- return ptr;
-}
-
-/*-------------------------------------------------------------.
-| Try to close file PTR, and print an error message if fails. |
-`-------------------------------------------------------------*/
-
-void
-xfclose (FILE *ptr)
-{
- if (ptr == NULL)
- return;
-
- if (ferror (ptr))
- error (EXIT_FAILURE, 0, _("input/output error"));
-
- if (fclose (ptr) != 0)
- error (EXIT_FAILURE, get_errno (), _("cannot close file"));
-}
-
-
-FILE *
-xfdopen (int fd, char const *mode)
-{
- FILE *res = fdopen (fd, mode);
- if (! res)
- error (EXIT_FAILURE, get_errno (),
- /* On a separate line to please the "unmarked_diagnostics"
- syntax-check. */
- "fdopen");
- return res;
-}
-
-/*------------------------------------------------------------------.
-| Compute ALL_BUT_EXT, ALL_BUT_TAB_EXT and output files extensions. |
-`------------------------------------------------------------------*/
-
-/* Compute extensions from the grammar file extension. */
-static void
-compute_exts_from_gf (const char *ext)
-{
- if (STREQ (ext, ".y"))
- {
- src_extension = xstrdup (language->src_extension);
- /* header_extension = xstrdup (language->header_extension); */
- header_extension = xstrdup(".h");
- }
- else
- {
- src_extension = xstrdup (ext);
- /*
- header_extension = xstrdup (ext);
- tr (src_extension, 'y', 'c');
- tr (src_extension, 'Y', 'C');
- tr (header_extension, 'y', 'h');
- tr (header_extension, 'Y', 'H');
- */
- header_extension = xstrdup(".h");
- }
-}
-
-/* Compute extensions from the given c source file extension. */
-static void
-compute_exts_from_src (const char *ext)
-{
- /* We use this function when the user specifies `-o' or `--output',
- so the extenions must be computed unconditionally from the file name
- given by this option. */
- src_extension = xstrdup (ext);
- /*
- header_extension = xstrdup (ext);
- tr (header_extension, 'c', 'h');
- tr (header_extension, 'C', 'H');
- */
- header_extension = xstrdup(".h");
-}
-
-
-/* Decompose FILE_NAME in four parts: *BASE, *TAB, and *EXT, the fourth
- part, (the directory) is ranging from FILE_NAME to the char before
- *BASE, so we don't need an additional parameter.
-
- *EXT points to the last period in the basename, or NULL if none.
-
- If there is no *EXT, *TAB is NULL. Otherwise, *TAB points to
- '.tab' or '_tab' if present right before *EXT, or is NULL. *TAB
- cannot be equal to *BASE.
-
- None are allocated, they are simply pointers to parts of FILE_NAME.
- Examples:
-
- '/tmp/foo.tab.c' -> *BASE = 'foo.tab.c', *TAB = '.tab.c', *EXT =
- '.c'
-
- 'foo.c' -> *BASE = 'foo.c', *TAB = NULL, *EXT = '.c'
-
- 'tab.c' -> *BASE = 'tab.c', *TAB = NULL, *EXT = '.c'
-
- '.tab.c' -> *BASE = '.tab.c', *TAB = NULL, *EXT = '.c'
-
- 'foo.tab' -> *BASE = 'foo.tab', *TAB = NULL, *EXT = '.tab'
-
- 'foo_tab' -> *BASE = 'foo_tab', *TAB = NULL, *EXT = NULL
-
- 'foo' -> *BASE = 'foo', *TAB = NULL, *EXT = NULL. */
-
-static void
-file_name_split (const char *file_name,
- const char **base, const char **tab, const char **ext)
-{
- *base = last_component (file_name);
-
- /* Look for the extension, i.e., look for the last dot. */
- *ext = strrchr (*base, '.');
- *tab = NULL;
-
- /* If there is an extension, check if there is a '.tab' part right
- before. */
- if (*ext)
- {
- size_t baselen = *ext - *base;
- size_t dottablen = sizeof (TAB_EXT) - 1;
- if (dottablen < baselen
- && STRPREFIX_LIT (TAB_EXT, *ext - dottablen))
- *tab = *ext - dottablen;
- }
-}
-
-
-static void
-compute_file_name_parts (void)
-{
- const char *base, *tab, *ext;
-
- /* Compute ALL_BUT_EXT and ALL_BUT_TAB_EXT from SPEC_OUTFILE
- or GRAMMAR_FILE.
-
- The precise -o name will be used for FTABLE. For other output
- files, remove the ".c" or ".tab.c" suffix. */
- if (spec_outfile)
- {
- file_name_split (spec_outfile, &base, &tab, &ext);
- dir_prefix = xstrndup (spec_outfile, base - spec_outfile);
-
- /* ALL_BUT_EXT goes up the EXT, excluding it. */
- all_but_ext =
- xstrndup (spec_outfile,
- (strlen (spec_outfile) - (ext ? strlen (ext) : 0)));
-
- /* ALL_BUT_TAB_EXT goes up to TAB, excluding it. */
- all_but_tab_ext =
- xstrndup (spec_outfile,
- (strlen (spec_outfile)
- - (tab ? strlen (tab) : (ext ? strlen (ext) : 0))));
-
- if (ext)
- compute_exts_from_src (ext);
- }
- else
- {
- file_name_split (grammar_file, &base, &tab, &ext);
-
- if (spec_file_prefix)
- {
- /* If --file-prefix=foo was specified, ALL_BUT_TAB_EXT = 'foo'. */
- dir_prefix =
- xstrndup (spec_file_prefix,
- last_component (spec_file_prefix) - spec_file_prefix);
- all_but_tab_ext = xstrdup (spec_file_prefix);
- }
- else if (yacc_flag)
- {
- /* If --yacc, then the output is 'y.tab.c'. */
- dir_prefix = xstrdup ("");
- all_but_tab_ext = xstrdup ("y");
- }
- else
- {
- /* Otherwise, ALL_BUT_TAB_EXT is computed from the input
- grammar: 'foo/bar.yy' => 'bar'. */
- dir_prefix = xstrdup ("");
- all_but_tab_ext =
- xstrndup (base, (strlen (base) - (ext ? strlen (ext) : 0)));
- }
-
- if (language->add_tab)
- all_but_ext = concat2 (all_but_tab_ext, TAB_EXT);
- else
- all_but_ext = xstrdup (all_but_tab_ext);
-
- /* Compute the extensions from the grammar file name. */
- if (ext && !yacc_flag)
- compute_exts_from_gf (ext);
- }
-}
-
-
-/* Compute the output file names. Warn if we detect conflicting
- outputs to the same file. */
-
-void
-compute_output_file_names (void)
-{
- compute_file_name_parts ();
-
- /* If not yet done. */
- if (!src_extension)
- src_extension = xstrdup (".c");
- if (!header_extension)
- header_extension = xstrdup (".h");
-
- parser_file_name =
- (spec_outfile
- ? xstrdup (spec_outfile)
- : concat2 (all_but_ext, src_extension));
-
- if (defines_flag)
- {
- if (! spec_defines_file)
- spec_defines_file = concat2 (all_but_ext, header_extension);
- }
-
- if (graph_flag)
- {
- if (! spec_graph_file)
- spec_graph_file = concat2 (all_but_tab_ext, ".dot");
- output_file_name_check (&spec_graph_file);
- }
-
- if (xml_flag)
- {
- if (! spec_xml_file)
- spec_xml_file = concat2 (all_but_tab_ext, ".xml");
- output_file_name_check (&spec_xml_file);
- }
-
- if (report_flag)
- {
- if (!spec_verbose_file)
- spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT);
- output_file_name_check (&spec_verbose_file);
- }
-
- free (all_but_tab_ext);
- free (src_extension);
- free (header_extension);
-}
-
-void
-output_file_name_check (char **file_name)
-{
- bool conflict = false;
- if (STREQ (*file_name, grammar_file))
- {
- complain (NULL, complaint, _("refusing to overwrite the input file %s"),
- quote (*file_name));
- conflict = true;
- }
- else
- {
- int i;
- for (i = 0; i < file_names_count; i++)
- if (STREQ (file_names[i], *file_name))
- {
- complain (NULL, Wother, _("conflicting outputs to file %s"),
- quote (*file_name));
- conflict = true;
- }
- }
- if (conflict)
- {
- free (*file_name);
- *file_name = strdup ("/dev/null");
- }
- else
- {
- file_names = xnrealloc (file_names, ++file_names_count,
- sizeof *file_names);
- file_names[file_names_count-1] = xstrdup (*file_name);
- }
-}
-
-void
-output_file_names_free (void)
-{
- free (all_but_ext);
- free (spec_verbose_file);
- free (spec_graph_file);
- free (spec_xml_file);
- free (spec_defines_file);
- free (parser_file_name);
- free (dir_prefix);
- {
- int i;
- for (i = 0; i < file_names_count; i++)
- free (file_names[i]);
- }
- free (file_names);
-}
+static char *
+concat2 (char const *str1, char const *str2)
+{
+ size_t len = strlen (str1) + strlen (str2);
+ char *res = xmalloc (len + 1);
+ char *cp;
+ cp = stpcpy (res, str1);
+ cp = stpcpy (cp, str2);
+ return res;
+}
+
+/*-----------------------------------------------------------------.
+| Try to open file NAME with mode MODE, and print an error message |
+| if fails. |
+`-----------------------------------------------------------------*/
+
+FILE *
+xfopen (const char *name, const char *mode)
+{
+ FILE *ptr;
+
+ ptr = fopen_safer (name, mode);
+ if (!ptr)
+ error (EXIT_FAILURE, get_errno (),
+ _("%s: cannot open"), quotearg_colon (name));
+
+ return ptr;
+}
+
+/*-------------------------------------------------------------.
+| Try to close file PTR, and print an error message if fails. |
+`-------------------------------------------------------------*/
+
+void
+xfclose (FILE *ptr)
+{
+ if (ptr == NULL)
+ return;
+
+ if (ferror (ptr))
+ error (EXIT_FAILURE, 0, _("input/output error"));
+
+ if (fclose (ptr) != 0)
+ error (EXIT_FAILURE, get_errno (), _("cannot close file"));
+}
+
+
+FILE *
+xfdopen (int fd, char const *mode)
+{
+ FILE *res = fdopen (fd, mode);
+ if (! res)
+ error (EXIT_FAILURE, get_errno (),
+ /* On a separate line to please the "unmarked_diagnostics"
+ syntax-check. */
+ "fdopen");
+ return res;
+}
+
+/*------------------------------------------------------------------.
+| Compute ALL_BUT_EXT, ALL_BUT_TAB_EXT and output files extensions. |
+`------------------------------------------------------------------*/
+
+/* Compute extensions from the grammar file extension. */
+static void
+compute_exts_from_gf (const char *ext)
+{
+ if (STREQ (ext, ".y"))
+ {
+ src_extension = xstrdup (language->src_extension);
+ /* header_extension = xstrdup (language->header_extension); */
+ header_extension = xstrdup(".h");
+ }
+ else
+ {
+ src_extension = xstrdup (ext);
+ /*
+ header_extension = xstrdup (ext);
+ tr (src_extension, 'y', 'c');
+ tr (src_extension, 'Y', 'C');
+ tr (header_extension, 'y', 'h');
+ tr (header_extension, 'Y', 'H');
+ */
+ header_extension = xstrdup(".h");
+ }
+}
+
+/* Compute extensions from the given c source file extension. */
+static void
+compute_exts_from_src (const char *ext)
+{
+ /* We use this function when the user specifies `-o' or `--output',
+ so the extenions must be computed unconditionally from the file name
+ given by this option. */
+ src_extension = xstrdup (ext);
+ /*
+ header_extension = xstrdup (ext);
+ tr (header_extension, 'c', 'h');
+ tr (header_extension, 'C', 'H');
+ */
+ header_extension = xstrdup(".h");
+}
+
+
+/* Decompose FILE_NAME in four parts: *BASE, *TAB, and *EXT, the fourth
+ part, (the directory) is ranging from FILE_NAME to the char before
+ *BASE, so we don't need an additional parameter.
+
+ *EXT points to the last period in the basename, or NULL if none.
+
+ If there is no *EXT, *TAB is NULL. Otherwise, *TAB points to
+ '.tab' or '_tab' if present right before *EXT, or is NULL. *TAB
+ cannot be equal to *BASE.
+
+ None are allocated, they are simply pointers to parts of FILE_NAME.
+ Examples:
+
+ '/tmp/foo.tab.c' -> *BASE = 'foo.tab.c', *TAB = '.tab.c', *EXT =
+ '.c'
+
+ 'foo.c' -> *BASE = 'foo.c', *TAB = NULL, *EXT = '.c'
+
+ 'tab.c' -> *BASE = 'tab.c', *TAB = NULL, *EXT = '.c'
+
+ '.tab.c' -> *BASE = '.tab.c', *TAB = NULL, *EXT = '.c'
+
+ 'foo.tab' -> *BASE = 'foo.tab', *TAB = NULL, *EXT = '.tab'
+
+ 'foo_tab' -> *BASE = 'foo_tab', *TAB = NULL, *EXT = NULL
+
+ 'foo' -> *BASE = 'foo', *TAB = NULL, *EXT = NULL. */
+
+static void
+file_name_split (const char *file_name,
+ const char **base, const char **tab, const char **ext)
+{
+ *base = last_component (file_name);
+
+ /* Look for the extension, i.e., look for the last dot. */
+ *ext = strrchr (*base, '.');
+ *tab = NULL;
+
+ /* If there is an extension, check if there is a '.tab' part right
+ before. */
+ if (*ext)
+ {
+ size_t baselen = *ext - *base;
+ size_t dottablen = sizeof (TAB_EXT) - 1;
+ if (dottablen < baselen
+ && STRPREFIX_LIT (TAB_EXT, *ext - dottablen))
+ *tab = *ext - dottablen;
+ }
+}
+
+
+static void
+compute_file_name_parts (void)
+{
+ const char *base, *tab, *ext;
+
+ /* Compute ALL_BUT_EXT and ALL_BUT_TAB_EXT from SPEC_OUTFILE
+ or GRAMMAR_FILE.
+
+ The precise -o name will be used for FTABLE. For other output
+ files, remove the ".c" or ".tab.c" suffix. */
+ if (spec_outfile)
+ {
+ file_name_split (spec_outfile, &base, &tab, &ext);
+ dir_prefix = xstrndup (spec_outfile, base - spec_outfile);
+
+ /* ALL_BUT_EXT goes up the EXT, excluding it. */
+ all_but_ext =
+ xstrndup (spec_outfile,
+ (strlen (spec_outfile) - (ext ? strlen (ext) : 0)));
+
+ /* ALL_BUT_TAB_EXT goes up to TAB, excluding it. */
+ all_but_tab_ext =
+ xstrndup (spec_outfile,
+ (strlen (spec_outfile)
+ - (tab ? strlen (tab) : (ext ? strlen (ext) : 0))));
+
+ if (ext)
+ compute_exts_from_src (ext);
+ }
+ else
+ {
+ file_name_split (grammar_file, &base, &tab, &ext);
+
+ if (spec_file_prefix)
+ {
+ /* If --file-prefix=foo was specified, ALL_BUT_TAB_EXT = 'foo'. */
+ dir_prefix =
+ xstrndup (spec_file_prefix,
+ last_component (spec_file_prefix) - spec_file_prefix);
+ all_but_tab_ext = xstrdup (spec_file_prefix);
+ }
+ else if (yacc_flag)
+ {
+ /* If --yacc, then the output is 'y.tab.c'. */
+ dir_prefix = xstrdup ("");
+ all_but_tab_ext = xstrdup ("y");
+ }
+ else
+ {
+ /* Otherwise, ALL_BUT_TAB_EXT is computed from the input
+ grammar: 'foo/bar.yy' => 'bar'. */
+ dir_prefix = xstrdup ("");
+ all_but_tab_ext =
+ xstrndup (base, (strlen (base) - (ext ? strlen (ext) : 0)));
+ }
+
+ if (language->add_tab)
+ all_but_ext = concat2 (all_but_tab_ext, TAB_EXT);
+ else
+ all_but_ext = xstrdup (all_but_tab_ext);
+
+ /* Compute the extensions from the grammar file name. */
+ if (ext && !yacc_flag)
+ compute_exts_from_gf (ext);
+ }
+}
+
+
+/* Compute the output file names. Warn if we detect conflicting
+ outputs to the same file. */
+
+void
+compute_output_file_names (void)
+{
+ compute_file_name_parts ();
+
+ /* If not yet done. */
+ if (!src_extension)
+ src_extension = xstrdup (".c");
+ if (!header_extension)
+ header_extension = xstrdup (".h");
+
+ parser_file_name =
+ (spec_outfile
+ ? xstrdup (spec_outfile)
+ : concat2 (all_but_ext, src_extension));
+
+ if (defines_flag)
+ {
+ if (! spec_defines_file)
+ spec_defines_file = concat2 (all_but_ext, header_extension);
+ }
+
+ if (graph_flag)
+ {
+ if (! spec_graph_file)
+ spec_graph_file = concat2 (all_but_tab_ext, ".dot");
+ output_file_name_check (&spec_graph_file);
+ }
+
+ if (xml_flag)
+ {
+ if (! spec_xml_file)
+ spec_xml_file = concat2 (all_but_tab_ext, ".xml");
+ output_file_name_check (&spec_xml_file);
+ }
+
+ if (report_flag)
+ {
+ if (!spec_verbose_file)
+ spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT);
+ output_file_name_check (&spec_verbose_file);
+ }
+
+ free (all_but_tab_ext);
+ free (src_extension);
+ free (header_extension);
+}
+
+void
+output_file_name_check (char **file_name)
+{
+ bool conflict = false;
+ if (STREQ (*file_name, grammar_file))
+ {
+ complain (NULL, complaint, _("refusing to overwrite the input file %s"),
+ quote (*file_name));
+ conflict = true;
+ }
+ else
+ {
+ int i;
+ for (i = 0; i < file_names_count; i++)
+ if (STREQ (file_names[i], *file_name))
+ {
+ complain (NULL, Wother, _("conflicting outputs to file %s"),
+ quote (*file_name));
+ conflict = true;
+ }
+ }
+ if (conflict)
+ {
+ free (*file_name);
+ *file_name = strdup ("/dev/null");
+ }
+ else
+ {
+ file_names = xnrealloc (file_names, ++file_names_count,
+ sizeof *file_names);
+ file_names[file_names_count-1] = xstrdup (*file_name);
+ }
+}
+
+void
+output_file_names_free (void)
+{
+ free (all_but_ext);
+ free (spec_verbose_file);
+ free (spec_graph_file);
+ free (spec_xml_file);
+ free (spec_defines_file);
+ free (parser_file_name);
+ free (dir_prefix);
+ {
+ int i;
+ for (i = 0; i < file_names_count; i++)
+ free (file_names[i]);
+ }
+ free (file_names);
+}
diff --git a/contrib/tools/bison/bison/src/files.h b/contrib/tools/bison/bison/src/files.h
index ebe5037c7a..1740de81d9 100644
--- a/contrib/tools/bison/bison/src/files.h
+++ b/contrib/tools/bison/bison/src/files.h
@@ -1,72 +1,72 @@
-/* File names and variables for bison,
-
- Copyright (C) 1984, 1989, 2000-2002, 2006-2007, 2009-2013 Free
- Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef FILES_H_
-# define FILES_H_
-
-# include "uniqstr.h"
-
-/* File name specified with -o for the output file, or 0 if no -o. */
-extern char const *spec_outfile;
-
-/* File name for the parser (i.e., the one above, or its default.) */
-extern char *parser_file_name;
-
-/* Symbol prefix specified with -p, or 0 if no -p. */
-extern const char *spec_name_prefix;
-
-/* File name prefix specified with -b, or 0 if no -b. */
-extern char const *spec_file_prefix;
-
-/* --verbose. */
-extern char *spec_verbose_file;
-
-/* File name specified for the output graph. */
-extern char *spec_graph_file;
-
-/* File name specified for the xml output. */
-extern char *spec_xml_file;
-
-/* File name specified with --defines. */
-extern char *spec_defines_file;
-
-/* Directory prefix of output file names. */
-extern char *dir_prefix;
-
-/* The file name as given on the command line.
- Not named "input_file" because Flex uses this name for an argument,
- and therefore GCC warns about a name clash. */
-extern uniqstr grammar_file;
-
-/* The current file name. Might change with %include, or with #line. */
-extern uniqstr current_file;
-
-/* The computed base for output file names. */
-extern char *all_but_ext;
-
-void compute_output_file_names (void);
-void output_file_names_free (void);
-void output_file_name_check (char **file_name);
-
-FILE *xfopen (const char *name, char const *mode);
-void xfclose (FILE *ptr);
-FILE *xfdopen (int fd, char const *mode);
-
-#endif /* !FILES_H_ */
+/* File names and variables for bison,
+
+ Copyright (C) 1984, 1989, 2000-2002, 2006-2007, 2009-2013 Free
+ Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef FILES_H_
+# define FILES_H_
+
+# include "uniqstr.h"
+
+/* File name specified with -o for the output file, or 0 if no -o. */
+extern char const *spec_outfile;
+
+/* File name for the parser (i.e., the one above, or its default.) */
+extern char *parser_file_name;
+
+/* Symbol prefix specified with -p, or 0 if no -p. */
+extern const char *spec_name_prefix;
+
+/* File name prefix specified with -b, or 0 if no -b. */
+extern char const *spec_file_prefix;
+
+/* --verbose. */
+extern char *spec_verbose_file;
+
+/* File name specified for the output graph. */
+extern char *spec_graph_file;
+
+/* File name specified for the xml output. */
+extern char *spec_xml_file;
+
+/* File name specified with --defines. */
+extern char *spec_defines_file;
+
+/* Directory prefix of output file names. */
+extern char *dir_prefix;
+
+/* The file name as given on the command line.
+ Not named "input_file" because Flex uses this name for an argument,
+ and therefore GCC warns about a name clash. */
+extern uniqstr grammar_file;
+
+/* The current file name. Might change with %include, or with #line. */
+extern uniqstr current_file;
+
+/* The computed base for output file names. */
+extern char *all_but_ext;
+
+void compute_output_file_names (void);
+void output_file_names_free (void);
+void output_file_name_check (char **file_name);
+
+FILE *xfopen (const char *name, char const *mode);
+void xfclose (FILE *ptr);
+FILE *xfdopen (int fd, char const *mode);
+
+#endif /* !FILES_H_ */
diff --git a/contrib/tools/bison/bison/src/flex-scanner.h b/contrib/tools/bison/bison/src/flex-scanner.h
index 03c9ec64fd..d928747526 100644
--- a/contrib/tools/bison/bison/src/flex-scanner.h
+++ b/contrib/tools/bison/bison/src/flex-scanner.h
@@ -1,90 +1,90 @@
-/* Common parts between scan-code.l, scan-gram.l, and scan-skel.l.
-
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef FLEX_PREFIX
-# error "FLEX_PREFIX not defined"
-#endif
-
-#include <obstack.h>
-
-/* Flex full version as a number. */
-#define FLEX_VERSION \
- ((YY_FLEX_MAJOR_VERSION) * 1000000 \
- + (YY_FLEX_MINOR_VERSION) * 1000 \
- + (YY_FLEX_SUBMINOR_VERSION))
-
-/* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */
-#if FLEX_VERSION <= 2005031
-int FLEX_PREFIX (get_lineno) (void);
-FILE *FLEX_PREFIX (get_in) (void);
-FILE *FLEX_PREFIX (get_out) (void);
-int FLEX_PREFIX (get_leng) (void);
-char *FLEX_PREFIX (get_text) (void);
-void FLEX_PREFIX (set_lineno) (int);
-void FLEX_PREFIX (set_in) (FILE *);
-void FLEX_PREFIX (set_out) (FILE *);
-int FLEX_PREFIX (get_debug) (void);
-void FLEX_PREFIX (set_debug) (int);
-int FLEX_PREFIX (lex_destroy) (void);
-#endif
-
-#define last_string FLEX_PREFIX (last_string)
-
-/* It seems to be a nice "feature" of Flex that one cannot use yytext,
- yyleng etc. when a prefix is given, since there is no longer a
- #define, but rather the token is actually changed in the output.
- However, this is not true for Flex 2.5.4. */
-#ifndef yyleng
-# define yyleng FLEX_PREFIX (leng)
-#endif
-#ifndef yytext
-# define yytext FLEX_PREFIX (text)
-#endif
-
-/* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier
- versions according to the Flex manual) leak memory if yylex_destroy is not
- invoked. However, yylex_destroy is not defined before Flex 2.5.9, so give
- an implementation here that at least appears to work with Flex 2.5.4. */
-#if FLEX_VERSION <= 2005009
-# define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER)
-#endif
-
-/* OBSTACK_FOR_STRING -- Used to store all the characters that we need to
- keep (to construct ID, STRINGS etc.). Use the following macros to
- use it.
-
- Use STRING_GROW to append what has just been matched, and
- STRING_FINISH to end the string (it puts the ending 0).
- STRING_FINISH also stores this string in LAST_STRING, which can be
- used, and which is used by STRING_FREE to free the last string. */
-
-#ifndef FLEX_NO_OBSTACK
-
-static struct obstack obstack_for_string;
-
-# define STRING_GROW \
- obstack_grow (&obstack_for_string, yytext, yyleng)
-
-# define STRING_FINISH \
- (last_string = obstack_finish0 (&obstack_for_string))
-
-# define STRING_FREE \
- obstack_free (&obstack_for_string, last_string)
-
-#endif
+/* Common parts between scan-code.l, scan-gram.l, and scan-skel.l.
+
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef FLEX_PREFIX
+# error "FLEX_PREFIX not defined"
+#endif
+
+#include <obstack.h>
+
+/* Flex full version as a number. */
+#define FLEX_VERSION \
+ ((YY_FLEX_MAJOR_VERSION) * 1000000 \
+ + (YY_FLEX_MINOR_VERSION) * 1000 \
+ + (YY_FLEX_SUBMINOR_VERSION))
+
+/* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */
+#if FLEX_VERSION <= 2005031
+int FLEX_PREFIX (get_lineno) (void);
+FILE *FLEX_PREFIX (get_in) (void);
+FILE *FLEX_PREFIX (get_out) (void);
+int FLEX_PREFIX (get_leng) (void);
+char *FLEX_PREFIX (get_text) (void);
+void FLEX_PREFIX (set_lineno) (int);
+void FLEX_PREFIX (set_in) (FILE *);
+void FLEX_PREFIX (set_out) (FILE *);
+int FLEX_PREFIX (get_debug) (void);
+void FLEX_PREFIX (set_debug) (int);
+int FLEX_PREFIX (lex_destroy) (void);
+#endif
+
+#define last_string FLEX_PREFIX (last_string)
+
+/* It seems to be a nice "feature" of Flex that one cannot use yytext,
+ yyleng etc. when a prefix is given, since there is no longer a
+ #define, but rather the token is actually changed in the output.
+ However, this is not true for Flex 2.5.4. */
+#ifndef yyleng
+# define yyleng FLEX_PREFIX (leng)
+#endif
+#ifndef yytext
+# define yytext FLEX_PREFIX (text)
+#endif
+
+/* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier
+ versions according to the Flex manual) leak memory if yylex_destroy is not
+ invoked. However, yylex_destroy is not defined before Flex 2.5.9, so give
+ an implementation here that at least appears to work with Flex 2.5.4. */
+#if FLEX_VERSION <= 2005009
+# define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER)
+#endif
+
+/* OBSTACK_FOR_STRING -- Used to store all the characters that we need to
+ keep (to construct ID, STRINGS etc.). Use the following macros to
+ use it.
+
+ Use STRING_GROW to append what has just been matched, and
+ STRING_FINISH to end the string (it puts the ending 0).
+ STRING_FINISH also stores this string in LAST_STRING, which can be
+ used, and which is used by STRING_FREE to free the last string. */
+
+#ifndef FLEX_NO_OBSTACK
+
+static struct obstack obstack_for_string;
+
+# define STRING_GROW \
+ obstack_grow (&obstack_for_string, yytext, yyleng)
+
+# define STRING_FINISH \
+ (last_string = obstack_finish0 (&obstack_for_string))
+
+# define STRING_FREE \
+ obstack_free (&obstack_for_string, last_string)
+
+#endif
diff --git a/contrib/tools/bison/bison/src/getargs.c b/contrib/tools/bison/bison/src/getargs.c
index d63bc7f9f5..fdfcf6d88a 100644
--- a/contrib/tools/bison/bison/src/getargs.c
+++ b/contrib/tools/bison/bison/src/getargs.c
@@ -1,741 +1,741 @@
-/* Parse command line arguments for Bison.
-
- Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-#include "output.h"
-
-#include <argmatch.h>
-#include <c-strcase.h>
-#include <configmake.h>
-#include <error.h>
-#include <getopt.h>
-#include <progname.h>
-
-#include "complain.h"
-#include "files.h"
-#include "getargs.h"
-#include "muscle-tab.h"
-#include "quote.h"
-#include "uniqstr.h"
-
-bool defines_flag;
-bool graph_flag;
-bool xml_flag;
-bool no_lines_flag;
-bool token_table_flag;
-bool yacc_flag; /* for -y */
-
-bool nondeterministic_parser = false;
-bool glr_parser = false;
-
-int feature_flag = feature_caret;
-int report_flag = report_none;
-int trace_flag = trace_none;
-
-static struct bison_language const valid_languages[] = {
- { "c", "c-skel.m4", ".c", ".h", true },
- { "c++", "c++-skel.m4", ".cc", ".hh", true },
- { "java", "java-skel.m4", ".java", ".java", false },
- { "", "", "", "", false }
-};
-
-int skeleton_prio = default_prio;
-const char *skeleton = NULL;
-int language_prio = default_prio;
-struct bison_language const *language = &valid_languages[0];
-
-const char* m4_path = NULL;
-
-/** Decode an option's key.
- *
- * \param option option being decoded.
- * \param keys array of valid subarguments.
- * \param values array of corresponding (int) values.
- * \param all the all value.
- * \param flags the flags to update
- * \param arg the subarguments to decode.
- * If null, then activate all the flags.
- * \param no length of the potential "no-" prefix.
- * Can be 0 or 3. If 3, negate the action of the subargument.
- *
- * If VALUE != 0 then KEY sets flags and no-KEY clears them.
- * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
- * flags from \c all. Thus no-none = all and no-all = none.
- */
-static void
-flag_argmatch (const char *option,
- const char * const keys[], const int values[],
- int all, int *flags, char *arg, size_t no)
-{
- int value = XARGMATCH (option, arg + no, keys, values);
-
- /* -rnone == -rno-all, and -rno-none == -rall. */
- if (!value)
- {
- value = all;
- no = !no;
- }
-
- if (no)
- *flags &= ~value;
- else
- *flags |= value;
-}
-
-/** Decode an option's set of keys.
- *
- * \param option option being decoded.
- * \param keys array of valid subarguments.
- * \param values array of corresponding (int) values.
- * \param all the all value.
- * \param flags the flags to update
- * \param args comma separated list of effective subarguments to decode.
- * If 0, then activate all the flags.
- */
-static void
-flags_argmatch (const char *option,
- const char * const keys[], const int values[],
- int all, int *flags, char *args)
-{
- if (args)
- for (args = strtok (args, ","); args; args = strtok (NULL, ","))
- {
- size_t no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
- flag_argmatch (option, keys,
- values, all, flags, args, no);
- }
- else
- *flags |= all;
-}
-
-
-/** Decode a set of sub arguments.
- *
- * \param FlagName the flag familly to update.
- * \param Args the effective sub arguments to decode.
- * \param All the "all" value.
- *
- * \arg FlagName_args the list of keys.
- * \arg FlagName_types the list of values.
- * \arg FlagName_flag the flag to update.
- */
-#define FLAGS_ARGMATCH(FlagName, Args, All) \
- flags_argmatch ("--" #FlagName, FlagName ## _args, FlagName ## _types, \
- All, &FlagName ## _flag, Args)
-
-
-/*----------------------.
-| --report's handling. |
-`----------------------*/
-
-static const char * const report_args[] =
-{
- /* In a series of synonyms, present the most meaningful first, so
- that argmatch_valid be more readable. */
- "none",
- "state", "states",
- "itemset", "itemsets",
- "lookahead", "lookaheads", "look-ahead",
- "solved",
- "all",
- 0
-};
-
-static const int report_types[] =
-{
- report_none,
- report_states, report_states,
- report_states | report_itemsets, report_states | report_itemsets,
- report_states | report_lookahead_tokens,
- report_states | report_lookahead_tokens,
- report_states | report_lookahead_tokens,
- report_states | report_solved_conflicts,
- report_all
-};
-
-ARGMATCH_VERIFY (report_args, report_types);
-
-
-/*---------------------.
-| --trace's handling. |
-`---------------------*/
-
-static const char * const trace_args[] =
-{
- "none - no traces",
- "scan - grammar scanner traces",
- "parse - grammar parser traces",
- "automaton - construction of the automaton",
- "bitsets - use of bitsets",
- "grammar - reading, reducing the grammar",
- "resource - memory consumption (where available)",
- "sets - grammar sets: firsts, nullable etc.",
- "muscles - m4 definitions passed to the skeleton",
- "tools - m4 invocation",
- "m4 - m4 traces",
- "skeleton - skeleton postprocessing",
- "time - time consumption",
- "ielr - IELR conversion",
- "all - all of the above",
- 0
-};
-
-static const int trace_types[] =
-{
- trace_none,
- trace_scan,
- trace_parse,
- trace_automaton,
- trace_bitsets,
- trace_grammar,
- trace_resource,
- trace_sets,
- trace_muscles,
- trace_tools,
- trace_m4,
- trace_skeleton,
- trace_time,
- trace_ielr,
- trace_all
-};
-
-ARGMATCH_VERIFY (trace_args, trace_types);
-
-
-/*-----------------------.
-| --feature's handling. |
-`-----------------------*/
-
-static const char * const feature_args[] =
-{
- "none",
- "caret", "diagnostics-show-caret",
- "all",
- 0
-};
-
-static const int feature_types[] =
-{
- feature_none,
- feature_caret, feature_caret,
- feature_all
-};
-
-ARGMATCH_VERIFY (feature_args, feature_types);
-
-/*-------------------------------------------.
-| Display the help message and exit STATUS. |
-`-------------------------------------------*/
-
-static void usage (int) ATTRIBUTE_NORETURN;
-
-static void
-usage (int status)
-{
- if (status != 0)
- fprintf (stderr, _("Try '%s --help' for more information.\n"),
- program_name);
- else
- {
- /* For ../build-aux/cross-options.pl to work, use the format:
- ^ -S, --long[=ARGS] (whitespace)
- A --long option is required.
- Otherwise, add exceptions to ../build-aux/cross-options.pl. */
-
- printf (_("Usage: %s [OPTION]... FILE\n"), program_name);
- fputs (_("\
-Generate a deterministic LR or generalized LR (GLR) parser employing\n\
-LALR(1), IELR(1), or canonical LR(1) parser tables. IELR(1) and\n\
-canonical LR(1) support is experimental.\n\
-\n\
-"), stdout);
-
- fputs (_("\
-Mandatory arguments to long options are mandatory for short options too.\n\
-"), stdout);
- fputs (_("\
-The same is true for optional arguments.\n\
-"), stdout);
-
- fputs (_("\
-\n\
-Operation modes:\n\
- -h, --help display this help and exit\n\
- -V, --version output version information and exit\n\
- --print-localedir output directory containing locale-dependent data\n\
- --print-datadir output directory containing skeletons and XSLT\n\
- -y, --yacc emulate POSIX Yacc\n\
- -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\
- -f, --feature[=FEATURE] activate miscellaneous features\n\
-\n\
-"), stdout);
-
- fputs (_("\
-Parser:\n\
- -L, --language=LANGUAGE specify the output programming language\n\
- -S, --skeleton=FILE specify the skeleton to use\n\
- -t, --debug instrument the parser for tracing\n\
- same as '-Dparse.trace'\n\
- --locations enable location support\n\
- -D, --define=NAME[=VALUE] similar to '%define NAME \"VALUE\"'\n\
- -F, --force-define=NAME[=VALUE] override '%define NAME \"VALUE\"'\n\
- -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
- deprecated by '-Dapi.prefix=PREFIX'\n\
- -l, --no-lines don't generate '#line' directives\n\
- -k, --token-table include a table of token names\n\
-"), stdout);
- putc ('\n', stdout);
-
- /* Keep -d and --defines separate so that ../build-aux/cross-options.pl
- * won't assume that -d also takes an argument. */
- fputs (_("\
-Output:\n\
- --defines[=FILE] also produce a header file\n\
- -d likewise but cannot specify FILE (for POSIX Yacc)\n\
- -r, --report=THINGS also produce details on the automaton\n\
- --report-file=FILE write report to FILE\n\
- -v, --verbose same as '--report=state'\n\
- -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
- -o, --output=FILE leave output to FILE\n\
- -g, --graph[=FILE] also output a graph of the automaton\n\
- -x, --xml[=FILE] also output an XML report of the automaton\n\
- (the XML schema is experimental)\n\
-"), stdout);
- putc ('\n', stdout);
-
- fputs (_("\
-Warning categories include:\n\
- 'midrule-values' unset or unused midrule values\n\
- 'yacc' incompatibilities with POSIX Yacc\n\
- 'conflicts-sr' S/R conflicts (enabled by default)\n\
- 'conflicts-rr' R/R conflicts (enabled by default)\n\
- 'deprecated' obsolete constructs\n\
- 'empty-rule' empty rules without %empty\n\
- 'precedence' useless precedence and associativity\n\
- 'other' all other warnings (enabled by default)\n\
- 'all' all the warnings except 'yacc'\n\
- 'no-CATEGORY' turn off warnings in CATEGORY\n\
- 'none' turn off all the warnings\n\
- 'error[=CATEGORY]' treat warnings as errors\n\
-"), stdout);
- putc ('\n', stdout);
-
- fputs (_("\
-THINGS is a list of comma separated words that can include:\n\
- 'state' describe the states\n\
- 'itemset' complete the core item sets with their closure\n\
- 'lookahead' explicitly associate lookahead tokens to items\n\
- 'solved' describe shift/reduce conflicts solving\n\
- 'all' include all the above information\n\
- 'none' disable the report\n\
-"), stdout);
- putc ('\n', stdout);
-
- fputs (_("\
-FEATURE is a list of comma separated words that can include:\n\
- 'caret' show errors with carets\n\
- 'all' all of the above\n\
- 'none' disable all of the above\n\
- "), stdout);
-
- putc ('\n', stdout);
- printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
- printf (_("%s home page: <%s>.\n"), PACKAGE_NAME, PACKAGE_URL);
- fputs (_("General help using GNU software: "
- "<http://www.gnu.org/gethelp/>.\n"),
- stdout);
- /* Don't output this redundant message for English locales.
- Note we still output for 'C' so that it gets included in the
- man page. */
- fputs (_("For complete documentation, run: info bison.\n"), stdout);
- }
-
- exit (status);
-}
-
-
-/*------------------------------.
-| Display the version message. |
-`------------------------------*/
-
-static void
-version (void)
-{
- /* Some efforts were made to ease the translators' task, please
- continue. */
- printf (_("bison (GNU Bison) %s"), VERSION);
- putc ('\n', stdout);
- fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout);
- putc ('\n', stdout);
-
- fprintf (stdout,
- _("Copyright (C) %d Free Software Foundation, Inc.\n"),
- 2013);
-
- fputs (_("\
-This is free software; see the source for copying conditions. There is NO\n\
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"),
- stdout);
-}
-
-
-/*-------------------------------------.
-| --skeleton and --language handling. |
-`--------------------------------------*/
-
-void
-skeleton_arg (char const *arg, int prio, location loc)
-{
- if (prio < skeleton_prio)
- {
- skeleton_prio = prio;
- skeleton = arg;
- }
- else if (prio == skeleton_prio)
- complain (&loc, complaint,
- _("multiple skeleton declarations are invalid"));
-}
-
-void
-language_argmatch (char const *arg, int prio, location loc)
-{
- char const *msg;
-
- if (prio < language_prio)
- {
- int i;
- for (i = 0; valid_languages[i].language[0]; i++)
- if (c_strcasecmp (arg, valid_languages[i].language) == 0)
- {
- language_prio = prio;
- language = &valid_languages[i];
- return;
- }
- msg = _("%s: invalid language");
- }
- else if (language_prio == prio)
- msg = _("multiple language declarations are invalid");
- else
- return;
-
- complain (&loc, complaint, msg, quotearg_colon (arg));
-}
-
-/*----------------------.
-| Process the options. |
-`----------------------*/
-
-/* Shorts options.
- Should be computed from long_options. */
-static char const short_options[] =
- "D:"
- "F:"
- "L:"
- "S:"
- "T::"
- "V"
- "W::"
- "b:"
- "d"
- "f::"
- "g::"
- "h"
- "k"
- "l"
- "o:"
- "p:"
- "r:"
- "t"
- "v"
- "x::"
- "y"
- ;
-
-/* Values for long options that do not have single-letter equivalents. */
-enum
-{
- LOCATIONS_OPTION = CHAR_MAX + 1,
- PRINT_LOCALEDIR_OPTION,
- PRINT_DATADIR_OPTION,
- REPORT_FILE_OPTION,
- M4_PATH
-};
-
-static struct option const long_options[] =
-{
- /* Operation modes. */
- { "help", no_argument, 0, 'h' },
- { "version", no_argument, 0, 'V' },
- { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION },
- { "print-datadir", no_argument, 0, PRINT_DATADIR_OPTION },
- { "warnings", optional_argument, 0, 'W' },
-
- /* Parser. */
- { "name-prefix", required_argument, 0, 'p' },
-
- /* Output. */
- { "file-prefix", required_argument, 0, 'b' },
- { "output", required_argument, 0, 'o' },
- { "output-file", required_argument, 0, 'o' },
- { "graph", optional_argument, 0, 'g' },
- { "xml", optional_argument, 0, 'x' },
- { "report", required_argument, 0, 'r' },
- { "report-file", required_argument, 0, REPORT_FILE_OPTION },
- { "verbose", no_argument, 0, 'v' },
-
- /* Hidden. */
- { "trace", optional_argument, 0, 'T' },
- { "m4", required_argument, 0, M4_PATH },
-
- /* Output. */
- { "defines", optional_argument, 0, 'd' },
- { "feature", optional_argument, 0, 'f' },
-
- /* Operation modes. */
- { "fixed-output-files", no_argument, 0, 'y' },
- { "yacc", no_argument, 0, 'y' },
-
- /* Parser. */
- { "debug", no_argument, 0, 't' },
- { "define", required_argument, 0, 'D' },
- { "force-define", required_argument, 0, 'F' },
- { "locations", no_argument, 0, LOCATIONS_OPTION },
- { "no-lines", no_argument, 0, 'l' },
- { "skeleton", required_argument, 0, 'S' },
- { "language", required_argument, 0, 'L' },
- { "token-table", no_argument, 0, 'k' },
-
- {0, 0, 0, 0}
-};
-
-/* Under DOS, there is no difference on the case. This can be
- troublesome when looking for '.tab' etc. */
-#ifdef MSDOS
-# define AS_FILE_NAME(File) (strlwr (File), (File))
-#else
-# define AS_FILE_NAME(File) (File)
-#endif
-
-/* Build a location for the current command line argument. */
-static
-location
-command_line_location (void)
-{
- location res;
- /* "<command line>" is used in GCC's messages about -D. */
- boundary_set (&res.start, uniqstr_new ("<command line>"), optind - 1, -1);
- res.end = res.start;
- return res;
-}
-
-
-void
-getargs (int argc, char *argv[])
-{
- int c;
-
- while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
- != -1)
- switch (c)
- {
- /* ASCII Sorting for short options (i.e., upper case then
- lower case), and then long-only options. */
-
- case 0:
- /* Certain long options cause getopt_long to return 0. */
- break;
-
- case 'D': /* -DNAME[=(VALUE|"VALUE"|{VALUE})]. */
- case 'F': /* -FNAME[=(VALUE|"VALUE"|{VALUE})]. */
- {
- char *name = optarg;
- char *value = strchr (optarg, '=');
- muscle_kind kind = muscle_keyword;
- if (value)
- {
- char *end = value + strlen (value) - 1;
- *value++ = 0;
- if (*value == '{' && *end == '}')
- {
- kind = muscle_code;
- ++value;
- *end = 0;
- }
- else if (*value == '"' && *end == '"')
- {
- kind = muscle_string;
- ++value;
- *end = 0;
- }
- }
- muscle_percent_define_insert (name, command_line_location (),
- kind, value ? value : "",
- c == 'D' ? MUSCLE_PERCENT_DEFINE_D
- : MUSCLE_PERCENT_DEFINE_F);
- }
- break;
-
- case 'L':
- language_argmatch (optarg, command_line_prio,
- command_line_location ());
- break;
-
- case 'S':
- skeleton_arg (AS_FILE_NAME (optarg), command_line_prio,
- command_line_location ());
- break;
-
- case 'T':
- FLAGS_ARGMATCH (trace, optarg, trace_all);
- break;
-
- case 'V':
- version ();
- exit (EXIT_SUCCESS);
-
- case 'f':
- FLAGS_ARGMATCH (feature, optarg, feature_all);
- break;
-
- case 'W':
- warnings_argmatch (optarg);
- break;
-
- case 'b':
- spec_file_prefix = AS_FILE_NAME (optarg);
- break;
-
- case 'd':
- /* Here, the -d and --defines options are differentiated. */
- defines_flag = true;
- if (optarg)
- {
- free (spec_defines_file);
- spec_defines_file = xstrdup (AS_FILE_NAME (optarg));
- }
- break;
-
- case 'g':
- graph_flag = true;
- if (optarg)
- {
- free (spec_graph_file);
- spec_graph_file = xstrdup (AS_FILE_NAME (optarg));
- }
- break;
-
- case 'h':
- usage (EXIT_SUCCESS);
-
- case 'k':
- token_table_flag = true;
- break;
-
- case 'l':
- no_lines_flag = true;
- break;
-
- case 'o':
- spec_outfile = AS_FILE_NAME (optarg);
- break;
-
- case 'p':
- spec_name_prefix = optarg;
- break;
-
- case 'r':
- FLAGS_ARGMATCH (report, optarg, report_all);
- break;
-
- case 't':
- muscle_percent_define_insert ("parse.trace",
- command_line_location (),
- muscle_keyword, "",
- MUSCLE_PERCENT_DEFINE_D);
- break;
-
- case 'v':
- report_flag |= report_states;
- break;
-
- case 'x':
- xml_flag = true;
- if (optarg)
- {
- free (spec_xml_file);
- spec_xml_file = xstrdup (AS_FILE_NAME (optarg));
- }
- break;
-
- case 'y':
- warning_argmatch ("error=yacc", 0, 6);
- yacc_flag = true;
- break;
-
- case LOCATIONS_OPTION:
- muscle_percent_define_ensure ("locations",
- command_line_location (), true);
- break;
-
-#if 0
- case PRINT_LOCALEDIR_OPTION:
- printf ("%s\n", LOCALEDIR);
- exit (EXIT_SUCCESS);
-#endif
-
- case PRINT_DATADIR_OPTION:
- printf ("%s\n", pkgdatadir ());
- exit (EXIT_SUCCESS);
-
- case REPORT_FILE_OPTION:
- free (spec_verbose_file);
- spec_verbose_file = xstrdup (AS_FILE_NAME (optarg));
- break;
-
- case M4_PATH:
- m4_path = xstrdup (AS_FILE_NAME (optarg));
- break;
-
- default:
- usage (EXIT_FAILURE);
- }
-
- if (argc - optind != 1)
- {
- if (argc - optind < 1)
- error (0, 0, _("%s: missing operand"), quotearg_colon (argv[argc - 1]));
- else
- error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
- usage (EXIT_FAILURE);
- }
-
- current_file = grammar_file = uniqstr_new (argv[optind]);
- MUSCLE_INSERT_C_STRING ("file_name", grammar_file);
-}
-
-void
-tr (char *s, char from, char to)
-{
- for (; *s; s++)
- if (*s == from)
- *s = to;
-}
+/* Parse command line arguments for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+#include "output.h"
+
+#include <argmatch.h>
+#include <c-strcase.h>
+#include <configmake.h>
+#include <error.h>
+#include <getopt.h>
+#include <progname.h>
+
+#include "complain.h"
+#include "files.h"
+#include "getargs.h"
+#include "muscle-tab.h"
+#include "quote.h"
+#include "uniqstr.h"
+
+bool defines_flag;
+bool graph_flag;
+bool xml_flag;
+bool no_lines_flag;
+bool token_table_flag;
+bool yacc_flag; /* for -y */
+
+bool nondeterministic_parser = false;
+bool glr_parser = false;
+
+int feature_flag = feature_caret;
+int report_flag = report_none;
+int trace_flag = trace_none;
+
+static struct bison_language const valid_languages[] = {
+ { "c", "c-skel.m4", ".c", ".h", true },
+ { "c++", "c++-skel.m4", ".cc", ".hh", true },
+ { "java", "java-skel.m4", ".java", ".java", false },
+ { "", "", "", "", false }
+};
+
+int skeleton_prio = default_prio;
+const char *skeleton = NULL;
+int language_prio = default_prio;
+struct bison_language const *language = &valid_languages[0];
+
+const char* m4_path = NULL;
+
+/** Decode an option's key.
+ *
+ * \param option option being decoded.
+ * \param keys array of valid subarguments.
+ * \param values array of corresponding (int) values.
+ * \param all the all value.
+ * \param flags the flags to update
+ * \param arg the subarguments to decode.
+ * If null, then activate all the flags.
+ * \param no length of the potential "no-" prefix.
+ * Can be 0 or 3. If 3, negate the action of the subargument.
+ *
+ * If VALUE != 0 then KEY sets flags and no-KEY clears them.
+ * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
+ * flags from \c all. Thus no-none = all and no-all = none.
+ */
+static void
+flag_argmatch (const char *option,
+ const char * const keys[], const int values[],
+ int all, int *flags, char *arg, size_t no)
+{
+ int value = XARGMATCH (option, arg + no, keys, values);
+
+ /* -rnone == -rno-all, and -rno-none == -rall. */
+ if (!value)
+ {
+ value = all;
+ no = !no;
+ }
+
+ if (no)
+ *flags &= ~value;
+ else
+ *flags |= value;
+}
+
+/** Decode an option's set of keys.
+ *
+ * \param option option being decoded.
+ * \param keys array of valid subarguments.
+ * \param values array of corresponding (int) values.
+ * \param all the all value.
+ * \param flags the flags to update
+ * \param args comma separated list of effective subarguments to decode.
+ * If 0, then activate all the flags.
+ */
+static void
+flags_argmatch (const char *option,
+ const char * const keys[], const int values[],
+ int all, int *flags, char *args)
+{
+ if (args)
+ for (args = strtok (args, ","); args; args = strtok (NULL, ","))
+ {
+ size_t no = STRPREFIX_LIT ("no-", args) ? 3 : 0;
+ flag_argmatch (option, keys,
+ values, all, flags, args, no);
+ }
+ else
+ *flags |= all;
+}
+
+
+/** Decode a set of sub arguments.
+ *
+ * \param FlagName the flag familly to update.
+ * \param Args the effective sub arguments to decode.
+ * \param All the "all" value.
+ *
+ * \arg FlagName_args the list of keys.
+ * \arg FlagName_types the list of values.
+ * \arg FlagName_flag the flag to update.
+ */
+#define FLAGS_ARGMATCH(FlagName, Args, All) \
+ flags_argmatch ("--" #FlagName, FlagName ## _args, FlagName ## _types, \
+ All, &FlagName ## _flag, Args)
+
+
+/*----------------------.
+| --report's handling. |
+`----------------------*/
+
+static const char * const report_args[] =
+{
+ /* In a series of synonyms, present the most meaningful first, so
+ that argmatch_valid be more readable. */
+ "none",
+ "state", "states",
+ "itemset", "itemsets",
+ "lookahead", "lookaheads", "look-ahead",
+ "solved",
+ "all",
+ 0
+};
+
+static const int report_types[] =
+{
+ report_none,
+ report_states, report_states,
+ report_states | report_itemsets, report_states | report_itemsets,
+ report_states | report_lookahead_tokens,
+ report_states | report_lookahead_tokens,
+ report_states | report_lookahead_tokens,
+ report_states | report_solved_conflicts,
+ report_all
+};
+
+ARGMATCH_VERIFY (report_args, report_types);
+
+
+/*---------------------.
+| --trace's handling. |
+`---------------------*/
+
+static const char * const trace_args[] =
+{
+ "none - no traces",
+ "scan - grammar scanner traces",
+ "parse - grammar parser traces",
+ "automaton - construction of the automaton",
+ "bitsets - use of bitsets",
+ "grammar - reading, reducing the grammar",
+ "resource - memory consumption (where available)",
+ "sets - grammar sets: firsts, nullable etc.",
+ "muscles - m4 definitions passed to the skeleton",
+ "tools - m4 invocation",
+ "m4 - m4 traces",
+ "skeleton - skeleton postprocessing",
+ "time - time consumption",
+ "ielr - IELR conversion",
+ "all - all of the above",
+ 0
+};
+
+static const int trace_types[] =
+{
+ trace_none,
+ trace_scan,
+ trace_parse,
+ trace_automaton,
+ trace_bitsets,
+ trace_grammar,
+ trace_resource,
+ trace_sets,
+ trace_muscles,
+ trace_tools,
+ trace_m4,
+ trace_skeleton,
+ trace_time,
+ trace_ielr,
+ trace_all
+};
+
+ARGMATCH_VERIFY (trace_args, trace_types);
+
+
+/*-----------------------.
+| --feature's handling. |
+`-----------------------*/
+
+static const char * const feature_args[] =
+{
+ "none",
+ "caret", "diagnostics-show-caret",
+ "all",
+ 0
+};
+
+static const int feature_types[] =
+{
+ feature_none,
+ feature_caret, feature_caret,
+ feature_all
+};
+
+ARGMATCH_VERIFY (feature_args, feature_types);
+
+/*-------------------------------------------.
+| Display the help message and exit STATUS. |
+`-------------------------------------------*/
+
+static void usage (int) ATTRIBUTE_NORETURN;
+
+static void
+usage (int status)
+{
+ if (status != 0)
+ fprintf (stderr, _("Try '%s --help' for more information.\n"),
+ program_name);
+ else
+ {
+ /* For ../build-aux/cross-options.pl to work, use the format:
+ ^ -S, --long[=ARGS] (whitespace)
+ A --long option is required.
+ Otherwise, add exceptions to ../build-aux/cross-options.pl. */
+
+ printf (_("Usage: %s [OPTION]... FILE\n"), program_name);
+ fputs (_("\
+Generate a deterministic LR or generalized LR (GLR) parser employing\n\
+LALR(1), IELR(1), or canonical LR(1) parser tables. IELR(1) and\n\
+canonical LR(1) support is experimental.\n\
+\n\
+"), stdout);
+
+ fputs (_("\
+Mandatory arguments to long options are mandatory for short options too.\n\
+"), stdout);
+ fputs (_("\
+The same is true for optional arguments.\n\
+"), stdout);
+
+ fputs (_("\
+\n\
+Operation modes:\n\
+ -h, --help display this help and exit\n\
+ -V, --version output version information and exit\n\
+ --print-localedir output directory containing locale-dependent data\n\
+ --print-datadir output directory containing skeletons and XSLT\n\
+ -y, --yacc emulate POSIX Yacc\n\
+ -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\
+ -f, --feature[=FEATURE] activate miscellaneous features\n\
+\n\
+"), stdout);
+
+ fputs (_("\
+Parser:\n\
+ -L, --language=LANGUAGE specify the output programming language\n\
+ -S, --skeleton=FILE specify the skeleton to use\n\
+ -t, --debug instrument the parser for tracing\n\
+ same as '-Dparse.trace'\n\
+ --locations enable location support\n\
+ -D, --define=NAME[=VALUE] similar to '%define NAME \"VALUE\"'\n\
+ -F, --force-define=NAME[=VALUE] override '%define NAME \"VALUE\"'\n\
+ -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
+ deprecated by '-Dapi.prefix=PREFIX'\n\
+ -l, --no-lines don't generate '#line' directives\n\
+ -k, --token-table include a table of token names\n\
+"), stdout);
+ putc ('\n', stdout);
+
+ /* Keep -d and --defines separate so that ../build-aux/cross-options.pl
+ * won't assume that -d also takes an argument. */
+ fputs (_("\
+Output:\n\
+ --defines[=FILE] also produce a header file\n\
+ -d likewise but cannot specify FILE (for POSIX Yacc)\n\
+ -r, --report=THINGS also produce details on the automaton\n\
+ --report-file=FILE write report to FILE\n\
+ -v, --verbose same as '--report=state'\n\
+ -b, --file-prefix=PREFIX specify a PREFIX for output files\n\
+ -o, --output=FILE leave output to FILE\n\
+ -g, --graph[=FILE] also output a graph of the automaton\n\
+ -x, --xml[=FILE] also output an XML report of the automaton\n\
+ (the XML schema is experimental)\n\
+"), stdout);
+ putc ('\n', stdout);
+
+ fputs (_("\
+Warning categories include:\n\
+ 'midrule-values' unset or unused midrule values\n\
+ 'yacc' incompatibilities with POSIX Yacc\n\
+ 'conflicts-sr' S/R conflicts (enabled by default)\n\
+ 'conflicts-rr' R/R conflicts (enabled by default)\n\
+ 'deprecated' obsolete constructs\n\
+ 'empty-rule' empty rules without %empty\n\
+ 'precedence' useless precedence and associativity\n\
+ 'other' all other warnings (enabled by default)\n\
+ 'all' all the warnings except 'yacc'\n\
+ 'no-CATEGORY' turn off warnings in CATEGORY\n\
+ 'none' turn off all the warnings\n\
+ 'error[=CATEGORY]' treat warnings as errors\n\
+"), stdout);
+ putc ('\n', stdout);
+
+ fputs (_("\
+THINGS is a list of comma separated words that can include:\n\
+ 'state' describe the states\n\
+ 'itemset' complete the core item sets with their closure\n\
+ 'lookahead' explicitly associate lookahead tokens to items\n\
+ 'solved' describe shift/reduce conflicts solving\n\
+ 'all' include all the above information\n\
+ 'none' disable the report\n\
+"), stdout);
+ putc ('\n', stdout);
+
+ fputs (_("\
+FEATURE is a list of comma separated words that can include:\n\
+ 'caret' show errors with carets\n\
+ 'all' all of the above\n\
+ 'none' disable all of the above\n\
+ "), stdout);
+
+ putc ('\n', stdout);
+ printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
+ printf (_("%s home page: <%s>.\n"), PACKAGE_NAME, PACKAGE_URL);
+ fputs (_("General help using GNU software: "
+ "<http://www.gnu.org/gethelp/>.\n"),
+ stdout);
+ /* Don't output this redundant message for English locales.
+ Note we still output for 'C' so that it gets included in the
+ man page. */
+ fputs (_("For complete documentation, run: info bison.\n"), stdout);
+ }
+
+ exit (status);
+}
+
+
+/*------------------------------.
+| Display the version message. |
+`------------------------------*/
+
+static void
+version (void)
+{
+ /* Some efforts were made to ease the translators' task, please
+ continue. */
+ printf (_("bison (GNU Bison) %s"), VERSION);
+ putc ('\n', stdout);
+ fputs (_("Written by Robert Corbett and Richard Stallman.\n"), stdout);
+ putc ('\n', stdout);
+
+ fprintf (stdout,
+ _("Copyright (C) %d Free Software Foundation, Inc.\n"),
+ 2013);
+
+ fputs (_("\
+This is free software; see the source for copying conditions. There is NO\n\
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
+"),
+ stdout);
+}
+
+
+/*-------------------------------------.
+| --skeleton and --language handling. |
+`--------------------------------------*/
+
+void
+skeleton_arg (char const *arg, int prio, location loc)
+{
+ if (prio < skeleton_prio)
+ {
+ skeleton_prio = prio;
+ skeleton = arg;
+ }
+ else if (prio == skeleton_prio)
+ complain (&loc, complaint,
+ _("multiple skeleton declarations are invalid"));
+}
+
+void
+language_argmatch (char const *arg, int prio, location loc)
+{
+ char const *msg;
+
+ if (prio < language_prio)
+ {
+ int i;
+ for (i = 0; valid_languages[i].language[0]; i++)
+ if (c_strcasecmp (arg, valid_languages[i].language) == 0)
+ {
+ language_prio = prio;
+ language = &valid_languages[i];
+ return;
+ }
+ msg = _("%s: invalid language");
+ }
+ else if (language_prio == prio)
+ msg = _("multiple language declarations are invalid");
+ else
+ return;
+
+ complain (&loc, complaint, msg, quotearg_colon (arg));
+}
+
+/*----------------------.
+| Process the options. |
+`----------------------*/
+
+/* Shorts options.
+ Should be computed from long_options. */
+static char const short_options[] =
+ "D:"
+ "F:"
+ "L:"
+ "S:"
+ "T::"
+ "V"
+ "W::"
+ "b:"
+ "d"
+ "f::"
+ "g::"
+ "h"
+ "k"
+ "l"
+ "o:"
+ "p:"
+ "r:"
+ "t"
+ "v"
+ "x::"
+ "y"
+ ;
+
+/* Values for long options that do not have single-letter equivalents. */
+enum
+{
+ LOCATIONS_OPTION = CHAR_MAX + 1,
+ PRINT_LOCALEDIR_OPTION,
+ PRINT_DATADIR_OPTION,
+ REPORT_FILE_OPTION,
+ M4_PATH
+};
+
+static struct option const long_options[] =
+{
+ /* Operation modes. */
+ { "help", no_argument, 0, 'h' },
+ { "version", no_argument, 0, 'V' },
+ { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION },
+ { "print-datadir", no_argument, 0, PRINT_DATADIR_OPTION },
+ { "warnings", optional_argument, 0, 'W' },
+
+ /* Parser. */
+ { "name-prefix", required_argument, 0, 'p' },
+
+ /* Output. */
+ { "file-prefix", required_argument, 0, 'b' },
+ { "output", required_argument, 0, 'o' },
+ { "output-file", required_argument, 0, 'o' },
+ { "graph", optional_argument, 0, 'g' },
+ { "xml", optional_argument, 0, 'x' },
+ { "report", required_argument, 0, 'r' },
+ { "report-file", required_argument, 0, REPORT_FILE_OPTION },
+ { "verbose", no_argument, 0, 'v' },
+
+ /* Hidden. */
+ { "trace", optional_argument, 0, 'T' },
+ { "m4", required_argument, 0, M4_PATH },
+
+ /* Output. */
+ { "defines", optional_argument, 0, 'd' },
+ { "feature", optional_argument, 0, 'f' },
+
+ /* Operation modes. */
+ { "fixed-output-files", no_argument, 0, 'y' },
+ { "yacc", no_argument, 0, 'y' },
+
+ /* Parser. */
+ { "debug", no_argument, 0, 't' },
+ { "define", required_argument, 0, 'D' },
+ { "force-define", required_argument, 0, 'F' },
+ { "locations", no_argument, 0, LOCATIONS_OPTION },
+ { "no-lines", no_argument, 0, 'l' },
+ { "skeleton", required_argument, 0, 'S' },
+ { "language", required_argument, 0, 'L' },
+ { "token-table", no_argument, 0, 'k' },
+
+ {0, 0, 0, 0}
+};
+
+/* Under DOS, there is no difference on the case. This can be
+ troublesome when looking for '.tab' etc. */
+#ifdef MSDOS
+# define AS_FILE_NAME(File) (strlwr (File), (File))
+#else
+# define AS_FILE_NAME(File) (File)
+#endif
+
+/* Build a location for the current command line argument. */
+static
+location
+command_line_location (void)
+{
+ location res;
+ /* "<command line>" is used in GCC's messages about -D. */
+ boundary_set (&res.start, uniqstr_new ("<command line>"), optind - 1, -1);
+ res.end = res.start;
+ return res;
+}
+
+
+void
+getargs (int argc, char *argv[])
+{
+ int c;
+
+ while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
+ != -1)
+ switch (c)
+ {
+ /* ASCII Sorting for short options (i.e., upper case then
+ lower case), and then long-only options. */
+
+ case 0:
+ /* Certain long options cause getopt_long to return 0. */
+ break;
+
+ case 'D': /* -DNAME[=(VALUE|"VALUE"|{VALUE})]. */
+ case 'F': /* -FNAME[=(VALUE|"VALUE"|{VALUE})]. */
+ {
+ char *name = optarg;
+ char *value = strchr (optarg, '=');
+ muscle_kind kind = muscle_keyword;
+ if (value)
+ {
+ char *end = value + strlen (value) - 1;
+ *value++ = 0;
+ if (*value == '{' && *end == '}')
+ {
+ kind = muscle_code;
+ ++value;
+ *end = 0;
+ }
+ else if (*value == '"' && *end == '"')
+ {
+ kind = muscle_string;
+ ++value;
+ *end = 0;
+ }
+ }
+ muscle_percent_define_insert (name, command_line_location (),
+ kind, value ? value : "",
+ c == 'D' ? MUSCLE_PERCENT_DEFINE_D
+ : MUSCLE_PERCENT_DEFINE_F);
+ }
+ break;
+
+ case 'L':
+ language_argmatch (optarg, command_line_prio,
+ command_line_location ());
+ break;
+
+ case 'S':
+ skeleton_arg (AS_FILE_NAME (optarg), command_line_prio,
+ command_line_location ());
+ break;
+
+ case 'T':
+ FLAGS_ARGMATCH (trace, optarg, trace_all);
+ break;
+
+ case 'V':
+ version ();
+ exit (EXIT_SUCCESS);
+
+ case 'f':
+ FLAGS_ARGMATCH (feature, optarg, feature_all);
+ break;
+
+ case 'W':
+ warnings_argmatch (optarg);
+ break;
+
+ case 'b':
+ spec_file_prefix = AS_FILE_NAME (optarg);
+ break;
+
+ case 'd':
+ /* Here, the -d and --defines options are differentiated. */
+ defines_flag = true;
+ if (optarg)
+ {
+ free (spec_defines_file);
+ spec_defines_file = xstrdup (AS_FILE_NAME (optarg));
+ }
+ break;
+
+ case 'g':
+ graph_flag = true;
+ if (optarg)
+ {
+ free (spec_graph_file);
+ spec_graph_file = xstrdup (AS_FILE_NAME (optarg));
+ }
+ break;
+
+ case 'h':
+ usage (EXIT_SUCCESS);
+
+ case 'k':
+ token_table_flag = true;
+ break;
+
+ case 'l':
+ no_lines_flag = true;
+ break;
+
+ case 'o':
+ spec_outfile = AS_FILE_NAME (optarg);
+ break;
+
+ case 'p':
+ spec_name_prefix = optarg;
+ break;
+
+ case 'r':
+ FLAGS_ARGMATCH (report, optarg, report_all);
+ break;
+
+ case 't':
+ muscle_percent_define_insert ("parse.trace",
+ command_line_location (),
+ muscle_keyword, "",
+ MUSCLE_PERCENT_DEFINE_D);
+ break;
+
+ case 'v':
+ report_flag |= report_states;
+ break;
+
+ case 'x':
+ xml_flag = true;
+ if (optarg)
+ {
+ free (spec_xml_file);
+ spec_xml_file = xstrdup (AS_FILE_NAME (optarg));
+ }
+ break;
+
+ case 'y':
+ warning_argmatch ("error=yacc", 0, 6);
+ yacc_flag = true;
+ break;
+
+ case LOCATIONS_OPTION:
+ muscle_percent_define_ensure ("locations",
+ command_line_location (), true);
+ break;
+
+#if 0
+ case PRINT_LOCALEDIR_OPTION:
+ printf ("%s\n", LOCALEDIR);
+ exit (EXIT_SUCCESS);
+#endif
+
+ case PRINT_DATADIR_OPTION:
+ printf ("%s\n", pkgdatadir ());
+ exit (EXIT_SUCCESS);
+
+ case REPORT_FILE_OPTION:
+ free (spec_verbose_file);
+ spec_verbose_file = xstrdup (AS_FILE_NAME (optarg));
+ break;
+
+ case M4_PATH:
+ m4_path = xstrdup (AS_FILE_NAME (optarg));
+ break;
+
+ default:
+ usage (EXIT_FAILURE);
+ }
+
+ if (argc - optind != 1)
+ {
+ if (argc - optind < 1)
+ error (0, 0, _("%s: missing operand"), quotearg_colon (argv[argc - 1]));
+ else
+ error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
+ usage (EXIT_FAILURE);
+ }
+
+ current_file = grammar_file = uniqstr_new (argv[optind]);
+ MUSCLE_INSERT_C_STRING ("file_name", grammar_file);
+}
+
+void
+tr (char *s, char from, char to)
+{
+ for (; *s; s++)
+ if (*s == from)
+ *s = to;
+}
diff --git a/contrib/tools/bison/bison/src/getargs.h b/contrib/tools/bison/bison/src/getargs.h
index 178fb94377..5050b9fec2 100644
--- a/contrib/tools/bison/bison/src/getargs.h
+++ b/contrib/tools/bison/bison/src/getargs.h
@@ -1,141 +1,141 @@
-/* Parse command line arguments for bison.
-
- Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef GETARGS_H_
-# define GETARGS_H_
-
-# include "location.h"
-
-enum { command_line_prio, grammar_prio, default_prio };
-
-/* flags set by % directives */
-
-/* for -S */
-extern char const *skeleton;
-extern int skeleton_prio;
-
-/* for -I */
-extern char const *include;
-
-extern bool defines_flag; /* for -d */
-extern bool graph_flag; /* for -g */
-extern bool xml_flag; /* for -x */
-extern bool no_lines_flag; /* for -l */
-extern bool token_table_flag; /* for -k */
-extern bool yacc_flag; /* for -y */
-
-extern const char *m4_path;
-
-
-/* GLR_PARSER is true if the input file says to use the GLR
- (Generalized LR) parser, and to output some additional information
- used by the GLR algorithm. */
-
-extern bool glr_parser;
-
-/* NONDETERMINISTIC_PARSER is true iff conflicts are accepted. This
- is used by the GLR parser, and might be used in BackTracking
- parsers too. */
-
-extern bool nondeterministic_parser;
-
-
-/* --language. */
-struct bison_language
-{
- char language[sizeof "Java"];
- char skeleton[sizeof "java-skel.m4"];
- char src_extension[sizeof ".java"];
- char header_extension[sizeof ".java"];
- bool add_tab;
-};
-
-extern int language_prio;
-extern struct bison_language const *language;
-
-/*-----------.
-| --report. |
-`-----------*/
-
-enum report
- {
- report_none = 0,
- report_states = 1 << 0,
- report_itemsets = 1 << 1,
- report_lookahead_tokens = 1 << 2,
- report_solved_conflicts = 1 << 3,
- report_all = ~0
- };
-/** What appears in the *.output file. */
-extern int report_flag;
-
-/*----------.
-| --trace. |
-`----------*/
-enum trace
- {
- trace_none = 0, /**< No traces. */
- trace_scan = 1 << 0, /**< Grammar scanner traces. */
- trace_parse = 1 << 1, /**< Grammar parser traces. */
- trace_resource = 1 << 2, /**< Memory allocation. */
- trace_sets = 1 << 3, /**< Grammar sets: firsts, nullable etc. */
- trace_bitsets = 1 << 4, /**< Use of bitsets. */
- trace_tools = 1 << 5, /**< m4 invocation. */
- trace_automaton = 1 << 6, /**< Construction of the automaton. */
- trace_grammar = 1 << 7, /**< Reading, reducing the grammar. */
- trace_time = 1 << 8, /**< Time consumption. */
- trace_skeleton = 1 << 9, /**< Skeleton postprocessing. */
- trace_m4 = 1 << 10, /**< M4 traces. */
- trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */
- trace_ielr = 1 << 12, /**< IELR conversion. */
- trace_all = ~0 /**< All of the above. */
- };
-/** What debug items bison displays during its run. */
-extern int trace_flag;
-
-/*-------------.
-| --features. |
-`-------------*/
-
-enum feature
- {
- feature_none = 0, /**< No additional feature. */
- feature_caret = 1 << 0, /**< Enhance the output of errors with carets. */
- feature_all = ~0 /**< All above features. */
- };
-/** What additional features to use. */
-extern int feature_flag;
-
-
-/** Process the command line arguments.
- *
- * \param argc size of \a argv
- * \param argv list of arguments.
- */
-void getargs (int argc, char *argv[]);
-
-/* Used by parse-gram.y. */
-void language_argmatch (char const *arg, int prio, location loc);
-void skeleton_arg (const char *arg, int prio, location loc);
-
-/** In the string \c s, replace all characters \c from by \c to. */
-void tr (char *s, char from, char to);
-
-#endif /* !GETARGS_H_ */
+/* Parse command line arguments for bison.
+
+ Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GETARGS_H_
+# define GETARGS_H_
+
+# include "location.h"
+
+enum { command_line_prio, grammar_prio, default_prio };
+
+/* flags set by % directives */
+
+/* for -S */
+extern char const *skeleton;
+extern int skeleton_prio;
+
+/* for -I */
+extern char const *include;
+
+extern bool defines_flag; /* for -d */
+extern bool graph_flag; /* for -g */
+extern bool xml_flag; /* for -x */
+extern bool no_lines_flag; /* for -l */
+extern bool token_table_flag; /* for -k */
+extern bool yacc_flag; /* for -y */
+
+extern const char *m4_path;
+
+
+/* GLR_PARSER is true if the input file says to use the GLR
+ (Generalized LR) parser, and to output some additional information
+ used by the GLR algorithm. */
+
+extern bool glr_parser;
+
+/* NONDETERMINISTIC_PARSER is true iff conflicts are accepted. This
+ is used by the GLR parser, and might be used in BackTracking
+ parsers too. */
+
+extern bool nondeterministic_parser;
+
+
+/* --language. */
+struct bison_language
+{
+ char language[sizeof "Java"];
+ char skeleton[sizeof "java-skel.m4"];
+ char src_extension[sizeof ".java"];
+ char header_extension[sizeof ".java"];
+ bool add_tab;
+};
+
+extern int language_prio;
+extern struct bison_language const *language;
+
+/*-----------.
+| --report. |
+`-----------*/
+
+enum report
+ {
+ report_none = 0,
+ report_states = 1 << 0,
+ report_itemsets = 1 << 1,
+ report_lookahead_tokens = 1 << 2,
+ report_solved_conflicts = 1 << 3,
+ report_all = ~0
+ };
+/** What appears in the *.output file. */
+extern int report_flag;
+
+/*----------.
+| --trace. |
+`----------*/
+enum trace
+ {
+ trace_none = 0, /**< No traces. */
+ trace_scan = 1 << 0, /**< Grammar scanner traces. */
+ trace_parse = 1 << 1, /**< Grammar parser traces. */
+ trace_resource = 1 << 2, /**< Memory allocation. */
+ trace_sets = 1 << 3, /**< Grammar sets: firsts, nullable etc. */
+ trace_bitsets = 1 << 4, /**< Use of bitsets. */
+ trace_tools = 1 << 5, /**< m4 invocation. */
+ trace_automaton = 1 << 6, /**< Construction of the automaton. */
+ trace_grammar = 1 << 7, /**< Reading, reducing the grammar. */
+ trace_time = 1 << 8, /**< Time consumption. */
+ trace_skeleton = 1 << 9, /**< Skeleton postprocessing. */
+ trace_m4 = 1 << 10, /**< M4 traces. */
+ trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */
+ trace_ielr = 1 << 12, /**< IELR conversion. */
+ trace_all = ~0 /**< All of the above. */
+ };
+/** What debug items bison displays during its run. */
+extern int trace_flag;
+
+/*-------------.
+| --features. |
+`-------------*/
+
+enum feature
+ {
+ feature_none = 0, /**< No additional feature. */
+ feature_caret = 1 << 0, /**< Enhance the output of errors with carets. */
+ feature_all = ~0 /**< All above features. */
+ };
+/** What additional features to use. */
+extern int feature_flag;
+
+
+/** Process the command line arguments.
+ *
+ * \param argc size of \a argv
+ * \param argv list of arguments.
+ */
+void getargs (int argc, char *argv[]);
+
+/* Used by parse-gram.y. */
+void language_argmatch (char const *arg, int prio, location loc);
+void skeleton_arg (const char *arg, int prio, location loc);
+
+/** In the string \c s, replace all characters \c from by \c to. */
+void tr (char *s, char from, char to);
+
+#endif /* !GETARGS_H_ */
diff --git a/contrib/tools/bison/bison/src/gram.c b/contrib/tools/bison/bison/src/gram.c
index f6cc3c5d87..44f3e3bbd8 100644
--- a/contrib/tools/bison/bison/src/gram.c
+++ b/contrib/tools/bison/bison/src/gram.c
@@ -1,310 +1,310 @@
-/* Allocate input grammar variables for Bison.
-
- Copyright (C) 1984, 1986, 1989, 2001-2003, 2005-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "complain.h"
-#include "getargs.h"
-#include "gram.h"
-#include "print-xml.h"
-#include "reader.h"
-#include "reduce.h"
-#include "symtab.h"
-
-/* Comments for these variables are in gram.h. */
-
-item_number *ritem = NULL;
-unsigned int nritems = 0;
-
-rule *rules = NULL;
-rule_number nrules = 0;
-
-symbol **symbols = NULL;
-int nsyms = 0;
-int ntokens = 1;
-int nvars = 0;
-
-symbol_number *token_translations = NULL;
-
-int max_user_token_number = 256;
-
-bool
-rule_useful_in_grammar_p (rule const *r)
-{
- return r->number < nrules;
-}
-
-bool
-rule_useless_in_grammar_p (rule const *r)
-{
- return !rule_useful_in_grammar_p (r);
-}
-
-bool
-rule_useless_in_parser_p (rule const *r)
-{
- return !r->useful && rule_useful_in_grammar_p (r);
-}
-
-void
-rule_lhs_print (rule const *r, symbol const *previous_lhs, FILE *out)
-{
- fprintf (out, " %3d ", r->number);
- if (previous_lhs != r->lhs)
- fprintf (out, "%s:", r->lhs->tag);
- else
- fprintf (out, "%*s|", (int) strlen (previous_lhs->tag), "");
-}
-
-void
-rule_lhs_print_xml (rule const *r, FILE *out, int level)
-{
- xml_printf (out, level, "<lhs>%s</lhs>", r->lhs->tag);
-}
-
-size_t
-rule_rhs_length (rule const *r)
-{
- size_t res = 0;
- item_number *rhsp;
- for (rhsp = r->rhs; *rhsp >= 0; ++rhsp)
- ++res;
- return res;
-}
-
-void
-rule_rhs_print (rule const *r, FILE *out)
-{
- if (0 <= *r->rhs)
- {
- item_number *rp;
- for (rp = r->rhs; *rp >= 0; rp++)
- fprintf (out, " %s", symbols[*rp]->tag);
- }
- else
- fputs (" %empty", out);
-}
-
-static void
-rule_rhs_print_xml (rule const *r, FILE *out, int level)
-{
- if (*r->rhs >= 0)
- {
- item_number *rp;
- xml_puts (out, level, "<rhs>");
- for (rp = r->rhs; *rp >= 0; rp++)
- xml_printf (out, level + 1, "<symbol>%s</symbol>",
- xml_escape (symbols[*rp]->tag));
- xml_puts (out, level, "</rhs>");
- }
- else
- {
- xml_puts (out, level, "<rhs>");
- xml_puts (out, level + 1, "<empty/>");
- xml_puts (out, level, "</rhs>");
- }
-}
-
-void
-ritem_print (FILE *out)
-{
- unsigned int i;
- fputs ("RITEM\n", out);
- for (i = 0; i < nritems; ++i)
- if (ritem[i] >= 0)
- fprintf (out, " %s", symbols[ritem[i]]->tag);
- else
- fprintf (out, " (rule %d)\n", item_number_as_rule_number (ritem[i]));
- fputs ("\n\n", out);
-}
-
-size_t
-ritem_longest_rhs (void)
-{
- int max = 0;
- rule_number r;
-
- for (r = 0; r < nrules; ++r)
- {
- int length = rule_rhs_length (&rules[r]);
- if (length > max)
- max = length;
- }
-
- return max;
-}
-
-void
-grammar_rules_partial_print (FILE *out, const char *title,
- rule_filter filter)
-{
- rule_number r;
- bool first = true;
- symbol *previous_lhs = NULL;
-
- /* rule # : LHS -> RHS */
- for (r = 0; r < nrules + nuseless_productions; r++)
- {
- if (filter && !filter (&rules[r]))
- continue;
- if (first)
- fprintf (out, "%s\n\n", title);
- else if (previous_lhs && previous_lhs != rules[r].lhs)
- fputc ('\n', out);
- first = false;
- rule_lhs_print (&rules[r], previous_lhs, out);
- rule_rhs_print (&rules[r], out);
- fprintf (out, "\n");
- previous_lhs = rules[r].lhs;
- }
- if (!first)
- fputs ("\n\n", out);
-}
-
-void
-grammar_rules_print (FILE *out)
-{
- grammar_rules_partial_print (out, _("Grammar"), rule_useful_in_grammar_p);
-}
-
-void
-grammar_rules_print_xml (FILE *out, int level)
-{
- rule_number r;
- bool first = true;
-
- for (r = 0; r < nrules + nuseless_productions; r++)
- {
- if (first)
- xml_puts (out, level + 1, "<rules>");
- first = false;
- {
- char const *usefulness;
- if (rule_useless_in_grammar_p (&rules[r]))
- usefulness = "useless-in-grammar";
- else if (rule_useless_in_parser_p (&rules[r]))
- usefulness = "useless-in-parser";
- else
- usefulness = "useful";
- xml_indent (out, level + 2);
- fprintf (out, "<rule number=\"%d\" usefulness=\"%s\"",
- rules[r].number, usefulness);
- if (rules[r].precsym)
- fprintf (out, " percent_prec=\"%s\"",
- xml_escape (rules[r].precsym->tag));
- fputs (">\n", out);
- }
- rule_lhs_print_xml (&rules[r], out, level + 3);
- rule_rhs_print_xml (&rules[r], out, level + 3);
- xml_puts (out, level + 2, "</rule>");
- }
- if (!first)
- xml_puts (out, level + 1, "</rules>");
- else
- xml_puts (out, level + 1, "<rules/>");
-}
-
-void
-grammar_dump (FILE *out, const char *title)
-{
- fprintf (out, "%s\n\n", title);
- fprintf (out,
- "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nritems = %d\n\n",
- ntokens, nvars, nsyms, nrules, nritems);
-
-
- fprintf (out, "Variables\n---------\n\n");
- {
- symbol_number i;
- fprintf (out, "Value Sprec Sassoc Tag\n");
-
- for (i = ntokens; i < nsyms; i++)
- fprintf (out, "%5d %5d %5d %s\n",
- i,
- symbols[i]->prec, symbols[i]->assoc,
- symbols[i]->tag);
- fprintf (out, "\n\n");
- }
-
- fprintf (out, "Rules\n-----\n\n");
- {
- rule_number i;
- fprintf (out,
- "Num (Prec, Assoc, Useful, Ritem Range) Lhs"
- " -> Rhs (Ritem range) [Num]\n");
- for (i = 0; i < nrules + nuseless_productions; i++)
- {
- rule const *rule_i = &rules[i];
- item_number *rp = NULL;
- unsigned int rhs_itemno = rule_i->rhs - ritem;
- unsigned int rhs_count = 0;
- /* Find the last RHS index in ritems. */
- for (rp = rule_i->rhs; *rp >= 0; ++rp)
- ++rhs_count;
- fprintf (out, "%3d (%2d, %2d, %2d, %2u-%2u) %2d ->",
- i,
- rule_i->prec ? rule_i->prec->prec : 0,
- rule_i->prec ? rule_i->prec->assoc : 0,
- rule_i->useful,
- rhs_itemno,
- rhs_itemno + rhs_count - 1,
- rule_i->lhs->number);
- /* Dumped the RHS. */
- for (rp = rule_i->rhs; *rp >= 0; rp++)
- fprintf (out, " %3d", *rp);
- fprintf (out, " [%d]\n", item_number_as_rule_number (*rp));
- }
- }
- fprintf (out, "\n\n");
-
- fprintf (out, "Rules interpreted\n-----------------\n\n");
- {
- rule_number r;
- for (r = 0; r < nrules + nuseless_productions; r++)
- {
- fprintf (out, "%-5d %s:", r, rules[r].lhs->tag);
- rule_rhs_print (&rules[r], out);
- fprintf (out, "\n");
- }
- }
- fprintf (out, "\n\n");
-}
-
-void
-grammar_rules_useless_report (const char *message)
-{
- rule_number r;
- for (r = 0; r < nrules ; ++r)
- if (!rules[r].useful)
- complain (&rules[r].location, Wother, "%s", message);
-}
-
-void
-grammar_free (void)
-{
- if (ritem)
- free (ritem - 1);
- free (rules);
- free (token_translations);
- /* Free the symbol table data structure. */
- symbols_free ();
- free_merger_functions ();
-}
+/* Allocate input grammar variables for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 2001-2003, 2005-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "complain.h"
+#include "getargs.h"
+#include "gram.h"
+#include "print-xml.h"
+#include "reader.h"
+#include "reduce.h"
+#include "symtab.h"
+
+/* Comments for these variables are in gram.h. */
+
+item_number *ritem = NULL;
+unsigned int nritems = 0;
+
+rule *rules = NULL;
+rule_number nrules = 0;
+
+symbol **symbols = NULL;
+int nsyms = 0;
+int ntokens = 1;
+int nvars = 0;
+
+symbol_number *token_translations = NULL;
+
+int max_user_token_number = 256;
+
+bool
+rule_useful_in_grammar_p (rule const *r)
+{
+ return r->number < nrules;
+}
+
+bool
+rule_useless_in_grammar_p (rule const *r)
+{
+ return !rule_useful_in_grammar_p (r);
+}
+
+bool
+rule_useless_in_parser_p (rule const *r)
+{
+ return !r->useful && rule_useful_in_grammar_p (r);
+}
+
+void
+rule_lhs_print (rule const *r, symbol const *previous_lhs, FILE *out)
+{
+ fprintf (out, " %3d ", r->number);
+ if (previous_lhs != r->lhs)
+ fprintf (out, "%s:", r->lhs->tag);
+ else
+ fprintf (out, "%*s|", (int) strlen (previous_lhs->tag), "");
+}
+
+void
+rule_lhs_print_xml (rule const *r, FILE *out, int level)
+{
+ xml_printf (out, level, "<lhs>%s</lhs>", r->lhs->tag);
+}
+
+size_t
+rule_rhs_length (rule const *r)
+{
+ size_t res = 0;
+ item_number *rhsp;
+ for (rhsp = r->rhs; *rhsp >= 0; ++rhsp)
+ ++res;
+ return res;
+}
+
+void
+rule_rhs_print (rule const *r, FILE *out)
+{
+ if (0 <= *r->rhs)
+ {
+ item_number *rp;
+ for (rp = r->rhs; *rp >= 0; rp++)
+ fprintf (out, " %s", symbols[*rp]->tag);
+ }
+ else
+ fputs (" %empty", out);
+}
+
+static void
+rule_rhs_print_xml (rule const *r, FILE *out, int level)
+{
+ if (*r->rhs >= 0)
+ {
+ item_number *rp;
+ xml_puts (out, level, "<rhs>");
+ for (rp = r->rhs; *rp >= 0; rp++)
+ xml_printf (out, level + 1, "<symbol>%s</symbol>",
+ xml_escape (symbols[*rp]->tag));
+ xml_puts (out, level, "</rhs>");
+ }
+ else
+ {
+ xml_puts (out, level, "<rhs>");
+ xml_puts (out, level + 1, "<empty/>");
+ xml_puts (out, level, "</rhs>");
+ }
+}
+
+void
+ritem_print (FILE *out)
+{
+ unsigned int i;
+ fputs ("RITEM\n", out);
+ for (i = 0; i < nritems; ++i)
+ if (ritem[i] >= 0)
+ fprintf (out, " %s", symbols[ritem[i]]->tag);
+ else
+ fprintf (out, " (rule %d)\n", item_number_as_rule_number (ritem[i]));
+ fputs ("\n\n", out);
+}
+
+size_t
+ritem_longest_rhs (void)
+{
+ int max = 0;
+ rule_number r;
+
+ for (r = 0; r < nrules; ++r)
+ {
+ int length = rule_rhs_length (&rules[r]);
+ if (length > max)
+ max = length;
+ }
+
+ return max;
+}
+
+void
+grammar_rules_partial_print (FILE *out, const char *title,
+ rule_filter filter)
+{
+ rule_number r;
+ bool first = true;
+ symbol *previous_lhs = NULL;
+
+ /* rule # : LHS -> RHS */
+ for (r = 0; r < nrules + nuseless_productions; r++)
+ {
+ if (filter && !filter (&rules[r]))
+ continue;
+ if (first)
+ fprintf (out, "%s\n\n", title);
+ else if (previous_lhs && previous_lhs != rules[r].lhs)
+ fputc ('\n', out);
+ first = false;
+ rule_lhs_print (&rules[r], previous_lhs, out);
+ rule_rhs_print (&rules[r], out);
+ fprintf (out, "\n");
+ previous_lhs = rules[r].lhs;
+ }
+ if (!first)
+ fputs ("\n\n", out);
+}
+
+void
+grammar_rules_print (FILE *out)
+{
+ grammar_rules_partial_print (out, _("Grammar"), rule_useful_in_grammar_p);
+}
+
+void
+grammar_rules_print_xml (FILE *out, int level)
+{
+ rule_number r;
+ bool first = true;
+
+ for (r = 0; r < nrules + nuseless_productions; r++)
+ {
+ if (first)
+ xml_puts (out, level + 1, "<rules>");
+ first = false;
+ {
+ char const *usefulness;
+ if (rule_useless_in_grammar_p (&rules[r]))
+ usefulness = "useless-in-grammar";
+ else if (rule_useless_in_parser_p (&rules[r]))
+ usefulness = "useless-in-parser";
+ else
+ usefulness = "useful";
+ xml_indent (out, level + 2);
+ fprintf (out, "<rule number=\"%d\" usefulness=\"%s\"",
+ rules[r].number, usefulness);
+ if (rules[r].precsym)
+ fprintf (out, " percent_prec=\"%s\"",
+ xml_escape (rules[r].precsym->tag));
+ fputs (">\n", out);
+ }
+ rule_lhs_print_xml (&rules[r], out, level + 3);
+ rule_rhs_print_xml (&rules[r], out, level + 3);
+ xml_puts (out, level + 2, "</rule>");
+ }
+ if (!first)
+ xml_puts (out, level + 1, "</rules>");
+ else
+ xml_puts (out, level + 1, "<rules/>");
+}
+
+void
+grammar_dump (FILE *out, const char *title)
+{
+ fprintf (out, "%s\n\n", title);
+ fprintf (out,
+ "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nritems = %d\n\n",
+ ntokens, nvars, nsyms, nrules, nritems);
+
+
+ fprintf (out, "Variables\n---------\n\n");
+ {
+ symbol_number i;
+ fprintf (out, "Value Sprec Sassoc Tag\n");
+
+ for (i = ntokens; i < nsyms; i++)
+ fprintf (out, "%5d %5d %5d %s\n",
+ i,
+ symbols[i]->prec, symbols[i]->assoc,
+ symbols[i]->tag);
+ fprintf (out, "\n\n");
+ }
+
+ fprintf (out, "Rules\n-----\n\n");
+ {
+ rule_number i;
+ fprintf (out,
+ "Num (Prec, Assoc, Useful, Ritem Range) Lhs"
+ " -> Rhs (Ritem range) [Num]\n");
+ for (i = 0; i < nrules + nuseless_productions; i++)
+ {
+ rule const *rule_i = &rules[i];
+ item_number *rp = NULL;
+ unsigned int rhs_itemno = rule_i->rhs - ritem;
+ unsigned int rhs_count = 0;
+ /* Find the last RHS index in ritems. */
+ for (rp = rule_i->rhs; *rp >= 0; ++rp)
+ ++rhs_count;
+ fprintf (out, "%3d (%2d, %2d, %2d, %2u-%2u) %2d ->",
+ i,
+ rule_i->prec ? rule_i->prec->prec : 0,
+ rule_i->prec ? rule_i->prec->assoc : 0,
+ rule_i->useful,
+ rhs_itemno,
+ rhs_itemno + rhs_count - 1,
+ rule_i->lhs->number);
+ /* Dumped the RHS. */
+ for (rp = rule_i->rhs; *rp >= 0; rp++)
+ fprintf (out, " %3d", *rp);
+ fprintf (out, " [%d]\n", item_number_as_rule_number (*rp));
+ }
+ }
+ fprintf (out, "\n\n");
+
+ fprintf (out, "Rules interpreted\n-----------------\n\n");
+ {
+ rule_number r;
+ for (r = 0; r < nrules + nuseless_productions; r++)
+ {
+ fprintf (out, "%-5d %s:", r, rules[r].lhs->tag);
+ rule_rhs_print (&rules[r], out);
+ fprintf (out, "\n");
+ }
+ }
+ fprintf (out, "\n\n");
+}
+
+void
+grammar_rules_useless_report (const char *message)
+{
+ rule_number r;
+ for (r = 0; r < nrules ; ++r)
+ if (!rules[r].useful)
+ complain (&rules[r].location, Wother, "%s", message);
+}
+
+void
+grammar_free (void)
+{
+ if (ritem)
+ free (ritem - 1);
+ free (rules);
+ free (token_translations);
+ /* Free the symbol table data structure. */
+ symbols_free ();
+ free_merger_functions ();
+}
diff --git a/contrib/tools/bison/bison/src/gram.h b/contrib/tools/bison/bison/src/gram.h
index c1dd9a648a..c92a6306ba 100644
--- a/contrib/tools/bison/bison/src/gram.h
+++ b/contrib/tools/bison/bison/src/gram.h
@@ -1,273 +1,273 @@
-/* Data definitions for internal representation of Bison's input.
-
- Copyright (C) 1984, 1986, 1989, 1992, 2001-2007, 2009-2013 Free
- Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef GRAM_H_
-# define GRAM_H_
-
-/* Representation of the grammar rules:
-
- NTOKENS is the number of tokens, and NVARS is the number of
- variables (nonterminals). NSYMS is the total number, ntokens +
- nvars.
-
- Each symbol (either token or variable) receives a symbol number.
- Numbers 0 to NTOKENS - 1 are for tokens, and NTOKENS to NSYMS - 1
- are for variables. Symbol number zero is the end-of-input token.
- This token is counted in ntokens. The true number of token values
- assigned is NTOKENS reduced by one for each alias declaration.
-
- The rules receive rule numbers 1 to NRULES in the order they are
- written. More precisely Bison augments the grammar with the
- initial rule, '$accept: START-SYMBOL $end', which is numbered 1,
- all the user rules are 2, 3 etc. Each time a rule number is
- presented to the user, we subtract 1, so *displayed* rule numbers
- are 0, 1, 2...
-
- Internally, we cannot use the number 0 for a rule because for
- instance RITEM stores both symbol (the RHS) and rule numbers: the
- symbols are shorts >= 0, and rule number are stored negative.
- Therefore 0 cannot be used, since it would be both the rule number
- 0, and the token $end).
-
- Actions are accessed via the rule number.
-
- The rules themselves are described by several arrays: amongst which
- RITEM, and RULES.
-
- RULES is an array of rules, whose members are:
-
- RULES[R].lhs -- the symbol of the left hand side of rule R.
-
- RULES[R].rhs -- the index in RITEM of the beginning of the portion
- for rule R.
-
- RULES[R].prec -- the symbol providing the precedence level of R.
-
- RULES[R].precsym -- the symbol attached (via %prec) to give its
- precedence to R. Of course, if set, it is equal to 'prec', but we
- need to distinguish one from the other when reducing: a symbol used
- in a %prec is not useless.
-
- RULES[R].assoc -- the associativity of R.
-
- RULES[R].dprec -- the dynamic precedence level of R (for GLR
- parsing).
-
- RULES[R].merger -- index of merging function for R (for GLR
- parsing).
-
- RULES[R].line -- the line where R was defined.
-
- RULES[R].useful -- true iff the rule is used (i.e., false if thrown
- away by reduce).
-
- The right hand side is stored as symbol numbers in a portion of
- RITEM.
-
- The length of the portion is one greater than the number of symbols
- in the rule's right hand side. The last element in the portion
- contains minus R, which identifies it as the end of a portion and
- says which rule it is for.
-
- The portions of RITEM come in order of increasing rule number.
- NRITEMS is the total length of RITEM. Each element of RITEM is
- called an "item" and its index in RITEM is an item number.
-
- Item numbers are used in the finite state machine to represent
- places that parsing can get to.
-
- SYMBOLS[I]->prec records the precedence level of each symbol.
-
- Precedence levels are assigned in increasing order starting with 1
- so that numerically higher precedence values mean tighter binding
- as they ought to. Zero as a symbol or rule's precedence means none
- is assigned.
-
- Associativities are recorded similarly in SYMBOLS[I]->assoc. */
-
-# include "location.h"
-# include "symtab.h"
-
-# define ISTOKEN(i) ((i) < ntokens)
-# define ISVAR(i) ((i) >= ntokens)
-
-extern int nsyms;
-extern int ntokens;
-extern int nvars;
-
-typedef int item_number;
-# define ITEM_NUMBER_MAX INT_MAX
-extern item_number *ritem;
-extern unsigned int nritems;
-
-/* There is weird relationship between OT1H item_number and OTOH
- symbol_number and rule_number: we store the latter in
- item_number. symbol_number values are stored as-is, while
- the negation of (rule_number + 1) is stored.
-
- Therefore, a symbol_number must be a valid item_number, and we
- sometimes have to perform the converse transformation. */
-
-static inline item_number
-symbol_number_as_item_number (symbol_number sym)
-{
- return sym;
-}
-
-static inline symbol_number
-item_number_as_symbol_number (item_number i)
-{
- return i;
-}
-
-static inline bool
-item_number_is_symbol_number (item_number i)
-{
- return i >= 0;
-}
-
-/* Rule numbers. */
-typedef int rule_number;
-# define RULE_NUMBER_MAX INT_MAX
-extern rule_number nrules;
-
-static inline item_number
-rule_number_as_item_number (rule_number r)
-{
- return -1 - r;
-}
-
-static inline rule_number
-item_number_as_rule_number (item_number i)
-{
- return -1 - i;
-}
-
-static inline bool
-item_number_is_rule_number (item_number i)
-{
- return i < 0;
-}
-
-/*--------.
-| Rules. |
-`--------*/
-
-typedef struct
-{
- /* The number of the rule in the source. It is usually the index in
- RULES too, except if there are useless rules. */
- rule_number user_number;
-
- /* The index in RULES. Usually the rule number in the source,
- except if some rules are useless. */
- rule_number number;
-
- symbol *lhs;
- item_number *rhs;
-
- /* This symbol provides both the associativity, and the precedence. */
- symbol *prec;
-
- int dprec;
- int merger;
-
- /* This symbol was attached to the rule via %prec. */
- symbol *precsym;
-
- location location;
- bool useful;
- bool is_predicate;
-
- const char *action;
- location action_location;
-} rule;
-
-extern rule *rules;
-
-/* A function that selects a rule. */
-typedef bool (*rule_filter) (rule const *);
-
-/* Return true IFF the rule has a 'number' smaller than NRULES. That is, it is
- useful in the grammar. */
-bool rule_useful_in_grammar_p (rule const *r);
-
-/* Return true IFF the rule has a 'number' higher than NRULES. That is, it is
- useless in the grammar. */
-bool rule_useless_in_grammar_p (rule const *r);
-
-/* Return true IFF the rule is not flagged as useful but is useful in the
- grammar. In other words, it was discarded because of conflicts. */
-bool rule_useless_in_parser_p (rule const *r);
-
-/* Print this rule's number and lhs on OUT. If a PREVIOUS_LHS was
- already displayed (by a previous call for another rule), avoid
- useless repetitions. */
-void rule_lhs_print (rule const *r, symbol const *previous_lhs, FILE *out);
-void rule_lhs_print_xml (rule const *r, FILE *out, int level);
-
-/* Return the length of the RHS. */
-size_t rule_rhs_length (rule const *r);
-
-/* Print this rule's RHS on OUT. */
-void rule_rhs_print (rule const *r, FILE *out);
-
-
-
-
-/* Table of the symbols, indexed by the symbol number. */
-extern symbol **symbols;
-
-/* TOKEN_TRANSLATION -- a table indexed by a token number as returned
- by the user's yylex routine, it yields the internal token number
- used by the parser and throughout bison. */
-extern symbol_number *token_translations;
-extern int max_user_token_number;
-
-
-
-/* Dump RITEM for traces. */
-void ritem_print (FILE *out);
-
-/* Return the size of the longest rule RHS. */
-size_t ritem_longest_rhs (void);
-
-/* Print the grammar's rules that match FILTER on OUT under TITLE. */
-void grammar_rules_partial_print (FILE *out, const char *title,
- rule_filter filter);
-
-/* Print the grammar's useful rules on OUT. */
-void grammar_rules_print (FILE *out);
-/* Print all of the grammar's rules with a "usefulness" attribute. */
-void grammar_rules_print_xml (FILE *out, int level);
-
-/* Dump the grammar. */
-void grammar_dump (FILE *out, const char *title);
-
-/* Report on STDERR the rules that are not flagged USEFUL, using the
- MESSAGE (which can be 'rule useless in grammar' when invoked after grammar
- reduction, or 'rule useless in parser due to conflicts' after conflicts
- were taken into account). */
-void grammar_rules_useless_report (const char *message);
-
-/* Free the packed grammar. */
-void grammar_free (void);
-
-#endif /* !GRAM_H_ */
+/* Data definitions for internal representation of Bison's input.
+
+ Copyright (C) 1984, 1986, 1989, 1992, 2001-2007, 2009-2013 Free
+ Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GRAM_H_
+# define GRAM_H_
+
+/* Representation of the grammar rules:
+
+ NTOKENS is the number of tokens, and NVARS is the number of
+ variables (nonterminals). NSYMS is the total number, ntokens +
+ nvars.
+
+ Each symbol (either token or variable) receives a symbol number.
+ Numbers 0 to NTOKENS - 1 are for tokens, and NTOKENS to NSYMS - 1
+ are for variables. Symbol number zero is the end-of-input token.
+ This token is counted in ntokens. The true number of token values
+ assigned is NTOKENS reduced by one for each alias declaration.
+
+ The rules receive rule numbers 1 to NRULES in the order they are
+ written. More precisely Bison augments the grammar with the
+ initial rule, '$accept: START-SYMBOL $end', which is numbered 1,
+ all the user rules are 2, 3 etc. Each time a rule number is
+ presented to the user, we subtract 1, so *displayed* rule numbers
+ are 0, 1, 2...
+
+ Internally, we cannot use the number 0 for a rule because for
+ instance RITEM stores both symbol (the RHS) and rule numbers: the
+ symbols are shorts >= 0, and rule number are stored negative.
+ Therefore 0 cannot be used, since it would be both the rule number
+ 0, and the token $end).
+
+ Actions are accessed via the rule number.
+
+ The rules themselves are described by several arrays: amongst which
+ RITEM, and RULES.
+
+ RULES is an array of rules, whose members are:
+
+ RULES[R].lhs -- the symbol of the left hand side of rule R.
+
+ RULES[R].rhs -- the index in RITEM of the beginning of the portion
+ for rule R.
+
+ RULES[R].prec -- the symbol providing the precedence level of R.
+
+ RULES[R].precsym -- the symbol attached (via %prec) to give its
+ precedence to R. Of course, if set, it is equal to 'prec', but we
+ need to distinguish one from the other when reducing: a symbol used
+ in a %prec is not useless.
+
+ RULES[R].assoc -- the associativity of R.
+
+ RULES[R].dprec -- the dynamic precedence level of R (for GLR
+ parsing).
+
+ RULES[R].merger -- index of merging function for R (for GLR
+ parsing).
+
+ RULES[R].line -- the line where R was defined.
+
+ RULES[R].useful -- true iff the rule is used (i.e., false if thrown
+ away by reduce).
+
+ The right hand side is stored as symbol numbers in a portion of
+ RITEM.
+
+ The length of the portion is one greater than the number of symbols
+ in the rule's right hand side. The last element in the portion
+ contains minus R, which identifies it as the end of a portion and
+ says which rule it is for.
+
+ The portions of RITEM come in order of increasing rule number.
+ NRITEMS is the total length of RITEM. Each element of RITEM is
+ called an "item" and its index in RITEM is an item number.
+
+ Item numbers are used in the finite state machine to represent
+ places that parsing can get to.
+
+ SYMBOLS[I]->prec records the precedence level of each symbol.
+
+ Precedence levels are assigned in increasing order starting with 1
+ so that numerically higher precedence values mean tighter binding
+ as they ought to. Zero as a symbol or rule's precedence means none
+ is assigned.
+
+ Associativities are recorded similarly in SYMBOLS[I]->assoc. */
+
+# include "location.h"
+# include "symtab.h"
+
+# define ISTOKEN(i) ((i) < ntokens)
+# define ISVAR(i) ((i) >= ntokens)
+
+extern int nsyms;
+extern int ntokens;
+extern int nvars;
+
+typedef int item_number;
+# define ITEM_NUMBER_MAX INT_MAX
+extern item_number *ritem;
+extern unsigned int nritems;
+
+/* There is weird relationship between OT1H item_number and OTOH
+ symbol_number and rule_number: we store the latter in
+ item_number. symbol_number values are stored as-is, while
+ the negation of (rule_number + 1) is stored.
+
+ Therefore, a symbol_number must be a valid item_number, and we
+ sometimes have to perform the converse transformation. */
+
+static inline item_number
+symbol_number_as_item_number (symbol_number sym)
+{
+ return sym;
+}
+
+static inline symbol_number
+item_number_as_symbol_number (item_number i)
+{
+ return i;
+}
+
+static inline bool
+item_number_is_symbol_number (item_number i)
+{
+ return i >= 0;
+}
+
+/* Rule numbers. */
+typedef int rule_number;
+# define RULE_NUMBER_MAX INT_MAX
+extern rule_number nrules;
+
+static inline item_number
+rule_number_as_item_number (rule_number r)
+{
+ return -1 - r;
+}
+
+static inline rule_number
+item_number_as_rule_number (item_number i)
+{
+ return -1 - i;
+}
+
+static inline bool
+item_number_is_rule_number (item_number i)
+{
+ return i < 0;
+}
+
+/*--------.
+| Rules. |
+`--------*/
+
+typedef struct
+{
+ /* The number of the rule in the source. It is usually the index in
+ RULES too, except if there are useless rules. */
+ rule_number user_number;
+
+ /* The index in RULES. Usually the rule number in the source,
+ except if some rules are useless. */
+ rule_number number;
+
+ symbol *lhs;
+ item_number *rhs;
+
+ /* This symbol provides both the associativity, and the precedence. */
+ symbol *prec;
+
+ int dprec;
+ int merger;
+
+ /* This symbol was attached to the rule via %prec. */
+ symbol *precsym;
+
+ location location;
+ bool useful;
+ bool is_predicate;
+
+ const char *action;
+ location action_location;
+} rule;
+
+extern rule *rules;
+
+/* A function that selects a rule. */
+typedef bool (*rule_filter) (rule const *);
+
+/* Return true IFF the rule has a 'number' smaller than NRULES. That is, it is
+ useful in the grammar. */
+bool rule_useful_in_grammar_p (rule const *r);
+
+/* Return true IFF the rule has a 'number' higher than NRULES. That is, it is
+ useless in the grammar. */
+bool rule_useless_in_grammar_p (rule const *r);
+
+/* Return true IFF the rule is not flagged as useful but is useful in the
+ grammar. In other words, it was discarded because of conflicts. */
+bool rule_useless_in_parser_p (rule const *r);
+
+/* Print this rule's number and lhs on OUT. If a PREVIOUS_LHS was
+ already displayed (by a previous call for another rule), avoid
+ useless repetitions. */
+void rule_lhs_print (rule const *r, symbol const *previous_lhs, FILE *out);
+void rule_lhs_print_xml (rule const *r, FILE *out, int level);
+
+/* Return the length of the RHS. */
+size_t rule_rhs_length (rule const *r);
+
+/* Print this rule's RHS on OUT. */
+void rule_rhs_print (rule const *r, FILE *out);
+
+
+
+
+/* Table of the symbols, indexed by the symbol number. */
+extern symbol **symbols;
+
+/* TOKEN_TRANSLATION -- a table indexed by a token number as returned
+ by the user's yylex routine, it yields the internal token number
+ used by the parser and throughout bison. */
+extern symbol_number *token_translations;
+extern int max_user_token_number;
+
+
+
+/* Dump RITEM for traces. */
+void ritem_print (FILE *out);
+
+/* Return the size of the longest rule RHS. */
+size_t ritem_longest_rhs (void);
+
+/* Print the grammar's rules that match FILTER on OUT under TITLE. */
+void grammar_rules_partial_print (FILE *out, const char *title,
+ rule_filter filter);
+
+/* Print the grammar's useful rules on OUT. */
+void grammar_rules_print (FILE *out);
+/* Print all of the grammar's rules with a "usefulness" attribute. */
+void grammar_rules_print_xml (FILE *out, int level);
+
+/* Dump the grammar. */
+void grammar_dump (FILE *out, const char *title);
+
+/* Report on STDERR the rules that are not flagged USEFUL, using the
+ MESSAGE (which can be 'rule useless in grammar' when invoked after grammar
+ reduction, or 'rule useless in parser due to conflicts' after conflicts
+ were taken into account). */
+void grammar_rules_useless_report (const char *message);
+
+/* Free the packed grammar. */
+void grammar_free (void);
+
+#endif /* !GRAM_H_ */
diff --git a/contrib/tools/bison/bison/src/graphviz.c b/contrib/tools/bison/bison/src/graphviz.c
index 5ee41e73f3..e593c23378 100644
--- a/contrib/tools/bison/bison/src/graphviz.c
+++ b/contrib/tools/bison/bison/src/graphviz.c
@@ -1,218 +1,218 @@
-/* Output Graphviz specification of a state machine generated by Bison.
-
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert and Satya Kiran Popuri. */
-
-#include <config.h>
-#include "system.h"
-
-#include <quotearg.h>
-
-#include "files.h"
-#include "gram.h"
-#include "graphviz.h"
-#include "tables.h"
-
-/* Return an unambiguous printable representation for NAME, suitable
- for C strings. Use slot 2 since the user may use slots 0 and 1. */
-
-static char *
-quote (char const *name)
-{
- return quotearg_n_style (2, c_quoting_style, name);
-}
-
-void
-start_graph (FILE *fout)
-{
- fprintf (fout,
- _("// Generated by %s.\n"
- "// Report bugs to <%s>.\n"
- "// Home page: <%s>.\n"
- "\n"),
- PACKAGE_STRING,
- PACKAGE_BUGREPORT,
- PACKAGE_URL);
- fprintf (fout,
- "digraph %s\n"
- "{\n",
- quote (grammar_file));
- fprintf (fout,
- " node [fontname = courier, shape = box, colorscheme = paired6]\n"
- " edge [fontname = courier]\n"
- "\n");
-}
-
-void
-output_node (int id, char const *label, FILE *fout)
-{
- fprintf (fout, " %d [label=\"%s\"]\n", id, label);
-}
-
-void
-output_edge (int source, int destination, char const *label,
- char const *style, FILE *fout)
-{
- fprintf (fout, " %d -> %d [style=%s", source, destination, style);
- if (label)
- fprintf (fout, " label=%s", quote (label));
- fputs ("]\n", fout);
-}
-
-char const *
-escape (char const *name)
-{
- char *q = quote (name);
- q[strlen (q) - 1] = '\0';
- return q + 1;
-}
-
-static void
-no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
-{
- int n;
- *no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
- bitset_zero (*no_reduce_set);
- FOR_EACH_SHIFT (s->transitions, n)
- bitset_set (*no_reduce_set, TRANSITION_SYMBOL (s->transitions, n));
- for (n = 0; n < s->errs->num; ++n)
- if (s->errs->symbols[n])
- bitset_set (*no_reduce_set, s->errs->symbols[n]->number);
-}
-
-static void
-conclude_red (struct obstack *out, int source, rule_number ruleno,
- bool enabled, bool first, FILE *fout)
-{
- /* If no lookahead tokens were valid transitions, this reduction is
- actually hidden, so cancel everything. */
- if (first)
- (void) obstack_finish0 (out);
- else
- {
- char const *ed = enabled ? "" : "d";
- char const *color = enabled ? ruleno ? "3" : "1" : "5";
-
- /* First, build the edge's head. The name of reduction nodes is "nRm",
- with n the source state and m the rule number. This is because we
- don't want all the reductions bearing a same rule number to point to
- the same state, since that is not the desired format. */
- fprintf (fout, " %1$d -> \"%1$dR%2$d%3$s\" [",
- source, ruleno, ed);
-
- /* (The lookahead tokens have been added to the beginning of the
- obstack, in the caller function.) */
- if (! obstack_empty_p (out))
- {
- char *label = obstack_finish0 (out);
- fprintf (fout, "label=\"[%s]\", ", label);
- obstack_free (out, label);
- }
-
- /* Then, the edge's tail. */
- fprintf (fout, "style=solid]\n");
-
- /* Build the associated diamond representation of the target rule. */
- fprintf (fout, " \"%dR%d%s\" [label=\"",
- source, ruleno, ed);
- if (ruleno)
- fprintf (fout, "R%d", ruleno);
- else
- fprintf (fout, "Acc");
-
- fprintf (fout, "\", fillcolor=%s, shape=diamond, style=filled]\n",
- color);
- }
-}
-
-static bool
-print_token (struct obstack *out, bool first, char const *tok)
-{
- char const *q = escape (tok);
-
- if (! first)
- obstack_sgrow (out, ", ");
- obstack_sgrow (out, q);
- return false;
-}
-
-void
-output_red (state const *s, reductions const *reds, FILE *fout)
-{
- bitset no_reduce_set;
- int j;
- int source = s->number;
-
- /* Two obstacks are needed: one for the enabled reductions, and one
- for the disabled reductions, because in the end we want two
- separate edges, even though in most cases only one will actually
- be printed. */
- struct obstack dout;
- struct obstack eout;
-
- no_reduce_bitset_init (s, &no_reduce_set);
- obstack_init (&dout);
- obstack_init (&eout);
-
- for (j = 0; j < reds->num; ++j)
- {
- bool defaulted = false;
- bool firstd = true;
- bool firste = true;
- rule_number ruleno = reds->rules[j]->number;
- rule *default_reduction = NULL;
-
- if (yydefact[s->number] != 0)
- default_reduction = &rules[yydefact[s->number] - 1];
-
- /* Build the lookahead tokens lists, one for enabled transitions and one
- for disabled transistions. */
- if (default_reduction && default_reduction == reds->rules[j])
- defaulted = true;
- if (reds->lookahead_tokens)
- {
- int i;
- for (i = 0; i < ntokens; i++)
- if (bitset_test (reds->lookahead_tokens[j], i))
- {
- if (bitset_test (no_reduce_set, i))
- firstd = print_token (&dout, firstd, symbols[i]->tag);
- else
- {
- if (! defaulted)
- firste = print_token (&eout, firste, symbols[i]->tag);
- bitset_set (no_reduce_set, i);
- }
- }
- }
-
- /* Do the actual output. */
- conclude_red (&dout, source, ruleno, false, firstd, fout);
- conclude_red (&eout, source, ruleno, true, firste && !defaulted, fout);
- }
- obstack_free (&dout, 0);
- obstack_free (&eout, 0);
- bitset_free (no_reduce_set);
-}
-
-void
-finish_graph (FILE *fout)
-{
- fputs ("}\n", fout);
-}
+/* Output Graphviz specification of a state machine generated by Bison.
+
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert and Satya Kiran Popuri. */
+
+#include <config.h>
+#include "system.h"
+
+#include <quotearg.h>
+
+#include "files.h"
+#include "gram.h"
+#include "graphviz.h"
+#include "tables.h"
+
+/* Return an unambiguous printable representation for NAME, suitable
+ for C strings. Use slot 2 since the user may use slots 0 and 1. */
+
+static char *
+quote (char const *name)
+{
+ return quotearg_n_style (2, c_quoting_style, name);
+}
+
+void
+start_graph (FILE *fout)
+{
+ fprintf (fout,
+ _("// Generated by %s.\n"
+ "// Report bugs to <%s>.\n"
+ "// Home page: <%s>.\n"
+ "\n"),
+ PACKAGE_STRING,
+ PACKAGE_BUGREPORT,
+ PACKAGE_URL);
+ fprintf (fout,
+ "digraph %s\n"
+ "{\n",
+ quote (grammar_file));
+ fprintf (fout,
+ " node [fontname = courier, shape = box, colorscheme = paired6]\n"
+ " edge [fontname = courier]\n"
+ "\n");
+}
+
+void
+output_node (int id, char const *label, FILE *fout)
+{
+ fprintf (fout, " %d [label=\"%s\"]\n", id, label);
+}
+
+void
+output_edge (int source, int destination, char const *label,
+ char const *style, FILE *fout)
+{
+ fprintf (fout, " %d -> %d [style=%s", source, destination, style);
+ if (label)
+ fprintf (fout, " label=%s", quote (label));
+ fputs ("]\n", fout);
+}
+
+char const *
+escape (char const *name)
+{
+ char *q = quote (name);
+ q[strlen (q) - 1] = '\0';
+ return q + 1;
+}
+
+static void
+no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
+{
+ int n;
+ *no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
+ bitset_zero (*no_reduce_set);
+ FOR_EACH_SHIFT (s->transitions, n)
+ bitset_set (*no_reduce_set, TRANSITION_SYMBOL (s->transitions, n));
+ for (n = 0; n < s->errs->num; ++n)
+ if (s->errs->symbols[n])
+ bitset_set (*no_reduce_set, s->errs->symbols[n]->number);
+}
+
+static void
+conclude_red (struct obstack *out, int source, rule_number ruleno,
+ bool enabled, bool first, FILE *fout)
+{
+ /* If no lookahead tokens were valid transitions, this reduction is
+ actually hidden, so cancel everything. */
+ if (first)
+ (void) obstack_finish0 (out);
+ else
+ {
+ char const *ed = enabled ? "" : "d";
+ char const *color = enabled ? ruleno ? "3" : "1" : "5";
+
+ /* First, build the edge's head. The name of reduction nodes is "nRm",
+ with n the source state and m the rule number. This is because we
+ don't want all the reductions bearing a same rule number to point to
+ the same state, since that is not the desired format. */
+ fprintf (fout, " %1$d -> \"%1$dR%2$d%3$s\" [",
+ source, ruleno, ed);
+
+ /* (The lookahead tokens have been added to the beginning of the
+ obstack, in the caller function.) */
+ if (! obstack_empty_p (out))
+ {
+ char *label = obstack_finish0 (out);
+ fprintf (fout, "label=\"[%s]\", ", label);
+ obstack_free (out, label);
+ }
+
+ /* Then, the edge's tail. */
+ fprintf (fout, "style=solid]\n");
+
+ /* Build the associated diamond representation of the target rule. */
+ fprintf (fout, " \"%dR%d%s\" [label=\"",
+ source, ruleno, ed);
+ if (ruleno)
+ fprintf (fout, "R%d", ruleno);
+ else
+ fprintf (fout, "Acc");
+
+ fprintf (fout, "\", fillcolor=%s, shape=diamond, style=filled]\n",
+ color);
+ }
+}
+
+static bool
+print_token (struct obstack *out, bool first, char const *tok)
+{
+ char const *q = escape (tok);
+
+ if (! first)
+ obstack_sgrow (out, ", ");
+ obstack_sgrow (out, q);
+ return false;
+}
+
+void
+output_red (state const *s, reductions const *reds, FILE *fout)
+{
+ bitset no_reduce_set;
+ int j;
+ int source = s->number;
+
+ /* Two obstacks are needed: one for the enabled reductions, and one
+ for the disabled reductions, because in the end we want two
+ separate edges, even though in most cases only one will actually
+ be printed. */
+ struct obstack dout;
+ struct obstack eout;
+
+ no_reduce_bitset_init (s, &no_reduce_set);
+ obstack_init (&dout);
+ obstack_init (&eout);
+
+ for (j = 0; j < reds->num; ++j)
+ {
+ bool defaulted = false;
+ bool firstd = true;
+ bool firste = true;
+ rule_number ruleno = reds->rules[j]->number;
+ rule *default_reduction = NULL;
+
+ if (yydefact[s->number] != 0)
+ default_reduction = &rules[yydefact[s->number] - 1];
+
+ /* Build the lookahead tokens lists, one for enabled transitions and one
+ for disabled transistions. */
+ if (default_reduction && default_reduction == reds->rules[j])
+ defaulted = true;
+ if (reds->lookahead_tokens)
+ {
+ int i;
+ for (i = 0; i < ntokens; i++)
+ if (bitset_test (reds->lookahead_tokens[j], i))
+ {
+ if (bitset_test (no_reduce_set, i))
+ firstd = print_token (&dout, firstd, symbols[i]->tag);
+ else
+ {
+ if (! defaulted)
+ firste = print_token (&eout, firste, symbols[i]->tag);
+ bitset_set (no_reduce_set, i);
+ }
+ }
+ }
+
+ /* Do the actual output. */
+ conclude_red (&dout, source, ruleno, false, firstd, fout);
+ conclude_red (&eout, source, ruleno, true, firste && !defaulted, fout);
+ }
+ obstack_free (&dout, 0);
+ obstack_free (&eout, 0);
+ bitset_free (no_reduce_set);
+}
+
+void
+finish_graph (FILE *fout)
+{
+ fputs ("}\n", fout);
+}
diff --git a/contrib/tools/bison/bison/src/graphviz.h b/contrib/tools/bison/bison/src/graphviz.h
index 0254ef748b..67efe53313 100644
--- a/contrib/tools/bison/bison/src/graphviz.h
+++ b/contrib/tools/bison/bison/src/graphviz.h
@@ -1,71 +1,71 @@
-/* Output Graphviz specification of a state machine generated by Bison.
-
- Copyright (C) 2006, 2010-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert and Satya Kiran Popuri. */
-
-#ifndef GRAPHVIZ_H_
-# define GRAPHVIZ_H_
-
-# include "state.h"
-
-/** Begin a Dot graph.
- *
- * \param fout output stream.
- */
-void start_graph (FILE *fout);
-
-/** Output a Dot node.
- *
- * \param id identifier of the node
- * \param label human readable label of the node (no Dot escaping needed).
- * \param fout output stream.
- */
-void output_node (int id, char const *label, FILE *fout);
-
-/** Output a Dot edge.
- * \param source id of the source node
- * \param destination id of the target node
- * \param label human readable label of the edge
- * (no Dot escaping needed). Can be 0.
- * \param style Dot style of the edge (e.g., "dotted" or "solid").
- * \param fout output stream.
- */
-void output_edge (int source, int destination, char const *label,
- char const *style, FILE *fout);
-
-/** Output a reduction.
- * \param s current state
- * \param reds the set of reductions
- * \param fout output stream.
- */
-void output_red (state const *s, reductions const *reds, FILE *fout);
-
-/** End a Dot graph.
- *
- * \param fout output stream.
- */
-void finish_graph (FILE *fout);
-
-/** Escape a lookahead token.
- *
- * \param name the token.
- */
-char const *escape (char const *name);
-
-#endif /* ! GRAPHVIZ_H_ */
+/* Output Graphviz specification of a state machine generated by Bison.
+
+ Copyright (C) 2006, 2010-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert and Satya Kiran Popuri. */
+
+#ifndef GRAPHVIZ_H_
+# define GRAPHVIZ_H_
+
+# include "state.h"
+
+/** Begin a Dot graph.
+ *
+ * \param fout output stream.
+ */
+void start_graph (FILE *fout);
+
+/** Output a Dot node.
+ *
+ * \param id identifier of the node
+ * \param label human readable label of the node (no Dot escaping needed).
+ * \param fout output stream.
+ */
+void output_node (int id, char const *label, FILE *fout);
+
+/** Output a Dot edge.
+ * \param source id of the source node
+ * \param destination id of the target node
+ * \param label human readable label of the edge
+ * (no Dot escaping needed). Can be 0.
+ * \param style Dot style of the edge (e.g., "dotted" or "solid").
+ * \param fout output stream.
+ */
+void output_edge (int source, int destination, char const *label,
+ char const *style, FILE *fout);
+
+/** Output a reduction.
+ * \param s current state
+ * \param reds the set of reductions
+ * \param fout output stream.
+ */
+void output_red (state const *s, reductions const *reds, FILE *fout);
+
+/** End a Dot graph.
+ *
+ * \param fout output stream.
+ */
+void finish_graph (FILE *fout);
+
+/** Escape a lookahead token.
+ *
+ * \param name the token.
+ */
+char const *escape (char const *name);
+
+#endif /* ! GRAPHVIZ_H_ */
diff --git a/contrib/tools/bison/bison/src/ielr.c b/contrib/tools/bison/bison/src/ielr.c
index 38156b384d..d1e836dded 100644
--- a/contrib/tools/bison/bison/src/ielr.c
+++ b/contrib/tools/bison/bison/src/ielr.c
@@ -1,1200 +1,1200 @@
-/* IELR main implementation.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "ielr.h"
-
-#include <bitset.h>
-#include <timevar.h>
-
-#include "AnnotationList.h"
-#include "derives.h"
-#include "getargs.h"
-#include "lalr.h"
-#include "muscle-tab.h"
-#include "nullable.h"
-#include "relation.h"
-#include "state.h"
-#include "symtab.h"
-
-/** Records the value of the \%define variable lr.type. */
-typedef enum { LR_TYPE__LALR, LR_TYPE__IELR, LR_TYPE__CANONICAL_LR } LrType;
-
-/**
- * \post:
- * - \c result = a new \c bitset of size \c ::nritems such that any bit \c i
- * is set iff <tt>ritem[i]</tt> is a nonterminal after which all ritems in
- * the same RHS are nullable nonterminals. In other words, the follows of
- * a goto on <tt>ritem[i]</tt> include the lookahead set of the item.
- */
-static bitset
-ielr_compute_ritem_sees_lookahead_set (void)
-{
- bitset result = bitset_create (nritems, BITSET_FIXED);
- unsigned int i = nritems-1;
- while (i>0)
- {
- --i;
- while (!item_number_is_rule_number (ritem[i])
- && ISVAR (ritem[i])
- && nullable [item_number_as_symbol_number (ritem[i]) - ntokens])
- bitset_set (result, i--);
- if (!item_number_is_rule_number (ritem[i]) && ISVAR (ritem[i]))
- bitset_set (result, i--);
- while (!item_number_is_rule_number (ritem[i]) && i>0)
- --i;
- }
- if (trace_flag & trace_ielr)
- {
- fprintf (stderr, "ritem_sees_lookahead_set:\n");
- debug_bitset (result);
- fprintf (stderr, "\n");
- }
- return result;
-}
-
-/**
- * \pre:
- * - \c ritem_sees_lookahead_set was computed by
- * \c ielr_compute_ritem_sees_lookahead_set.
- * \post:
- * - Each of \c *edgesp and \c *edge_countsp is a new array of size
- * \c ::ngotos.
- * - <tt>(*edgesp)[i]</tt> points to a \c goto_number array of size
- * <tt>(*edge_countsp)[i]+1</tt>.
- * - In such a \c goto_number array, the last element is \c ::END_NODE.
- * - All remaining elements are the indices of the gotos to which there is an
- * internal follow edge from goto \c i.
- * - There is an internal follow edge from goto \c i to goto \c j iff both:
- * - The from states of gotos \c i and \c j are the same.
- * - The transition nonterminal for goto \c i appears as the first RHS
- * symbol of at least one production for which both:
- * - The LHS is the transition symbol of goto \c j.
- * - All other RHS symbols are nullable nonterminals.
- * - In other words, the follows of goto \c i include the follows of
- * goto \c j and it's an internal edge because the from states are the
- * same.
- */
-static void
-ielr_compute_internal_follow_edges (bitset ritem_sees_lookahead_set,
- goto_number ***edgesp, int **edge_countsp)
-{
- *edgesp = xnmalloc (ngotos, sizeof **edgesp);
- *edge_countsp = xnmalloc (ngotos, sizeof **edge_countsp);
- {
- bitset sources = bitset_create (ngotos, BITSET_FIXED);
- goto_number i;
- for (i = 0; i < ngotos; ++i)
- (*edge_countsp)[i] = 0;
- for (i = 0; i < ngotos; ++i)
- {
- int nsources = 0;
- {
- rule **rulep;
- for (rulep = derives[states[to_state[i]]->accessing_symbol
- - ntokens];
- *rulep;
- ++rulep)
- {
- /* If there is at least one RHS symbol, if the first RHS symbol
- is a nonterminal, and if all remaining RHS symbols (if any)
- are nullable nonterminals, create an edge from the LHS
- symbol's goto to the first RHS symbol's goto such that the RHS
- symbol's goto will be the source of the edge after the
- eventual relation_transpose below.
-
- Unlike in ielr_compute_always_follows, I use a bitset for
- edges rather than an array because it is possible that
- multiple RHS's with the same first symbol could fit and thus
- that we could end up with redundant edges. With the
- possibility of redundant edges, it's hard to know ahead of
- time how large to make such an array. Another possible
- redundancy is that source and destination might be the same
- goto. Eliminating all these possible redundancies now might
- possibly help performance a little. I have not proven any of
- this, but I'm guessing the bitset shouldn't entail much of a
- performance penalty, if any. */
- if (bitset_test (ritem_sees_lookahead_set,
- (*rulep)->rhs - ritem))
- {
- goto_number source =
- map_goto (from_state[i],
- item_number_as_symbol_number (*(*rulep)->rhs));
- if (i != source && !bitset_test (sources, source))
- {
- bitset_set (sources, source);
- ++nsources;
- ++(*edge_countsp)[source];
- }
- }
- }
- }
- if (nsources == 0)
- (*edgesp)[i] = NULL;
- else
- {
- (*edgesp)[i] = xnmalloc (nsources + 1, sizeof *(*edgesp)[i]);
- {
- bitset_iterator biter_source;
- bitset_bindex source;
- int j = 0;
- BITSET_FOR_EACH (biter_source, sources, source, 0)
- (*edgesp)[i][j++] = source;
- }
- (*edgesp)[i][nsources] = END_NODE;
- }
- bitset_zero (sources);
- }
- bitset_free (sources);
- }
-
- relation_transpose (edgesp, ngotos);
-
- if (trace_flag & trace_ielr)
- {
- fprintf (stderr, "internal_follow_edges:\n");
- relation_print (*edgesp, ngotos, stderr);
- }
-}
-
-/**
- * \pre:
- * - \c ritem_sees_lookahead_set was computed by
- * \c ielr_compute_ritem_sees_lookahead_set.
- * - \c internal_follow_edges was computed by
- * \c ielr_compute_internal_follow_edges.
- * \post:
- * - \c *follow_kernel_itemsp is a new \c bitsetv in which the number of rows
- * is \c ngotos and the number of columns is maximum number of kernel items
- * in any state.
- * - <tt>(*follow_kernel_itemsp)[i][j]</tt> is set iff the follows of goto
- * \c i include the lookahead set of item \c j in the from state of goto
- * \c i.
- * - Thus, <tt>(*follow_kernel_itemsp)[i][j]</tt> is always unset if there is
- * no item \c j in the from state of goto \c i.
- */
-static void
-ielr_compute_follow_kernel_items (bitset ritem_sees_lookahead_set,
- goto_number **internal_follow_edges,
- bitsetv *follow_kernel_itemsp)
-{
- {
- size_t max_nitems = 0;
- state_number i;
- for (i = 0; i < nstates; ++i)
- if (states[i]->nitems > max_nitems)
- max_nitems = states[i]->nitems;
- *follow_kernel_itemsp = bitsetv_create (ngotos, max_nitems, BITSET_FIXED);
- }
- {
- goto_number i;
- for (i = 0; i < ngotos; ++i)
- {
- size_t nitems = states[from_state[i]]->nitems;
- item_number *items = states[from_state[i]]->items;
- size_t j;
- for (j = 0; j < nitems; ++j)
- /* If this item has this goto and if all subsequent symbols in this
- RHS (if any) are nullable nonterminals, then record this item as
- one whose lookahead set is included in this goto's follows. */
- if (item_number_is_symbol_number (ritem[items[j]])
- && item_number_as_symbol_number (ritem[items[j]])
- == states[to_state[i]]->accessing_symbol
- && bitset_test (ritem_sees_lookahead_set, items[j]))
- bitset_set ((*follow_kernel_itemsp)[i], j);
- }
- }
- relation_digraph (internal_follow_edges, ngotos, follow_kernel_itemsp);
-
- if (trace_flag & trace_ielr)
- {
- fprintf (stderr, "follow_kernel_items:\n");
- debug_bitsetv (*follow_kernel_itemsp);
- }
-}
-
-/**
- * \pre
- * - \c *edgesp and \c edge_counts were computed by
- * \c ielr_compute_internal_follow_edges.
- * \post
- * - \c *always_followsp is a new \c bitsetv with \c ngotos rows and
- * \c ntokens columns.
- * - <tt>(*always_followsp)[i][j]</tt> is set iff token \c j is an always
- * follow (that is, it's computed by internal and successor edges) of goto
- * \c i.
- * - Rows of \c *edgesp have been realloc'ed and extended to include
- * successor follow edges. \c edge_counts has not been updated.
- */
-static void
-ielr_compute_always_follows (goto_number ***edgesp,
- int const edge_counts[],
- bitsetv *always_followsp)
-{
- *always_followsp = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
- {
- goto_number *edge_array = xnmalloc (ngotos, sizeof *edge_array);
- goto_number i;
- for (i = 0; i < ngotos; ++i)
- {
- goto_number nedges = edge_counts[i];
- {
- int j;
- transitions *trans = states[to_state[i]]->transitions;
- FOR_EACH_SHIFT (trans, j)
- bitset_set ((*always_followsp)[i], TRANSITION_SYMBOL (trans, j));
- for (; j < trans->num; ++j)
- {
- symbol_number sym = TRANSITION_SYMBOL (trans, j);
- if (nullable[sym - ntokens])
- edge_array[nedges++] = map_goto (to_state[i], sym);
- }
- }
- if (nedges - edge_counts[i])
- {
- (*edgesp)[i] =
- xnrealloc ((*edgesp)[i], nedges + 1, sizeof *(*edgesp)[i]);
- memcpy ((*edgesp)[i] + edge_counts[i], edge_array + edge_counts[i],
- (nedges - edge_counts[i]) * sizeof *(*edgesp)[i]);
- (*edgesp)[i][nedges] = END_NODE;
- }
- }
- free (edge_array);
- }
- relation_digraph (*edgesp, ngotos, always_followsp);
-
- if (trace_flag & trace_ielr)
- {
- fprintf (stderr, "always follow edges:\n");
- relation_print (*edgesp, ngotos, stderr);
- fprintf (stderr, "always_follows:\n");
- debug_bitsetv (*always_followsp);
- }
-}
-
-/**
- * \post
- * - \c result is a new array of size \c ::nstates.
- * - <tt>result[i]</tt> is an array of pointers to the predecessor
- * <tt>state</tt>'s of state \c i.
- * - The last element of such an array is \c NULL.
- */
-static state ***
-ielr_compute_predecessors (void)
-{
- state_number i;
- int *predecessor_counts = xnmalloc (nstates, sizeof *predecessor_counts);
- state ***result = xnmalloc (nstates, sizeof *result);
- for (i = 0; i < nstates; ++i)
- predecessor_counts[i] = 0;
- for (i = 0; i < nstates; ++i)
- {
- int j;
- for (j = 0; j < states[i]->transitions->num; ++j)
- ++predecessor_counts[states[i]->transitions->states[j]->number];
- }
- for (i = 0; i < nstates; ++i)
- {
- result[i] = xnmalloc (predecessor_counts[i]+1, sizeof *result[i]);
- result[i][predecessor_counts[i]] = NULL;
- predecessor_counts[i] = 0;
- }
- for (i = 0; i < nstates; ++i)
- {
- int j;
- for (j = 0; j < states[i]->transitions->num; ++j)
- {
- state_number k = states[i]->transitions->states[j]->number;
- result[k][predecessor_counts[k]++] = states[i];
- }
- }
- free (predecessor_counts);
- return result;
-}
-
-/**
- * \post
- * - \c *follow_kernel_itemsp and \c *always_followsp were computed by
- * \c ielr_compute_follow_kernel_items and
- * \c ielr_compute_always_follows.
- * - Iff <tt>predecessorsp != NULL</tt>, then \c *predecessorsp was computed
- * by \c ielr_compute_predecessors.
- */
-static void
-ielr_compute_auxiliary_tables (bitsetv *follow_kernel_itemsp,
- bitsetv *always_followsp,
- state ****predecessorsp)
-{
- goto_number **edges;
- int *edge_counts;
- {
- bitset ritem_sees_lookahead_set = ielr_compute_ritem_sees_lookahead_set ();
- ielr_compute_internal_follow_edges (ritem_sees_lookahead_set,
- &edges, &edge_counts);
- ielr_compute_follow_kernel_items (ritem_sees_lookahead_set, edges,
- follow_kernel_itemsp);
- bitset_free (ritem_sees_lookahead_set);
- }
- ielr_compute_always_follows (&edges, edge_counts, always_followsp);
- {
- int i;
- for (i = 0; i < ngotos; ++i)
- free (edges[i]);
- }
- free (edges);
- free (edge_counts);
- if (predecessorsp)
- *predecessorsp = ielr_compute_predecessors ();
-}
-
-/**
- * \note
- * - FIXME: It might be an interesting experiment to compare the space and
- * time efficiency of computing \c item_lookahead_sets either:
- * - Fully up front.
- * - Just-in-time, as implemented below.
- * - Not at all. That is, just let annotations continue even when
- * unnecessary.
- */
-bool
-ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item,
- symbol_number lookahead, state ***predecessors,
- bitset **item_lookahead_sets)
-{
- if (!item_lookahead_sets[s->number])
- {
- size_t i;
- item_lookahead_sets[s->number] =
- xnmalloc (s->nitems, sizeof item_lookahead_sets[s->number][0]);
- for (i = 0; i < s->nitems; ++i)
- item_lookahead_sets[s->number][i] = NULL;
- }
- if (!item_lookahead_sets[s->number][item])
- {
- item_lookahead_sets[s->number][item] =
- bitset_create (ntokens, BITSET_FIXED);
- /* If this kernel item is the beginning of a RHS, it must be the kernel
- item in the start state, and so its LHS has no follows and no goto to
- check. If, instead, this kernel item is the successor of the start
- state's kernel item, there are still no follows and no goto. This
- situation is fortunate because we want to avoid the - 2 below in both
- cases.
-
- Actually, IELR(1) should never invoke this function for either of
- those cases because (1) follow_kernel_items will never reference a
- kernel item for this RHS because the end token blocks sight of the
- lookahead set from the RHS's only nonterminal, and (2) no reduction
- has a lookback dependency on this lookahead set. Nevertheless, I
- didn't change this test to an aver just in case the usage of this
- function evolves to need those two cases. In both cases, the current
- implementation returns the right result. */
- if (s->items[item] > 1)
- {
- /* If the LHS symbol of this item isn't known (because this is a
- top-level invocation), go get it. */
- if (!lhs)
- {
- unsigned int i;
- for (i = s->items[item];
- !item_number_is_rule_number (ritem[i]);
- ++i)
- ;
- lhs = rules[item_number_as_rule_number (ritem[i])].lhs->number;
- }
- /* If this kernel item is next to the beginning of the RHS, then
- check all predecessors' goto follows for the LHS. */
- if (item_number_is_rule_number (ritem[s->items[item] - 2]))
- {
- state **predecessor;
- aver (lhs != accept->number);
- for (predecessor = predecessors[s->number];
- *predecessor;
- ++predecessor)
- bitset_or (item_lookahead_sets[s->number][item],
- item_lookahead_sets[s->number][item],
- goto_follows[map_goto ((*predecessor)->number,
- lhs)]);
- }
- /* If this kernel item is later in the RHS, then check all
- predecessor items' lookahead sets. */
- else
- {
- state **predecessor;
- for (predecessor = predecessors[s->number];
- *predecessor;
- ++predecessor)
- {
- size_t predecessor_item;
- for (predecessor_item = 0;
- predecessor_item < (*predecessor)->nitems;
- ++predecessor_item)
- if ((*predecessor)->items[predecessor_item]
- == s->items[item] - 1)
- break;
- aver (predecessor_item != (*predecessor)->nitems);
- ielr_item_has_lookahead (*predecessor, lhs,
- predecessor_item, 0 /*irrelevant*/,
- predecessors, item_lookahead_sets);
- bitset_or (item_lookahead_sets[s->number][item],
- item_lookahead_sets[s->number][item],
- item_lookahead_sets[(*predecessor)->number]
- [predecessor_item]);
- }
- }
- }
- }
- return bitset_test (item_lookahead_sets[s->number][item], lookahead);
-}
-
-/**
- * \pre
- * - \c follow_kernel_items, \c always_follows, and \c predecessors
- * were computed by \c ielr_compute_auxiliary_tables.
- * \post
- * - Each of <tt>*inadequacy_listsp</tt> and <tt>*annotation_listsp</tt>
- * points to a new array of size \c ::nstates.
- * - For <tt>0 <= i < ::nstates</tt>:
- * - <tt>(*inadequacy_listsp)[i]</tt> contains the \c InadequacyList head
- * node for <tt>states[i]</tt>.
- * - <tt>(*annotation_listsp)[i]</tt> contains the \c AnnotationList head
- * node for <tt>states[i]</tt>.
- * - <tt>*max_annotationsp</tt> is the maximum number of annotations per
- * state.
- */
-static void
-ielr_compute_annotation_lists (bitsetv follow_kernel_items,
- bitsetv always_follows, state ***predecessors,
- AnnotationIndex *max_annotationsp,
- InadequacyList ***inadequacy_listsp,
- AnnotationList ***annotation_listsp,
- struct obstack *annotations_obstackp)
-{
- bitset **item_lookahead_sets =
- xnmalloc (nstates, sizeof *item_lookahead_sets);
- AnnotationIndex *annotation_counts =
- xnmalloc (nstates, sizeof *annotation_counts);
- ContributionIndex max_contributions = 0;
- unsigned int total_annotations = 0;
- state_number i;
-
- *inadequacy_listsp = xnmalloc (nstates, sizeof **inadequacy_listsp);
- *annotation_listsp = xnmalloc (nstates, sizeof **annotation_listsp);
- for (i = 0; i < nstates; ++i)
- {
- item_lookahead_sets[i] = NULL;
- (*inadequacy_listsp)[i] = NULL;
- (*annotation_listsp)[i] = NULL;
- annotation_counts[i] = 0;
- }
- {
- InadequacyListNodeCount inadequacy_list_node_count = 0;
- for (i = 0; i < nstates; ++i)
- AnnotationList__compute_from_inadequacies (
- states[i], follow_kernel_items, always_follows, predecessors,
- item_lookahead_sets, *inadequacy_listsp, *annotation_listsp,
- annotation_counts, &max_contributions, annotations_obstackp,
- &inadequacy_list_node_count);
- }
- *max_annotationsp = 0;
- for (i = 0; i < nstates; ++i)
- {
- if (annotation_counts[i] > *max_annotationsp)
- *max_annotationsp = annotation_counts[i];
- total_annotations += annotation_counts[i];
- }
- if (trace_flag & trace_ielr)
- {
- for (i = 0; i < nstates; ++i)
- {
- fprintf (stderr, "Inadequacy annotations for state %d:\n", i);
- AnnotationList__debug ((*annotation_listsp)[i],
- states[i]->nitems, 2);
- }
- fprintf (stderr, "Number of LR(0)/LALR(1) states: %d\n", nstates);
- fprintf (stderr, "Average number of annotations per state: %f\n",
- (float)total_annotations/nstates);
- fprintf (stderr, "Max number of annotations per state: %d\n",
- *max_annotationsp);
- fprintf (stderr, "Max number of contributions per annotation: %d\n",
- max_contributions);
- }
- for (i = 0; i < nstates; ++i)
- if (item_lookahead_sets[i])
- {
- size_t j;
- for (j = 0; j < states[i]->nitems; ++j)
- if (item_lookahead_sets[i][j])
- bitset_free (item_lookahead_sets[i][j]);
- free (item_lookahead_sets[i]);
- }
- free (item_lookahead_sets);
- free (annotation_counts);
-}
-
-typedef struct state_list {
- struct state_list *next;
- state *state;
- /** Has this state been recomputed as a successor of another state? */
- bool recomputedAsSuccessor;
- /**
- * \c NULL iff all lookahead sets are empty. <tt>lookaheads[i] = NULL</tt>
- * iff the lookahead set on item \c i is empty.
- */
- bitset *lookaheads;
- /**
- * nextIsocore is the next state in a circularly linked-list of all states
- * with the same core. The one originally computed by generate_states in
- * LR0.c is lr0Isocore.
- */
- struct state_list *lr0Isocore;
- struct state_list *nextIsocore;
-} state_list;
-
-/**
- * \pre
- * - \c follow_kernel_items and \c always_follows were computed by
- * \c ielr_compute_auxiliary_tables.
- * - <tt>n->class = nterm_sym</tt>.
- * \post
- * - \c follow_set contains the follow set for the goto on nonterminal \c n
- * in state \c s based on the lookaheads stored in <tt>s->lookaheads</tt>.
- */
-static void
-ielr_compute_goto_follow_set (bitsetv follow_kernel_items,
- bitsetv always_follows, state_list *s,
- symbol *n, bitset follow_set)
-{
- goto_number n_goto = map_goto (s->lr0Isocore->state->number, n->number);
- bitset_copy (follow_set, always_follows[n_goto]);
- if (s->lookaheads)
- {
- bitset_iterator biter_item;
- bitset_bindex item;
- BITSET_FOR_EACH (biter_item, follow_kernel_items[n_goto], item, 0)
- if (s->lookaheads[item])
- bitset_or (follow_set, follow_set, s->lookaheads[item]);
- }
-}
-
-/**
- * \pre
- * - \c follow_kernel_items and \c always_follows were computed by
- * \c ielr_compute_auxiliary_tables.
- * - \c lookahead_filter was computed by
- * \c AnnotationList__computeLookaheadFilter for the original LR(0) isocore
- * of \c t.
- * - The number of rows in \c lookaheads is at least the number of items in
- * \c t, and the number of columns is \c ::ntokens.
- * \post
- * - <tt>lookaheads[i][j]</tt> is set iff both:
- * - <tt>lookahead_filter[i][j]</tt> is set.
- * - The isocore of \c t that will be the transition successor of \c s will
- * inherit from \c s token \c j into the lookahead set of item \c i.
- */
-static void
-ielr_compute_lookaheads (bitsetv follow_kernel_items, bitsetv always_follows,
- state_list *s, state *t, bitsetv lookahead_filter,
- bitsetv lookaheads)
-{
- size_t s_item = 0;
- size_t t_item;
- bitsetv_zero (lookaheads);
- for (t_item = 0; t_item < t->nitems; ++t_item)
- {
- /* If this kernel item is the beginning of a RHS, it must be the
- kernel item in the start state, but t is supposed to be a successor
- state. If, instead, this kernel item is the successor of the start
- state's kernel item, the lookahead set is empty. This second case is
- a special case to avoid the - 2 below, but the next successor can be
- handled fine without special casing it. */
- aver (t->items[t_item] != 0);
- if (t->items[t_item] > 1
- && !bitset_empty_p (lookahead_filter[t_item]))
- {
- if (item_number_is_rule_number (ritem[t->items[t_item] - 2]))
- {
- unsigned int rule_item;
- for (rule_item = t->items[t_item];
- !item_number_is_rule_number (ritem[rule_item]);
- ++rule_item)
- ;
- ielr_compute_goto_follow_set (
- follow_kernel_items, always_follows, s,
- rules[item_number_as_rule_number (ritem[rule_item])].lhs,
- lookaheads[t_item]);
- }
- else if (s->lookaheads)
- {
- /* We don't have to start the s item search at the beginning
- every time because items from both states are sorted by their
- indices in ritem. */
- for (; s_item < s->state->nitems; ++s_item)
- if (s->state->items[s_item] == t->items[t_item] - 1)
- break;
- aver (s_item != s->state->nitems);
- if (s->lookaheads[s_item])
- bitset_copy (lookaheads[t_item], s->lookaheads[s_item]);
- }
- bitset_and (lookaheads[t_item],
- lookaheads[t_item], lookahead_filter[t_item]);
- }
- }
-}
-
-/**
- * \pre
- * - \c follow_kernel_items and \c always_follows were computed by
- * \c ielr_compute_auxiliary_tables.
- * - Either:
- * - <tt>annotation_lists = NULL</tt> and all bits in work2 are set.
- * - \c annotation_lists was computed by \c ielr_compute_annotation_lists.
- * - The number of rows in each of \c lookaheads and \c work2 is the maximum
- * number of items in any state. The number of columns in each is
- * \c ::ntokens.
- * - \c lookaheads was computed by \c ielr_compute_lookaheads for \c t.
- * - \c ::nstates is the total number of states, some not yet fully computed,
- * in the list ending at \c *last_statep. It is at least the number of
- * original LR(0) states.
- * - The size of \c work1 is at least the number of annotations for the LR(0)
- * isocore of \c t.
- * \post
- * - Either:
- * - In the case that <tt>annotation_lists != NULL</tt>,
- * <tt>lookaheads \@pre</tt> was merged with some isocore of \c t if
- * permitted by the annotations for the original LR(0) isocore of \c t.
- * If this changed the lookaheads in that isocore, those changes were
- * propagated to all already computed transition successors recursively
- * possibly resulting in the splitting of some of those successors.
- * - In the case that <tt>annotation_lists = NULL</tt>,
- * <tt>lookaheads \@pre</tt> was merged with some isocore of \c t if the
- * isocore's lookahead sets were identical to those specified by
- * <tt>lookaheads \@pre</tt>.
- * - If no such merge was permitted, a new isocore of \c t containing
- * <tt>lookaheads \@pre</tt> was appended to the state list whose
- * previous tail was <tt>*last_statep \@pre</tt> and \c ::nstates was
- * incremented. It was also appended to \c t's isocore list.
- * - <tt>*tp</tt> = the isocore of \c t into which
- * <tt>lookaheads \@pre</tt> was placed/merged.
- * - \c lookaheads, \c work1, and \c work2 may have been altered.
- */
-static void
-ielr_compute_state (bitsetv follow_kernel_items, bitsetv always_follows,
- AnnotationList **annotation_lists, state *t,
- bitsetv lookaheads, state_list **last_statep,
- ContributionIndex work1[], bitsetv work2, state **tp)
-{
- state_list *lr0_isocore = t->state_list->lr0Isocore;
- state_list **this_isocorep;
- bool has_lookaheads;
-
- /* Determine whether there's an isocore of t with which these lookaheads can
- be merged. */
- {
- AnnotationIndex ai;
- AnnotationList *a;
- if (annotation_lists)
- for (ai = 0, a = annotation_lists[lr0_isocore->state->number];
- a;
- ++ai, a = a->next)
- work1[ai] =
- AnnotationList__computeDominantContribution (
- a, lr0_isocore->state->nitems, lookaheads, false);
- for (this_isocorep = &t->state_list;
- this_isocorep == &t->state_list || *this_isocorep != t->state_list;
- this_isocorep = &(*this_isocorep)->nextIsocore)
- {
- if (!(*this_isocorep)->recomputedAsSuccessor)
- break;
- if (annotation_lists)
- {
- for (ai = 0, a = annotation_lists[lr0_isocore->state->number];
- a;
- ++ai, a = a->next)
- {
- if (work1[ai] != ContributionIndex__none)
- {
- /* This isocore compatibility test depends on the fact
- that, if the dominant contributions are the same for the
- two isocores, then merging their lookahead sets will not
- produce a state with a different dominant contribution.
- */
- ContributionIndex ci =
- AnnotationList__computeDominantContribution (
- a, lr0_isocore->state->nitems,
- (*this_isocorep)->lookaheads, false);
- if (ci != ContributionIndex__none && work1[ai] != ci)
- break;
- }
- }
- if (!a)
- break;
- }
- else
- {
- size_t i;
- for (i = 0; i < t->nitems; ++i)
- {
- if (!(*this_isocorep)->lookaheads
- || !(*this_isocorep)->lookaheads[i])
- {
- if (!bitset_empty_p (lookaheads[i]))
- break;
- }
- /* bitset_equal_p uses the size of the first argument,
- so lookaheads[i] must be the second argument. */
- else if (!bitset_equal_p ((*this_isocorep)->lookaheads[i],
- lookaheads[i]))
- break;
- }
- if (i == t->nitems)
- break;
- }
- }
- }
-
- has_lookaheads = false;
- {
- size_t i;
- for (i = 0; i < lr0_isocore->state->nitems; ++i)
- if (!bitset_empty_p (lookaheads[i]))
- {
- has_lookaheads = true;
- break;
- }
- }
-
- /* Merge with an existing isocore. */
- if (this_isocorep == &t->state_list || *this_isocorep != t->state_list)
- {
- bool new_lookaheads = false;
- *tp = (*this_isocorep)->state;
-
- /* Merge lookaheads into the state and record whether any of them are
- actually new. */
- if (has_lookaheads)
- {
- size_t i;
- if (!(*this_isocorep)->lookaheads)
- {
- (*this_isocorep)->lookaheads =
- xnmalloc (t->nitems, sizeof (*this_isocorep)->lookaheads);
- for (i = 0; i < t->nitems; ++i)
- (*this_isocorep)->lookaheads[i] = NULL;
- }
- for (i = 0; i < t->nitems; ++i)
- if (!bitset_empty_p (lookaheads[i]))
- {
- if (!(*this_isocorep)->lookaheads[i])
- (*this_isocorep)->lookaheads[i] =
- bitset_create (ntokens, BITSET_FIXED);
- bitset_andn (lookaheads[i],
- lookaheads[i], (*this_isocorep)->lookaheads[i]);
- bitset_or ((*this_isocorep)->lookaheads[i],
- lookaheads[i], (*this_isocorep)->lookaheads[i]);
- if (!bitset_empty_p (lookaheads[i]))
- new_lookaheads = true;
- }
- }
-
- /* If new lookaheads were merged, propagate those lookaheads to the
- successors, possibly splitting them. If *tp is being recomputed for
- the first time, this isn't necessary because the main
- ielr_split_states loop will handle the successors later. */
- if (!(*this_isocorep)->recomputedAsSuccessor)
- (*this_isocorep)->recomputedAsSuccessor = true;
- else if (new_lookaheads)
- {
- int i;
- /* When merging demands identical lookahead sets, it is impossible to
- merge new lookaheads. */
- aver (annotation_lists);
- for (i = 0; i < (*tp)->transitions->num; ++i)
- {
- state *t2 = (*tp)->transitions->states[i];
- /* At any time, there's at most one state for which we have so
- far initially recomputed only some of its successors in the
- main ielr_split_states loop. Because we recompute successors
- in order, we can just stop at the first such successor. Of
- course, *tp might be a state some of whose successors have
- been recomputed as successors of other states rather than as
- successors of *tp. It's fine if we go ahead and propagate to
- some of those. We'll propagate to them again (but stop when
- we see nothing changes) and to the others when we reach *tp in
- the main ielr_split_states loop later. */
- if (!t2->state_list->recomputedAsSuccessor)
- break;
- AnnotationList__computeLookaheadFilter (
- annotation_lists[t2->state_list->lr0Isocore->state->number],
- t2->nitems, work2);
- ielr_compute_lookaheads (follow_kernel_items, always_follows,
- (*this_isocorep), t2, work2,
- lookaheads);
- /* FIXME: If splitting t2 here, it's possible that lookaheads
- that had already propagated from *tp to t2 will be left in t2
- after *tp has been removed as t2's predecessor:
- - We're going to recompute all lookaheads in phase 4, so these
- extra lookaheads won't appear in the final parser table.
- - If t2 has just one annotation, then these extra lookaheads
- cannot alter the dominating contribution to the associated
- inadequacy and thus cannot needlessly prevent a future merge
- of some new state with t2. We can be sure of this because:
- - The fact that we're splitting t2 now means that some
- predecessors (at least one) other than *tp must be
- propagating contributions to t2.
- - The fact that t2 was merged in the first place means that,
- if *tp propagated any contributions, the dominating
- contribution must be the same as that from those other
- predecessors.
- - Thus, if some new state to be merged with t2 in the future
- proves to be compatible with the contributions propagated
- by the other predecessors, it will also be compatible with
- the contributions made by the extra lookaheads left behind
- by *tp.
- - However, if t2 has more than one annotation and these extra
- lookaheads contribute to one of their inadequacies, it's
- possible these extra lookaheads may needlessly prevent a
- future merge with t2. For example:
- - Let's say there's an inadequacy A that makes the split
- necessary as follows:
- - There's currently just one other predecessor and it
- propagates to t2 some contributions to inadequacy A.
- - The new lookaheads that we were attempting to propagate
- from *tp to t2 made contributions to inadequacy A with a
- different dominating contribution than those from that
- other predecessor.
- - The extra lookaheads either make no contribution to
- inadequacy A or have the same dominating contribution as
- the contributions from the other predecessor. Either
- way, as explained above, they can't prevent a future
- merge.
- - Let's say there's an inadequacy B that causes the trouble
- with future merges as follows:
- - The extra lookaheads make contributions to inadequacy B.
- - Those extra contributions did not prevent the original
- merge to create t2 because the other predecessor
- propagates to t2 no contributions to inadequacy B.
- - Thus, those extra contributions may prevent a future
- merge with t2 even though the merge would be fine if *tp
- had not left them behind.
- - Is the latter case common enough to worry about?
- - Perhaps we should track all predecessors and iterate them
- now to recreate t2 without those extra lookaheads. */
- ielr_compute_state (follow_kernel_items, always_follows,
- annotation_lists, t2, lookaheads,
- last_statep, work1, work2,
- &(*tp)->transitions->states[i]);
- }
- }
- }
-
- /* Create a new isocore. */
- else
- {
- state_list *old_isocore = *this_isocorep;
- (*last_statep)->next = *this_isocorep = xmalloc (sizeof **last_statep);
- *last_statep = *this_isocorep;
- (*last_statep)->state = *tp = state_new_isocore (t);
- (*tp)->state_list = *last_statep;
- (*last_statep)->recomputedAsSuccessor = true;
- (*last_statep)->next = NULL;
- (*last_statep)->lookaheads = NULL;
- if (has_lookaheads)
- {
- size_t i;
- (*last_statep)->lookaheads =
- xnmalloc (t->nitems, sizeof (*last_statep)->lookaheads);
- for (i = 0; i < t->nitems; ++i)
- {
- if (bitset_empty_p (lookaheads[i]))
- (*last_statep)->lookaheads[i] = NULL;
- else
- {
- (*last_statep)->lookaheads[i] =
- bitset_create (ntokens, BITSET_FIXED);
- bitset_copy ((*last_statep)->lookaheads[i], lookaheads[i]);
- }
- }
- }
- (*last_statep)->lr0Isocore = lr0_isocore;
- (*last_statep)->nextIsocore = old_isocore;
- }
-}
-
-/**
- * \pre
- * - \c follow_kernel_items and \c always_follows were computed by
- * \c ielr_compute_auxiliary_tables.
- * - Either:
- * - <tt>annotation_lists = NULL</tt> and <tt>max_annotations=0</tt>.
- * - \c annotation_lists and \c max_annotations were computed by
- * \c ielr_compute_annotation_lists.
- * \post
- * - \c ::states is of size \c ::nstates (which might be greater than
- * <tt>::nstates \@pre</tt>) and no longer contains any LR(1)-relative
- * inadequacy. \c annotation_lists was used to determine state
- * compatibility or, if <tt>annotation_lists = NULL</tt>, the canonical
- * LR(1) state compatibility test was used.
- * - If <tt>annotation_lists = NULL</tt>, reduction lookahead sets were
- * computed in all states. TV_IELR_PHASE4 was pushed while they were
- * computed from item lookahead sets.
- */
-static void
-ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows,
- AnnotationList **annotation_lists,
- AnnotationIndex max_annotations)
-{
- state_list *first_state;
- state_list *last_state;
- bitsetv lookahead_filter = NULL;
- bitsetv lookaheads;
-
- /* Set up state list and some reusable bitsets. */
- {
- size_t max_nitems = 0;
- state_number i;
- state_list **nodep = &first_state;
- for (i = 0; i < nstates; ++i)
- {
- *nodep = states[i]->state_list = last_state = xmalloc (sizeof **nodep);
- (*nodep)->state = states[i];
- (*nodep)->recomputedAsSuccessor = false;
- (*nodep)->lookaheads = NULL;
- (*nodep)->lr0Isocore = *nodep;
- (*nodep)->nextIsocore = *nodep;
- nodep = &(*nodep)->next;
- if (states[i]->nitems > max_nitems)
- max_nitems = states[i]->nitems;
- }
- *nodep = NULL;
- lookahead_filter = bitsetv_create (max_nitems, ntokens, BITSET_FIXED);
- if (!annotation_lists)
- bitsetv_ones (lookahead_filter);
- lookaheads = bitsetv_create (max_nitems, ntokens, BITSET_FIXED);
- }
-
- /* Recompute states. */
- {
- ContributionIndex *work = xnmalloc (max_annotations, sizeof *work);
- state_list *this_state;
- for (this_state = first_state; this_state; this_state = this_state->next)
- {
- state *s = this_state->state;
- int i;
- for (i = 0; i < s->transitions->num; ++i)
- {
- state *t = s->transitions->states[i];
- if (annotation_lists)
- AnnotationList__computeLookaheadFilter (
- annotation_lists[t->state_list->lr0Isocore->state->number],
- t->nitems, lookahead_filter);
- ielr_compute_lookaheads (follow_kernel_items, always_follows,
- this_state, t, lookahead_filter,
- lookaheads);
- ielr_compute_state (follow_kernel_items, always_follows,
- annotation_lists, t, lookaheads, &last_state,
- work, lookahead_filter,
- &s->transitions->states[i]);
- }
- }
- free (work);
- }
-
- bitsetv_free (lookahead_filter);
- bitsetv_free (lookaheads);
-
- /* Store states back in the states array. */
- states = xnrealloc (states, nstates, sizeof *states);
- {
- state_list *node;
- for (node = first_state; node; node = node->next)
- states[node->state->number] = node->state;
- }
-
- /* In the case of canonical LR(1), copy item lookahead sets to reduction
- lookahead sets. */
- if (!annotation_lists)
- {
- state_list *node;
- timevar_push (TV_IELR_PHASE4);
- initialize_LA ();
- for (node = first_state; node; node = node->next)
- if (!node->state->consistent)
- {
- size_t i = 0;
- item_number *itemset = node->state->items;
- size_t r;
- for (r = 0; r < node->state->reductions->num; ++r)
- {
- rule *this_rule = node->state->reductions->rules[r];
- bitset lookahead_set =
- node->state->reductions->lookahead_tokens[r];
- if (item_number_is_rule_number (*this_rule->rhs))
- ielr_compute_goto_follow_set (follow_kernel_items,
- always_follows, node,
- this_rule->lhs, lookahead_set);
- else if (node->lookaheads)
- {
- /* We don't need to start the kernel item search back at
- i=0 because both items and reductions are sorted on rule
- number. */
- while (!item_number_is_rule_number (ritem[itemset[i]])
- || item_number_as_rule_number (ritem[itemset[i]])
- != this_rule->number)
- {
- ++i;
- aver (i < node->state->nitems);
- }
- if (node->lookaheads[i])
- bitset_copy (lookahead_set, node->lookaheads[i]);
- }
- }
- }
- timevar_pop (TV_IELR_PHASE4);
- }
-
- /* Free state list. */
- while (first_state)
- {
- state_list *node = first_state;
- if (node->lookaheads)
- {
- size_t i;
- for (i = 0; i < node->state->nitems; ++i)
- if (node->lookaheads[i])
- bitset_free (node->lookaheads[i]);
- free (node->lookaheads);
- }
- first_state = node->next;
- free (node);
- }
-}
-
-void
-ielr (void)
-{
- LrType lr_type;
-
- /* Examine user options. */
- {
- char *type = muscle_percent_define_get ("lr.type");
- if (STREQ (type, "lalr"))
- lr_type = LR_TYPE__LALR;
- else if (STREQ (type, "ielr"))
- lr_type = LR_TYPE__IELR;
- else if (STREQ (type, "canonical-lr"))
- lr_type = LR_TYPE__CANONICAL_LR;
- else
- aver (false);
- free (type);
- }
-
- /* Phase 0: LALR(1). */
- timevar_push (TV_LALR);
- if (lr_type == LR_TYPE__CANONICAL_LR)
- set_goto_map ();
- else
- lalr ();
- if (lr_type == LR_TYPE__LALR)
- {
- bitsetv_free (goto_follows);
- timevar_pop (TV_LALR);
- return;
- }
- timevar_pop (TV_LALR);
-
- {
- bitsetv follow_kernel_items;
- bitsetv always_follows;
- InadequacyList **inadequacy_lists = NULL;
- AnnotationList **annotation_lists = NULL;
- struct obstack annotations_obstack;
- AnnotationIndex max_annotations = 0;
-
- {
- /* Phase 1: Compute Auxiliary Tables. */
- state ***predecessors;
- timevar_push (TV_IELR_PHASE1);
- ielr_compute_auxiliary_tables (
- &follow_kernel_items, &always_follows,
- lr_type == LR_TYPE__CANONICAL_LR ? NULL : &predecessors);
- timevar_pop (TV_IELR_PHASE1);
-
- /* Phase 2: Compute Annotations. */
- timevar_push (TV_IELR_PHASE2);
- if (lr_type != LR_TYPE__CANONICAL_LR)
- {
- obstack_init (&annotations_obstack);
- ielr_compute_annotation_lists (follow_kernel_items, always_follows,
- predecessors, &max_annotations,
- &inadequacy_lists, &annotation_lists,
- &annotations_obstack);
- {
- state_number i;
- for (i = 0; i < nstates; ++i)
- free (predecessors[i]);
- }
- free (predecessors);
- bitsetv_free (goto_follows);
- lalr_free ();
- }
- timevar_pop (TV_IELR_PHASE2);
- }
-
- /* Phase 3: Split States. */
- timevar_push (TV_IELR_PHASE3);
- {
- state_number nstates_lr0 = nstates;
- ielr_split_states (follow_kernel_items, always_follows,
- annotation_lists, max_annotations);
- if (inadequacy_lists)
- {
- state_number i;
- for (i = 0; i < nstates_lr0; ++i)
- InadequacyList__delete (inadequacy_lists[i]);
- }
- }
- free (inadequacy_lists);
- if (annotation_lists)
- obstack_free (&annotations_obstack, NULL);
- free (annotation_lists);
- bitsetv_free (follow_kernel_items);
- bitsetv_free (always_follows);
- timevar_pop (TV_IELR_PHASE3);
- }
-
- /* Phase 4: Compute Reduction Lookaheads. */
- timevar_push (TV_IELR_PHASE4);
- free (goto_map);
- free (from_state);
- free (to_state);
- if (lr_type == LR_TYPE__CANONICAL_LR)
- {
- /* Reduction lookaheads are computed in ielr_split_states above
- but are timed as part of phase 4. */
- set_goto_map ();
- }
- else
- {
- lalr ();
- bitsetv_free (goto_follows);
- }
- timevar_pop (TV_IELR_PHASE4);
-}
+/* IELR main implementation.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "ielr.h"
+
+#include <bitset.h>
+#include <timevar.h>
+
+#include "AnnotationList.h"
+#include "derives.h"
+#include "getargs.h"
+#include "lalr.h"
+#include "muscle-tab.h"
+#include "nullable.h"
+#include "relation.h"
+#include "state.h"
+#include "symtab.h"
+
+/** Records the value of the \%define variable lr.type. */
+typedef enum { LR_TYPE__LALR, LR_TYPE__IELR, LR_TYPE__CANONICAL_LR } LrType;
+
+/**
+ * \post:
+ * - \c result = a new \c bitset of size \c ::nritems such that any bit \c i
+ * is set iff <tt>ritem[i]</tt> is a nonterminal after which all ritems in
+ * the same RHS are nullable nonterminals. In other words, the follows of
+ * a goto on <tt>ritem[i]</tt> include the lookahead set of the item.
+ */
+static bitset
+ielr_compute_ritem_sees_lookahead_set (void)
+{
+ bitset result = bitset_create (nritems, BITSET_FIXED);
+ unsigned int i = nritems-1;
+ while (i>0)
+ {
+ --i;
+ while (!item_number_is_rule_number (ritem[i])
+ && ISVAR (ritem[i])
+ && nullable [item_number_as_symbol_number (ritem[i]) - ntokens])
+ bitset_set (result, i--);
+ if (!item_number_is_rule_number (ritem[i]) && ISVAR (ritem[i]))
+ bitset_set (result, i--);
+ while (!item_number_is_rule_number (ritem[i]) && i>0)
+ --i;
+ }
+ if (trace_flag & trace_ielr)
+ {
+ fprintf (stderr, "ritem_sees_lookahead_set:\n");
+ debug_bitset (result);
+ fprintf (stderr, "\n");
+ }
+ return result;
+}
+
+/**
+ * \pre:
+ * - \c ritem_sees_lookahead_set was computed by
+ * \c ielr_compute_ritem_sees_lookahead_set.
+ * \post:
+ * - Each of \c *edgesp and \c *edge_countsp is a new array of size
+ * \c ::ngotos.
+ * - <tt>(*edgesp)[i]</tt> points to a \c goto_number array of size
+ * <tt>(*edge_countsp)[i]+1</tt>.
+ * - In such a \c goto_number array, the last element is \c ::END_NODE.
+ * - All remaining elements are the indices of the gotos to which there is an
+ * internal follow edge from goto \c i.
+ * - There is an internal follow edge from goto \c i to goto \c j iff both:
+ * - The from states of gotos \c i and \c j are the same.
+ * - The transition nonterminal for goto \c i appears as the first RHS
+ * symbol of at least one production for which both:
+ * - The LHS is the transition symbol of goto \c j.
+ * - All other RHS symbols are nullable nonterminals.
+ * - In other words, the follows of goto \c i include the follows of
+ * goto \c j and it's an internal edge because the from states are the
+ * same.
+ */
+static void
+ielr_compute_internal_follow_edges (bitset ritem_sees_lookahead_set,
+ goto_number ***edgesp, int **edge_countsp)
+{
+ *edgesp = xnmalloc (ngotos, sizeof **edgesp);
+ *edge_countsp = xnmalloc (ngotos, sizeof **edge_countsp);
+ {
+ bitset sources = bitset_create (ngotos, BITSET_FIXED);
+ goto_number i;
+ for (i = 0; i < ngotos; ++i)
+ (*edge_countsp)[i] = 0;
+ for (i = 0; i < ngotos; ++i)
+ {
+ int nsources = 0;
+ {
+ rule **rulep;
+ for (rulep = derives[states[to_state[i]]->accessing_symbol
+ - ntokens];
+ *rulep;
+ ++rulep)
+ {
+ /* If there is at least one RHS symbol, if the first RHS symbol
+ is a nonterminal, and if all remaining RHS symbols (if any)
+ are nullable nonterminals, create an edge from the LHS
+ symbol's goto to the first RHS symbol's goto such that the RHS
+ symbol's goto will be the source of the edge after the
+ eventual relation_transpose below.
+
+ Unlike in ielr_compute_always_follows, I use a bitset for
+ edges rather than an array because it is possible that
+ multiple RHS's with the same first symbol could fit and thus
+ that we could end up with redundant edges. With the
+ possibility of redundant edges, it's hard to know ahead of
+ time how large to make such an array. Another possible
+ redundancy is that source and destination might be the same
+ goto. Eliminating all these possible redundancies now might
+ possibly help performance a little. I have not proven any of
+ this, but I'm guessing the bitset shouldn't entail much of a
+ performance penalty, if any. */
+ if (bitset_test (ritem_sees_lookahead_set,
+ (*rulep)->rhs - ritem))
+ {
+ goto_number source =
+ map_goto (from_state[i],
+ item_number_as_symbol_number (*(*rulep)->rhs));
+ if (i != source && !bitset_test (sources, source))
+ {
+ bitset_set (sources, source);
+ ++nsources;
+ ++(*edge_countsp)[source];
+ }
+ }
+ }
+ }
+ if (nsources == 0)
+ (*edgesp)[i] = NULL;
+ else
+ {
+ (*edgesp)[i] = xnmalloc (nsources + 1, sizeof *(*edgesp)[i]);
+ {
+ bitset_iterator biter_source;
+ bitset_bindex source;
+ int j = 0;
+ BITSET_FOR_EACH (biter_source, sources, source, 0)
+ (*edgesp)[i][j++] = source;
+ }
+ (*edgesp)[i][nsources] = END_NODE;
+ }
+ bitset_zero (sources);
+ }
+ bitset_free (sources);
+ }
+
+ relation_transpose (edgesp, ngotos);
+
+ if (trace_flag & trace_ielr)
+ {
+ fprintf (stderr, "internal_follow_edges:\n");
+ relation_print (*edgesp, ngotos, stderr);
+ }
+}
+
+/**
+ * \pre:
+ * - \c ritem_sees_lookahead_set was computed by
+ * \c ielr_compute_ritem_sees_lookahead_set.
+ * - \c internal_follow_edges was computed by
+ * \c ielr_compute_internal_follow_edges.
+ * \post:
+ * - \c *follow_kernel_itemsp is a new \c bitsetv in which the number of rows
+ * is \c ngotos and the number of columns is maximum number of kernel items
+ * in any state.
+ * - <tt>(*follow_kernel_itemsp)[i][j]</tt> is set iff the follows of goto
+ * \c i include the lookahead set of item \c j in the from state of goto
+ * \c i.
+ * - Thus, <tt>(*follow_kernel_itemsp)[i][j]</tt> is always unset if there is
+ * no item \c j in the from state of goto \c i.
+ */
+static void
+ielr_compute_follow_kernel_items (bitset ritem_sees_lookahead_set,
+ goto_number **internal_follow_edges,
+ bitsetv *follow_kernel_itemsp)
+{
+ {
+ size_t max_nitems = 0;
+ state_number i;
+ for (i = 0; i < nstates; ++i)
+ if (states[i]->nitems > max_nitems)
+ max_nitems = states[i]->nitems;
+ *follow_kernel_itemsp = bitsetv_create (ngotos, max_nitems, BITSET_FIXED);
+ }
+ {
+ goto_number i;
+ for (i = 0; i < ngotos; ++i)
+ {
+ size_t nitems = states[from_state[i]]->nitems;
+ item_number *items = states[from_state[i]]->items;
+ size_t j;
+ for (j = 0; j < nitems; ++j)
+ /* If this item has this goto and if all subsequent symbols in this
+ RHS (if any) are nullable nonterminals, then record this item as
+ one whose lookahead set is included in this goto's follows. */
+ if (item_number_is_symbol_number (ritem[items[j]])
+ && item_number_as_symbol_number (ritem[items[j]])
+ == states[to_state[i]]->accessing_symbol
+ && bitset_test (ritem_sees_lookahead_set, items[j]))
+ bitset_set ((*follow_kernel_itemsp)[i], j);
+ }
+ }
+ relation_digraph (internal_follow_edges, ngotos, follow_kernel_itemsp);
+
+ if (trace_flag & trace_ielr)
+ {
+ fprintf (stderr, "follow_kernel_items:\n");
+ debug_bitsetv (*follow_kernel_itemsp);
+ }
+}
+
+/**
+ * \pre
+ * - \c *edgesp and \c edge_counts were computed by
+ * \c ielr_compute_internal_follow_edges.
+ * \post
+ * - \c *always_followsp is a new \c bitsetv with \c ngotos rows and
+ * \c ntokens columns.
+ * - <tt>(*always_followsp)[i][j]</tt> is set iff token \c j is an always
+ * follow (that is, it's computed by internal and successor edges) of goto
+ * \c i.
+ * - Rows of \c *edgesp have been realloc'ed and extended to include
+ * successor follow edges. \c edge_counts has not been updated.
+ */
+static void
+ielr_compute_always_follows (goto_number ***edgesp,
+ int const edge_counts[],
+ bitsetv *always_followsp)
+{
+ *always_followsp = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
+ {
+ goto_number *edge_array = xnmalloc (ngotos, sizeof *edge_array);
+ goto_number i;
+ for (i = 0; i < ngotos; ++i)
+ {
+ goto_number nedges = edge_counts[i];
+ {
+ int j;
+ transitions *trans = states[to_state[i]]->transitions;
+ FOR_EACH_SHIFT (trans, j)
+ bitset_set ((*always_followsp)[i], TRANSITION_SYMBOL (trans, j));
+ for (; j < trans->num; ++j)
+ {
+ symbol_number sym = TRANSITION_SYMBOL (trans, j);
+ if (nullable[sym - ntokens])
+ edge_array[nedges++] = map_goto (to_state[i], sym);
+ }
+ }
+ if (nedges - edge_counts[i])
+ {
+ (*edgesp)[i] =
+ xnrealloc ((*edgesp)[i], nedges + 1, sizeof *(*edgesp)[i]);
+ memcpy ((*edgesp)[i] + edge_counts[i], edge_array + edge_counts[i],
+ (nedges - edge_counts[i]) * sizeof *(*edgesp)[i]);
+ (*edgesp)[i][nedges] = END_NODE;
+ }
+ }
+ free (edge_array);
+ }
+ relation_digraph (*edgesp, ngotos, always_followsp);
+
+ if (trace_flag & trace_ielr)
+ {
+ fprintf (stderr, "always follow edges:\n");
+ relation_print (*edgesp, ngotos, stderr);
+ fprintf (stderr, "always_follows:\n");
+ debug_bitsetv (*always_followsp);
+ }
+}
+
+/**
+ * \post
+ * - \c result is a new array of size \c ::nstates.
+ * - <tt>result[i]</tt> is an array of pointers to the predecessor
+ * <tt>state</tt>'s of state \c i.
+ * - The last element of such an array is \c NULL.
+ */
+static state ***
+ielr_compute_predecessors (void)
+{
+ state_number i;
+ int *predecessor_counts = xnmalloc (nstates, sizeof *predecessor_counts);
+ state ***result = xnmalloc (nstates, sizeof *result);
+ for (i = 0; i < nstates; ++i)
+ predecessor_counts[i] = 0;
+ for (i = 0; i < nstates; ++i)
+ {
+ int j;
+ for (j = 0; j < states[i]->transitions->num; ++j)
+ ++predecessor_counts[states[i]->transitions->states[j]->number];
+ }
+ for (i = 0; i < nstates; ++i)
+ {
+ result[i] = xnmalloc (predecessor_counts[i]+1, sizeof *result[i]);
+ result[i][predecessor_counts[i]] = NULL;
+ predecessor_counts[i] = 0;
+ }
+ for (i = 0; i < nstates; ++i)
+ {
+ int j;
+ for (j = 0; j < states[i]->transitions->num; ++j)
+ {
+ state_number k = states[i]->transitions->states[j]->number;
+ result[k][predecessor_counts[k]++] = states[i];
+ }
+ }
+ free (predecessor_counts);
+ return result;
+}
+
+/**
+ * \post
+ * - \c *follow_kernel_itemsp and \c *always_followsp were computed by
+ * \c ielr_compute_follow_kernel_items and
+ * \c ielr_compute_always_follows.
+ * - Iff <tt>predecessorsp != NULL</tt>, then \c *predecessorsp was computed
+ * by \c ielr_compute_predecessors.
+ */
+static void
+ielr_compute_auxiliary_tables (bitsetv *follow_kernel_itemsp,
+ bitsetv *always_followsp,
+ state ****predecessorsp)
+{
+ goto_number **edges;
+ int *edge_counts;
+ {
+ bitset ritem_sees_lookahead_set = ielr_compute_ritem_sees_lookahead_set ();
+ ielr_compute_internal_follow_edges (ritem_sees_lookahead_set,
+ &edges, &edge_counts);
+ ielr_compute_follow_kernel_items (ritem_sees_lookahead_set, edges,
+ follow_kernel_itemsp);
+ bitset_free (ritem_sees_lookahead_set);
+ }
+ ielr_compute_always_follows (&edges, edge_counts, always_followsp);
+ {
+ int i;
+ for (i = 0; i < ngotos; ++i)
+ free (edges[i]);
+ }
+ free (edges);
+ free (edge_counts);
+ if (predecessorsp)
+ *predecessorsp = ielr_compute_predecessors ();
+}
+
+/**
+ * \note
+ * - FIXME: It might be an interesting experiment to compare the space and
+ * time efficiency of computing \c item_lookahead_sets either:
+ * - Fully up front.
+ * - Just-in-time, as implemented below.
+ * - Not at all. That is, just let annotations continue even when
+ * unnecessary.
+ */
+bool
+ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item,
+ symbol_number lookahead, state ***predecessors,
+ bitset **item_lookahead_sets)
+{
+ if (!item_lookahead_sets[s->number])
+ {
+ size_t i;
+ item_lookahead_sets[s->number] =
+ xnmalloc (s->nitems, sizeof item_lookahead_sets[s->number][0]);
+ for (i = 0; i < s->nitems; ++i)
+ item_lookahead_sets[s->number][i] = NULL;
+ }
+ if (!item_lookahead_sets[s->number][item])
+ {
+ item_lookahead_sets[s->number][item] =
+ bitset_create (ntokens, BITSET_FIXED);
+ /* If this kernel item is the beginning of a RHS, it must be the kernel
+ item in the start state, and so its LHS has no follows and no goto to
+ check. If, instead, this kernel item is the successor of the start
+ state's kernel item, there are still no follows and no goto. This
+ situation is fortunate because we want to avoid the - 2 below in both
+ cases.
+
+ Actually, IELR(1) should never invoke this function for either of
+ those cases because (1) follow_kernel_items will never reference a
+ kernel item for this RHS because the end token blocks sight of the
+ lookahead set from the RHS's only nonterminal, and (2) no reduction
+ has a lookback dependency on this lookahead set. Nevertheless, I
+ didn't change this test to an aver just in case the usage of this
+ function evolves to need those two cases. In both cases, the current
+ implementation returns the right result. */
+ if (s->items[item] > 1)
+ {
+ /* If the LHS symbol of this item isn't known (because this is a
+ top-level invocation), go get it. */
+ if (!lhs)
+ {
+ unsigned int i;
+ for (i = s->items[item];
+ !item_number_is_rule_number (ritem[i]);
+ ++i)
+ ;
+ lhs = rules[item_number_as_rule_number (ritem[i])].lhs->number;
+ }
+ /* If this kernel item is next to the beginning of the RHS, then
+ check all predecessors' goto follows for the LHS. */
+ if (item_number_is_rule_number (ritem[s->items[item] - 2]))
+ {
+ state **predecessor;
+ aver (lhs != accept->number);
+ for (predecessor = predecessors[s->number];
+ *predecessor;
+ ++predecessor)
+ bitset_or (item_lookahead_sets[s->number][item],
+ item_lookahead_sets[s->number][item],
+ goto_follows[map_goto ((*predecessor)->number,
+ lhs)]);
+ }
+ /* If this kernel item is later in the RHS, then check all
+ predecessor items' lookahead sets. */
+ else
+ {
+ state **predecessor;
+ for (predecessor = predecessors[s->number];
+ *predecessor;
+ ++predecessor)
+ {
+ size_t predecessor_item;
+ for (predecessor_item = 0;
+ predecessor_item < (*predecessor)->nitems;
+ ++predecessor_item)
+ if ((*predecessor)->items[predecessor_item]
+ == s->items[item] - 1)
+ break;
+ aver (predecessor_item != (*predecessor)->nitems);
+ ielr_item_has_lookahead (*predecessor, lhs,
+ predecessor_item, 0 /*irrelevant*/,
+ predecessors, item_lookahead_sets);
+ bitset_or (item_lookahead_sets[s->number][item],
+ item_lookahead_sets[s->number][item],
+ item_lookahead_sets[(*predecessor)->number]
+ [predecessor_item]);
+ }
+ }
+ }
+ }
+ return bitset_test (item_lookahead_sets[s->number][item], lookahead);
+}
+
+/**
+ * \pre
+ * - \c follow_kernel_items, \c always_follows, and \c predecessors
+ * were computed by \c ielr_compute_auxiliary_tables.
+ * \post
+ * - Each of <tt>*inadequacy_listsp</tt> and <tt>*annotation_listsp</tt>
+ * points to a new array of size \c ::nstates.
+ * - For <tt>0 <= i < ::nstates</tt>:
+ * - <tt>(*inadequacy_listsp)[i]</tt> contains the \c InadequacyList head
+ * node for <tt>states[i]</tt>.
+ * - <tt>(*annotation_listsp)[i]</tt> contains the \c AnnotationList head
+ * node for <tt>states[i]</tt>.
+ * - <tt>*max_annotationsp</tt> is the maximum number of annotations per
+ * state.
+ */
+static void
+ielr_compute_annotation_lists (bitsetv follow_kernel_items,
+ bitsetv always_follows, state ***predecessors,
+ AnnotationIndex *max_annotationsp,
+ InadequacyList ***inadequacy_listsp,
+ AnnotationList ***annotation_listsp,
+ struct obstack *annotations_obstackp)
+{
+ bitset **item_lookahead_sets =
+ xnmalloc (nstates, sizeof *item_lookahead_sets);
+ AnnotationIndex *annotation_counts =
+ xnmalloc (nstates, sizeof *annotation_counts);
+ ContributionIndex max_contributions = 0;
+ unsigned int total_annotations = 0;
+ state_number i;
+
+ *inadequacy_listsp = xnmalloc (nstates, sizeof **inadequacy_listsp);
+ *annotation_listsp = xnmalloc (nstates, sizeof **annotation_listsp);
+ for (i = 0; i < nstates; ++i)
+ {
+ item_lookahead_sets[i] = NULL;
+ (*inadequacy_listsp)[i] = NULL;
+ (*annotation_listsp)[i] = NULL;
+ annotation_counts[i] = 0;
+ }
+ {
+ InadequacyListNodeCount inadequacy_list_node_count = 0;
+ for (i = 0; i < nstates; ++i)
+ AnnotationList__compute_from_inadequacies (
+ states[i], follow_kernel_items, always_follows, predecessors,
+ item_lookahead_sets, *inadequacy_listsp, *annotation_listsp,
+ annotation_counts, &max_contributions, annotations_obstackp,
+ &inadequacy_list_node_count);
+ }
+ *max_annotationsp = 0;
+ for (i = 0; i < nstates; ++i)
+ {
+ if (annotation_counts[i] > *max_annotationsp)
+ *max_annotationsp = annotation_counts[i];
+ total_annotations += annotation_counts[i];
+ }
+ if (trace_flag & trace_ielr)
+ {
+ for (i = 0; i < nstates; ++i)
+ {
+ fprintf (stderr, "Inadequacy annotations for state %d:\n", i);
+ AnnotationList__debug ((*annotation_listsp)[i],
+ states[i]->nitems, 2);
+ }
+ fprintf (stderr, "Number of LR(0)/LALR(1) states: %d\n", nstates);
+ fprintf (stderr, "Average number of annotations per state: %f\n",
+ (float)total_annotations/nstates);
+ fprintf (stderr, "Max number of annotations per state: %d\n",
+ *max_annotationsp);
+ fprintf (stderr, "Max number of contributions per annotation: %d\n",
+ max_contributions);
+ }
+ for (i = 0; i < nstates; ++i)
+ if (item_lookahead_sets[i])
+ {
+ size_t j;
+ for (j = 0; j < states[i]->nitems; ++j)
+ if (item_lookahead_sets[i][j])
+ bitset_free (item_lookahead_sets[i][j]);
+ free (item_lookahead_sets[i]);
+ }
+ free (item_lookahead_sets);
+ free (annotation_counts);
+}
+
+typedef struct state_list {
+ struct state_list *next;
+ state *state;
+ /** Has this state been recomputed as a successor of another state? */
+ bool recomputedAsSuccessor;
+ /**
+ * \c NULL iff all lookahead sets are empty. <tt>lookaheads[i] = NULL</tt>
+ * iff the lookahead set on item \c i is empty.
+ */
+ bitset *lookaheads;
+ /**
+ * nextIsocore is the next state in a circularly linked-list of all states
+ * with the same core. The one originally computed by generate_states in
+ * LR0.c is lr0Isocore.
+ */
+ struct state_list *lr0Isocore;
+ struct state_list *nextIsocore;
+} state_list;
+
+/**
+ * \pre
+ * - \c follow_kernel_items and \c always_follows were computed by
+ * \c ielr_compute_auxiliary_tables.
+ * - <tt>n->class = nterm_sym</tt>.
+ * \post
+ * - \c follow_set contains the follow set for the goto on nonterminal \c n
+ * in state \c s based on the lookaheads stored in <tt>s->lookaheads</tt>.
+ */
+static void
+ielr_compute_goto_follow_set (bitsetv follow_kernel_items,
+ bitsetv always_follows, state_list *s,
+ symbol *n, bitset follow_set)
+{
+ goto_number n_goto = map_goto (s->lr0Isocore->state->number, n->number);
+ bitset_copy (follow_set, always_follows[n_goto]);
+ if (s->lookaheads)
+ {
+ bitset_iterator biter_item;
+ bitset_bindex item;
+ BITSET_FOR_EACH (biter_item, follow_kernel_items[n_goto], item, 0)
+ if (s->lookaheads[item])
+ bitset_or (follow_set, follow_set, s->lookaheads[item]);
+ }
+}
+
+/**
+ * \pre
+ * - \c follow_kernel_items and \c always_follows were computed by
+ * \c ielr_compute_auxiliary_tables.
+ * - \c lookahead_filter was computed by
+ * \c AnnotationList__computeLookaheadFilter for the original LR(0) isocore
+ * of \c t.
+ * - The number of rows in \c lookaheads is at least the number of items in
+ * \c t, and the number of columns is \c ::ntokens.
+ * \post
+ * - <tt>lookaheads[i][j]</tt> is set iff both:
+ * - <tt>lookahead_filter[i][j]</tt> is set.
+ * - The isocore of \c t that will be the transition successor of \c s will
+ * inherit from \c s token \c j into the lookahead set of item \c i.
+ */
+static void
+ielr_compute_lookaheads (bitsetv follow_kernel_items, bitsetv always_follows,
+ state_list *s, state *t, bitsetv lookahead_filter,
+ bitsetv lookaheads)
+{
+ size_t s_item = 0;
+ size_t t_item;
+ bitsetv_zero (lookaheads);
+ for (t_item = 0; t_item < t->nitems; ++t_item)
+ {
+ /* If this kernel item is the beginning of a RHS, it must be the
+ kernel item in the start state, but t is supposed to be a successor
+ state. If, instead, this kernel item is the successor of the start
+ state's kernel item, the lookahead set is empty. This second case is
+ a special case to avoid the - 2 below, but the next successor can be
+ handled fine without special casing it. */
+ aver (t->items[t_item] != 0);
+ if (t->items[t_item] > 1
+ && !bitset_empty_p (lookahead_filter[t_item]))
+ {
+ if (item_number_is_rule_number (ritem[t->items[t_item] - 2]))
+ {
+ unsigned int rule_item;
+ for (rule_item = t->items[t_item];
+ !item_number_is_rule_number (ritem[rule_item]);
+ ++rule_item)
+ ;
+ ielr_compute_goto_follow_set (
+ follow_kernel_items, always_follows, s,
+ rules[item_number_as_rule_number (ritem[rule_item])].lhs,
+ lookaheads[t_item]);
+ }
+ else if (s->lookaheads)
+ {
+ /* We don't have to start the s item search at the beginning
+ every time because items from both states are sorted by their
+ indices in ritem. */
+ for (; s_item < s->state->nitems; ++s_item)
+ if (s->state->items[s_item] == t->items[t_item] - 1)
+ break;
+ aver (s_item != s->state->nitems);
+ if (s->lookaheads[s_item])
+ bitset_copy (lookaheads[t_item], s->lookaheads[s_item]);
+ }
+ bitset_and (lookaheads[t_item],
+ lookaheads[t_item], lookahead_filter[t_item]);
+ }
+ }
+}
+
+/**
+ * \pre
+ * - \c follow_kernel_items and \c always_follows were computed by
+ * \c ielr_compute_auxiliary_tables.
+ * - Either:
+ * - <tt>annotation_lists = NULL</tt> and all bits in work2 are set.
+ * - \c annotation_lists was computed by \c ielr_compute_annotation_lists.
+ * - The number of rows in each of \c lookaheads and \c work2 is the maximum
+ * number of items in any state. The number of columns in each is
+ * \c ::ntokens.
+ * - \c lookaheads was computed by \c ielr_compute_lookaheads for \c t.
+ * - \c ::nstates is the total number of states, some not yet fully computed,
+ * in the list ending at \c *last_statep. It is at least the number of
+ * original LR(0) states.
+ * - The size of \c work1 is at least the number of annotations for the LR(0)
+ * isocore of \c t.
+ * \post
+ * - Either:
+ * - In the case that <tt>annotation_lists != NULL</tt>,
+ * <tt>lookaheads \@pre</tt> was merged with some isocore of \c t if
+ * permitted by the annotations for the original LR(0) isocore of \c t.
+ * If this changed the lookaheads in that isocore, those changes were
+ * propagated to all already computed transition successors recursively
+ * possibly resulting in the splitting of some of those successors.
+ * - In the case that <tt>annotation_lists = NULL</tt>,
+ * <tt>lookaheads \@pre</tt> was merged with some isocore of \c t if the
+ * isocore's lookahead sets were identical to those specified by
+ * <tt>lookaheads \@pre</tt>.
+ * - If no such merge was permitted, a new isocore of \c t containing
+ * <tt>lookaheads \@pre</tt> was appended to the state list whose
+ * previous tail was <tt>*last_statep \@pre</tt> and \c ::nstates was
+ * incremented. It was also appended to \c t's isocore list.
+ * - <tt>*tp</tt> = the isocore of \c t into which
+ * <tt>lookaheads \@pre</tt> was placed/merged.
+ * - \c lookaheads, \c work1, and \c work2 may have been altered.
+ */
+static void
+ielr_compute_state (bitsetv follow_kernel_items, bitsetv always_follows,
+ AnnotationList **annotation_lists, state *t,
+ bitsetv lookaheads, state_list **last_statep,
+ ContributionIndex work1[], bitsetv work2, state **tp)
+{
+ state_list *lr0_isocore = t->state_list->lr0Isocore;
+ state_list **this_isocorep;
+ bool has_lookaheads;
+
+ /* Determine whether there's an isocore of t with which these lookaheads can
+ be merged. */
+ {
+ AnnotationIndex ai;
+ AnnotationList *a;
+ if (annotation_lists)
+ for (ai = 0, a = annotation_lists[lr0_isocore->state->number];
+ a;
+ ++ai, a = a->next)
+ work1[ai] =
+ AnnotationList__computeDominantContribution (
+ a, lr0_isocore->state->nitems, lookaheads, false);
+ for (this_isocorep = &t->state_list;
+ this_isocorep == &t->state_list || *this_isocorep != t->state_list;
+ this_isocorep = &(*this_isocorep)->nextIsocore)
+ {
+ if (!(*this_isocorep)->recomputedAsSuccessor)
+ break;
+ if (annotation_lists)
+ {
+ for (ai = 0, a = annotation_lists[lr0_isocore->state->number];
+ a;
+ ++ai, a = a->next)
+ {
+ if (work1[ai] != ContributionIndex__none)
+ {
+ /* This isocore compatibility test depends on the fact
+ that, if the dominant contributions are the same for the
+ two isocores, then merging their lookahead sets will not
+ produce a state with a different dominant contribution.
+ */
+ ContributionIndex ci =
+ AnnotationList__computeDominantContribution (
+ a, lr0_isocore->state->nitems,
+ (*this_isocorep)->lookaheads, false);
+ if (ci != ContributionIndex__none && work1[ai] != ci)
+ break;
+ }
+ }
+ if (!a)
+ break;
+ }
+ else
+ {
+ size_t i;
+ for (i = 0; i < t->nitems; ++i)
+ {
+ if (!(*this_isocorep)->lookaheads
+ || !(*this_isocorep)->lookaheads[i])
+ {
+ if (!bitset_empty_p (lookaheads[i]))
+ break;
+ }
+ /* bitset_equal_p uses the size of the first argument,
+ so lookaheads[i] must be the second argument. */
+ else if (!bitset_equal_p ((*this_isocorep)->lookaheads[i],
+ lookaheads[i]))
+ break;
+ }
+ if (i == t->nitems)
+ break;
+ }
+ }
+ }
+
+ has_lookaheads = false;
+ {
+ size_t i;
+ for (i = 0; i < lr0_isocore->state->nitems; ++i)
+ if (!bitset_empty_p (lookaheads[i]))
+ {
+ has_lookaheads = true;
+ break;
+ }
+ }
+
+ /* Merge with an existing isocore. */
+ if (this_isocorep == &t->state_list || *this_isocorep != t->state_list)
+ {
+ bool new_lookaheads = false;
+ *tp = (*this_isocorep)->state;
+
+ /* Merge lookaheads into the state and record whether any of them are
+ actually new. */
+ if (has_lookaheads)
+ {
+ size_t i;
+ if (!(*this_isocorep)->lookaheads)
+ {
+ (*this_isocorep)->lookaheads =
+ xnmalloc (t->nitems, sizeof (*this_isocorep)->lookaheads);
+ for (i = 0; i < t->nitems; ++i)
+ (*this_isocorep)->lookaheads[i] = NULL;
+ }
+ for (i = 0; i < t->nitems; ++i)
+ if (!bitset_empty_p (lookaheads[i]))
+ {
+ if (!(*this_isocorep)->lookaheads[i])
+ (*this_isocorep)->lookaheads[i] =
+ bitset_create (ntokens, BITSET_FIXED);
+ bitset_andn (lookaheads[i],
+ lookaheads[i], (*this_isocorep)->lookaheads[i]);
+ bitset_or ((*this_isocorep)->lookaheads[i],
+ lookaheads[i], (*this_isocorep)->lookaheads[i]);
+ if (!bitset_empty_p (lookaheads[i]))
+ new_lookaheads = true;
+ }
+ }
+
+ /* If new lookaheads were merged, propagate those lookaheads to the
+ successors, possibly splitting them. If *tp is being recomputed for
+ the first time, this isn't necessary because the main
+ ielr_split_states loop will handle the successors later. */
+ if (!(*this_isocorep)->recomputedAsSuccessor)
+ (*this_isocorep)->recomputedAsSuccessor = true;
+ else if (new_lookaheads)
+ {
+ int i;
+ /* When merging demands identical lookahead sets, it is impossible to
+ merge new lookaheads. */
+ aver (annotation_lists);
+ for (i = 0; i < (*tp)->transitions->num; ++i)
+ {
+ state *t2 = (*tp)->transitions->states[i];
+ /* At any time, there's at most one state for which we have so
+ far initially recomputed only some of its successors in the
+ main ielr_split_states loop. Because we recompute successors
+ in order, we can just stop at the first such successor. Of
+ course, *tp might be a state some of whose successors have
+ been recomputed as successors of other states rather than as
+ successors of *tp. It's fine if we go ahead and propagate to
+ some of those. We'll propagate to them again (but stop when
+ we see nothing changes) and to the others when we reach *tp in
+ the main ielr_split_states loop later. */
+ if (!t2->state_list->recomputedAsSuccessor)
+ break;
+ AnnotationList__computeLookaheadFilter (
+ annotation_lists[t2->state_list->lr0Isocore->state->number],
+ t2->nitems, work2);
+ ielr_compute_lookaheads (follow_kernel_items, always_follows,
+ (*this_isocorep), t2, work2,
+ lookaheads);
+ /* FIXME: If splitting t2 here, it's possible that lookaheads
+ that had already propagated from *tp to t2 will be left in t2
+ after *tp has been removed as t2's predecessor:
+ - We're going to recompute all lookaheads in phase 4, so these
+ extra lookaheads won't appear in the final parser table.
+ - If t2 has just one annotation, then these extra lookaheads
+ cannot alter the dominating contribution to the associated
+ inadequacy and thus cannot needlessly prevent a future merge
+ of some new state with t2. We can be sure of this because:
+ - The fact that we're splitting t2 now means that some
+ predecessors (at least one) other than *tp must be
+ propagating contributions to t2.
+ - The fact that t2 was merged in the first place means that,
+ if *tp propagated any contributions, the dominating
+ contribution must be the same as that from those other
+ predecessors.
+ - Thus, if some new state to be merged with t2 in the future
+ proves to be compatible with the contributions propagated
+ by the other predecessors, it will also be compatible with
+ the contributions made by the extra lookaheads left behind
+ by *tp.
+ - However, if t2 has more than one annotation and these extra
+ lookaheads contribute to one of their inadequacies, it's
+ possible these extra lookaheads may needlessly prevent a
+ future merge with t2. For example:
+ - Let's say there's an inadequacy A that makes the split
+ necessary as follows:
+ - There's currently just one other predecessor and it
+ propagates to t2 some contributions to inadequacy A.
+ - The new lookaheads that we were attempting to propagate
+ from *tp to t2 made contributions to inadequacy A with a
+ different dominating contribution than those from that
+ other predecessor.
+ - The extra lookaheads either make no contribution to
+ inadequacy A or have the same dominating contribution as
+ the contributions from the other predecessor. Either
+ way, as explained above, they can't prevent a future
+ merge.
+ - Let's say there's an inadequacy B that causes the trouble
+ with future merges as follows:
+ - The extra lookaheads make contributions to inadequacy B.
+ - Those extra contributions did not prevent the original
+ merge to create t2 because the other predecessor
+ propagates to t2 no contributions to inadequacy B.
+ - Thus, those extra contributions may prevent a future
+ merge with t2 even though the merge would be fine if *tp
+ had not left them behind.
+ - Is the latter case common enough to worry about?
+ - Perhaps we should track all predecessors and iterate them
+ now to recreate t2 without those extra lookaheads. */
+ ielr_compute_state (follow_kernel_items, always_follows,
+ annotation_lists, t2, lookaheads,
+ last_statep, work1, work2,
+ &(*tp)->transitions->states[i]);
+ }
+ }
+ }
+
+ /* Create a new isocore. */
+ else
+ {
+ state_list *old_isocore = *this_isocorep;
+ (*last_statep)->next = *this_isocorep = xmalloc (sizeof **last_statep);
+ *last_statep = *this_isocorep;
+ (*last_statep)->state = *tp = state_new_isocore (t);
+ (*tp)->state_list = *last_statep;
+ (*last_statep)->recomputedAsSuccessor = true;
+ (*last_statep)->next = NULL;
+ (*last_statep)->lookaheads = NULL;
+ if (has_lookaheads)
+ {
+ size_t i;
+ (*last_statep)->lookaheads =
+ xnmalloc (t->nitems, sizeof (*last_statep)->lookaheads);
+ for (i = 0; i < t->nitems; ++i)
+ {
+ if (bitset_empty_p (lookaheads[i]))
+ (*last_statep)->lookaheads[i] = NULL;
+ else
+ {
+ (*last_statep)->lookaheads[i] =
+ bitset_create (ntokens, BITSET_FIXED);
+ bitset_copy ((*last_statep)->lookaheads[i], lookaheads[i]);
+ }
+ }
+ }
+ (*last_statep)->lr0Isocore = lr0_isocore;
+ (*last_statep)->nextIsocore = old_isocore;
+ }
+}
+
+/**
+ * \pre
+ * - \c follow_kernel_items and \c always_follows were computed by
+ * \c ielr_compute_auxiliary_tables.
+ * - Either:
+ * - <tt>annotation_lists = NULL</tt> and <tt>max_annotations=0</tt>.
+ * - \c annotation_lists and \c max_annotations were computed by
+ * \c ielr_compute_annotation_lists.
+ * \post
+ * - \c ::states is of size \c ::nstates (which might be greater than
+ * <tt>::nstates \@pre</tt>) and no longer contains any LR(1)-relative
+ * inadequacy. \c annotation_lists was used to determine state
+ * compatibility or, if <tt>annotation_lists = NULL</tt>, the canonical
+ * LR(1) state compatibility test was used.
+ * - If <tt>annotation_lists = NULL</tt>, reduction lookahead sets were
+ * computed in all states. TV_IELR_PHASE4 was pushed while they were
+ * computed from item lookahead sets.
+ */
+static void
+ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows,
+ AnnotationList **annotation_lists,
+ AnnotationIndex max_annotations)
+{
+ state_list *first_state;
+ state_list *last_state;
+ bitsetv lookahead_filter = NULL;
+ bitsetv lookaheads;
+
+ /* Set up state list and some reusable bitsets. */
+ {
+ size_t max_nitems = 0;
+ state_number i;
+ state_list **nodep = &first_state;
+ for (i = 0; i < nstates; ++i)
+ {
+ *nodep = states[i]->state_list = last_state = xmalloc (sizeof **nodep);
+ (*nodep)->state = states[i];
+ (*nodep)->recomputedAsSuccessor = false;
+ (*nodep)->lookaheads = NULL;
+ (*nodep)->lr0Isocore = *nodep;
+ (*nodep)->nextIsocore = *nodep;
+ nodep = &(*nodep)->next;
+ if (states[i]->nitems > max_nitems)
+ max_nitems = states[i]->nitems;
+ }
+ *nodep = NULL;
+ lookahead_filter = bitsetv_create (max_nitems, ntokens, BITSET_FIXED);
+ if (!annotation_lists)
+ bitsetv_ones (lookahead_filter);
+ lookaheads = bitsetv_create (max_nitems, ntokens, BITSET_FIXED);
+ }
+
+ /* Recompute states. */
+ {
+ ContributionIndex *work = xnmalloc (max_annotations, sizeof *work);
+ state_list *this_state;
+ for (this_state = first_state; this_state; this_state = this_state->next)
+ {
+ state *s = this_state->state;
+ int i;
+ for (i = 0; i < s->transitions->num; ++i)
+ {
+ state *t = s->transitions->states[i];
+ if (annotation_lists)
+ AnnotationList__computeLookaheadFilter (
+ annotation_lists[t->state_list->lr0Isocore->state->number],
+ t->nitems, lookahead_filter);
+ ielr_compute_lookaheads (follow_kernel_items, always_follows,
+ this_state, t, lookahead_filter,
+ lookaheads);
+ ielr_compute_state (follow_kernel_items, always_follows,
+ annotation_lists, t, lookaheads, &last_state,
+ work, lookahead_filter,
+ &s->transitions->states[i]);
+ }
+ }
+ free (work);
+ }
+
+ bitsetv_free (lookahead_filter);
+ bitsetv_free (lookaheads);
+
+ /* Store states back in the states array. */
+ states = xnrealloc (states, nstates, sizeof *states);
+ {
+ state_list *node;
+ for (node = first_state; node; node = node->next)
+ states[node->state->number] = node->state;
+ }
+
+ /* In the case of canonical LR(1), copy item lookahead sets to reduction
+ lookahead sets. */
+ if (!annotation_lists)
+ {
+ state_list *node;
+ timevar_push (TV_IELR_PHASE4);
+ initialize_LA ();
+ for (node = first_state; node; node = node->next)
+ if (!node->state->consistent)
+ {
+ size_t i = 0;
+ item_number *itemset = node->state->items;
+ size_t r;
+ for (r = 0; r < node->state->reductions->num; ++r)
+ {
+ rule *this_rule = node->state->reductions->rules[r];
+ bitset lookahead_set =
+ node->state->reductions->lookahead_tokens[r];
+ if (item_number_is_rule_number (*this_rule->rhs))
+ ielr_compute_goto_follow_set (follow_kernel_items,
+ always_follows, node,
+ this_rule->lhs, lookahead_set);
+ else if (node->lookaheads)
+ {
+ /* We don't need to start the kernel item search back at
+ i=0 because both items and reductions are sorted on rule
+ number. */
+ while (!item_number_is_rule_number (ritem[itemset[i]])
+ || item_number_as_rule_number (ritem[itemset[i]])
+ != this_rule->number)
+ {
+ ++i;
+ aver (i < node->state->nitems);
+ }
+ if (node->lookaheads[i])
+ bitset_copy (lookahead_set, node->lookaheads[i]);
+ }
+ }
+ }
+ timevar_pop (TV_IELR_PHASE4);
+ }
+
+ /* Free state list. */
+ while (first_state)
+ {
+ state_list *node = first_state;
+ if (node->lookaheads)
+ {
+ size_t i;
+ for (i = 0; i < node->state->nitems; ++i)
+ if (node->lookaheads[i])
+ bitset_free (node->lookaheads[i]);
+ free (node->lookaheads);
+ }
+ first_state = node->next;
+ free (node);
+ }
+}
+
+void
+ielr (void)
+{
+ LrType lr_type;
+
+ /* Examine user options. */
+ {
+ char *type = muscle_percent_define_get ("lr.type");
+ if (STREQ (type, "lalr"))
+ lr_type = LR_TYPE__LALR;
+ else if (STREQ (type, "ielr"))
+ lr_type = LR_TYPE__IELR;
+ else if (STREQ (type, "canonical-lr"))
+ lr_type = LR_TYPE__CANONICAL_LR;
+ else
+ aver (false);
+ free (type);
+ }
+
+ /* Phase 0: LALR(1). */
+ timevar_push (TV_LALR);
+ if (lr_type == LR_TYPE__CANONICAL_LR)
+ set_goto_map ();
+ else
+ lalr ();
+ if (lr_type == LR_TYPE__LALR)
+ {
+ bitsetv_free (goto_follows);
+ timevar_pop (TV_LALR);
+ return;
+ }
+ timevar_pop (TV_LALR);
+
+ {
+ bitsetv follow_kernel_items;
+ bitsetv always_follows;
+ InadequacyList **inadequacy_lists = NULL;
+ AnnotationList **annotation_lists = NULL;
+ struct obstack annotations_obstack;
+ AnnotationIndex max_annotations = 0;
+
+ {
+ /* Phase 1: Compute Auxiliary Tables. */
+ state ***predecessors;
+ timevar_push (TV_IELR_PHASE1);
+ ielr_compute_auxiliary_tables (
+ &follow_kernel_items, &always_follows,
+ lr_type == LR_TYPE__CANONICAL_LR ? NULL : &predecessors);
+ timevar_pop (TV_IELR_PHASE1);
+
+ /* Phase 2: Compute Annotations. */
+ timevar_push (TV_IELR_PHASE2);
+ if (lr_type != LR_TYPE__CANONICAL_LR)
+ {
+ obstack_init (&annotations_obstack);
+ ielr_compute_annotation_lists (follow_kernel_items, always_follows,
+ predecessors, &max_annotations,
+ &inadequacy_lists, &annotation_lists,
+ &annotations_obstack);
+ {
+ state_number i;
+ for (i = 0; i < nstates; ++i)
+ free (predecessors[i]);
+ }
+ free (predecessors);
+ bitsetv_free (goto_follows);
+ lalr_free ();
+ }
+ timevar_pop (TV_IELR_PHASE2);
+ }
+
+ /* Phase 3: Split States. */
+ timevar_push (TV_IELR_PHASE3);
+ {
+ state_number nstates_lr0 = nstates;
+ ielr_split_states (follow_kernel_items, always_follows,
+ annotation_lists, max_annotations);
+ if (inadequacy_lists)
+ {
+ state_number i;
+ for (i = 0; i < nstates_lr0; ++i)
+ InadequacyList__delete (inadequacy_lists[i]);
+ }
+ }
+ free (inadequacy_lists);
+ if (annotation_lists)
+ obstack_free (&annotations_obstack, NULL);
+ free (annotation_lists);
+ bitsetv_free (follow_kernel_items);
+ bitsetv_free (always_follows);
+ timevar_pop (TV_IELR_PHASE3);
+ }
+
+ /* Phase 4: Compute Reduction Lookaheads. */
+ timevar_push (TV_IELR_PHASE4);
+ free (goto_map);
+ free (from_state);
+ free (to_state);
+ if (lr_type == LR_TYPE__CANONICAL_LR)
+ {
+ /* Reduction lookaheads are computed in ielr_split_states above
+ but are timed as part of phase 4. */
+ set_goto_map ();
+ }
+ else
+ {
+ lalr ();
+ bitsetv_free (goto_follows);
+ }
+ timevar_pop (TV_IELR_PHASE4);
+}
diff --git a/contrib/tools/bison/bison/src/ielr.h b/contrib/tools/bison/bison/src/ielr.h
index b60ae36348..fe16746163 100644
--- a/contrib/tools/bison/bison/src/ielr.h
+++ b/contrib/tools/bison/bison/src/ielr.h
@@ -1,46 +1,46 @@
-/* IELR main implementation.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef IELR_H_
-# define IELR_H_
-
-# include <bitset.h>
-
-# include "state.h"
-
-/**
- * \pre
- * - \c ::states is of size \c ::nstates and defines an LR(0) parser
- * for the users's grammar.
- * - \c ::ntokens is the number of tokens in the grammar.
- * \post
- * - \c ::states is of size \c ::nstates (which might be greater than
- * <tt>::nstates \@pre</tt>) and defines the type of parser specified by
- * the value of the \c \%define variable \c lr.type. Its value can be:
- * - \c "lalr".
- * - \c "ielr".
- * - \c "canonical-lr".
- */
-void ielr (void);
-
-bool ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item,
- symbol_number lookahead, state ***predecessors,
- bitset **item_lookahead_sets);
-
-#endif /* !IELR_H_ */
+/* IELR main implementation.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef IELR_H_
+# define IELR_H_
+
+# include <bitset.h>
+
+# include "state.h"
+
+/**
+ * \pre
+ * - \c ::states is of size \c ::nstates and defines an LR(0) parser
+ * for the users's grammar.
+ * - \c ::ntokens is the number of tokens in the grammar.
+ * \post
+ * - \c ::states is of size \c ::nstates (which might be greater than
+ * <tt>::nstates \@pre</tt>) and defines the type of parser specified by
+ * the value of the \c \%define variable \c lr.type. Its value can be:
+ * - \c "lalr".
+ * - \c "ielr".
+ * - \c "canonical-lr".
+ */
+void ielr (void);
+
+bool ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item,
+ symbol_number lookahead, state ***predecessors,
+ bitset **item_lookahead_sets);
+
+#endif /* !IELR_H_ */
diff --git a/contrib/tools/bison/bison/src/lalr.c b/contrib/tools/bison/bison/src/lalr.c
index d99f960fbf..379e209d98 100644
--- a/contrib/tools/bison/bison/src/lalr.c
+++ b/contrib/tools/bison/bison/src/lalr.c
@@ -1,500 +1,500 @@
-/* Compute lookahead criteria for Bison.
-
- Copyright (C) 1984, 1986, 1989, 2000-2013 Free Software Foundation,
- Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/* Find which rules need lookahead in each state, and which lookahead
- tokens they accept. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitset.h>
-#include <bitsetv.h>
-
-#include "LR0.h"
-#include "complain.h"
-#include "derives.h"
-#include "getargs.h"
-#include "gram.h"
-#include "lalr.h"
-#include "muscle-tab.h"
-#include "nullable.h"
-#include "reader.h"
-#include "relation.h"
-#include "symtab.h"
-
-goto_number *goto_map;
-goto_number ngotos;
-state_number *from_state;
-state_number *to_state;
-bitsetv goto_follows = NULL;
-
-/* Linked list of goto numbers. */
-typedef struct goto_list
-{
- struct goto_list *next;
- goto_number value;
-} goto_list;
-
-
-/* LA is an NLA by NTOKENS matrix of bits. LA[l, i] is 1 if the rule
- LArule[l] is applicable in the appropriate state when the next
- token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j,
- it is a conflict. */
-
-static bitsetv LA = NULL;
-size_t nLA;
-
-
-static goto_number **includes;
-static goto_list **lookback;
-
-
-
-
-void
-set_goto_map (void)
-{
- state_number s;
- goto_number *temp_map;
-
- goto_map = xcalloc (nvars + 1, sizeof *goto_map);
- temp_map = xnmalloc (nvars + 1, sizeof *temp_map);
-
- ngotos = 0;
- for (s = 0; s < nstates; ++s)
- {
- transitions *sp = states[s]->transitions;
- int i;
- for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
- {
- ngotos++;
-
- /* Abort if (ngotos + 1) would overflow. */
- aver (ngotos != GOTO_NUMBER_MAXIMUM);
-
- goto_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
- }
- }
-
- {
- goto_number k = 0;
- int i;
- for (i = ntokens; i < nsyms; i++)
- {
- temp_map[i - ntokens] = k;
- k += goto_map[i - ntokens];
- }
-
- for (i = ntokens; i < nsyms; i++)
- goto_map[i - ntokens] = temp_map[i - ntokens];
-
- goto_map[nsyms - ntokens] = ngotos;
- temp_map[nsyms - ntokens] = ngotos;
- }
-
- from_state = xcalloc (ngotos, sizeof *from_state);
- to_state = xcalloc (ngotos, sizeof *to_state);
-
- for (s = 0; s < nstates; ++s)
- {
- transitions *sp = states[s]->transitions;
- int i;
- for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
- {
- goto_number k = temp_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
- from_state[k] = s;
- to_state[k] = sp->states[i]->number;
- }
- }
-
- free (temp_map);
-}
-
-
-goto_number
-map_goto (state_number s0, symbol_number sym)
-{
- goto_number high;
- goto_number low;
- goto_number middle;
- state_number s;
-
- low = goto_map[sym - ntokens];
- high = goto_map[sym - ntokens + 1] - 1;
-
- for (;;)
- {
- aver (low <= high);
- middle = (low + high) / 2;
- s = from_state[middle];
- if (s == s0)
- return middle;
- else if (s < s0)
- low = middle + 1;
- else
- high = middle - 1;
- }
-}
-
-
-static void
-initialize_F (void)
-{
- goto_number **reads = xnmalloc (ngotos, sizeof *reads);
- goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
- goto_number nedges = 0;
-
- goto_number i;
-
- goto_follows = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
-
- for (i = 0; i < ngotos; i++)
- {
- state_number stateno = to_state[i];
- transitions *sp = states[stateno]->transitions;
-
- int j;
- FOR_EACH_SHIFT (sp, j)
- bitset_set (goto_follows[i], TRANSITION_SYMBOL (sp, j));
-
- for (; j < sp->num; j++)
- {
- symbol_number sym = TRANSITION_SYMBOL (sp, j);
- if (nullable[sym - ntokens])
- edge[nedges++] = map_goto (stateno, sym);
- }
-
- if (nedges == 0)
- reads[i] = NULL;
- else
- {
- reads[i] = xnmalloc (nedges + 1, sizeof reads[i][0]);
- memcpy (reads[i], edge, nedges * sizeof edge[0]);
- reads[i][nedges] = END_NODE;
- nedges = 0;
- }
- }
-
- relation_digraph (reads, ngotos, &goto_follows);
-
- for (i = 0; i < ngotos; i++)
- free (reads[i]);
-
- free (reads);
- free (edge);
-}
-
-
-static void
-add_lookback_edge (state *s, rule *r, goto_number gotono)
-{
- int ri = state_reduction_find (s, r);
- goto_list *sp = xmalloc (sizeof *sp);
- sp->next = lookback[(s->reductions->lookahead_tokens - LA) + ri];
- sp->value = gotono;
- lookback[(s->reductions->lookahead_tokens - LA) + ri] = sp;
-}
-
-
-
-static void
-build_relations (void)
-{
- goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
- state_number *states1 = xnmalloc (ritem_longest_rhs () + 1, sizeof *states1);
- goto_number i;
-
- includes = xnmalloc (ngotos, sizeof *includes);
-
- for (i = 0; i < ngotos; i++)
- {
- int nedges = 0;
- symbol_number symbol1 = states[to_state[i]]->accessing_symbol;
- rule **rulep;
-
- for (rulep = derives[symbol1 - ntokens]; *rulep; rulep++)
- {
- bool done;
- int length = 1;
- item_number const *rp;
- state *s = states[from_state[i]];
- states1[0] = s->number;
-
- for (rp = (*rulep)->rhs; ! item_number_is_rule_number (*rp); rp++)
- {
- s = transitions_to (s->transitions,
- item_number_as_symbol_number (*rp));
- states1[length++] = s->number;
- }
-
- if (!s->consistent)
- add_lookback_edge (s, *rulep, i);
-
- length--;
- done = false;
- while (!done)
- {
- done = true;
- /* Each rhs ends in a rule number, and there is a
- sentinel (ritem[-1]=0) before the first rhs, so it is safe to
- decrement RP here. */
- rp--;
- if (ISVAR (*rp))
- {
- /* Downcasting from item_number to symbol_number. */
- edge[nedges++] = map_goto (states1[--length],
- item_number_as_symbol_number (*rp));
- if (nullable[*rp - ntokens])
- done = false;
- }
- }
- }
-
- if (nedges == 0)
- includes[i] = NULL;
- else
- {
- int j;
- includes[i] = xnmalloc (nedges + 1, sizeof includes[i][0]);
- for (j = 0; j < nedges; j++)
- includes[i][j] = edge[j];
- includes[i][nedges] = END_NODE;
- }
- }
-
- free (edge);
- free (states1);
-
- relation_transpose (&includes, ngotos);
-}
-
-
-
-static void
-compute_FOLLOWS (void)
-{
- goto_number i;
-
- relation_digraph (includes, ngotos, &goto_follows);
-
- for (i = 0; i < ngotos; i++)
- free (includes[i]);
-
- free (includes);
-}
-
-
-static void
-compute_lookahead_tokens (void)
-{
- size_t i;
- goto_list *sp;
-
- for (i = 0; i < nLA; i++)
- for (sp = lookback[i]; sp; sp = sp->next)
- bitset_or (LA[i], LA[i], goto_follows[sp->value]);
-
- /* Free LOOKBACK. */
- for (i = 0; i < nLA; i++)
- LIST_FREE (goto_list, lookback[i]);
-
- free (lookback);
-}
-
-
-/*----------------------------------------------------.
-| Count the number of lookahead tokens required for S |
-| (N_LOOKAHEAD_TOKENS member). |
-`----------------------------------------------------*/
-
-static int
-state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
-{
- int n_lookahead_tokens = 0;
- reductions *rp = s->reductions;
- transitions *sp = s->transitions;
-
- /* Transitions are only disabled during conflict resolution, and that
- hasn't happened yet, so there should be no need to check that
- transition 0 hasn't been disabled before checking if it is a shift.
- However, this check was performed at one time, so we leave it as an
- aver. */
- aver (sp->num == 0 || !TRANSITION_IS_DISABLED (sp, 0));
-
- /* We need a lookahead either to distinguish different reductions
- (i.e., there are two or more), or to distinguish a reduction from a
- shift. Otherwise, it is straightforward, and the state is
- 'consistent'. However, do not treat a state with any reductions as
- consistent unless it is the accepting state (because there is never
- a lookahead token that makes sense there, and so no lookahead token
- should be read) if the user has otherwise disabled default
- reductions. */
- if (rp->num > 1
- || (rp->num == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0))
- || (rp->num == 1 && rp->rules[0]->number != 0
- && default_reduction_only_for_accept))
- n_lookahead_tokens += rp->num;
- else
- s->consistent = 1;
-
- return n_lookahead_tokens;
-}
-
-
-/*----------------------------------------------------.
-| Compute LA, NLA, and the lookahead_tokens members. |
-`----------------------------------------------------*/
-
-void
-initialize_LA (void)
-{
- state_number i;
- bitsetv pLA;
- bool default_reduction_only_for_accept;
- {
- char *default_reductions =
- muscle_percent_define_get ("lr.default-reduction");
- default_reduction_only_for_accept = STREQ (default_reductions, "accepting");
- free (default_reductions);
- }
-
- /* Compute the total number of reductions requiring a lookahead. */
- nLA = 0;
- for (i = 0; i < nstates; i++)
- nLA +=
- state_lookahead_tokens_count (states[i],
- default_reduction_only_for_accept);
- /* Avoid having to special case 0. */
- if (!nLA)
- nLA = 1;
-
- pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
-
- /* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
- require lookahead tokens. */
- for (i = 0; i < nstates; i++)
- {
- int count =
- state_lookahead_tokens_count (states[i],
- default_reduction_only_for_accept);
- if (count)
- {
- states[i]->reductions->lookahead_tokens = pLA;
- pLA += count;
- }
- }
-}
-
-
-/*---------------------------------------------.
-| Output the lookahead tokens for each state. |
-`---------------------------------------------*/
-
-static void
-lookahead_tokens_print (FILE *out)
-{
- state_number i;
- int j, k;
- fprintf (out, "Lookahead tokens: BEGIN\n");
- for (i = 0; i < nstates; ++i)
- {
- reductions *reds = states[i]->reductions;
- bitset_iterator iter;
- int n_lookahead_tokens = 0;
-
- if (reds->lookahead_tokens)
- for (k = 0; k < reds->num; ++k)
- if (reds->lookahead_tokens[k])
- ++n_lookahead_tokens;
-
- fprintf (out, "State %d: %d lookahead tokens\n",
- i, n_lookahead_tokens);
-
- if (reds->lookahead_tokens)
- for (j = 0; j < reds->num; ++j)
- BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0)
- {
- fprintf (out, " on %d (%s) -> rule %d\n",
- k, symbols[k]->tag,
- reds->rules[j]->number);
- };
- }
- fprintf (out, "Lookahead tokens: END\n");
-}
-
-void
-lalr (void)
-{
- initialize_LA ();
- set_goto_map ();
- initialize_F ();
- lookback = xcalloc (nLA, sizeof *lookback);
- build_relations ();
- compute_FOLLOWS ();
- compute_lookahead_tokens ();
-
- if (trace_flag & trace_sets)
- lookahead_tokens_print (stderr);
-}
-
-
-void
-lalr_update_state_numbers (state_number old_to_new[], state_number nstates_old)
-{
- goto_number ngotos_reachable = 0;
- symbol_number nonterminal = 0;
- aver (nsyms == nvars + ntokens);
- {
- goto_number i;
- for (i = 0; i < ngotos; ++i)
- {
- while (i == goto_map[nonterminal])
- goto_map[nonterminal++] = ngotos_reachable;
- /* If old_to_new[from_state[i]] = nstates_old, remove this goto
- entry. */
- if (old_to_new[from_state[i]] != nstates_old)
- {
- /* from_state[i] is not removed, so it and thus to_state[i] are
- reachable, so to_state[i] != nstates_old. */
- aver (old_to_new[to_state[i]] != nstates_old);
- from_state[ngotos_reachable] = old_to_new[from_state[i]];
- to_state[ngotos_reachable] = old_to_new[to_state[i]];
- ++ngotos_reachable;
- }
- }
- }
- while (nonterminal <= nvars)
- {
- aver (ngotos == goto_map[nonterminal]);
- goto_map[nonterminal++] = ngotos_reachable;
- }
- ngotos = ngotos_reachable;
-}
-
-
-void
-lalr_free (void)
-{
- state_number s;
- for (s = 0; s < nstates; ++s)
- states[s]->reductions->lookahead_tokens = NULL;
- bitsetv_free (LA);
-}
+/* Compute lookahead criteria for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 2000-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+/* Find which rules need lookahead in each state, and which lookahead
+ tokens they accept. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitset.h>
+#include <bitsetv.h>
+
+#include "LR0.h"
+#include "complain.h"
+#include "derives.h"
+#include "getargs.h"
+#include "gram.h"
+#include "lalr.h"
+#include "muscle-tab.h"
+#include "nullable.h"
+#include "reader.h"
+#include "relation.h"
+#include "symtab.h"
+
+goto_number *goto_map;
+goto_number ngotos;
+state_number *from_state;
+state_number *to_state;
+bitsetv goto_follows = NULL;
+
+/* Linked list of goto numbers. */
+typedef struct goto_list
+{
+ struct goto_list *next;
+ goto_number value;
+} goto_list;
+
+
+/* LA is an NLA by NTOKENS matrix of bits. LA[l, i] is 1 if the rule
+ LArule[l] is applicable in the appropriate state when the next
+ token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j,
+ it is a conflict. */
+
+static bitsetv LA = NULL;
+size_t nLA;
+
+
+static goto_number **includes;
+static goto_list **lookback;
+
+
+
+
+void
+set_goto_map (void)
+{
+ state_number s;
+ goto_number *temp_map;
+
+ goto_map = xcalloc (nvars + 1, sizeof *goto_map);
+ temp_map = xnmalloc (nvars + 1, sizeof *temp_map);
+
+ ngotos = 0;
+ for (s = 0; s < nstates; ++s)
+ {
+ transitions *sp = states[s]->transitions;
+ int i;
+ for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
+ {
+ ngotos++;
+
+ /* Abort if (ngotos + 1) would overflow. */
+ aver (ngotos != GOTO_NUMBER_MAXIMUM);
+
+ goto_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
+ }
+ }
+
+ {
+ goto_number k = 0;
+ int i;
+ for (i = ntokens; i < nsyms; i++)
+ {
+ temp_map[i - ntokens] = k;
+ k += goto_map[i - ntokens];
+ }
+
+ for (i = ntokens; i < nsyms; i++)
+ goto_map[i - ntokens] = temp_map[i - ntokens];
+
+ goto_map[nsyms - ntokens] = ngotos;
+ temp_map[nsyms - ntokens] = ngotos;
+ }
+
+ from_state = xcalloc (ngotos, sizeof *from_state);
+ to_state = xcalloc (ngotos, sizeof *to_state);
+
+ for (s = 0; s < nstates; ++s)
+ {
+ transitions *sp = states[s]->transitions;
+ int i;
+ for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
+ {
+ goto_number k = temp_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
+ from_state[k] = s;
+ to_state[k] = sp->states[i]->number;
+ }
+ }
+
+ free (temp_map);
+}
+
+
+goto_number
+map_goto (state_number s0, symbol_number sym)
+{
+ goto_number high;
+ goto_number low;
+ goto_number middle;
+ state_number s;
+
+ low = goto_map[sym - ntokens];
+ high = goto_map[sym - ntokens + 1] - 1;
+
+ for (;;)
+ {
+ aver (low <= high);
+ middle = (low + high) / 2;
+ s = from_state[middle];
+ if (s == s0)
+ return middle;
+ else if (s < s0)
+ low = middle + 1;
+ else
+ high = middle - 1;
+ }
+}
+
+
+static void
+initialize_F (void)
+{
+ goto_number **reads = xnmalloc (ngotos, sizeof *reads);
+ goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
+ goto_number nedges = 0;
+
+ goto_number i;
+
+ goto_follows = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
+
+ for (i = 0; i < ngotos; i++)
+ {
+ state_number stateno = to_state[i];
+ transitions *sp = states[stateno]->transitions;
+
+ int j;
+ FOR_EACH_SHIFT (sp, j)
+ bitset_set (goto_follows[i], TRANSITION_SYMBOL (sp, j));
+
+ for (; j < sp->num; j++)
+ {
+ symbol_number sym = TRANSITION_SYMBOL (sp, j);
+ if (nullable[sym - ntokens])
+ edge[nedges++] = map_goto (stateno, sym);
+ }
+
+ if (nedges == 0)
+ reads[i] = NULL;
+ else
+ {
+ reads[i] = xnmalloc (nedges + 1, sizeof reads[i][0]);
+ memcpy (reads[i], edge, nedges * sizeof edge[0]);
+ reads[i][nedges] = END_NODE;
+ nedges = 0;
+ }
+ }
+
+ relation_digraph (reads, ngotos, &goto_follows);
+
+ for (i = 0; i < ngotos; i++)
+ free (reads[i]);
+
+ free (reads);
+ free (edge);
+}
+
+
+static void
+add_lookback_edge (state *s, rule *r, goto_number gotono)
+{
+ int ri = state_reduction_find (s, r);
+ goto_list *sp = xmalloc (sizeof *sp);
+ sp->next = lookback[(s->reductions->lookahead_tokens - LA) + ri];
+ sp->value = gotono;
+ lookback[(s->reductions->lookahead_tokens - LA) + ri] = sp;
+}
+
+
+
+static void
+build_relations (void)
+{
+ goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge);
+ state_number *states1 = xnmalloc (ritem_longest_rhs () + 1, sizeof *states1);
+ goto_number i;
+
+ includes = xnmalloc (ngotos, sizeof *includes);
+
+ for (i = 0; i < ngotos; i++)
+ {
+ int nedges = 0;
+ symbol_number symbol1 = states[to_state[i]]->accessing_symbol;
+ rule **rulep;
+
+ for (rulep = derives[symbol1 - ntokens]; *rulep; rulep++)
+ {
+ bool done;
+ int length = 1;
+ item_number const *rp;
+ state *s = states[from_state[i]];
+ states1[0] = s->number;
+
+ for (rp = (*rulep)->rhs; ! item_number_is_rule_number (*rp); rp++)
+ {
+ s = transitions_to (s->transitions,
+ item_number_as_symbol_number (*rp));
+ states1[length++] = s->number;
+ }
+
+ if (!s->consistent)
+ add_lookback_edge (s, *rulep, i);
+
+ length--;
+ done = false;
+ while (!done)
+ {
+ done = true;
+ /* Each rhs ends in a rule number, and there is a
+ sentinel (ritem[-1]=0) before the first rhs, so it is safe to
+ decrement RP here. */
+ rp--;
+ if (ISVAR (*rp))
+ {
+ /* Downcasting from item_number to symbol_number. */
+ edge[nedges++] = map_goto (states1[--length],
+ item_number_as_symbol_number (*rp));
+ if (nullable[*rp - ntokens])
+ done = false;
+ }
+ }
+ }
+
+ if (nedges == 0)
+ includes[i] = NULL;
+ else
+ {
+ int j;
+ includes[i] = xnmalloc (nedges + 1, sizeof includes[i][0]);
+ for (j = 0; j < nedges; j++)
+ includes[i][j] = edge[j];
+ includes[i][nedges] = END_NODE;
+ }
+ }
+
+ free (edge);
+ free (states1);
+
+ relation_transpose (&includes, ngotos);
+}
+
+
+
+static void
+compute_FOLLOWS (void)
+{
+ goto_number i;
+
+ relation_digraph (includes, ngotos, &goto_follows);
+
+ for (i = 0; i < ngotos; i++)
+ free (includes[i]);
+
+ free (includes);
+}
+
+
+static void
+compute_lookahead_tokens (void)
+{
+ size_t i;
+ goto_list *sp;
+
+ for (i = 0; i < nLA; i++)
+ for (sp = lookback[i]; sp; sp = sp->next)
+ bitset_or (LA[i], LA[i], goto_follows[sp->value]);
+
+ /* Free LOOKBACK. */
+ for (i = 0; i < nLA; i++)
+ LIST_FREE (goto_list, lookback[i]);
+
+ free (lookback);
+}
+
+
+/*----------------------------------------------------.
+| Count the number of lookahead tokens required for S |
+| (N_LOOKAHEAD_TOKENS member). |
+`----------------------------------------------------*/
+
+static int
+state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
+{
+ int n_lookahead_tokens = 0;
+ reductions *rp = s->reductions;
+ transitions *sp = s->transitions;
+
+ /* Transitions are only disabled during conflict resolution, and that
+ hasn't happened yet, so there should be no need to check that
+ transition 0 hasn't been disabled before checking if it is a shift.
+ However, this check was performed at one time, so we leave it as an
+ aver. */
+ aver (sp->num == 0 || !TRANSITION_IS_DISABLED (sp, 0));
+
+ /* We need a lookahead either to distinguish different reductions
+ (i.e., there are two or more), or to distinguish a reduction from a
+ shift. Otherwise, it is straightforward, and the state is
+ 'consistent'. However, do not treat a state with any reductions as
+ consistent unless it is the accepting state (because there is never
+ a lookahead token that makes sense there, and so no lookahead token
+ should be read) if the user has otherwise disabled default
+ reductions. */
+ if (rp->num > 1
+ || (rp->num == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0))
+ || (rp->num == 1 && rp->rules[0]->number != 0
+ && default_reduction_only_for_accept))
+ n_lookahead_tokens += rp->num;
+ else
+ s->consistent = 1;
+
+ return n_lookahead_tokens;
+}
+
+
+/*----------------------------------------------------.
+| Compute LA, NLA, and the lookahead_tokens members. |
+`----------------------------------------------------*/
+
+void
+initialize_LA (void)
+{
+ state_number i;
+ bitsetv pLA;
+ bool default_reduction_only_for_accept;
+ {
+ char *default_reductions =
+ muscle_percent_define_get ("lr.default-reduction");
+ default_reduction_only_for_accept = STREQ (default_reductions, "accepting");
+ free (default_reductions);
+ }
+
+ /* Compute the total number of reductions requiring a lookahead. */
+ nLA = 0;
+ for (i = 0; i < nstates; i++)
+ nLA +=
+ state_lookahead_tokens_count (states[i],
+ default_reduction_only_for_accept);
+ /* Avoid having to special case 0. */
+ if (!nLA)
+ nLA = 1;
+
+ pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
+
+ /* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
+ require lookahead tokens. */
+ for (i = 0; i < nstates; i++)
+ {
+ int count =
+ state_lookahead_tokens_count (states[i],
+ default_reduction_only_for_accept);
+ if (count)
+ {
+ states[i]->reductions->lookahead_tokens = pLA;
+ pLA += count;
+ }
+ }
+}
+
+
+/*---------------------------------------------.
+| Output the lookahead tokens for each state. |
+`---------------------------------------------*/
+
+static void
+lookahead_tokens_print (FILE *out)
+{
+ state_number i;
+ int j, k;
+ fprintf (out, "Lookahead tokens: BEGIN\n");
+ for (i = 0; i < nstates; ++i)
+ {
+ reductions *reds = states[i]->reductions;
+ bitset_iterator iter;
+ int n_lookahead_tokens = 0;
+
+ if (reds->lookahead_tokens)
+ for (k = 0; k < reds->num; ++k)
+ if (reds->lookahead_tokens[k])
+ ++n_lookahead_tokens;
+
+ fprintf (out, "State %d: %d lookahead tokens\n",
+ i, n_lookahead_tokens);
+
+ if (reds->lookahead_tokens)
+ for (j = 0; j < reds->num; ++j)
+ BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0)
+ {
+ fprintf (out, " on %d (%s) -> rule %d\n",
+ k, symbols[k]->tag,
+ reds->rules[j]->number);
+ };
+ }
+ fprintf (out, "Lookahead tokens: END\n");
+}
+
+void
+lalr (void)
+{
+ initialize_LA ();
+ set_goto_map ();
+ initialize_F ();
+ lookback = xcalloc (nLA, sizeof *lookback);
+ build_relations ();
+ compute_FOLLOWS ();
+ compute_lookahead_tokens ();
+
+ if (trace_flag & trace_sets)
+ lookahead_tokens_print (stderr);
+}
+
+
+void
+lalr_update_state_numbers (state_number old_to_new[], state_number nstates_old)
+{
+ goto_number ngotos_reachable = 0;
+ symbol_number nonterminal = 0;
+ aver (nsyms == nvars + ntokens);
+ {
+ goto_number i;
+ for (i = 0; i < ngotos; ++i)
+ {
+ while (i == goto_map[nonterminal])
+ goto_map[nonterminal++] = ngotos_reachable;
+ /* If old_to_new[from_state[i]] = nstates_old, remove this goto
+ entry. */
+ if (old_to_new[from_state[i]] != nstates_old)
+ {
+ /* from_state[i] is not removed, so it and thus to_state[i] are
+ reachable, so to_state[i] != nstates_old. */
+ aver (old_to_new[to_state[i]] != nstates_old);
+ from_state[ngotos_reachable] = old_to_new[from_state[i]];
+ to_state[ngotos_reachable] = old_to_new[to_state[i]];
+ ++ngotos_reachable;
+ }
+ }
+ }
+ while (nonterminal <= nvars)
+ {
+ aver (ngotos == goto_map[nonterminal]);
+ goto_map[nonterminal++] = ngotos_reachable;
+ }
+ ngotos = ngotos_reachable;
+}
+
+
+void
+lalr_free (void)
+{
+ state_number s;
+ for (s = 0; s < nstates; ++s)
+ states[s]->reductions->lookahead_tokens = NULL;
+ bitsetv_free (LA);
+}
diff --git a/contrib/tools/bison/bison/src/lalr.h b/contrib/tools/bison/bison/src/lalr.h
index f483315747..e904bc9e00 100644
--- a/contrib/tools/bison/bison/src/lalr.h
+++ b/contrib/tools/bison/bison/src/lalr.h
@@ -1,106 +1,106 @@
-/* Compute lookahead criteria for bison,
-
- Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004, 2006-2007,
- 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef LALR_H_
-# define LALR_H_
-
-# include <bitset.h>
-# include <bitsetv.h>
-
-/* Import the definition of RULE_T. */
-# include "gram.h"
-
-/* Import the definition of CORE, TRANSITIONS and REDUCTIONS. */
-# include "state.h"
-
-
-/** Build the LALR(1) automaton.
-
- Find which rules need lookahead in each state, and which lookahead
- tokens they accept.
-
- Also builds:
- - #goto_map
- - #from_state
- - #to_state
- - #goto_follows
-*/
-void lalr (void);
-
-/**
- * Set #nLA and allocate all reduction lookahead sets. Normally invoked by
- * #lalr.
- */
-void initialize_LA (void);
-
-/**
- * Build only:
- * - #goto_map
- * - #from_state
- * - #to_state
- * Normally invoked by #lalr.
- */
-void set_goto_map (void);
-
-/**
- * Update state numbers recorded in #goto_map, #from_state, and #to_state such
- * that:
- * - \c nstates_old is the old number of states.
- * - Where \c i is the old state number, <tt>old_to_new[i]</tt> is either:
- * - \c nstates_old if state \c i is removed because it is unreachable.
- * Thus, remove all goto entries involving this state.
- * - The new state number.
- */
-void lalr_update_state_numbers (state_number old_to_new[],
- state_number nstates_old);
-
-
-/** Release the information related to lookahead tokens.
-
- Can be performed once the action tables are computed. */
-void lalr_free (void);
-
-typedef size_t goto_number;
-# define GOTO_NUMBER_MAXIMUM ((goto_number) -1)
-
-/** Index into #from_state and #to_state.
-
- All the transitions that accept a particular variable are grouped
- together and GOTO_MAP[I - NTOKENS] is the index in FROM_STATE and
- TO_STATE of the first of them. */
-extern goto_number *goto_map;
-
-/** The size of #from_state and #to_state. */
-extern goto_number ngotos;
-
-/** State number which a transition leads from. */
-extern state_number *from_state;
-
-/** State number it leads to. */
-extern state_number *to_state;
-
-/** Map a state/symbol pair into its numeric representation. */
-goto_number map_goto (state_number s0, symbol_number sym);
-
-/* goto_follows[i] is the set of tokens following goto i. */
-extern bitsetv goto_follows;
-
-
-#endif /* !LALR_H_ */
+/* Compute lookahead criteria for bison,
+
+ Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004, 2006-2007,
+ 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LALR_H_
+# define LALR_H_
+
+# include <bitset.h>
+# include <bitsetv.h>
+
+/* Import the definition of RULE_T. */
+# include "gram.h"
+
+/* Import the definition of CORE, TRANSITIONS and REDUCTIONS. */
+# include "state.h"
+
+
+/** Build the LALR(1) automaton.
+
+ Find which rules need lookahead in each state, and which lookahead
+ tokens they accept.
+
+ Also builds:
+ - #goto_map
+ - #from_state
+ - #to_state
+ - #goto_follows
+*/
+void lalr (void);
+
+/**
+ * Set #nLA and allocate all reduction lookahead sets. Normally invoked by
+ * #lalr.
+ */
+void initialize_LA (void);
+
+/**
+ * Build only:
+ * - #goto_map
+ * - #from_state
+ * - #to_state
+ * Normally invoked by #lalr.
+ */
+void set_goto_map (void);
+
+/**
+ * Update state numbers recorded in #goto_map, #from_state, and #to_state such
+ * that:
+ * - \c nstates_old is the old number of states.
+ * - Where \c i is the old state number, <tt>old_to_new[i]</tt> is either:
+ * - \c nstates_old if state \c i is removed because it is unreachable.
+ * Thus, remove all goto entries involving this state.
+ * - The new state number.
+ */
+void lalr_update_state_numbers (state_number old_to_new[],
+ state_number nstates_old);
+
+
+/** Release the information related to lookahead tokens.
+
+ Can be performed once the action tables are computed. */
+void lalr_free (void);
+
+typedef size_t goto_number;
+# define GOTO_NUMBER_MAXIMUM ((goto_number) -1)
+
+/** Index into #from_state and #to_state.
+
+ All the transitions that accept a particular variable are grouped
+ together and GOTO_MAP[I - NTOKENS] is the index in FROM_STATE and
+ TO_STATE of the first of them. */
+extern goto_number *goto_map;
+
+/** The size of #from_state and #to_state. */
+extern goto_number ngotos;
+
+/** State number which a transition leads from. */
+extern state_number *from_state;
+
+/** State number it leads to. */
+extern state_number *to_state;
+
+/** Map a state/symbol pair into its numeric representation. */
+goto_number map_goto (state_number s0, symbol_number sym);
+
+/* goto_follows[i] is the set of tokens following goto i. */
+extern bitsetv goto_follows;
+
+
+#endif /* !LALR_H_ */
diff --git a/contrib/tools/bison/bison/src/local.mk b/contrib/tools/bison/bison/src/local.mk
index 9e0848c29d..7a14e3a5c2 100644
--- a/contrib/tools/bison/bison/src/local.mk
+++ b/contrib/tools/bison/bison/src/local.mk
@@ -1,123 +1,123 @@
-# Copyright (C) 2001-2013 Free Software Foundation, Inc.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-LDADD = lib/libbison.a $(LIBINTL)
-
-bin_PROGRAMS = src/bison
-# Prettify Automake-computed names of compiled objects.
-src_bison_SHORTNAME = bison
-
-src_bison_CFLAGS = $(AM_CFLAGS) $(WERROR_CFLAGS)
-src_bison_SOURCES = \
- src/AnnotationList.c \
- src/AnnotationList.h \
- src/InadequacyList.c \
- src/InadequacyList.h \
- src/LR0.c \
- src/LR0.h \
- src/Sbitset.c \
- src/Sbitset.h \
- src/assoc.c \
- src/assoc.h \
- src/closure.c \
- src/closure.h \
- src/complain.c \
- src/complain.h \
- src/conflicts.c \
- src/conflicts.h \
- src/derives.c \
- src/derives.h \
- src/files.c \
- src/files.h \
- src/flex-scanner.h \
- src/getargs.c \
- src/getargs.h \
- src/gram.c \
- src/gram.h \
- src/graphviz.c \
- src/graphviz.h \
- src/lalr.c \
- src/lalr.h \
- src/ielr.c \
- src/ielr.h \
- src/location.c \
- src/location.h \
- src/main.c \
- src/muscle-tab.c \
- src/muscle-tab.h \
- src/named-ref.c \
- src/named-ref.h \
- src/nullable.c \
- src/nullable.h \
- src/output.c \
- src/output.h \
- src/parse-gram.y \
- src/print-xml.c \
- src/print-xml.h \
- src/print.c \
- src/print.h \
- src/print_graph.c \
- src/print_graph.h \
- src/reader.c \
- src/reader.h \
- src/reduce.c \
- src/reduce.h \
- src/relation.c \
- src/relation.h \
- src/scan-code-c.c \
- src/scan-code.h \
- src/scan-gram-c.c \
- src/scan-gram.h \
- src/scan-skel-c.c \
- src/scan-skel.h \
- src/state.c \
- src/state.h \
- src/symlist.c \
- src/symlist.h \
- src/symtab.c \
- src/symtab.h \
- src/system.h \
- src/tables.c \
- src/tables.h \
- src/uniqstr.c \
- src/uniqstr.h
-
-EXTRA_src_bison_SOURCES = \
- src/scan-code.l \
- src/scan-gram.l \
- src/scan-skel.l
-
-BUILT_SOURCES += \
- src/parse-gram.c \
- src/parse-gram.h \
- src/scan-code.c \
- src/scan-gram.c \
- src/scan-skel.c
-
-
-## ------ ##
-## yacc. ##
-## ------ ##
-
-bin_SCRIPTS = $(YACC_SCRIPT)
-EXTRA_SCRIPTS = src/yacc
-MOSTLYCLEANFILES += src/yacc
-
-src/yacc:
- $(AM_V_GEN)rm -f $@ $@.tmp
- $(AM_V_at)echo '#! /bin/sh' >$@.tmp
- $(AM_V_at)echo "exec '$(bindir)/bison' -y "'"$$@"' >>$@.tmp
- $(AM_V_at)chmod a+x $@.tmp
- $(AM_V_at)mv $@.tmp $@
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+LDADD = lib/libbison.a $(LIBINTL)
+
+bin_PROGRAMS = src/bison
+# Prettify Automake-computed names of compiled objects.
+src_bison_SHORTNAME = bison
+
+src_bison_CFLAGS = $(AM_CFLAGS) $(WERROR_CFLAGS)
+src_bison_SOURCES = \
+ src/AnnotationList.c \
+ src/AnnotationList.h \
+ src/InadequacyList.c \
+ src/InadequacyList.h \
+ src/LR0.c \
+ src/LR0.h \
+ src/Sbitset.c \
+ src/Sbitset.h \
+ src/assoc.c \
+ src/assoc.h \
+ src/closure.c \
+ src/closure.h \
+ src/complain.c \
+ src/complain.h \
+ src/conflicts.c \
+ src/conflicts.h \
+ src/derives.c \
+ src/derives.h \
+ src/files.c \
+ src/files.h \
+ src/flex-scanner.h \
+ src/getargs.c \
+ src/getargs.h \
+ src/gram.c \
+ src/gram.h \
+ src/graphviz.c \
+ src/graphviz.h \
+ src/lalr.c \
+ src/lalr.h \
+ src/ielr.c \
+ src/ielr.h \
+ src/location.c \
+ src/location.h \
+ src/main.c \
+ src/muscle-tab.c \
+ src/muscle-tab.h \
+ src/named-ref.c \
+ src/named-ref.h \
+ src/nullable.c \
+ src/nullable.h \
+ src/output.c \
+ src/output.h \
+ src/parse-gram.y \
+ src/print-xml.c \
+ src/print-xml.h \
+ src/print.c \
+ src/print.h \
+ src/print_graph.c \
+ src/print_graph.h \
+ src/reader.c \
+ src/reader.h \
+ src/reduce.c \
+ src/reduce.h \
+ src/relation.c \
+ src/relation.h \
+ src/scan-code-c.c \
+ src/scan-code.h \
+ src/scan-gram-c.c \
+ src/scan-gram.h \
+ src/scan-skel-c.c \
+ src/scan-skel.h \
+ src/state.c \
+ src/state.h \
+ src/symlist.c \
+ src/symlist.h \
+ src/symtab.c \
+ src/symtab.h \
+ src/system.h \
+ src/tables.c \
+ src/tables.h \
+ src/uniqstr.c \
+ src/uniqstr.h
+
+EXTRA_src_bison_SOURCES = \
+ src/scan-code.l \
+ src/scan-gram.l \
+ src/scan-skel.l
+
+BUILT_SOURCES += \
+ src/parse-gram.c \
+ src/parse-gram.h \
+ src/scan-code.c \
+ src/scan-gram.c \
+ src/scan-skel.c
+
+
+## ------ ##
+## yacc. ##
+## ------ ##
+
+bin_SCRIPTS = $(YACC_SCRIPT)
+EXTRA_SCRIPTS = src/yacc
+MOSTLYCLEANFILES += src/yacc
+
+src/yacc:
+ $(AM_V_GEN)rm -f $@ $@.tmp
+ $(AM_V_at)echo '#! /bin/sh' >$@.tmp
+ $(AM_V_at)echo "exec '$(bindir)/bison' -y "'"$$@"' >>$@.tmp
+ $(AM_V_at)chmod a+x $@.tmp
+ $(AM_V_at)mv $@.tmp $@
diff --git a/contrib/tools/bison/bison/src/location.c b/contrib/tools/bison/bison/src/location.c
index 662b2a12a0..1a7055ea96 100644
--- a/contrib/tools/bison/bison/src/location.c
+++ b/contrib/tools/bison/bison/src/location.c
@@ -1,232 +1,232 @@
-/* Locations for Bison
-
- Copyright (C) 2002, 2005-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <mbswidth.h>
-#include <quotearg.h>
-
-#include "complain.h"
-#include "location.h"
-
-location const empty_location = EMPTY_LOCATION_INIT;
-
-/* If BUF is null, add BUFSIZE (which in this case must be less than
- INT_MAX) to COLUMN; otherwise, add mbsnwidth (BUF, BUFSIZE, 0) to
- COLUMN. If an overflow occurs, or might occur but is undetectable,
- return INT_MAX. Assume COLUMN is nonnegative. */
-
-static inline int
-add_column_width (int column, char const *buf, size_t bufsize)
-{
- size_t width;
- unsigned int remaining_columns = INT_MAX - column;
-
- if (buf)
- {
- if (INT_MAX / 2 <= bufsize)
- return INT_MAX;
- width = mbsnwidth (buf, bufsize, 0);
- }
- else
- width = bufsize;
-
- return width <= remaining_columns ? column + width : INT_MAX;
-}
-
-/* Set *LOC and adjust scanner cursor to account for token TOKEN of
- size SIZE. */
-
-void
-location_compute (location *loc, boundary *cur, char const *token, size_t size)
-{
- int line = cur->line;
- int column = cur->column;
- char const *p0 = token;
- char const *p = token;
- char const *lim = token + size;
-
- loc->start = *cur;
-
- for (p = token; p < lim; p++)
- switch (*p)
- {
- case '\n':
- line += line < INT_MAX;
- column = 1;
- p0 = p + 1;
- break;
-
- case '\t':
- column = add_column_width (column, p0, p - p0);
- column = add_column_width (column, NULL, 8 - ((column - 1) & 7));
- p0 = p + 1;
- break;
-
- default:
- break;
- }
-
- cur->line = line;
- cur->column = column = add_column_width (column, p0, p - p0);
-
- loc->end = *cur;
-
- if (line == INT_MAX && loc->start.line != INT_MAX)
- complain (loc, Wother, _("line number overflow"));
- if (column == INT_MAX && loc->start.column != INT_MAX)
- complain (loc, Wother, _("column number overflow"));
-}
-
-
-unsigned
-location_print (location loc, FILE *out)
-{
- unsigned res = 0;
- int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0;
- res += fprintf (out, "%s",
- quotearg_n_style (3, escape_quoting_style, loc.start.file));
- if (0 <= loc.start.line)
- {
- res += fprintf (out, ":%d", loc.start.line);
- if (0 <= loc.start.column)
- res += fprintf (out, ".%d", loc.start.column);
- }
- if (loc.start.file != loc.end.file)
- {
- res += fprintf (out, "-%s",
- quotearg_n_style (3, escape_quoting_style,
- loc.end.file));
- if (0 <= loc.end.line)
- {
- res += fprintf (out, ":%d", loc.end.line);
- if (0 <= end_col)
- res += fprintf (out, ".%d", end_col);
- }
- }
- else if (0 <= loc.end.line)
- {
- if (loc.start.line < loc.end.line)
- {
- res += fprintf (out, "-%d", loc.end.line);
- if (0 <= end_col)
- res += fprintf (out, ".%d", end_col);
- }
- else if (0 <= end_col && loc.start.column < end_col)
- res += fprintf (out, "-%d", end_col);
- }
-
- return res;
-}
-
-
-/* Persistant data used by location_caret to avoid reopening and rereading the
- same file all over for each error. */
-struct caret_info
-{
- FILE *source;
- size_t line;
- size_t offset;
-};
-
-static struct caret_info caret_info = { NULL, 1, 0 };
-
-void
-cleanup_caret ()
-{
- if (caret_info.source)
- fclose (caret_info.source);
- caret_info.source = NULL;
- caret_info.line = 1;
- caret_info.offset = 0;
-}
-
-void
-location_caret (location loc, FILE *out)
-{
- /* FIXME: find a way to support multifile locations, and only open once each
- file. That would make the procedure future-proof. */
- if (! (caret_info.source
- || (caret_info.source = fopen (loc.start.file, "r")))
- || loc.start.column == -1 || loc.start.line == -1)
- return;
-
- /* If the line we want to quote is seekable (the same line as the previous
- location), just seek it. If it was a previous line, we lost track of it,
- so return to the start of file. */
- if (caret_info.line <= loc.start.line)
- fseek (caret_info.source, caret_info.offset, SEEK_SET);
- else
- {
- caret_info.line = 1;
- caret_info.offset = 0;
- fseek (caret_info.source, caret_info.offset, SEEK_SET);
- }
-
- /* Advance to the line's position, keeping track of the offset. */
- while (caret_info.line < loc.start.line)
- caret_info.line += getc (caret_info.source) == '\n';
- caret_info.offset = ftell (caret_info.source);
-
- /* Read the actual line. Don't update the offset, so that we keep a pointer
- to the start of the line. */
- {
- char c = getc (caret_info.source);
- if (c != EOF)
- {
- /* Quote the file, indent by a single column. */
- putc (' ', out);
- do
- putc (c, out);
- while ((c = getc (caret_info.source)) != EOF && c != '\n');
- putc ('\n', out);
-
- {
- /* The caret of a multiline location ends with the first line. */
- size_t len = loc.start.line != loc.end.line
- ? ftell (caret_info.source) - caret_info.offset
- : loc.end.column;
- int i;
-
- /* Print the carets (at least one), with the same indent as above.*/
- fprintf (out, " %*s", loc.start.column - 1, "");
- for (i = loc.start.column; i == loc.start.column || i < len; ++i)
- putc ('^', out);
- }
- putc ('\n', out);
- }
- }
-}
-
-void
-boundary_set_from_string (boundary *bound, char *loc_str)
-{
- /* Must search in reverse since the file name field may
- * contain '.' or ':'. */
- char *delim = strrchr (loc_str, '.');
- aver (delim);
- *delim = '\0';
- bound->column = atoi (delim+1);
- delim = strrchr (loc_str, ':');
- aver (delim);
- *delim = '\0';
- bound->line = atoi (delim+1);
- bound->file = uniqstr_new (loc_str);
-}
+/* Locations for Bison
+
+ Copyright (C) 2002, 2005-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <mbswidth.h>
+#include <quotearg.h>
+
+#include "complain.h"
+#include "location.h"
+
+location const empty_location = EMPTY_LOCATION_INIT;
+
+/* If BUF is null, add BUFSIZE (which in this case must be less than
+ INT_MAX) to COLUMN; otherwise, add mbsnwidth (BUF, BUFSIZE, 0) to
+ COLUMN. If an overflow occurs, or might occur but is undetectable,
+ return INT_MAX. Assume COLUMN is nonnegative. */
+
+static inline int
+add_column_width (int column, char const *buf, size_t bufsize)
+{
+ size_t width;
+ unsigned int remaining_columns = INT_MAX - column;
+
+ if (buf)
+ {
+ if (INT_MAX / 2 <= bufsize)
+ return INT_MAX;
+ width = mbsnwidth (buf, bufsize, 0);
+ }
+ else
+ width = bufsize;
+
+ return width <= remaining_columns ? column + width : INT_MAX;
+}
+
+/* Set *LOC and adjust scanner cursor to account for token TOKEN of
+ size SIZE. */
+
+void
+location_compute (location *loc, boundary *cur, char const *token, size_t size)
+{
+ int line = cur->line;
+ int column = cur->column;
+ char const *p0 = token;
+ char const *p = token;
+ char const *lim = token + size;
+
+ loc->start = *cur;
+
+ for (p = token; p < lim; p++)
+ switch (*p)
+ {
+ case '\n':
+ line += line < INT_MAX;
+ column = 1;
+ p0 = p + 1;
+ break;
+
+ case '\t':
+ column = add_column_width (column, p0, p - p0);
+ column = add_column_width (column, NULL, 8 - ((column - 1) & 7));
+ p0 = p + 1;
+ break;
+
+ default:
+ break;
+ }
+
+ cur->line = line;
+ cur->column = column = add_column_width (column, p0, p - p0);
+
+ loc->end = *cur;
+
+ if (line == INT_MAX && loc->start.line != INT_MAX)
+ complain (loc, Wother, _("line number overflow"));
+ if (column == INT_MAX && loc->start.column != INT_MAX)
+ complain (loc, Wother, _("column number overflow"));
+}
+
+
+unsigned
+location_print (location loc, FILE *out)
+{
+ unsigned res = 0;
+ int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0;
+ res += fprintf (out, "%s",
+ quotearg_n_style (3, escape_quoting_style, loc.start.file));
+ if (0 <= loc.start.line)
+ {
+ res += fprintf (out, ":%d", loc.start.line);
+ if (0 <= loc.start.column)
+ res += fprintf (out, ".%d", loc.start.column);
+ }
+ if (loc.start.file != loc.end.file)
+ {
+ res += fprintf (out, "-%s",
+ quotearg_n_style (3, escape_quoting_style,
+ loc.end.file));
+ if (0 <= loc.end.line)
+ {
+ res += fprintf (out, ":%d", loc.end.line);
+ if (0 <= end_col)
+ res += fprintf (out, ".%d", end_col);
+ }
+ }
+ else if (0 <= loc.end.line)
+ {
+ if (loc.start.line < loc.end.line)
+ {
+ res += fprintf (out, "-%d", loc.end.line);
+ if (0 <= end_col)
+ res += fprintf (out, ".%d", end_col);
+ }
+ else if (0 <= end_col && loc.start.column < end_col)
+ res += fprintf (out, "-%d", end_col);
+ }
+
+ return res;
+}
+
+
+/* Persistant data used by location_caret to avoid reopening and rereading the
+ same file all over for each error. */
+struct caret_info
+{
+ FILE *source;
+ size_t line;
+ size_t offset;
+};
+
+static struct caret_info caret_info = { NULL, 1, 0 };
+
+void
+cleanup_caret ()
+{
+ if (caret_info.source)
+ fclose (caret_info.source);
+ caret_info.source = NULL;
+ caret_info.line = 1;
+ caret_info.offset = 0;
+}
+
+void
+location_caret (location loc, FILE *out)
+{
+ /* FIXME: find a way to support multifile locations, and only open once each
+ file. That would make the procedure future-proof. */
+ if (! (caret_info.source
+ || (caret_info.source = fopen (loc.start.file, "r")))
+ || loc.start.column == -1 || loc.start.line == -1)
+ return;
+
+ /* If the line we want to quote is seekable (the same line as the previous
+ location), just seek it. If it was a previous line, we lost track of it,
+ so return to the start of file. */
+ if (caret_info.line <= loc.start.line)
+ fseek (caret_info.source, caret_info.offset, SEEK_SET);
+ else
+ {
+ caret_info.line = 1;
+ caret_info.offset = 0;
+ fseek (caret_info.source, caret_info.offset, SEEK_SET);
+ }
+
+ /* Advance to the line's position, keeping track of the offset. */
+ while (caret_info.line < loc.start.line)
+ caret_info.line += getc (caret_info.source) == '\n';
+ caret_info.offset = ftell (caret_info.source);
+
+ /* Read the actual line. Don't update the offset, so that we keep a pointer
+ to the start of the line. */
+ {
+ char c = getc (caret_info.source);
+ if (c != EOF)
+ {
+ /* Quote the file, indent by a single column. */
+ putc (' ', out);
+ do
+ putc (c, out);
+ while ((c = getc (caret_info.source)) != EOF && c != '\n');
+ putc ('\n', out);
+
+ {
+ /* The caret of a multiline location ends with the first line. */
+ size_t len = loc.start.line != loc.end.line
+ ? ftell (caret_info.source) - caret_info.offset
+ : loc.end.column;
+ int i;
+
+ /* Print the carets (at least one), with the same indent as above.*/
+ fprintf (out, " %*s", loc.start.column - 1, "");
+ for (i = loc.start.column; i == loc.start.column || i < len; ++i)
+ putc ('^', out);
+ }
+ putc ('\n', out);
+ }
+ }
+}
+
+void
+boundary_set_from_string (boundary *bound, char *loc_str)
+{
+ /* Must search in reverse since the file name field may
+ * contain '.' or ':'. */
+ char *delim = strrchr (loc_str, '.');
+ aver (delim);
+ *delim = '\0';
+ bound->column = atoi (delim+1);
+ delim = strrchr (loc_str, ':');
+ aver (delim);
+ *delim = '\0';
+ bound->line = atoi (delim+1);
+ bound->file = uniqstr_new (loc_str);
+}
diff --git a/contrib/tools/bison/bison/src/location.h b/contrib/tools/bison/bison/src/location.h
index 9c6e53c190..b836f3a185 100644
--- a/contrib/tools/bison/bison/src/location.h
+++ b/contrib/tools/bison/bison/src/location.h
@@ -1,131 +1,131 @@
-/* Locations for Bison
-
- Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef LOCATION_H_
-# define LOCATION_H_
-
-# include <stdbool.h>
-# include <stdio.h>
-# include <string.h> /* strcmp */
-
-# include "uniqstr.h"
-
-/* A boundary between two characters. */
-typedef struct
-{
- /* The name of the file that contains the boundary. */
- uniqstr file;
-
- /* If nonnegative, the (origin-1) line that contains the boundary.
- If this is INT_MAX, the line number has overflowed.
-
- Meaningless and not displayed if negative.
- */
- int line;
-
- /* If nonnegative, the (origin-1) column just after the boundary.
- This is neither a byte count, nor a character count; it is a
- column count. If this is INT_MAX, the column number has
- overflowed.
-
- Meaningless and not displayed if negative.
- */
- int column;
-
-} boundary;
-
-/* Set the position of \a a. */
-static inline void
-boundary_set (boundary *b, const char *f, int l, int c)
-{
- b->file = f;
- b->line = l;
- b->column = c;
-}
-
-/* Return -1, 0, 1, depending whether a is before, equal, or
- after b. */
-static inline int
-boundary_cmp (boundary a, boundary b)
-{
- int res = strcmp (a.file, b.file);
- if (!res)
- res = a.line - b.line;
- if (!res)
- res = a.column - b.column;
- return res;
-}
-
-/* Return nonzero if A and B are equal boundaries. */
-static inline bool
-equal_boundaries (boundary a, boundary b)
-{
- return (a.column == b.column
- && a.line == b.line
- && UNIQSTR_EQ (a.file, b.file));
-}
-
-/* A location, that is, a region of source code. */
-typedef struct
-{
- /* Boundary just before the location starts. */
- boundary start;
-
- /* Boundary just after the location ends. */
- boundary end;
-
-} location;
-
-# define GRAM_LTYPE location
-
-# define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
-extern location const empty_location;
-
-/* Set *LOC and adjust scanner cursor to account for token TOKEN of
- size SIZE. */
-void location_compute (location *loc,
- boundary *cur, char const *token, size_t size);
-
-/* Print location to file.
- Return number of actually printed characters.
- Warning: uses quotearg's slot 3. */
-unsigned location_print (location loc, FILE *out);
-
-/* Free any allocated ressources and close any open file handles that are
- left-over by the usage of location_caret. */
-void cleanup_caret (void);
-
-/* Output to OUT the line and caret corresponding to location LOC. */
-void location_caret (location loc, FILE *out);
-
-/* Return -1, 0, 1, depending whether a is before, equal, or
- after b. */
-static inline int
-location_cmp (location a, location b)
-{
- int res = boundary_cmp (a.start, b.start);
- if (!res)
- res = boundary_cmp (a.end, b.end);
- return res;
-}
-
-/* LOC_STR must be formatted as 'file:line.column', it will be modified. */
-void boundary_set_from_string (boundary *bound, char *loc_str);
-
-#endif /* ! defined LOCATION_H_ */
+/* Locations for Bison
+
+ Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LOCATION_H_
+# define LOCATION_H_
+
+# include <stdbool.h>
+# include <stdio.h>
+# include <string.h> /* strcmp */
+
+# include "uniqstr.h"
+
+/* A boundary between two characters. */
+typedef struct
+{
+ /* The name of the file that contains the boundary. */
+ uniqstr file;
+
+ /* If nonnegative, the (origin-1) line that contains the boundary.
+ If this is INT_MAX, the line number has overflowed.
+
+ Meaningless and not displayed if negative.
+ */
+ int line;
+
+ /* If nonnegative, the (origin-1) column just after the boundary.
+ This is neither a byte count, nor a character count; it is a
+ column count. If this is INT_MAX, the column number has
+ overflowed.
+
+ Meaningless and not displayed if negative.
+ */
+ int column;
+
+} boundary;
+
+/* Set the position of \a a. */
+static inline void
+boundary_set (boundary *b, const char *f, int l, int c)
+{
+ b->file = f;
+ b->line = l;
+ b->column = c;
+}
+
+/* Return -1, 0, 1, depending whether a is before, equal, or
+ after b. */
+static inline int
+boundary_cmp (boundary a, boundary b)
+{
+ int res = strcmp (a.file, b.file);
+ if (!res)
+ res = a.line - b.line;
+ if (!res)
+ res = a.column - b.column;
+ return res;
+}
+
+/* Return nonzero if A and B are equal boundaries. */
+static inline bool
+equal_boundaries (boundary a, boundary b)
+{
+ return (a.column == b.column
+ && a.line == b.line
+ && UNIQSTR_EQ (a.file, b.file));
+}
+
+/* A location, that is, a region of source code. */
+typedef struct
+{
+ /* Boundary just before the location starts. */
+ boundary start;
+
+ /* Boundary just after the location ends. */
+ boundary end;
+
+} location;
+
+# define GRAM_LTYPE location
+
+# define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}}
+extern location const empty_location;
+
+/* Set *LOC and adjust scanner cursor to account for token TOKEN of
+ size SIZE. */
+void location_compute (location *loc,
+ boundary *cur, char const *token, size_t size);
+
+/* Print location to file.
+ Return number of actually printed characters.
+ Warning: uses quotearg's slot 3. */
+unsigned location_print (location loc, FILE *out);
+
+/* Free any allocated ressources and close any open file handles that are
+ left-over by the usage of location_caret. */
+void cleanup_caret (void);
+
+/* Output to OUT the line and caret corresponding to location LOC. */
+void location_caret (location loc, FILE *out);
+
+/* Return -1, 0, 1, depending whether a is before, equal, or
+ after b. */
+static inline int
+location_cmp (location a, location b)
+{
+ int res = boundary_cmp (a.start, b.start);
+ if (!res)
+ res = boundary_cmp (a.end, b.end);
+ return res;
+}
+
+/* LOC_STR must be formatted as 'file:line.column', it will be modified. */
+void boundary_set_from_string (boundary *bound, char *loc_str);
+
+#endif /* ! defined LOCATION_H_ */
diff --git a/contrib/tools/bison/bison/src/main.c b/contrib/tools/bison/bison/src/main.c
index f391a9417e..5c28da9c9a 100644
--- a/contrib/tools/bison/bison/src/main.c
+++ b/contrib/tools/bison/bison/src/main.c
@@ -1,226 +1,226 @@
-/* Top level entry point of Bison.
-
- Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000-2002, 2004-2013 Free
- Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitset_stats.h>
-#include <bitset.h>
-#include <configmake.h>
-#include <progname.h>
-#include <quotearg.h>
-#include <timevar.h>
-
-#include "LR0.h"
-#include "closeout.h"
-#include "complain.h"
-#include "conflicts.h"
-#include "derives.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "lalr.h"
-#include "ielr.h"
-#include "muscle-tab.h"
-#include "nullable.h"
-#include "output.h"
-#include "print.h"
-#include "print_graph.h"
-#include "print-xml.h"
-#include <quote.h>
-#include "reader.h"
-#include "reduce.h"
-#include "scan-code.h"
-#include "scan-gram.h"
-#include "scan-skel.h"
-#include "symtab.h"
-#include "tables.h"
-#include "uniqstr.h"
-
-
-int
-main (int argc, char *argv[])
-{
- set_program_name (argv[0]);
- setlocale (LC_ALL, "");
-#if 0
- (void) bindtextdomain (PACKAGE, LOCALEDIR);
- (void) bindtextdomain ("bison-runtime", LOCALEDIR);
- (void) textdomain (PACKAGE);
-#endif
-
- {
- char const *cp = getenv ("LC_CTYPE");
- if (cp && STREQ (cp, "C"))
- set_custom_quoting (&quote_quoting_options, "'", "'");
- else
- set_quoting_style (&quote_quoting_options, locale_quoting_style);
- }
-
- atexit (close_stdout);
-
- uniqstrs_new ();
- muscle_init ();
- complain_init ();
-
- getargs (argc, argv);
-
- timevar_report = trace_flag & trace_time;
- init_timevar ();
- timevar_start (TV_TOTAL);
-
- if (trace_flag & trace_bitsets)
- bitset_stats_enable ();
-
- /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE
- and FATTRS. In file reader.c. The other parts are recorded in
- the grammar; see gram.h. */
-
- timevar_push (TV_READER);
- reader ();
- timevar_pop (TV_READER);
-
- if (complaint_status == status_complaint)
- goto finish;
-
- /* Find useless nonterminals and productions and reduce the grammar. */
- timevar_push (TV_REDUCE);
- reduce_grammar ();
- timevar_pop (TV_REDUCE);
-
- /* Record other info about the grammar. In files derives and
- nullable. */
- timevar_push (TV_SETS);
- derives_compute ();
- nullable_compute ();
- timevar_pop (TV_SETS);
-
- /* Compute LR(0) parser states. See state.h for more info. */
- timevar_push (TV_LR0);
- generate_states ();
- timevar_pop (TV_LR0);
-
- /* Add lookahead sets to parser states. Except when LALR(1) is
- requested, split states to eliminate LR(1)-relative
- inadequacies. */
- ielr ();
-
- /* Find and record any conflicts: places where one token of
- lookahead is not enough to disambiguate the parsing. In file
- conflicts. Also resolve s/r conflicts based on precedence
- declarations. */
- timevar_push (TV_CONFLICTS);
- conflicts_solve ();
- if (!muscle_percent_define_flag_if ("lr.keep-unreachable-state"))
- {
- state_number *old_to_new = xnmalloc (nstates, sizeof *old_to_new);
- state_number nstates_old = nstates;
- state_remove_unreachable_states (old_to_new);
- lalr_update_state_numbers (old_to_new, nstates_old);
- conflicts_update_state_numbers (old_to_new, nstates_old);
- free (old_to_new);
- }
- conflicts_print ();
- timevar_pop (TV_CONFLICTS);
-
- /* Compute the parser tables. */
- timevar_push (TV_ACTIONS);
- tables_generate ();
- timevar_pop (TV_ACTIONS);
-
- grammar_rules_useless_report (_("rule useless in parser due to conflicts"));
-
- print_precedence_warnings ();
-
- /* Output file names. */
- compute_output_file_names ();
-
- /* Output the detailed report on the grammar. */
- if (report_flag)
- {
- timevar_push (TV_REPORT);
- print_results ();
- timevar_pop (TV_REPORT);
- }
-
- /* Output the graph. */
- if (graph_flag)
- {
- timevar_push (TV_GRAPH);
- print_graph ();
- timevar_pop (TV_GRAPH);
- }
-
- /* Output xml. */
- if (xml_flag)
- {
- timevar_push (TV_XML);
- print_xml ();
- timevar_pop (TV_XML);
- }
-
- /* Stop if there were errors, to avoid trashing previous output
- files. */
- if (complaint_status == status_complaint)
- goto finish;
-
- /* Lookahead tokens are no longer needed. */
- timevar_push (TV_FREE);
- lalr_free ();
- timevar_pop (TV_FREE);
-
- /* Output the tables and the parser to ftable. In file output. */
- timevar_push (TV_PARSER);
- output ();
- timevar_pop (TV_PARSER);
-
- timevar_push (TV_FREE);
- nullable_free ();
- derives_free ();
- tables_free ();
- states_free ();
- reduce_free ();
- conflicts_free ();
- grammar_free ();
- output_file_names_free ();
-
- /* The scanner memory cannot be released right after parsing, as it
- contains things such as user actions, prologue, epilogue etc. */
- gram_scanner_free ();
- muscle_free ();
- uniqstrs_free ();
- code_scanner_free ();
- skel_scanner_free ();
- quotearg_free ();
- timevar_pop (TV_FREE);
-
- if (trace_flag & trace_bitsets)
- bitset_stats_dump (stderr);
-
- finish:
-
- /* Stop timing and print the times. */
- timevar_stop (TV_TOTAL);
- timevar_print (stderr);
-
- cleanup_caret ();
-
- return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS;
-}
+/* Top level entry point of Bison.
+
+ Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000-2002, 2004-2013 Free
+ Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitset_stats.h>
+#include <bitset.h>
+#include <configmake.h>
+#include <progname.h>
+#include <quotearg.h>
+#include <timevar.h>
+
+#include "LR0.h"
+#include "closeout.h"
+#include "complain.h"
+#include "conflicts.h"
+#include "derives.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "lalr.h"
+#include "ielr.h"
+#include "muscle-tab.h"
+#include "nullable.h"
+#include "output.h"
+#include "print.h"
+#include "print_graph.h"
+#include "print-xml.h"
+#include <quote.h>
+#include "reader.h"
+#include "reduce.h"
+#include "scan-code.h"
+#include "scan-gram.h"
+#include "scan-skel.h"
+#include "symtab.h"
+#include "tables.h"
+#include "uniqstr.h"
+
+
+int
+main (int argc, char *argv[])
+{
+ set_program_name (argv[0]);
+ setlocale (LC_ALL, "");
+#if 0
+ (void) bindtextdomain (PACKAGE, LOCALEDIR);
+ (void) bindtextdomain ("bison-runtime", LOCALEDIR);
+ (void) textdomain (PACKAGE);
+#endif
+
+ {
+ char const *cp = getenv ("LC_CTYPE");
+ if (cp && STREQ (cp, "C"))
+ set_custom_quoting (&quote_quoting_options, "'", "'");
+ else
+ set_quoting_style (&quote_quoting_options, locale_quoting_style);
+ }
+
+ atexit (close_stdout);
+
+ uniqstrs_new ();
+ muscle_init ();
+ complain_init ();
+
+ getargs (argc, argv);
+
+ timevar_report = trace_flag & trace_time;
+ init_timevar ();
+ timevar_start (TV_TOTAL);
+
+ if (trace_flag & trace_bitsets)
+ bitset_stats_enable ();
+
+ /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE
+ and FATTRS. In file reader.c. The other parts are recorded in
+ the grammar; see gram.h. */
+
+ timevar_push (TV_READER);
+ reader ();
+ timevar_pop (TV_READER);
+
+ if (complaint_status == status_complaint)
+ goto finish;
+
+ /* Find useless nonterminals and productions and reduce the grammar. */
+ timevar_push (TV_REDUCE);
+ reduce_grammar ();
+ timevar_pop (TV_REDUCE);
+
+ /* Record other info about the grammar. In files derives and
+ nullable. */
+ timevar_push (TV_SETS);
+ derives_compute ();
+ nullable_compute ();
+ timevar_pop (TV_SETS);
+
+ /* Compute LR(0) parser states. See state.h for more info. */
+ timevar_push (TV_LR0);
+ generate_states ();
+ timevar_pop (TV_LR0);
+
+ /* Add lookahead sets to parser states. Except when LALR(1) is
+ requested, split states to eliminate LR(1)-relative
+ inadequacies. */
+ ielr ();
+
+ /* Find and record any conflicts: places where one token of
+ lookahead is not enough to disambiguate the parsing. In file
+ conflicts. Also resolve s/r conflicts based on precedence
+ declarations. */
+ timevar_push (TV_CONFLICTS);
+ conflicts_solve ();
+ if (!muscle_percent_define_flag_if ("lr.keep-unreachable-state"))
+ {
+ state_number *old_to_new = xnmalloc (nstates, sizeof *old_to_new);
+ state_number nstates_old = nstates;
+ state_remove_unreachable_states (old_to_new);
+ lalr_update_state_numbers (old_to_new, nstates_old);
+ conflicts_update_state_numbers (old_to_new, nstates_old);
+ free (old_to_new);
+ }
+ conflicts_print ();
+ timevar_pop (TV_CONFLICTS);
+
+ /* Compute the parser tables. */
+ timevar_push (TV_ACTIONS);
+ tables_generate ();
+ timevar_pop (TV_ACTIONS);
+
+ grammar_rules_useless_report (_("rule useless in parser due to conflicts"));
+
+ print_precedence_warnings ();
+
+ /* Output file names. */
+ compute_output_file_names ();
+
+ /* Output the detailed report on the grammar. */
+ if (report_flag)
+ {
+ timevar_push (TV_REPORT);
+ print_results ();
+ timevar_pop (TV_REPORT);
+ }
+
+ /* Output the graph. */
+ if (graph_flag)
+ {
+ timevar_push (TV_GRAPH);
+ print_graph ();
+ timevar_pop (TV_GRAPH);
+ }
+
+ /* Output xml. */
+ if (xml_flag)
+ {
+ timevar_push (TV_XML);
+ print_xml ();
+ timevar_pop (TV_XML);
+ }
+
+ /* Stop if there were errors, to avoid trashing previous output
+ files. */
+ if (complaint_status == status_complaint)
+ goto finish;
+
+ /* Lookahead tokens are no longer needed. */
+ timevar_push (TV_FREE);
+ lalr_free ();
+ timevar_pop (TV_FREE);
+
+ /* Output the tables and the parser to ftable. In file output. */
+ timevar_push (TV_PARSER);
+ output ();
+ timevar_pop (TV_PARSER);
+
+ timevar_push (TV_FREE);
+ nullable_free ();
+ derives_free ();
+ tables_free ();
+ states_free ();
+ reduce_free ();
+ conflicts_free ();
+ grammar_free ();
+ output_file_names_free ();
+
+ /* The scanner memory cannot be released right after parsing, as it
+ contains things such as user actions, prologue, epilogue etc. */
+ gram_scanner_free ();
+ muscle_free ();
+ uniqstrs_free ();
+ code_scanner_free ();
+ skel_scanner_free ();
+ quotearg_free ();
+ timevar_pop (TV_FREE);
+
+ if (trace_flag & trace_bitsets)
+ bitset_stats_dump (stderr);
+
+ finish:
+
+ /* Stop timing and print the times. */
+ timevar_stop (TV_TOTAL);
+ timevar_print (stderr);
+
+ cleanup_caret ();
+
+ return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS;
+}
diff --git a/contrib/tools/bison/bison/src/muscle-tab.c b/contrib/tools/bison/bison/src/muscle-tab.c
index ca63ed21ad..6a758a9540 100644
--- a/contrib/tools/bison/bison/src/muscle-tab.c
+++ b/contrib/tools/bison/bison/src/muscle-tab.c
@@ -1,775 +1,775 @@
-/* Muscle table manager for Bison.
-
- Copyright (C) 2001-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <hash.h>
-
-#include "complain.h"
-#include "files.h"
-#include "getargs.h"
-#include "muscle-tab.h"
-#include "quote.h"
-
-muscle_kind
-muscle_kind_new (char const *k)
-{
- if (STREQ (k, "code"))
- return muscle_code;
- else if (STREQ (k, "keyword"))
- return muscle_keyword;
- else if (STREQ (k, "string"))
- return muscle_string;
- aver (0);
-}
-
-char const *
-muscle_kind_string (muscle_kind k)
-{
- switch (k)
- {
- case muscle_code: return "code";
- case muscle_keyword: return "keyword";
- case muscle_string: return "string";
- }
- aver (0);
-}
-
-
-/* A key-value pair, along with storage that can be reclaimed when
- this pair is no longer needed. */
-typedef struct
-{
- char const *key;
- char const *value;
- char *storage;
- muscle_kind kind;
-} muscle_entry;
-
-
-/* The name of muscle for the %define variable VAR (corresponding to
- FIELD, if defined). */
-static uniqstr
-muscle_name (char const *var, char const *field)
-{
- if (field)
- return uniqstr_vsprintf("percent_define_%s(%s)", field, var);
- else
- return uniqstr_vsprintf("percent_define(%s)", var);
-}
-
-/* An obstack used to create some entries. */
-struct obstack muscle_obstack;
-
-/* Initial capacity of muscles hash table. */
-#define HT_INITIAL_CAPACITY 257
-
-static struct hash_table *muscle_table = NULL;
-
-static bool
-hash_compare_muscles (void const *x, void const *y)
-{
- muscle_entry const *m1 = x;
- muscle_entry const *m2 = y;
- return STREQ (m1->key, m2->key);
-}
-
-static size_t
-hash_muscle (const void *x, size_t tablesize)
-{
- muscle_entry const *m = x;
- return hash_string (m->key, tablesize);
-}
-
-/* Create a fresh muscle name KEY, and insert in the hash table. */
-static void *
-muscle_entry_new (char const *key)
-{
- muscle_entry *res = xmalloc (sizeof *res);
- res->key = key;
- res->value = NULL;
- res->storage = NULL;
- if (!hash_insert (muscle_table, res))
- xalloc_die ();
- return res;
-}
-
-static void
-muscle_entry_free (void *entry)
-{
- muscle_entry *mentry = entry;
- free (mentry->storage);
- free (mentry);
-}
-
-void
-muscle_init (void)
-{
- /* Initialize the muscle obstack. */
- obstack_init (&muscle_obstack);
-
- muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
- hash_compare_muscles, muscle_entry_free);
-
- /* Version and input file. */
- MUSCLE_INSERT_STRING ("version", VERSION);
-}
-
-
-void
-muscle_free (void)
-{
- hash_free (muscle_table);
- obstack_free (&muscle_obstack, NULL);
-}
-
-/* Look for the muscle named KEY. Return NULL if does not exist. */
-static
-muscle_entry *
-muscle_lookup (char const *key)
-{
- muscle_entry probe;
- probe.key = key;
- return hash_lookup (muscle_table, &probe);
-}
-
-
-void
-muscle_insert (char const *key, char const *value)
-{
- muscle_entry *entry = muscle_lookup (key);
- if (entry)
- free (entry->storage);
- else
- /* First insertion in the hash. */
- entry = muscle_entry_new (key);
- entry->value = value;
- entry->storage = NULL;
-}
-
-
-/* Append VALUE to the current value of KEY. If KEY did not already
- exist, create it. Use MUSCLE_OBSTACK. De-allocate the previously
- associated value. Copy VALUE and SEPARATOR. If VALUE does not end
- with TERMINATOR, append one. */
-
-static void
-muscle_grow (const char *key, const char *val,
- const char *separator, const char *terminator)
-{
- muscle_entry *entry = muscle_lookup (key);
- size_t vals = strlen (val);
- size_t terms = strlen (terminator);
-
- if (entry)
- {
- obstack_sgrow (&muscle_obstack, entry->value);
- obstack_sgrow (&muscle_obstack, separator);
- free (entry->storage);
- }
- else
- entry = muscle_entry_new (key);
-
- obstack_sgrow (&muscle_obstack, val);
-
- if (terms <= vals
- && STRNEQ (val + vals - terms, terminator))
- obstack_sgrow (&muscle_obstack, terminator);
-
- {
- char *new_val = obstack_finish0 (&muscle_obstack);
- entry->value = entry->storage = xstrdup (new_val);
- obstack_free (&muscle_obstack, new_val);
- }
-}
-
-/*------------------------------------------------------------------.
-| Using muscle_grow, append a synchronization line for the location |
-| LOC to the current value of KEY. |
-`------------------------------------------------------------------*/
-
-static void
-muscle_syncline_grow (char const *key, location loc)
-{
- char *extension = NULL;
- obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
- obstack_quote (&muscle_obstack,
- quotearg_style (c_quoting_style, loc.start.file));
- obstack_sgrow (&muscle_obstack, ")[");
- extension = obstack_finish0 (&muscle_obstack);
- muscle_grow (key, extension, "", "");
- obstack_free (&muscle_obstack, extension);
-}
-
-/*------------------------------------------------------------------.
-| Append VALUE to the current value of KEY, using muscle_grow. But |
-| in addition, issue a synchronization line for the location LOC |
-| using muscle_syncline_grow. |
-`------------------------------------------------------------------*/
-
-void
-muscle_code_grow (const char *key, const char *val, location loc)
-{
- muscle_syncline_grow (key, loc);
- muscle_grow (key, val, "\n", "\n");
-}
-
-
-void
-muscle_pair_list_grow (const char *muscle,
- const char *a1, const char *a2)
-{
- char *pair;
- obstack_sgrow (&muscle_obstack, "[");
- obstack_quote (&muscle_obstack, a1);
- obstack_sgrow (&muscle_obstack, ", ");
- obstack_quote (&muscle_obstack, a2);
- obstack_sgrow (&muscle_obstack, "]");
- pair = obstack_finish0 (&muscle_obstack);
- muscle_grow (muscle, pair, ",\n", "");
- obstack_free (&muscle_obstack, pair);
-}
-
-
-char const *
-muscle_find_const (char const *key)
-{
- muscle_entry *entry = muscle_lookup (key);
- return entry ? entry->value : NULL;
-}
-
-
-char *
-muscle_find (char const *key)
-{
- muscle_entry *entry = muscle_lookup (key);
- if (entry)
- {
- aver (entry->value == entry->storage);
- return entry->storage;
- }
- return NULL;
-}
-
-
-/* In the format 'file_name:line.column', append BOUND to MUSCLE. Use
- digraphs for special characters in the file name. */
-
-static void
-muscle_boundary_grow (char const *key, boundary bound)
-{
- char *extension;
- obstack_sgrow (&muscle_obstack, "[[");
- obstack_escape (&muscle_obstack, bound.file);
- obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
- extension = obstack_finish0 (&muscle_obstack);
- muscle_grow (key, extension, "", "");
- obstack_free (&muscle_obstack, extension);
-}
-
-
-/* In the format '[[file_name:line.column]], [[file_name:line.column]]',
- append LOC to MUSCLE. Use digraphs for special characters in each
- file name. */
-
-static void
-muscle_location_grow (char const *key, location loc)
-{
- muscle_boundary_grow (key, loc.start);
- muscle_grow (key, "", ", ", "");
- muscle_boundary_grow (key, loc.end);
-}
-
-#define COMMON_DECODE(Value) \
- case '$': \
- aver (*++(Value) == ']'); \
- aver (*++(Value) == '['); \
- obstack_sgrow (&muscle_obstack, "$"); \
- break; \
- case '@': \
- switch (*++(Value)) \
- { \
- case '@': obstack_sgrow (&muscle_obstack, "@" ); break; \
- case '{': obstack_sgrow (&muscle_obstack, "[" ); break; \
- case '}': obstack_sgrow (&muscle_obstack, "]" ); break; \
- default: aver (false); break; \
- } \
- break; \
- default: \
- obstack_1grow (&muscle_obstack, *(Value)); \
- break;
-
-/* Reverse of obstack_escape. */
-static char *
-string_decode (char const *key)
-{
- char const *value = muscle_find_const (key);
- char *value_decoded;
- char *result;
-
- if (!value)
- return NULL;
- do {
- switch (*value)
- {
- COMMON_DECODE (value)
- case '[':
- case ']':
- aver (false);
- break;
- }
- } while (*value++);
- value_decoded = obstack_finish (&muscle_obstack);
- result = xstrdup (value_decoded);
- obstack_free (&muscle_obstack, value_decoded);
- return result;
-}
-
-/* Reverse of muscle_location_grow. */
-static location
-location_decode (char const *value)
-{
- location loc;
- aver (value);
- aver (*value == '[');
- aver (*++value == '[');
- while (*++value)
- switch (*value)
- {
- COMMON_DECODE (value)
- case '[':
- aver (false);
- break;
- case ']':
- {
- char *boundary_str;
- aver (*++value == ']');
- boundary_str = obstack_finish0 (&muscle_obstack);
- switch (*++value)
- {
- case ',':
- boundary_set_from_string (&loc.start, boundary_str);
- obstack_free (&muscle_obstack, boundary_str);
- aver (*++value == ' ');
- aver (*++value == '[');
- aver (*++value == '[');
- break;
- case '\0':
- boundary_set_from_string (&loc.end, boundary_str);
- obstack_free (&muscle_obstack, boundary_str);
- return loc;
- break;
- default:
- aver (false);
- break;
- }
- }
- break;
- }
- aver (false);
- return loc;
-}
-
-void
-muscle_user_name_list_grow (char const *key, char const *user_name,
- location loc)
-{
- muscle_grow (key, "[[[[", ",", "");
- muscle_grow (key, user_name, "", "");
- muscle_grow (key, "]], ", "", "");
- muscle_location_grow (key, loc);
- muscle_grow (key, "]]", "", "");
-}
-
-
-/** Return an allocated string that represents the %define directive
- that performs the assignment.
-
- @param assignment "VAR", or "VAR=VAL".
- @param value default value if VAL \a assignment has no '='.
-
- For instance:
- "foo", NULL => "%define foo"
- "foo", "baz" => "%define foo baz"
- "foo=bar", NULL => "%define foo bar"
- "foo=bar", "baz" => "%define foo bar"
- "foo=", NULL => "%define foo"
- "foo=", "baz" => "%define foo"
- */
-
-static
-char *
-define_directive (char const *assignment, char const *value)
-{
- char *eq = strchr (assignment, '=');
- char const *fmt = !eq && value && *value ? "%%define %s %s" : "%%define %s";
- char *res = xmalloc (strlen (fmt) + strlen (assignment)
- + (value ? strlen (value) : 0));
- sprintf (res, fmt, assignment, value);
- eq = strchr (res, '=');
- if (eq)
- *eq = eq[1] ? ' ' : '\0';
- return res;
-}
-
-/** If the \a variable name is obsolete, return the name to use,
- * otherwise \a variable. If the \a value is obsolete, update it too.
- *
- * Allocates the returned value. */
-static
-char *
-muscle_percent_variable_update (char const *variable, location variable_loc,
- char const **value)
-{
- typedef struct
- {
- const char *obsolete;
- const char *updated;
- } conversion_type;
- const conversion_type conversion[] =
- {
- { "api.push_pull", "api.push-pull", },
- { "api.tokens.prefix", "api.token.prefix", },
- { "lex_symbol", "api.token.constructor", },
- { "location_type", "api.location.type", },
- { "lr.default-reductions", "lr.default-reduction", },
- { "lr.keep-unreachable-states", "lr.keep-unreachable-state", },
- { "lr.keep_unreachable_states", "lr.keep-unreachable-state", },
- { "namespace", "api.namespace", },
- { "stype", "api.value.type", },
- { "variant=", "api.value.type=variant", },
- { "variant=true", "api.value.type=variant", },
- { NULL, NULL, }
- };
- conversion_type const *c;
- char* res;
- char* eq2;
- for (c = conversion; c->obsolete; ++c)
- {
- char const *eq = strchr (c->obsolete, '=');
- if (eq
- ? (!strncmp (c->obsolete, variable, eq - c->obsolete)
- && STREQ (eq + 1, *value))
- : STREQ (c->obsolete, variable))
- {
- char *old = define_directive (c->obsolete, *value);
- char *upd = define_directive (c->updated, *value);
- deprecated_directive (&variable_loc, old, upd);
- free (old);
- free (upd);
- res = xstrdup (c->updated);
- {
- eq2 = strchr (res, '=');
- if (eq2)
- {
- *eq2 = '\0';
- *value = eq2 + 1;
- }
- }
- return res;
- }
- }
- return xstrdup (variable);
-}
-
-void
-muscle_percent_define_insert (char const *var, location variable_loc,
- muscle_kind kind,
- char const *value,
- muscle_percent_define_how how)
-{
- /* Backward compatibility. */
- char *variable = muscle_percent_variable_update (var, variable_loc, &value);
- uniqstr name = muscle_name (variable, NULL);
- uniqstr loc_name = muscle_name (variable, "loc");
- uniqstr syncline_name = muscle_name (variable, "syncline");
- uniqstr how_name = muscle_name (variable, "how");
- uniqstr kind_name = muscle_name (variable, "kind");
- location loc;
-
- /* Command-line options are processed before the grammar file. */
- if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE
- && muscle_find_const (name))
- {
- muscle_percent_define_how how_old = atoi (muscle_find_const (how_name));
- unsigned i = 0;
- if (how_old == MUSCLE_PERCENT_DEFINE_F)
- goto end;
- complain_indent (&variable_loc, complaint, &i,
- _("%%define variable %s redefined"),
- quote (variable));
- i += SUB_INDENT;
- loc = muscle_percent_define_get_loc (variable);
- complain_indent (&loc, complaint, &i, _("previous definition"));
- }
-
- MUSCLE_INSERT_STRING (name, value);
- muscle_insert (loc_name, "");
- muscle_location_grow (loc_name, variable_loc);
- muscle_insert (syncline_name, "");
- muscle_syncline_grow (syncline_name, variable_loc);
- muscle_user_name_list_grow ("percent_define_user_variables", variable,
- variable_loc);
- MUSCLE_INSERT_INT (how_name, how);
- MUSCLE_INSERT_STRING (kind_name, muscle_kind_string (kind));
- end:
- free (variable);
-}
-
-/* This is used for backward compatibility, e.g., "%define api.pure"
- supersedes "%pure-parser". */
-void
-muscle_percent_define_ensure (char const *variable, location loc,
- bool value)
-{
- uniqstr name = muscle_name (variable, NULL);
- char const *val = value ? "" : "false";
-
- /* Don't complain is VARIABLE is already defined, but be sure to set
- its value to VAL. */
- if (!muscle_find_const (name)
- || muscle_percent_define_flag_if (variable) != value)
- muscle_percent_define_insert (variable, loc, muscle_keyword, val,
- MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
-}
-
-/* Mark %define VARIABLE as used. */
-static void
-muscle_percent_define_use (char const *variable)
-{
- muscle_insert (muscle_name (variable, "bison_variables"), "");
-}
-
-/* The value of %define variable VARIABLE (corresponding to FIELD, if
- defined). Do not register as used, but diagnose unset variables. */
-
-static
-char const *
-muscle_percent_define_get_raw (char const *variable, char const *field)
-{
- uniqstr name = muscle_name (variable, field);
- char const *res = muscle_find_const (name);
- if (!res)
- complain (NULL, fatal, _("%s: undefined %%define variable %s"),
- "muscle_percent_define_get_raw", quote (variable));
- return res;
-}
-
-char *
-muscle_percent_define_get (char const *variable)
-{
- uniqstr name = muscle_name (variable, NULL);
- char *value = string_decode (name);
- if (!value)
- value = xstrdup ("");
- muscle_percent_define_use (variable);
- return value;
-}
-
-/* The kind of VARIABLE. An error if undefined. */
-static muscle_kind
-muscle_percent_define_get_kind (char const *variable)
-{
- return muscle_kind_new (muscle_percent_define_get_raw (variable, "kind"));
-}
-
-/* Check the kind of VARIABLE. An error if undefined. */
-static void
-muscle_percent_define_check_kind (char const *variable, muscle_kind kind)
-{
- if (muscle_percent_define_get_kind (variable) != kind)
- {
- location loc = muscle_percent_define_get_loc (variable);
- switch (kind)
- {
- case muscle_code:
- complain (&loc, Wdeprecated,
- "%%define variable '%s' requires '{...}' values",
- variable);
- break;
- case muscle_keyword:
- complain (&loc, Wdeprecated,
- "%%define variable '%s' requires keyword values",
- variable);
- break;
- case muscle_string:
- complain (&loc, Wdeprecated,
- "%%define variable '%s' requires '\"...\"' values",
- variable);
- break;
- }
- }
-}
-
-
-location
-muscle_percent_define_get_loc (char const *variable)
-{
- return location_decode (muscle_percent_define_get_raw (variable, "loc"));
-}
-
-char const *
-muscle_percent_define_get_syncline (char const *variable)
-{
- return muscle_percent_define_get_raw (variable, "syncline");
-}
-
-bool
-muscle_percent_define_ifdef (char const *variable)
-{
- if (muscle_find_const (muscle_name (variable, NULL)))
- {
- muscle_percent_define_use (variable);
- return true;
- }
- else
- return false;
-}
-
-bool
-muscle_percent_define_flag_if (char const *variable)
-{
- uniqstr invalid_boolean_name = muscle_name (variable, "invalid_boolean");
- bool result = false;
- location loc;
-
- if (muscle_percent_define_ifdef (variable))
- {
- char *value = muscle_percent_define_get (variable);
- muscle_percent_define_check_kind (variable, muscle_keyword);
- if (value[0] == '\0' || STREQ (value, "true"))
- result = true;
- else if (STREQ (value, "false"))
- result = false;
- else if (!muscle_find_const (invalid_boolean_name))
- {
- muscle_insert (invalid_boolean_name, "");
- loc = muscle_percent_define_get_loc (variable);
- complain (&loc, complaint,
- _("invalid value for %%define Boolean variable %s"),
- quote (variable));
- }
- free (value);
- }
- else
- complain (NULL, fatal, _("%s: undefined %%define variable %s"),
- "muscle_percent_define_flag", quote (variable));
-
- return result;
-}
-
-void
-muscle_percent_define_default (char const *variable, char const *value)
-{
- uniqstr name = muscle_name (variable, NULL);
- if (!muscle_find_const (name))
- {
- MUSCLE_INSERT_STRING (name, value);
- MUSCLE_INSERT_STRING (muscle_name (variable, "kind"), "keyword");
- {
- uniqstr loc_name = muscle_name (variable, "loc");
- location loc;
- loc.start.file = loc.end.file = "<default value>";
- loc.start.line = loc.end.line = -1;
- loc.start.column = loc.end.column = -1;
- muscle_insert (loc_name, "");
- muscle_location_grow (loc_name, loc);
- }
- muscle_insert (muscle_name (variable, "syncline"), "");
- }
-}
-
-void
-muscle_percent_define_check_values (char const * const *values)
-{
- for (; *values; ++values)
- {
- char const * const *variablep = values;
- uniqstr name = muscle_name (*variablep, NULL);
- char *value = string_decode (name);
- muscle_percent_define_check_kind (*variablep, muscle_keyword);
- if (value)
- {
- for (++values; *values; ++values)
- {
- if (STREQ (value, *values))
- break;
- }
- if (!*values)
- {
- unsigned i = 0;
- location loc = muscle_percent_define_get_loc (*variablep);
- complain_indent (&loc, complaint, &i,
- _("invalid value for %%define variable %s: %s"),
- quote (*variablep), quote_n (1, value));
- i += SUB_INDENT;
- for (values = variablep + 1; *values; ++values)
- complain_indent (&loc, complaint | no_caret | silent, &i,
- _("accepted value: %s"), quote (*values));
- }
- else
- {
- while (*values)
- ++values;
- }
- free (value);
- }
- else
- complain (NULL, fatal, _("%s: undefined %%define variable %s"),
- "muscle_percent_define_check_values", quote (*variablep));
- }
-}
-
-void
-muscle_percent_code_grow (char const *qualifier, location qualifier_loc,
- char const *code, location code_loc)
-{
- char const *name = uniqstr_vsprintf("percent_code(%s)", qualifier);
- muscle_code_grow (name, code, code_loc);
- muscle_user_name_list_grow ("percent_code_user_qualifiers", qualifier,
- qualifier_loc);
-}
-
-
-/*------------------------------------------------.
-| Output the definition of ENTRY as a m4_define. |
-`------------------------------------------------*/
-
-static inline bool
-muscle_m4_output (muscle_entry *entry, FILE *out)
-{
- fprintf (out,
- "m4_define([b4_%s],\n"
- "[[%s]])\n\n\n", entry->key, entry->value);
- return true;
-}
-
-static bool
-muscle_m4_output_processor (void *entry, void *out)
-{
- return muscle_m4_output (entry, out);
-}
-
-
-void
-muscles_m4_output (FILE *out)
-{
- hash_do_for_each (muscle_table, muscle_m4_output_processor, out);
-}
+/* Muscle table manager for Bison.
+
+ Copyright (C) 2001-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <hash.h>
+
+#include "complain.h"
+#include "files.h"
+#include "getargs.h"
+#include "muscle-tab.h"
+#include "quote.h"
+
+muscle_kind
+muscle_kind_new (char const *k)
+{
+ if (STREQ (k, "code"))
+ return muscle_code;
+ else if (STREQ (k, "keyword"))
+ return muscle_keyword;
+ else if (STREQ (k, "string"))
+ return muscle_string;
+ aver (0);
+}
+
+char const *
+muscle_kind_string (muscle_kind k)
+{
+ switch (k)
+ {
+ case muscle_code: return "code";
+ case muscle_keyword: return "keyword";
+ case muscle_string: return "string";
+ }
+ aver (0);
+}
+
+
+/* A key-value pair, along with storage that can be reclaimed when
+ this pair is no longer needed. */
+typedef struct
+{
+ char const *key;
+ char const *value;
+ char *storage;
+ muscle_kind kind;
+} muscle_entry;
+
+
+/* The name of muscle for the %define variable VAR (corresponding to
+ FIELD, if defined). */
+static uniqstr
+muscle_name (char const *var, char const *field)
+{
+ if (field)
+ return uniqstr_vsprintf("percent_define_%s(%s)", field, var);
+ else
+ return uniqstr_vsprintf("percent_define(%s)", var);
+}
+
+/* An obstack used to create some entries. */
+struct obstack muscle_obstack;
+
+/* Initial capacity of muscles hash table. */
+#define HT_INITIAL_CAPACITY 257
+
+static struct hash_table *muscle_table = NULL;
+
+static bool
+hash_compare_muscles (void const *x, void const *y)
+{
+ muscle_entry const *m1 = x;
+ muscle_entry const *m2 = y;
+ return STREQ (m1->key, m2->key);
+}
+
+static size_t
+hash_muscle (const void *x, size_t tablesize)
+{
+ muscle_entry const *m = x;
+ return hash_string (m->key, tablesize);
+}
+
+/* Create a fresh muscle name KEY, and insert in the hash table. */
+static void *
+muscle_entry_new (char const *key)
+{
+ muscle_entry *res = xmalloc (sizeof *res);
+ res->key = key;
+ res->value = NULL;
+ res->storage = NULL;
+ if (!hash_insert (muscle_table, res))
+ xalloc_die ();
+ return res;
+}
+
+static void
+muscle_entry_free (void *entry)
+{
+ muscle_entry *mentry = entry;
+ free (mentry->storage);
+ free (mentry);
+}
+
+void
+muscle_init (void)
+{
+ /* Initialize the muscle obstack. */
+ obstack_init (&muscle_obstack);
+
+ muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle,
+ hash_compare_muscles, muscle_entry_free);
+
+ /* Version and input file. */
+ MUSCLE_INSERT_STRING ("version", VERSION);
+}
+
+
+void
+muscle_free (void)
+{
+ hash_free (muscle_table);
+ obstack_free (&muscle_obstack, NULL);
+}
+
+/* Look for the muscle named KEY. Return NULL if does not exist. */
+static
+muscle_entry *
+muscle_lookup (char const *key)
+{
+ muscle_entry probe;
+ probe.key = key;
+ return hash_lookup (muscle_table, &probe);
+}
+
+
+void
+muscle_insert (char const *key, char const *value)
+{
+ muscle_entry *entry = muscle_lookup (key);
+ if (entry)
+ free (entry->storage);
+ else
+ /* First insertion in the hash. */
+ entry = muscle_entry_new (key);
+ entry->value = value;
+ entry->storage = NULL;
+}
+
+
+/* Append VALUE to the current value of KEY. If KEY did not already
+ exist, create it. Use MUSCLE_OBSTACK. De-allocate the previously
+ associated value. Copy VALUE and SEPARATOR. If VALUE does not end
+ with TERMINATOR, append one. */
+
+static void
+muscle_grow (const char *key, const char *val,
+ const char *separator, const char *terminator)
+{
+ muscle_entry *entry = muscle_lookup (key);
+ size_t vals = strlen (val);
+ size_t terms = strlen (terminator);
+
+ if (entry)
+ {
+ obstack_sgrow (&muscle_obstack, entry->value);
+ obstack_sgrow (&muscle_obstack, separator);
+ free (entry->storage);
+ }
+ else
+ entry = muscle_entry_new (key);
+
+ obstack_sgrow (&muscle_obstack, val);
+
+ if (terms <= vals
+ && STRNEQ (val + vals - terms, terminator))
+ obstack_sgrow (&muscle_obstack, terminator);
+
+ {
+ char *new_val = obstack_finish0 (&muscle_obstack);
+ entry->value = entry->storage = xstrdup (new_val);
+ obstack_free (&muscle_obstack, new_val);
+ }
+}
+
+/*------------------------------------------------------------------.
+| Using muscle_grow, append a synchronization line for the location |
+| LOC to the current value of KEY. |
+`------------------------------------------------------------------*/
+
+static void
+muscle_syncline_grow (char const *key, location loc)
+{
+ char *extension = NULL;
+ obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
+ obstack_quote (&muscle_obstack,
+ quotearg_style (c_quoting_style, loc.start.file));
+ obstack_sgrow (&muscle_obstack, ")[");
+ extension = obstack_finish0 (&muscle_obstack);
+ muscle_grow (key, extension, "", "");
+ obstack_free (&muscle_obstack, extension);
+}
+
+/*------------------------------------------------------------------.
+| Append VALUE to the current value of KEY, using muscle_grow. But |
+| in addition, issue a synchronization line for the location LOC |
+| using muscle_syncline_grow. |
+`------------------------------------------------------------------*/
+
+void
+muscle_code_grow (const char *key, const char *val, location loc)
+{
+ muscle_syncline_grow (key, loc);
+ muscle_grow (key, val, "\n", "\n");
+}
+
+
+void
+muscle_pair_list_grow (const char *muscle,
+ const char *a1, const char *a2)
+{
+ char *pair;
+ obstack_sgrow (&muscle_obstack, "[");
+ obstack_quote (&muscle_obstack, a1);
+ obstack_sgrow (&muscle_obstack, ", ");
+ obstack_quote (&muscle_obstack, a2);
+ obstack_sgrow (&muscle_obstack, "]");
+ pair = obstack_finish0 (&muscle_obstack);
+ muscle_grow (muscle, pair, ",\n", "");
+ obstack_free (&muscle_obstack, pair);
+}
+
+
+char const *
+muscle_find_const (char const *key)
+{
+ muscle_entry *entry = muscle_lookup (key);
+ return entry ? entry->value : NULL;
+}
+
+
+char *
+muscle_find (char const *key)
+{
+ muscle_entry *entry = muscle_lookup (key);
+ if (entry)
+ {
+ aver (entry->value == entry->storage);
+ return entry->storage;
+ }
+ return NULL;
+}
+
+
+/* In the format 'file_name:line.column', append BOUND to MUSCLE. Use
+ digraphs for special characters in the file name. */
+
+static void
+muscle_boundary_grow (char const *key, boundary bound)
+{
+ char *extension;
+ obstack_sgrow (&muscle_obstack, "[[");
+ obstack_escape (&muscle_obstack, bound.file);
+ obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column);
+ extension = obstack_finish0 (&muscle_obstack);
+ muscle_grow (key, extension, "", "");
+ obstack_free (&muscle_obstack, extension);
+}
+
+
+/* In the format '[[file_name:line.column]], [[file_name:line.column]]',
+ append LOC to MUSCLE. Use digraphs for special characters in each
+ file name. */
+
+static void
+muscle_location_grow (char const *key, location loc)
+{
+ muscle_boundary_grow (key, loc.start);
+ muscle_grow (key, "", ", ", "");
+ muscle_boundary_grow (key, loc.end);
+}
+
+#define COMMON_DECODE(Value) \
+ case '$': \
+ aver (*++(Value) == ']'); \
+ aver (*++(Value) == '['); \
+ obstack_sgrow (&muscle_obstack, "$"); \
+ break; \
+ case '@': \
+ switch (*++(Value)) \
+ { \
+ case '@': obstack_sgrow (&muscle_obstack, "@" ); break; \
+ case '{': obstack_sgrow (&muscle_obstack, "[" ); break; \
+ case '}': obstack_sgrow (&muscle_obstack, "]" ); break; \
+ default: aver (false); break; \
+ } \
+ break; \
+ default: \
+ obstack_1grow (&muscle_obstack, *(Value)); \
+ break;
+
+/* Reverse of obstack_escape. */
+static char *
+string_decode (char const *key)
+{
+ char const *value = muscle_find_const (key);
+ char *value_decoded;
+ char *result;
+
+ if (!value)
+ return NULL;
+ do {
+ switch (*value)
+ {
+ COMMON_DECODE (value)
+ case '[':
+ case ']':
+ aver (false);
+ break;
+ }
+ } while (*value++);
+ value_decoded = obstack_finish (&muscle_obstack);
+ result = xstrdup (value_decoded);
+ obstack_free (&muscle_obstack, value_decoded);
+ return result;
+}
+
+/* Reverse of muscle_location_grow. */
+static location
+location_decode (char const *value)
+{
+ location loc;
+ aver (value);
+ aver (*value == '[');
+ aver (*++value == '[');
+ while (*++value)
+ switch (*value)
+ {
+ COMMON_DECODE (value)
+ case '[':
+ aver (false);
+ break;
+ case ']':
+ {
+ char *boundary_str;
+ aver (*++value == ']');
+ boundary_str = obstack_finish0 (&muscle_obstack);
+ switch (*++value)
+ {
+ case ',':
+ boundary_set_from_string (&loc.start, boundary_str);
+ obstack_free (&muscle_obstack, boundary_str);
+ aver (*++value == ' ');
+ aver (*++value == '[');
+ aver (*++value == '[');
+ break;
+ case '\0':
+ boundary_set_from_string (&loc.end, boundary_str);
+ obstack_free (&muscle_obstack, boundary_str);
+ return loc;
+ break;
+ default:
+ aver (false);
+ break;
+ }
+ }
+ break;
+ }
+ aver (false);
+ return loc;
+}
+
+void
+muscle_user_name_list_grow (char const *key, char const *user_name,
+ location loc)
+{
+ muscle_grow (key, "[[[[", ",", "");
+ muscle_grow (key, user_name, "", "");
+ muscle_grow (key, "]], ", "", "");
+ muscle_location_grow (key, loc);
+ muscle_grow (key, "]]", "", "");
+}
+
+
+/** Return an allocated string that represents the %define directive
+ that performs the assignment.
+
+ @param assignment "VAR", or "VAR=VAL".
+ @param value default value if VAL \a assignment has no '='.
+
+ For instance:
+ "foo", NULL => "%define foo"
+ "foo", "baz" => "%define foo baz"
+ "foo=bar", NULL => "%define foo bar"
+ "foo=bar", "baz" => "%define foo bar"
+ "foo=", NULL => "%define foo"
+ "foo=", "baz" => "%define foo"
+ */
+
+static
+char *
+define_directive (char const *assignment, char const *value)
+{
+ char *eq = strchr (assignment, '=');
+ char const *fmt = !eq && value && *value ? "%%define %s %s" : "%%define %s";
+ char *res = xmalloc (strlen (fmt) + strlen (assignment)
+ + (value ? strlen (value) : 0));
+ sprintf (res, fmt, assignment, value);
+ eq = strchr (res, '=');
+ if (eq)
+ *eq = eq[1] ? ' ' : '\0';
+ return res;
+}
+
+/** If the \a variable name is obsolete, return the name to use,
+ * otherwise \a variable. If the \a value is obsolete, update it too.
+ *
+ * Allocates the returned value. */
+static
+char *
+muscle_percent_variable_update (char const *variable, location variable_loc,
+ char const **value)
+{
+ typedef struct
+ {
+ const char *obsolete;
+ const char *updated;
+ } conversion_type;
+ const conversion_type conversion[] =
+ {
+ { "api.push_pull", "api.push-pull", },
+ { "api.tokens.prefix", "api.token.prefix", },
+ { "lex_symbol", "api.token.constructor", },
+ { "location_type", "api.location.type", },
+ { "lr.default-reductions", "lr.default-reduction", },
+ { "lr.keep-unreachable-states", "lr.keep-unreachable-state", },
+ { "lr.keep_unreachable_states", "lr.keep-unreachable-state", },
+ { "namespace", "api.namespace", },
+ { "stype", "api.value.type", },
+ { "variant=", "api.value.type=variant", },
+ { "variant=true", "api.value.type=variant", },
+ { NULL, NULL, }
+ };
+ conversion_type const *c;
+ char* res;
+ char* eq2;
+ for (c = conversion; c->obsolete; ++c)
+ {
+ char const *eq = strchr (c->obsolete, '=');
+ if (eq
+ ? (!strncmp (c->obsolete, variable, eq - c->obsolete)
+ && STREQ (eq + 1, *value))
+ : STREQ (c->obsolete, variable))
+ {
+ char *old = define_directive (c->obsolete, *value);
+ char *upd = define_directive (c->updated, *value);
+ deprecated_directive (&variable_loc, old, upd);
+ free (old);
+ free (upd);
+ res = xstrdup (c->updated);
+ {
+ eq2 = strchr (res, '=');
+ if (eq2)
+ {
+ *eq2 = '\0';
+ *value = eq2 + 1;
+ }
+ }
+ return res;
+ }
+ }
+ return xstrdup (variable);
+}
+
+void
+muscle_percent_define_insert (char const *var, location variable_loc,
+ muscle_kind kind,
+ char const *value,
+ muscle_percent_define_how how)
+{
+ /* Backward compatibility. */
+ char *variable = muscle_percent_variable_update (var, variable_loc, &value);
+ uniqstr name = muscle_name (variable, NULL);
+ uniqstr loc_name = muscle_name (variable, "loc");
+ uniqstr syncline_name = muscle_name (variable, "syncline");
+ uniqstr how_name = muscle_name (variable, "how");
+ uniqstr kind_name = muscle_name (variable, "kind");
+ location loc;
+
+ /* Command-line options are processed before the grammar file. */
+ if (how == MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE
+ && muscle_find_const (name))
+ {
+ muscle_percent_define_how how_old = atoi (muscle_find_const (how_name));
+ unsigned i = 0;
+ if (how_old == MUSCLE_PERCENT_DEFINE_F)
+ goto end;
+ complain_indent (&variable_loc, complaint, &i,
+ _("%%define variable %s redefined"),
+ quote (variable));
+ i += SUB_INDENT;
+ loc = muscle_percent_define_get_loc (variable);
+ complain_indent (&loc, complaint, &i, _("previous definition"));
+ }
+
+ MUSCLE_INSERT_STRING (name, value);
+ muscle_insert (loc_name, "");
+ muscle_location_grow (loc_name, variable_loc);
+ muscle_insert (syncline_name, "");
+ muscle_syncline_grow (syncline_name, variable_loc);
+ muscle_user_name_list_grow ("percent_define_user_variables", variable,
+ variable_loc);
+ MUSCLE_INSERT_INT (how_name, how);
+ MUSCLE_INSERT_STRING (kind_name, muscle_kind_string (kind));
+ end:
+ free (variable);
+}
+
+/* This is used for backward compatibility, e.g., "%define api.pure"
+ supersedes "%pure-parser". */
+void
+muscle_percent_define_ensure (char const *variable, location loc,
+ bool value)
+{
+ uniqstr name = muscle_name (variable, NULL);
+ char const *val = value ? "" : "false";
+
+ /* Don't complain is VARIABLE is already defined, but be sure to set
+ its value to VAL. */
+ if (!muscle_find_const (name)
+ || muscle_percent_define_flag_if (variable) != value)
+ muscle_percent_define_insert (variable, loc, muscle_keyword, val,
+ MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
+}
+
+/* Mark %define VARIABLE as used. */
+static void
+muscle_percent_define_use (char const *variable)
+{
+ muscle_insert (muscle_name (variable, "bison_variables"), "");
+}
+
+/* The value of %define variable VARIABLE (corresponding to FIELD, if
+ defined). Do not register as used, but diagnose unset variables. */
+
+static
+char const *
+muscle_percent_define_get_raw (char const *variable, char const *field)
+{
+ uniqstr name = muscle_name (variable, field);
+ char const *res = muscle_find_const (name);
+ if (!res)
+ complain (NULL, fatal, _("%s: undefined %%define variable %s"),
+ "muscle_percent_define_get_raw", quote (variable));
+ return res;
+}
+
+char *
+muscle_percent_define_get (char const *variable)
+{
+ uniqstr name = muscle_name (variable, NULL);
+ char *value = string_decode (name);
+ if (!value)
+ value = xstrdup ("");
+ muscle_percent_define_use (variable);
+ return value;
+}
+
+/* The kind of VARIABLE. An error if undefined. */
+static muscle_kind
+muscle_percent_define_get_kind (char const *variable)
+{
+ return muscle_kind_new (muscle_percent_define_get_raw (variable, "kind"));
+}
+
+/* Check the kind of VARIABLE. An error if undefined. */
+static void
+muscle_percent_define_check_kind (char const *variable, muscle_kind kind)
+{
+ if (muscle_percent_define_get_kind (variable) != kind)
+ {
+ location loc = muscle_percent_define_get_loc (variable);
+ switch (kind)
+ {
+ case muscle_code:
+ complain (&loc, Wdeprecated,
+ "%%define variable '%s' requires '{...}' values",
+ variable);
+ break;
+ case muscle_keyword:
+ complain (&loc, Wdeprecated,
+ "%%define variable '%s' requires keyword values",
+ variable);
+ break;
+ case muscle_string:
+ complain (&loc, Wdeprecated,
+ "%%define variable '%s' requires '\"...\"' values",
+ variable);
+ break;
+ }
+ }
+}
+
+
+location
+muscle_percent_define_get_loc (char const *variable)
+{
+ return location_decode (muscle_percent_define_get_raw (variable, "loc"));
+}
+
+char const *
+muscle_percent_define_get_syncline (char const *variable)
+{
+ return muscle_percent_define_get_raw (variable, "syncline");
+}
+
+bool
+muscle_percent_define_ifdef (char const *variable)
+{
+ if (muscle_find_const (muscle_name (variable, NULL)))
+ {
+ muscle_percent_define_use (variable);
+ return true;
+ }
+ else
+ return false;
+}
+
+bool
+muscle_percent_define_flag_if (char const *variable)
+{
+ uniqstr invalid_boolean_name = muscle_name (variable, "invalid_boolean");
+ bool result = false;
+ location loc;
+
+ if (muscle_percent_define_ifdef (variable))
+ {
+ char *value = muscle_percent_define_get (variable);
+ muscle_percent_define_check_kind (variable, muscle_keyword);
+ if (value[0] == '\0' || STREQ (value, "true"))
+ result = true;
+ else if (STREQ (value, "false"))
+ result = false;
+ else if (!muscle_find_const (invalid_boolean_name))
+ {
+ muscle_insert (invalid_boolean_name, "");
+ loc = muscle_percent_define_get_loc (variable);
+ complain (&loc, complaint,
+ _("invalid value for %%define Boolean variable %s"),
+ quote (variable));
+ }
+ free (value);
+ }
+ else
+ complain (NULL, fatal, _("%s: undefined %%define variable %s"),
+ "muscle_percent_define_flag", quote (variable));
+
+ return result;
+}
+
+void
+muscle_percent_define_default (char const *variable, char const *value)
+{
+ uniqstr name = muscle_name (variable, NULL);
+ if (!muscle_find_const (name))
+ {
+ MUSCLE_INSERT_STRING (name, value);
+ MUSCLE_INSERT_STRING (muscle_name (variable, "kind"), "keyword");
+ {
+ uniqstr loc_name = muscle_name (variable, "loc");
+ location loc;
+ loc.start.file = loc.end.file = "<default value>";
+ loc.start.line = loc.end.line = -1;
+ loc.start.column = loc.end.column = -1;
+ muscle_insert (loc_name, "");
+ muscle_location_grow (loc_name, loc);
+ }
+ muscle_insert (muscle_name (variable, "syncline"), "");
+ }
+}
+
+void
+muscle_percent_define_check_values (char const * const *values)
+{
+ for (; *values; ++values)
+ {
+ char const * const *variablep = values;
+ uniqstr name = muscle_name (*variablep, NULL);
+ char *value = string_decode (name);
+ muscle_percent_define_check_kind (*variablep, muscle_keyword);
+ if (value)
+ {
+ for (++values; *values; ++values)
+ {
+ if (STREQ (value, *values))
+ break;
+ }
+ if (!*values)
+ {
+ unsigned i = 0;
+ location loc = muscle_percent_define_get_loc (*variablep);
+ complain_indent (&loc, complaint, &i,
+ _("invalid value for %%define variable %s: %s"),
+ quote (*variablep), quote_n (1, value));
+ i += SUB_INDENT;
+ for (values = variablep + 1; *values; ++values)
+ complain_indent (&loc, complaint | no_caret | silent, &i,
+ _("accepted value: %s"), quote (*values));
+ }
+ else
+ {
+ while (*values)
+ ++values;
+ }
+ free (value);
+ }
+ else
+ complain (NULL, fatal, _("%s: undefined %%define variable %s"),
+ "muscle_percent_define_check_values", quote (*variablep));
+ }
+}
+
+void
+muscle_percent_code_grow (char const *qualifier, location qualifier_loc,
+ char const *code, location code_loc)
+{
+ char const *name = uniqstr_vsprintf("percent_code(%s)", qualifier);
+ muscle_code_grow (name, code, code_loc);
+ muscle_user_name_list_grow ("percent_code_user_qualifiers", qualifier,
+ qualifier_loc);
+}
+
+
+/*------------------------------------------------.
+| Output the definition of ENTRY as a m4_define. |
+`------------------------------------------------*/
+
+static inline bool
+muscle_m4_output (muscle_entry *entry, FILE *out)
+{
+ fprintf (out,
+ "m4_define([b4_%s],\n"
+ "[[%s]])\n\n\n", entry->key, entry->value);
+ return true;
+}
+
+static bool
+muscle_m4_output_processor (void *entry, void *out)
+{
+ return muscle_m4_output (entry, out);
+}
+
+
+void
+muscles_m4_output (FILE *out)
+{
+ hash_do_for_each (muscle_table, muscle_m4_output_processor, out);
+}
diff --git a/contrib/tools/bison/bison/src/muscle-tab.h b/contrib/tools/bison/bison/src/muscle-tab.h
index 0993f74ed7..f6fa4cb5c5 100644
--- a/contrib/tools/bison/bison/src/muscle-tab.h
+++ b/contrib/tools/bison/bison/src/muscle-tab.h
@@ -1,217 +1,217 @@
-/* Muscle table manager for Bison,
-
- Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef MUSCLE_TAB_H_
-# define MUSCLE_TAB_H_
-
-# include <quotearg.h>
-
-# include "location.h"
-
-/* The kind of value associated to this muscle, depending on the
- syntax of the value: keyword (no delimiter, e.g., true), string
- (double quotes, e.g., "foo.h"), or code (braces, e.g., {int}). */
-typedef enum
-{
- muscle_code,
- muscle_keyword,
- muscle_string
-} muscle_kind;
-
-/* Conversion from string. */
-muscle_kind muscle_kind_new (char const *k);
-
-/* Conversion to string. */
-char const *muscle_kind_string (muscle_kind k);
-
-
-/* Create the MUSCLE_TABLE, and initialize it with default values.
- Also set up the MUSCLE_OBSTACK. */
-void muscle_init (void);
-
-/* Insert (KEY, VALUE). If KEY already existed, overwrite the
- previous value. Otherwise create as a muscle_string type. */
-void muscle_insert (char const *key, char const *value);
-
-/* Find the value of muscle KEY. Unlike MUSCLE_FIND, this is always
- reliable to determine whether KEY has a value. */
-char const *muscle_find_const (char const *key);
-
-/* Find the value of muscle KEY. Abort if muscle_insert was invoked
- more recently than muscle_grow for KEY since muscle_find can't
- return a char const *. */
-char *muscle_find (char const *key);
-
-/* Free all the memory consumed by the muscle machinery only. */
-void muscle_free (void);
-
-
-/* An obstack dedicated to receive muscle keys and values. */
-extern struct obstack muscle_obstack;
-
-# define MUSCLE_INSERT_BOOL(Key, Value) \
- do { \
- int v__ = Value; \
- MUSCLE_INSERT_INT (Key, v__); \
- } while (0)
-
-# define MUSCLE_INSERTF(Key, Format, Value) \
- do { \
- obstack_printf (&muscle_obstack, Format, Value); \
- muscle_insert (Key, obstack_finish0 (&muscle_obstack)); \
- } while (0)
-
-# define MUSCLE_INSERT_INT(Key, Value) \
- MUSCLE_INSERTF (Key, "%d", Value)
-
-# define MUSCLE_INSERT_LONG_INT(Key, Value) \
- MUSCLE_INSERTF (Key, "%ld", Value)
-
-/* Key -> Value, but don't apply escaping to Value. */
-# define MUSCLE_INSERT_STRING_RAW(Key, Value) \
- MUSCLE_INSERTF (Key, "%s", Value)
-
-/* Key -> Value, applying M4 escaping to Value. */
-# define MUSCLE_INSERT_STRING(Key, Value) \
- do { \
- obstack_escape (&muscle_obstack, Value); \
- muscle_insert (Key, obstack_finish0 (&muscle_obstack)); \
- } while (0)
-
-/* Key -> Value, applying C escaping to Value (and then M4). */
-# define MUSCLE_INSERT_C_STRING(Key, Value) \
- MUSCLE_INSERT_STRING (Key, quotearg_style (c_quoting_style, Value))
-
-
-/* Append VALUE to the current value of KEY, using muscle_grow. But
- in addition, issue a synchronization line for the location LOC.
- Be sure to append on a new line. */
-void muscle_code_grow (const char *key, const char *value, location loc);
-
-
-/* MUSCLE is an M4 list of pairs. Create or extend it with the pair
- (A1, A2) after escaping both values with digraphs. Note that because the
- muscle values are output *double* quoted, one needs to strip the first level
- of quotes to reach the list itself. */
-void muscle_pair_list_grow (const char *muscle,
- const char *a1, const char *a2);
-
-/* Grow KEY for the occurrence of the name USER_NAME at LOC appropriately for
- use with b4_check_user_names in ../data/bison.m4. USER_NAME is not escaped
- with digraphs, so it must not contain '[' or ']'. */
-void muscle_user_name_list_grow (char const *key, char const *user_name,
- location loc);
-
-/* Indicates whether a variable's value was specified with -D/--define, with
- -F/--force-define, or in the grammar file. */
-typedef enum {
- MUSCLE_PERCENT_DEFINE_D = 0,
- MUSCLE_PERCENT_DEFINE_F,
- MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE
-} muscle_percent_define_how;
-
-/* Define the muscles for %define variable VARIABLE with VALUE specified
- at VARIABLE_LOC in the manner HOW unless it was specified in the
- grammar file while the previous definition for VARIABLE was specified
- with -F/--force-define. Complain if a previous definition is being
- overridden and the new definition is specified in the grammar file.
- (These rules support the documented behavior as long as command-line
- definitions are processed before grammar file definitions.) Record
- this as a user occurrence of VARIABLE by invoking
- muscle_user_name_list_grow. */
-void muscle_percent_define_insert (char const *variable, location variable_loc,
- muscle_kind kind,
- char const *value,
- muscle_percent_define_how how);
-
-/* Make sure that VARIABLE is set to the boolean VALUE. Warn on mismatches
- only, but accept repeated declaration. Used for backward compatibility
- between old directives such as %pure-parser, and the recommended use of
- variables (%define api.pure). */
-void muscle_percent_define_ensure (char const *variable, location variable_loc,
- bool value);
-
-/* Mimic b4_percent_define_get in ../data/bison.m4 exactly. That is, if the
- %define variable VARIABLE is defined, return its value. Otherwise, return
- the empty string. Also, record Bison's usage of VARIABLE by defining
- b4_percent_define_bison_variables(VARIABLE). The caller is responsible for
- freeing the memory of the returned string. */
-char *muscle_percent_define_get (char const *variable);
-
-/* Mimic muscle_percent_define_get_loc in ../data/bison.m4 exactly. That is,
- if the %define variable VARIABLE is undefined, complain fatally since that's
- a Bison error. Otherwise, return its definition location in a form
- approriate for the first argument of warn_at, complain_at, or fatal_at.
- Don't record this as a Bison usage of VARIABLE as there's no reason to
- suspect that the user-supplied value has yet influenced the output. */
-location muscle_percent_define_get_loc (char const *variable);
-
-/* Mimic muscle_percent_define_get_syncline in ../data/bison.m4 exactly. That
- is, if the %define variable VARIABLE is undefined, complain fatally since
- that's a Bison error. Otherwise, return its definition location as a
- b4_syncline invocation. Don't record this as a Bison usage of VARIABLE as
- there's no reason to suspect that the user-supplied value has yet influenced
- the output. */
-char const *muscle_percent_define_get_syncline (char const *variable);
-
-/* Mimic b4_percent_define_ifdef in ../data/bison.m4 exactly. That is, if the
- %define variable VARIABLE is defined, return true. Otherwise, return false.
- Also, record Bison's usage of VARIABLE by defining
- b4_percent_define_bison_variables(VARIABLE). */
-bool muscle_percent_define_ifdef (char const *variable);
-
-/* Mimic b4_percent_define_flag_if in ../data/bison.m4 exactly. That is, if
- the %define variable VARIABLE is defined to "" or "true", return true. If
- it is defined to "false", return false. Complain if it is undefined (a
- Bison error since the default value should have been set already) or defined
- to any other value (possibly a user error). Also, record Bison's usage of
- VARIABLE by defining b4_percent_define_bison_variables(VARIABLE). */
-bool muscle_percent_define_flag_if (char const *variable);
-
-/* Mimic b4_percent_define_default in ../data/bison.m4 exactly. That is, if
- the %define variable VARIABLE is undefined, set its value to VALUE.
- Don't record this as a Bison usage of VARIABLE as there's no reason to
- suspect that the value has yet influenced the output. */
-void muscle_percent_define_default (char const *variable, char const *value);
-
-/* Mimic b4_percent_define_check_values in ../data/bison.m4 exactly except that
- the VALUES structure is more appropriate for C. That is, VALUES points to a
- list of strings that is partitioned into sublists by NULL's, one terminating
- each sublist. The last sublist is followed by a second NULL. For each
- sublist, the first string is the name of a %define variable, and all
- remaining strings in that sublist are the valid values for that variable.
- Complain if such a variable is undefined (a Bison error since the default
- value should have been set already) or defined to any other value (possibly
- a user error). Don't record this as a Bison usage of the variable as
- there's no reason to suspect that the value has yet influenced the
- output. */
-void muscle_percent_define_check_values (char const * const *values);
-
-/* Grow the muscle for the %code qualifier QUALIFIER appearing at
- QUALIFIER_LOC with code CODE appearing at CODE_LOC. Record this as a
- user occurrence of QUALIFIER by invoking
- muscle_user_name_list_grow. */
-void muscle_percent_code_grow (char const *qualifier, location qualifier_loc,
- char const *code, location code_loc);
-
-/* Output the definition of all the current muscles into a list of
- m4_defines. */
-void muscles_m4_output (FILE *out);
-
-#endif /* not MUSCLE_TAB_H_ */
+/* Muscle table manager for Bison,
+
+ Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef MUSCLE_TAB_H_
+# define MUSCLE_TAB_H_
+
+# include <quotearg.h>
+
+# include "location.h"
+
+/* The kind of value associated to this muscle, depending on the
+ syntax of the value: keyword (no delimiter, e.g., true), string
+ (double quotes, e.g., "foo.h"), or code (braces, e.g., {int}). */
+typedef enum
+{
+ muscle_code,
+ muscle_keyword,
+ muscle_string
+} muscle_kind;
+
+/* Conversion from string. */
+muscle_kind muscle_kind_new (char const *k);
+
+/* Conversion to string. */
+char const *muscle_kind_string (muscle_kind k);
+
+
+/* Create the MUSCLE_TABLE, and initialize it with default values.
+ Also set up the MUSCLE_OBSTACK. */
+void muscle_init (void);
+
+/* Insert (KEY, VALUE). If KEY already existed, overwrite the
+ previous value. Otherwise create as a muscle_string type. */
+void muscle_insert (char const *key, char const *value);
+
+/* Find the value of muscle KEY. Unlike MUSCLE_FIND, this is always
+ reliable to determine whether KEY has a value. */
+char const *muscle_find_const (char const *key);
+
+/* Find the value of muscle KEY. Abort if muscle_insert was invoked
+ more recently than muscle_grow for KEY since muscle_find can't
+ return a char const *. */
+char *muscle_find (char const *key);
+
+/* Free all the memory consumed by the muscle machinery only. */
+void muscle_free (void);
+
+
+/* An obstack dedicated to receive muscle keys and values. */
+extern struct obstack muscle_obstack;
+
+# define MUSCLE_INSERT_BOOL(Key, Value) \
+ do { \
+ int v__ = Value; \
+ MUSCLE_INSERT_INT (Key, v__); \
+ } while (0)
+
+# define MUSCLE_INSERTF(Key, Format, Value) \
+ do { \
+ obstack_printf (&muscle_obstack, Format, Value); \
+ muscle_insert (Key, obstack_finish0 (&muscle_obstack)); \
+ } while (0)
+
+# define MUSCLE_INSERT_INT(Key, Value) \
+ MUSCLE_INSERTF (Key, "%d", Value)
+
+# define MUSCLE_INSERT_LONG_INT(Key, Value) \
+ MUSCLE_INSERTF (Key, "%ld", Value)
+
+/* Key -> Value, but don't apply escaping to Value. */
+# define MUSCLE_INSERT_STRING_RAW(Key, Value) \
+ MUSCLE_INSERTF (Key, "%s", Value)
+
+/* Key -> Value, applying M4 escaping to Value. */
+# define MUSCLE_INSERT_STRING(Key, Value) \
+ do { \
+ obstack_escape (&muscle_obstack, Value); \
+ muscle_insert (Key, obstack_finish0 (&muscle_obstack)); \
+ } while (0)
+
+/* Key -> Value, applying C escaping to Value (and then M4). */
+# define MUSCLE_INSERT_C_STRING(Key, Value) \
+ MUSCLE_INSERT_STRING (Key, quotearg_style (c_quoting_style, Value))
+
+
+/* Append VALUE to the current value of KEY, using muscle_grow. But
+ in addition, issue a synchronization line for the location LOC.
+ Be sure to append on a new line. */
+void muscle_code_grow (const char *key, const char *value, location loc);
+
+
+/* MUSCLE is an M4 list of pairs. Create or extend it with the pair
+ (A1, A2) after escaping both values with digraphs. Note that because the
+ muscle values are output *double* quoted, one needs to strip the first level
+ of quotes to reach the list itself. */
+void muscle_pair_list_grow (const char *muscle,
+ const char *a1, const char *a2);
+
+/* Grow KEY for the occurrence of the name USER_NAME at LOC appropriately for
+ use with b4_check_user_names in ../data/bison.m4. USER_NAME is not escaped
+ with digraphs, so it must not contain '[' or ']'. */
+void muscle_user_name_list_grow (char const *key, char const *user_name,
+ location loc);
+
+/* Indicates whether a variable's value was specified with -D/--define, with
+ -F/--force-define, or in the grammar file. */
+typedef enum {
+ MUSCLE_PERCENT_DEFINE_D = 0,
+ MUSCLE_PERCENT_DEFINE_F,
+ MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE
+} muscle_percent_define_how;
+
+/* Define the muscles for %define variable VARIABLE with VALUE specified
+ at VARIABLE_LOC in the manner HOW unless it was specified in the
+ grammar file while the previous definition for VARIABLE was specified
+ with -F/--force-define. Complain if a previous definition is being
+ overridden and the new definition is specified in the grammar file.
+ (These rules support the documented behavior as long as command-line
+ definitions are processed before grammar file definitions.) Record
+ this as a user occurrence of VARIABLE by invoking
+ muscle_user_name_list_grow. */
+void muscle_percent_define_insert (char const *variable, location variable_loc,
+ muscle_kind kind,
+ char const *value,
+ muscle_percent_define_how how);
+
+/* Make sure that VARIABLE is set to the boolean VALUE. Warn on mismatches
+ only, but accept repeated declaration. Used for backward compatibility
+ between old directives such as %pure-parser, and the recommended use of
+ variables (%define api.pure). */
+void muscle_percent_define_ensure (char const *variable, location variable_loc,
+ bool value);
+
+/* Mimic b4_percent_define_get in ../data/bison.m4 exactly. That is, if the
+ %define variable VARIABLE is defined, return its value. Otherwise, return
+ the empty string. Also, record Bison's usage of VARIABLE by defining
+ b4_percent_define_bison_variables(VARIABLE). The caller is responsible for
+ freeing the memory of the returned string. */
+char *muscle_percent_define_get (char const *variable);
+
+/* Mimic muscle_percent_define_get_loc in ../data/bison.m4 exactly. That is,
+ if the %define variable VARIABLE is undefined, complain fatally since that's
+ a Bison error. Otherwise, return its definition location in a form
+ approriate for the first argument of warn_at, complain_at, or fatal_at.
+ Don't record this as a Bison usage of VARIABLE as there's no reason to
+ suspect that the user-supplied value has yet influenced the output. */
+location muscle_percent_define_get_loc (char const *variable);
+
+/* Mimic muscle_percent_define_get_syncline in ../data/bison.m4 exactly. That
+ is, if the %define variable VARIABLE is undefined, complain fatally since
+ that's a Bison error. Otherwise, return its definition location as a
+ b4_syncline invocation. Don't record this as a Bison usage of VARIABLE as
+ there's no reason to suspect that the user-supplied value has yet influenced
+ the output. */
+char const *muscle_percent_define_get_syncline (char const *variable);
+
+/* Mimic b4_percent_define_ifdef in ../data/bison.m4 exactly. That is, if the
+ %define variable VARIABLE is defined, return true. Otherwise, return false.
+ Also, record Bison's usage of VARIABLE by defining
+ b4_percent_define_bison_variables(VARIABLE). */
+bool muscle_percent_define_ifdef (char const *variable);
+
+/* Mimic b4_percent_define_flag_if in ../data/bison.m4 exactly. That is, if
+ the %define variable VARIABLE is defined to "" or "true", return true. If
+ it is defined to "false", return false. Complain if it is undefined (a
+ Bison error since the default value should have been set already) or defined
+ to any other value (possibly a user error). Also, record Bison's usage of
+ VARIABLE by defining b4_percent_define_bison_variables(VARIABLE). */
+bool muscle_percent_define_flag_if (char const *variable);
+
+/* Mimic b4_percent_define_default in ../data/bison.m4 exactly. That is, if
+ the %define variable VARIABLE is undefined, set its value to VALUE.
+ Don't record this as a Bison usage of VARIABLE as there's no reason to
+ suspect that the value has yet influenced the output. */
+void muscle_percent_define_default (char const *variable, char const *value);
+
+/* Mimic b4_percent_define_check_values in ../data/bison.m4 exactly except that
+ the VALUES structure is more appropriate for C. That is, VALUES points to a
+ list of strings that is partitioned into sublists by NULL's, one terminating
+ each sublist. The last sublist is followed by a second NULL. For each
+ sublist, the first string is the name of a %define variable, and all
+ remaining strings in that sublist are the valid values for that variable.
+ Complain if such a variable is undefined (a Bison error since the default
+ value should have been set already) or defined to any other value (possibly
+ a user error). Don't record this as a Bison usage of the variable as
+ there's no reason to suspect that the value has yet influenced the
+ output. */
+void muscle_percent_define_check_values (char const * const *values);
+
+/* Grow the muscle for the %code qualifier QUALIFIER appearing at
+ QUALIFIER_LOC with code CODE appearing at CODE_LOC. Record this as a
+ user occurrence of QUALIFIER by invoking
+ muscle_user_name_list_grow. */
+void muscle_percent_code_grow (char const *qualifier, location qualifier_loc,
+ char const *code, location code_loc);
+
+/* Output the definition of all the current muscles into a list of
+ m4_defines. */
+void muscles_m4_output (FILE *out);
+
+#endif /* not MUSCLE_TAB_H_ */
diff --git a/contrib/tools/bison/bison/src/named-ref.c b/contrib/tools/bison/bison/src/named-ref.c
index 1693767918..88827d1445 100644
--- a/contrib/tools/bison/bison/src/named-ref.c
+++ b/contrib/tools/bison/bison/src/named-ref.c
@@ -1,46 +1,46 @@
-/* Named symbol references for Bison
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "named-ref.h"
-
-named_ref *
-named_ref_new (uniqstr id, location loc)
-{
- named_ref *res = xmalloc (sizeof *res);
-
- res->id = id;
- res->loc = loc;
-
- return res;
-}
-
-named_ref *
-named_ref_copy (const named_ref *r)
-{
- return named_ref_new (r->id, r->loc);
-}
-
-void
-named_ref_free (named_ref *r)
-{
- free (r);
-}
+/* Named symbol references for Bison
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "named-ref.h"
+
+named_ref *
+named_ref_new (uniqstr id, location loc)
+{
+ named_ref *res = xmalloc (sizeof *res);
+
+ res->id = id;
+ res->loc = loc;
+
+ return res;
+}
+
+named_ref *
+named_ref_copy (const named_ref *r)
+{
+ return named_ref_new (r->id, r->loc);
+}
+
+void
+named_ref_free (named_ref *r)
+{
+ free (r);
+}
diff --git a/contrib/tools/bison/bison/src/named-ref.h b/contrib/tools/bison/bison/src/named-ref.h
index 84d02d7adb..ec918448f6 100644
--- a/contrib/tools/bison/bison/src/named-ref.h
+++ b/contrib/tools/bison/bison/src/named-ref.h
@@ -1,46 +1,46 @@
-/* Named symbol references for Bison
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef NAMED_REF_H_
-# define NAMED_REF_H_
-
-# include "location.h"
-# include "uniqstr.h"
-
-/* Named reference object. Keeps information about
- a symbolic name of a symbol in a rule. */
-typedef struct named_ref
-{
- /* Symbolic named given by user. */
- uniqstr id;
-
- /* Location of the symbolic name. Not including brackets. */
- location loc;
-} named_ref;
-
-/* Allocate a named reference object. */
-named_ref *named_ref_new (uniqstr id, location loc);
-
-/* Allocate and return a copy. */
-named_ref *named_ref_copy (const named_ref *r);
-
-/* Free a named reference object. */
-void named_ref_free (named_ref *r);
-
-#endif /* !NAMED_REF_H_ */
+/* Named symbol references for Bison
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef NAMED_REF_H_
+# define NAMED_REF_H_
+
+# include "location.h"
+# include "uniqstr.h"
+
+/* Named reference object. Keeps information about
+ a symbolic name of a symbol in a rule. */
+typedef struct named_ref
+{
+ /* Symbolic named given by user. */
+ uniqstr id;
+
+ /* Location of the symbolic name. Not including brackets. */
+ location loc;
+} named_ref;
+
+/* Allocate a named reference object. */
+named_ref *named_ref_new (uniqstr id, location loc);
+
+/* Allocate and return a copy. */
+named_ref *named_ref_copy (const named_ref *r);
+
+/* Free a named reference object. */
+void named_ref_free (named_ref *r);
+
+#endif /* !NAMED_REF_H_ */
diff --git a/contrib/tools/bison/bison/src/nullable.c b/contrib/tools/bison/bison/src/nullable.c
index a150f5f5c7..bb061b7033 100644
--- a/contrib/tools/bison/bison/src/nullable.c
+++ b/contrib/tools/bison/bison/src/nullable.c
@@ -1,142 +1,142 @@
-/* Calculate which nonterminals can expand into the null string for Bison.
-
- Copyright (C) 1984, 1989, 2000-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/* Set up NULLABLE, a vector saying which nonterminals can expand into
- the null string. NULLABLE[I - NTOKENS] is nonzero if symbol I can
- do so. */
-
-#include <config.h>
-#include "system.h"
-
-#include "getargs.h"
-#include "gram.h"
-#include "nullable.h"
-#include "reduce.h"
-#include "symtab.h"
-
-/* Linked list of rules. */
-typedef struct rule_list
-{
- struct rule_list *next;
- rule *value;
-} rule_list;
-
-bool *nullable = NULL;
-
-static void
-nullable_print (FILE *out)
-{
- int i;
- fputs ("NULLABLE\n", out);
- for (i = ntokens; i < nsyms; i++)
- fprintf (out, " %s: %s\n", symbols[i]->tag,
- nullable[i - ntokens] ? "yes" : "no");
- fputs ("\n\n", out);
-}
-
-void
-nullable_compute (void)
-{
- rule_number ruleno;
- symbol_number *s1;
- symbol_number *s2;
- rule_list *p;
-
- symbol_number *squeue = xnmalloc (nvars, sizeof *squeue);
- size_t *rcount = xcalloc (nrules, sizeof *rcount);
- /* RITEM contains all the rules, including useless productions.
- Hence we must allocate room for useless nonterminals too. */
- rule_list **rsets = xcalloc (nvars, sizeof *rsets);
- /* This is said to be more elements than we actually use.
- Supposedly NRITEMS - NRULES is enough. But why take the risk? */
- rule_list *relts = xnmalloc (nritems + nvars + 1, sizeof *relts);
-
- nullable = xcalloc (nvars, sizeof *nullable);
-
- s1 = s2 = squeue;
- p = relts;
-
- for (ruleno = 0; ruleno < nrules; ++ruleno)
- if (rules[ruleno].useful)
- {
- rule *rules_ruleno = &rules[ruleno];
- if (rules_ruleno->rhs[0] >= 0)
- {
- /* This rule has a non empty RHS. */
- item_number *rp = NULL;
- bool any_tokens = false;
- for (rp = rules_ruleno->rhs; *rp >= 0; ++rp)
- if (ISTOKEN (*rp))
- any_tokens = true;
-
- /* This rule has only nonterminals: schedule it for the second
- pass. */
- if (!any_tokens)
- for (rp = rules_ruleno->rhs; *rp >= 0; ++rp)
- {
- rcount[ruleno]++;
- p->next = rsets[*rp - ntokens];
- p->value = rules_ruleno;
- rsets[*rp - ntokens] = p;
- p++;
- }
- }
- else
- {
- /* This rule has an empty RHS. */
- aver (item_number_as_rule_number (rules_ruleno->rhs[0])
- == ruleno);
- if (rules_ruleno->useful
- && ! nullable[rules_ruleno->lhs->number - ntokens])
- {
- nullable[rules_ruleno->lhs->number - ntokens] = true;
- *s2++ = rules_ruleno->lhs->number;
- }
- }
- }
-
- while (s1 < s2)
- for (p = rsets[*s1++ - ntokens]; p; p = p->next)
- {
- rule *r = p->value;
- if (--rcount[r->number] == 0)
- if (r->useful && ! nullable[r->lhs->number - ntokens])
- {
- nullable[r->lhs->number - ntokens] = true;
- *s2++ = r->lhs->number;
- }
- }
-
- free (squeue);
- free (rcount);
- free (rsets);
- free (relts);
-
- if (trace_flag & trace_sets)
- nullable_print (stderr);
-}
-
-
-void
-nullable_free (void)
-{
- free (nullable);
-}
+/* Calculate which nonterminals can expand into the null string for Bison.
+
+ Copyright (C) 1984, 1989, 2000-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+/* Set up NULLABLE, a vector saying which nonterminals can expand into
+ the null string. NULLABLE[I - NTOKENS] is nonzero if symbol I can
+ do so. */
+
+#include <config.h>
+#include "system.h"
+
+#include "getargs.h"
+#include "gram.h"
+#include "nullable.h"
+#include "reduce.h"
+#include "symtab.h"
+
+/* Linked list of rules. */
+typedef struct rule_list
+{
+ struct rule_list *next;
+ rule *value;
+} rule_list;
+
+bool *nullable = NULL;
+
+static void
+nullable_print (FILE *out)
+{
+ int i;
+ fputs ("NULLABLE\n", out);
+ for (i = ntokens; i < nsyms; i++)
+ fprintf (out, " %s: %s\n", symbols[i]->tag,
+ nullable[i - ntokens] ? "yes" : "no");
+ fputs ("\n\n", out);
+}
+
+void
+nullable_compute (void)
+{
+ rule_number ruleno;
+ symbol_number *s1;
+ symbol_number *s2;
+ rule_list *p;
+
+ symbol_number *squeue = xnmalloc (nvars, sizeof *squeue);
+ size_t *rcount = xcalloc (nrules, sizeof *rcount);
+ /* RITEM contains all the rules, including useless productions.
+ Hence we must allocate room for useless nonterminals too. */
+ rule_list **rsets = xcalloc (nvars, sizeof *rsets);
+ /* This is said to be more elements than we actually use.
+ Supposedly NRITEMS - NRULES is enough. But why take the risk? */
+ rule_list *relts = xnmalloc (nritems + nvars + 1, sizeof *relts);
+
+ nullable = xcalloc (nvars, sizeof *nullable);
+
+ s1 = s2 = squeue;
+ p = relts;
+
+ for (ruleno = 0; ruleno < nrules; ++ruleno)
+ if (rules[ruleno].useful)
+ {
+ rule *rules_ruleno = &rules[ruleno];
+ if (rules_ruleno->rhs[0] >= 0)
+ {
+ /* This rule has a non empty RHS. */
+ item_number *rp = NULL;
+ bool any_tokens = false;
+ for (rp = rules_ruleno->rhs; *rp >= 0; ++rp)
+ if (ISTOKEN (*rp))
+ any_tokens = true;
+
+ /* This rule has only nonterminals: schedule it for the second
+ pass. */
+ if (!any_tokens)
+ for (rp = rules_ruleno->rhs; *rp >= 0; ++rp)
+ {
+ rcount[ruleno]++;
+ p->next = rsets[*rp - ntokens];
+ p->value = rules_ruleno;
+ rsets[*rp - ntokens] = p;
+ p++;
+ }
+ }
+ else
+ {
+ /* This rule has an empty RHS. */
+ aver (item_number_as_rule_number (rules_ruleno->rhs[0])
+ == ruleno);
+ if (rules_ruleno->useful
+ && ! nullable[rules_ruleno->lhs->number - ntokens])
+ {
+ nullable[rules_ruleno->lhs->number - ntokens] = true;
+ *s2++ = rules_ruleno->lhs->number;
+ }
+ }
+ }
+
+ while (s1 < s2)
+ for (p = rsets[*s1++ - ntokens]; p; p = p->next)
+ {
+ rule *r = p->value;
+ if (--rcount[r->number] == 0)
+ if (r->useful && ! nullable[r->lhs->number - ntokens])
+ {
+ nullable[r->lhs->number - ntokens] = true;
+ *s2++ = r->lhs->number;
+ }
+ }
+
+ free (squeue);
+ free (rcount);
+ free (rsets);
+ free (relts);
+
+ if (trace_flag & trace_sets)
+ nullable_print (stderr);
+}
+
+
+void
+nullable_free (void)
+{
+ free (nullable);
+}
diff --git a/contrib/tools/bison/bison/src/nullable.h b/contrib/tools/bison/bison/src/nullable.h
index 63a8ae3f14..31d74061a6 100644
--- a/contrib/tools/bison/bison/src/nullable.h
+++ b/contrib/tools/bison/bison/src/nullable.h
@@ -1,32 +1,32 @@
-/* Part of the bison parser generator,
-
- Copyright (C) 2000, 2002, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef NULLABLE_H_
-# define NULLABLE_H_
-
-/* A vector saying which nonterminals can expand into the null string.
- NULLABLE[I - NTOKENS] is nonzero if symbol I can do so. */
-extern bool *nullable;
-
-/* Set up NULLABLE. */
-extern void nullable_compute (void);
-
-/* Free NULLABLE. */
-extern void nullable_free (void);
-#endif /* !NULLABLE_H_ */
+/* Part of the bison parser generator,
+
+ Copyright (C) 2000, 2002, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef NULLABLE_H_
+# define NULLABLE_H_
+
+/* A vector saying which nonterminals can expand into the null string.
+ NULLABLE[I - NTOKENS] is nonzero if symbol I can do so. */
+extern bool *nullable;
+
+/* Set up NULLABLE. */
+extern void nullable_compute (void);
+
+/* Free NULLABLE. */
+extern void nullable_free (void);
+#endif /* !NULLABLE_H_ */
diff --git a/contrib/tools/bison/bison/src/output.c b/contrib/tools/bison/bison/src/output.c
index 61376ba390..b6a6111e85 100644
--- a/contrib/tools/bison/bison/src/output.c
+++ b/contrib/tools/bison/bison/src/output.c
@@ -1,740 +1,740 @@
-/* Output the generated parsing program for Bison.
-
- Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <concat-filename.h>
-#include <configmake.h>
-#include <filename.h>
-#include <get-errno.h>
-#include <quotearg.h>
-#include <spawn-pipe.h>
-#include <timevar.h>
-#include <wait-process.h>
-
-#include "complain.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "muscle-tab.h"
-#include "output.h"
-#include "reader.h"
-#include "scan-code.h" /* max_left_semantic_context */
-#include "scan-skel.h"
-#include "symtab.h"
-#include "tables.h"
-
-#include "uniqstr.h"
-
+/* Output the generated parsing program for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 1992, 2000-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <concat-filename.h>
+#include <configmake.h>
+#include <filename.h>
+#include <get-errno.h>
+#include <quotearg.h>
+#include <spawn-pipe.h>
+#include <timevar.h>
+#include <wait-process.h>
+
+#include "complain.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "muscle-tab.h"
+#include "output.h"
+#include "reader.h"
+#include "scan-code.h" /* max_left_semantic_context */
+#include "scan-skel.h"
+#include "symtab.h"
+#include "tables.h"
+
+#include "uniqstr.h"
+
#include <contrib/tools/bison/bison/arcadia_root.h>
-#ifndef M4
-#define M4 (m4_path)
-#endif
-
-#ifndef PKGDATADIR
+#ifndef M4
+#define M4 (m4_path)
+#endif
+
+#ifndef PKGDATADIR
#define STR(a) XSTR(a)
#define XSTR(a) #a
-const char*
-default_pkgdatadir()
-{
+const char*
+default_pkgdatadir()
+{
const char* arc_path = getenv("ARCADIA_ROOT_DISTBUILD");
if (arc_path == NULL)
arc_path = ArcadiaRoot();
return uniqstr_vsprintf("%s/" STR(BISON_DATA_DIR), arc_path);
-}
-#define PKGDATADIR (default_pkgdatadir())
-#endif
-
-static struct obstack format_obstack;
-
-
-/*-------------------------------------------------------------------.
-| Create a function NAME which associates to the muscle NAME the |
-| result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
-| TYPE), and to the muscle NAME_max, the max value of the |
-| TABLE_DATA. |
-`-------------------------------------------------------------------*/
-
-
-#define GENERATE_MUSCLE_INSERT_TABLE(Name, Type) \
- \
-static void \
-Name (char const *name, \
- Type *table_data, \
- Type first, \
- int begin, \
- int end) \
-{ \
- Type min = first; \
- Type max = first; \
- long int lmin; \
- long int lmax; \
- int i; \
- int j = 1; \
- \
- obstack_printf (&format_obstack, "%6d", first); \
- for (i = begin; i < end; ++i) \
- { \
- obstack_1grow (&format_obstack, ','); \
- if (j >= 10) \
- { \
- obstack_sgrow (&format_obstack, "\n "); \
- j = 1; \
- } \
- else \
- ++j; \
- obstack_printf (&format_obstack, "%6d", table_data[i]); \
- if (table_data[i] < min) \
- min = table_data[i]; \
- if (max < table_data[i]) \
- max = table_data[i]; \
- } \
- muscle_insert (name, obstack_finish0 (&format_obstack)); \
- \
- lmin = min; \
- lmax = max; \
- /* Build 'NAME_min' and 'NAME_max' in the obstack. */ \
- obstack_printf (&format_obstack, "%s_min", name); \
- MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmin); \
- obstack_printf (&format_obstack, "%s_max", name); \
- MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmax); \
-}
-
-GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_unsigned_int_table, unsigned int)
-GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_int_table, int)
-GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_base_table, base_number)
-GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_rule_number_table, rule_number)
-GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_symbol_number_table, symbol_number)
-GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_state_number_table, state_number)
-
-/*----------------------------------------------------------------.
-| Print to OUT a representation of CP quoted and escaped for M4. |
-`----------------------------------------------------------------*/
-
-static void
-quoted_output (FILE *out, char const *cp)
-{
- fprintf (out, "[[");
-
- for (; *cp; cp++)
- switch (*cp)
- {
- case '$': fputs ("$][", out); break;
- case '@': fputs ("@@", out); break;
- case '[': fputs ("@{", out); break;
- case ']': fputs ("@}", out); break;
- default: fputc (*cp, out); break;
- }
-
- fprintf (out, "]]");
-}
-
-/*----------------------------------------------------------------.
-| Print to OUT a representation of STRING quoted and escaped both |
-| for C and M4. |
-`----------------------------------------------------------------*/
-
-static void
-string_output (FILE *out, char const *string)
-{
- quoted_output (out, quotearg_style (c_quoting_style, string));
-}
-
-
-/*------------------------------------------------------------------.
-| Prepare the muscles related to the symbols: translate, tname, and |
-| toknum. |
-`------------------------------------------------------------------*/
-
-static void
-prepare_symbols (void)
-{
- MUSCLE_INSERT_INT ("tokens_number", ntokens);
- MUSCLE_INSERT_INT ("nterms_number", nvars);
- MUSCLE_INSERT_INT ("symbols_number", nsyms);
- MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
- MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
-
- muscle_insert_symbol_number_table ("translate",
- token_translations,
- token_translations[0],
- 1, max_user_token_number + 1);
-
- /* tname -- token names. */
- {
- int i;
- /* We assume that the table will be output starting at column 2. */
- int j = 2;
- struct quoting_options *qo = clone_quoting_options (0);
- set_quoting_style (qo, c_quoting_style);
- set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
- for (i = 0; i < nsyms; i++)
- {
- char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);
- /* Width of the next token, including the two quotes, the
- comma and the space. */
- int width = strlen (cp) + 2;
-
- if (j + width > 75)
- {
- obstack_sgrow (&format_obstack, "\n ");
- j = 1;
- }
-
- if (i)
- obstack_1grow (&format_obstack, ' ');
- obstack_escape (&format_obstack, cp);
- free (cp);
- obstack_1grow (&format_obstack, ',');
- j += width;
- }
- free (qo);
- obstack_sgrow (&format_obstack, " ]b4_null[");
-
- /* Finish table and store. */
- muscle_insert ("tname", obstack_finish0 (&format_obstack));
- }
-
- /* Output YYTOKNUM. */
- {
- int i;
- int *values = xnmalloc (ntokens, sizeof *values);
- for (i = 0; i < ntokens; ++i)
- values[i] = symbols[i]->user_token_number;
- muscle_insert_int_table ("toknum", values,
- values[0], 1, ntokens);
- free (values);
- }
-}
-
-
-/*----------------------------------------------------------------.
-| Prepare the muscles related to the rules: r1, r2, rline, dprec, |
-| merger, immediate. |
-`----------------------------------------------------------------*/
-
-static void
-prepare_rules (void)
-{
- unsigned int *rline = xnmalloc (nrules, sizeof *rline);
- symbol_number *r1 = xnmalloc (nrules, sizeof *r1);
- unsigned int *r2 = xnmalloc (nrules, sizeof *r2);
- int *dprec = xnmalloc (nrules, sizeof *dprec);
- int *merger = xnmalloc (nrules, sizeof *merger);
- int *immediate = xnmalloc (nrules, sizeof *immediate);
-
- rule_number r;
- for (r = 0; r < nrules; ++r)
- {
- /* LHS of the rule R. */
- r1[r] = rules[r].lhs->number;
- /* Length of rule R's RHS. */
- r2[r] = rule_rhs_length (&rules[r]);
- /* Line where rule was defined. */
- rline[r] = rules[r].location.start.line;
- /* Dynamic precedence (GLR). */
- dprec[r] = rules[r].dprec;
- /* Merger-function index (GLR). */
- merger[r] = rules[r].merger;
- /* Immediate reduction flags (GLR). */
- immediate[r] = rules[r].is_predicate;
- }
-
- muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules);
- muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules);
- muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules);
- muscle_insert_int_table ("dprec", dprec, 0, 0, nrules);
- muscle_insert_int_table ("merger", merger, 0, 0, nrules);
- muscle_insert_int_table ("immediate", immediate, 0, 0, nrules);
-
- MUSCLE_INSERT_INT ("rules_number", nrules);
- MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context);
-
- free (rline);
- free (r1);
- free (r2);
- free (dprec);
- free (merger);
- free (immediate);
-}
-
-/*--------------------------------------------.
-| Prepare the muscles related to the states. |
-`--------------------------------------------*/
-
-static void
-prepare_states (void)
-{
- state_number i;
- symbol_number *values = xnmalloc (nstates, sizeof *values);
- for (i = 0; i < nstates; ++i)
- values[i] = states[i]->accessing_symbol;
- muscle_insert_symbol_number_table ("stos", values,
- 0, 1, nstates);
- free (values);
-
- MUSCLE_INSERT_INT ("last", high);
- MUSCLE_INSERT_INT ("final_state_number", final_state->number);
- MUSCLE_INSERT_INT ("states_number", nstates);
-}
-
-
-/*-------------------------------------------------------.
-| Compare two symbols by type-name, and then by number. |
-`-------------------------------------------------------*/
-
-static int
-symbol_type_name_cmp (const symbol **lhs, const symbol **rhs)
-{
- int res = uniqstr_cmp ((*lhs)->type_name, (*rhs)->type_name);
- if (!res)
- res = (*lhs)->number - (*rhs)->number;
- return res;
-}
-
-
-/*----------------------------------------------------------------.
-| Return a (malloc'ed) table of the symbols sorted by type-name. |
-`----------------------------------------------------------------*/
-
-static symbol **
-symbols_by_type_name (void)
-{
- typedef int (*qcmp_type) (const void *, const void *);
- symbol **res = xmemdup (symbols, nsyms * sizeof *res);
- qsort (res, nsyms, sizeof *res, (qcmp_type) &symbol_type_name_cmp);
- return res;
-}
-
-
-/*------------------------------------------------------------------.
-| Define b4_type_names, which is a list of (lists of the numbers of |
-| symbols with same type-name). |
-`------------------------------------------------------------------*/
-
-static void
-type_names_output (FILE *out)
-{
- int i;
- symbol **syms = symbols_by_type_name ();
- fputs ("m4_define([b4_type_names],\n[", out);
- for (i = 0; i < nsyms; /* nothing */)
- {
- /* The index of the first symbol of the current type-name. */
- int i0 = i;
- fputs (i ? ",\n[" : "[", out);
- for (; i < nsyms && syms[i]->type_name == syms[i0]->type_name; ++i)
- fprintf (out, "%s%d", i != i0 ? ", " : "", syms[i]->number);
- fputs ("]", out);
- }
- fputs ("])\n\n", out);
- free (syms);
-}
-
-
-/*-------------------------------------.
-| The list of all the symbol numbers. |
-`-------------------------------------*/
-
-static void
-symbol_numbers_output (FILE *out)
-{
- int i;
- fputs ("m4_define([b4_symbol_numbers],\n[", out);
- for (i = 0; i < nsyms; ++i)
- fprintf (out, "%s[%d]", i ? ", " : "", i);
- fputs ("])\n\n", out);
-}
-
-
-/*---------------------------------.
-| Output the user actions to OUT. |
-`---------------------------------*/
-
-static void
-user_actions_output (FILE *out)
-{
- rule_number r;
-
- fputs ("m4_define([b4_actions], \n[", out);
- for (r = 0; r < nrules; ++r)
- if (rules[r].action)
- {
- fprintf (out, "b4_%scase(%d, [b4_syncline(%d, ",
- rules[r].is_predicate ? "predicate_" : "",
- r + 1, rules[r].action_location.start.line);
- string_output (out, rules[r].action_location.start.file);
- fprintf (out, ")\n[ %s]])\n\n", rules[r].action);
- }
- fputs ("])\n\n", out);
-}
-
-/*------------------------------------.
-| Output the merge functions to OUT. |
-`------------------------------------*/
-
-static void
-merger_output (FILE *out)
-{
- int n;
- merger_list* p;
-
- fputs ("m4_define([b4_mergers], \n[[", out);
- for (n = 1, p = merge_functions; p != NULL; n += 1, p = p->next)
- {
- if (p->type[0] == '\0')
- fprintf (out, " case %d: *yy0 = %s (*yy0, *yy1); break;\n",
- n, p->name);
- else
- fprintf (out, " case %d: yy0->%s = %s (*yy0, *yy1); break;\n",
- n, p->type, p->name);
- }
- fputs ("]])\n\n", out);
-}
-
-
-/*---------------------------------------------.
-| Prepare the muscles for symbol definitions. |
-`---------------------------------------------*/
-
-static void
-prepare_symbol_definitions (void)
-{
- int i;
- for (i = 0; i < nsyms; ++i)
- {
- symbol *sym = symbols[i];
- const char *key;
- const char *value;
-
-#define SET_KEY(Entry) \
- obstack_printf (&format_obstack, "symbol(%d, %s)", \
- i, Entry); \
- key = obstack_finish0 (&format_obstack);
-
-#define SET_KEY2(Entry, Suffix) \
- obstack_printf (&format_obstack, "symbol(%d, %s_%s)", \
- i, Entry, Suffix); \
- key = obstack_finish0 (&format_obstack);
-
- /* Whether the symbol has an identifier. */
- value = symbol_id_get (sym);
- SET_KEY ("has_id");
- MUSCLE_INSERT_INT (key, !!value);
-
- /* Its identifier. */
- SET_KEY ("id");
- MUSCLE_INSERT_STRING (key, value ? value : "");
-
- /* Its tag. Typically for documentation purpose. */
- SET_KEY ("tag");
- MUSCLE_INSERT_STRING (key, sym->tag);
-
- SET_KEY ("user_number");
- MUSCLE_INSERT_INT (key, sym->user_token_number);
-
- SET_KEY ("is_token");
- MUSCLE_INSERT_INT (key,
- i < ntokens && sym != errtoken && sym != undeftoken);
-
- SET_KEY ("number");
- MUSCLE_INSERT_INT (key, sym->number);
-
- SET_KEY ("has_type");
- MUSCLE_INSERT_INT (key, !!sym->type_name);
-
- SET_KEY ("type");
- MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
-
- {
- int j;
- for (j = 0; j < CODE_PROPS_SIZE; ++j)
- {
- /* "printer", not "%printer". */
- char const *pname = code_props_type_string (j) + 1;
- code_props const *p = symbol_code_props_get (sym, j);
- SET_KEY2 ("has", pname);
- MUSCLE_INSERT_INT (key, !!p->code);
-
- if (p->code)
- {
- SET_KEY2 (pname, "file");
- MUSCLE_INSERT_STRING (key, p->location.start.file);
-
- SET_KEY2 (pname, "line");
- MUSCLE_INSERT_INT (key, p->location.start.line);
-
- SET_KEY (pname);
- MUSCLE_INSERT_STRING_RAW (key, p->code);
- }
- }
- }
-#undef SET_KEY2
-#undef SET_KEY
- }
-}
-
-
-static void
-prepare_actions (void)
-{
- /* Figure out the actions for the specified state, indexed by
- lookahead token type. */
-
- muscle_insert_rule_number_table ("defact", yydefact,
- yydefact[0], 1, nstates);
-
- /* Figure out what to do after reducing with each rule, depending on
- the saved state from before the beginning of parsing the data
- that matched this rule. */
- muscle_insert_state_number_table ("defgoto", yydefgoto,
- yydefgoto[0], 1, nsyms - ntokens);
-
-
- /* Output PACT. */
- muscle_insert_base_table ("pact", base,
- base[0], 1, nstates);
- MUSCLE_INSERT_INT ("pact_ninf", base_ninf);
-
- /* Output PGOTO. */
- muscle_insert_base_table ("pgoto", base,
- base[nstates], nstates + 1, nvectors);
-
- muscle_insert_base_table ("table", table,
- table[0], 1, high + 1);
- MUSCLE_INSERT_INT ("table_ninf", table_ninf);
-
- muscle_insert_base_table ("check", check,
- check[0], 1, high + 1);
-
- /* GLR parsing slightly modifies YYTABLE and YYCHECK (and thus
- YYPACT) so that in states with unresolved conflicts, the default
- reduction is not used in the conflicted entries, so that there is
- a place to put a conflict pointer.
-
- This means that YYCONFLP and YYCONFL are nonsense for a non-GLR
- parser, so we could avoid accidents by not writing them out in
- that case. Nevertheless, it seems even better to be able to use
- the GLR skeletons even without the non-deterministic tables. */
- muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table,
- conflict_table[0], 1, high + 1);
- muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list,
- 0, 1, conflict_list_cnt);
-}
-
-
-/*--------------------------------------------.
-| Output the definitions of all the muscles. |
-`--------------------------------------------*/
-
-static void
-muscles_output (FILE *out)
-{
- fputs ("m4_init()\n", out);
- merger_output (out);
- symbol_numbers_output (out);
- type_names_output (out);
- user_actions_output (out);
- /* Must be last. */
- muscles_m4_output (out);
-}
-
-/*---------------------------.
-| Call the skeleton parser. |
-`---------------------------*/
-
-#define M4_GNU_OPTION "--gnu"
-
-static void
-output_skeleton (void)
-{
- int filter_fd[2];
- pid_t pid;
-
- /* Compute the names of the package data dir and skeleton files. */
- char const *m4 = (m4 = getenv ("M4")) ? m4 : M4;
- char const *datadir = pkgdatadir ();
- char *m4sugar = xconcatenated_filename (datadir, "m4sugar/m4sugar.m4", NULL);
- char *m4bison = xconcatenated_filename (datadir, "bison.m4", NULL);
- char *skel = (IS_PATH_WITH_DIR (skeleton)
- ? xstrdup (skeleton)
- : xconcatenated_filename (datadir, skeleton, NULL));
-
- /* Test whether m4sugar.m4 is readable, to check for proper
- installation. A faulty installation can cause deadlock, so a
- cheap sanity check is worthwhile. */
- xfclose (xfopen (m4sugar, "r"));
-
- /* Create an m4 subprocess connected to us via two pipes. */
-
- if (trace_flag & trace_tools)
- fprintf (stderr, "running: %s %s - %s %s\n",
- m4, m4sugar, m4bison, skel);
-
- /* Some future version of GNU M4 (most likely 1.6) may treat the -dV in a
- position-dependent manner. Keep it as the first argument so that all
- files are traced.
-
- See the thread starting at
- <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
- for details. */
- {
- char const *argv[10];
- int i = 0;
- argv[i++] = m4;
-
- /* When POSIXLY_CORRECT is set, GNU M4 1.6 and later disable GNU
- extensions, which Bison's skeletons depend on. With older M4,
- it has no effect. M4 1.4.12 added a -g/--gnu command-line
- option to make it explicit that a program wants GNU M4
- extensions even when POSIXLY_CORRECT is set.
-
- See the thread starting at
- <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
- for details. */
- if (*M4_GNU_OPTION)
- argv[i++] = M4_GNU_OPTION;
-
- argv[i++] = "-I";
- argv[i++] = datadir;
- if (trace_flag & trace_m4)
- argv[i++] = "-dV";
- argv[i++] = m4sugar;
- argv[i++] = "-";
- argv[i++] = m4bison;
- argv[i++] = skel;
- argv[i++] = NULL;
- aver (i <= ARRAY_CARDINALITY (argv));
-
- /* The ugly cast is because gnulib gets the const-ness wrong. */
- pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true,
- true, filter_fd);
- }
-
- free (m4sugar);
- free (m4bison);
- free (skel);
-
- if (trace_flag & trace_muscles)
- muscles_output (stderr);
- {
- FILE *out = xfdopen (filter_fd[1], "w");
- muscles_output (out);
- xfclose (out);
- }
-
- /* Read and process m4's output. */
- timevar_push (TV_M4);
- {
- FILE *in = xfdopen (filter_fd[0], "r");
- scan_skel (in);
- /* scan_skel should have read all of M4's output. Otherwise, when we
- close the pipe, we risk letting M4 report a broken-pipe to the
- Bison user. */
- aver (feof (in));
- xfclose (in);
- }
- wait_subprocess (pid, "m4", false, false, true, true, NULL);
- timevar_pop (TV_M4);
-}
-
-static void
-prepare (void)
-{
- /* BISON_USE_PUSH_FOR_PULL is for the test suite and should not be
- documented for the user. */
- char const *cp = getenv ("BISON_USE_PUSH_FOR_PULL");
- bool use_push_for_pull_flag = cp && *cp && strtol (cp, 0, 10);
-
- /* Flags. */
- MUSCLE_INSERT_BOOL ("defines_flag", defines_flag);
- MUSCLE_INSERT_BOOL ("glr_flag", glr_parser);
- MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
- MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
- MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen);
- MUSCLE_INSERT_BOOL ("token_table_flag", token_table_flag);
- MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag);
- MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);
-
- /* File names. */
- if (spec_name_prefix)
- MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
-
- MUSCLE_INSERT_STRING ("file_name_all_but_ext", all_but_ext);
-
-#define DEFINE(Name) MUSCLE_INSERT_STRING (#Name, Name ? Name : "")
- DEFINE (dir_prefix);
- DEFINE (parser_file_name);
- DEFINE (spec_defines_file);
- DEFINE (spec_file_prefix);
- DEFINE (spec_graph_file);
- DEFINE (spec_name_prefix);
- DEFINE (spec_outfile);
- DEFINE (spec_verbose_file);
-#undef DEFINE
-
- /* Find the right skeleton file, and add muscles about the skeletons. */
- if (skeleton)
- MUSCLE_INSERT_C_STRING ("skeleton", skeleton);
- else
- skeleton = language->skeleton;
-
- /* About the skeletons. */
- {
- /* b4_pkgdatadir is used inside m4_include in the skeletons, so digraphs
- would never be expanded. Hopefully no one has M4-special characters in
- his Bison installation path. */
- MUSCLE_INSERT_STRING_RAW ("pkgdatadir", pkgdatadir ());
- }
-}
-
-
-/*----------------------------------------------------------.
-| Output the parsing tables and the parser code to ftable. |
-`----------------------------------------------------------*/
-
-void
-output (void)
-{
- obstack_init (&format_obstack);
-
- prepare_symbols ();
- prepare_rules ();
- prepare_states ();
- prepare_actions ();
- prepare_symbol_definitions ();
-
- prepare ();
-
- /* Process the selected skeleton file. */
- output_skeleton ();
-
- obstack_free (&format_obstack, NULL);
-}
-
-char const *
-pkgdatadir (void)
-{
- char const *cp = getenv ("BISON_PKGDATADIR");
- return cp ? cp : PKGDATADIR;
-}
+}
+#define PKGDATADIR (default_pkgdatadir())
+#endif
+
+static struct obstack format_obstack;
+
+
+/*-------------------------------------------------------------------.
+| Create a function NAME which associates to the muscle NAME the |
+| result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
+| TYPE), and to the muscle NAME_max, the max value of the |
+| TABLE_DATA. |
+`-------------------------------------------------------------------*/
+
+
+#define GENERATE_MUSCLE_INSERT_TABLE(Name, Type) \
+ \
+static void \
+Name (char const *name, \
+ Type *table_data, \
+ Type first, \
+ int begin, \
+ int end) \
+{ \
+ Type min = first; \
+ Type max = first; \
+ long int lmin; \
+ long int lmax; \
+ int i; \
+ int j = 1; \
+ \
+ obstack_printf (&format_obstack, "%6d", first); \
+ for (i = begin; i < end; ++i) \
+ { \
+ obstack_1grow (&format_obstack, ','); \
+ if (j >= 10) \
+ { \
+ obstack_sgrow (&format_obstack, "\n "); \
+ j = 1; \
+ } \
+ else \
+ ++j; \
+ obstack_printf (&format_obstack, "%6d", table_data[i]); \
+ if (table_data[i] < min) \
+ min = table_data[i]; \
+ if (max < table_data[i]) \
+ max = table_data[i]; \
+ } \
+ muscle_insert (name, obstack_finish0 (&format_obstack)); \
+ \
+ lmin = min; \
+ lmax = max; \
+ /* Build 'NAME_min' and 'NAME_max' in the obstack. */ \
+ obstack_printf (&format_obstack, "%s_min", name); \
+ MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmin); \
+ obstack_printf (&format_obstack, "%s_max", name); \
+ MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmax); \
+}
+
+GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_unsigned_int_table, unsigned int)
+GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_int_table, int)
+GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_base_table, base_number)
+GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_rule_number_table, rule_number)
+GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_symbol_number_table, symbol_number)
+GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_state_number_table, state_number)
+
+/*----------------------------------------------------------------.
+| Print to OUT a representation of CP quoted and escaped for M4. |
+`----------------------------------------------------------------*/
+
+static void
+quoted_output (FILE *out, char const *cp)
+{
+ fprintf (out, "[[");
+
+ for (; *cp; cp++)
+ switch (*cp)
+ {
+ case '$': fputs ("$][", out); break;
+ case '@': fputs ("@@", out); break;
+ case '[': fputs ("@{", out); break;
+ case ']': fputs ("@}", out); break;
+ default: fputc (*cp, out); break;
+ }
+
+ fprintf (out, "]]");
+}
+
+/*----------------------------------------------------------------.
+| Print to OUT a representation of STRING quoted and escaped both |
+| for C and M4. |
+`----------------------------------------------------------------*/
+
+static void
+string_output (FILE *out, char const *string)
+{
+ quoted_output (out, quotearg_style (c_quoting_style, string));
+}
+
+
+/*------------------------------------------------------------------.
+| Prepare the muscles related to the symbols: translate, tname, and |
+| toknum. |
+`------------------------------------------------------------------*/
+
+static void
+prepare_symbols (void)
+{
+ MUSCLE_INSERT_INT ("tokens_number", ntokens);
+ MUSCLE_INSERT_INT ("nterms_number", nvars);
+ MUSCLE_INSERT_INT ("symbols_number", nsyms);
+ MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
+ MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
+
+ muscle_insert_symbol_number_table ("translate",
+ token_translations,
+ token_translations[0],
+ 1, max_user_token_number + 1);
+
+ /* tname -- token names. */
+ {
+ int i;
+ /* We assume that the table will be output starting at column 2. */
+ int j = 2;
+ struct quoting_options *qo = clone_quoting_options (0);
+ set_quoting_style (qo, c_quoting_style);
+ set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
+ for (i = 0; i < nsyms; i++)
+ {
+ char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);
+ /* Width of the next token, including the two quotes, the
+ comma and the space. */
+ int width = strlen (cp) + 2;
+
+ if (j + width > 75)
+ {
+ obstack_sgrow (&format_obstack, "\n ");
+ j = 1;
+ }
+
+ if (i)
+ obstack_1grow (&format_obstack, ' ');
+ obstack_escape (&format_obstack, cp);
+ free (cp);
+ obstack_1grow (&format_obstack, ',');
+ j += width;
+ }
+ free (qo);
+ obstack_sgrow (&format_obstack, " ]b4_null[");
+
+ /* Finish table and store. */
+ muscle_insert ("tname", obstack_finish0 (&format_obstack));
+ }
+
+ /* Output YYTOKNUM. */
+ {
+ int i;
+ int *values = xnmalloc (ntokens, sizeof *values);
+ for (i = 0; i < ntokens; ++i)
+ values[i] = symbols[i]->user_token_number;
+ muscle_insert_int_table ("toknum", values,
+ values[0], 1, ntokens);
+ free (values);
+ }
+}
+
+
+/*----------------------------------------------------------------.
+| Prepare the muscles related to the rules: r1, r2, rline, dprec, |
+| merger, immediate. |
+`----------------------------------------------------------------*/
+
+static void
+prepare_rules (void)
+{
+ unsigned int *rline = xnmalloc (nrules, sizeof *rline);
+ symbol_number *r1 = xnmalloc (nrules, sizeof *r1);
+ unsigned int *r2 = xnmalloc (nrules, sizeof *r2);
+ int *dprec = xnmalloc (nrules, sizeof *dprec);
+ int *merger = xnmalloc (nrules, sizeof *merger);
+ int *immediate = xnmalloc (nrules, sizeof *immediate);
+
+ rule_number r;
+ for (r = 0; r < nrules; ++r)
+ {
+ /* LHS of the rule R. */
+ r1[r] = rules[r].lhs->number;
+ /* Length of rule R's RHS. */
+ r2[r] = rule_rhs_length (&rules[r]);
+ /* Line where rule was defined. */
+ rline[r] = rules[r].location.start.line;
+ /* Dynamic precedence (GLR). */
+ dprec[r] = rules[r].dprec;
+ /* Merger-function index (GLR). */
+ merger[r] = rules[r].merger;
+ /* Immediate reduction flags (GLR). */
+ immediate[r] = rules[r].is_predicate;
+ }
+
+ muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules);
+ muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules);
+ muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules);
+ muscle_insert_int_table ("dprec", dprec, 0, 0, nrules);
+ muscle_insert_int_table ("merger", merger, 0, 0, nrules);
+ muscle_insert_int_table ("immediate", immediate, 0, 0, nrules);
+
+ MUSCLE_INSERT_INT ("rules_number", nrules);
+ MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context);
+
+ free (rline);
+ free (r1);
+ free (r2);
+ free (dprec);
+ free (merger);
+ free (immediate);
+}
+
+/*--------------------------------------------.
+| Prepare the muscles related to the states. |
+`--------------------------------------------*/
+
+static void
+prepare_states (void)
+{
+ state_number i;
+ symbol_number *values = xnmalloc (nstates, sizeof *values);
+ for (i = 0; i < nstates; ++i)
+ values[i] = states[i]->accessing_symbol;
+ muscle_insert_symbol_number_table ("stos", values,
+ 0, 1, nstates);
+ free (values);
+
+ MUSCLE_INSERT_INT ("last", high);
+ MUSCLE_INSERT_INT ("final_state_number", final_state->number);
+ MUSCLE_INSERT_INT ("states_number", nstates);
+}
+
+
+/*-------------------------------------------------------.
+| Compare two symbols by type-name, and then by number. |
+`-------------------------------------------------------*/
+
+static int
+symbol_type_name_cmp (const symbol **lhs, const symbol **rhs)
+{
+ int res = uniqstr_cmp ((*lhs)->type_name, (*rhs)->type_name);
+ if (!res)
+ res = (*lhs)->number - (*rhs)->number;
+ return res;
+}
+
+
+/*----------------------------------------------------------------.
+| Return a (malloc'ed) table of the symbols sorted by type-name. |
+`----------------------------------------------------------------*/
+
+static symbol **
+symbols_by_type_name (void)
+{
+ typedef int (*qcmp_type) (const void *, const void *);
+ symbol **res = xmemdup (symbols, nsyms * sizeof *res);
+ qsort (res, nsyms, sizeof *res, (qcmp_type) &symbol_type_name_cmp);
+ return res;
+}
+
+
+/*------------------------------------------------------------------.
+| Define b4_type_names, which is a list of (lists of the numbers of |
+| symbols with same type-name). |
+`------------------------------------------------------------------*/
+
+static void
+type_names_output (FILE *out)
+{
+ int i;
+ symbol **syms = symbols_by_type_name ();
+ fputs ("m4_define([b4_type_names],\n[", out);
+ for (i = 0; i < nsyms; /* nothing */)
+ {
+ /* The index of the first symbol of the current type-name. */
+ int i0 = i;
+ fputs (i ? ",\n[" : "[", out);
+ for (; i < nsyms && syms[i]->type_name == syms[i0]->type_name; ++i)
+ fprintf (out, "%s%d", i != i0 ? ", " : "", syms[i]->number);
+ fputs ("]", out);
+ }
+ fputs ("])\n\n", out);
+ free (syms);
+}
+
+
+/*-------------------------------------.
+| The list of all the symbol numbers. |
+`-------------------------------------*/
+
+static void
+symbol_numbers_output (FILE *out)
+{
+ int i;
+ fputs ("m4_define([b4_symbol_numbers],\n[", out);
+ for (i = 0; i < nsyms; ++i)
+ fprintf (out, "%s[%d]", i ? ", " : "", i);
+ fputs ("])\n\n", out);
+}
+
+
+/*---------------------------------.
+| Output the user actions to OUT. |
+`---------------------------------*/
+
+static void
+user_actions_output (FILE *out)
+{
+ rule_number r;
+
+ fputs ("m4_define([b4_actions], \n[", out);
+ for (r = 0; r < nrules; ++r)
+ if (rules[r].action)
+ {
+ fprintf (out, "b4_%scase(%d, [b4_syncline(%d, ",
+ rules[r].is_predicate ? "predicate_" : "",
+ r + 1, rules[r].action_location.start.line);
+ string_output (out, rules[r].action_location.start.file);
+ fprintf (out, ")\n[ %s]])\n\n", rules[r].action);
+ }
+ fputs ("])\n\n", out);
+}
+
+/*------------------------------------.
+| Output the merge functions to OUT. |
+`------------------------------------*/
+
+static void
+merger_output (FILE *out)
+{
+ int n;
+ merger_list* p;
+
+ fputs ("m4_define([b4_mergers], \n[[", out);
+ for (n = 1, p = merge_functions; p != NULL; n += 1, p = p->next)
+ {
+ if (p->type[0] == '\0')
+ fprintf (out, " case %d: *yy0 = %s (*yy0, *yy1); break;\n",
+ n, p->name);
+ else
+ fprintf (out, " case %d: yy0->%s = %s (*yy0, *yy1); break;\n",
+ n, p->type, p->name);
+ }
+ fputs ("]])\n\n", out);
+}
+
+
+/*---------------------------------------------.
+| Prepare the muscles for symbol definitions. |
+`---------------------------------------------*/
+
+static void
+prepare_symbol_definitions (void)
+{
+ int i;
+ for (i = 0; i < nsyms; ++i)
+ {
+ symbol *sym = symbols[i];
+ const char *key;
+ const char *value;
+
+#define SET_KEY(Entry) \
+ obstack_printf (&format_obstack, "symbol(%d, %s)", \
+ i, Entry); \
+ key = obstack_finish0 (&format_obstack);
+
+#define SET_KEY2(Entry, Suffix) \
+ obstack_printf (&format_obstack, "symbol(%d, %s_%s)", \
+ i, Entry, Suffix); \
+ key = obstack_finish0 (&format_obstack);
+
+ /* Whether the symbol has an identifier. */
+ value = symbol_id_get (sym);
+ SET_KEY ("has_id");
+ MUSCLE_INSERT_INT (key, !!value);
+
+ /* Its identifier. */
+ SET_KEY ("id");
+ MUSCLE_INSERT_STRING (key, value ? value : "");
+
+ /* Its tag. Typically for documentation purpose. */
+ SET_KEY ("tag");
+ MUSCLE_INSERT_STRING (key, sym->tag);
+
+ SET_KEY ("user_number");
+ MUSCLE_INSERT_INT (key, sym->user_token_number);
+
+ SET_KEY ("is_token");
+ MUSCLE_INSERT_INT (key,
+ i < ntokens && sym != errtoken && sym != undeftoken);
+
+ SET_KEY ("number");
+ MUSCLE_INSERT_INT (key, sym->number);
+
+ SET_KEY ("has_type");
+ MUSCLE_INSERT_INT (key, !!sym->type_name);
+
+ SET_KEY ("type");
+ MUSCLE_INSERT_STRING (key, sym->type_name ? sym->type_name : "");
+
+ {
+ int j;
+ for (j = 0; j < CODE_PROPS_SIZE; ++j)
+ {
+ /* "printer", not "%printer". */
+ char const *pname = code_props_type_string (j) + 1;
+ code_props const *p = symbol_code_props_get (sym, j);
+ SET_KEY2 ("has", pname);
+ MUSCLE_INSERT_INT (key, !!p->code);
+
+ if (p->code)
+ {
+ SET_KEY2 (pname, "file");
+ MUSCLE_INSERT_STRING (key, p->location.start.file);
+
+ SET_KEY2 (pname, "line");
+ MUSCLE_INSERT_INT (key, p->location.start.line);
+
+ SET_KEY (pname);
+ MUSCLE_INSERT_STRING_RAW (key, p->code);
+ }
+ }
+ }
+#undef SET_KEY2
+#undef SET_KEY
+ }
+}
+
+
+static void
+prepare_actions (void)
+{
+ /* Figure out the actions for the specified state, indexed by
+ lookahead token type. */
+
+ muscle_insert_rule_number_table ("defact", yydefact,
+ yydefact[0], 1, nstates);
+
+ /* Figure out what to do after reducing with each rule, depending on
+ the saved state from before the beginning of parsing the data
+ that matched this rule. */
+ muscle_insert_state_number_table ("defgoto", yydefgoto,
+ yydefgoto[0], 1, nsyms - ntokens);
+
+
+ /* Output PACT. */
+ muscle_insert_base_table ("pact", base,
+ base[0], 1, nstates);
+ MUSCLE_INSERT_INT ("pact_ninf", base_ninf);
+
+ /* Output PGOTO. */
+ muscle_insert_base_table ("pgoto", base,
+ base[nstates], nstates + 1, nvectors);
+
+ muscle_insert_base_table ("table", table,
+ table[0], 1, high + 1);
+ MUSCLE_INSERT_INT ("table_ninf", table_ninf);
+
+ muscle_insert_base_table ("check", check,
+ check[0], 1, high + 1);
+
+ /* GLR parsing slightly modifies YYTABLE and YYCHECK (and thus
+ YYPACT) so that in states with unresolved conflicts, the default
+ reduction is not used in the conflicted entries, so that there is
+ a place to put a conflict pointer.
+
+ This means that YYCONFLP and YYCONFL are nonsense for a non-GLR
+ parser, so we could avoid accidents by not writing them out in
+ that case. Nevertheless, it seems even better to be able to use
+ the GLR skeletons even without the non-deterministic tables. */
+ muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table,
+ conflict_table[0], 1, high + 1);
+ muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list,
+ 0, 1, conflict_list_cnt);
+}
+
+
+/*--------------------------------------------.
+| Output the definitions of all the muscles. |
+`--------------------------------------------*/
+
+static void
+muscles_output (FILE *out)
+{
+ fputs ("m4_init()\n", out);
+ merger_output (out);
+ symbol_numbers_output (out);
+ type_names_output (out);
+ user_actions_output (out);
+ /* Must be last. */
+ muscles_m4_output (out);
+}
+
+/*---------------------------.
+| Call the skeleton parser. |
+`---------------------------*/
+
+#define M4_GNU_OPTION "--gnu"
+
+static void
+output_skeleton (void)
+{
+ int filter_fd[2];
+ pid_t pid;
+
+ /* Compute the names of the package data dir and skeleton files. */
+ char const *m4 = (m4 = getenv ("M4")) ? m4 : M4;
+ char const *datadir = pkgdatadir ();
+ char *m4sugar = xconcatenated_filename (datadir, "m4sugar/m4sugar.m4", NULL);
+ char *m4bison = xconcatenated_filename (datadir, "bison.m4", NULL);
+ char *skel = (IS_PATH_WITH_DIR (skeleton)
+ ? xstrdup (skeleton)
+ : xconcatenated_filename (datadir, skeleton, NULL));
+
+ /* Test whether m4sugar.m4 is readable, to check for proper
+ installation. A faulty installation can cause deadlock, so a
+ cheap sanity check is worthwhile. */
+ xfclose (xfopen (m4sugar, "r"));
+
+ /* Create an m4 subprocess connected to us via two pipes. */
+
+ if (trace_flag & trace_tools)
+ fprintf (stderr, "running: %s %s - %s %s\n",
+ m4, m4sugar, m4bison, skel);
+
+ /* Some future version of GNU M4 (most likely 1.6) may treat the -dV in a
+ position-dependent manner. Keep it as the first argument so that all
+ files are traced.
+
+ See the thread starting at
+ <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
+ for details. */
+ {
+ char const *argv[10];
+ int i = 0;
+ argv[i++] = m4;
+
+ /* When POSIXLY_CORRECT is set, GNU M4 1.6 and later disable GNU
+ extensions, which Bison's skeletons depend on. With older M4,
+ it has no effect. M4 1.4.12 added a -g/--gnu command-line
+ option to make it explicit that a program wants GNU M4
+ extensions even when POSIXLY_CORRECT is set.
+
+ See the thread starting at
+ <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
+ for details. */
+ if (*M4_GNU_OPTION)
+ argv[i++] = M4_GNU_OPTION;
+
+ argv[i++] = "-I";
+ argv[i++] = datadir;
+ if (trace_flag & trace_m4)
+ argv[i++] = "-dV";
+ argv[i++] = m4sugar;
+ argv[i++] = "-";
+ argv[i++] = m4bison;
+ argv[i++] = skel;
+ argv[i++] = NULL;
+ aver (i <= ARRAY_CARDINALITY (argv));
+
+ /* The ugly cast is because gnulib gets the const-ness wrong. */
+ pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true,
+ true, filter_fd);
+ }
+
+ free (m4sugar);
+ free (m4bison);
+ free (skel);
+
+ if (trace_flag & trace_muscles)
+ muscles_output (stderr);
+ {
+ FILE *out = xfdopen (filter_fd[1], "w");
+ muscles_output (out);
+ xfclose (out);
+ }
+
+ /* Read and process m4's output. */
+ timevar_push (TV_M4);
+ {
+ FILE *in = xfdopen (filter_fd[0], "r");
+ scan_skel (in);
+ /* scan_skel should have read all of M4's output. Otherwise, when we
+ close the pipe, we risk letting M4 report a broken-pipe to the
+ Bison user. */
+ aver (feof (in));
+ xfclose (in);
+ }
+ wait_subprocess (pid, "m4", false, false, true, true, NULL);
+ timevar_pop (TV_M4);
+}
+
+static void
+prepare (void)
+{
+ /* BISON_USE_PUSH_FOR_PULL is for the test suite and should not be
+ documented for the user. */
+ char const *cp = getenv ("BISON_USE_PUSH_FOR_PULL");
+ bool use_push_for_pull_flag = cp && *cp && strtol (cp, 0, 10);
+
+ /* Flags. */
+ MUSCLE_INSERT_BOOL ("defines_flag", defines_flag);
+ MUSCLE_INSERT_BOOL ("glr_flag", glr_parser);
+ MUSCLE_INSERT_BOOL ("nondeterministic_flag", nondeterministic_parser);
+ MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
+ MUSCLE_INSERT_BOOL ("tag_seen_flag", tag_seen);
+ MUSCLE_INSERT_BOOL ("token_table_flag", token_table_flag);
+ MUSCLE_INSERT_BOOL ("use_push_for_pull_flag", use_push_for_pull_flag);
+ MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);
+
+ /* File names. */
+ if (spec_name_prefix)
+ MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
+
+ MUSCLE_INSERT_STRING ("file_name_all_but_ext", all_but_ext);
+
+#define DEFINE(Name) MUSCLE_INSERT_STRING (#Name, Name ? Name : "")
+ DEFINE (dir_prefix);
+ DEFINE (parser_file_name);
+ DEFINE (spec_defines_file);
+ DEFINE (spec_file_prefix);
+ DEFINE (spec_graph_file);
+ DEFINE (spec_name_prefix);
+ DEFINE (spec_outfile);
+ DEFINE (spec_verbose_file);
+#undef DEFINE
+
+ /* Find the right skeleton file, and add muscles about the skeletons. */
+ if (skeleton)
+ MUSCLE_INSERT_C_STRING ("skeleton", skeleton);
+ else
+ skeleton = language->skeleton;
+
+ /* About the skeletons. */
+ {
+ /* b4_pkgdatadir is used inside m4_include in the skeletons, so digraphs
+ would never be expanded. Hopefully no one has M4-special characters in
+ his Bison installation path. */
+ MUSCLE_INSERT_STRING_RAW ("pkgdatadir", pkgdatadir ());
+ }
+}
+
+
+/*----------------------------------------------------------.
+| Output the parsing tables and the parser code to ftable. |
+`----------------------------------------------------------*/
+
+void
+output (void)
+{
+ obstack_init (&format_obstack);
+
+ prepare_symbols ();
+ prepare_rules ();
+ prepare_states ();
+ prepare_actions ();
+ prepare_symbol_definitions ();
+
+ prepare ();
+
+ /* Process the selected skeleton file. */
+ output_skeleton ();
+
+ obstack_free (&format_obstack, NULL);
+}
+
+char const *
+pkgdatadir (void)
+{
+ char const *cp = getenv ("BISON_PKGDATADIR");
+ return cp ? cp : PKGDATADIR;
+}
diff --git a/contrib/tools/bison/bison/src/output.h b/contrib/tools/bison/bison/src/output.h
index 63a0ca803a..0d14c48483 100644
--- a/contrib/tools/bison/bison/src/output.h
+++ b/contrib/tools/bison/bison/src/output.h
@@ -1,30 +1,30 @@
-/* Output the generated parsing program for bison,
-
- Copyright (C) 2000-2003, 2006-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef OUTPUT_H_
-# define OUTPUT_H_
-
-/* Output the parsing tables and the parser code to FTABLE. */
-void output (void);
-
-/* Where our data files are installed. */
-char const *pkgdatadir (void);
-
-#endif /* !OUTPUT_H_ */
+/* Output the generated parsing program for bison,
+
+ Copyright (C) 2000-2003, 2006-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef OUTPUT_H_
+# define OUTPUT_H_
+
+/* Output the parsing tables and the parser code to FTABLE. */
+void output (void);
+
+/* Where our data files are installed. */
+char const *pkgdatadir (void);
+
+#endif /* !OUTPUT_H_ */
diff --git a/contrib/tools/bison/bison/src/parse-gram.c b/contrib/tools/bison/bison/src/parse-gram.c
index 5b862667e9..e3a20a96aa 100644
--- a/contrib/tools/bison/bison/src/parse-gram.c
+++ b/contrib/tools/bison/bison/src/parse-gram.c
@@ -1,3106 +1,3106 @@
-/* A Bison parser, made by GNU Bison 3.0. */
-
-/* Bison implementation for Yacc-like parsers in C
-
- Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* As a special exception, you may create a larger work that contains
- part or all of the Bison parser skeleton and distribute that work
- under terms of your choice, so long as that work isn't itself a
- parser generator using the skeleton or a modified version thereof
- as a parser skeleton. Alternatively, if you modify or redistribute
- the parser skeleton itself, you may (at your option) remove this
- special exception, which will cause the skeleton and the resulting
- Bison output files to be licensed under the GNU General Public
- License without this special exception.
-
- This special exception was added by the Free Software Foundation in
- version 2.2 of Bison. */
-
-/* C LALR(1) parser skeleton written by Richard Stallman, by
- simplifying the original so-called "semantic" parser. */
-
-/* All symbols defined below should begin with yy or YY, to avoid
- infringing on user name space. This should be done even for local
- variables, as they might otherwise be expanded by user macros.
- There are some unavoidable exceptions within include files to
- define necessary library symbols; they are noted "INFRINGES ON
- USER NAME SPACE" below. */
-
-/* Identify Bison output. */
-#define YYBISON 1
-
-/* Bison version. */
-#define YYBISON_VERSION "3.0"
-
-/* Skeleton name. */
-#define YYSKELETON_NAME "yacc.c"
-
-/* Pure parsers. */
-#define YYPURE 2
-
-/* Push parsers. */
-#define YYPUSH 0
-
-/* Pull parsers. */
-#define YYPULL 1
-
-/* "%code top" blocks. */
-#line 27 "src/parse-gram.y" /* yacc.c:316 */
-
- /* On column 0 to please syntax-check. */
-#include <config.h>
+/* A Bison parser, made by GNU Bison 3.0. */
+
+/* Bison implementation for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "3.0"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 2
+
+/* Push parsers. */
+#define YYPUSH 0
+
+/* Pull parsers. */
+#define YYPULL 1
+
+/* "%code top" blocks. */
+#line 27 "src/parse-gram.y" /* yacc.c:316 */
+
+ /* On column 0 to please syntax-check. */
+#include <config.h>
#include "string--.h"
-
-#line 68 "src/parse-gram.c" /* yacc.c:316 */
-/* Substitute the type names. */
-#define YYSTYPE GRAM_STYPE
-#define YYLTYPE GRAM_LTYPE
-/* Substitute the variable and function names. */
-#define yyparse gram_parse
-#define yylex gram_lex
-#define yyerror gram_error
-#define yydebug gram_debug
-#define yynerrs gram_nerrs
-
-
-/* Copy the first part of user declarations. */
-
-#line 82 "src/parse-gram.c" /* yacc.c:339 */
-
-# ifndef YY_NULL
-# if defined __cplusplus && 201103L <= __cplusplus
-# define YY_NULL nullptr
-# else
-# define YY_NULL 0
-# endif
-# endif
-
-/* Enabling verbose error messages. */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 1
-#endif
-
-/* In a future release of Bison, this section will be replaced
- by #include "src/parse-gram.h". */
-#ifndef YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
-# define YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
-/* Debug traces. */
-#ifndef GRAM_DEBUG
-# if defined YYDEBUG
-#if YYDEBUG
-# define GRAM_DEBUG 1
-# else
-# define GRAM_DEBUG 0
-# endif
-# else /* ! defined YYDEBUG */
-# define GRAM_DEBUG 1
-# endif /* ! defined YYDEBUG */
-#endif /* ! defined GRAM_DEBUG */
-#if GRAM_DEBUG
-extern int gram_debug;
-#endif
-/* "%code requires" blocks. */
-#line 21 "src/parse-gram.y" /* yacc.c:355 */
-
- #include "symlist.h"
- #include "symtab.h"
-#line 221 "src/parse-gram.y" /* yacc.c:355 */
-
- typedef enum
- {
- param_none = 0,
- param_lex = 1 << 0,
- param_parse = 1 << 1,
- param_both = param_lex | param_parse
- } param_type;
-#line 645 "src/parse-gram.y" /* yacc.c:355 */
-#include "muscle-tab.h"
-
-#line 136 "src/parse-gram.c" /* yacc.c:355 */
-
-/* Token type. */
-#ifndef GRAM_TOKENTYPE
-# define GRAM_TOKENTYPE
- enum gram_tokentype
- {
- GRAM_EOF = 0,
- STRING = 258,
- PERCENT_TOKEN = 259,
- PERCENT_NTERM = 260,
- PERCENT_TYPE = 261,
- PERCENT_DESTRUCTOR = 262,
- PERCENT_PRINTER = 263,
- PERCENT_LEFT = 264,
- PERCENT_RIGHT = 265,
- PERCENT_NONASSOC = 266,
- PERCENT_PRECEDENCE = 267,
- PERCENT_PREC = 268,
- PERCENT_DPREC = 269,
- PERCENT_MERGE = 270,
- PERCENT_CODE = 271,
- PERCENT_DEFAULT_PREC = 272,
- PERCENT_DEFINE = 273,
- PERCENT_DEFINES = 274,
- PERCENT_ERROR_VERBOSE = 275,
- PERCENT_EXPECT = 276,
- PERCENT_EXPECT_RR = 277,
- PERCENT_FLAG = 278,
- PERCENT_FILE_PREFIX = 279,
- PERCENT_GLR_PARSER = 280,
- PERCENT_INITIAL_ACTION = 281,
- PERCENT_LANGUAGE = 282,
- PERCENT_NAME_PREFIX = 283,
- PERCENT_NO_DEFAULT_PREC = 284,
- PERCENT_NO_LINES = 285,
- PERCENT_NONDETERMINISTIC_PARSER = 286,
- PERCENT_OUTPUT = 287,
- PERCENT_REQUIRE = 288,
- PERCENT_SKELETON = 289,
- PERCENT_START = 290,
- PERCENT_TOKEN_TABLE = 291,
- PERCENT_VERBOSE = 292,
- PERCENT_YACC = 293,
- BRACED_CODE = 294,
- BRACED_PREDICATE = 295,
- BRACKETED_ID = 296,
- CHAR = 297,
- EPILOGUE = 298,
- EQUAL = 299,
- ID = 300,
- ID_COLON = 301,
- PERCENT_PERCENT = 302,
- PIPE = 303,
- PROLOGUE = 304,
- SEMICOLON = 305,
- TAG = 306,
- TAG_ANY = 307,
- TAG_NONE = 308,
- INT = 309,
- PERCENT_PARAM = 310,
- PERCENT_UNION = 311,
- PERCENT_EMPTY = 312
- };
-#endif
-
-/* Value type. */
-#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED
-typedef union GRAM_STYPE GRAM_STYPE;
-union GRAM_STYPE
-{
-#line 182 "src/parse-gram.y" /* yacc.c:355 */
-unsigned char character;
-#line 186 "src/parse-gram.y" /* yacc.c:355 */
-char *code;
-#line 191 "src/parse-gram.y" /* yacc.c:355 */
-uniqstr uniqstr;
-#line 199 "src/parse-gram.y" /* yacc.c:355 */
-int integer;
-#line 203 "src/parse-gram.y" /* yacc.c:355 */
-symbol *symbol;
-#line 208 "src/parse-gram.y" /* yacc.c:355 */
-assoc assoc;
-#line 211 "src/parse-gram.y" /* yacc.c:355 */
-symbol_list *list;
-#line 214 "src/parse-gram.y" /* yacc.c:355 */
-named_ref *named_ref;
-#line 241 "src/parse-gram.y" /* yacc.c:355 */
-param_type param;
-#line 409 "src/parse-gram.y" /* yacc.c:355 */
-code_props_type code_type;
-#line 647 "src/parse-gram.y" /* yacc.c:355 */
-
- struct
- {
- char const *chars;
- muscle_kind kind;
- } value;
-
-#line 235 "src/parse-gram.c" /* yacc.c:355 */
-};
-# define GRAM_STYPE_IS_TRIVIAL 1
-# define GRAM_STYPE_IS_DECLARED 1
-#endif
-
-/* Location type. */
-#if ! defined GRAM_LTYPE && ! defined GRAM_LTYPE_IS_DECLARED
-typedef struct GRAM_LTYPE GRAM_LTYPE;
-struct GRAM_LTYPE
-{
- int first_line;
- int first_column;
- int last_line;
- int last_column;
-};
-# define GRAM_LTYPE_IS_DECLARED 1
-# define GRAM_LTYPE_IS_TRIVIAL 1
-#endif
-
-
-
-int gram_parse (void);
-
-#endif /* !YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED */
-
-/* Copy the second part of user declarations. */
-
-#line 263 "src/parse-gram.c" /* yacc.c:358 */
-/* Unqualified %code blocks. */
-#line 33 "src/parse-gram.y" /* yacc.c:359 */
-
- #include "system.h"
-
- #include "c-ctype.h"
- #include "complain.h"
- #include "conflicts.h"
- #include "files.h"
- #include "getargs.h"
- #include "gram.h"
- #include "named-ref.h"
- #include "quotearg.h"
- #include "reader.h"
- #include "scan-gram.h"
- #include "scan-code.h"
- #include "xmemdup0.h"
-
- static int current_prec = 0;
- static location current_lhs_location;
- static named_ref *current_lhs_named_ref;
- static symbol *current_lhs_symbol;
- static symbol_class current_class = unknown_sym;
- static uniqstr current_type = NULL;
-
- /** Set the new current left-hand side symbol, possibly common
- * to several right-hand side parts of rule.
- */
- static void current_lhs (symbol *sym, location loc, named_ref *ref);
-
- #define YYLLOC_DEFAULT(Current, Rhs, N) \
- (Current) = lloc_default (Rhs, N)
- static YYLTYPE lloc_default (YYLTYPE const *, int);
-
- #define YY_LOCATION_PRINT(File, Loc) \
- location_print (Loc, File)
-
- /* Strip initial '{' and final '}' (must be first and last characters).
- Return the result. */
- static char *strip_braces (char *code);
-
- /* Convert CODE by calling code_props_plain_init if PLAIN, otherwise
- code_props_symbol_action_init. Call
- gram_scanner_last_string_free to release the latest string from
- the scanner (should be CODE). */
- static char const *translate_code (char *code, location loc, bool plain);
-
- /* Convert CODE by calling code_props_plain_init after having
- stripped the first and last characters (expected to be '{', and
- '}'). Call gram_scanner_last_string_free to release the latest
- string from the scanner (should be CODE). */
- static char const *translate_code_braceless (char *code, location loc);
-
- static void version_check (location const *loc, char const *version);
-
- static void gram_error (location const *, char const *);
-
- /* A string that describes a char (e.g., 'a' -> "'a'"). */
- static char const *char_name (char);
-
- #define YYTYPE_INT16 int_fast16_t
- #define YYTYPE_INT8 int_fast8_t
- #define YYTYPE_UINT16 uint_fast16_t
- #define YYTYPE_UINT8 uint_fast8_t
-#line 231 "src/parse-gram.y" /* yacc.c:359 */
-
- /** Add a lex-param and/or a parse-param.
- *
- * \param type where to push this formal argument.
- * \param decl the formal argument. Destroyed.
- * \param loc the location in the source.
- */
- static void add_param (param_type type, char *decl, location loc);
- static param_type current_param = param_none;
-
-#line 339 "src/parse-gram.c" /* yacc.c:359 */
-
-#ifdef short
-# undef short
-#endif
-
-#ifdef YYTYPE_UINT8
-typedef YYTYPE_UINT8 yytype_uint8;
-#else
-typedef unsigned char yytype_uint8;
-#endif
-
-#ifdef YYTYPE_INT8
-typedef YYTYPE_INT8 yytype_int8;
-#else
-typedef signed char yytype_int8;
-#endif
-
-#ifdef YYTYPE_UINT16
-typedef YYTYPE_UINT16 yytype_uint16;
-#else
-typedef unsigned short int yytype_uint16;
-#endif
-
-#ifdef YYTYPE_INT16
-typedef YYTYPE_INT16 yytype_int16;
-#else
-typedef short int yytype_int16;
-#endif
-
-#ifndef YYSIZE_T
-# ifdef __SIZE_TYPE__
-# define YYSIZE_T __SIZE_TYPE__
-# elif defined size_t
-# define YYSIZE_T size_t
-# elif ! defined YYSIZE_T
-# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
-# define YYSIZE_T size_t
-# else
-# define YYSIZE_T unsigned int
-# endif
-#endif
-
-#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
-
-#ifndef YY_
-# if defined YYENABLE_NLS && YYENABLE_NLS
-# if ENABLE_NLS
-# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
-# endif
-# endif
-# ifndef YY_
-# define YY_(Msgid) Msgid
-# endif
-#endif
-
-#ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if (! defined __GNUC__ || __GNUC__ < 2 \
- || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
-# define __attribute__(Spec) /* empty */
-# endif
-#endif
-
-/* Suppress unused-variable warnings by "using" E. */
-#if ! defined lint || defined __GNUC__
-# define YYUSE(E) ((void) (E))
-#else
-# define YYUSE(E) /* empty */
-#endif
-
-#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
-/* Suppress an incorrect diagnostic about yylval being uninitialized. */
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
- _Pragma ("GCC diagnostic push") \
- _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
- _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
- _Pragma ("GCC diagnostic pop")
-#else
-# define YY_INITIAL_VALUE(Value) Value
-#endif
-#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
-# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
-# define YY_IGNORE_MAYBE_UNINITIALIZED_END
-#endif
-#ifndef YY_INITIAL_VALUE
-# define YY_INITIAL_VALUE(Value) /* Nothing. */
-#endif
-
-
-#if 1
-
-/* The parser invokes alloca or malloc; define the necessary symbols. */
-
-# ifdef YYSTACK_ALLOC
- /* Pacify GCC's 'empty if-body' warning. */
-# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
-# ifndef YYSTACK_ALLOC_MAXIMUM
- /* The OS might guarantee only one guard page at the bottom of the stack,
- and a page size can be as small as 4096 bytes. So we cannot safely
- invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
- to allow for a few compiler-allocated temporary stack slots. */
-# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
-# endif
-# else
-# define YYSTACK_ALLOC YYMALLOC
-# define YYSTACK_FREE YYFREE
-# ifndef YYSTACK_ALLOC_MAXIMUM
-# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
-# endif
-# if (defined __cplusplus && ! defined EXIT_SUCCESS \
- && ! ((defined YYMALLOC || defined malloc) \
- && (defined YYFREE || defined free)))
-# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
-# ifndef EXIT_SUCCESS
-# define EXIT_SUCCESS 0
-# endif
-# endif
-# ifndef YYMALLOC
-# define YYMALLOC malloc
-# if ! defined malloc && ! defined EXIT_SUCCESS
-void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
-# endif
-# endif
-# ifndef YYFREE
-# define YYFREE free
-# if ! defined free && ! defined EXIT_SUCCESS
-void free (void *); /* INFRINGES ON USER NAME SPACE */
-# endif
-# endif
-# endif
-# define YYCOPY_NEEDED 1
-#endif
-
-
-#if (! defined yyoverflow \
- && (! defined __cplusplus \
- || (defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL \
- && defined GRAM_STYPE_IS_TRIVIAL && GRAM_STYPE_IS_TRIVIAL)))
-
-/* A type that is properly aligned for any stack member. */
-union yyalloc
-{
- yytype_int16 yyss_alloc;
- YYSTYPE yyvs_alloc;
- YYLTYPE yyls_alloc;
-};
-
-/* The size of the maximum gap between one aligned stack and the next. */
-# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
-
-/* The size of an array large to enough to hold all stacks, each with
- N elements. */
-# define YYSTACK_BYTES(N) \
- ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
- + 2 * YYSTACK_GAP_MAXIMUM)
-
-# define YYCOPY_NEEDED 1
-
-/* Relocate STACK from its old location to the new one. The
- local variables YYSIZE and YYSTACKSIZE give the old and new number of
- elements in the stack, and YYPTR gives the new location of the
- stack. Advance YYPTR to a properly aligned location for the next
- stack. */
-# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
- do \
- { \
- YYSIZE_T yynewbytes; \
- YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
- Stack = &yyptr->Stack_alloc; \
- yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
- yyptr += yynewbytes / sizeof (*yyptr); \
- } \
- while (0)
-
-#endif
-
-#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
-/* Copy COUNT objects from SRC to DST. The source and destination do
- not overlap. */
-# ifndef YYCOPY
-# if defined __GNUC__ && 1 < __GNUC__
-# define YYCOPY(Dst, Src, Count) \
- __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
-# else
-# define YYCOPY(Dst, Src, Count) \
- do \
- { \
- YYSIZE_T yyi; \
- for (yyi = 0; yyi < (Count); yyi++) \
- (Dst)[yyi] = (Src)[yyi]; \
- } \
- while (0)
-# endif
-# endif
-#endif /* !YYCOPY_NEEDED */
-
-/* YYFINAL -- State number of the termination state. */
-#define YYFINAL 3
-/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 164
-
-/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS 58
-/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS 37
-/* YYNRULES -- Number of rules. */
-#define YYNRULES 110
-/* YYNSTATES -- Number of states. */
-#define YYNSTATES 144
-
-/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
- by yylex, with out-of-bounds checking. */
-#define YYUNDEFTOK 2
-#define YYMAXUTOK 312
-
-#define YYTRANSLATE(YYX) \
- ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-
-/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
- as returned by yylex, without out-of-bounds checking. */
-static const yytype_uint8 yytranslate[] =
-{
- 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
- 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
- 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
- 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
- 55, 56, 57
-};
-
-#if GRAM_DEBUG
- /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
-static const yytype_uint16 yyrline[] =
-{
- 0, 264, 264, 273, 274, 278, 279, 285, 289, 294,
- 295, 300, 306, 307, 308, 309, 314, 319, 320, 321,
- 322, 323, 324, 324, 325, 326, 350, 351, 352, 353,
- 357, 358, 367, 368, 369, 373, 385, 389, 393, 401,
- 412, 413, 423, 424, 428, 440, 440, 445, 445, 450,
- 461, 476, 477, 478, 479, 483, 484, 489, 491, 496,
- 501, 511, 513, 518, 519, 523, 524, 528, 529, 530,
- 535, 540, 545, 551, 557, 568, 569, 578, 579, 585,
- 586, 587, 594, 594, 602, 603, 604, 609, 612, 614,
- 616, 618, 620, 622, 624, 629, 630, 640, 641, 666,
- 667, 668, 669, 681, 683, 692, 697, 698, 703, 711,
- 712
-};
-#endif
-
-#if GRAM_DEBUG || YYERROR_VERBOSE || 1
-/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at YYNTOKENS, nonterminals. */
-static const char *const yytname[] =
-{
- "\"end of file\"", "error", "$undefined", "\"string\"", "\"%token\"",
- "\"%nterm\"", "\"%type\"", "\"%destructor\"", "\"%printer\"",
- "\"%left\"", "\"%right\"", "\"%nonassoc\"", "\"%precedence\"",
- "\"%prec\"", "\"%dprec\"", "\"%merge\"", "\"%code\"",
- "\"%default-prec\"", "\"%define\"", "\"%defines\"", "\"%error-verbose\"",
- "\"%expect\"", "\"%expect-rr\"", "\"%<flag>\"", "\"%file-prefix\"",
- "\"%glr-parser\"", "\"%initial-action\"", "\"%language\"",
- "\"%name-prefix\"", "\"%no-default-prec\"", "\"%no-lines\"",
- "\"%nondeterministic-parser\"", "\"%output\"", "\"%require\"",
- "\"%skeleton\"", "\"%start\"", "\"%token-table\"", "\"%verbose\"",
- "\"%yacc\"", "\"{...}\"", "\"%?{...}\"", "\"[identifier]\"", "\"char\"",
- "\"epilogue\"", "\"=\"", "\"identifier\"", "\"identifier:\"", "\"%%\"",
- "\"|\"", "\"%{...%}\"", "\";\"", "\"<tag>\"", "\"<*>\"", "\"<>\"",
- "\"integer\"", "\"%param\"", "\"%union\"", "\"%empty\"", "$accept",
- "input", "prologue_declarations", "prologue_declaration", "$@1",
- "params", "grammar_declaration", "code_props_type", "union_name",
- "symbol_declaration", "$@2", "$@3", "precedence_declaration",
- "precedence_declarator", "tag.opt", "symbols.prec", "symbol.prec",
- "symbols.1", "generic_symlist", "generic_symlist_item", "tag",
- "symbol_def", "symbol_defs.1", "grammar", "rules_or_grammar_declaration",
- "rules", "$@4", "rhses.1", "rhs", "named_ref.opt", "variable", "value",
- "id", "id_colon", "symbol", "string_as_id", "epilogue.opt", YY_NULL
-};
-#endif
-
-# ifdef YYPRINT
-/* YYTOKNUM[NUM] -- (External) token number corresponding to the
- (internal) symbol number NUM (which must be that of a token). */
-static const yytype_uint16 yytoknum[] =
-{
- 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
- 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
- 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
- 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
- 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
- 305, 306, 307, 308, 309, 310, 311, 312
-};
-# endif
-
-#define YYPACT_NINF -113
-
-#define yypact_value_is_default(Yystate) \
- (!!((Yystate) == (-113)))
-
-#define YYTABLE_NINF -110
-
-#define yytable_value_is_error(Yytable_value) \
- 0
-
- /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
- STATE-NUM. */
-static const yytype_int8 yypact[] =
-{
- -113, 16, 108, -113, -113, -113, -27, -113, -113, -113,
- -113, -113, -113, -24, -113, 23, 24, -113, -21, -15,
- -113, 29, -113, 3, 38, 42, -113, -113, -113, 44,
- 47, 71, 31, -113, -113, -113, 55, -113, -113, -113,
- 30, -113, -113, 39, -113, -113, 26, -22, -22, 31,
- -113, 48, -113, -113, 1, -113, -113, -113, -113, -113,
- -113, -113, -113, -113, -113, -113, -113, -113, -113, -113,
- -113, 45, -113, 50, 2, -113, -113, 57, 49, -113,
- 52, 41, -113, 31, -113, -113, -22, -2, -22, 31,
- -113, -113, -113, -113, -113, -113, -113, -113, 46, -113,
- -113, -113, -113, -113, 63, -113, -113, -113, -113, 41,
- -113, -113, -113, 31, -113, 51, -113, 100, -113, -113,
- -113, -113, -113, -113, -113, -113, -113, -20, 40, -113,
- -113, 31, 53, 58, 57, -113, -113, 57, 40, -113,
- -113, -113, -113, -113
-};
-
- /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
- Performed when YYTABLE does not specify something else to do. Zero
- means the default is an error. */
-static const yytype_uint8 yydefact[] =
-{
- 3, 0, 0, 1, 47, 45, 0, 40, 41, 51,
- 52, 53, 54, 0, 36, 0, 9, 11, 0, 0,
- 7, 0, 15, 0, 0, 0, 37, 19, 20, 0,
- 0, 0, 0, 26, 27, 28, 0, 6, 29, 22,
- 42, 4, 5, 0, 33, 32, 55, 0, 0, 0,
- 38, 0, 98, 97, 99, 10, 12, 13, 14, 16,
- 17, 18, 21, 24, 25, 108, 104, 103, 106, 34,
- 107, 0, 105, 0, 0, 77, 79, 95, 0, 43,
- 0, 0, 56, 0, 70, 75, 48, 71, 46, 49,
- 61, 39, 101, 102, 100, 8, 81, 80, 0, 78,
- 2, 96, 82, 31, 23, 44, 67, 68, 69, 35,
- 63, 66, 65, 50, 57, 59, 76, 72, 73, 62,
- 110, 87, 30, 64, 58, 60, 74, 83, 84, 87,
- 86, 0, 0, 0, 95, 90, 91, 95, 85, 92,
- 93, 94, 89, 88
-};
-
- /* YYPGOTO[NTERM-NUM]. */
-static const yytype_int8 yypgoto[] =
-{
- -113, -113, -113, -113, -113, -113, 102, -113, -113, -113,
- -113, -113, -113, -113, -113, -113, 8, -113, -113, 13,
- -113, -50, 75, -113, 73, -113, -113, -113, 19, -112,
- -113, -113, 22, -113, -32, -82, -113
-};
-
- /* YYDEFGOTO[NTERM-NUM]. */
-static const yytype_int16 yydefgoto[] =
-{
- -1, 1, 2, 41, 78, 104, 73, 43, 80, 44,
- 48, 47, 45, 46, 83, 113, 114, 89, 109, 110,
- 111, 85, 86, 74, 75, 76, 121, 127, 128, 102,
- 54, 95, 68, 77, 112, 70, 100
-};
-
- /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
- positive, shift that token. If negative, reduce the rule whose
- number is the opposite. If YYTABLE_NINF, syntax error. */
-static const yytype_int16 yytable[] =
-{
- 69, 65, -109, 71, 92, 118, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 50, 3, 90, 13, 14,
- 66, 51, 142, 67, 49, 143, 52, 55, 129, 84,
- 130, 26, 58, 56, 65, 126, 116, 32, 116, 57,
- 93, 60, 59, 65, 65, 61, 94, 62, 72, 98,
- 63, 115, 117, 131, 132, 133, 71, 119, 40, 4,
- 5, 6, 7, 8, 9, 10, 11, 12, 53, 87,
- 87, 13, 14, 66, 64, 79, 67, 82, 81, 134,
- 135, 115, 66, 66, 26, 67, 67, 91, 103, 120,
- 32, 105, 106, 107, 108, 96, 137, 136, 101, 139,
- 97, 72, 122, 65, 42, 125, 137, 140, 87, 141,
- 87, 40, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 124, 123, 88, 13, 14, 15, 16, 17, 18,
- 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
- 29, 30, 31, 32, 33, 34, 35, 99, 138, 0,
- 0, 0, 0, 0, 0, 36, 0, 37, 38, 0,
- 0, 0, 0, 39, 40
-};
-
-static const yytype_int16 yycheck[] =
-{
- 32, 3, 0, 1, 3, 87, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 39, 0, 49, 16, 17,
- 42, 45, 134, 45, 51, 137, 3, 3, 48, 51,
- 50, 29, 3, 54, 3, 117, 86, 35, 88, 54,
- 39, 3, 39, 3, 3, 3, 45, 3, 46, 47,
- 3, 83, 54, 13, 14, 15, 1, 89, 56, 4,
- 5, 6, 7, 8, 9, 10, 11, 12, 45, 47,
- 48, 16, 17, 42, 3, 45, 45, 51, 39, 39,
- 40, 113, 42, 42, 29, 45, 45, 39, 39, 43,
- 35, 39, 51, 52, 53, 50, 128, 57, 41, 131,
- 50, 46, 39, 3, 2, 54, 138, 54, 86, 51,
- 88, 56, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 113, 109, 48, 16, 17, 18, 19, 20, 21,
- 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 74, 129, -1,
- -1, -1, -1, -1, -1, 47, -1, 49, 50, -1,
- -1, -1, -1, 55, 56
-};
-
- /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
- symbol of state STATE-NUM. */
-static const yytype_uint8 yystos[] =
-{
- 0, 59, 60, 0, 4, 5, 6, 7, 8, 9,
- 10, 11, 12, 16, 17, 18, 19, 20, 21, 22,
- 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
- 33, 34, 35, 36, 37, 38, 47, 49, 50, 55,
- 56, 61, 64, 65, 67, 70, 71, 69, 68, 51,
- 39, 45, 3, 45, 88, 3, 54, 54, 3, 39,
- 3, 3, 3, 3, 3, 3, 42, 45, 90, 92,
- 93, 1, 46, 64, 81, 82, 83, 91, 62, 45,
- 66, 39, 51, 72, 51, 79, 80, 90, 80, 75,
- 92, 39, 3, 39, 45, 89, 50, 50, 47, 82,
- 94, 41, 87, 39, 63, 39, 51, 52, 53, 76,
- 77, 78, 92, 73, 74, 92, 79, 54, 93, 92,
- 43, 84, 39, 77, 74, 54, 93, 85, 86, 48,
- 50, 13, 14, 15, 39, 40, 57, 92, 86, 92,
- 54, 51, 87, 87
-};
-
- /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
-static const yytype_uint8 yyr1[] =
-{
- 0, 58, 59, 60, 60, 61, 61, 61, 61, 61,
- 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
- 61, 61, 62, 61, 61, 61, 61, 61, 61, 61,
- 63, 63, 64, 64, 64, 64, 64, 64, 64, 64,
- 65, 65, 66, 66, 64, 68, 67, 69, 67, 67,
- 70, 71, 71, 71, 71, 72, 72, 73, 73, 74,
- 74, 75, 75, 76, 76, 77, 77, 78, 78, 78,
- 79, 79, 79, 79, 79, 80, 80, 81, 81, 82,
- 82, 82, 84, 83, 85, 85, 85, 86, 86, 86,
- 86, 86, 86, 86, 86, 87, 87, 88, 88, 89,
- 89, 89, 89, 90, 90, 91, 92, 92, 93, 94,
- 94
-};
-
- /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
-static const yytype_uint8 yyr2[] =
-{
- 0, 2, 4, 0, 2, 1, 1, 1, 3, 1,
- 2, 1, 2, 2, 2, 1, 2, 2, 2, 1,
- 1, 2, 0, 3, 2, 2, 1, 1, 1, 1,
- 2, 1, 1, 1, 2, 3, 1, 1, 2, 3,
- 1, 1, 0, 1, 3, 0, 3, 0, 3, 3,
- 3, 1, 1, 1, 1, 0, 1, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 2, 2, 3, 1, 2, 1, 2, 1,
- 2, 2, 0, 4, 1, 3, 2, 0, 3, 3,
- 2, 2, 3, 3, 3, 0, 1, 1, 1, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
- 2
-};
-
-
-#define yyerrok (yyerrstatus = 0)
-#define yyclearin (yychar = YYEMPTY)
-#define YYEMPTY (-2)
-#define YYEOF 0
-
-#define YYACCEPT goto yyacceptlab
-#define YYABORT goto yyabortlab
-#define YYERROR goto yyerrorlab
-
-
-#define YYRECOVERING() (!!yyerrstatus)
-
-#define YYBACKUP(Token, Value) \
-do \
- if (yychar == YYEMPTY) \
- { \
- yychar = (Token); \
- yylval = (Value); \
- YYPOPSTACK (yylen); \
- yystate = *yyssp; \
- YY_LAC_DISCARD ("YYBACKUP"); \
- goto yybackup; \
- } \
- else \
- { \
- yyerror (&yylloc, YY_("syntax error: cannot back up")); \
- YYERROR; \
- } \
-while (0)
-
-/* Error token number */
-#define YYTERROR 1
-#define YYERRCODE 256
-
-
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (N) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
- while (0)
-#endif
-
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-
-
-/* Enable debugging if requested. */
-#if GRAM_DEBUG
-
-# ifndef YYFPRINTF
-# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
-# define YYFPRINTF fprintf
-# endif
-
-# define YYDPRINTF(Args) \
-do { \
- if (yydebug) \
- YYFPRINTF Args; \
-} while (0)
-
-
-/* YY_LOCATION_PRINT -- Print the location on the stream.
- This macro was not mandated originally: define only if we know
- we won't break user code: when these are the locations we know. */
-
-#ifndef YY_LOCATION_PRINT
-# if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
-
-/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
-
-__attribute__((__unused__))
-static unsigned
-yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
-{
- unsigned res = 0;
- int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
- if (0 <= yylocp->first_line)
- {
- res += YYFPRINTF (yyo, "%d", yylocp->first_line);
- if (0 <= yylocp->first_column)
- res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
- }
- if (0 <= yylocp->last_line)
- {
- if (yylocp->first_line < yylocp->last_line)
- {
- res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
- if (0 <= end_col)
- res += YYFPRINTF (yyo, ".%d", end_col);
- }
- else if (0 <= end_col && yylocp->first_column < end_col)
- res += YYFPRINTF (yyo, "-%d", end_col);
- }
- return res;
- }
-
-# define YY_LOCATION_PRINT(File, Loc) \
- yy_location_print_ (File, &(Loc))
-
-# else
-# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
-# endif
-#endif
-
-
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
-do { \
- if (yydebug) \
- { \
- YYFPRINTF (stderr, "%s ", Title); \
- yy_symbol_print (stderr, \
- Type, Value, Location); \
- YYFPRINTF (stderr, "\n"); \
- } \
-} while (0)
-
-
-/*----------------------------------------.
-| Print this symbol's value on YYOUTPUT. |
-`----------------------------------------*/
-
-static void
-yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
-{
- FILE *yyo = yyoutput;
- YYUSE (yyo);
- YYUSE (yylocationp);
- if (!yyvaluep)
- return;
-# ifdef YYPRINT
- if (yytype < YYNTOKENS)
- YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
-# endif
- switch (yytype)
- {
- case 3: /* "string" */
-#line 188 "src/parse-gram.y" /* yacc.c:684 */
- { fputs (quotearg_style (c_quoting_style, ((*yyvaluep).code)), yyo); }
-#line 987 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 23: /* "%<flag>" */
-#line 196 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%%%s", ((*yyvaluep).uniqstr)); }
-#line 993 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 39: /* "{...}" */
-#line 189 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
-#line 999 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 40: /* "%?{...}" */
-#line 189 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
-#line 1005 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 41: /* "[identifier]" */
-#line 194 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "[%s]", ((*yyvaluep).uniqstr)); }
-#line 1011 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 42: /* "char" */
-#line 184 "src/parse-gram.y" /* yacc.c:684 */
- { fputs (char_name (((*yyvaluep).character)), yyo); }
-#line 1017 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 43: /* "epilogue" */
-#line 189 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
-#line 1023 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 45: /* "identifier" */
-#line 193 "src/parse-gram.y" /* yacc.c:684 */
- { fputs (((*yyvaluep).uniqstr), yyo); }
-#line 1029 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 46: /* "identifier:" */
-#line 195 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%s:", ((*yyvaluep).uniqstr)); }
-#line 1035 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 49: /* "%{...%}" */
-#line 189 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
-#line 1041 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 51: /* "<tag>" */
-#line 197 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "<%s>", ((*yyvaluep).uniqstr)); }
-#line 1047 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 54: /* "integer" */
-#line 201 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%d", ((*yyvaluep).integer)); }
-#line 1053 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 55: /* "%param" */
-#line 244 "src/parse-gram.y" /* yacc.c:684 */
- {
- switch (((*yyvaluep).param))
- {
-#define CASE(In, Out) \
- case param_ ## In: fputs ("%" #Out, yyo); break
- CASE (lex, lex-param);
- CASE (parse, parse-param);
- CASE (both, param);
-#undef CASE
- case param_none: aver (false); break;
- }
-}
-#line 1070 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 65: /* code_props_type */
-#line 410 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%s", code_props_type_string (((*yyvaluep).code_type))); }
-#line 1076 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 74: /* symbol.prec */
-#line 205 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
-#line 1082 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 78: /* tag */
-#line 197 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "<%s>", ((*yyvaluep).uniqstr)); }
-#line 1088 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 88: /* variable */
-#line 193 "src/parse-gram.y" /* yacc.c:684 */
- { fputs (((*yyvaluep).uniqstr), yyo); }
-#line 1094 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 89: /* value */
-#line 656 "src/parse-gram.y" /* yacc.c:684 */
- {
- switch (((*yyvaluep).value).kind)
- {
- case muscle_code: fprintf (yyo, "{%s}", ((*yyvaluep).value).chars); break;
- case muscle_keyword: fprintf (yyo, "%s", ((*yyvaluep).value).chars); break;
- case muscle_string: fprintf (yyo, "\"%s\"", ((*yyvaluep).value).chars); break;
- }
-}
-#line 1107 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 90: /* id */
-#line 205 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
-#line 1113 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 91: /* id_colon */
-#line 206 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%s:", ((*yyvaluep).symbol)->tag); }
-#line 1119 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 92: /* symbol */
-#line 205 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
-#line 1125 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
- case 93: /* string_as_id */
-#line 205 "src/parse-gram.y" /* yacc.c:684 */
- { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
-#line 1131 "src/parse-gram.c" /* yacc.c:684 */
- break;
-
-
- default:
- break;
- }
-}
-
-
-/*--------------------------------.
-| Print this symbol on YYOUTPUT. |
-`--------------------------------*/
-
-static void
-yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
-{
- YYFPRINTF (yyoutput, "%s %s (",
- yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
-
- YY_LOCATION_PRINT (yyoutput, *yylocationp);
- YYFPRINTF (yyoutput, ": ");
- yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
- YYFPRINTF (yyoutput, ")");
-}
-
-/*------------------------------------------------------------------.
-| yy_stack_print -- Print the state stack from its BOTTOM up to its |
-| TOP (included). |
-`------------------------------------------------------------------*/
-
-static void
-yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
-{
- YYFPRINTF (stderr, "Stack now");
- for (; yybottom <= yytop; yybottom++)
- {
- int yybot = *yybottom;
- YYFPRINTF (stderr, " %d", yybot);
- }
- YYFPRINTF (stderr, "\n");
-}
-
-# define YY_STACK_PRINT(Bottom, Top) \
-do { \
- if (yydebug) \
- yy_stack_print ((Bottom), (Top)); \
-} while (0)
-
-
-/*------------------------------------------------.
-| Report that the YYRULE is going to be reduced. |
-`------------------------------------------------*/
-
-static void
-yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
-{
- unsigned long int yylno = yyrline[yyrule];
- int yynrhs = yyr2[yyrule];
- int yyi;
- YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
- yyrule - 1, yylno);
- /* The symbols being reduced. */
- for (yyi = 0; yyi < yynrhs; yyi++)
- {
- YYFPRINTF (stderr, " $%d = ", yyi + 1);
- yy_symbol_print (stderr,
- yystos[yyssp[yyi + 1 - yynrhs]],
- &(yyvsp[(yyi + 1) - (yynrhs)])
- , &(yylsp[(yyi + 1) - (yynrhs)]) );
- YYFPRINTF (stderr, "\n");
- }
-}
-
-# define YY_REDUCE_PRINT(Rule) \
-do { \
- if (yydebug) \
- yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
-} while (0)
-
-/* Nonzero means print parse trace. It is left uninitialized so that
- multiple parsers can coexist. */
-int yydebug;
-#else /* !GRAM_DEBUG */
-# define YYDPRINTF(Args)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
-# define YY_STACK_PRINT(Bottom, Top)
-# define YY_REDUCE_PRINT(Rule)
-#endif /* !GRAM_DEBUG */
-
-
-/* YYINITDEPTH -- initial size of the parser's stacks. */
-#ifndef YYINITDEPTH
-# define YYINITDEPTH 200
-#endif
-
-/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
- if the built-in stack extension method is used).
-
- Do not make this value too large; the results are undefined if
- YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
- evaluated with infinite-precision integer arithmetic. */
-
-#ifndef YYMAXDEPTH
-# define YYMAXDEPTH 10000
-#endif
-
-/* Given a state stack such that *YYBOTTOM is its bottom, such that
- *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty
- stack, and such that *YYCAPACITY is the maximum number of elements it
- can hold without a reallocation, make sure there is enough room to
- store YYADD more elements. If not, allocate a new stack using
- YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM,
- *YYTOP, and *YYCAPACITY to reflect the new capacity and memory
- location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack
- using YYSTACK_FREE. Return 0 if successful or if no reallocation is
- required. Return 1 if memory is exhausted. */
-static int
-yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
-#if GRAM_DEBUG
- char const *yydebug_prefix,
- char const *yydebug_suffix,
-#endif
- yytype_int16 **yybottom,
- yytype_int16 *yybottom_no_free,
- yytype_int16 **yytop, yytype_int16 *yytop_empty)
-{
- YYSIZE_T yysize_old =
- *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
- YYSIZE_T yysize_new = yysize_old + yyadd;
- if (*yycapacity < yysize_new)
- {
- YYSIZE_T yyalloc = 2 * yysize_new;
- yytype_int16 *yybottom_new;
- /* Use YYMAXDEPTH for maximum stack size given that the stack
- should never need to grow larger than the main state stack
- needs to grow without LAC. */
- if (YYMAXDEPTH < yysize_new)
- {
- YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix,
- yydebug_suffix));
- return 1;
- }
- if (YYMAXDEPTH < yyalloc)
- yyalloc = YYMAXDEPTH;
- yybottom_new =
- (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new);
- if (!yybottom_new)
- {
- YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
- yydebug_suffix));
- return 1;
- }
- if (*yytop != yytop_empty)
- {
- YYCOPY (yybottom_new, *yybottom, yysize_old);
- *yytop = yybottom_new + (yysize_old - 1);
- }
- if (*yybottom != yybottom_no_free)
- YYSTACK_FREE (*yybottom);
- *yybottom = yybottom_new;
- *yycapacity = yyalloc;
- }
- return 0;
-}
-
-/* Establish the initial context for the current lookahead if no initial
- context is currently established.
-
- We define a context as a snapshot of the parser stacks. We define
- the initial context for a lookahead as the context in which the
- parser initially examines that lookahead in order to select a
- syntactic action. Thus, if the lookahead eventually proves
- syntactically unacceptable (possibly in a later context reached via a
- series of reductions), the initial context can be used to determine
- the exact set of tokens that would be syntactically acceptable in the
- lookahead's place. Moreover, it is the context after which any
- further semantic actions would be erroneous because they would be
- determined by a syntactically unacceptable token.
-
- YY_LAC_ESTABLISH should be invoked when a reduction is about to be
- performed in an inconsistent state (which, for the purposes of LAC,
- includes consistent states that don't know they're consistent because
- their default reductions have been disabled). Iff there is a
- lookahead token, it should also be invoked before reporting a syntax
- error. This latter case is for the sake of the debugging output.
-
- For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as
- follows. If no initial context is currently established for the
- current lookahead, then check if that lookahead can eventually be
- shifted if syntactic actions continue from the current context.
- Report a syntax error if it cannot. */
-#define YY_LAC_ESTABLISH \
-do { \
- if (!yy_lac_established) \
- { \
- YYDPRINTF ((stderr, \
- "LAC: initial context established for %s\n", \
- yytname[yytoken])); \
- yy_lac_established = 1; \
- { \
- int yy_lac_status = \
- yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken); \
- if (yy_lac_status == 2) \
- goto yyexhaustedlab; \
- if (yy_lac_status == 1) \
- goto yyerrlab; \
- } \
- } \
-} while (0)
-
-/* Discard any previous initial lookahead context because of Event,
- which may be a lookahead change or an invalidation of the currently
- established initial context for the current lookahead.
-
- The most common example of a lookahead change is a shift. An example
- of both cases is syntax error recovery. That is, a syntax error
- occurs when the lookahead is syntactically erroneous for the
- currently established initial context, so error recovery manipulates
- the parser stacks to try to find a new initial context in which the
- current lookahead is syntactically acceptable. If it fails to find
- such a context, it discards the lookahead. */
-#if GRAM_DEBUG
-# define YY_LAC_DISCARD(Event) \
-do { \
- if (yy_lac_established) \
- { \
- if (yydebug) \
- YYFPRINTF (stderr, "LAC: initial context discarded due to " \
- Event "\n"); \
- yy_lac_established = 0; \
- } \
-} while (0)
-#else
-# define YY_LAC_DISCARD(Event) yy_lac_established = 0
-#endif
-
-/* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can
- eventually (after perhaps some reductions) be shifted, return 1 if
- not, or return 2 if memory is exhausted. As preconditions and
- postconditions: *YYES_CAPACITY is the allocated size of the array to
- which *YYES points, and either *YYES = YYESA or *YYES points to an
- array allocated with YYSTACK_ALLOC. yy_lac may overwrite the
- contents of either array, alter *YYES and *YYES_CAPACITY, and free
- any old *YYES other than YYESA. */
-static int
-yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
- YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
-{
- yytype_int16 *yyes_prev = yyssp;
- yytype_int16 *yyesp = yyes_prev;
- YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken]));
- if (yytoken == YYUNDEFTOK)
- {
- YYDPRINTF ((stderr, " Always Err\n"));
- return 1;
- }
- while (1)
- {
- int yyrule = yypact[*yyesp];
- if (yypact_value_is_default (yyrule)
- || (yyrule += yytoken) < 0 || YYLAST < yyrule
- || yycheck[yyrule] != yytoken)
- {
- yyrule = yydefact[*yyesp];
- if (yyrule == 0)
- {
- YYDPRINTF ((stderr, " Err\n"));
- return 1;
- }
- }
- else
- {
- yyrule = yytable[yyrule];
- if (yytable_value_is_error (yyrule))
- {
- YYDPRINTF ((stderr, " Err\n"));
- return 1;
- }
- if (0 < yyrule)
- {
- YYDPRINTF ((stderr, " S%d\n", yyrule));
- return 0;
- }
- yyrule = -yyrule;
- }
- {
- YYSIZE_T yylen = yyr2[yyrule];
- YYDPRINTF ((stderr, " R%d", yyrule - 1));
- if (yyesp != yyes_prev)
- {
- YYSIZE_T yysize = yyesp - *yyes + 1;
- if (yylen < yysize)
- {
- yyesp -= yylen;
- yylen = 0;
- }
- else
- {
- yylen -= yysize;
- yyesp = yyes_prev;
- }
- }
- if (yylen)
- yyesp = yyes_prev -= yylen;
- }
- {
- int yystate;
- {
- int yylhs = yyr1[yyrule] - YYNTOKENS;
- yystate = yypgoto[yylhs] + *yyesp;
- if (yystate < 0 || YYLAST < yystate
- || yycheck[yystate] != *yyesp)
- yystate = yydefgoto[yylhs];
- else
- yystate = yytable[yystate];
- }
- if (yyesp == yyes_prev)
- {
- yyesp = *yyes;
- *yyesp = yystate;
- }
- else
- {
- if (yy_lac_stack_realloc (yyes_capacity, 1,
-#if GRAM_DEBUG
- " (", ")",
-#endif
- yyes, yyesa, &yyesp, yyes_prev))
- {
- YYDPRINTF ((stderr, "\n"));
- return 2;
- }
- *++yyesp = yystate;
- }
- YYDPRINTF ((stderr, " G%d", yystate));
- }
- }
-}
-
-
-#if YYERROR_VERBOSE
-
-# ifndef yystrlen
-# if defined __GLIBC__ && defined _STRING_H
-# define yystrlen strlen
-# else
-/* Return the length of YYSTR. */
-static YYSIZE_T
-yystrlen (const char *yystr)
-{
- YYSIZE_T yylen;
- for (yylen = 0; yystr[yylen]; yylen++)
- continue;
- return yylen;
-}
-# endif
-# endif
-
-# ifndef yystpcpy
-# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
-# define yystpcpy stpcpy
-# else
-/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
- YYDEST. */
-static char *
-yystpcpy (char *yydest, const char *yysrc)
-{
- char *yyd = yydest;
- const char *yys = yysrc;
-
- while ((*yyd++ = *yys++) != '\0')
- continue;
-
- return yyd - 1;
-}
-# endif
-# endif
-
-# ifndef yytnamerr
-/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
- quotes and backslashes, so that it's suitable for yyerror. The
- heuristic is that double-quoting is unnecessary unless the string
- contains an apostrophe, a comma, or backslash (other than
- backslash-backslash). YYSTR is taken from yytname. If YYRES is
- null, do not copy; instead, return the length of what the result
- would have been. */
-static YYSIZE_T
-yytnamerr (char *yyres, const char *yystr)
-{
- if (*yystr == '"')
- {
- YYSIZE_T yyn = 0;
- char const *yyp = yystr;
-
- for (;;)
- switch (*++yyp)
- {
- case '\'':
- case ',':
- goto do_not_strip_quotes;
-
- case '\\':
- if (*++yyp != '\\')
- goto do_not_strip_quotes;
- /* Fall through. */
- default:
- if (yyres)
- yyres[yyn] = *yyp;
- yyn++;
- break;
-
- case '"':
- if (yyres)
- yyres[yyn] = '\0';
- return yyn;
- }
- do_not_strip_quotes: ;
- }
-
- if (! yyres)
- return yystrlen (yystr);
-
- return yystpcpy (yyres, yystr) - yyres;
-}
-# endif
-
-/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
- about the unexpected token YYTOKEN for the state stack whose top is
- YYSSP. In order to see if a particular token T is a
- valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).
-
- Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
- not large enough to hold the message. In that case, also set
- *YYMSG_ALLOC to the required number of bytes. Return 2 if the
- required number of bytes is too large to store or if
- yy_lac returned 2. */
-static int
-yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
- yytype_int16 *yyesa, yytype_int16 **yyes,
- YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
-{
- YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
- YYSIZE_T yysize = yysize0;
- enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
- /* Internationalized format string. */
- const char *yyformat = YY_NULL;
- /* Arguments of yyformat. */
- char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
- /* Number of reported tokens (one for the "unexpected", one per
- "expected"). */
- int yycount = 0;
-
- /* There are many possibilities here to consider:
- - If this state is a consistent state with a default action, then
- the only way this function was invoked is if the default action
- is an error action. In that case, don't check for expected
- tokens because there are none.
- - The only way there can be no lookahead present (in yychar) is if
- this state is a consistent state with a default action. Thus,
- detecting the absence of a lookahead is sufficient to determine
- that there is no unexpected or expected token to report. In that
- case, just report a simple "syntax error".
- - Don't assume there isn't a lookahead just because this state is a
- consistent state with a default action. There might have been a
- previous inconsistent state, consistent state with a non-default
- action, or user semantic action that manipulated yychar.
- In the first two cases, it might appear that the current syntax
- error should have been detected in the previous state when yy_lac
- was invoked. However, at that time, there might have been a
- different syntax error that discarded a different initial context
- during error recovery, leaving behind the current lookahead.
- */
- if (yytoken != YYEMPTY)
- {
- int yyn = yypact[*yyssp];
- YYDPRINTF ((stderr, "Constructing syntax error message\n"));
- yyarg[yycount++] = yytname[yytoken];
- if (!yypact_value_is_default (yyn))
- {
- int yyx;
-
- for (yyx = 0; yyx < YYNTOKENS; ++yyx)
- if (yyx != YYTERROR && yyx != YYUNDEFTOK)
- {
- {
- int yy_lac_status = yy_lac (yyesa, yyes, yyes_capacity,
- yyssp, yyx);
- if (yy_lac_status == 2)
- return 2;
- if (yy_lac_status == 1)
- continue;
- }
- if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
- {
- yycount = 1;
- yysize = yysize0;
- break;
- }
- yyarg[yycount++] = yytname[yyx];
- {
- YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
- if (! (yysize <= yysize1
- && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
- }
- }
- }
-# if GRAM_DEBUG
- else if (yydebug)
- YYFPRINTF (stderr, "No expected tokens.\n");
-# endif
- }
-
- switch (yycount)
- {
-# define YYCASE_(N, S) \
- case N: \
- yyformat = S; \
- break
- YYCASE_(0, YY_("syntax error"));
- YYCASE_(1, YY_("syntax error, unexpected %s"));
- YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
- YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
- YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
- YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
-# undef YYCASE_
- }
-
- {
- YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
- if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
- }
-
- if (*yymsg_alloc < yysize)
- {
- *yymsg_alloc = 2 * yysize;
- if (! (yysize <= *yymsg_alloc
- && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
- *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
- return 1;
- }
-
- /* Avoid sprintf, as that infringes on the user's name space.
- Don't have undefined behavior even if the translation
- produced a string with the wrong number of "%s"s. */
- {
- char *yyp = *yymsg;
- int yyi = 0;
- while ((*yyp = *yyformat) != '\0')
- if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
- {
- yyp += yytnamerr (yyp, yyarg[yyi++]);
- yyformat += 2;
- }
- else
- {
- yyp++;
- yyformat++;
- }
- }
- return 0;
-}
-#endif /* YYERROR_VERBOSE */
-
-/*-----------------------------------------------.
-| Release the memory associated to this symbol. |
-`-----------------------------------------------*/
-
-static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
-{
- YYUSE (yyvaluep);
- YYUSE (yylocationp);
- if (!yymsg)
- yymsg = "Deleting";
- YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
-
- YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
- YYUSE (yytype);
- YY_IGNORE_MAYBE_UNINITIALIZED_END
-}
-
-
-
-
-/*----------.
-| yyparse. |
-`----------*/
-
-int
-yyparse (void)
-{
-/* The lookahead symbol. */
-int yychar;
-
-
-/* The semantic value of the lookahead symbol. */
-/* Default value used for initialization, for pacifying older GCCs
- or non-GCC compilers. */
-YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
-YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
-
-/* Location data for the lookahead symbol. */
-static YYLTYPE yyloc_default
-# if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
- = { 1, 1, 1, 1 }
-# endif
-;
-YYLTYPE yylloc = yyloc_default;
-
- /* Number of syntax errors so far. */
- int yynerrs;
-
- int yystate;
- /* Number of tokens to shift before error messages enabled. */
- int yyerrstatus;
-
- /* The stacks and their tools:
- 'yyss': related to states.
- 'yyvs': related to semantic values.
- 'yyls': related to locations.
-
- Refer to the stacks through separate pointers, to allow yyoverflow
- to reallocate them elsewhere. */
-
- /* The state stack. */
- yytype_int16 yyssa[YYINITDEPTH];
- yytype_int16 *yyss;
- yytype_int16 *yyssp;
-
- /* The semantic value stack. */
- YYSTYPE yyvsa[YYINITDEPTH];
- YYSTYPE *yyvs;
- YYSTYPE *yyvsp;
-
- /* The location stack. */
- YYLTYPE yylsa[YYINITDEPTH];
- YYLTYPE *yyls;
- YYLTYPE *yylsp;
-
- /* The locations where the error started and ended. */
- YYLTYPE yyerror_range[3];
-
- YYSIZE_T yystacksize;
-
- yytype_int16 yyesa[20];
- yytype_int16 *yyes;
- YYSIZE_T yyes_capacity;
-
- int yy_lac_established = 0;
- int yyn;
- int yyresult;
- /* Lookahead token as an internal (translated) token number. */
- int yytoken = 0;
- /* The variables used to return semantic value and location from the
- action routines. */
- YYSTYPE yyval;
- YYLTYPE yyloc;
-
-#if YYERROR_VERBOSE
- /* Buffer for error messages, and its allocated size. */
- char yymsgbuf[128];
- char *yymsg = yymsgbuf;
- YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
-#endif
-
-#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
-
- /* The number of symbols on the RHS of the reduced rule.
- Keep to zero when no symbol should be popped. */
- int yylen = 0;
-
- yyssp = yyss = yyssa;
- yyvsp = yyvs = yyvsa;
- yylsp = yyls = yylsa;
- yystacksize = YYINITDEPTH;
-
- yyes = yyesa;
- yyes_capacity = sizeof yyesa / sizeof *yyes;
- if (YYMAXDEPTH < yyes_capacity)
- yyes_capacity = YYMAXDEPTH;
-
- YYDPRINTF ((stderr, "Starting parse\n"));
-
- yystate = 0;
- yyerrstatus = 0;
- yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
-
-/* User initialization code. */
-#line 108 "src/parse-gram.y" /* yacc.c:1429 */
-{
- /* Bison's grammar can initial empty locations, hence a default
- location is needed. */
- boundary_set (&yylloc.start, current_file, 1, 1);
- boundary_set (&yylloc.end, current_file, 1, 1);
-}
-
-#line 1833 "src/parse-gram.c" /* yacc.c:1429 */
- yylsp[0] = yylloc;
- goto yysetstate;
-
-/*------------------------------------------------------------.
-| yynewstate -- Push a new state, which is found in yystate. |
-`------------------------------------------------------------*/
- yynewstate:
- /* In all cases, when you get here, the value and location stacks
- have just been pushed. So pushing a state here evens the stacks. */
- yyssp++;
-
- yysetstate:
- *yyssp = yystate;
-
- if (yyss + yystacksize - 1 <= yyssp)
- {
- /* Get the current used size of the three stacks, in elements. */
- YYSIZE_T yysize = yyssp - yyss + 1;
-
-#ifdef yyoverflow
- {
- /* Give user a chance to reallocate the stack. Use copies of
- these so that the &'s don't force the real ones into
- memory. */
- YYSTYPE *yyvs1 = yyvs;
- yytype_int16 *yyss1 = yyss;
- YYLTYPE *yyls1 = yyls;
-
- /* Each stack pointer address is followed by the size of the
- data in use in that stack, in bytes. This used to be a
- conditional around just the two extra args, but that might
- be undefined if yyoverflow is a macro. */
- yyoverflow (YY_("memory exhausted"),
- &yyss1, yysize * sizeof (*yyssp),
- &yyvs1, yysize * sizeof (*yyvsp),
- &yyls1, yysize * sizeof (*yylsp),
- &yystacksize);
-
- yyls = yyls1;
- yyss = yyss1;
- yyvs = yyvs1;
- }
-#else /* no yyoverflow */
-# ifndef YYSTACK_RELOCATE
- goto yyexhaustedlab;
-# else
- /* Extend the stack our own way. */
- if (YYMAXDEPTH <= yystacksize)
- goto yyexhaustedlab;
- yystacksize *= 2;
- if (YYMAXDEPTH < yystacksize)
- yystacksize = YYMAXDEPTH;
-
- {
- yytype_int16 *yyss1 = yyss;
- union yyalloc *yyptr =
- (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
- if (! yyptr)
- goto yyexhaustedlab;
- YYSTACK_RELOCATE (yyss_alloc, yyss);
- YYSTACK_RELOCATE (yyvs_alloc, yyvs);
- YYSTACK_RELOCATE (yyls_alloc, yyls);
-# undef YYSTACK_RELOCATE
- if (yyss1 != yyssa)
- YYSTACK_FREE (yyss1);
- }
-# endif
-#endif /* no yyoverflow */
-
- yyssp = yyss + yysize - 1;
- yyvsp = yyvs + yysize - 1;
- yylsp = yyls + yysize - 1;
-
- YYDPRINTF ((stderr, "Stack size increased to %lu\n",
- (unsigned long int) yystacksize));
-
- if (yyss + yystacksize - 1 <= yyssp)
- YYABORT;
- }
-
- YYDPRINTF ((stderr, "Entering state %d\n", yystate));
-
- if (yystate == YYFINAL)
- YYACCEPT;
-
- goto yybackup;
-
-/*-----------.
-| yybackup. |
-`-----------*/
-yybackup:
-
- /* Do appropriate processing given the current state. Read a
- lookahead token if we need one and don't already have one. */
-
- /* First try to decide what to do without reference to lookahead token. */
- yyn = yypact[yystate];
- if (yypact_value_is_default (yyn))
- goto yydefault;
-
- /* Not known => get a lookahead token if don't already have one. */
-
- /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
- if (yychar == YYEMPTY)
- {
- YYDPRINTF ((stderr, "Reading a token: "));
- yychar = yylex (&yylval, &yylloc);
- }
-
- if (yychar <= YYEOF)
- {
- yychar = yytoken = YYEOF;
- YYDPRINTF ((stderr, "Now at end of input.\n"));
- }
- else
- {
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
- }
-
- /* If the proper action on seeing token YYTOKEN is to reduce or to
- detect an error, take that action. */
- yyn += yytoken;
- if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
- {
- YY_LAC_ESTABLISH;
- goto yydefault;
- }
- yyn = yytable[yyn];
- if (yyn <= 0)
- {
- if (yytable_value_is_error (yyn))
- goto yyerrlab;
- YY_LAC_ESTABLISH;
- yyn = -yyn;
- goto yyreduce;
- }
-
- /* Count tokens shifted since error; after three, turn off error
- status. */
- if (yyerrstatus)
- yyerrstatus--;
-
- /* Shift the lookahead token. */
- YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
-
- /* Discard the shifted token. */
- yychar = YYEMPTY;
- YY_LAC_DISCARD ("shift");
-
- yystate = yyn;
- YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
- *++yyvsp = yylval;
- YY_IGNORE_MAYBE_UNINITIALIZED_END
- *++yylsp = yylloc;
- goto yynewstate;
-
-
-/*-----------------------------------------------------------.
-| yydefault -- do the default action for the current state. |
-`-----------------------------------------------------------*/
-yydefault:
- yyn = yydefact[yystate];
- if (yyn == 0)
- goto yyerrlab;
- goto yyreduce;
-
-
-/*-----------------------------.
-| yyreduce -- Do a reduction. |
-`-----------------------------*/
-yyreduce:
- /* yyn is the number of a rule to reduce with. */
- yylen = yyr2[yyn];
-
- /* If YYLEN is nonzero, implement the default value of the action:
- '$$ = $1'.
-
- Otherwise, the following line sets YYVAL to garbage.
- This behavior is undocumented and Bison
- users should not rely upon it. Assigning to YYVAL
- unconditionally makes the parser a bit smaller, and it avoids a
- GCC warning that YYVAL may be used uninitialized. */
- yyval = yyvsp[1-yylen];
-
- /* Default location. */
- YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
- YY_REDUCE_PRINT (yyn);
- {
- int yychar_backup = yychar;
- switch (yyn)
- {
- case 6:
-#line 280 "src/parse-gram.y" /* yacc.c:1646 */
- {
- muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
- translate_code ((yyvsp[0].code), (yylsp[0]), true), (yylsp[0]));
- code_scanner_last_string_free ();
- }
-#line 2033 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 7:
-#line 286 "src/parse-gram.y" /* yacc.c:1646 */
- {
- muscle_percent_define_ensure ((yyvsp[0].uniqstr), (yylsp[0]), true);
- }
-#line 2041 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 8:
-#line 290 "src/parse-gram.y" /* yacc.c:1646 */
- {
- muscle_percent_define_insert ((yyvsp[-1].uniqstr), (yylsp[-1]), (yyvsp[0].value).kind, (yyvsp[0].value).chars,
- MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
- }
-#line 2050 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 9:
-#line 294 "src/parse-gram.y" /* yacc.c:1646 */
- { defines_flag = true; }
-#line 2056 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 10:
-#line 296 "src/parse-gram.y" /* yacc.c:1646 */
- {
- defines_flag = true;
- spec_defines_file = xstrdup ((yyvsp[0].code));
- }
-#line 2065 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 11:
-#line 301 "src/parse-gram.y" /* yacc.c:1646 */
- {
- muscle_percent_define_insert ("parse.error", (yylsp[0]), muscle_keyword,
- "verbose",
- MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
- }
-#line 2075 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 12:
-#line 306 "src/parse-gram.y" /* yacc.c:1646 */
- { expected_sr_conflicts = (yyvsp[0].integer); }
-#line 2081 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 13:
-#line 307 "src/parse-gram.y" /* yacc.c:1646 */
- { expected_rr_conflicts = (yyvsp[0].integer); }
-#line 2087 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 14:
-#line 308 "src/parse-gram.y" /* yacc.c:1646 */
- { spec_file_prefix = (yyvsp[0].code); }
-#line 2093 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 15:
-#line 310 "src/parse-gram.y" /* yacc.c:1646 */
- {
- nondeterministic_parser = true;
- glr_parser = true;
- }
-#line 2102 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 16:
-#line 315 "src/parse-gram.y" /* yacc.c:1646 */
- {
- muscle_code_grow ("initial_action", translate_code ((yyvsp[0].code), (yylsp[0]), false), (yylsp[0]));
- code_scanner_last_string_free ();
- }
-#line 2111 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 17:
-#line 319 "src/parse-gram.y" /* yacc.c:1646 */
- { language_argmatch ((yyvsp[0].code), grammar_prio, (yylsp[-1])); }
-#line 2117 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 18:
-#line 320 "src/parse-gram.y" /* yacc.c:1646 */
- { spec_name_prefix = (yyvsp[0].code); }
-#line 2123 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 19:
-#line 321 "src/parse-gram.y" /* yacc.c:1646 */
- { no_lines_flag = true; }
-#line 2129 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 20:
-#line 322 "src/parse-gram.y" /* yacc.c:1646 */
- { nondeterministic_parser = true; }
-#line 2135 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 21:
-#line 323 "src/parse-gram.y" /* yacc.c:1646 */
- { spec_outfile = (yyvsp[0].code); }
-#line 2141 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 22:
-#line 324 "src/parse-gram.y" /* yacc.c:1646 */
- { current_param = (yyvsp[0].param); }
-#line 2147 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 23:
-#line 324 "src/parse-gram.y" /* yacc.c:1646 */
- { current_param = param_none; }
-#line 2153 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 24:
-#line 325 "src/parse-gram.y" /* yacc.c:1646 */
- { version_check (&(yylsp[0]), (yyvsp[0].code)); }
-#line 2159 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 25:
-#line 327 "src/parse-gram.y" /* yacc.c:1646 */
- {
- char const *skeleton_user = (yyvsp[0].code);
- if (strchr (skeleton_user, '/'))
- {
- size_t dir_length = strlen (current_file);
- char *skeleton_build;
- while (dir_length && current_file[dir_length - 1] != '/')
- --dir_length;
- while (dir_length && current_file[dir_length - 1] == '/')
- --dir_length;
- skeleton_build =
- xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
- if (dir_length > 0)
- {
- memcpy (skeleton_build, current_file, dir_length);
- skeleton_build[dir_length++] = '/';
- }
- strcpy (skeleton_build + dir_length, skeleton_user);
- skeleton_user = uniqstr_new (skeleton_build);
- free (skeleton_build);
- }
- skeleton_arg (skeleton_user, grammar_prio, (yylsp[-1]));
- }
-#line 2187 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 26:
-#line 350 "src/parse-gram.y" /* yacc.c:1646 */
- { token_table_flag = true; }
-#line 2193 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 27:
-#line 351 "src/parse-gram.y" /* yacc.c:1646 */
- { report_flag |= report_states; }
-#line 2199 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 28:
-#line 352 "src/parse-gram.y" /* yacc.c:1646 */
- { yacc_flag = true; }
-#line 2205 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 30:
-#line 357 "src/parse-gram.y" /* yacc.c:1646 */
- { add_param (current_param, (yyvsp[0].code), (yylsp[0])); }
-#line 2211 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 31:
-#line 358 "src/parse-gram.y" /* yacc.c:1646 */
- { add_param (current_param, (yyvsp[0].code), (yylsp[0])); }
-#line 2217 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 34:
-#line 370 "src/parse-gram.y" /* yacc.c:1646 */
- {
- grammar_start_symbol_set ((yyvsp[0].symbol), (yylsp[0]));
- }
-#line 2225 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 35:
-#line 374 "src/parse-gram.y" /* yacc.c:1646 */
- {
- code_props code;
- code_props_symbol_action_init (&code, (yyvsp[-1].code), (yylsp[-1]));
- code_props_translate_code (&code);
- {
- symbol_list *list;
- for (list = (yyvsp[0].list); list; list = list->next)
- symbol_list_code_props_set (list, (yyvsp[-2].code_type), &code);
- symbol_list_free ((yyvsp[0].list));
- }
- }
-#line 2241 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 36:
-#line 386 "src/parse-gram.y" /* yacc.c:1646 */
- {
- default_prec = true;
- }
-#line 2249 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 37:
-#line 390 "src/parse-gram.y" /* yacc.c:1646 */
- {
- default_prec = false;
- }
-#line 2257 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 38:
-#line 394 "src/parse-gram.y" /* yacc.c:1646 */
- {
- /* Do not invoke muscle_percent_code_grow here since it invokes
- muscle_user_name_list_grow. */
- muscle_code_grow ("percent_code()",
- translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
- code_scanner_last_string_free ();
- }
-#line 2269 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 39:
-#line 402 "src/parse-gram.y" /* yacc.c:1646 */
- {
- muscle_percent_code_grow ((yyvsp[-1].uniqstr), (yylsp[-1]), translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
- code_scanner_last_string_free ();
- }
-#line 2278 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 40:
-#line 412 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.code_type) = destructor; }
-#line 2284 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 41:
-#line 413 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.code_type) = printer; }
-#line 2290 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 42:
-#line 423 "src/parse-gram.y" /* yacc.c:1646 */
- {}
-#line 2296 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 43:
-#line 424 "src/parse-gram.y" /* yacc.c:1646 */
- { muscle_code_grow ("union_name", (yyvsp[0].uniqstr), (yylsp[0])); }
-#line 2302 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 44:
-#line 429 "src/parse-gram.y" /* yacc.c:1646 */
- {
- union_seen = true;
- muscle_code_grow ("union_members", translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
- code_scanner_last_string_free ();
- }
-#line 2312 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 45:
-#line 440 "src/parse-gram.y" /* yacc.c:1646 */
- { current_class = nterm_sym; }
-#line 2318 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 46:
-#line 441 "src/parse-gram.y" /* yacc.c:1646 */
- {
- current_class = unknown_sym;
- current_type = NULL;
- }
-#line 2327 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 47:
-#line 445 "src/parse-gram.y" /* yacc.c:1646 */
- { current_class = token_sym; }
-#line 2333 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 48:
-#line 446 "src/parse-gram.y" /* yacc.c:1646 */
- {
- current_class = unknown_sym;
- current_type = NULL;
- }
-#line 2342 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 49:
-#line 451 "src/parse-gram.y" /* yacc.c:1646 */
- {
- symbol_list *list;
- tag_seen = true;
- for (list = (yyvsp[0].list); list; list = list->next)
- symbol_type_set (list->content.sym, (yyvsp[-1].uniqstr), (yylsp[-1]));
- symbol_list_free ((yyvsp[0].list));
- }
-#line 2354 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 50:
-#line 462 "src/parse-gram.y" /* yacc.c:1646 */
- {
- symbol_list *list;
- ++current_prec;
- for (list = (yyvsp[0].list); list; list = list->next)
- {
- symbol_type_set (list->content.sym, current_type, (yylsp[-1]));
- symbol_precedence_set (list->content.sym, current_prec, (yyvsp[-2].assoc), (yylsp[-2]));
- }
- symbol_list_free ((yyvsp[0].list));
- current_type = NULL;
- }
-#line 2370 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 51:
-#line 476 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.assoc) = left_assoc; }
-#line 2376 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 52:
-#line 477 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.assoc) = right_assoc; }
-#line 2382 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 53:
-#line 478 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.assoc) = non_assoc; }
-#line 2388 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 54:
-#line 479 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.assoc) = precedence_assoc; }
-#line 2394 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 55:
-#line 483 "src/parse-gram.y" /* yacc.c:1646 */
- { current_type = NULL; }
-#line 2400 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 56:
-#line 484 "src/parse-gram.y" /* yacc.c:1646 */
- { current_type = (yyvsp[0].uniqstr); tag_seen = true; }
-#line 2406 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 57:
-#line 490 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
-#line 2412 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 58:
-#line 492 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = symbol_list_append ((yyvsp[-1].list), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); }
-#line 2418 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 59:
-#line 497 "src/parse-gram.y" /* yacc.c:1646 */
- {
- (yyval.symbol) = (yyvsp[0].symbol);
- symbol_class_set ((yyvsp[0].symbol), token_sym, (yylsp[0]), false);
- }
-#line 2427 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 60:
-#line 502 "src/parse-gram.y" /* yacc.c:1646 */
- {
- (yyval.symbol) = (yyvsp[-1].symbol);
- symbol_user_token_number_set ((yyvsp[-1].symbol), (yyvsp[0].integer), (yylsp[0]));
- symbol_class_set ((yyvsp[-1].symbol), token_sym, (yylsp[-1]), false);
- }
-#line 2437 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 61:
-#line 512 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
-#line 2443 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 62:
-#line 514 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = symbol_list_append ((yyvsp[-1].list), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); }
-#line 2449 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 63:
-#line 518 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = (yyvsp[0].list); }
-#line 2455 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 64:
-#line 519 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = symbol_list_append ((yyvsp[-1].list), (yyvsp[0].list)); }
-#line 2461 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 65:
-#line 523 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
-#line 2467 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 66:
-#line 524 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.list) = symbol_list_type_new ((yyvsp[0].uniqstr), (yylsp[0])); }
-#line 2473 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 68:
-#line 529 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.uniqstr) = uniqstr_new ("*"); }
-#line 2479 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 69:
-#line 530 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.uniqstr) = uniqstr_new (""); }
-#line 2485 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 70:
-#line 536 "src/parse-gram.y" /* yacc.c:1646 */
- {
- current_type = (yyvsp[0].uniqstr);
- tag_seen = true;
- }
-#line 2494 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 71:
-#line 541 "src/parse-gram.y" /* yacc.c:1646 */
- {
- symbol_class_set ((yyvsp[0].symbol), current_class, (yylsp[0]), true);
- symbol_type_set ((yyvsp[0].symbol), current_type, (yylsp[0]));
- }
-#line 2503 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 72:
-#line 546 "src/parse-gram.y" /* yacc.c:1646 */
- {
- symbol_class_set ((yyvsp[-1].symbol), current_class, (yylsp[-1]), true);
- symbol_type_set ((yyvsp[-1].symbol), current_type, (yylsp[-1]));
- symbol_user_token_number_set ((yyvsp[-1].symbol), (yyvsp[0].integer), (yylsp[0]));
- }
-#line 2513 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 73:
-#line 552 "src/parse-gram.y" /* yacc.c:1646 */
- {
- symbol_class_set ((yyvsp[-1].symbol), current_class, (yylsp[-1]), true);
- symbol_type_set ((yyvsp[-1].symbol), current_type, (yylsp[-1]));
- symbol_make_alias ((yyvsp[-1].symbol), (yyvsp[0].symbol), (yyloc));
- }
-#line 2523 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 74:
-#line 558 "src/parse-gram.y" /* yacc.c:1646 */
- {
- symbol_class_set ((yyvsp[-2].symbol), current_class, (yylsp[-2]), true);
- symbol_type_set ((yyvsp[-2].symbol), current_type, (yylsp[-2]));
- symbol_user_token_number_set ((yyvsp[-2].symbol), (yyvsp[-1].integer), (yylsp[-1]));
- symbol_make_alias ((yyvsp[-2].symbol), (yyvsp[0].symbol), (yyloc));
- }
-#line 2534 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 81:
-#line 588 "src/parse-gram.y" /* yacc.c:1646 */
- {
- yyerrok;
- }
-#line 2542 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 82:
-#line 594 "src/parse-gram.y" /* yacc.c:1646 */
- { current_lhs ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].named_ref)); }
-#line 2548 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 83:
-#line 595 "src/parse-gram.y" /* yacc.c:1646 */
- {
- /* Free the current lhs. */
- current_lhs (0, (yylsp[-3]), 0);
- }
-#line 2557 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 84:
-#line 602 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_end ((yylsp[0])); }
-#line 2563 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 85:
-#line 603 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_end ((yylsp[0])); }
-#line 2569 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 87:
-#line 610 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location,
- current_lhs_named_ref); }
-#line 2576 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 88:
-#line 613 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_symbol_append ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].named_ref)); }
-#line 2582 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 89:
-#line 615 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_action_append ((yyvsp[-1].code), (yylsp[-1]), (yyvsp[0].named_ref), false); }
-#line 2588 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 90:
-#line 617 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_action_append ((yyvsp[0].code), (yylsp[0]), NULL, true); }
-#line 2594 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 91:
-#line 619 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_empty_set ((yylsp[0])); }
-#line 2600 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 92:
-#line 621 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_prec_set ((yyvsp[0].symbol), (yylsp[0])); }
-#line 2606 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 93:
-#line 623 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_dprec_set ((yyvsp[0].integer), (yylsp[0])); }
-#line 2612 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 94:
-#line 625 "src/parse-gram.y" /* yacc.c:1646 */
- { grammar_current_rule_merge_set ((yyvsp[0].uniqstr), (yylsp[0])); }
-#line 2618 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 95:
-#line 629 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.named_ref) = 0; }
-#line 2624 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 96:
-#line 630 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.named_ref) = named_ref_new ((yyvsp[0].uniqstr), (yylsp[0])); }
-#line 2630 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 98:
-#line 641 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.uniqstr) = uniqstr_new ((yyvsp[0].code)); }
-#line 2636 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 99:
-#line 666 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.value).kind = muscle_keyword; (yyval.value).chars = ""; }
-#line 2642 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 100:
-#line 667 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.value).kind = muscle_keyword; (yyval.value).chars = (yyvsp[0].uniqstr); }
-#line 2648 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 101:
-#line 668 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.value).kind = muscle_string; (yyval.value).chars = (yyvsp[0].code); }
-#line 2654 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 102:
-#line 669 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.value).kind = muscle_code; (yyval.value).chars = strip_braces ((yyvsp[0].code)); }
-#line 2660 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 103:
-#line 682 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[0].uniqstr), (yylsp[0])); }
-#line 2666 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 104:
-#line 684 "src/parse-gram.y" /* yacc.c:1646 */
- {
- (yyval.symbol) = symbol_get (char_name ((yyvsp[0].character)), (yylsp[0]));
- symbol_class_set ((yyval.symbol), token_sym, (yylsp[0]), false);
- symbol_user_token_number_set ((yyval.symbol), (yyvsp[0].character), (yylsp[0]));
- }
-#line 2676 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 105:
-#line 692 "src/parse-gram.y" /* yacc.c:1646 */
- { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[0].uniqstr), (yylsp[0])); }
-#line 2682 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 108:
-#line 704 "src/parse-gram.y" /* yacc.c:1646 */
- {
- (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[0].code)), (yylsp[0]));
- symbol_class_set ((yyval.symbol), token_sym, (yylsp[0]), false);
- }
-#line 2691 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
- case 110:
-#line 713 "src/parse-gram.y" /* yacc.c:1646 */
- {
- muscle_code_grow ("epilogue", translate_code ((yyvsp[0].code), (yylsp[0]), true), (yylsp[0]));
- code_scanner_last_string_free ();
- }
-#line 2700 "src/parse-gram.c" /* yacc.c:1646 */
- break;
-
-
-#line 2704 "src/parse-gram.c" /* yacc.c:1646 */
- default: break;
- }
- if (yychar_backup != yychar)
- YY_LAC_DISCARD ("yychar change");
- }
- /* User semantic actions sometimes alter yychar, and that requires
- that yytoken be updated with the new translation. We take the
- approach of translating immediately before every use of yytoken.
- One alternative is translating here after every semantic action,
- but that translation would be missed if the semantic action invokes
- YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
- if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
- incorrect destructor might then be invoked immediately. In the
- case of YYERROR or YYBACKUP, subsequent parser actions might lead
- to an incorrect destructor call or verbose syntax error message
- before the lookahead is translated. */
- YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
-
- YYPOPSTACK (yylen);
- yylen = 0;
- YY_STACK_PRINT (yyss, yyssp);
-
- *++yyvsp = yyval;
- *++yylsp = yyloc;
-
- /* Now 'shift' the result of the reduction. Determine what state
- that goes to, based on the state we popped back to and the rule
- number reduced by. */
-
- yyn = yyr1[yyn];
-
- yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
- if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
- yystate = yytable[yystate];
- else
- yystate = yydefgoto[yyn - YYNTOKENS];
-
- goto yynewstate;
-
-
-/*--------------------------------------.
-| yyerrlab -- here on detecting error. |
-`--------------------------------------*/
-yyerrlab:
- /* Make sure we have latest lookahead translation. See comments at
- user semantic actions for why this is necessary. */
- yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
-
- /* If not already recovering from an error, report this error. */
- if (!yyerrstatus)
- {
- ++yynerrs;
-#if ! YYERROR_VERBOSE
- yyerror (&yylloc, YY_("syntax error"));
-#else
-# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
- yyesa, &yyes, &yyes_capacity, \
- yyssp, yytoken)
- {
- char const *yymsgp = YY_("syntax error");
- int yysyntax_error_status;
- if (yychar != YYEMPTY)
- YY_LAC_ESTABLISH;
- yysyntax_error_status = YYSYNTAX_ERROR;
- if (yysyntax_error_status == 0)
- yymsgp = yymsg;
- else if (yysyntax_error_status == 1)
- {
- if (yymsg != yymsgbuf)
- YYSTACK_FREE (yymsg);
- yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
- if (!yymsg)
- {
- yymsg = yymsgbuf;
- yymsg_alloc = sizeof yymsgbuf;
- yysyntax_error_status = 2;
- }
- else
- {
- yysyntax_error_status = YYSYNTAX_ERROR;
- yymsgp = yymsg;
- }
- }
- yyerror (&yylloc, yymsgp);
- if (yysyntax_error_status == 2)
- goto yyexhaustedlab;
- }
-# undef YYSYNTAX_ERROR
-#endif
- }
-
- yyerror_range[1] = yylloc;
-
- if (yyerrstatus == 3)
- {
- /* If just tried and failed to reuse lookahead token after an
- error, discard it. */
-
- if (yychar <= YYEOF)
- {
- /* Return failure if at end of input. */
- if (yychar == YYEOF)
- YYABORT;
- }
- else
- {
- yydestruct ("Error: discarding",
- yytoken, &yylval, &yylloc);
- yychar = YYEMPTY;
- }
- }
-
- /* Else will try to reuse lookahead token after shifting the error
- token. */
- goto yyerrlab1;
-
-
-/*---------------------------------------------------.
-| yyerrorlab -- error raised explicitly by YYERROR. |
-`---------------------------------------------------*/
-yyerrorlab:
-
- /* Pacify compilers like GCC when the user code never invokes
- YYERROR and the label yyerrorlab therefore never appears in user
- code. */
- if (/*CONSTCOND*/ 0)
- goto yyerrorlab;
-
- yyerror_range[1] = yylsp[1-yylen];
- /* Do not reclaim the symbols of the rule whose action triggered
- this YYERROR. */
- YYPOPSTACK (yylen);
- yylen = 0;
- YY_STACK_PRINT (yyss, yyssp);
- yystate = *yyssp;
- goto yyerrlab1;
-
-
-/*-------------------------------------------------------------.
-| yyerrlab1 -- common code for both syntax error and YYERROR. |
-`-------------------------------------------------------------*/
-yyerrlab1:
- yyerrstatus = 3; /* Each real token shifted decrements this. */
-
- for (;;)
- {
- yyn = yypact[yystate];
- if (!yypact_value_is_default (yyn))
- {
- yyn += YYTERROR;
- if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
- {
- yyn = yytable[yyn];
- if (0 < yyn)
- break;
- }
- }
-
- /* Pop the current state because it cannot handle the error token. */
- if (yyssp == yyss)
- YYABORT;
-
- yyerror_range[1] = *yylsp;
- yydestruct ("Error: popping",
- yystos[yystate], yyvsp, yylsp);
- YYPOPSTACK (1);
- yystate = *yyssp;
- YY_STACK_PRINT (yyss, yyssp);
- }
-
- /* If the stack popping above didn't lose the initial context for the
- current lookahead token, the shift below will for sure. */
- YY_LAC_DISCARD ("error recovery");
-
- YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
- *++yyvsp = yylval;
- YY_IGNORE_MAYBE_UNINITIALIZED_END
-
- yyerror_range[2] = yylloc;
- /* Using YYLLOC is tempting, but would change the location of
- the lookahead. YYLOC is available though. */
- YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
- *++yylsp = yyloc;
-
- /* Shift the error token. */
- YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
-
- yystate = yyn;
- goto yynewstate;
-
-
-/*-------------------------------------.
-| yyacceptlab -- YYACCEPT comes here. |
-`-------------------------------------*/
-yyacceptlab:
- yyresult = 0;
- goto yyreturn;
-
-/*-----------------------------------.
-| yyabortlab -- YYABORT comes here. |
-`-----------------------------------*/
-yyabortlab:
- yyresult = 1;
- goto yyreturn;
-
-#if 1
-/*-------------------------------------------------.
-| yyexhaustedlab -- memory exhaustion comes here. |
-`-------------------------------------------------*/
-yyexhaustedlab:
- yyerror (&yylloc, YY_("memory exhausted"));
- yyresult = 2;
- /* Fall through. */
-#endif
-
-yyreturn:
- if (yychar != YYEMPTY)
- {
- /* Make sure we have latest lookahead translation. See comments at
- user semantic actions for why this is necessary. */
- yytoken = YYTRANSLATE (yychar);
- yydestruct ("Cleanup: discarding lookahead",
- yytoken, &yylval, &yylloc);
- }
- /* Do not reclaim the symbols of the rule whose action triggered
- this YYABORT or YYACCEPT. */
- YYPOPSTACK (yylen);
- YY_STACK_PRINT (yyss, yyssp);
- while (yyssp != yyss)
- {
- yydestruct ("Cleanup: popping",
- yystos[*yyssp], yyvsp, yylsp);
- YYPOPSTACK (1);
- }
-#ifndef yyoverflow
- if (yyss != yyssa)
- YYSTACK_FREE (yyss);
-#endif
- if (yyes != yyesa)
- YYSTACK_FREE (yyes);
-#if YYERROR_VERBOSE
- if (yymsg != yymsgbuf)
- YYSTACK_FREE (yymsg);
-#endif
- return yyresult;
-}
-#line 719 "src/parse-gram.y" /* yacc.c:1906 */
-
-
-/* Return the location of the left-hand side of a rule whose
- right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
- the right-hand side, and return an empty location equal to the end
- boundary of RHS[0] if the right-hand side is empty. */
-
-static YYLTYPE
-lloc_default (YYLTYPE const *rhs, int n)
-{
- int i;
- YYLTYPE loc;
-
- /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
- The bug is fixed in 7.4.2m, but play it safe for now. */
- loc.start = rhs[n].end;
- loc.end = rhs[n].end;
-
- /* Ignore empty nonterminals the start of the right-hand side.
- Do not bother to ignore them at the end of the right-hand side,
- since empty nonterminals have the same end as their predecessors. */
- for (i = 1; i <= n; i++)
- if (! equal_boundaries (rhs[i].start, rhs[i].end))
- {
- loc.start = rhs[i].start;
- break;
- }
-
- return loc;
-}
-
-static
-char *strip_braces (char *code)
-{
- code[strlen (code) - 1] = 0;
- return code + 1;
-}
-
-static
-char const *
-translate_code (char *code, location loc, bool plain)
-{
- code_props plain_code;
- if (plain)
- code_props_plain_init (&plain_code, code, loc);
- else
- code_props_symbol_action_init (&plain_code, code, loc);
- code_props_translate_code (&plain_code);
- gram_scanner_last_string_free ();
- return plain_code.code;
-}
-
-static
-char const *
-translate_code_braceless (char *code, location loc)
-{
- return translate_code (strip_braces (code), loc, true);
-}
-
-static void
-add_param (param_type type, char *decl, location loc)
-{
- static char const alphanum[26 + 26 + 1 + 10] =
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "_"
- "0123456789";
-
- char const *name_start = NULL;
- {
- char *p;
- /* Stop on last actual character. */
- for (p = decl; p[1]; p++)
- if ((p == decl
- || ! memchr (alphanum, p[-1], sizeof alphanum))
- && memchr (alphanum, p[0], sizeof alphanum - 10))
- name_start = p;
-
- /* Strip the surrounding '{' and '}', and any blanks just inside
- the braces. */
- --p;
- while (c_isspace ((unsigned char) *p))
- --p;
- p[1] = '\0';
- ++decl;
- while (c_isspace ((unsigned char) *decl))
- ++decl;
- }
-
- if (! name_start)
- complain (&loc, complaint, _("missing identifier in parameter declaration"));
- else
- {
- char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
- if (type & param_lex)
- muscle_pair_list_grow ("lex_param", decl, name);
- if (type & param_parse)
- muscle_pair_list_grow ("parse_param", decl, name);
- free (name);
- }
-
- gram_scanner_last_string_free ();
-}
-
-
-static void
-version_check (location const *loc, char const *version)
-{
- if (strverscmp (version, PACKAGE_VERSION) > 0)
- {
- complain (loc, complaint, "require bison %s, but have %s",
- version, PACKAGE_VERSION);
- exit (EX_MISMATCH);
- }
-}
-
-static void
-gram_error (location const *loc, char const *msg)
-{
- complain (loc, complaint, "%s", msg);
-}
-
-char const *
-token_name (int type)
-{
- return yytname[YYTRANSLATE (type)];
-}
-
-static char const *
-char_name (char c)
-{
- if (c == '\'')
- return "'\\''";
- else
- {
- char buf[4];
- buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
- return quotearg_style (escape_quoting_style, buf);
- }
-}
-
-static
-void
-current_lhs (symbol *sym, location loc, named_ref *ref)
-{
- current_lhs_symbol = sym;
- current_lhs_location = loc;
- /* In order to simplify memory management, named references for lhs
- are always assigned by deep copy into the current symbol_list
- node. This is because a single named-ref in the grammar may
- result in several uses when the user factors lhs between several
- rules using "|". Therefore free the parser's original copy. */
- free (current_lhs_named_ref);
- current_lhs_named_ref = ref;
-}
+
+#line 68 "src/parse-gram.c" /* yacc.c:316 */
+/* Substitute the type names. */
+#define YYSTYPE GRAM_STYPE
+#define YYLTYPE GRAM_LTYPE
+/* Substitute the variable and function names. */
+#define yyparse gram_parse
+#define yylex gram_lex
+#define yyerror gram_error
+#define yydebug gram_debug
+#define yynerrs gram_nerrs
+
+
+/* Copy the first part of user declarations. */
+
+#line 82 "src/parse-gram.c" /* yacc.c:339 */
+
+# ifndef YY_NULL
+# if defined __cplusplus && 201103L <= __cplusplus
+# define YY_NULL nullptr
+# else
+# define YY_NULL 0
+# endif
+# endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 1
+#endif
+
+/* In a future release of Bison, this section will be replaced
+ by #include "src/parse-gram.h". */
+#ifndef YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
+# define YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
+/* Debug traces. */
+#ifndef GRAM_DEBUG
+# if defined YYDEBUG
+#if YYDEBUG
+# define GRAM_DEBUG 1
+# else
+# define GRAM_DEBUG 0
+# endif
+# else /* ! defined YYDEBUG */
+# define GRAM_DEBUG 1
+# endif /* ! defined YYDEBUG */
+#endif /* ! defined GRAM_DEBUG */
+#if GRAM_DEBUG
+extern int gram_debug;
+#endif
+/* "%code requires" blocks. */
+#line 21 "src/parse-gram.y" /* yacc.c:355 */
+
+ #include "symlist.h"
+ #include "symtab.h"
+#line 221 "src/parse-gram.y" /* yacc.c:355 */
+
+ typedef enum
+ {
+ param_none = 0,
+ param_lex = 1 << 0,
+ param_parse = 1 << 1,
+ param_both = param_lex | param_parse
+ } param_type;
+#line 645 "src/parse-gram.y" /* yacc.c:355 */
+#include "muscle-tab.h"
+
+#line 136 "src/parse-gram.c" /* yacc.c:355 */
+
+/* Token type. */
+#ifndef GRAM_TOKENTYPE
+# define GRAM_TOKENTYPE
+ enum gram_tokentype
+ {
+ GRAM_EOF = 0,
+ STRING = 258,
+ PERCENT_TOKEN = 259,
+ PERCENT_NTERM = 260,
+ PERCENT_TYPE = 261,
+ PERCENT_DESTRUCTOR = 262,
+ PERCENT_PRINTER = 263,
+ PERCENT_LEFT = 264,
+ PERCENT_RIGHT = 265,
+ PERCENT_NONASSOC = 266,
+ PERCENT_PRECEDENCE = 267,
+ PERCENT_PREC = 268,
+ PERCENT_DPREC = 269,
+ PERCENT_MERGE = 270,
+ PERCENT_CODE = 271,
+ PERCENT_DEFAULT_PREC = 272,
+ PERCENT_DEFINE = 273,
+ PERCENT_DEFINES = 274,
+ PERCENT_ERROR_VERBOSE = 275,
+ PERCENT_EXPECT = 276,
+ PERCENT_EXPECT_RR = 277,
+ PERCENT_FLAG = 278,
+ PERCENT_FILE_PREFIX = 279,
+ PERCENT_GLR_PARSER = 280,
+ PERCENT_INITIAL_ACTION = 281,
+ PERCENT_LANGUAGE = 282,
+ PERCENT_NAME_PREFIX = 283,
+ PERCENT_NO_DEFAULT_PREC = 284,
+ PERCENT_NO_LINES = 285,
+ PERCENT_NONDETERMINISTIC_PARSER = 286,
+ PERCENT_OUTPUT = 287,
+ PERCENT_REQUIRE = 288,
+ PERCENT_SKELETON = 289,
+ PERCENT_START = 290,
+ PERCENT_TOKEN_TABLE = 291,
+ PERCENT_VERBOSE = 292,
+ PERCENT_YACC = 293,
+ BRACED_CODE = 294,
+ BRACED_PREDICATE = 295,
+ BRACKETED_ID = 296,
+ CHAR = 297,
+ EPILOGUE = 298,
+ EQUAL = 299,
+ ID = 300,
+ ID_COLON = 301,
+ PERCENT_PERCENT = 302,
+ PIPE = 303,
+ PROLOGUE = 304,
+ SEMICOLON = 305,
+ TAG = 306,
+ TAG_ANY = 307,
+ TAG_NONE = 308,
+ INT = 309,
+ PERCENT_PARAM = 310,
+ PERCENT_UNION = 311,
+ PERCENT_EMPTY = 312
+ };
+#endif
+
+/* Value type. */
+#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED
+typedef union GRAM_STYPE GRAM_STYPE;
+union GRAM_STYPE
+{
+#line 182 "src/parse-gram.y" /* yacc.c:355 */
+unsigned char character;
+#line 186 "src/parse-gram.y" /* yacc.c:355 */
+char *code;
+#line 191 "src/parse-gram.y" /* yacc.c:355 */
+uniqstr uniqstr;
+#line 199 "src/parse-gram.y" /* yacc.c:355 */
+int integer;
+#line 203 "src/parse-gram.y" /* yacc.c:355 */
+symbol *symbol;
+#line 208 "src/parse-gram.y" /* yacc.c:355 */
+assoc assoc;
+#line 211 "src/parse-gram.y" /* yacc.c:355 */
+symbol_list *list;
+#line 214 "src/parse-gram.y" /* yacc.c:355 */
+named_ref *named_ref;
+#line 241 "src/parse-gram.y" /* yacc.c:355 */
+param_type param;
+#line 409 "src/parse-gram.y" /* yacc.c:355 */
+code_props_type code_type;
+#line 647 "src/parse-gram.y" /* yacc.c:355 */
+
+ struct
+ {
+ char const *chars;
+ muscle_kind kind;
+ } value;
+
+#line 235 "src/parse-gram.c" /* yacc.c:355 */
+};
+# define GRAM_STYPE_IS_TRIVIAL 1
+# define GRAM_STYPE_IS_DECLARED 1
+#endif
+
+/* Location type. */
+#if ! defined GRAM_LTYPE && ! defined GRAM_LTYPE_IS_DECLARED
+typedef struct GRAM_LTYPE GRAM_LTYPE;
+struct GRAM_LTYPE
+{
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+};
+# define GRAM_LTYPE_IS_DECLARED 1
+# define GRAM_LTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+int gram_parse (void);
+
+#endif /* !YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED */
+
+/* Copy the second part of user declarations. */
+
+#line 263 "src/parse-gram.c" /* yacc.c:358 */
+/* Unqualified %code blocks. */
+#line 33 "src/parse-gram.y" /* yacc.c:359 */
+
+ #include "system.h"
+
+ #include "c-ctype.h"
+ #include "complain.h"
+ #include "conflicts.h"
+ #include "files.h"
+ #include "getargs.h"
+ #include "gram.h"
+ #include "named-ref.h"
+ #include "quotearg.h"
+ #include "reader.h"
+ #include "scan-gram.h"
+ #include "scan-code.h"
+ #include "xmemdup0.h"
+
+ static int current_prec = 0;
+ static location current_lhs_location;
+ static named_ref *current_lhs_named_ref;
+ static symbol *current_lhs_symbol;
+ static symbol_class current_class = unknown_sym;
+ static uniqstr current_type = NULL;
+
+ /** Set the new current left-hand side symbol, possibly common
+ * to several right-hand side parts of rule.
+ */
+ static void current_lhs (symbol *sym, location loc, named_ref *ref);
+
+ #define YYLLOC_DEFAULT(Current, Rhs, N) \
+ (Current) = lloc_default (Rhs, N)
+ static YYLTYPE lloc_default (YYLTYPE const *, int);
+
+ #define YY_LOCATION_PRINT(File, Loc) \
+ location_print (Loc, File)
+
+ /* Strip initial '{' and final '}' (must be first and last characters).
+ Return the result. */
+ static char *strip_braces (char *code);
+
+ /* Convert CODE by calling code_props_plain_init if PLAIN, otherwise
+ code_props_symbol_action_init. Call
+ gram_scanner_last_string_free to release the latest string from
+ the scanner (should be CODE). */
+ static char const *translate_code (char *code, location loc, bool plain);
+
+ /* Convert CODE by calling code_props_plain_init after having
+ stripped the first and last characters (expected to be '{', and
+ '}'). Call gram_scanner_last_string_free to release the latest
+ string from the scanner (should be CODE). */
+ static char const *translate_code_braceless (char *code, location loc);
+
+ static void version_check (location const *loc, char const *version);
+
+ static void gram_error (location const *, char const *);
+
+ /* A string that describes a char (e.g., 'a' -> "'a'"). */
+ static char const *char_name (char);
+
+ #define YYTYPE_INT16 int_fast16_t
+ #define YYTYPE_INT8 int_fast8_t
+ #define YYTYPE_UINT16 uint_fast16_t
+ #define YYTYPE_UINT8 uint_fast8_t
+#line 231 "src/parse-gram.y" /* yacc.c:359 */
+
+ /** Add a lex-param and/or a parse-param.
+ *
+ * \param type where to push this formal argument.
+ * \param decl the formal argument. Destroyed.
+ * \param loc the location in the source.
+ */
+ static void add_param (param_type type, char *decl, location loc);
+ static param_type current_param = param_none;
+
+#line 339 "src/parse-gram.c" /* yacc.c:359 */
+
+#ifdef short
+# undef short
+#endif
+
+#ifdef YYTYPE_UINT8
+typedef YYTYPE_UINT8 yytype_uint8;
+#else
+typedef unsigned char yytype_uint8;
+#endif
+
+#ifdef YYTYPE_INT8
+typedef YYTYPE_INT8 yytype_int8;
+#else
+typedef signed char yytype_int8;
+#endif
+
+#ifdef YYTYPE_UINT16
+typedef YYTYPE_UINT16 yytype_uint16;
+#else
+typedef unsigned short int yytype_uint16;
+#endif
+
+#ifdef YYTYPE_INT16
+typedef YYTYPE_INT16 yytype_int16;
+#else
+typedef short int yytype_int16;
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif ! defined YYSIZE_T
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned int
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(Msgid) Msgid
+# endif
+#endif
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if (! defined __GNUC__ || __GNUC__ < 2 \
+ || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
+# define __attribute__(Spec) /* empty */
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(E) ((void) (E))
+#else
+# define YYUSE(E) /* empty */
+#endif
+
+#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
+/* Suppress an incorrect diagnostic about yylval being uninitialized. */
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define YY_INITIAL_VALUE(Value) Value
+#endif
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+
+
+#if 1
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's 'empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined EXIT_SUCCESS \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined EXIT_SUCCESS
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined EXIT_SUCCESS
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+# define YYCOPY_NEEDED 1
+#endif
+
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL \
+ && defined GRAM_STYPE_IS_TRIVIAL && GRAM_STYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yytype_int16 yyss_alloc;
+ YYSTYPE yyvs_alloc;
+ YYLTYPE yyls_alloc;
+};
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
+ + 2 * YYSTACK_GAP_MAXIMUM)
+
+# define YYCOPY_NEEDED 1
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
+ do \
+ { \
+ YYSIZE_T yynewbytes; \
+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
+ Stack = &yyptr->Stack_alloc; \
+ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / sizeof (*yyptr); \
+ } \
+ while (0)
+
+#endif
+
+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
+/* Copy COUNT objects from SRC to DST. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(Dst, Src, Count) \
+ __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
+# else
+# define YYCOPY(Dst, Src, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (Dst)[yyi] = (Src)[yyi]; \
+ } \
+ while (0)
+# endif
+# endif
+#endif /* !YYCOPY_NEEDED */
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 3
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 164
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 58
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 37
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 110
+/* YYNSTATES -- Number of states. */
+#define YYNSTATES 144
+
+/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
+ by yylex, with out-of-bounds checking. */
+#define YYUNDEFTOK 2
+#define YYMAXUTOK 312
+
+#define YYTRANSLATE(YYX) \
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+
+/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex, without out-of-bounds checking. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57
+};
+
+#if GRAM_DEBUG
+ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
+static const yytype_uint16 yyrline[] =
+{
+ 0, 264, 264, 273, 274, 278, 279, 285, 289, 294,
+ 295, 300, 306, 307, 308, 309, 314, 319, 320, 321,
+ 322, 323, 324, 324, 325, 326, 350, 351, 352, 353,
+ 357, 358, 367, 368, 369, 373, 385, 389, 393, 401,
+ 412, 413, 423, 424, 428, 440, 440, 445, 445, 450,
+ 461, 476, 477, 478, 479, 483, 484, 489, 491, 496,
+ 501, 511, 513, 518, 519, 523, 524, 528, 529, 530,
+ 535, 540, 545, 551, 557, 568, 569, 578, 579, 585,
+ 586, 587, 594, 594, 602, 603, 604, 609, 612, 614,
+ 616, 618, 620, 622, 624, 629, 630, 640, 641, 666,
+ 667, 668, 669, 681, 683, 692, 697, 698, 703, 711,
+ 712
+};
+#endif
+
+#if GRAM_DEBUG || YYERROR_VERBOSE || 1
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "\"end of file\"", "error", "$undefined", "\"string\"", "\"%token\"",
+ "\"%nterm\"", "\"%type\"", "\"%destructor\"", "\"%printer\"",
+ "\"%left\"", "\"%right\"", "\"%nonassoc\"", "\"%precedence\"",
+ "\"%prec\"", "\"%dprec\"", "\"%merge\"", "\"%code\"",
+ "\"%default-prec\"", "\"%define\"", "\"%defines\"", "\"%error-verbose\"",
+ "\"%expect\"", "\"%expect-rr\"", "\"%<flag>\"", "\"%file-prefix\"",
+ "\"%glr-parser\"", "\"%initial-action\"", "\"%language\"",
+ "\"%name-prefix\"", "\"%no-default-prec\"", "\"%no-lines\"",
+ "\"%nondeterministic-parser\"", "\"%output\"", "\"%require\"",
+ "\"%skeleton\"", "\"%start\"", "\"%token-table\"", "\"%verbose\"",
+ "\"%yacc\"", "\"{...}\"", "\"%?{...}\"", "\"[identifier]\"", "\"char\"",
+ "\"epilogue\"", "\"=\"", "\"identifier\"", "\"identifier:\"", "\"%%\"",
+ "\"|\"", "\"%{...%}\"", "\";\"", "\"<tag>\"", "\"<*>\"", "\"<>\"",
+ "\"integer\"", "\"%param\"", "\"%union\"", "\"%empty\"", "$accept",
+ "input", "prologue_declarations", "prologue_declaration", "$@1",
+ "params", "grammar_declaration", "code_props_type", "union_name",
+ "symbol_declaration", "$@2", "$@3", "precedence_declaration",
+ "precedence_declarator", "tag.opt", "symbols.prec", "symbol.prec",
+ "symbols.1", "generic_symlist", "generic_symlist_item", "tag",
+ "symbol_def", "symbol_defs.1", "grammar", "rules_or_grammar_declaration",
+ "rules", "$@4", "rhses.1", "rhs", "named_ref.opt", "variable", "value",
+ "id", "id_colon", "symbol", "string_as_id", "epilogue.opt", YY_NULL
+};
+#endif
+
+# ifdef YYPRINT
+/* YYTOKNUM[NUM] -- (External) token number corresponding to the
+ (internal) symbol number NUM (which must be that of a token). */
+static const yytype_uint16 yytoknum[] =
+{
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
+ 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
+ 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
+ 305, 306, 307, 308, 309, 310, 311, 312
+};
+# endif
+
+#define YYPACT_NINF -113
+
+#define yypact_value_is_default(Yystate) \
+ (!!((Yystate) == (-113)))
+
+#define YYTABLE_NINF -110
+
+#define yytable_value_is_error(Yytable_value) \
+ 0
+
+ /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+static const yytype_int8 yypact[] =
+{
+ -113, 16, 108, -113, -113, -113, -27, -113, -113, -113,
+ -113, -113, -113, -24, -113, 23, 24, -113, -21, -15,
+ -113, 29, -113, 3, 38, 42, -113, -113, -113, 44,
+ 47, 71, 31, -113, -113, -113, 55, -113, -113, -113,
+ 30, -113, -113, 39, -113, -113, 26, -22, -22, 31,
+ -113, 48, -113, -113, 1, -113, -113, -113, -113, -113,
+ -113, -113, -113, -113, -113, -113, -113, -113, -113, -113,
+ -113, 45, -113, 50, 2, -113, -113, 57, 49, -113,
+ 52, 41, -113, 31, -113, -113, -22, -2, -22, 31,
+ -113, -113, -113, -113, -113, -113, -113, -113, 46, -113,
+ -113, -113, -113, -113, 63, -113, -113, -113, -113, 41,
+ -113, -113, -113, 31, -113, 51, -113, 100, -113, -113,
+ -113, -113, -113, -113, -113, -113, -113, -20, 40, -113,
+ -113, 31, 53, 58, 57, -113, -113, 57, 40, -113,
+ -113, -113, -113, -113
+};
+
+ /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
+ Performed when YYTABLE does not specify something else to do. Zero
+ means the default is an error. */
+static const yytype_uint8 yydefact[] =
+{
+ 3, 0, 0, 1, 47, 45, 0, 40, 41, 51,
+ 52, 53, 54, 0, 36, 0, 9, 11, 0, 0,
+ 7, 0, 15, 0, 0, 0, 37, 19, 20, 0,
+ 0, 0, 0, 26, 27, 28, 0, 6, 29, 22,
+ 42, 4, 5, 0, 33, 32, 55, 0, 0, 0,
+ 38, 0, 98, 97, 99, 10, 12, 13, 14, 16,
+ 17, 18, 21, 24, 25, 108, 104, 103, 106, 34,
+ 107, 0, 105, 0, 0, 77, 79, 95, 0, 43,
+ 0, 0, 56, 0, 70, 75, 48, 71, 46, 49,
+ 61, 39, 101, 102, 100, 8, 81, 80, 0, 78,
+ 2, 96, 82, 31, 23, 44, 67, 68, 69, 35,
+ 63, 66, 65, 50, 57, 59, 76, 72, 73, 62,
+ 110, 87, 30, 64, 58, 60, 74, 83, 84, 87,
+ 86, 0, 0, 0, 95, 90, 91, 95, 85, 92,
+ 93, 94, 89, 88
+};
+
+ /* YYPGOTO[NTERM-NUM]. */
+static const yytype_int8 yypgoto[] =
+{
+ -113, -113, -113, -113, -113, -113, 102, -113, -113, -113,
+ -113, -113, -113, -113, -113, -113, 8, -113, -113, 13,
+ -113, -50, 75, -113, 73, -113, -113, -113, 19, -112,
+ -113, -113, 22, -113, -32, -82, -113
+};
+
+ /* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int16 yydefgoto[] =
+{
+ -1, 1, 2, 41, 78, 104, 73, 43, 80, 44,
+ 48, 47, 45, 46, 83, 113, 114, 89, 109, 110,
+ 111, 85, 86, 74, 75, 76, 121, 127, 128, 102,
+ 54, 95, 68, 77, 112, 70, 100
+};
+
+ /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule whose
+ number is the opposite. If YYTABLE_NINF, syntax error. */
+static const yytype_int16 yytable[] =
+{
+ 69, 65, -109, 71, 92, 118, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 50, 3, 90, 13, 14,
+ 66, 51, 142, 67, 49, 143, 52, 55, 129, 84,
+ 130, 26, 58, 56, 65, 126, 116, 32, 116, 57,
+ 93, 60, 59, 65, 65, 61, 94, 62, 72, 98,
+ 63, 115, 117, 131, 132, 133, 71, 119, 40, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 53, 87,
+ 87, 13, 14, 66, 64, 79, 67, 82, 81, 134,
+ 135, 115, 66, 66, 26, 67, 67, 91, 103, 120,
+ 32, 105, 106, 107, 108, 96, 137, 136, 101, 139,
+ 97, 72, 122, 65, 42, 125, 137, 140, 87, 141,
+ 87, 40, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 124, 123, 88, 13, 14, 15, 16, 17, 18,
+ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
+ 29, 30, 31, 32, 33, 34, 35, 99, 138, 0,
+ 0, 0, 0, 0, 0, 36, 0, 37, 38, 0,
+ 0, 0, 0, 39, 40
+};
+
+static const yytype_int16 yycheck[] =
+{
+ 32, 3, 0, 1, 3, 87, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 39, 0, 49, 16, 17,
+ 42, 45, 134, 45, 51, 137, 3, 3, 48, 51,
+ 50, 29, 3, 54, 3, 117, 86, 35, 88, 54,
+ 39, 3, 39, 3, 3, 3, 45, 3, 46, 47,
+ 3, 83, 54, 13, 14, 15, 1, 89, 56, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 45, 47,
+ 48, 16, 17, 42, 3, 45, 45, 51, 39, 39,
+ 40, 113, 42, 42, 29, 45, 45, 39, 39, 43,
+ 35, 39, 51, 52, 53, 50, 128, 57, 41, 131,
+ 50, 46, 39, 3, 2, 54, 138, 54, 86, 51,
+ 88, 56, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 113, 109, 48, 16, 17, 18, 19, 20, 21,
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 74, 129, -1,
+ -1, -1, -1, -1, -1, 47, -1, 49, 50, -1,
+ -1, -1, -1, 55, 56
+};
+
+ /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const yytype_uint8 yystos[] =
+{
+ 0, 59, 60, 0, 4, 5, 6, 7, 8, 9,
+ 10, 11, 12, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 47, 49, 50, 55,
+ 56, 61, 64, 65, 67, 70, 71, 69, 68, 51,
+ 39, 45, 3, 45, 88, 3, 54, 54, 3, 39,
+ 3, 3, 3, 3, 3, 3, 42, 45, 90, 92,
+ 93, 1, 46, 64, 81, 82, 83, 91, 62, 45,
+ 66, 39, 51, 72, 51, 79, 80, 90, 80, 75,
+ 92, 39, 3, 39, 45, 89, 50, 50, 47, 82,
+ 94, 41, 87, 39, 63, 39, 51, 52, 53, 76,
+ 77, 78, 92, 73, 74, 92, 79, 54, 93, 92,
+ 43, 84, 39, 77, 74, 54, 93, 85, 86, 48,
+ 50, 13, 14, 15, 39, 40, 57, 92, 86, 92,
+ 54, 51, 87, 87
+};
+
+ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+static const yytype_uint8 yyr1[] =
+{
+ 0, 58, 59, 60, 60, 61, 61, 61, 61, 61,
+ 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
+ 61, 61, 62, 61, 61, 61, 61, 61, 61, 61,
+ 63, 63, 64, 64, 64, 64, 64, 64, 64, 64,
+ 65, 65, 66, 66, 64, 68, 67, 69, 67, 67,
+ 70, 71, 71, 71, 71, 72, 72, 73, 73, 74,
+ 74, 75, 75, 76, 76, 77, 77, 78, 78, 78,
+ 79, 79, 79, 79, 79, 80, 80, 81, 81, 82,
+ 82, 82, 84, 83, 85, 85, 85, 86, 86, 86,
+ 86, 86, 86, 86, 86, 87, 87, 88, 88, 89,
+ 89, 89, 89, 90, 90, 91, 92, 92, 93, 94,
+ 94
+};
+
+ /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
+static const yytype_uint8 yyr2[] =
+{
+ 0, 2, 4, 0, 2, 1, 1, 1, 3, 1,
+ 2, 1, 2, 2, 2, 1, 2, 2, 2, 1,
+ 1, 2, 0, 3, 2, 2, 1, 1, 1, 1,
+ 2, 1, 1, 1, 2, 3, 1, 1, 2, 3,
+ 1, 1, 0, 1, 3, 0, 3, 0, 3, 3,
+ 3, 1, 1, 1, 1, 0, 1, 1, 2, 1,
+ 2, 1, 2, 1, 2, 1, 1, 1, 1, 1,
+ 1, 1, 2, 2, 3, 1, 2, 1, 2, 1,
+ 2, 2, 0, 4, 1, 3, 2, 0, 3, 3,
+ 2, 2, 3, 3, 3, 0, 1, 1, 1, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 2
+};
+
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+#define YYEMPTY (-2)
+#define YYEOF 0
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ YYPOPSTACK (yylen); \
+ yystate = *yyssp; \
+ YY_LAC_DISCARD ("YYBACKUP"); \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (&yylloc, YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+while (0)
+
+/* Error token number */
+#define YYTERROR 1
+#define YYERRCODE 256
+
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (N) \
+ { \
+ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
+ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
+ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
+ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
+ } \
+ else \
+ { \
+ (Current).first_line = (Current).last_line = \
+ YYRHSLOC (Rhs, 0).last_line; \
+ (Current).first_column = (Current).last_column = \
+ YYRHSLOC (Rhs, 0).last_column; \
+ } \
+ while (0)
+#endif
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+
+
+/* Enable debugging if requested. */
+#if GRAM_DEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (0)
+
+
+/* YY_LOCATION_PRINT -- Print the location on the stream.
+ This macro was not mandated originally: define only if we know
+ we won't break user code: when these are the locations we know. */
+
+#ifndef YY_LOCATION_PRINT
+# if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
+
+/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
+
+__attribute__((__unused__))
+static unsigned
+yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
+{
+ unsigned res = 0;
+ int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
+ if (0 <= yylocp->first_line)
+ {
+ res += YYFPRINTF (yyo, "%d", yylocp->first_line);
+ if (0 <= yylocp->first_column)
+ res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
+ }
+ if (0 <= yylocp->last_line)
+ {
+ if (yylocp->first_line < yylocp->last_line)
+ {
+ res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
+ if (0 <= end_col)
+ res += YYFPRINTF (yyo, ".%d", end_col);
+ }
+ else if (0 <= end_col && yylocp->first_column < end_col)
+ res += YYFPRINTF (yyo, "-%d", end_col);
+ }
+ return res;
+ }
+
+# define YY_LOCATION_PRINT(File, Loc) \
+ yy_location_print_ (File, &(Loc))
+
+# else
+# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
+# endif
+#endif
+
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Type, Value, Location); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (0)
+
+
+/*----------------------------------------.
+| Print this symbol's value on YYOUTPUT. |
+`----------------------------------------*/
+
+static void
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
+{
+ FILE *yyo = yyoutput;
+ YYUSE (yyo);
+ YYUSE (yylocationp);
+ if (!yyvaluep)
+ return;
+# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# endif
+ switch (yytype)
+ {
+ case 3: /* "string" */
+#line 188 "src/parse-gram.y" /* yacc.c:684 */
+ { fputs (quotearg_style (c_quoting_style, ((*yyvaluep).code)), yyo); }
+#line 987 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 23: /* "%<flag>" */
+#line 196 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%%%s", ((*yyvaluep).uniqstr)); }
+#line 993 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 39: /* "{...}" */
+#line 189 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
+#line 999 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 40: /* "%?{...}" */
+#line 189 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
+#line 1005 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 41: /* "[identifier]" */
+#line 194 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "[%s]", ((*yyvaluep).uniqstr)); }
+#line 1011 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 42: /* "char" */
+#line 184 "src/parse-gram.y" /* yacc.c:684 */
+ { fputs (char_name (((*yyvaluep).character)), yyo); }
+#line 1017 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 43: /* "epilogue" */
+#line 189 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
+#line 1023 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 45: /* "identifier" */
+#line 193 "src/parse-gram.y" /* yacc.c:684 */
+ { fputs (((*yyvaluep).uniqstr), yyo); }
+#line 1029 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 46: /* "identifier:" */
+#line 195 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%s:", ((*yyvaluep).uniqstr)); }
+#line 1035 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 49: /* "%{...%}" */
+#line 189 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); }
+#line 1041 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 51: /* "<tag>" */
+#line 197 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "<%s>", ((*yyvaluep).uniqstr)); }
+#line 1047 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 54: /* "integer" */
+#line 201 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%d", ((*yyvaluep).integer)); }
+#line 1053 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 55: /* "%param" */
+#line 244 "src/parse-gram.y" /* yacc.c:684 */
+ {
+ switch (((*yyvaluep).param))
+ {
+#define CASE(In, Out) \
+ case param_ ## In: fputs ("%" #Out, yyo); break
+ CASE (lex, lex-param);
+ CASE (parse, parse-param);
+ CASE (both, param);
+#undef CASE
+ case param_none: aver (false); break;
+ }
+}
+#line 1070 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 65: /* code_props_type */
+#line 410 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%s", code_props_type_string (((*yyvaluep).code_type))); }
+#line 1076 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 74: /* symbol.prec */
+#line 205 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
+#line 1082 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 78: /* tag */
+#line 197 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "<%s>", ((*yyvaluep).uniqstr)); }
+#line 1088 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 88: /* variable */
+#line 193 "src/parse-gram.y" /* yacc.c:684 */
+ { fputs (((*yyvaluep).uniqstr), yyo); }
+#line 1094 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 89: /* value */
+#line 656 "src/parse-gram.y" /* yacc.c:684 */
+ {
+ switch (((*yyvaluep).value).kind)
+ {
+ case muscle_code: fprintf (yyo, "{%s}", ((*yyvaluep).value).chars); break;
+ case muscle_keyword: fprintf (yyo, "%s", ((*yyvaluep).value).chars); break;
+ case muscle_string: fprintf (yyo, "\"%s\"", ((*yyvaluep).value).chars); break;
+ }
+}
+#line 1107 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 90: /* id */
+#line 205 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
+#line 1113 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 91: /* id_colon */
+#line 206 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%s:", ((*yyvaluep).symbol)->tag); }
+#line 1119 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 92: /* symbol */
+#line 205 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
+#line 1125 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+ case 93: /* string_as_id */
+#line 205 "src/parse-gram.y" /* yacc.c:684 */
+ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); }
+#line 1131 "src/parse-gram.c" /* yacc.c:684 */
+ break;
+
+
+ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+static void
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
+{
+ YYFPRINTF (yyoutput, "%s %s (",
+ yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
+
+ YY_LOCATION_PRINT (yyoutput, *yylocationp);
+ YYFPRINTF (yyoutput, ": ");
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
+ YYFPRINTF (yyoutput, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+static void
+yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; yybottom <= yytop; yybottom++)
+ {
+ int yybot = *yybottom;
+ YYFPRINTF (stderr, " %d", yybot);
+ }
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+static void
+yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
+{
+ unsigned long int yylno = yyrline[yyrule];
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr,
+ yystos[yyssp[yyi + 1 - yynrhs]],
+ &(yyvsp[(yyi + 1) - (yynrhs)])
+ , &(yylsp[(yyi + 1) - (yynrhs)]) );
+ YYFPRINTF (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
+} while (0)
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !GRAM_DEBUG */
+# define YYDPRINTF(Args)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !GRAM_DEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+/* Given a state stack such that *YYBOTTOM is its bottom, such that
+ *YYTOP is either its top or is YYTOP_EMPTY to indicate an empty
+ stack, and such that *YYCAPACITY is the maximum number of elements it
+ can hold without a reallocation, make sure there is enough room to
+ store YYADD more elements. If not, allocate a new stack using
+ YYSTACK_ALLOC, copy the existing elements, and adjust *YYBOTTOM,
+ *YYTOP, and *YYCAPACITY to reflect the new capacity and memory
+ location. If *YYBOTTOM != YYBOTTOM_NO_FREE, then free the old stack
+ using YYSTACK_FREE. Return 0 if successful or if no reallocation is
+ required. Return 1 if memory is exhausted. */
+static int
+yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
+#if GRAM_DEBUG
+ char const *yydebug_prefix,
+ char const *yydebug_suffix,
+#endif
+ yytype_int16 **yybottom,
+ yytype_int16 *yybottom_no_free,
+ yytype_int16 **yytop, yytype_int16 *yytop_empty)
+{
+ YYSIZE_T yysize_old =
+ *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
+ YYSIZE_T yysize_new = yysize_old + yyadd;
+ if (*yycapacity < yysize_new)
+ {
+ YYSIZE_T yyalloc = 2 * yysize_new;
+ yytype_int16 *yybottom_new;
+ /* Use YYMAXDEPTH for maximum stack size given that the stack
+ should never need to grow larger than the main state stack
+ needs to grow without LAC. */
+ if (YYMAXDEPTH < yysize_new)
+ {
+ YYDPRINTF ((stderr, "%smax size exceeded%s", yydebug_prefix,
+ yydebug_suffix));
+ return 1;
+ }
+ if (YYMAXDEPTH < yyalloc)
+ yyalloc = YYMAXDEPTH;
+ yybottom_new =
+ (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new);
+ if (!yybottom_new)
+ {
+ YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix,
+ yydebug_suffix));
+ return 1;
+ }
+ if (*yytop != yytop_empty)
+ {
+ YYCOPY (yybottom_new, *yybottom, yysize_old);
+ *yytop = yybottom_new + (yysize_old - 1);
+ }
+ if (*yybottom != yybottom_no_free)
+ YYSTACK_FREE (*yybottom);
+ *yybottom = yybottom_new;
+ *yycapacity = yyalloc;
+ }
+ return 0;
+}
+
+/* Establish the initial context for the current lookahead if no initial
+ context is currently established.
+
+ We define a context as a snapshot of the parser stacks. We define
+ the initial context for a lookahead as the context in which the
+ parser initially examines that lookahead in order to select a
+ syntactic action. Thus, if the lookahead eventually proves
+ syntactically unacceptable (possibly in a later context reached via a
+ series of reductions), the initial context can be used to determine
+ the exact set of tokens that would be syntactically acceptable in the
+ lookahead's place. Moreover, it is the context after which any
+ further semantic actions would be erroneous because they would be
+ determined by a syntactically unacceptable token.
+
+ YY_LAC_ESTABLISH should be invoked when a reduction is about to be
+ performed in an inconsistent state (which, for the purposes of LAC,
+ includes consistent states that don't know they're consistent because
+ their default reductions have been disabled). Iff there is a
+ lookahead token, it should also be invoked before reporting a syntax
+ error. This latter case is for the sake of the debugging output.
+
+ For parse.lac=full, the implementation of YY_LAC_ESTABLISH is as
+ follows. If no initial context is currently established for the
+ current lookahead, then check if that lookahead can eventually be
+ shifted if syntactic actions continue from the current context.
+ Report a syntax error if it cannot. */
+#define YY_LAC_ESTABLISH \
+do { \
+ if (!yy_lac_established) \
+ { \
+ YYDPRINTF ((stderr, \
+ "LAC: initial context established for %s\n", \
+ yytname[yytoken])); \
+ yy_lac_established = 1; \
+ { \
+ int yy_lac_status = \
+ yy_lac (yyesa, &yyes, &yyes_capacity, yyssp, yytoken); \
+ if (yy_lac_status == 2) \
+ goto yyexhaustedlab; \
+ if (yy_lac_status == 1) \
+ goto yyerrlab; \
+ } \
+ } \
+} while (0)
+
+/* Discard any previous initial lookahead context because of Event,
+ which may be a lookahead change or an invalidation of the currently
+ established initial context for the current lookahead.
+
+ The most common example of a lookahead change is a shift. An example
+ of both cases is syntax error recovery. That is, a syntax error
+ occurs when the lookahead is syntactically erroneous for the
+ currently established initial context, so error recovery manipulates
+ the parser stacks to try to find a new initial context in which the
+ current lookahead is syntactically acceptable. If it fails to find
+ such a context, it discards the lookahead. */
+#if GRAM_DEBUG
+# define YY_LAC_DISCARD(Event) \
+do { \
+ if (yy_lac_established) \
+ { \
+ if (yydebug) \
+ YYFPRINTF (stderr, "LAC: initial context discarded due to " \
+ Event "\n"); \
+ yy_lac_established = 0; \
+ } \
+} while (0)
+#else
+# define YY_LAC_DISCARD(Event) yy_lac_established = 0
+#endif
+
+/* Given the stack whose top is *YYSSP, return 0 iff YYTOKEN can
+ eventually (after perhaps some reductions) be shifted, return 1 if
+ not, or return 2 if memory is exhausted. As preconditions and
+ postconditions: *YYES_CAPACITY is the allocated size of the array to
+ which *YYES points, and either *YYES = YYESA or *YYES points to an
+ array allocated with YYSTACK_ALLOC. yy_lac may overwrite the
+ contents of either array, alter *YYES and *YYES_CAPACITY, and free
+ any old *YYES other than YYESA. */
+static int
+yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
+ YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
+{
+ yytype_int16 *yyes_prev = yyssp;
+ yytype_int16 *yyesp = yyes_prev;
+ YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken]));
+ if (yytoken == YYUNDEFTOK)
+ {
+ YYDPRINTF ((stderr, " Always Err\n"));
+ return 1;
+ }
+ while (1)
+ {
+ int yyrule = yypact[*yyesp];
+ if (yypact_value_is_default (yyrule)
+ || (yyrule += yytoken) < 0 || YYLAST < yyrule
+ || yycheck[yyrule] != yytoken)
+ {
+ yyrule = yydefact[*yyesp];
+ if (yyrule == 0)
+ {
+ YYDPRINTF ((stderr, " Err\n"));
+ return 1;
+ }
+ }
+ else
+ {
+ yyrule = yytable[yyrule];
+ if (yytable_value_is_error (yyrule))
+ {
+ YYDPRINTF ((stderr, " Err\n"));
+ return 1;
+ }
+ if (0 < yyrule)
+ {
+ YYDPRINTF ((stderr, " S%d\n", yyrule));
+ return 0;
+ }
+ yyrule = -yyrule;
+ }
+ {
+ YYSIZE_T yylen = yyr2[yyrule];
+ YYDPRINTF ((stderr, " R%d", yyrule - 1));
+ if (yyesp != yyes_prev)
+ {
+ YYSIZE_T yysize = yyesp - *yyes + 1;
+ if (yylen < yysize)
+ {
+ yyesp -= yylen;
+ yylen = 0;
+ }
+ else
+ {
+ yylen -= yysize;
+ yyesp = yyes_prev;
+ }
+ }
+ if (yylen)
+ yyesp = yyes_prev -= yylen;
+ }
+ {
+ int yystate;
+ {
+ int yylhs = yyr1[yyrule] - YYNTOKENS;
+ yystate = yypgoto[yylhs] + *yyesp;
+ if (yystate < 0 || YYLAST < yystate
+ || yycheck[yystate] != *yyesp)
+ yystate = yydefgoto[yylhs];
+ else
+ yystate = yytable[yystate];
+ }
+ if (yyesp == yyes_prev)
+ {
+ yyesp = *yyes;
+ *yyesp = yystate;
+ }
+ else
+ {
+ if (yy_lac_stack_realloc (yyes_capacity, 1,
+#if GRAM_DEBUG
+ " (", ")",
+#endif
+ yyes, yyesa, &yyesp, yyes_prev))
+ {
+ YYDPRINTF ((stderr, "\n"));
+ return 2;
+ }
+ *++yyesp = yystate;
+ }
+ YYDPRINTF ((stderr, " G%d", yystate));
+ }
+ }
+}
+
+
+#if YYERROR_VERBOSE
+
+# ifndef yystrlen
+# if defined __GLIBC__ && defined _STRING_H
+# define yystrlen strlen
+# else
+/* Return the length of YYSTR. */
+static YYSIZE_T
+yystrlen (const char *yystr)
+{
+ YYSIZE_T yylen;
+ for (yylen = 0; yystr[yylen]; yylen++)
+ continue;
+ return yylen;
+}
+# endif
+# endif
+
+# ifndef yystpcpy
+# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# define yystpcpy stpcpy
+# else
+/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
+ YYDEST. */
+static char *
+yystpcpy (char *yydest, const char *yysrc)
+{
+ char *yyd = yydest;
+ const char *yys = yysrc;
+
+ while ((*yyd++ = *yys++) != '\0')
+ continue;
+
+ return yyd - 1;
+}
+# endif
+# endif
+
+# ifndef yytnamerr
+/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
+ quotes and backslashes, so that it's suitable for yyerror. The
+ heuristic is that double-quoting is unnecessary unless the string
+ contains an apostrophe, a comma, or backslash (other than
+ backslash-backslash). YYSTR is taken from yytname. If YYRES is
+ null, do not copy; instead, return the length of what the result
+ would have been. */
+static YYSIZE_T
+yytnamerr (char *yyres, const char *yystr)
+{
+ if (*yystr == '"')
+ {
+ YYSIZE_T yyn = 0;
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ if (yyres)
+ yyres[yyn] = *yyp;
+ yyn++;
+ break;
+
+ case '"':
+ if (yyres)
+ yyres[yyn] = '\0';
+ return yyn;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ if (! yyres)
+ return yystrlen (yystr);
+
+ return yystpcpy (yyres, yystr) - yyres;
+}
+# endif
+
+/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
+ about the unexpected token YYTOKEN for the state stack whose top is
+ YYSSP. In order to see if a particular token T is a
+ valid looakhead, invoke yy_lac (YYESA, YYES, YYES_CAPACITY, YYSSP, T).
+
+ Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
+ not large enough to hold the message. In that case, also set
+ *YYMSG_ALLOC to the required number of bytes. Return 2 if the
+ required number of bytes is too large to store or if
+ yy_lac returned 2. */
+static int
+yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
+ yytype_int16 *yyesa, yytype_int16 **yyes,
+ YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken)
+{
+ YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
+ YYSIZE_T yysize = yysize0;
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ /* Internationalized format string. */
+ const char *yyformat = YY_NULL;
+ /* Arguments of yyformat. */
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+ /* Number of reported tokens (one for the "unexpected", one per
+ "expected"). */
+ int yycount = 0;
+
+ /* There are many possibilities here to consider:
+ - If this state is a consistent state with a default action, then
+ the only way this function was invoked is if the default action
+ is an error action. In that case, don't check for expected
+ tokens because there are none.
+ - The only way there can be no lookahead present (in yychar) is if
+ this state is a consistent state with a default action. Thus,
+ detecting the absence of a lookahead is sufficient to determine
+ that there is no unexpected or expected token to report. In that
+ case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this state is a
+ consistent state with a default action. There might have been a
+ previous inconsistent state, consistent state with a non-default
+ action, or user semantic action that manipulated yychar.
+ In the first two cases, it might appear that the current syntax
+ error should have been detected in the previous state when yy_lac
+ was invoked. However, at that time, there might have been a
+ different syntax error that discarded a different initial context
+ during error recovery, leaving behind the current lookahead.
+ */
+ if (yytoken != YYEMPTY)
+ {
+ int yyn = yypact[*yyssp];
+ YYDPRINTF ((stderr, "Constructing syntax error message\n"));
+ yyarg[yycount++] = yytname[yytoken];
+ if (!yypact_value_is_default (yyn))
+ {
+ int yyx;
+
+ for (yyx = 0; yyx < YYNTOKENS; ++yyx)
+ if (yyx != YYTERROR && yyx != YYUNDEFTOK)
+ {
+ {
+ int yy_lac_status = yy_lac (yyesa, yyes, yyes_capacity,
+ yyssp, yyx);
+ if (yy_lac_status == 2)
+ return 2;
+ if (yy_lac_status == 1)
+ continue;
+ }
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ yysize = yysize0;
+ break;
+ }
+ yyarg[yycount++] = yytname[yyx];
+ {
+ YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
+ if (! (yysize <= yysize1
+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
+ }
+ }
+# if GRAM_DEBUG
+ else if (yydebug)
+ YYFPRINTF (stderr, "No expected tokens.\n");
+# endif
+ }
+
+ switch (yycount)
+ {
+# define YYCASE_(N, S) \
+ case N: \
+ yyformat = S; \
+ break
+ YYCASE_(0, YY_("syntax error"));
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+# undef YYCASE_
+ }
+
+ {
+ YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
+
+ if (*yymsg_alloc < yysize)
+ {
+ *yymsg_alloc = 2 * yysize;
+ if (! (yysize <= *yymsg_alloc
+ && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
+ *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
+ return 1;
+ }
+
+ /* Avoid sprintf, as that infringes on the user's name space.
+ Don't have undefined behavior even if the translation
+ produced a string with the wrong number of "%s"s. */
+ {
+ char *yyp = *yymsg;
+ int yyi = 0;
+ while ((*yyp = *yyformat) != '\0')
+ if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
+ {
+ yyp += yytnamerr (yyp, yyarg[yyi++]);
+ yyformat += 2;
+ }
+ else
+ {
+ yyp++;
+ yyformat++;
+ }
+ }
+ return 0;
+}
+#endif /* YYERROR_VERBOSE */
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+static void
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
+{
+ YYUSE (yyvaluep);
+ YYUSE (yylocationp);
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ YYUSE (yytype);
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+int
+yyparse (void)
+{
+/* The lookahead symbol. */
+int yychar;
+
+
+/* The semantic value of the lookahead symbol. */
+/* Default value used for initialization, for pacifying older GCCs
+ or non-GCC compilers. */
+YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
+YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
+
+/* Location data for the lookahead symbol. */
+static YYLTYPE yyloc_default
+# if defined GRAM_LTYPE_IS_TRIVIAL && GRAM_LTYPE_IS_TRIVIAL
+ = { 1, 1, 1, 1 }
+# endif
+;
+YYLTYPE yylloc = yyloc_default;
+
+ /* Number of syntax errors so far. */
+ int yynerrs;
+
+ int yystate;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus;
+
+ /* The stacks and their tools:
+ 'yyss': related to states.
+ 'yyvs': related to semantic values.
+ 'yyls': related to locations.
+
+ Refer to the stacks through separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* The state stack. */
+ yytype_int16 yyssa[YYINITDEPTH];
+ yytype_int16 *yyss;
+ yytype_int16 *yyssp;
+
+ /* The semantic value stack. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs;
+ YYSTYPE *yyvsp;
+
+ /* The location stack. */
+ YYLTYPE yylsa[YYINITDEPTH];
+ YYLTYPE *yyls;
+ YYLTYPE *yylsp;
+
+ /* The locations where the error started and ended. */
+ YYLTYPE yyerror_range[3];
+
+ YYSIZE_T yystacksize;
+
+ yytype_int16 yyesa[20];
+ yytype_int16 *yyes;
+ YYSIZE_T yyes_capacity;
+
+ int yy_lac_established = 0;
+ int yyn;
+ int yyresult;
+ /* Lookahead token as an internal (translated) token number. */
+ int yytoken = 0;
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+ YYLTYPE yyloc;
+
+#if YYERROR_VERBOSE
+ /* Buffer for error messages, and its allocated size. */
+ char yymsgbuf[128];
+ char *yymsg = yymsgbuf;
+ YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
+#endif
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ yyssp = yyss = yyssa;
+ yyvsp = yyvs = yyvsa;
+ yylsp = yyls = yylsa;
+ yystacksize = YYINITDEPTH;
+
+ yyes = yyesa;
+ yyes_capacity = sizeof yyesa / sizeof *yyes;
+ if (YYMAXDEPTH < yyes_capacity)
+ yyes_capacity = YYMAXDEPTH;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yystate = 0;
+ yyerrstatus = 0;
+ yynerrs = 0;
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+/* User initialization code. */
+#line 108 "src/parse-gram.y" /* yacc.c:1429 */
+{
+ /* Bison's grammar can initial empty locations, hence a default
+ location is needed. */
+ boundary_set (&yylloc.start, current_file, 1, 1);
+ boundary_set (&yylloc.end, current_file, 1, 1);
+}
+
+#line 1833 "src/parse-gram.c" /* yacc.c:1429 */
+ yylsp[0] = yylloc;
+ goto yysetstate;
+
+/*------------------------------------------------------------.
+| yynewstate -- Push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+ yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+ yysetstate:
+ *yyssp = yystate;
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYSIZE_T yysize = yyssp - yyss + 1;
+
+#ifdef yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ YYSTYPE *yyvs1 = yyvs;
+ yytype_int16 *yyss1 = yyss;
+ YYLTYPE *yyls1 = yyls;
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * sizeof (*yyssp),
+ &yyvs1, yysize * sizeof (*yyvsp),
+ &yyls1, yysize * sizeof (*yylsp),
+ &yystacksize);
+
+ yyls = yyls1;
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+#else /* no yyoverflow */
+# ifndef YYSTACK_RELOCATE
+ goto yyexhaustedlab;
+# else
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ goto yyexhaustedlab;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yytype_int16 *yyss1 = yyss;
+ union yyalloc *yyptr =
+ (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
+ if (! yyptr)
+ goto yyexhaustedlab;
+ YYSTACK_RELOCATE (yyss_alloc, yyss);
+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);
+ YYSTACK_RELOCATE (yyls_alloc, yyls);
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+#endif /* no yyoverflow */
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+ yylsp = yyls + yysize - 1;
+
+ YYDPRINTF ((stderr, "Stack size increased to %lu\n",
+ (unsigned long int) yystacksize));
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+
+ if (yystate == YYFINAL)
+ YYACCEPT;
+
+ goto yybackup;
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+
+ /* Do appropriate processing given the current state. Read a
+ lookahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to lookahead token. */
+ yyn = yypact[yystate];
+ if (yypact_value_is_default (yyn))
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token: "));
+ yychar = yylex (&yylval, &yylloc);
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ {
+ YY_LAC_ESTABLISH;
+ goto yydefault;
+ }
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yytable_value_is_error (yyn))
+ goto yyerrlab;
+ YY_LAC_ESTABLISH;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the lookahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the shifted token. */
+ yychar = YYEMPTY;
+ YY_LAC_DISCARD ("shift");
+
+ yystate = yyn;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+ *++yylsp = yylloc;
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- Do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ '$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+ /* Default location. */
+ YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
+ YY_REDUCE_PRINT (yyn);
+ {
+ int yychar_backup = yychar;
+ switch (yyn)
+ {
+ case 6:
+#line 280 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
+ translate_code ((yyvsp[0].code), (yylsp[0]), true), (yylsp[0]));
+ code_scanner_last_string_free ();
+ }
+#line 2033 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 7:
+#line 286 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ muscle_percent_define_ensure ((yyvsp[0].uniqstr), (yylsp[0]), true);
+ }
+#line 2041 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 8:
+#line 290 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ muscle_percent_define_insert ((yyvsp[-1].uniqstr), (yylsp[-1]), (yyvsp[0].value).kind, (yyvsp[0].value).chars,
+ MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
+ }
+#line 2050 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 9:
+#line 294 "src/parse-gram.y" /* yacc.c:1646 */
+ { defines_flag = true; }
+#line 2056 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 10:
+#line 296 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ defines_flag = true;
+ spec_defines_file = xstrdup ((yyvsp[0].code));
+ }
+#line 2065 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 11:
+#line 301 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ muscle_percent_define_insert ("parse.error", (yylsp[0]), muscle_keyword,
+ "verbose",
+ MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
+ }
+#line 2075 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 12:
+#line 306 "src/parse-gram.y" /* yacc.c:1646 */
+ { expected_sr_conflicts = (yyvsp[0].integer); }
+#line 2081 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 13:
+#line 307 "src/parse-gram.y" /* yacc.c:1646 */
+ { expected_rr_conflicts = (yyvsp[0].integer); }
+#line 2087 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 14:
+#line 308 "src/parse-gram.y" /* yacc.c:1646 */
+ { spec_file_prefix = (yyvsp[0].code); }
+#line 2093 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 15:
+#line 310 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ nondeterministic_parser = true;
+ glr_parser = true;
+ }
+#line 2102 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 16:
+#line 315 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ muscle_code_grow ("initial_action", translate_code ((yyvsp[0].code), (yylsp[0]), false), (yylsp[0]));
+ code_scanner_last_string_free ();
+ }
+#line 2111 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 17:
+#line 319 "src/parse-gram.y" /* yacc.c:1646 */
+ { language_argmatch ((yyvsp[0].code), grammar_prio, (yylsp[-1])); }
+#line 2117 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 18:
+#line 320 "src/parse-gram.y" /* yacc.c:1646 */
+ { spec_name_prefix = (yyvsp[0].code); }
+#line 2123 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 19:
+#line 321 "src/parse-gram.y" /* yacc.c:1646 */
+ { no_lines_flag = true; }
+#line 2129 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 20:
+#line 322 "src/parse-gram.y" /* yacc.c:1646 */
+ { nondeterministic_parser = true; }
+#line 2135 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 21:
+#line 323 "src/parse-gram.y" /* yacc.c:1646 */
+ { spec_outfile = (yyvsp[0].code); }
+#line 2141 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 22:
+#line 324 "src/parse-gram.y" /* yacc.c:1646 */
+ { current_param = (yyvsp[0].param); }
+#line 2147 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 23:
+#line 324 "src/parse-gram.y" /* yacc.c:1646 */
+ { current_param = param_none; }
+#line 2153 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 24:
+#line 325 "src/parse-gram.y" /* yacc.c:1646 */
+ { version_check (&(yylsp[0]), (yyvsp[0].code)); }
+#line 2159 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 25:
+#line 327 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ char const *skeleton_user = (yyvsp[0].code);
+ if (strchr (skeleton_user, '/'))
+ {
+ size_t dir_length = strlen (current_file);
+ char *skeleton_build;
+ while (dir_length && current_file[dir_length - 1] != '/')
+ --dir_length;
+ while (dir_length && current_file[dir_length - 1] == '/')
+ --dir_length;
+ skeleton_build =
+ xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
+ if (dir_length > 0)
+ {
+ memcpy (skeleton_build, current_file, dir_length);
+ skeleton_build[dir_length++] = '/';
+ }
+ strcpy (skeleton_build + dir_length, skeleton_user);
+ skeleton_user = uniqstr_new (skeleton_build);
+ free (skeleton_build);
+ }
+ skeleton_arg (skeleton_user, grammar_prio, (yylsp[-1]));
+ }
+#line 2187 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 26:
+#line 350 "src/parse-gram.y" /* yacc.c:1646 */
+ { token_table_flag = true; }
+#line 2193 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 27:
+#line 351 "src/parse-gram.y" /* yacc.c:1646 */
+ { report_flag |= report_states; }
+#line 2199 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 28:
+#line 352 "src/parse-gram.y" /* yacc.c:1646 */
+ { yacc_flag = true; }
+#line 2205 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 30:
+#line 357 "src/parse-gram.y" /* yacc.c:1646 */
+ { add_param (current_param, (yyvsp[0].code), (yylsp[0])); }
+#line 2211 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 31:
+#line 358 "src/parse-gram.y" /* yacc.c:1646 */
+ { add_param (current_param, (yyvsp[0].code), (yylsp[0])); }
+#line 2217 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 34:
+#line 370 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ grammar_start_symbol_set ((yyvsp[0].symbol), (yylsp[0]));
+ }
+#line 2225 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 35:
+#line 374 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ code_props code;
+ code_props_symbol_action_init (&code, (yyvsp[-1].code), (yylsp[-1]));
+ code_props_translate_code (&code);
+ {
+ symbol_list *list;
+ for (list = (yyvsp[0].list); list; list = list->next)
+ symbol_list_code_props_set (list, (yyvsp[-2].code_type), &code);
+ symbol_list_free ((yyvsp[0].list));
+ }
+ }
+#line 2241 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 36:
+#line 386 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ default_prec = true;
+ }
+#line 2249 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 37:
+#line 390 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ default_prec = false;
+ }
+#line 2257 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 38:
+#line 394 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ /* Do not invoke muscle_percent_code_grow here since it invokes
+ muscle_user_name_list_grow. */
+ muscle_code_grow ("percent_code()",
+ translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
+ code_scanner_last_string_free ();
+ }
+#line 2269 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 39:
+#line 402 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ muscle_percent_code_grow ((yyvsp[-1].uniqstr), (yylsp[-1]), translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
+ code_scanner_last_string_free ();
+ }
+#line 2278 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 40:
+#line 412 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.code_type) = destructor; }
+#line 2284 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 41:
+#line 413 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.code_type) = printer; }
+#line 2290 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 42:
+#line 423 "src/parse-gram.y" /* yacc.c:1646 */
+ {}
+#line 2296 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 43:
+#line 424 "src/parse-gram.y" /* yacc.c:1646 */
+ { muscle_code_grow ("union_name", (yyvsp[0].uniqstr), (yylsp[0])); }
+#line 2302 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 44:
+#line 429 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ union_seen = true;
+ muscle_code_grow ("union_members", translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
+ code_scanner_last_string_free ();
+ }
+#line 2312 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 45:
+#line 440 "src/parse-gram.y" /* yacc.c:1646 */
+ { current_class = nterm_sym; }
+#line 2318 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 46:
+#line 441 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ current_class = unknown_sym;
+ current_type = NULL;
+ }
+#line 2327 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 47:
+#line 445 "src/parse-gram.y" /* yacc.c:1646 */
+ { current_class = token_sym; }
+#line 2333 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 48:
+#line 446 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ current_class = unknown_sym;
+ current_type = NULL;
+ }
+#line 2342 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 49:
+#line 451 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ symbol_list *list;
+ tag_seen = true;
+ for (list = (yyvsp[0].list); list; list = list->next)
+ symbol_type_set (list->content.sym, (yyvsp[-1].uniqstr), (yylsp[-1]));
+ symbol_list_free ((yyvsp[0].list));
+ }
+#line 2354 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 50:
+#line 462 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ symbol_list *list;
+ ++current_prec;
+ for (list = (yyvsp[0].list); list; list = list->next)
+ {
+ symbol_type_set (list->content.sym, current_type, (yylsp[-1]));
+ symbol_precedence_set (list->content.sym, current_prec, (yyvsp[-2].assoc), (yylsp[-2]));
+ }
+ symbol_list_free ((yyvsp[0].list));
+ current_type = NULL;
+ }
+#line 2370 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 51:
+#line 476 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.assoc) = left_assoc; }
+#line 2376 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 52:
+#line 477 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.assoc) = right_assoc; }
+#line 2382 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 53:
+#line 478 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.assoc) = non_assoc; }
+#line 2388 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 54:
+#line 479 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.assoc) = precedence_assoc; }
+#line 2394 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 55:
+#line 483 "src/parse-gram.y" /* yacc.c:1646 */
+ { current_type = NULL; }
+#line 2400 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 56:
+#line 484 "src/parse-gram.y" /* yacc.c:1646 */
+ { current_type = (yyvsp[0].uniqstr); tag_seen = true; }
+#line 2406 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 57:
+#line 490 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
+#line 2412 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 58:
+#line 492 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = symbol_list_append ((yyvsp[-1].list), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); }
+#line 2418 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 59:
+#line 497 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ (yyval.symbol) = (yyvsp[0].symbol);
+ symbol_class_set ((yyvsp[0].symbol), token_sym, (yylsp[0]), false);
+ }
+#line 2427 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 60:
+#line 502 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ (yyval.symbol) = (yyvsp[-1].symbol);
+ symbol_user_token_number_set ((yyvsp[-1].symbol), (yyvsp[0].integer), (yylsp[0]));
+ symbol_class_set ((yyvsp[-1].symbol), token_sym, (yylsp[-1]), false);
+ }
+#line 2437 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 61:
+#line 512 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
+#line 2443 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 62:
+#line 514 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = symbol_list_append ((yyvsp[-1].list), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); }
+#line 2449 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 63:
+#line 518 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = (yyvsp[0].list); }
+#line 2455 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 64:
+#line 519 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = symbol_list_append ((yyvsp[-1].list), (yyvsp[0].list)); }
+#line 2461 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 65:
+#line 523 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); }
+#line 2467 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 66:
+#line 524 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.list) = symbol_list_type_new ((yyvsp[0].uniqstr), (yylsp[0])); }
+#line 2473 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 68:
+#line 529 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.uniqstr) = uniqstr_new ("*"); }
+#line 2479 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 69:
+#line 530 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.uniqstr) = uniqstr_new (""); }
+#line 2485 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 70:
+#line 536 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ current_type = (yyvsp[0].uniqstr);
+ tag_seen = true;
+ }
+#line 2494 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 71:
+#line 541 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ symbol_class_set ((yyvsp[0].symbol), current_class, (yylsp[0]), true);
+ symbol_type_set ((yyvsp[0].symbol), current_type, (yylsp[0]));
+ }
+#line 2503 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 72:
+#line 546 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ symbol_class_set ((yyvsp[-1].symbol), current_class, (yylsp[-1]), true);
+ symbol_type_set ((yyvsp[-1].symbol), current_type, (yylsp[-1]));
+ symbol_user_token_number_set ((yyvsp[-1].symbol), (yyvsp[0].integer), (yylsp[0]));
+ }
+#line 2513 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 73:
+#line 552 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ symbol_class_set ((yyvsp[-1].symbol), current_class, (yylsp[-1]), true);
+ symbol_type_set ((yyvsp[-1].symbol), current_type, (yylsp[-1]));
+ symbol_make_alias ((yyvsp[-1].symbol), (yyvsp[0].symbol), (yyloc));
+ }
+#line 2523 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 74:
+#line 558 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ symbol_class_set ((yyvsp[-2].symbol), current_class, (yylsp[-2]), true);
+ symbol_type_set ((yyvsp[-2].symbol), current_type, (yylsp[-2]));
+ symbol_user_token_number_set ((yyvsp[-2].symbol), (yyvsp[-1].integer), (yylsp[-1]));
+ symbol_make_alias ((yyvsp[-2].symbol), (yyvsp[0].symbol), (yyloc));
+ }
+#line 2534 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 81:
+#line 588 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ yyerrok;
+ }
+#line 2542 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 82:
+#line 594 "src/parse-gram.y" /* yacc.c:1646 */
+ { current_lhs ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].named_ref)); }
+#line 2548 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 83:
+#line 595 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ /* Free the current lhs. */
+ current_lhs (0, (yylsp[-3]), 0);
+ }
+#line 2557 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 84:
+#line 602 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_end ((yylsp[0])); }
+#line 2563 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 85:
+#line 603 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_end ((yylsp[0])); }
+#line 2569 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 87:
+#line 610 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location,
+ current_lhs_named_ref); }
+#line 2576 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 88:
+#line 613 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_symbol_append ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].named_ref)); }
+#line 2582 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 89:
+#line 615 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_action_append ((yyvsp[-1].code), (yylsp[-1]), (yyvsp[0].named_ref), false); }
+#line 2588 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 90:
+#line 617 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_action_append ((yyvsp[0].code), (yylsp[0]), NULL, true); }
+#line 2594 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 91:
+#line 619 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_empty_set ((yylsp[0])); }
+#line 2600 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 92:
+#line 621 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_prec_set ((yyvsp[0].symbol), (yylsp[0])); }
+#line 2606 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 93:
+#line 623 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_dprec_set ((yyvsp[0].integer), (yylsp[0])); }
+#line 2612 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 94:
+#line 625 "src/parse-gram.y" /* yacc.c:1646 */
+ { grammar_current_rule_merge_set ((yyvsp[0].uniqstr), (yylsp[0])); }
+#line 2618 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 95:
+#line 629 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.named_ref) = 0; }
+#line 2624 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 96:
+#line 630 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.named_ref) = named_ref_new ((yyvsp[0].uniqstr), (yylsp[0])); }
+#line 2630 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 98:
+#line 641 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.uniqstr) = uniqstr_new ((yyvsp[0].code)); }
+#line 2636 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 99:
+#line 666 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.value).kind = muscle_keyword; (yyval.value).chars = ""; }
+#line 2642 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 100:
+#line 667 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.value).kind = muscle_keyword; (yyval.value).chars = (yyvsp[0].uniqstr); }
+#line 2648 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 101:
+#line 668 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.value).kind = muscle_string; (yyval.value).chars = (yyvsp[0].code); }
+#line 2654 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 102:
+#line 669 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.value).kind = muscle_code; (yyval.value).chars = strip_braces ((yyvsp[0].code)); }
+#line 2660 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 103:
+#line 682 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[0].uniqstr), (yylsp[0])); }
+#line 2666 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 104:
+#line 684 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ (yyval.symbol) = symbol_get (char_name ((yyvsp[0].character)), (yylsp[0]));
+ symbol_class_set ((yyval.symbol), token_sym, (yylsp[0]), false);
+ symbol_user_token_number_set ((yyval.symbol), (yyvsp[0].character), (yylsp[0]));
+ }
+#line 2676 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 105:
+#line 692 "src/parse-gram.y" /* yacc.c:1646 */
+ { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[0].uniqstr), (yylsp[0])); }
+#line 2682 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 108:
+#line 704 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[0].code)), (yylsp[0]));
+ symbol_class_set ((yyval.symbol), token_sym, (yylsp[0]), false);
+ }
+#line 2691 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+ case 110:
+#line 713 "src/parse-gram.y" /* yacc.c:1646 */
+ {
+ muscle_code_grow ("epilogue", translate_code ((yyvsp[0].code), (yylsp[0]), true), (yylsp[0]));
+ code_scanner_last_string_free ();
+ }
+#line 2700 "src/parse-gram.c" /* yacc.c:1646 */
+ break;
+
+
+#line 2704 "src/parse-gram.c" /* yacc.c:1646 */
+ default: break;
+ }
+ if (yychar_backup != yychar)
+ YY_LAC_DISCARD ("yychar change");
+ }
+ /* User semantic actions sometimes alter yychar, and that requires
+ that yytoken be updated with the new translation. We take the
+ approach of translating immediately before every use of yytoken.
+ One alternative is translating here after every semantic action,
+ but that translation would be missed if the semantic action invokes
+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
+ incorrect destructor might then be invoked immediately. In the
+ case of YYERROR or YYBACKUP, subsequent parser actions might lead
+ to an incorrect destructor call or verbose syntax error message
+ before the lookahead is translated. */
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+
+ *++yyvsp = yyval;
+ *++yylsp = yyloc;
+
+ /* Now 'shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+
+ yyn = yyr1[yyn];
+
+ yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
+ if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
+ yystate = yytable[yystate];
+ else
+ yystate = yydefgoto[yyn - YYNTOKENS];
+
+ goto yynewstate;
+
+
+/*--------------------------------------.
+| yyerrlab -- here on detecting error. |
+`--------------------------------------*/
+yyerrlab:
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
+
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+#if ! YYERROR_VERBOSE
+ yyerror (&yylloc, YY_("syntax error"));
+#else
+# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
+ yyesa, &yyes, &yyes_capacity, \
+ yyssp, yytoken)
+ {
+ char const *yymsgp = YY_("syntax error");
+ int yysyntax_error_status;
+ if (yychar != YYEMPTY)
+ YY_LAC_ESTABLISH;
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ if (yysyntax_error_status == 0)
+ yymsgp = yymsg;
+ else if (yysyntax_error_status == 1)
+ {
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+ yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
+ if (!yymsg)
+ {
+ yymsg = yymsgbuf;
+ yymsg_alloc = sizeof yymsgbuf;
+ yysyntax_error_status = 2;
+ }
+ else
+ {
+ yysyntax_error_status = YYSYNTAX_ERROR;
+ yymsgp = yymsg;
+ }
+ }
+ yyerror (&yylloc, yymsgp);
+ if (yysyntax_error_status == 2)
+ goto yyexhaustedlab;
+ }
+# undef YYSYNTAX_ERROR
+#endif
+ }
+
+ yyerror_range[1] = yylloc;
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval, &yylloc);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (/*CONSTCOND*/ 0)
+ goto yyerrorlab;
+
+ yyerror_range[1] = yylsp[1-yylen];
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (!yypact_value_is_default (yyn))
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+ yyerror_range[1] = *yylsp;
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp, yylsp);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ /* If the stack popping above didn't lose the initial context for the
+ current lookahead token, the shift below will for sure. */
+ YY_LAC_DISCARD ("error recovery");
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+
+ yyerror_range[2] = yylloc;
+ /* Using YYLLOC is tempting, but would change the location of
+ the lookahead. YYLOC is available though. */
+ YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
+ *++yylsp = yyloc;
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+#if 1
+/*-------------------------------------------------.
+| yyexhaustedlab -- memory exhaustion comes here. |
+`-------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (&yylloc, YY_("memory exhausted"));
+ yyresult = 2;
+ /* Fall through. */
+#endif
+
+yyreturn:
+ if (yychar != YYEMPTY)
+ {
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = YYTRANSLATE (yychar);
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval, &yylloc);
+ }
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ yystos[*yyssp], yyvsp, yylsp);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+ if (yyes != yyesa)
+ YYSTACK_FREE (yyes);
+#if YYERROR_VERBOSE
+ if (yymsg != yymsgbuf)
+ YYSTACK_FREE (yymsg);
+#endif
+ return yyresult;
+}
+#line 719 "src/parse-gram.y" /* yacc.c:1906 */
+
+
+/* Return the location of the left-hand side of a rule whose
+ right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
+ the right-hand side, and return an empty location equal to the end
+ boundary of RHS[0] if the right-hand side is empty. */
+
+static YYLTYPE
+lloc_default (YYLTYPE const *rhs, int n)
+{
+ int i;
+ YYLTYPE loc;
+
+ /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
+ The bug is fixed in 7.4.2m, but play it safe for now. */
+ loc.start = rhs[n].end;
+ loc.end = rhs[n].end;
+
+ /* Ignore empty nonterminals the start of the right-hand side.
+ Do not bother to ignore them at the end of the right-hand side,
+ since empty nonterminals have the same end as their predecessors. */
+ for (i = 1; i <= n; i++)
+ if (! equal_boundaries (rhs[i].start, rhs[i].end))
+ {
+ loc.start = rhs[i].start;
+ break;
+ }
+
+ return loc;
+}
+
+static
+char *strip_braces (char *code)
+{
+ code[strlen (code) - 1] = 0;
+ return code + 1;
+}
+
+static
+char const *
+translate_code (char *code, location loc, bool plain)
+{
+ code_props plain_code;
+ if (plain)
+ code_props_plain_init (&plain_code, code, loc);
+ else
+ code_props_symbol_action_init (&plain_code, code, loc);
+ code_props_translate_code (&plain_code);
+ gram_scanner_last_string_free ();
+ return plain_code.code;
+}
+
+static
+char const *
+translate_code_braceless (char *code, location loc)
+{
+ return translate_code (strip_braces (code), loc, true);
+}
+
+static void
+add_param (param_type type, char *decl, location loc)
+{
+ static char const alphanum[26 + 26 + 1 + 10] =
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "_"
+ "0123456789";
+
+ char const *name_start = NULL;
+ {
+ char *p;
+ /* Stop on last actual character. */
+ for (p = decl; p[1]; p++)
+ if ((p == decl
+ || ! memchr (alphanum, p[-1], sizeof alphanum))
+ && memchr (alphanum, p[0], sizeof alphanum - 10))
+ name_start = p;
+
+ /* Strip the surrounding '{' and '}', and any blanks just inside
+ the braces. */
+ --p;
+ while (c_isspace ((unsigned char) *p))
+ --p;
+ p[1] = '\0';
+ ++decl;
+ while (c_isspace ((unsigned char) *decl))
+ ++decl;
+ }
+
+ if (! name_start)
+ complain (&loc, complaint, _("missing identifier in parameter declaration"));
+ else
+ {
+ char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
+ if (type & param_lex)
+ muscle_pair_list_grow ("lex_param", decl, name);
+ if (type & param_parse)
+ muscle_pair_list_grow ("parse_param", decl, name);
+ free (name);
+ }
+
+ gram_scanner_last_string_free ();
+}
+
+
+static void
+version_check (location const *loc, char const *version)
+{
+ if (strverscmp (version, PACKAGE_VERSION) > 0)
+ {
+ complain (loc, complaint, "require bison %s, but have %s",
+ version, PACKAGE_VERSION);
+ exit (EX_MISMATCH);
+ }
+}
+
+static void
+gram_error (location const *loc, char const *msg)
+{
+ complain (loc, complaint, "%s", msg);
+}
+
+char const *
+token_name (int type)
+{
+ return yytname[YYTRANSLATE (type)];
+}
+
+static char const *
+char_name (char c)
+{
+ if (c == '\'')
+ return "'\\''";
+ else
+ {
+ char buf[4];
+ buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
+ return quotearg_style (escape_quoting_style, buf);
+ }
+}
+
+static
+void
+current_lhs (symbol *sym, location loc, named_ref *ref)
+{
+ current_lhs_symbol = sym;
+ current_lhs_location = loc;
+ /* In order to simplify memory management, named references for lhs
+ are always assigned by deep copy into the current symbol_list
+ node. This is because a single named-ref in the grammar may
+ result in several uses when the user factors lhs between several
+ rules using "|". Therefore free the parser's original copy. */
+ free (current_lhs_named_ref);
+ current_lhs_named_ref = ref;
+}
diff --git a/contrib/tools/bison/bison/src/parse-gram.h b/contrib/tools/bison/bison/src/parse-gram.h
index 09358961d3..fb0c026358 100644
--- a/contrib/tools/bison/bison/src/parse-gram.h
+++ b/contrib/tools/bison/bison/src/parse-gram.h
@@ -1,190 +1,190 @@
-/* A Bison parser, made by GNU Bison 3.0. */
-
-/* Bison interface for Yacc-like parsers in C
-
- Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* As a special exception, you may create a larger work that contains
- part or all of the Bison parser skeleton and distribute that work
- under terms of your choice, so long as that work isn't itself a
- parser generator using the skeleton or a modified version thereof
- as a parser skeleton. Alternatively, if you modify or redistribute
- the parser skeleton itself, you may (at your option) remove this
- special exception, which will cause the skeleton and the resulting
- Bison output files to be licensed under the GNU General Public
- License without this special exception.
-
- This special exception was added by the Free Software Foundation in
- version 2.2 of Bison. */
-
-#ifndef YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
-# define YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
-/* Debug traces. */
-#ifndef GRAM_DEBUG
-# if defined YYDEBUG
-#if YYDEBUG
-# define GRAM_DEBUG 1
-# else
-# define GRAM_DEBUG 0
-# endif
-# else /* ! defined YYDEBUG */
-# define GRAM_DEBUG 1
-# endif /* ! defined YYDEBUG */
-#endif /* ! defined GRAM_DEBUG */
-#if GRAM_DEBUG
-extern int gram_debug;
-#endif
-/* "%code requires" blocks. */
-#line 21 "src/parse-gram.y" /* yacc.c:1909 */
-
- #include "symlist.h"
- #include "symtab.h"
-#line 221 "src/parse-gram.y" /* yacc.c:1909 */
-
- typedef enum
- {
- param_none = 0,
- param_lex = 1 << 0,
- param_parse = 1 << 1,
- param_both = param_lex | param_parse
- } param_type;
-#line 645 "src/parse-gram.y" /* yacc.c:1909 */
-#include "muscle-tab.h"
-
-#line 68 "src/parse-gram.h" /* yacc.c:1909 */
-
-/* Token type. */
-#ifndef GRAM_TOKENTYPE
-# define GRAM_TOKENTYPE
- enum gram_tokentype
- {
- GRAM_EOF = 0,
- STRING = 258,
- PERCENT_TOKEN = 259,
- PERCENT_NTERM = 260,
- PERCENT_TYPE = 261,
- PERCENT_DESTRUCTOR = 262,
- PERCENT_PRINTER = 263,
- PERCENT_LEFT = 264,
- PERCENT_RIGHT = 265,
- PERCENT_NONASSOC = 266,
- PERCENT_PRECEDENCE = 267,
- PERCENT_PREC = 268,
- PERCENT_DPREC = 269,
- PERCENT_MERGE = 270,
- PERCENT_CODE = 271,
- PERCENT_DEFAULT_PREC = 272,
- PERCENT_DEFINE = 273,
- PERCENT_DEFINES = 274,
- PERCENT_ERROR_VERBOSE = 275,
- PERCENT_EXPECT = 276,
- PERCENT_EXPECT_RR = 277,
- PERCENT_FLAG = 278,
- PERCENT_FILE_PREFIX = 279,
- PERCENT_GLR_PARSER = 280,
- PERCENT_INITIAL_ACTION = 281,
- PERCENT_LANGUAGE = 282,
- PERCENT_NAME_PREFIX = 283,
- PERCENT_NO_DEFAULT_PREC = 284,
- PERCENT_NO_LINES = 285,
- PERCENT_NONDETERMINISTIC_PARSER = 286,
- PERCENT_OUTPUT = 287,
- PERCENT_REQUIRE = 288,
- PERCENT_SKELETON = 289,
- PERCENT_START = 290,
- PERCENT_TOKEN_TABLE = 291,
- PERCENT_VERBOSE = 292,
- PERCENT_YACC = 293,
- BRACED_CODE = 294,
- BRACED_PREDICATE = 295,
- BRACKETED_ID = 296,
- CHAR = 297,
- EPILOGUE = 298,
- EQUAL = 299,
- ID = 300,
- ID_COLON = 301,
- PERCENT_PERCENT = 302,
- PIPE = 303,
- PROLOGUE = 304,
- SEMICOLON = 305,
- TAG = 306,
- TAG_ANY = 307,
- TAG_NONE = 308,
- INT = 309,
- PERCENT_PARAM = 310,
- PERCENT_UNION = 311,
- PERCENT_EMPTY = 312
- };
-#endif
-
-/* Value type. */
-#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED
-typedef union GRAM_STYPE GRAM_STYPE;
-union GRAM_STYPE
-{
-#line 182 "src/parse-gram.y" /* yacc.c:1909 */
-unsigned char character;
-#line 186 "src/parse-gram.y" /* yacc.c:1909 */
-char *code;
-#line 191 "src/parse-gram.y" /* yacc.c:1909 */
-uniqstr uniqstr;
-#line 199 "src/parse-gram.y" /* yacc.c:1909 */
-int integer;
-#line 203 "src/parse-gram.y" /* yacc.c:1909 */
-symbol *symbol;
-#line 208 "src/parse-gram.y" /* yacc.c:1909 */
-assoc assoc;
-#line 211 "src/parse-gram.y" /* yacc.c:1909 */
-symbol_list *list;
-#line 214 "src/parse-gram.y" /* yacc.c:1909 */
-named_ref *named_ref;
-#line 241 "src/parse-gram.y" /* yacc.c:1909 */
-param_type param;
-#line 409 "src/parse-gram.y" /* yacc.c:1909 */
-code_props_type code_type;
-#line 647 "src/parse-gram.y" /* yacc.c:1909 */
-
- struct
- {
- char const *chars;
- muscle_kind kind;
- } value;
-
-#line 167 "src/parse-gram.h" /* yacc.c:1909 */
-};
-# define GRAM_STYPE_IS_TRIVIAL 1
-# define GRAM_STYPE_IS_DECLARED 1
-#endif
-
-/* Location type. */
-#if ! defined GRAM_LTYPE && ! defined GRAM_LTYPE_IS_DECLARED
-typedef struct GRAM_LTYPE GRAM_LTYPE;
-struct GRAM_LTYPE
-{
- int first_line;
- int first_column;
- int last_line;
- int last_column;
-};
-# define GRAM_LTYPE_IS_DECLARED 1
-# define GRAM_LTYPE_IS_TRIVIAL 1
-#endif
-
-
-
-int gram_parse (void);
-
-#endif /* !YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED */
+/* A Bison parser, made by GNU Bison 3.0. */
+
+/* Bison interface for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+#ifndef YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
+# define YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
+/* Debug traces. */
+#ifndef GRAM_DEBUG
+# if defined YYDEBUG
+#if YYDEBUG
+# define GRAM_DEBUG 1
+# else
+# define GRAM_DEBUG 0
+# endif
+# else /* ! defined YYDEBUG */
+# define GRAM_DEBUG 1
+# endif /* ! defined YYDEBUG */
+#endif /* ! defined GRAM_DEBUG */
+#if GRAM_DEBUG
+extern int gram_debug;
+#endif
+/* "%code requires" blocks. */
+#line 21 "src/parse-gram.y" /* yacc.c:1909 */
+
+ #include "symlist.h"
+ #include "symtab.h"
+#line 221 "src/parse-gram.y" /* yacc.c:1909 */
+
+ typedef enum
+ {
+ param_none = 0,
+ param_lex = 1 << 0,
+ param_parse = 1 << 1,
+ param_both = param_lex | param_parse
+ } param_type;
+#line 645 "src/parse-gram.y" /* yacc.c:1909 */
+#include "muscle-tab.h"
+
+#line 68 "src/parse-gram.h" /* yacc.c:1909 */
+
+/* Token type. */
+#ifndef GRAM_TOKENTYPE
+# define GRAM_TOKENTYPE
+ enum gram_tokentype
+ {
+ GRAM_EOF = 0,
+ STRING = 258,
+ PERCENT_TOKEN = 259,
+ PERCENT_NTERM = 260,
+ PERCENT_TYPE = 261,
+ PERCENT_DESTRUCTOR = 262,
+ PERCENT_PRINTER = 263,
+ PERCENT_LEFT = 264,
+ PERCENT_RIGHT = 265,
+ PERCENT_NONASSOC = 266,
+ PERCENT_PRECEDENCE = 267,
+ PERCENT_PREC = 268,
+ PERCENT_DPREC = 269,
+ PERCENT_MERGE = 270,
+ PERCENT_CODE = 271,
+ PERCENT_DEFAULT_PREC = 272,
+ PERCENT_DEFINE = 273,
+ PERCENT_DEFINES = 274,
+ PERCENT_ERROR_VERBOSE = 275,
+ PERCENT_EXPECT = 276,
+ PERCENT_EXPECT_RR = 277,
+ PERCENT_FLAG = 278,
+ PERCENT_FILE_PREFIX = 279,
+ PERCENT_GLR_PARSER = 280,
+ PERCENT_INITIAL_ACTION = 281,
+ PERCENT_LANGUAGE = 282,
+ PERCENT_NAME_PREFIX = 283,
+ PERCENT_NO_DEFAULT_PREC = 284,
+ PERCENT_NO_LINES = 285,
+ PERCENT_NONDETERMINISTIC_PARSER = 286,
+ PERCENT_OUTPUT = 287,
+ PERCENT_REQUIRE = 288,
+ PERCENT_SKELETON = 289,
+ PERCENT_START = 290,
+ PERCENT_TOKEN_TABLE = 291,
+ PERCENT_VERBOSE = 292,
+ PERCENT_YACC = 293,
+ BRACED_CODE = 294,
+ BRACED_PREDICATE = 295,
+ BRACKETED_ID = 296,
+ CHAR = 297,
+ EPILOGUE = 298,
+ EQUAL = 299,
+ ID = 300,
+ ID_COLON = 301,
+ PERCENT_PERCENT = 302,
+ PIPE = 303,
+ PROLOGUE = 304,
+ SEMICOLON = 305,
+ TAG = 306,
+ TAG_ANY = 307,
+ TAG_NONE = 308,
+ INT = 309,
+ PERCENT_PARAM = 310,
+ PERCENT_UNION = 311,
+ PERCENT_EMPTY = 312
+ };
+#endif
+
+/* Value type. */
+#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED
+typedef union GRAM_STYPE GRAM_STYPE;
+union GRAM_STYPE
+{
+#line 182 "src/parse-gram.y" /* yacc.c:1909 */
+unsigned char character;
+#line 186 "src/parse-gram.y" /* yacc.c:1909 */
+char *code;
+#line 191 "src/parse-gram.y" /* yacc.c:1909 */
+uniqstr uniqstr;
+#line 199 "src/parse-gram.y" /* yacc.c:1909 */
+int integer;
+#line 203 "src/parse-gram.y" /* yacc.c:1909 */
+symbol *symbol;
+#line 208 "src/parse-gram.y" /* yacc.c:1909 */
+assoc assoc;
+#line 211 "src/parse-gram.y" /* yacc.c:1909 */
+symbol_list *list;
+#line 214 "src/parse-gram.y" /* yacc.c:1909 */
+named_ref *named_ref;
+#line 241 "src/parse-gram.y" /* yacc.c:1909 */
+param_type param;
+#line 409 "src/parse-gram.y" /* yacc.c:1909 */
+code_props_type code_type;
+#line 647 "src/parse-gram.y" /* yacc.c:1909 */
+
+ struct
+ {
+ char const *chars;
+ muscle_kind kind;
+ } value;
+
+#line 167 "src/parse-gram.h" /* yacc.c:1909 */
+};
+# define GRAM_STYPE_IS_TRIVIAL 1
+# define GRAM_STYPE_IS_DECLARED 1
+#endif
+
+/* Location type. */
+#if ! defined GRAM_LTYPE && ! defined GRAM_LTYPE_IS_DECLARED
+typedef struct GRAM_LTYPE GRAM_LTYPE;
+struct GRAM_LTYPE
+{
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
+};
+# define GRAM_LTYPE_IS_DECLARED 1
+# define GRAM_LTYPE_IS_TRIVIAL 1
+#endif
+
+
+
+int gram_parse (void);
+
+#endif /* !YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED */
diff --git a/contrib/tools/bison/bison/src/parse-gram.y b/contrib/tools/bison/bison/src/parse-gram.y
index 8c438dfeda..300de25f6d 100644
--- a/contrib/tools/bison/bison/src/parse-gram.y
+++ b/contrib/tools/bison/bison/src/parse-gram.y
@@ -1,874 +1,874 @@
-/* Bison Grammar Parser -*- C -*-
-
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-%code requires
-{
- #include "symlist.h"
- #include "symtab.h"
-}
-
-%code top
-{
- /* On column 0 to please syntax-check. */
-#include <config.h>
+/* Bison Grammar Parser -*- C -*-
+
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+%code requires
+{
+ #include "symlist.h"
+ #include "symtab.h"
+}
+
+%code top
+{
+ /* On column 0 to please syntax-check. */
+#include <config.h>
#include "string--.h"
-}
-
-%code
-{
- #include "system.h"
-
- #include "c-ctype.h"
- #include "complain.h"
- #include "conflicts.h"
- #include "files.h"
- #include "getargs.h"
- #include "gram.h"
- #include "named-ref.h"
- #include "quotearg.h"
- #include "reader.h"
- #include "scan-gram.h"
- #include "scan-code.h"
- #include "xmemdup0.h"
-
- static int current_prec = 0;
- static location current_lhs_location;
- static named_ref *current_lhs_named_ref;
- static symbol *current_lhs_symbol;
- static symbol_class current_class = unknown_sym;
- static uniqstr current_type = NULL;
-
- /** Set the new current left-hand side symbol, possibly common
- * to several right-hand side parts of rule.
- */
- static void current_lhs (symbol *sym, location loc, named_ref *ref);
-
- #define YYLLOC_DEFAULT(Current, Rhs, N) \
- (Current) = lloc_default (Rhs, N)
- static YYLTYPE lloc_default (YYLTYPE const *, int);
-
- #define YY_LOCATION_PRINT(File, Loc) \
- location_print (Loc, File)
-
- /* Strip initial '{' and final '}' (must be first and last characters).
- Return the result. */
- static char *strip_braces (char *code);
-
- /* Convert CODE by calling code_props_plain_init if PLAIN, otherwise
- code_props_symbol_action_init. Call
- gram_scanner_last_string_free to release the latest string from
- the scanner (should be CODE). */
- static char const *translate_code (char *code, location loc, bool plain);
-
- /* Convert CODE by calling code_props_plain_init after having
- stripped the first and last characters (expected to be '{', and
- '}'). Call gram_scanner_last_string_free to release the latest
- string from the scanner (should be CODE). */
- static char const *translate_code_braceless (char *code, location loc);
-
- static void version_check (location const *loc, char const *version);
-
- static void gram_error (location const *, char const *);
-
- /* A string that describes a char (e.g., 'a' -> "'a'"). */
- static char const *char_name (char);
-
- #define YYTYPE_INT16 int_fast16_t
- #define YYTYPE_INT8 int_fast8_t
- #define YYTYPE_UINT16 uint_fast16_t
- #define YYTYPE_UINT8 uint_fast8_t
-}
-
-%define api.prefix {gram_}
-%define api.pure full
-%define locations
-%define parse.error verbose
-%define parse.lac full
-%define parse.trace
-%defines
-%expect 0
-%verbose
-
-%initial-action
-{
- /* Bison's grammar can initial empty locations, hence a default
- location is needed. */
- boundary_set (&@$.start, current_file, 1, 1);
- boundary_set (&@$.end, current_file, 1, 1);
-}
-
-/* Define the tokens together with their human representation. */
-%token GRAM_EOF 0 "end of file"
-%token STRING "string"
-
-%token PERCENT_TOKEN "%token"
-%token PERCENT_NTERM "%nterm"
-
-%token PERCENT_TYPE "%type"
-%token PERCENT_DESTRUCTOR "%destructor"
-%token PERCENT_PRINTER "%printer"
-
-%token PERCENT_LEFT "%left"
-%token PERCENT_RIGHT "%right"
-%token PERCENT_NONASSOC "%nonassoc"
-%token PERCENT_PRECEDENCE "%precedence"
-
-%token PERCENT_PREC "%prec"
-%token PERCENT_DPREC "%dprec"
-%token PERCENT_MERGE "%merge"
-
-/*----------------------.
-| Global Declarations. |
-`----------------------*/
-
-%token
- PERCENT_CODE "%code"
- PERCENT_DEFAULT_PREC "%default-prec"
- PERCENT_DEFINE "%define"
- PERCENT_DEFINES "%defines"
- PERCENT_ERROR_VERBOSE "%error-verbose"
- PERCENT_EXPECT "%expect"
- PERCENT_EXPECT_RR "%expect-rr"
- PERCENT_FLAG "%<flag>"
- PERCENT_FILE_PREFIX "%file-prefix"
- PERCENT_GLR_PARSER "%glr-parser"
- PERCENT_INITIAL_ACTION "%initial-action"
- PERCENT_LANGUAGE "%language"
- PERCENT_NAME_PREFIX "%name-prefix"
- PERCENT_NO_DEFAULT_PREC "%no-default-prec"
- PERCENT_NO_LINES "%no-lines"
- PERCENT_NONDETERMINISTIC_PARSER
- "%nondeterministic-parser"
- PERCENT_OUTPUT "%output"
- PERCENT_REQUIRE "%require"
- PERCENT_SKELETON "%skeleton"
- PERCENT_START "%start"
- PERCENT_TOKEN_TABLE "%token-table"
- PERCENT_VERBOSE "%verbose"
- PERCENT_YACC "%yacc"
-;
-
-%token BRACED_CODE "{...}"
-%token BRACED_PREDICATE "%?{...}"
-%token BRACKETED_ID "[identifier]"
-%token CHAR "char"
-%token EPILOGUE "epilogue"
-%token EQUAL "="
-%token ID "identifier"
-%token ID_COLON "identifier:"
-%token PERCENT_PERCENT "%%"
-%token PIPE "|"
-%token PROLOGUE "%{...%}"
-%token SEMICOLON ";"
-%token TAG "<tag>"
-%token TAG_ANY "<*>"
-%token TAG_NONE "<>"
-
-%union {unsigned char character;}
-%type <character> CHAR
-%printer { fputs (char_name ($$), yyo); } CHAR
-
-%union {char *code;};
-%type <code> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING
-%printer { fputs (quotearg_style (c_quoting_style, $$), yyo); } STRING
-%printer { fprintf (yyo, "{\n%s\n}", $$); } <code>
-
-%union {uniqstr uniqstr;}
-%type <uniqstr> BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG tag variable
-%printer { fputs ($$, yyo); } <uniqstr>
-%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID
-%printer { fprintf (yyo, "%s:", $$); } ID_COLON
-%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
-%printer { fprintf (yyo, "<%s>", $$); } TAG tag
-
-%union {int integer;};
-%token <integer> INT "integer"
-%printer { fprintf (yyo, "%d", $$); } <integer>
-
-%union {symbol *symbol;}
-%type <symbol> id id_colon string_as_id symbol symbol.prec
-%printer { fprintf (yyo, "%s", $$->tag); } <symbol>
-%printer { fprintf (yyo, "%s:", $$->tag); } id_colon
-
-%union {assoc assoc;};
-%type <assoc> precedence_declarator
-
-%union {symbol_list *list;}
-%type <list> symbols.1 symbols.prec generic_symlist generic_symlist_item
-
-%union {named_ref *named_ref;}
-%type <named_ref> named_ref.opt
-
-/*---------.
-| %param. |
-`---------*/
-%code requires
-{
- typedef enum
- {
- param_none = 0,
- param_lex = 1 << 0,
- param_parse = 1 << 1,
- param_both = param_lex | param_parse
- } param_type;
-};
-%code
-{
- /** Add a lex-param and/or a parse-param.
- *
- * \param type where to push this formal argument.
- * \param decl the formal argument. Destroyed.
- * \param loc the location in the source.
- */
- static void add_param (param_type type, char *decl, location loc);
- static param_type current_param = param_none;
-};
-%union {param_type param;}
-%token <param> PERCENT_PARAM "%param";
-%printer
-{
- switch ($$)
- {
-#define CASE(In, Out) \
- case param_ ## In: fputs ("%" #Out, yyo); break
- CASE (lex, lex-param);
- CASE (parse, parse-param);
- CASE (both, param);
-#undef CASE
- case param_none: aver (false); break;
- }
-} <param>;
-
-
- /*==========\
- | Grammar. |
- \==========*/
-%%
-
-input:
- prologue_declarations "%%" grammar epilogue.opt
-;
-
-
- /*------------------------------------.
- | Declarations: before the first %%. |
- `------------------------------------*/
-
-prologue_declarations:
- %empty
-| prologue_declarations prologue_declaration
-;
-
-prologue_declaration:
- grammar_declaration
-| "%{...%}"
- {
- muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
- translate_code ($1, @1, true), @1);
- code_scanner_last_string_free ();
- }
-| "%<flag>"
- {
- muscle_percent_define_ensure ($1, @1, true);
- }
-| "%define" variable value
- {
- muscle_percent_define_insert ($2, @2, $3.kind, $3.chars,
- MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
- }
-| "%defines" { defines_flag = true; }
-| "%defines" STRING
- {
- defines_flag = true;
- spec_defines_file = xstrdup ($2);
- }
-| "%error-verbose"
- {
- muscle_percent_define_insert ("parse.error", @1, muscle_keyword,
- "verbose",
- MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
- }
-| "%expect" INT { expected_sr_conflicts = $2; }
-| "%expect-rr" INT { expected_rr_conflicts = $2; }
-| "%file-prefix" STRING { spec_file_prefix = $2; }
-| "%glr-parser"
- {
- nondeterministic_parser = true;
- glr_parser = true;
- }
-| "%initial-action" "{...}"
- {
- muscle_code_grow ("initial_action", translate_code ($2, @2, false), @2);
- code_scanner_last_string_free ();
- }
-| "%language" STRING { language_argmatch ($2, grammar_prio, @1); }
-| "%name-prefix" STRING { spec_name_prefix = $2; }
-| "%no-lines" { no_lines_flag = true; }
-| "%nondeterministic-parser" { nondeterministic_parser = true; }
-| "%output" STRING { spec_outfile = $2; }
-| "%param" { current_param = $1; } params { current_param = param_none; }
-| "%require" STRING { version_check (&@2, $2); }
-| "%skeleton" STRING
- {
- char const *skeleton_user = $2;
- if (strchr (skeleton_user, '/'))
- {
- size_t dir_length = strlen (current_file);
- char *skeleton_build;
- while (dir_length && current_file[dir_length - 1] != '/')
- --dir_length;
- while (dir_length && current_file[dir_length - 1] == '/')
- --dir_length;
- skeleton_build =
- xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
- if (dir_length > 0)
- {
- memcpy (skeleton_build, current_file, dir_length);
- skeleton_build[dir_length++] = '/';
- }
- strcpy (skeleton_build + dir_length, skeleton_user);
- skeleton_user = uniqstr_new (skeleton_build);
- free (skeleton_build);
- }
- skeleton_arg (skeleton_user, grammar_prio, @1);
- }
-| "%token-table" { token_table_flag = true; }
-| "%verbose" { report_flag |= report_states; }
-| "%yacc" { yacc_flag = true; }
-| /*FIXME: Err? What is this horror doing here? */ ";"
-;
-
-params:
- params "{...}" { add_param (current_param, $2, @2); }
-| "{...}" { add_param (current_param, $1, @1); }
-;
-
-
-/*----------------------.
-| grammar_declaration. |
-`----------------------*/
-
-grammar_declaration:
- precedence_declaration
-| symbol_declaration
-| "%start" symbol
- {
- grammar_start_symbol_set ($2, @2);
- }
-| code_props_type "{...}" generic_symlist
- {
- code_props code;
- code_props_symbol_action_init (&code, $2, @2);
- code_props_translate_code (&code);
- {
- symbol_list *list;
- for (list = $3; list; list = list->next)
- symbol_list_code_props_set (list, $1, &code);
- symbol_list_free ($3);
- }
- }
-| "%default-prec"
- {
- default_prec = true;
- }
-| "%no-default-prec"
- {
- default_prec = false;
- }
-| "%code" "{...}"
- {
- /* Do not invoke muscle_percent_code_grow here since it invokes
- muscle_user_name_list_grow. */
- muscle_code_grow ("percent_code()",
- translate_code_braceless ($2, @2), @2);
- code_scanner_last_string_free ();
- }
-| "%code" ID "{...}"
- {
- muscle_percent_code_grow ($2, @2, translate_code_braceless ($3, @3), @3);
- code_scanner_last_string_free ();
- }
-;
-
-%type <code_type> code_props_type;
-%union {code_props_type code_type;};
-%printer { fprintf (yyo, "%s", code_props_type_string ($$)); } <code_type>;
-code_props_type:
- "%destructor" { $$ = destructor; }
-| "%printer" { $$ = printer; }
-;
-
-/*---------.
-| %union. |
-`---------*/
-
-%token PERCENT_UNION "%union";
-
-union_name:
- %empty {}
-| ID { muscle_code_grow ("union_name", $1, @1); }
-;
-
-grammar_declaration:
- "%union" union_name "{...}"
- {
- union_seen = true;
- muscle_code_grow ("union_members", translate_code_braceless ($3, @3), @3);
- code_scanner_last_string_free ();
- }
-;
-
-
-
-
-symbol_declaration:
- "%nterm" { current_class = nterm_sym; } symbol_defs.1
- {
- current_class = unknown_sym;
- current_type = NULL;
- }
-| "%token" { current_class = token_sym; } symbol_defs.1
- {
- current_class = unknown_sym;
- current_type = NULL;
- }
-| "%type" TAG symbols.1
- {
- symbol_list *list;
- tag_seen = true;
- for (list = $3; list; list = list->next)
- symbol_type_set (list->content.sym, $2, @2);
- symbol_list_free ($3);
- }
-;
-
-precedence_declaration:
- precedence_declarator tag.opt symbols.prec
- {
- symbol_list *list;
- ++current_prec;
- for (list = $3; list; list = list->next)
- {
- symbol_type_set (list->content.sym, current_type, @2);
- symbol_precedence_set (list->content.sym, current_prec, $1, @1);
- }
- symbol_list_free ($3);
- current_type = NULL;
- }
-;
-
-precedence_declarator:
- "%left" { $$ = left_assoc; }
-| "%right" { $$ = right_assoc; }
-| "%nonassoc" { $$ = non_assoc; }
-| "%precedence" { $$ = precedence_assoc; }
-;
-
-tag.opt:
- %empty { current_type = NULL; }
-| TAG { current_type = $1; tag_seen = true; }
-;
-
-/* Just like symbols.1 but accept INT for the sake of POSIX. */
-symbols.prec:
- symbol.prec
- { $$ = symbol_list_sym_new ($1, @1); }
-| symbols.prec symbol.prec
- { $$ = symbol_list_append ($1, symbol_list_sym_new ($2, @2)); }
-;
-
-symbol.prec:
- symbol
- {
- $$ = $1;
- symbol_class_set ($1, token_sym, @1, false);
- }
-| symbol INT
- {
- $$ = $1;
- symbol_user_token_number_set ($1, $2, @2);
- symbol_class_set ($1, token_sym, @1, false);
- }
-;
-
-/* One or more symbols to be %typed. */
-symbols.1:
- symbol
- { $$ = symbol_list_sym_new ($1, @1); }
-| symbols.1 symbol
- { $$ = symbol_list_append ($1, symbol_list_sym_new ($2, @2)); }
-;
-
-generic_symlist:
- generic_symlist_item { $$ = $1; }
-| generic_symlist generic_symlist_item { $$ = symbol_list_append ($1, $2); }
-;
-
-generic_symlist_item:
- symbol { $$ = symbol_list_sym_new ($1, @1); }
-| tag { $$ = symbol_list_type_new ($1, @1); }
-;
-
-tag:
- TAG
-| "<*>" { $$ = uniqstr_new ("*"); }
-| "<>" { $$ = uniqstr_new (""); }
-;
-
-/* One token definition. */
-symbol_def:
- TAG
- {
- current_type = $1;
- tag_seen = true;
- }
-| id
- {
- symbol_class_set ($1, current_class, @1, true);
- symbol_type_set ($1, current_type, @1);
- }
-| id INT
- {
- symbol_class_set ($1, current_class, @1, true);
- symbol_type_set ($1, current_type, @1);
- symbol_user_token_number_set ($1, $2, @2);
- }
-| id string_as_id
- {
- symbol_class_set ($1, current_class, @1, true);
- symbol_type_set ($1, current_type, @1);
- symbol_make_alias ($1, $2, @$);
- }
-| id INT string_as_id
- {
- symbol_class_set ($1, current_class, @1, true);
- symbol_type_set ($1, current_type, @1);
- symbol_user_token_number_set ($1, $2, @2);
- symbol_make_alias ($1, $3, @$);
- }
-;
-
-/* One or more symbol definitions. */
-symbol_defs.1:
- symbol_def
-| symbol_defs.1 symbol_def
-;
-
-
- /*------------------------------------------.
- | The grammar section: between the two %%. |
- `------------------------------------------*/
-
-grammar:
- rules_or_grammar_declaration
-| grammar rules_or_grammar_declaration
-;
-
-/* As a Bison extension, one can use the grammar declarations in the
- body of the grammar. */
-rules_or_grammar_declaration:
- rules
-| grammar_declaration ";"
-| error ";"
- {
- yyerrok;
- }
-;
-
-rules:
- id_colon named_ref.opt { current_lhs ($1, @1, $2); } rhses.1
- {
- /* Free the current lhs. */
- current_lhs (0, @1, 0);
- }
-;
-
-rhses.1:
- rhs { grammar_current_rule_end (@1); }
-| rhses.1 "|" rhs { grammar_current_rule_end (@3); }
-| rhses.1 ";"
-;
-
-%token PERCENT_EMPTY "%empty";
-rhs:
- %empty
- { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location,
- current_lhs_named_ref); }
-| rhs symbol named_ref.opt
- { grammar_current_rule_symbol_append ($2, @2, $3); }
-| rhs "{...}" named_ref.opt
- { grammar_current_rule_action_append ($2, @2, $3, false); }
-| rhs "%?{...}"
- { grammar_current_rule_action_append ($2, @2, NULL, true); }
-| rhs "%empty"
- { grammar_current_rule_empty_set (@2); }
-| rhs "%prec" symbol
- { grammar_current_rule_prec_set ($3, @3); }
-| rhs "%dprec" INT
- { grammar_current_rule_dprec_set ($3, @3); }
-| rhs "%merge" TAG
- { grammar_current_rule_merge_set ($3, @3); }
-;
-
-named_ref.opt:
- %empty { $$ = 0; }
-| BRACKETED_ID { $$ = named_ref_new ($1, @1); }
-;
-
-/*---------------------.
-| variable and value. |
-`---------------------*/
-
-/* The STRING form of variable is deprecated and is not M4-friendly.
- For example, M4 fails for '%define "[" "value"'. */
-variable:
- ID
-| STRING { $$ = uniqstr_new ($1); }
-;
-
-/* Some content or empty by default. */
-%code requires {#include "muscle-tab.h"};
-%union
-{
- struct
- {
- char const *chars;
- muscle_kind kind;
- } value;
-};
-%type <value> value;
-%printer
-{
- switch ($$.kind)
- {
- case muscle_code: fprintf (yyo, "{%s}", $$.chars); break;
- case muscle_keyword: fprintf (yyo, "%s", $$.chars); break;
- case muscle_string: fprintf (yyo, "\"%s\"", $$.chars); break;
- }
-} <value>;
-
-value:
- %empty { $$.kind = muscle_keyword; $$.chars = ""; }
-| ID { $$.kind = muscle_keyword; $$.chars = $1; }
-| STRING { $$.kind = muscle_string; $$.chars = $1; }
-| "{...}" { $$.kind = muscle_code; $$.chars = strip_braces ($1); }
-;
-
-
-/*--------------.
-| Identifiers. |
-`--------------*/
-
-/* Identifiers are returned as uniqstr values by the scanner.
- Depending on their use, we may need to make them genuine symbols. */
-
-id:
- ID
- { $$ = symbol_from_uniqstr ($1, @1); }
-| CHAR
- {
- $$ = symbol_get (char_name ($1), @1);
- symbol_class_set ($$, token_sym, @1, false);
- symbol_user_token_number_set ($$, $1, @1);
- }
-;
-
-id_colon:
- ID_COLON { $$ = symbol_from_uniqstr ($1, @1); }
-;
-
-
-symbol:
- id
-| string_as_id
-;
-
-/* A string used as an ID: quote it. */
-string_as_id:
- STRING
- {
- $$ = symbol_get (quotearg_style (c_quoting_style, $1), @1);
- symbol_class_set ($$, token_sym, @1, false);
- }
-;
-
-epilogue.opt:
- %empty
-| "%%" EPILOGUE
- {
- muscle_code_grow ("epilogue", translate_code ($2, @2, true), @2);
- code_scanner_last_string_free ();
- }
-;
-
-%%
-
-/* Return the location of the left-hand side of a rule whose
- right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
- the right-hand side, and return an empty location equal to the end
- boundary of RHS[0] if the right-hand side is empty. */
-
-static YYLTYPE
-lloc_default (YYLTYPE const *rhs, int n)
-{
- int i;
- YYLTYPE loc;
-
- /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
- The bug is fixed in 7.4.2m, but play it safe for now. */
- loc.start = rhs[n].end;
- loc.end = rhs[n].end;
-
- /* Ignore empty nonterminals the start of the right-hand side.
- Do not bother to ignore them at the end of the right-hand side,
- since empty nonterminals have the same end as their predecessors. */
- for (i = 1; i <= n; i++)
- if (! equal_boundaries (rhs[i].start, rhs[i].end))
- {
- loc.start = rhs[i].start;
- break;
- }
-
- return loc;
-}
-
-static
-char *strip_braces (char *code)
-{
- code[strlen (code) - 1] = 0;
- return code + 1;
-}
-
-static
-char const *
-translate_code (char *code, location loc, bool plain)
-{
- code_props plain_code;
- if (plain)
- code_props_plain_init (&plain_code, code, loc);
- else
- code_props_symbol_action_init (&plain_code, code, loc);
- code_props_translate_code (&plain_code);
- gram_scanner_last_string_free ();
- return plain_code.code;
-}
-
-static
-char const *
-translate_code_braceless (char *code, location loc)
-{
- return translate_code (strip_braces (code), loc, true);
-}
-
-static void
-add_param (param_type type, char *decl, location loc)
-{
+}
+
+%code
+{
+ #include "system.h"
+
+ #include "c-ctype.h"
+ #include "complain.h"
+ #include "conflicts.h"
+ #include "files.h"
+ #include "getargs.h"
+ #include "gram.h"
+ #include "named-ref.h"
+ #include "quotearg.h"
+ #include "reader.h"
+ #include "scan-gram.h"
+ #include "scan-code.h"
+ #include "xmemdup0.h"
+
+ static int current_prec = 0;
+ static location current_lhs_location;
+ static named_ref *current_lhs_named_ref;
+ static symbol *current_lhs_symbol;
+ static symbol_class current_class = unknown_sym;
+ static uniqstr current_type = NULL;
+
+ /** Set the new current left-hand side symbol, possibly common
+ * to several right-hand side parts of rule.
+ */
+ static void current_lhs (symbol *sym, location loc, named_ref *ref);
+
+ #define YYLLOC_DEFAULT(Current, Rhs, N) \
+ (Current) = lloc_default (Rhs, N)
+ static YYLTYPE lloc_default (YYLTYPE const *, int);
+
+ #define YY_LOCATION_PRINT(File, Loc) \
+ location_print (Loc, File)
+
+ /* Strip initial '{' and final '}' (must be first and last characters).
+ Return the result. */
+ static char *strip_braces (char *code);
+
+ /* Convert CODE by calling code_props_plain_init if PLAIN, otherwise
+ code_props_symbol_action_init. Call
+ gram_scanner_last_string_free to release the latest string from
+ the scanner (should be CODE). */
+ static char const *translate_code (char *code, location loc, bool plain);
+
+ /* Convert CODE by calling code_props_plain_init after having
+ stripped the first and last characters (expected to be '{', and
+ '}'). Call gram_scanner_last_string_free to release the latest
+ string from the scanner (should be CODE). */
+ static char const *translate_code_braceless (char *code, location loc);
+
+ static void version_check (location const *loc, char const *version);
+
+ static void gram_error (location const *, char const *);
+
+ /* A string that describes a char (e.g., 'a' -> "'a'"). */
+ static char const *char_name (char);
+
+ #define YYTYPE_INT16 int_fast16_t
+ #define YYTYPE_INT8 int_fast8_t
+ #define YYTYPE_UINT16 uint_fast16_t
+ #define YYTYPE_UINT8 uint_fast8_t
+}
+
+%define api.prefix {gram_}
+%define api.pure full
+%define locations
+%define parse.error verbose
+%define parse.lac full
+%define parse.trace
+%defines
+%expect 0
+%verbose
+
+%initial-action
+{
+ /* Bison's grammar can initial empty locations, hence a default
+ location is needed. */
+ boundary_set (&@$.start, current_file, 1, 1);
+ boundary_set (&@$.end, current_file, 1, 1);
+}
+
+/* Define the tokens together with their human representation. */
+%token GRAM_EOF 0 "end of file"
+%token STRING "string"
+
+%token PERCENT_TOKEN "%token"
+%token PERCENT_NTERM "%nterm"
+
+%token PERCENT_TYPE "%type"
+%token PERCENT_DESTRUCTOR "%destructor"
+%token PERCENT_PRINTER "%printer"
+
+%token PERCENT_LEFT "%left"
+%token PERCENT_RIGHT "%right"
+%token PERCENT_NONASSOC "%nonassoc"
+%token PERCENT_PRECEDENCE "%precedence"
+
+%token PERCENT_PREC "%prec"
+%token PERCENT_DPREC "%dprec"
+%token PERCENT_MERGE "%merge"
+
+/*----------------------.
+| Global Declarations. |
+`----------------------*/
+
+%token
+ PERCENT_CODE "%code"
+ PERCENT_DEFAULT_PREC "%default-prec"
+ PERCENT_DEFINE "%define"
+ PERCENT_DEFINES "%defines"
+ PERCENT_ERROR_VERBOSE "%error-verbose"
+ PERCENT_EXPECT "%expect"
+ PERCENT_EXPECT_RR "%expect-rr"
+ PERCENT_FLAG "%<flag>"
+ PERCENT_FILE_PREFIX "%file-prefix"
+ PERCENT_GLR_PARSER "%glr-parser"
+ PERCENT_INITIAL_ACTION "%initial-action"
+ PERCENT_LANGUAGE "%language"
+ PERCENT_NAME_PREFIX "%name-prefix"
+ PERCENT_NO_DEFAULT_PREC "%no-default-prec"
+ PERCENT_NO_LINES "%no-lines"
+ PERCENT_NONDETERMINISTIC_PARSER
+ "%nondeterministic-parser"
+ PERCENT_OUTPUT "%output"
+ PERCENT_REQUIRE "%require"
+ PERCENT_SKELETON "%skeleton"
+ PERCENT_START "%start"
+ PERCENT_TOKEN_TABLE "%token-table"
+ PERCENT_VERBOSE "%verbose"
+ PERCENT_YACC "%yacc"
+;
+
+%token BRACED_CODE "{...}"
+%token BRACED_PREDICATE "%?{...}"
+%token BRACKETED_ID "[identifier]"
+%token CHAR "char"
+%token EPILOGUE "epilogue"
+%token EQUAL "="
+%token ID "identifier"
+%token ID_COLON "identifier:"
+%token PERCENT_PERCENT "%%"
+%token PIPE "|"
+%token PROLOGUE "%{...%}"
+%token SEMICOLON ";"
+%token TAG "<tag>"
+%token TAG_ANY "<*>"
+%token TAG_NONE "<>"
+
+%union {unsigned char character;}
+%type <character> CHAR
+%printer { fputs (char_name ($$), yyo); } CHAR
+
+%union {char *code;};
+%type <code> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING
+%printer { fputs (quotearg_style (c_quoting_style, $$), yyo); } STRING
+%printer { fprintf (yyo, "{\n%s\n}", $$); } <code>
+
+%union {uniqstr uniqstr;}
+%type <uniqstr> BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG tag variable
+%printer { fputs ($$, yyo); } <uniqstr>
+%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID
+%printer { fprintf (yyo, "%s:", $$); } ID_COLON
+%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
+%printer { fprintf (yyo, "<%s>", $$); } TAG tag
+
+%union {int integer;};
+%token <integer> INT "integer"
+%printer { fprintf (yyo, "%d", $$); } <integer>
+
+%union {symbol *symbol;}
+%type <symbol> id id_colon string_as_id symbol symbol.prec
+%printer { fprintf (yyo, "%s", $$->tag); } <symbol>
+%printer { fprintf (yyo, "%s:", $$->tag); } id_colon
+
+%union {assoc assoc;};
+%type <assoc> precedence_declarator
+
+%union {symbol_list *list;}
+%type <list> symbols.1 symbols.prec generic_symlist generic_symlist_item
+
+%union {named_ref *named_ref;}
+%type <named_ref> named_ref.opt
+
+/*---------.
+| %param. |
+`---------*/
+%code requires
+{
+ typedef enum
+ {
+ param_none = 0,
+ param_lex = 1 << 0,
+ param_parse = 1 << 1,
+ param_both = param_lex | param_parse
+ } param_type;
+};
+%code
+{
+ /** Add a lex-param and/or a parse-param.
+ *
+ * \param type where to push this formal argument.
+ * \param decl the formal argument. Destroyed.
+ * \param loc the location in the source.
+ */
+ static void add_param (param_type type, char *decl, location loc);
+ static param_type current_param = param_none;
+};
+%union {param_type param;}
+%token <param> PERCENT_PARAM "%param";
+%printer
+{
+ switch ($$)
+ {
+#define CASE(In, Out) \
+ case param_ ## In: fputs ("%" #Out, yyo); break
+ CASE (lex, lex-param);
+ CASE (parse, parse-param);
+ CASE (both, param);
+#undef CASE
+ case param_none: aver (false); break;
+ }
+} <param>;
+
+
+ /*==========\
+ | Grammar. |
+ \==========*/
+%%
+
+input:
+ prologue_declarations "%%" grammar epilogue.opt
+;
+
+
+ /*------------------------------------.
+ | Declarations: before the first %%. |
+ `------------------------------------*/
+
+prologue_declarations:
+ %empty
+| prologue_declarations prologue_declaration
+;
+
+prologue_declaration:
+ grammar_declaration
+| "%{...%}"
+ {
+ muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
+ translate_code ($1, @1, true), @1);
+ code_scanner_last_string_free ();
+ }
+| "%<flag>"
+ {
+ muscle_percent_define_ensure ($1, @1, true);
+ }
+| "%define" variable value
+ {
+ muscle_percent_define_insert ($2, @2, $3.kind, $3.chars,
+ MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
+ }
+| "%defines" { defines_flag = true; }
+| "%defines" STRING
+ {
+ defines_flag = true;
+ spec_defines_file = xstrdup ($2);
+ }
+| "%error-verbose"
+ {
+ muscle_percent_define_insert ("parse.error", @1, muscle_keyword,
+ "verbose",
+ MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
+ }
+| "%expect" INT { expected_sr_conflicts = $2; }
+| "%expect-rr" INT { expected_rr_conflicts = $2; }
+| "%file-prefix" STRING { spec_file_prefix = $2; }
+| "%glr-parser"
+ {
+ nondeterministic_parser = true;
+ glr_parser = true;
+ }
+| "%initial-action" "{...}"
+ {
+ muscle_code_grow ("initial_action", translate_code ($2, @2, false), @2);
+ code_scanner_last_string_free ();
+ }
+| "%language" STRING { language_argmatch ($2, grammar_prio, @1); }
+| "%name-prefix" STRING { spec_name_prefix = $2; }
+| "%no-lines" { no_lines_flag = true; }
+| "%nondeterministic-parser" { nondeterministic_parser = true; }
+| "%output" STRING { spec_outfile = $2; }
+| "%param" { current_param = $1; } params { current_param = param_none; }
+| "%require" STRING { version_check (&@2, $2); }
+| "%skeleton" STRING
+ {
+ char const *skeleton_user = $2;
+ if (strchr (skeleton_user, '/'))
+ {
+ size_t dir_length = strlen (current_file);
+ char *skeleton_build;
+ while (dir_length && current_file[dir_length - 1] != '/')
+ --dir_length;
+ while (dir_length && current_file[dir_length - 1] == '/')
+ --dir_length;
+ skeleton_build =
+ xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
+ if (dir_length > 0)
+ {
+ memcpy (skeleton_build, current_file, dir_length);
+ skeleton_build[dir_length++] = '/';
+ }
+ strcpy (skeleton_build + dir_length, skeleton_user);
+ skeleton_user = uniqstr_new (skeleton_build);
+ free (skeleton_build);
+ }
+ skeleton_arg (skeleton_user, grammar_prio, @1);
+ }
+| "%token-table" { token_table_flag = true; }
+| "%verbose" { report_flag |= report_states; }
+| "%yacc" { yacc_flag = true; }
+| /*FIXME: Err? What is this horror doing here? */ ";"
+;
+
+params:
+ params "{...}" { add_param (current_param, $2, @2); }
+| "{...}" { add_param (current_param, $1, @1); }
+;
+
+
+/*----------------------.
+| grammar_declaration. |
+`----------------------*/
+
+grammar_declaration:
+ precedence_declaration
+| symbol_declaration
+| "%start" symbol
+ {
+ grammar_start_symbol_set ($2, @2);
+ }
+| code_props_type "{...}" generic_symlist
+ {
+ code_props code;
+ code_props_symbol_action_init (&code, $2, @2);
+ code_props_translate_code (&code);
+ {
+ symbol_list *list;
+ for (list = $3; list; list = list->next)
+ symbol_list_code_props_set (list, $1, &code);
+ symbol_list_free ($3);
+ }
+ }
+| "%default-prec"
+ {
+ default_prec = true;
+ }
+| "%no-default-prec"
+ {
+ default_prec = false;
+ }
+| "%code" "{...}"
+ {
+ /* Do not invoke muscle_percent_code_grow here since it invokes
+ muscle_user_name_list_grow. */
+ muscle_code_grow ("percent_code()",
+ translate_code_braceless ($2, @2), @2);
+ code_scanner_last_string_free ();
+ }
+| "%code" ID "{...}"
+ {
+ muscle_percent_code_grow ($2, @2, translate_code_braceless ($3, @3), @3);
+ code_scanner_last_string_free ();
+ }
+;
+
+%type <code_type> code_props_type;
+%union {code_props_type code_type;};
+%printer { fprintf (yyo, "%s", code_props_type_string ($$)); } <code_type>;
+code_props_type:
+ "%destructor" { $$ = destructor; }
+| "%printer" { $$ = printer; }
+;
+
+/*---------.
+| %union. |
+`---------*/
+
+%token PERCENT_UNION "%union";
+
+union_name:
+ %empty {}
+| ID { muscle_code_grow ("union_name", $1, @1); }
+;
+
+grammar_declaration:
+ "%union" union_name "{...}"
+ {
+ union_seen = true;
+ muscle_code_grow ("union_members", translate_code_braceless ($3, @3), @3);
+ code_scanner_last_string_free ();
+ }
+;
+
+
+
+
+symbol_declaration:
+ "%nterm" { current_class = nterm_sym; } symbol_defs.1
+ {
+ current_class = unknown_sym;
+ current_type = NULL;
+ }
+| "%token" { current_class = token_sym; } symbol_defs.1
+ {
+ current_class = unknown_sym;
+ current_type = NULL;
+ }
+| "%type" TAG symbols.1
+ {
+ symbol_list *list;
+ tag_seen = true;
+ for (list = $3; list; list = list->next)
+ symbol_type_set (list->content.sym, $2, @2);
+ symbol_list_free ($3);
+ }
+;
+
+precedence_declaration:
+ precedence_declarator tag.opt symbols.prec
+ {
+ symbol_list *list;
+ ++current_prec;
+ for (list = $3; list; list = list->next)
+ {
+ symbol_type_set (list->content.sym, current_type, @2);
+ symbol_precedence_set (list->content.sym, current_prec, $1, @1);
+ }
+ symbol_list_free ($3);
+ current_type = NULL;
+ }
+;
+
+precedence_declarator:
+ "%left" { $$ = left_assoc; }
+| "%right" { $$ = right_assoc; }
+| "%nonassoc" { $$ = non_assoc; }
+| "%precedence" { $$ = precedence_assoc; }
+;
+
+tag.opt:
+ %empty { current_type = NULL; }
+| TAG { current_type = $1; tag_seen = true; }
+;
+
+/* Just like symbols.1 but accept INT for the sake of POSIX. */
+symbols.prec:
+ symbol.prec
+ { $$ = symbol_list_sym_new ($1, @1); }
+| symbols.prec symbol.prec
+ { $$ = symbol_list_append ($1, symbol_list_sym_new ($2, @2)); }
+;
+
+symbol.prec:
+ symbol
+ {
+ $$ = $1;
+ symbol_class_set ($1, token_sym, @1, false);
+ }
+| symbol INT
+ {
+ $$ = $1;
+ symbol_user_token_number_set ($1, $2, @2);
+ symbol_class_set ($1, token_sym, @1, false);
+ }
+;
+
+/* One or more symbols to be %typed. */
+symbols.1:
+ symbol
+ { $$ = symbol_list_sym_new ($1, @1); }
+| symbols.1 symbol
+ { $$ = symbol_list_append ($1, symbol_list_sym_new ($2, @2)); }
+;
+
+generic_symlist:
+ generic_symlist_item { $$ = $1; }
+| generic_symlist generic_symlist_item { $$ = symbol_list_append ($1, $2); }
+;
+
+generic_symlist_item:
+ symbol { $$ = symbol_list_sym_new ($1, @1); }
+| tag { $$ = symbol_list_type_new ($1, @1); }
+;
+
+tag:
+ TAG
+| "<*>" { $$ = uniqstr_new ("*"); }
+| "<>" { $$ = uniqstr_new (""); }
+;
+
+/* One token definition. */
+symbol_def:
+ TAG
+ {
+ current_type = $1;
+ tag_seen = true;
+ }
+| id
+ {
+ symbol_class_set ($1, current_class, @1, true);
+ symbol_type_set ($1, current_type, @1);
+ }
+| id INT
+ {
+ symbol_class_set ($1, current_class, @1, true);
+ symbol_type_set ($1, current_type, @1);
+ symbol_user_token_number_set ($1, $2, @2);
+ }
+| id string_as_id
+ {
+ symbol_class_set ($1, current_class, @1, true);
+ symbol_type_set ($1, current_type, @1);
+ symbol_make_alias ($1, $2, @$);
+ }
+| id INT string_as_id
+ {
+ symbol_class_set ($1, current_class, @1, true);
+ symbol_type_set ($1, current_type, @1);
+ symbol_user_token_number_set ($1, $2, @2);
+ symbol_make_alias ($1, $3, @$);
+ }
+;
+
+/* One or more symbol definitions. */
+symbol_defs.1:
+ symbol_def
+| symbol_defs.1 symbol_def
+;
+
+
+ /*------------------------------------------.
+ | The grammar section: between the two %%. |
+ `------------------------------------------*/
+
+grammar:
+ rules_or_grammar_declaration
+| grammar rules_or_grammar_declaration
+;
+
+/* As a Bison extension, one can use the grammar declarations in the
+ body of the grammar. */
+rules_or_grammar_declaration:
+ rules
+| grammar_declaration ";"
+| error ";"
+ {
+ yyerrok;
+ }
+;
+
+rules:
+ id_colon named_ref.opt { current_lhs ($1, @1, $2); } rhses.1
+ {
+ /* Free the current lhs. */
+ current_lhs (0, @1, 0);
+ }
+;
+
+rhses.1:
+ rhs { grammar_current_rule_end (@1); }
+| rhses.1 "|" rhs { grammar_current_rule_end (@3); }
+| rhses.1 ";"
+;
+
+%token PERCENT_EMPTY "%empty";
+rhs:
+ %empty
+ { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location,
+ current_lhs_named_ref); }
+| rhs symbol named_ref.opt
+ { grammar_current_rule_symbol_append ($2, @2, $3); }
+| rhs "{...}" named_ref.opt
+ { grammar_current_rule_action_append ($2, @2, $3, false); }
+| rhs "%?{...}"
+ { grammar_current_rule_action_append ($2, @2, NULL, true); }
+| rhs "%empty"
+ { grammar_current_rule_empty_set (@2); }
+| rhs "%prec" symbol
+ { grammar_current_rule_prec_set ($3, @3); }
+| rhs "%dprec" INT
+ { grammar_current_rule_dprec_set ($3, @3); }
+| rhs "%merge" TAG
+ { grammar_current_rule_merge_set ($3, @3); }
+;
+
+named_ref.opt:
+ %empty { $$ = 0; }
+| BRACKETED_ID { $$ = named_ref_new ($1, @1); }
+;
+
+/*---------------------.
+| variable and value. |
+`---------------------*/
+
+/* The STRING form of variable is deprecated and is not M4-friendly.
+ For example, M4 fails for '%define "[" "value"'. */
+variable:
+ ID
+| STRING { $$ = uniqstr_new ($1); }
+;
+
+/* Some content or empty by default. */
+%code requires {#include "muscle-tab.h"};
+%union
+{
+ struct
+ {
+ char const *chars;
+ muscle_kind kind;
+ } value;
+};
+%type <value> value;
+%printer
+{
+ switch ($$.kind)
+ {
+ case muscle_code: fprintf (yyo, "{%s}", $$.chars); break;
+ case muscle_keyword: fprintf (yyo, "%s", $$.chars); break;
+ case muscle_string: fprintf (yyo, "\"%s\"", $$.chars); break;
+ }
+} <value>;
+
+value:
+ %empty { $$.kind = muscle_keyword; $$.chars = ""; }
+| ID { $$.kind = muscle_keyword; $$.chars = $1; }
+| STRING { $$.kind = muscle_string; $$.chars = $1; }
+| "{...}" { $$.kind = muscle_code; $$.chars = strip_braces ($1); }
+;
+
+
+/*--------------.
+| Identifiers. |
+`--------------*/
+
+/* Identifiers are returned as uniqstr values by the scanner.
+ Depending on their use, we may need to make them genuine symbols. */
+
+id:
+ ID
+ { $$ = symbol_from_uniqstr ($1, @1); }
+| CHAR
+ {
+ $$ = symbol_get (char_name ($1), @1);
+ symbol_class_set ($$, token_sym, @1, false);
+ symbol_user_token_number_set ($$, $1, @1);
+ }
+;
+
+id_colon:
+ ID_COLON { $$ = symbol_from_uniqstr ($1, @1); }
+;
+
+
+symbol:
+ id
+| string_as_id
+;
+
+/* A string used as an ID: quote it. */
+string_as_id:
+ STRING
+ {
+ $$ = symbol_get (quotearg_style (c_quoting_style, $1), @1);
+ symbol_class_set ($$, token_sym, @1, false);
+ }
+;
+
+epilogue.opt:
+ %empty
+| "%%" EPILOGUE
+ {
+ muscle_code_grow ("epilogue", translate_code ($2, @2, true), @2);
+ code_scanner_last_string_free ();
+ }
+;
+
+%%
+
+/* Return the location of the left-hand side of a rule whose
+ right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
+ the right-hand side, and return an empty location equal to the end
+ boundary of RHS[0] if the right-hand side is empty. */
+
+static YYLTYPE
+lloc_default (YYLTYPE const *rhs, int n)
+{
+ int i;
+ YYLTYPE loc;
+
+ /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
+ The bug is fixed in 7.4.2m, but play it safe for now. */
+ loc.start = rhs[n].end;
+ loc.end = rhs[n].end;
+
+ /* Ignore empty nonterminals the start of the right-hand side.
+ Do not bother to ignore them at the end of the right-hand side,
+ since empty nonterminals have the same end as their predecessors. */
+ for (i = 1; i <= n; i++)
+ if (! equal_boundaries (rhs[i].start, rhs[i].end))
+ {
+ loc.start = rhs[i].start;
+ break;
+ }
+
+ return loc;
+}
+
+static
+char *strip_braces (char *code)
+{
+ code[strlen (code) - 1] = 0;
+ return code + 1;
+}
+
+static
+char const *
+translate_code (char *code, location loc, bool plain)
+{
+ code_props plain_code;
+ if (plain)
+ code_props_plain_init (&plain_code, code, loc);
+ else
+ code_props_symbol_action_init (&plain_code, code, loc);
+ code_props_translate_code (&plain_code);
+ gram_scanner_last_string_free ();
+ return plain_code.code;
+}
+
+static
+char const *
+translate_code_braceless (char *code, location loc)
+{
+ return translate_code (strip_braces (code), loc, true);
+}
+
+static void
+add_param (param_type type, char *decl, location loc)
+{
static char const alphanum[26 + 26 + 1 + 10 + 1] =
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "_"
- "0123456789";
-
- char const *name_start = NULL;
- {
- char *p;
- /* Stop on last actual character. */
- for (p = decl; p[1]; p++)
- if ((p == decl
- || ! memchr (alphanum, p[-1], sizeof alphanum))
- && memchr (alphanum, p[0], sizeof alphanum - 10))
- name_start = p;
-
- /* Strip the surrounding '{' and '}', and any blanks just inside
- the braces. */
- --p;
- while (c_isspace ((unsigned char) *p))
- --p;
- p[1] = '\0';
- ++decl;
- while (c_isspace ((unsigned char) *decl))
- ++decl;
- }
-
- if (! name_start)
- complain (&loc, complaint, _("missing identifier in parameter declaration"));
- else
- {
- char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
- if (type & param_lex)
- muscle_pair_list_grow ("lex_param", decl, name);
- if (type & param_parse)
- muscle_pair_list_grow ("parse_param", decl, name);
- free (name);
- }
-
- gram_scanner_last_string_free ();
-}
-
-
-static void
-version_check (location const *loc, char const *version)
-{
- if (strverscmp (version, PACKAGE_VERSION) > 0)
- {
- complain (loc, complaint, "require bison %s, but have %s",
- version, PACKAGE_VERSION);
- exit (EX_MISMATCH);
- }
-}
-
-static void
-gram_error (location const *loc, char const *msg)
-{
- complain (loc, complaint, "%s", msg);
-}
-
-char const *
-token_name (int type)
-{
- return yytname[YYTRANSLATE (type)];
-}
-
-static char const *
-char_name (char c)
-{
- if (c == '\'')
- return "'\\''";
- else
- {
- char buf[4];
- buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
- return quotearg_style (escape_quoting_style, buf);
- }
-}
-
-static
-void
-current_lhs (symbol *sym, location loc, named_ref *ref)
-{
- current_lhs_symbol = sym;
- current_lhs_location = loc;
- /* In order to simplify memory management, named references for lhs
- are always assigned by deep copy into the current symbol_list
- node. This is because a single named-ref in the grammar may
- result in several uses when the user factors lhs between several
- rules using "|". Therefore free the parser's original copy. */
- free (current_lhs_named_ref);
- current_lhs_named_ref = ref;
-}
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "_"
+ "0123456789";
+
+ char const *name_start = NULL;
+ {
+ char *p;
+ /* Stop on last actual character. */
+ for (p = decl; p[1]; p++)
+ if ((p == decl
+ || ! memchr (alphanum, p[-1], sizeof alphanum))
+ && memchr (alphanum, p[0], sizeof alphanum - 10))
+ name_start = p;
+
+ /* Strip the surrounding '{' and '}', and any blanks just inside
+ the braces. */
+ --p;
+ while (c_isspace ((unsigned char) *p))
+ --p;
+ p[1] = '\0';
+ ++decl;
+ while (c_isspace ((unsigned char) *decl))
+ ++decl;
+ }
+
+ if (! name_start)
+ complain (&loc, complaint, _("missing identifier in parameter declaration"));
+ else
+ {
+ char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
+ if (type & param_lex)
+ muscle_pair_list_grow ("lex_param", decl, name);
+ if (type & param_parse)
+ muscle_pair_list_grow ("parse_param", decl, name);
+ free (name);
+ }
+
+ gram_scanner_last_string_free ();
+}
+
+
+static void
+version_check (location const *loc, char const *version)
+{
+ if (strverscmp (version, PACKAGE_VERSION) > 0)
+ {
+ complain (loc, complaint, "require bison %s, but have %s",
+ version, PACKAGE_VERSION);
+ exit (EX_MISMATCH);
+ }
+}
+
+static void
+gram_error (location const *loc, char const *msg)
+{
+ complain (loc, complaint, "%s", msg);
+}
+
+char const *
+token_name (int type)
+{
+ return yytname[YYTRANSLATE (type)];
+}
+
+static char const *
+char_name (char c)
+{
+ if (c == '\'')
+ return "'\\''";
+ else
+ {
+ char buf[4];
+ buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
+ return quotearg_style (escape_quoting_style, buf);
+ }
+}
+
+static
+void
+current_lhs (symbol *sym, location loc, named_ref *ref)
+{
+ current_lhs_symbol = sym;
+ current_lhs_location = loc;
+ /* In order to simplify memory management, named references for lhs
+ are always assigned by deep copy into the current symbol_list
+ node. This is because a single named-ref in the grammar may
+ result in several uses when the user factors lhs between several
+ rules using "|". Therefore free the parser's original copy. */
+ free (current_lhs_named_ref);
+ current_lhs_named_ref = ref;
+}
diff --git a/contrib/tools/bison/bison/src/print-xml.c b/contrib/tools/bison/bison/src/print-xml.c
index c30da729db..23dedaf839 100644
--- a/contrib/tools/bison/bison/src/print-xml.c
+++ b/contrib/tools/bison/bison/src/print-xml.c
@@ -1,545 +1,545 @@
-/* Print an xml on generated parser, for Bison,
-
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
+/* Print an xml on generated parser, for Bison,
+
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
#include "string--.h"
-#include "system.h"
-
-#include <stdarg.h>
-
-#include <bitset.h>
-
-#include "LR0.h"
-#include "closure.h"
-#include "conflicts.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "lalr.h"
-#include "print.h"
-#include "print-xml.h"
-#include "reader.h"
-#include "reduce.h"
-#include "state.h"
-#include "symtab.h"
-#include "tables.h"
-
-static bitset no_reduce_set;
-struct escape_buf
-{
- char *ptr;
- size_t size;
-};
-enum { num_escape_bufs = 3 };
-static struct escape_buf escape_bufs[num_escape_bufs];
-
-
-/*--------------------------------.
-| Report information on a state. |
-`--------------------------------*/
-
-static void
-print_core (FILE *out, int level, state *s)
-{
- size_t i;
- item_number *sitems = s->items;
- size_t snritems = s->nitems;
-
- /* Output all the items of a state, not only its kernel. */
- closure (sitems, snritems);
- sitems = itemset;
- snritems = nitemset;
-
- if (!snritems) {
- xml_puts (out, level, "<itemset/>");
- return;
- }
-
- xml_puts (out, level, "<itemset>");
-
- for (i = 0; i < snritems; i++)
- {
- bool printed = false;
- item_number *sp;
- item_number *sp1;
- rule_number r;
-
- sp1 = sp = ritem + sitems[i];
-
- while (*sp >= 0)
- sp++;
-
- r = item_number_as_rule_number (*sp);
- sp = rules[r].rhs;
-
- /* Display the lookahead tokens? */
- if (item_number_is_rule_number (*sp1))
- {
- reductions *reds = s->reductions;
- int red = state_reduction_find (s, &rules[r]);
- /* Print item with lookaheads if there are. */
- if (reds->lookahead_tokens && red != -1)
- {
- xml_printf (out, level + 1,
- "<item rule-number=\"%d\" point=\"%d\">",
- rules[r].number, sp1 - sp);
- state_rule_lookahead_tokens_print_xml (s, &rules[r],
- out, level + 2);
- xml_puts (out, level + 1, "</item>");
- printed = true;
- }
- }
-
- if (!printed)
- {
- xml_printf (out, level + 1,
- "<item rule-number=\"%d\" point=\"%d\"/>",
- rules[r].number,
- sp1 - sp);
- }
- }
- xml_puts (out, level, "</itemset>");
-}
-
-
-/*-----------------------------------------------------------.
-| Report the shifts if DISPLAY_SHIFTS_P or the gotos of S on |
-| OUT. |
-`-----------------------------------------------------------*/
-
-static void
-print_transitions (state *s, FILE *out, int level)
-{
- transitions *trans = s->transitions;
- int n = 0;
- int i;
-
- for (i = 0; i < trans->num; i++)
- if (!TRANSITION_IS_DISABLED (trans, i))
- {
- n++;
- }
-
- /* Nothing to report. */
- if (!n) {
- xml_puts (out, level, "<transitions/>");
- return;
- }
-
- /* Report lookahead tokens and shifts. */
- xml_puts (out, level, "<transitions>");
-
- for (i = 0; i < trans->num; i++)
- if (!TRANSITION_IS_DISABLED (trans, i)
- && TRANSITION_IS_SHIFT (trans, i))
- {
- symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
- char const *tag = sym->tag;
- state *s1 = trans->states[i];
-
- xml_printf (out, level + 1,
- "<transition type=\"shift\" symbol=\"%s\" state=\"%d\"/>",
- xml_escape (tag), s1->number);
- }
-
- for (i = 0; i < trans->num; i++)
- if (!TRANSITION_IS_DISABLED (trans, i)
- && !TRANSITION_IS_SHIFT (trans, i))
- {
- symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
- char const *tag = sym->tag;
- state *s1 = trans->states[i];
-
- xml_printf (out, level + 1,
- "<transition type=\"goto\" symbol=\"%s\" state=\"%d\"/>",
- xml_escape (tag), s1->number);
- }
-
- xml_puts (out, level, "</transitions>");
-}
-
-
-/*--------------------------------------------------------.
-| Report the explicit errors of S raised from %nonassoc. |
-`--------------------------------------------------------*/
-
-static void
-print_errs (FILE *out, int level, state *s)
-{
- errs *errp = s->errs;
- bool count = false;
- int i;
-
- for (i = 0; i < errp->num; ++i)
- if (errp->symbols[i])
- count = true;
-
- /* Nothing to report. */
- if (!count) {
- xml_puts (out, level, "<errors/>");
- return;
- }
-
- /* Report lookahead tokens and errors. */
- xml_puts (out, level, "<errors>");
- for (i = 0; i < errp->num; ++i)
- if (errp->symbols[i])
- {
- char const *tag = errp->symbols[i]->tag;
- xml_printf (out, level + 1,
- "<error symbol=\"%s\">nonassociative</error>",
- xml_escape (tag));
- }
- xml_puts (out, level, "</errors>");
-}
-
-
-/*-------------------------------------------------------------------------.
-| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). |
-| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
-| R/R conflicts). |
-`-------------------------------------------------------------------------*/
-
-static void
-print_reduction (FILE *out, int level, char const *lookahead_token,
- rule *r, bool enabled)
-{
- if (r->number)
- xml_printf (out, level,
- "<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>",
- xml_escape (lookahead_token),
- r->number,
- enabled ? "true" : "false");
- else
- xml_printf (out, level,
- "<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
- xml_escape (lookahead_token),
- enabled ? "true" : "false");
-}
-
-
-/*-------------------------------------------.
-| Report on OUT the reduction actions of S. |
-`-------------------------------------------*/
-
-static void
-print_reductions (FILE *out, int level, state *s)
-{
- transitions *trans = s->transitions;
- reductions *reds = s->reductions;
- rule *default_reduction = NULL;
- int report = false;
- int i, j;
-
- if (reds->num == 0)
- {
- xml_puts (out, level, "<reductions/>");
- return;
- }
-
- if (yydefact[s->number] != 0)
- default_reduction = &rules[yydefact[s->number] - 1];
-
- bitset_zero (no_reduce_set);
- FOR_EACH_SHIFT (trans, i)
- bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i));
- for (i = 0; i < s->errs->num; ++i)
- if (s->errs->symbols[i])
- bitset_set (no_reduce_set, s->errs->symbols[i]->number);
-
- if (default_reduction)
- report = true;
-
- if (reds->lookahead_tokens)
- for (i = 0; i < ntokens; i++)
- {
- bool count = bitset_test (no_reduce_set, i);
-
- for (j = 0; j < reds->num; ++j)
- if (bitset_test (reds->lookahead_tokens[j], i))
- {
- if (! count)
- {
- if (reds->rules[j] != default_reduction)
- report = true;
- count = true;
- }
- else
- {
- report = true;
- }
- }
- }
-
- /* Nothing to report. */
- if (!report) {
- xml_puts (out, level, "<reductions/>");
- return;
- }
-
- xml_puts (out, level, "<reductions>");
-
- /* Report lookahead tokens (or $default) and reductions. */
- if (reds->lookahead_tokens)
- for (i = 0; i < ntokens; i++)
- {
- bool defaulted = false;
- bool count = bitset_test (no_reduce_set, i);
-
- for (j = 0; j < reds->num; ++j)
- if (bitset_test (reds->lookahead_tokens[j], i))
- {
- if (! count)
- {
- if (reds->rules[j] != default_reduction)
- print_reduction (out, level + 1, symbols[i]->tag,
- reds->rules[j], true);
- else
- defaulted = true;
- count = true;
- }
- else
- {
- if (defaulted)
- print_reduction (out, level + 1, symbols[i]->tag,
- default_reduction, true);
- defaulted = false;
- print_reduction (out, level + 1, symbols[i]->tag,
- reds->rules[j], false);
- }
- }
- }
-
- if (default_reduction)
- print_reduction (out, level + 1,
- "$default", default_reduction, true);
-
- xml_puts (out, level, "</reductions>");
-}
-
-
-/*--------------------------------------------------------------.
-| Report on OUT all the actions (shifts, gotos, reductions, and |
-| explicit erros from %nonassoc) of S. |
-`--------------------------------------------------------------*/
-
-static void
-print_actions (FILE *out, int level, state *s)
-{
- xml_puts (out, level, "<actions>");
- print_transitions (s, out, level + 1);
- print_errs (out, level + 1, s);
- print_reductions (out, level + 1, s);
- xml_puts (out, level, "</actions>");
-}
-
-
-/*----------------------------------.
-| Report all the data on S on OUT. |
-`----------------------------------*/
-
-static void
-print_state (FILE *out, int level, state *s)
-{
- fputc ('\n', out);
- xml_printf (out, level, "<state number=\"%d\">", s->number);
- print_core (out, level + 1, s);
- print_actions (out, level + 1, s);
- if (s->solved_conflicts_xml)
- {
- xml_puts (out, level + 1, "<solved-conflicts>");
- fputs (s->solved_conflicts_xml, out);
- xml_puts (out, level + 1, "</solved-conflicts>");
- }
- else
- xml_puts (out, level + 1, "<solved-conflicts/>");
- xml_puts (out, level, "</state>");
-}
-
-
-/*-----------------------------------------.
-| Print information on the whole grammar. |
-`-----------------------------------------*/
-
-static void
-print_grammar (FILE *out, int level)
-{
- symbol_number i;
-
- fputc ('\n', out);
- xml_puts (out, level, "<grammar>");
- grammar_rules_print_xml (out, level);
-
- /* Terminals */
- xml_puts (out, level + 1, "<terminals>");
- for (i = 0; i < max_user_token_number + 1; i++)
- if (token_translations[i] != undeftoken->number)
- {
- char const *tag = symbols[token_translations[i]]->tag;
- int precedence = symbols[token_translations[i]]->prec;
- assoc associativity = symbols[token_translations[i]]->assoc;
- xml_indent (out, level + 2);
- fprintf (out,
- "<terminal symbol-number=\"%d\" token-number=\"%d\""
- " name=\"%s\" usefulness=\"%s\"",
- token_translations[i], i, xml_escape (tag),
- reduce_token_unused_in_grammar (token_translations[i])
- ? "unused-in-grammar" : "useful");
- if (precedence)
- fprintf (out, " prec=\"%d\"", precedence);
- if (associativity != undef_assoc)
- fprintf (out, " assoc=\"%s\"", assoc_to_string (associativity) + 1);
- fputs ("/>\n", out);
- }
- xml_puts (out, level + 1, "</terminals>");
-
- /* Nonterminals */
- xml_puts (out, level + 1, "<nonterminals>");
- for (i = ntokens; i < nsyms + nuseless_nonterminals; i++)
- {
- char const *tag = symbols[i]->tag;
- xml_printf (out, level + 2,
- "<nonterminal symbol-number=\"%d\" name=\"%s\""
- " usefulness=\"%s\"/>",
- i, xml_escape (tag),
- reduce_nonterminal_useless_in_grammar (i)
- ? "useless-in-grammar" : "useful");
- }
- xml_puts (out, level + 1, "</nonterminals>");
- xml_puts (out, level, "</grammar>");
-}
-
-void
-xml_indent (FILE *out, int level)
-{
- int i;
- for (i = 0; i < level; i++)
- fputs (" ", out);
-}
-
-void
-xml_puts (FILE *out, int level, char const *s)
-{
- xml_indent (out, level);
- fputs (s, out);
- fputc ('\n', out);
-}
-
-void
-xml_printf (FILE *out, int level, char const *fmt, ...)
-{
- va_list arglist;
-
- xml_indent (out, level);
-
- va_start (arglist, fmt);
- vfprintf (out, fmt, arglist);
- va_end (arglist);
-
- fputc ('\n', out);
-}
-
-static char const *
-xml_escape_string (struct escape_buf *buf, char const *str)
-{
- size_t len = strlen (str);
- size_t max_expansion = sizeof "&quot;" - 1;
- char *p;
-
- if (buf->size <= max_expansion * len)
- {
- buf->size = max_expansion * len + 1;
- buf->ptr = x2realloc (buf->ptr, &buf->size);
- }
- p = buf->ptr;
-
- for (; *str; str++)
- switch (*str)
- {
- default: *p++ = *str; break;
- case '&': p = stpcpy (p, "&amp;" ); break;
- case '<': p = stpcpy (p, "&lt;" ); break;
- case '>': p = stpcpy (p, "&gt;" ); break;
- case '"': p = stpcpy (p, "&quot;"); break;
- }
-
- *p = '\0';
- return buf->ptr;
-}
-
-char const *
-xml_escape_n (int n, char const *str)
-{
- return xml_escape_string (escape_bufs + n, str);
-}
-
-char const *
-xml_escape (char const *str)
-{
- return xml_escape_n (0, str);
-}
-
-void
-print_xml (void)
-{
- int level = 0;
-
- FILE *out = xfopen (spec_xml_file, "w");
-
- fputs ("<?xml version=\"1.0\"?>\n\n", out);
- xml_printf (out, level,
- "<bison-xml-report version=\"%s\" bug-report=\"%s\""
- " url=\"%s\">",
- xml_escape_n (0, VERSION),
- xml_escape_n (1, PACKAGE_BUGREPORT),
- xml_escape_n (2, PACKAGE_URL));
-
- fputc ('\n', out);
- xml_printf (out, level + 1, "<filename>%s</filename>",
- xml_escape (grammar_file));
-
- /* print grammar */
- print_grammar (out, level + 1);
-
- new_closure (nritems);
- no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
-
- /* print automaton */
- fputc ('\n', out);
- xml_puts (out, level + 1, "<automaton>");
- {
- state_number i;
- for (i = 0; i < nstates; i++)
- print_state (out, level + 2, states[i]);
- }
- xml_puts (out, level + 1, "</automaton>");
-
- bitset_free (no_reduce_set);
- free_closure ();
-
- xml_puts (out, 0, "</bison-xml-report>");
-
- {
- int i;
- for (i = 0; i < num_escape_bufs; ++i)
- free (escape_bufs[i].ptr);
- }
-
- xfclose (out);
-}
+#include "system.h"
+
+#include <stdarg.h>
+
+#include <bitset.h>
+
+#include "LR0.h"
+#include "closure.h"
+#include "conflicts.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "lalr.h"
+#include "print.h"
+#include "print-xml.h"
+#include "reader.h"
+#include "reduce.h"
+#include "state.h"
+#include "symtab.h"
+#include "tables.h"
+
+static bitset no_reduce_set;
+struct escape_buf
+{
+ char *ptr;
+ size_t size;
+};
+enum { num_escape_bufs = 3 };
+static struct escape_buf escape_bufs[num_escape_bufs];
+
+
+/*--------------------------------.
+| Report information on a state. |
+`--------------------------------*/
+
+static void
+print_core (FILE *out, int level, state *s)
+{
+ size_t i;
+ item_number *sitems = s->items;
+ size_t snritems = s->nitems;
+
+ /* Output all the items of a state, not only its kernel. */
+ closure (sitems, snritems);
+ sitems = itemset;
+ snritems = nitemset;
+
+ if (!snritems) {
+ xml_puts (out, level, "<itemset/>");
+ return;
+ }
+
+ xml_puts (out, level, "<itemset>");
+
+ for (i = 0; i < snritems; i++)
+ {
+ bool printed = false;
+ item_number *sp;
+ item_number *sp1;
+ rule_number r;
+
+ sp1 = sp = ritem + sitems[i];
+
+ while (*sp >= 0)
+ sp++;
+
+ r = item_number_as_rule_number (*sp);
+ sp = rules[r].rhs;
+
+ /* Display the lookahead tokens? */
+ if (item_number_is_rule_number (*sp1))
+ {
+ reductions *reds = s->reductions;
+ int red = state_reduction_find (s, &rules[r]);
+ /* Print item with lookaheads if there are. */
+ if (reds->lookahead_tokens && red != -1)
+ {
+ xml_printf (out, level + 1,
+ "<item rule-number=\"%d\" point=\"%d\">",
+ rules[r].number, sp1 - sp);
+ state_rule_lookahead_tokens_print_xml (s, &rules[r],
+ out, level + 2);
+ xml_puts (out, level + 1, "</item>");
+ printed = true;
+ }
+ }
+
+ if (!printed)
+ {
+ xml_printf (out, level + 1,
+ "<item rule-number=\"%d\" point=\"%d\"/>",
+ rules[r].number,
+ sp1 - sp);
+ }
+ }
+ xml_puts (out, level, "</itemset>");
+}
+
+
+/*-----------------------------------------------------------.
+| Report the shifts if DISPLAY_SHIFTS_P or the gotos of S on |
+| OUT. |
+`-----------------------------------------------------------*/
+
+static void
+print_transitions (state *s, FILE *out, int level)
+{
+ transitions *trans = s->transitions;
+ int n = 0;
+ int i;
+
+ for (i = 0; i < trans->num; i++)
+ if (!TRANSITION_IS_DISABLED (trans, i))
+ {
+ n++;
+ }
+
+ /* Nothing to report. */
+ if (!n) {
+ xml_puts (out, level, "<transitions/>");
+ return;
+ }
+
+ /* Report lookahead tokens and shifts. */
+ xml_puts (out, level, "<transitions>");
+
+ for (i = 0; i < trans->num; i++)
+ if (!TRANSITION_IS_DISABLED (trans, i)
+ && TRANSITION_IS_SHIFT (trans, i))
+ {
+ symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+ char const *tag = sym->tag;
+ state *s1 = trans->states[i];
+
+ xml_printf (out, level + 1,
+ "<transition type=\"shift\" symbol=\"%s\" state=\"%d\"/>",
+ xml_escape (tag), s1->number);
+ }
+
+ for (i = 0; i < trans->num; i++)
+ if (!TRANSITION_IS_DISABLED (trans, i)
+ && !TRANSITION_IS_SHIFT (trans, i))
+ {
+ symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+ char const *tag = sym->tag;
+ state *s1 = trans->states[i];
+
+ xml_printf (out, level + 1,
+ "<transition type=\"goto\" symbol=\"%s\" state=\"%d\"/>",
+ xml_escape (tag), s1->number);
+ }
+
+ xml_puts (out, level, "</transitions>");
+}
+
+
+/*--------------------------------------------------------.
+| Report the explicit errors of S raised from %nonassoc. |
+`--------------------------------------------------------*/
+
+static void
+print_errs (FILE *out, int level, state *s)
+{
+ errs *errp = s->errs;
+ bool count = false;
+ int i;
+
+ for (i = 0; i < errp->num; ++i)
+ if (errp->symbols[i])
+ count = true;
+
+ /* Nothing to report. */
+ if (!count) {
+ xml_puts (out, level, "<errors/>");
+ return;
+ }
+
+ /* Report lookahead tokens and errors. */
+ xml_puts (out, level, "<errors>");
+ for (i = 0; i < errp->num; ++i)
+ if (errp->symbols[i])
+ {
+ char const *tag = errp->symbols[i]->tag;
+ xml_printf (out, level + 1,
+ "<error symbol=\"%s\">nonassociative</error>",
+ xml_escape (tag));
+ }
+ xml_puts (out, level, "</errors>");
+}
+
+
+/*-------------------------------------------------------------------------.
+| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). |
+| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
+| R/R conflicts). |
+`-------------------------------------------------------------------------*/
+
+static void
+print_reduction (FILE *out, int level, char const *lookahead_token,
+ rule *r, bool enabled)
+{
+ if (r->number)
+ xml_printf (out, level,
+ "<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>",
+ xml_escape (lookahead_token),
+ r->number,
+ enabled ? "true" : "false");
+ else
+ xml_printf (out, level,
+ "<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
+ xml_escape (lookahead_token),
+ enabled ? "true" : "false");
+}
+
+
+/*-------------------------------------------.
+| Report on OUT the reduction actions of S. |
+`-------------------------------------------*/
+
+static void
+print_reductions (FILE *out, int level, state *s)
+{
+ transitions *trans = s->transitions;
+ reductions *reds = s->reductions;
+ rule *default_reduction = NULL;
+ int report = false;
+ int i, j;
+
+ if (reds->num == 0)
+ {
+ xml_puts (out, level, "<reductions/>");
+ return;
+ }
+
+ if (yydefact[s->number] != 0)
+ default_reduction = &rules[yydefact[s->number] - 1];
+
+ bitset_zero (no_reduce_set);
+ FOR_EACH_SHIFT (trans, i)
+ bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i));
+ for (i = 0; i < s->errs->num; ++i)
+ if (s->errs->symbols[i])
+ bitset_set (no_reduce_set, s->errs->symbols[i]->number);
+
+ if (default_reduction)
+ report = true;
+
+ if (reds->lookahead_tokens)
+ for (i = 0; i < ntokens; i++)
+ {
+ bool count = bitset_test (no_reduce_set, i);
+
+ for (j = 0; j < reds->num; ++j)
+ if (bitset_test (reds->lookahead_tokens[j], i))
+ {
+ if (! count)
+ {
+ if (reds->rules[j] != default_reduction)
+ report = true;
+ count = true;
+ }
+ else
+ {
+ report = true;
+ }
+ }
+ }
+
+ /* Nothing to report. */
+ if (!report) {
+ xml_puts (out, level, "<reductions/>");
+ return;
+ }
+
+ xml_puts (out, level, "<reductions>");
+
+ /* Report lookahead tokens (or $default) and reductions. */
+ if (reds->lookahead_tokens)
+ for (i = 0; i < ntokens; i++)
+ {
+ bool defaulted = false;
+ bool count = bitset_test (no_reduce_set, i);
+
+ for (j = 0; j < reds->num; ++j)
+ if (bitset_test (reds->lookahead_tokens[j], i))
+ {
+ if (! count)
+ {
+ if (reds->rules[j] != default_reduction)
+ print_reduction (out, level + 1, symbols[i]->tag,
+ reds->rules[j], true);
+ else
+ defaulted = true;
+ count = true;
+ }
+ else
+ {
+ if (defaulted)
+ print_reduction (out, level + 1, symbols[i]->tag,
+ default_reduction, true);
+ defaulted = false;
+ print_reduction (out, level + 1, symbols[i]->tag,
+ reds->rules[j], false);
+ }
+ }
+ }
+
+ if (default_reduction)
+ print_reduction (out, level + 1,
+ "$default", default_reduction, true);
+
+ xml_puts (out, level, "</reductions>");
+}
+
+
+/*--------------------------------------------------------------.
+| Report on OUT all the actions (shifts, gotos, reductions, and |
+| explicit erros from %nonassoc) of S. |
+`--------------------------------------------------------------*/
+
+static void
+print_actions (FILE *out, int level, state *s)
+{
+ xml_puts (out, level, "<actions>");
+ print_transitions (s, out, level + 1);
+ print_errs (out, level + 1, s);
+ print_reductions (out, level + 1, s);
+ xml_puts (out, level, "</actions>");
+}
+
+
+/*----------------------------------.
+| Report all the data on S on OUT. |
+`----------------------------------*/
+
+static void
+print_state (FILE *out, int level, state *s)
+{
+ fputc ('\n', out);
+ xml_printf (out, level, "<state number=\"%d\">", s->number);
+ print_core (out, level + 1, s);
+ print_actions (out, level + 1, s);
+ if (s->solved_conflicts_xml)
+ {
+ xml_puts (out, level + 1, "<solved-conflicts>");
+ fputs (s->solved_conflicts_xml, out);
+ xml_puts (out, level + 1, "</solved-conflicts>");
+ }
+ else
+ xml_puts (out, level + 1, "<solved-conflicts/>");
+ xml_puts (out, level, "</state>");
+}
+
+
+/*-----------------------------------------.
+| Print information on the whole grammar. |
+`-----------------------------------------*/
+
+static void
+print_grammar (FILE *out, int level)
+{
+ symbol_number i;
+
+ fputc ('\n', out);
+ xml_puts (out, level, "<grammar>");
+ grammar_rules_print_xml (out, level);
+
+ /* Terminals */
+ xml_puts (out, level + 1, "<terminals>");
+ for (i = 0; i < max_user_token_number + 1; i++)
+ if (token_translations[i] != undeftoken->number)
+ {
+ char const *tag = symbols[token_translations[i]]->tag;
+ int precedence = symbols[token_translations[i]]->prec;
+ assoc associativity = symbols[token_translations[i]]->assoc;
+ xml_indent (out, level + 2);
+ fprintf (out,
+ "<terminal symbol-number=\"%d\" token-number=\"%d\""
+ " name=\"%s\" usefulness=\"%s\"",
+ token_translations[i], i, xml_escape (tag),
+ reduce_token_unused_in_grammar (token_translations[i])
+ ? "unused-in-grammar" : "useful");
+ if (precedence)
+ fprintf (out, " prec=\"%d\"", precedence);
+ if (associativity != undef_assoc)
+ fprintf (out, " assoc=\"%s\"", assoc_to_string (associativity) + 1);
+ fputs ("/>\n", out);
+ }
+ xml_puts (out, level + 1, "</terminals>");
+
+ /* Nonterminals */
+ xml_puts (out, level + 1, "<nonterminals>");
+ for (i = ntokens; i < nsyms + nuseless_nonterminals; i++)
+ {
+ char const *tag = symbols[i]->tag;
+ xml_printf (out, level + 2,
+ "<nonterminal symbol-number=\"%d\" name=\"%s\""
+ " usefulness=\"%s\"/>",
+ i, xml_escape (tag),
+ reduce_nonterminal_useless_in_grammar (i)
+ ? "useless-in-grammar" : "useful");
+ }
+ xml_puts (out, level + 1, "</nonterminals>");
+ xml_puts (out, level, "</grammar>");
+}
+
+void
+xml_indent (FILE *out, int level)
+{
+ int i;
+ for (i = 0; i < level; i++)
+ fputs (" ", out);
+}
+
+void
+xml_puts (FILE *out, int level, char const *s)
+{
+ xml_indent (out, level);
+ fputs (s, out);
+ fputc ('\n', out);
+}
+
+void
+xml_printf (FILE *out, int level, char const *fmt, ...)
+{
+ va_list arglist;
+
+ xml_indent (out, level);
+
+ va_start (arglist, fmt);
+ vfprintf (out, fmt, arglist);
+ va_end (arglist);
+
+ fputc ('\n', out);
+}
+
+static char const *
+xml_escape_string (struct escape_buf *buf, char const *str)
+{
+ size_t len = strlen (str);
+ size_t max_expansion = sizeof "&quot;" - 1;
+ char *p;
+
+ if (buf->size <= max_expansion * len)
+ {
+ buf->size = max_expansion * len + 1;
+ buf->ptr = x2realloc (buf->ptr, &buf->size);
+ }
+ p = buf->ptr;
+
+ for (; *str; str++)
+ switch (*str)
+ {
+ default: *p++ = *str; break;
+ case '&': p = stpcpy (p, "&amp;" ); break;
+ case '<': p = stpcpy (p, "&lt;" ); break;
+ case '>': p = stpcpy (p, "&gt;" ); break;
+ case '"': p = stpcpy (p, "&quot;"); break;
+ }
+
+ *p = '\0';
+ return buf->ptr;
+}
+
+char const *
+xml_escape_n (int n, char const *str)
+{
+ return xml_escape_string (escape_bufs + n, str);
+}
+
+char const *
+xml_escape (char const *str)
+{
+ return xml_escape_n (0, str);
+}
+
+void
+print_xml (void)
+{
+ int level = 0;
+
+ FILE *out = xfopen (spec_xml_file, "w");
+
+ fputs ("<?xml version=\"1.0\"?>\n\n", out);
+ xml_printf (out, level,
+ "<bison-xml-report version=\"%s\" bug-report=\"%s\""
+ " url=\"%s\">",
+ xml_escape_n (0, VERSION),
+ xml_escape_n (1, PACKAGE_BUGREPORT),
+ xml_escape_n (2, PACKAGE_URL));
+
+ fputc ('\n', out);
+ xml_printf (out, level + 1, "<filename>%s</filename>",
+ xml_escape (grammar_file));
+
+ /* print grammar */
+ print_grammar (out, level + 1);
+
+ new_closure (nritems);
+ no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
+
+ /* print automaton */
+ fputc ('\n', out);
+ xml_puts (out, level + 1, "<automaton>");
+ {
+ state_number i;
+ for (i = 0; i < nstates; i++)
+ print_state (out, level + 2, states[i]);
+ }
+ xml_puts (out, level + 1, "</automaton>");
+
+ bitset_free (no_reduce_set);
+ free_closure ();
+
+ xml_puts (out, 0, "</bison-xml-report>");
+
+ {
+ int i;
+ for (i = 0; i < num_escape_bufs; ++i)
+ free (escape_bufs[i].ptr);
+ }
+
+ xfclose (out);
+}
diff --git a/contrib/tools/bison/bison/src/print-xml.h b/contrib/tools/bison/bison/src/print-xml.h
index 251c2033b9..c553076ae5 100644
--- a/contrib/tools/bison/bison/src/print-xml.h
+++ b/contrib/tools/bison/bison/src/print-xml.h
@@ -1,30 +1,30 @@
-/* Output an xml of the generated parser, for Bison.
-
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef PRINT_XML_H_
-# define PRINT_XML_H_
-
-void xml_indent (FILE *out, int level);
-void xml_puts (FILE *, int, char const *);
-void xml_printf (FILE *, int, char const *, ...);
-char const *xml_escape_n (int n, char const *str);
-char const *xml_escape (char const *str);
-void print_xml (void);
-
-#endif /* !PRINT_XML_H_ */
+/* Output an xml of the generated parser, for Bison.
+
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef PRINT_XML_H_
+# define PRINT_XML_H_
+
+void xml_indent (FILE *out, int level);
+void xml_puts (FILE *, int, char const *);
+void xml_printf (FILE *, int, char const *, ...);
+char const *xml_escape_n (int n, char const *str);
+char const *xml_escape (char const *str);
+void print_xml (void);
+
+#endif /* !PRINT_XML_H_ */
diff --git a/contrib/tools/bison/bison/src/print.c b/contrib/tools/bison/bison/src/print.c
index 824bb4ae82..c6af733333 100644
--- a/contrib/tools/bison/bison/src/print.c
+++ b/contrib/tools/bison/bison/src/print.c
@@ -1,529 +1,529 @@
-/* Print information on generated parser, for bison,
-
- Copyright (C) 1984, 1986, 1989, 2000-2005, 2007, 2009-2013 Free
- Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitset.h>
-
-#include "LR0.h"
-#include "closure.h"
-#include "conflicts.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "lalr.h"
-#include "muscle-tab.h"
-#include "print.h"
-#include "reader.h"
-#include "reduce.h"
-#include "state.h"
-#include "symtab.h"
-#include "tables.h"
-
-static bitset no_reduce_set;
-
-#if 0
-static void
-print_token (int extnum, int token)
-{
- fprintf (out, _(" type %d is %s\n"), extnum, tags[token]);
-}
-#endif
-
-
-
-/*---------------------------------------.
-| *WIDTH := max (*WIDTH, strlen (STR)). |
-`---------------------------------------*/
-
-static void
-max_length (size_t *width, const char *str)
-{
- size_t len = strlen (str);
- if (len > *width)
- *width = len;
-}
-
-/*--------------------------------.
-| Report information on a state. |
-`--------------------------------*/
-
-static void
-print_core (FILE *out, state *s)
-{
- size_t i;
- item_number *sitems = s->items;
- size_t snritems = s->nitems;
- symbol *previous_lhs = NULL;
-
- /* Output all the items of a state, not only its kernel. */
- if (report_flag & report_itemsets)
- {
- closure (sitems, snritems);
- sitems = itemset;
- snritems = nitemset;
- }
-
- if (!snritems)
- return;
-
- fputc ('\n', out);
-
- for (i = 0; i < snritems; i++)
- {
- item_number *sp;
- item_number *sp1;
- rule_number r;
-
- sp1 = sp = ritem + sitems[i];
-
- while (*sp >= 0)
- sp++;
-
- r = item_number_as_rule_number (*sp);
-
- rule_lhs_print (&rules[r], previous_lhs, out);
- previous_lhs = rules[r].lhs;
-
- for (sp = rules[r].rhs; sp < sp1; sp++)
- fprintf (out, " %s", symbols[*sp]->tag);
- fputs (" .", out);
- for (/* Nothing */; *sp >= 0; ++sp)
- fprintf (out, " %s", symbols[*sp]->tag);
-
- /* Display the lookahead tokens? */
- if (report_flag & report_lookahead_tokens
- && item_number_is_rule_number (*sp1))
- state_rule_lookahead_tokens_print (s, &rules[r], out);
-
- fputc ('\n', out);
- }
-}
-
-
-/*------------------------------------------------------------.
-| Report the shifts iff DISPLAY_SHIFTS_P or the gotos of S on |
-| OUT. |
-`------------------------------------------------------------*/
-
-static void
-print_transitions (state *s, FILE *out, bool display_transitions_p)
-{
- transitions *trans = s->transitions;
- size_t width = 0;
- int i;
-
- /* Compute the width of the lookahead token column. */
- for (i = 0; i < trans->num; i++)
- if (!TRANSITION_IS_DISABLED (trans, i)
- && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
- {
- symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
- max_length (&width, sym->tag);
- }
-
- /* Nothing to report. */
- if (!width)
- return;
-
- fputc ('\n', out);
- width += 2;
-
- /* Report lookahead tokens and shifts. */
- for (i = 0; i < trans->num; i++)
- if (!TRANSITION_IS_DISABLED (trans, i)
- && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
- {
- symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
- const char *tag = sym->tag;
- state *s1 = trans->states[i];
- int j;
-
- fprintf (out, " %s", tag);
- for (j = width - strlen (tag); j > 0; --j)
- fputc (' ', out);
- if (display_transitions_p)
- fprintf (out, _("shift, and go to state %d\n"), s1->number);
- else
- fprintf (out, _("go to state %d\n"), s1->number);
- }
-}
-
-
-/*--------------------------------------------------------.
-| Report the explicit errors of S raised from %nonassoc. |
-`--------------------------------------------------------*/
-
-static void
-print_errs (FILE *out, state *s)
-{
- errs *errp = s->errs;
- size_t width = 0;
- int i;
-
- /* Compute the width of the lookahead token column. */
- for (i = 0; i < errp->num; ++i)
- if (errp->symbols[i])
- max_length (&width, errp->symbols[i]->tag);
-
- /* Nothing to report. */
- if (!width)
- return;
-
- fputc ('\n', out);
- width += 2;
-
- /* Report lookahead tokens and errors. */
- for (i = 0; i < errp->num; ++i)
- if (errp->symbols[i])
- {
- const char *tag = errp->symbols[i]->tag;
- int j;
- fprintf (out, " %s", tag);
- for (j = width - strlen (tag); j > 0; --j)
- fputc (' ', out);
- fputs (_("error (nonassociative)\n"), out);
- }
-}
-
-
-/*-------------------------------------------------------------------------.
-| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). |
-| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
-| R/R conflicts). |
-`-------------------------------------------------------------------------*/
-
-static void
-print_reduction (FILE *out, size_t width,
- const char *lookahead_token,
- rule *r, bool enabled)
-{
- int j;
- fprintf (out, " %s", lookahead_token);
- for (j = width - strlen (lookahead_token); j > 0; --j)
- fputc (' ', out);
- if (!enabled)
- fputc ('[', out);
- if (r->number)
- fprintf (out, _("reduce using rule %d (%s)"), r->number, r->lhs->tag);
- else
- fprintf (out, _("accept"));
- if (!enabled)
- fputc (']', out);
- fputc ('\n', out);
-}
-
-
-/*-------------------------------------------.
-| Report on OUT the reduction actions of S. |
-`-------------------------------------------*/
-
-static void
-print_reductions (FILE *out, state *s)
-{
- transitions *trans = s->transitions;
- reductions *reds = s->reductions;
- rule *default_reduction = NULL;
- size_t width = 0;
- int i, j;
- bool default_reduction_only = true;
-
- if (reds->num == 0)
- return;
-
- if (yydefact[s->number] != 0)
- default_reduction = &rules[yydefact[s->number] - 1];
-
- bitset_zero (no_reduce_set);
- FOR_EACH_SHIFT (trans, i)
- bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i));
- for (i = 0; i < s->errs->num; ++i)
- if (s->errs->symbols[i])
- bitset_set (no_reduce_set, s->errs->symbols[i]->number);
-
- /* Compute the width of the lookahead token column. */
- if (default_reduction)
- width = strlen (_("$default"));
-
- if (reds->lookahead_tokens)
- for (i = 0; i < ntokens; i++)
- {
- bool count = bitset_test (no_reduce_set, i);
-
- for (j = 0; j < reds->num; ++j)
- if (bitset_test (reds->lookahead_tokens[j], i))
- {
- if (! count)
- {
- if (reds->rules[j] != default_reduction)
- max_length (&width, symbols[i]->tag);
- count = true;
- }
- else
- {
- max_length (&width, symbols[i]->tag);
- }
- }
- }
-
- /* Nothing to report. */
- if (!width)
- return;
-
- fputc ('\n', out);
- width += 2;
-
- /* Report lookahead tokens (or $default) and reductions. */
- if (reds->lookahead_tokens)
- for (i = 0; i < ntokens; i++)
- {
- bool defaulted = false;
- bool count = bitset_test (no_reduce_set, i);
- if (count)
- default_reduction_only = false;
-
- for (j = 0; j < reds->num; ++j)
- if (bitset_test (reds->lookahead_tokens[j], i))
- {
- if (! count)
- {
- if (reds->rules[j] != default_reduction)
- {
- default_reduction_only = false;
- print_reduction (out, width,
- symbols[i]->tag,
- reds->rules[j], true);
- }
- else
- defaulted = true;
- count = true;
- }
- else
- {
- default_reduction_only = false;
- if (defaulted)
- print_reduction (out, width,
- symbols[i]->tag,
- default_reduction, true);
- defaulted = false;
- print_reduction (out, width,
- symbols[i]->tag,
- reds->rules[j], false);
- }
- }
- }
-
- if (default_reduction)
- {
- char *default_reductions =
- muscle_percent_define_get ("lr.default-reduction");
- print_reduction (out, width, _("$default"), default_reduction, true);
- aver (STREQ (default_reductions, "most")
- || (STREQ (default_reductions, "consistent")
- && default_reduction_only)
- || (reds->num == 1 && reds->rules[0]->number == 0));
- free (default_reductions);
- }
-}
-
-
-/*--------------------------------------------------------------.
-| Report on OUT all the actions (shifts, gotos, reductions, and |
-| explicit erros from %nonassoc) of S. |
-`--------------------------------------------------------------*/
-
-static void
-print_actions (FILE *out, state *s)
-{
- /* Print shifts. */
- print_transitions (s, out, true);
- print_errs (out, s);
- print_reductions (out, s);
- /* Print gotos. */
- print_transitions (s, out, false);
-}
-
-
-/*----------------------------------.
-| Report all the data on S on OUT. |
-`----------------------------------*/
-
-static void
-print_state (FILE *out, state *s)
-{
- fputs ("\n\n", out);
- fprintf (out, _("State %d"), s->number);
- fputc ('\n', out);
- print_core (out, s);
- print_actions (out, s);
- if ((report_flag & report_solved_conflicts) && s->solved_conflicts)
- {
- fputc ('\n', out);
- fputs (s->solved_conflicts, out);
- }
-}
-
-/*-----------------------------------------.
-| Print information on the whole grammar. |
-`-----------------------------------------*/
-
-#define END_TEST(End) \
- do { \
- if (column + strlen (buffer) > (End)) \
- { \
- fprintf (out, "%s\n ", buffer); \
- column = 3; \
- buffer[0] = 0; \
- } \
- } while (0)
-
-
-static void
-print_grammar (FILE *out)
-{
- symbol_number i;
- char buffer[90];
- int column = 0;
-
- grammar_rules_print (out);
-
- /* TERMINAL (type #) : rule #s terminal is on RHS */
- fprintf (out, "%s\n\n", _("Terminals, with rules where they appear"));
- for (i = 0; i < max_user_token_number + 1; i++)
- if (token_translations[i] != undeftoken->number)
- {
- const char *tag = symbols[token_translations[i]]->tag;
- rule_number r;
- item_number *rhsp;
-
- buffer[0] = 0;
- column = strlen (tag);
- fputs (tag, out);
- END_TEST (65);
- sprintf (buffer, " (%d)", i);
-
- for (r = 0; r < nrules; r++)
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == token_translations[i])
- {
- END_TEST (65);
- sprintf (buffer + strlen (buffer), " %d", r);
- break;
- }
- fprintf (out, "%s\n", buffer);
- }
- fputs ("\n\n", out);
-
-
- fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
- for (i = ntokens; i < nsyms; i++)
- {
- int left_count = 0, right_count = 0;
- rule_number r;
- const char *tag = symbols[i]->tag;
-
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- if (rules[r].lhs->number == i)
- left_count++;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- right_count++;
- break;
- }
- }
-
- buffer[0] = 0;
- fputs (tag, out);
- column = strlen (tag);
- sprintf (buffer, " (%d)", i);
- END_TEST (0);
-
- if (left_count > 0)
- {
- END_TEST (65);
- sprintf (buffer + strlen (buffer), _(" on left:"));
-
- for (r = 0; r < nrules; r++)
- {
- if (rules[r].lhs->number == i)
- {
- END_TEST (65);
- sprintf (buffer + strlen (buffer), " %d", r);
- }
- }
- }
-
- if (right_count > 0)
- {
- if (left_count > 0)
- sprintf (buffer + strlen (buffer), ",");
- END_TEST (65);
- sprintf (buffer + strlen (buffer), _(" on right:"));
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- END_TEST (65);
- sprintf (buffer + strlen (buffer), " %d", r);
- break;
- }
- }
- }
- fprintf (out, "%s\n", buffer);
- }
-}
-
-void
-print_results (void)
-{
- state_number i;
-
- /* We used to use just .out if SPEC_NAME_PREFIX (-p) was used, but
- that conflicts with Posix. */
- FILE *out = xfopen (spec_verbose_file, "w");
-
- reduce_output (out);
- grammar_rules_partial_print (out,
- _("Rules useless in parser due to conflicts"),
- rule_useless_in_parser_p);
- conflicts_output (out);
-
- print_grammar (out);
-
- /* If the whole state item sets, not only the kernels, are wanted,
- 'closure' will be run, which needs memory allocation/deallocation. */
- if (report_flag & report_itemsets)
- new_closure (nritems);
- /* Storage for print_reductions. */
- no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
- for (i = 0; i < nstates; i++)
- print_state (out, states[i]);
- bitset_free (no_reduce_set);
- if (report_flag & report_itemsets)
- free_closure ();
-
- xfclose (out);
-}
+/* Print information on generated parser, for bison,
+
+ Copyright (C) 1984, 1986, 1989, 2000-2005, 2007, 2009-2013 Free
+ Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitset.h>
+
+#include "LR0.h"
+#include "closure.h"
+#include "conflicts.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "lalr.h"
+#include "muscle-tab.h"
+#include "print.h"
+#include "reader.h"
+#include "reduce.h"
+#include "state.h"
+#include "symtab.h"
+#include "tables.h"
+
+static bitset no_reduce_set;
+
+#if 0
+static void
+print_token (int extnum, int token)
+{
+ fprintf (out, _(" type %d is %s\n"), extnum, tags[token]);
+}
+#endif
+
+
+
+/*---------------------------------------.
+| *WIDTH := max (*WIDTH, strlen (STR)). |
+`---------------------------------------*/
+
+static void
+max_length (size_t *width, const char *str)
+{
+ size_t len = strlen (str);
+ if (len > *width)
+ *width = len;
+}
+
+/*--------------------------------.
+| Report information on a state. |
+`--------------------------------*/
+
+static void
+print_core (FILE *out, state *s)
+{
+ size_t i;
+ item_number *sitems = s->items;
+ size_t snritems = s->nitems;
+ symbol *previous_lhs = NULL;
+
+ /* Output all the items of a state, not only its kernel. */
+ if (report_flag & report_itemsets)
+ {
+ closure (sitems, snritems);
+ sitems = itemset;
+ snritems = nitemset;
+ }
+
+ if (!snritems)
+ return;
+
+ fputc ('\n', out);
+
+ for (i = 0; i < snritems; i++)
+ {
+ item_number *sp;
+ item_number *sp1;
+ rule_number r;
+
+ sp1 = sp = ritem + sitems[i];
+
+ while (*sp >= 0)
+ sp++;
+
+ r = item_number_as_rule_number (*sp);
+
+ rule_lhs_print (&rules[r], previous_lhs, out);
+ previous_lhs = rules[r].lhs;
+
+ for (sp = rules[r].rhs; sp < sp1; sp++)
+ fprintf (out, " %s", symbols[*sp]->tag);
+ fputs (" .", out);
+ for (/* Nothing */; *sp >= 0; ++sp)
+ fprintf (out, " %s", symbols[*sp]->tag);
+
+ /* Display the lookahead tokens? */
+ if (report_flag & report_lookahead_tokens
+ && item_number_is_rule_number (*sp1))
+ state_rule_lookahead_tokens_print (s, &rules[r], out);
+
+ fputc ('\n', out);
+ }
+}
+
+
+/*------------------------------------------------------------.
+| Report the shifts iff DISPLAY_SHIFTS_P or the gotos of S on |
+| OUT. |
+`------------------------------------------------------------*/
+
+static void
+print_transitions (state *s, FILE *out, bool display_transitions_p)
+{
+ transitions *trans = s->transitions;
+ size_t width = 0;
+ int i;
+
+ /* Compute the width of the lookahead token column. */
+ for (i = 0; i < trans->num; i++)
+ if (!TRANSITION_IS_DISABLED (trans, i)
+ && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
+ {
+ symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+ max_length (&width, sym->tag);
+ }
+
+ /* Nothing to report. */
+ if (!width)
+ return;
+
+ fputc ('\n', out);
+ width += 2;
+
+ /* Report lookahead tokens and shifts. */
+ for (i = 0; i < trans->num; i++)
+ if (!TRANSITION_IS_DISABLED (trans, i)
+ && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
+ {
+ symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
+ const char *tag = sym->tag;
+ state *s1 = trans->states[i];
+ int j;
+
+ fprintf (out, " %s", tag);
+ for (j = width - strlen (tag); j > 0; --j)
+ fputc (' ', out);
+ if (display_transitions_p)
+ fprintf (out, _("shift, and go to state %d\n"), s1->number);
+ else
+ fprintf (out, _("go to state %d\n"), s1->number);
+ }
+}
+
+
+/*--------------------------------------------------------.
+| Report the explicit errors of S raised from %nonassoc. |
+`--------------------------------------------------------*/
+
+static void
+print_errs (FILE *out, state *s)
+{
+ errs *errp = s->errs;
+ size_t width = 0;
+ int i;
+
+ /* Compute the width of the lookahead token column. */
+ for (i = 0; i < errp->num; ++i)
+ if (errp->symbols[i])
+ max_length (&width, errp->symbols[i]->tag);
+
+ /* Nothing to report. */
+ if (!width)
+ return;
+
+ fputc ('\n', out);
+ width += 2;
+
+ /* Report lookahead tokens and errors. */
+ for (i = 0; i < errp->num; ++i)
+ if (errp->symbols[i])
+ {
+ const char *tag = errp->symbols[i]->tag;
+ int j;
+ fprintf (out, " %s", tag);
+ for (j = width - strlen (tag); j > 0; --j)
+ fputc (' ', out);
+ fputs (_("error (nonassociative)\n"), out);
+ }
+}
+
+
+/*-------------------------------------------------------------------------.
+| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). |
+| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
+| R/R conflicts). |
+`-------------------------------------------------------------------------*/
+
+static void
+print_reduction (FILE *out, size_t width,
+ const char *lookahead_token,
+ rule *r, bool enabled)
+{
+ int j;
+ fprintf (out, " %s", lookahead_token);
+ for (j = width - strlen (lookahead_token); j > 0; --j)
+ fputc (' ', out);
+ if (!enabled)
+ fputc ('[', out);
+ if (r->number)
+ fprintf (out, _("reduce using rule %d (%s)"), r->number, r->lhs->tag);
+ else
+ fprintf (out, _("accept"));
+ if (!enabled)
+ fputc (']', out);
+ fputc ('\n', out);
+}
+
+
+/*-------------------------------------------.
+| Report on OUT the reduction actions of S. |
+`-------------------------------------------*/
+
+static void
+print_reductions (FILE *out, state *s)
+{
+ transitions *trans = s->transitions;
+ reductions *reds = s->reductions;
+ rule *default_reduction = NULL;
+ size_t width = 0;
+ int i, j;
+ bool default_reduction_only = true;
+
+ if (reds->num == 0)
+ return;
+
+ if (yydefact[s->number] != 0)
+ default_reduction = &rules[yydefact[s->number] - 1];
+
+ bitset_zero (no_reduce_set);
+ FOR_EACH_SHIFT (trans, i)
+ bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i));
+ for (i = 0; i < s->errs->num; ++i)
+ if (s->errs->symbols[i])
+ bitset_set (no_reduce_set, s->errs->symbols[i]->number);
+
+ /* Compute the width of the lookahead token column. */
+ if (default_reduction)
+ width = strlen (_("$default"));
+
+ if (reds->lookahead_tokens)
+ for (i = 0; i < ntokens; i++)
+ {
+ bool count = bitset_test (no_reduce_set, i);
+
+ for (j = 0; j < reds->num; ++j)
+ if (bitset_test (reds->lookahead_tokens[j], i))
+ {
+ if (! count)
+ {
+ if (reds->rules[j] != default_reduction)
+ max_length (&width, symbols[i]->tag);
+ count = true;
+ }
+ else
+ {
+ max_length (&width, symbols[i]->tag);
+ }
+ }
+ }
+
+ /* Nothing to report. */
+ if (!width)
+ return;
+
+ fputc ('\n', out);
+ width += 2;
+
+ /* Report lookahead tokens (or $default) and reductions. */
+ if (reds->lookahead_tokens)
+ for (i = 0; i < ntokens; i++)
+ {
+ bool defaulted = false;
+ bool count = bitset_test (no_reduce_set, i);
+ if (count)
+ default_reduction_only = false;
+
+ for (j = 0; j < reds->num; ++j)
+ if (bitset_test (reds->lookahead_tokens[j], i))
+ {
+ if (! count)
+ {
+ if (reds->rules[j] != default_reduction)
+ {
+ default_reduction_only = false;
+ print_reduction (out, width,
+ symbols[i]->tag,
+ reds->rules[j], true);
+ }
+ else
+ defaulted = true;
+ count = true;
+ }
+ else
+ {
+ default_reduction_only = false;
+ if (defaulted)
+ print_reduction (out, width,
+ symbols[i]->tag,
+ default_reduction, true);
+ defaulted = false;
+ print_reduction (out, width,
+ symbols[i]->tag,
+ reds->rules[j], false);
+ }
+ }
+ }
+
+ if (default_reduction)
+ {
+ char *default_reductions =
+ muscle_percent_define_get ("lr.default-reduction");
+ print_reduction (out, width, _("$default"), default_reduction, true);
+ aver (STREQ (default_reductions, "most")
+ || (STREQ (default_reductions, "consistent")
+ && default_reduction_only)
+ || (reds->num == 1 && reds->rules[0]->number == 0));
+ free (default_reductions);
+ }
+}
+
+
+/*--------------------------------------------------------------.
+| Report on OUT all the actions (shifts, gotos, reductions, and |
+| explicit erros from %nonassoc) of S. |
+`--------------------------------------------------------------*/
+
+static void
+print_actions (FILE *out, state *s)
+{
+ /* Print shifts. */
+ print_transitions (s, out, true);
+ print_errs (out, s);
+ print_reductions (out, s);
+ /* Print gotos. */
+ print_transitions (s, out, false);
+}
+
+
+/*----------------------------------.
+| Report all the data on S on OUT. |
+`----------------------------------*/
+
+static void
+print_state (FILE *out, state *s)
+{
+ fputs ("\n\n", out);
+ fprintf (out, _("State %d"), s->number);
+ fputc ('\n', out);
+ print_core (out, s);
+ print_actions (out, s);
+ if ((report_flag & report_solved_conflicts) && s->solved_conflicts)
+ {
+ fputc ('\n', out);
+ fputs (s->solved_conflicts, out);
+ }
+}
+
+/*-----------------------------------------.
+| Print information on the whole grammar. |
+`-----------------------------------------*/
+
+#define END_TEST(End) \
+ do { \
+ if (column + strlen (buffer) > (End)) \
+ { \
+ fprintf (out, "%s\n ", buffer); \
+ column = 3; \
+ buffer[0] = 0; \
+ } \
+ } while (0)
+
+
+static void
+print_grammar (FILE *out)
+{
+ symbol_number i;
+ char buffer[90];
+ int column = 0;
+
+ grammar_rules_print (out);
+
+ /* TERMINAL (type #) : rule #s terminal is on RHS */
+ fprintf (out, "%s\n\n", _("Terminals, with rules where they appear"));
+ for (i = 0; i < max_user_token_number + 1; i++)
+ if (token_translations[i] != undeftoken->number)
+ {
+ const char *tag = symbols[token_translations[i]]->tag;
+ rule_number r;
+ item_number *rhsp;
+
+ buffer[0] = 0;
+ column = strlen (tag);
+ fputs (tag, out);
+ END_TEST (65);
+ sprintf (buffer, " (%d)", i);
+
+ for (r = 0; r < nrules; r++)
+ for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
+ if (item_number_as_symbol_number (*rhsp) == token_translations[i])
+ {
+ END_TEST (65);
+ sprintf (buffer + strlen (buffer), " %d", r);
+ break;
+ }
+ fprintf (out, "%s\n", buffer);
+ }
+ fputs ("\n\n", out);
+
+
+ fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
+ for (i = ntokens; i < nsyms; i++)
+ {
+ int left_count = 0, right_count = 0;
+ rule_number r;
+ const char *tag = symbols[i]->tag;
+
+ for (r = 0; r < nrules; r++)
+ {
+ item_number *rhsp;
+ if (rules[r].lhs->number == i)
+ left_count++;
+ for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
+ if (item_number_as_symbol_number (*rhsp) == i)
+ {
+ right_count++;
+ break;
+ }
+ }
+
+ buffer[0] = 0;
+ fputs (tag, out);
+ column = strlen (tag);
+ sprintf (buffer, " (%d)", i);
+ END_TEST (0);
+
+ if (left_count > 0)
+ {
+ END_TEST (65);
+ sprintf (buffer + strlen (buffer), _(" on left:"));
+
+ for (r = 0; r < nrules; r++)
+ {
+ if (rules[r].lhs->number == i)
+ {
+ END_TEST (65);
+ sprintf (buffer + strlen (buffer), " %d", r);
+ }
+ }
+ }
+
+ if (right_count > 0)
+ {
+ if (left_count > 0)
+ sprintf (buffer + strlen (buffer), ",");
+ END_TEST (65);
+ sprintf (buffer + strlen (buffer), _(" on right:"));
+ for (r = 0; r < nrules; r++)
+ {
+ item_number *rhsp;
+ for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
+ if (item_number_as_symbol_number (*rhsp) == i)
+ {
+ END_TEST (65);
+ sprintf (buffer + strlen (buffer), " %d", r);
+ break;
+ }
+ }
+ }
+ fprintf (out, "%s\n", buffer);
+ }
+}
+
+void
+print_results (void)
+{
+ state_number i;
+
+ /* We used to use just .out if SPEC_NAME_PREFIX (-p) was used, but
+ that conflicts with Posix. */
+ FILE *out = xfopen (spec_verbose_file, "w");
+
+ reduce_output (out);
+ grammar_rules_partial_print (out,
+ _("Rules useless in parser due to conflicts"),
+ rule_useless_in_parser_p);
+ conflicts_output (out);
+
+ print_grammar (out);
+
+ /* If the whole state item sets, not only the kernels, are wanted,
+ 'closure' will be run, which needs memory allocation/deallocation. */
+ if (report_flag & report_itemsets)
+ new_closure (nritems);
+ /* Storage for print_reductions. */
+ no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
+ for (i = 0; i < nstates; i++)
+ print_state (out, states[i]);
+ bitset_free (no_reduce_set);
+ if (report_flag & report_itemsets)
+ free_closure ();
+
+ xfclose (out);
+}
diff --git a/contrib/tools/bison/bison/src/print.h b/contrib/tools/bison/bison/src/print.h
index e1e254a9bc..f117bd8c17 100644
--- a/contrib/tools/bison/bison/src/print.h
+++ b/contrib/tools/bison/bison/src/print.h
@@ -1,25 +1,25 @@
-/* Print information on generated parser, for bison,
-
- Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef PRINT_H_
-# define PRINT_H_
-
-void print_results (void);
-
-#endif /* !PRINT_H_ */
+/* Print information on generated parser, for bison,
+
+ Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef PRINT_H_
+# define PRINT_H_
+
+void print_results (void);
+
+#endif /* !PRINT_H_ */
diff --git a/contrib/tools/bison/bison/src/print_graph.c b/contrib/tools/bison/bison/src/print_graph.c
index 7e429dbd10..81d7f4c763 100644
--- a/contrib/tools/bison/bison/src/print_graph.c
+++ b/contrib/tools/bison/bison/src/print_graph.c
@@ -1,193 +1,193 @@
-/* Output a graph of the generated parser, for Bison.
-
- Copyright (C) 2001-2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "LR0.h"
-#include "closure.h"
-#include "complain.h"
-#include "conflicts.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "graphviz.h"
-#include "lalr.h"
-#include "print_graph.h"
-#include "reader.h"
-#include "state.h"
-#include "symtab.h"
-
-
-/*----------------------------.
-| Construct the node labels. |
-`----------------------------*/
-
-/* Print the lhs of a rule in such a manner that there is no vertical
- repetition, like in *.output files. */
-
-static void
-print_core (struct obstack *oout, state *s)
-{
- item_number const *sitems = s->items;
- symbol *previous_lhs = NULL;
- size_t i;
- size_t snritems = s->nitems;
-
- /* Output all the items of a state, not just its kernel. */
- if (report_flag & report_itemsets)
- {
- closure (sitems, snritems);
- sitems = itemset;
- snritems = nitemset;
- }
-
- obstack_printf (oout, _("State %d"), s->number);
- obstack_sgrow (oout, "\\n\\l");
- for (i = 0; i < snritems; i++)
- {
- item_number const *sp1 = ritem + sitems[i];
- item_number const *sp = sp1;
- rule *r;
-
- while (0 <= *sp)
- sp++;
-
- r = &rules[item_number_as_rule_number (*sp)];
-
- obstack_printf (oout, "%3d ", r->number);
- if (previous_lhs && UNIQSTR_EQ (previous_lhs->tag, r->lhs->tag))
- obstack_printf (oout, "%*s| ",
- (int) strlen (previous_lhs->tag), "");
- else
- obstack_printf (oout, "%s: ", escape (r->lhs->tag));
- previous_lhs = r->lhs;
-
- for (sp = r->rhs; sp < sp1; sp++)
- obstack_printf (oout, "%s ", escape (symbols[*sp]->tag));
-
- obstack_1grow (oout, '.');
-
- for (/* Nothing */; *sp >= 0; ++sp)
- obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
-
- /* Experimental feature: display the lookahead tokens. */
- if (report_flag & report_lookahead_tokens
- && item_number_is_rule_number (*sp1))
- {
- /* Find the reduction we are handling. */
- reductions *reds = s->reductions;
- int redno = state_reduction_find (s, r);
-
- /* Print them if there are. */
- if (reds->lookahead_tokens && redno != -1)
- {
- bitset_iterator biter;
- int k;
- char const *sep = "";
- obstack_sgrow (oout, " [");
- BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
- {
- obstack_sgrow (oout, sep);
- obstack_sgrow (oout, escape (symbols[k]->tag));
- sep = ", ";
- }
- obstack_1grow (oout, ']');
- }
- }
- obstack_sgrow (oout, "\\l");
- }
-}
-
-
-/*---------------------------------------------------------------.
-| Output in graph_obstack edges specifications in incidence with |
-| current node. |
-`---------------------------------------------------------------*/
-
-static void
-print_actions (state const *s, FILE *fgraph)
-{
- transitions const *trans = s->transitions;
- int i;
-
- if (!trans->num && !s->reductions)
- return;
-
- for (i = 0; i < trans->num; i++)
- if (!TRANSITION_IS_DISABLED (trans, i))
- {
- state *s1 = trans->states[i];
- symbol_number sym = s1->accessing_symbol;
-
- /* Shifts are solid, gotos are dashed, and error is dotted. */
- char const *style =
- (TRANSITION_IS_ERROR (trans, i) ? "dotted"
- : TRANSITION_IS_SHIFT (trans, i) ? "solid"
- : "dashed");
-
- if (TRANSITION_IS_ERROR (trans, i)
- && STRNEQ (symbols[sym]->tag, "error"))
- abort ();
- output_edge (s->number, s1->number,
- TRANSITION_IS_ERROR (trans, i) ? NULL : symbols[sym]->tag,
- style, fgraph);
- }
- /* Display reductions. */
- output_red (s, s->reductions, fgraph);
-}
-
-
-/*-------------------------------------------------------------.
-| Output in FGRAPH the current node specifications and exiting |
-| edges. |
-`-------------------------------------------------------------*/
-
-static void
-print_state (state *s, FILE *fgraph)
-{
- struct obstack node_obstack;
-
- /* A node's label contains its items. */
- obstack_init (&node_obstack);
- print_core (&node_obstack, s);
- output_node (s->number, obstack_finish0 (&node_obstack), fgraph);
- obstack_free (&node_obstack, 0);
-
- /* Output the edges. */
- print_actions (s, fgraph);
-}
-
-
-void
-print_graph (void)
-{
- state_number i;
- FILE *fgraph = xfopen (spec_graph_file, "w");
- start_graph (fgraph);
-
- /* Output nodes and edges. */
- new_closure (nritems);
- for (i = 0; i < nstates; i++)
- print_state (states[i], fgraph);
- free_closure ();
-
- finish_graph (fgraph);
- xfclose (fgraph);
-}
+/* Output a graph of the generated parser, for Bison.
+
+ Copyright (C) 2001-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "LR0.h"
+#include "closure.h"
+#include "complain.h"
+#include "conflicts.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "graphviz.h"
+#include "lalr.h"
+#include "print_graph.h"
+#include "reader.h"
+#include "state.h"
+#include "symtab.h"
+
+
+/*----------------------------.
+| Construct the node labels. |
+`----------------------------*/
+
+/* Print the lhs of a rule in such a manner that there is no vertical
+ repetition, like in *.output files. */
+
+static void
+print_core (struct obstack *oout, state *s)
+{
+ item_number const *sitems = s->items;
+ symbol *previous_lhs = NULL;
+ size_t i;
+ size_t snritems = s->nitems;
+
+ /* Output all the items of a state, not just its kernel. */
+ if (report_flag & report_itemsets)
+ {
+ closure (sitems, snritems);
+ sitems = itemset;
+ snritems = nitemset;
+ }
+
+ obstack_printf (oout, _("State %d"), s->number);
+ obstack_sgrow (oout, "\\n\\l");
+ for (i = 0; i < snritems; i++)
+ {
+ item_number const *sp1 = ritem + sitems[i];
+ item_number const *sp = sp1;
+ rule *r;
+
+ while (0 <= *sp)
+ sp++;
+
+ r = &rules[item_number_as_rule_number (*sp)];
+
+ obstack_printf (oout, "%3d ", r->number);
+ if (previous_lhs && UNIQSTR_EQ (previous_lhs->tag, r->lhs->tag))
+ obstack_printf (oout, "%*s| ",
+ (int) strlen (previous_lhs->tag), "");
+ else
+ obstack_printf (oout, "%s: ", escape (r->lhs->tag));
+ previous_lhs = r->lhs;
+
+ for (sp = r->rhs; sp < sp1; sp++)
+ obstack_printf (oout, "%s ", escape (symbols[*sp]->tag));
+
+ obstack_1grow (oout, '.');
+
+ for (/* Nothing */; *sp >= 0; ++sp)
+ obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
+
+ /* Experimental feature: display the lookahead tokens. */
+ if (report_flag & report_lookahead_tokens
+ && item_number_is_rule_number (*sp1))
+ {
+ /* Find the reduction we are handling. */
+ reductions *reds = s->reductions;
+ int redno = state_reduction_find (s, r);
+
+ /* Print them if there are. */
+ if (reds->lookahead_tokens && redno != -1)
+ {
+ bitset_iterator biter;
+ int k;
+ char const *sep = "";
+ obstack_sgrow (oout, " [");
+ BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
+ {
+ obstack_sgrow (oout, sep);
+ obstack_sgrow (oout, escape (symbols[k]->tag));
+ sep = ", ";
+ }
+ obstack_1grow (oout, ']');
+ }
+ }
+ obstack_sgrow (oout, "\\l");
+ }
+}
+
+
+/*---------------------------------------------------------------.
+| Output in graph_obstack edges specifications in incidence with |
+| current node. |
+`---------------------------------------------------------------*/
+
+static void
+print_actions (state const *s, FILE *fgraph)
+{
+ transitions const *trans = s->transitions;
+ int i;
+
+ if (!trans->num && !s->reductions)
+ return;
+
+ for (i = 0; i < trans->num; i++)
+ if (!TRANSITION_IS_DISABLED (trans, i))
+ {
+ state *s1 = trans->states[i];
+ symbol_number sym = s1->accessing_symbol;
+
+ /* Shifts are solid, gotos are dashed, and error is dotted. */
+ char const *style =
+ (TRANSITION_IS_ERROR (trans, i) ? "dotted"
+ : TRANSITION_IS_SHIFT (trans, i) ? "solid"
+ : "dashed");
+
+ if (TRANSITION_IS_ERROR (trans, i)
+ && STRNEQ (symbols[sym]->tag, "error"))
+ abort ();
+ output_edge (s->number, s1->number,
+ TRANSITION_IS_ERROR (trans, i) ? NULL : symbols[sym]->tag,
+ style, fgraph);
+ }
+ /* Display reductions. */
+ output_red (s, s->reductions, fgraph);
+}
+
+
+/*-------------------------------------------------------------.
+| Output in FGRAPH the current node specifications and exiting |
+| edges. |
+`-------------------------------------------------------------*/
+
+static void
+print_state (state *s, FILE *fgraph)
+{
+ struct obstack node_obstack;
+
+ /* A node's label contains its items. */
+ obstack_init (&node_obstack);
+ print_core (&node_obstack, s);
+ output_node (s->number, obstack_finish0 (&node_obstack), fgraph);
+ obstack_free (&node_obstack, 0);
+
+ /* Output the edges. */
+ print_actions (s, fgraph);
+}
+
+
+void
+print_graph (void)
+{
+ state_number i;
+ FILE *fgraph = xfopen (spec_graph_file, "w");
+ start_graph (fgraph);
+
+ /* Output nodes and edges. */
+ new_closure (nritems);
+ for (i = 0; i < nstates; i++)
+ print_state (states[i], fgraph);
+ free_closure ();
+
+ finish_graph (fgraph);
+ xfclose (fgraph);
+}
diff --git a/contrib/tools/bison/bison/src/print_graph.h b/contrib/tools/bison/bison/src/print_graph.h
index 073ae988b6..fccddfadb0 100644
--- a/contrib/tools/bison/bison/src/print_graph.h
+++ b/contrib/tools/bison/bison/src/print_graph.h
@@ -1,25 +1,25 @@
-/* Output a graph of the generated parser, for Bison.
-
- Copyright (C) 2000, 2006, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef PRINT_GRAPH_H_
-# define PRINT_GRAPH_H_
-
-void print_graph (void);
-
-#endif /* !PRINT_GRAPH_H_ */
+/* Output a graph of the generated parser, for Bison.
+
+ Copyright (C) 2000, 2006, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef PRINT_GRAPH_H_
+# define PRINT_GRAPH_H_
+
+void print_graph (void);
+
+#endif /* !PRINT_GRAPH_H_ */
diff --git a/contrib/tools/bison/bison/src/reader.c b/contrib/tools/bison/bison/src/reader.c
index 95c595ed4e..354b2adfa7 100644
--- a/contrib/tools/bison/bison/src/reader.c
+++ b/contrib/tools/bison/bison/src/reader.c
@@ -1,796 +1,796 @@
-/* Input parser for Bison
-
- Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000-2003, 2005-2007,
- 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <quote.h>
-
-#include "complain.h"
-#include "conflicts.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "muscle-tab.h"
-#include "reader.h"
-#include "symlist.h"
-#include "symtab.h"
-#include "scan-gram.h"
-#include "scan-code.h"
-
-static void prepare_percent_define_front_end_variables (void);
-static void check_and_convert_grammar (void);
-
-static symbol_list *grammar = NULL;
-static bool start_flag = false;
-merger_list *merge_functions;
-
-/* Was %union seen? */
-bool union_seen = false;
-
-/* Was a tag seen? */
-bool tag_seen = false;
-
-/* Should rules have a default precedence? */
-bool default_prec = true;
-
-/*-----------------------.
-| Set the start symbol. |
-`-----------------------*/
-
-void
-grammar_start_symbol_set (symbol *sym, location loc)
-{
- if (start_flag)
- complain (&loc, complaint, _("multiple %s declarations"), "%start");
- else
- {
- start_flag = true;
- startsymbol = sym;
- startsymbol_location = loc;
- }
-}
-
-
-
-/*------------------------------------------------------------------------.
-| Return the merger index for a merging function named NAME. Records the |
-| function, if new, in MERGER_LIST. |
-`------------------------------------------------------------------------*/
-
-static int
-get_merge_function (uniqstr name)
-{
- merger_list *syms;
- merger_list head;
- int n;
-
- if (! glr_parser)
- return 0;
-
- head.next = merge_functions;
- for (syms = &head, n = 1; syms->next; syms = syms->next, n += 1)
- if (UNIQSTR_EQ (name, syms->next->name))
- break;
- if (syms->next == NULL)
- {
- syms->next = xmalloc (sizeof syms->next[0]);
- syms->next->name = uniqstr_new (name);
- /* After all symbol type declarations have been parsed, packgram invokes
- record_merge_function_type to set the type. */
- syms->next->type = NULL;
- syms->next->next = NULL;
- merge_functions = head.next;
- }
- return n;
-}
-
-/*-------------------------------------------------------------------------.
-| For the existing merging function with index MERGER, record the result |
-| type as TYPE as required by the lhs of the rule whose %merge declaration |
-| is at DECLARATION_LOC. |
-`-------------------------------------------------------------------------*/
-
-static void
-record_merge_function_type (int merger, uniqstr type, location declaration_loc)
-{
- int merger_find;
- merger_list *merge_function;
-
- if (merger <= 0)
- return;
-
- if (type == NULL)
- type = uniqstr_new ("");
-
- merger_find = 1;
- for (merge_function = merge_functions;
- merge_function != NULL && merger_find != merger;
- merge_function = merge_function->next)
- merger_find += 1;
- aver (merge_function != NULL && merger_find == merger);
- if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type))
- {
- unsigned indent = 0;
- complain_indent (&declaration_loc, complaint, &indent,
- _("result type clash on merge function %s: "
- "<%s> != <%s>"),
- quote (merge_function->name), type,
- merge_function->type);
- indent += SUB_INDENT;
- complain_indent (&merge_function->type_declaration_location, complaint,
- &indent,
- _("previous declaration"));
- }
- merge_function->type = uniqstr_new (type);
- merge_function->type_declaration_location = declaration_loc;
-}
-
-/*--------------------------------------.
-| Free all merge-function definitions. |
-`--------------------------------------*/
-
-void
-free_merger_functions (void)
-{
- merger_list *L0 = merge_functions;
- while (L0)
- {
- merger_list *L1 = L0->next;
- free (L0);
- L0 = L1;
- }
-}
-
-
-/*-------------------------------------------------------------------.
-| Parse the input grammar into a one symbol_list structure. Each |
-| rule is represented by a sequence of symbols: the left hand side |
-| followed by the contents of the right hand side, followed by a |
-| null pointer instead of a symbol to terminate the rule. The next |
-| symbol is the lhs of the following rule. |
-| |
-| All actions are copied out, labelled by the rule number they apply |
-| to. |
-`-------------------------------------------------------------------*/
-
-/* The (currently) last symbol of GRAMMAR. */
-static symbol_list *grammar_end = NULL;
-
-/* Append SYM to the grammar. */
-static symbol_list *
-grammar_symbol_append (symbol *sym, location loc)
-{
- symbol_list *p = symbol_list_sym_new (sym, loc);
-
- if (grammar_end)
- grammar_end->next = p;
- else
- grammar = p;
-
- grammar_end = p;
-
- /* A null SYM stands for an end of rule; it is not an actual
- part of it. */
- if (sym)
- ++nritems;
-
- return p;
-}
-
-static void
-assign_named_ref (symbol_list *p, named_ref *name)
-{
- symbol *sym = p->content.sym;
-
- if (name->id == sym->tag)
- {
- complain (&name->loc, Wother,
- _("duplicated symbol name for %s ignored"),
- quote (sym->tag));
- named_ref_free (name);
- }
- else
- p->named_ref = name;
-}
-
-
-/* The rule currently being defined, and the previous rule.
- CURRENT_RULE points to the first LHS of the current rule, while
- PREVIOUS_RULE_END points to the *end* of the previous rule (NULL). */
-static symbol_list *current_rule = NULL;
-static symbol_list *previous_rule_end = NULL;
-
-
-/*----------------------------------------------.
-| Create a new rule for LHS in to the GRAMMAR. |
-`----------------------------------------------*/
-
-void
-grammar_current_rule_begin (symbol *lhs, location loc,
- named_ref *lhs_name)
-{
- symbol_list* p;
-
- /* Start a new rule and record its lhs. */
- ++nrules;
- previous_rule_end = grammar_end;
-
- p = grammar_symbol_append (lhs, loc);
- if (lhs_name)
- assign_named_ref (p, named_ref_copy (lhs_name));
-
- current_rule = grammar_end;
-
- /* Mark the rule's lhs as a nonterminal if not already so. */
- if (lhs->class == unknown_sym)
- {
- lhs->class = nterm_sym;
- lhs->number = nvars;
- ++nvars;
- }
- else if (lhs->class == token_sym)
- complain (&loc, complaint, _("rule given for %s, which is a token"),
- lhs->tag);
-}
-
-
-/*----------------------------------------------------------------------.
-| A symbol should be used if either: |
-| 1. It has a destructor. |
-| 2. The symbol is a mid-rule symbol (i.e., the generated LHS |
-| replacing a mid-rule action) that was assigned to or used, as in |
-| "exp: { $$ = 1; } { $$ = $1; }". |
-`----------------------------------------------------------------------*/
-
-static bool
-symbol_should_be_used (symbol_list const *s, bool *midrule_warning)
-{
- if (symbol_code_props_get (s->content.sym, destructor)->code)
- return true;
- if ((s->midrule && s->midrule->action_props.is_value_used)
- || (s->midrule_parent_rule
- && (symbol_list_n_get (s->midrule_parent_rule,
- s->midrule_parent_rhs_index)
- ->action_props.is_value_used)))
- {
- *midrule_warning = true;
- return true;
- }
- return false;
-}
-
-/*----------------------------------------------------------------.
-| Check that the rule R is properly defined. For instance, there |
-| should be no type clash on the default action. |
-`----------------------------------------------------------------*/
-
-static void
-grammar_rule_check (const symbol_list *r)
-{
- /* Type check.
-
- If there is an action, then there is nothing we can do: the user
- is allowed to shoot herself in the foot.
-
- Don't worry about the default action if $$ is untyped, since $$'s
- value can't be used. */
- if (!r->action_props.code && r->content.sym->type_name)
- {
- symbol *first_rhs = r->next->content.sym;
- /* If $$ is being set in default way, report if any type mismatch. */
- if (first_rhs)
- {
- char const *lhs_type = r->content.sym->type_name;
- const char *rhs_type =
- first_rhs->type_name ? first_rhs->type_name : "";
- if (!UNIQSTR_EQ (lhs_type, rhs_type))
- complain (&r->location, Wother,
- _("type clash on default action: <%s> != <%s>"),
- lhs_type, rhs_type);
- }
- /* Warn if there is no default for $$ but we need one. */
- else
- complain (&r->location, Wother,
- _("empty rule for typed nonterminal, and no action"));
- }
-
- /* Check that symbol values that should be used are in fact used. */
- {
- symbol_list const *l = r;
- int n = 0;
- for (; l && l->content.sym; l = l->next, ++n)
- {
- bool midrule_warning = false;
- if (!l->action_props.is_value_used
- && symbol_should_be_used (l, &midrule_warning)
- /* The default action, $$ = $1, 'uses' both. */
- && (r->action_props.code || (n != 0 && n != 1)))
- {
- warnings warn_flag = midrule_warning ? Wmidrule_values : Wother;
- if (n)
- complain (&l->location, warn_flag, _("unused value: $%d"), n);
- else
- complain (&l->location, warn_flag, _("unset value: $$"));
- }
- }
- }
-
- /* Check that %empty => empty rule. */
- if (r->percent_empty_loc.start.file
- && r->next && r->next->content.sym)
- complain (&r->percent_empty_loc, complaint,
- _("%%empty on non-empty rule"));
-
- /* Check that empty rule => %empty. */
- if (!(r->next && r->next->content.sym)
- && !r->midrule_parent_rule
- && !r->percent_empty_loc.start.file)
- complain (&r->location, Wempty_rule, _("empty rule without %%empty"));
-
- /* See comments in grammar_current_rule_prec_set for how POSIX
- mandates this complaint. It's only for identifiers, so skip
- it for char literals and strings, which are always tokens. */
- if (r->ruleprec
- && r->ruleprec->tag[0] != '\'' && r->ruleprec->tag[0] != '"'
- && r->ruleprec->status != declared && !r->ruleprec->prec)
- complain (&r->location, Wother,
- _("token for %%prec is not defined: %s"), r->ruleprec->tag);
-}
-
-
-/*-------------------------------------.
-| End the currently being grown rule. |
-`-------------------------------------*/
-
-void
-grammar_current_rule_end (location loc)
-{
- /* Put an empty link in the list to mark the end of this rule */
- grammar_symbol_append (NULL, grammar_end->location);
- current_rule->location = loc;
-}
-
-
-/*-------------------------------------------------------------------.
-| The previous action turns out the be a mid-rule action. Attach it |
-| to the current rule, i.e., create a dummy symbol, attach it this |
-| mid-rule action, and append this dummy nonterminal to the current |
-| rule. |
-`-------------------------------------------------------------------*/
-
-void
-grammar_midrule_action (void)
-{
- /* Since the action was written out with this rule's number, we must
- give the new rule this number by inserting the new rule before
- it. */
-
- /* Make a DUMMY nonterminal, whose location is that of the midrule
- action. Create the MIDRULE. */
- location dummy_location = current_rule->action_props.location;
- symbol *dummy = dummy_symbol_get (dummy_location);
- symbol_list *midrule = symbol_list_sym_new (dummy, dummy_location);
-
- /* Remember named_ref of previous action. */
- named_ref *action_name = current_rule->action_props.named_ref;
-
- /* Make a new rule, whose body is empty, before the current one, so
- that the action just read can belong to it. */
- ++nrules;
- ++nritems;
- /* Attach its location and actions to that of the DUMMY. */
- midrule->location = dummy_location;
- code_props_rule_action_init (&midrule->action_props,
- current_rule->action_props.code,
- current_rule->action_props.location,
- midrule, 0,
- current_rule->action_props.is_predicate);
- code_props_none_init (&current_rule->action_props);
-
- if (previous_rule_end)
- previous_rule_end->next = midrule;
- else
- grammar = midrule;
-
- /* End the dummy's rule. */
- midrule->next = symbol_list_sym_new (NULL, dummy_location);
- midrule->next->next = current_rule;
-
- previous_rule_end = midrule->next;
-
- /* Insert the dummy nonterminal replacing the midrule action into
- the current rule. Bind it to its dedicated rule. */
- grammar_current_rule_symbol_append (dummy, dummy_location,
- action_name);
- grammar_end->midrule = midrule;
- midrule->midrule_parent_rule = current_rule;
- midrule->midrule_parent_rhs_index = symbol_list_length (current_rule->next);
-}
-
-/* Set the precedence symbol of the current rule to PRECSYM. */
-
-void
-grammar_current_rule_prec_set (symbol *precsym, location loc)
-{
- /* POSIX says that any identifier is a nonterminal if it does not
- appear on the LHS of a grammar rule and is not defined by %token
- or by one of the directives that assigns precedence to a token. We
- ignore this here because the only kind of identifier that POSIX
- allows to follow a %prec is a token and because assuming it's a
- token now can produce more logical error messages. Nevertheless,
- grammar_rule_check does obey what we believe is the real intent of
- POSIX here: that an error be reported for any identifier that
- appears after %prec but that is not defined separately as a
- token. */
- symbol_class_set (precsym, token_sym, loc, false);
- if (current_rule->ruleprec)
- duplicate_directive ("%prec",
- current_rule->ruleprec->location, loc);
- else
- current_rule->ruleprec = precsym;
-}
-
-/* Set %empty for the current rule. */
-
-void
-grammar_current_rule_empty_set (location loc)
-{
- /* If %empty is used and -Wno-empty-rule is not, then enable
- -Wempty-rule. */
- if (warning_is_unset (Wempty_rule))
- warning_argmatch ("empty-rule", 0, 0);
- if (current_rule->percent_empty_loc.start.file)
- duplicate_directive ("%empty",
- current_rule->percent_empty_loc, loc);
- else
- current_rule->percent_empty_loc = loc;
-}
-
-/* Attach dynamic precedence DPREC to the current rule. */
-
-void
-grammar_current_rule_dprec_set (int dprec, location loc)
-{
- if (! glr_parser)
- complain (&loc, Wother, _("%s affects only GLR parsers"),
- "%dprec");
- if (dprec <= 0)
- complain (&loc, complaint, _("%s must be followed by positive number"),
- "%dprec");
- else if (current_rule->dprec != 0)
- duplicate_directive ("%dprec",
- current_rule->dprec_location, loc);
- else
- {
- current_rule->dprec = dprec;
- current_rule->dprec_location = loc;
- }
-}
-
-/* Attach a merge function NAME with argument type TYPE to current
- rule. */
-
-void
-grammar_current_rule_merge_set (uniqstr name, location loc)
-{
- if (! glr_parser)
- complain (&loc, Wother, _("%s affects only GLR parsers"),
- "%merge");
- if (current_rule->merger != 0)
- duplicate_directive ("%merge",
- current_rule->merger_declaration_location, loc);
- else
- {
- current_rule->merger = get_merge_function (name);
- current_rule->merger_declaration_location = loc;
- }
-}
-
-/* Attach SYM to the current rule. If needed, move the previous
- action as a mid-rule action. */
-
-void
-grammar_current_rule_symbol_append (symbol *sym, location loc,
- named_ref *name)
-{
- symbol_list *p;
- if (current_rule->action_props.code)
- grammar_midrule_action ();
- p = grammar_symbol_append (sym, loc);
- if (name)
- assign_named_ref (p, name);
- if (sym->status == undeclared || sym->status == used)
- sym->status = needed;
-}
-
-/* Attach an ACTION to the current rule. */
-
-void
-grammar_current_rule_action_append (const char *action, location loc,
- named_ref *name, bool is_predicate)
-{
- if (current_rule->action_props.code)
- grammar_midrule_action ();
- /* After all symbol declarations have been parsed, packgram invokes
- code_props_translate_code. */
- code_props_rule_action_init (&current_rule->action_props, action, loc,
- current_rule, name, is_predicate);
-}
-
-
-/*---------------------------------------------------------------.
-| Convert the rules into the representation using RRHS, RLHS and |
-| RITEM. |
-`---------------------------------------------------------------*/
-
-static void
-packgram (void)
-{
- unsigned int itemno = 0;
- rule_number ruleno = 0;
- symbol_list *p;
-
- ritem = xnmalloc (nritems + 1, sizeof *ritem);
-
- /* This sentinel is used by build_relations in gram.c. */
- *ritem++ = 0;
-
- rules = xnmalloc (nrules, sizeof *rules);
-
- for (p = grammar; p; p = p->next)
- {
- symbol *ruleprec = p->ruleprec;
- record_merge_function_type (p->merger, p->content.sym->type_name,
- p->merger_declaration_location);
- rules[ruleno].user_number = ruleno;
- rules[ruleno].number = ruleno;
- rules[ruleno].lhs = p->content.sym;
- rules[ruleno].rhs = ritem + itemno;
- rules[ruleno].prec = NULL;
- rules[ruleno].dprec = p->dprec;
- rules[ruleno].merger = p->merger;
- rules[ruleno].precsym = NULL;
- rules[ruleno].location = p->location;
- rules[ruleno].useful = true;
- rules[ruleno].action = p->action_props.code;
- rules[ruleno].action_location = p->action_props.location;
- rules[ruleno].is_predicate = p->action_props.is_predicate;
-
- /* If the midrule's $$ is set or its $n is used, remove the '$' from the
- symbol name so that it's a user-defined symbol so that the default
- %destructor and %printer apply. */
- if (p->midrule_parent_rule
- && (p->action_props.is_value_used
- || (symbol_list_n_get (p->midrule_parent_rule,
- p->midrule_parent_rhs_index)
- ->action_props.is_value_used)))
- p->content.sym->tag += 1;
-
- /* Don't check the generated rule 0. It has no action, so some rhs
- symbols may appear unused, but the parsing algorithm ensures that
- %destructor's are invoked appropriately. */
- if (p != grammar)
- grammar_rule_check (p);
-
- {
- size_t rule_length = 0;
- for (p = p->next; p->content.sym; p = p->next)
- {
- ++rule_length;
-
- /* Don't allow rule_length == INT_MAX, since that might
- cause confusion with strtol if INT_MAX == LONG_MAX. */
- if (rule_length == INT_MAX)
- complain (&rules[ruleno].location, fatal, _("rule is too long"));
-
- /* item_number = symbol_number.
- But the former needs to contain more: negative rule numbers. */
- ritem[itemno++] =
- symbol_number_as_item_number (p->content.sym->number);
- /* A rule gets by default the precedence and associativity
- of its last token. */
- if (p->content.sym->class == token_sym && default_prec)
- rules[ruleno].prec = p->content.sym;
- }
- }
-
- /* If this rule has a %prec,
- the specified symbol's precedence replaces the default. */
- if (ruleprec)
- {
- rules[ruleno].precsym = ruleprec;
- rules[ruleno].prec = ruleprec;
- }
- /* An item ends by the rule number (negated). */
- ritem[itemno++] = rule_number_as_item_number (ruleno);
- aver (itemno < ITEM_NUMBER_MAX);
- ++ruleno;
- aver (ruleno < RULE_NUMBER_MAX);
- }
-
- aver (itemno == nritems);
-
- if (trace_flag & trace_sets)
- ritem_print (stderr);
-}
-
-/*------------------------------------------------------------------.
-| Read in the grammar specification and record it in the format |
-| described in gram.h. All actions are copied into ACTION_OBSTACK, |
-| in each case forming the body of a C function (YYACTION) which |
-| contains a switch statement to decide which action to execute. |
-`------------------------------------------------------------------*/
-
-void
-reader (void)
-{
- /* Initialize the symbol table. */
- symbols_new ();
-
- /* Construct the accept symbol. */
- accept = symbol_get ("$accept", empty_location);
- accept->class = nterm_sym;
- accept->number = nvars++;
-
- /* Construct the error token */
- errtoken = symbol_get ("error", empty_location);
- errtoken->class = token_sym;
- errtoken->number = ntokens++;
-
- /* Construct a token that represents all undefined literal tokens.
- It is always token number 2. */
- undeftoken = symbol_get ("$undefined", empty_location);
- undeftoken->class = token_sym;
- undeftoken->number = ntokens++;
-
- gram_in = xfopen (grammar_file, "r");
-
- gram__flex_debug = trace_flag & trace_scan;
- gram_debug = trace_flag & trace_parse;
- gram_scanner_initialize ();
- gram_parse ();
- prepare_percent_define_front_end_variables ();
-
- if (complaint_status < status_complaint)
- check_and_convert_grammar ();
-
- xfclose (gram_in);
-}
-
-static void
-prepare_percent_define_front_end_variables (void)
-{
- /* Set %define front-end variable defaults. */
- muscle_percent_define_default ("lr.keep-unreachable-state", "false");
- {
- char *lr_type;
- /* IELR would be a better default, but LALR is historically the
- default. */
- muscle_percent_define_default ("lr.type", "lalr");
- lr_type = muscle_percent_define_get ("lr.type");
- if (STRNEQ (lr_type, "canonical-lr"))
- muscle_percent_define_default ("lr.default-reduction", "most");
- else
- muscle_percent_define_default ("lr.default-reduction", "accepting");
- free (lr_type);
- }
-
- /* Check %define front-end variables. */
- {
- static char const * const values[] = {
- "lr.type", "lalr", "ielr", "canonical-lr", NULL,
- "lr.default-reduction", "most", "consistent", "accepting", NULL,
- NULL
- };
- muscle_percent_define_check_values (values);
- }
-}
-
-
-/*-------------------------------------------------------------.
-| Check the grammar that has just been read, and convert it to |
-| internal form. |
-`-------------------------------------------------------------*/
-
-static void
-check_and_convert_grammar (void)
-{
- /* Grammar has been read. Do some checking. */
- if (nrules == 0)
- complain (NULL, fatal, _("no rules in the input grammar"));
-
- /* If the user did not define her ENDTOKEN, do it now. */
- if (!endtoken)
- {
- endtoken = symbol_get ("$end", empty_location);
- endtoken->class = token_sym;
- endtoken->number = 0;
- /* Value specified by POSIX. */
- endtoken->user_token_number = 0;
- }
-
- /* Report any undefined symbols and consider them nonterminals. */
- symbols_check_defined ();
-
- /* Find the start symbol if no %start. */
- if (!start_flag)
- {
- symbol_list *node;
- for (node = grammar;
- node != NULL && symbol_is_dummy (node->content.sym);
- node = node->next)
- {
- for (node = node->next;
- node != NULL && node->content.sym != NULL;
- node = node->next)
- ;
- }
- aver (node != NULL);
- grammar_start_symbol_set (node->content.sym,
- node->content.sym->location);
- }
-
- /* Insert the initial rule, whose line is that of the first rule
- (not that of the start symbol):
-
- $accept: %start $end. */
- {
- symbol_list *p = symbol_list_sym_new (accept, empty_location);
- p->location = grammar->location;
- p->next = symbol_list_sym_new (startsymbol, empty_location);
- p->next->next = symbol_list_sym_new (endtoken, empty_location);
- p->next->next->next = symbol_list_sym_new (NULL, empty_location);
- p->next->next->next->next = grammar;
- nrules += 1;
- nritems += 3;
- grammar = p;
- }
-
- aver (nsyms <= SYMBOL_NUMBER_MAXIMUM);
- aver (nsyms == ntokens + nvars);
-
- /* Assign the symbols their symbol numbers. Write #defines for the
- token symbols into FDEFINES if requested. */
- symbols_pack ();
-
- /* Scan rule actions after invoking symbol_check_alias_consistency (in
- symbols_pack above) so that token types are set correctly before the rule
- action type checking.
-
- Before invoking grammar_rule_check (in packgram below) on any rule, make
- sure all actions have already been scanned in order to set 'used' flags.
- Otherwise, checking that a midrule's $$ should be set will not always work
- properly because the check must forward-reference the midrule's parent
- rule. For the same reason, all the 'used' flags must be set before
- checking whether to remove '$' from any midrule symbol name (also in
- packgram). */
- {
- symbol_list *sym;
- for (sym = grammar; sym; sym = sym->next)
- code_props_translate_code (&sym->action_props);
- }
-
- /* Convert the grammar into the format described in gram.h. */
- packgram ();
-
- /* The grammar as a symbol_list is no longer needed. */
- symbol_list_free (grammar);
-}
+/* Input parser for Bison
+
+ Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000-2003, 2005-2007,
+ 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <quote.h>
+
+#include "complain.h"
+#include "conflicts.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "muscle-tab.h"
+#include "reader.h"
+#include "symlist.h"
+#include "symtab.h"
+#include "scan-gram.h"
+#include "scan-code.h"
+
+static void prepare_percent_define_front_end_variables (void);
+static void check_and_convert_grammar (void);
+
+static symbol_list *grammar = NULL;
+static bool start_flag = false;
+merger_list *merge_functions;
+
+/* Was %union seen? */
+bool union_seen = false;
+
+/* Was a tag seen? */
+bool tag_seen = false;
+
+/* Should rules have a default precedence? */
+bool default_prec = true;
+
+/*-----------------------.
+| Set the start symbol. |
+`-----------------------*/
+
+void
+grammar_start_symbol_set (symbol *sym, location loc)
+{
+ if (start_flag)
+ complain (&loc, complaint, _("multiple %s declarations"), "%start");
+ else
+ {
+ start_flag = true;
+ startsymbol = sym;
+ startsymbol_location = loc;
+ }
+}
+
+
+
+/*------------------------------------------------------------------------.
+| Return the merger index for a merging function named NAME. Records the |
+| function, if new, in MERGER_LIST. |
+`------------------------------------------------------------------------*/
+
+static int
+get_merge_function (uniqstr name)
+{
+ merger_list *syms;
+ merger_list head;
+ int n;
+
+ if (! glr_parser)
+ return 0;
+
+ head.next = merge_functions;
+ for (syms = &head, n = 1; syms->next; syms = syms->next, n += 1)
+ if (UNIQSTR_EQ (name, syms->next->name))
+ break;
+ if (syms->next == NULL)
+ {
+ syms->next = xmalloc (sizeof syms->next[0]);
+ syms->next->name = uniqstr_new (name);
+ /* After all symbol type declarations have been parsed, packgram invokes
+ record_merge_function_type to set the type. */
+ syms->next->type = NULL;
+ syms->next->next = NULL;
+ merge_functions = head.next;
+ }
+ return n;
+}
+
+/*-------------------------------------------------------------------------.
+| For the existing merging function with index MERGER, record the result |
+| type as TYPE as required by the lhs of the rule whose %merge declaration |
+| is at DECLARATION_LOC. |
+`-------------------------------------------------------------------------*/
+
+static void
+record_merge_function_type (int merger, uniqstr type, location declaration_loc)
+{
+ int merger_find;
+ merger_list *merge_function;
+
+ if (merger <= 0)
+ return;
+
+ if (type == NULL)
+ type = uniqstr_new ("");
+
+ merger_find = 1;
+ for (merge_function = merge_functions;
+ merge_function != NULL && merger_find != merger;
+ merge_function = merge_function->next)
+ merger_find += 1;
+ aver (merge_function != NULL && merger_find == merger);
+ if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type))
+ {
+ unsigned indent = 0;
+ complain_indent (&declaration_loc, complaint, &indent,
+ _("result type clash on merge function %s: "
+ "<%s> != <%s>"),
+ quote (merge_function->name), type,
+ merge_function->type);
+ indent += SUB_INDENT;
+ complain_indent (&merge_function->type_declaration_location, complaint,
+ &indent,
+ _("previous declaration"));
+ }
+ merge_function->type = uniqstr_new (type);
+ merge_function->type_declaration_location = declaration_loc;
+}
+
+/*--------------------------------------.
+| Free all merge-function definitions. |
+`--------------------------------------*/
+
+void
+free_merger_functions (void)
+{
+ merger_list *L0 = merge_functions;
+ while (L0)
+ {
+ merger_list *L1 = L0->next;
+ free (L0);
+ L0 = L1;
+ }
+}
+
+
+/*-------------------------------------------------------------------.
+| Parse the input grammar into a one symbol_list structure. Each |
+| rule is represented by a sequence of symbols: the left hand side |
+| followed by the contents of the right hand side, followed by a |
+| null pointer instead of a symbol to terminate the rule. The next |
+| symbol is the lhs of the following rule. |
+| |
+| All actions are copied out, labelled by the rule number they apply |
+| to. |
+`-------------------------------------------------------------------*/
+
+/* The (currently) last symbol of GRAMMAR. */
+static symbol_list *grammar_end = NULL;
+
+/* Append SYM to the grammar. */
+static symbol_list *
+grammar_symbol_append (symbol *sym, location loc)
+{
+ symbol_list *p = symbol_list_sym_new (sym, loc);
+
+ if (grammar_end)
+ grammar_end->next = p;
+ else
+ grammar = p;
+
+ grammar_end = p;
+
+ /* A null SYM stands for an end of rule; it is not an actual
+ part of it. */
+ if (sym)
+ ++nritems;
+
+ return p;
+}
+
+static void
+assign_named_ref (symbol_list *p, named_ref *name)
+{
+ symbol *sym = p->content.sym;
+
+ if (name->id == sym->tag)
+ {
+ complain (&name->loc, Wother,
+ _("duplicated symbol name for %s ignored"),
+ quote (sym->tag));
+ named_ref_free (name);
+ }
+ else
+ p->named_ref = name;
+}
+
+
+/* The rule currently being defined, and the previous rule.
+ CURRENT_RULE points to the first LHS of the current rule, while
+ PREVIOUS_RULE_END points to the *end* of the previous rule (NULL). */
+static symbol_list *current_rule = NULL;
+static symbol_list *previous_rule_end = NULL;
+
+
+/*----------------------------------------------.
+| Create a new rule for LHS in to the GRAMMAR. |
+`----------------------------------------------*/
+
+void
+grammar_current_rule_begin (symbol *lhs, location loc,
+ named_ref *lhs_name)
+{
+ symbol_list* p;
+
+ /* Start a new rule and record its lhs. */
+ ++nrules;
+ previous_rule_end = grammar_end;
+
+ p = grammar_symbol_append (lhs, loc);
+ if (lhs_name)
+ assign_named_ref (p, named_ref_copy (lhs_name));
+
+ current_rule = grammar_end;
+
+ /* Mark the rule's lhs as a nonterminal if not already so. */
+ if (lhs->class == unknown_sym)
+ {
+ lhs->class = nterm_sym;
+ lhs->number = nvars;
+ ++nvars;
+ }
+ else if (lhs->class == token_sym)
+ complain (&loc, complaint, _("rule given for %s, which is a token"),
+ lhs->tag);
+}
+
+
+/*----------------------------------------------------------------------.
+| A symbol should be used if either: |
+| 1. It has a destructor. |
+| 2. The symbol is a mid-rule symbol (i.e., the generated LHS |
+| replacing a mid-rule action) that was assigned to or used, as in |
+| "exp: { $$ = 1; } { $$ = $1; }". |
+`----------------------------------------------------------------------*/
+
+static bool
+symbol_should_be_used (symbol_list const *s, bool *midrule_warning)
+{
+ if (symbol_code_props_get (s->content.sym, destructor)->code)
+ return true;
+ if ((s->midrule && s->midrule->action_props.is_value_used)
+ || (s->midrule_parent_rule
+ && (symbol_list_n_get (s->midrule_parent_rule,
+ s->midrule_parent_rhs_index)
+ ->action_props.is_value_used)))
+ {
+ *midrule_warning = true;
+ return true;
+ }
+ return false;
+}
+
+/*----------------------------------------------------------------.
+| Check that the rule R is properly defined. For instance, there |
+| should be no type clash on the default action. |
+`----------------------------------------------------------------*/
+
+static void
+grammar_rule_check (const symbol_list *r)
+{
+ /* Type check.
+
+ If there is an action, then there is nothing we can do: the user
+ is allowed to shoot herself in the foot.
+
+ Don't worry about the default action if $$ is untyped, since $$'s
+ value can't be used. */
+ if (!r->action_props.code && r->content.sym->type_name)
+ {
+ symbol *first_rhs = r->next->content.sym;
+ /* If $$ is being set in default way, report if any type mismatch. */
+ if (first_rhs)
+ {
+ char const *lhs_type = r->content.sym->type_name;
+ const char *rhs_type =
+ first_rhs->type_name ? first_rhs->type_name : "";
+ if (!UNIQSTR_EQ (lhs_type, rhs_type))
+ complain (&r->location, Wother,
+ _("type clash on default action: <%s> != <%s>"),
+ lhs_type, rhs_type);
+ }
+ /* Warn if there is no default for $$ but we need one. */
+ else
+ complain (&r->location, Wother,
+ _("empty rule for typed nonterminal, and no action"));
+ }
+
+ /* Check that symbol values that should be used are in fact used. */
+ {
+ symbol_list const *l = r;
+ int n = 0;
+ for (; l && l->content.sym; l = l->next, ++n)
+ {
+ bool midrule_warning = false;
+ if (!l->action_props.is_value_used
+ && symbol_should_be_used (l, &midrule_warning)
+ /* The default action, $$ = $1, 'uses' both. */
+ && (r->action_props.code || (n != 0 && n != 1)))
+ {
+ warnings warn_flag = midrule_warning ? Wmidrule_values : Wother;
+ if (n)
+ complain (&l->location, warn_flag, _("unused value: $%d"), n);
+ else
+ complain (&l->location, warn_flag, _("unset value: $$"));
+ }
+ }
+ }
+
+ /* Check that %empty => empty rule. */
+ if (r->percent_empty_loc.start.file
+ && r->next && r->next->content.sym)
+ complain (&r->percent_empty_loc, complaint,
+ _("%%empty on non-empty rule"));
+
+ /* Check that empty rule => %empty. */
+ if (!(r->next && r->next->content.sym)
+ && !r->midrule_parent_rule
+ && !r->percent_empty_loc.start.file)
+ complain (&r->location, Wempty_rule, _("empty rule without %%empty"));
+
+ /* See comments in grammar_current_rule_prec_set for how POSIX
+ mandates this complaint. It's only for identifiers, so skip
+ it for char literals and strings, which are always tokens. */
+ if (r->ruleprec
+ && r->ruleprec->tag[0] != '\'' && r->ruleprec->tag[0] != '"'
+ && r->ruleprec->status != declared && !r->ruleprec->prec)
+ complain (&r->location, Wother,
+ _("token for %%prec is not defined: %s"), r->ruleprec->tag);
+}
+
+
+/*-------------------------------------.
+| End the currently being grown rule. |
+`-------------------------------------*/
+
+void
+grammar_current_rule_end (location loc)
+{
+ /* Put an empty link in the list to mark the end of this rule */
+ grammar_symbol_append (NULL, grammar_end->location);
+ current_rule->location = loc;
+}
+
+
+/*-------------------------------------------------------------------.
+| The previous action turns out the be a mid-rule action. Attach it |
+| to the current rule, i.e., create a dummy symbol, attach it this |
+| mid-rule action, and append this dummy nonterminal to the current |
+| rule. |
+`-------------------------------------------------------------------*/
+
+void
+grammar_midrule_action (void)
+{
+ /* Since the action was written out with this rule's number, we must
+ give the new rule this number by inserting the new rule before
+ it. */
+
+ /* Make a DUMMY nonterminal, whose location is that of the midrule
+ action. Create the MIDRULE. */
+ location dummy_location = current_rule->action_props.location;
+ symbol *dummy = dummy_symbol_get (dummy_location);
+ symbol_list *midrule = symbol_list_sym_new (dummy, dummy_location);
+
+ /* Remember named_ref of previous action. */
+ named_ref *action_name = current_rule->action_props.named_ref;
+
+ /* Make a new rule, whose body is empty, before the current one, so
+ that the action just read can belong to it. */
+ ++nrules;
+ ++nritems;
+ /* Attach its location and actions to that of the DUMMY. */
+ midrule->location = dummy_location;
+ code_props_rule_action_init (&midrule->action_props,
+ current_rule->action_props.code,
+ current_rule->action_props.location,
+ midrule, 0,
+ current_rule->action_props.is_predicate);
+ code_props_none_init (&current_rule->action_props);
+
+ if (previous_rule_end)
+ previous_rule_end->next = midrule;
+ else
+ grammar = midrule;
+
+ /* End the dummy's rule. */
+ midrule->next = symbol_list_sym_new (NULL, dummy_location);
+ midrule->next->next = current_rule;
+
+ previous_rule_end = midrule->next;
+
+ /* Insert the dummy nonterminal replacing the midrule action into
+ the current rule. Bind it to its dedicated rule. */
+ grammar_current_rule_symbol_append (dummy, dummy_location,
+ action_name);
+ grammar_end->midrule = midrule;
+ midrule->midrule_parent_rule = current_rule;
+ midrule->midrule_parent_rhs_index = symbol_list_length (current_rule->next);
+}
+
+/* Set the precedence symbol of the current rule to PRECSYM. */
+
+void
+grammar_current_rule_prec_set (symbol *precsym, location loc)
+{
+ /* POSIX says that any identifier is a nonterminal if it does not
+ appear on the LHS of a grammar rule and is not defined by %token
+ or by one of the directives that assigns precedence to a token. We
+ ignore this here because the only kind of identifier that POSIX
+ allows to follow a %prec is a token and because assuming it's a
+ token now can produce more logical error messages. Nevertheless,
+ grammar_rule_check does obey what we believe is the real intent of
+ POSIX here: that an error be reported for any identifier that
+ appears after %prec but that is not defined separately as a
+ token. */
+ symbol_class_set (precsym, token_sym, loc, false);
+ if (current_rule->ruleprec)
+ duplicate_directive ("%prec",
+ current_rule->ruleprec->location, loc);
+ else
+ current_rule->ruleprec = precsym;
+}
+
+/* Set %empty for the current rule. */
+
+void
+grammar_current_rule_empty_set (location loc)
+{
+ /* If %empty is used and -Wno-empty-rule is not, then enable
+ -Wempty-rule. */
+ if (warning_is_unset (Wempty_rule))
+ warning_argmatch ("empty-rule", 0, 0);
+ if (current_rule->percent_empty_loc.start.file)
+ duplicate_directive ("%empty",
+ current_rule->percent_empty_loc, loc);
+ else
+ current_rule->percent_empty_loc = loc;
+}
+
+/* Attach dynamic precedence DPREC to the current rule. */
+
+void
+grammar_current_rule_dprec_set (int dprec, location loc)
+{
+ if (! glr_parser)
+ complain (&loc, Wother, _("%s affects only GLR parsers"),
+ "%dprec");
+ if (dprec <= 0)
+ complain (&loc, complaint, _("%s must be followed by positive number"),
+ "%dprec");
+ else if (current_rule->dprec != 0)
+ duplicate_directive ("%dprec",
+ current_rule->dprec_location, loc);
+ else
+ {
+ current_rule->dprec = dprec;
+ current_rule->dprec_location = loc;
+ }
+}
+
+/* Attach a merge function NAME with argument type TYPE to current
+ rule. */
+
+void
+grammar_current_rule_merge_set (uniqstr name, location loc)
+{
+ if (! glr_parser)
+ complain (&loc, Wother, _("%s affects only GLR parsers"),
+ "%merge");
+ if (current_rule->merger != 0)
+ duplicate_directive ("%merge",
+ current_rule->merger_declaration_location, loc);
+ else
+ {
+ current_rule->merger = get_merge_function (name);
+ current_rule->merger_declaration_location = loc;
+ }
+}
+
+/* Attach SYM to the current rule. If needed, move the previous
+ action as a mid-rule action. */
+
+void
+grammar_current_rule_symbol_append (symbol *sym, location loc,
+ named_ref *name)
+{
+ symbol_list *p;
+ if (current_rule->action_props.code)
+ grammar_midrule_action ();
+ p = grammar_symbol_append (sym, loc);
+ if (name)
+ assign_named_ref (p, name);
+ if (sym->status == undeclared || sym->status == used)
+ sym->status = needed;
+}
+
+/* Attach an ACTION to the current rule. */
+
+void
+grammar_current_rule_action_append (const char *action, location loc,
+ named_ref *name, bool is_predicate)
+{
+ if (current_rule->action_props.code)
+ grammar_midrule_action ();
+ /* After all symbol declarations have been parsed, packgram invokes
+ code_props_translate_code. */
+ code_props_rule_action_init (&current_rule->action_props, action, loc,
+ current_rule, name, is_predicate);
+}
+
+
+/*---------------------------------------------------------------.
+| Convert the rules into the representation using RRHS, RLHS and |
+| RITEM. |
+`---------------------------------------------------------------*/
+
+static void
+packgram (void)
+{
+ unsigned int itemno = 0;
+ rule_number ruleno = 0;
+ symbol_list *p;
+
+ ritem = xnmalloc (nritems + 1, sizeof *ritem);
+
+ /* This sentinel is used by build_relations in gram.c. */
+ *ritem++ = 0;
+
+ rules = xnmalloc (nrules, sizeof *rules);
+
+ for (p = grammar; p; p = p->next)
+ {
+ symbol *ruleprec = p->ruleprec;
+ record_merge_function_type (p->merger, p->content.sym->type_name,
+ p->merger_declaration_location);
+ rules[ruleno].user_number = ruleno;
+ rules[ruleno].number = ruleno;
+ rules[ruleno].lhs = p->content.sym;
+ rules[ruleno].rhs = ritem + itemno;
+ rules[ruleno].prec = NULL;
+ rules[ruleno].dprec = p->dprec;
+ rules[ruleno].merger = p->merger;
+ rules[ruleno].precsym = NULL;
+ rules[ruleno].location = p->location;
+ rules[ruleno].useful = true;
+ rules[ruleno].action = p->action_props.code;
+ rules[ruleno].action_location = p->action_props.location;
+ rules[ruleno].is_predicate = p->action_props.is_predicate;
+
+ /* If the midrule's $$ is set or its $n is used, remove the '$' from the
+ symbol name so that it's a user-defined symbol so that the default
+ %destructor and %printer apply. */
+ if (p->midrule_parent_rule
+ && (p->action_props.is_value_used
+ || (symbol_list_n_get (p->midrule_parent_rule,
+ p->midrule_parent_rhs_index)
+ ->action_props.is_value_used)))
+ p->content.sym->tag += 1;
+
+ /* Don't check the generated rule 0. It has no action, so some rhs
+ symbols may appear unused, but the parsing algorithm ensures that
+ %destructor's are invoked appropriately. */
+ if (p != grammar)
+ grammar_rule_check (p);
+
+ {
+ size_t rule_length = 0;
+ for (p = p->next; p->content.sym; p = p->next)
+ {
+ ++rule_length;
+
+ /* Don't allow rule_length == INT_MAX, since that might
+ cause confusion with strtol if INT_MAX == LONG_MAX. */
+ if (rule_length == INT_MAX)
+ complain (&rules[ruleno].location, fatal, _("rule is too long"));
+
+ /* item_number = symbol_number.
+ But the former needs to contain more: negative rule numbers. */
+ ritem[itemno++] =
+ symbol_number_as_item_number (p->content.sym->number);
+ /* A rule gets by default the precedence and associativity
+ of its last token. */
+ if (p->content.sym->class == token_sym && default_prec)
+ rules[ruleno].prec = p->content.sym;
+ }
+ }
+
+ /* If this rule has a %prec,
+ the specified symbol's precedence replaces the default. */
+ if (ruleprec)
+ {
+ rules[ruleno].precsym = ruleprec;
+ rules[ruleno].prec = ruleprec;
+ }
+ /* An item ends by the rule number (negated). */
+ ritem[itemno++] = rule_number_as_item_number (ruleno);
+ aver (itemno < ITEM_NUMBER_MAX);
+ ++ruleno;
+ aver (ruleno < RULE_NUMBER_MAX);
+ }
+
+ aver (itemno == nritems);
+
+ if (trace_flag & trace_sets)
+ ritem_print (stderr);
+}
+
+/*------------------------------------------------------------------.
+| Read in the grammar specification and record it in the format |
+| described in gram.h. All actions are copied into ACTION_OBSTACK, |
+| in each case forming the body of a C function (YYACTION) which |
+| contains a switch statement to decide which action to execute. |
+`------------------------------------------------------------------*/
+
+void
+reader (void)
+{
+ /* Initialize the symbol table. */
+ symbols_new ();
+
+ /* Construct the accept symbol. */
+ accept = symbol_get ("$accept", empty_location);
+ accept->class = nterm_sym;
+ accept->number = nvars++;
+
+ /* Construct the error token */
+ errtoken = symbol_get ("error", empty_location);
+ errtoken->class = token_sym;
+ errtoken->number = ntokens++;
+
+ /* Construct a token that represents all undefined literal tokens.
+ It is always token number 2. */
+ undeftoken = symbol_get ("$undefined", empty_location);
+ undeftoken->class = token_sym;
+ undeftoken->number = ntokens++;
+
+ gram_in = xfopen (grammar_file, "r");
+
+ gram__flex_debug = trace_flag & trace_scan;
+ gram_debug = trace_flag & trace_parse;
+ gram_scanner_initialize ();
+ gram_parse ();
+ prepare_percent_define_front_end_variables ();
+
+ if (complaint_status < status_complaint)
+ check_and_convert_grammar ();
+
+ xfclose (gram_in);
+}
+
+static void
+prepare_percent_define_front_end_variables (void)
+{
+ /* Set %define front-end variable defaults. */
+ muscle_percent_define_default ("lr.keep-unreachable-state", "false");
+ {
+ char *lr_type;
+ /* IELR would be a better default, but LALR is historically the
+ default. */
+ muscle_percent_define_default ("lr.type", "lalr");
+ lr_type = muscle_percent_define_get ("lr.type");
+ if (STRNEQ (lr_type, "canonical-lr"))
+ muscle_percent_define_default ("lr.default-reduction", "most");
+ else
+ muscle_percent_define_default ("lr.default-reduction", "accepting");
+ free (lr_type);
+ }
+
+ /* Check %define front-end variables. */
+ {
+ static char const * const values[] = {
+ "lr.type", "lalr", "ielr", "canonical-lr", NULL,
+ "lr.default-reduction", "most", "consistent", "accepting", NULL,
+ NULL
+ };
+ muscle_percent_define_check_values (values);
+ }
+}
+
+
+/*-------------------------------------------------------------.
+| Check the grammar that has just been read, and convert it to |
+| internal form. |
+`-------------------------------------------------------------*/
+
+static void
+check_and_convert_grammar (void)
+{
+ /* Grammar has been read. Do some checking. */
+ if (nrules == 0)
+ complain (NULL, fatal, _("no rules in the input grammar"));
+
+ /* If the user did not define her ENDTOKEN, do it now. */
+ if (!endtoken)
+ {
+ endtoken = symbol_get ("$end", empty_location);
+ endtoken->class = token_sym;
+ endtoken->number = 0;
+ /* Value specified by POSIX. */
+ endtoken->user_token_number = 0;
+ }
+
+ /* Report any undefined symbols and consider them nonterminals. */
+ symbols_check_defined ();
+
+ /* Find the start symbol if no %start. */
+ if (!start_flag)
+ {
+ symbol_list *node;
+ for (node = grammar;
+ node != NULL && symbol_is_dummy (node->content.sym);
+ node = node->next)
+ {
+ for (node = node->next;
+ node != NULL && node->content.sym != NULL;
+ node = node->next)
+ ;
+ }
+ aver (node != NULL);
+ grammar_start_symbol_set (node->content.sym,
+ node->content.sym->location);
+ }
+
+ /* Insert the initial rule, whose line is that of the first rule
+ (not that of the start symbol):
+
+ $accept: %start $end. */
+ {
+ symbol_list *p = symbol_list_sym_new (accept, empty_location);
+ p->location = grammar->location;
+ p->next = symbol_list_sym_new (startsymbol, empty_location);
+ p->next->next = symbol_list_sym_new (endtoken, empty_location);
+ p->next->next->next = symbol_list_sym_new (NULL, empty_location);
+ p->next->next->next->next = grammar;
+ nrules += 1;
+ nritems += 3;
+ grammar = p;
+ }
+
+ aver (nsyms <= SYMBOL_NUMBER_MAXIMUM);
+ aver (nsyms == ntokens + nvars);
+
+ /* Assign the symbols their symbol numbers. Write #defines for the
+ token symbols into FDEFINES if requested. */
+ symbols_pack ();
+
+ /* Scan rule actions after invoking symbol_check_alias_consistency (in
+ symbols_pack above) so that token types are set correctly before the rule
+ action type checking.
+
+ Before invoking grammar_rule_check (in packgram below) on any rule, make
+ sure all actions have already been scanned in order to set 'used' flags.
+ Otherwise, checking that a midrule's $$ should be set will not always work
+ properly because the check must forward-reference the midrule's parent
+ rule. For the same reason, all the 'used' flags must be set before
+ checking whether to remove '$' from any midrule symbol name (also in
+ packgram). */
+ {
+ symbol_list *sym;
+ for (sym = grammar; sym; sym = sym->next)
+ code_props_translate_code (&sym->action_props);
+ }
+
+ /* Convert the grammar into the format described in gram.h. */
+ packgram ();
+
+ /* The grammar as a symbol_list is no longer needed. */
+ symbol_list_free (grammar);
+}
diff --git a/contrib/tools/bison/bison/src/reader.h b/contrib/tools/bison/bison/src/reader.h
index ba6ffe6edc..fd0708046e 100644
--- a/contrib/tools/bison/bison/src/reader.h
+++ b/contrib/tools/bison/bison/src/reader.h
@@ -1,73 +1,73 @@
-/* Input parser for Bison
-
- Copyright (C) 2000-2003, 2005-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef READER_H_
-# define READER_H_
-
-# include "location.h"
-# include "symlist.h"
-# include "named-ref.h"
-
-# include "parse-gram.h"
-
-typedef struct merger_list
-{
- struct merger_list* next;
- uniqstr name;
- uniqstr type;
- location type_declaration_location;
-} merger_list;
-
-/* From the parser. */
-extern int gram_debug;
-int gram_parse (void);
-char const *token_name (int type);
-
-
-/* From reader.c. */
-void grammar_start_symbol_set (symbol *sym, location loc);
-void grammar_current_rule_begin (symbol *lhs, location loc,
- named_ref *lhs_named_ref);
-void grammar_current_rule_end (location loc);
-void grammar_midrule_action (void);
-/* Apply %empty to the current rule. */
-void grammar_current_rule_empty_set (location loc);
-void grammar_current_rule_prec_set (symbol *precsym, location loc);
-void grammar_current_rule_dprec_set (int dprec, location loc);
-void grammar_current_rule_merge_set (uniqstr name, location loc);
-void grammar_current_rule_symbol_append (symbol *sym, location loc,
- named_ref *nref);
-void grammar_current_rule_action_append (const char *action, location loc,
- named_ref *nref, bool);
-void reader (void);
-void free_merger_functions (void);
-
-extern merger_list *merge_functions;
-
-/* Was %union seen? */
-extern bool union_seen;
-
-/* Was a tag seen? */
-extern bool tag_seen;
-
-/* Should rules have a default precedence? */
-extern bool default_prec;
-
-#endif /* !READER_H_ */
+/* Input parser for Bison
+
+ Copyright (C) 2000-2003, 2005-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef READER_H_
+# define READER_H_
+
+# include "location.h"
+# include "symlist.h"
+# include "named-ref.h"
+
+# include "parse-gram.h"
+
+typedef struct merger_list
+{
+ struct merger_list* next;
+ uniqstr name;
+ uniqstr type;
+ location type_declaration_location;
+} merger_list;
+
+/* From the parser. */
+extern int gram_debug;
+int gram_parse (void);
+char const *token_name (int type);
+
+
+/* From reader.c. */
+void grammar_start_symbol_set (symbol *sym, location loc);
+void grammar_current_rule_begin (symbol *lhs, location loc,
+ named_ref *lhs_named_ref);
+void grammar_current_rule_end (location loc);
+void grammar_midrule_action (void);
+/* Apply %empty to the current rule. */
+void grammar_current_rule_empty_set (location loc);
+void grammar_current_rule_prec_set (symbol *precsym, location loc);
+void grammar_current_rule_dprec_set (int dprec, location loc);
+void grammar_current_rule_merge_set (uniqstr name, location loc);
+void grammar_current_rule_symbol_append (symbol *sym, location loc,
+ named_ref *nref);
+void grammar_current_rule_action_append (const char *action, location loc,
+ named_ref *nref, bool);
+void reader (void);
+void free_merger_functions (void);
+
+extern merger_list *merge_functions;
+
+/* Was %union seen? */
+extern bool union_seen;
+
+/* Was a tag seen? */
+extern bool tag_seen;
+
+/* Should rules have a default precedence? */
+extern bool default_prec;
+
+#endif /* !READER_H_ */
diff --git a/contrib/tools/bison/bison/src/reduce.c b/contrib/tools/bison/bison/src/reduce.c
index eea11b1e20..7b518ae3a1 100644
--- a/contrib/tools/bison/bison/src/reduce.c
+++ b/contrib/tools/bison/bison/src/reduce.c
@@ -1,466 +1,466 @@
-/* Grammar reduction for Bison.
-
- Copyright (C) 1988-1989, 2000-2003, 2005-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/* Reduce the grammar: Find and eliminate unreachable terminals,
- nonterminals, and productions. David S. Bakin. */
-
-/* Don't eliminate unreachable terminals: They may be used by the
- user's parser. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitset.h>
-
-#include "complain.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "print-xml.h"
-#include "reader.h"
-#include "reduce.h"
-#include "symtab.h"
-
-/* Set of all nonterminals which are not useless. */
-static bitset N;
-
-/* Set of all rules which have no useless nonterminals in their RHS. */
-static bitset P;
-
-/* Set of all accessible symbols. */
-static bitset V;
-
-/* Set of symbols used to define rule precedence (so they are
- 'useless', but no warning should be issued). */
-static bitset V1;
-
-static rule_number nuseful_productions;
-rule_number nuseless_productions;
-static int nuseful_nonterminals;
-symbol_number nuseless_nonterminals;
-
-/*-------------------------------------------------------------------.
-| Another way to do this would be with a set for each production and |
-| then do subset tests against N0, but even for the C grammar the |
-| whole reducing process takes only 2 seconds on my 8Mhz AT. |
-`-------------------------------------------------------------------*/
-
-static bool
-useful_production (rule_number r, bitset N0)
-{
- item_number *rhsp;
-
- /* A production is useful if all of the nonterminals in its appear
- in the set of useful nonterminals. */
-
- for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
- if (ISVAR (*rhsp) && !bitset_test (N0, *rhsp - ntokens))
- return false;
- return true;
-}
-
-
-/*---------------------------------------------------------.
-| Remember that rules are 1-origin, symbols are 0-origin. |
-`---------------------------------------------------------*/
-
-static void
-useless_nonterminals (void)
-{
- bitset Np, Ns;
- rule_number r;
-
- /* N is set as built. Np is set being built this iteration. P is
- set of all productions which have a RHS all in N. */
-
- Np = bitset_create (nvars, BITSET_FIXED);
-
-
- /* The set being computed is a set of nonterminals which can derive
- the empty string or strings consisting of all terminals. At each
- iteration a nonterminal is added to the set if there is a
- production with that nonterminal as its LHS for which all the
- nonterminals in its RHS are already in the set. Iterate until
- the set being computed remains unchanged. Any nonterminals not
- in the set at that point are useless in that they will never be
- used in deriving a sentence of the language.
-
- This iteration doesn't use any special traversal over the
- productions. A set is kept of all productions for which all the
- nonterminals in the RHS are in useful. Only productions not in
- this set are scanned on each iteration. At the end, this set is
- saved to be used when finding useful productions: only
- productions in this set will appear in the final grammar. */
-
- while (1)
- {
- bitset_copy (Np, N);
- for (r = 0; r < nrules; r++)
- if (!bitset_test (P, r)
- && useful_production (r, N))
- {
- bitset_set (Np, rules[r].lhs->number - ntokens);
- bitset_set (P, r);
- }
- if (bitset_equal_p (N, Np))
- break;
- Ns = Np;
- Np = N;
- N = Ns;
- }
- bitset_free (N);
- N = Np;
-}
-
-
-static void
-inaccessable_symbols (void)
-{
- bitset Vp, Vs, Pp;
-
- /* Find out which productions are reachable and which symbols are
- used. Starting with an empty set of productions and a set of
- symbols which only has the start symbol in it, iterate over all
- productions until the set of productions remains unchanged for an
- iteration. For each production which has a LHS in the set of
- reachable symbols, add the production to the set of reachable
- productions, and add all of the nonterminals in the RHS of the
- production to the set of reachable symbols.
-
- Consider only the (partially) reduced grammar which has only
- nonterminals in N and productions in P.
-
- The result is the set P of productions in the reduced grammar,
- and the set V of symbols in the reduced grammar.
-
- Although this algorithm also computes the set of terminals which
- are reachable, no terminal will be deleted from the grammar. Some
- terminals might not be in the grammar but might be generated by
- semantic routines, and so the user might want them available with
- specified numbers. (Is this true?) However, the nonreachable
- terminals are printed (if running in verbose mode) so that the
- user can know. */
-
- Vp = bitset_create (nsyms, BITSET_FIXED);
- Pp = bitset_create (nrules, BITSET_FIXED);
-
- /* If the start symbol isn't useful, then nothing will be useful. */
- if (bitset_test (N, accept->number - ntokens))
- {
- bitset_set (V, accept->number);
-
- while (1)
- {
- rule_number r;
- bitset_copy (Vp, V);
- for (r = 0; r < nrules; r++)
- {
- if (!bitset_test (Pp, r)
- && bitset_test (P, r)
- && bitset_test (V, rules[r].lhs->number))
- {
- item_number *rhsp;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (ISTOKEN (*rhsp) || bitset_test (N, *rhsp - ntokens))
- bitset_set (Vp, *rhsp);
- bitset_set (Pp, r);
- }
- }
- if (bitset_equal_p (V, Vp))
- break;
- Vs = Vp;
- Vp = V;
- V = Vs;
- }
- }
-
- bitset_free (V);
- V = Vp;
-
- /* Tokens 0, 1, and 2 are internal to Bison. Consider them useful. */
- bitset_set (V, endtoken->number); /* end-of-input token */
- bitset_set (V, errtoken->number); /* error token */
- bitset_set (V, undeftoken->number); /* some undefined token */
-
- bitset_free (P);
- P = Pp;
-
- nuseful_productions = bitset_count (P);
- nuseless_productions = nrules - nuseful_productions;
-
- nuseful_nonterminals = 0;
- {
- symbol_number i;
- for (i = ntokens; i < nsyms; i++)
- if (bitset_test (V, i))
- nuseful_nonterminals++;
- }
- nuseless_nonterminals = nvars - nuseful_nonterminals;
-
- /* A token that was used in %prec should not be warned about. */
- {
- rule_number r;
- for (r = 0; r < nrules; ++r)
- if (rules[r].precsym != 0)
- bitset_set (V1, rules[r].precsym->number);
- }
-}
-
-
-/*-------------------------------------------------------------------.
-| Put the useless productions at the end of RULES, and adjust NRULES |
-| accordingly. |
-`-------------------------------------------------------------------*/
-
-static void
-reduce_grammar_tables (void)
-{
- /* Report and flag useless productions. */
- {
- rule_number r;
- for (r = 0; r < nrules; r++)
- rules[r].useful = bitset_test (P, r);
- grammar_rules_useless_report (_("rule useless in grammar"));
- }
-
- /* Map the nonterminals to their new index: useful first, useless
- afterwards. Kept for later report. */
- {
- int useful = 0;
- int useless = nrules - nuseless_productions;
- rule *rules_sorted = xnmalloc (nrules, sizeof *rules_sorted);
- rule_number r;
- for (r = 0; r < nrules; ++r)
- rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r];
- free (rules);
- rules = rules_sorted;
-
- /* Renumber the rules markers in RITEMS. */
- for (r = 0; r < nrules; ++r)
- {
- item_number *rhsp = rules[r].rhs;
- for (/* Nothing. */; *rhsp >= 0; ++rhsp)
- /* Nothing. */;
- *rhsp = rule_number_as_item_number (r);
- rules[r].number = r;
- }
- nrules -= nuseless_productions;
- }
-
- /* Adjust NRITEMS. */
- {
- rule_number r;
- int length;
- for (r = nrules; r < nrules + nuseless_productions; ++r)
- {
- length = rule_rhs_length (&rules[r]);
- nritems -= length + 1;
- }
- }
-}
-
-
-/*------------------------------.
-| Remove useless nonterminals. |
-`------------------------------*/
-
-static void
-nonterminals_reduce (void)
-{
- /* Map the nonterminals to their new index: useful first, useless
- afterwards. Kept for later report. */
-
- symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap);
- symbol_number n = ntokens;
- symbol_number i;
- for (i = ntokens; i < nsyms; i++)
- if (bitset_test (V, i))
- nontermmap[i - ntokens] = n++;
- for (i = ntokens; i < nsyms; i++)
- if (!bitset_test (V, i))
- {
- nontermmap[i - ntokens] = n++;
- if (symbols[i]->status != used)
- complain (&symbols[i]->location, Wother,
- _("nonterminal useless in grammar: %s"),
- symbols[i]->tag);
- }
-
-
- /* Shuffle elements of tables indexed by symbol number. */
- {
- symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted);
-
- for (i = ntokens; i < nsyms; i++)
- symbols[i]->number = nontermmap[i - ntokens];
- for (i = ntokens; i < nsyms; i++)
- symbols_sorted[nontermmap[i - ntokens] - ntokens] = symbols[i];
- for (i = ntokens; i < nsyms; i++)
- symbols[i] = symbols_sorted[i - ntokens];
- free (symbols_sorted);
- }
-
- {
- rule_number r;
- for (r = 0; r < nrules; ++r)
- {
- item_number *rhsp;
- for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
- if (ISVAR (*rhsp))
- *rhsp = symbol_number_as_item_number (nontermmap[*rhsp
- - ntokens]);
- }
- accept->number = nontermmap[accept->number - ntokens];
- }
-
- nsyms -= nuseless_nonterminals;
- nvars -= nuseless_nonterminals;
-
- free (nontermmap);
-}
-
-
-/*------------------------------------------------------------------.
-| Output the detailed results of the reductions. For FILE.output. |
-`------------------------------------------------------------------*/
-
-void
-reduce_output (FILE *out)
-{
- if (nuseless_nonterminals > 0)
- {
- int i;
- fprintf (out, "%s\n\n", _("Nonterminals useless in grammar"));
- for (i = 0; i < nuseless_nonterminals; ++i)
- fprintf (out, " %s\n", symbols[nsyms + i]->tag);
- fputs ("\n\n", out);
- }
-
- {
- bool b = false;
- int i;
- for (i = 0; i < ntokens; i++)
- if (reduce_token_unused_in_grammar (i))
- {
- if (!b)
- fprintf (out, "%s\n\n", _("Terminals unused in grammar"));
- b = true;
- fprintf (out, " %s\n", symbols[i]->tag);
- }
- if (b)
- fputs ("\n\n", out);
- }
-
- if (nuseless_productions > 0)
- grammar_rules_partial_print (out, _("Rules useless in grammar"),
- rule_useless_in_grammar_p);
-}
-
-
-/*-------------------------------.
-| Report the results to STDERR. |
-`-------------------------------*/
-
-static void
-reduce_print (void)
-{
- if (nuseless_nonterminals > 0)
- complain (NULL, Wother, ngettext ("%d nonterminal useless in grammar",
- "%d nonterminals useless in grammar",
- nuseless_nonterminals),
- nuseless_nonterminals);
- if (nuseless_productions > 0)
- complain (NULL, Wother, ngettext ("%d rule useless in grammar",
- "%d rules useless in grammar",
- nuseless_productions),
- nuseless_productions);
-}
-
-void
-reduce_grammar (void)
-{
- bool reduced;
-
- /* Allocate the global sets used to compute the reduced grammar */
-
- N = bitset_create (nvars, BITSET_FIXED);
- P = bitset_create (nrules, BITSET_FIXED);
- V = bitset_create (nsyms, BITSET_FIXED);
- V1 = bitset_create (nsyms, BITSET_FIXED);
-
- useless_nonterminals ();
- inaccessable_symbols ();
-
- reduced = (nuseless_nonterminals + nuseless_productions > 0);
- if (!reduced)
- return;
-
- reduce_print ();
-
- if (!bitset_test (N, accept->number - ntokens))
- complain (&startsymbol_location, fatal,
- _("start symbol %s does not derive any sentence"),
- startsymbol->tag);
-
- /* First reduce the nonterminals, as they renumber themselves in the
- whole grammar. If you change the order, nonterms would be
- renumbered only in the reduced grammar. */
- if (nuseless_nonterminals > 0)
- nonterminals_reduce ();
- if (nuseless_productions > 0)
- reduce_grammar_tables ();
-
- if (trace_flag & trace_grammar)
- {
- grammar_dump (stderr, "Reduced Grammar");
-
- fprintf (stderr, "reduced %s defines %d terminals, %d nonterminals"
- ", and %d productions.\n",
- grammar_file, ntokens, nvars, nrules);
- }
-}
-
-bool
-reduce_token_unused_in_grammar (symbol_number i)
-{
- aver (i < ntokens);
- return !bitset_test (V, i) && !bitset_test (V1, i);
-}
-
-bool
-reduce_nonterminal_useless_in_grammar (symbol_number i)
-{
- aver (ntokens <= i && i < nsyms + nuseless_nonterminals);
- return nsyms <= i;
-}
-
-/*-----------------------------------------------------------.
-| Free the global sets used to compute the reduced grammar. |
-`-----------------------------------------------------------*/
-
-void
-reduce_free (void)
-{
- bitset_free (N);
- bitset_free (V);
- bitset_free (V1);
- bitset_free (P);
-}
+/* Grammar reduction for Bison.
+
+ Copyright (C) 1988-1989, 2000-2003, 2005-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+/* Reduce the grammar: Find and eliminate unreachable terminals,
+ nonterminals, and productions. David S. Bakin. */
+
+/* Don't eliminate unreachable terminals: They may be used by the
+ user's parser. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitset.h>
+
+#include "complain.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "print-xml.h"
+#include "reader.h"
+#include "reduce.h"
+#include "symtab.h"
+
+/* Set of all nonterminals which are not useless. */
+static bitset N;
+
+/* Set of all rules which have no useless nonterminals in their RHS. */
+static bitset P;
+
+/* Set of all accessible symbols. */
+static bitset V;
+
+/* Set of symbols used to define rule precedence (so they are
+ 'useless', but no warning should be issued). */
+static bitset V1;
+
+static rule_number nuseful_productions;
+rule_number nuseless_productions;
+static int nuseful_nonterminals;
+symbol_number nuseless_nonterminals;
+
+/*-------------------------------------------------------------------.
+| Another way to do this would be with a set for each production and |
+| then do subset tests against N0, but even for the C grammar the |
+| whole reducing process takes only 2 seconds on my 8Mhz AT. |
+`-------------------------------------------------------------------*/
+
+static bool
+useful_production (rule_number r, bitset N0)
+{
+ item_number *rhsp;
+
+ /* A production is useful if all of the nonterminals in its appear
+ in the set of useful nonterminals. */
+
+ for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
+ if (ISVAR (*rhsp) && !bitset_test (N0, *rhsp - ntokens))
+ return false;
+ return true;
+}
+
+
+/*---------------------------------------------------------.
+| Remember that rules are 1-origin, symbols are 0-origin. |
+`---------------------------------------------------------*/
+
+static void
+useless_nonterminals (void)
+{
+ bitset Np, Ns;
+ rule_number r;
+
+ /* N is set as built. Np is set being built this iteration. P is
+ set of all productions which have a RHS all in N. */
+
+ Np = bitset_create (nvars, BITSET_FIXED);
+
+
+ /* The set being computed is a set of nonterminals which can derive
+ the empty string or strings consisting of all terminals. At each
+ iteration a nonterminal is added to the set if there is a
+ production with that nonterminal as its LHS for which all the
+ nonterminals in its RHS are already in the set. Iterate until
+ the set being computed remains unchanged. Any nonterminals not
+ in the set at that point are useless in that they will never be
+ used in deriving a sentence of the language.
+
+ This iteration doesn't use any special traversal over the
+ productions. A set is kept of all productions for which all the
+ nonterminals in the RHS are in useful. Only productions not in
+ this set are scanned on each iteration. At the end, this set is
+ saved to be used when finding useful productions: only
+ productions in this set will appear in the final grammar. */
+
+ while (1)
+ {
+ bitset_copy (Np, N);
+ for (r = 0; r < nrules; r++)
+ if (!bitset_test (P, r)
+ && useful_production (r, N))
+ {
+ bitset_set (Np, rules[r].lhs->number - ntokens);
+ bitset_set (P, r);
+ }
+ if (bitset_equal_p (N, Np))
+ break;
+ Ns = Np;
+ Np = N;
+ N = Ns;
+ }
+ bitset_free (N);
+ N = Np;
+}
+
+
+static void
+inaccessable_symbols (void)
+{
+ bitset Vp, Vs, Pp;
+
+ /* Find out which productions are reachable and which symbols are
+ used. Starting with an empty set of productions and a set of
+ symbols which only has the start symbol in it, iterate over all
+ productions until the set of productions remains unchanged for an
+ iteration. For each production which has a LHS in the set of
+ reachable symbols, add the production to the set of reachable
+ productions, and add all of the nonterminals in the RHS of the
+ production to the set of reachable symbols.
+
+ Consider only the (partially) reduced grammar which has only
+ nonterminals in N and productions in P.
+
+ The result is the set P of productions in the reduced grammar,
+ and the set V of symbols in the reduced grammar.
+
+ Although this algorithm also computes the set of terminals which
+ are reachable, no terminal will be deleted from the grammar. Some
+ terminals might not be in the grammar but might be generated by
+ semantic routines, and so the user might want them available with
+ specified numbers. (Is this true?) However, the nonreachable
+ terminals are printed (if running in verbose mode) so that the
+ user can know. */
+
+ Vp = bitset_create (nsyms, BITSET_FIXED);
+ Pp = bitset_create (nrules, BITSET_FIXED);
+
+ /* If the start symbol isn't useful, then nothing will be useful. */
+ if (bitset_test (N, accept->number - ntokens))
+ {
+ bitset_set (V, accept->number);
+
+ while (1)
+ {
+ rule_number r;
+ bitset_copy (Vp, V);
+ for (r = 0; r < nrules; r++)
+ {
+ if (!bitset_test (Pp, r)
+ && bitset_test (P, r)
+ && bitset_test (V, rules[r].lhs->number))
+ {
+ item_number *rhsp;
+ for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
+ if (ISTOKEN (*rhsp) || bitset_test (N, *rhsp - ntokens))
+ bitset_set (Vp, *rhsp);
+ bitset_set (Pp, r);
+ }
+ }
+ if (bitset_equal_p (V, Vp))
+ break;
+ Vs = Vp;
+ Vp = V;
+ V = Vs;
+ }
+ }
+
+ bitset_free (V);
+ V = Vp;
+
+ /* Tokens 0, 1, and 2 are internal to Bison. Consider them useful. */
+ bitset_set (V, endtoken->number); /* end-of-input token */
+ bitset_set (V, errtoken->number); /* error token */
+ bitset_set (V, undeftoken->number); /* some undefined token */
+
+ bitset_free (P);
+ P = Pp;
+
+ nuseful_productions = bitset_count (P);
+ nuseless_productions = nrules - nuseful_productions;
+
+ nuseful_nonterminals = 0;
+ {
+ symbol_number i;
+ for (i = ntokens; i < nsyms; i++)
+ if (bitset_test (V, i))
+ nuseful_nonterminals++;
+ }
+ nuseless_nonterminals = nvars - nuseful_nonterminals;
+
+ /* A token that was used in %prec should not be warned about. */
+ {
+ rule_number r;
+ for (r = 0; r < nrules; ++r)
+ if (rules[r].precsym != 0)
+ bitset_set (V1, rules[r].precsym->number);
+ }
+}
+
+
+/*-------------------------------------------------------------------.
+| Put the useless productions at the end of RULES, and adjust NRULES |
+| accordingly. |
+`-------------------------------------------------------------------*/
+
+static void
+reduce_grammar_tables (void)
+{
+ /* Report and flag useless productions. */
+ {
+ rule_number r;
+ for (r = 0; r < nrules; r++)
+ rules[r].useful = bitset_test (P, r);
+ grammar_rules_useless_report (_("rule useless in grammar"));
+ }
+
+ /* Map the nonterminals to their new index: useful first, useless
+ afterwards. Kept for later report. */
+ {
+ int useful = 0;
+ int useless = nrules - nuseless_productions;
+ rule *rules_sorted = xnmalloc (nrules, sizeof *rules_sorted);
+ rule_number r;
+ for (r = 0; r < nrules; ++r)
+ rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r];
+ free (rules);
+ rules = rules_sorted;
+
+ /* Renumber the rules markers in RITEMS. */
+ for (r = 0; r < nrules; ++r)
+ {
+ item_number *rhsp = rules[r].rhs;
+ for (/* Nothing. */; *rhsp >= 0; ++rhsp)
+ /* Nothing. */;
+ *rhsp = rule_number_as_item_number (r);
+ rules[r].number = r;
+ }
+ nrules -= nuseless_productions;
+ }
+
+ /* Adjust NRITEMS. */
+ {
+ rule_number r;
+ int length;
+ for (r = nrules; r < nrules + nuseless_productions; ++r)
+ {
+ length = rule_rhs_length (&rules[r]);
+ nritems -= length + 1;
+ }
+ }
+}
+
+
+/*------------------------------.
+| Remove useless nonterminals. |
+`------------------------------*/
+
+static void
+nonterminals_reduce (void)
+{
+ /* Map the nonterminals to their new index: useful first, useless
+ afterwards. Kept for later report. */
+
+ symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap);
+ symbol_number n = ntokens;
+ symbol_number i;
+ for (i = ntokens; i < nsyms; i++)
+ if (bitset_test (V, i))
+ nontermmap[i - ntokens] = n++;
+ for (i = ntokens; i < nsyms; i++)
+ if (!bitset_test (V, i))
+ {
+ nontermmap[i - ntokens] = n++;
+ if (symbols[i]->status != used)
+ complain (&symbols[i]->location, Wother,
+ _("nonterminal useless in grammar: %s"),
+ symbols[i]->tag);
+ }
+
+
+ /* Shuffle elements of tables indexed by symbol number. */
+ {
+ symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted);
+
+ for (i = ntokens; i < nsyms; i++)
+ symbols[i]->number = nontermmap[i - ntokens];
+ for (i = ntokens; i < nsyms; i++)
+ symbols_sorted[nontermmap[i - ntokens] - ntokens] = symbols[i];
+ for (i = ntokens; i < nsyms; i++)
+ symbols[i] = symbols_sorted[i - ntokens];
+ free (symbols_sorted);
+ }
+
+ {
+ rule_number r;
+ for (r = 0; r < nrules; ++r)
+ {
+ item_number *rhsp;
+ for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
+ if (ISVAR (*rhsp))
+ *rhsp = symbol_number_as_item_number (nontermmap[*rhsp
+ - ntokens]);
+ }
+ accept->number = nontermmap[accept->number - ntokens];
+ }
+
+ nsyms -= nuseless_nonterminals;
+ nvars -= nuseless_nonterminals;
+
+ free (nontermmap);
+}
+
+
+/*------------------------------------------------------------------.
+| Output the detailed results of the reductions. For FILE.output. |
+`------------------------------------------------------------------*/
+
+void
+reduce_output (FILE *out)
+{
+ if (nuseless_nonterminals > 0)
+ {
+ int i;
+ fprintf (out, "%s\n\n", _("Nonterminals useless in grammar"));
+ for (i = 0; i < nuseless_nonterminals; ++i)
+ fprintf (out, " %s\n", symbols[nsyms + i]->tag);
+ fputs ("\n\n", out);
+ }
+
+ {
+ bool b = false;
+ int i;
+ for (i = 0; i < ntokens; i++)
+ if (reduce_token_unused_in_grammar (i))
+ {
+ if (!b)
+ fprintf (out, "%s\n\n", _("Terminals unused in grammar"));
+ b = true;
+ fprintf (out, " %s\n", symbols[i]->tag);
+ }
+ if (b)
+ fputs ("\n\n", out);
+ }
+
+ if (nuseless_productions > 0)
+ grammar_rules_partial_print (out, _("Rules useless in grammar"),
+ rule_useless_in_grammar_p);
+}
+
+
+/*-------------------------------.
+| Report the results to STDERR. |
+`-------------------------------*/
+
+static void
+reduce_print (void)
+{
+ if (nuseless_nonterminals > 0)
+ complain (NULL, Wother, ngettext ("%d nonterminal useless in grammar",
+ "%d nonterminals useless in grammar",
+ nuseless_nonterminals),
+ nuseless_nonterminals);
+ if (nuseless_productions > 0)
+ complain (NULL, Wother, ngettext ("%d rule useless in grammar",
+ "%d rules useless in grammar",
+ nuseless_productions),
+ nuseless_productions);
+}
+
+void
+reduce_grammar (void)
+{
+ bool reduced;
+
+ /* Allocate the global sets used to compute the reduced grammar */
+
+ N = bitset_create (nvars, BITSET_FIXED);
+ P = bitset_create (nrules, BITSET_FIXED);
+ V = bitset_create (nsyms, BITSET_FIXED);
+ V1 = bitset_create (nsyms, BITSET_FIXED);
+
+ useless_nonterminals ();
+ inaccessable_symbols ();
+
+ reduced = (nuseless_nonterminals + nuseless_productions > 0);
+ if (!reduced)
+ return;
+
+ reduce_print ();
+
+ if (!bitset_test (N, accept->number - ntokens))
+ complain (&startsymbol_location, fatal,
+ _("start symbol %s does not derive any sentence"),
+ startsymbol->tag);
+
+ /* First reduce the nonterminals, as they renumber themselves in the
+ whole grammar. If you change the order, nonterms would be
+ renumbered only in the reduced grammar. */
+ if (nuseless_nonterminals > 0)
+ nonterminals_reduce ();
+ if (nuseless_productions > 0)
+ reduce_grammar_tables ();
+
+ if (trace_flag & trace_grammar)
+ {
+ grammar_dump (stderr, "Reduced Grammar");
+
+ fprintf (stderr, "reduced %s defines %d terminals, %d nonterminals"
+ ", and %d productions.\n",
+ grammar_file, ntokens, nvars, nrules);
+ }
+}
+
+bool
+reduce_token_unused_in_grammar (symbol_number i)
+{
+ aver (i < ntokens);
+ return !bitset_test (V, i) && !bitset_test (V1, i);
+}
+
+bool
+reduce_nonterminal_useless_in_grammar (symbol_number i)
+{
+ aver (ntokens <= i && i < nsyms + nuseless_nonterminals);
+ return nsyms <= i;
+}
+
+/*-----------------------------------------------------------.
+| Free the global sets used to compute the reduced grammar. |
+`-----------------------------------------------------------*/
+
+void
+reduce_free (void)
+{
+ bitset_free (N);
+ bitset_free (V);
+ bitset_free (V1);
+ bitset_free (P);
+}
diff --git a/contrib/tools/bison/bison/src/reduce.h b/contrib/tools/bison/bison/src/reduce.h
index bc12ed0e50..11c0352784 100644
--- a/contrib/tools/bison/bison/src/reduce.h
+++ b/contrib/tools/bison/bison/src/reduce.h
@@ -1,32 +1,32 @@
-/* Grammar reduction for Bison.
-
- Copyright (C) 2000-2002, 2007, 2009-2013 Free Software Foundation,
- Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef REDUCE_H_
-# define REDUCE_H_
-
-void reduce_grammar (void);
-void reduce_output (FILE *out);
-bool reduce_token_unused_in_grammar (symbol_number i);
-bool reduce_nonterminal_useless_in_grammar (symbol_number i);
-void reduce_free (void);
-
-extern symbol_number nuseless_nonterminals;
-extern rule_number nuseless_productions;
-#endif /* !REDUCE_H_ */
+/* Grammar reduction for Bison.
+
+ Copyright (C) 2000-2002, 2007, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef REDUCE_H_
+# define REDUCE_H_
+
+void reduce_grammar (void);
+void reduce_output (FILE *out);
+bool reduce_token_unused_in_grammar (symbol_number i);
+bool reduce_nonterminal_useless_in_grammar (symbol_number i);
+void reduce_free (void);
+
+extern symbol_number nuseless_nonterminals;
+extern rule_number nuseless_productions;
+#endif /* !REDUCE_H_ */
diff --git a/contrib/tools/bison/bison/src/relation.c b/contrib/tools/bison/bison/src/relation.c
index 5746eca704..b3113801db 100644
--- a/contrib/tools/bison/bison/src/relation.c
+++ b/contrib/tools/bison/bison/src/relation.c
@@ -1,183 +1,183 @@
-/* Binary relations.
-
- Copyright (C) 2002, 2004-2005, 2009-2013 Free Software Foundation,
- Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitsetv.h>
-
-#include "getargs.h"
-#include "relation.h"
-
-void
-relation_print (relation r, relation_node size, FILE *out)
-{
- relation_node i;
- relation_node j;
-
- for (i = 0; i < size; ++i)
- {
- fprintf (out, "%3lu: ", (unsigned long int) i);
- if (r[i])
- for (j = 0; r[i][j] != END_NODE; ++j)
- fprintf (out, "%3lu ", (unsigned long int) r[i][j]);
- fputc ('\n', out);
- }
- fputc ('\n', out);
-}
-
-
-/*---------------------------------------------------------------.
-| digraph & traverse. |
-| |
-| The following variables are used as common storage between the |
-| two. |
-`---------------------------------------------------------------*/
-
-static relation R;
-static relation_nodes INDEX;
-static relation_nodes VERTICES;
-static relation_node top;
-static relation_node infinity;
-static bitsetv F;
-
-static void
-traverse (relation_node i)
-{
- relation_node j;
- relation_node height;
-
- VERTICES[++top] = i;
- INDEX[i] = height = top;
-
- if (R[i])
- for (j = 0; R[i][j] != END_NODE; ++j)
- {
- if (INDEX[R[i][j]] == 0)
- traverse (R[i][j]);
-
- if (INDEX[i] > INDEX[R[i][j]])
- INDEX[i] = INDEX[R[i][j]];
-
- bitset_or (F[i], F[i], F[R[i][j]]);
- }
-
- if (INDEX[i] == height)
- for (;;)
- {
- j = VERTICES[top--];
- INDEX[j] = infinity;
-
- if (i == j)
- break;
-
- bitset_copy (F[j], F[i]);
- }
-}
-
-
-void
-relation_digraph (relation r, relation_node size, bitsetv *function)
-{
- relation_node i;
-
- infinity = size + 2;
- INDEX = xcalloc (size + 1, sizeof *INDEX);
- VERTICES = xnmalloc (size + 1, sizeof *VERTICES);
- top = 0;
-
- R = r;
- F = *function;
-
- for (i = 0; i < size; i++)
- if (INDEX[i] == 0 && R[i])
- traverse (i);
-
- free (INDEX);
- free (VERTICES);
-
- *function = F;
-}
-
-
-/*-------------------------------------------.
-| Destructively transpose R_ARG, of size N. |
-`-------------------------------------------*/
-
-void
-relation_transpose (relation *R_arg, relation_node n)
-{
- relation r = *R_arg;
- /* The result. */
- relation new_R = xnmalloc (n, sizeof *new_R);
- /* END_R[I] -- next entry of NEW_R[I]. */
- relation end_R = xnmalloc (n, sizeof *end_R);
- /* NEDGES[I] -- total size of NEW_R[I]. */
- size_t *nedges = xcalloc (n, sizeof *nedges);
- relation_node i;
- relation_node j;
-
- if (trace_flag & trace_sets)
- {
- fputs ("relation_transpose: input\n", stderr);
- relation_print (r, n, stderr);
- }
-
- /* Count. */
- for (i = 0; i < n; i++)
- if (r[i])
- for (j = 0; r[i][j] != END_NODE; ++j)
- ++nedges[r[i][j]];
-
- /* Allocate. */
- for (i = 0; i < n; i++)
- {
- relation_node *sp = NULL;
- if (nedges[i] > 0)
- {
- sp = xnmalloc (nedges[i] + 1, sizeof *sp);
- sp[nedges[i]] = END_NODE;
- }
- new_R[i] = sp;
- end_R[i] = sp;
- }
-
- /* Store. */
- for (i = 0; i < n; i++)
- if (r[i])
- for (j = 0; r[i][j] != END_NODE; ++j)
- *end_R[r[i][j]]++ = i;
-
- free (nedges);
- free (end_R);
-
- /* Free the input: it is replaced with the result. */
- for (i = 0; i < n; i++)
- free (r[i]);
- free (r);
-
- if (trace_flag & trace_sets)
- {
- fputs ("relation_transpose: output\n", stderr);
- relation_print (new_R, n, stderr);
- }
-
- *R_arg = new_R;
-}
+/* Binary relations.
+
+ Copyright (C) 2002, 2004-2005, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitsetv.h>
+
+#include "getargs.h"
+#include "relation.h"
+
+void
+relation_print (relation r, relation_node size, FILE *out)
+{
+ relation_node i;
+ relation_node j;
+
+ for (i = 0; i < size; ++i)
+ {
+ fprintf (out, "%3lu: ", (unsigned long int) i);
+ if (r[i])
+ for (j = 0; r[i][j] != END_NODE; ++j)
+ fprintf (out, "%3lu ", (unsigned long int) r[i][j]);
+ fputc ('\n', out);
+ }
+ fputc ('\n', out);
+}
+
+
+/*---------------------------------------------------------------.
+| digraph & traverse. |
+| |
+| The following variables are used as common storage between the |
+| two. |
+`---------------------------------------------------------------*/
+
+static relation R;
+static relation_nodes INDEX;
+static relation_nodes VERTICES;
+static relation_node top;
+static relation_node infinity;
+static bitsetv F;
+
+static void
+traverse (relation_node i)
+{
+ relation_node j;
+ relation_node height;
+
+ VERTICES[++top] = i;
+ INDEX[i] = height = top;
+
+ if (R[i])
+ for (j = 0; R[i][j] != END_NODE; ++j)
+ {
+ if (INDEX[R[i][j]] == 0)
+ traverse (R[i][j]);
+
+ if (INDEX[i] > INDEX[R[i][j]])
+ INDEX[i] = INDEX[R[i][j]];
+
+ bitset_or (F[i], F[i], F[R[i][j]]);
+ }
+
+ if (INDEX[i] == height)
+ for (;;)
+ {
+ j = VERTICES[top--];
+ INDEX[j] = infinity;
+
+ if (i == j)
+ break;
+
+ bitset_copy (F[j], F[i]);
+ }
+}
+
+
+void
+relation_digraph (relation r, relation_node size, bitsetv *function)
+{
+ relation_node i;
+
+ infinity = size + 2;
+ INDEX = xcalloc (size + 1, sizeof *INDEX);
+ VERTICES = xnmalloc (size + 1, sizeof *VERTICES);
+ top = 0;
+
+ R = r;
+ F = *function;
+
+ for (i = 0; i < size; i++)
+ if (INDEX[i] == 0 && R[i])
+ traverse (i);
+
+ free (INDEX);
+ free (VERTICES);
+
+ *function = F;
+}
+
+
+/*-------------------------------------------.
+| Destructively transpose R_ARG, of size N. |
+`-------------------------------------------*/
+
+void
+relation_transpose (relation *R_arg, relation_node n)
+{
+ relation r = *R_arg;
+ /* The result. */
+ relation new_R = xnmalloc (n, sizeof *new_R);
+ /* END_R[I] -- next entry of NEW_R[I]. */
+ relation end_R = xnmalloc (n, sizeof *end_R);
+ /* NEDGES[I] -- total size of NEW_R[I]. */
+ size_t *nedges = xcalloc (n, sizeof *nedges);
+ relation_node i;
+ relation_node j;
+
+ if (trace_flag & trace_sets)
+ {
+ fputs ("relation_transpose: input\n", stderr);
+ relation_print (r, n, stderr);
+ }
+
+ /* Count. */
+ for (i = 0; i < n; i++)
+ if (r[i])
+ for (j = 0; r[i][j] != END_NODE; ++j)
+ ++nedges[r[i][j]];
+
+ /* Allocate. */
+ for (i = 0; i < n; i++)
+ {
+ relation_node *sp = NULL;
+ if (nedges[i] > 0)
+ {
+ sp = xnmalloc (nedges[i] + 1, sizeof *sp);
+ sp[nedges[i]] = END_NODE;
+ }
+ new_R[i] = sp;
+ end_R[i] = sp;
+ }
+
+ /* Store. */
+ for (i = 0; i < n; i++)
+ if (r[i])
+ for (j = 0; r[i][j] != END_NODE; ++j)
+ *end_R[r[i][j]]++ = i;
+
+ free (nedges);
+ free (end_R);
+
+ /* Free the input: it is replaced with the result. */
+ for (i = 0; i < n; i++)
+ free (r[i]);
+ free (r);
+
+ if (trace_flag & trace_sets)
+ {
+ fputs ("relation_transpose: output\n", stderr);
+ relation_print (new_R, n, stderr);
+ }
+
+ *R_arg = new_R;
+}
diff --git a/contrib/tools/bison/bison/src/relation.h b/contrib/tools/bison/bison/src/relation.h
index b44e1a7f98..1abba00a5e 100644
--- a/contrib/tools/bison/bison/src/relation.h
+++ b/contrib/tools/bison/bison/src/relation.h
@@ -1,49 +1,49 @@
-/* Binary relations.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#ifndef RELATION_H_
-# define RELATION_H_
-
-/* Performing operations on graphs coded as list of adjacency.
-
- If GRAPH is a relation, then GRAPH[Node] is a list of adjacent
- nodes, ended with END_NODE. */
-
-# define END_NODE ((relation_node) -1)
-
-typedef size_t relation_node;
-typedef relation_node *relation_nodes;
-typedef relation_nodes *relation;
-
-
-/* Report a relation R that has SIZE vertices. */
-void relation_print (relation r, relation_node size, FILE *out);
-
-/* Compute the transitive closure of the FUNCTION on the relation R
- with SIZE vertices.
-
- If R (NODE-1, NODE-2) then on exit FUNCTION[NODE - 1] was extended
- (unioned) with FUNCTION[NODE - 2]. */
-void relation_digraph (relation r, relation_node size, bitsetv *function);
-
-/* Destructively transpose *R_ARG, of size N. */
-void relation_transpose (relation *R_arg, relation_node n);
-
-#endif /* ! RELATION_H_ */
+/* Binary relations.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifndef RELATION_H_
+# define RELATION_H_
+
+/* Performing operations on graphs coded as list of adjacency.
+
+ If GRAPH is a relation, then GRAPH[Node] is a list of adjacent
+ nodes, ended with END_NODE. */
+
+# define END_NODE ((relation_node) -1)
+
+typedef size_t relation_node;
+typedef relation_node *relation_nodes;
+typedef relation_nodes *relation;
+
+
+/* Report a relation R that has SIZE vertices. */
+void relation_print (relation r, relation_node size, FILE *out);
+
+/* Compute the transitive closure of the FUNCTION on the relation R
+ with SIZE vertices.
+
+ If R (NODE-1, NODE-2) then on exit FUNCTION[NODE - 1] was extended
+ (unioned) with FUNCTION[NODE - 2]. */
+void relation_digraph (relation r, relation_node size, bitsetv *function);
+
+/* Destructively transpose *R_ARG, of size N. */
+void relation_transpose (relation *R_arg, relation_node n);
+
+#endif /* ! RELATION_H_ */
diff --git a/contrib/tools/bison/bison/src/scan-code-c.c b/contrib/tools/bison/bison/src/scan-code-c.c
index 7d37b766b5..f730482a26 100644
--- a/contrib/tools/bison/bison/src/scan-code-c.c
+++ b/contrib/tools/bison/bison/src/scan-code-c.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#include "system.h"
-#include "src/scan-code.c"
+#include <config.h>
+#include "system.h"
+#include "src/scan-code.c"
diff --git a/contrib/tools/bison/bison/src/scan-code.c b/contrib/tools/bison/bison/src/scan-code.c
index 971f30241f..504a206ee9 100644
--- a/contrib/tools/bison/bison/src/scan-code.c
+++ b/contrib/tools/bison/bison/src/scan-code.c
@@ -1,2990 +1,2990 @@
-#line 2 "src/scan-code.c"
-
-#line 4 "src/scan-code.c"
-
-#define YY_INT_ALIGNED short int
-
-/* A lexical scanner generated by flex */
-
-/* %not-for-header */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-#define yy_create_buffer code__create_buffer
-#define yy_delete_buffer code__delete_buffer
-#define yy_flex_debug code__flex_debug
-#define yy_init_buffer code__init_buffer
-#define yy_flush_buffer code__flush_buffer
-#define yy_load_buffer_state code__load_buffer_state
-#define yy_switch_to_buffer code__switch_to_buffer
-#define yyin code_in
-#define yyleng code_leng
-#define yylex code_lex
-#define yylineno code_lineno
-#define yyout code_out
-#define yyrestart code_restart
-#define yytext code_text
-#define yywrap code_wrap
-#define yyalloc code_alloc
-#define yyrealloc code_realloc
-#define yyfree code_free
-
-/* %endif */
-/* %endif */
-/* %ok-for-header */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 37
-#if YY_FLEX_SUBMINOR_VERSION > 0
-#define FLEX_BETA
-#endif
-
-/* %if-c++-only */
-/* %endif */
-
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c-only */
-
-/* %endif */
-
-/* First, we deal with platform-specific or compiler-specific issues. */
-
-/* begin standard C headers. */
-/* %if-c-only */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-/* %endif */
-
-/* %if-tables-serialization */
-/* %endif */
-/* end standard C headers. */
-
-/* %if-c-or-c++ */
-/* flex integer type definitions */
-
-#ifndef FLEXINT_H
-#define FLEXINT_H
-
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
-
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-
-/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types.
- */
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS 1
-#endif
-
-#include <inttypes.h>
-typedef int8_t flex_int8_t;
-typedef uint8_t flex_uint8_t;
-typedef int16_t flex_int16_t;
-typedef uint16_t flex_uint16_t;
-typedef int32_t flex_int32_t;
-typedef uint32_t flex_uint32_t;
-#else
-typedef signed char flex_int8_t;
-typedef short int flex_int16_t;
-typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
-typedef unsigned short int flex_uint16_t;
-typedef unsigned int flex_uint32_t;
-
-/* Limits of integral types. */
-#ifndef INT8_MIN
-#define INT8_MIN (-128)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN (-32767-1)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN (-2147483647-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX (127)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX (32767)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX (2147483647)
-#endif
-#ifndef UINT8_MAX
-#define UINT8_MAX (255U)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX (65535U)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX (4294967295U)
-#endif
-
-#endif /* ! C99 */
-
-#endif /* ! FLEXINT_H */
-
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
-#ifdef __cplusplus
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else /* ! __cplusplus */
-
-/* C99 requires __STDC__ to be defined as 1. */
-#if defined (__STDC__)
-
-#define YY_USE_CONST
-
-#endif /* defined (__STDC__) */
-#endif /* ! __cplusplus */
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-/* %not-for-header */
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index. If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-/* %ok-for-header */
-
-/* %if-reentrant */
-/* %endif */
-
-/* %if-not-reentrant */
-
-/* %endif */
-
-/* Enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN (yy_start) = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state. The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START (((yy_start) - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE code_restart(code_in )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#ifndef YY_BUF_SIZE
-#define YY_BUF_SIZE 16384
-#endif
-
-/* The state buf must be large enough to hold one state per character in the main buffer.
- */
-#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
-
-#ifndef YY_TYPEDEF_YY_BUFFER_STATE
-#define YY_TYPEDEF_YY_BUFFER_STATE
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-#endif
-
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
-/* %if-not-reentrant */
-extern yy_size_t code_leng;
-/* %endif */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-extern FILE *code_in, *code_out;
-/* %endif */
-/* %endif */
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
- #define YY_LESS_LINENO(n)
-
-/* Return all but the first "n" matched characters back to the input stream. */
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up code_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- *yy_cp = (yy_hold_char); \
- YY_RESTORE_YY_MORE_OFFSET \
- (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
- YY_DO_BEFORE_ACTION; /* set up code_text again */ \
- } \
- while ( 0 )
-
-#define unput(c) yyunput( c, (yytext_ptr) )
-
-#ifndef YY_STRUCT_YY_BUFFER_STATE
-#define YY_STRUCT_YY_BUFFER_STATE
-struct yy_buffer_state
- {
-/* %if-c-only */
- FILE *yy_input_file;
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
- char *yy_ch_buf; /* input buffer */
- char *yy_buf_pos; /* current position in input buffer */
-
- /* Size of input buffer in bytes, not including room for EOB
- * characters.
- */
- yy_size_t yy_buf_size;
-
- /* Number of characters read into yy_ch_buf, not including EOB
- * characters.
- */
- yy_size_t yy_n_chars;
-
- /* Whether we "own" the buffer - i.e., we know we created it,
- * and can realloc() it to grow it, and should free() it to
- * delete it.
- */
- int yy_is_our_buffer;
-
- /* Whether this is an "interactive" input source; if so, and
- * if we're using stdio for input, then we want to use getc()
- * instead of fread(), to make sure we stop fetching input after
- * each newline.
- */
- int yy_is_interactive;
-
- /* Whether we're considered to be at the beginning of a line.
- * If so, '^' rules will be active on the next match, otherwise
- * not.
- */
- int yy_at_bol;
-
- int yy_bs_lineno; /**< The line count. */
- int yy_bs_column; /**< The column count. */
-
- /* Whether to try to fill the input buffer when we reach the
- * end of it.
- */
- int yy_fill_buffer;
-
- int yy_buffer_status;
-
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
- /* When an EOF's been seen but there's still some text to process
- * then we mark the buffer as YY_EOF_PENDING, to indicate that we
- * shouldn't try reading from the input source any more. We might
- * still have a bunch of tokens to match, though, because of
- * possible backing-up.
- *
- * When we actually see the EOF, we change the status to "new"
- * (via code_restart()), so that the user can continue scanning by
- * just pointing code_in at a new input file.
- */
-#define YY_BUFFER_EOF_PENDING 2
-
- };
-#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-/* %if-not-reentrant */
-
-/* Stack of input buffers. */
-static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
-static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
-static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
-/* %endif */
-/* %ok-for-header */
-
-/* %endif */
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
- ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
- : NULL)
-
-/* Same as previous macro, but useful when we know that the buffer stack is not
- * NULL or when we need an lvalue. For internal use only.
- */
-#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
-
-/* %if-c-only Standard (non-C++) definition */
-
-/* %if-not-reentrant */
-/* %not-for-header */
-
-/* yy_hold_char holds the character lost when code_text is formed. */
-static char yy_hold_char;
-static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
-yy_size_t code_leng;
-
-/* Points to current character in buffer. */
-static char *yy_c_buf_p = (char *) 0;
-static int yy_init = 0; /* whether we need to initialize */
-static int yy_start = 0; /* start state number */
-
-/* Flag which is used to allow code_wrap()'s to do buffer switches
- * instead of setting up a fresh code_in. A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-/* %ok-for-header */
-
-/* %endif */
-
-void code_restart (FILE *input_file );
-void code__switch_to_buffer (YY_BUFFER_STATE new_buffer );
-YY_BUFFER_STATE code__create_buffer (FILE *file,int size );
-void code__delete_buffer (YY_BUFFER_STATE b );
-void code__flush_buffer (YY_BUFFER_STATE b );
-void code_push_buffer_state (YY_BUFFER_STATE new_buffer );
-void code_pop_buffer_state (void );
-
-static void code_ensure_buffer_stack (void );
-static void code__load_buffer_state (void );
-static void code__init_buffer (YY_BUFFER_STATE b,FILE *file );
-
-#define YY_FLUSH_BUFFER code__flush_buffer(YY_CURRENT_BUFFER )
-
-YY_BUFFER_STATE code__scan_buffer (char *base,yy_size_t size );
-YY_BUFFER_STATE code__scan_string (yyconst char *yy_str );
-YY_BUFFER_STATE code__scan_bytes (yyconst char *bytes,yy_size_t len );
-
-/* %endif */
-
-void *code_alloc (yy_size_t );
-void *code_realloc (void *,yy_size_t );
-void code_free (void * );
-
-#define yy_new_buffer code__create_buffer
-
-#define yy_set_interactive(is_interactive) \
- { \
- if ( ! YY_CURRENT_BUFFER ){ \
- code_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- code__create_buffer(code_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
- }
-
-#define yy_set_bol(at_bol) \
- { \
- if ( ! YY_CURRENT_BUFFER ){\
- code_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- code__create_buffer(code_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
- }
-
-#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
-
-/* %% [1.0] code_text/code_in/code_out/yy_state_type/code_lineno etc. def's & init go here */
-/* Begin user sect3 */
-
-#define code_wrap() 1
-#define YY_SKIP_YYWRAP
-
-#define FLEX_DEBUG
-
-typedef unsigned char YY_CHAR;
-
-FILE *code_in = (FILE *) 0, *code_out = (FILE *) 0;
-
-typedef int yy_state_type;
-
-extern int code_lineno;
-
-int code_lineno = 1;
-
-extern char *code_text;
-#define yytext_ptr code_text
-
-/* %if-c-only Standard (non-C++) definition */
-
-static yy_state_type yy_get_previous_state (void );
-static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
-static int yy_get_next_buffer (void );
-static void yy_fatal_error (yyconst char msg[] );
-
-/* %endif */
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up code_text.
- */
-#define YY_DO_BEFORE_ACTION \
- (yytext_ptr) = yy_bp; \
-/* %% [2.0] code to fiddle code_text and code_leng for yymore() goes here \ */\
- code_leng = (size_t) (yy_cp - yy_bp); \
- (yy_hold_char) = *yy_cp; \
- *yy_cp = '\0'; \
-/* %% [3.0] code to copy yytext_ptr to code_text[] goes here, if %array \ */\
- (yy_c_buf_p) = yy_cp;
-
-/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
-#define YY_NUM_RULES 18
-#define YY_END_OF_BUFFER 19
-/* This struct is not used in this scanner,
- but its presence is necessary. */
-struct yy_trans_info
- {
- flex_int32_t yy_verify;
- flex_int32_t yy_nxt;
- };
-static yyconst flex_int16_t yy_accept[91] =
- { 0,
- 0, 0, 0, 0, 3, 3, 4, 4, 4, 4,
- 0, 0, 0, 0, 19, 17, 16, 17, 2, 17,
- 6, 17, 5, 8, 11, 7, 17, 11, 11, 11,
- 1, 0, 0, 3, 4, 4, 4, 4, 12, 0,
- 12, 12, 0, 0, 9, 10, 0, 13, 0, 13,
- 13, 0, 14, 0, 15, 0, 0, 0, 0, 0,
- 0, 0, 12, 0, 0, 0, 0, 0, 13, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 12, 0,
- 12, 12, 0, 14, 12, 12, 0, 0, 0, 0
- } ;
-
-static yyconst flex_int32_t yy_ec[256] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 4, 1, 5, 1, 1, 6, 1,
- 1, 7, 1, 1, 8, 9, 10, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 1, 1, 12,
- 1, 13, 1, 14, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 15, 16, 17, 1, 9, 1, 9, 9, 9, 9,
-
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
- } ;
-
-static yyconst flex_int32_t yy_meta[19] =
- { 0,
- 1, 1, 2, 1, 1, 1, 1, 3, 3, 1,
- 3, 1, 2, 1, 1, 1, 1, 2
- } ;
-
-static yyconst flex_int16_t yy_base[97] =
- { 0,
- 0, 13, 121, 120, 0, 3, 4, 5, 6, 7,
- 27, 0, 20, 21, 125, 178, 178, 26, 178, 8,
- 178, 41, 178, 178, 53, 178, 62, 74, 33, 119,
- 178, 37, 44, 105, 178, 46, 101, 48, 178, 99,
- 0, 96, 98, 91, 178, 178, 50, 178, 87, 0,
- 86, 87, 178, 76, 178, 52, 50, 68, 71, 73,
- 78, 74, 0, 16, 78, 84, 85, 0, 0, 94,
- 86, 96, 55, 107, 0, 0, 58, 118, 100, 124,
- 130, 136, 142, 106, 46, 0, 148, 43, 0, 178,
- 165, 168, 4, 171, 1, 174
-
- } ;
-
-static yyconst flex_int16_t yy_def[97] =
- { 0,
- 91, 91, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 11, 11, 11, 90, 90, 90, 90, 90, 90,
- 90, 92, 90, 90, 90, 90, 90, 90, 90, 90,
- 90, 90, 90, 90, 90, 90, 90, 90, 90, 90,
- 93, 90, 94, 90, 90, 90, 90, 90, 90, 95,
- 90, 90, 90, 96, 90, 90, 90, 90, 90, 90,
- 90, 92, 93, 94, 94, 90, 90, 27, 95, 90,
- 96, 96, 25, 94, 66, 70, 90, 96, 94, 94,
- 94, 94, 94, 96, 81, 81, 81, 87, 87, 0,
- 90, 90, 90, 90, 90, 90
-
- } ;
-
-static yyconst flex_int16_t yy_nxt[197] =
- { 0,
- 90, 90, 19, 69, 17, 19, 63, 21, 21, 33,
- 34, 23, 23, 17, 17, 20, 17, 17, 20, 22,
- 22, 22, 22, 65, 29, 29, 17, 17, 73, 17,
- 24, 25, 26, 30, 30, 31, 27, 53, 56, 57,
- 28, 32, 36, 37, 54, 33, 34, 59, 37, 61,
- 62, 67, 68, 56, 57, 74, 38, 39, 74, 31,
- 40, 41, 53, 42, 43, 32, 90, 44, 45, 33,
- 34, 46, 59, 37, 59, 37, 90, 47, 48, 61,
- 62, 49, 50, 72, 51, 65, 67, 68, 52, 38,
- 74, 75, 75, 72, 75, 70, 51, 51, 77, 66,
-
- 39, 76, 76, 72, 76, 65, 42, 65, 78, 42,
- 48, 79, 73, 72, 80, 81, 60, 82, 77, 73,
- 58, 83, 84, 55, 90, 72, 18, 18, 90, 90,
- 77, 65, 90, 90, 82, 90, 74, 85, 86, 90,
- 86, 90, 73, 65, 90, 90, 82, 90, 73, 65,
- 87, 90, 90, 90, 73, 88, 89, 90, 89, 90,
- 90, 90, 90, 90, 79, 16, 16, 16, 35, 35,
- 35, 64, 90, 64, 71, 90, 71, 15, 90, 90,
- 90, 90, 90, 90, 90, 90, 90, 90, 90, 90,
- 90, 90, 90, 90, 90, 90
-
- } ;
-
-static yyconst flex_int16_t yy_chk[197] =
- { 0,
- 0, 0, 5, 95, 1, 6, 93, 7, 8, 20,
- 20, 9, 10, 1, 1, 5, 1, 2, 6, 7,
- 8, 9, 10, 64, 13, 14, 2, 2, 64, 2,
- 11, 11, 11, 13, 14, 18, 11, 29, 32, 32,
- 11, 18, 22, 22, 29, 33, 33, 36, 36, 38,
- 38, 47, 47, 56, 56, 88, 22, 25, 85, 57,
- 25, 25, 77, 25, 25, 57, 73, 25, 27, 58,
- 58, 27, 59, 59, 60, 60, 62, 27, 28, 61,
- 61, 28, 28, 54, 28, 65, 67, 67, 28, 62,
- 65, 66, 66, 71, 66, 52, 51, 49, 71, 44,
-
- 66, 70, 70, 72, 70, 43, 42, 79, 72, 40,
- 70, 74, 79, 84, 74, 74, 37, 74, 84, 74,
- 34, 74, 78, 30, 15, 78, 4, 3, 0, 0,
- 78, 80, 0, 0, 80, 0, 80, 81, 81, 0,
- 81, 0, 81, 82, 0, 0, 82, 0, 82, 83,
- 83, 0, 0, 0, 83, 87, 87, 0, 87, 0,
- 0, 0, 0, 0, 87, 91, 91, 91, 92, 92,
- 92, 94, 0, 94, 96, 0, 96, 90, 90, 90,
- 90, 90, 90, 90, 90, 90, 90, 90, 90, 90,
- 90, 90, 90, 90, 90, 90
-
- } ;
-
-static yy_state_type yy_last_accepting_state;
-static char *yy_last_accepting_cpos;
-
-extern int code__flex_debug;
-int code__flex_debug = 1;
-
-static yyconst flex_int16_t yy_rule_linenum[18] =
- { 0,
- 114, 124, 125, 135, 140, 145, 151, 152, 153, 154,
- 156, 164, 170, 180, 188, 198, 201
- } ;
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-char *code_text;
-#line 1 "../../src/scan-code.l"
-/* Bison Action Scanner -*- C -*-
-
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#define YY_NO_INPUT 1
-#line 24 "../../src/scan-code.l"
-/* Work around a bug in flex 2.5.31. See Debian bug 333231
- <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
-#undef code_wrap
-#define code_wrap() 1
-
-#define FLEX_PREFIX(Id) code_ ## Id
-#include <src/flex-scanner.h>
-
-#include <src/complain.h>
-#include <src/reader.h>
-#include <src/getargs.h>
-#include <src/muscle-tab.h>
-#include <src/scan-code.h>
-#include <src/symlist.h>
-
-#include <c-ctype.h>
-#include <get-errno.h>
-#include <quote.h>
-
-/* The current calling start condition: SC_RULE_ACTION or
- SC_SYMBOL_ACTION. */
-# define YY_DECL static char *code_lex (code_props *self, int sc_context)
-YY_DECL;
-
-#define YY_USER_ACTION location_compute (loc, &loc->end, code_text, code_leng);
-
-static char *fetch_type_name (char *cp, char const **type_name,
- location dollar_loc);
-
-static void handle_action_dollar (symbol_list *rule, char *cp,
- location dollar_loc);
-static void handle_action_at (symbol_list *rule, char *cp, location at_loc);
-
-/* A string to be pushed to obstack after dollar/at has been handled. */
-static char *ref_tail_fields;
-
-static location the_location;
-static location *loc = &the_location;
-
-/* A string representing the most recent translation. */
-static char *last_string;
-
-/* True if an untyped $$ or $n was seen. */
-static bool untyped_var_seen;
-
-/* C and C++ comments in code. */
-
-/* Strings and characters in code. */
-
-/* Whether in a rule or symbol action. Specifies the translation
-of $ and @. */
-
-/* POSIX says that a tag must be both an id and a C union member, but
- historically almost any character is allowed in a tag. We disallow
- NUL and newline, as this simplifies our implementation. We allow
- "->" as a means to dereference a pointer. */
-/* Zero or more instances of backslash-newline. Following GCC, allow
- white space between the backslash and the newline. */
-/* C style identifier. Must start with letter. Will be used for
- named symbol references. Shall be kept synchronized with
- scan-gram.l "letter" and "id". */
-#line 713 "src/scan-code.c"
-
-#define INITIAL 0
-#define SC_COMMENT 1
-#define SC_LINE_COMMENT 2
-#define SC_STRING 3
-#define SC_CHARACTER 4
-#define SC_RULE_ACTION 5
-#define SC_SYMBOL_ACTION 6
-
-#ifndef YY_NO_UNISTD_H
-/* Special case for "unistd.h", since it is non-ANSI. We include it way
- * down here because we want the user's section 1 to have been scanned first.
- * The user has a chance to override it with an option.
- */
-/* %if-c-only */
-#include <unistd.h>
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-#ifndef YY_EXTRA_TYPE
-#define YY_EXTRA_TYPE void *
-#endif
-
-/* %if-c-only Reentrant structure and macros (non-C++). */
-/* %if-reentrant */
-/* %if-c-only */
-
-static int yy_init_globals (void );
-
-/* %endif */
-/* %if-reentrant */
-/* %endif */
-/* %endif End reentrant structures and macros. */
-
-/* Accessor methods to globals.
- These are made visible to non-reentrant scanners for convenience. */
-
-int code_lex_destroy (void );
-
-int code_get_debug (void );
-
-void code_set_debug (int debug_flag );
-
-YY_EXTRA_TYPE code_get_extra (void );
-
-void code_set_extra (YY_EXTRA_TYPE user_defined );
-
-FILE *code_get_in (void );
-
-void code_set_in (FILE * in_str );
-
-FILE *code_get_out (void );
-
-void code_set_out (FILE * out_str );
-
-yy_size_t code_get_leng (void );
-
-char *code_get_text (void );
-
-int code_get_lineno (void );
-
-void code_set_lineno (int line_number );
-
-/* %if-bison-bridge */
-/* %endif */
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int code_wrap (void );
-#else
-extern int code_wrap (void );
-#endif
-#endif
-
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %endif */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int );
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * );
-#endif
-
-#ifndef YY_NO_INPUT
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-#ifdef __cplusplus
-static int yyinput (void );
-#else
-static int input (void );
-#endif
-/* %ok-for-header */
-
-/* %endif */
-#endif
-
-/* %if-c-only */
-
-/* %endif */
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-#ifndef ECHO
-/* %if-c-only Standard (non-C++) definition */
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO do { if (fwrite( code_text, code_leng, 1, code_out )) {} } while (0)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif
-
-/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
- if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
- { \
- int c = '*'; \
- size_t n; \
- for ( n = 0; n < max_size && \
- (c = getc( code_in )) != EOF && c != '\n'; ++n ) \
- buf[n] = (char) c; \
- if ( c == '\n' ) \
- buf[n++] = (char) c; \
- if ( c == EOF && ferror( code_in ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- result = n; \
- } \
- else \
- { \
- errno=0; \
- while ( (result = fread(buf, 1, max_size, code_in))==0 && ferror(code_in)) \
- { \
- if( errno != EINTR) \
- { \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- break; \
- } \
- errno=0; \
- clearerr(code_in); \
- } \
- }\
-\
-/* %if-c++-only C++ definition \ */\
-/* %endif */
-
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-/* %if-c-only */
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-/* %if-tables-serialization structures and prototypes */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* %tables-yydmap generated elements */
-/* %endif */
-/* end tables serialization structures and prototypes */
-
-/* %ok-for-header */
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL_IS_OURS 1
-/* %if-c-only Standard (non-C++) definition */
-
-extern int code_lex (void);
-
-#define YY_DECL int code_lex (void)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif /* !YY_DECL */
-
-/* Code executed at the beginning of each rule, after code_text and code_leng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-/* %% [6.0] YY_RULE_SETUP definition goes here */
-#define YY_RULE_SETUP \
- YY_USER_ACTION
-
-/* %not-for-header */
-
-/** The main scanner function which does all the work.
- */
-YY_DECL
-{
- register yy_state_type yy_current_state;
- register char *yy_cp, *yy_bp;
- register int yy_act;
-
-/* %% [7.0] user's declarations go here */
-#line 96 "../../src/scan-code.l"
-
-
-
- /* This scanner is special: it is invoked only once, henceforth
- is expected to return only once. This initialization is
- therefore done once per action to translate. */
- aver (sc_context == SC_SYMBOL_ACTION
- || sc_context == SC_RULE_ACTION
- || sc_context == INITIAL);
- BEGIN sc_context;
-
-
- /*------------------------------------------------------------.
- | Scanning a C comment. The initial '/ *' is already eaten. |
- `------------------------------------------------------------*/
-
-#line 976 "src/scan-code.c"
-
- if ( !(yy_init) )
- {
- (yy_init) = 1;
-
-#ifdef YY_USER_INIT
- YY_USER_INIT;
-#endif
-
- if ( ! (yy_start) )
- (yy_start) = 1; /* first start state */
-
- if ( ! code_in )
-/* %if-c-only */
- code_in = stdin;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! code_out )
-/* %if-c-only */
- code_out = stdout;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! YY_CURRENT_BUFFER ) {
- code_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- code__create_buffer(code_in,YY_BUF_SIZE );
- }
-
- code__load_buffer_state( );
- }
-
- while ( 1 ) /* loops until end-of-file is reached */
- {
-/* %% [8.0] yymore()-related code goes here */
- yy_cp = (yy_c_buf_p);
-
- /* Support of code_text. */
- *yy_cp = (yy_hold_char);
-
- /* yy_bp points to the position in yy_ch_buf of the start of
- * the current run.
- */
- yy_bp = yy_cp;
-
-/* %% [9.0] code to set up and find next match goes here */
- yy_current_state = (yy_start);
-yy_match:
- do
- {
- register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 91 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- ++yy_cp;
- }
- while ( yy_current_state != 90 );
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
-
-yy_find_action:
-/* %% [10.0] code to find the action number goes here */
- yy_act = yy_accept[yy_current_state];
-
- YY_DO_BEFORE_ACTION;
-
-/* %% [11.0] code for code_lineno update goes here */
-
-do_action: /* This label is used only to access EOF actions. */
-
-/* %% [12.0] debug code goes here */
- if ( code__flex_debug )
- {
- if ( yy_act == 0 )
- fprintf( stderr, "--scanner backing up\n" );
- else if ( yy_act < 18 )
- fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
- (long)yy_rule_linenum[yy_act], code_text );
- else if ( yy_act == 18 )
- fprintf( stderr, "--accepting default rule (\"%s\")\n",
- code_text );
- else if ( yy_act == 19 )
- fprintf( stderr, "--(end of buffer or a NUL)\n" );
- else
- fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
- }
-
- switch ( yy_act )
- { /* beginning of action switch */
-/* %% [13.0] actions go here */
- case 0: /* must back up */
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = (yy_hold_char);
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
-
-case 1:
-/* rule 1 can match eol */
-YY_RULE_SETUP
-#line 114 "../../src/scan-code.l"
-STRING_GROW; BEGIN sc_context;
- YY_BREAK
-
-/*--------------------------------------------------------------.
- | Scanning a line comment. The initial '//' is already eaten. |
- `--------------------------------------------------------------*/
-
-
-case 2:
-/* rule 2 can match eol */
-YY_RULE_SETUP
-#line 124 "../../src/scan-code.l"
-STRING_GROW; BEGIN sc_context;
- YY_BREAK
-case 3:
-/* rule 3 can match eol */
-YY_RULE_SETUP
-#line 125 "../../src/scan-code.l"
-STRING_GROW;
- YY_BREAK
-
-/*--------------------------------------------.
- | Scanning user-code characters and strings. |
- `--------------------------------------------*/
-
-
-case 4:
-/* rule 4 can match eol */
-YY_RULE_SETUP
-#line 135 "../../src/scan-code.l"
-STRING_GROW;
- YY_BREAK
-
-
-
-case 5:
-YY_RULE_SETUP
-#line 140 "../../src/scan-code.l"
-STRING_GROW; BEGIN sc_context;
- YY_BREAK
-
-
-
-case 6:
-YY_RULE_SETUP
-#line 145 "../../src/scan-code.l"
-STRING_GROW; BEGIN sc_context;
- YY_BREAK
-
-
-
-case 7:
-YY_RULE_SETUP
-#line 151 "../../src/scan-code.l"
-STRING_GROW; BEGIN SC_CHARACTER;
- YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 152 "../../src/scan-code.l"
-STRING_GROW; BEGIN SC_STRING;
- YY_BREAK
-case 9:
-/* rule 9 can match eol */
-YY_RULE_SETUP
-#line 153 "../../src/scan-code.l"
-STRING_GROW; BEGIN SC_COMMENT;
- YY_BREAK
-case 10:
-/* rule 10 can match eol */
-YY_RULE_SETUP
-#line 154 "../../src/scan-code.l"
-STRING_GROW; BEGIN SC_LINE_COMMENT;
- YY_BREAK
-case 11:
-YY_RULE_SETUP
-#line 156 "../../src/scan-code.l"
-{
- complain (loc, Wother, _("stray '%s'"), code_text);
- obstack_escape (&obstack_for_string, code_text);
- }
- YY_BREAK
-
-
-
-case 12:
-YY_RULE_SETUP
-#line 164 "../../src/scan-code.l"
-{
- ref_tail_fields = NULL;
- handle_action_dollar (self->rule, code_text, *loc);
- if (ref_tail_fields)
- obstack_sgrow (&obstack_for_string, ref_tail_fields);
- }
- YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 170 "../../src/scan-code.l"
-{
- ref_tail_fields = NULL;
- handle_action_at (self->rule, code_text, *loc);
- if (ref_tail_fields)
- obstack_sgrow (&obstack_for_string, ref_tail_fields);
- }
- YY_BREAK
-
-
-
-case 14:
-YY_RULE_SETUP
-#line 180 "../../src/scan-code.l"
-{
- const char *type_name = NULL;
- fetch_type_name (code_text + 1, &type_name, *loc)[-1] = 0;
- obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
- obstack_quote (&obstack_for_string, type_name);
- obstack_sgrow (&obstack_for_string, ")[");
- self->is_value_used = true;
- }
- YY_BREAK
-case 15:
-YY_RULE_SETUP
-#line 188 "../../src/scan-code.l"
-{
- obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
- muscle_percent_define_ensure("locations", the_location, true);
- }
- YY_BREAK
-
-
-
-/* Escape M4 quoting characters in C code. */
-case 16:
-YY_RULE_SETUP
-#line 198 "../../src/scan-code.l"
-obstack_escape (&obstack_for_string, code_text);
- YY_BREAK
-/* By default, grow the string obstack with the input. */
-case 17:
-/* rule 17 can match eol */
-YY_RULE_SETUP
-#line 201 "../../src/scan-code.l"
-STRING_GROW;
- YY_BREAK
-/* End of processing. */
-case YY_STATE_EOF(INITIAL):
-case YY_STATE_EOF(SC_COMMENT):
-case YY_STATE_EOF(SC_LINE_COMMENT):
-case YY_STATE_EOF(SC_STRING):
-case YY_STATE_EOF(SC_CHARACTER):
-case YY_STATE_EOF(SC_RULE_ACTION):
-case YY_STATE_EOF(SC_SYMBOL_ACTION):
-#line 204 "../../src/scan-code.l"
-STRING_FINISH; return last_string;
- YY_BREAK
-
-case 18:
-YY_RULE_SETUP
-#line 207 "../../src/scan-code.l"
-YY_FATAL_ERROR( "flex scanner jammed" );
- YY_BREAK
-#line 1250 "src/scan-code.c"
-
- case YY_END_OF_BUFFER:
- {
- /* Amount of text matched not including the EOB char. */
- int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
-
- /* Undo the effects of YY_DO_BEFORE_ACTION. */
- *yy_cp = (yy_hold_char);
- YY_RESTORE_YY_MORE_OFFSET
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
- {
- /* We're scanning a new file or input source. It's
- * possible that this happened because the user
- * just pointed code_in at a new source and called
- * code_lex(). If so, then we have to assure
- * consistency between YY_CURRENT_BUFFER and our
- * globals. Here is the right place to do so, because
- * this is the first action (other than possibly a
- * back-up) that will match for the new input source.
- */
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- YY_CURRENT_BUFFER_LVALUE->yy_input_file = code_in;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
- }
-
- /* Note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the
- * end-of-buffer state). Contrast this with the test
- * in input().
- */
- if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- { /* This was really a NUL. */
- yy_state_type yy_next_state;
-
- (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- /* Okay, we're now positioned to make the NUL
- * transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we don't
- * want to build jamming into it because then it
- * will run more slowly).
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state );
-
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* Consume the NUL. */
- yy_cp = ++(yy_c_buf_p);
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
-/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_END_OF_FILE:
- {
- (yy_did_buffer_switch_on_eof) = 0;
-
- if ( code_wrap( ) )
- {
- /* Note: because we've taken care in
- * yy_get_next_buffer() to have set up
- * code_text, we can now set up
- * yy_c_buf_p so that if some total
- * hoser (like flex itself) wants to
- * call the scanner after we return the
- * YY_NULL, it'll still work - another
- * YY_NULL will get returned.
- */
- (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF(YY_START);
- goto do_action;
- }
-
- else
- {
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
- }
- break;
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) =
- (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- (yy_c_buf_p) =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- } /* end of action switch */
- } /* end of scanning one token */
-} /* end of code_lex */
-/* %ok-for-header */
-
-/* %if-c++-only */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %endif */
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-/* %if-c-only */
-static int yy_get_next_buffer (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
- register char *source = (yytext_ptr);
- register int number_to_move, i;
- int ret_val;
-
- if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
- { /* Don't try to fill the buffer, so this is an EOF. */
- if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
- {
- /* We matched a single character, the EOB, so
- * treat this as a final EOF.
- */
- return EOB_ACT_END_OF_FILE;
- }
-
- else
- {
- /* We matched some text prior to the EOB, first
- * process it.
- */
- return EOB_ACT_LAST_MATCH;
- }
- }
-
- /* Try to read more data. */
-
- /* First move last chars to start of buffer. */
- number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
-
- else
- {
- yy_size_t num_to_read =
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
-
- while ( num_to_read <= 0 )
- { /* Not enough room in the buffer - grow it. */
-
- /* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
-
- int yy_c_buf_p_offset =
- (int) ((yy_c_buf_p) - b->yy_ch_buf);
-
- if ( b->yy_is_our_buffer )
- {
- yy_size_t new_size = b->yy_buf_size * 2;
-
- if ( new_size <= 0 )
- b->yy_buf_size += b->yy_buf_size / 8;
- else
- b->yy_buf_size *= 2;
-
- b->yy_ch_buf = (char *)
- /* Include room in for 2 EOB chars. */
- code_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
- }
- else
- /* Can't grow it, we don't own it. */
- b->yy_ch_buf = 0;
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
-
- (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
-
- num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
- number_to_move - 1;
-
- }
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- /* Read in more data. */
- YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- (yy_n_chars), num_to_read );
-
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- if ( (yy_n_chars) == 0 )
- {
- if ( number_to_move == YY_MORE_ADJ )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- code_restart(code_in );
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
- YY_BUFFER_EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
- /* Extend the array by 50%, plus the number we really need. */
- yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) code_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
- if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
- }
-
- (yy_n_chars) += number_to_move;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
-
- (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
-
- return ret_val;
-}
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
-/* %if-c-only */
-/* %not-for-header */
-
- static yy_state_type yy_get_previous_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register yy_state_type yy_current_state;
- register char *yy_cp;
-
-/* %% [15.0] code to get the start state into yy_current_state goes here */
- yy_current_state = (yy_start);
-
- for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
- {
-/* %% [16.0] code to find the next state goes here */
- register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 18);
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 91 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- }
-
- return yy_current_state;
-}
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
-/* %if-c-only */
- static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register int yy_is_jam;
- /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
- register char *yy_cp = (yy_c_buf_p);
-
- register YY_CHAR yy_c = 18;
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 91 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 90);
-
- return yy_is_jam ? 0 : yy_current_state;
-}
-
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c-only */
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
- static int yyinput (void)
-#else
- static int input (void)
-#endif
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- int c;
-
- *(yy_c_buf_p) = (yy_hold_char);
-
- if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- /* This was really a NUL. */
- *(yy_c_buf_p) = '\0';
-
- else
- { /* need more input */
- yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
- ++(yy_c_buf_p);
-
- switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_LAST_MATCH:
- /* This happens because yy_g_n_b()
- * sees that we've accumulated a
- * token and flags that we need to
- * try matching the token before
- * proceeding. But for input(),
- * there's no matching to consider.
- * So convert the EOB_ACT_LAST_MATCH
- * to EOB_ACT_END_OF_FILE.
- */
-
- /* Reset buffer status. */
- code_restart(code_in );
-
- /*FALLTHROUGH*/
-
- case EOB_ACT_END_OF_FILE:
- {
- if ( code_wrap( ) )
- return EOF;
-
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
-#ifdef __cplusplus
- return yyinput();
-#else
- return input();
-#endif
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) = (yytext_ptr) + offset;
- break;
- }
- }
- }
-
- c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
- *(yy_c_buf_p) = '\0'; /* preserve code_text */
- (yy_hold_char) = *++(yy_c_buf_p);
-
-/* %% [19.0] update BOL and code_lineno */
-
- return c;
-}
-/* %if-c-only */
-#endif /* ifndef YY_NO_INPUT */
-/* %endif */
-
-/** Immediately switch to a different input stream.
- * @param input_file A readable stream.
+#line 2 "src/scan-code.c"
+
+#line 4 "src/scan-code.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+/* %not-for-header */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+#define yy_create_buffer code__create_buffer
+#define yy_delete_buffer code__delete_buffer
+#define yy_flex_debug code__flex_debug
+#define yy_init_buffer code__init_buffer
+#define yy_flush_buffer code__flush_buffer
+#define yy_load_buffer_state code__load_buffer_state
+#define yy_switch_to_buffer code__switch_to_buffer
+#define yyin code_in
+#define yyleng code_leng
+#define yylex code_lex
+#define yylineno code_lineno
+#define yyout code_out
+#define yyrestart code_restart
+#define yytext code_text
+#define yywrap code_wrap
+#define yyalloc code_alloc
+#define yyrealloc code_realloc
+#define yyfree code_free
+
+/* %endif */
+/* %endif */
+/* %ok-for-header */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 37
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* %if-c++-only */
+/* %endif */
+
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c-only */
+
+/* %endif */
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+/* %if-c-only */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+/* %endif */
+
+/* %if-tables-serialization */
+/* %endif */
+/* end standard C headers. */
+
+/* %if-c-or-c++ */
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* %not-for-header */
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+/* %ok-for-header */
+
+/* %if-reentrant */
+/* %endif */
+
+/* %if-not-reentrant */
+
+/* %endif */
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE code_restart(code_in )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+/* %if-not-reentrant */
+extern yy_size_t code_leng;
+/* %endif */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+extern FILE *code_in, *code_out;
+/* %endif */
+/* %endif */
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up code_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up code_text again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+/* %if-c-only */
+ FILE *yy_input_file;
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ yy_size_t yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via code_restart()), so that the user can continue scanning by
+ * just pointing code_in at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+/* %if-not-reentrant */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
+/* %endif */
+/* %ok-for-header */
+
+/* %endif */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
*
- * @note This function does not reset the start condition to @c INITIAL .
- */
-/* %if-c-only */
- void code_restart (FILE * input_file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! YY_CURRENT_BUFFER ){
- code_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- code__create_buffer(code_in,YY_BUF_SIZE );
- }
-
- code__init_buffer(YY_CURRENT_BUFFER,input_file );
- code__load_buffer_state( );
-}
-
-/** Switch to a different input buffer.
- * @param new_buffer The new input buffer.
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* %if-c-only Standard (non-C++) definition */
+
+/* %if-not-reentrant */
+/* %not-for-header */
+
+/* yy_hold_char holds the character lost when code_text is formed. */
+static char yy_hold_char;
+static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
+yy_size_t code_leng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow code_wrap()'s to do buffer switches
+ * instead of setting up a fresh code_in. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+/* %ok-for-header */
+
+/* %endif */
+
+void code_restart (FILE *input_file );
+void code__switch_to_buffer (YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE code__create_buffer (FILE *file,int size );
+void code__delete_buffer (YY_BUFFER_STATE b );
+void code__flush_buffer (YY_BUFFER_STATE b );
+void code_push_buffer_state (YY_BUFFER_STATE new_buffer );
+void code_pop_buffer_state (void );
+
+static void code_ensure_buffer_stack (void );
+static void code__load_buffer_state (void );
+static void code__init_buffer (YY_BUFFER_STATE b,FILE *file );
+
+#define YY_FLUSH_BUFFER code__flush_buffer(YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE code__scan_buffer (char *base,yy_size_t size );
+YY_BUFFER_STATE code__scan_string (yyconst char *yy_str );
+YY_BUFFER_STATE code__scan_bytes (yyconst char *bytes,yy_size_t len );
+
+/* %endif */
+
+void *code_alloc (yy_size_t );
+void *code_realloc (void *,yy_size_t );
+void code_free (void * );
+
+#define yy_new_buffer code__create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ code_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ code__create_buffer(code_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ code_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ code__create_buffer(code_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* %% [1.0] code_text/code_in/code_out/yy_state_type/code_lineno etc. def's & init go here */
+/* Begin user sect3 */
+
+#define code_wrap() 1
+#define YY_SKIP_YYWRAP
+
+#define FLEX_DEBUG
+
+typedef unsigned char YY_CHAR;
+
+FILE *code_in = (FILE *) 0, *code_out = (FILE *) 0;
+
+typedef int yy_state_type;
+
+extern int code_lineno;
+
+int code_lineno = 1;
+
+extern char *code_text;
+#define yytext_ptr code_text
+
+/* %if-c-only Standard (non-C++) definition */
+
+static yy_state_type yy_get_previous_state (void );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
+static int yy_get_next_buffer (void );
+static void yy_fatal_error (yyconst char msg[] );
+
+/* %endif */
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up code_text.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+/* %% [2.0] code to fiddle code_text and code_leng for yymore() goes here \ */\
+ code_leng = (size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+/* %% [3.0] code to copy yytext_ptr to code_text[] goes here, if %array \ */\
+ (yy_c_buf_p) = yy_cp;
+
+/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
+#define YY_NUM_RULES 18
+#define YY_END_OF_BUFFER 19
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[91] =
+ { 0,
+ 0, 0, 0, 0, 3, 3, 4, 4, 4, 4,
+ 0, 0, 0, 0, 19, 17, 16, 17, 2, 17,
+ 6, 17, 5, 8, 11, 7, 17, 11, 11, 11,
+ 1, 0, 0, 3, 4, 4, 4, 4, 12, 0,
+ 12, 12, 0, 0, 9, 10, 0, 13, 0, 13,
+ 13, 0, 14, 0, 15, 0, 0, 0, 0, 0,
+ 0, 0, 12, 0, 0, 0, 0, 0, 13, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 12, 0,
+ 12, 12, 0, 14, 12, 12, 0, 0, 0, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 4, 1, 5, 1, 1, 6, 1,
+ 1, 7, 1, 1, 8, 9, 10, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 1, 1, 12,
+ 1, 13, 1, 14, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 15, 16, 17, 1, 9, 1, 9, 9, 9, 9,
+
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[19] =
+ { 0,
+ 1, 1, 2, 1, 1, 1, 1, 3, 3, 1,
+ 3, 1, 2, 1, 1, 1, 1, 2
+ } ;
+
+static yyconst flex_int16_t yy_base[97] =
+ { 0,
+ 0, 13, 121, 120, 0, 3, 4, 5, 6, 7,
+ 27, 0, 20, 21, 125, 178, 178, 26, 178, 8,
+ 178, 41, 178, 178, 53, 178, 62, 74, 33, 119,
+ 178, 37, 44, 105, 178, 46, 101, 48, 178, 99,
+ 0, 96, 98, 91, 178, 178, 50, 178, 87, 0,
+ 86, 87, 178, 76, 178, 52, 50, 68, 71, 73,
+ 78, 74, 0, 16, 78, 84, 85, 0, 0, 94,
+ 86, 96, 55, 107, 0, 0, 58, 118, 100, 124,
+ 130, 136, 142, 106, 46, 0, 148, 43, 0, 178,
+ 165, 168, 4, 171, 1, 174
+
+ } ;
+
+static yyconst flex_int16_t yy_def[97] =
+ { 0,
+ 91, 91, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 11, 11, 11, 90, 90, 90, 90, 90, 90,
+ 90, 92, 90, 90, 90, 90, 90, 90, 90, 90,
+ 90, 90, 90, 90, 90, 90, 90, 90, 90, 90,
+ 93, 90, 94, 90, 90, 90, 90, 90, 90, 95,
+ 90, 90, 90, 96, 90, 90, 90, 90, 90, 90,
+ 90, 92, 93, 94, 94, 90, 90, 27, 95, 90,
+ 96, 96, 25, 94, 66, 70, 90, 96, 94, 94,
+ 94, 94, 94, 96, 81, 81, 81, 87, 87, 0,
+ 90, 90, 90, 90, 90, 90
+
+ } ;
+
+static yyconst flex_int16_t yy_nxt[197] =
+ { 0,
+ 90, 90, 19, 69, 17, 19, 63, 21, 21, 33,
+ 34, 23, 23, 17, 17, 20, 17, 17, 20, 22,
+ 22, 22, 22, 65, 29, 29, 17, 17, 73, 17,
+ 24, 25, 26, 30, 30, 31, 27, 53, 56, 57,
+ 28, 32, 36, 37, 54, 33, 34, 59, 37, 61,
+ 62, 67, 68, 56, 57, 74, 38, 39, 74, 31,
+ 40, 41, 53, 42, 43, 32, 90, 44, 45, 33,
+ 34, 46, 59, 37, 59, 37, 90, 47, 48, 61,
+ 62, 49, 50, 72, 51, 65, 67, 68, 52, 38,
+ 74, 75, 75, 72, 75, 70, 51, 51, 77, 66,
+
+ 39, 76, 76, 72, 76, 65, 42, 65, 78, 42,
+ 48, 79, 73, 72, 80, 81, 60, 82, 77, 73,
+ 58, 83, 84, 55, 90, 72, 18, 18, 90, 90,
+ 77, 65, 90, 90, 82, 90, 74, 85, 86, 90,
+ 86, 90, 73, 65, 90, 90, 82, 90, 73, 65,
+ 87, 90, 90, 90, 73, 88, 89, 90, 89, 90,
+ 90, 90, 90, 90, 79, 16, 16, 16, 35, 35,
+ 35, 64, 90, 64, 71, 90, 71, 15, 90, 90,
+ 90, 90, 90, 90, 90, 90, 90, 90, 90, 90,
+ 90, 90, 90, 90, 90, 90
+
+ } ;
+
+static yyconst flex_int16_t yy_chk[197] =
+ { 0,
+ 0, 0, 5, 95, 1, 6, 93, 7, 8, 20,
+ 20, 9, 10, 1, 1, 5, 1, 2, 6, 7,
+ 8, 9, 10, 64, 13, 14, 2, 2, 64, 2,
+ 11, 11, 11, 13, 14, 18, 11, 29, 32, 32,
+ 11, 18, 22, 22, 29, 33, 33, 36, 36, 38,
+ 38, 47, 47, 56, 56, 88, 22, 25, 85, 57,
+ 25, 25, 77, 25, 25, 57, 73, 25, 27, 58,
+ 58, 27, 59, 59, 60, 60, 62, 27, 28, 61,
+ 61, 28, 28, 54, 28, 65, 67, 67, 28, 62,
+ 65, 66, 66, 71, 66, 52, 51, 49, 71, 44,
+
+ 66, 70, 70, 72, 70, 43, 42, 79, 72, 40,
+ 70, 74, 79, 84, 74, 74, 37, 74, 84, 74,
+ 34, 74, 78, 30, 15, 78, 4, 3, 0, 0,
+ 78, 80, 0, 0, 80, 0, 80, 81, 81, 0,
+ 81, 0, 81, 82, 0, 0, 82, 0, 82, 83,
+ 83, 0, 0, 0, 83, 87, 87, 0, 87, 0,
+ 0, 0, 0, 0, 87, 91, 91, 91, 92, 92,
+ 92, 94, 0, 94, 96, 0, 96, 90, 90, 90,
+ 90, 90, 90, 90, 90, 90, 90, 90, 90, 90,
+ 90, 90, 90, 90, 90, 90
+
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int code__flex_debug;
+int code__flex_debug = 1;
+
+static yyconst flex_int16_t yy_rule_linenum[18] =
+ { 0,
+ 114, 124, 125, 135, 140, 145, 151, 152, 153, 154,
+ 156, 164, 170, 180, 188, 198, 201
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *code_text;
+#line 1 "../../src/scan-code.l"
+/* Bison Action Scanner -*- C -*-
+
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define YY_NO_INPUT 1
+#line 24 "../../src/scan-code.l"
+/* Work around a bug in flex 2.5.31. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+#undef code_wrap
+#define code_wrap() 1
+
+#define FLEX_PREFIX(Id) code_ ## Id
+#include <src/flex-scanner.h>
+
+#include <src/complain.h>
+#include <src/reader.h>
+#include <src/getargs.h>
+#include <src/muscle-tab.h>
+#include <src/scan-code.h>
+#include <src/symlist.h>
+
+#include <c-ctype.h>
+#include <get-errno.h>
+#include <quote.h>
+
+/* The current calling start condition: SC_RULE_ACTION or
+ SC_SYMBOL_ACTION. */
+# define YY_DECL static char *code_lex (code_props *self, int sc_context)
+YY_DECL;
+
+#define YY_USER_ACTION location_compute (loc, &loc->end, code_text, code_leng);
+
+static char *fetch_type_name (char *cp, char const **type_name,
+ location dollar_loc);
+
+static void handle_action_dollar (symbol_list *rule, char *cp,
+ location dollar_loc);
+static void handle_action_at (symbol_list *rule, char *cp, location at_loc);
+
+/* A string to be pushed to obstack after dollar/at has been handled. */
+static char *ref_tail_fields;
+
+static location the_location;
+static location *loc = &the_location;
+
+/* A string representing the most recent translation. */
+static char *last_string;
+
+/* True if an untyped $$ or $n was seen. */
+static bool untyped_var_seen;
+
+/* C and C++ comments in code. */
+
+/* Strings and characters in code. */
+
+/* Whether in a rule or symbol action. Specifies the translation
+of $ and @. */
+
+/* POSIX says that a tag must be both an id and a C union member, but
+ historically almost any character is allowed in a tag. We disallow
+ NUL and newline, as this simplifies our implementation. We allow
+ "->" as a means to dereference a pointer. */
+/* Zero or more instances of backslash-newline. Following GCC, allow
+ white space between the backslash and the newline. */
+/* C style identifier. Must start with letter. Will be used for
+ named symbol references. Shall be kept synchronized with
+ scan-gram.l "letter" and "id". */
+#line 713 "src/scan-code.c"
+
+#define INITIAL 0
+#define SC_COMMENT 1
+#define SC_LINE_COMMENT 2
+#define SC_STRING 3
+#define SC_CHARACTER 4
+#define SC_RULE_ACTION 5
+#define SC_SYMBOL_ACTION 6
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+/* %if-c-only */
+#include <unistd.h>
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* %if-c-only Reentrant structure and macros (non-C++). */
+/* %if-reentrant */
+/* %if-c-only */
+
+static int yy_init_globals (void );
+
+/* %endif */
+/* %if-reentrant */
+/* %endif */
+/* %endif End reentrant structures and macros. */
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int code_lex_destroy (void );
+
+int code_get_debug (void );
+
+void code_set_debug (int debug_flag );
+
+YY_EXTRA_TYPE code_get_extra (void );
+
+void code_set_extra (YY_EXTRA_TYPE user_defined );
+
+FILE *code_get_in (void );
+
+void code_set_in (FILE * in_str );
+
+FILE *code_get_out (void );
+
+void code_set_out (FILE * out_str );
+
+yy_size_t code_get_leng (void );
+
+char *code_get_text (void );
+
+int code_get_lineno (void );
+
+void code_set_lineno (int line_number );
+
+/* %if-bison-bridge */
+/* %endif */
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int code_wrap (void );
+#else
+extern int code_wrap (void );
+#endif
+#endif
+
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %endif */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+#ifdef __cplusplus
+static int yyinput (void );
+#else
+static int input (void );
+#endif
+/* %ok-for-header */
+
+/* %endif */
+#endif
+
+/* %if-c-only */
+
+/* %endif */
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* %if-c-only Standard (non-C++) definition */
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( code_text, code_leng, 1, code_out )) {} } while (0)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( code_in )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( code_in ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, code_in))==0 && ferror(code_in)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(code_in); \
+ } \
+ }\
+\
+/* %if-c++-only C++ definition \ */\
+/* %endif */
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+/* %if-c-only */
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+/* %if-tables-serialization structures and prototypes */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* %tables-yydmap generated elements */
+/* %endif */
+/* end tables serialization structures and prototypes */
+
+/* %ok-for-header */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+/* %if-c-only Standard (non-C++) definition */
+
+extern int code_lex (void);
+
+#define YY_DECL int code_lex (void)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after code_text and code_leng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+/* %% [6.0] YY_RULE_SETUP definition goes here */
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/* %not-for-header */
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+/* %% [7.0] user's declarations go here */
+#line 96 "../../src/scan-code.l"
+
+
+
+ /* This scanner is special: it is invoked only once, henceforth
+ is expected to return only once. This initialization is
+ therefore done once per action to translate. */
+ aver (sc_context == SC_SYMBOL_ACTION
+ || sc_context == SC_RULE_ACTION
+ || sc_context == INITIAL);
+ BEGIN sc_context;
+
+
+ /*------------------------------------------------------------.
+ | Scanning a C comment. The initial '/ *' is already eaten. |
+ `------------------------------------------------------------*/
+
+#line 976 "src/scan-code.c"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! code_in )
+/* %if-c-only */
+ code_in = stdin;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! code_out )
+/* %if-c-only */
+ code_out = stdout;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ code_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ code__create_buffer(code_in,YY_BUF_SIZE );
+ }
+
+ code__load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+/* %% [8.0] yymore()-related code goes here */
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of code_text. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+/* %% [9.0] code to set up and find next match goes here */
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 91 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 90 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+/* %% [10.0] code to find the action number goes here */
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+/* %% [11.0] code for code_lineno update goes here */
+
+do_action: /* This label is used only to access EOF actions. */
+
+/* %% [12.0] debug code goes here */
+ if ( code__flex_debug )
+ {
+ if ( yy_act == 0 )
+ fprintf( stderr, "--scanner backing up\n" );
+ else if ( yy_act < 18 )
+ fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
+ (long)yy_rule_linenum[yy_act], code_text );
+ else if ( yy_act == 18 )
+ fprintf( stderr, "--accepting default rule (\"%s\")\n",
+ code_text );
+ else if ( yy_act == 19 )
+ fprintf( stderr, "--(end of buffer or a NUL)\n" );
+ else
+ fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
+ }
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+/* %% [13.0] actions go here */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+/* rule 1 can match eol */
+YY_RULE_SETUP
+#line 114 "../../src/scan-code.l"
+STRING_GROW; BEGIN sc_context;
+ YY_BREAK
+
+/*--------------------------------------------------------------.
+ | Scanning a line comment. The initial '//' is already eaten. |
+ `--------------------------------------------------------------*/
+
+
+case 2:
+/* rule 2 can match eol */
+YY_RULE_SETUP
+#line 124 "../../src/scan-code.l"
+STRING_GROW; BEGIN sc_context;
+ YY_BREAK
+case 3:
+/* rule 3 can match eol */
+YY_RULE_SETUP
+#line 125 "../../src/scan-code.l"
+STRING_GROW;
+ YY_BREAK
+
+/*--------------------------------------------.
+ | Scanning user-code characters and strings. |
+ `--------------------------------------------*/
+
+
+case 4:
+/* rule 4 can match eol */
+YY_RULE_SETUP
+#line 135 "../../src/scan-code.l"
+STRING_GROW;
+ YY_BREAK
+
+
+
+case 5:
+YY_RULE_SETUP
+#line 140 "../../src/scan-code.l"
+STRING_GROW; BEGIN sc_context;
+ YY_BREAK
+
+
+
+case 6:
+YY_RULE_SETUP
+#line 145 "../../src/scan-code.l"
+STRING_GROW; BEGIN sc_context;
+ YY_BREAK
+
+
+
+case 7:
+YY_RULE_SETUP
+#line 151 "../../src/scan-code.l"
+STRING_GROW; BEGIN SC_CHARACTER;
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 152 "../../src/scan-code.l"
+STRING_GROW; BEGIN SC_STRING;
+ YY_BREAK
+case 9:
+/* rule 9 can match eol */
+YY_RULE_SETUP
+#line 153 "../../src/scan-code.l"
+STRING_GROW; BEGIN SC_COMMENT;
+ YY_BREAK
+case 10:
+/* rule 10 can match eol */
+YY_RULE_SETUP
+#line 154 "../../src/scan-code.l"
+STRING_GROW; BEGIN SC_LINE_COMMENT;
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 156 "../../src/scan-code.l"
+{
+ complain (loc, Wother, _("stray '%s'"), code_text);
+ obstack_escape (&obstack_for_string, code_text);
+ }
+ YY_BREAK
+
+
+
+case 12:
+YY_RULE_SETUP
+#line 164 "../../src/scan-code.l"
+{
+ ref_tail_fields = NULL;
+ handle_action_dollar (self->rule, code_text, *loc);
+ if (ref_tail_fields)
+ obstack_sgrow (&obstack_for_string, ref_tail_fields);
+ }
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 170 "../../src/scan-code.l"
+{
+ ref_tail_fields = NULL;
+ handle_action_at (self->rule, code_text, *loc);
+ if (ref_tail_fields)
+ obstack_sgrow (&obstack_for_string, ref_tail_fields);
+ }
+ YY_BREAK
+
+
+
+case 14:
+YY_RULE_SETUP
+#line 180 "../../src/scan-code.l"
+{
+ const char *type_name = NULL;
+ fetch_type_name (code_text + 1, &type_name, *loc)[-1] = 0;
+ obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
+ obstack_quote (&obstack_for_string, type_name);
+ obstack_sgrow (&obstack_for_string, ")[");
+ self->is_value_used = true;
+ }
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 188 "../../src/scan-code.l"
+{
+ obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
+ muscle_percent_define_ensure("locations", the_location, true);
+ }
+ YY_BREAK
+
+
+
+/* Escape M4 quoting characters in C code. */
+case 16:
+YY_RULE_SETUP
+#line 198 "../../src/scan-code.l"
+obstack_escape (&obstack_for_string, code_text);
+ YY_BREAK
+/* By default, grow the string obstack with the input. */
+case 17:
+/* rule 17 can match eol */
+YY_RULE_SETUP
+#line 201 "../../src/scan-code.l"
+STRING_GROW;
+ YY_BREAK
+/* End of processing. */
+case YY_STATE_EOF(INITIAL):
+case YY_STATE_EOF(SC_COMMENT):
+case YY_STATE_EOF(SC_LINE_COMMENT):
+case YY_STATE_EOF(SC_STRING):
+case YY_STATE_EOF(SC_CHARACTER):
+case YY_STATE_EOF(SC_RULE_ACTION):
+case YY_STATE_EOF(SC_SYMBOL_ACTION):
+#line 204 "../../src/scan-code.l"
+STRING_FINISH; return last_string;
+ YY_BREAK
+
+case 18:
+YY_RULE_SETUP
+#line 207 "../../src/scan-code.l"
+YY_FATAL_ERROR( "flex scanner jammed" );
+ YY_BREAK
+#line 1250 "src/scan-code.c"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed code_in at a new source and called
+ * code_lex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = code_in;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( code_wrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * code_text, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of code_lex */
+/* %ok-for-header */
+
+/* %if-c++-only */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %endif */
+
+/* yy_get_next_buffer - try to read in a new buffer
*
- */
-/* %if-c-only */
- void code__switch_to_buffer (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- /* TODO. We should be able to replace this entire function body
- * with
- * code_pop_buffer_state();
- * code_push_buffer_state(new_buffer);
- */
- code_ensure_buffer_stack ();
- if ( YY_CURRENT_BUFFER == new_buffer )
- return;
-
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
- code__load_buffer_state( );
-
- /* We don't actually know whether we did this switch during
- * EOF (code_wrap()) processing, but the only time this flag
- * is looked at is after code_wrap() is called, so it's safe
- * to go ahead and always set it.
- */
- (yy_did_buffer_switch_on_eof) = 1;
-}
-
-/* %if-c-only */
-static void code__load_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
- code_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
- (yy_hold_char) = *(yy_c_buf_p);
-}
-
-/** Allocate and initialize an input buffer state.
- * @param file A readable stream.
- * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+/* %if-c-only */
+static int yy_get_next_buffer (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ yy_size_t num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ yy_size_t new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ code_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ code_restart(code_in );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) code_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+/* %if-c-only */
+/* %not-for-header */
+
+ static yy_state_type yy_get_previous_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+/* %% [15.0] code to get the start state into yy_current_state goes here */
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+/* %% [16.0] code to find the next state goes here */
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 18);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 91 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
*
- * @return the allocated buffer state.
- */
-/* %if-c-only */
- YY_BUFFER_STATE code__create_buffer (FILE * file, int size )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) code_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in code__create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (char *) code_alloc(b->yy_buf_size + 2 );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in code__create_buffer()" );
-
- b->yy_is_our_buffer = 1;
-
- code__init_buffer(b,file );
-
- return b;
-}
-
-/** Destroy the buffer.
- * @param b a buffer created with code__create_buffer()
- *
- */
-/* %if-c-only */
- void code__delete_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! b )
- return;
-
- if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
- YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
-
- if ( b->yy_is_our_buffer )
- code_free((void *) b->yy_ch_buf );
-
- code_free((void *) b );
-}
-
-/* Initializes or reinitializes a buffer.
- * This function is sometimes called more than once on the same buffer,
- * such as during a code_restart() or at EOF.
- */
-/* %if-c-only */
- static void code__init_buffer (YY_BUFFER_STATE b, FILE * file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-{
- int oerrno = errno;
-
- code__flush_buffer(b );
-
- b->yy_input_file = file;
- b->yy_fill_buffer = 1;
-
- /* If b is the current buffer, then code__init_buffer was _probably_
- * called from code_restart() or through yy_get_next_buffer.
- * In that case, we don't want to reset the lineno or column.
- */
- if (b != YY_CURRENT_BUFFER){
- b->yy_bs_lineno = 1;
- b->yy_bs_column = 0;
- }
-
-/* %if-c-only */
-
- b->yy_is_interactive = 0;
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
- errno = oerrno;
-}
-
-/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
- * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- *
- */
-/* %if-c-only */
- void code__flush_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if ( ! b )
- return;
-
- b->yy_n_chars = 0;
-
- /* We always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[0];
-
- b->yy_at_bol = 1;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- if ( b == YY_CURRENT_BUFFER )
- code__load_buffer_state( );
-}
-
-/* %if-c-or-c++ */
-/** Pushes the new state onto the stack. The new state becomes
- * the current state. This function will allocate the stack
- * if necessary.
- * @param new_buffer The new state.
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+/* %if-c-only */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register int yy_is_jam;
+ /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 18;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 91 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 90);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c-only */
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ code_restart(code_in );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( code_wrap( ) )
+ return EOF;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve code_text */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+/* %% [19.0] update BOL and code_lineno */
+
+ return c;
+}
+/* %if-c-only */
+#endif /* ifndef YY_NO_INPUT */
+/* %endif */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
*
- */
-/* %if-c-only */
-void code_push_buffer_state (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (new_buffer == NULL)
- return;
-
- code_ensure_buffer_stack();
-
- /* This block is copied from code__switch_to_buffer. */
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- /* Only push if top exists. Otherwise, replace top. */
- if (YY_CURRENT_BUFFER)
- (yy_buffer_stack_top)++;
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
-
- /* copied from code__switch_to_buffer. */
- code__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/** Removes and deletes the top of the stack, if present.
- * The next element becomes the new top.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+/* %if-c-only */
+ void code_restart (FILE * input_file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ code_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ code__create_buffer(code_in,YY_BUF_SIZE );
+ }
+
+ code__init_buffer(YY_CURRENT_BUFFER,input_file );
+ code__load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+/* %if-c-only */
+ void code__switch_to_buffer (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * code_pop_buffer_state();
+ * code_push_buffer_state(new_buffer);
+ */
+ code_ensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ code__load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (code_wrap()) processing, but the only time this flag
+ * is looked at is after code_wrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/* %if-c-only */
+static void code__load_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ code_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+/* %if-c-only */
+ YY_BUFFER_STATE code__create_buffer (FILE * file, int size )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) code_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in code__create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) code_alloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in code__create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ code__init_buffer(b,file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with code__create_buffer()
+ *
+ */
+/* %if-c-only */
+ void code__delete_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ code_free((void *) b->yy_ch_buf );
+
+ code_free((void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a code_restart() or at EOF.
+ */
+/* %if-c-only */
+ static void code__init_buffer (YY_BUFFER_STATE b, FILE * file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+{
+ int oerrno = errno;
+
+ code__flush_buffer(b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then code__init_buffer was _probably_
+ * called from code_restart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+/* %if-c-only */
+
+ b->yy_is_interactive = 0;
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+/* %if-c-only */
+ void code__flush_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ code__load_buffer_state( );
+}
+
+/* %if-c-or-c++ */
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+/* %if-c-only */
+void code_push_buffer_state (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (new_buffer == NULL)
+ return;
+
+ code_ensure_buffer_stack();
+
+ /* This block is copied from code__switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from code__switch_to_buffer. */
+ code__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+/* %if-c-only */
+void code_pop_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ code__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ code__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+/* %if-c-only */
+static void code_ensure_buffer_stack (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)code_alloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in code_ensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)code_realloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in code_ensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE code__scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) code_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in code__scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ code__switch_to_buffer(b );
+
+ return b;
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan a string. The next call to code_lex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
*
- */
-/* %if-c-only */
-void code_pop_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (!YY_CURRENT_BUFFER)
- return;
-
- code__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- if ((yy_buffer_stack_top) > 0)
- --(yy_buffer_stack_top);
-
- if (YY_CURRENT_BUFFER) {
- code__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
- }
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/* Allocates the stack if it does not exist.
- * Guarantees space for at least one push.
- */
-/* %if-c-only */
-static void code_ensure_buffer_stack (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- yy_size_t num_to_alloc;
-
- if (!(yy_buffer_stack)) {
-
- /* First allocation is just for 2 elements, since we don't know if this
- * scanner will even need a stack. We use 2 instead of 1 to avoid an
- * immediate realloc on the next call.
- */
- num_to_alloc = 1;
- (yy_buffer_stack) = (struct yy_buffer_state**)code_alloc
- (num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in code_ensure_buffer_stack()" );
-
- memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-
- (yy_buffer_stack_max) = num_to_alloc;
- (yy_buffer_stack_top) = 0;
- return;
- }
-
- if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
-
- /* Increase the buffer to prepare for a possible push. */
- int grow_size = 8 /* arbitrary grow size */;
-
- num_to_alloc = (yy_buffer_stack_max) + grow_size;
- (yy_buffer_stack) = (struct yy_buffer_state**)code_realloc
- ((yy_buffer_stack),
- num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in code_ensure_buffer_stack()" );
-
- /* zero only the new slots.*/
- memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
- (yy_buffer_stack_max) = num_to_alloc;
- }
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan directly from a user-specified character buffer.
- * @param base the character buffer
- * @param size the size in bytes of the character buffer
- *
* @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE code__scan_buffer (char * base, yy_size_t size )
-{
- YY_BUFFER_STATE b;
-
- if ( size < 2 ||
- base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
- /* They forgot to leave room for the EOB's. */
- return 0;
-
- b = (YY_BUFFER_STATE) code_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in code__scan_buffer()" );
-
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
- b->yy_buf_pos = b->yy_ch_buf = base;
- b->yy_is_our_buffer = 0;
- b->yy_input_file = 0;
- b->yy_n_chars = b->yy_buf_size;
- b->yy_is_interactive = 0;
- b->yy_at_bol = 1;
- b->yy_fill_buffer = 0;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- code__switch_to_buffer(b );
-
- return b;
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan a string. The next call to code_lex() will
- * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
- *
- * @return the newly allocated buffer state object.
- * @note If you want to scan bytes that may contain NUL values, then use
- * code__scan_bytes() instead.
- */
-YY_BUFFER_STATE code__scan_string (yyconst char * yystr )
-{
-
- return code__scan_bytes(yystr,strlen(yystr) );
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan the given bytes. The next call to code_lex() will
- * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
- *
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE code__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
-{
- YY_BUFFER_STATE b;
- char *buf;
- yy_size_t n;
- int i;
-
- /* Get memory for full buffer, including space for trailing EOB's. */
- n = _yybytes_len + 2;
- buf = (char *) code_alloc(n );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in code__scan_bytes()" );
-
- for ( i = 0; i < _yybytes_len; ++i )
- buf[i] = yybytes[i];
-
- buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
-
- b = code__scan_buffer(buf,n );
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in code__scan_bytes()" );
-
- /* It's okay to grow etc. this buffer, and we should throw it
- * away when we're done.
- */
- b->yy_is_our_buffer = 1;
-
- return b;
-}
-/* %endif */
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-/* %if-c-only */
-static void yy_fatal_error (yyconst char* msg )
-{
- (void) fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
-}
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up code_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- code_text[code_leng] = (yy_hold_char); \
- (yy_c_buf_p) = code_text + yyless_macro_arg; \
- (yy_hold_char) = *(yy_c_buf_p); \
- *(yy_c_buf_p) = '\0'; \
- code_leng = yyless_macro_arg; \
- } \
- while ( 0 )
-
-/* Accessor methods (get/set functions) to struct members. */
-
-/* %if-c-only */
-/* %if-reentrant */
-/* %endif */
-
-/** Get the current line number.
- *
- */
-int code_get_lineno (void)
-{
-
- return code_lineno;
-}
-
-/** Get the input stream.
- *
- */
-FILE *code_get_in (void)
-{
- return code_in;
-}
-
-/** Get the output stream.
- *
- */
-FILE *code_get_out (void)
-{
- return code_out;
-}
-
-/** Get the length of the current token.
- *
- */
-yy_size_t code_get_leng (void)
-{
- return code_leng;
-}
-
-/** Get the current token.
- *
- */
-
-char *code_get_text (void)
-{
- return code_text;
-}
-
-/* %if-reentrant */
-/* %endif */
-
-/** Set the current line number.
- * @param line_number
- *
- */
-void code_set_lineno (int line_number )
-{
-
- code_lineno = line_number;
-}
-
-/** Set the input stream. This does not discard the current
- * input buffer.
- * @param in_str A readable stream.
- *
- * @see code__switch_to_buffer
- */
-void code_set_in (FILE * in_str )
-{
- code_in = in_str ;
-}
-
-void code_set_out (FILE * out_str )
-{
- code_out = out_str ;
-}
-
-int code_get_debug (void)
-{
- return code__flex_debug;
-}
-
-void code_set_debug (int bdebug )
-{
- code__flex_debug = bdebug ;
-}
-
-/* %endif */
-
-/* %if-reentrant */
-/* %if-bison-bridge */
-/* %endif */
-/* %endif if-c-only */
-
-/* %if-c-only */
-static int yy_init_globals (void)
-{
- /* Initialization is the same as for the non-reentrant scanner.
- * This function is called from code_lex_destroy(), so don't allocate here.
- */
-
- (yy_buffer_stack) = 0;
- (yy_buffer_stack_top) = 0;
- (yy_buffer_stack_max) = 0;
- (yy_c_buf_p) = (char *) 0;
- (yy_init) = 0;
- (yy_start) = 0;
-
-/* Defined in main.c */
-#ifdef YY_STDINIT
- code_in = stdin;
- code_out = stdout;
-#else
- code_in = (FILE *) 0;
- code_out = (FILE *) 0;
-#endif
-
- /* For future reference: Set errno on error, since we are called by
- * code_lex_init()
- */
- return 0;
-}
-/* %endif */
-
-/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
-/* code_lex_destroy is for both reentrant and non-reentrant scanners. */
-int code_lex_destroy (void)
-{
-
- /* Pop the buffer stack, destroying each element. */
- while(YY_CURRENT_BUFFER){
- code__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- code_pop_buffer_state();
- }
-
- /* Destroy the stack itself. */
- code_free((yy_buffer_stack) );
- (yy_buffer_stack) = NULL;
-
- /* Reset the globals. This is important in a non-reentrant scanner so the next time
- * code_lex() is called, initialization will occur. */
- yy_init_globals( );
-
-/* %if-reentrant */
-/* %endif */
- return 0;
-}
-/* %endif */
-
-/*
- * Internal utility routines.
- */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
-{
- register int i;
- for ( i = 0; i < n; ++i )
- s1[i] = s2[i];
-}
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s )
-{
- register int n;
- for ( n = 0; s[n]; ++n )
- ;
-
- return n;
-}
-#endif
-
-void *code_alloc (yy_size_t size )
-{
- return (void *) malloc( size );
-}
-
-void *code_realloc (void * ptr, yy_size_t size )
-{
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- return (void *) realloc( (char *) ptr, size );
-}
-
-void code_free (void * ptr )
-{
- free( (char *) ptr ); /* see code_realloc() for (char *) cast */
-}
-
-/* %if-tables-serialization definitions */
-/* %define-yytables The name for this specific scanner's tables. */
-#define YYTABLES_NAME "yytables"
-/* %endif */
-
-/* %ok-for-header */
-
-#line 207 "../../src/scan-code.l"
-
-
-
-static inline bool
-is_dot_or_dash (char ch)
-{
- return ch == '.' || ch == '-';
-}
-
-static inline bool
-contains_dot_or_dash (const char* p)
-{
- for (; *p; ++p)
- if (is_dot_or_dash (*p))
- return true;
- return false;
-}
-
-/* Defines a variant of a symbolic name resolution. */
-typedef struct
-{
- /* Index in symbol list. */
- unsigned symbol_index;
-
- /* Matched symbol id and loc. */
- uniqstr id;
- location loc;
-
- /* Hiding named reference. */
- named_ref* hidden_by;
-
- /* Error flags. May contain zero (no errors) or
- a combination of VARIANT_* values. */
- unsigned err;
-} variant;
-
-/* Set when the variant refers to a symbol hidden
- by an explicit symbol reference. */
-#define VARIANT_HIDDEN (1 << 0)
-
-/* Set when the variant refers to a symbol containing
- dots or dashes. Will require explicit bracketing. */
-#define VARIANT_BAD_BRACKETING (1 << 1)
-
-/* Set when the variant refers to a symbol which is
- not visible from current midrule. */
-#define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2)
-
-static variant *variant_table = NULL;
-static unsigned variant_table_size = 0;
-static unsigned variant_count = 0;
-
-static variant *
-variant_table_grow (void)
-{
- ++variant_count;
- if (variant_count > variant_table_size)
- {
- while (variant_count > variant_table_size)
- variant_table_size = 2 * variant_table_size + 3;
- variant_table = xnrealloc (variant_table, variant_table_size,
- sizeof *variant_table);
- }
- return &variant_table[variant_count - 1];
-}
-
-static void
-variant_table_free (void)
-{
- free (variant_table);
- variant_table = NULL;
- variant_table_size = variant_count = 0;
-}
-
-static char *
-find_prefix_end (const char *prefix, char *begin, char *end)
-{
- char *ptr = begin;
-
- for (; *prefix && ptr != end; ++prefix, ++ptr)
- if (*prefix != *ptr)
- return 0;
-
- if (*prefix)
- return 0;
-
- return ptr;
-}
-
-static variant *
-variant_add (uniqstr id, location id_loc, unsigned symbol_index,
- char *cp, char *cp_end, bool explicit_bracketing)
-{
- char *prefix_end;
-
- prefix_end = find_prefix_end (id, cp, cp_end);
- if (prefix_end &&
- (prefix_end == cp_end ||
- (!explicit_bracketing && is_dot_or_dash (*prefix_end))))
- {
- variant *r = variant_table_grow ();
- r->symbol_index = symbol_index;
- r->id = id;
- r->loc = id_loc;
- r->hidden_by = NULL;
- r->err = 0;
- return r;
- }
- else
- return NULL;
-}
-
-static const char *
-get_at_spec(unsigned symbol_index)
-{
- static char at_buf[20];
- if (symbol_index == 0)
- strcpy (at_buf, "$$");
- else
- snprintf (at_buf, sizeof at_buf, "$%u", symbol_index);
- return at_buf;
-}
-
-static void
-show_sub_message (warnings warning,
- const char* cp, bool explicit_bracketing,
- int midrule_rhs_index, char dollar_or_at,
- unsigned indent, const variant *var)
-{
- const char *at_spec = get_at_spec (var->symbol_index);
-
- if (var->err == 0)
- complain_indent (&var->loc, warning, &indent,
- _("refers to: %c%s at %s"), dollar_or_at,
- var->id, at_spec);
- else
- {
- static struct obstack msg_buf;
- const char *tail = explicit_bracketing ? "" : cp + strlen (var->id);
- const char *id = var->hidden_by ? var->hidden_by->id : var->id;
- location id_loc = var->hidden_by ? var->hidden_by->loc : var->loc;
-
- /* Create the explanation message. */
- obstack_init (&msg_buf);
-
- obstack_printf (&msg_buf, _("possibly meant: %c"), dollar_or_at);
- if (contains_dot_or_dash (id))
- obstack_printf (&msg_buf, "[%s]", id);
- else
- obstack_sgrow (&msg_buf, id);
- obstack_sgrow (&msg_buf, tail);
-
- if (var->err & VARIANT_HIDDEN)
- {
- obstack_printf (&msg_buf, _(", hiding %c"), dollar_or_at);
- if (contains_dot_or_dash (var->id))
- obstack_printf (&msg_buf, "[%s]", var->id);
- else
- obstack_sgrow (&msg_buf, var->id);
- obstack_sgrow (&msg_buf, tail);
- }
-
- obstack_printf (&msg_buf, _(" at %s"), at_spec);
-
- if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
- obstack_printf (&msg_buf,
- _(", cannot be accessed from mid-rule action at $%d"),
- midrule_rhs_index);
-
- complain_indent (&id_loc, warning, &indent, "%s",
- obstack_finish0 (&msg_buf));
- obstack_free (&msg_buf, 0);
- }
-}
-
-static void
-show_sub_messages (warnings warning,
- const char* cp, bool explicit_bracketing,
- int midrule_rhs_index, char dollar_or_at,
- unsigned indent)
-{
- unsigned i;
-
- for (i = 0; i < variant_count; ++i)
- show_sub_message (warning | silent,
- cp, explicit_bracketing,
- midrule_rhs_index, dollar_or_at,
- indent, &variant_table[i]);
-}
-
-/* Returned from "parse_ref" when the reference
- is inappropriate. */
-#define INVALID_REF (INT_MIN)
-
-/* Returned from "parse_ref" when the reference
- points to LHS ($$) of the current rule or midrule. */
-#define LHS_REF (INT_MIN + 1)
-
-/* Parse named or positional reference. In case of positional
- references, can return negative values for $-n "deep" stack
- accesses. */
-static long int
-parse_ref (char *cp, symbol_list *rule, int rule_length,
- int midrule_rhs_index, char *text, location text_loc,
- char dollar_or_at)
-{
- symbol_list *l;
- char *cp_end;
- bool explicit_bracketing;
- unsigned i;
- unsigned valid_variants = 0;
- unsigned valid_variant_index = 0;
-
- if ('$' == *cp)
- return LHS_REF;
-
- if (c_isdigit (*cp) || (*cp == '-' && c_isdigit (* (cp + 1))))
- {
- long int num = strtol (cp, &cp, 10);
- if (1 - INT_MAX + rule_length <= num && num <= rule_length)
- return num;
- else
- {
- complain (&text_loc, complaint, _("integer out of range: %s"),
- quote (text));
- return INVALID_REF;
- }
- }
-
- if ('[' == *cp)
- {
- /* Ignore the brackets. */
- char *p;
- for (p = ++cp; *p != ']'; ++p)
- continue;
- cp_end = p;
-
- explicit_bracketing = true;
- }
- else
- {
- /* Take all characters of the name. */
- char* p;
- for (p = cp; *p; ++p)
- if (is_dot_or_dash (*p))
- {
- ref_tail_fields = p;
- break;
- }
- for (p = cp; *p; ++p)
- continue;
- cp_end = p;
-
- explicit_bracketing = false;
- }
-
- /* Add all relevant variants. */
- {
- unsigned symbol_index;
- variant_count = 0;
- for (symbol_index = 0, l = rule; !symbol_list_null (l);
- ++symbol_index, l = l->next)
- {
- variant *var;
- if (l->content_type != SYMLIST_SYMBOL)
- continue;
-
- var = variant_add (l->content.sym->tag, l->sym_loc,
- symbol_index, cp, cp_end, explicit_bracketing);
- if (var && l->named_ref)
- var->hidden_by = l->named_ref;
-
- if (l->named_ref)
- variant_add (l->named_ref->id, l->named_ref->loc,
- symbol_index, cp, cp_end, explicit_bracketing);
- }
- }
-
- /* Check errors. */
- for (i = 0; i < variant_count; ++i)
- {
- variant *var = &variant_table[i];
- unsigned symbol_index = var->symbol_index;
-
- /* Check visibility from mid-rule actions. */
- if (midrule_rhs_index != 0
- && (symbol_index == 0 || midrule_rhs_index < symbol_index))
- var->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE;
-
- /* Check correct bracketing. */
- if (!explicit_bracketing && contains_dot_or_dash (var->id))
- var->err |= VARIANT_BAD_BRACKETING;
-
- /* Check using of hidden symbols. */
- if (var->hidden_by)
- var->err |= VARIANT_HIDDEN;
-
- if (!var->err)
- {
- valid_variant_index = i;
- ++valid_variants;
- }
- }
-
- switch (valid_variants)
- {
- case 0:
- {
- unsigned len = (explicit_bracketing || !ref_tail_fields) ?
- cp_end - cp : ref_tail_fields - cp;
- unsigned indent = 0;
-
- complain_indent (&text_loc, complaint, &indent,
- _("invalid reference: %s"), quote (text));
- indent += SUB_INDENT;
- if (len == 0)
- {
- location sym_loc = text_loc;
- sym_loc.start.column += 1;
- sym_loc.end = sym_loc.start;
- complain_indent (&sym_loc, complaint, &indent,
- _("syntax error after '%c', expecting integer, "
- "letter, '_', '[', or '$'"),
- dollar_or_at);
- }
- else if (midrule_rhs_index)
- complain_indent (&rule->location, complaint, &indent,
- _("symbol not found in production before $%d: "
- "%.*s"),
- midrule_rhs_index, len, cp);
- else
- complain_indent (&rule->location, complaint, &indent,
- _("symbol not found in production: %.*s"),
- len, cp);
-
- if (variant_count > 0)
- show_sub_messages (complaint,
- cp, explicit_bracketing, midrule_rhs_index,
- dollar_or_at, indent);
- return INVALID_REF;
- }
- case 1:
- {
- unsigned indent = 0;
- if (variant_count > 1)
- {
- complain_indent (&text_loc, Wother, &indent,
- _("misleading reference: %s"), quote (text));
- show_sub_messages (Wother,
- cp, explicit_bracketing, midrule_rhs_index,
- dollar_or_at, indent + SUB_INDENT);
- }
- {
- unsigned symbol_index =
- variant_table[valid_variant_index].symbol_index;
- return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index;
- }
- }
- case 2:
- default:
- {
- unsigned indent = 0;
- complain_indent (&text_loc, complaint, &indent,
- _("ambiguous reference: %s"), quote (text));
- show_sub_messages (complaint,
- cp, explicit_bracketing, midrule_rhs_index,
- dollar_or_at, indent + SUB_INDENT);
- return INVALID_REF;
- }
- }
-
- /* Not reachable. */
- return INVALID_REF;
-}
-
-/* Keeps track of the maximum number of semantic values to the left of
- a handle (those referenced by $0, $-1, etc.) are required by the
- semantic actions of this grammar. */
-int max_left_semantic_context = 0;
-
-
-/* If CP points to a typename (i.e., <.*?>), set TYPE_NAME to its
- beginning (i.e., after the opening "<", and return the pointer
- immediately after it. */
-
-static
-char *
-fetch_type_name (char *cp, char const **type_name,
- location dollar_loc)
-{
- if (*cp == '<')
- {
- *type_name = ++cp;
- /* Series of non-'>' or "->". */
- while (*cp != '>' || cp[-1] == '-')
- ++cp;
-
- /* The '>' symbol will be later replaced by '\0'. Original
- 'text' is needed for error messages. */
- ++cp;
- if (untyped_var_seen)
- complain (&dollar_loc, complaint,
- _("explicit type given in untyped grammar"));
- tag_seen = true;
- }
- return cp;
-}
-
-/*------------------------------------------------------------------.
-| TEXT is pointing to a wannabee semantic value (i.e., a '$'). |
-| |
-| Possible inputs: $[<TYPENAME>]($|integer) |
-| |
-| Output to OBSTACK_FOR_STRING a reference to this semantic value. |
-`------------------------------------------------------------------*/
-
-static void
-handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
-{
- char const *type_name = NULL;
- char *cp = text + 1;
- symbol_list *effective_rule;
- int effective_rule_length;
- int n;
-
- if (rule->midrule_parent_rule)
- {
- effective_rule = rule->midrule_parent_rule;
- effective_rule_length = rule->midrule_parent_rhs_index - 1;
- }
- else
- {
- effective_rule = rule;
- effective_rule_length = symbol_list_length (rule->next);
- }
-
- /* Get the type name if explicit. */
- cp = fetch_type_name (cp, &type_name, dollar_loc);
-
- n = parse_ref (cp, effective_rule, effective_rule_length,
- rule->midrule_parent_rhs_index, text, dollar_loc, '$');
-
- /* End type_name. */
- if (type_name)
- cp[-1] = '\0';
-
- switch (n)
- {
- case INVALID_REF:
- break;
-
- case LHS_REF:
- if (!type_name)
- type_name = symbol_list_n_type_name_get (rule, dollar_loc, 0);
-
- if (!type_name)
- {
- if (union_seen | tag_seen)
- {
- if (rule->midrule_parent_rule)
- complain (&dollar_loc, complaint,
- _("$$ for the midrule at $%d of %s"
- " has no declared type"),
- rule->midrule_parent_rhs_index,
- quote (effective_rule->content.sym->tag));
- else
- complain (&dollar_loc, complaint,
- _("$$ of %s has no declared type"),
- quote (rule->content.sym->tag));
- }
- else
- untyped_var_seen = true;
- }
-
- obstack_sgrow (&obstack_for_string, "]b4_lhs_value(");
- obstack_quote (&obstack_for_string, type_name);
- obstack_sgrow (&obstack_for_string, ")[");
- rule->action_props.is_value_used = true;
- break;
-
- default:
- if (max_left_semantic_context < 1 - n)
- max_left_semantic_context = 1 - n;
- if (!type_name && 0 < n)
- type_name =
- symbol_list_n_type_name_get (effective_rule, dollar_loc, n);
- if (!type_name)
- {
- if (union_seen | tag_seen)
- complain (&dollar_loc, complaint,
- _("$%s of %s has no declared type"), cp,
- quote (effective_rule->content.sym->tag));
- else
- untyped_var_seen = true;
- }
-
- obstack_printf (&obstack_for_string,
- "]b4_rhs_value(%d, %d, ", effective_rule_length, n);
- obstack_quote (&obstack_for_string, type_name);
- obstack_sgrow (&obstack_for_string, ")[");
- if (n > 0)
- symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
- true;
- break;
- }
-}
-
-
-/*------------------------------------------------------.
-| TEXT is a location token (i.e., a '@...'). Output to |
-| OBSTACK_FOR_STRING a reference to this location. |
-`------------------------------------------------------*/
-
-static void
-handle_action_at (symbol_list *rule, char *text, location at_loc)
-{
- char *cp = text + 1;
- symbol_list *effective_rule;
- int effective_rule_length;
- int n;
-
- if (rule->midrule_parent_rule)
- {
- effective_rule = rule->midrule_parent_rule;
- effective_rule_length = rule->midrule_parent_rhs_index - 1;
- }
- else
- {
- effective_rule = rule;
- effective_rule_length = symbol_list_length (rule->next);
- }
-
- muscle_percent_define_ensure("locations", at_loc, true);
-
- n = parse_ref (cp, effective_rule, effective_rule_length,
- rule->midrule_parent_rhs_index, text, at_loc, '@');
- switch (n)
- {
- case INVALID_REF:
- break;
-
- case LHS_REF:
- obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");
- break;
-
- default:
- obstack_printf (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
- effective_rule_length, n);
- break;
- }
-}
-
-
-/*-------------------------.
-| Initialize the scanner. |
-`-------------------------*/
-
-/* Translate the dollars and ats in \a self, in the context \a sc_context
- (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */
-
-static char const *
-translate_action (code_props *self, int sc_context)
-{
- char *res;
- static bool initialized = false;
- if (!initialized)
- {
- obstack_init (&obstack_for_string);
- code__flex_debug = 0;
- initialized = true;
- }
-
- loc->start = loc->end = self->location.start;
- code__switch_to_buffer (code__scan_string (self->code));
- res = code_lex (self, sc_context);
- code__delete_buffer (YY_CURRENT_BUFFER);
-
- return res;
-}
-
-/*------------------------------------------------------------------------.
-| Implementation of the public interface as documented in "scan-code.h". |
-`------------------------------------------------------------------------*/
-
-void
-code_props_none_init (code_props *self)
-{
- *self = code_props_none;
-}
-
-code_props code_props_none = CODE_PROPS_NONE_INIT;
-
-void
-code_props_plain_init (code_props *self, char const *code,
- location code_loc)
-{
- code_props_none_init (self);
- self->kind = CODE_PROPS_PLAIN;
- self->code = code;
- self->location = code_loc;
-}
-
-void
-code_props_symbol_action_init (code_props *self, char const *code,
- location code_loc)
-{
- code_props_none_init (self);
- self->kind = CODE_PROPS_SYMBOL_ACTION;
- self->code = code;
- self->location = code_loc;
-}
-
-void
-code_props_rule_action_init (code_props *self, char const *code,
- location code_loc, symbol_list *rule,
- named_ref *name, bool is_predicate)
-{
- code_props_none_init (self);
- self->kind = CODE_PROPS_RULE_ACTION;
- self->code = code;
- self->location = code_loc;
- self->rule = rule;
- self->named_ref = name;
- self->is_predicate = is_predicate;
-}
-
-void
-code_props_translate_code (code_props *self)
-{
- switch (self->kind)
- {
- case CODE_PROPS_NONE:
- break;
- case CODE_PROPS_PLAIN:
- self->code = translate_action (self, INITIAL);
- break;
- case CODE_PROPS_SYMBOL_ACTION:
- self->code = translate_action (self, SC_SYMBOL_ACTION);
- break;
- case CODE_PROPS_RULE_ACTION:
- self->code = translate_action (self, SC_RULE_ACTION);
- break;
- }
-}
-
-void
-code_scanner_last_string_free (void)
-{
- STRING_FREE;
-}
-
-void
-code_scanner_free (void)
-{
- obstack_free (&obstack_for_string, 0);
- variant_table_free ();
-
- /* Reclaim Flex's buffers. */
- code_lex_destroy ();
-}
-
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * code__scan_bytes() instead.
+ */
+YY_BUFFER_STATE code__scan_string (yyconst char * yystr )
+{
+
+ return code__scan_bytes(yystr,strlen(yystr) );
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan the given bytes. The next call to code_lex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE code__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) code_alloc(n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in code__scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = code__scan_buffer(buf,n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in code__scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+/* %endif */
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+/* %if-c-only */
+static void yy_fatal_error (yyconst char* msg )
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up code_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ code_text[code_leng] = (yy_hold_char); \
+ (yy_c_buf_p) = code_text + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ code_leng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/* %if-c-only */
+/* %if-reentrant */
+/* %endif */
+
+/** Get the current line number.
+ *
+ */
+int code_get_lineno (void)
+{
+
+ return code_lineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *code_get_in (void)
+{
+ return code_in;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *code_get_out (void)
+{
+ return code_out;
+}
+
+/** Get the length of the current token.
+ *
+ */
+yy_size_t code_get_leng (void)
+{
+ return code_leng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *code_get_text (void)
+{
+ return code_text;
+}
+
+/* %if-reentrant */
+/* %endif */
+
+/** Set the current line number.
+ * @param line_number
+ *
+ */
+void code_set_lineno (int line_number )
+{
+
+ code_lineno = line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ *
+ * @see code__switch_to_buffer
+ */
+void code_set_in (FILE * in_str )
+{
+ code_in = in_str ;
+}
+
+void code_set_out (FILE * out_str )
+{
+ code_out = out_str ;
+}
+
+int code_get_debug (void)
+{
+ return code__flex_debug;
+}
+
+void code_set_debug (int bdebug )
+{
+ code__flex_debug = bdebug ;
+}
+
+/* %endif */
+
+/* %if-reentrant */
+/* %if-bison-bridge */
+/* %endif */
+/* %endif if-c-only */
+
+/* %if-c-only */
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from code_lex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = 0;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = (char *) 0;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ code_in = stdin;
+ code_out = stdout;
+#else
+ code_in = (FILE *) 0;
+ code_out = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * code_lex_init()
+ */
+ return 0;
+}
+/* %endif */
+
+/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
+/* code_lex_destroy is for both reentrant and non-reentrant scanners. */
+int code_lex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ code__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ code_pop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ code_free((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * code_lex() is called, initialization will occur. */
+ yy_init_globals( );
+
+/* %if-reentrant */
+/* %endif */
+ return 0;
+}
+/* %endif */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *code_alloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *code_realloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void code_free (void * ptr )
+{
+ free( (char *) ptr ); /* see code_realloc() for (char *) cast */
+}
+
+/* %if-tables-serialization definitions */
+/* %define-yytables The name for this specific scanner's tables. */
+#define YYTABLES_NAME "yytables"
+/* %endif */
+
+/* %ok-for-header */
+
+#line 207 "../../src/scan-code.l"
+
+
+
+static inline bool
+is_dot_or_dash (char ch)
+{
+ return ch == '.' || ch == '-';
+}
+
+static inline bool
+contains_dot_or_dash (const char* p)
+{
+ for (; *p; ++p)
+ if (is_dot_or_dash (*p))
+ return true;
+ return false;
+}
+
+/* Defines a variant of a symbolic name resolution. */
+typedef struct
+{
+ /* Index in symbol list. */
+ unsigned symbol_index;
+
+ /* Matched symbol id and loc. */
+ uniqstr id;
+ location loc;
+
+ /* Hiding named reference. */
+ named_ref* hidden_by;
+
+ /* Error flags. May contain zero (no errors) or
+ a combination of VARIANT_* values. */
+ unsigned err;
+} variant;
+
+/* Set when the variant refers to a symbol hidden
+ by an explicit symbol reference. */
+#define VARIANT_HIDDEN (1 << 0)
+
+/* Set when the variant refers to a symbol containing
+ dots or dashes. Will require explicit bracketing. */
+#define VARIANT_BAD_BRACKETING (1 << 1)
+
+/* Set when the variant refers to a symbol which is
+ not visible from current midrule. */
+#define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2)
+
+static variant *variant_table = NULL;
+static unsigned variant_table_size = 0;
+static unsigned variant_count = 0;
+
+static variant *
+variant_table_grow (void)
+{
+ ++variant_count;
+ if (variant_count > variant_table_size)
+ {
+ while (variant_count > variant_table_size)
+ variant_table_size = 2 * variant_table_size + 3;
+ variant_table = xnrealloc (variant_table, variant_table_size,
+ sizeof *variant_table);
+ }
+ return &variant_table[variant_count - 1];
+}
+
+static void
+variant_table_free (void)
+{
+ free (variant_table);
+ variant_table = NULL;
+ variant_table_size = variant_count = 0;
+}
+
+static char *
+find_prefix_end (const char *prefix, char *begin, char *end)
+{
+ char *ptr = begin;
+
+ for (; *prefix && ptr != end; ++prefix, ++ptr)
+ if (*prefix != *ptr)
+ return 0;
+
+ if (*prefix)
+ return 0;
+
+ return ptr;
+}
+
+static variant *
+variant_add (uniqstr id, location id_loc, unsigned symbol_index,
+ char *cp, char *cp_end, bool explicit_bracketing)
+{
+ char *prefix_end;
+
+ prefix_end = find_prefix_end (id, cp, cp_end);
+ if (prefix_end &&
+ (prefix_end == cp_end ||
+ (!explicit_bracketing && is_dot_or_dash (*prefix_end))))
+ {
+ variant *r = variant_table_grow ();
+ r->symbol_index = symbol_index;
+ r->id = id;
+ r->loc = id_loc;
+ r->hidden_by = NULL;
+ r->err = 0;
+ return r;
+ }
+ else
+ return NULL;
+}
+
+static const char *
+get_at_spec(unsigned symbol_index)
+{
+ static char at_buf[20];
+ if (symbol_index == 0)
+ strcpy (at_buf, "$$");
+ else
+ snprintf (at_buf, sizeof at_buf, "$%u", symbol_index);
+ return at_buf;
+}
+
+static void
+show_sub_message (warnings warning,
+ const char* cp, bool explicit_bracketing,
+ int midrule_rhs_index, char dollar_or_at,
+ unsigned indent, const variant *var)
+{
+ const char *at_spec = get_at_spec (var->symbol_index);
+
+ if (var->err == 0)
+ complain_indent (&var->loc, warning, &indent,
+ _("refers to: %c%s at %s"), dollar_or_at,
+ var->id, at_spec);
+ else
+ {
+ static struct obstack msg_buf;
+ const char *tail = explicit_bracketing ? "" : cp + strlen (var->id);
+ const char *id = var->hidden_by ? var->hidden_by->id : var->id;
+ location id_loc = var->hidden_by ? var->hidden_by->loc : var->loc;
+
+ /* Create the explanation message. */
+ obstack_init (&msg_buf);
+
+ obstack_printf (&msg_buf, _("possibly meant: %c"), dollar_or_at);
+ if (contains_dot_or_dash (id))
+ obstack_printf (&msg_buf, "[%s]", id);
+ else
+ obstack_sgrow (&msg_buf, id);
+ obstack_sgrow (&msg_buf, tail);
+
+ if (var->err & VARIANT_HIDDEN)
+ {
+ obstack_printf (&msg_buf, _(", hiding %c"), dollar_or_at);
+ if (contains_dot_or_dash (var->id))
+ obstack_printf (&msg_buf, "[%s]", var->id);
+ else
+ obstack_sgrow (&msg_buf, var->id);
+ obstack_sgrow (&msg_buf, tail);
+ }
+
+ obstack_printf (&msg_buf, _(" at %s"), at_spec);
+
+ if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
+ obstack_printf (&msg_buf,
+ _(", cannot be accessed from mid-rule action at $%d"),
+ midrule_rhs_index);
+
+ complain_indent (&id_loc, warning, &indent, "%s",
+ obstack_finish0 (&msg_buf));
+ obstack_free (&msg_buf, 0);
+ }
+}
+
+static void
+show_sub_messages (warnings warning,
+ const char* cp, bool explicit_bracketing,
+ int midrule_rhs_index, char dollar_or_at,
+ unsigned indent)
+{
+ unsigned i;
+
+ for (i = 0; i < variant_count; ++i)
+ show_sub_message (warning | silent,
+ cp, explicit_bracketing,
+ midrule_rhs_index, dollar_or_at,
+ indent, &variant_table[i]);
+}
+
+/* Returned from "parse_ref" when the reference
+ is inappropriate. */
+#define INVALID_REF (INT_MIN)
+
+/* Returned from "parse_ref" when the reference
+ points to LHS ($$) of the current rule or midrule. */
+#define LHS_REF (INT_MIN + 1)
+
+/* Parse named or positional reference. In case of positional
+ references, can return negative values for $-n "deep" stack
+ accesses. */
+static long int
+parse_ref (char *cp, symbol_list *rule, int rule_length,
+ int midrule_rhs_index, char *text, location text_loc,
+ char dollar_or_at)
+{
+ symbol_list *l;
+ char *cp_end;
+ bool explicit_bracketing;
+ unsigned i;
+ unsigned valid_variants = 0;
+ unsigned valid_variant_index = 0;
+
+ if ('$' == *cp)
+ return LHS_REF;
+
+ if (c_isdigit (*cp) || (*cp == '-' && c_isdigit (* (cp + 1))))
+ {
+ long int num = strtol (cp, &cp, 10);
+ if (1 - INT_MAX + rule_length <= num && num <= rule_length)
+ return num;
+ else
+ {
+ complain (&text_loc, complaint, _("integer out of range: %s"),
+ quote (text));
+ return INVALID_REF;
+ }
+ }
+
+ if ('[' == *cp)
+ {
+ /* Ignore the brackets. */
+ char *p;
+ for (p = ++cp; *p != ']'; ++p)
+ continue;
+ cp_end = p;
+
+ explicit_bracketing = true;
+ }
+ else
+ {
+ /* Take all characters of the name. */
+ char* p;
+ for (p = cp; *p; ++p)
+ if (is_dot_or_dash (*p))
+ {
+ ref_tail_fields = p;
+ break;
+ }
+ for (p = cp; *p; ++p)
+ continue;
+ cp_end = p;
+
+ explicit_bracketing = false;
+ }
+
+ /* Add all relevant variants. */
+ {
+ unsigned symbol_index;
+ variant_count = 0;
+ for (symbol_index = 0, l = rule; !symbol_list_null (l);
+ ++symbol_index, l = l->next)
+ {
+ variant *var;
+ if (l->content_type != SYMLIST_SYMBOL)
+ continue;
+
+ var = variant_add (l->content.sym->tag, l->sym_loc,
+ symbol_index, cp, cp_end, explicit_bracketing);
+ if (var && l->named_ref)
+ var->hidden_by = l->named_ref;
+
+ if (l->named_ref)
+ variant_add (l->named_ref->id, l->named_ref->loc,
+ symbol_index, cp, cp_end, explicit_bracketing);
+ }
+ }
+
+ /* Check errors. */
+ for (i = 0; i < variant_count; ++i)
+ {
+ variant *var = &variant_table[i];
+ unsigned symbol_index = var->symbol_index;
+
+ /* Check visibility from mid-rule actions. */
+ if (midrule_rhs_index != 0
+ && (symbol_index == 0 || midrule_rhs_index < symbol_index))
+ var->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE;
+
+ /* Check correct bracketing. */
+ if (!explicit_bracketing && contains_dot_or_dash (var->id))
+ var->err |= VARIANT_BAD_BRACKETING;
+
+ /* Check using of hidden symbols. */
+ if (var->hidden_by)
+ var->err |= VARIANT_HIDDEN;
+
+ if (!var->err)
+ {
+ valid_variant_index = i;
+ ++valid_variants;
+ }
+ }
+
+ switch (valid_variants)
+ {
+ case 0:
+ {
+ unsigned len = (explicit_bracketing || !ref_tail_fields) ?
+ cp_end - cp : ref_tail_fields - cp;
+ unsigned indent = 0;
+
+ complain_indent (&text_loc, complaint, &indent,
+ _("invalid reference: %s"), quote (text));
+ indent += SUB_INDENT;
+ if (len == 0)
+ {
+ location sym_loc = text_loc;
+ sym_loc.start.column += 1;
+ sym_loc.end = sym_loc.start;
+ complain_indent (&sym_loc, complaint, &indent,
+ _("syntax error after '%c', expecting integer, "
+ "letter, '_', '[', or '$'"),
+ dollar_or_at);
+ }
+ else if (midrule_rhs_index)
+ complain_indent (&rule->location, complaint, &indent,
+ _("symbol not found in production before $%d: "
+ "%.*s"),
+ midrule_rhs_index, len, cp);
+ else
+ complain_indent (&rule->location, complaint, &indent,
+ _("symbol not found in production: %.*s"),
+ len, cp);
+
+ if (variant_count > 0)
+ show_sub_messages (complaint,
+ cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, indent);
+ return INVALID_REF;
+ }
+ case 1:
+ {
+ unsigned indent = 0;
+ if (variant_count > 1)
+ {
+ complain_indent (&text_loc, Wother, &indent,
+ _("misleading reference: %s"), quote (text));
+ show_sub_messages (Wother,
+ cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, indent + SUB_INDENT);
+ }
+ {
+ unsigned symbol_index =
+ variant_table[valid_variant_index].symbol_index;
+ return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index;
+ }
+ }
+ case 2:
+ default:
+ {
+ unsigned indent = 0;
+ complain_indent (&text_loc, complaint, &indent,
+ _("ambiguous reference: %s"), quote (text));
+ show_sub_messages (complaint,
+ cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, indent + SUB_INDENT);
+ return INVALID_REF;
+ }
+ }
+
+ /* Not reachable. */
+ return INVALID_REF;
+}
+
+/* Keeps track of the maximum number of semantic values to the left of
+ a handle (those referenced by $0, $-1, etc.) are required by the
+ semantic actions of this grammar. */
+int max_left_semantic_context = 0;
+
+
+/* If CP points to a typename (i.e., <.*?>), set TYPE_NAME to its
+ beginning (i.e., after the opening "<", and return the pointer
+ immediately after it. */
+
+static
+char *
+fetch_type_name (char *cp, char const **type_name,
+ location dollar_loc)
+{
+ if (*cp == '<')
+ {
+ *type_name = ++cp;
+ /* Series of non-'>' or "->". */
+ while (*cp != '>' || cp[-1] == '-')
+ ++cp;
+
+ /* The '>' symbol will be later replaced by '\0'. Original
+ 'text' is needed for error messages. */
+ ++cp;
+ if (untyped_var_seen)
+ complain (&dollar_loc, complaint,
+ _("explicit type given in untyped grammar"));
+ tag_seen = true;
+ }
+ return cp;
+}
+
+/*------------------------------------------------------------------.
+| TEXT is pointing to a wannabee semantic value (i.e., a '$'). |
+| |
+| Possible inputs: $[<TYPENAME>]($|integer) |
+| |
+| Output to OBSTACK_FOR_STRING a reference to this semantic value. |
+`------------------------------------------------------------------*/
+
+static void
+handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
+{
+ char const *type_name = NULL;
+ char *cp = text + 1;
+ symbol_list *effective_rule;
+ int effective_rule_length;
+ int n;
+
+ if (rule->midrule_parent_rule)
+ {
+ effective_rule = rule->midrule_parent_rule;
+ effective_rule_length = rule->midrule_parent_rhs_index - 1;
+ }
+ else
+ {
+ effective_rule = rule;
+ effective_rule_length = symbol_list_length (rule->next);
+ }
+
+ /* Get the type name if explicit. */
+ cp = fetch_type_name (cp, &type_name, dollar_loc);
+
+ n = parse_ref (cp, effective_rule, effective_rule_length,
+ rule->midrule_parent_rhs_index, text, dollar_loc, '$');
+
+ /* End type_name. */
+ if (type_name)
+ cp[-1] = '\0';
+
+ switch (n)
+ {
+ case INVALID_REF:
+ break;
+
+ case LHS_REF:
+ if (!type_name)
+ type_name = symbol_list_n_type_name_get (rule, dollar_loc, 0);
+
+ if (!type_name)
+ {
+ if (union_seen | tag_seen)
+ {
+ if (rule->midrule_parent_rule)
+ complain (&dollar_loc, complaint,
+ _("$$ for the midrule at $%d of %s"
+ " has no declared type"),
+ rule->midrule_parent_rhs_index,
+ quote (effective_rule->content.sym->tag));
+ else
+ complain (&dollar_loc, complaint,
+ _("$$ of %s has no declared type"),
+ quote (rule->content.sym->tag));
+ }
+ else
+ untyped_var_seen = true;
+ }
+
+ obstack_sgrow (&obstack_for_string, "]b4_lhs_value(");
+ obstack_quote (&obstack_for_string, type_name);
+ obstack_sgrow (&obstack_for_string, ")[");
+ rule->action_props.is_value_used = true;
+ break;
+
+ default:
+ if (max_left_semantic_context < 1 - n)
+ max_left_semantic_context = 1 - n;
+ if (!type_name && 0 < n)
+ type_name =
+ symbol_list_n_type_name_get (effective_rule, dollar_loc, n);
+ if (!type_name)
+ {
+ if (union_seen | tag_seen)
+ complain (&dollar_loc, complaint,
+ _("$%s of %s has no declared type"), cp,
+ quote (effective_rule->content.sym->tag));
+ else
+ untyped_var_seen = true;
+ }
+
+ obstack_printf (&obstack_for_string,
+ "]b4_rhs_value(%d, %d, ", effective_rule_length, n);
+ obstack_quote (&obstack_for_string, type_name);
+ obstack_sgrow (&obstack_for_string, ")[");
+ if (n > 0)
+ symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
+ true;
+ break;
+ }
+}
+
+
+/*------------------------------------------------------.
+| TEXT is a location token (i.e., a '@...'). Output to |
+| OBSTACK_FOR_STRING a reference to this location. |
+`------------------------------------------------------*/
+
+static void
+handle_action_at (symbol_list *rule, char *text, location at_loc)
+{
+ char *cp = text + 1;
+ symbol_list *effective_rule;
+ int effective_rule_length;
+ int n;
+
+ if (rule->midrule_parent_rule)
+ {
+ effective_rule = rule->midrule_parent_rule;
+ effective_rule_length = rule->midrule_parent_rhs_index - 1;
+ }
+ else
+ {
+ effective_rule = rule;
+ effective_rule_length = symbol_list_length (rule->next);
+ }
+
+ muscle_percent_define_ensure("locations", at_loc, true);
+
+ n = parse_ref (cp, effective_rule, effective_rule_length,
+ rule->midrule_parent_rhs_index, text, at_loc, '@');
+ switch (n)
+ {
+ case INVALID_REF:
+ break;
+
+ case LHS_REF:
+ obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");
+ break;
+
+ default:
+ obstack_printf (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
+ effective_rule_length, n);
+ break;
+ }
+}
+
+
+/*-------------------------.
+| Initialize the scanner. |
+`-------------------------*/
+
+/* Translate the dollars and ats in \a self, in the context \a sc_context
+ (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */
+
+static char const *
+translate_action (code_props *self, int sc_context)
+{
+ char *res;
+ static bool initialized = false;
+ if (!initialized)
+ {
+ obstack_init (&obstack_for_string);
+ code__flex_debug = 0;
+ initialized = true;
+ }
+
+ loc->start = loc->end = self->location.start;
+ code__switch_to_buffer (code__scan_string (self->code));
+ res = code_lex (self, sc_context);
+ code__delete_buffer (YY_CURRENT_BUFFER);
+
+ return res;
+}
+
+/*------------------------------------------------------------------------.
+| Implementation of the public interface as documented in "scan-code.h". |
+`------------------------------------------------------------------------*/
+
+void
+code_props_none_init (code_props *self)
+{
+ *self = code_props_none;
+}
+
+code_props code_props_none = CODE_PROPS_NONE_INIT;
+
+void
+code_props_plain_init (code_props *self, char const *code,
+ location code_loc)
+{
+ code_props_none_init (self);
+ self->kind = CODE_PROPS_PLAIN;
+ self->code = code;
+ self->location = code_loc;
+}
+
+void
+code_props_symbol_action_init (code_props *self, char const *code,
+ location code_loc)
+{
+ code_props_none_init (self);
+ self->kind = CODE_PROPS_SYMBOL_ACTION;
+ self->code = code;
+ self->location = code_loc;
+}
+
+void
+code_props_rule_action_init (code_props *self, char const *code,
+ location code_loc, symbol_list *rule,
+ named_ref *name, bool is_predicate)
+{
+ code_props_none_init (self);
+ self->kind = CODE_PROPS_RULE_ACTION;
+ self->code = code;
+ self->location = code_loc;
+ self->rule = rule;
+ self->named_ref = name;
+ self->is_predicate = is_predicate;
+}
+
+void
+code_props_translate_code (code_props *self)
+{
+ switch (self->kind)
+ {
+ case CODE_PROPS_NONE:
+ break;
+ case CODE_PROPS_PLAIN:
+ self->code = translate_action (self, INITIAL);
+ break;
+ case CODE_PROPS_SYMBOL_ACTION:
+ self->code = translate_action (self, SC_SYMBOL_ACTION);
+ break;
+ case CODE_PROPS_RULE_ACTION:
+ self->code = translate_action (self, SC_RULE_ACTION);
+ break;
+ }
+}
+
+void
+code_scanner_last_string_free (void)
+{
+ STRING_FREE;
+}
+
+void
+code_scanner_free (void)
+{
+ obstack_free (&obstack_for_string, 0);
+ variant_table_free ();
+
+ /* Reclaim Flex's buffers. */
+ code_lex_destroy ();
+}
+
diff --git a/contrib/tools/bison/bison/src/scan-code.h b/contrib/tools/bison/bison/src/scan-code.h
index d5a15c1a1c..304fefe21a 100644
--- a/contrib/tools/bison/bison/src/scan-code.h
+++ b/contrib/tools/bison/bison/src/scan-code.h
@@ -1,196 +1,196 @@
-/* Bison code properties structure and scanner.
-
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SCAN_CODE_H_
-# define SCAN_CODE_H_
-
-# include "location.h"
-# include "named-ref.h"
-
-struct symbol_list;
-
-/**
- * Keeps track of the maximum number of semantic values to the left of a handle
- * (those referenced by $0, $-1, etc.) that are required by the semantic
- * actions of this grammar.
- */
-extern int max_left_semantic_context;
-
-/**
- * A code passage captured from the grammar file and possibly translated,
- * and/or properties associated with such a code passage. Don't break
- * encapsulation by modifying the fields directly. Use the provided interface
- * functions.
- */
-typedef struct code_props {
- /** Set by the init functions. */
- enum {
- CODE_PROPS_NONE, CODE_PROPS_PLAIN,
- CODE_PROPS_SYMBOL_ACTION, CODE_PROPS_RULE_ACTION
- } kind;
-
- /**
- * \c NULL iff \c code_props::kind is \c CODE_PROPS_NONE.
- * Memory is allocated in an obstack freed elsewhere.
- */
- char const *code;
- /** Undefined iff \c code_props::code is \c NULL. */
- location location;
-
- /**
- * \c false iff either:
- * - \c code_props_translate_code has never previously been invoked for
- * the \c code_props that would contain the code passage associated
- * with \c self. (That \c code_props is not the same as this one if this
- * one is for a RHS \c symbol_list node. Instead, it's the \c code_props
- * for the LHS symbol of the same rule.)
- * - \c code_props_translate_code has been invoked for that \c code_props,
- * but the symbol value associated with this \c code_props was not
- * referenced in the code passage.
- */
- bool is_value_used;
-
- /**
- * \c true iff this code is an action that is not to be deferred in
- * a non-deterministic parser.
- */
- bool is_predicate;
-
- /**
- * Whether this is actually used (i.e., not completely masked by
- * other code props). */
- bool is_used;
-
- /** \c NULL iff \c code_props::kind is not \c CODE_PROPS_RULE_ACTION. */
- struct symbol_list *rule;
-
- /* Named reference. */
- named_ref *named_ref;
-} code_props;
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * \post
- * - \c self has been overwritten to contain no code.
- */
-void code_props_none_init (code_props *self);
-
-/** Equivalent to \c code_props_none_init. */
-# define CODE_PROPS_NONE_INIT \
- { \
- /* .kind = */ CODE_PROPS_NONE, \
- /* .code = */ NULL, \
- /* .location = */ EMPTY_LOCATION_INIT, \
- /* .is_value_used = */ false, \
- /* .is_predicate = */ false, \
- /* .is_used = */ false, \
- /* .rule = */ NULL, \
- /* .named_ref = */ NULL \
- }
-
-/** Initialized by \c CODE_PROPS_NONE_INIT with no further modification. */
-extern code_props code_props_none;
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - <tt>code != NULL</tt>.
- * - \c code is an untranslated code passage containing no Bison escapes.
- * - \c code was extracted from the grammar file at \c code_loc.
- * \post
- * - \c self has been overwritten to represent the specified plain code
- * passage.
- * - \c self will become invalid if the caller frees \c code before invoking
- * \c code_props_translate_code on \c self.
- */
-void code_props_plain_init (code_props *self, char const *code,
- location code_loc);
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - <tt>code != NULL</tt>.
- * - \c code is an untranslated code passage. The only Bison escapes it
- * might contain are $$ and \@$, referring to a single symbol.
- * - \c code was extracted from the grammar file at \c code_loc.
- * \post
- * - \c self has been overwritten to represent the specified symbol action.
- * - \c self will become invalid if the caller frees \c code before invoking
- * \c code_props_translate_code on \c self.
- */
-void code_props_symbol_action_init (code_props *self, char const *code,
- location code_loc);
-
-/**
- * \pre
- * - <tt>self != NULL</tt>.
- * - <tt>code != NULL</tt>.
- * - <tt>rule != NULL</tt>.
- * - \c code is the untranslated action of the rule for which \c rule is the
- * LHS node. Thus, \c code possibly contains Bison escapes such as $$, $1,
- * $2, etc referring to the values of the rule.
- * - \c code was extracted from the grammar file at \c code_loc.
- * \post
- * - \c self has been overwritten to represent the specified rule action.
- * - \c self does not claim responsibility for the memory of \c rule.
- * - \c self will become invalid if:
- * - The caller frees \c code before invoking \c code_props_translate_code
- * on \c self.
- * - The caller frees \c rule.
- */
-void code_props_rule_action_init (code_props *self, char const *code,
- location code_loc, struct symbol_list *rule,
- named_ref *name, bool is_predicate);
-
-/**
- * \pre
- * - If there's a code passage contained in \c self and it contains Bison
- * escapes, all grammar declarations have already been parsed as they may
- * affect warnings and complaints issued here.
- * \post
- * - All M4-special symbols and Bison escapes have been translated in
- * \c self->code.
- * - <tt>self->code != self->code\@pre</tt> unless
- * <tt>self->code\@pre = NULL</tt>.
- */
-void code_props_translate_code (code_props *self);
-
-/**
- * \pre
- * - None.
- * \post
- * - The dynamic memory allocated by the previous invocation of
- * \c code_props_translate_code (if any) was freed. The \c code_props
- * instance for which \c code_props_translate_code was invoked is now
- * invalid.
- */
-void code_scanner_last_string_free (void);
-
-/**
- * \pre
- * - None.
- * \post
- * - All dynamic memory allocated during invocations of
- * \c code_props_translate_code (if any) has been freed. All \c code_props
- * instances may now be invalid.
- */
-void code_scanner_free (void);
-
-#endif /* !SCAN_CODE_H_ */
+/* Bison code properties structure and scanner.
+
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SCAN_CODE_H_
+# define SCAN_CODE_H_
+
+# include "location.h"
+# include "named-ref.h"
+
+struct symbol_list;
+
+/**
+ * Keeps track of the maximum number of semantic values to the left of a handle
+ * (those referenced by $0, $-1, etc.) that are required by the semantic
+ * actions of this grammar.
+ */
+extern int max_left_semantic_context;
+
+/**
+ * A code passage captured from the grammar file and possibly translated,
+ * and/or properties associated with such a code passage. Don't break
+ * encapsulation by modifying the fields directly. Use the provided interface
+ * functions.
+ */
+typedef struct code_props {
+ /** Set by the init functions. */
+ enum {
+ CODE_PROPS_NONE, CODE_PROPS_PLAIN,
+ CODE_PROPS_SYMBOL_ACTION, CODE_PROPS_RULE_ACTION
+ } kind;
+
+ /**
+ * \c NULL iff \c code_props::kind is \c CODE_PROPS_NONE.
+ * Memory is allocated in an obstack freed elsewhere.
+ */
+ char const *code;
+ /** Undefined iff \c code_props::code is \c NULL. */
+ location location;
+
+ /**
+ * \c false iff either:
+ * - \c code_props_translate_code has never previously been invoked for
+ * the \c code_props that would contain the code passage associated
+ * with \c self. (That \c code_props is not the same as this one if this
+ * one is for a RHS \c symbol_list node. Instead, it's the \c code_props
+ * for the LHS symbol of the same rule.)
+ * - \c code_props_translate_code has been invoked for that \c code_props,
+ * but the symbol value associated with this \c code_props was not
+ * referenced in the code passage.
+ */
+ bool is_value_used;
+
+ /**
+ * \c true iff this code is an action that is not to be deferred in
+ * a non-deterministic parser.
+ */
+ bool is_predicate;
+
+ /**
+ * Whether this is actually used (i.e., not completely masked by
+ * other code props). */
+ bool is_used;
+
+ /** \c NULL iff \c code_props::kind is not \c CODE_PROPS_RULE_ACTION. */
+ struct symbol_list *rule;
+
+ /* Named reference. */
+ named_ref *named_ref;
+} code_props;
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * \post
+ * - \c self has been overwritten to contain no code.
+ */
+void code_props_none_init (code_props *self);
+
+/** Equivalent to \c code_props_none_init. */
+# define CODE_PROPS_NONE_INIT \
+ { \
+ /* .kind = */ CODE_PROPS_NONE, \
+ /* .code = */ NULL, \
+ /* .location = */ EMPTY_LOCATION_INIT, \
+ /* .is_value_used = */ false, \
+ /* .is_predicate = */ false, \
+ /* .is_used = */ false, \
+ /* .rule = */ NULL, \
+ /* .named_ref = */ NULL \
+ }
+
+/** Initialized by \c CODE_PROPS_NONE_INIT with no further modification. */
+extern code_props code_props_none;
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>code != NULL</tt>.
+ * - \c code is an untranslated code passage containing no Bison escapes.
+ * - \c code was extracted from the grammar file at \c code_loc.
+ * \post
+ * - \c self has been overwritten to represent the specified plain code
+ * passage.
+ * - \c self will become invalid if the caller frees \c code before invoking
+ * \c code_props_translate_code on \c self.
+ */
+void code_props_plain_init (code_props *self, char const *code,
+ location code_loc);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>code != NULL</tt>.
+ * - \c code is an untranslated code passage. The only Bison escapes it
+ * might contain are $$ and \@$, referring to a single symbol.
+ * - \c code was extracted from the grammar file at \c code_loc.
+ * \post
+ * - \c self has been overwritten to represent the specified symbol action.
+ * - \c self will become invalid if the caller frees \c code before invoking
+ * \c code_props_translate_code on \c self.
+ */
+void code_props_symbol_action_init (code_props *self, char const *code,
+ location code_loc);
+
+/**
+ * \pre
+ * - <tt>self != NULL</tt>.
+ * - <tt>code != NULL</tt>.
+ * - <tt>rule != NULL</tt>.
+ * - \c code is the untranslated action of the rule for which \c rule is the
+ * LHS node. Thus, \c code possibly contains Bison escapes such as $$, $1,
+ * $2, etc referring to the values of the rule.
+ * - \c code was extracted from the grammar file at \c code_loc.
+ * \post
+ * - \c self has been overwritten to represent the specified rule action.
+ * - \c self does not claim responsibility for the memory of \c rule.
+ * - \c self will become invalid if:
+ * - The caller frees \c code before invoking \c code_props_translate_code
+ * on \c self.
+ * - The caller frees \c rule.
+ */
+void code_props_rule_action_init (code_props *self, char const *code,
+ location code_loc, struct symbol_list *rule,
+ named_ref *name, bool is_predicate);
+
+/**
+ * \pre
+ * - If there's a code passage contained in \c self and it contains Bison
+ * escapes, all grammar declarations have already been parsed as they may
+ * affect warnings and complaints issued here.
+ * \post
+ * - All M4-special symbols and Bison escapes have been translated in
+ * \c self->code.
+ * - <tt>self->code != self->code\@pre</tt> unless
+ * <tt>self->code\@pre = NULL</tt>.
+ */
+void code_props_translate_code (code_props *self);
+
+/**
+ * \pre
+ * - None.
+ * \post
+ * - The dynamic memory allocated by the previous invocation of
+ * \c code_props_translate_code (if any) was freed. The \c code_props
+ * instance for which \c code_props_translate_code was invoked is now
+ * invalid.
+ */
+void code_scanner_last_string_free (void);
+
+/**
+ * \pre
+ * - None.
+ * \post
+ * - All dynamic memory allocated during invocations of
+ * \c code_props_translate_code (if any) has been freed. All \c code_props
+ * instances may now be invalid.
+ */
+void code_scanner_free (void);
+
+#endif /* !SCAN_CODE_H_ */
diff --git a/contrib/tools/bison/bison/src/scan-code.l b/contrib/tools/bison/bison/src/scan-code.l
index cced97bfea..d1c523489e 100644
--- a/contrib/tools/bison/bison/src/scan-code.l
+++ b/contrib/tools/bison/bison/src/scan-code.l
@@ -1,865 +1,865 @@
-/* Bison Action Scanner -*- C -*-
-
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-%option debug nodefault noinput nounput noyywrap never-interactive
-%option prefix="code_" outfile="lex.yy.c"
-
-%{
-/* Work around a bug in flex 2.5.31. See Debian bug 333231
- <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
-#undef code_wrap
-#define code_wrap() 1
-
-#define FLEX_PREFIX(Id) code_ ## Id
-#include <src/flex-scanner.h>
-
-#include <src/complain.h>
-#include <src/reader.h>
-#include <src/getargs.h>
-#include <src/muscle-tab.h>
-#include <src/scan-code.h>
-#include <src/symlist.h>
-
-#include <c-ctype.h>
-#include <get-errno.h>
-#include <quote.h>
-
-/* The current calling start condition: SC_RULE_ACTION or
- SC_SYMBOL_ACTION. */
-# define YY_DECL static char *code_lex (code_props *self, int sc_context)
-YY_DECL;
-
-#define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng);
-
-static char *fetch_type_name (char *cp, char const **type_name,
- location dollar_loc);
-
-static void handle_action_dollar (symbol_list *rule, char *cp,
- location dollar_loc);
-static void handle_action_at (symbol_list *rule, char *cp, location at_loc);
-
-/* A string to be pushed to obstack after dollar/at has been handled. */
-static char *ref_tail_fields;
-
-static location the_location;
-static location *loc = &the_location;
-
-/* A string representing the most recent translation. */
-static char *last_string;
-
-/* True if an untyped $$ or $n was seen. */
-static bool untyped_var_seen;
-
-%}
- /* C and C++ comments in code. */
-%x SC_COMMENT SC_LINE_COMMENT
- /* Strings and characters in code. */
-%x SC_STRING SC_CHARACTER
- /* Whether in a rule or symbol action. Specifies the translation
- of $ and @. */
-%x SC_RULE_ACTION SC_SYMBOL_ACTION
-
-
-/* POSIX says that a tag must be both an id and a C union member, but
- historically almost any character is allowed in a tag. We disallow
- NUL and newline, as this simplifies our implementation. We allow
- "->" as a means to dereference a pointer. */
-tag ([^\0\n>]|->)+
-
-/* Zero or more instances of backslash-newline. Following GCC, allow
- white space between the backslash and the newline. */
-splice (\\[ \f\t\v]*\n)*
-
-/* C style identifier. Must start with letter. Will be used for
- named symbol references. Shall be kept synchronized with
- scan-gram.l "letter" and "id". */
-letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
-id {letter}({letter}|[-0-9])*
-ref -?[0-9]+|{id}|"["{id}"]"|"$"
-
-%%
-
-%{
- /* This scanner is special: it is invoked only once, henceforth
- is expected to return only once. This initialization is
- therefore done once per action to translate. */
- aver (sc_context == SC_SYMBOL_ACTION
- || sc_context == SC_RULE_ACTION
- || sc_context == INITIAL);
- BEGIN sc_context;
-%}
-
- /*------------------------------------------------------------.
- | Scanning a C comment. The initial '/ *' is already eaten. |
- `------------------------------------------------------------*/
-
-<SC_COMMENT>
-{
- "*"{splice}"/" STRING_GROW; BEGIN sc_context;
-}
-
-
- /*--------------------------------------------------------------.
- | Scanning a line comment. The initial '//' is already eaten. |
- `--------------------------------------------------------------*/
-
-<SC_LINE_COMMENT>
-{
- "\n" STRING_GROW; BEGIN sc_context;
- {splice} STRING_GROW;
-}
-
-
- /*--------------------------------------------.
- | Scanning user-code characters and strings. |
- `--------------------------------------------*/
-
-<SC_CHARACTER,SC_STRING>
-{
- {splice}|\\{splice}. STRING_GROW;
-}
-
-<SC_CHARACTER>
-{
- "'" STRING_GROW; BEGIN sc_context;
-}
-
-<SC_STRING>
-{
- "\"" STRING_GROW; BEGIN sc_context;
-}
-
-
-<SC_RULE_ACTION,SC_SYMBOL_ACTION>
-{
- "'" STRING_GROW; BEGIN SC_CHARACTER;
- "\"" STRING_GROW; BEGIN SC_STRING;
- "/"{splice}"*" STRING_GROW; BEGIN SC_COMMENT;
- "/"{splice}"/" STRING_GROW; BEGIN SC_LINE_COMMENT;
-
- [$@] {
- complain (loc, Wother, _("stray '%s'"), yytext);
- obstack_escape (&obstack_for_string, yytext);
- }
-}
-
-<SC_RULE_ACTION>
-{
- "$"("<"{tag}">")?{ref} {
- ref_tail_fields = NULL;
- handle_action_dollar (self->rule, yytext, *loc);
- if (ref_tail_fields)
- obstack_sgrow (&obstack_for_string, ref_tail_fields);
- }
- "@"{ref} {
- ref_tail_fields = NULL;
- handle_action_at (self->rule, yytext, *loc);
- if (ref_tail_fields)
- obstack_sgrow (&obstack_for_string, ref_tail_fields);
- }
-}
-
-<SC_SYMBOL_ACTION>
-{
- "$"("<"{tag}">")?"$" {
- const char *type_name = NULL;
- fetch_type_name (yytext + 1, &type_name, *loc)[-1] = 0;
- obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
- obstack_quote (&obstack_for_string, type_name);
- obstack_sgrow (&obstack_for_string, ")[");
- self->is_value_used = true;
- }
- "@$" {
- obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
- muscle_percent_define_ensure("locations", the_location, true);
- }
-}
-
-
-<*>
-{
- /* Escape M4 quoting characters in C code. */
- [$@\[\]] obstack_escape (&obstack_for_string, yytext);
-
- /* By default, grow the string obstack with the input. */
- .|\n STRING_GROW;
-
- /* End of processing. */
- <<EOF>> STRING_FINISH; return last_string;
-}
-
-%%
-
-static inline bool
-is_dot_or_dash (char ch)
-{
- return ch == '.' || ch == '-';
-}
-
-static inline bool
-contains_dot_or_dash (const char* p)
-{
- for (; *p; ++p)
- if (is_dot_or_dash (*p))
- return true;
- return false;
-}
-
-/* Defines a variant of a symbolic name resolution. */
-typedef struct
-{
- /* Index in symbol list. */
- unsigned symbol_index;
-
- /* Matched symbol id and loc. */
- uniqstr id;
- location loc;
-
- /* Hiding named reference. */
- named_ref* hidden_by;
-
- /* Error flags. May contain zero (no errors) or
- a combination of VARIANT_* values. */
- unsigned err;
-} variant;
-
-/* Set when the variant refers to a symbol hidden
- by an explicit symbol reference. */
-#define VARIANT_HIDDEN (1 << 0)
-
-/* Set when the variant refers to a symbol containing
- dots or dashes. Will require explicit bracketing. */
-#define VARIANT_BAD_BRACKETING (1 << 1)
-
-/* Set when the variant refers to a symbol which is
- not visible from current midrule. */
-#define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2)
-
-static variant *variant_table = NULL;
-static unsigned variant_table_size = 0;
-static unsigned variant_count = 0;
-
-static variant *
-variant_table_grow (void)
-{
- ++variant_count;
- if (variant_count > variant_table_size)
- {
- while (variant_count > variant_table_size)
- variant_table_size = 2 * variant_table_size + 3;
- variant_table = xnrealloc (variant_table, variant_table_size,
- sizeof *variant_table);
- }
- return &variant_table[variant_count - 1];
-}
-
-static void
-variant_table_free (void)
-{
- free (variant_table);
- variant_table = NULL;
- variant_table_size = variant_count = 0;
-}
-
-static char *
-find_prefix_end (const char *prefix, char *begin, char *end)
-{
- char *ptr = begin;
-
- for (; *prefix && ptr != end; ++prefix, ++ptr)
- if (*prefix != *ptr)
- return 0;
-
- if (*prefix)
- return 0;
-
- return ptr;
-}
-
-static variant *
-variant_add (uniqstr id, location id_loc, unsigned symbol_index,
- char *cp, char *cp_end, bool explicit_bracketing)
-{
- char *prefix_end;
-
- prefix_end = find_prefix_end (id, cp, cp_end);
- if (prefix_end &&
- (prefix_end == cp_end ||
- (!explicit_bracketing && is_dot_or_dash (*prefix_end))))
- {
- variant *r = variant_table_grow ();
- r->symbol_index = symbol_index;
- r->id = id;
- r->loc = id_loc;
- r->hidden_by = NULL;
- r->err = 0;
- return r;
- }
- else
- return NULL;
-}
-
-static const char *
-get_at_spec(unsigned symbol_index)
-{
- static char at_buf[20];
- if (symbol_index == 0)
- strcpy (at_buf, "$$");
- else
- snprintf (at_buf, sizeof at_buf, "$%u", symbol_index);
- return at_buf;
-}
-
-static void
-show_sub_message (warnings warning,
- const char* cp, bool explicit_bracketing,
- int midrule_rhs_index, char dollar_or_at,
- unsigned indent, const variant *var)
-{
- const char *at_spec = get_at_spec (var->symbol_index);
-
- if (var->err == 0)
- complain_indent (&var->loc, warning, &indent,
- _("refers to: %c%s at %s"), dollar_or_at,
- var->id, at_spec);
- else
- {
- static struct obstack msg_buf;
- const char *tail = explicit_bracketing ? "" : cp + strlen (var->id);
- const char *id = var->hidden_by ? var->hidden_by->id : var->id;
- location id_loc = var->hidden_by ? var->hidden_by->loc : var->loc;
-
- /* Create the explanation message. */
- obstack_init (&msg_buf);
-
- obstack_printf (&msg_buf, _("possibly meant: %c"), dollar_or_at);
- if (contains_dot_or_dash (id))
- obstack_printf (&msg_buf, "[%s]", id);
- else
- obstack_sgrow (&msg_buf, id);
- obstack_sgrow (&msg_buf, tail);
-
- if (var->err & VARIANT_HIDDEN)
- {
- obstack_printf (&msg_buf, _(", hiding %c"), dollar_or_at);
- if (contains_dot_or_dash (var->id))
- obstack_printf (&msg_buf, "[%s]", var->id);
- else
- obstack_sgrow (&msg_buf, var->id);
- obstack_sgrow (&msg_buf, tail);
- }
-
- obstack_printf (&msg_buf, _(" at %s"), at_spec);
-
- if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
- obstack_printf (&msg_buf,
- _(", cannot be accessed from mid-rule action at $%d"),
- midrule_rhs_index);
-
- complain_indent (&id_loc, warning, &indent, "%s",
- obstack_finish0 (&msg_buf));
- obstack_free (&msg_buf, 0);
- }
-}
-
-static void
-show_sub_messages (warnings warning,
- const char* cp, bool explicit_bracketing,
- int midrule_rhs_index, char dollar_or_at,
- unsigned indent)
-{
- unsigned i;
-
- for (i = 0; i < variant_count; ++i)
- show_sub_message (warning | silent,
- cp, explicit_bracketing,
- midrule_rhs_index, dollar_or_at,
- indent, &variant_table[i]);
-}
-
-/* Returned from "parse_ref" when the reference
- is inappropriate. */
-#define INVALID_REF (INT_MIN)
-
-/* Returned from "parse_ref" when the reference
- points to LHS ($$) of the current rule or midrule. */
-#define LHS_REF (INT_MIN + 1)
-
-/* Parse named or positional reference. In case of positional
- references, can return negative values for $-n "deep" stack
- accesses. */
-static long int
-parse_ref (char *cp, symbol_list *rule, int rule_length,
- int midrule_rhs_index, char *text, location text_loc,
- char dollar_or_at)
-{
- symbol_list *l;
- char *cp_end;
- bool explicit_bracketing;
- unsigned i;
- unsigned valid_variants = 0;
- unsigned valid_variant_index = 0;
-
- if ('$' == *cp)
- return LHS_REF;
-
- if (c_isdigit (*cp) || (*cp == '-' && c_isdigit (* (cp + 1))))
- {
- long int num = strtol (cp, &cp, 10);
- if (1 - INT_MAX + rule_length <= num && num <= rule_length)
- return num;
- else
- {
- complain (&text_loc, complaint, _("integer out of range: %s"),
- quote (text));
- return INVALID_REF;
- }
- }
-
- if ('[' == *cp)
- {
- /* Ignore the brackets. */
- char *p;
- for (p = ++cp; *p != ']'; ++p)
- continue;
- cp_end = p;
-
- explicit_bracketing = true;
- }
- else
- {
- /* Take all characters of the name. */
- char* p;
- for (p = cp; *p; ++p)
- if (is_dot_or_dash (*p))
- {
- ref_tail_fields = p;
- break;
- }
- for (p = cp; *p; ++p)
- continue;
- cp_end = p;
-
- explicit_bracketing = false;
- }
-
- /* Add all relevant variants. */
- {
- unsigned symbol_index;
- variant_count = 0;
- for (symbol_index = 0, l = rule; !symbol_list_null (l);
- ++symbol_index, l = l->next)
- {
- variant *var;
- if (l->content_type != SYMLIST_SYMBOL)
- continue;
-
- var = variant_add (l->content.sym->tag, l->sym_loc,
- symbol_index, cp, cp_end, explicit_bracketing);
- if (var && l->named_ref)
- var->hidden_by = l->named_ref;
-
- if (l->named_ref)
- variant_add (l->named_ref->id, l->named_ref->loc,
- symbol_index, cp, cp_end, explicit_bracketing);
- }
- }
-
- /* Check errors. */
- for (i = 0; i < variant_count; ++i)
- {
- variant *var = &variant_table[i];
- unsigned symbol_index = var->symbol_index;
-
- /* Check visibility from mid-rule actions. */
- if (midrule_rhs_index != 0
- && (symbol_index == 0 || midrule_rhs_index < symbol_index))
- var->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE;
-
- /* Check correct bracketing. */
- if (!explicit_bracketing && contains_dot_or_dash (var->id))
- var->err |= VARIANT_BAD_BRACKETING;
-
- /* Check using of hidden symbols. */
- if (var->hidden_by)
- var->err |= VARIANT_HIDDEN;
-
- if (!var->err)
- {
- valid_variant_index = i;
- ++valid_variants;
- }
- }
-
- switch (valid_variants)
- {
- case 0:
- {
- unsigned len = (explicit_bracketing || !ref_tail_fields) ?
- cp_end - cp : ref_tail_fields - cp;
- unsigned indent = 0;
-
- complain_indent (&text_loc, complaint, &indent,
- _("invalid reference: %s"), quote (text));
- indent += SUB_INDENT;
- if (len == 0)
- {
- location sym_loc = text_loc;
- sym_loc.start.column += 1;
- sym_loc.end = sym_loc.start;
- complain_indent (&sym_loc, complaint, &indent,
- _("syntax error after '%c', expecting integer, "
- "letter, '_', '[', or '$'"),
- dollar_or_at);
- }
- else if (midrule_rhs_index)
- complain_indent (&rule->location, complaint, &indent,
- _("symbol not found in production before $%d: "
- "%.*s"),
- midrule_rhs_index, len, cp);
- else
- complain_indent (&rule->location, complaint, &indent,
- _("symbol not found in production: %.*s"),
- len, cp);
-
- if (variant_count > 0)
- show_sub_messages (complaint,
- cp, explicit_bracketing, midrule_rhs_index,
- dollar_or_at, indent);
- return INVALID_REF;
- }
- case 1:
- {
- unsigned indent = 0;
- if (variant_count > 1)
- {
- complain_indent (&text_loc, Wother, &indent,
- _("misleading reference: %s"), quote (text));
- show_sub_messages (Wother,
- cp, explicit_bracketing, midrule_rhs_index,
- dollar_or_at, indent + SUB_INDENT);
- }
- {
- unsigned symbol_index =
- variant_table[valid_variant_index].symbol_index;
- return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index;
- }
- }
- case 2:
- default:
- {
- unsigned indent = 0;
- complain_indent (&text_loc, complaint, &indent,
- _("ambiguous reference: %s"), quote (text));
- show_sub_messages (complaint,
- cp, explicit_bracketing, midrule_rhs_index,
- dollar_or_at, indent + SUB_INDENT);
- return INVALID_REF;
- }
- }
-
- /* Not reachable. */
- return INVALID_REF;
-}
-
-/* Keeps track of the maximum number of semantic values to the left of
- a handle (those referenced by $0, $-1, etc.) are required by the
- semantic actions of this grammar. */
-int max_left_semantic_context = 0;
-
-
-/* If CP points to a typename (i.e., <.*?>), set TYPE_NAME to its
- beginning (i.e., after the opening "<", and return the pointer
- immediately after it. */
-
-static
-char *
-fetch_type_name (char *cp, char const **type_name,
- location dollar_loc)
-{
- if (*cp == '<')
- {
- *type_name = ++cp;
- /* Series of non-'>' or "->". */
- while (*cp != '>' || cp[-1] == '-')
- ++cp;
-
- /* The '>' symbol will be later replaced by '\0'. Original
- 'text' is needed for error messages. */
- ++cp;
- if (untyped_var_seen)
- complain (&dollar_loc, complaint,
- _("explicit type given in untyped grammar"));
- tag_seen = true;
- }
- return cp;
-}
-
-/*------------------------------------------------------------------.
-| TEXT is pointing to a wannabee semantic value (i.e., a '$'). |
-| |
-| Possible inputs: $[<TYPENAME>]($|integer) |
-| |
-| Output to OBSTACK_FOR_STRING a reference to this semantic value. |
-`------------------------------------------------------------------*/
-
-static void
-handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
-{
- char const *type_name = NULL;
- char *cp = text + 1;
- symbol_list *effective_rule;
- int effective_rule_length;
- int n;
-
- if (rule->midrule_parent_rule)
- {
- effective_rule = rule->midrule_parent_rule;
- effective_rule_length = rule->midrule_parent_rhs_index - 1;
- }
- else
- {
- effective_rule = rule;
- effective_rule_length = symbol_list_length (rule->next);
- }
-
- /* Get the type name if explicit. */
- cp = fetch_type_name (cp, &type_name, dollar_loc);
-
- n = parse_ref (cp, effective_rule, effective_rule_length,
- rule->midrule_parent_rhs_index, text, dollar_loc, '$');
-
- /* End type_name. */
- if (type_name)
- cp[-1] = '\0';
-
- switch (n)
- {
- case INVALID_REF:
- break;
-
- case LHS_REF:
- if (!type_name)
- type_name = symbol_list_n_type_name_get (rule, dollar_loc, 0);
-
- if (!type_name)
- {
- if (union_seen | tag_seen)
- {
- if (rule->midrule_parent_rule)
- complain (&dollar_loc, complaint,
- _("$$ for the midrule at $%d of %s"
- " has no declared type"),
- rule->midrule_parent_rhs_index,
- quote (effective_rule->content.sym->tag));
- else
- complain (&dollar_loc, complaint,
- _("$$ of %s has no declared type"),
- quote (rule->content.sym->tag));
- }
- else
- untyped_var_seen = true;
- }
-
- obstack_sgrow (&obstack_for_string, "]b4_lhs_value(");
- obstack_quote (&obstack_for_string, type_name);
- obstack_sgrow (&obstack_for_string, ")[");
- rule->action_props.is_value_used = true;
- break;
-
- default:
- if (max_left_semantic_context < 1 - n)
- max_left_semantic_context = 1 - n;
- if (!type_name && 0 < n)
- type_name =
- symbol_list_n_type_name_get (effective_rule, dollar_loc, n);
- if (!type_name)
- {
- if (union_seen | tag_seen)
- complain (&dollar_loc, complaint,
- _("$%s of %s has no declared type"), cp,
- quote (effective_rule->content.sym->tag));
- else
- untyped_var_seen = true;
- }
-
- obstack_printf (&obstack_for_string,
- "]b4_rhs_value(%d, %d, ", effective_rule_length, n);
- obstack_quote (&obstack_for_string, type_name);
- obstack_sgrow (&obstack_for_string, ")[");
- if (n > 0)
- symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
- true;
- break;
- }
-}
-
-
-/*------------------------------------------------------.
-| TEXT is a location token (i.e., a '@...'). Output to |
-| OBSTACK_FOR_STRING a reference to this location. |
-`------------------------------------------------------*/
-
-static void
-handle_action_at (symbol_list *rule, char *text, location at_loc)
-{
- char *cp = text + 1;
- symbol_list *effective_rule;
- int effective_rule_length;
- int n;
-
- if (rule->midrule_parent_rule)
- {
- effective_rule = rule->midrule_parent_rule;
- effective_rule_length = rule->midrule_parent_rhs_index - 1;
- }
- else
- {
- effective_rule = rule;
- effective_rule_length = symbol_list_length (rule->next);
- }
-
- muscle_percent_define_ensure("locations", at_loc, true);
-
- n = parse_ref (cp, effective_rule, effective_rule_length,
- rule->midrule_parent_rhs_index, text, at_loc, '@');
- switch (n)
- {
- case INVALID_REF:
- break;
-
- case LHS_REF:
- obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");
- break;
-
- default:
- obstack_printf (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
- effective_rule_length, n);
- break;
- }
-}
-
-
-/*-------------------------.
-| Initialize the scanner. |
-`-------------------------*/
-
-/* Translate the dollars and ats in \a self, in the context \a sc_context
- (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */
-
-static char const *
-translate_action (code_props *self, int sc_context)
-{
- char *res;
- static bool initialized = false;
- if (!initialized)
- {
- obstack_init (&obstack_for_string);
- yy_flex_debug = 0;
- initialized = true;
- }
-
- loc->start = loc->end = self->location.start;
- yy_switch_to_buffer (yy_scan_string (self->code));
- res = code_lex (self, sc_context);
- yy_delete_buffer (YY_CURRENT_BUFFER);
-
- return res;
-}
-
-/*------------------------------------------------------------------------.
-| Implementation of the public interface as documented in "scan-code.h". |
-`------------------------------------------------------------------------*/
-
-void
-code_props_none_init (code_props *self)
-{
- *self = code_props_none;
-}
-
-code_props code_props_none = CODE_PROPS_NONE_INIT;
-
-void
-code_props_plain_init (code_props *self, char const *code,
- location code_loc)
-{
- code_props_none_init (self);
- self->kind = CODE_PROPS_PLAIN;
- self->code = code;
- self->location = code_loc;
-}
-
-void
-code_props_symbol_action_init (code_props *self, char const *code,
- location code_loc)
-{
- code_props_none_init (self);
- self->kind = CODE_PROPS_SYMBOL_ACTION;
- self->code = code;
- self->location = code_loc;
-}
-
-void
-code_props_rule_action_init (code_props *self, char const *code,
- location code_loc, symbol_list *rule,
- named_ref *name, bool is_predicate)
-{
- code_props_none_init (self);
- self->kind = CODE_PROPS_RULE_ACTION;
- self->code = code;
- self->location = code_loc;
- self->rule = rule;
- self->named_ref = name;
- self->is_predicate = is_predicate;
-}
-
-void
-code_props_translate_code (code_props *self)
-{
- switch (self->kind)
- {
- case CODE_PROPS_NONE:
- break;
- case CODE_PROPS_PLAIN:
- self->code = translate_action (self, INITIAL);
- break;
- case CODE_PROPS_SYMBOL_ACTION:
- self->code = translate_action (self, SC_SYMBOL_ACTION);
- break;
- case CODE_PROPS_RULE_ACTION:
- self->code = translate_action (self, SC_RULE_ACTION);
- break;
- }
-}
-
-void
-code_scanner_last_string_free (void)
-{
- STRING_FREE;
-}
-
-void
-code_scanner_free (void)
-{
- obstack_free (&obstack_for_string, 0);
- variant_table_free ();
-
- /* Reclaim Flex's buffers. */
- yylex_destroy ();
-}
+/* Bison Action Scanner -*- C -*-
+
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+%option debug nodefault noinput nounput noyywrap never-interactive
+%option prefix="code_" outfile="lex.yy.c"
+
+%{
+/* Work around a bug in flex 2.5.31. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+#undef code_wrap
+#define code_wrap() 1
+
+#define FLEX_PREFIX(Id) code_ ## Id
+#include <src/flex-scanner.h>
+
+#include <src/complain.h>
+#include <src/reader.h>
+#include <src/getargs.h>
+#include <src/muscle-tab.h>
+#include <src/scan-code.h>
+#include <src/symlist.h>
+
+#include <c-ctype.h>
+#include <get-errno.h>
+#include <quote.h>
+
+/* The current calling start condition: SC_RULE_ACTION or
+ SC_SYMBOL_ACTION. */
+# define YY_DECL static char *code_lex (code_props *self, int sc_context)
+YY_DECL;
+
+#define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng);
+
+static char *fetch_type_name (char *cp, char const **type_name,
+ location dollar_loc);
+
+static void handle_action_dollar (symbol_list *rule, char *cp,
+ location dollar_loc);
+static void handle_action_at (symbol_list *rule, char *cp, location at_loc);
+
+/* A string to be pushed to obstack after dollar/at has been handled. */
+static char *ref_tail_fields;
+
+static location the_location;
+static location *loc = &the_location;
+
+/* A string representing the most recent translation. */
+static char *last_string;
+
+/* True if an untyped $$ or $n was seen. */
+static bool untyped_var_seen;
+
+%}
+ /* C and C++ comments in code. */
+%x SC_COMMENT SC_LINE_COMMENT
+ /* Strings and characters in code. */
+%x SC_STRING SC_CHARACTER
+ /* Whether in a rule or symbol action. Specifies the translation
+ of $ and @. */
+%x SC_RULE_ACTION SC_SYMBOL_ACTION
+
+
+/* POSIX says that a tag must be both an id and a C union member, but
+ historically almost any character is allowed in a tag. We disallow
+ NUL and newline, as this simplifies our implementation. We allow
+ "->" as a means to dereference a pointer. */
+tag ([^\0\n>]|->)+
+
+/* Zero or more instances of backslash-newline. Following GCC, allow
+ white space between the backslash and the newline. */
+splice (\\[ \f\t\v]*\n)*
+
+/* C style identifier. Must start with letter. Will be used for
+ named symbol references. Shall be kept synchronized with
+ scan-gram.l "letter" and "id". */
+letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
+id {letter}({letter}|[-0-9])*
+ref -?[0-9]+|{id}|"["{id}"]"|"$"
+
+%%
+
+%{
+ /* This scanner is special: it is invoked only once, henceforth
+ is expected to return only once. This initialization is
+ therefore done once per action to translate. */
+ aver (sc_context == SC_SYMBOL_ACTION
+ || sc_context == SC_RULE_ACTION
+ || sc_context == INITIAL);
+ BEGIN sc_context;
+%}
+
+ /*------------------------------------------------------------.
+ | Scanning a C comment. The initial '/ *' is already eaten. |
+ `------------------------------------------------------------*/
+
+<SC_COMMENT>
+{
+ "*"{splice}"/" STRING_GROW; BEGIN sc_context;
+}
+
+
+ /*--------------------------------------------------------------.
+ | Scanning a line comment. The initial '//' is already eaten. |
+ `--------------------------------------------------------------*/
+
+<SC_LINE_COMMENT>
+{
+ "\n" STRING_GROW; BEGIN sc_context;
+ {splice} STRING_GROW;
+}
+
+
+ /*--------------------------------------------.
+ | Scanning user-code characters and strings. |
+ `--------------------------------------------*/
+
+<SC_CHARACTER,SC_STRING>
+{
+ {splice}|\\{splice}. STRING_GROW;
+}
+
+<SC_CHARACTER>
+{
+ "'" STRING_GROW; BEGIN sc_context;
+}
+
+<SC_STRING>
+{
+ "\"" STRING_GROW; BEGIN sc_context;
+}
+
+
+<SC_RULE_ACTION,SC_SYMBOL_ACTION>
+{
+ "'" STRING_GROW; BEGIN SC_CHARACTER;
+ "\"" STRING_GROW; BEGIN SC_STRING;
+ "/"{splice}"*" STRING_GROW; BEGIN SC_COMMENT;
+ "/"{splice}"/" STRING_GROW; BEGIN SC_LINE_COMMENT;
+
+ [$@] {
+ complain (loc, Wother, _("stray '%s'"), yytext);
+ obstack_escape (&obstack_for_string, yytext);
+ }
+}
+
+<SC_RULE_ACTION>
+{
+ "$"("<"{tag}">")?{ref} {
+ ref_tail_fields = NULL;
+ handle_action_dollar (self->rule, yytext, *loc);
+ if (ref_tail_fields)
+ obstack_sgrow (&obstack_for_string, ref_tail_fields);
+ }
+ "@"{ref} {
+ ref_tail_fields = NULL;
+ handle_action_at (self->rule, yytext, *loc);
+ if (ref_tail_fields)
+ obstack_sgrow (&obstack_for_string, ref_tail_fields);
+ }
+}
+
+<SC_SYMBOL_ACTION>
+{
+ "$"("<"{tag}">")?"$" {
+ const char *type_name = NULL;
+ fetch_type_name (yytext + 1, &type_name, *loc)[-1] = 0;
+ obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
+ obstack_quote (&obstack_for_string, type_name);
+ obstack_sgrow (&obstack_for_string, ")[");
+ self->is_value_used = true;
+ }
+ "@$" {
+ obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
+ muscle_percent_define_ensure("locations", the_location, true);
+ }
+}
+
+
+<*>
+{
+ /* Escape M4 quoting characters in C code. */
+ [$@\[\]] obstack_escape (&obstack_for_string, yytext);
+
+ /* By default, grow the string obstack with the input. */
+ .|\n STRING_GROW;
+
+ /* End of processing. */
+ <<EOF>> STRING_FINISH; return last_string;
+}
+
+%%
+
+static inline bool
+is_dot_or_dash (char ch)
+{
+ return ch == '.' || ch == '-';
+}
+
+static inline bool
+contains_dot_or_dash (const char* p)
+{
+ for (; *p; ++p)
+ if (is_dot_or_dash (*p))
+ return true;
+ return false;
+}
+
+/* Defines a variant of a symbolic name resolution. */
+typedef struct
+{
+ /* Index in symbol list. */
+ unsigned symbol_index;
+
+ /* Matched symbol id and loc. */
+ uniqstr id;
+ location loc;
+
+ /* Hiding named reference. */
+ named_ref* hidden_by;
+
+ /* Error flags. May contain zero (no errors) or
+ a combination of VARIANT_* values. */
+ unsigned err;
+} variant;
+
+/* Set when the variant refers to a symbol hidden
+ by an explicit symbol reference. */
+#define VARIANT_HIDDEN (1 << 0)
+
+/* Set when the variant refers to a symbol containing
+ dots or dashes. Will require explicit bracketing. */
+#define VARIANT_BAD_BRACKETING (1 << 1)
+
+/* Set when the variant refers to a symbol which is
+ not visible from current midrule. */
+#define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2)
+
+static variant *variant_table = NULL;
+static unsigned variant_table_size = 0;
+static unsigned variant_count = 0;
+
+static variant *
+variant_table_grow (void)
+{
+ ++variant_count;
+ if (variant_count > variant_table_size)
+ {
+ while (variant_count > variant_table_size)
+ variant_table_size = 2 * variant_table_size + 3;
+ variant_table = xnrealloc (variant_table, variant_table_size,
+ sizeof *variant_table);
+ }
+ return &variant_table[variant_count - 1];
+}
+
+static void
+variant_table_free (void)
+{
+ free (variant_table);
+ variant_table = NULL;
+ variant_table_size = variant_count = 0;
+}
+
+static char *
+find_prefix_end (const char *prefix, char *begin, char *end)
+{
+ char *ptr = begin;
+
+ for (; *prefix && ptr != end; ++prefix, ++ptr)
+ if (*prefix != *ptr)
+ return 0;
+
+ if (*prefix)
+ return 0;
+
+ return ptr;
+}
+
+static variant *
+variant_add (uniqstr id, location id_loc, unsigned symbol_index,
+ char *cp, char *cp_end, bool explicit_bracketing)
+{
+ char *prefix_end;
+
+ prefix_end = find_prefix_end (id, cp, cp_end);
+ if (prefix_end &&
+ (prefix_end == cp_end ||
+ (!explicit_bracketing && is_dot_or_dash (*prefix_end))))
+ {
+ variant *r = variant_table_grow ();
+ r->symbol_index = symbol_index;
+ r->id = id;
+ r->loc = id_loc;
+ r->hidden_by = NULL;
+ r->err = 0;
+ return r;
+ }
+ else
+ return NULL;
+}
+
+static const char *
+get_at_spec(unsigned symbol_index)
+{
+ static char at_buf[20];
+ if (symbol_index == 0)
+ strcpy (at_buf, "$$");
+ else
+ snprintf (at_buf, sizeof at_buf, "$%u", symbol_index);
+ return at_buf;
+}
+
+static void
+show_sub_message (warnings warning,
+ const char* cp, bool explicit_bracketing,
+ int midrule_rhs_index, char dollar_or_at,
+ unsigned indent, const variant *var)
+{
+ const char *at_spec = get_at_spec (var->symbol_index);
+
+ if (var->err == 0)
+ complain_indent (&var->loc, warning, &indent,
+ _("refers to: %c%s at %s"), dollar_or_at,
+ var->id, at_spec);
+ else
+ {
+ static struct obstack msg_buf;
+ const char *tail = explicit_bracketing ? "" : cp + strlen (var->id);
+ const char *id = var->hidden_by ? var->hidden_by->id : var->id;
+ location id_loc = var->hidden_by ? var->hidden_by->loc : var->loc;
+
+ /* Create the explanation message. */
+ obstack_init (&msg_buf);
+
+ obstack_printf (&msg_buf, _("possibly meant: %c"), dollar_or_at);
+ if (contains_dot_or_dash (id))
+ obstack_printf (&msg_buf, "[%s]", id);
+ else
+ obstack_sgrow (&msg_buf, id);
+ obstack_sgrow (&msg_buf, tail);
+
+ if (var->err & VARIANT_HIDDEN)
+ {
+ obstack_printf (&msg_buf, _(", hiding %c"), dollar_or_at);
+ if (contains_dot_or_dash (var->id))
+ obstack_printf (&msg_buf, "[%s]", var->id);
+ else
+ obstack_sgrow (&msg_buf, var->id);
+ obstack_sgrow (&msg_buf, tail);
+ }
+
+ obstack_printf (&msg_buf, _(" at %s"), at_spec);
+
+ if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE)
+ obstack_printf (&msg_buf,
+ _(", cannot be accessed from mid-rule action at $%d"),
+ midrule_rhs_index);
+
+ complain_indent (&id_loc, warning, &indent, "%s",
+ obstack_finish0 (&msg_buf));
+ obstack_free (&msg_buf, 0);
+ }
+}
+
+static void
+show_sub_messages (warnings warning,
+ const char* cp, bool explicit_bracketing,
+ int midrule_rhs_index, char dollar_or_at,
+ unsigned indent)
+{
+ unsigned i;
+
+ for (i = 0; i < variant_count; ++i)
+ show_sub_message (warning | silent,
+ cp, explicit_bracketing,
+ midrule_rhs_index, dollar_or_at,
+ indent, &variant_table[i]);
+}
+
+/* Returned from "parse_ref" when the reference
+ is inappropriate. */
+#define INVALID_REF (INT_MIN)
+
+/* Returned from "parse_ref" when the reference
+ points to LHS ($$) of the current rule or midrule. */
+#define LHS_REF (INT_MIN + 1)
+
+/* Parse named or positional reference. In case of positional
+ references, can return negative values for $-n "deep" stack
+ accesses. */
+static long int
+parse_ref (char *cp, symbol_list *rule, int rule_length,
+ int midrule_rhs_index, char *text, location text_loc,
+ char dollar_or_at)
+{
+ symbol_list *l;
+ char *cp_end;
+ bool explicit_bracketing;
+ unsigned i;
+ unsigned valid_variants = 0;
+ unsigned valid_variant_index = 0;
+
+ if ('$' == *cp)
+ return LHS_REF;
+
+ if (c_isdigit (*cp) || (*cp == '-' && c_isdigit (* (cp + 1))))
+ {
+ long int num = strtol (cp, &cp, 10);
+ if (1 - INT_MAX + rule_length <= num && num <= rule_length)
+ return num;
+ else
+ {
+ complain (&text_loc, complaint, _("integer out of range: %s"),
+ quote (text));
+ return INVALID_REF;
+ }
+ }
+
+ if ('[' == *cp)
+ {
+ /* Ignore the brackets. */
+ char *p;
+ for (p = ++cp; *p != ']'; ++p)
+ continue;
+ cp_end = p;
+
+ explicit_bracketing = true;
+ }
+ else
+ {
+ /* Take all characters of the name. */
+ char* p;
+ for (p = cp; *p; ++p)
+ if (is_dot_or_dash (*p))
+ {
+ ref_tail_fields = p;
+ break;
+ }
+ for (p = cp; *p; ++p)
+ continue;
+ cp_end = p;
+
+ explicit_bracketing = false;
+ }
+
+ /* Add all relevant variants. */
+ {
+ unsigned symbol_index;
+ variant_count = 0;
+ for (symbol_index = 0, l = rule; !symbol_list_null (l);
+ ++symbol_index, l = l->next)
+ {
+ variant *var;
+ if (l->content_type != SYMLIST_SYMBOL)
+ continue;
+
+ var = variant_add (l->content.sym->tag, l->sym_loc,
+ symbol_index, cp, cp_end, explicit_bracketing);
+ if (var && l->named_ref)
+ var->hidden_by = l->named_ref;
+
+ if (l->named_ref)
+ variant_add (l->named_ref->id, l->named_ref->loc,
+ symbol_index, cp, cp_end, explicit_bracketing);
+ }
+ }
+
+ /* Check errors. */
+ for (i = 0; i < variant_count; ++i)
+ {
+ variant *var = &variant_table[i];
+ unsigned symbol_index = var->symbol_index;
+
+ /* Check visibility from mid-rule actions. */
+ if (midrule_rhs_index != 0
+ && (symbol_index == 0 || midrule_rhs_index < symbol_index))
+ var->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE;
+
+ /* Check correct bracketing. */
+ if (!explicit_bracketing && contains_dot_or_dash (var->id))
+ var->err |= VARIANT_BAD_BRACKETING;
+
+ /* Check using of hidden symbols. */
+ if (var->hidden_by)
+ var->err |= VARIANT_HIDDEN;
+
+ if (!var->err)
+ {
+ valid_variant_index = i;
+ ++valid_variants;
+ }
+ }
+
+ switch (valid_variants)
+ {
+ case 0:
+ {
+ unsigned len = (explicit_bracketing || !ref_tail_fields) ?
+ cp_end - cp : ref_tail_fields - cp;
+ unsigned indent = 0;
+
+ complain_indent (&text_loc, complaint, &indent,
+ _("invalid reference: %s"), quote (text));
+ indent += SUB_INDENT;
+ if (len == 0)
+ {
+ location sym_loc = text_loc;
+ sym_loc.start.column += 1;
+ sym_loc.end = sym_loc.start;
+ complain_indent (&sym_loc, complaint, &indent,
+ _("syntax error after '%c', expecting integer, "
+ "letter, '_', '[', or '$'"),
+ dollar_or_at);
+ }
+ else if (midrule_rhs_index)
+ complain_indent (&rule->location, complaint, &indent,
+ _("symbol not found in production before $%d: "
+ "%.*s"),
+ midrule_rhs_index, len, cp);
+ else
+ complain_indent (&rule->location, complaint, &indent,
+ _("symbol not found in production: %.*s"),
+ len, cp);
+
+ if (variant_count > 0)
+ show_sub_messages (complaint,
+ cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, indent);
+ return INVALID_REF;
+ }
+ case 1:
+ {
+ unsigned indent = 0;
+ if (variant_count > 1)
+ {
+ complain_indent (&text_loc, Wother, &indent,
+ _("misleading reference: %s"), quote (text));
+ show_sub_messages (Wother,
+ cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, indent + SUB_INDENT);
+ }
+ {
+ unsigned symbol_index =
+ variant_table[valid_variant_index].symbol_index;
+ return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index;
+ }
+ }
+ case 2:
+ default:
+ {
+ unsigned indent = 0;
+ complain_indent (&text_loc, complaint, &indent,
+ _("ambiguous reference: %s"), quote (text));
+ show_sub_messages (complaint,
+ cp, explicit_bracketing, midrule_rhs_index,
+ dollar_or_at, indent + SUB_INDENT);
+ return INVALID_REF;
+ }
+ }
+
+ /* Not reachable. */
+ return INVALID_REF;
+}
+
+/* Keeps track of the maximum number of semantic values to the left of
+ a handle (those referenced by $0, $-1, etc.) are required by the
+ semantic actions of this grammar. */
+int max_left_semantic_context = 0;
+
+
+/* If CP points to a typename (i.e., <.*?>), set TYPE_NAME to its
+ beginning (i.e., after the opening "<", and return the pointer
+ immediately after it. */
+
+static
+char *
+fetch_type_name (char *cp, char const **type_name,
+ location dollar_loc)
+{
+ if (*cp == '<')
+ {
+ *type_name = ++cp;
+ /* Series of non-'>' or "->". */
+ while (*cp != '>' || cp[-1] == '-')
+ ++cp;
+
+ /* The '>' symbol will be later replaced by '\0'. Original
+ 'text' is needed for error messages. */
+ ++cp;
+ if (untyped_var_seen)
+ complain (&dollar_loc, complaint,
+ _("explicit type given in untyped grammar"));
+ tag_seen = true;
+ }
+ return cp;
+}
+
+/*------------------------------------------------------------------.
+| TEXT is pointing to a wannabee semantic value (i.e., a '$'). |
+| |
+| Possible inputs: $[<TYPENAME>]($|integer) |
+| |
+| Output to OBSTACK_FOR_STRING a reference to this semantic value. |
+`------------------------------------------------------------------*/
+
+static void
+handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
+{
+ char const *type_name = NULL;
+ char *cp = text + 1;
+ symbol_list *effective_rule;
+ int effective_rule_length;
+ int n;
+
+ if (rule->midrule_parent_rule)
+ {
+ effective_rule = rule->midrule_parent_rule;
+ effective_rule_length = rule->midrule_parent_rhs_index - 1;
+ }
+ else
+ {
+ effective_rule = rule;
+ effective_rule_length = symbol_list_length (rule->next);
+ }
+
+ /* Get the type name if explicit. */
+ cp = fetch_type_name (cp, &type_name, dollar_loc);
+
+ n = parse_ref (cp, effective_rule, effective_rule_length,
+ rule->midrule_parent_rhs_index, text, dollar_loc, '$');
+
+ /* End type_name. */
+ if (type_name)
+ cp[-1] = '\0';
+
+ switch (n)
+ {
+ case INVALID_REF:
+ break;
+
+ case LHS_REF:
+ if (!type_name)
+ type_name = symbol_list_n_type_name_get (rule, dollar_loc, 0);
+
+ if (!type_name)
+ {
+ if (union_seen | tag_seen)
+ {
+ if (rule->midrule_parent_rule)
+ complain (&dollar_loc, complaint,
+ _("$$ for the midrule at $%d of %s"
+ " has no declared type"),
+ rule->midrule_parent_rhs_index,
+ quote (effective_rule->content.sym->tag));
+ else
+ complain (&dollar_loc, complaint,
+ _("$$ of %s has no declared type"),
+ quote (rule->content.sym->tag));
+ }
+ else
+ untyped_var_seen = true;
+ }
+
+ obstack_sgrow (&obstack_for_string, "]b4_lhs_value(");
+ obstack_quote (&obstack_for_string, type_name);
+ obstack_sgrow (&obstack_for_string, ")[");
+ rule->action_props.is_value_used = true;
+ break;
+
+ default:
+ if (max_left_semantic_context < 1 - n)
+ max_left_semantic_context = 1 - n;
+ if (!type_name && 0 < n)
+ type_name =
+ symbol_list_n_type_name_get (effective_rule, dollar_loc, n);
+ if (!type_name)
+ {
+ if (union_seen | tag_seen)
+ complain (&dollar_loc, complaint,
+ _("$%s of %s has no declared type"), cp,
+ quote (effective_rule->content.sym->tag));
+ else
+ untyped_var_seen = true;
+ }
+
+ obstack_printf (&obstack_for_string,
+ "]b4_rhs_value(%d, %d, ", effective_rule_length, n);
+ obstack_quote (&obstack_for_string, type_name);
+ obstack_sgrow (&obstack_for_string, ")[");
+ if (n > 0)
+ symbol_list_n_get (effective_rule, n)->action_props.is_value_used =
+ true;
+ break;
+ }
+}
+
+
+/*------------------------------------------------------.
+| TEXT is a location token (i.e., a '@...'). Output to |
+| OBSTACK_FOR_STRING a reference to this location. |
+`------------------------------------------------------*/
+
+static void
+handle_action_at (symbol_list *rule, char *text, location at_loc)
+{
+ char *cp = text + 1;
+ symbol_list *effective_rule;
+ int effective_rule_length;
+ int n;
+
+ if (rule->midrule_parent_rule)
+ {
+ effective_rule = rule->midrule_parent_rule;
+ effective_rule_length = rule->midrule_parent_rhs_index - 1;
+ }
+ else
+ {
+ effective_rule = rule;
+ effective_rule_length = symbol_list_length (rule->next);
+ }
+
+ muscle_percent_define_ensure("locations", at_loc, true);
+
+ n = parse_ref (cp, effective_rule, effective_rule_length,
+ rule->midrule_parent_rhs_index, text, at_loc, '@');
+ switch (n)
+ {
+ case INVALID_REF:
+ break;
+
+ case LHS_REF:
+ obstack_sgrow (&obstack_for_string, "]b4_lhs_location[");
+ break;
+
+ default:
+ obstack_printf (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
+ effective_rule_length, n);
+ break;
+ }
+}
+
+
+/*-------------------------.
+| Initialize the scanner. |
+`-------------------------*/
+
+/* Translate the dollars and ats in \a self, in the context \a sc_context
+ (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */
+
+static char const *
+translate_action (code_props *self, int sc_context)
+{
+ char *res;
+ static bool initialized = false;
+ if (!initialized)
+ {
+ obstack_init (&obstack_for_string);
+ yy_flex_debug = 0;
+ initialized = true;
+ }
+
+ loc->start = loc->end = self->location.start;
+ yy_switch_to_buffer (yy_scan_string (self->code));
+ res = code_lex (self, sc_context);
+ yy_delete_buffer (YY_CURRENT_BUFFER);
+
+ return res;
+}
+
+/*------------------------------------------------------------------------.
+| Implementation of the public interface as documented in "scan-code.h". |
+`------------------------------------------------------------------------*/
+
+void
+code_props_none_init (code_props *self)
+{
+ *self = code_props_none;
+}
+
+code_props code_props_none = CODE_PROPS_NONE_INIT;
+
+void
+code_props_plain_init (code_props *self, char const *code,
+ location code_loc)
+{
+ code_props_none_init (self);
+ self->kind = CODE_PROPS_PLAIN;
+ self->code = code;
+ self->location = code_loc;
+}
+
+void
+code_props_symbol_action_init (code_props *self, char const *code,
+ location code_loc)
+{
+ code_props_none_init (self);
+ self->kind = CODE_PROPS_SYMBOL_ACTION;
+ self->code = code;
+ self->location = code_loc;
+}
+
+void
+code_props_rule_action_init (code_props *self, char const *code,
+ location code_loc, symbol_list *rule,
+ named_ref *name, bool is_predicate)
+{
+ code_props_none_init (self);
+ self->kind = CODE_PROPS_RULE_ACTION;
+ self->code = code;
+ self->location = code_loc;
+ self->rule = rule;
+ self->named_ref = name;
+ self->is_predicate = is_predicate;
+}
+
+void
+code_props_translate_code (code_props *self)
+{
+ switch (self->kind)
+ {
+ case CODE_PROPS_NONE:
+ break;
+ case CODE_PROPS_PLAIN:
+ self->code = translate_action (self, INITIAL);
+ break;
+ case CODE_PROPS_SYMBOL_ACTION:
+ self->code = translate_action (self, SC_SYMBOL_ACTION);
+ break;
+ case CODE_PROPS_RULE_ACTION:
+ self->code = translate_action (self, SC_RULE_ACTION);
+ break;
+ }
+}
+
+void
+code_scanner_last_string_free (void)
+{
+ STRING_FREE;
+}
+
+void
+code_scanner_free (void)
+{
+ obstack_free (&obstack_for_string, 0);
+ variant_table_free ();
+
+ /* Reclaim Flex's buffers. */
+ yylex_destroy ();
+}
diff --git a/contrib/tools/bison/bison/src/scan-gram-c.c b/contrib/tools/bison/bison/src/scan-gram-c.c
index 2b4fc67b48..ab5d47319e 100644
--- a/contrib/tools/bison/bison/src/scan-gram-c.c
+++ b/contrib/tools/bison/bison/src/scan-gram-c.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#include "system.h"
-#include "src/scan-gram.c"
+#include <config.h>
+#include "system.h"
+#include "src/scan-gram.c"
diff --git a/contrib/tools/bison/bison/src/scan-gram.c b/contrib/tools/bison/bison/src/scan-gram.c
index 3c74a56bea..6a8d02be77 100644
--- a/contrib/tools/bison/bison/src/scan-gram.c
+++ b/contrib/tools/bison/bison/src/scan-gram.c
@@ -1,4018 +1,4018 @@
-#line 2 "src/scan-gram.c"
-
-#line 4 "src/scan-gram.c"
-
-#define YY_INT_ALIGNED short int
-
-/* A lexical scanner generated by flex */
-
-/* %not-for-header */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-#define yy_create_buffer gram__create_buffer
-#define yy_delete_buffer gram__delete_buffer
-#define yy_flex_debug gram__flex_debug
-#define yy_init_buffer gram__init_buffer
-#define yy_flush_buffer gram__flush_buffer
-#define yy_load_buffer_state gram__load_buffer_state
-#define yy_switch_to_buffer gram__switch_to_buffer
-#define yyin gram_in
-#define yyleng gram_leng
-#define yylex gram_lex
-#define yylineno gram_lineno
-#define yyout gram_out
-#define yyrestart gram_restart
-#define yytext gram_text
-#define yywrap gram_wrap
-#define yyalloc gram_alloc
-#define yyrealloc gram_realloc
-#define yyfree gram_free
-
-/* %endif */
-/* %endif */
-/* %ok-for-header */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 37
-#if YY_FLEX_SUBMINOR_VERSION > 0
-#define FLEX_BETA
-#endif
-
-/* %if-c++-only */
-/* %endif */
-
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c-only */
-
-/* %endif */
-
-/* First, we deal with platform-specific or compiler-specific issues. */
-
-/* begin standard C headers. */
-/* %if-c-only */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-/* %endif */
-
-/* %if-tables-serialization */
-/* %endif */
-/* end standard C headers. */
-
-/* %if-c-or-c++ */
-/* flex integer type definitions */
-
-#ifndef FLEXINT_H
-#define FLEXINT_H
-
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
-
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-
-/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types.
- */
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS 1
-#endif
-
-#include <inttypes.h>
-typedef int8_t flex_int8_t;
-typedef uint8_t flex_uint8_t;
-typedef int16_t flex_int16_t;
-typedef uint16_t flex_uint16_t;
-typedef int32_t flex_int32_t;
-typedef uint32_t flex_uint32_t;
-#else
-typedef signed char flex_int8_t;
-typedef short int flex_int16_t;
-typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
-typedef unsigned short int flex_uint16_t;
-typedef unsigned int flex_uint32_t;
-
-/* Limits of integral types. */
-#ifndef INT8_MIN
-#define INT8_MIN (-128)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN (-32767-1)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN (-2147483647-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX (127)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX (32767)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX (2147483647)
-#endif
-#ifndef UINT8_MAX
-#define UINT8_MAX (255U)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX (65535U)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX (4294967295U)
-#endif
-
-#endif /* ! C99 */
-
-#endif /* ! FLEXINT_H */
-
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
-#ifdef __cplusplus
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else /* ! __cplusplus */
-
-/* C99 requires __STDC__ to be defined as 1. */
-#if defined (__STDC__)
-
-#define YY_USE_CONST
-
-#endif /* defined (__STDC__) */
-#endif /* ! __cplusplus */
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-/* %not-for-header */
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index. If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-/* %ok-for-header */
-
-/* %if-reentrant */
-/* %endif */
-
-/* %if-not-reentrant */
-
-/* %endif */
-
-/* Enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN (yy_start) = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state. The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START (((yy_start) - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE gram_restart(gram_in )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#ifndef YY_BUF_SIZE
-#define YY_BUF_SIZE 16384
-#endif
-
-/* The state buf must be large enough to hold one state per character in the main buffer.
- */
-#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
-
-#ifndef YY_TYPEDEF_YY_BUFFER_STATE
-#define YY_TYPEDEF_YY_BUFFER_STATE
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-#endif
-
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
-/* %if-not-reentrant */
-extern yy_size_t gram_leng;
-/* %endif */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-extern FILE *gram_in, *gram_out;
-/* %endif */
-/* %endif */
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
- #define YY_LESS_LINENO(n)
-
-/* Return all but the first "n" matched characters back to the input stream. */
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up gram_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- *yy_cp = (yy_hold_char); \
- YY_RESTORE_YY_MORE_OFFSET \
- (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
- YY_DO_BEFORE_ACTION; /* set up gram_text again */ \
- } \
- while ( 0 )
-
-#define unput(c) yyunput( c, (yytext_ptr) )
-
-#ifndef YY_STRUCT_YY_BUFFER_STATE
-#define YY_STRUCT_YY_BUFFER_STATE
-struct yy_buffer_state
- {
-/* %if-c-only */
- FILE *yy_input_file;
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
- char *yy_ch_buf; /* input buffer */
- char *yy_buf_pos; /* current position in input buffer */
-
- /* Size of input buffer in bytes, not including room for EOB
- * characters.
- */
- yy_size_t yy_buf_size;
-
- /* Number of characters read into yy_ch_buf, not including EOB
- * characters.
- */
- yy_size_t yy_n_chars;
-
- /* Whether we "own" the buffer - i.e., we know we created it,
- * and can realloc() it to grow it, and should free() it to
- * delete it.
- */
- int yy_is_our_buffer;
-
- /* Whether this is an "interactive" input source; if so, and
- * if we're using stdio for input, then we want to use getc()
- * instead of fread(), to make sure we stop fetching input after
- * each newline.
- */
- int yy_is_interactive;
-
- /* Whether we're considered to be at the beginning of a line.
- * If so, '^' rules will be active on the next match, otherwise
- * not.
- */
- int yy_at_bol;
-
- int yy_bs_lineno; /**< The line count. */
- int yy_bs_column; /**< The column count. */
-
- /* Whether to try to fill the input buffer when we reach the
- * end of it.
- */
- int yy_fill_buffer;
-
- int yy_buffer_status;
-
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
- /* When an EOF's been seen but there's still some text to process
- * then we mark the buffer as YY_EOF_PENDING, to indicate that we
- * shouldn't try reading from the input source any more. We might
- * still have a bunch of tokens to match, though, because of
- * possible backing-up.
- *
- * When we actually see the EOF, we change the status to "new"
- * (via gram_restart()), so that the user can continue scanning by
- * just pointing gram_in at a new input file.
- */
-#define YY_BUFFER_EOF_PENDING 2
-
- };
-#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-/* %if-not-reentrant */
-
-/* Stack of input buffers. */
-static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
-static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
-static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
-/* %endif */
-/* %ok-for-header */
-
-/* %endif */
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
- ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
- : NULL)
-
-/* Same as previous macro, but useful when we know that the buffer stack is not
- * NULL or when we need an lvalue. For internal use only.
- */
-#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
-
-/* %if-c-only Standard (non-C++) definition */
-
-/* %if-not-reentrant */
-/* %not-for-header */
-
-/* yy_hold_char holds the character lost when gram_text is formed. */
-static char yy_hold_char;
-static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
-yy_size_t gram_leng;
-
-/* Points to current character in buffer. */
-static char *yy_c_buf_p = (char *) 0;
-static int yy_init = 0; /* whether we need to initialize */
-static int yy_start = 0; /* start state number */
-
-/* Flag which is used to allow gram_wrap()'s to do buffer switches
- * instead of setting up a fresh gram_in. A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-/* %ok-for-header */
-
-/* %endif */
-
-void gram_restart (FILE *input_file );
-void gram__switch_to_buffer (YY_BUFFER_STATE new_buffer );
-YY_BUFFER_STATE gram__create_buffer (FILE *file,int size );
-void gram__delete_buffer (YY_BUFFER_STATE b );
-void gram__flush_buffer (YY_BUFFER_STATE b );
-void gram_push_buffer_state (YY_BUFFER_STATE new_buffer );
-void gram_pop_buffer_state (void );
-
-static void gram_ensure_buffer_stack (void );
-static void gram__load_buffer_state (void );
-static void gram__init_buffer (YY_BUFFER_STATE b,FILE *file );
-
-#define YY_FLUSH_BUFFER gram__flush_buffer(YY_CURRENT_BUFFER )
-
-YY_BUFFER_STATE gram__scan_buffer (char *base,yy_size_t size );
-YY_BUFFER_STATE gram__scan_string (yyconst char *yy_str );
-YY_BUFFER_STATE gram__scan_bytes (yyconst char *bytes,yy_size_t len );
-
-/* %endif */
-
-void *gram_alloc (yy_size_t );
-void *gram_realloc (void *,yy_size_t );
-void gram_free (void * );
-
-#define yy_new_buffer gram__create_buffer
-
-#define yy_set_interactive(is_interactive) \
- { \
- if ( ! YY_CURRENT_BUFFER ){ \
- gram_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- gram__create_buffer(gram_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
- }
-
-#define yy_set_bol(at_bol) \
- { \
- if ( ! YY_CURRENT_BUFFER ){\
- gram_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- gram__create_buffer(gram_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
- }
-
-#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
-
-/* %% [1.0] gram_text/gram_in/gram_out/yy_state_type/gram_lineno etc. def's & init go here */
-/* Begin user sect3 */
-
-#define gram_wrap() 1
-#define YY_SKIP_YYWRAP
-
-#define FLEX_DEBUG
-
-typedef unsigned char YY_CHAR;
-
-FILE *gram_in = (FILE *) 0, *gram_out = (FILE *) 0;
-
-typedef int yy_state_type;
-
-extern int gram_lineno;
-
-int gram_lineno = 1;
-
-extern char *gram_text;
-#define yytext_ptr gram_text
-
-/* %if-c-only Standard (non-C++) definition */
-
-static yy_state_type yy_get_previous_state (void );
-static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
-static int yy_get_next_buffer (void );
-static void yy_fatal_error (yyconst char msg[] );
-
-/* %endif */
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up gram_text.
- */
-#define YY_DO_BEFORE_ACTION \
- (yytext_ptr) = yy_bp; \
-/* %% [2.0] code to fiddle gram_text and gram_leng for yymore() goes here \ */\
- gram_leng = (size_t) (yy_cp - yy_bp); \
- (yy_hold_char) = *yy_cp; \
- *yy_cp = '\0'; \
-/* %% [3.0] code to copy yytext_ptr to gram_text[] goes here, if %array \ */\
- (yy_c_buf_p) = yy_cp;
-
-/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
-#define YY_NUM_RULES 130
-#define YY_END_OF_BUFFER 131
-/* This struct is not used in this scanner,
- but its presence is necessary. */
-struct yy_trans_info
- {
- flex_int32_t yy_verify;
- flex_int32_t yy_nxt;
- };
-static yyconst flex_int16_t yy_accept[582] =
- { 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 93, 93, 113, 113, 113, 113, 0, 0,
- 0, 0, 131, 80, 2, 2, 71, 80, 70, 80,
- 1, 66, 80, 67, 67, 65, 77, 63, 66, 79,
- 73, 64, 80, 90, 90, 128, 95, 94, 128, 81,
- 97, 96, 84, 2, 1, 84, 83, 82, 84, 99,
- 99, 100, 98, 81, 129, 119, 128, 118, 128, 128,
- 128, 122, 125, 126, 128, 92, 128, 117, 116, 128,
- 115, 114, 87, 2, 1, 85, 87, 87, 86, 87,
-
- 88, 2, 1, 88, 88, 80, 0, 78, 62, 0,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 72, 66,
- 66, 4, 3, 69, 67, 69, 0, 76, 0, 89,
- 112, 110, 101, 112, 103, 104, 105, 106, 107, 108,
- 112, 109, 112, 99, 99, 100, 127, 120, 121, 0,
- 123, 0, 122, 124, 0, 91, 0, 0, 93, 113,
- 113, 113, 113, 87, 85, 62, 62, 0, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
-
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 3, 69, 68, 75, 0, 101, 0, 0, 102, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 74, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 0, 101, 0, 0, 62, 7, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 23, 62, 62, 62, 62, 62, 62, 62, 62, 62,
-
- 62, 62, 62, 62, 62, 36, 62, 62, 62, 62,
- 62, 62, 44, 62, 47, 62, 62, 50, 0, 0,
- 0, 62, 8, 62, 62, 62, 13, 14, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 26, 62, 62,
- 62, 62, 62, 62, 62, 62, 32, 62, 34, 62,
- 62, 62, 62, 62, 62, 41, 62, 43, 45, 48,
- 62, 0, 0, 111, 6, 62, 10, 62, 62, 62,
- 16, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 33, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 0, 62,
-
- 11, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 0, 59, 62, 62, 38, 62, 62, 40,
- 62, 62, 62, 49, 5, 0, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 22, 62,
- 62, 62, 62, 62, 29, 62, 58, 30, 62, 62,
- 62, 62, 62, 42, 62, 62, 0, 62, 62, 62,
- 62, 62, 17, 53, 62, 62, 62, 62, 62, 24,
- 25, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 0, 0, 62, 62, 12, 62, 62, 62,
-
- 62, 62, 21, 62, 62, 62, 62, 62, 62, 62,
- 37, 62, 62, 62, 62, 62, 62, 62, 62, 18,
- 62, 62, 62, 27, 56, 62, 62, 62, 35, 39,
- 60, 46, 61, 9, 51, 62, 62, 0, 54, 62,
- 62, 62, 0, 56, 62, 62, 62, 15, 52, 62,
- 62, 62, 62, 62, 62, 62, 62, 20, 62, 62,
- 62, 62, 62, 28, 57, 62, 62, 62, 62, 62,
- 62, 62, 19, 55, 62, 62, 62, 62, 62, 31,
- 0
- } ;
-
-static yyconst flex_int32_t yy_ec[256] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 2, 2, 4, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 5, 6, 7, 8, 6, 9, 6, 10, 6,
- 6, 11, 6, 12, 13, 14, 15, 16, 17, 17,
- 17, 17, 17, 17, 17, 18, 18, 19, 20, 21,
- 22, 23, 24, 6, 25, 25, 25, 25, 25, 25,
- 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
- 26, 26, 26, 26, 27, 26, 26, 28, 26, 26,
- 29, 30, 31, 6, 32, 6, 33, 34, 35, 36,
-
- 37, 38, 39, 40, 41, 26, 42, 43, 44, 45,
- 46, 47, 48, 49, 50, 51, 52, 53, 26, 54,
- 55, 26, 56, 57, 58, 6, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
- } ;
-
-static yyconst flex_int32_t yy_meta[60] =
- { 0,
- 1, 2, 3, 1, 2, 4, 5, 4, 5, 5,
- 5, 5, 6, 7, 8, 9, 9, 9, 4, 5,
- 10, 5, 10, 4, 9, 11, 11, 11, 12, 4,
- 13, 11, 9, 9, 9, 9, 9, 9, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 5, 5, 5, 1
- } ;
-
-static yyconst flex_int16_t yy_base[609] =
- { 0,
- 0, 1065, 1061, 1060, 57, 58, 59, 60, 79, 94,
- 53, 62, 117, 126, 135, 144, 100, 145, 154, 163,
- 68, 69, 65, 70, 98, 155, 101, 164, 221, 1062,
- 174, 193, 1069, 0, 1074, 1074, 1074, 280, 1074, 1074,
- 1074, 339, 119, 164, 197, 1074, 114, 1074, 398, 1074,
- 1074, 1074, 1025, 1074, 1052, 1074, 1074, 1074, 451, 1074,
- 1074, 1074, 1074, 1074, 1074, 128, 1074, 1074, 1023, 1052,
- 54, 1043, 1074, 1050, 1074, 1074, 1004, 1074, 331, 63,
- 190, 1074, 1074, 1074, 153, 1074, 185, 1074, 1074, 346,
- 1074, 1074, 0, 1074, 0, 0, 192, 1074, 1074, 1018,
-
- 1074, 1074, 1074, 339, 1017, 0, 0, 1074, 0, 354,
- 1018, 1012, 169, 311, 1016, 1013, 1010, 329, 1017, 331,
- 1001, 334, 331, 98, 334, 1007, 1014, 1017, 1074, 505,
- 0, 1074, 0, 0, 374, 549, 1026, 1074, 1007, 1074,
- 1074, 1074, 357, 0, 1074, 1074, 1074, 1074, 1074, 1074,
- 0, 1074, 0, 1034, 365, 1025, 1074, 1074, 1074, 382,
- 1074, 391, 1074, 1074, 398, 1074, 406, 410, 1015, 1074,
- 416, 1014, 421, 0, 0, 0, 0, 430, 0, 998,
- 1006, 393, 992, 993, 990, 991, 362, 988, 995, 990,
- 341, 999, 984, 988, 407, 994, 979, 980, 393, 979,
-
- 979, 987, 988, 991, 974, 980, 974, 979, 970, 983,
- 0, 0, 0, 1074, 972, 420, 0, 0, 0, 439,
- 434, 445, 174, 451, 442, 457, 410, 468, 474, 485,
- 489, 435, 1074, 983, 978, 962, 81, 962, 975, 960,
- 964, 972, 971, 970, 993, 954, 965, 952, 989, 968,
- 961, 962, 371, 465, 308, 949, 950, 433, 961, 950,
- 957, 941, 952, 948, 941, 945, 951, 950, 940, 951,
- 949, 946, 1074, 0, 0, 933, 0, 942, 928, 934,
- 929, 942, 921, 926, 939, 960, 936, 924, 929, 917,
- 0, 921, 916, 929, 442, 928, 923, 926, 921, 911,
-
- 923, 915, 906, 913, 919, 918, 903, 467, 912, 901,
- 914, 899, 0, 904, 0, 903, 901, 0, 941, 0,
- 0, 890, 0, 901, 906, 890, 0, 0, 480, 890,
- 893, 482, 906, 905, 904, 903, 894, 0, 887, 886,
- 894, 886, 892, 884, 878, 876, 0, 875, 0, 912,
- 888, 886, 875, 874, 871, 0, 868, 0, 484, 0,
- 868, 504, 0, 1074, 0, 866, 866, 880, 861, 860,
- 485, 863, 865, 864, 860, 865, 868, 857, 859, 855,
- 854, 869, 864, 867, 862, 852, 860, 523, 849, 858,
- 845, 860, 859, 854, 844, 838, 837, 850, 534, 502,
-
- 0, 835, 848, 847, 834, 833, 844, 828, 827, 828,
- 864, 839, 842, 829, 836, 835, 819, 820, 817, 818,
- 832, 817, 538, 1074, 832, 819, 0, 814, 813, 0,
- 816, 827, 826, 0, 1074, 851, 810, 809, 809, 805,
- 804, 803, 802, 812, 798, 797, 810, 813, 0, 801,
- 794, 805, 804, 798, 0, 797, 0, 0, 795, 789,
- 802, 786, 785, 0, 800, 799, 825, 782, 781, 780,
- 794, 793, 0, 0, 785, 778, 777, 774, 787, 0,
- 0, 780, 779, 768, 767, 776, 783, 768, 764, 762,
- 743, 739, 773, 541, 729, 727, 0, 714, 712, 703,
-
- 704, 700, 0, 700, 681, 657, 517, 525, 664, 662,
- 0, 655, 653, 662, 660, 661, 658, 642, 641, 551,
- 639, 638, 645, 566, 573, 637, 636, 574, 0, 0,
- 0, 0, 0, 0, 0, 577, 576, 587, 1074, 548,
- 549, 566, 594, 1074, 562, 561, 558, 0, 0, 569,
- 568, 560, 567, 566, 551, 560, 559, 0, 559, 558,
- 538, 529, 520, 0, 0, 524, 521, 510, 533, 483,
- 482, 484, 0, 0, 490, 461, 457, 445, 420, 0,
- 1074, 616, 629, 642, 655, 668, 681, 694, 701, 712,
- 725, 738, 749, 756, 764, 772, 783, 791, 437, 388,
-
- 372, 208, 200, 162, 137, 83, 69, 802
- } ;
-
-static yyconst flex_int16_t yy_def[609] =
- { 0,
- 581, 1, 582, 582, 583, 583, 583, 583, 584, 584,
- 585, 585, 583, 583, 583, 583, 583, 583, 583, 583,
- 583, 583, 583, 583, 583, 583, 583, 583, 581, 29,
- 586, 586, 581, 587, 581, 581, 581, 581, 581, 581,
- 581, 588, 581, 589, 589, 581, 581, 581, 588, 581,
- 581, 581, 587, 581, 581, 581, 581, 581, 590, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 591,
- 591, 581, 581, 591, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 592,
- 581, 581, 593, 581, 593, 594, 581, 581, 581, 593,
-
- 581, 581, 581, 581, 581, 587, 595, 581, 596, 595,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 581, 588,
- 49, 581, 597, 598, 589, 598, 581, 581, 581, 581,
- 581, 581, 581, 599, 581, 581, 581, 581, 581, 581,
- 600, 581, 601, 591, 591, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 593, 594, 595, 596, 581, 595, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
-
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 597, 598, 136, 581, 581, 581, 602, 603, 601, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 592, 581, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 581, 581, 604, 605, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
-
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 581, 606,
- 607, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 581, 600, 581, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 581, 596,
-
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 581, 581, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 581, 581, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 608, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 608, 608, 596, 596, 596, 596, 596, 596,
-
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 581, 581, 596,
- 596, 596, 581, 581, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
- 0, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
-
- 581, 581, 581, 581, 581, 581, 581, 581
- } ;
-
-static yyconst flex_int16_t yy_nxt[1134] =
- { 0,
- 34, 35, 36, 34, 35, 34, 37, 34, 38, 39,
- 40, 41, 34, 42, 43, 44, 45, 45, 34, 46,
- 47, 48, 40, 34, 49, 49, 49, 49, 50, 34,
- 34, 49, 49, 49, 49, 49, 49, 49, 49, 49,
- 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
- 49, 49, 49, 49, 49, 51, 52, 40, 34, 57,
- 57, 61, 61, 58, 58, 71, 155, 86, 62, 62,
- 75, 75, 86, 72, 71, 73, 154, 364, 85, 85,
- 64, 36, 72, 64, 73, 161, 59, 59, 59, 59,
- 65, 363, 162, 66, 87, 64, 36, 67, 64, 87,
-
- 88, 69, 75, 91, 89, 65, 76, 68, 66, 78,
- 92, 74, 67, 279, 79, 60, 60, 60, 60, 75,
- 74, 280, 68, 76, 137, 77, 78, 90, 75, 132,
- 90, 79, 76, 133, 77, 78, 138, 75, 132, 203,
- 79, 76, 133, 80, 78, 321, 75, 75, 204, 79,
- 76, 76, 80, 78, 78, 81, 75, 88, 79, 79,
- 76, 89, 80, 78, 81, 75, 91, 166, 79, 76,
- 320, 80, 78, 92, 81, 102, 36, 79, 102, 135,
- 135, 135, 167, 81, 90, 103, 168, 169, 104, 168,
- 82, 136, 83, 90, 102, 36, 161, 102, 163, 82,
-
- 105, 83, 132, 162, 103, 182, 133, 104, 275, 82,
- 164, 84, 135, 135, 135, 183, 274, 136, 82, 165,
- 84, 93, 94, 36, 93, 94, 93, 93, 93, 93,
- 93, 93, 95, 93, 96, 97, 98, 98, 98, 93,
- 93, 93, 93, 93, 93, 96, 96, 96, 96, 93,
- 93, 99, 96, 96, 96, 96, 96, 96, 96, 96,
- 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
- 96, 96, 96, 96, 96, 96, 93, 93, 93, 93,
- 107, 107, 107, 107, 107, 107, 107, 107, 108, 107,
- 107, 107, 107, 109, 107, 107, 107, 107, 107, 107,
-
- 107, 107, 107, 110, 109, 109, 109, 109, 107, 107,
- 107, 109, 109, 111, 112, 113, 114, 115, 116, 109,
- 117, 109, 118, 119, 120, 121, 122, 109, 123, 124,
- 125, 126, 127, 109, 128, 129, 107, 107, 107, 106,
- 300, 158, 106, 301, 106, 159, 106, 171, 172, 132,
- 171, 130, 130, 133, 184, 178, 178, 106, 178, 185,
- 160, 190, 106, 194, 186, 191, 198, 201, 106, 106,
- 205, 202, 216, 216, 192, 173, 195, 155, 248, 206,
- 219, 196, 199, 220, 221, 200, 220, 154, 207, 135,
- 135, 135, 222, 223, 249, 222, 218, 106, 581, 224,
-
- 225, 581, 224, 581, 243, 581, 296, 226, 227, 179,
- 226, 168, 169, 297, 168, 244, 581, 229, 172, 253,
- 229, 581, 231, 232, 166, 231, 236, 581, 581, 259,
- 237, 178, 178, 260, 178, 273, 273, 581, 254, 167,
- 220, 221, 238, 220, 158, 217, 222, 223, 159, 222,
- 163, 255, 224, 225, 339, 224, 581, 142, 226, 227,
- 142, 226, 164, 160, 173, 304, 143, 143, 580, 168,
- 169, 165, 168, 340, 142, 229, 172, 144, 229, 353,
- 142, 579, 305, 145, 146, 233, 229, 172, 147, 229,
- 231, 232, 369, 231, 373, 148, 396, 405, 354, 149,
-
- 298, 150, 151, 152, 153, 106, 578, 299, 106, 577,
- 106, 370, 106, 374, 437, 397, 406, 130, 130, 399,
- 399, 399, 576, 106, 423, 423, 423, 423, 106, 526,
- 575, 574, 573, 438, 106, 106, 435, 527, 436, 423,
- 423, 423, 423, 435, 424, 572, 571, 494, 527, 399,
- 399, 399, 538, 538, 538, 538, 527, 570, 569, 424,
- 550, 551, 568, 106, 213, 213, 213, 543, 543, 543,
- 543, 567, 539, 213, 543, 543, 543, 543, 566, 551,
- 551, 213, 213, 213, 213, 213, 213, 544, 538, 538,
- 538, 538, 565, 564, 544, 543, 543, 543, 543, 563,
-
- 562, 561, 560, 559, 558, 557, 556, 555, 539, 554,
- 553, 552, 549, 548, 547, 544, 54, 54, 54, 54,
- 54, 54, 54, 54, 54, 54, 54, 54, 54, 56,
- 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
- 56, 56, 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 70, 70, 70, 70, 70,
- 70, 70, 70, 70, 70, 70, 70, 70, 101, 101,
- 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
- 101, 106, 546, 545, 106, 542, 106, 106, 541, 540,
- 537, 536, 535, 106, 131, 534, 533, 131, 532, 131,
-
- 131, 531, 131, 530, 131, 529, 131, 134, 528, 134,
- 525, 134, 141, 141, 141, 141, 141, 141, 141, 141,
- 141, 141, 141, 141, 141, 154, 154, 154, 154, 154,
- 154, 154, 154, 154, 524, 154, 154, 154, 170, 170,
- 170, 170, 170, 170, 170, 170, 170, 170, 170, 174,
- 523, 522, 174, 174, 174, 521, 520, 519, 174, 518,
- 174, 175, 175, 517, 175, 516, 175, 176, 176, 176,
- 176, 176, 176, 176, 176, 176, 176, 177, 177, 494,
- 177, 515, 177, 211, 211, 514, 211, 211, 211, 211,
- 211, 211, 211, 211, 211, 211, 212, 212, 513, 212,
-
- 512, 212, 493, 493, 511, 493, 493, 493, 493, 493,
- 493, 493, 493, 493, 493, 510, 509, 508, 507, 506,
- 505, 504, 503, 502, 501, 500, 499, 498, 497, 496,
- 495, 494, 492, 491, 490, 489, 488, 487, 486, 485,
- 484, 483, 482, 481, 480, 479, 478, 477, 476, 475,
- 474, 473, 472, 471, 470, 469, 468, 467, 466, 465,
- 464, 463, 462, 461, 460, 459, 458, 457, 456, 455,
- 454, 453, 452, 451, 450, 449, 448, 447, 446, 445,
- 444, 443, 442, 441, 440, 439, 434, 433, 432, 431,
- 430, 429, 428, 427, 426, 425, 422, 421, 420, 419,
-
- 418, 417, 416, 415, 414, 413, 412, 411, 410, 409,
- 408, 407, 404, 403, 402, 401, 400, 398, 395, 394,
- 393, 392, 391, 390, 389, 388, 387, 386, 385, 384,
- 383, 382, 381, 380, 379, 378, 377, 376, 375, 372,
- 371, 368, 367, 366, 365, 362, 361, 360, 359, 358,
- 357, 356, 355, 352, 351, 350, 349, 348, 347, 346,
- 345, 344, 343, 342, 341, 338, 337, 336, 335, 334,
- 333, 332, 331, 330, 329, 328, 327, 326, 325, 324,
- 323, 322, 319, 318, 317, 316, 315, 314, 313, 312,
- 311, 310, 309, 308, 307, 306, 303, 302, 295, 294,
-
- 293, 292, 291, 290, 289, 288, 287, 286, 285, 284,
- 283, 282, 281, 278, 277, 276, 272, 271, 270, 269,
- 268, 267, 266, 265, 264, 263, 262, 261, 258, 257,
- 256, 252, 251, 250, 247, 246, 245, 242, 241, 240,
- 239, 235, 234, 230, 228, 156, 155, 215, 214, 210,
- 209, 208, 197, 193, 189, 188, 187, 181, 180, 139,
- 139, 157, 155, 156, 155, 139, 140, 139, 581, 100,
- 55, 55, 53, 33, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
-
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581
- } ;
-
-static yyconst flex_int16_t yy_chk[1134] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 5,
- 6, 7, 8, 5, 6, 11, 71, 23, 7, 8,
- 21, 22, 24, 11, 12, 11, 71, 607, 21, 22,
- 9, 9, 12, 9, 12, 80, 5, 6, 7, 8,
- 9, 606, 80, 9, 23, 10, 10, 9, 10, 24,
-
- 25, 10, 17, 27, 25, 10, 17, 9, 10, 17,
- 27, 11, 10, 237, 17, 5, 6, 7, 8, 13,
- 12, 237, 10, 13, 47, 13, 13, 25, 14, 43,
- 27, 13, 14, 43, 14, 14, 47, 15, 66, 124,
- 14, 15, 66, 15, 15, 605, 16, 18, 124, 15,
- 16, 18, 16, 16, 18, 15, 19, 26, 16, 18,
- 19, 26, 19, 19, 16, 20, 28, 85, 19, 20,
- 604, 20, 20, 28, 19, 31, 31, 20, 31, 44,
- 44, 44, 85, 20, 26, 31, 87, 87, 31, 87,
- 15, 44, 15, 28, 32, 32, 223, 32, 81, 16,
-
- 32, 16, 97, 223, 32, 113, 97, 32, 603, 19,
- 81, 19, 45, 45, 45, 113, 602, 44, 20, 81,
- 20, 29, 29, 29, 29, 29, 29, 29, 29, 29,
- 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
- 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
- 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
- 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
- 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
-
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 42,
- 255, 79, 42, 255, 42, 79, 42, 90, 90, 104,
- 90, 42, 42, 104, 114, 110, 110, 42, 110, 114,
- 79, 118, 42, 120, 114, 118, 122, 123, 42, 42,
- 125, 123, 143, 143, 118, 90, 120, 155, 191, 125,
- 601, 120, 122, 160, 160, 122, 160, 155, 125, 135,
- 135, 135, 162, 162, 191, 162, 600, 42, 49, 165,
-
- 165, 49, 165, 49, 187, 49, 253, 167, 167, 110,
- 167, 168, 168, 253, 168, 187, 49, 171, 171, 195,
- 171, 49, 173, 173, 227, 173, 182, 49, 49, 199,
- 182, 178, 178, 199, 178, 216, 216, 232, 195, 227,
- 220, 220, 182, 220, 221, 599, 222, 222, 221, 222,
- 225, 195, 224, 224, 295, 224, 49, 59, 226, 226,
- 59, 226, 225, 221, 232, 258, 59, 59, 579, 228,
- 228, 225, 228, 295, 59, 229, 229, 59, 229, 308,
- 59, 578, 258, 59, 59, 178, 230, 230, 59, 230,
- 231, 231, 329, 231, 332, 59, 359, 371, 308, 59,
-
- 254, 59, 59, 59, 59, 130, 577, 254, 130, 576,
- 130, 329, 130, 332, 400, 359, 371, 130, 130, 362,
- 362, 362, 575, 130, 388, 388, 388, 388, 130, 507,
- 572, 571, 570, 400, 130, 130, 399, 508, 399, 423,
- 423, 423, 423, 494, 388, 569, 568, 494, 507, 399,
- 399, 399, 520, 520, 520, 520, 508, 567, 566, 423,
- 540, 541, 563, 130, 136, 136, 136, 524, 524, 524,
- 524, 562, 520, 136, 525, 525, 525, 525, 561, 540,
- 541, 136, 136, 136, 136, 136, 136, 524, 538, 538,
- 538, 538, 560, 559, 525, 543, 543, 543, 543, 557,
-
- 556, 555, 554, 553, 552, 551, 550, 547, 538, 546,
- 545, 542, 537, 536, 528, 543, 582, 582, 582, 582,
- 582, 582, 582, 582, 582, 582, 582, 582, 582, 583,
- 583, 583, 583, 583, 583, 583, 583, 583, 583, 583,
- 583, 583, 584, 584, 584, 584, 584, 584, 584, 584,
- 584, 584, 584, 584, 584, 585, 585, 585, 585, 585,
- 585, 585, 585, 585, 585, 585, 585, 585, 586, 586,
- 586, 586, 586, 586, 586, 586, 586, 586, 586, 586,
- 586, 587, 527, 526, 587, 523, 587, 587, 522, 521,
- 519, 518, 517, 587, 588, 516, 515, 588, 514, 588,
-
- 588, 513, 588, 512, 588, 510, 588, 589, 509, 589,
- 506, 589, 590, 590, 590, 590, 590, 590, 590, 590,
- 590, 590, 590, 590, 590, 591, 591, 591, 591, 591,
- 591, 591, 591, 591, 505, 591, 591, 591, 592, 592,
- 592, 592, 592, 592, 592, 592, 592, 592, 592, 593,
- 504, 502, 593, 593, 593, 501, 500, 499, 593, 498,
- 593, 594, 594, 496, 594, 495, 594, 595, 595, 595,
- 595, 595, 595, 595, 595, 595, 595, 596, 596, 493,
- 596, 492, 596, 597, 597, 491, 597, 597, 597, 597,
- 597, 597, 597, 597, 597, 597, 598, 598, 490, 598,
-
- 489, 598, 608, 608, 488, 608, 608, 608, 608, 608,
- 608, 608, 608, 608, 608, 487, 486, 485, 484, 483,
- 482, 479, 478, 477, 476, 475, 472, 471, 470, 469,
- 468, 467, 466, 465, 463, 462, 461, 460, 459, 456,
- 454, 453, 452, 451, 450, 448, 447, 446, 445, 444,
- 443, 442, 441, 440, 439, 438, 437, 436, 433, 432,
- 431, 429, 428, 426, 425, 422, 421, 420, 419, 418,
- 417, 416, 415, 414, 413, 412, 411, 410, 409, 408,
- 407, 406, 405, 404, 403, 402, 398, 397, 396, 395,
- 394, 393, 392, 391, 390, 389, 387, 386, 385, 384,
-
- 383, 382, 381, 380, 379, 378, 377, 376, 375, 374,
- 373, 372, 370, 369, 368, 367, 366, 361, 357, 355,
- 354, 353, 352, 351, 350, 348, 346, 345, 344, 343,
- 342, 341, 340, 339, 337, 336, 335, 334, 333, 331,
- 330, 326, 325, 324, 322, 319, 317, 316, 314, 312,
- 311, 310, 309, 307, 306, 305, 304, 303, 302, 301,
- 300, 299, 298, 297, 296, 294, 293, 292, 290, 289,
- 288, 287, 286, 285, 284, 283, 282, 281, 280, 279,
- 278, 276, 272, 271, 270, 269, 268, 267, 266, 265,
- 264, 263, 262, 261, 260, 259, 257, 256, 252, 251,
-
- 250, 249, 248, 247, 246, 245, 244, 243, 242, 241,
- 240, 239, 238, 236, 235, 234, 215, 210, 209, 208,
- 207, 206, 205, 204, 203, 202, 201, 200, 198, 197,
- 196, 194, 193, 192, 190, 189, 188, 186, 185, 184,
- 183, 181, 180, 172, 169, 156, 154, 139, 137, 128,
- 127, 126, 121, 119, 117, 116, 115, 112, 111, 105,
- 100, 77, 74, 72, 70, 69, 55, 53, 33, 30,
- 4, 3, 2, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
-
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
- 581, 581, 581
- } ;
-
-static yy_state_type yy_last_accepting_state;
-static char *yy_last_accepting_cpos;
-
-extern int gram__flex_debug;
-int gram__flex_debug = 1;
-
-static yyconst flex_int16_t yy_rule_linenum[130] =
- { 0,
- 179, 182, 183, 184, 192, 210, 211, 212, 213, 214,
- 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
- 225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
- 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
- 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
- 257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
- 267, 269, 273, 274, 275, 277, 284, 288, 295, 300,
- 303, 306, 309, 317, 324, 325, 326, 332, 339, 346,
- 366, 376, 391, 396, 415, 428, 444, 459, 476, 477,
- 488, 499, 500, 512, 520, 530, 549, 561, 575, 576,
-
- 587, 596, 606, 607, 608, 609, 610, 611, 612, 615,
- 617, 625, 643, 648, 649, 655, 656, 667, 673, 679,
- 685, 701, 702, 706, 713, 730, 751, 784, 785
- } ;
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-char *gram_text;
-#line 1 "../../src/scan-gram.l"
-/* Bison Grammar Scanner -*- C -*-
-
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#define YY_NO_INPUT 1
-#line 24 "../../src/scan-gram.l"
-/* Work around a bug in flex 2.5.31. See Debian bug 333231
- <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
-#undef gram_wrap
-#define gram_wrap() 1
-
-#define FLEX_PREFIX(Id) gram_ ## Id
-#include <src/flex-scanner.h>
-
-#include <src/complain.h>
-#include <src/files.h>
-#include <src/getargs.h>
-#include <src/gram.h>
-#include <quotearg.h>
-#include <src/reader.h>
-#include <src/uniqstr.h>
-
-#include <c-ctype.h>
-#include <mbswidth.h>
-#include <quote.h>
-
-#include <src/scan-gram.h>
-
-#define YY_DECL GRAM_LEX_DECL
-
-#define YY_USER_INIT \
- code_start = scanner_cursor = loc->start; \
-
-/* Location of scanner cursor. */
-static boundary scanner_cursor;
-
-#define YY_USER_ACTION location_compute (loc, &scanner_cursor, gram_text, gram_leng);
-
-static size_t no_cr_read (FILE *, char *, size_t);
-#define YY_INPUT(buf, result, size) ((result) = no_cr_read (gram_in, buf, size))
-
-#define RETURN_PERCENT_PARAM(Value) \
- RETURN_VALUE(PERCENT_PARAM, param, param_ ## Value)
-
-#define RETURN_PERCENT_FLAG(Value) \
- RETURN_VALUE(PERCENT_FLAG, uniqstr, uniqstr_new (Value))
-
-#define RETURN_VALUE(Token, Field, Value) \
- do { \
- val->Field = Value; \
- return Token; \
- } while (0)
-
-#define ROLLBACK_CURRENT_TOKEN \
- do { \
- scanner_cursor.column -= mbsnwidth (gram_text, gram_leng, 0); \
- yyless (0); \
- } while (0)
-
-#define DEPRECATED(Msg) \
- do { \
- size_t i; \
- deprecated_directive (loc, gram_text, Msg); \
- scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \
- for (i = strlen (Msg); i != 0; --i) \
- unput (Msg[i - 1]); \
- } while (0)
-
-/* A string representing the most recently saved token. */
-static char *last_string;
-
-/* Bracketed identifier. */
-static uniqstr bracketed_id_str = 0;
-static location bracketed_id_loc;
-static boundary bracketed_id_start;
-static int bracketed_id_context_state = 0;
-
-void
-gram_scanner_last_string_free (void)
-{
- STRING_FREE;
-}
-
-static void handle_syncline (char *, location);
-static unsigned long int scan_integer (char const *p, int base, location loc);
-static int convert_ucn_to_byte (char const *hex_text);
-static void unexpected_eof (boundary, char const *);
-static void unexpected_newline (boundary, char const *);
-
-/* A C-like comment in directives/rules. */
-
-/* Strings and characters in directives/rules. */
-
-/* A identifier was just read in directives/rules. Special state
-to capture the sequence 'identifier :'. */
-
-/* POSIX says that a tag must be both an id and a C union member, but
-historically almost any character is allowed in a tag. We
-disallow NUL, as this simplifies our implementation. We match
-angle brackets in nested pairs: several languages use them for
-generics/template types. */
-
-/* Four types of user code:
-- prologue (code between '%{' '%}' in the first section, before %%);
-- actions, printers, union, etc, (between braced in the middle section);
-- epilogue (everything after the second %%).
-- predicate (code between '%?{' and '{' in middle section); */
-
-/* C and C++ comments in code. */
-
-/* Strings and characters in code. */
-
-/* Bracketed identifiers support. */
-
-/* Zero or more instances of backslash-newline. Following GCC, allow
- white space between the backslash and the newline. */
-/* An equal sign, with optional leading whitespaces. This is used in some
- deprecated constructs. */
-#line 1153 "src/scan-gram.c"
-
-#define INITIAL 0
-#define SC_YACC_COMMENT 1
-#define SC_ESCAPED_STRING 2
-#define SC_ESCAPED_CHARACTER 3
-#define SC_AFTER_IDENTIFIER 4
-#define SC_TAG 5
-#define SC_PROLOGUE 6
-#define SC_BRACED_CODE 7
-#define SC_EPILOGUE 8
-#define SC_PREDICATE 9
-#define SC_COMMENT 10
-#define SC_LINE_COMMENT 11
-#define SC_STRING 12
-#define SC_CHARACTER 13
-#define SC_BRACKETED_ID 14
-#define SC_RETURN_BRACKETED_ID 15
-
-#ifndef YY_NO_UNISTD_H
-/* Special case for "unistd.h", since it is non-ANSI. We include it way
- * down here because we want the user's section 1 to have been scanned first.
- * The user has a chance to override it with an option.
- */
-/* %if-c-only */
-#include <unistd.h>
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-#ifndef YY_EXTRA_TYPE
-#define YY_EXTRA_TYPE void *
-#endif
-
-/* %if-c-only Reentrant structure and macros (non-C++). */
-/* %if-reentrant */
-/* %if-c-only */
-
-static int yy_init_globals (void );
-
-/* %endif */
-/* %if-reentrant */
-/* %endif */
-/* %endif End reentrant structures and macros. */
-
-/* Accessor methods to globals.
- These are made visible to non-reentrant scanners for convenience. */
-
-int gram_lex_destroy (void );
-
-int gram_get_debug (void );
-
-void gram_set_debug (int debug_flag );
-
-YY_EXTRA_TYPE gram_get_extra (void );
-
-void gram_set_extra (YY_EXTRA_TYPE user_defined );
-
-FILE *gram_get_in (void );
-
-void gram_set_in (FILE * in_str );
-
-FILE *gram_get_out (void );
-
-void gram_set_out (FILE * out_str );
-
-yy_size_t gram_get_leng (void );
-
-char *gram_get_text (void );
-
-int gram_get_lineno (void );
-
-void gram_set_lineno (int line_number );
-
-/* %if-bison-bridge */
-/* %endif */
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int gram_wrap (void );
-#else
-extern int gram_wrap (void );
-#endif
-#endif
-
-/* %not-for-header */
-
- static void yyunput (int c,char *buf_ptr );
-
-/* %ok-for-header */
-
-/* %endif */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int );
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * );
-#endif
-
-#ifndef YY_NO_INPUT
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-#ifdef __cplusplus
-static int yyinput (void );
-#else
-static int input (void );
-#endif
-/* %ok-for-header */
-
-/* %endif */
-#endif
-
-/* %if-c-only */
-
-/* %endif */
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-#ifndef ECHO
-/* %if-c-only Standard (non-C++) definition */
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO do { if (fwrite( gram_text, gram_leng, 1, gram_out )) {} } while (0)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif
-
-/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
- if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
- { \
- int c = '*'; \
- size_t n; \
- for ( n = 0; n < max_size && \
- (c = getc( gram_in )) != EOF && c != '\n'; ++n ) \
- buf[n] = (char) c; \
- if ( c == '\n' ) \
- buf[n++] = (char) c; \
- if ( c == EOF && ferror( gram_in ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- result = n; \
- } \
- else \
- { \
- errno=0; \
- while ( (result = fread(buf, 1, max_size, gram_in))==0 && ferror(gram_in)) \
- { \
- if( errno != EINTR) \
- { \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- break; \
- } \
- errno=0; \
- clearerr(gram_in); \
- } \
- }\
-\
-/* %if-c++-only C++ definition \ */\
-/* %endif */
-
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-/* %if-c-only */
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-/* %if-tables-serialization structures and prototypes */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* %tables-yydmap generated elements */
-/* %endif */
-/* end tables serialization structures and prototypes */
-
-/* %ok-for-header */
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL_IS_OURS 1
-/* %if-c-only Standard (non-C++) definition */
-
-extern int gram_lex (void);
-
-#define YY_DECL int gram_lex (void)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif /* !YY_DECL */
-
-/* Code executed at the beginning of each rule, after gram_text and gram_leng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-/* %% [6.0] YY_RULE_SETUP definition goes here */
-#define YY_RULE_SETUP \
- if ( gram_leng > 0 ) \
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \
- (gram_text[gram_leng - 1] == '\n'); \
- YY_USER_ACTION
-
-/* %not-for-header */
-
-/** The main scanner function which does all the work.
- */
-YY_DECL
-{
- register yy_state_type yy_current_state;
- register char *yy_cp, *yy_bp;
- register int yy_act;
-
-/* %% [7.0] user's declarations go here */
-#line 149 "../../src/scan-gram.l"
-
-
- /* Nesting level. Either for nested braces, or nested angle brackets
- (but not mixed). */
- int nesting PACIFY_CC (= 0);
-
- /* Parent context state, when applicable. */
- int context_state PACIFY_CC (= 0);
-
- /* Location of most recent identifier, when applicable. */
- location id_loc PACIFY_CC (= empty_location);
-
- /* Where containing code started, when applicable. Its initial
- value is relevant only when gram_lex is invoked in the SC_EPILOGUE
- start condition. */
- boundary code_start = scanner_cursor;
-
- /* Where containing comment or string or character literal started,
- when applicable. */
- boundary token_start PACIFY_CC (= scanner_cursor);
-
-
-
- /*-----------------------.
- | Scanning white space. |
- `-----------------------*/
-
-#line 1441 "src/scan-gram.c"
-
- if ( !(yy_init) )
- {
- (yy_init) = 1;
-
-#ifdef YY_USER_INIT
- YY_USER_INIT;
-#endif
-
- if ( ! (yy_start) )
- (yy_start) = 1; /* first start state */
-
- if ( ! gram_in )
-/* %if-c-only */
- gram_in = stdin;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! gram_out )
-/* %if-c-only */
- gram_out = stdout;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! YY_CURRENT_BUFFER ) {
- gram_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- gram__create_buffer(gram_in,YY_BUF_SIZE );
- }
-
- gram__load_buffer_state( );
- }
-
- while ( 1 ) /* loops until end-of-file is reached */
- {
-/* %% [8.0] yymore()-related code goes here */
- yy_cp = (yy_c_buf_p);
-
- /* Support of gram_text. */
- *yy_cp = (yy_hold_char);
-
- /* yy_bp points to the position in yy_ch_buf of the start of
- * the current run.
- */
- yy_bp = yy_cp;
-
-/* %% [9.0] code to set up and find next match goes here */
- yy_current_state = (yy_start);
- yy_current_state += YY_AT_BOL();
-yy_match:
- do
- {
- register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 582 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- ++yy_cp;
- }
- while ( yy_current_state != 581 );
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
-
-yy_find_action:
-/* %% [10.0] code to find the action number goes here */
- yy_act = yy_accept[yy_current_state];
-
- YY_DO_BEFORE_ACTION;
-
-/* %% [11.0] code for gram_lineno update goes here */
-
-do_action: /* This label is used only to access EOF actions. */
-
-/* %% [12.0] debug code goes here */
- if ( gram__flex_debug )
- {
- if ( yy_act == 0 )
- fprintf( stderr, "--scanner backing up\n" );
- else if ( yy_act < 130 )
- fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
- (long)yy_rule_linenum[yy_act], gram_text );
- else if ( yy_act == 130 )
- fprintf( stderr, "--accepting default rule (\"%s\")\n",
- gram_text );
- else if ( yy_act == 131 )
- fprintf( stderr, "--(end of buffer or a NUL)\n" );
- else
- fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
- }
-
- switch ( yy_act )
- { /* beginning of action switch */
-/* %% [13.0] actions go here */
- case 0: /* must back up */
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = (yy_hold_char);
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
-
-/* Comments and white space. */
-case 1:
-YY_RULE_SETUP
-#line 179 "../../src/scan-gram.l"
-{
- complain (loc, Wother, _("stray ',' treated as white space"));
- }
- YY_BREAK
-case 2:
-/* rule 2 can match eol */
-#line 183 "../../src/scan-gram.l"
-case 3:
-/* rule 3 can match eol */
-YY_RULE_SETUP
-#line 183 "../../src/scan-gram.l"
-continue;
- YY_BREAK
-case 4:
-YY_RULE_SETUP
-#line 184 "../../src/scan-gram.l"
-{
- token_start = loc->start;
- context_state = YY_START;
- BEGIN SC_YACC_COMMENT;
- }
- YY_BREAK
-/* #line directives are not documented, and may be withdrawn or
- modified in future versions of Bison. */
-case 5:
-/* rule 5 can match eol */
-YY_RULE_SETUP
-#line 192 "../../src/scan-gram.l"
-{
- handle_syncline (gram_text + sizeof "#line " - 1, *loc);
- }
- YY_BREAK
-
-/*----------------------------.
- | Scanning Bison directives. |
- `----------------------------*/
-/* For directives that are also command line options, the regex must be
- "%..."
- after "[-_]"s are removed, and the directive must match the --long
- option name, with a single string argument. Otherwise, add exceptions
- to ../build-aux/cross-options.pl. */
-
-
-case 6:
-YY_RULE_SETUP
-#line 210 "../../src/scan-gram.l"
-return PERCENT_NONASSOC;
- YY_BREAK
-case 7:
-YY_RULE_SETUP
-#line 211 "../../src/scan-gram.l"
-return PERCENT_CODE;
- YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 212 "../../src/scan-gram.l"
-RETURN_PERCENT_FLAG("parse.trace");
- YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 213 "../../src/scan-gram.l"
-return PERCENT_DEFAULT_PREC;
- YY_BREAK
-case 10:
-YY_RULE_SETUP
-#line 214 "../../src/scan-gram.l"
-return PERCENT_DEFINE;
- YY_BREAK
-case 11:
-YY_RULE_SETUP
-#line 215 "../../src/scan-gram.l"
-return PERCENT_DEFINES;
- YY_BREAK
-case 12:
-YY_RULE_SETUP
-#line 216 "../../src/scan-gram.l"
-return PERCENT_DESTRUCTOR;
- YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 217 "../../src/scan-gram.l"
-return PERCENT_DPREC;
- YY_BREAK
-case 14:
-YY_RULE_SETUP
-#line 218 "../../src/scan-gram.l"
-return PERCENT_EMPTY;
- YY_BREAK
-case 15:
-YY_RULE_SETUP
-#line 219 "../../src/scan-gram.l"
-return PERCENT_ERROR_VERBOSE;
- YY_BREAK
-case 16:
-YY_RULE_SETUP
-#line 220 "../../src/scan-gram.l"
-return PERCENT_EXPECT;
- YY_BREAK
-case 17:
-YY_RULE_SETUP
-#line 221 "../../src/scan-gram.l"
-return PERCENT_EXPECT_RR;
- YY_BREAK
-case 18:
-YY_RULE_SETUP
-#line 222 "../../src/scan-gram.l"
-return PERCENT_FILE_PREFIX;
- YY_BREAK
-case 19:
-YY_RULE_SETUP
-#line 223 "../../src/scan-gram.l"
-return PERCENT_YACC;
- YY_BREAK
-case 20:
-YY_RULE_SETUP
-#line 224 "../../src/scan-gram.l"
-return PERCENT_INITIAL_ACTION;
- YY_BREAK
-case 21:
-YY_RULE_SETUP
-#line 225 "../../src/scan-gram.l"
-return PERCENT_GLR_PARSER;
- YY_BREAK
-case 22:
-YY_RULE_SETUP
-#line 226 "../../src/scan-gram.l"
-return PERCENT_LANGUAGE;
- YY_BREAK
-case 23:
-YY_RULE_SETUP
-#line 227 "../../src/scan-gram.l"
-return PERCENT_LEFT;
- YY_BREAK
-case 24:
-YY_RULE_SETUP
-#line 228 "../../src/scan-gram.l"
-RETURN_PERCENT_PARAM(lex);
- YY_BREAK
-case 25:
-YY_RULE_SETUP
-#line 229 "../../src/scan-gram.l"
-RETURN_PERCENT_FLAG("locations");
- YY_BREAK
-case 26:
-YY_RULE_SETUP
-#line 230 "../../src/scan-gram.l"
-return PERCENT_MERGE;
- YY_BREAK
-case 27:
-YY_RULE_SETUP
-#line 231 "../../src/scan-gram.l"
-return PERCENT_NAME_PREFIX;
- YY_BREAK
-case 28:
-YY_RULE_SETUP
-#line 232 "../../src/scan-gram.l"
-return PERCENT_NO_DEFAULT_PREC;
- YY_BREAK
-case 29:
-YY_RULE_SETUP
-#line 233 "../../src/scan-gram.l"
-return PERCENT_NO_LINES;
- YY_BREAK
-case 30:
-YY_RULE_SETUP
-#line 234 "../../src/scan-gram.l"
-return PERCENT_NONASSOC;
- YY_BREAK
-case 31:
-YY_RULE_SETUP
-#line 235 "../../src/scan-gram.l"
-return PERCENT_NONDETERMINISTIC_PARSER;
- YY_BREAK
-case 32:
-YY_RULE_SETUP
-#line 236 "../../src/scan-gram.l"
-return PERCENT_NTERM;
- YY_BREAK
-case 33:
-YY_RULE_SETUP
-#line 237 "../../src/scan-gram.l"
-return PERCENT_OUTPUT;
- YY_BREAK
-case 34:
-YY_RULE_SETUP
-#line 238 "../../src/scan-gram.l"
-RETURN_PERCENT_PARAM(both);
- YY_BREAK
-case 35:
-YY_RULE_SETUP
-#line 239 "../../src/scan-gram.l"
-RETURN_PERCENT_PARAM(parse);
- YY_BREAK
-case 36:
-YY_RULE_SETUP
-#line 240 "../../src/scan-gram.l"
-return PERCENT_PREC;
- YY_BREAK
-case 37:
-YY_RULE_SETUP
-#line 241 "../../src/scan-gram.l"
-return PERCENT_PRECEDENCE;
- YY_BREAK
-case 38:
-YY_RULE_SETUP
-#line 242 "../../src/scan-gram.l"
-return PERCENT_PRINTER;
- YY_BREAK
-case 39:
-YY_RULE_SETUP
-#line 243 "../../src/scan-gram.l"
-RETURN_PERCENT_FLAG("api.pure");
- YY_BREAK
-case 40:
-YY_RULE_SETUP
-#line 244 "../../src/scan-gram.l"
-return PERCENT_REQUIRE;
- YY_BREAK
-case 41:
-YY_RULE_SETUP
-#line 245 "../../src/scan-gram.l"
-return PERCENT_RIGHT;
- YY_BREAK
-case 42:
-YY_RULE_SETUP
-#line 246 "../../src/scan-gram.l"
-return PERCENT_SKELETON;
- YY_BREAK
-case 43:
-YY_RULE_SETUP
-#line 247 "../../src/scan-gram.l"
-return PERCENT_START;
- YY_BREAK
-case 44:
-YY_RULE_SETUP
-#line 248 "../../src/scan-gram.l"
-return PERCENT_TOKEN;
- YY_BREAK
-case 45:
-YY_RULE_SETUP
-#line 249 "../../src/scan-gram.l"
-return PERCENT_TOKEN;
- YY_BREAK
-case 46:
-YY_RULE_SETUP
-#line 250 "../../src/scan-gram.l"
-return PERCENT_TOKEN_TABLE;
- YY_BREAK
-case 47:
-YY_RULE_SETUP
-#line 251 "../../src/scan-gram.l"
-return PERCENT_TYPE;
- YY_BREAK
-case 48:
-YY_RULE_SETUP
-#line 252 "../../src/scan-gram.l"
-return PERCENT_UNION;
- YY_BREAK
-case 49:
-YY_RULE_SETUP
-#line 253 "../../src/scan-gram.l"
-return PERCENT_VERBOSE;
- YY_BREAK
-case 50:
-YY_RULE_SETUP
-#line 254 "../../src/scan-gram.l"
-return PERCENT_YACC;
- YY_BREAK
-/* deprecated */
-case 51:
-YY_RULE_SETUP
-#line 257 "../../src/scan-gram.l"
-DEPRECATED("%default-prec");
- YY_BREAK
-case 52:
-YY_RULE_SETUP
-#line 258 "../../src/scan-gram.l"
-DEPRECATED("%define parse.error verbose");
- YY_BREAK
-case 53:
-YY_RULE_SETUP
-#line 259 "../../src/scan-gram.l"
-DEPRECATED("%expect-rr");
- YY_BREAK
-case 54:
-/* rule 54 can match eol */
-YY_RULE_SETUP
-#line 260 "../../src/scan-gram.l"
-DEPRECATED("%file-prefix");
- YY_BREAK
-case 55:
-YY_RULE_SETUP
-#line 261 "../../src/scan-gram.l"
-DEPRECATED("%fixed-output-files");
- YY_BREAK
-case 56:
-/* rule 56 can match eol */
-YY_RULE_SETUP
-#line 262 "../../src/scan-gram.l"
-DEPRECATED("%name-prefix");
- YY_BREAK
-case 57:
-YY_RULE_SETUP
-#line 263 "../../src/scan-gram.l"
-DEPRECATED("%no-default-prec");
- YY_BREAK
-case 58:
-YY_RULE_SETUP
-#line 264 "../../src/scan-gram.l"
-DEPRECATED("%no-lines");
- YY_BREAK
-case 59:
-/* rule 59 can match eol */
-YY_RULE_SETUP
-#line 265 "../../src/scan-gram.l"
-DEPRECATED("%output");
- YY_BREAK
-case 60:
-YY_RULE_SETUP
-#line 266 "../../src/scan-gram.l"
-DEPRECATED("%pure-parser");
- YY_BREAK
-case 61:
-YY_RULE_SETUP
-#line 267 "../../src/scan-gram.l"
-DEPRECATED("%token-table");
- YY_BREAK
-case 62:
-/* rule 62 can match eol */
-YY_RULE_SETUP
-#line 269 "../../src/scan-gram.l"
-{
- complain (loc, complaint, _("invalid directive: %s"), quote (gram_text));
- }
- YY_BREAK
-case 63:
-YY_RULE_SETUP
-#line 273 "../../src/scan-gram.l"
-return EQUAL;
- YY_BREAK
-case 64:
-YY_RULE_SETUP
-#line 274 "../../src/scan-gram.l"
-return PIPE;
- YY_BREAK
-case 65:
-YY_RULE_SETUP
-#line 275 "../../src/scan-gram.l"
-return SEMICOLON;
- YY_BREAK
-case 66:
-YY_RULE_SETUP
-#line 277 "../../src/scan-gram.l"
-{
- val->uniqstr = uniqstr_new (gram_text);
- id_loc = *loc;
- bracketed_id_str = NULL;
- BEGIN SC_AFTER_IDENTIFIER;
- }
- YY_BREAK
-case 67:
-YY_RULE_SETUP
-#line 284 "../../src/scan-gram.l"
-{
- val->integer = scan_integer (gram_text, 10, *loc);
- return INT;
- }
- YY_BREAK
-case 68:
-YY_RULE_SETUP
-#line 288 "../../src/scan-gram.l"
-{
- val->integer = scan_integer (gram_text, 16, *loc);
- return INT;
- }
- YY_BREAK
-/* Identifiers may not start with a digit. Yet, don't silently
- accept "1FOO" as "1 FOO". */
-case 69:
-YY_RULE_SETUP
-#line 295 "../../src/scan-gram.l"
-{
- complain (loc, complaint, _("invalid identifier: %s"), quote (gram_text));
- }
- YY_BREAK
-/* Characters. */
-case 70:
-YY_RULE_SETUP
-#line 300 "../../src/scan-gram.l"
-token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
- YY_BREAK
-/* Strings. */
-case 71:
-YY_RULE_SETUP
-#line 303 "../../src/scan-gram.l"
-token_start = loc->start; BEGIN SC_ESCAPED_STRING;
- YY_BREAK
-/* Prologue. */
-case 72:
-YY_RULE_SETUP
-#line 306 "../../src/scan-gram.l"
-code_start = loc->start; BEGIN SC_PROLOGUE;
- YY_BREAK
-/* Code in between braces. */
-case 73:
-YY_RULE_SETUP
-#line 309 "../../src/scan-gram.l"
-{
- STRING_GROW;
- nesting = 0;
- code_start = loc->start;
- BEGIN SC_BRACED_CODE;
- }
- YY_BREAK
-/* Semantic predicate. */
-case 74:
-/* rule 74 can match eol */
-YY_RULE_SETUP
-#line 317 "../../src/scan-gram.l"
-{
- nesting = 0;
- code_start = loc->start;
- BEGIN SC_PREDICATE;
- }
- YY_BREAK
-/* A type. */
-case 75:
-YY_RULE_SETUP
-#line 324 "../../src/scan-gram.l"
-return TAG_ANY;
- YY_BREAK
-case 76:
-YY_RULE_SETUP
-#line 325 "../../src/scan-gram.l"
-return TAG_NONE;
- YY_BREAK
-case 77:
-YY_RULE_SETUP
-#line 326 "../../src/scan-gram.l"
-{
- nesting = 0;
- token_start = loc->start;
- BEGIN SC_TAG;
- }
- YY_BREAK
-case 78:
-YY_RULE_SETUP
-#line 332 "../../src/scan-gram.l"
-{
- static int percent_percent_count;
- if (++percent_percent_count == 2)
- BEGIN SC_EPILOGUE;
- return PERCENT_PERCENT;
- }
- YY_BREAK
-case 79:
-YY_RULE_SETUP
-#line 339 "../../src/scan-gram.l"
-{
- bracketed_id_str = NULL;
- bracketed_id_start = loc->start;
- bracketed_id_context_state = YY_START;
- BEGIN SC_BRACKETED_ID;
- }
- YY_BREAK
-case 80:
-YY_RULE_SETUP
-#line 346 "../../src/scan-gram.l"
-{
- complain (loc, complaint, "%s: %s",
- ngettext ("invalid character", "invalid characters", gram_leng),
- quote_mem (gram_text, gram_leng));
- }
- YY_BREAK
-case YY_STATE_EOF(INITIAL):
-#line 352 "../../src/scan-gram.l"
-{
- loc->start = loc->end = scanner_cursor;
- yyterminate ();
- }
- YY_BREAK
-
-/*--------------------------------------------------------------.
- | Supporting \0 complexifies our implementation for no expected |
- | added value. |
- `--------------------------------------------------------------*/
-
-
-case 81:
-YY_RULE_SETUP
-#line 366 "../../src/scan-gram.l"
-complain (loc, complaint, _("invalid null character"));
- YY_BREAK
-
-/*-----------------------------------------------------------------.
- | Scanning after an identifier, checking whether a colon is next. |
- `-----------------------------------------------------------------*/
-
-
-case 82:
-YY_RULE_SETUP
-#line 376 "../../src/scan-gram.l"
-{
- if (bracketed_id_str)
- {
- ROLLBACK_CURRENT_TOKEN;
- BEGIN SC_RETURN_BRACKETED_ID;
- *loc = id_loc;
- return ID;
- }
- else
- {
- bracketed_id_start = loc->start;
- bracketed_id_context_state = YY_START;
- BEGIN SC_BRACKETED_ID;
- }
- }
- YY_BREAK
-case 83:
-YY_RULE_SETUP
-#line 391 "../../src/scan-gram.l"
-{
- BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
- *loc = id_loc;
- return ID_COLON;
- }
- YY_BREAK
-case 84:
-YY_RULE_SETUP
-#line 396 "../../src/scan-gram.l"
-{
- ROLLBACK_CURRENT_TOKEN;
- BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
- *loc = id_loc;
- return ID;
- }
- YY_BREAK
-case YY_STATE_EOF(SC_AFTER_IDENTIFIER):
-#line 402 "../../src/scan-gram.l"
-{
- BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
- *loc = id_loc;
- return ID;
- }
- YY_BREAK
-
-/*--------------------------------.
- | Scanning bracketed identifiers. |
- `--------------------------------*/
-
-
-case 85:
-YY_RULE_SETUP
-#line 415 "../../src/scan-gram.l"
-{
- if (bracketed_id_str)
- {
- complain (loc, complaint,
- _("unexpected identifier in bracketed name: %s"),
- quote (gram_text));
- }
- else
- {
- bracketed_id_str = uniqstr_new (gram_text);
- bracketed_id_loc = *loc;
- }
- }
- YY_BREAK
-case 86:
-YY_RULE_SETUP
-#line 428 "../../src/scan-gram.l"
-{
- BEGIN bracketed_id_context_state;
- if (bracketed_id_str)
- {
- if (INITIAL == bracketed_id_context_state)
- {
- val->uniqstr = bracketed_id_str;
- bracketed_id_str = 0;
- *loc = bracketed_id_loc;
- return BRACKETED_ID;
- }
- }
- else
- complain (loc, complaint, _("an identifier expected"));
- }
- YY_BREAK
-case 87:
-YY_RULE_SETUP
-#line 444 "../../src/scan-gram.l"
-{
- complain (loc, complaint, "%s: %s",
- ngettext ("invalid character in bracketed name",
- "invalid characters in bracketed name", gram_leng),
- quote_mem (gram_text, gram_leng));
- }
- YY_BREAK
-case YY_STATE_EOF(SC_BRACKETED_ID):
-#line 451 "../../src/scan-gram.l"
-{
- BEGIN bracketed_id_context_state;
- unexpected_eof (bracketed_id_start, "]");
- }
- YY_BREAK
-
-
-
-case 88:
-YY_RULE_SETUP
-#line 459 "../../src/scan-gram.l"
-{
- ROLLBACK_CURRENT_TOKEN;
- val->uniqstr = bracketed_id_str;
- bracketed_id_str = 0;
- *loc = bracketed_id_loc;
- BEGIN INITIAL;
- return BRACKETED_ID;
- }
- YY_BREAK
-
-/*---------------------------------------------------------------.
- | Scanning a Yacc comment. The initial '/ *' is already eaten. |
- `---------------------------------------------------------------*/
-
-
-case 89:
-YY_RULE_SETUP
-#line 476 "../../src/scan-gram.l"
-BEGIN context_state;
- YY_BREAK
-case 90:
-/* rule 90 can match eol */
-YY_RULE_SETUP
-#line 477 "../../src/scan-gram.l"
-continue;
- YY_BREAK
-case YY_STATE_EOF(SC_YACC_COMMENT):
-#line 478 "../../src/scan-gram.l"
-unexpected_eof (token_start, "*/"); BEGIN context_state;
- YY_BREAK
-
-/*------------------------------------------------------------.
- | Scanning a C comment. The initial '/ *' is already eaten. |
- `------------------------------------------------------------*/
-
-
-case 91:
-/* rule 91 can match eol */
-YY_RULE_SETUP
-#line 488 "../../src/scan-gram.l"
-STRING_GROW; BEGIN context_state;
- YY_BREAK
-case YY_STATE_EOF(SC_COMMENT):
-#line 489 "../../src/scan-gram.l"
-unexpected_eof (token_start, "*/"); BEGIN context_state;
- YY_BREAK
-
-/*--------------------------------------------------------------.
- | Scanning a line comment. The initial '//' is already eaten. |
- `--------------------------------------------------------------*/
-
-
-case 92:
-/* rule 92 can match eol */
-YY_RULE_SETUP
-#line 499 "../../src/scan-gram.l"
-STRING_GROW; BEGIN context_state;
- YY_BREAK
-case 93:
-/* rule 93 can match eol */
-YY_RULE_SETUP
-#line 500 "../../src/scan-gram.l"
-STRING_GROW;
- YY_BREAK
-case YY_STATE_EOF(SC_LINE_COMMENT):
-#line 501 "../../src/scan-gram.l"
-BEGIN context_state;
- YY_BREAK
-
-/*------------------------------------------------.
- | Scanning a Bison string, including its escapes. |
- | The initial quote is already eaten. |
- `------------------------------------------------*/
-
-
-case 94:
-YY_RULE_SETUP
-#line 512 "../../src/scan-gram.l"
-{
- STRING_FINISH;
- loc->start = token_start;
- val->code = last_string;
- BEGIN INITIAL;
- return STRING;
- }
- YY_BREAK
-case YY_STATE_EOF(SC_ESCAPED_STRING):
-#line 519 "../../src/scan-gram.l"
-unexpected_eof (token_start, "\"");
- YY_BREAK
-case 95:
-/* rule 95 can match eol */
-YY_RULE_SETUP
-#line 520 "../../src/scan-gram.l"
-unexpected_newline (token_start, "\"");
- YY_BREAK
-
-/*----------------------------------------------------------.
- | Scanning a Bison character literal, decoding its escapes. |
- | The initial quote is already eaten. |
- `----------------------------------------------------------*/
-
-
-case 96:
-YY_RULE_SETUP
-#line 530 "../../src/scan-gram.l"
-{
- STRING_FINISH;
- loc->start = token_start;
- val->character = last_string[0];
-
- /* FIXME: Eventually, make these errors. */
- if (last_string[0] == '\0')
- {
- complain (loc, Wother, _("empty character literal"));
- /* '\0' seems dangerous even if we are about to complain. */
- val->character = '\'';
- }
- else if (last_string[1] != '\0')
- complain (loc, Wother,
- _("extra characters in character literal"));
- STRING_FREE;
- BEGIN INITIAL;
- return CHAR;
- }
- YY_BREAK
-case 97:
-/* rule 97 can match eol */
-YY_RULE_SETUP
-#line 549 "../../src/scan-gram.l"
-unexpected_newline (token_start, "'");
- YY_BREAK
-case YY_STATE_EOF(SC_ESCAPED_CHARACTER):
-#line 550 "../../src/scan-gram.l"
-unexpected_eof (token_start, "'");
- YY_BREAK
-
-/*--------------------------------------------------------------.
- | Scanning a tag. The initial angle bracket is already eaten. |
- `--------------------------------------------------------------*/
-
-
-case 98:
-YY_RULE_SETUP
-#line 561 "../../src/scan-gram.l"
-{
- --nesting;
- if (nesting < 0)
- {
- STRING_FINISH;
- loc->start = token_start;
- val->uniqstr = uniqstr_new (last_string);
- STRING_FREE;
- BEGIN INITIAL;
- return TAG;
- }
- STRING_GROW;
- }
- YY_BREAK
-case 99:
-/* rule 99 can match eol */
-YY_RULE_SETUP
-#line 575 "../../src/scan-gram.l"
-STRING_GROW;
- YY_BREAK
-case 100:
-YY_RULE_SETUP
-#line 576 "../../src/scan-gram.l"
-STRING_GROW; nesting += gram_leng;
- YY_BREAK
-case YY_STATE_EOF(SC_TAG):
-#line 578 "../../src/scan-gram.l"
-unexpected_eof (token_start, ">");
- YY_BREAK
-
-/*----------------------------.
- | Decode escaped characters. |
- `----------------------------*/
-
-
-case 101:
-YY_RULE_SETUP
-#line 587 "../../src/scan-gram.l"
-{
- unsigned long int c = strtoul (gram_text + 1, NULL, 8);
- if (!c || UCHAR_MAX < c)
- complain (loc, complaint, _("invalid number after \\-escape: %s"),
- gram_text+1);
- else
- obstack_1grow (&obstack_for_string, c);
- }
- YY_BREAK
-case 102:
-YY_RULE_SETUP
-#line 596 "../../src/scan-gram.l"
-{
- verify (UCHAR_MAX < ULONG_MAX);
- unsigned long int c = strtoul (gram_text + 2, NULL, 16);
- if (!c || UCHAR_MAX < c)
- complain (loc, complaint, _("invalid number after \\-escape: %s"),
- gram_text+1);
- else
- obstack_1grow (&obstack_for_string, c);
- }
- YY_BREAK
-case 103:
-YY_RULE_SETUP
-#line 606 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, '\a');
- YY_BREAK
-case 104:
-YY_RULE_SETUP
-#line 607 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, '\b');
- YY_BREAK
-case 105:
-YY_RULE_SETUP
-#line 608 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, '\f');
- YY_BREAK
-case 106:
-YY_RULE_SETUP
-#line 609 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, '\n');
- YY_BREAK
-case 107:
-YY_RULE_SETUP
-#line 610 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, '\r');
- YY_BREAK
-case 108:
-YY_RULE_SETUP
-#line 611 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, '\t');
- YY_BREAK
-case 109:
-YY_RULE_SETUP
-#line 612 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, '\v');
- YY_BREAK
-/* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
-case 110:
-YY_RULE_SETUP
-#line 615 "../../src/scan-gram.l"
-obstack_1grow (&obstack_for_string, gram_text[1]);
- YY_BREAK
-case 111:
-YY_RULE_SETUP
-#line 617 "../../src/scan-gram.l"
-{
- int c = convert_ucn_to_byte (gram_text);
- if (c <= 0)
- complain (loc, complaint, _("invalid number after \\-escape: %s"),
- gram_text+1);
- else
- obstack_1grow (&obstack_for_string, c);
- }
- YY_BREAK
-case 112:
-/* rule 112 can match eol */
-YY_RULE_SETUP
-#line 625 "../../src/scan-gram.l"
-{
- char const *p = gram_text + 1;
- /* Quote only if escaping won't make the character visible. */
- if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
- p = quote (p);
- else
- p = quotearg_style_mem (escape_quoting_style, p, 1);
- complain (loc, complaint, _("invalid character after \\-escape: %s"),
- p);
- }
- YY_BREAK
-
-/*--------------------------------------------.
- | Scanning user-code characters and strings. |
- `--------------------------------------------*/
-
-
-case 113:
-/* rule 113 can match eol */
-YY_RULE_SETUP
-#line 643 "../../src/scan-gram.l"
-STRING_GROW;
- YY_BREAK
-
-
-
-case 114:
-YY_RULE_SETUP
-#line 648 "../../src/scan-gram.l"
-STRING_GROW; BEGIN context_state;
- YY_BREAK
-case 115:
-/* rule 115 can match eol */
-YY_RULE_SETUP
-#line 649 "../../src/scan-gram.l"
-unexpected_newline (token_start, "'");
- YY_BREAK
-case YY_STATE_EOF(SC_CHARACTER):
-#line 650 "../../src/scan-gram.l"
-unexpected_eof (token_start, "'");
- YY_BREAK
-
-
-
-case 116:
-YY_RULE_SETUP
-#line 655 "../../src/scan-gram.l"
-STRING_GROW; BEGIN context_state;
- YY_BREAK
-case 117:
-/* rule 117 can match eol */
-YY_RULE_SETUP
-#line 656 "../../src/scan-gram.l"
-unexpected_newline (token_start, "\"");
- YY_BREAK
-case YY_STATE_EOF(SC_STRING):
-#line 657 "../../src/scan-gram.l"
-unexpected_eof (token_start, "\"");
- YY_BREAK
-
-/*---------------------------------------------------.
- | Strings, comments etc. can be found in user code. |
- `---------------------------------------------------*/
-
-
-case 118:
-YY_RULE_SETUP
-#line 667 "../../src/scan-gram.l"
-{
- STRING_GROW;
- context_state = YY_START;
- token_start = loc->start;
- BEGIN SC_CHARACTER;
- }
- YY_BREAK
-case 119:
-YY_RULE_SETUP
-#line 673 "../../src/scan-gram.l"
-{
- STRING_GROW;
- context_state = YY_START;
- token_start = loc->start;
- BEGIN SC_STRING;
- }
- YY_BREAK
-case 120:
-/* rule 120 can match eol */
-YY_RULE_SETUP
-#line 679 "../../src/scan-gram.l"
-{
- STRING_GROW;
- context_state = YY_START;
- token_start = loc->start;
- BEGIN SC_COMMENT;
- }
- YY_BREAK
-case 121:
-/* rule 121 can match eol */
-YY_RULE_SETUP
-#line 685 "../../src/scan-gram.l"
-{
- STRING_GROW;
- context_state = YY_START;
- BEGIN SC_LINE_COMMENT;
- }
- YY_BREAK
-
-/*-----------------------------------------------------------.
- | Scanning some code in braces (actions, predicates). The |
- | initial "{" is already eaten. |
- `-----------------------------------------------------------*/
-
-
-case 122:
-/* rule 122 can match eol */
-YY_RULE_SETUP
-#line 701 "../../src/scan-gram.l"
-STRING_GROW; nesting++;
- YY_BREAK
-case 123:
-/* rule 123 can match eol */
-YY_RULE_SETUP
-#line 702 "../../src/scan-gram.l"
-STRING_GROW; nesting--;
- YY_BREAK
-/* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
- (as '<' '<%'). */
-case 124:
-/* rule 124 can match eol */
-YY_RULE_SETUP
-#line 706 "../../src/scan-gram.l"
-STRING_GROW;
- YY_BREAK
-case YY_STATE_EOF(SC_BRACED_CODE):
-case YY_STATE_EOF(SC_PREDICATE):
-#line 708 "../../src/scan-gram.l"
-unexpected_eof (code_start, "}");
- YY_BREAK
-
-
-
-case 125:
-YY_RULE_SETUP
-#line 713 "../../src/scan-gram.l"
-{
- obstack_1grow (&obstack_for_string, '}');
-
- --nesting;
- if (nesting < 0)
- {
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return BRACED_CODE;
- }
- }
- YY_BREAK
-
-
-
-case 126:
-YY_RULE_SETUP
-#line 730 "../../src/scan-gram.l"
-{
- --nesting;
- if (nesting < 0)
- {
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return BRACED_PREDICATE;
- }
- else
- obstack_1grow (&obstack_for_string, '}');
- }
- YY_BREAK
-
-/*--------------------------------------------------------------.
- | Scanning some prologue: from "%{" (already scanned) to "%}". |
- `--------------------------------------------------------------*/
-
-
-case 127:
-YY_RULE_SETUP
-#line 751 "../../src/scan-gram.l"
-{
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return PROLOGUE;
- }
- YY_BREAK
-case YY_STATE_EOF(SC_PROLOGUE):
-#line 759 "../../src/scan-gram.l"
-unexpected_eof (code_start, "%}");
- YY_BREAK
-
-/*---------------------------------------------------------------.
- | Scanning the epilogue (everything after the second "%%", which |
- | has already been eaten). |
- `---------------------------------------------------------------*/
-
-
-case YY_STATE_EOF(SC_EPILOGUE):
-#line 770 "../../src/scan-gram.l"
-{
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return EPILOGUE;
- }
- YY_BREAK
-
-/*-----------------------------------------------------.
- | By default, grow the string obstack with the input. |
- `-----------------------------------------------------*/
-case 128:
-#line 785 "../../src/scan-gram.l"
-case 129:
-/* rule 129 can match eol */
-YY_RULE_SETUP
-#line 785 "../../src/scan-gram.l"
-STRING_GROW;
- YY_BREAK
-case 130:
-YY_RULE_SETUP
-#line 787 "../../src/scan-gram.l"
-YY_FATAL_ERROR( "flex scanner jammed" );
- YY_BREAK
-#line 2661 "src/scan-gram.c"
-case YY_STATE_EOF(SC_RETURN_BRACKETED_ID):
- yyterminate();
-
- case YY_END_OF_BUFFER:
- {
- /* Amount of text matched not including the EOB char. */
- int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
-
- /* Undo the effects of YY_DO_BEFORE_ACTION. */
- *yy_cp = (yy_hold_char);
- YY_RESTORE_YY_MORE_OFFSET
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
- {
- /* We're scanning a new file or input source. It's
- * possible that this happened because the user
- * just pointed gram_in at a new source and called
- * gram_lex(). If so, then we have to assure
- * consistency between YY_CURRENT_BUFFER and our
- * globals. Here is the right place to do so, because
- * this is the first action (other than possibly a
- * back-up) that will match for the new input source.
- */
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- YY_CURRENT_BUFFER_LVALUE->yy_input_file = gram_in;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
- }
-
- /* Note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the
- * end-of-buffer state). Contrast this with the test
- * in input().
- */
- if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- { /* This was really a NUL. */
- yy_state_type yy_next_state;
-
- (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- /* Okay, we're now positioned to make the NUL
- * transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we don't
- * want to build jamming into it because then it
- * will run more slowly).
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state );
-
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* Consume the NUL. */
- yy_cp = ++(yy_c_buf_p);
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
-/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_END_OF_FILE:
- {
- (yy_did_buffer_switch_on_eof) = 0;
-
- if ( gram_wrap( ) )
- {
- /* Note: because we've taken care in
- * yy_get_next_buffer() to have set up
- * gram_text, we can now set up
- * yy_c_buf_p so that if some total
- * hoser (like flex itself) wants to
- * call the scanner after we return the
- * YY_NULL, it'll still work - another
- * YY_NULL will get returned.
- */
- (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF(YY_START);
- goto do_action;
- }
-
- else
- {
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
- }
- break;
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) =
- (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- (yy_c_buf_p) =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- } /* end of action switch */
- } /* end of scanning one token */
-} /* end of gram_lex */
-/* %ok-for-header */
-
-/* %if-c++-only */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %endif */
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-/* %if-c-only */
-static int yy_get_next_buffer (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
- register char *source = (yytext_ptr);
- register int number_to_move, i;
- int ret_val;
-
- if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
- { /* Don't try to fill the buffer, so this is an EOF. */
- if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
- {
- /* We matched a single character, the EOB, so
- * treat this as a final EOF.
- */
- return EOB_ACT_END_OF_FILE;
- }
-
- else
- {
- /* We matched some text prior to the EOB, first
- * process it.
- */
- return EOB_ACT_LAST_MATCH;
- }
- }
-
- /* Try to read more data. */
-
- /* First move last chars to start of buffer. */
- number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
-
- else
- {
- yy_size_t num_to_read =
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
-
- while ( num_to_read <= 0 )
- { /* Not enough room in the buffer - grow it. */
-
- /* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
-
- int yy_c_buf_p_offset =
- (int) ((yy_c_buf_p) - b->yy_ch_buf);
-
- if ( b->yy_is_our_buffer )
- {
- yy_size_t new_size = b->yy_buf_size * 2;
-
- if ( new_size <= 0 )
- b->yy_buf_size += b->yy_buf_size / 8;
- else
- b->yy_buf_size *= 2;
-
- b->yy_ch_buf = (char *)
- /* Include room in for 2 EOB chars. */
- gram_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
- }
- else
- /* Can't grow it, we don't own it. */
- b->yy_ch_buf = 0;
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
-
- (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
-
- num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
- number_to_move - 1;
-
- }
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- /* Read in more data. */
- YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- (yy_n_chars), num_to_read );
-
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- if ( (yy_n_chars) == 0 )
- {
- if ( number_to_move == YY_MORE_ADJ )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- gram_restart(gram_in );
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
- YY_BUFFER_EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
- /* Extend the array by 50%, plus the number we really need. */
- yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) gram_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
- if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
- }
-
- (yy_n_chars) += number_to_move;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
-
- (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
-
- return ret_val;
-}
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
-/* %if-c-only */
-/* %not-for-header */
-
- static yy_state_type yy_get_previous_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register yy_state_type yy_current_state;
- register char *yy_cp;
-
-/* %% [15.0] code to get the start state into yy_current_state goes here */
- yy_current_state = (yy_start);
- yy_current_state += YY_AT_BOL();
-
- for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
- {
-/* %% [16.0] code to find the next state goes here */
- register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 59);
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 582 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- }
-
- return yy_current_state;
-}
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
-/* %if-c-only */
- static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register int yy_is_jam;
- /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
- register char *yy_cp = (yy_c_buf_p);
-
- register YY_CHAR yy_c = 59;
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 582 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 581);
-
- return yy_is_jam ? 0 : yy_current_state;
-}
-
-/* %if-c-only */
-
- static void yyunput (int c, register char * yy_bp )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register char *yy_cp;
-
- yy_cp = (yy_c_buf_p);
-
- /* undo effects of setting up gram_text */
- *yy_cp = (yy_hold_char);
-
- if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
- { /* need to shift things up to make room */
- /* +2 for EOB chars. */
- register yy_size_t number_to_move = (yy_n_chars) + 2;
- register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
- register char *source =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
-
- while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- *--dest = *--source;
-
- yy_cp += (int) (dest - source);
- yy_bp += (int) (dest - source);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
-
- if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
- YY_FATAL_ERROR( "flex scanner push-back overflow" );
- }
-
- *--yy_cp = (char) c;
-
-/* %% [18.0] update gram_lineno here */
-
- (yytext_ptr) = yy_bp;
- (yy_hold_char) = *yy_cp;
- (yy_c_buf_p) = yy_cp;
-}
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c-only */
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
- static int yyinput (void)
-#else
- static int input (void)
-#endif
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- int c;
-
- *(yy_c_buf_p) = (yy_hold_char);
-
- if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- /* This was really a NUL. */
- *(yy_c_buf_p) = '\0';
-
- else
- { /* need more input */
- yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
- ++(yy_c_buf_p);
-
- switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_LAST_MATCH:
- /* This happens because yy_g_n_b()
- * sees that we've accumulated a
- * token and flags that we need to
- * try matching the token before
- * proceeding. But for input(),
- * there's no matching to consider.
- * So convert the EOB_ACT_LAST_MATCH
- * to EOB_ACT_END_OF_FILE.
- */
-
- /* Reset buffer status. */
- gram_restart(gram_in );
-
- /*FALLTHROUGH*/
-
- case EOB_ACT_END_OF_FILE:
- {
- if ( gram_wrap( ) )
- return EOF;
-
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
-#ifdef __cplusplus
- return yyinput();
-#else
- return input();
-#endif
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) = (yytext_ptr) + offset;
- break;
- }
- }
- }
-
- c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
- *(yy_c_buf_p) = '\0'; /* preserve gram_text */
- (yy_hold_char) = *++(yy_c_buf_p);
-
-/* %% [19.0] update BOL and gram_lineno */
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n');
-
- return c;
-}
-/* %if-c-only */
-#endif /* ifndef YY_NO_INPUT */
-/* %endif */
-
-/** Immediately switch to a different input stream.
- * @param input_file A readable stream.
+#line 2 "src/scan-gram.c"
+
+#line 4 "src/scan-gram.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+/* %not-for-header */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+#define yy_create_buffer gram__create_buffer
+#define yy_delete_buffer gram__delete_buffer
+#define yy_flex_debug gram__flex_debug
+#define yy_init_buffer gram__init_buffer
+#define yy_flush_buffer gram__flush_buffer
+#define yy_load_buffer_state gram__load_buffer_state
+#define yy_switch_to_buffer gram__switch_to_buffer
+#define yyin gram_in
+#define yyleng gram_leng
+#define yylex gram_lex
+#define yylineno gram_lineno
+#define yyout gram_out
+#define yyrestart gram_restart
+#define yytext gram_text
+#define yywrap gram_wrap
+#define yyalloc gram_alloc
+#define yyrealloc gram_realloc
+#define yyfree gram_free
+
+/* %endif */
+/* %endif */
+/* %ok-for-header */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 37
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* %if-c++-only */
+/* %endif */
+
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c-only */
+
+/* %endif */
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+/* %if-c-only */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+/* %endif */
+
+/* %if-tables-serialization */
+/* %endif */
+/* end standard C headers. */
+
+/* %if-c-or-c++ */
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* %not-for-header */
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+/* %ok-for-header */
+
+/* %if-reentrant */
+/* %endif */
+
+/* %if-not-reentrant */
+
+/* %endif */
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE gram_restart(gram_in )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+/* %if-not-reentrant */
+extern yy_size_t gram_leng;
+/* %endif */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+extern FILE *gram_in, *gram_out;
+/* %endif */
+/* %endif */
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up gram_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up gram_text again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+/* %if-c-only */
+ FILE *yy_input_file;
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ yy_size_t yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via gram_restart()), so that the user can continue scanning by
+ * just pointing gram_in at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+/* %if-not-reentrant */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
+/* %endif */
+/* %ok-for-header */
+
+/* %endif */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
*
- * @note This function does not reset the start condition to @c INITIAL .
- */
-/* %if-c-only */
- void gram_restart (FILE * input_file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! YY_CURRENT_BUFFER ){
- gram_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- gram__create_buffer(gram_in,YY_BUF_SIZE );
- }
-
- gram__init_buffer(YY_CURRENT_BUFFER,input_file );
- gram__load_buffer_state( );
-}
-
-/** Switch to a different input buffer.
- * @param new_buffer The new input buffer.
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* %if-c-only Standard (non-C++) definition */
+
+/* %if-not-reentrant */
+/* %not-for-header */
+
+/* yy_hold_char holds the character lost when gram_text is formed. */
+static char yy_hold_char;
+static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
+yy_size_t gram_leng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow gram_wrap()'s to do buffer switches
+ * instead of setting up a fresh gram_in. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+/* %ok-for-header */
+
+/* %endif */
+
+void gram_restart (FILE *input_file );
+void gram__switch_to_buffer (YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE gram__create_buffer (FILE *file,int size );
+void gram__delete_buffer (YY_BUFFER_STATE b );
+void gram__flush_buffer (YY_BUFFER_STATE b );
+void gram_push_buffer_state (YY_BUFFER_STATE new_buffer );
+void gram_pop_buffer_state (void );
+
+static void gram_ensure_buffer_stack (void );
+static void gram__load_buffer_state (void );
+static void gram__init_buffer (YY_BUFFER_STATE b,FILE *file );
+
+#define YY_FLUSH_BUFFER gram__flush_buffer(YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE gram__scan_buffer (char *base,yy_size_t size );
+YY_BUFFER_STATE gram__scan_string (yyconst char *yy_str );
+YY_BUFFER_STATE gram__scan_bytes (yyconst char *bytes,yy_size_t len );
+
+/* %endif */
+
+void *gram_alloc (yy_size_t );
+void *gram_realloc (void *,yy_size_t );
+void gram_free (void * );
+
+#define yy_new_buffer gram__create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ gram_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ gram__create_buffer(gram_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ gram_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ gram__create_buffer(gram_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* %% [1.0] gram_text/gram_in/gram_out/yy_state_type/gram_lineno etc. def's & init go here */
+/* Begin user sect3 */
+
+#define gram_wrap() 1
+#define YY_SKIP_YYWRAP
+
+#define FLEX_DEBUG
+
+typedef unsigned char YY_CHAR;
+
+FILE *gram_in = (FILE *) 0, *gram_out = (FILE *) 0;
+
+typedef int yy_state_type;
+
+extern int gram_lineno;
+
+int gram_lineno = 1;
+
+extern char *gram_text;
+#define yytext_ptr gram_text
+
+/* %if-c-only Standard (non-C++) definition */
+
+static yy_state_type yy_get_previous_state (void );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
+static int yy_get_next_buffer (void );
+static void yy_fatal_error (yyconst char msg[] );
+
+/* %endif */
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up gram_text.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+/* %% [2.0] code to fiddle gram_text and gram_leng for yymore() goes here \ */\
+ gram_leng = (size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+/* %% [3.0] code to copy yytext_ptr to gram_text[] goes here, if %array \ */\
+ (yy_c_buf_p) = yy_cp;
+
+/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
+#define YY_NUM_RULES 130
+#define YY_END_OF_BUFFER 131
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[582] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 93, 93, 113, 113, 113, 113, 0, 0,
+ 0, 0, 131, 80, 2, 2, 71, 80, 70, 80,
+ 1, 66, 80, 67, 67, 65, 77, 63, 66, 79,
+ 73, 64, 80, 90, 90, 128, 95, 94, 128, 81,
+ 97, 96, 84, 2, 1, 84, 83, 82, 84, 99,
+ 99, 100, 98, 81, 129, 119, 128, 118, 128, 128,
+ 128, 122, 125, 126, 128, 92, 128, 117, 116, 128,
+ 115, 114, 87, 2, 1, 85, 87, 87, 86, 87,
+
+ 88, 2, 1, 88, 88, 80, 0, 78, 62, 0,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 72, 66,
+ 66, 4, 3, 69, 67, 69, 0, 76, 0, 89,
+ 112, 110, 101, 112, 103, 104, 105, 106, 107, 108,
+ 112, 109, 112, 99, 99, 100, 127, 120, 121, 0,
+ 123, 0, 122, 124, 0, 91, 0, 0, 93, 113,
+ 113, 113, 113, 87, 85, 62, 62, 0, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 3, 69, 68, 75, 0, 101, 0, 0, 102, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 74, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 0, 101, 0, 0, 62, 7, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 23, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+
+ 62, 62, 62, 62, 62, 36, 62, 62, 62, 62,
+ 62, 62, 44, 62, 47, 62, 62, 50, 0, 0,
+ 0, 62, 8, 62, 62, 62, 13, 14, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 26, 62, 62,
+ 62, 62, 62, 62, 62, 62, 32, 62, 34, 62,
+ 62, 62, 62, 62, 62, 41, 62, 43, 45, 48,
+ 62, 0, 0, 111, 6, 62, 10, 62, 62, 62,
+ 16, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 33, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 0, 62,
+
+ 11, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 0, 59, 62, 62, 38, 62, 62, 40,
+ 62, 62, 62, 49, 5, 0, 62, 62, 62, 62,
+ 62, 62, 62, 62, 62, 62, 62, 62, 22, 62,
+ 62, 62, 62, 62, 29, 62, 58, 30, 62, 62,
+ 62, 62, 62, 42, 62, 62, 0, 62, 62, 62,
+ 62, 62, 17, 53, 62, 62, 62, 62, 62, 24,
+ 25, 62, 62, 62, 62, 62, 62, 62, 62, 62,
+ 62, 62, 0, 0, 62, 62, 12, 62, 62, 62,
+
+ 62, 62, 21, 62, 62, 62, 62, 62, 62, 62,
+ 37, 62, 62, 62, 62, 62, 62, 62, 62, 18,
+ 62, 62, 62, 27, 56, 62, 62, 62, 35, 39,
+ 60, 46, 61, 9, 51, 62, 62, 0, 54, 62,
+ 62, 62, 0, 56, 62, 62, 62, 15, 52, 62,
+ 62, 62, 62, 62, 62, 62, 62, 20, 62, 62,
+ 62, 62, 62, 28, 57, 62, 62, 62, 62, 62,
+ 62, 62, 19, 55, 62, 62, 62, 62, 62, 31,
+ 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 2, 2, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 5, 6, 7, 8, 6, 9, 6, 10, 6,
+ 6, 11, 6, 12, 13, 14, 15, 16, 17, 17,
+ 17, 17, 17, 17, 17, 18, 18, 19, 20, 21,
+ 22, 23, 24, 6, 25, 25, 25, 25, 25, 25,
+ 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 27, 26, 26, 28, 26, 26,
+ 29, 30, 31, 6, 32, 6, 33, 34, 35, 36,
+
+ 37, 38, 39, 40, 41, 26, 42, 43, 44, 45,
+ 46, 47, 48, 49, 50, 51, 52, 53, 26, 54,
+ 55, 26, 56, 57, 58, 6, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[60] =
+ { 0,
+ 1, 2, 3, 1, 2, 4, 5, 4, 5, 5,
+ 5, 5, 6, 7, 8, 9, 9, 9, 4, 5,
+ 10, 5, 10, 4, 9, 11, 11, 11, 12, 4,
+ 13, 11, 9, 9, 9, 9, 9, 9, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 5, 5, 5, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[609] =
+ { 0,
+ 0, 1065, 1061, 1060, 57, 58, 59, 60, 79, 94,
+ 53, 62, 117, 126, 135, 144, 100, 145, 154, 163,
+ 68, 69, 65, 70, 98, 155, 101, 164, 221, 1062,
+ 174, 193, 1069, 0, 1074, 1074, 1074, 280, 1074, 1074,
+ 1074, 339, 119, 164, 197, 1074, 114, 1074, 398, 1074,
+ 1074, 1074, 1025, 1074, 1052, 1074, 1074, 1074, 451, 1074,
+ 1074, 1074, 1074, 1074, 1074, 128, 1074, 1074, 1023, 1052,
+ 54, 1043, 1074, 1050, 1074, 1074, 1004, 1074, 331, 63,
+ 190, 1074, 1074, 1074, 153, 1074, 185, 1074, 1074, 346,
+ 1074, 1074, 0, 1074, 0, 0, 192, 1074, 1074, 1018,
+
+ 1074, 1074, 1074, 339, 1017, 0, 0, 1074, 0, 354,
+ 1018, 1012, 169, 311, 1016, 1013, 1010, 329, 1017, 331,
+ 1001, 334, 331, 98, 334, 1007, 1014, 1017, 1074, 505,
+ 0, 1074, 0, 0, 374, 549, 1026, 1074, 1007, 1074,
+ 1074, 1074, 357, 0, 1074, 1074, 1074, 1074, 1074, 1074,
+ 0, 1074, 0, 1034, 365, 1025, 1074, 1074, 1074, 382,
+ 1074, 391, 1074, 1074, 398, 1074, 406, 410, 1015, 1074,
+ 416, 1014, 421, 0, 0, 0, 0, 430, 0, 998,
+ 1006, 393, 992, 993, 990, 991, 362, 988, 995, 990,
+ 341, 999, 984, 988, 407, 994, 979, 980, 393, 979,
+
+ 979, 987, 988, 991, 974, 980, 974, 979, 970, 983,
+ 0, 0, 0, 1074, 972, 420, 0, 0, 0, 439,
+ 434, 445, 174, 451, 442, 457, 410, 468, 474, 485,
+ 489, 435, 1074, 983, 978, 962, 81, 962, 975, 960,
+ 964, 972, 971, 970, 993, 954, 965, 952, 989, 968,
+ 961, 962, 371, 465, 308, 949, 950, 433, 961, 950,
+ 957, 941, 952, 948, 941, 945, 951, 950, 940, 951,
+ 949, 946, 1074, 0, 0, 933, 0, 942, 928, 934,
+ 929, 942, 921, 926, 939, 960, 936, 924, 929, 917,
+ 0, 921, 916, 929, 442, 928, 923, 926, 921, 911,
+
+ 923, 915, 906, 913, 919, 918, 903, 467, 912, 901,
+ 914, 899, 0, 904, 0, 903, 901, 0, 941, 0,
+ 0, 890, 0, 901, 906, 890, 0, 0, 480, 890,
+ 893, 482, 906, 905, 904, 903, 894, 0, 887, 886,
+ 894, 886, 892, 884, 878, 876, 0, 875, 0, 912,
+ 888, 886, 875, 874, 871, 0, 868, 0, 484, 0,
+ 868, 504, 0, 1074, 0, 866, 866, 880, 861, 860,
+ 485, 863, 865, 864, 860, 865, 868, 857, 859, 855,
+ 854, 869, 864, 867, 862, 852, 860, 523, 849, 858,
+ 845, 860, 859, 854, 844, 838, 837, 850, 534, 502,
+
+ 0, 835, 848, 847, 834, 833, 844, 828, 827, 828,
+ 864, 839, 842, 829, 836, 835, 819, 820, 817, 818,
+ 832, 817, 538, 1074, 832, 819, 0, 814, 813, 0,
+ 816, 827, 826, 0, 1074, 851, 810, 809, 809, 805,
+ 804, 803, 802, 812, 798, 797, 810, 813, 0, 801,
+ 794, 805, 804, 798, 0, 797, 0, 0, 795, 789,
+ 802, 786, 785, 0, 800, 799, 825, 782, 781, 780,
+ 794, 793, 0, 0, 785, 778, 777, 774, 787, 0,
+ 0, 780, 779, 768, 767, 776, 783, 768, 764, 762,
+ 743, 739, 773, 541, 729, 727, 0, 714, 712, 703,
+
+ 704, 700, 0, 700, 681, 657, 517, 525, 664, 662,
+ 0, 655, 653, 662, 660, 661, 658, 642, 641, 551,
+ 639, 638, 645, 566, 573, 637, 636, 574, 0, 0,
+ 0, 0, 0, 0, 0, 577, 576, 587, 1074, 548,
+ 549, 566, 594, 1074, 562, 561, 558, 0, 0, 569,
+ 568, 560, 567, 566, 551, 560, 559, 0, 559, 558,
+ 538, 529, 520, 0, 0, 524, 521, 510, 533, 483,
+ 482, 484, 0, 0, 490, 461, 457, 445, 420, 0,
+ 1074, 616, 629, 642, 655, 668, 681, 694, 701, 712,
+ 725, 738, 749, 756, 764, 772, 783, 791, 437, 388,
+
+ 372, 208, 200, 162, 137, 83, 69, 802
+ } ;
+
+static yyconst flex_int16_t yy_def[609] =
+ { 0,
+ 581, 1, 582, 582, 583, 583, 583, 583, 584, 584,
+ 585, 585, 583, 583, 583, 583, 583, 583, 583, 583,
+ 583, 583, 583, 583, 583, 583, 583, 583, 581, 29,
+ 586, 586, 581, 587, 581, 581, 581, 581, 581, 581,
+ 581, 588, 581, 589, 589, 581, 581, 581, 588, 581,
+ 581, 581, 587, 581, 581, 581, 581, 581, 590, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 591,
+ 591, 581, 581, 591, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 592,
+ 581, 581, 593, 581, 593, 594, 581, 581, 581, 593,
+
+ 581, 581, 581, 581, 581, 587, 595, 581, 596, 595,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 581, 588,
+ 49, 581, 597, 598, 589, 598, 581, 581, 581, 581,
+ 581, 581, 581, 599, 581, 581, 581, 581, 581, 581,
+ 600, 581, 601, 591, 591, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 593, 594, 595, 596, 581, 595, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 597, 598, 136, 581, 581, 581, 602, 603, 601, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 592, 581, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 581, 581, 604, 605, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 581, 606,
+ 607, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 581, 600, 581, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 581, 596,
+
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 581, 581, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 581, 581, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 608, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 608, 608, 596, 596, 596, 596, 596, 596,
+
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 581, 581, 596,
+ 596, 596, 581, 581, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 596, 596, 596, 596, 596, 596, 596, 596, 596, 596,
+ 0, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+
+ 581, 581, 581, 581, 581, 581, 581, 581
+ } ;
+
+static yyconst flex_int16_t yy_nxt[1134] =
+ { 0,
+ 34, 35, 36, 34, 35, 34, 37, 34, 38, 39,
+ 40, 41, 34, 42, 43, 44, 45, 45, 34, 46,
+ 47, 48, 40, 34, 49, 49, 49, 49, 50, 34,
+ 34, 49, 49, 49, 49, 49, 49, 49, 49, 49,
+ 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
+ 49, 49, 49, 49, 49, 51, 52, 40, 34, 57,
+ 57, 61, 61, 58, 58, 71, 155, 86, 62, 62,
+ 75, 75, 86, 72, 71, 73, 154, 364, 85, 85,
+ 64, 36, 72, 64, 73, 161, 59, 59, 59, 59,
+ 65, 363, 162, 66, 87, 64, 36, 67, 64, 87,
+
+ 88, 69, 75, 91, 89, 65, 76, 68, 66, 78,
+ 92, 74, 67, 279, 79, 60, 60, 60, 60, 75,
+ 74, 280, 68, 76, 137, 77, 78, 90, 75, 132,
+ 90, 79, 76, 133, 77, 78, 138, 75, 132, 203,
+ 79, 76, 133, 80, 78, 321, 75, 75, 204, 79,
+ 76, 76, 80, 78, 78, 81, 75, 88, 79, 79,
+ 76, 89, 80, 78, 81, 75, 91, 166, 79, 76,
+ 320, 80, 78, 92, 81, 102, 36, 79, 102, 135,
+ 135, 135, 167, 81, 90, 103, 168, 169, 104, 168,
+ 82, 136, 83, 90, 102, 36, 161, 102, 163, 82,
+
+ 105, 83, 132, 162, 103, 182, 133, 104, 275, 82,
+ 164, 84, 135, 135, 135, 183, 274, 136, 82, 165,
+ 84, 93, 94, 36, 93, 94, 93, 93, 93, 93,
+ 93, 93, 95, 93, 96, 97, 98, 98, 98, 93,
+ 93, 93, 93, 93, 93, 96, 96, 96, 96, 93,
+ 93, 99, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
+ 96, 96, 96, 96, 96, 96, 93, 93, 93, 93,
+ 107, 107, 107, 107, 107, 107, 107, 107, 108, 107,
+ 107, 107, 107, 109, 107, 107, 107, 107, 107, 107,
+
+ 107, 107, 107, 110, 109, 109, 109, 109, 107, 107,
+ 107, 109, 109, 111, 112, 113, 114, 115, 116, 109,
+ 117, 109, 118, 119, 120, 121, 122, 109, 123, 124,
+ 125, 126, 127, 109, 128, 129, 107, 107, 107, 106,
+ 300, 158, 106, 301, 106, 159, 106, 171, 172, 132,
+ 171, 130, 130, 133, 184, 178, 178, 106, 178, 185,
+ 160, 190, 106, 194, 186, 191, 198, 201, 106, 106,
+ 205, 202, 216, 216, 192, 173, 195, 155, 248, 206,
+ 219, 196, 199, 220, 221, 200, 220, 154, 207, 135,
+ 135, 135, 222, 223, 249, 222, 218, 106, 581, 224,
+
+ 225, 581, 224, 581, 243, 581, 296, 226, 227, 179,
+ 226, 168, 169, 297, 168, 244, 581, 229, 172, 253,
+ 229, 581, 231, 232, 166, 231, 236, 581, 581, 259,
+ 237, 178, 178, 260, 178, 273, 273, 581, 254, 167,
+ 220, 221, 238, 220, 158, 217, 222, 223, 159, 222,
+ 163, 255, 224, 225, 339, 224, 581, 142, 226, 227,
+ 142, 226, 164, 160, 173, 304, 143, 143, 580, 168,
+ 169, 165, 168, 340, 142, 229, 172, 144, 229, 353,
+ 142, 579, 305, 145, 146, 233, 229, 172, 147, 229,
+ 231, 232, 369, 231, 373, 148, 396, 405, 354, 149,
+
+ 298, 150, 151, 152, 153, 106, 578, 299, 106, 577,
+ 106, 370, 106, 374, 437, 397, 406, 130, 130, 399,
+ 399, 399, 576, 106, 423, 423, 423, 423, 106, 526,
+ 575, 574, 573, 438, 106, 106, 435, 527, 436, 423,
+ 423, 423, 423, 435, 424, 572, 571, 494, 527, 399,
+ 399, 399, 538, 538, 538, 538, 527, 570, 569, 424,
+ 550, 551, 568, 106, 213, 213, 213, 543, 543, 543,
+ 543, 567, 539, 213, 543, 543, 543, 543, 566, 551,
+ 551, 213, 213, 213, 213, 213, 213, 544, 538, 538,
+ 538, 538, 565, 564, 544, 543, 543, 543, 543, 563,
+
+ 562, 561, 560, 559, 558, 557, 556, 555, 539, 554,
+ 553, 552, 549, 548, 547, 544, 54, 54, 54, 54,
+ 54, 54, 54, 54, 54, 54, 54, 54, 54, 56,
+ 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
+ 56, 56, 63, 63, 63, 63, 63, 63, 63, 63,
+ 63, 63, 63, 63, 63, 70, 70, 70, 70, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 101, 101,
+ 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
+ 101, 106, 546, 545, 106, 542, 106, 106, 541, 540,
+ 537, 536, 535, 106, 131, 534, 533, 131, 532, 131,
+
+ 131, 531, 131, 530, 131, 529, 131, 134, 528, 134,
+ 525, 134, 141, 141, 141, 141, 141, 141, 141, 141,
+ 141, 141, 141, 141, 141, 154, 154, 154, 154, 154,
+ 154, 154, 154, 154, 524, 154, 154, 154, 170, 170,
+ 170, 170, 170, 170, 170, 170, 170, 170, 170, 174,
+ 523, 522, 174, 174, 174, 521, 520, 519, 174, 518,
+ 174, 175, 175, 517, 175, 516, 175, 176, 176, 176,
+ 176, 176, 176, 176, 176, 176, 176, 177, 177, 494,
+ 177, 515, 177, 211, 211, 514, 211, 211, 211, 211,
+ 211, 211, 211, 211, 211, 211, 212, 212, 513, 212,
+
+ 512, 212, 493, 493, 511, 493, 493, 493, 493, 493,
+ 493, 493, 493, 493, 493, 510, 509, 508, 507, 506,
+ 505, 504, 503, 502, 501, 500, 499, 498, 497, 496,
+ 495, 494, 492, 491, 490, 489, 488, 487, 486, 485,
+ 484, 483, 482, 481, 480, 479, 478, 477, 476, 475,
+ 474, 473, 472, 471, 470, 469, 468, 467, 466, 465,
+ 464, 463, 462, 461, 460, 459, 458, 457, 456, 455,
+ 454, 453, 452, 451, 450, 449, 448, 447, 446, 445,
+ 444, 443, 442, 441, 440, 439, 434, 433, 432, 431,
+ 430, 429, 428, 427, 426, 425, 422, 421, 420, 419,
+
+ 418, 417, 416, 415, 414, 413, 412, 411, 410, 409,
+ 408, 407, 404, 403, 402, 401, 400, 398, 395, 394,
+ 393, 392, 391, 390, 389, 388, 387, 386, 385, 384,
+ 383, 382, 381, 380, 379, 378, 377, 376, 375, 372,
+ 371, 368, 367, 366, 365, 362, 361, 360, 359, 358,
+ 357, 356, 355, 352, 351, 350, 349, 348, 347, 346,
+ 345, 344, 343, 342, 341, 338, 337, 336, 335, 334,
+ 333, 332, 331, 330, 329, 328, 327, 326, 325, 324,
+ 323, 322, 319, 318, 317, 316, 315, 314, 313, 312,
+ 311, 310, 309, 308, 307, 306, 303, 302, 295, 294,
+
+ 293, 292, 291, 290, 289, 288, 287, 286, 285, 284,
+ 283, 282, 281, 278, 277, 276, 272, 271, 270, 269,
+ 268, 267, 266, 265, 264, 263, 262, 261, 258, 257,
+ 256, 252, 251, 250, 247, 246, 245, 242, 241, 240,
+ 239, 235, 234, 230, 228, 156, 155, 215, 214, 210,
+ 209, 208, 197, 193, 189, 188, 187, 181, 180, 139,
+ 139, 157, 155, 156, 155, 139, 140, 139, 581, 100,
+ 55, 55, 53, 33, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581
+ } ;
+
+static yyconst flex_int16_t yy_chk[1134] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 5,
+ 6, 7, 8, 5, 6, 11, 71, 23, 7, 8,
+ 21, 22, 24, 11, 12, 11, 71, 607, 21, 22,
+ 9, 9, 12, 9, 12, 80, 5, 6, 7, 8,
+ 9, 606, 80, 9, 23, 10, 10, 9, 10, 24,
+
+ 25, 10, 17, 27, 25, 10, 17, 9, 10, 17,
+ 27, 11, 10, 237, 17, 5, 6, 7, 8, 13,
+ 12, 237, 10, 13, 47, 13, 13, 25, 14, 43,
+ 27, 13, 14, 43, 14, 14, 47, 15, 66, 124,
+ 14, 15, 66, 15, 15, 605, 16, 18, 124, 15,
+ 16, 18, 16, 16, 18, 15, 19, 26, 16, 18,
+ 19, 26, 19, 19, 16, 20, 28, 85, 19, 20,
+ 604, 20, 20, 28, 19, 31, 31, 20, 31, 44,
+ 44, 44, 85, 20, 26, 31, 87, 87, 31, 87,
+ 15, 44, 15, 28, 32, 32, 223, 32, 81, 16,
+
+ 32, 16, 97, 223, 32, 113, 97, 32, 603, 19,
+ 81, 19, 45, 45, 45, 113, 602, 44, 20, 81,
+ 20, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 42,
+ 255, 79, 42, 255, 42, 79, 42, 90, 90, 104,
+ 90, 42, 42, 104, 114, 110, 110, 42, 110, 114,
+ 79, 118, 42, 120, 114, 118, 122, 123, 42, 42,
+ 125, 123, 143, 143, 118, 90, 120, 155, 191, 125,
+ 601, 120, 122, 160, 160, 122, 160, 155, 125, 135,
+ 135, 135, 162, 162, 191, 162, 600, 42, 49, 165,
+
+ 165, 49, 165, 49, 187, 49, 253, 167, 167, 110,
+ 167, 168, 168, 253, 168, 187, 49, 171, 171, 195,
+ 171, 49, 173, 173, 227, 173, 182, 49, 49, 199,
+ 182, 178, 178, 199, 178, 216, 216, 232, 195, 227,
+ 220, 220, 182, 220, 221, 599, 222, 222, 221, 222,
+ 225, 195, 224, 224, 295, 224, 49, 59, 226, 226,
+ 59, 226, 225, 221, 232, 258, 59, 59, 579, 228,
+ 228, 225, 228, 295, 59, 229, 229, 59, 229, 308,
+ 59, 578, 258, 59, 59, 178, 230, 230, 59, 230,
+ 231, 231, 329, 231, 332, 59, 359, 371, 308, 59,
+
+ 254, 59, 59, 59, 59, 130, 577, 254, 130, 576,
+ 130, 329, 130, 332, 400, 359, 371, 130, 130, 362,
+ 362, 362, 575, 130, 388, 388, 388, 388, 130, 507,
+ 572, 571, 570, 400, 130, 130, 399, 508, 399, 423,
+ 423, 423, 423, 494, 388, 569, 568, 494, 507, 399,
+ 399, 399, 520, 520, 520, 520, 508, 567, 566, 423,
+ 540, 541, 563, 130, 136, 136, 136, 524, 524, 524,
+ 524, 562, 520, 136, 525, 525, 525, 525, 561, 540,
+ 541, 136, 136, 136, 136, 136, 136, 524, 538, 538,
+ 538, 538, 560, 559, 525, 543, 543, 543, 543, 557,
+
+ 556, 555, 554, 553, 552, 551, 550, 547, 538, 546,
+ 545, 542, 537, 536, 528, 543, 582, 582, 582, 582,
+ 582, 582, 582, 582, 582, 582, 582, 582, 582, 583,
+ 583, 583, 583, 583, 583, 583, 583, 583, 583, 583,
+ 583, 583, 584, 584, 584, 584, 584, 584, 584, 584,
+ 584, 584, 584, 584, 584, 585, 585, 585, 585, 585,
+ 585, 585, 585, 585, 585, 585, 585, 585, 586, 586,
+ 586, 586, 586, 586, 586, 586, 586, 586, 586, 586,
+ 586, 587, 527, 526, 587, 523, 587, 587, 522, 521,
+ 519, 518, 517, 587, 588, 516, 515, 588, 514, 588,
+
+ 588, 513, 588, 512, 588, 510, 588, 589, 509, 589,
+ 506, 589, 590, 590, 590, 590, 590, 590, 590, 590,
+ 590, 590, 590, 590, 590, 591, 591, 591, 591, 591,
+ 591, 591, 591, 591, 505, 591, 591, 591, 592, 592,
+ 592, 592, 592, 592, 592, 592, 592, 592, 592, 593,
+ 504, 502, 593, 593, 593, 501, 500, 499, 593, 498,
+ 593, 594, 594, 496, 594, 495, 594, 595, 595, 595,
+ 595, 595, 595, 595, 595, 595, 595, 596, 596, 493,
+ 596, 492, 596, 597, 597, 491, 597, 597, 597, 597,
+ 597, 597, 597, 597, 597, 597, 598, 598, 490, 598,
+
+ 489, 598, 608, 608, 488, 608, 608, 608, 608, 608,
+ 608, 608, 608, 608, 608, 487, 486, 485, 484, 483,
+ 482, 479, 478, 477, 476, 475, 472, 471, 470, 469,
+ 468, 467, 466, 465, 463, 462, 461, 460, 459, 456,
+ 454, 453, 452, 451, 450, 448, 447, 446, 445, 444,
+ 443, 442, 441, 440, 439, 438, 437, 436, 433, 432,
+ 431, 429, 428, 426, 425, 422, 421, 420, 419, 418,
+ 417, 416, 415, 414, 413, 412, 411, 410, 409, 408,
+ 407, 406, 405, 404, 403, 402, 398, 397, 396, 395,
+ 394, 393, 392, 391, 390, 389, 387, 386, 385, 384,
+
+ 383, 382, 381, 380, 379, 378, 377, 376, 375, 374,
+ 373, 372, 370, 369, 368, 367, 366, 361, 357, 355,
+ 354, 353, 352, 351, 350, 348, 346, 345, 344, 343,
+ 342, 341, 340, 339, 337, 336, 335, 334, 333, 331,
+ 330, 326, 325, 324, 322, 319, 317, 316, 314, 312,
+ 311, 310, 309, 307, 306, 305, 304, 303, 302, 301,
+ 300, 299, 298, 297, 296, 294, 293, 292, 290, 289,
+ 288, 287, 286, 285, 284, 283, 282, 281, 280, 279,
+ 278, 276, 272, 271, 270, 269, 268, 267, 266, 265,
+ 264, 263, 262, 261, 260, 259, 257, 256, 252, 251,
+
+ 250, 249, 248, 247, 246, 245, 244, 243, 242, 241,
+ 240, 239, 238, 236, 235, 234, 215, 210, 209, 208,
+ 207, 206, 205, 204, 203, 202, 201, 200, 198, 197,
+ 196, 194, 193, 192, 190, 189, 188, 186, 185, 184,
+ 183, 181, 180, 172, 169, 156, 154, 139, 137, 128,
+ 127, 126, 121, 119, 117, 116, 115, 112, 111, 105,
+ 100, 77, 74, 72, 70, 69, 55, 53, 33, 30,
+ 4, 3, 2, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581, 581, 581, 581, 581, 581, 581, 581,
+ 581, 581, 581
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int gram__flex_debug;
+int gram__flex_debug = 1;
+
+static yyconst flex_int16_t yy_rule_linenum[130] =
+ { 0,
+ 179, 182, 183, 184, 192, 210, 211, 212, 213, 214,
+ 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
+ 225, 226, 227, 228, 229, 230, 231, 232, 233, 234,
+ 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
+ 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
+ 257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
+ 267, 269, 273, 274, 275, 277, 284, 288, 295, 300,
+ 303, 306, 309, 317, 324, 325, 326, 332, 339, 346,
+ 366, 376, 391, 396, 415, 428, 444, 459, 476, 477,
+ 488, 499, 500, 512, 520, 530, 549, 561, 575, 576,
+
+ 587, 596, 606, 607, 608, 609, 610, 611, 612, 615,
+ 617, 625, 643, 648, 649, 655, 656, 667, 673, 679,
+ 685, 701, 702, 706, 713, 730, 751, 784, 785
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *gram_text;
+#line 1 "../../src/scan-gram.l"
+/* Bison Grammar Scanner -*- C -*-
+
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define YY_NO_INPUT 1
+#line 24 "../../src/scan-gram.l"
+/* Work around a bug in flex 2.5.31. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+#undef gram_wrap
+#define gram_wrap() 1
+
+#define FLEX_PREFIX(Id) gram_ ## Id
+#include <src/flex-scanner.h>
+
+#include <src/complain.h>
+#include <src/files.h>
+#include <src/getargs.h>
+#include <src/gram.h>
+#include <quotearg.h>
+#include <src/reader.h>
+#include <src/uniqstr.h>
+
+#include <c-ctype.h>
+#include <mbswidth.h>
+#include <quote.h>
+
+#include <src/scan-gram.h>
+
+#define YY_DECL GRAM_LEX_DECL
+
+#define YY_USER_INIT \
+ code_start = scanner_cursor = loc->start; \
+
+/* Location of scanner cursor. */
+static boundary scanner_cursor;
+
+#define YY_USER_ACTION location_compute (loc, &scanner_cursor, gram_text, gram_leng);
+
+static size_t no_cr_read (FILE *, char *, size_t);
+#define YY_INPUT(buf, result, size) ((result) = no_cr_read (gram_in, buf, size))
+
+#define RETURN_PERCENT_PARAM(Value) \
+ RETURN_VALUE(PERCENT_PARAM, param, param_ ## Value)
+
+#define RETURN_PERCENT_FLAG(Value) \
+ RETURN_VALUE(PERCENT_FLAG, uniqstr, uniqstr_new (Value))
+
+#define RETURN_VALUE(Token, Field, Value) \
+ do { \
+ val->Field = Value; \
+ return Token; \
+ } while (0)
+
+#define ROLLBACK_CURRENT_TOKEN \
+ do { \
+ scanner_cursor.column -= mbsnwidth (gram_text, gram_leng, 0); \
+ yyless (0); \
+ } while (0)
+
+#define DEPRECATED(Msg) \
+ do { \
+ size_t i; \
+ deprecated_directive (loc, gram_text, Msg); \
+ scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \
+ for (i = strlen (Msg); i != 0; --i) \
+ unput (Msg[i - 1]); \
+ } while (0)
+
+/* A string representing the most recently saved token. */
+static char *last_string;
+
+/* Bracketed identifier. */
+static uniqstr bracketed_id_str = 0;
+static location bracketed_id_loc;
+static boundary bracketed_id_start;
+static int bracketed_id_context_state = 0;
+
+void
+gram_scanner_last_string_free (void)
+{
+ STRING_FREE;
+}
+
+static void handle_syncline (char *, location);
+static unsigned long int scan_integer (char const *p, int base, location loc);
+static int convert_ucn_to_byte (char const *hex_text);
+static void unexpected_eof (boundary, char const *);
+static void unexpected_newline (boundary, char const *);
+
+/* A C-like comment in directives/rules. */
+
+/* Strings and characters in directives/rules. */
+
+/* A identifier was just read in directives/rules. Special state
+to capture the sequence 'identifier :'. */
+
+/* POSIX says that a tag must be both an id and a C union member, but
+historically almost any character is allowed in a tag. We
+disallow NUL, as this simplifies our implementation. We match
+angle brackets in nested pairs: several languages use them for
+generics/template types. */
+
+/* Four types of user code:
+- prologue (code between '%{' '%}' in the first section, before %%);
+- actions, printers, union, etc, (between braced in the middle section);
+- epilogue (everything after the second %%).
+- predicate (code between '%?{' and '{' in middle section); */
+
+/* C and C++ comments in code. */
+
+/* Strings and characters in code. */
+
+/* Bracketed identifiers support. */
+
+/* Zero or more instances of backslash-newline. Following GCC, allow
+ white space between the backslash and the newline. */
+/* An equal sign, with optional leading whitespaces. This is used in some
+ deprecated constructs. */
+#line 1153 "src/scan-gram.c"
+
+#define INITIAL 0
+#define SC_YACC_COMMENT 1
+#define SC_ESCAPED_STRING 2
+#define SC_ESCAPED_CHARACTER 3
+#define SC_AFTER_IDENTIFIER 4
+#define SC_TAG 5
+#define SC_PROLOGUE 6
+#define SC_BRACED_CODE 7
+#define SC_EPILOGUE 8
+#define SC_PREDICATE 9
+#define SC_COMMENT 10
+#define SC_LINE_COMMENT 11
+#define SC_STRING 12
+#define SC_CHARACTER 13
+#define SC_BRACKETED_ID 14
+#define SC_RETURN_BRACKETED_ID 15
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+/* %if-c-only */
+#include <unistd.h>
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* %if-c-only Reentrant structure and macros (non-C++). */
+/* %if-reentrant */
+/* %if-c-only */
+
+static int yy_init_globals (void );
+
+/* %endif */
+/* %if-reentrant */
+/* %endif */
+/* %endif End reentrant structures and macros. */
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int gram_lex_destroy (void );
+
+int gram_get_debug (void );
+
+void gram_set_debug (int debug_flag );
+
+YY_EXTRA_TYPE gram_get_extra (void );
+
+void gram_set_extra (YY_EXTRA_TYPE user_defined );
+
+FILE *gram_get_in (void );
+
+void gram_set_in (FILE * in_str );
+
+FILE *gram_get_out (void );
+
+void gram_set_out (FILE * out_str );
+
+yy_size_t gram_get_leng (void );
+
+char *gram_get_text (void );
+
+int gram_get_lineno (void );
+
+void gram_set_lineno (int line_number );
+
+/* %if-bison-bridge */
+/* %endif */
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int gram_wrap (void );
+#else
+extern int gram_wrap (void );
+#endif
+#endif
+
+/* %not-for-header */
+
+ static void yyunput (int c,char *buf_ptr );
+
+/* %ok-for-header */
+
+/* %endif */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+#ifdef __cplusplus
+static int yyinput (void );
+#else
+static int input (void );
+#endif
+/* %ok-for-header */
+
+/* %endif */
+#endif
+
+/* %if-c-only */
+
+/* %endif */
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* %if-c-only Standard (non-C++) definition */
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( gram_text, gram_leng, 1, gram_out )) {} } while (0)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( gram_in )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( gram_in ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, gram_in))==0 && ferror(gram_in)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(gram_in); \
+ } \
+ }\
+\
+/* %if-c++-only C++ definition \ */\
+/* %endif */
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+/* %if-c-only */
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+/* %if-tables-serialization structures and prototypes */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* %tables-yydmap generated elements */
+/* %endif */
+/* end tables serialization structures and prototypes */
+
+/* %ok-for-header */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+/* %if-c-only Standard (non-C++) definition */
+
+extern int gram_lex (void);
+
+#define YY_DECL int gram_lex (void)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after gram_text and gram_leng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+/* %% [6.0] YY_RULE_SETUP definition goes here */
+#define YY_RULE_SETUP \
+ if ( gram_leng > 0 ) \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \
+ (gram_text[gram_leng - 1] == '\n'); \
+ YY_USER_ACTION
+
+/* %not-for-header */
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+/* %% [7.0] user's declarations go here */
+#line 149 "../../src/scan-gram.l"
+
+
+ /* Nesting level. Either for nested braces, or nested angle brackets
+ (but not mixed). */
+ int nesting PACIFY_CC (= 0);
+
+ /* Parent context state, when applicable. */
+ int context_state PACIFY_CC (= 0);
+
+ /* Location of most recent identifier, when applicable. */
+ location id_loc PACIFY_CC (= empty_location);
+
+ /* Where containing code started, when applicable. Its initial
+ value is relevant only when gram_lex is invoked in the SC_EPILOGUE
+ start condition. */
+ boundary code_start = scanner_cursor;
+
+ /* Where containing comment or string or character literal started,
+ when applicable. */
+ boundary token_start PACIFY_CC (= scanner_cursor);
+
+
+
+ /*-----------------------.
+ | Scanning white space. |
+ `-----------------------*/
+
+#line 1441 "src/scan-gram.c"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! gram_in )
+/* %if-c-only */
+ gram_in = stdin;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! gram_out )
+/* %if-c-only */
+ gram_out = stdout;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ gram_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ gram__create_buffer(gram_in,YY_BUF_SIZE );
+ }
+
+ gram__load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+/* %% [8.0] yymore()-related code goes here */
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of gram_text. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+/* %% [9.0] code to set up and find next match goes here */
+ yy_current_state = (yy_start);
+ yy_current_state += YY_AT_BOL();
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 582 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 581 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+/* %% [10.0] code to find the action number goes here */
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+/* %% [11.0] code for gram_lineno update goes here */
+
+do_action: /* This label is used only to access EOF actions. */
+
+/* %% [12.0] debug code goes here */
+ if ( gram__flex_debug )
+ {
+ if ( yy_act == 0 )
+ fprintf( stderr, "--scanner backing up\n" );
+ else if ( yy_act < 130 )
+ fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
+ (long)yy_rule_linenum[yy_act], gram_text );
+ else if ( yy_act == 130 )
+ fprintf( stderr, "--accepting default rule (\"%s\")\n",
+ gram_text );
+ else if ( yy_act == 131 )
+ fprintf( stderr, "--(end of buffer or a NUL)\n" );
+ else
+ fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
+ }
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+/* %% [13.0] actions go here */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+/* Comments and white space. */
+case 1:
+YY_RULE_SETUP
+#line 179 "../../src/scan-gram.l"
+{
+ complain (loc, Wother, _("stray ',' treated as white space"));
+ }
+ YY_BREAK
+case 2:
+/* rule 2 can match eol */
+#line 183 "../../src/scan-gram.l"
+case 3:
+/* rule 3 can match eol */
+YY_RULE_SETUP
+#line 183 "../../src/scan-gram.l"
+continue;
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 184 "../../src/scan-gram.l"
+{
+ token_start = loc->start;
+ context_state = YY_START;
+ BEGIN SC_YACC_COMMENT;
+ }
+ YY_BREAK
+/* #line directives are not documented, and may be withdrawn or
+ modified in future versions of Bison. */
+case 5:
+/* rule 5 can match eol */
+YY_RULE_SETUP
+#line 192 "../../src/scan-gram.l"
+{
+ handle_syncline (gram_text + sizeof "#line " - 1, *loc);
+ }
+ YY_BREAK
+
+/*----------------------------.
+ | Scanning Bison directives. |
+ `----------------------------*/
+/* For directives that are also command line options, the regex must be
+ "%..."
+ after "[-_]"s are removed, and the directive must match the --long
+ option name, with a single string argument. Otherwise, add exceptions
+ to ../build-aux/cross-options.pl. */
+
+
+case 6:
+YY_RULE_SETUP
+#line 210 "../../src/scan-gram.l"
+return PERCENT_NONASSOC;
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 211 "../../src/scan-gram.l"
+return PERCENT_CODE;
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 212 "../../src/scan-gram.l"
+RETURN_PERCENT_FLAG("parse.trace");
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 213 "../../src/scan-gram.l"
+return PERCENT_DEFAULT_PREC;
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 214 "../../src/scan-gram.l"
+return PERCENT_DEFINE;
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 215 "../../src/scan-gram.l"
+return PERCENT_DEFINES;
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 216 "../../src/scan-gram.l"
+return PERCENT_DESTRUCTOR;
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 217 "../../src/scan-gram.l"
+return PERCENT_DPREC;
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 218 "../../src/scan-gram.l"
+return PERCENT_EMPTY;
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 219 "../../src/scan-gram.l"
+return PERCENT_ERROR_VERBOSE;
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 220 "../../src/scan-gram.l"
+return PERCENT_EXPECT;
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 221 "../../src/scan-gram.l"
+return PERCENT_EXPECT_RR;
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 222 "../../src/scan-gram.l"
+return PERCENT_FILE_PREFIX;
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 223 "../../src/scan-gram.l"
+return PERCENT_YACC;
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 224 "../../src/scan-gram.l"
+return PERCENT_INITIAL_ACTION;
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 225 "../../src/scan-gram.l"
+return PERCENT_GLR_PARSER;
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 226 "../../src/scan-gram.l"
+return PERCENT_LANGUAGE;
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 227 "../../src/scan-gram.l"
+return PERCENT_LEFT;
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 228 "../../src/scan-gram.l"
+RETURN_PERCENT_PARAM(lex);
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 229 "../../src/scan-gram.l"
+RETURN_PERCENT_FLAG("locations");
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 230 "../../src/scan-gram.l"
+return PERCENT_MERGE;
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 231 "../../src/scan-gram.l"
+return PERCENT_NAME_PREFIX;
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 232 "../../src/scan-gram.l"
+return PERCENT_NO_DEFAULT_PREC;
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 233 "../../src/scan-gram.l"
+return PERCENT_NO_LINES;
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 234 "../../src/scan-gram.l"
+return PERCENT_NONASSOC;
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 235 "../../src/scan-gram.l"
+return PERCENT_NONDETERMINISTIC_PARSER;
+ YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 236 "../../src/scan-gram.l"
+return PERCENT_NTERM;
+ YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 237 "../../src/scan-gram.l"
+return PERCENT_OUTPUT;
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 238 "../../src/scan-gram.l"
+RETURN_PERCENT_PARAM(both);
+ YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 239 "../../src/scan-gram.l"
+RETURN_PERCENT_PARAM(parse);
+ YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 240 "../../src/scan-gram.l"
+return PERCENT_PREC;
+ YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 241 "../../src/scan-gram.l"
+return PERCENT_PRECEDENCE;
+ YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 242 "../../src/scan-gram.l"
+return PERCENT_PRINTER;
+ YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 243 "../../src/scan-gram.l"
+RETURN_PERCENT_FLAG("api.pure");
+ YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 244 "../../src/scan-gram.l"
+return PERCENT_REQUIRE;
+ YY_BREAK
+case 41:
+YY_RULE_SETUP
+#line 245 "../../src/scan-gram.l"
+return PERCENT_RIGHT;
+ YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 246 "../../src/scan-gram.l"
+return PERCENT_SKELETON;
+ YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 247 "../../src/scan-gram.l"
+return PERCENT_START;
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 248 "../../src/scan-gram.l"
+return PERCENT_TOKEN;
+ YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 249 "../../src/scan-gram.l"
+return PERCENT_TOKEN;
+ YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 250 "../../src/scan-gram.l"
+return PERCENT_TOKEN_TABLE;
+ YY_BREAK
+case 47:
+YY_RULE_SETUP
+#line 251 "../../src/scan-gram.l"
+return PERCENT_TYPE;
+ YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 252 "../../src/scan-gram.l"
+return PERCENT_UNION;
+ YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 253 "../../src/scan-gram.l"
+return PERCENT_VERBOSE;
+ YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 254 "../../src/scan-gram.l"
+return PERCENT_YACC;
+ YY_BREAK
+/* deprecated */
+case 51:
+YY_RULE_SETUP
+#line 257 "../../src/scan-gram.l"
+DEPRECATED("%default-prec");
+ YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 258 "../../src/scan-gram.l"
+DEPRECATED("%define parse.error verbose");
+ YY_BREAK
+case 53:
+YY_RULE_SETUP
+#line 259 "../../src/scan-gram.l"
+DEPRECATED("%expect-rr");
+ YY_BREAK
+case 54:
+/* rule 54 can match eol */
+YY_RULE_SETUP
+#line 260 "../../src/scan-gram.l"
+DEPRECATED("%file-prefix");
+ YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 261 "../../src/scan-gram.l"
+DEPRECATED("%fixed-output-files");
+ YY_BREAK
+case 56:
+/* rule 56 can match eol */
+YY_RULE_SETUP
+#line 262 "../../src/scan-gram.l"
+DEPRECATED("%name-prefix");
+ YY_BREAK
+case 57:
+YY_RULE_SETUP
+#line 263 "../../src/scan-gram.l"
+DEPRECATED("%no-default-prec");
+ YY_BREAK
+case 58:
+YY_RULE_SETUP
+#line 264 "../../src/scan-gram.l"
+DEPRECATED("%no-lines");
+ YY_BREAK
+case 59:
+/* rule 59 can match eol */
+YY_RULE_SETUP
+#line 265 "../../src/scan-gram.l"
+DEPRECATED("%output");
+ YY_BREAK
+case 60:
+YY_RULE_SETUP
+#line 266 "../../src/scan-gram.l"
+DEPRECATED("%pure-parser");
+ YY_BREAK
+case 61:
+YY_RULE_SETUP
+#line 267 "../../src/scan-gram.l"
+DEPRECATED("%token-table");
+ YY_BREAK
+case 62:
+/* rule 62 can match eol */
+YY_RULE_SETUP
+#line 269 "../../src/scan-gram.l"
+{
+ complain (loc, complaint, _("invalid directive: %s"), quote (gram_text));
+ }
+ YY_BREAK
+case 63:
+YY_RULE_SETUP
+#line 273 "../../src/scan-gram.l"
+return EQUAL;
+ YY_BREAK
+case 64:
+YY_RULE_SETUP
+#line 274 "../../src/scan-gram.l"
+return PIPE;
+ YY_BREAK
+case 65:
+YY_RULE_SETUP
+#line 275 "../../src/scan-gram.l"
+return SEMICOLON;
+ YY_BREAK
+case 66:
+YY_RULE_SETUP
+#line 277 "../../src/scan-gram.l"
+{
+ val->uniqstr = uniqstr_new (gram_text);
+ id_loc = *loc;
+ bracketed_id_str = NULL;
+ BEGIN SC_AFTER_IDENTIFIER;
+ }
+ YY_BREAK
+case 67:
+YY_RULE_SETUP
+#line 284 "../../src/scan-gram.l"
+{
+ val->integer = scan_integer (gram_text, 10, *loc);
+ return INT;
+ }
+ YY_BREAK
+case 68:
+YY_RULE_SETUP
+#line 288 "../../src/scan-gram.l"
+{
+ val->integer = scan_integer (gram_text, 16, *loc);
+ return INT;
+ }
+ YY_BREAK
+/* Identifiers may not start with a digit. Yet, don't silently
+ accept "1FOO" as "1 FOO". */
+case 69:
+YY_RULE_SETUP
+#line 295 "../../src/scan-gram.l"
+{
+ complain (loc, complaint, _("invalid identifier: %s"), quote (gram_text));
+ }
+ YY_BREAK
+/* Characters. */
+case 70:
+YY_RULE_SETUP
+#line 300 "../../src/scan-gram.l"
+token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
+ YY_BREAK
+/* Strings. */
+case 71:
+YY_RULE_SETUP
+#line 303 "../../src/scan-gram.l"
+token_start = loc->start; BEGIN SC_ESCAPED_STRING;
+ YY_BREAK
+/* Prologue. */
+case 72:
+YY_RULE_SETUP
+#line 306 "../../src/scan-gram.l"
+code_start = loc->start; BEGIN SC_PROLOGUE;
+ YY_BREAK
+/* Code in between braces. */
+case 73:
+YY_RULE_SETUP
+#line 309 "../../src/scan-gram.l"
+{
+ STRING_GROW;
+ nesting = 0;
+ code_start = loc->start;
+ BEGIN SC_BRACED_CODE;
+ }
+ YY_BREAK
+/* Semantic predicate. */
+case 74:
+/* rule 74 can match eol */
+YY_RULE_SETUP
+#line 317 "../../src/scan-gram.l"
+{
+ nesting = 0;
+ code_start = loc->start;
+ BEGIN SC_PREDICATE;
+ }
+ YY_BREAK
+/* A type. */
+case 75:
+YY_RULE_SETUP
+#line 324 "../../src/scan-gram.l"
+return TAG_ANY;
+ YY_BREAK
+case 76:
+YY_RULE_SETUP
+#line 325 "../../src/scan-gram.l"
+return TAG_NONE;
+ YY_BREAK
+case 77:
+YY_RULE_SETUP
+#line 326 "../../src/scan-gram.l"
+{
+ nesting = 0;
+ token_start = loc->start;
+ BEGIN SC_TAG;
+ }
+ YY_BREAK
+case 78:
+YY_RULE_SETUP
+#line 332 "../../src/scan-gram.l"
+{
+ static int percent_percent_count;
+ if (++percent_percent_count == 2)
+ BEGIN SC_EPILOGUE;
+ return PERCENT_PERCENT;
+ }
+ YY_BREAK
+case 79:
+YY_RULE_SETUP
+#line 339 "../../src/scan-gram.l"
+{
+ bracketed_id_str = NULL;
+ bracketed_id_start = loc->start;
+ bracketed_id_context_state = YY_START;
+ BEGIN SC_BRACKETED_ID;
+ }
+ YY_BREAK
+case 80:
+YY_RULE_SETUP
+#line 346 "../../src/scan-gram.l"
+{
+ complain (loc, complaint, "%s: %s",
+ ngettext ("invalid character", "invalid characters", gram_leng),
+ quote_mem (gram_text, gram_leng));
+ }
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+#line 352 "../../src/scan-gram.l"
+{
+ loc->start = loc->end = scanner_cursor;
+ yyterminate ();
+ }
+ YY_BREAK
+
+/*--------------------------------------------------------------.
+ | Supporting \0 complexifies our implementation for no expected |
+ | added value. |
+ `--------------------------------------------------------------*/
+
+
+case 81:
+YY_RULE_SETUP
+#line 366 "../../src/scan-gram.l"
+complain (loc, complaint, _("invalid null character"));
+ YY_BREAK
+
+/*-----------------------------------------------------------------.
+ | Scanning after an identifier, checking whether a colon is next. |
+ `-----------------------------------------------------------------*/
+
+
+case 82:
+YY_RULE_SETUP
+#line 376 "../../src/scan-gram.l"
+{
+ if (bracketed_id_str)
+ {
+ ROLLBACK_CURRENT_TOKEN;
+ BEGIN SC_RETURN_BRACKETED_ID;
+ *loc = id_loc;
+ return ID;
+ }
+ else
+ {
+ bracketed_id_start = loc->start;
+ bracketed_id_context_state = YY_START;
+ BEGIN SC_BRACKETED_ID;
+ }
+ }
+ YY_BREAK
+case 83:
+YY_RULE_SETUP
+#line 391 "../../src/scan-gram.l"
+{
+ BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
+ *loc = id_loc;
+ return ID_COLON;
+ }
+ YY_BREAK
+case 84:
+YY_RULE_SETUP
+#line 396 "../../src/scan-gram.l"
+{
+ ROLLBACK_CURRENT_TOKEN;
+ BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
+ *loc = id_loc;
+ return ID;
+ }
+ YY_BREAK
+case YY_STATE_EOF(SC_AFTER_IDENTIFIER):
+#line 402 "../../src/scan-gram.l"
+{
+ BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
+ *loc = id_loc;
+ return ID;
+ }
+ YY_BREAK
+
+/*--------------------------------.
+ | Scanning bracketed identifiers. |
+ `--------------------------------*/
+
+
+case 85:
+YY_RULE_SETUP
+#line 415 "../../src/scan-gram.l"
+{
+ if (bracketed_id_str)
+ {
+ complain (loc, complaint,
+ _("unexpected identifier in bracketed name: %s"),
+ quote (gram_text));
+ }
+ else
+ {
+ bracketed_id_str = uniqstr_new (gram_text);
+ bracketed_id_loc = *loc;
+ }
+ }
+ YY_BREAK
+case 86:
+YY_RULE_SETUP
+#line 428 "../../src/scan-gram.l"
+{
+ BEGIN bracketed_id_context_state;
+ if (bracketed_id_str)
+ {
+ if (INITIAL == bracketed_id_context_state)
+ {
+ val->uniqstr = bracketed_id_str;
+ bracketed_id_str = 0;
+ *loc = bracketed_id_loc;
+ return BRACKETED_ID;
+ }
+ }
+ else
+ complain (loc, complaint, _("an identifier expected"));
+ }
+ YY_BREAK
+case 87:
+YY_RULE_SETUP
+#line 444 "../../src/scan-gram.l"
+{
+ complain (loc, complaint, "%s: %s",
+ ngettext ("invalid character in bracketed name",
+ "invalid characters in bracketed name", gram_leng),
+ quote_mem (gram_text, gram_leng));
+ }
+ YY_BREAK
+case YY_STATE_EOF(SC_BRACKETED_ID):
+#line 451 "../../src/scan-gram.l"
+{
+ BEGIN bracketed_id_context_state;
+ unexpected_eof (bracketed_id_start, "]");
+ }
+ YY_BREAK
+
+
+
+case 88:
+YY_RULE_SETUP
+#line 459 "../../src/scan-gram.l"
+{
+ ROLLBACK_CURRENT_TOKEN;
+ val->uniqstr = bracketed_id_str;
+ bracketed_id_str = 0;
+ *loc = bracketed_id_loc;
+ BEGIN INITIAL;
+ return BRACKETED_ID;
+ }
+ YY_BREAK
+
+/*---------------------------------------------------------------.
+ | Scanning a Yacc comment. The initial '/ *' is already eaten. |
+ `---------------------------------------------------------------*/
+
+
+case 89:
+YY_RULE_SETUP
+#line 476 "../../src/scan-gram.l"
+BEGIN context_state;
+ YY_BREAK
+case 90:
+/* rule 90 can match eol */
+YY_RULE_SETUP
+#line 477 "../../src/scan-gram.l"
+continue;
+ YY_BREAK
+case YY_STATE_EOF(SC_YACC_COMMENT):
+#line 478 "../../src/scan-gram.l"
+unexpected_eof (token_start, "*/"); BEGIN context_state;
+ YY_BREAK
+
+/*------------------------------------------------------------.
+ | Scanning a C comment. The initial '/ *' is already eaten. |
+ `------------------------------------------------------------*/
+
+
+case 91:
+/* rule 91 can match eol */
+YY_RULE_SETUP
+#line 488 "../../src/scan-gram.l"
+STRING_GROW; BEGIN context_state;
+ YY_BREAK
+case YY_STATE_EOF(SC_COMMENT):
+#line 489 "../../src/scan-gram.l"
+unexpected_eof (token_start, "*/"); BEGIN context_state;
+ YY_BREAK
+
+/*--------------------------------------------------------------.
+ | Scanning a line comment. The initial '//' is already eaten. |
+ `--------------------------------------------------------------*/
+
+
+case 92:
+/* rule 92 can match eol */
+YY_RULE_SETUP
+#line 499 "../../src/scan-gram.l"
+STRING_GROW; BEGIN context_state;
+ YY_BREAK
+case 93:
+/* rule 93 can match eol */
+YY_RULE_SETUP
+#line 500 "../../src/scan-gram.l"
+STRING_GROW;
+ YY_BREAK
+case YY_STATE_EOF(SC_LINE_COMMENT):
+#line 501 "../../src/scan-gram.l"
+BEGIN context_state;
+ YY_BREAK
+
+/*------------------------------------------------.
+ | Scanning a Bison string, including its escapes. |
+ | The initial quote is already eaten. |
+ `------------------------------------------------*/
+
+
+case 94:
+YY_RULE_SETUP
+#line 512 "../../src/scan-gram.l"
+{
+ STRING_FINISH;
+ loc->start = token_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return STRING;
+ }
+ YY_BREAK
+case YY_STATE_EOF(SC_ESCAPED_STRING):
+#line 519 "../../src/scan-gram.l"
+unexpected_eof (token_start, "\"");
+ YY_BREAK
+case 95:
+/* rule 95 can match eol */
+YY_RULE_SETUP
+#line 520 "../../src/scan-gram.l"
+unexpected_newline (token_start, "\"");
+ YY_BREAK
+
+/*----------------------------------------------------------.
+ | Scanning a Bison character literal, decoding its escapes. |
+ | The initial quote is already eaten. |
+ `----------------------------------------------------------*/
+
+
+case 96:
+YY_RULE_SETUP
+#line 530 "../../src/scan-gram.l"
+{
+ STRING_FINISH;
+ loc->start = token_start;
+ val->character = last_string[0];
+
+ /* FIXME: Eventually, make these errors. */
+ if (last_string[0] == '\0')
+ {
+ complain (loc, Wother, _("empty character literal"));
+ /* '\0' seems dangerous even if we are about to complain. */
+ val->character = '\'';
+ }
+ else if (last_string[1] != '\0')
+ complain (loc, Wother,
+ _("extra characters in character literal"));
+ STRING_FREE;
+ BEGIN INITIAL;
+ return CHAR;
+ }
+ YY_BREAK
+case 97:
+/* rule 97 can match eol */
+YY_RULE_SETUP
+#line 549 "../../src/scan-gram.l"
+unexpected_newline (token_start, "'");
+ YY_BREAK
+case YY_STATE_EOF(SC_ESCAPED_CHARACTER):
+#line 550 "../../src/scan-gram.l"
+unexpected_eof (token_start, "'");
+ YY_BREAK
+
+/*--------------------------------------------------------------.
+ | Scanning a tag. The initial angle bracket is already eaten. |
+ `--------------------------------------------------------------*/
+
+
+case 98:
+YY_RULE_SETUP
+#line 561 "../../src/scan-gram.l"
+{
+ --nesting;
+ if (nesting < 0)
+ {
+ STRING_FINISH;
+ loc->start = token_start;
+ val->uniqstr = uniqstr_new (last_string);
+ STRING_FREE;
+ BEGIN INITIAL;
+ return TAG;
+ }
+ STRING_GROW;
+ }
+ YY_BREAK
+case 99:
+/* rule 99 can match eol */
+YY_RULE_SETUP
+#line 575 "../../src/scan-gram.l"
+STRING_GROW;
+ YY_BREAK
+case 100:
+YY_RULE_SETUP
+#line 576 "../../src/scan-gram.l"
+STRING_GROW; nesting += gram_leng;
+ YY_BREAK
+case YY_STATE_EOF(SC_TAG):
+#line 578 "../../src/scan-gram.l"
+unexpected_eof (token_start, ">");
+ YY_BREAK
+
+/*----------------------------.
+ | Decode escaped characters. |
+ `----------------------------*/
+
+
+case 101:
+YY_RULE_SETUP
+#line 587 "../../src/scan-gram.l"
+{
+ unsigned long int c = strtoul (gram_text + 1, NULL, 8);
+ if (!c || UCHAR_MAX < c)
+ complain (loc, complaint, _("invalid number after \\-escape: %s"),
+ gram_text+1);
+ else
+ obstack_1grow (&obstack_for_string, c);
+ }
+ YY_BREAK
+case 102:
+YY_RULE_SETUP
+#line 596 "../../src/scan-gram.l"
+{
+ verify (UCHAR_MAX < ULONG_MAX);
+ unsigned long int c = strtoul (gram_text + 2, NULL, 16);
+ if (!c || UCHAR_MAX < c)
+ complain (loc, complaint, _("invalid number after \\-escape: %s"),
+ gram_text+1);
+ else
+ obstack_1grow (&obstack_for_string, c);
+ }
+ YY_BREAK
+case 103:
+YY_RULE_SETUP
+#line 606 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, '\a');
+ YY_BREAK
+case 104:
+YY_RULE_SETUP
+#line 607 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, '\b');
+ YY_BREAK
+case 105:
+YY_RULE_SETUP
+#line 608 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, '\f');
+ YY_BREAK
+case 106:
+YY_RULE_SETUP
+#line 609 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, '\n');
+ YY_BREAK
+case 107:
+YY_RULE_SETUP
+#line 610 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, '\r');
+ YY_BREAK
+case 108:
+YY_RULE_SETUP
+#line 611 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, '\t');
+ YY_BREAK
+case 109:
+YY_RULE_SETUP
+#line 612 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, '\v');
+ YY_BREAK
+/* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
+case 110:
+YY_RULE_SETUP
+#line 615 "../../src/scan-gram.l"
+obstack_1grow (&obstack_for_string, gram_text[1]);
+ YY_BREAK
+case 111:
+YY_RULE_SETUP
+#line 617 "../../src/scan-gram.l"
+{
+ int c = convert_ucn_to_byte (gram_text);
+ if (c <= 0)
+ complain (loc, complaint, _("invalid number after \\-escape: %s"),
+ gram_text+1);
+ else
+ obstack_1grow (&obstack_for_string, c);
+ }
+ YY_BREAK
+case 112:
+/* rule 112 can match eol */
+YY_RULE_SETUP
+#line 625 "../../src/scan-gram.l"
+{
+ char const *p = gram_text + 1;
+ /* Quote only if escaping won't make the character visible. */
+ if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
+ p = quote (p);
+ else
+ p = quotearg_style_mem (escape_quoting_style, p, 1);
+ complain (loc, complaint, _("invalid character after \\-escape: %s"),
+ p);
+ }
+ YY_BREAK
+
+/*--------------------------------------------.
+ | Scanning user-code characters and strings. |
+ `--------------------------------------------*/
+
+
+case 113:
+/* rule 113 can match eol */
+YY_RULE_SETUP
+#line 643 "../../src/scan-gram.l"
+STRING_GROW;
+ YY_BREAK
+
+
+
+case 114:
+YY_RULE_SETUP
+#line 648 "../../src/scan-gram.l"
+STRING_GROW; BEGIN context_state;
+ YY_BREAK
+case 115:
+/* rule 115 can match eol */
+YY_RULE_SETUP
+#line 649 "../../src/scan-gram.l"
+unexpected_newline (token_start, "'");
+ YY_BREAK
+case YY_STATE_EOF(SC_CHARACTER):
+#line 650 "../../src/scan-gram.l"
+unexpected_eof (token_start, "'");
+ YY_BREAK
+
+
+
+case 116:
+YY_RULE_SETUP
+#line 655 "../../src/scan-gram.l"
+STRING_GROW; BEGIN context_state;
+ YY_BREAK
+case 117:
+/* rule 117 can match eol */
+YY_RULE_SETUP
+#line 656 "../../src/scan-gram.l"
+unexpected_newline (token_start, "\"");
+ YY_BREAK
+case YY_STATE_EOF(SC_STRING):
+#line 657 "../../src/scan-gram.l"
+unexpected_eof (token_start, "\"");
+ YY_BREAK
+
+/*---------------------------------------------------.
+ | Strings, comments etc. can be found in user code. |
+ `---------------------------------------------------*/
+
+
+case 118:
+YY_RULE_SETUP
+#line 667 "../../src/scan-gram.l"
+{
+ STRING_GROW;
+ context_state = YY_START;
+ token_start = loc->start;
+ BEGIN SC_CHARACTER;
+ }
+ YY_BREAK
+case 119:
+YY_RULE_SETUP
+#line 673 "../../src/scan-gram.l"
+{
+ STRING_GROW;
+ context_state = YY_START;
+ token_start = loc->start;
+ BEGIN SC_STRING;
+ }
+ YY_BREAK
+case 120:
+/* rule 120 can match eol */
+YY_RULE_SETUP
+#line 679 "../../src/scan-gram.l"
+{
+ STRING_GROW;
+ context_state = YY_START;
+ token_start = loc->start;
+ BEGIN SC_COMMENT;
+ }
+ YY_BREAK
+case 121:
+/* rule 121 can match eol */
+YY_RULE_SETUP
+#line 685 "../../src/scan-gram.l"
+{
+ STRING_GROW;
+ context_state = YY_START;
+ BEGIN SC_LINE_COMMENT;
+ }
+ YY_BREAK
+
+/*-----------------------------------------------------------.
+ | Scanning some code in braces (actions, predicates). The |
+ | initial "{" is already eaten. |
+ `-----------------------------------------------------------*/
+
+
+case 122:
+/* rule 122 can match eol */
+YY_RULE_SETUP
+#line 701 "../../src/scan-gram.l"
+STRING_GROW; nesting++;
+ YY_BREAK
+case 123:
+/* rule 123 can match eol */
+YY_RULE_SETUP
+#line 702 "../../src/scan-gram.l"
+STRING_GROW; nesting--;
+ YY_BREAK
+/* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
+ (as '<' '<%'). */
+case 124:
+/* rule 124 can match eol */
+YY_RULE_SETUP
+#line 706 "../../src/scan-gram.l"
+STRING_GROW;
+ YY_BREAK
+case YY_STATE_EOF(SC_BRACED_CODE):
+case YY_STATE_EOF(SC_PREDICATE):
+#line 708 "../../src/scan-gram.l"
+unexpected_eof (code_start, "}");
+ YY_BREAK
+
+
+
+case 125:
+YY_RULE_SETUP
+#line 713 "../../src/scan-gram.l"
+{
+ obstack_1grow (&obstack_for_string, '}');
+
+ --nesting;
+ if (nesting < 0)
+ {
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return BRACED_CODE;
+ }
+ }
+ YY_BREAK
+
+
+
+case 126:
+YY_RULE_SETUP
+#line 730 "../../src/scan-gram.l"
+{
+ --nesting;
+ if (nesting < 0)
+ {
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return BRACED_PREDICATE;
+ }
+ else
+ obstack_1grow (&obstack_for_string, '}');
+ }
+ YY_BREAK
+
+/*--------------------------------------------------------------.
+ | Scanning some prologue: from "%{" (already scanned) to "%}". |
+ `--------------------------------------------------------------*/
+
+
+case 127:
+YY_RULE_SETUP
+#line 751 "../../src/scan-gram.l"
+{
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return PROLOGUE;
+ }
+ YY_BREAK
+case YY_STATE_EOF(SC_PROLOGUE):
+#line 759 "../../src/scan-gram.l"
+unexpected_eof (code_start, "%}");
+ YY_BREAK
+
+/*---------------------------------------------------------------.
+ | Scanning the epilogue (everything after the second "%%", which |
+ | has already been eaten). |
+ `---------------------------------------------------------------*/
+
+
+case YY_STATE_EOF(SC_EPILOGUE):
+#line 770 "../../src/scan-gram.l"
+{
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return EPILOGUE;
+ }
+ YY_BREAK
+
+/*-----------------------------------------------------.
+ | By default, grow the string obstack with the input. |
+ `-----------------------------------------------------*/
+case 128:
+#line 785 "../../src/scan-gram.l"
+case 129:
+/* rule 129 can match eol */
+YY_RULE_SETUP
+#line 785 "../../src/scan-gram.l"
+STRING_GROW;
+ YY_BREAK
+case 130:
+YY_RULE_SETUP
+#line 787 "../../src/scan-gram.l"
+YY_FATAL_ERROR( "flex scanner jammed" );
+ YY_BREAK
+#line 2661 "src/scan-gram.c"
+case YY_STATE_EOF(SC_RETURN_BRACKETED_ID):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed gram_in at a new source and called
+ * gram_lex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = gram_in;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( gram_wrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * gram_text, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of gram_lex */
+/* %ok-for-header */
+
+/* %if-c++-only */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %endif */
+
+/* yy_get_next_buffer - try to read in a new buffer
*
- */
-/* %if-c-only */
- void gram__switch_to_buffer (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- /* TODO. We should be able to replace this entire function body
- * with
- * gram_pop_buffer_state();
- * gram_push_buffer_state(new_buffer);
- */
- gram_ensure_buffer_stack ();
- if ( YY_CURRENT_BUFFER == new_buffer )
- return;
-
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
- gram__load_buffer_state( );
-
- /* We don't actually know whether we did this switch during
- * EOF (gram_wrap()) processing, but the only time this flag
- * is looked at is after gram_wrap() is called, so it's safe
- * to go ahead and always set it.
- */
- (yy_did_buffer_switch_on_eof) = 1;
-}
-
-/* %if-c-only */
-static void gram__load_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
- gram_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
- (yy_hold_char) = *(yy_c_buf_p);
-}
-
-/** Allocate and initialize an input buffer state.
- * @param file A readable stream.
- * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+/* %if-c-only */
+static int yy_get_next_buffer (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ yy_size_t num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ yy_size_t new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ gram_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ gram_restart(gram_in );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) gram_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+/* %if-c-only */
+/* %not-for-header */
+
+ static yy_state_type yy_get_previous_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+/* %% [15.0] code to get the start state into yy_current_state goes here */
+ yy_current_state = (yy_start);
+ yy_current_state += YY_AT_BOL();
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+/* %% [16.0] code to find the next state goes here */
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 59);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 582 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
*
- * @return the allocated buffer state.
- */
-/* %if-c-only */
- YY_BUFFER_STATE gram__create_buffer (FILE * file, int size )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) gram_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in gram__create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (char *) gram_alloc(b->yy_buf_size + 2 );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in gram__create_buffer()" );
-
- b->yy_is_our_buffer = 1;
-
- gram__init_buffer(b,file );
-
- return b;
-}
-
-/** Destroy the buffer.
- * @param b a buffer created with gram__create_buffer()
- *
- */
-/* %if-c-only */
- void gram__delete_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! b )
- return;
-
- if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
- YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
-
- if ( b->yy_is_our_buffer )
- gram_free((void *) b->yy_ch_buf );
-
- gram_free((void *) b );
-}
-
-/* Initializes or reinitializes a buffer.
- * This function is sometimes called more than once on the same buffer,
- * such as during a gram_restart() or at EOF.
- */
-/* %if-c-only */
- static void gram__init_buffer (YY_BUFFER_STATE b, FILE * file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-{
- int oerrno = errno;
-
- gram__flush_buffer(b );
-
- b->yy_input_file = file;
- b->yy_fill_buffer = 1;
-
- /* If b is the current buffer, then gram__init_buffer was _probably_
- * called from gram_restart() or through yy_get_next_buffer.
- * In that case, we don't want to reset the lineno or column.
- */
- if (b != YY_CURRENT_BUFFER){
- b->yy_bs_lineno = 1;
- b->yy_bs_column = 0;
- }
-
-/* %if-c-only */
-
- b->yy_is_interactive = 0;
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
- errno = oerrno;
-}
-
-/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
- * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- *
- */
-/* %if-c-only */
- void gram__flush_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if ( ! b )
- return;
-
- b->yy_n_chars = 0;
-
- /* We always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[0];
-
- b->yy_at_bol = 1;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- if ( b == YY_CURRENT_BUFFER )
- gram__load_buffer_state( );
-}
-
-/* %if-c-or-c++ */
-/** Pushes the new state onto the stack. The new state becomes
- * the current state. This function will allocate the stack
- * if necessary.
- * @param new_buffer The new state.
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+/* %if-c-only */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register int yy_is_jam;
+ /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 59;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 582 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 581);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+/* %if-c-only */
+
+ static void yyunput (int c, register char * yy_bp )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register char *yy_cp;
+
+ yy_cp = (yy_c_buf_p);
+
+ /* undo effects of setting up gram_text */
+ *yy_cp = (yy_hold_char);
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ { /* need to shift things up to make room */
+ /* +2 for EOB chars. */
+ register yy_size_t number_to_move = (yy_n_chars) + 2;
+ register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
+ register char *source =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
+
+ while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
+
+ if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
+ YY_FATAL_ERROR( "flex scanner push-back overflow" );
+ }
+
+ *--yy_cp = (char) c;
+
+/* %% [18.0] update gram_lineno here */
+
+ (yytext_ptr) = yy_bp;
+ (yy_hold_char) = *yy_cp;
+ (yy_c_buf_p) = yy_cp;
+}
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c-only */
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ gram_restart(gram_in );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( gram_wrap( ) )
+ return EOF;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve gram_text */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+/* %% [19.0] update BOL and gram_lineno */
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n');
+
+ return c;
+}
+/* %if-c-only */
+#endif /* ifndef YY_NO_INPUT */
+/* %endif */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
*
- */
-/* %if-c-only */
-void gram_push_buffer_state (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (new_buffer == NULL)
- return;
-
- gram_ensure_buffer_stack();
-
- /* This block is copied from gram__switch_to_buffer. */
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- /* Only push if top exists. Otherwise, replace top. */
- if (YY_CURRENT_BUFFER)
- (yy_buffer_stack_top)++;
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
-
- /* copied from gram__switch_to_buffer. */
- gram__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/** Removes and deletes the top of the stack, if present.
- * The next element becomes the new top.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+/* %if-c-only */
+ void gram_restart (FILE * input_file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ gram_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ gram__create_buffer(gram_in,YY_BUF_SIZE );
+ }
+
+ gram__init_buffer(YY_CURRENT_BUFFER,input_file );
+ gram__load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+/* %if-c-only */
+ void gram__switch_to_buffer (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * gram_pop_buffer_state();
+ * gram_push_buffer_state(new_buffer);
+ */
+ gram_ensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ gram__load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (gram_wrap()) processing, but the only time this flag
+ * is looked at is after gram_wrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/* %if-c-only */
+static void gram__load_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ gram_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+/* %if-c-only */
+ YY_BUFFER_STATE gram__create_buffer (FILE * file, int size )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) gram_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in gram__create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) gram_alloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in gram__create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ gram__init_buffer(b,file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with gram__create_buffer()
+ *
+ */
+/* %if-c-only */
+ void gram__delete_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ gram_free((void *) b->yy_ch_buf );
+
+ gram_free((void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a gram_restart() or at EOF.
+ */
+/* %if-c-only */
+ static void gram__init_buffer (YY_BUFFER_STATE b, FILE * file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+{
+ int oerrno = errno;
+
+ gram__flush_buffer(b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then gram__init_buffer was _probably_
+ * called from gram_restart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+/* %if-c-only */
+
+ b->yy_is_interactive = 0;
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+/* %if-c-only */
+ void gram__flush_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ gram__load_buffer_state( );
+}
+
+/* %if-c-or-c++ */
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+/* %if-c-only */
+void gram_push_buffer_state (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (new_buffer == NULL)
+ return;
+
+ gram_ensure_buffer_stack();
+
+ /* This block is copied from gram__switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from gram__switch_to_buffer. */
+ gram__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+/* %if-c-only */
+void gram_pop_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ gram__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ gram__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+/* %if-c-only */
+static void gram_ensure_buffer_stack (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)gram_alloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in gram_ensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)gram_realloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in gram_ensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE gram__scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) gram_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in gram__scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ gram__switch_to_buffer(b );
+
+ return b;
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan a string. The next call to gram_lex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
*
- */
-/* %if-c-only */
-void gram_pop_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (!YY_CURRENT_BUFFER)
- return;
-
- gram__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- if ((yy_buffer_stack_top) > 0)
- --(yy_buffer_stack_top);
-
- if (YY_CURRENT_BUFFER) {
- gram__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
- }
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/* Allocates the stack if it does not exist.
- * Guarantees space for at least one push.
- */
-/* %if-c-only */
-static void gram_ensure_buffer_stack (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- yy_size_t num_to_alloc;
-
- if (!(yy_buffer_stack)) {
-
- /* First allocation is just for 2 elements, since we don't know if this
- * scanner will even need a stack. We use 2 instead of 1 to avoid an
- * immediate realloc on the next call.
- */
- num_to_alloc = 1;
- (yy_buffer_stack) = (struct yy_buffer_state**)gram_alloc
- (num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in gram_ensure_buffer_stack()" );
-
- memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-
- (yy_buffer_stack_max) = num_to_alloc;
- (yy_buffer_stack_top) = 0;
- return;
- }
-
- if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
-
- /* Increase the buffer to prepare for a possible push. */
- int grow_size = 8 /* arbitrary grow size */;
-
- num_to_alloc = (yy_buffer_stack_max) + grow_size;
- (yy_buffer_stack) = (struct yy_buffer_state**)gram_realloc
- ((yy_buffer_stack),
- num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in gram_ensure_buffer_stack()" );
-
- /* zero only the new slots.*/
- memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
- (yy_buffer_stack_max) = num_to_alloc;
- }
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan directly from a user-specified character buffer.
- * @param base the character buffer
- * @param size the size in bytes of the character buffer
- *
* @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE gram__scan_buffer (char * base, yy_size_t size )
-{
- YY_BUFFER_STATE b;
-
- if ( size < 2 ||
- base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
- /* They forgot to leave room for the EOB's. */
- return 0;
-
- b = (YY_BUFFER_STATE) gram_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in gram__scan_buffer()" );
-
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
- b->yy_buf_pos = b->yy_ch_buf = base;
- b->yy_is_our_buffer = 0;
- b->yy_input_file = 0;
- b->yy_n_chars = b->yy_buf_size;
- b->yy_is_interactive = 0;
- b->yy_at_bol = 1;
- b->yy_fill_buffer = 0;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- gram__switch_to_buffer(b );
-
- return b;
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan a string. The next call to gram_lex() will
- * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
- *
- * @return the newly allocated buffer state object.
- * @note If you want to scan bytes that may contain NUL values, then use
- * gram__scan_bytes() instead.
- */
-YY_BUFFER_STATE gram__scan_string (yyconst char * yystr )
-{
-
- return gram__scan_bytes(yystr,strlen(yystr) );
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan the given bytes. The next call to gram_lex() will
- * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
- *
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE gram__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
-{
- YY_BUFFER_STATE b;
- char *buf;
- yy_size_t n;
- int i;
-
- /* Get memory for full buffer, including space for trailing EOB's. */
- n = _yybytes_len + 2;
- buf = (char *) gram_alloc(n );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in gram__scan_bytes()" );
-
- for ( i = 0; i < _yybytes_len; ++i )
- buf[i] = yybytes[i];
-
- buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
-
- b = gram__scan_buffer(buf,n );
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in gram__scan_bytes()" );
-
- /* It's okay to grow etc. this buffer, and we should throw it
- * away when we're done.
- */
- b->yy_is_our_buffer = 1;
-
- return b;
-}
-/* %endif */
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-/* %if-c-only */
-static void yy_fatal_error (yyconst char* msg )
-{
- (void) fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
-}
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up gram_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- gram_text[gram_leng] = (yy_hold_char); \
- (yy_c_buf_p) = gram_text + yyless_macro_arg; \
- (yy_hold_char) = *(yy_c_buf_p); \
- *(yy_c_buf_p) = '\0'; \
- gram_leng = yyless_macro_arg; \
- } \
- while ( 0 )
-
-/* Accessor methods (get/set functions) to struct members. */
-
-/* %if-c-only */
-/* %if-reentrant */
-/* %endif */
-
-/** Get the current line number.
- *
- */
-int gram_get_lineno (void)
-{
-
- return gram_lineno;
-}
-
-/** Get the input stream.
- *
- */
-FILE *gram_get_in (void)
-{
- return gram_in;
-}
-
-/** Get the output stream.
- *
- */
-FILE *gram_get_out (void)
-{
- return gram_out;
-}
-
-/** Get the length of the current token.
- *
- */
-yy_size_t gram_get_leng (void)
-{
- return gram_leng;
-}
-
-/** Get the current token.
- *
- */
-
-char *gram_get_text (void)
-{
- return gram_text;
-}
-
-/* %if-reentrant */
-/* %endif */
-
-/** Set the current line number.
- * @param line_number
- *
- */
-void gram_set_lineno (int line_number )
-{
-
- gram_lineno = line_number;
-}
-
-/** Set the input stream. This does not discard the current
- * input buffer.
- * @param in_str A readable stream.
- *
- * @see gram__switch_to_buffer
- */
-void gram_set_in (FILE * in_str )
-{
- gram_in = in_str ;
-}
-
-void gram_set_out (FILE * out_str )
-{
- gram_out = out_str ;
-}
-
-int gram_get_debug (void)
-{
- return gram__flex_debug;
-}
-
-void gram_set_debug (int bdebug )
-{
- gram__flex_debug = bdebug ;
-}
-
-/* %endif */
-
-/* %if-reentrant */
-/* %if-bison-bridge */
-/* %endif */
-/* %endif if-c-only */
-
-/* %if-c-only */
-static int yy_init_globals (void)
-{
- /* Initialization is the same as for the non-reentrant scanner.
- * This function is called from gram_lex_destroy(), so don't allocate here.
- */
-
- (yy_buffer_stack) = 0;
- (yy_buffer_stack_top) = 0;
- (yy_buffer_stack_max) = 0;
- (yy_c_buf_p) = (char *) 0;
- (yy_init) = 0;
- (yy_start) = 0;
-
-/* Defined in main.c */
-#ifdef YY_STDINIT
- gram_in = stdin;
- gram_out = stdout;
-#else
- gram_in = (FILE *) 0;
- gram_out = (FILE *) 0;
-#endif
-
- /* For future reference: Set errno on error, since we are called by
- * gram_lex_init()
- */
- return 0;
-}
-/* %endif */
-
-/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
-/* gram_lex_destroy is for both reentrant and non-reentrant scanners. */
-int gram_lex_destroy (void)
-{
-
- /* Pop the buffer stack, destroying each element. */
- while(YY_CURRENT_BUFFER){
- gram__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- gram_pop_buffer_state();
- }
-
- /* Destroy the stack itself. */
- gram_free((yy_buffer_stack) );
- (yy_buffer_stack) = NULL;
-
- /* Reset the globals. This is important in a non-reentrant scanner so the next time
- * gram_lex() is called, initialization will occur. */
- yy_init_globals( );
-
-/* %if-reentrant */
-/* %endif */
- return 0;
-}
-/* %endif */
-
-/*
- * Internal utility routines.
- */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
-{
- register int i;
- for ( i = 0; i < n; ++i )
- s1[i] = s2[i];
-}
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s )
-{
- register int n;
- for ( n = 0; s[n]; ++n )
- ;
-
- return n;
-}
-#endif
-
-void *gram_alloc (yy_size_t size )
-{
- return (void *) malloc( size );
-}
-
-void *gram_realloc (void * ptr, yy_size_t size )
-{
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- return (void *) realloc( (char *) ptr, size );
-}
-
-void gram_free (void * ptr )
-{
- free( (char *) ptr ); /* see gram_realloc() for (char *) cast */
-}
-
-/* %if-tables-serialization definitions */
-/* %define-yytables The name for this specific scanner's tables. */
-#define YYTABLES_NAME "yytables"
-/* %endif */
-
-/* %ok-for-header */
-
-#line 787 "../../src/scan-gram.l"
-
-
-
-/* Read bytes from FP into buffer BUF of size SIZE. Return the
- number of bytes read. Remove '\r' from input, treating \r\n
- and isolated \r as \n. */
-
-static size_t
-no_cr_read (FILE *fp, char *buf, size_t size)
-{
- size_t bytes_read = fread (buf, 1, size, fp);
- if (bytes_read)
- {
- char *w = memchr (buf, '\r', bytes_read);
- if (w)
- {
- char const *r = ++w;
- char const *lim = buf + bytes_read;
-
- for (;;)
- {
- /* Found an '\r'. Treat it like '\n', but ignore any
- '\n' that immediately follows. */
- w[-1] = '\n';
- if (r == lim)
- {
- int ch = getc (fp);
- if (ch != '\n' && ungetc (ch, fp) != ch)
- break;
- }
- else if (*r == '\n')
- r++;
-
- /* Copy until the next '\r'. */
- do
- {
- if (r == lim)
- return w - buf;
- }
- while ((*w++ = *r++) != '\r');
- }
-
- return w - buf;
- }
- }
-
- return bytes_read;
-}
-
-
-
-/*------------------------------------------------------.
-| Scan NUMBER for a base-BASE integer at location LOC. |
-`------------------------------------------------------*/
-
-static unsigned long int
-scan_integer (char const *number, int base, location loc)
-{
- verify (INT_MAX < ULONG_MAX);
- unsigned long int num = strtoul (number, NULL, base);
-
- if (INT_MAX < num)
- {
- complain (&loc, complaint, _("integer out of range: %s"),
- quote (number));
- num = INT_MAX;
- }
-
- return num;
-}
-
-
-/*------------------------------------------------------------------.
-| Convert universal character name UCN to a single-byte character, |
-| and return that character. Return -1 if UCN does not correspond |
-| to a single-byte character. |
-`------------------------------------------------------------------*/
-
-static int
-convert_ucn_to_byte (char const *ucn)
-{
- verify (UCHAR_MAX <= INT_MAX);
- unsigned long int code = strtoul (ucn + 2, NULL, 16);
-
- /* FIXME: Currently we assume Unicode-compatible unibyte characters
- on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
- non-ASCII hosts we support only the portable C character set.
- These limitations should be removed once we add support for
- multibyte characters. */
-
- if (UCHAR_MAX < code)
- return -1;
-
-#if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
- {
- /* A non-ASCII host. Use CODE to index into a table of the C
- basic execution character set, which is guaranteed to exist on
- all Standard C platforms. This table also includes '$', '@',
- and '`', which are not in the basic execution character set but
- which are unibyte characters on all the platforms that we know
- about. */
- static signed char const table[] =
- {
- '\0', -1, -1, -1, -1, -1, -1, '\a',
- '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1,
- ' ', '!', '"', '#', '$', '%', '&', '\'',
- '(', ')', '*', '+', ',', '-', '.', '/',
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', ':', ';', '<', '=', '>', '?',
- '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
- 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
- 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
- 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
- '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', '{', '|', '}', '~'
- };
-
- code = code < sizeof table ? table[code] : -1;
- }
-#endif
-
- return code;
-}
-
-
-/*---------------------------------------------------------------------.
-| Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
-`---------------------------------------------------------------------*/
-
-static void
-handle_syncline (char *args, location loc)
-{
- char *file;
- unsigned long int lineno = strtoul (args, &file, 10);
- if (INT_MAX <= lineno)
- {
- complain (&loc, Wother, _("line number overflow"));
- lineno = INT_MAX;
- }
-
- file = strchr (file, '"');
- if (file)
- {
- *strchr (file + 1, '"') = '\0';
- current_file = uniqstr_new (file + 1);
- }
- boundary_set (&scanner_cursor, current_file, lineno, 1);
-}
-
-
-/*----------------------------------------------------------------.
-| For a token or comment starting at START, report message MSGID, |
-| which should say that an end marker was found before the |
-| expected TOKEN_END. Then, pretend that TOKEN_END was found. |
-`----------------------------------------------------------------*/
-
-static void
-unexpected_end (boundary start, char const *msgid, char const *token_end)
-{
- location loc;
- size_t i;
- loc.start = start;
- loc.end = scanner_cursor;
- i = strlen (token_end);
-
-/* Adjust scanner cursor so that any later message does not count
- the characters about to be inserted. */
- scanner_cursor.column -= i;
-
- while (i != 0)
- unput (token_end[--i]);
-
- token_end = quote (token_end);
- /* Instead of '\'', display "'". */
- if (STREQ (token_end, "'\\''"))
- token_end = "\"'\"";
- complain (&loc, complaint, _(msgid), token_end);
-}
-
-
-/*------------------------------------------------------------------------.
-| Report an unexpected EOF in a token or comment starting at START. |
-| An end of file was encountered and the expected TOKEN_END was missing. |
-| After reporting the problem, pretend that TOKEN_END was found. |
-`------------------------------------------------------------------------*/
-
-static void
-unexpected_eof (boundary start, char const *token_end)
-{
- unexpected_end (start, N_("missing %s at end of file"), token_end);
-}
-
-
-/*----------------------------------------.
-| Likewise, but for unexpected newlines. |
-`----------------------------------------*/
-
-static void
-unexpected_newline (boundary start, char const *token_end)
-{
- unexpected_end (start, N_("missing %s at end of line"), token_end);
-}
-
-
-/*-------------------------.
-| Initialize the scanner. |
-`-------------------------*/
-
-void
-gram_scanner_initialize (void)
-{
- obstack_init (&obstack_for_string);
-}
-
-
-/*-----------------------------------------------.
-| Free all the memory allocated to the scanner. |
-`-----------------------------------------------*/
-
-void
-gram_scanner_free (void)
-{
- obstack_free (&obstack_for_string, 0);
- /* Reclaim Flex's buffers. */
- gram_lex_destroy ();
-}
-
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * gram__scan_bytes() instead.
+ */
+YY_BUFFER_STATE gram__scan_string (yyconst char * yystr )
+{
+
+ return gram__scan_bytes(yystr,strlen(yystr) );
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan the given bytes. The next call to gram_lex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE gram__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) gram_alloc(n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in gram__scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = gram__scan_buffer(buf,n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in gram__scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+/* %endif */
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+/* %if-c-only */
+static void yy_fatal_error (yyconst char* msg )
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up gram_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ gram_text[gram_leng] = (yy_hold_char); \
+ (yy_c_buf_p) = gram_text + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ gram_leng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/* %if-c-only */
+/* %if-reentrant */
+/* %endif */
+
+/** Get the current line number.
+ *
+ */
+int gram_get_lineno (void)
+{
+
+ return gram_lineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *gram_get_in (void)
+{
+ return gram_in;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *gram_get_out (void)
+{
+ return gram_out;
+}
+
+/** Get the length of the current token.
+ *
+ */
+yy_size_t gram_get_leng (void)
+{
+ return gram_leng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *gram_get_text (void)
+{
+ return gram_text;
+}
+
+/* %if-reentrant */
+/* %endif */
+
+/** Set the current line number.
+ * @param line_number
+ *
+ */
+void gram_set_lineno (int line_number )
+{
+
+ gram_lineno = line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ *
+ * @see gram__switch_to_buffer
+ */
+void gram_set_in (FILE * in_str )
+{
+ gram_in = in_str ;
+}
+
+void gram_set_out (FILE * out_str )
+{
+ gram_out = out_str ;
+}
+
+int gram_get_debug (void)
+{
+ return gram__flex_debug;
+}
+
+void gram_set_debug (int bdebug )
+{
+ gram__flex_debug = bdebug ;
+}
+
+/* %endif */
+
+/* %if-reentrant */
+/* %if-bison-bridge */
+/* %endif */
+/* %endif if-c-only */
+
+/* %if-c-only */
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from gram_lex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = 0;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = (char *) 0;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ gram_in = stdin;
+ gram_out = stdout;
+#else
+ gram_in = (FILE *) 0;
+ gram_out = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * gram_lex_init()
+ */
+ return 0;
+}
+/* %endif */
+
+/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
+/* gram_lex_destroy is for both reentrant and non-reentrant scanners. */
+int gram_lex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ gram__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ gram_pop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ gram_free((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * gram_lex() is called, initialization will occur. */
+ yy_init_globals( );
+
+/* %if-reentrant */
+/* %endif */
+ return 0;
+}
+/* %endif */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *gram_alloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *gram_realloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void gram_free (void * ptr )
+{
+ free( (char *) ptr ); /* see gram_realloc() for (char *) cast */
+}
+
+/* %if-tables-serialization definitions */
+/* %define-yytables The name for this specific scanner's tables. */
+#define YYTABLES_NAME "yytables"
+/* %endif */
+
+/* %ok-for-header */
+
+#line 787 "../../src/scan-gram.l"
+
+
+
+/* Read bytes from FP into buffer BUF of size SIZE. Return the
+ number of bytes read. Remove '\r' from input, treating \r\n
+ and isolated \r as \n. */
+
+static size_t
+no_cr_read (FILE *fp, char *buf, size_t size)
+{
+ size_t bytes_read = fread (buf, 1, size, fp);
+ if (bytes_read)
+ {
+ char *w = memchr (buf, '\r', bytes_read);
+ if (w)
+ {
+ char const *r = ++w;
+ char const *lim = buf + bytes_read;
+
+ for (;;)
+ {
+ /* Found an '\r'. Treat it like '\n', but ignore any
+ '\n' that immediately follows. */
+ w[-1] = '\n';
+ if (r == lim)
+ {
+ int ch = getc (fp);
+ if (ch != '\n' && ungetc (ch, fp) != ch)
+ break;
+ }
+ else if (*r == '\n')
+ r++;
+
+ /* Copy until the next '\r'. */
+ do
+ {
+ if (r == lim)
+ return w - buf;
+ }
+ while ((*w++ = *r++) != '\r');
+ }
+
+ return w - buf;
+ }
+ }
+
+ return bytes_read;
+}
+
+
+
+/*------------------------------------------------------.
+| Scan NUMBER for a base-BASE integer at location LOC. |
+`------------------------------------------------------*/
+
+static unsigned long int
+scan_integer (char const *number, int base, location loc)
+{
+ verify (INT_MAX < ULONG_MAX);
+ unsigned long int num = strtoul (number, NULL, base);
+
+ if (INT_MAX < num)
+ {
+ complain (&loc, complaint, _("integer out of range: %s"),
+ quote (number));
+ num = INT_MAX;
+ }
+
+ return num;
+}
+
+
+/*------------------------------------------------------------------.
+| Convert universal character name UCN to a single-byte character, |
+| and return that character. Return -1 if UCN does not correspond |
+| to a single-byte character. |
+`------------------------------------------------------------------*/
+
+static int
+convert_ucn_to_byte (char const *ucn)
+{
+ verify (UCHAR_MAX <= INT_MAX);
+ unsigned long int code = strtoul (ucn + 2, NULL, 16);
+
+ /* FIXME: Currently we assume Unicode-compatible unibyte characters
+ on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
+ non-ASCII hosts we support only the portable C character set.
+ These limitations should be removed once we add support for
+ multibyte characters. */
+
+ if (UCHAR_MAX < code)
+ return -1;
+
+#if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
+ {
+ /* A non-ASCII host. Use CODE to index into a table of the C
+ basic execution character set, which is guaranteed to exist on
+ all Standard C platforms. This table also includes '$', '@',
+ and '`', which are not in the basic execution character set but
+ which are unibyte characters on all the platforms that we know
+ about. */
+ static signed char const table[] =
+ {
+ '\0', -1, -1, -1, -1, -1, -1, '\a',
+ '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ ' ', '!', '"', '#', '$', '%', '&', '\'',
+ '(', ')', '*', '+', ',', '-', '.', '/',
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', ':', ';', '<', '=', '>', '?',
+ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
+ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+ 'x', 'y', 'z', '{', '|', '}', '~'
+ };
+
+ code = code < sizeof table ? table[code] : -1;
+ }
+#endif
+
+ return code;
+}
+
+
+/*---------------------------------------------------------------------.
+| Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
+`---------------------------------------------------------------------*/
+
+static void
+handle_syncline (char *args, location loc)
+{
+ char *file;
+ unsigned long int lineno = strtoul (args, &file, 10);
+ if (INT_MAX <= lineno)
+ {
+ complain (&loc, Wother, _("line number overflow"));
+ lineno = INT_MAX;
+ }
+
+ file = strchr (file, '"');
+ if (file)
+ {
+ *strchr (file + 1, '"') = '\0';
+ current_file = uniqstr_new (file + 1);
+ }
+ boundary_set (&scanner_cursor, current_file, lineno, 1);
+}
+
+
+/*----------------------------------------------------------------.
+| For a token or comment starting at START, report message MSGID, |
+| which should say that an end marker was found before the |
+| expected TOKEN_END. Then, pretend that TOKEN_END was found. |
+`----------------------------------------------------------------*/
+
+static void
+unexpected_end (boundary start, char const *msgid, char const *token_end)
+{
+ location loc;
+ size_t i;
+ loc.start = start;
+ loc.end = scanner_cursor;
+ i = strlen (token_end);
+
+/* Adjust scanner cursor so that any later message does not count
+ the characters about to be inserted. */
+ scanner_cursor.column -= i;
+
+ while (i != 0)
+ unput (token_end[--i]);
+
+ token_end = quote (token_end);
+ /* Instead of '\'', display "'". */
+ if (STREQ (token_end, "'\\''"))
+ token_end = "\"'\"";
+ complain (&loc, complaint, _(msgid), token_end);
+}
+
+
+/*------------------------------------------------------------------------.
+| Report an unexpected EOF in a token or comment starting at START. |
+| An end of file was encountered and the expected TOKEN_END was missing. |
+| After reporting the problem, pretend that TOKEN_END was found. |
+`------------------------------------------------------------------------*/
+
+static void
+unexpected_eof (boundary start, char const *token_end)
+{
+ unexpected_end (start, N_("missing %s at end of file"), token_end);
+}
+
+
+/*----------------------------------------.
+| Likewise, but for unexpected newlines. |
+`----------------------------------------*/
+
+static void
+unexpected_newline (boundary start, char const *token_end)
+{
+ unexpected_end (start, N_("missing %s at end of line"), token_end);
+}
+
+
+/*-------------------------.
+| Initialize the scanner. |
+`-------------------------*/
+
+void
+gram_scanner_initialize (void)
+{
+ obstack_init (&obstack_for_string);
+}
+
+
+/*-----------------------------------------------.
+| Free all the memory allocated to the scanner. |
+`-----------------------------------------------*/
+
+void
+gram_scanner_free (void)
+{
+ obstack_free (&obstack_for_string, 0);
+ /* Reclaim Flex's buffers. */
+ gram_lex_destroy ();
+}
+
diff --git a/contrib/tools/bison/bison/src/scan-gram.h b/contrib/tools/bison/bison/src/scan-gram.h
index ee397ed2e7..6b9fa2513d 100644
--- a/contrib/tools/bison/bison/src/scan-gram.h
+++ b/contrib/tools/bison/bison/src/scan-gram.h
@@ -1,38 +1,38 @@
-/* Bison Grammar Scanner
-
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SCAN_GRAM_H_
-# define SCAN_GRAM_H_
-
-/* From the scanner. */
-extern FILE *gram_in;
-extern int gram__flex_debug;
-void gram_scanner_initialize (void);
-void gram_scanner_free (void);
-void gram_scanner_last_string_free (void);
-
-/* These are declared by the scanner, but not used. We put them here
- to pacify "make syntax-check". */
-extern FILE *gram_out;
-extern int gram_lineno;
-
-# define GRAM_LEX_DECL int gram_lex (GRAM_STYPE *val, location *loc)
-GRAM_LEX_DECL;
-
-#endif /* !SCAN_GRAM_H_ */
+/* Bison Grammar Scanner
+
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SCAN_GRAM_H_
+# define SCAN_GRAM_H_
+
+/* From the scanner. */
+extern FILE *gram_in;
+extern int gram__flex_debug;
+void gram_scanner_initialize (void);
+void gram_scanner_free (void);
+void gram_scanner_last_string_free (void);
+
+/* These are declared by the scanner, but not used. We put them here
+ to pacify "make syntax-check". */
+extern FILE *gram_out;
+extern int gram_lineno;
+
+# define GRAM_LEX_DECL int gram_lex (GRAM_STYPE *val, location *loc)
+GRAM_LEX_DECL;
+
+#endif /* !SCAN_GRAM_H_ */
diff --git a/contrib/tools/bison/bison/src/scan-gram.l b/contrib/tools/bison/bison/src/scan-gram.l
index 665e80de64..052d578a2c 100644
--- a/contrib/tools/bison/bison/src/scan-gram.l
+++ b/contrib/tools/bison/bison/src/scan-gram.l
@@ -1,1014 +1,1014 @@
-/* Bison Grammar Scanner -*- C -*-
-
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-%option debug nodefault noinput noyywrap never-interactive
-%option prefix="gram_" outfile="lex.yy.c"
-
-%{
-/* Work around a bug in flex 2.5.31. See Debian bug 333231
- <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
-#undef gram_wrap
-#define gram_wrap() 1
-
-#define FLEX_PREFIX(Id) gram_ ## Id
-#include <src/flex-scanner.h>
-
-#include <src/complain.h>
-#include <src/files.h>
-#include <src/getargs.h>
-#include <src/gram.h>
-#include <quotearg.h>
-#include <src/reader.h>
-#include <src/uniqstr.h>
-
-#include <c-ctype.h>
-#include <mbswidth.h>
-#include <quote.h>
-
-#include <src/scan-gram.h>
-
-#define YY_DECL GRAM_LEX_DECL
-
-#define YY_USER_INIT \
- code_start = scanner_cursor = loc->start; \
-
-/* Location of scanner cursor. */
-static boundary scanner_cursor;
-
-#define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng);
-
-static size_t no_cr_read (FILE *, char *, size_t);
-#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
-
-#define RETURN_PERCENT_PARAM(Value) \
- RETURN_VALUE(PERCENT_PARAM, param, param_ ## Value)
-
-#define RETURN_PERCENT_FLAG(Value) \
- RETURN_VALUE(PERCENT_FLAG, uniqstr, uniqstr_new (Value))
-
-#define RETURN_VALUE(Token, Field, Value) \
- do { \
- val->Field = Value; \
- return Token; \
- } while (0)
-
-#define ROLLBACK_CURRENT_TOKEN \
- do { \
- scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0); \
- yyless (0); \
- } while (0)
-
-#define DEPRECATED(Msg) \
- do { \
- size_t i; \
- deprecated_directive (loc, yytext, Msg); \
- scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \
- for (i = strlen (Msg); i != 0; --i) \
- unput (Msg[i - 1]); \
- } while (0)
-
-/* A string representing the most recently saved token. */
-static char *last_string;
-
-/* Bracketed identifier. */
-static uniqstr bracketed_id_str = 0;
-static location bracketed_id_loc;
-static boundary bracketed_id_start;
-static int bracketed_id_context_state = 0;
-
-void
-gram_scanner_last_string_free (void)
-{
- STRING_FREE;
-}
-
-static void handle_syncline (char *, location);
-static unsigned long int scan_integer (char const *p, int base, location loc);
-static int convert_ucn_to_byte (char const *hex_text);
-static void unexpected_eof (boundary, char const *);
-static void unexpected_newline (boundary, char const *);
-
-%}
- /* A C-like comment in directives/rules. */
-%x SC_YACC_COMMENT
- /* Strings and characters in directives/rules. */
-%x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
- /* A identifier was just read in directives/rules. Special state
- to capture the sequence 'identifier :'. */
-%x SC_AFTER_IDENTIFIER
-
- /* POSIX says that a tag must be both an id and a C union member, but
- historically almost any character is allowed in a tag. We
- disallow NUL, as this simplifies our implementation. We match
- angle brackets in nested pairs: several languages use them for
- generics/template types. */
-%x SC_TAG
-
- /* Four types of user code:
- - prologue (code between '%{' '%}' in the first section, before %%);
- - actions, printers, union, etc, (between braced in the middle section);
- - epilogue (everything after the second %%).
- - predicate (code between '%?{' and '{' in middle section); */
-%x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE SC_PREDICATE
- /* C and C++ comments in code. */
-%x SC_COMMENT SC_LINE_COMMENT
- /* Strings and characters in code. */
-%x SC_STRING SC_CHARACTER
- /* Bracketed identifiers support. */
-%x SC_BRACKETED_ID SC_RETURN_BRACKETED_ID
-
-letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
-notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]
-id {letter}({letter}|[-0-9])*
-int [0-9]+
-
-/* Zero or more instances of backslash-newline. Following GCC, allow
- white space between the backslash and the newline. */
-splice (\\[ \f\t\v]*\n)*
-
-/* An equal sign, with optional leading whitespaces. This is used in some
- deprecated constructs. */
-eqopt ([[:space:]]*=)?
-
-%%
-%{
- /* Nesting level. Either for nested braces, or nested angle brackets
- (but not mixed). */
- int nesting PACIFY_CC (= 0);
-
- /* Parent context state, when applicable. */
- int context_state PACIFY_CC (= 0);
-
- /* Location of most recent identifier, when applicable. */
- location id_loc PACIFY_CC (= empty_location);
-
- /* Where containing code started, when applicable. Its initial
- value is relevant only when yylex is invoked in the SC_EPILOGUE
- start condition. */
- boundary code_start = scanner_cursor;
-
- /* Where containing comment or string or character literal started,
- when applicable. */
- boundary token_start PACIFY_CC (= scanner_cursor);
-%}
-
-
- /*-----------------------.
- | Scanning white space. |
- `-----------------------*/
-
-<INITIAL,SC_AFTER_IDENTIFIER,SC_BRACKETED_ID,SC_RETURN_BRACKETED_ID>
-{
- /* Comments and white space. */
- "," {
- complain (loc, Wother, _("stray ',' treated as white space"));
- }
- [ \f\n\t\v] |
- "//".* continue;
- "/*" {
- token_start = loc->start;
- context_state = YY_START;
- BEGIN SC_YACC_COMMENT;
- }
-
- /* #line directives are not documented, and may be withdrawn or
- modified in future versions of Bison. */
- ^"#line "{int}(" \"".*"\"")?"\n" {
- handle_syncline (yytext + sizeof "#line " - 1, *loc);
- }
-}
-
-
- /*----------------------------.
- | Scanning Bison directives. |
- `----------------------------*/
-
- /* For directives that are also command line options, the regex must be
- "%..."
- after "[-_]"s are removed, and the directive must match the --long
- option name, with a single string argument. Otherwise, add exceptions
- to ../build-aux/cross-options.pl. */
-
-<INITIAL>
-{
- "%binary" return PERCENT_NONASSOC;
- "%code" return PERCENT_CODE;
- "%debug" RETURN_PERCENT_FLAG("parse.trace");
- "%default-prec" return PERCENT_DEFAULT_PREC;
- "%define" return PERCENT_DEFINE;
- "%defines" return PERCENT_DEFINES;
- "%destructor" return PERCENT_DESTRUCTOR;
- "%dprec" return PERCENT_DPREC;
- "%empty" return PERCENT_EMPTY;
- "%error-verbose" return PERCENT_ERROR_VERBOSE;
- "%expect" return PERCENT_EXPECT;
- "%expect-rr" return PERCENT_EXPECT_RR;
- "%file-prefix" return PERCENT_FILE_PREFIX;
- "%fixed-output-files" return PERCENT_YACC;
- "%initial-action" return PERCENT_INITIAL_ACTION;
- "%glr-parser" return PERCENT_GLR_PARSER;
- "%language" return PERCENT_LANGUAGE;
- "%left" return PERCENT_LEFT;
- "%lex-param" RETURN_PERCENT_PARAM(lex);
- "%locations" RETURN_PERCENT_FLAG("locations");
- "%merge" return PERCENT_MERGE;
- "%name-prefix" return PERCENT_NAME_PREFIX;
- "%no-default-prec" return PERCENT_NO_DEFAULT_PREC;
- "%no-lines" return PERCENT_NO_LINES;
- "%nonassoc" return PERCENT_NONASSOC;
- "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
- "%nterm" return PERCENT_NTERM;
- "%output" return PERCENT_OUTPUT;
- "%param" RETURN_PERCENT_PARAM(both);
- "%parse-param" RETURN_PERCENT_PARAM(parse);
- "%prec" return PERCENT_PREC;
- "%precedence" return PERCENT_PRECEDENCE;
- "%printer" return PERCENT_PRINTER;
- "%pure-parser" RETURN_PERCENT_FLAG("api.pure");
- "%require" return PERCENT_REQUIRE;
- "%right" return PERCENT_RIGHT;
- "%skeleton" return PERCENT_SKELETON;
- "%start" return PERCENT_START;
- "%term" return PERCENT_TOKEN;
- "%token" return PERCENT_TOKEN;
- "%token-table" return PERCENT_TOKEN_TABLE;
- "%type" return PERCENT_TYPE;
- "%union" return PERCENT_UNION;
- "%verbose" return PERCENT_VERBOSE;
- "%yacc" return PERCENT_YACC;
-
- /* deprecated */
- "%default"[-_]"prec" DEPRECATED("%default-prec");
- "%error"[-_]"verbose" DEPRECATED("%define parse.error verbose");
- "%expect"[-_]"rr" DEPRECATED("%expect-rr");
- "%file-prefix"{eqopt} DEPRECATED("%file-prefix");
- "%fixed"[-_]"output"[-_]"files" DEPRECATED("%fixed-output-files");
- "%name"[-_]"prefix"{eqopt} DEPRECATED("%name-prefix");
- "%no"[-_]"default"[-_]"prec" DEPRECATED("%no-default-prec");
- "%no"[-_]"lines" DEPRECATED("%no-lines");
- "%output"{eqopt} DEPRECATED("%output");
- "%pure"[-_]"parser" DEPRECATED("%pure-parser");
- "%token"[-_]"table" DEPRECATED("%token-table");
-
- "%"{id}|"%"{notletter}([[:graph:]])+ {
- complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
- }
-
- "=" return EQUAL;
- "|" return PIPE;
- ";" return SEMICOLON;
-
- {id} {
- val->uniqstr = uniqstr_new (yytext);
- id_loc = *loc;
- bracketed_id_str = NULL;
- BEGIN SC_AFTER_IDENTIFIER;
- }
-
- {int} {
- val->integer = scan_integer (yytext, 10, *loc);
- return INT;
- }
- 0[xX][0-9abcdefABCDEF]+ {
- val->integer = scan_integer (yytext, 16, *loc);
- return INT;
- }
-
- /* Identifiers may not start with a digit. Yet, don't silently
- accept "1FOO" as "1 FOO". */
- {int}{id} {
- complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
- }
-
- /* Characters. */
- "'" token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
-
- /* Strings. */
- "\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
-
- /* Prologue. */
- "%{" code_start = loc->start; BEGIN SC_PROLOGUE;
-
- /* Code in between braces. */
- "{" {
- STRING_GROW;
- nesting = 0;
- code_start = loc->start;
- BEGIN SC_BRACED_CODE;
- }
-
- /* Semantic predicate. */
- "%?"[ \f\n\t\v]*"{" {
- nesting = 0;
- code_start = loc->start;
- BEGIN SC_PREDICATE;
- }
-
- /* A type. */
- "<*>" return TAG_ANY;
- "<>" return TAG_NONE;
- "<" {
- nesting = 0;
- token_start = loc->start;
- BEGIN SC_TAG;
- }
-
- "%%" {
- static int percent_percent_count;
- if (++percent_percent_count == 2)
- BEGIN SC_EPILOGUE;
- return PERCENT_PERCENT;
- }
-
- "[" {
- bracketed_id_str = NULL;
- bracketed_id_start = loc->start;
- bracketed_id_context_state = YY_START;
- BEGIN SC_BRACKETED_ID;
- }
-
- [^\[%A-Za-z0-9_<>{}\"\'*;|=/, \f\n\t\v]+|. {
- complain (loc, complaint, "%s: %s",
- ngettext ("invalid character", "invalid characters", yyleng),
- quote_mem (yytext, yyleng));
- }
-
- <<EOF>> {
- loc->start = loc->end = scanner_cursor;
- yyterminate ();
- }
-}
-
-
- /*--------------------------------------------------------------.
- | Supporting \0 complexifies our implementation for no expected |
- | added value. |
- `--------------------------------------------------------------*/
-
-<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
-{
- \0 complain (loc, complaint, _("invalid null character"));
-}
-
-
- /*-----------------------------------------------------------------.
- | Scanning after an identifier, checking whether a colon is next. |
- `-----------------------------------------------------------------*/
-
-<SC_AFTER_IDENTIFIER>
-{
- "[" {
- if (bracketed_id_str)
- {
- ROLLBACK_CURRENT_TOKEN;
- BEGIN SC_RETURN_BRACKETED_ID;
- *loc = id_loc;
- return ID;
- }
- else
- {
- bracketed_id_start = loc->start;
- bracketed_id_context_state = YY_START;
- BEGIN SC_BRACKETED_ID;
- }
- }
- ":" {
- BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
- *loc = id_loc;
- return ID_COLON;
- }
- . {
- ROLLBACK_CURRENT_TOKEN;
- BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
- *loc = id_loc;
- return ID;
- }
- <<EOF>> {
- BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
- *loc = id_loc;
- return ID;
- }
-}
-
- /*--------------------------------.
- | Scanning bracketed identifiers. |
- `--------------------------------*/
-
-<SC_BRACKETED_ID>
-{
- {id} {
- if (bracketed_id_str)
- {
- complain (loc, complaint,
- _("unexpected identifier in bracketed name: %s"),
- quote (yytext));
- }
- else
- {
- bracketed_id_str = uniqstr_new (yytext);
- bracketed_id_loc = *loc;
- }
- }
- "]" {
- BEGIN bracketed_id_context_state;
- if (bracketed_id_str)
- {
- if (INITIAL == bracketed_id_context_state)
- {
- val->uniqstr = bracketed_id_str;
- bracketed_id_str = 0;
- *loc = bracketed_id_loc;
- return BRACKETED_ID;
- }
- }
- else
- complain (loc, complaint, _("an identifier expected"));
- }
-
- [^\].A-Za-z0-9_/ \f\n\t\v]+|. {
- complain (loc, complaint, "%s: %s",
- ngettext ("invalid character in bracketed name",
- "invalid characters in bracketed name", yyleng),
- quote_mem (yytext, yyleng));
- }
-
- <<EOF>> {
- BEGIN bracketed_id_context_state;
- unexpected_eof (bracketed_id_start, "]");
- }
-}
-
-<SC_RETURN_BRACKETED_ID>
-{
- . {
- ROLLBACK_CURRENT_TOKEN;
- val->uniqstr = bracketed_id_str;
- bracketed_id_str = 0;
- *loc = bracketed_id_loc;
- BEGIN INITIAL;
- return BRACKETED_ID;
- }
-}
-
-
- /*---------------------------------------------------------------.
- | Scanning a Yacc comment. The initial '/ *' is already eaten. |
- `---------------------------------------------------------------*/
-
-<SC_YACC_COMMENT>
-{
- "*/" BEGIN context_state;
- .|\n continue;
- <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
-}
-
-
- /*------------------------------------------------------------.
- | Scanning a C comment. The initial '/ *' is already eaten. |
- `------------------------------------------------------------*/
-
-<SC_COMMENT>
-{
- "*"{splice}"/" STRING_GROW; BEGIN context_state;
- <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
-}
-
-
- /*--------------------------------------------------------------.
- | Scanning a line comment. The initial '//' is already eaten. |
- `--------------------------------------------------------------*/
-
-<SC_LINE_COMMENT>
-{
- "\n" STRING_GROW; BEGIN context_state;
- {splice} STRING_GROW;
- <<EOF>> BEGIN context_state;
-}
-
-
- /*------------------------------------------------.
- | Scanning a Bison string, including its escapes. |
- | The initial quote is already eaten. |
- `------------------------------------------------*/
-
-<SC_ESCAPED_STRING>
-{
- "\"" {
- STRING_FINISH;
- loc->start = token_start;
- val->code = last_string;
- BEGIN INITIAL;
- return STRING;
- }
- <<EOF>> unexpected_eof (token_start, "\"");
- "\n" unexpected_newline (token_start, "\"");
-}
-
- /*----------------------------------------------------------.
- | Scanning a Bison character literal, decoding its escapes. |
- | The initial quote is already eaten. |
- `----------------------------------------------------------*/
-
-<SC_ESCAPED_CHARACTER>
-{
- "'" {
- STRING_FINISH;
- loc->start = token_start;
- val->character = last_string[0];
-
- /* FIXME: Eventually, make these errors. */
- if (last_string[0] == '\0')
- {
- complain (loc, Wother, _("empty character literal"));
- /* '\0' seems dangerous even if we are about to complain. */
- val->character = '\'';
- }
- else if (last_string[1] != '\0')
- complain (loc, Wother,
- _("extra characters in character literal"));
- STRING_FREE;
- BEGIN INITIAL;
- return CHAR;
- }
- "\n" unexpected_newline (token_start, "'");
- <<EOF>> unexpected_eof (token_start, "'");
-}
-
-
-
- /*--------------------------------------------------------------.
- | Scanning a tag. The initial angle bracket is already eaten. |
- `--------------------------------------------------------------*/
-
-<SC_TAG>
-{
- ">" {
- --nesting;
- if (nesting < 0)
- {
- STRING_FINISH;
- loc->start = token_start;
- val->uniqstr = uniqstr_new (last_string);
- STRING_FREE;
- BEGIN INITIAL;
- return TAG;
- }
- STRING_GROW;
- }
-
- ([^<>]|->)+ STRING_GROW;
- "<"+ STRING_GROW; nesting += yyleng;
-
- <<EOF>> unexpected_eof (token_start, ">");
-}
-
- /*----------------------------.
- | Decode escaped characters. |
- `----------------------------*/
-
-<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
-{
- \\[0-7]{1,3} {
- unsigned long int c = strtoul (yytext + 1, NULL, 8);
- if (!c || UCHAR_MAX < c)
- complain (loc, complaint, _("invalid number after \\-escape: %s"),
- yytext+1);
- else
- obstack_1grow (&obstack_for_string, c);
- }
-
- \\x[0-9abcdefABCDEF]+ {
- verify (UCHAR_MAX < ULONG_MAX);
- unsigned long int c = strtoul (yytext + 2, NULL, 16);
- if (!c || UCHAR_MAX < c)
- complain (loc, complaint, _("invalid number after \\-escape: %s"),
- yytext+1);
- else
- obstack_1grow (&obstack_for_string, c);
- }
-
- \\a obstack_1grow (&obstack_for_string, '\a');
- \\b obstack_1grow (&obstack_for_string, '\b');
- \\f obstack_1grow (&obstack_for_string, '\f');
- \\n obstack_1grow (&obstack_for_string, '\n');
- \\r obstack_1grow (&obstack_for_string, '\r');
- \\t obstack_1grow (&obstack_for_string, '\t');
- \\v obstack_1grow (&obstack_for_string, '\v');
-
- /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
- \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
-
- \\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
- int c = convert_ucn_to_byte (yytext);
- if (c <= 0)
- complain (loc, complaint, _("invalid number after \\-escape: %s"),
- yytext+1);
- else
- obstack_1grow (&obstack_for_string, c);
- }
- \\(.|\n) {
- char const *p = yytext + 1;
- /* Quote only if escaping won't make the character visible. */
- if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
- p = quote (p);
- else
- p = quotearg_style_mem (escape_quoting_style, p, 1);
- complain (loc, complaint, _("invalid character after \\-escape: %s"),
- p);
- }
-}
-
- /*--------------------------------------------.
- | Scanning user-code characters and strings. |
- `--------------------------------------------*/
-
-<SC_CHARACTER,SC_STRING>
-{
- {splice}|\\{splice}[^\n\[\]] STRING_GROW;
-}
-
-<SC_CHARACTER>
-{
- "'" STRING_GROW; BEGIN context_state;
- \n unexpected_newline (token_start, "'");
- <<EOF>> unexpected_eof (token_start, "'");
-}
-
-<SC_STRING>
-{
- "\"" STRING_GROW; BEGIN context_state;
- \n unexpected_newline (token_start, "\"");
- <<EOF>> unexpected_eof (token_start, "\"");
-}
-
-
- /*---------------------------------------------------.
- | Strings, comments etc. can be found in user code. |
- `---------------------------------------------------*/
-
-<SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_PREDICATE>
-{
- "'" {
- STRING_GROW;
- context_state = YY_START;
- token_start = loc->start;
- BEGIN SC_CHARACTER;
- }
- "\"" {
- STRING_GROW;
- context_state = YY_START;
- token_start = loc->start;
- BEGIN SC_STRING;
- }
- "/"{splice}"*" {
- STRING_GROW;
- context_state = YY_START;
- token_start = loc->start;
- BEGIN SC_COMMENT;
- }
- "/"{splice}"/" {
- STRING_GROW;
- context_state = YY_START;
- BEGIN SC_LINE_COMMENT;
- }
-}
-
-
-
- /*-----------------------------------------------------------.
- | Scanning some code in braces (actions, predicates). The |
- | initial "{" is already eaten. |
- `-----------------------------------------------------------*/
-
-<SC_BRACED_CODE,SC_PREDICATE>
-{
- "{"|"<"{splice}"%" STRING_GROW; nesting++;
- "%"{splice}">" STRING_GROW; nesting--;
-
- /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
- (as '<' '<%'). */
- "<"{splice}"<" STRING_GROW;
-
- <<EOF>> unexpected_eof (code_start, "}");
-}
-
-<SC_BRACED_CODE>
-{
- "}" {
- obstack_1grow (&obstack_for_string, '}');
-
- --nesting;
- if (nesting < 0)
- {
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return BRACED_CODE;
- }
- }
-}
-
-<SC_PREDICATE>
-{
- "}" {
- --nesting;
- if (nesting < 0)
- {
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return BRACED_PREDICATE;
- }
- else
- obstack_1grow (&obstack_for_string, '}');
- }
-}
-
- /*--------------------------------------------------------------.
- | Scanning some prologue: from "%{" (already scanned) to "%}". |
- `--------------------------------------------------------------*/
-
-<SC_PROLOGUE>
-{
- "%}" {
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return PROLOGUE;
- }
-
- <<EOF>> unexpected_eof (code_start, "%}");
-}
-
-
- /*---------------------------------------------------------------.
- | Scanning the epilogue (everything after the second "%%", which |
- | has already been eaten). |
- `---------------------------------------------------------------*/
-
-<SC_EPILOGUE>
-{
- <<EOF>> {
- STRING_FINISH;
- loc->start = code_start;
- val->code = last_string;
- BEGIN INITIAL;
- return EPILOGUE;
- }
-}
-
-
- /*-----------------------------------------------------.
- | By default, grow the string obstack with the input. |
- `-----------------------------------------------------*/
-
-<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>. |
- <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE>\n STRING_GROW;
-
-%%
-
-/* Read bytes from FP into buffer BUF of size SIZE. Return the
- number of bytes read. Remove '\r' from input, treating \r\n
- and isolated \r as \n. */
-
-static size_t
-no_cr_read (FILE *fp, char *buf, size_t size)
-{
- size_t bytes_read = fread (buf, 1, size, fp);
- if (bytes_read)
- {
- char *w = memchr (buf, '\r', bytes_read);
- if (w)
- {
- char const *r = ++w;
- char const *lim = buf + bytes_read;
-
- for (;;)
- {
- /* Found an '\r'. Treat it like '\n', but ignore any
- '\n' that immediately follows. */
- w[-1] = '\n';
- if (r == lim)
- {
- int ch = getc (fp);
- if (ch != '\n' && ungetc (ch, fp) != ch)
- break;
- }
- else if (*r == '\n')
- r++;
-
- /* Copy until the next '\r'. */
- do
- {
- if (r == lim)
- return w - buf;
- }
- while ((*w++ = *r++) != '\r');
- }
-
- return w - buf;
- }
- }
-
- return bytes_read;
-}
-
-
-
-/*------------------------------------------------------.
-| Scan NUMBER for a base-BASE integer at location LOC. |
-`------------------------------------------------------*/
-
-static unsigned long int
-scan_integer (char const *number, int base, location loc)
-{
- verify (INT_MAX < ULONG_MAX);
- unsigned long int num = strtoul (number, NULL, base);
-
- if (INT_MAX < num)
- {
- complain (&loc, complaint, _("integer out of range: %s"),
- quote (number));
- num = INT_MAX;
- }
-
- return num;
-}
-
-
-/*------------------------------------------------------------------.
-| Convert universal character name UCN to a single-byte character, |
-| and return that character. Return -1 if UCN does not correspond |
-| to a single-byte character. |
-`------------------------------------------------------------------*/
-
-static int
-convert_ucn_to_byte (char const *ucn)
-{
- verify (UCHAR_MAX <= INT_MAX);
- unsigned long int code = strtoul (ucn + 2, NULL, 16);
-
- /* FIXME: Currently we assume Unicode-compatible unibyte characters
- on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
- non-ASCII hosts we support only the portable C character set.
- These limitations should be removed once we add support for
- multibyte characters. */
-
- if (UCHAR_MAX < code)
- return -1;
-
-#if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
- {
- /* A non-ASCII host. Use CODE to index into a table of the C
- basic execution character set, which is guaranteed to exist on
- all Standard C platforms. This table also includes '$', '@',
- and '`', which are not in the basic execution character set but
- which are unibyte characters on all the platforms that we know
- about. */
- static signed char const table[] =
- {
- '\0', -1, -1, -1, -1, -1, -1, '\a',
- '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1,
- ' ', '!', '"', '#', '$', '%', '&', '\'',
- '(', ')', '*', '+', ',', '-', '.', '/',
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', ':', ';', '<', '=', '>', '?',
- '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
- 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
- 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
- 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
- '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', '{', '|', '}', '~'
- };
-
- code = code < sizeof table ? table[code] : -1;
- }
-#endif
-
- return code;
-}
-
-
-/*---------------------------------------------------------------------.
-| Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
-`---------------------------------------------------------------------*/
-
-static void
-handle_syncline (char *args, location loc)
-{
- char *file;
- unsigned long int lineno = strtoul (args, &file, 10);
- if (INT_MAX <= lineno)
- {
- complain (&loc, Wother, _("line number overflow"));
- lineno = INT_MAX;
- }
-
- file = strchr (file, '"');
- if (file)
- {
- *strchr (file + 1, '"') = '\0';
- current_file = uniqstr_new (file + 1);
- }
- boundary_set (&scanner_cursor, current_file, lineno, 1);
-}
-
-
-/*----------------------------------------------------------------.
-| For a token or comment starting at START, report message MSGID, |
-| which should say that an end marker was found before the |
-| expected TOKEN_END. Then, pretend that TOKEN_END was found. |
-`----------------------------------------------------------------*/
-
-static void
-unexpected_end (boundary start, char const *msgid, char const *token_end)
-{
- location loc;
- loc.start = start;
- loc.end = scanner_cursor;
- size_t i = strlen (token_end);
-
-/* Adjust scanner cursor so that any later message does not count
- the characters about to be inserted. */
- scanner_cursor.column -= i;
-
- while (i != 0)
- unput (token_end[--i]);
-
- token_end = quote (token_end);
- /* Instead of '\'', display "'". */
- if (STREQ (token_end, "'\\''"))
- token_end = "\"'\"";
- complain (&loc, complaint, _(msgid), token_end);
-}
-
-
-/*------------------------------------------------------------------------.
-| Report an unexpected EOF in a token or comment starting at START. |
-| An end of file was encountered and the expected TOKEN_END was missing. |
-| After reporting the problem, pretend that TOKEN_END was found. |
-`------------------------------------------------------------------------*/
-
-static void
-unexpected_eof (boundary start, char const *token_end)
-{
- unexpected_end (start, N_("missing %s at end of file"), token_end);
-}
-
-
-/*----------------------------------------.
-| Likewise, but for unexpected newlines. |
-`----------------------------------------*/
-
-static void
-unexpected_newline (boundary start, char const *token_end)
-{
- unexpected_end (start, N_("missing %s at end of line"), token_end);
-}
-
-
-/*-------------------------.
-| Initialize the scanner. |
-`-------------------------*/
-
-void
-gram_scanner_initialize (void)
-{
- obstack_init (&obstack_for_string);
-}
-
-
-/*-----------------------------------------------.
-| Free all the memory allocated to the scanner. |
-`-----------------------------------------------*/
-
-void
-gram_scanner_free (void)
-{
- obstack_free (&obstack_for_string, 0);
- /* Reclaim Flex's buffers. */
- yylex_destroy ();
-}
+/* Bison Grammar Scanner -*- C -*-
+
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+%option debug nodefault noinput noyywrap never-interactive
+%option prefix="gram_" outfile="lex.yy.c"
+
+%{
+/* Work around a bug in flex 2.5.31. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+#undef gram_wrap
+#define gram_wrap() 1
+
+#define FLEX_PREFIX(Id) gram_ ## Id
+#include <src/flex-scanner.h>
+
+#include <src/complain.h>
+#include <src/files.h>
+#include <src/getargs.h>
+#include <src/gram.h>
+#include <quotearg.h>
+#include <src/reader.h>
+#include <src/uniqstr.h>
+
+#include <c-ctype.h>
+#include <mbswidth.h>
+#include <quote.h>
+
+#include <src/scan-gram.h>
+
+#define YY_DECL GRAM_LEX_DECL
+
+#define YY_USER_INIT \
+ code_start = scanner_cursor = loc->start; \
+
+/* Location of scanner cursor. */
+static boundary scanner_cursor;
+
+#define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng);
+
+static size_t no_cr_read (FILE *, char *, size_t);
+#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
+
+#define RETURN_PERCENT_PARAM(Value) \
+ RETURN_VALUE(PERCENT_PARAM, param, param_ ## Value)
+
+#define RETURN_PERCENT_FLAG(Value) \
+ RETURN_VALUE(PERCENT_FLAG, uniqstr, uniqstr_new (Value))
+
+#define RETURN_VALUE(Token, Field, Value) \
+ do { \
+ val->Field = Value; \
+ return Token; \
+ } while (0)
+
+#define ROLLBACK_CURRENT_TOKEN \
+ do { \
+ scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0); \
+ yyless (0); \
+ } while (0)
+
+#define DEPRECATED(Msg) \
+ do { \
+ size_t i; \
+ deprecated_directive (loc, yytext, Msg); \
+ scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \
+ for (i = strlen (Msg); i != 0; --i) \
+ unput (Msg[i - 1]); \
+ } while (0)
+
+/* A string representing the most recently saved token. */
+static char *last_string;
+
+/* Bracketed identifier. */
+static uniqstr bracketed_id_str = 0;
+static location bracketed_id_loc;
+static boundary bracketed_id_start;
+static int bracketed_id_context_state = 0;
+
+void
+gram_scanner_last_string_free (void)
+{
+ STRING_FREE;
+}
+
+static void handle_syncline (char *, location);
+static unsigned long int scan_integer (char const *p, int base, location loc);
+static int convert_ucn_to_byte (char const *hex_text);
+static void unexpected_eof (boundary, char const *);
+static void unexpected_newline (boundary, char const *);
+
+%}
+ /* A C-like comment in directives/rules. */
+%x SC_YACC_COMMENT
+ /* Strings and characters in directives/rules. */
+%x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
+ /* A identifier was just read in directives/rules. Special state
+ to capture the sequence 'identifier :'. */
+%x SC_AFTER_IDENTIFIER
+
+ /* POSIX says that a tag must be both an id and a C union member, but
+ historically almost any character is allowed in a tag. We
+ disallow NUL, as this simplifies our implementation. We match
+ angle brackets in nested pairs: several languages use them for
+ generics/template types. */
+%x SC_TAG
+
+ /* Four types of user code:
+ - prologue (code between '%{' '%}' in the first section, before %%);
+ - actions, printers, union, etc, (between braced in the middle section);
+ - epilogue (everything after the second %%).
+ - predicate (code between '%?{' and '{' in middle section); */
+%x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE SC_PREDICATE
+ /* C and C++ comments in code. */
+%x SC_COMMENT SC_LINE_COMMENT
+ /* Strings and characters in code. */
+%x SC_STRING SC_CHARACTER
+ /* Bracketed identifiers support. */
+%x SC_BRACKETED_ID SC_RETURN_BRACKETED_ID
+
+letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
+notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]
+id {letter}({letter}|[-0-9])*
+int [0-9]+
+
+/* Zero or more instances of backslash-newline. Following GCC, allow
+ white space between the backslash and the newline. */
+splice (\\[ \f\t\v]*\n)*
+
+/* An equal sign, with optional leading whitespaces. This is used in some
+ deprecated constructs. */
+eqopt ([[:space:]]*=)?
+
+%%
+%{
+ /* Nesting level. Either for nested braces, or nested angle brackets
+ (but not mixed). */
+ int nesting PACIFY_CC (= 0);
+
+ /* Parent context state, when applicable. */
+ int context_state PACIFY_CC (= 0);
+
+ /* Location of most recent identifier, when applicable. */
+ location id_loc PACIFY_CC (= empty_location);
+
+ /* Where containing code started, when applicable. Its initial
+ value is relevant only when yylex is invoked in the SC_EPILOGUE
+ start condition. */
+ boundary code_start = scanner_cursor;
+
+ /* Where containing comment or string or character literal started,
+ when applicable. */
+ boundary token_start PACIFY_CC (= scanner_cursor);
+%}
+
+
+ /*-----------------------.
+ | Scanning white space. |
+ `-----------------------*/
+
+<INITIAL,SC_AFTER_IDENTIFIER,SC_BRACKETED_ID,SC_RETURN_BRACKETED_ID>
+{
+ /* Comments and white space. */
+ "," {
+ complain (loc, Wother, _("stray ',' treated as white space"));
+ }
+ [ \f\n\t\v] |
+ "//".* continue;
+ "/*" {
+ token_start = loc->start;
+ context_state = YY_START;
+ BEGIN SC_YACC_COMMENT;
+ }
+
+ /* #line directives are not documented, and may be withdrawn or
+ modified in future versions of Bison. */
+ ^"#line "{int}(" \"".*"\"")?"\n" {
+ handle_syncline (yytext + sizeof "#line " - 1, *loc);
+ }
+}
+
+
+ /*----------------------------.
+ | Scanning Bison directives. |
+ `----------------------------*/
+
+ /* For directives that are also command line options, the regex must be
+ "%..."
+ after "[-_]"s are removed, and the directive must match the --long
+ option name, with a single string argument. Otherwise, add exceptions
+ to ../build-aux/cross-options.pl. */
+
+<INITIAL>
+{
+ "%binary" return PERCENT_NONASSOC;
+ "%code" return PERCENT_CODE;
+ "%debug" RETURN_PERCENT_FLAG("parse.trace");
+ "%default-prec" return PERCENT_DEFAULT_PREC;
+ "%define" return PERCENT_DEFINE;
+ "%defines" return PERCENT_DEFINES;
+ "%destructor" return PERCENT_DESTRUCTOR;
+ "%dprec" return PERCENT_DPREC;
+ "%empty" return PERCENT_EMPTY;
+ "%error-verbose" return PERCENT_ERROR_VERBOSE;
+ "%expect" return PERCENT_EXPECT;
+ "%expect-rr" return PERCENT_EXPECT_RR;
+ "%file-prefix" return PERCENT_FILE_PREFIX;
+ "%fixed-output-files" return PERCENT_YACC;
+ "%initial-action" return PERCENT_INITIAL_ACTION;
+ "%glr-parser" return PERCENT_GLR_PARSER;
+ "%language" return PERCENT_LANGUAGE;
+ "%left" return PERCENT_LEFT;
+ "%lex-param" RETURN_PERCENT_PARAM(lex);
+ "%locations" RETURN_PERCENT_FLAG("locations");
+ "%merge" return PERCENT_MERGE;
+ "%name-prefix" return PERCENT_NAME_PREFIX;
+ "%no-default-prec" return PERCENT_NO_DEFAULT_PREC;
+ "%no-lines" return PERCENT_NO_LINES;
+ "%nonassoc" return PERCENT_NONASSOC;
+ "%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
+ "%nterm" return PERCENT_NTERM;
+ "%output" return PERCENT_OUTPUT;
+ "%param" RETURN_PERCENT_PARAM(both);
+ "%parse-param" RETURN_PERCENT_PARAM(parse);
+ "%prec" return PERCENT_PREC;
+ "%precedence" return PERCENT_PRECEDENCE;
+ "%printer" return PERCENT_PRINTER;
+ "%pure-parser" RETURN_PERCENT_FLAG("api.pure");
+ "%require" return PERCENT_REQUIRE;
+ "%right" return PERCENT_RIGHT;
+ "%skeleton" return PERCENT_SKELETON;
+ "%start" return PERCENT_START;
+ "%term" return PERCENT_TOKEN;
+ "%token" return PERCENT_TOKEN;
+ "%token-table" return PERCENT_TOKEN_TABLE;
+ "%type" return PERCENT_TYPE;
+ "%union" return PERCENT_UNION;
+ "%verbose" return PERCENT_VERBOSE;
+ "%yacc" return PERCENT_YACC;
+
+ /* deprecated */
+ "%default"[-_]"prec" DEPRECATED("%default-prec");
+ "%error"[-_]"verbose" DEPRECATED("%define parse.error verbose");
+ "%expect"[-_]"rr" DEPRECATED("%expect-rr");
+ "%file-prefix"{eqopt} DEPRECATED("%file-prefix");
+ "%fixed"[-_]"output"[-_]"files" DEPRECATED("%fixed-output-files");
+ "%name"[-_]"prefix"{eqopt} DEPRECATED("%name-prefix");
+ "%no"[-_]"default"[-_]"prec" DEPRECATED("%no-default-prec");
+ "%no"[-_]"lines" DEPRECATED("%no-lines");
+ "%output"{eqopt} DEPRECATED("%output");
+ "%pure"[-_]"parser" DEPRECATED("%pure-parser");
+ "%token"[-_]"table" DEPRECATED("%token-table");
+
+ "%"{id}|"%"{notletter}([[:graph:]])+ {
+ complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
+ }
+
+ "=" return EQUAL;
+ "|" return PIPE;
+ ";" return SEMICOLON;
+
+ {id} {
+ val->uniqstr = uniqstr_new (yytext);
+ id_loc = *loc;
+ bracketed_id_str = NULL;
+ BEGIN SC_AFTER_IDENTIFIER;
+ }
+
+ {int} {
+ val->integer = scan_integer (yytext, 10, *loc);
+ return INT;
+ }
+ 0[xX][0-9abcdefABCDEF]+ {
+ val->integer = scan_integer (yytext, 16, *loc);
+ return INT;
+ }
+
+ /* Identifiers may not start with a digit. Yet, don't silently
+ accept "1FOO" as "1 FOO". */
+ {int}{id} {
+ complain (loc, complaint, _("invalid identifier: %s"), quote (yytext));
+ }
+
+ /* Characters. */
+ "'" token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER;
+
+ /* Strings. */
+ "\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
+
+ /* Prologue. */
+ "%{" code_start = loc->start; BEGIN SC_PROLOGUE;
+
+ /* Code in between braces. */
+ "{" {
+ STRING_GROW;
+ nesting = 0;
+ code_start = loc->start;
+ BEGIN SC_BRACED_CODE;
+ }
+
+ /* Semantic predicate. */
+ "%?"[ \f\n\t\v]*"{" {
+ nesting = 0;
+ code_start = loc->start;
+ BEGIN SC_PREDICATE;
+ }
+
+ /* A type. */
+ "<*>" return TAG_ANY;
+ "<>" return TAG_NONE;
+ "<" {
+ nesting = 0;
+ token_start = loc->start;
+ BEGIN SC_TAG;
+ }
+
+ "%%" {
+ static int percent_percent_count;
+ if (++percent_percent_count == 2)
+ BEGIN SC_EPILOGUE;
+ return PERCENT_PERCENT;
+ }
+
+ "[" {
+ bracketed_id_str = NULL;
+ bracketed_id_start = loc->start;
+ bracketed_id_context_state = YY_START;
+ BEGIN SC_BRACKETED_ID;
+ }
+
+ [^\[%A-Za-z0-9_<>{}\"\'*;|=/, \f\n\t\v]+|. {
+ complain (loc, complaint, "%s: %s",
+ ngettext ("invalid character", "invalid characters", yyleng),
+ quote_mem (yytext, yyleng));
+ }
+
+ <<EOF>> {
+ loc->start = loc->end = scanner_cursor;
+ yyterminate ();
+ }
+}
+
+
+ /*--------------------------------------------------------------.
+ | Supporting \0 complexifies our implementation for no expected |
+ | added value. |
+ `--------------------------------------------------------------*/
+
+<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
+{
+ \0 complain (loc, complaint, _("invalid null character"));
+}
+
+
+ /*-----------------------------------------------------------------.
+ | Scanning after an identifier, checking whether a colon is next. |
+ `-----------------------------------------------------------------*/
+
+<SC_AFTER_IDENTIFIER>
+{
+ "[" {
+ if (bracketed_id_str)
+ {
+ ROLLBACK_CURRENT_TOKEN;
+ BEGIN SC_RETURN_BRACKETED_ID;
+ *loc = id_loc;
+ return ID;
+ }
+ else
+ {
+ bracketed_id_start = loc->start;
+ bracketed_id_context_state = YY_START;
+ BEGIN SC_BRACKETED_ID;
+ }
+ }
+ ":" {
+ BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
+ *loc = id_loc;
+ return ID_COLON;
+ }
+ . {
+ ROLLBACK_CURRENT_TOKEN;
+ BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
+ *loc = id_loc;
+ return ID;
+ }
+ <<EOF>> {
+ BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL);
+ *loc = id_loc;
+ return ID;
+ }
+}
+
+ /*--------------------------------.
+ | Scanning bracketed identifiers. |
+ `--------------------------------*/
+
+<SC_BRACKETED_ID>
+{
+ {id} {
+ if (bracketed_id_str)
+ {
+ complain (loc, complaint,
+ _("unexpected identifier in bracketed name: %s"),
+ quote (yytext));
+ }
+ else
+ {
+ bracketed_id_str = uniqstr_new (yytext);
+ bracketed_id_loc = *loc;
+ }
+ }
+ "]" {
+ BEGIN bracketed_id_context_state;
+ if (bracketed_id_str)
+ {
+ if (INITIAL == bracketed_id_context_state)
+ {
+ val->uniqstr = bracketed_id_str;
+ bracketed_id_str = 0;
+ *loc = bracketed_id_loc;
+ return BRACKETED_ID;
+ }
+ }
+ else
+ complain (loc, complaint, _("an identifier expected"));
+ }
+
+ [^\].A-Za-z0-9_/ \f\n\t\v]+|. {
+ complain (loc, complaint, "%s: %s",
+ ngettext ("invalid character in bracketed name",
+ "invalid characters in bracketed name", yyleng),
+ quote_mem (yytext, yyleng));
+ }
+
+ <<EOF>> {
+ BEGIN bracketed_id_context_state;
+ unexpected_eof (bracketed_id_start, "]");
+ }
+}
+
+<SC_RETURN_BRACKETED_ID>
+{
+ . {
+ ROLLBACK_CURRENT_TOKEN;
+ val->uniqstr = bracketed_id_str;
+ bracketed_id_str = 0;
+ *loc = bracketed_id_loc;
+ BEGIN INITIAL;
+ return BRACKETED_ID;
+ }
+}
+
+
+ /*---------------------------------------------------------------.
+ | Scanning a Yacc comment. The initial '/ *' is already eaten. |
+ `---------------------------------------------------------------*/
+
+<SC_YACC_COMMENT>
+{
+ "*/" BEGIN context_state;
+ .|\n continue;
+ <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
+}
+
+
+ /*------------------------------------------------------------.
+ | Scanning a C comment. The initial '/ *' is already eaten. |
+ `------------------------------------------------------------*/
+
+<SC_COMMENT>
+{
+ "*"{splice}"/" STRING_GROW; BEGIN context_state;
+ <<EOF>> unexpected_eof (token_start, "*/"); BEGIN context_state;
+}
+
+
+ /*--------------------------------------------------------------.
+ | Scanning a line comment. The initial '//' is already eaten. |
+ `--------------------------------------------------------------*/
+
+<SC_LINE_COMMENT>
+{
+ "\n" STRING_GROW; BEGIN context_state;
+ {splice} STRING_GROW;
+ <<EOF>> BEGIN context_state;
+}
+
+
+ /*------------------------------------------------.
+ | Scanning a Bison string, including its escapes. |
+ | The initial quote is already eaten. |
+ `------------------------------------------------*/
+
+<SC_ESCAPED_STRING>
+{
+ "\"" {
+ STRING_FINISH;
+ loc->start = token_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return STRING;
+ }
+ <<EOF>> unexpected_eof (token_start, "\"");
+ "\n" unexpected_newline (token_start, "\"");
+}
+
+ /*----------------------------------------------------------.
+ | Scanning a Bison character literal, decoding its escapes. |
+ | The initial quote is already eaten. |
+ `----------------------------------------------------------*/
+
+<SC_ESCAPED_CHARACTER>
+{
+ "'" {
+ STRING_FINISH;
+ loc->start = token_start;
+ val->character = last_string[0];
+
+ /* FIXME: Eventually, make these errors. */
+ if (last_string[0] == '\0')
+ {
+ complain (loc, Wother, _("empty character literal"));
+ /* '\0' seems dangerous even if we are about to complain. */
+ val->character = '\'';
+ }
+ else if (last_string[1] != '\0')
+ complain (loc, Wother,
+ _("extra characters in character literal"));
+ STRING_FREE;
+ BEGIN INITIAL;
+ return CHAR;
+ }
+ "\n" unexpected_newline (token_start, "'");
+ <<EOF>> unexpected_eof (token_start, "'");
+}
+
+
+
+ /*--------------------------------------------------------------.
+ | Scanning a tag. The initial angle bracket is already eaten. |
+ `--------------------------------------------------------------*/
+
+<SC_TAG>
+{
+ ">" {
+ --nesting;
+ if (nesting < 0)
+ {
+ STRING_FINISH;
+ loc->start = token_start;
+ val->uniqstr = uniqstr_new (last_string);
+ STRING_FREE;
+ BEGIN INITIAL;
+ return TAG;
+ }
+ STRING_GROW;
+ }
+
+ ([^<>]|->)+ STRING_GROW;
+ "<"+ STRING_GROW; nesting += yyleng;
+
+ <<EOF>> unexpected_eof (token_start, ">");
+}
+
+ /*----------------------------.
+ | Decode escaped characters. |
+ `----------------------------*/
+
+<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
+{
+ \\[0-7]{1,3} {
+ unsigned long int c = strtoul (yytext + 1, NULL, 8);
+ if (!c || UCHAR_MAX < c)
+ complain (loc, complaint, _("invalid number after \\-escape: %s"),
+ yytext+1);
+ else
+ obstack_1grow (&obstack_for_string, c);
+ }
+
+ \\x[0-9abcdefABCDEF]+ {
+ verify (UCHAR_MAX < ULONG_MAX);
+ unsigned long int c = strtoul (yytext + 2, NULL, 16);
+ if (!c || UCHAR_MAX < c)
+ complain (loc, complaint, _("invalid number after \\-escape: %s"),
+ yytext+1);
+ else
+ obstack_1grow (&obstack_for_string, c);
+ }
+
+ \\a obstack_1grow (&obstack_for_string, '\a');
+ \\b obstack_1grow (&obstack_for_string, '\b');
+ \\f obstack_1grow (&obstack_for_string, '\f');
+ \\n obstack_1grow (&obstack_for_string, '\n');
+ \\r obstack_1grow (&obstack_for_string, '\r');
+ \\t obstack_1grow (&obstack_for_string, '\t');
+ \\v obstack_1grow (&obstack_for_string, '\v');
+
+ /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
+ \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
+
+ \\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
+ int c = convert_ucn_to_byte (yytext);
+ if (c <= 0)
+ complain (loc, complaint, _("invalid number after \\-escape: %s"),
+ yytext+1);
+ else
+ obstack_1grow (&obstack_for_string, c);
+ }
+ \\(.|\n) {
+ char const *p = yytext + 1;
+ /* Quote only if escaping won't make the character visible. */
+ if (c_isspace ((unsigned char) *p) && c_isprint ((unsigned char) *p))
+ p = quote (p);
+ else
+ p = quotearg_style_mem (escape_quoting_style, p, 1);
+ complain (loc, complaint, _("invalid character after \\-escape: %s"),
+ p);
+ }
+}
+
+ /*--------------------------------------------.
+ | Scanning user-code characters and strings. |
+ `--------------------------------------------*/
+
+<SC_CHARACTER,SC_STRING>
+{
+ {splice}|\\{splice}[^\n\[\]] STRING_GROW;
+}
+
+<SC_CHARACTER>
+{
+ "'" STRING_GROW; BEGIN context_state;
+ \n unexpected_newline (token_start, "'");
+ <<EOF>> unexpected_eof (token_start, "'");
+}
+
+<SC_STRING>
+{
+ "\"" STRING_GROW; BEGIN context_state;
+ \n unexpected_newline (token_start, "\"");
+ <<EOF>> unexpected_eof (token_start, "\"");
+}
+
+
+ /*---------------------------------------------------.
+ | Strings, comments etc. can be found in user code. |
+ `---------------------------------------------------*/
+
+<SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_PREDICATE>
+{
+ "'" {
+ STRING_GROW;
+ context_state = YY_START;
+ token_start = loc->start;
+ BEGIN SC_CHARACTER;
+ }
+ "\"" {
+ STRING_GROW;
+ context_state = YY_START;
+ token_start = loc->start;
+ BEGIN SC_STRING;
+ }
+ "/"{splice}"*" {
+ STRING_GROW;
+ context_state = YY_START;
+ token_start = loc->start;
+ BEGIN SC_COMMENT;
+ }
+ "/"{splice}"/" {
+ STRING_GROW;
+ context_state = YY_START;
+ BEGIN SC_LINE_COMMENT;
+ }
+}
+
+
+
+ /*-----------------------------------------------------------.
+ | Scanning some code in braces (actions, predicates). The |
+ | initial "{" is already eaten. |
+ `-----------------------------------------------------------*/
+
+<SC_BRACED_CODE,SC_PREDICATE>
+{
+ "{"|"<"{splice}"%" STRING_GROW; nesting++;
+ "%"{splice}">" STRING_GROW; nesting--;
+
+ /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly
+ (as '<' '<%'). */
+ "<"{splice}"<" STRING_GROW;
+
+ <<EOF>> unexpected_eof (code_start, "}");
+}
+
+<SC_BRACED_CODE>
+{
+ "}" {
+ obstack_1grow (&obstack_for_string, '}');
+
+ --nesting;
+ if (nesting < 0)
+ {
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return BRACED_CODE;
+ }
+ }
+}
+
+<SC_PREDICATE>
+{
+ "}" {
+ --nesting;
+ if (nesting < 0)
+ {
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return BRACED_PREDICATE;
+ }
+ else
+ obstack_1grow (&obstack_for_string, '}');
+ }
+}
+
+ /*--------------------------------------------------------------.
+ | Scanning some prologue: from "%{" (already scanned) to "%}". |
+ `--------------------------------------------------------------*/
+
+<SC_PROLOGUE>
+{
+ "%}" {
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return PROLOGUE;
+ }
+
+ <<EOF>> unexpected_eof (code_start, "%}");
+}
+
+
+ /*---------------------------------------------------------------.
+ | Scanning the epilogue (everything after the second "%%", which |
+ | has already been eaten). |
+ `---------------------------------------------------------------*/
+
+<SC_EPILOGUE>
+{
+ <<EOF>> {
+ STRING_FINISH;
+ loc->start = code_start;
+ val->code = last_string;
+ BEGIN INITIAL;
+ return EPILOGUE;
+ }
+}
+
+
+ /*-----------------------------------------------------.
+ | By default, grow the string obstack with the input. |
+ `-----------------------------------------------------*/
+
+<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>. |
+ <SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE>\n STRING_GROW;
+
+%%
+
+/* Read bytes from FP into buffer BUF of size SIZE. Return the
+ number of bytes read. Remove '\r' from input, treating \r\n
+ and isolated \r as \n. */
+
+static size_t
+no_cr_read (FILE *fp, char *buf, size_t size)
+{
+ size_t bytes_read = fread (buf, 1, size, fp);
+ if (bytes_read)
+ {
+ char *w = memchr (buf, '\r', bytes_read);
+ if (w)
+ {
+ char const *r = ++w;
+ char const *lim = buf + bytes_read;
+
+ for (;;)
+ {
+ /* Found an '\r'. Treat it like '\n', but ignore any
+ '\n' that immediately follows. */
+ w[-1] = '\n';
+ if (r == lim)
+ {
+ int ch = getc (fp);
+ if (ch != '\n' && ungetc (ch, fp) != ch)
+ break;
+ }
+ else if (*r == '\n')
+ r++;
+
+ /* Copy until the next '\r'. */
+ do
+ {
+ if (r == lim)
+ return w - buf;
+ }
+ while ((*w++ = *r++) != '\r');
+ }
+
+ return w - buf;
+ }
+ }
+
+ return bytes_read;
+}
+
+
+
+/*------------------------------------------------------.
+| Scan NUMBER for a base-BASE integer at location LOC. |
+`------------------------------------------------------*/
+
+static unsigned long int
+scan_integer (char const *number, int base, location loc)
+{
+ verify (INT_MAX < ULONG_MAX);
+ unsigned long int num = strtoul (number, NULL, base);
+
+ if (INT_MAX < num)
+ {
+ complain (&loc, complaint, _("integer out of range: %s"),
+ quote (number));
+ num = INT_MAX;
+ }
+
+ return num;
+}
+
+
+/*------------------------------------------------------------------.
+| Convert universal character name UCN to a single-byte character, |
+| and return that character. Return -1 if UCN does not correspond |
+| to a single-byte character. |
+`------------------------------------------------------------------*/
+
+static int
+convert_ucn_to_byte (char const *ucn)
+{
+ verify (UCHAR_MAX <= INT_MAX);
+ unsigned long int code = strtoul (ucn + 2, NULL, 16);
+
+ /* FIXME: Currently we assume Unicode-compatible unibyte characters
+ on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
+ non-ASCII hosts we support only the portable C character set.
+ These limitations should be removed once we add support for
+ multibyte characters. */
+
+ if (UCHAR_MAX < code)
+ return -1;
+
+#if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
+ {
+ /* A non-ASCII host. Use CODE to index into a table of the C
+ basic execution character set, which is guaranteed to exist on
+ all Standard C platforms. This table also includes '$', '@',
+ and '`', which are not in the basic execution character set but
+ which are unibyte characters on all the platforms that we know
+ about. */
+ static signed char const table[] =
+ {
+ '\0', -1, -1, -1, -1, -1, -1, '\a',
+ '\b', '\t', '\n', '\v', '\f', '\r', -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ ' ', '!', '"', '#', '$', '%', '&', '\'',
+ '(', ')', '*', '+', ',', '-', '.', '/',
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', ':', ';', '<', '=', '>', '?',
+ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
+ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+ 'x', 'y', 'z', '{', '|', '}', '~'
+ };
+
+ code = code < sizeof table ? table[code] : -1;
+ }
+#endif
+
+ return code;
+}
+
+
+/*---------------------------------------------------------------------.
+| Handle '#line INT( "FILE")?\n'. ARGS has already skipped '#line '. |
+`---------------------------------------------------------------------*/
+
+static void
+handle_syncline (char *args, location loc)
+{
+ char *file;
+ unsigned long int lineno = strtoul (args, &file, 10);
+ if (INT_MAX <= lineno)
+ {
+ complain (&loc, Wother, _("line number overflow"));
+ lineno = INT_MAX;
+ }
+
+ file = strchr (file, '"');
+ if (file)
+ {
+ *strchr (file + 1, '"') = '\0';
+ current_file = uniqstr_new (file + 1);
+ }
+ boundary_set (&scanner_cursor, current_file, lineno, 1);
+}
+
+
+/*----------------------------------------------------------------.
+| For a token or comment starting at START, report message MSGID, |
+| which should say that an end marker was found before the |
+| expected TOKEN_END. Then, pretend that TOKEN_END was found. |
+`----------------------------------------------------------------*/
+
+static void
+unexpected_end (boundary start, char const *msgid, char const *token_end)
+{
+ location loc;
+ loc.start = start;
+ loc.end = scanner_cursor;
+ size_t i = strlen (token_end);
+
+/* Adjust scanner cursor so that any later message does not count
+ the characters about to be inserted. */
+ scanner_cursor.column -= i;
+
+ while (i != 0)
+ unput (token_end[--i]);
+
+ token_end = quote (token_end);
+ /* Instead of '\'', display "'". */
+ if (STREQ (token_end, "'\\''"))
+ token_end = "\"'\"";
+ complain (&loc, complaint, _(msgid), token_end);
+}
+
+
+/*------------------------------------------------------------------------.
+| Report an unexpected EOF in a token or comment starting at START. |
+| An end of file was encountered and the expected TOKEN_END was missing. |
+| After reporting the problem, pretend that TOKEN_END was found. |
+`------------------------------------------------------------------------*/
+
+static void
+unexpected_eof (boundary start, char const *token_end)
+{
+ unexpected_end (start, N_("missing %s at end of file"), token_end);
+}
+
+
+/*----------------------------------------.
+| Likewise, but for unexpected newlines. |
+`----------------------------------------*/
+
+static void
+unexpected_newline (boundary start, char const *token_end)
+{
+ unexpected_end (start, N_("missing %s at end of line"), token_end);
+}
+
+
+/*-------------------------.
+| Initialize the scanner. |
+`-------------------------*/
+
+void
+gram_scanner_initialize (void)
+{
+ obstack_init (&obstack_for_string);
+}
+
+
+/*-----------------------------------------------.
+| Free all the memory allocated to the scanner. |
+`-----------------------------------------------*/
+
+void
+gram_scanner_free (void)
+{
+ obstack_free (&obstack_for_string, 0);
+ /* Reclaim Flex's buffers. */
+ yylex_destroy ();
+}
diff --git a/contrib/tools/bison/bison/src/scan-skel-c.c b/contrib/tools/bison/bison/src/scan-skel-c.c
index 3e1e73deb0..cc6de06c19 100644
--- a/contrib/tools/bison/bison/src/scan-skel-c.c
+++ b/contrib/tools/bison/bison/src/scan-skel-c.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#include "system.h"
-#include "src/scan-skel.c"
+#include <config.h>
+#include "system.h"
+#include "src/scan-skel.c"
diff --git a/contrib/tools/bison/bison/src/scan-skel.c b/contrib/tools/bison/bison/src/scan-skel.c
index 1e116da14d..06fc7825c6 100644
--- a/contrib/tools/bison/bison/src/scan-skel.c
+++ b/contrib/tools/bison/bison/src/scan-skel.c
@@ -1,2435 +1,2435 @@
-#line 2 "lex.yy.c"
-
-#line 4 "lex.yy.c"
-
-#define YY_INT_ALIGNED short int
-
-/* A lexical scanner generated by flex */
-
-/* %not-for-header */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-#define yy_create_buffer skel__create_buffer
-#define yy_delete_buffer skel__delete_buffer
-#define yy_flex_debug skel__flex_debug
-#define yy_init_buffer skel__init_buffer
-#define yy_flush_buffer skel__flush_buffer
-#define yy_load_buffer_state skel__load_buffer_state
-#define yy_switch_to_buffer skel__switch_to_buffer
-#define yyin skel_in
-#define yyleng skel_leng
-#define yylex skel_lex
-#define yylineno skel_lineno
-#define yyout skel_out
-#define yyrestart skel_restart
-#define yytext skel_text
-#define yywrap skel_wrap
-#define yyalloc skel_alloc
-#define yyrealloc skel_realloc
-#define yyfree skel_free
-
-/* %endif */
-/* %endif */
-/* %ok-for-header */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
-#if YY_FLEX_SUBMINOR_VERSION > 0
-#define FLEX_BETA
-#endif
-
-/* %if-c++-only */
+#line 2 "lex.yy.c"
+
+#line 4 "lex.yy.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+/* %not-for-header */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+#define yy_create_buffer skel__create_buffer
+#define yy_delete_buffer skel__delete_buffer
+#define yy_flex_debug skel__flex_debug
+#define yy_init_buffer skel__init_buffer
+#define yy_flush_buffer skel__flush_buffer
+#define yy_load_buffer_state skel__load_buffer_state
+#define yy_switch_to_buffer skel__switch_to_buffer
+#define yyin skel_in
+#define yyleng skel_leng
+#define yylex skel_lex
+#define yylineno skel_lineno
+#define yyout skel_out
+#define yyrestart skel_restart
+#define yytext skel_text
+#define yywrap skel_wrap
+#define yyalloc skel_alloc
+#define yyrealloc skel_realloc
+#define yyfree skel_free
+
+/* %endif */
+/* %endif */
+/* %ok-for-header */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 35
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* %if-c++-only */
#define BISON_FALLTHROUGH [[fallthrough]]
-/* %endif */
-
-/* %if-c-only */
+/* %endif */
+
+/* %if-c-only */
#define BISON_FALLTHROUGH
-/* %endif */
-
-/* %if-c-only */
-
-/* %endif */
-
-/* First, we deal with platform-specific or compiler-specific issues. */
-
-/* begin standard C headers. */
-/* %if-c-only */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-/* %endif */
-
-/* %if-tables-serialization */
-/* %endif */
-/* end standard C headers. */
-
-/* %if-c-or-c++ */
-/* flex integer type definitions */
-
-#ifndef FLEXINT_H
-#define FLEXINT_H
-
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
-
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-
-/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types.
- */
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS 1
-#endif
-
-#include <inttypes.h>
-typedef int8_t flex_int8_t;
-typedef uint8_t flex_uint8_t;
-typedef int16_t flex_int16_t;
-typedef uint16_t flex_uint16_t;
-typedef int32_t flex_int32_t;
-typedef uint32_t flex_uint32_t;
-#else
-typedef signed char flex_int8_t;
-typedef short int flex_int16_t;
-typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
-typedef unsigned short int flex_uint16_t;
-typedef unsigned int flex_uint32_t;
-
-/* Limits of integral types. */
-#ifndef INT8_MIN
-#define INT8_MIN (-128)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN (-32767-1)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN (-2147483647-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX (127)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX (32767)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX (2147483647)
-#endif
-#ifndef UINT8_MAX
-#define UINT8_MAX (255U)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX (65535U)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX (4294967295U)
-#endif
-
-#endif /* ! C99 */
-
-#endif /* ! FLEXINT_H */
-
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
-#ifdef __cplusplus
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else /* ! __cplusplus */
-
-/* C99 requires __STDC__ to be defined as 1. */
-#if defined (__STDC__)
-
-#define YY_USE_CONST
-
-#endif /* defined (__STDC__) */
-#endif /* ! __cplusplus */
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-/* %not-for-header */
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index. If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-/* %ok-for-header */
-
-/* %if-reentrant */
-/* %endif */
-
-/* %if-not-reentrant */
-
-/* %endif */
-
-/* Enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN (yy_start) = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state. The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START (((yy_start) - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE skel_restart(skel_in )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#ifndef YY_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k.
- * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
- * Ditto for the __ia64__ case accordingly.
- */
-#define YY_BUF_SIZE 32768
-#else
-#define YY_BUF_SIZE 16384
-#endif /* __ia64__ */
-#endif
-
-/* The state buf must be large enough to hold one state per character in the main buffer.
- */
-#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
-
-#ifndef YY_TYPEDEF_YY_BUFFER_STATE
-#define YY_TYPEDEF_YY_BUFFER_STATE
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-#endif
-
-/* %if-not-reentrant */
-extern int skel_leng;
-/* %endif */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-extern FILE *skel_in, *skel_out;
-/* %endif */
-/* %endif */
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
- #define YY_LESS_LINENO(n)
-
-/* Return all but the first "n" matched characters back to the input stream. */
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up skel_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- *yy_cp = (yy_hold_char); \
- YY_RESTORE_YY_MORE_OFFSET \
- (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
- YY_DO_BEFORE_ACTION; /* set up skel_text again */ \
- } \
- while ( 0 )
-
-#define unput(c) yyunput( c, (yytext_ptr) )
-
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
-#ifndef YY_STRUCT_YY_BUFFER_STATE
-#define YY_STRUCT_YY_BUFFER_STATE
-struct yy_buffer_state
- {
-/* %if-c-only */
- FILE *yy_input_file;
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
- char *yy_ch_buf; /* input buffer */
- char *yy_buf_pos; /* current position in input buffer */
-
- /* Size of input buffer in bytes, not including room for EOB
- * characters.
- */
- yy_size_t yy_buf_size;
-
- /* Number of characters read into yy_ch_buf, not including EOB
- * characters.
- */
- int yy_n_chars;
-
- /* Whether we "own" the buffer - i.e., we know we created it,
- * and can realloc() it to grow it, and should free() it to
- * delete it.
- */
- int yy_is_our_buffer;
-
- /* Whether this is an "interactive" input source; if so, and
- * if we're using stdio for input, then we want to use getc()
- * instead of fread(), to make sure we stop fetching input after
- * each newline.
- */
- int yy_is_interactive;
-
- /* Whether we're considered to be at the beginning of a line.
- * If so, '^' rules will be active on the next match, otherwise
- * not.
- */
- int yy_at_bol;
-
- int yy_bs_lineno; /**< The line count. */
- int yy_bs_column; /**< The column count. */
-
- /* Whether to try to fill the input buffer when we reach the
- * end of it.
- */
- int yy_fill_buffer;
-
- int yy_buffer_status;
-
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
- /* When an EOF's been seen but there's still some text to process
- * then we mark the buffer as YY_EOF_PENDING, to indicate that we
- * shouldn't try reading from the input source any more. We might
- * still have a bunch of tokens to match, though, because of
- * possible backing-up.
- *
- * When we actually see the EOF, we change the status to "new"
- * (via skel_restart()), so that the user can continue scanning by
- * just pointing skel_in at a new input file.
- */
-#define YY_BUFFER_EOF_PENDING 2
-
- };
-#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-/* %if-not-reentrant */
-
-/* Stack of input buffers. */
-static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
-static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
-static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
-/* %endif */
-/* %ok-for-header */
-
-/* %endif */
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
- ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
- : NULL)
-
-/* Same as previous macro, but useful when we know that the buffer stack is not
- * NULL or when we need an lvalue. For internal use only.
- */
-#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
-
-/* %if-c-only Standard (non-C++) definition */
-
-/* %if-not-reentrant */
-/* %not-for-header */
-
-/* yy_hold_char holds the character lost when skel_text is formed. */
-static char yy_hold_char;
-static int yy_n_chars; /* number of characters read into yy_ch_buf */
-int skel_leng;
-
-/* Points to current character in buffer. */
-static char *yy_c_buf_p = (char *) 0;
-static int yy_init = 0; /* whether we need to initialize */
-static int yy_start = 0; /* start state number */
-
-/* Flag which is used to allow skel_wrap()'s to do buffer switches
- * instead of setting up a fresh skel_in. A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-/* %ok-for-header */
-
-/* %endif */
-
-void skel_restart (FILE *input_file );
-void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer );
-YY_BUFFER_STATE skel__create_buffer (FILE *file,int size );
-void skel__delete_buffer (YY_BUFFER_STATE b );
-void skel__flush_buffer (YY_BUFFER_STATE b );
-void skel_push_buffer_state (YY_BUFFER_STATE new_buffer );
-void skel_pop_buffer_state (void );
-
-static void skel_ensure_buffer_stack (void );
-static void skel__load_buffer_state (void );
-static void skel__init_buffer (YY_BUFFER_STATE b,FILE *file );
-
-#define YY_FLUSH_BUFFER skel__flush_buffer(YY_CURRENT_BUFFER )
-
-YY_BUFFER_STATE skel__scan_buffer (char *base,yy_size_t size );
-YY_BUFFER_STATE skel__scan_string (yyconst char *yy_str );
-YY_BUFFER_STATE skel__scan_bytes (yyconst char *bytes,int len );
-
-/* %endif */
-
-void *skel_alloc (yy_size_t );
-void *skel_realloc (void *,yy_size_t );
-void skel_free (void * );
-
-#define yy_new_buffer skel__create_buffer
-
-#define yy_set_interactive(is_interactive) \
- { \
- if ( ! YY_CURRENT_BUFFER ){ \
- skel_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- skel__create_buffer(skel_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
- }
-
-#define yy_set_bol(at_bol) \
- { \
- if ( ! YY_CURRENT_BUFFER ){\
- skel_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- skel__create_buffer(skel_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
- }
-
-#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
-
-/* %% [1.0] skel_text/skel_in/skel_out/yy_state_type/skel_lineno etc. def's & init go here */
-/* Begin user sect3 */
-
-#define skel_wrap(n) 1
-#define YY_SKIP_YYWRAP
-
-#define FLEX_DEBUG
-
-typedef unsigned char YY_CHAR;
-
-FILE *skel_in = (FILE *) 0, *skel_out = (FILE *) 0;
-
-typedef int yy_state_type;
-
-extern int skel_lineno;
-
-int skel_lineno = 1;
-
-extern char *skel_text;
-#define yytext_ptr skel_text
-
-/* %if-c-only Standard (non-C++) definition */
-
-static yy_state_type yy_get_previous_state (void );
-static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
-static int yy_get_next_buffer (void );
-static void yy_fatal_error (yyconst char msg[] );
-
-/* %endif */
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up skel_text.
- */
-#define YY_DO_BEFORE_ACTION \
- (yytext_ptr) = yy_bp; \
-/* %% [2.0] code to fiddle skel_text and skel_leng for yymore() goes here \ */\
- skel_leng = (size_t) (yy_cp - yy_bp); \
- (yy_hold_char) = *yy_cp; \
- *yy_cp = '\0'; \
-/* %% [3.0] code to copy yytext_ptr to skel_text[] goes here, if %array \ */\
- (yy_c_buf_p) = yy_cp;
-
-/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
-#define YY_NUM_RULES 25
-#define YY_END_OF_BUFFER 26
-/* This struct is not used in this scanner,
- but its presence is necessary. */
-struct yy_trans_info
- {
- flex_int32_t yy_verify;
- flex_int32_t yy_nxt;
- };
-static yyconst flex_int16_t yy_accept[72] =
- { 0,
- 0, 0, 0, 0, 0, 0, 26, 14, 13, 1,
- 12, 15, 22, 24, 23, 23, 14, 1, 12, 6,
- 12, 5, 2, 12, 12, 12, 3, 4, 15, 22,
- 20, 22, 19, 21, 16, 17, 18, 12, 12, 12,
- 12, 12, 0, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
- 8, 7, 12, 12, 12, 11, 12, 12, 9, 10,
- 0
- } ;
-
-static yyconst flex_int32_t yy_ec[256] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 1, 1, 1, 1, 1, 5, 6,
- 7, 1, 1, 7, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 8, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 9, 10, 11, 1,
-
- 12, 13, 1, 1, 14, 1, 1, 15, 16, 17,
- 18, 19, 1, 1, 20, 21, 22, 1, 1, 1,
- 1, 1, 23, 1, 24, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
- } ;
-
-static yyconst flex_int32_t yy_meta[25] =
- { 0,
- 1, 1, 2, 1, 1, 3, 1, 4, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1
- } ;
-
-static yyconst flex_int16_t yy_base[79] =
- { 0,
- 0, 2, 68, 67, 9, 12, 74, 0, 109, 69,
- 14, 0, 36, 109, 109, 109, 0, 68, 58, 109,
- 17, 109, 109, 62, 52, 13, 109, 109, 0, 109,
- 109, 26, 109, 109, 109, 109, 109, 49, 52, 53,
- 51, 43, 30, 50, 39, 42, 39, 36, 37, 38,
- 40, 39, 28, 40, 39, 39, 38, 24, 26, 22,
- 109, 109, 25, 15, 6, 109, 3, 1, 109, 109,
- 109, 82, 86, 90, 94, 97, 101, 104
- } ;
-
-static yyconst flex_int16_t yy_def[79] =
- { 0,
- 72, 72, 73, 73, 74, 74, 71, 75, 71, 75,
- 76, 77, 78, 71, 71, 71, 75, 75, 76, 71,
- 19, 71, 71, 19, 19, 19, 71, 71, 77, 71,
- 71, 71, 71, 71, 71, 71, 71, 19, 19, 19,
- 19, 19, 71, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 71, 71, 19, 19, 19, 71, 19, 19, 71, 71,
- 0, 71, 71, 71, 71, 71, 71, 71
- } ;
-
-static yyconst flex_int16_t yy_nxt[134] =
- { 0,
- 71, 71, 9, 10, 9, 10, 70, 11, 69, 11,
- 15, 16, 15, 15, 16, 15, 20, 21, 22, 20,
- 21, 23, 68, 24, 25, 40, 67, 41, 31, 43,
- 66, 26, 31, 43, 42, 65, 27, 28, 31, 32,
- 33, 64, 34, 35, 63, 62, 61, 60, 59, 58,
- 57, 56, 55, 54, 53, 52, 51, 50, 36, 37,
- 71, 49, 71, 48, 47, 71, 46, 45, 44, 39,
- 38, 18, 18, 71, 13, 13, 71, 71, 71, 71,
- 71, 71, 8, 8, 8, 8, 12, 12, 12, 12,
- 14, 14, 14, 14, 17, 71, 17, 19, 19, 71,
-
- 19, 29, 29, 29, 30, 30, 30, 30, 7, 71,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
- 71, 71, 71
- } ;
-
-static yyconst flex_int16_t yy_chk[134] =
- { 0,
- 0, 0, 1, 1, 2, 2, 68, 1, 67, 2,
- 5, 5, 5, 6, 6, 6, 11, 11, 11, 21,
- 21, 11, 65, 11, 11, 26, 64, 26, 32, 32,
- 63, 11, 43, 43, 26, 60, 11, 11, 13, 13,
- 13, 59, 13, 13, 58, 57, 56, 55, 54, 53,
- 52, 51, 50, 49, 48, 47, 46, 45, 13, 13,
- 19, 44, 19, 42, 41, 19, 40, 39, 38, 25,
- 24, 18, 10, 7, 4, 3, 0, 0, 0, 0,
- 19, 19, 72, 72, 72, 72, 73, 73, 73, 73,
- 74, 74, 74, 74, 75, 0, 75, 76, 76, 0,
-
- 76, 77, 77, 77, 78, 78, 78, 78, 71, 71,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
- 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
- 71, 71, 71
- } ;
-
-static yy_state_type yy_last_accepting_state;
-static char *yy_last_accepting_cpos;
-
-extern int skel__flex_debug;
-int skel__flex_debug = 1;
-
-static yyconst flex_int16_t yy_rule_linenum[25] =
- { 0,
- 72, 73, 74, 75, 76, 77, 79, 80, 82, 83,
- 84, 87, 88, 89, 102, 104, 105, 106, 107, 108,
- 110, 129, 134, 135
- } ;
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-char *skel_text;
-#line 1 "scan-skel.l"
-/* Scan Bison Skeletons. -*- C -*-
-
- Copyright (C) 2001-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#define YY_NO_INPUT 1
-#line 24 "scan-skel.l"
-/* Work around a bug in flex 2.5.31. See Debian bug 333231
- <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
-#undef skel_wrap
-#define skel_wrap() 1
-
-#define FLEX_PREFIX(Id) skel_ ## Id
-#include <src/flex-scanner.h>
-
-#include <dirname.h>
-#include <error.h>
-#include <quotearg.h>
-
-#include <src/complain.h>
-#include <src/getargs.h>
-#include <src/files.h>
-#include <src/scan-skel.h>
-
-#define YY_DECL static int skel_lex (void)
-YY_DECL;
-
-typedef void (*at_directive)(int, char**, char **, int*);
-static void at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun);
-static void at_basename (int argc, char *argv[], char**, int*);
-static void at_complain (int argc, char *argv[], char**, int*);
-static void at_output (int argc, char *argv[], char **name, int *lineno);
-static void fail_for_at_directive_too_many_args (char const *at_directive_name);
-static void fail_for_at_directive_too_few_args (char const *at_directive_name);
-static void fail_for_invalid_at (char const *at);
-
-
-#line 671 "lex.yy.c"
-
-#define INITIAL 0
-#define SC_AT_DIRECTIVE_ARGS 1
-#define SC_AT_DIRECTIVE_SKIP_WS 2
-
-#ifndef YY_NO_UNISTD_H
-/* Special case for "unistd.h", since it is non-ANSI. We include it way
- * down here because we want the user's section 1 to have been scanned first.
- * The user has a chance to override it with an option.
- */
-/* %if-c-only */
-#include <unistd.h>
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-#ifndef YY_EXTRA_TYPE
-#define YY_EXTRA_TYPE void *
-#endif
-
-/* %if-c-only Reentrant structure and macros (non-C++). */
-/* %if-reentrant */
-/* %if-c-only */
-
-static int yy_init_globals (void );
-
-/* %endif */
-/* %if-reentrant */
-/* %endif */
-/* %endif End reentrant structures and macros. */
-
-/* Accessor methods to globals.
- These are made visible to non-reentrant scanners for convenience. */
-
-int skel_lex_destroy (void );
-
-int skel_get_debug (void );
-
-void skel_set_debug (int debug_flag );
-
-YY_EXTRA_TYPE skel_get_extra (void );
-
-void skel_set_extra (YY_EXTRA_TYPE user_defined );
-
-FILE *skel_get_in (void );
-
-void skel_set_in (FILE * in_str );
-
-FILE *skel_get_out (void );
-
-void skel_set_out (FILE * out_str );
-
-int skel_get_leng (void );
-
-char *skel_get_text (void );
-
-int skel_get_lineno (void );
-
-void skel_set_lineno (int line_number );
-
-/* %if-bison-bridge */
-/* %endif */
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int skel_wrap (void );
-#else
-extern int skel_wrap (void );
-#endif
-#endif
-
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %endif */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int );
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * );
-#endif
-
-#ifndef YY_NO_INPUT
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-#ifdef __cplusplus
-static int yyinput (void );
-#else
-static int input (void );
-#endif
-/* %ok-for-header */
-
-/* %endif */
-#endif
-
-/* %if-c-only */
-
-/* %endif */
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#ifdef __ia64__
-/* On IA-64, the buffer size is 16k, not 8k */
-#define YY_READ_BUF_SIZE 16384
-#else
-#define YY_READ_BUF_SIZE 8192
-#endif /* __ia64__ */
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-#ifndef ECHO
-/* %if-c-only Standard (non-C++) definition */
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO do { if (fwrite( skel_text, skel_leng, 1, skel_out )) {} } while (0)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif
-
-/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
- if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
- { \
- int c = '*'; \
- size_t n; \
- for ( n = 0; n < max_size && \
- (c = getc( skel_in )) != EOF && c != '\n'; ++n ) \
- buf[n] = (char) c; \
- if ( c == '\n' ) \
- buf[n++] = (char) c; \
- if ( c == EOF && ferror( skel_in ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- result = n; \
- } \
- else \
- { \
- errno=0; \
- while ( (result = fread(buf, 1, max_size, skel_in))==0 && ferror(skel_in)) \
- { \
- if( errno != EINTR) \
- { \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- break; \
- } \
- errno=0; \
- clearerr(skel_in); \
- } \
- }\
-\
-/* %if-c++-only C++ definition \ */\
-/* %endif */
-
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-/* %if-c-only */
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-/* %if-tables-serialization structures and prototypes */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* %tables-yydmap generated elements */
-/* %endif */
-/* end tables serialization structures and prototypes */
-
-/* %ok-for-header */
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL_IS_OURS 1
-/* %if-c-only Standard (non-C++) definition */
-
-extern int skel_lex (void);
-
-#define YY_DECL int skel_lex (void)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif /* !YY_DECL */
-
-/* Code executed at the beginning of each rule, after skel_text and skel_leng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-/* %% [6.0] YY_RULE_SETUP definition goes here */
-#define YY_RULE_SETUP \
- YY_USER_ACTION
-
-/* %not-for-header */
-
-/** The main scanner function which does all the work.
- */
-YY_DECL
-{
- register yy_state_type yy_current_state;
- register char *yy_cp, *yy_bp;
- register int yy_act;
-
-/* %% [7.0] user's declarations go here */
-#line 57 "scan-skel.l"
-
-
-
- int out_lineno PACIFY_CC (= 0);
- char *out_name = NULL;
-
- /* Currently, only the @complain directive takes multiple arguments, and
- never more than 7, with argv[0] being the directive name and argv[1]
- being the type of complaint to dispatch. */
-#define ARGC_MAX 9
- int argc = 0;
- char *argv[ARGC_MAX];
- at_directive at_ptr = NULL;
-
-
-#line 934 "lex.yy.c"
-
- if ( !(yy_init) )
- {
- (yy_init) = 1;
-
-#ifdef YY_USER_INIT
- YY_USER_INIT;
-#endif
-
- if ( ! (yy_start) )
- (yy_start) = 1; /* first start state */
-
- if ( ! skel_in )
-/* %if-c-only */
- skel_in = stdin;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! skel_out )
-/* %if-c-only */
- skel_out = stdout;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! YY_CURRENT_BUFFER ) {
- skel_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- skel__create_buffer(skel_in,YY_BUF_SIZE );
- }
-
- skel__load_buffer_state( );
- }
-
- while ( 1 ) /* loops until end-of-file is reached */
- {
-/* %% [8.0] yymore()-related code goes here */
- yy_cp = (yy_c_buf_p);
-
- /* Support of skel_text. */
- *yy_cp = (yy_hold_char);
-
- /* yy_bp points to the position in yy_ch_buf of the start of
- * the current run.
- */
- yy_bp = yy_cp;
-
-/* %% [9.0] code to set up and find next match goes here */
- yy_current_state = (yy_start);
-yy_match:
- do
- {
- register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 72 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- ++yy_cp;
- }
- while ( yy_current_state != 71 );
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
-
-yy_find_action:
-/* %% [10.0] code to find the action number goes here */
- yy_act = yy_accept[yy_current_state];
-
- YY_DO_BEFORE_ACTION;
-
-/* %% [11.0] code for skel_lineno update goes here */
-
-do_action: /* This label is used only to access EOF actions. */
-
-/* %% [12.0] debug code goes here */
- if ( skel__flex_debug )
- {
- if ( yy_act == 0 )
- fprintf( stderr, "--scanner backing up\n" );
- else if ( yy_act < 25 )
- fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
- (long)yy_rule_linenum[yy_act], skel_text );
- else if ( yy_act == 25 )
- fprintf( stderr, "--accepting default rule (\"%s\")\n",
- skel_text );
- else if ( yy_act == 26 )
- fprintf( stderr, "--(end of buffer or a NUL)\n" );
- else
- fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
- }
-
- switch ( yy_act )
- { /* beginning of action switch */
-/* %% [13.0] actions go here */
- case 0: /* must back up */
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = (yy_hold_char);
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
-
-case 1:
-YY_RULE_SETUP
-#line 72 "scan-skel.l"
-continue;
- YY_BREAK
-case 2:
-YY_RULE_SETUP
-#line 73 "scan-skel.l"
-fputc ('@', skel_out);
- YY_BREAK
-case 3:
-YY_RULE_SETUP
-#line 74 "scan-skel.l"
-fputc ('[', skel_out);
- YY_BREAK
-case 4:
-YY_RULE_SETUP
-#line 75 "scan-skel.l"
-fputc (']', skel_out);
- YY_BREAK
-case 5:
-YY_RULE_SETUP
-#line 76 "scan-skel.l"
-continue; /* Used by b4_cat in ../data/bison.m4. */
- YY_BREAK
-case 6:
-/* rule 6 can match eol */
-YY_RULE_SETUP
-#line 77 "scan-skel.l"
-continue;
- YY_BREAK
-case 7:
-YY_RULE_SETUP
-#line 79 "scan-skel.l"
-fprintf (skel_out, "%d", out_lineno + 1);
- YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 80 "scan-skel.l"
-fputs (quotearg_style (c_quoting_style, out_name), skel_out);
- YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 82 "scan-skel.l"
-at_init (&argc, argv, &at_ptr, &at_basename);
- YY_BREAK
-case 10:
-YY_RULE_SETUP
-#line 83 "scan-skel.l"
-at_init (&argc, argv, &at_ptr, &at_complain);
- YY_BREAK
-case 11:
-YY_RULE_SETUP
-#line 84 "scan-skel.l"
-at_init (&argc, argv, &at_ptr, &at_output);
- YY_BREAK
-/* This pattern must not match more than the previous @ patterns. */
-case 12:
-YY_RULE_SETUP
-#line 87 "scan-skel.l"
-fail_for_invalid_at (skel_text);
- YY_BREAK
-case 13:
-/* rule 13 can match eol */
-YY_RULE_SETUP
-#line 88 "scan-skel.l"
-out_lineno++; ECHO;
- YY_BREAK
-case 14:
-YY_RULE_SETUP
-#line 89 "scan-skel.l"
-ECHO;
- YY_BREAK
-case YY_STATE_EOF(INITIAL):
-#line 91 "scan-skel.l"
-{
- if (out_name)
- {
- free (out_name);
- xfclose (skel_out);
- }
- return EOF;
-}
- YY_BREAK
-
-
-case 15:
-/* rule 15 can match eol */
-YY_RULE_SETUP
-#line 102 "scan-skel.l"
-STRING_GROW;
- YY_BREAK
-case 16:
-YY_RULE_SETUP
-#line 104 "scan-skel.l"
-obstack_1grow (&obstack_for_string, '@');
- YY_BREAK
-case 17:
-YY_RULE_SETUP
-#line 105 "scan-skel.l"
-obstack_1grow (&obstack_for_string, '[');
- YY_BREAK
-case 18:
-YY_RULE_SETUP
-#line 106 "scan-skel.l"
-obstack_1grow (&obstack_for_string, ']');
- YY_BREAK
-case 19:
-YY_RULE_SETUP
-#line 107 "scan-skel.l"
-continue; /* For starting an argument that begins with whitespace. */
- YY_BREAK
-case 20:
-/* rule 20 can match eol */
-YY_RULE_SETUP
-#line 108 "scan-skel.l"
-continue;
- YY_BREAK
-case 21:
-YY_RULE_SETUP
-#line 110 "scan-skel.l"
-{
- if (argc >= ARGC_MAX)
- fail_for_at_directive_too_many_args (argv[0]);
-
- argv[argc++] = obstack_finish0 (&obstack_for_string);
-
- /* Like M4, skip whitespace after a comma. */
- if (skel_text[1] == ',')
- BEGIN SC_AT_DIRECTIVE_SKIP_WS;
- else
- {
- aver (at_ptr);
- at_ptr (argc, argv, &out_name, &out_lineno);
- obstack_free (&obstack_for_string, argv[0]);
- argc = 0;
- BEGIN INITIAL;
- }
- }
- YY_BREAK
-case 22:
-YY_RULE_SETUP
-#line 129 "scan-skel.l"
-fail_for_invalid_at (skel_text);
- YY_BREAK
-
-
-
-case 23:
-/* rule 23 can match eol */
-YY_RULE_SETUP
-#line 134 "scan-skel.l"
-continue;
- YY_BREAK
-case 24:
-YY_RULE_SETUP
-#line 135 "scan-skel.l"
-yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS;
- YY_BREAK
-
-
-
-case YY_STATE_EOF(SC_AT_DIRECTIVE_ARGS):
-case YY_STATE_EOF(SC_AT_DIRECTIVE_SKIP_WS):
-#line 140 "scan-skel.l"
-complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]);
- YY_BREAK
-
-case 25:
-YY_RULE_SETUP
-#line 143 "scan-skel.l"
-YY_FATAL_ERROR( "flex scanner jammed" );
- YY_BREAK
-#line 1217 "lex.yy.c"
-
- case YY_END_OF_BUFFER:
- {
- /* Amount of text matched not including the EOB char. */
- int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
-
- /* Undo the effects of YY_DO_BEFORE_ACTION. */
- *yy_cp = (yy_hold_char);
- YY_RESTORE_YY_MORE_OFFSET
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
- {
- /* We're scanning a new file or input source. It's
- * possible that this happened because the user
- * just pointed skel_in at a new source and called
- * skel_lex(). If so, then we have to assure
- * consistency between YY_CURRENT_BUFFER and our
- * globals. Here is the right place to do so, because
- * this is the first action (other than possibly a
- * back-up) that will match for the new input source.
- */
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- YY_CURRENT_BUFFER_LVALUE->yy_input_file = skel_in;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
- }
-
- /* Note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the
- * end-of-buffer state). Contrast this with the test
- * in input().
- */
- if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- { /* This was really a NUL. */
- yy_state_type yy_next_state;
-
- (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- /* Okay, we're now positioned to make the NUL
- * transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we don't
- * want to build jamming into it because then it
- * will run more slowly).
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state );
-
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* Consume the NUL. */
- yy_cp = ++(yy_c_buf_p);
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
-/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_END_OF_FILE:
- {
- (yy_did_buffer_switch_on_eof) = 0;
-
- if ( skel_wrap( ) )
- {
- /* Note: because we've taken care in
- * yy_get_next_buffer() to have set up
- * skel_text, we can now set up
- * yy_c_buf_p so that if some total
- * hoser (like flex itself) wants to
- * call the scanner after we return the
- * YY_NULL, it'll still work - another
- * YY_NULL will get returned.
- */
- (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF(YY_START);
- goto do_action;
- }
-
- else
- {
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
- }
- break;
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) =
- (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- (yy_c_buf_p) =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- } /* end of action switch */
- } /* end of scanning one token */
-} /* end of skel_lex */
-/* %ok-for-header */
-
-/* %if-c++-only */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %endif */
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-/* %if-c-only */
-static int yy_get_next_buffer (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
- register char *source = (yytext_ptr);
- register int number_to_move, i;
- int ret_val;
-
- if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
- { /* Don't try to fill the buffer, so this is an EOF. */
- if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
- {
- /* We matched a single character, the EOB, so
- * treat this as a final EOF.
- */
- return EOB_ACT_END_OF_FILE;
- }
-
- else
- {
- /* We matched some text prior to the EOB, first
- * process it.
- */
- return EOB_ACT_LAST_MATCH;
- }
- }
-
- /* Try to read more data. */
-
- /* First move last chars to start of buffer. */
- number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
-
- else
- {
- int num_to_read =
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
-
- while ( num_to_read <= 0 )
- { /* Not enough room in the buffer - grow it. */
-
- /* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
-
- int yy_c_buf_p_offset =
- (int) ((yy_c_buf_p) - b->yy_ch_buf);
-
- if ( b->yy_is_our_buffer )
- {
- int new_size = b->yy_buf_size * 2;
-
- if ( new_size <= 0 )
- b->yy_buf_size += b->yy_buf_size / 8;
- else
- b->yy_buf_size *= 2;
-
- b->yy_ch_buf = (char *)
- /* Include room in for 2 EOB chars. */
- skel_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
- }
- else
- /* Can't grow it, we don't own it. */
- b->yy_ch_buf = 0;
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
-
- (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
-
- num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
- number_to_move - 1;
-
- }
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- /* Read in more data. */
- YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- (yy_n_chars), (size_t) num_to_read );
-
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- if ( (yy_n_chars) == 0 )
- {
- if ( number_to_move == YY_MORE_ADJ )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- skel_restart(skel_in );
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
- YY_BUFFER_EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
- /* Extend the array by 50%, plus the number we really need. */
- yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) skel_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
- if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
- }
-
- (yy_n_chars) += number_to_move;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
-
- (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
-
- return ret_val;
-}
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
-/* %if-c-only */
-/* %not-for-header */
-
- static yy_state_type yy_get_previous_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register yy_state_type yy_current_state;
- register char *yy_cp;
-
-/* %% [15.0] code to get the start state into yy_current_state goes here */
- yy_current_state = (yy_start);
-
- for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
- {
-/* %% [16.0] code to find the next state goes here */
- register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 72 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- }
-
- return yy_current_state;
-}
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
-/* %if-c-only */
- static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register int yy_is_jam;
- /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
- register char *yy_cp = (yy_c_buf_p);
-
- register YY_CHAR yy_c = 1;
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 72 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 71);
-
- return yy_is_jam ? 0 : yy_current_state;
-}
-
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c-only */
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
- static int yyinput (void)
-#else
- static int input (void)
-#endif
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- int c;
-
- *(yy_c_buf_p) = (yy_hold_char);
-
- if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- /* This was really a NUL. */
- *(yy_c_buf_p) = '\0';
-
- else
- { /* need more input */
- int offset = (yy_c_buf_p) - (yytext_ptr);
- ++(yy_c_buf_p);
-
- switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_LAST_MATCH:
- /* This happens because yy_g_n_b()
- * sees that we've accumulated a
- * token and flags that we need to
- * try matching the token before
- * proceeding. But for input(),
- * there's no matching to consider.
- * So convert the EOB_ACT_LAST_MATCH
- * to EOB_ACT_END_OF_FILE.
- */
-
- /* Reset buffer status. */
- skel_restart(skel_in );
-
- BISON_FALLTHROUGH;
-
- case EOB_ACT_END_OF_FILE:
- {
- if ( skel_wrap( ) )
- return EOF;
-
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
-#ifdef __cplusplus
- return yyinput();
-#else
- return input();
-#endif
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) = (yytext_ptr) + offset;
- break;
- }
- }
- }
-
- c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
- *(yy_c_buf_p) = '\0'; /* preserve skel_text */
- (yy_hold_char) = *++(yy_c_buf_p);
-
-/* %% [19.0] update BOL and skel_lineno */
-
- return c;
-}
-/* %if-c-only */
-#endif /* ifndef YY_NO_INPUT */
-/* %endif */
-
-/** Immediately switch to a different input stream.
- * @param input_file A readable stream.
- *
- * @note This function does not reset the start condition to @c INITIAL .
- */
-/* %if-c-only */
- void skel_restart (FILE * input_file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! YY_CURRENT_BUFFER ){
- skel_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- skel__create_buffer(skel_in,YY_BUF_SIZE );
- }
-
- skel__init_buffer(YY_CURRENT_BUFFER,input_file );
- skel__load_buffer_state( );
-}
-
-/** Switch to a different input buffer.
- * @param new_buffer The new input buffer.
+/* %endif */
+
+/* %if-c-only */
+
+/* %endif */
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+/* %if-c-only */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+/* %endif */
+
+/* %if-tables-serialization */
+/* %endif */
+/* end standard C headers. */
+
+/* %if-c-or-c++ */
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* %not-for-header */
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+/* %ok-for-header */
+
+/* %if-reentrant */
+/* %endif */
+
+/* %if-not-reentrant */
+
+/* %endif */
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE skel_restart(skel_in )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+/* %if-not-reentrant */
+extern int skel_leng;
+/* %endif */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+extern FILE *skel_in, *skel_out;
+/* %endif */
+/* %endif */
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up skel_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up skel_text again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+/* %if-c-only */
+ FILE *yy_input_file;
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via skel_restart()), so that the user can continue scanning by
+ * just pointing skel_in at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+/* %if-not-reentrant */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
+/* %endif */
+/* %ok-for-header */
+
+/* %endif */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
*
- */
-/* %if-c-only */
- void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- /* TODO. We should be able to replace this entire function body
- * with
- * skel_pop_buffer_state();
- * skel_push_buffer_state(new_buffer);
- */
- skel_ensure_buffer_stack ();
- if ( YY_CURRENT_BUFFER == new_buffer )
- return;
-
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
- skel__load_buffer_state( );
-
- /* We don't actually know whether we did this switch during
- * EOF (skel_wrap()) processing, but the only time this flag
- * is looked at is after skel_wrap() is called, so it's safe
- * to go ahead and always set it.
- */
- (yy_did_buffer_switch_on_eof) = 1;
-}
-
-/* %if-c-only */
-static void skel__load_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
- skel_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
- (yy_hold_char) = *(yy_c_buf_p);
-}
-
-/** Allocate and initialize an input buffer state.
- * @param file A readable stream.
- * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* %if-c-only Standard (non-C++) definition */
+
+/* %if-not-reentrant */
+/* %not-for-header */
+
+/* yy_hold_char holds the character lost when skel_text is formed. */
+static char yy_hold_char;
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+int skel_leng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow skel_wrap()'s to do buffer switches
+ * instead of setting up a fresh skel_in. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+/* %ok-for-header */
+
+/* %endif */
+
+void skel_restart (FILE *input_file );
+void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE skel__create_buffer (FILE *file,int size );
+void skel__delete_buffer (YY_BUFFER_STATE b );
+void skel__flush_buffer (YY_BUFFER_STATE b );
+void skel_push_buffer_state (YY_BUFFER_STATE new_buffer );
+void skel_pop_buffer_state (void );
+
+static void skel_ensure_buffer_stack (void );
+static void skel__load_buffer_state (void );
+static void skel__init_buffer (YY_BUFFER_STATE b,FILE *file );
+
+#define YY_FLUSH_BUFFER skel__flush_buffer(YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE skel__scan_buffer (char *base,yy_size_t size );
+YY_BUFFER_STATE skel__scan_string (yyconst char *yy_str );
+YY_BUFFER_STATE skel__scan_bytes (yyconst char *bytes,int len );
+
+/* %endif */
+
+void *skel_alloc (yy_size_t );
+void *skel_realloc (void *,yy_size_t );
+void skel_free (void * );
+
+#define yy_new_buffer skel__create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ skel_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ skel__create_buffer(skel_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ skel_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ skel__create_buffer(skel_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* %% [1.0] skel_text/skel_in/skel_out/yy_state_type/skel_lineno etc. def's & init go here */
+/* Begin user sect3 */
+
+#define skel_wrap(n) 1
+#define YY_SKIP_YYWRAP
+
+#define FLEX_DEBUG
+
+typedef unsigned char YY_CHAR;
+
+FILE *skel_in = (FILE *) 0, *skel_out = (FILE *) 0;
+
+typedef int yy_state_type;
+
+extern int skel_lineno;
+
+int skel_lineno = 1;
+
+extern char *skel_text;
+#define yytext_ptr skel_text
+
+/* %if-c-only Standard (non-C++) definition */
+
+static yy_state_type yy_get_previous_state (void );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
+static int yy_get_next_buffer (void );
+static void yy_fatal_error (yyconst char msg[] );
+
+/* %endif */
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up skel_text.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+/* %% [2.0] code to fiddle skel_text and skel_leng for yymore() goes here \ */\
+ skel_leng = (size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+/* %% [3.0] code to copy yytext_ptr to skel_text[] goes here, if %array \ */\
+ (yy_c_buf_p) = yy_cp;
+
+/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
+#define YY_NUM_RULES 25
+#define YY_END_OF_BUFFER 26
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[72] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 26, 14, 13, 1,
+ 12, 15, 22, 24, 23, 23, 14, 1, 12, 6,
+ 12, 5, 2, 12, 12, 12, 3, 4, 15, 22,
+ 20, 22, 19, 21, 16, 17, 18, 12, 12, 12,
+ 12, 12, 0, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 8, 7, 12, 12, 12, 11, 12, 12, 9, 10,
+ 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 1, 1, 1, 1, 1, 5, 6,
+ 7, 1, 1, 7, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 8, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 9, 10, 11, 1,
+
+ 12, 13, 1, 1, 14, 1, 1, 15, 16, 17,
+ 18, 19, 1, 1, 20, 21, 22, 1, 1, 1,
+ 1, 1, 23, 1, 24, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[25] =
+ { 0,
+ 1, 1, 2, 1, 1, 3, 1, 4, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[79] =
+ { 0,
+ 0, 2, 68, 67, 9, 12, 74, 0, 109, 69,
+ 14, 0, 36, 109, 109, 109, 0, 68, 58, 109,
+ 17, 109, 109, 62, 52, 13, 109, 109, 0, 109,
+ 109, 26, 109, 109, 109, 109, 109, 49, 52, 53,
+ 51, 43, 30, 50, 39, 42, 39, 36, 37, 38,
+ 40, 39, 28, 40, 39, 39, 38, 24, 26, 22,
+ 109, 109, 25, 15, 6, 109, 3, 1, 109, 109,
+ 109, 82, 86, 90, 94, 97, 101, 104
+ } ;
+
+static yyconst flex_int16_t yy_def[79] =
+ { 0,
+ 72, 72, 73, 73, 74, 74, 71, 75, 71, 75,
+ 76, 77, 78, 71, 71, 71, 75, 75, 76, 71,
+ 19, 71, 71, 19, 19, 19, 71, 71, 77, 71,
+ 71, 71, 71, 71, 71, 71, 71, 19, 19, 19,
+ 19, 19, 71, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 71, 71, 19, 19, 19, 71, 19, 19, 71, 71,
+ 0, 71, 71, 71, 71, 71, 71, 71
+ } ;
+
+static yyconst flex_int16_t yy_nxt[134] =
+ { 0,
+ 71, 71, 9, 10, 9, 10, 70, 11, 69, 11,
+ 15, 16, 15, 15, 16, 15, 20, 21, 22, 20,
+ 21, 23, 68, 24, 25, 40, 67, 41, 31, 43,
+ 66, 26, 31, 43, 42, 65, 27, 28, 31, 32,
+ 33, 64, 34, 35, 63, 62, 61, 60, 59, 58,
+ 57, 56, 55, 54, 53, 52, 51, 50, 36, 37,
+ 71, 49, 71, 48, 47, 71, 46, 45, 44, 39,
+ 38, 18, 18, 71, 13, 13, 71, 71, 71, 71,
+ 71, 71, 8, 8, 8, 8, 12, 12, 12, 12,
+ 14, 14, 14, 14, 17, 71, 17, 19, 19, 71,
+
+ 19, 29, 29, 29, 30, 30, 30, 30, 7, 71,
+ 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
+ 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
+ 71, 71, 71
+ } ;
+
+static yyconst flex_int16_t yy_chk[134] =
+ { 0,
+ 0, 0, 1, 1, 2, 2, 68, 1, 67, 2,
+ 5, 5, 5, 6, 6, 6, 11, 11, 11, 21,
+ 21, 11, 65, 11, 11, 26, 64, 26, 32, 32,
+ 63, 11, 43, 43, 26, 60, 11, 11, 13, 13,
+ 13, 59, 13, 13, 58, 57, 56, 55, 54, 53,
+ 52, 51, 50, 49, 48, 47, 46, 45, 13, 13,
+ 19, 44, 19, 42, 41, 19, 40, 39, 38, 25,
+ 24, 18, 10, 7, 4, 3, 0, 0, 0, 0,
+ 19, 19, 72, 72, 72, 72, 73, 73, 73, 73,
+ 74, 74, 74, 74, 75, 0, 75, 76, 76, 0,
+
+ 76, 77, 77, 77, 78, 78, 78, 78, 71, 71,
+ 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
+ 71, 71, 71, 71, 71, 71, 71, 71, 71, 71,
+ 71, 71, 71
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int skel__flex_debug;
+int skel__flex_debug = 1;
+
+static yyconst flex_int16_t yy_rule_linenum[25] =
+ { 0,
+ 72, 73, 74, 75, 76, 77, 79, 80, 82, 83,
+ 84, 87, 88, 89, 102, 104, 105, 106, 107, 108,
+ 110, 129, 134, 135
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *skel_text;
+#line 1 "scan-skel.l"
+/* Scan Bison Skeletons. -*- C -*-
+
+ Copyright (C) 2001-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define YY_NO_INPUT 1
+#line 24 "scan-skel.l"
+/* Work around a bug in flex 2.5.31. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+#undef skel_wrap
+#define skel_wrap() 1
+
+#define FLEX_PREFIX(Id) skel_ ## Id
+#include <src/flex-scanner.h>
+
+#include <dirname.h>
+#include <error.h>
+#include <quotearg.h>
+
+#include <src/complain.h>
+#include <src/getargs.h>
+#include <src/files.h>
+#include <src/scan-skel.h>
+
+#define YY_DECL static int skel_lex (void)
+YY_DECL;
+
+typedef void (*at_directive)(int, char**, char **, int*);
+static void at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun);
+static void at_basename (int argc, char *argv[], char**, int*);
+static void at_complain (int argc, char *argv[], char**, int*);
+static void at_output (int argc, char *argv[], char **name, int *lineno);
+static void fail_for_at_directive_too_many_args (char const *at_directive_name);
+static void fail_for_at_directive_too_few_args (char const *at_directive_name);
+static void fail_for_invalid_at (char const *at);
+
+
+#line 671 "lex.yy.c"
+
+#define INITIAL 0
+#define SC_AT_DIRECTIVE_ARGS 1
+#define SC_AT_DIRECTIVE_SKIP_WS 2
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+/* %if-c-only */
+#include <unistd.h>
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* %if-c-only Reentrant structure and macros (non-C++). */
+/* %if-reentrant */
+/* %if-c-only */
+
+static int yy_init_globals (void );
+
+/* %endif */
+/* %if-reentrant */
+/* %endif */
+/* %endif End reentrant structures and macros. */
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int skel_lex_destroy (void );
+
+int skel_get_debug (void );
+
+void skel_set_debug (int debug_flag );
+
+YY_EXTRA_TYPE skel_get_extra (void );
+
+void skel_set_extra (YY_EXTRA_TYPE user_defined );
+
+FILE *skel_get_in (void );
+
+void skel_set_in (FILE * in_str );
+
+FILE *skel_get_out (void );
+
+void skel_set_out (FILE * out_str );
+
+int skel_get_leng (void );
+
+char *skel_get_text (void );
+
+int skel_get_lineno (void );
+
+void skel_set_lineno (int line_number );
+
+/* %if-bison-bridge */
+/* %endif */
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int skel_wrap (void );
+#else
+extern int skel_wrap (void );
+#endif
+#endif
+
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %endif */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+#ifdef __cplusplus
+static int yyinput (void );
+#else
+static int input (void );
+#endif
+/* %ok-for-header */
+
+/* %endif */
+#endif
+
+/* %if-c-only */
+
+/* %endif */
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* %if-c-only Standard (non-C++) definition */
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( skel_text, skel_leng, 1, skel_out )) {} } while (0)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( skel_in )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( skel_in ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, skel_in))==0 && ferror(skel_in)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(skel_in); \
+ } \
+ }\
+\
+/* %if-c++-only C++ definition \ */\
+/* %endif */
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+/* %if-c-only */
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+/* %if-tables-serialization structures and prototypes */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* %tables-yydmap generated elements */
+/* %endif */
+/* end tables serialization structures and prototypes */
+
+/* %ok-for-header */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+/* %if-c-only Standard (non-C++) definition */
+
+extern int skel_lex (void);
+
+#define YY_DECL int skel_lex (void)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after skel_text and skel_leng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+/* %% [6.0] YY_RULE_SETUP definition goes here */
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/* %not-for-header */
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+/* %% [7.0] user's declarations go here */
+#line 57 "scan-skel.l"
+
+
+
+ int out_lineno PACIFY_CC (= 0);
+ char *out_name = NULL;
+
+ /* Currently, only the @complain directive takes multiple arguments, and
+ never more than 7, with argv[0] being the directive name and argv[1]
+ being the type of complaint to dispatch. */
+#define ARGC_MAX 9
+ int argc = 0;
+ char *argv[ARGC_MAX];
+ at_directive at_ptr = NULL;
+
+
+#line 934 "lex.yy.c"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! skel_in )
+/* %if-c-only */
+ skel_in = stdin;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! skel_out )
+/* %if-c-only */
+ skel_out = stdout;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ skel_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ skel__create_buffer(skel_in,YY_BUF_SIZE );
+ }
+
+ skel__load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+/* %% [8.0] yymore()-related code goes here */
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of skel_text. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+/* %% [9.0] code to set up and find next match goes here */
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 72 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 71 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+/* %% [10.0] code to find the action number goes here */
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+/* %% [11.0] code for skel_lineno update goes here */
+
+do_action: /* This label is used only to access EOF actions. */
+
+/* %% [12.0] debug code goes here */
+ if ( skel__flex_debug )
+ {
+ if ( yy_act == 0 )
+ fprintf( stderr, "--scanner backing up\n" );
+ else if ( yy_act < 25 )
+ fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
+ (long)yy_rule_linenum[yy_act], skel_text );
+ else if ( yy_act == 25 )
+ fprintf( stderr, "--accepting default rule (\"%s\")\n",
+ skel_text );
+ else if ( yy_act == 26 )
+ fprintf( stderr, "--(end of buffer or a NUL)\n" );
+ else
+ fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
+ }
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+/* %% [13.0] actions go here */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 72 "scan-skel.l"
+continue;
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 73 "scan-skel.l"
+fputc ('@', skel_out);
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 74 "scan-skel.l"
+fputc ('[', skel_out);
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 75 "scan-skel.l"
+fputc (']', skel_out);
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 76 "scan-skel.l"
+continue; /* Used by b4_cat in ../data/bison.m4. */
+ YY_BREAK
+case 6:
+/* rule 6 can match eol */
+YY_RULE_SETUP
+#line 77 "scan-skel.l"
+continue;
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 79 "scan-skel.l"
+fprintf (skel_out, "%d", out_lineno + 1);
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 80 "scan-skel.l"
+fputs (quotearg_style (c_quoting_style, out_name), skel_out);
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 82 "scan-skel.l"
+at_init (&argc, argv, &at_ptr, &at_basename);
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 83 "scan-skel.l"
+at_init (&argc, argv, &at_ptr, &at_complain);
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 84 "scan-skel.l"
+at_init (&argc, argv, &at_ptr, &at_output);
+ YY_BREAK
+/* This pattern must not match more than the previous @ patterns. */
+case 12:
+YY_RULE_SETUP
+#line 87 "scan-skel.l"
+fail_for_invalid_at (skel_text);
+ YY_BREAK
+case 13:
+/* rule 13 can match eol */
+YY_RULE_SETUP
+#line 88 "scan-skel.l"
+out_lineno++; ECHO;
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 89 "scan-skel.l"
+ECHO;
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+#line 91 "scan-skel.l"
+{
+ if (out_name)
+ {
+ free (out_name);
+ xfclose (skel_out);
+ }
+ return EOF;
+}
+ YY_BREAK
+
+
+case 15:
+/* rule 15 can match eol */
+YY_RULE_SETUP
+#line 102 "scan-skel.l"
+STRING_GROW;
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 104 "scan-skel.l"
+obstack_1grow (&obstack_for_string, '@');
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 105 "scan-skel.l"
+obstack_1grow (&obstack_for_string, '[');
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 106 "scan-skel.l"
+obstack_1grow (&obstack_for_string, ']');
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 107 "scan-skel.l"
+continue; /* For starting an argument that begins with whitespace. */
+ YY_BREAK
+case 20:
+/* rule 20 can match eol */
+YY_RULE_SETUP
+#line 108 "scan-skel.l"
+continue;
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 110 "scan-skel.l"
+{
+ if (argc >= ARGC_MAX)
+ fail_for_at_directive_too_many_args (argv[0]);
+
+ argv[argc++] = obstack_finish0 (&obstack_for_string);
+
+ /* Like M4, skip whitespace after a comma. */
+ if (skel_text[1] == ',')
+ BEGIN SC_AT_DIRECTIVE_SKIP_WS;
+ else
+ {
+ aver (at_ptr);
+ at_ptr (argc, argv, &out_name, &out_lineno);
+ obstack_free (&obstack_for_string, argv[0]);
+ argc = 0;
+ BEGIN INITIAL;
+ }
+ }
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 129 "scan-skel.l"
+fail_for_invalid_at (skel_text);
+ YY_BREAK
+
+
+
+case 23:
+/* rule 23 can match eol */
+YY_RULE_SETUP
+#line 134 "scan-skel.l"
+continue;
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 135 "scan-skel.l"
+yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS;
+ YY_BREAK
+
+
+
+case YY_STATE_EOF(SC_AT_DIRECTIVE_ARGS):
+case YY_STATE_EOF(SC_AT_DIRECTIVE_SKIP_WS):
+#line 140 "scan-skel.l"
+complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]);
+ YY_BREAK
+
+case 25:
+YY_RULE_SETUP
+#line 143 "scan-skel.l"
+YY_FATAL_ERROR( "flex scanner jammed" );
+ YY_BREAK
+#line 1217 "lex.yy.c"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed skel_in at a new source and called
+ * skel_lex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = skel_in;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( skel_wrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * skel_text, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of skel_lex */
+/* %ok-for-header */
+
+/* %if-c++-only */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %endif */
+
+/* yy_get_next_buffer - try to read in a new buffer
*
- * @return the allocated buffer state.
- */
-/* %if-c-only */
- YY_BUFFER_STATE skel__create_buffer (FILE * file, int size )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (char *) skel_alloc(b->yy_buf_size + 2 );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
-
- b->yy_is_our_buffer = 1;
-
- skel__init_buffer(b,file );
-
- return b;
-}
-
-/** Destroy the buffer.
- * @param b a buffer created with skel__create_buffer()
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+/* %if-c-only */
+static int yy_get_next_buffer (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ int num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ skel_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), (size_t) num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ skel_restart(skel_in );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) skel_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+/* %if-c-only */
+/* %not-for-header */
+
+ static yy_state_type yy_get_previous_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+/* %% [15.0] code to get the start state into yy_current_state goes here */
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+/* %% [16.0] code to find the next state goes here */
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 72 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
*
- */
-/* %if-c-only */
- void skel__delete_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! b )
- return;
-
- if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
- YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
-
- if ( b->yy_is_our_buffer )
- skel_free((void *) b->yy_ch_buf );
-
- skel_free((void *) b );
-}
-
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
-/* Initializes or reinitializes a buffer.
- * This function is sometimes called more than once on the same buffer,
- * such as during a skel_restart() or at EOF.
- */
-/* %if-c-only */
- static void skel__init_buffer (YY_BUFFER_STATE b, FILE * file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-{
- int oerrno = errno;
-
- skel__flush_buffer(b );
-
- b->yy_input_file = file;
- b->yy_fill_buffer = 1;
-
- /* If b is the current buffer, then skel__init_buffer was _probably_
- * called from skel_restart() or through yy_get_next_buffer.
- * In that case, we don't want to reset the lineno or column.
- */
- if (b != YY_CURRENT_BUFFER){
- b->yy_bs_lineno = 1;
- b->yy_bs_column = 0;
- }
-
-/* %if-c-only */
-
- b->yy_is_interactive = 0;
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
- errno = oerrno;
-}
-
-/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
- * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- *
- */
-/* %if-c-only */
- void skel__flush_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if ( ! b )
- return;
-
- b->yy_n_chars = 0;
-
- /* We always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[0];
-
- b->yy_at_bol = 1;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- if ( b == YY_CURRENT_BUFFER )
- skel__load_buffer_state( );
-}
-
-/* %if-c-or-c++ */
-/** Pushes the new state onto the stack. The new state becomes
- * the current state. This function will allocate the stack
- * if necessary.
- * @param new_buffer The new state.
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+/* %if-c-only */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register int yy_is_jam;
+ /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 72 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 71);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c-only */
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ int offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ skel_restart(skel_in );
+
+ BISON_FALLTHROUGH;
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( skel_wrap( ) )
+ return EOF;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve skel_text */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+/* %% [19.0] update BOL and skel_lineno */
+
+ return c;
+}
+/* %if-c-only */
+#endif /* ifndef YY_NO_INPUT */
+/* %endif */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
*
- */
-/* %if-c-only */
-void skel_push_buffer_state (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (new_buffer == NULL)
- return;
-
- skel_ensure_buffer_stack();
-
- /* This block is copied from skel__switch_to_buffer. */
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- /* Only push if top exists. Otherwise, replace top. */
- if (YY_CURRENT_BUFFER)
- (yy_buffer_stack_top)++;
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
-
- /* copied from skel__switch_to_buffer. */
- skel__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/** Removes and deletes the top of the stack, if present.
- * The next element becomes the new top.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+/* %if-c-only */
+ void skel_restart (FILE * input_file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ skel_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ skel__create_buffer(skel_in,YY_BUF_SIZE );
+ }
+
+ skel__init_buffer(YY_CURRENT_BUFFER,input_file );
+ skel__load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+/* %if-c-only */
+ void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * skel_pop_buffer_state();
+ * skel_push_buffer_state(new_buffer);
+ */
+ skel_ensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ skel__load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (skel_wrap()) processing, but the only time this flag
+ * is looked at is after skel_wrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/* %if-c-only */
+static void skel__load_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ skel_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+/* %if-c-only */
+ YY_BUFFER_STATE skel__create_buffer (FILE * file, int size )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) skel_alloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ skel__init_buffer(b,file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with skel__create_buffer()
+ *
+ */
+/* %if-c-only */
+ void skel__delete_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ skel_free((void *) b->yy_ch_buf );
+
+ skel_free((void *) b );
+}
+
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a skel_restart() or at EOF.
+ */
+/* %if-c-only */
+ static void skel__init_buffer (YY_BUFFER_STATE b, FILE * file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+{
+ int oerrno = errno;
+
+ skel__flush_buffer(b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then skel__init_buffer was _probably_
+ * called from skel_restart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+/* %if-c-only */
+
+ b->yy_is_interactive = 0;
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+/* %if-c-only */
+ void skel__flush_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ skel__load_buffer_state( );
+}
+
+/* %if-c-or-c++ */
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+/* %if-c-only */
+void skel_push_buffer_state (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (new_buffer == NULL)
+ return;
+
+ skel_ensure_buffer_stack();
+
+ /* This block is copied from skel__switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from skel__switch_to_buffer. */
+ skel__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+/* %if-c-only */
+void skel_pop_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ skel__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ skel__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+/* %if-c-only */
+static void skel_ensure_buffer_stack (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ int num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)skel_alloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)skel_realloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE skel__scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ skel__switch_to_buffer(b );
+
+ return b;
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan a string. The next call to skel_lex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
*
- */
-/* %if-c-only */
-void skel_pop_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (!YY_CURRENT_BUFFER)
- return;
-
- skel__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- if ((yy_buffer_stack_top) > 0)
- --(yy_buffer_stack_top);
-
- if (YY_CURRENT_BUFFER) {
- skel__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
- }
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/* Allocates the stack if it does not exist.
- * Guarantees space for at least one push.
- */
-/* %if-c-only */
-static void skel_ensure_buffer_stack (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- int num_to_alloc;
-
- if (!(yy_buffer_stack)) {
-
- /* First allocation is just for 2 elements, since we don't know if this
- * scanner will even need a stack. We use 2 instead of 1 to avoid an
- * immediate realloc on the next call.
- */
- num_to_alloc = 1;
- (yy_buffer_stack) = (struct yy_buffer_state**)skel_alloc
- (num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
-
- memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-
- (yy_buffer_stack_max) = num_to_alloc;
- (yy_buffer_stack_top) = 0;
- return;
- }
-
- if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
-
- /* Increase the buffer to prepare for a possible push. */
- int grow_size = 8 /* arbitrary grow size */;
-
- num_to_alloc = (yy_buffer_stack_max) + grow_size;
- (yy_buffer_stack) = (struct yy_buffer_state**)skel_realloc
- ((yy_buffer_stack),
- num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
-
- /* zero only the new slots.*/
- memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
- (yy_buffer_stack_max) = num_to_alloc;
- }
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan directly from a user-specified character buffer.
- * @param base the character buffer
- * @param size the size in bytes of the character buffer
- *
* @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE skel__scan_buffer (char * base, yy_size_t size )
-{
- YY_BUFFER_STATE b;
-
- if ( size < 2 ||
- base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
- /* They forgot to leave room for the EOB's. */
- return 0;
-
- b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in skel__scan_buffer()" );
-
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
- b->yy_buf_pos = b->yy_ch_buf = base;
- b->yy_is_our_buffer = 0;
- b->yy_input_file = 0;
- b->yy_n_chars = b->yy_buf_size;
- b->yy_is_interactive = 0;
- b->yy_at_bol = 1;
- b->yy_fill_buffer = 0;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- skel__switch_to_buffer(b );
-
- return b;
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan a string. The next call to skel_lex() will
- * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
- *
- * @return the newly allocated buffer state object.
- * @note If you want to scan bytes that may contain NUL values, then use
- * skel__scan_bytes() instead.
- */
-YY_BUFFER_STATE skel__scan_string (yyconst char * yystr )
-{
-
- return skel__scan_bytes(yystr,strlen(yystr) );
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan the given bytes. The next call to skel_lex() will
- * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
- *
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE skel__scan_bytes (yyconst char * yybytes, int _yybytes_len )
-{
- YY_BUFFER_STATE b;
- char *buf;
- yy_size_t n;
- int i;
-
- /* Get memory for full buffer, including space for trailing EOB's. */
- n = _yybytes_len + 2;
- buf = (char *) skel_alloc(n );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in skel__scan_bytes()" );
-
- for ( i = 0; i < _yybytes_len; ++i )
- buf[i] = yybytes[i];
-
- buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
-
- b = skel__scan_buffer(buf,n );
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in skel__scan_bytes()" );
-
- /* It's okay to grow etc. this buffer, and we should throw it
- * away when we're done.
- */
- b->yy_is_our_buffer = 1;
-
- return b;
-}
-/* %endif */
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-/* %if-c-only */
-static void yy_fatal_error (yyconst char* msg )
-{
- (void) fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
-}
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up skel_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- skel_text[skel_leng] = (yy_hold_char); \
- (yy_c_buf_p) = skel_text + yyless_macro_arg; \
- (yy_hold_char) = *(yy_c_buf_p); \
- *(yy_c_buf_p) = '\0'; \
- skel_leng = yyless_macro_arg; \
- } \
- while ( 0 )
-
-/* Accessor methods (get/set functions) to struct members. */
-
-/* %if-c-only */
-/* %if-reentrant */
-/* %endif */
-
-/** Get the current line number.
- *
- */
-int skel_get_lineno (void)
-{
-
- return skel_lineno;
-}
-
-/** Get the input stream.
- *
- */
-FILE *skel_get_in (void)
-{
- return skel_in;
-}
-
-/** Get the output stream.
- *
- */
-FILE *skel_get_out (void)
-{
- return skel_out;
-}
-
-/** Get the length of the current token.
- *
- */
-int skel_get_leng (void)
-{
- return skel_leng;
-}
-
-/** Get the current token.
- *
- */
-
-char *skel_get_text (void)
-{
- return skel_text;
-}
-
-/* %if-reentrant */
-/* %endif */
-
-/** Set the current line number.
- * @param line_number
- *
- */
-void skel_set_lineno (int line_number )
-{
-
- skel_lineno = line_number;
-}
-
-/** Set the input stream. This does not discard the current
- * input buffer.
- * @param in_str A readable stream.
- *
- * @see skel__switch_to_buffer
- */
-void skel_set_in (FILE * in_str )
-{
- skel_in = in_str ;
-}
-
-void skel_set_out (FILE * out_str )
-{
- skel_out = out_str ;
-}
-
-int skel_get_debug (void)
-{
- return skel__flex_debug;
-}
-
-void skel_set_debug (int bdebug )
-{
- skel__flex_debug = bdebug ;
-}
-
-/* %endif */
-
-/* %if-reentrant */
-/* %if-bison-bridge */
-/* %endif */
-/* %endif if-c-only */
-
-/* %if-c-only */
-static int yy_init_globals (void)
-{
- /* Initialization is the same as for the non-reentrant scanner.
- * This function is called from skel_lex_destroy(), so don't allocate here.
- */
-
- (yy_buffer_stack) = 0;
- (yy_buffer_stack_top) = 0;
- (yy_buffer_stack_max) = 0;
- (yy_c_buf_p) = (char *) 0;
- (yy_init) = 0;
- (yy_start) = 0;
-
-/* Defined in main.c */
-#ifdef YY_STDINIT
- skel_in = stdin;
- skel_out = stdout;
-#else
- skel_in = (FILE *) 0;
- skel_out = (FILE *) 0;
-#endif
-
- /* For future reference: Set errno on error, since we are called by
- * skel_lex_init()
- */
- return 0;
-}
-/* %endif */
-
-/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
-/* skel_lex_destroy is for both reentrant and non-reentrant scanners. */
-int skel_lex_destroy (void)
-{
-
- /* Pop the buffer stack, destroying each element. */
- while(YY_CURRENT_BUFFER){
- skel__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- skel_pop_buffer_state();
- }
-
- /* Destroy the stack itself. */
- skel_free((yy_buffer_stack) );
- (yy_buffer_stack) = NULL;
-
- /* Reset the globals. This is important in a non-reentrant scanner so the next time
- * skel_lex() is called, initialization will occur. */
- yy_init_globals( );
-
-/* %if-reentrant */
-/* %endif */
- return 0;
-}
-/* %endif */
-
-/*
- * Internal utility routines.
- */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
-{
- register int i;
- for ( i = 0; i < n; ++i )
- s1[i] = s2[i];
-}
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s )
-{
- register int n;
- for ( n = 0; s[n]; ++n )
- ;
-
- return n;
-}
-#endif
-
-void *skel_alloc (yy_size_t size )
-{
- return (void *) malloc( size );
-}
-
-void *skel_realloc (void * ptr, yy_size_t size )
-{
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- return (void *) realloc( (char *) ptr, size );
-}
-
-void skel_free (void * ptr )
-{
- free( (char *) ptr ); /* see skel_realloc() for (char *) cast */
-}
-
-/* %if-tables-serialization definitions */
-/* %define-yytables The name for this specific scanner's tables. */
-#define YYTABLES_NAME "yytables"
-/* %endif */
-
-/* %ok-for-header */
-
-#line 143 "scan-skel.l"
-
-
-
-static void
-at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun)
-{
- *at_ptr = fun;
- skel_text[skel_leng-1] = '\0';
- obstack_grow (&obstack_for_string, skel_text, skel_leng);
- argv[(*argc)++] = obstack_finish (&obstack_for_string);
- BEGIN SC_AT_DIRECTIVE_ARGS;
-}
-
-/*------------------------.
-| Scan a Bison skeleton. |
-`------------------------*/
-
-void
-scan_skel (FILE *in)
-{
- static bool initialized = false;
- if (!initialized)
- {
- initialized = true;
- obstack_init (&obstack_for_string);
- }
- skel_in = in;
- skel__flex_debug = trace_flag & trace_skeleton;
- skel_lex ();
-}
-
-void
-skel_scanner_free (void)
-{
- obstack_free (&obstack_for_string, 0);
- /* Reclaim Flex's buffers. */
- skel_lex_destroy ();
-}
-
-static inline warnings
-flag (const char *arg)
-{
- /* compare with values issued from b4_error */
- if (STREQ (arg, "complain"))
- return complaint;
- else if (STREQ (arg, "deprecated"))
- return Wdeprecated;
- else if (STREQ (arg, "fatal"))
- return fatal;
- else if (STREQ (arg, "note"))
- return silent | complaint | no_caret;
- else if (STREQ (arg, "warn"))
- return Wother;
- else
- aver (false);
-}
-
-static void
-at_basename (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- (void) out_namep;
- (void) out_linenop;
- if (2 < argc)
- fail_for_at_directive_too_many_args (argv[0]);
- fputs (last_component (argv[1]), skel_out);
-}
-
-static void
-at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- static unsigned indent;
- warnings w = flag (argv[1]);
- location loc;
- location *locp = NULL;
-
- (void) out_namep;
- (void) out_linenop;
-
- if (argc < 4)
- fail_for_at_directive_too_few_args (argv[0]);
- if (argv[2] && argv[2][0])
- {
- boundary_set_from_string (&loc.start, argv[2]);
- boundary_set_from_string (&loc.end, argv[3]);
- locp = &loc;
- }
- if (w & silent)
- indent += SUB_INDENT;
- else
- indent = 0;
- complain_args (locp, w, &indent, argc - 4, argv + 4);
- if (w & silent)
- indent -= SUB_INDENT;
-}
-
-static void
-at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- if (2 < argc)
- fail_for_at_directive_too_many_args (argv[0]);
- if (*out_namep)
- {
- free (*out_namep);
- xfclose (skel_out);
- }
- *out_namep = xstrdup (argv[1]);
- output_file_name_check (out_namep);
- skel_out = xfopen (*out_namep, "wb");
- *out_linenop = 1;
-}
-
-static void
-fail_for_at_directive_too_few_args (char const *at_directive_name)
-{
- complain (NULL, fatal, _("too few arguments for %s directive in skeleton"),
- at_directive_name);
-}
-
-static void
-fail_for_at_directive_too_many_args (char const *at_directive_name)
-{
- complain (NULL, fatal, _("too many arguments for %s directive in skeleton"),
- at_directive_name);
-}
-
-static void
-fail_for_invalid_at (char const *at)
-{
- complain (NULL, fatal, "invalid @ in skeleton: %s", at);
-}
-
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * skel__scan_bytes() instead.
+ */
+YY_BUFFER_STATE skel__scan_string (yyconst char * yystr )
+{
+
+ return skel__scan_bytes(yystr,strlen(yystr) );
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan the given bytes. The next call to skel_lex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE skel__scan_bytes (yyconst char * yybytes, int _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) skel_alloc(n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = skel__scan_buffer(buf,n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in skel__scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+/* %endif */
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+/* %if-c-only */
+static void yy_fatal_error (yyconst char* msg )
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up skel_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ skel_text[skel_leng] = (yy_hold_char); \
+ (yy_c_buf_p) = skel_text + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ skel_leng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/* %if-c-only */
+/* %if-reentrant */
+/* %endif */
+
+/** Get the current line number.
+ *
+ */
+int skel_get_lineno (void)
+{
+
+ return skel_lineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *skel_get_in (void)
+{
+ return skel_in;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *skel_get_out (void)
+{
+ return skel_out;
+}
+
+/** Get the length of the current token.
+ *
+ */
+int skel_get_leng (void)
+{
+ return skel_leng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *skel_get_text (void)
+{
+ return skel_text;
+}
+
+/* %if-reentrant */
+/* %endif */
+
+/** Set the current line number.
+ * @param line_number
+ *
+ */
+void skel_set_lineno (int line_number )
+{
+
+ skel_lineno = line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ *
+ * @see skel__switch_to_buffer
+ */
+void skel_set_in (FILE * in_str )
+{
+ skel_in = in_str ;
+}
+
+void skel_set_out (FILE * out_str )
+{
+ skel_out = out_str ;
+}
+
+int skel_get_debug (void)
+{
+ return skel__flex_debug;
+}
+
+void skel_set_debug (int bdebug )
+{
+ skel__flex_debug = bdebug ;
+}
+
+/* %endif */
+
+/* %if-reentrant */
+/* %if-bison-bridge */
+/* %endif */
+/* %endif if-c-only */
+
+/* %if-c-only */
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from skel_lex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = 0;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = (char *) 0;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ skel_in = stdin;
+ skel_out = stdout;
+#else
+ skel_in = (FILE *) 0;
+ skel_out = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * skel_lex_init()
+ */
+ return 0;
+}
+/* %endif */
+
+/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
+/* skel_lex_destroy is for both reentrant and non-reentrant scanners. */
+int skel_lex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ skel__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ skel_pop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ skel_free((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * skel_lex() is called, initialization will occur. */
+ yy_init_globals( );
+
+/* %if-reentrant */
+/* %endif */
+ return 0;
+}
+/* %endif */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *skel_alloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *skel_realloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void skel_free (void * ptr )
+{
+ free( (char *) ptr ); /* see skel_realloc() for (char *) cast */
+}
+
+/* %if-tables-serialization definitions */
+/* %define-yytables The name for this specific scanner's tables. */
+#define YYTABLES_NAME "yytables"
+/* %endif */
+
+/* %ok-for-header */
+
+#line 143 "scan-skel.l"
+
+
+
+static void
+at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun)
+{
+ *at_ptr = fun;
+ skel_text[skel_leng-1] = '\0';
+ obstack_grow (&obstack_for_string, skel_text, skel_leng);
+ argv[(*argc)++] = obstack_finish (&obstack_for_string);
+ BEGIN SC_AT_DIRECTIVE_ARGS;
+}
+
+/*------------------------.
+| Scan a Bison skeleton. |
+`------------------------*/
+
+void
+scan_skel (FILE *in)
+{
+ static bool initialized = false;
+ if (!initialized)
+ {
+ initialized = true;
+ obstack_init (&obstack_for_string);
+ }
+ skel_in = in;
+ skel__flex_debug = trace_flag & trace_skeleton;
+ skel_lex ();
+}
+
+void
+skel_scanner_free (void)
+{
+ obstack_free (&obstack_for_string, 0);
+ /* Reclaim Flex's buffers. */
+ skel_lex_destroy ();
+}
+
+static inline warnings
+flag (const char *arg)
+{
+ /* compare with values issued from b4_error */
+ if (STREQ (arg, "complain"))
+ return complaint;
+ else if (STREQ (arg, "deprecated"))
+ return Wdeprecated;
+ else if (STREQ (arg, "fatal"))
+ return fatal;
+ else if (STREQ (arg, "note"))
+ return silent | complaint | no_caret;
+ else if (STREQ (arg, "warn"))
+ return Wother;
+ else
+ aver (false);
+}
+
+static void
+at_basename (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ (void) out_namep;
+ (void) out_linenop;
+ if (2 < argc)
+ fail_for_at_directive_too_many_args (argv[0]);
+ fputs (last_component (argv[1]), skel_out);
+}
+
+static void
+at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ static unsigned indent;
+ warnings w = flag (argv[1]);
+ location loc;
+ location *locp = NULL;
+
+ (void) out_namep;
+ (void) out_linenop;
+
+ if (argc < 4)
+ fail_for_at_directive_too_few_args (argv[0]);
+ if (argv[2] && argv[2][0])
+ {
+ boundary_set_from_string (&loc.start, argv[2]);
+ boundary_set_from_string (&loc.end, argv[3]);
+ locp = &loc;
+ }
+ if (w & silent)
+ indent += SUB_INDENT;
+ else
+ indent = 0;
+ complain_args (locp, w, &indent, argc - 4, argv + 4);
+ if (w & silent)
+ indent -= SUB_INDENT;
+}
+
+static void
+at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ if (2 < argc)
+ fail_for_at_directive_too_many_args (argv[0]);
+ if (*out_namep)
+ {
+ free (*out_namep);
+ xfclose (skel_out);
+ }
+ *out_namep = xstrdup (argv[1]);
+ output_file_name_check (out_namep);
+ skel_out = xfopen (*out_namep, "wb");
+ *out_linenop = 1;
+}
+
+static void
+fail_for_at_directive_too_few_args (char const *at_directive_name)
+{
+ complain (NULL, fatal, _("too few arguments for %s directive in skeleton"),
+ at_directive_name);
+}
+
+static void
+fail_for_at_directive_too_many_args (char const *at_directive_name)
+{
+ complain (NULL, fatal, _("too many arguments for %s directive in skeleton"),
+ at_directive_name);
+}
+
+static void
+fail_for_invalid_at (char const *at)
+{
+ complain (NULL, fatal, "invalid @ in skeleton: %s", at);
+}
+
diff --git a/contrib/tools/bison/bison/src/scan-skel.c.saved b/contrib/tools/bison/bison/src/scan-skel.c.saved
index 88c66c1778..a0d9d135d2 100644
--- a/contrib/tools/bison/bison/src/scan-skel.c.saved
+++ b/contrib/tools/bison/bison/src/scan-skel.c.saved
@@ -1,2409 +1,2409 @@
-#line 2 "src/scan-skel.c"
-
-#line 4 "src/scan-skel.c"
-
-#define YY_INT_ALIGNED short int
-
-/* A lexical scanner generated by flex */
-
-/* %not-for-header */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-#define yy_create_buffer skel__create_buffer
-#define yy_delete_buffer skel__delete_buffer
-#define yy_flex_debug skel__flex_debug
-#define yy_init_buffer skel__init_buffer
-#define yy_flush_buffer skel__flush_buffer
-#define yy_load_buffer_state skel__load_buffer_state
-#define yy_switch_to_buffer skel__switch_to_buffer
-#define yyin skel_in
-#define yyleng skel_leng
-#define yylex skel_lex
-#define yylineno skel_lineno
-#define yyout skel_out
-#define yyrestart skel_restart
-#define yytext skel_text
-#define yywrap skel_wrap
-#define yyalloc skel_alloc
-#define yyrealloc skel_realloc
-#define yyfree skel_free
-
-/* %endif */
-/* %endif */
-/* %ok-for-header */
-
-#define FLEX_SCANNER
-#define YY_FLEX_MAJOR_VERSION 2
-#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 37
-#if YY_FLEX_SUBMINOR_VERSION > 0
-#define FLEX_BETA
-#endif
-
-/* %if-c++-only */
-/* %endif */
-
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c-only */
-
-/* %endif */
-
-/* First, we deal with platform-specific or compiler-specific issues. */
-
-/* begin standard C headers. */
-/* %if-c-only */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-
-/* %endif */
-
-/* %if-tables-serialization */
-/* %endif */
-/* end standard C headers. */
-
-/* %if-c-or-c++ */
-/* flex integer type definitions */
-
-#ifndef FLEXINT_H
-#define FLEXINT_H
-
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
-
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-
-/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types.
- */
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS 1
-#endif
-
-#include <inttypes.h>
-typedef int8_t flex_int8_t;
-typedef uint8_t flex_uint8_t;
-typedef int16_t flex_int16_t;
-typedef uint16_t flex_uint16_t;
-typedef int32_t flex_int32_t;
-typedef uint32_t flex_uint32_t;
-#else
-typedef signed char flex_int8_t;
-typedef short int flex_int16_t;
-typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
-typedef unsigned short int flex_uint16_t;
-typedef unsigned int flex_uint32_t;
-
-/* Limits of integral types. */
-#ifndef INT8_MIN
-#define INT8_MIN (-128)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN (-32767-1)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN (-2147483647-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX (127)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX (32767)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX (2147483647)
-#endif
-#ifndef UINT8_MAX
-#define UINT8_MAX (255U)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX (65535U)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX (4294967295U)
-#endif
-
-#endif /* ! C99 */
-
-#endif /* ! FLEXINT_H */
-
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
-#ifdef __cplusplus
-
-/* The "const" storage-class-modifier is valid. */
-#define YY_USE_CONST
-
-#else /* ! __cplusplus */
-
-/* C99 requires __STDC__ to be defined as 1. */
-#if defined (__STDC__)
-
-#define YY_USE_CONST
-
-#endif /* defined (__STDC__) */
-#endif /* ! __cplusplus */
-
-#ifdef YY_USE_CONST
-#define yyconst const
-#else
-#define yyconst
-#endif
-
-/* %not-for-header */
-
-/* Returned upon end-of-file. */
-#define YY_NULL 0
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* Promotes a possibly negative, possibly signed char to an unsigned
- * integer for use as an array index. If the signed char is negative,
- * we want to instead treat it as an 8-bit unsigned char, hence the
- * double cast.
- */
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
-/* %ok-for-header */
-
-/* %if-reentrant */
-/* %endif */
-
-/* %if-not-reentrant */
-
-/* %endif */
-
-/* Enter a start condition. This macro really ought to take a parameter,
- * but we do it the disgusting crufty way forced on us by the ()-less
- * definition of BEGIN.
- */
-#define BEGIN (yy_start) = 1 + 2 *
-
-/* Translate the current start state into a value that can be later handed
- * to BEGIN to return to the state. The YYSTATE alias is for lex
- * compatibility.
- */
-#define YY_START (((yy_start) - 1) / 2)
-#define YYSTATE YY_START
-
-/* Action number for EOF rule of a given start state. */
-#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
-
-/* Special action meaning "start processing a new file". */
-#define YY_NEW_FILE skel_restart(skel_in )
-
-#define YY_END_OF_BUFFER_CHAR 0
-
-/* Size of default input buffer. */
-#ifndef YY_BUF_SIZE
-#define YY_BUF_SIZE 16384
-#endif
-
-/* The state buf must be large enough to hold one state per character in the main buffer.
- */
-#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
-
-#ifndef YY_TYPEDEF_YY_BUFFER_STATE
-#define YY_TYPEDEF_YY_BUFFER_STATE
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-#endif
-
-#ifndef YY_TYPEDEF_YY_SIZE_T
-#define YY_TYPEDEF_YY_SIZE_T
-typedef size_t yy_size_t;
-#endif
-
-/* %if-not-reentrant */
-extern yy_size_t skel_leng;
-/* %endif */
-
-/* %if-c-only */
-/* %if-not-reentrant */
-extern FILE *skel_in, *skel_out;
-/* %endif */
-/* %endif */
-
-#define EOB_ACT_CONTINUE_SCAN 0
-#define EOB_ACT_END_OF_FILE 1
-#define EOB_ACT_LAST_MATCH 2
-
- #define YY_LESS_LINENO(n)
-
-/* Return all but the first "n" matched characters back to the input stream. */
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up skel_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- *yy_cp = (yy_hold_char); \
- YY_RESTORE_YY_MORE_OFFSET \
- (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
- YY_DO_BEFORE_ACTION; /* set up skel_text again */ \
- } \
- while ( 0 )
-
-#define unput(c) yyunput( c, (yytext_ptr) )
-
-#ifndef YY_STRUCT_YY_BUFFER_STATE
-#define YY_STRUCT_YY_BUFFER_STATE
-struct yy_buffer_state
- {
-/* %if-c-only */
- FILE *yy_input_file;
-/* %endif */
-
-/* %if-c++-only */
-/* %endif */
-
- char *yy_ch_buf; /* input buffer */
- char *yy_buf_pos; /* current position in input buffer */
-
- /* Size of input buffer in bytes, not including room for EOB
- * characters.
- */
- yy_size_t yy_buf_size;
-
- /* Number of characters read into yy_ch_buf, not including EOB
- * characters.
- */
- yy_size_t yy_n_chars;
-
- /* Whether we "own" the buffer - i.e., we know we created it,
- * and can realloc() it to grow it, and should free() it to
- * delete it.
- */
- int yy_is_our_buffer;
-
- /* Whether this is an "interactive" input source; if so, and
- * if we're using stdio for input, then we want to use getc()
- * instead of fread(), to make sure we stop fetching input after
- * each newline.
- */
- int yy_is_interactive;
-
- /* Whether we're considered to be at the beginning of a line.
- * If so, '^' rules will be active on the next match, otherwise
- * not.
- */
- int yy_at_bol;
-
- int yy_bs_lineno; /**< The line count. */
- int yy_bs_column; /**< The column count. */
-
- /* Whether to try to fill the input buffer when we reach the
- * end of it.
- */
- int yy_fill_buffer;
-
- int yy_buffer_status;
-
-#define YY_BUFFER_NEW 0
-#define YY_BUFFER_NORMAL 1
- /* When an EOF's been seen but there's still some text to process
- * then we mark the buffer as YY_EOF_PENDING, to indicate that we
- * shouldn't try reading from the input source any more. We might
- * still have a bunch of tokens to match, though, because of
- * possible backing-up.
- *
- * When we actually see the EOF, we change the status to "new"
- * (via skel_restart()), so that the user can continue scanning by
- * just pointing skel_in at a new input file.
- */
-#define YY_BUFFER_EOF_PENDING 2
-
- };
-#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-/* %if-not-reentrant */
-
-/* Stack of input buffers. */
-static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
-static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
-static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
-/* %endif */
-/* %ok-for-header */
-
-/* %endif */
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
- ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
- : NULL)
-
-/* Same as previous macro, but useful when we know that the buffer stack is not
- * NULL or when we need an lvalue. For internal use only.
- */
-#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
-
-/* %if-c-only Standard (non-C++) definition */
-
-/* %if-not-reentrant */
-/* %not-for-header */
-
-/* yy_hold_char holds the character lost when skel_text is formed. */
-static char yy_hold_char;
-static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
-yy_size_t skel_leng;
-
-/* Points to current character in buffer. */
-static char *yy_c_buf_p = (char *) 0;
-static int yy_init = 0; /* whether we need to initialize */
-static int yy_start = 0; /* start state number */
-
-/* Flag which is used to allow skel_wrap()'s to do buffer switches
- * instead of setting up a fresh skel_in. A bit of a hack ...
- */
-static int yy_did_buffer_switch_on_eof;
-/* %ok-for-header */
-
-/* %endif */
-
-void skel_restart (FILE *input_file );
-void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer );
-YY_BUFFER_STATE skel__create_buffer (FILE *file,int size );
-void skel__delete_buffer (YY_BUFFER_STATE b );
-void skel__flush_buffer (YY_BUFFER_STATE b );
-void skel_push_buffer_state (YY_BUFFER_STATE new_buffer );
-void skel_pop_buffer_state (void );
-
-static void skel_ensure_buffer_stack (void );
-static void skel__load_buffer_state (void );
-static void skel__init_buffer (YY_BUFFER_STATE b,FILE *file );
-
-#define YY_FLUSH_BUFFER skel__flush_buffer(YY_CURRENT_BUFFER )
-
-YY_BUFFER_STATE skel__scan_buffer (char *base,yy_size_t size );
-YY_BUFFER_STATE skel__scan_string (yyconst char *yy_str );
-YY_BUFFER_STATE skel__scan_bytes (yyconst char *bytes,yy_size_t len );
-
-/* %endif */
-
-void *skel_alloc (yy_size_t );
-void *skel_realloc (void *,yy_size_t );
-void skel_free (void * );
-
-#define yy_new_buffer skel__create_buffer
-
-#define yy_set_interactive(is_interactive) \
- { \
- if ( ! YY_CURRENT_BUFFER ){ \
- skel_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- skel__create_buffer(skel_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
- }
-
-#define yy_set_bol(at_bol) \
- { \
- if ( ! YY_CURRENT_BUFFER ){\
- skel_ensure_buffer_stack (); \
- YY_CURRENT_BUFFER_LVALUE = \
- skel__create_buffer(skel_in,YY_BUF_SIZE ); \
- } \
- YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
- }
-
-#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
-
-/* %% [1.0] skel_text/skel_in/skel_out/yy_state_type/skel_lineno etc. def's & init go here */
-/* Begin user sect3 */
-
-#define skel_wrap() 1
-#define YY_SKIP_YYWRAP
-
-#define FLEX_DEBUG
-
-typedef unsigned char YY_CHAR;
-
-FILE *skel_in = (FILE *) 0, *skel_out = (FILE *) 0;
-
-typedef int yy_state_type;
-
-extern int skel_lineno;
-
-int skel_lineno = 1;
-
-extern char *skel_text;
-#define yytext_ptr skel_text
-
-/* %if-c-only Standard (non-C++) definition */
-
-static yy_state_type yy_get_previous_state (void );
-static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
-static int yy_get_next_buffer (void );
-static void yy_fatal_error (yyconst char msg[] );
-
-/* %endif */
-
-/* Done after the current pattern has been matched and before the
- * corresponding action - sets up skel_text.
- */
-#define YY_DO_BEFORE_ACTION \
- (yytext_ptr) = yy_bp; \
-/* %% [2.0] code to fiddle skel_text and skel_leng for yymore() goes here \ */\
- skel_leng = (size_t) (yy_cp - yy_bp); \
- (yy_hold_char) = *yy_cp; \
- *yy_cp = '\0'; \
-/* %% [3.0] code to copy yytext_ptr to skel_text[] goes here, if %array \ */\
- (yy_c_buf_p) = yy_cp;
-
-/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
-#define YY_NUM_RULES 24
-#define YY_END_OF_BUFFER 25
-/* This struct is not used in this scanner,
- but its presence is necessary. */
-struct yy_trans_info
- {
- flex_int32_t yy_verify;
- flex_int32_t yy_nxt;
- };
-static yyconst flex_int16_t yy_accept[67] =
- { 0,
- 0, 0, 0, 0, 0, 0, 25, 13, 12, 11,
- 14, 21, 23, 22, 22, 13, 11, 5, 4, 1,
- 11, 11, 11, 2, 3, 14, 21, 19, 18, 20,
- 15, 16, 17, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 7, 6, 11, 11, 11,
- 10, 11, 11, 8, 9, 0
- } ;
-
-static yyconst flex_int32_t yy_ec[256] =
- { 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
- 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 1, 1, 1, 1, 1, 4, 5,
- 6, 1, 1, 6, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 7, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 8, 9, 10, 1,
-
- 11, 12, 1, 1, 13, 1, 1, 14, 15, 16,
- 17, 18, 1, 1, 19, 20, 21, 1, 1, 1,
- 1, 1, 22, 1, 23, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
- } ;
-
-static yyconst flex_int32_t yy_meta[24] =
- { 0,
- 1, 1, 2, 1, 3, 1, 4, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1
- } ;
-
-static yyconst flex_int16_t yy_base[74] =
- { 0,
- 0, 1, 55, 54, 3, 7, 60, 0, 100, 8,
- 0, 29, 100, 100, 100, 0, 50, 100, 100, 100,
- 51, 41, 2, 100, 100, 0, 100, 100, 100, 100,
- 100, 100, 100, 37, 40, 37, 36, 28, 36, 28,
- 31, 28, 25, 26, 27, 29, 28, 17, 29, 26,
- 22, 21, 7, 11, 11, 100, 100, 17, 10, 4,
- 100, 14, 8, 100, 100, 100, 73, 77, 81, 85,
- 88, 92, 95
- } ;
-
-static yyconst flex_int16_t yy_def[74] =
- { 0,
- 67, 67, 68, 68, 69, 69, 66, 70, 66, 71,
- 72, 73, 66, 66, 66, 70, 71, 66, 66, 66,
- 17, 17, 17, 66, 66, 72, 66, 66, 66, 66,
- 66, 66, 66, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 66, 66, 17, 17, 17,
- 66, 17, 17, 66, 66, 0, 66, 66, 66, 66,
- 66, 66, 66
- } ;
-
-static yyconst flex_int16_t yy_nxt[124] =
- { 0,
- 66, 66, 9, 9, 14, 15, 10, 10, 14, 15,
- 18, 19, 65, 36, 20, 37, 21, 22, 64, 63,
- 62, 61, 38, 60, 23, 59, 58, 57, 56, 24,
- 25, 28, 29, 55, 30, 31, 54, 53, 52, 51,
- 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
- 32, 33, 66, 66, 40, 39, 66, 35, 34, 66,
- 12, 12, 66, 66, 66, 66, 66, 66, 66, 66,
- 66, 66, 66, 8, 8, 8, 8, 11, 11, 11,
- 11, 13, 13, 13, 13, 16, 66, 16, 17, 17,
- 66, 17, 26, 26, 26, 27, 27, 27, 27, 7,
-
- 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
- 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
- 66, 66, 66
- } ;
-
-static yyconst flex_int16_t yy_chk[124] =
- { 0,
- 0, 0, 1, 2, 5, 5, 1, 2, 6, 6,
- 10, 10, 63, 23, 10, 23, 10, 10, 62, 60,
- 59, 58, 23, 55, 10, 54, 53, 52, 51, 10,
- 10, 12, 12, 50, 12, 12, 49, 48, 47, 46,
- 45, 44, 43, 42, 41, 40, 39, 38, 37, 36,
- 12, 12, 17, 17, 35, 34, 17, 22, 21, 7,
- 4, 3, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 17, 17, 67, 67, 67, 67, 68, 68, 68,
- 68, 69, 69, 69, 69, 70, 0, 70, 71, 71,
- 0, 71, 72, 72, 72, 73, 73, 73, 73, 66,
-
- 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
- 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
- 66, 66, 66
- } ;
-
-static yy_state_type yy_last_accepting_state;
-static char *yy_last_accepting_cpos;
-
-extern int skel__flex_debug;
-int skel__flex_debug = 1;
-
-static yyconst flex_int16_t yy_rule_linenum[24] =
- { 0,
- 72, 73, 74, 75, 76, 78, 79, 81, 82, 83,
- 86, 87, 88, 101, 103, 104, 105, 106, 107, 109,
- 128, 133, 134
- } ;
-
-/* The intent behind this definition is that it'll catch
- * any uses of REJECT which flex missed.
- */
-#define REJECT reject_used_but_not_detected
-#define yymore() yymore_used_but_not_detected
-#define YY_MORE_ADJ 0
-#define YY_RESTORE_YY_MORE_OFFSET
-char *skel_text;
-#line 1 "../../src/scan-skel.l"
-/* Scan Bison Skeletons. -*- C -*-
-
- Copyright (C) 2001-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#define YY_NO_INPUT 1
-#line 24 "../../src/scan-skel.l"
-/* Work around a bug in flex 2.5.31. See Debian bug 333231
- <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
-#undef skel_wrap
-#define skel_wrap() 1
-
-#define FLEX_PREFIX(Id) skel_ ## Id
-#include <src/flex-scanner.h>
-
-#include <dirname.h>
-#include <error.h>
-#include <quotearg.h>
-
-#include <src/complain.h>
-#include <src/getargs.h>
-#include <src/files.h>
-#include <src/scan-skel.h>
-
-#include "uniqstr.h"
-
-#define YY_DECL static int skel_lex (void)
-YY_DECL;
-
-typedef void (*at_directive)(int, char**, char **, int*);
-static void at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun);
-static void at_basename (int argc, char *argv[], char**, int*);
-static void at_complain (int argc, char *argv[], char**, int*);
-static void at_output (int argc, char *argv[], char **name, int *lineno);
-static void fail_for_at_directive_too_many_args (char const *at_directive_name);
-static void fail_for_at_directive_too_few_args (char const *at_directive_name);
-static void fail_for_invalid_at (char const *at);
-
-
-#line 660 "src/scan-skel.c"
-
-#define INITIAL 0
-#define SC_AT_DIRECTIVE_ARGS 1
-#define SC_AT_DIRECTIVE_SKIP_WS 2
-
-#ifndef YY_NO_UNISTD_H
-/* Special case for "unistd.h", since it is non-ANSI. We include it way
- * down here because we want the user's section 1 to have been scanned first.
- * The user has a chance to override it with an option.
- */
-/* %if-c-only */
-#include <unistd.h>
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-#ifndef YY_EXTRA_TYPE
-#define YY_EXTRA_TYPE void *
-#endif
-
-/* %if-c-only Reentrant structure and macros (non-C++). */
-/* %if-reentrant */
-/* %if-c-only */
-
-static int yy_init_globals (void );
-
-/* %endif */
-/* %if-reentrant */
-/* %endif */
-/* %endif End reentrant structures and macros. */
-
-/* Accessor methods to globals.
- These are made visible to non-reentrant scanners for convenience. */
-
-int skel_lex_destroy (void );
-
-int skel_get_debug (void );
-
-void skel_set_debug (int debug_flag );
-
-YY_EXTRA_TYPE skel_get_extra (void );
-
-void skel_set_extra (YY_EXTRA_TYPE user_defined );
-
-FILE *skel_get_in (void );
-
-void skel_set_in (FILE * in_str );
-
-FILE *skel_get_out (void );
-
-void skel_set_out (FILE * out_str );
-
-yy_size_t skel_get_leng (void );
-
-char *skel_get_text (void );
-
-int skel_get_lineno (void );
-
-void skel_set_lineno (int line_number );
-
-/* %if-bison-bridge */
-/* %endif */
-
-/* Macros after this point can all be overridden by user definitions in
- * section 1.
- */
-
-#ifndef YY_SKIP_YYWRAP
-#ifdef __cplusplus
-extern "C" int skel_wrap (void );
-#else
-extern int skel_wrap (void );
-#endif
-#endif
-
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %endif */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int );
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * );
-#endif
-
-#ifndef YY_NO_INPUT
-/* %if-c-only Standard (non-C++) definition */
-/* %not-for-header */
-
-#ifdef __cplusplus
-static int yyinput (void );
-#else
-static int input (void );
-#endif
-/* %ok-for-header */
-
-/* %endif */
-#endif
-
-/* %if-c-only */
-
-/* %endif */
-
-/* Amount of stuff to slurp up with each read. */
-#ifndef YY_READ_BUF_SIZE
-#define YY_READ_BUF_SIZE 8192
-#endif
-
-/* Copy whatever the last rule matched to the standard output. */
-#ifndef ECHO
-/* %if-c-only Standard (non-C++) definition */
-/* This used to be an fputs(), but since the string might contain NUL's,
- * we now use fwrite().
- */
-#define ECHO do { if (fwrite( skel_text, skel_leng, 1, skel_out )) {} } while (0)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif
-
-/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
- * is returned in "result".
- */
-#ifndef YY_INPUT
-#define YY_INPUT(buf,result,max_size) \
-/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
- if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
- { \
- int c = '*'; \
- size_t n; \
- for ( n = 0; n < max_size && \
- (c = getc( skel_in )) != EOF && c != '\n'; ++n ) \
- buf[n] = (char) c; \
- if ( c == '\n' ) \
- buf[n++] = (char) c; \
- if ( c == EOF && ferror( skel_in ) ) \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- result = n; \
- } \
- else \
- { \
- errno=0; \
- while ( (result = fread(buf, 1, max_size, skel_in))==0 && ferror(skel_in)) \
- { \
- if( errno != EINTR) \
- { \
- YY_FATAL_ERROR( "input in flex scanner failed" ); \
- break; \
- } \
- errno=0; \
- clearerr(skel_in); \
- } \
- }\
-\
-/* %if-c++-only C++ definition \ */\
-/* %endif */
-
-#endif
-
-/* No semi-colon after return; correct usage is to write "yyterminate();" -
- * we don't want an extra ';' after the "return" because that will cause
- * some compilers to complain about unreachable statements.
- */
-#ifndef yyterminate
-#define yyterminate() return YY_NULL
-#endif
-
-/* Number of entries by which start-condition stack grows. */
-#ifndef YY_START_STACK_INCR
-#define YY_START_STACK_INCR 25
-#endif
-
-/* Report a fatal error. */
-#ifndef YY_FATAL_ERROR
-/* %if-c-only */
-#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-#endif
-
-/* %if-tables-serialization structures and prototypes */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %not-for-header */
-
-/* %tables-yydmap generated elements */
-/* %endif */
-/* end tables serialization structures and prototypes */
-
-/* %ok-for-header */
-
-/* Default declaration of generated scanner - a define so the user can
- * easily add parameters.
- */
-#ifndef YY_DECL
-#define YY_DECL_IS_OURS 1
-/* %if-c-only Standard (non-C++) definition */
-
-extern int skel_lex (void);
-
-#define YY_DECL int skel_lex (void)
-/* %endif */
-/* %if-c++-only C++ definition */
-/* %endif */
-#endif /* !YY_DECL */
-
-/* Code executed at the beginning of each rule, after skel_text and skel_leng
- * have been set up.
- */
-#ifndef YY_USER_ACTION
-#define YY_USER_ACTION
-#endif
-
-/* Code executed at the end of each rule. */
-#ifndef YY_BREAK
-#define YY_BREAK break;
-#endif
-
-/* %% [6.0] YY_RULE_SETUP definition goes here */
-#define YY_RULE_SETUP \
- YY_USER_ACTION
-
-/* %not-for-header */
-
-/** The main scanner function which does all the work.
- */
-YY_DECL
-{
- register yy_state_type yy_current_state;
- register char *yy_cp, *yy_bp;
- register int yy_act;
-
-/* %% [7.0] user's declarations go here */
-#line 57 "../../src/scan-skel.l"
-
-
-
- int out_lineno PACIFY_CC (= 0);
- char *out_name = NULL;
-
- /* Currently, only the @complain directive takes multiple arguments, and
- never more than 7, with argv[0] being the directive name and argv[1]
- being the type of complaint to dispatch. */
-#define ARGC_MAX 9
- int argc = 0;
- char *argv[ARGC_MAX];
- at_directive at_ptr = NULL;
-
-
-#line 918 "src/scan-skel.c"
-
- if ( !(yy_init) )
- {
- (yy_init) = 1;
-
-#ifdef YY_USER_INIT
- YY_USER_INIT;
-#endif
-
- if ( ! (yy_start) )
- (yy_start) = 1; /* first start state */
-
- if ( ! skel_in )
-/* %if-c-only */
- skel_in = stdin;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! skel_out )
-/* %if-c-only */
- skel_out = stdout;
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
- if ( ! YY_CURRENT_BUFFER ) {
- skel_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- skel__create_buffer(skel_in,YY_BUF_SIZE );
- }
-
- skel__load_buffer_state( );
- }
-
- while ( 1 ) /* loops until end-of-file is reached */
- {
-/* %% [8.0] yymore()-related code goes here */
- yy_cp = (yy_c_buf_p);
-
- /* Support of skel_text. */
- *yy_cp = (yy_hold_char);
-
- /* yy_bp points to the position in yy_ch_buf of the start of
- * the current run.
- */
- yy_bp = yy_cp;
-
-/* %% [9.0] code to set up and find next match goes here */
- yy_current_state = (yy_start);
-yy_match:
- do
- {
- register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 67 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- ++yy_cp;
- }
- while ( yy_current_state != 66 );
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
-
-yy_find_action:
-/* %% [10.0] code to find the action number goes here */
- yy_act = yy_accept[yy_current_state];
-
- YY_DO_BEFORE_ACTION;
-
-/* %% [11.0] code for skel_lineno update goes here */
-
-do_action: /* This label is used only to access EOF actions. */
-
-/* %% [12.0] debug code goes here */
- if ( skel__flex_debug )
- {
- if ( yy_act == 0 )
- fprintf( stderr, "--scanner backing up\n" );
- else if ( yy_act < 24 )
- fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
- (long)yy_rule_linenum[yy_act], skel_text );
- else if ( yy_act == 24 )
- fprintf( stderr, "--accepting default rule (\"%s\")\n",
- skel_text );
- else if ( yy_act == 25 )
- fprintf( stderr, "--(end of buffer or a NUL)\n" );
- else
- fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
- }
-
- switch ( yy_act )
- { /* beginning of action switch */
-/* %% [13.0] actions go here */
- case 0: /* must back up */
- /* undo the effects of YY_DO_BEFORE_ACTION */
- *yy_cp = (yy_hold_char);
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
-
-case 1:
-YY_RULE_SETUP
-#line 72 "../../src/scan-skel.l"
-fputc ('@', skel_out);
- YY_BREAK
-case 2:
-YY_RULE_SETUP
-#line 73 "../../src/scan-skel.l"
-fputc ('[', skel_out);
- YY_BREAK
-case 3:
-YY_RULE_SETUP
-#line 74 "../../src/scan-skel.l"
-fputc (']', skel_out);
- YY_BREAK
-case 4:
-YY_RULE_SETUP
-#line 75 "../../src/scan-skel.l"
-continue; /* Used by b4_cat in ../data/bison.m4. */
- YY_BREAK
-case 5:
-/* rule 5 can match eol */
-YY_RULE_SETUP
-#line 76 "../../src/scan-skel.l"
-continue;
- YY_BREAK
-case 6:
-YY_RULE_SETUP
-#line 78 "../../src/scan-skel.l"
-fprintf (skel_out, "%d", out_lineno + 1);
- YY_BREAK
-case 7:
-YY_RULE_SETUP
-#line 79 "../../src/scan-skel.l"
-fputs (quotearg_style (c_quoting_style, out_name), skel_out);
- YY_BREAK
-case 8:
-YY_RULE_SETUP
-#line 81 "../../src/scan-skel.l"
-at_init (&argc, argv, &at_ptr, &at_basename);
- YY_BREAK
-case 9:
-YY_RULE_SETUP
-#line 82 "../../src/scan-skel.l"
-at_init (&argc, argv, &at_ptr, &at_complain);
- YY_BREAK
-case 10:
-YY_RULE_SETUP
-#line 83 "../../src/scan-skel.l"
-at_init (&argc, argv, &at_ptr, &at_output);
- YY_BREAK
-/* This pattern must not match more than the previous @ patterns. */
-case 11:
-YY_RULE_SETUP
-#line 86 "../../src/scan-skel.l"
-fail_for_invalid_at (skel_text);
- YY_BREAK
-case 12:
-/* rule 12 can match eol */
-YY_RULE_SETUP
-#line 87 "../../src/scan-skel.l"
-out_lineno++; ECHO;
- YY_BREAK
-case 13:
-YY_RULE_SETUP
-#line 88 "../../src/scan-skel.l"
-ECHO;
- YY_BREAK
-case YY_STATE_EOF(INITIAL):
-#line 90 "../../src/scan-skel.l"
-{
- if (out_name)
- {
- free (out_name);
- xfclose (skel_out);
- }
- return EOF;
-}
- YY_BREAK
-
-
-case 14:
-/* rule 14 can match eol */
-YY_RULE_SETUP
-#line 101 "../../src/scan-skel.l"
-STRING_GROW;
- YY_BREAK
-case 15:
-YY_RULE_SETUP
-#line 103 "../../src/scan-skel.l"
-obstack_1grow (&obstack_for_string, '@');
- YY_BREAK
-case 16:
-YY_RULE_SETUP
-#line 104 "../../src/scan-skel.l"
-obstack_1grow (&obstack_for_string, '[');
- YY_BREAK
-case 17:
-YY_RULE_SETUP
-#line 105 "../../src/scan-skel.l"
-obstack_1grow (&obstack_for_string, ']');
- YY_BREAK
-case 18:
-YY_RULE_SETUP
-#line 106 "../../src/scan-skel.l"
-continue; /* For starting an argument that begins with whitespace. */
- YY_BREAK
-case 19:
-/* rule 19 can match eol */
-YY_RULE_SETUP
-#line 107 "../../src/scan-skel.l"
-continue;
- YY_BREAK
-case 20:
-YY_RULE_SETUP
-#line 109 "../../src/scan-skel.l"
-{
- if (argc >= ARGC_MAX)
- fail_for_at_directive_too_many_args (argv[0]);
-
- argv[argc++] = obstack_finish0 (&obstack_for_string);
-
- /* Like M4, skip whitespace after a comma. */
- if (skel_text[1] == ',')
- BEGIN SC_AT_DIRECTIVE_SKIP_WS;
- else
- {
- aver (at_ptr);
- at_ptr (argc, argv, &out_name, &out_lineno);
- obstack_free (&obstack_for_string, argv[0]);
- argc = 0;
- BEGIN INITIAL;
- }
- }
- YY_BREAK
-case 21:
-YY_RULE_SETUP
-#line 128 "../../src/scan-skel.l"
-fail_for_invalid_at (skel_text);
- YY_BREAK
-
-
-
-case 22:
-/* rule 22 can match eol */
-YY_RULE_SETUP
-#line 133 "../../src/scan-skel.l"
-continue;
- YY_BREAK
-case 23:
-YY_RULE_SETUP
-#line 134 "../../src/scan-skel.l"
-yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS;
- YY_BREAK
-
-
-
-case YY_STATE_EOF(SC_AT_DIRECTIVE_ARGS):
-case YY_STATE_EOF(SC_AT_DIRECTIVE_SKIP_WS):
-#line 139 "../../src/scan-skel.l"
-complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]);
- YY_BREAK
-
-case 24:
-YY_RULE_SETUP
-#line 142 "../../src/scan-skel.l"
-YY_FATAL_ERROR( "flex scanner jammed" );
- YY_BREAK
-#line 1196 "src/scan-skel.c"
-
- case YY_END_OF_BUFFER:
- {
- /* Amount of text matched not including the EOB char. */
- int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
-
- /* Undo the effects of YY_DO_BEFORE_ACTION. */
- *yy_cp = (yy_hold_char);
- YY_RESTORE_YY_MORE_OFFSET
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
- {
- /* We're scanning a new file or input source. It's
- * possible that this happened because the user
- * just pointed skel_in at a new source and called
- * skel_lex(). If so, then we have to assure
- * consistency between YY_CURRENT_BUFFER and our
- * globals. Here is the right place to do so, because
- * this is the first action (other than possibly a
- * back-up) that will match for the new input source.
- */
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- YY_CURRENT_BUFFER_LVALUE->yy_input_file = skel_in;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
- }
-
- /* Note that here we test for yy_c_buf_p "<=" to the position
- * of the first EOB in the buffer, since yy_c_buf_p will
- * already have been incremented past the NUL character
- * (since all states make transitions on EOB to the
- * end-of-buffer state). Contrast this with the test
- * in input().
- */
- if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- { /* This was really a NUL. */
- yy_state_type yy_next_state;
-
- (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- /* Okay, we're now positioned to make the NUL
- * transition. We couldn't have
- * yy_get_previous_state() go ahead and do it
- * for us because it doesn't know how to deal
- * with the possibility of jamming (and we don't
- * want to build jamming into it because then it
- * will run more slowly).
- */
-
- yy_next_state = yy_try_NUL_trans( yy_current_state );
-
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
-
- if ( yy_next_state )
- {
- /* Consume the NUL. */
- yy_cp = ++(yy_c_buf_p);
- yy_current_state = yy_next_state;
- goto yy_match;
- }
-
- else
- {
-/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
- yy_cp = (yy_last_accepting_cpos);
- yy_current_state = (yy_last_accepting_state);
- goto yy_find_action;
- }
- }
-
- else switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_END_OF_FILE:
- {
- (yy_did_buffer_switch_on_eof) = 0;
-
- if ( skel_wrap( ) )
- {
- /* Note: because we've taken care in
- * yy_get_next_buffer() to have set up
- * skel_text, we can now set up
- * yy_c_buf_p so that if some total
- * hoser (like flex itself) wants to
- * call the scanner after we return the
- * YY_NULL, it'll still work - another
- * YY_NULL will get returned.
- */
- (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
-
- yy_act = YY_STATE_EOF(YY_START);
- goto do_action;
- }
-
- else
- {
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
- }
- break;
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) =
- (yytext_ptr) + yy_amount_of_matched_text;
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_match;
-
- case EOB_ACT_LAST_MATCH:
- (yy_c_buf_p) =
- &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
-
- yy_current_state = yy_get_previous_state( );
-
- yy_cp = (yy_c_buf_p);
- yy_bp = (yytext_ptr) + YY_MORE_ADJ;
- goto yy_find_action;
- }
- break;
- }
-
- default:
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--no action found" );
- } /* end of action switch */
- } /* end of scanning one token */
-} /* end of skel_lex */
-/* %ok-for-header */
-
-/* %if-c++-only */
-/* %not-for-header */
-
-/* %ok-for-header */
-
-/* %endif */
-
-/* yy_get_next_buffer - try to read in a new buffer
- *
- * Returns a code representing an action:
- * EOB_ACT_LAST_MATCH -
- * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
- * EOB_ACT_END_OF_FILE - end of file
- */
-/* %if-c-only */
-static int yy_get_next_buffer (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
- register char *source = (yytext_ptr);
- register int number_to_move, i;
- int ret_val;
-
- if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
- YY_FATAL_ERROR(
- "fatal flex scanner internal error--end of buffer missed" );
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
- { /* Don't try to fill the buffer, so this is an EOF. */
- if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
- {
- /* We matched a single character, the EOB, so
- * treat this as a final EOF.
- */
- return EOB_ACT_END_OF_FILE;
- }
-
- else
- {
- /* We matched some text prior to the EOB, first
- * process it.
- */
- return EOB_ACT_LAST_MATCH;
- }
- }
-
- /* Try to read more data. */
-
- /* First move last chars to start of buffer. */
- number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
-
- for ( i = 0; i < number_to_move; ++i )
- *(dest++) = *(source++);
-
- if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
- /* don't do the read, it's not guaranteed to return an EOF,
- * just force an EOF
- */
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
-
- else
- {
- yy_size_t num_to_read =
- YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
-
- while ( num_to_read <= 0 )
- { /* Not enough room in the buffer - grow it. */
-
- /* just a shorter name for the current buffer */
- YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
-
- int yy_c_buf_p_offset =
- (int) ((yy_c_buf_p) - b->yy_ch_buf);
-
- if ( b->yy_is_our_buffer )
- {
- yy_size_t new_size = b->yy_buf_size * 2;
-
- if ( new_size <= 0 )
- b->yy_buf_size += b->yy_buf_size / 8;
- else
- b->yy_buf_size *= 2;
-
- b->yy_ch_buf = (char *)
- /* Include room in for 2 EOB chars. */
- skel_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
- }
- else
- /* Can't grow it, we don't own it. */
- b->yy_ch_buf = 0;
-
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR(
- "fatal error - scanner input buffer overflow" );
-
- (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
-
- num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
- number_to_move - 1;
-
- }
-
- if ( num_to_read > YY_READ_BUF_SIZE )
- num_to_read = YY_READ_BUF_SIZE;
-
- /* Read in more data. */
- YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
- (yy_n_chars), num_to_read );
-
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- if ( (yy_n_chars) == 0 )
- {
- if ( number_to_move == YY_MORE_ADJ )
- {
- ret_val = EOB_ACT_END_OF_FILE;
- skel_restart(skel_in );
- }
-
- else
- {
- ret_val = EOB_ACT_LAST_MATCH;
- YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
- YY_BUFFER_EOF_PENDING;
- }
- }
-
- else
- ret_val = EOB_ACT_CONTINUE_SCAN;
-
- if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
- /* Extend the array by 50%, plus the number we really need. */
- yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) skel_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
- if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
- }
-
- (yy_n_chars) += number_to_move;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
-
- (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
-
- return ret_val;
-}
-
-/* yy_get_previous_state - get the state just before the EOB char was reached */
-
-/* %if-c-only */
-/* %not-for-header */
-
- static yy_state_type yy_get_previous_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register yy_state_type yy_current_state;
- register char *yy_cp;
-
-/* %% [15.0] code to get the start state into yy_current_state goes here */
- yy_current_state = (yy_start);
-
- for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
- {
-/* %% [16.0] code to find the next state goes here */
- register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 67 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- }
-
- return yy_current_state;
-}
-
-/* yy_try_NUL_trans - try to make a transition on the NUL character
- *
- * synopsis
- * next_state = yy_try_NUL_trans( current_state );
- */
-/* %if-c-only */
- static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- register int yy_is_jam;
- /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
- register char *yy_cp = (yy_c_buf_p);
-
- register YY_CHAR yy_c = 1;
- if ( yy_accept[yy_current_state] )
- {
- (yy_last_accepting_state) = yy_current_state;
- (yy_last_accepting_cpos) = yy_cp;
- }
- while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
- {
- yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 67 )
- yy_c = yy_meta[(unsigned int) yy_c];
- }
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 66);
-
- return yy_is_jam ? 0 : yy_current_state;
-}
-
-/* %if-c-only */
-
-/* %endif */
-
-/* %if-c-only */
-#ifndef YY_NO_INPUT
-#ifdef __cplusplus
- static int yyinput (void)
-#else
- static int input (void)
-#endif
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- int c;
-
- *(yy_c_buf_p) = (yy_hold_char);
-
- if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
- {
- /* yy_c_buf_p now points to the character we want to return.
- * If this occurs *before* the EOB characters, then it's a
- * valid NUL; if not, then we've hit the end of the buffer.
- */
- if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
- /* This was really a NUL. */
- *(yy_c_buf_p) = '\0';
-
- else
- { /* need more input */
- yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
- ++(yy_c_buf_p);
-
- switch ( yy_get_next_buffer( ) )
- {
- case EOB_ACT_LAST_MATCH:
- /* This happens because yy_g_n_b()
- * sees that we've accumulated a
- * token and flags that we need to
- * try matching the token before
- * proceeding. But for input(),
- * there's no matching to consider.
- * So convert the EOB_ACT_LAST_MATCH
- * to EOB_ACT_END_OF_FILE.
- */
-
- /* Reset buffer status. */
- skel_restart(skel_in );
-
- /*FALLTHROUGH*/
-
- case EOB_ACT_END_OF_FILE:
- {
- if ( skel_wrap( ) )
- return EOF;
-
- if ( ! (yy_did_buffer_switch_on_eof) )
- YY_NEW_FILE;
-#ifdef __cplusplus
- return yyinput();
-#else
- return input();
-#endif
- }
-
- case EOB_ACT_CONTINUE_SCAN:
- (yy_c_buf_p) = (yytext_ptr) + offset;
- break;
- }
- }
- }
-
- c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
- *(yy_c_buf_p) = '\0'; /* preserve skel_text */
- (yy_hold_char) = *++(yy_c_buf_p);
-
-/* %% [19.0] update BOL and skel_lineno */
-
- return c;
-}
-/* %if-c-only */
-#endif /* ifndef YY_NO_INPUT */
-/* %endif */
-
-/** Immediately switch to a different input stream.
- * @param input_file A readable stream.
+#line 2 "src/scan-skel.c"
+
+#line 4 "src/scan-skel.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+/* %not-for-header */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+#define yy_create_buffer skel__create_buffer
+#define yy_delete_buffer skel__delete_buffer
+#define yy_flex_debug skel__flex_debug
+#define yy_init_buffer skel__init_buffer
+#define yy_flush_buffer skel__flush_buffer
+#define yy_load_buffer_state skel__load_buffer_state
+#define yy_switch_to_buffer skel__switch_to_buffer
+#define yyin skel_in
+#define yyleng skel_leng
+#define yylex skel_lex
+#define yylineno skel_lineno
+#define yyout skel_out
+#define yyrestart skel_restart
+#define yytext skel_text
+#define yywrap skel_wrap
+#define yyalloc skel_alloc
+#define yyrealloc skel_realloc
+#define yyfree skel_free
+
+/* %endif */
+/* %endif */
+/* %ok-for-header */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 37
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* %if-c++-only */
+/* %endif */
+
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c-only */
+
+/* %endif */
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+/* %if-c-only */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* %endif */
+
+/* %if-tables-serialization */
+/* %endif */
+/* end standard C headers. */
+
+/* %if-c-or-c++ */
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* %not-for-header */
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+/* %ok-for-header */
+
+/* %if-reentrant */
+/* %endif */
+
+/* %if-not-reentrant */
+
+/* %endif */
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE skel_restart(skel_in )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+/* %if-not-reentrant */
+extern yy_size_t skel_leng;
+/* %endif */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+extern FILE *skel_in, *skel_out;
+/* %endif */
+/* %endif */
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up skel_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up skel_text again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+/* %if-c-only */
+ FILE *yy_input_file;
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ yy_size_t yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via skel_restart()), so that the user can continue scanning by
+ * just pointing skel_in at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+/* %if-not-reentrant */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
+/* %endif */
+/* %ok-for-header */
+
+/* %endif */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
*
- * @note This function does not reset the start condition to @c INITIAL .
- */
-/* %if-c-only */
- void skel_restart (FILE * input_file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! YY_CURRENT_BUFFER ){
- skel_ensure_buffer_stack ();
- YY_CURRENT_BUFFER_LVALUE =
- skel__create_buffer(skel_in,YY_BUF_SIZE );
- }
-
- skel__init_buffer(YY_CURRENT_BUFFER,input_file );
- skel__load_buffer_state( );
-}
-
-/** Switch to a different input buffer.
- * @param new_buffer The new input buffer.
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* %if-c-only Standard (non-C++) definition */
+
+/* %if-not-reentrant */
+/* %not-for-header */
+
+/* yy_hold_char holds the character lost when skel_text is formed. */
+static char yy_hold_char;
+static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
+yy_size_t skel_leng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow skel_wrap()'s to do buffer switches
+ * instead of setting up a fresh skel_in. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+/* %ok-for-header */
+
+/* %endif */
+
+void skel_restart (FILE *input_file );
+void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE skel__create_buffer (FILE *file,int size );
+void skel__delete_buffer (YY_BUFFER_STATE b );
+void skel__flush_buffer (YY_BUFFER_STATE b );
+void skel_push_buffer_state (YY_BUFFER_STATE new_buffer );
+void skel_pop_buffer_state (void );
+
+static void skel_ensure_buffer_stack (void );
+static void skel__load_buffer_state (void );
+static void skel__init_buffer (YY_BUFFER_STATE b,FILE *file );
+
+#define YY_FLUSH_BUFFER skel__flush_buffer(YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE skel__scan_buffer (char *base,yy_size_t size );
+YY_BUFFER_STATE skel__scan_string (yyconst char *yy_str );
+YY_BUFFER_STATE skel__scan_bytes (yyconst char *bytes,yy_size_t len );
+
+/* %endif */
+
+void *skel_alloc (yy_size_t );
+void *skel_realloc (void *,yy_size_t );
+void skel_free (void * );
+
+#define yy_new_buffer skel__create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ skel_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ skel__create_buffer(skel_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ skel_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ skel__create_buffer(skel_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* %% [1.0] skel_text/skel_in/skel_out/yy_state_type/skel_lineno etc. def's & init go here */
+/* Begin user sect3 */
+
+#define skel_wrap() 1
+#define YY_SKIP_YYWRAP
+
+#define FLEX_DEBUG
+
+typedef unsigned char YY_CHAR;
+
+FILE *skel_in = (FILE *) 0, *skel_out = (FILE *) 0;
+
+typedef int yy_state_type;
+
+extern int skel_lineno;
+
+int skel_lineno = 1;
+
+extern char *skel_text;
+#define yytext_ptr skel_text
+
+/* %if-c-only Standard (non-C++) definition */
+
+static yy_state_type yy_get_previous_state (void );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state );
+static int yy_get_next_buffer (void );
+static void yy_fatal_error (yyconst char msg[] );
+
+/* %endif */
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up skel_text.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+/* %% [2.0] code to fiddle skel_text and skel_leng for yymore() goes here \ */\
+ skel_leng = (size_t) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+/* %% [3.0] code to copy yytext_ptr to skel_text[] goes here, if %array \ */\
+ (yy_c_buf_p) = yy_cp;
+
+/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
+#define YY_NUM_RULES 24
+#define YY_END_OF_BUFFER 25
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[67] =
+ { 0,
+ 0, 0, 0, 0, 0, 0, 25, 13, 12, 11,
+ 14, 21, 23, 22, 22, 13, 11, 5, 4, 1,
+ 11, 11, 11, 2, 3, 14, 21, 19, 18, 20,
+ 15, 16, 17, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+ 11, 11, 11, 11, 11, 7, 6, 11, 11, 11,
+ 10, 11, 11, 8, 9, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 1, 1, 1, 1, 1, 4, 5,
+ 6, 1, 1, 6, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 7, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 8, 9, 10, 1,
+
+ 11, 12, 1, 1, 13, 1, 1, 14, 15, 16,
+ 17, 18, 1, 1, 19, 20, 21, 1, 1, 1,
+ 1, 1, 22, 1, 23, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+ } ;
+
+static yyconst flex_int32_t yy_meta[24] =
+ { 0,
+ 1, 1, 2, 1, 3, 1, 4, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1
+ } ;
+
+static yyconst flex_int16_t yy_base[74] =
+ { 0,
+ 0, 1, 55, 54, 3, 7, 60, 0, 100, 8,
+ 0, 29, 100, 100, 100, 0, 50, 100, 100, 100,
+ 51, 41, 2, 100, 100, 0, 100, 100, 100, 100,
+ 100, 100, 100, 37, 40, 37, 36, 28, 36, 28,
+ 31, 28, 25, 26, 27, 29, 28, 17, 29, 26,
+ 22, 21, 7, 11, 11, 100, 100, 17, 10, 4,
+ 100, 14, 8, 100, 100, 100, 73, 77, 81, 85,
+ 88, 92, 95
+ } ;
+
+static yyconst flex_int16_t yy_def[74] =
+ { 0,
+ 67, 67, 68, 68, 69, 69, 66, 70, 66, 71,
+ 72, 73, 66, 66, 66, 70, 71, 66, 66, 66,
+ 17, 17, 17, 66, 66, 72, 66, 66, 66, 66,
+ 66, 66, 66, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
+ 17, 17, 17, 17, 17, 66, 66, 17, 17, 17,
+ 66, 17, 17, 66, 66, 0, 66, 66, 66, 66,
+ 66, 66, 66
+ } ;
+
+static yyconst flex_int16_t yy_nxt[124] =
+ { 0,
+ 66, 66, 9, 9, 14, 15, 10, 10, 14, 15,
+ 18, 19, 65, 36, 20, 37, 21, 22, 64, 63,
+ 62, 61, 38, 60, 23, 59, 58, 57, 56, 24,
+ 25, 28, 29, 55, 30, 31, 54, 53, 52, 51,
+ 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
+ 32, 33, 66, 66, 40, 39, 66, 35, 34, 66,
+ 12, 12, 66, 66, 66, 66, 66, 66, 66, 66,
+ 66, 66, 66, 8, 8, 8, 8, 11, 11, 11,
+ 11, 13, 13, 13, 13, 16, 66, 16, 17, 17,
+ 66, 17, 26, 26, 26, 27, 27, 27, 27, 7,
+
+ 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+ 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+ 66, 66, 66
+ } ;
+
+static yyconst flex_int16_t yy_chk[124] =
+ { 0,
+ 0, 0, 1, 2, 5, 5, 1, 2, 6, 6,
+ 10, 10, 63, 23, 10, 23, 10, 10, 62, 60,
+ 59, 58, 23, 55, 10, 54, 53, 52, 51, 10,
+ 10, 12, 12, 50, 12, 12, 49, 48, 47, 46,
+ 45, 44, 43, 42, 41, 40, 39, 38, 37, 36,
+ 12, 12, 17, 17, 35, 34, 17, 22, 21, 7,
+ 4, 3, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 17, 17, 67, 67, 67, 67, 68, 68, 68,
+ 68, 69, 69, 69, 69, 70, 0, 70, 71, 71,
+ 0, 71, 72, 72, 72, 73, 73, 73, 73, 66,
+
+ 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+ 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+ 66, 66, 66
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int skel__flex_debug;
+int skel__flex_debug = 1;
+
+static yyconst flex_int16_t yy_rule_linenum[24] =
+ { 0,
+ 72, 73, 74, 75, 76, 78, 79, 81, 82, 83,
+ 86, 87, 88, 101, 103, 104, 105, 106, 107, 109,
+ 128, 133, 134
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *skel_text;
+#line 1 "../../src/scan-skel.l"
+/* Scan Bison Skeletons. -*- C -*-
+
+ Copyright (C) 2001-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#define YY_NO_INPUT 1
+#line 24 "../../src/scan-skel.l"
+/* Work around a bug in flex 2.5.31. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+#undef skel_wrap
+#define skel_wrap() 1
+
+#define FLEX_PREFIX(Id) skel_ ## Id
+#include <src/flex-scanner.h>
+
+#include <dirname.h>
+#include <error.h>
+#include <quotearg.h>
+
+#include <src/complain.h>
+#include <src/getargs.h>
+#include <src/files.h>
+#include <src/scan-skel.h>
+
+#include "uniqstr.h"
+
+#define YY_DECL static int skel_lex (void)
+YY_DECL;
+
+typedef void (*at_directive)(int, char**, char **, int*);
+static void at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun);
+static void at_basename (int argc, char *argv[], char**, int*);
+static void at_complain (int argc, char *argv[], char**, int*);
+static void at_output (int argc, char *argv[], char **name, int *lineno);
+static void fail_for_at_directive_too_many_args (char const *at_directive_name);
+static void fail_for_at_directive_too_few_args (char const *at_directive_name);
+static void fail_for_invalid_at (char const *at);
+
+
+#line 660 "src/scan-skel.c"
+
+#define INITIAL 0
+#define SC_AT_DIRECTIVE_ARGS 1
+#define SC_AT_DIRECTIVE_SKIP_WS 2
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+/* %if-c-only */
+#include <unistd.h>
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* %if-c-only Reentrant structure and macros (non-C++). */
+/* %if-reentrant */
+/* %if-c-only */
+
+static int yy_init_globals (void );
+
+/* %endif */
+/* %if-reentrant */
+/* %endif */
+/* %endif End reentrant structures and macros. */
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int skel_lex_destroy (void );
+
+int skel_get_debug (void );
+
+void skel_set_debug (int debug_flag );
+
+YY_EXTRA_TYPE skel_get_extra (void );
+
+void skel_set_extra (YY_EXTRA_TYPE user_defined );
+
+FILE *skel_get_in (void );
+
+void skel_set_in (FILE * in_str );
+
+FILE *skel_get_out (void );
+
+void skel_set_out (FILE * out_str );
+
+yy_size_t skel_get_leng (void );
+
+char *skel_get_text (void );
+
+int skel_get_lineno (void );
+
+void skel_set_lineno (int line_number );
+
+/* %if-bison-bridge */
+/* %endif */
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int skel_wrap (void );
+#else
+extern int skel_wrap (void );
+#endif
+#endif
+
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %endif */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * );
+#endif
+
+#ifndef YY_NO_INPUT
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+
+#ifdef __cplusplus
+static int yyinput (void );
+#else
+static int input (void );
+#endif
+/* %ok-for-header */
+
+/* %endif */
+#endif
+
+/* %if-c-only */
+
+/* %endif */
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* %if-c-only Standard (non-C++) definition */
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( skel_text, skel_leng, 1, skel_out )) {} } while (0)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( skel_in )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( skel_in ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, skel_in))==0 && ferror(skel_in)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(skel_in); \
+ } \
+ }\
+\
+/* %if-c++-only C++ definition \ */\
+/* %endif */
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+/* %if-c-only */
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+/* %if-tables-serialization structures and prototypes */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %not-for-header */
+
+/* %tables-yydmap generated elements */
+/* %endif */
+/* end tables serialization structures and prototypes */
+
+/* %ok-for-header */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+/* %if-c-only Standard (non-C++) definition */
+
+extern int skel_lex (void);
+
+#define YY_DECL int skel_lex (void)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after skel_text and skel_leng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+/* %% [6.0] YY_RULE_SETUP definition goes here */
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/* %not-for-header */
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+/* %% [7.0] user's declarations go here */
+#line 57 "../../src/scan-skel.l"
+
+
+
+ int out_lineno PACIFY_CC (= 0);
+ char *out_name = NULL;
+
+ /* Currently, only the @complain directive takes multiple arguments, and
+ never more than 7, with argv[0] being the directive name and argv[1]
+ being the type of complaint to dispatch. */
+#define ARGC_MAX 9
+ int argc = 0;
+ char *argv[ARGC_MAX];
+ at_directive at_ptr = NULL;
+
+
+#line 918 "src/scan-skel.c"
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! skel_in )
+/* %if-c-only */
+ skel_in = stdin;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! skel_out )
+/* %if-c-only */
+ skel_out = stdout;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ skel_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ skel__create_buffer(skel_in,YY_BUF_SIZE );
+ }
+
+ skel__load_buffer_state( );
+ }
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+/* %% [8.0] yymore()-related code goes here */
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of skel_text. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+/* %% [9.0] code to set up and find next match goes here */
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 67 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 66 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+/* %% [10.0] code to find the action number goes here */
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+/* %% [11.0] code for skel_lineno update goes here */
+
+do_action: /* This label is used only to access EOF actions. */
+
+/* %% [12.0] debug code goes here */
+ if ( skel__flex_debug )
+ {
+ if ( yy_act == 0 )
+ fprintf( stderr, "--scanner backing up\n" );
+ else if ( yy_act < 24 )
+ fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
+ (long)yy_rule_linenum[yy_act], skel_text );
+ else if ( yy_act == 24 )
+ fprintf( stderr, "--accepting default rule (\"%s\")\n",
+ skel_text );
+ else if ( yy_act == 25 )
+ fprintf( stderr, "--(end of buffer or a NUL)\n" );
+ else
+ fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
+ }
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+/* %% [13.0] actions go here */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 72 "../../src/scan-skel.l"
+fputc ('@', skel_out);
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 73 "../../src/scan-skel.l"
+fputc ('[', skel_out);
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 74 "../../src/scan-skel.l"
+fputc (']', skel_out);
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 75 "../../src/scan-skel.l"
+continue; /* Used by b4_cat in ../data/bison.m4. */
+ YY_BREAK
+case 5:
+/* rule 5 can match eol */
+YY_RULE_SETUP
+#line 76 "../../src/scan-skel.l"
+continue;
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 78 "../../src/scan-skel.l"
+fprintf (skel_out, "%d", out_lineno + 1);
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 79 "../../src/scan-skel.l"
+fputs (quotearg_style (c_quoting_style, out_name), skel_out);
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 81 "../../src/scan-skel.l"
+at_init (&argc, argv, &at_ptr, &at_basename);
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 82 "../../src/scan-skel.l"
+at_init (&argc, argv, &at_ptr, &at_complain);
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 83 "../../src/scan-skel.l"
+at_init (&argc, argv, &at_ptr, &at_output);
+ YY_BREAK
+/* This pattern must not match more than the previous @ patterns. */
+case 11:
+YY_RULE_SETUP
+#line 86 "../../src/scan-skel.l"
+fail_for_invalid_at (skel_text);
+ YY_BREAK
+case 12:
+/* rule 12 can match eol */
+YY_RULE_SETUP
+#line 87 "../../src/scan-skel.l"
+out_lineno++; ECHO;
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 88 "../../src/scan-skel.l"
+ECHO;
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+#line 90 "../../src/scan-skel.l"
+{
+ if (out_name)
+ {
+ free (out_name);
+ xfclose (skel_out);
+ }
+ return EOF;
+}
+ YY_BREAK
+
+
+case 14:
+/* rule 14 can match eol */
+YY_RULE_SETUP
+#line 101 "../../src/scan-skel.l"
+STRING_GROW;
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 103 "../../src/scan-skel.l"
+obstack_1grow (&obstack_for_string, '@');
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 104 "../../src/scan-skel.l"
+obstack_1grow (&obstack_for_string, '[');
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 105 "../../src/scan-skel.l"
+obstack_1grow (&obstack_for_string, ']');
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 106 "../../src/scan-skel.l"
+continue; /* For starting an argument that begins with whitespace. */
+ YY_BREAK
+case 19:
+/* rule 19 can match eol */
+YY_RULE_SETUP
+#line 107 "../../src/scan-skel.l"
+continue;
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 109 "../../src/scan-skel.l"
+{
+ if (argc >= ARGC_MAX)
+ fail_for_at_directive_too_many_args (argv[0]);
+
+ argv[argc++] = obstack_finish0 (&obstack_for_string);
+
+ /* Like M4, skip whitespace after a comma. */
+ if (skel_text[1] == ',')
+ BEGIN SC_AT_DIRECTIVE_SKIP_WS;
+ else
+ {
+ aver (at_ptr);
+ at_ptr (argc, argv, &out_name, &out_lineno);
+ obstack_free (&obstack_for_string, argv[0]);
+ argc = 0;
+ BEGIN INITIAL;
+ }
+ }
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 128 "../../src/scan-skel.l"
+fail_for_invalid_at (skel_text);
+ YY_BREAK
+
+
+
+case 22:
+/* rule 22 can match eol */
+YY_RULE_SETUP
+#line 133 "../../src/scan-skel.l"
+continue;
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 134 "../../src/scan-skel.l"
+yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS;
+ YY_BREAK
+
+
+
+case YY_STATE_EOF(SC_AT_DIRECTIVE_ARGS):
+case YY_STATE_EOF(SC_AT_DIRECTIVE_SKIP_WS):
+#line 139 "../../src/scan-skel.l"
+complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]);
+ YY_BREAK
+
+case 24:
+YY_RULE_SETUP
+#line 142 "../../src/scan-skel.l"
+YY_FATAL_ERROR( "flex scanner jammed" );
+ YY_BREAK
+#line 1196 "src/scan-skel.c"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed skel_in at a new source and called
+ * skel_lex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = skel_in;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( skel_wrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * skel_text, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of skel_lex */
+/* %ok-for-header */
+
+/* %if-c++-only */
+/* %not-for-header */
+
+/* %ok-for-header */
+
+/* %endif */
+
+/* yy_get_next_buffer - try to read in a new buffer
*
- */
-/* %if-c-only */
- void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- /* TODO. We should be able to replace this entire function body
- * with
- * skel_pop_buffer_state();
- * skel_push_buffer_state(new_buffer);
- */
- skel_ensure_buffer_stack ();
- if ( YY_CURRENT_BUFFER == new_buffer )
- return;
-
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
- skel__load_buffer_state( );
-
- /* We don't actually know whether we did this switch during
- * EOF (skel_wrap()) processing, but the only time this flag
- * is looked at is after skel_wrap() is called, so it's safe
- * to go ahead and always set it.
- */
- (yy_did_buffer_switch_on_eof) = 1;
-}
-
-/* %if-c-only */
-static void skel__load_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
- (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
- skel_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
- (yy_hold_char) = *(yy_c_buf_p);
-}
-
-/** Allocate and initialize an input buffer state.
- * @param file A readable stream.
- * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+/* %if-c-only */
+static int yy_get_next_buffer (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = (yytext_ptr);
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ yy_size_t num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ yy_size_t new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ skel_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ skel_restart(skel_in );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) skel_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+/* %if-c-only */
+/* %not-for-header */
+
+ static yy_state_type yy_get_previous_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+/* %% [15.0] code to get the start state into yy_current_state goes here */
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+/* %% [16.0] code to find the next state goes here */
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 67 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
*
- * @return the allocated buffer state.
- */
-/* %if-c-only */
- YY_BUFFER_STATE skel__create_buffer (FILE * file, int size )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- YY_BUFFER_STATE b;
-
- b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
-
- b->yy_buf_size = size;
-
- /* yy_ch_buf has to be 2 characters longer than the size given because
- * we need to put in 2 end-of-buffer characters.
- */
- b->yy_ch_buf = (char *) skel_alloc(b->yy_buf_size + 2 );
- if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
-
- b->yy_is_our_buffer = 1;
-
- skel__init_buffer(b,file );
-
- return b;
-}
-
-/** Destroy the buffer.
- * @param b a buffer created with skel__create_buffer()
- *
- */
-/* %if-c-only */
- void skel__delete_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
-
- if ( ! b )
- return;
-
- if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
- YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
-
- if ( b->yy_is_our_buffer )
- skel_free((void *) b->yy_ch_buf );
-
- skel_free((void *) b );
-}
-
-/* Initializes or reinitializes a buffer.
- * This function is sometimes called more than once on the same buffer,
- * such as during a skel_restart() or at EOF.
- */
-/* %if-c-only */
- static void skel__init_buffer (YY_BUFFER_STATE b, FILE * file )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-{
- int oerrno = errno;
-
- skel__flush_buffer(b );
-
- b->yy_input_file = file;
- b->yy_fill_buffer = 1;
-
- /* If b is the current buffer, then skel__init_buffer was _probably_
- * called from skel_restart() or through yy_get_next_buffer.
- * In that case, we don't want to reset the lineno or column.
- */
- if (b != YY_CURRENT_BUFFER){
- b->yy_bs_lineno = 1;
- b->yy_bs_column = 0;
- }
-
-/* %if-c-only */
-
- b->yy_is_interactive = 0;
-
-/* %endif */
-/* %if-c++-only */
-/* %endif */
- errno = oerrno;
-}
-
-/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
- * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
- *
- */
-/* %if-c-only */
- void skel__flush_buffer (YY_BUFFER_STATE b )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if ( ! b )
- return;
-
- b->yy_n_chars = 0;
-
- /* We always need two end-of-buffer characters. The first causes
- * a transition to the end-of-buffer state. The second causes
- * a jam in that state.
- */
- b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
- b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
-
- b->yy_buf_pos = &b->yy_ch_buf[0];
-
- b->yy_at_bol = 1;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- if ( b == YY_CURRENT_BUFFER )
- skel__load_buffer_state( );
-}
-
-/* %if-c-or-c++ */
-/** Pushes the new state onto the stack. The new state becomes
- * the current state. This function will allocate the stack
- * if necessary.
- * @param new_buffer The new state.
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+/* %if-c-only */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ register int yy_is_jam;
+ /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
+ register char *yy_cp = (yy_c_buf_p);
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 67 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 66);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+/* %if-c-only */
+
+/* %endif */
+
+/* %if-c-only */
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ skel_restart(skel_in );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( skel_wrap( ) )
+ return EOF;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve skel_text */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+/* %% [19.0] update BOL and skel_lineno */
+
+ return c;
+}
+/* %if-c-only */
+#endif /* ifndef YY_NO_INPUT */
+/* %endif */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
*
- */
-/* %if-c-only */
-void skel_push_buffer_state (YY_BUFFER_STATE new_buffer )
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (new_buffer == NULL)
- return;
-
- skel_ensure_buffer_stack();
-
- /* This block is copied from skel__switch_to_buffer. */
- if ( YY_CURRENT_BUFFER )
- {
- /* Flush out information for old buffer. */
- *(yy_c_buf_p) = (yy_hold_char);
- YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
- YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
- }
-
- /* Only push if top exists. Otherwise, replace top. */
- if (YY_CURRENT_BUFFER)
- (yy_buffer_stack_top)++;
- YY_CURRENT_BUFFER_LVALUE = new_buffer;
-
- /* copied from skel__switch_to_buffer. */
- skel__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/** Removes and deletes the top of the stack, if present.
- * The next element becomes the new top.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+/* %if-c-only */
+ void skel_restart (FILE * input_file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ skel_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ skel__create_buffer(skel_in,YY_BUF_SIZE );
+ }
+
+ skel__init_buffer(YY_CURRENT_BUFFER,input_file );
+ skel__load_buffer_state( );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+/* %if-c-only */
+ void skel__switch_to_buffer (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * skel_pop_buffer_state();
+ * skel_push_buffer_state(new_buffer);
+ */
+ skel_ensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ skel__load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (skel_wrap()) processing, but the only time this flag
+ * is looked at is after skel_wrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/* %if-c-only */
+static void skel__load_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ skel_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+/* %if-c-only */
+ YY_BUFFER_STATE skel__create_buffer (FILE * file, int size )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) skel_alloc(b->yy_buf_size + 2 );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ skel__init_buffer(b,file );
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with skel__create_buffer()
+ *
+ */
+/* %if-c-only */
+ void skel__delete_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ skel_free((void *) b->yy_ch_buf );
+
+ skel_free((void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a skel_restart() or at EOF.
+ */
+/* %if-c-only */
+ static void skel__init_buffer (YY_BUFFER_STATE b, FILE * file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+{
+ int oerrno = errno;
+
+ skel__flush_buffer(b );
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then skel__init_buffer was _probably_
+ * called from skel_restart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+/* %if-c-only */
+
+ b->yy_is_interactive = 0;
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+/* %if-c-only */
+ void skel__flush_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ skel__load_buffer_state( );
+}
+
+/* %if-c-or-c++ */
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+/* %if-c-only */
+void skel_push_buffer_state (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (new_buffer == NULL)
+ return;
+
+ skel_ensure_buffer_stack();
+
+ /* This block is copied from skel__switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from skel__switch_to_buffer. */
+ skel__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+/* %if-c-only */
+void skel_pop_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ skel__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ skel__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+/* %if-c-only */
+static void skel_ensure_buffer_stack (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ (yy_buffer_stack) = (struct yy_buffer_state**)skel_alloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)skel_realloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE skel__scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ skel__switch_to_buffer(b );
+
+ return b;
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan a string. The next call to skel_lex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
*
- */
-/* %if-c-only */
-void skel_pop_buffer_state (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- if (!YY_CURRENT_BUFFER)
- return;
-
- skel__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- if ((yy_buffer_stack_top) > 0)
- --(yy_buffer_stack_top);
-
- if (YY_CURRENT_BUFFER) {
- skel__load_buffer_state( );
- (yy_did_buffer_switch_on_eof) = 1;
- }
-}
-/* %endif */
-
-/* %if-c-or-c++ */
-/* Allocates the stack if it does not exist.
- * Guarantees space for at least one push.
- */
-/* %if-c-only */
-static void skel_ensure_buffer_stack (void)
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-{
- yy_size_t num_to_alloc;
-
- if (!(yy_buffer_stack)) {
-
- /* First allocation is just for 2 elements, since we don't know if this
- * scanner will even need a stack. We use 2 instead of 1 to avoid an
- * immediate realloc on the next call.
- */
- num_to_alloc = 1;
- (yy_buffer_stack) = (struct yy_buffer_state**)skel_alloc
- (num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
-
- memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-
- (yy_buffer_stack_max) = num_to_alloc;
- (yy_buffer_stack_top) = 0;
- return;
- }
-
- if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
-
- /* Increase the buffer to prepare for a possible push. */
- int grow_size = 8 /* arbitrary grow size */;
-
- num_to_alloc = (yy_buffer_stack_max) + grow_size;
- (yy_buffer_stack) = (struct yy_buffer_state**)skel_realloc
- ((yy_buffer_stack),
- num_to_alloc * sizeof(struct yy_buffer_state*)
- );
- if ( ! (yy_buffer_stack) )
- YY_FATAL_ERROR( "out of dynamic memory in skel_ensure_buffer_stack()" );
-
- /* zero only the new slots.*/
- memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
- (yy_buffer_stack_max) = num_to_alloc;
- }
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan directly from a user-specified character buffer.
- * @param base the character buffer
- * @param size the size in bytes of the character buffer
- *
* @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE skel__scan_buffer (char * base, yy_size_t size )
-{
- YY_BUFFER_STATE b;
-
- if ( size < 2 ||
- base[size-2] != YY_END_OF_BUFFER_CHAR ||
- base[size-1] != YY_END_OF_BUFFER_CHAR )
- /* They forgot to leave room for the EOB's. */
- return 0;
-
- b = (YY_BUFFER_STATE) skel_alloc(sizeof( struct yy_buffer_state ) );
- if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in skel__scan_buffer()" );
-
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
- b->yy_buf_pos = b->yy_ch_buf = base;
- b->yy_is_our_buffer = 0;
- b->yy_input_file = 0;
- b->yy_n_chars = b->yy_buf_size;
- b->yy_is_interactive = 0;
- b->yy_at_bol = 1;
- b->yy_fill_buffer = 0;
- b->yy_buffer_status = YY_BUFFER_NEW;
-
- skel__switch_to_buffer(b );
-
- return b;
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan a string. The next call to skel_lex() will
- * scan from a @e copy of @a str.
- * @param yystr a NUL-terminated string to scan
- *
- * @return the newly allocated buffer state object.
- * @note If you want to scan bytes that may contain NUL values, then use
- * skel__scan_bytes() instead.
- */
-YY_BUFFER_STATE skel__scan_string (yyconst char * yystr )
-{
-
- return skel__scan_bytes(yystr,strlen(yystr) );
-}
-/* %endif */
-
-/* %if-c-only */
-/** Setup the input buffer state to scan the given bytes. The next call to skel_lex() will
- * scan from a @e copy of @a bytes.
- * @param yybytes the byte buffer to scan
- * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
- *
- * @return the newly allocated buffer state object.
- */
-YY_BUFFER_STATE skel__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
-{
- YY_BUFFER_STATE b;
- char *buf;
- yy_size_t n;
- int i;
-
- /* Get memory for full buffer, including space for trailing EOB's. */
- n = _yybytes_len + 2;
- buf = (char *) skel_alloc(n );
- if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in skel__scan_bytes()" );
-
- for ( i = 0; i < _yybytes_len; ++i )
- buf[i] = yybytes[i];
-
- buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
-
- b = skel__scan_buffer(buf,n );
- if ( ! b )
- YY_FATAL_ERROR( "bad buffer in skel__scan_bytes()" );
-
- /* It's okay to grow etc. this buffer, and we should throw it
- * away when we're done.
- */
- b->yy_is_our_buffer = 1;
-
- return b;
-}
-/* %endif */
-
-#ifndef YY_EXIT_FAILURE
-#define YY_EXIT_FAILURE 2
-#endif
-
-/* %if-c-only */
-static void yy_fatal_error (yyconst char* msg )
-{
- (void) fprintf( stderr, "%s\n", msg );
- exit( YY_EXIT_FAILURE );
-}
-/* %endif */
-/* %if-c++-only */
-/* %endif */
-
-/* Redefine yyless() so it works in section 3 code. */
-
-#undef yyless
-#define yyless(n) \
- do \
- { \
- /* Undo effects of setting up skel_text. */ \
- int yyless_macro_arg = (n); \
- YY_LESS_LINENO(yyless_macro_arg);\
- skel_text[skel_leng] = (yy_hold_char); \
- (yy_c_buf_p) = skel_text + yyless_macro_arg; \
- (yy_hold_char) = *(yy_c_buf_p); \
- *(yy_c_buf_p) = '\0'; \
- skel_leng = yyless_macro_arg; \
- } \
- while ( 0 )
-
-/* Accessor methods (get/set functions) to struct members. */
-
-/* %if-c-only */
-/* %if-reentrant */
-/* %endif */
-
-/** Get the current line number.
- *
- */
-int skel_get_lineno (void)
-{
-
- return skel_lineno;
-}
-
-/** Get the input stream.
- *
- */
-FILE *skel_get_in (void)
-{
- return skel_in;
-}
-
-/** Get the output stream.
- *
- */
-FILE *skel_get_out (void)
-{
- return skel_out;
-}
-
-/** Get the length of the current token.
- *
- */
-yy_size_t skel_get_leng (void)
-{
- return skel_leng;
-}
-
-/** Get the current token.
- *
- */
-
-char *skel_get_text (void)
-{
- return skel_text;
-}
-
-/* %if-reentrant */
-/* %endif */
-
-/** Set the current line number.
- * @param line_number
- *
- */
-void skel_set_lineno (int line_number )
-{
-
- skel_lineno = line_number;
-}
-
-/** Set the input stream. This does not discard the current
- * input buffer.
- * @param in_str A readable stream.
- *
- * @see skel__switch_to_buffer
- */
-void skel_set_in (FILE * in_str )
-{
- skel_in = in_str ;
-}
-
-void skel_set_out (FILE * out_str )
-{
- skel_out = out_str ;
-}
-
-int skel_get_debug (void)
-{
- return skel__flex_debug;
-}
-
-void skel_set_debug (int bdebug )
-{
- skel__flex_debug = bdebug ;
-}
-
-/* %endif */
-
-/* %if-reentrant */
-/* %if-bison-bridge */
-/* %endif */
-/* %endif if-c-only */
-
-/* %if-c-only */
-static int yy_init_globals (void)
-{
- /* Initialization is the same as for the non-reentrant scanner.
- * This function is called from skel_lex_destroy(), so don't allocate here.
- */
-
- (yy_buffer_stack) = 0;
- (yy_buffer_stack_top) = 0;
- (yy_buffer_stack_max) = 0;
- (yy_c_buf_p) = (char *) 0;
- (yy_init) = 0;
- (yy_start) = 0;
-
-/* Defined in main.c */
-#ifdef YY_STDINIT
- skel_in = stdin;
- skel_out = stdout;
-#else
- skel_in = (FILE *) 0;
- skel_out = (FILE *) 0;
-#endif
-
- /* For future reference: Set errno on error, since we are called by
- * skel_lex_init()
- */
- return 0;
-}
-/* %endif */
-
-/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
-/* skel_lex_destroy is for both reentrant and non-reentrant scanners. */
-int skel_lex_destroy (void)
-{
-
- /* Pop the buffer stack, destroying each element. */
- while(YY_CURRENT_BUFFER){
- skel__delete_buffer(YY_CURRENT_BUFFER );
- YY_CURRENT_BUFFER_LVALUE = NULL;
- skel_pop_buffer_state();
- }
-
- /* Destroy the stack itself. */
- skel_free((yy_buffer_stack) );
- (yy_buffer_stack) = NULL;
-
- /* Reset the globals. This is important in a non-reentrant scanner so the next time
- * skel_lex() is called, initialization will occur. */
- yy_init_globals( );
-
-/* %if-reentrant */
-/* %endif */
- return 0;
-}
-/* %endif */
-
-/*
- * Internal utility routines.
- */
-
-#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
-{
- register int i;
- for ( i = 0; i < n; ++i )
- s1[i] = s2[i];
-}
-#endif
-
-#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s )
-{
- register int n;
- for ( n = 0; s[n]; ++n )
- ;
-
- return n;
-}
-#endif
-
-void *skel_alloc (yy_size_t size )
-{
- return (void *) malloc( size );
-}
-
-void *skel_realloc (void * ptr, yy_size_t size )
-{
- /* The cast to (char *) in the following accommodates both
- * implementations that use char* generic pointers, and those
- * that use void* generic pointers. It works with the latter
- * because both ANSI C and C++ allow castless assignment from
- * any pointer type to void*, and deal with argument conversions
- * as though doing an assignment.
- */
- return (void *) realloc( (char *) ptr, size );
-}
-
-void skel_free (void * ptr )
-{
- free( (char *) ptr ); /* see skel_realloc() for (char *) cast */
-}
-
-/* %if-tables-serialization definitions */
-/* %define-yytables The name for this specific scanner's tables. */
-#define YYTABLES_NAME "yytables"
-/* %endif */
-
-/* %ok-for-header */
-
-#line 142 "../../src/scan-skel.l"
-
-
-
-static void
-at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun)
-{
- *at_ptr = fun;
- skel_text[skel_leng-1] = '\0';
- obstack_grow (&obstack_for_string, skel_text, skel_leng);
- argv[(*argc)++] = obstack_finish (&obstack_for_string);
- BEGIN SC_AT_DIRECTIVE_ARGS;
-}
-
-/*------------------------.
-| Scan a Bison skeleton. |
-`------------------------*/
-
-void
-scan_skel (FILE *in)
-{
- static bool initialized = false;
- if (!initialized)
- {
- initialized = true;
- obstack_init (&obstack_for_string);
- }
- skel_in = in;
- skel__flex_debug = trace_flag & trace_skeleton;
- skel_lex ();
-}
-
-void
-skel_scanner_free (void)
-{
- obstack_free (&obstack_for_string, 0);
- /* Reclaim Flex's buffers. */
- skel_lex_destroy ();
-}
-
-static inline warnings
-flag (const char *arg)
-{
- /* compare with values issued from b4_error */
- if (STREQ (arg, "complain"))
- return complaint;
- else if (STREQ (arg, "deprecated"))
- return Wdeprecated;
- else if (STREQ (arg, "fatal"))
- return fatal;
- else if (STREQ (arg, "note"))
- return silent | complaint | no_caret;
- else if (STREQ (arg, "warn"))
- return Wother;
- else
- aver (false);
-}
-
-static void
-at_basename (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- (void) out_namep;
- (void) out_linenop;
- if (2 < argc)
- fail_for_at_directive_too_many_args (argv[0]);
- fputs (last_component (argv[1]), skel_out);
-}
-
-static void
-at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- static unsigned indent;
- warnings w = flag (argv[1]);
- location loc;
- location *locp = NULL;
-
- (void) out_namep;
- (void) out_linenop;
-
- if (argc < 4)
- fail_for_at_directive_too_few_args (argv[0]);
- if (argv[2] && argv[2][0])
- {
- boundary_set_from_string (&loc.start, argv[2]);
- boundary_set_from_string (&loc.end, argv[3]);
- locp = &loc;
- }
- if (w & silent)
- indent += SUB_INDENT;
- else
- indent = 0;
- complain_args (locp, w, &indent, argc - 4, argv + 4);
- if (w & silent)
- indent -= SUB_INDENT;
-}
-
-static void
-at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- if (2 < argc)
- fail_for_at_directive_too_many_args (argv[0]);
- if (*out_namep)
- {
- free (*out_namep);
- xfclose (skel_out);
- }
- *out_namep = xstrdup (argv[1]);
- output_file_name_check (out_namep);
- skel_out = xfopen (*out_namep, "w");
- *out_linenop = 1;
-}
-
-static void
-fail_for_at_directive_too_few_args (char const *at_directive_name)
-{
- complain (NULL, fatal, _("too few arguments for %s directive in skeleton"),
- at_directive_name);
-}
-
-static void
-fail_for_at_directive_too_many_args (char const *at_directive_name)
-{
- complain (NULL, fatal, _("too many arguments for %s directive in skeleton"),
- at_directive_name);
-}
-
-static void
-fail_for_invalid_at (char const *at)
-{
- complain (NULL, fatal, "invalid @ in skeleton: %s", at);
-}
-
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * skel__scan_bytes() instead.
+ */
+YY_BUFFER_STATE skel__scan_string (yyconst char * yystr )
+{
+
+ return skel__scan_bytes(yystr,strlen(yystr) );
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan the given bytes. The next call to skel_lex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE skel__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) skel_alloc(n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in skel__scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = skel__scan_buffer(buf,n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in skel__scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+/* %endif */
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+/* %if-c-only */
+static void yy_fatal_error (yyconst char* msg )
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up skel_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ skel_text[skel_leng] = (yy_hold_char); \
+ (yy_c_buf_p) = skel_text + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ skel_leng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/* %if-c-only */
+/* %if-reentrant */
+/* %endif */
+
+/** Get the current line number.
+ *
+ */
+int skel_get_lineno (void)
+{
+
+ return skel_lineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *skel_get_in (void)
+{
+ return skel_in;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *skel_get_out (void)
+{
+ return skel_out;
+}
+
+/** Get the length of the current token.
+ *
+ */
+yy_size_t skel_get_leng (void)
+{
+ return skel_leng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *skel_get_text (void)
+{
+ return skel_text;
+}
+
+/* %if-reentrant */
+/* %endif */
+
+/** Set the current line number.
+ * @param line_number
+ *
+ */
+void skel_set_lineno (int line_number )
+{
+
+ skel_lineno = line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ *
+ * @see skel__switch_to_buffer
+ */
+void skel_set_in (FILE * in_str )
+{
+ skel_in = in_str ;
+}
+
+void skel_set_out (FILE * out_str )
+{
+ skel_out = out_str ;
+}
+
+int skel_get_debug (void)
+{
+ return skel__flex_debug;
+}
+
+void skel_set_debug (int bdebug )
+{
+ skel__flex_debug = bdebug ;
+}
+
+/* %endif */
+
+/* %if-reentrant */
+/* %if-bison-bridge */
+/* %endif */
+/* %endif if-c-only */
+
+/* %if-c-only */
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from skel_lex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = 0;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = (char *) 0;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ skel_in = stdin;
+ skel_out = stdout;
+#else
+ skel_in = (FILE *) 0;
+ skel_out = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * skel_lex_init()
+ */
+ return 0;
+}
+/* %endif */
+
+/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
+/* skel_lex_destroy is for both reentrant and non-reentrant scanners. */
+int skel_lex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ skel__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ skel_pop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ skel_free((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * skel_lex() is called, initialization will occur. */
+ yy_init_globals( );
+
+/* %if-reentrant */
+/* %endif */
+ return 0;
+}
+/* %endif */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s )
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *skel_alloc (yy_size_t size )
+{
+ return (void *) malloc( size );
+}
+
+void *skel_realloc (void * ptr, yy_size_t size )
+{
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return (void *) realloc( (char *) ptr, size );
+}
+
+void skel_free (void * ptr )
+{
+ free( (char *) ptr ); /* see skel_realloc() for (char *) cast */
+}
+
+/* %if-tables-serialization definitions */
+/* %define-yytables The name for this specific scanner's tables. */
+#define YYTABLES_NAME "yytables"
+/* %endif */
+
+/* %ok-for-header */
+
+#line 142 "../../src/scan-skel.l"
+
+
+
+static void
+at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun)
+{
+ *at_ptr = fun;
+ skel_text[skel_leng-1] = '\0';
+ obstack_grow (&obstack_for_string, skel_text, skel_leng);
+ argv[(*argc)++] = obstack_finish (&obstack_for_string);
+ BEGIN SC_AT_DIRECTIVE_ARGS;
+}
+
+/*------------------------.
+| Scan a Bison skeleton. |
+`------------------------*/
+
+void
+scan_skel (FILE *in)
+{
+ static bool initialized = false;
+ if (!initialized)
+ {
+ initialized = true;
+ obstack_init (&obstack_for_string);
+ }
+ skel_in = in;
+ skel__flex_debug = trace_flag & trace_skeleton;
+ skel_lex ();
+}
+
+void
+skel_scanner_free (void)
+{
+ obstack_free (&obstack_for_string, 0);
+ /* Reclaim Flex's buffers. */
+ skel_lex_destroy ();
+}
+
+static inline warnings
+flag (const char *arg)
+{
+ /* compare with values issued from b4_error */
+ if (STREQ (arg, "complain"))
+ return complaint;
+ else if (STREQ (arg, "deprecated"))
+ return Wdeprecated;
+ else if (STREQ (arg, "fatal"))
+ return fatal;
+ else if (STREQ (arg, "note"))
+ return silent | complaint | no_caret;
+ else if (STREQ (arg, "warn"))
+ return Wother;
+ else
+ aver (false);
+}
+
+static void
+at_basename (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ (void) out_namep;
+ (void) out_linenop;
+ if (2 < argc)
+ fail_for_at_directive_too_many_args (argv[0]);
+ fputs (last_component (argv[1]), skel_out);
+}
+
+static void
+at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ static unsigned indent;
+ warnings w = flag (argv[1]);
+ location loc;
+ location *locp = NULL;
+
+ (void) out_namep;
+ (void) out_linenop;
+
+ if (argc < 4)
+ fail_for_at_directive_too_few_args (argv[0]);
+ if (argv[2] && argv[2][0])
+ {
+ boundary_set_from_string (&loc.start, argv[2]);
+ boundary_set_from_string (&loc.end, argv[3]);
+ locp = &loc;
+ }
+ if (w & silent)
+ indent += SUB_INDENT;
+ else
+ indent = 0;
+ complain_args (locp, w, &indent, argc - 4, argv + 4);
+ if (w & silent)
+ indent -= SUB_INDENT;
+}
+
+static void
+at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ if (2 < argc)
+ fail_for_at_directive_too_many_args (argv[0]);
+ if (*out_namep)
+ {
+ free (*out_namep);
+ xfclose (skel_out);
+ }
+ *out_namep = xstrdup (argv[1]);
+ output_file_name_check (out_namep);
+ skel_out = xfopen (*out_namep, "w");
+ *out_linenop = 1;
+}
+
+static void
+fail_for_at_directive_too_few_args (char const *at_directive_name)
+{
+ complain (NULL, fatal, _("too few arguments for %s directive in skeleton"),
+ at_directive_name);
+}
+
+static void
+fail_for_at_directive_too_many_args (char const *at_directive_name)
+{
+ complain (NULL, fatal, _("too many arguments for %s directive in skeleton"),
+ at_directive_name);
+}
+
+static void
+fail_for_invalid_at (char const *at)
+{
+ complain (NULL, fatal, "invalid @ in skeleton: %s", at);
+}
+
diff --git a/contrib/tools/bison/bison/src/scan-skel.h b/contrib/tools/bison/bison/src/scan-skel.h
index 019d38af5a..28f0ff424b 100644
--- a/contrib/tools/bison/bison/src/scan-skel.h
+++ b/contrib/tools/bison/bison/src/scan-skel.h
@@ -1,27 +1,27 @@
-/* Scan Bison Skeletons.
-
- Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-void scan_skel (FILE *);
-
-/* Pacify "make syntax-check". */
-extern FILE *skel_in;
-extern FILE *skel_out;
-extern int skel__flex_debug;
-extern int skel_lineno;
-void skel_scanner_free (void);
+/* Scan Bison Skeletons.
+
+ Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+void scan_skel (FILE *);
+
+/* Pacify "make syntax-check". */
+extern FILE *skel_in;
+extern FILE *skel_out;
+extern int skel__flex_debug;
+extern int skel_lineno;
+void skel_scanner_free (void);
diff --git a/contrib/tools/bison/bison/src/scan-skel.l b/contrib/tools/bison/bison/src/scan-skel.l
index c7f58f8b28..88a1251ab2 100644
--- a/contrib/tools/bison/bison/src/scan-skel.l
+++ b/contrib/tools/bison/bison/src/scan-skel.l
@@ -1,271 +1,271 @@
-/* Scan Bison Skeletons. -*- C -*-
-
- Copyright (C) 2001-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-%option nodefault noyywrap noinput nounput never-interactive debug
-%option prefix="skel_" outfile="lex.yy.c"
-
-%{
-/* Work around a bug in flex 2.5.31. See Debian bug 333231
- <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
-#undef skel_wrap
-#define skel_wrap() 1
-
-#define FLEX_PREFIX(Id) skel_ ## Id
-#include <src/flex-scanner.h>
-
-#include <dirname.h>
-#include <error.h>
-#include <quotearg.h>
-
-#include <src/complain.h>
-#include <src/getargs.h>
-#include <src/files.h>
-#include <src/scan-skel.h>
-
-#define YY_DECL static int skel_lex (void)
-YY_DECL;
-
-typedef void (*at_directive)(int, char**, char **, int*);
-static void at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun);
-static void at_basename (int argc, char *argv[], char**, int*);
-static void at_complain (int argc, char *argv[], char**, int*);
-static void at_output (int argc, char *argv[], char **name, int *lineno);
-static void fail_for_at_directive_too_many_args (char const *at_directive_name);
-static void fail_for_at_directive_too_few_args (char const *at_directive_name);
-static void fail_for_invalid_at (char const *at);
-%}
-
-%x SC_AT_DIRECTIVE_ARGS
-%x SC_AT_DIRECTIVE_SKIP_WS
-
-%%
-
-%{
- int out_lineno PACIFY_CC (= 0);
- char *out_name = NULL;
-
- /* Currently, only the @complain directive takes multiple arguments, and
- never more than 7, with argv[0] being the directive name and argv[1]
- being the type of complaint to dispatch. */
-#define ARGC_MAX 9
- int argc = 0;
- char *argv[ARGC_MAX];
- at_directive at_ptr = NULL;
-%}
-
-\r+ continue;
-"@@" fputc ('@', yyout);
-"@{" fputc ('[', yyout);
-"@}" fputc (']', yyout);
-"@'" continue; /* Used by b4_cat in ../data/bison.m4. */
-@\r*\n continue;
-
-"@oline@" fprintf (yyout, "%d", out_lineno + 1);
-"@ofile@" fputs (quotearg_style (c_quoting_style, out_name), yyout);
-
-"@basename(" at_init (&argc, argv, &at_ptr, &at_basename);
-"@complain(" at_init (&argc, argv, &at_ptr, &at_complain);
-"@output(" at_init (&argc, argv, &at_ptr, &at_output);
-
- /* This pattern must not match more than the previous @ patterns. */
-@[^@{}\'(\n]* fail_for_invalid_at (yytext);
-\n out_lineno++; ECHO;
-[^@\n]+ ECHO;
-
-<INITIAL><<EOF>> {
- if (out_name)
- {
- free (out_name);
- xfclose (yyout);
- }
- return EOF;
-}
-
-<SC_AT_DIRECTIVE_ARGS>
-{
- [^@]+ STRING_GROW;
-
- "@@" obstack_1grow (&obstack_for_string, '@');
- "@{" obstack_1grow (&obstack_for_string, '[');
- "@}" obstack_1grow (&obstack_for_string, ']');
- "@'" continue; /* For starting an argument that begins with whitespace. */
- @\r*\n continue;
-
- @[,)] {
- if (argc >= ARGC_MAX)
- fail_for_at_directive_too_many_args (argv[0]);
-
- argv[argc++] = obstack_finish0 (&obstack_for_string);
-
- /* Like M4, skip whitespace after a comma. */
- if (yytext[1] == ',')
- BEGIN SC_AT_DIRECTIVE_SKIP_WS;
- else
- {
- aver (at_ptr);
- at_ptr (argc, argv, &out_name, &out_lineno);
- obstack_free (&obstack_for_string, argv[0]);
- argc = 0;
- BEGIN INITIAL;
- }
- }
-
- @.? fail_for_invalid_at (yytext);
-}
-
-<SC_AT_DIRECTIVE_SKIP_WS>
-{
- [ \t\r\n] continue;
- . yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS;
-}
-
-<SC_AT_DIRECTIVE_ARGS,SC_AT_DIRECTIVE_SKIP_WS>
-{
- <<EOF>> complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]);
-}
-
-%%
-
-static void
-at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun)
-{
- *at_ptr = fun;
- yytext[yyleng-1] = '\0';
- obstack_grow (&obstack_for_string, yytext, yyleng);
- argv[(*argc)++] = obstack_finish (&obstack_for_string);
- BEGIN SC_AT_DIRECTIVE_ARGS;
-}
-
-/*------------------------.
-| Scan a Bison skeleton. |
-`------------------------*/
-
-void
-scan_skel (FILE *in)
-{
- static bool initialized = false;
- if (!initialized)
- {
- initialized = true;
- obstack_init (&obstack_for_string);
- }
- skel_in = in;
- skel__flex_debug = trace_flag & trace_skeleton;
- skel_lex ();
-}
-
-void
-skel_scanner_free (void)
-{
- obstack_free (&obstack_for_string, 0);
- /* Reclaim Flex's buffers. */
- yylex_destroy ();
-}
-
-static inline warnings
-flag (const char *arg)
-{
- /* compare with values issued from b4_error */
- if (STREQ (arg, "complain"))
- return complaint;
- else if (STREQ (arg, "deprecated"))
- return Wdeprecated;
- else if (STREQ (arg, "fatal"))
- return fatal;
- else if (STREQ (arg, "note"))
- return silent | complaint | no_caret;
- else if (STREQ (arg, "warn"))
- return Wother;
- else
- aver (false);
-}
-
-static void
-at_basename (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- (void) out_namep;
- (void) out_linenop;
- if (2 < argc)
- fail_for_at_directive_too_many_args (argv[0]);
- fputs (last_component (argv[1]), yyout);
-}
-
-static void
-at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- static unsigned indent;
- warnings w = flag (argv[1]);
- location loc;
- location *locp = NULL;
-
- (void) out_namep;
- (void) out_linenop;
-
- if (argc < 4)
- fail_for_at_directive_too_few_args (argv[0]);
- if (argv[2] && argv[2][0])
- {
- boundary_set_from_string (&loc.start, argv[2]);
- boundary_set_from_string (&loc.end, argv[3]);
- locp = &loc;
- }
- if (w & silent)
- indent += SUB_INDENT;
- else
- indent = 0;
- complain_args (locp, w, &indent, argc - 4, argv + 4);
- if (w & silent)
- indent -= SUB_INDENT;
-}
-
-static void
-at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
-{
- if (2 < argc)
- fail_for_at_directive_too_many_args (argv[0]);
- if (*out_namep)
- {
- free (*out_namep);
- xfclose (yyout);
- }
- *out_namep = xstrdup (argv[1]);
- output_file_name_check (out_namep);
- yyout = xfopen (*out_namep, "wb");
- *out_linenop = 1;
-}
-
-static void
-fail_for_at_directive_too_few_args (char const *at_directive_name)
-{
- complain (NULL, fatal, _("too few arguments for %s directive in skeleton"),
- at_directive_name);
-}
-
-static void
-fail_for_at_directive_too_many_args (char const *at_directive_name)
-{
- complain (NULL, fatal, _("too many arguments for %s directive in skeleton"),
- at_directive_name);
-}
-
-static void
-fail_for_invalid_at (char const *at)
-{
- complain (NULL, fatal, "invalid @ in skeleton: %s", at);
-}
+/* Scan Bison Skeletons. -*- C -*-
+
+ Copyright (C) 2001-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+%option nodefault noyywrap noinput nounput never-interactive debug
+%option prefix="skel_" outfile="lex.yy.c"
+
+%{
+/* Work around a bug in flex 2.5.31. See Debian bug 333231
+ <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
+#undef skel_wrap
+#define skel_wrap() 1
+
+#define FLEX_PREFIX(Id) skel_ ## Id
+#include <src/flex-scanner.h>
+
+#include <dirname.h>
+#include <error.h>
+#include <quotearg.h>
+
+#include <src/complain.h>
+#include <src/getargs.h>
+#include <src/files.h>
+#include <src/scan-skel.h>
+
+#define YY_DECL static int skel_lex (void)
+YY_DECL;
+
+typedef void (*at_directive)(int, char**, char **, int*);
+static void at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun);
+static void at_basename (int argc, char *argv[], char**, int*);
+static void at_complain (int argc, char *argv[], char**, int*);
+static void at_output (int argc, char *argv[], char **name, int *lineno);
+static void fail_for_at_directive_too_many_args (char const *at_directive_name);
+static void fail_for_at_directive_too_few_args (char const *at_directive_name);
+static void fail_for_invalid_at (char const *at);
+%}
+
+%x SC_AT_DIRECTIVE_ARGS
+%x SC_AT_DIRECTIVE_SKIP_WS
+
+%%
+
+%{
+ int out_lineno PACIFY_CC (= 0);
+ char *out_name = NULL;
+
+ /* Currently, only the @complain directive takes multiple arguments, and
+ never more than 7, with argv[0] being the directive name and argv[1]
+ being the type of complaint to dispatch. */
+#define ARGC_MAX 9
+ int argc = 0;
+ char *argv[ARGC_MAX];
+ at_directive at_ptr = NULL;
+%}
+
+\r+ continue;
+"@@" fputc ('@', yyout);
+"@{" fputc ('[', yyout);
+"@}" fputc (']', yyout);
+"@'" continue; /* Used by b4_cat in ../data/bison.m4. */
+@\r*\n continue;
+
+"@oline@" fprintf (yyout, "%d", out_lineno + 1);
+"@ofile@" fputs (quotearg_style (c_quoting_style, out_name), yyout);
+
+"@basename(" at_init (&argc, argv, &at_ptr, &at_basename);
+"@complain(" at_init (&argc, argv, &at_ptr, &at_complain);
+"@output(" at_init (&argc, argv, &at_ptr, &at_output);
+
+ /* This pattern must not match more than the previous @ patterns. */
+@[^@{}\'(\n]* fail_for_invalid_at (yytext);
+\n out_lineno++; ECHO;
+[^@\n]+ ECHO;
+
+<INITIAL><<EOF>> {
+ if (out_name)
+ {
+ free (out_name);
+ xfclose (yyout);
+ }
+ return EOF;
+}
+
+<SC_AT_DIRECTIVE_ARGS>
+{
+ [^@]+ STRING_GROW;
+
+ "@@" obstack_1grow (&obstack_for_string, '@');
+ "@{" obstack_1grow (&obstack_for_string, '[');
+ "@}" obstack_1grow (&obstack_for_string, ']');
+ "@'" continue; /* For starting an argument that begins with whitespace. */
+ @\r*\n continue;
+
+ @[,)] {
+ if (argc >= ARGC_MAX)
+ fail_for_at_directive_too_many_args (argv[0]);
+
+ argv[argc++] = obstack_finish0 (&obstack_for_string);
+
+ /* Like M4, skip whitespace after a comma. */
+ if (yytext[1] == ',')
+ BEGIN SC_AT_DIRECTIVE_SKIP_WS;
+ else
+ {
+ aver (at_ptr);
+ at_ptr (argc, argv, &out_name, &out_lineno);
+ obstack_free (&obstack_for_string, argv[0]);
+ argc = 0;
+ BEGIN INITIAL;
+ }
+ }
+
+ @.? fail_for_invalid_at (yytext);
+}
+
+<SC_AT_DIRECTIVE_SKIP_WS>
+{
+ [ \t\r\n] continue;
+ . yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS;
+}
+
+<SC_AT_DIRECTIVE_ARGS,SC_AT_DIRECTIVE_SKIP_WS>
+{
+ <<EOF>> complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]);
+}
+
+%%
+
+static void
+at_init (int *argc, char *argv[], at_directive *at_ptr, at_directive fun)
+{
+ *at_ptr = fun;
+ yytext[yyleng-1] = '\0';
+ obstack_grow (&obstack_for_string, yytext, yyleng);
+ argv[(*argc)++] = obstack_finish (&obstack_for_string);
+ BEGIN SC_AT_DIRECTIVE_ARGS;
+}
+
+/*------------------------.
+| Scan a Bison skeleton. |
+`------------------------*/
+
+void
+scan_skel (FILE *in)
+{
+ static bool initialized = false;
+ if (!initialized)
+ {
+ initialized = true;
+ obstack_init (&obstack_for_string);
+ }
+ skel_in = in;
+ skel__flex_debug = trace_flag & trace_skeleton;
+ skel_lex ();
+}
+
+void
+skel_scanner_free (void)
+{
+ obstack_free (&obstack_for_string, 0);
+ /* Reclaim Flex's buffers. */
+ yylex_destroy ();
+}
+
+static inline warnings
+flag (const char *arg)
+{
+ /* compare with values issued from b4_error */
+ if (STREQ (arg, "complain"))
+ return complaint;
+ else if (STREQ (arg, "deprecated"))
+ return Wdeprecated;
+ else if (STREQ (arg, "fatal"))
+ return fatal;
+ else if (STREQ (arg, "note"))
+ return silent | complaint | no_caret;
+ else if (STREQ (arg, "warn"))
+ return Wother;
+ else
+ aver (false);
+}
+
+static void
+at_basename (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ (void) out_namep;
+ (void) out_linenop;
+ if (2 < argc)
+ fail_for_at_directive_too_many_args (argv[0]);
+ fputs (last_component (argv[1]), yyout);
+}
+
+static void
+at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ static unsigned indent;
+ warnings w = flag (argv[1]);
+ location loc;
+ location *locp = NULL;
+
+ (void) out_namep;
+ (void) out_linenop;
+
+ if (argc < 4)
+ fail_for_at_directive_too_few_args (argv[0]);
+ if (argv[2] && argv[2][0])
+ {
+ boundary_set_from_string (&loc.start, argv[2]);
+ boundary_set_from_string (&loc.end, argv[3]);
+ locp = &loc;
+ }
+ if (w & silent)
+ indent += SUB_INDENT;
+ else
+ indent = 0;
+ complain_args (locp, w, &indent, argc - 4, argv + 4);
+ if (w & silent)
+ indent -= SUB_INDENT;
+}
+
+static void
+at_output (int argc, char *argv[], char **out_namep, int *out_linenop)
+{
+ if (2 < argc)
+ fail_for_at_directive_too_many_args (argv[0]);
+ if (*out_namep)
+ {
+ free (*out_namep);
+ xfclose (yyout);
+ }
+ *out_namep = xstrdup (argv[1]);
+ output_file_name_check (out_namep);
+ yyout = xfopen (*out_namep, "wb");
+ *out_linenop = 1;
+}
+
+static void
+fail_for_at_directive_too_few_args (char const *at_directive_name)
+{
+ complain (NULL, fatal, _("too few arguments for %s directive in skeleton"),
+ at_directive_name);
+}
+
+static void
+fail_for_at_directive_too_many_args (char const *at_directive_name)
+{
+ complain (NULL, fatal, _("too many arguments for %s directive in skeleton"),
+ at_directive_name);
+}
+
+static void
+fail_for_invalid_at (char const *at)
+{
+ complain (NULL, fatal, "invalid @ in skeleton: %s", at);
+}
diff --git a/contrib/tools/bison/bison/src/state.c b/contrib/tools/bison/bison/src/state.c
index c11b10f7dd..b3b1dabb0d 100644
--- a/contrib/tools/bison/bison/src/state.c
+++ b/contrib/tools/bison/bison/src/state.c
@@ -1,466 +1,466 @@
-/* Type definitions for the finite state machine for Bison.
-
- Copyright (C) 2001-2007, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <hash.h>
-
-#include "complain.h"
-#include "gram.h"
-#include "state.h"
-#include "print-xml.h"
-
-
- /*-------------------.
- | Shifts and Gotos. |
- `-------------------*/
-
-
-/*-----------------------------------------.
-| Create a new array of NUM shifts/gotos. |
-`-----------------------------------------*/
-
-static transitions *
-transitions_new (int num, state **the_states)
-{
- size_t states_size = num * sizeof *the_states;
- transitions *res = xmalloc (offsetof (transitions, states) + states_size);
- res->num = num;
- memcpy (res->states, the_states, states_size);
- return res;
-}
-
-
-/*-------------------------------------------------------.
-| Return the state such that SHIFTS contain a shift/goto |
-| to it on SYM. Abort if none found. |
-`-------------------------------------------------------*/
-
-state *
-transitions_to (transitions *shifts, symbol_number sym)
-{
- int j;
- for (j = 0; ; j++)
- {
- aver (j < shifts->num);
- if (TRANSITION_SYMBOL (shifts, j) == sym)
- return shifts->states[j];
- }
-}
-
-
- /*--------------------.
- | Error transitions. |
- `--------------------*/
-
-
-/*---------------------------------.
-| Create a new array of NUM errs. |
-`---------------------------------*/
-
-errs *
-errs_new (int num, symbol **tokens)
-{
- size_t symbols_size = num * sizeof *tokens;
- errs *res = xmalloc (offsetof (errs, symbols) + symbols_size);
- res->num = num;
- memcpy (res->symbols, tokens, symbols_size);
- return res;
-}
-
-
-
-
- /*-------------.
- | Reductions. |
- `-------------*/
-
-
-/*---------------------------------------.
-| Create a new array of NUM reductions. |
-`---------------------------------------*/
-
-static reductions *
-reductions_new (int num, rule **reds)
-{
- size_t rules_size = num * sizeof *reds;
- reductions *res = xmalloc (offsetof (reductions, rules) + rules_size);
- res->num = num;
- res->lookahead_tokens = NULL;
- memcpy (res->rules, reds, rules_size);
- return res;
-}
-
-
-
- /*---------.
- | States. |
- `---------*/
-
-
-state_number nstates = 0;
-/* FINAL_STATE is properly set by new_state when it recognizes its
- accessing symbol: $end. */
-state *final_state = NULL;
-
-
-/*------------------------------------------------------------------.
-| Create a new state with ACCESSING_SYMBOL, for those items. Store |
-| it in the state hash table. |
-`------------------------------------------------------------------*/
-
-state *
-state_new (symbol_number accessing_symbol,
- size_t nitems, item_number *core)
-{
- state *res;
- size_t items_size = nitems * sizeof *core;
-
- aver (nstates < STATE_NUMBER_MAXIMUM);
-
- res = xmalloc (offsetof (state, items) + items_size);
- res->number = nstates++;
- res->accessing_symbol = accessing_symbol;
- res->transitions = NULL;
- res->reductions = NULL;
- res->errs = NULL;
- res->state_list = NULL;
- res->consistent = 0;
- res->solved_conflicts = NULL;
- res->solved_conflicts_xml = NULL;
-
- res->nitems = nitems;
- memcpy (res->items, core, items_size);
-
- state_hash_insert (res);
-
- return res;
-}
-
-state *
-state_new_isocore (state const *s)
-{
- state *res;
- size_t items_size = s->nitems * sizeof *s->items;
-
- aver (nstates < STATE_NUMBER_MAXIMUM);
-
- res = xmalloc (offsetof (state, items) + items_size);
- res->number = nstates++;
- res->accessing_symbol = s->accessing_symbol;
- res->transitions =
- transitions_new (s->transitions->num, s->transitions->states);
- res->reductions = reductions_new (s->reductions->num, s->reductions->rules);
- res->errs = NULL;
- res->state_list = NULL;
- res->consistent = s->consistent;
- res->solved_conflicts = NULL;
- res->solved_conflicts_xml = NULL;
-
- res->nitems = s->nitems;
- memcpy (res->items, s->items, items_size);
-
- return res;
-}
-
-
-/*---------.
-| Free S. |
-`---------*/
-
-static void
-state_free (state *s)
-{
- free (s->transitions);
- free (s->reductions);
- free (s->errs);
- free (s);
-}
-
-
-/*---------------------------.
-| Set the transitions of S. |
-`---------------------------*/
-
-void
-state_transitions_set (state *s, int num, state **trans)
-{
- aver (!s->transitions);
- s->transitions = transitions_new (num, trans);
-}
-
-
-/*--------------------------.
-| Set the reductions of S. |
-`--------------------------*/
-
-void
-state_reductions_set (state *s, int num, rule **reds)
-{
- aver (!s->reductions);
- s->reductions = reductions_new (num, reds);
-}
-
-
-int
-state_reduction_find (state *s, rule *r)
-{
- int i;
- reductions *reds = s->reductions;
- for (i = 0; i < reds->num; ++i)
- if (reds->rules[i] == r)
- return i;
- return -1;
-}
-
-
-/*--------------------.
-| Set the errs of S. |
-`--------------------*/
-
-void
-state_errs_set (state *s, int num, symbol **tokens)
-{
- aver (!s->errs);
- s->errs = errs_new (num, tokens);
-}
-
-
-
-/*--------------------------------------------------.
-| Print on OUT all the lookahead tokens such that S |
-| wants to reduce R. |
-`--------------------------------------------------*/
-
-void
-state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out)
-{
- /* Find the reduction we are handling. */
- reductions *reds = s->reductions;
- int red = state_reduction_find (s, r);
-
- /* Print them if there are. */
- if (reds->lookahead_tokens && red != -1)
- {
- bitset_iterator biter;
- int k;
- char const *sep = "";
- fprintf (out, " [");
- BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
- {
- fprintf (out, "%s%s", sep, symbols[k]->tag);
- sep = ", ";
- }
- fprintf (out, "]");
- }
-}
-
-void
-state_rule_lookahead_tokens_print_xml (state *s, rule *r,
- FILE *out, int level)
-{
- /* Find the reduction we are handling. */
- reductions *reds = s->reductions;
- int red = state_reduction_find (s, r);
-
- /* Print them if there are. */
- if (reds->lookahead_tokens && red != -1)
- {
- bitset_iterator biter;
- int k;
- xml_puts (out, level, "<lookaheads>");
- BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
- {
- xml_printf (out, level + 1, "<symbol>%s</symbol>",
- xml_escape (symbols[k]->tag));
- }
- xml_puts (out, level, "</lookaheads>");
- }
-}
-
-
-/*---------------------.
-| A state hash table. |
-`---------------------*/
-
-/* Initial capacity of states hash table. */
-#define HT_INITIAL_CAPACITY 257
-
-static struct hash_table *state_table = NULL;
-
-/* Two states are equal if they have the same core items. */
-static inline bool
-state_compare (state const *s1, state const *s2)
-{
- size_t i;
-
- if (s1->nitems != s2->nitems)
- return false;
-
- for (i = 0; i < s1->nitems; ++i)
- if (s1->items[i] != s2->items[i])
- return false;
-
- return true;
-}
-
-static bool
-state_comparator (void const *s1, void const *s2)
-{
- return state_compare (s1, s2);
-}
-
-static inline size_t
-state_hash (state const *s, size_t tablesize)
-{
- /* Add up the state's item numbers to get a hash key. */
- size_t key = 0;
- size_t i;
- for (i = 0; i < s->nitems; ++i)
- key += s->items[i];
- return key % tablesize;
-}
-
-static size_t
-state_hasher (void const *s, size_t tablesize)
-{
- return state_hash (s, tablesize);
-}
-
-
-/*-------------------------------.
-| Create the states hash table. |
-`-------------------------------*/
-
-void
-state_hash_new (void)
-{
- state_table = hash_initialize (HT_INITIAL_CAPACITY,
- NULL,
- state_hasher,
- state_comparator,
- NULL);
-}
-
-
-/*---------------------------------------------.
-| Free the states hash table, not the states. |
-`---------------------------------------------*/
-
-void
-state_hash_free (void)
-{
- hash_free (state_table);
-}
-
-
-/*-----------------------------------.
-| Insert S in the state hash table. |
-`-----------------------------------*/
-
-void
-state_hash_insert (state *s)
-{
- if (!hash_insert (state_table, s))
- xalloc_die ();
-}
-
-
-/*------------------------------------------------------------------.
-| Find the state associated to the CORE, and return it. If it does |
-| not exist yet, return NULL. |
-`------------------------------------------------------------------*/
-
-state *
-state_hash_lookup (size_t nitems, item_number *core)
-{
- size_t items_size = nitems * sizeof *core;
- state *probe = xmalloc (offsetof (state, items) + items_size);
- state *entry;
-
- probe->nitems = nitems;
- memcpy (probe->items, core, items_size);
- entry = hash_lookup (state_table, probe);
- free (probe);
- return entry;
-}
-
-
-/*--------------------------------------------------------.
-| Record S and all states reachable from S in REACHABLE. |
-`--------------------------------------------------------*/
-
-static void
-state_record_reachable_states (state *s, bitset reachable)
-{
- if (bitset_test (reachable, s->number))
- return;
- bitset_set (reachable, s->number);
- {
- int i;
- for (i = 0; i < s->transitions->num; ++i)
- if (!TRANSITION_IS_DISABLED (s->transitions, i))
- state_record_reachable_states (s->transitions->states[i], reachable);
- }
-}
-
-void
-state_remove_unreachable_states (state_number old_to_new[])
-{
- state_number nstates_reachable = 0;
- bitset reachable = bitset_create (nstates, BITSET_FIXED);
- state_record_reachable_states (states[0], reachable);
- {
- state_number i;
- for (i = 0; i < nstates; ++i)
- {
- if (bitset_test (reachable, states[i]->number))
- {
- states[nstates_reachable] = states[i];
- states[nstates_reachable]->number = nstates_reachable;
- old_to_new[i] = nstates_reachable++;
- }
- else
- {
- state_free (states[i]);
- old_to_new[i] = nstates;
- }
- }
- }
- nstates = nstates_reachable;
- bitset_free (reachable);
-}
-
-/* All the decorated states, indexed by the state number. */
-state **states = NULL;
-
-
-/*----------------------.
-| Free all the states. |
-`----------------------*/
-
-void
-states_free (void)
-{
- state_number i;
- for (i = 0; i < nstates; ++i)
- state_free (states[i]);
- free (states);
-}
+/* Type definitions for the finite state machine for Bison.
+
+ Copyright (C) 2001-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <hash.h>
+
+#include "complain.h"
+#include "gram.h"
+#include "state.h"
+#include "print-xml.h"
+
+
+ /*-------------------.
+ | Shifts and Gotos. |
+ `-------------------*/
+
+
+/*-----------------------------------------.
+| Create a new array of NUM shifts/gotos. |
+`-----------------------------------------*/
+
+static transitions *
+transitions_new (int num, state **the_states)
+{
+ size_t states_size = num * sizeof *the_states;
+ transitions *res = xmalloc (offsetof (transitions, states) + states_size);
+ res->num = num;
+ memcpy (res->states, the_states, states_size);
+ return res;
+}
+
+
+/*-------------------------------------------------------.
+| Return the state such that SHIFTS contain a shift/goto |
+| to it on SYM. Abort if none found. |
+`-------------------------------------------------------*/
+
+state *
+transitions_to (transitions *shifts, symbol_number sym)
+{
+ int j;
+ for (j = 0; ; j++)
+ {
+ aver (j < shifts->num);
+ if (TRANSITION_SYMBOL (shifts, j) == sym)
+ return shifts->states[j];
+ }
+}
+
+
+ /*--------------------.
+ | Error transitions. |
+ `--------------------*/
+
+
+/*---------------------------------.
+| Create a new array of NUM errs. |
+`---------------------------------*/
+
+errs *
+errs_new (int num, symbol **tokens)
+{
+ size_t symbols_size = num * sizeof *tokens;
+ errs *res = xmalloc (offsetof (errs, symbols) + symbols_size);
+ res->num = num;
+ memcpy (res->symbols, tokens, symbols_size);
+ return res;
+}
+
+
+
+
+ /*-------------.
+ | Reductions. |
+ `-------------*/
+
+
+/*---------------------------------------.
+| Create a new array of NUM reductions. |
+`---------------------------------------*/
+
+static reductions *
+reductions_new (int num, rule **reds)
+{
+ size_t rules_size = num * sizeof *reds;
+ reductions *res = xmalloc (offsetof (reductions, rules) + rules_size);
+ res->num = num;
+ res->lookahead_tokens = NULL;
+ memcpy (res->rules, reds, rules_size);
+ return res;
+}
+
+
+
+ /*---------.
+ | States. |
+ `---------*/
+
+
+state_number nstates = 0;
+/* FINAL_STATE is properly set by new_state when it recognizes its
+ accessing symbol: $end. */
+state *final_state = NULL;
+
+
+/*------------------------------------------------------------------.
+| Create a new state with ACCESSING_SYMBOL, for those items. Store |
+| it in the state hash table. |
+`------------------------------------------------------------------*/
+
+state *
+state_new (symbol_number accessing_symbol,
+ size_t nitems, item_number *core)
+{
+ state *res;
+ size_t items_size = nitems * sizeof *core;
+
+ aver (nstates < STATE_NUMBER_MAXIMUM);
+
+ res = xmalloc (offsetof (state, items) + items_size);
+ res->number = nstates++;
+ res->accessing_symbol = accessing_symbol;
+ res->transitions = NULL;
+ res->reductions = NULL;
+ res->errs = NULL;
+ res->state_list = NULL;
+ res->consistent = 0;
+ res->solved_conflicts = NULL;
+ res->solved_conflicts_xml = NULL;
+
+ res->nitems = nitems;
+ memcpy (res->items, core, items_size);
+
+ state_hash_insert (res);
+
+ return res;
+}
+
+state *
+state_new_isocore (state const *s)
+{
+ state *res;
+ size_t items_size = s->nitems * sizeof *s->items;
+
+ aver (nstates < STATE_NUMBER_MAXIMUM);
+
+ res = xmalloc (offsetof (state, items) + items_size);
+ res->number = nstates++;
+ res->accessing_symbol = s->accessing_symbol;
+ res->transitions =
+ transitions_new (s->transitions->num, s->transitions->states);
+ res->reductions = reductions_new (s->reductions->num, s->reductions->rules);
+ res->errs = NULL;
+ res->state_list = NULL;
+ res->consistent = s->consistent;
+ res->solved_conflicts = NULL;
+ res->solved_conflicts_xml = NULL;
+
+ res->nitems = s->nitems;
+ memcpy (res->items, s->items, items_size);
+
+ return res;
+}
+
+
+/*---------.
+| Free S. |
+`---------*/
+
+static void
+state_free (state *s)
+{
+ free (s->transitions);
+ free (s->reductions);
+ free (s->errs);
+ free (s);
+}
+
+
+/*---------------------------.
+| Set the transitions of S. |
+`---------------------------*/
+
+void
+state_transitions_set (state *s, int num, state **trans)
+{
+ aver (!s->transitions);
+ s->transitions = transitions_new (num, trans);
+}
+
+
+/*--------------------------.
+| Set the reductions of S. |
+`--------------------------*/
+
+void
+state_reductions_set (state *s, int num, rule **reds)
+{
+ aver (!s->reductions);
+ s->reductions = reductions_new (num, reds);
+}
+
+
+int
+state_reduction_find (state *s, rule *r)
+{
+ int i;
+ reductions *reds = s->reductions;
+ for (i = 0; i < reds->num; ++i)
+ if (reds->rules[i] == r)
+ return i;
+ return -1;
+}
+
+
+/*--------------------.
+| Set the errs of S. |
+`--------------------*/
+
+void
+state_errs_set (state *s, int num, symbol **tokens)
+{
+ aver (!s->errs);
+ s->errs = errs_new (num, tokens);
+}
+
+
+
+/*--------------------------------------------------.
+| Print on OUT all the lookahead tokens such that S |
+| wants to reduce R. |
+`--------------------------------------------------*/
+
+void
+state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out)
+{
+ /* Find the reduction we are handling. */
+ reductions *reds = s->reductions;
+ int red = state_reduction_find (s, r);
+
+ /* Print them if there are. */
+ if (reds->lookahead_tokens && red != -1)
+ {
+ bitset_iterator biter;
+ int k;
+ char const *sep = "";
+ fprintf (out, " [");
+ BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
+ {
+ fprintf (out, "%s%s", sep, symbols[k]->tag);
+ sep = ", ";
+ }
+ fprintf (out, "]");
+ }
+}
+
+void
+state_rule_lookahead_tokens_print_xml (state *s, rule *r,
+ FILE *out, int level)
+{
+ /* Find the reduction we are handling. */
+ reductions *reds = s->reductions;
+ int red = state_reduction_find (s, r);
+
+ /* Print them if there are. */
+ if (reds->lookahead_tokens && red != -1)
+ {
+ bitset_iterator biter;
+ int k;
+ xml_puts (out, level, "<lookaheads>");
+ BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
+ {
+ xml_printf (out, level + 1, "<symbol>%s</symbol>",
+ xml_escape (symbols[k]->tag));
+ }
+ xml_puts (out, level, "</lookaheads>");
+ }
+}
+
+
+/*---------------------.
+| A state hash table. |
+`---------------------*/
+
+/* Initial capacity of states hash table. */
+#define HT_INITIAL_CAPACITY 257
+
+static struct hash_table *state_table = NULL;
+
+/* Two states are equal if they have the same core items. */
+static inline bool
+state_compare (state const *s1, state const *s2)
+{
+ size_t i;
+
+ if (s1->nitems != s2->nitems)
+ return false;
+
+ for (i = 0; i < s1->nitems; ++i)
+ if (s1->items[i] != s2->items[i])
+ return false;
+
+ return true;
+}
+
+static bool
+state_comparator (void const *s1, void const *s2)
+{
+ return state_compare (s1, s2);
+}
+
+static inline size_t
+state_hash (state const *s, size_t tablesize)
+{
+ /* Add up the state's item numbers to get a hash key. */
+ size_t key = 0;
+ size_t i;
+ for (i = 0; i < s->nitems; ++i)
+ key += s->items[i];
+ return key % tablesize;
+}
+
+static size_t
+state_hasher (void const *s, size_t tablesize)
+{
+ return state_hash (s, tablesize);
+}
+
+
+/*-------------------------------.
+| Create the states hash table. |
+`-------------------------------*/
+
+void
+state_hash_new (void)
+{
+ state_table = hash_initialize (HT_INITIAL_CAPACITY,
+ NULL,
+ state_hasher,
+ state_comparator,
+ NULL);
+}
+
+
+/*---------------------------------------------.
+| Free the states hash table, not the states. |
+`---------------------------------------------*/
+
+void
+state_hash_free (void)
+{
+ hash_free (state_table);
+}
+
+
+/*-----------------------------------.
+| Insert S in the state hash table. |
+`-----------------------------------*/
+
+void
+state_hash_insert (state *s)
+{
+ if (!hash_insert (state_table, s))
+ xalloc_die ();
+}
+
+
+/*------------------------------------------------------------------.
+| Find the state associated to the CORE, and return it. If it does |
+| not exist yet, return NULL. |
+`------------------------------------------------------------------*/
+
+state *
+state_hash_lookup (size_t nitems, item_number *core)
+{
+ size_t items_size = nitems * sizeof *core;
+ state *probe = xmalloc (offsetof (state, items) + items_size);
+ state *entry;
+
+ probe->nitems = nitems;
+ memcpy (probe->items, core, items_size);
+ entry = hash_lookup (state_table, probe);
+ free (probe);
+ return entry;
+}
+
+
+/*--------------------------------------------------------.
+| Record S and all states reachable from S in REACHABLE. |
+`--------------------------------------------------------*/
+
+static void
+state_record_reachable_states (state *s, bitset reachable)
+{
+ if (bitset_test (reachable, s->number))
+ return;
+ bitset_set (reachable, s->number);
+ {
+ int i;
+ for (i = 0; i < s->transitions->num; ++i)
+ if (!TRANSITION_IS_DISABLED (s->transitions, i))
+ state_record_reachable_states (s->transitions->states[i], reachable);
+ }
+}
+
+void
+state_remove_unreachable_states (state_number old_to_new[])
+{
+ state_number nstates_reachable = 0;
+ bitset reachable = bitset_create (nstates, BITSET_FIXED);
+ state_record_reachable_states (states[0], reachable);
+ {
+ state_number i;
+ for (i = 0; i < nstates; ++i)
+ {
+ if (bitset_test (reachable, states[i]->number))
+ {
+ states[nstates_reachable] = states[i];
+ states[nstates_reachable]->number = nstates_reachable;
+ old_to_new[i] = nstates_reachable++;
+ }
+ else
+ {
+ state_free (states[i]);
+ old_to_new[i] = nstates;
+ }
+ }
+ }
+ nstates = nstates_reachable;
+ bitset_free (reachable);
+}
+
+/* All the decorated states, indexed by the state number. */
+state **states = NULL;
+
+
+/*----------------------.
+| Free all the states. |
+`----------------------*/
+
+void
+states_free (void)
+{
+ state_number i;
+ for (i = 0; i < nstates; ++i)
+ state_free (states[i]);
+ free (states);
+}
diff --git a/contrib/tools/bison/bison/src/state.h b/contrib/tools/bison/bison/src/state.h
index 37cd9bf9ec..0cc2a0efc9 100644
--- a/contrib/tools/bison/bison/src/state.h
+++ b/contrib/tools/bison/bison/src/state.h
@@ -1,274 +1,274 @@
-/* Type definitions for the finite state machine for Bison.
-
- Copyright (C) 1984, 1989, 2000-2004, 2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/* These type definitions are used to represent a nondeterministic
- finite state machine that parses the specified grammar. This
- information is generated by the function generate_states in the
- file LR0.
-
- Each state of the machine is described by a set of items --
- particular positions in particular rules -- that are the possible
- places where parsing could continue when the machine is in this
- state. These symbols at these items are the allowable inputs that
- can follow now.
-
- A core represents one state. States are numbered in the NUMBER
- field. When generate_states is finished, the starting state is
- state 0 and NSTATES is the number of states. (FIXME: This sentence
- is no longer true: A transition to a state whose state number is
- NSTATES indicates termination.) All the cores are chained together
- and FIRST_STATE points to the first one (state 0).
-
- For each state there is a particular symbol which must have been
- the last thing accepted to reach that state. It is the
- ACCESSING_SYMBOL of the core.
-
- Each core contains a vector of NITEMS items which are the indices
- in the RITEM vector of the items that are selected in this state.
-
- The two types of actions are shifts/gotos (push the lookahead token
- and read another/goto to the state designated by a nterm) and
- reductions (combine the last n things on the stack via a rule,
- replace them with the symbol that the rule derives, and leave the
- lookahead token alone). When the states are generated, these
- actions are represented in two other lists.
-
- Each transition structure describes the possible transitions out
- of one state, the state whose number is in the number field. Each
- contains a vector of numbers of the states that transitions can go
- to. The accessing_symbol fields of those states' cores say what
- kind of input leads to them.
-
- A transition to state zero should be ignored: conflict resolution
- deletes transitions by having them point to zero.
-
- Each reductions structure describes the possible reductions at the
- state whose number is in the number field. rules is an array of
- num rules. lookahead_tokens is an array of bitsets, one per rule.
-
- Conflict resolution can decide that certain tokens in certain
- states should explicitly be errors (for implementing %nonassoc).
- For each state, the tokens that are errors for this reason are
- recorded in an errs structure, which holds the token numbers.
-
- There is at least one goto transition present in state zero. It
- leads to a next-to-final state whose accessing_symbol is the
- grammar's start symbol. The next-to-final state has one shift to
- the final state, whose accessing_symbol is zero (end of input).
- The final state has one shift, which goes to the termination state.
- The reason for the extra state at the end is to placate the
- parser's strategy of making all decisions one token ahead of its
- actions. */
-
-#ifndef STATE_H_
-# define STATE_H_
-
-# include <bitset.h>
-
-# include "gram.h"
-# include "symtab.h"
-
-
-/*-------------------.
-| Numbering states. |
-`-------------------*/
-
-typedef int state_number;
-# define STATE_NUMBER_MAXIMUM INT_MAX
-
-/* Be ready to map a state_number to an int. */
-static inline int
-state_number_as_int (state_number s)
-{
- return s;
-}
-
-
-typedef struct state state;
-
-/*--------------.
-| Transitions. |
-`--------------*/
-
-typedef struct
-{
- int num;
- state *states[1];
-} transitions;
-
-
-/* What is the symbol labelling the transition to
- TRANSITIONS->states[Num]? Can be a token (amongst which the error
- token), or non terminals in case of gotos. */
-
-# define TRANSITION_SYMBOL(Transitions, Num) \
- (Transitions->states[Num]->accessing_symbol)
-
-/* Is the TRANSITIONS->states[Num] a shift? (as opposed to gotos). */
-
-# define TRANSITION_IS_SHIFT(Transitions, Num) \
- (ISTOKEN (TRANSITION_SYMBOL (Transitions, Num)))
-
-/* Is the TRANSITIONS->states[Num] a goto?. */
-
-# define TRANSITION_IS_GOTO(Transitions, Num) \
- (!TRANSITION_IS_SHIFT (Transitions, Num))
-
-/* Is the TRANSITIONS->states[Num] labelled by the error token? */
-
-# define TRANSITION_IS_ERROR(Transitions, Num) \
- (TRANSITION_SYMBOL (Transitions, Num) == errtoken->number)
-
-/* When resolving a SR conflicts, if the reduction wins, the shift is
- disabled. */
-
-# define TRANSITION_DISABLE(Transitions, Num) \
- (Transitions->states[Num] = NULL)
-
-# define TRANSITION_IS_DISABLED(Transitions, Num) \
- (Transitions->states[Num] == NULL)
-
-
-/* Iterate over each transition over a token (shifts). */
-# define FOR_EACH_SHIFT(Transitions, Iter) \
- for (Iter = 0; \
- Iter < Transitions->num \
- && (TRANSITION_IS_DISABLED (Transitions, Iter) \
- || TRANSITION_IS_SHIFT (Transitions, Iter)); \
- ++Iter) \
- if (!TRANSITION_IS_DISABLED (Transitions, Iter))
-
-
-/* Return the state such SHIFTS contain a shift/goto to it on SYM.
- Abort if none found. */
-struct state *transitions_to (transitions *shifts, symbol_number sym);
-
-
-/*-------.
-| Errs. |
-`-------*/
-
-typedef struct
-{
- int num;
- symbol *symbols[1];
-} errs;
-
-errs *errs_new (int num, symbol **tokens);
-
-
-/*-------------.
-| Reductions. |
-`-------------*/
-
-typedef struct
-{
- int num;
- bitset *lookahead_tokens;
- /* Sorted ascendingly on rule number. */
- rule *rules[1];
-} reductions;
-
-
-
-/*---------.
-| states. |
-`---------*/
-
-struct state_list;
-
-struct state
-{
- state_number number;
- symbol_number accessing_symbol;
- transitions *transitions;
- reductions *reductions;
- errs *errs;
-
- /* When an includer (such as ielr.c) needs to store states in a list, the
- includer can define struct state_list as the list node structure and can
- store in this member a reference to the node containing each state. */
- struct state_list *state_list;
-
- /* If non-zero, then no lookahead sets on reduce actions are needed to
- decide what to do in state S. */
- char consistent;
-
- /* If some conflicts were solved thanks to precedence/associativity,
- a human readable description of the resolution. */
- const char *solved_conflicts;
- const char *solved_conflicts_xml;
-
- /* Its items. Must be last, since ITEMS can be arbitrarily large. Sorted
- ascendingly on item index in RITEM, which is sorted on rule number. */
- size_t nitems;
- item_number items[1];
-};
-
-extern state_number nstates;
-extern state *final_state;
-
-/* Create a new state with ACCESSING_SYMBOL for those items. */
-state *state_new (symbol_number accessing_symbol,
- size_t core_size, item_number *core);
-state *state_new_isocore (state const *s);
-
-/* Set the transitions of STATE. */
-void state_transitions_set (state *s, int num, state **trans);
-
-/* Set the reductions of STATE. */
-void state_reductions_set (state *s, int num, rule **reds);
-
-int state_reduction_find (state *s, rule *r);
-
-/* Set the errs of STATE. */
-void state_errs_set (state *s, int num, symbol **errors);
-
-/* Print on OUT all the lookahead tokens such that this STATE wants to
- reduce R. */
-void state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out);
-void state_rule_lookahead_tokens_print_xml (state *s, rule *r,
- FILE *out, int level);
-
-/* Create/destroy the states hash table. */
-void state_hash_new (void);
-void state_hash_free (void);
-
-/* Find the state associated to the CORE, and return it. If it does
- not exist yet, return NULL. */
-state *state_hash_lookup (size_t core_size, item_number *core);
-
-/* Insert STATE in the state hash table. */
-void state_hash_insert (state *s);
-
-/* Remove unreachable states, renumber remaining states, update NSTATES, and
- write to OLD_TO_NEW a mapping of old state numbers to new state numbers such
- that the old value of NSTATES is written as the new state number for removed
- states. The size of OLD_TO_NEW must be the old value of NSTATES. */
-void state_remove_unreachable_states (state_number old_to_new[]);
-
-/* All the states, indexed by the state number. */
-extern state **states;
-
-/* Free all the states. */
-void states_free (void);
-
-#endif /* !STATE_H_ */
+/* Type definitions for the finite state machine for Bison.
+
+ Copyright (C) 1984, 1989, 2000-2004, 2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+/* These type definitions are used to represent a nondeterministic
+ finite state machine that parses the specified grammar. This
+ information is generated by the function generate_states in the
+ file LR0.
+
+ Each state of the machine is described by a set of items --
+ particular positions in particular rules -- that are the possible
+ places where parsing could continue when the machine is in this
+ state. These symbols at these items are the allowable inputs that
+ can follow now.
+
+ A core represents one state. States are numbered in the NUMBER
+ field. When generate_states is finished, the starting state is
+ state 0 and NSTATES is the number of states. (FIXME: This sentence
+ is no longer true: A transition to a state whose state number is
+ NSTATES indicates termination.) All the cores are chained together
+ and FIRST_STATE points to the first one (state 0).
+
+ For each state there is a particular symbol which must have been
+ the last thing accepted to reach that state. It is the
+ ACCESSING_SYMBOL of the core.
+
+ Each core contains a vector of NITEMS items which are the indices
+ in the RITEM vector of the items that are selected in this state.
+
+ The two types of actions are shifts/gotos (push the lookahead token
+ and read another/goto to the state designated by a nterm) and
+ reductions (combine the last n things on the stack via a rule,
+ replace them with the symbol that the rule derives, and leave the
+ lookahead token alone). When the states are generated, these
+ actions are represented in two other lists.
+
+ Each transition structure describes the possible transitions out
+ of one state, the state whose number is in the number field. Each
+ contains a vector of numbers of the states that transitions can go
+ to. The accessing_symbol fields of those states' cores say what
+ kind of input leads to them.
+
+ A transition to state zero should be ignored: conflict resolution
+ deletes transitions by having them point to zero.
+
+ Each reductions structure describes the possible reductions at the
+ state whose number is in the number field. rules is an array of
+ num rules. lookahead_tokens is an array of bitsets, one per rule.
+
+ Conflict resolution can decide that certain tokens in certain
+ states should explicitly be errors (for implementing %nonassoc).
+ For each state, the tokens that are errors for this reason are
+ recorded in an errs structure, which holds the token numbers.
+
+ There is at least one goto transition present in state zero. It
+ leads to a next-to-final state whose accessing_symbol is the
+ grammar's start symbol. The next-to-final state has one shift to
+ the final state, whose accessing_symbol is zero (end of input).
+ The final state has one shift, which goes to the termination state.
+ The reason for the extra state at the end is to placate the
+ parser's strategy of making all decisions one token ahead of its
+ actions. */
+
+#ifndef STATE_H_
+# define STATE_H_
+
+# include <bitset.h>
+
+# include "gram.h"
+# include "symtab.h"
+
+
+/*-------------------.
+| Numbering states. |
+`-------------------*/
+
+typedef int state_number;
+# define STATE_NUMBER_MAXIMUM INT_MAX
+
+/* Be ready to map a state_number to an int. */
+static inline int
+state_number_as_int (state_number s)
+{
+ return s;
+}
+
+
+typedef struct state state;
+
+/*--------------.
+| Transitions. |
+`--------------*/
+
+typedef struct
+{
+ int num;
+ state *states[1];
+} transitions;
+
+
+/* What is the symbol labelling the transition to
+ TRANSITIONS->states[Num]? Can be a token (amongst which the error
+ token), or non terminals in case of gotos. */
+
+# define TRANSITION_SYMBOL(Transitions, Num) \
+ (Transitions->states[Num]->accessing_symbol)
+
+/* Is the TRANSITIONS->states[Num] a shift? (as opposed to gotos). */
+
+# define TRANSITION_IS_SHIFT(Transitions, Num) \
+ (ISTOKEN (TRANSITION_SYMBOL (Transitions, Num)))
+
+/* Is the TRANSITIONS->states[Num] a goto?. */
+
+# define TRANSITION_IS_GOTO(Transitions, Num) \
+ (!TRANSITION_IS_SHIFT (Transitions, Num))
+
+/* Is the TRANSITIONS->states[Num] labelled by the error token? */
+
+# define TRANSITION_IS_ERROR(Transitions, Num) \
+ (TRANSITION_SYMBOL (Transitions, Num) == errtoken->number)
+
+/* When resolving a SR conflicts, if the reduction wins, the shift is
+ disabled. */
+
+# define TRANSITION_DISABLE(Transitions, Num) \
+ (Transitions->states[Num] = NULL)
+
+# define TRANSITION_IS_DISABLED(Transitions, Num) \
+ (Transitions->states[Num] == NULL)
+
+
+/* Iterate over each transition over a token (shifts). */
+# define FOR_EACH_SHIFT(Transitions, Iter) \
+ for (Iter = 0; \
+ Iter < Transitions->num \
+ && (TRANSITION_IS_DISABLED (Transitions, Iter) \
+ || TRANSITION_IS_SHIFT (Transitions, Iter)); \
+ ++Iter) \
+ if (!TRANSITION_IS_DISABLED (Transitions, Iter))
+
+
+/* Return the state such SHIFTS contain a shift/goto to it on SYM.
+ Abort if none found. */
+struct state *transitions_to (transitions *shifts, symbol_number sym);
+
+
+/*-------.
+| Errs. |
+`-------*/
+
+typedef struct
+{
+ int num;
+ symbol *symbols[1];
+} errs;
+
+errs *errs_new (int num, symbol **tokens);
+
+
+/*-------------.
+| Reductions. |
+`-------------*/
+
+typedef struct
+{
+ int num;
+ bitset *lookahead_tokens;
+ /* Sorted ascendingly on rule number. */
+ rule *rules[1];
+} reductions;
+
+
+
+/*---------.
+| states. |
+`---------*/
+
+struct state_list;
+
+struct state
+{
+ state_number number;
+ symbol_number accessing_symbol;
+ transitions *transitions;
+ reductions *reductions;
+ errs *errs;
+
+ /* When an includer (such as ielr.c) needs to store states in a list, the
+ includer can define struct state_list as the list node structure and can
+ store in this member a reference to the node containing each state. */
+ struct state_list *state_list;
+
+ /* If non-zero, then no lookahead sets on reduce actions are needed to
+ decide what to do in state S. */
+ char consistent;
+
+ /* If some conflicts were solved thanks to precedence/associativity,
+ a human readable description of the resolution. */
+ const char *solved_conflicts;
+ const char *solved_conflicts_xml;
+
+ /* Its items. Must be last, since ITEMS can be arbitrarily large. Sorted
+ ascendingly on item index in RITEM, which is sorted on rule number. */
+ size_t nitems;
+ item_number items[1];
+};
+
+extern state_number nstates;
+extern state *final_state;
+
+/* Create a new state with ACCESSING_SYMBOL for those items. */
+state *state_new (symbol_number accessing_symbol,
+ size_t core_size, item_number *core);
+state *state_new_isocore (state const *s);
+
+/* Set the transitions of STATE. */
+void state_transitions_set (state *s, int num, state **trans);
+
+/* Set the reductions of STATE. */
+void state_reductions_set (state *s, int num, rule **reds);
+
+int state_reduction_find (state *s, rule *r);
+
+/* Set the errs of STATE. */
+void state_errs_set (state *s, int num, symbol **errors);
+
+/* Print on OUT all the lookahead tokens such that this STATE wants to
+ reduce R. */
+void state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out);
+void state_rule_lookahead_tokens_print_xml (state *s, rule *r,
+ FILE *out, int level);
+
+/* Create/destroy the states hash table. */
+void state_hash_new (void);
+void state_hash_free (void);
+
+/* Find the state associated to the CORE, and return it. If it does
+ not exist yet, return NULL. */
+state *state_hash_lookup (size_t core_size, item_number *core);
+
+/* Insert STATE in the state hash table. */
+void state_hash_insert (state *s);
+
+/* Remove unreachable states, renumber remaining states, update NSTATES, and
+ write to OLD_TO_NEW a mapping of old state numbers to new state numbers such
+ that the old value of NSTATES is written as the new state number for removed
+ states. The size of OLD_TO_NEW must be the old value of NSTATES. */
+void state_remove_unreachable_states (state_number old_to_new[]);
+
+/* All the states, indexed by the state number. */
+extern state **states;
+
+/* Free all the states. */
+void states_free (void);
+
+#endif /* !STATE_H_ */
diff --git a/contrib/tools/bison/bison/src/symlist.c b/contrib/tools/bison/bison/src/symlist.c
index 531ec52fb8..8fdae784d1 100644
--- a/contrib/tools/bison/bison/src/symlist.c
+++ b/contrib/tools/bison/bison/src/symlist.c
@@ -1,239 +1,239 @@
-/* Lists of symbols for Bison
-
- Copyright (C) 2002, 2005-2007, 2009-2013 Free Software Foundation,
- Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include "complain.h"
-#include "symlist.h"
-
-/*--------------------------------------.
-| Create a list containing SYM at LOC. |
-`--------------------------------------*/
-
-symbol_list *
-symbol_list_sym_new (symbol *sym, location loc)
-{
- symbol_list *res = xmalloc (sizeof *res);
-
- res->content_type = SYMLIST_SYMBOL;
- res->content.sym = sym;
- res->location = res->sym_loc = loc;
- res->named_ref = NULL;
-
- res->midrule = NULL;
- res->midrule_parent_rule = NULL;
- res->midrule_parent_rhs_index = 0;
-
- /* Members used for LHS only. */
- res->ruleprec = NULL;
- res->percent_empty_loc = empty_location;
- code_props_none_init (&res->action_props);
- res->dprec = 0;
- res->dprec_location = empty_location;
- res->merger = 0;
- res->merger_declaration_location = empty_location;
-
- res->next = NULL;
-
- return res;
-}
-
-
-/*--------------------------------------------.
-| Create a list containing TYPE_NAME at LOC. |
-`--------------------------------------------*/
-
-symbol_list *
-symbol_list_type_new (uniqstr type_name, location loc)
-{
- symbol_list *res = xmalloc (sizeof *res);
-
- res->content_type = SYMLIST_TYPE;
- res->content.sem_type = xmalloc (sizeof (semantic_type));
- res->content.sem_type->tag = type_name;
- res->content.sem_type->location = loc;
- res->content.sem_type->status = undeclared;
-
- res->location = res->sym_loc = loc;
- res->named_ref = NULL;
- res->next = NULL;
-
- return res;
-}
-
-
-/*-----------------------------------------------------------------------.
-| Print this list, for which every content_type must be SYMLIST_SYMBOL. |
-`-----------------------------------------------------------------------*/
-
-void
-symbol_list_syms_print (const symbol_list *l, FILE *f)
-{
- char const *sep = "";
- for (/* Nothing. */; l && l->content.sym; l = l->next)
- {
- fputs (sep, f);
- fputs (l->content_type == SYMLIST_SYMBOL ? "symbol: "
- : l->content_type == SYMLIST_TYPE ? "type: "
- : "invalid content_type: ",
- f);
- symbol_print (l->content.sym, f);
- fputs (l->action_props.is_value_used ? " used" : " unused", f);
- sep = ", ";
- }
-}
-
-
-/*---------------------------.
-| Prepend NODE to the LIST. |
-`---------------------------*/
-
-symbol_list *
-symbol_list_prepend (symbol_list *list, symbol_list *node)
-{
- node->next = list;
- return node;
-}
-
-
-/*-------------------------.
-| Append NODE to the LIST. |
-`-------------------------*/
-
-symbol_list *
-symbol_list_append (symbol_list *list, symbol_list *node)
-{
- symbol_list* next;
- if (!list)
- return node;
- next = list;
- while (next->next)
- next = next->next;
- next->next = node;
- return list;
-}
-
-
-/*-----------------------------------------------.
-| Free the LIST, but not the items it contains. |
-`-----------------------------------------------*/
-
-void
-symbol_list_free (symbol_list *list)
-{
- symbol_list *node, *next;
- for (node = list; node; node = next)
- {
- next = node->next;
- named_ref_free (node->named_ref);
- if (node->content_type == SYMLIST_TYPE)
- free (node->content.sem_type);
- free (node);
- }
-}
-
-
-/*--------------------.
-| Return its length. |
-`--------------------*/
-
-int
-symbol_list_length (symbol_list const *l)
-{
- int res = 0;
- for (/* Nothing. */;
- l && !(l->content_type == SYMLIST_SYMBOL && l->content.sym == NULL);
- l = l->next)
- ++res;
- return res;
-}
-
-
-/*------------------------------.
-| Get item N in symbol list L. |
-`------------------------------*/
-
-symbol_list *
-symbol_list_n_get (symbol_list *l, int n)
-{
- int i;
-
- if (n < 0)
- return NULL;
-
- for (i = 0; i < n; ++i)
- {
- l = l->next;
- if (l == NULL
- || (l->content_type == SYMLIST_SYMBOL && l->content.sym == NULL))
- return NULL;
- }
-
- return l;
-}
-
-
-/*--------------------------------------------------------------.
-| Get the data type (alternative in the union) of the value for |
-| symbol N in symbol list L. |
-`--------------------------------------------------------------*/
-
-uniqstr
-symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
-{
- l = symbol_list_n_get (l, n);
- if (!l)
- {
- complain (&loc, complaint, _("invalid $ value: $%d"), n);
- return NULL;
- }
- aver (l->content_type == SYMLIST_SYMBOL);
- return l->content.sym->type_name;
-}
-
-bool
-symbol_list_null (symbol_list *node)
-{
- return !node ||
- (node->content_type == SYMLIST_SYMBOL && !(node->content.sym));
-}
-
-void
-symbol_list_code_props_set (symbol_list *node, code_props_type kind,
- code_props const *cprops)
-{
- switch (node->content_type)
- {
- case SYMLIST_SYMBOL:
- symbol_code_props_set (node->content.sym, kind, cprops);
- if (node->content.sym->status == undeclared)
- node->content.sym->status = used;
- break;
- case SYMLIST_TYPE:
- semantic_type_code_props_set
- (semantic_type_get (node->content.sem_type->tag,
- &node->content.sem_type->location),
- kind, cprops);
- if (node->content.sem_type->status == undeclared)
- node->content.sem_type->status = used;
- break;
- }
-}
+/* Lists of symbols for Bison
+
+ Copyright (C) 2002, 2005-2007, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include "complain.h"
+#include "symlist.h"
+
+/*--------------------------------------.
+| Create a list containing SYM at LOC. |
+`--------------------------------------*/
+
+symbol_list *
+symbol_list_sym_new (symbol *sym, location loc)
+{
+ symbol_list *res = xmalloc (sizeof *res);
+
+ res->content_type = SYMLIST_SYMBOL;
+ res->content.sym = sym;
+ res->location = res->sym_loc = loc;
+ res->named_ref = NULL;
+
+ res->midrule = NULL;
+ res->midrule_parent_rule = NULL;
+ res->midrule_parent_rhs_index = 0;
+
+ /* Members used for LHS only. */
+ res->ruleprec = NULL;
+ res->percent_empty_loc = empty_location;
+ code_props_none_init (&res->action_props);
+ res->dprec = 0;
+ res->dprec_location = empty_location;
+ res->merger = 0;
+ res->merger_declaration_location = empty_location;
+
+ res->next = NULL;
+
+ return res;
+}
+
+
+/*--------------------------------------------.
+| Create a list containing TYPE_NAME at LOC. |
+`--------------------------------------------*/
+
+symbol_list *
+symbol_list_type_new (uniqstr type_name, location loc)
+{
+ symbol_list *res = xmalloc (sizeof *res);
+
+ res->content_type = SYMLIST_TYPE;
+ res->content.sem_type = xmalloc (sizeof (semantic_type));
+ res->content.sem_type->tag = type_name;
+ res->content.sem_type->location = loc;
+ res->content.sem_type->status = undeclared;
+
+ res->location = res->sym_loc = loc;
+ res->named_ref = NULL;
+ res->next = NULL;
+
+ return res;
+}
+
+
+/*-----------------------------------------------------------------------.
+| Print this list, for which every content_type must be SYMLIST_SYMBOL. |
+`-----------------------------------------------------------------------*/
+
+void
+symbol_list_syms_print (const symbol_list *l, FILE *f)
+{
+ char const *sep = "";
+ for (/* Nothing. */; l && l->content.sym; l = l->next)
+ {
+ fputs (sep, f);
+ fputs (l->content_type == SYMLIST_SYMBOL ? "symbol: "
+ : l->content_type == SYMLIST_TYPE ? "type: "
+ : "invalid content_type: ",
+ f);
+ symbol_print (l->content.sym, f);
+ fputs (l->action_props.is_value_used ? " used" : " unused", f);
+ sep = ", ";
+ }
+}
+
+
+/*---------------------------.
+| Prepend NODE to the LIST. |
+`---------------------------*/
+
+symbol_list *
+symbol_list_prepend (symbol_list *list, symbol_list *node)
+{
+ node->next = list;
+ return node;
+}
+
+
+/*-------------------------.
+| Append NODE to the LIST. |
+`-------------------------*/
+
+symbol_list *
+symbol_list_append (symbol_list *list, symbol_list *node)
+{
+ symbol_list* next;
+ if (!list)
+ return node;
+ next = list;
+ while (next->next)
+ next = next->next;
+ next->next = node;
+ return list;
+}
+
+
+/*-----------------------------------------------.
+| Free the LIST, but not the items it contains. |
+`-----------------------------------------------*/
+
+void
+symbol_list_free (symbol_list *list)
+{
+ symbol_list *node, *next;
+ for (node = list; node; node = next)
+ {
+ next = node->next;
+ named_ref_free (node->named_ref);
+ if (node->content_type == SYMLIST_TYPE)
+ free (node->content.sem_type);
+ free (node);
+ }
+}
+
+
+/*--------------------.
+| Return its length. |
+`--------------------*/
+
+int
+symbol_list_length (symbol_list const *l)
+{
+ int res = 0;
+ for (/* Nothing. */;
+ l && !(l->content_type == SYMLIST_SYMBOL && l->content.sym == NULL);
+ l = l->next)
+ ++res;
+ return res;
+}
+
+
+/*------------------------------.
+| Get item N in symbol list L. |
+`------------------------------*/
+
+symbol_list *
+symbol_list_n_get (symbol_list *l, int n)
+{
+ int i;
+
+ if (n < 0)
+ return NULL;
+
+ for (i = 0; i < n; ++i)
+ {
+ l = l->next;
+ if (l == NULL
+ || (l->content_type == SYMLIST_SYMBOL && l->content.sym == NULL))
+ return NULL;
+ }
+
+ return l;
+}
+
+
+/*--------------------------------------------------------------.
+| Get the data type (alternative in the union) of the value for |
+| symbol N in symbol list L. |
+`--------------------------------------------------------------*/
+
+uniqstr
+symbol_list_n_type_name_get (symbol_list *l, location loc, int n)
+{
+ l = symbol_list_n_get (l, n);
+ if (!l)
+ {
+ complain (&loc, complaint, _("invalid $ value: $%d"), n);
+ return NULL;
+ }
+ aver (l->content_type == SYMLIST_SYMBOL);
+ return l->content.sym->type_name;
+}
+
+bool
+symbol_list_null (symbol_list *node)
+{
+ return !node ||
+ (node->content_type == SYMLIST_SYMBOL && !(node->content.sym));
+}
+
+void
+symbol_list_code_props_set (symbol_list *node, code_props_type kind,
+ code_props const *cprops)
+{
+ switch (node->content_type)
+ {
+ case SYMLIST_SYMBOL:
+ symbol_code_props_set (node->content.sym, kind, cprops);
+ if (node->content.sym->status == undeclared)
+ node->content.sym->status = used;
+ break;
+ case SYMLIST_TYPE:
+ semantic_type_code_props_set
+ (semantic_type_get (node->content.sem_type->tag,
+ &node->content.sem_type->location),
+ kind, cprops);
+ if (node->content.sem_type->status == undeclared)
+ node->content.sem_type->status = used;
+ break;
+ }
+}
diff --git a/contrib/tools/bison/bison/src/symlist.h b/contrib/tools/bison/bison/src/symlist.h
index c369f69bb1..4254d2629f 100644
--- a/contrib/tools/bison/bison/src/symlist.h
+++ b/contrib/tools/bison/bison/src/symlist.h
@@ -1,133 +1,133 @@
-/* Lists of symbols for Bison
-
- Copyright (C) 2002, 2005-2007, 2009-2013 Free Software Foundation,
- Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SYMLIST_H_
-# define SYMLIST_H_
-
-# include "location.h"
-# include "scan-code.h"
-# include "symtab.h"
-# include "named-ref.h"
-
-/* A list of symbols, used during the parsing to store the rules. */
-typedef struct symbol_list
-{
- /**
- * Whether this node contains a symbol, a semantic type, a \c <*>, or a
- * \c <>.
- */
- enum {
- SYMLIST_SYMBOL,
- SYMLIST_TYPE
- } content_type;
- union {
- /**
- * The symbol or \c NULL iff
- * <tt>symbol_list::content_type = SYMLIST_SYMBOL</tt>.
- */
- symbol *sym;
- /**
- * The semantic type iff <tt>symbol_list::content_type = SYMLIST_TYPE</tt>.
- */
- semantic_type *sem_type;
- } content;
- location location;
-
- /* Named reference. */
- named_ref *named_ref;
-
- /* Proper location of the symbol, not all the rule */
- location sym_loc;
-
- /* If this symbol is the generated lhs for a midrule but this is the rule in
- whose rhs it appears, MIDRULE = a pointer to that midrule. */
- struct symbol_list *midrule;
-
- /* If this symbol is the generated lhs for a midrule and this is that
- midrule, MIDRULE_PARENT_RULE = a pointer to the rule in whose rhs it
- appears, and MIDRULE_PARENT_RHS_INDEX = its rhs index (1-origin) in the
- parent rule. */
- struct symbol_list *midrule_parent_rule;
- int midrule_parent_rhs_index;
-
- /* ---------------------------------------------- */
- /* Apply to the rule (attached to the LHS only). */
- /* ---------------------------------------------- */
-
- /* Precedence/associativity. */
- symbol *ruleprec;
-
- /* The action is attached to the LHS of a rule, but action properties for
- * each RHS are also stored here. */
- code_props action_props;
-
- /* The location of the first %empty for this rule, or \a
- empty_location. */
- location percent_empty_loc;
-
- int dprec;
- location dprec_location;
- int merger;
- location merger_declaration_location;
-
- /* The list. */
- struct symbol_list *next;
-} symbol_list;
-
-
-/** Create a list containing \c sym at \c loc. */
-symbol_list *symbol_list_sym_new (symbol *sym, location loc);
-
-/** Create a list containing \c type_name at \c loc. */
-symbol_list *symbol_list_type_new (uniqstr type_name, location loc);
-
-/** Print this list.
-
- \pre For every node \c n in the list, <tt>n->content_type =
- SYMLIST_SYMBOL</tt>. */
-void symbol_list_syms_print (const symbol_list *l, FILE *f);
-
-/** Prepend \c node to \c list. */
-symbol_list *symbol_list_prepend (symbol_list *list, symbol_list *node);
-
-/** Append \c node to \c list. */
-symbol_list *symbol_list_append (symbol_list *list, symbol_list *node);
-
-/** Free \c list, but not the items it contains. */
-void symbol_list_free (symbol_list *list);
-
-/** Return the length of \c l. */
-int symbol_list_length (symbol_list const *l);
-
-/** Get item \c n in symbol list \c l. */
-symbol_list *symbol_list_n_get (symbol_list *l, int n);
-
-/* Get the data type (alternative in the union) of the value for
- symbol N in rule RULE. */
-uniqstr symbol_list_n_type_name_get (symbol_list *l, location loc, int n);
-
-/* Check whether the node is a border element of a rule. */
-bool symbol_list_null (symbol_list *node);
-
-/** Set the \c \%destructor or \c \%printer for \c node as \c cprops. */
-void symbol_list_code_props_set (symbol_list *node, code_props_type kind,
- code_props const *cprops);
-
-#endif /* !SYMLIST_H_ */
+/* Lists of symbols for Bison
+
+ Copyright (C) 2002, 2005-2007, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SYMLIST_H_
+# define SYMLIST_H_
+
+# include "location.h"
+# include "scan-code.h"
+# include "symtab.h"
+# include "named-ref.h"
+
+/* A list of symbols, used during the parsing to store the rules. */
+typedef struct symbol_list
+{
+ /**
+ * Whether this node contains a symbol, a semantic type, a \c <*>, or a
+ * \c <>.
+ */
+ enum {
+ SYMLIST_SYMBOL,
+ SYMLIST_TYPE
+ } content_type;
+ union {
+ /**
+ * The symbol or \c NULL iff
+ * <tt>symbol_list::content_type = SYMLIST_SYMBOL</tt>.
+ */
+ symbol *sym;
+ /**
+ * The semantic type iff <tt>symbol_list::content_type = SYMLIST_TYPE</tt>.
+ */
+ semantic_type *sem_type;
+ } content;
+ location location;
+
+ /* Named reference. */
+ named_ref *named_ref;
+
+ /* Proper location of the symbol, not all the rule */
+ location sym_loc;
+
+ /* If this symbol is the generated lhs for a midrule but this is the rule in
+ whose rhs it appears, MIDRULE = a pointer to that midrule. */
+ struct symbol_list *midrule;
+
+ /* If this symbol is the generated lhs for a midrule and this is that
+ midrule, MIDRULE_PARENT_RULE = a pointer to the rule in whose rhs it
+ appears, and MIDRULE_PARENT_RHS_INDEX = its rhs index (1-origin) in the
+ parent rule. */
+ struct symbol_list *midrule_parent_rule;
+ int midrule_parent_rhs_index;
+
+ /* ---------------------------------------------- */
+ /* Apply to the rule (attached to the LHS only). */
+ /* ---------------------------------------------- */
+
+ /* Precedence/associativity. */
+ symbol *ruleprec;
+
+ /* The action is attached to the LHS of a rule, but action properties for
+ * each RHS are also stored here. */
+ code_props action_props;
+
+ /* The location of the first %empty for this rule, or \a
+ empty_location. */
+ location percent_empty_loc;
+
+ int dprec;
+ location dprec_location;
+ int merger;
+ location merger_declaration_location;
+
+ /* The list. */
+ struct symbol_list *next;
+} symbol_list;
+
+
+/** Create a list containing \c sym at \c loc. */
+symbol_list *symbol_list_sym_new (symbol *sym, location loc);
+
+/** Create a list containing \c type_name at \c loc. */
+symbol_list *symbol_list_type_new (uniqstr type_name, location loc);
+
+/** Print this list.
+
+ \pre For every node \c n in the list, <tt>n->content_type =
+ SYMLIST_SYMBOL</tt>. */
+void symbol_list_syms_print (const symbol_list *l, FILE *f);
+
+/** Prepend \c node to \c list. */
+symbol_list *symbol_list_prepend (symbol_list *list, symbol_list *node);
+
+/** Append \c node to \c list. */
+symbol_list *symbol_list_append (symbol_list *list, symbol_list *node);
+
+/** Free \c list, but not the items it contains. */
+void symbol_list_free (symbol_list *list);
+
+/** Return the length of \c l. */
+int symbol_list_length (symbol_list const *l);
+
+/** Get item \c n in symbol list \c l. */
+symbol_list *symbol_list_n_get (symbol_list *l, int n);
+
+/* Get the data type (alternative in the union) of the value for
+ symbol N in rule RULE. */
+uniqstr symbol_list_n_type_name_get (symbol_list *l, location loc, int n);
+
+/* Check whether the node is a border element of a rule. */
+bool symbol_list_null (symbol_list *node);
+
+/** Set the \c \%destructor or \c \%printer for \c node as \c cprops. */
+void symbol_list_code_props_set (symbol_list *node, code_props_type kind,
+ code_props const *cprops);
+
+#endif /* !SYMLIST_H_ */
diff --git a/contrib/tools/bison/bison/src/symtab.c b/contrib/tools/bison/bison/src/symtab.c
index c06fcd2621..94a7b600e5 100644
--- a/contrib/tools/bison/bison/src/symtab.c
+++ b/contrib/tools/bison/bison/src/symtab.c
@@ -1,1178 +1,1178 @@
-/* Symbol table manager for Bison.
-
- Copyright (C) 1984, 1989, 2000-2002, 2004-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <hash.h>
-
-#include "complain.h"
-#include "gram.h"
-#include "symtab.h"
-
-/*-------------------------------------------------------------------.
-| Symbols sorted by tag. Allocated by the first invocation of |
-| symbols_do, after which no more symbols should be created. |
-`-------------------------------------------------------------------*/
-
-static symbol **symbols_sorted = NULL;
-static symbol **semantic_types_sorted = NULL;
-
-/*------------------------.
-| Distinguished symbols. |
-`------------------------*/
-
-symbol *errtoken = NULL;
-symbol *undeftoken = NULL;
-symbol *endtoken = NULL;
-symbol *accept = NULL;
-symbol *startsymbol = NULL;
-location startsymbol_location;
-
-/*---------------------------.
-| Precedence relation graph. |
-`---------------------------*/
-
-static symgraph **prec_nodes;
-
-/*-----------------------------------.
-| Store which associativity is used. |
-`-----------------------------------*/
-
-bool *used_assoc = NULL;
-
-/*---------------------------------.
-| Create a new symbol, named TAG. |
-`---------------------------------*/
-
-static symbol *
-symbol_new (uniqstr tag, location loc)
-{
- symbol *res = xmalloc (sizeof *res);
- uniqstr_assert (tag);
-
- /* If the tag is not a string (starts with a double quote), check
- that it is valid for Yacc. */
- if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-'))
- complain (&loc, Wyacc,
- _("POSIX Yacc forbids dashes in symbol names: %s"), tag);
-
- res->tag = tag;
- res->location = loc;
-
- res->type_name = NULL;
- {
- int i;
- for (i = 0; i < CODE_PROPS_SIZE; ++i)
- code_props_none_init (&res->props[i]);
- }
-
- res->number = NUMBER_UNDEFINED;
- res->prec = 0;
- res->assoc = undef_assoc;
- res->user_token_number = USER_NUMBER_UNDEFINED;
-
- res->alias = NULL;
- res->class = unknown_sym;
- res->status = undeclared;
-
- if (nsyms == SYMBOL_NUMBER_MAXIMUM)
- complain (NULL, fatal, _("too many symbols in input grammar (limit is %d)"),
- SYMBOL_NUMBER_MAXIMUM);
- nsyms++;
- return res;
-}
-
-char const *
-code_props_type_string (code_props_type kind)
-{
- switch (kind)
- {
- case destructor:
- return "%destructor";
- case printer:
- return "%printer";
- }
- assert (0);
-}
-
-/*----------------------------------------.
-| Create a new semantic type, named TAG. |
-`----------------------------------------*/
-
-static semantic_type *
-semantic_type_new (uniqstr tag, const location *loc)
-{
- semantic_type *res = xmalloc (sizeof *res);
-
- uniqstr_assert (tag);
- res->tag = tag;
- res->location = loc ? *loc : empty_location;
- res->status = undeclared;
- {
- int i;
- for (i = 0; i < CODE_PROPS_SIZE; ++i)
- code_props_none_init (&res->props[i]);
- }
-
- return res;
-}
-
-
-/*-----------------.
-| Print a symbol. |
-`-----------------*/
-
-#define SYMBOL_ATTR_PRINT(Attr) \
- if (s->Attr) \
- fprintf (f, " %s { %s }", #Attr, s->Attr)
-
-#define SYMBOL_CODE_PRINT(Attr) \
- if (s->props[Attr].code) \
- fprintf (f, " %s { %s }", #Attr, s->props[Attr].code)
-
-void
-symbol_print (symbol const *s, FILE *f)
-{
- if (s)
- {
- fputs (s->tag, f);
- SYMBOL_ATTR_PRINT (type_name);
- SYMBOL_CODE_PRINT (destructor);
- SYMBOL_CODE_PRINT (printer);
- }
- else
- fputs ("<NULL>", f);
-}
-
-#undef SYMBOL_ATTR_PRINT
-#undef SYMBOL_CODE_PRINT
-
-
-/*----------------------------------.
-| Whether S is a valid identifier. |
-`----------------------------------*/
-
-static bool
-is_identifier (uniqstr s)
-{
+/* Symbol table manager for Bison.
+
+ Copyright (C) 1984, 1989, 2000-2002, 2004-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <hash.h>
+
+#include "complain.h"
+#include "gram.h"
+#include "symtab.h"
+
+/*-------------------------------------------------------------------.
+| Symbols sorted by tag. Allocated by the first invocation of |
+| symbols_do, after which no more symbols should be created. |
+`-------------------------------------------------------------------*/
+
+static symbol **symbols_sorted = NULL;
+static symbol **semantic_types_sorted = NULL;
+
+/*------------------------.
+| Distinguished symbols. |
+`------------------------*/
+
+symbol *errtoken = NULL;
+symbol *undeftoken = NULL;
+symbol *endtoken = NULL;
+symbol *accept = NULL;
+symbol *startsymbol = NULL;
+location startsymbol_location;
+
+/*---------------------------.
+| Precedence relation graph. |
+`---------------------------*/
+
+static symgraph **prec_nodes;
+
+/*-----------------------------------.
+| Store which associativity is used. |
+`-----------------------------------*/
+
+bool *used_assoc = NULL;
+
+/*---------------------------------.
+| Create a new symbol, named TAG. |
+`---------------------------------*/
+
+static symbol *
+symbol_new (uniqstr tag, location loc)
+{
+ symbol *res = xmalloc (sizeof *res);
+ uniqstr_assert (tag);
+
+ /* If the tag is not a string (starts with a double quote), check
+ that it is valid for Yacc. */
+ if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-'))
+ complain (&loc, Wyacc,
+ _("POSIX Yacc forbids dashes in symbol names: %s"), tag);
+
+ res->tag = tag;
+ res->location = loc;
+
+ res->type_name = NULL;
+ {
+ int i;
+ for (i = 0; i < CODE_PROPS_SIZE; ++i)
+ code_props_none_init (&res->props[i]);
+ }
+
+ res->number = NUMBER_UNDEFINED;
+ res->prec = 0;
+ res->assoc = undef_assoc;
+ res->user_token_number = USER_NUMBER_UNDEFINED;
+
+ res->alias = NULL;
+ res->class = unknown_sym;
+ res->status = undeclared;
+
+ if (nsyms == SYMBOL_NUMBER_MAXIMUM)
+ complain (NULL, fatal, _("too many symbols in input grammar (limit is %d)"),
+ SYMBOL_NUMBER_MAXIMUM);
+ nsyms++;
+ return res;
+}
+
+char const *
+code_props_type_string (code_props_type kind)
+{
+ switch (kind)
+ {
+ case destructor:
+ return "%destructor";
+ case printer:
+ return "%printer";
+ }
+ assert (0);
+}
+
+/*----------------------------------------.
+| Create a new semantic type, named TAG. |
+`----------------------------------------*/
+
+static semantic_type *
+semantic_type_new (uniqstr tag, const location *loc)
+{
+ semantic_type *res = xmalloc (sizeof *res);
+
+ uniqstr_assert (tag);
+ res->tag = tag;
+ res->location = loc ? *loc : empty_location;
+ res->status = undeclared;
+ {
+ int i;
+ for (i = 0; i < CODE_PROPS_SIZE; ++i)
+ code_props_none_init (&res->props[i]);
+ }
+
+ return res;
+}
+
+
+/*-----------------.
+| Print a symbol. |
+`-----------------*/
+
+#define SYMBOL_ATTR_PRINT(Attr) \
+ if (s->Attr) \
+ fprintf (f, " %s { %s }", #Attr, s->Attr)
+
+#define SYMBOL_CODE_PRINT(Attr) \
+ if (s->props[Attr].code) \
+ fprintf (f, " %s { %s }", #Attr, s->props[Attr].code)
+
+void
+symbol_print (symbol const *s, FILE *f)
+{
+ if (s)
+ {
+ fputs (s->tag, f);
+ SYMBOL_ATTR_PRINT (type_name);
+ SYMBOL_CODE_PRINT (destructor);
+ SYMBOL_CODE_PRINT (printer);
+ }
+ else
+ fputs ("<NULL>", f);
+}
+
+#undef SYMBOL_ATTR_PRINT
+#undef SYMBOL_CODE_PRINT
+
+
+/*----------------------------------.
+| Whether S is a valid identifier. |
+`----------------------------------*/
+
+static bool
+is_identifier (uniqstr s)
+{
static char const alphanum[26 + 26 + 1 + 10 + 1] =
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "_"
- "0123456789";
- if (!s || ! memchr (alphanum, *s, sizeof alphanum - 10))
- return false;
- for (++s; *s; ++s)
- if (! memchr (alphanum, *s, sizeof alphanum))
- return false;
- return true;
-}
-
-
-/*-----------------------------------------------.
-| Get the identifier associated to this symbol. |
-`-----------------------------------------------*/
-uniqstr
-symbol_id_get (symbol const *sym)
-{
- aver (sym->user_token_number != USER_NUMBER_HAS_STRING_ALIAS);
- if (sym->alias)
- sym = sym->alias;
- return is_identifier (sym->tag) ? sym->tag : 0;
-}
-
-
-/*------------------------------------------------------------------.
-| Complain that S's WHAT is redeclared at SECOND, and was first set |
-| at FIRST. |
-`------------------------------------------------------------------*/
-
-static void
-symbol_redeclaration (symbol *s, const char *what, location first,
- location second)
-{
- unsigned i = 0;
- complain_indent (&second, complaint, &i,
- _("%s redeclaration for %s"), what, s->tag);
- i += SUB_INDENT;
- complain_indent (&first, complaint, &i,
- _("previous declaration"));
-}
-
-static void
-semantic_type_redeclaration (semantic_type *s, const char *what, location first,
- location second)
-{
- unsigned i = 0;
- complain_indent (&second, complaint, &i,
- _("%s redeclaration for <%s>"), what, s->tag);
- i += SUB_INDENT;
- complain_indent (&first, complaint, &i,
- _("previous declaration"));
-}
-
-
-
-/*-----------------------------------------------------------------.
-| Set the TYPE_NAME associated with SYM. Does nothing if passed 0 |
-| as TYPE_NAME. |
-`-----------------------------------------------------------------*/
-
-void
-symbol_type_set (symbol *sym, uniqstr type_name, location loc)
-{
- if (type_name)
- {
- if (sym->type_name)
- symbol_redeclaration (sym, "%type", sym->type_location, loc);
- else
- {
- uniqstr_assert (type_name);
- sym->type_name = type_name;
- sym->type_location = loc;
- }
- }
-}
-
-/*--------------------------------------------------------.
-| Set the DESTRUCTOR or PRINTER associated with the SYM. |
-`--------------------------------------------------------*/
-
-void
-symbol_code_props_set (symbol *sym, code_props_type kind,
- code_props const *code)
-{
- if (sym->props[kind].code)
- symbol_redeclaration (sym, code_props_type_string (kind),
- sym->props[kind].location,
- code->location);
- else
- sym->props[kind] = *code;
-}
-
-/*-----------------------------------------------------.
-| Set the DESTRUCTOR or PRINTER associated with TYPE. |
-`-----------------------------------------------------*/
-
-void
-semantic_type_code_props_set (semantic_type *type,
- code_props_type kind,
- code_props const *code)
-{
- if (type->props[kind].code)
- semantic_type_redeclaration (type, code_props_type_string (kind),
- type->props[kind].location,
- code->location);
- else
- type->props[kind] = *code;
-}
-
-/*---------------------------------------------------.
-| Get the computed %destructor or %printer for SYM. |
-`---------------------------------------------------*/
-
-code_props *
-symbol_code_props_get (symbol *sym, code_props_type kind)
-{
- /* Per-symbol code props. */
- if (sym->props[kind].code)
- return &sym->props[kind];
-
- /* Per-type code props. */
- if (sym->type_name)
- {
- code_props *code =
- &semantic_type_get (sym->type_name, NULL)->props[kind];
- if (code->code)
- return code;
- }
-
- /* Apply default code props's only to user-defined symbols. */
- if (sym->tag[0] != '$' && sym != errtoken)
- {
- code_props *code =
- &semantic_type_get (sym->type_name ? "*" : "", NULL)->props[kind];
- if (code->code)
- return code;
- }
- return &code_props_none;
-}
-
-/*-----------------------------------------------------------------.
-| Set the PRECEDENCE associated with SYM. Does nothing if invoked |
-| with UNDEF_ASSOC as ASSOC. |
-`-----------------------------------------------------------------*/
-
-void
-symbol_precedence_set (symbol *sym, int prec, assoc a, location loc)
-{
- if (a != undef_assoc)
- {
- if (sym->prec)
- symbol_redeclaration (sym, assoc_to_string (a), sym->prec_location,
- loc);
- else
- {
- sym->prec = prec;
- sym->assoc = a;
- sym->prec_location = loc;
- }
- }
-
- /* Only terminals have a precedence. */
- symbol_class_set (sym, token_sym, loc, false);
-}
-
-
-/*------------------------------------.
-| Set the CLASS associated with SYM. |
-`------------------------------------*/
-
-void
-symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
-{
- bool warned = false;
- if (sym->class != unknown_sym && sym->class != class)
- {
- complain (&loc, complaint, _("symbol %s redefined"), sym->tag);
- /* Don't report both "redefined" and "redeclared". */
- warned = true;
- }
-
- if (class == nterm_sym && sym->class != nterm_sym)
- sym->number = nvars++;
- else if (class == token_sym && sym->number == NUMBER_UNDEFINED)
- sym->number = ntokens++;
-
- sym->class = class;
-
- if (declaring)
- {
- if (sym->status == declared && !warned)
- complain (&loc, Wother, _("symbol %s redeclared"), sym->tag);
- else
- sym->status = declared;
- }
-}
-
-
-/*------------------------------------------------.
-| Set the USER_TOKEN_NUMBER associated with SYM. |
-`------------------------------------------------*/
-
-void
-symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
-{
- int *user_token_numberp;
-
- if (sym->user_token_number != USER_NUMBER_HAS_STRING_ALIAS)
- user_token_numberp = &sym->user_token_number;
- else
- user_token_numberp = &sym->alias->user_token_number;
- if (*user_token_numberp != USER_NUMBER_UNDEFINED
- && *user_token_numberp != user_token_number)
- complain (&loc, complaint, _("redefining user token number of %s"),
- sym->tag);
-
- *user_token_numberp = user_token_number;
- /* User defined $end token? */
- if (user_token_number == 0)
- {
- endtoken = sym;
- /* It is always mapped to 0, so it was already counted in
- NTOKENS. */
- if (endtoken->number != NUMBER_UNDEFINED)
- --ntokens;
- endtoken->number = 0;
- }
-}
-
-
-/*----------------------------------------------------------.
-| If SYM is not defined, report an error, and consider it a |
-| nonterminal. |
-`----------------------------------------------------------*/
-
-static inline bool
-symbol_check_defined (symbol *sym)
-{
- if (sym->class == unknown_sym)
- {
- assert (sym->status != declared);
- complain (&sym->location,
- sym->status == needed ? complaint : Wother,
- _("symbol %s is used, but is not defined as a token"
- " and has no rules"),
- sym->tag);
- sym->class = nterm_sym;
- sym->number = nvars++;
- }
-
- {
- int i;
- for (i = 0; i < 2; ++i)
- symbol_code_props_get (sym, i)->is_used = true;
- }
-
- /* Set the semantic type status associated to the current symbol to
- 'declared' so that we could check semantic types unnecessary uses. */
- if (sym->type_name)
- {
- semantic_type *sem_type = semantic_type_get (sym->type_name, NULL);
- if (sem_type)
- sem_type->status = declared;
- }
-
- return true;
-}
-
-static inline bool
-semantic_type_check_defined (semantic_type *sem_type)
-{
- /* <*> and <> do not have to be "declared". */
- if (sem_type->status == declared
- || !*sem_type->tag
- || STREQ (sem_type->tag, "*"))
- {
- int i;
- for (i = 0; i < 2; ++i)
- if (sem_type->props[i].kind != CODE_PROPS_NONE
- && ! sem_type->props[i].is_used)
- complain (&sem_type->location, Wother,
- _("useless %s for type <%s>"),
- code_props_type_string (i), sem_type->tag);
- }
- else
- complain (&sem_type->location, Wother,
- _("type <%s> is used, but is not associated to any symbol"),
- sem_type->tag);
-
- return true;
-}
-
-static bool
-symbol_check_defined_processor (void *sym, void *null ATTRIBUTE_UNUSED)
-{
- return symbol_check_defined (sym);
-}
-
-static bool
-semantic_type_check_defined_processor (void *sem_type,
- void *null ATTRIBUTE_UNUSED)
-{
- return semantic_type_check_defined (sem_type);
-}
-
-
-void
-symbol_make_alias (symbol *sym, symbol *str, location loc)
-{
- if (str->alias)
- complain (&loc, Wother,
- _("symbol %s used more than once as a literal string"), str->tag);
- else if (sym->alias)
- complain (&loc, Wother,
- _("symbol %s given more than one literal string"), sym->tag);
- else
- {
- str->class = token_sym;
- str->user_token_number = sym->user_token_number;
- sym->user_token_number = USER_NUMBER_HAS_STRING_ALIAS;
- str->alias = sym;
- sym->alias = str;
- str->number = sym->number;
- symbol_type_set (str, sym->type_name, loc);
- }
-}
-
-
-/*---------------------------------------------------------.
-| Check that THIS, and its alias, have same precedence and |
-| associativity. |
-`---------------------------------------------------------*/
-
-static inline void
-symbol_check_alias_consistency (symbol *this)
-{
- symbol *sym = this;
- symbol *str = this->alias;
-
- /* Check only the symbol in the symbol-string pair. */
- if (!(this->alias
- && this->user_token_number == USER_NUMBER_HAS_STRING_ALIAS))
- return;
-
- if (str->type_name != sym->type_name)
- {
- if (str->type_name)
- symbol_type_set (sym, str->type_name, str->type_location);
- else
- symbol_type_set (str, sym->type_name, sym->type_location);
- }
-
-
- {
- int i;
- for (i = 0; i < CODE_PROPS_SIZE; ++i)
- if (str->props[i].code)
- symbol_code_props_set (sym, i, &str->props[i]);
- else if (sym->props[i].code)
- symbol_code_props_set (str, i, &sym->props[i]);
- }
-
- if (sym->prec || str->prec)
- {
- if (str->prec)
- symbol_precedence_set (sym, str->prec, str->assoc,
- str->prec_location);
- else
- symbol_precedence_set (str, sym->prec, sym->assoc,
- sym->prec_location);
- }
-}
-
-static bool
-symbol_check_alias_consistency_processor (void *this,
- void *null ATTRIBUTE_UNUSED)
-{
- symbol_check_alias_consistency (this);
- return true;
-}
-
-
-/*-------------------------------------------------------------------.
-| Assign a symbol number, and write the definition of the token name |
-| into FDEFINES. Put in SYMBOLS. |
-`-------------------------------------------------------------------*/
-
-static inline bool
-symbol_pack (symbol *this)
-{
- aver (this->number != NUMBER_UNDEFINED);
- if (this->class == nterm_sym)
- this->number += ntokens;
- else if (this->user_token_number == USER_NUMBER_HAS_STRING_ALIAS)
- return true;
-
- symbols[this->number] = this;
- return true;
-}
-
-static bool
-symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED)
-{
- return symbol_pack (this);
-}
-
-
-static void
-user_token_number_redeclaration (int num, symbol *first, symbol *second)
-{
- unsigned i = 0;
- /* User token numbers are not assigned during the parsing, but in a
- second step, via a traversal of the symbol table sorted on tag.
-
- However, error messages make more sense if we keep the first
- declaration first. */
- if (location_cmp (first->location, second->location) > 0)
- {
- symbol* tmp = first;
- first = second;
- second = tmp;
- }
- complain_indent (&second->location, complaint, &i,
- _("user token number %d redeclaration for %s"),
- num, second->tag);
- i += SUB_INDENT;
- complain_indent (&first->location, complaint, &i,
- _("previous declaration for %s"),
- first->tag);
-}
-
-/*--------------------------------------------------.
-| Put THIS in TOKEN_TRANSLATIONS if it is a token. |
-`--------------------------------------------------*/
-
-static inline bool
-symbol_translation (symbol *this)
-{
- /* Non-terminal? */
- if (this->class == token_sym
- && this->user_token_number != USER_NUMBER_HAS_STRING_ALIAS)
- {
- /* A token which translation has already been set? */
- if (token_translations[this->user_token_number] != undeftoken->number)
- user_token_number_redeclaration
- (this->user_token_number,
- symbols[token_translations[this->user_token_number]],
- this);
- else
- token_translations[this->user_token_number] = this->number;
- }
-
- return true;
-}
-
-static bool
-symbol_translation_processor (void *this, void *null ATTRIBUTE_UNUSED)
-{
- return symbol_translation (this);
-}
-
-
-/*---------------------------------------.
-| Symbol and semantic type hash tables. |
-`---------------------------------------*/
-
-/* Initial capacity of symbol and semantic type hash table. */
-#define HT_INITIAL_CAPACITY 257
-
-static struct hash_table *symbol_table = NULL;
-static struct hash_table *semantic_type_table = NULL;
-
-static inline bool
-hash_compare_symbol (const symbol *m1, const symbol *m2)
-{
- /* Since tags are unique, we can compare the pointers themselves. */
- return UNIQSTR_EQ (m1->tag, m2->tag);
-}
-
-static inline bool
-hash_compare_semantic_type (const semantic_type *m1, const semantic_type *m2)
-{
- /* Since names are unique, we can compare the pointers themselves. */
- return UNIQSTR_EQ (m1->tag, m2->tag);
-}
-
-static bool
-hash_symbol_comparator (void const *m1, void const *m2)
-{
- return hash_compare_symbol (m1, m2);
-}
-
-static bool
-hash_semantic_type_comparator (void const *m1, void const *m2)
-{
- return hash_compare_semantic_type (m1, m2);
-}
-
-static inline size_t
-hash_symbol (const symbol *m, size_t tablesize)
-{
- /* Since tags are unique, we can hash the pointer itself. */
- return ((uintptr_t) m->tag) % tablesize;
-}
-
-static inline size_t
-hash_semantic_type (const semantic_type *m, size_t tablesize)
-{
- /* Since names are unique, we can hash the pointer itself. */
- return ((uintptr_t) m->tag) % tablesize;
-}
-
-static size_t
-hash_symbol_hasher (void const *m, size_t tablesize)
-{
- return hash_symbol (m, tablesize);
-}
-
-static size_t
-hash_semantic_type_hasher (void const *m, size_t tablesize)
-{
- return hash_semantic_type (m, tablesize);
-}
-
-/*-------------------------------.
-| Create the symbol hash table. |
-`-------------------------------*/
-
-void
-symbols_new (void)
-{
- symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
- NULL,
- hash_symbol_hasher,
- hash_symbol_comparator,
- free);
- semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY,
- NULL,
- hash_semantic_type_hasher,
- hash_semantic_type_comparator,
- free);
-}
-
-
-/*----------------------------------------------------------------.
-| Find the symbol named KEY, and return it. If it does not exist |
-| yet, create it. |
-`----------------------------------------------------------------*/
-
-symbol *
-symbol_from_uniqstr (const uniqstr key, location loc)
-{
- symbol probe;
- symbol *entry;
-
- probe.tag = key;
- entry = hash_lookup (symbol_table, &probe);
-
- if (!entry)
- {
- /* First insertion in the hash. */
- aver (!symbols_sorted);
- entry = symbol_new (key, loc);
- if (!hash_insert (symbol_table, entry))
- xalloc_die ();
- }
- return entry;
-}
-
-
-/*-----------------------------------------------------------------------.
-| Find the semantic type named KEY, and return it. If it does not exist |
-| yet, create it. |
-`-----------------------------------------------------------------------*/
-
-semantic_type *
-semantic_type_from_uniqstr (const uniqstr key, const location *loc)
-{
- semantic_type probe;
- semantic_type *entry;
-
- probe.tag = key;
- entry = hash_lookup (semantic_type_table, &probe);
-
- if (!entry)
- {
- /* First insertion in the hash. */
- entry = semantic_type_new (key, loc);
- if (!hash_insert (semantic_type_table, entry))
- xalloc_die ();
- }
- return entry;
-}
-
-
-/*----------------------------------------------------------------.
-| Find the symbol named KEY, and return it. If it does not exist |
-| yet, create it. |
-`----------------------------------------------------------------*/
-
-symbol *
-symbol_get (const char *key, location loc)
-{
- return symbol_from_uniqstr (uniqstr_new (key), loc);
-}
-
-
-/*-----------------------------------------------------------------------.
-| Find the semantic type named KEY, and return it. If it does not exist |
-| yet, create it. |
-`-----------------------------------------------------------------------*/
-
-semantic_type *
-semantic_type_get (const char *key, const location *loc)
-{
- return semantic_type_from_uniqstr (uniqstr_new (key), loc);
-}
-
-
-/*------------------------------------------------------------------.
-| Generate a dummy nonterminal, whose name cannot conflict with the |
-| user's names. |
-`------------------------------------------------------------------*/
-
-symbol *
-dummy_symbol_get (location loc)
-{
- /* Incremented for each generated symbol. */
- static int dummy_count = 0;
- static char buf[256];
-
- symbol *sym;
-
- sprintf (buf, "$@%d", ++dummy_count);
- sym = symbol_get (buf, loc);
- sym->class = nterm_sym;
- sym->number = nvars++;
- return sym;
-}
-
-bool
-symbol_is_dummy (const symbol *sym)
-{
- return sym->tag[0] == '@' || (sym->tag[0] == '$' && sym->tag[1] == '@');
-}
-
-/*-------------------.
-| Free the symbols. |
-`-------------------*/
-
-void
-symbols_free (void)
-{
- hash_free (symbol_table);
- hash_free (semantic_type_table);
- free (symbols);
- free (symbols_sorted);
- free (semantic_types_sorted);
-}
-
-
-/*---------------------------------------------------------------.
-| Look for undefined symbols, report an error, and consider them |
-| terminals. |
-`---------------------------------------------------------------*/
-
-static int
-symbols_cmp (symbol const *a, symbol const *b)
-{
- return strcmp (a->tag, b->tag);
-}
-
-static int
-symbols_cmp_qsort (void const *a, void const *b)
-{
- return symbols_cmp (*(symbol * const *)a, *(symbol * const *)b);
-}
-
-static void
-symbols_do (Hash_processor processor, void *processor_data,
- struct hash_table *table, symbol ***sorted)
-{
- size_t count = hash_get_n_entries (table);
- if (!*sorted)
- {
- *sorted = xnmalloc (count, sizeof **sorted);
- hash_get_entries (table, (void**)*sorted, count);
- qsort (*sorted, count, sizeof **sorted, symbols_cmp_qsort);
- }
- {
- size_t i;
- for (i = 0; i < count; ++i)
- processor ((*sorted)[i], processor_data);
- }
-}
-
-/*--------------------------------------------------------------.
-| Check that all the symbols are defined. Report any undefined |
-| symbols and consider them nonterminals. |
-`--------------------------------------------------------------*/
-
-void
-symbols_check_defined (void)
-{
- symbols_do (symbol_check_defined_processor, NULL,
- symbol_table, &symbols_sorted);
- symbols_do (semantic_type_check_defined_processor, NULL,
- semantic_type_table, &semantic_types_sorted);
-}
-
-/*------------------------------------------------------------------.
-| Set TOKEN_TRANSLATIONS. Check that no two symbols share the same |
-| number. |
-`------------------------------------------------------------------*/
-
-static void
-symbols_token_translations_init (void)
-{
- bool num_256_available_p = true;
- int i;
-
- /* Find the highest user token number, and whether 256, the POSIX
- preferred user token number for the error token, is used. */
- max_user_token_number = 0;
- for (i = 0; i < ntokens; ++i)
- {
- symbol *this = symbols[i];
- if (this->user_token_number != USER_NUMBER_UNDEFINED)
- {
- if (this->user_token_number > max_user_token_number)
- max_user_token_number = this->user_token_number;
- if (this->user_token_number == 256)
- num_256_available_p = false;
- }
- }
-
- /* If 256 is not used, assign it to error, to follow POSIX. */
- if (num_256_available_p
- && errtoken->user_token_number == USER_NUMBER_UNDEFINED)
- errtoken->user_token_number = 256;
-
- /* Set the missing user numbers. */
- if (max_user_token_number < 256)
- max_user_token_number = 256;
-
- for (i = 0; i < ntokens; ++i)
- {
- symbol *this = symbols[i];
- if (this->user_token_number == USER_NUMBER_UNDEFINED)
- this->user_token_number = ++max_user_token_number;
- if (this->user_token_number > max_user_token_number)
- max_user_token_number = this->user_token_number;
- }
-
- token_translations = xnmalloc (max_user_token_number + 1,
- sizeof *token_translations);
-
- /* Initialize all entries for literal tokens to the internal token
- number for $undefined, which represents all invalid inputs. */
- for (i = 0; i < max_user_token_number + 1; i++)
- token_translations[i] = undeftoken->number;
- symbols_do (symbol_translation_processor, NULL,
- symbol_table, &symbols_sorted);
-}
-
-
-/*----------------------------------------------------------------.
-| Assign symbol numbers, and write definition of token names into |
-| FDEFINES. Set up vectors SYMBOL_TABLE, TAGS of symbols. |
-`----------------------------------------------------------------*/
-
-void
-symbols_pack (void)
-{
- symbols_do (symbol_check_alias_consistency_processor, NULL,
- symbol_table, &symbols_sorted);
-
- symbols = xcalloc (nsyms, sizeof *symbols);
- symbols_do (symbol_pack_processor, NULL, symbol_table, &symbols_sorted);
-
- /* Aliases leave empty slots in symbols, so remove them. */
- {
- int writei;
- int readi;
- int nsyms_old = nsyms;
- for (writei = 0, readi = 0; readi < nsyms_old; readi += 1)
- {
- if (symbols[readi] == NULL)
- {
- nsyms -= 1;
- ntokens -= 1;
- }
- else
- {
- symbols[writei] = symbols[readi];
- symbols[writei]->number = writei;
- if (symbols[writei]->alias)
- symbols[writei]->alias->number = writei;
- writei += 1;
- }
- }
- }
- symbols = xnrealloc (symbols, nsyms, sizeof *symbols);
-
- symbols_token_translations_init ();
-
- if (startsymbol->class == unknown_sym)
- complain (&startsymbol_location, fatal,
- _("the start symbol %s is undefined"),
- startsymbol->tag);
- else if (startsymbol->class == token_sym)
- complain (&startsymbol_location, fatal,
- _("the start symbol %s is a token"),
- startsymbol->tag);
-}
-
-/*---------------------------------.
-| Initialize relation graph nodes. |
-`---------------------------------*/
-
-static void
-init_prec_nodes (void)
-{
- int i;
- symgraph* s;
- prec_nodes = xcalloc (nsyms, sizeof *prec_nodes);
- for (i = 0; i < nsyms; ++i)
- {
- prec_nodes[i] = xmalloc (sizeof *prec_nodes[i]);
- s = prec_nodes[i];
- s->id = i;
- s->succ = 0;
- s->pred = 0;
- }
-}
-
-/*----------------.
-| Create a link. |
-`----------------*/
-
-static symgraphlink *
-symgraphlink_new (graphid id, symgraphlink *next)
-{
- symgraphlink *l = xmalloc (sizeof *l);
- l->id = id;
- l->next = next;
- return l;
-}
-
-
-/*------------------------------------------------------------------.
-| Register the second symbol of the precedence relation, and return |
-| whether this relation is new. Use only in register_precedence. |
-`------------------------------------------------------------------*/
-
-static bool
-register_precedence_second_symbol (symgraphlink **first, graphid sym)
-{
- if (!*first || sym < (*first)->id)
- *first = symgraphlink_new (sym, *first);
- else
- {
- symgraphlink *slist = *first;
-
- while (slist->next && slist->next->id <= sym)
- slist = slist->next;
-
- if (slist->id == sym)
- /* Relation already present. */
- return false;
-
- slist->next = symgraphlink_new (sym, slist->next);
- }
- return true;
-}
-
-/*------------------------------------------------------------------.
-| Register a new relation between symbols as used. The first symbol |
-| has a greater precedence than the second one. |
-`------------------------------------------------------------------*/
-
-void
-register_precedence (graphid first, graphid snd)
-{
- if (!prec_nodes)
- init_prec_nodes ();
- register_precedence_second_symbol (&(prec_nodes[first]->succ), snd);
- register_precedence_second_symbol (&(prec_nodes[snd]->pred), first);
-}
-
-
-/*---------------------------------------.
-| Deep clear a linked / adjacency list). |
-`---------------------------------------*/
-
-static void
-linkedlist_free (symgraphlink *node)
-{
- if (node)
- {
- while (node->next)
- {
- symgraphlink *tmp = node->next;
- free (node);
- node = tmp;
- }
- free (node);
- }
-}
-
-/*----------------------------------------------.
-| Clear and destroy association tracking table. |
-`----------------------------------------------*/
-
-static void
-assoc_free (void)
-{
- int i;
- for (i = 0; i < nsyms; ++i)
- {
- linkedlist_free (prec_nodes[i]->pred);
- linkedlist_free (prec_nodes[i]->succ);
- free (prec_nodes[i]);
- }
- free (prec_nodes);
-}
-
-/*---------------------------------------.
-| Initialize association tracking table. |
-`---------------------------------------*/
-
-static void
-init_assoc (void)
-{
- graphid i;
- used_assoc = xcalloc (nsyms, sizeof *used_assoc);
- for (i = 0; i < nsyms; ++i)
- used_assoc[i] = false;
-}
-
-/*------------------------------------------------------------------.
-| Test if the associativity for the symbols is defined and useless. |
-`------------------------------------------------------------------*/
-
-static inline bool
-is_assoc_useless (symbol *s)
-{
- return s
- && s->assoc != undef_assoc
- && s->assoc != precedence_assoc
- && !used_assoc[s->number];
-}
-
-/*-------------------------------.
-| Register a used associativity. |
-`-------------------------------*/
-
-void
-register_assoc (graphid i, graphid j)
-{
- if (!used_assoc)
- init_assoc ();
- used_assoc[i] = true;
- used_assoc[j] = true;
-}
-
-/*--------------------------------------------------.
-| Print a warning for unused precedence relations. |
-`--------------------------------------------------*/
-
-void
-print_precedence_warnings (void)
-{
- int i;
- if (!prec_nodes)
- init_prec_nodes ();
- if (!used_assoc)
- init_assoc ();
- for (i = 0; i < nsyms; ++i)
- {
- symbol *s = symbols[i];
- if (s
- && s->prec != 0
- && !prec_nodes[i]->pred
- && !prec_nodes[i]->succ)
- {
- if (is_assoc_useless (s))
- complain (&s->prec_location, Wprecedence,
- _("useless precedence and associativity for %s"), s->tag);
- else if (s->assoc == precedence_assoc)
- complain (&s->prec_location, Wprecedence,
- _("useless precedence for %s"), s->tag);
- }
- else if (is_assoc_useless (s))
- complain (&s->prec_location, Wprecedence,
- _("useless associativity for %s, use %%precedence"), s->tag);
- }
- free (used_assoc);
- assoc_free ();
-}
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "_"
+ "0123456789";
+ if (!s || ! memchr (alphanum, *s, sizeof alphanum - 10))
+ return false;
+ for (++s; *s; ++s)
+ if (! memchr (alphanum, *s, sizeof alphanum))
+ return false;
+ return true;
+}
+
+
+/*-----------------------------------------------.
+| Get the identifier associated to this symbol. |
+`-----------------------------------------------*/
+uniqstr
+symbol_id_get (symbol const *sym)
+{
+ aver (sym->user_token_number != USER_NUMBER_HAS_STRING_ALIAS);
+ if (sym->alias)
+ sym = sym->alias;
+ return is_identifier (sym->tag) ? sym->tag : 0;
+}
+
+
+/*------------------------------------------------------------------.
+| Complain that S's WHAT is redeclared at SECOND, and was first set |
+| at FIRST. |
+`------------------------------------------------------------------*/
+
+static void
+symbol_redeclaration (symbol *s, const char *what, location first,
+ location second)
+{
+ unsigned i = 0;
+ complain_indent (&second, complaint, &i,
+ _("%s redeclaration for %s"), what, s->tag);
+ i += SUB_INDENT;
+ complain_indent (&first, complaint, &i,
+ _("previous declaration"));
+}
+
+static void
+semantic_type_redeclaration (semantic_type *s, const char *what, location first,
+ location second)
+{
+ unsigned i = 0;
+ complain_indent (&second, complaint, &i,
+ _("%s redeclaration for <%s>"), what, s->tag);
+ i += SUB_INDENT;
+ complain_indent (&first, complaint, &i,
+ _("previous declaration"));
+}
+
+
+
+/*-----------------------------------------------------------------.
+| Set the TYPE_NAME associated with SYM. Does nothing if passed 0 |
+| as TYPE_NAME. |
+`-----------------------------------------------------------------*/
+
+void
+symbol_type_set (symbol *sym, uniqstr type_name, location loc)
+{
+ if (type_name)
+ {
+ if (sym->type_name)
+ symbol_redeclaration (sym, "%type", sym->type_location, loc);
+ else
+ {
+ uniqstr_assert (type_name);
+ sym->type_name = type_name;
+ sym->type_location = loc;
+ }
+ }
+}
+
+/*--------------------------------------------------------.
+| Set the DESTRUCTOR or PRINTER associated with the SYM. |
+`--------------------------------------------------------*/
+
+void
+symbol_code_props_set (symbol *sym, code_props_type kind,
+ code_props const *code)
+{
+ if (sym->props[kind].code)
+ symbol_redeclaration (sym, code_props_type_string (kind),
+ sym->props[kind].location,
+ code->location);
+ else
+ sym->props[kind] = *code;
+}
+
+/*-----------------------------------------------------.
+| Set the DESTRUCTOR or PRINTER associated with TYPE. |
+`-----------------------------------------------------*/
+
+void
+semantic_type_code_props_set (semantic_type *type,
+ code_props_type kind,
+ code_props const *code)
+{
+ if (type->props[kind].code)
+ semantic_type_redeclaration (type, code_props_type_string (kind),
+ type->props[kind].location,
+ code->location);
+ else
+ type->props[kind] = *code;
+}
+
+/*---------------------------------------------------.
+| Get the computed %destructor or %printer for SYM. |
+`---------------------------------------------------*/
+
+code_props *
+symbol_code_props_get (symbol *sym, code_props_type kind)
+{
+ /* Per-symbol code props. */
+ if (sym->props[kind].code)
+ return &sym->props[kind];
+
+ /* Per-type code props. */
+ if (sym->type_name)
+ {
+ code_props *code =
+ &semantic_type_get (sym->type_name, NULL)->props[kind];
+ if (code->code)
+ return code;
+ }
+
+ /* Apply default code props's only to user-defined symbols. */
+ if (sym->tag[0] != '$' && sym != errtoken)
+ {
+ code_props *code =
+ &semantic_type_get (sym->type_name ? "*" : "", NULL)->props[kind];
+ if (code->code)
+ return code;
+ }
+ return &code_props_none;
+}
+
+/*-----------------------------------------------------------------.
+| Set the PRECEDENCE associated with SYM. Does nothing if invoked |
+| with UNDEF_ASSOC as ASSOC. |
+`-----------------------------------------------------------------*/
+
+void
+symbol_precedence_set (symbol *sym, int prec, assoc a, location loc)
+{
+ if (a != undef_assoc)
+ {
+ if (sym->prec)
+ symbol_redeclaration (sym, assoc_to_string (a), sym->prec_location,
+ loc);
+ else
+ {
+ sym->prec = prec;
+ sym->assoc = a;
+ sym->prec_location = loc;
+ }
+ }
+
+ /* Only terminals have a precedence. */
+ symbol_class_set (sym, token_sym, loc, false);
+}
+
+
+/*------------------------------------.
+| Set the CLASS associated with SYM. |
+`------------------------------------*/
+
+void
+symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
+{
+ bool warned = false;
+ if (sym->class != unknown_sym && sym->class != class)
+ {
+ complain (&loc, complaint, _("symbol %s redefined"), sym->tag);
+ /* Don't report both "redefined" and "redeclared". */
+ warned = true;
+ }
+
+ if (class == nterm_sym && sym->class != nterm_sym)
+ sym->number = nvars++;
+ else if (class == token_sym && sym->number == NUMBER_UNDEFINED)
+ sym->number = ntokens++;
+
+ sym->class = class;
+
+ if (declaring)
+ {
+ if (sym->status == declared && !warned)
+ complain (&loc, Wother, _("symbol %s redeclared"), sym->tag);
+ else
+ sym->status = declared;
+ }
+}
+
+
+/*------------------------------------------------.
+| Set the USER_TOKEN_NUMBER associated with SYM. |
+`------------------------------------------------*/
+
+void
+symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
+{
+ int *user_token_numberp;
+
+ if (sym->user_token_number != USER_NUMBER_HAS_STRING_ALIAS)
+ user_token_numberp = &sym->user_token_number;
+ else
+ user_token_numberp = &sym->alias->user_token_number;
+ if (*user_token_numberp != USER_NUMBER_UNDEFINED
+ && *user_token_numberp != user_token_number)
+ complain (&loc, complaint, _("redefining user token number of %s"),
+ sym->tag);
+
+ *user_token_numberp = user_token_number;
+ /* User defined $end token? */
+ if (user_token_number == 0)
+ {
+ endtoken = sym;
+ /* It is always mapped to 0, so it was already counted in
+ NTOKENS. */
+ if (endtoken->number != NUMBER_UNDEFINED)
+ --ntokens;
+ endtoken->number = 0;
+ }
+}
+
+
+/*----------------------------------------------------------.
+| If SYM is not defined, report an error, and consider it a |
+| nonterminal. |
+`----------------------------------------------------------*/
+
+static inline bool
+symbol_check_defined (symbol *sym)
+{
+ if (sym->class == unknown_sym)
+ {
+ assert (sym->status != declared);
+ complain (&sym->location,
+ sym->status == needed ? complaint : Wother,
+ _("symbol %s is used, but is not defined as a token"
+ " and has no rules"),
+ sym->tag);
+ sym->class = nterm_sym;
+ sym->number = nvars++;
+ }
+
+ {
+ int i;
+ for (i = 0; i < 2; ++i)
+ symbol_code_props_get (sym, i)->is_used = true;
+ }
+
+ /* Set the semantic type status associated to the current symbol to
+ 'declared' so that we could check semantic types unnecessary uses. */
+ if (sym->type_name)
+ {
+ semantic_type *sem_type = semantic_type_get (sym->type_name, NULL);
+ if (sem_type)
+ sem_type->status = declared;
+ }
+
+ return true;
+}
+
+static inline bool
+semantic_type_check_defined (semantic_type *sem_type)
+{
+ /* <*> and <> do not have to be "declared". */
+ if (sem_type->status == declared
+ || !*sem_type->tag
+ || STREQ (sem_type->tag, "*"))
+ {
+ int i;
+ for (i = 0; i < 2; ++i)
+ if (sem_type->props[i].kind != CODE_PROPS_NONE
+ && ! sem_type->props[i].is_used)
+ complain (&sem_type->location, Wother,
+ _("useless %s for type <%s>"),
+ code_props_type_string (i), sem_type->tag);
+ }
+ else
+ complain (&sem_type->location, Wother,
+ _("type <%s> is used, but is not associated to any symbol"),
+ sem_type->tag);
+
+ return true;
+}
+
+static bool
+symbol_check_defined_processor (void *sym, void *null ATTRIBUTE_UNUSED)
+{
+ return symbol_check_defined (sym);
+}
+
+static bool
+semantic_type_check_defined_processor (void *sem_type,
+ void *null ATTRIBUTE_UNUSED)
+{
+ return semantic_type_check_defined (sem_type);
+}
+
+
+void
+symbol_make_alias (symbol *sym, symbol *str, location loc)
+{
+ if (str->alias)
+ complain (&loc, Wother,
+ _("symbol %s used more than once as a literal string"), str->tag);
+ else if (sym->alias)
+ complain (&loc, Wother,
+ _("symbol %s given more than one literal string"), sym->tag);
+ else
+ {
+ str->class = token_sym;
+ str->user_token_number = sym->user_token_number;
+ sym->user_token_number = USER_NUMBER_HAS_STRING_ALIAS;
+ str->alias = sym;
+ sym->alias = str;
+ str->number = sym->number;
+ symbol_type_set (str, sym->type_name, loc);
+ }
+}
+
+
+/*---------------------------------------------------------.
+| Check that THIS, and its alias, have same precedence and |
+| associativity. |
+`---------------------------------------------------------*/
+
+static inline void
+symbol_check_alias_consistency (symbol *this)
+{
+ symbol *sym = this;
+ symbol *str = this->alias;
+
+ /* Check only the symbol in the symbol-string pair. */
+ if (!(this->alias
+ && this->user_token_number == USER_NUMBER_HAS_STRING_ALIAS))
+ return;
+
+ if (str->type_name != sym->type_name)
+ {
+ if (str->type_name)
+ symbol_type_set (sym, str->type_name, str->type_location);
+ else
+ symbol_type_set (str, sym->type_name, sym->type_location);
+ }
+
+
+ {
+ int i;
+ for (i = 0; i < CODE_PROPS_SIZE; ++i)
+ if (str->props[i].code)
+ symbol_code_props_set (sym, i, &str->props[i]);
+ else if (sym->props[i].code)
+ symbol_code_props_set (str, i, &sym->props[i]);
+ }
+
+ if (sym->prec || str->prec)
+ {
+ if (str->prec)
+ symbol_precedence_set (sym, str->prec, str->assoc,
+ str->prec_location);
+ else
+ symbol_precedence_set (str, sym->prec, sym->assoc,
+ sym->prec_location);
+ }
+}
+
+static bool
+symbol_check_alias_consistency_processor (void *this,
+ void *null ATTRIBUTE_UNUSED)
+{
+ symbol_check_alias_consistency (this);
+ return true;
+}
+
+
+/*-------------------------------------------------------------------.
+| Assign a symbol number, and write the definition of the token name |
+| into FDEFINES. Put in SYMBOLS. |
+`-------------------------------------------------------------------*/
+
+static inline bool
+symbol_pack (symbol *this)
+{
+ aver (this->number != NUMBER_UNDEFINED);
+ if (this->class == nterm_sym)
+ this->number += ntokens;
+ else if (this->user_token_number == USER_NUMBER_HAS_STRING_ALIAS)
+ return true;
+
+ symbols[this->number] = this;
+ return true;
+}
+
+static bool
+symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED)
+{
+ return symbol_pack (this);
+}
+
+
+static void
+user_token_number_redeclaration (int num, symbol *first, symbol *second)
+{
+ unsigned i = 0;
+ /* User token numbers are not assigned during the parsing, but in a
+ second step, via a traversal of the symbol table sorted on tag.
+
+ However, error messages make more sense if we keep the first
+ declaration first. */
+ if (location_cmp (first->location, second->location) > 0)
+ {
+ symbol* tmp = first;
+ first = second;
+ second = tmp;
+ }
+ complain_indent (&second->location, complaint, &i,
+ _("user token number %d redeclaration for %s"),
+ num, second->tag);
+ i += SUB_INDENT;
+ complain_indent (&first->location, complaint, &i,
+ _("previous declaration for %s"),
+ first->tag);
+}
+
+/*--------------------------------------------------.
+| Put THIS in TOKEN_TRANSLATIONS if it is a token. |
+`--------------------------------------------------*/
+
+static inline bool
+symbol_translation (symbol *this)
+{
+ /* Non-terminal? */
+ if (this->class == token_sym
+ && this->user_token_number != USER_NUMBER_HAS_STRING_ALIAS)
+ {
+ /* A token which translation has already been set? */
+ if (token_translations[this->user_token_number] != undeftoken->number)
+ user_token_number_redeclaration
+ (this->user_token_number,
+ symbols[token_translations[this->user_token_number]],
+ this);
+ else
+ token_translations[this->user_token_number] = this->number;
+ }
+
+ return true;
+}
+
+static bool
+symbol_translation_processor (void *this, void *null ATTRIBUTE_UNUSED)
+{
+ return symbol_translation (this);
+}
+
+
+/*---------------------------------------.
+| Symbol and semantic type hash tables. |
+`---------------------------------------*/
+
+/* Initial capacity of symbol and semantic type hash table. */
+#define HT_INITIAL_CAPACITY 257
+
+static struct hash_table *symbol_table = NULL;
+static struct hash_table *semantic_type_table = NULL;
+
+static inline bool
+hash_compare_symbol (const symbol *m1, const symbol *m2)
+{
+ /* Since tags are unique, we can compare the pointers themselves. */
+ return UNIQSTR_EQ (m1->tag, m2->tag);
+}
+
+static inline bool
+hash_compare_semantic_type (const semantic_type *m1, const semantic_type *m2)
+{
+ /* Since names are unique, we can compare the pointers themselves. */
+ return UNIQSTR_EQ (m1->tag, m2->tag);
+}
+
+static bool
+hash_symbol_comparator (void const *m1, void const *m2)
+{
+ return hash_compare_symbol (m1, m2);
+}
+
+static bool
+hash_semantic_type_comparator (void const *m1, void const *m2)
+{
+ return hash_compare_semantic_type (m1, m2);
+}
+
+static inline size_t
+hash_symbol (const symbol *m, size_t tablesize)
+{
+ /* Since tags are unique, we can hash the pointer itself. */
+ return ((uintptr_t) m->tag) % tablesize;
+}
+
+static inline size_t
+hash_semantic_type (const semantic_type *m, size_t tablesize)
+{
+ /* Since names are unique, we can hash the pointer itself. */
+ return ((uintptr_t) m->tag) % tablesize;
+}
+
+static size_t
+hash_symbol_hasher (void const *m, size_t tablesize)
+{
+ return hash_symbol (m, tablesize);
+}
+
+static size_t
+hash_semantic_type_hasher (void const *m, size_t tablesize)
+{
+ return hash_semantic_type (m, tablesize);
+}
+
+/*-------------------------------.
+| Create the symbol hash table. |
+`-------------------------------*/
+
+void
+symbols_new (void)
+{
+ symbol_table = hash_initialize (HT_INITIAL_CAPACITY,
+ NULL,
+ hash_symbol_hasher,
+ hash_symbol_comparator,
+ free);
+ semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY,
+ NULL,
+ hash_semantic_type_hasher,
+ hash_semantic_type_comparator,
+ free);
+}
+
+
+/*----------------------------------------------------------------.
+| Find the symbol named KEY, and return it. If it does not exist |
+| yet, create it. |
+`----------------------------------------------------------------*/
+
+symbol *
+symbol_from_uniqstr (const uniqstr key, location loc)
+{
+ symbol probe;
+ symbol *entry;
+
+ probe.tag = key;
+ entry = hash_lookup (symbol_table, &probe);
+
+ if (!entry)
+ {
+ /* First insertion in the hash. */
+ aver (!symbols_sorted);
+ entry = symbol_new (key, loc);
+ if (!hash_insert (symbol_table, entry))
+ xalloc_die ();
+ }
+ return entry;
+}
+
+
+/*-----------------------------------------------------------------------.
+| Find the semantic type named KEY, and return it. If it does not exist |
+| yet, create it. |
+`-----------------------------------------------------------------------*/
+
+semantic_type *
+semantic_type_from_uniqstr (const uniqstr key, const location *loc)
+{
+ semantic_type probe;
+ semantic_type *entry;
+
+ probe.tag = key;
+ entry = hash_lookup (semantic_type_table, &probe);
+
+ if (!entry)
+ {
+ /* First insertion in the hash. */
+ entry = semantic_type_new (key, loc);
+ if (!hash_insert (semantic_type_table, entry))
+ xalloc_die ();
+ }
+ return entry;
+}
+
+
+/*----------------------------------------------------------------.
+| Find the symbol named KEY, and return it. If it does not exist |
+| yet, create it. |
+`----------------------------------------------------------------*/
+
+symbol *
+symbol_get (const char *key, location loc)
+{
+ return symbol_from_uniqstr (uniqstr_new (key), loc);
+}
+
+
+/*-----------------------------------------------------------------------.
+| Find the semantic type named KEY, and return it. If it does not exist |
+| yet, create it. |
+`-----------------------------------------------------------------------*/
+
+semantic_type *
+semantic_type_get (const char *key, const location *loc)
+{
+ return semantic_type_from_uniqstr (uniqstr_new (key), loc);
+}
+
+
+/*------------------------------------------------------------------.
+| Generate a dummy nonterminal, whose name cannot conflict with the |
+| user's names. |
+`------------------------------------------------------------------*/
+
+symbol *
+dummy_symbol_get (location loc)
+{
+ /* Incremented for each generated symbol. */
+ static int dummy_count = 0;
+ static char buf[256];
+
+ symbol *sym;
+
+ sprintf (buf, "$@%d", ++dummy_count);
+ sym = symbol_get (buf, loc);
+ sym->class = nterm_sym;
+ sym->number = nvars++;
+ return sym;
+}
+
+bool
+symbol_is_dummy (const symbol *sym)
+{
+ return sym->tag[0] == '@' || (sym->tag[0] == '$' && sym->tag[1] == '@');
+}
+
+/*-------------------.
+| Free the symbols. |
+`-------------------*/
+
+void
+symbols_free (void)
+{
+ hash_free (symbol_table);
+ hash_free (semantic_type_table);
+ free (symbols);
+ free (symbols_sorted);
+ free (semantic_types_sorted);
+}
+
+
+/*---------------------------------------------------------------.
+| Look for undefined symbols, report an error, and consider them |
+| terminals. |
+`---------------------------------------------------------------*/
+
+static int
+symbols_cmp (symbol const *a, symbol const *b)
+{
+ return strcmp (a->tag, b->tag);
+}
+
+static int
+symbols_cmp_qsort (void const *a, void const *b)
+{
+ return symbols_cmp (*(symbol * const *)a, *(symbol * const *)b);
+}
+
+static void
+symbols_do (Hash_processor processor, void *processor_data,
+ struct hash_table *table, symbol ***sorted)
+{
+ size_t count = hash_get_n_entries (table);
+ if (!*sorted)
+ {
+ *sorted = xnmalloc (count, sizeof **sorted);
+ hash_get_entries (table, (void**)*sorted, count);
+ qsort (*sorted, count, sizeof **sorted, symbols_cmp_qsort);
+ }
+ {
+ size_t i;
+ for (i = 0; i < count; ++i)
+ processor ((*sorted)[i], processor_data);
+ }
+}
+
+/*--------------------------------------------------------------.
+| Check that all the symbols are defined. Report any undefined |
+| symbols and consider them nonterminals. |
+`--------------------------------------------------------------*/
+
+void
+symbols_check_defined (void)
+{
+ symbols_do (symbol_check_defined_processor, NULL,
+ symbol_table, &symbols_sorted);
+ symbols_do (semantic_type_check_defined_processor, NULL,
+ semantic_type_table, &semantic_types_sorted);
+}
+
+/*------------------------------------------------------------------.
+| Set TOKEN_TRANSLATIONS. Check that no two symbols share the same |
+| number. |
+`------------------------------------------------------------------*/
+
+static void
+symbols_token_translations_init (void)
+{
+ bool num_256_available_p = true;
+ int i;
+
+ /* Find the highest user token number, and whether 256, the POSIX
+ preferred user token number for the error token, is used. */
+ max_user_token_number = 0;
+ for (i = 0; i < ntokens; ++i)
+ {
+ symbol *this = symbols[i];
+ if (this->user_token_number != USER_NUMBER_UNDEFINED)
+ {
+ if (this->user_token_number > max_user_token_number)
+ max_user_token_number = this->user_token_number;
+ if (this->user_token_number == 256)
+ num_256_available_p = false;
+ }
+ }
+
+ /* If 256 is not used, assign it to error, to follow POSIX. */
+ if (num_256_available_p
+ && errtoken->user_token_number == USER_NUMBER_UNDEFINED)
+ errtoken->user_token_number = 256;
+
+ /* Set the missing user numbers. */
+ if (max_user_token_number < 256)
+ max_user_token_number = 256;
+
+ for (i = 0; i < ntokens; ++i)
+ {
+ symbol *this = symbols[i];
+ if (this->user_token_number == USER_NUMBER_UNDEFINED)
+ this->user_token_number = ++max_user_token_number;
+ if (this->user_token_number > max_user_token_number)
+ max_user_token_number = this->user_token_number;
+ }
+
+ token_translations = xnmalloc (max_user_token_number + 1,
+ sizeof *token_translations);
+
+ /* Initialize all entries for literal tokens to the internal token
+ number for $undefined, which represents all invalid inputs. */
+ for (i = 0; i < max_user_token_number + 1; i++)
+ token_translations[i] = undeftoken->number;
+ symbols_do (symbol_translation_processor, NULL,
+ symbol_table, &symbols_sorted);
+}
+
+
+/*----------------------------------------------------------------.
+| Assign symbol numbers, and write definition of token names into |
+| FDEFINES. Set up vectors SYMBOL_TABLE, TAGS of symbols. |
+`----------------------------------------------------------------*/
+
+void
+symbols_pack (void)
+{
+ symbols_do (symbol_check_alias_consistency_processor, NULL,
+ symbol_table, &symbols_sorted);
+
+ symbols = xcalloc (nsyms, sizeof *symbols);
+ symbols_do (symbol_pack_processor, NULL, symbol_table, &symbols_sorted);
+
+ /* Aliases leave empty slots in symbols, so remove them. */
+ {
+ int writei;
+ int readi;
+ int nsyms_old = nsyms;
+ for (writei = 0, readi = 0; readi < nsyms_old; readi += 1)
+ {
+ if (symbols[readi] == NULL)
+ {
+ nsyms -= 1;
+ ntokens -= 1;
+ }
+ else
+ {
+ symbols[writei] = symbols[readi];
+ symbols[writei]->number = writei;
+ if (symbols[writei]->alias)
+ symbols[writei]->alias->number = writei;
+ writei += 1;
+ }
+ }
+ }
+ symbols = xnrealloc (symbols, nsyms, sizeof *symbols);
+
+ symbols_token_translations_init ();
+
+ if (startsymbol->class == unknown_sym)
+ complain (&startsymbol_location, fatal,
+ _("the start symbol %s is undefined"),
+ startsymbol->tag);
+ else if (startsymbol->class == token_sym)
+ complain (&startsymbol_location, fatal,
+ _("the start symbol %s is a token"),
+ startsymbol->tag);
+}
+
+/*---------------------------------.
+| Initialize relation graph nodes. |
+`---------------------------------*/
+
+static void
+init_prec_nodes (void)
+{
+ int i;
+ symgraph* s;
+ prec_nodes = xcalloc (nsyms, sizeof *prec_nodes);
+ for (i = 0; i < nsyms; ++i)
+ {
+ prec_nodes[i] = xmalloc (sizeof *prec_nodes[i]);
+ s = prec_nodes[i];
+ s->id = i;
+ s->succ = 0;
+ s->pred = 0;
+ }
+}
+
+/*----------------.
+| Create a link. |
+`----------------*/
+
+static symgraphlink *
+symgraphlink_new (graphid id, symgraphlink *next)
+{
+ symgraphlink *l = xmalloc (sizeof *l);
+ l->id = id;
+ l->next = next;
+ return l;
+}
+
+
+/*------------------------------------------------------------------.
+| Register the second symbol of the precedence relation, and return |
+| whether this relation is new. Use only in register_precedence. |
+`------------------------------------------------------------------*/
+
+static bool
+register_precedence_second_symbol (symgraphlink **first, graphid sym)
+{
+ if (!*first || sym < (*first)->id)
+ *first = symgraphlink_new (sym, *first);
+ else
+ {
+ symgraphlink *slist = *first;
+
+ while (slist->next && slist->next->id <= sym)
+ slist = slist->next;
+
+ if (slist->id == sym)
+ /* Relation already present. */
+ return false;
+
+ slist->next = symgraphlink_new (sym, slist->next);
+ }
+ return true;
+}
+
+/*------------------------------------------------------------------.
+| Register a new relation between symbols as used. The first symbol |
+| has a greater precedence than the second one. |
+`------------------------------------------------------------------*/
+
+void
+register_precedence (graphid first, graphid snd)
+{
+ if (!prec_nodes)
+ init_prec_nodes ();
+ register_precedence_second_symbol (&(prec_nodes[first]->succ), snd);
+ register_precedence_second_symbol (&(prec_nodes[snd]->pred), first);
+}
+
+
+/*---------------------------------------.
+| Deep clear a linked / adjacency list). |
+`---------------------------------------*/
+
+static void
+linkedlist_free (symgraphlink *node)
+{
+ if (node)
+ {
+ while (node->next)
+ {
+ symgraphlink *tmp = node->next;
+ free (node);
+ node = tmp;
+ }
+ free (node);
+ }
+}
+
+/*----------------------------------------------.
+| Clear and destroy association tracking table. |
+`----------------------------------------------*/
+
+static void
+assoc_free (void)
+{
+ int i;
+ for (i = 0; i < nsyms; ++i)
+ {
+ linkedlist_free (prec_nodes[i]->pred);
+ linkedlist_free (prec_nodes[i]->succ);
+ free (prec_nodes[i]);
+ }
+ free (prec_nodes);
+}
+
+/*---------------------------------------.
+| Initialize association tracking table. |
+`---------------------------------------*/
+
+static void
+init_assoc (void)
+{
+ graphid i;
+ used_assoc = xcalloc (nsyms, sizeof *used_assoc);
+ for (i = 0; i < nsyms; ++i)
+ used_assoc[i] = false;
+}
+
+/*------------------------------------------------------------------.
+| Test if the associativity for the symbols is defined and useless. |
+`------------------------------------------------------------------*/
+
+static inline bool
+is_assoc_useless (symbol *s)
+{
+ return s
+ && s->assoc != undef_assoc
+ && s->assoc != precedence_assoc
+ && !used_assoc[s->number];
+}
+
+/*-------------------------------.
+| Register a used associativity. |
+`-------------------------------*/
+
+void
+register_assoc (graphid i, graphid j)
+{
+ if (!used_assoc)
+ init_assoc ();
+ used_assoc[i] = true;
+ used_assoc[j] = true;
+}
+
+/*--------------------------------------------------.
+| Print a warning for unused precedence relations. |
+`--------------------------------------------------*/
+
+void
+print_precedence_warnings (void)
+{
+ int i;
+ if (!prec_nodes)
+ init_prec_nodes ();
+ if (!used_assoc)
+ init_assoc ();
+ for (i = 0; i < nsyms; ++i)
+ {
+ symbol *s = symbols[i];
+ if (s
+ && s->prec != 0
+ && !prec_nodes[i]->pred
+ && !prec_nodes[i]->succ)
+ {
+ if (is_assoc_useless (s))
+ complain (&s->prec_location, Wprecedence,
+ _("useless precedence and associativity for %s"), s->tag);
+ else if (s->assoc == precedence_assoc)
+ complain (&s->prec_location, Wprecedence,
+ _("useless precedence for %s"), s->tag);
+ }
+ else if (is_assoc_useless (s))
+ complain (&s->prec_location, Wprecedence,
+ _("useless associativity for %s, use %%precedence"), s->tag);
+ }
+ free (used_assoc);
+ assoc_free ();
+}
diff --git a/contrib/tools/bison/bison/src/symtab.h b/contrib/tools/bison/bison/src/symtab.h
index bcc749511c..59f2f0e990 100644
--- a/contrib/tools/bison/bison/src/symtab.h
+++ b/contrib/tools/bison/bison/src/symtab.h
@@ -1,338 +1,338 @@
-/* Definitions for symtab.c and callers, part of Bison.
-
- Copyright (C) 1984, 1989, 1992, 2000-2002, 2004-2013 Free Software
- Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/**
- * \file symtab.h
- * \brief Manipulating ::symbol.
- */
-
-#ifndef SYMTAB_H_
-# define SYMTAB_H_
-
-# include "assoc.h"
-# include "location.h"
-# include "scan-code.h"
-# include "uniqstr.h"
-
-/*----------.
-| Symbols. |
-`----------*/
-
-/** Symbol classes. */
-typedef enum
-{
- unknown_sym, /**< Undefined. */
- token_sym, /**< Terminal. */
- nterm_sym /**< Non-terminal. */
-} symbol_class;
-
-
-/** Internal token numbers. */
-typedef int symbol_number;
-# define SYMBOL_NUMBER_MAXIMUM INT_MAX
-
-
-typedef struct symbol symbol;
-
-/* Declaration status of a symbol.
-
- First, it is "undeclared". Then, if "undeclared" and used in a
- %printer/%destructor, it is "used". If not "declared" but used in
- a rule, it is "needed". Finally, if declared (via a rule for
- nonterminals, or %token), it is "declared".
-
- When status are checked at the end, "declared" symbols are fine,
- "used" symbols trigger warnings, otherwise it's an error. */
-
-typedef enum
- {
- /** Used in the input file for an unknown reason (error). */
- undeclared,
- /** Used by %destructor/%printer but not defined (warning). */
- used,
- /** Used in the gramar (rules) but not defined (error). */
- needed,
- /** Defined with %type or %token (good). */
- declared,
- } status;
-
-typedef enum code_props_type code_props_type;
-enum code_props_type
- {
- destructor = 0,
- printer = 1,
- };
-
-enum { CODE_PROPS_SIZE = 2 };
-
-/* When extending this structure, be sure to complete
- symbol_check_alias_consistency. */
-struct symbol
-{
- /** The key, name of the symbol. */
- uniqstr tag;
- /** The location of its first occurrence. */
- location location;
-
- /** Its \c \%type.
-
- Beware that this is the type_name as was entered by the user,
- including silly things such as "]" if she entered "%token <]> t".
- Therefore, when outputting type_name to M4, be sure to escape it
- into "@}". See quoted_output for instance. */
- uniqstr type_name;
-
- /** Its \c \%type's location. */
- location type_location;
-
- /** Any \c \%destructor (resp. \%printer) declared specificially for this
- symbol.
-
- Access this field only through <tt>symbol</tt>'s interface functions. For
- example, if <tt>symbol::destructor = NULL</tt> (resp. <tt>symbol::printer
- = NULL</tt>), a default \c \%destructor (resp. \%printer) or a per-type
- \c symbol_destructor_printer_get will compute the correct one. */
- code_props props[CODE_PROPS_SIZE];
-
- symbol_number number;
- location prec_location;
- int prec;
- assoc assoc;
- int user_token_number;
-
- /* Points to the other in the symbol-string pair for an alias.
- Special value USER_NUMBER_HAS_STRING_ALIAS in the symbol half of the
- symbol-string pair for an alias. */
- symbol *alias;
- symbol_class class;
- status status;
-};
-
-/** Undefined user number. */
-# define USER_NUMBER_UNDEFINED -1
-
-/* 'symbol->user_token_number == USER_NUMBER_HAS_STRING_ALIAS' means
- this symbol has a literal string alias. For instance, '%token foo
- "foo"' has '"foo"' numbered regularly, and 'foo' numbered as
- USER_NUMBER_HAS_STRING_ALIAS. */
-# define USER_NUMBER_HAS_STRING_ALIAS -9991
-
-/* Undefined internal token number. */
-# define NUMBER_UNDEFINED (-1)
-
-/** Fetch (or create) the symbol associated to KEY. */
-symbol *symbol_from_uniqstr (const uniqstr key, location loc);
-
-/** Fetch (or create) the symbol associated to KEY. */
-symbol *symbol_get (const char *key, location loc);
-
-/** Generate a dummy nonterminal.
-
- Its name cannot conflict with the user's names. */
-symbol *dummy_symbol_get (location loc);
-
-
-/*--------------------.
-| Methods on symbol. |
-`--------------------*/
-
-/** Print a symbol (for debugging). */
-void symbol_print (symbol const *s, FILE *f);
-
-/** Is this a dummy nonterminal? */
-bool symbol_is_dummy (const symbol *sym);
-
-/** The name of the code_props type: "\%destructor" or "\%printer". */
-char const *code_props_type_string (code_props_type kind);
-
-/** The name of the symbol that can be used as an identifier.
- ** Consider the alias if needed.
- ** Return 0 if there is none (e.g., the symbol is only defined as
- ** a string). */
-uniqstr symbol_id_get (symbol const *sym);
-
-/**
- * Make \c str the literal string alias of \c sym. Copy token number,
- * symbol number, and type from \c sym to \c str.
- */
-void symbol_make_alias (symbol *sym, symbol *str, location loc);
-
-/** Set the \c type_name associated with \c sym.
-
- Do nothing if passed 0 as \c type_name. */
-void symbol_type_set (symbol *sym, uniqstr type_name, location loc);
-
-/** Set the \c \%destructor or \c \%printer associated with \c sym. */
-void symbol_code_props_set (symbol *sym, code_props_type kind,
- code_props const *destructor);
-
-/** Get the computed \c \%destructor or \c %printer for \c sym, which was
- initialized with \c code_props_none_init if there's no \c \%destructor or
- \c %printer. */
-code_props *symbol_code_props_get (symbol *sym, code_props_type kind);
-
-/** Set the \c precedence associated with \c sym.
-
- Ensure that \a symbol is a terminal.
- Do nothing if invoked with \c undef_assoc as \c assoc. */
-void symbol_precedence_set (symbol *sym, int prec, assoc a, location loc);
-
-/** Set the \c class associated with \c sym. */
-void symbol_class_set (symbol *sym, symbol_class class, location loc,
- bool declaring);
-
-/** Set the \c user_token_number associated with \c sym. */
-void symbol_user_token_number_set (symbol *sym, int user_number, location loc);
-
-
-
-/*------------------.
-| Special symbols. |
-`------------------*/
-
-/** The error token. */
-extern symbol *errtoken;
-/** The token for unknown tokens. */
-extern symbol *undeftoken;
-/** The end of input token. */
-extern symbol *endtoken;
-/** The genuine start symbol.
-
- $accept: start-symbol $end */
-extern symbol *accept;
-
-/** The user start symbol. */
-extern symbol *startsymbol;
-/** The location of the \c \%start declaration. */
-extern location startsymbol_location;
-
-
-
-/*-------------------.
-| Symbol Relations. |
-`-------------------*/
-
-/* The symbol relations are represented by a directed graph. */
-
-/* The id of a node */
-typedef int graphid;
-
-typedef struct symgraphlink symgraphlink;
-
-struct symgraphlink
-{
- /** The second \c symbol or group of a precedence relation.
- * See \c symgraph. */
- graphid id;
-
- symgraphlink *next;
-};
-
-/* Symbol precedence graph, to store the used precedence relations between
- * symbols. */
-
-typedef struct symgraph symgraph;
-
-struct symgraph
-{
- /** Identifier for the node: equal to the number of the symbol. */
- graphid id;
-
- /** The list of related symbols that have a smaller precedence. */
- symgraphlink *succ;
-
- /** The list of related symbols that have a greater precedence. */
- symgraphlink *pred;
-};
-
-/** Register a new precedence relation as used. */
-
-void register_precedence (graphid first, graphid snd);
-
-/** Print a warning for each symbol whose precedence and/or associativity
- * is useless. */
-
-void print_precedence_warnings (void);
-
-/*----------------------.
-| Symbol associativity |
-`----------------------*/
-
-void register_assoc (graphid i, graphid j);
-
-/*-----------------.
-| Semantic types. |
-`-----------------*/
-
-/** A semantic type and its associated \c \%destructor and \c \%printer.
-
- Access the fields of this struct only through the interface functions in
- this file. \sa symbol::destructor */
-typedef struct {
- /** The key, name of the semantic type. */
- uniqstr tag;
-
- /** The location of its first occurence. */
- location location;
-
- /** Its status : "undeclared", "used" or "declared".
- It cannot be "needed". */
- status status;
-
- /** Any \c %destructor and %printer declared for this
- semantic type. */
- code_props props[CODE_PROPS_SIZE];
-
-} semantic_type;
-
-/** Fetch (or create) the semantic type associated to KEY. */
-semantic_type *semantic_type_from_uniqstr (const uniqstr key,
- const location *loc);
-
-/** Fetch (or create) the semantic type associated to KEY. */
-semantic_type *semantic_type_get (const char *key, const location *loc);
-
-/** Set the \c destructor or \c printer associated with \c type. */
-void semantic_type_code_props_set (semantic_type *type,
- code_props_type kind,
- code_props const *code);
-
-/*----------------------------------.
-| Symbol and semantic type tables. |
-`----------------------------------*/
-
-/** Create the symbol and semantic type tables. */
-void symbols_new (void);
-
-/** Free all the memory allocated for symbols and semantic types. */
-void symbols_free (void);
-
-/** Check that all the symbols are defined.
-
- Report any undefined symbols and consider them nonterminals. */
-void symbols_check_defined (void);
-
-/** Sanity checks and #token_translations construction.
-
- Perform various sanity checks, assign symbol numbers, and set up
- #token_translations. */
-void symbols_pack (void);
-
-#endif /* !SYMTAB_H_ */
+/* Definitions for symtab.c and callers, part of Bison.
+
+ Copyright (C) 1984, 1989, 1992, 2000-2002, 2004-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/**
+ * \file symtab.h
+ * \brief Manipulating ::symbol.
+ */
+
+#ifndef SYMTAB_H_
+# define SYMTAB_H_
+
+# include "assoc.h"
+# include "location.h"
+# include "scan-code.h"
+# include "uniqstr.h"
+
+/*----------.
+| Symbols. |
+`----------*/
+
+/** Symbol classes. */
+typedef enum
+{
+ unknown_sym, /**< Undefined. */
+ token_sym, /**< Terminal. */
+ nterm_sym /**< Non-terminal. */
+} symbol_class;
+
+
+/** Internal token numbers. */
+typedef int symbol_number;
+# define SYMBOL_NUMBER_MAXIMUM INT_MAX
+
+
+typedef struct symbol symbol;
+
+/* Declaration status of a symbol.
+
+ First, it is "undeclared". Then, if "undeclared" and used in a
+ %printer/%destructor, it is "used". If not "declared" but used in
+ a rule, it is "needed". Finally, if declared (via a rule for
+ nonterminals, or %token), it is "declared".
+
+ When status are checked at the end, "declared" symbols are fine,
+ "used" symbols trigger warnings, otherwise it's an error. */
+
+typedef enum
+ {
+ /** Used in the input file for an unknown reason (error). */
+ undeclared,
+ /** Used by %destructor/%printer but not defined (warning). */
+ used,
+ /** Used in the gramar (rules) but not defined (error). */
+ needed,
+ /** Defined with %type or %token (good). */
+ declared,
+ } status;
+
+typedef enum code_props_type code_props_type;
+enum code_props_type
+ {
+ destructor = 0,
+ printer = 1,
+ };
+
+enum { CODE_PROPS_SIZE = 2 };
+
+/* When extending this structure, be sure to complete
+ symbol_check_alias_consistency. */
+struct symbol
+{
+ /** The key, name of the symbol. */
+ uniqstr tag;
+ /** The location of its first occurrence. */
+ location location;
+
+ /** Its \c \%type.
+
+ Beware that this is the type_name as was entered by the user,
+ including silly things such as "]" if she entered "%token <]> t".
+ Therefore, when outputting type_name to M4, be sure to escape it
+ into "@}". See quoted_output for instance. */
+ uniqstr type_name;
+
+ /** Its \c \%type's location. */
+ location type_location;
+
+ /** Any \c \%destructor (resp. \%printer) declared specificially for this
+ symbol.
+
+ Access this field only through <tt>symbol</tt>'s interface functions. For
+ example, if <tt>symbol::destructor = NULL</tt> (resp. <tt>symbol::printer
+ = NULL</tt>), a default \c \%destructor (resp. \%printer) or a per-type
+ \c symbol_destructor_printer_get will compute the correct one. */
+ code_props props[CODE_PROPS_SIZE];
+
+ symbol_number number;
+ location prec_location;
+ int prec;
+ assoc assoc;
+ int user_token_number;
+
+ /* Points to the other in the symbol-string pair for an alias.
+ Special value USER_NUMBER_HAS_STRING_ALIAS in the symbol half of the
+ symbol-string pair for an alias. */
+ symbol *alias;
+ symbol_class class;
+ status status;
+};
+
+/** Undefined user number. */
+# define USER_NUMBER_UNDEFINED -1
+
+/* 'symbol->user_token_number == USER_NUMBER_HAS_STRING_ALIAS' means
+ this symbol has a literal string alias. For instance, '%token foo
+ "foo"' has '"foo"' numbered regularly, and 'foo' numbered as
+ USER_NUMBER_HAS_STRING_ALIAS. */
+# define USER_NUMBER_HAS_STRING_ALIAS -9991
+
+/* Undefined internal token number. */
+# define NUMBER_UNDEFINED (-1)
+
+/** Fetch (or create) the symbol associated to KEY. */
+symbol *symbol_from_uniqstr (const uniqstr key, location loc);
+
+/** Fetch (or create) the symbol associated to KEY. */
+symbol *symbol_get (const char *key, location loc);
+
+/** Generate a dummy nonterminal.
+
+ Its name cannot conflict with the user's names. */
+symbol *dummy_symbol_get (location loc);
+
+
+/*--------------------.
+| Methods on symbol. |
+`--------------------*/
+
+/** Print a symbol (for debugging). */
+void symbol_print (symbol const *s, FILE *f);
+
+/** Is this a dummy nonterminal? */
+bool symbol_is_dummy (const symbol *sym);
+
+/** The name of the code_props type: "\%destructor" or "\%printer". */
+char const *code_props_type_string (code_props_type kind);
+
+/** The name of the symbol that can be used as an identifier.
+ ** Consider the alias if needed.
+ ** Return 0 if there is none (e.g., the symbol is only defined as
+ ** a string). */
+uniqstr symbol_id_get (symbol const *sym);
+
+/**
+ * Make \c str the literal string alias of \c sym. Copy token number,
+ * symbol number, and type from \c sym to \c str.
+ */
+void symbol_make_alias (symbol *sym, symbol *str, location loc);
+
+/** Set the \c type_name associated with \c sym.
+
+ Do nothing if passed 0 as \c type_name. */
+void symbol_type_set (symbol *sym, uniqstr type_name, location loc);
+
+/** Set the \c \%destructor or \c \%printer associated with \c sym. */
+void symbol_code_props_set (symbol *sym, code_props_type kind,
+ code_props const *destructor);
+
+/** Get the computed \c \%destructor or \c %printer for \c sym, which was
+ initialized with \c code_props_none_init if there's no \c \%destructor or
+ \c %printer. */
+code_props *symbol_code_props_get (symbol *sym, code_props_type kind);
+
+/** Set the \c precedence associated with \c sym.
+
+ Ensure that \a symbol is a terminal.
+ Do nothing if invoked with \c undef_assoc as \c assoc. */
+void symbol_precedence_set (symbol *sym, int prec, assoc a, location loc);
+
+/** Set the \c class associated with \c sym. */
+void symbol_class_set (symbol *sym, symbol_class class, location loc,
+ bool declaring);
+
+/** Set the \c user_token_number associated with \c sym. */
+void symbol_user_token_number_set (symbol *sym, int user_number, location loc);
+
+
+
+/*------------------.
+| Special symbols. |
+`------------------*/
+
+/** The error token. */
+extern symbol *errtoken;
+/** The token for unknown tokens. */
+extern symbol *undeftoken;
+/** The end of input token. */
+extern symbol *endtoken;
+/** The genuine start symbol.
+
+ $accept: start-symbol $end */
+extern symbol *accept;
+
+/** The user start symbol. */
+extern symbol *startsymbol;
+/** The location of the \c \%start declaration. */
+extern location startsymbol_location;
+
+
+
+/*-------------------.
+| Symbol Relations. |
+`-------------------*/
+
+/* The symbol relations are represented by a directed graph. */
+
+/* The id of a node */
+typedef int graphid;
+
+typedef struct symgraphlink symgraphlink;
+
+struct symgraphlink
+{
+ /** The second \c symbol or group of a precedence relation.
+ * See \c symgraph. */
+ graphid id;
+
+ symgraphlink *next;
+};
+
+/* Symbol precedence graph, to store the used precedence relations between
+ * symbols. */
+
+typedef struct symgraph symgraph;
+
+struct symgraph
+{
+ /** Identifier for the node: equal to the number of the symbol. */
+ graphid id;
+
+ /** The list of related symbols that have a smaller precedence. */
+ symgraphlink *succ;
+
+ /** The list of related symbols that have a greater precedence. */
+ symgraphlink *pred;
+};
+
+/** Register a new precedence relation as used. */
+
+void register_precedence (graphid first, graphid snd);
+
+/** Print a warning for each symbol whose precedence and/or associativity
+ * is useless. */
+
+void print_precedence_warnings (void);
+
+/*----------------------.
+| Symbol associativity |
+`----------------------*/
+
+void register_assoc (graphid i, graphid j);
+
+/*-----------------.
+| Semantic types. |
+`-----------------*/
+
+/** A semantic type and its associated \c \%destructor and \c \%printer.
+
+ Access the fields of this struct only through the interface functions in
+ this file. \sa symbol::destructor */
+typedef struct {
+ /** The key, name of the semantic type. */
+ uniqstr tag;
+
+ /** The location of its first occurence. */
+ location location;
+
+ /** Its status : "undeclared", "used" or "declared".
+ It cannot be "needed". */
+ status status;
+
+ /** Any \c %destructor and %printer declared for this
+ semantic type. */
+ code_props props[CODE_PROPS_SIZE];
+
+} semantic_type;
+
+/** Fetch (or create) the semantic type associated to KEY. */
+semantic_type *semantic_type_from_uniqstr (const uniqstr key,
+ const location *loc);
+
+/** Fetch (or create) the semantic type associated to KEY. */
+semantic_type *semantic_type_get (const char *key, const location *loc);
+
+/** Set the \c destructor or \c printer associated with \c type. */
+void semantic_type_code_props_set (semantic_type *type,
+ code_props_type kind,
+ code_props const *code);
+
+/*----------------------------------.
+| Symbol and semantic type tables. |
+`----------------------------------*/
+
+/** Create the symbol and semantic type tables. */
+void symbols_new (void);
+
+/** Free all the memory allocated for symbols and semantic types. */
+void symbols_free (void);
+
+/** Check that all the symbols are defined.
+
+ Report any undefined symbols and consider them nonterminals. */
+void symbols_check_defined (void);
+
+/** Sanity checks and #token_translations construction.
+
+ Perform various sanity checks, assign symbol numbers, and set up
+ #token_translations. */
+void symbols_pack (void);
+
+#endif /* !SYMTAB_H_ */
diff --git a/contrib/tools/bison/bison/src/system.h b/contrib/tools/bison/bison/src/system.h
index 3267f2d24c..396a609435 100644
--- a/contrib/tools/bison/bison/src/system.h
+++ b/contrib/tools/bison/bison/src/system.h
@@ -1,261 +1,261 @@
-/* System-dependent definitions for Bison.
-
- Copyright (C) 2000-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef BISON_SYSTEM_H
-# define BISON_SYSTEM_H
-
-/* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this
- runs afoul of pre-C99 compilers that have <inttypes.h> or
- <stdint.h>, which are included below if available. It also runs
- afoul of pre-C99 compilers that define these macros in <limits.h>. */
-# if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901
-# undef INT8_MIN
-# undef INT16_MIN
-# undef INT32_MIN
-# undef INT8_MAX
-# undef INT16_MAX
-# undef UINT8_MAX
-# undef INT32_MAX
-# undef UINT16_MAX
-# undef UINT32_MAX
-# endif
-
-# include <limits.h>
-# include <stddef.h>
-# include <stdlib.h>
-# include <string.h>
-
-# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
-# define STREQ(L, R) (strcmp(L, R) == 0)
-# define STRNEQ(L, R) (!STREQ(L, R))
-
-/* Just like strncmp, but the second argument must be a literal string
- and you don't specify the length. */
-# define STRNCMP_LIT(S, Literal) \
- strncmp (S, "" Literal "", sizeof (Literal) - 1)
-
-/* Whether Literal is a prefix of S. */
-# define STRPREFIX_LIT(Literal, S) \
- (STRNCMP_LIT (S, Literal) == 0)
-
-# include <unistd.h>
-# include <inttypes.h>
-
-# ifndef UINTPTR_MAX
-/* This isn't perfect, but it's good enough for Bison, which needs
- only to hash pointers. */
-typedef size_t uintptr_t;
-# endif
-
-/* Version mismatch. */
-# define EX_MISMATCH 63
-
-/*---------.
-| Gnulib. |
-`---------*/
-
-# include <unlocked-io.h>
-# include <verify.h>
-# include <xalloc.h>
-
-
-/*-----------------.
-| GCC extensions. |
-`-----------------*/
-
-/* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison
- but that it is necessary for suppressing compiler warnings. For example,
- Code might be a variable initializer that's always overwritten before the
- variable is used.
-
- PACIFY_CC is intended to be useful only as a comment as it does not alter
- Code. It is tempting to redefine PACIFY_CC so that it will suppress Code
- when configuring without --enable-gcc-warnings. However, that would mean
- that, for maintainers, Bison would compile with potentially less warnings
- and safer logic than it would for users. Due to the overhead of M4,
- suppressing Code is unlikely to offer any significant improvement in
- Bison's performance anyway. */
-# define PACIFY_CC(Code) Code
-
-# ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if (! defined __GNUC__ || __GNUC__ < 2 \
- || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
-# define __attribute__(Spec) /* empty */
-# endif
-# endif
-
-/* The __-protected variants of 'format' and 'printf' attributes
- are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __format__ format
-# define __printf__ printf
-# endif
-
-# ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
-# endif
-
-# ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-# endif
-
-
-/*------.
-| NLS. |
-`------*/
-
-# include <locale.h>
-
-# include <gettext.h>
-# define _(Msgid) gettext (Msgid)
-# define N_(Msgid) (Msgid)
-
-
-/*-----------.
-| Booleans. |
-`-----------*/
-
-# include <stdbool.h>
-
-
-
-/*-------------.
-| Assertions. |
-`-------------*/
-
-/* In the past, Bison defined aver to simply invoke abort in the case of
- a failed assertion. The rationale was that <assert.h>'s assertions
- were too heavyweight and could be disabled too easily. See
- discussions at
- <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
- <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
-
- However, normal assert output can be helpful during development and
- in bug reports from users. Moreover, it's not clear now that
- <assert.h>'s assertions are significantly heavyweight. Finally, if
- users want to experiment with disabling assertions, it's debatable
- whether it's our responsibility to stop them. See discussion
- starting at
- <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
-
- For now, we use assert but we call it aver throughout Bison in case
- we later wish to try another scheme.
-*/
-# include <assert.h>
-# define aver assert
-
-
-/*-----------.
-| Obstacks. |
-`-----------*/
-
-# define obstack_chunk_alloc xmalloc
-# define obstack_chunk_free free
-# include <obstack.h>
-
-/* String-grow: append Str to Obs. */
-
-# define obstack_sgrow(Obs, Str) \
- obstack_grow (Obs, Str, strlen (Str))
-
-/* Output Str escaped for our postprocessing (i.e., escape M4 special
- characters).
-
- For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */
-
-# define obstack_escape(Obs, Str) \
- do { \
- char const *p__; \
- for (p__ = Str; *p__; p__++) \
- switch (*p__) \
- { \
- case '$': obstack_sgrow (Obs, "$]["); break; \
- case '@': obstack_sgrow (Obs, "@@" ); break; \
- case '[': obstack_sgrow (Obs, "@{" ); break; \
- case ']': obstack_sgrow (Obs, "@}" ); break; \
- default: obstack_1grow (Obs, *p__ ); break; \
- } \
- } while (0)
-
-
-/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
- for our postprocessing (i.e., escape M4 special characters). If
- Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
- programming easier (m4_ifval can be used).
-
- For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
-
-# define obstack_quote(Obs, Str) \
- do { \
- char const* obstack_quote_p = Str; \
- if (obstack_quote_p && obstack_quote_p[0]) \
- { \
- obstack_sgrow (Obs, "[["); \
- obstack_escape (Obs, obstack_quote_p); \
- obstack_sgrow (Obs, "]]"); \
- } \
- else \
- obstack_sgrow (Obs, "[]"); \
- } while (0)
-
-
-/* Append the ending 0, finish Obs, and return the string. */
-
-# define obstack_finish0(Obs) \
- (obstack_1grow (Obs, '\0'), (char *) obstack_finish (Obs))
-
-
-/*-----------------------------------------.
-| Extensions to use for the output files. |
-`-----------------------------------------*/
-
-# ifndef OUTPUT_EXT
-# define OUTPUT_EXT ".output"
-# endif
-
-# ifndef TAB_EXT
-# define TAB_EXT ".tab"
-# endif
-
-
-
-/*---------------------.
-| Free a linked list. |
-`---------------------*/
-
-# define LIST_FREE(Type, List) \
- do { \
- Type *_node, *_next; \
- for (_node = List; _node; _node = _next) \
- { \
- _next = _node->next; \
- free (_node); \
- } \
- } while (0)
-
-
-/*---------------------------------------------.
-| Debugging memory allocation (must be last). |
-`---------------------------------------------*/
-
-# if WITH_DMALLOC
-# define DMALLOC_FUNC_CHECK
-# include <dmalloc.h>
-# endif /* WITH_DMALLOC */
-
-#endif /* ! BISON_SYSTEM_H */
+/* System-dependent definitions for Bison.
+
+ Copyright (C) 2000-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef BISON_SYSTEM_H
+# define BISON_SYSTEM_H
+
+/* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this
+ runs afoul of pre-C99 compilers that have <inttypes.h> or
+ <stdint.h>, which are included below if available. It also runs
+ afoul of pre-C99 compilers that define these macros in <limits.h>. */
+# if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901
+# undef INT8_MIN
+# undef INT16_MIN
+# undef INT32_MIN
+# undef INT8_MAX
+# undef INT16_MAX
+# undef UINT8_MAX
+# undef INT32_MAX
+# undef UINT16_MAX
+# undef UINT32_MAX
+# endif
+
+# include <limits.h>
+# include <stddef.h>
+# include <stdlib.h>
+# include <string.h>
+
+# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
+# define STREQ(L, R) (strcmp(L, R) == 0)
+# define STRNEQ(L, R) (!STREQ(L, R))
+
+/* Just like strncmp, but the second argument must be a literal string
+ and you don't specify the length. */
+# define STRNCMP_LIT(S, Literal) \
+ strncmp (S, "" Literal "", sizeof (Literal) - 1)
+
+/* Whether Literal is a prefix of S. */
+# define STRPREFIX_LIT(Literal, S) \
+ (STRNCMP_LIT (S, Literal) == 0)
+
+# include <unistd.h>
+# include <inttypes.h>
+
+# ifndef UINTPTR_MAX
+/* This isn't perfect, but it's good enough for Bison, which needs
+ only to hash pointers. */
+typedef size_t uintptr_t;
+# endif
+
+/* Version mismatch. */
+# define EX_MISMATCH 63
+
+/*---------.
+| Gnulib. |
+`---------*/
+
+# include <unlocked-io.h>
+# include <verify.h>
+# include <xalloc.h>
+
+
+/*-----------------.
+| GCC extensions. |
+`-----------------*/
+
+/* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison
+ but that it is necessary for suppressing compiler warnings. For example,
+ Code might be a variable initializer that's always overwritten before the
+ variable is used.
+
+ PACIFY_CC is intended to be useful only as a comment as it does not alter
+ Code. It is tempting to redefine PACIFY_CC so that it will suppress Code
+ when configuring without --enable-gcc-warnings. However, that would mean
+ that, for maintainers, Bison would compile with potentially less warnings
+ and safer logic than it would for users. Due to the overhead of M4,
+ suppressing Code is unlikely to offer any significant improvement in
+ Bison's performance anyway. */
+# define PACIFY_CC(Code) Code
+
+# ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if (! defined __GNUC__ || __GNUC__ < 2 \
+ || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
+# define __attribute__(Spec) /* empty */
+# endif
+# endif
+
+/* The __-protected variants of 'format' and 'printf' attributes
+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __format__ format
+# define __printf__ printf
+# endif
+
+# ifndef ATTRIBUTE_NORETURN
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# endif
+
+# ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+# endif
+
+
+/*------.
+| NLS. |
+`------*/
+
+# include <locale.h>
+
+# include <gettext.h>
+# define _(Msgid) gettext (Msgid)
+# define N_(Msgid) (Msgid)
+
+
+/*-----------.
+| Booleans. |
+`-----------*/
+
+# include <stdbool.h>
+
+
+
+/*-------------.
+| Assertions. |
+`-------------*/
+
+/* In the past, Bison defined aver to simply invoke abort in the case of
+ a failed assertion. The rationale was that <assert.h>'s assertions
+ were too heavyweight and could be disabled too easily. See
+ discussions at
+ <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
+ <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
+
+ However, normal assert output can be helpful during development and
+ in bug reports from users. Moreover, it's not clear now that
+ <assert.h>'s assertions are significantly heavyweight. Finally, if
+ users want to experiment with disabling assertions, it's debatable
+ whether it's our responsibility to stop them. See discussion
+ starting at
+ <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
+
+ For now, we use assert but we call it aver throughout Bison in case
+ we later wish to try another scheme.
+*/
+# include <assert.h>
+# define aver assert
+
+
+/*-----------.
+| Obstacks. |
+`-----------*/
+
+# define obstack_chunk_alloc xmalloc
+# define obstack_chunk_free free
+# include <obstack.h>
+
+/* String-grow: append Str to Obs. */
+
+# define obstack_sgrow(Obs, Str) \
+ obstack_grow (Obs, Str, strlen (Str))
+
+/* Output Str escaped for our postprocessing (i.e., escape M4 special
+ characters).
+
+ For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */
+
+# define obstack_escape(Obs, Str) \
+ do { \
+ char const *p__; \
+ for (p__ = Str; *p__; p__++) \
+ switch (*p__) \
+ { \
+ case '$': obstack_sgrow (Obs, "$]["); break; \
+ case '@': obstack_sgrow (Obs, "@@" ); break; \
+ case '[': obstack_sgrow (Obs, "@{" ); break; \
+ case ']': obstack_sgrow (Obs, "@}" ); break; \
+ default: obstack_1grow (Obs, *p__ ); break; \
+ } \
+ } while (0)
+
+
+/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
+ for our postprocessing (i.e., escape M4 special characters). If
+ Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
+ programming easier (m4_ifval can be used).
+
+ For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
+
+# define obstack_quote(Obs, Str) \
+ do { \
+ char const* obstack_quote_p = Str; \
+ if (obstack_quote_p && obstack_quote_p[0]) \
+ { \
+ obstack_sgrow (Obs, "[["); \
+ obstack_escape (Obs, obstack_quote_p); \
+ obstack_sgrow (Obs, "]]"); \
+ } \
+ else \
+ obstack_sgrow (Obs, "[]"); \
+ } while (0)
+
+
+/* Append the ending 0, finish Obs, and return the string. */
+
+# define obstack_finish0(Obs) \
+ (obstack_1grow (Obs, '\0'), (char *) obstack_finish (Obs))
+
+
+/*-----------------------------------------.
+| Extensions to use for the output files. |
+`-----------------------------------------*/
+
+# ifndef OUTPUT_EXT
+# define OUTPUT_EXT ".output"
+# endif
+
+# ifndef TAB_EXT
+# define TAB_EXT ".tab"
+# endif
+
+
+
+/*---------------------.
+| Free a linked list. |
+`---------------------*/
+
+# define LIST_FREE(Type, List) \
+ do { \
+ Type *_node, *_next; \
+ for (_node = List; _node; _node = _next) \
+ { \
+ _next = _node->next; \
+ free (_node); \
+ } \
+ } while (0)
+
+
+/*---------------------------------------------.
+| Debugging memory allocation (must be last). |
+`---------------------------------------------*/
+
+# if WITH_DMALLOC
+# define DMALLOC_FUNC_CHECK
+# include <dmalloc.h>
+# endif /* WITH_DMALLOC */
+
+#endif /* ! BISON_SYSTEM_H */
diff --git a/contrib/tools/bison/bison/src/tables.c b/contrib/tools/bison/bison/src/tables.c
index f06cba86b9..771b0ff691 100644
--- a/contrib/tools/bison/bison/src/tables.c
+++ b/contrib/tools/bison/bison/src/tables.c
@@ -1,863 +1,863 @@
-/* Output the generated parsing program for Bison.
-
- Copyright (C) 1984, 1986, 1989, 1992, 2000-2006, 2009-2013 Free
- Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <bitsetv.h>
-
-#include "complain.h"
-#include "conflicts.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "lalr.h"
-#include "muscle-tab.h"
-#include "reader.h"
-#include "symtab.h"
-#include "tables.h"
-
-/* Several tables are indexed both by state and nonterminal numbers.
- We call such an index a 'vector'; i.e., a vector is either a state
- or a nonterminal number.
-
- Of course vector_number_t ought to be wide enough to contain
- state_number and symbol_number. */
-typedef int vector_number;
-
-#if 0 /* Not currently used. */
-static inline vector_number
-state_number_to_vector_number (state_number s)
-{
- return s;
-}
-#endif
-
-static inline vector_number
-symbol_number_to_vector_number (symbol_number sym)
-{
- return state_number_as_int (nstates) + sym - ntokens;
-}
-
-int nvectors;
-
-
-/* FROMS and TOS are indexed by vector_number.
-
- If VECTOR is a nonterminal, (FROMS[VECTOR], TOS[VECTOR]) form an
- array of state numbers of the non defaulted GOTO on VECTOR.
-
- If VECTOR is a state, TOS[VECTOR] is the array of actions to do on
- the (array of) symbols FROMS[VECTOR].
-
- In both cases, TALLY[VECTOR] is the size of the arrays
- FROMS[VECTOR], TOS[VECTOR]; and WIDTH[VECTOR] =
- (FROMS[VECTOR][SIZE] - FROMS[VECTOR][0] + 1) where SIZE =
- TALLY[VECTOR].
-
- FROMS therefore contains symbol_number and action_number,
- TOS state_number and action_number,
- TALLY sizes,
- WIDTH differences of FROMS.
-
- Let base_number be the type of FROMS, TOS, and WIDTH. */
-#define BASE_MAXIMUM INT_MAX
-#define BASE_MINIMUM INT_MIN
-
-static base_number **froms;
-static base_number **tos;
-static unsigned int **conflict_tos;
-static size_t *tally;
-static base_number *width;
-
-
-/* For a given state, N = ACTROW[SYMBOL]:
-
- If N = 0, stands for 'run the default action'.
- If N = MIN, stands for 'raise a syntax error'.
- If N > 0, stands for 'shift SYMBOL and go to n'.
- If N < 0, stands for 'reduce -N'. */
-typedef int action_number;
-#define ACTION_NUMBER_MINIMUM INT_MIN
-
-static action_number *actrow;
-
-/* FROMS and TOS are reordered to be compressed. ORDER[VECTOR] is the
- new vector number of VECTOR. We skip 'empty' vectors (i.e.,
- TALLY[VECTOR] = 0), and call these 'entries'. */
-static vector_number *order;
-static int nentries;
-
-base_number *base = NULL;
-/* A distinguished value of BASE, negative infinite. During the
- computation equals to BASE_MINIMUM, later mapped to BASE_NINF to
- keep parser tables small. */
-base_number base_ninf = 0;
-static base_number *pos = NULL;
-
-static unsigned int *conflrow;
-unsigned int *conflict_table;
-unsigned int *conflict_list;
-int conflict_list_cnt;
-static int conflict_list_free;
-
-/* TABLE_SIZE is the allocated size of both TABLE and CHECK. We start
- with more or less the original hard-coded value (which was
- SHRT_MAX). */
-static int table_size = 32768;
-base_number *table;
-base_number *check;
-/* The value used in TABLE to denote explicit syntax errors
- (%nonassoc), a negative infinite. First defaults to ACTION_NUMBER_MINIMUM,
- but in order to keep small tables, renumbered as TABLE_ERROR, which
- is the smallest (non error) value minus 1. */
-base_number table_ninf = 0;
-static int lowzero;
-int high;
-
-state_number *yydefgoto;
-rule_number *yydefact;
-
-/*-------------------------------------------------------------------.
-| If TABLE, CONFLICT_TABLE, and CHECK are too small to be addressed |
-| at DESIRED, grow them. TABLE[DESIRED] can be used, so the desired |
-| size is at least DESIRED + 1. |
-`-------------------------------------------------------------------*/
-
-static void
-table_grow (int desired)
-{
- int old_size = table_size;
-
- while (table_size <= desired)
- table_size *= 2;
-
- if (trace_flag & trace_resource)
- fprintf (stderr, "growing table and check from: %d to %d\n",
- old_size, table_size);
-
- table = xnrealloc (table, table_size, sizeof *table);
- conflict_table = xnrealloc (conflict_table, table_size,
- sizeof *conflict_table);
- check = xnrealloc (check, table_size, sizeof *check);
-
- for (/* Nothing. */; old_size < table_size; ++old_size)
- {
- table[old_size] = 0;
- conflict_table[old_size] = 0;
- check[old_size] = -1;
- }
-}
-
-
-
-
-/*-------------------------------------------------------------------.
-| For GLR parsers, for each conflicted token in S, as indicated |
-| by non-zero entries in CONFLROW, create a list of possible |
-| reductions that are alternatives to the shift or reduction |
-| currently recorded for that token in S. Store the alternative |
-| reductions followed by a 0 in CONFLICT_LIST, updating |
-| CONFLICT_LIST_CNT, and storing an index to the start of the list |
-| back into CONFLROW. |
-`-------------------------------------------------------------------*/
-
-static void
-conflict_row (state *s)
-{
- int i, j;
- reductions *reds = s->reductions;
-
- if (!nondeterministic_parser)
- return;
-
- for (j = 0; j < ntokens; j += 1)
- if (conflrow[j])
- {
- conflrow[j] = conflict_list_cnt;
-
- /* Find all reductions for token J, and record all that do not
- match ACTROW[J]. */
- for (i = 0; i < reds->num; i += 1)
- if (bitset_test (reds->lookahead_tokens[i], j)
- && (actrow[j]
- != rule_number_as_item_number (reds->rules[i]->number)))
- {
- aver (0 < conflict_list_free);
- conflict_list[conflict_list_cnt] = reds->rules[i]->number + 1;
- conflict_list_cnt += 1;
- conflict_list_free -= 1;
- }
-
- /* Leave a 0 at the end. */
- aver (0 < conflict_list_free);
- conflict_list[conflict_list_cnt] = 0;
- conflict_list_cnt += 1;
- conflict_list_free -= 1;
- }
-}
-
-
-/*------------------------------------------------------------------.
-| Decide what to do for each type of token if seen as the |
-| lookahead in specified state. The value returned is used as the |
-| default action (yydefact) for the state. In addition, ACTROW is |
-| filled with what to do for each kind of token, index by symbol |
-| number, with zero meaning do the default action. The value |
-| ACTION_NUMBER_MINIMUM, a very negative number, means this |
-| situation is an error. The parser recognizes this value |
-| specially. |
-| |
-| This is where conflicts are resolved. The loop over lookahead |
-| rules considered lower-numbered rules last, and the last rule |
-| considered that likes a token gets to handle it. |
-| |
-| For GLR parsers, also sets CONFLROW[SYM] to an index into |
-| CONFLICT_LIST iff there is an unresolved conflict (s/r or r/r) |
-| with symbol SYM. The default reduction is not used for a symbol |
-| that has any such conflicts. |
-`------------------------------------------------------------------*/
-
-static rule *
-action_row (state *s)
-{
- int i;
- rule *default_reduction = NULL;
- reductions *reds = s->reductions;
- transitions *trans = s->transitions;
- errs *errp = s->errs;
- /* Set to nonzero to inhibit having any default reduction. */
- bool nodefault = false;
- bool conflicted = false;
-
- for (i = 0; i < ntokens; i++)
- actrow[i] = conflrow[i] = 0;
-
- if (reds->lookahead_tokens)
- {
- int j;
- bitset_iterator biter;
- /* loop over all the rules available here which require
- lookahead (in reverse order to give precedence to the first
- rule) */
- for (i = reds->num - 1; i >= 0; --i)
- /* and find each token which the rule finds acceptable
- to come next */
- BITSET_FOR_EACH (biter, reds->lookahead_tokens[i], j, 0)
- {
- /* and record this rule as the rule to use if that
- token follows. */
- if (actrow[j] != 0)
- {
- conflicted = true;
- conflrow[j] = 1;
- }
- actrow[j] = rule_number_as_item_number (reds->rules[i]->number);
- }
- }
-
- /* Now see which tokens are allowed for shifts in this state. For
- them, record the shift as the thing to do. So shift is preferred
- to reduce. */
- FOR_EACH_SHIFT (trans, i)
- {
- symbol_number sym = TRANSITION_SYMBOL (trans, i);
- state *shift_state = trans->states[i];
-
- if (actrow[sym] != 0)
- {
- conflicted = true;
- conflrow[sym] = 1;
- }
- actrow[sym] = state_number_as_int (shift_state->number);
-
- /* Do not use any default reduction if there is a shift for
- error */
- if (sym == errtoken->number)
- nodefault = true;
- }
-
- /* See which tokens are an explicit error in this state (due to
- %nonassoc). For them, record ACTION_NUMBER_MINIMUM as the
- action. */
- for (i = 0; i < errp->num; i++)
- {
- symbol *sym = errp->symbols[i];
- actrow[sym->number] = ACTION_NUMBER_MINIMUM;
- }
-
- /* Turn off default reductions where requested by the user. See
- state_lookahead_tokens_count in lalr.c to understand when states are
- labeled as consistent. */
- {
- char *default_reductions =
- muscle_percent_define_get ("lr.default-reduction");
- if (STRNEQ (default_reductions, "most") && !s->consistent)
- nodefault = true;
- free (default_reductions);
- }
-
- /* Now find the most common reduction and make it the default action
- for this state. */
-
- if (reds->num >= 1 && !nodefault)
- {
- if (s->consistent)
- default_reduction = reds->rules[0];
- else
- {
- int max = 0;
- for (i = 0; i < reds->num; i++)
- {
- int count = 0;
- rule *r = reds->rules[i];
- symbol_number j;
-
- for (j = 0; j < ntokens; j++)
- if (actrow[j] == rule_number_as_item_number (r->number))
- count++;
-
- if (count > max)
- {
- max = count;
- default_reduction = r;
- }
- }
-
- /* GLR parsers need space for conflict lists, so we can't
- default conflicted entries. For non-conflicted entries
- or as long as we are not building a GLR parser,
- actions that match the default are replaced with zero,
- which means "use the default". */
-
- if (max > 0)
- {
- int j;
- for (j = 0; j < ntokens; j++)
- if (actrow[j]
- == rule_number_as_item_number (default_reduction->number)
- && ! (nondeterministic_parser && conflrow[j]))
- actrow[j] = 0;
- }
- }
- }
-
- /* If have no default reduction, the default is an error.
- So replace any action which says "error" with "use default". */
-
- if (!default_reduction)
- for (i = 0; i < ntokens; i++)
- if (actrow[i] == ACTION_NUMBER_MINIMUM)
- actrow[i] = 0;
-
- if (conflicted)
- conflict_row (s);
-
- return default_reduction;
-}
-
-
-/*----------------------------------------.
-| Set FROMS, TOS, TALLY and WIDTH for S. |
-`----------------------------------------*/
-
-static void
-save_row (state_number s)
-{
- symbol_number i;
-
- /* Number of non default actions in S. */
- size_t count = 0;
- for (i = 0; i < ntokens; i++)
- if (actrow[i] != 0)
- count++;
-
- if (count)
- {
- /* Allocate non defaulted actions. */
- base_number *sp1 = froms[s] = xnmalloc (count, sizeof *sp1);
- base_number *sp2 = tos[s] = xnmalloc (count, sizeof *sp2);
- unsigned int *sp3 = conflict_tos[s] =
- nondeterministic_parser ? xnmalloc (count, sizeof *sp3) : NULL;
-
- /* Store non defaulted actions. */
- for (i = 0; i < ntokens; i++)
- if (actrow[i] != 0)
- {
- *sp1++ = i;
- *sp2++ = actrow[i];
- if (nondeterministic_parser)
- *sp3++ = conflrow[i];
- }
-
- tally[s] = count;
- width[s] = sp1[-1] - froms[s][0] + 1;
- }
-}
-
-
-/*------------------------------------------------------------------.
-| Figure out the actions for the specified state, indexed by |
-| lookahead token type. |
-| |
-| The YYDEFACT table is output now. The detailed info is saved for |
-| putting into YYTABLE later. |
-`------------------------------------------------------------------*/
-
-static void
-token_actions (void)
-{
- int nconflict = nondeterministic_parser ? conflicts_total_count () : 0;
-
- yydefact = xnmalloc (nstates, sizeof *yydefact);
-
- actrow = xnmalloc (ntokens, sizeof *actrow);
- conflrow = xnmalloc (ntokens, sizeof *conflrow);
-
- conflict_list = xnmalloc (1 + 2 * nconflict, sizeof *conflict_list);
- conflict_list_free = 2 * nconflict;
- conflict_list_cnt = 1;
-
- /* Find the rules which are reduced. */
- if (!nondeterministic_parser)
- {
- rule_number r;
- for (r = 0; r < nrules; ++r)
- rules[r].useful = false;
- }
-
- {
- state_number i;
- for (i = 0; i < nstates; ++i)
- {
- rule *default_reduction = action_row (states[i]);
- yydefact[i] = default_reduction ? default_reduction->number + 1 : 0;
- save_row (i);
-
- /* Now that the parser was computed, we can find which rules are
- really reduced, and which are not because of SR or RR
- conflicts. */
- if (!nondeterministic_parser)
- {
- symbol_number j;
- for (j = 0; j < ntokens; ++j)
- if (actrow[j] < 0 && actrow[j] != ACTION_NUMBER_MINIMUM)
- rules[item_number_as_rule_number (actrow[j])].useful = true;
- if (yydefact[i])
- rules[yydefact[i] - 1].useful = true;
- }
- }
- }
- free (actrow);
- free (conflrow);
-}
-
-
-/*------------------------------------------------------------------.
-| Compute FROMS[VECTOR], TOS[VECTOR], TALLY[VECTOR], WIDTH[VECTOR], |
-| i.e., the information related to non defaulted GOTO on the nterm |
-| SYM. |
-| |
-| DEFAULT_STATE is the principal destination on SYM, i.e., the |
-| default GOTO destination on SYM. |
-`------------------------------------------------------------------*/
-
-static void
-save_column (symbol_number sym, state_number default_state)
-{
- goto_number i;
- goto_number begin = goto_map[sym - ntokens];
- goto_number end = goto_map[sym - ntokens + 1];
-
- /* Number of non default GOTO. */
- size_t count = 0;
- for (i = begin; i < end; i++)
- if (to_state[i] != default_state)
- count++;
-
- if (count)
- {
- /* Allocate room for non defaulted gotos. */
- vector_number symno = symbol_number_to_vector_number (sym);
- base_number *sp1 = froms[symno] = xnmalloc (count, sizeof *sp1);
- base_number *sp2 = tos[symno] = xnmalloc (count, sizeof *sp2);
-
- /* Store the state numbers of the non defaulted gotos. */
- for (i = begin; i < end; i++)
- if (to_state[i] != default_state)
- {
- *sp1++ = from_state[i];
- *sp2++ = to_state[i];
- }
-
- tally[symno] = count;
- width[symno] = sp1[-1] - froms[symno][0] + 1;
- }
-}
-
-
-/*----------------------------------------------------------------.
-| The default state for SYM: the state which is 'the' most common |
-| GOTO destination on SYM (an nterm). |
-`----------------------------------------------------------------*/
-
-static state_number
-default_goto (symbol_number sym, size_t state_count[])
-{
- goto_number begin = goto_map[sym - ntokens];
- goto_number end = goto_map[sym - ntokens + 1];
- state_number res = -1;
-
- if (begin != end)
- {
- size_t max = 0;
- goto_number i;
- state_number s;
-
- for (s = 0; s < nstates; s++)
- state_count[s] = 0;
-
- for (i = begin; i < end; i++)
- state_count[to_state[i]]++;
-
- for (s = 0; s < nstates; s++)
- if (max < state_count[s])
- {
- max = state_count[s];
- res = s;
- }
- }
- return res;
-}
-
-
-/*-------------------------------------------------------------------.
-| Figure out what to do after reducing with each rule, depending on |
-| the saved state from before the beginning of parsing the data that |
-| matched this rule. |
-| |
-| The YYDEFGOTO table is output now. The detailed info is saved for |
-| putting into YYTABLE later. |
-`-------------------------------------------------------------------*/
-
-static void
-goto_actions (void)
-{
- symbol_number i;
- size_t *state_count = xnmalloc (nstates, sizeof *state_count);
- yydefgoto = xnmalloc (nvars, sizeof *yydefgoto);
-
- /* For a given nterm I, STATE_COUNT[S] is the number of times there
- is a GOTO to S on I. */
- for (i = ntokens; i < nsyms; ++i)
- {
- state_number default_state = default_goto (i, state_count);
- save_column (i, default_state);
- yydefgoto[i - ntokens] = default_state;
- }
- free (state_count);
-}
-
-
-/*------------------------------------------------------------------.
-| Compute ORDER, a reordering of vectors, in order to decide how to |
-| pack the actions and gotos information into yytable. |
-`------------------------------------------------------------------*/
-
-static void
-sort_actions (void)
-{
- int i;
-
- nentries = 0;
-
- for (i = 0; i < nvectors; i++)
- if (0 < tally[i])
- {
- int k;
- size_t t = tally[i];
- int w = width[i];
- int j = nentries - 1;
-
- while (0 <= j && width[order[j]] < w)
- j--;
-
- while (0 <= j && width[order[j]] == w && tally[order[j]] < t)
- j--;
-
- for (k = nentries - 1; k > j; k--)
- order[k + 1] = order[k];
-
- order[j + 1] = i;
- nentries++;
- }
-}
-
-
-/* If VECTOR is a state whose actions (reflected by FROMS, TOS, TALLY
- and WIDTH of VECTOR) are common to a previous state, return this
- state number.
-
- In any other case, return -1. */
-
-static state_number
-matching_state (vector_number vector)
-{
- vector_number i = order[vector];
- /* If VECTOR is a nterm, return -1. */
- if (i < nstates)
- {
- size_t t = tally[i];
- int w = width[i];
- int prev;
-
- /* If VECTOR has GLR conflicts, return -1 */
- if (conflict_tos[i] != NULL)
- {
- int j;
- for (j = 0; j < t; j += 1)
- if (conflict_tos[i][j] != 0)
- return -1;
- }
-
- for (prev = vector - 1; 0 <= prev; prev--)
- {
- vector_number j = order[prev];
- /* Given how ORDER was computed, if the WIDTH or TALLY is
- different, there cannot be a matching state. */
- if (width[j] != w || tally[j] != t)
- return -1;
- else
- {
- bool match = true;
- int k;
- for (k = 0; match && k < t; k++)
- if (tos[j][k] != tos[i][k]
- || froms[j][k] != froms[i][k]
- || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0))
- match = false;
- if (match)
- return j;
- }
- }
- }
- return -1;
-}
-
-
-static base_number
-pack_vector (vector_number vector)
-{
- base_number res;
- vector_number i = order[vector];
- size_t t = tally[i];
- base_number *from = froms[i];
- base_number *to = tos[i];
- unsigned int *conflict_to = conflict_tos[i];
-
- aver (t != 0);
-
- for (res = lowzero - from[0]; ; res++)
- {
- bool ok = true;
- aver (res < table_size);
- {
- int k;
- for (k = 0; ok && k < t; k++)
- {
- int loc = res + state_number_as_int (from[k]);
- if (table_size <= loc)
- table_grow (loc);
-
- if (table[loc] != 0)
- ok = false;
- }
-
- if (ok)
- for (k = 0; k < vector; k++)
- if (pos[k] == res)
- ok = false;
- }
-
- if (ok)
- {
- int loc;
- int k;
- for (k = 0; k < t; k++)
- {
- loc = res + state_number_as_int (from[k]);
- table[loc] = to[k];
- if (nondeterministic_parser && conflict_to != NULL)
- conflict_table[loc] = conflict_to[k];
- check[loc] = from[k];
- }
-
- while (table[lowzero] != 0)
- lowzero++;
-
- if (high < loc)
- high = loc;
-
- aver (BASE_MINIMUM <= res && res <= BASE_MAXIMUM);
- return res;
- }
- }
-}
-
-
-/*-------------------------------------------------------------.
-| Remap the negative infinite in TAB from NINF to the greatest |
-| possible smallest value. Return it. |
-| |
-| In most case this allows us to use shorts instead of ints in |
-| parsers. |
-`-------------------------------------------------------------*/
-
-static base_number
-table_ninf_remap (base_number tab[], int size, base_number ninf)
-{
- base_number res = 0;
- int i;
-
- for (i = 0; i < size; i++)
- if (tab[i] < res && tab[i] != ninf)
- res = tab[i];
-
- --res;
-
- for (i = 0; i < size; i++)
- if (tab[i] == ninf)
- tab[i] = res;
-
- return res;
-}
-
-static void
-pack_table (void)
-{
- int i;
-
- base = xnmalloc (nvectors, sizeof *base);
- pos = xnmalloc (nentries, sizeof *pos);
- table = xcalloc (table_size, sizeof *table);
- conflict_table = xcalloc (table_size, sizeof *conflict_table);
- check = xnmalloc (table_size, sizeof *check);
-
- lowzero = 0;
- high = 0;
-
- for (i = 0; i < nvectors; i++)
- base[i] = BASE_MINIMUM;
-
- for (i = 0; i < table_size; i++)
- check[i] = -1;
-
- for (i = 0; i < nentries; i++)
- {
- state_number s = matching_state (i);
- base_number place;
-
- if (s < 0)
- /* A new set of state actions, or a nonterminal. */
- place = pack_vector (i);
- else
- /* Action of I were already coded for S. */
- place = base[s];
-
- pos[i] = place;
- base[order[i]] = place;
- }
-
- /* Use the greatest possible negative infinites. */
- base_ninf = table_ninf_remap (base, nvectors, BASE_MINIMUM);
- table_ninf = table_ninf_remap (table, high + 1, ACTION_NUMBER_MINIMUM);
-
- free (pos);
-}
-
-
-
-/*-----------------------------------------------------------------.
-| Compute and output yydefact, yydefgoto, yypact, yypgoto, yytable |
-| and yycheck. |
-`-----------------------------------------------------------------*/
-
-void
-tables_generate (void)
-{
- int i;
-
- /* This is a poor way to make sure the sizes are properly
- correlated. In particular the signedness is not taken into
- account. But it's not useless. */
- verify (sizeof nstates <= sizeof nvectors
- && sizeof nvars <= sizeof nvectors);
-
- nvectors = state_number_as_int (nstates) + nvars;
-
- froms = xcalloc (nvectors, sizeof *froms);
- tos = xcalloc (nvectors, sizeof *tos);
- conflict_tos = xcalloc (nvectors, sizeof *conflict_tos);
- tally = xcalloc (nvectors, sizeof *tally);
- width = xnmalloc (nvectors, sizeof *width);
-
- token_actions ();
-
- goto_actions ();
- free (goto_map);
- free (from_state);
- free (to_state);
-
- order = xcalloc (nvectors, sizeof *order);
- sort_actions ();
- pack_table ();
- free (order);
-
- free (tally);
- free (width);
-
- for (i = 0; i < nvectors; i++)
- {
- free (froms[i]);
- free (tos[i]);
- free (conflict_tos[i]);
- }
-
- free (froms);
- free (tos);
- free (conflict_tos);
-}
-
-
-/*-------------------------.
-| Free the parser tables. |
-`-------------------------*/
-
-void
-tables_free (void)
-{
- free (base);
- free (conflict_table);
- free (conflict_list);
- free (table);
- free (check);
- free (yydefgoto);
- free (yydefact);
-}
+/* Output the generated parsing program for Bison.
+
+ Copyright (C) 1984, 1986, 1989, 1992, 2000-2006, 2009-2013 Free
+ Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <bitsetv.h>
+
+#include "complain.h"
+#include "conflicts.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "lalr.h"
+#include "muscle-tab.h"
+#include "reader.h"
+#include "symtab.h"
+#include "tables.h"
+
+/* Several tables are indexed both by state and nonterminal numbers.
+ We call such an index a 'vector'; i.e., a vector is either a state
+ or a nonterminal number.
+
+ Of course vector_number_t ought to be wide enough to contain
+ state_number and symbol_number. */
+typedef int vector_number;
+
+#if 0 /* Not currently used. */
+static inline vector_number
+state_number_to_vector_number (state_number s)
+{
+ return s;
+}
+#endif
+
+static inline vector_number
+symbol_number_to_vector_number (symbol_number sym)
+{
+ return state_number_as_int (nstates) + sym - ntokens;
+}
+
+int nvectors;
+
+
+/* FROMS and TOS are indexed by vector_number.
+
+ If VECTOR is a nonterminal, (FROMS[VECTOR], TOS[VECTOR]) form an
+ array of state numbers of the non defaulted GOTO on VECTOR.
+
+ If VECTOR is a state, TOS[VECTOR] is the array of actions to do on
+ the (array of) symbols FROMS[VECTOR].
+
+ In both cases, TALLY[VECTOR] is the size of the arrays
+ FROMS[VECTOR], TOS[VECTOR]; and WIDTH[VECTOR] =
+ (FROMS[VECTOR][SIZE] - FROMS[VECTOR][0] + 1) where SIZE =
+ TALLY[VECTOR].
+
+ FROMS therefore contains symbol_number and action_number,
+ TOS state_number and action_number,
+ TALLY sizes,
+ WIDTH differences of FROMS.
+
+ Let base_number be the type of FROMS, TOS, and WIDTH. */
+#define BASE_MAXIMUM INT_MAX
+#define BASE_MINIMUM INT_MIN
+
+static base_number **froms;
+static base_number **tos;
+static unsigned int **conflict_tos;
+static size_t *tally;
+static base_number *width;
+
+
+/* For a given state, N = ACTROW[SYMBOL]:
+
+ If N = 0, stands for 'run the default action'.
+ If N = MIN, stands for 'raise a syntax error'.
+ If N > 0, stands for 'shift SYMBOL and go to n'.
+ If N < 0, stands for 'reduce -N'. */
+typedef int action_number;
+#define ACTION_NUMBER_MINIMUM INT_MIN
+
+static action_number *actrow;
+
+/* FROMS and TOS are reordered to be compressed. ORDER[VECTOR] is the
+ new vector number of VECTOR. We skip 'empty' vectors (i.e.,
+ TALLY[VECTOR] = 0), and call these 'entries'. */
+static vector_number *order;
+static int nentries;
+
+base_number *base = NULL;
+/* A distinguished value of BASE, negative infinite. During the
+ computation equals to BASE_MINIMUM, later mapped to BASE_NINF to
+ keep parser tables small. */
+base_number base_ninf = 0;
+static base_number *pos = NULL;
+
+static unsigned int *conflrow;
+unsigned int *conflict_table;
+unsigned int *conflict_list;
+int conflict_list_cnt;
+static int conflict_list_free;
+
+/* TABLE_SIZE is the allocated size of both TABLE and CHECK. We start
+ with more or less the original hard-coded value (which was
+ SHRT_MAX). */
+static int table_size = 32768;
+base_number *table;
+base_number *check;
+/* The value used in TABLE to denote explicit syntax errors
+ (%nonassoc), a negative infinite. First defaults to ACTION_NUMBER_MINIMUM,
+ but in order to keep small tables, renumbered as TABLE_ERROR, which
+ is the smallest (non error) value minus 1. */
+base_number table_ninf = 0;
+static int lowzero;
+int high;
+
+state_number *yydefgoto;
+rule_number *yydefact;
+
+/*-------------------------------------------------------------------.
+| If TABLE, CONFLICT_TABLE, and CHECK are too small to be addressed |
+| at DESIRED, grow them. TABLE[DESIRED] can be used, so the desired |
+| size is at least DESIRED + 1. |
+`-------------------------------------------------------------------*/
+
+static void
+table_grow (int desired)
+{
+ int old_size = table_size;
+
+ while (table_size <= desired)
+ table_size *= 2;
+
+ if (trace_flag & trace_resource)
+ fprintf (stderr, "growing table and check from: %d to %d\n",
+ old_size, table_size);
+
+ table = xnrealloc (table, table_size, sizeof *table);
+ conflict_table = xnrealloc (conflict_table, table_size,
+ sizeof *conflict_table);
+ check = xnrealloc (check, table_size, sizeof *check);
+
+ for (/* Nothing. */; old_size < table_size; ++old_size)
+ {
+ table[old_size] = 0;
+ conflict_table[old_size] = 0;
+ check[old_size] = -1;
+ }
+}
+
+
+
+
+/*-------------------------------------------------------------------.
+| For GLR parsers, for each conflicted token in S, as indicated |
+| by non-zero entries in CONFLROW, create a list of possible |
+| reductions that are alternatives to the shift or reduction |
+| currently recorded for that token in S. Store the alternative |
+| reductions followed by a 0 in CONFLICT_LIST, updating |
+| CONFLICT_LIST_CNT, and storing an index to the start of the list |
+| back into CONFLROW. |
+`-------------------------------------------------------------------*/
+
+static void
+conflict_row (state *s)
+{
+ int i, j;
+ reductions *reds = s->reductions;
+
+ if (!nondeterministic_parser)
+ return;
+
+ for (j = 0; j < ntokens; j += 1)
+ if (conflrow[j])
+ {
+ conflrow[j] = conflict_list_cnt;
+
+ /* Find all reductions for token J, and record all that do not
+ match ACTROW[J]. */
+ for (i = 0; i < reds->num; i += 1)
+ if (bitset_test (reds->lookahead_tokens[i], j)
+ && (actrow[j]
+ != rule_number_as_item_number (reds->rules[i]->number)))
+ {
+ aver (0 < conflict_list_free);
+ conflict_list[conflict_list_cnt] = reds->rules[i]->number + 1;
+ conflict_list_cnt += 1;
+ conflict_list_free -= 1;
+ }
+
+ /* Leave a 0 at the end. */
+ aver (0 < conflict_list_free);
+ conflict_list[conflict_list_cnt] = 0;
+ conflict_list_cnt += 1;
+ conflict_list_free -= 1;
+ }
+}
+
+
+/*------------------------------------------------------------------.
+| Decide what to do for each type of token if seen as the |
+| lookahead in specified state. The value returned is used as the |
+| default action (yydefact) for the state. In addition, ACTROW is |
+| filled with what to do for each kind of token, index by symbol |
+| number, with zero meaning do the default action. The value |
+| ACTION_NUMBER_MINIMUM, a very negative number, means this |
+| situation is an error. The parser recognizes this value |
+| specially. |
+| |
+| This is where conflicts are resolved. The loop over lookahead |
+| rules considered lower-numbered rules last, and the last rule |
+| considered that likes a token gets to handle it. |
+| |
+| For GLR parsers, also sets CONFLROW[SYM] to an index into |
+| CONFLICT_LIST iff there is an unresolved conflict (s/r or r/r) |
+| with symbol SYM. The default reduction is not used for a symbol |
+| that has any such conflicts. |
+`------------------------------------------------------------------*/
+
+static rule *
+action_row (state *s)
+{
+ int i;
+ rule *default_reduction = NULL;
+ reductions *reds = s->reductions;
+ transitions *trans = s->transitions;
+ errs *errp = s->errs;
+ /* Set to nonzero to inhibit having any default reduction. */
+ bool nodefault = false;
+ bool conflicted = false;
+
+ for (i = 0; i < ntokens; i++)
+ actrow[i] = conflrow[i] = 0;
+
+ if (reds->lookahead_tokens)
+ {
+ int j;
+ bitset_iterator biter;
+ /* loop over all the rules available here which require
+ lookahead (in reverse order to give precedence to the first
+ rule) */
+ for (i = reds->num - 1; i >= 0; --i)
+ /* and find each token which the rule finds acceptable
+ to come next */
+ BITSET_FOR_EACH (biter, reds->lookahead_tokens[i], j, 0)
+ {
+ /* and record this rule as the rule to use if that
+ token follows. */
+ if (actrow[j] != 0)
+ {
+ conflicted = true;
+ conflrow[j] = 1;
+ }
+ actrow[j] = rule_number_as_item_number (reds->rules[i]->number);
+ }
+ }
+
+ /* Now see which tokens are allowed for shifts in this state. For
+ them, record the shift as the thing to do. So shift is preferred
+ to reduce. */
+ FOR_EACH_SHIFT (trans, i)
+ {
+ symbol_number sym = TRANSITION_SYMBOL (trans, i);
+ state *shift_state = trans->states[i];
+
+ if (actrow[sym] != 0)
+ {
+ conflicted = true;
+ conflrow[sym] = 1;
+ }
+ actrow[sym] = state_number_as_int (shift_state->number);
+
+ /* Do not use any default reduction if there is a shift for
+ error */
+ if (sym == errtoken->number)
+ nodefault = true;
+ }
+
+ /* See which tokens are an explicit error in this state (due to
+ %nonassoc). For them, record ACTION_NUMBER_MINIMUM as the
+ action. */
+ for (i = 0; i < errp->num; i++)
+ {
+ symbol *sym = errp->symbols[i];
+ actrow[sym->number] = ACTION_NUMBER_MINIMUM;
+ }
+
+ /* Turn off default reductions where requested by the user. See
+ state_lookahead_tokens_count in lalr.c to understand when states are
+ labeled as consistent. */
+ {
+ char *default_reductions =
+ muscle_percent_define_get ("lr.default-reduction");
+ if (STRNEQ (default_reductions, "most") && !s->consistent)
+ nodefault = true;
+ free (default_reductions);
+ }
+
+ /* Now find the most common reduction and make it the default action
+ for this state. */
+
+ if (reds->num >= 1 && !nodefault)
+ {
+ if (s->consistent)
+ default_reduction = reds->rules[0];
+ else
+ {
+ int max = 0;
+ for (i = 0; i < reds->num; i++)
+ {
+ int count = 0;
+ rule *r = reds->rules[i];
+ symbol_number j;
+
+ for (j = 0; j < ntokens; j++)
+ if (actrow[j] == rule_number_as_item_number (r->number))
+ count++;
+
+ if (count > max)
+ {
+ max = count;
+ default_reduction = r;
+ }
+ }
+
+ /* GLR parsers need space for conflict lists, so we can't
+ default conflicted entries. For non-conflicted entries
+ or as long as we are not building a GLR parser,
+ actions that match the default are replaced with zero,
+ which means "use the default". */
+
+ if (max > 0)
+ {
+ int j;
+ for (j = 0; j < ntokens; j++)
+ if (actrow[j]
+ == rule_number_as_item_number (default_reduction->number)
+ && ! (nondeterministic_parser && conflrow[j]))
+ actrow[j] = 0;
+ }
+ }
+ }
+
+ /* If have no default reduction, the default is an error.
+ So replace any action which says "error" with "use default". */
+
+ if (!default_reduction)
+ for (i = 0; i < ntokens; i++)
+ if (actrow[i] == ACTION_NUMBER_MINIMUM)
+ actrow[i] = 0;
+
+ if (conflicted)
+ conflict_row (s);
+
+ return default_reduction;
+}
+
+
+/*----------------------------------------.
+| Set FROMS, TOS, TALLY and WIDTH for S. |
+`----------------------------------------*/
+
+static void
+save_row (state_number s)
+{
+ symbol_number i;
+
+ /* Number of non default actions in S. */
+ size_t count = 0;
+ for (i = 0; i < ntokens; i++)
+ if (actrow[i] != 0)
+ count++;
+
+ if (count)
+ {
+ /* Allocate non defaulted actions. */
+ base_number *sp1 = froms[s] = xnmalloc (count, sizeof *sp1);
+ base_number *sp2 = tos[s] = xnmalloc (count, sizeof *sp2);
+ unsigned int *sp3 = conflict_tos[s] =
+ nondeterministic_parser ? xnmalloc (count, sizeof *sp3) : NULL;
+
+ /* Store non defaulted actions. */
+ for (i = 0; i < ntokens; i++)
+ if (actrow[i] != 0)
+ {
+ *sp1++ = i;
+ *sp2++ = actrow[i];
+ if (nondeterministic_parser)
+ *sp3++ = conflrow[i];
+ }
+
+ tally[s] = count;
+ width[s] = sp1[-1] - froms[s][0] + 1;
+ }
+}
+
+
+/*------------------------------------------------------------------.
+| Figure out the actions for the specified state, indexed by |
+| lookahead token type. |
+| |
+| The YYDEFACT table is output now. The detailed info is saved for |
+| putting into YYTABLE later. |
+`------------------------------------------------------------------*/
+
+static void
+token_actions (void)
+{
+ int nconflict = nondeterministic_parser ? conflicts_total_count () : 0;
+
+ yydefact = xnmalloc (nstates, sizeof *yydefact);
+
+ actrow = xnmalloc (ntokens, sizeof *actrow);
+ conflrow = xnmalloc (ntokens, sizeof *conflrow);
+
+ conflict_list = xnmalloc (1 + 2 * nconflict, sizeof *conflict_list);
+ conflict_list_free = 2 * nconflict;
+ conflict_list_cnt = 1;
+
+ /* Find the rules which are reduced. */
+ if (!nondeterministic_parser)
+ {
+ rule_number r;
+ for (r = 0; r < nrules; ++r)
+ rules[r].useful = false;
+ }
+
+ {
+ state_number i;
+ for (i = 0; i < nstates; ++i)
+ {
+ rule *default_reduction = action_row (states[i]);
+ yydefact[i] = default_reduction ? default_reduction->number + 1 : 0;
+ save_row (i);
+
+ /* Now that the parser was computed, we can find which rules are
+ really reduced, and which are not because of SR or RR
+ conflicts. */
+ if (!nondeterministic_parser)
+ {
+ symbol_number j;
+ for (j = 0; j < ntokens; ++j)
+ if (actrow[j] < 0 && actrow[j] != ACTION_NUMBER_MINIMUM)
+ rules[item_number_as_rule_number (actrow[j])].useful = true;
+ if (yydefact[i])
+ rules[yydefact[i] - 1].useful = true;
+ }
+ }
+ }
+ free (actrow);
+ free (conflrow);
+}
+
+
+/*------------------------------------------------------------------.
+| Compute FROMS[VECTOR], TOS[VECTOR], TALLY[VECTOR], WIDTH[VECTOR], |
+| i.e., the information related to non defaulted GOTO on the nterm |
+| SYM. |
+| |
+| DEFAULT_STATE is the principal destination on SYM, i.e., the |
+| default GOTO destination on SYM. |
+`------------------------------------------------------------------*/
+
+static void
+save_column (symbol_number sym, state_number default_state)
+{
+ goto_number i;
+ goto_number begin = goto_map[sym - ntokens];
+ goto_number end = goto_map[sym - ntokens + 1];
+
+ /* Number of non default GOTO. */
+ size_t count = 0;
+ for (i = begin; i < end; i++)
+ if (to_state[i] != default_state)
+ count++;
+
+ if (count)
+ {
+ /* Allocate room for non defaulted gotos. */
+ vector_number symno = symbol_number_to_vector_number (sym);
+ base_number *sp1 = froms[symno] = xnmalloc (count, sizeof *sp1);
+ base_number *sp2 = tos[symno] = xnmalloc (count, sizeof *sp2);
+
+ /* Store the state numbers of the non defaulted gotos. */
+ for (i = begin; i < end; i++)
+ if (to_state[i] != default_state)
+ {
+ *sp1++ = from_state[i];
+ *sp2++ = to_state[i];
+ }
+
+ tally[symno] = count;
+ width[symno] = sp1[-1] - froms[symno][0] + 1;
+ }
+}
+
+
+/*----------------------------------------------------------------.
+| The default state for SYM: the state which is 'the' most common |
+| GOTO destination on SYM (an nterm). |
+`----------------------------------------------------------------*/
+
+static state_number
+default_goto (symbol_number sym, size_t state_count[])
+{
+ goto_number begin = goto_map[sym - ntokens];
+ goto_number end = goto_map[sym - ntokens + 1];
+ state_number res = -1;
+
+ if (begin != end)
+ {
+ size_t max = 0;
+ goto_number i;
+ state_number s;
+
+ for (s = 0; s < nstates; s++)
+ state_count[s] = 0;
+
+ for (i = begin; i < end; i++)
+ state_count[to_state[i]]++;
+
+ for (s = 0; s < nstates; s++)
+ if (max < state_count[s])
+ {
+ max = state_count[s];
+ res = s;
+ }
+ }
+ return res;
+}
+
+
+/*-------------------------------------------------------------------.
+| Figure out what to do after reducing with each rule, depending on |
+| the saved state from before the beginning of parsing the data that |
+| matched this rule. |
+| |
+| The YYDEFGOTO table is output now. The detailed info is saved for |
+| putting into YYTABLE later. |
+`-------------------------------------------------------------------*/
+
+static void
+goto_actions (void)
+{
+ symbol_number i;
+ size_t *state_count = xnmalloc (nstates, sizeof *state_count);
+ yydefgoto = xnmalloc (nvars, sizeof *yydefgoto);
+
+ /* For a given nterm I, STATE_COUNT[S] is the number of times there
+ is a GOTO to S on I. */
+ for (i = ntokens; i < nsyms; ++i)
+ {
+ state_number default_state = default_goto (i, state_count);
+ save_column (i, default_state);
+ yydefgoto[i - ntokens] = default_state;
+ }
+ free (state_count);
+}
+
+
+/*------------------------------------------------------------------.
+| Compute ORDER, a reordering of vectors, in order to decide how to |
+| pack the actions and gotos information into yytable. |
+`------------------------------------------------------------------*/
+
+static void
+sort_actions (void)
+{
+ int i;
+
+ nentries = 0;
+
+ for (i = 0; i < nvectors; i++)
+ if (0 < tally[i])
+ {
+ int k;
+ size_t t = tally[i];
+ int w = width[i];
+ int j = nentries - 1;
+
+ while (0 <= j && width[order[j]] < w)
+ j--;
+
+ while (0 <= j && width[order[j]] == w && tally[order[j]] < t)
+ j--;
+
+ for (k = nentries - 1; k > j; k--)
+ order[k + 1] = order[k];
+
+ order[j + 1] = i;
+ nentries++;
+ }
+}
+
+
+/* If VECTOR is a state whose actions (reflected by FROMS, TOS, TALLY
+ and WIDTH of VECTOR) are common to a previous state, return this
+ state number.
+
+ In any other case, return -1. */
+
+static state_number
+matching_state (vector_number vector)
+{
+ vector_number i = order[vector];
+ /* If VECTOR is a nterm, return -1. */
+ if (i < nstates)
+ {
+ size_t t = tally[i];
+ int w = width[i];
+ int prev;
+
+ /* If VECTOR has GLR conflicts, return -1 */
+ if (conflict_tos[i] != NULL)
+ {
+ int j;
+ for (j = 0; j < t; j += 1)
+ if (conflict_tos[i][j] != 0)
+ return -1;
+ }
+
+ for (prev = vector - 1; 0 <= prev; prev--)
+ {
+ vector_number j = order[prev];
+ /* Given how ORDER was computed, if the WIDTH or TALLY is
+ different, there cannot be a matching state. */
+ if (width[j] != w || tally[j] != t)
+ return -1;
+ else
+ {
+ bool match = true;
+ int k;
+ for (k = 0; match && k < t; k++)
+ if (tos[j][k] != tos[i][k]
+ || froms[j][k] != froms[i][k]
+ || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0))
+ match = false;
+ if (match)
+ return j;
+ }
+ }
+ }
+ return -1;
+}
+
+
+static base_number
+pack_vector (vector_number vector)
+{
+ base_number res;
+ vector_number i = order[vector];
+ size_t t = tally[i];
+ base_number *from = froms[i];
+ base_number *to = tos[i];
+ unsigned int *conflict_to = conflict_tos[i];
+
+ aver (t != 0);
+
+ for (res = lowzero - from[0]; ; res++)
+ {
+ bool ok = true;
+ aver (res < table_size);
+ {
+ int k;
+ for (k = 0; ok && k < t; k++)
+ {
+ int loc = res + state_number_as_int (from[k]);
+ if (table_size <= loc)
+ table_grow (loc);
+
+ if (table[loc] != 0)
+ ok = false;
+ }
+
+ if (ok)
+ for (k = 0; k < vector; k++)
+ if (pos[k] == res)
+ ok = false;
+ }
+
+ if (ok)
+ {
+ int loc;
+ int k;
+ for (k = 0; k < t; k++)
+ {
+ loc = res + state_number_as_int (from[k]);
+ table[loc] = to[k];
+ if (nondeterministic_parser && conflict_to != NULL)
+ conflict_table[loc] = conflict_to[k];
+ check[loc] = from[k];
+ }
+
+ while (table[lowzero] != 0)
+ lowzero++;
+
+ if (high < loc)
+ high = loc;
+
+ aver (BASE_MINIMUM <= res && res <= BASE_MAXIMUM);
+ return res;
+ }
+ }
+}
+
+
+/*-------------------------------------------------------------.
+| Remap the negative infinite in TAB from NINF to the greatest |
+| possible smallest value. Return it. |
+| |
+| In most case this allows us to use shorts instead of ints in |
+| parsers. |
+`-------------------------------------------------------------*/
+
+static base_number
+table_ninf_remap (base_number tab[], int size, base_number ninf)
+{
+ base_number res = 0;
+ int i;
+
+ for (i = 0; i < size; i++)
+ if (tab[i] < res && tab[i] != ninf)
+ res = tab[i];
+
+ --res;
+
+ for (i = 0; i < size; i++)
+ if (tab[i] == ninf)
+ tab[i] = res;
+
+ return res;
+}
+
+static void
+pack_table (void)
+{
+ int i;
+
+ base = xnmalloc (nvectors, sizeof *base);
+ pos = xnmalloc (nentries, sizeof *pos);
+ table = xcalloc (table_size, sizeof *table);
+ conflict_table = xcalloc (table_size, sizeof *conflict_table);
+ check = xnmalloc (table_size, sizeof *check);
+
+ lowzero = 0;
+ high = 0;
+
+ for (i = 0; i < nvectors; i++)
+ base[i] = BASE_MINIMUM;
+
+ for (i = 0; i < table_size; i++)
+ check[i] = -1;
+
+ for (i = 0; i < nentries; i++)
+ {
+ state_number s = matching_state (i);
+ base_number place;
+
+ if (s < 0)
+ /* A new set of state actions, or a nonterminal. */
+ place = pack_vector (i);
+ else
+ /* Action of I were already coded for S. */
+ place = base[s];
+
+ pos[i] = place;
+ base[order[i]] = place;
+ }
+
+ /* Use the greatest possible negative infinites. */
+ base_ninf = table_ninf_remap (base, nvectors, BASE_MINIMUM);
+ table_ninf = table_ninf_remap (table, high + 1, ACTION_NUMBER_MINIMUM);
+
+ free (pos);
+}
+
+
+
+/*-----------------------------------------------------------------.
+| Compute and output yydefact, yydefgoto, yypact, yypgoto, yytable |
+| and yycheck. |
+`-----------------------------------------------------------------*/
+
+void
+tables_generate (void)
+{
+ int i;
+
+ /* This is a poor way to make sure the sizes are properly
+ correlated. In particular the signedness is not taken into
+ account. But it's not useless. */
+ verify (sizeof nstates <= sizeof nvectors
+ && sizeof nvars <= sizeof nvectors);
+
+ nvectors = state_number_as_int (nstates) + nvars;
+
+ froms = xcalloc (nvectors, sizeof *froms);
+ tos = xcalloc (nvectors, sizeof *tos);
+ conflict_tos = xcalloc (nvectors, sizeof *conflict_tos);
+ tally = xcalloc (nvectors, sizeof *tally);
+ width = xnmalloc (nvectors, sizeof *width);
+
+ token_actions ();
+
+ goto_actions ();
+ free (goto_map);
+ free (from_state);
+ free (to_state);
+
+ order = xcalloc (nvectors, sizeof *order);
+ sort_actions ();
+ pack_table ();
+ free (order);
+
+ free (tally);
+ free (width);
+
+ for (i = 0; i < nvectors; i++)
+ {
+ free (froms[i]);
+ free (tos[i]);
+ free (conflict_tos[i]);
+ }
+
+ free (froms);
+ free (tos);
+ free (conflict_tos);
+}
+
+
+/*-------------------------.
+| Free the parser tables. |
+`-------------------------*/
+
+void
+tables_free (void)
+{
+ free (base);
+ free (conflict_table);
+ free (conflict_list);
+ free (table);
+ free (check);
+ free (yydefgoto);
+ free (yydefact);
+}
diff --git a/contrib/tools/bison/bison/src/tables.h b/contrib/tools/bison/bison/src/tables.h
index c631584d6e..3cf4a5959a 100644
--- a/contrib/tools/bison/bison/src/tables.h
+++ b/contrib/tools/bison/bison/src/tables.h
@@ -1,141 +1,141 @@
-/* Prepare the LALR and GLR parser tables.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef TABLES_H_
-# define TABLES_H_
-
-# include "state.h"
-
-/* The parser tables consist of these tables.
-
- YYTRANSLATE = vector mapping yylex's token numbers into bison's
- token numbers.
-
- YYTNAME = vector of string-names indexed by bison token number.
-
- YYTOKNUM = vector of yylex token numbers corresponding to entries
- in YYTNAME.
-
- YYRLINE = vector of line-numbers of all rules. For yydebug
- printouts.
-
- YYRHS = vector of items of all rules. This is exactly what RITEMS
- contains. For yydebug and for semantic parser.
-
- YYPRHS[R] = index in YYRHS of first item for rule R.
-
- YYR1[R] = symbol number of symbol that rule R derives.
-
- YYR2[R] = number of symbols composing right hand side of rule R.
-
- YYSTOS[S] = the symbol number of the symbol that leads to state S.
-
- YYFINAL = the state number of the termination state.
-
- YYTABLE = a vector filled with portions for different uses, found
- via YYPACT and YYPGOTO, described below.
-
- YYLAST ( = high) the number of the last element of YYTABLE, i.e.,
- sizeof (YYTABLE) - 1.
-
- YYCHECK = a vector indexed in parallel with YYTABLE. It indicates,
- in a roundabout way, the bounds of the portion you are trying to
- examine.
-
- Suppose that the portion of YYTABLE starts at index P and the index
- to be examined within the portion is I. Then if YYCHECK[P+I] != I,
- I is outside the bounds of what is actually allocated, and the
- default (from YYDEFACT or YYDEFGOTO) should be used. Otherwise,
- YYTABLE[P+I] should be used.
-
- YYDEFACT[S] = default reduction number in state s. Performed when
- YYTABLE doesn't specify something else to do. Zero means the default
- is an error.
-
- YYDEFGOTO[I] = default state to go to after a reduction of a rule
- that generates variable NTOKENS + I, except when YYTABLE specifies
- something else to do.
-
- YYPACT[S] = index in YYTABLE of the portion describing state S.
- The lookahead token's number, I, is used to index that portion of
- YYTABLE to find out what action to perform.
-
- If YYPACT[S] == YYPACT_NINF, if YYPACT[S] + I is outside the bounds
- of YYTABLE (from 0 to YYLAST), or I is outside the bounds for portion
- S (that is, YYCHECK[YYPACT[S] + I] != I), then the default action
- (that is, YYDEFACT[S]) should be used instead of YYTABLE. Otherwise,
- the value YYTABLE[YYPACT[S] + I] should be used even if
- YYPACT[S] < 0.
-
- If the value in YYTABLE is positive, we shift the token and go to
- that state.
-
- If the value is negative, it is minus a rule number to reduce by.
-
- If the value is YYTABLE_NINF, it's a syntax error.
-
- YYPGOTO[I] = the index in YYTABLE of the portion describing what to
- do after reducing a rule that derives variable I + NTOKENS. This
- portion is indexed by the parser state number, S, as of before the
- text for this nonterminal was read.
-
- If YYPGOTO[I] + S is outside the bounds of YYTABLE (from 0 to YYLAST)
- or if S is outside the bounds of the portion for I (that is,
- YYCHECK[YYPGOTO[I] + S] != S), then the default state (that is,
- YYDEFGOTO[I]) should be used instead of YYTABLE. Otherwise,
- YYTABLE[YYPGOTO[I] + S] is the state to go to even if YYPGOTO[I] < 0.
-
- When the above YYPACT, YYPGOTO, and YYCHECK tests determine that a
- value from YYTABLE should be used, that value is never zero, so it is
- useless to check for zero. When those tests indicate that the value
- from YYDEFACT or YYDEFGOTO should be used instead, the value from
- YYTABLE *might* be zero, which, as a consequence of the way in which
- the tables are constructed, also happens to indicate that YYDEFACT or
- YYDEFGOTO should be used. However, the YYTABLE value cannot be
- trusted when the YYDEFACT or YYDEFGOTO value should be used. In
- summary, forget about zero values in YYTABLE.
-*/
-
-extern int nvectors;
-
-typedef int base_number;
-extern base_number *base;
-/* A distinguished value of BASE, negative infinite. During the
- computation equals to BASE_MINIMUM, later mapped to BASE_NINF to
- keep parser tables small. */
-extern base_number base_ninf;
-
-extern unsigned int *conflict_table;
-extern unsigned int *conflict_list;
-extern int conflict_list_cnt;
-
-extern base_number *table;
-extern base_number *check;
-/* The value used in TABLE to denote explicit syntax errors
- (%nonassoc), a negative infinite. */
-extern base_number table_ninf;
-
-extern state_number *yydefgoto;
-extern rule_number *yydefact;
-extern int high;
-
-void tables_generate (void);
-void tables_free (void);
-
-#endif /* !TABLES_H_ */
+/* Prepare the LALR and GLR parser tables.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef TABLES_H_
+# define TABLES_H_
+
+# include "state.h"
+
+/* The parser tables consist of these tables.
+
+ YYTRANSLATE = vector mapping yylex's token numbers into bison's
+ token numbers.
+
+ YYTNAME = vector of string-names indexed by bison token number.
+
+ YYTOKNUM = vector of yylex token numbers corresponding to entries
+ in YYTNAME.
+
+ YYRLINE = vector of line-numbers of all rules. For yydebug
+ printouts.
+
+ YYRHS = vector of items of all rules. This is exactly what RITEMS
+ contains. For yydebug and for semantic parser.
+
+ YYPRHS[R] = index in YYRHS of first item for rule R.
+
+ YYR1[R] = symbol number of symbol that rule R derives.
+
+ YYR2[R] = number of symbols composing right hand side of rule R.
+
+ YYSTOS[S] = the symbol number of the symbol that leads to state S.
+
+ YYFINAL = the state number of the termination state.
+
+ YYTABLE = a vector filled with portions for different uses, found
+ via YYPACT and YYPGOTO, described below.
+
+ YYLAST ( = high) the number of the last element of YYTABLE, i.e.,
+ sizeof (YYTABLE) - 1.
+
+ YYCHECK = a vector indexed in parallel with YYTABLE. It indicates,
+ in a roundabout way, the bounds of the portion you are trying to
+ examine.
+
+ Suppose that the portion of YYTABLE starts at index P and the index
+ to be examined within the portion is I. Then if YYCHECK[P+I] != I,
+ I is outside the bounds of what is actually allocated, and the
+ default (from YYDEFACT or YYDEFGOTO) should be used. Otherwise,
+ YYTABLE[P+I] should be used.
+
+ YYDEFACT[S] = default reduction number in state s. Performed when
+ YYTABLE doesn't specify something else to do. Zero means the default
+ is an error.
+
+ YYDEFGOTO[I] = default state to go to after a reduction of a rule
+ that generates variable NTOKENS + I, except when YYTABLE specifies
+ something else to do.
+
+ YYPACT[S] = index in YYTABLE of the portion describing state S.
+ The lookahead token's number, I, is used to index that portion of
+ YYTABLE to find out what action to perform.
+
+ If YYPACT[S] == YYPACT_NINF, if YYPACT[S] + I is outside the bounds
+ of YYTABLE (from 0 to YYLAST), or I is outside the bounds for portion
+ S (that is, YYCHECK[YYPACT[S] + I] != I), then the default action
+ (that is, YYDEFACT[S]) should be used instead of YYTABLE. Otherwise,
+ the value YYTABLE[YYPACT[S] + I] should be used even if
+ YYPACT[S] < 0.
+
+ If the value in YYTABLE is positive, we shift the token and go to
+ that state.
+
+ If the value is negative, it is minus a rule number to reduce by.
+
+ If the value is YYTABLE_NINF, it's a syntax error.
+
+ YYPGOTO[I] = the index in YYTABLE of the portion describing what to
+ do after reducing a rule that derives variable I + NTOKENS. This
+ portion is indexed by the parser state number, S, as of before the
+ text for this nonterminal was read.
+
+ If YYPGOTO[I] + S is outside the bounds of YYTABLE (from 0 to YYLAST)
+ or if S is outside the bounds of the portion for I (that is,
+ YYCHECK[YYPGOTO[I] + S] != S), then the default state (that is,
+ YYDEFGOTO[I]) should be used instead of YYTABLE. Otherwise,
+ YYTABLE[YYPGOTO[I] + S] is the state to go to even if YYPGOTO[I] < 0.
+
+ When the above YYPACT, YYPGOTO, and YYCHECK tests determine that a
+ value from YYTABLE should be used, that value is never zero, so it is
+ useless to check for zero. When those tests indicate that the value
+ from YYDEFACT or YYDEFGOTO should be used instead, the value from
+ YYTABLE *might* be zero, which, as a consequence of the way in which
+ the tables are constructed, also happens to indicate that YYDEFACT or
+ YYDEFGOTO should be used. However, the YYTABLE value cannot be
+ trusted when the YYDEFACT or YYDEFGOTO value should be used. In
+ summary, forget about zero values in YYTABLE.
+*/
+
+extern int nvectors;
+
+typedef int base_number;
+extern base_number *base;
+/* A distinguished value of BASE, negative infinite. During the
+ computation equals to BASE_MINIMUM, later mapped to BASE_NINF to
+ keep parser tables small. */
+extern base_number base_ninf;
+
+extern unsigned int *conflict_table;
+extern unsigned int *conflict_list;
+extern int conflict_list_cnt;
+
+extern base_number *table;
+extern base_number *check;
+/* The value used in TABLE to denote explicit syntax errors
+ (%nonassoc), a negative infinite. */
+extern base_number table_ninf;
+
+extern state_number *yydefgoto;
+extern rule_number *yydefact;
+extern int high;
+
+void tables_generate (void);
+void tables_free (void);
+
+#endif /* !TABLES_H_ */
diff --git a/contrib/tools/bison/bison/src/uniqstr.c b/contrib/tools/bison/bison/src/uniqstr.c
index 4a62e989c9..12f2ebd9c3 100644
--- a/contrib/tools/bison/bison/src/uniqstr.c
+++ b/contrib/tools/bison/bison/src/uniqstr.c
@@ -1,184 +1,184 @@
-/* Keep a unique copy of strings.
-
- Copyright (C) 2002-2005, 2009-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-#include "system.h"
-
-#include <error.h>
-#include <hash.h>
-#include <quotearg.h>
-#include <stdarg.h>
-#include <xmalloca.h>
-
-#include "uniqstr.h"
-
-/*-----------------------.
-| A uniqstr hash table. |
-`-----------------------*/
-
-/* Initial capacity of uniqstr hash table. */
-#define HT_INITIAL_CAPACITY 257
-
-static struct hash_table *uniqstrs_table = NULL;
-
-/*-------------------------------------.
-| Create the uniqstr for S if needed. |
-`-------------------------------------*/
-
-uniqstr
-uniqstr_new (char const *str)
-{
- uniqstr res = (uniqstr) hash_lookup (uniqstrs_table, str);
- if (!res)
- {
- /* First insertion in the hash. */
- res = xstrdup (str);
- if (!hash_insert (uniqstrs_table, res))
- xalloc_die ();
- }
- return res;
-}
-
-uniqstr
-uniqstr_vsprintf (char const *format, ...)
-{
- va_list args;
- size_t length;
- char* res;
- uniqstr str;
- va_start (args, format);
- length = vsnprintf (NULL, 0, format, args);
- va_end (args);
-
- res = xmalloca(length + 1);
- va_start (args, format);
- vsprintf (res, format, args);
- va_end (args);
- str = uniqstr_new (res);
- freea(res);
- return str;
-}
-
-/*------------------------------.
-| Abort if S is not a uniqstr. |
-`------------------------------*/
-
-void
-uniqstr_assert (char const *str)
-{
- if (!hash_lookup (uniqstrs_table, str))
- {
- error (0, 0,
- "not a uniqstr: %s", quotearg (str));
- abort ();
- }
-}
-
-
-/*--------------------.
-| Print the uniqstr. |
-`--------------------*/
-
-static inline bool
-uniqstr_print (uniqstr ustr)
-{
- fprintf (stderr, "%s\n", ustr);
- return true;
-}
-
-static bool
-uniqstr_print_processor (void *ustr, void *null ATTRIBUTE_UNUSED)
-{
- return uniqstr_print (ustr);
-}
-
-
-int
-uniqstr_cmp (uniqstr l, uniqstr r)
-{
- return (l == r ? 0
- : !l ? -1
- : !r ? +1
- : strcmp (l, r));
-}
-
-
-/*-----------------------.
-| A uniqstr hash table. |
-`-----------------------*/
-
-static bool
-hash_compare_uniqstr (void const *m1, void const *m2)
-{
- return STREQ (m1, m2);
-}
-
-static size_t
-hash_uniqstr (void const *m, size_t tablesize)
-{
- return hash_string (m, tablesize);
-}
-
-
-/*----------------------------.
-| Create the uniqstrs table. |
-`----------------------------*/
-
-void
-uniqstrs_new (void)
-{
- uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY,
- NULL,
- hash_uniqstr,
- hash_compare_uniqstr,
- free);
-}
-
-
-/*-------------------------------------.
-| Perform a task on all the uniqstrs. |
-`-------------------------------------*/
-
-static void
-uniqstrs_do (Hash_processor processor, void *processor_data)
-{
- hash_do_for_each (uniqstrs_table, processor, processor_data);
-}
-
-
-/*-----------------.
-| Print them all. |
-`-----------------*/
-
-void
-uniqstrs_print (void)
-{
- uniqstrs_do (uniqstr_print_processor, NULL);
-}
-
-
-/*--------------------.
-| Free the uniqstrs. |
-`--------------------*/
-
-void
-uniqstrs_free (void)
-{
- hash_free (uniqstrs_table);
-}
+/* Keep a unique copy of strings.
+
+ Copyright (C) 2002-2005, 2009-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+
+#include <error.h>
+#include <hash.h>
+#include <quotearg.h>
+#include <stdarg.h>
+#include <xmalloca.h>
+
+#include "uniqstr.h"
+
+/*-----------------------.
+| A uniqstr hash table. |
+`-----------------------*/
+
+/* Initial capacity of uniqstr hash table. */
+#define HT_INITIAL_CAPACITY 257
+
+static struct hash_table *uniqstrs_table = NULL;
+
+/*-------------------------------------.
+| Create the uniqstr for S if needed. |
+`-------------------------------------*/
+
+uniqstr
+uniqstr_new (char const *str)
+{
+ uniqstr res = (uniqstr) hash_lookup (uniqstrs_table, str);
+ if (!res)
+ {
+ /* First insertion in the hash. */
+ res = xstrdup (str);
+ if (!hash_insert (uniqstrs_table, res))
+ xalloc_die ();
+ }
+ return res;
+}
+
+uniqstr
+uniqstr_vsprintf (char const *format, ...)
+{
+ va_list args;
+ size_t length;
+ char* res;
+ uniqstr str;
+ va_start (args, format);
+ length = vsnprintf (NULL, 0, format, args);
+ va_end (args);
+
+ res = xmalloca(length + 1);
+ va_start (args, format);
+ vsprintf (res, format, args);
+ va_end (args);
+ str = uniqstr_new (res);
+ freea(res);
+ return str;
+}
+
+/*------------------------------.
+| Abort if S is not a uniqstr. |
+`------------------------------*/
+
+void
+uniqstr_assert (char const *str)
+{
+ if (!hash_lookup (uniqstrs_table, str))
+ {
+ error (0, 0,
+ "not a uniqstr: %s", quotearg (str));
+ abort ();
+ }
+}
+
+
+/*--------------------.
+| Print the uniqstr. |
+`--------------------*/
+
+static inline bool
+uniqstr_print (uniqstr ustr)
+{
+ fprintf (stderr, "%s\n", ustr);
+ return true;
+}
+
+static bool
+uniqstr_print_processor (void *ustr, void *null ATTRIBUTE_UNUSED)
+{
+ return uniqstr_print (ustr);
+}
+
+
+int
+uniqstr_cmp (uniqstr l, uniqstr r)
+{
+ return (l == r ? 0
+ : !l ? -1
+ : !r ? +1
+ : strcmp (l, r));
+}
+
+
+/*-----------------------.
+| A uniqstr hash table. |
+`-----------------------*/
+
+static bool
+hash_compare_uniqstr (void const *m1, void const *m2)
+{
+ return STREQ (m1, m2);
+}
+
+static size_t
+hash_uniqstr (void const *m, size_t tablesize)
+{
+ return hash_string (m, tablesize);
+}
+
+
+/*----------------------------.
+| Create the uniqstrs table. |
+`----------------------------*/
+
+void
+uniqstrs_new (void)
+{
+ uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY,
+ NULL,
+ hash_uniqstr,
+ hash_compare_uniqstr,
+ free);
+}
+
+
+/*-------------------------------------.
+| Perform a task on all the uniqstrs. |
+`-------------------------------------*/
+
+static void
+uniqstrs_do (Hash_processor processor, void *processor_data)
+{
+ hash_do_for_each (uniqstrs_table, processor, processor_data);
+}
+
+
+/*-----------------.
+| Print them all. |
+`-----------------*/
+
+void
+uniqstrs_print (void)
+{
+ uniqstrs_do (uniqstr_print_processor, NULL);
+}
+
+
+/*--------------------.
+| Free the uniqstrs. |
+`--------------------*/
+
+void
+uniqstrs_free (void)
+{
+ hash_free (uniqstrs_table);
+}
diff --git a/contrib/tools/bison/bison/src/uniqstr.h b/contrib/tools/bison/bison/src/uniqstr.h
index f8e59ab24f..9158fb0f8b 100644
--- a/contrib/tools/bison/bison/src/uniqstr.h
+++ b/contrib/tools/bison/bison/src/uniqstr.h
@@ -1,103 +1,103 @@
-/* Keeping a unique copy of strings.
-
- Copyright (C) 2002-2003, 2008-2013 Free Software Foundation, Inc.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef UNIQSTR_H_
-# define UNIQSTR_H_
-
-#include "system.h"
-
-/*-----------------------------------------.
-| Pointers to unique copies of C strings. |
-`-----------------------------------------*/
-
-typedef char const *uniqstr;
-
-/* Return the uniqstr for STR. */
-uniqstr uniqstr_new (char const *str);
-
-/* Return a uniqstr built by vsprintf. In order to simply concatenate
- strings, use UNIQSTR_CONCAT, which is a convenient wrapper around
- this function. */
-uniqstr uniqstr_vsprintf (char const *format, ...)
- __attribute__ ((__format__ (__printf__, 1, 2)));
-
-/* Two uniqstr values have the same value iff they are the same. */
-# define UNIQSTR_EQ(Ustr1, Ustr2) (!!((Ustr1) == (Ustr2)))
-
-/* Compare two uniqstr a la strcmp: negative for <, nul for =, and
- positive for >. Undefined order, relies on addresses. */
-int uniqstr_cmp (uniqstr u1, uniqstr u2);
-
-/* Die if STR is not a uniqstr. */
-void uniqstr_assert (char const *str);
-
-#if 0
- // msvc still does not support __VA_ARGS__
-/*----------------.
-| Concatenation. |
-`----------------*/
-
-/* Concatenate at most 20 strings and return a uniqstr. The goal of
- this macro is to make the caller's code a little more succinct
- without a trivial uniqstr_vsprintf format string to maintain
- (for example, "%s%s%s") while still benefitting from gcc's type
- checking. Unfortunately, because of the missing format string in the
- macro invocation, the argument number reported by gcc for a bad
- argument type is 1 too large. */
-# define UNIQSTR_CONCAT(...) \
- uniqstr_vsprintf (UNIQSTR_GEN_FORMAT (__VA_ARGS__, \
- "%s", "%s", "%s", "%s", "%s", \
- "%s", "%s", "%s", "%s", "%s", \
- "%s", "%s", "%s", "%s", "%s", \
- "%s", "%s", "%s", "%s", "%s"), \
- __VA_ARGS__)
-
-# define UNIQSTR_GEN_FORMAT(F1, F2, F3, F4, F5, \
- F6, F7, F8, F9, F10, \
- F11, F12, F13, F14, F15, \
- F16, F17, F18, F19, F20, \
- ...) \
- UNIQSTR_GEN_FORMAT_ (__VA_ARGS__, \
- "", "", "", "", "", \
- "", "", "", "", "", \
- "", "", "", "", "", \
- "", "", "", "", "")
-
-# define UNIQSTR_GEN_FORMAT_(F1, F2, F3, F4, F5, \
- F6, F7, F8, F9, F10, \
- F11, F12, F13, F14, F15, \
- F16, F17, F18, F19, F20, ...) \
- F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 \
- F11 F12 F13 F14 F15 F16 F17 F18 F19 F20
-
-#endif
-/*--------------------.
-| Table of uniqstrs. |
-`--------------------*/
-
-/* Create the string table. */
-void uniqstrs_new (void);
-
-/* Free all the memory allocated for symbols. */
-void uniqstrs_free (void);
-
-/* Report them all. */
-void uniqstrs_print (void);
-
-#endif /* ! defined UNIQSTR_H_ */
+/* Keeping a unique copy of strings.
+
+ Copyright (C) 2002-2003, 2008-2013 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef UNIQSTR_H_
+# define UNIQSTR_H_
+
+#include "system.h"
+
+/*-----------------------------------------.
+| Pointers to unique copies of C strings. |
+`-----------------------------------------*/
+
+typedef char const *uniqstr;
+
+/* Return the uniqstr for STR. */
+uniqstr uniqstr_new (char const *str);
+
+/* Return a uniqstr built by vsprintf. In order to simply concatenate
+ strings, use UNIQSTR_CONCAT, which is a convenient wrapper around
+ this function. */
+uniqstr uniqstr_vsprintf (char const *format, ...)
+ __attribute__ ((__format__ (__printf__, 1, 2)));
+
+/* Two uniqstr values have the same value iff they are the same. */
+# define UNIQSTR_EQ(Ustr1, Ustr2) (!!((Ustr1) == (Ustr2)))
+
+/* Compare two uniqstr a la strcmp: negative for <, nul for =, and
+ positive for >. Undefined order, relies on addresses. */
+int uniqstr_cmp (uniqstr u1, uniqstr u2);
+
+/* Die if STR is not a uniqstr. */
+void uniqstr_assert (char const *str);
+
+#if 0
+ // msvc still does not support __VA_ARGS__
+/*----------------.
+| Concatenation. |
+`----------------*/
+
+/* Concatenate at most 20 strings and return a uniqstr. The goal of
+ this macro is to make the caller's code a little more succinct
+ without a trivial uniqstr_vsprintf format string to maintain
+ (for example, "%s%s%s") while still benefitting from gcc's type
+ checking. Unfortunately, because of the missing format string in the
+ macro invocation, the argument number reported by gcc for a bad
+ argument type is 1 too large. */
+# define UNIQSTR_CONCAT(...) \
+ uniqstr_vsprintf (UNIQSTR_GEN_FORMAT (__VA_ARGS__, \
+ "%s", "%s", "%s", "%s", "%s", \
+ "%s", "%s", "%s", "%s", "%s", \
+ "%s", "%s", "%s", "%s", "%s", \
+ "%s", "%s", "%s", "%s", "%s"), \
+ __VA_ARGS__)
+
+# define UNIQSTR_GEN_FORMAT(F1, F2, F3, F4, F5, \
+ F6, F7, F8, F9, F10, \
+ F11, F12, F13, F14, F15, \
+ F16, F17, F18, F19, F20, \
+ ...) \
+ UNIQSTR_GEN_FORMAT_ (__VA_ARGS__, \
+ "", "", "", "", "", \
+ "", "", "", "", "", \
+ "", "", "", "", "", \
+ "", "", "", "", "")
+
+# define UNIQSTR_GEN_FORMAT_(F1, F2, F3, F4, F5, \
+ F6, F7, F8, F9, F10, \
+ F11, F12, F13, F14, F15, \
+ F16, F17, F18, F19, F20, ...) \
+ F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 \
+ F11 F12 F13 F14 F15 F16 F17 F18 F19 F20
+
+#endif
+/*--------------------.
+| Table of uniqstrs. |
+`--------------------*/
+
+/* Create the string table. */
+void uniqstrs_new (void);
+
+/* Free all the memory allocated for symbols. */
+void uniqstrs_free (void);
+
+/* Report them all. */
+void uniqstrs_print (void);
+
+#endif /* ! defined UNIQSTR_H_ */
diff --git a/contrib/tools/bison/bison/ya.make b/contrib/tools/bison/bison/ya.make
index 04f8ae3758..d1ca8f5f2e 100644
--- a/contrib/tools/bison/bison/ya.make
+++ b/contrib/tools/bison/bison/ya.make
@@ -1,7 +1,7 @@
OWNER(g:contrib)
PROGRAM()
-
+
LICENSE(
GPL-3.0-or-later AND
GPL-3.0-or-later WITH Bison-exception-2.2
@@ -13,57 +13,57 @@ IF (NOT MUSL)
NO_RUNTIME()
ENDIF()
-NO_COMPILER_WARNINGS()
+NO_COMPILER_WARNINGS()
ADDINCLSELF()
-
-SRCS(
- src/AnnotationList.c
- src/InadequacyList.c
- src/LR0.c
- src/Sbitset.c
- src/assoc.c
- src/closure.c
- src/complain.c
- src/conflicts.c
- src/derives.c
- src/files.c
- src/getargs.c
- src/gram.c
- src/graphviz.c
- src/ielr.c
- src/lalr.c
- src/location.c
- src/main.c
- src/muscle-tab.c
- src/named-ref.c
- src/nullable.c
- src/output.c
- src/parse-gram.c
- src/print-xml.c
- src/print.c
- src/print_graph.c
- src/reader.c
- src/reduce.c
- src/relation.c
- src/scan-code-c.c
- src/scan-gram-c.c
- src/scan-skel-c.c
- src/state.c
- src/symlist.c
- src/symtab.c
- src/tables.c
- src/uniqstr.c
+
+SRCS(
+ src/AnnotationList.c
+ src/InadequacyList.c
+ src/LR0.c
+ src/Sbitset.c
+ src/assoc.c
+ src/closure.c
+ src/complain.c
+ src/conflicts.c
+ src/derives.c
+ src/files.c
+ src/getargs.c
+ src/gram.c
+ src/graphviz.c
+ src/ielr.c
+ src/lalr.c
+ src/location.c
+ src/main.c
+ src/muscle-tab.c
+ src/named-ref.c
+ src/nullable.c
+ src/output.c
+ src/parse-gram.c
+ src/print-xml.c
+ src/print.c
+ src/print_graph.c
+ src/reader.c
+ src/reduce.c
+ src/relation.c
+ src/scan-code-c.c
+ src/scan-gram-c.c
+ src/scan-skel-c.c
+ src/state.c
+ src/symlist.c
+ src/symtab.c
+ src/tables.c
+ src/uniqstr.c
arcadia_root.cpp.in
-)
-
+)
+
CFLAGS(
-Daccept=bison_accept
-DBISON_DATA_DIR="contrib/tools/bison/bison/data"
)
-
+
PEERDIR(
contrib/tools/bison/gnulib
)
-
-END()
+
+END()
diff --git a/contrib/tools/bison/gnulib/platform/posix/config.h b/contrib/tools/bison/gnulib/platform/posix/config.h
index 8fa4b4f092..b101f69154 100644
--- a/contrib/tools/bison/gnulib/platform/posix/config.h
+++ b/contrib/tools/bison/gnulib/platform/posix/config.h
@@ -1,1806 +1,1806 @@
-/* lib/config.h. Generated from config.hin by configure. */
-/* lib/config.hin. Generated from configure.ac by autoheader. */
-
-/* Define if building universal (internal helper macro) */
-/* #undef AC_APPLE_UNIVERSAL_BUILD */
-
-/* Define to the number of bits in type 'ptrdiff_t'. */
-/* #undef BITSIZEOF_PTRDIFF_T */
-
-/* Define to the number of bits in type 'sig_atomic_t'. */
-/* #undef BITSIZEOF_SIG_ATOMIC_T */
-
-/* Define to the number of bits in type 'size_t'. */
-/* #undef BITSIZEOF_SIZE_T */
-
-/* Define to the number of bits in type 'wchar_t'. */
-/* #undef BITSIZEOF_WCHAR_T */
-
-/* Define to the number of bits in type 'wint_t'. */
-/* #undef BITSIZEOF_WINT_T */
-
-/* Define if you wish *printf() functions that have a safe handling of
- non-IEEE-754 'long double' values. */
-#define CHECK_PRINTF_SAFE 1
-
-/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
- systems. This function is required for `alloca.c' support on those systems.
- */
-/* #undef CRAY_STACKSEG_END */
-
-/* Define to 1 if using `alloca.c'. */
-/* #undef C_ALLOCA */
-
-/* Define as the bit index in the word where to find bit 0 of the exponent of
- 'double'. */
-#define DBL_EXPBIT0_BIT 20
-
-/* Define as the word index where to find the exponent of 'double'. */
-#define DBL_EXPBIT0_WORD 1
-
-/* Define as the bit index in the word where to find the sign of 'double'. */
-/* #undef DBL_SIGNBIT_BIT */
-
-/* Define as the word index where to find the sign of 'double'. */
-/* #undef DBL_SIGNBIT_WORD */
-
-/* Define to 1 if // is a file system root distinct from /. */
-/* #undef DOUBLE_SLASH_IS_DISTINCT_ROOT */
-
-/* Define to 1 if the changeword(REGEXP) functionality is wanted */
-/* #undef ENABLE_CHANGEWORD */
-
-/* Define to 1 if an invalid memory address access may yield a SIGBUS. */
-#define FAULT_YIELDS_SIGBUS 0
-
-/* Define this to 1 if F_DUPFD behavior does not match POSIX */
-/* #undef FCNTL_DUPFD_BUGGY */
-
-/* Define as the bit index in the word where to find bit 0 of the exponent of
- 'float'. */
-#define FLT_EXPBIT0_BIT 23
-
-/* Define as the word index where to find the exponent of 'float'. */
-#define FLT_EXPBIT0_WORD 0
-
-/* Define as the bit index in the word where to find the sign of 'float'. */
-/* #undef FLT_SIGNBIT_BIT */
-
-/* Define as the word index where to find the sign of 'float'. */
-/* #undef FLT_SIGNBIT_WORD */
-
-/* Define to 1 if fopen() fails to recognize a trailing slash. */
-/* #undef FOPEN_TRAILING_SLASH_BUG */
-
-/* Enable compile-time and run-time bounds-checking, and some warnings,
- without upsetting newer glibc. */
- #if defined __OPTIMIZE__ && __OPTIMIZE__
- # define _FORTIFY_SOURCE 2
- #endif
-
-
-/* Define to 1 if the system's ftello function has the Solaris bug. */
-/* #undef FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE */
-
-/* Define to 1 if fflush is known to work on stdin as per POSIX.1-2008, 0 if
- fflush is known to not work, -1 if unknown. */
-#define FUNC_FFLUSH_STDIN 0
-
-/* Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string. */
-#define FUNC_NL_LANGINFO_YESEXPR_WORKS 1
-
-/* Define to 1 if realpath() can malloc memory, always gives an absolute path,
- and handles trailing slash correctly. */
-#define FUNC_REALPATH_WORKS 1
-
-/* Define to 1 if ungetc is broken when used on arbitrary bytes. */
-/* #undef FUNC_UNGETC_BROKEN */
-
-/* Define if gettimeofday clobbers the localtime buffer. */
-/* #undef GETTIMEOFDAY_CLOBBERS_LOCALTIME */
-
-/* Define this to 'void' or 'struct timezone' to match the system's
- declaration of the second argument to gettimeofday. */
-#define GETTIMEOFDAY_TIMEZONE struct timezone
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module canonicalize-lgpl shall be considered present. */
-#define GNULIB_CANONICALIZE_LGPL 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module close-stream shall be considered present. */
-#define GNULIB_CLOSE_STREAM 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module dirname shall be considered present. */
-#define GNULIB_DIRNAME 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fd-safer-flag shall be considered present. */
-#define GNULIB_FD_SAFER_FLAG 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fflush shall be considered present. */
-#define GNULIB_FFLUSH 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module filenamecat shall be considered present. */
-#define GNULIB_FILENAMECAT 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fopen-safer shall be considered present. */
-#define GNULIB_FOPEN_SAFER 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fscanf shall be considered present. */
-#define GNULIB_FSCANF 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module lock shall be considered present. */
-#define GNULIB_LOCK 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module malloc-gnu shall be considered present. */
-#define GNULIB_MALLOC_GNU 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module pipe2-safer shall be considered present. */
-#define GNULIB_PIPE2_SAFER 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module scanf shall be considered present. */
-#define GNULIB_SCANF 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module sigpipe shall be considered present. */
-#define GNULIB_SIGPIPE 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module snprintf shall be considered present. */
-#define GNULIB_SNPRINTF 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module strerror shall be considered present. */
-#define GNULIB_STRERROR 1
-
-/* Define to 1 when the gnulib module btowc should be tested. */
-#define GNULIB_TEST_BTOWC 1
-
-/* Define to 1 when the gnulib module canonicalize_file_name should be tested.
- */
-#define GNULIB_TEST_CANONICALIZE_FILE_NAME 1
-
-/* Define to 1 when the gnulib module chdir should be tested. */
-#define GNULIB_TEST_CHDIR 1
-
-/* Define to 1 when the gnulib module cloexec should be tested. */
-#define GNULIB_TEST_CLOEXEC 1
-
-/* Define to 1 when the gnulib module close should be tested. */
-#define GNULIB_TEST_CLOSE 1
-
-/* Define to 1 when the gnulib module closedir should be tested. */
-#define GNULIB_TEST_CLOSEDIR 1
-
-/* Define to 1 when the gnulib module dup should be tested. */
-#define GNULIB_TEST_DUP 1
-
-/* Define to 1 when the gnulib module dup2 should be tested. */
-#define GNULIB_TEST_DUP2 1
-
-/* Define to 1 when the gnulib module environ should be tested. */
-#define GNULIB_TEST_ENVIRON 1
-
-/* Define to 1 when the gnulib module fclose should be tested. */
-#define GNULIB_TEST_FCLOSE 1
-
-/* Define to 1 when the gnulib module fcntl should be tested. */
-#define GNULIB_TEST_FCNTL 1
-
-/* Define to 1 when the gnulib module fdopen should be tested. */
-#define GNULIB_TEST_FDOPEN 1
-
-/* Define to 1 when the gnulib module fflush should be tested. */
-#define GNULIB_TEST_FFLUSH 1
-
-/* Define to 1 when the gnulib module fopen should be tested. */
-#define GNULIB_TEST_FOPEN 1
-
-/* Define to 1 when the gnulib module fpurge should be tested. */
-#define GNULIB_TEST_FPURGE 1
-
-/* Define to 1 when the gnulib module frexp should be tested. */
-#define GNULIB_TEST_FREXP 1
-
-/* Define to 1 when the gnulib module frexpl should be tested. */
-#define GNULIB_TEST_FREXPL 1
-
-/* Define to 1 when the gnulib module fseek should be tested. */
-#define GNULIB_TEST_FSEEK 1
-
-/* Define to 1 when the gnulib module fseeko should be tested. */
-#define GNULIB_TEST_FSEEKO 1
-
-/* Define to 1 when the gnulib module fstat should be tested. */
-#define GNULIB_TEST_FSTAT 1
-
-/* Define to 1 when the gnulib module ftell should be tested. */
-#define GNULIB_TEST_FTELL 1
-
-/* Define to 1 when the gnulib module ftello should be tested. */
-#define GNULIB_TEST_FTELLO 1
-
-/* Define to 1 when the gnulib module getcwd should be tested. */
-#define GNULIB_TEST_GETCWD 1
-
-/* Define to 1 when the gnulib module getdtablesize should be tested. */
-#define GNULIB_TEST_GETDTABLESIZE 1
-
-/* Define to 1 when the gnulib module getopt-gnu should be tested. */
-#define GNULIB_TEST_GETOPT_GNU 1
-
-/* Define to 1 when the gnulib module getpagesize should be tested. */
-#define GNULIB_TEST_GETPAGESIZE 1
-
-/* Define to 1 when the gnulib module gettimeofday should be tested. */
-#define GNULIB_TEST_GETTIMEOFDAY 1
-
-/* Define to 1 when the gnulib module link should be tested. */
-#define GNULIB_TEST_LINK 1
-
-/* Define to 1 when the gnulib module localeconv should be tested. */
-#define GNULIB_TEST_LOCALECONV 1
-
-/* Define to 1 when the gnulib module lseek should be tested. */
-#define GNULIB_TEST_LSEEK 1
-
-/* Define to 1 when the gnulib module lstat should be tested. */
-#define GNULIB_TEST_LSTAT 1
-
-/* Define to 1 when the gnulib module malloc-posix should be tested. */
-#define GNULIB_TEST_MALLOC_POSIX 1
-
-/* Define to 1 when the gnulib module mbrtowc should be tested. */
-#define GNULIB_TEST_MBRTOWC 1
-
-/* Define to 1 when the gnulib module mbsinit should be tested. */
-#define GNULIB_TEST_MBSINIT 1
-
-/* Define to 1 when the gnulib module mbtowc should be tested. */
-#define GNULIB_TEST_MBTOWC 1
-
-/* Define to 1 when the gnulib module memchr should be tested. */
-#define GNULIB_TEST_MEMCHR 1
-
-/* Define to 1 when the gnulib module mkdtemp should be tested. */
-#define GNULIB_TEST_MKDTEMP 1
-
-/* Define to 1 when the gnulib module mkstemp should be tested. */
-#define GNULIB_TEST_MKSTEMP 1
-
-/* Define to 1 when the gnulib module nl_langinfo should be tested. */
-#define GNULIB_TEST_NL_LANGINFO 1
-
-/* Define to 1 when the gnulib module open should be tested. */
-#define GNULIB_TEST_OPEN 1
-
-/* Define to 1 when the gnulib module opendir should be tested. */
-#define GNULIB_TEST_OPENDIR 1
-
-/* Define to 1 when the gnulib module pipe2 should be tested. */
-#define GNULIB_TEST_PIPE2 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_destroy should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWNATTR_DESTROY 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_init should be tested.
- */
-#define GNULIB_TEST_POSIX_SPAWNATTR_INIT 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_setflags should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWNATTR_SETFLAGS 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_setsigmask should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWNATTR_SETSIGMASK 1
-
-/* Define to 1 when the gnulib module posix_spawnp should be tested. */
-#define GNULIB_TEST_POSIX_SPAWNP 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_addclose should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_adddup2 should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_addopen should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_destroy should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_DESTROY 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_init should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_INIT 1
-
-/* Define to 1 when the gnulib module putenv should be tested. */
-#define GNULIB_TEST_PUTENV 1
-
-/* Define to 1 when the gnulib module raise should be tested. */
-#define GNULIB_TEST_RAISE 1
-
-/* Define to 1 when the gnulib module rawmemchr should be tested. */
-#define GNULIB_TEST_RAWMEMCHR 1
-
-/* Define to 1 when the gnulib module readdir should be tested. */
-#define GNULIB_TEST_READDIR 1
-
-/* Define to 1 when the gnulib module readlink should be tested. */
-#define GNULIB_TEST_READLINK 1
-
-/* Define to 1 when the gnulib module realpath should be tested. */
-#define GNULIB_TEST_REALPATH 1
-
-/* Define to 1 when the gnulib module rename should be tested. */
-#define GNULIB_TEST_RENAME 1
-
-/* Define to 1 when the gnulib module rmdir should be tested. */
-#define GNULIB_TEST_RMDIR 1
-
-/* Define to 1 when the gnulib module secure_getenv should be tested. */
-#define GNULIB_TEST_SECURE_GETENV 1
-
-/* Define to 1 when the gnulib module setenv should be tested. */
-#define GNULIB_TEST_SETENV 1
-
-/* Define to 1 when the gnulib module setlocale should be tested. */
-#define GNULIB_TEST_SETLOCALE 1
-
-/* Define to 1 when the gnulib module sigaction should be tested. */
-#define GNULIB_TEST_SIGACTION 1
-
-/* Define to 1 when the gnulib module signbit should be tested. */
-#define GNULIB_TEST_SIGNBIT 1
-
-/* Define to 1 when the gnulib module sigprocmask should be tested. */
-#define GNULIB_TEST_SIGPROCMASK 1
-
-/* Define to 1 when the gnulib module sleep should be tested. */
-#define GNULIB_TEST_SLEEP 1
-
-/* Define to 1 when the gnulib module snprintf should be tested. */
-#define GNULIB_TEST_SNPRINTF 1
-
-/* Define to 1 when the gnulib module stat should be tested. */
-#define GNULIB_TEST_STAT 1
-
-/* Define to 1 when the gnulib module strchrnul should be tested. */
-#define GNULIB_TEST_STRCHRNUL 1
-
-/* Define to 1 when the gnulib module strdup should be tested. */
-#define GNULIB_TEST_STRDUP 1
-
-/* Define to 1 when the gnulib module strerror should be tested. */
-#define GNULIB_TEST_STRERROR 1
-
-/* Define to 1 when the gnulib module strndup should be tested. */
-#define GNULIB_TEST_STRNDUP 1
-
-/* Define to 1 when the gnulib module strnlen should be tested. */
-#define GNULIB_TEST_STRNLEN 1
-
-/* Define to 1 when the gnulib module strsignal should be tested. */
-#define GNULIB_TEST_STRSIGNAL 1
-
-/* Define to 1 when the gnulib module strstr should be tested. */
-#define GNULIB_TEST_STRSTR 1
-
-/* Define to 1 when the gnulib module strtod should be tested. */
-#define GNULIB_TEST_STRTOD 1
-
-/* Define to 1 when the gnulib module symlink should be tested. */
-#define GNULIB_TEST_SYMLINK 1
-
-/* Define to 1 when the gnulib module unsetenv should be tested. */
-#define GNULIB_TEST_UNSETENV 1
-
-/* Define to 1 when the gnulib module vasprintf should be tested. */
-#define GNULIB_TEST_VASPRINTF 1
-
-/* Define to 1 when the gnulib module waitpid should be tested. */
-#define GNULIB_TEST_WAITPID 1
-
-/* Define to 1 when the gnulib module wcrtomb should be tested. */
-#define GNULIB_TEST_WCRTOMB 1
-
-/* Define to 1 when the gnulib module wctob should be tested. */
-#define GNULIB_TEST_WCTOB 1
-
-/* Define to 1 when the gnulib module wctomb should be tested. */
-#define GNULIB_TEST_WCTOMB 1
-
-/* Define to 1 when the gnulib module write should be tested. */
-#define GNULIB_TEST_WRITE 1
-
-/* Define to 1 if you have 'alloca' after including <alloca.h>, a header that
- may be supplied by this distribution. */
-#define HAVE_ALLOCA 1
-
-/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
- */
-#define HAVE_ALLOCA_H 1
-
-/* Define to 1 if you have the <bp-sym.h> header file. */
-/* #undef HAVE_BP_SYM_H */
-
-/* Define to 1 if you have the `btowc' function. */
-#define HAVE_BTOWC 1
-
-/* Define to 1 if you have the `canonicalize_file_name' function. */
-#define HAVE_CANONICALIZE_FILE_NAME 1
-
-/* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the
- CoreFoundation framework. */
-/* #undef HAVE_CFLOCALECOPYCURRENT */
-
-/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
- the CoreFoundation framework. */
-/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
-
-/* Define to 1 if you have the `closedir' function. */
-#define HAVE_CLOSEDIR 1
-
-/* Define to 1 if you have the `confstr' function. */
-/* #undef HAVE_CONFSTR */
-
-/* Define if the copysignf function is declared in <math.h> and available in
- libc. */
-/* #undef HAVE_COPYSIGNF_IN_LIBC */
-
-/* Define if the copysignl function is declared in <math.h> and available in
- libc. */
-/* #undef HAVE_COPYSIGNL_IN_LIBC */
-
-/* Define if the copysign function is declared in <math.h> and available in
- libc. */
-/* #undef HAVE_COPYSIGN_IN_LIBC */
-
-/* Define to 1 if you have the declaration of `alarm', and to 0 if you don't.
- */
-#define HAVE_DECL_ALARM 1
-
+/* lib/config.h. Generated from config.hin by configure. */
+/* lib/config.hin. Generated from configure.ac by autoheader. */
+
+/* Define if building universal (internal helper macro) */
+/* #undef AC_APPLE_UNIVERSAL_BUILD */
+
+/* Define to the number of bits in type 'ptrdiff_t'. */
+/* #undef BITSIZEOF_PTRDIFF_T */
+
+/* Define to the number of bits in type 'sig_atomic_t'. */
+/* #undef BITSIZEOF_SIG_ATOMIC_T */
+
+/* Define to the number of bits in type 'size_t'. */
+/* #undef BITSIZEOF_SIZE_T */
+
+/* Define to the number of bits in type 'wchar_t'. */
+/* #undef BITSIZEOF_WCHAR_T */
+
+/* Define to the number of bits in type 'wint_t'. */
+/* #undef BITSIZEOF_WINT_T */
+
+/* Define if you wish *printf() functions that have a safe handling of
+ non-IEEE-754 'long double' values. */
+#define CHECK_PRINTF_SAFE 1
+
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+ systems. This function is required for `alloca.c' support on those systems.
+ */
+/* #undef CRAY_STACKSEG_END */
+
+/* Define to 1 if using `alloca.c'. */
+/* #undef C_ALLOCA */
+
+/* Define as the bit index in the word where to find bit 0 of the exponent of
+ 'double'. */
+#define DBL_EXPBIT0_BIT 20
+
+/* Define as the word index where to find the exponent of 'double'. */
+#define DBL_EXPBIT0_WORD 1
+
+/* Define as the bit index in the word where to find the sign of 'double'. */
+/* #undef DBL_SIGNBIT_BIT */
+
+/* Define as the word index where to find the sign of 'double'. */
+/* #undef DBL_SIGNBIT_WORD */
+
+/* Define to 1 if // is a file system root distinct from /. */
+/* #undef DOUBLE_SLASH_IS_DISTINCT_ROOT */
+
+/* Define to 1 if the changeword(REGEXP) functionality is wanted */
+/* #undef ENABLE_CHANGEWORD */
+
+/* Define to 1 if an invalid memory address access may yield a SIGBUS. */
+#define FAULT_YIELDS_SIGBUS 0
+
+/* Define this to 1 if F_DUPFD behavior does not match POSIX */
+/* #undef FCNTL_DUPFD_BUGGY */
+
+/* Define as the bit index in the word where to find bit 0 of the exponent of
+ 'float'. */
+#define FLT_EXPBIT0_BIT 23
+
+/* Define as the word index where to find the exponent of 'float'. */
+#define FLT_EXPBIT0_WORD 0
+
+/* Define as the bit index in the word where to find the sign of 'float'. */
+/* #undef FLT_SIGNBIT_BIT */
+
+/* Define as the word index where to find the sign of 'float'. */
+/* #undef FLT_SIGNBIT_WORD */
+
+/* Define to 1 if fopen() fails to recognize a trailing slash. */
+/* #undef FOPEN_TRAILING_SLASH_BUG */
+
+/* Enable compile-time and run-time bounds-checking, and some warnings,
+ without upsetting newer glibc. */
+ #if defined __OPTIMIZE__ && __OPTIMIZE__
+ # define _FORTIFY_SOURCE 2
+ #endif
+
+
+/* Define to 1 if the system's ftello function has the Solaris bug. */
+/* #undef FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE */
+
+/* Define to 1 if fflush is known to work on stdin as per POSIX.1-2008, 0 if
+ fflush is known to not work, -1 if unknown. */
+#define FUNC_FFLUSH_STDIN 0
+
+/* Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string. */
+#define FUNC_NL_LANGINFO_YESEXPR_WORKS 1
+
+/* Define to 1 if realpath() can malloc memory, always gives an absolute path,
+ and handles trailing slash correctly. */
+#define FUNC_REALPATH_WORKS 1
+
+/* Define to 1 if ungetc is broken when used on arbitrary bytes. */
+/* #undef FUNC_UNGETC_BROKEN */
+
+/* Define if gettimeofday clobbers the localtime buffer. */
+/* #undef GETTIMEOFDAY_CLOBBERS_LOCALTIME */
+
+/* Define this to 'void' or 'struct timezone' to match the system's
+ declaration of the second argument to gettimeofday. */
+#define GETTIMEOFDAY_TIMEZONE struct timezone
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module canonicalize-lgpl shall be considered present. */
+#define GNULIB_CANONICALIZE_LGPL 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module close-stream shall be considered present. */
+#define GNULIB_CLOSE_STREAM 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module dirname shall be considered present. */
+#define GNULIB_DIRNAME 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fd-safer-flag shall be considered present. */
+#define GNULIB_FD_SAFER_FLAG 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fflush shall be considered present. */
+#define GNULIB_FFLUSH 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module filenamecat shall be considered present. */
+#define GNULIB_FILENAMECAT 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fopen-safer shall be considered present. */
+#define GNULIB_FOPEN_SAFER 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fscanf shall be considered present. */
+#define GNULIB_FSCANF 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module lock shall be considered present. */
+#define GNULIB_LOCK 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module malloc-gnu shall be considered present. */
+#define GNULIB_MALLOC_GNU 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module pipe2-safer shall be considered present. */
+#define GNULIB_PIPE2_SAFER 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module scanf shall be considered present. */
+#define GNULIB_SCANF 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module sigpipe shall be considered present. */
+#define GNULIB_SIGPIPE 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module snprintf shall be considered present. */
+#define GNULIB_SNPRINTF 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module strerror shall be considered present. */
+#define GNULIB_STRERROR 1
+
+/* Define to 1 when the gnulib module btowc should be tested. */
+#define GNULIB_TEST_BTOWC 1
+
+/* Define to 1 when the gnulib module canonicalize_file_name should be tested.
+ */
+#define GNULIB_TEST_CANONICALIZE_FILE_NAME 1
+
+/* Define to 1 when the gnulib module chdir should be tested. */
+#define GNULIB_TEST_CHDIR 1
+
+/* Define to 1 when the gnulib module cloexec should be tested. */
+#define GNULIB_TEST_CLOEXEC 1
+
+/* Define to 1 when the gnulib module close should be tested. */
+#define GNULIB_TEST_CLOSE 1
+
+/* Define to 1 when the gnulib module closedir should be tested. */
+#define GNULIB_TEST_CLOSEDIR 1
+
+/* Define to 1 when the gnulib module dup should be tested. */
+#define GNULIB_TEST_DUP 1
+
+/* Define to 1 when the gnulib module dup2 should be tested. */
+#define GNULIB_TEST_DUP2 1
+
+/* Define to 1 when the gnulib module environ should be tested. */
+#define GNULIB_TEST_ENVIRON 1
+
+/* Define to 1 when the gnulib module fclose should be tested. */
+#define GNULIB_TEST_FCLOSE 1
+
+/* Define to 1 when the gnulib module fcntl should be tested. */
+#define GNULIB_TEST_FCNTL 1
+
+/* Define to 1 when the gnulib module fdopen should be tested. */
+#define GNULIB_TEST_FDOPEN 1
+
+/* Define to 1 when the gnulib module fflush should be tested. */
+#define GNULIB_TEST_FFLUSH 1
+
+/* Define to 1 when the gnulib module fopen should be tested. */
+#define GNULIB_TEST_FOPEN 1
+
+/* Define to 1 when the gnulib module fpurge should be tested. */
+#define GNULIB_TEST_FPURGE 1
+
+/* Define to 1 when the gnulib module frexp should be tested. */
+#define GNULIB_TEST_FREXP 1
+
+/* Define to 1 when the gnulib module frexpl should be tested. */
+#define GNULIB_TEST_FREXPL 1
+
+/* Define to 1 when the gnulib module fseek should be tested. */
+#define GNULIB_TEST_FSEEK 1
+
+/* Define to 1 when the gnulib module fseeko should be tested. */
+#define GNULIB_TEST_FSEEKO 1
+
+/* Define to 1 when the gnulib module fstat should be tested. */
+#define GNULIB_TEST_FSTAT 1
+
+/* Define to 1 when the gnulib module ftell should be tested. */
+#define GNULIB_TEST_FTELL 1
+
+/* Define to 1 when the gnulib module ftello should be tested. */
+#define GNULIB_TEST_FTELLO 1
+
+/* Define to 1 when the gnulib module getcwd should be tested. */
+#define GNULIB_TEST_GETCWD 1
+
+/* Define to 1 when the gnulib module getdtablesize should be tested. */
+#define GNULIB_TEST_GETDTABLESIZE 1
+
+/* Define to 1 when the gnulib module getopt-gnu should be tested. */
+#define GNULIB_TEST_GETOPT_GNU 1
+
+/* Define to 1 when the gnulib module getpagesize should be tested. */
+#define GNULIB_TEST_GETPAGESIZE 1
+
+/* Define to 1 when the gnulib module gettimeofday should be tested. */
+#define GNULIB_TEST_GETTIMEOFDAY 1
+
+/* Define to 1 when the gnulib module link should be tested. */
+#define GNULIB_TEST_LINK 1
+
+/* Define to 1 when the gnulib module localeconv should be tested. */
+#define GNULIB_TEST_LOCALECONV 1
+
+/* Define to 1 when the gnulib module lseek should be tested. */
+#define GNULIB_TEST_LSEEK 1
+
+/* Define to 1 when the gnulib module lstat should be tested. */
+#define GNULIB_TEST_LSTAT 1
+
+/* Define to 1 when the gnulib module malloc-posix should be tested. */
+#define GNULIB_TEST_MALLOC_POSIX 1
+
+/* Define to 1 when the gnulib module mbrtowc should be tested. */
+#define GNULIB_TEST_MBRTOWC 1
+
+/* Define to 1 when the gnulib module mbsinit should be tested. */
+#define GNULIB_TEST_MBSINIT 1
+
+/* Define to 1 when the gnulib module mbtowc should be tested. */
+#define GNULIB_TEST_MBTOWC 1
+
+/* Define to 1 when the gnulib module memchr should be tested. */
+#define GNULIB_TEST_MEMCHR 1
+
+/* Define to 1 when the gnulib module mkdtemp should be tested. */
+#define GNULIB_TEST_MKDTEMP 1
+
+/* Define to 1 when the gnulib module mkstemp should be tested. */
+#define GNULIB_TEST_MKSTEMP 1
+
+/* Define to 1 when the gnulib module nl_langinfo should be tested. */
+#define GNULIB_TEST_NL_LANGINFO 1
+
+/* Define to 1 when the gnulib module open should be tested. */
+#define GNULIB_TEST_OPEN 1
+
+/* Define to 1 when the gnulib module opendir should be tested. */
+#define GNULIB_TEST_OPENDIR 1
+
+/* Define to 1 when the gnulib module pipe2 should be tested. */
+#define GNULIB_TEST_PIPE2 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_destroy should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWNATTR_DESTROY 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_init should be tested.
+ */
+#define GNULIB_TEST_POSIX_SPAWNATTR_INIT 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_setflags should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWNATTR_SETFLAGS 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_setsigmask should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWNATTR_SETSIGMASK 1
+
+/* Define to 1 when the gnulib module posix_spawnp should be tested. */
+#define GNULIB_TEST_POSIX_SPAWNP 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_addclose should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_adddup2 should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_addopen should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_destroy should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_DESTROY 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_init should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_INIT 1
+
+/* Define to 1 when the gnulib module putenv should be tested. */
+#define GNULIB_TEST_PUTENV 1
+
+/* Define to 1 when the gnulib module raise should be tested. */
+#define GNULIB_TEST_RAISE 1
+
+/* Define to 1 when the gnulib module rawmemchr should be tested. */
+#define GNULIB_TEST_RAWMEMCHR 1
+
+/* Define to 1 when the gnulib module readdir should be tested. */
+#define GNULIB_TEST_READDIR 1
+
+/* Define to 1 when the gnulib module readlink should be tested. */
+#define GNULIB_TEST_READLINK 1
+
+/* Define to 1 when the gnulib module realpath should be tested. */
+#define GNULIB_TEST_REALPATH 1
+
+/* Define to 1 when the gnulib module rename should be tested. */
+#define GNULIB_TEST_RENAME 1
+
+/* Define to 1 when the gnulib module rmdir should be tested. */
+#define GNULIB_TEST_RMDIR 1
+
+/* Define to 1 when the gnulib module secure_getenv should be tested. */
+#define GNULIB_TEST_SECURE_GETENV 1
+
+/* Define to 1 when the gnulib module setenv should be tested. */
+#define GNULIB_TEST_SETENV 1
+
+/* Define to 1 when the gnulib module setlocale should be tested. */
+#define GNULIB_TEST_SETLOCALE 1
+
+/* Define to 1 when the gnulib module sigaction should be tested. */
+#define GNULIB_TEST_SIGACTION 1
+
+/* Define to 1 when the gnulib module signbit should be tested. */
+#define GNULIB_TEST_SIGNBIT 1
+
+/* Define to 1 when the gnulib module sigprocmask should be tested. */
+#define GNULIB_TEST_SIGPROCMASK 1
+
+/* Define to 1 when the gnulib module sleep should be tested. */
+#define GNULIB_TEST_SLEEP 1
+
+/* Define to 1 when the gnulib module snprintf should be tested. */
+#define GNULIB_TEST_SNPRINTF 1
+
+/* Define to 1 when the gnulib module stat should be tested. */
+#define GNULIB_TEST_STAT 1
+
+/* Define to 1 when the gnulib module strchrnul should be tested. */
+#define GNULIB_TEST_STRCHRNUL 1
+
+/* Define to 1 when the gnulib module strdup should be tested. */
+#define GNULIB_TEST_STRDUP 1
+
+/* Define to 1 when the gnulib module strerror should be tested. */
+#define GNULIB_TEST_STRERROR 1
+
+/* Define to 1 when the gnulib module strndup should be tested. */
+#define GNULIB_TEST_STRNDUP 1
+
+/* Define to 1 when the gnulib module strnlen should be tested. */
+#define GNULIB_TEST_STRNLEN 1
+
+/* Define to 1 when the gnulib module strsignal should be tested. */
+#define GNULIB_TEST_STRSIGNAL 1
+
+/* Define to 1 when the gnulib module strstr should be tested. */
+#define GNULIB_TEST_STRSTR 1
+
+/* Define to 1 when the gnulib module strtod should be tested. */
+#define GNULIB_TEST_STRTOD 1
+
+/* Define to 1 when the gnulib module symlink should be tested. */
+#define GNULIB_TEST_SYMLINK 1
+
+/* Define to 1 when the gnulib module unsetenv should be tested. */
+#define GNULIB_TEST_UNSETENV 1
+
+/* Define to 1 when the gnulib module vasprintf should be tested. */
+#define GNULIB_TEST_VASPRINTF 1
+
+/* Define to 1 when the gnulib module waitpid should be tested. */
+#define GNULIB_TEST_WAITPID 1
+
+/* Define to 1 when the gnulib module wcrtomb should be tested. */
+#define GNULIB_TEST_WCRTOMB 1
+
+/* Define to 1 when the gnulib module wctob should be tested. */
+#define GNULIB_TEST_WCTOB 1
+
+/* Define to 1 when the gnulib module wctomb should be tested. */
+#define GNULIB_TEST_WCTOMB 1
+
+/* Define to 1 when the gnulib module write should be tested. */
+#define GNULIB_TEST_WRITE 1
+
+/* Define to 1 if you have 'alloca' after including <alloca.h>, a header that
+ may be supplied by this distribution. */
+#define HAVE_ALLOCA 1
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+ */
+#define HAVE_ALLOCA_H 1
+
+/* Define to 1 if you have the <bp-sym.h> header file. */
+/* #undef HAVE_BP_SYM_H */
+
+/* Define to 1 if you have the `btowc' function. */
+#define HAVE_BTOWC 1
+
+/* Define to 1 if you have the `canonicalize_file_name' function. */
+#define HAVE_CANONICALIZE_FILE_NAME 1
+
+/* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the
+ CoreFoundation framework. */
+/* #undef HAVE_CFLOCALECOPYCURRENT */
+
+/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
+ the CoreFoundation framework. */
+/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
+
+/* Define to 1 if you have the `closedir' function. */
+#define HAVE_CLOSEDIR 1
+
+/* Define to 1 if you have the `confstr' function. */
+/* #undef HAVE_CONFSTR */
+
+/* Define if the copysignf function is declared in <math.h> and available in
+ libc. */
+/* #undef HAVE_COPYSIGNF_IN_LIBC */
+
+/* Define if the copysignl function is declared in <math.h> and available in
+ libc. */
+/* #undef HAVE_COPYSIGNL_IN_LIBC */
+
+/* Define if the copysign function is declared in <math.h> and available in
+ libc. */
+/* #undef HAVE_COPYSIGN_IN_LIBC */
+
+/* Define to 1 if you have the declaration of `alarm', and to 0 if you don't.
+ */
+#define HAVE_DECL_ALARM 1
+
#if defined(__linux__)
#define HAVE_UNLOCKED_IO 1
#else
#define HAVE_UNLOCKED_IO 0
#endif
-/* Define to 1 if you have the declaration of `clearerr_unlocked', and to 0 if
- you don't. */
+/* Define to 1 if you have the declaration of `clearerr_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_CLEARERR_UNLOCKED 1
#else
#define HAVE_DECL_CLEARERR_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `copysign', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_COPYSIGN */
-
-/* Define to 1 if you have the declaration of `copysignf', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_COPYSIGNF */
-
-/* Define to 1 if you have the declaration of `copysignl', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_COPYSIGNL */
-
-/* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you
- don't. */
+
+/* Define to 1 if you have the declaration of `copysign', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_COPYSIGN */
+
+/* Define to 1 if you have the declaration of `copysignf', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_COPYSIGNF */
+
+/* Define to 1 if you have the declaration of `copysignl', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_COPYSIGNL */
+
+/* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you
+ don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FEOF_UNLOCKED 1
#else
#define HAVE_DECL_FEOF_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `ferror_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `ferror_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FERROR_UNLOCKED 1
#else
#define HAVE_DECL_FERROR_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `fflush_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `fflush_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FFLUSH_UNLOCKED 1
#else
#define HAVE_DECL_FFLUSH_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FGETS_UNLOCKED 1
#else
#define HAVE_DECL_FGETS_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `fpurge', and to 0 if you don't.
- */
-#define HAVE_DECL_FPURGE 0
-
-/* Define to 1 if you have the declaration of `fputc_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `fpurge', and to 0 if you don't.
+ */
+#define HAVE_DECL_FPURGE 0
+
+/* Define to 1 if you have the declaration of `fputc_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FPUTC_UNLOCKED 1
#else
#define HAVE_DECL_FPUTC_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `fputs_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `fputs_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FPUTS_UNLOCKED 1
#else
#define HAVE_DECL_FPUTS_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `fread_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `fread_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FREAD_UNLOCKED 1
#else
#define HAVE_DECL_FREAD_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `fseeko', and to 0 if you don't.
- */
-#define HAVE_DECL_FSEEKO 1
-
-/* Define to 1 if you have the declaration of `ftello', and to 0 if you don't.
- */
-#define HAVE_DECL_FTELLO 1
-
-/* Define to 1 if you have the declaration of `fwrite_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `fseeko', and to 0 if you don't.
+ */
+#define HAVE_DECL_FSEEKO 1
+
+/* Define to 1 if you have the declaration of `ftello', and to 0 if you don't.
+ */
+#define HAVE_DECL_FTELLO 1
+
+/* Define to 1 if you have the declaration of `fwrite_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_FWRITE_UNLOCKED 1
#else
#define HAVE_DECL_FWRITE_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `getchar_unlocked', and to 0 if
- you don't. */
+
+/* Define to 1 if you have the declaration of `getchar_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_GETCHAR_UNLOCKED 1
#else
#define HAVE_DECL_GETCHAR_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
- don't. */
+
+/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
+ don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_GETC_UNLOCKED 1
#else
#define HAVE_DECL_GETC_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
- */
-#define HAVE_DECL_GETENV 1
-
-/* Define to 1 if you have the declaration of `isblank', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_ISBLANK */
-
-/* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_MBRTOWC */
-
-/* Define to 1 if you have the declaration of `mbsinit', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_MBSINIT */
-
+
+/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
+ */
+#define HAVE_DECL_GETENV 1
+
+/* Define to 1 if you have the declaration of `isblank', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_ISBLANK */
+
+/* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_MBRTOWC */
+
+/* Define to 1 if you have the declaration of `mbsinit', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_MBSINIT */
+
#if defined(__linux__)
-/* Define to 1 if you have the declaration of `program_invocation_name', and
- to 0 if you don't. */
-#define HAVE_DECL_PROGRAM_INVOCATION_NAME 1
-
-/* Define to 1 if you have the declaration of `program_invocation_short_name',
- and to 0 if you don't. */
-#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 1
+/* Define to 1 if you have the declaration of `program_invocation_name', and
+ to 0 if you don't. */
+#define HAVE_DECL_PROGRAM_INVOCATION_NAME 1
+
+/* Define to 1 if you have the declaration of `program_invocation_short_name',
+ and to 0 if you don't. */
+#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 1
#else
/* Define to 1 if you have the declaration of `program_invocation_name', and
to 0 if you don't. */
#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
-
+
/* Define to 1 if you have the declaration of `program_invocation_short_name',
and to 0 if you don't. */
#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 0
#endif
-/* Define to 1 if you have the declaration of `putchar_unlocked', and to 0 if
- you don't. */
+/* Define to 1 if you have the declaration of `putchar_unlocked', and to 0 if
+ you don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_PUTCHAR_UNLOCKED 1
#else
#define HAVE_DECL_PUTCHAR_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `putc_unlocked', and to 0 if you
- don't. */
+
+/* Define to 1 if you have the declaration of `putc_unlocked', and to 0 if you
+ don't. */
#if HAVE_UNLOCKED_IO
#define HAVE_DECL_PUTC_UNLOCKED 1
#else
#define HAVE_DECL_PUTC_UNLOCKED 0
#endif
-
-/* Define to 1 if you have the declaration of `setenv', and to 0 if you don't.
- */
-#define HAVE_DECL_SETENV 1
-
-/* Define to 1 if you have the declaration of `sigaltstack', and to 0 if you
- don't. */
-#define HAVE_DECL_SIGALTSTACK 1
-
-/* Define to 1 if you have the declaration of `sleep', and to 0 if you don't.
- */
-#define HAVE_DECL_SLEEP 1
-
-/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
- don't. */
-#define HAVE_DECL_SNPRINTF 1
-
-/* Define to 1 if you have the declaration of `strdup', and to 0 if you don't.
- */
-#define HAVE_DECL_STRDUP 1
-
-/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
- don't. */
-#define HAVE_DECL_STRERROR_R 1
-
-/* Define to 1 if you have the declaration of `strndup', and to 0 if you
- don't. */
-#define HAVE_DECL_STRNDUP 1
-
-/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
- don't. */
-#define HAVE_DECL_STRNLEN 1
-
-/* Define to 1 if you have the declaration of `strsignal', and to 0 if you
- don't. */
-#define HAVE_DECL_STRSIGNAL 1
-
-/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
- don't. */
+
+/* Define to 1 if you have the declaration of `setenv', and to 0 if you don't.
+ */
+#define HAVE_DECL_SETENV 1
+
+/* Define to 1 if you have the declaration of `sigaltstack', and to 0 if you
+ don't. */
+#define HAVE_DECL_SIGALTSTACK 1
+
+/* Define to 1 if you have the declaration of `sleep', and to 0 if you don't.
+ */
+#define HAVE_DECL_SLEEP 1
+
+/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
+ don't. */
+#define HAVE_DECL_SNPRINTF 1
+
+/* Define to 1 if you have the declaration of `strdup', and to 0 if you don't.
+ */
+#define HAVE_DECL_STRDUP 1
+
+/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRERROR_R 1
+
+/* Define to 1 if you have the declaration of `strndup', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNDUP 1
+
+/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNLEN 1
+
+/* Define to 1 if you have the declaration of `strsignal', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRSIGNAL 1
+
+/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
+ don't. */
#if defined(_musl_)
#define HAVE_DECL_SYS_SIGLIST 0
#else
#define HAVE_DECL_SYS_SIGLIST 1
#endif
-
-/* Define to 1 if you have the declaration of `towlower', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_TOWLOWER */
-
-/* Define to 1 if you have the declaration of `unsetenv', and to 0 if you
- don't. */
-#define HAVE_DECL_UNSETENV 1
-
-/* Define to 1 if you have the declaration of `wcrtomb', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_WCRTOMB */
-
-/* Define to 1 if you have the declaration of `wctob', and to 0 if you don't.
- */
-#define HAVE_DECL_WCTOB 1
-
-/* Define to 1 if you have the declaration of `_putenv', and to 0 if you
- don't. */
-/* #undef HAVE_DECL__PUTENV */
-
-/* Define to 1 if you have the declaration of `_snprintf', and to 0 if you
- don't. */
-#define HAVE_DECL__SNPRINTF 0
-
-/* Define to 1 if you have the declaration of `_sys_siglist', and to 0 if you
- don't. */
-/* #undef HAVE_DECL__SYS_SIGLIST */
-
-/* Define to 1 if you have the <dirent.h> header file. */
-#define HAVE_DIRENT_H 1
-
-/* Define to 1 if you have the 'dup2' function. */
-#define HAVE_DUP2 1
-
-/* Define if you have the declaration of environ. */
-#define HAVE_ENVIRON_DECL 1
-
-/* Define to 1 if you have the `fcntl' function. */
-#define HAVE_FCNTL 1
-
-/* Define to 1 if you have the <features.h> header file. */
+
+/* Define to 1 if you have the declaration of `towlower', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_TOWLOWER */
+
+/* Define to 1 if you have the declaration of `unsetenv', and to 0 if you
+ don't. */
+#define HAVE_DECL_UNSETENV 1
+
+/* Define to 1 if you have the declaration of `wcrtomb', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_WCRTOMB */
+
+/* Define to 1 if you have the declaration of `wctob', and to 0 if you don't.
+ */
+#define HAVE_DECL_WCTOB 1
+
+/* Define to 1 if you have the declaration of `_putenv', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL__PUTENV */
+
+/* Define to 1 if you have the declaration of `_snprintf', and to 0 if you
+ don't. */
+#define HAVE_DECL__SNPRINTF 0
+
+/* Define to 1 if you have the declaration of `_sys_siglist', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL__SYS_SIGLIST */
+
+/* Define to 1 if you have the <dirent.h> header file. */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the 'dup2' function. */
+#define HAVE_DUP2 1
+
+/* Define if you have the declaration of environ. */
+#define HAVE_ENVIRON_DECL 1
+
+/* Define to 1 if you have the `fcntl' function. */
+#define HAVE_FCNTL 1
+
+/* Define to 1 if you have the <features.h> header file. */
#if defined(__linux__)
#define HAVE_FEATURES_H 1
#else
#define HAVE_FEATURES_H 0
#endif
-
-/* Define to 1 if you have the `fpurge' function. */
-/* #undef HAVE_FPURGE */
-
-/* Define if the frexpl function is available in libc. */
-#define HAVE_FREXPL_IN_LIBC 1
-
-/* Define if the frexp function is available in libc. */
-#define HAVE_FREXP_IN_LIBC 1
-
-/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
-#define HAVE_FSEEKO 1
-
-/* Define to 1 if you have the `getcwd' function. */
-#define HAVE_GETCWD 1
-
-/* Define to 1 if you have the `getdtablesize' function. */
-#define HAVE_GETDTABLESIZE 1
-
-/* Define to 1 if you have the <getopt.h> header file. */
-#define HAVE_GETOPT_H 1
-
-/* Define to 1 if you have the `getopt_long_only' function. */
-#define HAVE_GETOPT_LONG_ONLY 1
-
-/* Define to 1 if you have the `getpagesize' function. */
-#define HAVE_GETPAGESIZE 1
-
-/* Define to 1 if you have the `gettimeofday' function. */
-#define HAVE_GETTIMEOFDAY 1
-
-/* Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>. */
-#define HAVE_INTMAX_T 1
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#define HAVE_INTTYPES_H 1
-
-/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and
- declares uintmax_t. */
-#define HAVE_INTTYPES_H_WITH_UINTMAX 1
-
-/* Define to 1 if you have the `isblank' function. */
-#define HAVE_ISBLANK 1
-
+
+/* Define to 1 if you have the `fpurge' function. */
+/* #undef HAVE_FPURGE */
+
+/* Define if the frexpl function is available in libc. */
+#define HAVE_FREXPL_IN_LIBC 1
+
+/* Define if the frexp function is available in libc. */
+#define HAVE_FREXP_IN_LIBC 1
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#define HAVE_FSEEKO 1
+
+/* Define to 1 if you have the `getcwd' function. */
+#define HAVE_GETCWD 1
+
+/* Define to 1 if you have the `getdtablesize' function. */
+#define HAVE_GETDTABLESIZE 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#define HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long_only' function. */
+#define HAVE_GETOPT_LONG_ONLY 1
+
+/* Define to 1 if you have the `getpagesize' function. */
+#define HAVE_GETPAGESIZE 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#define HAVE_GETTIMEOFDAY 1
+
+/* Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>. */
+#define HAVE_INTMAX_T 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and
+ declares uintmax_t. */
+#define HAVE_INTTYPES_H_WITH_UINTMAX 1
+
+/* Define to 1 if you have the `isblank' function. */
+#define HAVE_ISBLANK 1
+
#if defined(_musl_)
#define HAVE_ISNAND_IN_LIBC 0
#define HAVE_ISNANF_IN_LIBC 0
#else
-/* Define if the isnan(double) function is available in libc. */
-#define HAVE_ISNAND_IN_LIBC 1
-
-/* Define if the isnan(float) function is available in libc. */
-#define HAVE_ISNANF_IN_LIBC 1
+/* Define if the isnan(double) function is available in libc. */
+#define HAVE_ISNAND_IN_LIBC 1
+
+/* Define if the isnan(float) function is available in libc. */
+#define HAVE_ISNANF_IN_LIBC 1
#endif
-
-/* Define if the isnan(long double) function is available in libc. */
-/* #undef HAVE_ISNANL_IN_LIBC */
-
-/* Define to 1 if you have the `issetugid' function. */
-/* #undef HAVE_ISSETUGID */
-
-/* Define to 1 if you have the `iswcntrl' function. */
-#define HAVE_ISWCNTRL 1
-
-/* Define to 1 if you have the `iswctype' function. */
-#define HAVE_ISWCTYPE 1
-
-/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
-#define HAVE_LANGINFO_CODESET 1
-
-/* Define to 1 if you have the <langinfo.h> header file. */
-#define HAVE_LANGINFO_H 1
-
-/* Define if your <locale.h> file defines LC_MESSAGES. */
-#define HAVE_LC_MESSAGES 1
-
-/* Define if the ldexpl function is available in libc. */
-#define HAVE_LDEXPL_IN_LIBC 1
-
-/* Define if the ldexp function is available in libc. */
-#define HAVE_LDEXP_IN_LIBC 1
-
-/* Define to 1 if you have the <libintl.h> header file. */
-/* #undef HAVE_LIBINTL_H */
-
-/* Define if you have the libsigsegv library. */
-/* #undef HAVE_LIBSIGSEGV */
-
-/* Define to 1 if you have the `link' function. */
-#define HAVE_LINK 1
-
-/* Define to 1 if the system has the type `long long int'. */
-#define HAVE_LONG_LONG_INT 1
-
-/* Define to 1 if you have the `lstat' function. */
-#define HAVE_LSTAT 1
-
-/* Define to 1 if your system has a GNU libc compatible 'malloc' function, and
- to 0 otherwise. */
-#define HAVE_MALLOC_GNU 1
-
-/* Define if the 'malloc' function is POSIX compliant. */
-#define HAVE_MALLOC_POSIX 1
-
-/* Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
- config.h and <sys/mman.h>. */
-#define HAVE_MAP_ANONYMOUS 1
-
-/* Define to 1 if you have the <math.h> header file. */
-#define HAVE_MATH_H 1
-
-/* Define to 1 if you have the `mbrtowc' function. */
-#define HAVE_MBRTOWC 1
-
-/* Define to 1 if you have the `mbsinit' function. */
-#define HAVE_MBSINIT 1
-
-/* Define to 1 if <wchar.h> declares mbstate_t. */
-#define HAVE_MBSTATE_T 1
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the `mempcpy' function. */
+
+/* Define if the isnan(long double) function is available in libc. */
+/* #undef HAVE_ISNANL_IN_LIBC */
+
+/* Define to 1 if you have the `issetugid' function. */
+/* #undef HAVE_ISSETUGID */
+
+/* Define to 1 if you have the `iswcntrl' function. */
+#define HAVE_ISWCNTRL 1
+
+/* Define to 1 if you have the `iswctype' function. */
+#define HAVE_ISWCTYPE 1
+
+/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
+#define HAVE_LANGINFO_CODESET 1
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+#define HAVE_LANGINFO_H 1
+
+/* Define if your <locale.h> file defines LC_MESSAGES. */
+#define HAVE_LC_MESSAGES 1
+
+/* Define if the ldexpl function is available in libc. */
+#define HAVE_LDEXPL_IN_LIBC 1
+
+/* Define if the ldexp function is available in libc. */
+#define HAVE_LDEXP_IN_LIBC 1
+
+/* Define to 1 if you have the <libintl.h> header file. */
+/* #undef HAVE_LIBINTL_H */
+
+/* Define if you have the libsigsegv library. */
+/* #undef HAVE_LIBSIGSEGV */
+
+/* Define to 1 if you have the `link' function. */
+#define HAVE_LINK 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#define HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `lstat' function. */
+#define HAVE_LSTAT 1
+
+/* Define to 1 if your system has a GNU libc compatible 'malloc' function, and
+ to 0 otherwise. */
+#define HAVE_MALLOC_GNU 1
+
+/* Define if the 'malloc' function is POSIX compliant. */
+#define HAVE_MALLOC_POSIX 1
+
+/* Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
+ config.h and <sys/mman.h>. */
+#define HAVE_MAP_ANONYMOUS 1
+
+/* Define to 1 if you have the <math.h> header file. */
+#define HAVE_MATH_H 1
+
+/* Define to 1 if you have the `mbrtowc' function. */
+#define HAVE_MBRTOWC 1
+
+/* Define to 1 if you have the `mbsinit' function. */
+#define HAVE_MBSINIT 1
+
+/* Define to 1 if <wchar.h> declares mbstate_t. */
+#define HAVE_MBSTATE_T 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `mempcpy' function. */
#if defined(__linux__)
-#define HAVE_MEMPCPY 1
+#define HAVE_MEMPCPY 1
#endif
-
-/* Define to 1 if you have the `mkdtemp' function. */
-#define HAVE_MKDTEMP 1
-
-/* Define to 1 if you have the `mkstemp' function. */
-#define HAVE_MKSTEMP 1
-
-/* Define to 1 if you have the `mprotect' function. */
-#define HAVE_MPROTECT 1
-
-/* Define to 1 on MSVC platforms that have the "invalid parameter handler"
- concept. */
-/* #undef HAVE_MSVC_INVALID_PARAMETER_HANDLER */
-
-/* Define to 1 if you have the `newlocale' function. */
-#define HAVE_NEWLOCALE 1
-
-/* Define to 1 if you have the `nl_langinfo' function. */
-#define HAVE_NL_LANGINFO 1
-
-/* Define to 1 if libc includes obstacks. */
+
+/* Define to 1 if you have the `mkdtemp' function. */
+#define HAVE_MKDTEMP 1
+
+/* Define to 1 if you have the `mkstemp' function. */
+#define HAVE_MKSTEMP 1
+
+/* Define to 1 if you have the `mprotect' function. */
+#define HAVE_MPROTECT 1
+
+/* Define to 1 on MSVC platforms that have the "invalid parameter handler"
+ concept. */
+/* #undef HAVE_MSVC_INVALID_PARAMETER_HANDLER */
+
+/* Define to 1 if you have the `newlocale' function. */
+#define HAVE_NEWLOCALE 1
+
+/* Define to 1 if you have the `nl_langinfo' function. */
+#define HAVE_NL_LANGINFO 1
+
+/* Define to 1 if libc includes obstacks. */
#if !defined(_musl_)
-#define HAVE_OBSTACK 1
+#define HAVE_OBSTACK 1
#endif
-
-/* Define to 1 if you have the `opendir' function. */
-#define HAVE_OPENDIR 1
-
-/* Define to 1 if you have the <OS.h> header file. */
-/* #undef HAVE_OS_H */
-
-/* Define to 1 if you have the <paths.h> header file. */
-/* #undef HAVE_PATHS_H */
-
-/* Define to 1 if you have the `pipe' function. */
-#define HAVE_PIPE 1
-
-/* Define to 1 if you have the `pipe2' function. */
-#define HAVE_PIPE2 1
-
-/* Define to 1 if you have the `posix_spawn' function. */
-#define HAVE_POSIX_SPAWN 1
-
-/* Define to 1 if the system has the type `posix_spawnattr_t'. */
-#define HAVE_POSIX_SPAWNATTR_T 1
-
-/* Define to 1 if the system has the type `posix_spawn_file_actions_t'. */
-#define HAVE_POSIX_SPAWN_FILE_ACTIONS_T 1
-
-/* Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE. */
-/* #undef HAVE_PTHREAD_MUTEX_RECURSIVE */
-
-/* Define if the POSIX multithreading library has read/write locks. */
-/* #undef HAVE_PTHREAD_RWLOCK */
-
-/* Define to 1 if you have the `raise' function. */
-#define HAVE_RAISE 1
-
-/* Define to 1 if you have the `rawmemchr' function. */
-#define HAVE_RAWMEMCHR 1
-
-/* Define to 1 if you have the `readdir' function. */
-#define HAVE_READDIR 1
-
-/* Define to 1 if you have the `readlink' function. */
-#define HAVE_READLINK 1
-
-/* Define to 1 if you have the `realpath' function. */
-#define HAVE_REALPATH 1
-
-/* Define to 1 if 'long double' and 'double' have the same representation. */
-/* #undef HAVE_SAME_LONG_DOUBLE_AS_DOUBLE */
-
-/* Define to 1 if you have the <sched.h> header file. */
-#define HAVE_SCHED_H 1
-
-/* Define to 1 if you have the `sched_setparam' function. */
-/* #undef HAVE_SCHED_SETPARAM */
-
-/* Define to 1 if you have the `sched_setscheduler' function. */
-/* #undef HAVE_SCHED_SETSCHEDULER */
-
-/* Define to 1 if you have the <search.h> header file. */
-#define HAVE_SEARCH_H 1
-
-/* Define to 1 if you have the `secure_getenv' function. */
-/* #undef HAVE_SECURE_GETENV */
-
-/* Define to 1 if you have the `setegid' function. */
-/* #undef HAVE_SETEGID */
-
-/* Define to 1 if you have the `setenv' function. */
-#define HAVE_SETENV 1
-
-/* Define to 1 if you have the `seteuid' function. */
-/* #undef HAVE_SETEUID */
-
-/* Define to 1 if you have the `setlocale' function. */
-#define HAVE_SETLOCALE 1
-
-/* Define to 1 if you have the `setrlimit' function. */
-#define HAVE_SETRLIMIT 1
-
-/* Define to 1 if you have the `sigaction' function. */
-#define HAVE_SIGACTION 1
-
-/* Define to 1 if you have the `sigaltstack' function. */
-#define HAVE_SIGALTSTACK 1
-
-/* Define to 1 if the system has the type `siginfo_t'. */
-/* #undef HAVE_SIGINFO_T */
-
-/* Define to 1 if you have the `siginterrupt' function. */
-#define HAVE_SIGINTERRUPT 1
-
-/* Define to 1 if 'sig_atomic_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_SIG_ATOMIC_T */
-
-/* Define to 1 if 'wchar_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_WCHAR_T */
-
-/* Define to 1 if 'wint_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_WINT_T */
-
-/* Define to 1 if the system has the type `sigset_t'. */
-#define HAVE_SIGSET_T 1
-
-/* Define to 1 if the system has the type `sig_atomic_t'. */
-#define HAVE_SIG_ATOMIC_T 1
-
-/* Define to 1 if you have the `sleep' function. */
-#define HAVE_SLEEP 1
-
-/* Define to 1 if you have the `snprintf' function. */
-#define HAVE_SNPRINTF 1
-
-/* Define if the return value of the snprintf function is the number of of
- bytes (excluding the terminating NUL) that would have been produced if the
- buffer had been large enough. */
-#define HAVE_SNPRINTF_RETVAL_C99 1
-
-/* Define to 1 if you have the <spawn.h> header file. */
-#define HAVE_SPAWN_H 1
-
-/* Define to 1 if extending the stack slightly past the limit causes a SIGSEGV
- which can be handled on an alternate stack established with sigaltstack. */
-#define HAVE_STACK_OVERFLOW_HANDLING 1
-
-/* Define to 1 if the system has the type `stack_t'. */
-#define HAVE_STACK_T 1
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#define HAVE_STDINT_H 1
-
-/* Define if <stdint.h> exists, doesn't clash with <sys/types.h>, and declares
- uintmax_t. */
-#define HAVE_STDINT_H_WITH_UINTMAX 1
-
-/* Define to 1 if you have the <stdio_ext.h> header file. */
+
+/* Define to 1 if you have the `opendir' function. */
+#define HAVE_OPENDIR 1
+
+/* Define to 1 if you have the <OS.h> header file. */
+/* #undef HAVE_OS_H */
+
+/* Define to 1 if you have the <paths.h> header file. */
+/* #undef HAVE_PATHS_H */
+
+/* Define to 1 if you have the `pipe' function. */
+#define HAVE_PIPE 1
+
+/* Define to 1 if you have the `pipe2' function. */
+#define HAVE_PIPE2 1
+
+/* Define to 1 if you have the `posix_spawn' function. */
+#define HAVE_POSIX_SPAWN 1
+
+/* Define to 1 if the system has the type `posix_spawnattr_t'. */
+#define HAVE_POSIX_SPAWNATTR_T 1
+
+/* Define to 1 if the system has the type `posix_spawn_file_actions_t'. */
+#define HAVE_POSIX_SPAWN_FILE_ACTIONS_T 1
+
+/* Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE. */
+/* #undef HAVE_PTHREAD_MUTEX_RECURSIVE */
+
+/* Define if the POSIX multithreading library has read/write locks. */
+/* #undef HAVE_PTHREAD_RWLOCK */
+
+/* Define to 1 if you have the `raise' function. */
+#define HAVE_RAISE 1
+
+/* Define to 1 if you have the `rawmemchr' function. */
+#define HAVE_RAWMEMCHR 1
+
+/* Define to 1 if you have the `readdir' function. */
+#define HAVE_READDIR 1
+
+/* Define to 1 if you have the `readlink' function. */
+#define HAVE_READLINK 1
+
+/* Define to 1 if you have the `realpath' function. */
+#define HAVE_REALPATH 1
+
+/* Define to 1 if 'long double' and 'double' have the same representation. */
+/* #undef HAVE_SAME_LONG_DOUBLE_AS_DOUBLE */
+
+/* Define to 1 if you have the <sched.h> header file. */
+#define HAVE_SCHED_H 1
+
+/* Define to 1 if you have the `sched_setparam' function. */
+/* #undef HAVE_SCHED_SETPARAM */
+
+/* Define to 1 if you have the `sched_setscheduler' function. */
+/* #undef HAVE_SCHED_SETSCHEDULER */
+
+/* Define to 1 if you have the <search.h> header file. */
+#define HAVE_SEARCH_H 1
+
+/* Define to 1 if you have the `secure_getenv' function. */
+/* #undef HAVE_SECURE_GETENV */
+
+/* Define to 1 if you have the `setegid' function. */
+/* #undef HAVE_SETEGID */
+
+/* Define to 1 if you have the `setenv' function. */
+#define HAVE_SETENV 1
+
+/* Define to 1 if you have the `seteuid' function. */
+/* #undef HAVE_SETEUID */
+
+/* Define to 1 if you have the `setlocale' function. */
+#define HAVE_SETLOCALE 1
+
+/* Define to 1 if you have the `setrlimit' function. */
+#define HAVE_SETRLIMIT 1
+
+/* Define to 1 if you have the `sigaction' function. */
+#define HAVE_SIGACTION 1
+
+/* Define to 1 if you have the `sigaltstack' function. */
+#define HAVE_SIGALTSTACK 1
+
+/* Define to 1 if the system has the type `siginfo_t'. */
+/* #undef HAVE_SIGINFO_T */
+
+/* Define to 1 if you have the `siginterrupt' function. */
+#define HAVE_SIGINTERRUPT 1
+
+/* Define to 1 if 'sig_atomic_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_SIG_ATOMIC_T */
+
+/* Define to 1 if 'wchar_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_WCHAR_T */
+
+/* Define to 1 if 'wint_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_WINT_T */
+
+/* Define to 1 if the system has the type `sigset_t'. */
+#define HAVE_SIGSET_T 1
+
+/* Define to 1 if the system has the type `sig_atomic_t'. */
+#define HAVE_SIG_ATOMIC_T 1
+
+/* Define to 1 if you have the `sleep' function. */
+#define HAVE_SLEEP 1
+
+/* Define to 1 if you have the `snprintf' function. */
+#define HAVE_SNPRINTF 1
+
+/* Define if the return value of the snprintf function is the number of of
+ bytes (excluding the terminating NUL) that would have been produced if the
+ buffer had been large enough. */
+#define HAVE_SNPRINTF_RETVAL_C99 1
+
+/* Define to 1 if you have the <spawn.h> header file. */
+#define HAVE_SPAWN_H 1
+
+/* Define to 1 if extending the stack slightly past the limit causes a SIGSEGV
+ which can be handled on an alternate stack established with sigaltstack. */
+#define HAVE_STACK_OVERFLOW_HANDLING 1
+
+/* Define to 1 if the system has the type `stack_t'. */
+#define HAVE_STACK_T 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define if <stdint.h> exists, doesn't clash with <sys/types.h>, and declares
+ uintmax_t. */
+#define HAVE_STDINT_H_WITH_UINTMAX 1
+
+/* Define to 1 if you have the <stdio_ext.h> header file. */
#if defined(__FreeBSD__) || defined(__MACH__)
#define HAVE_STDIO_EXT_H 0
#else
-#define HAVE_STDIO_EXT_H 1
+#define HAVE_STDIO_EXT_H 1
#endif
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the `strchrnul' function. */
-#define HAVE_STRCHRNUL 1
-
-/* Define to 1 if you have the `strdup' function. */
-#define HAVE_STRDUP 1
-
-/* Define to 1 if you have the `strerror_r' function. */
-#define HAVE_STRERROR_R 1
-
-/* Define to 1 if you have the <strings.h> header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the <string.h> header file. */
-#define HAVE_STRING_H 1
-
-/* Define to 1 if you have the `strndup' function. */
-#define HAVE_STRNDUP 1
-
-/* Define to 1 if you have the `strnlen' function. */
-#define HAVE_STRNLEN 1
-
-/* Define to 1 if you have the `strsignal' function. */
-#define HAVE_STRSIGNAL 1
-
-/* Define to 1 if `decimal_point' is a member of `struct lconv'. */
-/* #undef HAVE_STRUCT_LCONV_DECIMAL_POINT */
-
-/* Define to 1 if `sa_sigaction' is a member of `struct sigaction'. */
-#define HAVE_STRUCT_SIGACTION_SA_SIGACTION 1
-
-/* Define to 1 if you have the `symlink' function. */
-#define HAVE_SYMLINK 1
-
-/* Define to 1 if you have the <sys/bitypes.h> header file. */
-/* #undef HAVE_SYS_BITYPES_H */
-
-/* Define to 1 if you have the <sys/inttypes.h> header file. */
-/* #undef HAVE_SYS_INTTYPES_H */
-
-/* Define to 1 if you have the <sys/mman.h> header file. */
-#define HAVE_SYS_MMAN_H 1
-
-/* Define to 1 if you have the <sys/param.h> header file. */
-#define HAVE_SYS_PARAM_H 1
-
-/* Define to 1 if you have the <sys/socket.h> header file. */
-#define HAVE_SYS_SOCKET_H 1
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/timeb.h> header file. */
-/* #undef HAVE_SYS_TIMEB_H */
-
-/* Define to 1 if you have the <sys/time.h> header file. */
-#define HAVE_SYS_TIME_H 1
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define to 1 if you have the <sys/wait.h> header file. */
-#define HAVE_SYS_WAIT_H 1
-
-/* Define to 1 if you have the `towlower' function. */
-#define HAVE_TOWLOWER 1
-
-/* Define to 1 if you have the `tsearch' function. */
-#define HAVE_TSEARCH 1
-
-/* Define to 1 if you have the <ucontext.h> header file. */
-#define HAVE_UCONTEXT_H 1
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#define HAVE_UNISTD_H 1
-
-/* Define to 1 if you have the `unsetenv' function. */
-#define HAVE_UNSETENV 1
-
-/* Define to 1 if the system has the type 'unsigned long long int'. */
-#define HAVE_UNSIGNED_LONG_LONG_INT 1
-
-/* Define to 1 if you have the `uselocale' function. */
-#define HAVE_USELOCALE 1
-
-/* Define to 1 if you have the `vasnprintf' function. */
-/* #undef HAVE_VASNPRINTF */
-
-/* Define to 1 if you have the `vasprintf' function. */
-#define HAVE_VASPRINTF 1
-
-/* Define to 1 if you have the `vfork' function. */
-/* #undef HAVE_VFORK */
-
-/* Define to 1 if you have the `waitid' function. */
-#define HAVE_WAITID 1
-
-/* Define to 1 if you have the <wchar.h> header file. */
-#define HAVE_WCHAR_H 1
-
-/* Define if you have the 'wchar_t' type. */
-#define HAVE_WCHAR_T 1
-
-/* Define to 1 if you have the `wcrtomb' function. */
-#define HAVE_WCRTOMB 1
-
-/* Define to 1 if you have the `wcscoll' function. */
-#define HAVE_WCSCOLL 1
-
-/* Define to 1 if you have the `wcslen' function. */
-#define HAVE_WCSLEN 1
-
-/* Define to 1 if you have the `wcsnlen' function. */
-#define HAVE_WCSNLEN 1
-
-/* Define to 1 if you have the `wctob' function. */
-#define HAVE_WCTOB 1
-
-/* Define to 1 if you have the <wctype.h> header file. */
-#define HAVE_WCTYPE_H 1
-
-/* Define to 1 if you have the <winsock2.h> header file. */
-/* #undef HAVE_WINSOCK2_H */
-
-/* Define if you have the 'wint_t' type. */
-#define HAVE_WINT_T 1
-
-/* Define to 1 if O_NOATIME works. */
-#define HAVE_WORKING_O_NOATIME 1
-
-/* Define to 1 if O_NOFOLLOW works. */
-#define HAVE_WORKING_O_NOFOLLOW 1
-
-/* Define if you have the posix_spawn and posix_spawnp functions and they
- work. */
-#define HAVE_WORKING_POSIX_SPAWN 1
-
-/* Define to 1 if you have the <xlocale.h> header file. */
-#define HAVE_XLOCALE_H 1
-
-/* Define to 1 if the system has the type `clock_t'. */
-#define HAVE_CLOCK_T 1
-
-/* Define to 1 if extending the stack slightly past the limit causes a
- SIGSEGV, and an alternate stack can be established with sigaltstack, and
- the signal handler is passed a context that specifies the run time stack.
- This behavior is defined by POSIX 1003.1-2001 with the X/Open System
- Interface (XSI) option and is a standardized way to implement a SEGV-based
- stack overflow detection heuristic. */
-/* #undef HAVE_XSI_STACK_OVERFLOW_HEURISTIC */
-
-/* Define to 1 if the system has the type `_Bool'. */
-#define HAVE__BOOL 1
-
-/* Define to 1 if you have the `_fseeki64' function. */
-/* #undef HAVE__FSEEKI64 */
-
-/* Define to 1 if you have the `_ftelli64' function. */
-/* #undef HAVE__FTELLI64 */
-
-/* Define to 1 if you have the `_ftime' function. */
-/* #undef HAVE__FTIME */
-
-/* Define to 1 if you have the `_set_invalid_parameter_handler' function. */
-/* #undef HAVE__SET_INVALID_PARAMETER_HANDLER */
-
-/* Define to 1 if you have the `__fpurge' function. */
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strchrnul' function. */
+#define HAVE_STRCHRNUL 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+#define HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strndup' function. */
+#define HAVE_STRNDUP 1
+
+/* Define to 1 if you have the `strnlen' function. */
+#define HAVE_STRNLEN 1
+
+/* Define to 1 if you have the `strsignal' function. */
+#define HAVE_STRSIGNAL 1
+
+/* Define to 1 if `decimal_point' is a member of `struct lconv'. */
+/* #undef HAVE_STRUCT_LCONV_DECIMAL_POINT */
+
+/* Define to 1 if `sa_sigaction' is a member of `struct sigaction'. */
+#define HAVE_STRUCT_SIGACTION_SA_SIGACTION 1
+
+/* Define to 1 if you have the `symlink' function. */
+#define HAVE_SYMLINK 1
+
+/* Define to 1 if you have the <sys/bitypes.h> header file. */
+/* #undef HAVE_SYS_BITYPES_H */
+
+/* Define to 1 if you have the <sys/inttypes.h> header file. */
+/* #undef HAVE_SYS_INTTYPES_H */
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#define HAVE_SYS_MMAN_H 1
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/timeb.h> header file. */
+/* #undef HAVE_SYS_TIMEB_H */
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/wait.h> header file. */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if you have the `towlower' function. */
+#define HAVE_TOWLOWER 1
+
+/* Define to 1 if you have the `tsearch' function. */
+#define HAVE_TSEARCH 1
+
+/* Define to 1 if you have the <ucontext.h> header file. */
+#define HAVE_UCONTEXT_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the `unsetenv' function. */
+#define HAVE_UNSETENV 1
+
+/* Define to 1 if the system has the type 'unsigned long long int'. */
+#define HAVE_UNSIGNED_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `uselocale' function. */
+#define HAVE_USELOCALE 1
+
+/* Define to 1 if you have the `vasnprintf' function. */
+/* #undef HAVE_VASNPRINTF */
+
+/* Define to 1 if you have the `vasprintf' function. */
+#define HAVE_VASPRINTF 1
+
+/* Define to 1 if you have the `vfork' function. */
+/* #undef HAVE_VFORK */
+
+/* Define to 1 if you have the `waitid' function. */
+#define HAVE_WAITID 1
+
+/* Define to 1 if you have the <wchar.h> header file. */
+#define HAVE_WCHAR_H 1
+
+/* Define if you have the 'wchar_t' type. */
+#define HAVE_WCHAR_T 1
+
+/* Define to 1 if you have the `wcrtomb' function. */
+#define HAVE_WCRTOMB 1
+
+/* Define to 1 if you have the `wcscoll' function. */
+#define HAVE_WCSCOLL 1
+
+/* Define to 1 if you have the `wcslen' function. */
+#define HAVE_WCSLEN 1
+
+/* Define to 1 if you have the `wcsnlen' function. */
+#define HAVE_WCSNLEN 1
+
+/* Define to 1 if you have the `wctob' function. */
+#define HAVE_WCTOB 1
+
+/* Define to 1 if you have the <wctype.h> header file. */
+#define HAVE_WCTYPE_H 1
+
+/* Define to 1 if you have the <winsock2.h> header file. */
+/* #undef HAVE_WINSOCK2_H */
+
+/* Define if you have the 'wint_t' type. */
+#define HAVE_WINT_T 1
+
+/* Define to 1 if O_NOATIME works. */
+#define HAVE_WORKING_O_NOATIME 1
+
+/* Define to 1 if O_NOFOLLOW works. */
+#define HAVE_WORKING_O_NOFOLLOW 1
+
+/* Define if you have the posix_spawn and posix_spawnp functions and they
+ work. */
+#define HAVE_WORKING_POSIX_SPAWN 1
+
+/* Define to 1 if you have the <xlocale.h> header file. */
+#define HAVE_XLOCALE_H 1
+
+/* Define to 1 if the system has the type `clock_t'. */
+#define HAVE_CLOCK_T 1
+
+/* Define to 1 if extending the stack slightly past the limit causes a
+ SIGSEGV, and an alternate stack can be established with sigaltstack, and
+ the signal handler is passed a context that specifies the run time stack.
+ This behavior is defined by POSIX 1003.1-2001 with the X/Open System
+ Interface (XSI) option and is a standardized way to implement a SEGV-based
+ stack overflow detection heuristic. */
+/* #undef HAVE_XSI_STACK_OVERFLOW_HEURISTIC */
+
+/* Define to 1 if the system has the type `_Bool'. */
+#define HAVE__BOOL 1
+
+/* Define to 1 if you have the `_fseeki64' function. */
+/* #undef HAVE__FSEEKI64 */
+
+/* Define to 1 if you have the `_ftelli64' function. */
+/* #undef HAVE__FTELLI64 */
+
+/* Define to 1 if you have the `_ftime' function. */
+/* #undef HAVE__FTIME */
+
+/* Define to 1 if you have the `_set_invalid_parameter_handler' function. */
+/* #undef HAVE__SET_INVALID_PARAMETER_HANDLER */
+
+/* Define to 1 if you have the `__fpurge' function. */
#if HAVE_STDIO_EXT_H
#define HAVE___FPURGE 1
#else
#define HAVE___FPURGE 0
#endif
-
+
#if defined(_musl_)
/* Define to 1 if you have the `__freadahead' function. */
#define HAVE___FREADAHEAD 1
#endif
-
-/* Define to 1 if you have the `__freading' function. */
+
+/* Define to 1 if you have the `__freading' function. */
#if HAVE_STDIO_EXT_H
#define HAVE___FREADING 1
#else
#define HAVE___FREADING 0
#endif
-
-/* Define to 1 if you have the `__secure_getenv' function. */
+
+/* Define to 1 if you have the `__secure_getenv' function. */
//#define HAVE___SECURE_GETENV 1
-
-/* Define as the bit index in the word where to find bit 0 of the exponent of
- 'long double'. */
-#define LDBL_EXPBIT0_BIT 0
-
-/* Define as the word index where to find the exponent of 'long double'. */
-#define LDBL_EXPBIT0_WORD 2
-
-/* Define as the bit index in the word where to find the sign of 'long
- double'. */
-/* #undef LDBL_SIGNBIT_BIT */
-
-/* Define as the word index where to find the sign of 'long double'. */
-/* #undef LDBL_SIGNBIT_WORD */
-
-/* Define to 1 if lseek does not detect pipes. */
-/* #undef LSEEK_PIPE_BROKEN */
-
-/* Define to 1 if 'lstat' dereferences a symlink specified with a trailing
- slash. */
-#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
-
-/* If malloc(0) is != NULL, define this to 1. Otherwise define this to 0. */
-#define MALLOC_0_IS_NONNULL 1
-
-/* Define to a substitute value for mmap()'s MAP_ANONYMOUS flag. */
-/* #undef MAP_ANONYMOUS */
-
-/* Define if the mbrtowc function has the NULL pwc argument bug. */
-/* #undef MBRTOWC_NULL_ARG1_BUG */
-
-/* Define if the mbrtowc function has the NULL string argument bug. */
-/* #undef MBRTOWC_NULL_ARG2_BUG */
-
-/* Define if the mbrtowc function does not return 0 for a NUL character. */
-/* #undef MBRTOWC_NUL_RETVAL_BUG */
-
-/* Define if the mbrtowc function returns a wrong return value. */
-/* #undef MBRTOWC_RETVAL_BUG */
-
-/* Define to 1 if assertions should be disabled. */
-/* #undef NDEBUG */
-
-/* Define if the vasnprintf implementation needs special code for the 'a' and
- 'A' directives. */
-/* #undef NEED_PRINTF_DIRECTIVE_A */
-
-/* Define if the vasnprintf implementation needs special code for the 'F'
- directive. */
-/* #undef NEED_PRINTF_DIRECTIVE_F */
-
-/* Define if the vasnprintf implementation needs special code for the 'ls'
- directive. */
-/* #undef NEED_PRINTF_DIRECTIVE_LS */
-
-/* Define if the vasnprintf implementation needs special code for 'double'
- arguments. */
-/* #undef NEED_PRINTF_DOUBLE */
-
-/* Define if the vasnprintf implementation needs special code for surviving
- out-of-memory conditions. */
-/* #undef NEED_PRINTF_ENOMEM */
-
-/* Define if the vasnprintf implementation needs special code for the ' flag.
- */
-/* #undef NEED_PRINTF_FLAG_GROUPING */
-
-/* Define if the vasnprintf implementation needs special code for the '-'
- flag. */
-/* #undef NEED_PRINTF_FLAG_LEFTADJUST */
-
-/* Define if the vasnprintf implementation needs special code for the 0 flag.
- */
-/* #undef NEED_PRINTF_FLAG_ZERO */
-
-/* Define if the vasnprintf implementation needs special code for infinite
- 'double' arguments. */
-/* #undef NEED_PRINTF_INFINITE_DOUBLE */
-
-/* Define if the vasnprintf implementation needs special code for infinite
- 'long double' arguments. */
-#define NEED_PRINTF_INFINITE_LONG_DOUBLE 1
-
-/* Define if the vasnprintf implementation needs special code for 'long
- double' arguments. */
-/* #undef NEED_PRINTF_LONG_DOUBLE */
-
-/* Define if the vasnprintf implementation needs special code for supporting
- large precisions without arbitrary bounds. */
-/* #undef NEED_PRINTF_UNBOUNDED_PRECISION */
-
-/* Define to 1 if open() fails to recognize a trailing slash. */
-/* #undef OPEN_TRAILING_SLASH_BUG */
-
-/* Name of package */
-#define PACKAGE "m4"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "bug-m4@gnu.org"
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME "GNU M4"
-
-/* String identifying the packager of this software */
-/* #undef PACKAGE_PACKAGER */
-
-/* Packager info for bug reports (URL/e-mail/...) */
-/* #undef PACKAGE_PACKAGER_BUG_REPORTS */
-
-/* Packager-specific version information */
-/* #undef PACKAGE_PACKAGER_VERSION */
-
-/* Define to the full name and version of this package. */
+
+/* Define as the bit index in the word where to find bit 0 of the exponent of
+ 'long double'. */
+#define LDBL_EXPBIT0_BIT 0
+
+/* Define as the word index where to find the exponent of 'long double'. */
+#define LDBL_EXPBIT0_WORD 2
+
+/* Define as the bit index in the word where to find the sign of 'long
+ double'. */
+/* #undef LDBL_SIGNBIT_BIT */
+
+/* Define as the word index where to find the sign of 'long double'. */
+/* #undef LDBL_SIGNBIT_WORD */
+
+/* Define to 1 if lseek does not detect pipes. */
+/* #undef LSEEK_PIPE_BROKEN */
+
+/* Define to 1 if 'lstat' dereferences a symlink specified with a trailing
+ slash. */
+#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
+
+/* If malloc(0) is != NULL, define this to 1. Otherwise define this to 0. */
+#define MALLOC_0_IS_NONNULL 1
+
+/* Define to a substitute value for mmap()'s MAP_ANONYMOUS flag. */
+/* #undef MAP_ANONYMOUS */
+
+/* Define if the mbrtowc function has the NULL pwc argument bug. */
+/* #undef MBRTOWC_NULL_ARG1_BUG */
+
+/* Define if the mbrtowc function has the NULL string argument bug. */
+/* #undef MBRTOWC_NULL_ARG2_BUG */
+
+/* Define if the mbrtowc function does not return 0 for a NUL character. */
+/* #undef MBRTOWC_NUL_RETVAL_BUG */
+
+/* Define if the mbrtowc function returns a wrong return value. */
+/* #undef MBRTOWC_RETVAL_BUG */
+
+/* Define to 1 if assertions should be disabled. */
+/* #undef NDEBUG */
+
+/* Define if the vasnprintf implementation needs special code for the 'a' and
+ 'A' directives. */
+/* #undef NEED_PRINTF_DIRECTIVE_A */
+
+/* Define if the vasnprintf implementation needs special code for the 'F'
+ directive. */
+/* #undef NEED_PRINTF_DIRECTIVE_F */
+
+/* Define if the vasnprintf implementation needs special code for the 'ls'
+ directive. */
+/* #undef NEED_PRINTF_DIRECTIVE_LS */
+
+/* Define if the vasnprintf implementation needs special code for 'double'
+ arguments. */
+/* #undef NEED_PRINTF_DOUBLE */
+
+/* Define if the vasnprintf implementation needs special code for surviving
+ out-of-memory conditions. */
+/* #undef NEED_PRINTF_ENOMEM */
+
+/* Define if the vasnprintf implementation needs special code for the ' flag.
+ */
+/* #undef NEED_PRINTF_FLAG_GROUPING */
+
+/* Define if the vasnprintf implementation needs special code for the '-'
+ flag. */
+/* #undef NEED_PRINTF_FLAG_LEFTADJUST */
+
+/* Define if the vasnprintf implementation needs special code for the 0 flag.
+ */
+/* #undef NEED_PRINTF_FLAG_ZERO */
+
+/* Define if the vasnprintf implementation needs special code for infinite
+ 'double' arguments. */
+/* #undef NEED_PRINTF_INFINITE_DOUBLE */
+
+/* Define if the vasnprintf implementation needs special code for infinite
+ 'long double' arguments. */
+#define NEED_PRINTF_INFINITE_LONG_DOUBLE 1
+
+/* Define if the vasnprintf implementation needs special code for 'long
+ double' arguments. */
+/* #undef NEED_PRINTF_LONG_DOUBLE */
+
+/* Define if the vasnprintf implementation needs special code for supporting
+ large precisions without arbitrary bounds. */
+/* #undef NEED_PRINTF_UNBOUNDED_PRECISION */
+
+/* Define to 1 if open() fails to recognize a trailing slash. */
+/* #undef OPEN_TRAILING_SLASH_BUG */
+
+/* Name of package */
+#define PACKAGE "m4"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "bug-m4@gnu.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "GNU M4"
+
+/* String identifying the packager of this software */
+/* #undef PACKAGE_PACKAGER */
+
+/* Packager info for bug reports (URL/e-mail/...) */
+/* #undef PACKAGE_PACKAGER_BUG_REPORTS */
+
+/* Packager-specific version information */
+/* #undef PACKAGE_PACKAGER_VERSION */
+
+/* Define to the full name and version of this package. */
#define PACKAGE_STRING "GNU M4 3.0.0"
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME "m4"
-
-/* Define to the home page for this package. */
-#define PACKAGE_URL "http://www.gnu.org/software/m4/"
-
-/* Define to the version of this package. */
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "m4"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "http://www.gnu.org/software/m4/"
+
+/* Define to the version of this package. */
#define PACKAGE_VERSION "3.0.0"
-
-/* the number of pending output bytes on stream 'fp' */
-/* #undef PENDING_OUTPUT_N_BYTES */
-
-/* Define if <inttypes.h> exists and defines unusable PRI* macros. */
-/* #undef PRI_MACROS_BROKEN */
-
-/* Define to the type that is the result of default argument promotions of
- type mode_t. */
-#define PROMOTED_MODE_T mode_t
-
-/* Define if the pthread_in_use() detection is hard. */
-/* #undef PTHREAD_IN_USE_DETECTION_HARD */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'ptrdiff_t'. */
-/* #undef PTRDIFF_T_SUFFIX */
-
-/* Define to 1 if readlink fails to recognize a trailing slash. */
-/* #undef READLINK_TRAILING_SLASH_BUG */
-
-/* Define if rename does not work when the destination file exists, as on
- Cygwin 1.5 or Windows. */
-/* #undef RENAME_DEST_EXISTS_BUG */
-
-/* Define if rename fails to leave hard links alone, as on NetBSD 1.6 or
- Cygwin 1.5. */
-/* #undef RENAME_HARD_LINK_BUG */
-
-/* Define to 1 if a file can be renamed while open, or to 0 if not. */
-#define RENAME_OPEN_FILE_WORKS 1
-
-/* Define if rename does not correctly handle slashes on the destination
- argument, such as on Solaris 10 or NetBSD 1.6. */
-/* #undef RENAME_TRAILING_SLASH_DEST_BUG */
-
-/* Define if rename does not correctly handle slashes on the source argument,
- such as on Solaris 9 or cygwin 1.5. */
-/* #undef RENAME_TRAILING_SLASH_SOURCE_BUG */
-
-/* Define to 1 if stat needs help when passed a directory name with a trailing
- slash */
-/* #undef REPLACE_FUNC_STAT_DIR */
-
-/* Define to 1 if stat needs help when passed a file name with a trailing
- slash */
-/* #undef REPLACE_FUNC_STAT_FILE */
-
-/* Define if nl_langinfo exists but is overridden by gnulib. */
-/* #undef REPLACE_NL_LANGINFO */
-
-/* Define to 1 if strerror(0) does not return a message implying success. */
-/* #undef REPLACE_STRERROR_0 */
-
-/* Define if vasnprintf exists but is overridden by gnulib. */
-/* #undef REPLACE_VASNPRINTF */
-
-/* Define if sigaltstack() interprets the stack_t.ss_sp field incorrectly, as
- the highest address of the alternate stack range rather than as the lowest
- address. */
-/* #undef SIGALTSTACK_SS_REVERSED */
-
-/* Define if lists must be signal-safe. */
-#define SIGNAL_SAFE_LIST 1
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'sig_atomic_t'. */
-/* #undef SIG_ATOMIC_T_SUFFIX */
-
-/* Define as the maximum value of type 'size_t', if the system doesn't define
- it. */
-#ifndef SIZE_MAX
-/* # undef SIZE_MAX */
-#endif
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'size_t'. */
-/* #undef SIZE_T_SUFFIX */
-
-/* If using the C implementation of alloca, define if you know the
- direction of stack growth for your system; otherwise it will be
- automatically deduced at runtime.
- STACK_DIRECTION > 0 => grows toward higher addresses
- STACK_DIRECTION < 0 => grows toward lower addresses
- STACK_DIRECTION = 0 => direction of growth unknown */
-/* #undef STACK_DIRECTION */
-
-/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
-/* #undef STAT_MACROS_BROKEN */
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Define to 1 if strerror_r returns char *. */
-#define STRERROR_R_CHAR_P 1
-
-/* Shell used by syscmd and esyscmd, must accept -c argument. */
-#define SYSCMD_SHELL "/bin/sh"
-
-/* Define to the prefix of C symbols at the assembler and linker level, either
- an underscore or empty. */
+
+/* the number of pending output bytes on stream 'fp' */
+/* #undef PENDING_OUTPUT_N_BYTES */
+
+/* Define if <inttypes.h> exists and defines unusable PRI* macros. */
+/* #undef PRI_MACROS_BROKEN */
+
+/* Define to the type that is the result of default argument promotions of
+ type mode_t. */
+#define PROMOTED_MODE_T mode_t
+
+/* Define if the pthread_in_use() detection is hard. */
+/* #undef PTHREAD_IN_USE_DETECTION_HARD */
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'ptrdiff_t'. */
+/* #undef PTRDIFF_T_SUFFIX */
+
+/* Define to 1 if readlink fails to recognize a trailing slash. */
+/* #undef READLINK_TRAILING_SLASH_BUG */
+
+/* Define if rename does not work when the destination file exists, as on
+ Cygwin 1.5 or Windows. */
+/* #undef RENAME_DEST_EXISTS_BUG */
+
+/* Define if rename fails to leave hard links alone, as on NetBSD 1.6 or
+ Cygwin 1.5. */
+/* #undef RENAME_HARD_LINK_BUG */
+
+/* Define to 1 if a file can be renamed while open, or to 0 if not. */
+#define RENAME_OPEN_FILE_WORKS 1
+
+/* Define if rename does not correctly handle slashes on the destination
+ argument, such as on Solaris 10 or NetBSD 1.6. */
+/* #undef RENAME_TRAILING_SLASH_DEST_BUG */
+
+/* Define if rename does not correctly handle slashes on the source argument,
+ such as on Solaris 9 or cygwin 1.5. */
+/* #undef RENAME_TRAILING_SLASH_SOURCE_BUG */
+
+/* Define to 1 if stat needs help when passed a directory name with a trailing
+ slash */
+/* #undef REPLACE_FUNC_STAT_DIR */
+
+/* Define to 1 if stat needs help when passed a file name with a trailing
+ slash */
+/* #undef REPLACE_FUNC_STAT_FILE */
+
+/* Define if nl_langinfo exists but is overridden by gnulib. */
+/* #undef REPLACE_NL_LANGINFO */
+
+/* Define to 1 if strerror(0) does not return a message implying success. */
+/* #undef REPLACE_STRERROR_0 */
+
+/* Define if vasnprintf exists but is overridden by gnulib. */
+/* #undef REPLACE_VASNPRINTF */
+
+/* Define if sigaltstack() interprets the stack_t.ss_sp field incorrectly, as
+ the highest address of the alternate stack range rather than as the lowest
+ address. */
+/* #undef SIGALTSTACK_SS_REVERSED */
+
+/* Define if lists must be signal-safe. */
+#define SIGNAL_SAFE_LIST 1
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'sig_atomic_t'. */
+/* #undef SIG_ATOMIC_T_SUFFIX */
+
+/* Define as the maximum value of type 'size_t', if the system doesn't define
+ it. */
+#ifndef SIZE_MAX
+/* # undef SIZE_MAX */
+#endif
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'size_t'. */
+/* #undef SIZE_T_SUFFIX */
+
+/* If using the C implementation of alloca, define if you know the
+ direction of stack growth for your system; otherwise it will be
+ automatically deduced at runtime.
+ STACK_DIRECTION > 0 => grows toward higher addresses
+ STACK_DIRECTION < 0 => grows toward lower addresses
+ STACK_DIRECTION = 0 => direction of growth unknown */
+/* #undef STACK_DIRECTION */
+
+/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
+/* #undef STAT_MACROS_BROKEN */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if strerror_r returns char *. */
+#define STRERROR_R_CHAR_P 1
+
+/* Shell used by syscmd and esyscmd, must accept -c argument. */
+#define SYSCMD_SHELL "/bin/sh"
+
+/* Define to the prefix of C symbols at the assembler and linker level, either
+ an underscore or empty. */
#define USER_LABEL_PREFIX
-
-/* Define if the POSIX multithreading library can be used. */
-/* #undef USE_POSIX_THREADS */
-
-/* Define if references to the POSIX multithreading library should be made
- weak. */
-/* #undef USE_POSIX_THREADS_WEAK */
-
-/* Define if the GNU Pth multithreading library can be used. */
-/* #undef USE_PTH_THREADS */
-
-/* Define if references to the GNU Pth multithreading library should be made
- weak. */
-/* #undef USE_PTH_THREADS_WEAK */
-
-/* Define if the old Solaris multithreading library can be used. */
-/* #undef USE_SOLARIS_THREADS */
-
-/* Define if references to the old Solaris multithreading library should be
- made weak. */
-/* #undef USE_SOLARIS_THREADS_WEAK */
-
-/* Enable extensions on AIX 3, Interix. */
-#ifndef _ALL_SOURCE
-# define _ALL_SOURCE 1
-#endif
-/* Enable general extensions on OS X. */
-#ifndef _DARWIN_C_SOURCE
-# define _DARWIN_C_SOURCE 1
-#endif
-/* Enable GNU extensions on systems that have them. */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
-/* Enable threading extensions on Solaris. */
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# define _POSIX_PTHREAD_SEMANTICS 1
-#endif
-/* Enable extensions on HP NonStop. */
-#ifndef _TANDEM_SOURCE
-# define _TANDEM_SOURCE 1
-#endif
-/* Enable X/Open extensions if necessary. HP-UX 11.11 defines
- mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of
- whether compiling with -Ae or -D_HPUX_SOURCE=1. */
-#ifndef _XOPEN_SOURCE
-/* # undef _XOPEN_SOURCE */
-#endif
-/* Enable general extensions on Solaris. */
-#ifndef __EXTENSIONS__
-# define __EXTENSIONS__ 1
-#endif
-
-
-/* Define to 1 if you want getc etc. to use unlocked I/O if available.
- Unlocked I/O can improve performance in unithreaded apps, but it is not
- safe for multithreaded apps. */
-#define USE_UNLOCKED_IO 1
-
-/* Define if the native Windows multithreading API can be used. */
-/* #undef USE_WINDOWS_THREADS */
-
-/* Version number of package */
+
+/* Define if the POSIX multithreading library can be used. */
+/* #undef USE_POSIX_THREADS */
+
+/* Define if references to the POSIX multithreading library should be made
+ weak. */
+/* #undef USE_POSIX_THREADS_WEAK */
+
+/* Define if the GNU Pth multithreading library can be used. */
+/* #undef USE_PTH_THREADS */
+
+/* Define if references to the GNU Pth multithreading library should be made
+ weak. */
+/* #undef USE_PTH_THREADS_WEAK */
+
+/* Define if the old Solaris multithreading library can be used. */
+/* #undef USE_SOLARIS_THREADS */
+
+/* Define if references to the old Solaris multithreading library should be
+ made weak. */
+/* #undef USE_SOLARIS_THREADS_WEAK */
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable general extensions on OS X. */
+#ifndef _DARWIN_C_SOURCE
+# define _DARWIN_C_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable X/Open extensions if necessary. HP-UX 11.11 defines
+ mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of
+ whether compiling with -Ae or -D_HPUX_SOURCE=1. */
+#ifndef _XOPEN_SOURCE
+/* # undef _XOPEN_SOURCE */
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+
+
+/* Define to 1 if you want getc etc. to use unlocked I/O if available.
+ Unlocked I/O can improve performance in unithreaded apps, but it is not
+ safe for multithreaded apps. */
+#define USE_UNLOCKED_IO 1
+
+/* Define if the native Windows multithreading API can be used. */
+/* #undef USE_WINDOWS_THREADS */
+
+/* Version number of package */
#define VERSION "3.0.0"
-
-/* Define to 1 if unsetenv returns void instead of int. */
-/* #undef VOID_UNSETENV */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'wchar_t'. */
-/* #undef WCHAR_T_SUFFIX */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'wint_t'. */
-/* #undef WINT_T_SUFFIX */
-
-/* Define to 1 if malloc debugging is enabled */
-/* #undef WITH_DMALLOC */
-
-/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
- significant byte first (like Motorola and SPARC, unlike Intel). */
-#if defined AC_APPLE_UNIVERSAL_BUILD
-# if defined __BIG_ENDIAN__
-# define WORDS_BIGENDIAN 1
-# endif
-#else
-# ifndef WORDS_BIGENDIAN
-/* # undef WORDS_BIGENDIAN */
-# endif
-#endif
-
-/* Enable large inode numbers on Mac OS X 10.5. */
-#define _DARWIN_USE_64_BIT_INODE 1
-
-/* Number of bits in a file offset, on hosts where this is settable. */
-/* #undef _FILE_OFFSET_BITS */
-
-/* Define to 1 if Gnulib overrides 'struct stat' on Windows so that struct
- stat.st_size becomes 64-bit. */
-/* #undef _GL_WINDOWS_64_BIT_ST_SIZE */
-
-/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
-/* #undef _LARGEFILE_SOURCE */
-
-/* Define for large files, on AIX-style hosts. */
-/* #undef _LARGE_FILES */
-
-/* Define to 1 on Solaris. */
-/* #undef _LCONV_C99 */
-
-/* Define to 1 if on MINIX. */
-/* #undef _MINIX */
-
-/* Define to 1 to make NetBSD features available. MINIX 3 needs this. */
-/* #undef _NETBSD_SOURCE */
-
-/* The _Noreturn keyword of C11. */
-#if ! (defined _Noreturn \
- || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
-# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
- || 0x5110 <= __SUNPRO_C)
-# define _Noreturn __attribute__ ((__noreturn__))
-# elif defined _MSC_VER && 1200 <= _MSC_VER
-# define _Noreturn __declspec (noreturn)
-# else
-# define _Noreturn
-# endif
-#endif
-
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
- this defined. */
-/* #undef _POSIX_1_SOURCE */
-
-/* Define to 1 if you need to in order for 'stat' and other things to work. */
-/* #undef _POSIX_SOURCE */
-
-/* Define if you want <regex.h> to include <limits.h>, so that it consistently
- overrides <limits.h>'s RE_DUP_MAX. */
-/* #undef _REGEX_INCLUDE_LIMITS_H */
-
-/* Define if you want regoff_t to be at least as wide POSIX requires. */
-/* #undef _REGEX_LARGE_OFFSETS */
-
-/* Define to rpl_ if the getopt replacement functions and variables should be
- used. */
-#define __GETOPT_PREFIX rpl_
-
-/* Please see the Gnulib manual for how to use these macros.
-
- Suppress extern inline with HP-UX cc, as it appears to be broken; see
- <http://lists.gnu.org/archive/html/bug-texinfo/2013-02/msg00030.html>.
-
- Suppress extern inline with Sun C in standards-conformance mode, as it
- mishandles inline functions that call each other. E.g., for 'inline void f
- (void) { } inline void g (void) { f (); }', c99 incorrectly complains
- 'reference to static identifier "f" in extern inline function'.
- This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16.
-
- Suppress the use of extern inline on problematic Apple configurations, as
- Libc at least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
- <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
- Perhaps Apple will fix this some day. */
-#if (defined __APPLE__ \
- && ((! defined _DONT_USE_CTYPE_INLINE_ \
- && (defined __GNUC__ || defined __cplusplus)) \
- || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
- && defined __GNUC__ && ! defined __cplusplus)))
-# define _GL_EXTERN_INLINE_APPLE_BUG
-#endif
-#if ((__GNUC__ \
- ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
- : (199901L <= __STDC_VERSION__ \
- && !defined __HP_cc \
- && !(defined __SUNPRO_C && __STDC__))) \
- && !defined _GL_EXTERN_INLINE_APPLE_BUG)
-# define _GL_INLINE inline
-# define _GL_EXTERN_INLINE extern inline
-# define _GL_EXTERN_INLINE_IN_USE
-#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
- && !defined _GL_EXTERN_INLINE_APPLE_BUG)
-# if __GNUC_GNU_INLINE__
- /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
-# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
-# else
-# define _GL_INLINE extern inline
-# endif
-# define _GL_EXTERN_INLINE extern
-# define _GL_EXTERN_INLINE_IN_USE
-#else
-# define _GL_INLINE static _GL_UNUSED
-# define _GL_EXTERN_INLINE static _GL_UNUSED
-#endif
-
-#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
-# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
-# define _GL_INLINE_HEADER_CONST_PRAGMA
-# else
-# define _GL_INLINE_HEADER_CONST_PRAGMA \
- _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
-# endif
- /* Suppress GCC's bogus "no previous prototype for 'FOO'"
- and "no previous declaration for 'FOO'" diagnostics,
- when FOO is an inline function in the header; see
- <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113>. */
-# define _GL_INLINE_HEADER_BEGIN \
- _Pragma ("GCC diagnostic push") \
- _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
- _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
- _GL_INLINE_HEADER_CONST_PRAGMA
-# define _GL_INLINE_HEADER_END \
- _Pragma ("GCC diagnostic pop")
-#else
-# define _GL_INLINE_HEADER_BEGIN
-# define _GL_INLINE_HEADER_END
-#endif
-
-/* Define to `int' if <sys/types.h> doesn't define. */
-/* #undef gid_t */
-
-/* A replacement for va_copy, if needed. */
-#define gl_va_copy(a,b) ((a) = (b))
-
-/* Define to rpl_gmtime if the replacement function should be used. */
-/* #undef gmtime */
-
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef __cplusplus
-/* #undef inline */
-#endif
-
-/* Define to long or long long if <stdint.h> and <inttypes.h> don't define. */
-/* #undef intmax_t */
-
-/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
- the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
- earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
- __APPLE__ && __MACH__ test for Mac OS X.
- __APPLE_CC__ tests for the Apple compiler and its version.
- __STDC_VERSION__ tests for the C99 mode. */
-#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
-# define __GNUC_STDC_INLINE__ 1
-#endif
-
-/* Define to rpl_localtime if the replacement function should be used. */
-/* #undef localtime */
-
-/* Define to a type if <wchar.h> does not define. */
-/* #undef mbstate_t */
-
-/* Define to `int' if <sys/types.h> does not define. */
-/* #undef mode_t */
-
-/* Define to the type of st_nlink in struct stat, or a supertype. */
-/* #undef nlink_t */
-
-/* Define to `int' if <sys/types.h> does not define. */
-/* #undef pid_t */
-
-/* Define as the type of the result of subtracting two pointers, if the system
- doesn't define it. */
-/* #undef ptrdiff_t */
-
-/* Define to rpl_re_comp if the replacement should be used. */
-/* #undef re_comp */
-
-/* Define to rpl_re_compile_fastmap if the replacement should be used. */
-/* #undef re_compile_fastmap */
-
-/* Define to rpl_re_compile_pattern if the replacement should be used. */
-/* #undef re_compile_pattern */
-
-/* Define to rpl_re_exec if the replacement should be used. */
-/* #undef re_exec */
-
-/* Define to rpl_re_match if the replacement should be used. */
-/* #undef re_match */
-
-/* Define to rpl_re_match_2 if the replacement should be used. */
-/* #undef re_match_2 */
-
-/* Define to rpl_re_search if the replacement should be used. */
-/* #undef re_search */
-
-/* Define to rpl_re_search_2 if the replacement should be used. */
-/* #undef re_search_2 */
-
-/* Define to rpl_re_set_registers if the replacement should be used. */
-/* #undef re_set_registers */
-
-/* Define to rpl_re_set_syntax if the replacement should be used. */
-/* #undef re_set_syntax */
-
-/* Define to rpl_re_syntax_options if the replacement should be used. */
-/* #undef re_syntax_options */
-
-/* Define to rpl_regcomp if the replacement should be used. */
-/* #undef regcomp */
-
-/* Define to rpl_regerror if the replacement should be used. */
-/* #undef regerror */
-
-/* Define to rpl_regexec if the replacement should be used. */
-/* #undef regexec */
-
-/* Define to rpl_regfree if the replacement should be used. */
-/* #undef regfree */
-
-/* Define to the equivalent of the C99 'restrict' keyword, or to
- nothing if this is not supported. Do not define if restrict is
- supported directly. */
-#define restrict __restrict
-/* Work around a bug in Sun C++: it does not support _Restrict or
- __restrict__, even though the corresponding Sun C compiler ends up with
- "#define restrict _Restrict" or "#define restrict __restrict__" in the
- previous line. Perhaps some future version of Sun C++ will work with
- restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
-#if defined __SUNPRO_CC && !defined __RESTRICT
-# define _Restrict
-# define __restrict__
-#endif
-
-/* Define as an integer type suitable for memory locations that can be
- accessed atomically even in the presence of asynchronous signals. */
-/* #undef sig_atomic_t */
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-/* #undef size_t */
-
-/* Define as a signed type of the same size as size_t. */
-/* #undef ssize_t */
-
-/* Define to `int' if <sys/types.h> doesn't define. */
-/* #undef uid_t */
-
-/* Define as a marker that can be attached to declarations that might not
- be used. This helps to reduce warnings, such as from
- GCC -Wunused-parameter. */
-#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_UNUSED __attribute__ ((__unused__))
-#else
-# define _GL_UNUSED
-#endif
-/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
- is a misnomer outside of parameter lists. */
-#define _UNUSED_PARAMETER_ _GL_UNUSED
-
-/* The __pure__ attribute was added in gcc 2.96. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
-# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
-#else
-# define _GL_ATTRIBUTE_PURE /* empty */
-#endif
-
-/* The __const__ attribute was added in gcc 2.95. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
-#else
-# define _GL_ATTRIBUTE_CONST /* empty */
-#endif
-
-
-/* Define as a macro for copying va_list variables. */
-/* #undef va_copy */
+
+/* Define to 1 if unsetenv returns void instead of int. */
+/* #undef VOID_UNSETENV */
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'wchar_t'. */
+/* #undef WCHAR_T_SUFFIX */
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'wint_t'. */
+/* #undef WINT_T_SUFFIX */
+
+/* Define to 1 if malloc debugging is enabled */
+/* #undef WITH_DMALLOC */
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+ significant byte first (like Motorola and SPARC, unlike Intel). */
+#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+# define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+/* # undef WORDS_BIGENDIAN */
+# endif
+#endif
+
+/* Enable large inode numbers on Mac OS X 10.5. */
+#define _DARWIN_USE_64_BIT_INODE 1
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define to 1 if Gnulib overrides 'struct stat' on Windows so that struct
+ stat.st_size becomes 64-bit. */
+/* #undef _GL_WINDOWS_64_BIT_ST_SIZE */
+
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/* #undef _LARGEFILE_SOURCE */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+/* Define to 1 on Solaris. */
+/* #undef _LCONV_C99 */
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 1 to make NetBSD features available. MINIX 3 needs this. */
+/* #undef _NETBSD_SOURCE */
+
+/* The _Noreturn keyword of C11. */
+#if ! (defined _Noreturn \
+ || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
+# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
+ || 0x5110 <= __SUNPRO_C)
+# define _Noreturn __attribute__ ((__noreturn__))
+# elif defined _MSC_VER && 1200 <= _MSC_VER
+# define _Noreturn __declspec (noreturn)
+# else
+# define _Noreturn
+# endif
+#endif
+
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for 'stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define if you want <regex.h> to include <limits.h>, so that it consistently
+ overrides <limits.h>'s RE_DUP_MAX. */
+/* #undef _REGEX_INCLUDE_LIMITS_H */
+
+/* Define if you want regoff_t to be at least as wide POSIX requires. */
+/* #undef _REGEX_LARGE_OFFSETS */
+
+/* Define to rpl_ if the getopt replacement functions and variables should be
+ used. */
+#define __GETOPT_PREFIX rpl_
+
+/* Please see the Gnulib manual for how to use these macros.
+
+ Suppress extern inline with HP-UX cc, as it appears to be broken; see
+ <http://lists.gnu.org/archive/html/bug-texinfo/2013-02/msg00030.html>.
+
+ Suppress extern inline with Sun C in standards-conformance mode, as it
+ mishandles inline functions that call each other. E.g., for 'inline void f
+ (void) { } inline void g (void) { f (); }', c99 incorrectly complains
+ 'reference to static identifier "f" in extern inline function'.
+ This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16.
+
+ Suppress the use of extern inline on problematic Apple configurations, as
+ Libc at least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
+ <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
+ Perhaps Apple will fix this some day. */
+#if (defined __APPLE__ \
+ && ((! defined _DONT_USE_CTYPE_INLINE_ \
+ && (defined __GNUC__ || defined __cplusplus)) \
+ || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
+ && defined __GNUC__ && ! defined __cplusplus)))
+# define _GL_EXTERN_INLINE_APPLE_BUG
+#endif
+#if ((__GNUC__ \
+ ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
+ : (199901L <= __STDC_VERSION__ \
+ && !defined __HP_cc \
+ && !(defined __SUNPRO_C && __STDC__))) \
+ && !defined _GL_EXTERN_INLINE_APPLE_BUG)
+# define _GL_INLINE inline
+# define _GL_EXTERN_INLINE extern inline
+# define _GL_EXTERN_INLINE_IN_USE
+#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
+ && !defined _GL_EXTERN_INLINE_APPLE_BUG)
+# if __GNUC_GNU_INLINE__
+ /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
+# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
+# else
+# define _GL_INLINE extern inline
+# endif
+# define _GL_EXTERN_INLINE extern
+# define _GL_EXTERN_INLINE_IN_USE
+#else
+# define _GL_INLINE static _GL_UNUSED
+# define _GL_EXTERN_INLINE static _GL_UNUSED
+#endif
+
+#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
+# define _GL_INLINE_HEADER_CONST_PRAGMA
+# else
+# define _GL_INLINE_HEADER_CONST_PRAGMA \
+ _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
+# endif
+ /* Suppress GCC's bogus "no previous prototype for 'FOO'"
+ and "no previous declaration for 'FOO'" diagnostics,
+ when FOO is an inline function in the header; see
+ <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113>. */
+# define _GL_INLINE_HEADER_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
+ _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
+ _GL_INLINE_HEADER_CONST_PRAGMA
+# define _GL_INLINE_HEADER_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define _GL_INLINE_HEADER_BEGIN
+# define _GL_INLINE_HEADER_END
+#endif
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef gid_t */
+
+/* A replacement for va_copy, if needed. */
+#define gl_va_copy(a,b) ((a) = (b))
+
+/* Define to rpl_gmtime if the replacement function should be used. */
+/* #undef gmtime */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to long or long long if <stdint.h> and <inttypes.h> don't define. */
+/* #undef intmax_t */
+
+/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
+ the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
+ earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
+ __APPLE__ && __MACH__ test for Mac OS X.
+ __APPLE_CC__ tests for the Apple compiler and its version.
+ __STDC_VERSION__ tests for the C99 mode. */
+#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
+# define __GNUC_STDC_INLINE__ 1
+#endif
+
+/* Define to rpl_localtime if the replacement function should be used. */
+/* #undef localtime */
+
+/* Define to a type if <wchar.h> does not define. */
+/* #undef mbstate_t */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef mode_t */
+
+/* Define to the type of st_nlink in struct stat, or a supertype. */
+/* #undef nlink_t */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define as the type of the result of subtracting two pointers, if the system
+ doesn't define it. */
+/* #undef ptrdiff_t */
+
+/* Define to rpl_re_comp if the replacement should be used. */
+/* #undef re_comp */
+
+/* Define to rpl_re_compile_fastmap if the replacement should be used. */
+/* #undef re_compile_fastmap */
+
+/* Define to rpl_re_compile_pattern if the replacement should be used. */
+/* #undef re_compile_pattern */
+
+/* Define to rpl_re_exec if the replacement should be used. */
+/* #undef re_exec */
+
+/* Define to rpl_re_match if the replacement should be used. */
+/* #undef re_match */
+
+/* Define to rpl_re_match_2 if the replacement should be used. */
+/* #undef re_match_2 */
+
+/* Define to rpl_re_search if the replacement should be used. */
+/* #undef re_search */
+
+/* Define to rpl_re_search_2 if the replacement should be used. */
+/* #undef re_search_2 */
+
+/* Define to rpl_re_set_registers if the replacement should be used. */
+/* #undef re_set_registers */
+
+/* Define to rpl_re_set_syntax if the replacement should be used. */
+/* #undef re_set_syntax */
+
+/* Define to rpl_re_syntax_options if the replacement should be used. */
+/* #undef re_syntax_options */
+
+/* Define to rpl_regcomp if the replacement should be used. */
+/* #undef regcomp */
+
+/* Define to rpl_regerror if the replacement should be used. */
+/* #undef regerror */
+
+/* Define to rpl_regexec if the replacement should be used. */
+/* #undef regexec */
+
+/* Define to rpl_regfree if the replacement should be used. */
+/* #undef regfree */
+
+/* Define to the equivalent of the C99 'restrict' keyword, or to
+ nothing if this is not supported. Do not define if restrict is
+ supported directly. */
+#define restrict __restrict
+/* Work around a bug in Sun C++: it does not support _Restrict or
+ __restrict__, even though the corresponding Sun C compiler ends up with
+ "#define restrict _Restrict" or "#define restrict __restrict__" in the
+ previous line. Perhaps some future version of Sun C++ will work with
+ restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
+#if defined __SUNPRO_CC && !defined __RESTRICT
+# define _Restrict
+# define __restrict__
+#endif
+
+/* Define as an integer type suitable for memory locations that can be
+ accessed atomically even in the presence of asynchronous signals. */
+/* #undef sig_atomic_t */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define as a signed type of the same size as size_t. */
+/* #undef ssize_t */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef uid_t */
+
+/* Define as a marker that can be attached to declarations that might not
+ be used. This helps to reduce warnings, such as from
+ GCC -Wunused-parameter. */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED __attribute__ ((__unused__))
+#else
+# define _GL_UNUSED
+#endif
+/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
+ is a misnomer outside of parameter lists. */
+#define _UNUSED_PARAMETER_ _GL_UNUSED
+
+/* The __pure__ attribute was added in gcc 2.96. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
+#else
+# define _GL_ATTRIBUTE_PURE /* empty */
+#endif
+
+/* The __const__ attribute was added in gcc 2.95. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
+#else
+# define _GL_ATTRIBUTE_CONST /* empty */
+#endif
+
+
+/* Define as a macro for copying va_list variables. */
+/* #undef va_copy */
diff --git a/contrib/tools/bison/gnulib/platform/posix/configmake.h b/contrib/tools/bison/gnulib/platform/posix/configmake.h
index 75ea1d7d03..ce2d6108c4 100644
--- a/contrib/tools/bison/gnulib/platform/posix/configmake.h
+++ b/contrib/tools/bison/gnulib/platform/posix/configmake.h
@@ -1,3 +1,3 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-
-#define LIBDIR "/usr/local/lib"
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+
+#define LIBDIR "/usr/local/lib"
diff --git a/contrib/tools/bison/gnulib/platform/posix/fcntl.h b/contrib/tools/bison/gnulib/platform/posix/fcntl.h
index a7a7d03b20..23802f3321 100644
--- a/contrib/tools/bison/gnulib/platform/posix/fcntl.h
+++ b/contrib/tools/bison/gnulib/platform/posix/fcntl.h
@@ -1,659 +1,659 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Like <fcntl.h>, but with non-working flags defined to 0.
-
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Paul Eggert */
-
-#if __GNUC__ >= 3
-#pragma GCC system_header
-#endif
-
-
-#if defined __need_system_fcntl_h
-/* Special invocation convention. */
-
-/* Needed before <sys/stat.h>.
- May also define off_t to a 64-bit type on native Windows. */
-#include <sys/types.h>
-/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
- <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
- But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
- extern "C" { ... } block, which leads to errors in C++ mode with the
- overridden <sys/stat.h> from gnulib. These errors are known to be gone
- with g++ version >= 4.3. */
-#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
-# include <sys/stat.h>
-#endif
-#include_next <fcntl.h>
-
-#else
-/* Normal invocation convention. */
-
-#ifndef _GL_M4_FCNTL_H
-
-/* Needed before <sys/stat.h>.
- May also define off_t to a 64-bit type on native Windows. */
-#include <sys/types.h>
-/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
- <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
- But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
- extern "C" { ... } block, which leads to errors in C++ mode with the
- overridden <sys/stat.h> from gnulib. These errors are known to be gone
- with g++ version >= 4.3. */
-#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
-# include <sys/stat.h>
-#endif
-/* The include_next requires a split double-inclusion guard. */
-#include_next <fcntl.h>
-
-#ifndef _GL_M4_FCNTL_H
-#define _GL_M4_FCNTL_H
-
-#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
-# include <unistd.h>
-#endif
-
-/* Native Windows platforms declare open(), creat() in <io.h>. */
-#if (1 || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
-# include <io.h>
-#endif
-
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-
-/* Declare overridden functions. */
-
-#if 1
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fcntl
-# define fcntl rpl_fcntl
-# endif
-_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
-_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
-# else
-# if !1
-_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
-# endif
-_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
-# endif
-_GL_CXXALIASWARN (fcntl);
-#elif defined GNULIB_POSIXCHECK
-# undef fcntl
-# if HAVE_RAW_DECL_FCNTL
-_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
- "use gnulib module fcntl for portability");
-# endif
-#endif
-
-#if 1
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef open
-# define open rpl_open
-# endif
-_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
-# else
-_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
-# endif
-/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
- default argument. _GL_CXXALIASWARN does not work in this case. */
-# if !defined __hpux
-_GL_CXXALIASWARN (open);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef open
-/* Assume open is always declared. */
-_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
- "use gnulib module open for portability");
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef openat
-# define openat rpl_openat
-# endif
-_GL_FUNCDECL_RPL (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...));
-# else
-# if !1
-_GL_FUNCDECL_SYS (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...));
-# endif
-_GL_CXXALIASWARN (openat);
-#elif defined GNULIB_POSIXCHECK
-# undef openat
-# if HAVE_RAW_DECL_OPENAT
-_GL_WARN_ON_USE (openat, "openat is not portable - "
- "use gnulib module openat for portability");
-# endif
-#endif
-
-
-/* Fix up the FD_* macros, only known to be missing on mingw. */
-
-#ifndef FD_CLOEXEC
-# define FD_CLOEXEC 1
-#endif
-
-/* Fix up the supported F_* macros. Intentionally leave other F_*
- macros undefined. Only known to be missing on mingw. */
-
-#ifndef F_DUPFD_CLOEXEC
-# define F_DUPFD_CLOEXEC 0x40000000
-/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
-# define GNULIB_defined_F_DUPFD_CLOEXEC 1
-#else
-# define GNULIB_defined_F_DUPFD_CLOEXEC 0
-#endif
-
-#ifndef F_DUPFD
-# define F_DUPFD 1
-#endif
-
-#ifndef F_GETFD
-# define F_GETFD 2
-#endif
-
-/* Fix up the O_* macros. */
-
-#if !defined O_DIRECT && defined O_DIRECTIO
-/* Tru64 spells it 'O_DIRECTIO'. */
-# define O_DIRECT O_DIRECTIO
-#endif
-
-#if !defined O_CLOEXEC && defined O_NOINHERIT
-/* Mingw spells it 'O_NOINHERIT'. */
-# define O_CLOEXEC O_NOINHERIT
-#endif
-
-#ifndef O_CLOEXEC
-# define O_CLOEXEC 0
-#endif
-
-#ifndef O_DIRECT
-# define O_DIRECT 0
-#endif
-
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-
-#ifndef O_DSYNC
-# define O_DSYNC 0
-#endif
-
-#ifndef O_EXEC
-# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
-#endif
-
-#ifndef O_IGNORE_CTTY
-# define O_IGNORE_CTTY 0
-#endif
-
-#ifndef O_NDELAY
-# define O_NDELAY 0
-#endif
-
-#ifndef O_NOATIME
-# define O_NOATIME 0
-#endif
-
-#ifndef O_NONBLOCK
-# define O_NONBLOCK O_NDELAY
-#endif
-
-/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
- value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
- or to 0 as fallback. */
-#if 0
-# if O_NONBLOCK
-# define GNULIB_defined_O_NONBLOCK 0
-# else
-# define GNULIB_defined_O_NONBLOCK 1
-# undef O_NONBLOCK
-# define O_NONBLOCK 0x40000000
-# endif
-#endif
-
-#ifndef O_NOCTTY
-# define O_NOCTTY 0
-#endif
-
-#ifndef O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
-#ifndef O_NOLINK
-# define O_NOLINK 0
-#endif
-
-#ifndef O_NOLINKS
-# define O_NOLINKS 0
-#endif
-
-#ifndef O_NOTRANS
-# define O_NOTRANS 0
-#endif
-
-#ifndef O_RSYNC
-# define O_RSYNC 0
-#endif
-
-#ifndef O_SEARCH
-# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
-#endif
-
-#ifndef O_SYNC
-# define O_SYNC 0
-#endif
-
-#ifndef O_TTY_INIT
-# define O_TTY_INIT 0
-#endif
-
-#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
-# undef O_ACCMODE
-# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
-#endif
-
-/* For systems that distinguish between text and binary I/O.
- O_BINARY is usually declared in fcntl.h */
-#if !defined O_BINARY && defined _O_BINARY
- /* For MSC-compatible compilers. */
-# define O_BINARY _O_BINARY
-# define O_TEXT _O_TEXT
-#endif
-
-#if defined __BEOS__ || defined __HAIKU__
- /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
-# undef O_BINARY
-# undef O_TEXT
-#endif
-
-#ifndef O_BINARY
-# define O_BINARY 0
-# define O_TEXT 0
-#endif
-
-/* Fix up the AT_* macros. */
-
-/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
- value exceeds INT_MAX, so its use as an int doesn't conform to the
- C standard, and GCC and Sun C complain in some cases. If the bug
- is present, undef AT_FDCWD here, so it can be redefined below. */
-#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
-# undef AT_FDCWD
-#endif
-
-/* Use the same bit pattern as Solaris 9, but with the proper
- signedness. The bit pattern is important, in case this actually is
- Solaris with the above workaround. */
-#ifndef AT_FDCWD
-# define AT_FDCWD (-3041965)
-#endif
-
-/* Use the same values as Solaris 9. This shouldn't matter, but
- there's no real reason to differ. */
-#ifndef AT_SYMLINK_NOFOLLOW
-# define AT_SYMLINK_NOFOLLOW 4096
-#endif
-
-#ifndef AT_REMOVEDIR
-# define AT_REMOVEDIR 1
-#endif
-
-/* Solaris 9 lacks these two, so just pick unique values. */
-#ifndef AT_SYMLINK_FOLLOW
-# define AT_SYMLINK_FOLLOW 2
-#endif
-
-#ifndef AT_EACCESS
-# define AT_EACCESS 4
-#endif
-
-
-#endif /* _GL_M4_FCNTL_H */
-#endif /* _GL_M4_FCNTL_H */
-#endif
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Like <fcntl.h>, but with non-working flags defined to 0.
+
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Paul Eggert */
+
+#if __GNUC__ >= 3
+#pragma GCC system_header
+#endif
+
+
+#if defined __need_system_fcntl_h
+/* Special invocation convention. */
+
+/* Needed before <sys/stat.h>.
+ May also define off_t to a 64-bit type on native Windows. */
+#include <sys/types.h>
+/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
+ <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
+ But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
+ extern "C" { ... } block, which leads to errors in C++ mode with the
+ overridden <sys/stat.h> from gnulib. These errors are known to be gone
+ with g++ version >= 4.3. */
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+# include <sys/stat.h>
+#endif
+#include_next <fcntl.h>
+
+#else
+/* Normal invocation convention. */
+
+#ifndef _GL_M4_FCNTL_H
+
+/* Needed before <sys/stat.h>.
+ May also define off_t to a 64-bit type on native Windows. */
+#include <sys/types.h>
+/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
+ <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
+ But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
+ extern "C" { ... } block, which leads to errors in C++ mode with the
+ overridden <sys/stat.h> from gnulib. These errors are known to be gone
+ with g++ version >= 4.3. */
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+# include <sys/stat.h>
+#endif
+/* The include_next requires a split double-inclusion guard. */
+#include_next <fcntl.h>
+
+#ifndef _GL_M4_FCNTL_H
+#define _GL_M4_FCNTL_H
+
+#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
+# include <unistd.h>
+#endif
+
+/* Native Windows platforms declare open(), creat() in <io.h>. */
+#if (1 || defined GNULIB_POSIXCHECK) \
+ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+# include <io.h>
+#endif
+
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+
+/* Declare overridden functions. */
+
+#if 1
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fcntl
+# define fcntl rpl_fcntl
+# endif
+_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
+_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
+# else
+# if !1
+_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
+# endif
+_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
+# endif
+_GL_CXXALIASWARN (fcntl);
+#elif defined GNULIB_POSIXCHECK
+# undef fcntl
+# if HAVE_RAW_DECL_FCNTL
+_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
+ "use gnulib module fcntl for portability");
+# endif
+#endif
+
+#if 1
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef open
+# define open rpl_open
+# endif
+_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+# else
+_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+# endif
+/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
+ default argument. _GL_CXXALIASWARN does not work in this case. */
+# if !defined __hpux
+_GL_CXXALIASWARN (open);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef open
+/* Assume open is always declared. */
+_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
+ "use gnulib module open for portability");
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef openat
+# define openat rpl_openat
+# endif
+_GL_FUNCDECL_RPL (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...));
+# else
+# if !1
+_GL_FUNCDECL_SYS (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...));
+# endif
+_GL_CXXALIASWARN (openat);
+#elif defined GNULIB_POSIXCHECK
+# undef openat
+# if HAVE_RAW_DECL_OPENAT
+_GL_WARN_ON_USE (openat, "openat is not portable - "
+ "use gnulib module openat for portability");
+# endif
+#endif
+
+
+/* Fix up the FD_* macros, only known to be missing on mingw. */
+
+#ifndef FD_CLOEXEC
+# define FD_CLOEXEC 1
+#endif
+
+/* Fix up the supported F_* macros. Intentionally leave other F_*
+ macros undefined. Only known to be missing on mingw. */
+
+#ifndef F_DUPFD_CLOEXEC
+# define F_DUPFD_CLOEXEC 0x40000000
+/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
+# define GNULIB_defined_F_DUPFD_CLOEXEC 1
+#else
+# define GNULIB_defined_F_DUPFD_CLOEXEC 0
+#endif
+
+#ifndef F_DUPFD
+# define F_DUPFD 1
+#endif
+
+#ifndef F_GETFD
+# define F_GETFD 2
+#endif
+
+/* Fix up the O_* macros. */
+
+#if !defined O_DIRECT && defined O_DIRECTIO
+/* Tru64 spells it 'O_DIRECTIO'. */
+# define O_DIRECT O_DIRECTIO
+#endif
+
+#if !defined O_CLOEXEC && defined O_NOINHERIT
+/* Mingw spells it 'O_NOINHERIT'. */
+# define O_CLOEXEC O_NOINHERIT
+#endif
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
+#ifndef O_DIRECT
+# define O_DIRECT 0
+#endif
+
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
+#ifndef O_DSYNC
+# define O_DSYNC 0
+#endif
+
+#ifndef O_EXEC
+# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
+#endif
+
+#ifndef O_IGNORE_CTTY
+# define O_IGNORE_CTTY 0
+#endif
+
+#ifndef O_NDELAY
+# define O_NDELAY 0
+#endif
+
+#ifndef O_NOATIME
+# define O_NOATIME 0
+#endif
+
+#ifndef O_NONBLOCK
+# define O_NONBLOCK O_NDELAY
+#endif
+
+/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
+ value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
+ or to 0 as fallback. */
+#if 0
+# if O_NONBLOCK
+# define GNULIB_defined_O_NONBLOCK 0
+# else
+# define GNULIB_defined_O_NONBLOCK 1
+# undef O_NONBLOCK
+# define O_NONBLOCK 0x40000000
+# endif
+#endif
+
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
+#ifndef O_NOLINK
+# define O_NOLINK 0
+#endif
+
+#ifndef O_NOLINKS
+# define O_NOLINKS 0
+#endif
+
+#ifndef O_NOTRANS
+# define O_NOTRANS 0
+#endif
+
+#ifndef O_RSYNC
+# define O_RSYNC 0
+#endif
+
+#ifndef O_SEARCH
+# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
+#endif
+
+#ifndef O_SYNC
+# define O_SYNC 0
+#endif
+
+#ifndef O_TTY_INIT
+# define O_TTY_INIT 0
+#endif
+
+#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+# undef O_ACCMODE
+# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+#endif
+
+/* For systems that distinguish between text and binary I/O.
+ O_BINARY is usually declared in fcntl.h */
+#if !defined O_BINARY && defined _O_BINARY
+ /* For MSC-compatible compilers. */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+
+#if defined __BEOS__ || defined __HAIKU__
+ /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+# define O_TEXT 0
+#endif
+
+/* Fix up the AT_* macros. */
+
+/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
+ value exceeds INT_MAX, so its use as an int doesn't conform to the
+ C standard, and GCC and Sun C complain in some cases. If the bug
+ is present, undef AT_FDCWD here, so it can be redefined below. */
+#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
+# undef AT_FDCWD
+#endif
+
+/* Use the same bit pattern as Solaris 9, but with the proper
+ signedness. The bit pattern is important, in case this actually is
+ Solaris with the above workaround. */
+#ifndef AT_FDCWD
+# define AT_FDCWD (-3041965)
+#endif
+
+/* Use the same values as Solaris 9. This shouldn't matter, but
+ there's no real reason to differ. */
+#ifndef AT_SYMLINK_NOFOLLOW
+# define AT_SYMLINK_NOFOLLOW 4096
+#endif
+
+#ifndef AT_REMOVEDIR
+# define AT_REMOVEDIR 1
+#endif
+
+/* Solaris 9 lacks these two, so just pick unique values. */
+#ifndef AT_SYMLINK_FOLLOW
+# define AT_SYMLINK_FOLLOW 2
+#endif
+
+#ifndef AT_EACCESS
+# define AT_EACCESS 4
+#endif
+
+
+#endif /* _GL_M4_FCNTL_H */
+#endif /* _GL_M4_FCNTL_H */
+#endif
diff --git a/contrib/tools/bison/gnulib/platform/posix/getopt.h b/contrib/tools/bison/gnulib/platform/posix/getopt.h
index 2096ceacfe..5ed9237ba9 100644
--- a/contrib/tools/bison/gnulib/platform/posix/getopt.h
+++ b/contrib/tools/bison/gnulib/platform/posix/getopt.h
@@ -1,266 +1,266 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Declarations for getopt.
- Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_M4_GETOPT_H
-
-#if __GNUC__ >= 3
-#pragma GCC system_header
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. We must
- also inform the replacement unistd.h to not recursively use
- <getopt.h>; our definitions will be present soon enough. */
-#if 1
-# define _GL_SYSTEM_GETOPT
-# include_next <getopt.h>
-# undef _GL_SYSTEM_GETOPT
-#endif
-
-#ifndef _GL_M4_GETOPT_H
-
-#ifndef __need_getopt
-# define _GL_M4_GETOPT_H 1
-#endif
-
-/* Standalone applications should #define __GETOPT_PREFIX to an
- identifier that prefixes the external functions and variables
- defined in this header. When this happens, include the
- headers that might declare getopt so that they will not cause
- confusion if included after this file (if the system had <getopt.h>,
- we have already included it). Then systematically rename
- identifiers so that they do not collide with the system functions
- and variables. Renaming avoids problems with some compilers and
- linkers. */
-#if defined __GETOPT_PREFIX && !defined __need_getopt
-# if !1
-# define __need_system_stdlib_h
-# include <stdlib.h>
-# undef __need_system_stdlib_h
-# include <stdio.h>
-# include <unistd.h>
-# endif
-# undef __need_getopt
-# undef getopt
-# undef getopt_long
-# undef getopt_long_only
-# undef optarg
-# undef opterr
-# undef optind
-# undef optopt
-# undef option
-# define __GETOPT_CONCAT(x, y) x ## y
-# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
-# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
-# define getopt __GETOPT_ID (getopt)
-# define getopt_long __GETOPT_ID (getopt_long)
-# define getopt_long_only __GETOPT_ID (getopt_long_only)
-# define optarg __GETOPT_ID (optarg)
-# define opterr __GETOPT_ID (opterr)
-# define optind __GETOPT_ID (optind)
-# define optopt __GETOPT_ID (optopt)
-# define option __GETOPT_ID (option)
-# define _getopt_internal __GETOPT_ID (getopt_internal)
-#endif
-
-/* Standalone applications get correct prototypes for getopt_long and
- getopt_long_only; they declare "char **argv". libc uses prototypes
- with "char *const *argv" that are incorrect because getopt_long and
- getopt_long_only can permute argv; this is required for backward
- compatibility (e.g., for LSB 2.0.1).
-
- This used to be '#if defined __GETOPT_PREFIX && !defined __need_getopt',
- but it caused redefinition warnings if both unistd.h and getopt.h were
- included, since unistd.h includes getopt.h having previously defined
- __need_getopt.
-
- The only place where __getopt_argv_const is used is in definitions
- of getopt_long and getopt_long_only below, but these are visible
- only if __need_getopt is not defined, so it is quite safe to rewrite
- the conditional as follows:
-*/
-#if !defined __need_getopt
-# if defined __GETOPT_PREFIX
-# define __getopt_argv_const /* empty */
-# else
-# define __getopt_argv_const const
-# endif
-#endif
-
-/* If __GNU_LIBRARY__ is not already defined, either we are being used
- standalone, or this is the first header included in the source file.
- If we are being used with glibc, we need to include <features.h>, but
- that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
- not defined, include <ctype.h>, which will pull in <features.h> for us
- if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
- doesn't flood the namespace with stuff the way some other headers do.) */
-#if !defined __GNU_LIBRARY__
-# include <ctype.h>
-#endif
-
-#ifndef __THROW
-# ifndef __GNUC_PREREQ
-# define __GNUC_PREREQ(maj, min) (0)
-# endif
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Declarations for getopt.
+ Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_M4_GETOPT_H
+
+#if __GNUC__ >= 3
+#pragma GCC system_header
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. We must
+ also inform the replacement unistd.h to not recursively use
+ <getopt.h>; our definitions will be present soon enough. */
+#if 1
+# define _GL_SYSTEM_GETOPT
+# include_next <getopt.h>
+# undef _GL_SYSTEM_GETOPT
+#endif
+
+#ifndef _GL_M4_GETOPT_H
+
+#ifndef __need_getopt
+# define _GL_M4_GETOPT_H 1
+#endif
+
+/* Standalone applications should #define __GETOPT_PREFIX to an
+ identifier that prefixes the external functions and variables
+ defined in this header. When this happens, include the
+ headers that might declare getopt so that they will not cause
+ confusion if included after this file (if the system had <getopt.h>,
+ we have already included it). Then systematically rename
+ identifiers so that they do not collide with the system functions
+ and variables. Renaming avoids problems with some compilers and
+ linkers. */
+#if defined __GETOPT_PREFIX && !defined __need_getopt
+# if !1
+# define __need_system_stdlib_h
+# include <stdlib.h>
+# undef __need_system_stdlib_h
+# include <stdio.h>
+# include <unistd.h>
+# endif
+# undef __need_getopt
+# undef getopt
+# undef getopt_long
+# undef getopt_long_only
+# undef optarg
+# undef opterr
+# undef optind
+# undef optopt
+# undef option
+# define __GETOPT_CONCAT(x, y) x ## y
+# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
+# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
+# define getopt __GETOPT_ID (getopt)
+# define getopt_long __GETOPT_ID (getopt_long)
+# define getopt_long_only __GETOPT_ID (getopt_long_only)
+# define optarg __GETOPT_ID (optarg)
+# define opterr __GETOPT_ID (opterr)
+# define optind __GETOPT_ID (optind)
+# define optopt __GETOPT_ID (optopt)
+# define option __GETOPT_ID (option)
+# define _getopt_internal __GETOPT_ID (getopt_internal)
+#endif
+
+/* Standalone applications get correct prototypes for getopt_long and
+ getopt_long_only; they declare "char **argv". libc uses prototypes
+ with "char *const *argv" that are incorrect because getopt_long and
+ getopt_long_only can permute argv; this is required for backward
+ compatibility (e.g., for LSB 2.0.1).
+
+ This used to be '#if defined __GETOPT_PREFIX && !defined __need_getopt',
+ but it caused redefinition warnings if both unistd.h and getopt.h were
+ included, since unistd.h includes getopt.h having previously defined
+ __need_getopt.
+
+ The only place where __getopt_argv_const is used is in definitions
+ of getopt_long and getopt_long_only below, but these are visible
+ only if __need_getopt is not defined, so it is quite safe to rewrite
+ the conditional as follows:
+*/
+#if !defined __need_getopt
+# if defined __GETOPT_PREFIX
+# define __getopt_argv_const /* empty */
+# else
+# define __getopt_argv_const const
+# endif
+#endif
+
+/* If __GNU_LIBRARY__ is not already defined, either we are being used
+ standalone, or this is the first header included in the source file.
+ If we are being used with glibc, we need to include <features.h>, but
+ that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
+ not defined, include <ctype.h>, which will pull in <features.h> for us
+ if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
+ doesn't flood the namespace with stuff the way some other headers do.) */
+#if !defined __GNU_LIBRARY__
+# include <ctype.h>
+#endif
+
+#ifndef __THROW
+# ifndef __GNUC_PREREQ
+# define __GNUC_PREREQ(maj, min) (0)
+# endif
+# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW noexcept
-# else
-# define __THROW
-# endif
-#endif
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* For communication from 'getopt' to the caller.
- When 'getopt' finds an option that takes an argument,
- the argument value is returned here.
- Also, when 'ordering' is RETURN_IN_ORDER,
- each non-option ARGV-element is returned here. */
-
-extern char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
- This is used for communication to and from the caller
- and for communication between successive calls to 'getopt'.
-
- On entry to 'getopt', zero means this is the first call; initialize.
-
- When 'getopt' returns -1, this is the index of the first of the
- non-option elements that the caller should itself scan.
-
- Otherwise, 'optind' communicates from one call to the next
- how much of ARGV has been scanned so far. */
-
-extern int optind;
-
-/* Callers store zero here to inhibit the error message 'getopt' prints
- for unrecognized options. */
-
-extern int opterr;
-
-/* Set to an option character which was unrecognized. */
-
-extern int optopt;
-
-#ifndef __need_getopt
-/* Describe the long-named options requested by the application.
- The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
- of 'struct option' terminated by an element containing a name which is
- zero.
-
- The field 'has_arg' is:
- no_argument (or 0) if the option does not take an argument,
- required_argument (or 1) if the option requires an argument,
- optional_argument (or 2) if the option takes an optional argument.
-
- If the field 'flag' is not NULL, it points to a variable that is set
- to the value given in the field 'val' when the option is found, but
- left unchanged if the option is not found.
-
- To have a long-named option do something other than set an 'int' to
- a compiled-in constant, such as set a value from 'optarg', set the
- option's 'flag' field to zero and its 'val' field to a nonzero
- value (the equivalent single-letter option character, if there is
- one). For long options that have a zero 'flag' field, 'getopt'
- returns the contents of the 'val' field. */
-
-# if !GNULIB_defined_struct_option
-struct option
-{
- const char *name;
- /* has_arg can't be an enum because some compilers complain about
- type mismatches in all the code that assumes it is an int. */
- int has_arg;
- int *flag;
- int val;
-};
-# define GNULIB_defined_struct_option 1
-# endif
-
-/* Names for the values of the 'has_arg' field of 'struct option'. */
-
-# define no_argument 0
-# define required_argument 1
-# define optional_argument 2
-#endif /* need getopt */
-
-
-/* Get definitions and prototypes for functions to process the
- arguments in ARGV (ARGC of them, minus the program name) for
- options given in OPTS.
-
- Return the option character from OPTS just read. Return -1 when
- there are no more options. For unrecognized options, or options
- missing arguments, 'optopt' is set to the option letter, and '?' is
- returned.
-
- The OPTS string is a list of characters which are recognized option
- letters, optionally followed by colons, specifying that that letter
- takes an argument, to be placed in 'optarg'.
-
- If a letter in OPTS is followed by two colons, its argument is
- optional. This behavior is specific to the GNU 'getopt'.
-
- The argument '--' causes premature termination of argument
- scanning, explicitly telling 'getopt' that there are no more
- options.
-
- If OPTS begins with '-', then non-option arguments are treated as
- arguments to the option '\1'. This behavior is specific to the GNU
- 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
- the environment, then do not permute arguments. */
-
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
- __THROW _GL_ARG_NONNULL ((2, 3));
-
-#ifndef __need_getopt
-extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind)
- __THROW _GL_ARG_NONNULL ((2, 3));
-extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind)
- __THROW _GL_ARG_NONNULL ((2, 3));
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-/* Make sure we later can get all the definitions and declarations. */
-#undef __need_getopt
-
-#endif /* _GL_M4_GETOPT_H */
-#endif /* _GL_M4_GETOPT_H */
+# else
+# define __THROW
+# endif
+#endif
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* For communication from 'getopt' to the caller.
+ When 'getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when 'ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+extern char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to 'getopt'.
+
+ On entry to 'getopt', zero means this is the first call; initialize.
+
+ When 'getopt' returns -1, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, 'optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+extern int optind;
+
+/* Callers store zero here to inhibit the error message 'getopt' prints
+ for unrecognized options. */
+
+extern int opterr;
+
+/* Set to an option character which was unrecognized. */
+
+extern int optopt;
+
+#ifndef __need_getopt
+/* Describe the long-named options requested by the application.
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ of 'struct option' terminated by an element containing a name which is
+ zero.
+
+ The field 'has_arg' is:
+ no_argument (or 0) if the option does not take an argument,
+ required_argument (or 1) if the option requires an argument,
+ optional_argument (or 2) if the option takes an optional argument.
+
+ If the field 'flag' is not NULL, it points to a variable that is set
+ to the value given in the field 'val' when the option is found, but
+ left unchanged if the option is not found.
+
+ To have a long-named option do something other than set an 'int' to
+ a compiled-in constant, such as set a value from 'optarg', set the
+ option's 'flag' field to zero and its 'val' field to a nonzero
+ value (the equivalent single-letter option character, if there is
+ one). For long options that have a zero 'flag' field, 'getopt'
+ returns the contents of the 'val' field. */
+
+# if !GNULIB_defined_struct_option
+struct option
+{
+ const char *name;
+ /* has_arg can't be an enum because some compilers complain about
+ type mismatches in all the code that assumes it is an int. */
+ int has_arg;
+ int *flag;
+ int val;
+};
+# define GNULIB_defined_struct_option 1
+# endif
+
+/* Names for the values of the 'has_arg' field of 'struct option'. */
+
+# define no_argument 0
+# define required_argument 1
+# define optional_argument 2
+#endif /* need getopt */
+
+
+/* Get definitions and prototypes for functions to process the
+ arguments in ARGV (ARGC of them, minus the program name) for
+ options given in OPTS.
+
+ Return the option character from OPTS just read. Return -1 when
+ there are no more options. For unrecognized options, or options
+ missing arguments, 'optopt' is set to the option letter, and '?' is
+ returned.
+
+ The OPTS string is a list of characters which are recognized option
+ letters, optionally followed by colons, specifying that that letter
+ takes an argument, to be placed in 'optarg'.
+
+ If a letter in OPTS is followed by two colons, its argument is
+ optional. This behavior is specific to the GNU 'getopt'.
+
+ The argument '--' causes premature termination of argument
+ scanning, explicitly telling 'getopt' that there are no more
+ options.
+
+ If OPTS begins with '-', then non-option arguments are treated as
+ arguments to the option '\1'. This behavior is specific to the GNU
+ 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
+ the environment, then do not permute arguments. */
+
+extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
+ __THROW _GL_ARG_NONNULL ((2, 3));
+
+#ifndef __need_getopt
+extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind)
+ __THROW _GL_ARG_NONNULL ((2, 3));
+extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind)
+ __THROW _GL_ARG_NONNULL ((2, 3));
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/* Make sure we later can get all the definitions and declarations. */
+#undef __need_getopt
+
+#endif /* _GL_M4_GETOPT_H */
+#endif /* _GL_M4_GETOPT_H */
diff --git a/contrib/tools/bison/gnulib/platform/posix/time.h b/contrib/tools/bison/gnulib/platform/posix/time.h
index c472f89c7f..e7a2140be5 100644
--- a/contrib/tools/bison/gnulib/platform/posix/time.h
+++ b/contrib/tools/bison/gnulib/platform/posix/time.h
@@ -1,560 +1,560 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* A more-standard <time.h>.
-
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#if __GNUC__ >= 3
-#pragma GCC system_header
-#endif
-
-
-/* Don't get in the way of glibc when it includes time.h merely to
- declare a few standard symbols, rather than to declare all the
- symbols. Also, Solaris 8 <time.h> eventually includes itself
- recursively; if that is happening, just include the system <time.h>
- without adding our own declarations. */
-#if (defined __need_time_t || defined __need_clock_t \
- || defined __need_timespec \
- || defined _GL_M4_TIME_H)
-
-# include_next <time.h>
-
-#else
-
-# define _GL_M4_TIME_H
-
-# include_next <time.h>
-
-/* NetBSD 5.0 mis-defines NULL. */
-# include <stddef.h>
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
- Or they define it with the wrong member names or define it in <sys/time.h>
- (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the
- pthreads-win32 library defines it in <pthread.h>. */
-# if ! 1
-# if 0
-# include <sys/time.h>
-# elif 0
-# include <pthread.h>
-/* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */
-# undef asctime_r
-# undef ctime_r
-# undef gmtime_r
-# undef localtime_r
-# undef rand_r
-# undef strtok_r
-# else
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-# if !GNULIB_defined_struct_timespec
-# undef timespec
-# define timespec rpl_timespec
-struct timespec
-{
- time_t tv_sec;
- long int tv_nsec;
-};
-# define GNULIB_defined_struct_timespec 1
-# endif
-
-# ifdef __cplusplus
-}
-# endif
-
-# endif
-# endif
-
-# if !GNULIB_defined_struct_time_t_must_be_integral
-/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
- time_t to be an integer type, even though C99 permits floating
- point. We don't know of any implementation that uses floating
- point, and it is much easier to write code that doesn't have to
- worry about that corner case, so we force the issue. */
-struct __time_t_must_be_integral {
- unsigned int __floating_time_t_unsupported : (time_t) 1;
-};
-# define GNULIB_defined_struct_time_t_must_be_integral 1
-# endif
-
-/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
- return -1 and store the remaining time into RMTP. See
- <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
-# if 0
-# if GNULIB_PORTCHECK
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define nanosleep rpl_nanosleep
-# endif
-_GL_FUNCDECL_RPL (nanosleep, int,
- (struct timespec const *__rqtp, struct timespec *__rmtp)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (nanosleep, int,
- (struct timespec const *__rqtp, struct timespec *__rmtp));
-# else
-# if ! 1
-_GL_FUNCDECL_SYS (nanosleep, int,
- (struct timespec const *__rqtp, struct timespec *__rmtp)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (nanosleep, int,
- (struct timespec const *__rqtp, struct timespec *__rmtp));
-# endif
-_GL_CXXALIASWARN (nanosleep);
-# endif
-
-/* Return the 'time_t' representation of TP and normalize TP. */
-# if 0
-# if GNULIB_PORTCHECK
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define mktime rpl_mktime
-# endif
-_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
-# else
-_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
-# endif
-_GL_CXXALIASWARN (mktime);
-# endif
-
-/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
- <http://www.opengroup.org/susv3xsh/localtime_r.html> and
- <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
-# if 0
-# if GNULIB_PORTCHECK
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef localtime_r
-# define localtime_r rpl_localtime_r
-# endif
-_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result)
- _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result));
-# else
-# if ! 1
-_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result)
- _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result));
-# endif
-# if 1
-_GL_CXXALIASWARN (localtime_r);
-# endif
-# if GNULIB_PORTCHECK
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef gmtime_r
-# define gmtime_r rpl_gmtime_r
-# endif
-_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result)
- _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result));
-# else
-# if ! 1
-_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result)
- _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
- struct tm *restrict __result));
-# endif
-# if 1
-_GL_CXXALIASWARN (gmtime_r);
-# endif
-# endif
-
-/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
- the resulting broken-down time into TM. See
- <http://www.opengroup.org/susv3xsh/strptime.html>. */
-# if 0
-# if ! 1
-_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
- char const *restrict __format,
- struct tm *restrict __tm)
- _GL_ARG_NONNULL ((1, 2, 3)));
-# endif
-_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
- char const *restrict __format,
- struct tm *restrict __tm));
-_GL_CXXALIASWARN (strptime);
-# endif
-
-/* Convert TM to a time_t value, assuming UTC. */
-# if 0
-# if GNULIB_PORTCHECK
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef timegm
-# define timegm rpl_timegm
-# endif
-_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
-# else
-# if ! 1
-_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
-# endif
-_GL_CXXALIASWARN (timegm);
-# endif
-
-/* Encourage applications to avoid unsafe functions that can overrun
- buffers when given outlandish struct tm values. Portable
- applications should use strftime (or even sprintf) instead. */
-# if defined GNULIB_POSIXCHECK
-# undef asctime
-_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
- "better use strftime (or even sprintf) instead");
-# endif
-# if defined GNULIB_POSIXCHECK
-# undef asctime_r
-_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
- "better use strftime (or even sprintf) instead");
-# endif
-# if defined GNULIB_POSIXCHECK
-# undef ctime
-_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
- "better use strftime (or even sprintf) instead");
-# endif
-# if defined GNULIB_POSIXCHECK
-# undef ctime_r
-_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
- "better use strftime (or even sprintf) instead");
-# endif
-
-#endif
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* A more-standard <time.h>.
+
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#if __GNUC__ >= 3
+#pragma GCC system_header
+#endif
+
+
+/* Don't get in the way of glibc when it includes time.h merely to
+ declare a few standard symbols, rather than to declare all the
+ symbols. Also, Solaris 8 <time.h> eventually includes itself
+ recursively; if that is happening, just include the system <time.h>
+ without adding our own declarations. */
+#if (defined __need_time_t || defined __need_clock_t \
+ || defined __need_timespec \
+ || defined _GL_M4_TIME_H)
+
+# include_next <time.h>
+
+#else
+
+# define _GL_M4_TIME_H
+
+# include_next <time.h>
+
+/* NetBSD 5.0 mis-defines NULL. */
+# include <stddef.h>
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
+ Or they define it with the wrong member names or define it in <sys/time.h>
+ (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the
+ pthreads-win32 library defines it in <pthread.h>. */
+# if ! 1
+# if 0
+# include <sys/time.h>
+# elif 0
+# include <pthread.h>
+/* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */
+# undef asctime_r
+# undef ctime_r
+# undef gmtime_r
+# undef localtime_r
+# undef rand_r
+# undef strtok_r
+# else
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if !GNULIB_defined_struct_timespec
+# undef timespec
+# define timespec rpl_timespec
+struct timespec
+{
+ time_t tv_sec;
+ long int tv_nsec;
+};
+# define GNULIB_defined_struct_timespec 1
+# endif
+
+# ifdef __cplusplus
+}
+# endif
+
+# endif
+# endif
+
+# if !GNULIB_defined_struct_time_t_must_be_integral
+/* Per http://austingroupbugs.net/view.php?id=327, POSIX requires
+ time_t to be an integer type, even though C99 permits floating
+ point. We don't know of any implementation that uses floating
+ point, and it is much easier to write code that doesn't have to
+ worry about that corner case, so we force the issue. */
+struct __time_t_must_be_integral {
+ unsigned int __floating_time_t_unsupported : (time_t) 1;
+};
+# define GNULIB_defined_struct_time_t_must_be_integral 1
+# endif
+
+/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
+ return -1 and store the remaining time into RMTP. See
+ <http://www.opengroup.org/susv3xsh/nanosleep.html>. */
+# if 0
+# if GNULIB_PORTCHECK
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define nanosleep rpl_nanosleep
+# endif
+_GL_FUNCDECL_RPL (nanosleep, int,
+ (struct timespec const *__rqtp, struct timespec *__rmtp)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (nanosleep, int,
+ (struct timespec const *__rqtp, struct timespec *__rmtp));
+# else
+# if ! 1
+_GL_FUNCDECL_SYS (nanosleep, int,
+ (struct timespec const *__rqtp, struct timespec *__rmtp)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (nanosleep, int,
+ (struct timespec const *__rqtp, struct timespec *__rmtp));
+# endif
+_GL_CXXALIASWARN (nanosleep);
+# endif
+
+/* Return the 'time_t' representation of TP and normalize TP. */
+# if 0
+# if GNULIB_PORTCHECK
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define mktime rpl_mktime
+# endif
+_GL_FUNCDECL_RPL (mktime, time_t, (struct tm *__tp) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
+# else
+_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
+# endif
+_GL_CXXALIASWARN (mktime);
+# endif
+
+/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
+ <http://www.opengroup.org/susv3xsh/localtime_r.html> and
+ <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
+# if 0
+# if GNULIB_PORTCHECK
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef localtime_r
+# define localtime_r rpl_localtime_r
+# endif
+_GL_FUNCDECL_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result));
+# else
+# if ! 1
+_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result)
+ _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result));
+# endif
+# if 1
+_GL_CXXALIASWARN (localtime_r);
+# endif
+# if GNULIB_PORTCHECK
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef gmtime_r
+# define gmtime_r rpl_gmtime_r
+# endif
+_GL_FUNCDECL_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result));
+# else
+# if ! 1
+_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result)
+ _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
+ struct tm *restrict __result));
+# endif
+# if 1
+_GL_CXXALIASWARN (gmtime_r);
+# endif
+# endif
+
+/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
+ the resulting broken-down time into TM. See
+ <http://www.opengroup.org/susv3xsh/strptime.html>. */
+# if 0
+# if ! 1
+_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
+ char const *restrict __format,
+ struct tm *restrict __tm)
+ _GL_ARG_NONNULL ((1, 2, 3)));
+# endif
+_GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
+ char const *restrict __format,
+ struct tm *restrict __tm));
+_GL_CXXALIASWARN (strptime);
+# endif
+
+/* Convert TM to a time_t value, assuming UTC. */
+# if 0
+# if GNULIB_PORTCHECK
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef timegm
+# define timegm rpl_timegm
+# endif
+_GL_FUNCDECL_RPL (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (timegm, time_t, (struct tm *__tm));
+# else
+# if ! 1
+_GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm));
+# endif
+_GL_CXXALIASWARN (timegm);
+# endif
+
+/* Encourage applications to avoid unsafe functions that can overrun
+ buffers when given outlandish struct tm values. Portable
+ applications should use strftime (or even sprintf) instead. */
+# if defined GNULIB_POSIXCHECK
+# undef asctime
+_GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
+ "better use strftime (or even sprintf) instead");
+# endif
+# if defined GNULIB_POSIXCHECK
+# undef asctime_r
+_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - "
+ "better use strftime (or even sprintf) instead");
+# endif
+# if defined GNULIB_POSIXCHECK
+# undef ctime
+_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - "
+ "better use strftime (or even sprintf) instead");
+# endif
+# if defined GNULIB_POSIXCHECK
+# undef ctime_r
+_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - "
+ "better use strftime (or even sprintf) instead");
+# endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/platform/posix/unused-parameter.h b/contrib/tools/bison/gnulib/platform/posix/unused-parameter.h
index 53474b5754..fa649b8221 100644
--- a/contrib/tools/bison/gnulib/platform/posix/unused-parameter.h
+++ b/contrib/tools/bison/gnulib/platform/posix/unused-parameter.h
@@ -1,20 +1,20 @@
-/* _GL_UNUSED_PARAMETER is a marker that can be appended to function parameter
- declarations for parameters that are not used. This helps to reduce
- warnings, such as from GCC -Wunused-parameter. The syntax is as follows:
- type param _GL_UNUSED_PARAMETER
- or more generally
- param_decl _GL_UNUSED_PARAMETER
- For example:
- int param _GL_UNUSED_PARAMETER
- int *(*param)(void) _GL_UNUSED_PARAMETER
- Other possible, but obscure and discouraged syntaxes:
- int _GL_UNUSED_PARAMETER *(*param)(void)
- _GL_UNUSED_PARAMETER int *(*param)(void)
- */
-#ifndef _GL_UNUSED_PARAMETER
-# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_UNUSED_PARAMETER __attribute__ ((__unused__))
-# else
-# define _GL_UNUSED_PARAMETER
-# endif
-#endif
+/* _GL_UNUSED_PARAMETER is a marker that can be appended to function parameter
+ declarations for parameters that are not used. This helps to reduce
+ warnings, such as from GCC -Wunused-parameter. The syntax is as follows:
+ type param _GL_UNUSED_PARAMETER
+ or more generally
+ param_decl _GL_UNUSED_PARAMETER
+ For example:
+ int param _GL_UNUSED_PARAMETER
+ int *(*param)(void) _GL_UNUSED_PARAMETER
+ Other possible, but obscure and discouraged syntaxes:
+ int _GL_UNUSED_PARAMETER *(*param)(void)
+ _GL_UNUSED_PARAMETER int *(*param)(void)
+ */
+#ifndef _GL_UNUSED_PARAMETER
+# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED_PARAMETER __attribute__ ((__unused__))
+# else
+# define _GL_UNUSED_PARAMETER
+# endif
+#endif
diff --git a/contrib/tools/bison/gnulib/platform/win64/alloca.h b/contrib/tools/bison/gnulib/platform/win64/alloca.h
index 4f6716faa0..a5866ee8bb 100644
--- a/contrib/tools/bison/gnulib/platform/win64/alloca.h
+++ b/contrib/tools/bison/gnulib/platform/win64/alloca.h
@@ -1,64 +1,64 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Memory allocation on the stack.
-
- Copyright (C) 1995, 1999, 2001-2004, 2006-2013 Free Software Foundation,
- Inc.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, see
- <http://www.gnu.org/licenses/>.
- */
-
-/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
- means there is a real alloca function. */
-#ifndef _GL_ALLOCA_H
-#define _GL_ALLOCA_H
-
-/* alloca (N) returns a pointer to N bytes of memory
- allocated on the stack, which will last until the function returns.
- Use of alloca should be avoided:
- - inside arguments of function calls - undefined behaviour,
- - in inline functions - the allocation may actually last until the
- calling function returns,
- - for huge N (say, N >= 65536) - you never know how large (or small)
- the stack is, and when the stack cannot fulfill the memory allocation
- request, the program just crashes.
- */
-
-#ifndef alloca
-# ifdef __GNUC__
-# define alloca __builtin_alloca
-# elif defined _AIX
-# define alloca __alloca
-# elif defined _MSC_VER
-# include <malloc.h>
-# define alloca _alloca
-# elif defined __DECC && defined __VMS
-# define alloca __ALLOCA
-# elif defined __TANDEM && defined _TNS_E_TARGET
-# ifdef __cplusplus
-extern "C"
-# endif
-void *_alloca (unsigned short);
-# pragma intrinsic (_alloca)
-# define alloca _alloca
-# else
-# include <stddef.h>
-# ifdef __cplusplus
-extern "C"
-# endif
-void *alloca (size_t);
-# endif
-#endif
-
-#endif /* _GL_ALLOCA_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Memory allocation on the stack.
+
+ Copyright (C) 1995, 1999, 2001-2004, 2006-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, see
+ <http://www.gnu.org/licenses/>.
+ */
+
+/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
+ means there is a real alloca function. */
+#ifndef _GL_ALLOCA_H
+#define _GL_ALLOCA_H
+
+/* alloca (N) returns a pointer to N bytes of memory
+ allocated on the stack, which will last until the function returns.
+ Use of alloca should be avoided:
+ - inside arguments of function calls - undefined behaviour,
+ - in inline functions - the allocation may actually last until the
+ calling function returns,
+ - for huge N (say, N >= 65536) - you never know how large (or small)
+ the stack is, and when the stack cannot fulfill the memory allocation
+ request, the program just crashes.
+ */
+
+#ifndef alloca
+# ifdef __GNUC__
+# define alloca __builtin_alloca
+# elif defined _AIX
+# define alloca __alloca
+# elif defined _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
+# elif defined __DECC && defined __VMS
+# define alloca __ALLOCA
+# elif defined __TANDEM && defined _TNS_E_TARGET
+# ifdef __cplusplus
+extern "C"
+# endif
+void *_alloca (unsigned short);
+# pragma intrinsic (_alloca)
+# define alloca _alloca
+# else
+# include <stddef.h>
+# ifdef __cplusplus
+extern "C"
+# endif
+void *alloca (size_t);
+# endif
+#endif
+
+#endif /* _GL_ALLOCA_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/config.h b/contrib/tools/bison/gnulib/platform/win64/config.h
index cf3d366e18..da186725dd 100644
--- a/contrib/tools/bison/gnulib/platform/win64/config.h
+++ b/contrib/tools/bison/gnulib/platform/win64/config.h
@@ -1,1711 +1,1711 @@
-/* lib/config.h. Generated from config.hin by configure. */
-/* lib/config.hin. Generated from configure.ac by autoheader. */
-
+/* lib/config.h. Generated from config.hin by configure. */
+/* lib/config.hin. Generated from configure.ac by autoheader. */
+
#include <contrib/tools/bison/gnulib/win_sdk10.h>
-/* Define if building universal (internal helper macro) */
-/* #undef AC_APPLE_UNIVERSAL_BUILD */
-
-/* Define to the number of bits in type 'ptrdiff_t'. */
-/* #undef BITSIZEOF_PTRDIFF_T */
-
-/* Define to the number of bits in type 'sig_atomic_t'. */
-/* #undef BITSIZEOF_SIG_ATOMIC_T */
-
-/* Define to the number of bits in type 'size_t'. */
-/* #undef BITSIZEOF_SIZE_T */
-
-/* Define to the number of bits in type 'wchar_t'. */
-/* #undef BITSIZEOF_WCHAR_T */
-
-/* Define to the number of bits in type 'wint_t'. */
-/* #undef BITSIZEOF_WINT_T */
-
-/* Define if you wish *printf() functions that have a safe handling of
- non-IEEE-754 'long double' values. */
-#define CHECK_PRINTF_SAFE 1
-
-/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
- systems. This function is required for `alloca.c' support on those systems.
- */
-/* #undef CRAY_STACKSEG_END */
-
-/* Define to 1 if using `alloca.c'. */
-/* #undef C_ALLOCA */
-
-/* Define as the bit index in the word where to find bit 0 of the exponent of
- 'double'. */
-#define DBL_EXPBIT0_BIT 20
-
-/* Define as the word index where to find the exponent of 'double'. */
-#define DBL_EXPBIT0_WORD 1
-
-/* Define as the bit index in the word where to find the sign of 'double'. */
-#define DBL_SIGNBIT_BIT 31
-
-/* Define as the word index where to find the sign of 'double'. */
-#define DBL_SIGNBIT_WORD 1
-
-/* Define to 1 if // is a file system root distinct from /. */
-#define DOUBLE_SLASH_IS_DISTINCT_ROOT 1
-
-/* Define to 1 if the changeword(REGEXP) functionality is wanted */
-/* #undef ENABLE_CHANGEWORD */
-
-/* Define to 1 if an invalid memory address access may yield a SIGBUS. */
-#define FAULT_YIELDS_SIGBUS 0
-
-/* Define this to 1 if F_DUPFD behavior does not match POSIX */
-/* #undef FCNTL_DUPFD_BUGGY */
-
-/* Define as the bit index in the word where to find bit 0 of the exponent of
- 'float'. */
-#define FLT_EXPBIT0_BIT 23
-
-/* Define as the word index where to find the exponent of 'float'. */
-#define FLT_EXPBIT0_WORD 0
-
-/* Define as the bit index in the word where to find the sign of 'float'. */
-#define FLT_SIGNBIT_BIT 31
-
-/* Define as the word index where to find the sign of 'float'. */
-#define FLT_SIGNBIT_WORD 0
-
-/* Define to 1 if fopen() fails to recognize a trailing slash. */
-#define FOPEN_TRAILING_SLASH_BUG 1
-
-/* Enable compile-time and run-time bounds-checking, and some warnings,
- without upsetting newer glibc. */
- #if defined __OPTIMIZE__ && __OPTIMIZE__
- # define _FORTIFY_SOURCE 2
- #endif
-
-
-/* Define to 1 if the system's ftello function has the Solaris bug. */
-/* #undef FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE */
-
-/* Define to 1 if fflush is known to work on stdin as per POSIX.1-2008, 0 if
- fflush is known to not work, -1 if unknown. */
-#define FUNC_FFLUSH_STDIN 0
-
-/* Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string. */
-/* #undef FUNC_NL_LANGINFO_YESEXPR_WORKS */
-
-/* Define to 1 if realpath() can malloc memory, always gives an absolute path,
- and handles trailing slash correctly. */
-/* #undef FUNC_REALPATH_WORKS */
-
-/* Define to 1 if ungetc is broken when used on arbitrary bytes. */
-/* #undef FUNC_UNGETC_BROKEN */
-
-/* Define if gettimeofday clobbers the localtime buffer. */
-/* #undef GETTIMEOFDAY_CLOBBERS_LOCALTIME */
-
-/* Define this to 'void' or 'struct timezone' to match the system's
- declaration of the second argument to gettimeofday. */
-#define GETTIMEOFDAY_TIMEZONE void
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module canonicalize-lgpl shall be considered present. */
-#define GNULIB_CANONICALIZE_LGPL 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module close-stream shall be considered present. */
-#define GNULIB_CLOSE_STREAM 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module dirname shall be considered present. */
-#define GNULIB_DIRNAME 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fd-safer-flag shall be considered present. */
-#define GNULIB_FD_SAFER_FLAG 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fflush shall be considered present. */
-#define GNULIB_FFLUSH 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module filenamecat shall be considered present. */
-#define GNULIB_FILENAMECAT 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fopen-safer shall be considered present. */
-#define GNULIB_FOPEN_SAFER 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module fscanf shall be considered present. */
-#define GNULIB_FSCANF 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module lock shall be considered present. */
-#define GNULIB_LOCK 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module malloc-gnu shall be considered present. */
-#define GNULIB_MALLOC_GNU 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module pipe2-safer shall be considered present. */
-#define GNULIB_PIPE2_SAFER 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module scanf shall be considered present. */
-#define GNULIB_SCANF 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module sigpipe shall be considered present. */
-#define GNULIB_SIGPIPE 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module snprintf shall be considered present. */
-#define GNULIB_SNPRINTF 1
-
-/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
- whether the gnulib module strerror shall be considered present. */
-#define GNULIB_STRERROR 1
-
-/* Define to 1 when the gnulib module btowc should be tested. */
-#define GNULIB_TEST_BTOWC 1
-
-/* Define to 1 when the gnulib module canonicalize_file_name should be tested.
- */
-#define GNULIB_TEST_CANONICALIZE_FILE_NAME 1
-
-/* Define to 1 when the gnulib module chdir should be tested. */
-#define GNULIB_TEST_CHDIR 1
-
-/* Define to 1 when the gnulib module cloexec should be tested. */
-#define GNULIB_TEST_CLOEXEC 1
-
-/* Define to 1 when the gnulib module close should be tested. */
-#define GNULIB_TEST_CLOSE 1
-
-/* Define to 1 when the gnulib module closedir should be tested. */
-#define GNULIB_TEST_CLOSEDIR 1
-
-/* Define to 1 when the gnulib module dup should be tested. */
-#define GNULIB_TEST_DUP 1
-
-/* Define to 1 when the gnulib module dup2 should be tested. */
-#define GNULIB_TEST_DUP2 1
-
-/* Define to 1 when the gnulib module environ should be tested. */
-#define GNULIB_TEST_ENVIRON 1
-
-/* Define to 1 when the gnulib module fclose should be tested. */
-#define GNULIB_TEST_FCLOSE 1
-
-/* Define to 1 when the gnulib module fcntl should be tested. */
-#define GNULIB_TEST_FCNTL 1
-
-/* Define to 1 when the gnulib module fdopen should be tested. */
-#define GNULIB_TEST_FDOPEN 1
-
-/* Define to 1 when the gnulib module fflush should be tested. */
-#define GNULIB_TEST_FFLUSH 1
-
-/* Define to 1 when the gnulib module fopen should be tested. */
-#define GNULIB_TEST_FOPEN 1
-
-/* Define to 1 when the gnulib module fpurge should be tested. */
-#define GNULIB_TEST_FPURGE 1
-
-/* Define to 1 when the gnulib module frexp should be tested. */
-#define GNULIB_TEST_FREXP 1
-
-/* Define to 1 when the gnulib module frexpl should be tested. */
-#define GNULIB_TEST_FREXPL 1
-
-/* Define to 1 when the gnulib module fseek should be tested. */
-#define GNULIB_TEST_FSEEK 1
-
-/* Define to 1 when the gnulib module fseeko should be tested. */
-#define GNULIB_TEST_FSEEKO 1
-
-/* Define to 1 when the gnulib module fstat should be tested. */
-#define GNULIB_TEST_FSTAT 1
-
-/* Define to 1 when the gnulib module ftell should be tested. */
-#define GNULIB_TEST_FTELL 1
-
-/* Define to 1 when the gnulib module ftello should be tested. */
-#define GNULIB_TEST_FTELLO 1
-
-/* Define to 1 when the gnulib module getcwd should be tested. */
-#define GNULIB_TEST_GETCWD 1
-
-/* Define to 1 when the gnulib module getdtablesize should be tested. */
-#define GNULIB_TEST_GETDTABLESIZE 1
-
-/* Define to 1 when the gnulib module getopt-gnu should be tested. */
-#define GNULIB_TEST_GETOPT_GNU 1
-
-/* Define to 1 when the gnulib module getpagesize should be tested. */
-#define GNULIB_TEST_GETPAGESIZE 1
-
-/* Define to 1 when the gnulib module gettimeofday should be tested. */
-#define GNULIB_TEST_GETTIMEOFDAY 1
-
-/* Define to 1 when the gnulib module link should be tested. */
-#define GNULIB_TEST_LINK 1
-
-/* Define to 1 when the gnulib module localeconv should be tested. */
-#define GNULIB_TEST_LOCALECONV 1
-
-/* Define to 1 when the gnulib module lseek should be tested. */
-#define GNULIB_TEST_LSEEK 1
-
-/* Define to 1 when the gnulib module lstat should be tested. */
-#define GNULIB_TEST_LSTAT 1
-
-/* Define to 1 when the gnulib module malloc-posix should be tested. */
-#define GNULIB_TEST_MALLOC_POSIX 1
-
-/* Define to 1 when the gnulib module mbrtowc should be tested. */
-#define GNULIB_TEST_MBRTOWC 1
-
-/* Define to 1 when the gnulib module mbsinit should be tested. */
-#define GNULIB_TEST_MBSINIT 1
-
-/* Define to 1 when the gnulib module mbtowc should be tested. */
-#define GNULIB_TEST_MBTOWC 1
-
-/* Define to 1 when the gnulib module memchr should be tested. */
-#define GNULIB_TEST_MEMCHR 1
-
-/* Define to 1 when the gnulib module mkdtemp should be tested. */
-#define GNULIB_TEST_MKDTEMP 1
-
-/* Define to 1 when the gnulib module mkstemp should be tested. */
-#define GNULIB_TEST_MKSTEMP 1
-
-/* Define to 1 when the gnulib module nl_langinfo should be tested. */
-#define GNULIB_TEST_NL_LANGINFO 1
-
-/* Define to 1 when the gnulib module open should be tested. */
-#define GNULIB_TEST_OPEN 1
-
-/* Define to 1 when the gnulib module opendir should be tested. */
-#define GNULIB_TEST_OPENDIR 1
-
-/* Define to 1 when the gnulib module pipe2 should be tested. */
-#define GNULIB_TEST_PIPE2 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_destroy should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWNATTR_DESTROY 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_init should be tested.
- */
-#define GNULIB_TEST_POSIX_SPAWNATTR_INIT 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_setflags should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWNATTR_SETFLAGS 1
-
-/* Define to 1 when the gnulib module posix_spawnattr_setsigmask should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWNATTR_SETSIGMASK 1
-
-/* Define to 1 when the gnulib module posix_spawnp should be tested. */
-#define GNULIB_TEST_POSIX_SPAWNP 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_addclose should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_adddup2 should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_addopen should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_destroy should
- be tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_DESTROY 1
-
-/* Define to 1 when the gnulib module posix_spawn_file_actions_init should be
- tested. */
-#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_INIT 1
-
-/* Define to 1 when the gnulib module putenv should be tested. */
-#define GNULIB_TEST_PUTENV 1
-
-/* Define to 1 when the gnulib module raise should be tested. */
-#define GNULIB_TEST_RAISE 1
-
-/* Define to 1 when the gnulib module rawmemchr should be tested. */
-#define GNULIB_TEST_RAWMEMCHR 1
-
-/* Define to 1 when the gnulib module readdir should be tested. */
-#define GNULIB_TEST_READDIR 1
-
-/* Define to 1 when the gnulib module readlink should be tested. */
-#define GNULIB_TEST_READLINK 1
-
-/* Define to 1 when the gnulib module realpath should be tested. */
-#define GNULIB_TEST_REALPATH 1
-
-/* Define to 1 when the gnulib module rename should be tested. */
-#define GNULIB_TEST_RENAME 1
-
-/* Define to 1 when the gnulib module rmdir should be tested. */
-#define GNULIB_TEST_RMDIR 1
-
-/* Define to 1 when the gnulib module secure_getenv should be tested. */
-#define GNULIB_TEST_SECURE_GETENV 1
-
-/* Define to 1 when the gnulib module setenv should be tested. */
-#define GNULIB_TEST_SETENV 1
-
-/* Define to 1 when the gnulib module setlocale should be tested. */
-#define GNULIB_TEST_SETLOCALE 1
-
-/* Define to 1 when the gnulib module sigaction should be tested. */
-#define GNULIB_TEST_SIGACTION 1
-
-/* Define to 1 when the gnulib module signbit should be tested. */
-#define GNULIB_TEST_SIGNBIT 1
-
-/* Define to 1 when the gnulib module sigprocmask should be tested. */
-#define GNULIB_TEST_SIGPROCMASK 1
-
-/* Define to 1 when the gnulib module sleep should be tested. */
-#define GNULIB_TEST_SLEEP 1
-
-/* Define to 1 when the gnulib module snprintf should be tested. */
-#define GNULIB_TEST_SNPRINTF 1
-
-/* Define to 1 when the gnulib module stat should be tested. */
-#define GNULIB_TEST_STAT 1
-
-/* Define to 1 when the gnulib module strchrnul should be tested. */
-#define GNULIB_TEST_STRCHRNUL 1
-
-/* Define to 1 when the gnulib module strdup should be tested. */
-#define GNULIB_TEST_STRDUP 1
-
-/* Define to 1 when the gnulib module strerror should be tested. */
-#define GNULIB_TEST_STRERROR 1
-
-/* Define to 1 when the gnulib module strndup should be tested. */
-#define GNULIB_TEST_STRNDUP 1
-
-/* Define to 1 when the gnulib module strnlen should be tested. */
-#define GNULIB_TEST_STRNLEN 1
-
-/* Define to 1 when the gnulib module strsignal should be tested. */
-#define GNULIB_TEST_STRSIGNAL 1
-
-/* Define to 1 when the gnulib module strstr should be tested. */
-#define GNULIB_TEST_STRSTR 1
-
-/* Define to 1 when the gnulib module strtod should be tested. */
-#define GNULIB_TEST_STRTOD 1
-
-/* Define to 1 when the gnulib module symlink should be tested. */
-#define GNULIB_TEST_SYMLINK 1
-
-/* Define to 1 when the gnulib module unsetenv should be tested. */
-#define GNULIB_TEST_UNSETENV 1
-
-/* Define to 1 when the gnulib module vasprintf should be tested. */
-#define GNULIB_TEST_VASPRINTF 1
-
-/* Define to 1 when the gnulib module waitpid should be tested. */
-#define GNULIB_TEST_WAITPID 1
-
-/* Define to 1 when the gnulib module wcrtomb should be tested. */
-#define GNULIB_TEST_WCRTOMB 1
-
-/* Define to 1 when the gnulib module wctob should be tested. */
-#define GNULIB_TEST_WCTOB 1
-
-/* Define to 1 when the gnulib module wctomb should be tested. */
-#define GNULIB_TEST_WCTOMB 1
-
-/* Define to 1 when the gnulib module write should be tested. */
-#define GNULIB_TEST_WRITE 1
-
-/* Define to 1 if you have 'alloca' after including <alloca.h>, a header that
- may be supplied by this distribution. */
-#define HAVE_ALLOCA 1
-
-/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
- */
-/* #undef HAVE_ALLOCA_H */
-
-/* Define to 1 if you have the <bp-sym.h> header file. */
-/* #undef HAVE_BP_SYM_H */
-
-/* Define to 1 if you have the `btowc' function. */
-#define HAVE_BTOWC 1
-
-/* Define to 1 if you have the `canonicalize_file_name' function. */
-/* #undef HAVE_CANONICALIZE_FILE_NAME */
-
-/* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the
- CoreFoundation framework. */
-/* #undef HAVE_CFLOCALECOPYCURRENT */
-
-/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
- the CoreFoundation framework. */
-/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
-
-/* Define to 1 if you have the `closedir' function. */
-/* #undef HAVE_CLOSEDIR */
-
-/* Define to 1 if you have the `confstr' function. */
-/* #undef HAVE_CONFSTR */
-
-/* Define if the copysignf function is declared in <math.h> and available in
- libc. */
-/* #undef HAVE_COPYSIGNF_IN_LIBC */
-
-/* Define if the copysignl function is declared in <math.h> and available in
- libc. */
-/* #undef HAVE_COPYSIGNL_IN_LIBC */
-
-/* Define if the copysign function is declared in <math.h> and available in
- libc. */
-/* #undef HAVE_COPYSIGN_IN_LIBC */
-
-/* Define to 1 if you have the declaration of `alarm', and to 0 if you don't.
- */
-#define HAVE_DECL_ALARM 0
-
-/* Define to 1 if you have the declaration of `clearerr_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_CLEARERR_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `copysign', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_COPYSIGN */
-
-/* Define to 1 if you have the declaration of `copysignf', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_COPYSIGNF */
-
-/* Define to 1 if you have the declaration of `copysignl', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_COPYSIGNL */
-
-/* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you
- don't. */
-#define HAVE_DECL_FEOF_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `ferror_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_FERROR_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fflush_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_FFLUSH_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_FGETS_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fpurge', and to 0 if you don't.
- */
-#define HAVE_DECL_FPURGE 0
-
-/* Define to 1 if you have the declaration of `fputc_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_FPUTC_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fputs_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_FPUTS_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fread_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_FREAD_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `fseeko', and to 0 if you don't.
- */
-#define HAVE_DECL_FSEEKO 0
-
-/* Define to 1 if you have the declaration of `ftello', and to 0 if you don't.
- */
-#define HAVE_DECL_FTELLO 0
-
-/* Define to 1 if you have the declaration of `fwrite_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_FWRITE_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `getchar_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_GETCHAR_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
- don't. */
-#define HAVE_DECL_GETC_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
- */
-#define HAVE_DECL_GETENV 1
-
-/* Define to 1 if you have the declaration of `isblank', and to 0 if you
- don't. */
-#define HAVE_DECL_ISBLANK 0
-
-/* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_MBRTOWC */
-
-/* Define to 1 if you have the declaration of `mbsinit', and to 0 if you
- don't. */
-#define HAVE_DECL_MBSINIT 1
-
-/* Define to 1 if you have the declaration of `program_invocation_name', and
- to 0 if you don't. */
-#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
-
-/* Define to 1 if you have the declaration of `program_invocation_short_name',
- and to 0 if you don't. */
-#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 0
-
-/* Define to 1 if you have the declaration of `putchar_unlocked', and to 0 if
- you don't. */
-#define HAVE_DECL_PUTCHAR_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `putc_unlocked', and to 0 if you
- don't. */
-#define HAVE_DECL_PUTC_UNLOCKED 0
-
-/* Define to 1 if you have the declaration of `setenv', and to 0 if you don't.
- */
-#define HAVE_DECL_SETENV 0
-
-/* Define to 1 if you have the declaration of `sigaltstack', and to 0 if you
- don't. */
-#define HAVE_DECL_SIGALTSTACK 0
-
-/* Define to 1 if you have the declaration of `sleep', and to 0 if you don't.
- */
-#define HAVE_DECL_SLEEP 0
-
-/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
- don't. */
-#define HAVE_DECL_SNPRINTF 0
-
-/* Define to 1 if you have the declaration of `strdup', and to 0 if you don't.
- */
-#define HAVE_DECL_STRDUP 1
-
-/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
- don't. */
-#define HAVE_DECL_STRERROR_R 0
-
-/* Define to 1 if you have the declaration of `strndup', and to 0 if you
- don't. */
-#define HAVE_DECL_STRNDUP 0
-
-/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
- don't. */
-#define HAVE_DECL_STRNLEN 1
-
-/* Define to 1 if you have the declaration of `strsignal', and to 0 if you
- don't. */
-#define HAVE_DECL_STRSIGNAL 0
-
-/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
- don't. */
-#define HAVE_DECL_SYS_SIGLIST 0
-
-/* Define to 1 if you have the declaration of `towlower', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_TOWLOWER */
-
-/* Define to 1 if you have the declaration of `unsetenv', and to 0 if you
- don't. */
-#define HAVE_DECL_UNSETENV 0
-
-/* Define to 1 if you have the declaration of `wcrtomb', and to 0 if you
- don't. */
-/* #undef HAVE_DECL_WCRTOMB */
-
-/* Define to 1 if you have the declaration of `wctob', and to 0 if you don't.
- */
-/* #undef HAVE_DECL_WCTOB */
-
-/* Define to 1 if you have the declaration of `_putenv', and to 0 if you
- don't. */
-#define HAVE_DECL__PUTENV 1
-
-/* Define to 1 if you have the declaration of `_snprintf', and to 0 if you
- don't. */
-#define HAVE_DECL__SNPRINTF 1
-
-/* Define to 1 if you have the declaration of `_sys_siglist', and to 0 if you
- don't. */
-#define HAVE_DECL__SYS_SIGLIST 0
-
-/* Define to 1 if you have the <dirent.h> header file. */
-/* #undef HAVE_DIRENT_H */
-
-/* Define to 1 if you have the 'dup2' function. */
-#define HAVE_DUP2 1
-
-/* Define if you have the declaration of environ. */
-#define HAVE_ENVIRON_DECL 1
-
-/* Define to 1 if you have the `fcntl' function. */
-/* #undef HAVE_FCNTL */
-
-/* Define to 1 if you have the <features.h> header file. */
-/* #undef HAVE_FEATURES_H */
-
-/* Define to 1 if you have the `fpurge' function. */
-/* #undef HAVE_FPURGE */
-
-/* Define if the frexpl function is available in libc. */
-/* #undef HAVE_FREXPL_IN_LIBC */
-
-/* Define if the frexp function is available in libc. */
-/* #undef HAVE_FREXP_IN_LIBC */
-
-/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
-/* #undef HAVE_FSEEKO */
-
-/* Define to 1 if you have the `getcwd' function. */
-#define HAVE_GETCWD 1
-
-/* Define to 1 if you have the `getdtablesize' function. */
-/* #undef HAVE_GETDTABLESIZE */
-
-/* Define to 1 if you have the <getopt.h> header file. */
-/* #undef HAVE_GETOPT_H */
-
-/* Define to 1 if you have the `getopt_long_only' function. */
-/* #undef HAVE_GETOPT_LONG_ONLY */
-
-/* Define to 1 if you have the `getpagesize' function. */
-/* #undef HAVE_GETPAGESIZE */
-
-/* Define to 1 if you have the `gettimeofday' function. */
-/* #undef HAVE_GETTIMEOFDAY */
-
-/* Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>. */
-#define HAVE_INTMAX_T 1
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-/* #undef HAVE_INTTYPES_H */
-
-/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and
- declares uintmax_t. */
-/* #undef HAVE_INTTYPES_H_WITH_UINTMAX */
-
-/* Define to 1 if you have the `isblank' function. */
-/* #undef HAVE_ISBLANK */
-
-/* Define if the isnan(double) function is available in libc. */
-/* #undef HAVE_ISNAND_IN_LIBC */
-
-/* Define if the isnan(float) function is available in libc. */
-/* #undef HAVE_ISNANF_IN_LIBC */
-
-/* Define if the isnan(long double) function is available in libc. */
-/* #undef HAVE_ISNANL_IN_LIBC */
-
-/* Define to 1 if you have the `issetugid' function. */
-/* #undef HAVE_ISSETUGID */
-
-/* Define to 1 if you have the `iswcntrl' function. */
-#define HAVE_ISWCNTRL 1
-
-/* Define to 1 if you have the `iswctype' function. */
-#define HAVE_ISWCTYPE 1
-
-/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
-/* #undef HAVE_LANGINFO_CODESET */
-
-/* Define to 1 if you have the <langinfo.h> header file. */
-/* #undef HAVE_LANGINFO_H */
-
-/* Define if your <locale.h> file defines LC_MESSAGES. */
-/* #undef HAVE_LC_MESSAGES */
-
-/* Define if the ldexpl function is available in libc. */
-/* #undef HAVE_LDEXPL_IN_LIBC */
-
-/* Define if the ldexp function is available in libc. */
-#define HAVE_LDEXP_IN_LIBC 1
-
-/* Define to 1 if you have the <libintl.h> header file. */
-/* #undef HAVE_LIBINTL_H */
-
-/* Define if you have the libsigsegv library. */
-/* #undef HAVE_LIBSIGSEGV */
-
-/* Define to 1 if you have the `link' function. */
-/* #undef HAVE_LINK */
-
-/* Define to 1 if the system has the type `long long int'. */
-#define HAVE_LONG_LONG_INT 1
-
-/* Define to 1 if you have the `lstat' function. */
-/* #undef HAVE_LSTAT */
-
-/* Define to 1 if your system has a GNU libc compatible 'malloc' function, and
- to 0 otherwise. */
-#define HAVE_MALLOC_GNU 1
-
-/* Define if the 'malloc' function is POSIX compliant. */
-/* #undef HAVE_MALLOC_POSIX */
-
-/* Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
- config.h and <sys/mman.h>. */
-/* #undef HAVE_MAP_ANONYMOUS */
-
-/* Define to 1 if you have the <math.h> header file. */
-#define HAVE_MATH_H 1
-
-/* Define to 1 if you have the `mbrtowc' function. */
-#define HAVE_MBRTOWC 1
-
-/* Define to 1 if you have the `mbsinit' function. */
-/* #undef HAVE_MBSINIT */
-
-/* Define to 1 if <wchar.h> declares mbstate_t. */
-#define HAVE_MBSTATE_T 1
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the `mempcpy' function. */
-/* #undef HAVE_MEMPCPY */
-
-/* Define to 1 if you have the `mkdtemp' function. */
-/* #undef HAVE_MKDTEMP */
-
-/* Define to 1 if you have the `mkstemp' function. */
-/* #undef HAVE_MKSTEMP */
-
-/* Define to 1 if you have the `mprotect' function. */
-/* #undef HAVE_MPROTECT */
-
-/* Define to 1 on MSVC platforms that have the "invalid parameter handler"
- concept. */
-#define HAVE_MSVC_INVALID_PARAMETER_HANDLER 1
-
-/* Define to 1 if you have the `newlocale' function. */
-/* #undef HAVE_NEWLOCALE */
-
-/* Define to 1 if you have the `nl_langinfo' function. */
-/* #undef HAVE_NL_LANGINFO */
-
-/* Define to 1 if libc includes obstacks. */
-/* #undef HAVE_OBSTACK */
-
-/* Define to 1 if you have the `opendir' function. */
-/* #undef HAVE_OPENDIR */
-
-/* Define to 1 if you have the <OS.h> header file. */
-/* #undef HAVE_OS_H */
-
-/* Define to 1 if you have the <paths.h> header file. */
-/* #undef HAVE_PATHS_H */
-
-/* Define to 1 if you have the `pipe' function. */
-/* #undef HAVE_PIPE */
-
-/* Define to 1 if you have the `pipe2' function. */
-/* #undef HAVE_PIPE2 */
-
-/* Define to 1 if you have the `posix_spawn' function. */
-/* #undef HAVE_POSIX_SPAWN */
-
-/* Define to 1 if the system has the type `posix_spawnattr_t'. */
-/* #undef HAVE_POSIX_SPAWNATTR_T */
-
-/* Define to 1 if the system has the type `posix_spawn_file_actions_t'. */
-/* #undef HAVE_POSIX_SPAWN_FILE_ACTIONS_T */
-
-/* Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE. */
-/* #undef HAVE_PTHREAD_MUTEX_RECURSIVE */
-
-/* Define if the POSIX multithreading library has read/write locks. */
-/* #undef HAVE_PTHREAD_RWLOCK */
-
-/* Define to 1 if you have the `raise' function. */
-#define HAVE_RAISE 1
-
-/* Define to 1 if you have the `rawmemchr' function. */
-/* #undef HAVE_RAWMEMCHR */
-
-/* Define to 1 if you have the `readdir' function. */
-/* #undef HAVE_READDIR */
-
-/* Define to 1 if you have the `readlink' function. */
-/* #undef HAVE_READLINK */
-
-/* Define to 1 if you have the `realpath' function. */
-/* #undef HAVE_REALPATH */
-
-/* Define to 1 if 'long double' and 'double' have the same representation. */
-#define HAVE_SAME_LONG_DOUBLE_AS_DOUBLE 1
-
-/* Define to 1 if you have the <sched.h> header file. */
-/* #undef HAVE_SCHED_H */
-
-/* Define to 1 if you have the `sched_setparam' function. */
-/* #undef HAVE_SCHED_SETPARAM */
-
-/* Define to 1 if you have the `sched_setscheduler' function. */
-/* #undef HAVE_SCHED_SETSCHEDULER */
-
-/* Define to 1 if you have the <search.h> header file. */
-#define HAVE_SEARCH_H 1
-
-/* Define to 1 if you have the `secure_getenv' function. */
-/* #undef HAVE_SECURE_GETENV */
-
-/* Define to 1 if you have the `setegid' function. */
-/* #undef HAVE_SETEGID */
-
-/* Define to 1 if you have the `setenv' function. */
-/* #undef HAVE_SETENV */
-
-/* Define to 1 if you have the `seteuid' function. */
-/* #undef HAVE_SETEUID */
-
-/* Define to 1 if you have the `setlocale' function. */
-#define HAVE_SETLOCALE 1
-
-/* Define to 1 if you have the `setrlimit' function. */
-/* #undef HAVE_SETRLIMIT */
-
-/* Define to 1 if you have the `sigaction' function. */
-/* #undef HAVE_SIGACTION */
-
-/* Define to 1 if you have the `sigaltstack' function. */
-/* #undef HAVE_SIGALTSTACK */
-
-/* Define to 1 if the system has the type `siginfo_t'. */
-/* #undef HAVE_SIGINFO_T */
-
-/* Define to 1 if you have the `siginterrupt' function. */
-/* #undef HAVE_SIGINTERRUPT */
-
-/* Define to 1 if 'sig_atomic_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_SIG_ATOMIC_T */
-
-/* Define to 1 if 'wchar_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_WCHAR_T */
-
-/* Define to 1 if 'wint_t' is a signed integer type. */
-/* #undef HAVE_SIGNED_WINT_T */
-
-/* Define to 1 if the system has the type `sigset_t'. */
-/* #undef HAVE_SIGSET_T */
-
-/* Define to 1 if the system has the type `sig_atomic_t'. */
-#define HAVE_SIG_ATOMIC_T 1
-
-/* Define to 1 if you have the `sleep' function. */
-/* #undef HAVE_SLEEP */
-
-/* Define to 1 if you have the `snprintf' function. */
+/* Define if building universal (internal helper macro) */
+/* #undef AC_APPLE_UNIVERSAL_BUILD */
+
+/* Define to the number of bits in type 'ptrdiff_t'. */
+/* #undef BITSIZEOF_PTRDIFF_T */
+
+/* Define to the number of bits in type 'sig_atomic_t'. */
+/* #undef BITSIZEOF_SIG_ATOMIC_T */
+
+/* Define to the number of bits in type 'size_t'. */
+/* #undef BITSIZEOF_SIZE_T */
+
+/* Define to the number of bits in type 'wchar_t'. */
+/* #undef BITSIZEOF_WCHAR_T */
+
+/* Define to the number of bits in type 'wint_t'. */
+/* #undef BITSIZEOF_WINT_T */
+
+/* Define if you wish *printf() functions that have a safe handling of
+ non-IEEE-754 'long double' values. */
+#define CHECK_PRINTF_SAFE 1
+
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+ systems. This function is required for `alloca.c' support on those systems.
+ */
+/* #undef CRAY_STACKSEG_END */
+
+/* Define to 1 if using `alloca.c'. */
+/* #undef C_ALLOCA */
+
+/* Define as the bit index in the word where to find bit 0 of the exponent of
+ 'double'. */
+#define DBL_EXPBIT0_BIT 20
+
+/* Define as the word index where to find the exponent of 'double'. */
+#define DBL_EXPBIT0_WORD 1
+
+/* Define as the bit index in the word where to find the sign of 'double'. */
+#define DBL_SIGNBIT_BIT 31
+
+/* Define as the word index where to find the sign of 'double'. */
+#define DBL_SIGNBIT_WORD 1
+
+/* Define to 1 if // is a file system root distinct from /. */
+#define DOUBLE_SLASH_IS_DISTINCT_ROOT 1
+
+/* Define to 1 if the changeword(REGEXP) functionality is wanted */
+/* #undef ENABLE_CHANGEWORD */
+
+/* Define to 1 if an invalid memory address access may yield a SIGBUS. */
+#define FAULT_YIELDS_SIGBUS 0
+
+/* Define this to 1 if F_DUPFD behavior does not match POSIX */
+/* #undef FCNTL_DUPFD_BUGGY */
+
+/* Define as the bit index in the word where to find bit 0 of the exponent of
+ 'float'. */
+#define FLT_EXPBIT0_BIT 23
+
+/* Define as the word index where to find the exponent of 'float'. */
+#define FLT_EXPBIT0_WORD 0
+
+/* Define as the bit index in the word where to find the sign of 'float'. */
+#define FLT_SIGNBIT_BIT 31
+
+/* Define as the word index where to find the sign of 'float'. */
+#define FLT_SIGNBIT_WORD 0
+
+/* Define to 1 if fopen() fails to recognize a trailing slash. */
+#define FOPEN_TRAILING_SLASH_BUG 1
+
+/* Enable compile-time and run-time bounds-checking, and some warnings,
+ without upsetting newer glibc. */
+ #if defined __OPTIMIZE__ && __OPTIMIZE__
+ # define _FORTIFY_SOURCE 2
+ #endif
+
+
+/* Define to 1 if the system's ftello function has the Solaris bug. */
+/* #undef FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE */
+
+/* Define to 1 if fflush is known to work on stdin as per POSIX.1-2008, 0 if
+ fflush is known to not work, -1 if unknown. */
+#define FUNC_FFLUSH_STDIN 0
+
+/* Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string. */
+/* #undef FUNC_NL_LANGINFO_YESEXPR_WORKS */
+
+/* Define to 1 if realpath() can malloc memory, always gives an absolute path,
+ and handles trailing slash correctly. */
+/* #undef FUNC_REALPATH_WORKS */
+
+/* Define to 1 if ungetc is broken when used on arbitrary bytes. */
+/* #undef FUNC_UNGETC_BROKEN */
+
+/* Define if gettimeofday clobbers the localtime buffer. */
+/* #undef GETTIMEOFDAY_CLOBBERS_LOCALTIME */
+
+/* Define this to 'void' or 'struct timezone' to match the system's
+ declaration of the second argument to gettimeofday. */
+#define GETTIMEOFDAY_TIMEZONE void
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module canonicalize-lgpl shall be considered present. */
+#define GNULIB_CANONICALIZE_LGPL 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module close-stream shall be considered present. */
+#define GNULIB_CLOSE_STREAM 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module dirname shall be considered present. */
+#define GNULIB_DIRNAME 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fd-safer-flag shall be considered present. */
+#define GNULIB_FD_SAFER_FLAG 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fflush shall be considered present. */
+#define GNULIB_FFLUSH 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module filenamecat shall be considered present. */
+#define GNULIB_FILENAMECAT 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fopen-safer shall be considered present. */
+#define GNULIB_FOPEN_SAFER 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module fscanf shall be considered present. */
+#define GNULIB_FSCANF 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module lock shall be considered present. */
+#define GNULIB_LOCK 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module malloc-gnu shall be considered present. */
+#define GNULIB_MALLOC_GNU 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module pipe2-safer shall be considered present. */
+#define GNULIB_PIPE2_SAFER 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module scanf shall be considered present. */
+#define GNULIB_SCANF 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module sigpipe shall be considered present. */
+#define GNULIB_SIGPIPE 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module snprintf shall be considered present. */
+#define GNULIB_SNPRINTF 1
+
+/* Define to a C preprocessor expression that evaluates to 1 or 0, depending
+ whether the gnulib module strerror shall be considered present. */
+#define GNULIB_STRERROR 1
+
+/* Define to 1 when the gnulib module btowc should be tested. */
+#define GNULIB_TEST_BTOWC 1
+
+/* Define to 1 when the gnulib module canonicalize_file_name should be tested.
+ */
+#define GNULIB_TEST_CANONICALIZE_FILE_NAME 1
+
+/* Define to 1 when the gnulib module chdir should be tested. */
+#define GNULIB_TEST_CHDIR 1
+
+/* Define to 1 when the gnulib module cloexec should be tested. */
+#define GNULIB_TEST_CLOEXEC 1
+
+/* Define to 1 when the gnulib module close should be tested. */
+#define GNULIB_TEST_CLOSE 1
+
+/* Define to 1 when the gnulib module closedir should be tested. */
+#define GNULIB_TEST_CLOSEDIR 1
+
+/* Define to 1 when the gnulib module dup should be tested. */
+#define GNULIB_TEST_DUP 1
+
+/* Define to 1 when the gnulib module dup2 should be tested. */
+#define GNULIB_TEST_DUP2 1
+
+/* Define to 1 when the gnulib module environ should be tested. */
+#define GNULIB_TEST_ENVIRON 1
+
+/* Define to 1 when the gnulib module fclose should be tested. */
+#define GNULIB_TEST_FCLOSE 1
+
+/* Define to 1 when the gnulib module fcntl should be tested. */
+#define GNULIB_TEST_FCNTL 1
+
+/* Define to 1 when the gnulib module fdopen should be tested. */
+#define GNULIB_TEST_FDOPEN 1
+
+/* Define to 1 when the gnulib module fflush should be tested. */
+#define GNULIB_TEST_FFLUSH 1
+
+/* Define to 1 when the gnulib module fopen should be tested. */
+#define GNULIB_TEST_FOPEN 1
+
+/* Define to 1 when the gnulib module fpurge should be tested. */
+#define GNULIB_TEST_FPURGE 1
+
+/* Define to 1 when the gnulib module frexp should be tested. */
+#define GNULIB_TEST_FREXP 1
+
+/* Define to 1 when the gnulib module frexpl should be tested. */
+#define GNULIB_TEST_FREXPL 1
+
+/* Define to 1 when the gnulib module fseek should be tested. */
+#define GNULIB_TEST_FSEEK 1
+
+/* Define to 1 when the gnulib module fseeko should be tested. */
+#define GNULIB_TEST_FSEEKO 1
+
+/* Define to 1 when the gnulib module fstat should be tested. */
+#define GNULIB_TEST_FSTAT 1
+
+/* Define to 1 when the gnulib module ftell should be tested. */
+#define GNULIB_TEST_FTELL 1
+
+/* Define to 1 when the gnulib module ftello should be tested. */
+#define GNULIB_TEST_FTELLO 1
+
+/* Define to 1 when the gnulib module getcwd should be tested. */
+#define GNULIB_TEST_GETCWD 1
+
+/* Define to 1 when the gnulib module getdtablesize should be tested. */
+#define GNULIB_TEST_GETDTABLESIZE 1
+
+/* Define to 1 when the gnulib module getopt-gnu should be tested. */
+#define GNULIB_TEST_GETOPT_GNU 1
+
+/* Define to 1 when the gnulib module getpagesize should be tested. */
+#define GNULIB_TEST_GETPAGESIZE 1
+
+/* Define to 1 when the gnulib module gettimeofday should be tested. */
+#define GNULIB_TEST_GETTIMEOFDAY 1
+
+/* Define to 1 when the gnulib module link should be tested. */
+#define GNULIB_TEST_LINK 1
+
+/* Define to 1 when the gnulib module localeconv should be tested. */
+#define GNULIB_TEST_LOCALECONV 1
+
+/* Define to 1 when the gnulib module lseek should be tested. */
+#define GNULIB_TEST_LSEEK 1
+
+/* Define to 1 when the gnulib module lstat should be tested. */
+#define GNULIB_TEST_LSTAT 1
+
+/* Define to 1 when the gnulib module malloc-posix should be tested. */
+#define GNULIB_TEST_MALLOC_POSIX 1
+
+/* Define to 1 when the gnulib module mbrtowc should be tested. */
+#define GNULIB_TEST_MBRTOWC 1
+
+/* Define to 1 when the gnulib module mbsinit should be tested. */
+#define GNULIB_TEST_MBSINIT 1
+
+/* Define to 1 when the gnulib module mbtowc should be tested. */
+#define GNULIB_TEST_MBTOWC 1
+
+/* Define to 1 when the gnulib module memchr should be tested. */
+#define GNULIB_TEST_MEMCHR 1
+
+/* Define to 1 when the gnulib module mkdtemp should be tested. */
+#define GNULIB_TEST_MKDTEMP 1
+
+/* Define to 1 when the gnulib module mkstemp should be tested. */
+#define GNULIB_TEST_MKSTEMP 1
+
+/* Define to 1 when the gnulib module nl_langinfo should be tested. */
+#define GNULIB_TEST_NL_LANGINFO 1
+
+/* Define to 1 when the gnulib module open should be tested. */
+#define GNULIB_TEST_OPEN 1
+
+/* Define to 1 when the gnulib module opendir should be tested. */
+#define GNULIB_TEST_OPENDIR 1
+
+/* Define to 1 when the gnulib module pipe2 should be tested. */
+#define GNULIB_TEST_PIPE2 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_destroy should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWNATTR_DESTROY 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_init should be tested.
+ */
+#define GNULIB_TEST_POSIX_SPAWNATTR_INIT 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_setflags should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWNATTR_SETFLAGS 1
+
+/* Define to 1 when the gnulib module posix_spawnattr_setsigmask should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWNATTR_SETSIGMASK 1
+
+/* Define to 1 when the gnulib module posix_spawnp should be tested. */
+#define GNULIB_TEST_POSIX_SPAWNP 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_addclose should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_adddup2 should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_addopen should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_destroy should
+ be tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_DESTROY 1
+
+/* Define to 1 when the gnulib module posix_spawn_file_actions_init should be
+ tested. */
+#define GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_INIT 1
+
+/* Define to 1 when the gnulib module putenv should be tested. */
+#define GNULIB_TEST_PUTENV 1
+
+/* Define to 1 when the gnulib module raise should be tested. */
+#define GNULIB_TEST_RAISE 1
+
+/* Define to 1 when the gnulib module rawmemchr should be tested. */
+#define GNULIB_TEST_RAWMEMCHR 1
+
+/* Define to 1 when the gnulib module readdir should be tested. */
+#define GNULIB_TEST_READDIR 1
+
+/* Define to 1 when the gnulib module readlink should be tested. */
+#define GNULIB_TEST_READLINK 1
+
+/* Define to 1 when the gnulib module realpath should be tested. */
+#define GNULIB_TEST_REALPATH 1
+
+/* Define to 1 when the gnulib module rename should be tested. */
+#define GNULIB_TEST_RENAME 1
+
+/* Define to 1 when the gnulib module rmdir should be tested. */
+#define GNULIB_TEST_RMDIR 1
+
+/* Define to 1 when the gnulib module secure_getenv should be tested. */
+#define GNULIB_TEST_SECURE_GETENV 1
+
+/* Define to 1 when the gnulib module setenv should be tested. */
+#define GNULIB_TEST_SETENV 1
+
+/* Define to 1 when the gnulib module setlocale should be tested. */
+#define GNULIB_TEST_SETLOCALE 1
+
+/* Define to 1 when the gnulib module sigaction should be tested. */
+#define GNULIB_TEST_SIGACTION 1
+
+/* Define to 1 when the gnulib module signbit should be tested. */
+#define GNULIB_TEST_SIGNBIT 1
+
+/* Define to 1 when the gnulib module sigprocmask should be tested. */
+#define GNULIB_TEST_SIGPROCMASK 1
+
+/* Define to 1 when the gnulib module sleep should be tested. */
+#define GNULIB_TEST_SLEEP 1
+
+/* Define to 1 when the gnulib module snprintf should be tested. */
+#define GNULIB_TEST_SNPRINTF 1
+
+/* Define to 1 when the gnulib module stat should be tested. */
+#define GNULIB_TEST_STAT 1
+
+/* Define to 1 when the gnulib module strchrnul should be tested. */
+#define GNULIB_TEST_STRCHRNUL 1
+
+/* Define to 1 when the gnulib module strdup should be tested. */
+#define GNULIB_TEST_STRDUP 1
+
+/* Define to 1 when the gnulib module strerror should be tested. */
+#define GNULIB_TEST_STRERROR 1
+
+/* Define to 1 when the gnulib module strndup should be tested. */
+#define GNULIB_TEST_STRNDUP 1
+
+/* Define to 1 when the gnulib module strnlen should be tested. */
+#define GNULIB_TEST_STRNLEN 1
+
+/* Define to 1 when the gnulib module strsignal should be tested. */
+#define GNULIB_TEST_STRSIGNAL 1
+
+/* Define to 1 when the gnulib module strstr should be tested. */
+#define GNULIB_TEST_STRSTR 1
+
+/* Define to 1 when the gnulib module strtod should be tested. */
+#define GNULIB_TEST_STRTOD 1
+
+/* Define to 1 when the gnulib module symlink should be tested. */
+#define GNULIB_TEST_SYMLINK 1
+
+/* Define to 1 when the gnulib module unsetenv should be tested. */
+#define GNULIB_TEST_UNSETENV 1
+
+/* Define to 1 when the gnulib module vasprintf should be tested. */
+#define GNULIB_TEST_VASPRINTF 1
+
+/* Define to 1 when the gnulib module waitpid should be tested. */
+#define GNULIB_TEST_WAITPID 1
+
+/* Define to 1 when the gnulib module wcrtomb should be tested. */
+#define GNULIB_TEST_WCRTOMB 1
+
+/* Define to 1 when the gnulib module wctob should be tested. */
+#define GNULIB_TEST_WCTOB 1
+
+/* Define to 1 when the gnulib module wctomb should be tested. */
+#define GNULIB_TEST_WCTOMB 1
+
+/* Define to 1 when the gnulib module write should be tested. */
+#define GNULIB_TEST_WRITE 1
+
+/* Define to 1 if you have 'alloca' after including <alloca.h>, a header that
+ may be supplied by this distribution. */
+#define HAVE_ALLOCA 1
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+ */
+/* #undef HAVE_ALLOCA_H */
+
+/* Define to 1 if you have the <bp-sym.h> header file. */
+/* #undef HAVE_BP_SYM_H */
+
+/* Define to 1 if you have the `btowc' function. */
+#define HAVE_BTOWC 1
+
+/* Define to 1 if you have the `canonicalize_file_name' function. */
+/* #undef HAVE_CANONICALIZE_FILE_NAME */
+
+/* Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the
+ CoreFoundation framework. */
+/* #undef HAVE_CFLOCALECOPYCURRENT */
+
+/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
+ the CoreFoundation framework. */
+/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
+
+/* Define to 1 if you have the `closedir' function. */
+/* #undef HAVE_CLOSEDIR */
+
+/* Define to 1 if you have the `confstr' function. */
+/* #undef HAVE_CONFSTR */
+
+/* Define if the copysignf function is declared in <math.h> and available in
+ libc. */
+/* #undef HAVE_COPYSIGNF_IN_LIBC */
+
+/* Define if the copysignl function is declared in <math.h> and available in
+ libc. */
+/* #undef HAVE_COPYSIGNL_IN_LIBC */
+
+/* Define if the copysign function is declared in <math.h> and available in
+ libc. */
+/* #undef HAVE_COPYSIGN_IN_LIBC */
+
+/* Define to 1 if you have the declaration of `alarm', and to 0 if you don't.
+ */
+#define HAVE_DECL_ALARM 0
+
+/* Define to 1 if you have the declaration of `clearerr_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_CLEARERR_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `copysign', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_COPYSIGN */
+
+/* Define to 1 if you have the declaration of `copysignf', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_COPYSIGNF */
+
+/* Define to 1 if you have the declaration of `copysignl', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_COPYSIGNL */
+
+/* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you
+ don't. */
+#define HAVE_DECL_FEOF_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `ferror_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_FERROR_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `fflush_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_FFLUSH_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_FGETS_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `fpurge', and to 0 if you don't.
+ */
+#define HAVE_DECL_FPURGE 0
+
+/* Define to 1 if you have the declaration of `fputc_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_FPUTC_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `fputs_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_FPUTS_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `fread_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_FREAD_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `fseeko', and to 0 if you don't.
+ */
+#define HAVE_DECL_FSEEKO 0
+
+/* Define to 1 if you have the declaration of `ftello', and to 0 if you don't.
+ */
+#define HAVE_DECL_FTELLO 0
+
+/* Define to 1 if you have the declaration of `fwrite_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_FWRITE_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `getchar_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_GETCHAR_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
+ don't. */
+#define HAVE_DECL_GETC_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
+ */
+#define HAVE_DECL_GETENV 1
+
+/* Define to 1 if you have the declaration of `isblank', and to 0 if you
+ don't. */
+#define HAVE_DECL_ISBLANK 0
+
+/* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_MBRTOWC */
+
+/* Define to 1 if you have the declaration of `mbsinit', and to 0 if you
+ don't. */
+#define HAVE_DECL_MBSINIT 1
+
+/* Define to 1 if you have the declaration of `program_invocation_name', and
+ to 0 if you don't. */
+#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
+
+/* Define to 1 if you have the declaration of `program_invocation_short_name',
+ and to 0 if you don't. */
+#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 0
+
+/* Define to 1 if you have the declaration of `putchar_unlocked', and to 0 if
+ you don't. */
+#define HAVE_DECL_PUTCHAR_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `putc_unlocked', and to 0 if you
+ don't. */
+#define HAVE_DECL_PUTC_UNLOCKED 0
+
+/* Define to 1 if you have the declaration of `setenv', and to 0 if you don't.
+ */
+#define HAVE_DECL_SETENV 0
+
+/* Define to 1 if you have the declaration of `sigaltstack', and to 0 if you
+ don't. */
+#define HAVE_DECL_SIGALTSTACK 0
+
+/* Define to 1 if you have the declaration of `sleep', and to 0 if you don't.
+ */
+#define HAVE_DECL_SLEEP 0
+
+/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
+ don't. */
+#define HAVE_DECL_SNPRINTF 0
+
+/* Define to 1 if you have the declaration of `strdup', and to 0 if you don't.
+ */
+#define HAVE_DECL_STRDUP 1
+
+/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRERROR_R 0
+
+/* Define to 1 if you have the declaration of `strndup', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNDUP 0
+
+/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNLEN 1
+
+/* Define to 1 if you have the declaration of `strsignal', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRSIGNAL 0
+
+/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
+ don't. */
+#define HAVE_DECL_SYS_SIGLIST 0
+
+/* Define to 1 if you have the declaration of `towlower', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_TOWLOWER */
+
+/* Define to 1 if you have the declaration of `unsetenv', and to 0 if you
+ don't. */
+#define HAVE_DECL_UNSETENV 0
+
+/* Define to 1 if you have the declaration of `wcrtomb', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_WCRTOMB */
+
+/* Define to 1 if you have the declaration of `wctob', and to 0 if you don't.
+ */
+/* #undef HAVE_DECL_WCTOB */
+
+/* Define to 1 if you have the declaration of `_putenv', and to 0 if you
+ don't. */
+#define HAVE_DECL__PUTENV 1
+
+/* Define to 1 if you have the declaration of `_snprintf', and to 0 if you
+ don't. */
+#define HAVE_DECL__SNPRINTF 1
+
+/* Define to 1 if you have the declaration of `_sys_siglist', and to 0 if you
+ don't. */
+#define HAVE_DECL__SYS_SIGLIST 0
+
+/* Define to 1 if you have the <dirent.h> header file. */
+/* #undef HAVE_DIRENT_H */
+
+/* Define to 1 if you have the 'dup2' function. */
+#define HAVE_DUP2 1
+
+/* Define if you have the declaration of environ. */
+#define HAVE_ENVIRON_DECL 1
+
+/* Define to 1 if you have the `fcntl' function. */
+/* #undef HAVE_FCNTL */
+
+/* Define to 1 if you have the <features.h> header file. */
+/* #undef HAVE_FEATURES_H */
+
+/* Define to 1 if you have the `fpurge' function. */
+/* #undef HAVE_FPURGE */
+
+/* Define if the frexpl function is available in libc. */
+/* #undef HAVE_FREXPL_IN_LIBC */
+
+/* Define if the frexp function is available in libc. */
+/* #undef HAVE_FREXP_IN_LIBC */
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+/* #undef HAVE_FSEEKO */
+
+/* Define to 1 if you have the `getcwd' function. */
+#define HAVE_GETCWD 1
+
+/* Define to 1 if you have the `getdtablesize' function. */
+/* #undef HAVE_GETDTABLESIZE */
+
+/* Define to 1 if you have the <getopt.h> header file. */
+/* #undef HAVE_GETOPT_H */
+
+/* Define to 1 if you have the `getopt_long_only' function. */
+/* #undef HAVE_GETOPT_LONG_ONLY */
+
+/* Define to 1 if you have the `getpagesize' function. */
+/* #undef HAVE_GETPAGESIZE */
+
+/* Define to 1 if you have the `gettimeofday' function. */
+/* #undef HAVE_GETTIMEOFDAY */
+
+/* Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>. */
+#define HAVE_INTMAX_T 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+/* #undef HAVE_INTTYPES_H */
+
+/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and
+ declares uintmax_t. */
+/* #undef HAVE_INTTYPES_H_WITH_UINTMAX */
+
+/* Define to 1 if you have the `isblank' function. */
+/* #undef HAVE_ISBLANK */
+
+/* Define if the isnan(double) function is available in libc. */
+/* #undef HAVE_ISNAND_IN_LIBC */
+
+/* Define if the isnan(float) function is available in libc. */
+/* #undef HAVE_ISNANF_IN_LIBC */
+
+/* Define if the isnan(long double) function is available in libc. */
+/* #undef HAVE_ISNANL_IN_LIBC */
+
+/* Define to 1 if you have the `issetugid' function. */
+/* #undef HAVE_ISSETUGID */
+
+/* Define to 1 if you have the `iswcntrl' function. */
+#define HAVE_ISWCNTRL 1
+
+/* Define to 1 if you have the `iswctype' function. */
+#define HAVE_ISWCTYPE 1
+
+/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
+/* #undef HAVE_LANGINFO_CODESET */
+
+/* Define to 1 if you have the <langinfo.h> header file. */
+/* #undef HAVE_LANGINFO_H */
+
+/* Define if your <locale.h> file defines LC_MESSAGES. */
+/* #undef HAVE_LC_MESSAGES */
+
+/* Define if the ldexpl function is available in libc. */
+/* #undef HAVE_LDEXPL_IN_LIBC */
+
+/* Define if the ldexp function is available in libc. */
+#define HAVE_LDEXP_IN_LIBC 1
+
+/* Define to 1 if you have the <libintl.h> header file. */
+/* #undef HAVE_LIBINTL_H */
+
+/* Define if you have the libsigsegv library. */
+/* #undef HAVE_LIBSIGSEGV */
+
+/* Define to 1 if you have the `link' function. */
+/* #undef HAVE_LINK */
+
+/* Define to 1 if the system has the type `long long int'. */
+#define HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `lstat' function. */
+/* #undef HAVE_LSTAT */
+
+/* Define to 1 if your system has a GNU libc compatible 'malloc' function, and
+ to 0 otherwise. */
+#define HAVE_MALLOC_GNU 1
+
+/* Define if the 'malloc' function is POSIX compliant. */
+/* #undef HAVE_MALLOC_POSIX */
+
+/* Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
+ config.h and <sys/mman.h>. */
+/* #undef HAVE_MAP_ANONYMOUS */
+
+/* Define to 1 if you have the <math.h> header file. */
+#define HAVE_MATH_H 1
+
+/* Define to 1 if you have the `mbrtowc' function. */
+#define HAVE_MBRTOWC 1
+
+/* Define to 1 if you have the `mbsinit' function. */
+/* #undef HAVE_MBSINIT */
+
+/* Define to 1 if <wchar.h> declares mbstate_t. */
+#define HAVE_MBSTATE_T 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `mempcpy' function. */
+/* #undef HAVE_MEMPCPY */
+
+/* Define to 1 if you have the `mkdtemp' function. */
+/* #undef HAVE_MKDTEMP */
+
+/* Define to 1 if you have the `mkstemp' function. */
+/* #undef HAVE_MKSTEMP */
+
+/* Define to 1 if you have the `mprotect' function. */
+/* #undef HAVE_MPROTECT */
+
+/* Define to 1 on MSVC platforms that have the "invalid parameter handler"
+ concept. */
+#define HAVE_MSVC_INVALID_PARAMETER_HANDLER 1
+
+/* Define to 1 if you have the `newlocale' function. */
+/* #undef HAVE_NEWLOCALE */
+
+/* Define to 1 if you have the `nl_langinfo' function. */
+/* #undef HAVE_NL_LANGINFO */
+
+/* Define to 1 if libc includes obstacks. */
+/* #undef HAVE_OBSTACK */
+
+/* Define to 1 if you have the `opendir' function. */
+/* #undef HAVE_OPENDIR */
+
+/* Define to 1 if you have the <OS.h> header file. */
+/* #undef HAVE_OS_H */
+
+/* Define to 1 if you have the <paths.h> header file. */
+/* #undef HAVE_PATHS_H */
+
+/* Define to 1 if you have the `pipe' function. */
+/* #undef HAVE_PIPE */
+
+/* Define to 1 if you have the `pipe2' function. */
+/* #undef HAVE_PIPE2 */
+
+/* Define to 1 if you have the `posix_spawn' function. */
+/* #undef HAVE_POSIX_SPAWN */
+
+/* Define to 1 if the system has the type `posix_spawnattr_t'. */
+/* #undef HAVE_POSIX_SPAWNATTR_T */
+
+/* Define to 1 if the system has the type `posix_spawn_file_actions_t'. */
+/* #undef HAVE_POSIX_SPAWN_FILE_ACTIONS_T */
+
+/* Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE. */
+/* #undef HAVE_PTHREAD_MUTEX_RECURSIVE */
+
+/* Define if the POSIX multithreading library has read/write locks. */
+/* #undef HAVE_PTHREAD_RWLOCK */
+
+/* Define to 1 if you have the `raise' function. */
+#define HAVE_RAISE 1
+
+/* Define to 1 if you have the `rawmemchr' function. */
+/* #undef HAVE_RAWMEMCHR */
+
+/* Define to 1 if you have the `readdir' function. */
+/* #undef HAVE_READDIR */
+
+/* Define to 1 if you have the `readlink' function. */
+/* #undef HAVE_READLINK */
+
+/* Define to 1 if you have the `realpath' function. */
+/* #undef HAVE_REALPATH */
+
+/* Define to 1 if 'long double' and 'double' have the same representation. */
+#define HAVE_SAME_LONG_DOUBLE_AS_DOUBLE 1
+
+/* Define to 1 if you have the <sched.h> header file. */
+/* #undef HAVE_SCHED_H */
+
+/* Define to 1 if you have the `sched_setparam' function. */
+/* #undef HAVE_SCHED_SETPARAM */
+
+/* Define to 1 if you have the `sched_setscheduler' function. */
+/* #undef HAVE_SCHED_SETSCHEDULER */
+
+/* Define to 1 if you have the <search.h> header file. */
+#define HAVE_SEARCH_H 1
+
+/* Define to 1 if you have the `secure_getenv' function. */
+/* #undef HAVE_SECURE_GETENV */
+
+/* Define to 1 if you have the `setegid' function. */
+/* #undef HAVE_SETEGID */
+
+/* Define to 1 if you have the `setenv' function. */
+/* #undef HAVE_SETENV */
+
+/* Define to 1 if you have the `seteuid' function. */
+/* #undef HAVE_SETEUID */
+
+/* Define to 1 if you have the `setlocale' function. */
+#define HAVE_SETLOCALE 1
+
+/* Define to 1 if you have the `setrlimit' function. */
+/* #undef HAVE_SETRLIMIT */
+
+/* Define to 1 if you have the `sigaction' function. */
+/* #undef HAVE_SIGACTION */
+
+/* Define to 1 if you have the `sigaltstack' function. */
+/* #undef HAVE_SIGALTSTACK */
+
+/* Define to 1 if the system has the type `siginfo_t'. */
+/* #undef HAVE_SIGINFO_T */
+
+/* Define to 1 if you have the `siginterrupt' function. */
+/* #undef HAVE_SIGINTERRUPT */
+
+/* Define to 1 if 'sig_atomic_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_SIG_ATOMIC_T */
+
+/* Define to 1 if 'wchar_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_WCHAR_T */
+
+/* Define to 1 if 'wint_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_WINT_T */
+
+/* Define to 1 if the system has the type `sigset_t'. */
+/* #undef HAVE_SIGSET_T */
+
+/* Define to 1 if the system has the type `sig_atomic_t'. */
+#define HAVE_SIG_ATOMIC_T 1
+
+/* Define to 1 if you have the `sleep' function. */
+/* #undef HAVE_SLEEP */
+
+/* Define to 1 if you have the `snprintf' function. */
#define HAVE_SNPRINTF 1
-
-/* Define if the return value of the snprintf function is the number of of
- bytes (excluding the terminating NUL) that would have been produced if the
- buffer had been large enough. */
-/* #undef HAVE_SNPRINTF_RETVAL_C99 */
-
-/* Define to 1 if you have the <spawn.h> header file. */
-/* #undef HAVE_SPAWN_H */
-
-/* Define to 1 if extending the stack slightly past the limit causes a SIGSEGV
- which can be handled on an alternate stack established with sigaltstack. */
-/* #undef HAVE_STACK_OVERFLOW_HANDLING */
-
-/* Define to 1 if the system has the type `stack_t'. */
-/* #undef HAVE_STACK_T */
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#define HAVE_STDINT_H 1
-
-/* Define if <stdint.h> exists, doesn't clash with <sys/types.h>, and declares
- uintmax_t. */
-#define HAVE_STDINT_H_WITH_UINTMAX 1
-
-/* Define to 1 if you have the <stdio_ext.h> header file. */
-/* #undef HAVE_STDIO_EXT_H */
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the `strchrnul' function. */
-/* #undef HAVE_STRCHRNUL */
-
-/* Define to 1 if you have the `strdup' function. */
-#define HAVE_STRDUP 1
-
-/* Define to 1 if you have the `strerror_r' function. */
-/* #undef HAVE_STRERROR_R */
-
-/* Define to 1 if you have the <strings.h> header file. */
-/* #undef HAVE_STRINGS_H */
-
-/* Define to 1 if you have the <string.h> header file. */
-#define HAVE_STRING_H 1
-
-/* Define to 1 if you have the `strndup' function. */
-/* #undef HAVE_STRNDUP */
-
-/* Define to 1 if you have the `strnlen' function. */
-#define HAVE_STRNLEN 1
-
-/* Define to 1 if you have the `strsignal' function. */
-/* #undef HAVE_STRSIGNAL */
+
+/* Define if the return value of the snprintf function is the number of of
+ bytes (excluding the terminating NUL) that would have been produced if the
+ buffer had been large enough. */
+/* #undef HAVE_SNPRINTF_RETVAL_C99 */
+
+/* Define to 1 if you have the <spawn.h> header file. */
+/* #undef HAVE_SPAWN_H */
+
+/* Define to 1 if extending the stack slightly past the limit causes a SIGSEGV
+ which can be handled on an alternate stack established with sigaltstack. */
+/* #undef HAVE_STACK_OVERFLOW_HANDLING */
+
+/* Define to 1 if the system has the type `stack_t'. */
+/* #undef HAVE_STACK_T */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define if <stdint.h> exists, doesn't clash with <sys/types.h>, and declares
+ uintmax_t. */
+#define HAVE_STDINT_H_WITH_UINTMAX 1
+
+/* Define to 1 if you have the <stdio_ext.h> header file. */
+/* #undef HAVE_STDIO_EXT_H */
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strchrnul' function. */
+/* #undef HAVE_STRCHRNUL */
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+/* #undef HAVE_STRERROR_R */
+
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strndup' function. */
+/* #undef HAVE_STRNDUP */
+
+/* Define to 1 if you have the `strnlen' function. */
+#define HAVE_STRNLEN 1
+
+/* Define to 1 if you have the `strsignal' function. */
+/* #undef HAVE_STRSIGNAL */
char *strsignal (int signum);
-
-/* Define to 1 if `decimal_point' is a member of `struct lconv'. */
-#define HAVE_STRUCT_LCONV_DECIMAL_POINT 1
-
-/* Define to 1 if `sa_sigaction' is a member of `struct sigaction'. */
-/* #undef HAVE_STRUCT_SIGACTION_SA_SIGACTION */
-
-/* Define to 1 if you have the `symlink' function. */
-/* #undef HAVE_SYMLINK */
-
-/* Define to 1 if you have the <sys/bitypes.h> header file. */
-/* #undef HAVE_SYS_BITYPES_H */
-
-/* Define to 1 if you have the <sys/inttypes.h> header file. */
-/* #undef HAVE_SYS_INTTYPES_H */
-
-/* Define to 1 if you have the <sys/mman.h> header file. */
-/* #undef HAVE_SYS_MMAN_H */
-
-/* Define to 1 if you have the <sys/param.h> header file. */
-/* #undef HAVE_SYS_PARAM_H */
-
-/* Define to 1 if you have the <sys/socket.h> header file. */
-/* #undef HAVE_SYS_SOCKET_H */
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/timeb.h> header file. */
-#define HAVE_SYS_TIMEB_H 1
-
-/* Define to 1 if you have the <sys/time.h> header file. */
-/* #undef HAVE_SYS_TIME_H */
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define to 1 if you have the <sys/wait.h> header file. */
-/* #undef HAVE_SYS_WAIT_H */
-
-/* Define to 1 if you have the `towlower' function. */
-#define HAVE_TOWLOWER 1
-
-/* Define to 1 if you have the `tsearch' function. */
-/* #undef HAVE_TSEARCH */
-
-/* Define to 1 if you have the <ucontext.h> header file. */
-/* #undef HAVE_UCONTEXT_H */
-
-/* Define to 1 if you have the <unistd.h> header file. */
-/* #undef HAVE_UNISTD_H */
-
-/* Define to 1 if you have the `unsetenv' function. */
-/* #undef HAVE_UNSETENV */
-
-/* Define to 1 if the system has the type 'unsigned long long int'. */
-#define HAVE_UNSIGNED_LONG_LONG_INT 1
-
-/* Define to 1 if you have the `uselocale' function. */
-/* #undef HAVE_USELOCALE */
-
-/* Define to 1 if you have the `vasnprintf' function. */
-/* #undef HAVE_VASNPRINTF */
-
-/* Define to 1 if you have the `vasprintf' function. */
-/* #undef HAVE_VASPRINTF */
-
-/* Define to 1 if you have the `vfork' function. */
-/* #undef HAVE_VFORK */
-
-/* Define to 1 if you have the `waitid' function. */
-/* #undef HAVE_WAITID */
-
-/* Define to 1 if you have the <wchar.h> header file. */
-#define HAVE_WCHAR_H 1
-
-/* Define if you have the 'wchar_t' type. */
-#define HAVE_WCHAR_T 1
-
-/* Define to 1 if you have the `wcrtomb' function. */
-#define HAVE_WCRTOMB 1
-
-/* Define to 1 if you have the `wcscoll' function. */
-#define HAVE_WCSCOLL 1
-
-/* Define to 1 if you have the `wcslen' function. */
-#define HAVE_WCSLEN 1
-
-/* Define to 1 if you have the `wcsnlen' function. */
-#define HAVE_WCSNLEN 1
-
-/* Define to 1 if you have the `wctob' function. */
-#define HAVE_WCTOB 1
-
-/* Define to 1 if you have the <wctype.h> header file. */
-#define HAVE_WCTYPE_H 1
-
-/* Define to 1 if you have the <winsock2.h> header file. */
-/* #undef HAVE_WINSOCK2_H */
-
-/* Define if you have the 'wint_t' type. */
-#define HAVE_WINT_T 1
-
-/* Define to 1 if O_NOATIME works. */
-#define HAVE_WORKING_O_NOATIME 0
-
-/* Define to 1 if O_NOFOLLOW works. */
-#define HAVE_WORKING_O_NOFOLLOW 0
-
-/* Define if you have the posix_spawn and posix_spawnp functions and they
- work. */
-/* #undef HAVE_WORKING_POSIX_SPAWN */
-
-/* Define to 1 if you have the <xlocale.h> header file. */
-/* #undef HAVE_XLOCALE_H */
-
-/* Define to 1 if extending the stack slightly past the limit causes a
- SIGSEGV, and an alternate stack can be established with sigaltstack, and
- the signal handler is passed a context that specifies the run time stack.
- This behavior is defined by POSIX 1003.1-2001 with the X/Open System
- Interface (XSI) option and is a standardized way to implement a SEGV-based
- stack overflow detection heuristic. */
-/* #undef HAVE_XSI_STACK_OVERFLOW_HEURISTIC */
-
-/* Define to 1 if the system has the type `_Bool'. */
-/* #undef HAVE__BOOL */
-
-/* Define to 1 if you have the `_fseeki64' function. */
-#define HAVE__FSEEKI64 1
-
-/* Define to 1 if you have the `_ftelli64' function. */
-#define HAVE__FTELLI64 1
-
-/* Define to 1 if you have the `_ftime' function. */
-#define HAVE__FTIME 1
-
-/* Define to 1 if you have the `_set_invalid_parameter_handler' function. */
-#define HAVE__SET_INVALID_PARAMETER_HANDLER 1
-
-/* Define to 1 if you have the `__fpurge' function. */
-/* #undef HAVE___FPURGE */
-
-/* Define to 1 if you have the `__freadahead' function. */
-/* #undef HAVE___FREADAHEAD */
-
-/* Define to 1 if you have the `__freading' function. */
-/* #undef HAVE___FREADING */
-
-/* Define to 1 if you have the `__secure_getenv' function. */
-/* #undef HAVE___SECURE_GETENV */
-
-/* Define as the bit index in the word where to find bit 0 of the exponent of
- 'long double'. */
-#define LDBL_EXPBIT0_BIT 20
-
-/* Define as the word index where to find the exponent of 'long double'. */
-#define LDBL_EXPBIT0_WORD 1
-
-/* Define as the bit index in the word where to find the sign of 'long
- double'. */
-#define LDBL_SIGNBIT_BIT 31
-
-/* Define as the word index where to find the sign of 'long double'. */
-#define LDBL_SIGNBIT_WORD 1
-
-/* Define to 1 if lseek does not detect pipes. */
-#define LSEEK_PIPE_BROKEN 1
-
-/* Define to 1 if 'lstat' dereferences a symlink specified with a trailing
- slash. */
-/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
-
-/* If malloc(0) is != NULL, define this to 1. Otherwise define this to 0. */
-#define MALLOC_0_IS_NONNULL 1
-
-/* Define to a substitute value for mmap()'s MAP_ANONYMOUS flag. */
-/* #undef MAP_ANONYMOUS */
-
-/* Define if the mbrtowc function has the NULL pwc argument bug. */
-/* #undef MBRTOWC_NULL_ARG1_BUG */
-
-/* Define if the mbrtowc function has the NULL string argument bug. */
-/* #undef MBRTOWC_NULL_ARG2_BUG */
-
-/* Define if the mbrtowc function does not return 0 for a NUL character. */
-/* #undef MBRTOWC_NUL_RETVAL_BUG */
-
-/* Define if the mbrtowc function returns a wrong return value. */
-/* #undef MBRTOWC_RETVAL_BUG */
-
-/* Define to 1 if assertions should be disabled. */
-/* #undef NDEBUG */
-
-/* Define if the vasnprintf implementation needs special code for the 'a' and
- 'A' directives. */
-#define NEED_PRINTF_DIRECTIVE_A 1
-
-/* Define if the vasnprintf implementation needs special code for the 'F'
- directive. */
-#define NEED_PRINTF_DIRECTIVE_F 1
-
-/* Define if the vasnprintf implementation needs special code for the 'ls'
- directive. */
-/* #undef NEED_PRINTF_DIRECTIVE_LS */
-
-/* Define if the vasnprintf implementation needs special code for 'double'
- arguments. */
-#define NEED_PRINTF_DOUBLE 1
-
-/* Define if the vasnprintf implementation needs special code for surviving
- out-of-memory conditions. */
-#define NEED_PRINTF_ENOMEM 1
-
-/* Define if the vasnprintf implementation needs special code for the ' flag.
- */
-#define NEED_PRINTF_FLAG_GROUPING 1
-
-/* Define if the vasnprintf implementation needs special code for the '-'
- flag. */
-/* #undef NEED_PRINTF_FLAG_LEFTADJUST */
-
-/* Define if the vasnprintf implementation needs special code for the 0 flag.
- */
-#define NEED_PRINTF_FLAG_ZERO 1
-
-/* Define if the vasnprintf implementation needs special code for infinite
- 'double' arguments. */
-#define NEED_PRINTF_INFINITE_DOUBLE 1
-
-/* Define if the vasnprintf implementation needs special code for infinite
- 'long double' arguments. */
-/* #undef NEED_PRINTF_INFINITE_LONG_DOUBLE */
-
-/* Define if the vasnprintf implementation needs special code for 'long
- double' arguments. */
-#define NEED_PRINTF_LONG_DOUBLE 1
-
-/* Define if the vasnprintf implementation needs special code for supporting
- large precisions without arbitrary bounds. */
-#define NEED_PRINTF_UNBOUNDED_PRECISION 1
-
-/* Define to 1 if open() fails to recognize a trailing slash. */
-/* #undef OPEN_TRAILING_SLASH_BUG */
-
-/* Name of package */
-#define PACKAGE "m4"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "bug-m4@gnu.org"
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME "GNU M4"
-
-/* String identifying the packager of this software */
-/* #undef PACKAGE_PACKAGER */
-
-/* Packager info for bug reports (URL/e-mail/...) */
-/* #undef PACKAGE_PACKAGER_BUG_REPORTS */
-
-/* Packager-specific version information */
-/* #undef PACKAGE_PACKAGER_VERSION */
-
-/* Define to the full name and version of this package. */
+
+/* Define to 1 if `decimal_point' is a member of `struct lconv'. */
+#define HAVE_STRUCT_LCONV_DECIMAL_POINT 1
+
+/* Define to 1 if `sa_sigaction' is a member of `struct sigaction'. */
+/* #undef HAVE_STRUCT_SIGACTION_SA_SIGACTION */
+
+/* Define to 1 if you have the `symlink' function. */
+/* #undef HAVE_SYMLINK */
+
+/* Define to 1 if you have the <sys/bitypes.h> header file. */
+/* #undef HAVE_SYS_BITYPES_H */
+
+/* Define to 1 if you have the <sys/inttypes.h> header file. */
+/* #undef HAVE_SYS_INTTYPES_H */
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+/* #undef HAVE_SYS_MMAN_H */
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+/* #undef HAVE_SYS_PARAM_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+/* #undef HAVE_SYS_SOCKET_H */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/timeb.h> header file. */
+#define HAVE_SYS_TIMEB_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <sys/wait.h> header file. */
+/* #undef HAVE_SYS_WAIT_H */
+
+/* Define to 1 if you have the `towlower' function. */
+#define HAVE_TOWLOWER 1
+
+/* Define to 1 if you have the `tsearch' function. */
+/* #undef HAVE_TSEARCH */
+
+/* Define to 1 if you have the <ucontext.h> header file. */
+/* #undef HAVE_UCONTEXT_H */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+/* #undef HAVE_UNISTD_H */
+
+/* Define to 1 if you have the `unsetenv' function. */
+/* #undef HAVE_UNSETENV */
+
+/* Define to 1 if the system has the type 'unsigned long long int'. */
+#define HAVE_UNSIGNED_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `uselocale' function. */
+/* #undef HAVE_USELOCALE */
+
+/* Define to 1 if you have the `vasnprintf' function. */
+/* #undef HAVE_VASNPRINTF */
+
+/* Define to 1 if you have the `vasprintf' function. */
+/* #undef HAVE_VASPRINTF */
+
+/* Define to 1 if you have the `vfork' function. */
+/* #undef HAVE_VFORK */
+
+/* Define to 1 if you have the `waitid' function. */
+/* #undef HAVE_WAITID */
+
+/* Define to 1 if you have the <wchar.h> header file. */
+#define HAVE_WCHAR_H 1
+
+/* Define if you have the 'wchar_t' type. */
+#define HAVE_WCHAR_T 1
+
+/* Define to 1 if you have the `wcrtomb' function. */
+#define HAVE_WCRTOMB 1
+
+/* Define to 1 if you have the `wcscoll' function. */
+#define HAVE_WCSCOLL 1
+
+/* Define to 1 if you have the `wcslen' function. */
+#define HAVE_WCSLEN 1
+
+/* Define to 1 if you have the `wcsnlen' function. */
+#define HAVE_WCSNLEN 1
+
+/* Define to 1 if you have the `wctob' function. */
+#define HAVE_WCTOB 1
+
+/* Define to 1 if you have the <wctype.h> header file. */
+#define HAVE_WCTYPE_H 1
+
+/* Define to 1 if you have the <winsock2.h> header file. */
+/* #undef HAVE_WINSOCK2_H */
+
+/* Define if you have the 'wint_t' type. */
+#define HAVE_WINT_T 1
+
+/* Define to 1 if O_NOATIME works. */
+#define HAVE_WORKING_O_NOATIME 0
+
+/* Define to 1 if O_NOFOLLOW works. */
+#define HAVE_WORKING_O_NOFOLLOW 0
+
+/* Define if you have the posix_spawn and posix_spawnp functions and they
+ work. */
+/* #undef HAVE_WORKING_POSIX_SPAWN */
+
+/* Define to 1 if you have the <xlocale.h> header file. */
+/* #undef HAVE_XLOCALE_H */
+
+/* Define to 1 if extending the stack slightly past the limit causes a
+ SIGSEGV, and an alternate stack can be established with sigaltstack, and
+ the signal handler is passed a context that specifies the run time stack.
+ This behavior is defined by POSIX 1003.1-2001 with the X/Open System
+ Interface (XSI) option and is a standardized way to implement a SEGV-based
+ stack overflow detection heuristic. */
+/* #undef HAVE_XSI_STACK_OVERFLOW_HEURISTIC */
+
+/* Define to 1 if the system has the type `_Bool'. */
+/* #undef HAVE__BOOL */
+
+/* Define to 1 if you have the `_fseeki64' function. */
+#define HAVE__FSEEKI64 1
+
+/* Define to 1 if you have the `_ftelli64' function. */
+#define HAVE__FTELLI64 1
+
+/* Define to 1 if you have the `_ftime' function. */
+#define HAVE__FTIME 1
+
+/* Define to 1 if you have the `_set_invalid_parameter_handler' function. */
+#define HAVE__SET_INVALID_PARAMETER_HANDLER 1
+
+/* Define to 1 if you have the `__fpurge' function. */
+/* #undef HAVE___FPURGE */
+
+/* Define to 1 if you have the `__freadahead' function. */
+/* #undef HAVE___FREADAHEAD */
+
+/* Define to 1 if you have the `__freading' function. */
+/* #undef HAVE___FREADING */
+
+/* Define to 1 if you have the `__secure_getenv' function. */
+/* #undef HAVE___SECURE_GETENV */
+
+/* Define as the bit index in the word where to find bit 0 of the exponent of
+ 'long double'. */
+#define LDBL_EXPBIT0_BIT 20
+
+/* Define as the word index where to find the exponent of 'long double'. */
+#define LDBL_EXPBIT0_WORD 1
+
+/* Define as the bit index in the word where to find the sign of 'long
+ double'. */
+#define LDBL_SIGNBIT_BIT 31
+
+/* Define as the word index where to find the sign of 'long double'. */
+#define LDBL_SIGNBIT_WORD 1
+
+/* Define to 1 if lseek does not detect pipes. */
+#define LSEEK_PIPE_BROKEN 1
+
+/* Define to 1 if 'lstat' dereferences a symlink specified with a trailing
+ slash. */
+/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
+
+/* If malloc(0) is != NULL, define this to 1. Otherwise define this to 0. */
+#define MALLOC_0_IS_NONNULL 1
+
+/* Define to a substitute value for mmap()'s MAP_ANONYMOUS flag. */
+/* #undef MAP_ANONYMOUS */
+
+/* Define if the mbrtowc function has the NULL pwc argument bug. */
+/* #undef MBRTOWC_NULL_ARG1_BUG */
+
+/* Define if the mbrtowc function has the NULL string argument bug. */
+/* #undef MBRTOWC_NULL_ARG2_BUG */
+
+/* Define if the mbrtowc function does not return 0 for a NUL character. */
+/* #undef MBRTOWC_NUL_RETVAL_BUG */
+
+/* Define if the mbrtowc function returns a wrong return value. */
+/* #undef MBRTOWC_RETVAL_BUG */
+
+/* Define to 1 if assertions should be disabled. */
+/* #undef NDEBUG */
+
+/* Define if the vasnprintf implementation needs special code for the 'a' and
+ 'A' directives. */
+#define NEED_PRINTF_DIRECTIVE_A 1
+
+/* Define if the vasnprintf implementation needs special code for the 'F'
+ directive. */
+#define NEED_PRINTF_DIRECTIVE_F 1
+
+/* Define if the vasnprintf implementation needs special code for the 'ls'
+ directive. */
+/* #undef NEED_PRINTF_DIRECTIVE_LS */
+
+/* Define if the vasnprintf implementation needs special code for 'double'
+ arguments. */
+#define NEED_PRINTF_DOUBLE 1
+
+/* Define if the vasnprintf implementation needs special code for surviving
+ out-of-memory conditions. */
+#define NEED_PRINTF_ENOMEM 1
+
+/* Define if the vasnprintf implementation needs special code for the ' flag.
+ */
+#define NEED_PRINTF_FLAG_GROUPING 1
+
+/* Define if the vasnprintf implementation needs special code for the '-'
+ flag. */
+/* #undef NEED_PRINTF_FLAG_LEFTADJUST */
+
+/* Define if the vasnprintf implementation needs special code for the 0 flag.
+ */
+#define NEED_PRINTF_FLAG_ZERO 1
+
+/* Define if the vasnprintf implementation needs special code for infinite
+ 'double' arguments. */
+#define NEED_PRINTF_INFINITE_DOUBLE 1
+
+/* Define if the vasnprintf implementation needs special code for infinite
+ 'long double' arguments. */
+/* #undef NEED_PRINTF_INFINITE_LONG_DOUBLE */
+
+/* Define if the vasnprintf implementation needs special code for 'long
+ double' arguments. */
+#define NEED_PRINTF_LONG_DOUBLE 1
+
+/* Define if the vasnprintf implementation needs special code for supporting
+ large precisions without arbitrary bounds. */
+#define NEED_PRINTF_UNBOUNDED_PRECISION 1
+
+/* Define to 1 if open() fails to recognize a trailing slash. */
+/* #undef OPEN_TRAILING_SLASH_BUG */
+
+/* Name of package */
+#define PACKAGE "m4"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "bug-m4@gnu.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "GNU M4"
+
+/* String identifying the packager of this software */
+/* #undef PACKAGE_PACKAGER */
+
+/* Packager info for bug reports (URL/e-mail/...) */
+/* #undef PACKAGE_PACKAGER_BUG_REPORTS */
+
+/* Packager-specific version information */
+/* #undef PACKAGE_PACKAGER_VERSION */
+
+/* Define to the full name and version of this package. */
#define PACKAGE_STRING "GNU M4 3.0.0"
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME "m4"
-
-/* Define to the home page for this package. */
-#define PACKAGE_URL "http://www.gnu.org/software/m4/"
-
-/* Define to the version of this package. */
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "m4"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "http://www.gnu.org/software/m4/"
+
+/* Define to the version of this package. */
#define PACKAGE_VERSION "3.0.0"
-
-/* the number of pending output bytes on stream 'fp' */
+
+/* the number of pending output bytes on stream 'fp' */
#if WIN_SDK10
#define PENDING_OUTPUT_N_BYTES ((TWinSdk10File*)fp)->_ptr - ((TWinSdk10File*)fp)->_base
#else
-#define PENDING_OUTPUT_N_BYTES fp->_ptr - fp->_base
+#define PENDING_OUTPUT_N_BYTES fp->_ptr - fp->_base
#endif
-
-/* Define if <inttypes.h> exists and defines unusable PRI* macros. */
-/* #undef PRI_MACROS_BROKEN */
-
-/* Define to the type that is the result of default argument promotions of
- type mode_t. */
-#define PROMOTED_MODE_T mode_t
-
-/* Define if the pthread_in_use() detection is hard. */
-/* #undef PTHREAD_IN_USE_DETECTION_HARD */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'ptrdiff_t'. */
-/* #undef PTRDIFF_T_SUFFIX */
-
-/* Define to 1 if readlink fails to recognize a trailing slash. */
-/* #undef READLINK_TRAILING_SLASH_BUG */
-
-/* Define if rename does not work when the destination file exists, as on
- Cygwin 1.5 or Windows. */
-#define RENAME_DEST_EXISTS_BUG 1
-
-/* Define if rename fails to leave hard links alone, as on NetBSD 1.6 or
- Cygwin 1.5. */
-/* #undef RENAME_HARD_LINK_BUG */
-
-/* Define to 1 if a file can be renamed while open, or to 0 if not. */
-#define RENAME_OPEN_FILE_WORKS 1
-
-/* Define if rename does not correctly handle slashes on the destination
- argument, such as on Solaris 10 or NetBSD 1.6. */
-#define RENAME_TRAILING_SLASH_DEST_BUG 1
-
-/* Define if rename does not correctly handle slashes on the source argument,
- such as on Solaris 9 or cygwin 1.5. */
-/* #undef RENAME_TRAILING_SLASH_SOURCE_BUG */
-
-/* Define to 1 if stat needs help when passed a directory name with a trailing
- slash */
-#define REPLACE_FUNC_STAT_DIR 1
-
-/* Define to 1 if stat needs help when passed a file name with a trailing
- slash */
-/* #undef REPLACE_FUNC_STAT_FILE */
-
-/* Define if nl_langinfo exists but is overridden by gnulib. */
-/* #undef REPLACE_NL_LANGINFO */
-
-/* Define to 1 if strerror(0) does not return a message implying success. */
-/* #undef REPLACE_STRERROR_0 */
-
-/* Define if vasnprintf exists but is overridden by gnulib. */
-/* #undef REPLACE_VASNPRINTF */
-
-/* Define if sigaltstack() interprets the stack_t.ss_sp field incorrectly, as
- the highest address of the alternate stack range rather than as the lowest
- address. */
-/* #undef SIGALTSTACK_SS_REVERSED */
-
-/* Define if lists must be signal-safe. */
-#define SIGNAL_SAFE_LIST 1
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'sig_atomic_t'. */
-/* #undef SIG_ATOMIC_T_SUFFIX */
-
-/* Define as the maximum value of type 'size_t', if the system doesn't define
- it. */
-#ifndef SIZE_MAX
-/* # undef SIZE_MAX */
-#endif
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'size_t'. */
-/* #undef SIZE_T_SUFFIX */
-
-/* If using the C implementation of alloca, define if you know the
- direction of stack growth for your system; otherwise it will be
- automatically deduced at runtime.
- STACK_DIRECTION > 0 => grows toward higher addresses
- STACK_DIRECTION < 0 => grows toward lower addresses
- STACK_DIRECTION = 0 => direction of growth unknown */
-/* #undef STACK_DIRECTION */
-
-/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
-/* #undef STAT_MACROS_BROKEN */
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Define to 1 if strerror_r returns char *. */
-/* #undef STRERROR_R_CHAR_P */
-
-/* Shell used by syscmd and esyscmd, must accept -c argument. */
-#define SYSCMD_SHELL "/bin/sh"
-
-/* Define to the prefix of C symbols at the assembler and linker level, either
- an underscore or empty. */
-#define USER_LABEL_PREFIX
-
-/* Define if the POSIX multithreading library can be used. */
-/* #undef USE_POSIX_THREADS */
-
-/* Define if references to the POSIX multithreading library should be made
- weak. */
-/* #undef USE_POSIX_THREADS_WEAK */
-
-/* Define if the GNU Pth multithreading library can be used. */
-/* #undef USE_PTH_THREADS */
-
-/* Define if references to the GNU Pth multithreading library should be made
- weak. */
-/* #undef USE_PTH_THREADS_WEAK */
-
-/* Define if the old Solaris multithreading library can be used. */
-/* #undef USE_SOLARIS_THREADS */
-
-/* Define if references to the old Solaris multithreading library should be
- made weak. */
-/* #undef USE_SOLARIS_THREADS_WEAK */
-
-/* Enable extensions on AIX 3, Interix. */
-#ifndef _ALL_SOURCE
-# define _ALL_SOURCE 1
-#endif
-/* Enable general extensions on OS X. */
-#ifndef _DARWIN_C_SOURCE
-# define _DARWIN_C_SOURCE 1
-#endif
-/* Enable GNU extensions on systems that have them. */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
-/* Enable threading extensions on Solaris. */
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# define _POSIX_PTHREAD_SEMANTICS 1
-#endif
-/* Enable extensions on HP NonStop. */
-#ifndef _TANDEM_SOURCE
-# define _TANDEM_SOURCE 1
-#endif
-/* Enable X/Open extensions if necessary. HP-UX 11.11 defines
- mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of
- whether compiling with -Ae or -D_HPUX_SOURCE=1. */
-#ifndef _XOPEN_SOURCE
-/* # undef _XOPEN_SOURCE */
-#endif
-/* Enable general extensions on Solaris. */
-#ifndef __EXTENSIONS__
-# define __EXTENSIONS__ 1
-#endif
-
-
-/* Define to 1 if you want getc etc. to use unlocked I/O if available.
- Unlocked I/O can improve performance in unithreaded apps, but it is not
- safe for multithreaded apps. */
-#define USE_UNLOCKED_IO 1
-
-/* Define if the native Windows multithreading API can be used. */
-/* #undef USE_WINDOWS_THREADS */
-
-/* Version number of package */
+
+/* Define if <inttypes.h> exists and defines unusable PRI* macros. */
+/* #undef PRI_MACROS_BROKEN */
+
+/* Define to the type that is the result of default argument promotions of
+ type mode_t. */
+#define PROMOTED_MODE_T mode_t
+
+/* Define if the pthread_in_use() detection is hard. */
+/* #undef PTHREAD_IN_USE_DETECTION_HARD */
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'ptrdiff_t'. */
+/* #undef PTRDIFF_T_SUFFIX */
+
+/* Define to 1 if readlink fails to recognize a trailing slash. */
+/* #undef READLINK_TRAILING_SLASH_BUG */
+
+/* Define if rename does not work when the destination file exists, as on
+ Cygwin 1.5 or Windows. */
+#define RENAME_DEST_EXISTS_BUG 1
+
+/* Define if rename fails to leave hard links alone, as on NetBSD 1.6 or
+ Cygwin 1.5. */
+/* #undef RENAME_HARD_LINK_BUG */
+
+/* Define to 1 if a file can be renamed while open, or to 0 if not. */
+#define RENAME_OPEN_FILE_WORKS 1
+
+/* Define if rename does not correctly handle slashes on the destination
+ argument, such as on Solaris 10 or NetBSD 1.6. */
+#define RENAME_TRAILING_SLASH_DEST_BUG 1
+
+/* Define if rename does not correctly handle slashes on the source argument,
+ such as on Solaris 9 or cygwin 1.5. */
+/* #undef RENAME_TRAILING_SLASH_SOURCE_BUG */
+
+/* Define to 1 if stat needs help when passed a directory name with a trailing
+ slash */
+#define REPLACE_FUNC_STAT_DIR 1
+
+/* Define to 1 if stat needs help when passed a file name with a trailing
+ slash */
+/* #undef REPLACE_FUNC_STAT_FILE */
+
+/* Define if nl_langinfo exists but is overridden by gnulib. */
+/* #undef REPLACE_NL_LANGINFO */
+
+/* Define to 1 if strerror(0) does not return a message implying success. */
+/* #undef REPLACE_STRERROR_0 */
+
+/* Define if vasnprintf exists but is overridden by gnulib. */
+/* #undef REPLACE_VASNPRINTF */
+
+/* Define if sigaltstack() interprets the stack_t.ss_sp field incorrectly, as
+ the highest address of the alternate stack range rather than as the lowest
+ address. */
+/* #undef SIGALTSTACK_SS_REVERSED */
+
+/* Define if lists must be signal-safe. */
+#define SIGNAL_SAFE_LIST 1
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'sig_atomic_t'. */
+/* #undef SIG_ATOMIC_T_SUFFIX */
+
+/* Define as the maximum value of type 'size_t', if the system doesn't define
+ it. */
+#ifndef SIZE_MAX
+/* # undef SIZE_MAX */
+#endif
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'size_t'. */
+/* #undef SIZE_T_SUFFIX */
+
+/* If using the C implementation of alloca, define if you know the
+ direction of stack growth for your system; otherwise it will be
+ automatically deduced at runtime.
+ STACK_DIRECTION > 0 => grows toward higher addresses
+ STACK_DIRECTION < 0 => grows toward lower addresses
+ STACK_DIRECTION = 0 => direction of growth unknown */
+/* #undef STACK_DIRECTION */
+
+/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
+/* #undef STAT_MACROS_BROKEN */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if strerror_r returns char *. */
+/* #undef STRERROR_R_CHAR_P */
+
+/* Shell used by syscmd and esyscmd, must accept -c argument. */
+#define SYSCMD_SHELL "/bin/sh"
+
+/* Define to the prefix of C symbols at the assembler and linker level, either
+ an underscore or empty. */
+#define USER_LABEL_PREFIX
+
+/* Define if the POSIX multithreading library can be used. */
+/* #undef USE_POSIX_THREADS */
+
+/* Define if references to the POSIX multithreading library should be made
+ weak. */
+/* #undef USE_POSIX_THREADS_WEAK */
+
+/* Define if the GNU Pth multithreading library can be used. */
+/* #undef USE_PTH_THREADS */
+
+/* Define if references to the GNU Pth multithreading library should be made
+ weak. */
+/* #undef USE_PTH_THREADS_WEAK */
+
+/* Define if the old Solaris multithreading library can be used. */
+/* #undef USE_SOLARIS_THREADS */
+
+/* Define if references to the old Solaris multithreading library should be
+ made weak. */
+/* #undef USE_SOLARIS_THREADS_WEAK */
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable general extensions on OS X. */
+#ifndef _DARWIN_C_SOURCE
+# define _DARWIN_C_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable X/Open extensions if necessary. HP-UX 11.11 defines
+ mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of
+ whether compiling with -Ae or -D_HPUX_SOURCE=1. */
+#ifndef _XOPEN_SOURCE
+/* # undef _XOPEN_SOURCE */
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+
+
+/* Define to 1 if you want getc etc. to use unlocked I/O if available.
+ Unlocked I/O can improve performance in unithreaded apps, but it is not
+ safe for multithreaded apps. */
+#define USE_UNLOCKED_IO 1
+
+/* Define if the native Windows multithreading API can be used. */
+/* #undef USE_WINDOWS_THREADS */
+
+/* Version number of package */
#define VERSION "3.0.0"
-
-/* Define to 1 if unsetenv returns void instead of int. */
-/* #undef VOID_UNSETENV */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'wchar_t'. */
-/* #undef WCHAR_T_SUFFIX */
-
-/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
- 'wint_t'. */
-/* #undef WINT_T_SUFFIX */
-
-/* Define to 1 if malloc debugging is enabled */
-/* #undef WITH_DMALLOC */
-
-/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
- significant byte first (like Motorola and SPARC, unlike Intel). */
-#if defined AC_APPLE_UNIVERSAL_BUILD
-# if defined __BIG_ENDIAN__
-# define WORDS_BIGENDIAN 1
-# endif
-#else
-# ifndef WORDS_BIGENDIAN
-/* # undef WORDS_BIGENDIAN */
-# endif
-#endif
-
-/* Enable large inode numbers on Mac OS X 10.5. */
-#define _DARWIN_USE_64_BIT_INODE 1
-
-/* Number of bits in a file offset, on hosts where this is settable. */
-/* #undef _FILE_OFFSET_BITS */
-
-/* Define to 1 if Gnulib overrides 'struct stat' on Windows so that struct
- stat.st_size becomes 64-bit. */
-#define _GL_WINDOWS_64_BIT_ST_SIZE 1
-
-/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
-/* #undef _LARGEFILE_SOURCE */
-
-/* Define for large files, on AIX-style hosts. */
-/* #undef _LARGE_FILES */
-
-/* Define to 1 on Solaris. */
-/* #undef _LCONV_C99 */
-
-/* Define to 1 if on MINIX. */
-/* #undef _MINIX */
-
-/* Define to 1 to make NetBSD features available. MINIX 3 needs this. */
-/* #undef _NETBSD_SOURCE */
-
-/* The _Noreturn keyword of C11. */
-#if ! (defined _Noreturn \
- || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
-# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
- || 0x5110 <= __SUNPRO_C)
-# define _Noreturn __attribute__ ((__noreturn__))
-# elif defined _MSC_VER && 1200 <= _MSC_VER
-# define _Noreturn __declspec (noreturn)
-# else
-# define _Noreturn
-# endif
-#endif
-
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
- this defined. */
-/* #undef _POSIX_1_SOURCE */
-
-/* Define to 1 if you need to in order for 'stat' and other things to work. */
-/* #undef _POSIX_SOURCE */
-
-/* Define if you want <regex.h> to include <limits.h>, so that it consistently
- overrides <limits.h>'s RE_DUP_MAX. */
-#define _REGEX_INCLUDE_LIMITS_H 1
-
-/* Define if you want regoff_t to be at least as wide POSIX requires. */
-#define _REGEX_LARGE_OFFSETS 1
-
-/* Define to rpl_ if the getopt replacement functions and variables should be
- used. */
-#define __GETOPT_PREFIX rpl_
-
-/* Please see the Gnulib manual for how to use these macros.
-
- Suppress extern inline with HP-UX cc, as it appears to be broken; see
- <http://lists.gnu.org/archive/html/bug-texinfo/2013-02/msg00030.html>.
-
- Suppress extern inline with Sun C in standards-conformance mode, as it
- mishandles inline functions that call each other. E.g., for 'inline void f
- (void) { } inline void g (void) { f (); }', c99 incorrectly complains
- 'reference to static identifier "f" in extern inline function'.
- This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16.
-
- Suppress the use of extern inline on problematic Apple configurations, as
- Libc at least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
- <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
- Perhaps Apple will fix this some day. */
-#if (defined __APPLE__ \
- && ((! defined _DONT_USE_CTYPE_INLINE_ \
- && (defined __GNUC__ || defined __cplusplus)) \
- || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
- && defined __GNUC__ && ! defined __cplusplus)))
-# define _GL_EXTERN_INLINE_APPLE_BUG
-#endif
-#if ((__GNUC__ \
- ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
- : (199901L <= __STDC_VERSION__ \
- && !defined __HP_cc \
- && !(defined __SUNPRO_C && __STDC__))) \
- && !defined _GL_EXTERN_INLINE_APPLE_BUG)
-# define _GL_INLINE inline
-# define _GL_EXTERN_INLINE extern inline
-# define _GL_EXTERN_INLINE_IN_USE
-#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
- && !defined _GL_EXTERN_INLINE_APPLE_BUG)
-# if __GNUC_GNU_INLINE__
- /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
-# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
-# else
-# define _GL_INLINE extern inline
-# endif
-# define _GL_EXTERN_INLINE extern
-# define _GL_EXTERN_INLINE_IN_USE
-#else
-# define _GL_INLINE static _GL_UNUSED
-# define _GL_EXTERN_INLINE static _GL_UNUSED
-#endif
-
-#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
-# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
-# define _GL_INLINE_HEADER_CONST_PRAGMA
-# else
-# define _GL_INLINE_HEADER_CONST_PRAGMA \
- _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
-# endif
- /* Suppress GCC's bogus "no previous prototype for 'FOO'"
- and "no previous declaration for 'FOO'" diagnostics,
- when FOO is an inline function in the header; see
- <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113>. */
-# define _GL_INLINE_HEADER_BEGIN \
- _Pragma ("GCC diagnostic push") \
- _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
- _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
- _GL_INLINE_HEADER_CONST_PRAGMA
-# define _GL_INLINE_HEADER_END \
- _Pragma ("GCC diagnostic pop")
-#else
-# define _GL_INLINE_HEADER_BEGIN
-# define _GL_INLINE_HEADER_END
-#endif
-
-/* Define to `int' if <sys/types.h> doesn't define. */
-#define gid_t int
-
-/* A replacement for va_copy, if needed. */
-#define gl_va_copy(a,b) ((a) = (b))
-
-/* Define to rpl_gmtime if the replacement function should be used. */
-/* #undef gmtime */
-
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef __cplusplus
-#define inline __inline
-#endif
-
-/* Define to long or long long if <stdint.h> and <inttypes.h> don't define. */
-/* #undef intmax_t */
-
-/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
- the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
- earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
- __APPLE__ && __MACH__ test for Mac OS X.
- __APPLE_CC__ tests for the Apple compiler and its version.
- __STDC_VERSION__ tests for the C99 mode. */
-#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
-# define __GNUC_STDC_INLINE__ 1
-#endif
-
-/* Define to rpl_localtime if the replacement function should be used. */
-/* #undef localtime */
-
-/* Define to a type if <wchar.h> does not define. */
-/* #undef mbstate_t */
-
-/* Define to `int' if <sys/types.h> does not define. */
-#define mode_t int
-
-/* Define to the type of st_nlink in struct stat, or a supertype. */
-#define nlink_t int
-
-/* Define to `int' if <sys/types.h> does not define. */
-#define pid_t int
-
-/* Define as the type of the result of subtracting two pointers, if the system
- doesn't define it. */
-/* #undef ptrdiff_t */
-
-/* Define to rpl_re_comp if the replacement should be used. */
-#define re_comp rpl_re_comp
-
-/* Define to rpl_re_compile_fastmap if the replacement should be used. */
-#define re_compile_fastmap rpl_re_compile_fastmap
-
-/* Define to rpl_re_compile_pattern if the replacement should be used. */
-#define re_compile_pattern rpl_re_compile_pattern
-
-/* Define to rpl_re_exec if the replacement should be used. */
-#define re_exec rpl_re_exec
-
-/* Define to rpl_re_match if the replacement should be used. */
-#define re_match rpl_re_match
-
-/* Define to rpl_re_match_2 if the replacement should be used. */
-#define re_match_2 rpl_re_match_2
-
-/* Define to rpl_re_search if the replacement should be used. */
-#define re_search rpl_re_search
-
-/* Define to rpl_re_search_2 if the replacement should be used. */
-#define re_search_2 rpl_re_search_2
-
-/* Define to rpl_re_set_registers if the replacement should be used. */
-#define re_set_registers rpl_re_set_registers
-
-/* Define to rpl_re_set_syntax if the replacement should be used. */
-#define re_set_syntax rpl_re_set_syntax
-
-/* Define to rpl_re_syntax_options if the replacement should be used. */
-#define re_syntax_options rpl_re_syntax_options
-
-/* Define to rpl_regcomp if the replacement should be used. */
-#define regcomp rpl_regcomp
-
-/* Define to rpl_regerror if the replacement should be used. */
-#define regerror rpl_regerror
-
-/* Define to rpl_regexec if the replacement should be used. */
-#define regexec rpl_regexec
-
-/* Define to rpl_regfree if the replacement should be used. */
-#define regfree rpl_regfree
-
-/* Define to the equivalent of the C99 'restrict' keyword, or to
- nothing if this is not supported. Do not define if restrict is
- supported directly. */
-#define restrict /**/
-/* Work around a bug in Sun C++: it does not support _Restrict or
- __restrict__, even though the corresponding Sun C compiler ends up with
- "#define restrict _Restrict" or "#define restrict __restrict__" in the
- previous line. Perhaps some future version of Sun C++ will work with
- restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
-#if defined __SUNPRO_CC && !defined __RESTRICT
-# define _Restrict
-# define __restrict__
-#endif
-
-/* Define as an integer type suitable for memory locations that can be
- accessed atomically even in the presence of asynchronous signals. */
-/* #undef sig_atomic_t */
-
-/* Define to `unsigned int' if <sys/types.h> does not define. */
-/* #undef size_t */
-
-/* Define as a signed type of the same size as size_t. */
-#define ssize_t int
-
-/* Define to `int' if <sys/types.h> doesn't define. */
-#define uid_t int
-
-/* Define as a marker that can be attached to declarations that might not
- be used. This helps to reduce warnings, such as from
- GCC -Wunused-parameter. */
-#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_UNUSED __attribute__ ((__unused__))
-#else
-# define _GL_UNUSED
-#endif
-/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
- is a misnomer outside of parameter lists. */
-#define _UNUSED_PARAMETER_ _GL_UNUSED
-
-/* The __pure__ attribute was added in gcc 2.96. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
-# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
-#else
-# define _GL_ATTRIBUTE_PURE /* empty */
-#endif
-
-/* The __const__ attribute was added in gcc 2.95. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
-#else
-# define _GL_ATTRIBUTE_CONST /* empty */
-#endif
-
-
-/* Define as a macro for copying va_list variables. */
-#define va_copy gl_va_copy
+
+/* Define to 1 if unsetenv returns void instead of int. */
+/* #undef VOID_UNSETENV */
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'wchar_t'. */
+/* #undef WCHAR_T_SUFFIX */
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'wint_t'. */
+/* #undef WINT_T_SUFFIX */
+
+/* Define to 1 if malloc debugging is enabled */
+/* #undef WITH_DMALLOC */
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+ significant byte first (like Motorola and SPARC, unlike Intel). */
+#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+# define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+/* # undef WORDS_BIGENDIAN */
+# endif
+#endif
+
+/* Enable large inode numbers on Mac OS X 10.5. */
+#define _DARWIN_USE_64_BIT_INODE 1
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define to 1 if Gnulib overrides 'struct stat' on Windows so that struct
+ stat.st_size becomes 64-bit. */
+#define _GL_WINDOWS_64_BIT_ST_SIZE 1
+
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/* #undef _LARGEFILE_SOURCE */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+/* Define to 1 on Solaris. */
+/* #undef _LCONV_C99 */
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 1 to make NetBSD features available. MINIX 3 needs this. */
+/* #undef _NETBSD_SOURCE */
+
+/* The _Noreturn keyword of C11. */
+#if ! (defined _Noreturn \
+ || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
+# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
+ || 0x5110 <= __SUNPRO_C)
+# define _Noreturn __attribute__ ((__noreturn__))
+# elif defined _MSC_VER && 1200 <= _MSC_VER
+# define _Noreturn __declspec (noreturn)
+# else
+# define _Noreturn
+# endif
+#endif
+
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for 'stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define if you want <regex.h> to include <limits.h>, so that it consistently
+ overrides <limits.h>'s RE_DUP_MAX. */
+#define _REGEX_INCLUDE_LIMITS_H 1
+
+/* Define if you want regoff_t to be at least as wide POSIX requires. */
+#define _REGEX_LARGE_OFFSETS 1
+
+/* Define to rpl_ if the getopt replacement functions and variables should be
+ used. */
+#define __GETOPT_PREFIX rpl_
+
+/* Please see the Gnulib manual for how to use these macros.
+
+ Suppress extern inline with HP-UX cc, as it appears to be broken; see
+ <http://lists.gnu.org/archive/html/bug-texinfo/2013-02/msg00030.html>.
+
+ Suppress extern inline with Sun C in standards-conformance mode, as it
+ mishandles inline functions that call each other. E.g., for 'inline void f
+ (void) { } inline void g (void) { f (); }', c99 incorrectly complains
+ 'reference to static identifier "f" in extern inline function'.
+ This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16.
+
+ Suppress the use of extern inline on problematic Apple configurations, as
+ Libc at least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
+ <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
+ Perhaps Apple will fix this some day. */
+#if (defined __APPLE__ \
+ && ((! defined _DONT_USE_CTYPE_INLINE_ \
+ && (defined __GNUC__ || defined __cplusplus)) \
+ || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
+ && defined __GNUC__ && ! defined __cplusplus)))
+# define _GL_EXTERN_INLINE_APPLE_BUG
+#endif
+#if ((__GNUC__ \
+ ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
+ : (199901L <= __STDC_VERSION__ \
+ && !defined __HP_cc \
+ && !(defined __SUNPRO_C && __STDC__))) \
+ && !defined _GL_EXTERN_INLINE_APPLE_BUG)
+# define _GL_INLINE inline
+# define _GL_EXTERN_INLINE extern inline
+# define _GL_EXTERN_INLINE_IN_USE
+#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
+ && !defined _GL_EXTERN_INLINE_APPLE_BUG)
+# if __GNUC_GNU_INLINE__
+ /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
+# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
+# else
+# define _GL_INLINE extern inline
+# endif
+# define _GL_EXTERN_INLINE extern
+# define _GL_EXTERN_INLINE_IN_USE
+#else
+# define _GL_INLINE static _GL_UNUSED
+# define _GL_EXTERN_INLINE static _GL_UNUSED
+#endif
+
+#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
+# define _GL_INLINE_HEADER_CONST_PRAGMA
+# else
+# define _GL_INLINE_HEADER_CONST_PRAGMA \
+ _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
+# endif
+ /* Suppress GCC's bogus "no previous prototype for 'FOO'"
+ and "no previous declaration for 'FOO'" diagnostics,
+ when FOO is an inline function in the header; see
+ <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113>. */
+# define _GL_INLINE_HEADER_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
+ _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
+ _GL_INLINE_HEADER_CONST_PRAGMA
+# define _GL_INLINE_HEADER_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define _GL_INLINE_HEADER_BEGIN
+# define _GL_INLINE_HEADER_END
+#endif
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+#define gid_t int
+
+/* A replacement for va_copy, if needed. */
+#define gl_va_copy(a,b) ((a) = (b))
+
+/* Define to rpl_gmtime if the replacement function should be used. */
+/* #undef gmtime */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#ifndef __cplusplus
+#define inline __inline
+#endif
+
+/* Define to long or long long if <stdint.h> and <inttypes.h> don't define. */
+/* #undef intmax_t */
+
+/* Work around a bug in Apple GCC 4.0.1 build 5465: In C99 mode, it supports
+ the ISO C 99 semantics of 'extern inline' (unlike the GNU C semantics of
+ earlier versions), but does not display it by setting __GNUC_STDC_INLINE__.
+ __APPLE__ && __MACH__ test for Mac OS X.
+ __APPLE_CC__ tests for the Apple compiler and its version.
+ __STDC_VERSION__ tests for the C99 mode. */
+#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
+# define __GNUC_STDC_INLINE__ 1
+#endif
+
+/* Define to rpl_localtime if the replacement function should be used. */
+/* #undef localtime */
+
+/* Define to a type if <wchar.h> does not define. */
+/* #undef mbstate_t */
+
+/* Define to `int' if <sys/types.h> does not define. */
+#define mode_t int
+
+/* Define to the type of st_nlink in struct stat, or a supertype. */
+#define nlink_t int
+
+/* Define to `int' if <sys/types.h> does not define. */
+#define pid_t int
+
+/* Define as the type of the result of subtracting two pointers, if the system
+ doesn't define it. */
+/* #undef ptrdiff_t */
+
+/* Define to rpl_re_comp if the replacement should be used. */
+#define re_comp rpl_re_comp
+
+/* Define to rpl_re_compile_fastmap if the replacement should be used. */
+#define re_compile_fastmap rpl_re_compile_fastmap
+
+/* Define to rpl_re_compile_pattern if the replacement should be used. */
+#define re_compile_pattern rpl_re_compile_pattern
+
+/* Define to rpl_re_exec if the replacement should be used. */
+#define re_exec rpl_re_exec
+
+/* Define to rpl_re_match if the replacement should be used. */
+#define re_match rpl_re_match
+
+/* Define to rpl_re_match_2 if the replacement should be used. */
+#define re_match_2 rpl_re_match_2
+
+/* Define to rpl_re_search if the replacement should be used. */
+#define re_search rpl_re_search
+
+/* Define to rpl_re_search_2 if the replacement should be used. */
+#define re_search_2 rpl_re_search_2
+
+/* Define to rpl_re_set_registers if the replacement should be used. */
+#define re_set_registers rpl_re_set_registers
+
+/* Define to rpl_re_set_syntax if the replacement should be used. */
+#define re_set_syntax rpl_re_set_syntax
+
+/* Define to rpl_re_syntax_options if the replacement should be used. */
+#define re_syntax_options rpl_re_syntax_options
+
+/* Define to rpl_regcomp if the replacement should be used. */
+#define regcomp rpl_regcomp
+
+/* Define to rpl_regerror if the replacement should be used. */
+#define regerror rpl_regerror
+
+/* Define to rpl_regexec if the replacement should be used. */
+#define regexec rpl_regexec
+
+/* Define to rpl_regfree if the replacement should be used. */
+#define regfree rpl_regfree
+
+/* Define to the equivalent of the C99 'restrict' keyword, or to
+ nothing if this is not supported. Do not define if restrict is
+ supported directly. */
+#define restrict /**/
+/* Work around a bug in Sun C++: it does not support _Restrict or
+ __restrict__, even though the corresponding Sun C compiler ends up with
+ "#define restrict _Restrict" or "#define restrict __restrict__" in the
+ previous line. Perhaps some future version of Sun C++ will work with
+ restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
+#if defined __SUNPRO_CC && !defined __RESTRICT
+# define _Restrict
+# define __restrict__
+#endif
+
+/* Define as an integer type suitable for memory locations that can be
+ accessed atomically even in the presence of asynchronous signals. */
+/* #undef sig_atomic_t */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define as a signed type of the same size as size_t. */
+#define ssize_t int
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+#define uid_t int
+
+/* Define as a marker that can be attached to declarations that might not
+ be used. This helps to reduce warnings, such as from
+ GCC -Wunused-parameter. */
+#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED __attribute__ ((__unused__))
+#else
+# define _GL_UNUSED
+#endif
+/* The name _UNUSED_PARAMETER_ is an earlier spelling, although the name
+ is a misnomer outside of parameter lists. */
+#define _UNUSED_PARAMETER_ _GL_UNUSED
+
+/* The __pure__ attribute was added in gcc 2.96. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
+#else
+# define _GL_ATTRIBUTE_PURE /* empty */
+#endif
+
+/* The __const__ attribute was added in gcc 2.95. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
+#else
+# define _GL_ATTRIBUTE_CONST /* empty */
+#endif
+
+
+/* Define as a macro for copying va_list variables. */
+#define va_copy gl_va_copy
diff --git a/contrib/tools/bison/gnulib/platform/win64/configmake.h b/contrib/tools/bison/gnulib/platform/win64/configmake.h
index 736cfb1bc6..c65d884fd6 100644
--- a/contrib/tools/bison/gnulib/platform/win64/configmake.h
+++ b/contrib/tools/bison/gnulib/platform/win64/configmake.h
@@ -1 +1 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
diff --git a/contrib/tools/bison/gnulib/platform/win64/fcntl.h b/contrib/tools/bison/gnulib/platform/win64/fcntl.h
index dd3a1e5208..c03c6cb9e0 100644
--- a/contrib/tools/bison/gnulib/platform/win64/fcntl.h
+++ b/contrib/tools/bison/gnulib/platform/win64/fcntl.h
@@ -1,667 +1,667 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Like <fcntl.h>, but with non-working flags defined to 0.
-
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Paul Eggert */
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-#if defined __need_system_fcntl_h
-/* Special invocation convention. */
-
-/* Needed before <sys/stat.h>.
- May also define off_t to a 64-bit type on native Windows. */
-#include <sys/types.h>
-/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
- <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
- But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
- extern "C" { ... } block, which leads to errors in C++ mode with the
- overridden <sys/stat.h> from gnulib. These errors are known to be gone
- with g++ version >= 4.3. */
-#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
-# include <sys/stat.h>
-#endif
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Like <fcntl.h>, but with non-working flags defined to 0.
+
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Paul Eggert */
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+#if defined __need_system_fcntl_h
+/* Special invocation convention. */
+
+/* Needed before <sys/stat.h>.
+ May also define off_t to a 64-bit type on native Windows. */
+#include <sys/types.h>
+/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
+ <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
+ But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
+ extern "C" { ... } block, which leads to errors in C++ mode with the
+ overridden <sys/stat.h> from gnulib. These errors are known to be gone
+ with g++ version >= 4.3. */
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+# include <sys/stat.h>
+#endif
#if _MSC_VER >= 1900
#include <../ucrt/fcntl.h>
#else
#include <../include/fcntl.h>
#endif
-
-#else
-/* Normal invocation convention. */
-
-#ifndef _GL_M4_FCNTL_H
-
-/* Needed before <sys/stat.h>.
- May also define off_t to a 64-bit type on native Windows. */
-#include <sys/types.h>
-/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
- <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
- But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
- extern "C" { ... } block, which leads to errors in C++ mode with the
- overridden <sys/stat.h> from gnulib. These errors are known to be gone
- with g++ version >= 4.3. */
-#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
-# include <sys/stat.h>
-#endif
-/* The include_next requires a split double-inclusion guard. */
+
+#else
+/* Normal invocation convention. */
+
+#ifndef _GL_M4_FCNTL_H
+
+/* Needed before <sys/stat.h>.
+ May also define off_t to a 64-bit type on native Windows. */
+#include <sys/types.h>
+/* On some systems other than glibc, <sys/stat.h> is a prerequisite of
+ <fcntl.h>. On glibc systems, we would like to avoid namespace pollution.
+ But on glibc systems, <fcntl.h> includes <sys/stat.h> inside an
+ extern "C" { ... } block, which leads to errors in C++ mode with the
+ overridden <sys/stat.h> from gnulib. These errors are known to be gone
+ with g++ version >= 4.3. */
+#if !(defined __GLIBC__ || defined __UCLIBC__) || (defined __cplusplus && defined GNULIB_NAMESPACE && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
+# include <sys/stat.h>
+#endif
+/* The include_next requires a split double-inclusion guard. */
#if _MSC_VER >= 1900
#include <../ucrt/fcntl.h>
#else
#include <../include/fcntl.h>
#endif
-
-#ifndef _GL_M4_FCNTL_H
-#define _GL_M4_FCNTL_H
-
-#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
-# include <unistd.h>
-#endif
-
-/* Native Windows platforms declare open(), creat() in <io.h>. */
-#if (1 || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
-# include <io.h>
-#endif
-
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-
-/* Declare overridden functions. */
-
-#if 1
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fcntl
-# define fcntl rpl_fcntl
-# endif
-_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
-_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
-# else
-# if !0
-_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
-# endif
-_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
-# endif
-_GL_CXXALIASWARN (fcntl);
-#elif defined GNULIB_POSIXCHECK
-# undef fcntl
-# if HAVE_RAW_DECL_FCNTL
-_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
- "use gnulib module fcntl for portability");
-# endif
-#endif
-
-#if 1
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef open
-# define open rpl_open
-# endif
-_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
-# else
-_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
-# endif
-/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
- default argument. _GL_CXXALIASWARN does not work in this case. */
-# if !defined __hpux
-_GL_CXXALIASWARN (open);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef open
-/* Assume open is always declared. */
-_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
- "use gnulib module open for portability");
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef openat
-# define openat rpl_openat
-# endif
-_GL_FUNCDECL_RPL (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...));
-# else
-# if !1
-_GL_FUNCDECL_SYS (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (openat, int,
- (int fd, char const *file, int flags, /* mode_t mode */ ...));
-# endif
-_GL_CXXALIASWARN (openat);
-#elif defined GNULIB_POSIXCHECK
-# undef openat
-# if HAVE_RAW_DECL_OPENAT
-_GL_WARN_ON_USE (openat, "openat is not portable - "
- "use gnulib module openat for portability");
-# endif
-#endif
-
-
-/* Fix up the FD_* macros, only known to be missing on mingw. */
-
-#ifndef FD_CLOEXEC
-# define FD_CLOEXEC 1
-#endif
-
-/* Fix up the supported F_* macros. Intentionally leave other F_*
- macros undefined. Only known to be missing on mingw. */
-
-#ifndef F_DUPFD_CLOEXEC
-# define F_DUPFD_CLOEXEC 0x40000000
-/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
-# define GNULIB_defined_F_DUPFD_CLOEXEC 1
-#else
-# define GNULIB_defined_F_DUPFD_CLOEXEC 0
-#endif
-
-#ifndef F_DUPFD
-# define F_DUPFD 1
-#endif
-
-#ifndef F_GETFD
-# define F_GETFD 2
-#endif
-
-/* Fix up the O_* macros. */
-
-#if !defined O_DIRECT && defined O_DIRECTIO
-/* Tru64 spells it 'O_DIRECTIO'. */
-# define O_DIRECT O_DIRECTIO
-#endif
-
-#if !defined O_CLOEXEC && defined O_NOINHERIT
-/* Mingw spells it 'O_NOINHERIT'. */
-# define O_CLOEXEC O_NOINHERIT
-#endif
-
-#ifndef O_CLOEXEC
-# define O_CLOEXEC 0
-#endif
-
-#ifndef O_DIRECT
-# define O_DIRECT 0
-#endif
-
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-
-#ifndef O_DSYNC
-# define O_DSYNC 0
-#endif
-
-#ifndef O_EXEC
-# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
-#endif
-
-#ifndef O_IGNORE_CTTY
-# define O_IGNORE_CTTY 0
-#endif
-
-#ifndef O_NDELAY
-# define O_NDELAY 0
-#endif
-
-#ifndef O_NOATIME
-# define O_NOATIME 0
-#endif
-
-#ifndef O_NONBLOCK
-# define O_NONBLOCK O_NDELAY
-#endif
-
-/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
- value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
- or to 0 as fallback. */
-#if 0
-# if O_NONBLOCK
-# define GNULIB_defined_O_NONBLOCK 0
-# else
-# define GNULIB_defined_O_NONBLOCK 1
-# undef O_NONBLOCK
-# define O_NONBLOCK 0x40000000
-# endif
-#endif
-
-#ifndef O_NOCTTY
-# define O_NOCTTY 0
-#endif
-
-#ifndef O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
-#ifndef O_NOLINK
-# define O_NOLINK 0
-#endif
-
-#ifndef O_NOLINKS
-# define O_NOLINKS 0
-#endif
-
-#ifndef O_NOTRANS
-# define O_NOTRANS 0
-#endif
-
-#ifndef O_RSYNC
-# define O_RSYNC 0
-#endif
-
-#ifndef O_SEARCH
-# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
-#endif
-
-#ifndef O_SYNC
-# define O_SYNC 0
-#endif
-
-#ifndef O_TTY_INIT
-# define O_TTY_INIT 0
-#endif
-
-#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
-# undef O_ACCMODE
-# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
-#endif
-
-/* For systems that distinguish between text and binary I/O.
- O_BINARY is usually declared in fcntl.h */
-#if !defined O_BINARY && defined _O_BINARY
- /* For MSC-compatible compilers. */
-# define O_BINARY _O_BINARY
-# define O_TEXT _O_TEXT
-#endif
-
-#if defined __BEOS__ || defined __HAIKU__
- /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
-# undef O_BINARY
-# undef O_TEXT
-#endif
-
-#ifndef O_BINARY
-# define O_BINARY 0
-# define O_TEXT 0
-#endif
-
-/* Fix up the AT_* macros. */
-
-/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
- value exceeds INT_MAX, so its use as an int doesn't conform to the
- C standard, and GCC and Sun C complain in some cases. If the bug
- is present, undef AT_FDCWD here, so it can be redefined below. */
-#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
-# undef AT_FDCWD
-#endif
-
-/* Use the same bit pattern as Solaris 9, but with the proper
- signedness. The bit pattern is important, in case this actually is
- Solaris with the above workaround. */
-#ifndef AT_FDCWD
-# define AT_FDCWD (-3041965)
-#endif
-
-/* Use the same values as Solaris 9. This shouldn't matter, but
- there's no real reason to differ. */
-#ifndef AT_SYMLINK_NOFOLLOW
-# define AT_SYMLINK_NOFOLLOW 4096
-#endif
-
-#ifndef AT_REMOVEDIR
-# define AT_REMOVEDIR 1
-#endif
-
-/* Solaris 9 lacks these two, so just pick unique values. */
-#ifndef AT_SYMLINK_FOLLOW
-# define AT_SYMLINK_FOLLOW 2
-#endif
-
-#ifndef AT_EACCESS
-# define AT_EACCESS 4
-#endif
-
-
-#endif /* _GL_M4_FCNTL_H */
-#endif /* _GL_M4_FCNTL_H */
-#endif
+
+#ifndef _GL_M4_FCNTL_H
+#define _GL_M4_FCNTL_H
+
+#ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */
+# include <unistd.h>
+#endif
+
+/* Native Windows platforms declare open(), creat() in <io.h>. */
+#if (1 || defined GNULIB_POSIXCHECK) \
+ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+# include <io.h>
+#endif
+
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+
+/* Declare overridden functions. */
+
+#if 1
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fcntl
+# define fcntl rpl_fcntl
+# endif
+_GL_FUNCDECL_RPL (fcntl, int, (int fd, int action, ...));
+_GL_CXXALIAS_RPL (fcntl, int, (int fd, int action, ...));
+# else
+# if !0
+_GL_FUNCDECL_SYS (fcntl, int, (int fd, int action, ...));
+# endif
+_GL_CXXALIAS_SYS (fcntl, int, (int fd, int action, ...));
+# endif
+_GL_CXXALIASWARN (fcntl);
+#elif defined GNULIB_POSIXCHECK
+# undef fcntl
+# if HAVE_RAW_DECL_FCNTL
+_GL_WARN_ON_USE (fcntl, "fcntl is not always POSIX compliant - "
+ "use gnulib module fcntl for portability");
+# endif
+#endif
+
+#if 1
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef open
+# define open rpl_open
+# endif
+_GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+# else
+_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+# endif
+/* On HP-UX 11, in C++ mode, open() is defined as an inline function with a
+ default argument. _GL_CXXALIASWARN does not work in this case. */
+# if !defined __hpux
+_GL_CXXALIASWARN (open);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef open
+/* Assume open is always declared. */
+_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
+ "use gnulib module open for portability");
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef openat
+# define openat rpl_openat
+# endif
+_GL_FUNCDECL_RPL (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...));
+# else
+# if !1
+_GL_FUNCDECL_SYS (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (openat, int,
+ (int fd, char const *file, int flags, /* mode_t mode */ ...));
+# endif
+_GL_CXXALIASWARN (openat);
+#elif defined GNULIB_POSIXCHECK
+# undef openat
+# if HAVE_RAW_DECL_OPENAT
+_GL_WARN_ON_USE (openat, "openat is not portable - "
+ "use gnulib module openat for portability");
+# endif
+#endif
+
+
+/* Fix up the FD_* macros, only known to be missing on mingw. */
+
+#ifndef FD_CLOEXEC
+# define FD_CLOEXEC 1
+#endif
+
+/* Fix up the supported F_* macros. Intentionally leave other F_*
+ macros undefined. Only known to be missing on mingw. */
+
+#ifndef F_DUPFD_CLOEXEC
+# define F_DUPFD_CLOEXEC 0x40000000
+/* Witness variable: 1 if gnulib defined F_DUPFD_CLOEXEC, 0 otherwise. */
+# define GNULIB_defined_F_DUPFD_CLOEXEC 1
+#else
+# define GNULIB_defined_F_DUPFD_CLOEXEC 0
+#endif
+
+#ifndef F_DUPFD
+# define F_DUPFD 1
+#endif
+
+#ifndef F_GETFD
+# define F_GETFD 2
+#endif
+
+/* Fix up the O_* macros. */
+
+#if !defined O_DIRECT && defined O_DIRECTIO
+/* Tru64 spells it 'O_DIRECTIO'. */
+# define O_DIRECT O_DIRECTIO
+#endif
+
+#if !defined O_CLOEXEC && defined O_NOINHERIT
+/* Mingw spells it 'O_NOINHERIT'. */
+# define O_CLOEXEC O_NOINHERIT
+#endif
+
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
+#ifndef O_DIRECT
+# define O_DIRECT 0
+#endif
+
+#ifndef O_DIRECTORY
+# define O_DIRECTORY 0
+#endif
+
+#ifndef O_DSYNC
+# define O_DSYNC 0
+#endif
+
+#ifndef O_EXEC
+# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
+#endif
+
+#ifndef O_IGNORE_CTTY
+# define O_IGNORE_CTTY 0
+#endif
+
+#ifndef O_NDELAY
+# define O_NDELAY 0
+#endif
+
+#ifndef O_NOATIME
+# define O_NOATIME 0
+#endif
+
+#ifndef O_NONBLOCK
+# define O_NONBLOCK O_NDELAY
+#endif
+
+/* If the gnulib module 'nonblocking' is in use, guarantee a working non-zero
+ value of O_NONBLOCK. Otherwise, O_NONBLOCK is defined (above) to O_NDELAY
+ or to 0 as fallback. */
+#if 0
+# if O_NONBLOCK
+# define GNULIB_defined_O_NONBLOCK 0
+# else
+# define GNULIB_defined_O_NONBLOCK 1
+# undef O_NONBLOCK
+# define O_NONBLOCK 0x40000000
+# endif
+#endif
+
+#ifndef O_NOCTTY
+# define O_NOCTTY 0
+#endif
+
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
+#ifndef O_NOLINK
+# define O_NOLINK 0
+#endif
+
+#ifndef O_NOLINKS
+# define O_NOLINKS 0
+#endif
+
+#ifndef O_NOTRANS
+# define O_NOTRANS 0
+#endif
+
+#ifndef O_RSYNC
+# define O_RSYNC 0
+#endif
+
+#ifndef O_SEARCH
+# define O_SEARCH O_RDONLY /* This is often close enough in older systems. */
+#endif
+
+#ifndef O_SYNC
+# define O_SYNC 0
+#endif
+
+#ifndef O_TTY_INIT
+# define O_TTY_INIT 0
+#endif
+
+#if ~O_ACCMODE & (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+# undef O_ACCMODE
+# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR | O_EXEC | O_SEARCH)
+#endif
+
+/* For systems that distinguish between text and binary I/O.
+ O_BINARY is usually declared in fcntl.h */
+#if !defined O_BINARY && defined _O_BINARY
+ /* For MSC-compatible compilers. */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+
+#if defined __BEOS__ || defined __HAIKU__
+ /* BeOS 5 and Haiku have O_BINARY and O_TEXT, but they have no effect. */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+
+#ifndef O_BINARY
+# define O_BINARY 0
+# define O_TEXT 0
+#endif
+
+/* Fix up the AT_* macros. */
+
+/* Work around a bug in Solaris 9 and 10: AT_FDCWD is positive. Its
+ value exceeds INT_MAX, so its use as an int doesn't conform to the
+ C standard, and GCC and Sun C complain in some cases. If the bug
+ is present, undef AT_FDCWD here, so it can be redefined below. */
+#if 0 < AT_FDCWD && AT_FDCWD == 0xffd19553
+# undef AT_FDCWD
+#endif
+
+/* Use the same bit pattern as Solaris 9, but with the proper
+ signedness. The bit pattern is important, in case this actually is
+ Solaris with the above workaround. */
+#ifndef AT_FDCWD
+# define AT_FDCWD (-3041965)
+#endif
+
+/* Use the same values as Solaris 9. This shouldn't matter, but
+ there's no real reason to differ. */
+#ifndef AT_SYMLINK_NOFOLLOW
+# define AT_SYMLINK_NOFOLLOW 4096
+#endif
+
+#ifndef AT_REMOVEDIR
+# define AT_REMOVEDIR 1
+#endif
+
+/* Solaris 9 lacks these two, so just pick unique values. */
+#ifndef AT_SYMLINK_FOLLOW
+# define AT_SYMLINK_FOLLOW 2
+#endif
+
+#ifndef AT_EACCESS
+# define AT_EACCESS 4
+#endif
+
+
+#endif /* _GL_M4_FCNTL_H */
+#endif /* _GL_M4_FCNTL_H */
+#endif
diff --git a/contrib/tools/bison/gnulib/platform/win64/getopt.h b/contrib/tools/bison/gnulib/platform/win64/getopt.h
index a80aa65455..508c5ee82a 100644
--- a/contrib/tools/bison/gnulib/platform/win64/getopt.h
+++ b/contrib/tools/bison/gnulib/platform/win64/getopt.h
@@ -1,266 +1,266 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Declarations for getopt.
- Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_M4_GETOPT_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. We must
- also inform the replacement unistd.h to not recursively use
- <getopt.h>; our definitions will be present soon enough. */
-#if 0
-# define _GL_SYSTEM_GETOPT
-# include <getopt.h>
-# undef _GL_SYSTEM_GETOPT
-#endif
-
-#ifndef _GL_M4_GETOPT_H
-
-#ifndef __need_getopt
-# define _GL_M4_GETOPT_H 1
-#endif
-
-/* Standalone applications should #define __GETOPT_PREFIX to an
- identifier that prefixes the external functions and variables
- defined in this header. When this happens, include the
- headers that might declare getopt so that they will not cause
- confusion if included after this file (if the system had <getopt.h>,
- we have already included it). Then systematically rename
- identifiers so that they do not collide with the system functions
- and variables. Renaming avoids problems with some compilers and
- linkers. */
-#if defined __GETOPT_PREFIX && !defined __need_getopt
-# if !0
-# define __need_system_stdlib_h
-# include <stdlib.h>
-# undef __need_system_stdlib_h
-# include <stdio.h>
-# include <unistd.h>
-# endif
-# undef __need_getopt
-# undef getopt
-# undef getopt_long
-# undef getopt_long_only
-# undef optarg
-# undef opterr
-# undef optind
-# undef optopt
-# undef option
-# define __GETOPT_CONCAT(x, y) x ## y
-# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
-# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
-# define getopt __GETOPT_ID (getopt)
-# define getopt_long __GETOPT_ID (getopt_long)
-# define getopt_long_only __GETOPT_ID (getopt_long_only)
-# define optarg __GETOPT_ID (optarg)
-# define opterr __GETOPT_ID (opterr)
-# define optind __GETOPT_ID (optind)
-# define optopt __GETOPT_ID (optopt)
-# define option __GETOPT_ID (option)
-# define _getopt_internal __GETOPT_ID (getopt_internal)
-#endif
-
-/* Standalone applications get correct prototypes for getopt_long and
- getopt_long_only; they declare "char **argv". libc uses prototypes
- with "char *const *argv" that are incorrect because getopt_long and
- getopt_long_only can permute argv; this is required for backward
- compatibility (e.g., for LSB 2.0.1).
-
- This used to be '#if defined __GETOPT_PREFIX && !defined __need_getopt',
- but it caused redefinition warnings if both unistd.h and getopt.h were
- included, since unistd.h includes getopt.h having previously defined
- __need_getopt.
-
- The only place where __getopt_argv_const is used is in definitions
- of getopt_long and getopt_long_only below, but these are visible
- only if __need_getopt is not defined, so it is quite safe to rewrite
- the conditional as follows:
-*/
-#if !defined __need_getopt
-# if defined __GETOPT_PREFIX
-# define __getopt_argv_const /* empty */
-# else
-# define __getopt_argv_const const
-# endif
-#endif
-
-/* If __GNU_LIBRARY__ is not already defined, either we are being used
- standalone, or this is the first header included in the source file.
- If we are being used with glibc, we need to include <features.h>, but
- that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
- not defined, include <ctype.h>, which will pull in <features.h> for us
- if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
- doesn't flood the namespace with stuff the way some other headers do.) */
-#if !defined __GNU_LIBRARY__
-# include <ctype.h>
-#endif
-
-#ifndef __THROW
-# ifndef __GNUC_PREREQ
-# define __GNUC_PREREQ(maj, min) (0)
-# endif
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Declarations for getopt.
+ Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_M4_GETOPT_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. We must
+ also inform the replacement unistd.h to not recursively use
+ <getopt.h>; our definitions will be present soon enough. */
+#if 0
+# define _GL_SYSTEM_GETOPT
+# include <getopt.h>
+# undef _GL_SYSTEM_GETOPT
+#endif
+
+#ifndef _GL_M4_GETOPT_H
+
+#ifndef __need_getopt
+# define _GL_M4_GETOPT_H 1
+#endif
+
+/* Standalone applications should #define __GETOPT_PREFIX to an
+ identifier that prefixes the external functions and variables
+ defined in this header. When this happens, include the
+ headers that might declare getopt so that they will not cause
+ confusion if included after this file (if the system had <getopt.h>,
+ we have already included it). Then systematically rename
+ identifiers so that they do not collide with the system functions
+ and variables. Renaming avoids problems with some compilers and
+ linkers. */
+#if defined __GETOPT_PREFIX && !defined __need_getopt
+# if !0
+# define __need_system_stdlib_h
+# include <stdlib.h>
+# undef __need_system_stdlib_h
+# include <stdio.h>
+# include <unistd.h>
+# endif
+# undef __need_getopt
+# undef getopt
+# undef getopt_long
+# undef getopt_long_only
+# undef optarg
+# undef opterr
+# undef optind
+# undef optopt
+# undef option
+# define __GETOPT_CONCAT(x, y) x ## y
+# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
+# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
+# define getopt __GETOPT_ID (getopt)
+# define getopt_long __GETOPT_ID (getopt_long)
+# define getopt_long_only __GETOPT_ID (getopt_long_only)
+# define optarg __GETOPT_ID (optarg)
+# define opterr __GETOPT_ID (opterr)
+# define optind __GETOPT_ID (optind)
+# define optopt __GETOPT_ID (optopt)
+# define option __GETOPT_ID (option)
+# define _getopt_internal __GETOPT_ID (getopt_internal)
+#endif
+
+/* Standalone applications get correct prototypes for getopt_long and
+ getopt_long_only; they declare "char **argv". libc uses prototypes
+ with "char *const *argv" that are incorrect because getopt_long and
+ getopt_long_only can permute argv; this is required for backward
+ compatibility (e.g., for LSB 2.0.1).
+
+ This used to be '#if defined __GETOPT_PREFIX && !defined __need_getopt',
+ but it caused redefinition warnings if both unistd.h and getopt.h were
+ included, since unistd.h includes getopt.h having previously defined
+ __need_getopt.
+
+ The only place where __getopt_argv_const is used is in definitions
+ of getopt_long and getopt_long_only below, but these are visible
+ only if __need_getopt is not defined, so it is quite safe to rewrite
+ the conditional as follows:
+*/
+#if !defined __need_getopt
+# if defined __GETOPT_PREFIX
+# define __getopt_argv_const /* empty */
+# else
+# define __getopt_argv_const const
+# endif
+#endif
+
+/* If __GNU_LIBRARY__ is not already defined, either we are being used
+ standalone, or this is the first header included in the source file.
+ If we are being used with glibc, we need to include <features.h>, but
+ that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
+ not defined, include <ctype.h>, which will pull in <features.h> for us
+ if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
+ doesn't flood the namespace with stuff the way some other headers do.) */
+#if !defined __GNU_LIBRARY__
+# include <ctype.h>
+#endif
+
+#ifndef __THROW
+# ifndef __GNUC_PREREQ
+# define __GNUC_PREREQ(maj, min) (0)
+# endif
+# if defined __cplusplus && __GNUC_PREREQ (2,8)
# define __THROW noexcept
-# else
-# define __THROW
-# endif
-#endif
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* For communication from 'getopt' to the caller.
- When 'getopt' finds an option that takes an argument,
- the argument value is returned here.
- Also, when 'ordering' is RETURN_IN_ORDER,
- each non-option ARGV-element is returned here. */
-
-extern char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
- This is used for communication to and from the caller
- and for communication between successive calls to 'getopt'.
-
- On entry to 'getopt', zero means this is the first call; initialize.
-
- When 'getopt' returns -1, this is the index of the first of the
- non-option elements that the caller should itself scan.
-
- Otherwise, 'optind' communicates from one call to the next
- how much of ARGV has been scanned so far. */
-
-extern int optind;
-
-/* Callers store zero here to inhibit the error message 'getopt' prints
- for unrecognized options. */
-
-extern int opterr;
-
-/* Set to an option character which was unrecognized. */
-
-extern int optopt;
-
-#ifndef __need_getopt
-/* Describe the long-named options requested by the application.
- The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
- of 'struct option' terminated by an element containing a name which is
- zero.
-
- The field 'has_arg' is:
- no_argument (or 0) if the option does not take an argument,
- required_argument (or 1) if the option requires an argument,
- optional_argument (or 2) if the option takes an optional argument.
-
- If the field 'flag' is not NULL, it points to a variable that is set
- to the value given in the field 'val' when the option is found, but
- left unchanged if the option is not found.
-
- To have a long-named option do something other than set an 'int' to
- a compiled-in constant, such as set a value from 'optarg', set the
- option's 'flag' field to zero and its 'val' field to a nonzero
- value (the equivalent single-letter option character, if there is
- one). For long options that have a zero 'flag' field, 'getopt'
- returns the contents of the 'val' field. */
-
-# if !GNULIB_defined_struct_option
-struct option
-{
- const char *name;
- /* has_arg can't be an enum because some compilers complain about
- type mismatches in all the code that assumes it is an int. */
- int has_arg;
- int *flag;
- int val;
-};
-# define GNULIB_defined_struct_option 1
-# endif
-
-/* Names for the values of the 'has_arg' field of 'struct option'. */
-
-# define no_argument 0
-# define required_argument 1
-# define optional_argument 2
-#endif /* need getopt */
-
-
-/* Get definitions and prototypes for functions to process the
- arguments in ARGV (ARGC of them, minus the program name) for
- options given in OPTS.
-
- Return the option character from OPTS just read. Return -1 when
- there are no more options. For unrecognized options, or options
- missing arguments, 'optopt' is set to the option letter, and '?' is
- returned.
-
- The OPTS string is a list of characters which are recognized option
- letters, optionally followed by colons, specifying that that letter
- takes an argument, to be placed in 'optarg'.
-
- If a letter in OPTS is followed by two colons, its argument is
- optional. This behavior is specific to the GNU 'getopt'.
-
- The argument '--' causes premature termination of argument
- scanning, explicitly telling 'getopt' that there are no more
- options.
-
- If OPTS begins with '-', then non-option arguments are treated as
- arguments to the option '\1'. This behavior is specific to the GNU
- 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
- the environment, then do not permute arguments. */
-
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
- __THROW _GL_ARG_NONNULL ((2, 3));
-
-#ifndef __need_getopt
-extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind)
- __THROW _GL_ARG_NONNULL ((2, 3));
-extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind)
- __THROW _GL_ARG_NONNULL ((2, 3));
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-/* Make sure we later can get all the definitions and declarations. */
-#undef __need_getopt
-
-#endif /* _GL_M4_GETOPT_H */
-#endif /* _GL_M4_GETOPT_H */
+# else
+# define __THROW
+# endif
+#endif
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* For communication from 'getopt' to the caller.
+ When 'getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when 'ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+extern char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to 'getopt'.
+
+ On entry to 'getopt', zero means this is the first call; initialize.
+
+ When 'getopt' returns -1, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, 'optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+extern int optind;
+
+/* Callers store zero here to inhibit the error message 'getopt' prints
+ for unrecognized options. */
+
+extern int opterr;
+
+/* Set to an option character which was unrecognized. */
+
+extern int optopt;
+
+#ifndef __need_getopt
+/* Describe the long-named options requested by the application.
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+ of 'struct option' terminated by an element containing a name which is
+ zero.
+
+ The field 'has_arg' is:
+ no_argument (or 0) if the option does not take an argument,
+ required_argument (or 1) if the option requires an argument,
+ optional_argument (or 2) if the option takes an optional argument.
+
+ If the field 'flag' is not NULL, it points to a variable that is set
+ to the value given in the field 'val' when the option is found, but
+ left unchanged if the option is not found.
+
+ To have a long-named option do something other than set an 'int' to
+ a compiled-in constant, such as set a value from 'optarg', set the
+ option's 'flag' field to zero and its 'val' field to a nonzero
+ value (the equivalent single-letter option character, if there is
+ one). For long options that have a zero 'flag' field, 'getopt'
+ returns the contents of the 'val' field. */
+
+# if !GNULIB_defined_struct_option
+struct option
+{
+ const char *name;
+ /* has_arg can't be an enum because some compilers complain about
+ type mismatches in all the code that assumes it is an int. */
+ int has_arg;
+ int *flag;
+ int val;
+};
+# define GNULIB_defined_struct_option 1
+# endif
+
+/* Names for the values of the 'has_arg' field of 'struct option'. */
+
+# define no_argument 0
+# define required_argument 1
+# define optional_argument 2
+#endif /* need getopt */
+
+
+/* Get definitions and prototypes for functions to process the
+ arguments in ARGV (ARGC of them, minus the program name) for
+ options given in OPTS.
+
+ Return the option character from OPTS just read. Return -1 when
+ there are no more options. For unrecognized options, or options
+ missing arguments, 'optopt' is set to the option letter, and '?' is
+ returned.
+
+ The OPTS string is a list of characters which are recognized option
+ letters, optionally followed by colons, specifying that that letter
+ takes an argument, to be placed in 'optarg'.
+
+ If a letter in OPTS is followed by two colons, its argument is
+ optional. This behavior is specific to the GNU 'getopt'.
+
+ The argument '--' causes premature termination of argument
+ scanning, explicitly telling 'getopt' that there are no more
+ options.
+
+ If OPTS begins with '-', then non-option arguments are treated as
+ arguments to the option '\1'. This behavior is specific to the GNU
+ 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
+ the environment, then do not permute arguments. */
+
+extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
+ __THROW _GL_ARG_NONNULL ((2, 3));
+
+#ifndef __need_getopt
+extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind)
+ __THROW _GL_ARG_NONNULL ((2, 3));
+extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind)
+ __THROW _GL_ARG_NONNULL ((2, 3));
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/* Make sure we later can get all the definitions and declarations. */
+#undef __need_getopt
+
+#endif /* _GL_M4_GETOPT_H */
+#endif /* _GL_M4_GETOPT_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/langinfo.h b/contrib/tools/bison/gnulib/platform/win64/langinfo.h
index 3fac25a2a7..d7cda4eaed 100644
--- a/contrib/tools/bison/gnulib/platform/win64/langinfo.h
+++ b/contrib/tools/bison/gnulib/platform/win64/langinfo.h
@@ -1,478 +1,478 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Substitute for and wrapper around <langinfo.h>.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/*
- * POSIX <langinfo.h> for platforms that lack it or have an incomplete one.
- * <http://www.opengroup.org/onlinepubs/9699919799/basedefs/langinfo.h.html>
- */
-
-#ifndef _GL_M4_LANGINFO_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. */
-#if 0
-# include <langinfo.h>
-#endif
-
-#ifndef _GL_M4_LANGINFO_H
-#define _GL_M4_LANGINFO_H
-
-
-#if !0
-
-/* A platform that lacks <langinfo.h>. */
-
-/* Assume that it also lacks <nl_types.h> and the nl_item type. */
-# if !GNULIB_defined_nl_item
-typedef int nl_item;
-# define GNULIB_defined_nl_item 1
-# endif
-
-/* nl_langinfo items of the LC_CTYPE category */
-# define CODESET 10000
-/* nl_langinfo items of the LC_NUMERIC category */
-# define RADIXCHAR 10001
-# define THOUSEP 10002
-/* nl_langinfo items of the LC_TIME category */
-# define D_T_FMT 10003
-# define D_FMT 10004
-# define T_FMT 10005
-# define T_FMT_AMPM 10006
-# define AM_STR 10007
-# define PM_STR 10008
-# define DAY_1 10009
-# define DAY_2 (DAY_1 + 1)
-# define DAY_3 (DAY_1 + 2)
-# define DAY_4 (DAY_1 + 3)
-# define DAY_5 (DAY_1 + 4)
-# define DAY_6 (DAY_1 + 5)
-# define DAY_7 (DAY_1 + 6)
-# define ABDAY_1 10016
-# define ABDAY_2 (ABDAY_1 + 1)
-# define ABDAY_3 (ABDAY_1 + 2)
-# define ABDAY_4 (ABDAY_1 + 3)
-# define ABDAY_5 (ABDAY_1 + 4)
-# define ABDAY_6 (ABDAY_1 + 5)
-# define ABDAY_7 (ABDAY_1 + 6)
-# define MON_1 10023
-# define MON_2 (MON_1 + 1)
-# define MON_3 (MON_1 + 2)
-# define MON_4 (MON_1 + 3)
-# define MON_5 (MON_1 + 4)
-# define MON_6 (MON_1 + 5)
-# define MON_7 (MON_1 + 6)
-# define MON_8 (MON_1 + 7)
-# define MON_9 (MON_1 + 8)
-# define MON_10 (MON_1 + 9)
-# define MON_11 (MON_1 + 10)
-# define MON_12 (MON_1 + 11)
-# define ABMON_1 10035
-# define ABMON_2 (ABMON_1 + 1)
-# define ABMON_3 (ABMON_1 + 2)
-# define ABMON_4 (ABMON_1 + 3)
-# define ABMON_5 (ABMON_1 + 4)
-# define ABMON_6 (ABMON_1 + 5)
-# define ABMON_7 (ABMON_1 + 6)
-# define ABMON_8 (ABMON_1 + 7)
-# define ABMON_9 (ABMON_1 + 8)
-# define ABMON_10 (ABMON_1 + 9)
-# define ABMON_11 (ABMON_1 + 10)
-# define ABMON_12 (ABMON_1 + 11)
-# define ERA 10047
-# define ERA_D_FMT 10048
-# define ERA_D_T_FMT 10049
-# define ERA_T_FMT 10050
-# define ALT_DIGITS 10051
-/* nl_langinfo items of the LC_MONETARY category */
-# define CRNCYSTR 10052
-/* nl_langinfo items of the LC_MESSAGES category */
-# define YESEXPR 10053
-# define NOEXPR 10054
-
-#else
-
-/* A platform that has <langinfo.h>. */
-
-# if !0
-# define CODESET 10000
-# define GNULIB_defined_CODESET 1
-# endif
-
-# if !0
-# define T_FMT_AMPM 10006
-# define GNULIB_defined_T_FMT_AMPM 1
-# endif
-
-# if !0
-# define ERA 10047
-# define ERA_D_FMT 10048
-# define ERA_D_T_FMT 10049
-# define ERA_T_FMT 10050
-# define ALT_DIGITS 10051
-# define GNULIB_defined_ERA 1
-# endif
-
-# if !0
-# define YESEXPR 10053
-# define NOEXPR 10054
-# define GNULIB_defined_YESEXPR 1
-# endif
-
-#endif
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-/* Declare overridden functions. */
-
-
-/* Return a piece of locale dependent information.
- Note: The difference between nl_langinfo (CODESET) and locale_charset ()
- is that the latter normalizes the encoding names to GNU conventions. */
-
-#if 1
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef nl_langinfo
-# define nl_langinfo rpl_nl_langinfo
-# endif
-_GL_FUNCDECL_RPL (nl_langinfo, char *, (nl_item item));
-_GL_CXXALIAS_RPL (nl_langinfo, char *, (nl_item item));
-# else
-# if !0
-_GL_FUNCDECL_SYS (nl_langinfo, char *, (nl_item item));
-# endif
-_GL_CXXALIAS_SYS (nl_langinfo, char *, (nl_item item));
-# endif
-_GL_CXXALIASWARN (nl_langinfo);
-#elif defined GNULIB_POSIXCHECK
-# undef nl_langinfo
-# if HAVE_RAW_DECL_NL_LANGINFO
-_GL_WARN_ON_USE (nl_langinfo, "nl_langinfo is not portable - "
- "use gnulib module nl_langinfo for portability");
-# endif
-#endif
-
-
-#endif /* _GL_M4_LANGINFO_H */
-#endif /* _GL_M4_LANGINFO_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Substitute for and wrapper around <langinfo.h>.
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/*
+ * POSIX <langinfo.h> for platforms that lack it or have an incomplete one.
+ * <http://www.opengroup.org/onlinepubs/9699919799/basedefs/langinfo.h.html>
+ */
+
+#ifndef _GL_M4_LANGINFO_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. */
+#if 0
+# include <langinfo.h>
+#endif
+
+#ifndef _GL_M4_LANGINFO_H
+#define _GL_M4_LANGINFO_H
+
+
+#if !0
+
+/* A platform that lacks <langinfo.h>. */
+
+/* Assume that it also lacks <nl_types.h> and the nl_item type. */
+# if !GNULIB_defined_nl_item
+typedef int nl_item;
+# define GNULIB_defined_nl_item 1
+# endif
+
+/* nl_langinfo items of the LC_CTYPE category */
+# define CODESET 10000
+/* nl_langinfo items of the LC_NUMERIC category */
+# define RADIXCHAR 10001
+# define THOUSEP 10002
+/* nl_langinfo items of the LC_TIME category */
+# define D_T_FMT 10003
+# define D_FMT 10004
+# define T_FMT 10005
+# define T_FMT_AMPM 10006
+# define AM_STR 10007
+# define PM_STR 10008
+# define DAY_1 10009
+# define DAY_2 (DAY_1 + 1)
+# define DAY_3 (DAY_1 + 2)
+# define DAY_4 (DAY_1 + 3)
+# define DAY_5 (DAY_1 + 4)
+# define DAY_6 (DAY_1 + 5)
+# define DAY_7 (DAY_1 + 6)
+# define ABDAY_1 10016
+# define ABDAY_2 (ABDAY_1 + 1)
+# define ABDAY_3 (ABDAY_1 + 2)
+# define ABDAY_4 (ABDAY_1 + 3)
+# define ABDAY_5 (ABDAY_1 + 4)
+# define ABDAY_6 (ABDAY_1 + 5)
+# define ABDAY_7 (ABDAY_1 + 6)
+# define MON_1 10023
+# define MON_2 (MON_1 + 1)
+# define MON_3 (MON_1 + 2)
+# define MON_4 (MON_1 + 3)
+# define MON_5 (MON_1 + 4)
+# define MON_6 (MON_1 + 5)
+# define MON_7 (MON_1 + 6)
+# define MON_8 (MON_1 + 7)
+# define MON_9 (MON_1 + 8)
+# define MON_10 (MON_1 + 9)
+# define MON_11 (MON_1 + 10)
+# define MON_12 (MON_1 + 11)
+# define ABMON_1 10035
+# define ABMON_2 (ABMON_1 + 1)
+# define ABMON_3 (ABMON_1 + 2)
+# define ABMON_4 (ABMON_1 + 3)
+# define ABMON_5 (ABMON_1 + 4)
+# define ABMON_6 (ABMON_1 + 5)
+# define ABMON_7 (ABMON_1 + 6)
+# define ABMON_8 (ABMON_1 + 7)
+# define ABMON_9 (ABMON_1 + 8)
+# define ABMON_10 (ABMON_1 + 9)
+# define ABMON_11 (ABMON_1 + 10)
+# define ABMON_12 (ABMON_1 + 11)
+# define ERA 10047
+# define ERA_D_FMT 10048
+# define ERA_D_T_FMT 10049
+# define ERA_T_FMT 10050
+# define ALT_DIGITS 10051
+/* nl_langinfo items of the LC_MONETARY category */
+# define CRNCYSTR 10052
+/* nl_langinfo items of the LC_MESSAGES category */
+# define YESEXPR 10053
+# define NOEXPR 10054
+
+#else
+
+/* A platform that has <langinfo.h>. */
+
+# if !0
+# define CODESET 10000
+# define GNULIB_defined_CODESET 1
+# endif
+
+# if !0
+# define T_FMT_AMPM 10006
+# define GNULIB_defined_T_FMT_AMPM 1
+# endif
+
+# if !0
+# define ERA 10047
+# define ERA_D_FMT 10048
+# define ERA_D_T_FMT 10049
+# define ERA_T_FMT 10050
+# define ALT_DIGITS 10051
+# define GNULIB_defined_ERA 1
+# endif
+
+# if !0
+# define YESEXPR 10053
+# define NOEXPR 10054
+# define GNULIB_defined_YESEXPR 1
+# endif
+
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+/* Declare overridden functions. */
+
+
+/* Return a piece of locale dependent information.
+ Note: The difference between nl_langinfo (CODESET) and locale_charset ()
+ is that the latter normalizes the encoding names to GNU conventions. */
+
+#if 1
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef nl_langinfo
+# define nl_langinfo rpl_nl_langinfo
+# endif
+_GL_FUNCDECL_RPL (nl_langinfo, char *, (nl_item item));
+_GL_CXXALIAS_RPL (nl_langinfo, char *, (nl_item item));
+# else
+# if !0
+_GL_FUNCDECL_SYS (nl_langinfo, char *, (nl_item item));
+# endif
+_GL_CXXALIAS_SYS (nl_langinfo, char *, (nl_item item));
+# endif
+_GL_CXXALIASWARN (nl_langinfo);
+#elif defined GNULIB_POSIXCHECK
+# undef nl_langinfo
+# if HAVE_RAW_DECL_NL_LANGINFO
+_GL_WARN_ON_USE (nl_langinfo, "nl_langinfo is not portable - "
+ "use gnulib module nl_langinfo for portability");
+# endif
+#endif
+
+
+#endif /* _GL_M4_LANGINFO_H */
+#endif /* _GL_M4_LANGINFO_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/locale.h b/contrib/tools/bison/gnulib/platform/win64/locale.h
index ddebf413d2..d3ef06b156 100644
--- a/contrib/tools/bison/gnulib/platform/win64/locale.h
+++ b/contrib/tools/bison/gnulib/platform/win64/locale.h
@@ -1,536 +1,536 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* A POSIX <locale.h>.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-#ifdef _GL_ALREADY_INCLUDING_LOCALE_H
-
-/* Special invocation conventions to handle Solaris header files
- (through Solaris 10) when combined with gettext's libintl.h. */
-
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* A POSIX <locale.h>.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+#ifdef _GL_ALREADY_INCLUDING_LOCALE_H
+
+/* Special invocation conventions to handle Solaris header files
+ (through Solaris 10) when combined with gettext's libintl.h. */
+
#if _MSC_VER >= 1900
#include <../ucrt/locale.h>
#else
#include <../include/locale.h>
#endif
-
-#else
-/* Normal invocation convention. */
-
-#ifndef _GL_M4_LOCALE_H
-
-#define _GL_ALREADY_INCLUDING_LOCALE_H
-
-/* The include_next requires a split double-inclusion guard. */
+
+#else
+/* Normal invocation convention. */
+
+#ifndef _GL_M4_LOCALE_H
+
+#define _GL_ALREADY_INCLUDING_LOCALE_H
+
+/* The include_next requires a split double-inclusion guard. */
#if _MSC_VER >= 1900
#include <../ucrt/locale.h>
#else
#include <../include/locale.h>
#endif
-
-#undef _GL_ALREADY_INCLUDING_LOCALE_H
-
-#ifndef _GL_M4_LOCALE_H
-#define _GL_M4_LOCALE_H
-
-/* NetBSD 5.0 mis-defines NULL. */
-#include <stddef.h>
-
-/* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */
-#if 0
-# include <xlocale.h>
-#endif
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
- On systems that don't define it, use the same value as GNU libintl. */
-#if !defined LC_MESSAGES
-# define LC_MESSAGES 1729
-#endif
-
-/* Bionic libc's 'struct lconv' is just a dummy. */
-#if 1
-# define lconv rpl_lconv
-struct lconv
-{
- /* All 'char *' are actually 'const char *'. */
-
- /* Members that depend on the LC_NUMERIC category of the locale. See
- <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_04> */
-
- /* Symbol used as decimal point. */
- char *decimal_point;
- /* Symbol used to separate groups of digits to the left of the decimal
- point. */
- char *thousands_sep;
- /* Definition of the size of groups of digits to the left of the decimal
- point. */
- char *grouping;
-
- /* Members that depend on the LC_MONETARY category of the locale. See
- <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_03> */
-
- /* Symbol used as decimal point. */
- char *mon_decimal_point;
- /* Symbol used to separate groups of digits to the left of the decimal
- point. */
- char *mon_thousands_sep;
- /* Definition of the size of groups of digits to the left of the decimal
- point. */
- char *mon_grouping;
- /* Sign used to indicate a value >= 0. */
- char *positive_sign;
- /* Sign used to indicate a value < 0. */
- char *negative_sign;
-
- /* For formatting local currency. */
- /* Currency symbol (3 characters) followed by separator (1 character). */
- char *currency_symbol;
- /* Number of digits after the decimal point. */
- char frac_digits;
- /* For values >= 0: 1 if the currency symbol precedes the number, 0 if it
- comes after the number. */
- char p_cs_precedes;
- /* For values >= 0: Position of the sign. */
- char p_sign_posn;
- /* For values >= 0: Placement of spaces between currency symbol, sign, and
- number. */
- char p_sep_by_space;
- /* For values < 0: 1 if the currency symbol precedes the number, 0 if it
- comes after the number. */
- char n_cs_precedes;
- /* For values < 0: Position of the sign. */
- char n_sign_posn;
- /* For values < 0: Placement of spaces between currency symbol, sign, and
- number. */
- char n_sep_by_space;
-
- /* For formatting international currency. */
- /* Currency symbol (3 characters) followed by separator (1 character). */
- char *int_curr_symbol;
- /* Number of digits after the decimal point. */
- char int_frac_digits;
- /* For values >= 0: 1 if the currency symbol precedes the number, 0 if it
- comes after the number. */
- char int_p_cs_precedes;
- /* For values >= 0: Position of the sign. */
- char int_p_sign_posn;
- /* For values >= 0: Placement of spaces between currency symbol, sign, and
- number. */
- char int_p_sep_by_space;
- /* For values < 0: 1 if the currency symbol precedes the number, 0 if it
- comes after the number. */
- char int_n_cs_precedes;
- /* For values < 0: Position of the sign. */
- char int_n_sign_posn;
- /* For values < 0: Placement of spaces between currency symbol, sign, and
- number. */
- char int_n_sep_by_space;
-};
-#endif
-
-#if 1
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef localeconv
-# define localeconv rpl_localeconv
-# endif
-_GL_FUNCDECL_RPL (localeconv, struct lconv *, (void));
-_GL_CXXALIAS_RPL (localeconv, struct lconv *, (void));
-# else
-_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void));
-# endif
-_GL_CXXALIASWARN (localeconv);
-#elif 1
-# undef localeconv
-# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv
-#elif defined GNULIB_POSIXCHECK
-# undef localeconv
-# if HAVE_RAW_DECL_LOCALECONV
-_GL_WARN_ON_USE (localeconv,
- "localeconv returns too few information on some platforms - "
- "use gnulib module localeconv for portability");
-# endif
-#endif
-
-#if IN_M4_GNULIB_TESTS
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef setlocale
-# define setlocale rpl_setlocale
-# define GNULIB_defined_setlocale 1
-# endif
-_GL_FUNCDECL_RPL (setlocale, char *, (int category, const char *locale));
-_GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale));
-# else
-_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale));
-# endif
-_GL_CXXALIASWARN (setlocale);
-#elif defined GNULIB_POSIXCHECK
-# undef setlocale
-# if HAVE_RAW_DECL_SETLOCALE
-_GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - "
- "use gnulib module setlocale for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef duplocale
-# define duplocale rpl_duplocale
-# endif
-_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale));
-# else
-# if 1
-_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale));
-# endif
-# endif
-# if 1
-_GL_CXXALIASWARN (duplocale);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef duplocale
-# if HAVE_RAW_DECL_DUPLOCALE
-_GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
- "use gnulib module duplocale for portability");
-# endif
-#endif
-
-#endif /* _GL_M4_LOCALE_H */
-#endif /* ! _GL_ALREADY_INCLUDING_LOCALE_H */
-#endif /* _GL_M4_LOCALE_H */
+
+#undef _GL_ALREADY_INCLUDING_LOCALE_H
+
+#ifndef _GL_M4_LOCALE_H
+#define _GL_M4_LOCALE_H
+
+/* NetBSD 5.0 mis-defines NULL. */
+#include <stddef.h>
+
+/* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */
+#if 0
+# include <xlocale.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
+ On systems that don't define it, use the same value as GNU libintl. */
+#if !defined LC_MESSAGES
+# define LC_MESSAGES 1729
+#endif
+
+/* Bionic libc's 'struct lconv' is just a dummy. */
+#if 1
+# define lconv rpl_lconv
+struct lconv
+{
+ /* All 'char *' are actually 'const char *'. */
+
+ /* Members that depend on the LC_NUMERIC category of the locale. See
+ <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_04> */
+
+ /* Symbol used as decimal point. */
+ char *decimal_point;
+ /* Symbol used to separate groups of digits to the left of the decimal
+ point. */
+ char *thousands_sep;
+ /* Definition of the size of groups of digits to the left of the decimal
+ point. */
+ char *grouping;
+
+ /* Members that depend on the LC_MONETARY category of the locale. See
+ <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_03> */
+
+ /* Symbol used as decimal point. */
+ char *mon_decimal_point;
+ /* Symbol used to separate groups of digits to the left of the decimal
+ point. */
+ char *mon_thousands_sep;
+ /* Definition of the size of groups of digits to the left of the decimal
+ point. */
+ char *mon_grouping;
+ /* Sign used to indicate a value >= 0. */
+ char *positive_sign;
+ /* Sign used to indicate a value < 0. */
+ char *negative_sign;
+
+ /* For formatting local currency. */
+ /* Currency symbol (3 characters) followed by separator (1 character). */
+ char *currency_symbol;
+ /* Number of digits after the decimal point. */
+ char frac_digits;
+ /* For values >= 0: 1 if the currency symbol precedes the number, 0 if it
+ comes after the number. */
+ char p_cs_precedes;
+ /* For values >= 0: Position of the sign. */
+ char p_sign_posn;
+ /* For values >= 0: Placement of spaces between currency symbol, sign, and
+ number. */
+ char p_sep_by_space;
+ /* For values < 0: 1 if the currency symbol precedes the number, 0 if it
+ comes after the number. */
+ char n_cs_precedes;
+ /* For values < 0: Position of the sign. */
+ char n_sign_posn;
+ /* For values < 0: Placement of spaces between currency symbol, sign, and
+ number. */
+ char n_sep_by_space;
+
+ /* For formatting international currency. */
+ /* Currency symbol (3 characters) followed by separator (1 character). */
+ char *int_curr_symbol;
+ /* Number of digits after the decimal point. */
+ char int_frac_digits;
+ /* For values >= 0: 1 if the currency symbol precedes the number, 0 if it
+ comes after the number. */
+ char int_p_cs_precedes;
+ /* For values >= 0: Position of the sign. */
+ char int_p_sign_posn;
+ /* For values >= 0: Placement of spaces between currency symbol, sign, and
+ number. */
+ char int_p_sep_by_space;
+ /* For values < 0: 1 if the currency symbol precedes the number, 0 if it
+ comes after the number. */
+ char int_n_cs_precedes;
+ /* For values < 0: Position of the sign. */
+ char int_n_sign_posn;
+ /* For values < 0: Placement of spaces between currency symbol, sign, and
+ number. */
+ char int_n_sep_by_space;
+};
+#endif
+
+#if 1
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef localeconv
+# define localeconv rpl_localeconv
+# endif
+_GL_FUNCDECL_RPL (localeconv, struct lconv *, (void));
+_GL_CXXALIAS_RPL (localeconv, struct lconv *, (void));
+# else
+_GL_CXXALIAS_SYS (localeconv, struct lconv *, (void));
+# endif
+_GL_CXXALIASWARN (localeconv);
+#elif 1
+# undef localeconv
+# define localeconv localeconv_used_without_requesting_gnulib_module_localeconv
+#elif defined GNULIB_POSIXCHECK
+# undef localeconv
+# if HAVE_RAW_DECL_LOCALECONV
+_GL_WARN_ON_USE (localeconv,
+ "localeconv returns too few information on some platforms - "
+ "use gnulib module localeconv for portability");
+# endif
+#endif
+
+#if IN_M4_GNULIB_TESTS
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef setlocale
+# define setlocale rpl_setlocale
+# define GNULIB_defined_setlocale 1
+# endif
+_GL_FUNCDECL_RPL (setlocale, char *, (int category, const char *locale));
+_GL_CXXALIAS_RPL (setlocale, char *, (int category, const char *locale));
+# else
+_GL_CXXALIAS_SYS (setlocale, char *, (int category, const char *locale));
+# endif
+_GL_CXXALIASWARN (setlocale);
+#elif defined GNULIB_POSIXCHECK
+# undef setlocale
+# if HAVE_RAW_DECL_SETLOCALE
+_GL_WARN_ON_USE (setlocale, "setlocale works differently on native Windows - "
+ "use gnulib module setlocale for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef duplocale
+# define duplocale rpl_duplocale
+# endif
+_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale));
+# else
+# if 1
+_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale));
+# endif
+# endif
+# if 1
+_GL_CXXALIASWARN (duplocale);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef duplocale
+# if HAVE_RAW_DECL_DUPLOCALE
+_GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
+ "use gnulib module duplocale for portability");
+# endif
+#endif
+
+#endif /* _GL_M4_LOCALE_H */
+#endif /* ! _GL_ALREADY_INCLUDING_LOCALE_H */
+#endif /* _GL_M4_LOCALE_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/math.h b/contrib/tools/bison/gnulib/platform/win64/math.h
index b2a0023d11..09a9a7b0c2 100644
--- a/contrib/tools/bison/gnulib/platform/win64/math.h
+++ b/contrib/tools/bison/gnulib/platform/win64/math.h
@@ -1,2599 +1,2599 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* A GNU-like <math.h>.
-
- Copyright (C) 2002-2003, 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_M4_MATH_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* A GNU-like <math.h>.
+
+ Copyright (C) 2002-2003, 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_M4_MATH_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. */
#if _MSC_VER >= 1900
#include <../ucrt/math.h>
#else
#include <../include/math.h>
#endif
-
-#ifndef _GL_M4_MATH_H
-#define _GL_M4_MATH_H
-
+
+#ifndef _GL_M4_MATH_H
+#define _GL_M4_MATH_H
+
#if _MSC_VER >= 1800 // [
#else // ] _MSC_VER >= 1600 [
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef _GL_MATH_INLINE
-# define _GL_MATH_INLINE _GL_INLINE
-#endif
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-#ifdef __cplusplus
-/* Helper macros to define type-generic function FUNC as overloaded functions,
- rather than as macros like in C. POSIX declares these with an argument of
- real-floating (that is, one of float, double, or long double). */
-# define _GL_MATH_CXX_REAL_FLOATING_DECL_1(func) \
-static inline int \
-_gl_cxx_ ## func ## f (float f) \
-{ \
- return func (f); \
-} \
-static inline int \
-_gl_cxx_ ## func ## d (double d) \
-{ \
- return func (d); \
-} \
-static inline int \
-_gl_cxx_ ## func ## l (long double l) \
-{ \
- return func (l); \
-}
-# define _GL_MATH_CXX_REAL_FLOATING_DECL_2(func) \
-inline int \
-func (float f) \
-{ \
- return _gl_cxx_ ## func ## f (f); \
-} \
-inline int \
-func (double d) \
-{ \
- return _gl_cxx_ ## func ## d (d); \
-} \
-inline int \
-func (long double l) \
-{ \
- return _gl_cxx_ ## func ## l (l); \
-}
-#endif
-
-/* Helper macros to define a portability warning for the
- classification macro FUNC called with VALUE. POSIX declares the
- classification macros with an argument of real-floating (that is,
- one of float, double, or long double). */
-#define _GL_WARN_REAL_FLOATING_DECL(func) \
-_GL_MATH_INLINE int \
-rpl_ ## func ## f (float f) \
-{ \
- return func (f); \
-} \
-_GL_MATH_INLINE int \
-rpl_ ## func ## d (double d) \
-{ \
- return func (d); \
-} \
-_GL_MATH_INLINE int \
-rpl_ ## func ## l (long double l) \
-{ \
- return func (l); \
-} \
-_GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \
- "use gnulib module " #func " for portability"); \
-_GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \
- "use gnulib module " #func " for portability"); \
-_GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \
- "use gnulib module " #func " for portability")
-#define _GL_WARN_REAL_FLOATING_IMPL(func, value) \
- (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \
- : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \
- : rpl_ ## func ## l (value))
-
-
-#if 0
-/* Pull in a function that fixes the 'int' to 'long double' conversion
- of glibc 2.7. */
-_GL_EXTERN_C void _Qp_itoq (long double *, int);
-static void (*_gl_math_fix_itold) (long double *, int) = _Qp_itoq;
-#endif
-
-
-/* POSIX allows platforms that don't support NAN. But all major
- machines in the past 15 years have supported something close to
- IEEE NaN, so we define this unconditionally. We also must define
- it on platforms like Solaris 10, where NAN is present but defined
- as a function pointer rather than a floating point constant. */
-#if !defined NAN || 0
-# if !GNULIB_defined_NAN
-# undef NAN
- /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler
- choke on the expression 0.0 / 0.0. */
-# if defined __DECC || defined _MSC_VER
-_GL_MATH_INLINE float
-_NaN ()
-{
- static float zero = 0.0f;
- return zero / zero;
-}
-# define NAN (_NaN())
-# else
-# define NAN (0.0f / 0.0f)
-# endif
-# define GNULIB_defined_NAN 1
-# endif
-#endif
-
-/* Solaris 10 defines HUGE_VAL, but as a function pointer rather
- than a floating point constant. */
-#if 0
-# undef HUGE_VALF
-# define HUGE_VALF (1.0f / 0.0f)
-# undef HUGE_VAL
-# define HUGE_VAL (1.0 / 0.0)
-# undef HUGE_VALL
-# define HUGE_VALL (1.0L / 0.0L)
-#endif
-
-/* HUGE_VALF is a 'float' Infinity. */
-#ifndef HUGE_VALF
-# if defined _MSC_VER
-/* The Microsoft MSVC 9 compiler chokes on the expression 1.0f / 0.0f. */
-# define HUGE_VALF (1e25f * 1e25f)
-# else
-# define HUGE_VALF (1.0f / 0.0f)
-# endif
-#endif
-
-/* HUGE_VAL is a 'double' Infinity. */
-#ifndef HUGE_VAL
-# if defined _MSC_VER
-/* The Microsoft MSVC 9 compiler chokes on the expression 1.0 / 0.0. */
-# define HUGE_VAL (1e250 * 1e250)
-# else
-# define HUGE_VAL (1.0 / 0.0)
-# endif
-#endif
-
-/* HUGE_VALL is a 'long double' Infinity. */
-#ifndef HUGE_VALL
-# if defined _MSC_VER
-/* The Microsoft MSVC 9 compiler chokes on the expression 1.0L / 0.0L. */
-# define HUGE_VALL (1e250L * 1e250L)
-# else
-# define HUGE_VALL (1.0L / 0.0L)
-# endif
-#endif
-
-
-/* Ensure FP_ILOGB0 and FP_ILOGBNAN are defined. */
-#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN)
-# if defined __NetBSD__ || defined __sgi
- /* NetBSD, IRIX 6.5: match what ilogb() does */
-# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
-# define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
-# elif defined _AIX
- /* AIX 5.1: match what ilogb() does in AIX >= 5.2 */
-# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
-# define FP_ILOGBNAN 2147483647 /* INT_MAX */
-# elif defined __sun
- /* Solaris 9: match what ilogb() does */
-# define FP_ILOGB0 (- 2147483647) /* - INT_MAX */
-# define FP_ILOGBNAN 2147483647 /* INT_MAX */
-# else
- /* Gnulib defined values. */
-# define FP_ILOGB0 (- 2147483647) /* - INT_MAX */
-# define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef acosf
-_GL_FUNCDECL_SYS (acosf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (acosf, float, (float x));
-_GL_CXXALIASWARN (acosf);
-#elif defined GNULIB_POSIXCHECK
-# undef acosf
-# if HAVE_RAW_DECL_ACOSF
-_GL_WARN_ON_USE (acosf, "acosf is unportable - "
- "use gnulib module acosf for portability");
-# endif
-#endif
-
-#if 0
-# if !1 || !1
-# undef acosl
-_GL_FUNCDECL_SYS (acosl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (acosl, long double, (long double x));
-_GL_CXXALIASWARN (acosl);
-#elif defined GNULIB_POSIXCHECK
-# undef acosl
-# if HAVE_RAW_DECL_ACOSL
-_GL_WARN_ON_USE (acosl, "acosl is unportable - "
- "use gnulib module acosl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef asinf
-_GL_FUNCDECL_SYS (asinf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (asinf, float, (float x));
-_GL_CXXALIASWARN (asinf);
-#elif defined GNULIB_POSIXCHECK
-# undef asinf
-# if HAVE_RAW_DECL_ASINF
-_GL_WARN_ON_USE (asinf, "asinf is unportable - "
- "use gnulib module asinf for portability");
-# endif
-#endif
-
-#if 0
-# if !1 || !1
-# undef asinl
-_GL_FUNCDECL_SYS (asinl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (asinl, long double, (long double x));
-_GL_CXXALIASWARN (asinl);
-#elif defined GNULIB_POSIXCHECK
-# undef asinl
-# if HAVE_RAW_DECL_ASINL
-_GL_WARN_ON_USE (asinl, "asinl is unportable - "
- "use gnulib module asinl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef atanf
-_GL_FUNCDECL_SYS (atanf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (atanf, float, (float x));
-_GL_CXXALIASWARN (atanf);
-#elif defined GNULIB_POSIXCHECK
-# undef atanf
-# if HAVE_RAW_DECL_ATANF
-_GL_WARN_ON_USE (atanf, "atanf is unportable - "
- "use gnulib module atanf for portability");
-# endif
-#endif
-
-#if 0
-# if !1 || !1
-# undef atanl
-_GL_FUNCDECL_SYS (atanl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (atanl, long double, (long double x));
-_GL_CXXALIASWARN (atanl);
-#elif defined GNULIB_POSIXCHECK
-# undef atanl
-# if HAVE_RAW_DECL_ATANL
-_GL_WARN_ON_USE (atanl, "atanl is unportable - "
- "use gnulib module atanl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef atan2f
-_GL_FUNCDECL_SYS (atan2f, float, (float y, float x));
-# endif
-_GL_CXXALIAS_SYS (atan2f, float, (float y, float x));
-_GL_CXXALIASWARN (atan2f);
-#elif defined GNULIB_POSIXCHECK
-# undef atan2f
-# if HAVE_RAW_DECL_ATAN2F
-_GL_WARN_ON_USE (atan2f, "atan2f is unportable - "
- "use gnulib module atan2f for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef cbrtf
-# define cbrtf rpl_cbrtf
-# endif
-_GL_FUNCDECL_RPL (cbrtf, float, (float x));
-_GL_CXXALIAS_RPL (cbrtf, float, (float x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (cbrtf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (cbrtf, float, (float x));
-# endif
-_GL_CXXALIASWARN (cbrtf);
-#elif defined GNULIB_POSIXCHECK
-# undef cbrtf
-# if HAVE_RAW_DECL_CBRTF
-_GL_WARN_ON_USE (cbrtf, "cbrtf is unportable - "
- "use gnulib module cbrtf for portability");
-# endif
-#endif
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (cbrt, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (cbrt, double, (double x));
-_GL_CXXALIASWARN (cbrt);
-#elif defined GNULIB_POSIXCHECK
-# undef cbrt
-# if HAVE_RAW_DECL_CBRT
-_GL_WARN_ON_USE (cbrt, "cbrt is unportable - "
- "use gnulib module cbrt for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef cbrtl
-# define cbrtl rpl_cbrtl
-# endif
-_GL_FUNCDECL_RPL (cbrtl, long double, (long double x));
-_GL_CXXALIAS_RPL (cbrtl, long double, (long double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (cbrtl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (cbrtl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (cbrtl);
-#elif defined GNULIB_POSIXCHECK
-# undef cbrtl
-# if HAVE_RAW_DECL_CBRTL
-_GL_WARN_ON_USE (cbrtl, "cbrtl is unportable - "
- "use gnulib module cbrtl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef ceilf
-# define ceilf rpl_ceilf
-# endif
-_GL_FUNCDECL_RPL (ceilf, float, (float x));
-_GL_CXXALIAS_RPL (ceilf, float, (float x));
-# else
-# if !1
-# undef ceilf
-_GL_FUNCDECL_SYS (ceilf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (ceilf, float, (float x));
-# endif
-_GL_CXXALIASWARN (ceilf);
-#elif defined GNULIB_POSIXCHECK
-# undef ceilf
-# if HAVE_RAW_DECL_CEILF
-_GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
- "use gnulib module ceilf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define ceil rpl_ceil
-# endif
-_GL_FUNCDECL_RPL (ceil, double, (double x));
-_GL_CXXALIAS_RPL (ceil, double, (double x));
-# else
-_GL_CXXALIAS_SYS (ceil, double, (double x));
-# endif
-_GL_CXXALIASWARN (ceil);
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef ceill
-# define ceill rpl_ceill
-# endif
-_GL_FUNCDECL_RPL (ceill, long double, (long double x));
-_GL_CXXALIAS_RPL (ceill, long double, (long double x));
-# else
-# if !1
-# undef ceill
-_GL_FUNCDECL_SYS (ceill, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (ceill, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (ceill);
-#elif defined GNULIB_POSIXCHECK
-# undef ceill
-# if HAVE_RAW_DECL_CEILL
-_GL_WARN_ON_USE (ceill, "ceill is unportable - "
- "use gnulib module ceill for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (copysignf, float, (float x, float y));
-# endif
-_GL_CXXALIAS_SYS (copysignf, float, (float x, float y));
-_GL_CXXALIASWARN (copysignf);
-#elif defined GNULIB_POSIXCHECK
-# undef copysignf
-# if HAVE_RAW_DECL_COPYSIGNF
-_GL_WARN_ON_USE (copysignf, "copysignf is unportable - "
- "use gnulib module copysignf for portability");
-# endif
-#endif
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (copysign, double, (double x, double y));
-# endif
-_GL_CXXALIAS_SYS (copysign, double, (double x, double y));
-_GL_CXXALIASWARN (copysign);
-#elif defined GNULIB_POSIXCHECK
-# undef copysign
-# if HAVE_RAW_DECL_COPYSIGN
-_GL_WARN_ON_USE (copysign, "copysign is unportable - "
- "use gnulib module copysign for portability");
-# endif
-#endif
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (copysignl, long double, (long double x, long double y));
-# endif
-_GL_CXXALIAS_SYS (copysignl, long double, (long double x, long double y));
-_GL_CXXALIASWARN (copysignl);
-#elif defined GNULIB_POSIXCHECK
-# undef copysignl
-# if HAVE_RAW_DECL_COPYSIGNL
-_GL_WARN_ON_USE (copysign, "copysignl is unportable - "
- "use gnulib module copysignl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef cosf
-_GL_FUNCDECL_SYS (cosf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (cosf, float, (float x));
-_GL_CXXALIASWARN (cosf);
-#elif defined GNULIB_POSIXCHECK
-# undef cosf
-# if HAVE_RAW_DECL_COSF
-_GL_WARN_ON_USE (cosf, "cosf is unportable - "
- "use gnulib module cosf for portability");
-# endif
-#endif
-
-#if 0
-# if !1 || !1
-# undef cosl
-_GL_FUNCDECL_SYS (cosl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (cosl, long double, (long double x));
-_GL_CXXALIASWARN (cosl);
-#elif defined GNULIB_POSIXCHECK
-# undef cosl
-# if HAVE_RAW_DECL_COSL
-_GL_WARN_ON_USE (cosl, "cosl is unportable - "
- "use gnulib module cosl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef coshf
-_GL_FUNCDECL_SYS (coshf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (coshf, float, (float x));
-_GL_CXXALIASWARN (coshf);
-#elif defined GNULIB_POSIXCHECK
-# undef coshf
-# if HAVE_RAW_DECL_COSHF
-_GL_WARN_ON_USE (coshf, "coshf is unportable - "
- "use gnulib module coshf for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef expf
-_GL_FUNCDECL_SYS (expf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (expf, float, (float x));
-_GL_CXXALIASWARN (expf);
-#elif defined GNULIB_POSIXCHECK
-# undef expf
-# if HAVE_RAW_DECL_EXPF
-_GL_WARN_ON_USE (expf, "expf is unportable - "
- "use gnulib module expf for portability");
-# endif
-#endif
-
-#if 0
-# if !1 || !1
-# undef expl
-_GL_FUNCDECL_SYS (expl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (expl, long double, (long double x));
-_GL_CXXALIASWARN (expl);
-#elif defined GNULIB_POSIXCHECK
-# undef expl
-# if HAVE_RAW_DECL_EXPL
-_GL_WARN_ON_USE (expl, "expl is unportable - "
- "use gnulib module expl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (exp2f, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (exp2f, float, (float x));
-_GL_CXXALIASWARN (exp2f);
-#elif defined GNULIB_POSIXCHECK
-# undef exp2f
-# if HAVE_RAW_DECL_EXP2F
-_GL_WARN_ON_USE (exp2f, "exp2f is unportable - "
- "use gnulib module exp2f for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef exp2
-# define exp2 rpl_exp2
-# endif
-_GL_FUNCDECL_RPL (exp2, double, (double x));
-_GL_CXXALIAS_RPL (exp2, double, (double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (exp2, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (exp2, double, (double x));
-# endif
-_GL_CXXALIASWARN (exp2);
-#elif defined GNULIB_POSIXCHECK
-# undef exp2
-# if HAVE_RAW_DECL_EXP2
-_GL_WARN_ON_USE (exp2, "exp2 is unportable - "
- "use gnulib module exp2 for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef exp2l
-# define exp2l rpl_exp2l
-# endif
-_GL_FUNCDECL_RPL (exp2l, long double, (long double x));
-_GL_CXXALIAS_RPL (exp2l, long double, (long double x));
-# else
-# if !1
-# undef exp2l
-_GL_FUNCDECL_SYS (exp2l, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (exp2l, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (exp2l);
-#elif defined GNULIB_POSIXCHECK
-# undef exp2l
-# if HAVE_RAW_DECL_EXP2L
-_GL_WARN_ON_USE (exp2l, "exp2l is unportable - "
- "use gnulib module exp2l for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef expm1f
-# define expm1f rpl_expm1f
-# endif
-_GL_FUNCDECL_RPL (expm1f, float, (float x));
-_GL_CXXALIAS_RPL (expm1f, float, (float x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (expm1f, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (expm1f, float, (float x));
-# endif
-_GL_CXXALIASWARN (expm1f);
-#elif defined GNULIB_POSIXCHECK
-# undef expm1f
-# if HAVE_RAW_DECL_EXPM1F
-_GL_WARN_ON_USE (expm1f, "expm1f is unportable - "
- "use gnulib module expm1f for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef expm1
-# define expm1 rpl_expm1
-# endif
-_GL_FUNCDECL_RPL (expm1, double, (double x));
-_GL_CXXALIAS_RPL (expm1, double, (double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (expm1, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (expm1, double, (double x));
-# endif
-_GL_CXXALIASWARN (expm1);
-#elif defined GNULIB_POSIXCHECK
-# undef expm1
-# if HAVE_RAW_DECL_EXPM1
-_GL_WARN_ON_USE (expm1, "expm1 is unportable - "
- "use gnulib module expm1 for portability");
-# endif
-#endif
-
-#if 0
-# if !1
-# undef expm1l
-_GL_FUNCDECL_SYS (expm1l, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (expm1l, long double, (long double x));
-_GL_CXXALIASWARN (expm1l);
-#elif defined GNULIB_POSIXCHECK
-# undef expm1l
-# if HAVE_RAW_DECL_EXPM1L
-_GL_WARN_ON_USE (expm1l, "expm1l is unportable - "
- "use gnulib module expm1l for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef fabsf
-_GL_FUNCDECL_SYS (fabsf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (fabsf, float, (float x));
-_GL_CXXALIASWARN (fabsf);
-#elif defined GNULIB_POSIXCHECK
-# undef fabsf
-# if HAVE_RAW_DECL_FABSF
-_GL_WARN_ON_USE (fabsf, "fabsf is unportable - "
- "use gnulib module fabsf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fabsl
-# define fabsl rpl_fabsl
-# endif
-_GL_FUNCDECL_RPL (fabsl, long double, (long double x));
-_GL_CXXALIAS_RPL (fabsl, long double, (long double x));
-# else
-# if !1
-# undef fabsl
-_GL_FUNCDECL_SYS (fabsl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (fabsl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (fabsl);
-#elif defined GNULIB_POSIXCHECK
-# undef fabsl
-# if HAVE_RAW_DECL_FABSL
-_GL_WARN_ON_USE (fabsl, "fabsl is unportable - "
- "use gnulib module fabsl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef floorf
-# define floorf rpl_floorf
-# endif
-_GL_FUNCDECL_RPL (floorf, float, (float x));
-_GL_CXXALIAS_RPL (floorf, float, (float x));
-# else
-# if !1
-# undef floorf
-_GL_FUNCDECL_SYS (floorf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (floorf, float, (float x));
-# endif
-_GL_CXXALIASWARN (floorf);
-#elif defined GNULIB_POSIXCHECK
-# undef floorf
-# if HAVE_RAW_DECL_FLOORF
-_GL_WARN_ON_USE (floorf, "floorf is unportable - "
- "use gnulib module floorf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define floor rpl_floor
-# endif
-_GL_FUNCDECL_RPL (floor, double, (double x));
-_GL_CXXALIAS_RPL (floor, double, (double x));
-# else
-_GL_CXXALIAS_SYS (floor, double, (double x));
-# endif
-_GL_CXXALIASWARN (floor);
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef floorl
-# define floorl rpl_floorl
-# endif
-_GL_FUNCDECL_RPL (floorl, long double, (long double x));
-_GL_CXXALIAS_RPL (floorl, long double, (long double x));
-# else
-# if !1
-# undef floorl
-_GL_FUNCDECL_SYS (floorl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (floorl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (floorl);
-#elif defined GNULIB_POSIXCHECK
-# undef floorl
-# if HAVE_RAW_DECL_FLOORL
-_GL_WARN_ON_USE (floorl, "floorl is unportable - "
- "use gnulib module floorl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fmaf
-# define fmaf rpl_fmaf
-# endif
-_GL_FUNCDECL_RPL (fmaf, float, (float x, float y, float z));
-_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z));
-# else
-# if !1
-_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z));
-# endif
-_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z));
-# endif
-_GL_CXXALIASWARN (fmaf);
-#elif defined GNULIB_POSIXCHECK
-# undef fmaf
-# if HAVE_RAW_DECL_FMAF
-_GL_WARN_ON_USE (fmaf, "fmaf is unportable - "
- "use gnulib module fmaf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fma
-# define fma rpl_fma
-# endif
-_GL_FUNCDECL_RPL (fma, double, (double x, double y, double z));
-_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z));
-# else
-# if !1
-_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z));
-# endif
-_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z));
-# endif
-_GL_CXXALIASWARN (fma);
-#elif defined GNULIB_POSIXCHECK
-# undef fma
-# if HAVE_RAW_DECL_FMA
-_GL_WARN_ON_USE (fma, "fma is unportable - "
- "use gnulib module fma for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fmal
-# define fmal rpl_fmal
-# endif
-_GL_FUNCDECL_RPL (fmal, long double,
- (long double x, long double y, long double z));
-_GL_CXXALIAS_RPL (fmal, long double,
- (long double x, long double y, long double z));
-# else
-# if !1
-# undef fmal
-_GL_FUNCDECL_SYS (fmal, long double,
- (long double x, long double y, long double z));
-# endif
-_GL_CXXALIAS_SYS (fmal, long double,
- (long double x, long double y, long double z));
-# endif
-_GL_CXXALIASWARN (fmal);
-#elif defined GNULIB_POSIXCHECK
-# undef fmal
-# if HAVE_RAW_DECL_FMAL
-_GL_WARN_ON_USE (fmal, "fmal is unportable - "
- "use gnulib module fmal for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fmodf
-# define fmodf rpl_fmodf
-# endif
-_GL_FUNCDECL_RPL (fmodf, float, (float x, float y));
-_GL_CXXALIAS_RPL (fmodf, float, (float x, float y));
-# else
-# if !1
-# undef fmodf
-_GL_FUNCDECL_SYS (fmodf, float, (float x, float y));
-# endif
-_GL_CXXALIAS_SYS (fmodf, float, (float x, float y));
-# endif
-_GL_CXXALIASWARN (fmodf);
-#elif defined GNULIB_POSIXCHECK
-# undef fmodf
-# if HAVE_RAW_DECL_FMODF
-_GL_WARN_ON_USE (fmodf, "fmodf is unportable - "
- "use gnulib module fmodf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fmod
-# define fmod rpl_fmod
-# endif
-_GL_FUNCDECL_RPL (fmod, double, (double x, double y));
-_GL_CXXALIAS_RPL (fmod, double, (double x, double y));
-# else
-_GL_CXXALIAS_SYS (fmod, double, (double x, double y));
-# endif
-_GL_CXXALIASWARN (fmod);
-#elif defined GNULIB_POSIXCHECK
-# undef fmod
-# if HAVE_RAW_DECL_FMOD
-_GL_WARN_ON_USE (fmod, "fmod has portability problems - "
- "use gnulib module fmod for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fmodl
-# define fmodl rpl_fmodl
-# endif
-_GL_FUNCDECL_RPL (fmodl, long double, (long double x, long double y));
-_GL_CXXALIAS_RPL (fmodl, long double, (long double x, long double y));
-# else
-# if !1
-# undef fmodl
-_GL_FUNCDECL_SYS (fmodl, long double, (long double x, long double y));
-# endif
-_GL_CXXALIAS_SYS (fmodl, long double, (long double x, long double y));
-# endif
-_GL_CXXALIASWARN (fmodl);
-#elif defined GNULIB_POSIXCHECK
-# undef fmodl
-# if HAVE_RAW_DECL_FMODL
-_GL_WARN_ON_USE (fmodl, "fmodl is unportable - "
- "use gnulib module fmodl for portability");
-# endif
-#endif
-
-
-/* Write x as
- x = mantissa * 2^exp
- where
- If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
- If x is zero: mantissa = x, exp = 0.
- If x is infinite or NaN: mantissa = x, exp unspecified.
- Store exp in *EXPPTR and return mantissa. */
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef frexpf
-# define frexpf rpl_frexpf
-# endif
-_GL_FUNCDECL_RPL (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (frexpf, float, (float x, int *expptr));
-# else
-# if !1
-# undef frexpf
-_GL_FUNCDECL_SYS (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr));
-# endif
-_GL_CXXALIASWARN (frexpf);
-#elif defined GNULIB_POSIXCHECK
-# undef frexpf
-# if HAVE_RAW_DECL_FREXPF
-_GL_WARN_ON_USE (frexpf, "frexpf is unportable - "
- "use gnulib module frexpf for portability");
-# endif
-#endif
-
-/* Write x as
- x = mantissa * 2^exp
- where
- If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
- If x is zero: mantissa = x, exp = 0.
- If x is infinite or NaN: mantissa = x, exp unspecified.
- Store exp in *EXPPTR and return mantissa. */
-#if 0
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define frexp rpl_frexp
-# endif
-_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
-# else
-_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
-# endif
-_GL_CXXALIASWARN (frexp);
-#elif defined GNULIB_POSIXCHECK
-# undef frexp
-/* Assume frexp is always declared. */
-_GL_WARN_ON_USE (frexp, "frexp is unportable - "
- "use gnulib module frexp for portability");
-#endif
-
-/* Write x as
- x = mantissa * 2^exp
- where
- If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
- If x is zero: mantissa = x, exp = 0.
- If x is infinite or NaN: mantissa = x, exp unspecified.
- Store exp in *EXPPTR and return mantissa. */
-#if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef frexpl
-# define frexpl rpl_frexpl
-# endif
-_GL_FUNCDECL_RPL (frexpl, long double,
- (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr));
-#else
-# if !1
-_GL_FUNCDECL_SYS (frexpl, long double,
- (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
-# endif
-# if 1
-_GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
-# endif
-#endif
-#if 1 && !(1 && !1)
-_GL_CXXALIASWARN (frexpl);
-#endif
-#if !1 && defined GNULIB_POSIXCHECK
-# undef frexpl
-# if HAVE_RAW_DECL_FREXPL
-_GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
- "use gnulib module frexpl for portability");
-# endif
-#endif
-
-
-/* Return sqrt(x^2+y^2). */
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef hypotf
-# define hypotf rpl_hypotf
-# endif
-_GL_FUNCDECL_RPL (hypotf, float, (float x, float y));
-_GL_CXXALIAS_RPL (hypotf, float, (float x, float y));
-# else
-# if !1
-_GL_FUNCDECL_SYS (hypotf, float, (float x, float y));
-# endif
-_GL_CXXALIAS_SYS (hypotf, float, (float x, float y));
-# endif
-_GL_CXXALIASWARN (hypotf);
-#elif defined GNULIB_POSIXCHECK
-# undef hypotf
-# if HAVE_RAW_DECL_HYPOTF
-_GL_WARN_ON_USE (hypotf, "hypotf is unportable - "
- "use gnulib module hypotf for portability");
-# endif
-#endif
-
-/* Return sqrt(x^2+y^2). */
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef hypot
-# define hypot rpl_hypot
-# endif
-_GL_FUNCDECL_RPL (hypot, double, (double x, double y));
-_GL_CXXALIAS_RPL (hypot, double, (double x, double y));
-# else
-_GL_CXXALIAS_SYS (hypot, double, (double x, double y));
-# endif
-_GL_CXXALIASWARN (hypot);
-#elif defined GNULIB_POSIXCHECK
-# undef hypot
-# if HAVE_RAW_DECL_HYPOT
-_GL_WARN_ON_USE (hypotf, "hypot has portability problems - "
- "use gnulib module hypot for portability");
-# endif
-#endif
-
-/* Return sqrt(x^2+y^2). */
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef hypotl
-# define hypotl rpl_hypotl
-# endif
-_GL_FUNCDECL_RPL (hypotl, long double, (long double x, long double y));
-_GL_CXXALIAS_RPL (hypotl, long double, (long double x, long double y));
-# else
-# if !1
-_GL_FUNCDECL_SYS (hypotl, long double, (long double x, long double y));
-# endif
-_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y));
-# endif
-_GL_CXXALIASWARN (hypotl);
-#elif defined GNULIB_POSIXCHECK
-# undef hypotl
-# if HAVE_RAW_DECL_HYPOTL
-_GL_WARN_ON_USE (hypotl, "hypotl is unportable - "
- "use gnulib module hypotl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef ilogbf
-# define ilogbf rpl_ilogbf
-# endif
-_GL_FUNCDECL_RPL (ilogbf, int, (float x));
-_GL_CXXALIAS_RPL (ilogbf, int, (float x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (ilogbf, int, (float x));
-# endif
-_GL_CXXALIAS_SYS (ilogbf, int, (float x));
-# endif
-_GL_CXXALIASWARN (ilogbf);
-#elif defined GNULIB_POSIXCHECK
-# undef ilogbf
-# if HAVE_RAW_DECL_ILOGBF
-_GL_WARN_ON_USE (ilogbf, "ilogbf is unportable - "
- "use gnulib module ilogbf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef ilogb
-# define ilogb rpl_ilogb
-# endif
-_GL_FUNCDECL_RPL (ilogb, int, (double x));
-_GL_CXXALIAS_RPL (ilogb, int, (double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (ilogb, int, (double x));
-# endif
-_GL_CXXALIAS_SYS (ilogb, int, (double x));
-# endif
-_GL_CXXALIASWARN (ilogb);
-#elif defined GNULIB_POSIXCHECK
-# undef ilogb
-# if HAVE_RAW_DECL_ILOGB
-_GL_WARN_ON_USE (ilogb, "ilogb is unportable - "
- "use gnulib module ilogb for portability");
-# endif
-#endif
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (ilogbl, int, (long double x));
-# endif
-_GL_CXXALIAS_SYS (ilogbl, int, (long double x));
-_GL_CXXALIASWARN (ilogbl);
-#elif defined GNULIB_POSIXCHECK
-# undef ilogbl
-# if HAVE_RAW_DECL_ILOGBL
-_GL_WARN_ON_USE (ilogbl, "ilogbl is unportable - "
- "use gnulib module ilogbl for portability");
-# endif
-#endif
-
-
-/* Return x * 2^exp. */
-#if 0
-# if !1
-# undef ldexpf
-_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp));
-# endif
-_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp));
-_GL_CXXALIASWARN (ldexpf);
-#elif defined GNULIB_POSIXCHECK
-# undef ldexpf
-# if HAVE_RAW_DECL_LDEXPF
-_GL_WARN_ON_USE (ldexpf, "ldexpf is unportable - "
- "use gnulib module ldexpf for portability");
-# endif
-#endif
-
-/* Return x * 2^exp. */
-#if 0 && 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef ldexpl
-# define ldexpl rpl_ldexpl
-# endif
-_GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp));
-_GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp));
-#else
-# if !1
-_GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp));
-# endif
-# if 0
-_GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
-# endif
-#endif
-#if 0
-_GL_CXXALIASWARN (ldexpl);
-#endif
-#if !0 && defined GNULIB_POSIXCHECK
-# undef ldexpl
-# if HAVE_RAW_DECL_LDEXPL
-_GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
- "use gnulib module ldexpl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef logf
-# define logf rpl_logf
-# endif
-_GL_FUNCDECL_RPL (logf, float, (float x));
-_GL_CXXALIAS_RPL (logf, float, (float x));
-# else
-# if !1
-# undef logf
-_GL_FUNCDECL_SYS (logf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (logf, float, (float x));
-# endif
-_GL_CXXALIASWARN (logf);
-#elif defined GNULIB_POSIXCHECK
-# undef logf
-# if HAVE_RAW_DECL_LOGF
-_GL_WARN_ON_USE (logf, "logf is unportable - "
- "use gnulib module logf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log
-# define log rpl_log
-# endif
-_GL_FUNCDECL_RPL (log, double, (double x));
-_GL_CXXALIAS_RPL (log, double, (double x));
-# else
-_GL_CXXALIAS_SYS (log, double, (double x));
-# endif
-_GL_CXXALIASWARN (log);
-#elif defined GNULIB_POSIXCHECK
-# undef log
-# if HAVE_RAW_DECL_LOG
-_GL_WARN_ON_USE (log, "log has portability problems - "
- "use gnulib module log for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef logl
-# define logl rpl_logl
-# endif
-_GL_FUNCDECL_RPL (logl, long double, (long double x));
-_GL_CXXALIAS_RPL (logl, long double, (long double x));
-# else
-# if !1 || !1
-# undef logl
-_GL_FUNCDECL_SYS (logl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (logl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (logl);
-#elif defined GNULIB_POSIXCHECK
-# undef logl
-# if HAVE_RAW_DECL_LOGL
-_GL_WARN_ON_USE (logl, "logl is unportable - "
- "use gnulib module logl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log10f
-# define log10f rpl_log10f
-# endif
-_GL_FUNCDECL_RPL (log10f, float, (float x));
-_GL_CXXALIAS_RPL (log10f, float, (float x));
-# else
-# if !1
-# undef log10f
-_GL_FUNCDECL_SYS (log10f, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (log10f, float, (float x));
-# endif
-_GL_CXXALIASWARN (log10f);
-#elif defined GNULIB_POSIXCHECK
-# undef log10f
-# if HAVE_RAW_DECL_LOG10F
-_GL_WARN_ON_USE (log10f, "log10f is unportable - "
- "use gnulib module log10f for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log10
-# define log10 rpl_log10
-# endif
-_GL_FUNCDECL_RPL (log10, double, (double x));
-_GL_CXXALIAS_RPL (log10, double, (double x));
-# else
-_GL_CXXALIAS_SYS (log10, double, (double x));
-# endif
-_GL_CXXALIASWARN (log10);
-#elif defined GNULIB_POSIXCHECK
-# undef log10
-# if HAVE_RAW_DECL_LOG10
-_GL_WARN_ON_USE (log10, "log10 has portability problems - "
- "use gnulib module log10 for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log10l
-# define log10l rpl_log10l
-# endif
-_GL_FUNCDECL_RPL (log10l, long double, (long double x));
-_GL_CXXALIAS_RPL (log10l, long double, (long double x));
-# else
-# if !1 || !1
-# undef log10l
-_GL_FUNCDECL_SYS (log10l, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (log10l, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (log10l);
-#elif defined GNULIB_POSIXCHECK
-# undef log10l
-# if HAVE_RAW_DECL_LOG10L
-_GL_WARN_ON_USE (log10l, "log10l is unportable - "
- "use gnulib module log10l for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log1pf
-# define log1pf rpl_log1pf
-# endif
-_GL_FUNCDECL_RPL (log1pf, float, (float x));
-_GL_CXXALIAS_RPL (log1pf, float, (float x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (log1pf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (log1pf, float, (float x));
-# endif
-_GL_CXXALIASWARN (log1pf);
-#elif defined GNULIB_POSIXCHECK
-# undef log1pf
-# if HAVE_RAW_DECL_LOG1PF
-_GL_WARN_ON_USE (log1pf, "log1pf is unportable - "
- "use gnulib module log1pf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log1p
-# define log1p rpl_log1p
-# endif
-_GL_FUNCDECL_RPL (log1p, double, (double x));
-_GL_CXXALIAS_RPL (log1p, double, (double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (log1p, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (log1p, double, (double x));
-# endif
-_GL_CXXALIASWARN (log1p);
-#elif defined GNULIB_POSIXCHECK
-# undef log1p
-# if HAVE_RAW_DECL_LOG1P
-_GL_WARN_ON_USE (log1p, "log1p has portability problems - "
- "use gnulib module log1p for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log1pl
-# define log1pl rpl_log1pl
-# endif
-_GL_FUNCDECL_RPL (log1pl, long double, (long double x));
-_GL_CXXALIAS_RPL (log1pl, long double, (long double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (log1pl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (log1pl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (log1pl);
-#elif defined GNULIB_POSIXCHECK
-# undef log1pl
-# if HAVE_RAW_DECL_LOG1PL
-_GL_WARN_ON_USE (log1pl, "log1pl has portability problems - "
- "use gnulib module log1pl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log2f
-# define log2f rpl_log2f
-# endif
-_GL_FUNCDECL_RPL (log2f, float, (float x));
-_GL_CXXALIAS_RPL (log2f, float, (float x));
-# else
-# if !1
-# undef log2f
-_GL_FUNCDECL_SYS (log2f, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (log2f, float, (float x));
-# endif
-_GL_CXXALIASWARN (log2f);
-#elif defined GNULIB_POSIXCHECK
-# undef log2f
-# if HAVE_RAW_DECL_LOG2F
-_GL_WARN_ON_USE (log2f, "log2f is unportable - "
- "use gnulib module log2f for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log2
-# define log2 rpl_log2
-# endif
-_GL_FUNCDECL_RPL (log2, double, (double x));
-_GL_CXXALIAS_RPL (log2, double, (double x));
-# else
-# if !1
-# undef log2
-_GL_FUNCDECL_SYS (log2, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (log2, double, (double x));
-# endif
-_GL_CXXALIASWARN (log2);
-#elif defined GNULIB_POSIXCHECK
-# undef log2
-# if HAVE_RAW_DECL_LOG2
-_GL_WARN_ON_USE (log2, "log2 is unportable - "
- "use gnulib module log2 for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef log2l
-# define log2l rpl_log2l
-# endif
-_GL_FUNCDECL_RPL (log2l, long double, (long double x));
-_GL_CXXALIAS_RPL (log2l, long double, (long double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (log2l, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (log2l, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (log2l);
-#elif defined GNULIB_POSIXCHECK
-# undef log2l
-# if HAVE_RAW_DECL_LOG2L
-_GL_WARN_ON_USE (log2l, "log2l is unportable - "
- "use gnulib module log2l for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef logbf
-# define logbf rpl_logbf
-# endif
-_GL_FUNCDECL_RPL (logbf, float, (float x));
-_GL_CXXALIAS_RPL (logbf, float, (float x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (logbf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (logbf, float, (float x));
-# endif
-_GL_CXXALIASWARN (logbf);
-#elif defined GNULIB_POSIXCHECK
-# undef logbf
-# if HAVE_RAW_DECL_LOGBF
-_GL_WARN_ON_USE (logbf, "logbf is unportable - "
- "use gnulib module logbf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef logb
-# define logb rpl_logb
-# endif
-_GL_FUNCDECL_RPL (logb, double, (double x));
-_GL_CXXALIAS_RPL (logb, double, (double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (logb, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (logb, double, (double x));
-# endif
-_GL_CXXALIASWARN (logb);
-#elif defined GNULIB_POSIXCHECK
-# undef logb
-# if HAVE_RAW_DECL_LOGB
-_GL_WARN_ON_USE (logb, "logb is unportable - "
- "use gnulib module logb for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef logbl
-# define logbl rpl_logbl
-# endif
-_GL_FUNCDECL_RPL (logbl, long double, (long double x));
-_GL_CXXALIAS_RPL (logbl, long double, (long double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (logbl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (logbl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (logbl);
-#elif defined GNULIB_POSIXCHECK
-# undef logbl
-# if HAVE_RAW_DECL_LOGBL
-_GL_WARN_ON_USE (logbl, "logbl is unportable - "
- "use gnulib module logbl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef modff
-# define modff rpl_modff
-# endif
-_GL_FUNCDECL_RPL (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (modff, float, (float x, float *iptr));
-# else
-# if !1
-# undef modff
-_GL_FUNCDECL_SYS (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (modff, float, (float x, float *iptr));
-# endif
-_GL_CXXALIASWARN (modff);
-#elif defined GNULIB_POSIXCHECK
-# undef modff
-# if HAVE_RAW_DECL_MODFF
-_GL_WARN_ON_USE (modff, "modff is unportable - "
- "use gnulib module modff for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef modf
-# define modf rpl_modf
-# endif
-_GL_FUNCDECL_RPL (modf, double, (double x, double *iptr) _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (modf, double, (double x, double *iptr));
-# else
-_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr));
-# endif
-_GL_CXXALIASWARN (modf);
-#elif defined GNULIB_POSIXCHECK
-# undef modf
-# if HAVE_RAW_DECL_MODF
-_GL_WARN_ON_USE (modf, "modf has portability problems - "
- "use gnulib module modf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef modfl
-# define modfl rpl_modfl
-# endif
-_GL_FUNCDECL_RPL (modfl, long double, (long double x, long double *iptr)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (modfl, long double, (long double x, long double *iptr));
-# else
-# if !1
-# undef modfl
-_GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
-# endif
-_GL_CXXALIASWARN (modfl);
-#elif defined GNULIB_POSIXCHECK
-# undef modfl
-# if HAVE_RAW_DECL_MODFL
-_GL_WARN_ON_USE (modfl, "modfl is unportable - "
- "use gnulib module modfl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef powf
-_GL_FUNCDECL_SYS (powf, float, (float x, float y));
-# endif
-_GL_CXXALIAS_SYS (powf, float, (float x, float y));
-_GL_CXXALIASWARN (powf);
-#elif defined GNULIB_POSIXCHECK
-# undef powf
-# if HAVE_RAW_DECL_POWF
-_GL_WARN_ON_USE (powf, "powf is unportable - "
- "use gnulib module powf for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef remainderf
-# define remainderf rpl_remainderf
-# endif
-_GL_FUNCDECL_RPL (remainderf, float, (float x, float y));
-_GL_CXXALIAS_RPL (remainderf, float, (float x, float y));
-# else
-# if !1
-_GL_FUNCDECL_SYS (remainderf, float, (float x, float y));
-# endif
-_GL_CXXALIAS_SYS (remainderf, float, (float x, float y));
-# endif
-_GL_CXXALIASWARN (remainderf);
-#elif defined GNULIB_POSIXCHECK
-# undef remainderf
-# if HAVE_RAW_DECL_REMAINDERF
-_GL_WARN_ON_USE (remainderf, "remainderf is unportable - "
- "use gnulib module remainderf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef remainder
-# define remainder rpl_remainder
-# endif
-_GL_FUNCDECL_RPL (remainder, double, (double x, double y));
-_GL_CXXALIAS_RPL (remainder, double, (double x, double y));
-# else
-# if !1 || !1
-_GL_FUNCDECL_SYS (remainder, double, (double x, double y));
-# endif
-_GL_CXXALIAS_SYS (remainder, double, (double x, double y));
-# endif
-_GL_CXXALIASWARN (remainder);
-#elif defined GNULIB_POSIXCHECK
-# undef remainder
-# if HAVE_RAW_DECL_REMAINDER
-_GL_WARN_ON_USE (remainder, "remainder is unportable - "
- "use gnulib module remainder for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef remainderl
-# define remainderl rpl_remainderl
-# endif
-_GL_FUNCDECL_RPL (remainderl, long double, (long double x, long double y));
-_GL_CXXALIAS_RPL (remainderl, long double, (long double x, long double y));
-# else
-# if !1
-# undef remainderl
-_GL_FUNCDECL_SYS (remainderl, long double, (long double x, long double y));
-# endif
-_GL_CXXALIAS_SYS (remainderl, long double, (long double x, long double y));
-# endif
-_GL_CXXALIASWARN (remainderl);
-#elif defined GNULIB_POSIXCHECK
-# undef remainderl
-# if HAVE_RAW_DECL_REMAINDERL
-_GL_WARN_ON_USE (remainderl, "remainderl is unportable - "
- "use gnulib module remainderl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (rintf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (rintf, float, (float x));
-_GL_CXXALIASWARN (rintf);
-#elif defined GNULIB_POSIXCHECK
-# undef rintf
-# if HAVE_RAW_DECL_RINTF
-_GL_WARN_ON_USE (rintf, "rintf is unportable - "
- "use gnulib module rintf for portability");
-# endif
-#endif
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (rint, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (rint, double, (double x));
-_GL_CXXALIASWARN (rint);
-#elif defined GNULIB_POSIXCHECK
-# undef rint
-# if HAVE_RAW_DECL_RINT
-_GL_WARN_ON_USE (rint, "rint is unportable - "
- "use gnulib module rint for portability");
-# endif
-#endif
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (rintl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (rintl, long double, (long double x));
-_GL_CXXALIASWARN (rintl);
-#elif defined GNULIB_POSIXCHECK
-# undef rintl
-# if HAVE_RAW_DECL_RINTL
-_GL_WARN_ON_USE (rintl, "rintl is unportable - "
- "use gnulib module rintl for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef roundf
-# define roundf rpl_roundf
-# endif
-_GL_FUNCDECL_RPL (roundf, float, (float x));
-_GL_CXXALIAS_RPL (roundf, float, (float x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (roundf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (roundf, float, (float x));
-# endif
-_GL_CXXALIASWARN (roundf);
-#elif defined GNULIB_POSIXCHECK
-# undef roundf
-# if HAVE_RAW_DECL_ROUNDF
-_GL_WARN_ON_USE (roundf, "roundf is unportable - "
- "use gnulib module roundf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef round
-# define round rpl_round
-# endif
-_GL_FUNCDECL_RPL (round, double, (double x));
-_GL_CXXALIAS_RPL (round, double, (double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (round, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (round, double, (double x));
-# endif
-_GL_CXXALIASWARN (round);
-#elif defined GNULIB_POSIXCHECK
-# undef round
-# if HAVE_RAW_DECL_ROUND
-_GL_WARN_ON_USE (round, "round is unportable - "
- "use gnulib module round for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef roundl
-# define roundl rpl_roundl
-# endif
-_GL_FUNCDECL_RPL (roundl, long double, (long double x));
-_GL_CXXALIAS_RPL (roundl, long double, (long double x));
-# else
-# if !1
-# undef roundl
-_GL_FUNCDECL_SYS (roundl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (roundl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (roundl);
-#elif defined GNULIB_POSIXCHECK
-# undef roundl
-# if HAVE_RAW_DECL_ROUNDL
-_GL_WARN_ON_USE (roundl, "roundl is unportable - "
- "use gnulib module roundl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef sinf
-_GL_FUNCDECL_SYS (sinf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (sinf, float, (float x));
-_GL_CXXALIASWARN (sinf);
-#elif defined GNULIB_POSIXCHECK
-# undef sinf
-# if HAVE_RAW_DECL_SINF
-_GL_WARN_ON_USE (sinf, "sinf is unportable - "
- "use gnulib module sinf for portability");
-# endif
-#endif
-
-#if 0
-# if !1 || !1
-# undef sinl
-_GL_FUNCDECL_SYS (sinl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (sinl, long double, (long double x));
-_GL_CXXALIASWARN (sinl);
-#elif defined GNULIB_POSIXCHECK
-# undef sinl
-# if HAVE_RAW_DECL_SINL
-_GL_WARN_ON_USE (sinl, "sinl is unportable - "
- "use gnulib module sinl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef sinhf
-_GL_FUNCDECL_SYS (sinhf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (sinhf, float, (float x));
-_GL_CXXALIASWARN (sinhf);
-#elif defined GNULIB_POSIXCHECK
-# undef sinhf
-# if HAVE_RAW_DECL_SINHF
-_GL_WARN_ON_USE (sinhf, "sinhf is unportable - "
- "use gnulib module sinhf for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef sqrtf
-_GL_FUNCDECL_SYS (sqrtf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (sqrtf, float, (float x));
-_GL_CXXALIASWARN (sqrtf);
-#elif defined GNULIB_POSIXCHECK
-# undef sqrtf
-# if HAVE_RAW_DECL_SQRTF
-_GL_WARN_ON_USE (sqrtf, "sqrtf is unportable - "
- "use gnulib module sqrtf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef sqrtl
-# define sqrtl rpl_sqrtl
-# endif
-_GL_FUNCDECL_RPL (sqrtl, long double, (long double x));
-_GL_CXXALIAS_RPL (sqrtl, long double, (long double x));
-# else
-# if !1 || !1
-# undef sqrtl
-_GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (sqrtl);
-#elif defined GNULIB_POSIXCHECK
-# undef sqrtl
-# if HAVE_RAW_DECL_SQRTL
-_GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
- "use gnulib module sqrtl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef tanf
-_GL_FUNCDECL_SYS (tanf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (tanf, float, (float x));
-_GL_CXXALIASWARN (tanf);
-#elif defined GNULIB_POSIXCHECK
-# undef tanf
-# if HAVE_RAW_DECL_TANF
-_GL_WARN_ON_USE (tanf, "tanf is unportable - "
- "use gnulib module tanf for portability");
-# endif
-#endif
-
-#if 0
-# if !1 || !1
-# undef tanl
-_GL_FUNCDECL_SYS (tanl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (tanl, long double, (long double x));
-_GL_CXXALIASWARN (tanl);
-#elif defined GNULIB_POSIXCHECK
-# undef tanl
-# if HAVE_RAW_DECL_TANL
-_GL_WARN_ON_USE (tanl, "tanl is unportable - "
- "use gnulib module tanl for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-# undef tanhf
-_GL_FUNCDECL_SYS (tanhf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (tanhf, float, (float x));
-_GL_CXXALIASWARN (tanhf);
-#elif defined GNULIB_POSIXCHECK
-# undef tanhf
-# if HAVE_RAW_DECL_TANHF
-_GL_WARN_ON_USE (tanhf, "tanhf is unportable - "
- "use gnulib module tanhf for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define truncf rpl_truncf
-# endif
-_GL_FUNCDECL_RPL (truncf, float, (float x));
-_GL_CXXALIAS_RPL (truncf, float, (float x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (truncf, float, (float x));
-# endif
-_GL_CXXALIAS_SYS (truncf, float, (float x));
-# endif
-_GL_CXXALIASWARN (truncf);
-#elif defined GNULIB_POSIXCHECK
-# undef truncf
-# if HAVE_RAW_DECL_TRUNCF
-_GL_WARN_ON_USE (truncf, "truncf is unportable - "
- "use gnulib module truncf for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define trunc rpl_trunc
-# endif
-_GL_FUNCDECL_RPL (trunc, double, (double x));
-_GL_CXXALIAS_RPL (trunc, double, (double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (trunc, double, (double x));
-# endif
-_GL_CXXALIAS_SYS (trunc, double, (double x));
-# endif
-_GL_CXXALIASWARN (trunc);
-#elif defined GNULIB_POSIXCHECK
-# undef trunc
-# if HAVE_RAW_DECL_TRUNC
-_GL_WARN_ON_USE (trunc, "trunc is unportable - "
- "use gnulib module trunc for portability");
-# endif
-#endif
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef truncl
-# define truncl rpl_truncl
-# endif
-_GL_FUNCDECL_RPL (truncl, long double, (long double x));
-_GL_CXXALIAS_RPL (truncl, long double, (long double x));
-# else
-# if !1
-_GL_FUNCDECL_SYS (truncl, long double, (long double x));
-# endif
-_GL_CXXALIAS_SYS (truncl, long double, (long double x));
-# endif
-_GL_CXXALIASWARN (truncl);
-#elif defined GNULIB_POSIXCHECK
-# undef truncl
-# if HAVE_RAW_DECL_TRUNCL
-_GL_WARN_ON_USE (truncl, "truncl is unportable - "
- "use gnulib module truncl for portability");
-# endif
-#endif
-
-
-/* Definitions of function-like macros come here, after the function
- declarations. */
-
-
-#if 0
-# if 0
-_GL_EXTERN_C int gl_isfinitef (float x);
-_GL_EXTERN_C int gl_isfinited (double x);
-_GL_EXTERN_C int gl_isfinitel (long double x);
-# undef isfinite
-# define isfinite(x) \
- (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
- sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
- gl_isfinitef (x))
-# endif
-# ifdef __cplusplus
-# ifdef isfinite
-_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isfinite)
-# undef isfinite
-_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite)
-# endif
-# endif
-#elif defined GNULIB_POSIXCHECK
-# if defined isfinite
-_GL_WARN_REAL_FLOATING_DECL (isfinite);
-# undef isfinite
-# define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x)
-# endif
-#endif
-
-
-#if 0
-# if 0
-_GL_EXTERN_C int gl_isinff (float x);
-_GL_EXTERN_C int gl_isinfd (double x);
-_GL_EXTERN_C int gl_isinfl (long double x);
-# undef isinf
-# define isinf(x) \
- (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
- sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
- gl_isinff (x))
-# endif
-# ifdef __cplusplus
-# ifdef isinf
-_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isinf)
-# undef isinf
-_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf)
-# endif
-# endif
-#elif defined GNULIB_POSIXCHECK
-# if defined isinf
-_GL_WARN_REAL_FLOATING_DECL (isinf);
-# undef isinf
-# define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x)
-# endif
-#endif
-
-
-#if 0
-/* Test for NaN for 'float' numbers. */
-# if 1
-/* The original <math.h> included above provides a declaration of isnan macro
- or (older) isnanf function. */
-# if __GNUC__ >= 4
- /* GCC 4.0 and newer provides three built-ins for isnan. */
-# undef isnanf
-# define isnanf(x) __builtin_isnanf ((float)(x))
-# elif defined isnan
-# undef isnanf
-# define isnanf(x) isnan ((float)(x))
-# endif
-# else
-/* Test whether X is a NaN. */
-# undef isnanf
-# define isnanf rpl_isnanf
-_GL_EXTERN_C int isnanf (float x);
-# endif
-#endif
-
-#if 0
-/* Test for NaN for 'double' numbers.
- This function is a gnulib extension, unlike isnan() which applied only
- to 'double' numbers earlier but now is a type-generic macro. */
-# if 1
-/* The original <math.h> included above provides a declaration of isnan
- macro. */
-# if __GNUC__ >= 4
- /* GCC 4.0 and newer provides three built-ins for isnan. */
-# undef isnand
-# define isnand(x) __builtin_isnan ((double)(x))
-# else
-# undef isnand
-# define isnand(x) isnan ((double)(x))
-# endif
-# else
-/* Test whether X is a NaN. */
-# undef isnand
-# define isnand rpl_isnand
-_GL_EXTERN_C int isnand (double x);
-# endif
-#endif
-
-#if 0
-/* Test for NaN for 'long double' numbers. */
-# if 1
-/* The original <math.h> included above provides a declaration of isnan
- macro or (older) isnanl function. */
-# if __GNUC__ >= 4
- /* GCC 4.0 and newer provides three built-ins for isnan. */
-# undef isnanl
-# define isnanl(x) __builtin_isnanl ((long double)(x))
-# elif defined isnan
-# undef isnanl
-# define isnanl(x) isnan ((long double)(x))
-# endif
-# else
-/* Test whether X is a NaN. */
-# undef isnanl
-# define isnanl rpl_isnanl
-_GL_EXTERN_C int isnanl (long double x) _GL_ATTRIBUTE_CONST;
-# endif
-#endif
-
-/* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL! */
-#if 0
-# if 0
-/* We can't just use the isnanf macro (e.g.) as exposed by
- isnanf.h (e.g.) here, because those may end up being macros
- that recursively expand back to isnan. So use the gnulib
- replacements for them directly. */
-# if 1 && __GNUC__ >= 4
-# define gl_isnan_f(x) __builtin_isnanf ((float)(x))
-# else
-_GL_EXTERN_C int rpl_isnanf (float x);
-# define gl_isnan_f(x) rpl_isnanf (x)
-# endif
-# if 1 && __GNUC__ >= 4
-# define gl_isnan_d(x) __builtin_isnan ((double)(x))
-# else
-_GL_EXTERN_C int rpl_isnand (double x);
-# define gl_isnan_d(x) rpl_isnand (x)
-# endif
-# if 1 && __GNUC__ >= 4
-# define gl_isnan_l(x) __builtin_isnanl ((long double)(x))
-# else
-_GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
-# define gl_isnan_l(x) rpl_isnanl (x)
-# endif
-# undef isnan
-# define isnan(x) \
- (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
- sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
- gl_isnan_f (x))
-# elif __GNUC__ >= 4
-# undef isnan
-# define isnan(x) \
- (sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \
- sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \
- __builtin_isnanf ((float)(x)))
-# endif
-# ifdef __cplusplus
-# ifdef isnan
-_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan)
-# undef isnan
-_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan)
-# endif
-# else
-/* Ensure isnan is a macro. */
-# ifndef isnan
-# define isnan isnan
-# endif
-# endif
-#elif defined GNULIB_POSIXCHECK
-# if defined isnan
-_GL_WARN_REAL_FLOATING_DECL (isnan);
-# undef isnan
-# define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x)
-# endif
-#endif
-
-
-#if 1
-# if 0
-# undef signbit
- /* GCC 4.0 and newer provides three built-ins for signbit. */
-# define signbit(x) \
- (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
- sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
- __builtin_signbitf (x))
-# endif
-# if 1
-# undef signbit
-_GL_EXTERN_C int gl_signbitf (float arg);
-_GL_EXTERN_C int gl_signbitd (double arg);
-_GL_EXTERN_C int gl_signbitl (long double arg);
-# if __GNUC__ >= 2 && !defined __STRICT_ANSI__
-# define _GL_NUM_UINT_WORDS(type) \
- ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
-# define gl_signbitf_OPTIMIZED_MACRO
-# define gl_signbitf(arg) \
- ({ union { float _value; \
- unsigned int _word[_GL_NUM_UINT_WORDS (float)]; \
- } _m; \
- _m._value = (arg); \
- (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
- })
-# endif
-# if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
-# define gl_signbitd_OPTIMIZED_MACRO
-# define gl_signbitd(arg) \
- ({ union { double _value; \
- unsigned int _word[_GL_NUM_UINT_WORDS (double)]; \
- } _m; \
- _m._value = (arg); \
- (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
- })
-# endif
-# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
-# define gl_signbitl_OPTIMIZED_MACRO
-# define gl_signbitl(arg) \
- ({ union { long double _value; \
- unsigned int _word[_GL_NUM_UINT_WORDS (long double)]; \
- } _m; \
- _m._value = (arg); \
- (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
- })
-# endif
-# endif
-# define signbit(x) \
- (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
- sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
- gl_signbitf (x))
-# endif
-# ifdef __cplusplus
-# ifdef signbit
-_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
-# undef signbit
-_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit)
-# endif
-# endif
-#elif defined GNULIB_POSIXCHECK
-# if defined signbit
-_GL_WARN_REAL_FLOATING_DECL (signbit);
-# undef signbit
-# define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x)
-# endif
-#endif
-
-_GL_INLINE_HEADER_END
-
-#endif
-
-#endif /* _GL_M4_MATH_H */
-#endif /* _GL_M4_MATH_H */
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef _GL_MATH_INLINE
+# define _GL_MATH_INLINE _GL_INLINE
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+#ifdef __cplusplus
+/* Helper macros to define type-generic function FUNC as overloaded functions,
+ rather than as macros like in C. POSIX declares these with an argument of
+ real-floating (that is, one of float, double, or long double). */
+# define _GL_MATH_CXX_REAL_FLOATING_DECL_1(func) \
+static inline int \
+_gl_cxx_ ## func ## f (float f) \
+{ \
+ return func (f); \
+} \
+static inline int \
+_gl_cxx_ ## func ## d (double d) \
+{ \
+ return func (d); \
+} \
+static inline int \
+_gl_cxx_ ## func ## l (long double l) \
+{ \
+ return func (l); \
+}
+# define _GL_MATH_CXX_REAL_FLOATING_DECL_2(func) \
+inline int \
+func (float f) \
+{ \
+ return _gl_cxx_ ## func ## f (f); \
+} \
+inline int \
+func (double d) \
+{ \
+ return _gl_cxx_ ## func ## d (d); \
+} \
+inline int \
+func (long double l) \
+{ \
+ return _gl_cxx_ ## func ## l (l); \
+}
+#endif
+
+/* Helper macros to define a portability warning for the
+ classification macro FUNC called with VALUE. POSIX declares the
+ classification macros with an argument of real-floating (that is,
+ one of float, double, or long double). */
+#define _GL_WARN_REAL_FLOATING_DECL(func) \
+_GL_MATH_INLINE int \
+rpl_ ## func ## f (float f) \
+{ \
+ return func (f); \
+} \
+_GL_MATH_INLINE int \
+rpl_ ## func ## d (double d) \
+{ \
+ return func (d); \
+} \
+_GL_MATH_INLINE int \
+rpl_ ## func ## l (long double l) \
+{ \
+ return func (l); \
+} \
+_GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \
+ "use gnulib module " #func " for portability"); \
+_GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \
+ "use gnulib module " #func " for portability"); \
+_GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \
+ "use gnulib module " #func " for portability")
+#define _GL_WARN_REAL_FLOATING_IMPL(func, value) \
+ (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \
+ : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \
+ : rpl_ ## func ## l (value))
+
+
+#if 0
+/* Pull in a function that fixes the 'int' to 'long double' conversion
+ of glibc 2.7. */
+_GL_EXTERN_C void _Qp_itoq (long double *, int);
+static void (*_gl_math_fix_itold) (long double *, int) = _Qp_itoq;
+#endif
+
+
+/* POSIX allows platforms that don't support NAN. But all major
+ machines in the past 15 years have supported something close to
+ IEEE NaN, so we define this unconditionally. We also must define
+ it on platforms like Solaris 10, where NAN is present but defined
+ as a function pointer rather than a floating point constant. */
+#if !defined NAN || 0
+# if !GNULIB_defined_NAN
+# undef NAN
+ /* The Compaq (ex-DEC) C 6.4 compiler and the Microsoft MSVC 9 compiler
+ choke on the expression 0.0 / 0.0. */
+# if defined __DECC || defined _MSC_VER
+_GL_MATH_INLINE float
+_NaN ()
+{
+ static float zero = 0.0f;
+ return zero / zero;
+}
+# define NAN (_NaN())
+# else
+# define NAN (0.0f / 0.0f)
+# endif
+# define GNULIB_defined_NAN 1
+# endif
+#endif
+
+/* Solaris 10 defines HUGE_VAL, but as a function pointer rather
+ than a floating point constant. */
+#if 0
+# undef HUGE_VALF
+# define HUGE_VALF (1.0f / 0.0f)
+# undef HUGE_VAL
+# define HUGE_VAL (1.0 / 0.0)
+# undef HUGE_VALL
+# define HUGE_VALL (1.0L / 0.0L)
+#endif
+
+/* HUGE_VALF is a 'float' Infinity. */
+#ifndef HUGE_VALF
+# if defined _MSC_VER
+/* The Microsoft MSVC 9 compiler chokes on the expression 1.0f / 0.0f. */
+# define HUGE_VALF (1e25f * 1e25f)
+# else
+# define HUGE_VALF (1.0f / 0.0f)
+# endif
+#endif
+
+/* HUGE_VAL is a 'double' Infinity. */
+#ifndef HUGE_VAL
+# if defined _MSC_VER
+/* The Microsoft MSVC 9 compiler chokes on the expression 1.0 / 0.0. */
+# define HUGE_VAL (1e250 * 1e250)
+# else
+# define HUGE_VAL (1.0 / 0.0)
+# endif
+#endif
+
+/* HUGE_VALL is a 'long double' Infinity. */
+#ifndef HUGE_VALL
+# if defined _MSC_VER
+/* The Microsoft MSVC 9 compiler chokes on the expression 1.0L / 0.0L. */
+# define HUGE_VALL (1e250L * 1e250L)
+# else
+# define HUGE_VALL (1.0L / 0.0L)
+# endif
+#endif
+
+
+/* Ensure FP_ILOGB0 and FP_ILOGBNAN are defined. */
+#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN)
+# if defined __NetBSD__ || defined __sgi
+ /* NetBSD, IRIX 6.5: match what ilogb() does */
+# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
+# define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
+# elif defined _AIX
+ /* AIX 5.1: match what ilogb() does in AIX >= 5.2 */
+# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */
+# define FP_ILOGBNAN 2147483647 /* INT_MAX */
+# elif defined __sun
+ /* Solaris 9: match what ilogb() does */
+# define FP_ILOGB0 (- 2147483647) /* - INT_MAX */
+# define FP_ILOGBNAN 2147483647 /* INT_MAX */
+# else
+ /* Gnulib defined values. */
+# define FP_ILOGB0 (- 2147483647) /* - INT_MAX */
+# define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef acosf
+_GL_FUNCDECL_SYS (acosf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (acosf, float, (float x));
+_GL_CXXALIASWARN (acosf);
+#elif defined GNULIB_POSIXCHECK
+# undef acosf
+# if HAVE_RAW_DECL_ACOSF
+_GL_WARN_ON_USE (acosf, "acosf is unportable - "
+ "use gnulib module acosf for portability");
+# endif
+#endif
+
+#if 0
+# if !1 || !1
+# undef acosl
+_GL_FUNCDECL_SYS (acosl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (acosl, long double, (long double x));
+_GL_CXXALIASWARN (acosl);
+#elif defined GNULIB_POSIXCHECK
+# undef acosl
+# if HAVE_RAW_DECL_ACOSL
+_GL_WARN_ON_USE (acosl, "acosl is unportable - "
+ "use gnulib module acosl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef asinf
+_GL_FUNCDECL_SYS (asinf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (asinf, float, (float x));
+_GL_CXXALIASWARN (asinf);
+#elif defined GNULIB_POSIXCHECK
+# undef asinf
+# if HAVE_RAW_DECL_ASINF
+_GL_WARN_ON_USE (asinf, "asinf is unportable - "
+ "use gnulib module asinf for portability");
+# endif
+#endif
+
+#if 0
+# if !1 || !1
+# undef asinl
+_GL_FUNCDECL_SYS (asinl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (asinl, long double, (long double x));
+_GL_CXXALIASWARN (asinl);
+#elif defined GNULIB_POSIXCHECK
+# undef asinl
+# if HAVE_RAW_DECL_ASINL
+_GL_WARN_ON_USE (asinl, "asinl is unportable - "
+ "use gnulib module asinl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef atanf
+_GL_FUNCDECL_SYS (atanf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (atanf, float, (float x));
+_GL_CXXALIASWARN (atanf);
+#elif defined GNULIB_POSIXCHECK
+# undef atanf
+# if HAVE_RAW_DECL_ATANF
+_GL_WARN_ON_USE (atanf, "atanf is unportable - "
+ "use gnulib module atanf for portability");
+# endif
+#endif
+
+#if 0
+# if !1 || !1
+# undef atanl
+_GL_FUNCDECL_SYS (atanl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (atanl, long double, (long double x));
+_GL_CXXALIASWARN (atanl);
+#elif defined GNULIB_POSIXCHECK
+# undef atanl
+# if HAVE_RAW_DECL_ATANL
+_GL_WARN_ON_USE (atanl, "atanl is unportable - "
+ "use gnulib module atanl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef atan2f
+_GL_FUNCDECL_SYS (atan2f, float, (float y, float x));
+# endif
+_GL_CXXALIAS_SYS (atan2f, float, (float y, float x));
+_GL_CXXALIASWARN (atan2f);
+#elif defined GNULIB_POSIXCHECK
+# undef atan2f
+# if HAVE_RAW_DECL_ATAN2F
+_GL_WARN_ON_USE (atan2f, "atan2f is unportable - "
+ "use gnulib module atan2f for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef cbrtf
+# define cbrtf rpl_cbrtf
+# endif
+_GL_FUNCDECL_RPL (cbrtf, float, (float x));
+_GL_CXXALIAS_RPL (cbrtf, float, (float x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (cbrtf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (cbrtf, float, (float x));
+# endif
+_GL_CXXALIASWARN (cbrtf);
+#elif defined GNULIB_POSIXCHECK
+# undef cbrtf
+# if HAVE_RAW_DECL_CBRTF
+_GL_WARN_ON_USE (cbrtf, "cbrtf is unportable - "
+ "use gnulib module cbrtf for portability");
+# endif
+#endif
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (cbrt, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (cbrt, double, (double x));
+_GL_CXXALIASWARN (cbrt);
+#elif defined GNULIB_POSIXCHECK
+# undef cbrt
+# if HAVE_RAW_DECL_CBRT
+_GL_WARN_ON_USE (cbrt, "cbrt is unportable - "
+ "use gnulib module cbrt for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef cbrtl
+# define cbrtl rpl_cbrtl
+# endif
+_GL_FUNCDECL_RPL (cbrtl, long double, (long double x));
+_GL_CXXALIAS_RPL (cbrtl, long double, (long double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (cbrtl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (cbrtl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (cbrtl);
+#elif defined GNULIB_POSIXCHECK
+# undef cbrtl
+# if HAVE_RAW_DECL_CBRTL
+_GL_WARN_ON_USE (cbrtl, "cbrtl is unportable - "
+ "use gnulib module cbrtl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ceilf
+# define ceilf rpl_ceilf
+# endif
+_GL_FUNCDECL_RPL (ceilf, float, (float x));
+_GL_CXXALIAS_RPL (ceilf, float, (float x));
+# else
+# if !1
+# undef ceilf
+_GL_FUNCDECL_SYS (ceilf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (ceilf, float, (float x));
+# endif
+_GL_CXXALIASWARN (ceilf);
+#elif defined GNULIB_POSIXCHECK
+# undef ceilf
+# if HAVE_RAW_DECL_CEILF
+_GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
+ "use gnulib module ceilf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define ceil rpl_ceil
+# endif
+_GL_FUNCDECL_RPL (ceil, double, (double x));
+_GL_CXXALIAS_RPL (ceil, double, (double x));
+# else
+_GL_CXXALIAS_SYS (ceil, double, (double x));
+# endif
+_GL_CXXALIASWARN (ceil);
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ceill
+# define ceill rpl_ceill
+# endif
+_GL_FUNCDECL_RPL (ceill, long double, (long double x));
+_GL_CXXALIAS_RPL (ceill, long double, (long double x));
+# else
+# if !1
+# undef ceill
+_GL_FUNCDECL_SYS (ceill, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (ceill, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (ceill);
+#elif defined GNULIB_POSIXCHECK
+# undef ceill
+# if HAVE_RAW_DECL_CEILL
+_GL_WARN_ON_USE (ceill, "ceill is unportable - "
+ "use gnulib module ceill for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (copysignf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (copysignf, float, (float x, float y));
+_GL_CXXALIASWARN (copysignf);
+#elif defined GNULIB_POSIXCHECK
+# undef copysignf
+# if HAVE_RAW_DECL_COPYSIGNF
+_GL_WARN_ON_USE (copysignf, "copysignf is unportable - "
+ "use gnulib module copysignf for portability");
+# endif
+#endif
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (copysign, double, (double x, double y));
+# endif
+_GL_CXXALIAS_SYS (copysign, double, (double x, double y));
+_GL_CXXALIASWARN (copysign);
+#elif defined GNULIB_POSIXCHECK
+# undef copysign
+# if HAVE_RAW_DECL_COPYSIGN
+_GL_WARN_ON_USE (copysign, "copysign is unportable - "
+ "use gnulib module copysign for portability");
+# endif
+#endif
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (copysignl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIAS_SYS (copysignl, long double, (long double x, long double y));
+_GL_CXXALIASWARN (copysignl);
+#elif defined GNULIB_POSIXCHECK
+# undef copysignl
+# if HAVE_RAW_DECL_COPYSIGNL
+_GL_WARN_ON_USE (copysign, "copysignl is unportable - "
+ "use gnulib module copysignl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef cosf
+_GL_FUNCDECL_SYS (cosf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (cosf, float, (float x));
+_GL_CXXALIASWARN (cosf);
+#elif defined GNULIB_POSIXCHECK
+# undef cosf
+# if HAVE_RAW_DECL_COSF
+_GL_WARN_ON_USE (cosf, "cosf is unportable - "
+ "use gnulib module cosf for portability");
+# endif
+#endif
+
+#if 0
+# if !1 || !1
+# undef cosl
+_GL_FUNCDECL_SYS (cosl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (cosl, long double, (long double x));
+_GL_CXXALIASWARN (cosl);
+#elif defined GNULIB_POSIXCHECK
+# undef cosl
+# if HAVE_RAW_DECL_COSL
+_GL_WARN_ON_USE (cosl, "cosl is unportable - "
+ "use gnulib module cosl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef coshf
+_GL_FUNCDECL_SYS (coshf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (coshf, float, (float x));
+_GL_CXXALIASWARN (coshf);
+#elif defined GNULIB_POSIXCHECK
+# undef coshf
+# if HAVE_RAW_DECL_COSHF
+_GL_WARN_ON_USE (coshf, "coshf is unportable - "
+ "use gnulib module coshf for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef expf
+_GL_FUNCDECL_SYS (expf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (expf, float, (float x));
+_GL_CXXALIASWARN (expf);
+#elif defined GNULIB_POSIXCHECK
+# undef expf
+# if HAVE_RAW_DECL_EXPF
+_GL_WARN_ON_USE (expf, "expf is unportable - "
+ "use gnulib module expf for portability");
+# endif
+#endif
+
+#if 0
+# if !1 || !1
+# undef expl
+_GL_FUNCDECL_SYS (expl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (expl, long double, (long double x));
+_GL_CXXALIASWARN (expl);
+#elif defined GNULIB_POSIXCHECK
+# undef expl
+# if HAVE_RAW_DECL_EXPL
+_GL_WARN_ON_USE (expl, "expl is unportable - "
+ "use gnulib module expl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (exp2f, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (exp2f, float, (float x));
+_GL_CXXALIASWARN (exp2f);
+#elif defined GNULIB_POSIXCHECK
+# undef exp2f
+# if HAVE_RAW_DECL_EXP2F
+_GL_WARN_ON_USE (exp2f, "exp2f is unportable - "
+ "use gnulib module exp2f for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef exp2
+# define exp2 rpl_exp2
+# endif
+_GL_FUNCDECL_RPL (exp2, double, (double x));
+_GL_CXXALIAS_RPL (exp2, double, (double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (exp2, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (exp2, double, (double x));
+# endif
+_GL_CXXALIASWARN (exp2);
+#elif defined GNULIB_POSIXCHECK
+# undef exp2
+# if HAVE_RAW_DECL_EXP2
+_GL_WARN_ON_USE (exp2, "exp2 is unportable - "
+ "use gnulib module exp2 for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef exp2l
+# define exp2l rpl_exp2l
+# endif
+_GL_FUNCDECL_RPL (exp2l, long double, (long double x));
+_GL_CXXALIAS_RPL (exp2l, long double, (long double x));
+# else
+# if !1
+# undef exp2l
+_GL_FUNCDECL_SYS (exp2l, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (exp2l, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (exp2l);
+#elif defined GNULIB_POSIXCHECK
+# undef exp2l
+# if HAVE_RAW_DECL_EXP2L
+_GL_WARN_ON_USE (exp2l, "exp2l is unportable - "
+ "use gnulib module exp2l for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef expm1f
+# define expm1f rpl_expm1f
+# endif
+_GL_FUNCDECL_RPL (expm1f, float, (float x));
+_GL_CXXALIAS_RPL (expm1f, float, (float x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (expm1f, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (expm1f, float, (float x));
+# endif
+_GL_CXXALIASWARN (expm1f);
+#elif defined GNULIB_POSIXCHECK
+# undef expm1f
+# if HAVE_RAW_DECL_EXPM1F
+_GL_WARN_ON_USE (expm1f, "expm1f is unportable - "
+ "use gnulib module expm1f for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef expm1
+# define expm1 rpl_expm1
+# endif
+_GL_FUNCDECL_RPL (expm1, double, (double x));
+_GL_CXXALIAS_RPL (expm1, double, (double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (expm1, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (expm1, double, (double x));
+# endif
+_GL_CXXALIASWARN (expm1);
+#elif defined GNULIB_POSIXCHECK
+# undef expm1
+# if HAVE_RAW_DECL_EXPM1
+_GL_WARN_ON_USE (expm1, "expm1 is unportable - "
+ "use gnulib module expm1 for portability");
+# endif
+#endif
+
+#if 0
+# if !1
+# undef expm1l
+_GL_FUNCDECL_SYS (expm1l, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (expm1l, long double, (long double x));
+_GL_CXXALIASWARN (expm1l);
+#elif defined GNULIB_POSIXCHECK
+# undef expm1l
+# if HAVE_RAW_DECL_EXPM1L
+_GL_WARN_ON_USE (expm1l, "expm1l is unportable - "
+ "use gnulib module expm1l for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef fabsf
+_GL_FUNCDECL_SYS (fabsf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (fabsf, float, (float x));
+_GL_CXXALIASWARN (fabsf);
+#elif defined GNULIB_POSIXCHECK
+# undef fabsf
+# if HAVE_RAW_DECL_FABSF
+_GL_WARN_ON_USE (fabsf, "fabsf is unportable - "
+ "use gnulib module fabsf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fabsl
+# define fabsl rpl_fabsl
+# endif
+_GL_FUNCDECL_RPL (fabsl, long double, (long double x));
+_GL_CXXALIAS_RPL (fabsl, long double, (long double x));
+# else
+# if !1
+# undef fabsl
+_GL_FUNCDECL_SYS (fabsl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (fabsl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (fabsl);
+#elif defined GNULIB_POSIXCHECK
+# undef fabsl
+# if HAVE_RAW_DECL_FABSL
+_GL_WARN_ON_USE (fabsl, "fabsl is unportable - "
+ "use gnulib module fabsl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef floorf
+# define floorf rpl_floorf
+# endif
+_GL_FUNCDECL_RPL (floorf, float, (float x));
+_GL_CXXALIAS_RPL (floorf, float, (float x));
+# else
+# if !1
+# undef floorf
+_GL_FUNCDECL_SYS (floorf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (floorf, float, (float x));
+# endif
+_GL_CXXALIASWARN (floorf);
+#elif defined GNULIB_POSIXCHECK
+# undef floorf
+# if HAVE_RAW_DECL_FLOORF
+_GL_WARN_ON_USE (floorf, "floorf is unportable - "
+ "use gnulib module floorf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define floor rpl_floor
+# endif
+_GL_FUNCDECL_RPL (floor, double, (double x));
+_GL_CXXALIAS_RPL (floor, double, (double x));
+# else
+_GL_CXXALIAS_SYS (floor, double, (double x));
+# endif
+_GL_CXXALIASWARN (floor);
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef floorl
+# define floorl rpl_floorl
+# endif
+_GL_FUNCDECL_RPL (floorl, long double, (long double x));
+_GL_CXXALIAS_RPL (floorl, long double, (long double x));
+# else
+# if !1
+# undef floorl
+_GL_FUNCDECL_SYS (floorl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (floorl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (floorl);
+#elif defined GNULIB_POSIXCHECK
+# undef floorl
+# if HAVE_RAW_DECL_FLOORL
+_GL_WARN_ON_USE (floorl, "floorl is unportable - "
+ "use gnulib module floorl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fmaf
+# define fmaf rpl_fmaf
+# endif
+_GL_FUNCDECL_RPL (fmaf, float, (float x, float y, float z));
+_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z));
+# else
+# if !1
+_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z));
+# endif
+_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z));
+# endif
+_GL_CXXALIASWARN (fmaf);
+#elif defined GNULIB_POSIXCHECK
+# undef fmaf
+# if HAVE_RAW_DECL_FMAF
+_GL_WARN_ON_USE (fmaf, "fmaf is unportable - "
+ "use gnulib module fmaf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fma
+# define fma rpl_fma
+# endif
+_GL_FUNCDECL_RPL (fma, double, (double x, double y, double z));
+_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z));
+# else
+# if !1
+_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z));
+# endif
+_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z));
+# endif
+_GL_CXXALIASWARN (fma);
+#elif defined GNULIB_POSIXCHECK
+# undef fma
+# if HAVE_RAW_DECL_FMA
+_GL_WARN_ON_USE (fma, "fma is unportable - "
+ "use gnulib module fma for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fmal
+# define fmal rpl_fmal
+# endif
+_GL_FUNCDECL_RPL (fmal, long double,
+ (long double x, long double y, long double z));
+_GL_CXXALIAS_RPL (fmal, long double,
+ (long double x, long double y, long double z));
+# else
+# if !1
+# undef fmal
+_GL_FUNCDECL_SYS (fmal, long double,
+ (long double x, long double y, long double z));
+# endif
+_GL_CXXALIAS_SYS (fmal, long double,
+ (long double x, long double y, long double z));
+# endif
+_GL_CXXALIASWARN (fmal);
+#elif defined GNULIB_POSIXCHECK
+# undef fmal
+# if HAVE_RAW_DECL_FMAL
+_GL_WARN_ON_USE (fmal, "fmal is unportable - "
+ "use gnulib module fmal for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fmodf
+# define fmodf rpl_fmodf
+# endif
+_GL_FUNCDECL_RPL (fmodf, float, (float x, float y));
+_GL_CXXALIAS_RPL (fmodf, float, (float x, float y));
+# else
+# if !1
+# undef fmodf
+_GL_FUNCDECL_SYS (fmodf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (fmodf, float, (float x, float y));
+# endif
+_GL_CXXALIASWARN (fmodf);
+#elif defined GNULIB_POSIXCHECK
+# undef fmodf
+# if HAVE_RAW_DECL_FMODF
+_GL_WARN_ON_USE (fmodf, "fmodf is unportable - "
+ "use gnulib module fmodf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fmod
+# define fmod rpl_fmod
+# endif
+_GL_FUNCDECL_RPL (fmod, double, (double x, double y));
+_GL_CXXALIAS_RPL (fmod, double, (double x, double y));
+# else
+_GL_CXXALIAS_SYS (fmod, double, (double x, double y));
+# endif
+_GL_CXXALIASWARN (fmod);
+#elif defined GNULIB_POSIXCHECK
+# undef fmod
+# if HAVE_RAW_DECL_FMOD
+_GL_WARN_ON_USE (fmod, "fmod has portability problems - "
+ "use gnulib module fmod for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fmodl
+# define fmodl rpl_fmodl
+# endif
+_GL_FUNCDECL_RPL (fmodl, long double, (long double x, long double y));
+_GL_CXXALIAS_RPL (fmodl, long double, (long double x, long double y));
+# else
+# if !1
+# undef fmodl
+_GL_FUNCDECL_SYS (fmodl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIAS_SYS (fmodl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIASWARN (fmodl);
+#elif defined GNULIB_POSIXCHECK
+# undef fmodl
+# if HAVE_RAW_DECL_FMODL
+_GL_WARN_ON_USE (fmodl, "fmodl is unportable - "
+ "use gnulib module fmodl for portability");
+# endif
+#endif
+
+
+/* Write x as
+ x = mantissa * 2^exp
+ where
+ If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
+ If x is zero: mantissa = x, exp = 0.
+ If x is infinite or NaN: mantissa = x, exp unspecified.
+ Store exp in *EXPPTR and return mantissa. */
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef frexpf
+# define frexpf rpl_frexpf
+# endif
+_GL_FUNCDECL_RPL (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (frexpf, float, (float x, int *expptr));
+# else
+# if !1
+# undef frexpf
+_GL_FUNCDECL_SYS (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr));
+# endif
+_GL_CXXALIASWARN (frexpf);
+#elif defined GNULIB_POSIXCHECK
+# undef frexpf
+# if HAVE_RAW_DECL_FREXPF
+_GL_WARN_ON_USE (frexpf, "frexpf is unportable - "
+ "use gnulib module frexpf for portability");
+# endif
+#endif
+
+/* Write x as
+ x = mantissa * 2^exp
+ where
+ If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
+ If x is zero: mantissa = x, exp = 0.
+ If x is infinite or NaN: mantissa = x, exp unspecified.
+ Store exp in *EXPPTR and return mantissa. */
+#if 0
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define frexp rpl_frexp
+# endif
+_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
+# else
+_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
+# endif
+_GL_CXXALIASWARN (frexp);
+#elif defined GNULIB_POSIXCHECK
+# undef frexp
+/* Assume frexp is always declared. */
+_GL_WARN_ON_USE (frexp, "frexp is unportable - "
+ "use gnulib module frexp for portability");
+#endif
+
+/* Write x as
+ x = mantissa * 2^exp
+ where
+ If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
+ If x is zero: mantissa = x, exp = 0.
+ If x is infinite or NaN: mantissa = x, exp unspecified.
+ Store exp in *EXPPTR and return mantissa. */
+#if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef frexpl
+# define frexpl rpl_frexpl
+# endif
+_GL_FUNCDECL_RPL (frexpl, long double,
+ (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr));
+#else
+# if !1
+_GL_FUNCDECL_SYS (frexpl, long double,
+ (long double x, int *expptr) _GL_ARG_NONNULL ((2)));
+# endif
+# if 1
+_GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
+# endif
+#endif
+#if 1 && !(1 && !1)
+_GL_CXXALIASWARN (frexpl);
+#endif
+#if !1 && defined GNULIB_POSIXCHECK
+# undef frexpl
+# if HAVE_RAW_DECL_FREXPL
+_GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
+ "use gnulib module frexpl for portability");
+# endif
+#endif
+
+
+/* Return sqrt(x^2+y^2). */
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef hypotf
+# define hypotf rpl_hypotf
+# endif
+_GL_FUNCDECL_RPL (hypotf, float, (float x, float y));
+_GL_CXXALIAS_RPL (hypotf, float, (float x, float y));
+# else
+# if !1
+_GL_FUNCDECL_SYS (hypotf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (hypotf, float, (float x, float y));
+# endif
+_GL_CXXALIASWARN (hypotf);
+#elif defined GNULIB_POSIXCHECK
+# undef hypotf
+# if HAVE_RAW_DECL_HYPOTF
+_GL_WARN_ON_USE (hypotf, "hypotf is unportable - "
+ "use gnulib module hypotf for portability");
+# endif
+#endif
+
+/* Return sqrt(x^2+y^2). */
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef hypot
+# define hypot rpl_hypot
+# endif
+_GL_FUNCDECL_RPL (hypot, double, (double x, double y));
+_GL_CXXALIAS_RPL (hypot, double, (double x, double y));
+# else
+_GL_CXXALIAS_SYS (hypot, double, (double x, double y));
+# endif
+_GL_CXXALIASWARN (hypot);
+#elif defined GNULIB_POSIXCHECK
+# undef hypot
+# if HAVE_RAW_DECL_HYPOT
+_GL_WARN_ON_USE (hypotf, "hypot has portability problems - "
+ "use gnulib module hypot for portability");
+# endif
+#endif
+
+/* Return sqrt(x^2+y^2). */
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef hypotl
+# define hypotl rpl_hypotl
+# endif
+_GL_FUNCDECL_RPL (hypotl, long double, (long double x, long double y));
+_GL_CXXALIAS_RPL (hypotl, long double, (long double x, long double y));
+# else
+# if !1
+_GL_FUNCDECL_SYS (hypotl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIASWARN (hypotl);
+#elif defined GNULIB_POSIXCHECK
+# undef hypotl
+# if HAVE_RAW_DECL_HYPOTL
+_GL_WARN_ON_USE (hypotl, "hypotl is unportable - "
+ "use gnulib module hypotl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ilogbf
+# define ilogbf rpl_ilogbf
+# endif
+_GL_FUNCDECL_RPL (ilogbf, int, (float x));
+_GL_CXXALIAS_RPL (ilogbf, int, (float x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (ilogbf, int, (float x));
+# endif
+_GL_CXXALIAS_SYS (ilogbf, int, (float x));
+# endif
+_GL_CXXALIASWARN (ilogbf);
+#elif defined GNULIB_POSIXCHECK
+# undef ilogbf
+# if HAVE_RAW_DECL_ILOGBF
+_GL_WARN_ON_USE (ilogbf, "ilogbf is unportable - "
+ "use gnulib module ilogbf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ilogb
+# define ilogb rpl_ilogb
+# endif
+_GL_FUNCDECL_RPL (ilogb, int, (double x));
+_GL_CXXALIAS_RPL (ilogb, int, (double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (ilogb, int, (double x));
+# endif
+_GL_CXXALIAS_SYS (ilogb, int, (double x));
+# endif
+_GL_CXXALIASWARN (ilogb);
+#elif defined GNULIB_POSIXCHECK
+# undef ilogb
+# if HAVE_RAW_DECL_ILOGB
+_GL_WARN_ON_USE (ilogb, "ilogb is unportable - "
+ "use gnulib module ilogb for portability");
+# endif
+#endif
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (ilogbl, int, (long double x));
+# endif
+_GL_CXXALIAS_SYS (ilogbl, int, (long double x));
+_GL_CXXALIASWARN (ilogbl);
+#elif defined GNULIB_POSIXCHECK
+# undef ilogbl
+# if HAVE_RAW_DECL_ILOGBL
+_GL_WARN_ON_USE (ilogbl, "ilogbl is unportable - "
+ "use gnulib module ilogbl for portability");
+# endif
+#endif
+
+
+/* Return x * 2^exp. */
+#if 0
+# if !1
+# undef ldexpf
+_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp));
+# endif
+_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp));
+_GL_CXXALIASWARN (ldexpf);
+#elif defined GNULIB_POSIXCHECK
+# undef ldexpf
+# if HAVE_RAW_DECL_LDEXPF
+_GL_WARN_ON_USE (ldexpf, "ldexpf is unportable - "
+ "use gnulib module ldexpf for portability");
+# endif
+#endif
+
+/* Return x * 2^exp. */
+#if 0 && 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ldexpl
+# define ldexpl rpl_ldexpl
+# endif
+_GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp));
+_GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp));
+#else
+# if !1
+_GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp));
+# endif
+# if 0
+_GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
+# endif
+#endif
+#if 0
+_GL_CXXALIASWARN (ldexpl);
+#endif
+#if !0 && defined GNULIB_POSIXCHECK
+# undef ldexpl
+# if HAVE_RAW_DECL_LDEXPL
+_GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
+ "use gnulib module ldexpl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef logf
+# define logf rpl_logf
+# endif
+_GL_FUNCDECL_RPL (logf, float, (float x));
+_GL_CXXALIAS_RPL (logf, float, (float x));
+# else
+# if !1
+# undef logf
+_GL_FUNCDECL_SYS (logf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (logf, float, (float x));
+# endif
+_GL_CXXALIASWARN (logf);
+#elif defined GNULIB_POSIXCHECK
+# undef logf
+# if HAVE_RAW_DECL_LOGF
+_GL_WARN_ON_USE (logf, "logf is unportable - "
+ "use gnulib module logf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log
+# define log rpl_log
+# endif
+_GL_FUNCDECL_RPL (log, double, (double x));
+_GL_CXXALIAS_RPL (log, double, (double x));
+# else
+_GL_CXXALIAS_SYS (log, double, (double x));
+# endif
+_GL_CXXALIASWARN (log);
+#elif defined GNULIB_POSIXCHECK
+# undef log
+# if HAVE_RAW_DECL_LOG
+_GL_WARN_ON_USE (log, "log has portability problems - "
+ "use gnulib module log for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef logl
+# define logl rpl_logl
+# endif
+_GL_FUNCDECL_RPL (logl, long double, (long double x));
+_GL_CXXALIAS_RPL (logl, long double, (long double x));
+# else
+# if !1 || !1
+# undef logl
+_GL_FUNCDECL_SYS (logl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (logl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (logl);
+#elif defined GNULIB_POSIXCHECK
+# undef logl
+# if HAVE_RAW_DECL_LOGL
+_GL_WARN_ON_USE (logl, "logl is unportable - "
+ "use gnulib module logl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log10f
+# define log10f rpl_log10f
+# endif
+_GL_FUNCDECL_RPL (log10f, float, (float x));
+_GL_CXXALIAS_RPL (log10f, float, (float x));
+# else
+# if !1
+# undef log10f
+_GL_FUNCDECL_SYS (log10f, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (log10f, float, (float x));
+# endif
+_GL_CXXALIASWARN (log10f);
+#elif defined GNULIB_POSIXCHECK
+# undef log10f
+# if HAVE_RAW_DECL_LOG10F
+_GL_WARN_ON_USE (log10f, "log10f is unportable - "
+ "use gnulib module log10f for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log10
+# define log10 rpl_log10
+# endif
+_GL_FUNCDECL_RPL (log10, double, (double x));
+_GL_CXXALIAS_RPL (log10, double, (double x));
+# else
+_GL_CXXALIAS_SYS (log10, double, (double x));
+# endif
+_GL_CXXALIASWARN (log10);
+#elif defined GNULIB_POSIXCHECK
+# undef log10
+# if HAVE_RAW_DECL_LOG10
+_GL_WARN_ON_USE (log10, "log10 has portability problems - "
+ "use gnulib module log10 for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log10l
+# define log10l rpl_log10l
+# endif
+_GL_FUNCDECL_RPL (log10l, long double, (long double x));
+_GL_CXXALIAS_RPL (log10l, long double, (long double x));
+# else
+# if !1 || !1
+# undef log10l
+_GL_FUNCDECL_SYS (log10l, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (log10l, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (log10l);
+#elif defined GNULIB_POSIXCHECK
+# undef log10l
+# if HAVE_RAW_DECL_LOG10L
+_GL_WARN_ON_USE (log10l, "log10l is unportable - "
+ "use gnulib module log10l for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log1pf
+# define log1pf rpl_log1pf
+# endif
+_GL_FUNCDECL_RPL (log1pf, float, (float x));
+_GL_CXXALIAS_RPL (log1pf, float, (float x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (log1pf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (log1pf, float, (float x));
+# endif
+_GL_CXXALIASWARN (log1pf);
+#elif defined GNULIB_POSIXCHECK
+# undef log1pf
+# if HAVE_RAW_DECL_LOG1PF
+_GL_WARN_ON_USE (log1pf, "log1pf is unportable - "
+ "use gnulib module log1pf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log1p
+# define log1p rpl_log1p
+# endif
+_GL_FUNCDECL_RPL (log1p, double, (double x));
+_GL_CXXALIAS_RPL (log1p, double, (double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (log1p, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (log1p, double, (double x));
+# endif
+_GL_CXXALIASWARN (log1p);
+#elif defined GNULIB_POSIXCHECK
+# undef log1p
+# if HAVE_RAW_DECL_LOG1P
+_GL_WARN_ON_USE (log1p, "log1p has portability problems - "
+ "use gnulib module log1p for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log1pl
+# define log1pl rpl_log1pl
+# endif
+_GL_FUNCDECL_RPL (log1pl, long double, (long double x));
+_GL_CXXALIAS_RPL (log1pl, long double, (long double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (log1pl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (log1pl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (log1pl);
+#elif defined GNULIB_POSIXCHECK
+# undef log1pl
+# if HAVE_RAW_DECL_LOG1PL
+_GL_WARN_ON_USE (log1pl, "log1pl has portability problems - "
+ "use gnulib module log1pl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log2f
+# define log2f rpl_log2f
+# endif
+_GL_FUNCDECL_RPL (log2f, float, (float x));
+_GL_CXXALIAS_RPL (log2f, float, (float x));
+# else
+# if !1
+# undef log2f
+_GL_FUNCDECL_SYS (log2f, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (log2f, float, (float x));
+# endif
+_GL_CXXALIASWARN (log2f);
+#elif defined GNULIB_POSIXCHECK
+# undef log2f
+# if HAVE_RAW_DECL_LOG2F
+_GL_WARN_ON_USE (log2f, "log2f is unportable - "
+ "use gnulib module log2f for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log2
+# define log2 rpl_log2
+# endif
+_GL_FUNCDECL_RPL (log2, double, (double x));
+_GL_CXXALIAS_RPL (log2, double, (double x));
+# else
+# if !1
+# undef log2
+_GL_FUNCDECL_SYS (log2, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (log2, double, (double x));
+# endif
+_GL_CXXALIASWARN (log2);
+#elif defined GNULIB_POSIXCHECK
+# undef log2
+# if HAVE_RAW_DECL_LOG2
+_GL_WARN_ON_USE (log2, "log2 is unportable - "
+ "use gnulib module log2 for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef log2l
+# define log2l rpl_log2l
+# endif
+_GL_FUNCDECL_RPL (log2l, long double, (long double x));
+_GL_CXXALIAS_RPL (log2l, long double, (long double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (log2l, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (log2l, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (log2l);
+#elif defined GNULIB_POSIXCHECK
+# undef log2l
+# if HAVE_RAW_DECL_LOG2L
+_GL_WARN_ON_USE (log2l, "log2l is unportable - "
+ "use gnulib module log2l for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef logbf
+# define logbf rpl_logbf
+# endif
+_GL_FUNCDECL_RPL (logbf, float, (float x));
+_GL_CXXALIAS_RPL (logbf, float, (float x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (logbf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (logbf, float, (float x));
+# endif
+_GL_CXXALIASWARN (logbf);
+#elif defined GNULIB_POSIXCHECK
+# undef logbf
+# if HAVE_RAW_DECL_LOGBF
+_GL_WARN_ON_USE (logbf, "logbf is unportable - "
+ "use gnulib module logbf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef logb
+# define logb rpl_logb
+# endif
+_GL_FUNCDECL_RPL (logb, double, (double x));
+_GL_CXXALIAS_RPL (logb, double, (double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (logb, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (logb, double, (double x));
+# endif
+_GL_CXXALIASWARN (logb);
+#elif defined GNULIB_POSIXCHECK
+# undef logb
+# if HAVE_RAW_DECL_LOGB
+_GL_WARN_ON_USE (logb, "logb is unportable - "
+ "use gnulib module logb for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef logbl
+# define logbl rpl_logbl
+# endif
+_GL_FUNCDECL_RPL (logbl, long double, (long double x));
+_GL_CXXALIAS_RPL (logbl, long double, (long double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (logbl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (logbl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (logbl);
+#elif defined GNULIB_POSIXCHECK
+# undef logbl
+# if HAVE_RAW_DECL_LOGBL
+_GL_WARN_ON_USE (logbl, "logbl is unportable - "
+ "use gnulib module logbl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef modff
+# define modff rpl_modff
+# endif
+_GL_FUNCDECL_RPL (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (modff, float, (float x, float *iptr));
+# else
+# if !1
+# undef modff
+_GL_FUNCDECL_SYS (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (modff, float, (float x, float *iptr));
+# endif
+_GL_CXXALIASWARN (modff);
+#elif defined GNULIB_POSIXCHECK
+# undef modff
+# if HAVE_RAW_DECL_MODFF
+_GL_WARN_ON_USE (modff, "modff is unportable - "
+ "use gnulib module modff for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef modf
+# define modf rpl_modf
+# endif
+_GL_FUNCDECL_RPL (modf, double, (double x, double *iptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (modf, double, (double x, double *iptr));
+# else
+_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr));
+# endif
+_GL_CXXALIASWARN (modf);
+#elif defined GNULIB_POSIXCHECK
+# undef modf
+# if HAVE_RAW_DECL_MODF
+_GL_WARN_ON_USE (modf, "modf has portability problems - "
+ "use gnulib module modf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef modfl
+# define modfl rpl_modfl
+# endif
+_GL_FUNCDECL_RPL (modfl, long double, (long double x, long double *iptr)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (modfl, long double, (long double x, long double *iptr));
+# else
+# if !1
+# undef modfl
+_GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
+# endif
+_GL_CXXALIASWARN (modfl);
+#elif defined GNULIB_POSIXCHECK
+# undef modfl
+# if HAVE_RAW_DECL_MODFL
+_GL_WARN_ON_USE (modfl, "modfl is unportable - "
+ "use gnulib module modfl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef powf
+_GL_FUNCDECL_SYS (powf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (powf, float, (float x, float y));
+_GL_CXXALIASWARN (powf);
+#elif defined GNULIB_POSIXCHECK
+# undef powf
+# if HAVE_RAW_DECL_POWF
+_GL_WARN_ON_USE (powf, "powf is unportable - "
+ "use gnulib module powf for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef remainderf
+# define remainderf rpl_remainderf
+# endif
+_GL_FUNCDECL_RPL (remainderf, float, (float x, float y));
+_GL_CXXALIAS_RPL (remainderf, float, (float x, float y));
+# else
+# if !1
+_GL_FUNCDECL_SYS (remainderf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (remainderf, float, (float x, float y));
+# endif
+_GL_CXXALIASWARN (remainderf);
+#elif defined GNULIB_POSIXCHECK
+# undef remainderf
+# if HAVE_RAW_DECL_REMAINDERF
+_GL_WARN_ON_USE (remainderf, "remainderf is unportable - "
+ "use gnulib module remainderf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef remainder
+# define remainder rpl_remainder
+# endif
+_GL_FUNCDECL_RPL (remainder, double, (double x, double y));
+_GL_CXXALIAS_RPL (remainder, double, (double x, double y));
+# else
+# if !1 || !1
+_GL_FUNCDECL_SYS (remainder, double, (double x, double y));
+# endif
+_GL_CXXALIAS_SYS (remainder, double, (double x, double y));
+# endif
+_GL_CXXALIASWARN (remainder);
+#elif defined GNULIB_POSIXCHECK
+# undef remainder
+# if HAVE_RAW_DECL_REMAINDER
+_GL_WARN_ON_USE (remainder, "remainder is unportable - "
+ "use gnulib module remainder for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef remainderl
+# define remainderl rpl_remainderl
+# endif
+_GL_FUNCDECL_RPL (remainderl, long double, (long double x, long double y));
+_GL_CXXALIAS_RPL (remainderl, long double, (long double x, long double y));
+# else
+# if !1
+# undef remainderl
+_GL_FUNCDECL_SYS (remainderl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIAS_SYS (remainderl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIASWARN (remainderl);
+#elif defined GNULIB_POSIXCHECK
+# undef remainderl
+# if HAVE_RAW_DECL_REMAINDERL
+_GL_WARN_ON_USE (remainderl, "remainderl is unportable - "
+ "use gnulib module remainderl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (rintf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (rintf, float, (float x));
+_GL_CXXALIASWARN (rintf);
+#elif defined GNULIB_POSIXCHECK
+# undef rintf
+# if HAVE_RAW_DECL_RINTF
+_GL_WARN_ON_USE (rintf, "rintf is unportable - "
+ "use gnulib module rintf for portability");
+# endif
+#endif
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (rint, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (rint, double, (double x));
+_GL_CXXALIASWARN (rint);
+#elif defined GNULIB_POSIXCHECK
+# undef rint
+# if HAVE_RAW_DECL_RINT
+_GL_WARN_ON_USE (rint, "rint is unportable - "
+ "use gnulib module rint for portability");
+# endif
+#endif
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (rintl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (rintl, long double, (long double x));
+_GL_CXXALIASWARN (rintl);
+#elif defined GNULIB_POSIXCHECK
+# undef rintl
+# if HAVE_RAW_DECL_RINTL
+_GL_WARN_ON_USE (rintl, "rintl is unportable - "
+ "use gnulib module rintl for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef roundf
+# define roundf rpl_roundf
+# endif
+_GL_FUNCDECL_RPL (roundf, float, (float x));
+_GL_CXXALIAS_RPL (roundf, float, (float x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (roundf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (roundf, float, (float x));
+# endif
+_GL_CXXALIASWARN (roundf);
+#elif defined GNULIB_POSIXCHECK
+# undef roundf
+# if HAVE_RAW_DECL_ROUNDF
+_GL_WARN_ON_USE (roundf, "roundf is unportable - "
+ "use gnulib module roundf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef round
+# define round rpl_round
+# endif
+_GL_FUNCDECL_RPL (round, double, (double x));
+_GL_CXXALIAS_RPL (round, double, (double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (round, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (round, double, (double x));
+# endif
+_GL_CXXALIASWARN (round);
+#elif defined GNULIB_POSIXCHECK
+# undef round
+# if HAVE_RAW_DECL_ROUND
+_GL_WARN_ON_USE (round, "round is unportable - "
+ "use gnulib module round for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef roundl
+# define roundl rpl_roundl
+# endif
+_GL_FUNCDECL_RPL (roundl, long double, (long double x));
+_GL_CXXALIAS_RPL (roundl, long double, (long double x));
+# else
+# if !1
+# undef roundl
+_GL_FUNCDECL_SYS (roundl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (roundl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (roundl);
+#elif defined GNULIB_POSIXCHECK
+# undef roundl
+# if HAVE_RAW_DECL_ROUNDL
+_GL_WARN_ON_USE (roundl, "roundl is unportable - "
+ "use gnulib module roundl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef sinf
+_GL_FUNCDECL_SYS (sinf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (sinf, float, (float x));
+_GL_CXXALIASWARN (sinf);
+#elif defined GNULIB_POSIXCHECK
+# undef sinf
+# if HAVE_RAW_DECL_SINF
+_GL_WARN_ON_USE (sinf, "sinf is unportable - "
+ "use gnulib module sinf for portability");
+# endif
+#endif
+
+#if 0
+# if !1 || !1
+# undef sinl
+_GL_FUNCDECL_SYS (sinl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (sinl, long double, (long double x));
+_GL_CXXALIASWARN (sinl);
+#elif defined GNULIB_POSIXCHECK
+# undef sinl
+# if HAVE_RAW_DECL_SINL
+_GL_WARN_ON_USE (sinl, "sinl is unportable - "
+ "use gnulib module sinl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef sinhf
+_GL_FUNCDECL_SYS (sinhf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (sinhf, float, (float x));
+_GL_CXXALIASWARN (sinhf);
+#elif defined GNULIB_POSIXCHECK
+# undef sinhf
+# if HAVE_RAW_DECL_SINHF
+_GL_WARN_ON_USE (sinhf, "sinhf is unportable - "
+ "use gnulib module sinhf for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef sqrtf
+_GL_FUNCDECL_SYS (sqrtf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (sqrtf, float, (float x));
+_GL_CXXALIASWARN (sqrtf);
+#elif defined GNULIB_POSIXCHECK
+# undef sqrtf
+# if HAVE_RAW_DECL_SQRTF
+_GL_WARN_ON_USE (sqrtf, "sqrtf is unportable - "
+ "use gnulib module sqrtf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef sqrtl
+# define sqrtl rpl_sqrtl
+# endif
+_GL_FUNCDECL_RPL (sqrtl, long double, (long double x));
+_GL_CXXALIAS_RPL (sqrtl, long double, (long double x));
+# else
+# if !1 || !1
+# undef sqrtl
+_GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (sqrtl);
+#elif defined GNULIB_POSIXCHECK
+# undef sqrtl
+# if HAVE_RAW_DECL_SQRTL
+_GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
+ "use gnulib module sqrtl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef tanf
+_GL_FUNCDECL_SYS (tanf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (tanf, float, (float x));
+_GL_CXXALIASWARN (tanf);
+#elif defined GNULIB_POSIXCHECK
+# undef tanf
+# if HAVE_RAW_DECL_TANF
+_GL_WARN_ON_USE (tanf, "tanf is unportable - "
+ "use gnulib module tanf for portability");
+# endif
+#endif
+
+#if 0
+# if !1 || !1
+# undef tanl
+_GL_FUNCDECL_SYS (tanl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (tanl, long double, (long double x));
+_GL_CXXALIASWARN (tanl);
+#elif defined GNULIB_POSIXCHECK
+# undef tanl
+# if HAVE_RAW_DECL_TANL
+_GL_WARN_ON_USE (tanl, "tanl is unportable - "
+ "use gnulib module tanl for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+# undef tanhf
+_GL_FUNCDECL_SYS (tanhf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (tanhf, float, (float x));
+_GL_CXXALIASWARN (tanhf);
+#elif defined GNULIB_POSIXCHECK
+# undef tanhf
+# if HAVE_RAW_DECL_TANHF
+_GL_WARN_ON_USE (tanhf, "tanhf is unportable - "
+ "use gnulib module tanhf for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define truncf rpl_truncf
+# endif
+_GL_FUNCDECL_RPL (truncf, float, (float x));
+_GL_CXXALIAS_RPL (truncf, float, (float x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (truncf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (truncf, float, (float x));
+# endif
+_GL_CXXALIASWARN (truncf);
+#elif defined GNULIB_POSIXCHECK
+# undef truncf
+# if HAVE_RAW_DECL_TRUNCF
+_GL_WARN_ON_USE (truncf, "truncf is unportable - "
+ "use gnulib module truncf for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define trunc rpl_trunc
+# endif
+_GL_FUNCDECL_RPL (trunc, double, (double x));
+_GL_CXXALIAS_RPL (trunc, double, (double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (trunc, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (trunc, double, (double x));
+# endif
+_GL_CXXALIASWARN (trunc);
+#elif defined GNULIB_POSIXCHECK
+# undef trunc
+# if HAVE_RAW_DECL_TRUNC
+_GL_WARN_ON_USE (trunc, "trunc is unportable - "
+ "use gnulib module trunc for portability");
+# endif
+#endif
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef truncl
+# define truncl rpl_truncl
+# endif
+_GL_FUNCDECL_RPL (truncl, long double, (long double x));
+_GL_CXXALIAS_RPL (truncl, long double, (long double x));
+# else
+# if !1
+_GL_FUNCDECL_SYS (truncl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (truncl, long double, (long double x));
+# endif
+_GL_CXXALIASWARN (truncl);
+#elif defined GNULIB_POSIXCHECK
+# undef truncl
+# if HAVE_RAW_DECL_TRUNCL
+_GL_WARN_ON_USE (truncl, "truncl is unportable - "
+ "use gnulib module truncl for portability");
+# endif
+#endif
+
+
+/* Definitions of function-like macros come here, after the function
+ declarations. */
+
+
+#if 0
+# if 0
+_GL_EXTERN_C int gl_isfinitef (float x);
+_GL_EXTERN_C int gl_isfinited (double x);
+_GL_EXTERN_C int gl_isfinitel (long double x);
+# undef isfinite
+# define isfinite(x) \
+ (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \
+ sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
+ gl_isfinitef (x))
+# endif
+# ifdef __cplusplus
+# ifdef isfinite
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isfinite)
+# undef isfinite
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite)
+# endif
+# endif
+#elif defined GNULIB_POSIXCHECK
+# if defined isfinite
+_GL_WARN_REAL_FLOATING_DECL (isfinite);
+# undef isfinite
+# define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x)
+# endif
+#endif
+
+
+#if 0
+# if 0
+_GL_EXTERN_C int gl_isinff (float x);
+_GL_EXTERN_C int gl_isinfd (double x);
+_GL_EXTERN_C int gl_isinfl (long double x);
+# undef isinf
+# define isinf(x) \
+ (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \
+ sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
+ gl_isinff (x))
+# endif
+# ifdef __cplusplus
+# ifdef isinf
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isinf)
+# undef isinf
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf)
+# endif
+# endif
+#elif defined GNULIB_POSIXCHECK
+# if defined isinf
+_GL_WARN_REAL_FLOATING_DECL (isinf);
+# undef isinf
+# define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x)
+# endif
+#endif
+
+
+#if 0
+/* Test for NaN for 'float' numbers. */
+# if 1
+/* The original <math.h> included above provides a declaration of isnan macro
+ or (older) isnanf function. */
+# if __GNUC__ >= 4
+ /* GCC 4.0 and newer provides three built-ins for isnan. */
+# undef isnanf
+# define isnanf(x) __builtin_isnanf ((float)(x))
+# elif defined isnan
+# undef isnanf
+# define isnanf(x) isnan ((float)(x))
+# endif
+# else
+/* Test whether X is a NaN. */
+# undef isnanf
+# define isnanf rpl_isnanf
+_GL_EXTERN_C int isnanf (float x);
+# endif
+#endif
+
+#if 0
+/* Test for NaN for 'double' numbers.
+ This function is a gnulib extension, unlike isnan() which applied only
+ to 'double' numbers earlier but now is a type-generic macro. */
+# if 1
+/* The original <math.h> included above provides a declaration of isnan
+ macro. */
+# if __GNUC__ >= 4
+ /* GCC 4.0 and newer provides three built-ins for isnan. */
+# undef isnand
+# define isnand(x) __builtin_isnan ((double)(x))
+# else
+# undef isnand
+# define isnand(x) isnan ((double)(x))
+# endif
+# else
+/* Test whether X is a NaN. */
+# undef isnand
+# define isnand rpl_isnand
+_GL_EXTERN_C int isnand (double x);
+# endif
+#endif
+
+#if 0
+/* Test for NaN for 'long double' numbers. */
+# if 1
+/* The original <math.h> included above provides a declaration of isnan
+ macro or (older) isnanl function. */
+# if __GNUC__ >= 4
+ /* GCC 4.0 and newer provides three built-ins for isnan. */
+# undef isnanl
+# define isnanl(x) __builtin_isnanl ((long double)(x))
+# elif defined isnan
+# undef isnanl
+# define isnanl(x) isnan ((long double)(x))
+# endif
+# else
+/* Test whether X is a NaN. */
+# undef isnanl
+# define isnanl rpl_isnanl
+_GL_EXTERN_C int isnanl (long double x) _GL_ATTRIBUTE_CONST;
+# endif
+#endif
+
+/* This must come *after* the snippets for GNULIB_ISNANF and GNULIB_ISNANL! */
+#if 0
+# if 0
+/* We can't just use the isnanf macro (e.g.) as exposed by
+ isnanf.h (e.g.) here, because those may end up being macros
+ that recursively expand back to isnan. So use the gnulib
+ replacements for them directly. */
+# if 1 && __GNUC__ >= 4
+# define gl_isnan_f(x) __builtin_isnanf ((float)(x))
+# else
+_GL_EXTERN_C int rpl_isnanf (float x);
+# define gl_isnan_f(x) rpl_isnanf (x)
+# endif
+# if 1 && __GNUC__ >= 4
+# define gl_isnan_d(x) __builtin_isnan ((double)(x))
+# else
+_GL_EXTERN_C int rpl_isnand (double x);
+# define gl_isnan_d(x) rpl_isnand (x)
+# endif
+# if 1 && __GNUC__ >= 4
+# define gl_isnan_l(x) __builtin_isnanl ((long double)(x))
+# else
+_GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
+# define gl_isnan_l(x) rpl_isnanl (x)
+# endif
+# undef isnan
+# define isnan(x) \
+ (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
+ sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
+ gl_isnan_f (x))
+# elif __GNUC__ >= 4
+# undef isnan
+# define isnan(x) \
+ (sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \
+ sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \
+ __builtin_isnanf ((float)(x)))
+# endif
+# ifdef __cplusplus
+# ifdef isnan
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan)
+# undef isnan
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan)
+# endif
+# else
+/* Ensure isnan is a macro. */
+# ifndef isnan
+# define isnan isnan
+# endif
+# endif
+#elif defined GNULIB_POSIXCHECK
+# if defined isnan
+_GL_WARN_REAL_FLOATING_DECL (isnan);
+# undef isnan
+# define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x)
+# endif
+#endif
+
+
+#if 1
+# if 0
+# undef signbit
+ /* GCC 4.0 and newer provides three built-ins for signbit. */
+# define signbit(x) \
+ (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
+ sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
+ __builtin_signbitf (x))
+# endif
+# if 1
+# undef signbit
+_GL_EXTERN_C int gl_signbitf (float arg);
+_GL_EXTERN_C int gl_signbitd (double arg);
+_GL_EXTERN_C int gl_signbitl (long double arg);
+# if __GNUC__ >= 2 && !defined __STRICT_ANSI__
+# define _GL_NUM_UINT_WORDS(type) \
+ ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
+# define gl_signbitf_OPTIMIZED_MACRO
+# define gl_signbitf(arg) \
+ ({ union { float _value; \
+ unsigned int _word[_GL_NUM_UINT_WORDS (float)]; \
+ } _m; \
+ _m._value = (arg); \
+ (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \
+ })
+# endif
+# if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd
+# define gl_signbitd_OPTIMIZED_MACRO
+# define gl_signbitd(arg) \
+ ({ union { double _value; \
+ unsigned int _word[_GL_NUM_UINT_WORDS (double)]; \
+ } _m; \
+ _m._value = (arg); \
+ (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \
+ })
+# endif
+# if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl
+# define gl_signbitl_OPTIMIZED_MACRO
+# define gl_signbitl(arg) \
+ ({ union { long double _value; \
+ unsigned int _word[_GL_NUM_UINT_WORDS (long double)]; \
+ } _m; \
+ _m._value = (arg); \
+ (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \
+ })
+# endif
+# endif
+# define signbit(x) \
+ (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
+ sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
+ gl_signbitf (x))
+# endif
+# ifdef __cplusplus
+# ifdef signbit
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
+# undef signbit
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit)
+# endif
+# endif
+#elif defined GNULIB_POSIXCHECK
+# if defined signbit
+_GL_WARN_REAL_FLOATING_DECL (signbit);
+# undef signbit
+# define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x)
+# endif
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif
+
+#endif /* _GL_M4_MATH_H */
+#endif /* _GL_M4_MATH_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/sched.h b/contrib/tools/bison/gnulib/platform/win64/sched.h
index 12968e5f2b..d2e5fd34b9 100644
--- a/contrib/tools/bison/gnulib/platform/win64/sched.h
+++ b/contrib/tools/bison/gnulib/platform/win64/sched.h
@@ -1,58 +1,58 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Replacement <sched.h> for platforms that lack it.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_M4_SCHED_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. */
-#if 0
-# include <sched.h>
-#endif
-
-#ifndef _GL_M4_SCHED_H
-#define _GL_M4_SCHED_H
-
-/* Get pid_t.
- This is needed on glibc 2.11 (see
- glibc bug <http://sourceware.org/bugzilla/show_bug.cgi?id=13198>)
- and Mac OS X 10.5. */
-#include <sys/types.h>
-
-#if !0
-
-# if !GNULIB_defined_struct_sched_param
-struct sched_param
-{
- int sched_priority;
-};
-# define GNULIB_defined_struct_sched_param 1
-# endif
-
-#endif
-
-#if !(defined SCHED_FIFO && defined SCHED_RR && defined SCHED_OTHER)
-# define SCHED_FIFO 1
-# define SCHED_RR 2
-# define SCHED_OTHER 0
-#endif
-
-#endif /* _GL_M4_SCHED_H */
-#endif /* _GL_M4_SCHED_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Replacement <sched.h> for platforms that lack it.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_M4_SCHED_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. */
+#if 0
+# include <sched.h>
+#endif
+
+#ifndef _GL_M4_SCHED_H
+#define _GL_M4_SCHED_H
+
+/* Get pid_t.
+ This is needed on glibc 2.11 (see
+ glibc bug <http://sourceware.org/bugzilla/show_bug.cgi?id=13198>)
+ and Mac OS X 10.5. */
+#include <sys/types.h>
+
+#if !0
+
+# if !GNULIB_defined_struct_sched_param
+struct sched_param
+{
+ int sched_priority;
+};
+# define GNULIB_defined_struct_sched_param 1
+# endif
+
+#endif
+
+#if !(defined SCHED_FIFO && defined SCHED_RR && defined SCHED_OTHER)
+# define SCHED_FIFO 1
+# define SCHED_RR 2
+# define SCHED_OTHER 0
+#endif
+
+#endif /* _GL_M4_SCHED_H */
+#endif /* _GL_M4_SCHED_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/signal.h b/contrib/tools/bison/gnulib/platform/win64/signal.h
index 11f3a81cf5..0fd8eb5267 100644
--- a/contrib/tools/bison/gnulib/platform/win64/signal.h
+++ b/contrib/tools/bison/gnulib/platform/win64/signal.h
@@ -1,781 +1,781 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* A GNU-like <signal.h>.
-
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-#if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T)
-/* Special invocation convention:
- - Inside glibc header files.
- - On glibc systems we have a sequence of nested includes
- <signal.h> -> <ucontext.h> -> <signal.h>.
- In this situation, the functions are not yet declared, therefore we cannot
- provide the C++ aliases.
- - On glibc systems with GCC 4.3 we have a sequence of nested includes
- <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
- In this situation, some of the functions are not yet declared, therefore
- we cannot provide the C++ aliases. */
-
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* A GNU-like <signal.h>.
+
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+#if defined __need_sig_atomic_t || defined __need_sigset_t || defined _GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined __SIZEOF_PTHREAD_MUTEX_T)
+/* Special invocation convention:
+ - Inside glibc header files.
+ - On glibc systems we have a sequence of nested includes
+ <signal.h> -> <ucontext.h> -> <signal.h>.
+ In this situation, the functions are not yet declared, therefore we cannot
+ provide the C++ aliases.
+ - On glibc systems with GCC 4.3 we have a sequence of nested includes
+ <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
+ In this situation, some of the functions are not yet declared, therefore
+ we cannot provide the C++ aliases. */
+
#if _MSC_VER >= 1900
#include <../ucrt/signal.h>
#else
#include <../include/signal.h>
#endif
-
-#else
-/* Normal invocation convention. */
-
-#ifndef _GL_M4_SIGNAL_H
-
-#define _GL_ALREADY_INCLUDING_SIGNAL_H
-
-/* Define pid_t, uid_t.
- Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
- On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
- us; so include <sys/types.h> now, before the second inclusion guard. */
-#include <sys/types.h>
-
-/* The include_next requires a split double-inclusion guard. */
+
+#else
+/* Normal invocation convention. */
+
+#ifndef _GL_M4_SIGNAL_H
+
+#define _GL_ALREADY_INCLUDING_SIGNAL_H
+
+/* Define pid_t, uid_t.
+ Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
+ On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
+ us; so include <sys/types.h> now, before the second inclusion guard. */
+#include <sys/types.h>
+
+/* The include_next requires a split double-inclusion guard. */
#if _MSC_VER >= 1900
#include <../ucrt/signal.h>
#else
#include <../include/signal.h>
#endif
-
-#undef _GL_ALREADY_INCLUDING_SIGNAL_H
-
-#ifndef _GL_M4_SIGNAL_H
-#define _GL_M4_SIGNAL_H
-
-/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6 declare
- pthread_sigmask in <pthread.h>, not in <signal.h>.
- But avoid namespace pollution on glibc systems.*/
-#if (0 || defined GNULIB_POSIXCHECK) \
- && ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ || defined __sun) \
- && ! defined __GLIBC__
-# include <pthread.h>
-#endif
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-/* On AIX, sig_atomic_t already includes volatile. C99 requires that
- 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
- Hence, redefine this to a non-volatile type as needed. */
-#if ! 1
-# if !GNULIB_defined_sig_atomic_t
-typedef int rpl_sig_atomic_t;
-# undef sig_atomic_t
-# define sig_atomic_t rpl_sig_atomic_t
-# define GNULIB_defined_sig_atomic_t 1
-# endif
-#endif
-
-/* A set or mask of signals. */
-#if !0
-# if !GNULIB_defined_sigset_t
-typedef unsigned int sigset_t;
-# define GNULIB_defined_sigset_t 1
-# endif
-#endif
-
-/* Define sighandler_t, the type of signal handlers. A GNU extension. */
-#if !0
-# ifdef __cplusplus
-extern "C" {
-# endif
-# if !GNULIB_defined_sighandler_t
-typedef void (*sighandler_t) (int);
-# define GNULIB_defined_sighandler_t 1
-# endif
-# ifdef __cplusplus
-}
-# endif
-#endif
-
-
-#if 1
-# ifndef SIGPIPE
-/* Define SIGPIPE to a value that does not overlap with other signals. */
-# define SIGPIPE 13
-# define GNULIB_defined_SIGPIPE 1
-/* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
- 'write', 'stdio'. */
-# endif
-#endif
-
-
-/* Maximum signal number + 1. */
-#ifndef NSIG
-# if defined __TANDEM
-# define NSIG 32
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef pthread_sigmask
-# define pthread_sigmask rpl_pthread_sigmask
-# endif
-_GL_FUNCDECL_RPL (pthread_sigmask, int,
- (int how, const sigset_t *new_mask, sigset_t *old_mask));
-_GL_CXXALIAS_RPL (pthread_sigmask, int,
- (int how, const sigset_t *new_mask, sigset_t *old_mask));
-# else
-# if !1
-_GL_FUNCDECL_SYS (pthread_sigmask, int,
- (int how, const sigset_t *new_mask, sigset_t *old_mask));
-# endif
-_GL_CXXALIAS_SYS (pthread_sigmask, int,
- (int how, const sigset_t *new_mask, sigset_t *old_mask));
-# endif
-_GL_CXXALIASWARN (pthread_sigmask);
-#elif defined GNULIB_POSIXCHECK
-# undef pthread_sigmask
-# if HAVE_RAW_DECL_PTHREAD_SIGMASK
-_GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
- "use gnulib module pthread_sigmask for portability");
-# endif
-#endif
-
-
-#if 1
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef raise
-# define raise rpl_raise
-# endif
-_GL_FUNCDECL_RPL (raise, int, (int sig));
-_GL_CXXALIAS_RPL (raise, int, (int sig));
-# else
-# if !1
-_GL_FUNCDECL_SYS (raise, int, (int sig));
-# endif
-_GL_CXXALIAS_SYS (raise, int, (int sig));
-# endif
-_GL_CXXALIASWARN (raise);
-#elif defined GNULIB_POSIXCHECK
-# undef raise
-/* Assume raise is always declared. */
-_GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
- "use gnulib module raise for portability");
-#endif
-
-
-#if 1
-# if !0
-
-# ifndef GNULIB_defined_signal_blocking
-# define GNULIB_defined_signal_blocking 1
-# endif
-
-/* Maximum signal number + 1. */
-# ifndef NSIG
-# define NSIG 32
-# endif
-
-/* This code supports only 32 signals. */
-# if !GNULIB_defined_verify_NSIG_constraint
-typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
-# define GNULIB_defined_verify_NSIG_constraint 1
-# endif
-
-# endif
-
-/* When also using extern inline, suppress the use of static inline in
- standard headers of problematic Apple configurations, as Libc at
- least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
- <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
- Perhaps Apple will fix this some day. */
-#if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
- && (defined __i386__ || defined __x86_64__))
-# undef sigaddset
-# undef sigdelset
-# undef sigemptyset
-# undef sigfillset
-# undef sigismember
-#endif
-
-/* Test whether a given signal is contained in a signal set. */
-# if 0
-/* This function is defined as a macro on Mac OS X. */
-# if defined __cplusplus && defined GNULIB_NAMESPACE
-# undef sigismember
-# endif
-# else
-_GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
-_GL_CXXALIASWARN (sigismember);
-
-/* Initialize a signal set to the empty set. */
-# if 0
-/* This function is defined as a macro on Mac OS X. */
-# if defined __cplusplus && defined GNULIB_NAMESPACE
-# undef sigemptyset
-# endif
-# else
-_GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
-_GL_CXXALIASWARN (sigemptyset);
-
-/* Add a signal to a signal set. */
-# if 0
-/* This function is defined as a macro on Mac OS X. */
-# if defined __cplusplus && defined GNULIB_NAMESPACE
-# undef sigaddset
-# endif
-# else
-_GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
-_GL_CXXALIASWARN (sigaddset);
-
-/* Remove a signal from a signal set. */
-# if 0
-/* This function is defined as a macro on Mac OS X. */
-# if defined __cplusplus && defined GNULIB_NAMESPACE
-# undef sigdelset
-# endif
-# else
-_GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
-_GL_CXXALIASWARN (sigdelset);
-
-/* Fill a signal set with all possible signals. */
-# if 0
-/* This function is defined as a macro on Mac OS X. */
-# if defined __cplusplus && defined GNULIB_NAMESPACE
-# undef sigfillset
-# endif
-# else
-_GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
-_GL_CXXALIASWARN (sigfillset);
-
-/* Return the set of those blocked signals that are pending. */
-# if !0
-_GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
-_GL_CXXALIASWARN (sigpending);
-
-/* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
- Then, if SET is not NULL, affect the current set of blocked signals by
- combining it with *SET as indicated in OPERATION.
- In this implementation, you are not allowed to change a signal handler
- while the signal is blocked. */
-# if !0
-# define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
-# define SIG_SETMASK 1 /* blocked_set = *set; */
-# define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
-_GL_FUNCDECL_SYS (sigprocmask, int,
- (int operation, const sigset_t *set, sigset_t *old_set));
-# endif
-_GL_CXXALIAS_SYS (sigprocmask, int,
- (int operation, const sigset_t *set, sigset_t *old_set));
-_GL_CXXALIASWARN (sigprocmask);
-
-/* Install the handler FUNC for signal SIG, and return the previous
- handler. */
-# ifdef __cplusplus
-extern "C" {
-# endif
-# if !GNULIB_defined_function_taking_int_returning_void_t
-typedef void (*_gl_function_taking_int_returning_void_t) (int);
-# define GNULIB_defined_function_taking_int_returning_void_t 1
-# endif
-# ifdef __cplusplus
-}
-# endif
-# if !0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define signal rpl_signal
-# endif
-_GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
- (int sig, _gl_function_taking_int_returning_void_t func));
-_GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
- (int sig, _gl_function_taking_int_returning_void_t func));
-# else
-_GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
- (int sig, _gl_function_taking_int_returning_void_t func));
-# endif
-_GL_CXXALIASWARN (signal);
-
-# if !0 && GNULIB_defined_SIGPIPE
-/* Raise signal SIGPIPE. */
-_GL_EXTERN_C int _gl_raise_SIGPIPE (void);
-# endif
-
-#elif defined GNULIB_POSIXCHECK
-# undef sigaddset
-# if HAVE_RAW_DECL_SIGADDSET
-_GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
- "use the gnulib module sigprocmask for portability");
-# endif
-# undef sigdelset
-# if HAVE_RAW_DECL_SIGDELSET
-_GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
- "use the gnulib module sigprocmask for portability");
-# endif
-# undef sigemptyset
-# if HAVE_RAW_DECL_SIGEMPTYSET
-_GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
- "use the gnulib module sigprocmask for portability");
-# endif
-# undef sigfillset
-# if HAVE_RAW_DECL_SIGFILLSET
-_GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
- "use the gnulib module sigprocmask for portability");
-# endif
-# undef sigismember
-# if HAVE_RAW_DECL_SIGISMEMBER
-_GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
- "use the gnulib module sigprocmask for portability");
-# endif
-# undef sigpending
-# if HAVE_RAW_DECL_SIGPENDING
-_GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
- "use the gnulib module sigprocmask for portability");
-# endif
-# undef sigprocmask
-# if HAVE_RAW_DECL_SIGPROCMASK
-_GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
- "use the gnulib module sigprocmask for portability");
-# endif
-#endif /* 1 */
-
-
-#if 1
-# if !0
-
-# if !0
-
-# if !GNULIB_defined_siginfo_types
-
-/* Present to allow compilation, but unsupported by gnulib. */
-union sigval
-{
- int sival_int;
- void *sival_ptr;
-};
-
-/* Present to allow compilation, but unsupported by gnulib. */
-struct siginfo_t
-{
- int si_signo;
- int si_code;
- int si_errno;
- pid_t si_pid;
- uid_t si_uid;
- void *si_addr;
- int si_status;
- long si_band;
- union sigval si_value;
-};
-typedef struct siginfo_t siginfo_t;
-
-# define GNULIB_defined_siginfo_types 1
-# endif
-
-# endif /* !0 */
-
-/* We assume that platforms which lack the sigaction() function also lack
- the 'struct sigaction' type, and vice versa. */
-
-# if !GNULIB_defined_struct_sigaction
-
-struct sigaction
-{
- union
- {
- void (*_sa_handler) (int);
- /* Present to allow compilation, but unsupported by gnulib. POSIX
- says that implementations may, but not must, make sa_sigaction
- overlap with sa_handler, but we know of no implementation where
- they do not overlap. */
- void (*_sa_sigaction) (int, siginfo_t *, void *);
- } _sa_func;
- sigset_t sa_mask;
- /* Not all POSIX flags are supported. */
- int sa_flags;
-};
-# define sa_handler _sa_func._sa_handler
-# define sa_sigaction _sa_func._sa_sigaction
-/* Unsupported flags are not present. */
-# define SA_RESETHAND 1
-# define SA_NODEFER 2
-# define SA_RESTART 4
-
-# define GNULIB_defined_struct_sigaction 1
-# endif
-
-_GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
- struct sigaction *restrict));
-
-# elif !1
-
-# define sa_sigaction sa_handler
-
-# endif /* !0, !1 */
-
-_GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
- struct sigaction *restrict));
-_GL_CXXALIASWARN (sigaction);
-
-#elif defined GNULIB_POSIXCHECK
-# undef sigaction
-# if HAVE_RAW_DECL_SIGACTION
-_GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
- "use the gnulib module sigaction for portability");
-# endif
-#endif
-
-/* Some systems don't have SA_NODEFER. */
-#ifndef SA_NODEFER
-# define SA_NODEFER 0
-#endif
-
-
-#endif /* _GL_M4_SIGNAL_H */
-#endif /* _GL_M4_SIGNAL_H */
-#endif
+
+#undef _GL_ALREADY_INCLUDING_SIGNAL_H
+
+#ifndef _GL_M4_SIGNAL_H
+#define _GL_M4_SIGNAL_H
+
+/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6 declare
+ pthread_sigmask in <pthread.h>, not in <signal.h>.
+ But avoid namespace pollution on glibc systems.*/
+#if (0 || defined GNULIB_POSIXCHECK) \
+ && ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ || defined __sun) \
+ && ! defined __GLIBC__
+# include <pthread.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+/* On AIX, sig_atomic_t already includes volatile. C99 requires that
+ 'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
+ Hence, redefine this to a non-volatile type as needed. */
+#if ! 1
+# if !GNULIB_defined_sig_atomic_t
+typedef int rpl_sig_atomic_t;
+# undef sig_atomic_t
+# define sig_atomic_t rpl_sig_atomic_t
+# define GNULIB_defined_sig_atomic_t 1
+# endif
+#endif
+
+/* A set or mask of signals. */
+#if !0
+# if !GNULIB_defined_sigset_t
+typedef unsigned int sigset_t;
+# define GNULIB_defined_sigset_t 1
+# endif
+#endif
+
+/* Define sighandler_t, the type of signal handlers. A GNU extension. */
+#if !0
+# ifdef __cplusplus
+extern "C" {
+# endif
+# if !GNULIB_defined_sighandler_t
+typedef void (*sighandler_t) (int);
+# define GNULIB_defined_sighandler_t 1
+# endif
+# ifdef __cplusplus
+}
+# endif
+#endif
+
+
+#if 1
+# ifndef SIGPIPE
+/* Define SIGPIPE to a value that does not overlap with other signals. */
+# define SIGPIPE 13
+# define GNULIB_defined_SIGPIPE 1
+/* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
+ 'write', 'stdio'. */
+# endif
+#endif
+
+
+/* Maximum signal number + 1. */
+#ifndef NSIG
+# if defined __TANDEM
+# define NSIG 32
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef pthread_sigmask
+# define pthread_sigmask rpl_pthread_sigmask
+# endif
+_GL_FUNCDECL_RPL (pthread_sigmask, int,
+ (int how, const sigset_t *new_mask, sigset_t *old_mask));
+_GL_CXXALIAS_RPL (pthread_sigmask, int,
+ (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# else
+# if !1
+_GL_FUNCDECL_SYS (pthread_sigmask, int,
+ (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# endif
+_GL_CXXALIAS_SYS (pthread_sigmask, int,
+ (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# endif
+_GL_CXXALIASWARN (pthread_sigmask);
+#elif defined GNULIB_POSIXCHECK
+# undef pthread_sigmask
+# if HAVE_RAW_DECL_PTHREAD_SIGMASK
+_GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
+ "use gnulib module pthread_sigmask for portability");
+# endif
+#endif
+
+
+#if 1
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef raise
+# define raise rpl_raise
+# endif
+_GL_FUNCDECL_RPL (raise, int, (int sig));
+_GL_CXXALIAS_RPL (raise, int, (int sig));
+# else
+# if !1
+_GL_FUNCDECL_SYS (raise, int, (int sig));
+# endif
+_GL_CXXALIAS_SYS (raise, int, (int sig));
+# endif
+_GL_CXXALIASWARN (raise);
+#elif defined GNULIB_POSIXCHECK
+# undef raise
+/* Assume raise is always declared. */
+_GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
+ "use gnulib module raise for portability");
+#endif
+
+
+#if 1
+# if !0
+
+# ifndef GNULIB_defined_signal_blocking
+# define GNULIB_defined_signal_blocking 1
+# endif
+
+/* Maximum signal number + 1. */
+# ifndef NSIG
+# define NSIG 32
+# endif
+
+/* This code supports only 32 signals. */
+# if !GNULIB_defined_verify_NSIG_constraint
+typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
+# define GNULIB_defined_verify_NSIG_constraint 1
+# endif
+
+# endif
+
+/* When also using extern inline, suppress the use of static inline in
+ standard headers of problematic Apple configurations, as Libc at
+ least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
+ <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
+ Perhaps Apple will fix this some day. */
+#if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
+ && (defined __i386__ || defined __x86_64__))
+# undef sigaddset
+# undef sigdelset
+# undef sigemptyset
+# undef sigfillset
+# undef sigismember
+#endif
+
+/* Test whether a given signal is contained in a signal set. */
+# if 0
+/* This function is defined as a macro on Mac OS X. */
+# if defined __cplusplus && defined GNULIB_NAMESPACE
+# undef sigismember
+# endif
+# else
+_GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigismember);
+
+/* Initialize a signal set to the empty set. */
+# if 0
+/* This function is defined as a macro on Mac OS X. */
+# if defined __cplusplus && defined GNULIB_NAMESPACE
+# undef sigemptyset
+# endif
+# else
+_GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigemptyset);
+
+/* Add a signal to a signal set. */
+# if 0
+/* This function is defined as a macro on Mac OS X. */
+# if defined __cplusplus && defined GNULIB_NAMESPACE
+# undef sigaddset
+# endif
+# else
+_GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigaddset);
+
+/* Remove a signal from a signal set. */
+# if 0
+/* This function is defined as a macro on Mac OS X. */
+# if defined __cplusplus && defined GNULIB_NAMESPACE
+# undef sigdelset
+# endif
+# else
+_GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigdelset);
+
+/* Fill a signal set with all possible signals. */
+# if 0
+/* This function is defined as a macro on Mac OS X. */
+# if defined __cplusplus && defined GNULIB_NAMESPACE
+# undef sigfillset
+# endif
+# else
+_GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigfillset);
+
+/* Return the set of those blocked signals that are pending. */
+# if !0
+_GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigpending);
+
+/* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
+ Then, if SET is not NULL, affect the current set of blocked signals by
+ combining it with *SET as indicated in OPERATION.
+ In this implementation, you are not allowed to change a signal handler
+ while the signal is blocked. */
+# if !0
+# define SIG_BLOCK 0 /* blocked_set = blocked_set | *set; */
+# define SIG_SETMASK 1 /* blocked_set = *set; */
+# define SIG_UNBLOCK 2 /* blocked_set = blocked_set & ~*set; */
+_GL_FUNCDECL_SYS (sigprocmask, int,
+ (int operation, const sigset_t *set, sigset_t *old_set));
+# endif
+_GL_CXXALIAS_SYS (sigprocmask, int,
+ (int operation, const sigset_t *set, sigset_t *old_set));
+_GL_CXXALIASWARN (sigprocmask);
+
+/* Install the handler FUNC for signal SIG, and return the previous
+ handler. */
+# ifdef __cplusplus
+extern "C" {
+# endif
+# if !GNULIB_defined_function_taking_int_returning_void_t
+typedef void (*_gl_function_taking_int_returning_void_t) (int);
+# define GNULIB_defined_function_taking_int_returning_void_t 1
+# endif
+# ifdef __cplusplus
+}
+# endif
+# if !0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define signal rpl_signal
+# endif
+_GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
+ (int sig, _gl_function_taking_int_returning_void_t func));
+_GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
+ (int sig, _gl_function_taking_int_returning_void_t func));
+# else
+_GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
+ (int sig, _gl_function_taking_int_returning_void_t func));
+# endif
+_GL_CXXALIASWARN (signal);
+
+# if !0 && GNULIB_defined_SIGPIPE
+/* Raise signal SIGPIPE. */
+_GL_EXTERN_C int _gl_raise_SIGPIPE (void);
+# endif
+
+#elif defined GNULIB_POSIXCHECK
+# undef sigaddset
+# if HAVE_RAW_DECL_SIGADDSET
+_GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
+ "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigdelset
+# if HAVE_RAW_DECL_SIGDELSET
+_GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
+ "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigemptyset
+# if HAVE_RAW_DECL_SIGEMPTYSET
+_GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
+ "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigfillset
+# if HAVE_RAW_DECL_SIGFILLSET
+_GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
+ "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigismember
+# if HAVE_RAW_DECL_SIGISMEMBER
+_GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
+ "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigpending
+# if HAVE_RAW_DECL_SIGPENDING
+_GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
+ "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigprocmask
+# if HAVE_RAW_DECL_SIGPROCMASK
+_GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
+ "use the gnulib module sigprocmask for portability");
+# endif
+#endif /* 1 */
+
+
+#if 1
+# if !0
+
+# if !0
+
+# if !GNULIB_defined_siginfo_types
+
+/* Present to allow compilation, but unsupported by gnulib. */
+union sigval
+{
+ int sival_int;
+ void *sival_ptr;
+};
+
+/* Present to allow compilation, but unsupported by gnulib. */
+struct siginfo_t
+{
+ int si_signo;
+ int si_code;
+ int si_errno;
+ pid_t si_pid;
+ uid_t si_uid;
+ void *si_addr;
+ int si_status;
+ long si_band;
+ union sigval si_value;
+};
+typedef struct siginfo_t siginfo_t;
+
+# define GNULIB_defined_siginfo_types 1
+# endif
+
+# endif /* !0 */
+
+/* We assume that platforms which lack the sigaction() function also lack
+ the 'struct sigaction' type, and vice versa. */
+
+# if !GNULIB_defined_struct_sigaction
+
+struct sigaction
+{
+ union
+ {
+ void (*_sa_handler) (int);
+ /* Present to allow compilation, but unsupported by gnulib. POSIX
+ says that implementations may, but not must, make sa_sigaction
+ overlap with sa_handler, but we know of no implementation where
+ they do not overlap. */
+ void (*_sa_sigaction) (int, siginfo_t *, void *);
+ } _sa_func;
+ sigset_t sa_mask;
+ /* Not all POSIX flags are supported. */
+ int sa_flags;
+};
+# define sa_handler _sa_func._sa_handler
+# define sa_sigaction _sa_func._sa_sigaction
+/* Unsupported flags are not present. */
+# define SA_RESETHAND 1
+# define SA_NODEFER 2
+# define SA_RESTART 4
+
+# define GNULIB_defined_struct_sigaction 1
+# endif
+
+_GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
+ struct sigaction *restrict));
+
+# elif !1
+
+# define sa_sigaction sa_handler
+
+# endif /* !0, !1 */
+
+_GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
+ struct sigaction *restrict));
+_GL_CXXALIASWARN (sigaction);
+
+#elif defined GNULIB_POSIXCHECK
+# undef sigaction
+# if HAVE_RAW_DECL_SIGACTION
+_GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
+ "use the gnulib module sigaction for portability");
+# endif
+#endif
+
+/* Some systems don't have SA_NODEFER. */
+#ifndef SA_NODEFER
+# define SA_NODEFER 0
+#endif
+
+
+#endif /* _GL_M4_SIGNAL_H */
+#endif /* _GL_M4_SIGNAL_H */
+#endif
diff --git a/contrib/tools/bison/gnulib/platform/win64/spawn.h b/contrib/tools/bison/gnulib/platform/win64/spawn.h
index 6797832daa..2eb7789c66 100644
--- a/contrib/tools/bison/gnulib/platform/win64/spawn.h
+++ b/contrib/tools/bison/gnulib/platform/win64/spawn.h
@@ -1,1193 +1,1193 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Definitions for POSIX spawn interface.
- Copyright (C) 2000, 2003-2004, 2008-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_M4_SPAWN_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. */
-#if 0
-# include <spawn.h>
-#endif
-
-#ifndef _GL_M4_SPAWN_H
-#define _GL_M4_SPAWN_H
-
-/* Get definitions of 'struct sched_param' and 'sigset_t'.
- But avoid namespace pollution on glibc systems. */
-#if !(defined __GLIBC__ && !defined __UCLIBC__)
-# include <sched.h>
-# include <signal.h>
-#endif
-
-#include <sys/types.h>
-
-#ifndef __THROW
-# define __THROW
-#endif
-
-/* GCC 2.95 and later have "__restrict"; C99 compilers have
- "restrict", and "configure" may have defined "restrict".
- Other compilers use __restrict, __restrict__, and _Restrict, and
- 'configure' might #define 'restrict' to those words, so pick a
- different name. */
-#ifndef _Restrict_
-# if 199901L <= __STDC_VERSION__
-# define _Restrict_ restrict
-# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
-# define _Restrict_ __restrict
-# else
-# define _Restrict_
-# endif
-#endif
-/* gcc 3.1 and up support the [restrict] syntax. Don't trust
- sys/cdefs.h's definition of __restrict_arr, though, as it
- mishandles gcc -ansi -pedantic. */
-#ifndef _Restrict_arr_
-# if ((199901L <= __STDC_VERSION__ \
- || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \
- && !defined __STRICT_ANSI__)) \
- && !defined __GNUG__)
-# define _Restrict_arr_ _Restrict_
-# else
-# define _Restrict_arr_
-# endif
-#endif
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-
-/* Data structure to contain attributes for thread creation. */
-#if 0
-# define posix_spawnattr_t rpl_posix_spawnattr_t
-#endif
-#if 0 || !0
-# if !GNULIB_defined_posix_spawnattr_t
-typedef struct
-{
- short int _flags;
- pid_t _pgrp;
- sigset_t _sd;
- sigset_t _ss;
- struct sched_param _sp;
- int _policy;
- int __pad[16];
-} posix_spawnattr_t;
-# define GNULIB_defined_posix_spawnattr_t 1
-# endif
-#endif
-
-
-/* Data structure to contain information about the actions to be
- performed in the new process with respect to file descriptors. */
-#if 0
-# define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t
-#endif
-#if 0 || !0
-# if !GNULIB_defined_posix_spawn_file_actions_t
-typedef struct
-{
- int _allocated;
- int _used;
- struct __spawn_action *_actions;
- int __pad[16];
-} posix_spawn_file_actions_t;
-# define GNULIB_defined_posix_spawn_file_actions_t 1
-# endif
-#endif
-
-
-/* Flags to be set in the 'posix_spawnattr_t'. */
-#if 0
-/* Use the values from the system, but provide the missing ones. */
-# ifndef POSIX_SPAWN_SETSCHEDPARAM
-# define POSIX_SPAWN_SETSCHEDPARAM 0
-# endif
-# ifndef POSIX_SPAWN_SETSCHEDULER
-# define POSIX_SPAWN_SETSCHEDULER 0
-# endif
-#else
-# if 0
-/* Use the values from the system, for better compatibility. */
-/* But this implementation does not support AIX extensions. */
-# undef POSIX_SPAWN_FORK_HANDLERS
-# else
-# define POSIX_SPAWN_RESETIDS 0x01
-# define POSIX_SPAWN_SETPGROUP 0x02
-# define POSIX_SPAWN_SETSIGDEF 0x04
-# define POSIX_SPAWN_SETSIGMASK 0x08
-# define POSIX_SPAWN_SETSCHEDPARAM 0x10
-# define POSIX_SPAWN_SETSCHEDULER 0x20
-# endif
-#endif
-/* A GNU extension. Use the next free bit position. */
-#define POSIX_SPAWN_USEVFORK \
- ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1) \
- | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1) \
- | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1) \
- | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1) \
- | POSIX_SPAWN_SETSCHEDPARAM \
- | (POSIX_SPAWN_SETSCHEDPARAM > 0 ? POSIX_SPAWN_SETSCHEDPARAM - 1 : 0) \
- | POSIX_SPAWN_SETSCHEDULER \
- | (POSIX_SPAWN_SETSCHEDULER > 0 ? POSIX_SPAWN_SETSCHEDULER - 1 : 0)) \
- + 1)
-#if !GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap
-typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
- [(((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
- | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
- | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
- & POSIX_SPAWN_USEVFORK)
- == 0)
- ? 1 : -1];
-# define GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap 1
-#endif
-
-
-#if 0
-/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
- Before running the process perform the actions described in FILE-ACTIONS.
-
- This function is a possible cancellation points and therefore not
- marked with __THROW. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawn rpl_posix_spawn
-# endif
-_GL_FUNCDECL_RPL (posix_spawn, int,
- (pid_t *_Restrict_ __pid,
- const char *_Restrict_ __path,
- const posix_spawn_file_actions_t *_Restrict_ __file_actions,
- const posix_spawnattr_t *_Restrict_ __attrp,
- char *const argv[_Restrict_arr_],
- char *const envp[_Restrict_arr_])
- _GL_ARG_NONNULL ((2, 5, 6)));
-_GL_CXXALIAS_RPL (posix_spawn, int,
- (pid_t *_Restrict_ __pid,
- const char *_Restrict_ __path,
- const posix_spawn_file_actions_t *_Restrict_ __file_actions,
- const posix_spawnattr_t *_Restrict_ __attrp,
- char *const argv[_Restrict_arr_],
- char *const envp[_Restrict_arr_]));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawn, int,
- (pid_t *_Restrict_ __pid,
- const char *_Restrict_ __path,
- const posix_spawn_file_actions_t *_Restrict_ __file_actions,
- const posix_spawnattr_t *_Restrict_ __attrp,
- char *const argv[_Restrict_arr_],
- char *const envp[_Restrict_arr_])
- _GL_ARG_NONNULL ((2, 5, 6)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawn, int,
- (pid_t *_Restrict_ __pid,
- const char *_Restrict_ __path,
- const posix_spawn_file_actions_t *_Restrict_ __file_actions,
- const posix_spawnattr_t *_Restrict_ __attrp,
- char *const argv[_Restrict_arr_],
- char *const envp[_Restrict_arr_]));
-# endif
-_GL_CXXALIASWARN (posix_spawn);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawn
-# if HAVE_RAW_DECL_POSIX_SPAWN
-_GL_WARN_ON_USE (posix_spawn, "posix_spawn is unportable - "
- "use gnulib module posix_spawn for portability");
-# endif
-#endif
-
-#if 1
-/* Similar to 'posix_spawn' but search for FILE in the PATH.
-
- This function is a possible cancellation points and therefore not
- marked with __THROW. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnp rpl_posix_spawnp
-# endif
-_GL_FUNCDECL_RPL (posix_spawnp, int,
- (pid_t *__pid, const char *__file,
- const posix_spawn_file_actions_t *__file_actions,
- const posix_spawnattr_t *__attrp,
- char *const argv[], char *const envp[])
- _GL_ARG_NONNULL ((2, 5, 6)));
-_GL_CXXALIAS_RPL (posix_spawnp, int,
- (pid_t *__pid, const char *__file,
- const posix_spawn_file_actions_t *__file_actions,
- const posix_spawnattr_t *__attrp,
- char *const argv[], char *const envp[]));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnp, int,
- (pid_t *__pid, const char *__file,
- const posix_spawn_file_actions_t *__file_actions,
- const posix_spawnattr_t *__attrp,
- char *const argv[], char *const envp[])
- _GL_ARG_NONNULL ((2, 5, 6)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnp, int,
- (pid_t *__pid, const char *__file,
- const posix_spawn_file_actions_t *__file_actions,
- const posix_spawnattr_t *__attrp,
- char *const argv[], char *const envp[]));
-# endif
-_GL_CXXALIASWARN (posix_spawnp);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnp
-# if HAVE_RAW_DECL_POSIX_SPAWNP
-_GL_WARN_ON_USE (posix_spawnp, "posix_spawnp is unportable - "
- "use gnulib module posix_spawnp for portability");
-# endif
-#endif
-
-
-#if 1
-/* Initialize data structure with attributes for 'spawn' to default values. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_init rpl_posix_spawnattr_init
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_init);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_init
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_INIT
-_GL_WARN_ON_USE (posix_spawnattr_init, "posix_spawnattr_init is unportable - "
- "use gnulib module posix_spawnattr_init for portability");
-# endif
-#endif
-
-#if 1
-/* Free resources associated with ATTR. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_destroy);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_destroy
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_DESTROY
-_GL_WARN_ON_USE (posix_spawnattr_destroy,
- "posix_spawnattr_destroy is unportable - "
- "use gnulib module posix_spawnattr_destroy for portability");
-# endif
-#endif
-
-#if 0
-/* Store signal mask for signals with default handling from ATTR in
- SIGDEFAULT. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_getsigdefault, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigdefault)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_getsigdefault, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigdefault));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_getsigdefault, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigdefault)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_getsigdefault, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigdefault));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_getsigdefault);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_getsigdefault
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGDEFAULT
-_GL_WARN_ON_USE (posix_spawnattr_getsigdefault,
- "posix_spawnattr_getsigdefault is unportable - "
- "use gnulib module posix_spawnattr_getsigdefault for portability");
-# endif
-#endif
-
-#if 0
-/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_setsigdefault, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigdefault)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_setsigdefault, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigdefault));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_setsigdefault, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigdefault)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_setsigdefault, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigdefault));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_setsigdefault);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_setsigdefault
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGDEFAULT
-_GL_WARN_ON_USE (posix_spawnattr_setsigdefault,
- "posix_spawnattr_setsigdefault is unportable - "
- "use gnulib module posix_spawnattr_setsigdefault for portability");
-# endif
-#endif
-
-#if 0
-/* Store signal mask for the new process from ATTR in SIGMASK. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_getsigmask, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigmask)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_getsigmask, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigmask));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_getsigmask, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigmask)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_getsigmask, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- sigset_t *_Restrict_ __sigmask));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_getsigmask);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_getsigmask
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGMASK
-_GL_WARN_ON_USE (posix_spawnattr_getsigmask,
- "posix_spawnattr_getsigmask is unportable - "
- "use gnulib module posix_spawnattr_getsigmask for portability");
-# endif
-#endif
-
-#if 1
-/* Set signal mask for the new process in ATTR to SIGMASK. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_setsigmask, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigmask)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_setsigmask, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigmask));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_setsigmask, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigmask)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_setsigmask, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const sigset_t *_Restrict_ __sigmask));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_setsigmask);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_setsigmask
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGMASK
-_GL_WARN_ON_USE (posix_spawnattr_setsigmask,
- "posix_spawnattr_setsigmask is unportable - "
- "use gnulib module posix_spawnattr_setsigmask for portability");
-# endif
-#endif
-
-#if 0
-/* Get flag word from the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_getflags, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- short int *_Restrict_ __flags)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_getflags, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- short int *_Restrict_ __flags));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_getflags, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- short int *_Restrict_ __flags)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_getflags, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- short int *_Restrict_ __flags));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_getflags);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_getflags
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETFLAGS
-_GL_WARN_ON_USE (posix_spawnattr_getflags,
- "posix_spawnattr_getflags is unportable - "
- "use gnulib module posix_spawnattr_getflags for portability");
-# endif
-#endif
-
-#if 1
-/* Store flags in the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_setflags, int,
- (posix_spawnattr_t *__attr, short int __flags)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawnattr_setflags, int,
- (posix_spawnattr_t *__attr, short int __flags));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_setflags, int,
- (posix_spawnattr_t *__attr, short int __flags)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_setflags, int,
- (posix_spawnattr_t *__attr, short int __flags));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_setflags);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_setflags
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETFLAGS
-_GL_WARN_ON_USE (posix_spawnattr_setflags,
- "posix_spawnattr_setflags is unportable - "
- "use gnulib module posix_spawnattr_setflags for portability");
-# endif
-#endif
-
-#if 0
-/* Get process group ID from the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_getpgroup, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- pid_t *_Restrict_ __pgroup)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_getpgroup, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- pid_t *_Restrict_ __pgroup));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_getpgroup, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- pid_t *_Restrict_ __pgroup)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_getpgroup, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- pid_t *_Restrict_ __pgroup));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_getpgroup);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_getpgroup
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETPGROUP
-_GL_WARN_ON_USE (posix_spawnattr_getpgroup,
- "posix_spawnattr_getpgroup is unportable - "
- "use gnulib module posix_spawnattr_getpgroup for portability");
-# endif
-#endif
-
-#if 0
-/* Store process group ID in the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_setpgroup, int,
- (posix_spawnattr_t *__attr, pid_t __pgroup)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawnattr_setpgroup, int,
- (posix_spawnattr_t *__attr, pid_t __pgroup));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawnattr_setpgroup, int,
- (posix_spawnattr_t *__attr, pid_t __pgroup)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_setpgroup, int,
- (posix_spawnattr_t *__attr, pid_t __pgroup));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_setpgroup);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_setpgroup
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETPGROUP
-_GL_WARN_ON_USE (posix_spawnattr_setpgroup,
- "posix_spawnattr_setpgroup is unportable - "
- "use gnulib module posix_spawnattr_setpgroup for portability");
-# endif
-#endif
-
-#if 0
-/* Get scheduling policy from the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_getschedpolicy, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- int *_Restrict_ __schedpolicy)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_getschedpolicy, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- int *_Restrict_ __schedpolicy));
-# else
-# if !0 || POSIX_SPAWN_SETSCHEDULER == 0
-_GL_FUNCDECL_SYS (posix_spawnattr_getschedpolicy, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- int *_Restrict_ __schedpolicy)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_getschedpolicy, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- int *_Restrict_ __schedpolicy));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_getschedpolicy);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_getschedpolicy
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPOLICY
-_GL_WARN_ON_USE (posix_spawnattr_getschedpolicy,
- "posix_spawnattr_getschedpolicy is unportable - "
- "use gnulib module posix_spawnattr_getschedpolicy for portability");
-# endif
-#endif
-
-#if 0
-/* Store scheduling policy in the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_setschedpolicy, int,
- (posix_spawnattr_t *__attr, int __schedpolicy)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawnattr_setschedpolicy, int,
- (posix_spawnattr_t *__attr, int __schedpolicy));
-# else
-# if !0 || POSIX_SPAWN_SETSCHEDULER == 0
-_GL_FUNCDECL_SYS (posix_spawnattr_setschedpolicy, int,
- (posix_spawnattr_t *__attr, int __schedpolicy)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_setschedpolicy, int,
- (posix_spawnattr_t *__attr, int __schedpolicy));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_setschedpolicy);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_setschedpolicy
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPOLICY
-_GL_WARN_ON_USE (posix_spawnattr_setschedpolicy,
- "posix_spawnattr_setschedpolicy is unportable - "
- "use gnulib module posix_spawnattr_setschedpolicy for portability");
-# endif
-#endif
-
-#if 0
-/* Get scheduling parameters from the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_getschedparam, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- struct sched_param *_Restrict_ __schedparam)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_getschedparam, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- struct sched_param *_Restrict_ __schedparam));
-# else
-# if !0 || POSIX_SPAWN_SETSCHEDPARAM == 0
-_GL_FUNCDECL_SYS (posix_spawnattr_getschedparam, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- struct sched_param *_Restrict_ __schedparam)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_getschedparam, int,
- (const posix_spawnattr_t *_Restrict_ __attr,
- struct sched_param *_Restrict_ __schedparam));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_getschedparam);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_getschedparam
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPARAM
-_GL_WARN_ON_USE (posix_spawnattr_getschedparam,
- "posix_spawnattr_getschedparam is unportable - "
- "use gnulib module posix_spawnattr_getschedparam for portability");
-# endif
-#endif
-
-#if 0
-/* Store scheduling parameters in the attribute structure. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
-# endif
-_GL_FUNCDECL_RPL (posix_spawnattr_setschedparam, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const struct sched_param *_Restrict_ __schedparam)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (posix_spawnattr_setschedparam, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const struct sched_param *_Restrict_ __schedparam));
-# else
-# if !0 || POSIX_SPAWN_SETSCHEDPARAM == 0
-_GL_FUNCDECL_SYS (posix_spawnattr_setschedparam, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const struct sched_param *_Restrict_ __schedparam)
- __THROW _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawnattr_setschedparam, int,
- (posix_spawnattr_t *_Restrict_ __attr,
- const struct sched_param *_Restrict_ __schedparam));
-# endif
-_GL_CXXALIASWARN (posix_spawnattr_setschedparam);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawnattr_setschedparam
-# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPARAM
-_GL_WARN_ON_USE (posix_spawnattr_setschedparam,
- "posix_spawnattr_setschedparam is unportable - "
- "use gnulib module posix_spawnattr_setschedparam for portability");
-# endif
-#endif
-
-
-#if 1
-/* Initialize data structure for file attribute for 'spawn' call. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
-# endif
-_GL_FUNCDECL_RPL (posix_spawn_file_actions_init, int,
- (posix_spawn_file_actions_t *__file_actions)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawn_file_actions_init, int,
- (posix_spawn_file_actions_t *__file_actions));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawn_file_actions_init, int,
- (posix_spawn_file_actions_t *__file_actions)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawn_file_actions_init, int,
- (posix_spawn_file_actions_t *__file_actions));
-# endif
-_GL_CXXALIASWARN (posix_spawn_file_actions_init);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawn_file_actions_init
-# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_INIT
-_GL_WARN_ON_USE (posix_spawn_file_actions_init,
- "posix_spawn_file_actions_init is unportable - "
- "use gnulib module posix_spawn_file_actions_init for portability");
-# endif
-#endif
-
-#if 1
-/* Free resources associated with FILE-ACTIONS. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
-# endif
-_GL_FUNCDECL_RPL (posix_spawn_file_actions_destroy, int,
- (posix_spawn_file_actions_t *__file_actions)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawn_file_actions_destroy, int,
- (posix_spawn_file_actions_t *__file_actions));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawn_file_actions_destroy, int,
- (posix_spawn_file_actions_t *__file_actions)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawn_file_actions_destroy, int,
- (posix_spawn_file_actions_t *__file_actions));
-# endif
-_GL_CXXALIASWARN (posix_spawn_file_actions_destroy);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawn_file_actions_destroy
-# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_DESTROY
-_GL_WARN_ON_USE (posix_spawn_file_actions_destroy,
- "posix_spawn_file_actions_destroy is unportable - "
- "use gnulib module posix_spawn_file_actions_destroy for portability");
-# endif
-#endif
-
-#if 1
-/* Add an action to FILE-ACTIONS which tells the implementation to call
- 'open' for the given file during the 'spawn' call. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
-# endif
-_GL_FUNCDECL_RPL (posix_spawn_file_actions_addopen, int,
- (posix_spawn_file_actions_t *_Restrict_ __file_actions,
- int __fd,
- const char *_Restrict_ __path, int __oflag, mode_t __mode)
- __THROW _GL_ARG_NONNULL ((1, 3)));
-_GL_CXXALIAS_RPL (posix_spawn_file_actions_addopen, int,
- (posix_spawn_file_actions_t *_Restrict_ __file_actions,
- int __fd,
- const char *_Restrict_ __path, int __oflag, mode_t __mode));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawn_file_actions_addopen, int,
- (posix_spawn_file_actions_t *_Restrict_ __file_actions,
- int __fd,
- const char *_Restrict_ __path, int __oflag, mode_t __mode)
- __THROW _GL_ARG_NONNULL ((1, 3)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawn_file_actions_addopen, int,
- (posix_spawn_file_actions_t *_Restrict_ __file_actions,
- int __fd,
- const char *_Restrict_ __path, int __oflag, mode_t __mode));
-# endif
-_GL_CXXALIASWARN (posix_spawn_file_actions_addopen);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawn_file_actions_addopen
-# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN
-_GL_WARN_ON_USE (posix_spawn_file_actions_addopen,
- "posix_spawn_file_actions_addopen is unportable - "
- "use gnulib module posix_spawn_file_actions_addopen for portability");
-# endif
-#endif
-
-#if 1
-/* Add an action to FILE-ACTIONS which tells the implementation to call
- 'close' for the given file descriptor during the 'spawn' call. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
-# endif
-_GL_FUNCDECL_RPL (posix_spawn_file_actions_addclose, int,
- (posix_spawn_file_actions_t *__file_actions, int __fd)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawn_file_actions_addclose, int,
- (posix_spawn_file_actions_t *__file_actions, int __fd));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawn_file_actions_addclose, int,
- (posix_spawn_file_actions_t *__file_actions, int __fd)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawn_file_actions_addclose, int,
- (posix_spawn_file_actions_t *__file_actions, int __fd));
-# endif
-_GL_CXXALIASWARN (posix_spawn_file_actions_addclose);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawn_file_actions_addclose
-# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE
-_GL_WARN_ON_USE (posix_spawn_file_actions_addclose,
- "posix_spawn_file_actions_addclose is unportable - "
- "use gnulib module posix_spawn_file_actions_addclose for portability");
-# endif
-#endif
-
-#if 1
-/* Add an action to FILE-ACTIONS which tells the implementation to call
- 'dup2' for the given file descriptors during the 'spawn' call. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
-# endif
-_GL_FUNCDECL_RPL (posix_spawn_file_actions_adddup2, int,
- (posix_spawn_file_actions_t *__file_actions,
- int __fd, int __newfd)
- __THROW _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (posix_spawn_file_actions_adddup2, int,
- (posix_spawn_file_actions_t *__file_actions,
- int __fd, int __newfd));
-# else
-# if !0
-_GL_FUNCDECL_SYS (posix_spawn_file_actions_adddup2, int,
- (posix_spawn_file_actions_t *__file_actions,
- int __fd, int __newfd)
- __THROW _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (posix_spawn_file_actions_adddup2, int,
- (posix_spawn_file_actions_t *__file_actions,
- int __fd, int __newfd));
-# endif
-_GL_CXXALIASWARN (posix_spawn_file_actions_adddup2);
-#elif defined GNULIB_POSIXCHECK
-# undef posix_spawn_file_actions_adddup2
-# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2
-_GL_WARN_ON_USE (posix_spawn_file_actions_adddup2,
- "posix_spawn_file_actions_adddup2 is unportable - "
- "use gnulib module posix_spawn_file_actions_adddup2 for portability");
-# endif
-#endif
-
-
-#endif /* _GL_M4_SPAWN_H */
-#endif /* _GL_M4_SPAWN_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Definitions for POSIX spawn interface.
+ Copyright (C) 2000, 2003-2004, 2008-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_M4_SPAWN_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. */
+#if 0
+# include <spawn.h>
+#endif
+
+#ifndef _GL_M4_SPAWN_H
+#define _GL_M4_SPAWN_H
+
+/* Get definitions of 'struct sched_param' and 'sigset_t'.
+ But avoid namespace pollution on glibc systems. */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <sched.h>
+# include <signal.h>
+#endif
+
+#include <sys/types.h>
+
+#ifndef __THROW
+# define __THROW
+#endif
+
+/* GCC 2.95 and later have "__restrict"; C99 compilers have
+ "restrict", and "configure" may have defined "restrict".
+ Other compilers use __restrict, __restrict__, and _Restrict, and
+ 'configure' might #define 'restrict' to those words, so pick a
+ different name. */
+#ifndef _Restrict_
+# if 199901L <= __STDC_VERSION__
+# define _Restrict_ restrict
+# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
+# define _Restrict_ __restrict
+# else
+# define _Restrict_
+# endif
+#endif
+/* gcc 3.1 and up support the [restrict] syntax. Don't trust
+ sys/cdefs.h's definition of __restrict_arr, though, as it
+ mishandles gcc -ansi -pedantic. */
+#ifndef _Restrict_arr_
+# if ((199901L <= __STDC_VERSION__ \
+ || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \
+ && !defined __STRICT_ANSI__)) \
+ && !defined __GNUG__)
+# define _Restrict_arr_ _Restrict_
+# else
+# define _Restrict_arr_
+# endif
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+
+/* Data structure to contain attributes for thread creation. */
+#if 0
+# define posix_spawnattr_t rpl_posix_spawnattr_t
+#endif
+#if 0 || !0
+# if !GNULIB_defined_posix_spawnattr_t
+typedef struct
+{
+ short int _flags;
+ pid_t _pgrp;
+ sigset_t _sd;
+ sigset_t _ss;
+ struct sched_param _sp;
+ int _policy;
+ int __pad[16];
+} posix_spawnattr_t;
+# define GNULIB_defined_posix_spawnattr_t 1
+# endif
+#endif
+
+
+/* Data structure to contain information about the actions to be
+ performed in the new process with respect to file descriptors. */
+#if 0
+# define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t
+#endif
+#if 0 || !0
+# if !GNULIB_defined_posix_spawn_file_actions_t
+typedef struct
+{
+ int _allocated;
+ int _used;
+ struct __spawn_action *_actions;
+ int __pad[16];
+} posix_spawn_file_actions_t;
+# define GNULIB_defined_posix_spawn_file_actions_t 1
+# endif
+#endif
+
+
+/* Flags to be set in the 'posix_spawnattr_t'. */
+#if 0
+/* Use the values from the system, but provide the missing ones. */
+# ifndef POSIX_SPAWN_SETSCHEDPARAM
+# define POSIX_SPAWN_SETSCHEDPARAM 0
+# endif
+# ifndef POSIX_SPAWN_SETSCHEDULER
+# define POSIX_SPAWN_SETSCHEDULER 0
+# endif
+#else
+# if 0
+/* Use the values from the system, for better compatibility. */
+/* But this implementation does not support AIX extensions. */
+# undef POSIX_SPAWN_FORK_HANDLERS
+# else
+# define POSIX_SPAWN_RESETIDS 0x01
+# define POSIX_SPAWN_SETPGROUP 0x02
+# define POSIX_SPAWN_SETSIGDEF 0x04
+# define POSIX_SPAWN_SETSIGMASK 0x08
+# define POSIX_SPAWN_SETSCHEDPARAM 0x10
+# define POSIX_SPAWN_SETSCHEDULER 0x20
+# endif
+#endif
+/* A GNU extension. Use the next free bit position. */
+#define POSIX_SPAWN_USEVFORK \
+ ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1) \
+ | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1) \
+ | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1) \
+ | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1) \
+ | POSIX_SPAWN_SETSCHEDPARAM \
+ | (POSIX_SPAWN_SETSCHEDPARAM > 0 ? POSIX_SPAWN_SETSCHEDPARAM - 1 : 0) \
+ | POSIX_SPAWN_SETSCHEDULER \
+ | (POSIX_SPAWN_SETSCHEDULER > 0 ? POSIX_SPAWN_SETSCHEDULER - 1 : 0)) \
+ + 1)
+#if !GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap
+typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
+ [(((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
+ | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
+ | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
+ & POSIX_SPAWN_USEVFORK)
+ == 0)
+ ? 1 : -1];
+# define GNULIB_defined_verify_POSIX_SPAWN_USEVFORK_no_overlap 1
+#endif
+
+
+#if 0
+/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
+ Before running the process perform the actions described in FILE-ACTIONS.
+
+ This function is a possible cancellation points and therefore not
+ marked with __THROW. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawn rpl_posix_spawn
+# endif
+_GL_FUNCDECL_RPL (posix_spawn, int,
+ (pid_t *_Restrict_ __pid,
+ const char *_Restrict_ __path,
+ const posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ const posix_spawnattr_t *_Restrict_ __attrp,
+ char *const argv[_Restrict_arr_],
+ char *const envp[_Restrict_arr_])
+ _GL_ARG_NONNULL ((2, 5, 6)));
+_GL_CXXALIAS_RPL (posix_spawn, int,
+ (pid_t *_Restrict_ __pid,
+ const char *_Restrict_ __path,
+ const posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ const posix_spawnattr_t *_Restrict_ __attrp,
+ char *const argv[_Restrict_arr_],
+ char *const envp[_Restrict_arr_]));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawn, int,
+ (pid_t *_Restrict_ __pid,
+ const char *_Restrict_ __path,
+ const posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ const posix_spawnattr_t *_Restrict_ __attrp,
+ char *const argv[_Restrict_arr_],
+ char *const envp[_Restrict_arr_])
+ _GL_ARG_NONNULL ((2, 5, 6)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawn, int,
+ (pid_t *_Restrict_ __pid,
+ const char *_Restrict_ __path,
+ const posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ const posix_spawnattr_t *_Restrict_ __attrp,
+ char *const argv[_Restrict_arr_],
+ char *const envp[_Restrict_arr_]));
+# endif
+_GL_CXXALIASWARN (posix_spawn);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawn
+# if HAVE_RAW_DECL_POSIX_SPAWN
+_GL_WARN_ON_USE (posix_spawn, "posix_spawn is unportable - "
+ "use gnulib module posix_spawn for portability");
+# endif
+#endif
+
+#if 1
+/* Similar to 'posix_spawn' but search for FILE in the PATH.
+
+ This function is a possible cancellation points and therefore not
+ marked with __THROW. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnp rpl_posix_spawnp
+# endif
+_GL_FUNCDECL_RPL (posix_spawnp, int,
+ (pid_t *__pid, const char *__file,
+ const posix_spawn_file_actions_t *__file_actions,
+ const posix_spawnattr_t *__attrp,
+ char *const argv[], char *const envp[])
+ _GL_ARG_NONNULL ((2, 5, 6)));
+_GL_CXXALIAS_RPL (posix_spawnp, int,
+ (pid_t *__pid, const char *__file,
+ const posix_spawn_file_actions_t *__file_actions,
+ const posix_spawnattr_t *__attrp,
+ char *const argv[], char *const envp[]));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnp, int,
+ (pid_t *__pid, const char *__file,
+ const posix_spawn_file_actions_t *__file_actions,
+ const posix_spawnattr_t *__attrp,
+ char *const argv[], char *const envp[])
+ _GL_ARG_NONNULL ((2, 5, 6)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnp, int,
+ (pid_t *__pid, const char *__file,
+ const posix_spawn_file_actions_t *__file_actions,
+ const posix_spawnattr_t *__attrp,
+ char *const argv[], char *const envp[]));
+# endif
+_GL_CXXALIASWARN (posix_spawnp);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnp
+# if HAVE_RAW_DECL_POSIX_SPAWNP
+_GL_WARN_ON_USE (posix_spawnp, "posix_spawnp is unportable - "
+ "use gnulib module posix_spawnp for portability");
+# endif
+#endif
+
+
+#if 1
+/* Initialize data structure with attributes for 'spawn' to default values. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_init rpl_posix_spawnattr_init
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawnattr_init, int, (posix_spawnattr_t *__attr));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_init, int, (posix_spawnattr_t *__attr));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_init);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_init
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_INIT
+_GL_WARN_ON_USE (posix_spawnattr_init, "posix_spawnattr_init is unportable - "
+ "use gnulib module posix_spawnattr_init for portability");
+# endif
+#endif
+
+#if 1
+/* Free resources associated with ATTR. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_destroy, int, (posix_spawnattr_t *__attr));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_destroy);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_destroy
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_DESTROY
+_GL_WARN_ON_USE (posix_spawnattr_destroy,
+ "posix_spawnattr_destroy is unportable - "
+ "use gnulib module posix_spawnattr_destroy for portability");
+# endif
+#endif
+
+#if 0
+/* Store signal mask for signals with default handling from ATTR in
+ SIGDEFAULT. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_getsigdefault, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigdefault)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_getsigdefault, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigdefault));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_getsigdefault, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigdefault)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_getsigdefault, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigdefault));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_getsigdefault);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_getsigdefault
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGDEFAULT
+_GL_WARN_ON_USE (posix_spawnattr_getsigdefault,
+ "posix_spawnattr_getsigdefault is unportable - "
+ "use gnulib module posix_spawnattr_getsigdefault for portability");
+# endif
+#endif
+
+#if 0
+/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_setsigdefault, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigdefault)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_setsigdefault, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigdefault));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_setsigdefault, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigdefault)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_setsigdefault, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigdefault));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_setsigdefault);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_setsigdefault
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGDEFAULT
+_GL_WARN_ON_USE (posix_spawnattr_setsigdefault,
+ "posix_spawnattr_setsigdefault is unportable - "
+ "use gnulib module posix_spawnattr_setsigdefault for portability");
+# endif
+#endif
+
+#if 0
+/* Store signal mask for the new process from ATTR in SIGMASK. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_getsigmask, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigmask)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_getsigmask, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigmask));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_getsigmask, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigmask)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_getsigmask, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ sigset_t *_Restrict_ __sigmask));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_getsigmask);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_getsigmask
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSIGMASK
+_GL_WARN_ON_USE (posix_spawnattr_getsigmask,
+ "posix_spawnattr_getsigmask is unportable - "
+ "use gnulib module posix_spawnattr_getsigmask for portability");
+# endif
+#endif
+
+#if 1
+/* Set signal mask for the new process in ATTR to SIGMASK. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_setsigmask, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigmask)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_setsigmask, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigmask));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_setsigmask, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigmask)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_setsigmask, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const sigset_t *_Restrict_ __sigmask));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_setsigmask);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_setsigmask
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSIGMASK
+_GL_WARN_ON_USE (posix_spawnattr_setsigmask,
+ "posix_spawnattr_setsigmask is unportable - "
+ "use gnulib module posix_spawnattr_setsigmask for portability");
+# endif
+#endif
+
+#if 0
+/* Get flag word from the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_getflags, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ short int *_Restrict_ __flags)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_getflags, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ short int *_Restrict_ __flags));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_getflags, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ short int *_Restrict_ __flags)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_getflags, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ short int *_Restrict_ __flags));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_getflags);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_getflags
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETFLAGS
+_GL_WARN_ON_USE (posix_spawnattr_getflags,
+ "posix_spawnattr_getflags is unportable - "
+ "use gnulib module posix_spawnattr_getflags for portability");
+# endif
+#endif
+
+#if 1
+/* Store flags in the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_setflags, int,
+ (posix_spawnattr_t *__attr, short int __flags)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawnattr_setflags, int,
+ (posix_spawnattr_t *__attr, short int __flags));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_setflags, int,
+ (posix_spawnattr_t *__attr, short int __flags)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_setflags, int,
+ (posix_spawnattr_t *__attr, short int __flags));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_setflags);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_setflags
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETFLAGS
+_GL_WARN_ON_USE (posix_spawnattr_setflags,
+ "posix_spawnattr_setflags is unportable - "
+ "use gnulib module posix_spawnattr_setflags for portability");
+# endif
+#endif
+
+#if 0
+/* Get process group ID from the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_getpgroup, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ pid_t *_Restrict_ __pgroup)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_getpgroup, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ pid_t *_Restrict_ __pgroup));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_getpgroup, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ pid_t *_Restrict_ __pgroup)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_getpgroup, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ pid_t *_Restrict_ __pgroup));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_getpgroup);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_getpgroup
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETPGROUP
+_GL_WARN_ON_USE (posix_spawnattr_getpgroup,
+ "posix_spawnattr_getpgroup is unportable - "
+ "use gnulib module posix_spawnattr_getpgroup for portability");
+# endif
+#endif
+
+#if 0
+/* Store process group ID in the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_setpgroup, int,
+ (posix_spawnattr_t *__attr, pid_t __pgroup)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawnattr_setpgroup, int,
+ (posix_spawnattr_t *__attr, pid_t __pgroup));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawnattr_setpgroup, int,
+ (posix_spawnattr_t *__attr, pid_t __pgroup)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_setpgroup, int,
+ (posix_spawnattr_t *__attr, pid_t __pgroup));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_setpgroup);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_setpgroup
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETPGROUP
+_GL_WARN_ON_USE (posix_spawnattr_setpgroup,
+ "posix_spawnattr_setpgroup is unportable - "
+ "use gnulib module posix_spawnattr_setpgroup for portability");
+# endif
+#endif
+
+#if 0
+/* Get scheduling policy from the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_getschedpolicy, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ int *_Restrict_ __schedpolicy)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_getschedpolicy, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ int *_Restrict_ __schedpolicy));
+# else
+# if !0 || POSIX_SPAWN_SETSCHEDULER == 0
+_GL_FUNCDECL_SYS (posix_spawnattr_getschedpolicy, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ int *_Restrict_ __schedpolicy)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_getschedpolicy, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ int *_Restrict_ __schedpolicy));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_getschedpolicy);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_getschedpolicy
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPOLICY
+_GL_WARN_ON_USE (posix_spawnattr_getschedpolicy,
+ "posix_spawnattr_getschedpolicy is unportable - "
+ "use gnulib module posix_spawnattr_getschedpolicy for portability");
+# endif
+#endif
+
+#if 0
+/* Store scheduling policy in the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_setschedpolicy, int,
+ (posix_spawnattr_t *__attr, int __schedpolicy)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawnattr_setschedpolicy, int,
+ (posix_spawnattr_t *__attr, int __schedpolicy));
+# else
+# if !0 || POSIX_SPAWN_SETSCHEDULER == 0
+_GL_FUNCDECL_SYS (posix_spawnattr_setschedpolicy, int,
+ (posix_spawnattr_t *__attr, int __schedpolicy)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_setschedpolicy, int,
+ (posix_spawnattr_t *__attr, int __schedpolicy));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_setschedpolicy);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_setschedpolicy
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPOLICY
+_GL_WARN_ON_USE (posix_spawnattr_setschedpolicy,
+ "posix_spawnattr_setschedpolicy is unportable - "
+ "use gnulib module posix_spawnattr_setschedpolicy for portability");
+# endif
+#endif
+
+#if 0
+/* Get scheduling parameters from the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_getschedparam, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ struct sched_param *_Restrict_ __schedparam)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_getschedparam, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ struct sched_param *_Restrict_ __schedparam));
+# else
+# if !0 || POSIX_SPAWN_SETSCHEDPARAM == 0
+_GL_FUNCDECL_SYS (posix_spawnattr_getschedparam, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ struct sched_param *_Restrict_ __schedparam)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_getschedparam, int,
+ (const posix_spawnattr_t *_Restrict_ __attr,
+ struct sched_param *_Restrict_ __schedparam));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_getschedparam);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_getschedparam
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_GETSCHEDPARAM
+_GL_WARN_ON_USE (posix_spawnattr_getschedparam,
+ "posix_spawnattr_getschedparam is unportable - "
+ "use gnulib module posix_spawnattr_getschedparam for portability");
+# endif
+#endif
+
+#if 0
+/* Store scheduling parameters in the attribute structure. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
+# endif
+_GL_FUNCDECL_RPL (posix_spawnattr_setschedparam, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const struct sched_param *_Restrict_ __schedparam)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawnattr_setschedparam, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const struct sched_param *_Restrict_ __schedparam));
+# else
+# if !0 || POSIX_SPAWN_SETSCHEDPARAM == 0
+_GL_FUNCDECL_SYS (posix_spawnattr_setschedparam, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const struct sched_param *_Restrict_ __schedparam)
+ __THROW _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawnattr_setschedparam, int,
+ (posix_spawnattr_t *_Restrict_ __attr,
+ const struct sched_param *_Restrict_ __schedparam));
+# endif
+_GL_CXXALIASWARN (posix_spawnattr_setschedparam);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawnattr_setschedparam
+# if HAVE_RAW_DECL_POSIX_SPAWNATTR_SETSCHEDPARAM
+_GL_WARN_ON_USE (posix_spawnattr_setschedparam,
+ "posix_spawnattr_setschedparam is unportable - "
+ "use gnulib module posix_spawnattr_setschedparam for portability");
+# endif
+#endif
+
+
+#if 1
+/* Initialize data structure for file attribute for 'spawn' call. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
+# endif
+_GL_FUNCDECL_RPL (posix_spawn_file_actions_init, int,
+ (posix_spawn_file_actions_t *__file_actions)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawn_file_actions_init, int,
+ (posix_spawn_file_actions_t *__file_actions));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawn_file_actions_init, int,
+ (posix_spawn_file_actions_t *__file_actions)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawn_file_actions_init, int,
+ (posix_spawn_file_actions_t *__file_actions));
+# endif
+_GL_CXXALIASWARN (posix_spawn_file_actions_init);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawn_file_actions_init
+# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_INIT
+_GL_WARN_ON_USE (posix_spawn_file_actions_init,
+ "posix_spawn_file_actions_init is unportable - "
+ "use gnulib module posix_spawn_file_actions_init for portability");
+# endif
+#endif
+
+#if 1
+/* Free resources associated with FILE-ACTIONS. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
+# endif
+_GL_FUNCDECL_RPL (posix_spawn_file_actions_destroy, int,
+ (posix_spawn_file_actions_t *__file_actions)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawn_file_actions_destroy, int,
+ (posix_spawn_file_actions_t *__file_actions));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawn_file_actions_destroy, int,
+ (posix_spawn_file_actions_t *__file_actions)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawn_file_actions_destroy, int,
+ (posix_spawn_file_actions_t *__file_actions));
+# endif
+_GL_CXXALIASWARN (posix_spawn_file_actions_destroy);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawn_file_actions_destroy
+# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_DESTROY
+_GL_WARN_ON_USE (posix_spawn_file_actions_destroy,
+ "posix_spawn_file_actions_destroy is unportable - "
+ "use gnulib module posix_spawn_file_actions_destroy for portability");
+# endif
+#endif
+
+#if 1
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+ 'open' for the given file during the 'spawn' call. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
+# endif
+_GL_FUNCDECL_RPL (posix_spawn_file_actions_addopen, int,
+ (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ int __fd,
+ const char *_Restrict_ __path, int __oflag, mode_t __mode)
+ __THROW _GL_ARG_NONNULL ((1, 3)));
+_GL_CXXALIAS_RPL (posix_spawn_file_actions_addopen, int,
+ (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ int __fd,
+ const char *_Restrict_ __path, int __oflag, mode_t __mode));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawn_file_actions_addopen, int,
+ (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ int __fd,
+ const char *_Restrict_ __path, int __oflag, mode_t __mode)
+ __THROW _GL_ARG_NONNULL ((1, 3)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawn_file_actions_addopen, int,
+ (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+ int __fd,
+ const char *_Restrict_ __path, int __oflag, mode_t __mode));
+# endif
+_GL_CXXALIASWARN (posix_spawn_file_actions_addopen);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawn_file_actions_addopen
+# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN
+_GL_WARN_ON_USE (posix_spawn_file_actions_addopen,
+ "posix_spawn_file_actions_addopen is unportable - "
+ "use gnulib module posix_spawn_file_actions_addopen for portability");
+# endif
+#endif
+
+#if 1
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+ 'close' for the given file descriptor during the 'spawn' call. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
+# endif
+_GL_FUNCDECL_RPL (posix_spawn_file_actions_addclose, int,
+ (posix_spawn_file_actions_t *__file_actions, int __fd)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawn_file_actions_addclose, int,
+ (posix_spawn_file_actions_t *__file_actions, int __fd));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawn_file_actions_addclose, int,
+ (posix_spawn_file_actions_t *__file_actions, int __fd)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawn_file_actions_addclose, int,
+ (posix_spawn_file_actions_t *__file_actions, int __fd));
+# endif
+_GL_CXXALIASWARN (posix_spawn_file_actions_addclose);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawn_file_actions_addclose
+# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE
+_GL_WARN_ON_USE (posix_spawn_file_actions_addclose,
+ "posix_spawn_file_actions_addclose is unportable - "
+ "use gnulib module posix_spawn_file_actions_addclose for portability");
+# endif
+#endif
+
+#if 1
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+ 'dup2' for the given file descriptors during the 'spawn' call. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
+# endif
+_GL_FUNCDECL_RPL (posix_spawn_file_actions_adddup2, int,
+ (posix_spawn_file_actions_t *__file_actions,
+ int __fd, int __newfd)
+ __THROW _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (posix_spawn_file_actions_adddup2, int,
+ (posix_spawn_file_actions_t *__file_actions,
+ int __fd, int __newfd));
+# else
+# if !0
+_GL_FUNCDECL_SYS (posix_spawn_file_actions_adddup2, int,
+ (posix_spawn_file_actions_t *__file_actions,
+ int __fd, int __newfd)
+ __THROW _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (posix_spawn_file_actions_adddup2, int,
+ (posix_spawn_file_actions_t *__file_actions,
+ int __fd, int __newfd));
+# endif
+_GL_CXXALIASWARN (posix_spawn_file_actions_adddup2);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawn_file_actions_adddup2
+# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2
+_GL_WARN_ON_USE (posix_spawn_file_actions_adddup2,
+ "posix_spawn_file_actions_adddup2 is unportable - "
+ "use gnulib module posix_spawn_file_actions_adddup2 for portability");
+# endif
+#endif
+
+
+#endif /* _GL_M4_SPAWN_H */
+#endif /* _GL_M4_SPAWN_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/stdbool.h b/contrib/tools/bison/gnulib/platform/win64/stdbool.h
index b898ca1f82..d5715248ac 100644
--- a/contrib/tools/bison/gnulib/platform/win64/stdbool.h
+++ b/contrib/tools/bison/gnulib/platform/win64/stdbool.h
@@ -1,133 +1,133 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_STDBOOL_H
-#define _GL_STDBOOL_H
-
-/* ISO C 99 <stdbool.h> for platforms that lack it. */
-
-/* Usage suggestions:
-
- Programs that use <stdbool.h> should be aware of some limitations
- and standards compliance issues.
-
- Standards compliance:
-
- - <stdbool.h> must be #included before 'bool', 'false', 'true'
- can be used.
-
- - You cannot assume that sizeof (bool) == 1.
-
- - Programs should not undefine the macros bool, true, and false,
- as C99 lists that as an "obsolescent feature".
-
- Limitations of this substitute, when used in a C89 environment:
-
- - <stdbool.h> must be #included before the '_Bool' type can be used.
-
- - You cannot assume that _Bool is a typedef; it might be a macro.
-
- - Bit-fields of type 'bool' are not supported. Portable code
- should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
-
- - In C99, casts and automatic conversions to '_Bool' or 'bool' are
- performed in such a way that every nonzero value gets converted
- to 'true', and zero gets converted to 'false'. This doesn't work
- with this substitute. With this substitute, only the values 0 and 1
- give the expected result when converted to _Bool' or 'bool'.
-
- - C99 allows the use of (_Bool)0.0 in constant expressions, but
- this substitute cannot always provide this property.
-
- Also, it is suggested that programs use 'bool' rather than '_Bool';
- this isn't required, but 'bool' is more common. */
-
-
-/* 7.16. Boolean type and values */
-
-/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
- definitions below, but temporarily we have to #undef them. */
-#if defined __BEOS__ && !defined __HAIKU__
-# include <OS.h> /* defines bool but not _Bool */
-# undef false
-# undef true
-#endif
-
-#ifdef __cplusplus
-# define _Bool bool
-# define bool bool
-#else
-# if defined __BEOS__ && !defined __HAIKU__
- /* A compiler known to have 'bool'. */
- /* If the compiler already has both 'bool' and '_Bool', we can assume they
- are the same types. */
-# if !0
-typedef bool _Bool;
-# endif
-# else
-# if !defined __GNUC__
- /* If 0:
- Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
- the built-in _Bool type is used. See
- http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
- http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
- http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
- Similar bugs are likely with other compilers as well; this file
- wouldn't be used if <stdbool.h> was working.
- So we override the _Bool type.
- If !0:
- Need to define _Bool ourselves. As 'signed char' or as an enum type?
- Use of a typedef, with SunPRO C, leads to a stupid
- "warning: _Bool is a keyword in ISO C99".
- Use of an enum type, with IRIX cc, leads to a stupid
- "warning(1185): enumerated type mixed with another type".
- Even the existence of an enum type, without a typedef,
- "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
- The only benefit of the enum, debuggability, is not important
- with these compilers. So use 'signed char' and no enum. */
-# define _Bool signed char
-# else
- /* With this compiler, trust the _Bool type if the compiler has it. */
-# if !0
- /* For the sake of symbolic names in gdb, define true and false as
- enum constants, not only as macros.
- It is tempting to write
- typedef enum { false = 0, true = 1 } _Bool;
- so that gdb prints values of type 'bool' symbolically. But then
- values of type '_Bool' might promote to 'int' or 'unsigned int'
- (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
- (see ISO C 99 6.3.1.1.(2)). So add a negative value to the
- enum; this ensures that '_Bool' promotes to 'int'. */
-typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
-# endif
-# endif
-# endif
-# define bool _Bool
-#endif
-
-/* The other macros must be usable in preprocessor directives. */
-#ifdef __cplusplus
-# define false false
-# define true true
-#else
-# define false 0
-# define true 1
-#endif
-
-#define __bool_true_false_are_defined 1
-
-#endif /* _GL_STDBOOL_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_STDBOOL_H
+#define _GL_STDBOOL_H
+
+/* ISO C 99 <stdbool.h> for platforms that lack it. */
+
+/* Usage suggestions:
+
+ Programs that use <stdbool.h> should be aware of some limitations
+ and standards compliance issues.
+
+ Standards compliance:
+
+ - <stdbool.h> must be #included before 'bool', 'false', 'true'
+ can be used.
+
+ - You cannot assume that sizeof (bool) == 1.
+
+ - Programs should not undefine the macros bool, true, and false,
+ as C99 lists that as an "obsolescent feature".
+
+ Limitations of this substitute, when used in a C89 environment:
+
+ - <stdbool.h> must be #included before the '_Bool' type can be used.
+
+ - You cannot assume that _Bool is a typedef; it might be a macro.
+
+ - Bit-fields of type 'bool' are not supported. Portable code
+ should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
+
+ - In C99, casts and automatic conversions to '_Bool' or 'bool' are
+ performed in such a way that every nonzero value gets converted
+ to 'true', and zero gets converted to 'false'. This doesn't work
+ with this substitute. With this substitute, only the values 0 and 1
+ give the expected result when converted to _Bool' or 'bool'.
+
+ - C99 allows the use of (_Bool)0.0 in constant expressions, but
+ this substitute cannot always provide this property.
+
+ Also, it is suggested that programs use 'bool' rather than '_Bool';
+ this isn't required, but 'bool' is more common. */
+
+
+/* 7.16. Boolean type and values */
+
+/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
+ definitions below, but temporarily we have to #undef them. */
+#if defined __BEOS__ && !defined __HAIKU__
+# include <OS.h> /* defines bool but not _Bool */
+# undef false
+# undef true
+#endif
+
+#ifdef __cplusplus
+# define _Bool bool
+# define bool bool
+#else
+# if defined __BEOS__ && !defined __HAIKU__
+ /* A compiler known to have 'bool'. */
+ /* If the compiler already has both 'bool' and '_Bool', we can assume they
+ are the same types. */
+# if !0
+typedef bool _Bool;
+# endif
+# else
+# if !defined __GNUC__
+ /* If 0:
+ Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
+ the built-in _Bool type is used. See
+ http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
+ http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
+ http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
+ Similar bugs are likely with other compilers as well; this file
+ wouldn't be used if <stdbool.h> was working.
+ So we override the _Bool type.
+ If !0:
+ Need to define _Bool ourselves. As 'signed char' or as an enum type?
+ Use of a typedef, with SunPRO C, leads to a stupid
+ "warning: _Bool is a keyword in ISO C99".
+ Use of an enum type, with IRIX cc, leads to a stupid
+ "warning(1185): enumerated type mixed with another type".
+ Even the existence of an enum type, without a typedef,
+ "Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
+ The only benefit of the enum, debuggability, is not important
+ with these compilers. So use 'signed char' and no enum. */
+# define _Bool signed char
+# else
+ /* With this compiler, trust the _Bool type if the compiler has it. */
+# if !0
+ /* For the sake of symbolic names in gdb, define true and false as
+ enum constants, not only as macros.
+ It is tempting to write
+ typedef enum { false = 0, true = 1 } _Bool;
+ so that gdb prints values of type 'bool' symbolically. But then
+ values of type '_Bool' might promote to 'int' or 'unsigned int'
+ (see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
+ (see ISO C 99 6.3.1.1.(2)). So add a negative value to the
+ enum; this ensures that '_Bool' promotes to 'int'. */
+typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
+# endif
+# endif
+# endif
+# define bool _Bool
+#endif
+
+/* The other macros must be usable in preprocessor directives. */
+#ifdef __cplusplus
+# define false false
+# define true true
+#else
+# define false 0
+# define true 1
+#endif
+
+#define __bool_true_false_are_defined 1
+
+#endif /* _GL_STDBOOL_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled b/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled
index 35ff0479f4..20d3ba7688 100644
--- a/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled
+++ b/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled
@@ -1,40 +1,40 @@
-// ISO C9x compliant stdint.h for Microsoft Visual Studio
-// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
-//
-// Copyright (c) 2006-2013 Alexander Chemeris
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-//
-// 3. Neither the name of the product nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef _MSC_VER // [
-#error "Use this header only with Microsoft Visual C++ compilers!"
-#endif // _MSC_VER ]
-
-
+// ISO C9x compliant stdint.h for Microsoft Visual Studio
+// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
+//
+// Copyright (c) 2006-2013 Alexander Chemeris
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the product nor the names of its contributors may
+// be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MSC_VER // [
+#error "Use this header only with Microsoft Visual C++ compilers!"
+#endif // _MSC_VER ]
+
+
#ifndef _MSC_STDINT_H_
#if _MSC_VER >= 1600
@@ -43,223 +43,223 @@
# else
# include_next <stdint.h>
# endif
-#endif
-
+#endif
+
#ifndef _MSC_STDINT_H_
#define _MSC_STDINT_H_
-
+
#if _MSC_VER < 1600
-#include <limits.h>
-
-// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
-// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
-// or compiler give many errors like this:
-// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
-#ifdef __cplusplus
-extern "C" {
-#endif
-# include <wchar.h>
-#ifdef __cplusplus
-}
-#endif
-
-// Define _W64 macros to mark types changing their size, like intptr_t.
-#ifndef _W64
-# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
-# define _W64 __w64
-# else
-# define _W64
-# endif
-#endif
-
-
-// 7.18.1 Integer types
-
-// 7.18.1.1 Exact-width integer types
-
-// Visual Studio 6 and Embedded Visual C++ 4 doesn't
-// realize that, e.g. char has the same size as __int8
-// so we give up on __intX for them.
-#if (_MSC_VER < 1300)
- typedef signed char int8_t;
- typedef signed short int16_t;
- typedef signed int int32_t;
- typedef unsigned char uint8_t;
- typedef unsigned short uint16_t;
- typedef unsigned int uint32_t;
-#else
- typedef signed __int8 int8_t;
- typedef signed __int16 int16_t;
- typedef signed __int32 int32_t;
- typedef unsigned __int8 uint8_t;
- typedef unsigned __int16 uint16_t;
- typedef unsigned __int32 uint32_t;
-#endif
-typedef signed __int64 int64_t;
-typedef unsigned __int64 uint64_t;
-
-
-// 7.18.1.2 Minimum-width integer types
-typedef int8_t int_least8_t;
-typedef int16_t int_least16_t;
-typedef int32_t int_least32_t;
-typedef int64_t int_least64_t;
-typedef uint8_t uint_least8_t;
-typedef uint16_t uint_least16_t;
-typedef uint32_t uint_least32_t;
-typedef uint64_t uint_least64_t;
-
-// 7.18.1.3 Fastest minimum-width integer types
-typedef int8_t int_fast8_t;
-typedef int16_t int_fast16_t;
-typedef int32_t int_fast32_t;
-typedef int64_t int_fast64_t;
-typedef uint8_t uint_fast8_t;
-typedef uint16_t uint_fast16_t;
-typedef uint32_t uint_fast32_t;
-typedef uint64_t uint_fast64_t;
-
-// 7.18.1.4 Integer types capable of holding object pointers
-#ifdef _WIN64 // [
- typedef signed __int64 intptr_t;
- typedef unsigned __int64 uintptr_t;
-#else // _WIN64 ][
- typedef _W64 signed int intptr_t;
- typedef _W64 unsigned int uintptr_t;
-#endif // _WIN64 ]
-
-// 7.18.1.5 Greatest-width integer types
-typedef int64_t intmax_t;
-typedef uint64_t uintmax_t;
-
-
-// 7.18.2 Limits of specified-width integer types
-
-#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
-
-// 7.18.2.1 Limits of exact-width integer types
-#define INT8_MIN ((int8_t)_I8_MIN)
-#define INT8_MAX _I8_MAX
-#define INT16_MIN ((int16_t)_I16_MIN)
-#define INT16_MAX _I16_MAX
-#define INT32_MIN ((int32_t)_I32_MIN)
-#define INT32_MAX _I32_MAX
-#define INT64_MIN ((int64_t)_I64_MIN)
-#define INT64_MAX _I64_MAX
-#define UINT8_MAX _UI8_MAX
-#define UINT16_MAX _UI16_MAX
-#define UINT32_MAX _UI32_MAX
-#define UINT64_MAX _UI64_MAX
-
-// 7.18.2.2 Limits of minimum-width integer types
-#define INT_LEAST8_MIN INT8_MIN
-#define INT_LEAST8_MAX INT8_MAX
-#define INT_LEAST16_MIN INT16_MIN
-#define INT_LEAST16_MAX INT16_MAX
-#define INT_LEAST32_MIN INT32_MIN
-#define INT_LEAST32_MAX INT32_MAX
-#define INT_LEAST64_MIN INT64_MIN
-#define INT_LEAST64_MAX INT64_MAX
-#define UINT_LEAST8_MAX UINT8_MAX
-#define UINT_LEAST16_MAX UINT16_MAX
-#define UINT_LEAST32_MAX UINT32_MAX
-#define UINT_LEAST64_MAX UINT64_MAX
-
-// 7.18.2.3 Limits of fastest minimum-width integer types
-#define INT_FAST8_MIN INT8_MIN
-#define INT_FAST8_MAX INT8_MAX
-#define INT_FAST16_MIN INT16_MIN
-#define INT_FAST16_MAX INT16_MAX
-#define INT_FAST32_MIN INT32_MIN
-#define INT_FAST32_MAX INT32_MAX
-#define INT_FAST64_MIN INT64_MIN
-#define INT_FAST64_MAX INT64_MAX
-#define UINT_FAST8_MAX UINT8_MAX
-#define UINT_FAST16_MAX UINT16_MAX
-#define UINT_FAST32_MAX UINT32_MAX
-#define UINT_FAST64_MAX UINT64_MAX
-
-// 7.18.2.4 Limits of integer types capable of holding object pointers
-#ifdef _WIN64 // [
-# define INTPTR_MIN INT64_MIN
-# define INTPTR_MAX INT64_MAX
-# define UINTPTR_MAX UINT64_MAX
-#else // _WIN64 ][
-# define INTPTR_MIN INT32_MIN
-# define INTPTR_MAX INT32_MAX
-# define UINTPTR_MAX UINT32_MAX
-#endif // _WIN64 ]
-
-// 7.18.2.5 Limits of greatest-width integer types
-#define INTMAX_MIN INT64_MIN
-#define INTMAX_MAX INT64_MAX
-#define UINTMAX_MAX UINT64_MAX
-
-// 7.18.3 Limits of other integer types
-
-#ifdef _WIN64 // [
-# define PTRDIFF_MIN _I64_MIN
-# define PTRDIFF_MAX _I64_MAX
-#else // _WIN64 ][
-# define PTRDIFF_MIN _I32_MIN
-# define PTRDIFF_MAX _I32_MAX
-#endif // _WIN64 ]
-
-#define SIG_ATOMIC_MIN INT_MIN
-#define SIG_ATOMIC_MAX INT_MAX
-
-#ifndef SIZE_MAX // [
-# ifdef _WIN64 // [
-# define SIZE_MAX _UI64_MAX
-# else // _WIN64 ][
-# define SIZE_MAX _UI32_MAX
-# endif // _WIN64 ]
-#endif // SIZE_MAX ]
-
-// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
-#ifndef WCHAR_MIN // [
-# define WCHAR_MIN 0
-#endif // WCHAR_MIN ]
-#ifndef WCHAR_MAX // [
-# define WCHAR_MAX _UI16_MAX
-#endif // WCHAR_MAX ]
-
-#define WINT_MIN 0
-#define WINT_MAX _UI16_MAX
-
-#endif // __STDC_LIMIT_MACROS ]
-
-
-// 7.18.4 Limits of other integer types
-
-#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
-
-// 7.18.4.1 Macros for minimum-width integer constants
-
-#define INT8_C(val) val##i8
-#define INT16_C(val) val##i16
-#define INT32_C(val) val##i32
-#define INT64_C(val) val##i64
-
-#define UINT8_C(val) val##ui8
-#define UINT16_C(val) val##ui16
-#define UINT32_C(val) val##ui32
-#define UINT64_C(val) val##ui64
-
-// 7.18.4.2 Macros for greatest-width integer constants
-// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
-// Check out Issue 9 for the details.
-#ifndef INTMAX_C // [
-# define INTMAX_C INT64_C
-#endif // INTMAX_C ]
-#ifndef UINTMAX_C // [
-# define UINTMAX_C UINT64_C
-#endif // UINTMAX_C ]
-
-#endif // __STDC_CONSTANT_MACROS ]
-
+#include <limits.h>
+
+// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
+// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
+// or compiler give many errors like this:
+// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
+#ifdef __cplusplus
+extern "C" {
+#endif
+# include <wchar.h>
+#ifdef __cplusplus
+}
+#endif
+
+// Define _W64 macros to mark types changing their size, like intptr_t.
+#ifndef _W64
+# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
+# define _W64 __w64
+# else
+# define _W64
+# endif
+#endif
+
+
+// 7.18.1 Integer types
+
+// 7.18.1.1 Exact-width integer types
+
+// Visual Studio 6 and Embedded Visual C++ 4 doesn't
+// realize that, e.g. char has the same size as __int8
+// so we give up on __intX for them.
+#if (_MSC_VER < 1300)
+ typedef signed char int8_t;
+ typedef signed short int16_t;
+ typedef signed int int32_t;
+ typedef unsigned char uint8_t;
+ typedef unsigned short uint16_t;
+ typedef unsigned int uint32_t;
+#else
+ typedef signed __int8 int8_t;
+ typedef signed __int16 int16_t;
+ typedef signed __int32 int32_t;
+ typedef unsigned __int8 uint8_t;
+ typedef unsigned __int16 uint16_t;
+ typedef unsigned __int32 uint32_t;
+#endif
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+
+
+// 7.18.1.2 Minimum-width integer types
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+typedef int64_t int_least64_t;
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+typedef uint64_t uint_least64_t;
+
+// 7.18.1.3 Fastest minimum-width integer types
+typedef int8_t int_fast8_t;
+typedef int16_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef int64_t int_fast64_t;
+typedef uint8_t uint_fast8_t;
+typedef uint16_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+typedef uint64_t uint_fast64_t;
+
+// 7.18.1.4 Integer types capable of holding object pointers
+#ifdef _WIN64 // [
+ typedef signed __int64 intptr_t;
+ typedef unsigned __int64 uintptr_t;
+#else // _WIN64 ][
+ typedef _W64 signed int intptr_t;
+ typedef _W64 unsigned int uintptr_t;
+#endif // _WIN64 ]
+
+// 7.18.1.5 Greatest-width integer types
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+
+
+// 7.18.2 Limits of specified-width integer types
+
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
+
+// 7.18.2.1 Limits of exact-width integer types
+#define INT8_MIN ((int8_t)_I8_MIN)
+#define INT8_MAX _I8_MAX
+#define INT16_MIN ((int16_t)_I16_MIN)
+#define INT16_MAX _I16_MAX
+#define INT32_MIN ((int32_t)_I32_MIN)
+#define INT32_MAX _I32_MAX
+#define INT64_MIN ((int64_t)_I64_MIN)
+#define INT64_MAX _I64_MAX
+#define UINT8_MAX _UI8_MAX
+#define UINT16_MAX _UI16_MAX
+#define UINT32_MAX _UI32_MAX
+#define UINT64_MAX _UI64_MAX
+
+// 7.18.2.2 Limits of minimum-width integer types
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+// 7.18.2.3 Limits of fastest minimum-width integer types
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST8_MAX INT8_MAX
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST16_MAX INT16_MAX
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST8_MAX UINT8_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+// 7.18.2.4 Limits of integer types capable of holding object pointers
+#ifdef _WIN64 // [
+# define INTPTR_MIN INT64_MIN
+# define INTPTR_MAX INT64_MAX
+# define UINTPTR_MAX UINT64_MAX
+#else // _WIN64 ][
+# define INTPTR_MIN INT32_MIN
+# define INTPTR_MAX INT32_MAX
+# define UINTPTR_MAX UINT32_MAX
+#endif // _WIN64 ]
+
+// 7.18.2.5 Limits of greatest-width integer types
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+// 7.18.3 Limits of other integer types
+
+#ifdef _WIN64 // [
+# define PTRDIFF_MIN _I64_MIN
+# define PTRDIFF_MAX _I64_MAX
+#else // _WIN64 ][
+# define PTRDIFF_MIN _I32_MIN
+# define PTRDIFF_MAX _I32_MAX
+#endif // _WIN64 ]
+
+#define SIG_ATOMIC_MIN INT_MIN
+#define SIG_ATOMIC_MAX INT_MAX
+
+#ifndef SIZE_MAX // [
+# ifdef _WIN64 // [
+# define SIZE_MAX _UI64_MAX
+# else // _WIN64 ][
+# define SIZE_MAX _UI32_MAX
+# endif // _WIN64 ]
+#endif // SIZE_MAX ]
+
+// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
+#ifndef WCHAR_MIN // [
+# define WCHAR_MIN 0
+#endif // WCHAR_MIN ]
+#ifndef WCHAR_MAX // [
+# define WCHAR_MAX _UI16_MAX
+#endif // WCHAR_MAX ]
+
+#define WINT_MIN 0
+#define WINT_MAX _UI16_MAX
+
+#endif // __STDC_LIMIT_MACROS ]
+
+
+// 7.18.4 Limits of other integer types
+
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
+
+// 7.18.4.1 Macros for minimum-width integer constants
+
+#define INT8_C(val) val##i8
+#define INT16_C(val) val##i16
+#define INT32_C(val) val##i32
+#define INT64_C(val) val##i64
+
+#define UINT8_C(val) val##ui8
+#define UINT16_C(val) val##ui16
+#define UINT32_C(val) val##ui32
+#define UINT64_C(val) val##ui64
+
+// 7.18.4.2 Macros for greatest-width integer constants
+// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
+// Check out Issue 9 for the details.
+#ifndef INTMAX_C // [
+# define INTMAX_C INT64_C
+#endif // INTMAX_C ]
+#ifndef UINTMAX_C // [
+# define UINTMAX_C UINT64_C
+#endif // UINTMAX_C ]
+
+#endif // __STDC_CONSTANT_MACROS ]
+
#endif // _MSC_VER < 1600 ]
-
-#endif // _MSC_STDINT_H_ ]
+
+#endif // _MSC_STDINT_H_ ]
#endif // _MSC_STDINT_H_ ]
diff --git a/contrib/tools/bison/gnulib/platform/win64/sys/stat.h b/contrib/tools/bison/gnulib/platform/win64/sys/stat.h
index 429d3886dc..7b62f88fc6 100644
--- a/contrib/tools/bison/gnulib/platform/win64/sys/stat.h
+++ b/contrib/tools/bison/gnulib/platform/win64/sys/stat.h
@@ -1,1052 +1,1052 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Provide a more complete sys/stat header file.
- Copyright (C) 2005-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
-
-/* This file is supposed to be used on platforms where <sys/stat.h> is
- incomplete. It is intended to provide definitions and prototypes
- needed by an application. Start with what the system provides. */
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-#if defined __need_system_sys_stat_h
-/* Special invocation convention. */
-
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Provide a more complete sys/stat header file.
+ Copyright (C) 2005-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
+
+/* This file is supposed to be used on platforms where <sys/stat.h> is
+ incomplete. It is intended to provide definitions and prototypes
+ needed by an application. Start with what the system provides. */
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+#if defined __need_system_sys_stat_h
+/* Special invocation convention. */
+
#if _MSC_VER >= 1900
#include <../ucrt/sys/stat.h>
#else
#include <../include/sys/stat.h>
#endif
-
-#else
-/* Normal invocation convention. */
-
-#ifndef _GL_M4_SYS_STAT_H
-
-/* Get nlink_t.
- May also define off_t to a 64-bit type on native Windows. */
-#include <sys/types.h>
-
-/* Get struct timespec. */
-#include <time.h>
-
-/* The include_next requires a split double-inclusion guard. */
+
+#else
+/* Normal invocation convention. */
+
+#ifndef _GL_M4_SYS_STAT_H
+
+/* Get nlink_t.
+ May also define off_t to a 64-bit type on native Windows. */
+#include <sys/types.h>
+
+/* Get struct timespec. */
+#include <time.h>
+
+/* The include_next requires a split double-inclusion guard. */
#if _MSC_VER >= 1900
#include <../ucrt/sys/stat.h>
#else
#include <../include/sys/stat.h>
#endif
-
-#ifndef _GL_M4_SYS_STAT_H
-#define _GL_M4_SYS_STAT_H
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
- headers that may declare mkdir(). Native Windows platforms declare mkdir
- in <io.h> and/or <direct.h>, not in <unistd.h>. */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-# include <io.h> /* mingw32, mingw64 */
-# include <direct.h> /* mingw64, MSVC 9 */
-#endif
-
-/* Native Windows platforms declare umask() in <io.h>. */
-#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
-# include <io.h>
-#endif
-
-/* Large File Support on native Windows. */
-#if 1
-# define stat _stati64
-#endif
-
-#ifndef S_IFIFO
-# ifdef _S_IFIFO
-# define S_IFIFO _S_IFIFO
-# endif
-#endif
-
-#ifndef S_IFMT
-# define S_IFMT 0170000
-#endif
-
-#if STAT_MACROS_BROKEN
-# undef S_ISBLK
-# undef S_ISCHR
-# undef S_ISDIR
-# undef S_ISFIFO
-# undef S_ISLNK
-# undef S_ISNAM
-# undef S_ISMPB
-# undef S_ISMPC
-# undef S_ISNWK
-# undef S_ISREG
-# undef S_ISSOCK
-#endif
-
-#ifndef S_ISBLK
-# ifdef S_IFBLK
-# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
-# else
-# define S_ISBLK(m) 0
-# endif
-#endif
-
-#ifndef S_ISCHR
-# ifdef S_IFCHR
-# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
-# else
-# define S_ISCHR(m) 0
-# endif
-#endif
-
-#ifndef S_ISDIR
-# ifdef S_IFDIR
-# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
-# else
-# define S_ISDIR(m) 0
-# endif
-#endif
-
-#ifndef S_ISDOOR /* Solaris 2.5 and up */
-# define S_ISDOOR(m) 0
-#endif
-
-#ifndef S_ISFIFO
-# ifdef S_IFIFO
-# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
-# else
-# define S_ISFIFO(m) 0
-# endif
-#endif
-
-#ifndef S_ISLNK
-# ifdef S_IFLNK
-# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
-# else
-# define S_ISLNK(m) 0
-# endif
-#endif
-
-#ifndef S_ISMPB /* V7 */
-# ifdef S_IFMPB
-# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
-# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
-# else
-# define S_ISMPB(m) 0
-# define S_ISMPC(m) 0
-# endif
-#endif
-
-#ifndef S_ISMPX /* AIX */
-# define S_ISMPX(m) 0
-#endif
-
-#ifndef S_ISNAM /* Xenix */
-# ifdef S_IFNAM
-# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
-# else
-# define S_ISNAM(m) 0
-# endif
-#endif
-
-#ifndef S_ISNWK /* HP/UX */
-# ifdef S_IFNWK
-# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
-# else
-# define S_ISNWK(m) 0
-# endif
-#endif
-
-#ifndef S_ISPORT /* Solaris 10 and up */
-# define S_ISPORT(m) 0
-#endif
-
-#ifndef S_ISREG
-# ifdef S_IFREG
-# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
-# else
-# define S_ISREG(m) 0
-# endif
-#endif
-
-#ifndef S_ISSOCK
-# ifdef S_IFSOCK
-# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
-# else
-# define S_ISSOCK(m) 0
-# endif
-#endif
-
-
-#ifndef S_TYPEISMQ
-# define S_TYPEISMQ(p) 0
-#endif
-
-#ifndef S_TYPEISTMO
-# define S_TYPEISTMO(p) 0
-#endif
-
-
-#ifndef S_TYPEISSEM
-# ifdef S_INSEM
-# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
-# else
-# define S_TYPEISSEM(p) 0
-# endif
-#endif
-
-#ifndef S_TYPEISSHM
-# ifdef S_INSHD
-# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
-# else
-# define S_TYPEISSHM(p) 0
-# endif
-#endif
-
-/* high performance ("contiguous data") */
-#ifndef S_ISCTG
-# define S_ISCTG(p) 0
-#endif
-
-/* Cray DMF (data migration facility): off line, with data */
-#ifndef S_ISOFD
-# define S_ISOFD(p) 0
-#endif
-
-/* Cray DMF (data migration facility): off line, with no data */
-#ifndef S_ISOFL
-# define S_ISOFL(p) 0
-#endif
-
-/* 4.4BSD whiteout */
-#ifndef S_ISWHT
-# define S_ISWHT(m) 0
-#endif
-
-/* If any of the following are undefined,
- define them to their de facto standard values. */
-#if !S_ISUID
-# define S_ISUID 04000
-#endif
-#if !S_ISGID
-# define S_ISGID 02000
-#endif
-
-/* S_ISVTX is a common extension to POSIX. */
-#ifndef S_ISVTX
-# define S_ISVTX 01000
-#endif
-
-#if !S_IRUSR && S_IREAD
-# define S_IRUSR S_IREAD
-#endif
-#if !S_IRUSR
-# define S_IRUSR 00400
-#endif
-#if !S_IRGRP
-# define S_IRGRP (S_IRUSR >> 3)
-#endif
-#if !S_IROTH
-# define S_IROTH (S_IRUSR >> 6)
-#endif
-
-#if !S_IWUSR && S_IWRITE
-# define S_IWUSR S_IWRITE
-#endif
-#if !S_IWUSR
-# define S_IWUSR 00200
-#endif
-#if !S_IWGRP
-# define S_IWGRP (S_IWUSR >> 3)
-#endif
-#if !S_IWOTH
-# define S_IWOTH (S_IWUSR >> 6)
-#endif
-
-#if !S_IXUSR && S_IEXEC
-# define S_IXUSR S_IEXEC
-#endif
-#if !S_IXUSR
-# define S_IXUSR 00100
-#endif
-#if !S_IXGRP
-# define S_IXGRP (S_IXUSR >> 3)
-#endif
-#if !S_IXOTH
-# define S_IXOTH (S_IXUSR >> 6)
-#endif
-
-#if !S_IRWXU
-# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
-#endif
-#if !S_IRWXG
-# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
-#endif
-#if !S_IRWXO
-# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
-#endif
-
-/* S_IXUGO is a common extension to POSIX. */
-#if !S_IXUGO
-# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
-#endif
-
-#ifndef S_IRWXUGO
-# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
-#endif
-
-/* Macros for futimens and utimensat. */
-#ifndef UTIME_NOW
-# define UTIME_NOW (-1)
-# define UTIME_OMIT (-2)
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (fchmodat, int,
- (int fd, char const *file, mode_t mode, int flag)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (fchmodat, int,
- (int fd, char const *file, mode_t mode, int flag));
-_GL_CXXALIASWARN (fchmodat);
-#elif defined GNULIB_POSIXCHECK
-# undef fchmodat
-# if HAVE_RAW_DECL_FCHMODAT
-_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
- "use gnulib module openat for portability");
-# endif
-#endif
-
-
-#if 1
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fstat
-# define fstat rpl_fstat
-# endif
-_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
-# else
-_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
-# endif
-_GL_CXXALIASWARN (fstat);
-#elif 1
-/* Above, we define stat to _stati64. */
-# define fstat _fstati64
-#elif defined GNULIB_POSIXCHECK
-# undef fstat
-# if HAVE_RAW_DECL_FSTAT
-_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
- "use gnulib module fstat for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fstatat
-# define fstatat rpl_fstatat
-# endif
-_GL_FUNCDECL_RPL (fstatat, int,
- (int fd, char const *name, struct stat *st, int flags)
- _GL_ARG_NONNULL ((2, 3)));
-_GL_CXXALIAS_RPL (fstatat, int,
- (int fd, char const *name, struct stat *st, int flags));
-# else
-# if !1
-_GL_FUNCDECL_SYS (fstatat, int,
- (int fd, char const *name, struct stat *st, int flags)
- _GL_ARG_NONNULL ((2, 3)));
-# endif
-_GL_CXXALIAS_SYS (fstatat, int,
- (int fd, char const *name, struct stat *st, int flags));
-# endif
-_GL_CXXALIASWARN (fstatat);
-#elif defined GNULIB_POSIXCHECK
-# undef fstatat
-# if HAVE_RAW_DECL_FSTATAT
-_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
- "use gnulib module openat for portability");
-# endif
-#endif
-
-
-#if 0
-/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
- implementation relies on futimesat, which on Solaris 10 makes an invocation
- to futimens that is meant to invoke the libc's futimens(), not gnulib's
- futimens(). */
-# if 0 || (!1 && defined __sun)
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef futimens
-# define futimens rpl_futimens
-# endif
-_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
-_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
-# else
-# if !1
-_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
-# endif
-_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
-# endif
-# if 1
-_GL_CXXALIASWARN (futimens);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef futimens
-# if HAVE_RAW_DECL_FUTIMENS
-_GL_WARN_ON_USE (futimens, "futimens is not portable - "
- "use gnulib module futimens for portability");
-# endif
-#endif
-
-
-#if 0
-/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
- denotes a symbolic link. */
-# if !1
-/* The lchmod replacement follows symbolic links. Callers should take
- this into account; lchmod should be applied only to arguments that
- are known to not be symbolic links. On hosts that lack lchmod,
- this can lead to race conditions between the check and the
- invocation of lchmod, but we know of no workarounds that are
- reliable in general. You might try requesting support for lchmod
- from your operating system supplier. */
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define lchmod chmod
-# endif
-/* Need to cast, because on mingw, the second parameter of chmod is
- int mode. */
-_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
- (const char *filename, mode_t mode));
-# else
-# if 0 /* assume already declared */
-_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
-# endif
-# if 1
-_GL_CXXALIASWARN (lchmod);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef lchmod
-# if HAVE_RAW_DECL_LCHMOD
-_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
- "use gnulib module lchmod for portability");
-# endif
-#endif
-
-
-#if 1
-# if ! 0
-/* mingw does not support symlinks, therefore it does not have lstat. But
- without links, stat does just fine. */
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define lstat stat
-# endif
-_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
-# elif 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef lstat
-# define lstat rpl_lstat
-# endif
-_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
- _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
-# else
-_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
-# endif
-# if 0
-_GL_CXXALIASWARN (lstat);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef lstat
-# if HAVE_RAW_DECL_LSTAT
-_GL_WARN_ON_USE (lstat, "lstat is unportable - "
- "use gnulib module lstat for portability");
-# endif
-#endif
-
-
-#if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef mkdir
-# define mkdir rpl_mkdir
-# endif
-_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
-#else
-/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
- Additionally, it declares _mkdir (and depending on compile flags, an
- alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
- which are included above. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-# if !GNULIB_defined_rpl_mkdir
-static int
-rpl_mkdir (char const *name, mode_t mode)
-{
- return _mkdir (name);
-}
-# define GNULIB_defined_rpl_mkdir 1
-# endif
-
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define mkdir rpl_mkdir
-# endif
-_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
-# else
-_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
-# endif
-#endif
-_GL_CXXALIASWARN (mkdir);
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
-_GL_CXXALIASWARN (mkdirat);
-#elif defined GNULIB_POSIXCHECK
-# undef mkdirat
-# if HAVE_RAW_DECL_MKDIRAT
-_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
- "use gnulib module openat for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef mkfifo
-# define mkfifo rpl_mkfifo
-# endif
-_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
-# else
-# if !1
-_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
-# endif
-_GL_CXXALIASWARN (mkfifo);
-#elif defined GNULIB_POSIXCHECK
-# undef mkfifo
-# if HAVE_RAW_DECL_MKFIFO
-_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
- "use gnulib module mkfifo for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
-_GL_CXXALIASWARN (mkfifoat);
-#elif defined GNULIB_POSIXCHECK
-# undef mkfifoat
-# if HAVE_RAW_DECL_MKFIFOAT
-_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
- "use gnulib module mkfifoat for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef mknod
-# define mknod rpl_mknod
-# endif
-_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
-# else
-# if !1
-_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
- _GL_ARG_NONNULL ((1)));
-# endif
-/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
-_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
-# endif
-_GL_CXXALIASWARN (mknod);
-#elif defined GNULIB_POSIXCHECK
-# undef mknod
-# if HAVE_RAW_DECL_MKNOD
-_GL_WARN_ON_USE (mknod, "mknod is not portable - "
- "use gnulib module mknod for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (mknodat, int,
- (int fd, char const *file, mode_t mode, dev_t dev)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (mknodat, int,
- (int fd, char const *file, mode_t mode, dev_t dev));
-_GL_CXXALIASWARN (mknodat);
-#elif defined GNULIB_POSIXCHECK
-# undef mknodat
-# if HAVE_RAW_DECL_MKNODAT
-_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
- "use gnulib module mkfifoat for portability");
-# endif
-#endif
-
-
-#if 1
-# if 1
-/* We can't use the object-like #define stat rpl_stat, because of
- struct stat. This means that rpl_stat will not be used if the user
- does (stat)(a,b). Oh well. */
-# if defined _AIX && defined stat && defined _LARGE_FILES
- /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
- so we have to replace stat64() instead of stat(). */
-# undef stat64
-# define stat64(name, st) rpl_stat (name, st)
-# elif 1
- /* Above, we define stat to _stati64. */
-# if defined __MINGW32__ && defined _stati64
-# ifndef _USE_32BIT_TIME_T
- /* The system headers define _stati64 to _stat64. */
-# undef _stat64
-# define _stat64(name, st) rpl_stat (name, st)
-# endif
-# elif defined _MSC_VER && defined _stati64
-# ifdef _USE_32BIT_TIME_T
- /* The system headers define _stati64 to _stat32i64. */
-# undef _stat32i64
-# define _stat32i64(name, st) rpl_stat (name, st)
-# else
- /* The system headers define _stati64 to _stat64. */
-# undef _stat64
-# define _stat64(name, st) rpl_stat (name, st)
-# endif
-# else
-# undef _stati64
-# define _stati64(name, st) rpl_stat (name, st)
-# endif
-# elif defined __MINGW32__ && defined stat
-# ifdef _USE_32BIT_TIME_T
- /* The system headers define stat to _stat32i64. */
-# undef _stat32i64
-# define _stat32i64(name, st) rpl_stat (name, st)
-# else
- /* The system headers define stat to _stat64. */
-# undef _stat64
-# define _stat64(name, st) rpl_stat (name, st)
-# endif
-# elif defined _MSC_VER && defined stat
-# ifdef _USE_32BIT_TIME_T
- /* The system headers define stat to _stat32. */
-# undef _stat32
-# define _stat32(name, st) rpl_stat (name, st)
-# else
- /* The system headers define stat to _stat64i32. */
-# undef _stat64i32
-# define _stat64i32(name, st) rpl_stat (name, st)
-# endif
-# else /* !(_AIX ||__MINGW32__ || _MSC_VER) */
-# undef stat
-# define stat(name, st) rpl_stat (name, st)
-# endif /* !_LARGE_FILES */
-_GL_EXTERN_C int stat (const char *name, struct stat *buf)
- _GL_ARG_NONNULL ((1, 2));
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef stat
-# if HAVE_RAW_DECL_STAT
-_GL_WARN_ON_USE (stat, "stat is unportable - "
- "use gnulib module stat for portability");
-# endif
-#endif
-
-
-#if 0
-/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
- implementation relies on futimesat, which on Solaris 10 makes an invocation
- to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
- utimensat(). */
-# if 0 || (!1 && defined __sun)
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef utimensat
-# define utimensat rpl_utimensat
-# endif
-_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
- struct timespec const times[2], int flag)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
- struct timespec const times[2], int flag));
-# else
-# if !1
-_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
- struct timespec const times[2], int flag)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
- struct timespec const times[2], int flag));
-# endif
-# if 1
-_GL_CXXALIASWARN (utimensat);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef utimensat
-# if HAVE_RAW_DECL_UTIMENSAT
-_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
- "use gnulib module utimensat for portability");
-# endif
-#endif
-
-
-#endif /* _GL_M4_SYS_STAT_H */
-#endif /* _GL_M4_SYS_STAT_H */
-#endif
+
+#ifndef _GL_M4_SYS_STAT_H
+#define _GL_M4_SYS_STAT_H
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
+ headers that may declare mkdir(). Native Windows platforms declare mkdir
+ in <io.h> and/or <direct.h>, not in <unistd.h>. */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# include <io.h> /* mingw32, mingw64 */
+# include <direct.h> /* mingw64, MSVC 9 */
+#endif
+
+/* Native Windows platforms declare umask() in <io.h>. */
+#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+# include <io.h>
+#endif
+
+/* Large File Support on native Windows. */
+#if 1
+# define stat _stati64
+#endif
+
+#ifndef S_IFIFO
+# ifdef _S_IFIFO
+# define S_IFIFO _S_IFIFO
+# endif
+#endif
+
+#ifndef S_IFMT
+# define S_IFMT 0170000
+#endif
+
+#if STAT_MACROS_BROKEN
+# undef S_ISBLK
+# undef S_ISCHR
+# undef S_ISDIR
+# undef S_ISFIFO
+# undef S_ISLNK
+# undef S_ISNAM
+# undef S_ISMPB
+# undef S_ISMPC
+# undef S_ISNWK
+# undef S_ISREG
+# undef S_ISSOCK
+#endif
+
+#ifndef S_ISBLK
+# ifdef S_IFBLK
+# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+# else
+# define S_ISBLK(m) 0
+# endif
+#endif
+
+#ifndef S_ISCHR
+# ifdef S_IFCHR
+# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+# else
+# define S_ISCHR(m) 0
+# endif
+#endif
+
+#ifndef S_ISDIR
+# ifdef S_IFDIR
+# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+# else
+# define S_ISDIR(m) 0
+# endif
+#endif
+
+#ifndef S_ISDOOR /* Solaris 2.5 and up */
+# define S_ISDOOR(m) 0
+#endif
+
+#ifndef S_ISFIFO
+# ifdef S_IFIFO
+# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+# else
+# define S_ISFIFO(m) 0
+# endif
+#endif
+
+#ifndef S_ISLNK
+# ifdef S_IFLNK
+# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+# else
+# define S_ISLNK(m) 0
+# endif
+#endif
+
+#ifndef S_ISMPB /* V7 */
+# ifdef S_IFMPB
+# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
+# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
+# else
+# define S_ISMPB(m) 0
+# define S_ISMPC(m) 0
+# endif
+#endif
+
+#ifndef S_ISMPX /* AIX */
+# define S_ISMPX(m) 0
+#endif
+
+#ifndef S_ISNAM /* Xenix */
+# ifdef S_IFNAM
+# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
+# else
+# define S_ISNAM(m) 0
+# endif
+#endif
+
+#ifndef S_ISNWK /* HP/UX */
+# ifdef S_IFNWK
+# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
+# else
+# define S_ISNWK(m) 0
+# endif
+#endif
+
+#ifndef S_ISPORT /* Solaris 10 and up */
+# define S_ISPORT(m) 0
+#endif
+
+#ifndef S_ISREG
+# ifdef S_IFREG
+# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+# else
+# define S_ISREG(m) 0
+# endif
+#endif
+
+#ifndef S_ISSOCK
+# ifdef S_IFSOCK
+# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+# else
+# define S_ISSOCK(m) 0
+# endif
+#endif
+
+
+#ifndef S_TYPEISMQ
+# define S_TYPEISMQ(p) 0
+#endif
+
+#ifndef S_TYPEISTMO
+# define S_TYPEISTMO(p) 0
+#endif
+
+
+#ifndef S_TYPEISSEM
+# ifdef S_INSEM
+# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
+# else
+# define S_TYPEISSEM(p) 0
+# endif
+#endif
+
+#ifndef S_TYPEISSHM
+# ifdef S_INSHD
+# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
+# else
+# define S_TYPEISSHM(p) 0
+# endif
+#endif
+
+/* high performance ("contiguous data") */
+#ifndef S_ISCTG
+# define S_ISCTG(p) 0
+#endif
+
+/* Cray DMF (data migration facility): off line, with data */
+#ifndef S_ISOFD
+# define S_ISOFD(p) 0
+#endif
+
+/* Cray DMF (data migration facility): off line, with no data */
+#ifndef S_ISOFL
+# define S_ISOFL(p) 0
+#endif
+
+/* 4.4BSD whiteout */
+#ifndef S_ISWHT
+# define S_ISWHT(m) 0
+#endif
+
+/* If any of the following are undefined,
+ define them to their de facto standard values. */
+#if !S_ISUID
+# define S_ISUID 04000
+#endif
+#if !S_ISGID
+# define S_ISGID 02000
+#endif
+
+/* S_ISVTX is a common extension to POSIX. */
+#ifndef S_ISVTX
+# define S_ISVTX 01000
+#endif
+
+#if !S_IRUSR && S_IREAD
+# define S_IRUSR S_IREAD
+#endif
+#if !S_IRUSR
+# define S_IRUSR 00400
+#endif
+#if !S_IRGRP
+# define S_IRGRP (S_IRUSR >> 3)
+#endif
+#if !S_IROTH
+# define S_IROTH (S_IRUSR >> 6)
+#endif
+
+#if !S_IWUSR && S_IWRITE
+# define S_IWUSR S_IWRITE
+#endif
+#if !S_IWUSR
+# define S_IWUSR 00200
+#endif
+#if !S_IWGRP
+# define S_IWGRP (S_IWUSR >> 3)
+#endif
+#if !S_IWOTH
+# define S_IWOTH (S_IWUSR >> 6)
+#endif
+
+#if !S_IXUSR && S_IEXEC
+# define S_IXUSR S_IEXEC
+#endif
+#if !S_IXUSR
+# define S_IXUSR 00100
+#endif
+#if !S_IXGRP
+# define S_IXGRP (S_IXUSR >> 3)
+#endif
+#if !S_IXOTH
+# define S_IXOTH (S_IXUSR >> 6)
+#endif
+
+#if !S_IRWXU
+# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
+#endif
+#if !S_IRWXG
+# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
+#endif
+#if !S_IRWXO
+# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
+#endif
+
+/* S_IXUGO is a common extension to POSIX. */
+#if !S_IXUGO
+# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
+#endif
+
+#ifndef S_IRWXUGO
+# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
+#endif
+
+/* Macros for futimens and utimensat. */
+#ifndef UTIME_NOW
+# define UTIME_NOW (-1)
+# define UTIME_OMIT (-2)
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (fchmodat, int,
+ (int fd, char const *file, mode_t mode, int flag)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (fchmodat, int,
+ (int fd, char const *file, mode_t mode, int flag));
+_GL_CXXALIASWARN (fchmodat);
+#elif defined GNULIB_POSIXCHECK
+# undef fchmodat
+# if HAVE_RAW_DECL_FCHMODAT
+_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
+ "use gnulib module openat for portability");
+# endif
+#endif
+
+
+#if 1
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fstat
+# define fstat rpl_fstat
+# endif
+_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
+# else
+_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
+# endif
+_GL_CXXALIASWARN (fstat);
+#elif 1
+/* Above, we define stat to _stati64. */
+# define fstat _fstati64
+#elif defined GNULIB_POSIXCHECK
+# undef fstat
+# if HAVE_RAW_DECL_FSTAT
+_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
+ "use gnulib module fstat for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fstatat
+# define fstatat rpl_fstatat
+# endif
+_GL_FUNCDECL_RPL (fstatat, int,
+ (int fd, char const *name, struct stat *st, int flags)
+ _GL_ARG_NONNULL ((2, 3)));
+_GL_CXXALIAS_RPL (fstatat, int,
+ (int fd, char const *name, struct stat *st, int flags));
+# else
+# if !1
+_GL_FUNCDECL_SYS (fstatat, int,
+ (int fd, char const *name, struct stat *st, int flags)
+ _GL_ARG_NONNULL ((2, 3)));
+# endif
+_GL_CXXALIAS_SYS (fstatat, int,
+ (int fd, char const *name, struct stat *st, int flags));
+# endif
+_GL_CXXALIASWARN (fstatat);
+#elif defined GNULIB_POSIXCHECK
+# undef fstatat
+# if HAVE_RAW_DECL_FSTATAT
+_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
+ "use gnulib module openat for portability");
+# endif
+#endif
+
+
+#if 0
+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
+ implementation relies on futimesat, which on Solaris 10 makes an invocation
+ to futimens that is meant to invoke the libc's futimens(), not gnulib's
+ futimens(). */
+# if 0 || (!1 && defined __sun)
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef futimens
+# define futimens rpl_futimens
+# endif
+_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
+_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
+# else
+# if !1
+_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
+# endif
+_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
+# endif
+# if 1
+_GL_CXXALIASWARN (futimens);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef futimens
+# if HAVE_RAW_DECL_FUTIMENS
+_GL_WARN_ON_USE (futimens, "futimens is not portable - "
+ "use gnulib module futimens for portability");
+# endif
+#endif
+
+
+#if 0
+/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
+ denotes a symbolic link. */
+# if !1
+/* The lchmod replacement follows symbolic links. Callers should take
+ this into account; lchmod should be applied only to arguments that
+ are known to not be symbolic links. On hosts that lack lchmod,
+ this can lead to race conditions between the check and the
+ invocation of lchmod, but we know of no workarounds that are
+ reliable in general. You might try requesting support for lchmod
+ from your operating system supplier. */
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define lchmod chmod
+# endif
+/* Need to cast, because on mingw, the second parameter of chmod is
+ int mode. */
+_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
+ (const char *filename, mode_t mode));
+# else
+# if 0 /* assume already declared */
+_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
+# endif
+# if 1
+_GL_CXXALIASWARN (lchmod);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lchmod
+# if HAVE_RAW_DECL_LCHMOD
+_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
+ "use gnulib module lchmod for portability");
+# endif
+#endif
+
+
+#if 1
+# if ! 0
+/* mingw does not support symlinks, therefore it does not have lstat. But
+ without links, stat does just fine. */
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define lstat stat
+# endif
+_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
+# elif 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef lstat
+# define lstat rpl_lstat
+# endif
+_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
+# else
+_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
+# endif
+# if 0
+_GL_CXXALIASWARN (lstat);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lstat
+# if HAVE_RAW_DECL_LSTAT
+_GL_WARN_ON_USE (lstat, "lstat is unportable - "
+ "use gnulib module lstat for portability");
+# endif
+#endif
+
+
+#if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef mkdir
+# define mkdir rpl_mkdir
+# endif
+_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
+#else
+/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
+ Additionally, it declares _mkdir (and depending on compile flags, an
+ alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
+ which are included above. */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+# if !GNULIB_defined_rpl_mkdir
+static int
+rpl_mkdir (char const *name, mode_t mode)
+{
+ return _mkdir (name);
+}
+# define GNULIB_defined_rpl_mkdir 1
+# endif
+
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define mkdir rpl_mkdir
+# endif
+_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
+# else
+_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
+# endif
+#endif
+_GL_CXXALIASWARN (mkdir);
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
+_GL_CXXALIASWARN (mkdirat);
+#elif defined GNULIB_POSIXCHECK
+# undef mkdirat
+# if HAVE_RAW_DECL_MKDIRAT
+_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
+ "use gnulib module openat for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef mkfifo
+# define mkfifo rpl_mkfifo
+# endif
+_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
+# else
+# if !1
+_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
+# endif
+_GL_CXXALIASWARN (mkfifo);
+#elif defined GNULIB_POSIXCHECK
+# undef mkfifo
+# if HAVE_RAW_DECL_MKFIFO
+_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
+ "use gnulib module mkfifo for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
+_GL_CXXALIASWARN (mkfifoat);
+#elif defined GNULIB_POSIXCHECK
+# undef mkfifoat
+# if HAVE_RAW_DECL_MKFIFOAT
+_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
+ "use gnulib module mkfifoat for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef mknod
+# define mknod rpl_mknod
+# endif
+_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
+# else
+# if !1
+_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
+ _GL_ARG_NONNULL ((1)));
+# endif
+/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
+_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
+# endif
+_GL_CXXALIASWARN (mknod);
+#elif defined GNULIB_POSIXCHECK
+# undef mknod
+# if HAVE_RAW_DECL_MKNOD
+_GL_WARN_ON_USE (mknod, "mknod is not portable - "
+ "use gnulib module mknod for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (mknodat, int,
+ (int fd, char const *file, mode_t mode, dev_t dev)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (mknodat, int,
+ (int fd, char const *file, mode_t mode, dev_t dev));
+_GL_CXXALIASWARN (mknodat);
+#elif defined GNULIB_POSIXCHECK
+# undef mknodat
+# if HAVE_RAW_DECL_MKNODAT
+_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
+ "use gnulib module mkfifoat for portability");
+# endif
+#endif
+
+
+#if 1
+# if 1
+/* We can't use the object-like #define stat rpl_stat, because of
+ struct stat. This means that rpl_stat will not be used if the user
+ does (stat)(a,b). Oh well. */
+# if defined _AIX && defined stat && defined _LARGE_FILES
+ /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
+ so we have to replace stat64() instead of stat(). */
+# undef stat64
+# define stat64(name, st) rpl_stat (name, st)
+# elif 1
+ /* Above, we define stat to _stati64. */
+# if defined __MINGW32__ && defined _stati64
+# ifndef _USE_32BIT_TIME_T
+ /* The system headers define _stati64 to _stat64. */
+# undef _stat64
+# define _stat64(name, st) rpl_stat (name, st)
+# endif
+# elif defined _MSC_VER && defined _stati64
+# ifdef _USE_32BIT_TIME_T
+ /* The system headers define _stati64 to _stat32i64. */
+# undef _stat32i64
+# define _stat32i64(name, st) rpl_stat (name, st)
+# else
+ /* The system headers define _stati64 to _stat64. */
+# undef _stat64
+# define _stat64(name, st) rpl_stat (name, st)
+# endif
+# else
+# undef _stati64
+# define _stati64(name, st) rpl_stat (name, st)
+# endif
+# elif defined __MINGW32__ && defined stat
+# ifdef _USE_32BIT_TIME_T
+ /* The system headers define stat to _stat32i64. */
+# undef _stat32i64
+# define _stat32i64(name, st) rpl_stat (name, st)
+# else
+ /* The system headers define stat to _stat64. */
+# undef _stat64
+# define _stat64(name, st) rpl_stat (name, st)
+# endif
+# elif defined _MSC_VER && defined stat
+# ifdef _USE_32BIT_TIME_T
+ /* The system headers define stat to _stat32. */
+# undef _stat32
+# define _stat32(name, st) rpl_stat (name, st)
+# else
+ /* The system headers define stat to _stat64i32. */
+# undef _stat64i32
+# define _stat64i32(name, st) rpl_stat (name, st)
+# endif
+# else /* !(_AIX ||__MINGW32__ || _MSC_VER) */
+# undef stat
+# define stat(name, st) rpl_stat (name, st)
+# endif /* !_LARGE_FILES */
+_GL_EXTERN_C int stat (const char *name, struct stat *buf)
+ _GL_ARG_NONNULL ((1, 2));
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef stat
+# if HAVE_RAW_DECL_STAT
+_GL_WARN_ON_USE (stat, "stat is unportable - "
+ "use gnulib module stat for portability");
+# endif
+#endif
+
+
+#if 0
+/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
+ implementation relies on futimesat, which on Solaris 10 makes an invocation
+ to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
+ utimensat(). */
+# if 0 || (!1 && defined __sun)
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef utimensat
+# define utimensat rpl_utimensat
+# endif
+_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
+ struct timespec const times[2], int flag)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
+ struct timespec const times[2], int flag));
+# else
+# if !1
+_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
+ struct timespec const times[2], int flag)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
+ struct timespec const times[2], int flag));
+# endif
+# if 1
+_GL_CXXALIASWARN (utimensat);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef utimensat
+# if HAVE_RAW_DECL_UTIMENSAT
+_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
+ "use gnulib module utimensat for portability");
+# endif
+#endif
+
+
+#endif /* _GL_M4_SYS_STAT_H */
+#endif /* _GL_M4_SYS_STAT_H */
+#endif
diff --git a/contrib/tools/bison/gnulib/platform/win64/sys/time.h b/contrib/tools/bison/gnulib/platform/win64/sys/time.h
index 3b520228f2..b728e2a6c4 100644
--- a/contrib/tools/bison/gnulib/platform/win64/sys/time.h
+++ b/contrib/tools/bison/gnulib/platform/win64/sys/time.h
@@ -1,525 +1,525 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Provide a more complete sys/time.h.
-
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#ifndef _GL_M4_SYS_TIME_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* On Cygwin and on many BSDish systems, <sys/time.h> includes itself
- recursively via <sys/select.h>.
- Simply delegate to the system's header in this case; it is a no-op.
- Without this extra ifdef, the C++ gettimeofday declaration below
- would be a forward declaration in gnulib's nested <sys/time.h>. */
-#if defined _CYGWIN_SYS_TIME_H || defined _SYS_TIME_H || defined _SYS_TIME_H_
-# include <sys/time.h>
-#else
-
-/* The include_next requires a split double-inclusion guard. */
-#if 0
-# include <sys/time.h>
-#endif
-
-#ifndef _GL_M4_SYS_TIME_H
-#define _GL_M4_SYS_TIME_H
-
-#if ! 0
-# include <time.h>
-#endif
-
-/* On native Windows with MSVC, get the 'struct timeval' type.
- Also, on native Windows with a 64-bit time_t, where we are overriding the
- 'struct timeval' type, get all declarations of system functions whose
- signature contains 'struct timeval'. */
-#if (defined _MSC_VER || 0) && 0 && !defined _GL_INCLUDING_WINSOCK2_H
-# define _GL_INCLUDING_WINSOCK2_H
-# include <winsock2.h>
-# undef _GL_INCLUDING_WINSOCK2_H
-#endif
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if !0 || 0
-
-# if 0
-# define timeval rpl_timeval
-# endif
-
-# if !GNULIB_defined_struct_timeval
-struct timeval
-{
- time_t tv_sec;
- long int tv_usec;
-};
-# define GNULIB_defined_struct_timeval 1
-# endif
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#if 1
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef gettimeofday
-# define gettimeofday rpl_gettimeofday
-# endif
-_GL_FUNCDECL_RPL (gettimeofday, int,
- (struct timeval *restrict, void *restrict)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (gettimeofday, int,
- (struct timeval *restrict, void *restrict));
-# else
-# if !0
-_GL_FUNCDECL_SYS (gettimeofday, int,
- (struct timeval *restrict, void *restrict)
- _GL_ARG_NONNULL ((1)));
-# endif
-/* Need to cast, because on glibc systems, by default, the second argument is
- struct timezone *. */
-_GL_CXXALIAS_SYS_CAST (gettimeofday, int,
- (struct timeval *restrict, void *restrict));
-# endif
-_GL_CXXALIASWARN (gettimeofday);
-#elif defined GNULIB_POSIXCHECK
-# undef gettimeofday
-# if HAVE_RAW_DECL_GETTIMEOFDAY
-_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
- "use gnulib module gettimeofday for portability");
-# endif
-#endif
-
-/* Hide some function declarations from <winsock2.h>. */
-
-#if defined _MSC_VER && 0
-# if !defined _GL_M4_UNISTD_H
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef close
-# define close close_used_without_including_unistd_h
-# else
- _GL_WARN_ON_USE (close,
- "close() used without including <unistd.h>");
-# endif
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef gethostname
-# define gethostname gethostname_used_without_including_unistd_h
-# else
- _GL_WARN_ON_USE (gethostname,
- "gethostname() used without including <unistd.h>");
-# endif
-# endif
-# if !defined _GL_M4_SYS_SOCKET_H
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef socket
-# define socket socket_used_without_including_sys_socket_h
-# undef connect
-# define connect connect_used_without_including_sys_socket_h
-# undef accept
-# define accept accept_used_without_including_sys_socket_h
-# undef bind
-# define bind bind_used_without_including_sys_socket_h
-# undef getpeername
-# define getpeername getpeername_used_without_including_sys_socket_h
-# undef getsockname
-# define getsockname getsockname_used_without_including_sys_socket_h
-# undef getsockopt
-# define getsockopt getsockopt_used_without_including_sys_socket_h
-# undef listen
-# define listen listen_used_without_including_sys_socket_h
-# undef recv
-# define recv recv_used_without_including_sys_socket_h
-# undef send
-# define send send_used_without_including_sys_socket_h
-# undef recvfrom
-# define recvfrom recvfrom_used_without_including_sys_socket_h
-# undef sendto
-# define sendto sendto_used_without_including_sys_socket_h
-# undef setsockopt
-# define setsockopt setsockopt_used_without_including_sys_socket_h
-# undef shutdown
-# define shutdown shutdown_used_without_including_sys_socket_h
-# else
- _GL_WARN_ON_USE (socket,
- "socket() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (connect,
- "connect() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (accept,
- "accept() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (bind,
- "bind() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (getpeername,
- "getpeername() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (getsockname,
- "getsockname() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (getsockopt,
- "getsockopt() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (listen,
- "listen() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (recv,
- "recv() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (send,
- "send() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (recvfrom,
- "recvfrom() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (sendto,
- "sendto() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (setsockopt,
- "setsockopt() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (shutdown,
- "shutdown() used without including <sys/socket.h>");
-# endif
-# endif
-# if !defined _GL_M4_SYS_SELECT_H
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef select
-# define select select_used_without_including_sys_select_h
-# else
- _GL_WARN_ON_USE (select,
- "select() used without including <sys/select.h>");
-# endif
-# endif
-#endif
-
-#endif /* _GL_M4_SYS_TIME_H */
-#endif /* _CYGWIN_SYS_TIME_H */
-#endif /* _GL_M4_SYS_TIME_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Provide a more complete sys/time.h.
+
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#ifndef _GL_M4_SYS_TIME_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* On Cygwin and on many BSDish systems, <sys/time.h> includes itself
+ recursively via <sys/select.h>.
+ Simply delegate to the system's header in this case; it is a no-op.
+ Without this extra ifdef, the C++ gettimeofday declaration below
+ would be a forward declaration in gnulib's nested <sys/time.h>. */
+#if defined _CYGWIN_SYS_TIME_H || defined _SYS_TIME_H || defined _SYS_TIME_H_
+# include <sys/time.h>
+#else
+
+/* The include_next requires a split double-inclusion guard. */
+#if 0
+# include <sys/time.h>
+#endif
+
+#ifndef _GL_M4_SYS_TIME_H
+#define _GL_M4_SYS_TIME_H
+
+#if ! 0
+# include <time.h>
+#endif
+
+/* On native Windows with MSVC, get the 'struct timeval' type.
+ Also, on native Windows with a 64-bit time_t, where we are overriding the
+ 'struct timeval' type, get all declarations of system functions whose
+ signature contains 'struct timeval'. */
+#if (defined _MSC_VER || 0) && 0 && !defined _GL_INCLUDING_WINSOCK2_H
+# define _GL_INCLUDING_WINSOCK2_H
+# include <winsock2.h>
+# undef _GL_INCLUDING_WINSOCK2_H
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !0 || 0
+
+# if 0
+# define timeval rpl_timeval
+# endif
+
+# if !GNULIB_defined_struct_timeval
+struct timeval
+{
+ time_t tv_sec;
+ long int tv_usec;
+};
+# define GNULIB_defined_struct_timeval 1
+# endif
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#if 1
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef gettimeofday
+# define gettimeofday rpl_gettimeofday
+# endif
+_GL_FUNCDECL_RPL (gettimeofday, int,
+ (struct timeval *restrict, void *restrict)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (gettimeofday, int,
+ (struct timeval *restrict, void *restrict));
+# else
+# if !0
+_GL_FUNCDECL_SYS (gettimeofday, int,
+ (struct timeval *restrict, void *restrict)
+ _GL_ARG_NONNULL ((1)));
+# endif
+/* Need to cast, because on glibc systems, by default, the second argument is
+ struct timezone *. */
+_GL_CXXALIAS_SYS_CAST (gettimeofday, int,
+ (struct timeval *restrict, void *restrict));
+# endif
+_GL_CXXALIASWARN (gettimeofday);
+#elif defined GNULIB_POSIXCHECK
+# undef gettimeofday
+# if HAVE_RAW_DECL_GETTIMEOFDAY
+_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
+ "use gnulib module gettimeofday for portability");
+# endif
+#endif
+
+/* Hide some function declarations from <winsock2.h>. */
+
+#if defined _MSC_VER && 0
+# if !defined _GL_M4_UNISTD_H
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef close
+# define close close_used_without_including_unistd_h
+# else
+ _GL_WARN_ON_USE (close,
+ "close() used without including <unistd.h>");
+# endif
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef gethostname
+# define gethostname gethostname_used_without_including_unistd_h
+# else
+ _GL_WARN_ON_USE (gethostname,
+ "gethostname() used without including <unistd.h>");
+# endif
+# endif
+# if !defined _GL_M4_SYS_SOCKET_H
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef socket
+# define socket socket_used_without_including_sys_socket_h
+# undef connect
+# define connect connect_used_without_including_sys_socket_h
+# undef accept
+# define accept accept_used_without_including_sys_socket_h
+# undef bind
+# define bind bind_used_without_including_sys_socket_h
+# undef getpeername
+# define getpeername getpeername_used_without_including_sys_socket_h
+# undef getsockname
+# define getsockname getsockname_used_without_including_sys_socket_h
+# undef getsockopt
+# define getsockopt getsockopt_used_without_including_sys_socket_h
+# undef listen
+# define listen listen_used_without_including_sys_socket_h
+# undef recv
+# define recv recv_used_without_including_sys_socket_h
+# undef send
+# define send send_used_without_including_sys_socket_h
+# undef recvfrom
+# define recvfrom recvfrom_used_without_including_sys_socket_h
+# undef sendto
+# define sendto sendto_used_without_including_sys_socket_h
+# undef setsockopt
+# define setsockopt setsockopt_used_without_including_sys_socket_h
+# undef shutdown
+# define shutdown shutdown_used_without_including_sys_socket_h
+# else
+ _GL_WARN_ON_USE (socket,
+ "socket() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (connect,
+ "connect() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (accept,
+ "accept() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (bind,
+ "bind() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (getpeername,
+ "getpeername() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (getsockname,
+ "getsockname() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (getsockopt,
+ "getsockopt() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (listen,
+ "listen() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (recv,
+ "recv() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (send,
+ "send() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (recvfrom,
+ "recvfrom() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (sendto,
+ "sendto() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (setsockopt,
+ "setsockopt() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (shutdown,
+ "shutdown() used without including <sys/socket.h>");
+# endif
+# endif
+# if !defined _GL_M4_SYS_SELECT_H
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef select
+# define select select_used_without_including_sys_select_h
+# else
+ _GL_WARN_ON_USE (select,
+ "select() used without including <sys/select.h>");
+# endif
+# endif
+#endif
+
+#endif /* _GL_M4_SYS_TIME_H */
+#endif /* _CYGWIN_SYS_TIME_H */
+#endif /* _GL_M4_SYS_TIME_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/sys/wait.h b/contrib/tools/bison/gnulib/platform/win64/sys/wait.h
index 38bbfa81dd..c895289d6f 100644
--- a/contrib/tools/bison/gnulib/platform/win64/sys/wait.h
+++ b/contrib/tools/bison/gnulib/platform/win64/sys/wait.h
@@ -1,431 +1,431 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* A POSIX-like <sys/wait.h>.
- Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-
-#ifndef _GL_M4_SYS_WAIT_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. */
-#if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
-# include <sys/wait.h>
-#endif
-
-#ifndef _GL_M4_SYS_WAIT_H
-#define _GL_M4_SYS_WAIT_H
-
-/* Get pid_t. */
-#include <sys/types.h>
-
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-/* The three most frequent use cases of these macros are:
-
- * For providing a substitute for a function that is missing on some
- platforms, but is declared and works fine on the platforms on which
- it exists:
-
- #if @GNULIB_FOO@
- # if !@HAVE_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on all platforms,
- but is broken/insufficient and needs to be replaced on some platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-
- * For providing a replacement for a function that exists on some platforms
- but is broken/insufficient and needs to be replaced on some of them and
- is additionally either missing or undeclared on some other platforms:
-
- #if @GNULIB_FOO@
- # if @REPLACE_FOO@
- # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
- # undef foo
- # define foo rpl_foo
- # endif
- _GL_FUNCDECL_RPL (foo, ...);
- _GL_CXXALIAS_RPL (foo, ...);
- # else
- # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
- _GL_FUNCDECL_SYS (foo, ...);
- # endif
- _GL_CXXALIAS_SYS (foo, ...);
- # endif
- _GL_CXXALIASWARN (foo);
- #elif defined GNULIB_POSIXCHECK
- ...
- #endif
-*/
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-
-#if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
-/* Unix API. */
-
-/* The following macros apply to an argument x, that is a status of a process,
- as returned by waitpid().
- On nearly all systems, including Linux/x86, WEXITSTATUS are bits 15..8 and
- WTERMSIG are bits 7..0, while BeOS uses the opposite. Therefore programs
- have to use the abstract macros. */
-
-/* For valid x, exactly one of WIFSIGNALED(x), WIFEXITED(x), WIFSTOPPED(x)
- is true. */
-# ifndef WIFSIGNALED
-# define WIFSIGNALED(x) (WTERMSIG (x) != 0 && WTERMSIG(x) != 0x7f)
-# endif
-# ifndef WIFEXITED
-# define WIFEXITED(x) (WTERMSIG (x) == 0)
-# endif
-# ifndef WIFSTOPPED
-# define WIFSTOPPED(x) (WTERMSIG (x) == 0x7f)
-# endif
-
-/* The termination signal. Only to be accessed if WIFSIGNALED(x) is true. */
-# ifndef WTERMSIG
-# define WTERMSIG(x) ((x) & 0x7f)
-# endif
-
-/* The exit status. Only to be accessed if WIFEXITED(x) is true. */
-# ifndef WEXITSTATUS
-# define WEXITSTATUS(x) (((x) >> 8) & 0xff)
-# endif
-
-/* The stopping signal. Only to be accessed if WIFSTOPPED(x) is true. */
-# ifndef WSTOPSIG
-# define WSTOPSIG(x) (((x) >> 8) & 0x7f)
-# endif
-
-/* True if the process dumped core. Not standardized by POSIX. */
-# ifndef WCOREDUMP
-# define WCOREDUMP(x) ((x) & 0x80)
-# endif
-
-#else
-/* Native Windows API. */
-
-# include <signal.h> /* for SIGTERM */
-
-/* The following macros apply to an argument x, that is a status of a process,
- as returned by waitpid() or, equivalently, _cwait() or GetExitCodeProcess().
- This value is simply an 'int', not composed of bit fields. */
-
-/* When an unhandled fatal signal terminates a process, the exit code is 3. */
-# define WIFSIGNALED(x) ((x) == 3)
-# define WIFEXITED(x) ((x) != 3)
-# define WIFSTOPPED(x) 0
-
-/* The signal that terminated a process is not known posthum. */
-# define WTERMSIG(x) SIGTERM
-
-# define WEXITSTATUS(x) (x)
-
-/* There are no stopping signals. */
-# define WSTOPSIG(x) 0
-
-/* There are no core dumps. */
-# define WCOREDUMP(x) 0
-
-#endif
-
-
-/* Declarations of functions. */
-
-#if 1
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-_GL_FUNCDECL_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
-# endif
-_GL_CXXALIAS_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
-_GL_CXXALIASWARN (waitpid);
-#elif defined GNULIB_POSIXCHECK
-# undef waitpid
-# if HAVE_RAW_DECL_WAITPID
-_GL_WARN_ON_USE (waitpid, "waitpid is unportable - "
- "use gnulib module sys_wait for portability");
-# endif
-#endif
-
-
-#endif /* _GL_M4_SYS_WAIT_H */
-#endif /* _GL_M4_SYS_WAIT_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* A POSIX-like <sys/wait.h>.
+ Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifndef _GL_M4_SYS_WAIT_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. */
+#if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+# include <sys/wait.h>
+#endif
+
+#ifndef _GL_M4_SYS_WAIT_H
+#define _GL_M4_SYS_WAIT_H
+
+/* Get pid_t. */
+#include <sys/types.h>
+
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+/* The three most frequent use cases of these macros are:
+
+ * For providing a substitute for a function that is missing on some
+ platforms, but is declared and works fine on the platforms on which
+ it exists:
+
+ #if @GNULIB_FOO@
+ # if !@HAVE_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on all platforms,
+ but is broken/insufficient and needs to be replaced on some platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+
+ * For providing a replacement for a function that exists on some platforms
+ but is broken/insufficient and needs to be replaced on some of them and
+ is additionally either missing or undeclared on some other platforms:
+
+ #if @GNULIB_FOO@
+ # if @REPLACE_FOO@
+ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+ # undef foo
+ # define foo rpl_foo
+ # endif
+ _GL_FUNCDECL_RPL (foo, ...);
+ _GL_CXXALIAS_RPL (foo, ...);
+ # else
+ # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
+ _GL_FUNCDECL_SYS (foo, ...);
+ # endif
+ _GL_CXXALIAS_SYS (foo, ...);
+ # endif
+ _GL_CXXALIASWARN (foo);
+ #elif defined GNULIB_POSIXCHECK
+ ...
+ #endif
+*/
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+
+#if !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+/* Unix API. */
+
+/* The following macros apply to an argument x, that is a status of a process,
+ as returned by waitpid().
+ On nearly all systems, including Linux/x86, WEXITSTATUS are bits 15..8 and
+ WTERMSIG are bits 7..0, while BeOS uses the opposite. Therefore programs
+ have to use the abstract macros. */
+
+/* For valid x, exactly one of WIFSIGNALED(x), WIFEXITED(x), WIFSTOPPED(x)
+ is true. */
+# ifndef WIFSIGNALED
+# define WIFSIGNALED(x) (WTERMSIG (x) != 0 && WTERMSIG(x) != 0x7f)
+# endif
+# ifndef WIFEXITED
+# define WIFEXITED(x) (WTERMSIG (x) == 0)
+# endif
+# ifndef WIFSTOPPED
+# define WIFSTOPPED(x) (WTERMSIG (x) == 0x7f)
+# endif
+
+/* The termination signal. Only to be accessed if WIFSIGNALED(x) is true. */
+# ifndef WTERMSIG
+# define WTERMSIG(x) ((x) & 0x7f)
+# endif
+
+/* The exit status. Only to be accessed if WIFEXITED(x) is true. */
+# ifndef WEXITSTATUS
+# define WEXITSTATUS(x) (((x) >> 8) & 0xff)
+# endif
+
+/* The stopping signal. Only to be accessed if WIFSTOPPED(x) is true. */
+# ifndef WSTOPSIG
+# define WSTOPSIG(x) (((x) >> 8) & 0x7f)
+# endif
+
+/* True if the process dumped core. Not standardized by POSIX. */
+# ifndef WCOREDUMP
+# define WCOREDUMP(x) ((x) & 0x80)
+# endif
+
+#else
+/* Native Windows API. */
+
+# include <signal.h> /* for SIGTERM */
+
+/* The following macros apply to an argument x, that is a status of a process,
+ as returned by waitpid() or, equivalently, _cwait() or GetExitCodeProcess().
+ This value is simply an 'int', not composed of bit fields. */
+
+/* When an unhandled fatal signal terminates a process, the exit code is 3. */
+# define WIFSIGNALED(x) ((x) == 3)
+# define WIFEXITED(x) ((x) != 3)
+# define WIFSTOPPED(x) 0
+
+/* The signal that terminated a process is not known posthum. */
+# define WTERMSIG(x) SIGTERM
+
+# define WEXITSTATUS(x) (x)
+
+/* There are no stopping signals. */
+# define WSTOPSIG(x) 0
+
+/* There are no core dumps. */
+# define WCOREDUMP(x) 0
+
+#endif
+
+
+/* Declarations of functions. */
+
+#if 1
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+_GL_FUNCDECL_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
+# endif
+_GL_CXXALIAS_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
+_GL_CXXALIASWARN (waitpid);
+#elif defined GNULIB_POSIXCHECK
+# undef waitpid
+# if HAVE_RAW_DECL_WAITPID
+_GL_WARN_ON_USE (waitpid, "waitpid is unportable - "
+ "use gnulib module sys_wait for portability");
+# endif
+#endif
+
+
+#endif /* _GL_M4_SYS_WAIT_H */
+#endif /* _GL_M4_SYS_WAIT_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/unistd.h b/contrib/tools/bison/gnulib/platform/win64/unistd.h
index 06babd93a7..c0c9b1a055 100644
--- a/contrib/tools/bison/gnulib/platform/win64/unistd.h
+++ b/contrib/tools/bison/gnulib/platform/win64/unistd.h
@@ -1,1787 +1,1787 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Substitute for and wrapper around <unistd.h>.
- Copyright (C) 2003-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_M4_UNISTD_H
-
-#if __GNUC__ >= 3
-
-#endif
-
-
-/* The include_next requires a split double-inclusion guard. */
-#if 0
-# include <unistd.h>
-#endif
-
-/* Get all possible declarations of gethostname(). */
-#if 0 && 0 \
- && !defined _GL_INCLUDING_WINSOCK2_H
-# define _GL_INCLUDING_WINSOCK2_H
-# include <winsock2.h>
-# undef _GL_INCLUDING_WINSOCK2_H
-#endif
-
-#if !defined _GL_M4_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
-#define _GL_M4_UNISTD_H
-
-/* NetBSD 5.0 mis-defines NULL. Also get size_t. */
-#include <stddef.h>
-
-/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
-/* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
-/* But avoid namespace pollution on glibc systems. */
-#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
- || ((0 || defined GNULIB_POSIXCHECK) \
- && defined __CYGWIN__)) \
- && ! defined __GLIBC__
-# include <stdio.h>
-#endif
-
-/* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */
-/* But avoid namespace pollution on glibc systems. */
-#if (0 || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \
- && ! defined __GLIBC__
-# include <fcntl.h>
-#endif
-
-/* mingw fails to declare _exit in <unistd.h>. */
-/* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in
- <unistd.h>. */
-/* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
-/* OSF Tru64 Unix cannot see gnulib rpl_strtod when system <stdlib.h> is
- included here. */
-/* But avoid namespace pollution on glibc systems. */
-#if !defined __GLIBC__ && !defined __osf__
-# define __need_system_stdlib_h
-# include <stdlib.h>
-# undef __need_system_stdlib_h
-#endif
-
-/* Native Windows platforms declare chdir, getcwd, rmdir in
- <io.h> and/or <direct.h>, not in <unistd.h>.
- They also declare access(), chmod(), close(), dup(), dup2(), isatty(),
- lseek(), read(), unlink(), write() in <io.h>. */
-#if ((1 || IN_M4_GNULIB_TESTS || 1 \
- || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
-# include <io.h> /* mingw32, mingw64 */
-# include <direct.h> /* mingw64, MSVC 9 */
-#elif (1 || IN_M4_GNULIB_TESTS || 1 || 0 \
- || 1 || 0 || 0 || IN_M4_GNULIB_TESTS \
- || defined GNULIB_POSIXCHECK) \
- && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
-# include <io.h>
-#endif
-
-/* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
- NonStop Kernel declares gethostname in <netdb.h>, not in <unistd.h>. */
-/* But avoid namespace pollution on glibc systems. */
-#if ((0 && (defined _AIX || defined __osf__)) \
- || (0 && defined __TANDEM)) \
- && !defined __GLIBC__
-# include <netdb.h>
-#endif
-
-/* MSVC defines off_t in <sys/types.h>.
- May also define off_t to a 64-bit type on native Windows. */
-#if !0 || 1
-/* Get off_t. */
-# include <sys/types.h>
-#endif
-
-#if (0 || IN_M4_GNULIB_TESTS \
- || 1 || 0 \
- || 0 || 0 || defined GNULIB_POSIXCHECK)
-/* Get ssize_t. */
-# include <sys/types.h>
-#endif
-
-/* Get getopt(), optarg, optind, opterr, optopt.
- But avoid namespace pollution on glibc systems. */
-#if 01 && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
-# define __need_getopt
-# include <getopt.h>
-#endif
-
-#ifndef _GL_INLINE_HEADER_BEGIN
-# error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef _GL_UNISTD_INLINE
-# define _GL_UNISTD_INLINE _GL_INLINE
-#endif
-
-/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
-#ifndef _GL_CXXDEFS_H
-#define _GL_CXXDEFS_H
-
-
-/* _GL_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#if defined __cplusplus
-# define _GL_EXTERN_C extern "C"
-#else
-# define _GL_EXTERN_C extern
-#endif
-
-/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
- declares a replacement function, named rpl_func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
- _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
-#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype rpl_func parameters_and_attributes
-
-/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
- declares the system function, named func, with the given prototype,
- consisting of return type, parameters, and attributes.
- Example:
- _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
- _GL_ARG_NONNULL ((1)));
- */
-#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C rettype func parameters_and_attributes
-
-/* _GL_CXXALIAS_RPL (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
- Example:
- _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
- */
-#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
- _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = ::rpl_func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
- is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
- except that the C function rpl_func may have a slightly different
- declaration. A cast is used to silence the "invalid conversion" error
- that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- rettype (*const func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::rpl_func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS (func, rettype, parameters);
- declares a C++ alias called GNULIB_NAMESPACE::func
- that redirects to the system provided function func, if GNULIB_NAMESPACE
- is defined.
- Example:
- _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
- */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* If we were to write
- rettype (*const func) parameters = ::func;
- like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
- better (remove an indirection through a 'static' pointer variable),
- but then the _GL_CXXALIASWARN macro below would cause a warning not only
- for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = ::func; \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function func may have a slightly different declaration.
- A cast is used to silence the "invalid conversion" error that would
- otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>(::func); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
- is like _GL_CXXALIAS_SYS (func, rettype, parameters);
- except that the C function is picked among a set of overloaded functions,
- namely the one with rettype2 and parameters2. Two consecutive casts
- are used to silence the "cannot find a match" and "invalid conversion"
- errors that would otherwise occur. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
- /* The outer cast must be a reinterpret_cast.
- The inner cast: When the function is defined as a set of overloaded
- functions, it works as a static_cast<>, choosing the designated variant.
- When the function is defined as a single variant, it works as a
- reinterpret_cast<>. The parenthesized cast syntax works both ways. */
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- namespace GNULIB_NAMESPACE \
- { \
- static rettype (*func) parameters = \
- reinterpret_cast<rettype(*)parameters>( \
- (rettype2(*)parameters2)(::func)); \
- } \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#else
-# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN (func);
- causes a warning to be emitted when ::func is used but not when
- GNULIB_NAMESPACE::func is used. func must be defined without overloaded
- variants. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN(func) \
- _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN_1(func,namespace) \
- _GL_CXXALIASWARN_2 (func, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_WARN_ON_USE (func, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN_2(func,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN_2(func,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN(func) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
- causes a warning to be emitted when the given overloaded variant of ::func
- is used but not when GNULIB_NAMESPACE::func is used. */
-#if defined __cplusplus && defined GNULIB_NAMESPACE
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
- GNULIB_NAMESPACE)
-# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
- _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
-/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
- we enable the warning only when not optimizing. */
-# if !__OPTIMIZE__
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
- "The symbol ::" #func " refers to the system function. " \
- "Use " #namespace "::" #func " instead.")
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- extern __typeof__ (func) func
-# else
-# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-# endif
-#else
-# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
- _GL_EXTERN_C int _gl_cxxalias_dummy
-#endif
-
-#endif /* _GL_CXXDEFS_H */
-
-/* The definition of _GL_ARG_NONNULL is copied here. */
-/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
- that the values passed as arguments n, ..., m must be non-NULL pointers.
- n = 1 stands for the first argument, n = 2 for the second argument etc. */
-#ifndef _GL_ARG_NONNULL
-# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
-# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
-# else
-# define _GL_ARG_NONNULL(params)
-# endif
-#endif
-
-/* The definition of _GL_WARN_ON_USE is copied here. */
-#ifndef _GL_WARN_ON_USE
-
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-/* A compiler attribute is available in gcc versions 4.3.0 and later. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE(function, message) \
-extern __typeof__ (function) function
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE(function, message) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
- is like _GL_WARN_ON_USE (function, "string"), except that the function is
- declared with the given prototype, consisting of return type, parameters,
- and attributes.
- This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
- not work in this case. */
-#ifndef _GL_WARN_ON_USE_CXX
-# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes \
- __attribute__ ((__warning__ (msg)))
-# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
-/* Verify the existence of the function. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-extern rettype function parameters_and_attributes
-# else /* Unsupported. */
-# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
-_GL_WARN_EXTERN_C int _gl_warn_on_use
-# endif
-#endif
-
-/* _GL_WARN_EXTERN_C declaration;
- performs the declaration with C linkage. */
-#ifndef _GL_WARN_EXTERN_C
-# if defined __cplusplus
-# define _GL_WARN_EXTERN_C extern "C"
-# else
-# define _GL_WARN_EXTERN_C extern
-# endif
-#endif
-
-
-/* Hide some function declarations from <winsock2.h>. */
-
-#if 0 && 0
-# if !defined _GL_M4_SYS_SOCKET_H
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef socket
-# define socket socket_used_without_including_sys_socket_h
-# undef connect
-# define connect connect_used_without_including_sys_socket_h
-# undef accept
-# define accept accept_used_without_including_sys_socket_h
-# undef bind
-# define bind bind_used_without_including_sys_socket_h
-# undef getpeername
-# define getpeername getpeername_used_without_including_sys_socket_h
-# undef getsockname
-# define getsockname getsockname_used_without_including_sys_socket_h
-# undef getsockopt
-# define getsockopt getsockopt_used_without_including_sys_socket_h
-# undef listen
-# define listen listen_used_without_including_sys_socket_h
-# undef recv
-# define recv recv_used_without_including_sys_socket_h
-# undef send
-# define send send_used_without_including_sys_socket_h
-# undef recvfrom
-# define recvfrom recvfrom_used_without_including_sys_socket_h
-# undef sendto
-# define sendto sendto_used_without_including_sys_socket_h
-# undef setsockopt
-# define setsockopt setsockopt_used_without_including_sys_socket_h
-# undef shutdown
-# define shutdown shutdown_used_without_including_sys_socket_h
-# else
- _GL_WARN_ON_USE (socket,
- "socket() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (connect,
- "connect() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (accept,
- "accept() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (bind,
- "bind() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (getpeername,
- "getpeername() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (getsockname,
- "getsockname() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (getsockopt,
- "getsockopt() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (listen,
- "listen() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (recv,
- "recv() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (send,
- "send() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (recvfrom,
- "recvfrom() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (sendto,
- "sendto() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (setsockopt,
- "setsockopt() used without including <sys/socket.h>");
- _GL_WARN_ON_USE (shutdown,
- "shutdown() used without including <sys/socket.h>");
-# endif
-# endif
-# if !defined _GL_M4_SYS_SELECT_H
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef select
-# define select select_used_without_including_sys_select_h
-# else
- _GL_WARN_ON_USE (select,
- "select() used without including <sys/select.h>");
-# endif
-# endif
-#endif
-
-
-/* OS/2 EMX lacks these macros. */
-#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
-#endif
-#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
-#endif
-#ifndef STDERR_FILENO
-# define STDERR_FILENO 2
-#endif
-
-/* Ensure *_OK macros exist. */
-#ifndef F_OK
-# define F_OK 0
-# define X_OK 1
-# define W_OK 2
-# define R_OK 4
-#endif
-
-
-/* Declare overridden functions. */
-
-
-#if defined GNULIB_POSIXCHECK
-/* The access() function is a security risk. */
-_GL_WARN_ON_USE (access, "the access function is a security risk - "
- "use the gnulib module faccessat instead");
-#endif
-
-
-#if 1
-_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIASWARN (chdir);
-#elif defined GNULIB_POSIXCHECK
-# undef chdir
-# if HAVE_RAW_DECL_CHDIR
-_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - "
- "use gnulib module chdir for portability");
-# endif
-#endif
-
-
-#if 0
-/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
- to GID (if GID is not -1). Follow symbolic links.
- Return 0 if successful, otherwise -1 and errno set.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef chown
-# define chown rpl_chown
-# endif
-_GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
-# else
-# if !1
-_GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
-# endif
-_GL_CXXALIASWARN (chown);
-#elif defined GNULIB_POSIXCHECK
-# undef chown
-# if HAVE_RAW_DECL_CHOWN
-_GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
- "doesn't treat a uid or gid of -1 on some systems - "
- "use gnulib module chown for portability");
-# endif
-#endif
-
-
-#if 1
-# if 1
-/* Automatically included by modules that need a replacement for close. */
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef close
-# define close rpl_close
-# endif
-_GL_FUNCDECL_RPL (close, int, (int fd));
-_GL_CXXALIAS_RPL (close, int, (int fd));
-# else
-_GL_CXXALIAS_SYS (close, int, (int fd));
-# endif
-_GL_CXXALIASWARN (close);
-#elif 0
-# undef close
-# define close close_used_without_requesting_gnulib_module_close
-#elif defined GNULIB_POSIXCHECK
-# undef close
-/* Assume close is always declared. */
-_GL_WARN_ON_USE (close, "close does not portably work on sockets - "
- "use gnulib module close for portability");
-#endif
-
-
-#if IN_M4_GNULIB_TESTS
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define dup rpl_dup
-# endif
-_GL_FUNCDECL_RPL (dup, int, (int oldfd));
-_GL_CXXALIAS_RPL (dup, int, (int oldfd));
-# else
-_GL_CXXALIAS_SYS (dup, int, (int oldfd));
-# endif
-_GL_CXXALIASWARN (dup);
-#elif defined GNULIB_POSIXCHECK
-# undef dup
-# if HAVE_RAW_DECL_DUP
-_GL_WARN_ON_USE (dup, "dup is unportable - "
- "use gnulib module dup for portability");
-# endif
-#endif
-
-
-#if 1
-/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
- NEWFD = OLDFD, otherwise close NEWFD first if it is open.
- Return newfd if successful, otherwise -1 and errno set.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define dup2 rpl_dup2
-# endif
-_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
-_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
-# else
-# if !1
-_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
-# endif
-_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
-# endif
-_GL_CXXALIASWARN (dup2);
-#elif defined GNULIB_POSIXCHECK
-# undef dup2
-# if HAVE_RAW_DECL_DUP2
-_GL_WARN_ON_USE (dup2, "dup2 is unportable - "
- "use gnulib module dup2 for portability");
-# endif
-#endif
-
-
-#if 0
-/* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
- specified flags.
- The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
- and O_TEXT, O_BINARY (defined in "binary-io.h").
- Close NEWFD first if it is open.
- Return newfd if successful, otherwise -1 and errno set.
- See the Linux man page at
- <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define dup3 rpl_dup3
-# endif
-_GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
-_GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
-# else
-_GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
-_GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
-# endif
-_GL_CXXALIASWARN (dup3);
-#elif defined GNULIB_POSIXCHECK
-# undef dup3
-# if HAVE_RAW_DECL_DUP3
-_GL_WARN_ON_USE (dup3, "dup3 is unportable - "
- "use gnulib module dup3 for portability");
-# endif
-#endif
-
-
-#if 1
-# if !1
-/* Set of environment variables and values. An array of strings of the form
- "VARIABLE=VALUE", terminated with a NULL. */
-# if defined __APPLE__ && defined __MACH__
-# include <crt_externs.h>
-# define environ (*_NSGetEnviron ())
-# else
-# ifdef __cplusplus
-extern "C" {
-# endif
-extern char **environ;
-# ifdef __cplusplus
-}
-# endif
-# endif
-# endif
-#elif defined GNULIB_POSIXCHECK
-# if HAVE_RAW_DECL_ENVIRON
-_GL_UNISTD_INLINE char ***
-rpl_environ (void)
-{
- return &environ;
-}
-_GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
- "use gnulib module environ for portability");
-# undef environ
-# define environ (*rpl_environ ())
-# endif
-#endif
-
-
-#if 0
-/* Like access(), except that it uses the effective user id and group id of
- the current process. */
-# if !1
-_GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
-_GL_CXXALIASWARN (euidaccess);
-# if defined GNULIB_POSIXCHECK
-/* Like access(), this function is a security risk. */
-_GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
- "use the gnulib module faccessat instead");
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef euidaccess
-# if HAVE_RAW_DECL_EUIDACCESS
-_GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
- "use gnulib module euidaccess for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (faccessat, int,
- (int fd, char const *file, int mode, int flag)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (faccessat, int,
- (int fd, char const *file, int mode, int flag));
-_GL_CXXALIASWARN (faccessat);
-#elif defined GNULIB_POSIXCHECK
-# undef faccessat
-# if HAVE_RAW_DECL_FACCESSAT
-_GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
- "use gnulib module faccessat for portability");
-# endif
-#endif
-
-
-#if 0
-/* Change the process' current working directory to the directory on which
- the given file descriptor is open.
- Return 0 if successful, otherwise -1 and errno set.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */
-# if ! 1
-_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
-
-/* Gnulib internal hooks needed to maintain the fchdir metadata. */
-_GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
- _GL_ARG_NONNULL ((2));
-_GL_EXTERN_C void _gl_unregister_fd (int fd);
-_GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
-_GL_EXTERN_C const char *_gl_directory_name (int fd);
-
-# else
-# if !1
-_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
-# endif
-# endif
-_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
-_GL_CXXALIASWARN (fchdir);
-#elif defined GNULIB_POSIXCHECK
-# undef fchdir
-# if HAVE_RAW_DECL_FCHDIR
-_GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
- "use gnulib module fchdir for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef fchownat
-# define fchownat rpl_fchownat
-# endif
-_GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
- uid_t owner, gid_t group, int flag)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
- uid_t owner, gid_t group, int flag));
-# else
-# if !1
-_GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
- uid_t owner, gid_t group, int flag)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
- uid_t owner, gid_t group, int flag));
-# endif
-_GL_CXXALIASWARN (fchownat);
-#elif defined GNULIB_POSIXCHECK
-# undef fchownat
-# if HAVE_RAW_DECL_FCHOWNAT
-_GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
- "use gnulib module openat for portability");
-# endif
-#endif
-
-
-#if 0
-/* Synchronize changes to a file.
- Return 0 if successful, otherwise -1 and errno set.
- See POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. */
-# if !1 || !1
-_GL_FUNCDECL_SYS (fdatasync, int, (int fd));
-# endif
-_GL_CXXALIAS_SYS (fdatasync, int, (int fd));
-_GL_CXXALIASWARN (fdatasync);
-#elif defined GNULIB_POSIXCHECK
-# undef fdatasync
-# if HAVE_RAW_DECL_FDATASYNC
-_GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - "
- "use gnulib module fdatasync for portability");
-# endif
-#endif
-
-
-#if 0
-/* Synchronize changes, including metadata, to a file.
- Return 0 if successful, otherwise -1 and errno set.
- See POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>. */
-# if !1
-_GL_FUNCDECL_SYS (fsync, int, (int fd));
-# endif
-_GL_CXXALIAS_SYS (fsync, int, (int fd));
-_GL_CXXALIASWARN (fsync);
-#elif defined GNULIB_POSIXCHECK
-# undef fsync
-# if HAVE_RAW_DECL_FSYNC
-_GL_WARN_ON_USE (fsync, "fsync is unportable - "
- "use gnulib module fsync for portability");
-# endif
-#endif
-
-
-#if 0
-/* Change the size of the file to which FD is opened to become equal to LENGTH.
- Return 0 if successful, otherwise -1 and errno set.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef ftruncate
-# define ftruncate rpl_ftruncate
-# endif
-_GL_FUNCDECL_RPL (ftruncate, int, (int fd, off_t length));
-_GL_CXXALIAS_RPL (ftruncate, int, (int fd, off_t length));
-# else
-# if !1
-_GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
-# endif
-_GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
-# endif
-_GL_CXXALIASWARN (ftruncate);
-#elif defined GNULIB_POSIXCHECK
-# undef ftruncate
-# if HAVE_RAW_DECL_FTRUNCATE
-_GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
- "use gnulib module ftruncate for portability");
-# endif
-#endif
-
-
-#if IN_M4_GNULIB_TESTS
-/* Get the name of the current working directory, and put it in SIZE bytes
- of BUF.
- Return BUF if successful, or NULL if the directory couldn't be determined
- or SIZE was too small.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
- Additionally, the gnulib module 'getcwd' guarantees the following GNU
- extension: If BUF is NULL, an array is allocated with 'malloc'; the array
- is SIZE bytes long, unless SIZE == 0, in which case it is as big as
- necessary. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define getcwd rpl_getcwd
-# endif
-_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
-_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
-# else
-/* Need to cast, because on mingw, the second parameter is
- int size. */
-_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
-# endif
-_GL_CXXALIASWARN (getcwd);
-#elif defined GNULIB_POSIXCHECK
-# undef getcwd
-# if HAVE_RAW_DECL_GETCWD
-_GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
- "use gnulib module getcwd for portability");
-# endif
-#endif
-
-
-#if 0
-/* Return the NIS domain name of the machine.
- WARNING! The NIS domain name is unrelated to the fully qualified host name
- of the machine. It is also unrelated to email addresses.
- WARNING! The NIS domain name is usually the empty string or "(none)" when
- not using NIS.
-
- Put up to LEN bytes of the NIS domain name into NAME.
- Null terminate it if the name is shorter than LEN.
- If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
- Return 0 if successful, otherwise set errno and return -1. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef getdomainname
-# define getdomainname rpl_getdomainname
-# endif
-_GL_FUNCDECL_RPL (getdomainname, int, (char *name, size_t len)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (getdomainname, int, (char *name, size_t len));
-# else
-# if !1
-_GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len));
-# endif
-_GL_CXXALIASWARN (getdomainname);
-#elif defined GNULIB_POSIXCHECK
-# undef getdomainname
-# if HAVE_RAW_DECL_GETDOMAINNAME
-_GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
- "use gnulib module getdomainname for portability");
-# endif
-#endif
-
-
-#if 1
-/* Return the maximum number of file descriptors in the current process.
- In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
-# if !0
-_GL_FUNCDECL_SYS (getdtablesize, int, (void));
-# endif
-_GL_CXXALIAS_SYS (getdtablesize, int, (void));
-_GL_CXXALIASWARN (getdtablesize);
-#elif defined GNULIB_POSIXCHECK
-# undef getdtablesize
-# if HAVE_RAW_DECL_GETDTABLESIZE
-_GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
- "use gnulib module getdtablesize for portability");
-# endif
-#endif
-
-
-#if 0
-/* Return the supplemental groups that the current process belongs to.
- It is unspecified whether the effective group id is in the list.
- If N is 0, return the group count; otherwise, N describes how many
- entries are available in GROUPS. Return -1 and set errno if N is
- not 0 and not large enough. Fails with ENOSYS on some systems. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef getgroups
-# define getgroups rpl_getgroups
-# endif
-_GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
-_GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
-# else
-# if !1
-_GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
-# endif
-_GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
-# endif
-_GL_CXXALIASWARN (getgroups);
-#elif defined GNULIB_POSIXCHECK
-# undef getgroups
-# if HAVE_RAW_DECL_GETGROUPS
-_GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
- "use gnulib module getgroups for portability");
-# endif
-#endif
-
-
-#if 0
-/* Return the standard host name of the machine.
- WARNING! The host name may or may not be fully qualified.
-
- Put up to LEN bytes of the host name into NAME.
- Null terminate it if the name is shorter than LEN.
- If the host name is longer than LEN, set errno = EINVAL and return -1.
- Return 0 if successful, otherwise set errno and return -1. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef gethostname
-# define gethostname rpl_gethostname
-# endif
-_GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
-# else
-# if !1
-_GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
- _GL_ARG_NONNULL ((1)));
-# endif
-/* Need to cast, because on Solaris 10 and OSF/1 5.1 systems, the second
- parameter is
- int len. */
-_GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
-# endif
-_GL_CXXALIASWARN (gethostname);
-#elif 0
-# undef gethostname
-# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
-#elif defined GNULIB_POSIXCHECK
-# undef gethostname
-# if HAVE_RAW_DECL_GETHOSTNAME
-_GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
- "use gnulib module gethostname for portability");
-# endif
-#endif
-
-
-#if 0
-/* Returns the user's login name, or NULL if it cannot be found. Upon error,
- returns NULL with errno set.
-
- See <http://www.opengroup.org/susv3xsh/getlogin.html>.
-
- Most programs don't need to use this function, because the information is
- available through environment variables:
- ${LOGNAME-$USER} on Unix platforms,
- $USERNAME on native Windows platforms.
- */
-# if !1
-_GL_FUNCDECL_SYS (getlogin, char *, (void));
-# endif
-_GL_CXXALIAS_SYS (getlogin, char *, (void));
-_GL_CXXALIASWARN (getlogin);
-#elif defined GNULIB_POSIXCHECK
-# undef getlogin
-# if HAVE_RAW_DECL_GETLOGIN
-_GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
- "use gnulib module getlogin for portability");
-# endif
-#endif
-
-
-#if 0
-/* Copies the user's login name to NAME.
- The array pointed to by NAME has room for SIZE bytes.
-
- Returns 0 if successful. Upon error, an error number is returned, or -1 in
- the case that the login name cannot be found but no specific error is
- provided (this case is hopefully rare but is left open by the POSIX spec).
-
- See <http://www.opengroup.org/susv3xsh/getlogin.html>.
-
- Most programs don't need to use this function, because the information is
- available through environment variables:
- ${LOGNAME-$USER} on Unix platforms,
- $USERNAME on native Windows platforms.
- */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define getlogin_r rpl_getlogin_r
-# endif
-_GL_FUNCDECL_RPL (getlogin_r, int, (char *name, size_t size)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (getlogin_r, int, (char *name, size_t size));
-# else
-# if !1
-_GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
- _GL_ARG_NONNULL ((1)));
-# endif
-/* Need to cast, because on Solaris 10 systems, the second argument is
- int size. */
-_GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
-# endif
-_GL_CXXALIASWARN (getlogin_r);
-#elif defined GNULIB_POSIXCHECK
-# undef getlogin_r
-# if HAVE_RAW_DECL_GETLOGIN_R
-_GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
- "use gnulib module getlogin_r for portability");
-# endif
-#endif
-
-
-#if IN_M4_GNULIB_TESTS
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define getpagesize rpl_getpagesize
-# endif
-_GL_FUNCDECL_RPL (getpagesize, int, (void));
-_GL_CXXALIAS_RPL (getpagesize, int, (void));
-# else
-# if !0
-# if !defined getpagesize
-/* This is for POSIX systems. */
-# if !defined _gl_getpagesize && defined _SC_PAGESIZE
-# if ! (defined __VMS && __VMS_VER < 70000000)
-# define _gl_getpagesize() sysconf (_SC_PAGESIZE)
-# endif
-# endif
-/* This is for older VMS. */
-# if !defined _gl_getpagesize && defined __VMS
-# ifdef __ALPHA
-# define _gl_getpagesize() 8192
-# else
-# define _gl_getpagesize() 512
-# endif
-# endif
-/* This is for BeOS. */
-# if !defined _gl_getpagesize && 0
-# include <OS.h>
-# if defined B_PAGE_SIZE
-# define _gl_getpagesize() B_PAGE_SIZE
-# endif
-# endif
-/* This is for AmigaOS4.0. */
-# if !defined _gl_getpagesize && defined __amigaos4__
-# define _gl_getpagesize() 2048
-# endif
-/* This is for older Unix systems. */
-# if !defined _gl_getpagesize && 0
-# include <sys/param.h>
-# ifdef EXEC_PAGESIZE
-# define _gl_getpagesize() EXEC_PAGESIZE
-# else
-# ifdef NBPG
-# ifndef CLSIZE
-# define CLSIZE 1
-# endif
-# define _gl_getpagesize() (NBPG * CLSIZE)
-# else
-# ifdef NBPC
-# define _gl_getpagesize() NBPC
-# endif
-# endif
-# endif
-# endif
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define getpagesize() _gl_getpagesize ()
-# else
-# if !GNULIB_defined_getpagesize_function
-_GL_UNISTD_INLINE int
-getpagesize ()
-{
- return _gl_getpagesize ();
-}
-# define GNULIB_defined_getpagesize_function 1
-# endif
-# endif
-# endif
-# endif
-/* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
-_GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
-# endif
-# if 0
-_GL_CXXALIASWARN (getpagesize);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef getpagesize
-# if HAVE_RAW_DECL_GETPAGESIZE
-_GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
- "use gnulib module getpagesize for portability");
-# endif
-#endif
-
-
-#if 0
-/* Return the next valid login shell on the system, or NULL when the end of
- the list has been reached. */
-# if !1
-_GL_FUNCDECL_SYS (getusershell, char *, (void));
-# endif
-_GL_CXXALIAS_SYS (getusershell, char *, (void));
-_GL_CXXALIASWARN (getusershell);
-#elif defined GNULIB_POSIXCHECK
-# undef getusershell
-# if HAVE_RAW_DECL_GETUSERSHELL
-_GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
- "use gnulib module getusershell for portability");
-# endif
-#endif
-
-#if 0
-/* Rewind to pointer that is advanced at each getusershell() call. */
-# if !1
-_GL_FUNCDECL_SYS (setusershell, void, (void));
-# endif
-_GL_CXXALIAS_SYS (setusershell, void, (void));
-_GL_CXXALIASWARN (setusershell);
-#elif defined GNULIB_POSIXCHECK
-# undef setusershell
-# if HAVE_RAW_DECL_SETUSERSHELL
-_GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
- "use gnulib module getusershell for portability");
-# endif
-#endif
-
-#if 0
-/* Free the pointer that is advanced at each getusershell() call and
- associated resources. */
-# if !1
-_GL_FUNCDECL_SYS (endusershell, void, (void));
-# endif
-_GL_CXXALIAS_SYS (endusershell, void, (void));
-_GL_CXXALIASWARN (endusershell);
-#elif defined GNULIB_POSIXCHECK
-# undef endusershell
-# if HAVE_RAW_DECL_ENDUSERSHELL
-_GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
- "use gnulib module getusershell for portability");
-# endif
-#endif
-
-
-#if 0
-/* Determine whether group id is in calling user's group list. */
-# if !1
-_GL_FUNCDECL_SYS (group_member, int, (gid_t gid));
-# endif
-_GL_CXXALIAS_SYS (group_member, int, (gid_t gid));
-_GL_CXXALIASWARN (group_member);
-#elif defined GNULIB_POSIXCHECK
-# undef group_member
-# if HAVE_RAW_DECL_GROUP_MEMBER
-_GL_WARN_ON_USE (group_member, "group_member is unportable - "
- "use gnulib module group-member for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef isatty
-# define isatty rpl_isatty
-# endif
-_GL_FUNCDECL_RPL (isatty, int, (int fd));
-_GL_CXXALIAS_RPL (isatty, int, (int fd));
-# else
-_GL_CXXALIAS_SYS (isatty, int, (int fd));
-# endif
-_GL_CXXALIASWARN (isatty);
-#elif defined GNULIB_POSIXCHECK
-# undef isatty
-# if HAVE_RAW_DECL_ISATTY
-_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - "
- "use gnulib module isatty for portability");
-# endif
-#endif
-
-
-#if 0
-/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
- to GID (if GID is not -1). Do not follow symbolic links.
- Return 0 if successful, otherwise -1 and errno set.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef lchown
-# define lchown rpl_lchown
-# endif
-_GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
- _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
-# else
-# if !1
-_GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
- _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
-# endif
-_GL_CXXALIASWARN (lchown);
-#elif defined GNULIB_POSIXCHECK
-# undef lchown
-# if HAVE_RAW_DECL_LCHOWN
-_GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
- "use gnulib module lchown for portability");
-# endif
-#endif
-
-
-#if IN_M4_GNULIB_TESTS
-/* Create a new hard link for an existing file.
- Return 0 if successful, otherwise -1 and errno set.
- See POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define link rpl_link
-# endif
-_GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
- _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
-# else
-# if !0
-_GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
- _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
-# endif
-_GL_CXXALIASWARN (link);
-#elif defined GNULIB_POSIXCHECK
-# undef link
-# if HAVE_RAW_DECL_LINK
-_GL_WARN_ON_USE (link, "link is unportable - "
- "use gnulib module link for portability");
-# endif
-#endif
-
-
-#if 0
-/* Create a new hard link for an existing file, relative to two
- directories. FLAG controls whether symlinks are followed.
- Return 0 if successful, otherwise -1 and errno set. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef linkat
-# define linkat rpl_linkat
-# endif
-_GL_FUNCDECL_RPL (linkat, int,
- (int fd1, const char *path1, int fd2, const char *path2,
- int flag)
- _GL_ARG_NONNULL ((2, 4)));
-_GL_CXXALIAS_RPL (linkat, int,
- (int fd1, const char *path1, int fd2, const char *path2,
- int flag));
-# else
-# if !1
-_GL_FUNCDECL_SYS (linkat, int,
- (int fd1, const char *path1, int fd2, const char *path2,
- int flag)
- _GL_ARG_NONNULL ((2, 4)));
-# endif
-_GL_CXXALIAS_SYS (linkat, int,
- (int fd1, const char *path1, int fd2, const char *path2,
- int flag));
-# endif
-_GL_CXXALIASWARN (linkat);
-#elif defined GNULIB_POSIXCHECK
-# undef linkat
-# if HAVE_RAW_DECL_LINKAT
-_GL_WARN_ON_USE (linkat, "linkat is unportable - "
- "use gnulib module linkat for portability");
-# endif
-#endif
-
-
-#if 1
-/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
- Return the new offset if successful, otherwise -1 and errno set.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define lseek rpl_lseek
-# endif
-_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
-_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
-# else
-_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
-# endif
-_GL_CXXALIASWARN (lseek);
-#elif defined GNULIB_POSIXCHECK
-# undef lseek
-# if HAVE_RAW_DECL_LSEEK
-_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
- "systems - use gnulib module lseek for portability");
-# endif
-#endif
-
-
-#if 0
-/* Create a pipe, defaulting to O_BINARY mode.
- Store the read-end as fd[0] and the write-end as fd[1].
- Return 0 upon success, or -1 with errno set upon failure. */
-# if !1
-_GL_FUNCDECL_SYS (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
-# endif
-_GL_CXXALIAS_SYS (pipe, int, (int fd[2]));
-_GL_CXXALIASWARN (pipe);
-#elif defined GNULIB_POSIXCHECK
-# undef pipe
-# if HAVE_RAW_DECL_PIPE
-_GL_WARN_ON_USE (pipe, "pipe is unportable - "
- "use gnulib module pipe-posix for portability");
-# endif
-#endif
-
-
-#if 1
-/* Create a pipe, applying the given flags when opening the read-end of the
- pipe and the write-end of the pipe.
- The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
- and O_TEXT, O_BINARY (defined in "binary-io.h").
- Store the read-end as fd[0] and the write-end as fd[1].
- Return 0 upon success, or -1 with errno set upon failure.
- See also the Linux man page at
- <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define pipe2 rpl_pipe2
-# endif
-_GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
-# else
-_GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
-# endif
-_GL_CXXALIASWARN (pipe2);
-#elif defined GNULIB_POSIXCHECK
-# undef pipe2
-# if HAVE_RAW_DECL_PIPE2
-_GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
- "use gnulib module pipe2 for portability");
-# endif
-#endif
-
-
-#if 0
-/* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
- Return the number of bytes placed into BUF if successful, otherwise
- set errno and return -1. 0 indicates EOF.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef pread
-# define pread rpl_pread
-# endif
-_GL_FUNCDECL_RPL (pread, ssize_t,
- (int fd, void *buf, size_t bufsize, off_t offset)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (pread, ssize_t,
- (int fd, void *buf, size_t bufsize, off_t offset));
-# else
-# if !1
-_GL_FUNCDECL_SYS (pread, ssize_t,
- (int fd, void *buf, size_t bufsize, off_t offset)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (pread, ssize_t,
- (int fd, void *buf, size_t bufsize, off_t offset));
-# endif
-_GL_CXXALIASWARN (pread);
-#elif defined GNULIB_POSIXCHECK
-# undef pread
-# if HAVE_RAW_DECL_PREAD
-_GL_WARN_ON_USE (pread, "pread is unportable - "
- "use gnulib module pread for portability");
-# endif
-#endif
-
-
-#if 0
-/* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
- Return the number of bytes written if successful, otherwise
- set errno and return -1. 0 indicates nothing written. See the
- POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef pwrite
-# define pwrite rpl_pwrite
-# endif
-_GL_FUNCDECL_RPL (pwrite, ssize_t,
- (int fd, const void *buf, size_t bufsize, off_t offset)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (pwrite, ssize_t,
- (int fd, const void *buf, size_t bufsize, off_t offset));
-# else
-# if !1
-_GL_FUNCDECL_SYS (pwrite, ssize_t,
- (int fd, const void *buf, size_t bufsize, off_t offset)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (pwrite, ssize_t,
- (int fd, const void *buf, size_t bufsize, off_t offset));
-# endif
-_GL_CXXALIASWARN (pwrite);
-#elif defined GNULIB_POSIXCHECK
-# undef pwrite
-# if HAVE_RAW_DECL_PWRITE
-_GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
- "use gnulib module pwrite for portability");
-# endif
-#endif
-
-
-#if 0
-/* Read up to COUNT bytes from file descriptor FD into the buffer starting
- at BUF. See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef read
-# define read rpl_read
-# endif
-_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count));
-# else
-/* Need to cast, because on mingw, the third parameter is
- unsigned int count
- and the return type is 'int'. */
-_GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count));
-# endif
-_GL_CXXALIASWARN (read);
-#endif
-
-
-#if 1
-/* Read the contents of the symbolic link FILE and place the first BUFSIZE
- bytes of it into BUF. Return the number of bytes placed into BUF if
- successful, otherwise -1 and errno set.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define readlink rpl_readlink
-# endif
-_GL_FUNCDECL_RPL (readlink, ssize_t,
- (const char *file, char *buf, size_t bufsize)
- _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (readlink, ssize_t,
- (const char *file, char *buf, size_t bufsize));
-# else
-# if !0
-_GL_FUNCDECL_SYS (readlink, ssize_t,
- (const char *file, char *buf, size_t bufsize)
- _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (readlink, ssize_t,
- (const char *file, char *buf, size_t bufsize));
-# endif
-_GL_CXXALIASWARN (readlink);
-#elif defined GNULIB_POSIXCHECK
-# undef readlink
-# if HAVE_RAW_DECL_READLINK
-_GL_WARN_ON_USE (readlink, "readlink is unportable - "
- "use gnulib module readlink for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (readlinkat, ssize_t,
- (int fd, char const *file, char *buf, size_t len)
- _GL_ARG_NONNULL ((2, 3)));
-# endif
-_GL_CXXALIAS_SYS (readlinkat, ssize_t,
- (int fd, char const *file, char *buf, size_t len));
-_GL_CXXALIASWARN (readlinkat);
-#elif defined GNULIB_POSIXCHECK
-# undef readlinkat
-# if HAVE_RAW_DECL_READLINKAT
-_GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
- "use gnulib module readlinkat for portability");
-# endif
-#endif
-
-
-#if 1
-/* Remove the directory DIR. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# define rmdir rpl_rmdir
-# endif
-_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (rmdir, int, (char const *name));
-# else
-_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
-# endif
-_GL_CXXALIASWARN (rmdir);
-#elif defined GNULIB_POSIXCHECK
-# undef rmdir
-# if HAVE_RAW_DECL_RMDIR
-_GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
- "use gnulib module rmdir for portability");
-# endif
-#endif
-
-
-#if 0
-/* Set the host name of the machine.
- The host name may or may not be fully qualified.
-
- Put LEN bytes of NAME into the host name.
- Return 0 if successful, otherwise, set errno and return -1.
-
- Platforms with no ability to set the hostname return -1 and set
- errno = ENOSYS. */
-# if !1 || !1
-_GL_FUNCDECL_SYS (sethostname, int, (const char *name, size_t len)
- _GL_ARG_NONNULL ((1)));
-# endif
-/* Need to cast, because on Solaris 11 2011-10, Mac OS X 10.5, IRIX 6.5
- and FreeBSD 6.4 the second parameter is int. On Solaris 11
- 2011-10, the first parameter is not const. */
-_GL_CXXALIAS_SYS_CAST (sethostname, int, (const char *name, size_t len));
-_GL_CXXALIASWARN (sethostname);
-#elif defined GNULIB_POSIXCHECK
-# undef sethostname
-# if HAVE_RAW_DECL_SETHOSTNAME
-_GL_WARN_ON_USE (sethostname, "sethostname is unportable - "
- "use gnulib module sethostname for portability");
-# endif
-#endif
-
-
-#if IN_M4_GNULIB_TESTS
-/* Pause the execution of the current thread for N seconds.
- Returns the number of seconds left to sleep.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef sleep
-# define sleep rpl_sleep
-# endif
-_GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
-_GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
-# else
-# if !0
-_GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
-# endif
-_GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
-# endif
-_GL_CXXALIASWARN (sleep);
-#elif defined GNULIB_POSIXCHECK
-# undef sleep
-# if HAVE_RAW_DECL_SLEEP
-_GL_WARN_ON_USE (sleep, "sleep is unportable - "
- "use gnulib module sleep for portability");
-# endif
-#endif
-
-
-#if IN_M4_GNULIB_TESTS
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef symlink
-# define symlink rpl_symlink
-# endif
-_GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
- _GL_ARG_NONNULL ((1, 2)));
-_GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
-# else
-# if !0
-_GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
- _GL_ARG_NONNULL ((1, 2)));
-# endif
-_GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
-# endif
-_GL_CXXALIASWARN (symlink);
-#elif defined GNULIB_POSIXCHECK
-# undef symlink
-# if HAVE_RAW_DECL_SYMLINK
-_GL_WARN_ON_USE (symlink, "symlink is not portable - "
- "use gnulib module symlink for portability");
-# endif
-#endif
-
-
-#if 0
-# if !1
-_GL_FUNCDECL_SYS (symlinkat, int,
- (char const *contents, int fd, char const *file)
- _GL_ARG_NONNULL ((1, 3)));
-# endif
-_GL_CXXALIAS_SYS (symlinkat, int,
- (char const *contents, int fd, char const *file));
-_GL_CXXALIASWARN (symlinkat);
-#elif defined GNULIB_POSIXCHECK
-# undef symlinkat
-# if HAVE_RAW_DECL_SYMLINKAT
-_GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
- "use gnulib module symlinkat for portability");
-# endif
-#endif
-
-
-#if 0
-/* Store at most BUFLEN characters of the pathname of the terminal FD is
- open on in BUF. Return 0 on success, otherwise an error number. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef ttyname_r
-# define ttyname_r rpl_ttyname_r
-# endif
-_GL_FUNCDECL_RPL (ttyname_r, int,
- (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (ttyname_r, int,
- (int fd, char *buf, size_t buflen));
-# else
-# if !1
-_GL_FUNCDECL_SYS (ttyname_r, int,
- (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (ttyname_r, int,
- (int fd, char *buf, size_t buflen));
-# endif
-_GL_CXXALIASWARN (ttyname_r);
-#elif defined GNULIB_POSIXCHECK
-# undef ttyname_r
-# if HAVE_RAW_DECL_TTYNAME_R
-_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
- "use gnulib module ttyname_r for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef unlink
-# define unlink rpl_unlink
-# endif
-_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (unlink, int, (char const *file));
-# else
-_GL_CXXALIAS_SYS (unlink, int, (char const *file));
-# endif
-_GL_CXXALIASWARN (unlink);
-#elif defined GNULIB_POSIXCHECK
-# undef unlink
-# if HAVE_RAW_DECL_UNLINK
-_GL_WARN_ON_USE (unlink, "unlink is not portable - "
- "use gnulib module unlink for portability");
-# endif
-#endif
-
-
-#if 0
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef unlinkat
-# define unlinkat rpl_unlinkat
-# endif
-_GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
-# else
-# if !1
-_GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
- _GL_ARG_NONNULL ((2)));
-# endif
-_GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
-# endif
-_GL_CXXALIASWARN (unlinkat);
-#elif defined GNULIB_POSIXCHECK
-# undef unlinkat
-# if HAVE_RAW_DECL_UNLINKAT
-_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
- "use gnulib module openat for portability");
-# endif
-#endif
-
-
-#if 0
-/* Pause the execution of the current thread for N microseconds.
- Returns 0 on completion, or -1 on range error.
- See the POSIX:2001 specification
- <http://www.opengroup.org/susv3xsh/usleep.html>. */
-# if 0
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef usleep
-# define usleep rpl_usleep
-# endif
-_GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
-_GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
-# else
-# if !1
-_GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
-# endif
-_GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
-# endif
-_GL_CXXALIASWARN (usleep);
-#elif defined GNULIB_POSIXCHECK
-# undef usleep
-# if HAVE_RAW_DECL_USLEEP
-_GL_WARN_ON_USE (usleep, "usleep is unportable - "
- "use gnulib module usleep for portability");
-# endif
-#endif
-
-
-#if IN_M4_GNULIB_TESTS
-/* Write up to COUNT bytes starting at BUF to file descriptor FD.
- See the POSIX:2008 specification
- <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>. */
-# if 1
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-# undef write
-# define write rpl_write
-# endif
-_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
- _GL_ARG_NONNULL ((2)));
-_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
-# else
-/* Need to cast, because on mingw, the third parameter is
- unsigned int count
- and the return type is 'int'. */
-_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count));
-# endif
-_GL_CXXALIASWARN (write);
-#endif
-
-_GL_INLINE_HEADER_END
-
-#endif /* _GL_M4_UNISTD_H */
-#endif /* _GL_M4_UNISTD_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Substitute for and wrapper around <unistd.h>.
+ Copyright (C) 2003-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_M4_UNISTD_H
+
+#if __GNUC__ >= 3
+
+#endif
+
+
+/* The include_next requires a split double-inclusion guard. */
+#if 0
+# include <unistd.h>
+#endif
+
+/* Get all possible declarations of gethostname(). */
+#if 0 && 0 \
+ && !defined _GL_INCLUDING_WINSOCK2_H
+# define _GL_INCLUDING_WINSOCK2_H
+# include <winsock2.h>
+# undef _GL_INCLUDING_WINSOCK2_H
+#endif
+
+#if !defined _GL_M4_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
+#define _GL_M4_UNISTD_H
+
+/* NetBSD 5.0 mis-defines NULL. Also get size_t. */
+#include <stddef.h>
+
+/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
+/* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
+/* But avoid namespace pollution on glibc systems. */
+#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
+ || ((0 || defined GNULIB_POSIXCHECK) \
+ && defined __CYGWIN__)) \
+ && ! defined __GLIBC__
+# include <stdio.h>
+#endif
+
+/* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */
+/* But avoid namespace pollution on glibc systems. */
+#if (0 || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \
+ && ! defined __GLIBC__
+# include <fcntl.h>
+#endif
+
+/* mingw fails to declare _exit in <unistd.h>. */
+/* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in
+ <unistd.h>. */
+/* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
+/* OSF Tru64 Unix cannot see gnulib rpl_strtod when system <stdlib.h> is
+ included here. */
+/* But avoid namespace pollution on glibc systems. */
+#if !defined __GLIBC__ && !defined __osf__
+# define __need_system_stdlib_h
+# include <stdlib.h>
+# undef __need_system_stdlib_h
+#endif
+
+/* Native Windows platforms declare chdir, getcwd, rmdir in
+ <io.h> and/or <direct.h>, not in <unistd.h>.
+ They also declare access(), chmod(), close(), dup(), dup2(), isatty(),
+ lseek(), read(), unlink(), write() in <io.h>. */
+#if ((1 || IN_M4_GNULIB_TESTS || 1 \
+ || defined GNULIB_POSIXCHECK) \
+ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
+# include <io.h> /* mingw32, mingw64 */
+# include <direct.h> /* mingw64, MSVC 9 */
+#elif (1 || IN_M4_GNULIB_TESTS || 1 || 0 \
+ || 1 || 0 || 0 || IN_M4_GNULIB_TESTS \
+ || defined GNULIB_POSIXCHECK) \
+ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+# include <io.h>
+#endif
+
+/* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
+ NonStop Kernel declares gethostname in <netdb.h>, not in <unistd.h>. */
+/* But avoid namespace pollution on glibc systems. */
+#if ((0 && (defined _AIX || defined __osf__)) \
+ || (0 && defined __TANDEM)) \
+ && !defined __GLIBC__
+# include <netdb.h>
+#endif
+
+/* MSVC defines off_t in <sys/types.h>.
+ May also define off_t to a 64-bit type on native Windows. */
+#if !0 || 1
+/* Get off_t. */
+# include <sys/types.h>
+#endif
+
+#if (0 || IN_M4_GNULIB_TESTS \
+ || 1 || 0 \
+ || 0 || 0 || defined GNULIB_POSIXCHECK)
+/* Get ssize_t. */
+# include <sys/types.h>
+#endif
+
+/* Get getopt(), optarg, optind, opterr, optopt.
+ But avoid namespace pollution on glibc systems. */
+#if 01 && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
+# define __need_getopt
+# include <getopt.h>
+#endif
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+# error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef _GL_UNISTD_INLINE
+# define _GL_UNISTD_INLINE _GL_INLINE
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+#ifndef _GL_CXXDEFS_H
+#define _GL_CXXDEFS_H
+
+
+/* _GL_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#if defined __cplusplus
+# define _GL_EXTERN_C extern "C"
+#else
+# define _GL_EXTERN_C extern
+#endif
+
+/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
+ declares a replacement function, named rpl_func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
+ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
+#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype rpl_func parameters_and_attributes
+
+/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
+ declares the system function, named func, with the given prototype,
+ consisting of return type, parameters, and attributes.
+ Example:
+ _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
+ _GL_ARG_NONNULL ((1)));
+ */
+#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C rettype func parameters_and_attributes
+
+/* _GL_CXXALIAS_RPL (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
+ Example:
+ _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
+ */
+#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
+ _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = ::rpl_func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
+ is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
+ except that the C function rpl_func may have a slightly different
+ declaration. A cast is used to silence the "invalid conversion" error
+ that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ rettype (*const func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::rpl_func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS (func, rettype, parameters);
+ declares a C++ alias called GNULIB_NAMESPACE::func
+ that redirects to the system provided function func, if GNULIB_NAMESPACE
+ is defined.
+ Example:
+ _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+ */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* If we were to write
+ rettype (*const func) parameters = ::func;
+ like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
+ better (remove an indirection through a 'static' pointer variable),
+ but then the _GL_CXXALIASWARN macro below would cause a warning not only
+ for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = ::func; \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function func may have a slightly different declaration.
+ A cast is used to silence the "invalid conversion" error that would
+ otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>(::func); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
+ is like _GL_CXXALIAS_SYS (func, rettype, parameters);
+ except that the C function is picked among a set of overloaded functions,
+ namely the one with rettype2 and parameters2. Two consecutive casts
+ are used to silence the "cannot find a match" and "invalid conversion"
+ errors that would otherwise occur. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+ /* The outer cast must be a reinterpret_cast.
+ The inner cast: When the function is defined as a set of overloaded
+ functions, it works as a static_cast<>, choosing the designated variant.
+ When the function is defined as a single variant, it works as a
+ reinterpret_cast<>. The parenthesized cast syntax works both ways. */
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ namespace GNULIB_NAMESPACE \
+ { \
+ static rettype (*func) parameters = \
+ reinterpret_cast<rettype(*)parameters>( \
+ (rettype2(*)parameters2)(::func)); \
+ } \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#else
+# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN (func);
+ causes a warning to be emitted when ::func is used but not when
+ GNULIB_NAMESPACE::func is used. func must be defined without overloaded
+ variants. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN(func) \
+ _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN_1(func,namespace) \
+ _GL_CXXALIASWARN_2 (func, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_WARN_ON_USE (func, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN_2(func,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN(func) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
+ causes a warning to be emitted when the given overloaded variant of ::func
+ is used but not when GNULIB_NAMESPACE::func is used. */
+#if defined __cplusplus && defined GNULIB_NAMESPACE
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
+ GNULIB_NAMESPACE)
+# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
+ _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
+/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
+ we enable the warning only when not optimizing. */
+# if !__OPTIMIZE__
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
+ "The symbol ::" #func " refers to the system function. " \
+ "Use " #namespace "::" #func " instead.")
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ extern __typeof__ (func) func
+# else
+# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+# endif
+#else
+# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
+ _GL_EXTERN_C int _gl_cxxalias_dummy
+#endif
+
+#endif /* _GL_CXXDEFS_H */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
+ that the values passed as arguments n, ..., m must be non-NULL pointers.
+ n = 1 stands for the first argument, n = 2 for the second argument etc. */
+#ifndef _GL_ARG_NONNULL
+# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
+# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
+# else
+# define _GL_ARG_NONNULL(params)
+# endif
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+#ifndef _GL_WARN_ON_USE
+
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+/* A compiler attribute is available in gcc versions 4.3.0 and later. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE(function, message) \
+extern __typeof__ (function) function
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE(function, message) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
+ is like _GL_WARN_ON_USE (function, "string"), except that the function is
+ declared with the given prototype, consisting of return type, parameters,
+ and attributes.
+ This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
+ not work in this case. */
+#ifndef _GL_WARN_ON_USE_CXX
+# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes \
+ __attribute__ ((__warning__ (msg)))
+# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
+/* Verify the existence of the function. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+extern rettype function parameters_and_attributes
+# else /* Unsupported. */
+# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
+_GL_WARN_EXTERN_C int _gl_warn_on_use
+# endif
+#endif
+
+/* _GL_WARN_EXTERN_C declaration;
+ performs the declaration with C linkage. */
+#ifndef _GL_WARN_EXTERN_C
+# if defined __cplusplus
+# define _GL_WARN_EXTERN_C extern "C"
+# else
+# define _GL_WARN_EXTERN_C extern
+# endif
+#endif
+
+
+/* Hide some function declarations from <winsock2.h>. */
+
+#if 0 && 0
+# if !defined _GL_M4_SYS_SOCKET_H
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef socket
+# define socket socket_used_without_including_sys_socket_h
+# undef connect
+# define connect connect_used_without_including_sys_socket_h
+# undef accept
+# define accept accept_used_without_including_sys_socket_h
+# undef bind
+# define bind bind_used_without_including_sys_socket_h
+# undef getpeername
+# define getpeername getpeername_used_without_including_sys_socket_h
+# undef getsockname
+# define getsockname getsockname_used_without_including_sys_socket_h
+# undef getsockopt
+# define getsockopt getsockopt_used_without_including_sys_socket_h
+# undef listen
+# define listen listen_used_without_including_sys_socket_h
+# undef recv
+# define recv recv_used_without_including_sys_socket_h
+# undef send
+# define send send_used_without_including_sys_socket_h
+# undef recvfrom
+# define recvfrom recvfrom_used_without_including_sys_socket_h
+# undef sendto
+# define sendto sendto_used_without_including_sys_socket_h
+# undef setsockopt
+# define setsockopt setsockopt_used_without_including_sys_socket_h
+# undef shutdown
+# define shutdown shutdown_used_without_including_sys_socket_h
+# else
+ _GL_WARN_ON_USE (socket,
+ "socket() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (connect,
+ "connect() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (accept,
+ "accept() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (bind,
+ "bind() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (getpeername,
+ "getpeername() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (getsockname,
+ "getsockname() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (getsockopt,
+ "getsockopt() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (listen,
+ "listen() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (recv,
+ "recv() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (send,
+ "send() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (recvfrom,
+ "recvfrom() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (sendto,
+ "sendto() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (setsockopt,
+ "setsockopt() used without including <sys/socket.h>");
+ _GL_WARN_ON_USE (shutdown,
+ "shutdown() used without including <sys/socket.h>");
+# endif
+# endif
+# if !defined _GL_M4_SYS_SELECT_H
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef select
+# define select select_used_without_including_sys_select_h
+# else
+ _GL_WARN_ON_USE (select,
+ "select() used without including <sys/select.h>");
+# endif
+# endif
+#endif
+
+
+/* OS/2 EMX lacks these macros. */
+#ifndef STDIN_FILENO
+# define STDIN_FILENO 0
+#endif
+#ifndef STDOUT_FILENO
+# define STDOUT_FILENO 1
+#endif
+#ifndef STDERR_FILENO
+# define STDERR_FILENO 2
+#endif
+
+/* Ensure *_OK macros exist. */
+#ifndef F_OK
+# define F_OK 0
+# define X_OK 1
+# define W_OK 2
+# define R_OK 4
+#endif
+
+
+/* Declare overridden functions. */
+
+
+#if defined GNULIB_POSIXCHECK
+/* The access() function is a security risk. */
+_GL_WARN_ON_USE (access, "the access function is a security risk - "
+ "use the gnulib module faccessat instead");
+#endif
+
+
+#if 1
+_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIASWARN (chdir);
+#elif defined GNULIB_POSIXCHECK
+# undef chdir
+# if HAVE_RAW_DECL_CHDIR
+_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - "
+ "use gnulib module chdir for portability");
+# endif
+#endif
+
+
+#if 0
+/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
+ to GID (if GID is not -1). Follow symbolic links.
+ Return 0 if successful, otherwise -1 and errno set.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef chown
+# define chown rpl_chown
+# endif
+_GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
+# else
+# if !1
+_GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
+# endif
+_GL_CXXALIASWARN (chown);
+#elif defined GNULIB_POSIXCHECK
+# undef chown
+# if HAVE_RAW_DECL_CHOWN
+_GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
+ "doesn't treat a uid or gid of -1 on some systems - "
+ "use gnulib module chown for portability");
+# endif
+#endif
+
+
+#if 1
+# if 1
+/* Automatically included by modules that need a replacement for close. */
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef close
+# define close rpl_close
+# endif
+_GL_FUNCDECL_RPL (close, int, (int fd));
+_GL_CXXALIAS_RPL (close, int, (int fd));
+# else
+_GL_CXXALIAS_SYS (close, int, (int fd));
+# endif
+_GL_CXXALIASWARN (close);
+#elif 0
+# undef close
+# define close close_used_without_requesting_gnulib_module_close
+#elif defined GNULIB_POSIXCHECK
+# undef close
+/* Assume close is always declared. */
+_GL_WARN_ON_USE (close, "close does not portably work on sockets - "
+ "use gnulib module close for portability");
+#endif
+
+
+#if IN_M4_GNULIB_TESTS
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define dup rpl_dup
+# endif
+_GL_FUNCDECL_RPL (dup, int, (int oldfd));
+_GL_CXXALIAS_RPL (dup, int, (int oldfd));
+# else
+_GL_CXXALIAS_SYS (dup, int, (int oldfd));
+# endif
+_GL_CXXALIASWARN (dup);
+#elif defined GNULIB_POSIXCHECK
+# undef dup
+# if HAVE_RAW_DECL_DUP
+_GL_WARN_ON_USE (dup, "dup is unportable - "
+ "use gnulib module dup for portability");
+# endif
+#endif
+
+
+#if 1
+/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
+ NEWFD = OLDFD, otherwise close NEWFD first if it is open.
+ Return newfd if successful, otherwise -1 and errno set.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define dup2 rpl_dup2
+# endif
+_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
+_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
+# else
+# if !1
+_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
+# endif
+_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
+# endif
+_GL_CXXALIASWARN (dup2);
+#elif defined GNULIB_POSIXCHECK
+# undef dup2
+# if HAVE_RAW_DECL_DUP2
+_GL_WARN_ON_USE (dup2, "dup2 is unportable - "
+ "use gnulib module dup2 for portability");
+# endif
+#endif
+
+
+#if 0
+/* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
+ specified flags.
+ The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
+ and O_TEXT, O_BINARY (defined in "binary-io.h").
+ Close NEWFD first if it is open.
+ Return newfd if successful, otherwise -1 and errno set.
+ See the Linux man page at
+ <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define dup3 rpl_dup3
+# endif
+_GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
+_GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
+# else
+_GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
+_GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
+# endif
+_GL_CXXALIASWARN (dup3);
+#elif defined GNULIB_POSIXCHECK
+# undef dup3
+# if HAVE_RAW_DECL_DUP3
+_GL_WARN_ON_USE (dup3, "dup3 is unportable - "
+ "use gnulib module dup3 for portability");
+# endif
+#endif
+
+
+#if 1
+# if !1
+/* Set of environment variables and values. An array of strings of the form
+ "VARIABLE=VALUE", terminated with a NULL. */
+# if defined __APPLE__ && defined __MACH__
+# include <crt_externs.h>
+# define environ (*_NSGetEnviron ())
+# else
+# ifdef __cplusplus
+extern "C" {
+# endif
+extern char **environ;
+# ifdef __cplusplus
+}
+# endif
+# endif
+# endif
+#elif defined GNULIB_POSIXCHECK
+# if HAVE_RAW_DECL_ENVIRON
+_GL_UNISTD_INLINE char ***
+rpl_environ (void)
+{
+ return &environ;
+}
+_GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
+ "use gnulib module environ for portability");
+# undef environ
+# define environ (*rpl_environ ())
+# endif
+#endif
+
+
+#if 0
+/* Like access(), except that it uses the effective user id and group id of
+ the current process. */
+# if !1
+_GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
+_GL_CXXALIASWARN (euidaccess);
+# if defined GNULIB_POSIXCHECK
+/* Like access(), this function is a security risk. */
+_GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
+ "use the gnulib module faccessat instead");
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef euidaccess
+# if HAVE_RAW_DECL_EUIDACCESS
+_GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
+ "use gnulib module euidaccess for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (faccessat, int,
+ (int fd, char const *file, int mode, int flag)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (faccessat, int,
+ (int fd, char const *file, int mode, int flag));
+_GL_CXXALIASWARN (faccessat);
+#elif defined GNULIB_POSIXCHECK
+# undef faccessat
+# if HAVE_RAW_DECL_FACCESSAT
+_GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
+ "use gnulib module faccessat for portability");
+# endif
+#endif
+
+
+#if 0
+/* Change the process' current working directory to the directory on which
+ the given file descriptor is open.
+ Return 0 if successful, otherwise -1 and errno set.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */
+# if ! 1
+_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
+
+/* Gnulib internal hooks needed to maintain the fchdir metadata. */
+_GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
+ _GL_ARG_NONNULL ((2));
+_GL_EXTERN_C void _gl_unregister_fd (int fd);
+_GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
+_GL_EXTERN_C const char *_gl_directory_name (int fd);
+
+# else
+# if !1
+_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
+# endif
+# endif
+_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
+_GL_CXXALIASWARN (fchdir);
+#elif defined GNULIB_POSIXCHECK
+# undef fchdir
+# if HAVE_RAW_DECL_FCHDIR
+_GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
+ "use gnulib module fchdir for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef fchownat
+# define fchownat rpl_fchownat
+# endif
+_GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
+ uid_t owner, gid_t group, int flag)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
+ uid_t owner, gid_t group, int flag));
+# else
+# if !1
+_GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
+ uid_t owner, gid_t group, int flag)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
+ uid_t owner, gid_t group, int flag));
+# endif
+_GL_CXXALIASWARN (fchownat);
+#elif defined GNULIB_POSIXCHECK
+# undef fchownat
+# if HAVE_RAW_DECL_FCHOWNAT
+_GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
+ "use gnulib module openat for portability");
+# endif
+#endif
+
+
+#if 0
+/* Synchronize changes to a file.
+ Return 0 if successful, otherwise -1 and errno set.
+ See POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. */
+# if !1 || !1
+_GL_FUNCDECL_SYS (fdatasync, int, (int fd));
+# endif
+_GL_CXXALIAS_SYS (fdatasync, int, (int fd));
+_GL_CXXALIASWARN (fdatasync);
+#elif defined GNULIB_POSIXCHECK
+# undef fdatasync
+# if HAVE_RAW_DECL_FDATASYNC
+_GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - "
+ "use gnulib module fdatasync for portability");
+# endif
+#endif
+
+
+#if 0
+/* Synchronize changes, including metadata, to a file.
+ Return 0 if successful, otherwise -1 and errno set.
+ See POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>. */
+# if !1
+_GL_FUNCDECL_SYS (fsync, int, (int fd));
+# endif
+_GL_CXXALIAS_SYS (fsync, int, (int fd));
+_GL_CXXALIASWARN (fsync);
+#elif defined GNULIB_POSIXCHECK
+# undef fsync
+# if HAVE_RAW_DECL_FSYNC
+_GL_WARN_ON_USE (fsync, "fsync is unportable - "
+ "use gnulib module fsync for portability");
+# endif
+#endif
+
+
+#if 0
+/* Change the size of the file to which FD is opened to become equal to LENGTH.
+ Return 0 if successful, otherwise -1 and errno set.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ftruncate
+# define ftruncate rpl_ftruncate
+# endif
+_GL_FUNCDECL_RPL (ftruncate, int, (int fd, off_t length));
+_GL_CXXALIAS_RPL (ftruncate, int, (int fd, off_t length));
+# else
+# if !1
+_GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
+# endif
+_GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
+# endif
+_GL_CXXALIASWARN (ftruncate);
+#elif defined GNULIB_POSIXCHECK
+# undef ftruncate
+# if HAVE_RAW_DECL_FTRUNCATE
+_GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
+ "use gnulib module ftruncate for portability");
+# endif
+#endif
+
+
+#if IN_M4_GNULIB_TESTS
+/* Get the name of the current working directory, and put it in SIZE bytes
+ of BUF.
+ Return BUF if successful, or NULL if the directory couldn't be determined
+ or SIZE was too small.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
+ Additionally, the gnulib module 'getcwd' guarantees the following GNU
+ extension: If BUF is NULL, an array is allocated with 'malloc'; the array
+ is SIZE bytes long, unless SIZE == 0, in which case it is as big as
+ necessary. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define getcwd rpl_getcwd
+# endif
+_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
+_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
+# else
+/* Need to cast, because on mingw, the second parameter is
+ int size. */
+_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
+# endif
+_GL_CXXALIASWARN (getcwd);
+#elif defined GNULIB_POSIXCHECK
+# undef getcwd
+# if HAVE_RAW_DECL_GETCWD
+_GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
+ "use gnulib module getcwd for portability");
+# endif
+#endif
+
+
+#if 0
+/* Return the NIS domain name of the machine.
+ WARNING! The NIS domain name is unrelated to the fully qualified host name
+ of the machine. It is also unrelated to email addresses.
+ WARNING! The NIS domain name is usually the empty string or "(none)" when
+ not using NIS.
+
+ Put up to LEN bytes of the NIS domain name into NAME.
+ Null terminate it if the name is shorter than LEN.
+ If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
+ Return 0 if successful, otherwise set errno and return -1. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef getdomainname
+# define getdomainname rpl_getdomainname
+# endif
+_GL_FUNCDECL_RPL (getdomainname, int, (char *name, size_t len)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (getdomainname, int, (char *name, size_t len));
+# else
+# if !1
+_GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len));
+# endif
+_GL_CXXALIASWARN (getdomainname);
+#elif defined GNULIB_POSIXCHECK
+# undef getdomainname
+# if HAVE_RAW_DECL_GETDOMAINNAME
+_GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
+ "use gnulib module getdomainname for portability");
+# endif
+#endif
+
+
+#if 1
+/* Return the maximum number of file descriptors in the current process.
+ In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
+# if !0
+_GL_FUNCDECL_SYS (getdtablesize, int, (void));
+# endif
+_GL_CXXALIAS_SYS (getdtablesize, int, (void));
+_GL_CXXALIASWARN (getdtablesize);
+#elif defined GNULIB_POSIXCHECK
+# undef getdtablesize
+# if HAVE_RAW_DECL_GETDTABLESIZE
+_GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
+ "use gnulib module getdtablesize for portability");
+# endif
+#endif
+
+
+#if 0
+/* Return the supplemental groups that the current process belongs to.
+ It is unspecified whether the effective group id is in the list.
+ If N is 0, return the group count; otherwise, N describes how many
+ entries are available in GROUPS. Return -1 and set errno if N is
+ not 0 and not large enough. Fails with ENOSYS on some systems. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef getgroups
+# define getgroups rpl_getgroups
+# endif
+_GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
+_GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
+# else
+# if !1
+_GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
+# endif
+_GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
+# endif
+_GL_CXXALIASWARN (getgroups);
+#elif defined GNULIB_POSIXCHECK
+# undef getgroups
+# if HAVE_RAW_DECL_GETGROUPS
+_GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
+ "use gnulib module getgroups for portability");
+# endif
+#endif
+
+
+#if 0
+/* Return the standard host name of the machine.
+ WARNING! The host name may or may not be fully qualified.
+
+ Put up to LEN bytes of the host name into NAME.
+ Null terminate it if the name is shorter than LEN.
+ If the host name is longer than LEN, set errno = EINVAL and return -1.
+ Return 0 if successful, otherwise set errno and return -1. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef gethostname
+# define gethostname rpl_gethostname
+# endif
+_GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
+# else
+# if !1
+_GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
+ _GL_ARG_NONNULL ((1)));
+# endif
+/* Need to cast, because on Solaris 10 and OSF/1 5.1 systems, the second
+ parameter is
+ int len. */
+_GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
+# endif
+_GL_CXXALIASWARN (gethostname);
+#elif 0
+# undef gethostname
+# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
+#elif defined GNULIB_POSIXCHECK
+# undef gethostname
+# if HAVE_RAW_DECL_GETHOSTNAME
+_GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
+ "use gnulib module gethostname for portability");
+# endif
+#endif
+
+
+#if 0
+/* Returns the user's login name, or NULL if it cannot be found. Upon error,
+ returns NULL with errno set.
+
+ See <http://www.opengroup.org/susv3xsh/getlogin.html>.
+
+ Most programs don't need to use this function, because the information is
+ available through environment variables:
+ ${LOGNAME-$USER} on Unix platforms,
+ $USERNAME on native Windows platforms.
+ */
+# if !1
+_GL_FUNCDECL_SYS (getlogin, char *, (void));
+# endif
+_GL_CXXALIAS_SYS (getlogin, char *, (void));
+_GL_CXXALIASWARN (getlogin);
+#elif defined GNULIB_POSIXCHECK
+# undef getlogin
+# if HAVE_RAW_DECL_GETLOGIN
+_GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
+ "use gnulib module getlogin for portability");
+# endif
+#endif
+
+
+#if 0
+/* Copies the user's login name to NAME.
+ The array pointed to by NAME has room for SIZE bytes.
+
+ Returns 0 if successful. Upon error, an error number is returned, or -1 in
+ the case that the login name cannot be found but no specific error is
+ provided (this case is hopefully rare but is left open by the POSIX spec).
+
+ See <http://www.opengroup.org/susv3xsh/getlogin.html>.
+
+ Most programs don't need to use this function, because the information is
+ available through environment variables:
+ ${LOGNAME-$USER} on Unix platforms,
+ $USERNAME on native Windows platforms.
+ */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define getlogin_r rpl_getlogin_r
+# endif
+_GL_FUNCDECL_RPL (getlogin_r, int, (char *name, size_t size)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (getlogin_r, int, (char *name, size_t size));
+# else
+# if !1
+_GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
+ _GL_ARG_NONNULL ((1)));
+# endif
+/* Need to cast, because on Solaris 10 systems, the second argument is
+ int size. */
+_GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
+# endif
+_GL_CXXALIASWARN (getlogin_r);
+#elif defined GNULIB_POSIXCHECK
+# undef getlogin_r
+# if HAVE_RAW_DECL_GETLOGIN_R
+_GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
+ "use gnulib module getlogin_r for portability");
+# endif
+#endif
+
+
+#if IN_M4_GNULIB_TESTS
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define getpagesize rpl_getpagesize
+# endif
+_GL_FUNCDECL_RPL (getpagesize, int, (void));
+_GL_CXXALIAS_RPL (getpagesize, int, (void));
+# else
+# if !0
+# if !defined getpagesize
+/* This is for POSIX systems. */
+# if !defined _gl_getpagesize && defined _SC_PAGESIZE
+# if ! (defined __VMS && __VMS_VER < 70000000)
+# define _gl_getpagesize() sysconf (_SC_PAGESIZE)
+# endif
+# endif
+/* This is for older VMS. */
+# if !defined _gl_getpagesize && defined __VMS
+# ifdef __ALPHA
+# define _gl_getpagesize() 8192
+# else
+# define _gl_getpagesize() 512
+# endif
+# endif
+/* This is for BeOS. */
+# if !defined _gl_getpagesize && 0
+# include <OS.h>
+# if defined B_PAGE_SIZE
+# define _gl_getpagesize() B_PAGE_SIZE
+# endif
+# endif
+/* This is for AmigaOS4.0. */
+# if !defined _gl_getpagesize && defined __amigaos4__
+# define _gl_getpagesize() 2048
+# endif
+/* This is for older Unix systems. */
+# if !defined _gl_getpagesize && 0
+# include <sys/param.h>
+# ifdef EXEC_PAGESIZE
+# define _gl_getpagesize() EXEC_PAGESIZE
+# else
+# ifdef NBPG
+# ifndef CLSIZE
+# define CLSIZE 1
+# endif
+# define _gl_getpagesize() (NBPG * CLSIZE)
+# else
+# ifdef NBPC
+# define _gl_getpagesize() NBPC
+# endif
+# endif
+# endif
+# endif
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define getpagesize() _gl_getpagesize ()
+# else
+# if !GNULIB_defined_getpagesize_function
+_GL_UNISTD_INLINE int
+getpagesize ()
+{
+ return _gl_getpagesize ();
+}
+# define GNULIB_defined_getpagesize_function 1
+# endif
+# endif
+# endif
+# endif
+/* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
+_GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
+# endif
+# if 0
+_GL_CXXALIASWARN (getpagesize);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getpagesize
+# if HAVE_RAW_DECL_GETPAGESIZE
+_GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
+ "use gnulib module getpagesize for portability");
+# endif
+#endif
+
+
+#if 0
+/* Return the next valid login shell on the system, or NULL when the end of
+ the list has been reached. */
+# if !1
+_GL_FUNCDECL_SYS (getusershell, char *, (void));
+# endif
+_GL_CXXALIAS_SYS (getusershell, char *, (void));
+_GL_CXXALIASWARN (getusershell);
+#elif defined GNULIB_POSIXCHECK
+# undef getusershell
+# if HAVE_RAW_DECL_GETUSERSHELL
+_GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
+ "use gnulib module getusershell for portability");
+# endif
+#endif
+
+#if 0
+/* Rewind to pointer that is advanced at each getusershell() call. */
+# if !1
+_GL_FUNCDECL_SYS (setusershell, void, (void));
+# endif
+_GL_CXXALIAS_SYS (setusershell, void, (void));
+_GL_CXXALIASWARN (setusershell);
+#elif defined GNULIB_POSIXCHECK
+# undef setusershell
+# if HAVE_RAW_DECL_SETUSERSHELL
+_GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
+ "use gnulib module getusershell for portability");
+# endif
+#endif
+
+#if 0
+/* Free the pointer that is advanced at each getusershell() call and
+ associated resources. */
+# if !1
+_GL_FUNCDECL_SYS (endusershell, void, (void));
+# endif
+_GL_CXXALIAS_SYS (endusershell, void, (void));
+_GL_CXXALIASWARN (endusershell);
+#elif defined GNULIB_POSIXCHECK
+# undef endusershell
+# if HAVE_RAW_DECL_ENDUSERSHELL
+_GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
+ "use gnulib module getusershell for portability");
+# endif
+#endif
+
+
+#if 0
+/* Determine whether group id is in calling user's group list. */
+# if !1
+_GL_FUNCDECL_SYS (group_member, int, (gid_t gid));
+# endif
+_GL_CXXALIAS_SYS (group_member, int, (gid_t gid));
+_GL_CXXALIASWARN (group_member);
+#elif defined GNULIB_POSIXCHECK
+# undef group_member
+# if HAVE_RAW_DECL_GROUP_MEMBER
+_GL_WARN_ON_USE (group_member, "group_member is unportable - "
+ "use gnulib module group-member for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef isatty
+# define isatty rpl_isatty
+# endif
+_GL_FUNCDECL_RPL (isatty, int, (int fd));
+_GL_CXXALIAS_RPL (isatty, int, (int fd));
+# else
+_GL_CXXALIAS_SYS (isatty, int, (int fd));
+# endif
+_GL_CXXALIASWARN (isatty);
+#elif defined GNULIB_POSIXCHECK
+# undef isatty
+# if HAVE_RAW_DECL_ISATTY
+_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - "
+ "use gnulib module isatty for portability");
+# endif
+#endif
+
+
+#if 0
+/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
+ to GID (if GID is not -1). Do not follow symbolic links.
+ Return 0 if successful, otherwise -1 and errno set.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef lchown
+# define lchown rpl_lchown
+# endif
+_GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
+# else
+# if !1
+_GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
+# endif
+_GL_CXXALIASWARN (lchown);
+#elif defined GNULIB_POSIXCHECK
+# undef lchown
+# if HAVE_RAW_DECL_LCHOWN
+_GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
+ "use gnulib module lchown for portability");
+# endif
+#endif
+
+
+#if IN_M4_GNULIB_TESTS
+/* Create a new hard link for an existing file.
+ Return 0 if successful, otherwise -1 and errno set.
+ See POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define link rpl_link
+# endif
+_GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
+# else
+# if !0
+_GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
+ _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
+# endif
+_GL_CXXALIASWARN (link);
+#elif defined GNULIB_POSIXCHECK
+# undef link
+# if HAVE_RAW_DECL_LINK
+_GL_WARN_ON_USE (link, "link is unportable - "
+ "use gnulib module link for portability");
+# endif
+#endif
+
+
+#if 0
+/* Create a new hard link for an existing file, relative to two
+ directories. FLAG controls whether symlinks are followed.
+ Return 0 if successful, otherwise -1 and errno set. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef linkat
+# define linkat rpl_linkat
+# endif
+_GL_FUNCDECL_RPL (linkat, int,
+ (int fd1, const char *path1, int fd2, const char *path2,
+ int flag)
+ _GL_ARG_NONNULL ((2, 4)));
+_GL_CXXALIAS_RPL (linkat, int,
+ (int fd1, const char *path1, int fd2, const char *path2,
+ int flag));
+# else
+# if !1
+_GL_FUNCDECL_SYS (linkat, int,
+ (int fd1, const char *path1, int fd2, const char *path2,
+ int flag)
+ _GL_ARG_NONNULL ((2, 4)));
+# endif
+_GL_CXXALIAS_SYS (linkat, int,
+ (int fd1, const char *path1, int fd2, const char *path2,
+ int flag));
+# endif
+_GL_CXXALIASWARN (linkat);
+#elif defined GNULIB_POSIXCHECK
+# undef linkat
+# if HAVE_RAW_DECL_LINKAT
+_GL_WARN_ON_USE (linkat, "linkat is unportable - "
+ "use gnulib module linkat for portability");
+# endif
+#endif
+
+
+#if 1
+/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
+ Return the new offset if successful, otherwise -1 and errno set.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define lseek rpl_lseek
+# endif
+_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
+_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
+# else
+_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
+# endif
+_GL_CXXALIASWARN (lseek);
+#elif defined GNULIB_POSIXCHECK
+# undef lseek
+# if HAVE_RAW_DECL_LSEEK
+_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
+ "systems - use gnulib module lseek for portability");
+# endif
+#endif
+
+
+#if 0
+/* Create a pipe, defaulting to O_BINARY mode.
+ Store the read-end as fd[0] and the write-end as fd[1].
+ Return 0 upon success, or -1 with errno set upon failure. */
+# if !1
+_GL_FUNCDECL_SYS (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (pipe, int, (int fd[2]));
+_GL_CXXALIASWARN (pipe);
+#elif defined GNULIB_POSIXCHECK
+# undef pipe
+# if HAVE_RAW_DECL_PIPE
+_GL_WARN_ON_USE (pipe, "pipe is unportable - "
+ "use gnulib module pipe-posix for portability");
+# endif
+#endif
+
+
+#if 1
+/* Create a pipe, applying the given flags when opening the read-end of the
+ pipe and the write-end of the pipe.
+ The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
+ and O_TEXT, O_BINARY (defined in "binary-io.h").
+ Store the read-end as fd[0] and the write-end as fd[1].
+ Return 0 upon success, or -1 with errno set upon failure.
+ See also the Linux man page at
+ <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define pipe2 rpl_pipe2
+# endif
+_GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
+# else
+_GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
+# endif
+_GL_CXXALIASWARN (pipe2);
+#elif defined GNULIB_POSIXCHECK
+# undef pipe2
+# if HAVE_RAW_DECL_PIPE2
+_GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
+ "use gnulib module pipe2 for portability");
+# endif
+#endif
+
+
+#if 0
+/* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
+ Return the number of bytes placed into BUF if successful, otherwise
+ set errno and return -1. 0 indicates EOF.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef pread
+# define pread rpl_pread
+# endif
+_GL_FUNCDECL_RPL (pread, ssize_t,
+ (int fd, void *buf, size_t bufsize, off_t offset)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (pread, ssize_t,
+ (int fd, void *buf, size_t bufsize, off_t offset));
+# else
+# if !1
+_GL_FUNCDECL_SYS (pread, ssize_t,
+ (int fd, void *buf, size_t bufsize, off_t offset)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (pread, ssize_t,
+ (int fd, void *buf, size_t bufsize, off_t offset));
+# endif
+_GL_CXXALIASWARN (pread);
+#elif defined GNULIB_POSIXCHECK
+# undef pread
+# if HAVE_RAW_DECL_PREAD
+_GL_WARN_ON_USE (pread, "pread is unportable - "
+ "use gnulib module pread for portability");
+# endif
+#endif
+
+
+#if 0
+/* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
+ Return the number of bytes written if successful, otherwise
+ set errno and return -1. 0 indicates nothing written. See the
+ POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef pwrite
+# define pwrite rpl_pwrite
+# endif
+_GL_FUNCDECL_RPL (pwrite, ssize_t,
+ (int fd, const void *buf, size_t bufsize, off_t offset)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (pwrite, ssize_t,
+ (int fd, const void *buf, size_t bufsize, off_t offset));
+# else
+# if !1
+_GL_FUNCDECL_SYS (pwrite, ssize_t,
+ (int fd, const void *buf, size_t bufsize, off_t offset)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (pwrite, ssize_t,
+ (int fd, const void *buf, size_t bufsize, off_t offset));
+# endif
+_GL_CXXALIASWARN (pwrite);
+#elif defined GNULIB_POSIXCHECK
+# undef pwrite
+# if HAVE_RAW_DECL_PWRITE
+_GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
+ "use gnulib module pwrite for portability");
+# endif
+#endif
+
+
+#if 0
+/* Read up to COUNT bytes from file descriptor FD into the buffer starting
+ at BUF. See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef read
+# define read rpl_read
+# endif
+_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count));
+# else
+/* Need to cast, because on mingw, the third parameter is
+ unsigned int count
+ and the return type is 'int'. */
+_GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count));
+# endif
+_GL_CXXALIASWARN (read);
+#endif
+
+
+#if 1
+/* Read the contents of the symbolic link FILE and place the first BUFSIZE
+ bytes of it into BUF. Return the number of bytes placed into BUF if
+ successful, otherwise -1 and errno set.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define readlink rpl_readlink
+# endif
+_GL_FUNCDECL_RPL (readlink, ssize_t,
+ (const char *file, char *buf, size_t bufsize)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (readlink, ssize_t,
+ (const char *file, char *buf, size_t bufsize));
+# else
+# if !0
+_GL_FUNCDECL_SYS (readlink, ssize_t,
+ (const char *file, char *buf, size_t bufsize)
+ _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (readlink, ssize_t,
+ (const char *file, char *buf, size_t bufsize));
+# endif
+_GL_CXXALIASWARN (readlink);
+#elif defined GNULIB_POSIXCHECK
+# undef readlink
+# if HAVE_RAW_DECL_READLINK
+_GL_WARN_ON_USE (readlink, "readlink is unportable - "
+ "use gnulib module readlink for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (readlinkat, ssize_t,
+ (int fd, char const *file, char *buf, size_t len)
+ _GL_ARG_NONNULL ((2, 3)));
+# endif
+_GL_CXXALIAS_SYS (readlinkat, ssize_t,
+ (int fd, char const *file, char *buf, size_t len));
+_GL_CXXALIASWARN (readlinkat);
+#elif defined GNULIB_POSIXCHECK
+# undef readlinkat
+# if HAVE_RAW_DECL_READLINKAT
+_GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
+ "use gnulib module readlinkat for portability");
+# endif
+#endif
+
+
+#if 1
+/* Remove the directory DIR. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define rmdir rpl_rmdir
+# endif
+_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (rmdir, int, (char const *name));
+# else
+_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
+# endif
+_GL_CXXALIASWARN (rmdir);
+#elif defined GNULIB_POSIXCHECK
+# undef rmdir
+# if HAVE_RAW_DECL_RMDIR
+_GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
+ "use gnulib module rmdir for portability");
+# endif
+#endif
+
+
+#if 0
+/* Set the host name of the machine.
+ The host name may or may not be fully qualified.
+
+ Put LEN bytes of NAME into the host name.
+ Return 0 if successful, otherwise, set errno and return -1.
+
+ Platforms with no ability to set the hostname return -1 and set
+ errno = ENOSYS. */
+# if !1 || !1
+_GL_FUNCDECL_SYS (sethostname, int, (const char *name, size_t len)
+ _GL_ARG_NONNULL ((1)));
+# endif
+/* Need to cast, because on Solaris 11 2011-10, Mac OS X 10.5, IRIX 6.5
+ and FreeBSD 6.4 the second parameter is int. On Solaris 11
+ 2011-10, the first parameter is not const. */
+_GL_CXXALIAS_SYS_CAST (sethostname, int, (const char *name, size_t len));
+_GL_CXXALIASWARN (sethostname);
+#elif defined GNULIB_POSIXCHECK
+# undef sethostname
+# if HAVE_RAW_DECL_SETHOSTNAME
+_GL_WARN_ON_USE (sethostname, "sethostname is unportable - "
+ "use gnulib module sethostname for portability");
+# endif
+#endif
+
+
+#if IN_M4_GNULIB_TESTS
+/* Pause the execution of the current thread for N seconds.
+ Returns the number of seconds left to sleep.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef sleep
+# define sleep rpl_sleep
+# endif
+_GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
+_GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
+# else
+# if !0
+_GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
+# endif
+_GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
+# endif
+_GL_CXXALIASWARN (sleep);
+#elif defined GNULIB_POSIXCHECK
+# undef sleep
+# if HAVE_RAW_DECL_SLEEP
+_GL_WARN_ON_USE (sleep, "sleep is unportable - "
+ "use gnulib module sleep for portability");
+# endif
+#endif
+
+
+#if IN_M4_GNULIB_TESTS
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef symlink
+# define symlink rpl_symlink
+# endif
+_GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
+# else
+# if !0
+_GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
+ _GL_ARG_NONNULL ((1, 2)));
+# endif
+_GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
+# endif
+_GL_CXXALIASWARN (symlink);
+#elif defined GNULIB_POSIXCHECK
+# undef symlink
+# if HAVE_RAW_DECL_SYMLINK
+_GL_WARN_ON_USE (symlink, "symlink is not portable - "
+ "use gnulib module symlink for portability");
+# endif
+#endif
+
+
+#if 0
+# if !1
+_GL_FUNCDECL_SYS (symlinkat, int,
+ (char const *contents, int fd, char const *file)
+ _GL_ARG_NONNULL ((1, 3)));
+# endif
+_GL_CXXALIAS_SYS (symlinkat, int,
+ (char const *contents, int fd, char const *file));
+_GL_CXXALIASWARN (symlinkat);
+#elif defined GNULIB_POSIXCHECK
+# undef symlinkat
+# if HAVE_RAW_DECL_SYMLINKAT
+_GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
+ "use gnulib module symlinkat for portability");
+# endif
+#endif
+
+
+#if 0
+/* Store at most BUFLEN characters of the pathname of the terminal FD is
+ open on in BUF. Return 0 on success, otherwise an error number. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef ttyname_r
+# define ttyname_r rpl_ttyname_r
+# endif
+_GL_FUNCDECL_RPL (ttyname_r, int,
+ (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (ttyname_r, int,
+ (int fd, char *buf, size_t buflen));
+# else
+# if !1
+_GL_FUNCDECL_SYS (ttyname_r, int,
+ (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (ttyname_r, int,
+ (int fd, char *buf, size_t buflen));
+# endif
+_GL_CXXALIASWARN (ttyname_r);
+#elif defined GNULIB_POSIXCHECK
+# undef ttyname_r
+# if HAVE_RAW_DECL_TTYNAME_R
+_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
+ "use gnulib module ttyname_r for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef unlink
+# define unlink rpl_unlink
+# endif
+_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (unlink, int, (char const *file));
+# else
+_GL_CXXALIAS_SYS (unlink, int, (char const *file));
+# endif
+_GL_CXXALIASWARN (unlink);
+#elif defined GNULIB_POSIXCHECK
+# undef unlink
+# if HAVE_RAW_DECL_UNLINK
+_GL_WARN_ON_USE (unlink, "unlink is not portable - "
+ "use gnulib module unlink for portability");
+# endif
+#endif
+
+
+#if 0
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef unlinkat
+# define unlinkat rpl_unlinkat
+# endif
+_GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
+# else
+# if !1
+_GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
+ _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
+# endif
+_GL_CXXALIASWARN (unlinkat);
+#elif defined GNULIB_POSIXCHECK
+# undef unlinkat
+# if HAVE_RAW_DECL_UNLINKAT
+_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
+ "use gnulib module openat for portability");
+# endif
+#endif
+
+
+#if 0
+/* Pause the execution of the current thread for N microseconds.
+ Returns 0 on completion, or -1 on range error.
+ See the POSIX:2001 specification
+ <http://www.opengroup.org/susv3xsh/usleep.html>. */
+# if 0
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef usleep
+# define usleep rpl_usleep
+# endif
+_GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
+_GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
+# else
+# if !1
+_GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
+# endif
+_GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
+# endif
+_GL_CXXALIASWARN (usleep);
+#elif defined GNULIB_POSIXCHECK
+# undef usleep
+# if HAVE_RAW_DECL_USLEEP
+_GL_WARN_ON_USE (usleep, "usleep is unportable - "
+ "use gnulib module usleep for portability");
+# endif
+#endif
+
+
+#if IN_M4_GNULIB_TESTS
+/* Write up to COUNT bytes starting at BUF to file descriptor FD.
+ See the POSIX:2008 specification
+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>. */
+# if 1
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef write
+# define write rpl_write
+# endif
+_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
+# else
+/* Need to cast, because on mingw, the third parameter is
+ unsigned int count
+ and the return type is 'int'. */
+_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count));
+# endif
+_GL_CXXALIASWARN (write);
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif /* _GL_M4_UNISTD_H */
+#endif /* _GL_M4_UNISTD_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/unitypes.h b/contrib/tools/bison/gnulib/platform/win64/unitypes.h
index 3d7db7510d..cacea10810 100644
--- a/contrib/tools/bison/gnulib/platform/win64/unitypes.h
+++ b/contrib/tools/bison/gnulib/platform/win64/unitypes.h
@@ -1,47 +1,47 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Elementary types and macros for the GNU UniString library.
- Copyright (C) 2002, 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _UNITYPES_H
-#define _UNITYPES_H
-
-/* Get uint8_t, uint16_t, uint32_t. */
-#include <stdint.h>
-
-/* Type representing a Unicode character. */
-typedef uint32_t ucs4_t;
-
-/* Attribute of a function whose result depends only on the arguments
- (not pointers!) and which has no side effects. */
-#ifndef _UC_ATTRIBUTE_CONST
-# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-# define _UC_ATTRIBUTE_CONST __attribute__ ((__const__))
-# else
-# define _UC_ATTRIBUTE_CONST
-# endif
-#endif
-
-/* Attribute of a function whose result depends only on the arguments
- (possibly pointers) and global memory, and which has no side effects. */
-#ifndef _UC_ATTRIBUTE_PURE
-# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
-# define _UC_ATTRIBUTE_PURE __attribute__ ((__pure__))
-# else
-# define _UC_ATTRIBUTE_PURE
-# endif
-#endif
-
-#endif /* _UNITYPES_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Elementary types and macros for the GNU UniString library.
+ Copyright (C) 2002, 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _UNITYPES_H
+#define _UNITYPES_H
+
+/* Get uint8_t, uint16_t, uint32_t. */
+#include <stdint.h>
+
+/* Type representing a Unicode character. */
+typedef uint32_t ucs4_t;
+
+/* Attribute of a function whose result depends only on the arguments
+ (not pointers!) and which has no side effects. */
+#ifndef _UC_ATTRIBUTE_CONST
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
+# define _UC_ATTRIBUTE_CONST __attribute__ ((__const__))
+# else
+# define _UC_ATTRIBUTE_CONST
+# endif
+#endif
+
+/* Attribute of a function whose result depends only on the arguments
+ (possibly pointers) and global memory, and which has no side effects. */
+#ifndef _UC_ATTRIBUTE_PURE
+# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+# define _UC_ATTRIBUTE_PURE __attribute__ ((__pure__))
+# else
+# define _UC_ATTRIBUTE_PURE
+# endif
+#endif
+
+#endif /* _UNITYPES_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/uniwidth.h b/contrib/tools/bison/gnulib/platform/win64/uniwidth.h
index 2ad29275a5..91ed0b6494 100644
--- a/contrib/tools/bison/gnulib/platform/win64/uniwidth.h
+++ b/contrib/tools/bison/gnulib/platform/win64/uniwidth.h
@@ -1,73 +1,73 @@
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
-/* Display width functions.
- Copyright (C) 2001-2002, 2005, 2007, 2009-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _UNIWIDTH_H
-#define _UNIWIDTH_H
-
-#include "unitypes.h"
-
-/* Get size_t. */
-#include <stddef.h>
-
-/* Get locale_charset() declaration. */
-#include "localcharset.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Display width. */
-
-/* These functions are locale dependent. The encoding argument identifies
- the encoding (e.g. "ISO-8859-2" for Polish). */
-
-/* Determine number of column positions required for UC. */
-extern int
- uc_width (ucs4_t uc, const char *encoding)
- _UC_ATTRIBUTE_PURE;
-
-/* Determine number of column positions required for first N units
- (or fewer if S ends before this) in S. */
-extern int
- u8_width (const uint8_t *s, size_t n, const char *encoding)
- _UC_ATTRIBUTE_PURE;
-extern int
- u16_width (const uint16_t *s, size_t n, const char *encoding)
- _UC_ATTRIBUTE_PURE;
-extern int
- u32_width (const uint32_t *s, size_t n, const char *encoding)
- _UC_ATTRIBUTE_PURE;
-
-/* Determine number of column positions required for S. */
-extern int
- u8_strwidth (const uint8_t *s, const char *encoding)
- _UC_ATTRIBUTE_PURE;
-extern int
- u16_strwidth (const uint16_t *s, const char *encoding)
- _UC_ATTRIBUTE_PURE;
-extern int
- u32_strwidth (const uint32_t *s, const char *encoding)
- _UC_ATTRIBUTE_PURE;
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _UNIWIDTH_H */
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Display width functions.
+ Copyright (C) 2001-2002, 2005, 2007, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _UNIWIDTH_H
+#define _UNIWIDTH_H
+
+#include "unitypes.h"
+
+/* Get size_t. */
+#include <stddef.h>
+
+/* Get locale_charset() declaration. */
+#include "localcharset.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Display width. */
+
+/* These functions are locale dependent. The encoding argument identifies
+ the encoding (e.g. "ISO-8859-2" for Polish). */
+
+/* Determine number of column positions required for UC. */
+extern int
+ uc_width (ucs4_t uc, const char *encoding)
+ _UC_ATTRIBUTE_PURE;
+
+/* Determine number of column positions required for first N units
+ (or fewer if S ends before this) in S. */
+extern int
+ u8_width (const uint8_t *s, size_t n, const char *encoding)
+ _UC_ATTRIBUTE_PURE;
+extern int
+ u16_width (const uint16_t *s, size_t n, const char *encoding)
+ _UC_ATTRIBUTE_PURE;
+extern int
+ u32_width (const uint32_t *s, size_t n, const char *encoding)
+ _UC_ATTRIBUTE_PURE;
+
+/* Determine number of column positions required for S. */
+extern int
+ u8_strwidth (const uint8_t *s, const char *encoding)
+ _UC_ATTRIBUTE_PURE;
+extern int
+ u16_strwidth (const uint16_t *s, const char *encoding)
+ _UC_ATTRIBUTE_PURE;
+extern int
+ u32_strwidth (const uint32_t *s, const char *encoding)
+ _UC_ATTRIBUTE_PURE;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _UNIWIDTH_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/unused-parameter.h b/contrib/tools/bison/gnulib/platform/win64/unused-parameter.h
index 53474b5754..fa649b8221 100644
--- a/contrib/tools/bison/gnulib/platform/win64/unused-parameter.h
+++ b/contrib/tools/bison/gnulib/platform/win64/unused-parameter.h
@@ -1,20 +1,20 @@
-/* _GL_UNUSED_PARAMETER is a marker that can be appended to function parameter
- declarations for parameters that are not used. This helps to reduce
- warnings, such as from GCC -Wunused-parameter. The syntax is as follows:
- type param _GL_UNUSED_PARAMETER
- or more generally
- param_decl _GL_UNUSED_PARAMETER
- For example:
- int param _GL_UNUSED_PARAMETER
- int *(*param)(void) _GL_UNUSED_PARAMETER
- Other possible, but obscure and discouraged syntaxes:
- int _GL_UNUSED_PARAMETER *(*param)(void)
- _GL_UNUSED_PARAMETER int *(*param)(void)
- */
-#ifndef _GL_UNUSED_PARAMETER
-# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_UNUSED_PARAMETER __attribute__ ((__unused__))
-# else
-# define _GL_UNUSED_PARAMETER
-# endif
-#endif
+/* _GL_UNUSED_PARAMETER is a marker that can be appended to function parameter
+ declarations for parameters that are not used. This helps to reduce
+ warnings, such as from GCC -Wunused-parameter. The syntax is as follows:
+ type param _GL_UNUSED_PARAMETER
+ or more generally
+ param_decl _GL_UNUSED_PARAMETER
+ For example:
+ int param _GL_UNUSED_PARAMETER
+ int *(*param)(void) _GL_UNUSED_PARAMETER
+ Other possible, but obscure and discouraged syntaxes:
+ int _GL_UNUSED_PARAMETER *(*param)(void)
+ _GL_UNUSED_PARAMETER int *(*param)(void)
+ */
+#ifndef _GL_UNUSED_PARAMETER
+# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_UNUSED_PARAMETER __attribute__ ((__unused__))
+# else
+# define _GL_UNUSED_PARAMETER
+# endif
+#endif
diff --git a/contrib/tools/bison/gnulib/src/abitset.c b/contrib/tools/bison/gnulib/src/abitset.c
index f876996bcf..3f2fc25195 100644
--- a/contrib/tools/bison/gnulib/src/abitset.c
+++ b/contrib/tools/bison/gnulib/src/abitset.c
@@ -1,828 +1,828 @@
-/* Array bitsets.
-
- Copyright (C) 2002-2003, 2006, 2009-2013 Free Software Foundation,
- Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "abitset.h"
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-/* This file implements fixed size bitsets stored as an array
- of words. Any unused bits in the last word must be zero. */
-
-#define ABITSET_N_WORDS(N) (((N) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
-#define ABITSET_WORDS(X) ((X)->a.words)
-
-
-static bitset_bindex
-abitset_resize (bitset src, bitset_bindex size)
-{
- /* These bitsets have a fixed size. */
- if (BITSET_SIZE_ (src) != size)
- abort ();
-
- return size;
-}
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT and store in array LIST. Return with actual number of bits
- found and with *NEXT indicating where search stopped. */
-static bitset_bindex
-abitset_small_list (bitset src, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex bitno;
- bitset_bindex count;
- bitset_windex size;
- bitset_word word;
-
- word = ABITSET_WORDS (src)[0];
-
- /* Short circuit common case. */
- if (!word)
- return 0;
-
- size = BITSET_SIZE_ (src);
- bitno = *next;
- if (bitno >= size)
- return 0;
-
- word >>= bitno;
-
- /* If num is 1, we could speed things up with a binary search
- of the word of interest. */
-
- if (num >= BITSET_WORD_BITS)
- {
- for (count = 0; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- else
- {
- for (count = 0; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- bitno++;
- break;
- }
- }
- word >>= 1;
- }
- }
-
- *next = bitno;
- return count;
-}
-
-
-/* Set bit BITNO in bitset DST. */
-static void
-abitset_set (bitset dst ATTRIBUTE_UNUSED, bitset_bindex bitno ATTRIBUTE_UNUSED)
-{
- /* This should never occur for abitsets since we should always hit
- the cache. It is likely someone is trying to access outside the
- bounds of the bitset. */
- abort ();
-}
-
-
-/* Reset bit BITNO in bitset DST. */
-static void
-abitset_reset (bitset dst ATTRIBUTE_UNUSED,
- bitset_bindex bitno ATTRIBUTE_UNUSED)
-{
- /* This should never occur for abitsets since we should always hit
- the cache. It is likely someone is trying to access outside the
- bounds of the bitset. Since the bit is zero anyway, let it pass. */
-}
-
-
-/* Test bit BITNO in bitset SRC. */
-static bool
-abitset_test (bitset src ATTRIBUTE_UNUSED,
- bitset_bindex bitno ATTRIBUTE_UNUSED)
-{
- /* This should never occur for abitsets since we should always
- hit the cache. */
- return false;
-}
-
-
-/* Find list of up to NUM bits set in BSET in reverse order, starting
- from and including NEXT and store in array LIST. Return with
- actual number of bits found and with *NEXT indicating where search
- stopped. */
-static bitset_bindex
-abitset_list_reverse (bitset src, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex bitno;
- bitset_bindex rbitno;
- bitset_bindex count;
- bitset_windex windex;
- unsigned int bitcnt;
- bitset_bindex bitoff;
- bitset_word *srcp = ABITSET_WORDS (src);
- bitset_bindex n_bits = BITSET_SIZE_ (src);
-
- rbitno = *next;
-
- /* If num is 1, we could speed things up with a binary search
- of the word of interest. */
-
- if (rbitno >= n_bits)
- return 0;
-
- count = 0;
-
- bitno = n_bits - (rbitno + 1);
-
- windex = bitno / BITSET_WORD_BITS;
- bitcnt = bitno % BITSET_WORD_BITS;
- bitoff = windex * BITSET_WORD_BITS;
-
- do
- {
- bitset_word word;
-
- word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt);
- for (; word; bitcnt--)
- {
- if (word & BITSET_MSB)
- {
- list[count++] = bitoff + bitcnt;
- if (count >= num)
- {
- *next = n_bits - (bitoff + bitcnt);
- return count;
- }
- }
- word <<= 1;
- }
- bitoff -= BITSET_WORD_BITS;
- bitcnt = BITSET_WORD_BITS - 1;
- }
- while (windex--);
-
- *next = n_bits - (bitoff + 1);
- return count;
-}
-
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT and store in array LIST. Return with actual number of bits
- found and with *NEXT indicating where search stopped. */
-static bitset_bindex
-abitset_list (bitset src, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex bitno;
- bitset_bindex count;
- bitset_windex windex;
- bitset_bindex bitoff;
- bitset_windex size = src->b.csize;
- bitset_word *srcp = ABITSET_WORDS (src);
- bitset_word word;
-
- bitno = *next;
-
- count = 0;
- if (!bitno)
- {
- /* Many bitsets are zero, so make this common case fast. */
- for (windex = 0; windex < size && !srcp[windex]; windex++)
- continue;
- if (windex >= size)
- return 0;
-
- /* If num is 1, we could speed things up with a binary search
- of the current word. */
-
- bitoff = windex * BITSET_WORD_BITS;
- }
- else
- {
- if (bitno >= BITSET_SIZE_ (src))
- return 0;
-
- windex = bitno / BITSET_WORD_BITS;
- bitno = bitno % BITSET_WORD_BITS;
-
- if (bitno)
- {
- /* Handle the case where we start within a word.
- Most often, this is executed with large bitsets
- with many set bits where we filled the array
- on the previous call to this function. */
-
- bitoff = windex * BITSET_WORD_BITS;
- word = srcp[windex] >> bitno;
- for (bitno = bitoff + bitno; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- windex++;
- }
- bitoff = windex * BITSET_WORD_BITS;
- }
-
- for (; windex < size; windex++, bitoff += BITSET_WORD_BITS)
- {
- if (!(word = srcp[windex]))
- continue;
-
- if ((count + BITSET_WORD_BITS) < num)
- {
- for (bitno = bitoff; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- else
- {
- for (bitno = bitoff; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- }
- }
-
- *next = bitoff;
- return count;
-}
-
-
-/* Ensure that any unused bits within the last word are clear. */
-static inline void
-abitset_unused_clear (bitset dst)
-{
- unsigned int last_bit;
-
- last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS;
- if (last_bit)
- ABITSET_WORDS (dst)[dst->b.csize - 1] &=
- ((bitset_word) 1 << last_bit) - 1;
-}
-
-
-static void
-abitset_ones (bitset dst)
-{
- bitset_word *dstp = ABITSET_WORDS (dst);
- size_t bytes;
-
- bytes = sizeof (bitset_word) * dst->b.csize;
-
- memset (dstp, -1, bytes);
- abitset_unused_clear (dst);
-}
-
-
-static void
-abitset_zero (bitset dst)
-{
- bitset_word *dstp = ABITSET_WORDS (dst);
- size_t bytes;
-
- bytes = sizeof (bitset_word) * dst->b.csize;
-
- memset (dstp, 0, bytes);
-}
-
-
-static bool
-abitset_empty_p (bitset dst)
-{
- bitset_windex i;
- bitset_word *dstp = ABITSET_WORDS (dst);
-
- for (i = 0; i < dst->b.csize; i++)
- if (dstp[i])
- return false;
-
- return true;
-}
-
-
-static void
-abitset_copy1 (bitset dst, bitset src)
-{
- bitset_word *srcp = ABITSET_WORDS (src);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- if (srcp == dstp)
- return;
- memcpy (dstp, srcp, sizeof (bitset_word) * size);
-}
-
-
-static void
-abitset_not (bitset dst, bitset src)
-{
- bitset_windex i;
- bitset_word *srcp = ABITSET_WORDS (src);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = ~(*srcp++);
- abitset_unused_clear (dst);
-}
-
-
-static bool
-abitset_equal_p (bitset dst, bitset src)
-{
- bitset_windex i;
- bitset_word *srcp = ABITSET_WORDS (src);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- if (*srcp++ != *dstp++)
- return false;
- return true;
-}
-
-
-static bool
-abitset_subset_p (bitset dst, bitset src)
-{
- bitset_windex i;
- bitset_word *srcp = ABITSET_WORDS (src);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++, srcp++)
- if (*dstp != (*srcp | *dstp))
- return false;
- return true;
-}
-
-
-static bool
-abitset_disjoint_p (bitset dst, bitset src)
-{
- bitset_windex i;
- bitset_word *srcp = ABITSET_WORDS (src);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- if (*srcp++ & *dstp++)
- return false;
-
- return true;
-}
-
-
-static void
-abitset_and (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = *src1p++ & *src2p++;
-}
-
-
-static bool
-abitset_and_cmp (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bool changed = false;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = *src1p++ & *src2p++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-abitset_andn (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = *src1p++ & ~(*src2p++);
-}
-
-
-static bool
-abitset_andn_cmp (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bool changed = false;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = *src1p++ & ~(*src2p++);
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-abitset_or (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = *src1p++ | *src2p++;
-}
-
-
-static bool
-abitset_or_cmp (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bool changed = false;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = *src1p++ | *src2p++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-abitset_xor (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = *src1p++ ^ *src2p++;
-}
-
-
-static bool
-abitset_xor_cmp (bitset dst, bitset src1, bitset src2)
-{
- bitset_windex i;
- bool changed = false;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = *src1p++ ^ *src2p++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-abitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_windex i;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *src3p = ABITSET_WORDS (src3);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = (*src1p++ & *src2p++) | *src3p++;
-}
-
-
-static bool
-abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_windex i;
- bool changed = false;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *src3p = ABITSET_WORDS (src3);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = (*src1p++ & *src2p++) | *src3p++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-abitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_windex i;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *src3p = ABITSET_WORDS (src3);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++;
-}
-
-
-static bool
-abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_windex i;
- bool changed = false;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *src3p = ABITSET_WORDS (src3);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-abitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_windex i;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *src3p = ABITSET_WORDS (src3);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++)
- *dstp++ = (*src1p++ | *src2p++) & *src3p++;
-}
-
-
-static bool
-abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_windex i;
- bool changed = false;
- bitset_word *src1p = ABITSET_WORDS (src1);
- bitset_word *src2p = ABITSET_WORDS (src2);
- bitset_word *src3p = ABITSET_WORDS (src3);
- bitset_word *dstp = ABITSET_WORDS (dst);
- bitset_windex size = dst->b.csize;
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-abitset_copy (bitset dst, bitset src)
-{
- if (BITSET_COMPATIBLE_ (dst, src))
- abitset_copy1 (dst, src);
- else
- bitset_copy_ (dst, src);
-}
-
-
-/* Vector of operations for single word bitsets. */
-struct bitset_vtable abitset_small_vtable = {
- abitset_set,
- abitset_reset,
- bitset_toggle_,
- abitset_test,
- abitset_resize,
- bitset_size_,
- bitset_count_,
- abitset_empty_p,
- abitset_ones,
- abitset_zero,
- abitset_copy,
- abitset_disjoint_p,
- abitset_equal_p,
- abitset_not,
- abitset_subset_p,
- abitset_and,
- abitset_and_cmp,
- abitset_andn,
- abitset_andn_cmp,
- abitset_or,
- abitset_or_cmp,
- abitset_xor,
- abitset_xor_cmp,
- abitset_and_or,
- abitset_and_or_cmp,
- abitset_andn_or,
- abitset_andn_or_cmp,
- abitset_or_and,
- abitset_or_and_cmp,
- abitset_small_list,
- abitset_list_reverse,
- NULL,
- BITSET_ARRAY
-};
-
-
-/* Vector of operations for multiple word bitsets. */
-struct bitset_vtable abitset_vtable = {
- abitset_set,
- abitset_reset,
- bitset_toggle_,
- abitset_test,
- abitset_resize,
- bitset_size_,
- bitset_count_,
- abitset_empty_p,
- abitset_ones,
- abitset_zero,
- abitset_copy,
- abitset_disjoint_p,
- abitset_equal_p,
- abitset_not,
- abitset_subset_p,
- abitset_and,
- abitset_and_cmp,
- abitset_andn,
- abitset_andn_cmp,
- abitset_or,
- abitset_or_cmp,
- abitset_xor,
- abitset_xor_cmp,
- abitset_and_or,
- abitset_and_or_cmp,
- abitset_andn_or,
- abitset_andn_or_cmp,
- abitset_or_and,
- abitset_or_and_cmp,
- abitset_list,
- abitset_list_reverse,
- NULL,
- BITSET_ARRAY
-};
-
-
-size_t
-abitset_bytes (bitset_bindex n_bits)
-{
- bitset_windex size;
- size_t bytes;
- size_t header_size = offsetof (union bitset_union, a.words);
- struct bitset_align_struct { char a; union bitset_union b; };
- size_t bitset_alignment = offsetof (struct bitset_align_struct, b);
-
- size = ABITSET_N_WORDS (n_bits);
- bytes = header_size + size * sizeof (bitset_word);
-
- /* Align the size properly for a vector of abitset objects. */
- if (header_size % bitset_alignment != 0
- || sizeof (bitset_word) % bitset_alignment != 0)
- {
- bytes += bitset_alignment - 1;
- bytes -= bytes % bitset_alignment;
- }
-
- return bytes;
-}
-
-
-bitset
-abitset_init (bitset bset, bitset_bindex n_bits)
-{
- bitset_windex size;
-
- size = ABITSET_N_WORDS (n_bits);
- BITSET_NBITS_ (bset) = n_bits;
-
- /* Use optimized routines if bitset fits within a single word.
- There is probably little merit if using caching since
- the small bitset will always fit in the cache. */
- if (size == 1)
- bset->b.vtable = &abitset_small_vtable;
- else
- bset->b.vtable = &abitset_vtable;
-
- bset->b.cindex = 0;
- bset->b.csize = size;
- bset->b.cdata = ABITSET_WORDS (bset);
- return bset;
-}
+/* Array bitsets.
+
+ Copyright (C) 2002-2003, 2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "abitset.h"
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* This file implements fixed size bitsets stored as an array
+ of words. Any unused bits in the last word must be zero. */
+
+#define ABITSET_N_WORDS(N) (((N) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
+#define ABITSET_WORDS(X) ((X)->a.words)
+
+
+static bitset_bindex
+abitset_resize (bitset src, bitset_bindex size)
+{
+ /* These bitsets have a fixed size. */
+ if (BITSET_SIZE_ (src) != size)
+ abort ();
+
+ return size;
+}
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT and store in array LIST. Return with actual number of bits
+ found and with *NEXT indicating where search stopped. */
+static bitset_bindex
+abitset_small_list (bitset src, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex bitno;
+ bitset_bindex count;
+ bitset_windex size;
+ bitset_word word;
+
+ word = ABITSET_WORDS (src)[0];
+
+ /* Short circuit common case. */
+ if (!word)
+ return 0;
+
+ size = BITSET_SIZE_ (src);
+ bitno = *next;
+ if (bitno >= size)
+ return 0;
+
+ word >>= bitno;
+
+ /* If num is 1, we could speed things up with a binary search
+ of the word of interest. */
+
+ if (num >= BITSET_WORD_BITS)
+ {
+ for (count = 0; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ else
+ {
+ for (count = 0; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ bitno++;
+ break;
+ }
+ }
+ word >>= 1;
+ }
+ }
+
+ *next = bitno;
+ return count;
+}
+
+
+/* Set bit BITNO in bitset DST. */
+static void
+abitset_set (bitset dst ATTRIBUTE_UNUSED, bitset_bindex bitno ATTRIBUTE_UNUSED)
+{
+ /* This should never occur for abitsets since we should always hit
+ the cache. It is likely someone is trying to access outside the
+ bounds of the bitset. */
+ abort ();
+}
+
+
+/* Reset bit BITNO in bitset DST. */
+static void
+abitset_reset (bitset dst ATTRIBUTE_UNUSED,
+ bitset_bindex bitno ATTRIBUTE_UNUSED)
+{
+ /* This should never occur for abitsets since we should always hit
+ the cache. It is likely someone is trying to access outside the
+ bounds of the bitset. Since the bit is zero anyway, let it pass. */
+}
+
+
+/* Test bit BITNO in bitset SRC. */
+static bool
+abitset_test (bitset src ATTRIBUTE_UNUSED,
+ bitset_bindex bitno ATTRIBUTE_UNUSED)
+{
+ /* This should never occur for abitsets since we should always
+ hit the cache. */
+ return false;
+}
+
+
+/* Find list of up to NUM bits set in BSET in reverse order, starting
+ from and including NEXT and store in array LIST. Return with
+ actual number of bits found and with *NEXT indicating where search
+ stopped. */
+static bitset_bindex
+abitset_list_reverse (bitset src, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex bitno;
+ bitset_bindex rbitno;
+ bitset_bindex count;
+ bitset_windex windex;
+ unsigned int bitcnt;
+ bitset_bindex bitoff;
+ bitset_word *srcp = ABITSET_WORDS (src);
+ bitset_bindex n_bits = BITSET_SIZE_ (src);
+
+ rbitno = *next;
+
+ /* If num is 1, we could speed things up with a binary search
+ of the word of interest. */
+
+ if (rbitno >= n_bits)
+ return 0;
+
+ count = 0;
+
+ bitno = n_bits - (rbitno + 1);
+
+ windex = bitno / BITSET_WORD_BITS;
+ bitcnt = bitno % BITSET_WORD_BITS;
+ bitoff = windex * BITSET_WORD_BITS;
+
+ do
+ {
+ bitset_word word;
+
+ word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt);
+ for (; word; bitcnt--)
+ {
+ if (word & BITSET_MSB)
+ {
+ list[count++] = bitoff + bitcnt;
+ if (count >= num)
+ {
+ *next = n_bits - (bitoff + bitcnt);
+ return count;
+ }
+ }
+ word <<= 1;
+ }
+ bitoff -= BITSET_WORD_BITS;
+ bitcnt = BITSET_WORD_BITS - 1;
+ }
+ while (windex--);
+
+ *next = n_bits - (bitoff + 1);
+ return count;
+}
+
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT and store in array LIST. Return with actual number of bits
+ found and with *NEXT indicating where search stopped. */
+static bitset_bindex
+abitset_list (bitset src, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex bitno;
+ bitset_bindex count;
+ bitset_windex windex;
+ bitset_bindex bitoff;
+ bitset_windex size = src->b.csize;
+ bitset_word *srcp = ABITSET_WORDS (src);
+ bitset_word word;
+
+ bitno = *next;
+
+ count = 0;
+ if (!bitno)
+ {
+ /* Many bitsets are zero, so make this common case fast. */
+ for (windex = 0; windex < size && !srcp[windex]; windex++)
+ continue;
+ if (windex >= size)
+ return 0;
+
+ /* If num is 1, we could speed things up with a binary search
+ of the current word. */
+
+ bitoff = windex * BITSET_WORD_BITS;
+ }
+ else
+ {
+ if (bitno >= BITSET_SIZE_ (src))
+ return 0;
+
+ windex = bitno / BITSET_WORD_BITS;
+ bitno = bitno % BITSET_WORD_BITS;
+
+ if (bitno)
+ {
+ /* Handle the case where we start within a word.
+ Most often, this is executed with large bitsets
+ with many set bits where we filled the array
+ on the previous call to this function. */
+
+ bitoff = windex * BITSET_WORD_BITS;
+ word = srcp[windex] >> bitno;
+ for (bitno = bitoff + bitno; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ windex++;
+ }
+ bitoff = windex * BITSET_WORD_BITS;
+ }
+
+ for (; windex < size; windex++, bitoff += BITSET_WORD_BITS)
+ {
+ if (!(word = srcp[windex]))
+ continue;
+
+ if ((count + BITSET_WORD_BITS) < num)
+ {
+ for (bitno = bitoff; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ else
+ {
+ for (bitno = bitoff; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ }
+ }
+
+ *next = bitoff;
+ return count;
+}
+
+
+/* Ensure that any unused bits within the last word are clear. */
+static inline void
+abitset_unused_clear (bitset dst)
+{
+ unsigned int last_bit;
+
+ last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS;
+ if (last_bit)
+ ABITSET_WORDS (dst)[dst->b.csize - 1] &=
+ ((bitset_word) 1 << last_bit) - 1;
+}
+
+
+static void
+abitset_ones (bitset dst)
+{
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ size_t bytes;
+
+ bytes = sizeof (bitset_word) * dst->b.csize;
+
+ memset (dstp, -1, bytes);
+ abitset_unused_clear (dst);
+}
+
+
+static void
+abitset_zero (bitset dst)
+{
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ size_t bytes;
+
+ bytes = sizeof (bitset_word) * dst->b.csize;
+
+ memset (dstp, 0, bytes);
+}
+
+
+static bool
+abitset_empty_p (bitset dst)
+{
+ bitset_windex i;
+ bitset_word *dstp = ABITSET_WORDS (dst);
+
+ for (i = 0; i < dst->b.csize; i++)
+ if (dstp[i])
+ return false;
+
+ return true;
+}
+
+
+static void
+abitset_copy1 (bitset dst, bitset src)
+{
+ bitset_word *srcp = ABITSET_WORDS (src);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ if (srcp == dstp)
+ return;
+ memcpy (dstp, srcp, sizeof (bitset_word) * size);
+}
+
+
+static void
+abitset_not (bitset dst, bitset src)
+{
+ bitset_windex i;
+ bitset_word *srcp = ABITSET_WORDS (src);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = ~(*srcp++);
+ abitset_unused_clear (dst);
+}
+
+
+static bool
+abitset_equal_p (bitset dst, bitset src)
+{
+ bitset_windex i;
+ bitset_word *srcp = ABITSET_WORDS (src);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ if (*srcp++ != *dstp++)
+ return false;
+ return true;
+}
+
+
+static bool
+abitset_subset_p (bitset dst, bitset src)
+{
+ bitset_windex i;
+ bitset_word *srcp = ABITSET_WORDS (src);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++, srcp++)
+ if (*dstp != (*srcp | *dstp))
+ return false;
+ return true;
+}
+
+
+static bool
+abitset_disjoint_p (bitset dst, bitset src)
+{
+ bitset_windex i;
+ bitset_word *srcp = ABITSET_WORDS (src);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ if (*srcp++ & *dstp++)
+ return false;
+
+ return true;
+}
+
+
+static void
+abitset_and (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = *src1p++ & *src2p++;
+}
+
+
+static bool
+abitset_and_cmp (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bool changed = false;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ & *src2p++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+abitset_andn (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = *src1p++ & ~(*src2p++);
+}
+
+
+static bool
+abitset_andn_cmp (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bool changed = false;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ & ~(*src2p++);
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+abitset_or (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = *src1p++ | *src2p++;
+}
+
+
+static bool
+abitset_or_cmp (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bool changed = false;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ | *src2p++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+abitset_xor (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = *src1p++ ^ *src2p++;
+}
+
+
+static bool
+abitset_xor_cmp (bitset dst, bitset src1, bitset src2)
+{
+ bitset_windex i;
+ bool changed = false;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ ^ *src2p++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+abitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_windex i;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *src3p = ABITSET_WORDS (src3);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = (*src1p++ & *src2p++) | *src3p++;
+}
+
+
+static bool
+abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_windex i;
+ bool changed = false;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *src3p = ABITSET_WORDS (src3);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = (*src1p++ & *src2p++) | *src3p++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+abitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_windex i;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *src3p = ABITSET_WORDS (src3);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++;
+}
+
+
+static bool
+abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_windex i;
+ bool changed = false;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *src3p = ABITSET_WORDS (src3);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+abitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_windex i;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *src3p = ABITSET_WORDS (src3);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++)
+ *dstp++ = (*src1p++ | *src2p++) & *src3p++;
+}
+
+
+static bool
+abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_windex i;
+ bool changed = false;
+ bitset_word *src1p = ABITSET_WORDS (src1);
+ bitset_word *src2p = ABITSET_WORDS (src2);
+ bitset_word *src3p = ABITSET_WORDS (src3);
+ bitset_word *dstp = ABITSET_WORDS (dst);
+ bitset_windex size = dst->b.csize;
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+abitset_copy (bitset dst, bitset src)
+{
+ if (BITSET_COMPATIBLE_ (dst, src))
+ abitset_copy1 (dst, src);
+ else
+ bitset_copy_ (dst, src);
+}
+
+
+/* Vector of operations for single word bitsets. */
+struct bitset_vtable abitset_small_vtable = {
+ abitset_set,
+ abitset_reset,
+ bitset_toggle_,
+ abitset_test,
+ abitset_resize,
+ bitset_size_,
+ bitset_count_,
+ abitset_empty_p,
+ abitset_ones,
+ abitset_zero,
+ abitset_copy,
+ abitset_disjoint_p,
+ abitset_equal_p,
+ abitset_not,
+ abitset_subset_p,
+ abitset_and,
+ abitset_and_cmp,
+ abitset_andn,
+ abitset_andn_cmp,
+ abitset_or,
+ abitset_or_cmp,
+ abitset_xor,
+ abitset_xor_cmp,
+ abitset_and_or,
+ abitset_and_or_cmp,
+ abitset_andn_or,
+ abitset_andn_or_cmp,
+ abitset_or_and,
+ abitset_or_and_cmp,
+ abitset_small_list,
+ abitset_list_reverse,
+ NULL,
+ BITSET_ARRAY
+};
+
+
+/* Vector of operations for multiple word bitsets. */
+struct bitset_vtable abitset_vtable = {
+ abitset_set,
+ abitset_reset,
+ bitset_toggle_,
+ abitset_test,
+ abitset_resize,
+ bitset_size_,
+ bitset_count_,
+ abitset_empty_p,
+ abitset_ones,
+ abitset_zero,
+ abitset_copy,
+ abitset_disjoint_p,
+ abitset_equal_p,
+ abitset_not,
+ abitset_subset_p,
+ abitset_and,
+ abitset_and_cmp,
+ abitset_andn,
+ abitset_andn_cmp,
+ abitset_or,
+ abitset_or_cmp,
+ abitset_xor,
+ abitset_xor_cmp,
+ abitset_and_or,
+ abitset_and_or_cmp,
+ abitset_andn_or,
+ abitset_andn_or_cmp,
+ abitset_or_and,
+ abitset_or_and_cmp,
+ abitset_list,
+ abitset_list_reverse,
+ NULL,
+ BITSET_ARRAY
+};
+
+
+size_t
+abitset_bytes (bitset_bindex n_bits)
+{
+ bitset_windex size;
+ size_t bytes;
+ size_t header_size = offsetof (union bitset_union, a.words);
+ struct bitset_align_struct { char a; union bitset_union b; };
+ size_t bitset_alignment = offsetof (struct bitset_align_struct, b);
+
+ size = ABITSET_N_WORDS (n_bits);
+ bytes = header_size + size * sizeof (bitset_word);
+
+ /* Align the size properly for a vector of abitset objects. */
+ if (header_size % bitset_alignment != 0
+ || sizeof (bitset_word) % bitset_alignment != 0)
+ {
+ bytes += bitset_alignment - 1;
+ bytes -= bytes % bitset_alignment;
+ }
+
+ return bytes;
+}
+
+
+bitset
+abitset_init (bitset bset, bitset_bindex n_bits)
+{
+ bitset_windex size;
+
+ size = ABITSET_N_WORDS (n_bits);
+ BITSET_NBITS_ (bset) = n_bits;
+
+ /* Use optimized routines if bitset fits within a single word.
+ There is probably little merit if using caching since
+ the small bitset will always fit in the cache. */
+ if (size == 1)
+ bset->b.vtable = &abitset_small_vtable;
+ else
+ bset->b.vtable = &abitset_vtable;
+
+ bset->b.cindex = 0;
+ bset->b.csize = size;
+ bset->b.cdata = ABITSET_WORDS (bset);
+ return bset;
+}
diff --git a/contrib/tools/bison/gnulib/src/abitset.h b/contrib/tools/bison/gnulib/src/abitset.h
index f66122894a..328267b8b6 100644
--- a/contrib/tools/bison/gnulib/src/abitset.h
+++ b/contrib/tools/bison/gnulib/src/abitset.h
@@ -1,29 +1,29 @@
-/* Functions to support abitsets.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _ABITSET_H
-#define _ABITSET_H
-
-#include "bitset.h"
-
-extern size_t abitset_bytes (bitset_bindex);
-
-extern bitset abitset_init (bitset, bitset_bindex);
-
-#endif
+/* Functions to support abitsets.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _ABITSET_H
+#define _ABITSET_H
+
+#include "bitset.h"
+
+extern size_t abitset_bytes (bitset_bindex);
+
+extern bitset abitset_init (bitset, bitset_bindex);
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/argmatch.c b/contrib/tools/bison/gnulib/src/argmatch.c
index 9125e2af04..02462edf4c 100644
--- a/contrib/tools/bison/gnulib/src/argmatch.c
+++ b/contrib/tools/bison/gnulib/src/argmatch.c
@@ -1,277 +1,277 @@
-/* argmatch.c -- find a match for a string in an array
-
- Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by David MacKenzie <djm@ai.mit.edu>
- Modified by Akim Demaille <demaille@inf.enst.fr> */
-
-#include <config.h>
-
-/* Specification. */
-#include "argmatch.h"
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
-#include "error.h"
-#include "quotearg.h"
-#include "quote.h"
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-/* When reporting an invalid argument, show nonprinting characters
- by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
- literal_quoting_style. */
-#ifndef ARGMATCH_QUOTING_STYLE
-# define ARGMATCH_QUOTING_STYLE locale_quoting_style
-#endif
-
-/* Non failing version of argmatch call this function after failing. */
-#ifndef ARGMATCH_DIE
-# include "exitfail.h"
-# define ARGMATCH_DIE exit (exit_failure)
-#endif
-
-#ifdef ARGMATCH_DIE_DECL
-ARGMATCH_DIE_DECL;
-#endif
-
-static void
-__argmatch_die (void)
-{
- ARGMATCH_DIE;
-}
-
-/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
- Default to __argmatch_die, but allow caller to change this at run-time. */
-argmatch_exit_fn argmatch_die = __argmatch_die;
-
-
-/* If ARG is an unambiguous match for an element of the
- NULL-terminated array ARGLIST, return the index in ARGLIST
- of the matched element, else -1 if it does not match any element
- or -2 if it is ambiguous (is a prefix of more than one element).
-
- If VALLIST is none null, use it to resolve ambiguities limited to
- synonyms, i.e., for
- "yes", "yop" -> 0
- "no", "nope" -> 1
- "y" is a valid argument, for 0, and "n" for 1. */
-
-ptrdiff_t
-argmatch (const char *arg, const char *const *arglist,
- const char *vallist, size_t valsize)
-{
- size_t i; /* Temporary index in ARGLIST. */
- size_t arglen; /* Length of ARG. */
- ptrdiff_t matchind = -1; /* Index of first nonexact match. */
- bool ambiguous = false; /* If true, multiple nonexact match(es). */
-
- arglen = strlen (arg);
-
- /* Test all elements for either exact match or abbreviated matches. */
- for (i = 0; arglist[i]; i++)
- {
- if (!strncmp (arglist[i], arg, arglen))
- {
- if (strlen (arglist[i]) == arglen)
- /* Exact match found. */
- return i;
- else if (matchind == -1)
- /* First nonexact match found. */
- matchind = i;
- else
- {
- /* Second nonexact match found. */
- if (vallist == NULL
- || memcmp (vallist + valsize * matchind,
- vallist + valsize * i, valsize))
- {
- /* There is a real ambiguity, or we could not
- disambiguate. */
- ambiguous = true;
- }
- }
- }
- }
- if (ambiguous)
- return -2;
- else
- return matchind;
-}
-
-/* Error reporting for argmatch.
- CONTEXT is a description of the type of entity that was being matched.
- VALUE is the invalid value that was given.
- PROBLEM is the return value from argmatch. */
-
-void
-argmatch_invalid (const char *context, const char *value, ptrdiff_t problem)
-{
- char const *format = (problem == -1
- ? _("invalid argument %s for %s")
- : _("ambiguous argument %s for %s"));
-
- error (0, 0, format, quotearg_n_style (0, ARGMATCH_QUOTING_STYLE, value),
- quote_n (1, context));
-}
-
-/* List the valid arguments for argmatch.
- ARGLIST is the same as in argmatch.
- VALLIST is a pointer to an array of values.
- VALSIZE is the size of the elements of VALLIST */
-void
-argmatch_valid (const char *const *arglist,
- const char *vallist, size_t valsize)
-{
- size_t i;
- const char *last_val = NULL;
-
- /* We try to put synonyms on the same line. The assumption is that
- synonyms follow each other */
- fputs (_("Valid arguments are:"), stderr);
- for (i = 0; arglist[i]; i++)
- if ((i == 0)
- || memcmp (last_val, vallist + valsize * i, valsize))
- {
- fprintf (stderr, "\n - %s", quote (arglist[i]));
- last_val = vallist + valsize * i;
- }
- else
- {
- fprintf (stderr, ", %s", quote (arglist[i]));
- }
- putc ('\n', stderr);
-}
-
-/* Never failing versions of the previous functions.
-
- CONTEXT is the context for which argmatch is called (e.g.,
- "--version-control", or "$VERSION_CONTROL" etc.). Upon failure,
- calls the (supposed never to return) function EXIT_FN. */
-
-ptrdiff_t
-__xargmatch_internal (const char *context,
- const char *arg, const char *const *arglist,
- const char *vallist, size_t valsize,
- argmatch_exit_fn exit_fn)
-{
- ptrdiff_t res = argmatch (arg, arglist, vallist, valsize);
- if (res >= 0)
- /* Success. */
- return res;
-
- /* We failed. Explain why. */
- argmatch_invalid (context, arg, res);
- argmatch_valid (arglist, vallist, valsize);
- (*exit_fn) ();
-
- return -1; /* To please the compilers. */
-}
-
-/* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
- return the first corresponding argument in ARGLIST */
-const char *
-argmatch_to_argument (const char *value,
- const char *const *arglist,
- const char *vallist, size_t valsize)
-{
- size_t i;
-
- for (i = 0; arglist[i]; i++)
- if (!memcmp (value, vallist + valsize * i, valsize))
- return arglist[i];
- return NULL;
-}
-
-#ifdef TEST
-/*
- * Based on "getversion.c" by David MacKenzie <djm@gnu.ai.mit.edu>
- */
-char *program_name;
-
-/* When to make backup files. */
-enum backup_type
-{
- /* Never make backups. */
- no_backups,
-
- /* Make simple backups of every file. */
- simple_backups,
-
- /* Make numbered backups of files that already have numbered backups,
- and simple backups of the others. */
- numbered_existing_backups,
-
- /* Make numbered backups of every file. */
- numbered_backups
-};
-
-/* Two tables describing arguments (keys) and their corresponding
- values */
-static const char *const backup_args[] =
-{
- "no", "none", "off",
- "simple", "never",
- "existing", "nil",
- "numbered", "t",
- 0
-};
-
-static const enum backup_type backup_vals[] =
-{
- no_backups, no_backups, no_backups,
- simple_backups, simple_backups,
- numbered_existing_backups, numbered_existing_backups,
- numbered_backups, numbered_backups
-};
-
-int
-main (int argc, const char *const *argv)
-{
- const char *cp;
- enum backup_type backup_type = no_backups;
-
- program_name = (char *) argv[0];
-
- if (argc > 2)
- {
- fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name);
- exit (1);
- }
-
- if ((cp = getenv ("VERSION_CONTROL")))
- backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
- backup_args, backup_vals);
-
- if (argc == 2)
- backup_type = XARGMATCH (program_name, argv[1],
- backup_args, backup_vals);
-
- printf ("The version control is '%s'\n",
- ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
-
- return 0;
-}
-#endif
+/* argmatch.c -- find a match for a string in an array
+
+ Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by David MacKenzie <djm@ai.mit.edu>
+ Modified by Akim Demaille <demaille@inf.enst.fr> */
+
+#include <config.h>
+
+/* Specification. */
+#include "argmatch.h"
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+#include "error.h"
+#include "quotearg.h"
+#include "quote.h"
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+/* When reporting an invalid argument, show nonprinting characters
+ by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
+ literal_quoting_style. */
+#ifndef ARGMATCH_QUOTING_STYLE
+# define ARGMATCH_QUOTING_STYLE locale_quoting_style
+#endif
+
+/* Non failing version of argmatch call this function after failing. */
+#ifndef ARGMATCH_DIE
+# include "exitfail.h"
+# define ARGMATCH_DIE exit (exit_failure)
+#endif
+
+#ifdef ARGMATCH_DIE_DECL
+ARGMATCH_DIE_DECL;
+#endif
+
+static void
+__argmatch_die (void)
+{
+ ARGMATCH_DIE;
+}
+
+/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
+ Default to __argmatch_die, but allow caller to change this at run-time. */
+argmatch_exit_fn argmatch_die = __argmatch_die;
+
+
+/* If ARG is an unambiguous match for an element of the
+ NULL-terminated array ARGLIST, return the index in ARGLIST
+ of the matched element, else -1 if it does not match any element
+ or -2 if it is ambiguous (is a prefix of more than one element).
+
+ If VALLIST is none null, use it to resolve ambiguities limited to
+ synonyms, i.e., for
+ "yes", "yop" -> 0
+ "no", "nope" -> 1
+ "y" is a valid argument, for 0, and "n" for 1. */
+
+ptrdiff_t
+argmatch (const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i; /* Temporary index in ARGLIST. */
+ size_t arglen; /* Length of ARG. */
+ ptrdiff_t matchind = -1; /* Index of first nonexact match. */
+ bool ambiguous = false; /* If true, multiple nonexact match(es). */
+
+ arglen = strlen (arg);
+
+ /* Test all elements for either exact match or abbreviated matches. */
+ for (i = 0; arglist[i]; i++)
+ {
+ if (!strncmp (arglist[i], arg, arglen))
+ {
+ if (strlen (arglist[i]) == arglen)
+ /* Exact match found. */
+ return i;
+ else if (matchind == -1)
+ /* First nonexact match found. */
+ matchind = i;
+ else
+ {
+ /* Second nonexact match found. */
+ if (vallist == NULL
+ || memcmp (vallist + valsize * matchind,
+ vallist + valsize * i, valsize))
+ {
+ /* There is a real ambiguity, or we could not
+ disambiguate. */
+ ambiguous = true;
+ }
+ }
+ }
+ }
+ if (ambiguous)
+ return -2;
+ else
+ return matchind;
+}
+
+/* Error reporting for argmatch.
+ CONTEXT is a description of the type of entity that was being matched.
+ VALUE is the invalid value that was given.
+ PROBLEM is the return value from argmatch. */
+
+void
+argmatch_invalid (const char *context, const char *value, ptrdiff_t problem)
+{
+ char const *format = (problem == -1
+ ? _("invalid argument %s for %s")
+ : _("ambiguous argument %s for %s"));
+
+ error (0, 0, format, quotearg_n_style (0, ARGMATCH_QUOTING_STYLE, value),
+ quote_n (1, context));
+}
+
+/* List the valid arguments for argmatch.
+ ARGLIST is the same as in argmatch.
+ VALLIST is a pointer to an array of values.
+ VALSIZE is the size of the elements of VALLIST */
+void
+argmatch_valid (const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i;
+ const char *last_val = NULL;
+
+ /* We try to put synonyms on the same line. The assumption is that
+ synonyms follow each other */
+ fputs (_("Valid arguments are:"), stderr);
+ for (i = 0; arglist[i]; i++)
+ if ((i == 0)
+ || memcmp (last_val, vallist + valsize * i, valsize))
+ {
+ fprintf (stderr, "\n - %s", quote (arglist[i]));
+ last_val = vallist + valsize * i;
+ }
+ else
+ {
+ fprintf (stderr, ", %s", quote (arglist[i]));
+ }
+ putc ('\n', stderr);
+}
+
+/* Never failing versions of the previous functions.
+
+ CONTEXT is the context for which argmatch is called (e.g.,
+ "--version-control", or "$VERSION_CONTROL" etc.). Upon failure,
+ calls the (supposed never to return) function EXIT_FN. */
+
+ptrdiff_t
+__xargmatch_internal (const char *context,
+ const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn)
+{
+ ptrdiff_t res = argmatch (arg, arglist, vallist, valsize);
+ if (res >= 0)
+ /* Success. */
+ return res;
+
+ /* We failed. Explain why. */
+ argmatch_invalid (context, arg, res);
+ argmatch_valid (arglist, vallist, valsize);
+ (*exit_fn) ();
+
+ return -1; /* To please the compilers. */
+}
+
+/* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
+ return the first corresponding argument in ARGLIST */
+const char *
+argmatch_to_argument (const char *value,
+ const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i;
+
+ for (i = 0; arglist[i]; i++)
+ if (!memcmp (value, vallist + valsize * i, valsize))
+ return arglist[i];
+ return NULL;
+}
+
+#ifdef TEST
+/*
+ * Based on "getversion.c" by David MacKenzie <djm@gnu.ai.mit.edu>
+ */
+char *program_name;
+
+/* When to make backup files. */
+enum backup_type
+{
+ /* Never make backups. */
+ no_backups,
+
+ /* Make simple backups of every file. */
+ simple_backups,
+
+ /* Make numbered backups of files that already have numbered backups,
+ and simple backups of the others. */
+ numbered_existing_backups,
+
+ /* Make numbered backups of every file. */
+ numbered_backups
+};
+
+/* Two tables describing arguments (keys) and their corresponding
+ values */
+static const char *const backup_args[] =
+{
+ "no", "none", "off",
+ "simple", "never",
+ "existing", "nil",
+ "numbered", "t",
+ 0
+};
+
+static const enum backup_type backup_vals[] =
+{
+ no_backups, no_backups, no_backups,
+ simple_backups, simple_backups,
+ numbered_existing_backups, numbered_existing_backups,
+ numbered_backups, numbered_backups
+};
+
+int
+main (int argc, const char *const *argv)
+{
+ const char *cp;
+ enum backup_type backup_type = no_backups;
+
+ program_name = (char *) argv[0];
+
+ if (argc > 2)
+ {
+ fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name);
+ exit (1);
+ }
+
+ if ((cp = getenv ("VERSION_CONTROL")))
+ backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
+ backup_args, backup_vals);
+
+ if (argc == 2)
+ backup_type = XARGMATCH (program_name, argv[1],
+ backup_args, backup_vals);
+
+ printf ("The version control is '%s'\n",
+ ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
+
+ return 0;
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/argmatch.h b/contrib/tools/bison/gnulib/src/argmatch.h
index e4c8027144..ead3027be6 100644
--- a/contrib/tools/bison/gnulib/src/argmatch.h
+++ b/contrib/tools/bison/gnulib/src/argmatch.h
@@ -1,111 +1,111 @@
-/* argmatch.h -- definitions and prototypes for argmatch.c
-
- Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by David MacKenzie <djm@ai.mit.edu>
- Modified by Akim Demaille <demaille@inf.enst.fr> */
-
-#ifndef ARGMATCH_H_
-# define ARGMATCH_H_ 1
-
-# include <stddef.h>
-
-# include "verify.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
-
-/* Assert there are as many real arguments as there are values
- (argument list ends with a NULL guard). */
-
-# define ARGMATCH_VERIFY(Arglist, Vallist) \
- verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
-
-/* Return the index of the element of ARGLIST (NULL terminated) that
- matches with ARG. If VALLIST is not NULL, then use it to resolve
- false ambiguities (i.e., different matches of ARG but corresponding
- to the same values in VALLIST). */
-
-ptrdiff_t argmatch (char const *arg, char const *const *arglist,
- char const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
-
-# define ARGMATCH(Arg, Arglist, Vallist) \
- argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
-
-/* xargmatch calls this function when it fails. This function should not
- return. By default, this is a function that calls ARGMATCH_DIE which
- in turn defaults to 'exit (exit_failure)'. */
-typedef void (*argmatch_exit_fn) (void);
-extern argmatch_exit_fn argmatch_die;
-
-/* Report on stderr why argmatch failed. Report correct values. */
-
-void argmatch_invalid (char const *context, char const *value,
- ptrdiff_t problem);
-
-/* Left for compatibility with the old name invalid_arg */
-
-# define invalid_arg(Context, Value, Problem) \
- argmatch_invalid (Context, Value, Problem)
-
-
-
-/* Report on stderr the list of possible arguments. */
-
-void argmatch_valid (char const *const *arglist,
- char const *vallist, size_t valsize);
-
-# define ARGMATCH_VALID(Arglist, Vallist) \
- argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
-
-
-
-/* Same as argmatch, but upon failure, report an explanation of the
- failure, and exit using the function EXIT_FN. */
-
-ptrdiff_t __xargmatch_internal (char const *context,
- char const *arg, char const *const *arglist,
- char const *vallist, size_t valsize,
- argmatch_exit_fn exit_fn);
-
-/* Programmer friendly interface to __xargmatch_internal. */
-
-# define XARGMATCH(Context, Arg, Arglist, Vallist) \
- ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
- (char const *) (Vallist), \
- sizeof *(Vallist), \
- argmatch_die)])
-
-/* Convert a value into a corresponding argument. */
-
-char const *argmatch_to_argument (char const *value,
- char const *const *arglist,
- char const *vallist, size_t valsize)
- _GL_ATTRIBUTE_PURE;
-
-# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
- argmatch_to_argument (Value, Arglist, \
- (char const *) (Vallist), sizeof *(Vallist))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ARGMATCH_H_ */
+/* argmatch.h -- definitions and prototypes for argmatch.c
+
+ Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by David MacKenzie <djm@ai.mit.edu>
+ Modified by Akim Demaille <demaille@inf.enst.fr> */
+
+#ifndef ARGMATCH_H_
+# define ARGMATCH_H_ 1
+
+# include <stddef.h>
+
+# include "verify.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
+
+/* Assert there are as many real arguments as there are values
+ (argument list ends with a NULL guard). */
+
+# define ARGMATCH_VERIFY(Arglist, Vallist) \
+ verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
+
+/* Return the index of the element of ARGLIST (NULL terminated) that
+ matches with ARG. If VALLIST is not NULL, then use it to resolve
+ false ambiguities (i.e., different matches of ARG but corresponding
+ to the same values in VALLIST). */
+
+ptrdiff_t argmatch (char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
+
+# define ARGMATCH(Arg, Arglist, Vallist) \
+ argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+/* xargmatch calls this function when it fails. This function should not
+ return. By default, this is a function that calls ARGMATCH_DIE which
+ in turn defaults to 'exit (exit_failure)'. */
+typedef void (*argmatch_exit_fn) (void);
+extern argmatch_exit_fn argmatch_die;
+
+/* Report on stderr why argmatch failed. Report correct values. */
+
+void argmatch_invalid (char const *context, char const *value,
+ ptrdiff_t problem);
+
+/* Left for compatibility with the old name invalid_arg */
+
+# define invalid_arg(Context, Value, Problem) \
+ argmatch_invalid (Context, Value, Problem)
+
+
+
+/* Report on stderr the list of possible arguments. */
+
+void argmatch_valid (char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH_VALID(Arglist, Vallist) \
+ argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+
+
+/* Same as argmatch, but upon failure, report an explanation of the
+ failure, and exit using the function EXIT_FN. */
+
+ptrdiff_t __xargmatch_internal (char const *context,
+ char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn);
+
+/* Programmer friendly interface to __xargmatch_internal. */
+
+# define XARGMATCH(Context, Arg, Arglist, Vallist) \
+ ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
+ (char const *) (Vallist), \
+ sizeof *(Vallist), \
+ argmatch_die)])
+
+/* Convert a value into a corresponding argument. */
+
+char const *argmatch_to_argument (char const *value,
+ char const *const *arglist,
+ char const *vallist, size_t valsize)
+ _GL_ATTRIBUTE_PURE;
+
+# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
+ argmatch_to_argument (Value, Arglist, \
+ (char const *) (Vallist), sizeof *(Vallist))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ARGMATCH_H_ */
diff --git a/contrib/tools/bison/gnulib/src/asnprintf.c b/contrib/tools/bison/gnulib/src/asnprintf.c
index 76e228d860..a7ad9da181 100644
--- a/contrib/tools/bison/gnulib/src/asnprintf.c
+++ b/contrib/tools/bison/gnulib/src/asnprintf.c
@@ -1,34 +1,34 @@
-/* Formatted output to strings.
- Copyright (C) 1999, 2002, 2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "vasnprintf.h"
-
-#include <stdarg.h>
-
-char *
-asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
-{
- va_list args;
- char *result;
-
- va_start (args, format);
- result = vasnprintf (resultbuf, lengthp, format, args);
- va_end (args);
- return result;
-}
+/* Formatted output to strings.
+ Copyright (C) 1999, 2002, 2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "vasnprintf.h"
+
+#include <stdarg.h>
+
+char *
+asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
+{
+ va_list args;
+ char *result;
+
+ va_start (args, format);
+ result = vasnprintf (resultbuf, lengthp, format, args);
+ va_end (args);
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/basename-lgpl.c b/contrib/tools/bison/gnulib/src/basename-lgpl.c
index 9307e83142..250e90a4f3 100644
--- a/contrib/tools/bison/gnulib/src/basename-lgpl.c
+++ b/contrib/tools/bison/gnulib/src/basename-lgpl.c
@@ -1,75 +1,75 @@
-/* basename.c -- return the last element in a file name
-
- Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "dirname.h"
-
-#include <string.h>
-
-/* Return the address of the last file name component of NAME. If
- NAME has no relative file name components because it is a file
- system root, return the empty string. */
-
-char *
-last_component (char const *name)
-{
- char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
- char const *p;
- bool saw_slash = false;
-
- while (ISSLASH (*base))
- base++;
-
- for (p = base; *p; p++)
- {
- if (ISSLASH (*p))
- saw_slash = true;
- else if (saw_slash)
- {
- base = p;
- saw_slash = false;
- }
- }
-
- return (char *) base;
-}
-
-/* Return the length of the basename NAME. Typically NAME is the
- value returned by base_name or last_component. Act like strlen
- (NAME), except omit all trailing slashes. */
-
-size_t
-base_len (char const *name)
-{
- size_t len;
- size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
-
- for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
- continue;
-
- if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
- && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
- return 2;
-
- if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
- && len == prefix_len && ISSLASH (name[prefix_len]))
- return prefix_len + 1;
-
- return len;
-}
+/* basename.c -- return the last element in a file name
+
+ Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "dirname.h"
+
+#include <string.h>
+
+/* Return the address of the last file name component of NAME. If
+ NAME has no relative file name components because it is a file
+ system root, return the empty string. */
+
+char *
+last_component (char const *name)
+{
+ char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
+ char const *p;
+ bool saw_slash = false;
+
+ while (ISSLASH (*base))
+ base++;
+
+ for (p = base; *p; p++)
+ {
+ if (ISSLASH (*p))
+ saw_slash = true;
+ else if (saw_slash)
+ {
+ base = p;
+ saw_slash = false;
+ }
+ }
+
+ return (char *) base;
+}
+
+/* Return the length of the basename NAME. Typically NAME is the
+ value returned by base_name or last_component. Act like strlen
+ (NAME), except omit all trailing slashes. */
+
+size_t
+base_len (char const *name)
+{
+ size_t len;
+ size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
+
+ for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
+ continue;
+
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
+ && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
+ return 2;
+
+ if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
+ && len == prefix_len && ISSLASH (name[prefix_len]))
+ return prefix_len + 1;
+
+ return len;
+}
diff --git a/contrib/tools/bison/gnulib/src/basename.c b/contrib/tools/bison/gnulib/src/basename.c
index d73fd41aa1..bb4b84bb4c 100644
--- a/contrib/tools/bison/gnulib/src/basename.c
+++ b/contrib/tools/bison/gnulib/src/basename.c
@@ -1,58 +1,58 @@
-/* basename.c -- return the last element in a file name
-
- Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "dirname.h"
-
-#include <string.h>
-#include "xalloc.h"
-#include "xstrndup.h"
-
-char *
-base_name (char const *name)
-{
- char const *base = last_component (name);
- size_t length;
-
- /* If there is no last component, then name is a file system root or the
- empty string. */
- if (! *base)
- return xstrndup (name, base_len (name));
-
- /* Collapse a sequence of trailing slashes into one. */
- length = base_len (base);
- if (ISSLASH (base[length]))
- length++;
-
- /* On systems with drive letters, "a/b:c" must return "./b:c" rather
- than "b:c" to avoid confusion with a drive letter. On systems
- with pure POSIX semantics, this is not an issue. */
- if (FILE_SYSTEM_PREFIX_LEN (base))
- {
- char *p = xmalloc (length + 3);
- p[0] = '.';
- p[1] = '/';
- memcpy (p + 2, base, length);
- p[length + 2] = '\0';
- return p;
- }
-
- /* Finally, copy the basename. */
- return xstrndup (base, length);
-}
+/* basename.c -- return the last element in a file name
+
+ Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "dirname.h"
+
+#include <string.h>
+#include "xalloc.h"
+#include "xstrndup.h"
+
+char *
+base_name (char const *name)
+{
+ char const *base = last_component (name);
+ size_t length;
+
+ /* If there is no last component, then name is a file system root or the
+ empty string. */
+ if (! *base)
+ return xstrndup (name, base_len (name));
+
+ /* Collapse a sequence of trailing slashes into one. */
+ length = base_len (base);
+ if (ISSLASH (base[length]))
+ length++;
+
+ /* On systems with drive letters, "a/b:c" must return "./b:c" rather
+ than "b:c" to avoid confusion with a drive letter. On systems
+ with pure POSIX semantics, this is not an issue. */
+ if (FILE_SYSTEM_PREFIX_LEN (base))
+ {
+ char *p = xmalloc (length + 3);
+ p[0] = '.';
+ p[1] = '/';
+ memcpy (p + 2, base, length);
+ p[length + 2] = '\0';
+ return p;
+ }
+
+ /* Finally, copy the basename. */
+ return xstrndup (base, length);
+}
diff --git a/contrib/tools/bison/gnulib/src/bbitset.h b/contrib/tools/bison/gnulib/src/bbitset.h
index 443d2da2e8..19db92e637 100644
--- a/contrib/tools/bison/gnulib/src/bbitset.h
+++ b/contrib/tools/bison/gnulib/src/bbitset.h
@@ -1,304 +1,304 @@
-/* Base bitset stuff.
-
- Copyright (C) 2002-2004, 2006, 2009-2013 Free Software Foundation,
- Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _BBITSET_H
-#define _BBITSET_H
-
-#include "libiberty.h"
-
-#include <stdbool.h>
-#include <limits.h>
-#include <stddef.h>
-
-/* Currently we support five flavours of bitsets:
- BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets).
- Memory for bit array and bitset structure allocated
- contiguously.
- BITSET_LIST: Linked list of arrays of bits (variable size, least storage
- for large very sparse sets).
- BITSET_TABLE: Expandable table of pointers to arrays of bits
- (variable size, less storage for large sparse sets).
- Faster than BITSET_LIST for random access.
- BITSET_VARRAY: Variable array of bits (variable size, fast for
- dense bitsets).
- BITSET_STATS: Wrapper bitset for internal use only. Used for gathering
- statistics and/or better run-time checking.
-*/
-enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_VARRAY,
- BITSET_TYPE_NUM, BITSET_STATS};
-#define BITSET_TYPE_NAMES {"abitset", "lbitset", "ebitset", "vbitset"}
-
-extern const char * const bitset_type_names[];
-
-enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};
-
-/* Data type used to store a word of bits. */
-typedef unsigned long int bitset_word;
-#define BITSET_WORD_BITS ((unsigned int) (CHAR_BIT * sizeof (bitset_word)))
-
-/* Bit index. In theory we might need a type wider than size_t, but
- in practice we lose at most a factor of CHAR_BIT by going with
- size_t, and that is good enough. If this type is changed to be
- wider than size_t, the code needs to be modified to check for
- overflow when converting bit counts to byte or word counts.
- The bit and word index types must be unsigned. */
-typedef size_t bitset_bindex;
-
-/* Word index. */
-typedef size_t bitset_windex;
-
-/* Maximum values for commonly-used unsigned types. BITSET_SIZE_MAX
- always equals SIZE_MAX, but some older systems lack SIZE_MAX. */
-#define BITSET_BINDEX_MAX ((bitset_bindex) -1)
-
-/* Limit max word index to the maximum value of a signed integer
- to simplify cache disabling. */
-#define BITSET_WINDEX_MAX (((bitset_windex) -1) >> 1)
-#define BITSET_SIZE_MAX ((size_t) -1)
-
-#define BITSET_MSB ((bitset_word) 1 << (BITSET_WORD_BITS - 1))
-
-#define BITSET_LIST_SIZE 1024
-
-enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
- BITSET_OP_COPY, BITSET_OP_NOT,
- BITSET_OP_EMPTY_P, BITSET_OP_EQUAL_P,
- BITSET_OP_SUBSET_P, BITSET_OP_DISJOINT_P,
- BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
- BITSET_OP_OR_AND, BITSET_OP_AND_OR, BITSET_OP_ANDN_OR};
-
-struct bbitset_struct
-{
- const struct bitset_vtable *vtable;
- bitset_windex cindex; /* Cache word index. */
- bitset_windex csize; /* Cache size in words. */
- bitset_word *cdata; /* Cache data pointer. */
- bitset_bindex n_bits; /* Number of bits. */
- /* Perhaps we could sacrifice another word to indicate
- that the bitset is known to be zero, that a bit has been set
- in the cache, and that a bit has been cleared in the cache.
- This would speed up some of the searches but slightly slow down
- bit set/reset operations of cached bits. */
-};
-
-
-typedef union bitset_union *bitset;
-
-
-/* Private accessor macros to bitset structure. */
-#define BITSET_VTABLE_(SRC) (SRC)->b.vtable
-#define BITSET_CINDEX_(SRC) (SRC)->b.cindex
-#define BITSET_CDATA_(SRC) (SRC)->b.cdata
-#define BITSET_CSIZE_(SRC) (SRC)->b.csize
-#define BITSET_NBITS_(SRC) (SRC)->b.n_bits
-
-
-/* The contents of this structure should be considered private. */
-struct bitset_vtable
-{
- void (*set) (bitset, bitset_bindex);
- void (*reset) (bitset, bitset_bindex);
- bool (*toggle) (bitset, bitset_bindex);
- bool (*test) (bitset, bitset_bindex);
- bitset_bindex (*resize) (bitset, bitset_bindex);
- bitset_bindex (*size) (bitset);
- bitset_bindex (*count) (bitset);
-
- bool (*empty_p) (bitset);
- void (*ones) (bitset);
- void (*zero) (bitset);
-
- void (*copy) (bitset, bitset);
- bool (*disjoint_p) (bitset, bitset);
- bool (*equal_p) (bitset, bitset);
- void (*not_) (bitset, bitset);
- bool (*subset_p) (bitset, bitset);
-
- void (*and_) (bitset, bitset, bitset);
- bool (*and_cmp) (bitset, bitset, bitset);
- void (*andn) (bitset, bitset, bitset);
- bool (*andn_cmp) (bitset, bitset, bitset);
- void (*or_) (bitset, bitset, bitset);
- bool (*or_cmp) (bitset, bitset, bitset);
- void (*xor_) (bitset, bitset, bitset);
- bool (*xor_cmp) (bitset, bitset, bitset);
-
- void (*and_or) (bitset, bitset, bitset, bitset);
- bool (*and_or_cmp) (bitset, bitset, bitset, bitset);
- void (*andn_or) (bitset, bitset, bitset, bitset);
- bool (*andn_or_cmp) (bitset, bitset, bitset, bitset);
- void (*or_and) (bitset, bitset, bitset, bitset);
- bool (*or_and_cmp) (bitset, bitset, bitset, bitset);
-
- bitset_bindex (*list) (bitset, bitset_bindex *, bitset_bindex,
- bitset_bindex *);
- bitset_bindex (*list_reverse) (bitset, bitset_bindex *, bitset_bindex,
- bitset_bindex *);
- void (*free) (bitset);
- enum bitset_type type;
-};
-
-#define BITSET_COMPATIBLE_(BSET1, BSET2) \
-((BSET1)->b.vtable == (BSET2)->b.vtable)
-
-#define BITSET_CHECK2_(DST, SRC) \
-if (!BITSET_COMPATIBLE_ (DST, SRC)) abort ();
-
-#define BITSET_CHECK3_(DST, SRC1, SRC2) \
-if (!BITSET_COMPATIBLE_ (DST, SRC1) \
- || !BITSET_COMPATIBLE_ (DST, SRC2)) abort ();
-
-#define BITSET_CHECK4_(DST, SRC1, SRC2, SRC3) \
-if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \
- || !BITSET_COMPATIBLE_ (DST, SRC3)) abort ();
-
-
-/* Redefine number of bits in bitset DST. */
-#define BITSET_RESIZE_(DST, SIZE) (DST)->b.vtable->resize (DST, SIZE)
-
-/* Return size in bits of bitset SRC. */
-#define BITSET_SIZE_(SRC) (SRC)->b.vtable->size (SRC)
-
-/* Return number of bits set in bitset SRC. */
-#define BITSET_COUNT_(SRC) (SRC)->b.vtable->count (SRC)
-
-/* Return type of bitset SRC. */
-#define BITSET_TYPE_(DST) (DST)->b.vtable->type
-
-/* Set bit BITNO in bitset DST. */
-#define BITSET_SET_(DST, BITNO) (DST)->b.vtable->set (DST, BITNO)
-
-/* Reset bit BITNO in bitset DST. */
-#define BITSET_RESET_(DST, BITNO) (DST)->b.vtable->reset (DST, BITNO)
-
-/* Toggle bit BITNO in bitset DST. */
-#define BITSET_TOGGLE_(DST, BITNO) (DST)->b.vtable->toggle (DST, BITNO)
-
-/* Return non-zero if bit BITNO in bitset SRC is set. */
-#define BITSET_TEST_(SRC, BITNO) (SRC)->b.vtable->test (SRC, BITNO)
-
-/* Free bitset SRC. */
-#define BITSET_FREE_(SRC)\
- ((SRC)->b.vtable->free ? (SRC)->b.vtable->free (SRC) :(void)0)
-
-
-/* Return SRC == 0. */
-#define BITSET_EMPTY_P_(SRC) (SRC)->b.vtable->empty_p (SRC)
-
-/* DST = ~0. */
-#define BITSET_ONES_(DST) (DST)->b.vtable->ones (DST)
-
-/* DST = 0. */
-#define BITSET_ZERO_(DST) (DST)->b.vtable->zero (DST)
-
-
-
-/* DST = SRC. */
-#define BITSET_COPY_(DST, SRC) (SRC)->b.vtable->copy (DST, SRC)
-
-/* Return DST & SRC == 0. */
-#define BITSET_DISJOINT_P_(DST, SRC) (SRC)->b.vtable->disjoint_p (DST, SRC)
-
-/* Return DST == SRC. */
-#define BITSET_EQUAL_P_(DST, SRC) (SRC)->b.vtable->equal_p (DST, SRC)
-
-/* DST = ~SRC. */
-#define BITSET_NOT_(DST, SRC) (SRC)->b.vtable->not_ (DST, SRC)
-
-/* Return DST == DST | SRC. */
-#define BITSET_SUBSET_P_(DST, SRC) (SRC)->b.vtable->subset_p (DST, SRC)
-
-
-/* DST = SRC1 & SRC2. */
-#define BITSET_AND_(DST, SRC1, SRC2) (SRC1)->b.vtable->and_ (DST, SRC1, SRC2)
-#define BITSET_AND_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->and_cmp (DST, SRC1, SRC2)
-
-/* DST = SRC1 & ~SRC2. */
-#define BITSET_ANDN_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn (DST, SRC1, SRC2)
-#define BITSET_ANDN_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn_cmp (DST, SRC1, SRC2)
-
-/* DST = SRC1 | SRC2. */
-#define BITSET_OR_(DST, SRC1, SRC2) (SRC1)->b.vtable->or_ (DST, SRC1, SRC2)
-#define BITSET_OR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->or_cmp (DST, SRC1, SRC2)
-
-/* DST = SRC1 ^ SRC2. */
-#define BITSET_XOR_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor_ (DST, SRC1, SRC2)
-#define BITSET_XOR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor_cmp (DST, SRC1, SRC2)
-
-
-
-/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
- DST != (SRC1 & SRC2) | SRC3. */
-#define BITSET_AND_OR_(DST, SRC1, SRC2, SRC3) \
- (SRC1)->b.vtable->and_or (DST, SRC1, SRC2, SRC3)
-#define BITSET_AND_OR_CMP_(DST, SRC1, SRC2, SRC3) \
- (SRC1)->b.vtable->and_or_cmp (DST, SRC1, SRC2, SRC3)
-
-/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
- DST != (SRC1 & ~SRC2) | SRC3. */
-#define BITSET_ANDN_OR_(DST, SRC1, SRC2, SRC3) \
- (SRC1)->b.vtable->andn_or (DST, SRC1, SRC2, SRC3)
-#define BITSET_ANDN_OR_CMP_(DST, SRC1, SRC2, SRC3) \
- (SRC1)->b.vtable->andn_or_cmp (DST, SRC1, SRC2, SRC3)
-
-/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
- DST != (SRC1 | SRC2) & SRC3. */
-#define BITSET_OR_AND_(DST, SRC1, SRC2, SRC3) \
- (SRC1)->b.vtable->or_and (DST, SRC1, SRC2, SRC3)
-#define BITSET_OR_AND_CMP_(DST, SRC1, SRC2, SRC3) \
- (SRC1)->b.vtable->or_and_cmp (DST, SRC1, SRC2, SRC3)
-
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT. Return with actual number of bits found and with *NEXT
- indicating where search stopped. */
-#define BITSET_LIST_(BSET, LIST, NUM, NEXT) \
- (BSET)->b.vtable->list (BSET, LIST, NUM, NEXT)
-
-/* Find reverse list of up to NUM bits set in BSET starting from and
- including NEXT. Return with actual number of bits found and with
- *NEXT indicating where search stopped. */
-#define BITSET_LIST_REVERSE_(BSET, LIST, NUM, NEXT) \
- (BSET)->b.vtable->list_reverse (BSET, LIST, NUM, NEXT)
-
-
-/* Private functions for bitset implementations. */
-
-extern bool bitset_toggle_ (bitset, bitset_bindex);
-
-extern bitset_bindex bitset_count_ (bitset);
-
-extern bitset_bindex bitset_size_ (bitset);
-
-extern bool bitset_copy_ (bitset, bitset);
-
-extern void bitset_and_or_ (bitset, bitset, bitset, bitset);
-
-extern bool bitset_and_or_cmp_ (bitset, bitset, bitset, bitset);
-
-extern void bitset_andn_or_ (bitset, bitset, bitset, bitset);
-
-extern bool bitset_andn_or_cmp_ (bitset, bitset, bitset, bitset);
-
-extern void bitset_or_and_ (bitset, bitset, bitset, bitset);
-
-extern bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset);
-
-#endif /* _BBITSET_H */
+/* Base bitset stuff.
+
+ Copyright (C) 2002-2004, 2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _BBITSET_H
+#define _BBITSET_H
+
+#include "libiberty.h"
+
+#include <stdbool.h>
+#include <limits.h>
+#include <stddef.h>
+
+/* Currently we support five flavours of bitsets:
+ BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets).
+ Memory for bit array and bitset structure allocated
+ contiguously.
+ BITSET_LIST: Linked list of arrays of bits (variable size, least storage
+ for large very sparse sets).
+ BITSET_TABLE: Expandable table of pointers to arrays of bits
+ (variable size, less storage for large sparse sets).
+ Faster than BITSET_LIST for random access.
+ BITSET_VARRAY: Variable array of bits (variable size, fast for
+ dense bitsets).
+ BITSET_STATS: Wrapper bitset for internal use only. Used for gathering
+ statistics and/or better run-time checking.
+*/
+enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_VARRAY,
+ BITSET_TYPE_NUM, BITSET_STATS};
+#define BITSET_TYPE_NAMES {"abitset", "lbitset", "ebitset", "vbitset"}
+
+extern const char * const bitset_type_names[];
+
+enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};
+
+/* Data type used to store a word of bits. */
+typedef unsigned long int bitset_word;
+#define BITSET_WORD_BITS ((unsigned int) (CHAR_BIT * sizeof (bitset_word)))
+
+/* Bit index. In theory we might need a type wider than size_t, but
+ in practice we lose at most a factor of CHAR_BIT by going with
+ size_t, and that is good enough. If this type is changed to be
+ wider than size_t, the code needs to be modified to check for
+ overflow when converting bit counts to byte or word counts.
+ The bit and word index types must be unsigned. */
+typedef size_t bitset_bindex;
+
+/* Word index. */
+typedef size_t bitset_windex;
+
+/* Maximum values for commonly-used unsigned types. BITSET_SIZE_MAX
+ always equals SIZE_MAX, but some older systems lack SIZE_MAX. */
+#define BITSET_BINDEX_MAX ((bitset_bindex) -1)
+
+/* Limit max word index to the maximum value of a signed integer
+ to simplify cache disabling. */
+#define BITSET_WINDEX_MAX (((bitset_windex) -1) >> 1)
+#define BITSET_SIZE_MAX ((size_t) -1)
+
+#define BITSET_MSB ((bitset_word) 1 << (BITSET_WORD_BITS - 1))
+
+#define BITSET_LIST_SIZE 1024
+
+enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
+ BITSET_OP_COPY, BITSET_OP_NOT,
+ BITSET_OP_EMPTY_P, BITSET_OP_EQUAL_P,
+ BITSET_OP_SUBSET_P, BITSET_OP_DISJOINT_P,
+ BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
+ BITSET_OP_OR_AND, BITSET_OP_AND_OR, BITSET_OP_ANDN_OR};
+
+struct bbitset_struct
+{
+ const struct bitset_vtable *vtable;
+ bitset_windex cindex; /* Cache word index. */
+ bitset_windex csize; /* Cache size in words. */
+ bitset_word *cdata; /* Cache data pointer. */
+ bitset_bindex n_bits; /* Number of bits. */
+ /* Perhaps we could sacrifice another word to indicate
+ that the bitset is known to be zero, that a bit has been set
+ in the cache, and that a bit has been cleared in the cache.
+ This would speed up some of the searches but slightly slow down
+ bit set/reset operations of cached bits. */
+};
+
+
+typedef union bitset_union *bitset;
+
+
+/* Private accessor macros to bitset structure. */
+#define BITSET_VTABLE_(SRC) (SRC)->b.vtable
+#define BITSET_CINDEX_(SRC) (SRC)->b.cindex
+#define BITSET_CDATA_(SRC) (SRC)->b.cdata
+#define BITSET_CSIZE_(SRC) (SRC)->b.csize
+#define BITSET_NBITS_(SRC) (SRC)->b.n_bits
+
+
+/* The contents of this structure should be considered private. */
+struct bitset_vtable
+{
+ void (*set) (bitset, bitset_bindex);
+ void (*reset) (bitset, bitset_bindex);
+ bool (*toggle) (bitset, bitset_bindex);
+ bool (*test) (bitset, bitset_bindex);
+ bitset_bindex (*resize) (bitset, bitset_bindex);
+ bitset_bindex (*size) (bitset);
+ bitset_bindex (*count) (bitset);
+
+ bool (*empty_p) (bitset);
+ void (*ones) (bitset);
+ void (*zero) (bitset);
+
+ void (*copy) (bitset, bitset);
+ bool (*disjoint_p) (bitset, bitset);
+ bool (*equal_p) (bitset, bitset);
+ void (*not_) (bitset, bitset);
+ bool (*subset_p) (bitset, bitset);
+
+ void (*and_) (bitset, bitset, bitset);
+ bool (*and_cmp) (bitset, bitset, bitset);
+ void (*andn) (bitset, bitset, bitset);
+ bool (*andn_cmp) (bitset, bitset, bitset);
+ void (*or_) (bitset, bitset, bitset);
+ bool (*or_cmp) (bitset, bitset, bitset);
+ void (*xor_) (bitset, bitset, bitset);
+ bool (*xor_cmp) (bitset, bitset, bitset);
+
+ void (*and_or) (bitset, bitset, bitset, bitset);
+ bool (*and_or_cmp) (bitset, bitset, bitset, bitset);
+ void (*andn_or) (bitset, bitset, bitset, bitset);
+ bool (*andn_or_cmp) (bitset, bitset, bitset, bitset);
+ void (*or_and) (bitset, bitset, bitset, bitset);
+ bool (*or_and_cmp) (bitset, bitset, bitset, bitset);
+
+ bitset_bindex (*list) (bitset, bitset_bindex *, bitset_bindex,
+ bitset_bindex *);
+ bitset_bindex (*list_reverse) (bitset, bitset_bindex *, bitset_bindex,
+ bitset_bindex *);
+ void (*free) (bitset);
+ enum bitset_type type;
+};
+
+#define BITSET_COMPATIBLE_(BSET1, BSET2) \
+((BSET1)->b.vtable == (BSET2)->b.vtable)
+
+#define BITSET_CHECK2_(DST, SRC) \
+if (!BITSET_COMPATIBLE_ (DST, SRC)) abort ();
+
+#define BITSET_CHECK3_(DST, SRC1, SRC2) \
+if (!BITSET_COMPATIBLE_ (DST, SRC1) \
+ || !BITSET_COMPATIBLE_ (DST, SRC2)) abort ();
+
+#define BITSET_CHECK4_(DST, SRC1, SRC2, SRC3) \
+if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \
+ || !BITSET_COMPATIBLE_ (DST, SRC3)) abort ();
+
+
+/* Redefine number of bits in bitset DST. */
+#define BITSET_RESIZE_(DST, SIZE) (DST)->b.vtable->resize (DST, SIZE)
+
+/* Return size in bits of bitset SRC. */
+#define BITSET_SIZE_(SRC) (SRC)->b.vtable->size (SRC)
+
+/* Return number of bits set in bitset SRC. */
+#define BITSET_COUNT_(SRC) (SRC)->b.vtable->count (SRC)
+
+/* Return type of bitset SRC. */
+#define BITSET_TYPE_(DST) (DST)->b.vtable->type
+
+/* Set bit BITNO in bitset DST. */
+#define BITSET_SET_(DST, BITNO) (DST)->b.vtable->set (DST, BITNO)
+
+/* Reset bit BITNO in bitset DST. */
+#define BITSET_RESET_(DST, BITNO) (DST)->b.vtable->reset (DST, BITNO)
+
+/* Toggle bit BITNO in bitset DST. */
+#define BITSET_TOGGLE_(DST, BITNO) (DST)->b.vtable->toggle (DST, BITNO)
+
+/* Return non-zero if bit BITNO in bitset SRC is set. */
+#define BITSET_TEST_(SRC, BITNO) (SRC)->b.vtable->test (SRC, BITNO)
+
+/* Free bitset SRC. */
+#define BITSET_FREE_(SRC)\
+ ((SRC)->b.vtable->free ? (SRC)->b.vtable->free (SRC) :(void)0)
+
+
+/* Return SRC == 0. */
+#define BITSET_EMPTY_P_(SRC) (SRC)->b.vtable->empty_p (SRC)
+
+/* DST = ~0. */
+#define BITSET_ONES_(DST) (DST)->b.vtable->ones (DST)
+
+/* DST = 0. */
+#define BITSET_ZERO_(DST) (DST)->b.vtable->zero (DST)
+
+
+
+/* DST = SRC. */
+#define BITSET_COPY_(DST, SRC) (SRC)->b.vtable->copy (DST, SRC)
+
+/* Return DST & SRC == 0. */
+#define BITSET_DISJOINT_P_(DST, SRC) (SRC)->b.vtable->disjoint_p (DST, SRC)
+
+/* Return DST == SRC. */
+#define BITSET_EQUAL_P_(DST, SRC) (SRC)->b.vtable->equal_p (DST, SRC)
+
+/* DST = ~SRC. */
+#define BITSET_NOT_(DST, SRC) (SRC)->b.vtable->not_ (DST, SRC)
+
+/* Return DST == DST | SRC. */
+#define BITSET_SUBSET_P_(DST, SRC) (SRC)->b.vtable->subset_p (DST, SRC)
+
+
+/* DST = SRC1 & SRC2. */
+#define BITSET_AND_(DST, SRC1, SRC2) (SRC1)->b.vtable->and_ (DST, SRC1, SRC2)
+#define BITSET_AND_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->and_cmp (DST, SRC1, SRC2)
+
+/* DST = SRC1 & ~SRC2. */
+#define BITSET_ANDN_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn (DST, SRC1, SRC2)
+#define BITSET_ANDN_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn_cmp (DST, SRC1, SRC2)
+
+/* DST = SRC1 | SRC2. */
+#define BITSET_OR_(DST, SRC1, SRC2) (SRC1)->b.vtable->or_ (DST, SRC1, SRC2)
+#define BITSET_OR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->or_cmp (DST, SRC1, SRC2)
+
+/* DST = SRC1 ^ SRC2. */
+#define BITSET_XOR_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor_ (DST, SRC1, SRC2)
+#define BITSET_XOR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor_cmp (DST, SRC1, SRC2)
+
+
+
+/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
+ DST != (SRC1 & SRC2) | SRC3. */
+#define BITSET_AND_OR_(DST, SRC1, SRC2, SRC3) \
+ (SRC1)->b.vtable->and_or (DST, SRC1, SRC2, SRC3)
+#define BITSET_AND_OR_CMP_(DST, SRC1, SRC2, SRC3) \
+ (SRC1)->b.vtable->and_or_cmp (DST, SRC1, SRC2, SRC3)
+
+/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
+ DST != (SRC1 & ~SRC2) | SRC3. */
+#define BITSET_ANDN_OR_(DST, SRC1, SRC2, SRC3) \
+ (SRC1)->b.vtable->andn_or (DST, SRC1, SRC2, SRC3)
+#define BITSET_ANDN_OR_CMP_(DST, SRC1, SRC2, SRC3) \
+ (SRC1)->b.vtable->andn_or_cmp (DST, SRC1, SRC2, SRC3)
+
+/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
+ DST != (SRC1 | SRC2) & SRC3. */
+#define BITSET_OR_AND_(DST, SRC1, SRC2, SRC3) \
+ (SRC1)->b.vtable->or_and (DST, SRC1, SRC2, SRC3)
+#define BITSET_OR_AND_CMP_(DST, SRC1, SRC2, SRC3) \
+ (SRC1)->b.vtable->or_and_cmp (DST, SRC1, SRC2, SRC3)
+
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT. Return with actual number of bits found and with *NEXT
+ indicating where search stopped. */
+#define BITSET_LIST_(BSET, LIST, NUM, NEXT) \
+ (BSET)->b.vtable->list (BSET, LIST, NUM, NEXT)
+
+/* Find reverse list of up to NUM bits set in BSET starting from and
+ including NEXT. Return with actual number of bits found and with
+ *NEXT indicating where search stopped. */
+#define BITSET_LIST_REVERSE_(BSET, LIST, NUM, NEXT) \
+ (BSET)->b.vtable->list_reverse (BSET, LIST, NUM, NEXT)
+
+
+/* Private functions for bitset implementations. */
+
+extern bool bitset_toggle_ (bitset, bitset_bindex);
+
+extern bitset_bindex bitset_count_ (bitset);
+
+extern bitset_bindex bitset_size_ (bitset);
+
+extern bool bitset_copy_ (bitset, bitset);
+
+extern void bitset_and_or_ (bitset, bitset, bitset, bitset);
+
+extern bool bitset_and_or_cmp_ (bitset, bitset, bitset, bitset);
+
+extern void bitset_andn_or_ (bitset, bitset, bitset, bitset);
+
+extern bool bitset_andn_or_cmp_ (bitset, bitset, bitset, bitset);
+
+extern void bitset_or_and_ (bitset, bitset, bitset, bitset);
+
+extern bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset);
+
+#endif /* _BBITSET_H */
diff --git a/contrib/tools/bison/gnulib/src/binary-io.c b/contrib/tools/bison/gnulib/src/binary-io.c
index 8bbdb44d12..95cbf89b97 100644
--- a/contrib/tools/bison/gnulib/src/binary-io.c
+++ b/contrib/tools/bison/gnulib/src/binary-io.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define BINARY_IO_INLINE _GL_EXTERN_INLINE
-#include "binary-io.h"
+#include <config.h>
+#define BINARY_IO_INLINE _GL_EXTERN_INLINE
+#include "binary-io.h"
diff --git a/contrib/tools/bison/gnulib/src/binary-io.h b/contrib/tools/bison/gnulib/src/binary-io.h
index 423c2ae3ff..f99d6da02c 100644
--- a/contrib/tools/bison/gnulib/src/binary-io.h
+++ b/contrib/tools/bison/gnulib/src/binary-io.h
@@ -1,75 +1,75 @@
-/* Binary mode I/O.
- Copyright (C) 2001, 2003, 2005, 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _BINARY_H
-#define _BINARY_H
-
-/* For systems that distinguish between text and binary I/O.
- O_BINARY is guaranteed by the gnulib <fcntl.h>. */
-#include <fcntl.h>
-
-/* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
- so we include it here first. */
-#include <stdio.h>
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef BINARY_IO_INLINE
-# define BINARY_IO_INLINE _GL_INLINE
-#endif
-
-/* set_binary_mode (fd, mode)
- sets the binary/text I/O mode of file descriptor fd to the given mode
- (must be O_BINARY or O_TEXT) and returns the previous mode. */
-#if O_BINARY
-# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
-# include <io.h> /* declares setmode() */
-# define set_binary_mode setmode
-# else
-# define set_binary_mode _setmode
-# undef fileno
-# define fileno _fileno
-# endif
-#else
- /* On reasonable systems, binary I/O is the only choice. */
- /* Use a function rather than a macro, to avoid gcc warnings
- "warning: statement with no effect". */
-BINARY_IO_INLINE int
-set_binary_mode (int fd, int mode)
-{
- (void) fd;
- (void) mode;
- return O_BINARY;
-}
-#endif
-
-/* SET_BINARY (fd);
- changes the file descriptor fd to perform binary I/O. */
-#ifdef __DJGPP__
-# include <unistd.h> /* declares isatty() */
- /* Avoid putting stdin/stdout in binary mode if it is connected to
- the console, because that would make it impossible for the user
- to interrupt the program through Ctrl-C or Ctrl-Break. */
-# define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
-#else
-# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
-#endif
-
-_GL_INLINE_HEADER_END
-
-#endif /* _BINARY_H */
+/* Binary mode I/O.
+ Copyright (C) 2001, 2003, 2005, 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _BINARY_H
+#define _BINARY_H
+
+/* For systems that distinguish between text and binary I/O.
+ O_BINARY is guaranteed by the gnulib <fcntl.h>. */
+#include <fcntl.h>
+
+/* The MSVC7 <stdio.h> doesn't like to be included after '#define fileno ...',
+ so we include it here first. */
+#include <stdio.h>
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef BINARY_IO_INLINE
+# define BINARY_IO_INLINE _GL_INLINE
+#endif
+
+/* set_binary_mode (fd, mode)
+ sets the binary/text I/O mode of file descriptor fd to the given mode
+ (must be O_BINARY or O_TEXT) and returns the previous mode. */
+#if O_BINARY
+# if defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__
+# include <io.h> /* declares setmode() */
+# define set_binary_mode setmode
+# else
+# define set_binary_mode _setmode
+# undef fileno
+# define fileno _fileno
+# endif
+#else
+ /* On reasonable systems, binary I/O is the only choice. */
+ /* Use a function rather than a macro, to avoid gcc warnings
+ "warning: statement with no effect". */
+BINARY_IO_INLINE int
+set_binary_mode (int fd, int mode)
+{
+ (void) fd;
+ (void) mode;
+ return O_BINARY;
+}
+#endif
+
+/* SET_BINARY (fd);
+ changes the file descriptor fd to perform binary I/O. */
+#ifdef __DJGPP__
+# include <unistd.h> /* declares isatty() */
+ /* Avoid putting stdin/stdout in binary mode if it is connected to
+ the console, because that would make it impossible for the user
+ to interrupt the program through Ctrl-C or Ctrl-Break. */
+# define SET_BINARY(fd) ((void) (!isatty (fd) ? (set_binary_mode (fd, O_BINARY), 0) : 0))
+#else
+# define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY))
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif /* _BINARY_H */
diff --git a/contrib/tools/bison/gnulib/src/bison-system.h b/contrib/tools/bison/gnulib/src/bison-system.h
index 472a1921a7..eb60509bb4 100644
--- a/contrib/tools/bison/gnulib/src/bison-system.h
+++ b/contrib/tools/bison/gnulib/src/bison-system.h
@@ -1,264 +1,264 @@
-/* System-dependent definitions for Bison.
-
- Copyright (C) 2000-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef BISON_SYSTEM_H
-# define BISON_SYSTEM_H
-
-/* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this
- runs afoul of pre-C99 compilers that have <inttypes.h> or
- <stdint.h>, which are included below if available. It also runs
- afoul of pre-C99 compilers that define these macros in <limits.h>. */
-# if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901
-# undef INT8_MIN
-# undef INT16_MIN
-# undef INT32_MIN
-# undef INT8_MAX
-# undef INT16_MAX
-# undef UINT8_MAX
-# undef INT32_MAX
-# undef UINT16_MAX
-# undef UINT32_MAX
-# endif
-
-# include <limits.h>
-# include <stddef.h>
-# include <stdlib.h>
-# include <string.h>
-
-# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
-# define STREQ(L, R) (strcmp(L, R) == 0)
-# define STRNEQ(L, R) (!STREQ(L, R))
-
-/* Just like strncmp, but the second argument must be a literal string
- and you don't specify the length. */
-# define STRNCMP_LIT(S, Literal) \
- strncmp (S, "" Literal "", sizeof (Literal) - 1)
-
-/* Whether Literal is a prefix of S. */
-# define STRPREFIX_LIT(Literal, S) \
- (STRNCMP_LIT (S, Literal) == 0)
-
-# include <unistd.h>
+/* System-dependent definitions for Bison.
+
+ Copyright (C) 2000-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef BISON_SYSTEM_H
+# define BISON_SYSTEM_H
+
+/* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this
+ runs afoul of pre-C99 compilers that have <inttypes.h> or
+ <stdint.h>, which are included below if available. It also runs
+ afoul of pre-C99 compilers that define these macros in <limits.h>. */
+# if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901
+# undef INT8_MIN
+# undef INT16_MIN
+# undef INT32_MIN
+# undef INT8_MAX
+# undef INT16_MAX
+# undef UINT8_MAX
+# undef INT32_MAX
+# undef UINT16_MAX
+# undef UINT32_MAX
+# endif
+
+# include <limits.h>
+# include <stddef.h>
+# include <stdlib.h>
+# include <string.h>
+
+# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
+# define STREQ(L, R) (strcmp(L, R) == 0)
+# define STRNEQ(L, R) (!STREQ(L, R))
+
+/* Just like strncmp, but the second argument must be a literal string
+ and you don't specify the length. */
+# define STRNCMP_LIT(S, Literal) \
+ strncmp (S, "" Literal "", sizeof (Literal) - 1)
+
+/* Whether Literal is a prefix of S. */
+# define STRPREFIX_LIT(Literal, S) \
+ (STRNCMP_LIT (S, Literal) == 0)
+
+# include <unistd.h>
#if (defined _MSC_VER) && (_MSC_VER < 1800)
#else
-# include <inttypes.h>
+# include <inttypes.h>
#endif
-
-# ifndef UINTPTR_MAX
-/* This isn't perfect, but it's good enough for Bison, which needs
- only to hash pointers. */
-typedef size_t uintptr_t;
-# endif
-
-/* Version mismatch. */
-# define EX_MISMATCH 63
-
-/*---------.
-| Gnulib. |
-`---------*/
-
-# include <unlocked-io.h>
-# include <verify.h>
-# include <xalloc.h>
-
-
-/*-----------------.
-| GCC extensions. |
-`-----------------*/
-
-/* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison
- but that it is necessary for suppressing compiler warnings. For example,
- Code might be a variable initializer that's always overwritten before the
- variable is used.
-
- PACIFY_CC is intended to be useful only as a comment as it does not alter
- Code. It is tempting to redefine PACIFY_CC so that it will suppress Code
- when configuring without --enable-gcc-warnings. However, that would mean
- that, for maintainers, Bison would compile with potentially less warnings
- and safer logic than it would for users. Due to the overhead of M4,
- suppressing Code is unlikely to offer any significant improvement in
- Bison's performance anyway. */
-# define PACIFY_CC(Code) Code
-
-# ifndef __attribute__
-/* This feature is available in gcc versions 2.5 and later. */
-# if (! defined __GNUC__ || __GNUC__ < 2 \
- || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
-# define __attribute__(Spec) /* empty */
-# endif
-# endif
-
-/* The __-protected variants of 'format' and 'printf' attributes
- are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __format__ format
-# define __printf__ printf
-# endif
-
-# ifndef ATTRIBUTE_NORETURN
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
-# endif
-
-# ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-# endif
-
-
-/*------.
-| NLS. |
-`------*/
-
-# include <locale.h>
-
-# include <gettext.h>
-# define _(Msgid) gettext (Msgid)
-# define N_(Msgid) (Msgid)
-
-
-/*-----------.
-| Booleans. |
-`-----------*/
-
-# include <stdbool.h>
-
-
-
-/*-------------.
-| Assertions. |
-`-------------*/
-
-/* In the past, Bison defined aver to simply invoke abort in the case of
- a failed assertion. The rationale was that <assert.h>'s assertions
- were too heavyweight and could be disabled too easily. See
- discussions at
- <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
- <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
-
- However, normal assert output can be helpful during development and
- in bug reports from users. Moreover, it's not clear now that
- <assert.h>'s assertions are significantly heavyweight. Finally, if
- users want to experiment with disabling assertions, it's debatable
- whether it's our responsibility to stop them. See discussion
- starting at
- <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
-
- For now, we use assert but we call it aver throughout Bison in case
- we later wish to try another scheme.
-*/
-# include <assert.h>
-# define aver assert
-
-
-/*-----------.
-| Obstacks. |
-`-----------*/
-
-# define obstack_chunk_alloc xmalloc
-# define obstack_chunk_free free
-# include <obstack.h>
-
-/* String-grow: append Str to Obs. */
-
-# define obstack_sgrow(Obs, Str) \
- obstack_grow (Obs, Str, strlen (Str))
-
-/* Output Str escaped for our postprocessing (i.e., escape M4 special
- characters).
-
- For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */
-
-# define obstack_escape(Obs, Str) \
- do { \
- char const *p__; \
- for (p__ = Str; *p__; p__++) \
- switch (*p__) \
- { \
- case '$': obstack_sgrow (Obs, "$]["); break; \
- case '@': obstack_sgrow (Obs, "@@" ); break; \
- case '[': obstack_sgrow (Obs, "@{" ); break; \
- case ']': obstack_sgrow (Obs, "@}" ); break; \
- default: obstack_1grow (Obs, *p__ ); break; \
- } \
- } while (0)
-
-
-/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
- for our postprocessing (i.e., escape M4 special characters). If
- Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
- programming easier (m4_ifval can be used).
-
- For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
-
-# define obstack_quote(Obs, Str) \
- do { \
- char const* obstack_quote_p = Str; \
- if (obstack_quote_p && obstack_quote_p[0]) \
- { \
- obstack_sgrow (Obs, "[["); \
- obstack_escape (Obs, obstack_quote_p); \
- obstack_sgrow (Obs, "]]"); \
- } \
- else \
- obstack_sgrow (Obs, "[]"); \
- } while (0)
-
-
-/* Append the ending 0, finish Obs, and return the string. */
-
-# define obstack_finish0(Obs) \
- (obstack_1grow (Obs, '\0'), (char *) obstack_finish (Obs))
-
-
-/*-----------------------------------------.
-| Extensions to use for the output files. |
-`-----------------------------------------*/
-
-# ifndef OUTPUT_EXT
-# define OUTPUT_EXT ".output"
-# endif
-
-# ifndef TAB_EXT
-# define TAB_EXT ".tab"
-# endif
-
-
-
-/*---------------------.
-| Free a linked list. |
-`---------------------*/
-
-# define LIST_FREE(Type, List) \
- do { \
- Type *_node, *_next; \
- for (_node = List; _node; _node = _next) \
- { \
- _next = _node->next; \
- free (_node); \
- } \
- } while (0)
-
-
-/*---------------------------------------------.
-| Debugging memory allocation (must be last). |
-`---------------------------------------------*/
-
-# if WITH_DMALLOC
-# define DMALLOC_FUNC_CHECK
-# include <dmalloc.h>
-# endif /* WITH_DMALLOC */
-
-#endif /* ! BISON_SYSTEM_H */
+
+# ifndef UINTPTR_MAX
+/* This isn't perfect, but it's good enough for Bison, which needs
+ only to hash pointers. */
+typedef size_t uintptr_t;
+# endif
+
+/* Version mismatch. */
+# define EX_MISMATCH 63
+
+/*---------.
+| Gnulib. |
+`---------*/
+
+# include <unlocked-io.h>
+# include <verify.h>
+# include <xalloc.h>
+
+
+/*-----------------.
+| GCC extensions. |
+`-----------------*/
+
+/* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison
+ but that it is necessary for suppressing compiler warnings. For example,
+ Code might be a variable initializer that's always overwritten before the
+ variable is used.
+
+ PACIFY_CC is intended to be useful only as a comment as it does not alter
+ Code. It is tempting to redefine PACIFY_CC so that it will suppress Code
+ when configuring without --enable-gcc-warnings. However, that would mean
+ that, for maintainers, Bison would compile with potentially less warnings
+ and safer logic than it would for users. Due to the overhead of M4,
+ suppressing Code is unlikely to offer any significant improvement in
+ Bison's performance anyway. */
+# define PACIFY_CC(Code) Code
+
+# ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later. */
+# if (! defined __GNUC__ || __GNUC__ < 2 \
+ || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
+# define __attribute__(Spec) /* empty */
+# endif
+# endif
+
+/* The __-protected variants of 'format' and 'printf' attributes
+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+# define __format__ format
+# define __printf__ printf
+# endif
+
+# ifndef ATTRIBUTE_NORETURN
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# endif
+
+# ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+# endif
+
+
+/*------.
+| NLS. |
+`------*/
+
+# include <locale.h>
+
+# include <gettext.h>
+# define _(Msgid) gettext (Msgid)
+# define N_(Msgid) (Msgid)
+
+
+/*-----------.
+| Booleans. |
+`-----------*/
+
+# include <stdbool.h>
+
+
+
+/*-------------.
+| Assertions. |
+`-------------*/
+
+/* In the past, Bison defined aver to simply invoke abort in the case of
+ a failed assertion. The rationale was that <assert.h>'s assertions
+ were too heavyweight and could be disabled too easily. See
+ discussions at
+ <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
+ <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
+
+ However, normal assert output can be helpful during development and
+ in bug reports from users. Moreover, it's not clear now that
+ <assert.h>'s assertions are significantly heavyweight. Finally, if
+ users want to experiment with disabling assertions, it's debatable
+ whether it's our responsibility to stop them. See discussion
+ starting at
+ <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
+
+ For now, we use assert but we call it aver throughout Bison in case
+ we later wish to try another scheme.
+*/
+# include <assert.h>
+# define aver assert
+
+
+/*-----------.
+| Obstacks. |
+`-----------*/
+
+# define obstack_chunk_alloc xmalloc
+# define obstack_chunk_free free
+# include <obstack.h>
+
+/* String-grow: append Str to Obs. */
+
+# define obstack_sgrow(Obs, Str) \
+ obstack_grow (Obs, Str, strlen (Str))
+
+/* Output Str escaped for our postprocessing (i.e., escape M4 special
+ characters).
+
+ For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */
+
+# define obstack_escape(Obs, Str) \
+ do { \
+ char const *p__; \
+ for (p__ = Str; *p__; p__++) \
+ switch (*p__) \
+ { \
+ case '$': obstack_sgrow (Obs, "$]["); break; \
+ case '@': obstack_sgrow (Obs, "@@" ); break; \
+ case '[': obstack_sgrow (Obs, "@{" ); break; \
+ case ']': obstack_sgrow (Obs, "@}" ); break; \
+ default: obstack_1grow (Obs, *p__ ); break; \
+ } \
+ } while (0)
+
+
+/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
+ for our postprocessing (i.e., escape M4 special characters). If
+ Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
+ programming easier (m4_ifval can be used).
+
+ For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
+
+# define obstack_quote(Obs, Str) \
+ do { \
+ char const* obstack_quote_p = Str; \
+ if (obstack_quote_p && obstack_quote_p[0]) \
+ { \
+ obstack_sgrow (Obs, "[["); \
+ obstack_escape (Obs, obstack_quote_p); \
+ obstack_sgrow (Obs, "]]"); \
+ } \
+ else \
+ obstack_sgrow (Obs, "[]"); \
+ } while (0)
+
+
+/* Append the ending 0, finish Obs, and return the string. */
+
+# define obstack_finish0(Obs) \
+ (obstack_1grow (Obs, '\0'), (char *) obstack_finish (Obs))
+
+
+/*-----------------------------------------.
+| Extensions to use for the output files. |
+`-----------------------------------------*/
+
+# ifndef OUTPUT_EXT
+# define OUTPUT_EXT ".output"
+# endif
+
+# ifndef TAB_EXT
+# define TAB_EXT ".tab"
+# endif
+
+
+
+/*---------------------.
+| Free a linked list. |
+`---------------------*/
+
+# define LIST_FREE(Type, List) \
+ do { \
+ Type *_node, *_next; \
+ for (_node = List; _node; _node = _next) \
+ { \
+ _next = _node->next; \
+ free (_node); \
+ } \
+ } while (0)
+
+
+/*---------------------------------------------.
+| Debugging memory allocation (must be last). |
+`---------------------------------------------*/
+
+# if WITH_DMALLOC
+# define DMALLOC_FUNC_CHECK
+# include <dmalloc.h>
+# endif /* WITH_DMALLOC */
+
+#endif /* ! BISON_SYSTEM_H */
diff --git a/contrib/tools/bison/gnulib/src/bitrotate.c b/contrib/tools/bison/gnulib/src/bitrotate.c
index a8f602889d..137156fe15 100644
--- a/contrib/tools/bison/gnulib/src/bitrotate.c
+++ b/contrib/tools/bison/gnulib/src/bitrotate.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define BITROTATE_INLINE _GL_EXTERN_INLINE
-#include "bitrotate.h"
+#include <config.h>
+#define BITROTATE_INLINE _GL_EXTERN_INLINE
+#include "bitrotate.h"
diff --git a/contrib/tools/bison/gnulib/src/bitrotate.h b/contrib/tools/bison/gnulib/src/bitrotate.h
index 9e10a45f43..fab0447667 100644
--- a/contrib/tools/bison/gnulib/src/bitrotate.h
+++ b/contrib/tools/bison/gnulib/src/bitrotate.h
@@ -1,133 +1,133 @@
-/* bitrotate.h - Rotate bits in integers
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Simon Josefsson <simon@josefsson.org>, 2008. */
-
-#ifndef _GL_BITROTATE_H
-#define _GL_BITROTATE_H
-
-#include <limits.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-_GL_INLINE_HEADER_BEGIN
-#ifndef BITROTATE_INLINE
-# define BITROTATE_INLINE _GL_INLINE
-#endif
-
-#ifdef UINT64_MAX
-/* Given an unsigned 64-bit argument X, return the value corresponding
- to rotating the bits N steps to the left. N must be between 1 and
- 63 inclusive. */
-BITROTATE_INLINE uint64_t
-rotl64 (uint64_t x, int n)
-{
- return ((x << n) | (x >> (64 - n))) & UINT64_MAX;
-}
-
-/* Given an unsigned 64-bit argument X, return the value corresponding
- to rotating the bits N steps to the right. N must be between 1 to
- 63 inclusive.*/
-BITROTATE_INLINE uint64_t
-rotr64 (uint64_t x, int n)
-{
- return ((x >> n) | (x << (64 - n))) & UINT64_MAX;
-}
-#endif
-
-/* Given an unsigned 32-bit argument X, return the value corresponding
- to rotating the bits N steps to the left. N must be between 1 and
- 31 inclusive. */
-BITROTATE_INLINE uint32_t
-rotl32 (uint32_t x, int n)
-{
- return ((x << n) | (x >> (32 - n))) & UINT32_MAX;
-}
-
-/* Given an unsigned 32-bit argument X, return the value corresponding
- to rotating the bits N steps to the right. N must be between 1 to
- 31 inclusive.*/
-BITROTATE_INLINE uint32_t
-rotr32 (uint32_t x, int n)
-{
- return ((x >> n) | (x << (32 - n))) & UINT32_MAX;
-}
-
-/* Given a size_t argument X, return the value corresponding
- to rotating the bits N steps to the left. N must be between 1 and
- (CHAR_BIT * sizeof (size_t) - 1) inclusive. */
-BITROTATE_INLINE size_t
-rotl_sz (size_t x, int n)
-{
- return ((x << n) | (x >> ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX;
-}
-
-/* Given a size_t argument X, return the value corresponding
- to rotating the bits N steps to the right. N must be between 1 to
- (CHAR_BIT * sizeof (size_t) - 1) inclusive. */
-BITROTATE_INLINE size_t
-rotr_sz (size_t x, int n)
-{
- return ((x >> n) | (x << ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX;
-}
-
-/* Given an unsigned 16-bit argument X, return the value corresponding
- to rotating the bits N steps to the left. N must be between 1 to
- 15 inclusive, but on most relevant targets N can also be 0 and 16
- because 'int' is at least 32 bits and the arguments must widen
- before shifting. */
-BITROTATE_INLINE uint16_t
-rotl16 (uint16_t x, int n)
-{
- return ((x << n) | (x >> (16 - n))) & UINT16_MAX;
-}
-
-/* Given an unsigned 16-bit argument X, return the value corresponding
- to rotating the bits N steps to the right. N must be in 1 to 15
- inclusive, but on most relevant targets N can also be 0 and 16
- because 'int' is at least 32 bits and the arguments must widen
- before shifting. */
-BITROTATE_INLINE uint16_t
-rotr16 (uint16_t x, int n)
-{
- return ((x >> n) | (x << (16 - n))) & UINT16_MAX;
-}
-
-/* Given an unsigned 8-bit argument X, return the value corresponding
- to rotating the bits N steps to the left. N must be between 1 to 7
- inclusive, but on most relevant targets N can also be 0 and 8
- because 'int' is at least 32 bits and the arguments must widen
- before shifting. */
-BITROTATE_INLINE uint8_t
-rotl8 (uint8_t x, int n)
-{
- return ((x << n) | (x >> (8 - n))) & UINT8_MAX;
-}
-
-/* Given an unsigned 8-bit argument X, return the value corresponding
- to rotating the bits N steps to the right. N must be in 1 to 7
- inclusive, but on most relevant targets N can also be 0 and 8
- because 'int' is at least 32 bits and the arguments must widen
- before shifting. */
-BITROTATE_INLINE uint8_t
-rotr8 (uint8_t x, int n)
-{
- return ((x >> n) | (x << (8 - n))) & UINT8_MAX;
-}
-
-_GL_INLINE_HEADER_END
-
-#endif /* _GL_BITROTATE_H */
+/* bitrotate.h - Rotate bits in integers
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Simon Josefsson <simon@josefsson.org>, 2008. */
+
+#ifndef _GL_BITROTATE_H
+#define _GL_BITROTATE_H
+
+#include <limits.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+_GL_INLINE_HEADER_BEGIN
+#ifndef BITROTATE_INLINE
+# define BITROTATE_INLINE _GL_INLINE
+#endif
+
+#ifdef UINT64_MAX
+/* Given an unsigned 64-bit argument X, return the value corresponding
+ to rotating the bits N steps to the left. N must be between 1 and
+ 63 inclusive. */
+BITROTATE_INLINE uint64_t
+rotl64 (uint64_t x, int n)
+{
+ return ((x << n) | (x >> (64 - n))) & UINT64_MAX;
+}
+
+/* Given an unsigned 64-bit argument X, return the value corresponding
+ to rotating the bits N steps to the right. N must be between 1 to
+ 63 inclusive.*/
+BITROTATE_INLINE uint64_t
+rotr64 (uint64_t x, int n)
+{
+ return ((x >> n) | (x << (64 - n))) & UINT64_MAX;
+}
+#endif
+
+/* Given an unsigned 32-bit argument X, return the value corresponding
+ to rotating the bits N steps to the left. N must be between 1 and
+ 31 inclusive. */
+BITROTATE_INLINE uint32_t
+rotl32 (uint32_t x, int n)
+{
+ return ((x << n) | (x >> (32 - n))) & UINT32_MAX;
+}
+
+/* Given an unsigned 32-bit argument X, return the value corresponding
+ to rotating the bits N steps to the right. N must be between 1 to
+ 31 inclusive.*/
+BITROTATE_INLINE uint32_t
+rotr32 (uint32_t x, int n)
+{
+ return ((x >> n) | (x << (32 - n))) & UINT32_MAX;
+}
+
+/* Given a size_t argument X, return the value corresponding
+ to rotating the bits N steps to the left. N must be between 1 and
+ (CHAR_BIT * sizeof (size_t) - 1) inclusive. */
+BITROTATE_INLINE size_t
+rotl_sz (size_t x, int n)
+{
+ return ((x << n) | (x >> ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX;
+}
+
+/* Given a size_t argument X, return the value corresponding
+ to rotating the bits N steps to the right. N must be between 1 to
+ (CHAR_BIT * sizeof (size_t) - 1) inclusive. */
+BITROTATE_INLINE size_t
+rotr_sz (size_t x, int n)
+{
+ return ((x >> n) | (x << ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX;
+}
+
+/* Given an unsigned 16-bit argument X, return the value corresponding
+ to rotating the bits N steps to the left. N must be between 1 to
+ 15 inclusive, but on most relevant targets N can also be 0 and 16
+ because 'int' is at least 32 bits and the arguments must widen
+ before shifting. */
+BITROTATE_INLINE uint16_t
+rotl16 (uint16_t x, int n)
+{
+ return ((x << n) | (x >> (16 - n))) & UINT16_MAX;
+}
+
+/* Given an unsigned 16-bit argument X, return the value corresponding
+ to rotating the bits N steps to the right. N must be in 1 to 15
+ inclusive, but on most relevant targets N can also be 0 and 16
+ because 'int' is at least 32 bits and the arguments must widen
+ before shifting. */
+BITROTATE_INLINE uint16_t
+rotr16 (uint16_t x, int n)
+{
+ return ((x >> n) | (x << (16 - n))) & UINT16_MAX;
+}
+
+/* Given an unsigned 8-bit argument X, return the value corresponding
+ to rotating the bits N steps to the left. N must be between 1 to 7
+ inclusive, but on most relevant targets N can also be 0 and 8
+ because 'int' is at least 32 bits and the arguments must widen
+ before shifting. */
+BITROTATE_INLINE uint8_t
+rotl8 (uint8_t x, int n)
+{
+ return ((x << n) | (x >> (8 - n))) & UINT8_MAX;
+}
+
+/* Given an unsigned 8-bit argument X, return the value corresponding
+ to rotating the bits N steps to the right. N must be in 1 to 7
+ inclusive, but on most relevant targets N can also be 0 and 8
+ because 'int' is at least 32 bits and the arguments must widen
+ before shifting. */
+BITROTATE_INLINE uint8_t
+rotr8 (uint8_t x, int n)
+{
+ return ((x >> n) | (x << (8 - n))) & UINT8_MAX;
+}
+
+_GL_INLINE_HEADER_END
+
+#endif /* _GL_BITROTATE_H */
diff --git a/contrib/tools/bison/gnulib/src/bitset.c b/contrib/tools/bison/gnulib/src/bitset.c
index f7a9996afb..98972c80ce 100644
--- a/contrib/tools/bison/gnulib/src/bitset.c
+++ b/contrib/tools/bison/gnulib/src/bitset.c
@@ -1,505 +1,505 @@
-/* General bitsets.
-
- Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "bitset.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include "abitset.h"
-#include "lbitset.h"
-#include "ebitset.h"
-#include "vbitset.h"
-#include "bitset_stats.h"
-#include "obstack.h"
-
-const char * const bitset_type_names[] = BITSET_TYPE_NAMES;
-
-
-/* Return number of bytes required to create a N_BIT bitset
- of TYPE. The bitset may grow to require more bytes than this. */
-size_t
-bitset_bytes (enum bitset_type type, bitset_bindex n_bits)
-{
- size_t bytes;
-
- if (bitset_stats_enabled)
- return bitset_stats_bytes ();
-
- switch (type)
- {
- default:
- abort ();
-
- case BITSET_ARRAY:
- bytes = abitset_bytes (n_bits);
- break;
-
- case BITSET_LIST:
- bytes = lbitset_bytes (n_bits);
- break;
-
- case BITSET_TABLE:
- bytes = ebitset_bytes (n_bits);
- break;
-
- case BITSET_VARRAY:
- bytes = vbitset_bytes (n_bits);
- break;
- }
-
- return bytes;
-}
-
-
-/* Initialise bitset BSET of TYPE for N_BITS. */
-bitset
-bitset_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
-{
- if (bitset_stats_enabled)
- return bitset_stats_init (bset, n_bits, type);
-
- switch (type)
- {
- default:
- abort ();
-
- case BITSET_ARRAY:
- return abitset_init (bset, n_bits);
-
- case BITSET_LIST:
- return lbitset_init (bset, n_bits);
-
- case BITSET_TABLE:
- return ebitset_init (bset, n_bits);
-
- case BITSET_VARRAY:
- return vbitset_init (bset, n_bits);
- }
-}
-
-
-/* Select a bitset type for a set of N_BITS and with attribute hints
- specified by ATTR. For variable size bitsets, N_BITS is only a
- hint and may be zero. */
-enum bitset_type
-bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned int attr)
-{
- /* Check attributes. */
- if (attr & BITSET_FIXED && attr & BITSET_VARIABLE)
- abort ();
- if (attr & BITSET_SPARSE && attr & BITSET_DENSE)
- abort ();
-
- /* Choose the type of bitset. Note that sometimes we will be asked
- for a zero length fixed size bitset. */
-
-
- /* If no attributes selected, choose a good compromise. */
- if (!attr)
- return BITSET_VARRAY;
-
- if (attr & BITSET_SPARSE)
- return BITSET_LIST;
-
- if (attr & BITSET_FIXED)
- return BITSET_ARRAY;
-
- if (attr & BITSET_GREEDY)
- return BITSET_TABLE;
-
- return BITSET_VARRAY;
-}
-
-
-/* Create a bitset of N_BITS of type TYPE. */
-bitset
-bitset_alloc (bitset_bindex n_bits, enum bitset_type type)
-{
- size_t bytes;
- bitset bset;
-
- bytes = bitset_bytes (type, n_bits);
-
- bset = xcalloc (1, bytes);
-
- /* The cache is disabled until some elements are allocated. If we
- have variable length arrays, then we may need to allocate a dummy
- element. */
-
- return bitset_init (bset, n_bits, type);
-}
-
-
-/* Create a bitset of N_BITS of type TYPE. */
-bitset
-bitset_obstack_alloc (struct obstack *bobstack,
- bitset_bindex n_bits, enum bitset_type type)
-{
- size_t bytes;
- bitset bset;
-
- bytes = bitset_bytes (type, n_bits);
-
- bset = obstack_alloc (bobstack, bytes);
- memset (bset, 0, bytes);
-
- return bitset_init (bset, n_bits, type);
-}
-
-
-/* Create a bitset of N_BITS and with attribute hints specified by
- ATTR. */
-bitset
-bitset_create (bitset_bindex n_bits, unsigned int attr)
-{
- enum bitset_type type;
-
- type = bitset_type_choose (n_bits, attr);
-
- return bitset_alloc (n_bits, type);
-}
-
-
-/* Free bitset BSET. */
-void
-bitset_free (bitset bset)
-{
- BITSET_FREE_ (bset);
- free (bset);
-}
-
-
-/* Free bitset BSET allocated on obstack. */
-void
-bitset_obstack_free (bitset bset)
-{
- BITSET_FREE_ (bset);
-}
-
-
-/* Return bitset type. */
-enum bitset_type
-bitset_type_get (bitset bset)
-{
- enum bitset_type type;
-
- type = BITSET_TYPE_ (bset);
- if (type != BITSET_STATS)
- return type;
-
- return bitset_stats_type_get (bset);
-}
-
-
-/* Return name of bitset type. */
-const char *
-bitset_type_name_get (bitset bset)
-{
- enum bitset_type type;
-
- type = bitset_type_get (bset);
-
- return bitset_type_names[type];
-}
-
-
-/* Find next bit set in SRC starting from and including BITNO.
- Return BITSET_BINDEX_MAX if SRC empty. */
-bitset_bindex
-bitset_next (bitset src, bitset_bindex bitno)
-{
- bitset_bindex val;
- bitset_bindex next = bitno;
-
- if (!bitset_list (src, &val, 1, &next))
- return BITSET_BINDEX_MAX;
- return val;
-}
-
-
-/* Return true if both bitsets are of the same type and size. */
-extern bool
-bitset_compatible_p (bitset bset1, bitset bset2)
-{
- return BITSET_COMPATIBLE_ (bset1, bset2);
-}
-
-
-/* Find previous bit set in SRC starting from and including BITNO.
- Return BITSET_BINDEX_MAX if SRC empty. */
-bitset_bindex
-bitset_prev (bitset src, bitset_bindex bitno)
-{
- bitset_bindex val;
- bitset_bindex next = bitno;
-
- if (!bitset_list_reverse (src, &val, 1, &next))
- return BITSET_BINDEX_MAX;
- return val;
-}
-
-
-/* Find first set bit. */
-bitset_bindex
-bitset_first (bitset src)
-{
- return bitset_next (src, 0);
-}
-
-
-/* Find last set bit. */
-bitset_bindex
-bitset_last (bitset src)
-{
- return bitset_prev (src, 0);
-}
-
-
-/* Is BITNO in SRC the only set bit? */
-bool
-bitset_only_set_p (bitset src, bitset_bindex bitno)
-{
- bitset_bindex val[2];
- bitset_bindex next = 0;
-
- if (bitset_list (src, val, 2, &next) != 1)
- return false;
- return val[0] == bitno;
-}
-
-
-/* Print contents of bitset BSET to FILE. */
-static void
-bitset_print (FILE *file, bitset bset, bool verbose)
-{
- unsigned int pos;
- bitset_bindex i;
- bitset_iterator iter;
-
- if (verbose)
- fprintf (file, "n_bits = %lu, set = {",
- (unsigned long int) bitset_size (bset));
-
- pos = 30;
- BITSET_FOR_EACH (iter, bset, i, 0)
- {
- if (pos > 70)
- {
- fprintf (file, "\n");
- pos = 0;
- }
-
- fprintf (file, "%lu ", (unsigned long int) i);
- pos += 1 + (i >= 10) + (i >= 100);
- };
-
- if (verbose)
- fprintf (file, "}\n");
-}
-
-
-/* Dump bitset BSET to FILE. */
-void
-bitset_dump (FILE *file, bitset bset)
-{
- bitset_print (file, bset, false);
-}
-
-
-/* Release memory associated with bitsets. */
-void
-bitset_release_memory (void)
-{
- lbitset_release_memory ();
- ebitset_release_memory ();
-}
-
-
-/* Toggle bit BITNO in bitset BSET and the new value of the bit. */
-bool
-bitset_toggle_ (bitset bset, bitset_bindex bitno)
-{
- /* This routine is for completeness. It could be optimized if
- required. */
- if (bitset_test (bset, bitno))
- {
- bitset_reset (bset, bitno);
- return false;
- }
- else
- {
- bitset_set (bset, bitno);
- return true;
- }
-}
-
-
-/* Return number of bits in bitset SRC. */
-bitset_bindex
-bitset_size_ (bitset src)
-{
- return BITSET_NBITS_ (src);
-}
-
-
-/* Return number of bits set in bitset SRC. */
-bitset_bindex
-bitset_count_ (bitset src)
-{
- bitset_bindex list[BITSET_LIST_SIZE];
- bitset_bindex next;
- bitset_bindex num;
- bitset_bindex count;
-
- /* This could be greatly sped up by adding a count method for each
- bitset implementation that uses a direct technique (based on
- masks) for counting the number of bits set in a word. */
-
- next = 0;
- for (count = 0; (num = bitset_list (src, list, BITSET_LIST_SIZE, &next));
- count += num)
- continue;
-
- return count;
-}
-
-
-/* DST = SRC. Return true if DST != SRC.
- This is a fallback for the case where SRC and DST are different
- bitset types. */
-bool
-bitset_copy_ (bitset dst, bitset src)
-{
- bitset_bindex i;
- bitset_iterator iter;
-
- /* Convert bitset types. We assume that the DST bitset
- is large enough to hold the SRC bitset. */
- bitset_zero (dst);
- BITSET_FOR_EACH (iter, src, i, 0)
- {
- bitset_set (dst, i);
- };
-
- return true;
-}
-
-
-/* This is a fallback for implementations that do not support
- four operand operations. */
-static inline bool
-bitset_op4_cmp (bitset dst, bitset src1, bitset src2, bitset src3,
- enum bitset_ops op)
-{
- bool changed = false;
- bool stats_enabled_save;
- bitset tmp;
-
- /* Create temporary bitset. */
- stats_enabled_save = bitset_stats_enabled;
- bitset_stats_enabled = false;
- tmp = bitset_alloc (0, bitset_type_get (dst));
- bitset_stats_enabled = stats_enabled_save;
-
- switch (op)
- {
- default:
- abort ();
-
- case BITSET_OP_OR_AND:
- bitset_or (tmp, src1, src2);
- changed = bitset_and_cmp (dst, src3, tmp);
- break;
-
- case BITSET_OP_AND_OR:
- bitset_and (tmp, src1, src2);
- changed = bitset_or_cmp (dst, src3, tmp);
- break;
-
- case BITSET_OP_ANDN_OR:
- bitset_andn (tmp, src1, src2);
- changed = bitset_or_cmp (dst, src3, tmp);
- break;
- }
-
- bitset_free (tmp);
- return changed;
-}
-
-
-/* DST = (SRC1 & SRC2) | SRC3. */
-void
-bitset_and_or_ (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_and_or_cmp_ (dst, src1, src2, src3);
-}
-
-
-/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
- DST != (SRC1 & SRC2) | SRC3. */
-bool
-bitset_and_or_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_AND_OR);
-}
-
-
-/* DST = (SRC1 & ~SRC2) | SRC3. */
-void
-bitset_andn_or_ (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_andn_or_cmp_ (dst, src1, src2, src3);
-}
-
-
-/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
- DST != (SRC1 & ~SRC2) | SRC3. */
-bool
-bitset_andn_or_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_ANDN_OR);
-}
-
-
-/* DST = (SRC1 | SRC2) & SRC3. */
-void
-bitset_or_and_ (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- bitset_or_and_cmp_ (dst, src1, src2, src3);
-}
-
-
-/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
- DST != (SRC1 | SRC2) & SRC3. */
-bool
-bitset_or_and_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_OR_AND);
-}
-
-
-/* Function to be called from debugger to print bitset. */
-void
-debug_bitset (bitset bset)
-{
- if (bset)
- bitset_print (stderr, bset, true);
-}
+/* General bitsets.
+
+ Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "bitset.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include "abitset.h"
+#include "lbitset.h"
+#include "ebitset.h"
+#include "vbitset.h"
+#include "bitset_stats.h"
+#include "obstack.h"
+
+const char * const bitset_type_names[] = BITSET_TYPE_NAMES;
+
+
+/* Return number of bytes required to create a N_BIT bitset
+ of TYPE. The bitset may grow to require more bytes than this. */
+size_t
+bitset_bytes (enum bitset_type type, bitset_bindex n_bits)
+{
+ size_t bytes;
+
+ if (bitset_stats_enabled)
+ return bitset_stats_bytes ();
+
+ switch (type)
+ {
+ default:
+ abort ();
+
+ case BITSET_ARRAY:
+ bytes = abitset_bytes (n_bits);
+ break;
+
+ case BITSET_LIST:
+ bytes = lbitset_bytes (n_bits);
+ break;
+
+ case BITSET_TABLE:
+ bytes = ebitset_bytes (n_bits);
+ break;
+
+ case BITSET_VARRAY:
+ bytes = vbitset_bytes (n_bits);
+ break;
+ }
+
+ return bytes;
+}
+
+
+/* Initialise bitset BSET of TYPE for N_BITS. */
+bitset
+bitset_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
+{
+ if (bitset_stats_enabled)
+ return bitset_stats_init (bset, n_bits, type);
+
+ switch (type)
+ {
+ default:
+ abort ();
+
+ case BITSET_ARRAY:
+ return abitset_init (bset, n_bits);
+
+ case BITSET_LIST:
+ return lbitset_init (bset, n_bits);
+
+ case BITSET_TABLE:
+ return ebitset_init (bset, n_bits);
+
+ case BITSET_VARRAY:
+ return vbitset_init (bset, n_bits);
+ }
+}
+
+
+/* Select a bitset type for a set of N_BITS and with attribute hints
+ specified by ATTR. For variable size bitsets, N_BITS is only a
+ hint and may be zero. */
+enum bitset_type
+bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned int attr)
+{
+ /* Check attributes. */
+ if (attr & BITSET_FIXED && attr & BITSET_VARIABLE)
+ abort ();
+ if (attr & BITSET_SPARSE && attr & BITSET_DENSE)
+ abort ();
+
+ /* Choose the type of bitset. Note that sometimes we will be asked
+ for a zero length fixed size bitset. */
+
+
+ /* If no attributes selected, choose a good compromise. */
+ if (!attr)
+ return BITSET_VARRAY;
+
+ if (attr & BITSET_SPARSE)
+ return BITSET_LIST;
+
+ if (attr & BITSET_FIXED)
+ return BITSET_ARRAY;
+
+ if (attr & BITSET_GREEDY)
+ return BITSET_TABLE;
+
+ return BITSET_VARRAY;
+}
+
+
+/* Create a bitset of N_BITS of type TYPE. */
+bitset
+bitset_alloc (bitset_bindex n_bits, enum bitset_type type)
+{
+ size_t bytes;
+ bitset bset;
+
+ bytes = bitset_bytes (type, n_bits);
+
+ bset = xcalloc (1, bytes);
+
+ /* The cache is disabled until some elements are allocated. If we
+ have variable length arrays, then we may need to allocate a dummy
+ element. */
+
+ return bitset_init (bset, n_bits, type);
+}
+
+
+/* Create a bitset of N_BITS of type TYPE. */
+bitset
+bitset_obstack_alloc (struct obstack *bobstack,
+ bitset_bindex n_bits, enum bitset_type type)
+{
+ size_t bytes;
+ bitset bset;
+
+ bytes = bitset_bytes (type, n_bits);
+
+ bset = obstack_alloc (bobstack, bytes);
+ memset (bset, 0, bytes);
+
+ return bitset_init (bset, n_bits, type);
+}
+
+
+/* Create a bitset of N_BITS and with attribute hints specified by
+ ATTR. */
+bitset
+bitset_create (bitset_bindex n_bits, unsigned int attr)
+{
+ enum bitset_type type;
+
+ type = bitset_type_choose (n_bits, attr);
+
+ return bitset_alloc (n_bits, type);
+}
+
+
+/* Free bitset BSET. */
+void
+bitset_free (bitset bset)
+{
+ BITSET_FREE_ (bset);
+ free (bset);
+}
+
+
+/* Free bitset BSET allocated on obstack. */
+void
+bitset_obstack_free (bitset bset)
+{
+ BITSET_FREE_ (bset);
+}
+
+
+/* Return bitset type. */
+enum bitset_type
+bitset_type_get (bitset bset)
+{
+ enum bitset_type type;
+
+ type = BITSET_TYPE_ (bset);
+ if (type != BITSET_STATS)
+ return type;
+
+ return bitset_stats_type_get (bset);
+}
+
+
+/* Return name of bitset type. */
+const char *
+bitset_type_name_get (bitset bset)
+{
+ enum bitset_type type;
+
+ type = bitset_type_get (bset);
+
+ return bitset_type_names[type];
+}
+
+
+/* Find next bit set in SRC starting from and including BITNO.
+ Return BITSET_BINDEX_MAX if SRC empty. */
+bitset_bindex
+bitset_next (bitset src, bitset_bindex bitno)
+{
+ bitset_bindex val;
+ bitset_bindex next = bitno;
+
+ if (!bitset_list (src, &val, 1, &next))
+ return BITSET_BINDEX_MAX;
+ return val;
+}
+
+
+/* Return true if both bitsets are of the same type and size. */
+extern bool
+bitset_compatible_p (bitset bset1, bitset bset2)
+{
+ return BITSET_COMPATIBLE_ (bset1, bset2);
+}
+
+
+/* Find previous bit set in SRC starting from and including BITNO.
+ Return BITSET_BINDEX_MAX if SRC empty. */
+bitset_bindex
+bitset_prev (bitset src, bitset_bindex bitno)
+{
+ bitset_bindex val;
+ bitset_bindex next = bitno;
+
+ if (!bitset_list_reverse (src, &val, 1, &next))
+ return BITSET_BINDEX_MAX;
+ return val;
+}
+
+
+/* Find first set bit. */
+bitset_bindex
+bitset_first (bitset src)
+{
+ return bitset_next (src, 0);
+}
+
+
+/* Find last set bit. */
+bitset_bindex
+bitset_last (bitset src)
+{
+ return bitset_prev (src, 0);
+}
+
+
+/* Is BITNO in SRC the only set bit? */
+bool
+bitset_only_set_p (bitset src, bitset_bindex bitno)
+{
+ bitset_bindex val[2];
+ bitset_bindex next = 0;
+
+ if (bitset_list (src, val, 2, &next) != 1)
+ return false;
+ return val[0] == bitno;
+}
+
+
+/* Print contents of bitset BSET to FILE. */
+static void
+bitset_print (FILE *file, bitset bset, bool verbose)
+{
+ unsigned int pos;
+ bitset_bindex i;
+ bitset_iterator iter;
+
+ if (verbose)
+ fprintf (file, "n_bits = %lu, set = {",
+ (unsigned long int) bitset_size (bset));
+
+ pos = 30;
+ BITSET_FOR_EACH (iter, bset, i, 0)
+ {
+ if (pos > 70)
+ {
+ fprintf (file, "\n");
+ pos = 0;
+ }
+
+ fprintf (file, "%lu ", (unsigned long int) i);
+ pos += 1 + (i >= 10) + (i >= 100);
+ };
+
+ if (verbose)
+ fprintf (file, "}\n");
+}
+
+
+/* Dump bitset BSET to FILE. */
+void
+bitset_dump (FILE *file, bitset bset)
+{
+ bitset_print (file, bset, false);
+}
+
+
+/* Release memory associated with bitsets. */
+void
+bitset_release_memory (void)
+{
+ lbitset_release_memory ();
+ ebitset_release_memory ();
+}
+
+
+/* Toggle bit BITNO in bitset BSET and the new value of the bit. */
+bool
+bitset_toggle_ (bitset bset, bitset_bindex bitno)
+{
+ /* This routine is for completeness. It could be optimized if
+ required. */
+ if (bitset_test (bset, bitno))
+ {
+ bitset_reset (bset, bitno);
+ return false;
+ }
+ else
+ {
+ bitset_set (bset, bitno);
+ return true;
+ }
+}
+
+
+/* Return number of bits in bitset SRC. */
+bitset_bindex
+bitset_size_ (bitset src)
+{
+ return BITSET_NBITS_ (src);
+}
+
+
+/* Return number of bits set in bitset SRC. */
+bitset_bindex
+bitset_count_ (bitset src)
+{
+ bitset_bindex list[BITSET_LIST_SIZE];
+ bitset_bindex next;
+ bitset_bindex num;
+ bitset_bindex count;
+
+ /* This could be greatly sped up by adding a count method for each
+ bitset implementation that uses a direct technique (based on
+ masks) for counting the number of bits set in a word. */
+
+ next = 0;
+ for (count = 0; (num = bitset_list (src, list, BITSET_LIST_SIZE, &next));
+ count += num)
+ continue;
+
+ return count;
+}
+
+
+/* DST = SRC. Return true if DST != SRC.
+ This is a fallback for the case where SRC and DST are different
+ bitset types. */
+bool
+bitset_copy_ (bitset dst, bitset src)
+{
+ bitset_bindex i;
+ bitset_iterator iter;
+
+ /* Convert bitset types. We assume that the DST bitset
+ is large enough to hold the SRC bitset. */
+ bitset_zero (dst);
+ BITSET_FOR_EACH (iter, src, i, 0)
+ {
+ bitset_set (dst, i);
+ };
+
+ return true;
+}
+
+
+/* This is a fallback for implementations that do not support
+ four operand operations. */
+static inline bool
+bitset_op4_cmp (bitset dst, bitset src1, bitset src2, bitset src3,
+ enum bitset_ops op)
+{
+ bool changed = false;
+ bool stats_enabled_save;
+ bitset tmp;
+
+ /* Create temporary bitset. */
+ stats_enabled_save = bitset_stats_enabled;
+ bitset_stats_enabled = false;
+ tmp = bitset_alloc (0, bitset_type_get (dst));
+ bitset_stats_enabled = stats_enabled_save;
+
+ switch (op)
+ {
+ default:
+ abort ();
+
+ case BITSET_OP_OR_AND:
+ bitset_or (tmp, src1, src2);
+ changed = bitset_and_cmp (dst, src3, tmp);
+ break;
+
+ case BITSET_OP_AND_OR:
+ bitset_and (tmp, src1, src2);
+ changed = bitset_or_cmp (dst, src3, tmp);
+ break;
+
+ case BITSET_OP_ANDN_OR:
+ bitset_andn (tmp, src1, src2);
+ changed = bitset_or_cmp (dst, src3, tmp);
+ break;
+ }
+
+ bitset_free (tmp);
+ return changed;
+}
+
+
+/* DST = (SRC1 & SRC2) | SRC3. */
+void
+bitset_and_or_ (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_and_or_cmp_ (dst, src1, src2, src3);
+}
+
+
+/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
+ DST != (SRC1 & SRC2) | SRC3. */
+bool
+bitset_and_or_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_AND_OR);
+}
+
+
+/* DST = (SRC1 & ~SRC2) | SRC3. */
+void
+bitset_andn_or_ (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_andn_or_cmp_ (dst, src1, src2, src3);
+}
+
+
+/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
+ DST != (SRC1 & ~SRC2) | SRC3. */
+bool
+bitset_andn_or_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_ANDN_OR);
+}
+
+
+/* DST = (SRC1 | SRC2) & SRC3. */
+void
+bitset_or_and_ (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ bitset_or_and_cmp_ (dst, src1, src2, src3);
+}
+
+
+/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
+ DST != (SRC1 | SRC2) & SRC3. */
+bool
+bitset_or_and_cmp_ (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ return bitset_op4_cmp (dst, src1, src2, src3, BITSET_OP_OR_AND);
+}
+
+
+/* Function to be called from debugger to print bitset. */
+void
+debug_bitset (bitset bset)
+{
+ if (bset)
+ bitset_print (stderr, bset, true);
+}
diff --git a/contrib/tools/bison/gnulib/src/bitset.h b/contrib/tools/bison/gnulib/src/bitset.h
index ef44ea4cf8..aaec7864a9 100644
--- a/contrib/tools/bison/gnulib/src/bitset.h
+++ b/contrib/tools/bison/gnulib/src/bitset.h
@@ -1,393 +1,393 @@
-/* Generic bitsets.
-
- Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _BITSET_H
-#define _BITSET_H
-
-/* This file is the public interface to the bitset abstract data type.
- Only use the functions and macros defined in this file. */
-
-#include "bbitset.h"
-#include "obstack.h"
-#include <stdio.h>
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-/* Attributes used to select a bitset implementation. */
-enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
- BITSET_VARIABLE = 2, /* Bitset size variable. */
- BITSET_DENSE = 4, /* Bitset dense. */
- BITSET_SPARSE = 8, /* Bitset sparse. */
- BITSET_FRUGAL = 16, /* Prefer most compact. */
- BITSET_GREEDY = 32}; /* Prefer fastest at memory expense. */
-
-typedef unsigned int bitset_attrs;
-
-/* The contents of the union should be considered to be private.
- While I would like to make this union opaque, it needs to be
- visible for the inline bit set/test functions, and for delegation
- to the proper implementation. */
-union bitset_union
-{
- /* This must be the first member of every other structure that is a
- member of this union. */
- struct bbitset_struct b; /* Base bitset data. */
-
- struct abitset_struct
- {
- struct bbitset_struct b;
- bitset_word words[1]; /* The array of bits. */
- } a;
-
- struct ebitset_struct
- {
- struct bbitset_struct b;
- bitset_windex size; /* Number of elements. */
- struct ebitset_elt_struct **elts; /* Expanding array of ptrs to elts. */
- } e;
-
- struct lbitset_struct
- {
- struct bbitset_struct b;
- struct lbitset_elt_struct *head; /* First element in linked list. */
- struct lbitset_elt_struct *tail; /* Last element in linked list. */
- } l;
-
- struct bitset_stats_struct
- {
- struct bbitset_struct b;
- bitset bset;
- } s;
-
- struct vbitset_struct
- {
- struct bbitset_struct b;
- bitset_windex size; /* Allocated size of array. */
- } v;
-
-};
-
-
-/* The contents of this structure should be considered private.
- It is used for iterating over set bits. */
-typedef struct
-{
- bitset_bindex list[BITSET_LIST_SIZE];
- bitset_bindex next;
- bitset_bindex num;
- bitset_bindex i;
-} bitset_iterator;
-
-
-/* Return bytes required for bitset of desired type and size. */
-extern size_t bitset_bytes (enum bitset_type, bitset_bindex);
-
-/* Initialise a bitset with desired type and size. */
-extern bitset bitset_init (bitset, bitset_bindex, enum bitset_type);
-
-/* Select an implementation type based on the desired bitset size
- and attributes. */
-extern enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs);
-
-/* Create a bitset of desired type and size. The bitset is zeroed. */
-extern bitset bitset_alloc (bitset_bindex, enum bitset_type);
-
-/* Free bitset. */
-extern void bitset_free (bitset);
-
-/* Create a bitset of desired type and size using an obstack. The
- bitset is zeroed. */
-extern bitset bitset_obstack_alloc (struct obstack *bobstack,
- bitset_bindex, enum bitset_type);
-
-/* Free bitset allocated on obstack. */
-extern void bitset_obstack_free (bitset);
-
-/* Create a bitset of desired size and attributes. The bitset is zeroed. */
-extern bitset bitset_create (bitset_bindex, bitset_attrs);
-
-/* Return bitset type. */
-extern enum bitset_type bitset_type_get (bitset);
-
-/* Return bitset type name. */
-extern const char *bitset_type_name_get (bitset);
-
-
-/* Set bit BITNO in bitset BSET. */
-static inline void
-bitset_set (bitset bset, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
- bitset_windex offset = windex - bset->b.cindex;
-
- if (offset < bset->b.csize)
- bset->b.cdata[offset] |= ((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
- else
- BITSET_SET_ (bset, bitno);
-}
-
-
-/* Reset bit BITNO in bitset BSET. */
-static inline void
-bitset_reset (bitset bset, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
- bitset_windex offset = windex - bset->b.cindex;
-
- if (offset < bset->b.csize)
- bset->b.cdata[offset] &= ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
- else
- BITSET_RESET_ (bset, bitno);
-}
-
-
-/* Test bit BITNO in bitset BSET. */
-static inline bool
-bitset_test (bitset bset, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
- bitset_windex offset = windex - bset->b.cindex;
-
- if (offset < bset->b.csize)
- return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
- else
- return BITSET_TEST_ (bset, bitno);
-}
-
-
-/* Toggle bit BITNO in bitset BSET and return non-zero if now set. */
-#define bitset_toggle(bset, bitno) BITSET_TOGGLE_ (bset, bitno)
-
-/* Return size in bits of bitset SRC. */
-#define bitset_size(SRC) BITSET_SIZE_ (SRC)
-
-/* Change size of bitset. */
-extern void bitset_resize (bitset, bitset_bindex);
-
-/* Return number of bits set in bitset SRC. */
-#define bitset_count(SRC) BITSET_COUNT_ (SRC)
-
-
-/* Return SRC == 0. */
-#define bitset_empty_p(SRC) BITSET_EMPTY_P_ (SRC)
-
-/* DST = ~0. */
-#define bitset_ones(DST) BITSET_ONES_ (DST)
-
-/* DST = 0. */
-#define bitset_zero(DST) BITSET_ZERO_ (DST)
-
-
-
-/* DST = SRC. */
-#define bitset_copy(DST, SRC) BITSET_COPY_ (DST, SRC)
-
-/* Return DST & SRC == 0. */
-#define bitset_disjoint_p(DST, SRC) BITSET_DISJOINT_P_ (DST, SRC)
-
-/* Return DST == SRC. */
-#define bitset_equal_p(DST, SRC) BITSET_EQUAL_P_ (DST, SRC)
-
-/* DST = ~SRC. */
-#define bitset_not(DST, SRC) BITSET_NOT_ (DST, SRC)
-
-/* Return DST == DST | SRC. */
-#define bitset_subset_p(DST, SRC) BITSET_SUBSET_P_ (DST, SRC)
-
-
-
-/* DST = SRC1 & SRC2. */
-#define bitset_and(DST, SRC1, SRC2) BITSET_AND_ (DST, SRC1, SRC2)
-
-/* DST = SRC1 & SRC2. Return non-zero if DST != SRC1 & SRC2. */
-#define bitset_and_cmp(DST, SRC1, SRC2) BITSET_AND_CMP_ (DST, SRC1, SRC2)
-
-/* DST = SRC1 & ~SRC2. */
-#define bitset_andn(DST, SRC1, SRC2) BITSET_ANDN_ (DST, SRC1, SRC2)
-
-/* DST = SRC1 & ~SRC2. Return non-zero if DST != SRC1 & ~SRC2. */
-#define bitset_andn_cmp(DST, SRC1, SRC2) BITSET_ANDN_CMP_ (DST, SRC1, SRC2)
-
-/* DST = SRC1 | SRC2. */
-#define bitset_or(DST, SRC1, SRC2) BITSET_OR_ (DST, SRC1, SRC2)
-
-/* DST = SRC1 | SRC2. Return non-zero if DST != SRC1 | SRC2. */
-#define bitset_or_cmp(DST, SRC1, SRC2) BITSET_OR_CMP_ (DST, SRC1, SRC2)
-
-/* DST = SRC1 ^ SRC2. */
-#define bitset_xor(DST, SRC1, SRC2) BITSET_XOR_ (DST, SRC1, SRC2)
-
-/* DST = SRC1 ^ SRC2. Return non-zero if DST != SRC1 ^ SRC2. */
-#define bitset_xor_cmp(DST, SRC1, SRC2) BITSET_XOR_CMP_ (DST, SRC1, SRC2)
-
-
-
-/* DST = (SRC1 & SRC2) | SRC3. */
-#define bitset_and_or(DST, SRC1, SRC2, SRC3) \
- BITSET_AND_OR_ (DST, SRC1, SRC2, SRC3)
-
-/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
- DST != (SRC1 & SRC2) | SRC3. */
-#define bitset_and_or_cmp(DST, SRC1, SRC2, SRC3) \
- BITSET_AND_OR_CMP_ (DST, SRC1, SRC2, SRC3)
-
-/* DST = (SRC1 & ~SRC2) | SRC3. */
-#define bitset_andn_or(DST, SRC1, SRC2, SRC3) \
- BITSET_ANDN_OR_ (DST, SRC1, SRC2, SRC3)
-
-/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
- DST != (SRC1 & ~SRC2) | SRC3. */
-#define bitset_andn_or_cmp(DST, SRC1, SRC2, SRC3) \
- BITSET_ANDN_OR_CMP_ (DST, SRC1, SRC2, SRC3)
-
-/* DST = (SRC1 | SRC2) & SRC3. */
-#define bitset_or_and(DST, SRC1, SRC2, SRC3)\
- BITSET_OR_AND_ (DST, SRC1, SRC2, SRC3)
-
-/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
- DST != (SRC1 | SRC2) & SRC3. */
-#define bitset_or_and_cmp(DST, SRC1, SRC2, SRC3)\
- BITSET_OR_AND_CMP_ (DST, SRC1, SRC2, SRC3)
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT. Return with actual number of bits found and with *NEXT
- indicating where search stopped. */
-#define bitset_list(BSET, LIST, NUM, NEXT) \
- BITSET_LIST_ (BSET, LIST, NUM, NEXT)
-
-/* Find reverse list of up to NUM bits set in BSET starting from and
- including NEXT. Return with actual number of bits found and with
- *NEXT indicating where search stopped. */
-#define bitset_list_reverse(BSET, LIST, NUM, NEXT) \
- BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
-
-/* Return true if both bitsets are of the same type and size. */
-extern bool bitset_compatible_p (bitset bset1, bitset bset2);
-
-/* Find next set bit from the given bit index. */
-extern bitset_bindex bitset_next (bitset, bitset_bindex);
-
-/* Find previous set bit from the given bit index. */
-extern bitset_bindex bitset_prev (bitset, bitset_bindex);
-
-/* Find first set bit. */
-extern bitset_bindex bitset_first (bitset);
-
-/* Find last set bit. */
-extern bitset_bindex bitset_last (bitset);
-
-/* Return nonzero if this is the only set bit. */
-extern bool bitset_only_set_p (bitset, bitset_bindex);
-
-/* Dump bitset. */
-extern void bitset_dump (FILE *, bitset);
-
-/* Loop over all elements of BSET, starting with MIN, setting INDEX
- to the index of each set bit. For example, the following will print
- the bits set in a bitset:
-
- bitset_bindex i;
- bitset_iterator iter;
-
- BITSET_FOR_EACH (iter, src, i, 0)
- {
- printf ("%lu ", (unsigned long int) i);
- };
-*/
-#define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \
- for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
- (ITER.num == BITSET_LIST_SIZE) \
- && (ITER.num = bitset_list (BSET, ITER.list, \
- BITSET_LIST_SIZE, &ITER.next));) \
- for (ITER.i = 0; \
- ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
- ITER.i++)
-
-
-/* Loop over all elements of BSET, in reverse order starting with
- MIN, setting INDEX to the index of each set bit. For example, the
- following will print the bits set in a bitset in reverse order:
-
- bitset_bindex i;
- bitset_iterator iter;
-
- BITSET_FOR_EACH_REVERSE (iter, src, i, 0)
- {
- printf ("%lu ", (unsigned long int) i);
- };
-*/
-#define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \
- for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
- (ITER.num == BITSET_LIST_SIZE) \
- && (ITER.num = bitset_list_reverse (BSET, ITER.list, \
- BITSET_LIST_SIZE, &ITER.next));) \
- for (ITER.i = 0; \
- ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
- ITER.i++)
-
-
-/* Define set operations in terms of logical operations. */
-
-#define bitset_diff(DST, SRC1, SRC2) bitset_andn (DST, SRC1, SRC2)
-#define bitset_diff_cmp(DST, SRC1, SRC2) bitset_andn_cmp (DST, SRC1, SRC2)
-
-#define bitset_intersection(DST, SRC1, SRC2) bitset_and (DST, SRC1, SRC2)
-#define bitset_intersection_cmp(DST, SRC1, SRC2) bitset_and_cmp (DST, SRC1, SRC2)
-
-#define bitset_union(DST, SRC1, SRC2) bitset_or (DST, SRC1, SRC2)
-#define bitset_union_cmp(DST, SRC1, SRC2) bitset_or_cmp (DST, SRC1, SRC2)
-
-/* Symmetrical difference. */
-#define bitset_symdiff(DST, SRC1, SRC2) bitset_xor (DST, SRC1, SRC2)
-#define bitset_symdiff_cmp(DST, SRC1, SRC2) bitset_xor_cmp (DST, SRC1, SRC2)
-
-/* Union of difference. */
-#define bitset_diff_union(DST, SRC1, SRC2, SRC3) \
- bitset_andn_or (DST, SRC1, SRC2, SRC3)
-#define bitset_diff_union_cmp(DST, SRC1, SRC2, SRC3) \
- bitset_andn_or_cmp (DST, SRC1, SRC2, SRC3)
-
-
-/* Release any memory tied up with bitsets. */
-extern void bitset_release_memory (void);
-
-/* Enable bitset stats gathering. */
-extern void bitset_stats_enable (void);
-
-/* Disable bitset stats gathering. */
-extern void bitset_stats_disable (void);
-
-/* Read bitset stats file of accummulated stats. */
-void bitset_stats_read (const char *file_name);
-
-/* Write bitset stats file of accummulated stats. */
-void bitset_stats_write (const char *file_name);
-
-/* Dump bitset stats. */
-extern void bitset_stats_dump (FILE *);
-
-/* Function to debug bitset from debugger. */
-extern void debug_bitset (bitset);
-
-/* Function to debug bitset stats from debugger. */
-extern void debug_bitset_stats (void);
-
-#endif /* _BITSET_H */
+/* Generic bitsets.
+
+ Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _BITSET_H
+#define _BITSET_H
+
+/* This file is the public interface to the bitset abstract data type.
+ Only use the functions and macros defined in this file. */
+
+#include "bbitset.h"
+#include "obstack.h"
+#include <stdio.h>
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+/* Attributes used to select a bitset implementation. */
+enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
+ BITSET_VARIABLE = 2, /* Bitset size variable. */
+ BITSET_DENSE = 4, /* Bitset dense. */
+ BITSET_SPARSE = 8, /* Bitset sparse. */
+ BITSET_FRUGAL = 16, /* Prefer most compact. */
+ BITSET_GREEDY = 32}; /* Prefer fastest at memory expense. */
+
+typedef unsigned int bitset_attrs;
+
+/* The contents of the union should be considered to be private.
+ While I would like to make this union opaque, it needs to be
+ visible for the inline bit set/test functions, and for delegation
+ to the proper implementation. */
+union bitset_union
+{
+ /* This must be the first member of every other structure that is a
+ member of this union. */
+ struct bbitset_struct b; /* Base bitset data. */
+
+ struct abitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_word words[1]; /* The array of bits. */
+ } a;
+
+ struct ebitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_windex size; /* Number of elements. */
+ struct ebitset_elt_struct **elts; /* Expanding array of ptrs to elts. */
+ } e;
+
+ struct lbitset_struct
+ {
+ struct bbitset_struct b;
+ struct lbitset_elt_struct *head; /* First element in linked list. */
+ struct lbitset_elt_struct *tail; /* Last element in linked list. */
+ } l;
+
+ struct bitset_stats_struct
+ {
+ struct bbitset_struct b;
+ bitset bset;
+ } s;
+
+ struct vbitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_windex size; /* Allocated size of array. */
+ } v;
+
+};
+
+
+/* The contents of this structure should be considered private.
+ It is used for iterating over set bits. */
+typedef struct
+{
+ bitset_bindex list[BITSET_LIST_SIZE];
+ bitset_bindex next;
+ bitset_bindex num;
+ bitset_bindex i;
+} bitset_iterator;
+
+
+/* Return bytes required for bitset of desired type and size. */
+extern size_t bitset_bytes (enum bitset_type, bitset_bindex);
+
+/* Initialise a bitset with desired type and size. */
+extern bitset bitset_init (bitset, bitset_bindex, enum bitset_type);
+
+/* Select an implementation type based on the desired bitset size
+ and attributes. */
+extern enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs);
+
+/* Create a bitset of desired type and size. The bitset is zeroed. */
+extern bitset bitset_alloc (bitset_bindex, enum bitset_type);
+
+/* Free bitset. */
+extern void bitset_free (bitset);
+
+/* Create a bitset of desired type and size using an obstack. The
+ bitset is zeroed. */
+extern bitset bitset_obstack_alloc (struct obstack *bobstack,
+ bitset_bindex, enum bitset_type);
+
+/* Free bitset allocated on obstack. */
+extern void bitset_obstack_free (bitset);
+
+/* Create a bitset of desired size and attributes. The bitset is zeroed. */
+extern bitset bitset_create (bitset_bindex, bitset_attrs);
+
+/* Return bitset type. */
+extern enum bitset_type bitset_type_get (bitset);
+
+/* Return bitset type name. */
+extern const char *bitset_type_name_get (bitset);
+
+
+/* Set bit BITNO in bitset BSET. */
+static inline void
+bitset_set (bitset bset, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+ bitset_windex offset = windex - bset->b.cindex;
+
+ if (offset < bset->b.csize)
+ bset->b.cdata[offset] |= ((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
+ else
+ BITSET_SET_ (bset, bitno);
+}
+
+
+/* Reset bit BITNO in bitset BSET. */
+static inline void
+bitset_reset (bitset bset, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+ bitset_windex offset = windex - bset->b.cindex;
+
+ if (offset < bset->b.csize)
+ bset->b.cdata[offset] &= ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
+ else
+ BITSET_RESET_ (bset, bitno);
+}
+
+
+/* Test bit BITNO in bitset BSET. */
+static inline bool
+bitset_test (bitset bset, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+ bitset_windex offset = windex - bset->b.cindex;
+
+ if (offset < bset->b.csize)
+ return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
+ else
+ return BITSET_TEST_ (bset, bitno);
+}
+
+
+/* Toggle bit BITNO in bitset BSET and return non-zero if now set. */
+#define bitset_toggle(bset, bitno) BITSET_TOGGLE_ (bset, bitno)
+
+/* Return size in bits of bitset SRC. */
+#define bitset_size(SRC) BITSET_SIZE_ (SRC)
+
+/* Change size of bitset. */
+extern void bitset_resize (bitset, bitset_bindex);
+
+/* Return number of bits set in bitset SRC. */
+#define bitset_count(SRC) BITSET_COUNT_ (SRC)
+
+
+/* Return SRC == 0. */
+#define bitset_empty_p(SRC) BITSET_EMPTY_P_ (SRC)
+
+/* DST = ~0. */
+#define bitset_ones(DST) BITSET_ONES_ (DST)
+
+/* DST = 0. */
+#define bitset_zero(DST) BITSET_ZERO_ (DST)
+
+
+
+/* DST = SRC. */
+#define bitset_copy(DST, SRC) BITSET_COPY_ (DST, SRC)
+
+/* Return DST & SRC == 0. */
+#define bitset_disjoint_p(DST, SRC) BITSET_DISJOINT_P_ (DST, SRC)
+
+/* Return DST == SRC. */
+#define bitset_equal_p(DST, SRC) BITSET_EQUAL_P_ (DST, SRC)
+
+/* DST = ~SRC. */
+#define bitset_not(DST, SRC) BITSET_NOT_ (DST, SRC)
+
+/* Return DST == DST | SRC. */
+#define bitset_subset_p(DST, SRC) BITSET_SUBSET_P_ (DST, SRC)
+
+
+
+/* DST = SRC1 & SRC2. */
+#define bitset_and(DST, SRC1, SRC2) BITSET_AND_ (DST, SRC1, SRC2)
+
+/* DST = SRC1 & SRC2. Return non-zero if DST != SRC1 & SRC2. */
+#define bitset_and_cmp(DST, SRC1, SRC2) BITSET_AND_CMP_ (DST, SRC1, SRC2)
+
+/* DST = SRC1 & ~SRC2. */
+#define bitset_andn(DST, SRC1, SRC2) BITSET_ANDN_ (DST, SRC1, SRC2)
+
+/* DST = SRC1 & ~SRC2. Return non-zero if DST != SRC1 & ~SRC2. */
+#define bitset_andn_cmp(DST, SRC1, SRC2) BITSET_ANDN_CMP_ (DST, SRC1, SRC2)
+
+/* DST = SRC1 | SRC2. */
+#define bitset_or(DST, SRC1, SRC2) BITSET_OR_ (DST, SRC1, SRC2)
+
+/* DST = SRC1 | SRC2. Return non-zero if DST != SRC1 | SRC2. */
+#define bitset_or_cmp(DST, SRC1, SRC2) BITSET_OR_CMP_ (DST, SRC1, SRC2)
+
+/* DST = SRC1 ^ SRC2. */
+#define bitset_xor(DST, SRC1, SRC2) BITSET_XOR_ (DST, SRC1, SRC2)
+
+/* DST = SRC1 ^ SRC2. Return non-zero if DST != SRC1 ^ SRC2. */
+#define bitset_xor_cmp(DST, SRC1, SRC2) BITSET_XOR_CMP_ (DST, SRC1, SRC2)
+
+
+
+/* DST = (SRC1 & SRC2) | SRC3. */
+#define bitset_and_or(DST, SRC1, SRC2, SRC3) \
+ BITSET_AND_OR_ (DST, SRC1, SRC2, SRC3)
+
+/* DST = (SRC1 & SRC2) | SRC3. Return non-zero if
+ DST != (SRC1 & SRC2) | SRC3. */
+#define bitset_and_or_cmp(DST, SRC1, SRC2, SRC3) \
+ BITSET_AND_OR_CMP_ (DST, SRC1, SRC2, SRC3)
+
+/* DST = (SRC1 & ~SRC2) | SRC3. */
+#define bitset_andn_or(DST, SRC1, SRC2, SRC3) \
+ BITSET_ANDN_OR_ (DST, SRC1, SRC2, SRC3)
+
+/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
+ DST != (SRC1 & ~SRC2) | SRC3. */
+#define bitset_andn_or_cmp(DST, SRC1, SRC2, SRC3) \
+ BITSET_ANDN_OR_CMP_ (DST, SRC1, SRC2, SRC3)
+
+/* DST = (SRC1 | SRC2) & SRC3. */
+#define bitset_or_and(DST, SRC1, SRC2, SRC3)\
+ BITSET_OR_AND_ (DST, SRC1, SRC2, SRC3)
+
+/* DST = (SRC1 | SRC2) & SRC3. Return non-zero if
+ DST != (SRC1 | SRC2) & SRC3. */
+#define bitset_or_and_cmp(DST, SRC1, SRC2, SRC3)\
+ BITSET_OR_AND_CMP_ (DST, SRC1, SRC2, SRC3)
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT. Return with actual number of bits found and with *NEXT
+ indicating where search stopped. */
+#define bitset_list(BSET, LIST, NUM, NEXT) \
+ BITSET_LIST_ (BSET, LIST, NUM, NEXT)
+
+/* Find reverse list of up to NUM bits set in BSET starting from and
+ including NEXT. Return with actual number of bits found and with
+ *NEXT indicating where search stopped. */
+#define bitset_list_reverse(BSET, LIST, NUM, NEXT) \
+ BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
+
+/* Return true if both bitsets are of the same type and size. */
+extern bool bitset_compatible_p (bitset bset1, bitset bset2);
+
+/* Find next set bit from the given bit index. */
+extern bitset_bindex bitset_next (bitset, bitset_bindex);
+
+/* Find previous set bit from the given bit index. */
+extern bitset_bindex bitset_prev (bitset, bitset_bindex);
+
+/* Find first set bit. */
+extern bitset_bindex bitset_first (bitset);
+
+/* Find last set bit. */
+extern bitset_bindex bitset_last (bitset);
+
+/* Return nonzero if this is the only set bit. */
+extern bool bitset_only_set_p (bitset, bitset_bindex);
+
+/* Dump bitset. */
+extern void bitset_dump (FILE *, bitset);
+
+/* Loop over all elements of BSET, starting with MIN, setting INDEX
+ to the index of each set bit. For example, the following will print
+ the bits set in a bitset:
+
+ bitset_bindex i;
+ bitset_iterator iter;
+
+ BITSET_FOR_EACH (iter, src, i, 0)
+ {
+ printf ("%lu ", (unsigned long int) i);
+ };
+*/
+#define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \
+ for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
+ (ITER.num == BITSET_LIST_SIZE) \
+ && (ITER.num = bitset_list (BSET, ITER.list, \
+ BITSET_LIST_SIZE, &ITER.next));) \
+ for (ITER.i = 0; \
+ ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
+ ITER.i++)
+
+
+/* Loop over all elements of BSET, in reverse order starting with
+ MIN, setting INDEX to the index of each set bit. For example, the
+ following will print the bits set in a bitset in reverse order:
+
+ bitset_bindex i;
+ bitset_iterator iter;
+
+ BITSET_FOR_EACH_REVERSE (iter, src, i, 0)
+ {
+ printf ("%lu ", (unsigned long int) i);
+ };
+*/
+#define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \
+ for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
+ (ITER.num == BITSET_LIST_SIZE) \
+ && (ITER.num = bitset_list_reverse (BSET, ITER.list, \
+ BITSET_LIST_SIZE, &ITER.next));) \
+ for (ITER.i = 0; \
+ ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
+ ITER.i++)
+
+
+/* Define set operations in terms of logical operations. */
+
+#define bitset_diff(DST, SRC1, SRC2) bitset_andn (DST, SRC1, SRC2)
+#define bitset_diff_cmp(DST, SRC1, SRC2) bitset_andn_cmp (DST, SRC1, SRC2)
+
+#define bitset_intersection(DST, SRC1, SRC2) bitset_and (DST, SRC1, SRC2)
+#define bitset_intersection_cmp(DST, SRC1, SRC2) bitset_and_cmp (DST, SRC1, SRC2)
+
+#define bitset_union(DST, SRC1, SRC2) bitset_or (DST, SRC1, SRC2)
+#define bitset_union_cmp(DST, SRC1, SRC2) bitset_or_cmp (DST, SRC1, SRC2)
+
+/* Symmetrical difference. */
+#define bitset_symdiff(DST, SRC1, SRC2) bitset_xor (DST, SRC1, SRC2)
+#define bitset_symdiff_cmp(DST, SRC1, SRC2) bitset_xor_cmp (DST, SRC1, SRC2)
+
+/* Union of difference. */
+#define bitset_diff_union(DST, SRC1, SRC2, SRC3) \
+ bitset_andn_or (DST, SRC1, SRC2, SRC3)
+#define bitset_diff_union_cmp(DST, SRC1, SRC2, SRC3) \
+ bitset_andn_or_cmp (DST, SRC1, SRC2, SRC3)
+
+
+/* Release any memory tied up with bitsets. */
+extern void bitset_release_memory (void);
+
+/* Enable bitset stats gathering. */
+extern void bitset_stats_enable (void);
+
+/* Disable bitset stats gathering. */
+extern void bitset_stats_disable (void);
+
+/* Read bitset stats file of accummulated stats. */
+void bitset_stats_read (const char *file_name);
+
+/* Write bitset stats file of accummulated stats. */
+void bitset_stats_write (const char *file_name);
+
+/* Dump bitset stats. */
+extern void bitset_stats_dump (FILE *);
+
+/* Function to debug bitset from debugger. */
+extern void debug_bitset (bitset);
+
+/* Function to debug bitset stats from debugger. */
+extern void debug_bitset_stats (void);
+
+#endif /* _BITSET_H */
diff --git a/contrib/tools/bison/gnulib/src/bitset_stats.c b/contrib/tools/bison/gnulib/src/bitset_stats.c
index 8316302616..d52ee2af0f 100644
--- a/contrib/tools/bison/gnulib/src/bitset_stats.c
+++ b/contrib/tools/bison/gnulib/src/bitset_stats.c
@@ -1,728 +1,728 @@
-/* Bitset statistics.
-
- Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* This file is a wrapper bitset implementation for the other bitset
- implementations. It provides bitset compatibility checking and
- statistics gathering without having to instrument the bitset
- implementations. When statistics gathering is enabled, the bitset
- operations get vectored through here and we then call the appropriate
- routines. */
-
-#include <config.h>
-
-#include "bitset_stats.h"
-
-#include "bbitset.h"
-#include "abitset.h"
-#include "ebitset.h"
-#include "lbitset.h"
-#include "vbitset.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "gettext.h"
-#define _(Msgid) gettext (Msgid)
-
-/* Configuration macros. */
-#define BITSET_STATS_FILE "bitset.dat"
-#define BITSET_LOG_COUNT_BINS 10
-#define BITSET_LOG_SIZE_BINS 16
-#define BITSET_DENSITY_BINS 20
-
-
-/* Accessor macros. */
-#define BITSET_STATS_ALLOCS_INC(TYPE) \
- bitset_stats_info->types[(TYPE)].allocs++
-#define BITSET_STATS_FREES_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].frees++
-#define BITSET_STATS_SETS_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].sets++
-#define BITSET_STATS_CACHE_SETS_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_sets++
-#define BITSET_STATS_RESETS_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].resets++
-#define BITSET_STATS_CACHE_RESETS_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_resets++
-#define BITSET_STATS_TESTS_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].tests++
-#define BITSET_STATS_CACHE_TESTS_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_tests++
-#define BITSET_STATS_LISTS_INC(BSET) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].lists++
-#define BITSET_STATS_LIST_COUNTS_INC(BSET, I) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_counts[(I)]++
-#define BITSET_STATS_LIST_SIZES_INC(BSET, I) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_sizes[(I)]++
-#define BITSET_STATS_LIST_DENSITY_INC(BSET, I) \
- bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_density[(I)]++
-
-
-struct bitset_type_info_struct
-{
- unsigned int allocs;
- unsigned int frees;
- unsigned int lists;
- unsigned int sets;
- unsigned int cache_sets;
- unsigned int resets;
- unsigned int cache_resets;
- unsigned int tests;
- unsigned int cache_tests;
- unsigned int list_counts[BITSET_LOG_COUNT_BINS];
- unsigned int list_sizes[BITSET_LOG_SIZE_BINS];
- unsigned int list_density[BITSET_DENSITY_BINS];
-};
-
-struct bitset_stats_info_struct
-{
- unsigned int runs;
- struct bitset_type_info_struct types[BITSET_TYPE_NUM];
-};
-
-
-struct bitset_stats_info_struct bitset_stats_info_data;
-struct bitset_stats_info_struct *bitset_stats_info;
-bool bitset_stats_enabled = false;
-
-
-/* Print a percentage histogram with message MSG to FILE. */
-static void
-bitset_percent_histogram_print (FILE *file, const char *name, const char *msg,
- unsigned int n_bins, unsigned int *bins)
-{
- unsigned int i;
- unsigned int total;
-
- total = 0;
- for (i = 0; i < n_bins; i++)
- total += bins[i];
-
- if (!total)
- return;
-
- fprintf (file, "%s %s", name, msg);
- for (i = 0; i < n_bins; i++)
- fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n",
- i * 100.0 / n_bins,
- (i + 1) * 100.0 / n_bins, bins[i],
- (100.0 * bins[i]) / total);
-}
-
-
-/* Print a log histogram with message MSG to FILE. */
-static void
-bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
- unsigned int n_bins, unsigned int *bins)
-{
- unsigned int i;
- unsigned int total;
- unsigned int max_width;
-
- total = 0;
- for (i = 0; i < n_bins; i++)
- total += bins[i];
-
- if (!total)
- return;
-
- /* Determine number of useful bins. */
- for (i = n_bins; i > 3 && ! bins[i - 1]; i--)
- continue;
- n_bins = i;
-
- /* 2 * ceil (log10 (2) * (N - 1)) + 1. */
- max_width = 2 * (unsigned int) (0.30103 * (n_bins - 1) + 0.9999) + 1;
-
- fprintf (file, "%s %s", name, msg);
- for (i = 0; i < 2; i++)
- fprintf (file, "%*d\t%8u (%5.1f%%)\n",
- max_width, i, bins[i], 100.0 * bins[i] / total);
-
- for (; i < n_bins; i++)
- fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n",
- max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1),
- 1UL << (i - 1),
- (1UL << i) - 1,
- bins[i],
- (100.0 * bins[i]) / total);
-}
-
-
-/* Print bitset statistics to FILE. */
-static void
-bitset_stats_print_1 (FILE *file, const char *name,
- struct bitset_type_info_struct *stats)
-{
- if (!stats)
- return;
-
- fprintf (file, "%s:\n", name);
- fprintf (file, _("%u bitset_allocs, %u freed (%.2f%%).\n"),
- stats->allocs, stats->frees,
- stats->allocs ? 100.0 * stats->frees / stats->allocs : 0);
- fprintf (file, _("%u bitset_sets, %u cached (%.2f%%)\n"),
- stats->sets, stats->cache_sets,
- stats->sets ? 100.0 * stats->cache_sets / stats->sets : 0);
- fprintf (file, _("%u bitset_resets, %u cached (%.2f%%)\n"),
- stats->resets, stats->cache_resets,
- stats->resets ? 100.0 * stats->cache_resets / stats->resets : 0);
- fprintf (file, _("%u bitset_tests, %u cached (%.2f%%)\n"),
- stats->tests, stats->cache_tests,
- stats->tests ? 100.0 * stats->cache_tests / stats->tests : 0);
-
- fprintf (file, _("%u bitset_lists\n"), stats->lists);
-
- bitset_log_histogram_print (file, name, _("count log histogram\n"),
- BITSET_LOG_COUNT_BINS, stats->list_counts);
-
- bitset_log_histogram_print (file, name, _("size log histogram\n"),
- BITSET_LOG_SIZE_BINS, stats->list_sizes);
-
- bitset_percent_histogram_print (file, name, _("density histogram\n"),
- BITSET_DENSITY_BINS, stats->list_density);
-}
-
-
-/* Print all bitset statistics to FILE. */
-static void
-bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
-{
- int i;
-
- if (!bitset_stats_info)
- return;
-
- fprintf (file, _("Bitset statistics:\n\n"));
-
- if (bitset_stats_info->runs > 1)
- fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs);
-
- for (i = 0; i < BITSET_TYPE_NUM; i++)
- bitset_stats_print_1 (file, bitset_type_names[i],
- &bitset_stats_info->types[i]);
-}
-
-
-/* Initialise bitset statistics logging. */
-void
-bitset_stats_enable (void)
-{
- if (!bitset_stats_info)
- bitset_stats_info = &bitset_stats_info_data;
- bitset_stats_enabled = true;
-}
-
-
-void
-bitset_stats_disable (void)
-{
- bitset_stats_enabled = false;
-}
-
-
-/* Read bitset statistics file. */
-void
-bitset_stats_read (const char *file_name)
-{
- FILE *file;
-
- if (!bitset_stats_info)
- return;
-
- if (!file_name)
- file_name = BITSET_STATS_FILE;
-
- file = fopen (file_name, "r");
- if (file)
- {
- if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
- 1, file) != 1)
- {
- if (ferror (file))
- perror (_("cannot read stats file"));
- else
- fprintf (stderr, _("bad stats file size\n"));
- }
- if (fclose (file) != 0)
- perror (_("cannot read stats file"));
- }
- bitset_stats_info_data.runs++;
-}
-
-
-/* Write bitset statistics file. */
-void
-bitset_stats_write (const char *file_name)
-{
- FILE *file;
-
- if (!bitset_stats_info)
- return;
-
- if (!file_name)
- file_name = BITSET_STATS_FILE;
-
- file = fopen (file_name, "w");
- if (file)
- {
- if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
- 1, file) != 1)
- perror (_("cannot write stats file"));
- if (fclose (file) != 0)
- perror (_("cannot write stats file"));
- }
- else
- perror (_("cannot open stats file for writing"));
-}
-
-
-/* Dump bitset statistics to FILE. */
-void
-bitset_stats_dump (FILE *file)
-{
- bitset_stats_print (file, false);
-}
-
-
-/* Function to be called from debugger to print bitset stats. */
-void
-debug_bitset_stats (void)
-{
- bitset_stats_print (stderr, true);
-}
-
-
-static void
-bitset_stats_set (bitset dst, bitset_bindex bitno)
-{
- bitset bset = dst->s.bset;
- bitset_windex wordno = bitno / BITSET_WORD_BITS;
- bitset_windex offset = wordno - bset->b.cindex;
-
- BITSET_STATS_SETS_INC (bset);
-
- if (offset < bset->b.csize)
- {
- bset->b.cdata[offset] |= (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
- BITSET_STATS_CACHE_SETS_INC (bset);
- }
- else
- BITSET_SET_ (bset, bitno);
-}
-
-
-static void
-bitset_stats_reset (bitset dst, bitset_bindex bitno)
-{
- bitset bset = dst->s.bset;
- bitset_windex wordno = bitno / BITSET_WORD_BITS;
- bitset_windex offset = wordno - bset->b.cindex;
-
- BITSET_STATS_RESETS_INC (bset);
-
- if (offset < bset->b.csize)
- {
- bset->b.cdata[offset] &=
- ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
- BITSET_STATS_CACHE_RESETS_INC (bset);
- }
- else
- BITSET_RESET_ (bset, bitno);
-}
-
-
-static bool
-bitset_stats_toggle (bitset src, bitset_bindex bitno)
-{
- return BITSET_TOGGLE_ (src->s.bset, bitno);
-}
-
-
-static bool
-bitset_stats_test (bitset src, bitset_bindex bitno)
-{
- bitset bset = src->s.bset;
- bitset_windex wordno = bitno / BITSET_WORD_BITS;
- bitset_windex offset = wordno - bset->b.cindex;
-
- BITSET_STATS_TESTS_INC (bset);
-
- if (offset < bset->b.csize)
- {
- BITSET_STATS_CACHE_TESTS_INC (bset);
- return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
- }
- else
- return BITSET_TEST_ (bset, bitno);
-}
-
-
-static bitset_bindex
-bitset_stats_resize (bitset src, bitset_bindex size)
-{
- return BITSET_RESIZE_ (src->s.bset, size);
-}
-
-
-static bitset_bindex
-bitset_stats_size (bitset src)
-{
- return BITSET_SIZE_ (src->s.bset);
-}
-
-
-static bitset_bindex
-bitset_stats_count (bitset src)
-{
- return BITSET_COUNT_ (src->s.bset);
-}
-
-
-static bool
-bitset_stats_empty_p (bitset dst)
-{
- return BITSET_EMPTY_P_ (dst->s.bset);
-}
-
-
-static void
-bitset_stats_ones (bitset dst)
-{
- BITSET_ONES_ (dst->s.bset);
-}
-
-
-static void
-bitset_stats_zero (bitset dst)
-{
- BITSET_ZERO_ (dst->s.bset);
-}
-
-
-static void
-bitset_stats_copy (bitset dst, bitset src)
-{
- BITSET_CHECK2_ (dst, src);
- BITSET_COPY_ (dst->s.bset, src->s.bset);
-}
-
-
-static bool
-bitset_stats_disjoint_p (bitset dst, bitset src)
-{
- BITSET_CHECK2_ (dst, src);
- return BITSET_DISJOINT_P_ (dst->s.bset, src->s.bset);
-}
-
-
-static bool
-bitset_stats_equal_p (bitset dst, bitset src)
-{
- BITSET_CHECK2_ (dst, src);
- return BITSET_EQUAL_P_ (dst->s.bset, src->s.bset);
-}
-
-
-static void
-bitset_stats_not (bitset dst, bitset src)
-{
- BITSET_CHECK2_ (dst, src);
- BITSET_NOT_ (dst->s.bset, src->s.bset);
-}
-
-
-static bool
-bitset_stats_subset_p (bitset dst, bitset src)
-{
- BITSET_CHECK2_ (dst, src);
- return BITSET_SUBSET_P_ (dst->s.bset, src->s.bset);
-}
-
-
-static void
-bitset_stats_and (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- BITSET_AND_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static bool
-bitset_stats_and_cmp (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- return BITSET_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static void
-bitset_stats_andn (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- BITSET_ANDN_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static bool
-bitset_stats_andn_cmp (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- return BITSET_ANDN_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static void
-bitset_stats_or (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- BITSET_OR_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static bool
-bitset_stats_or_cmp (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- return BITSET_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static void
-bitset_stats_xor (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- BITSET_XOR_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static bool
-bitset_stats_xor_cmp (bitset dst, bitset src1, bitset src2)
-{
- BITSET_CHECK3_ (dst, src1, src2);
- return BITSET_XOR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
-}
-
-
-static void
-bitset_stats_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- BITSET_CHECK4_ (dst, src1, src2, src3);
- BITSET_AND_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
-}
-
-
-static bool
-bitset_stats_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- BITSET_CHECK4_ (dst, src1, src2, src3);
- return BITSET_AND_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
-}
-
-
-static void
-bitset_stats_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- BITSET_CHECK4_ (dst, src1, src2, src3);
- BITSET_ANDN_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
-}
-
-
-static bool
-bitset_stats_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- BITSET_CHECK4_ (dst, src1, src2, src3);
- return BITSET_ANDN_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
-}
-
-
-static void
-bitset_stats_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- BITSET_CHECK4_ (dst, src1, src2, src3);
- BITSET_OR_AND_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
-}
-
-
-static bool
-bitset_stats_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- BITSET_CHECK4_ (dst, src1, src2, src3);
- return BITSET_OR_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
-}
-
-
-static bitset_bindex
-bitset_stats_list (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex count;
- bitset_bindex tmp;
- bitset_bindex size;
- bitset_bindex i;
-
- count = BITSET_LIST_ (bset->s.bset, list, num, next);
-
- BITSET_STATS_LISTS_INC (bset->s.bset);
-
- /* Log histogram of number of set bits. */
- for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
- continue;
- if (i >= BITSET_LOG_COUNT_BINS)
- i = BITSET_LOG_COUNT_BINS - 1;
- BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i);
-
- /* Log histogram of number of bits in set. */
- size = BITSET_SIZE_ (bset->s.bset);
- for (i = 0, tmp = size; tmp; tmp >>= 1, i++)
- continue;
- if (i >= BITSET_LOG_SIZE_BINS)
- i = BITSET_LOG_SIZE_BINS - 1;
- BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i);
-
- /* Histogram of fraction of bits set. */
- i = size ? (count * BITSET_DENSITY_BINS) / size : 0;
- if (i >= BITSET_DENSITY_BINS)
- i = BITSET_DENSITY_BINS - 1;
- BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i);
- return count;
-}
-
-
-static bitset_bindex
-bitset_stats_list_reverse (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- return BITSET_LIST_REVERSE_ (bset->s.bset, list, num, next);
-}
-
-
-static void
-bitset_stats_free (bitset bset)
-{
- BITSET_STATS_FREES_INC (bset->s.bset);
- BITSET_FREE_ (bset->s.bset);
-}
-
-
-struct bitset_vtable bitset_stats_vtable = {
- bitset_stats_set,
- bitset_stats_reset,
- bitset_stats_toggle,
- bitset_stats_test,
- bitset_stats_resize,
- bitset_stats_size,
- bitset_stats_count,
- bitset_stats_empty_p,
- bitset_stats_ones,
- bitset_stats_zero,
- bitset_stats_copy,
- bitset_stats_disjoint_p,
- bitset_stats_equal_p,
- bitset_stats_not,
- bitset_stats_subset_p,
- bitset_stats_and,
- bitset_stats_and_cmp,
- bitset_stats_andn,
- bitset_stats_andn_cmp,
- bitset_stats_or,
- bitset_stats_or_cmp,
- bitset_stats_xor,
- bitset_stats_xor_cmp,
- bitset_stats_and_or,
- bitset_stats_and_or_cmp,
- bitset_stats_andn_or,
- bitset_stats_andn_or_cmp,
- bitset_stats_or_and,
- bitset_stats_or_and_cmp,
- bitset_stats_list,
- bitset_stats_list_reverse,
- bitset_stats_free,
- BITSET_STATS
-};
-
-
-/* Return enclosed bitset type. */
-enum bitset_type
-bitset_stats_type_get (bitset bset)
-{
- return BITSET_TYPE_ (bset->s.bset);
-}
-
-
-size_t
-bitset_stats_bytes (void)
-{
- return sizeof (struct bitset_stats_struct);
-}
-
-
-bitset
-bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
-{
- size_t bytes;
- bitset sbset;
-
- bset->b.vtable = &bitset_stats_vtable;
-
- /* Disable cache. */
- bset->b.cindex = 0;
- bset->b.csize = 0;
- bset->b.cdata = 0;
-
- BITSET_NBITS_ (bset) = n_bits;
-
- /* Set up the actual bitset implementation that
- we are a wrapper over. */
- switch (type)
- {
- default:
- abort ();
-
- case BITSET_ARRAY:
- bytes = abitset_bytes (n_bits);
- sbset = xcalloc (1, bytes);
- abitset_init (sbset, n_bits);
- break;
-
- case BITSET_LIST:
- bytes = lbitset_bytes (n_bits);
- sbset = xcalloc (1, bytes);
- lbitset_init (sbset, n_bits);
- break;
-
- case BITSET_TABLE:
- bytes = ebitset_bytes (n_bits);
- sbset = xcalloc (1, bytes);
- ebitset_init (sbset, n_bits);
- break;
-
- case BITSET_VARRAY:
- bytes = vbitset_bytes (n_bits);
- sbset = xcalloc (1, bytes);
- vbitset_init (sbset, n_bits);
- break;
- }
-
- bset->s.bset = sbset;
-
- BITSET_STATS_ALLOCS_INC (type);
-
- return bset;
-}
+/* Bitset statistics.
+
+ Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* This file is a wrapper bitset implementation for the other bitset
+ implementations. It provides bitset compatibility checking and
+ statistics gathering without having to instrument the bitset
+ implementations. When statistics gathering is enabled, the bitset
+ operations get vectored through here and we then call the appropriate
+ routines. */
+
+#include <config.h>
+
+#include "bitset_stats.h"
+
+#include "bbitset.h"
+#include "abitset.h"
+#include "ebitset.h"
+#include "lbitset.h"
+#include "vbitset.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "gettext.h"
+#define _(Msgid) gettext (Msgid)
+
+/* Configuration macros. */
+#define BITSET_STATS_FILE "bitset.dat"
+#define BITSET_LOG_COUNT_BINS 10
+#define BITSET_LOG_SIZE_BINS 16
+#define BITSET_DENSITY_BINS 20
+
+
+/* Accessor macros. */
+#define BITSET_STATS_ALLOCS_INC(TYPE) \
+ bitset_stats_info->types[(TYPE)].allocs++
+#define BITSET_STATS_FREES_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].frees++
+#define BITSET_STATS_SETS_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].sets++
+#define BITSET_STATS_CACHE_SETS_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_sets++
+#define BITSET_STATS_RESETS_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].resets++
+#define BITSET_STATS_CACHE_RESETS_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_resets++
+#define BITSET_STATS_TESTS_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].tests++
+#define BITSET_STATS_CACHE_TESTS_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_tests++
+#define BITSET_STATS_LISTS_INC(BSET) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].lists++
+#define BITSET_STATS_LIST_COUNTS_INC(BSET, I) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_counts[(I)]++
+#define BITSET_STATS_LIST_SIZES_INC(BSET, I) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_sizes[(I)]++
+#define BITSET_STATS_LIST_DENSITY_INC(BSET, I) \
+ bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_density[(I)]++
+
+
+struct bitset_type_info_struct
+{
+ unsigned int allocs;
+ unsigned int frees;
+ unsigned int lists;
+ unsigned int sets;
+ unsigned int cache_sets;
+ unsigned int resets;
+ unsigned int cache_resets;
+ unsigned int tests;
+ unsigned int cache_tests;
+ unsigned int list_counts[BITSET_LOG_COUNT_BINS];
+ unsigned int list_sizes[BITSET_LOG_SIZE_BINS];
+ unsigned int list_density[BITSET_DENSITY_BINS];
+};
+
+struct bitset_stats_info_struct
+{
+ unsigned int runs;
+ struct bitset_type_info_struct types[BITSET_TYPE_NUM];
+};
+
+
+struct bitset_stats_info_struct bitset_stats_info_data;
+struct bitset_stats_info_struct *bitset_stats_info;
+bool bitset_stats_enabled = false;
+
+
+/* Print a percentage histogram with message MSG to FILE. */
+static void
+bitset_percent_histogram_print (FILE *file, const char *name, const char *msg,
+ unsigned int n_bins, unsigned int *bins)
+{
+ unsigned int i;
+ unsigned int total;
+
+ total = 0;
+ for (i = 0; i < n_bins; i++)
+ total += bins[i];
+
+ if (!total)
+ return;
+
+ fprintf (file, "%s %s", name, msg);
+ for (i = 0; i < n_bins; i++)
+ fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n",
+ i * 100.0 / n_bins,
+ (i + 1) * 100.0 / n_bins, bins[i],
+ (100.0 * bins[i]) / total);
+}
+
+
+/* Print a log histogram with message MSG to FILE. */
+static void
+bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
+ unsigned int n_bins, unsigned int *bins)
+{
+ unsigned int i;
+ unsigned int total;
+ unsigned int max_width;
+
+ total = 0;
+ for (i = 0; i < n_bins; i++)
+ total += bins[i];
+
+ if (!total)
+ return;
+
+ /* Determine number of useful bins. */
+ for (i = n_bins; i > 3 && ! bins[i - 1]; i--)
+ continue;
+ n_bins = i;
+
+ /* 2 * ceil (log10 (2) * (N - 1)) + 1. */
+ max_width = 2 * (unsigned int) (0.30103 * (n_bins - 1) + 0.9999) + 1;
+
+ fprintf (file, "%s %s", name, msg);
+ for (i = 0; i < 2; i++)
+ fprintf (file, "%*d\t%8u (%5.1f%%)\n",
+ max_width, i, bins[i], 100.0 * bins[i] / total);
+
+ for (; i < n_bins; i++)
+ fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n",
+ max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1),
+ 1UL << (i - 1),
+ (1UL << i) - 1,
+ bins[i],
+ (100.0 * bins[i]) / total);
+}
+
+
+/* Print bitset statistics to FILE. */
+static void
+bitset_stats_print_1 (FILE *file, const char *name,
+ struct bitset_type_info_struct *stats)
+{
+ if (!stats)
+ return;
+
+ fprintf (file, "%s:\n", name);
+ fprintf (file, _("%u bitset_allocs, %u freed (%.2f%%).\n"),
+ stats->allocs, stats->frees,
+ stats->allocs ? 100.0 * stats->frees / stats->allocs : 0);
+ fprintf (file, _("%u bitset_sets, %u cached (%.2f%%)\n"),
+ stats->sets, stats->cache_sets,
+ stats->sets ? 100.0 * stats->cache_sets / stats->sets : 0);
+ fprintf (file, _("%u bitset_resets, %u cached (%.2f%%)\n"),
+ stats->resets, stats->cache_resets,
+ stats->resets ? 100.0 * stats->cache_resets / stats->resets : 0);
+ fprintf (file, _("%u bitset_tests, %u cached (%.2f%%)\n"),
+ stats->tests, stats->cache_tests,
+ stats->tests ? 100.0 * stats->cache_tests / stats->tests : 0);
+
+ fprintf (file, _("%u bitset_lists\n"), stats->lists);
+
+ bitset_log_histogram_print (file, name, _("count log histogram\n"),
+ BITSET_LOG_COUNT_BINS, stats->list_counts);
+
+ bitset_log_histogram_print (file, name, _("size log histogram\n"),
+ BITSET_LOG_SIZE_BINS, stats->list_sizes);
+
+ bitset_percent_histogram_print (file, name, _("density histogram\n"),
+ BITSET_DENSITY_BINS, stats->list_density);
+}
+
+
+/* Print all bitset statistics to FILE. */
+static void
+bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
+{
+ int i;
+
+ if (!bitset_stats_info)
+ return;
+
+ fprintf (file, _("Bitset statistics:\n\n"));
+
+ if (bitset_stats_info->runs > 1)
+ fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs);
+
+ for (i = 0; i < BITSET_TYPE_NUM; i++)
+ bitset_stats_print_1 (file, bitset_type_names[i],
+ &bitset_stats_info->types[i]);
+}
+
+
+/* Initialise bitset statistics logging. */
+void
+bitset_stats_enable (void)
+{
+ if (!bitset_stats_info)
+ bitset_stats_info = &bitset_stats_info_data;
+ bitset_stats_enabled = true;
+}
+
+
+void
+bitset_stats_disable (void)
+{
+ bitset_stats_enabled = false;
+}
+
+
+/* Read bitset statistics file. */
+void
+bitset_stats_read (const char *file_name)
+{
+ FILE *file;
+
+ if (!bitset_stats_info)
+ return;
+
+ if (!file_name)
+ file_name = BITSET_STATS_FILE;
+
+ file = fopen (file_name, "r");
+ if (file)
+ {
+ if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
+ 1, file) != 1)
+ {
+ if (ferror (file))
+ perror (_("cannot read stats file"));
+ else
+ fprintf (stderr, _("bad stats file size\n"));
+ }
+ if (fclose (file) != 0)
+ perror (_("cannot read stats file"));
+ }
+ bitset_stats_info_data.runs++;
+}
+
+
+/* Write bitset statistics file. */
+void
+bitset_stats_write (const char *file_name)
+{
+ FILE *file;
+
+ if (!bitset_stats_info)
+ return;
+
+ if (!file_name)
+ file_name = BITSET_STATS_FILE;
+
+ file = fopen (file_name, "w");
+ if (file)
+ {
+ if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
+ 1, file) != 1)
+ perror (_("cannot write stats file"));
+ if (fclose (file) != 0)
+ perror (_("cannot write stats file"));
+ }
+ else
+ perror (_("cannot open stats file for writing"));
+}
+
+
+/* Dump bitset statistics to FILE. */
+void
+bitset_stats_dump (FILE *file)
+{
+ bitset_stats_print (file, false);
+}
+
+
+/* Function to be called from debugger to print bitset stats. */
+void
+debug_bitset_stats (void)
+{
+ bitset_stats_print (stderr, true);
+}
+
+
+static void
+bitset_stats_set (bitset dst, bitset_bindex bitno)
+{
+ bitset bset = dst->s.bset;
+ bitset_windex wordno = bitno / BITSET_WORD_BITS;
+ bitset_windex offset = wordno - bset->b.cindex;
+
+ BITSET_STATS_SETS_INC (bset);
+
+ if (offset < bset->b.csize)
+ {
+ bset->b.cdata[offset] |= (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
+ BITSET_STATS_CACHE_SETS_INC (bset);
+ }
+ else
+ BITSET_SET_ (bset, bitno);
+}
+
+
+static void
+bitset_stats_reset (bitset dst, bitset_bindex bitno)
+{
+ bitset bset = dst->s.bset;
+ bitset_windex wordno = bitno / BITSET_WORD_BITS;
+ bitset_windex offset = wordno - bset->b.cindex;
+
+ BITSET_STATS_RESETS_INC (bset);
+
+ if (offset < bset->b.csize)
+ {
+ bset->b.cdata[offset] &=
+ ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
+ BITSET_STATS_CACHE_RESETS_INC (bset);
+ }
+ else
+ BITSET_RESET_ (bset, bitno);
+}
+
+
+static bool
+bitset_stats_toggle (bitset src, bitset_bindex bitno)
+{
+ return BITSET_TOGGLE_ (src->s.bset, bitno);
+}
+
+
+static bool
+bitset_stats_test (bitset src, bitset_bindex bitno)
+{
+ bitset bset = src->s.bset;
+ bitset_windex wordno = bitno / BITSET_WORD_BITS;
+ bitset_windex offset = wordno - bset->b.cindex;
+
+ BITSET_STATS_TESTS_INC (bset);
+
+ if (offset < bset->b.csize)
+ {
+ BITSET_STATS_CACHE_TESTS_INC (bset);
+ return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
+ }
+ else
+ return BITSET_TEST_ (bset, bitno);
+}
+
+
+static bitset_bindex
+bitset_stats_resize (bitset src, bitset_bindex size)
+{
+ return BITSET_RESIZE_ (src->s.bset, size);
+}
+
+
+static bitset_bindex
+bitset_stats_size (bitset src)
+{
+ return BITSET_SIZE_ (src->s.bset);
+}
+
+
+static bitset_bindex
+bitset_stats_count (bitset src)
+{
+ return BITSET_COUNT_ (src->s.bset);
+}
+
+
+static bool
+bitset_stats_empty_p (bitset dst)
+{
+ return BITSET_EMPTY_P_ (dst->s.bset);
+}
+
+
+static void
+bitset_stats_ones (bitset dst)
+{
+ BITSET_ONES_ (dst->s.bset);
+}
+
+
+static void
+bitset_stats_zero (bitset dst)
+{
+ BITSET_ZERO_ (dst->s.bset);
+}
+
+
+static void
+bitset_stats_copy (bitset dst, bitset src)
+{
+ BITSET_CHECK2_ (dst, src);
+ BITSET_COPY_ (dst->s.bset, src->s.bset);
+}
+
+
+static bool
+bitset_stats_disjoint_p (bitset dst, bitset src)
+{
+ BITSET_CHECK2_ (dst, src);
+ return BITSET_DISJOINT_P_ (dst->s.bset, src->s.bset);
+}
+
+
+static bool
+bitset_stats_equal_p (bitset dst, bitset src)
+{
+ BITSET_CHECK2_ (dst, src);
+ return BITSET_EQUAL_P_ (dst->s.bset, src->s.bset);
+}
+
+
+static void
+bitset_stats_not (bitset dst, bitset src)
+{
+ BITSET_CHECK2_ (dst, src);
+ BITSET_NOT_ (dst->s.bset, src->s.bset);
+}
+
+
+static bool
+bitset_stats_subset_p (bitset dst, bitset src)
+{
+ BITSET_CHECK2_ (dst, src);
+ return BITSET_SUBSET_P_ (dst->s.bset, src->s.bset);
+}
+
+
+static void
+bitset_stats_and (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ BITSET_AND_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static bool
+bitset_stats_and_cmp (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ return BITSET_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static void
+bitset_stats_andn (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ BITSET_ANDN_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static bool
+bitset_stats_andn_cmp (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ return BITSET_ANDN_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static void
+bitset_stats_or (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ BITSET_OR_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static bool
+bitset_stats_or_cmp (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ return BITSET_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static void
+bitset_stats_xor (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ BITSET_XOR_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static bool
+bitset_stats_xor_cmp (bitset dst, bitset src1, bitset src2)
+{
+ BITSET_CHECK3_ (dst, src1, src2);
+ return BITSET_XOR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
+}
+
+
+static void
+bitset_stats_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ BITSET_CHECK4_ (dst, src1, src2, src3);
+ BITSET_AND_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
+}
+
+
+static bool
+bitset_stats_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ BITSET_CHECK4_ (dst, src1, src2, src3);
+ return BITSET_AND_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
+}
+
+
+static void
+bitset_stats_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ BITSET_CHECK4_ (dst, src1, src2, src3);
+ BITSET_ANDN_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
+}
+
+
+static bool
+bitset_stats_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ BITSET_CHECK4_ (dst, src1, src2, src3);
+ return BITSET_ANDN_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
+}
+
+
+static void
+bitset_stats_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ BITSET_CHECK4_ (dst, src1, src2, src3);
+ BITSET_OR_AND_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
+}
+
+
+static bool
+bitset_stats_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ BITSET_CHECK4_ (dst, src1, src2, src3);
+ return BITSET_OR_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
+}
+
+
+static bitset_bindex
+bitset_stats_list (bitset bset, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex count;
+ bitset_bindex tmp;
+ bitset_bindex size;
+ bitset_bindex i;
+
+ count = BITSET_LIST_ (bset->s.bset, list, num, next);
+
+ BITSET_STATS_LISTS_INC (bset->s.bset);
+
+ /* Log histogram of number of set bits. */
+ for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
+ continue;
+ if (i >= BITSET_LOG_COUNT_BINS)
+ i = BITSET_LOG_COUNT_BINS - 1;
+ BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i);
+
+ /* Log histogram of number of bits in set. */
+ size = BITSET_SIZE_ (bset->s.bset);
+ for (i = 0, tmp = size; tmp; tmp >>= 1, i++)
+ continue;
+ if (i >= BITSET_LOG_SIZE_BINS)
+ i = BITSET_LOG_SIZE_BINS - 1;
+ BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i);
+
+ /* Histogram of fraction of bits set. */
+ i = size ? (count * BITSET_DENSITY_BINS) / size : 0;
+ if (i >= BITSET_DENSITY_BINS)
+ i = BITSET_DENSITY_BINS - 1;
+ BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i);
+ return count;
+}
+
+
+static bitset_bindex
+bitset_stats_list_reverse (bitset bset, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ return BITSET_LIST_REVERSE_ (bset->s.bset, list, num, next);
+}
+
+
+static void
+bitset_stats_free (bitset bset)
+{
+ BITSET_STATS_FREES_INC (bset->s.bset);
+ BITSET_FREE_ (bset->s.bset);
+}
+
+
+struct bitset_vtable bitset_stats_vtable = {
+ bitset_stats_set,
+ bitset_stats_reset,
+ bitset_stats_toggle,
+ bitset_stats_test,
+ bitset_stats_resize,
+ bitset_stats_size,
+ bitset_stats_count,
+ bitset_stats_empty_p,
+ bitset_stats_ones,
+ bitset_stats_zero,
+ bitset_stats_copy,
+ bitset_stats_disjoint_p,
+ bitset_stats_equal_p,
+ bitset_stats_not,
+ bitset_stats_subset_p,
+ bitset_stats_and,
+ bitset_stats_and_cmp,
+ bitset_stats_andn,
+ bitset_stats_andn_cmp,
+ bitset_stats_or,
+ bitset_stats_or_cmp,
+ bitset_stats_xor,
+ bitset_stats_xor_cmp,
+ bitset_stats_and_or,
+ bitset_stats_and_or_cmp,
+ bitset_stats_andn_or,
+ bitset_stats_andn_or_cmp,
+ bitset_stats_or_and,
+ bitset_stats_or_and_cmp,
+ bitset_stats_list,
+ bitset_stats_list_reverse,
+ bitset_stats_free,
+ BITSET_STATS
+};
+
+
+/* Return enclosed bitset type. */
+enum bitset_type
+bitset_stats_type_get (bitset bset)
+{
+ return BITSET_TYPE_ (bset->s.bset);
+}
+
+
+size_t
+bitset_stats_bytes (void)
+{
+ return sizeof (struct bitset_stats_struct);
+}
+
+
+bitset
+bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
+{
+ size_t bytes;
+ bitset sbset;
+
+ bset->b.vtable = &bitset_stats_vtable;
+
+ /* Disable cache. */
+ bset->b.cindex = 0;
+ bset->b.csize = 0;
+ bset->b.cdata = 0;
+
+ BITSET_NBITS_ (bset) = n_bits;
+
+ /* Set up the actual bitset implementation that
+ we are a wrapper over. */
+ switch (type)
+ {
+ default:
+ abort ();
+
+ case BITSET_ARRAY:
+ bytes = abitset_bytes (n_bits);
+ sbset = xcalloc (1, bytes);
+ abitset_init (sbset, n_bits);
+ break;
+
+ case BITSET_LIST:
+ bytes = lbitset_bytes (n_bits);
+ sbset = xcalloc (1, bytes);
+ lbitset_init (sbset, n_bits);
+ break;
+
+ case BITSET_TABLE:
+ bytes = ebitset_bytes (n_bits);
+ sbset = xcalloc (1, bytes);
+ ebitset_init (sbset, n_bits);
+ break;
+
+ case BITSET_VARRAY:
+ bytes = vbitset_bytes (n_bits);
+ sbset = xcalloc (1, bytes);
+ vbitset_init (sbset, n_bits);
+ break;
+ }
+
+ bset->s.bset = sbset;
+
+ BITSET_STATS_ALLOCS_INC (type);
+
+ return bset;
+}
diff --git a/contrib/tools/bison/gnulib/src/bitset_stats.h b/contrib/tools/bison/gnulib/src/bitset_stats.h
index d65fcad93c..1860375c7b 100644
--- a/contrib/tools/bison/gnulib/src/bitset_stats.h
+++ b/contrib/tools/bison/gnulib/src/bitset_stats.h
@@ -1,33 +1,33 @@
-/* Functions to support bitset statistics.
-
- Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _BITSET_STATS_H
-#define _BITSET_STATS_H
-
-#include "bbitset.h"
-
-extern bool bitset_stats_enabled;
-
-extern enum bitset_type bitset_stats_type_get (bitset);
-
-extern size_t bitset_stats_bytes (void);
-
-extern bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type);
-
-#endif
+/* Functions to support bitset statistics.
+
+ Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _BITSET_STATS_H
+#define _BITSET_STATS_H
+
+#include "bbitset.h"
+
+extern bool bitset_stats_enabled;
+
+extern enum bitset_type bitset_stats_type_get (bitset);
+
+extern size_t bitset_stats_bytes (void);
+
+extern bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type);
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/bitsetv-print.c b/contrib/tools/bison/gnulib/src/bitsetv-print.c
index dd544a9c9e..1bbe83d99a 100644
--- a/contrib/tools/bison/gnulib/src/bitsetv-print.c
+++ b/contrib/tools/bison/gnulib/src/bitsetv-print.c
@@ -1,71 +1,71 @@
-/* Bitset vectors.
-
- Copyright (C) 2001-2002, 2004, 2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "bitsetv-print.h"
-
-#include <stdlib.h>
-
-/*--------------------------------------------------------.
-| Display the MATRIX array of SIZE bitsets of size SIZE. |
-`--------------------------------------------------------*/
-
-void
-bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset)
-{
- bitset_bindex i, j;
- bitset_bindex hsize = bitset_size (bset[0]);
-
- /* Title. */
- fprintf (out, "%s BEGIN\n", title);
-
- /* Column numbers. */
- fputs (" ", out);
- for (i = 0; i < hsize; ++i)
- putc (i / 10 ? '0' + i / 10 : ' ', out);
- putc ('\n', out);
- fputs (" ", out);
- for (i = 0; i < hsize; ++i)
- fprintf (out, "%d", (int) (i % 10));
- putc ('\n', out);
-
- /* Bar. */
- fputs (" .", out);
- for (i = 0; i < hsize; ++i)
- putc ('-', out);
- fputs (".\n", out);
-
- /* Contents. */
- for (i = 0; bset[i]; ++i)
- {
- fprintf (out, "%2lu|", (unsigned long int) i);
- for (j = 0; j < hsize; ++j)
- fputs (bitset_test (bset[i], j) ? "1" : " ", out);
- fputs ("|\n", out);
- }
-
- /* Bar. */
- fputs (" `", out);
- for (i = 0; i < hsize; ++i)
- putc ('-', out);
- fputs ("'\n", out);
-
- /* End title. */
- fprintf (out, "%s END\n\n", title);
-}
+/* Bitset vectors.
+
+ Copyright (C) 2001-2002, 2004, 2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "bitsetv-print.h"
+
+#include <stdlib.h>
+
+/*--------------------------------------------------------.
+| Display the MATRIX array of SIZE bitsets of size SIZE. |
+`--------------------------------------------------------*/
+
+void
+bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset)
+{
+ bitset_bindex i, j;
+ bitset_bindex hsize = bitset_size (bset[0]);
+
+ /* Title. */
+ fprintf (out, "%s BEGIN\n", title);
+
+ /* Column numbers. */
+ fputs (" ", out);
+ for (i = 0; i < hsize; ++i)
+ putc (i / 10 ? '0' + i / 10 : ' ', out);
+ putc ('\n', out);
+ fputs (" ", out);
+ for (i = 0; i < hsize; ++i)
+ fprintf (out, "%d", (int) (i % 10));
+ putc ('\n', out);
+
+ /* Bar. */
+ fputs (" .", out);
+ for (i = 0; i < hsize; ++i)
+ putc ('-', out);
+ fputs (".\n", out);
+
+ /* Contents. */
+ for (i = 0; bset[i]; ++i)
+ {
+ fprintf (out, "%2lu|", (unsigned long int) i);
+ for (j = 0; j < hsize; ++j)
+ fputs (bitset_test (bset[i], j) ? "1" : " ", out);
+ fputs ("|\n", out);
+ }
+
+ /* Bar. */
+ fputs (" `", out);
+ for (i = 0; i < hsize; ++i)
+ putc ('-', out);
+ fputs ("'\n", out);
+
+ /* End title. */
+ fprintf (out, "%s END\n\n", title);
+}
diff --git a/contrib/tools/bison/gnulib/src/bitsetv-print.h b/contrib/tools/bison/gnulib/src/bitsetv-print.h
index a7cc8bc106..6b7c48e60d 100644
--- a/contrib/tools/bison/gnulib/src/bitsetv-print.h
+++ b/contrib/tools/bison/gnulib/src/bitsetv-print.h
@@ -1,28 +1,28 @@
-/* Bitset vectors.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Akim Demaille (akim@freefriends.org).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _BITSETV_PRINT_H
-#define _BITSETV_PRINT_H
-
-#include "bitsetv.h"
-
-/* Dump vector of bitsets as a matrix. */
-extern void bitsetv_matrix_dump (FILE *, const char *, bitsetv);
-
-#endif /* _BITSETV_H */
+/* Bitset vectors.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Akim Demaille (akim@freefriends.org).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _BITSETV_PRINT_H
+#define _BITSETV_PRINT_H
+
+#include "bitsetv.h"
+
+/* Dump vector of bitsets as a matrix. */
+extern void bitsetv_matrix_dump (FILE *, const char *, bitsetv);
+
+#endif /* _BITSETV_H */
diff --git a/contrib/tools/bison/gnulib/src/bitsetv.c b/contrib/tools/bison/gnulib/src/bitsetv.c
index 2bdf1bfa1a..f78248c3e4 100644
--- a/contrib/tools/bison/gnulib/src/bitsetv.c
+++ b/contrib/tools/bison/gnulib/src/bitsetv.c
@@ -1,169 +1,169 @@
-/* Bitset vectors.
-
- Copyright (C) 2001-2002, 2004-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "bitsetv.h"
-
-#include <stdlib.h>
-
-
-/* Create a vector of N_VECS bitsets, each of N_BITS, and of
- type TYPE. */
-bitset *
-bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits,
- enum bitset_type type)
-{
- size_t vector_bytes;
- size_t bytes;
- bitset *bsetv;
- bitset_bindex i;
-
- /* Determine number of bytes for each set. */
- bytes = bitset_bytes (type, n_bits);
-
- /* If size calculation overflows, memory is exhausted. */
- if (BITSET_SIZE_MAX / (sizeof (bitset) + bytes) <= n_vecs)
- xalloc_die ();
-
- /* Allocate vector table at head of bitset array. */
- vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1;
- vector_bytes -= vector_bytes % bytes;
- bsetv = xcalloc (1, vector_bytes + bytes * n_vecs);
-
- for (i = 0; i < n_vecs; i++)
- {
- bsetv[i] = (bitset) (void *) ((char *) bsetv + vector_bytes + i * bytes);
-
- bitset_init (bsetv[i], n_bits, type);
- }
-
- /* Null terminate table. */
- bsetv[i] = 0;
- return bsetv;
-}
-
-
-/* Create a vector of N_VECS bitsets, each of N_BITS, and with
- attribute hints specified by ATTR. */
-bitset *
-bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned int attr)
-{
- enum bitset_type type;
-
- type = bitset_type_choose (n_bits, attr);
- return bitsetv_alloc (n_vecs, n_bits, type);
-}
-
-
-/* Free bitset vector BSETV. */
-void
-bitsetv_free (bitsetv bsetv)
-{
- bitset_bindex i;
-
- for (i = 0; bsetv[i]; i++)
- BITSET_FREE_ (bsetv[i]);
- free (bsetv);
-}
-
-
-/* Zero a vector of bitsets. */
-void
-bitsetv_zero (bitsetv bsetv)
-{
- bitset_bindex i;
-
- for (i = 0; bsetv[i]; i++)
- bitset_zero (bsetv[i]);
-}
-
-
-/* Set a vector of bitsets to ones. */
-void
-bitsetv_ones (bitsetv bsetv)
-{
- bitset_bindex i;
-
- for (i = 0; bsetv[i]; i++)
- bitset_ones (bsetv[i]);
-}
-
-
-/* Given a vector BSETV of N bitsets of size N, modify its contents to
- be the transitive closure of what was given. */
-void
-bitsetv_transitive_closure (bitsetv bsetv)
-{
- bitset_bindex i;
- bitset_bindex j;
-
- for (i = 0; bsetv[i]; i++)
- for (j = 0; bsetv[j]; j++)
- if (bitset_test (bsetv[j], i))
- bitset_or (bsetv[j], bsetv[j], bsetv[i]);
-}
-
-
-/* Given a vector BSETV of N bitsets of size N, modify its contents to
- be the reflexive transitive closure of what was given. This is
- the same as transitive closure but with all bits on the diagonal
- of the bit matrix set. */
-void
-bitsetv_reflexive_transitive_closure (bitsetv bsetv)
-{
- bitset_bindex i;
-
- bitsetv_transitive_closure (bsetv);
- for (i = 0; bsetv[i]; i++)
- bitset_set (bsetv[i], i);
-}
-
-
-/* Dump the contents of a bitset vector BSETV with N_VECS elements to
- FILE. */
-void
-bitsetv_dump (FILE *file, char const *title, char const *subtitle,
- bitsetv bsetv)
-{
- bitset_windex i;
-
- fprintf (file, "%s\n", title);
- for (i = 0; bsetv[i]; i++)
- {
- fprintf (file, "%s %lu\n", subtitle, (unsigned long int) i);
- bitset_dump (file, bsetv[i]);
- }
-
- fprintf (file, "\n");
-}
-
-
-void
-debug_bitsetv (bitsetv bsetv)
-{
- bitset_windex i;
-
- for (i = 0; bsetv[i]; i++)
- {
- fprintf (stderr, "%lu: ", (unsigned long int) i);
- debug_bitset (bsetv[i]);
- }
-
- fprintf (stderr, "\n");
-}
+/* Bitset vectors.
+
+ Copyright (C) 2001-2002, 2004-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "bitsetv.h"
+
+#include <stdlib.h>
+
+
+/* Create a vector of N_VECS bitsets, each of N_BITS, and of
+ type TYPE. */
+bitset *
+bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits,
+ enum bitset_type type)
+{
+ size_t vector_bytes;
+ size_t bytes;
+ bitset *bsetv;
+ bitset_bindex i;
+
+ /* Determine number of bytes for each set. */
+ bytes = bitset_bytes (type, n_bits);
+
+ /* If size calculation overflows, memory is exhausted. */
+ if (BITSET_SIZE_MAX / (sizeof (bitset) + bytes) <= n_vecs)
+ xalloc_die ();
+
+ /* Allocate vector table at head of bitset array. */
+ vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1;
+ vector_bytes -= vector_bytes % bytes;
+ bsetv = xcalloc (1, vector_bytes + bytes * n_vecs);
+
+ for (i = 0; i < n_vecs; i++)
+ {
+ bsetv[i] = (bitset) (void *) ((char *) bsetv + vector_bytes + i * bytes);
+
+ bitset_init (bsetv[i], n_bits, type);
+ }
+
+ /* Null terminate table. */
+ bsetv[i] = 0;
+ return bsetv;
+}
+
+
+/* Create a vector of N_VECS bitsets, each of N_BITS, and with
+ attribute hints specified by ATTR. */
+bitset *
+bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned int attr)
+{
+ enum bitset_type type;
+
+ type = bitset_type_choose (n_bits, attr);
+ return bitsetv_alloc (n_vecs, n_bits, type);
+}
+
+
+/* Free bitset vector BSETV. */
+void
+bitsetv_free (bitsetv bsetv)
+{
+ bitset_bindex i;
+
+ for (i = 0; bsetv[i]; i++)
+ BITSET_FREE_ (bsetv[i]);
+ free (bsetv);
+}
+
+
+/* Zero a vector of bitsets. */
+void
+bitsetv_zero (bitsetv bsetv)
+{
+ bitset_bindex i;
+
+ for (i = 0; bsetv[i]; i++)
+ bitset_zero (bsetv[i]);
+}
+
+
+/* Set a vector of bitsets to ones. */
+void
+bitsetv_ones (bitsetv bsetv)
+{
+ bitset_bindex i;
+
+ for (i = 0; bsetv[i]; i++)
+ bitset_ones (bsetv[i]);
+}
+
+
+/* Given a vector BSETV of N bitsets of size N, modify its contents to
+ be the transitive closure of what was given. */
+void
+bitsetv_transitive_closure (bitsetv bsetv)
+{
+ bitset_bindex i;
+ bitset_bindex j;
+
+ for (i = 0; bsetv[i]; i++)
+ for (j = 0; bsetv[j]; j++)
+ if (bitset_test (bsetv[j], i))
+ bitset_or (bsetv[j], bsetv[j], bsetv[i]);
+}
+
+
+/* Given a vector BSETV of N bitsets of size N, modify its contents to
+ be the reflexive transitive closure of what was given. This is
+ the same as transitive closure but with all bits on the diagonal
+ of the bit matrix set. */
+void
+bitsetv_reflexive_transitive_closure (bitsetv bsetv)
+{
+ bitset_bindex i;
+
+ bitsetv_transitive_closure (bsetv);
+ for (i = 0; bsetv[i]; i++)
+ bitset_set (bsetv[i], i);
+}
+
+
+/* Dump the contents of a bitset vector BSETV with N_VECS elements to
+ FILE. */
+void
+bitsetv_dump (FILE *file, char const *title, char const *subtitle,
+ bitsetv bsetv)
+{
+ bitset_windex i;
+
+ fprintf (file, "%s\n", title);
+ for (i = 0; bsetv[i]; i++)
+ {
+ fprintf (file, "%s %lu\n", subtitle, (unsigned long int) i);
+ bitset_dump (file, bsetv[i]);
+ }
+
+ fprintf (file, "\n");
+}
+
+
+void
+debug_bitsetv (bitsetv bsetv)
+{
+ bitset_windex i;
+
+ for (i = 0; bsetv[i]; i++)
+ {
+ fprintf (stderr, "%lu: ", (unsigned long int) i);
+ debug_bitset (bsetv[i]);
+ }
+
+ fprintf (stderr, "\n");
+}
diff --git a/contrib/tools/bison/gnulib/src/bitsetv.h b/contrib/tools/bison/gnulib/src/bitsetv.h
index 2472a82a5c..20c518fc78 100644
--- a/contrib/tools/bison/gnulib/src/bitsetv.h
+++ b/contrib/tools/bison/gnulib/src/bitsetv.h
@@ -1,60 +1,60 @@
-/* Bitset vectors.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _BITSETV_H
-#define _BITSETV_H
-
-#include "bitset.h"
-
-typedef bitset * bitsetv;
-
-/* Create a vector of N_VECS bitsets, each of N_BITS, and of
- type TYPE. */
-extern bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type);
-
-/* Create a vector of N_VECS bitsets, each of N_BITS, and with
- attribute hints specified by ATTR. */
-extern bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned int);
-
-/* Free vector of bitsets. */
-extern void bitsetv_free (bitsetv);
-
-/* Zero vector of bitsets. */
-extern void bitsetv_zero (bitsetv);
-
-/* Set vector of bitsets. */
-extern void bitsetv_ones (bitsetv);
-
-/* Given a vector BSETV of N bitsets of size N, modify its contents to
- be the transitive closure of what was given. */
-extern void bitsetv_transitive_closure (bitsetv);
-
-/* Given a vector BSETV of N bitsets of size N, modify its contents to
- be the reflexive transitive closure of what was given. This is
- the same as transitive closure but with all bits on the diagonal
- of the bit matrix set. */
-extern void bitsetv_reflexive_transitive_closure (bitsetv);
-
-/* Dump vector of bitsets. */
-extern void bitsetv_dump (FILE *, const char *, const char *, bitsetv);
-
-/* Function to debug vector of bitsets from debugger. */
-extern void debug_bitsetv (bitsetv);
-
-#endif /* _BITSETV_H */
+/* Bitset vectors.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _BITSETV_H
+#define _BITSETV_H
+
+#include "bitset.h"
+
+typedef bitset * bitsetv;
+
+/* Create a vector of N_VECS bitsets, each of N_BITS, and of
+ type TYPE. */
+extern bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type);
+
+/* Create a vector of N_VECS bitsets, each of N_BITS, and with
+ attribute hints specified by ATTR. */
+extern bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned int);
+
+/* Free vector of bitsets. */
+extern void bitsetv_free (bitsetv);
+
+/* Zero vector of bitsets. */
+extern void bitsetv_zero (bitsetv);
+
+/* Set vector of bitsets. */
+extern void bitsetv_ones (bitsetv);
+
+/* Given a vector BSETV of N bitsets of size N, modify its contents to
+ be the transitive closure of what was given. */
+extern void bitsetv_transitive_closure (bitsetv);
+
+/* Given a vector BSETV of N bitsets of size N, modify its contents to
+ be the reflexive transitive closure of what was given. This is
+ the same as transitive closure but with all bits on the diagonal
+ of the bit matrix set. */
+extern void bitsetv_reflexive_transitive_closure (bitsetv);
+
+/* Dump vector of bitsets. */
+extern void bitsetv_dump (FILE *, const char *, const char *, bitsetv);
+
+/* Function to debug vector of bitsets from debugger. */
+extern void debug_bitsetv (bitsetv);
+
+#endif /* _BITSETV_H */
diff --git a/contrib/tools/bison/gnulib/src/btowc.c b/contrib/tools/bison/gnulib/src/btowc.c
index 6c7cbec9d4..1419247603 100644
--- a/contrib/tools/bison/gnulib/src/btowc.c
+++ b/contrib/tools/bison/gnulib/src/btowc.c
@@ -1,39 +1,39 @@
-/* Convert unibyte character to wide character.
- Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2008.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <wchar.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-wint_t
-btowc (int c)
-{
- if (c != EOF)
- {
- char buf[1];
- wchar_t wc;
-
- buf[0] = c;
- if (mbtowc (&wc, buf, 1) >= 0)
- return wc;
- }
- return WEOF;
-}
+/* Convert unibyte character to wide character.
+ Copyright (C) 2008, 2010-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+wint_t
+btowc (int c)
+{
+ if (c != EOF)
+ {
+ char buf[1];
+ wchar_t wc;
+
+ buf[0] = c;
+ if (mbtowc (&wc, buf, 1) >= 0)
+ return wc;
+ }
+ return WEOF;
+}
diff --git a/contrib/tools/bison/gnulib/src/c-ctype.c b/contrib/tools/bison/gnulib/src/c-ctype.c
index 752d2e32ae..88deb6c0a3 100644
--- a/contrib/tools/bison/gnulib/src/c-ctype.c
+++ b/contrib/tools/bison/gnulib/src/c-ctype.c
@@ -1,395 +1,395 @@
-/* Character handling in C locale.
-
- Copyright 2000-2003, 2006, 2009-2013 Free Software Foundation, Inc.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#define NO_C_CTYPE_MACROS
-#include "c-ctype.h"
-
-/* The function isascii is not locale dependent. Its use in EBCDIC is
- questionable. */
-bool
-c_isascii (int c)
-{
- return (c >= 0x00 && c <= 0x7f);
-}
-
-bool
-c_isalnum (int c)
-{
-#if C_CTYPE_CONSECUTIVE_DIGITS \
- && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-#if C_CTYPE_ASCII
- return ((c >= '0' && c <= '9')
- || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z'));
-#else
- return ((c >= '0' && c <= '9')
- || (c >= 'A' && c <= 'Z')
- || (c >= 'a' && c <= 'z'));
-#endif
-#else
- switch (c)
- {
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_isalpha (int c)
-{
-#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-#if C_CTYPE_ASCII
- return ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z');
-#else
- return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
-#endif
-#else
- switch (c)
- {
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_isblank (int c)
-{
- return (c == ' ' || c == '\t');
-}
-
-bool
-c_iscntrl (int c)
-{
-#if C_CTYPE_ASCII
- return ((c & ~0x1f) == 0 || c == 0x7f);
-#else
- switch (c)
- {
- case ' ': case '!': case '"': case '#': case '$': case '%':
- case '&': case '\'': case '(': case ')': case '*': case '+':
- case ',': case '-': case '.': case '/':
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- case ':': case ';': case '<': case '=': case '>': case '?':
- case '@':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- case '[': case '\\': case ']': case '^': case '_': case '`':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- case '{': case '|': case '}': case '~':
- return 0;
- default:
- return 1;
- }
-#endif
-}
-
-bool
-c_isdigit (int c)
-{
-#if C_CTYPE_CONSECUTIVE_DIGITS
- return (c >= '0' && c <= '9');
-#else
- switch (c)
- {
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_islower (int c)
-{
-#if C_CTYPE_CONSECUTIVE_LOWERCASE
- return (c >= 'a' && c <= 'z');
-#else
- switch (c)
- {
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_isgraph (int c)
-{
-#if C_CTYPE_ASCII
- return (c >= '!' && c <= '~');
-#else
- switch (c)
- {
- case '!': case '"': case '#': case '$': case '%': case '&':
- case '\'': case '(': case ')': case '*': case '+': case ',':
- case '-': case '.': case '/':
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- case ':': case ';': case '<': case '=': case '>': case '?':
- case '@':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- case '[': case '\\': case ']': case '^': case '_': case '`':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- case '{': case '|': case '}': case '~':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_isprint (int c)
-{
-#if C_CTYPE_ASCII
- return (c >= ' ' && c <= '~');
-#else
- switch (c)
- {
- case ' ': case '!': case '"': case '#': case '$': case '%':
- case '&': case '\'': case '(': case ')': case '*': case '+':
- case ',': case '-': case '.': case '/':
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- case ':': case ';': case '<': case '=': case '>': case '?':
- case '@':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- case '[': case '\\': case ']': case '^': case '_': case '`':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
- case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
- case 's': case 't': case 'u': case 'v': case 'w': case 'x':
- case 'y': case 'z':
- case '{': case '|': case '}': case '~':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_ispunct (int c)
-{
-#if C_CTYPE_ASCII
- return ((c >= '!' && c <= '~')
- && !((c >= '0' && c <= '9')
- || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z')));
-#else
- switch (c)
- {
- case '!': case '"': case '#': case '$': case '%': case '&':
- case '\'': case '(': case ')': case '*': case '+': case ',':
- case '-': case '.': case '/':
- case ':': case ';': case '<': case '=': case '>': case '?':
- case '@':
- case '[': case '\\': case ']': case '^': case '_': case '`':
- case '{': case '|': case '}': case '~':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_isspace (int c)
-{
- return (c == ' ' || c == '\t'
- || c == '\n' || c == '\v' || c == '\f' || c == '\r');
-}
-
-bool
-c_isupper (int c)
-{
-#if C_CTYPE_CONSECUTIVE_UPPERCASE
- return (c >= 'A' && c <= 'Z');
-#else
- switch (c)
- {
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-bool
-c_isxdigit (int c)
-{
-#if C_CTYPE_CONSECUTIVE_DIGITS \
- && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-#if C_CTYPE_ASCII
- return ((c >= '0' && c <= '9')
- || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F'));
-#else
- return ((c >= '0' && c <= '9')
- || (c >= 'A' && c <= 'F')
- || (c >= 'a' && c <= 'f'));
-#endif
-#else
- switch (c)
- {
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- return 1;
- default:
- return 0;
- }
-#endif
-}
-
-int
-c_tolower (int c)
-{
-#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
- return (c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c);
-#else
- switch (c)
- {
- case 'A': return 'a';
- case 'B': return 'b';
- case 'C': return 'c';
- case 'D': return 'd';
- case 'E': return 'e';
- case 'F': return 'f';
- case 'G': return 'g';
- case 'H': return 'h';
- case 'I': return 'i';
- case 'J': return 'j';
- case 'K': return 'k';
- case 'L': return 'l';
- case 'M': return 'm';
- case 'N': return 'n';
- case 'O': return 'o';
- case 'P': return 'p';
- case 'Q': return 'q';
- case 'R': return 'r';
- case 'S': return 's';
- case 'T': return 't';
- case 'U': return 'u';
- case 'V': return 'v';
- case 'W': return 'w';
- case 'X': return 'x';
- case 'Y': return 'y';
- case 'Z': return 'z';
- default: return c;
- }
-#endif
-}
-
-int
-c_toupper (int c)
-{
-#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
- return (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
-#else
- switch (c)
- {
- case 'a': return 'A';
- case 'b': return 'B';
- case 'c': return 'C';
- case 'd': return 'D';
- case 'e': return 'E';
- case 'f': return 'F';
- case 'g': return 'G';
- case 'h': return 'H';
- case 'i': return 'I';
- case 'j': return 'J';
- case 'k': return 'K';
- case 'l': return 'L';
- case 'm': return 'M';
- case 'n': return 'N';
- case 'o': return 'O';
- case 'p': return 'P';
- case 'q': return 'Q';
- case 'r': return 'R';
- case 's': return 'S';
- case 't': return 'T';
- case 'u': return 'U';
- case 'v': return 'V';
- case 'w': return 'W';
- case 'x': return 'X';
- case 'y': return 'Y';
- case 'z': return 'Z';
- default: return c;
- }
-#endif
-}
+/* Character handling in C locale.
+
+ Copyright 2000-2003, 2006, 2009-2013 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#define NO_C_CTYPE_MACROS
+#include "c-ctype.h"
+
+/* The function isascii is not locale dependent. Its use in EBCDIC is
+ questionable. */
+bool
+c_isascii (int c)
+{
+ return (c >= 0x00 && c <= 0x7f);
+}
+
+bool
+c_isalnum (int c)
+{
+#if C_CTYPE_CONSECUTIVE_DIGITS \
+ && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+#if C_CTYPE_ASCII
+ return ((c >= '0' && c <= '9')
+ || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z'));
+#else
+ return ((c >= '0' && c <= '9')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= 'a' && c <= 'z'));
+#endif
+#else
+ switch (c)
+ {
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
+ case 's': case 't': case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_isalpha (int c)
+{
+#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+#if C_CTYPE_ASCII
+ return ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z');
+#else
+ return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
+#endif
+#else
+ switch (c)
+ {
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
+ case 's': case 't': case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_isblank (int c)
+{
+ return (c == ' ' || c == '\t');
+}
+
+bool
+c_iscntrl (int c)
+{
+#if C_CTYPE_ASCII
+ return ((c & ~0x1f) == 0 || c == 0x7f);
+#else
+ switch (c)
+ {
+ case ' ': case '!': case '"': case '#': case '$': case '%':
+ case '&': case '\'': case '(': case ')': case '*': case '+':
+ case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ case ':': case ';': case '<': case '=': case '>': case '?':
+ case '@':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ case '[': case '\\': case ']': case '^': case '_': case '`':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
+ case 's': case 't': case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ case '{': case '|': case '}': case '~':
+ return 0;
+ default:
+ return 1;
+ }
+#endif
+}
+
+bool
+c_isdigit (int c)
+{
+#if C_CTYPE_CONSECUTIVE_DIGITS
+ return (c >= '0' && c <= '9');
+#else
+ switch (c)
+ {
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_islower (int c)
+{
+#if C_CTYPE_CONSECUTIVE_LOWERCASE
+ return (c >= 'a' && c <= 'z');
+#else
+ switch (c)
+ {
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
+ case 's': case 't': case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_isgraph (int c)
+{
+#if C_CTYPE_ASCII
+ return (c >= '!' && c <= '~');
+#else
+ switch (c)
+ {
+ case '!': case '"': case '#': case '$': case '%': case '&':
+ case '\'': case '(': case ')': case '*': case '+': case ',':
+ case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ case ':': case ';': case '<': case '=': case '>': case '?':
+ case '@':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ case '[': case '\\': case ']': case '^': case '_': case '`':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
+ case 's': case 't': case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ case '{': case '|': case '}': case '~':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_isprint (int c)
+{
+#if C_CTYPE_ASCII
+ return (c >= ' ' && c <= '~');
+#else
+ switch (c)
+ {
+ case ' ': case '!': case '"': case '#': case '$': case '%':
+ case '&': case '\'': case '(': case ')': case '*': case '+':
+ case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ case ':': case ';': case '<': case '=': case '>': case '?':
+ case '@':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ case '[': case '\\': case ']': case '^': case '_': case '`':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
+ case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
+ case 's': case 't': case 'u': case 'v': case 'w': case 'x':
+ case 'y': case 'z':
+ case '{': case '|': case '}': case '~':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_ispunct (int c)
+{
+#if C_CTYPE_ASCII
+ return ((c >= '!' && c <= '~')
+ && !((c >= '0' && c <= '9')
+ || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z')));
+#else
+ switch (c)
+ {
+ case '!': case '"': case '#': case '$': case '%': case '&':
+ case '\'': case '(': case ')': case '*': case '+': case ',':
+ case '-': case '.': case '/':
+ case ':': case ';': case '<': case '=': case '>': case '?':
+ case '@':
+ case '[': case '\\': case ']': case '^': case '_': case '`':
+ case '{': case '|': case '}': case '~':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_isspace (int c)
+{
+ return (c == ' ' || c == '\t'
+ || c == '\n' || c == '\v' || c == '\f' || c == '\r');
+}
+
+bool
+c_isupper (int c)
+{
+#if C_CTYPE_CONSECUTIVE_UPPERCASE
+ return (c >= 'A' && c <= 'Z');
+#else
+ switch (c)
+ {
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+bool
+c_isxdigit (int c)
+{
+#if C_CTYPE_CONSECUTIVE_DIGITS \
+ && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+#if C_CTYPE_ASCII
+ return ((c >= '0' && c <= '9')
+ || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F'));
+#else
+ return ((c >= '0' && c <= '9')
+ || (c >= 'A' && c <= 'F')
+ || (c >= 'a' && c <= 'f'));
+#endif
+#else
+ switch (c)
+ {
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+int
+c_tolower (int c)
+{
+#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+ return (c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c);
+#else
+ switch (c)
+ {
+ case 'A': return 'a';
+ case 'B': return 'b';
+ case 'C': return 'c';
+ case 'D': return 'd';
+ case 'E': return 'e';
+ case 'F': return 'f';
+ case 'G': return 'g';
+ case 'H': return 'h';
+ case 'I': return 'i';
+ case 'J': return 'j';
+ case 'K': return 'k';
+ case 'L': return 'l';
+ case 'M': return 'm';
+ case 'N': return 'n';
+ case 'O': return 'o';
+ case 'P': return 'p';
+ case 'Q': return 'q';
+ case 'R': return 'r';
+ case 'S': return 's';
+ case 'T': return 't';
+ case 'U': return 'u';
+ case 'V': return 'v';
+ case 'W': return 'w';
+ case 'X': return 'x';
+ case 'Y': return 'y';
+ case 'Z': return 'z';
+ default: return c;
+ }
+#endif
+}
+
+int
+c_toupper (int c)
+{
+#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+ return (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
+#else
+ switch (c)
+ {
+ case 'a': return 'A';
+ case 'b': return 'B';
+ case 'c': return 'C';
+ case 'd': return 'D';
+ case 'e': return 'E';
+ case 'f': return 'F';
+ case 'g': return 'G';
+ case 'h': return 'H';
+ case 'i': return 'I';
+ case 'j': return 'J';
+ case 'k': return 'K';
+ case 'l': return 'L';
+ case 'm': return 'M';
+ case 'n': return 'N';
+ case 'o': return 'O';
+ case 'p': return 'P';
+ case 'q': return 'Q';
+ case 'r': return 'R';
+ case 's': return 'S';
+ case 't': return 'T';
+ case 'u': return 'U';
+ case 'v': return 'V';
+ case 'w': return 'W';
+ case 'x': return 'X';
+ case 'y': return 'Y';
+ case 'z': return 'Z';
+ default: return c;
+ }
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/c-ctype.h b/contrib/tools/bison/gnulib/src/c-ctype.h
index ad589b5c20..3ebd375c96 100644
--- a/contrib/tools/bison/gnulib/src/c-ctype.h
+++ b/contrib/tools/bison/gnulib/src/c-ctype.h
@@ -1,295 +1,295 @@
-/* Character handling in C locale.
-
- These functions work like the corresponding functions in <ctype.h>,
- except that they have the C (POSIX) locale hardwired, whereas the
- <ctype.h> functions' behaviour depends on the current locale set via
- setlocale.
-
- Copyright (C) 2000-2003, 2006, 2008-2013 Free Software Foundation, Inc.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef C_CTYPE_H
-#define C_CTYPE_H
-
-#include <stdbool.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* The functions defined in this file assume the "C" locale and a character
- set without diacritics (ASCII-US or EBCDIC-US or something like that).
- Even if the "C" locale on a particular system is an extension of the ASCII
- character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
- is ISO-8859-1), the functions in this file recognize only the ASCII
- characters. */
-
-
-/* Check whether the ASCII optimizations apply. */
-
-/* ANSI C89 (and ISO C99 5.2.1.3 too) already guarantees that
- '0', '1', ..., '9' have consecutive integer values. */
-#define C_CTYPE_CONSECUTIVE_DIGITS 1
-
-#if ('A' <= 'Z') \
- && ('A' + 1 == 'B') && ('B' + 1 == 'C') && ('C' + 1 == 'D') \
- && ('D' + 1 == 'E') && ('E' + 1 == 'F') && ('F' + 1 == 'G') \
- && ('G' + 1 == 'H') && ('H' + 1 == 'I') && ('I' + 1 == 'J') \
- && ('J' + 1 == 'K') && ('K' + 1 == 'L') && ('L' + 1 == 'M') \
- && ('M' + 1 == 'N') && ('N' + 1 == 'O') && ('O' + 1 == 'P') \
- && ('P' + 1 == 'Q') && ('Q' + 1 == 'R') && ('R' + 1 == 'S') \
- && ('S' + 1 == 'T') && ('T' + 1 == 'U') && ('U' + 1 == 'V') \
- && ('V' + 1 == 'W') && ('W' + 1 == 'X') && ('X' + 1 == 'Y') \
- && ('Y' + 1 == 'Z')
-#define C_CTYPE_CONSECUTIVE_UPPERCASE 1
-#endif
-
-#if ('a' <= 'z') \
- && ('a' + 1 == 'b') && ('b' + 1 == 'c') && ('c' + 1 == 'd') \
- && ('d' + 1 == 'e') && ('e' + 1 == 'f') && ('f' + 1 == 'g') \
- && ('g' + 1 == 'h') && ('h' + 1 == 'i') && ('i' + 1 == 'j') \
- && ('j' + 1 == 'k') && ('k' + 1 == 'l') && ('l' + 1 == 'm') \
- && ('m' + 1 == 'n') && ('n' + 1 == 'o') && ('o' + 1 == 'p') \
- && ('p' + 1 == 'q') && ('q' + 1 == 'r') && ('r' + 1 == 's') \
- && ('s' + 1 == 't') && ('t' + 1 == 'u') && ('u' + 1 == 'v') \
- && ('v' + 1 == 'w') && ('w' + 1 == 'x') && ('x' + 1 == 'y') \
- && ('y' + 1 == 'z')
-#define C_CTYPE_CONSECUTIVE_LOWERCASE 1
-#endif
-
-#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
- && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
- && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
- && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
- && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
- && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
- && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
- && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
- && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
- && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
- && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
- && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
- && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
- && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
- && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
- && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
- && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
- && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
- && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
- && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
- && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
- && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
- && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
-/* The character set is ASCII or one of its variants or extensions, not EBCDIC.
- Testing the value of '\n' and '\r' is not relevant. */
-#define C_CTYPE_ASCII 1
-#endif
-
-
-/* Function declarations. */
-
-/* Unlike the functions in <ctype.h>, which require an argument in the range
- of the 'unsigned char' type, the functions here operate on values that are
- in the 'unsigned char' range or in the 'char' range. In other words,
- when you have a 'char' value, you need to cast it before using it as
- argument to a <ctype.h> function:
-
- const char *s = ...;
- if (isalpha ((unsigned char) *s)) ...
-
- but you don't need to cast it for the functions defined in this file:
-
- const char *s = ...;
- if (c_isalpha (*s)) ...
- */
-
-extern bool c_isascii (int c) _GL_ATTRIBUTE_CONST; /* not locale dependent */
-
-extern bool c_isalnum (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isalpha (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isblank (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_iscntrl (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isdigit (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_islower (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isgraph (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isprint (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_ispunct (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isspace (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isupper (int c) _GL_ATTRIBUTE_CONST;
-extern bool c_isxdigit (int c) _GL_ATTRIBUTE_CONST;
-
-extern int c_tolower (int c) _GL_ATTRIBUTE_CONST;
-extern int c_toupper (int c) _GL_ATTRIBUTE_CONST;
-
-
-#if (defined __GNUC__ && !defined __STRICT_ANSI__ && defined __OPTIMIZE__ \
- && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS)
-
-/* ASCII optimizations. */
-
-#undef c_isascii
-#define c_isascii(c) \
- ({ int __c = (c); \
- (__c >= 0x00 && __c <= 0x7f); \
- })
-
-#if C_CTYPE_CONSECUTIVE_DIGITS \
- && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-#if C_CTYPE_ASCII
-#undef c_isalnum
-#define c_isalnum(c) \
- ({ int __c = (c); \
- ((__c >= '0' && __c <= '9') \
- || ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z')); \
- })
-#else
-#undef c_isalnum
-#define c_isalnum(c) \
- ({ int __c = (c); \
- ((__c >= '0' && __c <= '9') \
- || (__c >= 'A' && __c <= 'Z') \
- || (__c >= 'a' && __c <= 'z')); \
- })
-#endif
-#endif
-
-#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-#if C_CTYPE_ASCII
-#undef c_isalpha
-#define c_isalpha(c) \
- ({ int __c = (c); \
- ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z'); \
- })
-#else
-#undef c_isalpha
-#define c_isalpha(c) \
- ({ int __c = (c); \
- ((__c >= 'A' && __c <= 'Z') || (__c >= 'a' && __c <= 'z')); \
- })
-#endif
-#endif
-
-#undef c_isblank
-#define c_isblank(c) \
- ({ int __c = (c); \
- (__c == ' ' || __c == '\t'); \
- })
-
-#if C_CTYPE_ASCII
-#undef c_iscntrl
-#define c_iscntrl(c) \
- ({ int __c = (c); \
- ((__c & ~0x1f) == 0 || __c == 0x7f); \
- })
-#endif
-
-#if C_CTYPE_CONSECUTIVE_DIGITS
-#undef c_isdigit
-#define c_isdigit(c) \
- ({ int __c = (c); \
- (__c >= '0' && __c <= '9'); \
- })
-#endif
-
-#if C_CTYPE_CONSECUTIVE_LOWERCASE
-#undef c_islower
-#define c_islower(c) \
- ({ int __c = (c); \
- (__c >= 'a' && __c <= 'z'); \
- })
-#endif
-
-#if C_CTYPE_ASCII
-#undef c_isgraph
-#define c_isgraph(c) \
- ({ int __c = (c); \
- (__c >= '!' && __c <= '~'); \
- })
-#endif
-
-#if C_CTYPE_ASCII
-#undef c_isprint
-#define c_isprint(c) \
- ({ int __c = (c); \
- (__c >= ' ' && __c <= '~'); \
- })
-#endif
-
-#if C_CTYPE_ASCII
-#undef c_ispunct
-#define c_ispunct(c) \
- ({ int _c = (c); \
- (c_isgraph (_c) && ! c_isalnum (_c)); \
- })
-#endif
-
-#undef c_isspace
-#define c_isspace(c) \
- ({ int __c = (c); \
- (__c == ' ' || __c == '\t' \
- || __c == '\n' || __c == '\v' || __c == '\f' || __c == '\r'); \
- })
-
-#if C_CTYPE_CONSECUTIVE_UPPERCASE
-#undef c_isupper
-#define c_isupper(c) \
- ({ int __c = (c); \
- (__c >= 'A' && __c <= 'Z'); \
- })
-#endif
-
-#if C_CTYPE_CONSECUTIVE_DIGITS \
- && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-#if C_CTYPE_ASCII
-#undef c_isxdigit
-#define c_isxdigit(c) \
- ({ int __c = (c); \
- ((__c >= '0' && __c <= '9') \
- || ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'F')); \
- })
-#else
-#undef c_isxdigit
-#define c_isxdigit(c) \
- ({ int __c = (c); \
- ((__c >= '0' && __c <= '9') \
- || (__c >= 'A' && __c <= 'F') \
- || (__c >= 'a' && __c <= 'f')); \
- })
-#endif
-#endif
-
-#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-#undef c_tolower
-#define c_tolower(c) \
- ({ int __c = (c); \
- (__c >= 'A' && __c <= 'Z' ? __c - 'A' + 'a' : __c); \
- })
-#undef c_toupper
-#define c_toupper(c) \
- ({ int __c = (c); \
- (__c >= 'a' && __c <= 'z' ? __c - 'a' + 'A' : __c); \
- })
-#endif
-
-#endif /* optimizing for speed */
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* C_CTYPE_H */
+/* Character handling in C locale.
+
+ These functions work like the corresponding functions in <ctype.h>,
+ except that they have the C (POSIX) locale hardwired, whereas the
+ <ctype.h> functions' behaviour depends on the current locale set via
+ setlocale.
+
+ Copyright (C) 2000-2003, 2006, 2008-2013 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef C_CTYPE_H
+#define C_CTYPE_H
+
+#include <stdbool.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* The functions defined in this file assume the "C" locale and a character
+ set without diacritics (ASCII-US or EBCDIC-US or something like that).
+ Even if the "C" locale on a particular system is an extension of the ASCII
+ character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
+ is ISO-8859-1), the functions in this file recognize only the ASCII
+ characters. */
+
+
+/* Check whether the ASCII optimizations apply. */
+
+/* ANSI C89 (and ISO C99 5.2.1.3 too) already guarantees that
+ '0', '1', ..., '9' have consecutive integer values. */
+#define C_CTYPE_CONSECUTIVE_DIGITS 1
+
+#if ('A' <= 'Z') \
+ && ('A' + 1 == 'B') && ('B' + 1 == 'C') && ('C' + 1 == 'D') \
+ && ('D' + 1 == 'E') && ('E' + 1 == 'F') && ('F' + 1 == 'G') \
+ && ('G' + 1 == 'H') && ('H' + 1 == 'I') && ('I' + 1 == 'J') \
+ && ('J' + 1 == 'K') && ('K' + 1 == 'L') && ('L' + 1 == 'M') \
+ && ('M' + 1 == 'N') && ('N' + 1 == 'O') && ('O' + 1 == 'P') \
+ && ('P' + 1 == 'Q') && ('Q' + 1 == 'R') && ('R' + 1 == 'S') \
+ && ('S' + 1 == 'T') && ('T' + 1 == 'U') && ('U' + 1 == 'V') \
+ && ('V' + 1 == 'W') && ('W' + 1 == 'X') && ('X' + 1 == 'Y') \
+ && ('Y' + 1 == 'Z')
+#define C_CTYPE_CONSECUTIVE_UPPERCASE 1
+#endif
+
+#if ('a' <= 'z') \
+ && ('a' + 1 == 'b') && ('b' + 1 == 'c') && ('c' + 1 == 'd') \
+ && ('d' + 1 == 'e') && ('e' + 1 == 'f') && ('f' + 1 == 'g') \
+ && ('g' + 1 == 'h') && ('h' + 1 == 'i') && ('i' + 1 == 'j') \
+ && ('j' + 1 == 'k') && ('k' + 1 == 'l') && ('l' + 1 == 'm') \
+ && ('m' + 1 == 'n') && ('n' + 1 == 'o') && ('o' + 1 == 'p') \
+ && ('p' + 1 == 'q') && ('q' + 1 == 'r') && ('r' + 1 == 's') \
+ && ('s' + 1 == 't') && ('t' + 1 == 'u') && ('u' + 1 == 'v') \
+ && ('v' + 1 == 'w') && ('w' + 1 == 'x') && ('x' + 1 == 'y') \
+ && ('y' + 1 == 'z')
+#define C_CTYPE_CONSECUTIVE_LOWERCASE 1
+#endif
+
+#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
+/* The character set is ASCII or one of its variants or extensions, not EBCDIC.
+ Testing the value of '\n' and '\r' is not relevant. */
+#define C_CTYPE_ASCII 1
+#endif
+
+
+/* Function declarations. */
+
+/* Unlike the functions in <ctype.h>, which require an argument in the range
+ of the 'unsigned char' type, the functions here operate on values that are
+ in the 'unsigned char' range or in the 'char' range. In other words,
+ when you have a 'char' value, you need to cast it before using it as
+ argument to a <ctype.h> function:
+
+ const char *s = ...;
+ if (isalpha ((unsigned char) *s)) ...
+
+ but you don't need to cast it for the functions defined in this file:
+
+ const char *s = ...;
+ if (c_isalpha (*s)) ...
+ */
+
+extern bool c_isascii (int c) _GL_ATTRIBUTE_CONST; /* not locale dependent */
+
+extern bool c_isalnum (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isalpha (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isblank (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_iscntrl (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isdigit (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_islower (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isgraph (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isprint (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_ispunct (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isspace (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isupper (int c) _GL_ATTRIBUTE_CONST;
+extern bool c_isxdigit (int c) _GL_ATTRIBUTE_CONST;
+
+extern int c_tolower (int c) _GL_ATTRIBUTE_CONST;
+extern int c_toupper (int c) _GL_ATTRIBUTE_CONST;
+
+
+#if (defined __GNUC__ && !defined __STRICT_ANSI__ && defined __OPTIMIZE__ \
+ && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS)
+
+/* ASCII optimizations. */
+
+#undef c_isascii
+#define c_isascii(c) \
+ ({ int __c = (c); \
+ (__c >= 0x00 && __c <= 0x7f); \
+ })
+
+#if C_CTYPE_CONSECUTIVE_DIGITS \
+ && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+#if C_CTYPE_ASCII
+#undef c_isalnum
+#define c_isalnum(c) \
+ ({ int __c = (c); \
+ ((__c >= '0' && __c <= '9') \
+ || ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z')); \
+ })
+#else
+#undef c_isalnum
+#define c_isalnum(c) \
+ ({ int __c = (c); \
+ ((__c >= '0' && __c <= '9') \
+ || (__c >= 'A' && __c <= 'Z') \
+ || (__c >= 'a' && __c <= 'z')); \
+ })
+#endif
+#endif
+
+#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+#if C_CTYPE_ASCII
+#undef c_isalpha
+#define c_isalpha(c) \
+ ({ int __c = (c); \
+ ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z'); \
+ })
+#else
+#undef c_isalpha
+#define c_isalpha(c) \
+ ({ int __c = (c); \
+ ((__c >= 'A' && __c <= 'Z') || (__c >= 'a' && __c <= 'z')); \
+ })
+#endif
+#endif
+
+#undef c_isblank
+#define c_isblank(c) \
+ ({ int __c = (c); \
+ (__c == ' ' || __c == '\t'); \
+ })
+
+#if C_CTYPE_ASCII
+#undef c_iscntrl
+#define c_iscntrl(c) \
+ ({ int __c = (c); \
+ ((__c & ~0x1f) == 0 || __c == 0x7f); \
+ })
+#endif
+
+#if C_CTYPE_CONSECUTIVE_DIGITS
+#undef c_isdigit
+#define c_isdigit(c) \
+ ({ int __c = (c); \
+ (__c >= '0' && __c <= '9'); \
+ })
+#endif
+
+#if C_CTYPE_CONSECUTIVE_LOWERCASE
+#undef c_islower
+#define c_islower(c) \
+ ({ int __c = (c); \
+ (__c >= 'a' && __c <= 'z'); \
+ })
+#endif
+
+#if C_CTYPE_ASCII
+#undef c_isgraph
+#define c_isgraph(c) \
+ ({ int __c = (c); \
+ (__c >= '!' && __c <= '~'); \
+ })
+#endif
+
+#if C_CTYPE_ASCII
+#undef c_isprint
+#define c_isprint(c) \
+ ({ int __c = (c); \
+ (__c >= ' ' && __c <= '~'); \
+ })
+#endif
+
+#if C_CTYPE_ASCII
+#undef c_ispunct
+#define c_ispunct(c) \
+ ({ int _c = (c); \
+ (c_isgraph (_c) && ! c_isalnum (_c)); \
+ })
+#endif
+
+#undef c_isspace
+#define c_isspace(c) \
+ ({ int __c = (c); \
+ (__c == ' ' || __c == '\t' \
+ || __c == '\n' || __c == '\v' || __c == '\f' || __c == '\r'); \
+ })
+
+#if C_CTYPE_CONSECUTIVE_UPPERCASE
+#undef c_isupper
+#define c_isupper(c) \
+ ({ int __c = (c); \
+ (__c >= 'A' && __c <= 'Z'); \
+ })
+#endif
+
+#if C_CTYPE_CONSECUTIVE_DIGITS \
+ && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+#if C_CTYPE_ASCII
+#undef c_isxdigit
+#define c_isxdigit(c) \
+ ({ int __c = (c); \
+ ((__c >= '0' && __c <= '9') \
+ || ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'F')); \
+ })
+#else
+#undef c_isxdigit
+#define c_isxdigit(c) \
+ ({ int __c = (c); \
+ ((__c >= '0' && __c <= '9') \
+ || (__c >= 'A' && __c <= 'F') \
+ || (__c >= 'a' && __c <= 'f')); \
+ })
+#endif
+#endif
+
+#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+#undef c_tolower
+#define c_tolower(c) \
+ ({ int __c = (c); \
+ (__c >= 'A' && __c <= 'Z' ? __c - 'A' + 'a' : __c); \
+ })
+#undef c_toupper
+#define c_toupper(c) \
+ ({ int __c = (c); \
+ (__c >= 'a' && __c <= 'z' ? __c - 'a' + 'A' : __c); \
+ })
+#endif
+
+#endif /* optimizing for speed */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* C_CTYPE_H */
diff --git a/contrib/tools/bison/gnulib/src/c-stack.c b/contrib/tools/bison/gnulib/src/c-stack.c
index b146cf254e..78bdb84bdc 100644
--- a/contrib/tools/bison/gnulib/src/c-stack.c
+++ b/contrib/tools/bison/gnulib/src/c-stack.c
@@ -1,333 +1,333 @@
-/* Stack overflow handling.
-
- Copyright (C) 2002, 2004, 2006, 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-/* NOTES:
-
- A program that uses alloca, dynamic arrays, or large local
- variables may extend the stack by more than a page at a time. If
- so, when the stack overflows the operating system may not detect
- the overflow until the program uses the array, and this module may
- incorrectly report a program error instead of a stack overflow.
-
- To avoid this problem, allocate only small objects on the stack; a
- program should be OK if it limits single allocations to a page or
- less. Allocate larger arrays in static storage, or on the heap
- (e.g., with malloc). Yes, this is a pain, but we don't know of any
- better solution that is portable.
-
- No attempt has been made to deal with multithreaded applications. */
-
-#include <config.h>
-
-#ifndef __attribute__
-# if __GNUC__ < 3
-# define __attribute__(x)
-# endif
-#endif
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
-#include <errno.h>
-
-#include <signal.h>
-#if ! HAVE_STACK_T && ! defined stack_t
-typedef struct sigaltstack stack_t;
-#endif
-#ifndef SIGSTKSZ
-# define SIGSTKSZ 16384
-#elif HAVE_LIBSIGSEGV && SIGSTKSZ < 16384
-/* libsigsegv 2.6 through 2.8 have a bug where some architectures use
- more than the Linux default of an 8k alternate stack when deciding
- if a fault was caused by stack overflow. */
-# undef SIGSTKSZ
-# define SIGSTKSZ 16384
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-/* Posix 2001 declares ucontext_t in <ucontext.h>, Posix 200x in
- <signal.h>. */
-#if HAVE_UCONTEXT_H
-# include <ucontext.h>
-#endif
-
-#include <unistd.h>
-
-#if HAVE_LIBSIGSEGV
-# include <sigsegv.h>
-#endif
-
-#include "c-stack.h"
-#include "exitfail.h"
-#include "ignore-value.h"
-
-#if defined SA_ONSTACK && defined SA_SIGINFO
-# define SIGINFO_WORKS 1
-#else
-# define SIGINFO_WORKS 0
-# ifndef SA_ONSTACK
-# define SA_ONSTACK 0
-# endif
-#endif
-
-extern char *program_name;
-
-/* The user-specified action to take when a SEGV-related program error
- or stack overflow occurs. */
-static void (* volatile segv_action) (int);
-
-/* Translated messages for program errors and stack overflow. Do not
- translate them in the signal handler, since gettext is not
- async-signal-safe. */
-static char const * volatile program_error_message;
-static char const * volatile stack_overflow_message;
-
-/* Output an error message, then exit with status EXIT_FAILURE if it
- appears to have been a stack overflow, or with a core dump
- otherwise. This function is async-signal-safe. */
-
-static _Noreturn void
-die (int signo)
-{
- char const *message;
-#if !SIGINFO_WORKS && !HAVE_LIBSIGSEGV
- /* We can't easily determine whether it is a stack overflow; so
- assume that the rest of our program is perfect (!) and that
- this segmentation violation is a stack overflow. */
- signo = 0;
-#endif /* !SIGINFO_WORKS && !HAVE_LIBSIGSEGV */
- segv_action (signo);
- message = signo ? program_error_message : stack_overflow_message;
- ignore_value (write (STDERR_FILENO, program_name, strlen (program_name)));
- ignore_value (write (STDERR_FILENO, ": ", 2));
- ignore_value (write (STDERR_FILENO, message, strlen (message)));
- ignore_value (write (STDERR_FILENO, "\n", 1));
- if (! signo)
- _exit (exit_failure);
- raise (signo);
- abort ();
-}
-
-#if (HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK \
- && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV
-
-/* Storage for the alternate signal stack. */
-static union
-{
- char buffer[SIGSTKSZ];
-
- /* These other members are for proper alignment. There's no
- standard way to guarantee stack alignment, but this seems enough
- in practice. */
- long double ld;
- long l;
- void *p;
-} alternate_signal_stack;
-
-static void
-null_action (int signo __attribute__ ((unused)))
-{
-}
-
-#endif /* SIGALTSTACK || LIBSIGSEGV */
-
-/* Only use libsigsegv if we need it; platforms like Solaris can
- detect stack overflow without the overhead of an external
- library. */
-#if HAVE_LIBSIGSEGV && ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC
-
-/* Nonzero if general segv handler could not be installed. */
-static volatile int segv_handler_missing;
-
-/* Handle a segmentation violation and exit if it cannot be stack
- overflow. This function is async-signal-safe. */
-
-static int segv_handler (void *address __attribute__ ((unused)),
- int serious)
-{
-# if DEBUG
- {
- char buf[1024];
- sprintf (buf, "segv_handler serious=%d\n", serious);
- write (STDERR_FILENO, buf, strlen (buf));
- }
-# endif
-
- /* If this fault is not serious, return 0 to let the stack overflow
- handler take a shot at it. */
- if (!serious)
- return 0;
- die (SIGSEGV);
-}
-
-/* Handle a segmentation violation that is likely to be a stack
- overflow and exit. This function is async-signal-safe. */
-
-static _Noreturn void
-overflow_handler (int emergency,
- stackoverflow_context_t context __attribute__ ((unused)))
-{
-# if DEBUG
- {
- char buf[1024];
- sprintf (buf, "overflow_handler emergency=%d segv_handler_missing=%d\n",
- emergency, segv_handler_missing);
- write (STDERR_FILENO, buf, strlen (buf));
- }
-# endif
-
- die ((!emergency || segv_handler_missing) ? 0 : SIGSEGV);
-}
-
-int
-c_stack_action (void (*action) (int))
-{
- segv_action = action ? action : null_action;
- program_error_message = _("program error");
- stack_overflow_message = _("stack overflow");
-
- /* Always install the overflow handler. */
- if (stackoverflow_install_handler (overflow_handler,
- alternate_signal_stack.buffer,
- sizeof alternate_signal_stack.buffer))
- {
- errno = ENOTSUP;
- return -1;
- }
- /* Try installing a general handler; if it fails, then treat all
- segv as stack overflow. */
- segv_handler_missing = sigsegv_install_handler (segv_handler);
- return 0;
-}
-
-#elif HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK && HAVE_STACK_OVERFLOW_HANDLING
-
-# if SIGINFO_WORKS
-
-/* Handle a segmentation violation and exit. This function is
- async-signal-safe. */
-
-static _Noreturn void
-segv_handler (int signo, siginfo_t *info,
- void *context __attribute__ ((unused)))
-{
- /* Clear SIGNO if it seems to have been a stack overflow. */
-# if ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC
- /* We can't easily determine whether it is a stack overflow; so
- assume that the rest of our program is perfect (!) and that
- this segmentation violation is a stack overflow.
-
- Note that although both Linux and Solaris provide
- sigaltstack, SA_ONSTACK, and SA_SIGINFO, currently only
- Solaris satisfies the XSI heuristic. This is because
- Solaris populates uc_stack with the details of the
- interrupted stack, while Linux populates it with the details
- of the current stack. */
- signo = 0;
-# else
- if (0 < info->si_code)
- {
- /* If the faulting address is within the stack, or within one
- page of the stack, assume that it is a stack overflow. */
- ucontext_t const *user_context = context;
- char const *stack_base = user_context->uc_stack.ss_sp;
- size_t stack_size = user_context->uc_stack.ss_size;
- char const *faulting_address = info->si_addr;
- size_t page_size = sysconf (_SC_PAGESIZE);
- size_t s = faulting_address - stack_base + page_size;
- if (s < stack_size + 2 * page_size)
- signo = 0;
-
-# if DEBUG
- {
- char buf[1024];
- sprintf (buf,
- "segv_handler fault=%p base=%p size=%lx page=%lx signo=%d\n",
- faulting_address, stack_base, (unsigned long) stack_size,
- (unsigned long) page_size, signo);
- write (STDERR_FILENO, buf, strlen (buf));
- }
-# endif
- }
-# endif
-
- die (signo);
-}
-# endif
-
-int
-c_stack_action (void (*action) (int))
-{
- int r;
- stack_t st;
- struct sigaction act;
- st.ss_flags = 0;
-# if SIGALTSTACK_SS_REVERSED
- /* Irix mistakenly treats ss_sp as the upper bound, rather than
- lower bound, of the alternate stack. */
- st.ss_sp = alternate_signal_stack.buffer + SIGSTKSZ - sizeof (void *);
- st.ss_size = sizeof alternate_signal_stack.buffer - sizeof (void *);
-# else
- st.ss_sp = alternate_signal_stack.buffer;
- st.ss_size = sizeof alternate_signal_stack.buffer;
-# endif
- r = sigaltstack (&st, NULL);
- if (r != 0)
- return r;
-
- segv_action = action ? action : null_action;
- program_error_message = _("program error");
- stack_overflow_message = _("stack overflow");
-
- sigemptyset (&act.sa_mask);
-
-# if SIGINFO_WORKS
- /* POSIX 1003.1-2001 says SA_RESETHAND implies SA_NODEFER, but
- this is not true on Solaris 8 at least. It doesn't hurt to use
- SA_NODEFER here, so leave it in. */
- act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
- act.sa_sigaction = segv_handler;
-# else
- act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
- act.sa_handler = die;
-# endif
-
-# if FAULT_YIELDS_SIGBUS
- if (sigaction (SIGBUS, &act, NULL) < 0)
- return -1;
-# endif
- return sigaction (SIGSEGV, &act, NULL);
-}
-
-#else /* ! ((HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK
- && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV) */
-
-int
-c_stack_action (void (*action) (int) __attribute__ ((unused)))
-{
+/* Stack overflow handling.
+
+ Copyright (C) 2002, 2004, 2006, 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+/* NOTES:
+
+ A program that uses alloca, dynamic arrays, or large local
+ variables may extend the stack by more than a page at a time. If
+ so, when the stack overflows the operating system may not detect
+ the overflow until the program uses the array, and this module may
+ incorrectly report a program error instead of a stack overflow.
+
+ To avoid this problem, allocate only small objects on the stack; a
+ program should be OK if it limits single allocations to a page or
+ less. Allocate larger arrays in static storage, or on the heap
+ (e.g., with malloc). Yes, this is a pain, but we don't know of any
+ better solution that is portable.
+
+ No attempt has been made to deal with multithreaded applications. */
+
+#include <config.h>
+
+#ifndef __attribute__
+# if __GNUC__ < 3
+# define __attribute__(x)
+# endif
+#endif
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+#include <errno.h>
+
+#include <signal.h>
+#if ! HAVE_STACK_T && ! defined stack_t
+typedef struct sigaltstack stack_t;
+#endif
+#ifndef SIGSTKSZ
+# define SIGSTKSZ 16384
+#elif HAVE_LIBSIGSEGV && SIGSTKSZ < 16384
+/* libsigsegv 2.6 through 2.8 have a bug where some architectures use
+ more than the Linux default of an 8k alternate stack when deciding
+ if a fault was caused by stack overflow. */
+# undef SIGSTKSZ
+# define SIGSTKSZ 16384
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+/* Posix 2001 declares ucontext_t in <ucontext.h>, Posix 200x in
+ <signal.h>. */
+#if HAVE_UCONTEXT_H
+# include <ucontext.h>
+#endif
+
+#include <unistd.h>
+
+#if HAVE_LIBSIGSEGV
+# include <sigsegv.h>
+#endif
+
+#include "c-stack.h"
+#include "exitfail.h"
+#include "ignore-value.h"
+
+#if defined SA_ONSTACK && defined SA_SIGINFO
+# define SIGINFO_WORKS 1
+#else
+# define SIGINFO_WORKS 0
+# ifndef SA_ONSTACK
+# define SA_ONSTACK 0
+# endif
+#endif
+
+extern char *program_name;
+
+/* The user-specified action to take when a SEGV-related program error
+ or stack overflow occurs. */
+static void (* volatile segv_action) (int);
+
+/* Translated messages for program errors and stack overflow. Do not
+ translate them in the signal handler, since gettext is not
+ async-signal-safe. */
+static char const * volatile program_error_message;
+static char const * volatile stack_overflow_message;
+
+/* Output an error message, then exit with status EXIT_FAILURE if it
+ appears to have been a stack overflow, or with a core dump
+ otherwise. This function is async-signal-safe. */
+
+static _Noreturn void
+die (int signo)
+{
+ char const *message;
+#if !SIGINFO_WORKS && !HAVE_LIBSIGSEGV
+ /* We can't easily determine whether it is a stack overflow; so
+ assume that the rest of our program is perfect (!) and that
+ this segmentation violation is a stack overflow. */
+ signo = 0;
+#endif /* !SIGINFO_WORKS && !HAVE_LIBSIGSEGV */
+ segv_action (signo);
+ message = signo ? program_error_message : stack_overflow_message;
+ ignore_value (write (STDERR_FILENO, program_name, strlen (program_name)));
+ ignore_value (write (STDERR_FILENO, ": ", 2));
+ ignore_value (write (STDERR_FILENO, message, strlen (message)));
+ ignore_value (write (STDERR_FILENO, "\n", 1));
+ if (! signo)
+ _exit (exit_failure);
+ raise (signo);
+ abort ();
+}
+
+#if (HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK \
+ && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV
+
+/* Storage for the alternate signal stack. */
+static union
+{
+ char buffer[SIGSTKSZ];
+
+ /* These other members are for proper alignment. There's no
+ standard way to guarantee stack alignment, but this seems enough
+ in practice. */
+ long double ld;
+ long l;
+ void *p;
+} alternate_signal_stack;
+
+static void
+null_action (int signo __attribute__ ((unused)))
+{
+}
+
+#endif /* SIGALTSTACK || LIBSIGSEGV */
+
+/* Only use libsigsegv if we need it; platforms like Solaris can
+ detect stack overflow without the overhead of an external
+ library. */
+#if HAVE_LIBSIGSEGV && ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC
+
+/* Nonzero if general segv handler could not be installed. */
+static volatile int segv_handler_missing;
+
+/* Handle a segmentation violation and exit if it cannot be stack
+ overflow. This function is async-signal-safe. */
+
+static int segv_handler (void *address __attribute__ ((unused)),
+ int serious)
+{
+# if DEBUG
+ {
+ char buf[1024];
+ sprintf (buf, "segv_handler serious=%d\n", serious);
+ write (STDERR_FILENO, buf, strlen (buf));
+ }
+# endif
+
+ /* If this fault is not serious, return 0 to let the stack overflow
+ handler take a shot at it. */
+ if (!serious)
+ return 0;
+ die (SIGSEGV);
+}
+
+/* Handle a segmentation violation that is likely to be a stack
+ overflow and exit. This function is async-signal-safe. */
+
+static _Noreturn void
+overflow_handler (int emergency,
+ stackoverflow_context_t context __attribute__ ((unused)))
+{
+# if DEBUG
+ {
+ char buf[1024];
+ sprintf (buf, "overflow_handler emergency=%d segv_handler_missing=%d\n",
+ emergency, segv_handler_missing);
+ write (STDERR_FILENO, buf, strlen (buf));
+ }
+# endif
+
+ die ((!emergency || segv_handler_missing) ? 0 : SIGSEGV);
+}
+
+int
+c_stack_action (void (*action) (int))
+{
+ segv_action = action ? action : null_action;
+ program_error_message = _("program error");
+ stack_overflow_message = _("stack overflow");
+
+ /* Always install the overflow handler. */
+ if (stackoverflow_install_handler (overflow_handler,
+ alternate_signal_stack.buffer,
+ sizeof alternate_signal_stack.buffer))
+ {
+ errno = ENOTSUP;
+ return -1;
+ }
+ /* Try installing a general handler; if it fails, then treat all
+ segv as stack overflow. */
+ segv_handler_missing = sigsegv_install_handler (segv_handler);
+ return 0;
+}
+
+#elif HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK && HAVE_STACK_OVERFLOW_HANDLING
+
+# if SIGINFO_WORKS
+
+/* Handle a segmentation violation and exit. This function is
+ async-signal-safe. */
+
+static _Noreturn void
+segv_handler (int signo, siginfo_t *info,
+ void *context __attribute__ ((unused)))
+{
+ /* Clear SIGNO if it seems to have been a stack overflow. */
+# if ! HAVE_XSI_STACK_OVERFLOW_HEURISTIC
+ /* We can't easily determine whether it is a stack overflow; so
+ assume that the rest of our program is perfect (!) and that
+ this segmentation violation is a stack overflow.
+
+ Note that although both Linux and Solaris provide
+ sigaltstack, SA_ONSTACK, and SA_SIGINFO, currently only
+ Solaris satisfies the XSI heuristic. This is because
+ Solaris populates uc_stack with the details of the
+ interrupted stack, while Linux populates it with the details
+ of the current stack. */
+ signo = 0;
+# else
+ if (0 < info->si_code)
+ {
+ /* If the faulting address is within the stack, or within one
+ page of the stack, assume that it is a stack overflow. */
+ ucontext_t const *user_context = context;
+ char const *stack_base = user_context->uc_stack.ss_sp;
+ size_t stack_size = user_context->uc_stack.ss_size;
+ char const *faulting_address = info->si_addr;
+ size_t page_size = sysconf (_SC_PAGESIZE);
+ size_t s = faulting_address - stack_base + page_size;
+ if (s < stack_size + 2 * page_size)
+ signo = 0;
+
+# if DEBUG
+ {
+ char buf[1024];
+ sprintf (buf,
+ "segv_handler fault=%p base=%p size=%lx page=%lx signo=%d\n",
+ faulting_address, stack_base, (unsigned long) stack_size,
+ (unsigned long) page_size, signo);
+ write (STDERR_FILENO, buf, strlen (buf));
+ }
+# endif
+ }
+# endif
+
+ die (signo);
+}
+# endif
+
+int
+c_stack_action (void (*action) (int))
+{
+ int r;
+ stack_t st;
+ struct sigaction act;
+ st.ss_flags = 0;
+# if SIGALTSTACK_SS_REVERSED
+ /* Irix mistakenly treats ss_sp as the upper bound, rather than
+ lower bound, of the alternate stack. */
+ st.ss_sp = alternate_signal_stack.buffer + SIGSTKSZ - sizeof (void *);
+ st.ss_size = sizeof alternate_signal_stack.buffer - sizeof (void *);
+# else
+ st.ss_sp = alternate_signal_stack.buffer;
+ st.ss_size = sizeof alternate_signal_stack.buffer;
+# endif
+ r = sigaltstack (&st, NULL);
+ if (r != 0)
+ return r;
+
+ segv_action = action ? action : null_action;
+ program_error_message = _("program error");
+ stack_overflow_message = _("stack overflow");
+
+ sigemptyset (&act.sa_mask);
+
+# if SIGINFO_WORKS
+ /* POSIX 1003.1-2001 says SA_RESETHAND implies SA_NODEFER, but
+ this is not true on Solaris 8 at least. It doesn't hurt to use
+ SA_NODEFER here, so leave it in. */
+ act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
+ act.sa_sigaction = segv_handler;
+# else
+ act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
+ act.sa_handler = die;
+# endif
+
+# if FAULT_YIELDS_SIGBUS
+ if (sigaction (SIGBUS, &act, NULL) < 0)
+ return -1;
+# endif
+ return sigaction (SIGSEGV, &act, NULL);
+}
+
+#else /* ! ((HAVE_SIGALTSTACK && HAVE_DECL_SIGALTSTACK
+ && HAVE_STACK_OVERFLOW_HANDLING) || HAVE_LIBSIGSEGV) */
+
+int
+c_stack_action (void (*action) (int) __attribute__ ((unused)))
+{
#if (defined _MSC_VER) && (_MSC_VER < 1800)
#else
- errno = ENOTSUP;
-#endif
- return -1;
-}
-
+ errno = ENOTSUP;
#endif
+ return -1;
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/c-stack.h b/contrib/tools/bison/gnulib/src/c-stack.h
index 2e61bdf01d..4325549f98 100644
--- a/contrib/tools/bison/gnulib/src/c-stack.h
+++ b/contrib/tools/bison/gnulib/src/c-stack.h
@@ -1,44 +1,44 @@
-/* Stack overflow handling.
-
- Copyright (C) 2002, 2004, 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/* Set up ACTION so that it is invoked on C stack overflow and on other,
- stack-unrelated, segmentation violation.
- Return -1 (setting errno) if this cannot be done.
-
- When a stack overflow or segmentation violation occurs:
- 1) ACTION is called. It is passed an argument equal to
- - 0, for a stack overflow,
- - SIGSEGV, for a segmentation violation that does not appear related
- to stack overflow.
- On many platforms the two cases are hard to distinguish; when in doubt,
- zero is passed.
- 2) If ACTION returns, a message is written to standard error, and the
- program is terminated: in the case of stack overflow, with exit code
- exit_failure (see "exitfail.h"), otherwise through a signal SIGSEGV.
-
- A null ACTION acts like an action that does nothing.
-
- ACTION must be async-signal-safe. ACTION together with its callees
- must not require more than SIGSTKSZ bytes of stack space. Also,
- ACTION should not call longjmp, because this implementation does
- not guarantee that it is safe to return to the original stack.
-
- This function may install a handler for the SIGSEGV signal or for the SIGBUS
- signal or exercise other system dependent exception handling APIs. */
-
-extern int c_stack_action (void (* /*action*/) (int));
+/* Stack overflow handling.
+
+ Copyright (C) 2002, 2004, 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+/* Set up ACTION so that it is invoked on C stack overflow and on other,
+ stack-unrelated, segmentation violation.
+ Return -1 (setting errno) if this cannot be done.
+
+ When a stack overflow or segmentation violation occurs:
+ 1) ACTION is called. It is passed an argument equal to
+ - 0, for a stack overflow,
+ - SIGSEGV, for a segmentation violation that does not appear related
+ to stack overflow.
+ On many platforms the two cases are hard to distinguish; when in doubt,
+ zero is passed.
+ 2) If ACTION returns, a message is written to standard error, and the
+ program is terminated: in the case of stack overflow, with exit code
+ exit_failure (see "exitfail.h"), otherwise through a signal SIGSEGV.
+
+ A null ACTION acts like an action that does nothing.
+
+ ACTION must be async-signal-safe. ACTION together with its callees
+ must not require more than SIGSTKSZ bytes of stack space. Also,
+ ACTION should not call longjmp, because this implementation does
+ not guarantee that it is safe to return to the original stack.
+
+ This function may install a handler for the SIGSEGV signal or for the SIGBUS
+ signal or exercise other system dependent exception handling APIs. */
+
+extern int c_stack_action (void (* /*action*/) (int));
diff --git a/contrib/tools/bison/gnulib/src/c-strcase.h b/contrib/tools/bison/gnulib/src/c-strcase.h
index 49e1bb03dd..d2a14fb14a 100644
--- a/contrib/tools/bison/gnulib/src/c-strcase.h
+++ b/contrib/tools/bison/gnulib/src/c-strcase.h
@@ -1,56 +1,56 @@
-/* Case-insensitive string comparison functions in C locale.
- Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef C_STRCASE_H
-#define C_STRCASE_H
-
-#include <stddef.h>
-
-
-/* The functions defined in this file assume the "C" locale and a character
- set without diacritics (ASCII-US or EBCDIC-US or something like that).
- Even if the "C" locale on a particular system is an extension of the ASCII
- character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
- is ISO-8859-1), the functions in this file recognize only the ASCII
- characters. More precisely, one of the string arguments must be an ASCII
- string; the other one can also contain non-ASCII characters (but then
- the comparison result will be nonzero). */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
- greater than zero if S1 is lexicographically less than, equal to or greater
- than S2. */
-extern int c_strcasecmp (const char *s1, const char *s2) _GL_ATTRIBUTE_PURE;
-
-/* Compare no more than N characters of strings S1 and S2, ignoring case,
- returning less than, equal to or greater than zero if S1 is
- lexicographically less than, equal to or greater than S2. */
-extern int c_strncasecmp (const char *s1, const char *s2, size_t n)
- _GL_ATTRIBUTE_PURE;
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* C_STRCASE_H */
+/* Case-insensitive string comparison functions in C locale.
+ Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef C_STRCASE_H
+#define C_STRCASE_H
+
+#include <stddef.h>
+
+
+/* The functions defined in this file assume the "C" locale and a character
+ set without diacritics (ASCII-US or EBCDIC-US or something like that).
+ Even if the "C" locale on a particular system is an extension of the ASCII
+ character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
+ is ISO-8859-1), the functions in this file recognize only the ASCII
+ characters. More precisely, one of the string arguments must be an ASCII
+ string; the other one can also contain non-ASCII characters (but then
+ the comparison result will be nonzero). */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
+ greater than zero if S1 is lexicographically less than, equal to or greater
+ than S2. */
+extern int c_strcasecmp (const char *s1, const char *s2) _GL_ATTRIBUTE_PURE;
+
+/* Compare no more than N characters of strings S1 and S2, ignoring case,
+ returning less than, equal to or greater than zero if S1 is
+ lexicographically less than, equal to or greater than S2. */
+extern int c_strncasecmp (const char *s1, const char *s2, size_t n)
+ _GL_ATTRIBUTE_PURE;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* C_STRCASE_H */
diff --git a/contrib/tools/bison/gnulib/src/c-strcasecmp.c b/contrib/tools/bison/gnulib/src/c-strcasecmp.c
index cd4e4d49cb..70e902f0e2 100644
--- a/contrib/tools/bison/gnulib/src/c-strcasecmp.c
+++ b/contrib/tools/bison/gnulib/src/c-strcasecmp.c
@@ -1,56 +1,56 @@
-/* c-strcasecmp.c -- case insensitive string comparator in C locale
- Copyright (C) 1998-1999, 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "c-strcase.h"
-
-#include <limits.h>
-
-#include "c-ctype.h"
-
-int
-c_strcasecmp (const char *s1, const char *s2)
-{
+/* c-strcasecmp.c -- case insensitive string comparator in C locale
+ Copyright (C) 1998-1999, 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "c-strcase.h"
+
+#include <limits.h>
+
+#include "c-ctype.h"
+
+int
+c_strcasecmp (const char *s1, const char *s2)
+{
const unsigned char *p1 = (const unsigned char *) s1;
const unsigned char *p2 = (const unsigned char *) s2;
- unsigned char c1, c2;
-
- if (p1 == p2)
- return 0;
-
- do
- {
- c1 = c_tolower (*p1);
- c2 = c_tolower (*p2);
-
- if (c1 == '\0')
- break;
-
- ++p1;
- ++p2;
- }
- while (c1 == c2);
-
- if (UCHAR_MAX <= INT_MAX)
- return c1 - c2;
- else
- /* On machines where 'char' and 'int' are types of the same size, the
- difference of two 'unsigned char' values - including the sign bit -
- doesn't fit in an 'int'. */
- return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
-}
+ unsigned char c1, c2;
+
+ if (p1 == p2)
+ return 0;
+
+ do
+ {
+ c1 = c_tolower (*p1);
+ c2 = c_tolower (*p2);
+
+ if (c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ }
+ while (c1 == c2);
+
+ if (UCHAR_MAX <= INT_MAX)
+ return c1 - c2;
+ else
+ /* On machines where 'char' and 'int' are types of the same size, the
+ difference of two 'unsigned char' values - including the sign bit -
+ doesn't fit in an 'int'. */
+ return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
+}
diff --git a/contrib/tools/bison/gnulib/src/c-strcaseeq.h b/contrib/tools/bison/gnulib/src/c-strcaseeq.h
index afdea26ba9..c8f983ce71 100644
--- a/contrib/tools/bison/gnulib/src/c-strcaseeq.h
+++ b/contrib/tools/bison/gnulib/src/c-strcaseeq.h
@@ -1,184 +1,184 @@
-/* Optimized case-insensitive string comparison in C locale.
- Copyright (C) 2001-2002, 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>. */
-
-#include "c-strcase.h"
-#include "c-ctype.h"
-
-/* STRCASEEQ allows to optimize string comparison with a small literal string.
- STRCASEEQ (s, "UTF-8", 'U','T','F','-','8',0,0,0,0)
- is semantically equivalent to
- c_strcasecmp (s, "UTF-8") == 0
- just faster. */
-
-/* Help GCC to generate good code for string comparisons with
- immediate strings. */
-#if defined (__GNUC__) && defined (__OPTIMIZE__)
-
-/* Case insensitive comparison of ASCII characters. */
-# if C_CTYPE_ASCII
-# define CASEEQ(other,upper) \
- (c_isupper (upper) ? ((other) & ~0x20) == (upper) : (other) == (upper))
-# elif C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
-# define CASEEQ(other,upper) \
- (c_isupper (upper) ? (other) == (upper) || (other) == (upper) - 'A' + 'a' : (other) == (upper))
-# else
-# define CASEEQ(other,upper) \
- (c_toupper (other) == (upper))
-# endif
-
-static inline int
-strcaseeq9 (const char *s1, const char *s2)
-{
- return c_strcasecmp (s1 + 9, s2 + 9) == 0;
-}
-
-static inline int
-strcaseeq8 (const char *s1, const char *s2, char s28)
-{
- if (CASEEQ (s1[8], s28))
- {
- if (s28 == 0)
- return 1;
- else
- return strcaseeq9 (s1, s2);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq7 (const char *s1, const char *s2, char s27, char s28)
-{
- if (CASEEQ (s1[7], s27))
- {
- if (s27 == 0)
- return 1;
- else
- return strcaseeq8 (s1, s2, s28);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq6 (const char *s1, const char *s2, char s26, char s27, char s28)
-{
- if (CASEEQ (s1[6], s26))
- {
- if (s26 == 0)
- return 1;
- else
- return strcaseeq7 (s1, s2, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
-{
- if (CASEEQ (s1[5], s25))
- {
- if (s25 == 0)
- return 1;
- else
- return strcaseeq6 (s1, s2, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
-{
- if (CASEEQ (s1[4], s24))
- {
- if (s24 == 0)
- return 1;
- else
- return strcaseeq5 (s1, s2, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (CASEEQ (s1[3], s23))
- {
- if (s23 == 0)
- return 1;
- else
- return strcaseeq4 (s1, s2, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (CASEEQ (s1[2], s22))
- {
- if (s22 == 0)
- return 1;
- else
- return strcaseeq3 (s1, s2, s23, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (CASEEQ (s1[1], s21))
- {
- if (s21 == 0)
- return 1;
- else
- return strcaseeq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-strcaseeq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (CASEEQ (s1[0], s20))
- {
- if (s20 == 0)
- return 1;
- else
- return strcaseeq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-#define STRCASEEQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
- strcaseeq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
-
-#else
-
-#define STRCASEEQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
- (c_strcasecmp (s1, s2) == 0)
-
-#endif
+/* Optimized case-insensitive string comparison in C locale.
+ Copyright (C) 2001-2002, 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>. */
+
+#include "c-strcase.h"
+#include "c-ctype.h"
+
+/* STRCASEEQ allows to optimize string comparison with a small literal string.
+ STRCASEEQ (s, "UTF-8", 'U','T','F','-','8',0,0,0,0)
+ is semantically equivalent to
+ c_strcasecmp (s, "UTF-8") == 0
+ just faster. */
+
+/* Help GCC to generate good code for string comparisons with
+ immediate strings. */
+#if defined (__GNUC__) && defined (__OPTIMIZE__)
+
+/* Case insensitive comparison of ASCII characters. */
+# if C_CTYPE_ASCII
+# define CASEEQ(other,upper) \
+ (c_isupper (upper) ? ((other) & ~0x20) == (upper) : (other) == (upper))
+# elif C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
+# define CASEEQ(other,upper) \
+ (c_isupper (upper) ? (other) == (upper) || (other) == (upper) - 'A' + 'a' : (other) == (upper))
+# else
+# define CASEEQ(other,upper) \
+ (c_toupper (other) == (upper))
+# endif
+
+static inline int
+strcaseeq9 (const char *s1, const char *s2)
+{
+ return c_strcasecmp (s1 + 9, s2 + 9) == 0;
+}
+
+static inline int
+strcaseeq8 (const char *s1, const char *s2, char s28)
+{
+ if (CASEEQ (s1[8], s28))
+ {
+ if (s28 == 0)
+ return 1;
+ else
+ return strcaseeq9 (s1, s2);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq7 (const char *s1, const char *s2, char s27, char s28)
+{
+ if (CASEEQ (s1[7], s27))
+ {
+ if (s27 == 0)
+ return 1;
+ else
+ return strcaseeq8 (s1, s2, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq6 (const char *s1, const char *s2, char s26, char s27, char s28)
+{
+ if (CASEEQ (s1[6], s26))
+ {
+ if (s26 == 0)
+ return 1;
+ else
+ return strcaseeq7 (s1, s2, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
+{
+ if (CASEEQ (s1[5], s25))
+ {
+ if (s25 == 0)
+ return 1;
+ else
+ return strcaseeq6 (s1, s2, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
+{
+ if (CASEEQ (s1[4], s24))
+ {
+ if (s24 == 0)
+ return 1;
+ else
+ return strcaseeq5 (s1, s2, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (CASEEQ (s1[3], s23))
+ {
+ if (s23 == 0)
+ return 1;
+ else
+ return strcaseeq4 (s1, s2, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (CASEEQ (s1[2], s22))
+ {
+ if (s22 == 0)
+ return 1;
+ else
+ return strcaseeq3 (s1, s2, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (CASEEQ (s1[1], s21))
+ {
+ if (s21 == 0)
+ return 1;
+ else
+ return strcaseeq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+strcaseeq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (CASEEQ (s1[0], s20))
+ {
+ if (s20 == 0)
+ return 1;
+ else
+ return strcaseeq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+#define STRCASEEQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+ strcaseeq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
+
+#else
+
+#define STRCASEEQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+ (c_strcasecmp (s1, s2) == 0)
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/c-strncasecmp.c b/contrib/tools/bison/gnulib/src/c-strncasecmp.c
index 053c70a73a..9a3b508ebb 100644
--- a/contrib/tools/bison/gnulib/src/c-strncasecmp.c
+++ b/contrib/tools/bison/gnulib/src/c-strncasecmp.c
@@ -1,56 +1,56 @@
-/* c-strncasecmp.c -- case insensitive string comparator in C locale
- Copyright (C) 1998-1999, 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "c-strcase.h"
-
-#include <limits.h>
-
-#include "c-ctype.h"
-
-int
-c_strncasecmp (const char *s1, const char *s2, size_t n)
-{
+/* c-strncasecmp.c -- case insensitive string comparator in C locale
+ Copyright (C) 1998-1999, 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "c-strcase.h"
+
+#include <limits.h>
+
+#include "c-ctype.h"
+
+int
+c_strncasecmp (const char *s1, const char *s2, size_t n)
+{
const unsigned char *p1 = (const unsigned char *) s1;
const unsigned char *p2 = (const unsigned char *) s2;
- unsigned char c1, c2;
-
- if (p1 == p2 || n == 0)
- return 0;
-
- do
- {
- c1 = c_tolower (*p1);
- c2 = c_tolower (*p2);
-
- if (--n == 0 || c1 == '\0')
- break;
-
- ++p1;
- ++p2;
- }
- while (c1 == c2);
-
- if (UCHAR_MAX <= INT_MAX)
- return c1 - c2;
- else
- /* On machines where 'char' and 'int' are types of the same size, the
- difference of two 'unsigned char' values - including the sign bit -
- doesn't fit in an 'int'. */
- return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
-}
+ unsigned char c1, c2;
+
+ if (p1 == p2 || n == 0)
+ return 0;
+
+ do
+ {
+ c1 = c_tolower (*p1);
+ c2 = c_tolower (*p2);
+
+ if (--n == 0 || c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ }
+ while (c1 == c2);
+
+ if (UCHAR_MAX <= INT_MAX)
+ return c1 - c2;
+ else
+ /* On machines where 'char' and 'int' are types of the same size, the
+ difference of two 'unsigned char' values - including the sign bit -
+ doesn't fit in an 'int'. */
+ return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
+}
diff --git a/contrib/tools/bison/gnulib/src/calloc.c b/contrib/tools/bison/gnulib/src/calloc.c
index 475d0aeab9..2372dd24ef 100644
--- a/contrib/tools/bison/gnulib/src/calloc.c
+++ b/contrib/tools/bison/gnulib/src/calloc.c
@@ -1,73 +1,73 @@
-/* calloc() function that is glibc compatible.
- This wrapper function is required at least on Tru64 UNIX 5.1 and mingw.
- Copyright (C) 2004-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Jim Meyering and Bruno Haible */
-
-#include <config.h>
-/* Only the AC_FUNC_CALLOC macro defines 'calloc' already in config.h. */
-#ifdef calloc
-# define NEED_CALLOC_GNU 1
-# undef calloc
-/* Whereas the gnulib module 'calloc-gnu' defines HAVE_CALLOC_GNU. */
-#elif GNULIB_CALLOC_GNU && !HAVE_CALLOC_GNU
-# define NEED_CALLOC_GNU 1
-#endif
-
-/* Specification. */
-#include <stdlib.h>
-
-#include <errno.h>
-
-/* Call the system's calloc below. */
-#undef calloc
-
-/* Allocate and zero-fill an NxS-byte block of memory from the heap.
- If N or S is zero, allocate and zero-fill a 1-byte block. */
-
-void *
-rpl_calloc (size_t n, size_t s)
-{
- void *result;
-
-#if NEED_CALLOC_GNU
- if (n == 0 || s == 0)
- {
- n = 1;
- s = 1;
- }
- else
- {
- /* Defend against buggy calloc implementations that mishandle
- size_t overflow. */
- size_t bytes = n * s;
- if (bytes / s != n)
- {
- errno = ENOMEM;
- return NULL;
- }
- }
-#endif
-
- result = calloc (n, s);
-
-#if !HAVE_CALLOC_POSIX
- if (result == NULL)
- errno = ENOMEM;
-#endif
-
- return result;
-}
+/* calloc() function that is glibc compatible.
+ This wrapper function is required at least on Tru64 UNIX 5.1 and mingw.
+ Copyright (C) 2004-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Jim Meyering and Bruno Haible */
+
+#include <config.h>
+/* Only the AC_FUNC_CALLOC macro defines 'calloc' already in config.h. */
+#ifdef calloc
+# define NEED_CALLOC_GNU 1
+# undef calloc
+/* Whereas the gnulib module 'calloc-gnu' defines HAVE_CALLOC_GNU. */
+#elif GNULIB_CALLOC_GNU && !HAVE_CALLOC_GNU
+# define NEED_CALLOC_GNU 1
+#endif
+
+/* Specification. */
+#include <stdlib.h>
+
+#include <errno.h>
+
+/* Call the system's calloc below. */
+#undef calloc
+
+/* Allocate and zero-fill an NxS-byte block of memory from the heap.
+ If N or S is zero, allocate and zero-fill a 1-byte block. */
+
+void *
+rpl_calloc (size_t n, size_t s)
+{
+ void *result;
+
+#if NEED_CALLOC_GNU
+ if (n == 0 || s == 0)
+ {
+ n = 1;
+ s = 1;
+ }
+ else
+ {
+ /* Defend against buggy calloc implementations that mishandle
+ size_t overflow. */
+ size_t bytes = n * s;
+ if (bytes / s != n)
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
+ }
+#endif
+
+ result = calloc (n, s);
+
+#if !HAVE_CALLOC_POSIX
+ if (result == NULL)
+ errno = ENOMEM;
+#endif
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/canonicalize-lgpl.c b/contrib/tools/bison/gnulib/src/canonicalize-lgpl.c
index 5cc9c5b4a0..929d1ca8e8 100644
--- a/contrib/tools/bison/gnulib/src/canonicalize-lgpl.c
+++ b/contrib/tools/bison/gnulib/src/canonicalize-lgpl.c
@@ -1,411 +1,411 @@
-/* Return the canonical absolute name of a given file.
- Copyright (C) 1996-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC
-/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
- optimizes away the name == NULL test below. */
-# define _GL_ARG_NONNULL(params)
-
-# define _GL_USE_STDLIB_ALLOC 1
-# include <config.h>
-#endif
-
-#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC
-
-/* Specification. */
-#include <stdlib.h>
-
+/* Return the canonical absolute name of a given file.
+ Copyright (C) 1996-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LIBC
+/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
+ optimizes away the name == NULL test below. */
+# define _GL_ARG_NONNULL(params)
+
+# define _GL_USE_STDLIB_ALLOC 1
+# include <config.h>
+#endif
+
+#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC
+
+/* Specification. */
+#include <stdlib.h>
+
#include "palloca.h"
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-#if HAVE_SYS_PARAM_H || defined _LIBC
-# include <sys/param.h>
-#endif
-#include <sys/stat.h>
-#include <errno.h>
-#include <stddef.h>
-
-#ifdef _LIBC
-# include <shlib-compat.h>
-#else
-# define SHLIB_COMPAT(lib, introduced, obsoleted) 0
-# define versioned_symbol(lib, local, symbol, version) extern int dummy
-# define compat_symbol(lib, local, symbol, version)
-# define weak_alias(local, symbol)
-# define __canonicalize_file_name canonicalize_file_name
-# define __realpath realpath
-# include "pathmax.h"
-# include "malloca.h"
-# include "dosname.h"
-# if HAVE_GETCWD
-# if IN_RELOCWRAPPER
- /* When building the relocatable program wrapper, use the system's getcwd
- function, not the gnulib override, otherwise we would get a link error.
- */
-# undef getcwd
-# endif
-# ifdef VMS
- /* We want the directory in Unix syntax, not in VMS syntax. */
-# define __getcwd(buf, max) getcwd (buf, max, 0)
-# else
-# define __getcwd getcwd
-# endif
-# else
-# define __getcwd(buf, max) getwd (buf)
-# endif
-# define __readlink readlink
-# define __set_errno(e) errno = (e)
-# ifndef MAXSYMLINKS
-# ifdef SYMLOOP_MAX
-# define MAXSYMLINKS SYMLOOP_MAX
-# else
-# define MAXSYMLINKS 20
-# endif
-# endif
-#endif
-
-#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
-# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
-#endif
-
-#if !FUNC_REALPATH_WORKS || defined _LIBC
-/* Return the canonical absolute name of file NAME. A canonical name
- does not contain any ".", ".." components nor any repeated path
- separators ('/') or symlinks. All path components must exist. If
- RESOLVED is null, the result is malloc'd; otherwise, if the
- canonical name is PATH_MAX chars or more, returns null with 'errno'
- set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
- returns the name in RESOLVED. If the name cannot be resolved and
- RESOLVED is non-NULL, it contains the path of the first component
- that cannot be resolved. If the path can be resolved, RESOLVED
- holds the same value as the value returned. */
-
-char *
-__realpath (const char *name, char *resolved)
-{
- char *rpath, *dest, *extra_buf = NULL;
- const char *start, *end, *rpath_limit;
- long int path_max;
- int num_links = 0;
- size_t prefix_len;
-
- if (name == NULL)
- {
- /* As per Single Unix Specification V2 we must return an error if
- either parameter is a null pointer. We extend this to allow
- the RESOLVED parameter to be NULL in case the we are expected to
- allocate the room for the return value. */
- __set_errno (EINVAL);
- return NULL;
- }
-
- if (name[0] == '\0')
- {
- /* As per Single Unix Specification V2 we must return an error if
- the name argument points to an empty string. */
- __set_errno (ENOENT);
- return NULL;
- }
-
-#ifdef PATH_MAX
- path_max = PATH_MAX;
-#else
- path_max = pathconf (name, _PC_PATH_MAX);
- if (path_max <= 0)
- path_max = 8192;
-#endif
-
- if (resolved == NULL)
- {
- rpath = malloc (path_max);
- if (rpath == NULL)
- {
- /* It's easier to set errno to ENOMEM than to rely on the
- 'malloc-posix' gnulib module. */
- errno = ENOMEM;
- return NULL;
- }
- }
- else
- rpath = resolved;
- rpath_limit = rpath + path_max;
-
- /* This is always zero for Posix hosts, but can be 2 for MS-Windows
- and MS-DOS X:/foo/bar file names. */
- prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
-
- if (!IS_ABSOLUTE_FILE_NAME (name))
- {
- if (!__getcwd (rpath, path_max))
- {
- rpath[0] = '\0';
- goto error;
- }
- dest = strchr (rpath, '\0');
- start = name;
- prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath);
- }
- else
- {
- dest = rpath;
- if (prefix_len)
- {
- memcpy (rpath, name, prefix_len);
- dest += prefix_len;
- }
- *dest++ = '/';
- if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
- {
- if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len)
- *dest++ = '/';
- *dest = '\0';
- }
- start = name + prefix_len;
- }
-
- for (end = start; *start; start = end)
- {
-#ifdef _LIBC
- struct stat64 st;
-#else
- struct stat st;
-#endif
- int n;
-
- /* Skip sequence of multiple path-separators. */
- while (ISSLASH (*start))
- ++start;
-
- /* Find end of path component. */
- for (end = start; *end && !ISSLASH (*end); ++end)
- /* Nothing. */;
-
- if (end - start == 0)
- break;
- else if (end - start == 1 && start[0] == '.')
- /* nothing */;
- else if (end - start == 2 && start[0] == '.' && start[1] == '.')
- {
- /* Back up to previous component, ignore if at root already. */
- if (dest > rpath + prefix_len + 1)
- for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
- continue;
- if (DOUBLE_SLASH_IS_DISTINCT_ROOT
- && dest == rpath + 1 && !prefix_len
- && ISSLASH (*dest) && !ISSLASH (dest[1]))
- dest++;
- }
- else
- {
- size_t new_size;
-
- if (!ISSLASH (dest[-1]))
- *dest++ = '/';
-
- if (dest + (end - start) >= rpath_limit)
- {
- ptrdiff_t dest_offset = dest - rpath;
- char *new_rpath;
-
- if (resolved)
- {
- __set_errno (ENAMETOOLONG);
- if (dest > rpath + prefix_len + 1)
- dest--;
- *dest = '\0';
- goto error;
- }
- new_size = rpath_limit - rpath;
- if (end - start + 1 > path_max)
- new_size += end - start + 1;
- else
- new_size += path_max;
- new_rpath = (char *) realloc (rpath, new_size);
- if (new_rpath == NULL)
- {
- /* It's easier to set errno to ENOMEM than to rely on the
- 'realloc-posix' gnulib module. */
- errno = ENOMEM;
- goto error;
- }
- rpath = new_rpath;
- rpath_limit = rpath + new_size;
-
- dest = rpath + dest_offset;
- }
-
-#ifdef _LIBC
- dest = __mempcpy (dest, start, end - start);
-#else
- memcpy (dest, start, end - start);
- dest += end - start;
-#endif
- *dest = '\0';
-
-#ifdef _LIBC
- if (__lxstat64 (_STAT_VER, rpath, &st) < 0)
-#else
- if (lstat (rpath, &st) < 0)
-#endif
- goto error;
-
- if (S_ISLNK (st.st_mode))
- {
- char *buf;
- size_t len;
-
- if (++num_links > MAXSYMLINKS)
- {
- __set_errno (ELOOP);
- goto error;
- }
-
- buf = malloca (path_max);
- if (!buf)
- {
- errno = ENOMEM;
- goto error;
- }
-
- n = __readlink (rpath, buf, path_max - 1);
- if (n < 0)
- {
- int saved_errno = errno;
- freea (buf);
- errno = saved_errno;
- goto error;
- }
- buf[n] = '\0';
-
- if (!extra_buf)
- {
- extra_buf = malloca (path_max);
- if (!extra_buf)
- {
- freea (buf);
- errno = ENOMEM;
- goto error;
- }
- }
-
- len = strlen (end);
- if ((long int) (n + len) >= path_max)
- {
- freea (buf);
- __set_errno (ENAMETOOLONG);
- goto error;
- }
-
- /* Careful here, end may be a pointer into extra_buf... */
- memmove (&extra_buf[n], end, len + 1);
- name = end = memcpy (extra_buf, buf, n);
-
- if (IS_ABSOLUTE_FILE_NAME (buf))
- {
- size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
-
- if (pfxlen)
- memcpy (rpath, buf, pfxlen);
- dest = rpath + pfxlen;
- *dest++ = '/'; /* It's an absolute symlink */
- if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
- {
- if (ISSLASH (buf[1]) && !ISSLASH (buf[2]) && !pfxlen)
- *dest++ = '/';
- *dest = '\0';
- }
- /* Install the new prefix to be in effect hereafter. */
- prefix_len = pfxlen;
- }
- else
- {
- /* Back up to previous component, ignore if at root
- already: */
- if (dest > rpath + prefix_len + 1)
- for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
- continue;
- if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
- && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
- dest++;
- }
- }
- else if (!S_ISDIR (st.st_mode) && *end != '\0')
- {
- __set_errno (ENOTDIR);
- goto error;
- }
- }
- }
- if (dest > rpath + prefix_len + 1 && ISSLASH (dest[-1]))
- --dest;
- if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len
- && ISSLASH (*dest) && !ISSLASH (dest[1]))
- dest++;
- *dest = '\0';
-
- if (extra_buf)
- freea (extra_buf);
-
- return rpath;
-
-error:
- {
- int saved_errno = errno;
- if (extra_buf)
- freea (extra_buf);
- if (resolved == NULL)
- free (rpath);
- errno = saved_errno;
- }
- return NULL;
-}
-versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
-#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */
-
-
-#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3)
-char *
-attribute_compat_text_section
-__old_realpath (const char *name, char *resolved)
-{
- if (resolved == NULL)
- {
- __set_errno (EINVAL);
- return NULL;
- }
-
- return __realpath (name, resolved);
-}
-compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0);
-#endif
-
-
-char *
-__canonicalize_file_name (const char *name)
-{
- return __realpath (name, NULL);
-}
-weak_alias (__canonicalize_file_name, canonicalize_file_name)
-
-#else
-
-/* This declaration is solely to ensure that after preprocessing
- this file is never empty. */
-typedef int dummy;
-
-#endif
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+#if HAVE_SYS_PARAM_H || defined _LIBC
+# include <sys/param.h>
+#endif
+#include <sys/stat.h>
+#include <errno.h>
+#include <stddef.h>
+
+#ifdef _LIBC
+# include <shlib-compat.h>
+#else
+# define SHLIB_COMPAT(lib, introduced, obsoleted) 0
+# define versioned_symbol(lib, local, symbol, version) extern int dummy
+# define compat_symbol(lib, local, symbol, version)
+# define weak_alias(local, symbol)
+# define __canonicalize_file_name canonicalize_file_name
+# define __realpath realpath
+# include "pathmax.h"
+# include "malloca.h"
+# include "dosname.h"
+# if HAVE_GETCWD
+# if IN_RELOCWRAPPER
+ /* When building the relocatable program wrapper, use the system's getcwd
+ function, not the gnulib override, otherwise we would get a link error.
+ */
+# undef getcwd
+# endif
+# ifdef VMS
+ /* We want the directory in Unix syntax, not in VMS syntax. */
+# define __getcwd(buf, max) getcwd (buf, max, 0)
+# else
+# define __getcwd getcwd
+# endif
+# else
+# define __getcwd(buf, max) getwd (buf)
+# endif
+# define __readlink readlink
+# define __set_errno(e) errno = (e)
+# ifndef MAXSYMLINKS
+# ifdef SYMLOOP_MAX
+# define MAXSYMLINKS SYMLOOP_MAX
+# else
+# define MAXSYMLINKS 20
+# endif
+# endif
+#endif
+
+#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
+# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
+#endif
+
+#if !FUNC_REALPATH_WORKS || defined _LIBC
+/* Return the canonical absolute name of file NAME. A canonical name
+ does not contain any ".", ".." components nor any repeated path
+ separators ('/') or symlinks. All path components must exist. If
+ RESOLVED is null, the result is malloc'd; otherwise, if the
+ canonical name is PATH_MAX chars or more, returns null with 'errno'
+ set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
+ returns the name in RESOLVED. If the name cannot be resolved and
+ RESOLVED is non-NULL, it contains the path of the first component
+ that cannot be resolved. If the path can be resolved, RESOLVED
+ holds the same value as the value returned. */
+
+char *
+__realpath (const char *name, char *resolved)
+{
+ char *rpath, *dest, *extra_buf = NULL;
+ const char *start, *end, *rpath_limit;
+ long int path_max;
+ int num_links = 0;
+ size_t prefix_len;
+
+ if (name == NULL)
+ {
+ /* As per Single Unix Specification V2 we must return an error if
+ either parameter is a null pointer. We extend this to allow
+ the RESOLVED parameter to be NULL in case the we are expected to
+ allocate the room for the return value. */
+ __set_errno (EINVAL);
+ return NULL;
+ }
+
+ if (name[0] == '\0')
+ {
+ /* As per Single Unix Specification V2 we must return an error if
+ the name argument points to an empty string. */
+ __set_errno (ENOENT);
+ return NULL;
+ }
+
+#ifdef PATH_MAX
+ path_max = PATH_MAX;
+#else
+ path_max = pathconf (name, _PC_PATH_MAX);
+ if (path_max <= 0)
+ path_max = 8192;
+#endif
+
+ if (resolved == NULL)
+ {
+ rpath = malloc (path_max);
+ if (rpath == NULL)
+ {
+ /* It's easier to set errno to ENOMEM than to rely on the
+ 'malloc-posix' gnulib module. */
+ errno = ENOMEM;
+ return NULL;
+ }
+ }
+ else
+ rpath = resolved;
+ rpath_limit = rpath + path_max;
+
+ /* This is always zero for Posix hosts, but can be 2 for MS-Windows
+ and MS-DOS X:/foo/bar file names. */
+ prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
+
+ if (!IS_ABSOLUTE_FILE_NAME (name))
+ {
+ if (!__getcwd (rpath, path_max))
+ {
+ rpath[0] = '\0';
+ goto error;
+ }
+ dest = strchr (rpath, '\0');
+ start = name;
+ prefix_len = FILE_SYSTEM_PREFIX_LEN (rpath);
+ }
+ else
+ {
+ dest = rpath;
+ if (prefix_len)
+ {
+ memcpy (rpath, name, prefix_len);
+ dest += prefix_len;
+ }
+ *dest++ = '/';
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
+ {
+ if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len)
+ *dest++ = '/';
+ *dest = '\0';
+ }
+ start = name + prefix_len;
+ }
+
+ for (end = start; *start; start = end)
+ {
+#ifdef _LIBC
+ struct stat64 st;
+#else
+ struct stat st;
+#endif
+ int n;
+
+ /* Skip sequence of multiple path-separators. */
+ while (ISSLASH (*start))
+ ++start;
+
+ /* Find end of path component. */
+ for (end = start; *end && !ISSLASH (*end); ++end)
+ /* Nothing. */;
+
+ if (end - start == 0)
+ break;
+ else if (end - start == 1 && start[0] == '.')
+ /* nothing */;
+ else if (end - start == 2 && start[0] == '.' && start[1] == '.')
+ {
+ /* Back up to previous component, ignore if at root already. */
+ if (dest > rpath + prefix_len + 1)
+ for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
+ continue;
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT
+ && dest == rpath + 1 && !prefix_len
+ && ISSLASH (*dest) && !ISSLASH (dest[1]))
+ dest++;
+ }
+ else
+ {
+ size_t new_size;
+
+ if (!ISSLASH (dest[-1]))
+ *dest++ = '/';
+
+ if (dest + (end - start) >= rpath_limit)
+ {
+ ptrdiff_t dest_offset = dest - rpath;
+ char *new_rpath;
+
+ if (resolved)
+ {
+ __set_errno (ENAMETOOLONG);
+ if (dest > rpath + prefix_len + 1)
+ dest--;
+ *dest = '\0';
+ goto error;
+ }
+ new_size = rpath_limit - rpath;
+ if (end - start + 1 > path_max)
+ new_size += end - start + 1;
+ else
+ new_size += path_max;
+ new_rpath = (char *) realloc (rpath, new_size);
+ if (new_rpath == NULL)
+ {
+ /* It's easier to set errno to ENOMEM than to rely on the
+ 'realloc-posix' gnulib module. */
+ errno = ENOMEM;
+ goto error;
+ }
+ rpath = new_rpath;
+ rpath_limit = rpath + new_size;
+
+ dest = rpath + dest_offset;
+ }
+
+#ifdef _LIBC
+ dest = __mempcpy (dest, start, end - start);
+#else
+ memcpy (dest, start, end - start);
+ dest += end - start;
+#endif
+ *dest = '\0';
+
+#ifdef _LIBC
+ if (__lxstat64 (_STAT_VER, rpath, &st) < 0)
+#else
+ if (lstat (rpath, &st) < 0)
+#endif
+ goto error;
+
+ if (S_ISLNK (st.st_mode))
+ {
+ char *buf;
+ size_t len;
+
+ if (++num_links > MAXSYMLINKS)
+ {
+ __set_errno (ELOOP);
+ goto error;
+ }
+
+ buf = malloca (path_max);
+ if (!buf)
+ {
+ errno = ENOMEM;
+ goto error;
+ }
+
+ n = __readlink (rpath, buf, path_max - 1);
+ if (n < 0)
+ {
+ int saved_errno = errno;
+ freea (buf);
+ errno = saved_errno;
+ goto error;
+ }
+ buf[n] = '\0';
+
+ if (!extra_buf)
+ {
+ extra_buf = malloca (path_max);
+ if (!extra_buf)
+ {
+ freea (buf);
+ errno = ENOMEM;
+ goto error;
+ }
+ }
+
+ len = strlen (end);
+ if ((long int) (n + len) >= path_max)
+ {
+ freea (buf);
+ __set_errno (ENAMETOOLONG);
+ goto error;
+ }
+
+ /* Careful here, end may be a pointer into extra_buf... */
+ memmove (&extra_buf[n], end, len + 1);
+ name = end = memcpy (extra_buf, buf, n);
+
+ if (IS_ABSOLUTE_FILE_NAME (buf))
+ {
+ size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
+
+ if (pfxlen)
+ memcpy (rpath, buf, pfxlen);
+ dest = rpath + pfxlen;
+ *dest++ = '/'; /* It's an absolute symlink */
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
+ {
+ if (ISSLASH (buf[1]) && !ISSLASH (buf[2]) && !pfxlen)
+ *dest++ = '/';
+ *dest = '\0';
+ }
+ /* Install the new prefix to be in effect hereafter. */
+ prefix_len = pfxlen;
+ }
+ else
+ {
+ /* Back up to previous component, ignore if at root
+ already: */
+ if (dest > rpath + prefix_len + 1)
+ for (--dest; dest > rpath && !ISSLASH (dest[-1]); --dest)
+ continue;
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1
+ && ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
+ dest++;
+ }
+ }
+ else if (!S_ISDIR (st.st_mode) && *end != '\0')
+ {
+ __set_errno (ENOTDIR);
+ goto error;
+ }
+ }
+ }
+ if (dest > rpath + prefix_len + 1 && ISSLASH (dest[-1]))
+ --dest;
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rpath + 1 && !prefix_len
+ && ISSLASH (*dest) && !ISSLASH (dest[1]))
+ dest++;
+ *dest = '\0';
+
+ if (extra_buf)
+ freea (extra_buf);
+
+ return rpath;
+
+error:
+ {
+ int saved_errno = errno;
+ if (extra_buf)
+ freea (extra_buf);
+ if (resolved == NULL)
+ free (rpath);
+ errno = saved_errno;
+ }
+ return NULL;
+}
+versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
+#endif /* !FUNC_REALPATH_WORKS || defined _LIBC */
+
+
+#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3)
+char *
+attribute_compat_text_section
+__old_realpath (const char *name, char *resolved)
+{
+ if (resolved == NULL)
+ {
+ __set_errno (EINVAL);
+ return NULL;
+ }
+
+ return __realpath (name, resolved);
+}
+compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0);
+#endif
+
+
+char *
+__canonicalize_file_name (const char *name)
+{
+ return __realpath (name, NULL);
+}
+weak_alias (__canonicalize_file_name, canonicalize_file_name)
+
+#else
+
+/* This declaration is solely to ensure that after preprocessing
+ this file is never empty. */
+typedef int dummy;
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/clean-temp.c b/contrib/tools/bison/gnulib/src/clean-temp.c
index 2961114168..60210de073 100644
--- a/contrib/tools/bison/gnulib/src/clean-temp.c
+++ b/contrib/tools/bison/gnulib/src/clean-temp.c
@@ -1,793 +1,793 @@
-/* Temporary directories and temporary files with automatic cleanup.
- Copyright (C) 2001, 2003, 2006-2007, 2009-2013 Free Software Foundation,
- Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#include <config.h>
-
-/* Specification. */
-#include "clean-temp.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdbool.h>
+/* Temporary directories and temporary files with automatic cleanup.
+ Copyright (C) 2001, 2003, 2006-2007, 2009-2013 Free Software Foundation,
+ Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include <config.h>
+
+/* Specification. */
+#include "clean-temp.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdbool.h>
#include "stdlib--.h"
-#include <string.h>
-#include <unistd.h>
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-# define WIN32_LEAN_AND_MEAN /* avoid including junk */
-# include <windows.h>
-#endif
-
-#include "error.h"
-#include "fatal-signal.h"
-#include "pathmax.h"
-#include "tmpdir.h"
-#include "xalloc.h"
-#include "xmalloca.h"
-#include "gl_xlist.h"
-#include "gl_linkedhash_list.h"
-#include "gettext.h"
-#if GNULIB_FWRITEERROR
-# include "fwriteerror.h"
-#endif
-#if GNULIB_CLOSE_STREAM
-# include "close-stream.h"
-#endif
-#if GNULIB_FCNTL_SAFER
-# include "fcntl--.h"
-#endif
-#if GNULIB_FOPEN_SAFER
-# include "stdio--.h"
-#endif
-
-#define _(str) gettext (str)
-
-/* GNU Hurd doesn't have PATH_MAX. Use a fallback.
- Temporary directory names are usually not that long. */
-#ifndef PATH_MAX
-# define PATH_MAX 1024
-#endif
-
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
-#if !GNULIB_FCNTL_SAFER
-/* The results of open() in this file are not used with fchdir,
- therefore save some unnecessary work in fchdir.c. */
-# undef open
-# undef close
-#endif
-
-
-/* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
- ensure that while constructing or modifying the data structures, the field
- values are written to memory in the order of the C statements. So the
- signal handler can rely on these field values to be up to date. */
-
-
-/* Registry for a single temporary directory.
- 'struct temp_dir' from the public header file overlaps with this. */
-struct tempdir
-{
- /* The absolute pathname of the directory. */
- char * volatile dirname;
- /* Whether errors during explicit cleanup are reported to standard error. */
- bool cleanup_verbose;
- /* Absolute pathnames of subdirectories. */
- gl_list_t /* <char *> */ volatile subdirs;
- /* Absolute pathnames of files. */
- gl_list_t /* <char *> */ volatile files;
-};
-
-/* List of all temporary directories. */
-static struct
-{
- struct tempdir * volatile * volatile tempdir_list;
- size_t volatile tempdir_count;
- size_t tempdir_allocated;
-} cleanup_list /* = { NULL, 0, 0 } */;
-
-/* List of all open file descriptors to temporary files. */
-static gl_list_t /* <int> */ volatile descriptors;
-
-
-/* For the subdirs and for the files, we use a gl_list_t of type LINKEDHASH.
- Why? We need a data structure that
-
- 1) Can contain an arbitrary number of 'char *' values. The strings
- are compared via strcmp, not pointer comparison.
- 2) Has insertion and deletion operations that are fast: ideally O(1),
- or possibly O(log n). This is important for GNU sort, which may
- create a large number of temporary files.
- 3) Allows iteration through all elements from within a signal handler.
- 4) May or may not allow duplicates. It doesn't matter here, since
- any file or subdir can only be removed once.
-
- Criterion 1) would allow any gl_list_t or gl_oset_t implementation.
-
- Criterion 2) leaves only GL_LINKEDHASH_LIST, GL_TREEHASH_LIST, or
- GL_TREE_OSET.
-
- Criterion 3) puts at disadvantage GL_TREEHASH_LIST and GL_TREE_OSET.
- Namely, iteration through the elements of a binary tree requires access
- to many ->left, ->right, ->parent pointers. However, the rebalancing
- code for insertion and deletion in an AVL or red-black tree is so
- complicated that we cannot assume that >left, ->right, ->parent pointers
- are in a consistent state throughout these operations. Therefore, to
- avoid a crash in the signal handler, all destructive operations to the
- lists would have to be protected by a
- block_fatal_signals ();
- ...
- unblock_fatal_signals ();
- pair. Which causes extra system calls.
-
- Criterion 3) would also discourage GL_ARRAY_LIST and GL_CARRAY_LIST,
- if they were not already excluded. Namely, these implementations use
- xrealloc(), leaving a time window in which in the list->elements pointer
- points to already deallocated memory. To avoid a crash in the signal
- handler at such a moment, all destructive operations would have to
- protected by block/unblock_fatal_signals (), in this case too.
-
- A list of type GL_LINKEDHASH_LIST without duplicates fulfills all
- requirements:
- 2) Insertion and deletion are O(1) on average.
- 3) The gl_list_iterator, gl_list_iterator_next implementations do
- not trigger memory allocations, nor other system calls, and are
- therefore safe to be called from a signal handler.
- Furthermore, since SIGNAL_SAFE_LIST is defined, the implementation
- of the destructive functions ensures that the list structure is
- safe to be traversed at any moment, even when interrupted by an
- asynchronous signal.
- */
-
-/* String equality and hash code functions used by the lists. */
-
-static bool
-string_equals (const void *x1, const void *x2)
-{
- const char *s1 = (const char *) x1;
- const char *s2 = (const char *) x2;
- return strcmp (s1, s2) == 0;
-}
-
-#define SIZE_BITS (sizeof (size_t) * CHAR_BIT)
-
-/* A hash function for NUL-terminated char* strings using
- the method described by Bruno Haible.
- See http://www.haible.de/bruno/hashfunc.html. */
-static size_t
-string_hash (const void *x)
-{
- const char *s = (const char *) x;
- size_t h = 0;
-
- for (; *s; s++)
- h = *s + ((h << 9) | (h >> (SIZE_BITS - 9)));
-
- return h;
-}
-
-
-/* The signal handler. It gets called asynchronously. */
-static void
-cleanup ()
-{
- size_t i;
-
- /* First close all file descriptors to temporary files. */
- {
- gl_list_t fds = descriptors;
-
- if (fds != NULL)
- {
- gl_list_iterator_t iter;
- const void *element;
-
- iter = gl_list_iterator (fds);
- while (gl_list_iterator_next (&iter, &element, NULL))
- {
- int fd = (int) (uintptr_t) element;
- close (fd);
- }
- gl_list_iterator_free (&iter);
- }
- }
-
- for (i = 0; i < cleanup_list.tempdir_count; i++)
- {
- struct tempdir *dir = cleanup_list.tempdir_list[i];
-
- if (dir != NULL)
- {
- gl_list_iterator_t iter;
- const void *element;
-
- /* First cleanup the files in the subdirectories. */
- iter = gl_list_iterator (dir->files);
- while (gl_list_iterator_next (&iter, &element, NULL))
- {
- const char *file = (const char *) element;
- unlink (file);
- }
- gl_list_iterator_free (&iter);
-
- /* Then cleanup the subdirectories. */
- iter = gl_list_iterator (dir->subdirs);
- while (gl_list_iterator_next (&iter, &element, NULL))
- {
- const char *subdir = (const char *) element;
- rmdir (subdir);
- }
- gl_list_iterator_free (&iter);
-
- /* Then cleanup the temporary directory itself. */
- rmdir (dir->dirname);
- }
- }
-}
-
-/* Create a temporary directory.
- PREFIX is used as a prefix for the name of the temporary directory. It
- should be short and still give an indication about the program.
- PARENTDIR can be used to specify the parent directory; if NULL, a default
- parent directory is used (either $TMPDIR or /tmp or similar).
- CLEANUP_VERBOSE determines whether errors during explicit cleanup are
- reported to standard error.
- Return a fresh 'struct temp_dir' on success. Upon error, an error message
- is shown and NULL is returned. */
-struct temp_dir *
-create_temp_dir (const char *prefix, const char *parentdir,
- bool cleanup_verbose)
-{
- struct tempdir * volatile *tmpdirp = NULL;
- struct tempdir *tmpdir;
- size_t i;
- char *xtemplate;
- char *tmpdirname;
-
- /* See whether it can take the slot of an earlier temporary directory
- already cleaned up. */
- for (i = 0; i < cleanup_list.tempdir_count; i++)
- if (cleanup_list.tempdir_list[i] == NULL)
- {
- tmpdirp = &cleanup_list.tempdir_list[i];
- break;
- }
- if (tmpdirp == NULL)
- {
- /* See whether the array needs to be extended. */
- if (cleanup_list.tempdir_count == cleanup_list.tempdir_allocated)
- {
- /* Note that we cannot use xrealloc(), because then the cleanup()
- function could access an already deallocated array. */
- struct tempdir * volatile *old_array = cleanup_list.tempdir_list;
- size_t old_allocated = cleanup_list.tempdir_allocated;
- size_t new_allocated = 2 * cleanup_list.tempdir_allocated + 1;
- struct tempdir * volatile *new_array =
- XNMALLOC (new_allocated, struct tempdir * volatile);
-
- if (old_allocated == 0)
- /* First use of this facility. Register the cleanup handler. */
- at_fatal_signal (&cleanup);
- else
- {
- /* Don't use memcpy() here, because memcpy takes non-volatile
- arguments and is therefore not guaranteed to complete all
- memory stores before the next statement. */
- size_t k;
-
- for (k = 0; k < old_allocated; k++)
- new_array[k] = old_array[k];
- }
-
- cleanup_list.tempdir_list = new_array;
- cleanup_list.tempdir_allocated = new_allocated;
-
- /* Now we can free the old array. */
- if (old_array != NULL)
- free ((struct tempdir **) old_array);
- }
-
- tmpdirp = &cleanup_list.tempdir_list[cleanup_list.tempdir_count];
- /* Initialize *tmpdirp before incrementing tempdir_count, so that
- cleanup() will skip this entry before it is fully initialized. */
- *tmpdirp = NULL;
- cleanup_list.tempdir_count++;
- }
-
- /* Initialize a 'struct tempdir'. */
- tmpdir = XMALLOC (struct tempdir);
- tmpdir->dirname = NULL;
- tmpdir->cleanup_verbose = cleanup_verbose;
- tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST,
- string_equals, string_hash, NULL,
- false);
- tmpdir->files = gl_list_create_empty (GL_LINKEDHASH_LIST,
- string_equals, string_hash, NULL,
- false);
-
- /* Create the temporary directory. */
- xtemplate = (char *) xmalloca (PATH_MAX);
- if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL))
- {
- error (0, errno,
- _("cannot find a temporary directory, try setting $TMPDIR"));
- goto quit;
- }
- block_fatal_signals ();
- tmpdirname = mkdtemp (xtemplate);
- if (tmpdirname != NULL)
- {
- tmpdir->dirname = tmpdirname;
- *tmpdirp = tmpdir;
- }
- unblock_fatal_signals ();
- if (tmpdirname == NULL)
- {
- error (0, errno,
- _("cannot create a temporary directory using template \"%s\""),
- xtemplate);
- goto quit;
- }
- /* Replace tmpdir->dirname with a copy that has indefinite extent.
- We cannot do this inside the block_fatal_signals/unblock_fatal_signals
- block because then the cleanup handler would not remove the directory
- if xstrdup fails. */
- tmpdir->dirname = xstrdup (tmpdirname);
- freea (xtemplate);
- return (struct temp_dir *) tmpdir;
-
- quit:
- freea (xtemplate);
- return NULL;
-}
-
-/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
- needs to be removed before DIR can be removed.
- Should be called before the file ABSOLUTE_FILE_NAME is created. */
-void
-register_temp_file (struct temp_dir *dir,
- const char *absolute_file_name)
-{
- struct tempdir *tmpdir = (struct tempdir *)dir;
-
- /* Add absolute_file_name to tmpdir->files, without duplicates. */
- if (gl_list_search (tmpdir->files, absolute_file_name) == NULL)
- gl_list_add_first (tmpdir->files, xstrdup (absolute_file_name));
-}
-
-/* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
- needs to be removed before DIR can be removed.
- Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
-void
-unregister_temp_file (struct temp_dir *dir,
- const char *absolute_file_name)
-{
- struct tempdir *tmpdir = (struct tempdir *)dir;
- gl_list_t list = tmpdir->files;
- gl_list_node_t node;
-
- node = gl_list_search (list, absolute_file_name);
- if (node != NULL)
- {
- char *old_string = (char *) gl_list_node_value (list, node);
-
- gl_list_remove_node (list, node);
- free (old_string);
- }
-}
-
-/* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
- that needs to be removed before DIR can be removed.
- Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
-void
-register_temp_subdir (struct temp_dir *dir,
- const char *absolute_dir_name)
-{
- struct tempdir *tmpdir = (struct tempdir *)dir;
-
- /* Add absolute_dir_name to tmpdir->subdirs, without duplicates. */
- if (gl_list_search (tmpdir->subdirs, absolute_dir_name) == NULL)
- gl_list_add_first (tmpdir->subdirs, xstrdup (absolute_dir_name));
-}
-
-/* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
- that needs to be removed before DIR can be removed.
- Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be
- created. */
-void
-unregister_temp_subdir (struct temp_dir *dir,
- const char *absolute_dir_name)
-{
- struct tempdir *tmpdir = (struct tempdir *)dir;
- gl_list_t list = tmpdir->subdirs;
- gl_list_node_t node;
-
- node = gl_list_search (list, absolute_dir_name);
- if (node != NULL)
- {
- char *old_string = (char *) gl_list_node_value (list, node);
-
- gl_list_remove_node (list, node);
- free (old_string);
- }
-}
-
-/* Remove a file, with optional error message.
- Return 0 upon success, or -1 if there was some problem. */
-static int
-do_unlink (struct temp_dir *dir, const char *absolute_file_name)
-{
- if (unlink (absolute_file_name) < 0 && dir->cleanup_verbose
- && errno != ENOENT)
- {
- error (0, errno, _("cannot remove temporary file %s"), absolute_file_name);
- return -1;
- }
- return 0;
-}
-
-/* Remove a directory, with optional error message.
- Return 0 upon success, or -1 if there was some problem. */
-static int
-do_rmdir (struct temp_dir *dir, const char *absolute_dir_name)
-{
- if (rmdir (absolute_dir_name) < 0 && dir->cleanup_verbose
- && errno != ENOENT)
- {
- error (0, errno,
- _("cannot remove temporary directory %s"), absolute_dir_name);
- return -1;
- }
- return 0;
-}
-
-/* Remove the given ABSOLUTE_FILE_NAME and unregister it.
- Return 0 upon success, or -1 if there was some problem. */
-int
-cleanup_temp_file (struct temp_dir *dir,
- const char *absolute_file_name)
-{
- int err;
-
- err = do_unlink (dir, absolute_file_name);
- unregister_temp_file (dir, absolute_file_name);
-
- return err;
-}
-
-/* Remove the given ABSOLUTE_DIR_NAME and unregister it.
- Return 0 upon success, or -1 if there was some problem. */
-int
-cleanup_temp_subdir (struct temp_dir *dir,
- const char *absolute_dir_name)
-{
- int err;
-
- err = do_rmdir (dir, absolute_dir_name);
- unregister_temp_subdir (dir, absolute_dir_name);
-
- return err;
-}
-
-/* Remove all registered files and subdirectories inside DIR.
- Return 0 upon success, or -1 if there was some problem. */
-int
-cleanup_temp_dir_contents (struct temp_dir *dir)
-{
- struct tempdir *tmpdir = (struct tempdir *)dir;
- int err = 0;
- gl_list_t list;
- gl_list_iterator_t iter;
- const void *element;
- gl_list_node_t node;
-
- /* First cleanup the files in the subdirectories. */
- list = tmpdir->files;
- iter = gl_list_iterator (list);
- while (gl_list_iterator_next (&iter, &element, &node))
- {
- char *file = (char *) element;
-
- err |= do_unlink (dir, file);
- gl_list_remove_node (list, node);
- /* Now only we can free file. */
- free (file);
- }
- gl_list_iterator_free (&iter);
-
- /* Then cleanup the subdirectories. */
- list = tmpdir->subdirs;
- iter = gl_list_iterator (list);
- while (gl_list_iterator_next (&iter, &element, &node))
- {
- char *subdir = (char *) element;
-
- err |= do_rmdir (dir, subdir);
- gl_list_remove_node (list, node);
- /* Now only we can free subdir. */
- free (subdir);
- }
- gl_list_iterator_free (&iter);
-
- return err;
-}
-
-/* Remove all registered files and subdirectories inside DIR and DIR itself.
- DIR cannot be used any more after this call.
- Return 0 upon success, or -1 if there was some problem. */
-int
-cleanup_temp_dir (struct temp_dir *dir)
-{
- struct tempdir *tmpdir = (struct tempdir *)dir;
- int err = 0;
- size_t i;
-
- err |= cleanup_temp_dir_contents (dir);
- err |= do_rmdir (dir, tmpdir->dirname);
-
- for (i = 0; i < cleanup_list.tempdir_count; i++)
- if (cleanup_list.tempdir_list[i] == tmpdir)
- {
- /* Remove cleanup_list.tempdir_list[i]. */
- if (i + 1 == cleanup_list.tempdir_count)
- {
- while (i > 0 && cleanup_list.tempdir_list[i - 1] == NULL)
- i--;
- cleanup_list.tempdir_count = i;
- }
- else
- cleanup_list.tempdir_list[i] = NULL;
- /* Now only we can free the tmpdir->dirname, tmpdir->subdirs,
- tmpdir->files, and tmpdir itself. */
- gl_list_free (tmpdir->files);
- gl_list_free (tmpdir->subdirs);
- free (tmpdir->dirname);
- free (tmpdir);
- return err;
- }
-
- /* The user passed an invalid DIR argument. */
- abort ();
-}
-
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* On Windows, opening a file with _O_TEMPORARY has the effect of passing
- the FILE_FLAG_DELETE_ON_CLOSE flag to CreateFile(), which has the effect
- of deleting the file when it is closed - even when the program crashes.
- But (according to the Cygwin sources) it works only on Windows NT or newer.
- So we cache the info whether we are running on Windows NT or newer. */
-
-static bool
-supports_delete_on_close ()
-{
- static int known; /* 1 = yes, -1 = no, 0 = unknown */
- /* M4 wants to close and later reopen a temporary file, so
- delete-on-close must not be used. */
- known = -1;
- if (!known)
- {
- OSVERSIONINFO v;
-
- /* According to
- <http://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx>
- this structure must be initialised as follows: */
- v.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
-
- if (GetVersionEx (&v))
- known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1);
- else
- known = -1;
- }
- return (known > 0);
-}
-
-#endif
-
-
-/* Register a file descriptor to be closed. */
-static void
-register_fd (int fd)
-{
- if (descriptors == NULL)
- descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL,
- false);
- gl_list_add_first (descriptors, (void *) (uintptr_t) fd);
-}
-
-/* Unregister a file descriptor to be closed. */
-static void
-unregister_fd (int fd)
-{
- gl_list_t fds = descriptors;
- gl_list_node_t node;
-
- if (fds == NULL)
- /* descriptors should already contain fd. */
- abort ();
- node = gl_list_search (fds, (void *) (uintptr_t) fd);
- if (node == NULL)
- /* descriptors should already contain fd. */
- abort ();
- gl_list_remove_node (fds, node);
-}
-
-/* Open a temporary file in a temporary directory.
- Registers the resulting file descriptor to be closed. */
-int
-open_temp (const char *file_name, int flags, mode_t mode)
-{
- int fd;
- int saved_errno;
-
- block_fatal_signals ();
- /* Note: 'open' here is actually open() or open_safer(). */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- /* Use _O_TEMPORARY when possible, to increase the chances that the
- temporary file is removed when the process crashes. */
- if (supports_delete_on_close ())
- fd = open (file_name, flags | _O_TEMPORARY, mode);
- else
-#endif
- fd = open (file_name, flags, mode);
- saved_errno = errno;
- if (fd >= 0)
- register_fd (fd);
- unblock_fatal_signals ();
- errno = saved_errno;
- return fd;
-}
-
-/* Open a temporary file in a temporary directory.
- Registers the resulting file descriptor to be closed. */
-FILE *
-fopen_temp (const char *file_name, const char *mode)
-{
- FILE *fp;
- int saved_errno;
-
- block_fatal_signals ();
- /* Note: 'fopen' here is actually fopen() or fopen_safer(). */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- /* Use _O_TEMPORARY when possible, to increase the chances that the
- temporary file is removed when the process crashes. */
- if (supports_delete_on_close ())
- {
- size_t mode_len = strlen (mode);
- char *augmented_mode = (char *) xmalloca (mode_len + 2);
- memcpy (augmented_mode, mode, mode_len);
- memcpy (augmented_mode + mode_len, "D", 2);
-
- fp = fopen (file_name, augmented_mode);
- saved_errno = errno;
-
- freea (augmented_mode);
- }
- else
-#endif
- {
- fp = fopen (file_name, mode);
- saved_errno = errno;
- }
- if (fp != NULL)
- {
- /* It is sufficient to register fileno (fp) instead of the entire fp,
- because at cleanup time there is no need to do an fflush (fp); a
- close (fileno (fp)) will be enough. */
- int fd = fileno (fp);
- if (!(fd >= 0))
- abort ();
- register_fd (fd);
- }
- unblock_fatal_signals ();
- errno = saved_errno;
- return fp;
-}
-
-/* Close a temporary file in a temporary directory.
- Unregisters the previously registered file descriptor. */
-int
-close_temp (int fd)
-{
- if (fd >= 0)
- {
- /* No blocking of signals is needed here, since a double close of a
- file descriptor is harmless. */
- int result = close (fd);
- int saved_errno = errno;
-
- /* No race condition here: we assume a single-threaded program, hence
- fd cannot be re-opened here. */
-
- unregister_fd (fd);
-
- errno = saved_errno;
- return result;
- }
- else
- return close (fd);
-}
-
-/* Close a temporary file in a temporary directory.
- Unregisters the previously registered file descriptor. */
-int
-fclose_temp (FILE *fp)
-{
- int fd = fileno (fp);
- /* No blocking of signals is needed here, since a double close of a
- file descriptor is harmless. */
- int result = fclose (fp);
- int saved_errno = errno;
-
- /* No race condition here: we assume a single-threaded program, hence
- fd cannot be re-opened here. */
-
- unregister_fd (fd);
-
- errno = saved_errno;
- return result;
-}
-
-#if GNULIB_FWRITEERROR
-/* Like fwriteerror.
- Unregisters the previously registered file descriptor. */
-int
-fwriteerror_temp (FILE *fp)
-{
- int fd = fileno (fp);
- /* No blocking of signals is needed here, since a double close of a
- file descriptor is harmless. */
- int result = fwriteerror (fp);
- int saved_errno = errno;
-
- /* No race condition here: we assume a single-threaded program, hence
- fd cannot be re-opened here. */
-
- unregister_fd (fd);
-
- errno = saved_errno;
- return result;
-}
-#endif
-
-#if GNULIB_CLOSE_STREAM
-/* Like close_stream.
- Unregisters the previously registered file descriptor. */
-int
-close_stream_temp (FILE *fp)
-{
- int fd = fileno (fp);
- /* No blocking of signals is needed here, since a double close of a
- file descriptor is harmless. */
- int result = close_stream (fp);
- int saved_errno = errno;
-
- /* No race condition here: we assume a single-threaded program, hence
- fd cannot be re-opened here. */
-
- unregister_fd (fd);
-
- errno = saved_errno;
- return result;
-}
-#endif
+#include <string.h>
+#include <unistd.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+#endif
+
+#include "error.h"
+#include "fatal-signal.h"
+#include "pathmax.h"
+#include "tmpdir.h"
+#include "xalloc.h"
+#include "xmalloca.h"
+#include "gl_xlist.h"
+#include "gl_linkedhash_list.h"
+#include "gettext.h"
+#if GNULIB_FWRITEERROR
+# include "fwriteerror.h"
+#endif
+#if GNULIB_CLOSE_STREAM
+# include "close-stream.h"
+#endif
+#if GNULIB_FCNTL_SAFER
+# include "fcntl--.h"
+#endif
+#if GNULIB_FOPEN_SAFER
+# include "stdio--.h"
+#endif
+
+#define _(str) gettext (str)
+
+/* GNU Hurd doesn't have PATH_MAX. Use a fallback.
+ Temporary directory names are usually not that long. */
+#ifndef PATH_MAX
+# define PATH_MAX 1024
+#endif
+
+#ifndef uintptr_t
+# define uintptr_t unsigned long
+#endif
+
+#if !GNULIB_FCNTL_SAFER
+/* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+# undef open
+# undef close
+#endif
+
+
+/* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
+ ensure that while constructing or modifying the data structures, the field
+ values are written to memory in the order of the C statements. So the
+ signal handler can rely on these field values to be up to date. */
+
+
+/* Registry for a single temporary directory.
+ 'struct temp_dir' from the public header file overlaps with this. */
+struct tempdir
+{
+ /* The absolute pathname of the directory. */
+ char * volatile dirname;
+ /* Whether errors during explicit cleanup are reported to standard error. */
+ bool cleanup_verbose;
+ /* Absolute pathnames of subdirectories. */
+ gl_list_t /* <char *> */ volatile subdirs;
+ /* Absolute pathnames of files. */
+ gl_list_t /* <char *> */ volatile files;
+};
+
+/* List of all temporary directories. */
+static struct
+{
+ struct tempdir * volatile * volatile tempdir_list;
+ size_t volatile tempdir_count;
+ size_t tempdir_allocated;
+} cleanup_list /* = { NULL, 0, 0 } */;
+
+/* List of all open file descriptors to temporary files. */
+static gl_list_t /* <int> */ volatile descriptors;
+
+
+/* For the subdirs and for the files, we use a gl_list_t of type LINKEDHASH.
+ Why? We need a data structure that
+
+ 1) Can contain an arbitrary number of 'char *' values. The strings
+ are compared via strcmp, not pointer comparison.
+ 2) Has insertion and deletion operations that are fast: ideally O(1),
+ or possibly O(log n). This is important for GNU sort, which may
+ create a large number of temporary files.
+ 3) Allows iteration through all elements from within a signal handler.
+ 4) May or may not allow duplicates. It doesn't matter here, since
+ any file or subdir can only be removed once.
+
+ Criterion 1) would allow any gl_list_t or gl_oset_t implementation.
+
+ Criterion 2) leaves only GL_LINKEDHASH_LIST, GL_TREEHASH_LIST, or
+ GL_TREE_OSET.
+
+ Criterion 3) puts at disadvantage GL_TREEHASH_LIST and GL_TREE_OSET.
+ Namely, iteration through the elements of a binary tree requires access
+ to many ->left, ->right, ->parent pointers. However, the rebalancing
+ code for insertion and deletion in an AVL or red-black tree is so
+ complicated that we cannot assume that >left, ->right, ->parent pointers
+ are in a consistent state throughout these operations. Therefore, to
+ avoid a crash in the signal handler, all destructive operations to the
+ lists would have to be protected by a
+ block_fatal_signals ();
+ ...
+ unblock_fatal_signals ();
+ pair. Which causes extra system calls.
+
+ Criterion 3) would also discourage GL_ARRAY_LIST and GL_CARRAY_LIST,
+ if they were not already excluded. Namely, these implementations use
+ xrealloc(), leaving a time window in which in the list->elements pointer
+ points to already deallocated memory. To avoid a crash in the signal
+ handler at such a moment, all destructive operations would have to
+ protected by block/unblock_fatal_signals (), in this case too.
+
+ A list of type GL_LINKEDHASH_LIST without duplicates fulfills all
+ requirements:
+ 2) Insertion and deletion are O(1) on average.
+ 3) The gl_list_iterator, gl_list_iterator_next implementations do
+ not trigger memory allocations, nor other system calls, and are
+ therefore safe to be called from a signal handler.
+ Furthermore, since SIGNAL_SAFE_LIST is defined, the implementation
+ of the destructive functions ensures that the list structure is
+ safe to be traversed at any moment, even when interrupted by an
+ asynchronous signal.
+ */
+
+/* String equality and hash code functions used by the lists. */
+
+static bool
+string_equals (const void *x1, const void *x2)
+{
+ const char *s1 = (const char *) x1;
+ const char *s2 = (const char *) x2;
+ return strcmp (s1, s2) == 0;
+}
+
+#define SIZE_BITS (sizeof (size_t) * CHAR_BIT)
+
+/* A hash function for NUL-terminated char* strings using
+ the method described by Bruno Haible.
+ See http://www.haible.de/bruno/hashfunc.html. */
+static size_t
+string_hash (const void *x)
+{
+ const char *s = (const char *) x;
+ size_t h = 0;
+
+ for (; *s; s++)
+ h = *s + ((h << 9) | (h >> (SIZE_BITS - 9)));
+
+ return h;
+}
+
+
+/* The signal handler. It gets called asynchronously. */
+static void
+cleanup ()
+{
+ size_t i;
+
+ /* First close all file descriptors to temporary files. */
+ {
+ gl_list_t fds = descriptors;
+
+ if (fds != NULL)
+ {
+ gl_list_iterator_t iter;
+ const void *element;
+
+ iter = gl_list_iterator (fds);
+ while (gl_list_iterator_next (&iter, &element, NULL))
+ {
+ int fd = (int) (uintptr_t) element;
+ close (fd);
+ }
+ gl_list_iterator_free (&iter);
+ }
+ }
+
+ for (i = 0; i < cleanup_list.tempdir_count; i++)
+ {
+ struct tempdir *dir = cleanup_list.tempdir_list[i];
+
+ if (dir != NULL)
+ {
+ gl_list_iterator_t iter;
+ const void *element;
+
+ /* First cleanup the files in the subdirectories. */
+ iter = gl_list_iterator (dir->files);
+ while (gl_list_iterator_next (&iter, &element, NULL))
+ {
+ const char *file = (const char *) element;
+ unlink (file);
+ }
+ gl_list_iterator_free (&iter);
+
+ /* Then cleanup the subdirectories. */
+ iter = gl_list_iterator (dir->subdirs);
+ while (gl_list_iterator_next (&iter, &element, NULL))
+ {
+ const char *subdir = (const char *) element;
+ rmdir (subdir);
+ }
+ gl_list_iterator_free (&iter);
+
+ /* Then cleanup the temporary directory itself. */
+ rmdir (dir->dirname);
+ }
+ }
+}
+
+/* Create a temporary directory.
+ PREFIX is used as a prefix for the name of the temporary directory. It
+ should be short and still give an indication about the program.
+ PARENTDIR can be used to specify the parent directory; if NULL, a default
+ parent directory is used (either $TMPDIR or /tmp or similar).
+ CLEANUP_VERBOSE determines whether errors during explicit cleanup are
+ reported to standard error.
+ Return a fresh 'struct temp_dir' on success. Upon error, an error message
+ is shown and NULL is returned. */
+struct temp_dir *
+create_temp_dir (const char *prefix, const char *parentdir,
+ bool cleanup_verbose)
+{
+ struct tempdir * volatile *tmpdirp = NULL;
+ struct tempdir *tmpdir;
+ size_t i;
+ char *xtemplate;
+ char *tmpdirname;
+
+ /* See whether it can take the slot of an earlier temporary directory
+ already cleaned up. */
+ for (i = 0; i < cleanup_list.tempdir_count; i++)
+ if (cleanup_list.tempdir_list[i] == NULL)
+ {
+ tmpdirp = &cleanup_list.tempdir_list[i];
+ break;
+ }
+ if (tmpdirp == NULL)
+ {
+ /* See whether the array needs to be extended. */
+ if (cleanup_list.tempdir_count == cleanup_list.tempdir_allocated)
+ {
+ /* Note that we cannot use xrealloc(), because then the cleanup()
+ function could access an already deallocated array. */
+ struct tempdir * volatile *old_array = cleanup_list.tempdir_list;
+ size_t old_allocated = cleanup_list.tempdir_allocated;
+ size_t new_allocated = 2 * cleanup_list.tempdir_allocated + 1;
+ struct tempdir * volatile *new_array =
+ XNMALLOC (new_allocated, struct tempdir * volatile);
+
+ if (old_allocated == 0)
+ /* First use of this facility. Register the cleanup handler. */
+ at_fatal_signal (&cleanup);
+ else
+ {
+ /* Don't use memcpy() here, because memcpy takes non-volatile
+ arguments and is therefore not guaranteed to complete all
+ memory stores before the next statement. */
+ size_t k;
+
+ for (k = 0; k < old_allocated; k++)
+ new_array[k] = old_array[k];
+ }
+
+ cleanup_list.tempdir_list = new_array;
+ cleanup_list.tempdir_allocated = new_allocated;
+
+ /* Now we can free the old array. */
+ if (old_array != NULL)
+ free ((struct tempdir **) old_array);
+ }
+
+ tmpdirp = &cleanup_list.tempdir_list[cleanup_list.tempdir_count];
+ /* Initialize *tmpdirp before incrementing tempdir_count, so that
+ cleanup() will skip this entry before it is fully initialized. */
+ *tmpdirp = NULL;
+ cleanup_list.tempdir_count++;
+ }
+
+ /* Initialize a 'struct tempdir'. */
+ tmpdir = XMALLOC (struct tempdir);
+ tmpdir->dirname = NULL;
+ tmpdir->cleanup_verbose = cleanup_verbose;
+ tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST,
+ string_equals, string_hash, NULL,
+ false);
+ tmpdir->files = gl_list_create_empty (GL_LINKEDHASH_LIST,
+ string_equals, string_hash, NULL,
+ false);
+
+ /* Create the temporary directory. */
+ xtemplate = (char *) xmalloca (PATH_MAX);
+ if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL))
+ {
+ error (0, errno,
+ _("cannot find a temporary directory, try setting $TMPDIR"));
+ goto quit;
+ }
+ block_fatal_signals ();
+ tmpdirname = mkdtemp (xtemplate);
+ if (tmpdirname != NULL)
+ {
+ tmpdir->dirname = tmpdirname;
+ *tmpdirp = tmpdir;
+ }
+ unblock_fatal_signals ();
+ if (tmpdirname == NULL)
+ {
+ error (0, errno,
+ _("cannot create a temporary directory using template \"%s\""),
+ xtemplate);
+ goto quit;
+ }
+ /* Replace tmpdir->dirname with a copy that has indefinite extent.
+ We cannot do this inside the block_fatal_signals/unblock_fatal_signals
+ block because then the cleanup handler would not remove the directory
+ if xstrdup fails. */
+ tmpdir->dirname = xstrdup (tmpdirname);
+ freea (xtemplate);
+ return (struct temp_dir *) tmpdir;
+
+ quit:
+ freea (xtemplate);
+ return NULL;
+}
+
+/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
+ needs to be removed before DIR can be removed.
+ Should be called before the file ABSOLUTE_FILE_NAME is created. */
+void
+register_temp_file (struct temp_dir *dir,
+ const char *absolute_file_name)
+{
+ struct tempdir *tmpdir = (struct tempdir *)dir;
+
+ /* Add absolute_file_name to tmpdir->files, without duplicates. */
+ if (gl_list_search (tmpdir->files, absolute_file_name) == NULL)
+ gl_list_add_first (tmpdir->files, xstrdup (absolute_file_name));
+}
+
+/* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
+ needs to be removed before DIR can be removed.
+ Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
+void
+unregister_temp_file (struct temp_dir *dir,
+ const char *absolute_file_name)
+{
+ struct tempdir *tmpdir = (struct tempdir *)dir;
+ gl_list_t list = tmpdir->files;
+ gl_list_node_t node;
+
+ node = gl_list_search (list, absolute_file_name);
+ if (node != NULL)
+ {
+ char *old_string = (char *) gl_list_node_value (list, node);
+
+ gl_list_remove_node (list, node);
+ free (old_string);
+ }
+}
+
+/* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
+ that needs to be removed before DIR can be removed.
+ Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
+void
+register_temp_subdir (struct temp_dir *dir,
+ const char *absolute_dir_name)
+{
+ struct tempdir *tmpdir = (struct tempdir *)dir;
+
+ /* Add absolute_dir_name to tmpdir->subdirs, without duplicates. */
+ if (gl_list_search (tmpdir->subdirs, absolute_dir_name) == NULL)
+ gl_list_add_first (tmpdir->subdirs, xstrdup (absolute_dir_name));
+}
+
+/* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
+ that needs to be removed before DIR can be removed.
+ Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be
+ created. */
+void
+unregister_temp_subdir (struct temp_dir *dir,
+ const char *absolute_dir_name)
+{
+ struct tempdir *tmpdir = (struct tempdir *)dir;
+ gl_list_t list = tmpdir->subdirs;
+ gl_list_node_t node;
+
+ node = gl_list_search (list, absolute_dir_name);
+ if (node != NULL)
+ {
+ char *old_string = (char *) gl_list_node_value (list, node);
+
+ gl_list_remove_node (list, node);
+ free (old_string);
+ }
+}
+
+/* Remove a file, with optional error message.
+ Return 0 upon success, or -1 if there was some problem. */
+static int
+do_unlink (struct temp_dir *dir, const char *absolute_file_name)
+{
+ if (unlink (absolute_file_name) < 0 && dir->cleanup_verbose
+ && errno != ENOENT)
+ {
+ error (0, errno, _("cannot remove temporary file %s"), absolute_file_name);
+ return -1;
+ }
+ return 0;
+}
+
+/* Remove a directory, with optional error message.
+ Return 0 upon success, or -1 if there was some problem. */
+static int
+do_rmdir (struct temp_dir *dir, const char *absolute_dir_name)
+{
+ if (rmdir (absolute_dir_name) < 0 && dir->cleanup_verbose
+ && errno != ENOENT)
+ {
+ error (0, errno,
+ _("cannot remove temporary directory %s"), absolute_dir_name);
+ return -1;
+ }
+ return 0;
+}
+
+/* Remove the given ABSOLUTE_FILE_NAME and unregister it.
+ Return 0 upon success, or -1 if there was some problem. */
+int
+cleanup_temp_file (struct temp_dir *dir,
+ const char *absolute_file_name)
+{
+ int err;
+
+ err = do_unlink (dir, absolute_file_name);
+ unregister_temp_file (dir, absolute_file_name);
+
+ return err;
+}
+
+/* Remove the given ABSOLUTE_DIR_NAME and unregister it.
+ Return 0 upon success, or -1 if there was some problem. */
+int
+cleanup_temp_subdir (struct temp_dir *dir,
+ const char *absolute_dir_name)
+{
+ int err;
+
+ err = do_rmdir (dir, absolute_dir_name);
+ unregister_temp_subdir (dir, absolute_dir_name);
+
+ return err;
+}
+
+/* Remove all registered files and subdirectories inside DIR.
+ Return 0 upon success, or -1 if there was some problem. */
+int
+cleanup_temp_dir_contents (struct temp_dir *dir)
+{
+ struct tempdir *tmpdir = (struct tempdir *)dir;
+ int err = 0;
+ gl_list_t list;
+ gl_list_iterator_t iter;
+ const void *element;
+ gl_list_node_t node;
+
+ /* First cleanup the files in the subdirectories. */
+ list = tmpdir->files;
+ iter = gl_list_iterator (list);
+ while (gl_list_iterator_next (&iter, &element, &node))
+ {
+ char *file = (char *) element;
+
+ err |= do_unlink (dir, file);
+ gl_list_remove_node (list, node);
+ /* Now only we can free file. */
+ free (file);
+ }
+ gl_list_iterator_free (&iter);
+
+ /* Then cleanup the subdirectories. */
+ list = tmpdir->subdirs;
+ iter = gl_list_iterator (list);
+ while (gl_list_iterator_next (&iter, &element, &node))
+ {
+ char *subdir = (char *) element;
+
+ err |= do_rmdir (dir, subdir);
+ gl_list_remove_node (list, node);
+ /* Now only we can free subdir. */
+ free (subdir);
+ }
+ gl_list_iterator_free (&iter);
+
+ return err;
+}
+
+/* Remove all registered files and subdirectories inside DIR and DIR itself.
+ DIR cannot be used any more after this call.
+ Return 0 upon success, or -1 if there was some problem. */
+int
+cleanup_temp_dir (struct temp_dir *dir)
+{
+ struct tempdir *tmpdir = (struct tempdir *)dir;
+ int err = 0;
+ size_t i;
+
+ err |= cleanup_temp_dir_contents (dir);
+ err |= do_rmdir (dir, tmpdir->dirname);
+
+ for (i = 0; i < cleanup_list.tempdir_count; i++)
+ if (cleanup_list.tempdir_list[i] == tmpdir)
+ {
+ /* Remove cleanup_list.tempdir_list[i]. */
+ if (i + 1 == cleanup_list.tempdir_count)
+ {
+ while (i > 0 && cleanup_list.tempdir_list[i - 1] == NULL)
+ i--;
+ cleanup_list.tempdir_count = i;
+ }
+ else
+ cleanup_list.tempdir_list[i] = NULL;
+ /* Now only we can free the tmpdir->dirname, tmpdir->subdirs,
+ tmpdir->files, and tmpdir itself. */
+ gl_list_free (tmpdir->files);
+ gl_list_free (tmpdir->subdirs);
+ free (tmpdir->dirname);
+ free (tmpdir);
+ return err;
+ }
+
+ /* The user passed an invalid DIR argument. */
+ abort ();
+}
+
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* On Windows, opening a file with _O_TEMPORARY has the effect of passing
+ the FILE_FLAG_DELETE_ON_CLOSE flag to CreateFile(), which has the effect
+ of deleting the file when it is closed - even when the program crashes.
+ But (according to the Cygwin sources) it works only on Windows NT or newer.
+ So we cache the info whether we are running on Windows NT or newer. */
+
+static bool
+supports_delete_on_close ()
+{
+ static int known; /* 1 = yes, -1 = no, 0 = unknown */
+ /* M4 wants to close and later reopen a temporary file, so
+ delete-on-close must not be used. */
+ known = -1;
+ if (!known)
+ {
+ OSVERSIONINFO v;
+
+ /* According to
+ <http://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx>
+ this structure must be initialised as follows: */
+ v.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+
+ if (GetVersionEx (&v))
+ known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1);
+ else
+ known = -1;
+ }
+ return (known > 0);
+}
+
+#endif
+
+
+/* Register a file descriptor to be closed. */
+static void
+register_fd (int fd)
+{
+ if (descriptors == NULL)
+ descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL,
+ false);
+ gl_list_add_first (descriptors, (void *) (uintptr_t) fd);
+}
+
+/* Unregister a file descriptor to be closed. */
+static void
+unregister_fd (int fd)
+{
+ gl_list_t fds = descriptors;
+ gl_list_node_t node;
+
+ if (fds == NULL)
+ /* descriptors should already contain fd. */
+ abort ();
+ node = gl_list_search (fds, (void *) (uintptr_t) fd);
+ if (node == NULL)
+ /* descriptors should already contain fd. */
+ abort ();
+ gl_list_remove_node (fds, node);
+}
+
+/* Open a temporary file in a temporary directory.
+ Registers the resulting file descriptor to be closed. */
+int
+open_temp (const char *file_name, int flags, mode_t mode)
+{
+ int fd;
+ int saved_errno;
+
+ block_fatal_signals ();
+ /* Note: 'open' here is actually open() or open_safer(). */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ /* Use _O_TEMPORARY when possible, to increase the chances that the
+ temporary file is removed when the process crashes. */
+ if (supports_delete_on_close ())
+ fd = open (file_name, flags | _O_TEMPORARY, mode);
+ else
+#endif
+ fd = open (file_name, flags, mode);
+ saved_errno = errno;
+ if (fd >= 0)
+ register_fd (fd);
+ unblock_fatal_signals ();
+ errno = saved_errno;
+ return fd;
+}
+
+/* Open a temporary file in a temporary directory.
+ Registers the resulting file descriptor to be closed. */
+FILE *
+fopen_temp (const char *file_name, const char *mode)
+{
+ FILE *fp;
+ int saved_errno;
+
+ block_fatal_signals ();
+ /* Note: 'fopen' here is actually fopen() or fopen_safer(). */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ /* Use _O_TEMPORARY when possible, to increase the chances that the
+ temporary file is removed when the process crashes. */
+ if (supports_delete_on_close ())
+ {
+ size_t mode_len = strlen (mode);
+ char *augmented_mode = (char *) xmalloca (mode_len + 2);
+ memcpy (augmented_mode, mode, mode_len);
+ memcpy (augmented_mode + mode_len, "D", 2);
+
+ fp = fopen (file_name, augmented_mode);
+ saved_errno = errno;
+
+ freea (augmented_mode);
+ }
+ else
+#endif
+ {
+ fp = fopen (file_name, mode);
+ saved_errno = errno;
+ }
+ if (fp != NULL)
+ {
+ /* It is sufficient to register fileno (fp) instead of the entire fp,
+ because at cleanup time there is no need to do an fflush (fp); a
+ close (fileno (fp)) will be enough. */
+ int fd = fileno (fp);
+ if (!(fd >= 0))
+ abort ();
+ register_fd (fd);
+ }
+ unblock_fatal_signals ();
+ errno = saved_errno;
+ return fp;
+}
+
+/* Close a temporary file in a temporary directory.
+ Unregisters the previously registered file descriptor. */
+int
+close_temp (int fd)
+{
+ if (fd >= 0)
+ {
+ /* No blocking of signals is needed here, since a double close of a
+ file descriptor is harmless. */
+ int result = close (fd);
+ int saved_errno = errno;
+
+ /* No race condition here: we assume a single-threaded program, hence
+ fd cannot be re-opened here. */
+
+ unregister_fd (fd);
+
+ errno = saved_errno;
+ return result;
+ }
+ else
+ return close (fd);
+}
+
+/* Close a temporary file in a temporary directory.
+ Unregisters the previously registered file descriptor. */
+int
+fclose_temp (FILE *fp)
+{
+ int fd = fileno (fp);
+ /* No blocking of signals is needed here, since a double close of a
+ file descriptor is harmless. */
+ int result = fclose (fp);
+ int saved_errno = errno;
+
+ /* No race condition here: we assume a single-threaded program, hence
+ fd cannot be re-opened here. */
+
+ unregister_fd (fd);
+
+ errno = saved_errno;
+ return result;
+}
+
+#if GNULIB_FWRITEERROR
+/* Like fwriteerror.
+ Unregisters the previously registered file descriptor. */
+int
+fwriteerror_temp (FILE *fp)
+{
+ int fd = fileno (fp);
+ /* No blocking of signals is needed here, since a double close of a
+ file descriptor is harmless. */
+ int result = fwriteerror (fp);
+ int saved_errno = errno;
+
+ /* No race condition here: we assume a single-threaded program, hence
+ fd cannot be re-opened here. */
+
+ unregister_fd (fd);
+
+ errno = saved_errno;
+ return result;
+}
+#endif
+
+#if GNULIB_CLOSE_STREAM
+/* Like close_stream.
+ Unregisters the previously registered file descriptor. */
+int
+close_stream_temp (FILE *fp)
+{
+ int fd = fileno (fp);
+ /* No blocking of signals is needed here, since a double close of a
+ file descriptor is harmless. */
+ int result = close_stream (fp);
+ int saved_errno = errno;
+
+ /* No race condition here: we assume a single-threaded program, hence
+ fd cannot be re-opened here. */
+
+ unregister_fd (fd);
+
+ errno = saved_errno;
+ return result;
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/clean-temp.h b/contrib/tools/bison/gnulib/src/clean-temp.h
index 24aeca83eb..536359dc3c 100644
--- a/contrib/tools/bison/gnulib/src/clean-temp.h
+++ b/contrib/tools/bison/gnulib/src/clean-temp.h
@@ -1,142 +1,142 @@
-/* Temporary directories and temporary files with automatic cleanup.
- Copyright (C) 2006, 2011-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _CLEAN_TEMP_H
-#define _CLEAN_TEMP_H
-
-#include <stdbool.h>
-#include <stdio.h>
-#include <sys/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Temporary directories and temporary files should be automatically removed
- when the program exits either normally or through a fatal signal. We can't
- rely on the "unlink before close" idiom, because it works only on Unix and
- also - if no signal blocking is used - leaves a time window where a fatal
- signal would not clean up the temporary file.
-
- Also, open file descriptors need to be closed before the temporary files
- and the temporary directories can be removed, because only on Unix
- (excluding Cygwin) can one remove directories containing open files.
-
- This module provides support for temporary directories and temporary files
- inside these temporary directories. Temporary files without temporary
- directories are not supported here. The temporary directories and files
- are automatically cleaned up (at the latest) when the program exits or
- dies from a fatal signal such as SIGINT, SIGTERM, SIGHUP, but not if it
- dies from a fatal signal such as SIGQUIT, SIGKILL, or SIGABRT, SIGSEGV,
- SIGBUS, SIGILL, SIGFPE.
-
- For the cleanup in the normal case, programs that use this module need to
- call 'cleanup_temp_dir' for each successful return of 'create_temp_dir'.
- The cleanup in the case of a fatal signal such as SIGINT, SIGTERM, SIGHUP,
- is done entirely automatically by the functions of this module. */
-
-struct temp_dir
-{
- /* The absolute pathname of the directory. */
- const char * const dir_name;
- /* Whether errors during explicit cleanup are reported to standard error. */
- bool cleanup_verbose;
- /* More fields are present here, but not public. */
-};
-
-/* Create a temporary directory.
- PREFIX is used as a prefix for the name of the temporary directory. It
- should be short and still give an indication about the program.
- PARENTDIR can be used to specify the parent directory; if NULL, a default
- parent directory is used (either $TMPDIR or /tmp or similar).
- CLEANUP_VERBOSE determines whether errors during explicit cleanup are
- reported to standard error.
- Return a fresh 'struct temp_dir' on success. Upon error, an error message
- is shown and NULL is returned. */
-extern struct temp_dir * create_temp_dir (const char *prefix,
- const char *parentdir,
- bool cleanup_verbose);
-
-/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
- needs to be removed before DIR can be removed.
- Should be called before the file ABSOLUTE_FILE_NAME is created. */
-extern void register_temp_file (struct temp_dir *dir,
- const char *absolute_file_name);
-
-/* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
- needs to be removed before DIR can be removed.
- Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
-extern void unregister_temp_file (struct temp_dir *dir,
- const char *absolute_file_name);
-
-/* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
- that needs to be removed before DIR can be removed.
- Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
-extern void register_temp_subdir (struct temp_dir *dir,
- const char *absolute_dir_name);
-
-/* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
- that needs to be removed before DIR can be removed.
- Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be
- created. */
-extern void unregister_temp_subdir (struct temp_dir *dir,
- const char *absolute_dir_name);
-
-/* Remove the given ABSOLUTE_FILE_NAME and unregister it.
- Return 0 upon success, or -1 if there was some problem. */
-extern int cleanup_temp_file (struct temp_dir *dir,
- const char *absolute_file_name);
-
-/* Remove the given ABSOLUTE_DIR_NAME and unregister it.
- Return 0 upon success, or -1 if there was some problem. */
-extern int cleanup_temp_subdir (struct temp_dir *dir,
- const char *absolute_dir_name);
-
-/* Remove all registered files and subdirectories inside DIR.
- Return 0 upon success, or -1 if there was some problem. */
-extern int cleanup_temp_dir_contents (struct temp_dir *dir);
-
-/* Remove all registered files and subdirectories inside DIR and DIR itself.
- DIR cannot be used any more after this call.
- Return 0 upon success, or -1 if there was some problem. */
-extern int cleanup_temp_dir (struct temp_dir *dir);
-
-/* Open a temporary file in a temporary directory.
- Registers the resulting file descriptor to be closed. */
-extern int open_temp (const char *file_name, int flags, mode_t mode);
-extern FILE * fopen_temp (const char *file_name, const char *mode);
-
-/* Close a temporary file in a temporary directory.
- Unregisters the previously registered file descriptor. */
-extern int close_temp (int fd);
-extern int fclose_temp (FILE *fp);
-
-/* Like fwriteerror.
- Unregisters the previously registered file descriptor. */
-extern int fwriteerror_temp (FILE *fp);
-
-/* Like close_stream.
- Unregisters the previously registered file descriptor. */
-extern int close_stream_temp (FILE *fp);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CLEAN_TEMP_H */
+/* Temporary directories and temporary files with automatic cleanup.
+ Copyright (C) 2006, 2011-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _CLEAN_TEMP_H
+#define _CLEAN_TEMP_H
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Temporary directories and temporary files should be automatically removed
+ when the program exits either normally or through a fatal signal. We can't
+ rely on the "unlink before close" idiom, because it works only on Unix and
+ also - if no signal blocking is used - leaves a time window where a fatal
+ signal would not clean up the temporary file.
+
+ Also, open file descriptors need to be closed before the temporary files
+ and the temporary directories can be removed, because only on Unix
+ (excluding Cygwin) can one remove directories containing open files.
+
+ This module provides support for temporary directories and temporary files
+ inside these temporary directories. Temporary files without temporary
+ directories are not supported here. The temporary directories and files
+ are automatically cleaned up (at the latest) when the program exits or
+ dies from a fatal signal such as SIGINT, SIGTERM, SIGHUP, but not if it
+ dies from a fatal signal such as SIGQUIT, SIGKILL, or SIGABRT, SIGSEGV,
+ SIGBUS, SIGILL, SIGFPE.
+
+ For the cleanup in the normal case, programs that use this module need to
+ call 'cleanup_temp_dir' for each successful return of 'create_temp_dir'.
+ The cleanup in the case of a fatal signal such as SIGINT, SIGTERM, SIGHUP,
+ is done entirely automatically by the functions of this module. */
+
+struct temp_dir
+{
+ /* The absolute pathname of the directory. */
+ const char * const dir_name;
+ /* Whether errors during explicit cleanup are reported to standard error. */
+ bool cleanup_verbose;
+ /* More fields are present here, but not public. */
+};
+
+/* Create a temporary directory.
+ PREFIX is used as a prefix for the name of the temporary directory. It
+ should be short and still give an indication about the program.
+ PARENTDIR can be used to specify the parent directory; if NULL, a default
+ parent directory is used (either $TMPDIR or /tmp or similar).
+ CLEANUP_VERBOSE determines whether errors during explicit cleanup are
+ reported to standard error.
+ Return a fresh 'struct temp_dir' on success. Upon error, an error message
+ is shown and NULL is returned. */
+extern struct temp_dir * create_temp_dir (const char *prefix,
+ const char *parentdir,
+ bool cleanup_verbose);
+
+/* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
+ needs to be removed before DIR can be removed.
+ Should be called before the file ABSOLUTE_FILE_NAME is created. */
+extern void register_temp_file (struct temp_dir *dir,
+ const char *absolute_file_name);
+
+/* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
+ needs to be removed before DIR can be removed.
+ Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
+extern void unregister_temp_file (struct temp_dir *dir,
+ const char *absolute_file_name);
+
+/* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
+ that needs to be removed before DIR can be removed.
+ Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
+extern void register_temp_subdir (struct temp_dir *dir,
+ const char *absolute_dir_name);
+
+/* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
+ that needs to be removed before DIR can be removed.
+ Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be
+ created. */
+extern void unregister_temp_subdir (struct temp_dir *dir,
+ const char *absolute_dir_name);
+
+/* Remove the given ABSOLUTE_FILE_NAME and unregister it.
+ Return 0 upon success, or -1 if there was some problem. */
+extern int cleanup_temp_file (struct temp_dir *dir,
+ const char *absolute_file_name);
+
+/* Remove the given ABSOLUTE_DIR_NAME and unregister it.
+ Return 0 upon success, or -1 if there was some problem. */
+extern int cleanup_temp_subdir (struct temp_dir *dir,
+ const char *absolute_dir_name);
+
+/* Remove all registered files and subdirectories inside DIR.
+ Return 0 upon success, or -1 if there was some problem. */
+extern int cleanup_temp_dir_contents (struct temp_dir *dir);
+
+/* Remove all registered files and subdirectories inside DIR and DIR itself.
+ DIR cannot be used any more after this call.
+ Return 0 upon success, or -1 if there was some problem. */
+extern int cleanup_temp_dir (struct temp_dir *dir);
+
+/* Open a temporary file in a temporary directory.
+ Registers the resulting file descriptor to be closed. */
+extern int open_temp (const char *file_name, int flags, mode_t mode);
+extern FILE * fopen_temp (const char *file_name, const char *mode);
+
+/* Close a temporary file in a temporary directory.
+ Unregisters the previously registered file descriptor. */
+extern int close_temp (int fd);
+extern int fclose_temp (FILE *fp);
+
+/* Like fwriteerror.
+ Unregisters the previously registered file descriptor. */
+extern int fwriteerror_temp (FILE *fp);
+
+/* Like close_stream.
+ Unregisters the previously registered file descriptor. */
+extern int close_stream_temp (FILE *fp);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CLEAN_TEMP_H */
diff --git a/contrib/tools/bison/gnulib/src/cloexec.c b/contrib/tools/bison/gnulib/src/cloexec.c
index e3e42d2855..f24711f096 100644
--- a/contrib/tools/bison/gnulib/src/cloexec.c
+++ b/contrib/tools/bison/gnulib/src/cloexec.c
@@ -1,83 +1,83 @@
-/* closexec.c - set or clear the close-on-exec descriptor flag
-
- Copyright (C) 1991, 2004-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- The code is taken from glibc/manual/llio.texi */
-
-#include <config.h>
-
-#include "cloexec.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
- or clear the flag if VALUE is false.
- Return 0 on success, or -1 on error with 'errno' set.
-
- Note that on MingW, this function does NOT protect DESC from being
- inherited into spawned children. Instead, either use dup_cloexec
- followed by closing the original DESC, or use interfaces such as
- open or pipe2 that accept flags like O_CLOEXEC to create DESC
- non-inheritable in the first place. */
-
-int
-set_cloexec_flag (int desc, bool value)
-{
-#ifdef F_SETFD
-
- int flags = fcntl (desc, F_GETFD, 0);
-
- if (0 <= flags)
- {
- int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
-
- if (flags == newflags
- || fcntl (desc, F_SETFD, newflags) != -1)
- return 0;
- }
-
- return -1;
-
-#else /* !F_SETFD */
-
- /* Use dup2 to reject invalid file descriptors; the cloexec flag
- will be unaffected. */
- if (desc < 0)
- {
- errno = EBADF;
- return -1;
- }
- if (dup2 (desc, desc) < 0)
- /* errno is EBADF here. */
- return -1;
-
- /* There is nothing we can do on this kind of platform. Punt. */
- return 0;
-#endif /* !F_SETFD */
-}
-
-
-/* Duplicates a file handle FD, while marking the copy to be closed
- prior to exec or spawn. Returns -1 and sets errno if FD could not
- be duplicated. */
-
-int
-dup_cloexec (int fd)
-{
- return fcntl (fd, F_DUPFD_CLOEXEC, 0);
-}
+/* closexec.c - set or clear the close-on-exec descriptor flag
+
+ Copyright (C) 1991, 2004-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ The code is taken from glibc/manual/llio.texi */
+
+#include <config.h>
+
+#include "cloexec.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
+ or clear the flag if VALUE is false.
+ Return 0 on success, or -1 on error with 'errno' set.
+
+ Note that on MingW, this function does NOT protect DESC from being
+ inherited into spawned children. Instead, either use dup_cloexec
+ followed by closing the original DESC, or use interfaces such as
+ open or pipe2 that accept flags like O_CLOEXEC to create DESC
+ non-inheritable in the first place. */
+
+int
+set_cloexec_flag (int desc, bool value)
+{
+#ifdef F_SETFD
+
+ int flags = fcntl (desc, F_GETFD, 0);
+
+ if (0 <= flags)
+ {
+ int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
+
+ if (flags == newflags
+ || fcntl (desc, F_SETFD, newflags) != -1)
+ return 0;
+ }
+
+ return -1;
+
+#else /* !F_SETFD */
+
+ /* Use dup2 to reject invalid file descriptors; the cloexec flag
+ will be unaffected. */
+ if (desc < 0)
+ {
+ errno = EBADF;
+ return -1;
+ }
+ if (dup2 (desc, desc) < 0)
+ /* errno is EBADF here. */
+ return -1;
+
+ /* There is nothing we can do on this kind of platform. Punt. */
+ return 0;
+#endif /* !F_SETFD */
+}
+
+
+/* Duplicates a file handle FD, while marking the copy to be closed
+ prior to exec or spawn. Returns -1 and sets errno if FD could not
+ be duplicated. */
+
+int
+dup_cloexec (int fd)
+{
+ return fcntl (fd, F_DUPFD_CLOEXEC, 0);
+}
diff --git a/contrib/tools/bison/gnulib/src/cloexec.h b/contrib/tools/bison/gnulib/src/cloexec.h
index 0c5935ba56..66b404a14a 100644
--- a/contrib/tools/bison/gnulib/src/cloexec.h
+++ b/contrib/tools/bison/gnulib/src/cloexec.h
@@ -1,38 +1,38 @@
-/* closexec.c - set or clear the close-on-exec descriptor flag
-
- Copyright (C) 2004, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include <stdbool.h>
-
-/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
- or clear the flag if VALUE is false.
- Return 0 on success, or -1 on error with 'errno' set.
-
- Note that on MingW, this function does NOT protect DESC from being
- inherited into spawned children. Instead, either use dup_cloexec
- followed by closing the original DESC, or use interfaces such as
- open or pipe2 that accept flags like O_CLOEXEC to create DESC
- non-inheritable in the first place. */
-
-int set_cloexec_flag (int desc, bool value);
-
-/* Duplicates a file handle FD, while marking the copy to be closed
- prior to exec or spawn. Returns -1 and sets errno if FD could not
- be duplicated. */
-
-int dup_cloexec (int fd);
+/* closexec.c - set or clear the close-on-exec descriptor flag
+
+ Copyright (C) 2004, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <stdbool.h>
+
+/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
+ or clear the flag if VALUE is false.
+ Return 0 on success, or -1 on error with 'errno' set.
+
+ Note that on MingW, this function does NOT protect DESC from being
+ inherited into spawned children. Instead, either use dup_cloexec
+ followed by closing the original DESC, or use interfaces such as
+ open or pipe2 that accept flags like O_CLOEXEC to create DESC
+ non-inheritable in the first place. */
+
+int set_cloexec_flag (int desc, bool value);
+
+/* Duplicates a file handle FD, while marking the copy to be closed
+ prior to exec or spawn. Returns -1 and sets errno if FD could not
+ be duplicated. */
+
+int dup_cloexec (int fd);
diff --git a/contrib/tools/bison/gnulib/src/close-stream.c b/contrib/tools/bison/gnulib/src/close-stream.c
index d6a869287e..e722517963 100644
--- a/contrib/tools/bison/gnulib/src/close-stream.c
+++ b/contrib/tools/bison/gnulib/src/close-stream.c
@@ -1,78 +1,78 @@
-/* Close a stream, with nicer error checking than fclose's.
-
- Copyright (C) 1998-2002, 2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "close-stream.h"
-
-#include <errno.h>
-#include <stdbool.h>
-
-#include "fpending.h"
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-/* Close STREAM. Return 0 if successful, EOF (setting errno)
- otherwise. A failure might set errno to 0 if the error number
- cannot be determined.
-
- A failure with errno set to EPIPE may or may not indicate an error
- situation worth signaling to the user. See the documentation of the
- close_stdout_set_ignore_EPIPE function for details.
-
- If a program writes *anything* to STREAM, that program should close
- STREAM and make sure that it succeeds before exiting. Otherwise,
- suppose that you go to the extreme of checking the return status
- of every function that does an explicit write to STREAM. The last
- printf can succeed in writing to the internal stream buffer, and yet
- the fclose(STREAM) could still fail (due e.g., to a disk full error)
- when it tries to write out that buffered data. Thus, you would be
- left with an incomplete output file and the offending program would
- exit successfully. Even calling fflush is not always sufficient,
- since some file systems (NFS and CODA) buffer written/flushed data
- until an actual close call.
-
- Besides, it's wasteful to check the return value from every call
- that writes to STREAM -- just let the internal stream state record
- the failure. That's what the ferror test is checking below. */
-
-int
-close_stream (FILE *stream)
-{
- const bool some_pending = (__fpending (stream) != 0);
- const bool prev_fail = (ferror (stream) != 0);
- const bool fclose_fail = (fclose (stream) != 0);
-
- /* Return an error indication if there was a previous failure or if
- fclose failed, with one exception: ignore an fclose failure if
- there was no previous error, no data remains to be flushed, and
- fclose failed with EBADF. That can happen when a program like cp
- is invoked like this 'cp a b >&-' (i.e., with standard output
- closed) and doesn't generate any output (hence no previous error
- and nothing to be flushed). */
-
- if (prev_fail || (fclose_fail && (some_pending || errno != EBADF)))
- {
- if (! fclose_fail)
- errno = 0;
- return EOF;
- }
-
- return 0;
-}
+/* Close a stream, with nicer error checking than fclose's.
+
+ Copyright (C) 1998-2002, 2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "close-stream.h"
+
+#include <errno.h>
+#include <stdbool.h>
+
+#include "fpending.h"
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+/* Close STREAM. Return 0 if successful, EOF (setting errno)
+ otherwise. A failure might set errno to 0 if the error number
+ cannot be determined.
+
+ A failure with errno set to EPIPE may or may not indicate an error
+ situation worth signaling to the user. See the documentation of the
+ close_stdout_set_ignore_EPIPE function for details.
+
+ If a program writes *anything* to STREAM, that program should close
+ STREAM and make sure that it succeeds before exiting. Otherwise,
+ suppose that you go to the extreme of checking the return status
+ of every function that does an explicit write to STREAM. The last
+ printf can succeed in writing to the internal stream buffer, and yet
+ the fclose(STREAM) could still fail (due e.g., to a disk full error)
+ when it tries to write out that buffered data. Thus, you would be
+ left with an incomplete output file and the offending program would
+ exit successfully. Even calling fflush is not always sufficient,
+ since some file systems (NFS and CODA) buffer written/flushed data
+ until an actual close call.
+
+ Besides, it's wasteful to check the return value from every call
+ that writes to STREAM -- just let the internal stream state record
+ the failure. That's what the ferror test is checking below. */
+
+int
+close_stream (FILE *stream)
+{
+ const bool some_pending = (__fpending (stream) != 0);
+ const bool prev_fail = (ferror (stream) != 0);
+ const bool fclose_fail = (fclose (stream) != 0);
+
+ /* Return an error indication if there was a previous failure or if
+ fclose failed, with one exception: ignore an fclose failure if
+ there was no previous error, no data remains to be flushed, and
+ fclose failed with EBADF. That can happen when a program like cp
+ is invoked like this 'cp a b >&-' (i.e., with standard output
+ closed) and doesn't generate any output (hence no previous error
+ and nothing to be flushed). */
+
+ if (prev_fail || (fclose_fail && (some_pending || errno != EBADF)))
+ {
+ if (! fclose_fail)
+ errno = 0;
+ return EOF;
+ }
+
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/close-stream.h b/contrib/tools/bison/gnulib/src/close-stream.h
index be3d4196b0..fb60c82552 100644
--- a/contrib/tools/bison/gnulib/src/close-stream.h
+++ b/contrib/tools/bison/gnulib/src/close-stream.h
@@ -1,2 +1,2 @@
-#include <stdio.h>
-int close_stream (FILE *stream);
+#include <stdio.h>
+int close_stream (FILE *stream);
diff --git a/contrib/tools/bison/gnulib/src/close.c b/contrib/tools/bison/gnulib/src/close.c
index f620e54bba..f32fea9ee3 100644
--- a/contrib/tools/bison/gnulib/src/close.c
+++ b/contrib/tools/bison/gnulib/src/close.c
@@ -1,69 +1,69 @@
-/* close replacement.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <unistd.h>
-
-#include <errno.h>
-
-#include "fd-hook.h"
-#include "msvc-inval.h"
-
-#undef close
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-close_nothrow (int fd)
-{
- int result;
-
- TRY_MSVC_INVAL
- {
- result = close (fd);
- }
- CATCH_MSVC_INVAL
- {
- result = -1;
- errno = EBADF;
- }
- DONE_MSVC_INVAL;
-
- return result;
-}
-#else
-# define close_nothrow close
-#endif
-
-/* Override close() to call into other gnulib modules. */
-
-int
-rpl_close (int fd)
-{
-#if WINDOWS_SOCKETS
- int retval = execute_all_close_hooks (close_nothrow, fd);
-#else
- int retval = close_nothrow (fd);
-#endif
-
-#if REPLACE_FCHDIR
- if (retval >= 0)
- _gl_unregister_fd (fd);
-#endif
-
- return retval;
-}
+/* close replacement.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#include <errno.h>
+
+#include "fd-hook.h"
+#include "msvc-inval.h"
+
+#undef close
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+close_nothrow (int fd)
+{
+ int result;
+
+ TRY_MSVC_INVAL
+ {
+ result = close (fd);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = -1;
+ errno = EBADF;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+#else
+# define close_nothrow close
+#endif
+
+/* Override close() to call into other gnulib modules. */
+
+int
+rpl_close (int fd)
+{
+#if WINDOWS_SOCKETS
+ int retval = execute_all_close_hooks (close_nothrow, fd);
+#else
+ int retval = close_nothrow (fd);
+#endif
+
+#if REPLACE_FCHDIR
+ if (retval >= 0)
+ _gl_unregister_fd (fd);
+#endif
+
+ return retval;
+}
diff --git a/contrib/tools/bison/gnulib/src/closein.c b/contrib/tools/bison/gnulib/src/closein.c
index c9bf73781f..3cd03874f0 100644
--- a/contrib/tools/bison/gnulib/src/closein.c
+++ b/contrib/tools/bison/gnulib/src/closein.c
@@ -1,112 +1,112 @@
-/* Close standard input, rewinding seekable stdin if necessary.
-
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "closein.h"
-
-#include <errno.h>
-#include <stdbool.h>
+/* Close standard input, rewinding seekable stdin if necessary.
+
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "closein.h"
+
+#include <errno.h>
+#include <stdbool.h>
#include "stdio--.h"
-#include <unistd.h>
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
-#include "close-stream.h"
-#include "closeout.h"
-#include "error.h"
-#include "exitfail.h"
-#include "freadahead.h"
-#include "quotearg.h"
-
-static const char *file_name;
-
-/* Set the file name to be reported in the event an error is detected
- on stdin by close_stdin. See also close_stdout_set_file_name, if
- an error is detected when closing stdout. */
-void
-close_stdin_set_file_name (const char *file)
-{
- file_name = file;
-}
-
-/* Close standard input, rewinding any unused input if stdin is
- seekable. On error, issue a diagnostic and _exit with status
- 'exit_failure'. Then call close_stdout.
-
- Most programs can get by with close_stdout. close_stdin is only
- needed when a program wants to guarantee that partially read input
- from seekable stdin is not consumed, for any subsequent clients.
- For example, POSIX requires that these two commands behave alike:
-
- (sed -ne 1q; cat) < file
- tail -n +2 file
-
- Since close_stdin is commonly registered via 'atexit', POSIX
- and the C standard both say that it should not call 'exit',
- because the behavior is undefined if 'exit' is called more than
- once. So it calls '_exit' instead of 'exit'. If close_stdin
- is registered via atexit before other functions are registered,
- the other functions can act before this _exit is invoked.
-
- Applications that use close_stdout should flush any streams other
- than stdin, stdout, and stderr before exiting, since the call to
- _exit will bypass other buffer flushing. Applications should be
- flushing and closing other streams anyway, to check for I/O errors.
- Also, applications should not use tmpfile, since _exit can bypass
- the removal of these files.
-
- It's important to detect such failures and exit nonzero because many
- tools (most notably 'make' and other build-management systems) depend
- on being able to detect failure in other tools via their exit status. */
-
-void
-close_stdin (void)
-{
- bool fail = false;
-
- /* There is no need to flush stdin if we can determine quickly that stdin's
- input buffer is empty; in this case we know that if stdin is seekable,
- (fseeko (stdin, 0, SEEK_CUR), ftello (stdin))
- == lseek (0, 0, SEEK_CUR). */
- if (freadahead (stdin) > 0)
- {
- /* Only attempt flush if stdin is seekable, as fflush is entitled to
- fail on non-seekable streams. */
- if (fseeko (stdin, 0, SEEK_CUR) == 0 && fflush (stdin) != 0)
- fail = true;
- }
- if (close_stream (stdin) != 0)
- fail = true;
- if (fail)
- {
- /* Report failure, but defer exit until after closing stdout,
- since the failure report should still be flushed. */
- char const *close_error = _("error closing file");
- if (file_name)
- error (0, errno, "%s: %s", quotearg_colon (file_name),
- close_error);
- else
- error (0, errno, "%s", close_error);
- }
-
- close_stdout ();
-
- if (fail)
- _exit (exit_failure);
-}
+#include <unistd.h>
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+#include "close-stream.h"
+#include "closeout.h"
+#include "error.h"
+#include "exitfail.h"
+#include "freadahead.h"
+#include "quotearg.h"
+
+static const char *file_name;
+
+/* Set the file name to be reported in the event an error is detected
+ on stdin by close_stdin. See also close_stdout_set_file_name, if
+ an error is detected when closing stdout. */
+void
+close_stdin_set_file_name (const char *file)
+{
+ file_name = file;
+}
+
+/* Close standard input, rewinding any unused input if stdin is
+ seekable. On error, issue a diagnostic and _exit with status
+ 'exit_failure'. Then call close_stdout.
+
+ Most programs can get by with close_stdout. close_stdin is only
+ needed when a program wants to guarantee that partially read input
+ from seekable stdin is not consumed, for any subsequent clients.
+ For example, POSIX requires that these two commands behave alike:
+
+ (sed -ne 1q; cat) < file
+ tail -n +2 file
+
+ Since close_stdin is commonly registered via 'atexit', POSIX
+ and the C standard both say that it should not call 'exit',
+ because the behavior is undefined if 'exit' is called more than
+ once. So it calls '_exit' instead of 'exit'. If close_stdin
+ is registered via atexit before other functions are registered,
+ the other functions can act before this _exit is invoked.
+
+ Applications that use close_stdout should flush any streams other
+ than stdin, stdout, and stderr before exiting, since the call to
+ _exit will bypass other buffer flushing. Applications should be
+ flushing and closing other streams anyway, to check for I/O errors.
+ Also, applications should not use tmpfile, since _exit can bypass
+ the removal of these files.
+
+ It's important to detect such failures and exit nonzero because many
+ tools (most notably 'make' and other build-management systems) depend
+ on being able to detect failure in other tools via their exit status. */
+
+void
+close_stdin (void)
+{
+ bool fail = false;
+
+ /* There is no need to flush stdin if we can determine quickly that stdin's
+ input buffer is empty; in this case we know that if stdin is seekable,
+ (fseeko (stdin, 0, SEEK_CUR), ftello (stdin))
+ == lseek (0, 0, SEEK_CUR). */
+ if (freadahead (stdin) > 0)
+ {
+ /* Only attempt flush if stdin is seekable, as fflush is entitled to
+ fail on non-seekable streams. */
+ if (fseeko (stdin, 0, SEEK_CUR) == 0 && fflush (stdin) != 0)
+ fail = true;
+ }
+ if (close_stream (stdin) != 0)
+ fail = true;
+ if (fail)
+ {
+ /* Report failure, but defer exit until after closing stdout,
+ since the failure report should still be flushed. */
+ char const *close_error = _("error closing file");
+ if (file_name)
+ error (0, errno, "%s: %s", quotearg_colon (file_name),
+ close_error);
+ else
+ error (0, errno, "%s", close_error);
+ }
+
+ close_stdout ();
+
+ if (fail)
+ _exit (exit_failure);
+}
diff --git a/contrib/tools/bison/gnulib/src/closein.h b/contrib/tools/bison/gnulib/src/closein.h
index 84bbeefceb..d173fe4d04 100644
--- a/contrib/tools/bison/gnulib/src/closein.h
+++ b/contrib/tools/bison/gnulib/src/closein.h
@@ -1,32 +1,32 @@
-/* Close standard input, rewinding seekable stdin if necessary.
-
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_CLOSEIN_H
-# define _GL_CLOSEIN_H 1
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-void close_stdin_set_file_name (const char *file);
-void close_stdin (void);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
+/* Close standard input, rewinding seekable stdin if necessary.
+
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_CLOSEIN_H
+# define _GL_CLOSEIN_H 1
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+void close_stdin_set_file_name (const char *file);
+void close_stdin (void);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/closeout.c b/contrib/tools/bison/gnulib/src/closeout.c
index d4d3edca4e..8fc1c341b0 100644
--- a/contrib/tools/bison/gnulib/src/closeout.c
+++ b/contrib/tools/bison/gnulib/src/closeout.c
@@ -1,124 +1,124 @@
-/* Close standard output and standard error, exiting with a diagnostic on error.
-
- Copyright (C) 1998-2002, 2004, 2006, 2008-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "closeout.h"
-
-#include <errno.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
-#include "close-stream.h"
-#include "error.h"
-#include "exitfail.h"
-#include "quotearg.h"
-
-static const char *file_name;
-
-/* Set the file name to be reported in the event an error is detected
- by close_stdout. */
-void
-close_stdout_set_file_name (const char *file)
-{
- file_name = file;
-}
-
-static bool ignore_EPIPE /* = false */;
-
-/* Specify the reaction to an EPIPE error during the closing of stdout:
- - If ignore = true, it shall be ignored.
- - If ignore = false, it shall evoke a diagnostic, along with a nonzero
- exit status.
- The default is ignore = false.
-
- This setting matters only if the SIGPIPE signal is ignored (i.e. its
- handler set to SIG_IGN) or blocked. Only particular programs need to
- temporarily ignore SIGPIPE. If SIGPIPE is ignored or blocked because
- it was ignored or blocked in the parent process when it created the
- child process, it usually is a bug in the parent process: It is bad
- practice to have SIGPIPE ignored or blocked while creating a child
- process.
-
- EPIPE occurs when writing to a pipe or socket that has no readers now,
- when SIGPIPE is ignored or blocked.
-
- The ignore = false setting is suitable for a scenario where it is normally
- guaranteed that the pipe writer terminates before the pipe reader. In
- this case, an EPIPE is an indication of a premature termination of the
- pipe reader and should lead to a diagnostic and a nonzero exit status.
-
- The ignore = true setting is suitable for a scenario where you don't know
- ahead of time whether the pipe writer or the pipe reader will terminate
- first. In this case, an EPIPE is an indication that the pipe writer can
- stop doing useless write() calls; this is what close_stdout does anyway.
- EPIPE is part of the normal pipe/socket shutdown protocol in this case,
- and should not lead to a diagnostic message. */
-
-void
-close_stdout_set_ignore_EPIPE (bool ignore)
-{
- ignore_EPIPE = ignore;
-}
-
-/* Close standard output. On error, issue a diagnostic and _exit
- with status 'exit_failure'.
-
- Also close standard error. On error, _exit with status 'exit_failure'.
-
- Since close_stdout is commonly registered via 'atexit', POSIX
- and the C standard both say that it should not call 'exit',
- because the behavior is undefined if 'exit' is called more than
- once. So it calls '_exit' instead of 'exit'. If close_stdout
- is registered via atexit before other functions are registered,
- the other functions can act before this _exit is invoked.
-
- Applications that use close_stdout should flush any streams
- other than stdout and stderr before exiting, since the call to
- _exit will bypass other buffer flushing. Applications should
- be flushing and closing other streams anyway, to check for I/O
- errors. Also, applications should not use tmpfile, since _exit
- can bypass the removal of these files.
-
- It's important to detect such failures and exit nonzero because many
- tools (most notably 'make' and other build-management systems) depend
- on being able to detect failure in other tools via their exit status. */
-
-void
-close_stdout (void)
-{
- if (close_stream (stdout) != 0
- && !(ignore_EPIPE && errno == EPIPE))
- {
- char const *write_error = _("write error");
- if (file_name)
- error (0, errno, "%s: %s", quotearg_colon (file_name),
- write_error);
- else
- error (0, errno, "%s", write_error);
-
- _exit (exit_failure);
- }
-
- if (close_stream (stderr) != 0)
- _exit (exit_failure);
-}
+/* Close standard output and standard error, exiting with a diagnostic on error.
+
+ Copyright (C) 1998-2002, 2004, 2006, 2008-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "closeout.h"
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+#include "close-stream.h"
+#include "error.h"
+#include "exitfail.h"
+#include "quotearg.h"
+
+static const char *file_name;
+
+/* Set the file name to be reported in the event an error is detected
+ by close_stdout. */
+void
+close_stdout_set_file_name (const char *file)
+{
+ file_name = file;
+}
+
+static bool ignore_EPIPE /* = false */;
+
+/* Specify the reaction to an EPIPE error during the closing of stdout:
+ - If ignore = true, it shall be ignored.
+ - If ignore = false, it shall evoke a diagnostic, along with a nonzero
+ exit status.
+ The default is ignore = false.
+
+ This setting matters only if the SIGPIPE signal is ignored (i.e. its
+ handler set to SIG_IGN) or blocked. Only particular programs need to
+ temporarily ignore SIGPIPE. If SIGPIPE is ignored or blocked because
+ it was ignored or blocked in the parent process when it created the
+ child process, it usually is a bug in the parent process: It is bad
+ practice to have SIGPIPE ignored or blocked while creating a child
+ process.
+
+ EPIPE occurs when writing to a pipe or socket that has no readers now,
+ when SIGPIPE is ignored or blocked.
+
+ The ignore = false setting is suitable for a scenario where it is normally
+ guaranteed that the pipe writer terminates before the pipe reader. In
+ this case, an EPIPE is an indication of a premature termination of the
+ pipe reader and should lead to a diagnostic and a nonzero exit status.
+
+ The ignore = true setting is suitable for a scenario where you don't know
+ ahead of time whether the pipe writer or the pipe reader will terminate
+ first. In this case, an EPIPE is an indication that the pipe writer can
+ stop doing useless write() calls; this is what close_stdout does anyway.
+ EPIPE is part of the normal pipe/socket shutdown protocol in this case,
+ and should not lead to a diagnostic message. */
+
+void
+close_stdout_set_ignore_EPIPE (bool ignore)
+{
+ ignore_EPIPE = ignore;
+}
+
+/* Close standard output. On error, issue a diagnostic and _exit
+ with status 'exit_failure'.
+
+ Also close standard error. On error, _exit with status 'exit_failure'.
+
+ Since close_stdout is commonly registered via 'atexit', POSIX
+ and the C standard both say that it should not call 'exit',
+ because the behavior is undefined if 'exit' is called more than
+ once. So it calls '_exit' instead of 'exit'. If close_stdout
+ is registered via atexit before other functions are registered,
+ the other functions can act before this _exit is invoked.
+
+ Applications that use close_stdout should flush any streams
+ other than stdout and stderr before exiting, since the call to
+ _exit will bypass other buffer flushing. Applications should
+ be flushing and closing other streams anyway, to check for I/O
+ errors. Also, applications should not use tmpfile, since _exit
+ can bypass the removal of these files.
+
+ It's important to detect such failures and exit nonzero because many
+ tools (most notably 'make' and other build-management systems) depend
+ on being able to detect failure in other tools via their exit status. */
+
+void
+close_stdout (void)
+{
+ if (close_stream (stdout) != 0
+ && !(ignore_EPIPE && errno == EPIPE))
+ {
+ char const *write_error = _("write error");
+ if (file_name)
+ error (0, errno, "%s: %s", quotearg_colon (file_name),
+ write_error);
+ else
+ error (0, errno, "%s", write_error);
+
+ _exit (exit_failure);
+ }
+
+ if (close_stream (stderr) != 0)
+ _exit (exit_failure);
+}
diff --git a/contrib/tools/bison/gnulib/src/closeout.h b/contrib/tools/bison/gnulib/src/closeout.h
index 131fe864ec..5971035854 100644
--- a/contrib/tools/bison/gnulib/src/closeout.h
+++ b/contrib/tools/bison/gnulib/src/closeout.h
@@ -1,36 +1,36 @@
-/* Close standard output and standard error.
-
- Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef CLOSEOUT_H
-# define CLOSEOUT_H 1
-
-# include <stdbool.h>
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-void close_stdout_set_file_name (const char *file);
-void close_stdout_set_ignore_EPIPE (bool ignore);
-void close_stdout (void);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
+/* Close standard output and standard error.
+
+ Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef CLOSEOUT_H
+# define CLOSEOUT_H 1
+
+# include <stdbool.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+void close_stdout_set_file_name (const char *file);
+void close_stdout_set_ignore_EPIPE (bool ignore);
+void close_stdout (void);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/concat-filename.c b/contrib/tools/bison/gnulib/src/concat-filename.c
index b749d6838b..a29827768b 100644
--- a/contrib/tools/bison/gnulib/src/concat-filename.c
+++ b/contrib/tools/bison/gnulib/src/concat-filename.c
@@ -1,73 +1,73 @@
-/* Construct a full filename from a directory and a relative filename.
- Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or any
- later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <haible@clisp.cons.org>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "concat-filename.h"
-
-#include <errno.h>
-#include <stdlib.h>
+/* Construct a full filename from a directory and a relative filename.
+ Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <haible@clisp.cons.org>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "concat-filename.h"
+
+#include <errno.h>
+#include <stdlib.h>
#include "string--.h"
-
-#include "filename.h"
-
-/* Concatenate a directory filename, a relative filename and an optional
- suffix. The directory may end with the directory separator. The second
- argument may not start with the directory separator (it is relative).
- Return a freshly allocated filename. Return NULL and set errno
- upon memory allocation failure. */
-char *
-concatenated_filename (const char *directory, const char *filename,
- const char *suffix)
-{
- char *result;
- char *p;
-
- if (strcmp (directory, ".") == 0)
- {
- /* No need to prepend the directory. */
- result = (char *) malloc (strlen (filename)
- + (suffix != NULL ? strlen (suffix) : 0)
- + 1);
- if (result == NULL)
- return NULL; /* errno is set here */
- p = result;
- }
- else
- {
- size_t directory_len = strlen (directory);
- int need_slash =
- (directory_len > FILE_SYSTEM_PREFIX_LEN (directory)
- && !ISSLASH (directory[directory_len - 1]));
- result = (char *) malloc (directory_len + need_slash
- + strlen (filename)
- + (suffix != NULL ? strlen (suffix) : 0)
- + 1);
- if (result == NULL)
- return NULL; /* errno is set here */
- memcpy (result, directory, directory_len);
- p = result + directory_len;
- if (need_slash)
- *p++ = '/';
- }
- p = stpcpy (p, filename);
- if (suffix != NULL)
- stpcpy (p, suffix);
- return result;
-}
+
+#include "filename.h"
+
+/* Concatenate a directory filename, a relative filename and an optional
+ suffix. The directory may end with the directory separator. The second
+ argument may not start with the directory separator (it is relative).
+ Return a freshly allocated filename. Return NULL and set errno
+ upon memory allocation failure. */
+char *
+concatenated_filename (const char *directory, const char *filename,
+ const char *suffix)
+{
+ char *result;
+ char *p;
+
+ if (strcmp (directory, ".") == 0)
+ {
+ /* No need to prepend the directory. */
+ result = (char *) malloc (strlen (filename)
+ + (suffix != NULL ? strlen (suffix) : 0)
+ + 1);
+ if (result == NULL)
+ return NULL; /* errno is set here */
+ p = result;
+ }
+ else
+ {
+ size_t directory_len = strlen (directory);
+ int need_slash =
+ (directory_len > FILE_SYSTEM_PREFIX_LEN (directory)
+ && !ISSLASH (directory[directory_len - 1]));
+ result = (char *) malloc (directory_len + need_slash
+ + strlen (filename)
+ + (suffix != NULL ? strlen (suffix) : 0)
+ + 1);
+ if (result == NULL)
+ return NULL; /* errno is set here */
+ memcpy (result, directory, directory_len);
+ p = result + directory_len;
+ if (need_slash)
+ *p++ = '/';
+ }
+ p = stpcpy (p, filename);
+ if (suffix != NULL)
+ stpcpy (p, suffix);
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/concat-filename.h b/contrib/tools/bison/gnulib/src/concat-filename.h
index 898dcee2d6..7beb2bca59 100644
--- a/contrib/tools/bison/gnulib/src/concat-filename.h
+++ b/contrib/tools/bison/gnulib/src/concat-filename.h
@@ -1,41 +1,41 @@
-/* Construct a full filename from a directory and a relative filename.
- Copyright (C) 2001-2004, 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _CONCAT_FILENAME_H
-#define _CONCAT_FILENAME_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Concatenate a directory filename, a relative filename and an optional
- suffix. Return a freshly allocated filename. Return NULL and set errno
- upon memory allocation failure. */
-extern char *concatenated_filename (const char *directory,
- const char *filename, const char *suffix);
-
-/* Concatenate a directory filename, a relative filename and an optional
- suffix. Return a freshly allocated filename. */
-extern char *xconcatenated_filename (const char *directory,
- const char *filename, const char *suffix);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CONCAT_FILENAME_H */
+/* Construct a full filename from a directory and a relative filename.
+ Copyright (C) 2001-2004, 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _CONCAT_FILENAME_H
+#define _CONCAT_FILENAME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Concatenate a directory filename, a relative filename and an optional
+ suffix. Return a freshly allocated filename. Return NULL and set errno
+ upon memory allocation failure. */
+extern char *concatenated_filename (const char *directory,
+ const char *filename, const char *suffix);
+
+/* Concatenate a directory filename, a relative filename and an optional
+ suffix. Return a freshly allocated filename. */
+extern char *xconcatenated_filename (const char *directory,
+ const char *filename, const char *suffix);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CONCAT_FILENAME_H */
diff --git a/contrib/tools/bison/gnulib/src/dirname-lgpl.c b/contrib/tools/bison/gnulib/src/dirname-lgpl.c
index 82f66301f2..a2ff26e0d6 100644
--- a/contrib/tools/bison/gnulib/src/dirname-lgpl.c
+++ b/contrib/tools/bison/gnulib/src/dirname-lgpl.c
@@ -1,86 +1,86 @@
-/* dirname.c -- return all but the last element in a file name
-
- Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "dirname.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-/* Return the length of the prefix of FILE that will be used by
- dir_name. If FILE is in the working directory, this returns zero
- even though 'dir_name (FILE)' will return ".". Works properly even
- if there are trailing slashes (by effectively ignoring them). */
-
-size_t
-dir_len (char const *file)
-{
- size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
- size_t length;
-
- /* Advance prefix_length beyond important leading slashes. */
- prefix_length += (prefix_length != 0
- ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
- && ISSLASH (file[prefix_length]))
- : (ISSLASH (file[0])
- ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
- && ISSLASH (file[1]) && ! ISSLASH (file[2])
- ? 2 : 1))
- : 0));
-
- /* Strip the basename and any redundant slashes before it. */
- for (length = last_component (file) - file;
- prefix_length < length; length--)
- if (! ISSLASH (file[length - 1]))
- break;
- return length;
-}
-
-
-/* In general, we can't use the builtin 'dirname' function if available,
- since it has different meanings in different environments.
- In some environments the builtin 'dirname' modifies its argument.
-
- Return the leading directories part of FILE, allocated with malloc.
- Works properly even if there are trailing slashes (by effectively
- ignoring them). Return NULL on failure.
-
- If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
- lstat (base_name (FILE)); } will access the same file. Likewise,
- if the sequence { chdir (dir_name (FILE));
- rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
- to "foo" in the same directory FILE was in. */
-
-char *
-mdir_name (char const *file)
-{
- size_t length = dir_len (file);
- bool append_dot = (length == 0
- || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
- && length == FILE_SYSTEM_PREFIX_LEN (file)
- && file[2] != '\0' && ! ISSLASH (file[2])));
- char *dir = malloc (length + append_dot + 1);
- if (!dir)
- return NULL;
- memcpy (dir, file, length);
- if (append_dot)
- dir[length++] = '.';
- dir[length] = '\0';
- return dir;
-}
+/* dirname.c -- return all but the last element in a file name
+
+ Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "dirname.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/* Return the length of the prefix of FILE that will be used by
+ dir_name. If FILE is in the working directory, this returns zero
+ even though 'dir_name (FILE)' will return ".". Works properly even
+ if there are trailing slashes (by effectively ignoring them). */
+
+size_t
+dir_len (char const *file)
+{
+ size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
+ size_t length;
+
+ /* Advance prefix_length beyond important leading slashes. */
+ prefix_length += (prefix_length != 0
+ ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+ && ISSLASH (file[prefix_length]))
+ : (ISSLASH (file[0])
+ ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
+ && ISSLASH (file[1]) && ! ISSLASH (file[2])
+ ? 2 : 1))
+ : 0));
+
+ /* Strip the basename and any redundant slashes before it. */
+ for (length = last_component (file) - file;
+ prefix_length < length; length--)
+ if (! ISSLASH (file[length - 1]))
+ break;
+ return length;
+}
+
+
+/* In general, we can't use the builtin 'dirname' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin 'dirname' modifies its argument.
+
+ Return the leading directories part of FILE, allocated with malloc.
+ Works properly even if there are trailing slashes (by effectively
+ ignoring them). Return NULL on failure.
+
+ If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
+ lstat (base_name (FILE)); } will access the same file. Likewise,
+ if the sequence { chdir (dir_name (FILE));
+ rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
+ to "foo" in the same directory FILE was in. */
+
+char *
+mdir_name (char const *file)
+{
+ size_t length = dir_len (file);
+ bool append_dot = (length == 0
+ || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+ && length == FILE_SYSTEM_PREFIX_LEN (file)
+ && file[2] != '\0' && ! ISSLASH (file[2])));
+ char *dir = malloc (length + append_dot + 1);
+ if (!dir)
+ return NULL;
+ memcpy (dir, file, length);
+ if (append_dot)
+ dir[length++] = '.';
+ dir[length] = '\0';
+ return dir;
+}
diff --git a/contrib/tools/bison/gnulib/src/dirname.c b/contrib/tools/bison/gnulib/src/dirname.c
index 1fb65888bb..da26cb4a05 100644
--- a/contrib/tools/bison/gnulib/src/dirname.c
+++ b/contrib/tools/bison/gnulib/src/dirname.c
@@ -1,38 +1,38 @@
-/* dirname.c -- return all but the last element in a file name
-
- Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "dirname.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include "xalloc.h"
-
-/* Just like mdir_name (dirname-lgpl.c), except, rather than
- returning NULL upon malloc failure, here, we report the
- "memory exhausted" condition and exit. */
-
-char *
-dir_name (char const *file)
-{
- char *result = mdir_name (file);
- if (!result)
- xalloc_die ();
- return result;
-}
+/* dirname.c -- return all but the last element in a file name
+
+ Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "dirname.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include "xalloc.h"
+
+/* Just like mdir_name (dirname-lgpl.c), except, rather than
+ returning NULL upon malloc failure, here, we report the
+ "memory exhausted" condition and exit. */
+
+char *
+dir_name (char const *file)
+{
+ char *result = mdir_name (file);
+ if (!result)
+ xalloc_die ();
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/dirname.h b/contrib/tools/bison/gnulib/src/dirname.h
index 4ad0312008..43258d36b7 100644
--- a/contrib/tools/bison/gnulib/src/dirname.h
+++ b/contrib/tools/bison/gnulib/src/dirname.h
@@ -1,46 +1,46 @@
-/* Take file names apart into directory and base names.
-
- Copyright (C) 1998, 2001, 2003-2006, 2009-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef DIRNAME_H_
-# define DIRNAME_H_ 1
-
-# include <stdbool.h>
-# include <stddef.h>
-# include "dosname.h"
-
-# ifndef DIRECTORY_SEPARATOR
-# define DIRECTORY_SEPARATOR '/'
-# endif
-
-# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
-# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
-# endif
-
-# if GNULIB_DIRNAME
-char *base_name (char const *file);
-char *dir_name (char const *file);
-# endif
-
-char *mdir_name (char const *file);
-size_t base_len (char const *file) _GL_ATTRIBUTE_PURE;
-size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE;
-char *last_component (char const *file) _GL_ATTRIBUTE_PURE;
-
-bool strip_trailing_slashes (char *file);
-
-#endif /* not DIRNAME_H_ */
+/* Take file names apart into directory and base names.
+
+ Copyright (C) 1998, 2001, 2003-2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef DIRNAME_H_
+# define DIRNAME_H_ 1
+
+# include <stdbool.h>
+# include <stddef.h>
+# include "dosname.h"
+
+# ifndef DIRECTORY_SEPARATOR
+# define DIRECTORY_SEPARATOR '/'
+# endif
+
+# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
+# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
+# endif
+
+# if GNULIB_DIRNAME
+char *base_name (char const *file);
+char *dir_name (char const *file);
+# endif
+
+char *mdir_name (char const *file);
+size_t base_len (char const *file) _GL_ATTRIBUTE_PURE;
+size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE;
+char *last_component (char const *file) _GL_ATTRIBUTE_PURE;
+
+bool strip_trailing_slashes (char *file);
+
+#endif /* not DIRNAME_H_ */
diff --git a/contrib/tools/bison/gnulib/src/dosname.h b/contrib/tools/bison/gnulib/src/dosname.h
index ba63ce4bd3..224c50eb97 100644
--- a/contrib/tools/bison/gnulib/src/dosname.h
+++ b/contrib/tools/bison/gnulib/src/dosname.h
@@ -1,53 +1,53 @@
-/* File names on MS-DOS/Windows systems.
-
- Copyright (C) 2000-2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- From Paul Eggert and Jim Meyering. */
-
-#ifndef _DOSNAME_H
-#define _DOSNAME_H
-
-#if (defined _WIN32 || defined __WIN32__ || \
- defined __MSDOS__ || defined __CYGWIN__ || \
- defined __EMX__ || defined __DJGPP__)
- /* This internal macro assumes ASCII, but all hosts that support drive
- letters use ASCII. */
-# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \
- <= 'z' - 'a')
-# define FILE_SYSTEM_PREFIX_LEN(Filename) \
- (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
-# ifndef __CYGWIN__
-# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
-# endif
-# define ISSLASH(C) ((C) == '/' || (C) == '\\')
-#else
-# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
-# define ISSLASH(C) ((C) == '/')
-#endif
-
-#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
-#endif
-
-#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
-# else
-# define IS_ABSOLUTE_FILE_NAME(F) \
- (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0)
-#endif
-#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
-
-#endif /* DOSNAME_H_ */
+/* File names on MS-DOS/Windows systems.
+
+ Copyright (C) 2000-2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ From Paul Eggert and Jim Meyering. */
+
+#ifndef _DOSNAME_H
+#define _DOSNAME_H
+
+#if (defined _WIN32 || defined __WIN32__ || \
+ defined __MSDOS__ || defined __CYGWIN__ || \
+ defined __EMX__ || defined __DJGPP__)
+ /* This internal macro assumes ASCII, but all hosts that support drive
+ letters use ASCII. */
+# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \
+ <= 'z' - 'a')
+# define FILE_SYSTEM_PREFIX_LEN(Filename) \
+ (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
+# ifndef __CYGWIN__
+# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1
+# endif
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#else
+# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
+# define ISSLASH(C) ((C) == '/')
+#endif
+
+#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
+#endif
+
+#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
+# else
+# define IS_ABSOLUTE_FILE_NAME(F) \
+ (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0)
+#endif
+#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
+
+#endif /* DOSNAME_H_ */
diff --git a/contrib/tools/bison/gnulib/src/dup-safer-flag.c b/contrib/tools/bison/gnulib/src/dup-safer-flag.c
index 8a09821dc8..98d27301c4 100644
--- a/contrib/tools/bison/gnulib/src/dup-safer-flag.c
+++ b/contrib/tools/bison/gnulib/src/dup-safer-flag.c
@@ -1,38 +1,38 @@
-/* Duplicate a file descriptor result, avoiding clobbering
- STD{IN,OUT,ERR}_FILENO, with specific flags.
-
- Copyright (C) 2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert and Eric Blake. */
-
-#include <config.h>
-
-/* Specification. */
-#include "unistd-safer.h"
-
-#include <fcntl.h>
-#include <unistd.h>
-
-/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
- STDERR_FILENO. If FLAG contains O_CLOEXEC, behave like
- fcntl(F_DUPFD_CLOEXEC) rather than fcntl(F_DUPFD). */
-
-int
-dup_safer_flag (int fd, int flag)
-{
- return fcntl (fd, (flag & O_CLOEXEC) ? F_DUPFD_CLOEXEC : F_DUPFD,
- STDERR_FILENO + 1);
-}
+/* Duplicate a file descriptor result, avoiding clobbering
+ STD{IN,OUT,ERR}_FILENO, with specific flags.
+
+ Copyright (C) 2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert and Eric Blake. */
+
+#include <config.h>
+
+/* Specification. */
+#include "unistd-safer.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
+ STDERR_FILENO. If FLAG contains O_CLOEXEC, behave like
+ fcntl(F_DUPFD_CLOEXEC) rather than fcntl(F_DUPFD). */
+
+int
+dup_safer_flag (int fd, int flag)
+{
+ return fcntl (fd, (flag & O_CLOEXEC) ? F_DUPFD_CLOEXEC : F_DUPFD,
+ STDERR_FILENO + 1);
+}
diff --git a/contrib/tools/bison/gnulib/src/dup-safer.c b/contrib/tools/bison/gnulib/src/dup-safer.c
index c20310785a..091db86e33 100644
--- a/contrib/tools/bison/gnulib/src/dup-safer.c
+++ b/contrib/tools/bison/gnulib/src/dup-safer.c
@@ -1,34 +1,34 @@
-/* Invoke dup, but avoid some glitches.
-
- Copyright (C) 2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <config.h>
-
-#include "unistd-safer.h"
-
-#include <fcntl.h>
-#include <unistd.h>
-
-/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
- STDERR_FILENO. */
-
-int
-dup_safer (int fd)
-{
- return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
-}
+/* Invoke dup, but avoid some glitches.
+
+ Copyright (C) 2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <config.h>
+
+#include "unistd-safer.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
+ STDERR_FILENO. */
+
+int
+dup_safer (int fd)
+{
+ return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
+}
diff --git a/contrib/tools/bison/gnulib/src/dup2.c b/contrib/tools/bison/gnulib/src/dup2.c
index 9219eb3823..e6c3161924 100644
--- a/contrib/tools/bison/gnulib/src/dup2.c
+++ b/contrib/tools/bison/gnulib/src/dup2.c
@@ -1,160 +1,160 @@
-/* Duplicate an open file descriptor to a specified file descriptor.
-
- Copyright (C) 1999, 2004-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Paul Eggert */
-
-#include <config.h>
-
-/* Specification. */
-#include <unistd.h>
-
-#include <errno.h>
-#include <fcntl.h>
-
-#if HAVE_DUP2
-
-# undef dup2
-
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* Get declarations of the native Windows API functions. */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-
-# include "msvc-inval.h"
-
-/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
-
-static int
-ms_windows_dup2 (int fd, int desired_fd)
-{
- int result;
-
- /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open,
- dup2 (fd, fd) returns 0, but all further attempts to use fd in
- future dup2 calls will hang. */
- if (fd == desired_fd)
- {
- if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
- {
- errno = EBADF;
- return -1;
- }
- return fd;
- }
-
- /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
- http://bugs.winehq.org/show_bug.cgi?id=21289 */
- if (desired_fd < 0)
- {
- errno = EBADF;
- return -1;
- }
-
- TRY_MSVC_INVAL
- {
- result = dup2 (fd, desired_fd);
- }
- CATCH_MSVC_INVAL
- {
- errno = EBADF;
- result = -1;
- }
- DONE_MSVC_INVAL;
-
- if (result == 0)
- result = desired_fd;
-
- return result;
-}
-
-# define dup2 ms_windows_dup2
-
-# endif
-
-int
-rpl_dup2 (int fd, int desired_fd)
-{
- int result;
-
-# ifdef F_GETFL
- /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
- On Cygwin 1.5.x, dup2 (1, 1) returns 0.
- On Cygwin 1.7.17, dup2 (1, -1) dumps core.
- On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */
- if (desired_fd < 0)
- fd = desired_fd;
- if (fd == desired_fd)
- return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
-# endif
-
- result = dup2 (fd, desired_fd);
-
- /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */
- if (result == -1 && errno == EMFILE)
- errno = EBADF;
-# if REPLACE_FCHDIR
- if (fd != desired_fd && result != -1)
- result = _gl_register_dup (fd, result);
-# endif
- return result;
-}
-
-#else /* !HAVE_DUP2 */
-
-/* On older platforms, dup2 did not exist. */
-
-# ifndef F_DUPFD
-static int
-dupfd (int fd, int desired_fd)
-{
- int duplicated_fd = dup (fd);
- if (duplicated_fd < 0 || duplicated_fd == desired_fd)
- return duplicated_fd;
- else
- {
- int r = dupfd (fd, desired_fd);
- int e = errno;
- close (duplicated_fd);
- errno = e;
- return r;
- }
-}
-# endif
-
-int
-dup2 (int fd, int desired_fd)
-{
- int result = fcntl (fd, F_GETFL) < 0 ? -1 : fd;
- if (result == -1 || fd == desired_fd)
- return result;
- close (desired_fd);
-# ifdef F_DUPFD
- result = fcntl (fd, F_DUPFD, desired_fd);
-# if REPLACE_FCHDIR
- if (0 <= result)
- result = _gl_register_dup (fd, result);
-# endif
-# else
- result = dupfd (fd, desired_fd);
-# endif
- if (result == -1 && (errno == EMFILE || errno == EINVAL))
- errno = EBADF;
- return result;
-}
-#endif /* !HAVE_DUP2 */
+/* Duplicate an open file descriptor to a specified file descriptor.
+
+ Copyright (C) 1999, 2004-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Paul Eggert */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#include <errno.h>
+#include <fcntl.h>
+
+#if HAVE_DUP2
+
+# undef dup2
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Get declarations of the native Windows API functions. */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+# include "msvc-inval.h"
+
+/* Get _get_osfhandle. */
+# include "msvc-nothrow.h"
+
+static int
+ms_windows_dup2 (int fd, int desired_fd)
+{
+ int result;
+
+ /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open,
+ dup2 (fd, fd) returns 0, but all further attempts to use fd in
+ future dup2 calls will hang. */
+ if (fd == desired_fd)
+ {
+ if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
+ {
+ errno = EBADF;
+ return -1;
+ }
+ return fd;
+ }
+
+ /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
+ http://bugs.winehq.org/show_bug.cgi?id=21289 */
+ if (desired_fd < 0)
+ {
+ errno = EBADF;
+ return -1;
+ }
+
+ TRY_MSVC_INVAL
+ {
+ result = dup2 (fd, desired_fd);
+ }
+ CATCH_MSVC_INVAL
+ {
+ errno = EBADF;
+ result = -1;
+ }
+ DONE_MSVC_INVAL;
+
+ if (result == 0)
+ result = desired_fd;
+
+ return result;
+}
+
+# define dup2 ms_windows_dup2
+
+# endif
+
+int
+rpl_dup2 (int fd, int desired_fd)
+{
+ int result;
+
+# ifdef F_GETFL
+ /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
+ On Cygwin 1.5.x, dup2 (1, 1) returns 0.
+ On Cygwin 1.7.17, dup2 (1, -1) dumps core.
+ On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC. */
+ if (desired_fd < 0)
+ fd = desired_fd;
+ if (fd == desired_fd)
+ return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
+# endif
+
+ result = dup2 (fd, desired_fd);
+
+ /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */
+ if (result == -1 && errno == EMFILE)
+ errno = EBADF;
+# if REPLACE_FCHDIR
+ if (fd != desired_fd && result != -1)
+ result = _gl_register_dup (fd, result);
+# endif
+ return result;
+}
+
+#else /* !HAVE_DUP2 */
+
+/* On older platforms, dup2 did not exist. */
+
+# ifndef F_DUPFD
+static int
+dupfd (int fd, int desired_fd)
+{
+ int duplicated_fd = dup (fd);
+ if (duplicated_fd < 0 || duplicated_fd == desired_fd)
+ return duplicated_fd;
+ else
+ {
+ int r = dupfd (fd, desired_fd);
+ int e = errno;
+ close (duplicated_fd);
+ errno = e;
+ return r;
+ }
+}
+# endif
+
+int
+dup2 (int fd, int desired_fd)
+{
+ int result = fcntl (fd, F_GETFL) < 0 ? -1 : fd;
+ if (result == -1 || fd == desired_fd)
+ return result;
+ close (desired_fd);
+# ifdef F_DUPFD
+ result = fcntl (fd, F_DUPFD, desired_fd);
+# if REPLACE_FCHDIR
+ if (0 <= result)
+ result = _gl_register_dup (fd, result);
+# endif
+# else
+ result = dupfd (fd, desired_fd);
+# endif
+ if (result == -1 && (errno == EMFILE || errno == EINVAL))
+ errno = EBADF;
+ return result;
+}
+#endif /* !HAVE_DUP2 */
diff --git a/contrib/tools/bison/gnulib/src/ebitset.c b/contrib/tools/bison/gnulib/src/ebitset.c
index e5d6c9239b..3ad4b8ae2c 100644
--- a/contrib/tools/bison/gnulib/src/ebitset.c
+++ b/contrib/tools/bison/gnulib/src/ebitset.c
@@ -1,1361 +1,1361 @@
-/* Functions to support expandable bitsets.
-
- Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "ebitset.h"
-
-#include "obstack.h"
-#include <stdlib.h>
-#include <string.h>
-
-/* This file implements expandable bitsets. These bitsets can be of
- arbitrary length and are more efficient than arrays of bits for
- large sparse sets.
-
- Empty elements are represented by a NULL pointer in the table of
- element pointers. An alternative is to point to a special zero
- element. Similarly, we could represent an all 1's element with
- another special ones element pointer.
-
- Bitsets are commonly empty so we need to ensure that this special
- case is fast. A zero bitset is indicated when cdata is 0. This is
- conservative since cdata may be non zero and the bitset may still
- be zero.
-
- The bitset cache can be disabled either by setting cindex to
- BITSET_WINDEX_MAX or by setting csize to 0. Here
- we use the former approach since cindex needs to be updated whenever
- cdata is changed.
-*/
-
-
-/* Number of words to use for each element. */
-#define EBITSET_ELT_WORDS 2
-
-/* Number of bits stored in each element. */
-#define EBITSET_ELT_BITS \
- ((unsigned int) (EBITSET_ELT_WORDS * BITSET_WORD_BITS))
-
-/* Ebitset element. We use an array of bits. */
-typedef struct ebitset_elt_struct
-{
- union
- {
- bitset_word words[EBITSET_ELT_WORDS]; /* Bits that are set. */
- struct ebitset_elt_struct *next;
- }
- u;
-}
-ebitset_elt;
-
-
-typedef ebitset_elt *ebitset_elts;
-
-
-/* Number of elements to initially allocate. */
-
-#ifndef EBITSET_INITIAL_SIZE
-#define EBITSET_INITIAL_SIZE 2
-#endif
-
-
-enum ebitset_find_mode
- { EBITSET_FIND, EBITSET_CREATE, EBITSET_SUBST };
-
-static ebitset_elt ebitset_zero_elts[1]; /* Elements of all zero bits. */
-
-/* Obstack to allocate bitset elements from. */
-static struct obstack ebitset_obstack;
-static bool ebitset_obstack_init = false;
-static ebitset_elt *ebitset_free_list; /* Free list of bitset elements. */
-
-#define EBITSET_N_ELTS(N) (((N) + EBITSET_ELT_BITS - 1) / EBITSET_ELT_BITS)
-#define EBITSET_ELTS(BSET) ((BSET)->e.elts)
-#define EBITSET_SIZE(BSET) EBITSET_N_ELTS (BITSET_NBITS_ (BSET))
-#define EBITSET_ASIZE(BSET) ((BSET)->e.size)
-
-#define EBITSET_NEXT(ELT) ((ELT)->u.next)
-#define EBITSET_WORDS(ELT) ((ELT)->u.words)
-
-/* Disable bitset cache and mark BSET as being zero. */
-#define EBITSET_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX, \
- (BSET)->b.cdata = 0)
-
-#define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX)
-
-/* Disable bitset cache and mark BSET as being possibly non-zero. */
-#define EBITSET_NONZERO_SET(BSET) \
- (EBITSET_CACHE_DISABLE (BSET), (BSET)->b.cdata = (bitset_word *)~0)
-
-/* A conservative estimate of whether the bitset is zero.
- This is non-zero only if we know for sure that the bitset is zero. */
-#define EBITSET_ZERO_P(BSET) ((BSET)->b.cdata == 0)
-
-/* Enable cache to point to element with table index EINDEX.
- The element must exist. */
-#define EBITSET_CACHE_SET(BSET, EINDEX) \
- ((BSET)->b.cindex = (EINDEX) * EBITSET_ELT_WORDS, \
- (BSET)->b.cdata = EBITSET_WORDS (EBITSET_ELTS (BSET) [EINDEX]))
-
-#undef min
-#undef max
-#define min(a, b) ((a) > (b) ? (b) : (a))
-#define max(a, b) ((a) > (b) ? (a) : (b))
-
-static bitset_bindex
-ebitset_resize (bitset src, bitset_bindex n_bits)
-{
- bitset_windex oldsize;
- bitset_windex newsize;
-
- if (n_bits == BITSET_NBITS_ (src))
- return n_bits;
-
- oldsize = EBITSET_SIZE (src);
- newsize = EBITSET_N_ELTS (n_bits);
-
- if (oldsize < newsize)
- {
- bitset_windex size;
-
- /* The bitset needs to grow. If we already have enough memory
- allocated, then just zero what we need. */
- if (newsize > EBITSET_ASIZE (src))
- {
- /* We need to allocate more memory. When oldsize is
- non-zero this means that we are changing the size, so
- grow the bitset 25% larger than requested to reduce
- number of reallocations. */
-
- if (oldsize == 0)
- size = newsize;
- else
- size = newsize + newsize / 4;
-
- EBITSET_ELTS (src)
- = realloc (EBITSET_ELTS (src), size * sizeof (ebitset_elt *));
- EBITSET_ASIZE (src) = size;
- }
-
- memset (EBITSET_ELTS (src) + oldsize, 0,
- (newsize - oldsize) * sizeof (ebitset_elt *));
- }
- else
- {
- /* The bitset needs to shrink. There's no point deallocating
- the memory unless it is shrinking by a reasonable amount. */
- if ((oldsize - newsize) >= oldsize / 2)
- {
- EBITSET_ELTS (src)
- = realloc (EBITSET_ELTS (src), newsize * sizeof (ebitset_elt *));
- EBITSET_ASIZE (src) = newsize;
- }
-
- /* Need to prune any excess bits. FIXME. */
- }
-
- BITSET_NBITS_ (src) = n_bits;
- return n_bits;
-}
-
-
-/* Allocate a ebitset element. The bits are not cleared. */
-static inline ebitset_elt *
-ebitset_elt_alloc (void)
-{
- ebitset_elt *elt;
-
- if (ebitset_free_list != 0)
- {
- elt = ebitset_free_list;
- ebitset_free_list = EBITSET_NEXT (elt);
- }
- else
- {
- if (!ebitset_obstack_init)
- {
- ebitset_obstack_init = true;
-
- /* Let particular systems override the size of a chunk. */
-
-#ifndef OBSTACK_CHUNK_SIZE
-#define OBSTACK_CHUNK_SIZE 0
-#endif
-
- /* Let them override the alloc and free routines too. */
-
-#ifndef OBSTACK_CHUNK_ALLOC
-#define OBSTACK_CHUNK_ALLOC xmalloc
-#endif
-
-#ifndef OBSTACK_CHUNK_FREE
-#define OBSTACK_CHUNK_FREE free
-#endif
-
-#if ! defined __GNUC__ || __GNUC__ < 2
-#define __alignof__(type) 0
-#endif
-
- obstack_specify_allocation (&ebitset_obstack, OBSTACK_CHUNK_SIZE,
- __alignof__ (ebitset_elt),
- OBSTACK_CHUNK_ALLOC,
- OBSTACK_CHUNK_FREE);
- }
-
- /* Perhaps we should add a number of new elements to the free
- list. */
- elt = (ebitset_elt *) obstack_alloc (&ebitset_obstack,
- sizeof (ebitset_elt));
- }
-
- return elt;
-}
-
-
-/* Allocate a ebitset element. The bits are cleared. */
-static inline ebitset_elt *
-ebitset_elt_calloc (void)
-{
- ebitset_elt *elt;
-
- elt = ebitset_elt_alloc ();
- memset (EBITSET_WORDS (elt), 0, sizeof (EBITSET_WORDS (elt)));
- return elt;
-}
-
-
-static inline void
-ebitset_elt_free (ebitset_elt *elt)
-{
- EBITSET_NEXT (elt) = ebitset_free_list;
- ebitset_free_list = elt;
-}
-
-
-/* Remove element with index EINDEX from bitset BSET. */
-static inline void
-ebitset_elt_remove (bitset bset, bitset_windex eindex)
-{
- ebitset_elts *elts;
- ebitset_elt *elt;
-
- elts = EBITSET_ELTS (bset);
-
- elt = elts[eindex];
-
- elts[eindex] = 0;
- ebitset_elt_free (elt);
-}
-
-
-/* Add ELT into elts at index EINDEX of bitset BSET. */
-static inline void
-ebitset_elt_add (bitset bset, ebitset_elt *elt, bitset_windex eindex)
-{
- ebitset_elts *elts;
-
- elts = EBITSET_ELTS (bset);
- /* Assume that the elts entry not allocated. */
- elts[eindex] = elt;
-}
-
-
-/* Are all bits in an element zero? */
-static inline bool
-ebitset_elt_zero_p (ebitset_elt *elt)
-{
- int i;
-
- for (i = 0; i < EBITSET_ELT_WORDS; i++)
- if (EBITSET_WORDS (elt)[i])
- return false;
-
- return true;
-}
-
-
-static ebitset_elt *
-ebitset_elt_find (bitset bset, bitset_bindex bindex,
- enum ebitset_find_mode mode)
-{
- ebitset_elt *elt;
- bitset_windex size;
- bitset_windex eindex;
- ebitset_elts *elts;
-
- eindex = bindex / EBITSET_ELT_BITS;
-
- elts = EBITSET_ELTS (bset);
- size = EBITSET_SIZE (bset);
-
- if (eindex < size)
- {
- if ((elt = elts[eindex]))
- {
- if (EBITSET_WORDS (elt) == bset->b.cdata)
- return elt;
-
- EBITSET_CACHE_SET (bset, eindex);
- return elt;
- }
- }
-
- /* The element could not be found. */
-
- switch (mode)
- {
- default:
- abort ();
-
- case EBITSET_FIND:
- return 0;
-
- case EBITSET_CREATE:
- if (eindex >= size)
- ebitset_resize (bset, bindex);
-
- /* Create a new element. */
- elt = ebitset_elt_calloc ();
- ebitset_elt_add (bset, elt, eindex);
- EBITSET_CACHE_SET (bset, eindex);
- return elt;
-
- case EBITSET_SUBST:
- return &ebitset_zero_elts[0];
- }
-}
-
-
-/* Weed out the zero elements from the elts. */
-static inline bitset_windex
-ebitset_weed (bitset bset)
-{
- ebitset_elts *elts;
- bitset_windex j;
- bitset_windex count;
-
- if (EBITSET_ZERO_P (bset))
- return 0;
-
- elts = EBITSET_ELTS (bset);
- count = 0;
- for (j = 0; j < EBITSET_SIZE (bset); j++)
- {
- ebitset_elt *elt = elts[j];
-
- if (elt)
- {
- if (ebitset_elt_zero_p (elt))
- {
- ebitset_elt_remove (bset, j);
- count++;
- }
- }
- else
- count++;
- }
-
- count = j - count;
- if (!count)
- {
- /* All the bits are zero. We could shrink the elts.
- For now just mark BSET as known to be zero. */
- EBITSET_ZERO_SET (bset);
- }
- else
- EBITSET_NONZERO_SET (bset);
-
- return count;
-}
-
-
-/* Set all bits in the bitset to zero. */
-static inline void
-ebitset_zero (bitset bset)
-{
- ebitset_elts *elts;
- bitset_windex j;
-
- if (EBITSET_ZERO_P (bset))
- return;
-
- elts = EBITSET_ELTS (bset);
- for (j = 0; j < EBITSET_SIZE (bset); j++)
- {
- ebitset_elt *elt = elts[j];
-
- if (elt)
- ebitset_elt_remove (bset, j);
- }
-
- /* All the bits are zero. We could shrink the elts.
- For now just mark BSET as known to be zero. */
- EBITSET_ZERO_SET (bset);
-}
-
-
-static inline bool
-ebitset_equal_p (bitset dst, bitset src)
-{
- ebitset_elts *selts;
- ebitset_elts *delts;
- bitset_windex j;
-
- if (src == dst)
- return true;
-
- ebitset_weed (dst);
- ebitset_weed (src);
-
- if (EBITSET_SIZE (src) != EBITSET_SIZE (dst))
- return false;
-
- selts = EBITSET_ELTS (src);
- delts = EBITSET_ELTS (dst);
-
- for (j = 0; j < EBITSET_SIZE (src); j++)
- {
- unsigned int i;
- ebitset_elt *selt = selts[j];
- ebitset_elt *delt = delts[j];
-
- if (!selt && !delt)
- continue;
- if ((selt && !delt) || (!selt && delt))
- return false;
-
- for (i = 0; i < EBITSET_ELT_WORDS; i++)
- if (EBITSET_WORDS (selt)[i] != EBITSET_WORDS (delt)[i])
- return false;
- }
- return true;
-}
-
-
-/* Copy bits from bitset SRC to bitset DST. */
-static inline void
-ebitset_copy_ (bitset dst, bitset src)
-{
- ebitset_elts *selts;
- ebitset_elts *delts;
- bitset_windex j;
-
- if (src == dst)
- return;
-
- ebitset_zero (dst);
-
- if (BITSET_NBITS_ (dst) != BITSET_NBITS_ (src))
- ebitset_resize (dst, BITSET_NBITS_ (src));
-
- selts = EBITSET_ELTS (src);
- delts = EBITSET_ELTS (dst);
- for (j = 0; j < EBITSET_SIZE (src); j++)
- {
- ebitset_elt *selt = selts[j];
-
- if (selt)
- {
- ebitset_elt *tmp;
-
- tmp = ebitset_elt_alloc ();
- delts[j] = tmp;
- memcpy (EBITSET_WORDS (tmp), EBITSET_WORDS (selt),
- sizeof (EBITSET_WORDS (selt)));
- }
- }
- EBITSET_NONZERO_SET (dst);
-}
-
-
-/* Copy bits from bitset SRC to bitset DST. Return true if
- bitsets different. */
-static inline bool
-ebitset_copy_cmp (bitset dst, bitset src)
-{
- if (src == dst)
- return false;
-
- if (EBITSET_ZERO_P (dst))
- {
- ebitset_copy_ (dst, src);
- return !EBITSET_ZERO_P (src);
- }
-
- if (ebitset_equal_p (dst, src))
- return false;
-
- ebitset_copy_ (dst, src);
- return true;
-}
-
-
-/* Set bit BITNO in bitset DST. */
-static void
-ebitset_set (bitset dst, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
-
- ebitset_elt_find (dst, bitno, EBITSET_CREATE);
-
- dst->b.cdata[windex - dst->b.cindex] |=
- (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
-}
-
-
-/* Reset bit BITNO in bitset DST. */
-static void
-ebitset_reset (bitset dst, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
-
- if (!ebitset_elt_find (dst, bitno, EBITSET_FIND))
- return;
-
- dst->b.cdata[windex - dst->b.cindex] &=
- ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
-
- /* If all the data is zero, perhaps we should remove it now...
- However, there is a good chance that the element will be needed
- again soon. */
-}
-
-
-/* Test bit BITNO in bitset SRC. */
-static bool
-ebitset_test (bitset src, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
-
- return (ebitset_elt_find (src, bitno, EBITSET_FIND)
- && ((src->b.cdata[windex - src->b.cindex]
- >> (bitno % BITSET_WORD_BITS))
- & 1));
-}
-
-
-static void
-ebitset_free (bitset bset)
-{
- ebitset_zero (bset);
- free (EBITSET_ELTS (bset));
-}
-
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT and store in array LIST. Return with actual number of bits
- found and with *NEXT indicating where search stopped. */
-static bitset_bindex
-ebitset_list_reverse (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex n_bits;
- bitset_bindex bitno;
- bitset_bindex rbitno;
- unsigned int bcount;
- bitset_bindex boffset;
- bitset_windex windex;
- bitset_windex eindex;
- bitset_windex woffset;
- bitset_bindex count;
- bitset_windex size;
- ebitset_elts *elts;
-
- if (EBITSET_ZERO_P (bset))
- return 0;
-
- size = EBITSET_SIZE (bset);
- n_bits = size * EBITSET_ELT_BITS;
- rbitno = *next;
-
- if (rbitno >= n_bits)
- return 0;
-
- elts = EBITSET_ELTS (bset);
-
- bitno = n_bits - (rbitno + 1);
-
- windex = bitno / BITSET_WORD_BITS;
- eindex = bitno / EBITSET_ELT_BITS;
- woffset = windex - eindex * EBITSET_ELT_WORDS;
-
- /* If num is 1, we could speed things up with a binary search
- of the word of interest. */
-
- count = 0;
- bcount = bitno % BITSET_WORD_BITS;
- boffset = windex * BITSET_WORD_BITS;
-
- do
- {
- ebitset_elt *elt;
- bitset_word *srcp;
-
- elt = elts[eindex];
- if (elt)
- {
- srcp = EBITSET_WORDS (elt);
-
- do
- {
- bitset_word word;
-
- word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount);
-
- for (; word; bcount--)
- {
- if (word & BITSET_MSB)
- {
- list[count++] = boffset + bcount;
- if (count >= num)
- {
- *next = n_bits - (boffset + bcount);
- return count;
- }
- }
- word <<= 1;
- }
- boffset -= BITSET_WORD_BITS;
- bcount = BITSET_WORD_BITS - 1;
- }
- while (woffset--);
- }
-
- woffset = EBITSET_ELT_WORDS - 1;
- boffset = eindex * EBITSET_ELT_BITS - BITSET_WORD_BITS;
- }
- while (eindex--);
-
- *next = n_bits - (boffset + 1);
- return count;
-}
-
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT and store in array LIST. Return with actual number of bits
- found and with *NEXT indicating where search stopped. */
-static bitset_bindex
-ebitset_list (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex bitno;
- bitset_windex windex;
- bitset_windex eindex;
- bitset_bindex count;
- bitset_windex size;
- ebitset_elt *elt;
- bitset_word word;
- ebitset_elts *elts;
-
- if (EBITSET_ZERO_P (bset))
- return 0;
-
- bitno = *next;
- count = 0;
-
- elts = EBITSET_ELTS (bset);
- size = EBITSET_SIZE (bset);
- eindex = bitno / EBITSET_ELT_BITS;
-
- if (bitno % EBITSET_ELT_BITS)
- {
- /* We need to start within an element. This is not very common. */
-
- elt = elts[eindex];
- if (elt)
- {
- bitset_windex woffset;
- bitset_word *srcp = EBITSET_WORDS (elt);
-
- windex = bitno / BITSET_WORD_BITS;
- woffset = eindex * EBITSET_ELT_WORDS;
-
- for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++)
- {
- word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS);
-
- for (; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- bitno = (windex + 1) * BITSET_WORD_BITS;
- }
- }
-
- /* Skip to next element. */
- eindex++;
- }
-
- /* If num is 1, we could speed things up with a binary search
- of the word of interest. */
-
- for (; eindex < size; eindex++)
- {
- int i;
- bitset_word *srcp;
-
- elt = elts[eindex];
- if (!elt)
- continue;
-
- srcp = EBITSET_WORDS (elt);
- windex = eindex * EBITSET_ELT_WORDS;
-
- if ((count + EBITSET_ELT_BITS) < num)
- {
- /* The coast is clear, plant boot! */
-
-#if EBITSET_ELT_WORDS == 2
- word = srcp[0];
- if (word)
- {
- if (!(word & 0xffff))
- {
- word >>= 16;
- bitno += 16;
- }
- if (!(word & 0xff))
- {
- word >>= 8;
- bitno += 8;
- }
- for (; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- windex++;
- bitno = windex * BITSET_WORD_BITS;
-
- word = srcp[1];
- if (word)
- {
- if (!(word & 0xffff))
- {
- word >>= 16;
- bitno += 16;
- }
- for (; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- windex++;
- bitno = windex * BITSET_WORD_BITS;
-#else
- for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++)
- {
- bitno = windex * BITSET_WORD_BITS;
-
- word = srcp[i];
- if (word)
- {
- if (!(word & 0xffff))
- {
- word >>= 16;
- bitno += 16;
- }
- if (!(word & 0xff))
- {
- word >>= 8;
- bitno += 8;
- }
- for (; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- }
-#endif
- }
- else
- {
- /* Tread more carefully since we need to check
- if array overflows. */
-
- for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++)
- {
- bitno = windex * BITSET_WORD_BITS;
-
- for (word = srcp[i]; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- }
- }
- }
-
- *next = bitno;
- return count;
-}
-
-
-/* Ensure that any unused bits within the last element are clear. */
-static inline void
-ebitset_unused_clear (bitset dst)
-{
- unsigned int last_bit;
- bitset_bindex n_bits;
-
- n_bits = BITSET_NBITS_ (dst);
- last_bit = n_bits % EBITSET_ELT_BITS;
-
- if (last_bit)
- {
- bitset_windex eindex;
- ebitset_elts *elts;
- ebitset_elt *elt;
-
- elts = EBITSET_ELTS (dst);
-
- eindex = n_bits / EBITSET_ELT_BITS;
-
- elt = elts[eindex];
- if (elt)
- {
- bitset_windex windex;
- bitset_windex woffset;
- bitset_word *srcp = EBITSET_WORDS (elt);
-
- windex = n_bits / BITSET_WORD_BITS;
- woffset = eindex * EBITSET_ELT_WORDS;
-
- srcp[windex - woffset] &= ((bitset_word) 1 << last_bit) - 1;
- windex++;
- for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++)
- srcp[windex - woffset] = 0;
- }
- }
-}
-
-
-static void
-ebitset_ones (bitset dst)
-{
- bitset_windex j;
- ebitset_elt *elt;
-
- for (j = 0; j < EBITSET_SIZE (dst); j++)
- {
- /* Create new elements if they cannot be found. Perhaps
- we should just add pointers to a ones element? */
- elt =
- ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE);
- memset (EBITSET_WORDS (elt), -1, sizeof (EBITSET_WORDS (elt)));
- }
- EBITSET_NONZERO_SET (dst);
- ebitset_unused_clear (dst);
-}
-
-
-static bool
-ebitset_empty_p (bitset dst)
-{
- ebitset_elts *elts;
- bitset_windex j;
-
- if (EBITSET_ZERO_P (dst))
- return 1;
-
- elts = EBITSET_ELTS (dst);
- for (j = 0; j < EBITSET_SIZE (dst); j++)
- {
- ebitset_elt *elt = elts[j];
-
- if (elt)
- {
- if (!ebitset_elt_zero_p (elt))
- return 0;
- /* Do some weeding as we go. */
- ebitset_elt_remove (dst, j);
- }
- }
-
- /* All the bits are zero. We could shrink the elts.
- For now just mark DST as known to be zero. */
- EBITSET_ZERO_SET (dst);
- return 1;
-}
-
-
-static void
-ebitset_not (bitset dst, bitset src)
-{
- unsigned int i;
- ebitset_elt *selt;
- ebitset_elt *delt;
- bitset_windex j;
-
- ebitset_resize (dst, BITSET_NBITS_ (src));
-
- for (j = 0; j < EBITSET_SIZE (src); j++)
- {
- /* Create new elements for dst if they cannot be found
- or substitute zero elements if src elements not found. */
- selt =
- ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_SUBST);
- delt =
- ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE);
-
- for (i = 0; i < EBITSET_ELT_WORDS; i++)
- EBITSET_WORDS (delt)[i] = ~EBITSET_WORDS (selt)[i];
- }
- EBITSET_NONZERO_SET (dst);
- ebitset_unused_clear (dst);
-}
-
-
-/* Is DST == DST | SRC? */
-static bool
-ebitset_subset_p (bitset dst, bitset src)
-{
- bitset_windex j;
- ebitset_elts *selts;
- ebitset_elts *delts;
- bitset_windex ssize;
- bitset_windex dsize;
-
- selts = EBITSET_ELTS (src);
- delts = EBITSET_ELTS (dst);
-
- ssize = EBITSET_SIZE (src);
- dsize = EBITSET_SIZE (dst);
-
- for (j = 0; j < ssize; j++)
- {
- unsigned int i;
- ebitset_elt *selt;
- ebitset_elt *delt;
-
- selt = j < ssize ? selts[j] : 0;
- delt = j < dsize ? delts[j] : 0;
-
- if (!selt && !delt)
- continue;
-
- if (!selt)
- selt = &ebitset_zero_elts[0];
- if (!delt)
- delt = &ebitset_zero_elts[0];
-
- for (i = 0; i < EBITSET_ELT_WORDS; i++)
- if (EBITSET_WORDS (delt)[i]
- != (EBITSET_WORDS (selt)[i] | EBITSET_WORDS (delt)[i]))
- return false;
- }
- return true;
-}
-
-
-/* Is DST & SRC == 0? */
-static bool
-ebitset_disjoint_p (bitset dst, bitset src)
-{
- bitset_windex j;
- ebitset_elts *selts;
- ebitset_elts *delts;
- bitset_windex ssize;
- bitset_windex dsize;
-
- selts = EBITSET_ELTS (src);
- delts = EBITSET_ELTS (dst);
-
- ssize = EBITSET_SIZE (src);
- dsize = EBITSET_SIZE (dst);
-
- for (j = 0; j < ssize; j++)
- {
- unsigned int i;
- ebitset_elt *selt;
- ebitset_elt *delt;
-
- selt = j < ssize ? selts[j] : 0;
- delt = j < dsize ? delts[j] : 0;
-
- if (!selt || !delt)
- continue;
-
- for (i = 0; i < EBITSET_ELT_WORDS; i++)
- if ((EBITSET_WORDS (selt)[i] & EBITSET_WORDS (delt)[i]))
- return false;
- }
- return true;
-}
-
-
-
-static bool
-ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
-{
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
- bitset_windex size;
- ebitset_elts *selts1;
- ebitset_elts *selts2;
- ebitset_elts *delts;
- bitset_word *srcp1;
- bitset_word *srcp2;
- bitset_word *dstp;
- bool changed = false;
- unsigned int i;
- bitset_windex j;
-
- ebitset_resize (dst, max (BITSET_NBITS_ (src1), BITSET_NBITS_ (src2)));
-
- ssize1 = EBITSET_SIZE (src1);
- ssize2 = EBITSET_SIZE (src2);
- dsize = EBITSET_SIZE (dst);
- size = ssize1;
- if (size < ssize2)
- size = ssize2;
-
- selts1 = EBITSET_ELTS (src1);
- selts2 = EBITSET_ELTS (src2);
- delts = EBITSET_ELTS (dst);
-
- for (j = 0; j < size; j++)
- {
- ebitset_elt *selt1;
- ebitset_elt *selt2;
- ebitset_elt *delt;
-
- selt1 = j < ssize1 ? selts1[j] : 0;
- selt2 = j < ssize2 ? selts2[j] : 0;
- delt = j < dsize ? delts[j] : 0;
-
- if (!selt1 && !selt2)
- {
- if (delt)
- {
- changed = true;
- ebitset_elt_remove (dst, j);
- }
- continue;
- }
-
- if (!selt1)
- selt1 = &ebitset_zero_elts[0];
- if (!selt2)
- selt2 = &ebitset_zero_elts[0];
- if (!delt)
- delt = ebitset_elt_calloc ();
- else
- delts[j] = 0;
-
- srcp1 = EBITSET_WORDS (selt1);
- srcp2 = EBITSET_WORDS (selt2);
- dstp = EBITSET_WORDS (delt);
- switch (op)
- {
- default:
- abort ();
-
- case BITSET_OP_OR:
- for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ | *srcp2++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
-
- case BITSET_OP_AND:
- for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ & *srcp2++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
-
- case BITSET_OP_XOR:
- for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ ^ *srcp2++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
-
- case BITSET_OP_ANDN:
- for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ & ~(*srcp2++);
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
- }
-
- if (!ebitset_elt_zero_p (delt))
- {
- ebitset_elt_add (dst, delt, j);
- }
- else
- {
- ebitset_elt_free (delt);
- }
- }
-
- /* If we have elements of DST left over, free them all. */
- for (; j < dsize; j++)
- {
- ebitset_elt *delt;
-
- changed = true;
-
- delt = delts[j];
-
- if (delt)
- ebitset_elt_remove (dst, j);
- }
-
- EBITSET_NONZERO_SET (dst);
- return changed;
-}
-
-
-static bool
-ebitset_and_cmp (bitset dst, bitset src1, bitset src2)
-{
- bool changed;
-
- if (EBITSET_ZERO_P (src2))
- {
- ebitset_weed (dst);
- changed = EBITSET_ZERO_P (dst);
- ebitset_zero (dst);
- return changed;
- }
- else if (EBITSET_ZERO_P (src1))
- {
- ebitset_weed (dst);
- changed = EBITSET_ZERO_P (dst);
- ebitset_zero (dst);
- return changed;
- }
- return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
-}
-
-
-static void
-ebitset_and (bitset dst, bitset src1, bitset src2)
-{
- ebitset_and_cmp (dst, src1, src2);
-}
-
-
-static bool
-ebitset_andn_cmp (bitset dst, bitset src1, bitset src2)
-{
- bool changed;
-
- if (EBITSET_ZERO_P (src2))
- {
- return ebitset_copy_cmp (dst, src1);
- }
- else if (EBITSET_ZERO_P (src1))
- {
- ebitset_weed (dst);
- changed = EBITSET_ZERO_P (dst);
- ebitset_zero (dst);
- return changed;
- }
- return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
-}
-
-
-static void
-ebitset_andn (bitset dst, bitset src1, bitset src2)
-{
- ebitset_andn_cmp (dst, src1, src2);
-}
-
-
-static bool
-ebitset_or_cmp (bitset dst, bitset src1, bitset src2)
-{
- if (EBITSET_ZERO_P (src2))
- {
- return ebitset_copy_cmp (dst, src1);
- }
- else if (EBITSET_ZERO_P (src1))
- {
- return ebitset_copy_cmp (dst, src2);
- }
- return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
-}
-
-
-static void
-ebitset_or (bitset dst, bitset src1, bitset src2)
-{
- ebitset_or_cmp (dst, src1, src2);
-}
-
-
-static bool
-ebitset_xor_cmp (bitset dst, bitset src1, bitset src2)
-{
- if (EBITSET_ZERO_P (src2))
- {
- return ebitset_copy_cmp (dst, src1);
- }
- else if (EBITSET_ZERO_P (src1))
- {
- return ebitset_copy_cmp (dst, src2);
- }
- return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
-}
-
-
-static void
-ebitset_xor (bitset dst, bitset src1, bitset src2)
-{
- ebitset_xor_cmp (dst, src1, src2);
-}
-
-
-static void
-ebitset_copy (bitset dst, bitset src)
-{
- if (BITSET_COMPATIBLE_ (dst, src))
- ebitset_copy_ (dst, src);
- else
- bitset_copy_ (dst, src);
-}
-
-
-/* Vector of operations for linked-list bitsets. */
-struct bitset_vtable ebitset_vtable = {
- ebitset_set,
- ebitset_reset,
- bitset_toggle_,
- ebitset_test,
- ebitset_resize,
- bitset_size_,
- bitset_count_,
- ebitset_empty_p,
- ebitset_ones,
- ebitset_zero,
- ebitset_copy,
- ebitset_disjoint_p,
- ebitset_equal_p,
- ebitset_not,
- ebitset_subset_p,
- ebitset_and,
- ebitset_and_cmp,
- ebitset_andn,
- ebitset_andn_cmp,
- ebitset_or,
- ebitset_or_cmp,
- ebitset_xor,
- ebitset_xor_cmp,
- bitset_and_or_,
- bitset_and_or_cmp_,
- bitset_andn_or_,
- bitset_andn_or_cmp_,
- bitset_or_and_,
- bitset_or_and_cmp_,
- ebitset_list,
- ebitset_list_reverse,
- ebitset_free,
- BITSET_TABLE
-};
-
-
-/* Return size of initial structure. */
-size_t
-ebitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED)
-{
- return sizeof (struct ebitset_struct);
-}
-
-
-/* Initialize a bitset. */
-
-bitset
-ebitset_init (bitset bset, bitset_bindex n_bits)
-{
- bset->b.vtable = &ebitset_vtable;
-
- bset->b.csize = EBITSET_ELT_WORDS;
-
- EBITSET_ZERO_SET (bset);
-
- EBITSET_ASIZE (bset) = 0;
- EBITSET_ELTS (bset) = 0;
- ebitset_resize (bset, n_bits);
-
- return bset;
-}
-
-
-void
-ebitset_release_memory (void)
-{
- ebitset_free_list = 0;
- if (ebitset_obstack_init)
- {
- ebitset_obstack_init = false;
- obstack_free (&ebitset_obstack, NULL);
- }
-}
+/* Functions to support expandable bitsets.
+
+ Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "ebitset.h"
+
+#include "obstack.h"
+#include <stdlib.h>
+#include <string.h>
+
+/* This file implements expandable bitsets. These bitsets can be of
+ arbitrary length and are more efficient than arrays of bits for
+ large sparse sets.
+
+ Empty elements are represented by a NULL pointer in the table of
+ element pointers. An alternative is to point to a special zero
+ element. Similarly, we could represent an all 1's element with
+ another special ones element pointer.
+
+ Bitsets are commonly empty so we need to ensure that this special
+ case is fast. A zero bitset is indicated when cdata is 0. This is
+ conservative since cdata may be non zero and the bitset may still
+ be zero.
+
+ The bitset cache can be disabled either by setting cindex to
+ BITSET_WINDEX_MAX or by setting csize to 0. Here
+ we use the former approach since cindex needs to be updated whenever
+ cdata is changed.
+*/
+
+
+/* Number of words to use for each element. */
+#define EBITSET_ELT_WORDS 2
+
+/* Number of bits stored in each element. */
+#define EBITSET_ELT_BITS \
+ ((unsigned int) (EBITSET_ELT_WORDS * BITSET_WORD_BITS))
+
+/* Ebitset element. We use an array of bits. */
+typedef struct ebitset_elt_struct
+{
+ union
+ {
+ bitset_word words[EBITSET_ELT_WORDS]; /* Bits that are set. */
+ struct ebitset_elt_struct *next;
+ }
+ u;
+}
+ebitset_elt;
+
+
+typedef ebitset_elt *ebitset_elts;
+
+
+/* Number of elements to initially allocate. */
+
+#ifndef EBITSET_INITIAL_SIZE
+#define EBITSET_INITIAL_SIZE 2
+#endif
+
+
+enum ebitset_find_mode
+ { EBITSET_FIND, EBITSET_CREATE, EBITSET_SUBST };
+
+static ebitset_elt ebitset_zero_elts[1]; /* Elements of all zero bits. */
+
+/* Obstack to allocate bitset elements from. */
+static struct obstack ebitset_obstack;
+static bool ebitset_obstack_init = false;
+static ebitset_elt *ebitset_free_list; /* Free list of bitset elements. */
+
+#define EBITSET_N_ELTS(N) (((N) + EBITSET_ELT_BITS - 1) / EBITSET_ELT_BITS)
+#define EBITSET_ELTS(BSET) ((BSET)->e.elts)
+#define EBITSET_SIZE(BSET) EBITSET_N_ELTS (BITSET_NBITS_ (BSET))
+#define EBITSET_ASIZE(BSET) ((BSET)->e.size)
+
+#define EBITSET_NEXT(ELT) ((ELT)->u.next)
+#define EBITSET_WORDS(ELT) ((ELT)->u.words)
+
+/* Disable bitset cache and mark BSET as being zero. */
+#define EBITSET_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX, \
+ (BSET)->b.cdata = 0)
+
+#define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX)
+
+/* Disable bitset cache and mark BSET as being possibly non-zero. */
+#define EBITSET_NONZERO_SET(BSET) \
+ (EBITSET_CACHE_DISABLE (BSET), (BSET)->b.cdata = (bitset_word *)~0)
+
+/* A conservative estimate of whether the bitset is zero.
+ This is non-zero only if we know for sure that the bitset is zero. */
+#define EBITSET_ZERO_P(BSET) ((BSET)->b.cdata == 0)
+
+/* Enable cache to point to element with table index EINDEX.
+ The element must exist. */
+#define EBITSET_CACHE_SET(BSET, EINDEX) \
+ ((BSET)->b.cindex = (EINDEX) * EBITSET_ELT_WORDS, \
+ (BSET)->b.cdata = EBITSET_WORDS (EBITSET_ELTS (BSET) [EINDEX]))
+
+#undef min
+#undef max
+#define min(a, b) ((a) > (b) ? (b) : (a))
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+static bitset_bindex
+ebitset_resize (bitset src, bitset_bindex n_bits)
+{
+ bitset_windex oldsize;
+ bitset_windex newsize;
+
+ if (n_bits == BITSET_NBITS_ (src))
+ return n_bits;
+
+ oldsize = EBITSET_SIZE (src);
+ newsize = EBITSET_N_ELTS (n_bits);
+
+ if (oldsize < newsize)
+ {
+ bitset_windex size;
+
+ /* The bitset needs to grow. If we already have enough memory
+ allocated, then just zero what we need. */
+ if (newsize > EBITSET_ASIZE (src))
+ {
+ /* We need to allocate more memory. When oldsize is
+ non-zero this means that we are changing the size, so
+ grow the bitset 25% larger than requested to reduce
+ number of reallocations. */
+
+ if (oldsize == 0)
+ size = newsize;
+ else
+ size = newsize + newsize / 4;
+
+ EBITSET_ELTS (src)
+ = realloc (EBITSET_ELTS (src), size * sizeof (ebitset_elt *));
+ EBITSET_ASIZE (src) = size;
+ }
+
+ memset (EBITSET_ELTS (src) + oldsize, 0,
+ (newsize - oldsize) * sizeof (ebitset_elt *));
+ }
+ else
+ {
+ /* The bitset needs to shrink. There's no point deallocating
+ the memory unless it is shrinking by a reasonable amount. */
+ if ((oldsize - newsize) >= oldsize / 2)
+ {
+ EBITSET_ELTS (src)
+ = realloc (EBITSET_ELTS (src), newsize * sizeof (ebitset_elt *));
+ EBITSET_ASIZE (src) = newsize;
+ }
+
+ /* Need to prune any excess bits. FIXME. */
+ }
+
+ BITSET_NBITS_ (src) = n_bits;
+ return n_bits;
+}
+
+
+/* Allocate a ebitset element. The bits are not cleared. */
+static inline ebitset_elt *
+ebitset_elt_alloc (void)
+{
+ ebitset_elt *elt;
+
+ if (ebitset_free_list != 0)
+ {
+ elt = ebitset_free_list;
+ ebitset_free_list = EBITSET_NEXT (elt);
+ }
+ else
+ {
+ if (!ebitset_obstack_init)
+ {
+ ebitset_obstack_init = true;
+
+ /* Let particular systems override the size of a chunk. */
+
+#ifndef OBSTACK_CHUNK_SIZE
+#define OBSTACK_CHUNK_SIZE 0
+#endif
+
+ /* Let them override the alloc and free routines too. */
+
+#ifndef OBSTACK_CHUNK_ALLOC
+#define OBSTACK_CHUNK_ALLOC xmalloc
+#endif
+
+#ifndef OBSTACK_CHUNK_FREE
+#define OBSTACK_CHUNK_FREE free
+#endif
+
+#if ! defined __GNUC__ || __GNUC__ < 2
+#define __alignof__(type) 0
+#endif
+
+ obstack_specify_allocation (&ebitset_obstack, OBSTACK_CHUNK_SIZE,
+ __alignof__ (ebitset_elt),
+ OBSTACK_CHUNK_ALLOC,
+ OBSTACK_CHUNK_FREE);
+ }
+
+ /* Perhaps we should add a number of new elements to the free
+ list. */
+ elt = (ebitset_elt *) obstack_alloc (&ebitset_obstack,
+ sizeof (ebitset_elt));
+ }
+
+ return elt;
+}
+
+
+/* Allocate a ebitset element. The bits are cleared. */
+static inline ebitset_elt *
+ebitset_elt_calloc (void)
+{
+ ebitset_elt *elt;
+
+ elt = ebitset_elt_alloc ();
+ memset (EBITSET_WORDS (elt), 0, sizeof (EBITSET_WORDS (elt)));
+ return elt;
+}
+
+
+static inline void
+ebitset_elt_free (ebitset_elt *elt)
+{
+ EBITSET_NEXT (elt) = ebitset_free_list;
+ ebitset_free_list = elt;
+}
+
+
+/* Remove element with index EINDEX from bitset BSET. */
+static inline void
+ebitset_elt_remove (bitset bset, bitset_windex eindex)
+{
+ ebitset_elts *elts;
+ ebitset_elt *elt;
+
+ elts = EBITSET_ELTS (bset);
+
+ elt = elts[eindex];
+
+ elts[eindex] = 0;
+ ebitset_elt_free (elt);
+}
+
+
+/* Add ELT into elts at index EINDEX of bitset BSET. */
+static inline void
+ebitset_elt_add (bitset bset, ebitset_elt *elt, bitset_windex eindex)
+{
+ ebitset_elts *elts;
+
+ elts = EBITSET_ELTS (bset);
+ /* Assume that the elts entry not allocated. */
+ elts[eindex] = elt;
+}
+
+
+/* Are all bits in an element zero? */
+static inline bool
+ebitset_elt_zero_p (ebitset_elt *elt)
+{
+ int i;
+
+ for (i = 0; i < EBITSET_ELT_WORDS; i++)
+ if (EBITSET_WORDS (elt)[i])
+ return false;
+
+ return true;
+}
+
+
+static ebitset_elt *
+ebitset_elt_find (bitset bset, bitset_bindex bindex,
+ enum ebitset_find_mode mode)
+{
+ ebitset_elt *elt;
+ bitset_windex size;
+ bitset_windex eindex;
+ ebitset_elts *elts;
+
+ eindex = bindex / EBITSET_ELT_BITS;
+
+ elts = EBITSET_ELTS (bset);
+ size = EBITSET_SIZE (bset);
+
+ if (eindex < size)
+ {
+ if ((elt = elts[eindex]))
+ {
+ if (EBITSET_WORDS (elt) == bset->b.cdata)
+ return elt;
+
+ EBITSET_CACHE_SET (bset, eindex);
+ return elt;
+ }
+ }
+
+ /* The element could not be found. */
+
+ switch (mode)
+ {
+ default:
+ abort ();
+
+ case EBITSET_FIND:
+ return 0;
+
+ case EBITSET_CREATE:
+ if (eindex >= size)
+ ebitset_resize (bset, bindex);
+
+ /* Create a new element. */
+ elt = ebitset_elt_calloc ();
+ ebitset_elt_add (bset, elt, eindex);
+ EBITSET_CACHE_SET (bset, eindex);
+ return elt;
+
+ case EBITSET_SUBST:
+ return &ebitset_zero_elts[0];
+ }
+}
+
+
+/* Weed out the zero elements from the elts. */
+static inline bitset_windex
+ebitset_weed (bitset bset)
+{
+ ebitset_elts *elts;
+ bitset_windex j;
+ bitset_windex count;
+
+ if (EBITSET_ZERO_P (bset))
+ return 0;
+
+ elts = EBITSET_ELTS (bset);
+ count = 0;
+ for (j = 0; j < EBITSET_SIZE (bset); j++)
+ {
+ ebitset_elt *elt = elts[j];
+
+ if (elt)
+ {
+ if (ebitset_elt_zero_p (elt))
+ {
+ ebitset_elt_remove (bset, j);
+ count++;
+ }
+ }
+ else
+ count++;
+ }
+
+ count = j - count;
+ if (!count)
+ {
+ /* All the bits are zero. We could shrink the elts.
+ For now just mark BSET as known to be zero. */
+ EBITSET_ZERO_SET (bset);
+ }
+ else
+ EBITSET_NONZERO_SET (bset);
+
+ return count;
+}
+
+
+/* Set all bits in the bitset to zero. */
+static inline void
+ebitset_zero (bitset bset)
+{
+ ebitset_elts *elts;
+ bitset_windex j;
+
+ if (EBITSET_ZERO_P (bset))
+ return;
+
+ elts = EBITSET_ELTS (bset);
+ for (j = 0; j < EBITSET_SIZE (bset); j++)
+ {
+ ebitset_elt *elt = elts[j];
+
+ if (elt)
+ ebitset_elt_remove (bset, j);
+ }
+
+ /* All the bits are zero. We could shrink the elts.
+ For now just mark BSET as known to be zero. */
+ EBITSET_ZERO_SET (bset);
+}
+
+
+static inline bool
+ebitset_equal_p (bitset dst, bitset src)
+{
+ ebitset_elts *selts;
+ ebitset_elts *delts;
+ bitset_windex j;
+
+ if (src == dst)
+ return true;
+
+ ebitset_weed (dst);
+ ebitset_weed (src);
+
+ if (EBITSET_SIZE (src) != EBITSET_SIZE (dst))
+ return false;
+
+ selts = EBITSET_ELTS (src);
+ delts = EBITSET_ELTS (dst);
+
+ for (j = 0; j < EBITSET_SIZE (src); j++)
+ {
+ unsigned int i;
+ ebitset_elt *selt = selts[j];
+ ebitset_elt *delt = delts[j];
+
+ if (!selt && !delt)
+ continue;
+ if ((selt && !delt) || (!selt && delt))
+ return false;
+
+ for (i = 0; i < EBITSET_ELT_WORDS; i++)
+ if (EBITSET_WORDS (selt)[i] != EBITSET_WORDS (delt)[i])
+ return false;
+ }
+ return true;
+}
+
+
+/* Copy bits from bitset SRC to bitset DST. */
+static inline void
+ebitset_copy_ (bitset dst, bitset src)
+{
+ ebitset_elts *selts;
+ ebitset_elts *delts;
+ bitset_windex j;
+
+ if (src == dst)
+ return;
+
+ ebitset_zero (dst);
+
+ if (BITSET_NBITS_ (dst) != BITSET_NBITS_ (src))
+ ebitset_resize (dst, BITSET_NBITS_ (src));
+
+ selts = EBITSET_ELTS (src);
+ delts = EBITSET_ELTS (dst);
+ for (j = 0; j < EBITSET_SIZE (src); j++)
+ {
+ ebitset_elt *selt = selts[j];
+
+ if (selt)
+ {
+ ebitset_elt *tmp;
+
+ tmp = ebitset_elt_alloc ();
+ delts[j] = tmp;
+ memcpy (EBITSET_WORDS (tmp), EBITSET_WORDS (selt),
+ sizeof (EBITSET_WORDS (selt)));
+ }
+ }
+ EBITSET_NONZERO_SET (dst);
+}
+
+
+/* Copy bits from bitset SRC to bitset DST. Return true if
+ bitsets different. */
+static inline bool
+ebitset_copy_cmp (bitset dst, bitset src)
+{
+ if (src == dst)
+ return false;
+
+ if (EBITSET_ZERO_P (dst))
+ {
+ ebitset_copy_ (dst, src);
+ return !EBITSET_ZERO_P (src);
+ }
+
+ if (ebitset_equal_p (dst, src))
+ return false;
+
+ ebitset_copy_ (dst, src);
+ return true;
+}
+
+
+/* Set bit BITNO in bitset DST. */
+static void
+ebitset_set (bitset dst, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+
+ ebitset_elt_find (dst, bitno, EBITSET_CREATE);
+
+ dst->b.cdata[windex - dst->b.cindex] |=
+ (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
+}
+
+
+/* Reset bit BITNO in bitset DST. */
+static void
+ebitset_reset (bitset dst, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+
+ if (!ebitset_elt_find (dst, bitno, EBITSET_FIND))
+ return;
+
+ dst->b.cdata[windex - dst->b.cindex] &=
+ ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
+
+ /* If all the data is zero, perhaps we should remove it now...
+ However, there is a good chance that the element will be needed
+ again soon. */
+}
+
+
+/* Test bit BITNO in bitset SRC. */
+static bool
+ebitset_test (bitset src, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+
+ return (ebitset_elt_find (src, bitno, EBITSET_FIND)
+ && ((src->b.cdata[windex - src->b.cindex]
+ >> (bitno % BITSET_WORD_BITS))
+ & 1));
+}
+
+
+static void
+ebitset_free (bitset bset)
+{
+ ebitset_zero (bset);
+ free (EBITSET_ELTS (bset));
+}
+
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT and store in array LIST. Return with actual number of bits
+ found and with *NEXT indicating where search stopped. */
+static bitset_bindex
+ebitset_list_reverse (bitset bset, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex n_bits;
+ bitset_bindex bitno;
+ bitset_bindex rbitno;
+ unsigned int bcount;
+ bitset_bindex boffset;
+ bitset_windex windex;
+ bitset_windex eindex;
+ bitset_windex woffset;
+ bitset_bindex count;
+ bitset_windex size;
+ ebitset_elts *elts;
+
+ if (EBITSET_ZERO_P (bset))
+ return 0;
+
+ size = EBITSET_SIZE (bset);
+ n_bits = size * EBITSET_ELT_BITS;
+ rbitno = *next;
+
+ if (rbitno >= n_bits)
+ return 0;
+
+ elts = EBITSET_ELTS (bset);
+
+ bitno = n_bits - (rbitno + 1);
+
+ windex = bitno / BITSET_WORD_BITS;
+ eindex = bitno / EBITSET_ELT_BITS;
+ woffset = windex - eindex * EBITSET_ELT_WORDS;
+
+ /* If num is 1, we could speed things up with a binary search
+ of the word of interest. */
+
+ count = 0;
+ bcount = bitno % BITSET_WORD_BITS;
+ boffset = windex * BITSET_WORD_BITS;
+
+ do
+ {
+ ebitset_elt *elt;
+ bitset_word *srcp;
+
+ elt = elts[eindex];
+ if (elt)
+ {
+ srcp = EBITSET_WORDS (elt);
+
+ do
+ {
+ bitset_word word;
+
+ word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount);
+
+ for (; word; bcount--)
+ {
+ if (word & BITSET_MSB)
+ {
+ list[count++] = boffset + bcount;
+ if (count >= num)
+ {
+ *next = n_bits - (boffset + bcount);
+ return count;
+ }
+ }
+ word <<= 1;
+ }
+ boffset -= BITSET_WORD_BITS;
+ bcount = BITSET_WORD_BITS - 1;
+ }
+ while (woffset--);
+ }
+
+ woffset = EBITSET_ELT_WORDS - 1;
+ boffset = eindex * EBITSET_ELT_BITS - BITSET_WORD_BITS;
+ }
+ while (eindex--);
+
+ *next = n_bits - (boffset + 1);
+ return count;
+}
+
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT and store in array LIST. Return with actual number of bits
+ found and with *NEXT indicating where search stopped. */
+static bitset_bindex
+ebitset_list (bitset bset, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex bitno;
+ bitset_windex windex;
+ bitset_windex eindex;
+ bitset_bindex count;
+ bitset_windex size;
+ ebitset_elt *elt;
+ bitset_word word;
+ ebitset_elts *elts;
+
+ if (EBITSET_ZERO_P (bset))
+ return 0;
+
+ bitno = *next;
+ count = 0;
+
+ elts = EBITSET_ELTS (bset);
+ size = EBITSET_SIZE (bset);
+ eindex = bitno / EBITSET_ELT_BITS;
+
+ if (bitno % EBITSET_ELT_BITS)
+ {
+ /* We need to start within an element. This is not very common. */
+
+ elt = elts[eindex];
+ if (elt)
+ {
+ bitset_windex woffset;
+ bitset_word *srcp = EBITSET_WORDS (elt);
+
+ windex = bitno / BITSET_WORD_BITS;
+ woffset = eindex * EBITSET_ELT_WORDS;
+
+ for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++)
+ {
+ word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS);
+
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ bitno = (windex + 1) * BITSET_WORD_BITS;
+ }
+ }
+
+ /* Skip to next element. */
+ eindex++;
+ }
+
+ /* If num is 1, we could speed things up with a binary search
+ of the word of interest. */
+
+ for (; eindex < size; eindex++)
+ {
+ int i;
+ bitset_word *srcp;
+
+ elt = elts[eindex];
+ if (!elt)
+ continue;
+
+ srcp = EBITSET_WORDS (elt);
+ windex = eindex * EBITSET_ELT_WORDS;
+
+ if ((count + EBITSET_ELT_BITS) < num)
+ {
+ /* The coast is clear, plant boot! */
+
+#if EBITSET_ELT_WORDS == 2
+ word = srcp[0];
+ if (word)
+ {
+ if (!(word & 0xffff))
+ {
+ word >>= 16;
+ bitno += 16;
+ }
+ if (!(word & 0xff))
+ {
+ word >>= 8;
+ bitno += 8;
+ }
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ windex++;
+ bitno = windex * BITSET_WORD_BITS;
+
+ word = srcp[1];
+ if (word)
+ {
+ if (!(word & 0xffff))
+ {
+ word >>= 16;
+ bitno += 16;
+ }
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ windex++;
+ bitno = windex * BITSET_WORD_BITS;
+#else
+ for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++)
+ {
+ bitno = windex * BITSET_WORD_BITS;
+
+ word = srcp[i];
+ if (word)
+ {
+ if (!(word & 0xffff))
+ {
+ word >>= 16;
+ bitno += 16;
+ }
+ if (!(word & 0xff))
+ {
+ word >>= 8;
+ bitno += 8;
+ }
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ }
+#endif
+ }
+ else
+ {
+ /* Tread more carefully since we need to check
+ if array overflows. */
+
+ for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++)
+ {
+ bitno = windex * BITSET_WORD_BITS;
+
+ for (word = srcp[i]; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ }
+ }
+ }
+
+ *next = bitno;
+ return count;
+}
+
+
+/* Ensure that any unused bits within the last element are clear. */
+static inline void
+ebitset_unused_clear (bitset dst)
+{
+ unsigned int last_bit;
+ bitset_bindex n_bits;
+
+ n_bits = BITSET_NBITS_ (dst);
+ last_bit = n_bits % EBITSET_ELT_BITS;
+
+ if (last_bit)
+ {
+ bitset_windex eindex;
+ ebitset_elts *elts;
+ ebitset_elt *elt;
+
+ elts = EBITSET_ELTS (dst);
+
+ eindex = n_bits / EBITSET_ELT_BITS;
+
+ elt = elts[eindex];
+ if (elt)
+ {
+ bitset_windex windex;
+ bitset_windex woffset;
+ bitset_word *srcp = EBITSET_WORDS (elt);
+
+ windex = n_bits / BITSET_WORD_BITS;
+ woffset = eindex * EBITSET_ELT_WORDS;
+
+ srcp[windex - woffset] &= ((bitset_word) 1 << last_bit) - 1;
+ windex++;
+ for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++)
+ srcp[windex - woffset] = 0;
+ }
+ }
+}
+
+
+static void
+ebitset_ones (bitset dst)
+{
+ bitset_windex j;
+ ebitset_elt *elt;
+
+ for (j = 0; j < EBITSET_SIZE (dst); j++)
+ {
+ /* Create new elements if they cannot be found. Perhaps
+ we should just add pointers to a ones element? */
+ elt =
+ ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE);
+ memset (EBITSET_WORDS (elt), -1, sizeof (EBITSET_WORDS (elt)));
+ }
+ EBITSET_NONZERO_SET (dst);
+ ebitset_unused_clear (dst);
+}
+
+
+static bool
+ebitset_empty_p (bitset dst)
+{
+ ebitset_elts *elts;
+ bitset_windex j;
+
+ if (EBITSET_ZERO_P (dst))
+ return 1;
+
+ elts = EBITSET_ELTS (dst);
+ for (j = 0; j < EBITSET_SIZE (dst); j++)
+ {
+ ebitset_elt *elt = elts[j];
+
+ if (elt)
+ {
+ if (!ebitset_elt_zero_p (elt))
+ return 0;
+ /* Do some weeding as we go. */
+ ebitset_elt_remove (dst, j);
+ }
+ }
+
+ /* All the bits are zero. We could shrink the elts.
+ For now just mark DST as known to be zero. */
+ EBITSET_ZERO_SET (dst);
+ return 1;
+}
+
+
+static void
+ebitset_not (bitset dst, bitset src)
+{
+ unsigned int i;
+ ebitset_elt *selt;
+ ebitset_elt *delt;
+ bitset_windex j;
+
+ ebitset_resize (dst, BITSET_NBITS_ (src));
+
+ for (j = 0; j < EBITSET_SIZE (src); j++)
+ {
+ /* Create new elements for dst if they cannot be found
+ or substitute zero elements if src elements not found. */
+ selt =
+ ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_SUBST);
+ delt =
+ ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE);
+
+ for (i = 0; i < EBITSET_ELT_WORDS; i++)
+ EBITSET_WORDS (delt)[i] = ~EBITSET_WORDS (selt)[i];
+ }
+ EBITSET_NONZERO_SET (dst);
+ ebitset_unused_clear (dst);
+}
+
+
+/* Is DST == DST | SRC? */
+static bool
+ebitset_subset_p (bitset dst, bitset src)
+{
+ bitset_windex j;
+ ebitset_elts *selts;
+ ebitset_elts *delts;
+ bitset_windex ssize;
+ bitset_windex dsize;
+
+ selts = EBITSET_ELTS (src);
+ delts = EBITSET_ELTS (dst);
+
+ ssize = EBITSET_SIZE (src);
+ dsize = EBITSET_SIZE (dst);
+
+ for (j = 0; j < ssize; j++)
+ {
+ unsigned int i;
+ ebitset_elt *selt;
+ ebitset_elt *delt;
+
+ selt = j < ssize ? selts[j] : 0;
+ delt = j < dsize ? delts[j] : 0;
+
+ if (!selt && !delt)
+ continue;
+
+ if (!selt)
+ selt = &ebitset_zero_elts[0];
+ if (!delt)
+ delt = &ebitset_zero_elts[0];
+
+ for (i = 0; i < EBITSET_ELT_WORDS; i++)
+ if (EBITSET_WORDS (delt)[i]
+ != (EBITSET_WORDS (selt)[i] | EBITSET_WORDS (delt)[i]))
+ return false;
+ }
+ return true;
+}
+
+
+/* Is DST & SRC == 0? */
+static bool
+ebitset_disjoint_p (bitset dst, bitset src)
+{
+ bitset_windex j;
+ ebitset_elts *selts;
+ ebitset_elts *delts;
+ bitset_windex ssize;
+ bitset_windex dsize;
+
+ selts = EBITSET_ELTS (src);
+ delts = EBITSET_ELTS (dst);
+
+ ssize = EBITSET_SIZE (src);
+ dsize = EBITSET_SIZE (dst);
+
+ for (j = 0; j < ssize; j++)
+ {
+ unsigned int i;
+ ebitset_elt *selt;
+ ebitset_elt *delt;
+
+ selt = j < ssize ? selts[j] : 0;
+ delt = j < dsize ? delts[j] : 0;
+
+ if (!selt || !delt)
+ continue;
+
+ for (i = 0; i < EBITSET_ELT_WORDS; i++)
+ if ((EBITSET_WORDS (selt)[i] & EBITSET_WORDS (delt)[i]))
+ return false;
+ }
+ return true;
+}
+
+
+
+static bool
+ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
+{
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+ bitset_windex size;
+ ebitset_elts *selts1;
+ ebitset_elts *selts2;
+ ebitset_elts *delts;
+ bitset_word *srcp1;
+ bitset_word *srcp2;
+ bitset_word *dstp;
+ bool changed = false;
+ unsigned int i;
+ bitset_windex j;
+
+ ebitset_resize (dst, max (BITSET_NBITS_ (src1), BITSET_NBITS_ (src2)));
+
+ ssize1 = EBITSET_SIZE (src1);
+ ssize2 = EBITSET_SIZE (src2);
+ dsize = EBITSET_SIZE (dst);
+ size = ssize1;
+ if (size < ssize2)
+ size = ssize2;
+
+ selts1 = EBITSET_ELTS (src1);
+ selts2 = EBITSET_ELTS (src2);
+ delts = EBITSET_ELTS (dst);
+
+ for (j = 0; j < size; j++)
+ {
+ ebitset_elt *selt1;
+ ebitset_elt *selt2;
+ ebitset_elt *delt;
+
+ selt1 = j < ssize1 ? selts1[j] : 0;
+ selt2 = j < ssize2 ? selts2[j] : 0;
+ delt = j < dsize ? delts[j] : 0;
+
+ if (!selt1 && !selt2)
+ {
+ if (delt)
+ {
+ changed = true;
+ ebitset_elt_remove (dst, j);
+ }
+ continue;
+ }
+
+ if (!selt1)
+ selt1 = &ebitset_zero_elts[0];
+ if (!selt2)
+ selt2 = &ebitset_zero_elts[0];
+ if (!delt)
+ delt = ebitset_elt_calloc ();
+ else
+ delts[j] = 0;
+
+ srcp1 = EBITSET_WORDS (selt1);
+ srcp2 = EBITSET_WORDS (selt2);
+ dstp = EBITSET_WORDS (delt);
+ switch (op)
+ {
+ default:
+ abort ();
+
+ case BITSET_OP_OR:
+ for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ | *srcp2++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+
+ case BITSET_OP_AND:
+ for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ & *srcp2++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+
+ case BITSET_OP_XOR:
+ for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ ^ *srcp2++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+
+ case BITSET_OP_ANDN:
+ for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ & ~(*srcp2++);
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+ }
+
+ if (!ebitset_elt_zero_p (delt))
+ {
+ ebitset_elt_add (dst, delt, j);
+ }
+ else
+ {
+ ebitset_elt_free (delt);
+ }
+ }
+
+ /* If we have elements of DST left over, free them all. */
+ for (; j < dsize; j++)
+ {
+ ebitset_elt *delt;
+
+ changed = true;
+
+ delt = delts[j];
+
+ if (delt)
+ ebitset_elt_remove (dst, j);
+ }
+
+ EBITSET_NONZERO_SET (dst);
+ return changed;
+}
+
+
+static bool
+ebitset_and_cmp (bitset dst, bitset src1, bitset src2)
+{
+ bool changed;
+
+ if (EBITSET_ZERO_P (src2))
+ {
+ ebitset_weed (dst);
+ changed = EBITSET_ZERO_P (dst);
+ ebitset_zero (dst);
+ return changed;
+ }
+ else if (EBITSET_ZERO_P (src1))
+ {
+ ebitset_weed (dst);
+ changed = EBITSET_ZERO_P (dst);
+ ebitset_zero (dst);
+ return changed;
+ }
+ return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
+}
+
+
+static void
+ebitset_and (bitset dst, bitset src1, bitset src2)
+{
+ ebitset_and_cmp (dst, src1, src2);
+}
+
+
+static bool
+ebitset_andn_cmp (bitset dst, bitset src1, bitset src2)
+{
+ bool changed;
+
+ if (EBITSET_ZERO_P (src2))
+ {
+ return ebitset_copy_cmp (dst, src1);
+ }
+ else if (EBITSET_ZERO_P (src1))
+ {
+ ebitset_weed (dst);
+ changed = EBITSET_ZERO_P (dst);
+ ebitset_zero (dst);
+ return changed;
+ }
+ return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
+}
+
+
+static void
+ebitset_andn (bitset dst, bitset src1, bitset src2)
+{
+ ebitset_andn_cmp (dst, src1, src2);
+}
+
+
+static bool
+ebitset_or_cmp (bitset dst, bitset src1, bitset src2)
+{
+ if (EBITSET_ZERO_P (src2))
+ {
+ return ebitset_copy_cmp (dst, src1);
+ }
+ else if (EBITSET_ZERO_P (src1))
+ {
+ return ebitset_copy_cmp (dst, src2);
+ }
+ return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
+}
+
+
+static void
+ebitset_or (bitset dst, bitset src1, bitset src2)
+{
+ ebitset_or_cmp (dst, src1, src2);
+}
+
+
+static bool
+ebitset_xor_cmp (bitset dst, bitset src1, bitset src2)
+{
+ if (EBITSET_ZERO_P (src2))
+ {
+ return ebitset_copy_cmp (dst, src1);
+ }
+ else if (EBITSET_ZERO_P (src1))
+ {
+ return ebitset_copy_cmp (dst, src2);
+ }
+ return ebitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
+}
+
+
+static void
+ebitset_xor (bitset dst, bitset src1, bitset src2)
+{
+ ebitset_xor_cmp (dst, src1, src2);
+}
+
+
+static void
+ebitset_copy (bitset dst, bitset src)
+{
+ if (BITSET_COMPATIBLE_ (dst, src))
+ ebitset_copy_ (dst, src);
+ else
+ bitset_copy_ (dst, src);
+}
+
+
+/* Vector of operations for linked-list bitsets. */
+struct bitset_vtable ebitset_vtable = {
+ ebitset_set,
+ ebitset_reset,
+ bitset_toggle_,
+ ebitset_test,
+ ebitset_resize,
+ bitset_size_,
+ bitset_count_,
+ ebitset_empty_p,
+ ebitset_ones,
+ ebitset_zero,
+ ebitset_copy,
+ ebitset_disjoint_p,
+ ebitset_equal_p,
+ ebitset_not,
+ ebitset_subset_p,
+ ebitset_and,
+ ebitset_and_cmp,
+ ebitset_andn,
+ ebitset_andn_cmp,
+ ebitset_or,
+ ebitset_or_cmp,
+ ebitset_xor,
+ ebitset_xor_cmp,
+ bitset_and_or_,
+ bitset_and_or_cmp_,
+ bitset_andn_or_,
+ bitset_andn_or_cmp_,
+ bitset_or_and_,
+ bitset_or_and_cmp_,
+ ebitset_list,
+ ebitset_list_reverse,
+ ebitset_free,
+ BITSET_TABLE
+};
+
+
+/* Return size of initial structure. */
+size_t
+ebitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED)
+{
+ return sizeof (struct ebitset_struct);
+}
+
+
+/* Initialize a bitset. */
+
+bitset
+ebitset_init (bitset bset, bitset_bindex n_bits)
+{
+ bset->b.vtable = &ebitset_vtable;
+
+ bset->b.csize = EBITSET_ELT_WORDS;
+
+ EBITSET_ZERO_SET (bset);
+
+ EBITSET_ASIZE (bset) = 0;
+ EBITSET_ELTS (bset) = 0;
+ ebitset_resize (bset, n_bits);
+
+ return bset;
+}
+
+
+void
+ebitset_release_memory (void)
+{
+ ebitset_free_list = 0;
+ if (ebitset_obstack_init)
+ {
+ ebitset_obstack_init = false;
+ obstack_free (&ebitset_obstack, NULL);
+ }
+}
diff --git a/contrib/tools/bison/gnulib/src/ebitset.h b/contrib/tools/bison/gnulib/src/ebitset.h
index d31bda7d50..327c1f8db4 100644
--- a/contrib/tools/bison/gnulib/src/ebitset.h
+++ b/contrib/tools/bison/gnulib/src/ebitset.h
@@ -1,31 +1,31 @@
-/* Functions to support ebitsets.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _EBITSET_H
-#define _EBITSET_H
-
-#include "bitset.h"
-
-extern size_t ebitset_bytes (bitset_bindex);
-
-extern bitset ebitset_init (bitset, bitset_bindex);
-
-extern void ebitset_release_memory (void);
-
-#endif
+/* Functions to support ebitsets.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _EBITSET_H
+#define _EBITSET_H
+
+#include "bitset.h"
+
+extern size_t ebitset_bytes (bitset_bindex);
+
+extern bitset ebitset_init (bitset, bitset_bindex);
+
+extern void ebitset_release_memory (void);
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/error.c b/contrib/tools/bison/gnulib/src/error.c
index 3078dd1b51..58d61cf7ec 100644
--- a/contrib/tools/bison/gnulib/src/error.c
+++ b/contrib/tools/bison/gnulib/src/error.c
@@ -1,403 +1,403 @@
-/* Error handler for noninteractive utilities
- Copyright (C) 1990-1998, 2000-2007, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
-
-#if !_LIBC
-# include <config.h>
-#endif
-
-#include "error.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#if !_LIBC && ENABLE_NLS
-# include "gettext.h"
-# define _(msgid) gettext (msgid)
-#endif
-
-#ifdef _LIBC
-# include <libintl.h>
-# include <stdbool.h>
-# include <stdint.h>
-# include <wchar.h>
-# define mbsrtowcs __mbsrtowcs
-#endif
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-#ifndef _
-# define _(String) String
-#endif
-
-/* If NULL, error will flush stdout, then print on stderr the program
- name, a colon and a space. Otherwise, error will call this
- function without parameters instead. */
-void (*error_print_progname) (void);
-
-/* This variable is incremented each time 'error' is called. */
-unsigned int error_message_count;
-
-#ifdef _LIBC
-/* In the GNU C library, there is a predefined variable for this. */
-
-# define program_name program_invocation_name
-# include <errno.h>
-# include <limits.h>
-# include <libio/libioP.h>
-
-/* In GNU libc we want do not want to use the common name 'error' directly.
- Instead make it a weak alias. */
-extern void __error (int status, int errnum, const char *message, ...)
- __attribute__ ((__format__ (__printf__, 3, 4)));
-extern void __error_at_line (int status, int errnum, const char *file_name,
- unsigned int line_number, const char *message,
- ...)
- __attribute__ ((__format__ (__printf__, 5, 6)));;
-# define error __error
-# define error_at_line __error_at_line
-
-# include <libio/iolibio.h>
-# define fflush(s) INTUSE(_IO_fflush) (s)
-# undef putc
-# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
-
-# include <bits/libc-lock.h>
-
-#else /* not _LIBC */
-
-# include <fcntl.h>
-# include <unistd.h>
-
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Get declarations of the native Windows API functions. */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
-# endif
-
-/* The gnulib override of fcntl is not needed in this file. */
-# undef fcntl
-
-# if !HAVE_DECL_STRERROR_R
-# ifndef HAVE_DECL_STRERROR_R
-"this configure-time declaration test was not run"
-# endif
-# if STRERROR_R_CHAR_P
-char *strerror_r ();
-# else
-int strerror_r ();
-# endif
-# endif
-
-/* The calling program should define program_name and set it to the
- name of the executing program. */
-extern char *program_name;
-
-# if HAVE_STRERROR_R || defined strerror_r
-# define __strerror_r strerror_r
-# endif /* HAVE_STRERROR_R || defined strerror_r */
-#endif /* not _LIBC */
-
-#if !_LIBC
-/* Return non-zero if FD is open. */
-static int
-is_open (int fd)
-{
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- /* On native Windows: The initial state of unassigned standard file
- descriptors is that they are open but point to an INVALID_HANDLE_VALUE.
- There is no fcntl, and the gnulib replacement fcntl does not support
- F_GETFL. */
- return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
-# else
-# ifndef F_GETFL
-# error Please port fcntl to your platform
-# endif
- return 0 <= fcntl (fd, F_GETFL);
-# endif
-}
-#endif
-
-static void
-flush_stdout (void)
-{
-#if !_LIBC
- int stdout_fd;
-
-# if GNULIB_FREOPEN_SAFER
- /* Use of gnulib's freopen-safer module normally ensures that
- fileno (stdout) == 1
- whenever stdout is open. */
- stdout_fd = STDOUT_FILENO;
-# else
- /* POSIX states that fileno (stdout) after fclose is unspecified. But in
- practice it is not a problem, because stdout is statically allocated and
- the fd of a FILE stream is stored as a field in its allocated memory. */
- stdout_fd = fileno (stdout);
-# endif
- /* POSIX states that fflush (stdout) after fclose is unspecified; it
- is safe in glibc, but not on all other platforms. fflush (NULL)
- is always defined, but too draconian. */
-#if !defined(_WIN32) && !defined(_WIN64)
- if (0 <= stdout_fd && is_open (stdout_fd))
-#endif
-#endif
- fflush (stdout);
-}
-
-static void
-print_errno_message (int errnum)
-{
- char const *s;
-
-#if defined HAVE_STRERROR_R || _LIBC
- char errbuf[1024];
-# if STRERROR_R_CHAR_P || _LIBC
- s = __strerror_r (errnum, errbuf, sizeof errbuf);
-# else
- if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
- s = errbuf;
- else
- s = 0;
-# endif
-#else
- s = strerror (errnum);
-#endif
-
-#if !_LIBC
- if (! s)
- s = _("Unknown system error");
-#endif
-
-#if _LIBC
- __fxprintf (NULL, ": %s", s);
-#else
- fprintf (stderr, ": %s", s);
-#endif
-}
-
-static void
-error_tail (int status, int errnum, const char *message, va_list args)
-{
-#if _LIBC
- if (_IO_fwide (stderr, 0) > 0)
- {
-# define ALLOCA_LIMIT 2000
- size_t len = strlen (message) + 1;
- wchar_t *wmessage = NULL;
- mbstate_t st;
- size_t res;
- const char *tmp;
- bool use_malloc = false;
-
- while (1)
- {
- if (__libc_use_alloca (len * sizeof (wchar_t)))
- wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
- else
- {
- if (!use_malloc)
- wmessage = NULL;
-
- wchar_t *p = (wchar_t *) realloc (wmessage,
- len * sizeof (wchar_t));
- if (p == NULL)
- {
- free (wmessage);
- fputws_unlocked (L"out of memory\n", stderr);
- return;
- }
- wmessage = p;
- use_malloc = true;
- }
-
- memset (&st, '\0', sizeof (st));
- tmp = message;
-
- res = mbsrtowcs (wmessage, &tmp, len, &st);
- if (res != len)
- break;
-
- if (__builtin_expect (len >= SIZE_MAX / 2, 0))
- {
- /* This really should not happen if everything is fine. */
- res = (size_t) -1;
- break;
- }
-
- len *= 2;
- }
-
- if (res == (size_t) -1)
- {
- /* The string cannot be converted. */
- if (use_malloc)
- {
- free (wmessage);
- use_malloc = false;
- }
- wmessage = (wchar_t *) L"???";
- }
-
- __vfwprintf (stderr, wmessage, args);
-
- if (use_malloc)
- free (wmessage);
- }
- else
-#endif
- vfprintf (stderr, message, args);
- va_end (args);
-
- ++error_message_count;
- if (errnum)
- print_errno_message (errnum);
-#if _LIBC
- __fxprintf (NULL, "\n");
-#else
- putc ('\n', stderr);
-#endif
- fflush (stderr);
- if (status)
- exit (status);
-}
-
-
-/* Print the program name and error message MESSAGE, which is a printf-style
- format string with optional args.
- If ERRNUM is nonzero, print its corresponding system error message.
- Exit with status STATUS if it is nonzero. */
-void
-error (int status, int errnum, const char *message, ...)
-{
- va_list args;
-
-#if defined _LIBC && defined __libc_ptf_call
- /* We do not want this call to be cut short by a thread
- cancellation. Therefore disable cancellation for now. */
- int state = PTHREAD_CANCEL_ENABLE;
- __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
- 0);
-#endif
-
- flush_stdout ();
-#ifdef _LIBC
- _IO_flockfile (stderr);
-#endif
- if (error_print_progname)
- (*error_print_progname) ();
- else
- {
-#if _LIBC
- __fxprintf (NULL, "%s: ", program_name);
-#else
- fprintf (stderr, "%s: ", program_name);
-#endif
- }
-
- va_start (args, message);
- error_tail (status, errnum, message, args);
-
-#ifdef _LIBC
- _IO_funlockfile (stderr);
-# ifdef __libc_ptf_call
- __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
-# endif
-#endif
-}
-
-/* Sometimes we want to have at most one error per line. This
- variable controls whether this mode is selected or not. */
-int error_one_per_line;
-
-void
-error_at_line (int status, int errnum, const char *file_name,
- unsigned int line_number, const char *message, ...)
-{
- va_list args;
-
- if (error_one_per_line)
- {
- static const char *old_file_name;
- static unsigned int old_line_number;
-
- if (old_line_number == line_number
- && (file_name == old_file_name
- || strcmp (old_file_name, file_name) == 0))
- /* Simply return and print nothing. */
- return;
-
- old_file_name = file_name;
- old_line_number = line_number;
- }
-
-#if defined _LIBC && defined __libc_ptf_call
- /* We do not want this call to be cut short by a thread
- cancellation. Therefore disable cancellation for now. */
- int state = PTHREAD_CANCEL_ENABLE;
- __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
- 0);
-#endif
-
- flush_stdout ();
-#ifdef _LIBC
- _IO_flockfile (stderr);
-#endif
- if (error_print_progname)
- (*error_print_progname) ();
- else
- {
-#if _LIBC
- __fxprintf (NULL, "%s:", program_name);
-#else
- fprintf (stderr, "%s:", program_name);
-#endif
- }
-
-#if _LIBC
- __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
- file_name, line_number);
-#else
- fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
- file_name, line_number);
-#endif
-
- va_start (args, message);
- error_tail (status, errnum, message, args);
-
-#ifdef _LIBC
- _IO_funlockfile (stderr);
-# ifdef __libc_ptf_call
- __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
-# endif
-#endif
-}
-
-#ifdef _LIBC
-/* Make the weak alias. */
-# undef error
-# undef error_at_line
-weak_alias (__error, error)
-weak_alias (__error_at_line, error_at_line)
-#endif
+/* Error handler for noninteractive utilities
+ Copyright (C) 1990-1998, 2000-2007, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
+
+#if !_LIBC
+# include <config.h>
+#endif
+
+#include "error.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if !_LIBC && ENABLE_NLS
+# include "gettext.h"
+# define _(msgid) gettext (msgid)
+#endif
+
+#ifdef _LIBC
+# include <libintl.h>
+# include <stdbool.h>
+# include <stdint.h>
+# include <wchar.h>
+# define mbsrtowcs __mbsrtowcs
+#endif
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+#ifndef _
+# define _(String) String
+#endif
+
+/* If NULL, error will flush stdout, then print on stderr the program
+ name, a colon and a space. Otherwise, error will call this
+ function without parameters instead. */
+void (*error_print_progname) (void);
+
+/* This variable is incremented each time 'error' is called. */
+unsigned int error_message_count;
+
+#ifdef _LIBC
+/* In the GNU C library, there is a predefined variable for this. */
+
+# define program_name program_invocation_name
+# include <errno.h>
+# include <limits.h>
+# include <libio/libioP.h>
+
+/* In GNU libc we want do not want to use the common name 'error' directly.
+ Instead make it a weak alias. */
+extern void __error (int status, int errnum, const char *message, ...)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+extern void __error_at_line (int status, int errnum, const char *file_name,
+ unsigned int line_number, const char *message,
+ ...)
+ __attribute__ ((__format__ (__printf__, 5, 6)));;
+# define error __error
+# define error_at_line __error_at_line
+
+# include <libio/iolibio.h>
+# define fflush(s) INTUSE(_IO_fflush) (s)
+# undef putc
+# define putc(c, fp) INTUSE(_IO_putc) (c, fp)
+
+# include <bits/libc-lock.h>
+
+#else /* not _LIBC */
+
+# include <fcntl.h>
+# include <unistd.h>
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Get declarations of the native Windows API functions. */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+/* Get _get_osfhandle. */
+# include "msvc-nothrow.h"
+# endif
+
+/* The gnulib override of fcntl is not needed in this file. */
+# undef fcntl
+
+# if !HAVE_DECL_STRERROR_R
+# ifndef HAVE_DECL_STRERROR_R
+"this configure-time declaration test was not run"
+# endif
+# if STRERROR_R_CHAR_P
+char *strerror_r ();
+# else
+int strerror_r ();
+# endif
+# endif
+
+/* The calling program should define program_name and set it to the
+ name of the executing program. */
+extern char *program_name;
+
+# if HAVE_STRERROR_R || defined strerror_r
+# define __strerror_r strerror_r
+# endif /* HAVE_STRERROR_R || defined strerror_r */
+#endif /* not _LIBC */
+
+#if !_LIBC
+/* Return non-zero if FD is open. */
+static int
+is_open (int fd)
+{
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ /* On native Windows: The initial state of unassigned standard file
+ descriptors is that they are open but point to an INVALID_HANDLE_VALUE.
+ There is no fcntl, and the gnulib replacement fcntl does not support
+ F_GETFL. */
+ return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
+# else
+# ifndef F_GETFL
+# error Please port fcntl to your platform
+# endif
+ return 0 <= fcntl (fd, F_GETFL);
+# endif
+}
+#endif
+
+static void
+flush_stdout (void)
+{
+#if !_LIBC
+ int stdout_fd;
+
+# if GNULIB_FREOPEN_SAFER
+ /* Use of gnulib's freopen-safer module normally ensures that
+ fileno (stdout) == 1
+ whenever stdout is open. */
+ stdout_fd = STDOUT_FILENO;
+# else
+ /* POSIX states that fileno (stdout) after fclose is unspecified. But in
+ practice it is not a problem, because stdout is statically allocated and
+ the fd of a FILE stream is stored as a field in its allocated memory. */
+ stdout_fd = fileno (stdout);
+# endif
+ /* POSIX states that fflush (stdout) after fclose is unspecified; it
+ is safe in glibc, but not on all other platforms. fflush (NULL)
+ is always defined, but too draconian. */
+#if !defined(_WIN32) && !defined(_WIN64)
+ if (0 <= stdout_fd && is_open (stdout_fd))
+#endif
+#endif
+ fflush (stdout);
+}
+
+static void
+print_errno_message (int errnum)
+{
+ char const *s;
+
+#if defined HAVE_STRERROR_R || _LIBC
+ char errbuf[1024];
+# if STRERROR_R_CHAR_P || _LIBC
+ s = __strerror_r (errnum, errbuf, sizeof errbuf);
+# else
+ if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
+ s = errbuf;
+ else
+ s = 0;
+# endif
+#else
+ s = strerror (errnum);
+#endif
+
+#if !_LIBC
+ if (! s)
+ s = _("Unknown system error");
+#endif
+
+#if _LIBC
+ __fxprintf (NULL, ": %s", s);
+#else
+ fprintf (stderr, ": %s", s);
+#endif
+}
+
+static void
+error_tail (int status, int errnum, const char *message, va_list args)
+{
+#if _LIBC
+ if (_IO_fwide (stderr, 0) > 0)
+ {
+# define ALLOCA_LIMIT 2000
+ size_t len = strlen (message) + 1;
+ wchar_t *wmessage = NULL;
+ mbstate_t st;
+ size_t res;
+ const char *tmp;
+ bool use_malloc = false;
+
+ while (1)
+ {
+ if (__libc_use_alloca (len * sizeof (wchar_t)))
+ wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
+ else
+ {
+ if (!use_malloc)
+ wmessage = NULL;
+
+ wchar_t *p = (wchar_t *) realloc (wmessage,
+ len * sizeof (wchar_t));
+ if (p == NULL)
+ {
+ free (wmessage);
+ fputws_unlocked (L"out of memory\n", stderr);
+ return;
+ }
+ wmessage = p;
+ use_malloc = true;
+ }
+
+ memset (&st, '\0', sizeof (st));
+ tmp = message;
+
+ res = mbsrtowcs (wmessage, &tmp, len, &st);
+ if (res != len)
+ break;
+
+ if (__builtin_expect (len >= SIZE_MAX / 2, 0))
+ {
+ /* This really should not happen if everything is fine. */
+ res = (size_t) -1;
+ break;
+ }
+
+ len *= 2;
+ }
+
+ if (res == (size_t) -1)
+ {
+ /* The string cannot be converted. */
+ if (use_malloc)
+ {
+ free (wmessage);
+ use_malloc = false;
+ }
+ wmessage = (wchar_t *) L"???";
+ }
+
+ __vfwprintf (stderr, wmessage, args);
+
+ if (use_malloc)
+ free (wmessage);
+ }
+ else
+#endif
+ vfprintf (stderr, message, args);
+ va_end (args);
+
+ ++error_message_count;
+ if (errnum)
+ print_errno_message (errnum);
+#if _LIBC
+ __fxprintf (NULL, "\n");
+#else
+ putc ('\n', stderr);
+#endif
+ fflush (stderr);
+ if (status)
+ exit (status);
+}
+
+
+/* Print the program name and error message MESSAGE, which is a printf-style
+ format string with optional args.
+ If ERRNUM is nonzero, print its corresponding system error message.
+ Exit with status STATUS if it is nonzero. */
+void
+error (int status, int errnum, const char *message, ...)
+{
+ va_list args;
+
+#if defined _LIBC && defined __libc_ptf_call
+ /* We do not want this call to be cut short by a thread
+ cancellation. Therefore disable cancellation for now. */
+ int state = PTHREAD_CANCEL_ENABLE;
+ __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
+ 0);
+#endif
+
+ flush_stdout ();
+#ifdef _LIBC
+ _IO_flockfile (stderr);
+#endif
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ {
+#if _LIBC
+ __fxprintf (NULL, "%s: ", program_name);
+#else
+ fprintf (stderr, "%s: ", program_name);
+#endif
+ }
+
+ va_start (args, message);
+ error_tail (status, errnum, message, args);
+
+#ifdef _LIBC
+ _IO_funlockfile (stderr);
+# ifdef __libc_ptf_call
+ __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
+# endif
+#endif
+}
+
+/* Sometimes we want to have at most one error per line. This
+ variable controls whether this mode is selected or not. */
+int error_one_per_line;
+
+void
+error_at_line (int status, int errnum, const char *file_name,
+ unsigned int line_number, const char *message, ...)
+{
+ va_list args;
+
+ if (error_one_per_line)
+ {
+ static const char *old_file_name;
+ static unsigned int old_line_number;
+
+ if (old_line_number == line_number
+ && (file_name == old_file_name
+ || strcmp (old_file_name, file_name) == 0))
+ /* Simply return and print nothing. */
+ return;
+
+ old_file_name = file_name;
+ old_line_number = line_number;
+ }
+
+#if defined _LIBC && defined __libc_ptf_call
+ /* We do not want this call to be cut short by a thread
+ cancellation. Therefore disable cancellation for now. */
+ int state = PTHREAD_CANCEL_ENABLE;
+ __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
+ 0);
+#endif
+
+ flush_stdout ();
+#ifdef _LIBC
+ _IO_flockfile (stderr);
+#endif
+ if (error_print_progname)
+ (*error_print_progname) ();
+ else
+ {
+#if _LIBC
+ __fxprintf (NULL, "%s:", program_name);
+#else
+ fprintf (stderr, "%s:", program_name);
+#endif
+ }
+
+#if _LIBC
+ __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
+ file_name, line_number);
+#else
+ fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
+ file_name, line_number);
+#endif
+
+ va_start (args, message);
+ error_tail (status, errnum, message, args);
+
+#ifdef _LIBC
+ _IO_funlockfile (stderr);
+# ifdef __libc_ptf_call
+ __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
+# endif
+#endif
+}
+
+#ifdef _LIBC
+/* Make the weak alias. */
+# undef error
+# undef error_at_line
+weak_alias (__error, error)
+weak_alias (__error_at_line, error_at_line)
+#endif
diff --git a/contrib/tools/bison/gnulib/src/error.h b/contrib/tools/bison/gnulib/src/error.h
index afcb0e10c8..303561736f 100644
--- a/contrib/tools/bison/gnulib/src/error.h
+++ b/contrib/tools/bison/gnulib/src/error.h
@@ -1,65 +1,65 @@
-/* Declaration for error-reporting function
- Copyright (C) 1995-1997, 2003, 2006, 2008-2013 Free Software Foundation,
- Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _ERROR_H
-#define _ERROR_H 1
-
-/* The __attribute__ feature is available in gcc versions 2.5 and later.
- The __-protected variants of the attributes 'format' and 'printf' are
- accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
- gnulib and libintl do '#define printf __printf__' when they override
- the 'printf' function. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
-#else
-# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Print a message with 'fprintf (stderr, FORMAT, ...)';
- if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
- If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */
-
-extern void error (int __status, int __errnum, const char *__format, ...)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
-
-extern void error_at_line (int __status, int __errnum, const char *__fname,
- unsigned int __lineno, const char *__format, ...)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 6));
-
-/* If NULL, error will flush stdout, then print on stderr the program
- name, a colon and a space. Otherwise, error will call this
- function without parameters instead. */
-extern void (*error_print_progname) (void);
-
-/* This variable is incremented each time 'error' is called. */
-extern unsigned int error_message_count;
-
-/* Sometimes we want to have at most one error per line. This
- variable controls whether this mode is selected or not. */
-extern int error_one_per_line;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* error.h */
+/* Declaration for error-reporting function
+ Copyright (C) 1995-1997, 2003, 2006, 2008-2013 Free Software Foundation,
+ Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _ERROR_H
+#define _ERROR_H 1
+
+/* The __attribute__ feature is available in gcc versions 2.5 and later.
+ The __-protected variants of the attributes 'format' and 'printf' are
+ accepted by gcc versions 2.6.4 (effectively 2.7) and later.
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
+ gnulib and libintl do '#define printf __printf__' when they override
+ the 'printf' function. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+#else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Print a message with 'fprintf (stderr, FORMAT, ...)';
+ if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+ If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */
+
+extern void error (int __status, int __errnum, const char *__format, ...)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
+
+extern void error_at_line (int __status, int __errnum, const char *__fname,
+ unsigned int __lineno, const char *__format, ...)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 6));
+
+/* If NULL, error will flush stdout, then print on stderr the program
+ name, a colon and a space. Otherwise, error will call this
+ function without parameters instead. */
+extern void (*error_print_progname) (void);
+
+/* This variable is incremented each time 'error' is called. */
+extern unsigned int error_message_count;
+
+/* Sometimes we want to have at most one error per line. This
+ variable controls whether this mode is selected or not. */
+extern int error_one_per_line;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* error.h */
diff --git a/contrib/tools/bison/gnulib/src/execute.c b/contrib/tools/bison/gnulib/src/execute.c
index 1bb577100e..892c1a6db5 100644
--- a/contrib/tools/bison/gnulib/src/execute.c
+++ b/contrib/tools/bison/gnulib/src/execute.c
@@ -1,279 +1,279 @@
-/* Creation of autonomous subprocesses.
- Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#include <config.h>
-
-/* Specification. */
-#include "execute.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
-
+/* Creation of autonomous subprocesses.
+ Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include <config.h>
+
+/* Specification. */
+#include "execute.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
#include "penviron.h"
-#include "error.h"
-#include "fatal-signal.h"
-#include "wait-process.h"
-#include "gettext.h"
-
-#define _(str) gettext (str)
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* Native Windows API. */
-# include <process.h>
-# include "w32spawn.h"
-
-#else
-
-/* Unix API. */
-# include <spawn.h>
-
-#endif
-
-/* The results of open() in this file are not used with fchdir,
- therefore save some unnecessary work in fchdir.c. */
-#undef open
-#undef close
-
-
-#if defined EINTR && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
-
-/* EINTR handling for close(), open().
- These functions can return -1/EINTR even though we don't have any
- signal handlers set up, namely when we get interrupted via SIGSTOP. */
-
-static int
-nonintr_close (int fd)
-{
- int retval;
-
- do
- retval = close (fd);
- while (retval < 0 && errno == EINTR);
-
- return retval;
-}
-#define close nonintr_close
-
-static int
-nonintr_open (const char *pathname, int oflag, mode_t mode)
-{
- int retval;
-
- do
- retval = open (pathname, oflag, mode);
- while (retval < 0 && errno == EINTR);
-
- return retval;
-}
-#undef open /* avoid warning on VMS */
-#define open nonintr_open
-
-#endif
-
-
-/* Execute a command, optionally redirecting any of the three standard file
- descriptors to /dev/null. Return its exit code.
- If it didn't terminate correctly, exit if exit_on_error is true, otherwise
- return 127.
- If slave_process is true, the child process will be terminated when its
- creator receives a catchable fatal signal. */
-int
-execute (const char *progname,
- const char *prog_path, char **prog_argv,
- bool ignore_sigpipe,
- bool null_stdin, bool null_stdout, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int *termsigp)
-{
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
- /* Native Windows API. */
- int orig_stdin;
- int orig_stdout;
- int orig_stderr;
- int exitcode;
- int nullinfd;
- int nulloutfd;
-
- /* FIXME: Need to free memory allocated by prepare_spawn. */
- prog_argv = prepare_spawn (prog_argv);
-
- /* Save standard file handles of parent process. */
- if (null_stdin)
- orig_stdin = dup_safer_noinherit (STDIN_FILENO);
- if (null_stdout)
- orig_stdout = dup_safer_noinherit (STDOUT_FILENO);
- if (null_stderr)
- orig_stderr = dup_safer_noinherit (STDERR_FILENO);
- exitcode = -1;
-
- /* Create standard file handles of child process. */
- nullinfd = -1;
- nulloutfd = -1;
- if ((!null_stdin
- || ((nullinfd = open ("NUL", O_RDONLY, 0)) >= 0
- && (nullinfd == STDIN_FILENO
- || (dup2 (nullinfd, STDIN_FILENO) >= 0
- && close (nullinfd) >= 0))))
- && (!(null_stdout || null_stderr)
- || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
- && (!null_stdout
- || nulloutfd == STDOUT_FILENO
- || dup2 (nulloutfd, STDOUT_FILENO) >= 0)
- && (!null_stderr
- || nulloutfd == STDERR_FILENO
- || dup2 (nulloutfd, STDERR_FILENO) >= 0)
- && ((null_stdout && nulloutfd == STDOUT_FILENO)
- || (null_stderr && nulloutfd == STDERR_FILENO)
- || close (nulloutfd) >= 0))))
- /* Use spawnvpe and pass the environment explicitly. This is needed if
- the program has modified the environment using putenv() or [un]setenv().
- On Windows, programs have two environments, one in the "environment
- block" of the process and managed through SetEnvironmentVariable(), and
- one inside the process, in the location retrieved by the 'environ'
- macro. When using spawnvp() without 'e', the child process inherits a
- copy of the environment block - ignoring the effects of putenv() and
- [un]setenv(). */
- {
- exitcode = spawnvpe (P_WAIT, prog_path, (const char **) prog_argv,
- (const char **) environ);
- if (exitcode < 0 && errno == ENOEXEC)
- {
- /* prog is not a native executable. Try to execute it as a
- shell script. Note that prepare_spawn() has already prepended
- a hidden element "sh.exe" to prog_argv. */
- --prog_argv;
- exitcode = spawnvpe (P_WAIT, prog_argv[0], (const char **) prog_argv,
- (const char **) environ);
- }
- }
- if (nulloutfd >= 0)
- close (nulloutfd);
- if (nullinfd >= 0)
- close (nullinfd);
-
- /* Restore standard file handles of parent process. */
- if (null_stderr)
- undup_safer_noinherit (orig_stderr, STDERR_FILENO);
- if (null_stdout)
- undup_safer_noinherit (orig_stdout, STDOUT_FILENO);
- if (null_stdin)
- undup_safer_noinherit (orig_stdin, STDIN_FILENO);
-
- if (termsigp != NULL)
- *termsigp = 0;
-
- if (exitcode == -1)
- {
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, errno,
- _("%s subprocess failed"), progname);
- return 127;
- }
-
- return exitcode;
-
-#else
-
- /* Unix API. */
- /* Note about 127: Some errors during posix_spawnp() cause the function
- posix_spawnp() to return an error code; some other errors cause the
- subprocess to exit with return code 127. It is implementation
- dependent which error is reported which way. We treat both cases as
- equivalent. */
- sigset_t blocked_signals;
- posix_spawn_file_actions_t actions;
- bool actions_allocated;
- posix_spawnattr_t attrs;
- bool attrs_allocated;
- int err;
- pid_t child;
-
- if (slave_process)
- {
- sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
- block_fatal_signals ();
- }
- actions_allocated = false;
- attrs_allocated = false;
- if ((err = posix_spawn_file_actions_init (&actions)) != 0
- || (actions_allocated = true,
- (null_stdin
- && (err = posix_spawn_file_actions_addopen (&actions,
- STDIN_FILENO,
- "/dev/null", O_RDONLY,
- 0))
- != 0)
- || (null_stdout
- && (err = posix_spawn_file_actions_addopen (&actions,
- STDOUT_FILENO,
- "/dev/null", O_RDWR,
- 0))
- != 0)
- || (null_stderr
- && (err = posix_spawn_file_actions_addopen (&actions,
- STDERR_FILENO,
- "/dev/null", O_RDWR,
- 0))
- != 0)
- || (slave_process
- && ((err = posix_spawnattr_init (&attrs)) != 0
- || (attrs_allocated = true,
- (err = posix_spawnattr_setsigmask (&attrs,
- &blocked_signals))
- != 0
- || (err = posix_spawnattr_setflags (&attrs,
- POSIX_SPAWN_SETSIGMASK))
- != 0)))
- || (err = posix_spawnp (&child, prog_path, &actions,
- attrs_allocated ? &attrs : NULL, prog_argv,
- environ))
- != 0))
- {
- if (actions_allocated)
- posix_spawn_file_actions_destroy (&actions);
- if (attrs_allocated)
- posix_spawnattr_destroy (&attrs);
- if (slave_process)
- unblock_fatal_signals ();
- if (termsigp != NULL)
- *termsigp = 0;
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, err,
- _("%s subprocess failed"), progname);
- return 127;
- }
- posix_spawn_file_actions_destroy (&actions);
- if (attrs_allocated)
- posix_spawnattr_destroy (&attrs);
- if (slave_process)
- {
- register_slave_subprocess (child);
- unblock_fatal_signals ();
- }
-
- return wait_subprocess (child, progname, ignore_sigpipe, null_stderr,
- slave_process, exit_on_error, termsigp);
-
-#endif
-}
+#include "error.h"
+#include "fatal-signal.h"
+#include "wait-process.h"
+#include "gettext.h"
+
+#define _(str) gettext (str)
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Native Windows API. */
+# include <process.h>
+# include "w32spawn.h"
+
+#else
+
+/* Unix API. */
+# include <spawn.h>
+
+#endif
+
+/* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+#undef open
+#undef close
+
+
+#if defined EINTR && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+
+/* EINTR handling for close(), open().
+ These functions can return -1/EINTR even though we don't have any
+ signal handlers set up, namely when we get interrupted via SIGSTOP. */
+
+static int
+nonintr_close (int fd)
+{
+ int retval;
+
+ do
+ retval = close (fd);
+ while (retval < 0 && errno == EINTR);
+
+ return retval;
+}
+#define close nonintr_close
+
+static int
+nonintr_open (const char *pathname, int oflag, mode_t mode)
+{
+ int retval;
+
+ do
+ retval = open (pathname, oflag, mode);
+ while (retval < 0 && errno == EINTR);
+
+ return retval;
+}
+#undef open /* avoid warning on VMS */
+#define open nonintr_open
+
+#endif
+
+
+/* Execute a command, optionally redirecting any of the three standard file
+ descriptors to /dev/null. Return its exit code.
+ If it didn't terminate correctly, exit if exit_on_error is true, otherwise
+ return 127.
+ If slave_process is true, the child process will be terminated when its
+ creator receives a catchable fatal signal. */
+int
+execute (const char *progname,
+ const char *prog_path, char **prog_argv,
+ bool ignore_sigpipe,
+ bool null_stdin, bool null_stdout, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int *termsigp)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+ /* Native Windows API. */
+ int orig_stdin;
+ int orig_stdout;
+ int orig_stderr;
+ int exitcode;
+ int nullinfd;
+ int nulloutfd;
+
+ /* FIXME: Need to free memory allocated by prepare_spawn. */
+ prog_argv = prepare_spawn (prog_argv);
+
+ /* Save standard file handles of parent process. */
+ if (null_stdin)
+ orig_stdin = dup_safer_noinherit (STDIN_FILENO);
+ if (null_stdout)
+ orig_stdout = dup_safer_noinherit (STDOUT_FILENO);
+ if (null_stderr)
+ orig_stderr = dup_safer_noinherit (STDERR_FILENO);
+ exitcode = -1;
+
+ /* Create standard file handles of child process. */
+ nullinfd = -1;
+ nulloutfd = -1;
+ if ((!null_stdin
+ || ((nullinfd = open ("NUL", O_RDONLY, 0)) >= 0
+ && (nullinfd == STDIN_FILENO
+ || (dup2 (nullinfd, STDIN_FILENO) >= 0
+ && close (nullinfd) >= 0))))
+ && (!(null_stdout || null_stderr)
+ || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
+ && (!null_stdout
+ || nulloutfd == STDOUT_FILENO
+ || dup2 (nulloutfd, STDOUT_FILENO) >= 0)
+ && (!null_stderr
+ || nulloutfd == STDERR_FILENO
+ || dup2 (nulloutfd, STDERR_FILENO) >= 0)
+ && ((null_stdout && nulloutfd == STDOUT_FILENO)
+ || (null_stderr && nulloutfd == STDERR_FILENO)
+ || close (nulloutfd) >= 0))))
+ /* Use spawnvpe and pass the environment explicitly. This is needed if
+ the program has modified the environment using putenv() or [un]setenv().
+ On Windows, programs have two environments, one in the "environment
+ block" of the process and managed through SetEnvironmentVariable(), and
+ one inside the process, in the location retrieved by the 'environ'
+ macro. When using spawnvp() without 'e', the child process inherits a
+ copy of the environment block - ignoring the effects of putenv() and
+ [un]setenv(). */
+ {
+ exitcode = spawnvpe (P_WAIT, prog_path, (const char **) prog_argv,
+ (const char **) environ);
+ if (exitcode < 0 && errno == ENOEXEC)
+ {
+ /* prog is not a native executable. Try to execute it as a
+ shell script. Note that prepare_spawn() has already prepended
+ a hidden element "sh.exe" to prog_argv. */
+ --prog_argv;
+ exitcode = spawnvpe (P_WAIT, prog_argv[0], (const char **) prog_argv,
+ (const char **) environ);
+ }
+ }
+ if (nulloutfd >= 0)
+ close (nulloutfd);
+ if (nullinfd >= 0)
+ close (nullinfd);
+
+ /* Restore standard file handles of parent process. */
+ if (null_stderr)
+ undup_safer_noinherit (orig_stderr, STDERR_FILENO);
+ if (null_stdout)
+ undup_safer_noinherit (orig_stdout, STDOUT_FILENO);
+ if (null_stdin)
+ undup_safer_noinherit (orig_stdin, STDIN_FILENO);
+
+ if (termsigp != NULL)
+ *termsigp = 0;
+
+ if (exitcode == -1)
+ {
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, errno,
+ _("%s subprocess failed"), progname);
+ return 127;
+ }
+
+ return exitcode;
+
+#else
+
+ /* Unix API. */
+ /* Note about 127: Some errors during posix_spawnp() cause the function
+ posix_spawnp() to return an error code; some other errors cause the
+ subprocess to exit with return code 127. It is implementation
+ dependent which error is reported which way. We treat both cases as
+ equivalent. */
+ sigset_t blocked_signals;
+ posix_spawn_file_actions_t actions;
+ bool actions_allocated;
+ posix_spawnattr_t attrs;
+ bool attrs_allocated;
+ int err;
+ pid_t child;
+
+ if (slave_process)
+ {
+ sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
+ block_fatal_signals ();
+ }
+ actions_allocated = false;
+ attrs_allocated = false;
+ if ((err = posix_spawn_file_actions_init (&actions)) != 0
+ || (actions_allocated = true,
+ (null_stdin
+ && (err = posix_spawn_file_actions_addopen (&actions,
+ STDIN_FILENO,
+ "/dev/null", O_RDONLY,
+ 0))
+ != 0)
+ || (null_stdout
+ && (err = posix_spawn_file_actions_addopen (&actions,
+ STDOUT_FILENO,
+ "/dev/null", O_RDWR,
+ 0))
+ != 0)
+ || (null_stderr
+ && (err = posix_spawn_file_actions_addopen (&actions,
+ STDERR_FILENO,
+ "/dev/null", O_RDWR,
+ 0))
+ != 0)
+ || (slave_process
+ && ((err = posix_spawnattr_init (&attrs)) != 0
+ || (attrs_allocated = true,
+ (err = posix_spawnattr_setsigmask (&attrs,
+ &blocked_signals))
+ != 0
+ || (err = posix_spawnattr_setflags (&attrs,
+ POSIX_SPAWN_SETSIGMASK))
+ != 0)))
+ || (err = posix_spawnp (&child, prog_path, &actions,
+ attrs_allocated ? &attrs : NULL, prog_argv,
+ environ))
+ != 0))
+ {
+ if (actions_allocated)
+ posix_spawn_file_actions_destroy (&actions);
+ if (attrs_allocated)
+ posix_spawnattr_destroy (&attrs);
+ if (slave_process)
+ unblock_fatal_signals ();
+ if (termsigp != NULL)
+ *termsigp = 0;
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, err,
+ _("%s subprocess failed"), progname);
+ return 127;
+ }
+ posix_spawn_file_actions_destroy (&actions);
+ if (attrs_allocated)
+ posix_spawnattr_destroy (&attrs);
+ if (slave_process)
+ {
+ register_slave_subprocess (child);
+ unblock_fatal_signals ();
+ }
+
+ return wait_subprocess (child, progname, ignore_sigpipe, null_stderr,
+ slave_process, exit_on_error, termsigp);
+
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/execute.h b/contrib/tools/bison/gnulib/src/execute.h
index 1fdc2abbad..796b15cc70 100644
--- a/contrib/tools/bison/gnulib/src/execute.h
+++ b/contrib/tools/bison/gnulib/src/execute.h
@@ -1,44 +1,44 @@
-/* Creation of autonomous subprocesses.
- Copyright (C) 2001-2003, 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _EXECUTE_H
-#define _EXECUTE_H
-
-#include <stdbool.h>
-
-/* Execute a command, optionally redirecting any of the three standard file
- descriptors to /dev/null. Return its exit code.
- If it didn't terminate correctly, exit if exit_on_error is true, otherwise
- return 127.
- If ignore_sigpipe is true, consider a subprocess termination due to SIGPIPE
- as equivalent to a success. This is suitable for processes whose only
- purpose is to write to standard output.
- If slave_process is true, the child process will be terminated when its
- creator receives a catchable fatal signal.
- If termsigp is not NULL, *termsig will be set to the signal that terminated
- the subprocess (if supported by the platform: not on native Windows
- platforms), otherwise 0.
- It is recommended that no signal is blocked or ignored while execute()
- is called. See pipe.h for the reason. */
-extern int execute (const char *progname,
- const char *prog_path, char **prog_argv,
- bool ignore_sigpipe,
- bool null_stdin, bool null_stdout, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int *termsigp);
-
-#endif /* _EXECUTE_H */
+/* Creation of autonomous subprocesses.
+ Copyright (C) 2001-2003, 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _EXECUTE_H
+#define _EXECUTE_H
+
+#include <stdbool.h>
+
+/* Execute a command, optionally redirecting any of the three standard file
+ descriptors to /dev/null. Return its exit code.
+ If it didn't terminate correctly, exit if exit_on_error is true, otherwise
+ return 127.
+ If ignore_sigpipe is true, consider a subprocess termination due to SIGPIPE
+ as equivalent to a success. This is suitable for processes whose only
+ purpose is to write to standard output.
+ If slave_process is true, the child process will be terminated when its
+ creator receives a catchable fatal signal.
+ If termsigp is not NULL, *termsig will be set to the signal that terminated
+ the subprocess (if supported by the platform: not on native Windows
+ platforms), otherwise 0.
+ It is recommended that no signal is blocked or ignored while execute()
+ is called. See pipe.h for the reason. */
+extern int execute (const char *progname,
+ const char *prog_path, char **prog_argv,
+ bool ignore_sigpipe,
+ bool null_stdin, bool null_stdout, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int *termsigp);
+
+#endif /* _EXECUTE_H */
diff --git a/contrib/tools/bison/gnulib/src/exitfail.c b/contrib/tools/bison/gnulib/src/exitfail.c
index b0b4ebe45a..4a3940a99f 100644
--- a/contrib/tools/bison/gnulib/src/exitfail.c
+++ b/contrib/tools/bison/gnulib/src/exitfail.c
@@ -1,24 +1,24 @@
-/* Failure exit status
-
- Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "exitfail.h"
-
-#include <stdlib.h>
-
-int volatile exit_failure = EXIT_FAILURE;
+/* Failure exit status
+
+ Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "exitfail.h"
+
+#include <stdlib.h>
+
+int volatile exit_failure = EXIT_FAILURE;
diff --git a/contrib/tools/bison/gnulib/src/exitfail.h b/contrib/tools/bison/gnulib/src/exitfail.h
index e54333bdd2..6f211f6ec8 100644
--- a/contrib/tools/bison/gnulib/src/exitfail.h
+++ b/contrib/tools/bison/gnulib/src/exitfail.h
@@ -1,18 +1,18 @@
-/* Failure exit status
-
- Copyright (C) 2002, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-extern int volatile exit_failure;
+/* Failure exit status
+
+ Copyright (C) 2002, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+extern int volatile exit_failure;
diff --git a/contrib/tools/bison/gnulib/src/fatal-signal.c b/contrib/tools/bison/gnulib/src/fatal-signal.c
index 8f7cb8ea3b..a913d4d4a0 100644
--- a/contrib/tools/bison/gnulib/src/fatal-signal.c
+++ b/contrib/tools/bison/gnulib/src/fatal-signal.c
@@ -1,286 +1,286 @@
-/* Emergency actions in case of a fatal signal.
- Copyright (C) 2003-2004, 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2003.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#include <config.h>
-
-/* Specification. */
-#include "fatal-signal.h"
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
-
-#include "sig-handler.h"
-#include "xalloc.h"
-
-#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
-
-/* ========================================================================= */
-
-
-/* The list of fatal signals.
- These are those signals whose default action is to terminate the process
- without a core dump, except
- SIGKILL - because it cannot be caught,
- SIGALRM SIGUSR1 SIGUSR2 SIGPOLL SIGIO SIGLOST - because applications
- often use them for their own purpose,
- SIGPROF SIGVTALRM - because they are used for profiling,
- SIGSTKFLT - because it is more similar to SIGFPE, SIGSEGV, SIGBUS,
- SIGSYS - because it is more similar to SIGABRT, SIGSEGV,
- SIGPWR - because it of too special use,
- SIGRTMIN...SIGRTMAX - because they are reserved for application use.
- plus
- SIGXCPU, SIGXFSZ - because they are quite similar to SIGTERM. */
-
-static int fatal_signals[] =
- {
- /* ISO C 99 signals. */
-#ifdef SIGINT
- SIGINT,
-#endif
-#ifdef SIGTERM
- SIGTERM,
-#endif
- /* POSIX:2001 signals. */
-#ifdef SIGHUP
- SIGHUP,
-#endif
-#ifdef SIGPIPE
- SIGPIPE,
-#endif
- /* BSD signals. */
-#ifdef SIGXCPU
- SIGXCPU,
-#endif
-#ifdef SIGXFSZ
- SIGXFSZ,
-#endif
- /* Native Windows signals. */
-#ifdef SIGBREAK
- SIGBREAK,
-#endif
- 0
- };
-
-#define num_fatal_signals (SIZEOF (fatal_signals) - 1)
-
-/* Eliminate signals whose signal handler is SIG_IGN. */
-
-static void
-init_fatal_signals (void)
-{
- static bool fatal_signals_initialized = false;
- if (!fatal_signals_initialized)
- {
- size_t i;
-
- for (i = 0; i < num_fatal_signals; i++)
- {
- struct sigaction action;
-
- if (sigaction (fatal_signals[i], NULL, &action) >= 0
- && get_handler (&action) == SIG_IGN)
- fatal_signals[i] = -1;
- }
-
- fatal_signals_initialized = true;
- }
-}
-
-
-/* ========================================================================= */
-
-
-typedef void (*action_t) (void);
-
-/* Type of an entry in the actions array.
- The 'action' field is accessed from within the fatal_signal_handler(),
- therefore we mark it as 'volatile'. */
-typedef struct
-{
- volatile action_t action;
-}
-actions_entry_t;
-
-/* The registered cleanup actions. */
-static actions_entry_t static_actions[32];
-static actions_entry_t * volatile actions = static_actions;
-static sig_atomic_t volatile actions_count = 0;
-static size_t actions_allocated = SIZEOF (static_actions);
-
-
-/* The saved signal handlers.
- Size 32 would not be sufficient: On HP-UX, SIGXCPU = 33, SIGXFSZ = 34. */
-static struct sigaction saved_sigactions[64];
-
-
-/* Uninstall the handlers. */
-static void
-uninstall_handlers (void)
-{
- size_t i;
-
- for (i = 0; i < num_fatal_signals; i++)
- if (fatal_signals[i] >= 0)
- {
- int sig = fatal_signals[i];
- if (saved_sigactions[sig].sa_handler == SIG_IGN)
- saved_sigactions[sig].sa_handler = SIG_DFL;
- sigaction (sig, &saved_sigactions[sig], NULL);
- }
-}
-
-
-/* The signal handler. It gets called asynchronously. */
-static void
-fatal_signal_handler (int sig)
-{
- for (;;)
- {
- /* Get the last registered cleanup action, in a reentrant way. */
- action_t action;
- size_t n = actions_count;
- if (n == 0)
- break;
- n--;
- actions_count = n;
- action = actions[n].action;
- /* Execute the action. */
- action ();
- }
-
- /* Now execute the signal's default action.
- If the signal being delivered was blocked, the re-raised signal would be
- delivered when this handler returns. But the way we install this handler,
- no signal is blocked, and the re-raised signal is delivered already
- during raise(). */
- uninstall_handlers ();
- raise (sig);
-}
-
-
-/* Install the handlers. */
-static void
-install_handlers (void)
-{
- size_t i;
- struct sigaction action;
-
- action.sa_handler = &fatal_signal_handler;
- /* If we get a fatal signal while executing fatal_signal_handler, enter
- fatal_signal_handler recursively, since it is reentrant. Hence no
- SA_RESETHAND. */
- action.sa_flags = SA_NODEFER;
- sigemptyset (&action.sa_mask);
- for (i = 0; i < num_fatal_signals; i++)
- if (fatal_signals[i] >= 0)
- {
- int sig = fatal_signals[i];
-
- if (!(sig < sizeof (saved_sigactions) / sizeof (saved_sigactions[0])))
- abort ();
- sigaction (sig, &action, &saved_sigactions[sig]);
- }
-}
-
-
-/* Register a cleanup function to be executed when a catchable fatal signal
- occurs. */
-void
-at_fatal_signal (action_t action)
-{
- static bool cleanup_initialized = false;
- if (!cleanup_initialized)
- {
- init_fatal_signals ();
- install_handlers ();
- cleanup_initialized = true;
- }
-
- if (actions_count == actions_allocated)
- {
- /* Extend the actions array. Note that we cannot use xrealloc(),
- because then the cleanup() function could access an already
- deallocated array. */
- actions_entry_t *old_actions = actions;
- size_t old_actions_allocated = actions_allocated;
- size_t new_actions_allocated = 2 * actions_allocated;
- actions_entry_t *new_actions =
- XNMALLOC (new_actions_allocated, actions_entry_t);
- size_t k;
-
- /* Don't use memcpy() here, because memcpy takes non-volatile arguments
- and is therefore not guaranteed to complete all memory stores before
- the next statement. */
- for (k = 0; k < old_actions_allocated; k++)
- new_actions[k] = old_actions[k];
- actions = new_actions;
- actions_allocated = new_actions_allocated;
- /* Now we can free the old actions array. */
- if (old_actions != static_actions)
- free (old_actions);
- }
- /* The two uses of 'volatile' in the types above (and ISO C 99 section
- 5.1.2.3.(5)) ensure that we increment the actions_count only after
- the new action has been written to the memory location
- actions[actions_count]. */
- actions[actions_count].action = action;
- actions_count++;
-}
-
-
-/* ========================================================================= */
-
-
-static sigset_t fatal_signal_set;
-
-static void
-init_fatal_signal_set (void)
-{
- static bool fatal_signal_set_initialized = false;
- if (!fatal_signal_set_initialized)
- {
- size_t i;
-
- init_fatal_signals ();
-
- sigemptyset (&fatal_signal_set);
- for (i = 0; i < num_fatal_signals; i++)
- if (fatal_signals[i] >= 0)
- sigaddset (&fatal_signal_set, fatal_signals[i]);
-
- fatal_signal_set_initialized = true;
- }
-}
-
-/* Temporarily delay the catchable fatal signals. */
-void
-block_fatal_signals (void)
-{
- init_fatal_signal_set ();
- sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
-}
-
-/* Stop delaying the catchable fatal signals. */
-void
-unblock_fatal_signals (void)
-{
- init_fatal_signal_set ();
- sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
-}
+/* Emergency actions in case of a fatal signal.
+ Copyright (C) 2003-2004, 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include <config.h>
+
+/* Specification. */
+#include "fatal-signal.h"
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include "sig-handler.h"
+#include "xalloc.h"
+
+#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
+
+/* ========================================================================= */
+
+
+/* The list of fatal signals.
+ These are those signals whose default action is to terminate the process
+ without a core dump, except
+ SIGKILL - because it cannot be caught,
+ SIGALRM SIGUSR1 SIGUSR2 SIGPOLL SIGIO SIGLOST - because applications
+ often use them for their own purpose,
+ SIGPROF SIGVTALRM - because they are used for profiling,
+ SIGSTKFLT - because it is more similar to SIGFPE, SIGSEGV, SIGBUS,
+ SIGSYS - because it is more similar to SIGABRT, SIGSEGV,
+ SIGPWR - because it of too special use,
+ SIGRTMIN...SIGRTMAX - because they are reserved for application use.
+ plus
+ SIGXCPU, SIGXFSZ - because they are quite similar to SIGTERM. */
+
+static int fatal_signals[] =
+ {
+ /* ISO C 99 signals. */
+#ifdef SIGINT
+ SIGINT,
+#endif
+#ifdef SIGTERM
+ SIGTERM,
+#endif
+ /* POSIX:2001 signals. */
+#ifdef SIGHUP
+ SIGHUP,
+#endif
+#ifdef SIGPIPE
+ SIGPIPE,
+#endif
+ /* BSD signals. */
+#ifdef SIGXCPU
+ SIGXCPU,
+#endif
+#ifdef SIGXFSZ
+ SIGXFSZ,
+#endif
+ /* Native Windows signals. */
+#ifdef SIGBREAK
+ SIGBREAK,
+#endif
+ 0
+ };
+
+#define num_fatal_signals (SIZEOF (fatal_signals) - 1)
+
+/* Eliminate signals whose signal handler is SIG_IGN. */
+
+static void
+init_fatal_signals (void)
+{
+ static bool fatal_signals_initialized = false;
+ if (!fatal_signals_initialized)
+ {
+ size_t i;
+
+ for (i = 0; i < num_fatal_signals; i++)
+ {
+ struct sigaction action;
+
+ if (sigaction (fatal_signals[i], NULL, &action) >= 0
+ && get_handler (&action) == SIG_IGN)
+ fatal_signals[i] = -1;
+ }
+
+ fatal_signals_initialized = true;
+ }
+}
+
+
+/* ========================================================================= */
+
+
+typedef void (*action_t) (void);
+
+/* Type of an entry in the actions array.
+ The 'action' field is accessed from within the fatal_signal_handler(),
+ therefore we mark it as 'volatile'. */
+typedef struct
+{
+ volatile action_t action;
+}
+actions_entry_t;
+
+/* The registered cleanup actions. */
+static actions_entry_t static_actions[32];
+static actions_entry_t * volatile actions = static_actions;
+static sig_atomic_t volatile actions_count = 0;
+static size_t actions_allocated = SIZEOF (static_actions);
+
+
+/* The saved signal handlers.
+ Size 32 would not be sufficient: On HP-UX, SIGXCPU = 33, SIGXFSZ = 34. */
+static struct sigaction saved_sigactions[64];
+
+
+/* Uninstall the handlers. */
+static void
+uninstall_handlers (void)
+{
+ size_t i;
+
+ for (i = 0; i < num_fatal_signals; i++)
+ if (fatal_signals[i] >= 0)
+ {
+ int sig = fatal_signals[i];
+ if (saved_sigactions[sig].sa_handler == SIG_IGN)
+ saved_sigactions[sig].sa_handler = SIG_DFL;
+ sigaction (sig, &saved_sigactions[sig], NULL);
+ }
+}
+
+
+/* The signal handler. It gets called asynchronously. */
+static void
+fatal_signal_handler (int sig)
+{
+ for (;;)
+ {
+ /* Get the last registered cleanup action, in a reentrant way. */
+ action_t action;
+ size_t n = actions_count;
+ if (n == 0)
+ break;
+ n--;
+ actions_count = n;
+ action = actions[n].action;
+ /* Execute the action. */
+ action ();
+ }
+
+ /* Now execute the signal's default action.
+ If the signal being delivered was blocked, the re-raised signal would be
+ delivered when this handler returns. But the way we install this handler,
+ no signal is blocked, and the re-raised signal is delivered already
+ during raise(). */
+ uninstall_handlers ();
+ raise (sig);
+}
+
+
+/* Install the handlers. */
+static void
+install_handlers (void)
+{
+ size_t i;
+ struct sigaction action;
+
+ action.sa_handler = &fatal_signal_handler;
+ /* If we get a fatal signal while executing fatal_signal_handler, enter
+ fatal_signal_handler recursively, since it is reentrant. Hence no
+ SA_RESETHAND. */
+ action.sa_flags = SA_NODEFER;
+ sigemptyset (&action.sa_mask);
+ for (i = 0; i < num_fatal_signals; i++)
+ if (fatal_signals[i] >= 0)
+ {
+ int sig = fatal_signals[i];
+
+ if (!(sig < sizeof (saved_sigactions) / sizeof (saved_sigactions[0])))
+ abort ();
+ sigaction (sig, &action, &saved_sigactions[sig]);
+ }
+}
+
+
+/* Register a cleanup function to be executed when a catchable fatal signal
+ occurs. */
+void
+at_fatal_signal (action_t action)
+{
+ static bool cleanup_initialized = false;
+ if (!cleanup_initialized)
+ {
+ init_fatal_signals ();
+ install_handlers ();
+ cleanup_initialized = true;
+ }
+
+ if (actions_count == actions_allocated)
+ {
+ /* Extend the actions array. Note that we cannot use xrealloc(),
+ because then the cleanup() function could access an already
+ deallocated array. */
+ actions_entry_t *old_actions = actions;
+ size_t old_actions_allocated = actions_allocated;
+ size_t new_actions_allocated = 2 * actions_allocated;
+ actions_entry_t *new_actions =
+ XNMALLOC (new_actions_allocated, actions_entry_t);
+ size_t k;
+
+ /* Don't use memcpy() here, because memcpy takes non-volatile arguments
+ and is therefore not guaranteed to complete all memory stores before
+ the next statement. */
+ for (k = 0; k < old_actions_allocated; k++)
+ new_actions[k] = old_actions[k];
+ actions = new_actions;
+ actions_allocated = new_actions_allocated;
+ /* Now we can free the old actions array. */
+ if (old_actions != static_actions)
+ free (old_actions);
+ }
+ /* The two uses of 'volatile' in the types above (and ISO C 99 section
+ 5.1.2.3.(5)) ensure that we increment the actions_count only after
+ the new action has been written to the memory location
+ actions[actions_count]. */
+ actions[actions_count].action = action;
+ actions_count++;
+}
+
+
+/* ========================================================================= */
+
+
+static sigset_t fatal_signal_set;
+
+static void
+init_fatal_signal_set (void)
+{
+ static bool fatal_signal_set_initialized = false;
+ if (!fatal_signal_set_initialized)
+ {
+ size_t i;
+
+ init_fatal_signals ();
+
+ sigemptyset (&fatal_signal_set);
+ for (i = 0; i < num_fatal_signals; i++)
+ if (fatal_signals[i] >= 0)
+ sigaddset (&fatal_signal_set, fatal_signals[i]);
+
+ fatal_signal_set_initialized = true;
+ }
+}
+
+/* Temporarily delay the catchable fatal signals. */
+void
+block_fatal_signals (void)
+{
+ init_fatal_signal_set ();
+ sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
+}
+
+/* Stop delaying the catchable fatal signals. */
+void
+unblock_fatal_signals (void)
+{
+ init_fatal_signal_set ();
+ sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
+}
diff --git a/contrib/tools/bison/gnulib/src/fatal-signal.h b/contrib/tools/bison/gnulib/src/fatal-signal.h
index f5df78a048..75d9e98051 100644
--- a/contrib/tools/bison/gnulib/src/fatal-signal.h
+++ b/contrib/tools/bison/gnulib/src/fatal-signal.h
@@ -1,76 +1,76 @@
-/* Emergency actions in case of a fatal signal.
- Copyright (C) 2003-2004, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2003.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* It is often useful to do some cleanup action when a usually fatal signal
- terminates the process, like removing a temporary file or killing a
- subprocess that may be stuck waiting for a device, pipe or network input.
- Such signals are SIGHUP, SIGINT, SIGPIPE, SIGTERM, and possibly others.
- The limitation of this facility is that it cannot work for SIGKILL.
-
- Signals with a SIG_IGN handler are considered to be non-fatal. The
- functions in this file assume that when a SIG_IGN handler is installed
- for a signal, it was installed before any functions in this file were
- called and it stays so for the whole lifetime of the process. */
-
-/* Register a cleanup function to be executed when a catchable fatal signal
- occurs.
-
- Restrictions for the cleanup function:
- - The cleanup function can do all kinds of system calls.
- - It can also access application dependent memory locations and data
- structures provided they are in a consistent state. One way to ensure
- this is through block_fatal_signals()/unblock_fatal_signals(), see
- below. Another - more tricky - way to ensure this is the careful use
- of 'volatile'.
- However,
- - malloc() and similarly complex facilities are not safe to be called
- because they are not guaranteed to be in a consistent state.
- - Also, the cleanup function must not block the catchable fatal signals
- and leave them blocked upon return.
-
- The cleanup function is executed asynchronously. It is unspecified
- whether during its execution the catchable fatal signals are blocked
- or not. */
-extern void at_fatal_signal (void (*function) (void));
-
-
-/* Sometimes it is necessary to block the usually fatal signals while the
- data structures being accessed by the cleanup action are being built or
- reorganized. This is the case, for example, when a temporary file or
- directory is created through mkstemp() or mkdtemp(), because these
- functions create the temporary file or directory _before_ returning its
- name to the application. */
-
-/* Temporarily delay the catchable fatal signals.
- The signals will be blocked (= delayed) until the next call to
- unblock_fatal_signals(). If the signals are already blocked, a further
- call to block_fatal_signals() has no effect. */
-extern void block_fatal_signals (void);
-
-/* Stop delaying the catchable fatal signals. */
-extern void unblock_fatal_signals (void);
-
-
-#ifdef __cplusplus
-}
-#endif
+/* Emergency actions in case of a fatal signal.
+ Copyright (C) 2003-2004, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* It is often useful to do some cleanup action when a usually fatal signal
+ terminates the process, like removing a temporary file or killing a
+ subprocess that may be stuck waiting for a device, pipe or network input.
+ Such signals are SIGHUP, SIGINT, SIGPIPE, SIGTERM, and possibly others.
+ The limitation of this facility is that it cannot work for SIGKILL.
+
+ Signals with a SIG_IGN handler are considered to be non-fatal. The
+ functions in this file assume that when a SIG_IGN handler is installed
+ for a signal, it was installed before any functions in this file were
+ called and it stays so for the whole lifetime of the process. */
+
+/* Register a cleanup function to be executed when a catchable fatal signal
+ occurs.
+
+ Restrictions for the cleanup function:
+ - The cleanup function can do all kinds of system calls.
+ - It can also access application dependent memory locations and data
+ structures provided they are in a consistent state. One way to ensure
+ this is through block_fatal_signals()/unblock_fatal_signals(), see
+ below. Another - more tricky - way to ensure this is the careful use
+ of 'volatile'.
+ However,
+ - malloc() and similarly complex facilities are not safe to be called
+ because they are not guaranteed to be in a consistent state.
+ - Also, the cleanup function must not block the catchable fatal signals
+ and leave them blocked upon return.
+
+ The cleanup function is executed asynchronously. It is unspecified
+ whether during its execution the catchable fatal signals are blocked
+ or not. */
+extern void at_fatal_signal (void (*function) (void));
+
+
+/* Sometimes it is necessary to block the usually fatal signals while the
+ data structures being accessed by the cleanup action are being built or
+ reorganized. This is the case, for example, when a temporary file or
+ directory is created through mkstemp() or mkdtemp(), because these
+ functions create the temporary file or directory _before_ returning its
+ name to the application. */
+
+/* Temporarily delay the catchable fatal signals.
+ The signals will be blocked (= delayed) until the next call to
+ unblock_fatal_signals(). If the signals are already blocked, a further
+ call to block_fatal_signals() has no effect. */
+extern void block_fatal_signals (void);
+
+/* Stop delaying the catchable fatal signals. */
+extern void unblock_fatal_signals (void);
+
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/fclose.c b/contrib/tools/bison/gnulib/src/fclose.c
index 90ed653a0e..21c0685b71 100644
--- a/contrib/tools/bison/gnulib/src/fclose.c
+++ b/contrib/tools/bison/gnulib/src/fclose.c
@@ -1,110 +1,110 @@
-/* fclose replacement.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-#include <errno.h>
-#include <unistd.h>
-
-#include "freading.h"
-#include "msvc-inval.h"
-
-#undef fclose
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-fclose_nothrow (FILE *fp)
-{
- int result;
-
- TRY_MSVC_INVAL
- {
- result = fclose (fp);
- }
- CATCH_MSVC_INVAL
- {
- result = EOF;
- errno = EBADF;
- }
- DONE_MSVC_INVAL;
-
- return result;
-}
-#else
-# define fclose_nothrow fclose
-#endif
-
-/* Override fclose() to call the overridden fflush() or close(). */
-
-int
-rpl_fclose (FILE *fp)
-{
- int saved_errno = 0;
- int fd;
- int result = 0;
-
- /* Don't change behavior on memstreams. */
- fd = fileno (fp);
- if (fd < 0)
- return fclose_nothrow (fp);
-
- /* We only need to flush the file if it is not reading or if it is
- seekable. This only guarantees the file position of input files
- if the fflush module is also in use. */
- if ((!freading (fp) || lseek (fileno (fp), 0, SEEK_CUR) != -1)
- && fflush (fp))
- saved_errno = errno;
-
- /* fclose() calls close(), but we need to also invoke all hooks that our
- overridden close() function invokes. See lib/close.c. */
-#if WINDOWS_SOCKETS
- /* Call the overridden close(), then the original fclose().
- Note about multithread-safety: There is a race condition where some
- other thread could open fd between our close and fclose. */
- if (close (fd) < 0 && saved_errno == 0)
- saved_errno = errno;
-
- fclose_nothrow (fp); /* will fail with errno = EBADF,
- if we did not lose a race */
-
-#else /* !WINDOWS_SOCKETS */
- /* Call fclose() and invoke all hooks of the overridden close(). */
-
-# if REPLACE_FCHDIR
- /* Note about multithread-safety: There is a race condition here as well.
- Some other thread could open fd between our calls to fclose and
- _gl_unregister_fd. */
- result = fclose_nothrow (fp);
- if (result == 0)
- _gl_unregister_fd (fd);
-# else
- /* No race condition here. */
- result = fclose_nothrow (fp);
-# endif
-
-#endif /* !WINDOWS_SOCKETS */
-
- if (saved_errno != 0)
- {
- errno = saved_errno;
- result = EOF;
- }
-
- return result;
-}
+/* fclose replacement.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "freading.h"
+#include "msvc-inval.h"
+
+#undef fclose
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+fclose_nothrow (FILE *fp)
+{
+ int result;
+
+ TRY_MSVC_INVAL
+ {
+ result = fclose (fp);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = EOF;
+ errno = EBADF;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+#else
+# define fclose_nothrow fclose
+#endif
+
+/* Override fclose() to call the overridden fflush() or close(). */
+
+int
+rpl_fclose (FILE *fp)
+{
+ int saved_errno = 0;
+ int fd;
+ int result = 0;
+
+ /* Don't change behavior on memstreams. */
+ fd = fileno (fp);
+ if (fd < 0)
+ return fclose_nothrow (fp);
+
+ /* We only need to flush the file if it is not reading or if it is
+ seekable. This only guarantees the file position of input files
+ if the fflush module is also in use. */
+ if ((!freading (fp) || lseek (fileno (fp), 0, SEEK_CUR) != -1)
+ && fflush (fp))
+ saved_errno = errno;
+
+ /* fclose() calls close(), but we need to also invoke all hooks that our
+ overridden close() function invokes. See lib/close.c. */
+#if WINDOWS_SOCKETS
+ /* Call the overridden close(), then the original fclose().
+ Note about multithread-safety: There is a race condition where some
+ other thread could open fd between our close and fclose. */
+ if (close (fd) < 0 && saved_errno == 0)
+ saved_errno = errno;
+
+ fclose_nothrow (fp); /* will fail with errno = EBADF,
+ if we did not lose a race */
+
+#else /* !WINDOWS_SOCKETS */
+ /* Call fclose() and invoke all hooks of the overridden close(). */
+
+# if REPLACE_FCHDIR
+ /* Note about multithread-safety: There is a race condition here as well.
+ Some other thread could open fd between our calls to fclose and
+ _gl_unregister_fd. */
+ result = fclose_nothrow (fp);
+ if (result == 0)
+ _gl_unregister_fd (fd);
+# else
+ /* No race condition here. */
+ result = fclose_nothrow (fp);
+# endif
+
+#endif /* !WINDOWS_SOCKETS */
+
+ if (saved_errno != 0)
+ {
+ errno = saved_errno;
+ result = EOF;
+ }
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/fcntl.c b/contrib/tools/bison/gnulib/src/fcntl.c
index 735fa66f4d..5ee9911a31 100644
--- a/contrib/tools/bison/gnulib/src/fcntl.c
+++ b/contrib/tools/bison/gnulib/src/fcntl.c
@@ -1,311 +1,311 @@
-/* Provide file descriptor control.
-
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Eric Blake <ebb9@byu.net>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <fcntl.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <unistd.h>
-
-#if !HAVE_FCNTL
-# define rpl_fcntl fcntl
-#endif
-#undef fcntl
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Get declarations of the native Windows API functions. */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-
-/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
-
-/* Upper bound on getdtablesize(). See lib/getdtablesize.c. */
-# define OPEN_MAX_MAX 0x10000
-
-/* Duplicate OLDFD into the first available slot of at least NEWFD,
- which must be positive, with FLAGS determining whether the duplicate
- will be inheritable. */
-static int
-dupfd (int oldfd, int newfd, int flags)
-{
- /* Mingw has no way to create an arbitrary fd. Iterate until all
- file descriptors less than newfd are filled up. */
- HANDLE curr_process = GetCurrentProcess ();
- HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd);
- unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT];
- unsigned int fds_to_close_bound = 0;
- int result;
- BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE;
- int mode;
-
- if (newfd < 0 || getdtablesize () <= newfd)
- {
- errno = EINVAL;
- return -1;
- }
- if (old_handle == INVALID_HANDLE_VALUE
- || (mode = setmode (oldfd, O_BINARY)) == -1)
- {
- /* oldfd is not open, or is an unassigned standard file
- descriptor. */
- errno = EBADF;
- return -1;
- }
- setmode (oldfd, mode);
- flags |= mode;
-
- for (;;)
- {
- HANDLE new_handle;
- int duplicated_fd;
- unsigned int index;
-
- if (!DuplicateHandle (curr_process, /* SourceProcessHandle */
- old_handle, /* SourceHandle */
- curr_process, /* TargetProcessHandle */
- (PHANDLE) &new_handle, /* TargetHandle */
- (DWORD) 0, /* DesiredAccess */
- inherit, /* InheritHandle */
- DUPLICATE_SAME_ACCESS)) /* Options */
- {
- /* TODO: Translate GetLastError () into errno. */
- errno = EMFILE;
- result = -1;
- break;
- }
- duplicated_fd = _open_osfhandle ((intptr_t) new_handle, flags);
- if (duplicated_fd < 0)
- {
- CloseHandle (new_handle);
- errno = EMFILE;
- result = -1;
- break;
- }
- if (newfd <= duplicated_fd)
- {
- result = duplicated_fd;
- break;
- }
-
- /* Set the bit duplicated_fd in fds_to_close[]. */
- index = (unsigned int) duplicated_fd / CHAR_BIT;
- if (fds_to_close_bound <= index)
- {
- if (sizeof fds_to_close <= index)
- /* Need to increase OPEN_MAX_MAX. */
- abort ();
- memset (fds_to_close + fds_to_close_bound, '\0',
- index + 1 - fds_to_close_bound);
- fds_to_close_bound = index + 1;
- }
- fds_to_close[index] |= 1 << ((unsigned int) duplicated_fd % CHAR_BIT);
- }
-
- /* Close the previous fds that turned out to be too small. */
- {
- int saved_errno = errno;
- unsigned int duplicated_fd;
-
- for (duplicated_fd = 0;
- duplicated_fd < fds_to_close_bound * CHAR_BIT;
- duplicated_fd++)
- if ((fds_to_close[duplicated_fd / CHAR_BIT]
- >> (duplicated_fd % CHAR_BIT))
- & 1)
- close (duplicated_fd);
-
- errno = saved_errno;
- }
-
-# if REPLACE_FCHDIR
- if (0 <= result)
- result = _gl_register_dup (oldfd, result);
-# endif
- return result;
-}
-#endif /* W32 */
-
-/* Perform the specified ACTION on the file descriptor FD, possibly
- using the argument ARG further described below. This replacement
- handles the following actions, and forwards all others on to the
- native fcntl. An unrecognized ACTION returns -1 with errno set to
- EINVAL.
-
- F_DUPFD - duplicate FD, with int ARG being the minimum target fd.
- If successful, return the duplicate, which will be inheritable;
- otherwise return -1 and set errno.
-
- F_DUPFD_CLOEXEC - duplicate FD, with int ARG being the minimum
- target fd. If successful, return the duplicate, which will not be
- inheritable; otherwise return -1 and set errno.
-
- F_GETFD - ARG need not be present. If successful, return a
- non-negative value containing the descriptor flags of FD (only
- FD_CLOEXEC is portable, but other flags may be present); otherwise
- return -1 and set errno. */
-
-int
-rpl_fcntl (int fd, int action, /* arg */...)
-{
- va_list arg;
- int result = -1;
- va_start (arg, action);
- switch (action)
- {
-
-#if !HAVE_FCNTL
- case F_DUPFD:
- {
- int target = va_arg (arg, int);
- result = dupfd (fd, target, 0);
- break;
- }
-#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
- case F_DUPFD:
- {
- int target = va_arg (arg, int);
- /* Detect invalid target; needed for cygwin 1.5.x. */
- if (target < 0 || getdtablesize () <= target)
- errno = EINVAL;
- else
- {
- /* Haiku alpha 2 loses fd flags on original. */
- int flags = fcntl (fd, F_GETFD);
- if (flags < 0)
- {
- result = -1;
- break;
- }
- result = fcntl (fd, action, target);
- if (0 <= result && fcntl (fd, F_SETFD, flags) == -1)
- {
- int saved_errno = errno;
- close (result);
- result = -1;
- errno = saved_errno;
- }
-# if REPLACE_FCHDIR
- if (0 <= result)
- result = _gl_register_dup (fd, result);
-# endif
- }
- break;
- } /* F_DUPFD */
-#endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */
-
- case F_DUPFD_CLOEXEC:
- {
- int target = va_arg (arg, int);
-
-#if !HAVE_FCNTL
- result = dupfd (fd, target, O_CLOEXEC);
- break;
-#else /* HAVE_FCNTL */
- /* Try the system call first, if the headers claim it exists
- (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we
- may be running with a glibc that has the macro but with an
- older kernel that does not support it. Cache the
- information on whether the system call really works, but
- avoid caching failure if the corresponding F_DUPFD fails
- for any reason. 0 = unknown, 1 = yes, -1 = no. */
- static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0;
- if (0 <= have_dupfd_cloexec)
- {
- result = fcntl (fd, action, target);
- if (0 <= result || errno != EINVAL)
- {
- have_dupfd_cloexec = 1;
-# if REPLACE_FCHDIR
- if (0 <= result)
- result = _gl_register_dup (fd, result);
-# endif
- }
- else
- {
- result = rpl_fcntl (fd, F_DUPFD, target);
- if (result < 0)
- break;
- have_dupfd_cloexec = -1;
- }
- }
- else
- result = rpl_fcntl (fd, F_DUPFD, target);
- if (0 <= result && have_dupfd_cloexec == -1)
- {
- int flags = fcntl (result, F_GETFD);
- if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1)
- {
- int saved_errno = errno;
- close (result);
- errno = saved_errno;
- result = -1;
- }
- }
- break;
-#endif /* HAVE_FCNTL */
- } /* F_DUPFD_CLOEXEC */
-
-#if !HAVE_FCNTL
- case F_GETFD:
- {
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- HANDLE handle = (HANDLE) _get_osfhandle (fd);
- DWORD flags;
- if (handle == INVALID_HANDLE_VALUE
- || GetHandleInformation (handle, &flags) == 0)
- errno = EBADF;
- else
- result = (flags & HANDLE_FLAG_INHERIT) ? 0 : FD_CLOEXEC;
-# else /* !W32 */
- /* Use dup2 to reject invalid file descriptors. No way to
- access this information, so punt. */
- if (0 <= dup2 (fd, fd))
- result = 0;
-# endif /* !W32 */
- break;
- } /* F_GETFD */
-#endif /* !HAVE_FCNTL */
-
- /* Implementing F_SETFD on mingw is not trivial - there is no
- API for changing the O_NOINHERIT bit on an fd, and merely
- changing the HANDLE_FLAG_INHERIT bit on the underlying handle
- can lead to odd state. It may be possible by duplicating the
- handle, using _open_osfhandle with the right flags, then
- using dup2 to move the duplicate onto the original, but that
- is not supported for now. */
-
- default:
- {
-#if HAVE_FCNTL
- void *p = va_arg (arg, void *);
- result = fcntl (fd, action, p);
-#else
- errno = EINVAL;
-#endif
- break;
- }
- }
- va_end (arg);
- return result;
-}
+/* Provide file descriptor control.
+
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake <ebb9@byu.net>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <fcntl.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+#if !HAVE_FCNTL
+# define rpl_fcntl fcntl
+#endif
+#undef fcntl
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Get declarations of the native Windows API functions. */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+/* Get _get_osfhandle. */
+# include "msvc-nothrow.h"
+
+/* Upper bound on getdtablesize(). See lib/getdtablesize.c. */
+# define OPEN_MAX_MAX 0x10000
+
+/* Duplicate OLDFD into the first available slot of at least NEWFD,
+ which must be positive, with FLAGS determining whether the duplicate
+ will be inheritable. */
+static int
+dupfd (int oldfd, int newfd, int flags)
+{
+ /* Mingw has no way to create an arbitrary fd. Iterate until all
+ file descriptors less than newfd are filled up. */
+ HANDLE curr_process = GetCurrentProcess ();
+ HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd);
+ unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT];
+ unsigned int fds_to_close_bound = 0;
+ int result;
+ BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE;
+ int mode;
+
+ if (newfd < 0 || getdtablesize () <= newfd)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ if (old_handle == INVALID_HANDLE_VALUE
+ || (mode = setmode (oldfd, O_BINARY)) == -1)
+ {
+ /* oldfd is not open, or is an unassigned standard file
+ descriptor. */
+ errno = EBADF;
+ return -1;
+ }
+ setmode (oldfd, mode);
+ flags |= mode;
+
+ for (;;)
+ {
+ HANDLE new_handle;
+ int duplicated_fd;
+ unsigned int index;
+
+ if (!DuplicateHandle (curr_process, /* SourceProcessHandle */
+ old_handle, /* SourceHandle */
+ curr_process, /* TargetProcessHandle */
+ (PHANDLE) &new_handle, /* TargetHandle */
+ (DWORD) 0, /* DesiredAccess */
+ inherit, /* InheritHandle */
+ DUPLICATE_SAME_ACCESS)) /* Options */
+ {
+ /* TODO: Translate GetLastError () into errno. */
+ errno = EMFILE;
+ result = -1;
+ break;
+ }
+ duplicated_fd = _open_osfhandle ((intptr_t) new_handle, flags);
+ if (duplicated_fd < 0)
+ {
+ CloseHandle (new_handle);
+ errno = EMFILE;
+ result = -1;
+ break;
+ }
+ if (newfd <= duplicated_fd)
+ {
+ result = duplicated_fd;
+ break;
+ }
+
+ /* Set the bit duplicated_fd in fds_to_close[]. */
+ index = (unsigned int) duplicated_fd / CHAR_BIT;
+ if (fds_to_close_bound <= index)
+ {
+ if (sizeof fds_to_close <= index)
+ /* Need to increase OPEN_MAX_MAX. */
+ abort ();
+ memset (fds_to_close + fds_to_close_bound, '\0',
+ index + 1 - fds_to_close_bound);
+ fds_to_close_bound = index + 1;
+ }
+ fds_to_close[index] |= 1 << ((unsigned int) duplicated_fd % CHAR_BIT);
+ }
+
+ /* Close the previous fds that turned out to be too small. */
+ {
+ int saved_errno = errno;
+ unsigned int duplicated_fd;
+
+ for (duplicated_fd = 0;
+ duplicated_fd < fds_to_close_bound * CHAR_BIT;
+ duplicated_fd++)
+ if ((fds_to_close[duplicated_fd / CHAR_BIT]
+ >> (duplicated_fd % CHAR_BIT))
+ & 1)
+ close (duplicated_fd);
+
+ errno = saved_errno;
+ }
+
+# if REPLACE_FCHDIR
+ if (0 <= result)
+ result = _gl_register_dup (oldfd, result);
+# endif
+ return result;
+}
+#endif /* W32 */
+
+/* Perform the specified ACTION on the file descriptor FD, possibly
+ using the argument ARG further described below. This replacement
+ handles the following actions, and forwards all others on to the
+ native fcntl. An unrecognized ACTION returns -1 with errno set to
+ EINVAL.
+
+ F_DUPFD - duplicate FD, with int ARG being the minimum target fd.
+ If successful, return the duplicate, which will be inheritable;
+ otherwise return -1 and set errno.
+
+ F_DUPFD_CLOEXEC - duplicate FD, with int ARG being the minimum
+ target fd. If successful, return the duplicate, which will not be
+ inheritable; otherwise return -1 and set errno.
+
+ F_GETFD - ARG need not be present. If successful, return a
+ non-negative value containing the descriptor flags of FD (only
+ FD_CLOEXEC is portable, but other flags may be present); otherwise
+ return -1 and set errno. */
+
+int
+rpl_fcntl (int fd, int action, /* arg */...)
+{
+ va_list arg;
+ int result = -1;
+ va_start (arg, action);
+ switch (action)
+ {
+
+#if !HAVE_FCNTL
+ case F_DUPFD:
+ {
+ int target = va_arg (arg, int);
+ result = dupfd (fd, target, 0);
+ break;
+ }
+#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
+ case F_DUPFD:
+ {
+ int target = va_arg (arg, int);
+ /* Detect invalid target; needed for cygwin 1.5.x. */
+ if (target < 0 || getdtablesize () <= target)
+ errno = EINVAL;
+ else
+ {
+ /* Haiku alpha 2 loses fd flags on original. */
+ int flags = fcntl (fd, F_GETFD);
+ if (flags < 0)
+ {
+ result = -1;
+ break;
+ }
+ result = fcntl (fd, action, target);
+ if (0 <= result && fcntl (fd, F_SETFD, flags) == -1)
+ {
+ int saved_errno = errno;
+ close (result);
+ result = -1;
+ errno = saved_errno;
+ }
+# if REPLACE_FCHDIR
+ if (0 <= result)
+ result = _gl_register_dup (fd, result);
+# endif
+ }
+ break;
+ } /* F_DUPFD */
+#endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */
+
+ case F_DUPFD_CLOEXEC:
+ {
+ int target = va_arg (arg, int);
+
+#if !HAVE_FCNTL
+ result = dupfd (fd, target, O_CLOEXEC);
+ break;
+#else /* HAVE_FCNTL */
+ /* Try the system call first, if the headers claim it exists
+ (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we
+ may be running with a glibc that has the macro but with an
+ older kernel that does not support it. Cache the
+ information on whether the system call really works, but
+ avoid caching failure if the corresponding F_DUPFD fails
+ for any reason. 0 = unknown, 1 = yes, -1 = no. */
+ static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0;
+ if (0 <= have_dupfd_cloexec)
+ {
+ result = fcntl (fd, action, target);
+ if (0 <= result || errno != EINVAL)
+ {
+ have_dupfd_cloexec = 1;
+# if REPLACE_FCHDIR
+ if (0 <= result)
+ result = _gl_register_dup (fd, result);
+# endif
+ }
+ else
+ {
+ result = rpl_fcntl (fd, F_DUPFD, target);
+ if (result < 0)
+ break;
+ have_dupfd_cloexec = -1;
+ }
+ }
+ else
+ result = rpl_fcntl (fd, F_DUPFD, target);
+ if (0 <= result && have_dupfd_cloexec == -1)
+ {
+ int flags = fcntl (result, F_GETFD);
+ if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1)
+ {
+ int saved_errno = errno;
+ close (result);
+ errno = saved_errno;
+ result = -1;
+ }
+ }
+ break;
+#endif /* HAVE_FCNTL */
+ } /* F_DUPFD_CLOEXEC */
+
+#if !HAVE_FCNTL
+ case F_GETFD:
+ {
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ HANDLE handle = (HANDLE) _get_osfhandle (fd);
+ DWORD flags;
+ if (handle == INVALID_HANDLE_VALUE
+ || GetHandleInformation (handle, &flags) == 0)
+ errno = EBADF;
+ else
+ result = (flags & HANDLE_FLAG_INHERIT) ? 0 : FD_CLOEXEC;
+# else /* !W32 */
+ /* Use dup2 to reject invalid file descriptors. No way to
+ access this information, so punt. */
+ if (0 <= dup2 (fd, fd))
+ result = 0;
+# endif /* !W32 */
+ break;
+ } /* F_GETFD */
+#endif /* !HAVE_FCNTL */
+
+ /* Implementing F_SETFD on mingw is not trivial - there is no
+ API for changing the O_NOINHERIT bit on an fd, and merely
+ changing the HANDLE_FLAG_INHERIT bit on the underlying handle
+ can lead to odd state. It may be possible by duplicating the
+ handle, using _open_osfhandle with the right flags, then
+ using dup2 to move the duplicate onto the original, but that
+ is not supported for now. */
+
+ default:
+ {
+#if HAVE_FCNTL
+ void *p = va_arg (arg, void *);
+ result = fcntl (fd, action, p);
+#else
+ errno = EINVAL;
+#endif
+ break;
+ }
+ }
+ va_end (arg);
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/fd-hook.c b/contrib/tools/bison/gnulib/src/fd-hook.c
index e158a52aa3..f89107e993 100644
--- a/contrib/tools/bison/gnulib/src/fd-hook.c
+++ b/contrib/tools/bison/gnulib/src/fd-hook.c
@@ -1,116 +1,116 @@
-/* Hook for making making file descriptor functions close(), ioctl() extensible.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2009.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "fd-hook.h"
-
-#include <stdlib.h>
-
-/* Currently, this entire code is only needed for the handling of sockets
- on native Windows platforms. */
-#if WINDOWS_SOCKETS
-
-/* The first and last link in the doubly linked list.
- Initially the list is empty. */
-static struct fd_hook anchor = { &anchor, &anchor, NULL, NULL };
-
-int
-execute_close_hooks (const struct fd_hook *remaining_list, gl_close_fn primary,
- int fd)
-{
- if (remaining_list == &anchor)
- /* End of list reached. */
- return primary (fd);
- else
- return remaining_list->private_close_fn (remaining_list->private_next,
- primary, fd);
-}
-
-int
-execute_all_close_hooks (gl_close_fn primary, int fd)
-{
- return execute_close_hooks (anchor.private_next, primary, fd);
-}
-
-int
-execute_ioctl_hooks (const struct fd_hook *remaining_list, gl_ioctl_fn primary,
- int fd, int request, void *arg)
-{
- if (remaining_list == &anchor)
- /* End of list reached. */
- return primary (fd, request, arg);
- else
- return remaining_list->private_ioctl_fn (remaining_list->private_next,
- primary, fd, request, arg);
-}
-
-int
-execute_all_ioctl_hooks (gl_ioctl_fn primary,
- int fd, int request, void *arg)
-{
- return execute_ioctl_hooks (anchor.private_next, primary, fd, request, arg);
-}
-
-void
-register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook, struct fd_hook *link)
-{
- if (close_hook == NULL)
- close_hook = execute_close_hooks;
- if (ioctl_hook == NULL)
- ioctl_hook = execute_ioctl_hooks;
-
- if (link->private_next == NULL && link->private_prev == NULL)
- {
- /* Add the link to the doubly linked list. */
- link->private_next = anchor.private_next;
- link->private_prev = &anchor;
- link->private_close_fn = close_hook;
- link->private_ioctl_fn = ioctl_hook;
- anchor.private_next->private_prev = link;
- anchor.private_next = link;
- }
- else
- {
- /* The link is already in use. */
- if (link->private_close_fn != close_hook
- || link->private_ioctl_fn != ioctl_hook)
- abort ();
- }
-}
-
-void
-unregister_fd_hook (struct fd_hook *link)
-{
- struct fd_hook *next = link->private_next;
- struct fd_hook *prev = link->private_prev;
-
- if (next != NULL && prev != NULL)
- {
- /* The link is in use. Remove it from the doubly linked list. */
- prev->private_next = next;
- next->private_prev = prev;
- /* Clear the link, to mark it unused. */
- link->private_next = NULL;
- link->private_prev = NULL;
- link->private_close_fn = NULL;
- link->private_ioctl_fn = NULL;
- }
-}
-
-#endif
+/* Hook for making making file descriptor functions close(), ioctl() extensible.
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2009.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "fd-hook.h"
+
+#include <stdlib.h>
+
+/* Currently, this entire code is only needed for the handling of sockets
+ on native Windows platforms. */
+#if WINDOWS_SOCKETS
+
+/* The first and last link in the doubly linked list.
+ Initially the list is empty. */
+static struct fd_hook anchor = { &anchor, &anchor, NULL, NULL };
+
+int
+execute_close_hooks (const struct fd_hook *remaining_list, gl_close_fn primary,
+ int fd)
+{
+ if (remaining_list == &anchor)
+ /* End of list reached. */
+ return primary (fd);
+ else
+ return remaining_list->private_close_fn (remaining_list->private_next,
+ primary, fd);
+}
+
+int
+execute_all_close_hooks (gl_close_fn primary, int fd)
+{
+ return execute_close_hooks (anchor.private_next, primary, fd);
+}
+
+int
+execute_ioctl_hooks (const struct fd_hook *remaining_list, gl_ioctl_fn primary,
+ int fd, int request, void *arg)
+{
+ if (remaining_list == &anchor)
+ /* End of list reached. */
+ return primary (fd, request, arg);
+ else
+ return remaining_list->private_ioctl_fn (remaining_list->private_next,
+ primary, fd, request, arg);
+}
+
+int
+execute_all_ioctl_hooks (gl_ioctl_fn primary,
+ int fd, int request, void *arg)
+{
+ return execute_ioctl_hooks (anchor.private_next, primary, fd, request, arg);
+}
+
+void
+register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook, struct fd_hook *link)
+{
+ if (close_hook == NULL)
+ close_hook = execute_close_hooks;
+ if (ioctl_hook == NULL)
+ ioctl_hook = execute_ioctl_hooks;
+
+ if (link->private_next == NULL && link->private_prev == NULL)
+ {
+ /* Add the link to the doubly linked list. */
+ link->private_next = anchor.private_next;
+ link->private_prev = &anchor;
+ link->private_close_fn = close_hook;
+ link->private_ioctl_fn = ioctl_hook;
+ anchor.private_next->private_prev = link;
+ anchor.private_next = link;
+ }
+ else
+ {
+ /* The link is already in use. */
+ if (link->private_close_fn != close_hook
+ || link->private_ioctl_fn != ioctl_hook)
+ abort ();
+ }
+}
+
+void
+unregister_fd_hook (struct fd_hook *link)
+{
+ struct fd_hook *next = link->private_next;
+ struct fd_hook *prev = link->private_prev;
+
+ if (next != NULL && prev != NULL)
+ {
+ /* The link is in use. Remove it from the doubly linked list. */
+ prev->private_next = next;
+ next->private_prev = prev;
+ /* Clear the link, to mark it unused. */
+ link->private_next = NULL;
+ link->private_prev = NULL;
+ link->private_close_fn = NULL;
+ link->private_ioctl_fn = NULL;
+ }
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/fd-hook.h b/contrib/tools/bison/gnulib/src/fd-hook.h
index d15b577114..469f86756e 100644
--- a/contrib/tools/bison/gnulib/src/fd-hook.h
+++ b/contrib/tools/bison/gnulib/src/fd-hook.h
@@ -1,119 +1,119 @@
-/* Hook for making making file descriptor functions close(), ioctl() extensible.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#ifndef FD_HOOK_H
-#define FD_HOOK_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Currently, this entire code is only needed for the handling of sockets
- on native Windows platforms. */
-#if WINDOWS_SOCKETS
-
-
-/* Type of function that closes FD. */
-typedef int (*gl_close_fn) (int fd);
-
-/* Type of function that applies a control request to FD. */
-typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
-
-/* An element of the list of file descriptor hooks.
- In CLOS (Common Lisp Object System) speak, it consists of an "around"
- method for the close() function and an "around" method for the ioctl()
- function.
- The fields of this structure are considered private. */
-struct fd_hook
-{
- /* Doubly linked list. */
- struct fd_hook *private_next;
- struct fd_hook *private_prev;
- /* Function that treats the types of FD that it knows about and calls
- execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback. */
- int (*private_close_fn) (const struct fd_hook *remaining_list,
- gl_close_fn primary,
- int fd);
- /* Function that treats the types of FD that it knows about and calls
- execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
- fallback. */
- int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
- gl_ioctl_fn primary,
- int fd, int request, void *arg);
-};
-
-/* This type of function closes FD, applying special knowledge for the FD
- types it knows about, and calls
- execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
- for the other FD types.
- In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
- and PRIMARY is the "primary" method for close(). */
-typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
- gl_close_fn primary,
- int fd);
-
-/* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
- Return 0 or -1, like close() would do. */
-extern int execute_close_hooks (const struct fd_hook *remaining_list,
- gl_close_fn primary,
- int fd);
-
-/* Execute all close hooks, with PRIMARY as "primary" method.
- Return 0 or -1, like close() would do. */
-extern int execute_all_close_hooks (gl_close_fn primary, int fd);
-
-/* This type of function applies a control request to FD, applying special
- knowledge for the FD types it knows about, and calls
- execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
- for the other FD types.
- In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
- and PRIMARY is the "primary" method for ioctl(). */
-typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
- gl_ioctl_fn primary,
- int fd, int request, void *arg);
-
-/* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
- Return 0 or -1, like ioctl() would do. */
-extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
- gl_ioctl_fn primary,
- int fd, int request, void *arg);
-
-/* Execute all ioctl hooks, with PRIMARY as "primary" method.
- Return 0 or -1, like ioctl() would do. */
-extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
- int fd, int request, void *arg);
-
-/* Add a function pair to the list of file descriptor hooks.
- CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
- The LINK variable points to a piece of memory which is guaranteed to be
- accessible until the corresponding call to unregister_fd_hook. */
-extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook,
- struct fd_hook *link);
-
-/* Removes a hook from the list of file descriptor hooks. */
-extern void unregister_fd_hook (struct fd_hook *link);
-
-
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* FD_HOOK_H */
+/* Hook for making making file descriptor functions close(), ioctl() extensible.
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#ifndef FD_HOOK_H
+#define FD_HOOK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Currently, this entire code is only needed for the handling of sockets
+ on native Windows platforms. */
+#if WINDOWS_SOCKETS
+
+
+/* Type of function that closes FD. */
+typedef int (*gl_close_fn) (int fd);
+
+/* Type of function that applies a control request to FD. */
+typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
+
+/* An element of the list of file descriptor hooks.
+ In CLOS (Common Lisp Object System) speak, it consists of an "around"
+ method for the close() function and an "around" method for the ioctl()
+ function.
+ The fields of this structure are considered private. */
+struct fd_hook
+{
+ /* Doubly linked list. */
+ struct fd_hook *private_next;
+ struct fd_hook *private_prev;
+ /* Function that treats the types of FD that it knows about and calls
+ execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback. */
+ int (*private_close_fn) (const struct fd_hook *remaining_list,
+ gl_close_fn primary,
+ int fd);
+ /* Function that treats the types of FD that it knows about and calls
+ execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
+ fallback. */
+ int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
+ gl_ioctl_fn primary,
+ int fd, int request, void *arg);
+};
+
+/* This type of function closes FD, applying special knowledge for the FD
+ types it knows about, and calls
+ execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
+ for the other FD types.
+ In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
+ and PRIMARY is the "primary" method for close(). */
+typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
+ gl_close_fn primary,
+ int fd);
+
+/* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
+ Return 0 or -1, like close() would do. */
+extern int execute_close_hooks (const struct fd_hook *remaining_list,
+ gl_close_fn primary,
+ int fd);
+
+/* Execute all close hooks, with PRIMARY as "primary" method.
+ Return 0 or -1, like close() would do. */
+extern int execute_all_close_hooks (gl_close_fn primary, int fd);
+
+/* This type of function applies a control request to FD, applying special
+ knowledge for the FD types it knows about, and calls
+ execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
+ for the other FD types.
+ In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
+ and PRIMARY is the "primary" method for ioctl(). */
+typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
+ gl_ioctl_fn primary,
+ int fd, int request, void *arg);
+
+/* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
+ Return 0 or -1, like ioctl() would do. */
+extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
+ gl_ioctl_fn primary,
+ int fd, int request, void *arg);
+
+/* Execute all ioctl hooks, with PRIMARY as "primary" method.
+ Return 0 or -1, like ioctl() would do. */
+extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
+ int fd, int request, void *arg);
+
+/* Add a function pair to the list of file descriptor hooks.
+ CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
+ The LINK variable points to a piece of memory which is guaranteed to be
+ accessible until the corresponding call to unregister_fd_hook. */
+extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook,
+ struct fd_hook *link);
+
+/* Removes a hook from the list of file descriptor hooks. */
+extern void unregister_fd_hook (struct fd_hook *link);
+
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FD_HOOK_H */
diff --git a/contrib/tools/bison/gnulib/src/fd-safer-flag.c b/contrib/tools/bison/gnulib/src/fd-safer-flag.c
index 8bc14bda2c..1ee8b88dde 100644
--- a/contrib/tools/bison/gnulib/src/fd-safer-flag.c
+++ b/contrib/tools/bison/gnulib/src/fd-safer-flag.c
@@ -1,52 +1,52 @@
-/* Adjust a file descriptor result so that it avoids clobbering
- STD{IN,OUT,ERR}_FILENO, with specific flags.
-
- Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert and Eric Blake. */
-
-#include <config.h>
-
-/* Specification. */
-#include "unistd-safer.h"
-
-#include <errno.h>
-#include <unistd.h>
-
-/* Return FD, unless FD would be a copy of standard input, output, or
- error; in that case, return a duplicate of FD, closing FD. If FLAG
- contains O_CLOEXEC, the returned FD will have close-on-exec
- semantics. On failure to duplicate, close FD, set errno, and
- return -1. Preserve errno if FD is negative, so that the caller
- can always inspect errno when the returned value is negative.
-
- This function is usefully wrapped around functions that return file
- descriptors, e.g., fd_safer_flag (open ("file", O_RDONLY | flag), flag). */
-
-int
-fd_safer_flag (int fd, int flag)
-{
- if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
- {
- int f = dup_safer_flag (fd, flag);
- int e = errno;
- close (fd);
- errno = e;
- fd = f;
- }
-
- return fd;
-}
+/* Adjust a file descriptor result so that it avoids clobbering
+ STD{IN,OUT,ERR}_FILENO, with specific flags.
+
+ Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert and Eric Blake. */
+
+#include <config.h>
+
+/* Specification. */
+#include "unistd-safer.h"
+
+#include <errno.h>
+#include <unistd.h>
+
+/* Return FD, unless FD would be a copy of standard input, output, or
+ error; in that case, return a duplicate of FD, closing FD. If FLAG
+ contains O_CLOEXEC, the returned FD will have close-on-exec
+ semantics. On failure to duplicate, close FD, set errno, and
+ return -1. Preserve errno if FD is negative, so that the caller
+ can always inspect errno when the returned value is negative.
+
+ This function is usefully wrapped around functions that return file
+ descriptors, e.g., fd_safer_flag (open ("file", O_RDONLY | flag), flag). */
+
+int
+fd_safer_flag (int fd, int flag)
+{
+ if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
+ {
+ int f = dup_safer_flag (fd, flag);
+ int e = errno;
+ close (fd);
+ errno = e;
+ fd = f;
+ }
+
+ return fd;
+}
diff --git a/contrib/tools/bison/gnulib/src/fd-safer.c b/contrib/tools/bison/gnulib/src/fd-safer.c
index 8ded8886a5..16f19f517d 100644
--- a/contrib/tools/bison/gnulib/src/fd-safer.c
+++ b/contrib/tools/bison/gnulib/src/fd-safer.c
@@ -1,49 +1,49 @@
-/* Return a safer copy of a file descriptor.
-
- Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <config.h>
-
-#include "unistd-safer.h"
-
-#include <errno.h>
-#include <unistd.h>
-
-/* Return FD, unless FD would be a copy of standard input, output, or
- error; in that case, return a duplicate of FD, closing FD. On
- failure to duplicate, close FD, set errno, and return -1. Preserve
- errno if FD is negative, so that the caller can always inspect
- errno when the returned value is negative.
-
- This function is usefully wrapped around functions that return file
- descriptors, e.g., fd_safer (open ("file", O_RDONLY)). */
-
-int
-fd_safer (int fd)
-{
- if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
- {
- int f = dup_safer (fd);
- int e = errno;
- close (fd);
- errno = e;
- fd = f;
- }
-
- return fd;
-}
+/* Return a safer copy of a file descriptor.
+
+ Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <config.h>
+
+#include "unistd-safer.h"
+
+#include <errno.h>
+#include <unistd.h>
+
+/* Return FD, unless FD would be a copy of standard input, output, or
+ error; in that case, return a duplicate of FD, closing FD. On
+ failure to duplicate, close FD, set errno, and return -1. Preserve
+ errno if FD is negative, so that the caller can always inspect
+ errno when the returned value is negative.
+
+ This function is usefully wrapped around functions that return file
+ descriptors, e.g., fd_safer (open ("file", O_RDONLY)). */
+
+int
+fd_safer (int fd)
+{
+ if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
+ {
+ int f = dup_safer (fd);
+ int e = errno;
+ close (fd);
+ errno = e;
+ fd = f;
+ }
+
+ return fd;
+}
diff --git a/contrib/tools/bison/gnulib/src/fflush.c b/contrib/tools/bison/gnulib/src/fflush.c
index 9df79119dd..af78c69a91 100644
--- a/contrib/tools/bison/gnulib/src/fflush.c
+++ b/contrib/tools/bison/gnulib/src/fflush.c
@@ -1,225 +1,225 @@
-/* fflush.c -- allow flushing input streams
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Eric Blake. */
-
-#include <config.h>
-
-/* Specification. */
+/* fflush.c -- allow flushing input streams
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake. */
+
+#include <config.h>
+
+/* Specification. */
#include "stdio--.h"
-
-#include <errno.h>
-#include <unistd.h>
-
-#include "freading.h"
-
-#include "stdio-impl.h"
-
-#include "unused-parameter.h"
-
-#undef fflush
-
-
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
-
-/* Clear the stream's ungetc buffer, preserving the value of ftello (fp). */
-static void
-clear_ungetc_buffer_preserving_position (FILE *fp)
-{
- if (fp->_flags & _IO_IN_BACKUP)
- /* _IO_free_backup_area is a bit complicated. Simply call fseek. */
- fseeko (fp, 0, SEEK_CUR);
-}
-
-#else
-
-/* Clear the stream's ungetc buffer. May modify the value of ftello (fp). */
-static void
-clear_ungetc_buffer (FILE *fp)
-{
-# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
- if (HASUB (fp))
- {
- fp_->_p += fp_->_r;
- fp_->_r = 0;
- }
-# elif defined __EMX__ /* emx+gcc */
- if (fp->_ungetc_count > 0)
- {
- fp->_ungetc_count = 0;
- fp->_rcount = - fp->_rcount;
- }
-# elif defined _IOERR /* Minix, AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
- /* Nothing to do. */
-# else /* other implementations */
- fseeko (fp, 0, SEEK_CUR);
-# endif
-}
-
-#endif
-
-#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
-
-# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
-
-static int
-disable_seek_optimization (FILE *fp)
-{
- int saved_flags = fp_->_flags & (__SOPT | __SNPT);
- fp_->_flags = (fp_->_flags & ~__SOPT) | __SNPT;
- return saved_flags;
-}
-
-static void
-restore_seek_optimization (FILE *fp, int saved_flags)
-{
- fp_->_flags = (fp_->_flags & ~(__SOPT | __SNPT)) | saved_flags;
-}
-
-# else
-
-static void
-update_fpos_cache (FILE *fp _GL_UNUSED_PARAMETER,
- off_t pos _GL_UNUSED_PARAMETER)
-{
-# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
-# if defined __CYGWIN__
- /* fp_->_offset is typed as an integer. */
- fp_->_offset = pos;
-# else
- /* fp_->_offset is an fpos_t. */
- /* Use a union, since on NetBSD, the compilation flags determine
- whether fpos_t is typedef'd to off_t or a struct containing a
- single off_t member. */
- union
- {
- fpos_t f;
- off_t o;
- } u;
- u.o = pos;
- fp_->_offset = u.f;
-# endif
- fp_->_flags |= __SOFF;
-# endif
-}
-# endif
-#endif
-
-/* Flush all pending data on STREAM according to POSIX rules. Both
- output and seekable input streams are supported. */
-int
-rpl_fflush (FILE *stream)
-{
- /* When stream is NULL, POSIX and C99 only require flushing of "output
- streams and update streams in which the most recent operation was not
- input", and all implementations do this.
-
- When stream is "an output stream or an update stream in which the most
- recent operation was not input", POSIX and C99 requires that fflush
- writes out any buffered data, and all implementations do this.
-
- When stream is, however, an input stream or an update stream in
- which the most recent operation was input, C99 specifies nothing,
- and POSIX only specifies behavior if the stream is seekable.
- mingw, in particular, drops the input buffer, leaving the file
- descriptor positioned at the end of the input buffer. I.e. ftell
- (stream) is lost. We don't want to call the implementation's
- fflush in this case.
-
- We test ! freading (stream) here, rather than fwriting (stream), because
- what we need to know is whether the stream holds a "read buffer", and on
- mingw this is indicated by _IOREAD, regardless of _IOWRT. */
- if (stream == NULL || ! freading (stream))
- return fflush (stream);
-
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
-
- clear_ungetc_buffer_preserving_position (stream);
-
- return fflush (stream);
-
-#else
- {
- /* Notes about the file-position indicator:
- 1) The file position indicator is incremented by fgetc() and decremented
- by ungetc():
- <http://www.opengroup.org/susv3/functions/fgetc.html>
- "... the fgetc() function shall ... advance the associated file
- position indicator for the stream ..."
- <http://www.opengroup.org/susv3/functions/ungetc.html>
- "The file-position indicator is decremented by each successful
- call to ungetc()..."
- 2) <http://www.opengroup.org/susv3/functions/ungetc.html> says:
- "The value of the file-position indicator for the stream after
- reading or discarding all pushed-back bytes shall be the same
- as it was before the bytes were pushed back."
- Here we are discarding all pushed-back bytes. But more specifically,
- 3) <http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt> says:
- "[After fflush(),] the file offset of the underlying open file
- description shall be set to the file position of the stream, and
- any characters pushed back onto the stream by ungetc() ... shall
- be discarded." */
-
- /* POSIX does not specify fflush behavior for non-seekable input
- streams. Some implementations purge unread data, some return
- EBADF, some do nothing. */
- off_t pos = ftello (stream);
- if (pos == -1)
- {
- errno = EBADF;
- return EOF;
- }
-
- /* Clear the ungetc buffer. */
- clear_ungetc_buffer (stream);
-
- /* To get here, we must be flushing a seekable input stream, so the
- semantics of fpurge are now appropriate to clear the buffer. To
- avoid losing data, the lseek is also necessary. */
- {
- int result = fpurge (stream);
- if (result != 0)
- return result;
- }
-
-# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
-
- {
- /* Disable seek optimization for the next fseeko call. This tells the
- following fseeko call to seek to the desired position directly, rather
- than to seek to a block-aligned boundary. */
- int saved_flags = disable_seek_optimization (stream);
- int result = fseeko (stream, pos, SEEK_SET);
-
- restore_seek_optimization (stream, saved_flags);
- return result;
- }
-
-# else
-
- pos = lseek (fileno (stream), pos, SEEK_SET);
- if (pos == -1)
- return EOF;
- /* After a successful lseek, update the file descriptor's position cache
- in the stream. */
- update_fpos_cache (stream, pos);
-
- return 0;
-
-# endif
- }
-#endif
-}
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "freading.h"
+
+#include "stdio-impl.h"
+
+#include "unused-parameter.h"
+
+#undef fflush
+
+
+#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+
+/* Clear the stream's ungetc buffer, preserving the value of ftello (fp). */
+static void
+clear_ungetc_buffer_preserving_position (FILE *fp)
+{
+ if (fp->_flags & _IO_IN_BACKUP)
+ /* _IO_free_backup_area is a bit complicated. Simply call fseek. */
+ fseeko (fp, 0, SEEK_CUR);
+}
+
+#else
+
+/* Clear the stream's ungetc buffer. May modify the value of ftello (fp). */
+static void
+clear_ungetc_buffer (FILE *fp)
+{
+# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+ if (HASUB (fp))
+ {
+ fp_->_p += fp_->_r;
+ fp_->_r = 0;
+ }
+# elif defined __EMX__ /* emx+gcc */
+ if (fp->_ungetc_count > 0)
+ {
+ fp->_ungetc_count = 0;
+ fp->_rcount = - fp->_rcount;
+ }
+# elif defined _IOERR /* Minix, AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
+ /* Nothing to do. */
+# else /* other implementations */
+ fseeko (fp, 0, SEEK_CUR);
+# endif
+}
+
+#endif
+
+#if ! (defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */)
+
+# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+
+static int
+disable_seek_optimization (FILE *fp)
+{
+ int saved_flags = fp_->_flags & (__SOPT | __SNPT);
+ fp_->_flags = (fp_->_flags & ~__SOPT) | __SNPT;
+ return saved_flags;
+}
+
+static void
+restore_seek_optimization (FILE *fp, int saved_flags)
+{
+ fp_->_flags = (fp_->_flags & ~(__SOPT | __SNPT)) | saved_flags;
+}
+
+# else
+
+static void
+update_fpos_cache (FILE *fp _GL_UNUSED_PARAMETER,
+ off_t pos _GL_UNUSED_PARAMETER)
+{
+# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+# if defined __CYGWIN__
+ /* fp_->_offset is typed as an integer. */
+ fp_->_offset = pos;
+# else
+ /* fp_->_offset is an fpos_t. */
+ /* Use a union, since on NetBSD, the compilation flags determine
+ whether fpos_t is typedef'd to off_t or a struct containing a
+ single off_t member. */
+ union
+ {
+ fpos_t f;
+ off_t o;
+ } u;
+ u.o = pos;
+ fp_->_offset = u.f;
+# endif
+ fp_->_flags |= __SOFF;
+# endif
+}
+# endif
+#endif
+
+/* Flush all pending data on STREAM according to POSIX rules. Both
+ output and seekable input streams are supported. */
+int
+rpl_fflush (FILE *stream)
+{
+ /* When stream is NULL, POSIX and C99 only require flushing of "output
+ streams and update streams in which the most recent operation was not
+ input", and all implementations do this.
+
+ When stream is "an output stream or an update stream in which the most
+ recent operation was not input", POSIX and C99 requires that fflush
+ writes out any buffered data, and all implementations do this.
+
+ When stream is, however, an input stream or an update stream in
+ which the most recent operation was input, C99 specifies nothing,
+ and POSIX only specifies behavior if the stream is seekable.
+ mingw, in particular, drops the input buffer, leaving the file
+ descriptor positioned at the end of the input buffer. I.e. ftell
+ (stream) is lost. We don't want to call the implementation's
+ fflush in this case.
+
+ We test ! freading (stream) here, rather than fwriting (stream), because
+ what we need to know is whether the stream holds a "read buffer", and on
+ mingw this is indicated by _IOREAD, regardless of _IOWRT. */
+ if (stream == NULL || ! freading (stream))
+ return fflush (stream);
+
+#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+
+ clear_ungetc_buffer_preserving_position (stream);
+
+ return fflush (stream);
+
+#else
+ {
+ /* Notes about the file-position indicator:
+ 1) The file position indicator is incremented by fgetc() and decremented
+ by ungetc():
+ <http://www.opengroup.org/susv3/functions/fgetc.html>
+ "... the fgetc() function shall ... advance the associated file
+ position indicator for the stream ..."
+ <http://www.opengroup.org/susv3/functions/ungetc.html>
+ "The file-position indicator is decremented by each successful
+ call to ungetc()..."
+ 2) <http://www.opengroup.org/susv3/functions/ungetc.html> says:
+ "The value of the file-position indicator for the stream after
+ reading or discarding all pushed-back bytes shall be the same
+ as it was before the bytes were pushed back."
+ Here we are discarding all pushed-back bytes. But more specifically,
+ 3) <http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt> says:
+ "[After fflush(),] the file offset of the underlying open file
+ description shall be set to the file position of the stream, and
+ any characters pushed back onto the stream by ungetc() ... shall
+ be discarded." */
+
+ /* POSIX does not specify fflush behavior for non-seekable input
+ streams. Some implementations purge unread data, some return
+ EBADF, some do nothing. */
+ off_t pos = ftello (stream);
+ if (pos == -1)
+ {
+ errno = EBADF;
+ return EOF;
+ }
+
+ /* Clear the ungetc buffer. */
+ clear_ungetc_buffer (stream);
+
+ /* To get here, we must be flushing a seekable input stream, so the
+ semantics of fpurge are now appropriate to clear the buffer. To
+ avoid losing data, the lseek is also necessary. */
+ {
+ int result = fpurge (stream);
+ if (result != 0)
+ return result;
+ }
+
+# if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+
+ {
+ /* Disable seek optimization for the next fseeko call. This tells the
+ following fseeko call to seek to the desired position directly, rather
+ than to seek to a block-aligned boundary. */
+ int saved_flags = disable_seek_optimization (stream);
+ int result = fseeko (stream, pos, SEEK_SET);
+
+ restore_seek_optimization (stream, saved_flags);
+ return result;
+ }
+
+# else
+
+ pos = lseek (fileno (stream), pos, SEEK_SET);
+ if (pos == -1)
+ return EOF;
+ /* After a successful lseek, update the file descriptor's position cache
+ in the stream. */
+ update_fpos_cache (stream, pos);
+
+ return 0;
+
+# endif
+ }
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/filename.h b/contrib/tools/bison/gnulib/src/filename.h
index b82a0ac389..31617cfb95 100644
--- a/contrib/tools/bison/gnulib/src/filename.h
+++ b/contrib/tools/bison/gnulib/src/filename.h
@@ -1,54 +1,54 @@
-/* Basic filename support macros.
- Copyright (C) 2001-2004, 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _FILENAME_H
-#define _FILENAME_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Pathname support.
- ISSLASH(C) tests whether C is a directory separator character.
- IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not,
- it may be concatenated to a directory pathname.
- IS_PATH_WITH_DIR(P) tests whether P contains a directory specification.
- */
-#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
- /* Native Windows, Cygwin, OS/2, DOS */
-# define ISSLASH(C) ((C) == '/' || (C) == '\\')
-# define HAS_DEVICE(P) \
- ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
- && (P)[1] == ':')
-# define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
-# define IS_PATH_WITH_DIR(P) \
- (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
-# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
-#else
- /* Unix */
-# define ISSLASH(C) ((C) == '/')
-# define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
-# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
-# define FILE_SYSTEM_PREFIX_LEN(P) 0
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _FILENAME_H */
+/* Basic filename support macros.
+ Copyright (C) 2001-2004, 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _FILENAME_H
+#define _FILENAME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Pathname support.
+ ISSLASH(C) tests whether C is a directory separator character.
+ IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not,
+ it may be concatenated to a directory pathname.
+ IS_PATH_WITH_DIR(P) tests whether P contains a directory specification.
+ */
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+ /* Native Windows, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+# define HAS_DEVICE(P) \
+ ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
+ && (P)[1] == ':')
+# define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
+# define IS_PATH_WITH_DIR(P) \
+ (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
+# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
+#else
+ /* Unix */
+# define ISSLASH(C) ((C) == '/')
+# define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
+# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
+# define FILE_SYSTEM_PREFIX_LEN(P) 0
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FILENAME_H */
diff --git a/contrib/tools/bison/gnulib/src/filenamecat-lgpl.c b/contrib/tools/bison/gnulib/src/filenamecat-lgpl.c
index 60c4988b4d..f479dbf432 100644
--- a/contrib/tools/bison/gnulib/src/filenamecat-lgpl.c
+++ b/contrib/tools/bison/gnulib/src/filenamecat-lgpl.c
@@ -1,88 +1,88 @@
-/* Concatenate two arbitrary file names.
-
- Copyright (C) 1996-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#include <config.h>
-
-/* Specification. */
-#include "filenamecat.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dirname.h"
-
-#if ! HAVE_MEMPCPY && ! defined mempcpy
-# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
-#endif
-
-/* Return the longest suffix of F that is a relative file name.
- If it has no such suffix, return the empty string. */
-
-static char const * _GL_ATTRIBUTE_PURE
-longest_relative_suffix (char const *f)
-{
- for (f += FILE_SYSTEM_PREFIX_LEN (f); ISSLASH (*f); f++)
- continue;
- return f;
-}
-
-/* Concatenate two file name components, DIR and ABASE, in
- newly-allocated storage and return the result.
- The resulting file name F is such that the commands "ls F" and "(cd
- DIR; ls BASE)" refer to the same file, where BASE is ABASE with any
- file system prefixes and leading separators removed.
- Arrange for a directory separator if necessary between DIR and BASE
- in the result, removing any redundant separators.
- In any case, if BASE_IN_RESULT is non-NULL, set
- *BASE_IN_RESULT to point to the copy of ABASE in the returned
- concatenation. However, if ABASE begins with more than one slash,
- set *BASE_IN_RESULT to point to the sole corresponding slash that
- is copied into the result buffer.
-
- Return NULL if malloc fails. */
-
-char *
-mfile_name_concat (char const *dir, char const *abase, char **base_in_result)
-{
- char const *dirbase = last_component (dir);
- size_t dirbaselen = base_len (dirbase);
- size_t dirlen = dirbase - dir + dirbaselen;
- size_t needs_separator = (dirbaselen && ! ISSLASH (dirbase[dirbaselen - 1]));
-
- char const *base = longest_relative_suffix (abase);
- size_t baselen = strlen (base);
-
- char *p_concat = malloc (dirlen + needs_separator + baselen + 1);
- char *p;
-
- if (p_concat == NULL)
- return NULL;
-
- p = mempcpy (p_concat, dir, dirlen);
- *p = DIRECTORY_SEPARATOR;
- p += needs_separator;
-
- if (base_in_result)
- *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase);
-
- p = mempcpy (p, base, baselen);
- *p = '\0';
-
- return p_concat;
-}
+/* Concatenate two arbitrary file names.
+
+ Copyright (C) 1996-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#include <config.h>
+
+/* Specification. */
+#include "filenamecat.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "dirname.h"
+
+#if ! HAVE_MEMPCPY && ! defined mempcpy
+# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
+#endif
+
+/* Return the longest suffix of F that is a relative file name.
+ If it has no such suffix, return the empty string. */
+
+static char const * _GL_ATTRIBUTE_PURE
+longest_relative_suffix (char const *f)
+{
+ for (f += FILE_SYSTEM_PREFIX_LEN (f); ISSLASH (*f); f++)
+ continue;
+ return f;
+}
+
+/* Concatenate two file name components, DIR and ABASE, in
+ newly-allocated storage and return the result.
+ The resulting file name F is such that the commands "ls F" and "(cd
+ DIR; ls BASE)" refer to the same file, where BASE is ABASE with any
+ file system prefixes and leading separators removed.
+ Arrange for a directory separator if necessary between DIR and BASE
+ in the result, removing any redundant separators.
+ In any case, if BASE_IN_RESULT is non-NULL, set
+ *BASE_IN_RESULT to point to the copy of ABASE in the returned
+ concatenation. However, if ABASE begins with more than one slash,
+ set *BASE_IN_RESULT to point to the sole corresponding slash that
+ is copied into the result buffer.
+
+ Return NULL if malloc fails. */
+
+char *
+mfile_name_concat (char const *dir, char const *abase, char **base_in_result)
+{
+ char const *dirbase = last_component (dir);
+ size_t dirbaselen = base_len (dirbase);
+ size_t dirlen = dirbase - dir + dirbaselen;
+ size_t needs_separator = (dirbaselen && ! ISSLASH (dirbase[dirbaselen - 1]));
+
+ char const *base = longest_relative_suffix (abase);
+ size_t baselen = strlen (base);
+
+ char *p_concat = malloc (dirlen + needs_separator + baselen + 1);
+ char *p;
+
+ if (p_concat == NULL)
+ return NULL;
+
+ p = mempcpy (p_concat, dir, dirlen);
+ *p = DIRECTORY_SEPARATOR;
+ p += needs_separator;
+
+ if (base_in_result)
+ *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase);
+
+ p = mempcpy (p, base, baselen);
+ *p = '\0';
+
+ return p_concat;
+}
diff --git a/contrib/tools/bison/gnulib/src/filenamecat.c b/contrib/tools/bison/gnulib/src/filenamecat.c
index 8809b571f5..f56dfe1326 100644
--- a/contrib/tools/bison/gnulib/src/filenamecat.c
+++ b/contrib/tools/bison/gnulib/src/filenamecat.c
@@ -1,41 +1,41 @@
-/* Concatenate two arbitrary file names.
-
- Copyright (C) 1996-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#include <config.h>
-
-/* Specification. */
-#include "filenamecat.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "xalloc.h"
-
-/* Just like mfile_name_concat (filenamecat-lgpl.c), except, rather than
- returning NULL upon malloc failure, here, we report the
- "memory exhausted" condition and exit. */
-
-char *
-file_name_concat (char const *dir, char const *abase, char **base_in_result)
-{
- char *p = mfile_name_concat (dir, abase, base_in_result);
- if (p == NULL)
- xalloc_die ();
- return p;
-}
+/* Concatenate two arbitrary file names.
+
+ Copyright (C) 1996-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#include <config.h>
+
+/* Specification. */
+#include "filenamecat.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "xalloc.h"
+
+/* Just like mfile_name_concat (filenamecat-lgpl.c), except, rather than
+ returning NULL upon malloc failure, here, we report the
+ "memory exhausted" condition and exit. */
+
+char *
+file_name_concat (char const *dir, char const *abase, char **base_in_result)
+{
+ char *p = mfile_name_concat (dir, abase, base_in_result);
+ if (p == NULL)
+ xalloc_die ();
+ return p;
+}
diff --git a/contrib/tools/bison/gnulib/src/filenamecat.h b/contrib/tools/bison/gnulib/src/filenamecat.h
index 1476e14c74..aab98f294c 100644
--- a/contrib/tools/bison/gnulib/src/filenamecat.h
+++ b/contrib/tools/bison/gnulib/src/filenamecat.h
@@ -1,27 +1,27 @@
-/* Concatenate two arbitrary file names.
-
- Copyright (C) 1996-1997, 2003, 2005, 2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#if GNULIB_FILENAMECAT
-char *file_name_concat (char const *dir, char const *base,
- char **base_in_result);
-#endif
-
-char *mfile_name_concat (char const *dir, char const *base,
- char **base_in_result);
+/* Concatenate two arbitrary file names.
+
+ Copyright (C) 1996-1997, 2003, 2005, 2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#if GNULIB_FILENAMECAT
+char *file_name_concat (char const *dir, char const *base,
+ char **base_in_result);
+#endif
+
+char *mfile_name_concat (char const *dir, char const *base,
+ char **base_in_result);
diff --git a/contrib/tools/bison/gnulib/src/float+.h b/contrib/tools/bison/gnulib/src/float+.h
index 32fb790bb5..7524ba904a 100644
--- a/contrib/tools/bison/gnulib/src/float+.h
+++ b/contrib/tools/bison/gnulib/src/float+.h
@@ -1,147 +1,147 @@
-/* Supplemental information about the floating-point formats.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2007.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _FLOATPLUS_H
-#define _FLOATPLUS_H
-
-#include <float.h>
-#include <limits.h>
-
-/* Number of bits in the mantissa of a floating-point number, including the
- "hidden bit". */
-#if FLT_RADIX == 2
-# define FLT_MANT_BIT FLT_MANT_DIG
-# define DBL_MANT_BIT DBL_MANT_DIG
-# define LDBL_MANT_BIT LDBL_MANT_DIG
-#elif FLT_RADIX == 4
-# define FLT_MANT_BIT (FLT_MANT_DIG * 2)
-# define DBL_MANT_BIT (DBL_MANT_DIG * 2)
-# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2)
-#elif FLT_RADIX == 16
-# define FLT_MANT_BIT (FLT_MANT_DIG * 4)
-# define DBL_MANT_BIT (DBL_MANT_DIG * 4)
-# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4)
-#endif
-
-/* Bit mask that can be used to mask the exponent, as an unsigned number. */
-#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7)
-#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
-#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7)
-
-/* Number of bits used for the exponent of a floating-point number, including
- the exponent's sign. */
-#define FLT_EXP_BIT \
- (FLT_EXP_MASK < 0x100 ? 8 : \
- FLT_EXP_MASK < 0x200 ? 9 : \
- FLT_EXP_MASK < 0x400 ? 10 : \
- FLT_EXP_MASK < 0x800 ? 11 : \
- FLT_EXP_MASK < 0x1000 ? 12 : \
- FLT_EXP_MASK < 0x2000 ? 13 : \
- FLT_EXP_MASK < 0x4000 ? 14 : \
- FLT_EXP_MASK < 0x8000 ? 15 : \
- FLT_EXP_MASK < 0x10000 ? 16 : \
- FLT_EXP_MASK < 0x20000 ? 17 : \
- FLT_EXP_MASK < 0x40000 ? 18 : \
- FLT_EXP_MASK < 0x80000 ? 19 : \
- FLT_EXP_MASK < 0x100000 ? 20 : \
- FLT_EXP_MASK < 0x200000 ? 21 : \
- FLT_EXP_MASK < 0x400000 ? 22 : \
- FLT_EXP_MASK < 0x800000 ? 23 : \
- FLT_EXP_MASK < 0x1000000 ? 24 : \
- FLT_EXP_MASK < 0x2000000 ? 25 : \
- FLT_EXP_MASK < 0x4000000 ? 26 : \
- FLT_EXP_MASK < 0x8000000 ? 27 : \
- FLT_EXP_MASK < 0x10000000 ? 28 : \
- FLT_EXP_MASK < 0x20000000 ? 29 : \
- FLT_EXP_MASK < 0x40000000 ? 30 : \
- FLT_EXP_MASK <= 0x7fffffff ? 31 : \
- 32)
-#define DBL_EXP_BIT \
- (DBL_EXP_MASK < 0x100 ? 8 : \
- DBL_EXP_MASK < 0x200 ? 9 : \
- DBL_EXP_MASK < 0x400 ? 10 : \
- DBL_EXP_MASK < 0x800 ? 11 : \
- DBL_EXP_MASK < 0x1000 ? 12 : \
- DBL_EXP_MASK < 0x2000 ? 13 : \
- DBL_EXP_MASK < 0x4000 ? 14 : \
- DBL_EXP_MASK < 0x8000 ? 15 : \
- DBL_EXP_MASK < 0x10000 ? 16 : \
- DBL_EXP_MASK < 0x20000 ? 17 : \
- DBL_EXP_MASK < 0x40000 ? 18 : \
- DBL_EXP_MASK < 0x80000 ? 19 : \
- DBL_EXP_MASK < 0x100000 ? 20 : \
- DBL_EXP_MASK < 0x200000 ? 21 : \
- DBL_EXP_MASK < 0x400000 ? 22 : \
- DBL_EXP_MASK < 0x800000 ? 23 : \
- DBL_EXP_MASK < 0x1000000 ? 24 : \
- DBL_EXP_MASK < 0x2000000 ? 25 : \
- DBL_EXP_MASK < 0x4000000 ? 26 : \
- DBL_EXP_MASK < 0x8000000 ? 27 : \
- DBL_EXP_MASK < 0x10000000 ? 28 : \
- DBL_EXP_MASK < 0x20000000 ? 29 : \
- DBL_EXP_MASK < 0x40000000 ? 30 : \
- DBL_EXP_MASK <= 0x7fffffff ? 31 : \
- 32)
-#define LDBL_EXP_BIT \
- (LDBL_EXP_MASK < 0x100 ? 8 : \
- LDBL_EXP_MASK < 0x200 ? 9 : \
- LDBL_EXP_MASK < 0x400 ? 10 : \
- LDBL_EXP_MASK < 0x800 ? 11 : \
- LDBL_EXP_MASK < 0x1000 ? 12 : \
- LDBL_EXP_MASK < 0x2000 ? 13 : \
- LDBL_EXP_MASK < 0x4000 ? 14 : \
- LDBL_EXP_MASK < 0x8000 ? 15 : \
- LDBL_EXP_MASK < 0x10000 ? 16 : \
- LDBL_EXP_MASK < 0x20000 ? 17 : \
- LDBL_EXP_MASK < 0x40000 ? 18 : \
- LDBL_EXP_MASK < 0x80000 ? 19 : \
- LDBL_EXP_MASK < 0x100000 ? 20 : \
- LDBL_EXP_MASK < 0x200000 ? 21 : \
- LDBL_EXP_MASK < 0x400000 ? 22 : \
- LDBL_EXP_MASK < 0x800000 ? 23 : \
- LDBL_EXP_MASK < 0x1000000 ? 24 : \
- LDBL_EXP_MASK < 0x2000000 ? 25 : \
- LDBL_EXP_MASK < 0x4000000 ? 26 : \
- LDBL_EXP_MASK < 0x8000000 ? 27 : \
- LDBL_EXP_MASK < 0x10000000 ? 28 : \
- LDBL_EXP_MASK < 0x20000000 ? 29 : \
- LDBL_EXP_MASK < 0x40000000 ? 30 : \
- LDBL_EXP_MASK <= 0x7fffffff ? 31 : \
- 32)
-
-/* Number of bits used for a floating-point number: the mantissa (not
- counting the "hidden bit", since it may or may not be explicit), the
- exponent, and the sign. */
-#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1)
-#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1)
-#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1)
-
-/* Number of bytes used for a floating-point number.
- This can be smaller than the 'sizeof'. For example, on i386 systems,
- 'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence
- LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but
- sizeof (long double) = 12 or = 16. */
-#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
-#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
-#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
-
-/* Verify that SIZEOF_FLT <= sizeof (float) etc. */
-typedef int verify_sizeof_flt[SIZEOF_FLT <= sizeof (float) ? 1 : -1];
-typedef int verify_sizeof_dbl[SIZEOF_DBL <= sizeof (double) ? 1 : - 1];
-typedef int verify_sizeof_ldbl[SIZEOF_LDBL <= sizeof (long double) ? 1 : - 1];
-
-#endif /* _FLOATPLUS_H */
+/* Supplemental information about the floating-point formats.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2007.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _FLOATPLUS_H
+#define _FLOATPLUS_H
+
+#include <float.h>
+#include <limits.h>
+
+/* Number of bits in the mantissa of a floating-point number, including the
+ "hidden bit". */
+#if FLT_RADIX == 2
+# define FLT_MANT_BIT FLT_MANT_DIG
+# define DBL_MANT_BIT DBL_MANT_DIG
+# define LDBL_MANT_BIT LDBL_MANT_DIG
+#elif FLT_RADIX == 4
+# define FLT_MANT_BIT (FLT_MANT_DIG * 2)
+# define DBL_MANT_BIT (DBL_MANT_DIG * 2)
+# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2)
+#elif FLT_RADIX == 16
+# define FLT_MANT_BIT (FLT_MANT_DIG * 4)
+# define DBL_MANT_BIT (DBL_MANT_DIG * 4)
+# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4)
+#endif
+
+/* Bit mask that can be used to mask the exponent, as an unsigned number. */
+#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7)
+#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
+#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7)
+
+/* Number of bits used for the exponent of a floating-point number, including
+ the exponent's sign. */
+#define FLT_EXP_BIT \
+ (FLT_EXP_MASK < 0x100 ? 8 : \
+ FLT_EXP_MASK < 0x200 ? 9 : \
+ FLT_EXP_MASK < 0x400 ? 10 : \
+ FLT_EXP_MASK < 0x800 ? 11 : \
+ FLT_EXP_MASK < 0x1000 ? 12 : \
+ FLT_EXP_MASK < 0x2000 ? 13 : \
+ FLT_EXP_MASK < 0x4000 ? 14 : \
+ FLT_EXP_MASK < 0x8000 ? 15 : \
+ FLT_EXP_MASK < 0x10000 ? 16 : \
+ FLT_EXP_MASK < 0x20000 ? 17 : \
+ FLT_EXP_MASK < 0x40000 ? 18 : \
+ FLT_EXP_MASK < 0x80000 ? 19 : \
+ FLT_EXP_MASK < 0x100000 ? 20 : \
+ FLT_EXP_MASK < 0x200000 ? 21 : \
+ FLT_EXP_MASK < 0x400000 ? 22 : \
+ FLT_EXP_MASK < 0x800000 ? 23 : \
+ FLT_EXP_MASK < 0x1000000 ? 24 : \
+ FLT_EXP_MASK < 0x2000000 ? 25 : \
+ FLT_EXP_MASK < 0x4000000 ? 26 : \
+ FLT_EXP_MASK < 0x8000000 ? 27 : \
+ FLT_EXP_MASK < 0x10000000 ? 28 : \
+ FLT_EXP_MASK < 0x20000000 ? 29 : \
+ FLT_EXP_MASK < 0x40000000 ? 30 : \
+ FLT_EXP_MASK <= 0x7fffffff ? 31 : \
+ 32)
+#define DBL_EXP_BIT \
+ (DBL_EXP_MASK < 0x100 ? 8 : \
+ DBL_EXP_MASK < 0x200 ? 9 : \
+ DBL_EXP_MASK < 0x400 ? 10 : \
+ DBL_EXP_MASK < 0x800 ? 11 : \
+ DBL_EXP_MASK < 0x1000 ? 12 : \
+ DBL_EXP_MASK < 0x2000 ? 13 : \
+ DBL_EXP_MASK < 0x4000 ? 14 : \
+ DBL_EXP_MASK < 0x8000 ? 15 : \
+ DBL_EXP_MASK < 0x10000 ? 16 : \
+ DBL_EXP_MASK < 0x20000 ? 17 : \
+ DBL_EXP_MASK < 0x40000 ? 18 : \
+ DBL_EXP_MASK < 0x80000 ? 19 : \
+ DBL_EXP_MASK < 0x100000 ? 20 : \
+ DBL_EXP_MASK < 0x200000 ? 21 : \
+ DBL_EXP_MASK < 0x400000 ? 22 : \
+ DBL_EXP_MASK < 0x800000 ? 23 : \
+ DBL_EXP_MASK < 0x1000000 ? 24 : \
+ DBL_EXP_MASK < 0x2000000 ? 25 : \
+ DBL_EXP_MASK < 0x4000000 ? 26 : \
+ DBL_EXP_MASK < 0x8000000 ? 27 : \
+ DBL_EXP_MASK < 0x10000000 ? 28 : \
+ DBL_EXP_MASK < 0x20000000 ? 29 : \
+ DBL_EXP_MASK < 0x40000000 ? 30 : \
+ DBL_EXP_MASK <= 0x7fffffff ? 31 : \
+ 32)
+#define LDBL_EXP_BIT \
+ (LDBL_EXP_MASK < 0x100 ? 8 : \
+ LDBL_EXP_MASK < 0x200 ? 9 : \
+ LDBL_EXP_MASK < 0x400 ? 10 : \
+ LDBL_EXP_MASK < 0x800 ? 11 : \
+ LDBL_EXP_MASK < 0x1000 ? 12 : \
+ LDBL_EXP_MASK < 0x2000 ? 13 : \
+ LDBL_EXP_MASK < 0x4000 ? 14 : \
+ LDBL_EXP_MASK < 0x8000 ? 15 : \
+ LDBL_EXP_MASK < 0x10000 ? 16 : \
+ LDBL_EXP_MASK < 0x20000 ? 17 : \
+ LDBL_EXP_MASK < 0x40000 ? 18 : \
+ LDBL_EXP_MASK < 0x80000 ? 19 : \
+ LDBL_EXP_MASK < 0x100000 ? 20 : \
+ LDBL_EXP_MASK < 0x200000 ? 21 : \
+ LDBL_EXP_MASK < 0x400000 ? 22 : \
+ LDBL_EXP_MASK < 0x800000 ? 23 : \
+ LDBL_EXP_MASK < 0x1000000 ? 24 : \
+ LDBL_EXP_MASK < 0x2000000 ? 25 : \
+ LDBL_EXP_MASK < 0x4000000 ? 26 : \
+ LDBL_EXP_MASK < 0x8000000 ? 27 : \
+ LDBL_EXP_MASK < 0x10000000 ? 28 : \
+ LDBL_EXP_MASK < 0x20000000 ? 29 : \
+ LDBL_EXP_MASK < 0x40000000 ? 30 : \
+ LDBL_EXP_MASK <= 0x7fffffff ? 31 : \
+ 32)
+
+/* Number of bits used for a floating-point number: the mantissa (not
+ counting the "hidden bit", since it may or may not be explicit), the
+ exponent, and the sign. */
+#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1)
+#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1)
+#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1)
+
+/* Number of bytes used for a floating-point number.
+ This can be smaller than the 'sizeof'. For example, on i386 systems,
+ 'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence
+ LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but
+ sizeof (long double) = 12 or = 16. */
+#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
+#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
+#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
+
+/* Verify that SIZEOF_FLT <= sizeof (float) etc. */
+typedef int verify_sizeof_flt[SIZEOF_FLT <= sizeof (float) ? 1 : -1];
+typedef int verify_sizeof_dbl[SIZEOF_DBL <= sizeof (double) ? 1 : - 1];
+typedef int verify_sizeof_ldbl[SIZEOF_LDBL <= sizeof (long double) ? 1 : - 1];
+
+#endif /* _FLOATPLUS_H */
diff --git a/contrib/tools/bison/gnulib/src/float.c b/contrib/tools/bison/gnulib/src/float.c
index 366945fa38..8fa1ee9432 100644
--- a/contrib/tools/bison/gnulib/src/float.c
+++ b/contrib/tools/bison/gnulib/src/float.c
@@ -1,33 +1,33 @@
-/* Auxiliary definitions for <float.h>.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2011.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <float.h>
-
-#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
-const union gl_long_double_union gl_LDBL_MAX =
- { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } };
-#elif defined __i386__
-const union gl_long_double_union gl_LDBL_MAX =
- { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } };
-#else
-/* This declaration is solely to ensure that after preprocessing
- this file is never empty. */
-typedef int dummy;
-#endif
+/* Auxiliary definitions for <float.h>.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <float.h>
+
+#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
+const union gl_long_double_union gl_LDBL_MAX =
+ { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } };
+#elif defined __i386__
+const union gl_long_double_union gl_LDBL_MAX =
+ { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } };
+#else
+/* This declaration is solely to ensure that after preprocessing
+ this file is never empty. */
+typedef int dummy;
+#endif
diff --git a/contrib/tools/bison/gnulib/src/fopen-safer.c b/contrib/tools/bison/gnulib/src/fopen-safer.c
index 917920d904..2ebe252571 100644
--- a/contrib/tools/bison/gnulib/src/fopen-safer.c
+++ b/contrib/tools/bison/gnulib/src/fopen-safer.c
@@ -1,63 +1,63 @@
-/* Invoke fopen, but avoid some glitches.
-
- Copyright (C) 2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <config.h>
-
-#include "stdio-safer.h"
-
-#include <errno.h>
-#include <unistd.h>
-#include "unistd-safer.h"
-
-/* Like fopen, but do not return stdin, stdout, or stderr. */
-
-FILE *
-fopen_safer (char const *file, char const *mode)
-{
- FILE *fp = fopen (file, mode);
-
- if (fp)
- {
- int fd = fileno (fp);
-
- if (0 <= fd && fd <= STDERR_FILENO)
- {
- int f = dup_safer (fd);
-
- if (f < 0)
- {
- int e = errno;
- fclose (fp);
- errno = e;
- return NULL;
- }
-
- if (fclose (fp) != 0
- || ! (fp = fdopen (f, mode)))
- {
- int e = errno;
- close (f);
- errno = e;
- return NULL;
- }
- }
- }
-
- return fp;
-}
+/* Invoke fopen, but avoid some glitches.
+
+ Copyright (C) 2001, 2004-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <config.h>
+
+#include "stdio-safer.h"
+
+#include <errno.h>
+#include <unistd.h>
+#include "unistd-safer.h"
+
+/* Like fopen, but do not return stdin, stdout, or stderr. */
+
+FILE *
+fopen_safer (char const *file, char const *mode)
+{
+ FILE *fp = fopen (file, mode);
+
+ if (fp)
+ {
+ int fd = fileno (fp);
+
+ if (0 <= fd && fd <= STDERR_FILENO)
+ {
+ int f = dup_safer (fd);
+
+ if (f < 0)
+ {
+ int e = errno;
+ fclose (fp);
+ errno = e;
+ return NULL;
+ }
+
+ if (fclose (fp) != 0
+ || ! (fp = fdopen (f, mode)))
+ {
+ int e = errno;
+ close (f);
+ errno = e;
+ return NULL;
+ }
+ }
+ }
+
+ return fp;
+}
diff --git a/contrib/tools/bison/gnulib/src/fopen.c b/contrib/tools/bison/gnulib/src/fopen.c
index f9d6763d21..46197b35b9 100644
--- a/contrib/tools/bison/gnulib/src/fopen.c
+++ b/contrib/tools/bison/gnulib/src/fopen.c
@@ -1,110 +1,110 @@
-/* Open a stream to a file.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
-
-/* If the user's config.h happens to include <stdio.h>, let it include only
- the system's <stdio.h> here, so that orig_fopen doesn't recurse to
- rpl_fopen. */
-#define __need_FILE
-#include <config.h>
-
-/* Get the original definition of fopen. It might be defined as a macro. */
-#include <stdio.h>
-#undef __need_FILE
-
-static FILE *
-orig_fopen (const char *filename, const char *mode)
-{
- return fopen (filename, mode);
-}
-
-/* Specification. */
-/* Write "stdio.h" here, not <stdio.h>, otherwise OSF/1 5.1 DTK cc eliminates
- this include because of the preliminary #include <stdio.h> above. */
-#include "stdio.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-FILE *
-rpl_fopen (const char *filename, const char *mode)
-{
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- if (strcmp (filename, "/dev/null") == 0)
- filename = "NUL";
-#endif
-
-#if FOPEN_TRAILING_SLASH_BUG
- /* If the filename ends in a slash and a mode that requires write access is
- specified, then fail.
- Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
- says that
- "A pathname that contains at least one non-slash character and that
- ends with one or more trailing slashes shall be resolved as if a
- single dot character ( '.' ) were appended to the pathname."
- and
- "The special filename dot shall refer to the directory specified by
- its predecessor."
- If the named file already exists as a directory, then if a mode that
- requires write access is specified, fopen() must fail because POSIX
- <http://www.opengroup.org/susv3/functions/fopen.html> says that it
- fails with errno = EISDIR in this case.
- If the named file does not exist or does not name a directory, then
- fopen() must fail since the file does not contain a '.' directory. */
- {
- size_t len = strlen (filename);
- if (len > 0 && filename[len - 1] == '/')
- {
- int fd;
- struct stat statbuf;
- FILE *fp;
-
- if (mode[0] == 'w' || mode[0] == 'a')
- {
- errno = EISDIR;
- return NULL;
- }
-
- fd = open (filename, O_RDONLY);
- if (fd < 0)
- return NULL;
-
- if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
- {
- close (fd);
- errno = ENOTDIR;
- return NULL;
- }
-
- fp = fdopen (fd, mode);
- if (fp == NULL)
- {
- int saved_errno = errno;
- close (fd);
- errno = saved_errno;
- }
- return fp;
- }
- }
-# endif
-
- return orig_fopen (filename, mode);
-}
+/* Open a stream to a file.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
+
+/* If the user's config.h happens to include <stdio.h>, let it include only
+ the system's <stdio.h> here, so that orig_fopen doesn't recurse to
+ rpl_fopen. */
+#define __need_FILE
+#include <config.h>
+
+/* Get the original definition of fopen. It might be defined as a macro. */
+#include <stdio.h>
+#undef __need_FILE
+
+static FILE *
+orig_fopen (const char *filename, const char *mode)
+{
+ return fopen (filename, mode);
+}
+
+/* Specification. */
+/* Write "stdio.h" here, not <stdio.h>, otherwise OSF/1 5.1 DTK cc eliminates
+ this include because of the preliminary #include <stdio.h> above. */
+#include "stdio.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+FILE *
+rpl_fopen (const char *filename, const char *mode)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ if (strcmp (filename, "/dev/null") == 0)
+ filename = "NUL";
+#endif
+
+#if FOPEN_TRAILING_SLASH_BUG
+ /* If the filename ends in a slash and a mode that requires write access is
+ specified, then fail.
+ Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
+ says that
+ "A pathname that contains at least one non-slash character and that
+ ends with one or more trailing slashes shall be resolved as if a
+ single dot character ( '.' ) were appended to the pathname."
+ and
+ "The special filename dot shall refer to the directory specified by
+ its predecessor."
+ If the named file already exists as a directory, then if a mode that
+ requires write access is specified, fopen() must fail because POSIX
+ <http://www.opengroup.org/susv3/functions/fopen.html> says that it
+ fails with errno = EISDIR in this case.
+ If the named file does not exist or does not name a directory, then
+ fopen() must fail since the file does not contain a '.' directory. */
+ {
+ size_t len = strlen (filename);
+ if (len > 0 && filename[len - 1] == '/')
+ {
+ int fd;
+ struct stat statbuf;
+ FILE *fp;
+
+ if (mode[0] == 'w' || mode[0] == 'a')
+ {
+ errno = EISDIR;
+ return NULL;
+ }
+
+ fd = open (filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
+ {
+ close (fd);
+ errno = ENOTDIR;
+ return NULL;
+ }
+
+ fp = fdopen (fd, mode);
+ if (fp == NULL)
+ {
+ int saved_errno = errno;
+ close (fd);
+ errno = saved_errno;
+ }
+ return fp;
+ }
+ }
+# endif
+
+ return orig_fopen (filename, mode);
+}
diff --git a/contrib/tools/bison/gnulib/src/fpending.c b/contrib/tools/bison/gnulib/src/fpending.c
index 1bc4568923..7cf4251968 100644
--- a/contrib/tools/bison/gnulib/src/fpending.c
+++ b/contrib/tools/bison/gnulib/src/fpending.c
@@ -1,34 +1,34 @@
-/* fpending.c -- return the number of pending output bytes on a stream
- Copyright (C) 2000, 2004, 2006-2007, 2009-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#include <config.h>
-
-#include "fpending.h"
-
-/* Return the number of pending (aka buffered, unflushed)
- bytes on the stream, FP, that is open for writing. */
-size_t
-__fpending (FILE *fp)
-{
+/* fpending.c -- return the number of pending output bytes on a stream
+ Copyright (C) 2000, 2004, 2006-2007, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#include <config.h>
+
+#include "fpending.h"
+
+/* Return the number of pending (aka buffered, unflushed)
+ bytes on the stream, FP, that is open for writing. */
+size_t
+__fpending (FILE *fp)
+{
#if defined(PENDING_OUTPUT_N_BYTES)
- return PENDING_OUTPUT_N_BYTES;
+ return PENDING_OUTPUT_N_BYTES;
#endif
return 0;
-}
+}
diff --git a/contrib/tools/bison/gnulib/src/fpending.h b/contrib/tools/bison/gnulib/src/fpending.h
index 4eca3f18e1..1a48d2f322 100644
--- a/contrib/tools/bison/gnulib/src/fpending.h
+++ b/contrib/tools/bison/gnulib/src/fpending.h
@@ -1,29 +1,29 @@
-/* Declare __fpending.
-
- Copyright (C) 2000, 2003, 2005-2006, 2009-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- Written by Jim Meyering. */
-
-#include <stddef.h>
-#include <stdio.h>
-#if HAVE_STDIO_EXT_H
-# include <stdio_ext.h>
-#endif
-
-#ifndef __fpending
-size_t __fpending (FILE *);
-#endif
+/* Declare __fpending.
+
+ Copyright (C) 2000, 2003, 2005-2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Written by Jim Meyering. */
+
+#include <stddef.h>
+#include <stdio.h>
+#if HAVE_STDIO_EXT_H
+# include <stdio_ext.h>
+#endif
+
+#ifndef __fpending
+size_t __fpending (FILE *);
+#endif
diff --git a/contrib/tools/bison/gnulib/src/fprintf.c b/contrib/tools/bison/gnulib/src/fprintf.c
index 450d7f1ea8..1d70c9376c 100644
--- a/contrib/tools/bison/gnulib/src/fprintf.c
+++ b/contrib/tools/bison/gnulib/src/fprintf.c
@@ -1,77 +1,77 @@
-/* Formatted output to a stream.
- Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if 1
-# include <config.h>
-#endif
-
-/* Specification. */
-#include <stdio.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
-#include "fseterr.h"
-#include "vasnprintf.h"
-
-/* Print formatted output to the stream FP.
- Return string length of formatted string. On error, return a negative
- value. */
-int
-fprintf (FILE *fp, const char *format, ...)
-{
- char buf[2000];
- char *output;
- size_t len;
- size_t lenbuf = sizeof (buf);
- va_list args;
-
- va_start (args, format);
- output = vasnprintf (buf, &lenbuf, format, args);
- len = lenbuf;
- va_end (args);
-
- if (!output)
- {
- fseterr (fp);
- return -1;
- }
-
- if (fwrite (output, 1, len, fp) < len)
- {
- if (output != buf)
- {
- int saved_errno = errno;
- free (output);
- errno = saved_errno;
- }
- return -1;
- }
-
- if (output != buf)
- free (output);
-
- if (len > INT_MAX)
- {
- errno = EOVERFLOW;
- fseterr (fp);
- return -1;
- }
-
- return len;
-}
+/* Formatted output to a stream.
+ Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if 1
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "fseterr.h"
+#include "vasnprintf.h"
+
+/* Print formatted output to the stream FP.
+ Return string length of formatted string. On error, return a negative
+ value. */
+int
+fprintf (FILE *fp, const char *format, ...)
+{
+ char buf[2000];
+ char *output;
+ size_t len;
+ size_t lenbuf = sizeof (buf);
+ va_list args;
+
+ va_start (args, format);
+ output = vasnprintf (buf, &lenbuf, format, args);
+ len = lenbuf;
+ va_end (args);
+
+ if (!output)
+ {
+ fseterr (fp);
+ return -1;
+ }
+
+ if (fwrite (output, 1, len, fp) < len)
+ {
+ if (output != buf)
+ {
+ int saved_errno = errno;
+ free (output);
+ errno = saved_errno;
+ }
+ return -1;
+ }
+
+ if (output != buf)
+ free (output);
+
+ if (len > INT_MAX)
+ {
+ errno = EOVERFLOW;
+ fseterr (fp);
+ return -1;
+ }
+
+ return len;
+}
diff --git a/contrib/tools/bison/gnulib/src/fpucw.h b/contrib/tools/bison/gnulib/src/fpucw.h
index 0b7f5284a1..35e7e65285 100644
--- a/contrib/tools/bison/gnulib/src/fpucw.h
+++ b/contrib/tools/bison/gnulib/src/fpucw.h
@@ -1,108 +1,108 @@
-/* Manipulating the FPU control word.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2007.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _FPUCW_H
-#define _FPUCW_H
-
-/* The i386 floating point hardware (the 387 compatible FPU, not the modern
- SSE/SSE2 hardware) has a controllable rounding precision. It is specified
- through the 'PC' bits in the FPU control word ('fctrl' register). (See
- the GNU libc i386 <fpu_control.h> header for details.)
-
- On some platforms, such as Linux or Solaris, the default precision setting
- is set to "extended precision". This means that 'long double' instructions
- operate correctly, but 'double' computations often produce slightly
- different results as on strictly IEEE 754 conforming systems.
-
- On some platforms, such as NetBSD, the default precision is set to
- "double precision". This means that 'long double' instructions will operate
- only as 'double', i.e. lead to wrong results. Similarly on FreeBSD 6.4, at
- least for the division of 'long double' numbers.
-
- The FPU control word is under control of the application, i.e. it is
- not required to be set either way by the ABI. (In fact, the i386 ABI
- http://refspecs.freestandards.org/elf/abi386-4.pdf page 3-12 = page 38
- is not clear about it. But in any case, gcc treats the control word
- like a "preserved" register: it emits code that assumes that the control
- word is preserved across calls, and it restores the control word at the
- end of functions that modify it.)
-
- See Vincent Lefèvre's page http://www.vinc17.org/research/extended.en.html
- for a good explanation.
- See http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.0/0453.html for
- some argumentation which setting should be the default. */
-
-/* This header file provides the following facilities:
- fpucw_t integral type holding the value of 'fctrl'
- FPU_PC_MASK bit mask denoting the precision control
- FPU_PC_DOUBLE precision control for 53 bits mantissa
- FPU_PC_EXTENDED precision control for 64 bits mantissa
- GET_FPUCW () yields the current FPU control word
- SET_FPUCW (word) sets the FPU control word
- DECL_LONG_DOUBLE_ROUNDING variable declaration for
- BEGIN/END_LONG_DOUBLE_ROUNDING
- BEGIN_LONG_DOUBLE_ROUNDING () starts a sequence of instructions with
- 'long double' safe operation precision
- END_LONG_DOUBLE_ROUNDING () ends a sequence of instructions with
- 'long double' safe operation precision
- */
-
-/* Inline assembler like this works only with GNU C. */
-#if (defined __i386__ || defined __x86_64__) && defined __GNUC__
-
-typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */
-
-# define FPU_PC_MASK 0x0300
-# define FPU_PC_DOUBLE 0x200 /* glibc calls this _FPU_DOUBLE */
-# define FPU_PC_EXTENDED 0x300 /* glibc calls this _FPU_EXTENDED */
-
-# define GET_FPUCW() \
- ({ fpucw_t _cw; \
- __asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \
- _cw; \
- })
-# define SET_FPUCW(word) \
- (void)({ fpucw_t _ncw = (word); \
- __asm__ __volatile__ ("fldcw %0" : : "m" (*&_ncw)); \
- })
-
-# define DECL_LONG_DOUBLE_ROUNDING \
- fpucw_t oldcw;
-# define BEGIN_LONG_DOUBLE_ROUNDING() \
- (void)(oldcw = GET_FPUCW (), \
- SET_FPUCW ((oldcw & ~FPU_PC_MASK) | FPU_PC_EXTENDED))
-# define END_LONG_DOUBLE_ROUNDING() \
- SET_FPUCW (oldcw)
-
-#else
-
-typedef unsigned int fpucw_t;
-
-# define FPU_PC_MASK 0
-# define FPU_PC_DOUBLE 0
-# define FPU_PC_EXTENDED 0
-
-# define GET_FPUCW() 0
-# define SET_FPUCW(word) (void)(word)
-
-# define DECL_LONG_DOUBLE_ROUNDING
-# define BEGIN_LONG_DOUBLE_ROUNDING()
-# define END_LONG_DOUBLE_ROUNDING()
-
-#endif
-
-#endif /* _FPUCW_H */
+/* Manipulating the FPU control word.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2007.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _FPUCW_H
+#define _FPUCW_H
+
+/* The i386 floating point hardware (the 387 compatible FPU, not the modern
+ SSE/SSE2 hardware) has a controllable rounding precision. It is specified
+ through the 'PC' bits in the FPU control word ('fctrl' register). (See
+ the GNU libc i386 <fpu_control.h> header for details.)
+
+ On some platforms, such as Linux or Solaris, the default precision setting
+ is set to "extended precision". This means that 'long double' instructions
+ operate correctly, but 'double' computations often produce slightly
+ different results as on strictly IEEE 754 conforming systems.
+
+ On some platforms, such as NetBSD, the default precision is set to
+ "double precision". This means that 'long double' instructions will operate
+ only as 'double', i.e. lead to wrong results. Similarly on FreeBSD 6.4, at
+ least for the division of 'long double' numbers.
+
+ The FPU control word is under control of the application, i.e. it is
+ not required to be set either way by the ABI. (In fact, the i386 ABI
+ http://refspecs.freestandards.org/elf/abi386-4.pdf page 3-12 = page 38
+ is not clear about it. But in any case, gcc treats the control word
+ like a "preserved" register: it emits code that assumes that the control
+ word is preserved across calls, and it restores the control word at the
+ end of functions that modify it.)
+
+ See Vincent Lefèvre's page http://www.vinc17.org/research/extended.en.html
+ for a good explanation.
+ See http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.0/0453.html for
+ some argumentation which setting should be the default. */
+
+/* This header file provides the following facilities:
+ fpucw_t integral type holding the value of 'fctrl'
+ FPU_PC_MASK bit mask denoting the precision control
+ FPU_PC_DOUBLE precision control for 53 bits mantissa
+ FPU_PC_EXTENDED precision control for 64 bits mantissa
+ GET_FPUCW () yields the current FPU control word
+ SET_FPUCW (word) sets the FPU control word
+ DECL_LONG_DOUBLE_ROUNDING variable declaration for
+ BEGIN/END_LONG_DOUBLE_ROUNDING
+ BEGIN_LONG_DOUBLE_ROUNDING () starts a sequence of instructions with
+ 'long double' safe operation precision
+ END_LONG_DOUBLE_ROUNDING () ends a sequence of instructions with
+ 'long double' safe operation precision
+ */
+
+/* Inline assembler like this works only with GNU C. */
+#if (defined __i386__ || defined __x86_64__) && defined __GNUC__
+
+typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */
+
+# define FPU_PC_MASK 0x0300
+# define FPU_PC_DOUBLE 0x200 /* glibc calls this _FPU_DOUBLE */
+# define FPU_PC_EXTENDED 0x300 /* glibc calls this _FPU_EXTENDED */
+
+# define GET_FPUCW() \
+ ({ fpucw_t _cw; \
+ __asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \
+ _cw; \
+ })
+# define SET_FPUCW(word) \
+ (void)({ fpucw_t _ncw = (word); \
+ __asm__ __volatile__ ("fldcw %0" : : "m" (*&_ncw)); \
+ })
+
+# define DECL_LONG_DOUBLE_ROUNDING \
+ fpucw_t oldcw;
+# define BEGIN_LONG_DOUBLE_ROUNDING() \
+ (void)(oldcw = GET_FPUCW (), \
+ SET_FPUCW ((oldcw & ~FPU_PC_MASK) | FPU_PC_EXTENDED))
+# define END_LONG_DOUBLE_ROUNDING() \
+ SET_FPUCW (oldcw)
+
+#else
+
+typedef unsigned int fpucw_t;
+
+# define FPU_PC_MASK 0
+# define FPU_PC_DOUBLE 0
+# define FPU_PC_EXTENDED 0
+
+# define GET_FPUCW() 0
+# define SET_FPUCW(word) (void)(word)
+
+# define DECL_LONG_DOUBLE_ROUNDING
+# define BEGIN_LONG_DOUBLE_ROUNDING()
+# define END_LONG_DOUBLE_ROUNDING()
+
+#endif
+
+#endif /* _FPUCW_H */
diff --git a/contrib/tools/bison/gnulib/src/fpurge.c b/contrib/tools/bison/gnulib/src/fpurge.c
index 6c74355b71..4323874803 100644
--- a/contrib/tools/bison/gnulib/src/fpurge.c
+++ b/contrib/tools/bison/gnulib/src/fpurge.c
@@ -1,150 +1,150 @@
-/* Flushing buffers of a FILE stream.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */
-# include <stdio_ext.h>
-#endif
-#include <stdlib.h>
-
-#include "stdio-impl.h"
-
-int
-fpurge (FILE *fp)
-{
-#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, musl libc */
-
- __fpurge (fp);
- /* The __fpurge function does not have a return value. */
- return 0;
-
-#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin 1.7 */
-
- /* Call the system's fpurge function. */
-# undef fpurge
-# if !HAVE_DECL_FPURGE
- extern int fpurge (FILE *);
-# endif
- int result = fpurge (fp);
-# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
- if (result == 0)
- /* Correct the invariants that fpurge broke.
- <stdio.h> on BSD systems says:
- "The following always hold: if _flags & __SRD, _w is 0."
- If this invariant is not fulfilled and the stream is read-write but
- currently reading, subsequent putc or fputc calls will write directly
- into the buffer, although they shouldn't be allowed to. */
- if ((fp_->_flags & __SRD) != 0)
- fp_->_w = 0;
-# endif
- return result;
-
-#else
-
- /* Most systems provide FILE as a struct and the necessary bitmask in
- <stdio.h>, because they need it for implementing getc() and putc() as
- fast macros. */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
- fp->_IO_read_end = fp->_IO_read_ptr;
- fp->_IO_write_ptr = fp->_IO_write_base;
- /* Avoid memory leak when there is an active ungetc buffer. */
- if (fp->_IO_save_base != NULL)
- {
- free (fp->_IO_save_base);
- fp->_IO_save_base = NULL;
- }
- return 0;
-# elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
- fp_->_p = fp_->_bf._base;
- fp_->_r = 0;
- fp_->_w = ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
- ? fp_->_bf._size
- : 0);
- /* Avoid memory leak when there is an active ungetc buffer. */
- if (fp_ub._base != NULL)
- {
- if (fp_ub._base != fp_->_ubuf)
- free (fp_ub._base);
- fp_ub._base = NULL;
- }
- return 0;
-# elif defined __EMX__ /* emx+gcc */
- fp->_ptr = fp->_buffer;
- fp->_rcount = 0;
- fp->_wcount = 0;
- fp->_ungetc_count = 0;
- return 0;
-# elif defined __minix /* Minix */
- fp->_ptr = fp->_buf;
- if (fp->_ptr != NULL)
- fp->_count = 0;
- return 0;
-# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
- fp->_ptr = fp->_base;
- if (fp->_ptr != NULL)
- fp->_cnt = 0;
- return 0;
+/* Flushing buffers of a FILE stream.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */
+# include <stdio_ext.h>
+#endif
+#include <stdlib.h>
+
+#include "stdio-impl.h"
+
+int
+fpurge (FILE *fp)
+{
+#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, musl libc */
+
+ __fpurge (fp);
+ /* The __fpurge function does not have a return value. */
+ return 0;
+
+#elif HAVE_FPURGE /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin 1.7 */
+
+ /* Call the system's fpurge function. */
+# undef fpurge
+# if !HAVE_DECL_FPURGE
+ extern int fpurge (FILE *);
+# endif
+ int result = fpurge (fp);
+# if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+ if (result == 0)
+ /* Correct the invariants that fpurge broke.
+ <stdio.h> on BSD systems says:
+ "The following always hold: if _flags & __SRD, _w is 0."
+ If this invariant is not fulfilled and the stream is read-write but
+ currently reading, subsequent putc or fputc calls will write directly
+ into the buffer, although they shouldn't be allowed to. */
+ if ((fp_->_flags & __SRD) != 0)
+ fp_->_w = 0;
+# endif
+ return result;
+
+#else
+
+ /* Most systems provide FILE as a struct and the necessary bitmask in
+ <stdio.h>, because they need it for implementing getc() and putc() as
+ fast macros. */
+# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+ fp->_IO_read_end = fp->_IO_read_ptr;
+ fp->_IO_write_ptr = fp->_IO_write_base;
+ /* Avoid memory leak when there is an active ungetc buffer. */
+ if (fp->_IO_save_base != NULL)
+ {
+ free (fp->_IO_save_base);
+ fp->_IO_save_base = NULL;
+ }
+ return 0;
+# elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+ fp_->_p = fp_->_bf._base;
+ fp_->_r = 0;
+ fp_->_w = ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
+ ? fp_->_bf._size
+ : 0);
+ /* Avoid memory leak when there is an active ungetc buffer. */
+ if (fp_ub._base != NULL)
+ {
+ if (fp_ub._base != fp_->_ubuf)
+ free (fp_ub._base);
+ fp_ub._base = NULL;
+ }
+ return 0;
+# elif defined __EMX__ /* emx+gcc */
+ fp->_ptr = fp->_buffer;
+ fp->_rcount = 0;
+ fp->_wcount = 0;
+ fp->_ungetc_count = 0;
+ return 0;
+# elif defined __minix /* Minix */
+ fp->_ptr = fp->_buf;
+ if (fp->_ptr != NULL)
+ fp->_count = 0;
+ return 0;
+# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
+ fp->_ptr = fp->_base;
+ if (fp->_ptr != NULL)
+ fp->_cnt = 0;
+ return 0;
# elif WIN_SDK10
((TWinSdk10File*)fp)->_ptr = ((TWinSdk10File*)fp)->_base;
if (((TWinSdk10File*)fp)->_ptr != NULL)
((TWinSdk10File*)fp)->_cnt = 0;
return 0;
-# elif defined __UCLIBC__ /* uClibc */
-# ifdef __STDIO_BUFFERS
- if (fp->__modeflags & __FLAG_WRITING)
- fp->__bufpos = fp->__bufstart;
- else if (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING))
- fp->__bufpos = fp->__bufread;
-# endif
- return 0;
-# elif defined __QNX__ /* QNX */
- fp->_Rback = fp->_Back + sizeof (fp->_Back);
- fp->_Rsave = NULL;
- if (fp->_Mode & 0x2000 /* _MWRITE */)
- /* fp->_Buf <= fp->_Next <= fp->_Wend */
- fp->_Next = fp->_Buf;
- else
- /* fp->_Buf <= fp->_Next <= fp->_Rend */
- fp->_Rend = fp->_Next;
- return 0;
-# elif defined __MINT__ /* Atari FreeMiNT */
- if (fp->__pushed_back)
- {
- fp->__bufp = fp->__pushback_bufp;
- fp->__pushed_back = 0;
- }
- /* Preserve the current file position. */
- if (fp->__target != -1)
- fp->__target += fp->__bufp - fp->__buffer;
- fp->__bufp = fp->__buffer;
- /* Nothing in the buffer, next getc is nontrivial. */
- fp->__get_limit = fp->__bufp;
- /* Nothing in the buffer, next putc is nontrivial. */
- fp->__put_limit = fp->__buffer;
- return 0;
-# elif defined EPLAN9 /* Plan9 */
- fp->rp = fp->wp = fp->lp = fp->buf;
- return 0;
-# else
-# error "Please port gnulib fpurge.c to your platform! Look at the definitions of fflush, setvbuf and ungetc on your system, then report this to bug-gnulib."
-# endif
-
-#endif
-}
+# elif defined __UCLIBC__ /* uClibc */
+# ifdef __STDIO_BUFFERS
+ if (fp->__modeflags & __FLAG_WRITING)
+ fp->__bufpos = fp->__bufstart;
+ else if (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING))
+ fp->__bufpos = fp->__bufread;
+# endif
+ return 0;
+# elif defined __QNX__ /* QNX */
+ fp->_Rback = fp->_Back + sizeof (fp->_Back);
+ fp->_Rsave = NULL;
+ if (fp->_Mode & 0x2000 /* _MWRITE */)
+ /* fp->_Buf <= fp->_Next <= fp->_Wend */
+ fp->_Next = fp->_Buf;
+ else
+ /* fp->_Buf <= fp->_Next <= fp->_Rend */
+ fp->_Rend = fp->_Next;
+ return 0;
+# elif defined __MINT__ /* Atari FreeMiNT */
+ if (fp->__pushed_back)
+ {
+ fp->__bufp = fp->__pushback_bufp;
+ fp->__pushed_back = 0;
+ }
+ /* Preserve the current file position. */
+ if (fp->__target != -1)
+ fp->__target += fp->__bufp - fp->__buffer;
+ fp->__bufp = fp->__buffer;
+ /* Nothing in the buffer, next getc is nontrivial. */
+ fp->__get_limit = fp->__bufp;
+ /* Nothing in the buffer, next putc is nontrivial. */
+ fp->__put_limit = fp->__buffer;
+ return 0;
+# elif defined EPLAN9 /* Plan9 */
+ fp->rp = fp->wp = fp->lp = fp->buf;
+ return 0;
+# else
+# error "Please port gnulib fpurge.c to your platform! Look at the definitions of fflush, setvbuf and ungetc on your system, then report this to bug-gnulib."
+# endif
+
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/freadahead.c b/contrib/tools/bison/gnulib/src/freadahead.c
index bf53271fd2..1d16344d41 100644
--- a/contrib/tools/bison/gnulib/src/freadahead.c
+++ b/contrib/tools/bison/gnulib/src/freadahead.c
@@ -1,97 +1,97 @@
-/* Retrieve information about a FILE stream.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "freadahead.h"
-
-#include <stdlib.h>
-#include "stdio-impl.h"
-
-size_t
-freadahead (FILE *fp)
-{
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
- if (fp->_IO_write_ptr > fp->_IO_write_base)
- return 0;
- return (fp->_IO_read_end - fp->_IO_read_ptr)
- + (fp->_flags & _IO_IN_BACKUP ? fp->_IO_save_end - fp->_IO_save_base :
- 0);
-#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
- if ((fp_->_flags & __SWR) != 0 || fp_->_r < 0)
- return 0;
-# if defined __DragonFly__
- return __sreadahead (fp);
-# else
- return fp_->_r
- + (HASUB (fp) ? fp_->_ur : 0);
-# endif
-#elif defined __EMX__ /* emx+gcc */
- if ((fp->_flags & _IOWRT) != 0)
- return 0;
- /* Note: fp->_ungetc_count > 0 implies fp->_rcount <= 0,
- fp->_ungetc_count = 0 implies fp->_rcount >= 0. */
- /* equivalent to
- (fp->_ungetc_count == 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount) */
- return (fp->_rcount > 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount);
-#elif defined __minix /* Minix */
- if ((fp_->_flags & _IOWRITING) != 0)
- return 0;
- return fp_->_count;
-#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
- if ((fp_->_flag & _IOWRT) != 0)
- return 0;
- return fp_->_cnt;
+/* Retrieve information about a FILE stream.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "freadahead.h"
+
+#include <stdlib.h>
+#include "stdio-impl.h"
+
+size_t
+freadahead (FILE *fp)
+{
+#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+ if (fp->_IO_write_ptr > fp->_IO_write_base)
+ return 0;
+ return (fp->_IO_read_end - fp->_IO_read_ptr)
+ + (fp->_flags & _IO_IN_BACKUP ? fp->_IO_save_end - fp->_IO_save_base :
+ 0);
+#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+ if ((fp_->_flags & __SWR) != 0 || fp_->_r < 0)
+ return 0;
+# if defined __DragonFly__
+ return __sreadahead (fp);
+# else
+ return fp_->_r
+ + (HASUB (fp) ? fp_->_ur : 0);
+# endif
+#elif defined __EMX__ /* emx+gcc */
+ if ((fp->_flags & _IOWRT) != 0)
+ return 0;
+ /* Note: fp->_ungetc_count > 0 implies fp->_rcount <= 0,
+ fp->_ungetc_count = 0 implies fp->_rcount >= 0. */
+ /* equivalent to
+ (fp->_ungetc_count == 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount) */
+ return (fp->_rcount > 0 ? fp->_rcount : fp->_ungetc_count - fp->_rcount);
+#elif defined __minix /* Minix */
+ if ((fp_->_flags & _IOWRITING) != 0)
+ return 0;
+ return fp_->_count;
+#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
+ if ((fp_->_flag & _IOWRT) != 0)
+ return 0;
+ return fp_->_cnt;
#elif WIN_SDK10
if ((((TWinSdk10File*)fp)->_flags & WIN_SDK10_IOWRITE) != 0)
return 0;
return ((TWinSdk10File*)fp)->_cnt;
-#elif defined __UCLIBC__ /* uClibc */
-# ifdef __STDIO_BUFFERS
- if (fp->__modeflags & __FLAG_WRITING)
- return 0;
- return (fp->__bufread - fp->__bufpos)
- + (fp->__modeflags & __FLAG_UNGOT ? 1 : 0);
-# else
- return 0;
-# endif
-#elif defined __QNX__ /* QNX */
- if ((fp->_Mode & 0x2000 /* _MWRITE */) != 0)
- return 0;
- /* fp->_Buf <= fp->_Next <= fp->_Rend,
- and fp->_Rend may be overridden by fp->_Rsave. */
- return ((fp->_Rsave ? fp->_Rsave : fp->_Rend) - fp->_Next)
- + (fp->_Mode & 0x4000 /* _MBYTE */
- ? (fp->_Back + sizeof (fp->_Back)) - fp->_Rback
- : 0);
-#elif defined __MINT__ /* Atari FreeMiNT */
- if (!fp->__mode.__read)
- return 0;
- return (fp->__pushed_back
- ? fp->__get_limit - fp->__pushback_bufp + 1
- : fp->__get_limit - fp->__bufp);
-#elif defined EPLAN9 /* Plan9 */
- if (fp->state == 4 /* WR */ || fp->rp >= fp->wp)
- return 0;
- return fp->wp - fp->rp;
-#elif defined SLOW_BUT_NO_HACKS /* users can define this */
- abort ();
- return 0;
-#else
- #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib."
-#endif
-}
+#elif defined __UCLIBC__ /* uClibc */
+# ifdef __STDIO_BUFFERS
+ if (fp->__modeflags & __FLAG_WRITING)
+ return 0;
+ return (fp->__bufread - fp->__bufpos)
+ + (fp->__modeflags & __FLAG_UNGOT ? 1 : 0);
+# else
+ return 0;
+# endif
+#elif defined __QNX__ /* QNX */
+ if ((fp->_Mode & 0x2000 /* _MWRITE */) != 0)
+ return 0;
+ /* fp->_Buf <= fp->_Next <= fp->_Rend,
+ and fp->_Rend may be overridden by fp->_Rsave. */
+ return ((fp->_Rsave ? fp->_Rsave : fp->_Rend) - fp->_Next)
+ + (fp->_Mode & 0x4000 /* _MBYTE */
+ ? (fp->_Back + sizeof (fp->_Back)) - fp->_Rback
+ : 0);
+#elif defined __MINT__ /* Atari FreeMiNT */
+ if (!fp->__mode.__read)
+ return 0;
+ return (fp->__pushed_back
+ ? fp->__get_limit - fp->__pushback_bufp + 1
+ : fp->__get_limit - fp->__bufp);
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->state == 4 /* WR */ || fp->rp >= fp->wp)
+ return 0;
+ return fp->wp - fp->rp;
+#elif defined SLOW_BUT_NO_HACKS /* users can define this */
+ abort ();
+ return 0;
+#else
+ #error "Please port gnulib freadahead.c to your platform! Look at the definition of fflush, fread, ungetc on your system, then report this to bug-gnulib."
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/freadahead.h b/contrib/tools/bison/gnulib/src/freadahead.h
index c691f89c0f..7f23d35f16 100644
--- a/contrib/tools/bison/gnulib/src/freadahead.h
+++ b/contrib/tools/bison/gnulib/src/freadahead.h
@@ -1,47 +1,47 @@
-/* Retrieve information about a FILE stream.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <stddef.h>
-#include <stdio.h>
-
-/* Assuming the stream STREAM is open for reading:
- Return the number of bytes waiting in the input buffer of STREAM.
- This includes both the bytes that have been read from the underlying input
- source and the bytes that have been pushed back through 'ungetc'.
-
- If this number is 0 and the stream is not currently writing,
- fflush (STREAM) is known to be a no-op.
-
- STREAM must not be wide-character oriented. */
-
-#if HAVE___FREADAHEAD /* musl libc */
-
-# include <stdio_ext.h>
-# define freadahead(stream) __freadahead (stream)
-
-#else
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-extern size_t freadahead (FILE *stream) _GL_ATTRIBUTE_PURE;
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
+/* Retrieve information about a FILE stream.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+#include <stdio.h>
+
+/* Assuming the stream STREAM is open for reading:
+ Return the number of bytes waiting in the input buffer of STREAM.
+ This includes both the bytes that have been read from the underlying input
+ source and the bytes that have been pushed back through 'ungetc'.
+
+ If this number is 0 and the stream is not currently writing,
+ fflush (STREAM) is known to be a no-op.
+
+ STREAM must not be wide-character oriented. */
+
+#if HAVE___FREADAHEAD /* musl libc */
+
+# include <stdio_ext.h>
+# define freadahead(stream) __freadahead (stream)
+
+#else
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+extern size_t freadahead (FILE *stream) _GL_ATTRIBUTE_PURE;
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/freading.c b/contrib/tools/bison/gnulib/src/freading.c
index 3d7e4e56f0..27a8373cb3 100644
--- a/contrib/tools/bison/gnulib/src/freading.c
+++ b/contrib/tools/bison/gnulib/src/freading.c
@@ -1,76 +1,76 @@
-/* Retrieve information about a FILE stream.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "freading.h"
-
-#include "stdio-impl.h"
-
-/* Don't use glibc's __freading function in glibc < 2.7, see
- <http://sourceware.org/bugzilla/show_bug.cgi?id=4359> */
-#if !(HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)))
-
-bool
-freading (FILE *fp)
-{
- /* Most systems provide FILE as a struct and the necessary bitmask in
- <stdio.h>, because they need it for implementing getc() and putc() as
- fast macros. */
-# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
- return ((fp->_flags & _IO_NO_WRITES) != 0
- || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
- && fp->_IO_read_base != NULL));
-# elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
- return (fp_->_flags & __SRD) != 0;
-# elif defined __EMX__ /* emx+gcc */
- return (fp->_flags & _IOREAD) != 0;
-# elif defined __minix /* Minix */
- return (fp->_flags & _IOREADING) != 0;
-# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
-# if defined __sun /* Solaris */
- return (fp->_flag & _IOREAD) != 0 && (fp->_flag & _IOWRT) == 0;
-# else
- return (fp->_flag & _IOREAD) != 0;
-# endif
+/* Retrieve information about a FILE stream.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "freading.h"
+
+#include "stdio-impl.h"
+
+/* Don't use glibc's __freading function in glibc < 2.7, see
+ <http://sourceware.org/bugzilla/show_bug.cgi?id=4359> */
+#if !(HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)))
+
+bool
+freading (FILE *fp)
+{
+ /* Most systems provide FILE as a struct and the necessary bitmask in
+ <stdio.h>, because they need it for implementing getc() and putc() as
+ fast macros. */
+# if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+ return ((fp->_flags & _IO_NO_WRITES) != 0
+ || ((fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0
+ && fp->_IO_read_base != NULL));
+# elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+ return (fp_->_flags & __SRD) != 0;
+# elif defined __EMX__ /* emx+gcc */
+ return (fp->_flags & _IOREAD) != 0;
+# elif defined __minix /* Minix */
+ return (fp->_flags & _IOREADING) != 0;
+# elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
+# if defined __sun /* Solaris */
+ return (fp->_flag & _IOREAD) != 0 && (fp->_flag & _IOWRT) == 0;
+# else
+ return (fp->_flag & _IOREAD) != 0;
+# endif
# elif WIN_SDK10
return (((TWinSdk10File*)fp)->_flags & WIN_SDK10_IOREAD) != 0;
-# elif defined __UCLIBC__ /* uClibc */
- return (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) != 0;
-# elif defined __QNX__ /* QNX */
- return ((fp->_Mode & 0x2 /* _MOPENW */) == 0
- || (fp->_Mode & 0x1000 /* _MREAD */) != 0);
-# elif defined __MINT__ /* Atari FreeMiNT */
- if (!fp->__mode.__write)
- return 1;
- if (!fp->__mode.__read)
- return 0;
-# ifdef _IO_CURRENTLY_GETTING /* Flag added on 2009-02-28 */
- return (fp->__flags & _IO_CURRENTLY_GETTING) != 0;
-# else
- return (fp->__buffer < fp->__get_limit /*|| fp->__bufp == fp->__put_limit ??*/);
-# endif
-# elif defined EPLAN9 /* Plan9 */
- if (fp->state == 0 /* CLOSED */ || fp->state == 4 /* WR */)
- return 0;
- return (fp->state == 3 /* RD */ && (fp->bufl == 0 || fp->rp < fp->wp));
-# else
-# error "Please port gnulib freading.c to your platform!"
-# endif
-}
-
-#endif
+# elif defined __UCLIBC__ /* uClibc */
+ return (fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) != 0;
+# elif defined __QNX__ /* QNX */
+ return ((fp->_Mode & 0x2 /* _MOPENW */) == 0
+ || (fp->_Mode & 0x1000 /* _MREAD */) != 0);
+# elif defined __MINT__ /* Atari FreeMiNT */
+ if (!fp->__mode.__write)
+ return 1;
+ if (!fp->__mode.__read)
+ return 0;
+# ifdef _IO_CURRENTLY_GETTING /* Flag added on 2009-02-28 */
+ return (fp->__flags & _IO_CURRENTLY_GETTING) != 0;
+# else
+ return (fp->__buffer < fp->__get_limit /*|| fp->__bufp == fp->__put_limit ??*/);
+# endif
+# elif defined EPLAN9 /* Plan9 */
+ if (fp->state == 0 /* CLOSED */ || fp->state == 4 /* WR */)
+ return 0;
+ return (fp->state == 3 /* RD */ && (fp->bufl == 0 || fp->rp < fp->wp));
+# else
+# error "Please port gnulib freading.c to your platform!"
+# endif
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/freading.h b/contrib/tools/bison/gnulib/src/freading.h
index 88ea789ea4..4cfe7c907f 100644
--- a/contrib/tools/bison/gnulib/src/freading.h
+++ b/contrib/tools/bison/gnulib/src/freading.h
@@ -1,53 +1,53 @@
-/* Retrieve information about a FILE stream.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <stdbool.h>
-#include <stdio.h>
-
-/* Return true if the stream STREAM is opened read-only, or if the
- last operation on the stream was a read operation. Return false if
- the stream is opened write-only or append-only, or if it supports
- writing and there is no current read operation (such as fgetc).
-
- freading and fwriting will never both be true. If STREAM supports
- both reads and writes, then:
- - both freading and fwriting might be false when the stream is first
- opened, after read encounters EOF, or after fflush,
- - freading might be false or true and fwriting might be false
- after repositioning (such as fseek, fsetpos, or rewind),
- depending on the underlying implementation.
-
- STREAM must not be wide-character oriented. */
-
-#if HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
-/* Solaris >= 7, not glibc >= 2.2, but glibc >= 2.7, or musl libc */
-
-# include <stdio_ext.h>
-# define freading(stream) (__freading (stream) != 0)
-
-#else
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-extern bool freading (FILE *stream);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
+/* Retrieve information about a FILE stream.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdbool.h>
+#include <stdio.h>
+
+/* Return true if the stream STREAM is opened read-only, or if the
+ last operation on the stream was a read operation. Return false if
+ the stream is opened write-only or append-only, or if it supports
+ writing and there is no current read operation (such as fgetc).
+
+ freading and fwriting will never both be true. If STREAM supports
+ both reads and writes, then:
+ - both freading and fwriting might be false when the stream is first
+ opened, after read encounters EOF, or after fflush,
+ - freading might be false or true and fwriting might be false
+ after repositioning (such as fseek, fsetpos, or rewind),
+ depending on the underlying implementation.
+
+ STREAM must not be wide-character oriented. */
+
+#if HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
+/* Solaris >= 7, not glibc >= 2.2, but glibc >= 2.7, or musl libc */
+
+# include <stdio_ext.h>
+# define freading(stream) (__freading (stream) != 0)
+
+#else
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+extern bool freading (FILE *stream);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/frexp.c b/contrib/tools/bison/gnulib/src/frexp.c
index d847fa38b3..d19deab85b 100644
--- a/contrib/tools/bison/gnulib/src/frexp.c
+++ b/contrib/tools/bison/gnulib/src/frexp.c
@@ -1,168 +1,168 @@
-/* Split a double into fraction and mantissa.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paolo Bonzini <bonzini@gnu.org>, 2003, and
- Bruno Haible <bruno@clisp.org>, 2007. */
-
-#if ! defined USE_LONG_DOUBLE
-# include <config.h>
-#endif
-
-/* Specification. */
-#include <math.h>
-
-#include <float.h>
-#ifdef USE_LONG_DOUBLE
-# include "isnanl-nolibm.h"
-# include "fpucw.h"
-#else
-# include "isnand-nolibm.h"
-#endif
-
-/* This file assumes FLT_RADIX = 2. If FLT_RADIX is a power of 2 greater
- than 2, or not even a power of 2, some rounding errors can occur, so that
- then the returned mantissa is only guaranteed to be <= 1.0, not < 1.0. */
-
-#ifdef USE_LONG_DOUBLE
-# define FUNC frexpl
-# define DOUBLE long double
-# define ISNAN isnanl
-# define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING
-# define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING ()
-# define END_ROUNDING() END_LONG_DOUBLE_ROUNDING ()
-# define L_(literal) literal##L
-#else
-# define FUNC frexp
-# define DOUBLE double
-# define ISNAN isnand
-# define DECL_ROUNDING
-# define BEGIN_ROUNDING()
-# define END_ROUNDING()
-# define L_(literal) literal
-#endif
-
-DOUBLE
-FUNC (DOUBLE x, int *expptr)
-{
- int sign;
- int exponent;
- DECL_ROUNDING
-
- /* Test for NaN, infinity, and zero. */
- if (ISNAN (x) || x + x == x)
- {
- *expptr = 0;
- return x;
- }
-
- sign = 0;
- if (x < 0)
- {
- x = - x;
- sign = -1;
- }
-
- BEGIN_ROUNDING ();
-
- {
- /* Since the exponent is an 'int', it fits in 64 bits. Therefore the
- loops are executed no more than 64 times. */
- DOUBLE pow2[64]; /* pow2[i] = 2^2^i */
- DOUBLE powh[64]; /* powh[i] = 2^-2^i */
- int i;
-
- exponent = 0;
- if (x >= L_(1.0))
- {
- /* A positive exponent. */
- DOUBLE pow2_i; /* = pow2[i] */
- DOUBLE powh_i; /* = powh[i] */
-
- /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
- x * 2^exponent = argument, x >= 1.0. */
- for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
- ;
- i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
- {
- if (x >= pow2_i)
- {
- exponent += (1 << i);
- x *= powh_i;
- }
- else
- break;
-
- pow2[i] = pow2_i;
- powh[i] = powh_i;
- }
- /* Avoid making x too small, as it could become a denormalized
- number and thus lose precision. */
- while (i > 0 && x < pow2[i - 1])
- {
- i--;
- powh_i = powh[i];
- }
- exponent += (1 << i);
- x *= powh_i;
- /* Here 2^-2^i <= x < 1.0. */
- }
- else
- {
- /* A negative or zero exponent. */
- DOUBLE pow2_i; /* = pow2[i] */
- DOUBLE powh_i; /* = powh[i] */
-
- /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
- x * 2^exponent = argument, x < 1.0. */
- for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
- ;
- i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
- {
- if (x < powh_i)
- {
- exponent -= (1 << i);
- x *= pow2_i;
- }
- else
- break;
-
- pow2[i] = pow2_i;
- powh[i] = powh_i;
- }
- /* Here 2^-2^i <= x < 1.0. */
- }
-
- /* Invariants: x * 2^exponent = argument, and 2^-2^i <= x < 1.0. */
- while (i > 0)
- {
- i--;
- if (x < powh[i])
- {
- exponent -= (1 << i);
- x *= pow2[i];
- }
- }
- /* Here 0.5 <= x < 1.0. */
- }
-
- if (sign < 0)
- x = - x;
-
- END_ROUNDING ();
-
- *expptr = exponent;
- return x;
-}
+/* Split a double into fraction and mantissa.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paolo Bonzini <bonzini@gnu.org>, 2003, and
+ Bruno Haible <bruno@clisp.org>, 2007. */
+
+#if ! defined USE_LONG_DOUBLE
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <math.h>
+
+#include <float.h>
+#ifdef USE_LONG_DOUBLE
+# include "isnanl-nolibm.h"
+# include "fpucw.h"
+#else
+# include "isnand-nolibm.h"
+#endif
+
+/* This file assumes FLT_RADIX = 2. If FLT_RADIX is a power of 2 greater
+ than 2, or not even a power of 2, some rounding errors can occur, so that
+ then the returned mantissa is only guaranteed to be <= 1.0, not < 1.0. */
+
+#ifdef USE_LONG_DOUBLE
+# define FUNC frexpl
+# define DOUBLE long double
+# define ISNAN isnanl
+# define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING
+# define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING ()
+# define END_ROUNDING() END_LONG_DOUBLE_ROUNDING ()
+# define L_(literal) literal##L
+#else
+# define FUNC frexp
+# define DOUBLE double
+# define ISNAN isnand
+# define DECL_ROUNDING
+# define BEGIN_ROUNDING()
+# define END_ROUNDING()
+# define L_(literal) literal
+#endif
+
+DOUBLE
+FUNC (DOUBLE x, int *expptr)
+{
+ int sign;
+ int exponent;
+ DECL_ROUNDING
+
+ /* Test for NaN, infinity, and zero. */
+ if (ISNAN (x) || x + x == x)
+ {
+ *expptr = 0;
+ return x;
+ }
+
+ sign = 0;
+ if (x < 0)
+ {
+ x = - x;
+ sign = -1;
+ }
+
+ BEGIN_ROUNDING ();
+
+ {
+ /* Since the exponent is an 'int', it fits in 64 bits. Therefore the
+ loops are executed no more than 64 times. */
+ DOUBLE pow2[64]; /* pow2[i] = 2^2^i */
+ DOUBLE powh[64]; /* powh[i] = 2^-2^i */
+ int i;
+
+ exponent = 0;
+ if (x >= L_(1.0))
+ {
+ /* A positive exponent. */
+ DOUBLE pow2_i; /* = pow2[i] */
+ DOUBLE powh_i; /* = powh[i] */
+
+ /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
+ x * 2^exponent = argument, x >= 1.0. */
+ for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
+ ;
+ i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
+ {
+ if (x >= pow2_i)
+ {
+ exponent += (1 << i);
+ x *= powh_i;
+ }
+ else
+ break;
+
+ pow2[i] = pow2_i;
+ powh[i] = powh_i;
+ }
+ /* Avoid making x too small, as it could become a denormalized
+ number and thus lose precision. */
+ while (i > 0 && x < pow2[i - 1])
+ {
+ i--;
+ powh_i = powh[i];
+ }
+ exponent += (1 << i);
+ x *= powh_i;
+ /* Here 2^-2^i <= x < 1.0. */
+ }
+ else
+ {
+ /* A negative or zero exponent. */
+ DOUBLE pow2_i; /* = pow2[i] */
+ DOUBLE powh_i; /* = powh[i] */
+
+ /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
+ x * 2^exponent = argument, x < 1.0. */
+ for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
+ ;
+ i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
+ {
+ if (x < powh_i)
+ {
+ exponent -= (1 << i);
+ x *= pow2_i;
+ }
+ else
+ break;
+
+ pow2[i] = pow2_i;
+ powh[i] = powh_i;
+ }
+ /* Here 2^-2^i <= x < 1.0. */
+ }
+
+ /* Invariants: x * 2^exponent = argument, and 2^-2^i <= x < 1.0. */
+ while (i > 0)
+ {
+ i--;
+ if (x < powh[i])
+ {
+ exponent -= (1 << i);
+ x *= pow2[i];
+ }
+ }
+ /* Here 0.5 <= x < 1.0. */
+ }
+
+ if (sign < 0)
+ x = - x;
+
+ END_ROUNDING ();
+
+ *expptr = exponent;
+ return x;
+}
diff --git a/contrib/tools/bison/gnulib/src/fseek.c b/contrib/tools/bison/gnulib/src/fseek.c
index 4708287c30..27945e0b42 100644
--- a/contrib/tools/bison/gnulib/src/fseek.c
+++ b/contrib/tools/bison/gnulib/src/fseek.c
@@ -1,30 +1,30 @@
-/* An fseek() function that, together with fflush(), is POSIX compliant.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-/* Get off_t. */
-#include <unistd.h>
-
-int
-fseek (FILE *fp, long offset, int whence)
-{
- /* Use the replacement fseeko function with all its workarounds. */
- return fseeko (fp, (off_t)offset, whence);
-}
+/* An fseek() function that, together with fflush(), is POSIX compliant.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+/* Get off_t. */
+#include <unistd.h>
+
+int
+fseek (FILE *fp, long offset, int whence)
+{
+ /* Use the replacement fseeko function with all its workarounds. */
+ return fseeko (fp, (off_t)offset, whence);
+}
diff --git a/contrib/tools/bison/gnulib/src/fseeko.c b/contrib/tools/bison/gnulib/src/fseeko.c
index 16404b71eb..effcefec9b 100644
--- a/contrib/tools/bison/gnulib/src/fseeko.c
+++ b/contrib/tools/bison/gnulib/src/fseeko.c
@@ -1,162 +1,162 @@
-/* An fseeko() function that, together with fflush(), is POSIX compliant.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-/* Get off_t, lseek, _POSIX_VERSION. */
-#include <unistd.h>
-
-#include "stdio-impl.h"
-
-int
-fseeko (FILE *fp, off_t offset, int whence)
-#undef fseeko
-#if !HAVE_FSEEKO
-# undef fseek
-# define fseeko fseek
-#endif
-#if _GL_WINDOWS_64_BIT_OFF_T
-# undef fseeko
-# if HAVE__FSEEKI64 /* msvc, mingw64 */
-# define fseeko _fseeki64
-# else /* mingw */
-# define fseeko fseeko64
-# endif
-#endif
-{
-#if LSEEK_PIPE_BROKEN
- /* mingw gives bogus answers rather than failure on non-seekable files. */
- if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
- return EOF;
-#endif
-
- /* These tests are based on fpurge.c. */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
- if (fp->_IO_read_end == fp->_IO_read_ptr
- && fp->_IO_write_ptr == fp->_IO_write_base
- && fp->_IO_save_base == NULL)
-#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
-# if defined __SL64 && defined __SCLE /* Cygwin */
- if ((fp->_flags & __SL64) == 0)
- {
- /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
- mode; but has an fseeko that requires 64-bit mode. */
- FILE *tmp = fopen ("/dev/null", "r");
- if (!tmp)
- return -1;
- fp->_flags |= __SL64;
- fp->_seek64 = tmp->_seek64;
- fclose (tmp);
- }
-# endif
- if (fp_->_p == fp_->_bf._base
- && fp_->_r == 0
- && fp_->_w == ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
- ? fp_->_bf._size
- : 0)
- && fp_ub._base == NULL)
-#elif defined __EMX__ /* emx+gcc */
- if (fp->_ptr == fp->_buffer
- && fp->_rcount == 0
- && fp->_wcount == 0
- && fp->_ungetc_count == 0)
-#elif defined __minix /* Minix */
- if (fp_->_ptr == fp_->_buf
- && (fp_->_ptr == NULL || fp_->_count == 0))
-#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
- if (fp_->_ptr == fp_->_base
- && (fp_->_ptr == NULL || fp_->_cnt == 0))
+/* An fseeko() function that, together with fflush(), is POSIX compliant.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+/* Get off_t, lseek, _POSIX_VERSION. */
+#include <unistd.h>
+
+#include "stdio-impl.h"
+
+int
+fseeko (FILE *fp, off_t offset, int whence)
+#undef fseeko
+#if !HAVE_FSEEKO
+# undef fseek
+# define fseeko fseek
+#endif
+#if _GL_WINDOWS_64_BIT_OFF_T
+# undef fseeko
+# if HAVE__FSEEKI64 /* msvc, mingw64 */
+# define fseeko _fseeki64
+# else /* mingw */
+# define fseeko fseeko64
+# endif
+#endif
+{
+#if LSEEK_PIPE_BROKEN
+ /* mingw gives bogus answers rather than failure on non-seekable files. */
+ if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
+ return EOF;
+#endif
+
+ /* These tests are based on fpurge.c. */
+#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+ if (fp->_IO_read_end == fp->_IO_read_ptr
+ && fp->_IO_write_ptr == fp->_IO_write_base
+ && fp->_IO_save_base == NULL)
+#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+# if defined __SL64 && defined __SCLE /* Cygwin */
+ if ((fp->_flags & __SL64) == 0)
+ {
+ /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
+ mode; but has an fseeko that requires 64-bit mode. */
+ FILE *tmp = fopen ("/dev/null", "r");
+ if (!tmp)
+ return -1;
+ fp->_flags |= __SL64;
+ fp->_seek64 = tmp->_seek64;
+ fclose (tmp);
+ }
+# endif
+ if (fp_->_p == fp_->_bf._base
+ && fp_->_r == 0
+ && fp_->_w == ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
+ ? fp_->_bf._size
+ : 0)
+ && fp_ub._base == NULL)
+#elif defined __EMX__ /* emx+gcc */
+ if (fp->_ptr == fp->_buffer
+ && fp->_rcount == 0
+ && fp->_wcount == 0
+ && fp->_ungetc_count == 0)
+#elif defined __minix /* Minix */
+ if (fp_->_ptr == fp_->_buf
+ && (fp_->_ptr == NULL || fp_->_count == 0))
+#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
+ if (fp_->_ptr == fp_->_base
+ && (fp_->_ptr == NULL || fp_->_cnt == 0))
#elif WIN_SDK10
if (((TWinSdk10File*)fp)->_ptr == ((TWinSdk10File*)fp)->_base
&& (((TWinSdk10File*)fp)->_ptr == NULL || ((TWinSdk10File*)fp)->_cnt == 0))
-#elif defined __UCLIBC__ /* uClibc */
- if (((fp->__modeflags & __FLAG_WRITING) == 0
- || fp->__bufpos == fp->__bufstart)
- && ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0
- || fp->__bufpos == fp->__bufread))
-#elif defined __QNX__ /* QNX */
- if ((fp->_Mode & 0x2000 /* _MWRITE */ ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
- && fp->_Rback == fp->_Back + sizeof (fp->_Back)
- && fp->_Rsave == NULL)
-#elif defined __MINT__ /* Atari FreeMiNT */
- if (fp->__bufp == fp->__buffer
- && fp->__get_limit == fp->__bufp
- && fp->__put_limit == fp->__bufp
- && !fp->__pushed_back)
-#elif defined EPLAN9 /* Plan9 */
- if (fp->rp == fp->buf
- && fp->wp == fp->buf)
-#elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION
- /* Cross-compiling to some other system advertising conformance to
- POSIX.1-2008 or later. Assume fseeko and fflush work as advertised.
- If this assumption is incorrect, please report the bug to
- bug-gnulib. */
- if (0)
-#else
- #error "Please port gnulib fseeko.c to your platform! Look at the code in fseeko.c, then report this to bug-gnulib."
-#endif
- {
- /* We get here when an fflush() call immediately preceded this one (or
- if ftell() has created buffers but no I/O has occurred on a
- newly-opened stream). We know there are no buffers. */
- off_t pos = lseek (fileno (fp), offset, whence);
- if (pos == -1)
- {
-#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
- fp_->_flags &= ~__SOFF;
-#endif
- return -1;
- }
-
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
- fp->_flags &= ~_IO_EOF_SEEN;
- fp->_offset = pos;
-#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
-# if defined __CYGWIN__
- /* fp_->_offset is typed as an integer. */
- fp_->_offset = pos;
-# else
- /* fp_->_offset is an fpos_t. */
- {
- /* Use a union, since on NetBSD, the compilation flags
- determine whether fpos_t is typedef'd to off_t or a struct
- containing a single off_t member. */
- union
- {
- fpos_t f;
- off_t o;
- } u;
- u.o = pos;
- fp_->_offset = u.f;
- }
-# endif
- fp_->_flags |= __SOFF;
- fp_->_flags &= ~__SEOF;
-#elif defined __EMX__ /* emx+gcc */
- fp->_flags &= ~_IOEOF;
-#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
- fp->_flag &= ~_IOEOF;
-#elif defined __MINT__ /* Atari FreeMiNT */
- fp->__offset = pos;
- fp->__eof = 0;
-#endif
- return 0;
- }
- return fseeko (fp, offset, whence);
-}
+#elif defined __UCLIBC__ /* uClibc */
+ if (((fp->__modeflags & __FLAG_WRITING) == 0
+ || fp->__bufpos == fp->__bufstart)
+ && ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0
+ || fp->__bufpos == fp->__bufread))
+#elif defined __QNX__ /* QNX */
+ if ((fp->_Mode & 0x2000 /* _MWRITE */ ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
+ && fp->_Rback == fp->_Back + sizeof (fp->_Back)
+ && fp->_Rsave == NULL)
+#elif defined __MINT__ /* Atari FreeMiNT */
+ if (fp->__bufp == fp->__buffer
+ && fp->__get_limit == fp->__bufp
+ && fp->__put_limit == fp->__bufp
+ && !fp->__pushed_back)
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->rp == fp->buf
+ && fp->wp == fp->buf)
+#elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION
+ /* Cross-compiling to some other system advertising conformance to
+ POSIX.1-2008 or later. Assume fseeko and fflush work as advertised.
+ If this assumption is incorrect, please report the bug to
+ bug-gnulib. */
+ if (0)
+#else
+ #error "Please port gnulib fseeko.c to your platform! Look at the code in fseeko.c, then report this to bug-gnulib."
+#endif
+ {
+ /* We get here when an fflush() call immediately preceded this one (or
+ if ftell() has created buffers but no I/O has occurred on a
+ newly-opened stream). We know there are no buffers. */
+ off_t pos = lseek (fileno (fp), offset, whence);
+ if (pos == -1)
+ {
+#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+ fp_->_flags &= ~__SOFF;
+#endif
+ return -1;
+ }
+
+#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+ fp->_flags &= ~_IO_EOF_SEEN;
+ fp->_offset = pos;
+#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+# if defined __CYGWIN__
+ /* fp_->_offset is typed as an integer. */
+ fp_->_offset = pos;
+# else
+ /* fp_->_offset is an fpos_t. */
+ {
+ /* Use a union, since on NetBSD, the compilation flags
+ determine whether fpos_t is typedef'd to off_t or a struct
+ containing a single off_t member. */
+ union
+ {
+ fpos_t f;
+ off_t o;
+ } u;
+ u.o = pos;
+ fp_->_offset = u.f;
+ }
+# endif
+ fp_->_flags |= __SOFF;
+ fp_->_flags &= ~__SEOF;
+#elif defined __EMX__ /* emx+gcc */
+ fp->_flags &= ~_IOEOF;
+#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
+ fp->_flag &= ~_IOEOF;
+#elif defined __MINT__ /* Atari FreeMiNT */
+ fp->__offset = pos;
+ fp->__eof = 0;
+#endif
+ return 0;
+ }
+ return fseeko (fp, offset, whence);
+}
diff --git a/contrib/tools/bison/gnulib/src/fseterr.c b/contrib/tools/bison/gnulib/src/fseterr.c
index 9f7bea13b3..8b842f6e7f 100644
--- a/contrib/tools/bison/gnulib/src/fseterr.c
+++ b/contrib/tools/bison/gnulib/src/fseterr.c
@@ -1,81 +1,81 @@
-/* Set the error indicator of a stream.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "fseterr.h"
-
-#include <errno.h>
-
-#include "stdio-impl.h"
-
-void
-fseterr (FILE *fp)
-{
- /* Most systems provide FILE as a struct and the necessary bitmask in
- <stdio.h>, because they need it for implementing getc() and putc() as
- fast macros. */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
- fp->_flags |= _IO_ERR_SEEN;
-#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
- fp_->_flags |= __SERR;
-#elif defined __EMX__ /* emx+gcc */
- fp->_flags |= _IOERR;
-#elif defined __minix /* Minix */
- fp->_flags |= _IOERR;
-#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
- fp_->_flag |= _IOERR;
+/* Set the error indicator of a stream.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "fseterr.h"
+
+#include <errno.h>
+
+#include "stdio-impl.h"
+
+void
+fseterr (FILE *fp)
+{
+ /* Most systems provide FILE as a struct and the necessary bitmask in
+ <stdio.h>, because they need it for implementing getc() and putc() as
+ fast macros. */
+#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+ fp->_flags |= _IO_ERR_SEEN;
+#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+ fp_->_flags |= __SERR;
+#elif defined __EMX__ /* emx+gcc */
+ fp->_flags |= _IOERR;
+#elif defined __minix /* Minix */
+ fp->_flags |= _IOERR;
+#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
+ fp_->_flag |= _IOERR;
#elif WIN_SDK10
((TWinSdk10File*)fp)->_flags |= WIN_SDK10_IOERROR;
-#elif defined __UCLIBC__ /* uClibc */
- fp->__modeflags |= __FLAG_ERROR;
-#elif defined __QNX__ /* QNX */
- fp->_Mode |= 0x200 /* _MERR */;
-#elif defined __MINT__ /* Atari FreeMiNT */
- fp->__error = 1;
-#elif defined EPLAN9 /* Plan9 */
- if (fp->state != 0 /* CLOSED */)
- fp->state = 5 /* ERR */;
-#elif 0 /* unknown */
- /* Portable fallback, based on an idea by Rich Felker.
- Wow! 6 system calls for something that is just a bit operation!
- Not activated on any system, because there is no way to repair FP when
- the sequence of system calls fails, and library code should not call
- abort(). */
- int saved_errno;
- int fd;
- int fd2;
-
- saved_errno = errno;
- fflush (fp);
- fd = fileno (fp);
- fd2 = dup (fd);
- if (fd2 >= 0)
- {
- close (fd);
- fputc ('\0', fp); /* This should set the error indicator. */
- fflush (fp); /* Or this. */
- if (dup2 (fd2, fd) < 0)
- /* Whee... we botched the stream and now cannot restore it! */
- abort ();
- close (fd2);
- }
- errno = saved_errno;
-#else
- #error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib."
-#endif
-}
+#elif defined __UCLIBC__ /* uClibc */
+ fp->__modeflags |= __FLAG_ERROR;
+#elif defined __QNX__ /* QNX */
+ fp->_Mode |= 0x200 /* _MERR */;
+#elif defined __MINT__ /* Atari FreeMiNT */
+ fp->__error = 1;
+#elif defined EPLAN9 /* Plan9 */
+ if (fp->state != 0 /* CLOSED */)
+ fp->state = 5 /* ERR */;
+#elif 0 /* unknown */
+ /* Portable fallback, based on an idea by Rich Felker.
+ Wow! 6 system calls for something that is just a bit operation!
+ Not activated on any system, because there is no way to repair FP when
+ the sequence of system calls fails, and library code should not call
+ abort(). */
+ int saved_errno;
+ int fd;
+ int fd2;
+
+ saved_errno = errno;
+ fflush (fp);
+ fd = fileno (fp);
+ fd2 = dup (fd);
+ if (fd2 >= 0)
+ {
+ close (fd);
+ fputc ('\0', fp); /* This should set the error indicator. */
+ fflush (fp); /* Or this. */
+ if (dup2 (fd2, fd) < 0)
+ /* Whee... we botched the stream and now cannot restore it! */
+ abort ();
+ close (fd2);
+ }
+ errno = saved_errno;
+#else
+ #error "Please port gnulib fseterr.c to your platform! Look at the definitions of ferror and clearerr on your system, then report this to bug-gnulib."
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/fseterr.h b/contrib/tools/bison/gnulib/src/fseterr.h
index 630fa8647f..f6825f76bd 100644
--- a/contrib/tools/bison/gnulib/src/fseterr.h
+++ b/contrib/tools/bison/gnulib/src/fseterr.h
@@ -1,45 +1,45 @@
-/* Set the error indicator of a stream.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _FSETERR_H
-#define _FSETERR_H
-
-#include <stdio.h>
-
-/* Set the error indicator of the stream FP.
- The "error indicator" is set when an I/O operation on the stream fails, and
- is cleared (together with the "end-of-file" indicator) by clearerr (FP). */
-
-#if HAVE___FSETERR /* musl libc */
-
-# include <stdio_ext.h>
-# define fseterr(fp) __fseterr (fp)
-
-#else
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-extern void fseterr (FILE *fp);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
-
-#endif /* _FSETERR_H */
+/* Set the error indicator of a stream.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _FSETERR_H
+#define _FSETERR_H
+
+#include <stdio.h>
+
+/* Set the error indicator of the stream FP.
+ The "error indicator" is set when an I/O operation on the stream fails, and
+ is cleared (together with the "end-of-file" indicator) by clearerr (FP). */
+
+#if HAVE___FSETERR /* musl libc */
+
+# include <stdio_ext.h>
+# define fseterr(fp) __fseterr (fp)
+
+#else
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+extern void fseterr (FILE *fp);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+#endif /* _FSETERR_H */
diff --git a/contrib/tools/bison/gnulib/src/fstat.c b/contrib/tools/bison/gnulib/src/fstat.c
index dc802f502b..0d9ca6e617 100644
--- a/contrib/tools/bison/gnulib/src/fstat.c
+++ b/contrib/tools/bison/gnulib/src/fstat.c
@@ -1,88 +1,88 @@
-/* fstat() replacement.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* If the user's config.h happens to include <sys/stat.h>, let it include only
- the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
- rpl_fstat. */
-#define __need_system_sys_stat_h
-#include <config.h>
-
-/* Get the original definition of fstat. It might be defined as a macro. */
-#include <sys/types.h>
-#include <sys/stat.h>
-#if _GL_WINDOWS_64_BIT_ST_SIZE
-# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
-# define stat _stati64
-# undef fstat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
-# define fstat _fstati64
-#endif
-#undef __need_system_sys_stat_h
-
-static int
-orig_fstat (int fd, struct stat *buf)
-{
- return fstat (fd, buf);
-}
-
-/* Specification. */
-/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
- eliminates this include because of the preliminary #include <sys/stat.h>
- above. */
-#include "sys/stat.h"
-
-#include <errno.h>
-#include <unistd.h>
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-# include "msvc-inval.h"
-#endif
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-fstat_nothrow (int fd, struct stat *buf)
-{
- int result;
-
- TRY_MSVC_INVAL
- {
- result = orig_fstat (fd, buf);
- }
- CATCH_MSVC_INVAL
- {
- result = -1;
- errno = EBADF;
- }
- DONE_MSVC_INVAL;
-
- return result;
-}
-#else
-# define fstat_nothrow orig_fstat
-#endif
-
-int
-rpl_fstat (int fd, struct stat *buf)
-{
-#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
- /* Handle the case when rpl_open() used a dummy file descriptor to work
- around an open() that can't normally visit directories. */
- const char *name = _gl_directory_name (fd);
- if (name != NULL)
- return stat (name, buf);
-#endif
-
- return fstat_nothrow (fd, buf);
-}
+/* fstat() replacement.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
+ the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
+ rpl_fstat. */
+#define __need_system_sys_stat_h
+#include <config.h>
+
+/* Get the original definition of fstat. It might be defined as a macro. */
+#include <sys/types.h>
+#include <sys/stat.h>
+#if _GL_WINDOWS_64_BIT_ST_SIZE
+# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
+# define stat _stati64
+# undef fstat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
+# define fstat _fstati64
+#endif
+#undef __need_system_sys_stat_h
+
+static int
+orig_fstat (int fd, struct stat *buf)
+{
+ return fstat (fd, buf);
+}
+
+/* Specification. */
+/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
+ eliminates this include because of the preliminary #include <sys/stat.h>
+ above. */
+#include "sys/stat.h"
+
+#include <errno.h>
+#include <unistd.h>
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+fstat_nothrow (int fd, struct stat *buf)
+{
+ int result;
+
+ TRY_MSVC_INVAL
+ {
+ result = orig_fstat (fd, buf);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = -1;
+ errno = EBADF;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+#else
+# define fstat_nothrow orig_fstat
+#endif
+
+int
+rpl_fstat (int fd, struct stat *buf)
+{
+#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
+ /* Handle the case when rpl_open() used a dummy file descriptor to work
+ around an open() that can't normally visit directories. */
+ const char *name = _gl_directory_name (fd);
+ if (name != NULL)
+ return stat (name, buf);
+#endif
+
+ return fstat_nothrow (fd, buf);
+}
diff --git a/contrib/tools/bison/gnulib/src/ftello.c b/contrib/tools/bison/gnulib/src/ftello.c
index 3a2a0f2012..1db0504161 100644
--- a/contrib/tools/bison/gnulib/src/ftello.c
+++ b/contrib/tools/bison/gnulib/src/ftello.c
@@ -1,85 +1,85 @@
-/* An ftello() function that works around platform bugs.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-/* Get lseek. */
-#include <unistd.h>
-
-#include "stdio-impl.h"
-
-off_t
-ftello (FILE *fp)
-#undef ftello
-#if !HAVE_FTELLO
-# undef ftell
-# define ftello ftell
-#endif
-#if _GL_WINDOWS_64_BIT_OFF_T
-# undef ftello
-# if HAVE__FTELLI64 /* msvc, mingw64 */
-# define ftello _ftelli64
-# else /* mingw */
-# define ftello ftello64
-# endif
-#endif
-{
-#if LSEEK_PIPE_BROKEN
- /* mingw gives bogus answers rather than failure on non-seekable files. */
- if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
- return -1;
-#endif
-
-#if FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE /* Solaris */
- /* The Solaris stdio leaves the _IOREAD flag set after reading from a file
- reaches EOF and the program then starts writing to the file. ftello
- gets confused by this. */
- if (fp_->_flag & _IOWRT)
- {
- off_t pos;
-
- /* Call ftello nevertheless, for the side effects that it does on fp. */
- ftello (fp);
-
- /* Compute the file position ourselves. */
- pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR);
- if (pos >= 0)
- {
- if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL)
- pos += fp_->_ptr - fp_->_base;
- }
- return pos;
- }
-#endif
-
-#if defined __SL64 && defined __SCLE /* Cygwin */
- if ((fp->_flags & __SL64) == 0)
- {
- /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
- mode; but has an ftello that requires 64-bit mode. */
- FILE *tmp = fopen ("/dev/null", "r");
- if (!tmp)
- return -1;
- fp->_flags |= __SL64;
- fp->_seek64 = tmp->_seek64;
- fclose (tmp);
- }
-#endif
- return ftello (fp);
-}
+/* An ftello() function that works around platform bugs.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+/* Get lseek. */
+#include <unistd.h>
+
+#include "stdio-impl.h"
+
+off_t
+ftello (FILE *fp)
+#undef ftello
+#if !HAVE_FTELLO
+# undef ftell
+# define ftello ftell
+#endif
+#if _GL_WINDOWS_64_BIT_OFF_T
+# undef ftello
+# if HAVE__FTELLI64 /* msvc, mingw64 */
+# define ftello _ftelli64
+# else /* mingw */
+# define ftello ftello64
+# endif
+#endif
+{
+#if LSEEK_PIPE_BROKEN
+ /* mingw gives bogus answers rather than failure on non-seekable files. */
+ if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
+ return -1;
+#endif
+
+#if FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE /* Solaris */
+ /* The Solaris stdio leaves the _IOREAD flag set after reading from a file
+ reaches EOF and the program then starts writing to the file. ftello
+ gets confused by this. */
+ if (fp_->_flag & _IOWRT)
+ {
+ off_t pos;
+
+ /* Call ftello nevertheless, for the side effects that it does on fp. */
+ ftello (fp);
+
+ /* Compute the file position ourselves. */
+ pos = lseek (fileno (fp), (off_t) 0, SEEK_CUR);
+ if (pos >= 0)
+ {
+ if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL)
+ pos += fp_->_ptr - fp_->_base;
+ }
+ return pos;
+ }
+#endif
+
+#if defined __SL64 && defined __SCLE /* Cygwin */
+ if ((fp->_flags & __SL64) == 0)
+ {
+ /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
+ mode; but has an ftello that requires 64-bit mode. */
+ FILE *tmp = fopen ("/dev/null", "r");
+ if (!tmp)
+ return -1;
+ fp->_flags |= __SL64;
+ fp->_seek64 = tmp->_seek64;
+ fclose (tmp);
+ }
+#endif
+ return ftello (fp);
+}
diff --git a/contrib/tools/bison/gnulib/src/get-errno.c b/contrib/tools/bison/gnulib/src/get-errno.c
index 7865212cc7..a4772ba1b6 100644
--- a/contrib/tools/bison/gnulib/src/get-errno.c
+++ b/contrib/tools/bison/gnulib/src/get-errno.c
@@ -1,42 +1,42 @@
-/* get-errno.c - get and set errno.
-
- Copyright (C) 2002, 2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <config.h>
-
-#include "get-errno.h"
-
-#include <errno.h>
-
-/* Get and set errno. A source file that needs to set or get errno,
- but doesn't need to test for specific errno values, can use these
- functions to avoid namespace pollution. For example, a file that
- defines EQUAL should not include <errno.h>, since <errno.h> might
- define EQUAL; such a file can include <get-errno.h> instead. */
-
-int
-get_errno (void)
-{
- return errno;
-}
-
-void
-set_errno (int e)
-{
- errno = e;
-}
+/* get-errno.c - get and set errno.
+
+ Copyright (C) 2002, 2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <config.h>
+
+#include "get-errno.h"
+
+#include <errno.h>
+
+/* Get and set errno. A source file that needs to set or get errno,
+ but doesn't need to test for specific errno values, can use these
+ functions to avoid namespace pollution. For example, a file that
+ defines EQUAL should not include <errno.h>, since <errno.h> might
+ define EQUAL; such a file can include <get-errno.h> instead. */
+
+int
+get_errno (void)
+{
+ return errno;
+}
+
+void
+set_errno (int e)
+{
+ errno = e;
+}
diff --git a/contrib/tools/bison/gnulib/src/get-errno.h b/contrib/tools/bison/gnulib/src/get-errno.h
index 04b3d4c8de..3f5b56811a 100644
--- a/contrib/tools/bison/gnulib/src/get-errno.h
+++ b/contrib/tools/bison/gnulib/src/get-errno.h
@@ -1,19 +1,19 @@
-/* get-errno.h - get and set errno.
-
- Copyright (C) 2002, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-extern int get_errno (void);
-extern void set_errno (int);
+/* get-errno.h - get and set errno.
+
+ Copyright (C) 2002, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+extern int get_errno (void);
+extern void set_errno (int);
diff --git a/contrib/tools/bison/gnulib/src/getdtablesize.c b/contrib/tools/bison/gnulib/src/getdtablesize.c
index 212b3c0f96..8cd12935d4 100644
--- a/contrib/tools/bison/gnulib/src/getdtablesize.c
+++ b/contrib/tools/bison/gnulib/src/getdtablesize.c
@@ -1,90 +1,90 @@
-/* getdtablesize() function for platforms that don't have it.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2008.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <unistd.h>
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-#include <stdio.h>
-
-#include "msvc-inval.h"
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-_setmaxstdio_nothrow (int newmax)
-{
- int result;
-
- TRY_MSVC_INVAL
- {
- result = _setmaxstdio (newmax);
- }
- CATCH_MSVC_INVAL
- {
- result = -1;
- }
- DONE_MSVC_INVAL;
-
- return result;
-}
-# define _setmaxstdio _setmaxstdio_nothrow
-#endif
-
-/* Cache for the previous getdtablesize () result. */
-static int dtablesize;
-
-int
-getdtablesize (void)
-{
- if (dtablesize == 0)
- {
- /* We are looking for the number N such that the valid file descriptors
- are 0..N-1. It can be obtained through a loop as follows:
- {
- int fd;
- for (fd = 3; fd < 65536; fd++)
- if (dup2 (0, fd) == -1)
- break;
- return fd;
- }
- On Windows XP, the result is 2048.
- The drawback of this loop is that it allocates memory for a libc
- internal array that is never freed.
-
- The number N can also be obtained as the upper bound for
- _getmaxstdio (). _getmaxstdio () returns the maximum number of open
- FILE objects. The sanity check in _setmaxstdio reveals the maximum
- number of file descriptors. This too allocates memory, but it is
- freed when we call _setmaxstdio with the original value. */
-#if !defined(_WIN32) && !defined(_WIN64)
- int orig_max_stdio = _getmaxstdio ();
- unsigned int bound;
- for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2)
- ;
- _setmaxstdio (orig_max_stdio);
- dtablesize = bound;
-#else
- dtablesize = _getmaxstdio();
-#endif
- }
- return dtablesize;
-}
-
-#endif
+/* getdtablesize() function for platforms that don't have it.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+#include <stdio.h>
+
+#include "msvc-inval.h"
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+_setmaxstdio_nothrow (int newmax)
+{
+ int result;
+
+ TRY_MSVC_INVAL
+ {
+ result = _setmaxstdio (newmax);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = -1;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+# define _setmaxstdio _setmaxstdio_nothrow
+#endif
+
+/* Cache for the previous getdtablesize () result. */
+static int dtablesize;
+
+int
+getdtablesize (void)
+{
+ if (dtablesize == 0)
+ {
+ /* We are looking for the number N such that the valid file descriptors
+ are 0..N-1. It can be obtained through a loop as follows:
+ {
+ int fd;
+ for (fd = 3; fd < 65536; fd++)
+ if (dup2 (0, fd) == -1)
+ break;
+ return fd;
+ }
+ On Windows XP, the result is 2048.
+ The drawback of this loop is that it allocates memory for a libc
+ internal array that is never freed.
+
+ The number N can also be obtained as the upper bound for
+ _getmaxstdio (). _getmaxstdio () returns the maximum number of open
+ FILE objects. The sanity check in _setmaxstdio reveals the maximum
+ number of file descriptors. This too allocates memory, but it is
+ freed when we call _setmaxstdio with the original value. */
+#if !defined(_WIN32) && !defined(_WIN64)
+ int orig_max_stdio = _getmaxstdio ();
+ unsigned int bound;
+ for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2)
+ ;
+ _setmaxstdio (orig_max_stdio);
+ dtablesize = bound;
+#else
+ dtablesize = _getmaxstdio();
+#endif
+ }
+ return dtablesize;
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/getopt.c b/contrib/tools/bison/gnulib/src/getopt.c
index 4b3d267067..67a369330e 100644
--- a/contrib/tools/bison/gnulib/src/getopt.c
+++ b/contrib/tools/bison/gnulib/src/getopt.c
@@ -1,1245 +1,1245 @@
-/* Getopt for GNU.
- NOTE: getopt is part of the C library, so if you don't know what
- "Keep this file name-space clean" means, talk to drepper@gnu.org
- before changing it!
- Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC
-# include <config.h>
-#endif
-
-#include "getopt.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef _LIBC
-# include <libintl.h>
-#else
-# include "gettext.h"
-# define _(msgid) gettext (msgid)
-#endif
-
-#if defined _LIBC && defined USE_IN_LIBIO
-# include <wchar.h>
-#endif
-
-/* This version of 'getopt' appears to the caller like standard Unix 'getopt'
- but it behaves differently for the user, since it allows the user
- to intersperse the options with the other arguments.
-
- As 'getopt_long' works, it permutes the elements of ARGV so that,
- when it is done, all the options precede everything else. Thus
- all application programs are extended to handle flexible argument order.
-
- Using 'getopt' or setting the environment variable POSIXLY_CORRECT
- disables permutation.
- Then the behavior is completely standard.
-
- GNU application programs can use a third alternative mode in which
- they can distinguish the relative order of options and other arguments. */
-
-#include "getopt_int.h"
-
-/* For communication from 'getopt' to the caller.
- When 'getopt' finds an option that takes an argument,
- the argument value is returned here.
- Also, when 'ordering' is RETURN_IN_ORDER,
- each non-option ARGV-element is returned here. */
-
-char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
- This is used for communication to and from the caller
- and for communication between successive calls to 'getopt'.
-
- On entry to 'getopt', zero means this is the first call; initialize.
-
- When 'getopt' returns -1, this is the index of the first of the
- non-option elements that the caller should itself scan.
-
- Otherwise, 'optind' communicates from one call to the next
- how much of ARGV has been scanned so far. */
-
-/* 1003.2 says this must be 1 before any call. */
-int optind = 1;
-
-/* Callers store zero here to inhibit the error message
- for unrecognized options. */
-
-int opterr = 1;
-
-/* Set to an option character which was unrecognized.
- This must be initialized on some systems to avoid linking in the
- system's own getopt implementation. */
-
-int optopt = '?';
-
-/* Keep a global copy of all internal members of getopt_data. */
-
-static struct _getopt_data getopt_data;
-
-
-#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
-extern char *getenv ();
-#endif
-
-#ifdef _LIBC
-/* Stored original parameters.
- XXX This is no good solution. We should rather copy the args so
- that we can compare them later. But we must not use malloc(3). */
-extern int __libc_argc;
-extern char **__libc_argv;
-
-/* Bash 2.0 gives us an environment variable containing flags
- indicating ARGV elements that should not be considered arguments. */
-
-# ifdef USE_NONOPTION_FLAGS
-/* Defined in getopt_init.c */
-extern char *__getopt_nonoption_flags;
-# endif
-
-# ifdef USE_NONOPTION_FLAGS
-# define SWAP_FLAGS(ch1, ch2) \
- if (d->__nonoption_flags_len > 0) \
- { \
- char __tmp = __getopt_nonoption_flags[ch1]; \
- __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
- __getopt_nonoption_flags[ch2] = __tmp; \
- }
-# else
-# define SWAP_FLAGS(ch1, ch2)
-# endif
-#else /* !_LIBC */
-# define SWAP_FLAGS(ch1, ch2)
-#endif /* _LIBC */
-
-/* Exchange two adjacent subsequences of ARGV.
- One subsequence is elements [first_nonopt,last_nonopt)
- which contains all the non-options that have been skipped so far.
- The other is elements [last_nonopt,optind), which contains all
- the options processed since those non-options were skipped.
-
- 'first_nonopt' and 'last_nonopt' are relocated so that they describe
- the new indices of the non-options in ARGV after they are moved. */
-
-static void
-exchange (char **argv, struct _getopt_data *d)
-{
- int bottom = d->__first_nonopt;
- int middle = d->__last_nonopt;
- int top = d->optind;
- char *tem;
-
- /* Exchange the shorter segment with the far end of the longer segment.
- That puts the shorter segment into the right place.
- It leaves the longer segment in the right place overall,
- but it consists of two parts that need to be swapped next. */
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
- /* First make sure the handling of the '__getopt_nonoption_flags'
- string can work normally. Our top argument must be in the range
- of the string. */
- if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
- {
- /* We must extend the array. The user plays games with us and
- presents new arguments. */
- char *new_str = malloc (top + 1);
- if (new_str == NULL)
- d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
- else
- {
- memset (__mempcpy (new_str, __getopt_nonoption_flags,
- d->__nonoption_flags_max_len),
- '\0', top + 1 - d->__nonoption_flags_max_len);
- d->__nonoption_flags_max_len = top + 1;
- __getopt_nonoption_flags = new_str;
- }
- }
-#endif
-
- while (top > middle && middle > bottom)
- {
- if (top - middle > middle - bottom)
- {
- /* Bottom segment is the short one. */
- int len = middle - bottom;
+/* Getopt for GNU.
+ NOTE: getopt is part of the C library, so if you don't know what
+ "Keep this file name-space clean" means, talk to drepper@gnu.org
+ before changing it!
+ Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LIBC
+# include <config.h>
+#endif
+
+#include "getopt.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else
+# include "gettext.h"
+# define _(msgid) gettext (msgid)
+#endif
+
+#if defined _LIBC && defined USE_IN_LIBIO
+# include <wchar.h>
+#endif
+
+/* This version of 'getopt' appears to the caller like standard Unix 'getopt'
+ but it behaves differently for the user, since it allows the user
+ to intersperse the options with the other arguments.
+
+ As 'getopt_long' works, it permutes the elements of ARGV so that,
+ when it is done, all the options precede everything else. Thus
+ all application programs are extended to handle flexible argument order.
+
+ Using 'getopt' or setting the environment variable POSIXLY_CORRECT
+ disables permutation.
+ Then the behavior is completely standard.
+
+ GNU application programs can use a third alternative mode in which
+ they can distinguish the relative order of options and other arguments. */
+
+#include "getopt_int.h"
+
+/* For communication from 'getopt' to the caller.
+ When 'getopt' finds an option that takes an argument,
+ the argument value is returned here.
+ Also, when 'ordering' is RETURN_IN_ORDER,
+ each non-option ARGV-element is returned here. */
+
+char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+ This is used for communication to and from the caller
+ and for communication between successive calls to 'getopt'.
+
+ On entry to 'getopt', zero means this is the first call; initialize.
+
+ When 'getopt' returns -1, this is the index of the first of the
+ non-option elements that the caller should itself scan.
+
+ Otherwise, 'optind' communicates from one call to the next
+ how much of ARGV has been scanned so far. */
+
+/* 1003.2 says this must be 1 before any call. */
+int optind = 1;
+
+/* Callers store zero here to inhibit the error message
+ for unrecognized options. */
+
+int opterr = 1;
+
+/* Set to an option character which was unrecognized.
+ This must be initialized on some systems to avoid linking in the
+ system's own getopt implementation. */
+
+int optopt = '?';
+
+/* Keep a global copy of all internal members of getopt_data. */
+
+static struct _getopt_data getopt_data;
+
+
+#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
+extern char *getenv ();
+#endif
+
+#ifdef _LIBC
+/* Stored original parameters.
+ XXX This is no good solution. We should rather copy the args so
+ that we can compare them later. But we must not use malloc(3). */
+extern int __libc_argc;
+extern char **__libc_argv;
+
+/* Bash 2.0 gives us an environment variable containing flags
+ indicating ARGV elements that should not be considered arguments. */
+
+# ifdef USE_NONOPTION_FLAGS
+/* Defined in getopt_init.c */
+extern char *__getopt_nonoption_flags;
+# endif
+
+# ifdef USE_NONOPTION_FLAGS
+# define SWAP_FLAGS(ch1, ch2) \
+ if (d->__nonoption_flags_len > 0) \
+ { \
+ char __tmp = __getopt_nonoption_flags[ch1]; \
+ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
+ __getopt_nonoption_flags[ch2] = __tmp; \
+ }
+# else
+# define SWAP_FLAGS(ch1, ch2)
+# endif
+#else /* !_LIBC */
+# define SWAP_FLAGS(ch1, ch2)
+#endif /* _LIBC */
+
+/* Exchange two adjacent subsequences of ARGV.
+ One subsequence is elements [first_nonopt,last_nonopt)
+ which contains all the non-options that have been skipped so far.
+ The other is elements [last_nonopt,optind), which contains all
+ the options processed since those non-options were skipped.
+
+ 'first_nonopt' and 'last_nonopt' are relocated so that they describe
+ the new indices of the non-options in ARGV after they are moved. */
+
+static void
+exchange (char **argv, struct _getopt_data *d)
+{
+ int bottom = d->__first_nonopt;
+ int middle = d->__last_nonopt;
+ int top = d->optind;
+ char *tem;
+
+ /* Exchange the shorter segment with the far end of the longer segment.
+ That puts the shorter segment into the right place.
+ It leaves the longer segment in the right place overall,
+ but it consists of two parts that need to be swapped next. */
+
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+ /* First make sure the handling of the '__getopt_nonoption_flags'
+ string can work normally. Our top argument must be in the range
+ of the string. */
+ if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
+ {
+ /* We must extend the array. The user plays games with us and
+ presents new arguments. */
+ char *new_str = malloc (top + 1);
+ if (new_str == NULL)
+ d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
+ else
+ {
+ memset (__mempcpy (new_str, __getopt_nonoption_flags,
+ d->__nonoption_flags_max_len),
+ '\0', top + 1 - d->__nonoption_flags_max_len);
+ d->__nonoption_flags_max_len = top + 1;
+ __getopt_nonoption_flags = new_str;
+ }
+ }
+#endif
+
+ while (top > middle && middle > bottom)
+ {
+ if (top - middle > middle - bottom)
+ {
+ /* Bottom segment is the short one. */
+ int len = middle - bottom;
int i;
-
- /* Swap it with the top part of the top segment. */
- for (i = 0; i < len; i++)
- {
- tem = argv[bottom + i];
- argv[bottom + i] = argv[top - (middle - bottom) + i];
- argv[top - (middle - bottom) + i] = tem;
- SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
- }
- /* Exclude the moved bottom segment from further swapping. */
- top -= len;
- }
- else
- {
- /* Top segment is the short one. */
- int len = top - middle;
+
+ /* Swap it with the top part of the top segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[top - (middle - bottom) + i];
+ argv[top - (middle - bottom) + i] = tem;
+ SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
+ }
+ /* Exclude the moved bottom segment from further swapping. */
+ top -= len;
+ }
+ else
+ {
+ /* Top segment is the short one. */
+ int len = top - middle;
int i;
-
- /* Swap it with the bottom part of the bottom segment. */
- for (i = 0; i < len; i++)
- {
- tem = argv[bottom + i];
- argv[bottom + i] = argv[middle + i];
- argv[middle + i] = tem;
- SWAP_FLAGS (bottom + i, middle + i);
- }
- /* Exclude the moved top segment from further swapping. */
- bottom += len;
- }
- }
-
- /* Update records for the slots the non-options now occupy. */
-
- d->__first_nonopt += (d->optind - d->__last_nonopt);
- d->__last_nonopt = d->optind;
-}
-
-/* Initialize the internal data when the first call is made. */
-
-static const char *
-_getopt_initialize (int argc _GL_UNUSED,
- char **argv _GL_UNUSED, const char *optstring,
- struct _getopt_data *d, int posixly_correct)
-{
- /* Start processing options with ARGV-element 1 (since ARGV-element 0
- is the program name); the sequence of previously skipped
- non-option ARGV-elements is empty. */
-
- d->__first_nonopt = d->__last_nonopt = d->optind;
-
- d->__nextchar = NULL;
-
- d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
-
- /* Determine how to handle the ordering of options and nonoptions. */
-
- if (optstring[0] == '-')
- {
- d->__ordering = RETURN_IN_ORDER;
- ++optstring;
- }
- else if (optstring[0] == '+')
- {
- d->__ordering = REQUIRE_ORDER;
- ++optstring;
- }
- else if (d->__posixly_correct)
- d->__ordering = REQUIRE_ORDER;
- else
- d->__ordering = PERMUTE;
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
- if (!d->__posixly_correct
- && argc == __libc_argc && argv == __libc_argv)
- {
- if (d->__nonoption_flags_max_len == 0)
- {
- if (__getopt_nonoption_flags == NULL
- || __getopt_nonoption_flags[0] == '\0')
- d->__nonoption_flags_max_len = -1;
- else
- {
- const char *orig_str = __getopt_nonoption_flags;
- int len = d->__nonoption_flags_max_len = strlen (orig_str);
- if (d->__nonoption_flags_max_len < argc)
- d->__nonoption_flags_max_len = argc;
- __getopt_nonoption_flags =
- (char *) malloc (d->__nonoption_flags_max_len);
- if (__getopt_nonoption_flags == NULL)
- d->__nonoption_flags_max_len = -1;
- else
- memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
- '\0', d->__nonoption_flags_max_len - len);
- }
- }
- d->__nonoption_flags_len = d->__nonoption_flags_max_len;
- }
- else
- d->__nonoption_flags_len = 0;
-#endif
-
- return optstring;
-}
-
-/* Scan elements of ARGV (whose length is ARGC) for option characters
- given in OPTSTRING.
-
- If an element of ARGV starts with '-', and is not exactly "-" or "--",
- then it is an option element. The characters of this element
- (aside from the initial '-') are option characters. If 'getopt'
- is called repeatedly, it returns successively each of the option characters
- from each of the option elements.
-
- If 'getopt' finds another option character, it returns that character,
- updating 'optind' and 'nextchar' so that the next call to 'getopt' can
- resume the scan with the following option character or ARGV-element.
-
- If there are no more option characters, 'getopt' returns -1.
- Then 'optind' is the index in ARGV of the first ARGV-element
- that is not an option. (The ARGV-elements have been permuted
- so that those that are not options now come last.)
-
- OPTSTRING is a string containing the legitimate option characters.
- If an option character is seen that is not listed in OPTSTRING,
- return '?' after printing an error message. If you set 'opterr' to
- zero, the error message is suppressed but we still return '?'.
-
- If a char in OPTSTRING is followed by a colon, that means it wants an arg,
- so the following text in the same ARGV-element, or the text of the following
- ARGV-element, is returned in 'optarg'. Two colons mean an option that
- wants an optional arg; if there is text in the current ARGV-element,
- it is returned in 'optarg', otherwise 'optarg' is set to zero.
-
- If OPTSTRING starts with '-' or '+', it requests different methods of
- handling the non-option ARGV-elements.
- See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
-
- Long-named options begin with '--' instead of '-'.
- Their names may be abbreviated as long as the abbreviation is unique
- or is an exact match for some defined option. If they have an
- argument, it follows the option name in the same ARGV-element, separated
- from the option name by a '=', or else the in next ARGV-element.
- When 'getopt' finds a long-named option, it returns 0 if that option's
- 'flag' field is nonzero, the value of the option's 'val' field
- if the 'flag' field is zero.
-
- The elements of ARGV aren't really const, because we permute them.
- But we pretend they're const in the prototype to be compatible
- with other systems.
-
- LONGOPTS is a vector of 'struct option' terminated by an
- element containing a name which is zero.
-
- LONGIND returns the index in LONGOPT of the long-named option found.
- It is only valid when a long-named option has been found by the most
- recent call.
-
- If LONG_ONLY is nonzero, '-' as well as '--' can introduce
- long-named options. */
-
-int
-_getopt_internal_r (int argc, char **argv, const char *optstring,
- const struct option *longopts, int *longind,
- int long_only, struct _getopt_data *d, int posixly_correct)
-{
- int print_errors = d->opterr;
-
- if (argc < 1)
- return -1;
-
- d->optarg = NULL;
-
- if (d->optind == 0 || !d->__initialized)
- {
- if (d->optind == 0)
- d->optind = 1; /* Don't scan ARGV[0], the program name. */
- optstring = _getopt_initialize (argc, argv, optstring, d,
- posixly_correct);
- d->__initialized = 1;
- }
- else if (optstring[0] == '-' || optstring[0] == '+')
- optstring++;
- if (optstring[0] == ':')
- print_errors = 0;
-
- /* Test whether ARGV[optind] points to a non-option argument.
- Either it does not have option syntax, or there is an environment flag
- from the shell indicating it is not an option. The later information
- is only used when the used in the GNU libc. */
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
- || (d->optind < d->__nonoption_flags_len \
- && __getopt_nonoption_flags[d->optind] == '1'))
-#else
-# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
-#endif
-
- if (d->__nextchar == NULL || *d->__nextchar == '\0')
- {
- /* Advance to the next ARGV-element. */
-
- /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
- moved back by the user (who may also have changed the arguments). */
- if (d->__last_nonopt > d->optind)
- d->__last_nonopt = d->optind;
- if (d->__first_nonopt > d->optind)
- d->__first_nonopt = d->optind;
-
- if (d->__ordering == PERMUTE)
- {
- /* If we have just processed some options following some non-options,
- exchange them so that the options come first. */
-
- if (d->__first_nonopt != d->__last_nonopt
- && d->__last_nonopt != d->optind)
- exchange ((char **) argv, d);
- else if (d->__last_nonopt != d->optind)
- d->__first_nonopt = d->optind;
-
- /* Skip any additional non-options
- and extend the range of non-options previously skipped. */
-
- while (d->optind < argc && NONOPTION_P)
- d->optind++;
- d->__last_nonopt = d->optind;
- }
-
- /* The special ARGV-element '--' means premature end of options.
- Skip it like a null option,
- then exchange with previous non-options as if it were an option,
- then skip everything else like a non-option. */
-
- if (d->optind != argc && !strcmp (argv[d->optind], "--"))
- {
- d->optind++;
-
- if (d->__first_nonopt != d->__last_nonopt
- && d->__last_nonopt != d->optind)
- exchange ((char **) argv, d);
- else if (d->__first_nonopt == d->__last_nonopt)
- d->__first_nonopt = d->optind;
- d->__last_nonopt = argc;
-
- d->optind = argc;
- }
-
- /* If we have done all the ARGV-elements, stop the scan
- and back over any non-options that we skipped and permuted. */
-
- if (d->optind == argc)
- {
- /* Set the next-arg-index to point at the non-options
- that we previously skipped, so the caller will digest them. */
- if (d->__first_nonopt != d->__last_nonopt)
- d->optind = d->__first_nonopt;
- return -1;
- }
-
- /* If we have come to a non-option and did not permute it,
- either stop the scan or describe it to the caller and pass it by. */
-
- if (NONOPTION_P)
- {
- if (d->__ordering == REQUIRE_ORDER)
- return -1;
- d->optarg = argv[d->optind++];
- return 1;
- }
-
- /* We have found another option-ARGV-element.
- Skip the initial punctuation. */
-
- d->__nextchar = (argv[d->optind] + 1
- + (longopts != NULL && argv[d->optind][1] == '-'));
- }
-
- /* Decode the current option-ARGV-element. */
-
- /* Check whether the ARGV-element is a long option.
-
- If long_only and the ARGV-element has the form "-f", where f is
- a valid short option, don't consider it an abbreviated form of
- a long option that starts with f. Otherwise there would be no
- way to give the -f short option.
-
- On the other hand, if there's a long option "fubar" and
- the ARGV-element is "-fu", do consider that an abbreviation of
- the long option, just like "--fu", and not "-f" with arg "u".
-
- This distinction seems to be the most useful approach. */
-
- if (longopts != NULL
- && (argv[d->optind][1] == '-'
- || (long_only && (argv[d->optind][2]
- || !strchr (optstring, argv[d->optind][1])))))
- {
- char *nameend;
- unsigned int namelen;
- const struct option *p;
- const struct option *pfound = NULL;
- struct option_list
- {
- const struct option *p;
- struct option_list *next;
- } *ambig_list = NULL;
- int exact = 0;
- int indfound = -1;
- int option_index;
-
- for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
- /* Do nothing. */ ;
- namelen = nameend - d->__nextchar;
-
- /* Test all long options for either exact match
- or abbreviated matches. */
- for (p = longopts, option_index = 0; p->name; p++, option_index++)
- if (!strncmp (p->name, d->__nextchar, namelen))
- {
- if (namelen == (unsigned int) strlen (p->name))
- {
- /* Exact match found. */
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- }
- else if (pfound == NULL)
- {
- /* First nonexact match found. */
- pfound = p;
- indfound = option_index;
- }
- else if (long_only
- || pfound->has_arg != p->has_arg
- || pfound->flag != p->flag
- || pfound->val != p->val)
- {
- /* Second or later nonexact match found. */
- struct option_list *newp = malloc (sizeof (*newp));
- newp->p = p;
- newp->next = ambig_list;
- ambig_list = newp;
- }
- }
-
- if (ambig_list != NULL && !exact)
- {
- if (print_errors)
- {
- struct option_list first;
- first.p = pfound;
- first.next = ambig_list;
- ambig_list = &first;
-
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf = NULL;
- size_t buflen = 0;
-
- FILE *fp = open_memstream (&buf, &buflen);
- if (fp != NULL)
- {
- fprintf (fp,
- _("%s: option '%s' is ambiguous; possibilities:"),
- argv[0], argv[d->optind]);
-
- do
- {
- fprintf (fp, " '--%s'", ambig_list->p->name);
- ambig_list = ambig_list->next;
- }
- while (ambig_list != NULL);
-
- fputc_unlocked ('\n', fp);
-
- if (__builtin_expect (fclose (fp) != EOF, 1))
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
- }
-#else
- fprintf (stderr,
- _("%s: option '%s' is ambiguous; possibilities:"),
- argv[0], argv[d->optind]);
- do
- {
- fprintf (stderr, " '--%s'", ambig_list->p->name);
- ambig_list = ambig_list->next;
- }
- while (ambig_list != NULL);
-
- fputc ('\n', stderr);
-#endif
- }
- d->__nextchar += strlen (d->__nextchar);
- d->optind++;
- d->optopt = 0;
- return '?';
- }
-
- while (ambig_list != NULL)
- {
- struct option_list *pn = ambig_list->next;
- free (ambig_list);
- ambig_list = pn;
- }
-
- if (pfound != NULL)
- {
- option_index = indfound;
- d->optind++;
- if (*nameend)
- {
- /* Don't test has_arg with >, because some C compilers don't
- allow it to be used on enums. */
- if (pfound->has_arg)
- d->optarg = nameend + 1;
- else
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
- int n;
-#endif
-
- if (argv[d->optind - 1][1] == '-')
- {
- /* --option */
-#if defined _LIBC && defined USE_IN_LIBIO
- n = __asprintf (&buf, _("\
-%s: option '--%s' doesn't allow an argument\n"),
- argv[0], pfound->name);
-#else
- fprintf (stderr, _("\
-%s: option '--%s' doesn't allow an argument\n"),
- argv[0], pfound->name);
-#endif
- }
- else
- {
- /* +option or -option */
-#if defined _LIBC && defined USE_IN_LIBIO
- n = __asprintf (&buf, _("\
-%s: option '%c%s' doesn't allow an argument\n"),
- argv[0], argv[d->optind - 1][0],
- pfound->name);
-#else
- fprintf (stderr, _("\
-%s: option '%c%s' doesn't allow an argument\n"),
- argv[0], argv[d->optind - 1][0],
- pfound->name);
-#endif
- }
-
-#if defined _LIBC && defined USE_IN_LIBIO
- if (n >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2
- |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#endif
- }
-
- d->__nextchar += strlen (d->__nextchar);
-
- d->optopt = pfound->val;
- return '?';
- }
- }
- else if (pfound->has_arg == 1)
- {
- if (d->optind < argc)
- d->optarg = argv[d->optind++];
- else
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
-
- if (__asprintf (&buf, _("\
-%s: option '--%s' requires an argument\n"),
- argv[0], pfound->name) >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2
- |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#else
- fprintf (stderr,
- _("%s: option '--%s' requires an argument\n"),
- argv[0], pfound->name);
-#endif
- }
- d->__nextchar += strlen (d->__nextchar);
- d->optopt = pfound->val;
- return optstring[0] == ':' ? ':' : '?';
- }
- }
- d->__nextchar += strlen (d->__nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag)
- {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
-
- /* Can't find it as a long option. If this is not getopt_long_only,
- or the option starts with '--' or is not a valid short
- option, then it's an error.
- Otherwise interpret it as a short option. */
- if (!long_only || argv[d->optind][1] == '-'
- || strchr (optstring, *d->__nextchar) == NULL)
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
- int n;
-#endif
-
- if (argv[d->optind][1] == '-')
- {
- /* --option */
-#if defined _LIBC && defined USE_IN_LIBIO
- n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
- argv[0], d->__nextchar);
-#else
- fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
- argv[0], d->__nextchar);
-#endif
- }
- else
- {
- /* +option or -option */
-#if defined _LIBC && defined USE_IN_LIBIO
- n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
- argv[0], argv[d->optind][0], d->__nextchar);
-#else
- fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
- argv[0], argv[d->optind][0], d->__nextchar);
-#endif
- }
-
-#if defined _LIBC && defined USE_IN_LIBIO
- if (n >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#endif
- }
- d->__nextchar = (char *) "";
- d->optind++;
- d->optopt = 0;
- return '?';
- }
- }
-
- /* Look at and handle the next short option-character. */
-
- {
- char c = *d->__nextchar++;
- const char *temp = strchr (optstring, c);
-
- /* Increment 'optind' when we start to process its last character. */
- if (*d->__nextchar == '\0')
- ++d->optind;
-
- if (temp == NULL || c == ':' || c == ';')
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
- int n;
-#endif
-
-#if defined _LIBC && defined USE_IN_LIBIO
- n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
- argv[0], c);
-#else
- fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
-#endif
-
-#if defined _LIBC && defined USE_IN_LIBIO
- if (n >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#endif
- }
- d->optopt = c;
- return '?';
- }
- /* Convenience. Treat POSIX -W foo same as long option --foo */
- if (temp[0] == 'W' && temp[1] == ';')
- {
- char *nameend;
- const struct option *p;
- const struct option *pfound = NULL;
- int exact = 0;
- int ambig = 0;
- int indfound = 0;
- int option_index;
-
- if (longopts == NULL)
- goto no_longs;
-
- /* This is an option that requires an argument. */
- if (*d->__nextchar != '\0')
- {
- d->optarg = d->__nextchar;
- /* If we end this ARGV-element by taking the rest as an arg,
- we must advance to the next element now. */
- d->optind++;
- }
- else if (d->optind == argc)
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
-
- if (__asprintf (&buf,
- _("%s: option requires an argument -- '%c'\n"),
- argv[0], c) >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#else
- fprintf (stderr,
- _("%s: option requires an argument -- '%c'\n"),
- argv[0], c);
-#endif
- }
- d->optopt = c;
- if (optstring[0] == ':')
- c = ':';
- else
- c = '?';
- return c;
- }
- else
- /* We already incremented 'd->optind' once;
- increment it again when taking next ARGV-elt as argument. */
- d->optarg = argv[d->optind++];
-
- /* optarg is now the argument, see if it's in the
- table of longopts. */
-
- for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
- nameend++)
- /* Do nothing. */ ;
-
- /* Test all long options for either exact match
- or abbreviated matches. */
- for (p = longopts, option_index = 0; p->name; p++, option_index++)
- if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
- {
- if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
- {
- /* Exact match found. */
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- }
- else if (pfound == NULL)
- {
- /* First nonexact match found. */
- pfound = p;
- indfound = option_index;
- }
- else if (long_only
- || pfound->has_arg != p->has_arg
- || pfound->flag != p->flag
- || pfound->val != p->val)
- /* Second or later nonexact match found. */
- ambig = 1;
- }
- if (ambig && !exact)
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
-
- if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
- argv[0], d->optarg) >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#else
- fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
- argv[0], d->optarg);
-#endif
- }
- d->__nextchar += strlen (d->__nextchar);
- d->optind++;
- return '?';
- }
- if (pfound != NULL)
- {
- option_index = indfound;
- if (*nameend)
- {
- /* Don't test has_arg with >, because some C compilers don't
- allow it to be used on enums. */
- if (pfound->has_arg)
- d->optarg = nameend + 1;
- else
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
-
- if (__asprintf (&buf, _("\
-%s: option '-W %s' doesn't allow an argument\n"),
- argv[0], pfound->name) >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2
- |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#else
- fprintf (stderr, _("\
-%s: option '-W %s' doesn't allow an argument\n"),
- argv[0], pfound->name);
-#endif
- }
-
- d->__nextchar += strlen (d->__nextchar);
- return '?';
- }
- }
- else if (pfound->has_arg == 1)
- {
- if (d->optind < argc)
- d->optarg = argv[d->optind++];
- else
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
-
- if (__asprintf (&buf, _("\
-%s: option '-W %s' requires an argument\n"),
- argv[0], pfound->name) >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2
- |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#else
- fprintf (stderr, _("\
-%s: option '-W %s' requires an argument\n"),
- argv[0], pfound->name);
-#endif
- }
- d->__nextchar += strlen (d->__nextchar);
- return optstring[0] == ':' ? ':' : '?';
- }
- }
- else
- d->optarg = NULL;
- d->__nextchar += strlen (d->__nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag)
- {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
-
- no_longs:
- d->__nextchar = NULL;
- return 'W'; /* Let the application handle it. */
- }
- if (temp[1] == ':')
- {
- if (temp[2] == ':')
- {
- /* This is an option that accepts an argument optionally. */
- if (*d->__nextchar != '\0')
- {
- d->optarg = d->__nextchar;
- d->optind++;
- }
- else
- d->optarg = NULL;
- d->__nextchar = NULL;
- }
- else
- {
- /* This is an option that requires an argument. */
- if (*d->__nextchar != '\0')
- {
- d->optarg = d->__nextchar;
- /* If we end this ARGV-element by taking the rest as an arg,
- we must advance to the next element now. */
- d->optind++;
- }
- else if (d->optind == argc)
- {
- if (print_errors)
- {
-#if defined _LIBC && defined USE_IN_LIBIO
- char *buf;
-
- if (__asprintf (&buf, _("\
-%s: option requires an argument -- '%c'\n"),
- argv[0], c) >= 0)
- {
- _IO_flockfile (stderr);
-
- int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
- ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
-
- __fxprintf (NULL, "%s", buf);
-
- ((_IO_FILE *) stderr)->_flags2 = old_flags2;
- _IO_funlockfile (stderr);
-
- free (buf);
- }
-#else
- fprintf (stderr,
- _("%s: option requires an argument -- '%c'\n"),
- argv[0], c);
-#endif
- }
- d->optopt = c;
- if (optstring[0] == ':')
- c = ':';
- else
- c = '?';
- }
- else
- /* We already incremented 'optind' once;
- increment it again when taking next ARGV-elt as argument. */
- d->optarg = argv[d->optind++];
- d->__nextchar = NULL;
- }
- }
- return c;
- }
-}
-
-int
-_getopt_internal (int argc, char **argv, const char *optstring,
- const struct option *longopts, int *longind, int long_only,
- int posixly_correct)
-{
- int result;
-
- getopt_data.optind = optind;
- getopt_data.opterr = opterr;
-
- result = _getopt_internal_r (argc, argv, optstring, longopts,
- longind, long_only, &getopt_data,
- posixly_correct);
-
- optind = getopt_data.optind;
- optarg = getopt_data.optarg;
- optopt = getopt_data.optopt;
-
- return result;
-}
-
-/* glibc gets a LSB-compliant getopt.
- Standalone applications get a POSIX-compliant getopt. */
-#if _LIBC
-enum { POSIXLY_CORRECT = 0 };
-#else
-enum { POSIXLY_CORRECT = 1 };
-#endif
-
-int
-getopt (int argc, char *const *argv, const char *optstring)
-{
- return _getopt_internal (argc, (char **) argv, optstring,
- (const struct option *) 0,
- (int *) 0,
- 0, POSIXLY_CORRECT);
-}
-
-#ifdef _LIBC
-int
-__posix_getopt (int argc, char *const *argv, const char *optstring)
-{
- return _getopt_internal (argc, argv, optstring,
- (const struct option *) 0,
- (int *) 0,
- 0, 1);
-}
-#endif
-
-
-#ifdef TEST
-
-/* Compile with -DTEST to make an executable for use in testing
- the above definition of 'getopt'. */
-
-int
-main (int argc, char **argv)
-{
- int c;
- int digit_optind = 0;
-
- while (1)
- {
- int this_option_optind = optind ? optind : 1;
-
- c = getopt (argc, argv, "abc:d:0123456789");
- if (c == -1)
- break;
-
- switch (c)
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (digit_optind != 0 && digit_optind != this_option_optind)
- printf ("digits occur in two different argv-elements.\n");
- digit_optind = this_option_optind;
- printf ("option %c\n", c);
- break;
-
- case 'a':
- printf ("option a\n");
- break;
-
- case 'b':
- printf ("option b\n");
- break;
-
- case 'c':
- printf ("option c with value '%s'\n", optarg);
- break;
-
- case '?':
- break;
-
- default:
- printf ("?? getopt returned character code 0%o ??\n", c);
- }
- }
-
- if (optind < argc)
- {
- printf ("non-option ARGV-elements: ");
- while (optind < argc)
- printf ("%s ", argv[optind++]);
- printf ("\n");
- }
-
- exit (0);
-}
-
-#endif /* TEST */
+
+ /* Swap it with the bottom part of the bottom segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[middle + i];
+ argv[middle + i] = tem;
+ SWAP_FLAGS (bottom + i, middle + i);
+ }
+ /* Exclude the moved top segment from further swapping. */
+ bottom += len;
+ }
+ }
+
+ /* Update records for the slots the non-options now occupy. */
+
+ d->__first_nonopt += (d->optind - d->__last_nonopt);
+ d->__last_nonopt = d->optind;
+}
+
+/* Initialize the internal data when the first call is made. */
+
+static const char *
+_getopt_initialize (int argc _GL_UNUSED,
+ char **argv _GL_UNUSED, const char *optstring,
+ struct _getopt_data *d, int posixly_correct)
+{
+ /* Start processing options with ARGV-element 1 (since ARGV-element 0
+ is the program name); the sequence of previously skipped
+ non-option ARGV-elements is empty. */
+
+ d->__first_nonopt = d->__last_nonopt = d->optind;
+
+ d->__nextchar = NULL;
+
+ d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
+
+ /* Determine how to handle the ordering of options and nonoptions. */
+
+ if (optstring[0] == '-')
+ {
+ d->__ordering = RETURN_IN_ORDER;
+ ++optstring;
+ }
+ else if (optstring[0] == '+')
+ {
+ d->__ordering = REQUIRE_ORDER;
+ ++optstring;
+ }
+ else if (d->__posixly_correct)
+ d->__ordering = REQUIRE_ORDER;
+ else
+ d->__ordering = PERMUTE;
+
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+ if (!d->__posixly_correct
+ && argc == __libc_argc && argv == __libc_argv)
+ {
+ if (d->__nonoption_flags_max_len == 0)
+ {
+ if (__getopt_nonoption_flags == NULL
+ || __getopt_nonoption_flags[0] == '\0')
+ d->__nonoption_flags_max_len = -1;
+ else
+ {
+ const char *orig_str = __getopt_nonoption_flags;
+ int len = d->__nonoption_flags_max_len = strlen (orig_str);
+ if (d->__nonoption_flags_max_len < argc)
+ d->__nonoption_flags_max_len = argc;
+ __getopt_nonoption_flags =
+ (char *) malloc (d->__nonoption_flags_max_len);
+ if (__getopt_nonoption_flags == NULL)
+ d->__nonoption_flags_max_len = -1;
+ else
+ memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
+ '\0', d->__nonoption_flags_max_len - len);
+ }
+ }
+ d->__nonoption_flags_len = d->__nonoption_flags_max_len;
+ }
+ else
+ d->__nonoption_flags_len = 0;
+#endif
+
+ return optstring;
+}
+
+/* Scan elements of ARGV (whose length is ARGC) for option characters
+ given in OPTSTRING.
+
+ If an element of ARGV starts with '-', and is not exactly "-" or "--",
+ then it is an option element. The characters of this element
+ (aside from the initial '-') are option characters. If 'getopt'
+ is called repeatedly, it returns successively each of the option characters
+ from each of the option elements.
+
+ If 'getopt' finds another option character, it returns that character,
+ updating 'optind' and 'nextchar' so that the next call to 'getopt' can
+ resume the scan with the following option character or ARGV-element.
+
+ If there are no more option characters, 'getopt' returns -1.
+ Then 'optind' is the index in ARGV of the first ARGV-element
+ that is not an option. (The ARGV-elements have been permuted
+ so that those that are not options now come last.)
+
+ OPTSTRING is a string containing the legitimate option characters.
+ If an option character is seen that is not listed in OPTSTRING,
+ return '?' after printing an error message. If you set 'opterr' to
+ zero, the error message is suppressed but we still return '?'.
+
+ If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+ so the following text in the same ARGV-element, or the text of the following
+ ARGV-element, is returned in 'optarg'. Two colons mean an option that
+ wants an optional arg; if there is text in the current ARGV-element,
+ it is returned in 'optarg', otherwise 'optarg' is set to zero.
+
+ If OPTSTRING starts with '-' or '+', it requests different methods of
+ handling the non-option ARGV-elements.
+ See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
+
+ Long-named options begin with '--' instead of '-'.
+ Their names may be abbreviated as long as the abbreviation is unique
+ or is an exact match for some defined option. If they have an
+ argument, it follows the option name in the same ARGV-element, separated
+ from the option name by a '=', or else the in next ARGV-element.
+ When 'getopt' finds a long-named option, it returns 0 if that option's
+ 'flag' field is nonzero, the value of the option's 'val' field
+ if the 'flag' field is zero.
+
+ The elements of ARGV aren't really const, because we permute them.
+ But we pretend they're const in the prototype to be compatible
+ with other systems.
+
+ LONGOPTS is a vector of 'struct option' terminated by an
+ element containing a name which is zero.
+
+ LONGIND returns the index in LONGOPT of the long-named option found.
+ It is only valid when a long-named option has been found by the most
+ recent call.
+
+ If LONG_ONLY is nonzero, '-' as well as '--' can introduce
+ long-named options. */
+
+int
+_getopt_internal_r (int argc, char **argv, const char *optstring,
+ const struct option *longopts, int *longind,
+ int long_only, struct _getopt_data *d, int posixly_correct)
+{
+ int print_errors = d->opterr;
+
+ if (argc < 1)
+ return -1;
+
+ d->optarg = NULL;
+
+ if (d->optind == 0 || !d->__initialized)
+ {
+ if (d->optind == 0)
+ d->optind = 1; /* Don't scan ARGV[0], the program name. */
+ optstring = _getopt_initialize (argc, argv, optstring, d,
+ posixly_correct);
+ d->__initialized = 1;
+ }
+ else if (optstring[0] == '-' || optstring[0] == '+')
+ optstring++;
+ if (optstring[0] == ':')
+ print_errors = 0;
+
+ /* Test whether ARGV[optind] points to a non-option argument.
+ Either it does not have option syntax, or there is an environment flag
+ from the shell indicating it is not an option. The later information
+ is only used when the used in the GNU libc. */
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
+ || (d->optind < d->__nonoption_flags_len \
+ && __getopt_nonoption_flags[d->optind] == '1'))
+#else
+# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
+#endif
+
+ if (d->__nextchar == NULL || *d->__nextchar == '\0')
+ {
+ /* Advance to the next ARGV-element. */
+
+ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
+ moved back by the user (who may also have changed the arguments). */
+ if (d->__last_nonopt > d->optind)
+ d->__last_nonopt = d->optind;
+ if (d->__first_nonopt > d->optind)
+ d->__first_nonopt = d->optind;
+
+ if (d->__ordering == PERMUTE)
+ {
+ /* If we have just processed some options following some non-options,
+ exchange them so that the options come first. */
+
+ if (d->__first_nonopt != d->__last_nonopt
+ && d->__last_nonopt != d->optind)
+ exchange ((char **) argv, d);
+ else if (d->__last_nonopt != d->optind)
+ d->__first_nonopt = d->optind;
+
+ /* Skip any additional non-options
+ and extend the range of non-options previously skipped. */
+
+ while (d->optind < argc && NONOPTION_P)
+ d->optind++;
+ d->__last_nonopt = d->optind;
+ }
+
+ /* The special ARGV-element '--' means premature end of options.
+ Skip it like a null option,
+ then exchange with previous non-options as if it were an option,
+ then skip everything else like a non-option. */
+
+ if (d->optind != argc && !strcmp (argv[d->optind], "--"))
+ {
+ d->optind++;
+
+ if (d->__first_nonopt != d->__last_nonopt
+ && d->__last_nonopt != d->optind)
+ exchange ((char **) argv, d);
+ else if (d->__first_nonopt == d->__last_nonopt)
+ d->__first_nonopt = d->optind;
+ d->__last_nonopt = argc;
+
+ d->optind = argc;
+ }
+
+ /* If we have done all the ARGV-elements, stop the scan
+ and back over any non-options that we skipped and permuted. */
+
+ if (d->optind == argc)
+ {
+ /* Set the next-arg-index to point at the non-options
+ that we previously skipped, so the caller will digest them. */
+ if (d->__first_nonopt != d->__last_nonopt)
+ d->optind = d->__first_nonopt;
+ return -1;
+ }
+
+ /* If we have come to a non-option and did not permute it,
+ either stop the scan or describe it to the caller and pass it by. */
+
+ if (NONOPTION_P)
+ {
+ if (d->__ordering == REQUIRE_ORDER)
+ return -1;
+ d->optarg = argv[d->optind++];
+ return 1;
+ }
+
+ /* We have found another option-ARGV-element.
+ Skip the initial punctuation. */
+
+ d->__nextchar = (argv[d->optind] + 1
+ + (longopts != NULL && argv[d->optind][1] == '-'));
+ }
+
+ /* Decode the current option-ARGV-element. */
+
+ /* Check whether the ARGV-element is a long option.
+
+ If long_only and the ARGV-element has the form "-f", where f is
+ a valid short option, don't consider it an abbreviated form of
+ a long option that starts with f. Otherwise there would be no
+ way to give the -f short option.
+
+ On the other hand, if there's a long option "fubar" and
+ the ARGV-element is "-fu", do consider that an abbreviation of
+ the long option, just like "--fu", and not "-f" with arg "u".
+
+ This distinction seems to be the most useful approach. */
+
+ if (longopts != NULL
+ && (argv[d->optind][1] == '-'
+ || (long_only && (argv[d->optind][2]
+ || !strchr (optstring, argv[d->optind][1])))))
+ {
+ char *nameend;
+ unsigned int namelen;
+ const struct option *p;
+ const struct option *pfound = NULL;
+ struct option_list
+ {
+ const struct option *p;
+ struct option_list *next;
+ } *ambig_list = NULL;
+ int exact = 0;
+ int indfound = -1;
+ int option_index;
+
+ for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
+ /* Do nothing. */ ;
+ namelen = nameend - d->__nextchar;
+
+ /* Test all long options for either exact match
+ or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, d->__nextchar, namelen))
+ {
+ if (namelen == (unsigned int) strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else if (long_only
+ || pfound->has_arg != p->has_arg
+ || pfound->flag != p->flag
+ || pfound->val != p->val)
+ {
+ /* Second or later nonexact match found. */
+ struct option_list *newp = malloc (sizeof (*newp));
+ newp->p = p;
+ newp->next = ambig_list;
+ ambig_list = newp;
+ }
+ }
+
+ if (ambig_list != NULL && !exact)
+ {
+ if (print_errors)
+ {
+ struct option_list first;
+ first.p = pfound;
+ first.next = ambig_list;
+ ambig_list = &first;
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf = NULL;
+ size_t buflen = 0;
+
+ FILE *fp = open_memstream (&buf, &buflen);
+ if (fp != NULL)
+ {
+ fprintf (fp,
+ _("%s: option '%s' is ambiguous; possibilities:"),
+ argv[0], argv[d->optind]);
+
+ do
+ {
+ fprintf (fp, " '--%s'", ambig_list->p->name);
+ ambig_list = ambig_list->next;
+ }
+ while (ambig_list != NULL);
+
+ fputc_unlocked ('\n', fp);
+
+ if (__builtin_expect (fclose (fp) != EOF, 1))
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+ }
+#else
+ fprintf (stderr,
+ _("%s: option '%s' is ambiguous; possibilities:"),
+ argv[0], argv[d->optind]);
+ do
+ {
+ fprintf (stderr, " '--%s'", ambig_list->p->name);
+ ambig_list = ambig_list->next;
+ }
+ while (ambig_list != NULL);
+
+ fputc ('\n', stderr);
+#endif
+ }
+ d->__nextchar += strlen (d->__nextchar);
+ d->optind++;
+ d->optopt = 0;
+ return '?';
+ }
+
+ while (ambig_list != NULL)
+ {
+ struct option_list *pn = ambig_list->next;
+ free (ambig_list);
+ ambig_list = pn;
+ }
+
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ d->optind++;
+ if (*nameend)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ allow it to be used on enums. */
+ if (pfound->has_arg)
+ d->optarg = nameend + 1;
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+ int n;
+#endif
+
+ if (argv[d->optind - 1][1] == '-')
+ {
+ /* --option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("\
+%s: option '--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+#else
+ fprintf (stderr, _("\
+%s: option '--%s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+#endif
+ }
+ else
+ {
+ /* +option or -option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("\
+%s: option '%c%s' doesn't allow an argument\n"),
+ argv[0], argv[d->optind - 1][0],
+ pfound->name);
+#else
+ fprintf (stderr, _("\
+%s: option '%c%s' doesn't allow an argument\n"),
+ argv[0], argv[d->optind - 1][0],
+ pfound->name);
+#endif
+ }
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ if (n >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2
+ |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#endif
+ }
+
+ d->__nextchar += strlen (d->__nextchar);
+
+ d->optopt = pfound->val;
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (d->optind < argc)
+ d->optarg = argv[d->optind++];
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option '--%s' requires an argument\n"),
+ argv[0], pfound->name) >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2
+ |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr,
+ _("%s: option '--%s' requires an argument\n"),
+ argv[0], pfound->name);
+#endif
+ }
+ d->__nextchar += strlen (d->__nextchar);
+ d->optopt = pfound->val;
+ return optstring[0] == ':' ? ':' : '?';
+ }
+ }
+ d->__nextchar += strlen (d->__nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
+
+ /* Can't find it as a long option. If this is not getopt_long_only,
+ or the option starts with '--' or is not a valid short
+ option, then it's an error.
+ Otherwise interpret it as a short option. */
+ if (!long_only || argv[d->optind][1] == '-'
+ || strchr (optstring, *d->__nextchar) == NULL)
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+ int n;
+#endif
+
+ if (argv[d->optind][1] == '-')
+ {
+ /* --option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
+ argv[0], d->__nextchar);
+#else
+ fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
+ argv[0], d->__nextchar);
+#endif
+ }
+ else
+ {
+ /* +option or -option */
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
+ argv[0], argv[d->optind][0], d->__nextchar);
+#else
+ fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
+ argv[0], argv[d->optind][0], d->__nextchar);
+#endif
+ }
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ if (n >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#endif
+ }
+ d->__nextchar = (char *) "";
+ d->optind++;
+ d->optopt = 0;
+ return '?';
+ }
+ }
+
+ /* Look at and handle the next short option-character. */
+
+ {
+ char c = *d->__nextchar++;
+ const char *temp = strchr (optstring, c);
+
+ /* Increment 'optind' when we start to process its last character. */
+ if (*d->__nextchar == '\0')
+ ++d->optind;
+
+ if (temp == NULL || c == ':' || c == ';')
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+ int n;
+#endif
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
+ argv[0], c);
+#else
+ fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
+#endif
+
+#if defined _LIBC && defined USE_IN_LIBIO
+ if (n >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#endif
+ }
+ d->optopt = c;
+ return '?';
+ }
+ /* Convenience. Treat POSIX -W foo same as long option --foo */
+ if (temp[0] == 'W' && temp[1] == ';')
+ {
+ char *nameend;
+ const struct option *p;
+ const struct option *pfound = NULL;
+ int exact = 0;
+ int ambig = 0;
+ int indfound = 0;
+ int option_index;
+
+ if (longopts == NULL)
+ goto no_longs;
+
+ /* This is an option that requires an argument. */
+ if (*d->__nextchar != '\0')
+ {
+ d->optarg = d->__nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ d->optind++;
+ }
+ else if (d->optind == argc)
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf,
+ _("%s: option requires an argument -- '%c'\n"),
+ argv[0], c) >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr,
+ _("%s: option requires an argument -- '%c'\n"),
+ argv[0], c);
+#endif
+ }
+ d->optopt = c;
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = '?';
+ return c;
+ }
+ else
+ /* We already incremented 'd->optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ d->optarg = argv[d->optind++];
+
+ /* optarg is now the argument, see if it's in the
+ table of longopts. */
+
+ for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
+ nameend++)
+ /* Do nothing. */ ;
+
+ /* Test all long options for either exact match
+ or abbreviated matches. */
+ for (p = longopts, option_index = 0; p->name; p++, option_index++)
+ if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
+ {
+ if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
+ {
+ /* Exact match found. */
+ pfound = p;
+ indfound = option_index;
+ exact = 1;
+ break;
+ }
+ else if (pfound == NULL)
+ {
+ /* First nonexact match found. */
+ pfound = p;
+ indfound = option_index;
+ }
+ else if (long_only
+ || pfound->has_arg != p->has_arg
+ || pfound->flag != p->flag
+ || pfound->val != p->val)
+ /* Second or later nonexact match found. */
+ ambig = 1;
+ }
+ if (ambig && !exact)
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
+ argv[0], d->optarg) >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
+ argv[0], d->optarg);
+#endif
+ }
+ d->__nextchar += strlen (d->__nextchar);
+ d->optind++;
+ return '?';
+ }
+ if (pfound != NULL)
+ {
+ option_index = indfound;
+ if (*nameend)
+ {
+ /* Don't test has_arg with >, because some C compilers don't
+ allow it to be used on enums. */
+ if (pfound->has_arg)
+ d->optarg = nameend + 1;
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option '-W %s' doesn't allow an argument\n"),
+ argv[0], pfound->name) >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2
+ |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr, _("\
+%s: option '-W %s' doesn't allow an argument\n"),
+ argv[0], pfound->name);
+#endif
+ }
+
+ d->__nextchar += strlen (d->__nextchar);
+ return '?';
+ }
+ }
+ else if (pfound->has_arg == 1)
+ {
+ if (d->optind < argc)
+ d->optarg = argv[d->optind++];
+ else
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option '-W %s' requires an argument\n"),
+ argv[0], pfound->name) >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2
+ |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr, _("\
+%s: option '-W %s' requires an argument\n"),
+ argv[0], pfound->name);
+#endif
+ }
+ d->__nextchar += strlen (d->__nextchar);
+ return optstring[0] == ':' ? ':' : '?';
+ }
+ }
+ else
+ d->optarg = NULL;
+ d->__nextchar += strlen (d->__nextchar);
+ if (longind != NULL)
+ *longind = option_index;
+ if (pfound->flag)
+ {
+ *(pfound->flag) = pfound->val;
+ return 0;
+ }
+ return pfound->val;
+ }
+
+ no_longs:
+ d->__nextchar = NULL;
+ return 'W'; /* Let the application handle it. */
+ }
+ if (temp[1] == ':')
+ {
+ if (temp[2] == ':')
+ {
+ /* This is an option that accepts an argument optionally. */
+ if (*d->__nextchar != '\0')
+ {
+ d->optarg = d->__nextchar;
+ d->optind++;
+ }
+ else
+ d->optarg = NULL;
+ d->__nextchar = NULL;
+ }
+ else
+ {
+ /* This is an option that requires an argument. */
+ if (*d->__nextchar != '\0')
+ {
+ d->optarg = d->__nextchar;
+ /* If we end this ARGV-element by taking the rest as an arg,
+ we must advance to the next element now. */
+ d->optind++;
+ }
+ else if (d->optind == argc)
+ {
+ if (print_errors)
+ {
+#if defined _LIBC && defined USE_IN_LIBIO
+ char *buf;
+
+ if (__asprintf (&buf, _("\
+%s: option requires an argument -- '%c'\n"),
+ argv[0], c) >= 0)
+ {
+ _IO_flockfile (stderr);
+
+ int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
+ ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
+
+ __fxprintf (NULL, "%s", buf);
+
+ ((_IO_FILE *) stderr)->_flags2 = old_flags2;
+ _IO_funlockfile (stderr);
+
+ free (buf);
+ }
+#else
+ fprintf (stderr,
+ _("%s: option requires an argument -- '%c'\n"),
+ argv[0], c);
+#endif
+ }
+ d->optopt = c;
+ if (optstring[0] == ':')
+ c = ':';
+ else
+ c = '?';
+ }
+ else
+ /* We already incremented 'optind' once;
+ increment it again when taking next ARGV-elt as argument. */
+ d->optarg = argv[d->optind++];
+ d->__nextchar = NULL;
+ }
+ }
+ return c;
+ }
+}
+
+int
+_getopt_internal (int argc, char **argv, const char *optstring,
+ const struct option *longopts, int *longind, int long_only,
+ int posixly_correct)
+{
+ int result;
+
+ getopt_data.optind = optind;
+ getopt_data.opterr = opterr;
+
+ result = _getopt_internal_r (argc, argv, optstring, longopts,
+ longind, long_only, &getopt_data,
+ posixly_correct);
+
+ optind = getopt_data.optind;
+ optarg = getopt_data.optarg;
+ optopt = getopt_data.optopt;
+
+ return result;
+}
+
+/* glibc gets a LSB-compliant getopt.
+ Standalone applications get a POSIX-compliant getopt. */
+#if _LIBC
+enum { POSIXLY_CORRECT = 0 };
+#else
+enum { POSIXLY_CORRECT = 1 };
+#endif
+
+int
+getopt (int argc, char *const *argv, const char *optstring)
+{
+ return _getopt_internal (argc, (char **) argv, optstring,
+ (const struct option *) 0,
+ (int *) 0,
+ 0, POSIXLY_CORRECT);
+}
+
+#ifdef _LIBC
+int
+__posix_getopt (int argc, char *const *argv, const char *optstring)
+{
+ return _getopt_internal (argc, argv, optstring,
+ (const struct option *) 0,
+ (int *) 0,
+ 0, 1);
+}
+#endif
+
+
+#ifdef TEST
+
+/* Compile with -DTEST to make an executable for use in testing
+ the above definition of 'getopt'. */
+
+int
+main (int argc, char **argv)
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+
+ c = getopt (argc, argv, "abc:d:0123456789");
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value '%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/contrib/tools/bison/gnulib/src/getopt1.c b/contrib/tools/bison/gnulib/src/getopt1.c
index 55a6b4eae4..6b4f72d3bf 100644
--- a/contrib/tools/bison/gnulib/src/getopt1.c
+++ b/contrib/tools/bison/gnulib/src/getopt1.c
@@ -1,170 +1,170 @@
-/* getopt_long and getopt_long_only entry points for GNU getopt.
- Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifdef _LIBC
-# include <getopt.h>
-#else
-# include <config.h>
-# include "getopt.h"
-#endif
-#include "getopt_int.h"
-
-#include <stdio.h>
-
-/* This needs to come after some library #include
- to get __GNU_LIBRARY__ defined. */
-#ifdef __GNU_LIBRARY__
-#include <stdlib.h>
-#endif
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-int
-getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
- const struct option *long_options, int *opt_index)
-{
- return _getopt_internal (argc, (char **) argv, options, long_options,
- opt_index, 0, 0);
-}
-
-int
-_getopt_long_r (int argc, char **argv, const char *options,
- const struct option *long_options, int *opt_index,
- struct _getopt_data *d)
-{
- return _getopt_internal_r (argc, argv, options, long_options, opt_index,
- 0, d, 0);
-}
-
-/* Like getopt_long, but '-' as well as '--' can indicate a long option.
- If an option that starts with '-' (not '--') doesn't match a long option,
- but does match a short option, it is parsed as a short option
- instead. */
-
-int
-getopt_long_only (int argc, char *__getopt_argv_const *argv,
- const char *options,
- const struct option *long_options, int *opt_index)
-{
- return _getopt_internal (argc, (char **) argv, options, long_options,
- opt_index, 1, 0);
-}
-
-int
-_getopt_long_only_r (int argc, char **argv, const char *options,
- const struct option *long_options, int *opt_index,
- struct _getopt_data *d)
-{
- return _getopt_internal_r (argc, argv, options, long_options, opt_index,
- 1, d, 0);
-}
-
-
-#ifdef TEST
-
-#include <stdio.h>
-
-int
-main (int argc, char **argv)
-{
- int c;
- int digit_optind = 0;
-
- while (1)
- {
- int this_option_optind = optind ? optind : 1;
- int option_index = 0;
- static const struct option long_options[] =
- {
- {"add", 1, 0, 0},
- {"append", 0, 0, 0},
- {"delete", 1, 0, 0},
- {"verbose", 0, 0, 0},
- {"create", 0, 0, 0},
- {"file", 1, 0, 0},
- {0, 0, 0, 0}
- };
-
- c = getopt_long (argc, argv, "abc:d:0123456789",
- long_options, &option_index);
- if (c == -1)
- break;
-
- switch (c)
- {
- case 0:
- printf ("option %s", long_options[option_index].name);
- if (optarg)
- printf (" with arg %s", optarg);
- printf ("\n");
- break;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (digit_optind != 0 && digit_optind != this_option_optind)
- printf ("digits occur in two different argv-elements.\n");
- digit_optind = this_option_optind;
- printf ("option %c\n", c);
- break;
-
- case 'a':
- printf ("option a\n");
- break;
-
- case 'b':
- printf ("option b\n");
- break;
-
- case 'c':
- printf ("option c with value '%s'\n", optarg);
- break;
-
- case 'd':
- printf ("option d with value '%s'\n", optarg);
- break;
-
- case '?':
- break;
-
- default:
- printf ("?? getopt returned character code 0%o ??\n", c);
- }
- }
-
- if (optind < argc)
- {
- printf ("non-option ARGV-elements: ");
- while (optind < argc)
- printf ("%s ", argv[optind++]);
- printf ("\n");
- }
-
- exit (0);
-}
-
-#endif /* TEST */
+/* getopt_long and getopt_long_only entry points for GNU getopt.
+ Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef _LIBC
+# include <getopt.h>
+#else
+# include <config.h>
+# include "getopt.h"
+#endif
+#include "getopt_int.h"
+
+#include <stdio.h>
+
+/* This needs to come after some library #include
+ to get __GNU_LIBRARY__ defined. */
+#ifdef __GNU_LIBRARY__
+#include <stdlib.h>
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+int
+getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
+ const struct option *long_options, int *opt_index)
+{
+ return _getopt_internal (argc, (char **) argv, options, long_options,
+ opt_index, 0, 0);
+}
+
+int
+_getopt_long_r (int argc, char **argv, const char *options,
+ const struct option *long_options, int *opt_index,
+ struct _getopt_data *d)
+{
+ return _getopt_internal_r (argc, argv, options, long_options, opt_index,
+ 0, d, 0);
+}
+
+/* Like getopt_long, but '-' as well as '--' can indicate a long option.
+ If an option that starts with '-' (not '--') doesn't match a long option,
+ but does match a short option, it is parsed as a short option
+ instead. */
+
+int
+getopt_long_only (int argc, char *__getopt_argv_const *argv,
+ const char *options,
+ const struct option *long_options, int *opt_index)
+{
+ return _getopt_internal (argc, (char **) argv, options, long_options,
+ opt_index, 1, 0);
+}
+
+int
+_getopt_long_only_r (int argc, char **argv, const char *options,
+ const struct option *long_options, int *opt_index,
+ struct _getopt_data *d)
+{
+ return _getopt_internal_r (argc, argv, options, long_options, opt_index,
+ 1, d, 0);
+}
+
+
+#ifdef TEST
+
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+ int c;
+ int digit_optind = 0;
+
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static const struct option long_options[] =
+ {
+ {"add", 1, 0, 0},
+ {"append", 0, 0, 0},
+ {"delete", 1, 0, 0},
+ {"verbose", 0, 0, 0},
+ {"create", 0, 0, 0},
+ {"file", 1, 0, 0},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long (argc, argv, "abc:d:0123456789",
+ long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case 0:
+ printf ("option %s", long_options[option_index].name);
+ if (optarg)
+ printf (" with arg %s", optarg);
+ printf ("\n");
+ break;
+
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ if (digit_optind != 0 && digit_optind != this_option_optind)
+ printf ("digits occur in two different argv-elements.\n");
+ digit_optind = this_option_optind;
+ printf ("option %c\n", c);
+ break;
+
+ case 'a':
+ printf ("option a\n");
+ break;
+
+ case 'b':
+ printf ("option b\n");
+ break;
+
+ case 'c':
+ printf ("option c with value '%s'\n", optarg);
+ break;
+
+ case 'd':
+ printf ("option d with value '%s'\n", optarg);
+ break;
+
+ case '?':
+ break;
+
+ default:
+ printf ("?? getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind < argc)
+ {
+ printf ("non-option ARGV-elements: ");
+ while (optind < argc)
+ printf ("%s ", argv[optind++]);
+ printf ("\n");
+ }
+
+ exit (0);
+}
+
+#endif /* TEST */
diff --git a/contrib/tools/bison/gnulib/src/getopt_int.h b/contrib/tools/bison/gnulib/src/getopt_int.h
index a6e4b9ea71..0074b98292 100644
--- a/contrib/tools/bison/gnulib/src/getopt_int.h
+++ b/contrib/tools/bison/gnulib/src/getopt_int.h
@@ -1,135 +1,135 @@
-/* Internal declarations for getopt.
- Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GETOPT_INT_H
-#define _GETOPT_INT_H 1
-
-#include <getopt.h>
-
-extern int _getopt_internal (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind,
- int __long_only, int __posixly_correct);
-
-
-/* Reentrant versions which can handle parsing multiple argument
- vectors at the same time. */
-
-/* Describe how to deal with options that follow non-option ARGV-elements.
-
- If the caller did not specify anything,
- the default is REQUIRE_ORDER if the environment variable
- POSIXLY_CORRECT is defined, PERMUTE otherwise.
-
- REQUIRE_ORDER means don't recognize them as options;
- stop option processing when the first non-option is seen.
- This is what Unix does.
- This mode of operation is selected by either setting the environment
- variable POSIXLY_CORRECT, or using '+' as the first character
- of the list of option characters, or by calling getopt.
-
- PERMUTE is the default. We permute the contents of ARGV as we
- scan, so that eventually all the non-options are at the end.
- This allows options to be given in any order, even with programs
- that were not written to expect this.
-
- RETURN_IN_ORDER is an option available to programs that were
- written to expect options and other ARGV-elements in any order
- and that care about the ordering of the two. We describe each
- non-option ARGV-element as if it were the argument of an option
- with character code 1. Using '-' as the first character of the
- list of option characters selects this mode of operation.
-
- The special argument '--' forces an end of option-scanning regardless
- of the value of 'ordering'. In the case of RETURN_IN_ORDER, only
- '--' can cause 'getopt' to return -1 with 'optind' != ARGC. */
-
-enum __ord
- {
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
- };
-
-/* Data type for reentrant functions. */
-struct _getopt_data
-{
- /* These have exactly the same meaning as the corresponding global
- variables, except that they are used for the reentrant
- versions of getopt. */
- int optind;
- int opterr;
- int optopt;
- char *optarg;
-
- /* Internal members. */
-
- /* True if the internal members have been initialized. */
- int __initialized;
-
- /* The next char to be scanned in the option-element
- in which the last option character we returned was found.
- This allows us to pick up the scan where we left off.
-
- If this is zero, or a null string, it means resume the scan
- by advancing to the next ARGV-element. */
- char *__nextchar;
-
- /* See __ord above. */
- enum __ord __ordering;
-
- /* If the POSIXLY_CORRECT environment variable is set
- or getopt was called. */
- int __posixly_correct;
-
-
- /* Handle permutation of arguments. */
-
- /* Describe the part of ARGV that contains non-options that have
- been skipped. 'first_nonopt' is the index in ARGV of the first
- of them; 'last_nonopt' is the index after the last of them. */
-
- int __first_nonopt;
- int __last_nonopt;
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
- int __nonoption_flags_max_len;
- int __nonoption_flags_len;
-#endif
-};
-
-/* The initializer is necessary to set OPTIND and OPTERR to their
- default values and to clear the initialization flag. */
-#define _GETOPT_DATA_INITIALIZER { 1, 1 }
-
-extern int _getopt_internal_r (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind,
- int __long_only, struct _getopt_data *__data,
- int __posixly_correct);
-
-extern int _getopt_long_r (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts, int *__longind,
- struct _getopt_data *__data);
-
-extern int _getopt_long_only_r (int ___argc, char **___argv,
- const char *__shortopts,
- const struct option *__longopts,
- int *__longind,
- struct _getopt_data *__data);
-
-#endif /* getopt_int.h */
+/* Internal declarations for getopt.
+ Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GETOPT_INT_H
+#define _GETOPT_INT_H 1
+
+#include <getopt.h>
+
+extern int _getopt_internal (int ___argc, char **___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind,
+ int __long_only, int __posixly_correct);
+
+
+/* Reentrant versions which can handle parsing multiple argument
+ vectors at the same time. */
+
+/* Describe how to deal with options that follow non-option ARGV-elements.
+
+ If the caller did not specify anything,
+ the default is REQUIRE_ORDER if the environment variable
+ POSIXLY_CORRECT is defined, PERMUTE otherwise.
+
+ REQUIRE_ORDER means don't recognize them as options;
+ stop option processing when the first non-option is seen.
+ This is what Unix does.
+ This mode of operation is selected by either setting the environment
+ variable POSIXLY_CORRECT, or using '+' as the first character
+ of the list of option characters, or by calling getopt.
+
+ PERMUTE is the default. We permute the contents of ARGV as we
+ scan, so that eventually all the non-options are at the end.
+ This allows options to be given in any order, even with programs
+ that were not written to expect this.
+
+ RETURN_IN_ORDER is an option available to programs that were
+ written to expect options and other ARGV-elements in any order
+ and that care about the ordering of the two. We describe each
+ non-option ARGV-element as if it were the argument of an option
+ with character code 1. Using '-' as the first character of the
+ list of option characters selects this mode of operation.
+
+ The special argument '--' forces an end of option-scanning regardless
+ of the value of 'ordering'. In the case of RETURN_IN_ORDER, only
+ '--' can cause 'getopt' to return -1 with 'optind' != ARGC. */
+
+enum __ord
+ {
+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+ };
+
+/* Data type for reentrant functions. */
+struct _getopt_data
+{
+ /* These have exactly the same meaning as the corresponding global
+ variables, except that they are used for the reentrant
+ versions of getopt. */
+ int optind;
+ int opterr;
+ int optopt;
+ char *optarg;
+
+ /* Internal members. */
+
+ /* True if the internal members have been initialized. */
+ int __initialized;
+
+ /* The next char to be scanned in the option-element
+ in which the last option character we returned was found.
+ This allows us to pick up the scan where we left off.
+
+ If this is zero, or a null string, it means resume the scan
+ by advancing to the next ARGV-element. */
+ char *__nextchar;
+
+ /* See __ord above. */
+ enum __ord __ordering;
+
+ /* If the POSIXLY_CORRECT environment variable is set
+ or getopt was called. */
+ int __posixly_correct;
+
+
+ /* Handle permutation of arguments. */
+
+ /* Describe the part of ARGV that contains non-options that have
+ been skipped. 'first_nonopt' is the index in ARGV of the first
+ of them; 'last_nonopt' is the index after the last of them. */
+
+ int __first_nonopt;
+ int __last_nonopt;
+
+#if defined _LIBC && defined USE_NONOPTION_FLAGS
+ int __nonoption_flags_max_len;
+ int __nonoption_flags_len;
+#endif
+};
+
+/* The initializer is necessary to set OPTIND and OPTERR to their
+ default values and to clear the initialization flag. */
+#define _GETOPT_DATA_INITIALIZER { 1, 1 }
+
+extern int _getopt_internal_r (int ___argc, char **___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind,
+ int __long_only, struct _getopt_data *__data,
+ int __posixly_correct);
+
+extern int _getopt_long_r (int ___argc, char **___argv,
+ const char *__shortopts,
+ const struct option *__longopts, int *__longind,
+ struct _getopt_data *__data);
+
+extern int _getopt_long_only_r (int ___argc, char **___argv,
+ const char *__shortopts,
+ const struct option *__longopts,
+ int *__longind,
+ struct _getopt_data *__data);
+
+#endif /* getopt_int.h */
diff --git a/contrib/tools/bison/gnulib/src/gettext.h b/contrib/tools/bison/gnulib/src/gettext.h
index d0215715a9..6888a53e42 100644
--- a/contrib/tools/bison/gnulib/src/gettext.h
+++ b/contrib/tools/bison/gnulib/src/gettext.h
@@ -1,288 +1,288 @@
-/* Convenience header for conditional use of GNU <libintl.h>.
- Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBGETTEXT_H
-#define _LIBGETTEXT_H 1
-
-/* NLS can be disabled through the configure --disable-nls option. */
-#if ENABLE_NLS
-
-/* Get declarations of GNU message catalog functions. */
-# include <libintl.h>
-
-/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
- the gettext() and ngettext() macros. This is an alternative to calling
- textdomain(), and is useful for libraries. */
-# ifdef DEFAULT_TEXT_DOMAIN
-# undef gettext
-# define gettext(Msgid) \
- dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
-# undef ngettext
-# define ngettext(Msgid1, Msgid2, N) \
- dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
-# endif
-
-#else
-
-/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
- chokes if dcgettext is defined as a macro. So include it now, to make
- later inclusions of <locale.h> a NOP. We don't include <libintl.h>
- as well because people using "gettext.h" will not include <libintl.h>,
- and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
- is OK. */
-#if defined(__sun)
-# include <locale.h>
-#endif
-
-/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
- <libintl.h>, which chokes if dcgettext is defined as a macro. So include
- it now, to make later inclusions of <libintl.h> a NOP. */
-#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
-# include <cstdlib>
-# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
-# include <libintl.h>
-# endif
-#endif
-
-/* Disabled NLS.
- The casts to 'const char *' serve the purpose of producing warnings
- for invalid uses of the value returned from these functions.
- On pre-ANSI systems without 'const', the config.h file is supposed to
- contain "#define const". */
-# undef gettext
-# define gettext(Msgid) ((const char *) (Msgid))
-# undef dgettext
-# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
-# undef dcgettext
-# define dcgettext(Domainname, Msgid, Category) \
- ((void) (Category), dgettext (Domainname, Msgid))
-# undef ngettext
-# define ngettext(Msgid1, Msgid2, N) \
- ((N) == 1 \
- ? ((void) (Msgid2), (const char *) (Msgid1)) \
- : ((void) (Msgid1), (const char *) (Msgid2)))
-# undef dngettext
-# define dngettext(Domainname, Msgid1, Msgid2, N) \
- ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
-# undef dcngettext
-# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
- ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
-# undef textdomain
-# define textdomain(Domainname) ((const char *) (Domainname))
-# undef bindtextdomain
-# define bindtextdomain(Domainname, Dirname) \
- ((void) (Domainname), (const char *) (Dirname))
-# undef bind_textdomain_codeset
-# define bind_textdomain_codeset(Domainname, Codeset) \
- ((void) (Domainname), (const char *) (Codeset))
-
-#endif
-
-/* Prefer gnulib's setlocale override over libintl's setlocale override. */
-#ifdef GNULIB_defined_setlocale
-# undef setlocale
-# define setlocale rpl_setlocale
-#endif
-
-/* A pseudo function call that serves as a marker for the automated
- extraction of messages, but does not call gettext(). The run-time
- translation is done at a different place in the code.
- The argument, String, should be a literal string. Concatenated strings
- and other string expressions won't work.
- The macro's expansion is not parenthesized, so that it is suitable as
- initializer for static 'char[]' or 'const char[]' variables. */
-#define gettext_noop(String) String
-
-/* The separator between msgctxt and msgid in a .mo file. */
-#define GETTEXT_CONTEXT_GLUE "\004"
-
-/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
- MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
- short and rarely need to change.
- The letter 'p' stands for 'particular' or 'special'. */
-#ifdef DEFAULT_TEXT_DOMAIN
-# define pgettext(Msgctxt, Msgid) \
- pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
-#else
-# define pgettext(Msgctxt, Msgid) \
- pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
-#endif
-#define dpgettext(Domainname, Msgctxt, Msgid) \
- pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
-#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
- pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
-#ifdef DEFAULT_TEXT_DOMAIN
-# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
- npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
-#else
-# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
- npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
-#endif
-#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
- npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
-#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
- npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-pgettext_aux (const char *domain,
- const char *msg_ctxt_id, const char *msgid,
- int category)
-{
- const char *translation = dcgettext (domain, msg_ctxt_id, category);
- if (translation == msg_ctxt_id)
- return msgid;
- else
- return translation;
-}
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-npgettext_aux (const char *domain,
- const char *msg_ctxt_id, const char *msgid,
- const char *msgid_plural, unsigned long int n,
- int category)
-{
- const char *translation =
- dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
- if (translation == msg_ctxt_id || translation == msgid_plural)
- return (n == 1 ? msgid : msgid_plural);
- else
- return translation;
-}
-
-/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
- can be arbitrary expressions. But for string literals these macros are
- less efficient than those above. */
-
-#include <string.h>
-
-#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
- /* || __STDC_VERSION__ >= 199901L */ )
-# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
-#else
-# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
-#endif
-
-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
-#include <stdlib.h>
-#endif
-
-#define pgettext_expr(Msgctxt, Msgid) \
- dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
-#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
- dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-dcpgettext_expr (const char *domain,
- const char *msgctxt, const char *msgid,
- int category)
-{
- size_t msgctxt_len = strlen (msgctxt) + 1;
- size_t msgid_len = strlen (msgid) + 1;
- const char *translation;
-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
- char msg_ctxt_id[msgctxt_len + msgid_len];
-#else
- char buf[1024];
- char *msg_ctxt_id =
- (msgctxt_len + msgid_len <= sizeof (buf)
- ? buf
- : (char *) malloc (msgctxt_len + msgid_len));
- if (msg_ctxt_id != NULL)
-#endif
- {
- memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
- msg_ctxt_id[msgctxt_len - 1] = '\004';
- memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
- translation = dcgettext (domain, msg_ctxt_id, category);
-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
- if (msg_ctxt_id != buf)
- free (msg_ctxt_id);
-#endif
- if (translation != msg_ctxt_id)
- return translation;
- }
- return msgid;
-}
-
-#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
- dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
-#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
- dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static const char *
-dcnpgettext_expr (const char *domain,
- const char *msgctxt, const char *msgid,
- const char *msgid_plural, unsigned long int n,
- int category)
-{
- size_t msgctxt_len = strlen (msgctxt) + 1;
- size_t msgid_len = strlen (msgid) + 1;
- const char *translation;
-#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
- char msg_ctxt_id[msgctxt_len + msgid_len];
-#else
- char buf[1024];
- char *msg_ctxt_id =
- (msgctxt_len + msgid_len <= sizeof (buf)
- ? buf
- : (char *) malloc (msgctxt_len + msgid_len));
- if (msg_ctxt_id != NULL)
-#endif
- {
- memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
- msg_ctxt_id[msgctxt_len - 1] = '\004';
- memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
- translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
-#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
- if (msg_ctxt_id != buf)
- free (msg_ctxt_id);
-#endif
- if (!(translation == msg_ctxt_id || translation == msgid_plural))
- return translation;
- }
- return (n == 1 ? msgid : msgid_plural);
-}
-
-#endif /* _LIBGETTEXT_H */
+/* Convenience header for conditional use of GNU <libintl.h>.
+ Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LIBGETTEXT_H
+#define _LIBGETTEXT_H 1
+
+/* NLS can be disabled through the configure --disable-nls option. */
+#if ENABLE_NLS
+
+/* Get declarations of GNU message catalog functions. */
+# include <libintl.h>
+
+/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
+ the gettext() and ngettext() macros. This is an alternative to calling
+ textdomain(), and is useful for libraries. */
+# ifdef DEFAULT_TEXT_DOMAIN
+# undef gettext
+# define gettext(Msgid) \
+ dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
+# undef ngettext
+# define ngettext(Msgid1, Msgid2, N) \
+ dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
+# endif
+
+#else
+
+/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
+ chokes if dcgettext is defined as a macro. So include it now, to make
+ later inclusions of <locale.h> a NOP. We don't include <libintl.h>
+ as well because people using "gettext.h" will not include <libintl.h>,
+ and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
+ is OK. */
+#if defined(__sun)
+# include <locale.h>
+#endif
+
+/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
+ <libintl.h>, which chokes if dcgettext is defined as a macro. So include
+ it now, to make later inclusions of <libintl.h> a NOP. */
+#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
+# include <cstdlib>
+# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
+# include <libintl.h>
+# endif
+#endif
+
+/* Disabled NLS.
+ The casts to 'const char *' serve the purpose of producing warnings
+ for invalid uses of the value returned from these functions.
+ On pre-ANSI systems without 'const', the config.h file is supposed to
+ contain "#define const". */
+# undef gettext
+# define gettext(Msgid) ((const char *) (Msgid))
+# undef dgettext
+# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
+# undef dcgettext
+# define dcgettext(Domainname, Msgid, Category) \
+ ((void) (Category), dgettext (Domainname, Msgid))
+# undef ngettext
+# define ngettext(Msgid1, Msgid2, N) \
+ ((N) == 1 \
+ ? ((void) (Msgid2), (const char *) (Msgid1)) \
+ : ((void) (Msgid1), (const char *) (Msgid2)))
+# undef dngettext
+# define dngettext(Domainname, Msgid1, Msgid2, N) \
+ ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
+# undef dcngettext
+# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
+ ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
+# undef textdomain
+# define textdomain(Domainname) ((const char *) (Domainname))
+# undef bindtextdomain
+# define bindtextdomain(Domainname, Dirname) \
+ ((void) (Domainname), (const char *) (Dirname))
+# undef bind_textdomain_codeset
+# define bind_textdomain_codeset(Domainname, Codeset) \
+ ((void) (Domainname), (const char *) (Codeset))
+
+#endif
+
+/* Prefer gnulib's setlocale override over libintl's setlocale override. */
+#ifdef GNULIB_defined_setlocale
+# undef setlocale
+# define setlocale rpl_setlocale
+#endif
+
+/* A pseudo function call that serves as a marker for the automated
+ extraction of messages, but does not call gettext(). The run-time
+ translation is done at a different place in the code.
+ The argument, String, should be a literal string. Concatenated strings
+ and other string expressions won't work.
+ The macro's expansion is not parenthesized, so that it is suitable as
+ initializer for static 'char[]' or 'const char[]' variables. */
+#define gettext_noop(String) String
+
+/* The separator between msgctxt and msgid in a .mo file. */
+#define GETTEXT_CONTEXT_GLUE "\004"
+
+/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
+ MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
+ short and rarely need to change.
+ The letter 'p' stands for 'particular' or 'special'. */
+#ifdef DEFAULT_TEXT_DOMAIN
+# define pgettext(Msgctxt, Msgid) \
+ pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
+#else
+# define pgettext(Msgctxt, Msgid) \
+ pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
+#endif
+#define dpgettext(Domainname, Msgctxt, Msgid) \
+ pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
+#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
+ pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
+#ifdef DEFAULT_TEXT_DOMAIN
+# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
+ npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
+#else
+# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
+ npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
+#endif
+#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
+ npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
+#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
+ npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+pgettext_aux (const char *domain,
+ const char *msg_ctxt_id, const char *msgid,
+ int category)
+{
+ const char *translation = dcgettext (domain, msg_ctxt_id, category);
+ if (translation == msg_ctxt_id)
+ return msgid;
+ else
+ return translation;
+}
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+npgettext_aux (const char *domain,
+ const char *msg_ctxt_id, const char *msgid,
+ const char *msgid_plural, unsigned long int n,
+ int category)
+{
+ const char *translation =
+ dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
+ if (translation == msg_ctxt_id || translation == msgid_plural)
+ return (n == 1 ? msgid : msgid_plural);
+ else
+ return translation;
+}
+
+/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
+ can be arbitrary expressions. But for string literals these macros are
+ less efficient than those above. */
+
+#include <string.h>
+
+#if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
+ /* || __STDC_VERSION__ >= 199901L */ )
+# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
+#else
+# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
+#endif
+
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+#include <stdlib.h>
+#endif
+
+#define pgettext_expr(Msgctxt, Msgid) \
+ dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
+#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
+ dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+dcpgettext_expr (const char *domain,
+ const char *msgctxt, const char *msgid,
+ int category)
+{
+ size_t msgctxt_len = strlen (msgctxt) + 1;
+ size_t msgid_len = strlen (msgid) + 1;
+ const char *translation;
+#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+ char msg_ctxt_id[msgctxt_len + msgid_len];
+#else
+ char buf[1024];
+ char *msg_ctxt_id =
+ (msgctxt_len + msgid_len <= sizeof (buf)
+ ? buf
+ : (char *) malloc (msgctxt_len + msgid_len));
+ if (msg_ctxt_id != NULL)
+#endif
+ {
+ memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+ msg_ctxt_id[msgctxt_len - 1] = '\004';
+ memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+ translation = dcgettext (domain, msg_ctxt_id, category);
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+ if (msg_ctxt_id != buf)
+ free (msg_ctxt_id);
+#endif
+ if (translation != msg_ctxt_id)
+ return translation;
+ }
+ return msgid;
+}
+
+#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
+ dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
+#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
+ dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+dcnpgettext_expr (const char *domain,
+ const char *msgctxt, const char *msgid,
+ const char *msgid_plural, unsigned long int n,
+ int category)
+{
+ size_t msgctxt_len = strlen (msgctxt) + 1;
+ size_t msgid_len = strlen (msgid) + 1;
+ const char *translation;
+#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+ char msg_ctxt_id[msgctxt_len + msgid_len];
+#else
+ char buf[1024];
+ char *msg_ctxt_id =
+ (msgctxt_len + msgid_len <= sizeof (buf)
+ ? buf
+ : (char *) malloc (msgctxt_len + msgid_len));
+ if (msg_ctxt_id != NULL)
+#endif
+ {
+ memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+ msg_ctxt_id[msgctxt_len - 1] = '\004';
+ memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+ translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+ if (msg_ctxt_id != buf)
+ free (msg_ctxt_id);
+#endif
+ if (!(translation == msg_ctxt_id || translation == msgid_plural))
+ return translation;
+ }
+ return (n == 1 ? msgid : msgid_plural);
+}
+
+#endif /* _LIBGETTEXT_H */
diff --git a/contrib/tools/bison/gnulib/src/gettimeofday.c b/contrib/tools/bison/gnulib/src/gettimeofday.c
index ad65c6da8b..948855c67d 100644
--- a/contrib/tools/bison/gnulib/src/gettimeofday.c
+++ b/contrib/tools/bison/gnulib/src/gettimeofday.c
@@ -1,154 +1,154 @@
-/* Provide gettimeofday for systems that don't have it or for which it's broken.
-
- Copyright (C) 2001-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Jim Meyering */
-
-#include <config.h>
-
-/* Specification. */
-#include <sys/time.h>
-
-#include <time.h>
-
-#if HAVE_SYS_TIMEB_H
-# include <sys/timeb.h>
-#endif
-
-#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
-
-/* Work around the bug in some systems whereby gettimeofday clobbers
- the static buffer that localtime uses for its return value. The
- gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
- this problem. The tzset replacement is necessary for at least
- Solaris 2.5, 2.5.1, and 2.6. */
-
-static struct tm tm_zero_buffer;
-static struct tm *localtime_buffer_addr = &tm_zero_buffer;
-
-# undef localtime
-extern struct tm *localtime (time_t const *);
-
-# undef gmtime
-extern struct tm *gmtime (time_t const *);
-
-/* This is a wrapper for localtime. It is used only on systems for which
- gettimeofday clobbers the static buffer used for localtime's result.
-
- On the first call, record the address of the static buffer that
- localtime uses for its result. */
-
-struct tm *
-rpl_localtime (time_t const *timep)
-{
- struct tm *tm = localtime (timep);
-
- if (localtime_buffer_addr == &tm_zero_buffer)
- localtime_buffer_addr = tm;
-
- return tm;
-}
-
-/* Same as above, since gmtime and localtime use the same buffer. */
-struct tm *
-rpl_gmtime (time_t const *timep)
-{
- struct tm *tm = gmtime (timep);
-
- if (localtime_buffer_addr == &tm_zero_buffer)
- localtime_buffer_addr = tm;
-
- return tm;
-}
-
-#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
-
-#if TZSET_CLOBBERS_LOCALTIME
-
-# undef tzset
-extern void tzset (void);
-
-/* This is a wrapper for tzset, for systems on which tzset may clobber
- the static buffer used for localtime's result. */
-void
-rpl_tzset (void)
-{
- /* Save and restore the contents of the buffer used for localtime's
- result around the call to tzset. */
- struct tm save = *localtime_buffer_addr;
- tzset ();
- *localtime_buffer_addr = save;
-}
-#endif
-
-/* This is a wrapper for gettimeofday. It is used only on systems
- that lack this function, or whose implementation of this function
- causes problems. */
-
-int
-gettimeofday (struct timeval *restrict tv, void *restrict tz)
-{
-#undef gettimeofday
-#if HAVE_GETTIMEOFDAY
-# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
- /* Save and restore the contents of the buffer used for localtime's
- result around the call to gettimeofday. */
- struct tm save = *localtime_buffer_addr;
-# endif
-
-# if defined timeval /* 'struct timeval' overridden by gnulib? */
-# undef timeval
- struct timeval otv;
- int result = gettimeofday (&otv, (struct timezone *) tz);
- if (result == 0)
- {
- tv->tv_sec = otv.tv_sec;
- tv->tv_usec = otv.tv_usec;
- }
-# else
- int result = gettimeofday (tv, (struct timezone *) tz);
-# endif
-
-# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
- *localtime_buffer_addr = save;
-# endif
-
- return result;
-
-#else
-
-# if HAVE__FTIME
-
- struct _timeb timebuf;
- _ftime (&timebuf);
- tv->tv_sec = timebuf.time;
- tv->tv_usec = timebuf.millitm * 1000;
-
-# else
-
-# if !defined OK_TO_USE_1S_CLOCK
-# error "Only 1-second nominal clock resolution found. Is that intended?" \
- "If so, compile with the -DOK_TO_USE_1S_CLOCK option."
-# endif
- tv->tv_sec = time (NULL);
- tv->tv_usec = 0;
-
-# endif
-
- return 0;
-
-#endif
-}
+/* Provide gettimeofday for systems that don't have it or for which it's broken.
+
+ Copyright (C) 2001-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Jim Meyering */
+
+#include <config.h>
+
+/* Specification. */
+#include <sys/time.h>
+
+#include <time.h>
+
+#if HAVE_SYS_TIMEB_H
+# include <sys/timeb.h>
+#endif
+
+#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
+
+/* Work around the bug in some systems whereby gettimeofday clobbers
+ the static buffer that localtime uses for its return value. The
+ gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
+ this problem. The tzset replacement is necessary for at least
+ Solaris 2.5, 2.5.1, and 2.6. */
+
+static struct tm tm_zero_buffer;
+static struct tm *localtime_buffer_addr = &tm_zero_buffer;
+
+# undef localtime
+extern struct tm *localtime (time_t const *);
+
+# undef gmtime
+extern struct tm *gmtime (time_t const *);
+
+/* This is a wrapper for localtime. It is used only on systems for which
+ gettimeofday clobbers the static buffer used for localtime's result.
+
+ On the first call, record the address of the static buffer that
+ localtime uses for its result. */
+
+struct tm *
+rpl_localtime (time_t const *timep)
+{
+ struct tm *tm = localtime (timep);
+
+ if (localtime_buffer_addr == &tm_zero_buffer)
+ localtime_buffer_addr = tm;
+
+ return tm;
+}
+
+/* Same as above, since gmtime and localtime use the same buffer. */
+struct tm *
+rpl_gmtime (time_t const *timep)
+{
+ struct tm *tm = gmtime (timep);
+
+ if (localtime_buffer_addr == &tm_zero_buffer)
+ localtime_buffer_addr = tm;
+
+ return tm;
+}
+
+#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
+
+#if TZSET_CLOBBERS_LOCALTIME
+
+# undef tzset
+extern void tzset (void);
+
+/* This is a wrapper for tzset, for systems on which tzset may clobber
+ the static buffer used for localtime's result. */
+void
+rpl_tzset (void)
+{
+ /* Save and restore the contents of the buffer used for localtime's
+ result around the call to tzset. */
+ struct tm save = *localtime_buffer_addr;
+ tzset ();
+ *localtime_buffer_addr = save;
+}
+#endif
+
+/* This is a wrapper for gettimeofday. It is used only on systems
+ that lack this function, or whose implementation of this function
+ causes problems. */
+
+int
+gettimeofday (struct timeval *restrict tv, void *restrict tz)
+{
+#undef gettimeofday
+#if HAVE_GETTIMEOFDAY
+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
+ /* Save and restore the contents of the buffer used for localtime's
+ result around the call to gettimeofday. */
+ struct tm save = *localtime_buffer_addr;
+# endif
+
+# if defined timeval /* 'struct timeval' overridden by gnulib? */
+# undef timeval
+ struct timeval otv;
+ int result = gettimeofday (&otv, (struct timezone *) tz);
+ if (result == 0)
+ {
+ tv->tv_sec = otv.tv_sec;
+ tv->tv_usec = otv.tv_usec;
+ }
+# else
+ int result = gettimeofday (tv, (struct timezone *) tz);
+# endif
+
+# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
+ *localtime_buffer_addr = save;
+# endif
+
+ return result;
+
+#else
+
+# if HAVE__FTIME
+
+ struct _timeb timebuf;
+ _ftime (&timebuf);
+ tv->tv_sec = timebuf.time;
+ tv->tv_usec = timebuf.millitm * 1000;
+
+# else
+
+# if !defined OK_TO_USE_1S_CLOCK
+# error "Only 1-second nominal clock resolution found. Is that intended?" \
+ "If so, compile with the -DOK_TO_USE_1S_CLOCK option."
+# endif
+ tv->tv_sec = time (NULL);
+ tv->tv_usec = 0;
+
+# endif
+
+ return 0;
+
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/gl_anyhash_list1.h b/contrib/tools/bison/gnulib/src/gl_anyhash_list1.h
index 57ead45073..44012a8be5 100644
--- a/contrib/tools/bison/gnulib/src/gl_anyhash_list1.h
+++ b/contrib/tools/bison/gnulib/src/gl_anyhash_list1.h
@@ -1,27 +1,27 @@
-/* Sequential list data type implemented by a hash table with another list.
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Common code of
- gl_linkedhash_list.c, gl_avltreehash_list.c, gl_rbtreehash_list.c. */
-
-/* Hash table entry. */
-struct gl_hash_entry
-{
- struct gl_hash_entry *hash_next; /* chain of entries in same bucket */
- size_t hashcode; /* cache of values' common hash code */
-};
-typedef struct gl_hash_entry * gl_hash_entry_t;
+/* Sequential list data type implemented by a hash table with another list.
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Common code of
+ gl_linkedhash_list.c, gl_avltreehash_list.c, gl_rbtreehash_list.c. */
+
+/* Hash table entry. */
+struct gl_hash_entry
+{
+ struct gl_hash_entry *hash_next; /* chain of entries in same bucket */
+ size_t hashcode; /* cache of values' common hash code */
+};
+typedef struct gl_hash_entry * gl_hash_entry_t;
diff --git a/contrib/tools/bison/gnulib/src/gl_anyhash_list2.h b/contrib/tools/bison/gnulib/src/gl_anyhash_list2.h
index 3791ae2432..d15f28fbdb 100644
--- a/contrib/tools/bison/gnulib/src/gl_anyhash_list2.h
+++ b/contrib/tools/bison/gnulib/src/gl_anyhash_list2.h
@@ -1,138 +1,138 @@
-/* Sequential list data type implemented by a hash table with another list.
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Common code of
- gl_linkedhash_list.c, gl_avltreehash_list.c, gl_rbtreehash_list.c. */
-
-/* Array of primes, approximately in steps of factor 1.2.
- This table was computed by executing the Common Lisp expression
- (dotimes (i 244) (format t "nextprime(~D)~%" (ceiling (expt 1.2d0 i))))
- and feeding the result to PARI/gp. */
-static const size_t primes[] =
- {
- 11, 13, 17, 19, 23, 29, 37, 41, 47, 59, 67, 83, 97, 127, 139, 167, 199,
- 239, 293, 347, 419, 499, 593, 709, 853, 1021, 1229, 1471, 1777, 2129, 2543,
- 3049, 3659, 4391, 5273, 6323, 7589, 9103, 10937, 13109, 15727, 18899,
- 22651, 27179, 32609, 39133, 46957, 56359, 67619, 81157, 97369, 116849,
- 140221, 168253, 201907, 242309, 290761, 348889, 418667, 502409, 602887,
- 723467, 868151, 1041779, 1250141, 1500181, 1800191, 2160233, 2592277,
- 3110741, 3732887, 4479463, 5375371, 6450413, 7740517, 9288589, 11146307,
- 13375573, 16050689, 19260817, 23112977, 27735583, 33282701, 39939233,
- 47927081, 57512503, 69014987, 82818011, 99381577, 119257891, 143109469,
- 171731387, 206077643, 247293161, 296751781, 356102141, 427322587,
- 512787097, 615344489, 738413383, 886096061, 1063315271, 1275978331,
- 1531174013, 1837408799, 2204890543UL, 2645868653UL, 3175042391UL,
- 3810050851UL,
-#if SIZE_MAX > 4294967295UL
- 4572061027UL, 5486473229UL, 6583767889UL, 7900521449UL, 9480625733UL,
- 11376750877UL, 13652101063UL, 16382521261UL, 19659025513UL, 23590830631UL,
- 28308996763UL, 33970796089UL, 40764955463UL, 48917946377UL, 58701535657UL,
- 70441842749UL, 84530211301UL, 101436253561UL, 121723504277UL,
- 146068205131UL, 175281846149UL, 210338215379UL, 252405858521UL,
- 302887030151UL, 363464436191UL, 436157323417UL, 523388788231UL,
- 628066545713UL, 753679854847UL, 904415825857UL, 1085298991109UL,
- 1302358789181UL, 1562830547009UL, 1875396656429UL, 2250475987709UL,
- 2700571185239UL, 3240685422287UL, 3888822506759UL, 4666587008147UL,
- 5599904409713UL, 6719885291641UL, 8063862349969UL, 9676634819959UL,
- 11611961783951UL, 13934354140769UL, 16721224968907UL, 20065469962669UL,
- 24078563955191UL, 28894276746229UL, 34673132095507UL, 41607758514593UL,
- 49929310217531UL, 59915172260971UL, 71898206713183UL, 86277848055823UL,
- 103533417666967UL, 124240101200359UL, 149088121440451UL, 178905745728529UL,
- 214686894874223UL, 257624273849081UL, 309149128618903UL, 370978954342639UL,
- 445174745211143UL, 534209694253381UL, 641051633104063UL, 769261959724877UL,
- 923114351670013UL, 1107737222003791UL, 1329284666404567UL,
- 1595141599685509UL, 1914169919622551UL, 2297003903547091UL,
- 2756404684256459UL, 3307685621107757UL, 3969222745329323UL,
- 4763067294395177UL, 5715680753274209UL, 6858816903929113UL,
- 8230580284714831UL, 9876696341657791UL, 11852035609989371UL,
- 14222442731987227UL, 17066931278384657UL, 20480317534061597UL,
- 24576381040873903UL, 29491657249048679UL, 35389988698858471UL,
- 42467986438630267UL, 50961583726356109UL, 61153900471627387UL,
- 73384680565952851UL, 88061616679143347UL, 105673940014972061UL,
- 126808728017966413UL, 152170473621559703UL, 182604568345871671UL,
- 219125482015045997UL, 262950578418055169UL, 315540694101666193UL,
- 378648832921999397UL, 454378599506399233UL, 545254319407679131UL,
- 654305183289214771UL, 785166219947057701UL, 942199463936469157UL,
- 1130639356723763129UL, 1356767228068515623UL, 1628120673682218619UL,
- 1953744808418662409UL, 2344493770102394881UL, 2813392524122873857UL,
- 3376071028947448339UL, 4051285234736937517UL, 4861542281684325481UL,
- 5833850738021191727UL, 7000620885625427969UL, 8400745062750513217UL,
- 10080894075300616261UL, 12097072890360739951UL, 14516487468432885797UL,
- 17419784962119465179UL,
-#endif
- SIZE_MAX /* sentinel, to ensure the search terminates */
- };
-
-/* Return a suitable prime >= ESTIMATE. */
-static size_t
-next_prime (size_t estimate)
-{
- size_t i;
-
- for (i = 0; i < sizeof (primes) / sizeof (primes[0]); i++)
- if (primes[i] >= estimate)
- return primes[i];
- return SIZE_MAX; /* not a prime, but better than nothing */
-}
-
-/* Resize the hash table with a new estimated size. */
-static void
-hash_resize (gl_list_t list, size_t estimate)
-{
- size_t new_size = next_prime (estimate);
-
- if (new_size > list->table_size)
- {
- gl_hash_entry_t *old_table = list->table;
- /* Allocate the new table. */
- gl_hash_entry_t *new_table;
- size_t i;
-
- if (size_overflow_p (xtimes (new_size, sizeof (gl_hash_entry_t))))
- goto fail;
- new_table =
- (gl_hash_entry_t *) calloc (new_size, sizeof (gl_hash_entry_t));
- if (new_table == NULL)
- goto fail;
-
- /* Iterate through the entries of the old table. */
- for (i = list->table_size; i > 0; )
- {
- gl_hash_entry_t node = old_table[--i];
-
- while (node != NULL)
- {
- gl_hash_entry_t next = node->hash_next;
- /* Add the entry to the new table. */
- size_t bucket = node->hashcode % new_size;
- node->hash_next = new_table[bucket];
- new_table[bucket] = node;
-
- node = next;
- }
- }
-
- list->table = new_table;
- list->table_size = new_size;
- free (old_table);
- }
- return;
-
- fail:
- /* Just continue without resizing the table. */
- return;
-}
+/* Sequential list data type implemented by a hash table with another list.
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Common code of
+ gl_linkedhash_list.c, gl_avltreehash_list.c, gl_rbtreehash_list.c. */
+
+/* Array of primes, approximately in steps of factor 1.2.
+ This table was computed by executing the Common Lisp expression
+ (dotimes (i 244) (format t "nextprime(~D)~%" (ceiling (expt 1.2d0 i))))
+ and feeding the result to PARI/gp. */
+static const size_t primes[] =
+ {
+ 11, 13, 17, 19, 23, 29, 37, 41, 47, 59, 67, 83, 97, 127, 139, 167, 199,
+ 239, 293, 347, 419, 499, 593, 709, 853, 1021, 1229, 1471, 1777, 2129, 2543,
+ 3049, 3659, 4391, 5273, 6323, 7589, 9103, 10937, 13109, 15727, 18899,
+ 22651, 27179, 32609, 39133, 46957, 56359, 67619, 81157, 97369, 116849,
+ 140221, 168253, 201907, 242309, 290761, 348889, 418667, 502409, 602887,
+ 723467, 868151, 1041779, 1250141, 1500181, 1800191, 2160233, 2592277,
+ 3110741, 3732887, 4479463, 5375371, 6450413, 7740517, 9288589, 11146307,
+ 13375573, 16050689, 19260817, 23112977, 27735583, 33282701, 39939233,
+ 47927081, 57512503, 69014987, 82818011, 99381577, 119257891, 143109469,
+ 171731387, 206077643, 247293161, 296751781, 356102141, 427322587,
+ 512787097, 615344489, 738413383, 886096061, 1063315271, 1275978331,
+ 1531174013, 1837408799, 2204890543UL, 2645868653UL, 3175042391UL,
+ 3810050851UL,
+#if SIZE_MAX > 4294967295UL
+ 4572061027UL, 5486473229UL, 6583767889UL, 7900521449UL, 9480625733UL,
+ 11376750877UL, 13652101063UL, 16382521261UL, 19659025513UL, 23590830631UL,
+ 28308996763UL, 33970796089UL, 40764955463UL, 48917946377UL, 58701535657UL,
+ 70441842749UL, 84530211301UL, 101436253561UL, 121723504277UL,
+ 146068205131UL, 175281846149UL, 210338215379UL, 252405858521UL,
+ 302887030151UL, 363464436191UL, 436157323417UL, 523388788231UL,
+ 628066545713UL, 753679854847UL, 904415825857UL, 1085298991109UL,
+ 1302358789181UL, 1562830547009UL, 1875396656429UL, 2250475987709UL,
+ 2700571185239UL, 3240685422287UL, 3888822506759UL, 4666587008147UL,
+ 5599904409713UL, 6719885291641UL, 8063862349969UL, 9676634819959UL,
+ 11611961783951UL, 13934354140769UL, 16721224968907UL, 20065469962669UL,
+ 24078563955191UL, 28894276746229UL, 34673132095507UL, 41607758514593UL,
+ 49929310217531UL, 59915172260971UL, 71898206713183UL, 86277848055823UL,
+ 103533417666967UL, 124240101200359UL, 149088121440451UL, 178905745728529UL,
+ 214686894874223UL, 257624273849081UL, 309149128618903UL, 370978954342639UL,
+ 445174745211143UL, 534209694253381UL, 641051633104063UL, 769261959724877UL,
+ 923114351670013UL, 1107737222003791UL, 1329284666404567UL,
+ 1595141599685509UL, 1914169919622551UL, 2297003903547091UL,
+ 2756404684256459UL, 3307685621107757UL, 3969222745329323UL,
+ 4763067294395177UL, 5715680753274209UL, 6858816903929113UL,
+ 8230580284714831UL, 9876696341657791UL, 11852035609989371UL,
+ 14222442731987227UL, 17066931278384657UL, 20480317534061597UL,
+ 24576381040873903UL, 29491657249048679UL, 35389988698858471UL,
+ 42467986438630267UL, 50961583726356109UL, 61153900471627387UL,
+ 73384680565952851UL, 88061616679143347UL, 105673940014972061UL,
+ 126808728017966413UL, 152170473621559703UL, 182604568345871671UL,
+ 219125482015045997UL, 262950578418055169UL, 315540694101666193UL,
+ 378648832921999397UL, 454378599506399233UL, 545254319407679131UL,
+ 654305183289214771UL, 785166219947057701UL, 942199463936469157UL,
+ 1130639356723763129UL, 1356767228068515623UL, 1628120673682218619UL,
+ 1953744808418662409UL, 2344493770102394881UL, 2813392524122873857UL,
+ 3376071028947448339UL, 4051285234736937517UL, 4861542281684325481UL,
+ 5833850738021191727UL, 7000620885625427969UL, 8400745062750513217UL,
+ 10080894075300616261UL, 12097072890360739951UL, 14516487468432885797UL,
+ 17419784962119465179UL,
+#endif
+ SIZE_MAX /* sentinel, to ensure the search terminates */
+ };
+
+/* Return a suitable prime >= ESTIMATE. */
+static size_t
+next_prime (size_t estimate)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof (primes) / sizeof (primes[0]); i++)
+ if (primes[i] >= estimate)
+ return primes[i];
+ return SIZE_MAX; /* not a prime, but better than nothing */
+}
+
+/* Resize the hash table with a new estimated size. */
+static void
+hash_resize (gl_list_t list, size_t estimate)
+{
+ size_t new_size = next_prime (estimate);
+
+ if (new_size > list->table_size)
+ {
+ gl_hash_entry_t *old_table = list->table;
+ /* Allocate the new table. */
+ gl_hash_entry_t *new_table;
+ size_t i;
+
+ if (size_overflow_p (xtimes (new_size, sizeof (gl_hash_entry_t))))
+ goto fail;
+ new_table =
+ (gl_hash_entry_t *) calloc (new_size, sizeof (gl_hash_entry_t));
+ if (new_table == NULL)
+ goto fail;
+
+ /* Iterate through the entries of the old table. */
+ for (i = list->table_size; i > 0; )
+ {
+ gl_hash_entry_t node = old_table[--i];
+
+ while (node != NULL)
+ {
+ gl_hash_entry_t next = node->hash_next;
+ /* Add the entry to the new table. */
+ size_t bucket = node->hashcode % new_size;
+ node->hash_next = new_table[bucket];
+ new_table[bucket] = node;
+
+ node = next;
+ }
+ }
+
+ list->table = new_table;
+ list->table_size = new_size;
+ free (old_table);
+ }
+ return;
+
+ fail:
+ /* Just continue without resizing the table. */
+ return;
+}
diff --git a/contrib/tools/bison/gnulib/src/gl_anylinked_list1.h b/contrib/tools/bison/gnulib/src/gl_anylinked_list1.h
index c8879f0f68..3c7ed963d8 100644
--- a/contrib/tools/bison/gnulib/src/gl_anylinked_list1.h
+++ b/contrib/tools/bison/gnulib/src/gl_anylinked_list1.h
@@ -1,48 +1,48 @@
-/* Sequential list data type implemented by a linked list.
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Common code of gl_linked_list.c and gl_linkedhash_list.c. */
-
-/* -------------------------- gl_list_t Data Type -------------------------- */
-
-/* Concrete list node implementation, valid for this file only. */
-struct gl_list_node_impl
-{
-#if WITH_HASHTABLE
- struct gl_hash_entry h; /* hash table entry fields; must be first */
-#endif
- struct gl_list_node_impl *next;
- struct gl_list_node_impl *prev;
- const void *value;
-};
-
-/* Concrete gl_list_impl type, valid for this file only. */
-struct gl_list_impl
-{
- struct gl_list_impl_base base;
-#if WITH_HASHTABLE
- /* A hash table: managed as an array of collision lists. */
- struct gl_hash_entry **table;
- size_t table_size;
-#endif
- /* A circular list anchored at root.
- The first node is = root.next, the last node is = root.prev.
- The root's value is unused. */
- struct gl_list_node_impl root;
- /* Number of list nodes, excluding the root. */
- size_t count;
-};
+/* Sequential list data type implemented by a linked list.
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Common code of gl_linked_list.c and gl_linkedhash_list.c. */
+
+/* -------------------------- gl_list_t Data Type -------------------------- */
+
+/* Concrete list node implementation, valid for this file only. */
+struct gl_list_node_impl
+{
+#if WITH_HASHTABLE
+ struct gl_hash_entry h; /* hash table entry fields; must be first */
+#endif
+ struct gl_list_node_impl *next;
+ struct gl_list_node_impl *prev;
+ const void *value;
+};
+
+/* Concrete gl_list_impl type, valid for this file only. */
+struct gl_list_impl
+{
+ struct gl_list_impl_base base;
+#if WITH_HASHTABLE
+ /* A hash table: managed as an array of collision lists. */
+ struct gl_hash_entry **table;
+ size_t table_size;
+#endif
+ /* A circular list anchored at root.
+ The first node is = root.next, the last node is = root.prev.
+ The root's value is unused. */
+ struct gl_list_node_impl root;
+ /* Number of list nodes, excluding the root. */
+ size_t count;
+};
diff --git a/contrib/tools/bison/gnulib/src/gl_anylinked_list2.h b/contrib/tools/bison/gnulib/src/gl_anylinked_list2.h
index 45ca7c829a..96a94f0e09 100644
--- a/contrib/tools/bison/gnulib/src/gl_anylinked_list2.h
+++ b/contrib/tools/bison/gnulib/src/gl_anylinked_list2.h
@@ -1,1195 +1,1195 @@
-/* Sequential list data type implemented by a linked list.
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Common code of gl_linked_list.c and gl_linkedhash_list.c. */
-
-/* If the symbol SIGNAL_SAFE_LIST is defined, the code is compiled in such
- a way that a gl_list_t data structure may be used from within a signal
- handler. The operations allowed in the signal handler are:
- gl_list_iterator, gl_list_iterator_next, gl_list_iterator_free.
- The list and node fields that are therefore accessed from the signal handler
- are:
- list->root, node->next, node->value.
- We are careful to make modifications to these fields only in an order
- that maintains the consistency of the list data structure at any moment,
- and we use 'volatile' assignments to prevent the compiler from reordering
- such assignments. */
-#ifdef SIGNAL_SAFE_LIST
-# define ASYNCSAFE(type) *(volatile type *)&
-#else
-# define ASYNCSAFE(type)
-#endif
-
-/* -------------------------- gl_list_t Data Type -------------------------- */
-
-static gl_list_t
-gl_linked_nx_create_empty (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates)
-{
- struct gl_list_impl *list =
- (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl));
-
- if (list == NULL)
- return NULL;
-
- list->base.vtable = implementation;
- list->base.equals_fn = equals_fn;
- list->base.hashcode_fn = hashcode_fn;
- list->base.dispose_fn = dispose_fn;
- list->base.allow_duplicates = allow_duplicates;
-#if WITH_HASHTABLE
- list->table_size = 11;
- list->table =
- (gl_hash_entry_t *) calloc (list->table_size, sizeof (gl_hash_entry_t));
- if (list->table == NULL)
- goto fail;
-#endif
- list->root.next = &list->root;
- list->root.prev = &list->root;
- list->count = 0;
-
- return list;
-
-#if WITH_HASHTABLE
- fail:
- free (list);
- return NULL;
-#endif
-}
-
-static gl_list_t
-gl_linked_nx_create (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates,
- size_t count, const void **contents)
-{
- struct gl_list_impl *list =
- (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl));
- gl_list_node_t tail;
-
- if (list == NULL)
- return NULL;
-
- list->base.vtable = implementation;
- list->base.equals_fn = equals_fn;
- list->base.hashcode_fn = hashcode_fn;
- list->base.dispose_fn = dispose_fn;
- list->base.allow_duplicates = allow_duplicates;
-#if WITH_HASHTABLE
- {
- size_t estimate = xsum (count, count / 2); /* 1.5 * count */
- if (estimate < 10)
- estimate = 10;
- list->table_size = next_prime (estimate);
- if (size_overflow_p (xtimes (list->table_size, sizeof (gl_hash_entry_t))))
- goto fail1;
- list->table =
- (gl_hash_entry_t *) calloc (list->table_size, sizeof (gl_hash_entry_t));
- if (list->table == NULL)
- goto fail1;
- }
-#endif
- list->count = count;
- tail = &list->root;
- for (; count > 0; contents++, count--)
- {
- gl_list_node_t node =
- (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
-
- if (node == NULL)
- goto fail2;
-
- node->value = *contents;
-#if WITH_HASHTABLE
- node->h.hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (node->value)
- : (size_t)(uintptr_t) node->value);
-
- /* Add node to the hash table. */
- if (add_to_bucket (list, node) < 0)
- {
- free (node);
- goto fail2;
- }
-#endif
-
- /* Add node to the list. */
- node->prev = tail;
- tail->next = node;
- tail = node;
- }
- tail->next = &list->root;
- list->root.prev = tail;
-
- return list;
-
- fail2:
- {
- gl_list_node_t node;
-
- for (node = tail; node != &list->root; )
- {
- gl_list_node_t prev = node->prev;
-
- free (node);
- node = prev;
- }
- }
-#if WITH_HASHTABLE
- free (list->table);
- fail1:
-#endif
- free (list);
- return NULL;
-}
-
-static size_t
-gl_linked_size (gl_list_t list)
-{
- return list->count;
-}
-
-static const void *
-gl_linked_node_value (gl_list_t list, gl_list_node_t node)
-{
- return node->value;
-}
-
-static int
-gl_linked_node_nx_set_value (gl_list_t list, gl_list_node_t node,
- const void *elt)
-{
-#if WITH_HASHTABLE
- if (elt != node->value)
- {
- size_t new_hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (elt)
- : (size_t)(uintptr_t) elt);
-
- if (new_hashcode != node->h.hashcode)
- {
- remove_from_bucket (list, node);
- node->value = elt;
- node->h.hashcode = new_hashcode;
- if (add_to_bucket (list, node) < 0)
- {
- /* Out of memory. We removed node from a bucket but cannot add
- it to another bucket. In order to avoid inconsistencies, we
- must remove node entirely from the list. */
- gl_list_node_t before_removed = node->prev;
- gl_list_node_t after_removed = node->next;
- ASYNCSAFE(gl_list_node_t) before_removed->next = after_removed;
- after_removed->prev = before_removed;
- list->count--;
- free (node);
- return -1;
- }
- }
- else
- node->value = elt;
- }
-#else
- node->value = elt;
-#endif
- return 0;
-}
-
-static gl_list_node_t
-gl_linked_next_node (gl_list_t list, gl_list_node_t node)
-{
- return (node->next != &list->root ? node->next : NULL);
-}
-
-static gl_list_node_t
-gl_linked_previous_node (gl_list_t list, gl_list_node_t node)
-{
- return (node->prev != &list->root ? node->prev : NULL);
-}
-
-static const void *
-gl_linked_get_at (gl_list_t list, size_t position)
-{
- size_t count = list->count;
- gl_list_node_t node;
-
- if (!(position < count))
- /* Invalid argument. */
- abort ();
- /* Here we know count > 0. */
- if (position <= ((count - 1) / 2))
- {
- node = list->root.next;
- for (; position > 0; position--)
- node = node->next;
- }
- else
- {
- position = count - 1 - position;
- node = list->root.prev;
- for (; position > 0; position--)
- node = node->prev;
- }
- return node->value;
-}
-
-static gl_list_node_t
-gl_linked_nx_set_at (gl_list_t list, size_t position, const void *elt)
-{
- size_t count = list->count;
- gl_list_node_t node;
-
- if (!(position < count))
- /* Invalid argument. */
- abort ();
- /* Here we know count > 0. */
- if (position <= ((count - 1) / 2))
- {
- node = list->root.next;
- for (; position > 0; position--)
- node = node->next;
- }
- else
- {
- position = count - 1 - position;
- node = list->root.prev;
- for (; position > 0; position--)
- node = node->prev;
- }
-#if WITH_HASHTABLE
- if (elt != node->value)
- {
- size_t new_hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (elt)
- : (size_t)(uintptr_t) elt);
-
- if (new_hashcode != node->h.hashcode)
- {
- remove_from_bucket (list, node);
- node->value = elt;
- node->h.hashcode = new_hashcode;
- if (add_to_bucket (list, node) < 0)
- {
- /* Out of memory. We removed node from a bucket but cannot add
- it to another bucket. In order to avoid inconsistencies, we
- must remove node entirely from the list. */
- gl_list_node_t before_removed = node->prev;
- gl_list_node_t after_removed = node->next;
- ASYNCSAFE(gl_list_node_t) before_removed->next = after_removed;
- after_removed->prev = before_removed;
- list->count--;
- free (node);
- return NULL;
- }
- }
- else
- node->value = elt;
- }
-#else
- node->value = elt;
-#endif
- return node;
-}
-
-static gl_list_node_t
-gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
- const void *elt)
-{
- size_t count = list->count;
-
- if (!(start_index <= end_index && end_index <= count))
- /* Invalid arguments. */
- abort ();
- {
-#if WITH_HASHTABLE
- size_t hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (elt)
- : (size_t)(uintptr_t) elt);
- size_t bucket = hashcode % list->table_size;
- gl_listelement_equals_fn equals = list->base.equals_fn;
-
- if (!list->base.allow_duplicates)
- {
- /* Look for the first match in the hash bucket. */
- gl_list_node_t found = NULL;
- gl_list_node_t node;
-
- for (node = (gl_list_node_t) list->table[bucket];
- node != NULL;
- node = (gl_list_node_t) node->h.hash_next)
- if (node->h.hashcode == hashcode
- && (equals != NULL
- ? equals (elt, node->value)
- : elt == node->value))
- {
- found = node;
- break;
- }
- if (start_index > 0)
- /* Look whether found's index is < start_index. */
- for (node = list->root.next; ; node = node->next)
- {
- if (node == found)
- return NULL;
- if (--start_index == 0)
- break;
- }
- if (end_index < count)
- /* Look whether found's index is >= end_index. */
- {
- end_index = count - end_index;
- for (node = list->root.prev; ; node = node->prev)
- {
- if (node == found)
- return NULL;
- if (--end_index == 0)
- break;
- }
- }
- return found;
- }
- else
- {
- /* Look whether there is more than one match in the hash bucket. */
- bool multiple_matches = false;
- gl_list_node_t first_match = NULL;
- gl_list_node_t node;
-
- for (node = (gl_list_node_t) list->table[bucket];
- node != NULL;
- node = (gl_list_node_t) node->h.hash_next)
- if (node->h.hashcode == hashcode
- && (equals != NULL
- ? equals (elt, node->value)
- : elt == node->value))
- {
- if (first_match == NULL)
- first_match = node;
- else
- {
- multiple_matches = true;
- break;
- }
- }
- if (multiple_matches)
- {
- /* We need the match with the smallest index. But we don't have
- a fast mapping node -> index. So we have to walk the list. */
- end_index -= start_index;
- node = list->root.next;
- for (; start_index > 0; start_index--)
- node = node->next;
-
- for (;
- end_index > 0;
- node = node->next, end_index--)
- if (node->h.hashcode == hashcode
- && (equals != NULL
- ? equals (elt, node->value)
- : elt == node->value))
- return node;
- /* The matches must have all been at indices < start_index or
- >= end_index. */
- return NULL;
- }
- else
- {
- if (start_index > 0)
- /* Look whether first_match's index is < start_index. */
- for (node = list->root.next; node != &list->root; node = node->next)
- {
- if (node == first_match)
- return NULL;
- if (--start_index == 0)
- break;
- }
- if (end_index < list->count)
- /* Look whether first_match's index is >= end_index. */
- {
- end_index = list->count - end_index;
- for (node = list->root.prev; ; node = node->prev)
- {
- if (node == first_match)
- return NULL;
- if (--end_index == 0)
- break;
- }
- }
- return first_match;
- }
- }
-#else
- gl_listelement_equals_fn equals = list->base.equals_fn;
- gl_list_node_t node = list->root.next;
-
- end_index -= start_index;
- for (; start_index > 0; start_index--)
- node = node->next;
-
- if (equals != NULL)
- {
- for (; end_index > 0; node = node->next, end_index--)
- if (equals (elt, node->value))
- return node;
- }
- else
- {
- for (; end_index > 0; node = node->next, end_index--)
- if (elt == node->value)
- return node;
- }
- return NULL;
-#endif
- }
-}
-
-static size_t
-gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
- const void *elt)
-{
- size_t count = list->count;
-
- if (!(start_index <= end_index && end_index <= count))
- /* Invalid arguments. */
- abort ();
- {
-#if WITH_HASHTABLE
- /* Here the hash table doesn't help much. It only allows us to minimize
- the number of equals() calls, by looking up first the node and then
- its index. */
- size_t hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (elt)
- : (size_t)(uintptr_t) elt);
- size_t bucket = hashcode % list->table_size;
- gl_listelement_equals_fn equals = list->base.equals_fn;
- gl_list_node_t node;
-
- /* First step: Look up the node. */
- if (!list->base.allow_duplicates)
- {
- /* Look for the first match in the hash bucket. */
- for (node = (gl_list_node_t) list->table[bucket];
- node != NULL;
- node = (gl_list_node_t) node->h.hash_next)
- if (node->h.hashcode == hashcode
- && (equals != NULL
- ? equals (elt, node->value)
- : elt == node->value))
- break;
- }
- else
- {
- /* Look whether there is more than one match in the hash bucket. */
- bool multiple_matches = false;
- gl_list_node_t first_match = NULL;
-
- for (node = (gl_list_node_t) list->table[bucket];
- node != NULL;
- node = (gl_list_node_t) node->h.hash_next)
- if (node->h.hashcode == hashcode
- && (equals != NULL
- ? equals (elt, node->value)
- : elt == node->value))
- {
- if (first_match == NULL)
- first_match = node;
- else
- {
- multiple_matches = true;
- break;
- }
- }
- if (multiple_matches)
- {
- /* We need the match with the smallest index. But we don't have
- a fast mapping node -> index. So we have to walk the list. */
- size_t index;
-
- index = start_index;
- node = list->root.next;
- for (; start_index > 0; start_index--)
- node = node->next;
-
- for (;
- index < end_index;
- node = node->next, index++)
- if (node->h.hashcode == hashcode
- && (equals != NULL
- ? equals (elt, node->value)
- : elt == node->value))
- return index;
- /* The matches must have all been at indices < start_index or
- >= end_index. */
- return (size_t)(-1);
- }
- node = first_match;
- }
-
- /* Second step: Look up the index of the node. */
- if (node == NULL)
- return (size_t)(-1);
- else
- {
- size_t index = 0;
-
- for (; node->prev != &list->root; node = node->prev)
- index++;
-
- if (index >= start_index && index < end_index)
- return index;
- else
- return (size_t)(-1);
- }
-#else
- gl_listelement_equals_fn equals = list->base.equals_fn;
- size_t index = start_index;
- gl_list_node_t node = list->root.next;
-
- for (; start_index > 0; start_index--)
- node = node->next;
-
- if (equals != NULL)
- {
- for (;
- index < end_index;
- node = node->next, index++)
- if (equals (elt, node->value))
- return index;
- }
- else
- {
- for (;
- index < end_index;
- node = node->next, index++)
- if (elt == node->value)
- return index;
- }
- return (size_t)(-1);
-#endif
- }
-}
-
-static gl_list_node_t
-gl_linked_nx_add_first (gl_list_t list, const void *elt)
-{
- gl_list_node_t node =
- (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
-
- if (node == NULL)
- return NULL;
-
- ASYNCSAFE(const void *) node->value = elt;
-#if WITH_HASHTABLE
- node->h.hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (node->value)
- : (size_t)(uintptr_t) node->value);
-
- /* Add node to the hash table. */
- if (add_to_bucket (list, node) < 0)
- {
- free (node);
- return NULL;
- }
-#endif
-
- /* Add node to the list. */
- node->prev = &list->root;
- ASYNCSAFE(gl_list_node_t) node->next = list->root.next;
- node->next->prev = node;
- ASYNCSAFE(gl_list_node_t) list->root.next = node;
- list->count++;
-
-#if WITH_HASHTABLE
- hash_resize_after_add (list);
-#endif
-
- return node;
-}
-
-static gl_list_node_t
-gl_linked_nx_add_last (gl_list_t list, const void *elt)
-{
- gl_list_node_t node =
- (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
-
- if (node == NULL)
- return NULL;
-
- ASYNCSAFE(const void *) node->value = elt;
-#if WITH_HASHTABLE
- node->h.hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (node->value)
- : (size_t)(uintptr_t) node->value);
-
- /* Add node to the hash table. */
- if (add_to_bucket (list, node) < 0)
- {
- free (node);
- return NULL;
- }
-#endif
-
- /* Add node to the list. */
- ASYNCSAFE(gl_list_node_t) node->next = &list->root;
- node->prev = list->root.prev;
- ASYNCSAFE(gl_list_node_t) node->prev->next = node;
- list->root.prev = node;
- list->count++;
-
-#if WITH_HASHTABLE
- hash_resize_after_add (list);
-#endif
-
- return node;
-}
-
-static gl_list_node_t
-gl_linked_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
-{
- gl_list_node_t new_node =
- (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
-
- if (new_node == NULL)
- return NULL;
-
- ASYNCSAFE(const void *) new_node->value = elt;
-#if WITH_HASHTABLE
- new_node->h.hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (new_node->value)
- : (size_t)(uintptr_t) new_node->value);
-
- /* Add new_node to the hash table. */
- if (add_to_bucket (list, new_node) < 0)
- {
- free (new_node);
- return NULL;
- }
-#endif
-
- /* Add new_node to the list. */
- ASYNCSAFE(gl_list_node_t) new_node->next = node;
- new_node->prev = node->prev;
- ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node;
- node->prev = new_node;
- list->count++;
-
-#if WITH_HASHTABLE
- hash_resize_after_add (list);
-#endif
-
- return new_node;
-}
-
-static gl_list_node_t
-gl_linked_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
-{
- gl_list_node_t new_node =
- (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
-
- if (new_node == NULL)
- return NULL;
-
- ASYNCSAFE(const void *) new_node->value = elt;
-#if WITH_HASHTABLE
- new_node->h.hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (new_node->value)
- : (size_t)(uintptr_t) new_node->value);
-
- /* Add new_node to the hash table. */
- if (add_to_bucket (list, new_node) < 0)
- {
- free (new_node);
- return NULL;
- }
-#endif
-
- /* Add new_node to the list. */
- new_node->prev = node;
- ASYNCSAFE(gl_list_node_t) new_node->next = node->next;
- new_node->next->prev = new_node;
- ASYNCSAFE(gl_list_node_t) node->next = new_node;
- list->count++;
-
-#if WITH_HASHTABLE
- hash_resize_after_add (list);
-#endif
-
- return new_node;
-}
-
-static gl_list_node_t
-gl_linked_nx_add_at (gl_list_t list, size_t position, const void *elt)
-{
- size_t count = list->count;
- gl_list_node_t new_node;
-
- if (!(position <= count))
- /* Invalid argument. */
- abort ();
-
- new_node = (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
- if (new_node == NULL)
- return NULL;
-
- ASYNCSAFE(const void *) new_node->value = elt;
-#if WITH_HASHTABLE
- new_node->h.hashcode =
- (list->base.hashcode_fn != NULL
- ? list->base.hashcode_fn (new_node->value)
- : (size_t)(uintptr_t) new_node->value);
-
- /* Add new_node to the hash table. */
- if (add_to_bucket (list, new_node) < 0)
- {
- free (new_node);
- return NULL;
- }
-#endif
-
- /* Add new_node to the list. */
- if (position <= (count / 2))
- {
- gl_list_node_t node;
-
- node = &list->root;
- for (; position > 0; position--)
- node = node->next;
- new_node->prev = node;
- ASYNCSAFE(gl_list_node_t) new_node->next = node->next;
- new_node->next->prev = new_node;
- ASYNCSAFE(gl_list_node_t) node->next = new_node;
- }
- else
- {
- gl_list_node_t node;
-
- position = count - position;
- node = &list->root;
- for (; position > 0; position--)
- node = node->prev;
- ASYNCSAFE(gl_list_node_t) new_node->next = node;
- new_node->prev = node->prev;
- ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node;
- node->prev = new_node;
- }
- list->count++;
-
-#if WITH_HASHTABLE
- hash_resize_after_add (list);
-#endif
-
- return new_node;
-}
-
-static bool
-gl_linked_remove_node (gl_list_t list, gl_list_node_t node)
-{
- gl_list_node_t prev;
- gl_list_node_t next;
-
-#if WITH_HASHTABLE
- /* Remove node from the hash table. */
- remove_from_bucket (list, node);
-#endif
-
- /* Remove node from the list. */
- prev = node->prev;
- next = node->next;
-
- ASYNCSAFE(gl_list_node_t) prev->next = next;
- next->prev = prev;
- list->count--;
-
- if (list->base.dispose_fn != NULL)
- list->base.dispose_fn (node->value);
- free (node);
- return true;
-}
-
-static bool
-gl_linked_remove_at (gl_list_t list, size_t position)
-{
- size_t count = list->count;
- gl_list_node_t removed_node;
-
- if (!(position < count))
- /* Invalid argument. */
- abort ();
- /* Here we know count > 0. */
- if (position <= ((count - 1) / 2))
- {
- gl_list_node_t node;
- gl_list_node_t after_removed;
-
- node = &list->root;
- for (; position > 0; position--)
- node = node->next;
- removed_node = node->next;
- after_removed = node->next->next;
- ASYNCSAFE(gl_list_node_t) node->next = after_removed;
- after_removed->prev = node;
- }
- else
- {
- gl_list_node_t node;
- gl_list_node_t before_removed;
-
- position = count - 1 - position;
- node = &list->root;
- for (; position > 0; position--)
- node = node->prev;
- removed_node = node->prev;
- before_removed = node->prev->prev;
- node->prev = before_removed;
- ASYNCSAFE(gl_list_node_t) before_removed->next = node;
- }
-#if WITH_HASHTABLE
- remove_from_bucket (list, removed_node);
-#endif
- list->count--;
-
- if (list->base.dispose_fn != NULL)
- list->base.dispose_fn (removed_node->value);
- free (removed_node);
- return true;
-}
-
-static bool
-gl_linked_remove (gl_list_t list, const void *elt)
-{
- gl_list_node_t node = gl_linked_search_from_to (list, 0, list->count, elt);
-
- if (node != NULL)
- return gl_linked_remove_node (list, node);
- else
- return false;
-}
-
-static void
-gl_linked_list_free (gl_list_t list)
-{
- gl_listelement_dispose_fn dispose = list->base.dispose_fn;
- gl_list_node_t node;
-
- for (node = list->root.next; node != &list->root; )
- {
- gl_list_node_t next = node->next;
- if (dispose != NULL)
- dispose (node->value);
- free (node);
- node = next;
- }
-#if WITH_HASHTABLE
- free (list->table);
-#endif
- free (list);
-}
-
-/* --------------------- gl_list_iterator_t Data Type --------------------- */
-
-static gl_list_iterator_t
-gl_linked_iterator (gl_list_t list)
-{
- gl_list_iterator_t result;
-
- result.vtable = list->base.vtable;
- result.list = list;
- result.p = list->root.next;
- result.q = &list->root;
-#ifdef lint
- result.i = 0;
- result.j = 0;
- result.count = 0;
-#endif
-
- return result;
-}
-
-static gl_list_iterator_t
-gl_linked_iterator_from_to (gl_list_t list,
- size_t start_index, size_t end_index)
-{
- gl_list_iterator_t result;
- size_t n1, n2, n3;
-
- if (!(start_index <= end_index && end_index <= list->count))
- /* Invalid arguments. */
- abort ();
- result.vtable = list->base.vtable;
- result.list = list;
- n1 = start_index;
- n2 = end_index - start_index;
- n3 = list->count - end_index;
- /* Find the maximum among n1, n2, n3, so as to reduce the number of
- loop iterations to n1 + n2 + n3 - max(n1,n2,n3). */
- if (n1 > n2 && n1 > n3)
- {
- /* n1 is the maximum, use n2 and n3. */
- gl_list_node_t node;
- size_t i;
-
- node = &list->root;
- for (i = n3; i > 0; i--)
- node = node->prev;
- result.q = node;
- for (i = n2; i > 0; i--)
- node = node->prev;
- result.p = node;
- }
- else if (n2 > n3)
- {
- /* n2 is the maximum, use n1 and n3. */
- gl_list_node_t node;
- size_t i;
-
- node = list->root.next;
- for (i = n1; i > 0; i--)
- node = node->next;
- result.p = node;
-
- node = &list->root;
- for (i = n3; i > 0; i--)
- node = node->prev;
- result.q = node;
- }
- else
- {
- /* n3 is the maximum, use n1 and n2. */
- gl_list_node_t node;
- size_t i;
-
- node = list->root.next;
- for (i = n1; i > 0; i--)
- node = node->next;
- result.p = node;
- for (i = n2; i > 0; i--)
- node = node->next;
- result.q = node;
- }
-
-#ifdef lint
- result.i = 0;
- result.j = 0;
- result.count = 0;
-#endif
-
- return result;
-}
-
-static bool
-gl_linked_iterator_next (gl_list_iterator_t *iterator,
- const void **eltp, gl_list_node_t *nodep)
-{
- if (iterator->p != iterator->q)
- {
- gl_list_node_t node = (gl_list_node_t) iterator->p;
- *eltp = node->value;
- if (nodep != NULL)
- *nodep = node;
- iterator->p = node->next;
- return true;
- }
- else
- return false;
-}
-
-static void
-gl_linked_iterator_free (gl_list_iterator_t *iterator)
-{
-}
-
-/* ---------------------- Sorted gl_list_t Data Type ---------------------- */
-
-static gl_list_node_t
-gl_linked_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar,
- const void *elt)
-{
- gl_list_node_t node;
-
- for (node = list->root.next; node != &list->root; node = node->next)
- {
- int cmp = compar (node->value, elt);
-
- if (cmp > 0)
- break;
- if (cmp == 0)
- return node;
- }
- return NULL;
-}
-
-static gl_list_node_t
-gl_linked_sortedlist_search_from_to (gl_list_t list,
- gl_listelement_compar_fn compar,
- size_t low, size_t high,
- const void *elt)
-{
- size_t count = list->count;
-
- if (!(low <= high && high <= list->count))
- /* Invalid arguments. */
- abort ();
-
- high -= low;
- if (high > 0)
- {
- /* Here we know low < count. */
- size_t position = low;
- gl_list_node_t node;
-
- if (position <= ((count - 1) / 2))
- {
- node = list->root.next;
- for (; position > 0; position--)
- node = node->next;
- }
- else
- {
- position = count - 1 - position;
- node = list->root.prev;
- for (; position > 0; position--)
- node = node->prev;
- }
-
- do
- {
- int cmp = compar (node->value, elt);
-
- if (cmp > 0)
- break;
- if (cmp == 0)
- return node;
- node = node->next;
- }
- while (--high > 0);
- }
- return NULL;
-}
-
-static size_t
-gl_linked_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar,
- const void *elt)
-{
- gl_list_node_t node;
- size_t index;
-
- for (node = list->root.next, index = 0;
- node != &list->root;
- node = node->next, index++)
- {
- int cmp = compar (node->value, elt);
-
- if (cmp > 0)
- break;
- if (cmp == 0)
- return index;
- }
- return (size_t)(-1);
-}
-
-static size_t
-gl_linked_sortedlist_indexof_from_to (gl_list_t list,
- gl_listelement_compar_fn compar,
- size_t low, size_t high,
- const void *elt)
-{
- size_t count = list->count;
-
- if (!(low <= high && high <= list->count))
- /* Invalid arguments. */
- abort ();
-
- high -= low;
- if (high > 0)
- {
- /* Here we know low < count. */
- size_t index = low;
- size_t position = low;
- gl_list_node_t node;
-
- if (position <= ((count - 1) / 2))
- {
- node = list->root.next;
- for (; position > 0; position--)
- node = node->next;
- }
- else
- {
- position = count - 1 - position;
- node = list->root.prev;
- for (; position > 0; position--)
- node = node->prev;
- }
-
- do
- {
- int cmp = compar (node->value, elt);
-
- if (cmp > 0)
- break;
- if (cmp == 0)
- return index;
- node = node->next;
- index++;
- }
- while (--high > 0);
- }
- return (size_t)(-1);
-}
-
-static gl_list_node_t
-gl_linked_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar,
- const void *elt)
-{
- gl_list_node_t node;
-
- for (node = list->root.next; node != &list->root; node = node->next)
- if (compar (node->value, elt) >= 0)
- return gl_linked_nx_add_before (list, node, elt);
- return gl_linked_nx_add_last (list, elt);
-}
-
-static bool
-gl_linked_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar,
- const void *elt)
-{
- gl_list_node_t node;
-
- for (node = list->root.next; node != &list->root; node = node->next)
- {
- int cmp = compar (node->value, elt);
-
- if (cmp > 0)
- break;
- if (cmp == 0)
- return gl_linked_remove_node (list, node);
- }
- return false;
-}
+/* Sequential list data type implemented by a linked list.
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Common code of gl_linked_list.c and gl_linkedhash_list.c. */
+
+/* If the symbol SIGNAL_SAFE_LIST is defined, the code is compiled in such
+ a way that a gl_list_t data structure may be used from within a signal
+ handler. The operations allowed in the signal handler are:
+ gl_list_iterator, gl_list_iterator_next, gl_list_iterator_free.
+ The list and node fields that are therefore accessed from the signal handler
+ are:
+ list->root, node->next, node->value.
+ We are careful to make modifications to these fields only in an order
+ that maintains the consistency of the list data structure at any moment,
+ and we use 'volatile' assignments to prevent the compiler from reordering
+ such assignments. */
+#ifdef SIGNAL_SAFE_LIST
+# define ASYNCSAFE(type) *(volatile type *)&
+#else
+# define ASYNCSAFE(type)
+#endif
+
+/* -------------------------- gl_list_t Data Type -------------------------- */
+
+static gl_list_t
+gl_linked_nx_create_empty (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates)
+{
+ struct gl_list_impl *list =
+ (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl));
+
+ if (list == NULL)
+ return NULL;
+
+ list->base.vtable = implementation;
+ list->base.equals_fn = equals_fn;
+ list->base.hashcode_fn = hashcode_fn;
+ list->base.dispose_fn = dispose_fn;
+ list->base.allow_duplicates = allow_duplicates;
+#if WITH_HASHTABLE
+ list->table_size = 11;
+ list->table =
+ (gl_hash_entry_t *) calloc (list->table_size, sizeof (gl_hash_entry_t));
+ if (list->table == NULL)
+ goto fail;
+#endif
+ list->root.next = &list->root;
+ list->root.prev = &list->root;
+ list->count = 0;
+
+ return list;
+
+#if WITH_HASHTABLE
+ fail:
+ free (list);
+ return NULL;
+#endif
+}
+
+static gl_list_t
+gl_linked_nx_create (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates,
+ size_t count, const void **contents)
+{
+ struct gl_list_impl *list =
+ (struct gl_list_impl *) malloc (sizeof (struct gl_list_impl));
+ gl_list_node_t tail;
+
+ if (list == NULL)
+ return NULL;
+
+ list->base.vtable = implementation;
+ list->base.equals_fn = equals_fn;
+ list->base.hashcode_fn = hashcode_fn;
+ list->base.dispose_fn = dispose_fn;
+ list->base.allow_duplicates = allow_duplicates;
+#if WITH_HASHTABLE
+ {
+ size_t estimate = xsum (count, count / 2); /* 1.5 * count */
+ if (estimate < 10)
+ estimate = 10;
+ list->table_size = next_prime (estimate);
+ if (size_overflow_p (xtimes (list->table_size, sizeof (gl_hash_entry_t))))
+ goto fail1;
+ list->table =
+ (gl_hash_entry_t *) calloc (list->table_size, sizeof (gl_hash_entry_t));
+ if (list->table == NULL)
+ goto fail1;
+ }
+#endif
+ list->count = count;
+ tail = &list->root;
+ for (; count > 0; contents++, count--)
+ {
+ gl_list_node_t node =
+ (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
+
+ if (node == NULL)
+ goto fail2;
+
+ node->value = *contents;
+#if WITH_HASHTABLE
+ node->h.hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (node->value)
+ : (size_t)(uintptr_t) node->value);
+
+ /* Add node to the hash table. */
+ if (add_to_bucket (list, node) < 0)
+ {
+ free (node);
+ goto fail2;
+ }
+#endif
+
+ /* Add node to the list. */
+ node->prev = tail;
+ tail->next = node;
+ tail = node;
+ }
+ tail->next = &list->root;
+ list->root.prev = tail;
+
+ return list;
+
+ fail2:
+ {
+ gl_list_node_t node;
+
+ for (node = tail; node != &list->root; )
+ {
+ gl_list_node_t prev = node->prev;
+
+ free (node);
+ node = prev;
+ }
+ }
+#if WITH_HASHTABLE
+ free (list->table);
+ fail1:
+#endif
+ free (list);
+ return NULL;
+}
+
+static size_t
+gl_linked_size (gl_list_t list)
+{
+ return list->count;
+}
+
+static const void *
+gl_linked_node_value (gl_list_t list, gl_list_node_t node)
+{
+ return node->value;
+}
+
+static int
+gl_linked_node_nx_set_value (gl_list_t list, gl_list_node_t node,
+ const void *elt)
+{
+#if WITH_HASHTABLE
+ if (elt != node->value)
+ {
+ size_t new_hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (elt)
+ : (size_t)(uintptr_t) elt);
+
+ if (new_hashcode != node->h.hashcode)
+ {
+ remove_from_bucket (list, node);
+ node->value = elt;
+ node->h.hashcode = new_hashcode;
+ if (add_to_bucket (list, node) < 0)
+ {
+ /* Out of memory. We removed node from a bucket but cannot add
+ it to another bucket. In order to avoid inconsistencies, we
+ must remove node entirely from the list. */
+ gl_list_node_t before_removed = node->prev;
+ gl_list_node_t after_removed = node->next;
+ ASYNCSAFE(gl_list_node_t) before_removed->next = after_removed;
+ after_removed->prev = before_removed;
+ list->count--;
+ free (node);
+ return -1;
+ }
+ }
+ else
+ node->value = elt;
+ }
+#else
+ node->value = elt;
+#endif
+ return 0;
+}
+
+static gl_list_node_t
+gl_linked_next_node (gl_list_t list, gl_list_node_t node)
+{
+ return (node->next != &list->root ? node->next : NULL);
+}
+
+static gl_list_node_t
+gl_linked_previous_node (gl_list_t list, gl_list_node_t node)
+{
+ return (node->prev != &list->root ? node->prev : NULL);
+}
+
+static const void *
+gl_linked_get_at (gl_list_t list, size_t position)
+{
+ size_t count = list->count;
+ gl_list_node_t node;
+
+ if (!(position < count))
+ /* Invalid argument. */
+ abort ();
+ /* Here we know count > 0. */
+ if (position <= ((count - 1) / 2))
+ {
+ node = list->root.next;
+ for (; position > 0; position--)
+ node = node->next;
+ }
+ else
+ {
+ position = count - 1 - position;
+ node = list->root.prev;
+ for (; position > 0; position--)
+ node = node->prev;
+ }
+ return node->value;
+}
+
+static gl_list_node_t
+gl_linked_nx_set_at (gl_list_t list, size_t position, const void *elt)
+{
+ size_t count = list->count;
+ gl_list_node_t node;
+
+ if (!(position < count))
+ /* Invalid argument. */
+ abort ();
+ /* Here we know count > 0. */
+ if (position <= ((count - 1) / 2))
+ {
+ node = list->root.next;
+ for (; position > 0; position--)
+ node = node->next;
+ }
+ else
+ {
+ position = count - 1 - position;
+ node = list->root.prev;
+ for (; position > 0; position--)
+ node = node->prev;
+ }
+#if WITH_HASHTABLE
+ if (elt != node->value)
+ {
+ size_t new_hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (elt)
+ : (size_t)(uintptr_t) elt);
+
+ if (new_hashcode != node->h.hashcode)
+ {
+ remove_from_bucket (list, node);
+ node->value = elt;
+ node->h.hashcode = new_hashcode;
+ if (add_to_bucket (list, node) < 0)
+ {
+ /* Out of memory. We removed node from a bucket but cannot add
+ it to another bucket. In order to avoid inconsistencies, we
+ must remove node entirely from the list. */
+ gl_list_node_t before_removed = node->prev;
+ gl_list_node_t after_removed = node->next;
+ ASYNCSAFE(gl_list_node_t) before_removed->next = after_removed;
+ after_removed->prev = before_removed;
+ list->count--;
+ free (node);
+ return NULL;
+ }
+ }
+ else
+ node->value = elt;
+ }
+#else
+ node->value = elt;
+#endif
+ return node;
+}
+
+static gl_list_node_t
+gl_linked_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
+ const void *elt)
+{
+ size_t count = list->count;
+
+ if (!(start_index <= end_index && end_index <= count))
+ /* Invalid arguments. */
+ abort ();
+ {
+#if WITH_HASHTABLE
+ size_t hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (elt)
+ : (size_t)(uintptr_t) elt);
+ size_t bucket = hashcode % list->table_size;
+ gl_listelement_equals_fn equals = list->base.equals_fn;
+
+ if (!list->base.allow_duplicates)
+ {
+ /* Look for the first match in the hash bucket. */
+ gl_list_node_t found = NULL;
+ gl_list_node_t node;
+
+ for (node = (gl_list_node_t) list->table[bucket];
+ node != NULL;
+ node = (gl_list_node_t) node->h.hash_next)
+ if (node->h.hashcode == hashcode
+ && (equals != NULL
+ ? equals (elt, node->value)
+ : elt == node->value))
+ {
+ found = node;
+ break;
+ }
+ if (start_index > 0)
+ /* Look whether found's index is < start_index. */
+ for (node = list->root.next; ; node = node->next)
+ {
+ if (node == found)
+ return NULL;
+ if (--start_index == 0)
+ break;
+ }
+ if (end_index < count)
+ /* Look whether found's index is >= end_index. */
+ {
+ end_index = count - end_index;
+ for (node = list->root.prev; ; node = node->prev)
+ {
+ if (node == found)
+ return NULL;
+ if (--end_index == 0)
+ break;
+ }
+ }
+ return found;
+ }
+ else
+ {
+ /* Look whether there is more than one match in the hash bucket. */
+ bool multiple_matches = false;
+ gl_list_node_t first_match = NULL;
+ gl_list_node_t node;
+
+ for (node = (gl_list_node_t) list->table[bucket];
+ node != NULL;
+ node = (gl_list_node_t) node->h.hash_next)
+ if (node->h.hashcode == hashcode
+ && (equals != NULL
+ ? equals (elt, node->value)
+ : elt == node->value))
+ {
+ if (first_match == NULL)
+ first_match = node;
+ else
+ {
+ multiple_matches = true;
+ break;
+ }
+ }
+ if (multiple_matches)
+ {
+ /* We need the match with the smallest index. But we don't have
+ a fast mapping node -> index. So we have to walk the list. */
+ end_index -= start_index;
+ node = list->root.next;
+ for (; start_index > 0; start_index--)
+ node = node->next;
+
+ for (;
+ end_index > 0;
+ node = node->next, end_index--)
+ if (node->h.hashcode == hashcode
+ && (equals != NULL
+ ? equals (elt, node->value)
+ : elt == node->value))
+ return node;
+ /* The matches must have all been at indices < start_index or
+ >= end_index. */
+ return NULL;
+ }
+ else
+ {
+ if (start_index > 0)
+ /* Look whether first_match's index is < start_index. */
+ for (node = list->root.next; node != &list->root; node = node->next)
+ {
+ if (node == first_match)
+ return NULL;
+ if (--start_index == 0)
+ break;
+ }
+ if (end_index < list->count)
+ /* Look whether first_match's index is >= end_index. */
+ {
+ end_index = list->count - end_index;
+ for (node = list->root.prev; ; node = node->prev)
+ {
+ if (node == first_match)
+ return NULL;
+ if (--end_index == 0)
+ break;
+ }
+ }
+ return first_match;
+ }
+ }
+#else
+ gl_listelement_equals_fn equals = list->base.equals_fn;
+ gl_list_node_t node = list->root.next;
+
+ end_index -= start_index;
+ for (; start_index > 0; start_index--)
+ node = node->next;
+
+ if (equals != NULL)
+ {
+ for (; end_index > 0; node = node->next, end_index--)
+ if (equals (elt, node->value))
+ return node;
+ }
+ else
+ {
+ for (; end_index > 0; node = node->next, end_index--)
+ if (elt == node->value)
+ return node;
+ }
+ return NULL;
+#endif
+ }
+}
+
+static size_t
+gl_linked_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
+ const void *elt)
+{
+ size_t count = list->count;
+
+ if (!(start_index <= end_index && end_index <= count))
+ /* Invalid arguments. */
+ abort ();
+ {
+#if WITH_HASHTABLE
+ /* Here the hash table doesn't help much. It only allows us to minimize
+ the number of equals() calls, by looking up first the node and then
+ its index. */
+ size_t hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (elt)
+ : (size_t)(uintptr_t) elt);
+ size_t bucket = hashcode % list->table_size;
+ gl_listelement_equals_fn equals = list->base.equals_fn;
+ gl_list_node_t node;
+
+ /* First step: Look up the node. */
+ if (!list->base.allow_duplicates)
+ {
+ /* Look for the first match in the hash bucket. */
+ for (node = (gl_list_node_t) list->table[bucket];
+ node != NULL;
+ node = (gl_list_node_t) node->h.hash_next)
+ if (node->h.hashcode == hashcode
+ && (equals != NULL
+ ? equals (elt, node->value)
+ : elt == node->value))
+ break;
+ }
+ else
+ {
+ /* Look whether there is more than one match in the hash bucket. */
+ bool multiple_matches = false;
+ gl_list_node_t first_match = NULL;
+
+ for (node = (gl_list_node_t) list->table[bucket];
+ node != NULL;
+ node = (gl_list_node_t) node->h.hash_next)
+ if (node->h.hashcode == hashcode
+ && (equals != NULL
+ ? equals (elt, node->value)
+ : elt == node->value))
+ {
+ if (first_match == NULL)
+ first_match = node;
+ else
+ {
+ multiple_matches = true;
+ break;
+ }
+ }
+ if (multiple_matches)
+ {
+ /* We need the match with the smallest index. But we don't have
+ a fast mapping node -> index. So we have to walk the list. */
+ size_t index;
+
+ index = start_index;
+ node = list->root.next;
+ for (; start_index > 0; start_index--)
+ node = node->next;
+
+ for (;
+ index < end_index;
+ node = node->next, index++)
+ if (node->h.hashcode == hashcode
+ && (equals != NULL
+ ? equals (elt, node->value)
+ : elt == node->value))
+ return index;
+ /* The matches must have all been at indices < start_index or
+ >= end_index. */
+ return (size_t)(-1);
+ }
+ node = first_match;
+ }
+
+ /* Second step: Look up the index of the node. */
+ if (node == NULL)
+ return (size_t)(-1);
+ else
+ {
+ size_t index = 0;
+
+ for (; node->prev != &list->root; node = node->prev)
+ index++;
+
+ if (index >= start_index && index < end_index)
+ return index;
+ else
+ return (size_t)(-1);
+ }
+#else
+ gl_listelement_equals_fn equals = list->base.equals_fn;
+ size_t index = start_index;
+ gl_list_node_t node = list->root.next;
+
+ for (; start_index > 0; start_index--)
+ node = node->next;
+
+ if (equals != NULL)
+ {
+ for (;
+ index < end_index;
+ node = node->next, index++)
+ if (equals (elt, node->value))
+ return index;
+ }
+ else
+ {
+ for (;
+ index < end_index;
+ node = node->next, index++)
+ if (elt == node->value)
+ return index;
+ }
+ return (size_t)(-1);
+#endif
+ }
+}
+
+static gl_list_node_t
+gl_linked_nx_add_first (gl_list_t list, const void *elt)
+{
+ gl_list_node_t node =
+ (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
+
+ if (node == NULL)
+ return NULL;
+
+ ASYNCSAFE(const void *) node->value = elt;
+#if WITH_HASHTABLE
+ node->h.hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (node->value)
+ : (size_t)(uintptr_t) node->value);
+
+ /* Add node to the hash table. */
+ if (add_to_bucket (list, node) < 0)
+ {
+ free (node);
+ return NULL;
+ }
+#endif
+
+ /* Add node to the list. */
+ node->prev = &list->root;
+ ASYNCSAFE(gl_list_node_t) node->next = list->root.next;
+ node->next->prev = node;
+ ASYNCSAFE(gl_list_node_t) list->root.next = node;
+ list->count++;
+
+#if WITH_HASHTABLE
+ hash_resize_after_add (list);
+#endif
+
+ return node;
+}
+
+static gl_list_node_t
+gl_linked_nx_add_last (gl_list_t list, const void *elt)
+{
+ gl_list_node_t node =
+ (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
+
+ if (node == NULL)
+ return NULL;
+
+ ASYNCSAFE(const void *) node->value = elt;
+#if WITH_HASHTABLE
+ node->h.hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (node->value)
+ : (size_t)(uintptr_t) node->value);
+
+ /* Add node to the hash table. */
+ if (add_to_bucket (list, node) < 0)
+ {
+ free (node);
+ return NULL;
+ }
+#endif
+
+ /* Add node to the list. */
+ ASYNCSAFE(gl_list_node_t) node->next = &list->root;
+ node->prev = list->root.prev;
+ ASYNCSAFE(gl_list_node_t) node->prev->next = node;
+ list->root.prev = node;
+ list->count++;
+
+#if WITH_HASHTABLE
+ hash_resize_after_add (list);
+#endif
+
+ return node;
+}
+
+static gl_list_node_t
+gl_linked_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
+{
+ gl_list_node_t new_node =
+ (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
+
+ if (new_node == NULL)
+ return NULL;
+
+ ASYNCSAFE(const void *) new_node->value = elt;
+#if WITH_HASHTABLE
+ new_node->h.hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (new_node->value)
+ : (size_t)(uintptr_t) new_node->value);
+
+ /* Add new_node to the hash table. */
+ if (add_to_bucket (list, new_node) < 0)
+ {
+ free (new_node);
+ return NULL;
+ }
+#endif
+
+ /* Add new_node to the list. */
+ ASYNCSAFE(gl_list_node_t) new_node->next = node;
+ new_node->prev = node->prev;
+ ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node;
+ node->prev = new_node;
+ list->count++;
+
+#if WITH_HASHTABLE
+ hash_resize_after_add (list);
+#endif
+
+ return new_node;
+}
+
+static gl_list_node_t
+gl_linked_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
+{
+ gl_list_node_t new_node =
+ (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
+
+ if (new_node == NULL)
+ return NULL;
+
+ ASYNCSAFE(const void *) new_node->value = elt;
+#if WITH_HASHTABLE
+ new_node->h.hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (new_node->value)
+ : (size_t)(uintptr_t) new_node->value);
+
+ /* Add new_node to the hash table. */
+ if (add_to_bucket (list, new_node) < 0)
+ {
+ free (new_node);
+ return NULL;
+ }
+#endif
+
+ /* Add new_node to the list. */
+ new_node->prev = node;
+ ASYNCSAFE(gl_list_node_t) new_node->next = node->next;
+ new_node->next->prev = new_node;
+ ASYNCSAFE(gl_list_node_t) node->next = new_node;
+ list->count++;
+
+#if WITH_HASHTABLE
+ hash_resize_after_add (list);
+#endif
+
+ return new_node;
+}
+
+static gl_list_node_t
+gl_linked_nx_add_at (gl_list_t list, size_t position, const void *elt)
+{
+ size_t count = list->count;
+ gl_list_node_t new_node;
+
+ if (!(position <= count))
+ /* Invalid argument. */
+ abort ();
+
+ new_node = (struct gl_list_node_impl *) malloc (sizeof (struct gl_list_node_impl));
+ if (new_node == NULL)
+ return NULL;
+
+ ASYNCSAFE(const void *) new_node->value = elt;
+#if WITH_HASHTABLE
+ new_node->h.hashcode =
+ (list->base.hashcode_fn != NULL
+ ? list->base.hashcode_fn (new_node->value)
+ : (size_t)(uintptr_t) new_node->value);
+
+ /* Add new_node to the hash table. */
+ if (add_to_bucket (list, new_node) < 0)
+ {
+ free (new_node);
+ return NULL;
+ }
+#endif
+
+ /* Add new_node to the list. */
+ if (position <= (count / 2))
+ {
+ gl_list_node_t node;
+
+ node = &list->root;
+ for (; position > 0; position--)
+ node = node->next;
+ new_node->prev = node;
+ ASYNCSAFE(gl_list_node_t) new_node->next = node->next;
+ new_node->next->prev = new_node;
+ ASYNCSAFE(gl_list_node_t) node->next = new_node;
+ }
+ else
+ {
+ gl_list_node_t node;
+
+ position = count - position;
+ node = &list->root;
+ for (; position > 0; position--)
+ node = node->prev;
+ ASYNCSAFE(gl_list_node_t) new_node->next = node;
+ new_node->prev = node->prev;
+ ASYNCSAFE(gl_list_node_t) new_node->prev->next = new_node;
+ node->prev = new_node;
+ }
+ list->count++;
+
+#if WITH_HASHTABLE
+ hash_resize_after_add (list);
+#endif
+
+ return new_node;
+}
+
+static bool
+gl_linked_remove_node (gl_list_t list, gl_list_node_t node)
+{
+ gl_list_node_t prev;
+ gl_list_node_t next;
+
+#if WITH_HASHTABLE
+ /* Remove node from the hash table. */
+ remove_from_bucket (list, node);
+#endif
+
+ /* Remove node from the list. */
+ prev = node->prev;
+ next = node->next;
+
+ ASYNCSAFE(gl_list_node_t) prev->next = next;
+ next->prev = prev;
+ list->count--;
+
+ if (list->base.dispose_fn != NULL)
+ list->base.dispose_fn (node->value);
+ free (node);
+ return true;
+}
+
+static bool
+gl_linked_remove_at (gl_list_t list, size_t position)
+{
+ size_t count = list->count;
+ gl_list_node_t removed_node;
+
+ if (!(position < count))
+ /* Invalid argument. */
+ abort ();
+ /* Here we know count > 0. */
+ if (position <= ((count - 1) / 2))
+ {
+ gl_list_node_t node;
+ gl_list_node_t after_removed;
+
+ node = &list->root;
+ for (; position > 0; position--)
+ node = node->next;
+ removed_node = node->next;
+ after_removed = node->next->next;
+ ASYNCSAFE(gl_list_node_t) node->next = after_removed;
+ after_removed->prev = node;
+ }
+ else
+ {
+ gl_list_node_t node;
+ gl_list_node_t before_removed;
+
+ position = count - 1 - position;
+ node = &list->root;
+ for (; position > 0; position--)
+ node = node->prev;
+ removed_node = node->prev;
+ before_removed = node->prev->prev;
+ node->prev = before_removed;
+ ASYNCSAFE(gl_list_node_t) before_removed->next = node;
+ }
+#if WITH_HASHTABLE
+ remove_from_bucket (list, removed_node);
+#endif
+ list->count--;
+
+ if (list->base.dispose_fn != NULL)
+ list->base.dispose_fn (removed_node->value);
+ free (removed_node);
+ return true;
+}
+
+static bool
+gl_linked_remove (gl_list_t list, const void *elt)
+{
+ gl_list_node_t node = gl_linked_search_from_to (list, 0, list->count, elt);
+
+ if (node != NULL)
+ return gl_linked_remove_node (list, node);
+ else
+ return false;
+}
+
+static void
+gl_linked_list_free (gl_list_t list)
+{
+ gl_listelement_dispose_fn dispose = list->base.dispose_fn;
+ gl_list_node_t node;
+
+ for (node = list->root.next; node != &list->root; )
+ {
+ gl_list_node_t next = node->next;
+ if (dispose != NULL)
+ dispose (node->value);
+ free (node);
+ node = next;
+ }
+#if WITH_HASHTABLE
+ free (list->table);
+#endif
+ free (list);
+}
+
+/* --------------------- gl_list_iterator_t Data Type --------------------- */
+
+static gl_list_iterator_t
+gl_linked_iterator (gl_list_t list)
+{
+ gl_list_iterator_t result;
+
+ result.vtable = list->base.vtable;
+ result.list = list;
+ result.p = list->root.next;
+ result.q = &list->root;
+#ifdef lint
+ result.i = 0;
+ result.j = 0;
+ result.count = 0;
+#endif
+
+ return result;
+}
+
+static gl_list_iterator_t
+gl_linked_iterator_from_to (gl_list_t list,
+ size_t start_index, size_t end_index)
+{
+ gl_list_iterator_t result;
+ size_t n1, n2, n3;
+
+ if (!(start_index <= end_index && end_index <= list->count))
+ /* Invalid arguments. */
+ abort ();
+ result.vtable = list->base.vtable;
+ result.list = list;
+ n1 = start_index;
+ n2 = end_index - start_index;
+ n3 = list->count - end_index;
+ /* Find the maximum among n1, n2, n3, so as to reduce the number of
+ loop iterations to n1 + n2 + n3 - max(n1,n2,n3). */
+ if (n1 > n2 && n1 > n3)
+ {
+ /* n1 is the maximum, use n2 and n3. */
+ gl_list_node_t node;
+ size_t i;
+
+ node = &list->root;
+ for (i = n3; i > 0; i--)
+ node = node->prev;
+ result.q = node;
+ for (i = n2; i > 0; i--)
+ node = node->prev;
+ result.p = node;
+ }
+ else if (n2 > n3)
+ {
+ /* n2 is the maximum, use n1 and n3. */
+ gl_list_node_t node;
+ size_t i;
+
+ node = list->root.next;
+ for (i = n1; i > 0; i--)
+ node = node->next;
+ result.p = node;
+
+ node = &list->root;
+ for (i = n3; i > 0; i--)
+ node = node->prev;
+ result.q = node;
+ }
+ else
+ {
+ /* n3 is the maximum, use n1 and n2. */
+ gl_list_node_t node;
+ size_t i;
+
+ node = list->root.next;
+ for (i = n1; i > 0; i--)
+ node = node->next;
+ result.p = node;
+ for (i = n2; i > 0; i--)
+ node = node->next;
+ result.q = node;
+ }
+
+#ifdef lint
+ result.i = 0;
+ result.j = 0;
+ result.count = 0;
+#endif
+
+ return result;
+}
+
+static bool
+gl_linked_iterator_next (gl_list_iterator_t *iterator,
+ const void **eltp, gl_list_node_t *nodep)
+{
+ if (iterator->p != iterator->q)
+ {
+ gl_list_node_t node = (gl_list_node_t) iterator->p;
+ *eltp = node->value;
+ if (nodep != NULL)
+ *nodep = node;
+ iterator->p = node->next;
+ return true;
+ }
+ else
+ return false;
+}
+
+static void
+gl_linked_iterator_free (gl_list_iterator_t *iterator)
+{
+}
+
+/* ---------------------- Sorted gl_list_t Data Type ---------------------- */
+
+static gl_list_node_t
+gl_linked_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar,
+ const void *elt)
+{
+ gl_list_node_t node;
+
+ for (node = list->root.next; node != &list->root; node = node->next)
+ {
+ int cmp = compar (node->value, elt);
+
+ if (cmp > 0)
+ break;
+ if (cmp == 0)
+ return node;
+ }
+ return NULL;
+}
+
+static gl_list_node_t
+gl_linked_sortedlist_search_from_to (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ size_t low, size_t high,
+ const void *elt)
+{
+ size_t count = list->count;
+
+ if (!(low <= high && high <= list->count))
+ /* Invalid arguments. */
+ abort ();
+
+ high -= low;
+ if (high > 0)
+ {
+ /* Here we know low < count. */
+ size_t position = low;
+ gl_list_node_t node;
+
+ if (position <= ((count - 1) / 2))
+ {
+ node = list->root.next;
+ for (; position > 0; position--)
+ node = node->next;
+ }
+ else
+ {
+ position = count - 1 - position;
+ node = list->root.prev;
+ for (; position > 0; position--)
+ node = node->prev;
+ }
+
+ do
+ {
+ int cmp = compar (node->value, elt);
+
+ if (cmp > 0)
+ break;
+ if (cmp == 0)
+ return node;
+ node = node->next;
+ }
+ while (--high > 0);
+ }
+ return NULL;
+}
+
+static size_t
+gl_linked_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar,
+ const void *elt)
+{
+ gl_list_node_t node;
+ size_t index;
+
+ for (node = list->root.next, index = 0;
+ node != &list->root;
+ node = node->next, index++)
+ {
+ int cmp = compar (node->value, elt);
+
+ if (cmp > 0)
+ break;
+ if (cmp == 0)
+ return index;
+ }
+ return (size_t)(-1);
+}
+
+static size_t
+gl_linked_sortedlist_indexof_from_to (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ size_t low, size_t high,
+ const void *elt)
+{
+ size_t count = list->count;
+
+ if (!(low <= high && high <= list->count))
+ /* Invalid arguments. */
+ abort ();
+
+ high -= low;
+ if (high > 0)
+ {
+ /* Here we know low < count. */
+ size_t index = low;
+ size_t position = low;
+ gl_list_node_t node;
+
+ if (position <= ((count - 1) / 2))
+ {
+ node = list->root.next;
+ for (; position > 0; position--)
+ node = node->next;
+ }
+ else
+ {
+ position = count - 1 - position;
+ node = list->root.prev;
+ for (; position > 0; position--)
+ node = node->prev;
+ }
+
+ do
+ {
+ int cmp = compar (node->value, elt);
+
+ if (cmp > 0)
+ break;
+ if (cmp == 0)
+ return index;
+ node = node->next;
+ index++;
+ }
+ while (--high > 0);
+ }
+ return (size_t)(-1);
+}
+
+static gl_list_node_t
+gl_linked_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar,
+ const void *elt)
+{
+ gl_list_node_t node;
+
+ for (node = list->root.next; node != &list->root; node = node->next)
+ if (compar (node->value, elt) >= 0)
+ return gl_linked_nx_add_before (list, node, elt);
+ return gl_linked_nx_add_last (list, elt);
+}
+
+static bool
+gl_linked_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar,
+ const void *elt)
+{
+ gl_list_node_t node;
+
+ for (node = list->root.next; node != &list->root; node = node->next)
+ {
+ int cmp = compar (node->value, elt);
+
+ if (cmp > 0)
+ break;
+ if (cmp == 0)
+ return gl_linked_remove_node (list, node);
+ }
+ return false;
+}
diff --git a/contrib/tools/bison/gnulib/src/gl_anytree_oset.h b/contrib/tools/bison/gnulib/src/gl_anytree_oset.h
index e1f90a99a2..738115c640 100644
--- a/contrib/tools/bison/gnulib/src/gl_anytree_oset.h
+++ b/contrib/tools/bison/gnulib/src/gl_anytree_oset.h
@@ -1,297 +1,297 @@
-/* Ordered set data type implemented by a binary tree.
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Common code of gl_avltree_oset.c and gl_rbtree_oset.c. */
-
-/* An item on the stack used for iterating across the elements. */
-typedef struct
-{
- gl_oset_node_t node;
- bool rightp;
-} iterstack_item_t;
-
-/* A stack used for iterating across the elements. */
-typedef iterstack_item_t iterstack_t[MAXHEIGHT];
-
-static gl_oset_t
-gl_tree_nx_create_empty (gl_oset_implementation_t implementation,
- gl_setelement_compar_fn compar_fn,
- gl_setelement_dispose_fn dispose_fn)
-{
- struct gl_oset_impl *set =
- (struct gl_oset_impl *) malloc (sizeof (struct gl_oset_impl));
-
- if (set == NULL)
- return NULL;
-
- set->base.vtable = implementation;
- set->base.compar_fn = compar_fn;
- set->base.dispose_fn = dispose_fn;
- set->root = NULL;
- set->count = 0;
-
- return set;
-}
-
-static size_t
-gl_tree_size (gl_oset_t set)
-{
- return set->count;
-}
-
-static bool
-gl_tree_search (gl_oset_t set, const void *elt)
-{
- gl_setelement_compar_fn compar = set->base.compar_fn;
- gl_oset_node_t node;
-
- for (node = set->root; node != NULL; )
- {
- int cmp = (compar != NULL
- ? compar (node->value, elt)
- : (node->value > elt ? 1 :
- node->value < elt ? -1 : 0));
-
- if (cmp < 0)
- node = node->right;
- else if (cmp > 0)
- node = node->left;
- else /* cmp == 0 */
- /* We have an element equal to ELT. */
- return true;
- }
- return false;
-}
-
-static bool
-gl_tree_search_atleast (gl_oset_t set,
- gl_setelement_threshold_fn threshold_fn,
- const void *threshold,
- const void **eltp)
-{
- gl_oset_node_t node;
-
- for (node = set->root; node != NULL; )
- {
- if (! threshold_fn (node->value, threshold))
- node = node->right;
- else
- {
- /* We have an element >= VALUE. But we need the leftmost such
- element. */
- gl_oset_node_t found = node;
- node = node->left;
- for (; node != NULL; )
- {
- if (! threshold_fn (node->value, threshold))
- node = node->right;
- else
- {
- found = node;
- node = node->left;
- }
- }
- *eltp = found->value;
- return true;
- }
- }
- return false;
-}
-
-static gl_oset_node_t
-gl_tree_search_node (gl_oset_t set, const void *elt)
-{
- gl_setelement_compar_fn compar = set->base.compar_fn;
- gl_oset_node_t node;
-
- for (node = set->root; node != NULL; )
- {
- int cmp = (compar != NULL
- ? compar (node->value, elt)
- : (node->value > elt ? 1 :
- node->value < elt ? -1 : 0));
-
- if (cmp < 0)
- node = node->right;
- else if (cmp > 0)
- node = node->left;
- else /* cmp == 0 */
- /* We have an element equal to ELT. */
- return node;
- }
- return NULL;
-}
-
-static int
-gl_tree_nx_add (gl_oset_t set, const void *elt)
-{
- gl_setelement_compar_fn compar;
- gl_oset_node_t node = set->root;
-
- if (node == NULL)
- {
- if (gl_tree_nx_add_first (set, elt) == NULL)
- return -1;
- return true;
- }
-
- compar = set->base.compar_fn;
-
- for (;;)
- {
- int cmp = (compar != NULL
- ? compar (node->value, elt)
- : (node->value > elt ? 1 :
- node->value < elt ? -1 : 0));
-
- if (cmp < 0)
- {
- if (node->right == NULL)
- {
- if (gl_tree_nx_add_after (set, node, elt) == NULL)
- return -1;
- return true;
- }
- node = node->right;
- }
- else if (cmp > 0)
- {
- if (node->left == NULL)
- {
- if (gl_tree_nx_add_before (set, node, elt) == NULL)
- return -1;
- return true;
- }
- node = node->left;
- }
- else /* cmp == 0 */
- return false;
- }
-}
-
-static bool
-gl_tree_remove (gl_oset_t set, const void *elt)
-{
- gl_oset_node_t node = gl_tree_search_node (set, elt);
-
- if (node != NULL)
- return gl_tree_remove_node (set, node);
- else
- return false;
-}
-
-static void
-gl_tree_oset_free (gl_oset_t set)
-{
- /* Iterate across all elements in post-order. */
- gl_oset_node_t node = set->root;
- iterstack_t stack;
- iterstack_item_t *stack_ptr = &stack[0];
-
- for (;;)
- {
- /* Descend on left branch. */
- for (;;)
- {
- if (node == NULL)
- break;
- stack_ptr->node = node;
- stack_ptr->rightp = false;
- node = node->left;
- stack_ptr++;
- }
- /* Climb up again. */
- for (;;)
- {
- if (stack_ptr == &stack[0])
- goto done_iterate;
- stack_ptr--;
- node = stack_ptr->node;
- if (!stack_ptr->rightp)
- break;
- /* Free the current node. */
- if (set->base.dispose_fn != NULL)
- set->base.dispose_fn (node->value);
- free (node);
- }
- /* Descend on right branch. */
- stack_ptr->rightp = true;
- node = node->right;
- stack_ptr++;
- }
- done_iterate:
- free (set);
-}
-
-/* --------------------- gl_oset_iterator_t Data Type --------------------- */
-
-static gl_oset_iterator_t
-gl_tree_iterator (gl_oset_t set)
-{
- gl_oset_iterator_t result;
- gl_oset_node_t node;
-
- result.vtable = set->base.vtable;
- result.set = set;
- /* Start node is the leftmost node. */
- node = set->root;
- if (node != NULL)
- while (node->left != NULL)
- node = node->left;
- result.p = node;
- /* End point is past the rightmost node. */
- result.q = NULL;
-#ifdef lint
- result.i = 0;
- result.j = 0;
- result.count = 0;
-#endif
-
- return result;
-}
-
-static bool
-gl_tree_iterator_next (gl_oset_iterator_t *iterator, const void **eltp)
-{
- if (iterator->p != iterator->q)
- {
- gl_oset_node_t node = (gl_oset_node_t) iterator->p;
- *eltp = node->value;
- /* Advance to the next node. */
- if (node->right != NULL)
- {
- node = node->right;
- while (node->left != NULL)
- node = node->left;
- }
- else
- {
- while (node->parent != NULL && node->parent->right == node)
- node = node->parent;
- node = node->parent;
- }
- iterator->p = node;
- return true;
- }
- else
- return false;
-}
-
-static void
-gl_tree_iterator_free (gl_oset_iterator_t *iterator)
-{
-}
+/* Ordered set data type implemented by a binary tree.
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Common code of gl_avltree_oset.c and gl_rbtree_oset.c. */
+
+/* An item on the stack used for iterating across the elements. */
+typedef struct
+{
+ gl_oset_node_t node;
+ bool rightp;
+} iterstack_item_t;
+
+/* A stack used for iterating across the elements. */
+typedef iterstack_item_t iterstack_t[MAXHEIGHT];
+
+static gl_oset_t
+gl_tree_nx_create_empty (gl_oset_implementation_t implementation,
+ gl_setelement_compar_fn compar_fn,
+ gl_setelement_dispose_fn dispose_fn)
+{
+ struct gl_oset_impl *set =
+ (struct gl_oset_impl *) malloc (sizeof (struct gl_oset_impl));
+
+ if (set == NULL)
+ return NULL;
+
+ set->base.vtable = implementation;
+ set->base.compar_fn = compar_fn;
+ set->base.dispose_fn = dispose_fn;
+ set->root = NULL;
+ set->count = 0;
+
+ return set;
+}
+
+static size_t
+gl_tree_size (gl_oset_t set)
+{
+ return set->count;
+}
+
+static bool
+gl_tree_search (gl_oset_t set, const void *elt)
+{
+ gl_setelement_compar_fn compar = set->base.compar_fn;
+ gl_oset_node_t node;
+
+ for (node = set->root; node != NULL; )
+ {
+ int cmp = (compar != NULL
+ ? compar (node->value, elt)
+ : (node->value > elt ? 1 :
+ node->value < elt ? -1 : 0));
+
+ if (cmp < 0)
+ node = node->right;
+ else if (cmp > 0)
+ node = node->left;
+ else /* cmp == 0 */
+ /* We have an element equal to ELT. */
+ return true;
+ }
+ return false;
+}
+
+static bool
+gl_tree_search_atleast (gl_oset_t set,
+ gl_setelement_threshold_fn threshold_fn,
+ const void *threshold,
+ const void **eltp)
+{
+ gl_oset_node_t node;
+
+ for (node = set->root; node != NULL; )
+ {
+ if (! threshold_fn (node->value, threshold))
+ node = node->right;
+ else
+ {
+ /* We have an element >= VALUE. But we need the leftmost such
+ element. */
+ gl_oset_node_t found = node;
+ node = node->left;
+ for (; node != NULL; )
+ {
+ if (! threshold_fn (node->value, threshold))
+ node = node->right;
+ else
+ {
+ found = node;
+ node = node->left;
+ }
+ }
+ *eltp = found->value;
+ return true;
+ }
+ }
+ return false;
+}
+
+static gl_oset_node_t
+gl_tree_search_node (gl_oset_t set, const void *elt)
+{
+ gl_setelement_compar_fn compar = set->base.compar_fn;
+ gl_oset_node_t node;
+
+ for (node = set->root; node != NULL; )
+ {
+ int cmp = (compar != NULL
+ ? compar (node->value, elt)
+ : (node->value > elt ? 1 :
+ node->value < elt ? -1 : 0));
+
+ if (cmp < 0)
+ node = node->right;
+ else if (cmp > 0)
+ node = node->left;
+ else /* cmp == 0 */
+ /* We have an element equal to ELT. */
+ return node;
+ }
+ return NULL;
+}
+
+static int
+gl_tree_nx_add (gl_oset_t set, const void *elt)
+{
+ gl_setelement_compar_fn compar;
+ gl_oset_node_t node = set->root;
+
+ if (node == NULL)
+ {
+ if (gl_tree_nx_add_first (set, elt) == NULL)
+ return -1;
+ return true;
+ }
+
+ compar = set->base.compar_fn;
+
+ for (;;)
+ {
+ int cmp = (compar != NULL
+ ? compar (node->value, elt)
+ : (node->value > elt ? 1 :
+ node->value < elt ? -1 : 0));
+
+ if (cmp < 0)
+ {
+ if (node->right == NULL)
+ {
+ if (gl_tree_nx_add_after (set, node, elt) == NULL)
+ return -1;
+ return true;
+ }
+ node = node->right;
+ }
+ else if (cmp > 0)
+ {
+ if (node->left == NULL)
+ {
+ if (gl_tree_nx_add_before (set, node, elt) == NULL)
+ return -1;
+ return true;
+ }
+ node = node->left;
+ }
+ else /* cmp == 0 */
+ return false;
+ }
+}
+
+static bool
+gl_tree_remove (gl_oset_t set, const void *elt)
+{
+ gl_oset_node_t node = gl_tree_search_node (set, elt);
+
+ if (node != NULL)
+ return gl_tree_remove_node (set, node);
+ else
+ return false;
+}
+
+static void
+gl_tree_oset_free (gl_oset_t set)
+{
+ /* Iterate across all elements in post-order. */
+ gl_oset_node_t node = set->root;
+ iterstack_t stack;
+ iterstack_item_t *stack_ptr = &stack[0];
+
+ for (;;)
+ {
+ /* Descend on left branch. */
+ for (;;)
+ {
+ if (node == NULL)
+ break;
+ stack_ptr->node = node;
+ stack_ptr->rightp = false;
+ node = node->left;
+ stack_ptr++;
+ }
+ /* Climb up again. */
+ for (;;)
+ {
+ if (stack_ptr == &stack[0])
+ goto done_iterate;
+ stack_ptr--;
+ node = stack_ptr->node;
+ if (!stack_ptr->rightp)
+ break;
+ /* Free the current node. */
+ if (set->base.dispose_fn != NULL)
+ set->base.dispose_fn (node->value);
+ free (node);
+ }
+ /* Descend on right branch. */
+ stack_ptr->rightp = true;
+ node = node->right;
+ stack_ptr++;
+ }
+ done_iterate:
+ free (set);
+}
+
+/* --------------------- gl_oset_iterator_t Data Type --------------------- */
+
+static gl_oset_iterator_t
+gl_tree_iterator (gl_oset_t set)
+{
+ gl_oset_iterator_t result;
+ gl_oset_node_t node;
+
+ result.vtable = set->base.vtable;
+ result.set = set;
+ /* Start node is the leftmost node. */
+ node = set->root;
+ if (node != NULL)
+ while (node->left != NULL)
+ node = node->left;
+ result.p = node;
+ /* End point is past the rightmost node. */
+ result.q = NULL;
+#ifdef lint
+ result.i = 0;
+ result.j = 0;
+ result.count = 0;
+#endif
+
+ return result;
+}
+
+static bool
+gl_tree_iterator_next (gl_oset_iterator_t *iterator, const void **eltp)
+{
+ if (iterator->p != iterator->q)
+ {
+ gl_oset_node_t node = (gl_oset_node_t) iterator->p;
+ *eltp = node->value;
+ /* Advance to the next node. */
+ if (node->right != NULL)
+ {
+ node = node->right;
+ while (node->left != NULL)
+ node = node->left;
+ }
+ else
+ {
+ while (node->parent != NULL && node->parent->right == node)
+ node = node->parent;
+ node = node->parent;
+ }
+ iterator->p = node;
+ return true;
+ }
+ else
+ return false;
+}
+
+static void
+gl_tree_iterator_free (gl_oset_iterator_t *iterator)
+{
+}
diff --git a/contrib/tools/bison/gnulib/src/gl_avltree_oset.c b/contrib/tools/bison/gnulib/src/gl_avltree_oset.c
index 09202ae0cc..75b3743a17 100644
--- a/contrib/tools/bison/gnulib/src/gl_avltree_oset.c
+++ b/contrib/tools/bison/gnulib/src/gl_avltree_oset.c
@@ -1,583 +1,583 @@
-/* Ordered set data type implemented by a binary tree.
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "gl_avltree_oset.h"
-
-#include <stdlib.h>
-
-/* An AVL tree is a binary tree where
- 1. The height of each node is calculated as
- heightof(node) = 1 + max (heightof(node.left), heightof(node.right)).
- 2. The heights of the subtrees of each node differ by at most 1:
- | heightof(right) - heightof(left) | <= 1.
- 3. The index of the elements in the node.left subtree are smaller than
- the index of node.
- The index of the elements in the node.right subtree are larger than
- the index of node.
- */
-
-/* -------------------------- gl_oset_t Data Type -------------------------- */
-
-/* Tree node implementation, valid for this file only. */
-struct gl_oset_node_impl
-{
- struct gl_oset_node_impl *left; /* left branch, or NULL */
- struct gl_oset_node_impl *right; /* right branch, or NULL */
- /* Parent pointer, or NULL. The parent pointer is not needed for most
- operations. It is needed so that a gl_oset_node_t can be returned
- without memory allocation, on which the functions gl_oset_remove_node,
- gl_oset_add_before, gl_oset_add_after can be implemented. */
- struct gl_oset_node_impl *parent;
- int balance; /* heightof(right) - heightof(left),
- always = -1 or 0 or 1 */
- const void *value;
-};
-typedef struct gl_oset_node_impl * gl_oset_node_t;
-
-/* Concrete gl_oset_impl type, valid for this file only. */
-struct gl_oset_impl
-{
- struct gl_oset_impl_base base;
- struct gl_oset_node_impl *root; /* root node or NULL */
- size_t count; /* number of nodes */
-};
-
-/* An AVL tree of height h has at least F_(h+2) [Fibonacci number] and at most
- 2^h - 1 elements. So, h <= 84 (because a tree of height h >= 85 would have
- at least F_87 elements, and because even on 64-bit machines,
- sizeof (gl_oset_node_impl) * F_87 > 2^64
- this would exceed the address space of the machine. */
-#define MAXHEIGHT 83
-
-/* Ensure the tree is balanced, after an insertion or deletion operation.
- The height of NODE is incremented by HEIGHT_DIFF (1 or -1).
- PARENT = NODE->parent. (NODE can also be NULL. But PARENT is non-NULL.)
- Rotation operations are performed starting at PARENT (not NODE itself!). */
-static void
-rebalance (gl_oset_t set,
- gl_oset_node_t node, int height_diff, gl_oset_node_t parent)
-{
- for (;;)
- {
- gl_oset_node_t child;
- int previous_balance;
- int balance_diff;
- gl_oset_node_t nodeleft;
- gl_oset_node_t noderight;
-
- child = node;
- node = parent;
-
- previous_balance = node->balance;
-
- /* The balance of NODE is incremented by BALANCE_DIFF: +1 if the right
- branch's height has increased by 1 or the left branch's height has
- decreased by 1, -1 if the right branch's height has decreased by 1 or
- the left branch's height has increased by 1, 0 if no height change. */
- if (node->left != NULL || node->right != NULL)
- balance_diff = (child == node->right ? height_diff : -height_diff);
- else
- /* Special case where above formula doesn't work, because the caller
- didn't tell whether node's left or right branch shrunk from height 1
- to NULL. */
- balance_diff = - previous_balance;
-
- node->balance += balance_diff;
- if (balance_diff == previous_balance)
- {
- /* node->balance is outside the range [-1,1]. Must rotate. */
- gl_oset_node_t *nodep;
-
- if (node->parent == NULL)
- /* node == set->root */
- nodep = &set->root;
- else if (node->parent->left == node)
- nodep = &node->parent->left;
- else if (node->parent->right == node)
- nodep = &node->parent->right;
- else
- abort ();
-
- nodeleft = node->left;
- noderight = node->right;
-
- if (balance_diff < 0)
- {
- /* node->balance = -2. The subtree is heavier on the left side.
- Rotate from left to right:
-
- *
- / \
- h+2 h
- */
- gl_oset_node_t nodeleftright = nodeleft->right;
- if (nodeleft->balance <= 0)
- {
- /*
- * h+2|h+3
- / \ / \
- h+2 h --> / h+1|h+2
- / \ | / \
- h+1 h|h+1 h+1 h|h+1 h
- */
- node->left = nodeleftright;
- nodeleft->right = node;
-
- nodeleft->parent = node->parent;
- node->parent = nodeleft;
- if (nodeleftright != NULL)
- nodeleftright->parent = node;
-
- nodeleft->balance += 1;
- node->balance = - nodeleft->balance;
-
- *nodep = nodeleft;
- height_diff = (height_diff < 0
- ? /* noderight's height had been decremented from
- h+1 to h. The subtree's height changes from
- h+3 to h+2|h+3. */
- nodeleft->balance - 1
- : /* nodeleft's height had been incremented from
- h+1 to h+2. The subtree's height changes from
- h+2 to h+2|h+3. */
- nodeleft->balance);
- }
- else
- {
- /*
- * h+2
- / \ / \
- h+2 h --> h+1 h+1
- / \ / \ / \
- h h+1 h L R h
- / \
- L R
-
- */
- gl_oset_node_t L = nodeleft->right = nodeleftright->left;
- gl_oset_node_t R = node->left = nodeleftright->right;
- nodeleftright->left = nodeleft;
- nodeleftright->right = node;
-
- nodeleftright->parent = node->parent;
- if (L != NULL)
- L->parent = nodeleft;
- if (R != NULL)
- R->parent = node;
- nodeleft->parent = nodeleftright;
- node->parent = nodeleftright;
-
- nodeleft->balance = (nodeleftright->balance > 0 ? -1 : 0);
- node->balance = (nodeleftright->balance < 0 ? 1 : 0);
- nodeleftright->balance = 0;
-
- *nodep = nodeleftright;
- height_diff = (height_diff < 0
- ? /* noderight's height had been decremented from
- h+1 to h. The subtree's height changes from
- h+3 to h+2. */
- -1
- : /* nodeleft's height had been incremented from
- h+1 to h+2. The subtree's height changes from
- h+2 to h+2. */
- 0);
- }
- }
- else
- {
- /* node->balance = 2. The subtree is heavier on the right side.
- Rotate from right to left:
-
- *
- / \
- h h+2
- */
- gl_oset_node_t noderightleft = noderight->left;
- if (noderight->balance >= 0)
- {
- /*
- * h+2|h+3
- / \ / \
- h h+2 --> h+1|h+2 \
- / \ / \ |
- h|h+1 h+1 h h|h+1 h+1
- */
- node->right = noderightleft;
- noderight->left = node;
-
- noderight->parent = node->parent;
- node->parent = noderight;
- if (noderightleft != NULL)
- noderightleft->parent = node;
-
- noderight->balance -= 1;
- node->balance = - noderight->balance;
-
- *nodep = noderight;
- height_diff = (height_diff < 0
- ? /* nodeleft's height had been decremented from
- h+1 to h. The subtree's height changes from
- h+3 to h+2|h+3. */
- - noderight->balance - 1
- : /* noderight's height had been incremented from
- h+1 to h+2. The subtree's height changes from
- h+2 to h+2|h+3. */
- - noderight->balance);
- }
- else
- {
- /*
- * h+2
- / \ / \
- h h+2 --> h+1 h+1
- / \ / \ / \
- h+1 h h L R h
- / \
- L R
-
- */
- gl_oset_node_t L = node->right = noderightleft->left;
- gl_oset_node_t R = noderight->left = noderightleft->right;
- noderightleft->left = node;
- noderightleft->right = noderight;
-
- noderightleft->parent = node->parent;
- if (L != NULL)
- L->parent = node;
- if (R != NULL)
- R->parent = noderight;
- node->parent = noderightleft;
- noderight->parent = noderightleft;
-
- node->balance = (noderightleft->balance > 0 ? -1 : 0);
- noderight->balance = (noderightleft->balance < 0 ? 1 : 0);
- noderightleft->balance = 0;
-
- *nodep = noderightleft;
- height_diff = (height_diff < 0
- ? /* nodeleft's height had been decremented from
- h+1 to h. The subtree's height changes from
- h+3 to h+2. */
- -1
- : /* noderight's height had been incremented from
- h+1 to h+2. The subtree's height changes from
- h+2 to h+2. */
- 0);
- }
- }
- node = *nodep;
- }
- else
- {
- /* No rotation needed. Only propagation of the height change to the
- next higher level. */
- if (height_diff < 0)
- height_diff = (previous_balance == 0 ? 0 : -1);
- else
- height_diff = (node->balance == 0 ? 0 : 1);
- }
-
- if (height_diff == 0)
- break;
-
- parent = node->parent;
- if (parent == NULL)
- break;
- }
-}
-
-static gl_oset_node_t
-gl_tree_nx_add_first (gl_oset_t set, const void *elt)
-{
- /* Create new node. */
- gl_oset_node_t new_node =
- (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
-
- if (new_node == NULL)
- return NULL;
-
- new_node->left = NULL;
- new_node->right = NULL;
- new_node->balance = 0;
- new_node->value = elt;
-
- /* Add it to the tree. */
- if (set->root == NULL)
- {
- set->root = new_node;
- new_node->parent = NULL;
- }
- else
- {
- gl_oset_node_t node;
-
- for (node = set->root; node->left != NULL; )
- node = node->left;
-
- node->left = new_node;
- new_node->parent = node;
- node->balance--;
-
- /* Rebalance. */
- if (node->right == NULL && node->parent != NULL)
- rebalance (set, node, 1, node->parent);
- }
-
- set->count++;
- return new_node;
-}
-
-static gl_oset_node_t
-gl_tree_nx_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt)
-{
- /* Create new node. */
- gl_oset_node_t new_node =
- (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
- bool height_inc;
-
- if (new_node == NULL)
- return NULL;
-
- new_node->left = NULL;
- new_node->right = NULL;
- new_node->balance = 0;
- new_node->value = elt;
-
- /* Add it to the tree. */
- if (node->left == NULL)
- {
- node->left = new_node;
- node->balance--;
- height_inc = (node->right == NULL);
- }
- else
- {
- for (node = node->left; node->right != NULL; )
- node = node->right;
- node->right = new_node;
- node->balance++;
- height_inc = (node->left == NULL);
- }
- new_node->parent = node;
-
- /* Rebalance. */
- if (height_inc && node->parent != NULL)
- rebalance (set, node, 1, node->parent);
-
- set->count++;
- return new_node;
-}
-
-static gl_oset_node_t
-gl_tree_nx_add_after (gl_oset_t set, gl_oset_node_t node, const void *elt)
-{
- /* Create new node. */
- gl_oset_node_t new_node =
- (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
- bool height_inc;
-
- if (new_node == NULL)
- return NULL;
-
- new_node->left = NULL;
- new_node->right = NULL;
- new_node->balance = 0;
- new_node->value = elt;
-
- /* Add it to the tree. */
- if (node->right == NULL)
- {
- node->right = new_node;
- node->balance++;
- height_inc = (node->left == NULL);
- }
- else
- {
- for (node = node->right; node->left != NULL; )
- node = node->left;
- node->left = new_node;
- node->balance--;
- height_inc = (node->right == NULL);
- }
- new_node->parent = node;
-
- /* Rebalance. */
- if (height_inc && node->parent != NULL)
- rebalance (set, node, 1, node->parent);
-
- set->count++;
- return new_node;
-}
-
-static bool
-gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node)
-{
- gl_oset_node_t parent = node->parent;
-
- if (node->left == NULL)
- {
- /* Replace node with node->right. */
- gl_oset_node_t child = node->right;
-
- if (child != NULL)
- child->parent = parent;
- if (parent == NULL)
- set->root = child;
- else
- {
- if (parent->left == node)
- parent->left = child;
- else /* parent->right == node */
- parent->right = child;
-
- rebalance (set, child, -1, parent);
- }
- }
- else if (node->right == NULL)
- {
- /* It is not absolutely necessary to treat this case. But the more
- general case below is more complicated, hence slower. */
- /* Replace node with node->left. */
- gl_oset_node_t child = node->left;
-
- child->parent = parent;
- if (parent == NULL)
- set->root = child;
- else
- {
- if (parent->left == node)
- parent->left = child;
- else /* parent->right == node */
- parent->right = child;
-
- rebalance (set, child, -1, parent);
- }
- }
- else
- {
- /* Replace node with the rightmost element of the node->left subtree. */
- gl_oset_node_t subst;
- gl_oset_node_t subst_parent;
- gl_oset_node_t child;
-
- for (subst = node->left; subst->right != NULL; )
- subst = subst->right;
-
- subst_parent = subst->parent;
-
- child = subst->left;
-
- /* The case subst_parent == node is special: If we do nothing special,
- we get confusion about node->left, subst->left and child->parent.
- subst_parent == node
- <==> The 'for' loop above terminated immediately.
- <==> subst == subst_parent->left
- [otherwise subst == subst_parent->right]
- In this case, we would need to first set
- child->parent = node; node->left = child;
- and later - when we copy subst into node's position - again
- child->parent = subst; subst->left = child;
- Altogether a no-op. */
- if (subst_parent != node)
- {
- if (child != NULL)
- child->parent = subst_parent;
- subst_parent->right = child;
- }
-
- /* Copy subst into node's position.
- (This is safer than to copy subst's value into node, keep node in
- place, and free subst.) */
- if (subst_parent != node)
- {
- subst->left = node->left;
- subst->left->parent = subst;
- }
- subst->right = node->right;
- subst->right->parent = subst;
- subst->balance = node->balance;
- subst->parent = parent;
- if (parent == NULL)
- set->root = subst;
- else if (parent->left == node)
- parent->left = subst;
- else /* parent->right == node */
- parent->right = subst;
-
- /* Rebalancing starts at child's parent, that is subst_parent -
- except when subst_parent == node. In this case, we need to use
- its replacement, subst. */
- rebalance (set, child, -1, subst_parent != node ? subst_parent : subst);
- }
-
- set->count--;
- if (set->base.dispose_fn != NULL)
- set->base.dispose_fn (node->value);
- free (node);
- return true;
-}
-
-/* Generic binary tree code. */
-#include "gl_anytree_oset.h"
-
-/* For debugging. */
-static unsigned int
-check_invariants (gl_oset_node_t node, gl_oset_node_t parent, size_t *counterp)
-{
- unsigned int left_height =
- (node->left != NULL ? check_invariants (node->left, node, counterp) : 0);
- unsigned int right_height =
- (node->right != NULL ? check_invariants (node->right, node, counterp) : 0);
- int balance = (int)right_height - (int)left_height;
-
- if (!(node->parent == parent))
- abort ();
- if (!(balance >= -1 && balance <= 1))
- abort ();
- if (!(node->balance == balance))
- abort ();
-
- (*counterp)++;
-
- return 1 + (left_height > right_height ? left_height : right_height);
-}
-void
-gl_avltree_oset_check_invariants (gl_oset_t set)
-{
- size_t counter = 0;
- if (set->root != NULL)
- check_invariants (set->root, NULL, &counter);
- if (!(set->count == counter))
- abort ();
-}
-
-const struct gl_oset_implementation gl_avltree_oset_implementation =
- {
- gl_tree_nx_create_empty,
- gl_tree_size,
- gl_tree_search,
- gl_tree_search_atleast,
- gl_tree_nx_add,
- gl_tree_remove,
- gl_tree_oset_free,
- gl_tree_iterator,
- gl_tree_iterator_next,
- gl_tree_iterator_free
- };
+/* Ordered set data type implemented by a binary tree.
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "gl_avltree_oset.h"
+
+#include <stdlib.h>
+
+/* An AVL tree is a binary tree where
+ 1. The height of each node is calculated as
+ heightof(node) = 1 + max (heightof(node.left), heightof(node.right)).
+ 2. The heights of the subtrees of each node differ by at most 1:
+ | heightof(right) - heightof(left) | <= 1.
+ 3. The index of the elements in the node.left subtree are smaller than
+ the index of node.
+ The index of the elements in the node.right subtree are larger than
+ the index of node.
+ */
+
+/* -------------------------- gl_oset_t Data Type -------------------------- */
+
+/* Tree node implementation, valid for this file only. */
+struct gl_oset_node_impl
+{
+ struct gl_oset_node_impl *left; /* left branch, or NULL */
+ struct gl_oset_node_impl *right; /* right branch, or NULL */
+ /* Parent pointer, or NULL. The parent pointer is not needed for most
+ operations. It is needed so that a gl_oset_node_t can be returned
+ without memory allocation, on which the functions gl_oset_remove_node,
+ gl_oset_add_before, gl_oset_add_after can be implemented. */
+ struct gl_oset_node_impl *parent;
+ int balance; /* heightof(right) - heightof(left),
+ always = -1 or 0 or 1 */
+ const void *value;
+};
+typedef struct gl_oset_node_impl * gl_oset_node_t;
+
+/* Concrete gl_oset_impl type, valid for this file only. */
+struct gl_oset_impl
+{
+ struct gl_oset_impl_base base;
+ struct gl_oset_node_impl *root; /* root node or NULL */
+ size_t count; /* number of nodes */
+};
+
+/* An AVL tree of height h has at least F_(h+2) [Fibonacci number] and at most
+ 2^h - 1 elements. So, h <= 84 (because a tree of height h >= 85 would have
+ at least F_87 elements, and because even on 64-bit machines,
+ sizeof (gl_oset_node_impl) * F_87 > 2^64
+ this would exceed the address space of the machine. */
+#define MAXHEIGHT 83
+
+/* Ensure the tree is balanced, after an insertion or deletion operation.
+ The height of NODE is incremented by HEIGHT_DIFF (1 or -1).
+ PARENT = NODE->parent. (NODE can also be NULL. But PARENT is non-NULL.)
+ Rotation operations are performed starting at PARENT (not NODE itself!). */
+static void
+rebalance (gl_oset_t set,
+ gl_oset_node_t node, int height_diff, gl_oset_node_t parent)
+{
+ for (;;)
+ {
+ gl_oset_node_t child;
+ int previous_balance;
+ int balance_diff;
+ gl_oset_node_t nodeleft;
+ gl_oset_node_t noderight;
+
+ child = node;
+ node = parent;
+
+ previous_balance = node->balance;
+
+ /* The balance of NODE is incremented by BALANCE_DIFF: +1 if the right
+ branch's height has increased by 1 or the left branch's height has
+ decreased by 1, -1 if the right branch's height has decreased by 1 or
+ the left branch's height has increased by 1, 0 if no height change. */
+ if (node->left != NULL || node->right != NULL)
+ balance_diff = (child == node->right ? height_diff : -height_diff);
+ else
+ /* Special case where above formula doesn't work, because the caller
+ didn't tell whether node's left or right branch shrunk from height 1
+ to NULL. */
+ balance_diff = - previous_balance;
+
+ node->balance += balance_diff;
+ if (balance_diff == previous_balance)
+ {
+ /* node->balance is outside the range [-1,1]. Must rotate. */
+ gl_oset_node_t *nodep;
+
+ if (node->parent == NULL)
+ /* node == set->root */
+ nodep = &set->root;
+ else if (node->parent->left == node)
+ nodep = &node->parent->left;
+ else if (node->parent->right == node)
+ nodep = &node->parent->right;
+ else
+ abort ();
+
+ nodeleft = node->left;
+ noderight = node->right;
+
+ if (balance_diff < 0)
+ {
+ /* node->balance = -2. The subtree is heavier on the left side.
+ Rotate from left to right:
+
+ *
+ / \
+ h+2 h
+ */
+ gl_oset_node_t nodeleftright = nodeleft->right;
+ if (nodeleft->balance <= 0)
+ {
+ /*
+ * h+2|h+3
+ / \ / \
+ h+2 h --> / h+1|h+2
+ / \ | / \
+ h+1 h|h+1 h+1 h|h+1 h
+ */
+ node->left = nodeleftright;
+ nodeleft->right = node;
+
+ nodeleft->parent = node->parent;
+ node->parent = nodeleft;
+ if (nodeleftright != NULL)
+ nodeleftright->parent = node;
+
+ nodeleft->balance += 1;
+ node->balance = - nodeleft->balance;
+
+ *nodep = nodeleft;
+ height_diff = (height_diff < 0
+ ? /* noderight's height had been decremented from
+ h+1 to h. The subtree's height changes from
+ h+3 to h+2|h+3. */
+ nodeleft->balance - 1
+ : /* nodeleft's height had been incremented from
+ h+1 to h+2. The subtree's height changes from
+ h+2 to h+2|h+3. */
+ nodeleft->balance);
+ }
+ else
+ {
+ /*
+ * h+2
+ / \ / \
+ h+2 h --> h+1 h+1
+ / \ / \ / \
+ h h+1 h L R h
+ / \
+ L R
+
+ */
+ gl_oset_node_t L = nodeleft->right = nodeleftright->left;
+ gl_oset_node_t R = node->left = nodeleftright->right;
+ nodeleftright->left = nodeleft;
+ nodeleftright->right = node;
+
+ nodeleftright->parent = node->parent;
+ if (L != NULL)
+ L->parent = nodeleft;
+ if (R != NULL)
+ R->parent = node;
+ nodeleft->parent = nodeleftright;
+ node->parent = nodeleftright;
+
+ nodeleft->balance = (nodeleftright->balance > 0 ? -1 : 0);
+ node->balance = (nodeleftright->balance < 0 ? 1 : 0);
+ nodeleftright->balance = 0;
+
+ *nodep = nodeleftright;
+ height_diff = (height_diff < 0
+ ? /* noderight's height had been decremented from
+ h+1 to h. The subtree's height changes from
+ h+3 to h+2. */
+ -1
+ : /* nodeleft's height had been incremented from
+ h+1 to h+2. The subtree's height changes from
+ h+2 to h+2. */
+ 0);
+ }
+ }
+ else
+ {
+ /* node->balance = 2. The subtree is heavier on the right side.
+ Rotate from right to left:
+
+ *
+ / \
+ h h+2
+ */
+ gl_oset_node_t noderightleft = noderight->left;
+ if (noderight->balance >= 0)
+ {
+ /*
+ * h+2|h+3
+ / \ / \
+ h h+2 --> h+1|h+2 \
+ / \ / \ |
+ h|h+1 h+1 h h|h+1 h+1
+ */
+ node->right = noderightleft;
+ noderight->left = node;
+
+ noderight->parent = node->parent;
+ node->parent = noderight;
+ if (noderightleft != NULL)
+ noderightleft->parent = node;
+
+ noderight->balance -= 1;
+ node->balance = - noderight->balance;
+
+ *nodep = noderight;
+ height_diff = (height_diff < 0
+ ? /* nodeleft's height had been decremented from
+ h+1 to h. The subtree's height changes from
+ h+3 to h+2|h+3. */
+ - noderight->balance - 1
+ : /* noderight's height had been incremented from
+ h+1 to h+2. The subtree's height changes from
+ h+2 to h+2|h+3. */
+ - noderight->balance);
+ }
+ else
+ {
+ /*
+ * h+2
+ / \ / \
+ h h+2 --> h+1 h+1
+ / \ / \ / \
+ h+1 h h L R h
+ / \
+ L R
+
+ */
+ gl_oset_node_t L = node->right = noderightleft->left;
+ gl_oset_node_t R = noderight->left = noderightleft->right;
+ noderightleft->left = node;
+ noderightleft->right = noderight;
+
+ noderightleft->parent = node->parent;
+ if (L != NULL)
+ L->parent = node;
+ if (R != NULL)
+ R->parent = noderight;
+ node->parent = noderightleft;
+ noderight->parent = noderightleft;
+
+ node->balance = (noderightleft->balance > 0 ? -1 : 0);
+ noderight->balance = (noderightleft->balance < 0 ? 1 : 0);
+ noderightleft->balance = 0;
+
+ *nodep = noderightleft;
+ height_diff = (height_diff < 0
+ ? /* nodeleft's height had been decremented from
+ h+1 to h. The subtree's height changes from
+ h+3 to h+2. */
+ -1
+ : /* noderight's height had been incremented from
+ h+1 to h+2. The subtree's height changes from
+ h+2 to h+2. */
+ 0);
+ }
+ }
+ node = *nodep;
+ }
+ else
+ {
+ /* No rotation needed. Only propagation of the height change to the
+ next higher level. */
+ if (height_diff < 0)
+ height_diff = (previous_balance == 0 ? 0 : -1);
+ else
+ height_diff = (node->balance == 0 ? 0 : 1);
+ }
+
+ if (height_diff == 0)
+ break;
+
+ parent = node->parent;
+ if (parent == NULL)
+ break;
+ }
+}
+
+static gl_oset_node_t
+gl_tree_nx_add_first (gl_oset_t set, const void *elt)
+{
+ /* Create new node. */
+ gl_oset_node_t new_node =
+ (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
+
+ if (new_node == NULL)
+ return NULL;
+
+ new_node->left = NULL;
+ new_node->right = NULL;
+ new_node->balance = 0;
+ new_node->value = elt;
+
+ /* Add it to the tree. */
+ if (set->root == NULL)
+ {
+ set->root = new_node;
+ new_node->parent = NULL;
+ }
+ else
+ {
+ gl_oset_node_t node;
+
+ for (node = set->root; node->left != NULL; )
+ node = node->left;
+
+ node->left = new_node;
+ new_node->parent = node;
+ node->balance--;
+
+ /* Rebalance. */
+ if (node->right == NULL && node->parent != NULL)
+ rebalance (set, node, 1, node->parent);
+ }
+
+ set->count++;
+ return new_node;
+}
+
+static gl_oset_node_t
+gl_tree_nx_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt)
+{
+ /* Create new node. */
+ gl_oset_node_t new_node =
+ (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
+ bool height_inc;
+
+ if (new_node == NULL)
+ return NULL;
+
+ new_node->left = NULL;
+ new_node->right = NULL;
+ new_node->balance = 0;
+ new_node->value = elt;
+
+ /* Add it to the tree. */
+ if (node->left == NULL)
+ {
+ node->left = new_node;
+ node->balance--;
+ height_inc = (node->right == NULL);
+ }
+ else
+ {
+ for (node = node->left; node->right != NULL; )
+ node = node->right;
+ node->right = new_node;
+ node->balance++;
+ height_inc = (node->left == NULL);
+ }
+ new_node->parent = node;
+
+ /* Rebalance. */
+ if (height_inc && node->parent != NULL)
+ rebalance (set, node, 1, node->parent);
+
+ set->count++;
+ return new_node;
+}
+
+static gl_oset_node_t
+gl_tree_nx_add_after (gl_oset_t set, gl_oset_node_t node, const void *elt)
+{
+ /* Create new node. */
+ gl_oset_node_t new_node =
+ (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
+ bool height_inc;
+
+ if (new_node == NULL)
+ return NULL;
+
+ new_node->left = NULL;
+ new_node->right = NULL;
+ new_node->balance = 0;
+ new_node->value = elt;
+
+ /* Add it to the tree. */
+ if (node->right == NULL)
+ {
+ node->right = new_node;
+ node->balance++;
+ height_inc = (node->left == NULL);
+ }
+ else
+ {
+ for (node = node->right; node->left != NULL; )
+ node = node->left;
+ node->left = new_node;
+ node->balance--;
+ height_inc = (node->right == NULL);
+ }
+ new_node->parent = node;
+
+ /* Rebalance. */
+ if (height_inc && node->parent != NULL)
+ rebalance (set, node, 1, node->parent);
+
+ set->count++;
+ return new_node;
+}
+
+static bool
+gl_tree_remove_node (gl_oset_t set, gl_oset_node_t node)
+{
+ gl_oset_node_t parent = node->parent;
+
+ if (node->left == NULL)
+ {
+ /* Replace node with node->right. */
+ gl_oset_node_t child = node->right;
+
+ if (child != NULL)
+ child->parent = parent;
+ if (parent == NULL)
+ set->root = child;
+ else
+ {
+ if (parent->left == node)
+ parent->left = child;
+ else /* parent->right == node */
+ parent->right = child;
+
+ rebalance (set, child, -1, parent);
+ }
+ }
+ else if (node->right == NULL)
+ {
+ /* It is not absolutely necessary to treat this case. But the more
+ general case below is more complicated, hence slower. */
+ /* Replace node with node->left. */
+ gl_oset_node_t child = node->left;
+
+ child->parent = parent;
+ if (parent == NULL)
+ set->root = child;
+ else
+ {
+ if (parent->left == node)
+ parent->left = child;
+ else /* parent->right == node */
+ parent->right = child;
+
+ rebalance (set, child, -1, parent);
+ }
+ }
+ else
+ {
+ /* Replace node with the rightmost element of the node->left subtree. */
+ gl_oset_node_t subst;
+ gl_oset_node_t subst_parent;
+ gl_oset_node_t child;
+
+ for (subst = node->left; subst->right != NULL; )
+ subst = subst->right;
+
+ subst_parent = subst->parent;
+
+ child = subst->left;
+
+ /* The case subst_parent == node is special: If we do nothing special,
+ we get confusion about node->left, subst->left and child->parent.
+ subst_parent == node
+ <==> The 'for' loop above terminated immediately.
+ <==> subst == subst_parent->left
+ [otherwise subst == subst_parent->right]
+ In this case, we would need to first set
+ child->parent = node; node->left = child;
+ and later - when we copy subst into node's position - again
+ child->parent = subst; subst->left = child;
+ Altogether a no-op. */
+ if (subst_parent != node)
+ {
+ if (child != NULL)
+ child->parent = subst_parent;
+ subst_parent->right = child;
+ }
+
+ /* Copy subst into node's position.
+ (This is safer than to copy subst's value into node, keep node in
+ place, and free subst.) */
+ if (subst_parent != node)
+ {
+ subst->left = node->left;
+ subst->left->parent = subst;
+ }
+ subst->right = node->right;
+ subst->right->parent = subst;
+ subst->balance = node->balance;
+ subst->parent = parent;
+ if (parent == NULL)
+ set->root = subst;
+ else if (parent->left == node)
+ parent->left = subst;
+ else /* parent->right == node */
+ parent->right = subst;
+
+ /* Rebalancing starts at child's parent, that is subst_parent -
+ except when subst_parent == node. In this case, we need to use
+ its replacement, subst. */
+ rebalance (set, child, -1, subst_parent != node ? subst_parent : subst);
+ }
+
+ set->count--;
+ if (set->base.dispose_fn != NULL)
+ set->base.dispose_fn (node->value);
+ free (node);
+ return true;
+}
+
+/* Generic binary tree code. */
+#include "gl_anytree_oset.h"
+
+/* For debugging. */
+static unsigned int
+check_invariants (gl_oset_node_t node, gl_oset_node_t parent, size_t *counterp)
+{
+ unsigned int left_height =
+ (node->left != NULL ? check_invariants (node->left, node, counterp) : 0);
+ unsigned int right_height =
+ (node->right != NULL ? check_invariants (node->right, node, counterp) : 0);
+ int balance = (int)right_height - (int)left_height;
+
+ if (!(node->parent == parent))
+ abort ();
+ if (!(balance >= -1 && balance <= 1))
+ abort ();
+ if (!(node->balance == balance))
+ abort ();
+
+ (*counterp)++;
+
+ return 1 + (left_height > right_height ? left_height : right_height);
+}
+void
+gl_avltree_oset_check_invariants (gl_oset_t set)
+{
+ size_t counter = 0;
+ if (set->root != NULL)
+ check_invariants (set->root, NULL, &counter);
+ if (!(set->count == counter))
+ abort ();
+}
+
+const struct gl_oset_implementation gl_avltree_oset_implementation =
+ {
+ gl_tree_nx_create_empty,
+ gl_tree_size,
+ gl_tree_search,
+ gl_tree_search_atleast,
+ gl_tree_nx_add,
+ gl_tree_remove,
+ gl_tree_oset_free,
+ gl_tree_iterator,
+ gl_tree_iterator_next,
+ gl_tree_iterator_free
+ };
diff --git a/contrib/tools/bison/gnulib/src/gl_avltree_oset.h b/contrib/tools/bison/gnulib/src/gl_avltree_oset.h
index abac895f08..30d5713cab 100644
--- a/contrib/tools/bison/gnulib/src/gl_avltree_oset.h
+++ b/contrib/tools/bison/gnulib/src/gl_avltree_oset.h
@@ -1,34 +1,34 @@
-/* Ordered set data type implemented by a binary tree.
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_AVLTREE_OSET_H
-#define _GL_AVLTREE_OSET_H
-
-#include "gl_oset.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const struct gl_oset_implementation gl_avltree_oset_implementation;
-#define GL_AVLTREE_OSET &gl_avltree_oset_implementation
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _GL_AVLTREE_OSET_H */
+/* Ordered set data type implemented by a binary tree.
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_AVLTREE_OSET_H
+#define _GL_AVLTREE_OSET_H
+
+#include "gl_oset.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const struct gl_oset_implementation gl_avltree_oset_implementation;
+#define GL_AVLTREE_OSET &gl_avltree_oset_implementation
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GL_AVLTREE_OSET_H */
diff --git a/contrib/tools/bison/gnulib/src/gl_linkedhash_list.c b/contrib/tools/bison/gnulib/src/gl_linkedhash_list.c
index 2f4e05f3a7..aeb073a9ec 100644
--- a/contrib/tools/bison/gnulib/src/gl_linkedhash_list.c
+++ b/contrib/tools/bison/gnulib/src/gl_linkedhash_list.c
@@ -1,124 +1,124 @@
-/* Sequential list data type implemented by a hash table with a linked list.
- Copyright (C) 2006, 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "gl_linkedhash_list.h"
-
-#include <stdint.h> /* for SIZE_MAX */
-#include <stdlib.h>
-
-#include "xsize.h"
-
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
-#define WITH_HASHTABLE 1
-
-/* -------------------------- gl_list_t Data Type -------------------------- */
-
-/* Generic hash-table code. */
-#include "gl_anyhash_list1.h"
-
-/* Generic linked list code. */
-#include "gl_anylinked_list1.h"
-
-/* Generic hash-table code. */
-#include "gl_anyhash_list2.h"
-
-/* Resize the hash table if needed, after list->count was incremented. */
-static void
-hash_resize_after_add (gl_list_t list)
-{
- size_t count = list->count;
- size_t estimate = xsum (count, count / 2); /* 1.5 * count */
- if (estimate > list->table_size)
- hash_resize (list, estimate);
-}
-
-/* Add a node to the hash table structure. */
-static void
-add_to_bucket (gl_list_t list, gl_list_node_t node)
-{
- size_t bucket = node->h.hashcode % list->table_size;
-
- node->h.hash_next = list->table[bucket];
- list->table[bucket] = &node->h;
-}
-/* Tell all compilers that the return value is 0. */
-#define add_to_bucket(list,node) ((add_to_bucket) (list, node), 0)
-
-/* Remove a node from the hash table structure. */
-static void
-remove_from_bucket (gl_list_t list, gl_list_node_t node)
-{
- size_t bucket = node->h.hashcode % list->table_size;
- gl_hash_entry_t *p;
-
- for (p = &list->table[bucket]; ; p = &(*p)->hash_next)
- {
- if (*p == &node->h)
- {
- *p = node->h.hash_next;
- break;
- }
- if (*p == NULL)
- /* node is not in the right bucket. Did the hash codes
- change inadvertently? */
- abort ();
- }
-}
-
-/* Generic linked list code. */
-#include "gl_anylinked_list2.h"
-
-
-const struct gl_list_implementation gl_linkedhash_list_implementation =
- {
- gl_linked_nx_create_empty,
- gl_linked_nx_create,
- gl_linked_size,
- gl_linked_node_value,
- gl_linked_node_nx_set_value,
- gl_linked_next_node,
- gl_linked_previous_node,
- gl_linked_get_at,
- gl_linked_nx_set_at,
- gl_linked_search_from_to,
- gl_linked_indexof_from_to,
- gl_linked_nx_add_first,
- gl_linked_nx_add_last,
- gl_linked_nx_add_before,
- gl_linked_nx_add_after,
- gl_linked_nx_add_at,
- gl_linked_remove_node,
- gl_linked_remove_at,
- gl_linked_remove,
- gl_linked_list_free,
- gl_linked_iterator,
- gl_linked_iterator_from_to,
- gl_linked_iterator_next,
- gl_linked_iterator_free,
- gl_linked_sortedlist_search,
- gl_linked_sortedlist_search_from_to,
- gl_linked_sortedlist_indexof,
- gl_linked_sortedlist_indexof_from_to,
- gl_linked_sortedlist_nx_add,
- gl_linked_sortedlist_remove
- };
+/* Sequential list data type implemented by a hash table with a linked list.
+ Copyright (C) 2006, 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "gl_linkedhash_list.h"
+
+#include <stdint.h> /* for SIZE_MAX */
+#include <stdlib.h>
+
+#include "xsize.h"
+
+#ifndef uintptr_t
+# define uintptr_t unsigned long
+#endif
+
+#define WITH_HASHTABLE 1
+
+/* -------------------------- gl_list_t Data Type -------------------------- */
+
+/* Generic hash-table code. */
+#include "gl_anyhash_list1.h"
+
+/* Generic linked list code. */
+#include "gl_anylinked_list1.h"
+
+/* Generic hash-table code. */
+#include "gl_anyhash_list2.h"
+
+/* Resize the hash table if needed, after list->count was incremented. */
+static void
+hash_resize_after_add (gl_list_t list)
+{
+ size_t count = list->count;
+ size_t estimate = xsum (count, count / 2); /* 1.5 * count */
+ if (estimate > list->table_size)
+ hash_resize (list, estimate);
+}
+
+/* Add a node to the hash table structure. */
+static void
+add_to_bucket (gl_list_t list, gl_list_node_t node)
+{
+ size_t bucket = node->h.hashcode % list->table_size;
+
+ node->h.hash_next = list->table[bucket];
+ list->table[bucket] = &node->h;
+}
+/* Tell all compilers that the return value is 0. */
+#define add_to_bucket(list,node) ((add_to_bucket) (list, node), 0)
+
+/* Remove a node from the hash table structure. */
+static void
+remove_from_bucket (gl_list_t list, gl_list_node_t node)
+{
+ size_t bucket = node->h.hashcode % list->table_size;
+ gl_hash_entry_t *p;
+
+ for (p = &list->table[bucket]; ; p = &(*p)->hash_next)
+ {
+ if (*p == &node->h)
+ {
+ *p = node->h.hash_next;
+ break;
+ }
+ if (*p == NULL)
+ /* node is not in the right bucket. Did the hash codes
+ change inadvertently? */
+ abort ();
+ }
+}
+
+/* Generic linked list code. */
+#include "gl_anylinked_list2.h"
+
+
+const struct gl_list_implementation gl_linkedhash_list_implementation =
+ {
+ gl_linked_nx_create_empty,
+ gl_linked_nx_create,
+ gl_linked_size,
+ gl_linked_node_value,
+ gl_linked_node_nx_set_value,
+ gl_linked_next_node,
+ gl_linked_previous_node,
+ gl_linked_get_at,
+ gl_linked_nx_set_at,
+ gl_linked_search_from_to,
+ gl_linked_indexof_from_to,
+ gl_linked_nx_add_first,
+ gl_linked_nx_add_last,
+ gl_linked_nx_add_before,
+ gl_linked_nx_add_after,
+ gl_linked_nx_add_at,
+ gl_linked_remove_node,
+ gl_linked_remove_at,
+ gl_linked_remove,
+ gl_linked_list_free,
+ gl_linked_iterator,
+ gl_linked_iterator_from_to,
+ gl_linked_iterator_next,
+ gl_linked_iterator_free,
+ gl_linked_sortedlist_search,
+ gl_linked_sortedlist_search_from_to,
+ gl_linked_sortedlist_indexof,
+ gl_linked_sortedlist_indexof_from_to,
+ gl_linked_sortedlist_nx_add,
+ gl_linked_sortedlist_remove
+ };
diff --git a/contrib/tools/bison/gnulib/src/gl_linkedhash_list.h b/contrib/tools/bison/gnulib/src/gl_linkedhash_list.h
index 577756c9d4..bf67598285 100644
--- a/contrib/tools/bison/gnulib/src/gl_linkedhash_list.h
+++ b/contrib/tools/bison/gnulib/src/gl_linkedhash_list.h
@@ -1,34 +1,34 @@
-/* Sequential list data type implemented by a hash table with a linked list.
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_LINKEDHASH_LIST_H
-#define _GL_LINKEDHASH_LIST_H
-
-#include "gl_list.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern const struct gl_list_implementation gl_linkedhash_list_implementation;
-#define GL_LINKEDHASH_LIST &gl_linkedhash_list_implementation
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _GL_LINKEDHASH_LIST_H */
+/* Sequential list data type implemented by a hash table with a linked list.
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_LINKEDHASH_LIST_H
+#define _GL_LINKEDHASH_LIST_H
+
+#include "gl_list.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const struct gl_list_implementation gl_linkedhash_list_implementation;
+#define GL_LINKEDHASH_LIST &gl_linkedhash_list_implementation
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GL_LINKEDHASH_LIST_H */
diff --git a/contrib/tools/bison/gnulib/src/gl_list.c b/contrib/tools/bison/gnulib/src/gl_list.c
index 8793298070..617b3d239a 100644
--- a/contrib/tools/bison/gnulib/src/gl_list.c
+++ b/contrib/tools/bison/gnulib/src/gl_list.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define GL_LIST_INLINE _GL_EXTERN_INLINE
-#include "gl_list.h"
+#include <config.h>
+#define GL_LIST_INLINE _GL_EXTERN_INLINE
+#include "gl_list.h"
diff --git a/contrib/tools/bison/gnulib/src/gl_list.h b/contrib/tools/bison/gnulib/src/gl_list.h
index 9094723fe5..6ca363e9dc 100644
--- a/contrib/tools/bison/gnulib/src/gl_list.h
+++ b/contrib/tools/bison/gnulib/src/gl_list.h
@@ -1,841 +1,841 @@
-/* Abstract sequential list data type.
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_LIST_H
-#define _GL_LIST_H
-
-#include <stdbool.h>
-#include <stddef.h>
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef GL_LIST_INLINE
-# define GL_LIST_INLINE _GL_INLINE
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* gl_list is an abstract list data type. It can contain any number of
- objects ('void *' or 'const void *' pointers) in any given order.
- Duplicates are allowed, but can optionally be forbidden.
-
- There are several implementations of this list datatype, optimized for
- different operations or for memory. You can start using the simplest list
- implementation, GL_ARRAY_LIST, and switch to a different implementation
- later, when you realize which operations are performed the most frequently.
- The API of the different implementations is exactly the same; when
- switching to a different implementation, you only have to change the
- gl_list_create call.
-
- The implementations are:
- GL_ARRAY_LIST a growable array
- GL_CARRAY_LIST a growable circular array
- GL_LINKED_LIST a linked list
- GL_AVLTREE_LIST a binary tree (AVL tree)
- GL_RBTREE_LIST a binary tree (red-black tree)
- GL_LINKEDHASH_LIST a hash table with a linked list
- GL_AVLTREEHASH_LIST a hash table with a binary tree (AVL tree)
- GL_RBTREEHASH_LIST a hash table with a binary tree (red-black tree)
-
- The memory consumption is asymptotically the same: O(1) for every object
- in the list. When looking more closely at the average memory consumed
- for an object, GL_ARRAY_LIST is the most compact representation, and
- GL_LINKEDHASH_LIST and GL_TREEHASH_LIST need more memory.
-
- The guaranteed average performance of the operations is, for a list of
- n elements:
-
- Operation ARRAY LINKED TREE LINKEDHASH TREEHASH
- CARRAY with|without with|without
- duplicates duplicates
-
- gl_list_size O(1) O(1) O(1) O(1) O(1)
- gl_list_node_value O(1) O(1) O(1) O(1) O(1)
- gl_list_node_set_value O(1) O(1) O(1) O(1) O((log n)²)/O(1)
- gl_list_next_node O(1) O(1) O(log n) O(1) O(log n)
- gl_list_previous_node O(1) O(1) O(log n) O(1) O(log n)
- gl_list_get_at O(1) O(n) O(log n) O(n) O(log n)
- gl_list_set_at O(1) O(n) O(log n) O(n) O((log n)²)/O(log n)
- gl_list_search O(n) O(n) O(n) O(n)/O(1) O(log n)/O(1)
- gl_list_search_from O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
- gl_list_search_from_to O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
- gl_list_indexof O(n) O(n) O(n) O(n) O(log n)
- gl_list_indexof_from O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
- gl_list_indexof_from_to O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
- gl_list_add_first O(n)/O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
- gl_list_add_last O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
- gl_list_add_before O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
- gl_list_add_after O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
- gl_list_add_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
- gl_list_remove_node O(n) O(1) O(log n) O(n)/O(1) O((log n)²)/O(log n)
- gl_list_remove_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
- gl_list_remove O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
- gl_list_iterator O(1) O(1) O(log n) O(1) O(log n)
- gl_list_iterator_from_to O(1) O(n) O(log n) O(n) O(log n)
- gl_list_iterator_next O(1) O(1) O(log n) O(1) O(log n)
- gl_sortedlist_search O(log n) O(n) O(log n) O(n) O(log n)
- gl_sortedlist_search_from O(log n) O(n) O(log n) O(n) O(log n)
- gl_sortedlist_indexof O(log n) O(n) O(log n) O(n) O(log n)
- gl_sortedlist_indexof_fro O(log n) O(n) O(log n) O(n) O(log n)
- gl_sortedlist_add O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
- gl_sortedlist_remove O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
- */
-
-/* -------------------------- gl_list_t Data Type -------------------------- */
-
-/* Type of function used to compare two elements.
- NULL denotes pointer comparison. */
-typedef bool (*gl_listelement_equals_fn) (const void *elt1, const void *elt2);
-
-/* Type of function used to compute a hash code.
- NULL denotes a function that depends only on the pointer itself. */
-typedef size_t (*gl_listelement_hashcode_fn) (const void *elt);
-
-/* Type of function used to dispose an element once it's removed from a list.
- NULL denotes a no-op. */
-typedef void (*gl_listelement_dispose_fn) (const void *elt);
-
-struct gl_list_impl;
-/* Type representing an entire list. */
-typedef struct gl_list_impl * gl_list_t;
-
-struct gl_list_node_impl;
-/* Type representing the position of an element in the list, in a way that
- is more adapted to the list implementation than a plain index.
- Note: It is invalidated by insertions and removals! */
-typedef struct gl_list_node_impl * gl_list_node_t;
-
-struct gl_list_implementation;
-/* Type representing a list datatype implementation. */
-typedef const struct gl_list_implementation * gl_list_implementation_t;
-
-#if 0 /* Unless otherwise specified, these are defined inline below. */
-
-/* Create an empty list.
- IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
- GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
- GL_RBTREEHASH_LIST.
- EQUALS_FN is an element comparison function or NULL.
- HASHCODE_FN is an element hash code function or NULL.
- DISPOSE_FN is an element disposal function or NULL.
- ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
- the list. The implementation may verify this at runtime. */
-/* declared in gl_xlist.h */
-extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_t gl_list_nx_create_empty (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates);
-
-/* Create a list with given contents.
- IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
- GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
- GL_RBTREEHASH_LIST.
- EQUALS_FN is an element comparison function or NULL.
- HASHCODE_FN is an element hash code function or NULL.
- DISPOSE_FN is an element disposal function or NULL.
- ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
- the list. The implementation may verify this at runtime.
- COUNT is the number of initial elements.
- CONTENTS[0..COUNT-1] is the initial contents. */
-/* declared in gl_xlist.h */
-extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates,
- size_t count, const void **contents);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates,
- size_t count, const void **contents);
-
-/* Return the current number of elements in a list. */
-extern size_t gl_list_size (gl_list_t list);
-
-/* Return the element value represented by a list node. */
-extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node);
-
-/* Replace the element value represented by a list node. */
-/* declared in gl_xlist.h */
-extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
- const void *elt);
-/* Likewise. Return 0 upon success, -1 upon out-of-memory. */
-extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node,
- const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Return the node immediately after the given node in the list, or NULL
- if the given node is the last (rightmost) one in the list. */
-extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node);
-
-/* Return the node immediately before the given node in the list, or NULL
- if the given node is the first (leftmost) one in the list. */
-extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node);
-
-/* Return the element at a given position in the list.
- POSITION must be >= 0 and < gl_list_size (list). */
-extern const void * gl_list_get_at (gl_list_t list, size_t position);
-
-/* Replace the element at a given position in the list.
- POSITION must be >= 0 and < gl_list_size (list).
- Return its node. */
-/* declared in gl_xlist.h */
-extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
- const void *elt);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position,
- const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Search whether an element is already in the list.
- Return its node if found, or NULL if not present in the list. */
-extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt);
-
-/* Search whether an element is already in the list,
- at a position >= START_INDEX.
- Return its node if found, or NULL if not present in the list. */
-extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index,
- const void *elt);
-
-/* Search whether an element is already in the list,
- at a position >= START_INDEX and < END_INDEX.
- Return its node if found, or NULL if not present in the list. */
-extern gl_list_node_t gl_list_search_from_to (gl_list_t list,
- size_t start_index,
- size_t end_index,
- const void *elt);
-
-/* Search whether an element is already in the list.
- Return its position if found, or (size_t)(-1) if not present in the list. */
-extern size_t gl_list_indexof (gl_list_t list, const void *elt);
-
-/* Search whether an element is already in the list,
- at a position >= START_INDEX.
- Return its position if found, or (size_t)(-1) if not present in the list. */
-extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index,
- const void *elt);
-
-/* Search whether an element is already in the list,
- at a position >= START_INDEX and < END_INDEX.
- Return its position if found, or (size_t)(-1) if not present in the list. */
-extern size_t gl_list_indexof_from_to (gl_list_t list,
- size_t start_index, size_t end_index,
- const void *elt);
-
-/* Add an element as the first element of the list.
- Return its node. */
-/* declared in gl_xlist.h */
-extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_node_t gl_list_nx_add_first (gl_list_t list, const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Add an element as the last element of the list.
- Return its node. */
-/* declared in gl_xlist.h */
-extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_node_t gl_list_nx_add_last (gl_list_t list, const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Add an element before a given element node of the list.
- Return its node. */
-/* declared in gl_xlist.h */
-extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
- const void *elt);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_node_t gl_list_nx_add_before (gl_list_t list,
- gl_list_node_t node,
- const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Add an element after a given element node of the list.
- Return its node. */
-/* declared in gl_xlist.h */
-extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
- const void *elt);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node,
- const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Add an element at a given position in the list.
- POSITION must be >= 0 and <= gl_list_size (list). */
-/* declared in gl_xlist.h */
-extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
- const void *elt);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position,
- const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Remove an element from the list.
- Return true. */
-extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node);
-
-/* Remove an element at a given position from the list.
- POSITION must be >= 0 and < gl_list_size (list).
- Return true. */
-extern bool gl_list_remove_at (gl_list_t list, size_t position);
-
-/* Search and remove an element from the list.
- Return true if it was found and removed. */
-extern bool gl_list_remove (gl_list_t list, const void *elt);
-
-/* Free an entire list.
- (But this call does not free the elements of the list.) */
-extern void gl_list_free (gl_list_t list);
-
-#endif /* End of inline and gl_xlist.h-defined functions. */
-
-/* --------------------- gl_list_iterator_t Data Type --------------------- */
-
-/* Functions for iterating through a list. */
-
-/* Type of an iterator that traverses a list.
- This is a fixed-size struct, so that creation of an iterator doesn't need
- memory allocation on the heap. */
-typedef struct
-{
- /* For fast dispatch of gl_list_iterator_next. */
- const struct gl_list_implementation *vtable;
- /* For detecting whether the last returned element was removed. */
- gl_list_t list;
- size_t count;
- /* Other, implementation-private fields. */
- void *p; void *q;
- size_t i; size_t j;
-} gl_list_iterator_t;
-
-#if 0 /* These are defined inline below. */
-
-/* Create an iterator traversing a list.
- The list contents must not be modified while the iterator is in use,
- except for replacing or removing the last returned element. */
-extern gl_list_iterator_t gl_list_iterator (gl_list_t list);
-
-/* Create an iterator traversing the element with indices i,
- start_index <= i < end_index, of a list.
- The list contents must not be modified while the iterator is in use,
- except for replacing or removing the last returned element. */
-extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list,
- size_t start_index,
- size_t end_index);
-
-/* If there is a next element, store the next element in *ELTP, store its
- node in *NODEP if NODEP is non-NULL, advance the iterator and return true.
- Otherwise, return false. */
-extern bool gl_list_iterator_next (gl_list_iterator_t *iterator,
- const void **eltp, gl_list_node_t *nodep);
-
-/* Free an iterator. */
-extern void gl_list_iterator_free (gl_list_iterator_t *iterator);
-
-#endif /* End of inline functions. */
-
-/* ---------------------- Sorted gl_list_t Data Type ---------------------- */
-
-/* The following functions are for lists without duplicates where the
- order is given by a sort criterion. */
-
-/* Type of function used to compare two elements. Same as for qsort().
- NULL denotes pointer comparison. */
-typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2);
-
-#if 0 /* Unless otherwise specified, these are defined inline below. */
-
-/* Search whether an element is already in the list.
- The list is assumed to be sorted with COMPAR.
- Return its node if found, or NULL if not present in the list.
- If the list contains several copies of ELT, the node of the leftmost one is
- returned. */
-extern gl_list_node_t gl_sortedlist_search (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
-
-/* Search whether an element is already in the list.
- The list is assumed to be sorted with COMPAR.
- Only list elements with indices >= START_INDEX and < END_INDEX are
- considered; the implementation uses these bounds to minimize the number
- of COMPAR invocations.
- Return its node if found, or NULL if not present in the list.
- If the list contains several copies of ELT, the node of the leftmost one is
- returned. */
-extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list,
- gl_listelement_compar_fn compar,
- size_t start_index,
- size_t end_index,
- const void *elt);
-
-/* Search whether an element is already in the list.
- The list is assumed to be sorted with COMPAR.
- Return its position if found, or (size_t)(-1) if not present in the list.
- If the list contains several copies of ELT, the position of the leftmost one
- is returned. */
-extern size_t gl_sortedlist_indexof (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
-
-/* Search whether an element is already in the list.
- The list is assumed to be sorted with COMPAR.
- Only list elements with indices >= START_INDEX and < END_INDEX are
- considered; the implementation uses these bounds to minimize the number
- of COMPAR invocations.
- Return its position if found, or (size_t)(-1) if not present in the list.
- If the list contains several copies of ELT, the position of the leftmost one
- is returned. */
-extern size_t gl_sortedlist_indexof_from_to (gl_list_t list,
- gl_listelement_compar_fn compar,
- size_t start_index,
- size_t end_index,
- const void *elt);
-
-/* Add an element at the appropriate position in the list.
- The list is assumed to be sorted with COMPAR.
- Return its node. */
-/* declared in gl_xlist.h */
-extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Search and remove an element from the list.
- The list is assumed to be sorted with COMPAR.
- Return true if it was found and removed.
- If the list contains several copies of ELT, only the leftmost one is
- removed. */
-extern bool gl_sortedlist_remove (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
-
-#endif /* End of inline and gl_xlist.h-defined functions. */
-
-/* ------------------------ Implementation Details ------------------------ */
-
-struct gl_list_implementation
-{
- /* gl_list_t functions. */
- gl_list_t (*nx_create_empty) (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates);
- gl_list_t (*nx_create) (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates,
- size_t count, const void **contents);
- size_t (*size) (gl_list_t list);
- const void * (*node_value) (gl_list_t list, gl_list_node_t node);
- int (*node_nx_set_value) (gl_list_t list, gl_list_node_t node,
- const void *elt);
- gl_list_node_t (*next_node) (gl_list_t list, gl_list_node_t node);
- gl_list_node_t (*previous_node) (gl_list_t list, gl_list_node_t node);
- const void * (*get_at) (gl_list_t list, size_t position);
- gl_list_node_t (*nx_set_at) (gl_list_t list, size_t position,
- const void *elt);
- gl_list_node_t (*search_from_to) (gl_list_t list, size_t start_index,
- size_t end_index, const void *elt);
- size_t (*indexof_from_to) (gl_list_t list, size_t start_index,
- size_t end_index, const void *elt);
- gl_list_node_t (*nx_add_first) (gl_list_t list, const void *elt);
- gl_list_node_t (*nx_add_last) (gl_list_t list, const void *elt);
- gl_list_node_t (*nx_add_before) (gl_list_t list, gl_list_node_t node,
- const void *elt);
- gl_list_node_t (*nx_add_after) (gl_list_t list, gl_list_node_t node,
- const void *elt);
- gl_list_node_t (*nx_add_at) (gl_list_t list, size_t position,
- const void *elt);
- bool (*remove_node) (gl_list_t list, gl_list_node_t node);
- bool (*remove_at) (gl_list_t list, size_t position);
- bool (*remove_elt) (gl_list_t list, const void *elt);
- void (*list_free) (gl_list_t list);
- /* gl_list_iterator_t functions. */
- gl_list_iterator_t (*iterator) (gl_list_t list);
- gl_list_iterator_t (*iterator_from_to) (gl_list_t list,
- size_t start_index,
- size_t end_index);
- bool (*iterator_next) (gl_list_iterator_t *iterator,
- const void **eltp, gl_list_node_t *nodep);
- void (*iterator_free) (gl_list_iterator_t *iterator);
- /* Sorted gl_list_t functions. */
- gl_list_node_t (*sortedlist_search) (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
- gl_list_node_t (*sortedlist_search_from_to) (gl_list_t list,
- gl_listelement_compar_fn compar,
- size_t start_index,
- size_t end_index,
- const void *elt);
- size_t (*sortedlist_indexof) (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
- size_t (*sortedlist_indexof_from_to) (gl_list_t list,
- gl_listelement_compar_fn compar,
- size_t start_index, size_t end_index,
- const void *elt);
- gl_list_node_t (*sortedlist_nx_add) (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
- bool (*sortedlist_remove) (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
-};
-
-struct gl_list_impl_base
-{
- const struct gl_list_implementation *vtable;
- gl_listelement_equals_fn equals_fn;
- gl_listelement_hashcode_fn hashcode_fn;
- gl_listelement_dispose_fn dispose_fn;
- bool allow_duplicates;
-};
-
-/* Define all functions of this file as accesses to the
- struct gl_list_implementation. */
-
-GL_LIST_INLINE gl_list_t
-gl_list_nx_create_empty (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates)
-{
- return implementation->nx_create_empty (implementation, equals_fn,
- hashcode_fn, dispose_fn,
- allow_duplicates);
-}
-
-GL_LIST_INLINE gl_list_t
-gl_list_nx_create (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates,
- size_t count, const void **contents)
-{
- return implementation->nx_create (implementation, equals_fn, hashcode_fn,
- dispose_fn, allow_duplicates, count,
- contents);
-}
-
-GL_LIST_INLINE size_t
-gl_list_size (gl_list_t list)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->size (list);
-}
-
-GL_LIST_INLINE const void *
-gl_list_node_value (gl_list_t list, gl_list_node_t node)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->node_value (list, node);
-}
-
-GL_LIST_INLINE int
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node,
- const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->node_nx_set_value (list, node, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-gl_list_next_node (gl_list_t list, gl_list_node_t node)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->next_node (list, node);
-}
-
-GL_LIST_INLINE gl_list_node_t
-gl_list_previous_node (gl_list_t list, gl_list_node_t node)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->previous_node (list, node);
-}
-
-GL_LIST_INLINE const void *
-gl_list_get_at (gl_list_t list, size_t position)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->get_at (list, position);
-}
-
-GL_LIST_INLINE gl_list_node_t
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_list_nx_set_at (gl_list_t list, size_t position, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->nx_set_at (list, position, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-gl_list_search (gl_list_t list, const void *elt)
-{
- size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
- return ((const struct gl_list_impl_base *) list)->vtable
- ->search_from_to (list, 0, size, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-gl_list_search_from (gl_list_t list, size_t start_index, const void *elt)
-{
- size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
- return ((const struct gl_list_impl_base *) list)->vtable
- ->search_from_to (list, start_index, size, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
- const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->search_from_to (list, start_index, end_index, elt);
-}
-
-GL_LIST_INLINE size_t
-gl_list_indexof (gl_list_t list, const void *elt)
-{
- size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
- return ((const struct gl_list_impl_base *) list)->vtable
- ->indexof_from_to (list, 0, size, elt);
-}
-
-GL_LIST_INLINE size_t
-gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt)
-{
- size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
- return ((const struct gl_list_impl_base *) list)->vtable
- ->indexof_from_to (list, start_index, size, elt);
-}
-
-GL_LIST_INLINE size_t
-gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
- const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->indexof_from_to (list, start_index, end_index, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_list_nx_add_first (gl_list_t list, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->nx_add_first (list, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_list_nx_add_last (gl_list_t list, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->nx_add_last (list, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_list_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->nx_add_before (list, node, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->nx_add_after (list, node, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_list_nx_add_at (gl_list_t list, size_t position, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->nx_add_at (list, position, elt);
-}
-
-GL_LIST_INLINE bool
-gl_list_remove_node (gl_list_t list, gl_list_node_t node)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->remove_node (list, node);
-}
-
-GL_LIST_INLINE bool
-gl_list_remove_at (gl_list_t list, size_t position)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->remove_at (list, position);
-}
-
-GL_LIST_INLINE bool
-gl_list_remove (gl_list_t list, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->remove_elt (list, elt);
-}
-
-GL_LIST_INLINE void
-gl_list_free (gl_list_t list)
-{
- ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
-}
-
-GL_LIST_INLINE gl_list_iterator_t
-gl_list_iterator (gl_list_t list)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->iterator (list);
-}
-
-GL_LIST_INLINE gl_list_iterator_t
-gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->iterator_from_to (list, start_index, end_index);
-}
-
-GL_LIST_INLINE bool
-gl_list_iterator_next (gl_list_iterator_t *iterator,
- const void **eltp, gl_list_node_t *nodep)
-{
- return iterator->vtable->iterator_next (iterator, eltp, nodep);
-}
-
-GL_LIST_INLINE void
-gl_list_iterator_free (gl_list_iterator_t *iterator)
-{
- iterator->vtable->iterator_free (iterator);
-}
-
-GL_LIST_INLINE gl_list_node_t
-gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->sortedlist_search (list, compar, elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-gl_sortedlist_search_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->sortedlist_search_from_to (list, compar, start_index, end_index,
- elt);
-}
-
-GL_LIST_INLINE size_t
-gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->sortedlist_indexof (list, compar, elt);
-}
-
-GL_LIST_INLINE size_t
-gl_sortedlist_indexof_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->sortedlist_indexof_from_to (list, compar, start_index, end_index,
- elt);
-}
-
-GL_LIST_INLINE gl_list_node_t
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->sortedlist_nx_add (list, compar, elt);
-}
-
-GL_LIST_INLINE bool
-gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
-{
- return ((const struct gl_list_impl_base *) list)->vtable
- ->sortedlist_remove (list, compar, elt);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-_GL_INLINE_HEADER_END
-
-#endif /* _GL_LIST_H */
+/* Abstract sequential list data type.
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_LIST_H
+#define _GL_LIST_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef GL_LIST_INLINE
+# define GL_LIST_INLINE _GL_INLINE
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* gl_list is an abstract list data type. It can contain any number of
+ objects ('void *' or 'const void *' pointers) in any given order.
+ Duplicates are allowed, but can optionally be forbidden.
+
+ There are several implementations of this list datatype, optimized for
+ different operations or for memory. You can start using the simplest list
+ implementation, GL_ARRAY_LIST, and switch to a different implementation
+ later, when you realize which operations are performed the most frequently.
+ The API of the different implementations is exactly the same; when
+ switching to a different implementation, you only have to change the
+ gl_list_create call.
+
+ The implementations are:
+ GL_ARRAY_LIST a growable array
+ GL_CARRAY_LIST a growable circular array
+ GL_LINKED_LIST a linked list
+ GL_AVLTREE_LIST a binary tree (AVL tree)
+ GL_RBTREE_LIST a binary tree (red-black tree)
+ GL_LINKEDHASH_LIST a hash table with a linked list
+ GL_AVLTREEHASH_LIST a hash table with a binary tree (AVL tree)
+ GL_RBTREEHASH_LIST a hash table with a binary tree (red-black tree)
+
+ The memory consumption is asymptotically the same: O(1) for every object
+ in the list. When looking more closely at the average memory consumed
+ for an object, GL_ARRAY_LIST is the most compact representation, and
+ GL_LINKEDHASH_LIST and GL_TREEHASH_LIST need more memory.
+
+ The guaranteed average performance of the operations is, for a list of
+ n elements:
+
+ Operation ARRAY LINKED TREE LINKEDHASH TREEHASH
+ CARRAY with|without with|without
+ duplicates duplicates
+
+ gl_list_size O(1) O(1) O(1) O(1) O(1)
+ gl_list_node_value O(1) O(1) O(1) O(1) O(1)
+ gl_list_node_set_value O(1) O(1) O(1) O(1) O((log n)²)/O(1)
+ gl_list_next_node O(1) O(1) O(log n) O(1) O(log n)
+ gl_list_previous_node O(1) O(1) O(log n) O(1) O(log n)
+ gl_list_get_at O(1) O(n) O(log n) O(n) O(log n)
+ gl_list_set_at O(1) O(n) O(log n) O(n) O((log n)²)/O(log n)
+ gl_list_search O(n) O(n) O(n) O(n)/O(1) O(log n)/O(1)
+ gl_list_search_from O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
+ gl_list_search_from_to O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
+ gl_list_indexof O(n) O(n) O(n) O(n) O(log n)
+ gl_list_indexof_from O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
+ gl_list_indexof_from_to O(n) O(n) O(n) O(n) O((log n)²)/O(log n)
+ gl_list_add_first O(n)/O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
+ gl_list_add_last O(1) O(1) O(log n) O(1) O((log n)²)/O(log n)
+ gl_list_add_before O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
+ gl_list_add_after O(n) O(1) O(log n) O(1) O((log n)²)/O(log n)
+ gl_list_add_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
+ gl_list_remove_node O(n) O(1) O(log n) O(n)/O(1) O((log n)²)/O(log n)
+ gl_list_remove_at O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
+ gl_list_remove O(n) O(n) O(n) O(n)/O(1) O((log n)²)/O(log n)
+ gl_list_iterator O(1) O(1) O(log n) O(1) O(log n)
+ gl_list_iterator_from_to O(1) O(n) O(log n) O(n) O(log n)
+ gl_list_iterator_next O(1) O(1) O(log n) O(1) O(log n)
+ gl_sortedlist_search O(log n) O(n) O(log n) O(n) O(log n)
+ gl_sortedlist_search_from O(log n) O(n) O(log n) O(n) O(log n)
+ gl_sortedlist_indexof O(log n) O(n) O(log n) O(n) O(log n)
+ gl_sortedlist_indexof_fro O(log n) O(n) O(log n) O(n) O(log n)
+ gl_sortedlist_add O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
+ gl_sortedlist_remove O(n) O(n) O(log n) O(n) O((log n)²)/O(log n)
+ */
+
+/* -------------------------- gl_list_t Data Type -------------------------- */
+
+/* Type of function used to compare two elements.
+ NULL denotes pointer comparison. */
+typedef bool (*gl_listelement_equals_fn) (const void *elt1, const void *elt2);
+
+/* Type of function used to compute a hash code.
+ NULL denotes a function that depends only on the pointer itself. */
+typedef size_t (*gl_listelement_hashcode_fn) (const void *elt);
+
+/* Type of function used to dispose an element once it's removed from a list.
+ NULL denotes a no-op. */
+typedef void (*gl_listelement_dispose_fn) (const void *elt);
+
+struct gl_list_impl;
+/* Type representing an entire list. */
+typedef struct gl_list_impl * gl_list_t;
+
+struct gl_list_node_impl;
+/* Type representing the position of an element in the list, in a way that
+ is more adapted to the list implementation than a plain index.
+ Note: It is invalidated by insertions and removals! */
+typedef struct gl_list_node_impl * gl_list_node_t;
+
+struct gl_list_implementation;
+/* Type representing a list datatype implementation. */
+typedef const struct gl_list_implementation * gl_list_implementation_t;
+
+#if 0 /* Unless otherwise specified, these are defined inline below. */
+
+/* Create an empty list.
+ IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
+ GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
+ GL_RBTREEHASH_LIST.
+ EQUALS_FN is an element comparison function or NULL.
+ HASHCODE_FN is an element hash code function or NULL.
+ DISPOSE_FN is an element disposal function or NULL.
+ ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
+ the list. The implementation may verify this at runtime. */
+/* declared in gl_xlist.h */
+extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_t gl_list_nx_create_empty (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates);
+
+/* Create a list with given contents.
+ IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST,
+ GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST,
+ GL_RBTREEHASH_LIST.
+ EQUALS_FN is an element comparison function or NULL.
+ HASHCODE_FN is an element hash code function or NULL.
+ DISPOSE_FN is an element disposal function or NULL.
+ ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
+ the list. The implementation may verify this at runtime.
+ COUNT is the number of initial elements.
+ CONTENTS[0..COUNT-1] is the initial contents. */
+/* declared in gl_xlist.h */
+extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates,
+ size_t count, const void **contents);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates,
+ size_t count, const void **contents);
+
+/* Return the current number of elements in a list. */
+extern size_t gl_list_size (gl_list_t list);
+
+/* Return the element value represented by a list node. */
+extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node);
+
+/* Replace the element value represented by a list node. */
+/* declared in gl_xlist.h */
+extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+/* Likewise. Return 0 upon success, -1 upon out-of-memory. */
+extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node,
+ const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Return the node immediately after the given node in the list, or NULL
+ if the given node is the last (rightmost) one in the list. */
+extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node);
+
+/* Return the node immediately before the given node in the list, or NULL
+ if the given node is the first (leftmost) one in the list. */
+extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node);
+
+/* Return the element at a given position in the list.
+ POSITION must be >= 0 and < gl_list_size (list). */
+extern const void * gl_list_get_at (gl_list_t list, size_t position);
+
+/* Replace the element at a given position in the list.
+ POSITION must be >= 0 and < gl_list_size (list).
+ Return its node. */
+/* declared in gl_xlist.h */
+extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
+ const void *elt);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position,
+ const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Search whether an element is already in the list.
+ Return its node if found, or NULL if not present in the list. */
+extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt);
+
+/* Search whether an element is already in the list,
+ at a position >= START_INDEX.
+ Return its node if found, or NULL if not present in the list. */
+extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index,
+ const void *elt);
+
+/* Search whether an element is already in the list,
+ at a position >= START_INDEX and < END_INDEX.
+ Return its node if found, or NULL if not present in the list. */
+extern gl_list_node_t gl_list_search_from_to (gl_list_t list,
+ size_t start_index,
+ size_t end_index,
+ const void *elt);
+
+/* Search whether an element is already in the list.
+ Return its position if found, or (size_t)(-1) if not present in the list. */
+extern size_t gl_list_indexof (gl_list_t list, const void *elt);
+
+/* Search whether an element is already in the list,
+ at a position >= START_INDEX.
+ Return its position if found, or (size_t)(-1) if not present in the list. */
+extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index,
+ const void *elt);
+
+/* Search whether an element is already in the list,
+ at a position >= START_INDEX and < END_INDEX.
+ Return its position if found, or (size_t)(-1) if not present in the list. */
+extern size_t gl_list_indexof_from_to (gl_list_t list,
+ size_t start_index, size_t end_index,
+ const void *elt);
+
+/* Add an element as the first element of the list.
+ Return its node. */
+/* declared in gl_xlist.h */
+extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_node_t gl_list_nx_add_first (gl_list_t list, const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Add an element as the last element of the list.
+ Return its node. */
+/* declared in gl_xlist.h */
+extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_node_t gl_list_nx_add_last (gl_list_t list, const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Add an element before a given element node of the list.
+ Return its node. */
+/* declared in gl_xlist.h */
+extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_node_t gl_list_nx_add_before (gl_list_t list,
+ gl_list_node_t node,
+ const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Add an element after a given element node of the list.
+ Return its node. */
+/* declared in gl_xlist.h */
+extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node,
+ const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Add an element at a given position in the list.
+ POSITION must be >= 0 and <= gl_list_size (list). */
+/* declared in gl_xlist.h */
+extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
+ const void *elt);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position,
+ const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Remove an element from the list.
+ Return true. */
+extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node);
+
+/* Remove an element at a given position from the list.
+ POSITION must be >= 0 and < gl_list_size (list).
+ Return true. */
+extern bool gl_list_remove_at (gl_list_t list, size_t position);
+
+/* Search and remove an element from the list.
+ Return true if it was found and removed. */
+extern bool gl_list_remove (gl_list_t list, const void *elt);
+
+/* Free an entire list.
+ (But this call does not free the elements of the list.) */
+extern void gl_list_free (gl_list_t list);
+
+#endif /* End of inline and gl_xlist.h-defined functions. */
+
+/* --------------------- gl_list_iterator_t Data Type --------------------- */
+
+/* Functions for iterating through a list. */
+
+/* Type of an iterator that traverses a list.
+ This is a fixed-size struct, so that creation of an iterator doesn't need
+ memory allocation on the heap. */
+typedef struct
+{
+ /* For fast dispatch of gl_list_iterator_next. */
+ const struct gl_list_implementation *vtable;
+ /* For detecting whether the last returned element was removed. */
+ gl_list_t list;
+ size_t count;
+ /* Other, implementation-private fields. */
+ void *p; void *q;
+ size_t i; size_t j;
+} gl_list_iterator_t;
+
+#if 0 /* These are defined inline below. */
+
+/* Create an iterator traversing a list.
+ The list contents must not be modified while the iterator is in use,
+ except for replacing or removing the last returned element. */
+extern gl_list_iterator_t gl_list_iterator (gl_list_t list);
+
+/* Create an iterator traversing the element with indices i,
+ start_index <= i < end_index, of a list.
+ The list contents must not be modified while the iterator is in use,
+ except for replacing or removing the last returned element. */
+extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list,
+ size_t start_index,
+ size_t end_index);
+
+/* If there is a next element, store the next element in *ELTP, store its
+ node in *NODEP if NODEP is non-NULL, advance the iterator and return true.
+ Otherwise, return false. */
+extern bool gl_list_iterator_next (gl_list_iterator_t *iterator,
+ const void **eltp, gl_list_node_t *nodep);
+
+/* Free an iterator. */
+extern void gl_list_iterator_free (gl_list_iterator_t *iterator);
+
+#endif /* End of inline functions. */
+
+/* ---------------------- Sorted gl_list_t Data Type ---------------------- */
+
+/* The following functions are for lists without duplicates where the
+ order is given by a sort criterion. */
+
+/* Type of function used to compare two elements. Same as for qsort().
+ NULL denotes pointer comparison. */
+typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2);
+
+#if 0 /* Unless otherwise specified, these are defined inline below. */
+
+/* Search whether an element is already in the list.
+ The list is assumed to be sorted with COMPAR.
+ Return its node if found, or NULL if not present in the list.
+ If the list contains several copies of ELT, the node of the leftmost one is
+ returned. */
+extern gl_list_node_t gl_sortedlist_search (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+
+/* Search whether an element is already in the list.
+ The list is assumed to be sorted with COMPAR.
+ Only list elements with indices >= START_INDEX and < END_INDEX are
+ considered; the implementation uses these bounds to minimize the number
+ of COMPAR invocations.
+ Return its node if found, or NULL if not present in the list.
+ If the list contains several copies of ELT, the node of the leftmost one is
+ returned. */
+extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ size_t start_index,
+ size_t end_index,
+ const void *elt);
+
+/* Search whether an element is already in the list.
+ The list is assumed to be sorted with COMPAR.
+ Return its position if found, or (size_t)(-1) if not present in the list.
+ If the list contains several copies of ELT, the position of the leftmost one
+ is returned. */
+extern size_t gl_sortedlist_indexof (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+
+/* Search whether an element is already in the list.
+ The list is assumed to be sorted with COMPAR.
+ Only list elements with indices >= START_INDEX and < END_INDEX are
+ considered; the implementation uses these bounds to minimize the number
+ of COMPAR invocations.
+ Return its position if found, or (size_t)(-1) if not present in the list.
+ If the list contains several copies of ELT, the position of the leftmost one
+ is returned. */
+extern size_t gl_sortedlist_indexof_from_to (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ size_t start_index,
+ size_t end_index,
+ const void *elt);
+
+/* Add an element at the appropriate position in the list.
+ The list is assumed to be sorted with COMPAR.
+ Return its node. */
+/* declared in gl_xlist.h */
+extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Search and remove an element from the list.
+ The list is assumed to be sorted with COMPAR.
+ Return true if it was found and removed.
+ If the list contains several copies of ELT, only the leftmost one is
+ removed. */
+extern bool gl_sortedlist_remove (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+
+#endif /* End of inline and gl_xlist.h-defined functions. */
+
+/* ------------------------ Implementation Details ------------------------ */
+
+struct gl_list_implementation
+{
+ /* gl_list_t functions. */
+ gl_list_t (*nx_create_empty) (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates);
+ gl_list_t (*nx_create) (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates,
+ size_t count, const void **contents);
+ size_t (*size) (gl_list_t list);
+ const void * (*node_value) (gl_list_t list, gl_list_node_t node);
+ int (*node_nx_set_value) (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+ gl_list_node_t (*next_node) (gl_list_t list, gl_list_node_t node);
+ gl_list_node_t (*previous_node) (gl_list_t list, gl_list_node_t node);
+ const void * (*get_at) (gl_list_t list, size_t position);
+ gl_list_node_t (*nx_set_at) (gl_list_t list, size_t position,
+ const void *elt);
+ gl_list_node_t (*search_from_to) (gl_list_t list, size_t start_index,
+ size_t end_index, const void *elt);
+ size_t (*indexof_from_to) (gl_list_t list, size_t start_index,
+ size_t end_index, const void *elt);
+ gl_list_node_t (*nx_add_first) (gl_list_t list, const void *elt);
+ gl_list_node_t (*nx_add_last) (gl_list_t list, const void *elt);
+ gl_list_node_t (*nx_add_before) (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+ gl_list_node_t (*nx_add_after) (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+ gl_list_node_t (*nx_add_at) (gl_list_t list, size_t position,
+ const void *elt);
+ bool (*remove_node) (gl_list_t list, gl_list_node_t node);
+ bool (*remove_at) (gl_list_t list, size_t position);
+ bool (*remove_elt) (gl_list_t list, const void *elt);
+ void (*list_free) (gl_list_t list);
+ /* gl_list_iterator_t functions. */
+ gl_list_iterator_t (*iterator) (gl_list_t list);
+ gl_list_iterator_t (*iterator_from_to) (gl_list_t list,
+ size_t start_index,
+ size_t end_index);
+ bool (*iterator_next) (gl_list_iterator_t *iterator,
+ const void **eltp, gl_list_node_t *nodep);
+ void (*iterator_free) (gl_list_iterator_t *iterator);
+ /* Sorted gl_list_t functions. */
+ gl_list_node_t (*sortedlist_search) (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+ gl_list_node_t (*sortedlist_search_from_to) (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ size_t start_index,
+ size_t end_index,
+ const void *elt);
+ size_t (*sortedlist_indexof) (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+ size_t (*sortedlist_indexof_from_to) (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ size_t start_index, size_t end_index,
+ const void *elt);
+ gl_list_node_t (*sortedlist_nx_add) (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+ bool (*sortedlist_remove) (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+};
+
+struct gl_list_impl_base
+{
+ const struct gl_list_implementation *vtable;
+ gl_listelement_equals_fn equals_fn;
+ gl_listelement_hashcode_fn hashcode_fn;
+ gl_listelement_dispose_fn dispose_fn;
+ bool allow_duplicates;
+};
+
+/* Define all functions of this file as accesses to the
+ struct gl_list_implementation. */
+
+GL_LIST_INLINE gl_list_t
+gl_list_nx_create_empty (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates)
+{
+ return implementation->nx_create_empty (implementation, equals_fn,
+ hashcode_fn, dispose_fn,
+ allow_duplicates);
+}
+
+GL_LIST_INLINE gl_list_t
+gl_list_nx_create (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates,
+ size_t count, const void **contents)
+{
+ return implementation->nx_create (implementation, equals_fn, hashcode_fn,
+ dispose_fn, allow_duplicates, count,
+ contents);
+}
+
+GL_LIST_INLINE size_t
+gl_list_size (gl_list_t list)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->size (list);
+}
+
+GL_LIST_INLINE const void *
+gl_list_node_value (gl_list_t list, gl_list_node_t node)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->node_value (list, node);
+}
+
+GL_LIST_INLINE int
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node,
+ const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->node_nx_set_value (list, node, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+gl_list_next_node (gl_list_t list, gl_list_node_t node)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->next_node (list, node);
+}
+
+GL_LIST_INLINE gl_list_node_t
+gl_list_previous_node (gl_list_t list, gl_list_node_t node)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->previous_node (list, node);
+}
+
+GL_LIST_INLINE const void *
+gl_list_get_at (gl_list_t list, size_t position)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->get_at (list, position);
+}
+
+GL_LIST_INLINE gl_list_node_t
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_list_nx_set_at (gl_list_t list, size_t position, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->nx_set_at (list, position, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+gl_list_search (gl_list_t list, const void *elt)
+{
+ size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->search_from_to (list, 0, size, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+gl_list_search_from (gl_list_t list, size_t start_index, const void *elt)
+{
+ size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->search_from_to (list, start_index, size, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index,
+ const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->search_from_to (list, start_index, end_index, elt);
+}
+
+GL_LIST_INLINE size_t
+gl_list_indexof (gl_list_t list, const void *elt)
+{
+ size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->indexof_from_to (list, 0, size, elt);
+}
+
+GL_LIST_INLINE size_t
+gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt)
+{
+ size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->indexof_from_to (list, start_index, size, elt);
+}
+
+GL_LIST_INLINE size_t
+gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index,
+ const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->indexof_from_to (list, start_index, end_index, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_list_nx_add_first (gl_list_t list, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->nx_add_first (list, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_list_nx_add_last (gl_list_t list, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->nx_add_last (list, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_list_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->nx_add_before (list, node, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->nx_add_after (list, node, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_list_nx_add_at (gl_list_t list, size_t position, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->nx_add_at (list, position, elt);
+}
+
+GL_LIST_INLINE bool
+gl_list_remove_node (gl_list_t list, gl_list_node_t node)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->remove_node (list, node);
+}
+
+GL_LIST_INLINE bool
+gl_list_remove_at (gl_list_t list, size_t position)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->remove_at (list, position);
+}
+
+GL_LIST_INLINE bool
+gl_list_remove (gl_list_t list, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->remove_elt (list, elt);
+}
+
+GL_LIST_INLINE void
+gl_list_free (gl_list_t list)
+{
+ ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
+}
+
+GL_LIST_INLINE gl_list_iterator_t
+gl_list_iterator (gl_list_t list)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->iterator (list);
+}
+
+GL_LIST_INLINE gl_list_iterator_t
+gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->iterator_from_to (list, start_index, end_index);
+}
+
+GL_LIST_INLINE bool
+gl_list_iterator_next (gl_list_iterator_t *iterator,
+ const void **eltp, gl_list_node_t *nodep)
+{
+ return iterator->vtable->iterator_next (iterator, eltp, nodep);
+}
+
+GL_LIST_INLINE void
+gl_list_iterator_free (gl_list_iterator_t *iterator)
+{
+ iterator->vtable->iterator_free (iterator);
+}
+
+GL_LIST_INLINE gl_list_node_t
+gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->sortedlist_search (list, compar, elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+gl_sortedlist_search_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->sortedlist_search_from_to (list, compar, start_index, end_index,
+ elt);
+}
+
+GL_LIST_INLINE size_t
+gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->sortedlist_indexof (list, compar, elt);
+}
+
+GL_LIST_INLINE size_t
+gl_sortedlist_indexof_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->sortedlist_indexof_from_to (list, compar, start_index, end_index,
+ elt);
+}
+
+GL_LIST_INLINE gl_list_node_t
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->sortedlist_nx_add (list, compar, elt);
+}
+
+GL_LIST_INLINE bool
+gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
+{
+ return ((const struct gl_list_impl_base *) list)->vtable
+ ->sortedlist_remove (list, compar, elt);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif /* _GL_LIST_H */
diff --git a/contrib/tools/bison/gnulib/src/gl_oset.c b/contrib/tools/bison/gnulib/src/gl_oset.c
index 21f731a31a..c3b88138c9 100644
--- a/contrib/tools/bison/gnulib/src/gl_oset.c
+++ b/contrib/tools/bison/gnulib/src/gl_oset.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define GL_OSET_INLINE _GL_EXTERN_INLINE
-#include "gl_oset.h"
+#include <config.h>
+#define GL_OSET_INLINE _GL_EXTERN_INLINE
+#include "gl_oset.h"
diff --git a/contrib/tools/bison/gnulib/src/gl_oset.h b/contrib/tools/bison/gnulib/src/gl_oset.h
index 5134065e5e..e4026cec36 100644
--- a/contrib/tools/bison/gnulib/src/gl_oset.h
+++ b/contrib/tools/bison/gnulib/src/gl_oset.h
@@ -1,293 +1,293 @@
-/* Abstract ordered set data type.
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_OSET_H
-#define _GL_OSET_H
-
-#include <stdbool.h>
-#include <stddef.h>
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef GL_OSET_INLINE
-# define GL_OSET_INLINE _GL_INLINE
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* gl_oset is an abstract ordered set data type. It can contain any number
- of objects ('void *' or 'const void *' pointers) in the order of a given
- comparator function. Duplicates (in the sense of the comparator) are
- forbidden.
-
- There are several implementations of this ordered set datatype, optimized
- for different operations or for memory. You can start using the simplest
- ordered set implementation, GL_ARRAY_OSET, and switch to a different
- implementation later, when you realize which operations are performed
- the most frequently. The API of the different implementations is exactly
- the same; when switching to a different implementation, you only have to
- change the gl_oset_create call.
-
- The implementations are:
- GL_ARRAY_OSET a growable array
- GL_AVLTREE_OSET a binary tree (AVL tree)
- GL_RBTREE_OSET a binary tree (red-black tree)
-
- The memory consumption is asymptotically the same: O(1) for every object
- in the set. When looking more closely at the average memory consumed
- for an object, GL_ARRAY_OSET is the most compact representation, and
- GL_AVLTREE_OSET, GL_RBTREE_OSET need more memory.
-
- The guaranteed average performance of the operations is, for a set of
- n elements:
-
- Operation ARRAY TREE
-
- gl_oset_size O(1) O(1)
- gl_oset_add O(n) O(log n)
- gl_oset_remove O(n) O(log n)
- gl_oset_search O(log n) O(log n)
- gl_oset_search_atleast O(log n) O(log n)
- gl_oset_iterator O(1) O(log n)
- gl_oset_iterator_next O(1) O(log n)
- */
-
-/* -------------------------- gl_oset_t Data Type -------------------------- */
-
-/* Type of function used to compare two elements. Same as for qsort().
- NULL denotes pointer comparison. */
-typedef int (*gl_setelement_compar_fn) (const void *elt1, const void *elt2);
-
-/* Type of function used to dispose an element once it's removed from a set.
- NULL denotes a no-op. */
-typedef void (*gl_setelement_dispose_fn) (const void *elt);
-
-/* Type of function used to compare an element with a threshold.
- Return true if the element is greater or equal than the threshold. */
-typedef bool (*gl_setelement_threshold_fn) (const void *elt, const void *threshold);
-
-struct gl_oset_impl;
-/* Type representing an entire ordered set. */
-typedef struct gl_oset_impl * gl_oset_t;
-
-struct gl_oset_implementation;
-/* Type representing a ordered set datatype implementation. */
-typedef const struct gl_oset_implementation * gl_oset_implementation_t;
-
-#if 0 /* Unless otherwise specified, these are defined inline below. */
-
-/* Create an empty set.
- IMPLEMENTATION is one of GL_ARRAY_OSET, GL_AVLTREE_OSET, GL_RBTREE_OSET.
- COMPAR_FN is an element comparison function or NULL.
- DISPOSE_FN is an element disposal function or NULL. */
-/* declared in gl_xoset.h */
-extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
- gl_setelement_compar_fn compar_fn,
- gl_setelement_dispose_fn dispose_fn);
-/* Likewise. Return NULL upon out-of-memory. */
-extern gl_oset_t gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
- gl_setelement_compar_fn compar_fn,
- gl_setelement_dispose_fn dispose_fn);
-
-/* Return the current number of elements in an ordered set. */
-extern size_t gl_oset_size (gl_oset_t set);
-
-/* Search whether an element is already in the ordered set.
- Return true if found, or false if not present in the set. */
-extern bool gl_oset_search (gl_oset_t set, const void *elt);
-
-/* Search the least element in the ordered set that compares greater or equal
- to the given THRESHOLD. The representation of the THRESHOLD is defined
- by the THRESHOLD_FN.
- Return true and store the found element in *ELTP if found, otherwise return
- false. */
-extern bool gl_oset_search_atleast (gl_oset_t set,
- gl_setelement_threshold_fn threshold_fn,
- const void *threshold,
- const void **eltp);
-
-/* Add an element to an ordered set.
- Return true if it was not already in the set and added, false otherwise. */
-/* declared in gl_xoset.h */
-extern bool gl_oset_add (gl_oset_t set, const void *elt);
-/* Likewise. Return -1 upon out-of-memory. */
-extern int gl_oset_nx_add (gl_oset_t set, const void *elt)
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
- ;
-
-/* Remove an element from an ordered set.
- Return true if it was found and removed. */
-extern bool gl_oset_remove (gl_oset_t set, const void *elt);
-
-/* Free an entire ordered set.
- (But this call does not free the elements of the set.) */
-extern void gl_oset_free (gl_oset_t set);
-
-#endif /* End of inline and gl_xlist.h-defined functions. */
-
-/* --------------------- gl_oset_iterator_t Data Type --------------------- */
-
-/* Functions for iterating through an ordered set. */
-
-/* Type of an iterator that traverses an ordered set.
- This is a fixed-size struct, so that creation of an iterator doesn't need
- memory allocation on the heap. */
-typedef struct
-{
- /* For fast dispatch of gl_oset_iterator_next. */
- const struct gl_oset_implementation *vtable;
- /* For detecting whether the last returned element was removed. */
- gl_oset_t set;
- size_t count;
- /* Other, implementation-private fields. */
- void *p; void *q;
- size_t i; size_t j;
-} gl_oset_iterator_t;
-
-#if 0 /* These are defined inline below. */
-
-/* Create an iterator traversing an ordered set.
- The set's contents must not be modified while the iterator is in use,
- except for removing the last returned element. */
-extern gl_oset_iterator_t gl_oset_iterator (gl_oset_t set);
-
-/* If there is a next element, store the next element in *ELTP, advance the
- iterator and return true. Otherwise, return false. */
-extern bool gl_oset_iterator_next (gl_oset_iterator_t *iterator,
- const void **eltp);
-
-/* Free an iterator. */
-extern void gl_oset_iterator_free (gl_oset_iterator_t *iterator);
-
-#endif /* End of inline functions. */
-
-/* ------------------------ Implementation Details ------------------------ */
-
-struct gl_oset_implementation
-{
- /* gl_oset_t functions. */
- gl_oset_t (*nx_create_empty) (gl_oset_implementation_t implementation,
- gl_setelement_compar_fn compar_fn,
- gl_setelement_dispose_fn dispose_fn);
- size_t (*size) (gl_oset_t set);
- bool (*search) (gl_oset_t set, const void *elt);
- bool (*search_atleast) (gl_oset_t set,
- gl_setelement_threshold_fn threshold_fn,
- const void *threshold, const void **eltp);
- int (*nx_add) (gl_oset_t set, const void *elt);
- bool (*remove_elt) (gl_oset_t set, const void *elt);
- void (*oset_free) (gl_oset_t set);
- /* gl_oset_iterator_t functions. */
- gl_oset_iterator_t (*iterator) (gl_oset_t set);
- bool (*iterator_next) (gl_oset_iterator_t *iterator, const void **eltp);
- void (*iterator_free) (gl_oset_iterator_t *iterator);
-};
-
-struct gl_oset_impl_base
-{
- const struct gl_oset_implementation *vtable;
- gl_setelement_compar_fn compar_fn;
- gl_setelement_dispose_fn dispose_fn;
-};
-
-/* Define all functions of this file as accesses to the
- struct gl_oset_implementation. */
-
-GL_OSET_INLINE gl_oset_t
-gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
- gl_setelement_compar_fn compar_fn,
- gl_setelement_dispose_fn dispose_fn)
-{
- return implementation->nx_create_empty (implementation, compar_fn,
- dispose_fn);
-}
-
-GL_OSET_INLINE size_t
-gl_oset_size (gl_oset_t set)
-{
- return ((const struct gl_oset_impl_base *) set)->vtable->size (set);
-}
-
-GL_OSET_INLINE bool
-gl_oset_search (gl_oset_t set, const void *elt)
-{
- return ((const struct gl_oset_impl_base *) set)->vtable->search (set, elt);
-}
-
-GL_OSET_INLINE bool
-gl_oset_search_atleast (gl_oset_t set,
- gl_setelement_threshold_fn threshold_fn,
- const void *threshold, const void **eltp)
-{
- return ((const struct gl_oset_impl_base *) set)->vtable
- ->search_atleast (set, threshold_fn, threshold, eltp);
-}
-
-GL_OSET_INLINE int
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- __attribute__ ((__warn_unused_result__))
-#endif
-gl_oset_nx_add (gl_oset_t set, const void *elt)
-{
- return ((const struct gl_oset_impl_base *) set)->vtable->nx_add (set, elt);
-}
-
-GL_OSET_INLINE bool
-gl_oset_remove (gl_oset_t set, const void *elt)
-{
- return ((const struct gl_oset_impl_base *) set)->vtable
- ->remove_elt (set, elt);
-}
-
-GL_OSET_INLINE void
-gl_oset_free (gl_oset_t set)
-{
- ((const struct gl_oset_impl_base *) set)->vtable->oset_free (set);
-}
-
-GL_OSET_INLINE gl_oset_iterator_t
-gl_oset_iterator (gl_oset_t set)
-{
- return ((const struct gl_oset_impl_base *) set)->vtable->iterator (set);
-}
-
-GL_OSET_INLINE bool
-gl_oset_iterator_next (gl_oset_iterator_t *iterator, const void **eltp)
-{
- return iterator->vtable->iterator_next (iterator, eltp);
-}
-
-GL_OSET_INLINE void
-gl_oset_iterator_free (gl_oset_iterator_t *iterator)
-{
- iterator->vtable->iterator_free (iterator);
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-_GL_INLINE_HEADER_END
-
-#endif /* _GL_OSET_H */
+/* Abstract ordered set data type.
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_OSET_H
+#define _GL_OSET_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef GL_OSET_INLINE
+# define GL_OSET_INLINE _GL_INLINE
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* gl_oset is an abstract ordered set data type. It can contain any number
+ of objects ('void *' or 'const void *' pointers) in the order of a given
+ comparator function. Duplicates (in the sense of the comparator) are
+ forbidden.
+
+ There are several implementations of this ordered set datatype, optimized
+ for different operations or for memory. You can start using the simplest
+ ordered set implementation, GL_ARRAY_OSET, and switch to a different
+ implementation later, when you realize which operations are performed
+ the most frequently. The API of the different implementations is exactly
+ the same; when switching to a different implementation, you only have to
+ change the gl_oset_create call.
+
+ The implementations are:
+ GL_ARRAY_OSET a growable array
+ GL_AVLTREE_OSET a binary tree (AVL tree)
+ GL_RBTREE_OSET a binary tree (red-black tree)
+
+ The memory consumption is asymptotically the same: O(1) for every object
+ in the set. When looking more closely at the average memory consumed
+ for an object, GL_ARRAY_OSET is the most compact representation, and
+ GL_AVLTREE_OSET, GL_RBTREE_OSET need more memory.
+
+ The guaranteed average performance of the operations is, for a set of
+ n elements:
+
+ Operation ARRAY TREE
+
+ gl_oset_size O(1) O(1)
+ gl_oset_add O(n) O(log n)
+ gl_oset_remove O(n) O(log n)
+ gl_oset_search O(log n) O(log n)
+ gl_oset_search_atleast O(log n) O(log n)
+ gl_oset_iterator O(1) O(log n)
+ gl_oset_iterator_next O(1) O(log n)
+ */
+
+/* -------------------------- gl_oset_t Data Type -------------------------- */
+
+/* Type of function used to compare two elements. Same as for qsort().
+ NULL denotes pointer comparison. */
+typedef int (*gl_setelement_compar_fn) (const void *elt1, const void *elt2);
+
+/* Type of function used to dispose an element once it's removed from a set.
+ NULL denotes a no-op. */
+typedef void (*gl_setelement_dispose_fn) (const void *elt);
+
+/* Type of function used to compare an element with a threshold.
+ Return true if the element is greater or equal than the threshold. */
+typedef bool (*gl_setelement_threshold_fn) (const void *elt, const void *threshold);
+
+struct gl_oset_impl;
+/* Type representing an entire ordered set. */
+typedef struct gl_oset_impl * gl_oset_t;
+
+struct gl_oset_implementation;
+/* Type representing a ordered set datatype implementation. */
+typedef const struct gl_oset_implementation * gl_oset_implementation_t;
+
+#if 0 /* Unless otherwise specified, these are defined inline below. */
+
+/* Create an empty set.
+ IMPLEMENTATION is one of GL_ARRAY_OSET, GL_AVLTREE_OSET, GL_RBTREE_OSET.
+ COMPAR_FN is an element comparison function or NULL.
+ DISPOSE_FN is an element disposal function or NULL. */
+/* declared in gl_xoset.h */
+extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
+ gl_setelement_compar_fn compar_fn,
+ gl_setelement_dispose_fn dispose_fn);
+/* Likewise. Return NULL upon out-of-memory. */
+extern gl_oset_t gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
+ gl_setelement_compar_fn compar_fn,
+ gl_setelement_dispose_fn dispose_fn);
+
+/* Return the current number of elements in an ordered set. */
+extern size_t gl_oset_size (gl_oset_t set);
+
+/* Search whether an element is already in the ordered set.
+ Return true if found, or false if not present in the set. */
+extern bool gl_oset_search (gl_oset_t set, const void *elt);
+
+/* Search the least element in the ordered set that compares greater or equal
+ to the given THRESHOLD. The representation of the THRESHOLD is defined
+ by the THRESHOLD_FN.
+ Return true and store the found element in *ELTP if found, otherwise return
+ false. */
+extern bool gl_oset_search_atleast (gl_oset_t set,
+ gl_setelement_threshold_fn threshold_fn,
+ const void *threshold,
+ const void **eltp);
+
+/* Add an element to an ordered set.
+ Return true if it was not already in the set and added, false otherwise. */
+/* declared in gl_xoset.h */
+extern bool gl_oset_add (gl_oset_t set, const void *elt);
+/* Likewise. Return -1 upon out-of-memory. */
+extern int gl_oset_nx_add (gl_oset_t set, const void *elt)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+ ;
+
+/* Remove an element from an ordered set.
+ Return true if it was found and removed. */
+extern bool gl_oset_remove (gl_oset_t set, const void *elt);
+
+/* Free an entire ordered set.
+ (But this call does not free the elements of the set.) */
+extern void gl_oset_free (gl_oset_t set);
+
+#endif /* End of inline and gl_xlist.h-defined functions. */
+
+/* --------------------- gl_oset_iterator_t Data Type --------------------- */
+
+/* Functions for iterating through an ordered set. */
+
+/* Type of an iterator that traverses an ordered set.
+ This is a fixed-size struct, so that creation of an iterator doesn't need
+ memory allocation on the heap. */
+typedef struct
+{
+ /* For fast dispatch of gl_oset_iterator_next. */
+ const struct gl_oset_implementation *vtable;
+ /* For detecting whether the last returned element was removed. */
+ gl_oset_t set;
+ size_t count;
+ /* Other, implementation-private fields. */
+ void *p; void *q;
+ size_t i; size_t j;
+} gl_oset_iterator_t;
+
+#if 0 /* These are defined inline below. */
+
+/* Create an iterator traversing an ordered set.
+ The set's contents must not be modified while the iterator is in use,
+ except for removing the last returned element. */
+extern gl_oset_iterator_t gl_oset_iterator (gl_oset_t set);
+
+/* If there is a next element, store the next element in *ELTP, advance the
+ iterator and return true. Otherwise, return false. */
+extern bool gl_oset_iterator_next (gl_oset_iterator_t *iterator,
+ const void **eltp);
+
+/* Free an iterator. */
+extern void gl_oset_iterator_free (gl_oset_iterator_t *iterator);
+
+#endif /* End of inline functions. */
+
+/* ------------------------ Implementation Details ------------------------ */
+
+struct gl_oset_implementation
+{
+ /* gl_oset_t functions. */
+ gl_oset_t (*nx_create_empty) (gl_oset_implementation_t implementation,
+ gl_setelement_compar_fn compar_fn,
+ gl_setelement_dispose_fn dispose_fn);
+ size_t (*size) (gl_oset_t set);
+ bool (*search) (gl_oset_t set, const void *elt);
+ bool (*search_atleast) (gl_oset_t set,
+ gl_setelement_threshold_fn threshold_fn,
+ const void *threshold, const void **eltp);
+ int (*nx_add) (gl_oset_t set, const void *elt);
+ bool (*remove_elt) (gl_oset_t set, const void *elt);
+ void (*oset_free) (gl_oset_t set);
+ /* gl_oset_iterator_t functions. */
+ gl_oset_iterator_t (*iterator) (gl_oset_t set);
+ bool (*iterator_next) (gl_oset_iterator_t *iterator, const void **eltp);
+ void (*iterator_free) (gl_oset_iterator_t *iterator);
+};
+
+struct gl_oset_impl_base
+{
+ const struct gl_oset_implementation *vtable;
+ gl_setelement_compar_fn compar_fn;
+ gl_setelement_dispose_fn dispose_fn;
+};
+
+/* Define all functions of this file as accesses to the
+ struct gl_oset_implementation. */
+
+GL_OSET_INLINE gl_oset_t
+gl_oset_nx_create_empty (gl_oset_implementation_t implementation,
+ gl_setelement_compar_fn compar_fn,
+ gl_setelement_dispose_fn dispose_fn)
+{
+ return implementation->nx_create_empty (implementation, compar_fn,
+ dispose_fn);
+}
+
+GL_OSET_INLINE size_t
+gl_oset_size (gl_oset_t set)
+{
+ return ((const struct gl_oset_impl_base *) set)->vtable->size (set);
+}
+
+GL_OSET_INLINE bool
+gl_oset_search (gl_oset_t set, const void *elt)
+{
+ return ((const struct gl_oset_impl_base *) set)->vtable->search (set, elt);
+}
+
+GL_OSET_INLINE bool
+gl_oset_search_atleast (gl_oset_t set,
+ gl_setelement_threshold_fn threshold_fn,
+ const void *threshold, const void **eltp)
+{
+ return ((const struct gl_oset_impl_base *) set)->vtable
+ ->search_atleast (set, threshold_fn, threshold, eltp);
+}
+
+GL_OSET_INLINE int
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ __attribute__ ((__warn_unused_result__))
+#endif
+gl_oset_nx_add (gl_oset_t set, const void *elt)
+{
+ return ((const struct gl_oset_impl_base *) set)->vtable->nx_add (set, elt);
+}
+
+GL_OSET_INLINE bool
+gl_oset_remove (gl_oset_t set, const void *elt)
+{
+ return ((const struct gl_oset_impl_base *) set)->vtable
+ ->remove_elt (set, elt);
+}
+
+GL_OSET_INLINE void
+gl_oset_free (gl_oset_t set)
+{
+ ((const struct gl_oset_impl_base *) set)->vtable->oset_free (set);
+}
+
+GL_OSET_INLINE gl_oset_iterator_t
+gl_oset_iterator (gl_oset_t set)
+{
+ return ((const struct gl_oset_impl_base *) set)->vtable->iterator (set);
+}
+
+GL_OSET_INLINE bool
+gl_oset_iterator_next (gl_oset_iterator_t *iterator, const void **eltp)
+{
+ return iterator->vtable->iterator_next (iterator, eltp);
+}
+
+GL_OSET_INLINE void
+gl_oset_iterator_free (gl_oset_iterator_t *iterator)
+{
+ iterator->vtable->iterator_free (iterator);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif /* _GL_OSET_H */
diff --git a/contrib/tools/bison/gnulib/src/gl_xlist.c b/contrib/tools/bison/gnulib/src/gl_xlist.c
index fe3c893396..ae4545a091 100644
--- a/contrib/tools/bison/gnulib/src/gl_xlist.c
+++ b/contrib/tools/bison/gnulib/src/gl_xlist.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define GL_XLIST_INLINE _GL_EXTERN_INLINE
-#include "gl_xlist.h"
+#include <config.h>
+#define GL_XLIST_INLINE _GL_EXTERN_INLINE
+#include "gl_xlist.h"
diff --git a/contrib/tools/bison/gnulib/src/gl_xlist.h b/contrib/tools/bison/gnulib/src/gl_xlist.h
index 1c9451c1ab..c4500a858f 100644
--- a/contrib/tools/bison/gnulib/src/gl_xlist.h
+++ b/contrib/tools/bison/gnulib/src/gl_xlist.h
@@ -1,177 +1,177 @@
-/* Abstract sequential list data type, with out-of-memory checking.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2009.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_XLIST_H
-#define _GL_XLIST_H
-
-#include "gl_list.h"
-#include "xalloc.h"
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef GL_XLIST_INLINE
-# define GL_XLIST_INLINE _GL_INLINE
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* These functions are thin wrappers around the corresponding functions with
- _nx_ infix from gl_list.h. Upon out-of-memory, they invoke xalloc_die (),
- instead of returning an error indicator. */
-#if 0 /* These are defined inline below. */
-extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates);
-extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates,
- size_t count, const void **contents);
-extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
- const void *elt);
-extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
- const void *elt);
-extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
-extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
-extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
- const void *elt);
-extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
- const void *elt);
-extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
- const void *elt);
-extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
- gl_listelement_compar_fn compar,
- const void *elt);
-#endif
-
-GL_XLIST_INLINE gl_list_t
-gl_list_create_empty (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates)
-{
- gl_list_t result =
- gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
- allow_duplicates);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE gl_list_t
-gl_list_create (gl_list_implementation_t implementation,
- gl_listelement_equals_fn equals_fn,
- gl_listelement_hashcode_fn hashcode_fn,
- gl_listelement_dispose_fn dispose_fn,
- bool allow_duplicates,
- size_t count, const void **contents)
-{
- gl_list_t result =
- gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
- allow_duplicates, count, contents);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE void
-gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
-{
- int result = gl_list_node_nx_set_value (list, node, elt);
- if (result < 0)
- xalloc_die ();
-}
-
-GL_XLIST_INLINE gl_list_node_t
-gl_list_set_at (gl_list_t list, size_t position, const void *elt)
-{
- gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE gl_list_node_t
-gl_list_add_first (gl_list_t list, const void *elt)
-{
- gl_list_node_t result = gl_list_nx_add_first (list, elt);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE gl_list_node_t
-gl_list_add_last (gl_list_t list, const void *elt)
-{
- gl_list_node_t result = gl_list_nx_add_last (list, elt);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE gl_list_node_t
-gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
-{
- gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE gl_list_node_t
-gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
-{
- gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE gl_list_node_t
-gl_list_add_at (gl_list_t list, size_t position, const void *elt)
-{
- gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XLIST_INLINE gl_list_node_t
-gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
- const void *elt)
-{
- gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-_GL_INLINE_HEADER_END
-
-#endif /* _GL_XLIST_H */
+/* Abstract sequential list data type, with out-of-memory checking.
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2009.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_XLIST_H
+#define _GL_XLIST_H
+
+#include "gl_list.h"
+#include "xalloc.h"
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef GL_XLIST_INLINE
+# define GL_XLIST_INLINE _GL_INLINE
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* These functions are thin wrappers around the corresponding functions with
+ _nx_ infix from gl_list.h. Upon out-of-memory, they invoke xalloc_die (),
+ instead of returning an error indicator. */
+#if 0 /* These are defined inline below. */
+extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates);
+extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates,
+ size_t count, const void **contents);
+extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
+ const void *elt);
+extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
+extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
+extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
+ const void *elt);
+extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
+ const void *elt);
+extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
+ gl_listelement_compar_fn compar,
+ const void *elt);
+#endif
+
+GL_XLIST_INLINE gl_list_t
+gl_list_create_empty (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates)
+{
+ gl_list_t result =
+ gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
+ allow_duplicates);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE gl_list_t
+gl_list_create (gl_list_implementation_t implementation,
+ gl_listelement_equals_fn equals_fn,
+ gl_listelement_hashcode_fn hashcode_fn,
+ gl_listelement_dispose_fn dispose_fn,
+ bool allow_duplicates,
+ size_t count, const void **contents)
+{
+ gl_list_t result =
+ gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
+ allow_duplicates, count, contents);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE void
+gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
+{
+ int result = gl_list_node_nx_set_value (list, node, elt);
+ if (result < 0)
+ xalloc_die ();
+}
+
+GL_XLIST_INLINE gl_list_node_t
+gl_list_set_at (gl_list_t list, size_t position, const void *elt)
+{
+ gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE gl_list_node_t
+gl_list_add_first (gl_list_t list, const void *elt)
+{
+ gl_list_node_t result = gl_list_nx_add_first (list, elt);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE gl_list_node_t
+gl_list_add_last (gl_list_t list, const void *elt)
+{
+ gl_list_node_t result = gl_list_nx_add_last (list, elt);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE gl_list_node_t
+gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
+{
+ gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE gl_list_node_t
+gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
+{
+ gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE gl_list_node_t
+gl_list_add_at (gl_list_t list, size_t position, const void *elt)
+{
+ gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XLIST_INLINE gl_list_node_t
+gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
+ const void *elt)
+{
+ gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif /* _GL_XLIST_H */
diff --git a/contrib/tools/bison/gnulib/src/gl_xoset.c b/contrib/tools/bison/gnulib/src/gl_xoset.c
index 6b05d94996..50d77d1a58 100644
--- a/contrib/tools/bison/gnulib/src/gl_xoset.c
+++ b/contrib/tools/bison/gnulib/src/gl_xoset.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define GL_XOSET_INLINE _GL_EXTERN_INLINE
-#include "gl_xoset.h"
+#include <config.h>
+#define GL_XOSET_INLINE _GL_EXTERN_INLINE
+#include "gl_xoset.h"
diff --git a/contrib/tools/bison/gnulib/src/gl_xoset.h b/contrib/tools/bison/gnulib/src/gl_xoset.h
index b30b2ced83..04522cd495 100644
--- a/contrib/tools/bison/gnulib/src/gl_xoset.h
+++ b/contrib/tools/bison/gnulib/src/gl_xoset.h
@@ -1,74 +1,74 @@
-/* Abstract ordered set data type, with out-of-memory checking.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2009.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_XOSET_H
-#define _GL_XOSET_H
-
-#include "gl_oset.h"
-#include "xalloc.h"
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef GL_XOSET_INLINE
-# define GL_XOSET_INLINE _GL_INLINE
-#endif
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* These functions are thin wrappers around the corresponding functions with
- _nx_ infix from gl_oset.h. Upon out-of-memory, they invoke xalloc_die (),
- instead of returning an error indicator. */
-#if 0 /* These are defined inline below. */
-extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
- gl_setelement_compar_fn compar_fn,
- gl_setelement_dispose_fn dispose_fn);
-extern bool gl_oset_add (gl_oset_t set, const void *elt);
-#endif
-
-GL_XOSET_INLINE gl_oset_t
-gl_oset_create_empty (gl_oset_implementation_t implementation,
- gl_setelement_compar_fn compar_fn,
- gl_setelement_dispose_fn dispose_fn)
-{
- gl_oset_t result =
- gl_oset_nx_create_empty (implementation, compar_fn, dispose_fn);
- if (result == NULL)
- xalloc_die ();
- return result;
-}
-
-GL_XOSET_INLINE bool
-gl_oset_add (gl_oset_t set, const void *elt)
-{
- int result = gl_oset_nx_add (set, elt);
- if (result < 0)
- xalloc_die ();
- return result;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-_GL_INLINE_HEADER_END
-
-#endif /* _GL_XOSET_H */
+/* Abstract ordered set data type, with out-of-memory checking.
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2009.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_XOSET_H
+#define _GL_XOSET_H
+
+#include "gl_oset.h"
+#include "xalloc.h"
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef GL_XOSET_INLINE
+# define GL_XOSET_INLINE _GL_INLINE
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* These functions are thin wrappers around the corresponding functions with
+ _nx_ infix from gl_oset.h. Upon out-of-memory, they invoke xalloc_die (),
+ instead of returning an error indicator. */
+#if 0 /* These are defined inline below. */
+extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
+ gl_setelement_compar_fn compar_fn,
+ gl_setelement_dispose_fn dispose_fn);
+extern bool gl_oset_add (gl_oset_t set, const void *elt);
+#endif
+
+GL_XOSET_INLINE gl_oset_t
+gl_oset_create_empty (gl_oset_implementation_t implementation,
+ gl_setelement_compar_fn compar_fn,
+ gl_setelement_dispose_fn dispose_fn)
+{
+ gl_oset_t result =
+ gl_oset_nx_create_empty (implementation, compar_fn, dispose_fn);
+ if (result == NULL)
+ xalloc_die ();
+ return result;
+}
+
+GL_XOSET_INLINE bool
+gl_oset_add (gl_oset_t set, const void *elt)
+{
+ int result = gl_oset_nx_add (set, elt);
+ if (result < 0)
+ xalloc_die ();
+ return result;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif /* _GL_XOSET_H */
diff --git a/contrib/tools/bison/gnulib/src/glthread/lock.c b/contrib/tools/bison/gnulib/src/glthread/lock.c
index f62aa301fe..6acfb8b1d0 100644
--- a/contrib/tools/bison/gnulib/src/glthread/lock.c
+++ b/contrib/tools/bison/gnulib/src/glthread/lock.c
@@ -1,1057 +1,1057 @@
-/* Locking in multithreaded situations.
- Copyright (C) 2005-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2005.
- Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
- gthr-win32.h. */
-
-#include <config.h>
-
-#include "glthread/lock.h"
-
-/* ========================================================================= */
-
-#if USE_POSIX_THREADS
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-# if HAVE_PTHREAD_RWLOCK
-
-# if !defined PTHREAD_RWLOCK_INITIALIZER
-
-int
-glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
-{
- int err;
-
- err = pthread_rwlock_init (&lock->rwlock, NULL);
- if (err != 0)
- return err;
- lock->initialized = 1;
- return 0;
-}
-
-int
-glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
-{
- if (!lock->initialized)
- {
- int err;
-
- err = pthread_mutex_lock (&lock->guard);
- if (err != 0)
- return err;
- if (!lock->initialized)
- {
- err = glthread_rwlock_init_multithreaded (lock);
- if (err != 0)
- {
- pthread_mutex_unlock (&lock->guard);
- return err;
- }
- }
- err = pthread_mutex_unlock (&lock->guard);
- if (err != 0)
- return err;
- }
- return pthread_rwlock_rdlock (&lock->rwlock);
-}
-
-int
-glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
-{
- if (!lock->initialized)
- {
- int err;
-
- err = pthread_mutex_lock (&lock->guard);
- if (err != 0)
- return err;
- if (!lock->initialized)
- {
- err = glthread_rwlock_init_multithreaded (lock);
- if (err != 0)
- {
- pthread_mutex_unlock (&lock->guard);
- return err;
- }
- }
- err = pthread_mutex_unlock (&lock->guard);
- if (err != 0)
- return err;
- }
- return pthread_rwlock_wrlock (&lock->rwlock);
-}
-
-int
-glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
-{
- if (!lock->initialized)
- return EINVAL;
- return pthread_rwlock_unlock (&lock->rwlock);
-}
-
-int
-glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
-{
- int err;
-
- if (!lock->initialized)
- return EINVAL;
- err = pthread_rwlock_destroy (&lock->rwlock);
- if (err != 0)
- return err;
- lock->initialized = 0;
- return 0;
-}
-
-# endif
-
-# else
-
-int
-glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
-{
- int err;
-
- err = pthread_mutex_init (&lock->lock, NULL);
- if (err != 0)
- return err;
- err = pthread_cond_init (&lock->waiting_readers, NULL);
- if (err != 0)
- return err;
- err = pthread_cond_init (&lock->waiting_writers, NULL);
- if (err != 0)
- return err;
- lock->waiting_writers_count = 0;
- lock->runcount = 0;
- return 0;
-}
-
-int
-glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
-{
- int err;
-
- err = pthread_mutex_lock (&lock->lock);
- if (err != 0)
- return err;
- /* Test whether only readers are currently running, and whether the runcount
- field will not overflow. */
- /* POSIX says: "It is implementation-defined whether the calling thread
- acquires the lock when a writer does not hold the lock and there are
- writers blocked on the lock." Let's say, no: give the writers a higher
- priority. */
- while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0))
- {
- /* This thread has to wait for a while. Enqueue it among the
- waiting_readers. */
- err = pthread_cond_wait (&lock->waiting_readers, &lock->lock);
- if (err != 0)
- {
- pthread_mutex_unlock (&lock->lock);
- return err;
- }
- }
- lock->runcount++;
- return pthread_mutex_unlock (&lock->lock);
-}
-
-int
-glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
-{
- int err;
-
- err = pthread_mutex_lock (&lock->lock);
- if (err != 0)
- return err;
- /* Test whether no readers or writers are currently running. */
- while (!(lock->runcount == 0))
- {
- /* This thread has to wait for a while. Enqueue it among the
- waiting_writers. */
- lock->waiting_writers_count++;
- err = pthread_cond_wait (&lock->waiting_writers, &lock->lock);
- if (err != 0)
- {
- lock->waiting_writers_count--;
- pthread_mutex_unlock (&lock->lock);
- return err;
- }
- lock->waiting_writers_count--;
- }
- lock->runcount--; /* runcount becomes -1 */
- return pthread_mutex_unlock (&lock->lock);
-}
-
-int
-glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
-{
- int err;
-
- err = pthread_mutex_lock (&lock->lock);
- if (err != 0)
- return err;
- if (lock->runcount < 0)
- {
- /* Drop a writer lock. */
- if (!(lock->runcount == -1))
- {
- pthread_mutex_unlock (&lock->lock);
- return EINVAL;
- }
- lock->runcount = 0;
- }
- else
- {
- /* Drop a reader lock. */
- if (!(lock->runcount > 0))
- {
- pthread_mutex_unlock (&lock->lock);
- return EINVAL;
- }
- lock->runcount--;
- }
- if (lock->runcount == 0)
- {
- /* POSIX recommends that "write locks shall take precedence over read
- locks", to avoid "writer starvation". */
- if (lock->waiting_writers_count > 0)
- {
- /* Wake up one of the waiting writers. */
- err = pthread_cond_signal (&lock->waiting_writers);
- if (err != 0)
- {
- pthread_mutex_unlock (&lock->lock);
- return err;
- }
- }
- else
- {
- /* Wake up all waiting readers. */
- err = pthread_cond_broadcast (&lock->waiting_readers);
- if (err != 0)
- {
- pthread_mutex_unlock (&lock->lock);
- return err;
- }
- }
- }
- return pthread_mutex_unlock (&lock->lock);
-}
-
-int
-glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
-{
- int err;
-
- err = pthread_mutex_destroy (&lock->lock);
- if (err != 0)
- return err;
- err = pthread_cond_destroy (&lock->waiting_readers);
- if (err != 0)
- return err;
- err = pthread_cond_destroy (&lock->waiting_writers);
- if (err != 0)
- return err;
- return 0;
-}
-
-# endif
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-# if HAVE_PTHREAD_MUTEX_RECURSIVE
-
-# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-
-int
-glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
-{
- pthread_mutexattr_t attributes;
- int err;
-
- err = pthread_mutexattr_init (&attributes);
- if (err != 0)
- return err;
- err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
- if (err != 0)
- {
- pthread_mutexattr_destroy (&attributes);
- return err;
- }
- err = pthread_mutex_init (lock, &attributes);
- if (err != 0)
- {
- pthread_mutexattr_destroy (&attributes);
- return err;
- }
- err = pthread_mutexattr_destroy (&attributes);
- if (err != 0)
- return err;
- return 0;
-}
-
-# else
-
-int
-glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
-{
- pthread_mutexattr_t attributes;
- int err;
-
- err = pthread_mutexattr_init (&attributes);
- if (err != 0)
- return err;
- err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
- if (err != 0)
- {
- pthread_mutexattr_destroy (&attributes);
- return err;
- }
- err = pthread_mutex_init (&lock->recmutex, &attributes);
- if (err != 0)
- {
- pthread_mutexattr_destroy (&attributes);
- return err;
- }
- err = pthread_mutexattr_destroy (&attributes);
- if (err != 0)
- return err;
- lock->initialized = 1;
- return 0;
-}
-
-int
-glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
-{
- if (!lock->initialized)
- {
- int err;
-
- err = pthread_mutex_lock (&lock->guard);
- if (err != 0)
- return err;
- if (!lock->initialized)
- {
- err = glthread_recursive_lock_init_multithreaded (lock);
- if (err != 0)
- {
- pthread_mutex_unlock (&lock->guard);
- return err;
- }
- }
- err = pthread_mutex_unlock (&lock->guard);
- if (err != 0)
- return err;
- }
- return pthread_mutex_lock (&lock->recmutex);
-}
-
-int
-glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
-{
- if (!lock->initialized)
- return EINVAL;
- return pthread_mutex_unlock (&lock->recmutex);
-}
-
-int
-glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
-{
- int err;
-
- if (!lock->initialized)
- return EINVAL;
- err = pthread_mutex_destroy (&lock->recmutex);
- if (err != 0)
- return err;
- lock->initialized = 0;
- return 0;
-}
-
-# endif
-
-# else
-
-int
-glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
-{
- int err;
-
- err = pthread_mutex_init (&lock->mutex, NULL);
- if (err != 0)
- return err;
- lock->owner = (pthread_t) 0;
- lock->depth = 0;
- return 0;
-}
-
-int
-glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
-{
- pthread_t self = pthread_self ();
- if (lock->owner != self)
- {
- int err;
-
- err = pthread_mutex_lock (&lock->mutex);
- if (err != 0)
- return err;
- lock->owner = self;
- }
- if (++(lock->depth) == 0) /* wraparound? */
- {
- lock->depth--;
- return EAGAIN;
- }
- return 0;
-}
-
-int
-glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
-{
- if (lock->owner != pthread_self ())
- return EPERM;
- if (lock->depth == 0)
- return EINVAL;
- if (--(lock->depth) == 0)
- {
- lock->owner = (pthread_t) 0;
- return pthread_mutex_unlock (&lock->mutex);
- }
- else
- return 0;
-}
-
-int
-glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
-{
- if (lock->owner != (pthread_t) 0)
- return EBUSY;
- return pthread_mutex_destroy (&lock->mutex);
-}
-
-# endif
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT;
-
-int
-glthread_once_singlethreaded (pthread_once_t *once_control)
-{
- /* We don't know whether pthread_once_t is an integer type, a floating-point
- type, a pointer type, or a structure type. */
- char *firstbyte = (char *)once_control;
- if (*firstbyte == *(const char *)&fresh_once)
- {
- /* First time use of once_control. Invert the first byte. */
- *firstbyte = ~ *(const char *)&fresh_once;
- return 1;
- }
- else
- return 0;
-}
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_PTH_THREADS
-
-/* Use the GNU Pth threads library. */
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-static void
-glthread_once_call (void *arg)
-{
- void (**gl_once_temp_addr) (void) = (void (**) (void)) arg;
- void (*initfunction) (void) = *gl_once_temp_addr;
- initfunction ();
-}
-
-int
-glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void))
-{
- void (*temp) (void) = initfunction;
- return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0);
-}
-
-int
-glthread_once_singlethreaded (pth_once_t *once_control)
-{
- /* We know that pth_once_t is an integer type. */
- if (*once_control == PTH_ONCE_INIT)
- {
- /* First time use of once_control. Invert the marker. */
- *once_control = ~ PTH_ONCE_INIT;
- return 1;
- }
- else
- return 0;
-}
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_SOLARIS_THREADS
-
-/* Use the old Solaris threads library. */
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-int
-glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
-{
- int err;
-
- err = mutex_init (&lock->mutex, USYNC_THREAD, NULL);
- if (err != 0)
- return err;
- lock->owner = (thread_t) 0;
- lock->depth = 0;
- return 0;
-}
-
-int
-glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
-{
- thread_t self = thr_self ();
- if (lock->owner != self)
- {
- int err;
-
- err = mutex_lock (&lock->mutex);
- if (err != 0)
- return err;
- lock->owner = self;
- }
- if (++(lock->depth) == 0) /* wraparound? */
- {
- lock->depth--;
- return EAGAIN;
- }
- return 0;
-}
-
-int
-glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
-{
- if (lock->owner != thr_self ())
- return EPERM;
- if (lock->depth == 0)
- return EINVAL;
- if (--(lock->depth) == 0)
- {
- lock->owner = (thread_t) 0;
- return mutex_unlock (&lock->mutex);
- }
- else
- return 0;
-}
-
-int
-glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
-{
- if (lock->owner != (thread_t) 0)
- return EBUSY;
- return mutex_destroy (&lock->mutex);
-}
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-int
-glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void))
-{
- if (!once_control->inited)
- {
- int err;
-
- /* Use the mutex to guarantee that if another thread is already calling
- the initfunction, this thread waits until it's finished. */
- err = mutex_lock (&once_control->mutex);
- if (err != 0)
- return err;
- if (!once_control->inited)
- {
- once_control->inited = 1;
- initfunction ();
- }
- return mutex_unlock (&once_control->mutex);
- }
- else
- return 0;
-}
-
-int
-glthread_once_singlethreaded (gl_once_t *once_control)
-{
- /* We know that gl_once_t contains an integer type. */
- if (!once_control->inited)
- {
- /* First time use of once_control. Invert the marker. */
- once_control->inited = ~ 0;
- return 1;
- }
- else
- return 0;
-}
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_WINDOWS_THREADS
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-void
-glthread_lock_init_func (gl_lock_t *lock)
-{
- InitializeCriticalSection (&lock->lock);
- lock->guard.done = 1;
-}
-
-int
-glthread_lock_lock_func (gl_lock_t *lock)
-{
- if (!lock->guard.done)
- {
- if (InterlockedIncrement (&lock->guard.started) == 0)
- /* This thread is the first one to need this lock. Initialize it. */
- glthread_lock_init (lock);
- else
- /* Yield the CPU while waiting for another thread to finish
- initializing this lock. */
- while (!lock->guard.done)
- Sleep (0);
- }
- EnterCriticalSection (&lock->lock);
- return 0;
-}
-
-int
-glthread_lock_unlock_func (gl_lock_t *lock)
-{
- if (!lock->guard.done)
- return EINVAL;
- LeaveCriticalSection (&lock->lock);
- return 0;
-}
-
-int
-glthread_lock_destroy_func (gl_lock_t *lock)
-{
- if (!lock->guard.done)
- return EINVAL;
- DeleteCriticalSection (&lock->lock);
- lock->guard.done = 0;
- return 0;
-}
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-/* In this file, the waitqueues are implemented as circular arrays. */
-#define gl_waitqueue_t gl_carray_waitqueue_t
-
-static void
-gl_waitqueue_init (gl_waitqueue_t *wq)
-{
- wq->array = NULL;
- wq->count = 0;
- wq->alloc = 0;
- wq->offset = 0;
-}
-
-/* Enqueues the current thread, represented by an event, in a wait queue.
- Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */
-static HANDLE
-gl_waitqueue_add (gl_waitqueue_t *wq)
-{
- HANDLE event;
- unsigned int index;
-
- if (wq->count == wq->alloc)
- {
- unsigned int new_alloc = 2 * wq->alloc + 1;
- HANDLE *new_array =
- (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE));
- if (new_array == NULL)
- /* No more memory. */
- return INVALID_HANDLE_VALUE;
- /* Now is a good opportunity to rotate the array so that its contents
- starts at offset 0. */
- if (wq->offset > 0)
- {
- unsigned int old_count = wq->count;
- unsigned int old_alloc = wq->alloc;
- unsigned int old_offset = wq->offset;
- unsigned int i;
- if (old_offset + old_count > old_alloc)
- {
- unsigned int limit = old_offset + old_count - old_alloc;
- for (i = 0; i < limit; i++)
- new_array[old_alloc + i] = new_array[i];
- }
- for (i = 0; i < old_count; i++)
- new_array[i] = new_array[old_offset + i];
- wq->offset = 0;
- }
- wq->array = new_array;
- wq->alloc = new_alloc;
- }
- /* Whether the created event is a manual-reset one or an auto-reset one,
- does not matter, since we will wait on it only once. */
- event = CreateEvent (NULL, TRUE, FALSE, NULL);
- if (event == INVALID_HANDLE_VALUE)
- /* No way to allocate an event. */
- return INVALID_HANDLE_VALUE;
- index = wq->offset + wq->count;
- if (index >= wq->alloc)
- index -= wq->alloc;
- wq->array[index] = event;
- wq->count++;
- return event;
-}
-
-/* Notifies the first thread from a wait queue and dequeues it. */
-static void
-gl_waitqueue_notify_first (gl_waitqueue_t *wq)
-{
- SetEvent (wq->array[wq->offset + 0]);
- wq->offset++;
- wq->count--;
- if (wq->count == 0 || wq->offset == wq->alloc)
- wq->offset = 0;
-}
-
-/* Notifies all threads from a wait queue and dequeues them all. */
-static void
-gl_waitqueue_notify_all (gl_waitqueue_t *wq)
-{
- unsigned int i;
-
- for (i = 0; i < wq->count; i++)
- {
- unsigned int index = wq->offset + i;
- if (index >= wq->alloc)
- index -= wq->alloc;
- SetEvent (wq->array[index]);
- }
- wq->count = 0;
- wq->offset = 0;
-}
-
-void
-glthread_rwlock_init_func (gl_rwlock_t *lock)
-{
- InitializeCriticalSection (&lock->lock);
- gl_waitqueue_init (&lock->waiting_readers);
- gl_waitqueue_init (&lock->waiting_writers);
- lock->runcount = 0;
- lock->guard.done = 1;
-}
-
-int
-glthread_rwlock_rdlock_func (gl_rwlock_t *lock)
-{
- if (!lock->guard.done)
- {
- if (InterlockedIncrement (&lock->guard.started) == 0)
- /* This thread is the first one to need this lock. Initialize it. */
- glthread_rwlock_init (lock);
- else
- /* Yield the CPU while waiting for another thread to finish
- initializing this lock. */
- while (!lock->guard.done)
- Sleep (0);
- }
- EnterCriticalSection (&lock->lock);
- /* Test whether only readers are currently running, and whether the runcount
- field will not overflow. */
- if (!(lock->runcount + 1 > 0))
- {
- /* This thread has to wait for a while. Enqueue it among the
- waiting_readers. */
- HANDLE event = gl_waitqueue_add (&lock->waiting_readers);
- if (event != INVALID_HANDLE_VALUE)
- {
- DWORD result;
- LeaveCriticalSection (&lock->lock);
- /* Wait until another thread signals this event. */
- result = WaitForSingleObject (event, INFINITE);
- if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
- abort ();
- CloseHandle (event);
- /* The thread which signalled the event already did the bookkeeping:
- removed us from the waiting_readers, incremented lock->runcount. */
- if (!(lock->runcount > 0))
- abort ();
- return 0;
- }
- else
- {
- /* Allocation failure. Weird. */
- do
- {
- LeaveCriticalSection (&lock->lock);
- Sleep (1);
- EnterCriticalSection (&lock->lock);
- }
- while (!(lock->runcount + 1 > 0));
- }
- }
- lock->runcount++;
- LeaveCriticalSection (&lock->lock);
- return 0;
-}
-
-int
-glthread_rwlock_wrlock_func (gl_rwlock_t *lock)
-{
- if (!lock->guard.done)
- {
- if (InterlockedIncrement (&lock->guard.started) == 0)
- /* This thread is the first one to need this lock. Initialize it. */
- glthread_rwlock_init (lock);
- else
- /* Yield the CPU while waiting for another thread to finish
- initializing this lock. */
- while (!lock->guard.done)
- Sleep (0);
- }
- EnterCriticalSection (&lock->lock);
- /* Test whether no readers or writers are currently running. */
- if (!(lock->runcount == 0))
- {
- /* This thread has to wait for a while. Enqueue it among the
- waiting_writers. */
- HANDLE event = gl_waitqueue_add (&lock->waiting_writers);
- if (event != INVALID_HANDLE_VALUE)
- {
- DWORD result;
- LeaveCriticalSection (&lock->lock);
- /* Wait until another thread signals this event. */
- result = WaitForSingleObject (event, INFINITE);
- if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
- abort ();
- CloseHandle (event);
- /* The thread which signalled the event already did the bookkeeping:
- removed us from the waiting_writers, set lock->runcount = -1. */
- if (!(lock->runcount == -1))
- abort ();
- return 0;
- }
- else
- {
- /* Allocation failure. Weird. */
- do
- {
- LeaveCriticalSection (&lock->lock);
- Sleep (1);
- EnterCriticalSection (&lock->lock);
- }
- while (!(lock->runcount == 0));
- }
- }
- lock->runcount--; /* runcount becomes -1 */
- LeaveCriticalSection (&lock->lock);
- return 0;
-}
-
-int
-glthread_rwlock_unlock_func (gl_rwlock_t *lock)
-{
- if (!lock->guard.done)
- return EINVAL;
- EnterCriticalSection (&lock->lock);
- if (lock->runcount < 0)
- {
- /* Drop a writer lock. */
- if (!(lock->runcount == -1))
- abort ();
- lock->runcount = 0;
- }
- else
- {
- /* Drop a reader lock. */
- if (!(lock->runcount > 0))
- {
- LeaveCriticalSection (&lock->lock);
- return EPERM;
- }
- lock->runcount--;
- }
- if (lock->runcount == 0)
- {
- /* POSIX recommends that "write locks shall take precedence over read
- locks", to avoid "writer starvation". */
- if (lock->waiting_writers.count > 0)
- {
- /* Wake up one of the waiting writers. */
- lock->runcount--;
- gl_waitqueue_notify_first (&lock->waiting_writers);
- }
- else
- {
- /* Wake up all waiting readers. */
- lock->runcount += lock->waiting_readers.count;
- gl_waitqueue_notify_all (&lock->waiting_readers);
- }
- }
- LeaveCriticalSection (&lock->lock);
- return 0;
-}
-
-int
-glthread_rwlock_destroy_func (gl_rwlock_t *lock)
-{
- if (!lock->guard.done)
- return EINVAL;
- if (lock->runcount != 0)
- return EBUSY;
- DeleteCriticalSection (&lock->lock);
- if (lock->waiting_readers.array != NULL)
- free (lock->waiting_readers.array);
- if (lock->waiting_writers.array != NULL)
- free (lock->waiting_writers.array);
- lock->guard.done = 0;
- return 0;
-}
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-void
-glthread_recursive_lock_init_func (gl_recursive_lock_t *lock)
-{
- lock->owner = 0;
- lock->depth = 0;
- InitializeCriticalSection (&lock->lock);
- lock->guard.done = 1;
-}
-
-int
-glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock)
-{
- if (!lock->guard.done)
- {
- if (InterlockedIncrement (&lock->guard.started) == 0)
- /* This thread is the first one to need this lock. Initialize it. */
- glthread_recursive_lock_init (lock);
- else
- /* Yield the CPU while waiting for another thread to finish
- initializing this lock. */
- while (!lock->guard.done)
- Sleep (0);
- }
- {
- DWORD self = GetCurrentThreadId ();
- if (lock->owner != self)
- {
- EnterCriticalSection (&lock->lock);
- lock->owner = self;
- }
- if (++(lock->depth) == 0) /* wraparound? */
- {
- lock->depth--;
- return EAGAIN;
- }
- }
- return 0;
-}
-
-int
-glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock)
-{
- if (lock->owner != GetCurrentThreadId ())
- return EPERM;
- if (lock->depth == 0)
- return EINVAL;
- if (--(lock->depth) == 0)
- {
- lock->owner = 0;
- LeaveCriticalSection (&lock->lock);
- }
- return 0;
-}
-
-int
-glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock)
-{
- if (lock->owner != 0)
- return EBUSY;
- DeleteCriticalSection (&lock->lock);
- lock->guard.done = 0;
- return 0;
-}
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-void
-glthread_once_func (gl_once_t *once_control, void (*initfunction) (void))
-{
- if (once_control->inited <= 0)
- {
- if (InterlockedIncrement (&once_control->started) == 0)
- {
- /* This thread is the first one to come to this once_control. */
- InitializeCriticalSection (&once_control->lock);
- EnterCriticalSection (&once_control->lock);
- once_control->inited = 0;
- initfunction ();
- once_control->inited = 1;
- LeaveCriticalSection (&once_control->lock);
- }
- else
- {
- /* Undo last operation. */
- InterlockedDecrement (&once_control->started);
- /* Some other thread has already started the initialization.
- Yield the CPU while waiting for the other thread to finish
- initializing and taking the lock. */
- while (once_control->inited < 0)
- Sleep (0);
- if (once_control->inited <= 0)
- {
- /* Take the lock. This blocks until the other thread has
- finished calling the initfunction. */
- EnterCriticalSection (&once_control->lock);
- LeaveCriticalSection (&once_control->lock);
- if (!(once_control->inited > 0))
- abort ();
- }
- }
- }
-}
-
-#endif
-
-/* ========================================================================= */
+/* Locking in multithreaded situations.
+ Copyright (C) 2005-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2005.
+ Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+ gthr-win32.h. */
+
+#include <config.h>
+
+#include "glthread/lock.h"
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+# if HAVE_PTHREAD_RWLOCK
+
+# if !defined PTHREAD_RWLOCK_INITIALIZER
+
+int
+glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
+{
+ int err;
+
+ err = pthread_rwlock_init (&lock->rwlock, NULL);
+ if (err != 0)
+ return err;
+ lock->initialized = 1;
+ return 0;
+}
+
+int
+glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
+{
+ if (!lock->initialized)
+ {
+ int err;
+
+ err = pthread_mutex_lock (&lock->guard);
+ if (err != 0)
+ return err;
+ if (!lock->initialized)
+ {
+ err = glthread_rwlock_init_multithreaded (lock);
+ if (err != 0)
+ {
+ pthread_mutex_unlock (&lock->guard);
+ return err;
+ }
+ }
+ err = pthread_mutex_unlock (&lock->guard);
+ if (err != 0)
+ return err;
+ }
+ return pthread_rwlock_rdlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
+{
+ if (!lock->initialized)
+ {
+ int err;
+
+ err = pthread_mutex_lock (&lock->guard);
+ if (err != 0)
+ return err;
+ if (!lock->initialized)
+ {
+ err = glthread_rwlock_init_multithreaded (lock);
+ if (err != 0)
+ {
+ pthread_mutex_unlock (&lock->guard);
+ return err;
+ }
+ }
+ err = pthread_mutex_unlock (&lock->guard);
+ if (err != 0)
+ return err;
+ }
+ return pthread_rwlock_wrlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
+{
+ if (!lock->initialized)
+ return EINVAL;
+ return pthread_rwlock_unlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
+{
+ int err;
+
+ if (!lock->initialized)
+ return EINVAL;
+ err = pthread_rwlock_destroy (&lock->rwlock);
+ if (err != 0)
+ return err;
+ lock->initialized = 0;
+ return 0;
+}
+
+# endif
+
+# else
+
+int
+glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
+{
+ int err;
+
+ err = pthread_mutex_init (&lock->lock, NULL);
+ if (err != 0)
+ return err;
+ err = pthread_cond_init (&lock->waiting_readers, NULL);
+ if (err != 0)
+ return err;
+ err = pthread_cond_init (&lock->waiting_writers, NULL);
+ if (err != 0)
+ return err;
+ lock->waiting_writers_count = 0;
+ lock->runcount = 0;
+ return 0;
+}
+
+int
+glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
+{
+ int err;
+
+ err = pthread_mutex_lock (&lock->lock);
+ if (err != 0)
+ return err;
+ /* Test whether only readers are currently running, and whether the runcount
+ field will not overflow. */
+ /* POSIX says: "It is implementation-defined whether the calling thread
+ acquires the lock when a writer does not hold the lock and there are
+ writers blocked on the lock." Let's say, no: give the writers a higher
+ priority. */
+ while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0))
+ {
+ /* This thread has to wait for a while. Enqueue it among the
+ waiting_readers. */
+ err = pthread_cond_wait (&lock->waiting_readers, &lock->lock);
+ if (err != 0)
+ {
+ pthread_mutex_unlock (&lock->lock);
+ return err;
+ }
+ }
+ lock->runcount++;
+ return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
+{
+ int err;
+
+ err = pthread_mutex_lock (&lock->lock);
+ if (err != 0)
+ return err;
+ /* Test whether no readers or writers are currently running. */
+ while (!(lock->runcount == 0))
+ {
+ /* This thread has to wait for a while. Enqueue it among the
+ waiting_writers. */
+ lock->waiting_writers_count++;
+ err = pthread_cond_wait (&lock->waiting_writers, &lock->lock);
+ if (err != 0)
+ {
+ lock->waiting_writers_count--;
+ pthread_mutex_unlock (&lock->lock);
+ return err;
+ }
+ lock->waiting_writers_count--;
+ }
+ lock->runcount--; /* runcount becomes -1 */
+ return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
+{
+ int err;
+
+ err = pthread_mutex_lock (&lock->lock);
+ if (err != 0)
+ return err;
+ if (lock->runcount < 0)
+ {
+ /* Drop a writer lock. */
+ if (!(lock->runcount == -1))
+ {
+ pthread_mutex_unlock (&lock->lock);
+ return EINVAL;
+ }
+ lock->runcount = 0;
+ }
+ else
+ {
+ /* Drop a reader lock. */
+ if (!(lock->runcount > 0))
+ {
+ pthread_mutex_unlock (&lock->lock);
+ return EINVAL;
+ }
+ lock->runcount--;
+ }
+ if (lock->runcount == 0)
+ {
+ /* POSIX recommends that "write locks shall take precedence over read
+ locks", to avoid "writer starvation". */
+ if (lock->waiting_writers_count > 0)
+ {
+ /* Wake up one of the waiting writers. */
+ err = pthread_cond_signal (&lock->waiting_writers);
+ if (err != 0)
+ {
+ pthread_mutex_unlock (&lock->lock);
+ return err;
+ }
+ }
+ else
+ {
+ /* Wake up all waiting readers. */
+ err = pthread_cond_broadcast (&lock->waiting_readers);
+ if (err != 0)
+ {
+ pthread_mutex_unlock (&lock->lock);
+ return err;
+ }
+ }
+ }
+ return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
+{
+ int err;
+
+ err = pthread_mutex_destroy (&lock->lock);
+ if (err != 0)
+ return err;
+ err = pthread_cond_destroy (&lock->waiting_readers);
+ if (err != 0)
+ return err;
+ err = pthread_cond_destroy (&lock->waiting_writers);
+ if (err != 0)
+ return err;
+ return 0;
+}
+
+# endif
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+# if HAVE_PTHREAD_MUTEX_RECURSIVE
+
+# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+ pthread_mutexattr_t attributes;
+ int err;
+
+ err = pthread_mutexattr_init (&attributes);
+ if (err != 0)
+ return err;
+ err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
+ if (err != 0)
+ {
+ pthread_mutexattr_destroy (&attributes);
+ return err;
+ }
+ err = pthread_mutex_init (lock, &attributes);
+ if (err != 0)
+ {
+ pthread_mutexattr_destroy (&attributes);
+ return err;
+ }
+ err = pthread_mutexattr_destroy (&attributes);
+ if (err != 0)
+ return err;
+ return 0;
+}
+
+# else
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+ pthread_mutexattr_t attributes;
+ int err;
+
+ err = pthread_mutexattr_init (&attributes);
+ if (err != 0)
+ return err;
+ err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
+ if (err != 0)
+ {
+ pthread_mutexattr_destroy (&attributes);
+ return err;
+ }
+ err = pthread_mutex_init (&lock->recmutex, &attributes);
+ if (err != 0)
+ {
+ pthread_mutexattr_destroy (&attributes);
+ return err;
+ }
+ err = pthread_mutexattr_destroy (&attributes);
+ if (err != 0)
+ return err;
+ lock->initialized = 1;
+ return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+ if (!lock->initialized)
+ {
+ int err;
+
+ err = pthread_mutex_lock (&lock->guard);
+ if (err != 0)
+ return err;
+ if (!lock->initialized)
+ {
+ err = glthread_recursive_lock_init_multithreaded (lock);
+ if (err != 0)
+ {
+ pthread_mutex_unlock (&lock->guard);
+ return err;
+ }
+ }
+ err = pthread_mutex_unlock (&lock->guard);
+ if (err != 0)
+ return err;
+ }
+ return pthread_mutex_lock (&lock->recmutex);
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+ if (!lock->initialized)
+ return EINVAL;
+ return pthread_mutex_unlock (&lock->recmutex);
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+ int err;
+
+ if (!lock->initialized)
+ return EINVAL;
+ err = pthread_mutex_destroy (&lock->recmutex);
+ if (err != 0)
+ return err;
+ lock->initialized = 0;
+ return 0;
+}
+
+# endif
+
+# else
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+ int err;
+
+ err = pthread_mutex_init (&lock->mutex, NULL);
+ if (err != 0)
+ return err;
+ lock->owner = (pthread_t) 0;
+ lock->depth = 0;
+ return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+ pthread_t self = pthread_self ();
+ if (lock->owner != self)
+ {
+ int err;
+
+ err = pthread_mutex_lock (&lock->mutex);
+ if (err != 0)
+ return err;
+ lock->owner = self;
+ }
+ if (++(lock->depth) == 0) /* wraparound? */
+ {
+ lock->depth--;
+ return EAGAIN;
+ }
+ return 0;
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+ if (lock->owner != pthread_self ())
+ return EPERM;
+ if (lock->depth == 0)
+ return EINVAL;
+ if (--(lock->depth) == 0)
+ {
+ lock->owner = (pthread_t) 0;
+ return pthread_mutex_unlock (&lock->mutex);
+ }
+ else
+ return 0;
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+ if (lock->owner != (pthread_t) 0)
+ return EBUSY;
+ return pthread_mutex_destroy (&lock->mutex);
+}
+
+# endif
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT;
+
+int
+glthread_once_singlethreaded (pthread_once_t *once_control)
+{
+ /* We don't know whether pthread_once_t is an integer type, a floating-point
+ type, a pointer type, or a structure type. */
+ char *firstbyte = (char *)once_control;
+ if (*firstbyte == *(const char *)&fresh_once)
+ {
+ /* First time use of once_control. Invert the first byte. */
+ *firstbyte = ~ *(const char *)&fresh_once;
+ return 1;
+ }
+ else
+ return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library. */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+static void
+glthread_once_call (void *arg)
+{
+ void (**gl_once_temp_addr) (void) = (void (**) (void)) arg;
+ void (*initfunction) (void) = *gl_once_temp_addr;
+ initfunction ();
+}
+
+int
+glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void))
+{
+ void (*temp) (void) = initfunction;
+ return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0);
+}
+
+int
+glthread_once_singlethreaded (pth_once_t *once_control)
+{
+ /* We know that pth_once_t is an integer type. */
+ if (*once_control == PTH_ONCE_INIT)
+ {
+ /* First time use of once_control. Invert the marker. */
+ *once_control = ~ PTH_ONCE_INIT;
+ return 1;
+ }
+ else
+ return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library. */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+ int err;
+
+ err = mutex_init (&lock->mutex, USYNC_THREAD, NULL);
+ if (err != 0)
+ return err;
+ lock->owner = (thread_t) 0;
+ lock->depth = 0;
+ return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+ thread_t self = thr_self ();
+ if (lock->owner != self)
+ {
+ int err;
+
+ err = mutex_lock (&lock->mutex);
+ if (err != 0)
+ return err;
+ lock->owner = self;
+ }
+ if (++(lock->depth) == 0) /* wraparound? */
+ {
+ lock->depth--;
+ return EAGAIN;
+ }
+ return 0;
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+ if (lock->owner != thr_self ())
+ return EPERM;
+ if (lock->depth == 0)
+ return EINVAL;
+ if (--(lock->depth) == 0)
+ {
+ lock->owner = (thread_t) 0;
+ return mutex_unlock (&lock->mutex);
+ }
+ else
+ return 0;
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+ if (lock->owner != (thread_t) 0)
+ return EBUSY;
+ return mutex_destroy (&lock->mutex);
+}
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+int
+glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void))
+{
+ if (!once_control->inited)
+ {
+ int err;
+
+ /* Use the mutex to guarantee that if another thread is already calling
+ the initfunction, this thread waits until it's finished. */
+ err = mutex_lock (&once_control->mutex);
+ if (err != 0)
+ return err;
+ if (!once_control->inited)
+ {
+ once_control->inited = 1;
+ initfunction ();
+ }
+ return mutex_unlock (&once_control->mutex);
+ }
+ else
+ return 0;
+}
+
+int
+glthread_once_singlethreaded (gl_once_t *once_control)
+{
+ /* We know that gl_once_t contains an integer type. */
+ if (!once_control->inited)
+ {
+ /* First time use of once_control. Invert the marker. */
+ once_control->inited = ~ 0;
+ return 1;
+ }
+ else
+ return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WINDOWS_THREADS
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+void
+glthread_lock_init_func (gl_lock_t *lock)
+{
+ InitializeCriticalSection (&lock->lock);
+ lock->guard.done = 1;
+}
+
+int
+glthread_lock_lock_func (gl_lock_t *lock)
+{
+ if (!lock->guard.done)
+ {
+ if (InterlockedIncrement (&lock->guard.started) == 0)
+ /* This thread is the first one to need this lock. Initialize it. */
+ glthread_lock_init (lock);
+ else
+ /* Yield the CPU while waiting for another thread to finish
+ initializing this lock. */
+ while (!lock->guard.done)
+ Sleep (0);
+ }
+ EnterCriticalSection (&lock->lock);
+ return 0;
+}
+
+int
+glthread_lock_unlock_func (gl_lock_t *lock)
+{
+ if (!lock->guard.done)
+ return EINVAL;
+ LeaveCriticalSection (&lock->lock);
+ return 0;
+}
+
+int
+glthread_lock_destroy_func (gl_lock_t *lock)
+{
+ if (!lock->guard.done)
+ return EINVAL;
+ DeleteCriticalSection (&lock->lock);
+ lock->guard.done = 0;
+ return 0;
+}
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* In this file, the waitqueues are implemented as circular arrays. */
+#define gl_waitqueue_t gl_carray_waitqueue_t
+
+static void
+gl_waitqueue_init (gl_waitqueue_t *wq)
+{
+ wq->array = NULL;
+ wq->count = 0;
+ wq->alloc = 0;
+ wq->offset = 0;
+}
+
+/* Enqueues the current thread, represented by an event, in a wait queue.
+ Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */
+static HANDLE
+gl_waitqueue_add (gl_waitqueue_t *wq)
+{
+ HANDLE event;
+ unsigned int index;
+
+ if (wq->count == wq->alloc)
+ {
+ unsigned int new_alloc = 2 * wq->alloc + 1;
+ HANDLE *new_array =
+ (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE));
+ if (new_array == NULL)
+ /* No more memory. */
+ return INVALID_HANDLE_VALUE;
+ /* Now is a good opportunity to rotate the array so that its contents
+ starts at offset 0. */
+ if (wq->offset > 0)
+ {
+ unsigned int old_count = wq->count;
+ unsigned int old_alloc = wq->alloc;
+ unsigned int old_offset = wq->offset;
+ unsigned int i;
+ if (old_offset + old_count > old_alloc)
+ {
+ unsigned int limit = old_offset + old_count - old_alloc;
+ for (i = 0; i < limit; i++)
+ new_array[old_alloc + i] = new_array[i];
+ }
+ for (i = 0; i < old_count; i++)
+ new_array[i] = new_array[old_offset + i];
+ wq->offset = 0;
+ }
+ wq->array = new_array;
+ wq->alloc = new_alloc;
+ }
+ /* Whether the created event is a manual-reset one or an auto-reset one,
+ does not matter, since we will wait on it only once. */
+ event = CreateEvent (NULL, TRUE, FALSE, NULL);
+ if (event == INVALID_HANDLE_VALUE)
+ /* No way to allocate an event. */
+ return INVALID_HANDLE_VALUE;
+ index = wq->offset + wq->count;
+ if (index >= wq->alloc)
+ index -= wq->alloc;
+ wq->array[index] = event;
+ wq->count++;
+ return event;
+}
+
+/* Notifies the first thread from a wait queue and dequeues it. */
+static void
+gl_waitqueue_notify_first (gl_waitqueue_t *wq)
+{
+ SetEvent (wq->array[wq->offset + 0]);
+ wq->offset++;
+ wq->count--;
+ if (wq->count == 0 || wq->offset == wq->alloc)
+ wq->offset = 0;
+}
+
+/* Notifies all threads from a wait queue and dequeues them all. */
+static void
+gl_waitqueue_notify_all (gl_waitqueue_t *wq)
+{
+ unsigned int i;
+
+ for (i = 0; i < wq->count; i++)
+ {
+ unsigned int index = wq->offset + i;
+ if (index >= wq->alloc)
+ index -= wq->alloc;
+ SetEvent (wq->array[index]);
+ }
+ wq->count = 0;
+ wq->offset = 0;
+}
+
+void
+glthread_rwlock_init_func (gl_rwlock_t *lock)
+{
+ InitializeCriticalSection (&lock->lock);
+ gl_waitqueue_init (&lock->waiting_readers);
+ gl_waitqueue_init (&lock->waiting_writers);
+ lock->runcount = 0;
+ lock->guard.done = 1;
+}
+
+int
+glthread_rwlock_rdlock_func (gl_rwlock_t *lock)
+{
+ if (!lock->guard.done)
+ {
+ if (InterlockedIncrement (&lock->guard.started) == 0)
+ /* This thread is the first one to need this lock. Initialize it. */
+ glthread_rwlock_init (lock);
+ else
+ /* Yield the CPU while waiting for another thread to finish
+ initializing this lock. */
+ while (!lock->guard.done)
+ Sleep (0);
+ }
+ EnterCriticalSection (&lock->lock);
+ /* Test whether only readers are currently running, and whether the runcount
+ field will not overflow. */
+ if (!(lock->runcount + 1 > 0))
+ {
+ /* This thread has to wait for a while. Enqueue it among the
+ waiting_readers. */
+ HANDLE event = gl_waitqueue_add (&lock->waiting_readers);
+ if (event != INVALID_HANDLE_VALUE)
+ {
+ DWORD result;
+ LeaveCriticalSection (&lock->lock);
+ /* Wait until another thread signals this event. */
+ result = WaitForSingleObject (event, INFINITE);
+ if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
+ abort ();
+ CloseHandle (event);
+ /* The thread which signalled the event already did the bookkeeping:
+ removed us from the waiting_readers, incremented lock->runcount. */
+ if (!(lock->runcount > 0))
+ abort ();
+ return 0;
+ }
+ else
+ {
+ /* Allocation failure. Weird. */
+ do
+ {
+ LeaveCriticalSection (&lock->lock);
+ Sleep (1);
+ EnterCriticalSection (&lock->lock);
+ }
+ while (!(lock->runcount + 1 > 0));
+ }
+ }
+ lock->runcount++;
+ LeaveCriticalSection (&lock->lock);
+ return 0;
+}
+
+int
+glthread_rwlock_wrlock_func (gl_rwlock_t *lock)
+{
+ if (!lock->guard.done)
+ {
+ if (InterlockedIncrement (&lock->guard.started) == 0)
+ /* This thread is the first one to need this lock. Initialize it. */
+ glthread_rwlock_init (lock);
+ else
+ /* Yield the CPU while waiting for another thread to finish
+ initializing this lock. */
+ while (!lock->guard.done)
+ Sleep (0);
+ }
+ EnterCriticalSection (&lock->lock);
+ /* Test whether no readers or writers are currently running. */
+ if (!(lock->runcount == 0))
+ {
+ /* This thread has to wait for a while. Enqueue it among the
+ waiting_writers. */
+ HANDLE event = gl_waitqueue_add (&lock->waiting_writers);
+ if (event != INVALID_HANDLE_VALUE)
+ {
+ DWORD result;
+ LeaveCriticalSection (&lock->lock);
+ /* Wait until another thread signals this event. */
+ result = WaitForSingleObject (event, INFINITE);
+ if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
+ abort ();
+ CloseHandle (event);
+ /* The thread which signalled the event already did the bookkeeping:
+ removed us from the waiting_writers, set lock->runcount = -1. */
+ if (!(lock->runcount == -1))
+ abort ();
+ return 0;
+ }
+ else
+ {
+ /* Allocation failure. Weird. */
+ do
+ {
+ LeaveCriticalSection (&lock->lock);
+ Sleep (1);
+ EnterCriticalSection (&lock->lock);
+ }
+ while (!(lock->runcount == 0));
+ }
+ }
+ lock->runcount--; /* runcount becomes -1 */
+ LeaveCriticalSection (&lock->lock);
+ return 0;
+}
+
+int
+glthread_rwlock_unlock_func (gl_rwlock_t *lock)
+{
+ if (!lock->guard.done)
+ return EINVAL;
+ EnterCriticalSection (&lock->lock);
+ if (lock->runcount < 0)
+ {
+ /* Drop a writer lock. */
+ if (!(lock->runcount == -1))
+ abort ();
+ lock->runcount = 0;
+ }
+ else
+ {
+ /* Drop a reader lock. */
+ if (!(lock->runcount > 0))
+ {
+ LeaveCriticalSection (&lock->lock);
+ return EPERM;
+ }
+ lock->runcount--;
+ }
+ if (lock->runcount == 0)
+ {
+ /* POSIX recommends that "write locks shall take precedence over read
+ locks", to avoid "writer starvation". */
+ if (lock->waiting_writers.count > 0)
+ {
+ /* Wake up one of the waiting writers. */
+ lock->runcount--;
+ gl_waitqueue_notify_first (&lock->waiting_writers);
+ }
+ else
+ {
+ /* Wake up all waiting readers. */
+ lock->runcount += lock->waiting_readers.count;
+ gl_waitqueue_notify_all (&lock->waiting_readers);
+ }
+ }
+ LeaveCriticalSection (&lock->lock);
+ return 0;
+}
+
+int
+glthread_rwlock_destroy_func (gl_rwlock_t *lock)
+{
+ if (!lock->guard.done)
+ return EINVAL;
+ if (lock->runcount != 0)
+ return EBUSY;
+ DeleteCriticalSection (&lock->lock);
+ if (lock->waiting_readers.array != NULL)
+ free (lock->waiting_readers.array);
+ if (lock->waiting_writers.array != NULL)
+ free (lock->waiting_writers.array);
+ lock->guard.done = 0;
+ return 0;
+}
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+void
+glthread_recursive_lock_init_func (gl_recursive_lock_t *lock)
+{
+ lock->owner = 0;
+ lock->depth = 0;
+ InitializeCriticalSection (&lock->lock);
+ lock->guard.done = 1;
+}
+
+int
+glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock)
+{
+ if (!lock->guard.done)
+ {
+ if (InterlockedIncrement (&lock->guard.started) == 0)
+ /* This thread is the first one to need this lock. Initialize it. */
+ glthread_recursive_lock_init (lock);
+ else
+ /* Yield the CPU while waiting for another thread to finish
+ initializing this lock. */
+ while (!lock->guard.done)
+ Sleep (0);
+ }
+ {
+ DWORD self = GetCurrentThreadId ();
+ if (lock->owner != self)
+ {
+ EnterCriticalSection (&lock->lock);
+ lock->owner = self;
+ }
+ if (++(lock->depth) == 0) /* wraparound? */
+ {
+ lock->depth--;
+ return EAGAIN;
+ }
+ }
+ return 0;
+}
+
+int
+glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock)
+{
+ if (lock->owner != GetCurrentThreadId ())
+ return EPERM;
+ if (lock->depth == 0)
+ return EINVAL;
+ if (--(lock->depth) == 0)
+ {
+ lock->owner = 0;
+ LeaveCriticalSection (&lock->lock);
+ }
+ return 0;
+}
+
+int
+glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock)
+{
+ if (lock->owner != 0)
+ return EBUSY;
+ DeleteCriticalSection (&lock->lock);
+ lock->guard.done = 0;
+ return 0;
+}
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+void
+glthread_once_func (gl_once_t *once_control, void (*initfunction) (void))
+{
+ if (once_control->inited <= 0)
+ {
+ if (InterlockedIncrement (&once_control->started) == 0)
+ {
+ /* This thread is the first one to come to this once_control. */
+ InitializeCriticalSection (&once_control->lock);
+ EnterCriticalSection (&once_control->lock);
+ once_control->inited = 0;
+ initfunction ();
+ once_control->inited = 1;
+ LeaveCriticalSection (&once_control->lock);
+ }
+ else
+ {
+ /* Undo last operation. */
+ InterlockedDecrement (&once_control->started);
+ /* Some other thread has already started the initialization.
+ Yield the CPU while waiting for the other thread to finish
+ initializing and taking the lock. */
+ while (once_control->inited < 0)
+ Sleep (0);
+ if (once_control->inited <= 0)
+ {
+ /* Take the lock. This blocks until the other thread has
+ finished calling the initfunction. */
+ EnterCriticalSection (&once_control->lock);
+ LeaveCriticalSection (&once_control->lock);
+ if (!(once_control->inited > 0))
+ abort ();
+ }
+ }
+ }
+}
+
+#endif
+
+/* ========================================================================= */
diff --git a/contrib/tools/bison/gnulib/src/glthread/lock.h b/contrib/tools/bison/gnulib/src/glthread/lock.h
index d20bbdefdd..4cf912cae0 100644
--- a/contrib/tools/bison/gnulib/src/glthread/lock.h
+++ b/contrib/tools/bison/gnulib/src/glthread/lock.h
@@ -1,927 +1,927 @@
-/* Locking in multithreaded situations.
- Copyright (C) 2005-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2005.
- Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
- gthr-win32.h. */
-
-/* This file contains locking primitives for use with a given thread library.
- It does not contain primitives for creating threads or for other
- synchronization primitives.
-
- Normal (non-recursive) locks:
- Type: gl_lock_t
- Declaration: gl_lock_define(extern, name)
- Initializer: gl_lock_define_initialized(, name)
- Initialization: gl_lock_init (name);
- Taking the lock: gl_lock_lock (name);
- Releasing the lock: gl_lock_unlock (name);
- De-initialization: gl_lock_destroy (name);
- Equivalent functions with control of error handling:
- Initialization: err = glthread_lock_init (&name);
- Taking the lock: err = glthread_lock_lock (&name);
- Releasing the lock: err = glthread_lock_unlock (&name);
- De-initialization: err = glthread_lock_destroy (&name);
-
- Read-Write (non-recursive) locks:
- Type: gl_rwlock_t
- Declaration: gl_rwlock_define(extern, name)
- Initializer: gl_rwlock_define_initialized(, name)
- Initialization: gl_rwlock_init (name);
- Taking the lock: gl_rwlock_rdlock (name);
- gl_rwlock_wrlock (name);
- Releasing the lock: gl_rwlock_unlock (name);
- De-initialization: gl_rwlock_destroy (name);
- Equivalent functions with control of error handling:
- Initialization: err = glthread_rwlock_init (&name);
- Taking the lock: err = glthread_rwlock_rdlock (&name);
- err = glthread_rwlock_wrlock (&name);
- Releasing the lock: err = glthread_rwlock_unlock (&name);
- De-initialization: err = glthread_rwlock_destroy (&name);
-
- Recursive locks:
- Type: gl_recursive_lock_t
- Declaration: gl_recursive_lock_define(extern, name)
- Initializer: gl_recursive_lock_define_initialized(, name)
- Initialization: gl_recursive_lock_init (name);
- Taking the lock: gl_recursive_lock_lock (name);
- Releasing the lock: gl_recursive_lock_unlock (name);
- De-initialization: gl_recursive_lock_destroy (name);
- Equivalent functions with control of error handling:
- Initialization: err = glthread_recursive_lock_init (&name);
- Taking the lock: err = glthread_recursive_lock_lock (&name);
- Releasing the lock: err = glthread_recursive_lock_unlock (&name);
- De-initialization: err = glthread_recursive_lock_destroy (&name);
-
- Once-only execution:
- Type: gl_once_t
- Initializer: gl_once_define(extern, name)
- Execution: gl_once (name, initfunction);
- Equivalent functions with control of error handling:
- Execution: err = glthread_once (&name, initfunction);
-*/
-
-
-#ifndef _LOCK_H
-#define _LOCK_H
-
-#include <errno.h>
-#include <stdlib.h>
-
-/* ========================================================================= */
-
-#if USE_POSIX_THREADS
-
-/* Use the POSIX threads library. */
-
-# include <pthread.h>
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-# if PTHREAD_IN_USE_DETECTION_HARD
-
-/* The pthread_in_use() detection needs to be done at runtime. */
-# define pthread_in_use() \
- glthread_in_use ()
-extern int glthread_in_use (void);
-
-# endif
-
-# if USE_POSIX_THREADS_WEAK
-
-/* Use weak references to the POSIX threads library. */
-
-/* Weak references avoid dragging in external libraries if the other parts
- of the program don't use them. Here we use them, because we don't want
- every program that uses libintl to depend on libpthread. This assumes
- that libpthread would not be loaded after libintl; i.e. if libintl is
- loaded first, by an executable that does not depend on libpthread, and
- then a module is dynamically loaded that depends on libpthread, libintl
- will not be multithread-safe. */
-
-/* The way to test at runtime whether libpthread is present is to test
- whether a function pointer's value, such as &pthread_mutex_init, is
- non-NULL. However, some versions of GCC have a bug through which, in
- PIC mode, &foo != NULL always evaluates to true if there is a direct
- call to foo(...) in the same function. To avoid this, we test the
- address of a function in libpthread that we don't use. */
-
-# pragma weak pthread_mutex_init
-# pragma weak pthread_mutex_lock
-# pragma weak pthread_mutex_unlock
-# pragma weak pthread_mutex_destroy
-# pragma weak pthread_rwlock_init
-# pragma weak pthread_rwlock_rdlock
-# pragma weak pthread_rwlock_wrlock
-# pragma weak pthread_rwlock_unlock
-# pragma weak pthread_rwlock_destroy
-# pragma weak pthread_once
-# pragma weak pthread_cond_init
-# pragma weak pthread_cond_wait
-# pragma weak pthread_cond_signal
-# pragma weak pthread_cond_broadcast
-# pragma weak pthread_cond_destroy
-# pragma weak pthread_mutexattr_init
-# pragma weak pthread_mutexattr_settype
-# pragma weak pthread_mutexattr_destroy
-# ifndef pthread_self
-# pragma weak pthread_self
-# endif
-
-# if !PTHREAD_IN_USE_DETECTION_HARD
-# pragma weak pthread_cancel
-# define pthread_in_use() (pthread_cancel != NULL)
-# endif
-
-# else
-
-# if !PTHREAD_IN_USE_DETECTION_HARD
-# define pthread_in_use() 1
-# endif
-
-# endif
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-typedef pthread_mutex_t gl_lock_t;
-# define gl_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS pthread_mutex_t NAME;
-# define gl_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer;
-# define gl_lock_initializer \
- PTHREAD_MUTEX_INITIALIZER
-# define glthread_lock_init(LOCK) \
- (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0)
-# define glthread_lock_lock(LOCK) \
- (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
-# define glthread_lock_unlock(LOCK) \
- (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
-# define glthread_lock_destroy(LOCK) \
- (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-# if HAVE_PTHREAD_RWLOCK
-
-# ifdef PTHREAD_RWLOCK_INITIALIZER
-
-typedef pthread_rwlock_t gl_rwlock_t;
-# define gl_rwlock_define(STORAGECLASS, NAME) \
- STORAGECLASS pthread_rwlock_t NAME;
-# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer;
-# define gl_rwlock_initializer \
- PTHREAD_RWLOCK_INITIALIZER
-# define glthread_rwlock_init(LOCK) \
- (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0)
-# define glthread_rwlock_rdlock(LOCK) \
- (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0)
-# define glthread_rwlock_wrlock(LOCK) \
- (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0)
-# define glthread_rwlock_unlock(LOCK) \
- (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0)
-# define glthread_rwlock_destroy(LOCK) \
- (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0)
-
-# else
-
-typedef struct
- {
- int initialized;
- pthread_mutex_t guard; /* protects the initialization */
- pthread_rwlock_t rwlock; /* read-write lock */
- }
- gl_rwlock_t;
-# define gl_rwlock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_rwlock_t NAME;
-# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
-# define gl_rwlock_initializer \
- { 0, PTHREAD_MUTEX_INITIALIZER }
-# define glthread_rwlock_init(LOCK) \
- (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
-# define glthread_rwlock_rdlock(LOCK) \
- (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
-# define glthread_rwlock_wrlock(LOCK) \
- (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
-# define glthread_rwlock_unlock(LOCK) \
- (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
-# define glthread_rwlock_destroy(LOCK) \
- (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
-extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
-
-# endif
-
-# else
-
-typedef struct
- {
- pthread_mutex_t lock; /* protects the remaining fields */
- pthread_cond_t waiting_readers; /* waiting readers */
- pthread_cond_t waiting_writers; /* waiting writers */
- unsigned int waiting_writers_count; /* number of waiting writers */
- int runcount; /* number of readers running, or -1 when a writer runs */
- }
- gl_rwlock_t;
-# define gl_rwlock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_rwlock_t NAME;
-# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
-# define gl_rwlock_initializer \
- { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 }
-# define glthread_rwlock_init(LOCK) \
- (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
-# define glthread_rwlock_rdlock(LOCK) \
- (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
-# define glthread_rwlock_wrlock(LOCK) \
- (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
-# define glthread_rwlock_unlock(LOCK) \
- (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
-# define glthread_rwlock_destroy(LOCK) \
- (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
-extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
-extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
-
-# endif
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-# if HAVE_PTHREAD_MUTEX_RECURSIVE
-
-# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-
-typedef pthread_mutex_t gl_recursive_lock_t;
-# define gl_recursive_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS pthread_mutex_t NAME;
-# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer;
-# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER
-# define gl_recursive_lock_initializer \
- PTHREAD_RECURSIVE_MUTEX_INITIALIZER
-# else
-# define gl_recursive_lock_initializer \
- PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-# endif
-# define glthread_recursive_lock_init(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_lock(LOCK) \
- (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
-# define glthread_recursive_lock_unlock(LOCK) \
- (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
-# define glthread_recursive_lock_destroy(LOCK) \
- (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
-extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
-
-# else
-
-typedef struct
- {
- pthread_mutex_t recmutex; /* recursive mutex */
- pthread_mutex_t guard; /* protects the initialization */
- int initialized;
- }
- gl_recursive_lock_t;
-# define gl_recursive_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME;
-# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
-# define gl_recursive_lock_initializer \
- { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 }
-# define glthread_recursive_lock_init(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_lock(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_unlock(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_destroy(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
-extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
-
-# endif
-
-# else
-
-/* Old versions of POSIX threads on Solaris did not have recursive locks.
- We have to implement them ourselves. */
-
-typedef struct
- {
- pthread_mutex_t mutex;
- pthread_t owner;
- unsigned long depth;
- }
- gl_recursive_lock_t;
-# define gl_recursive_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME;
-# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
-# define gl_recursive_lock_initializer \
- { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 }
-# define glthread_recursive_lock_init(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_lock(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_unlock(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_destroy(LOCK) \
- (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
-extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
-
-# endif
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-typedef pthread_once_t gl_once_t;
-# define gl_once_define(STORAGECLASS, NAME) \
- STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;
-# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
- (pthread_in_use () \
- ? pthread_once (ONCE_CONTROL, INITFUNCTION) \
- : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
-extern int glthread_once_singlethreaded (pthread_once_t *once_control);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_PTH_THREADS
-
-/* Use the GNU Pth threads library. */
-
-# include <pth.h>
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-# if USE_PTH_THREADS_WEAK
-
-/* Use weak references to the GNU Pth threads library. */
-
-# pragma weak pth_mutex_init
-# pragma weak pth_mutex_acquire
-# pragma weak pth_mutex_release
-# pragma weak pth_rwlock_init
-# pragma weak pth_rwlock_acquire
-# pragma weak pth_rwlock_release
-# pragma weak pth_once
-
-# pragma weak pth_cancel
-# define pth_in_use() (pth_cancel != NULL)
-
-# else
-
-# define pth_in_use() 1
-
-# endif
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-typedef pth_mutex_t gl_lock_t;
-# define gl_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS pth_mutex_t NAME;
-# define gl_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS pth_mutex_t NAME = gl_lock_initializer;
-# define gl_lock_initializer \
- PTH_MUTEX_INIT
-# define glthread_lock_init(LOCK) \
- (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
-# define glthread_lock_lock(LOCK) \
- (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
-# define glthread_lock_unlock(LOCK) \
- (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
-# define glthread_lock_destroy(LOCK) \
- ((void)(LOCK), 0)
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-typedef pth_rwlock_t gl_rwlock_t;
-# define gl_rwlock_define(STORAGECLASS, NAME) \
- STORAGECLASS pth_rwlock_t NAME;
-# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer;
-# define gl_rwlock_initializer \
- PTH_RWLOCK_INIT
-# define glthread_rwlock_init(LOCK) \
- (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0)
-# define glthread_rwlock_rdlock(LOCK) \
- (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? errno : 0)
-# define glthread_rwlock_wrlock(LOCK) \
- (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? errno : 0)
-# define glthread_rwlock_unlock(LOCK) \
- (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0)
-# define glthread_rwlock_destroy(LOCK) \
- ((void)(LOCK), 0)
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-/* In Pth, mutexes are recursive by default. */
-typedef pth_mutex_t gl_recursive_lock_t;
-# define gl_recursive_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS pth_mutex_t NAME;
-# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer;
-# define gl_recursive_lock_initializer \
- PTH_MUTEX_INIT
-# define glthread_recursive_lock_init(LOCK) \
- (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
-# define glthread_recursive_lock_lock(LOCK) \
- (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
-# define glthread_recursive_lock_unlock(LOCK) \
- (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
-# define glthread_recursive_lock_destroy(LOCK) \
- ((void)(LOCK), 0)
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-typedef pth_once_t gl_once_t;
-# define gl_once_define(STORAGECLASS, NAME) \
- STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT;
-# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
- (pth_in_use () \
- ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \
- : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
-extern int glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void));
-extern int glthread_once_singlethreaded (pth_once_t *once_control);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_SOLARIS_THREADS
-
-/* Use the old Solaris threads library. */
-
-# include <thread.h>
-# include <synch.h>
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-# if USE_SOLARIS_THREADS_WEAK
-
-/* Use weak references to the old Solaris threads library. */
-
-# pragma weak mutex_init
-# pragma weak mutex_lock
-# pragma weak mutex_unlock
-# pragma weak mutex_destroy
-# pragma weak rwlock_init
-# pragma weak rw_rdlock
-# pragma weak rw_wrlock
-# pragma weak rw_unlock
-# pragma weak rwlock_destroy
-# pragma weak thr_self
-
-# pragma weak thr_suspend
-# define thread_in_use() (thr_suspend != NULL)
-
-# else
-
-# define thread_in_use() 1
-
-# endif
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-typedef mutex_t gl_lock_t;
-# define gl_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS mutex_t NAME;
-# define gl_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS mutex_t NAME = gl_lock_initializer;
-# define gl_lock_initializer \
- DEFAULTMUTEX
-# define glthread_lock_init(LOCK) \
- (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0)
-# define glthread_lock_lock(LOCK) \
- (thread_in_use () ? mutex_lock (LOCK) : 0)
-# define glthread_lock_unlock(LOCK) \
- (thread_in_use () ? mutex_unlock (LOCK) : 0)
-# define glthread_lock_destroy(LOCK) \
- (thread_in_use () ? mutex_destroy (LOCK) : 0)
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-typedef rwlock_t gl_rwlock_t;
-# define gl_rwlock_define(STORAGECLASS, NAME) \
- STORAGECLASS rwlock_t NAME;
-# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS rwlock_t NAME = gl_rwlock_initializer;
-# define gl_rwlock_initializer \
- DEFAULTRWLOCK
-# define glthread_rwlock_init(LOCK) \
- (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0)
-# define glthread_rwlock_rdlock(LOCK) \
- (thread_in_use () ? rw_rdlock (LOCK) : 0)
-# define glthread_rwlock_wrlock(LOCK) \
- (thread_in_use () ? rw_wrlock (LOCK) : 0)
-# define glthread_rwlock_unlock(LOCK) \
- (thread_in_use () ? rw_unlock (LOCK) : 0)
-# define glthread_rwlock_destroy(LOCK) \
- (thread_in_use () ? rwlock_destroy (LOCK) : 0)
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-/* Old Solaris threads did not have recursive locks.
- We have to implement them ourselves. */
-
-typedef struct
- {
- mutex_t mutex;
- thread_t owner;
- unsigned long depth;
- }
- gl_recursive_lock_t;
-# define gl_recursive_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME;
-# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
-# define gl_recursive_lock_initializer \
- { DEFAULTMUTEX, (thread_t) 0, 0 }
-# define glthread_recursive_lock_init(LOCK) \
- (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_lock(LOCK) \
- (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_unlock(LOCK) \
- (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
-# define glthread_recursive_lock_destroy(LOCK) \
- (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
-extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-typedef struct
- {
- volatile int inited;
- mutex_t mutex;
- }
- gl_once_t;
-# define gl_once_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX };
-# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
- (thread_in_use () \
- ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \
- : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
-extern int glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void));
-extern int glthread_once_singlethreaded (gl_once_t *once_control);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_WINDOWS_THREADS
-
-# define WIN32_LEAN_AND_MEAN /* avoid including junk */
-# include <windows.h>
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-/* We can use CRITICAL_SECTION directly, rather than the native Windows Event,
- Mutex, Semaphore types, because
- - we need only to synchronize inside a single process (address space),
- not inter-process locking,
- - we don't need to support trylock operations. (TryEnterCriticalSection
- does not work on Windows 95/98/ME. Packages that need trylock usually
- define their own mutex type.) */
-
-/* There is no way to statically initialize a CRITICAL_SECTION. It needs
- to be done lazily, once only. For this we need spinlocks. */
-
-typedef struct { volatile int done; volatile long started; } gl_spinlock_t;
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-typedef struct
- {
- gl_spinlock_t guard; /* protects the initialization */
- CRITICAL_SECTION lock;
- }
- gl_lock_t;
-# define gl_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_lock_t NAME;
-# define gl_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_lock_t NAME = gl_lock_initializer;
-# define gl_lock_initializer \
- { { 0, -1 } }
-# define glthread_lock_init(LOCK) \
- (glthread_lock_init_func (LOCK), 0)
-# define glthread_lock_lock(LOCK) \
- glthread_lock_lock_func (LOCK)
-# define glthread_lock_unlock(LOCK) \
- glthread_lock_unlock_func (LOCK)
-# define glthread_lock_destroy(LOCK) \
- glthread_lock_destroy_func (LOCK)
-extern void glthread_lock_init_func (gl_lock_t *lock);
-extern int glthread_lock_lock_func (gl_lock_t *lock);
-extern int glthread_lock_unlock_func (gl_lock_t *lock);
-extern int glthread_lock_destroy_func (gl_lock_t *lock);
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-/* It is impossible to implement read-write locks using plain locks, without
- introducing an extra thread dedicated to managing read-write locks.
- Therefore here we need to use the low-level Event type. */
-
-typedef struct
- {
- HANDLE *array; /* array of waiting threads, each represented by an event */
- unsigned int count; /* number of waiting threads */
- unsigned int alloc; /* length of allocated array */
- unsigned int offset; /* index of first waiting thread in array */
- }
- gl_carray_waitqueue_t;
-typedef struct
- {
- gl_spinlock_t guard; /* protects the initialization */
- CRITICAL_SECTION lock; /* protects the remaining fields */
- gl_carray_waitqueue_t waiting_readers; /* waiting readers */
- gl_carray_waitqueue_t waiting_writers; /* waiting writers */
- int runcount; /* number of readers running, or -1 when a writer runs */
- }
- gl_rwlock_t;
-# define gl_rwlock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_rwlock_t NAME;
-# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
-# define gl_rwlock_initializer \
- { { 0, -1 } }
-# define glthread_rwlock_init(LOCK) \
- (glthread_rwlock_init_func (LOCK), 0)
-# define glthread_rwlock_rdlock(LOCK) \
- glthread_rwlock_rdlock_func (LOCK)
-# define glthread_rwlock_wrlock(LOCK) \
- glthread_rwlock_wrlock_func (LOCK)
-# define glthread_rwlock_unlock(LOCK) \
- glthread_rwlock_unlock_func (LOCK)
-# define glthread_rwlock_destroy(LOCK) \
- glthread_rwlock_destroy_func (LOCK)
-extern void glthread_rwlock_init_func (gl_rwlock_t *lock);
-extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock);
-extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock);
-extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock);
-extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock);
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-/* The native Windows documentation says that CRITICAL_SECTION already
- implements a recursive lock. But we need not rely on it: It's easy to
- implement a recursive lock without this assumption. */
-
-typedef struct
- {
- gl_spinlock_t guard; /* protects the initialization */
- DWORD owner;
- unsigned long depth;
- CRITICAL_SECTION lock;
- }
- gl_recursive_lock_t;
-# define gl_recursive_lock_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME;
-# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
- STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
-# define gl_recursive_lock_initializer \
- { { 0, -1 }, 0, 0 }
-# define glthread_recursive_lock_init(LOCK) \
- (glthread_recursive_lock_init_func (LOCK), 0)
-# define glthread_recursive_lock_lock(LOCK) \
- glthread_recursive_lock_lock_func (LOCK)
-# define glthread_recursive_lock_unlock(LOCK) \
- glthread_recursive_lock_unlock_func (LOCK)
-# define glthread_recursive_lock_destroy(LOCK) \
- glthread_recursive_lock_destroy_func (LOCK)
-extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock);
-extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock);
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-typedef struct
- {
- volatile int inited;
- volatile long started;
- CRITICAL_SECTION lock;
- }
- gl_once_t;
-# define gl_once_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_once_t NAME = { -1, -1 };
-# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
- (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0)
-extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) (void));
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif
-
-/* ========================================================================= */
-
-#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS)
-
-/* Provide dummy implementation if threads are not supported. */
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-typedef int gl_lock_t;
-# define gl_lock_define(STORAGECLASS, NAME)
-# define gl_lock_define_initialized(STORAGECLASS, NAME)
-# define glthread_lock_init(NAME) 0
-# define glthread_lock_lock(NAME) 0
-# define glthread_lock_unlock(NAME) 0
-# define glthread_lock_destroy(NAME) 0
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-typedef int gl_rwlock_t;
-# define gl_rwlock_define(STORAGECLASS, NAME)
-# define gl_rwlock_define_initialized(STORAGECLASS, NAME)
-# define glthread_rwlock_init(NAME) 0
-# define glthread_rwlock_rdlock(NAME) 0
-# define glthread_rwlock_wrlock(NAME) 0
-# define glthread_rwlock_unlock(NAME) 0
-# define glthread_rwlock_destroy(NAME) 0
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-typedef int gl_recursive_lock_t;
-# define gl_recursive_lock_define(STORAGECLASS, NAME)
-# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME)
-# define glthread_recursive_lock_init(NAME) 0
-# define glthread_recursive_lock_lock(NAME) 0
-# define glthread_recursive_lock_unlock(NAME) 0
-# define glthread_recursive_lock_destroy(NAME) 0
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-typedef int gl_once_t;
-# define gl_once_define(STORAGECLASS, NAME) \
- STORAGECLASS gl_once_t NAME = 0;
-# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
- (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0)
-
-#endif
-
-/* ========================================================================= */
-
-/* Macros with built-in error handling. */
-
-/* -------------------------- gl_lock_t datatype -------------------------- */
-
-#define gl_lock_init(NAME) \
- do \
- { \
- if (glthread_lock_init (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_lock_lock(NAME) \
- do \
- { \
- if (glthread_lock_lock (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_lock_unlock(NAME) \
- do \
- { \
- if (glthread_lock_unlock (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_lock_destroy(NAME) \
- do \
- { \
- if (glthread_lock_destroy (&NAME)) \
- abort (); \
- } \
- while (0)
-
-/* ------------------------- gl_rwlock_t datatype ------------------------- */
-
-#define gl_rwlock_init(NAME) \
- do \
- { \
- if (glthread_rwlock_init (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_rwlock_rdlock(NAME) \
- do \
- { \
- if (glthread_rwlock_rdlock (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_rwlock_wrlock(NAME) \
- do \
- { \
- if (glthread_rwlock_wrlock (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_rwlock_unlock(NAME) \
- do \
- { \
- if (glthread_rwlock_unlock (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_rwlock_destroy(NAME) \
- do \
- { \
- if (glthread_rwlock_destroy (&NAME)) \
- abort (); \
- } \
- while (0)
-
-/* --------------------- gl_recursive_lock_t datatype --------------------- */
-
-#define gl_recursive_lock_init(NAME) \
- do \
- { \
- if (glthread_recursive_lock_init (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_recursive_lock_lock(NAME) \
- do \
- { \
- if (glthread_recursive_lock_lock (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_recursive_lock_unlock(NAME) \
- do \
- { \
- if (glthread_recursive_lock_unlock (&NAME)) \
- abort (); \
- } \
- while (0)
-#define gl_recursive_lock_destroy(NAME) \
- do \
- { \
- if (glthread_recursive_lock_destroy (&NAME)) \
- abort (); \
- } \
- while (0)
-
-/* -------------------------- gl_once_t datatype -------------------------- */
-
-#define gl_once(NAME, INITFUNCTION) \
- do \
- { \
- if (glthread_once (&NAME, INITFUNCTION)) \
- abort (); \
- } \
- while (0)
-
-/* ========================================================================= */
-
-#endif /* _LOCK_H */
+/* Locking in multithreaded situations.
+ Copyright (C) 2005-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2005.
+ Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+ gthr-win32.h. */
+
+/* This file contains locking primitives for use with a given thread library.
+ It does not contain primitives for creating threads or for other
+ synchronization primitives.
+
+ Normal (non-recursive) locks:
+ Type: gl_lock_t
+ Declaration: gl_lock_define(extern, name)
+ Initializer: gl_lock_define_initialized(, name)
+ Initialization: gl_lock_init (name);
+ Taking the lock: gl_lock_lock (name);
+ Releasing the lock: gl_lock_unlock (name);
+ De-initialization: gl_lock_destroy (name);
+ Equivalent functions with control of error handling:
+ Initialization: err = glthread_lock_init (&name);
+ Taking the lock: err = glthread_lock_lock (&name);
+ Releasing the lock: err = glthread_lock_unlock (&name);
+ De-initialization: err = glthread_lock_destroy (&name);
+
+ Read-Write (non-recursive) locks:
+ Type: gl_rwlock_t
+ Declaration: gl_rwlock_define(extern, name)
+ Initializer: gl_rwlock_define_initialized(, name)
+ Initialization: gl_rwlock_init (name);
+ Taking the lock: gl_rwlock_rdlock (name);
+ gl_rwlock_wrlock (name);
+ Releasing the lock: gl_rwlock_unlock (name);
+ De-initialization: gl_rwlock_destroy (name);
+ Equivalent functions with control of error handling:
+ Initialization: err = glthread_rwlock_init (&name);
+ Taking the lock: err = glthread_rwlock_rdlock (&name);
+ err = glthread_rwlock_wrlock (&name);
+ Releasing the lock: err = glthread_rwlock_unlock (&name);
+ De-initialization: err = glthread_rwlock_destroy (&name);
+
+ Recursive locks:
+ Type: gl_recursive_lock_t
+ Declaration: gl_recursive_lock_define(extern, name)
+ Initializer: gl_recursive_lock_define_initialized(, name)
+ Initialization: gl_recursive_lock_init (name);
+ Taking the lock: gl_recursive_lock_lock (name);
+ Releasing the lock: gl_recursive_lock_unlock (name);
+ De-initialization: gl_recursive_lock_destroy (name);
+ Equivalent functions with control of error handling:
+ Initialization: err = glthread_recursive_lock_init (&name);
+ Taking the lock: err = glthread_recursive_lock_lock (&name);
+ Releasing the lock: err = glthread_recursive_lock_unlock (&name);
+ De-initialization: err = glthread_recursive_lock_destroy (&name);
+
+ Once-only execution:
+ Type: gl_once_t
+ Initializer: gl_once_define(extern, name)
+ Execution: gl_once (name, initfunction);
+ Equivalent functions with control of error handling:
+ Execution: err = glthread_once (&name, initfunction);
+*/
+
+
+#ifndef _LOCK_H
+#define _LOCK_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library. */
+
+# include <pthread.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The pthread_in_use() detection needs to be done at runtime. */
+# define pthread_in_use() \
+ glthread_in_use ()
+extern int glthread_in_use (void);
+
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+
+/* Use weak references to the POSIX threads library. */
+
+/* Weak references avoid dragging in external libraries if the other parts
+ of the program don't use them. Here we use them, because we don't want
+ every program that uses libintl to depend on libpthread. This assumes
+ that libpthread would not be loaded after libintl; i.e. if libintl is
+ loaded first, by an executable that does not depend on libpthread, and
+ then a module is dynamically loaded that depends on libpthread, libintl
+ will not be multithread-safe. */
+
+/* The way to test at runtime whether libpthread is present is to test
+ whether a function pointer's value, such as &pthread_mutex_init, is
+ non-NULL. However, some versions of GCC have a bug through which, in
+ PIC mode, &foo != NULL always evaluates to true if there is a direct
+ call to foo(...) in the same function. To avoid this, we test the
+ address of a function in libpthread that we don't use. */
+
+# pragma weak pthread_mutex_init
+# pragma weak pthread_mutex_lock
+# pragma weak pthread_mutex_unlock
+# pragma weak pthread_mutex_destroy
+# pragma weak pthread_rwlock_init
+# pragma weak pthread_rwlock_rdlock
+# pragma weak pthread_rwlock_wrlock
+# pragma weak pthread_rwlock_unlock
+# pragma weak pthread_rwlock_destroy
+# pragma weak pthread_once
+# pragma weak pthread_cond_init
+# pragma weak pthread_cond_wait
+# pragma weak pthread_cond_signal
+# pragma weak pthread_cond_broadcast
+# pragma weak pthread_cond_destroy
+# pragma weak pthread_mutexattr_init
+# pragma weak pthread_mutexattr_settype
+# pragma weak pthread_mutexattr_destroy
+# ifndef pthread_self
+# pragma weak pthread_self
+# endif
+
+# if !PTHREAD_IN_USE_DETECTION_HARD
+# pragma weak pthread_cancel
+# define pthread_in_use() (pthread_cancel != NULL)
+# endif
+
+# else
+
+# if !PTHREAD_IN_USE_DETECTION_HARD
+# define pthread_in_use() 1
+# endif
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef pthread_mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS pthread_mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+ PTHREAD_MUTEX_INITIALIZER
+# define glthread_lock_init(LOCK) \
+ (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0)
+# define glthread_lock_lock(LOCK) \
+ (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
+# define glthread_lock_unlock(LOCK) \
+ (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
+# define glthread_lock_destroy(LOCK) \
+ (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+# if HAVE_PTHREAD_RWLOCK
+
+# ifdef PTHREAD_RWLOCK_INITIALIZER
+
+typedef pthread_rwlock_t gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+ STORAGECLASS pthread_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+ PTHREAD_RWLOCK_INITIALIZER
+# define glthread_rwlock_init(LOCK) \
+ (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+ (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+ (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+ (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+ (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0)
+
+# else
+
+typedef struct
+ {
+ int initialized;
+ pthread_mutex_t guard; /* protects the initialization */
+ pthread_rwlock_t rwlock; /* read-write lock */
+ }
+ gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+ { 0, PTHREAD_MUTEX_INITIALIZER }
+# define glthread_rwlock_init(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
+
+# endif
+
+# else
+
+typedef struct
+ {
+ pthread_mutex_t lock; /* protects the remaining fields */
+ pthread_cond_t waiting_readers; /* waiting readers */
+ pthread_cond_t waiting_writers; /* waiting writers */
+ unsigned int waiting_writers_count; /* number of waiting writers */
+ int runcount; /* number of readers running, or -1 when a writer runs */
+ }
+ gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+ { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 }
+# define glthread_rwlock_init(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+ (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
+
+# endif
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+# if HAVE_PTHREAD_MUTEX_RECURSIVE
+
+# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+
+typedef pthread_mutex_t gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS pthread_mutex_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer;
+# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+# define gl_recursive_lock_initializer \
+ PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+# else
+# define gl_recursive_lock_initializer \
+ PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+# endif
+# define glthread_recursive_lock_init(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_lock(LOCK) \
+ (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
+# define glthread_recursive_lock_unlock(LOCK) \
+ (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
+# define glthread_recursive_lock_destroy(LOCK) \
+ (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
+
+# else
+
+typedef struct
+ {
+ pthread_mutex_t recmutex; /* recursive mutex */
+ pthread_mutex_t guard; /* protects the initialization */
+ int initialized;
+ }
+ gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+ { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_lock(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_unlock(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_destroy(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
+
+# endif
+
+# else
+
+/* Old versions of POSIX threads on Solaris did not have recursive locks.
+ We have to implement them ourselves. */
+
+typedef struct
+ {
+ pthread_mutex_t mutex;
+ pthread_t owner;
+ unsigned long depth;
+ }
+ gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+ { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_lock(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_unlock(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_destroy(LOCK) \
+ (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
+
+# endif
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef pthread_once_t gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+ STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+ (pthread_in_use () \
+ ? pthread_once (ONCE_CONTROL, INITFUNCTION) \
+ : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
+extern int glthread_once_singlethreaded (pthread_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library. */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_PTH_THREADS_WEAK
+
+/* Use weak references to the GNU Pth threads library. */
+
+# pragma weak pth_mutex_init
+# pragma weak pth_mutex_acquire
+# pragma weak pth_mutex_release
+# pragma weak pth_rwlock_init
+# pragma weak pth_rwlock_acquire
+# pragma weak pth_rwlock_release
+# pragma weak pth_once
+
+# pragma weak pth_cancel
+# define pth_in_use() (pth_cancel != NULL)
+
+# else
+
+# define pth_in_use() 1
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef pth_mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS pth_mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS pth_mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+ PTH_MUTEX_INIT
+# define glthread_lock_init(LOCK) \
+ (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
+# define glthread_lock_lock(LOCK) \
+ (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
+# define glthread_lock_unlock(LOCK) \
+ (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
+# define glthread_lock_destroy(LOCK) \
+ ((void)(LOCK), 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef pth_rwlock_t gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+ STORAGECLASS pth_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+ PTH_RWLOCK_INIT
+# define glthread_rwlock_init(LOCK) \
+ (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+ (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? errno : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+ (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? errno : 0)
+# define glthread_rwlock_unlock(LOCK) \
+ (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0)
+# define glthread_rwlock_destroy(LOCK) \
+ ((void)(LOCK), 0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* In Pth, mutexes are recursive by default. */
+typedef pth_mutex_t gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS pth_mutex_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+ PTH_MUTEX_INIT
+# define glthread_recursive_lock_init(LOCK) \
+ (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
+# define glthread_recursive_lock_lock(LOCK) \
+ (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
+# define glthread_recursive_lock_unlock(LOCK) \
+ (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
+# define glthread_recursive_lock_destroy(LOCK) \
+ ((void)(LOCK), 0)
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef pth_once_t gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+ STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+ (pth_in_use () \
+ ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \
+ : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
+extern int glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void));
+extern int glthread_once_singlethreaded (pth_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library. */
+
+# include <thread.h>
+# include <synch.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_SOLARIS_THREADS_WEAK
+
+/* Use weak references to the old Solaris threads library. */
+
+# pragma weak mutex_init
+# pragma weak mutex_lock
+# pragma weak mutex_unlock
+# pragma weak mutex_destroy
+# pragma weak rwlock_init
+# pragma weak rw_rdlock
+# pragma weak rw_wrlock
+# pragma weak rw_unlock
+# pragma weak rwlock_destroy
+# pragma weak thr_self
+
+# pragma weak thr_suspend
+# define thread_in_use() (thr_suspend != NULL)
+
+# else
+
+# define thread_in_use() 1
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+ DEFAULTMUTEX
+# define glthread_lock_init(LOCK) \
+ (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0)
+# define glthread_lock_lock(LOCK) \
+ (thread_in_use () ? mutex_lock (LOCK) : 0)
+# define glthread_lock_unlock(LOCK) \
+ (thread_in_use () ? mutex_unlock (LOCK) : 0)
+# define glthread_lock_destroy(LOCK) \
+ (thread_in_use () ? mutex_destroy (LOCK) : 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef rwlock_t gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+ STORAGECLASS rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+ DEFAULTRWLOCK
+# define glthread_rwlock_init(LOCK) \
+ (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+ (thread_in_use () ? rw_rdlock (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+ (thread_in_use () ? rw_wrlock (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+ (thread_in_use () ? rw_unlock (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+ (thread_in_use () ? rwlock_destroy (LOCK) : 0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* Old Solaris threads did not have recursive locks.
+ We have to implement them ourselves. */
+
+typedef struct
+ {
+ mutex_t mutex;
+ thread_t owner;
+ unsigned long depth;
+ }
+ gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+ { DEFAULTMUTEX, (thread_t) 0, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+ (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_lock(LOCK) \
+ (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_unlock(LOCK) \
+ (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_destroy(LOCK) \
+ (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef struct
+ {
+ volatile int inited;
+ mutex_t mutex;
+ }
+ gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX };
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+ (thread_in_use () \
+ ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \
+ : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
+extern int glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void));
+extern int glthread_once_singlethreaded (gl_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WINDOWS_THREADS
+
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* We can use CRITICAL_SECTION directly, rather than the native Windows Event,
+ Mutex, Semaphore types, because
+ - we need only to synchronize inside a single process (address space),
+ not inter-process locking,
+ - we don't need to support trylock operations. (TryEnterCriticalSection
+ does not work on Windows 95/98/ME. Packages that need trylock usually
+ define their own mutex type.) */
+
+/* There is no way to statically initialize a CRITICAL_SECTION. It needs
+ to be done lazily, once only. For this we need spinlocks. */
+
+typedef struct { volatile int done; volatile long started; } gl_spinlock_t;
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef struct
+ {
+ gl_spinlock_t guard; /* protects the initialization */
+ CRITICAL_SECTION lock;
+ }
+ gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_lock_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_lock_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+ { { 0, -1 } }
+# define glthread_lock_init(LOCK) \
+ (glthread_lock_init_func (LOCK), 0)
+# define glthread_lock_lock(LOCK) \
+ glthread_lock_lock_func (LOCK)
+# define glthread_lock_unlock(LOCK) \
+ glthread_lock_unlock_func (LOCK)
+# define glthread_lock_destroy(LOCK) \
+ glthread_lock_destroy_func (LOCK)
+extern void glthread_lock_init_func (gl_lock_t *lock);
+extern int glthread_lock_lock_func (gl_lock_t *lock);
+extern int glthread_lock_unlock_func (gl_lock_t *lock);
+extern int glthread_lock_destroy_func (gl_lock_t *lock);
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* It is impossible to implement read-write locks using plain locks, without
+ introducing an extra thread dedicated to managing read-write locks.
+ Therefore here we need to use the low-level Event type. */
+
+typedef struct
+ {
+ HANDLE *array; /* array of waiting threads, each represented by an event */
+ unsigned int count; /* number of waiting threads */
+ unsigned int alloc; /* length of allocated array */
+ unsigned int offset; /* index of first waiting thread in array */
+ }
+ gl_carray_waitqueue_t;
+typedef struct
+ {
+ gl_spinlock_t guard; /* protects the initialization */
+ CRITICAL_SECTION lock; /* protects the remaining fields */
+ gl_carray_waitqueue_t waiting_readers; /* waiting readers */
+ gl_carray_waitqueue_t waiting_writers; /* waiting writers */
+ int runcount; /* number of readers running, or -1 when a writer runs */
+ }
+ gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+ { { 0, -1 } }
+# define glthread_rwlock_init(LOCK) \
+ (glthread_rwlock_init_func (LOCK), 0)
+# define glthread_rwlock_rdlock(LOCK) \
+ glthread_rwlock_rdlock_func (LOCK)
+# define glthread_rwlock_wrlock(LOCK) \
+ glthread_rwlock_wrlock_func (LOCK)
+# define glthread_rwlock_unlock(LOCK) \
+ glthread_rwlock_unlock_func (LOCK)
+# define glthread_rwlock_destroy(LOCK) \
+ glthread_rwlock_destroy_func (LOCK)
+extern void glthread_rwlock_init_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock);
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* The native Windows documentation says that CRITICAL_SECTION already
+ implements a recursive lock. But we need not rely on it: It's easy to
+ implement a recursive lock without this assumption. */
+
+typedef struct
+ {
+ gl_spinlock_t guard; /* protects the initialization */
+ DWORD owner;
+ unsigned long depth;
+ CRITICAL_SECTION lock;
+ }
+ gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+ STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+ { { 0, -1 }, 0, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+ (glthread_recursive_lock_init_func (LOCK), 0)
+# define glthread_recursive_lock_lock(LOCK) \
+ glthread_recursive_lock_lock_func (LOCK)
+# define glthread_recursive_lock_unlock(LOCK) \
+ glthread_recursive_lock_unlock_func (LOCK)
+# define glthread_recursive_lock_destroy(LOCK) \
+ glthread_recursive_lock_destroy_func (LOCK)
+extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock);
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef struct
+ {
+ volatile int inited;
+ volatile long started;
+ CRITICAL_SECTION lock;
+ }
+ gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_once_t NAME = { -1, -1 };
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+ (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0)
+extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) (void));
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS)
+
+/* Provide dummy implementation if threads are not supported. */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef int gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME)
+# define gl_lock_define_initialized(STORAGECLASS, NAME)
+# define glthread_lock_init(NAME) 0
+# define glthread_lock_lock(NAME) 0
+# define glthread_lock_unlock(NAME) 0
+# define glthread_lock_destroy(NAME) 0
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef int gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME)
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME)
+# define glthread_rwlock_init(NAME) 0
+# define glthread_rwlock_rdlock(NAME) 0
+# define glthread_rwlock_wrlock(NAME) 0
+# define glthread_rwlock_unlock(NAME) 0
+# define glthread_rwlock_destroy(NAME) 0
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+typedef int gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME)
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME)
+# define glthread_recursive_lock_init(NAME) 0
+# define glthread_recursive_lock_lock(NAME) 0
+# define glthread_recursive_lock_unlock(NAME) 0
+# define glthread_recursive_lock_destroy(NAME) 0
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef int gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+ STORAGECLASS gl_once_t NAME = 0;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+ (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0)
+
+#endif
+
+/* ========================================================================= */
+
+/* Macros with built-in error handling. */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+#define gl_lock_init(NAME) \
+ do \
+ { \
+ if (glthread_lock_init (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_lock_lock(NAME) \
+ do \
+ { \
+ if (glthread_lock_lock (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_lock_unlock(NAME) \
+ do \
+ { \
+ if (glthread_lock_unlock (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_lock_destroy(NAME) \
+ do \
+ { \
+ if (glthread_lock_destroy (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+#define gl_rwlock_init(NAME) \
+ do \
+ { \
+ if (glthread_rwlock_init (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_rwlock_rdlock(NAME) \
+ do \
+ { \
+ if (glthread_rwlock_rdlock (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_rwlock_wrlock(NAME) \
+ do \
+ { \
+ if (glthread_rwlock_wrlock (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_rwlock_unlock(NAME) \
+ do \
+ { \
+ if (glthread_rwlock_unlock (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_rwlock_destroy(NAME) \
+ do \
+ { \
+ if (glthread_rwlock_destroy (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+#define gl_recursive_lock_init(NAME) \
+ do \
+ { \
+ if (glthread_recursive_lock_init (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_recursive_lock_lock(NAME) \
+ do \
+ { \
+ if (glthread_recursive_lock_lock (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_recursive_lock_unlock(NAME) \
+ do \
+ { \
+ if (glthread_recursive_lock_unlock (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_recursive_lock_destroy(NAME) \
+ do \
+ { \
+ if (glthread_recursive_lock_destroy (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+#define gl_once(NAME, INITFUNCTION) \
+ do \
+ { \
+ if (glthread_once (&NAME, INITFUNCTION)) \
+ abort (); \
+ } \
+ while (0)
+
+/* ========================================================================= */
+
+#endif /* _LOCK_H */
diff --git a/contrib/tools/bison/gnulib/src/glthread/threadlib.c b/contrib/tools/bison/gnulib/src/glthread/threadlib.c
index b447657302..a31d14e98b 100644
--- a/contrib/tools/bison/gnulib/src/glthread/threadlib.c
+++ b/contrib/tools/bison/gnulib/src/glthread/threadlib.c
@@ -1,73 +1,73 @@
-/* Multithreading primitives.
- Copyright (C) 2005-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
-
-#include <config.h>
-
-/* ========================================================================= */
-
-#if USE_POSIX_THREADS
-
-/* Use the POSIX threads library. */
-
-# include <pthread.h>
-# include <stdlib.h>
-
-# if PTHREAD_IN_USE_DETECTION_HARD
-
-/* The function to be executed by a dummy thread. */
-static void *
-dummy_thread_func (void *arg)
-{
- return arg;
-}
-
-int
-glthread_in_use (void)
-{
- static int tested;
- static int result; /* 1: linked with -lpthread, 0: only with libc */
-
- if (!tested)
- {
- pthread_t thread;
-
- if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
- /* Thread creation failed. */
- result = 0;
- else
- {
- /* Thread creation works. */
- void *retval;
- if (pthread_join (thread, &retval) != 0)
- abort ();
- result = 1;
- }
- tested = 1;
- }
- return result;
-}
-
-# endif
-
-#endif
-
-/* ========================================================================= */
-
-/* This declaration is solely to ensure that after preprocessing
- this file is never empty. */
-typedef int dummy;
+/* Multithreading primitives.
+ Copyright (C) 2005-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
+
+#include <config.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library. */
+
+# include <pthread.h>
+# include <stdlib.h>
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The function to be executed by a dummy thread. */
+static void *
+dummy_thread_func (void *arg)
+{
+ return arg;
+}
+
+int
+glthread_in_use (void)
+{
+ static int tested;
+ static int result; /* 1: linked with -lpthread, 0: only with libc */
+
+ if (!tested)
+ {
+ pthread_t thread;
+
+ if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
+ /* Thread creation failed. */
+ result = 0;
+ else
+ {
+ /* Thread creation works. */
+ void *retval;
+ if (pthread_join (thread, &retval) != 0)
+ abort ();
+ result = 1;
+ }
+ tested = 1;
+ }
+ return result;
+}
+
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+/* This declaration is solely to ensure that after preprocessing
+ this file is never empty. */
+typedef int dummy;
diff --git a/contrib/tools/bison/gnulib/src/glthread/tls.c b/contrib/tools/bison/gnulib/src/glthread/tls.c
index bcd285c273..a92506f073 100644
--- a/contrib/tools/bison/gnulib/src/glthread/tls.c
+++ b/contrib/tools/bison/gnulib/src/glthread/tls.c
@@ -1,61 +1,61 @@
-/* Thread-local storage in multithreaded situations.
- Copyright (C) 2005-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
-
-#include <config.h>
-
-#include "glthread/tls.h"
-
-/* ========================================================================= */
-
-#if USE_POSIX_THREADS
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_PTH_THREADS
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_SOLARIS_THREADS
-
-/* Use the old Solaris threads library. */
-
-/* ------------------------- gl_tls_key_t datatype ------------------------- */
-
-void *
-glthread_tls_get_multithreaded (thread_key_t key)
-{
- void *value;
-
- if (thr_getspecific (key, &value) != 0)
- abort ();
- return value;
-}
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_WINDOWS_THREADS
-
-#endif
-
-/* ========================================================================= */
+/* Thread-local storage in multithreaded situations.
+ Copyright (C) 2005-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
+
+#include <config.h>
+
+#include "glthread/tls.h"
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library. */
+
+/* ------------------------- gl_tls_key_t datatype ------------------------- */
+
+void *
+glthread_tls_get_multithreaded (thread_key_t key)
+{
+ void *value;
+
+ if (thr_getspecific (key, &value) != 0)
+ abort ();
+ return value;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WINDOWS_THREADS
+
+#endif
+
+/* ========================================================================= */
diff --git a/contrib/tools/bison/gnulib/src/glthread/tls.h b/contrib/tools/bison/gnulib/src/glthread/tls.h
index 2afe0b43c3..ea8ce75c23 100644
--- a/contrib/tools/bison/gnulib/src/glthread/tls.h
+++ b/contrib/tools/bison/gnulib/src/glthread/tls.h
@@ -1,299 +1,299 @@
-/* Thread-local storage in multithreaded situations.
- Copyright (C) 2005, 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
-
-/* This file contains thread-local storage primitives for use with a given
- thread library. It does not contain primitives for creating threads or
- for other multithreading primitives.
-
- Type: gl_tls_key_t
- Initialization: gl_tls_key_init (name, destructor);
- Getting per-thread value: gl_tls_get (name)
- Setting per-thread value: gl_tls_set (name, pointer);
- De-initialization: gl_tls_key_destroy (name);
- Equivalent functions with control of error handling:
- Initialization: err = glthread_tls_key_init (&name, destructor);
- Setting per-thread value: err = glthread_tls_set (&name, pointer);
- De-initialization: err = glthread_tls_key_destroy (&name);
-
- A per-thread value is of type 'void *'.
-
- A destructor is a function pointer of type 'void (*) (void *)', called
- when a thread exits, and taking the last per-thread value as argument. It
- is unspecified whether the destructor function is called when the last
- per-thread value is NULL. On some platforms, the destructor function is
- not called at all.
-*/
-
-
-#ifndef _TLS_H
-#define _TLS_H
-
-#include <errno.h>
-#include <stdlib.h>
-
-/* ========================================================================= */
-
-#if USE_POSIX_THREADS
-
-/* Use the POSIX threads library. */
-
-# include <pthread.h>
-
-# if PTHREAD_IN_USE_DETECTION_HARD
-
-/* The pthread_in_use() detection needs to be done at runtime. */
-# define pthread_in_use() \
- glthread_in_use ()
-extern int glthread_in_use (void);
-
-# endif
-
-# if USE_POSIX_THREADS_WEAK
-
-/* Use weak references to the POSIX threads library. */
-
-# pragma weak pthread_key_create
-# pragma weak pthread_getspecific
-# pragma weak pthread_setspecific
-# pragma weak pthread_key_delete
-# ifndef pthread_self
-# pragma weak pthread_self
-# endif
-
-# if !PTHREAD_IN_USE_DETECTION_HARD
-# pragma weak pthread_cancel
-# define pthread_in_use() (pthread_cancel != NULL)
-# endif
-
-# else
-
-# if !PTHREAD_IN_USE_DETECTION_HARD
-# define pthread_in_use() 1
-# endif
-
-# endif
-
-/* ------------------------- gl_tls_key_t datatype ------------------------- */
-
-typedef union
- {
- void *singlethread_value;
- pthread_key_t key;
- }
- gl_tls_key_t;
-# define glthread_tls_key_init(KEY, DESTRUCTOR) \
- (pthread_in_use () \
- ? pthread_key_create (&(KEY)->key, DESTRUCTOR) \
- : ((KEY)->singlethread_value = NULL, 0))
-# define gl_tls_get(NAME) \
- (pthread_in_use () \
- ? pthread_getspecific ((NAME).key) \
- : (NAME).singlethread_value)
-# define glthread_tls_set(KEY, POINTER) \
- (pthread_in_use () \
- ? pthread_setspecific ((KEY)->key, (POINTER)) \
- : ((KEY)->singlethread_value = (POINTER), 0))
-# define glthread_tls_key_destroy(KEY) \
- (pthread_in_use () ? pthread_key_delete ((KEY)->key) : 0)
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_PTH_THREADS
-
-/* Use the GNU Pth threads library. */
-
-# include <pth.h>
-
-# if USE_PTH_THREADS_WEAK
-
-/* Use weak references to the GNU Pth threads library. */
-
-# pragma weak pth_key_create
-# pragma weak pth_key_getdata
-# pragma weak pth_key_setdata
-# pragma weak pth_key_delete
-
-# pragma weak pth_cancel
-# define pth_in_use() (pth_cancel != NULL)
-
-# else
-
-# define pth_in_use() 1
-
-# endif
-
-/* ------------------------- gl_tls_key_t datatype ------------------------- */
-
-typedef union
- {
- void *singlethread_value;
- pth_key_t key;
- }
- gl_tls_key_t;
-# define glthread_tls_key_init(KEY, DESTRUCTOR) \
- (pth_in_use () \
- ? (!pth_key_create (&(KEY)->key, DESTRUCTOR) ? errno : 0) \
- : ((KEY)->singlethread_value = NULL, 0))
-# define gl_tls_get(NAME) \
- (pth_in_use () \
- ? pth_key_getdata ((NAME).key) \
- : (NAME).singlethread_value)
-# define glthread_tls_set(KEY, POINTER) \
- (pth_in_use () \
- ? (!pth_key_setdata ((KEY)->key, (POINTER)) ? errno : 0) \
- : ((KEY)->singlethread_value = (POINTER), 0))
-# define glthread_tls_key_destroy(KEY) \
- (pth_in_use () \
- ? (!pth_key_delete ((KEY)->key) ? errno : 0) \
- : 0)
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_SOLARIS_THREADS
-
-/* Use the old Solaris threads library. */
-
-# include <thread.h>
-
-# if USE_SOLARIS_THREADS_WEAK
-
-/* Use weak references to the old Solaris threads library. */
-
-# pragma weak thr_keycreate
-# pragma weak thr_getspecific
-# pragma weak thr_setspecific
-
-# pragma weak thr_suspend
-# define thread_in_use() (thr_suspend != NULL)
-
-# else
-
-# define thread_in_use() 1
-
-# endif
-
-/* ------------------------- gl_tls_key_t datatype ------------------------- */
-
-typedef union
- {
- void *singlethread_value;
- thread_key_t key;
- }
- gl_tls_key_t;
-# define glthread_tls_key_init(KEY, DESTRUCTOR) \
- (thread_in_use () \
- ? thr_keycreate (&(KEY)->key, DESTRUCTOR) \
- : ((KEY)->singlethread_value = NULL, 0))
-# define gl_tls_get(NAME) \
- (thread_in_use () \
- ? glthread_tls_get_multithreaded ((NAME).key) \
- : (NAME).singlethread_value)
-extern void *glthread_tls_get_multithreaded (thread_key_t key);
-# define glthread_tls_set(KEY, POINTER) \
- (thread_in_use () \
- ? thr_setspecific ((KEY)->key, (POINTER)) \
- : ((KEY)->singlethread_value = (POINTER), 0))
-# define glthread_tls_key_destroy(KEY) \
- /* Unsupported. */ \
- 0
-
-#endif
-
-/* ========================================================================= */
-
-#if USE_WINDOWS_THREADS
-
-# define WIN32_LEAN_AND_MEAN /* avoid including junk */
-# include <windows.h>
-
-/* ------------------------- gl_tls_key_t datatype ------------------------- */
-
-typedef DWORD gl_tls_key_t;
-# define glthread_tls_key_init(KEY, DESTRUCTOR) \
- /* The destructor is unsupported. */ \
- ((*(KEY) = TlsAlloc ()) == (DWORD)-1 ? EAGAIN : ((void) (DESTRUCTOR), 0))
-# define gl_tls_get(NAME) \
- TlsGetValue (NAME)
-# define glthread_tls_set(KEY, POINTER) \
- (!TlsSetValue (*(KEY), POINTER) ? EINVAL : 0)
-# define glthread_tls_key_destroy(KEY) \
- (!TlsFree (*(KEY)) ? EINVAL : 0)
-
-#endif
-
-/* ========================================================================= */
-
-#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS)
-
-/* Provide dummy implementation if threads are not supported. */
-
-/* ------------------------- gl_tls_key_t datatype ------------------------- */
-
-typedef struct
- {
- void *singlethread_value;
- }
- gl_tls_key_t;
-# define glthread_tls_key_init(KEY, DESTRUCTOR) \
- ((KEY)->singlethread_value = NULL, \
- (void) (DESTRUCTOR), \
- 0)
-# define gl_tls_get(NAME) \
- (NAME).singlethread_value
-# define glthread_tls_set(KEY, POINTER) \
- ((KEY)->singlethread_value = (POINTER), 0)
-# define glthread_tls_key_destroy(KEY) \
- 0
-
-#endif
-
-/* ========================================================================= */
-
-/* Macros with built-in error handling. */
-
-/* ------------------------- gl_tls_key_t datatype ------------------------- */
-
-#define gl_tls_key_init(NAME, DESTRUCTOR) \
- do \
- { \
- if (glthread_tls_key_init (&NAME, DESTRUCTOR)) \
- abort (); \
- } \
- while (0)
-#define gl_tls_set(NAME, POINTER) \
- do \
- { \
- if (glthread_tls_set (&NAME, POINTER)) \
- abort (); \
- } \
- while (0)
-#define gl_tls_key_destroy(NAME) \
- do \
- { \
- if (glthread_tls_key_destroy (&NAME)) \
- abort (); \
- } \
- while (0)
-
-/* ========================================================================= */
-
-#endif /* _TLS_H */
+/* Thread-local storage in multithreaded situations.
+ Copyright (C) 2005, 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
+
+/* This file contains thread-local storage primitives for use with a given
+ thread library. It does not contain primitives for creating threads or
+ for other multithreading primitives.
+
+ Type: gl_tls_key_t
+ Initialization: gl_tls_key_init (name, destructor);
+ Getting per-thread value: gl_tls_get (name)
+ Setting per-thread value: gl_tls_set (name, pointer);
+ De-initialization: gl_tls_key_destroy (name);
+ Equivalent functions with control of error handling:
+ Initialization: err = glthread_tls_key_init (&name, destructor);
+ Setting per-thread value: err = glthread_tls_set (&name, pointer);
+ De-initialization: err = glthread_tls_key_destroy (&name);
+
+ A per-thread value is of type 'void *'.
+
+ A destructor is a function pointer of type 'void (*) (void *)', called
+ when a thread exits, and taking the last per-thread value as argument. It
+ is unspecified whether the destructor function is called when the last
+ per-thread value is NULL. On some platforms, the destructor function is
+ not called at all.
+*/
+
+
+#ifndef _TLS_H
+#define _TLS_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library. */
+
+# include <pthread.h>
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The pthread_in_use() detection needs to be done at runtime. */
+# define pthread_in_use() \
+ glthread_in_use ()
+extern int glthread_in_use (void);
+
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+
+/* Use weak references to the POSIX threads library. */
+
+# pragma weak pthread_key_create
+# pragma weak pthread_getspecific
+# pragma weak pthread_setspecific
+# pragma weak pthread_key_delete
+# ifndef pthread_self
+# pragma weak pthread_self
+# endif
+
+# if !PTHREAD_IN_USE_DETECTION_HARD
+# pragma weak pthread_cancel
+# define pthread_in_use() (pthread_cancel != NULL)
+# endif
+
+# else
+
+# if !PTHREAD_IN_USE_DETECTION_HARD
+# define pthread_in_use() 1
+# endif
+
+# endif
+
+/* ------------------------- gl_tls_key_t datatype ------------------------- */
+
+typedef union
+ {
+ void *singlethread_value;
+ pthread_key_t key;
+ }
+ gl_tls_key_t;
+# define glthread_tls_key_init(KEY, DESTRUCTOR) \
+ (pthread_in_use () \
+ ? pthread_key_create (&(KEY)->key, DESTRUCTOR) \
+ : ((KEY)->singlethread_value = NULL, 0))
+# define gl_tls_get(NAME) \
+ (pthread_in_use () \
+ ? pthread_getspecific ((NAME).key) \
+ : (NAME).singlethread_value)
+# define glthread_tls_set(KEY, POINTER) \
+ (pthread_in_use () \
+ ? pthread_setspecific ((KEY)->key, (POINTER)) \
+ : ((KEY)->singlethread_value = (POINTER), 0))
+# define glthread_tls_key_destroy(KEY) \
+ (pthread_in_use () ? pthread_key_delete ((KEY)->key) : 0)
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library. */
+
+# include <pth.h>
+
+# if USE_PTH_THREADS_WEAK
+
+/* Use weak references to the GNU Pth threads library. */
+
+# pragma weak pth_key_create
+# pragma weak pth_key_getdata
+# pragma weak pth_key_setdata
+# pragma weak pth_key_delete
+
+# pragma weak pth_cancel
+# define pth_in_use() (pth_cancel != NULL)
+
+# else
+
+# define pth_in_use() 1
+
+# endif
+
+/* ------------------------- gl_tls_key_t datatype ------------------------- */
+
+typedef union
+ {
+ void *singlethread_value;
+ pth_key_t key;
+ }
+ gl_tls_key_t;
+# define glthread_tls_key_init(KEY, DESTRUCTOR) \
+ (pth_in_use () \
+ ? (!pth_key_create (&(KEY)->key, DESTRUCTOR) ? errno : 0) \
+ : ((KEY)->singlethread_value = NULL, 0))
+# define gl_tls_get(NAME) \
+ (pth_in_use () \
+ ? pth_key_getdata ((NAME).key) \
+ : (NAME).singlethread_value)
+# define glthread_tls_set(KEY, POINTER) \
+ (pth_in_use () \
+ ? (!pth_key_setdata ((KEY)->key, (POINTER)) ? errno : 0) \
+ : ((KEY)->singlethread_value = (POINTER), 0))
+# define glthread_tls_key_destroy(KEY) \
+ (pth_in_use () \
+ ? (!pth_key_delete ((KEY)->key) ? errno : 0) \
+ : 0)
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library. */
+
+# include <thread.h>
+
+# if USE_SOLARIS_THREADS_WEAK
+
+/* Use weak references to the old Solaris threads library. */
+
+# pragma weak thr_keycreate
+# pragma weak thr_getspecific
+# pragma weak thr_setspecific
+
+# pragma weak thr_suspend
+# define thread_in_use() (thr_suspend != NULL)
+
+# else
+
+# define thread_in_use() 1
+
+# endif
+
+/* ------------------------- gl_tls_key_t datatype ------------------------- */
+
+typedef union
+ {
+ void *singlethread_value;
+ thread_key_t key;
+ }
+ gl_tls_key_t;
+# define glthread_tls_key_init(KEY, DESTRUCTOR) \
+ (thread_in_use () \
+ ? thr_keycreate (&(KEY)->key, DESTRUCTOR) \
+ : ((KEY)->singlethread_value = NULL, 0))
+# define gl_tls_get(NAME) \
+ (thread_in_use () \
+ ? glthread_tls_get_multithreaded ((NAME).key) \
+ : (NAME).singlethread_value)
+extern void *glthread_tls_get_multithreaded (thread_key_t key);
+# define glthread_tls_set(KEY, POINTER) \
+ (thread_in_use () \
+ ? thr_setspecific ((KEY)->key, (POINTER)) \
+ : ((KEY)->singlethread_value = (POINTER), 0))
+# define glthread_tls_key_destroy(KEY) \
+ /* Unsupported. */ \
+ 0
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WINDOWS_THREADS
+
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+
+/* ------------------------- gl_tls_key_t datatype ------------------------- */
+
+typedef DWORD gl_tls_key_t;
+# define glthread_tls_key_init(KEY, DESTRUCTOR) \
+ /* The destructor is unsupported. */ \
+ ((*(KEY) = TlsAlloc ()) == (DWORD)-1 ? EAGAIN : ((void) (DESTRUCTOR), 0))
+# define gl_tls_get(NAME) \
+ TlsGetValue (NAME)
+# define glthread_tls_set(KEY, POINTER) \
+ (!TlsSetValue (*(KEY), POINTER) ? EINVAL : 0)
+# define glthread_tls_key_destroy(KEY) \
+ (!TlsFree (*(KEY)) ? EINVAL : 0)
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS)
+
+/* Provide dummy implementation if threads are not supported. */
+
+/* ------------------------- gl_tls_key_t datatype ------------------------- */
+
+typedef struct
+ {
+ void *singlethread_value;
+ }
+ gl_tls_key_t;
+# define glthread_tls_key_init(KEY, DESTRUCTOR) \
+ ((KEY)->singlethread_value = NULL, \
+ (void) (DESTRUCTOR), \
+ 0)
+# define gl_tls_get(NAME) \
+ (NAME).singlethread_value
+# define glthread_tls_set(KEY, POINTER) \
+ ((KEY)->singlethread_value = (POINTER), 0)
+# define glthread_tls_key_destroy(KEY) \
+ 0
+
+#endif
+
+/* ========================================================================= */
+
+/* Macros with built-in error handling. */
+
+/* ------------------------- gl_tls_key_t datatype ------------------------- */
+
+#define gl_tls_key_init(NAME, DESTRUCTOR) \
+ do \
+ { \
+ if (glthread_tls_key_init (&NAME, DESTRUCTOR)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_tls_set(NAME, POINTER) \
+ do \
+ { \
+ if (glthread_tls_set (&NAME, POINTER)) \
+ abort (); \
+ } \
+ while (0)
+#define gl_tls_key_destroy(NAME) \
+ do \
+ { \
+ if (glthread_tls_key_destroy (&NAME)) \
+ abort (); \
+ } \
+ while (0)
+
+/* ========================================================================= */
+
+#endif /* _TLS_H */
diff --git a/contrib/tools/bison/gnulib/src/hash.c b/contrib/tools/bison/gnulib/src/hash.c
index 685928ec0c..5d4bb31208 100644
--- a/contrib/tools/bison/gnulib/src/hash.c
+++ b/contrib/tools/bison/gnulib/src/hash.c
@@ -1,1233 +1,1233 @@
-/* hash - hashing table processing.
-
- Copyright (C) 1998-2004, 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- Written by Jim Meyering, 1992.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* A generic hash table package. */
-
-/* Define USE_OBSTACK to 1 if you want the allocator to use obstacks instead
- of malloc. If you change USE_OBSTACK, you have to recompile! */
-
-#include <config.h>
-
-#include "hash.h"
-
-#include "bitrotate.h"
-#include "xalloc-oversized.h"
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#if USE_OBSTACK
-# include "obstack.h"
-# ifndef obstack_chunk_alloc
-# define obstack_chunk_alloc malloc
-# endif
-# ifndef obstack_chunk_free
-# define obstack_chunk_free free
-# endif
-#endif
-
-struct hash_entry
- {
- void *data;
- struct hash_entry *next;
- };
-
-struct hash_table
- {
- /* The array of buckets starts at BUCKET and extends to BUCKET_LIMIT-1,
- for a possibility of N_BUCKETS. Among those, N_BUCKETS_USED buckets
- are not empty, there are N_ENTRIES active entries in the table. */
- struct hash_entry *bucket;
- struct hash_entry const *bucket_limit;
- size_t n_buckets;
- size_t n_buckets_used;
- size_t n_entries;
-
- /* Tuning arguments, kept in a physically separate structure. */
- const Hash_tuning *tuning;
-
- /* Three functions are given to 'hash_initialize', see the documentation
- block for this function. In a word, HASHER randomizes a user entry
- into a number up from 0 up to some maximum minus 1; COMPARATOR returns
- true if two user entries compare equally; and DATA_FREER is the cleanup
- function for a user entry. */
- Hash_hasher hasher;
- Hash_comparator comparator;
- Hash_data_freer data_freer;
-
- /* A linked list of freed struct hash_entry structs. */
- struct hash_entry *free_entry_list;
-
-#if USE_OBSTACK
- /* Whenever obstacks are used, it is possible to allocate all overflowed
- entries into a single stack, so they all can be freed in a single
- operation. It is not clear if the speedup is worth the trouble. */
- struct obstack entry_stack;
-#endif
- };
-
-/* A hash table contains many internal entries, each holding a pointer to
- some user-provided data (also called a user entry). An entry indistinctly
- refers to both the internal entry and its associated user entry. A user
- entry contents may be hashed by a randomization function (the hashing
- function, or just "hasher" for short) into a number (or "slot") between 0
- and the current table size. At each slot position in the hash table,
- starts a linked chain of entries for which the user data all hash to this
- slot. A bucket is the collection of all entries hashing to the same slot.
-
- A good "hasher" function will distribute entries rather evenly in buckets.
- In the ideal case, the length of each bucket is roughly the number of
- entries divided by the table size. Finding the slot for a data is usually
- done in constant time by the "hasher", and the later finding of a precise
- entry is linear in time with the size of the bucket. Consequently, a
- larger hash table size (that is, a larger number of buckets) is prone to
- yielding shorter chains, *given* the "hasher" function behaves properly.
-
- Long buckets slow down the lookup algorithm. One might use big hash table
- sizes in hope to reduce the average length of buckets, but this might
- become inordinate, as unused slots in the hash table take some space. The
- best bet is to make sure you are using a good "hasher" function (beware
- that those are not that easy to write! :-), and to use a table size
- larger than the actual number of entries. */
-
-/* If an insertion makes the ratio of nonempty buckets to table size larger
- than the growth threshold (a number between 0.0 and 1.0), then increase
- the table size by multiplying by the growth factor (a number greater than
- 1.0). The growth threshold defaults to 0.8, and the growth factor
- defaults to 1.414, meaning that the table will have doubled its size
- every second time 80% of the buckets get used. */
-#define DEFAULT_GROWTH_THRESHOLD 0.8f
-#define DEFAULT_GROWTH_FACTOR 1.414f
-
-/* If a deletion empties a bucket and causes the ratio of used buckets to
- table size to become smaller than the shrink threshold (a number between
- 0.0 and 1.0), then shrink the table by multiplying by the shrink factor (a
- number greater than the shrink threshold but smaller than 1.0). The shrink
- threshold and factor default to 0.0 and 1.0, meaning that the table never
- shrinks. */
-#define DEFAULT_SHRINK_THRESHOLD 0.0f
-#define DEFAULT_SHRINK_FACTOR 1.0f
-
-/* Use this to initialize or reset a TUNING structure to
- some sensible values. */
-static const Hash_tuning default_tuning =
- {
- DEFAULT_SHRINK_THRESHOLD,
- DEFAULT_SHRINK_FACTOR,
- DEFAULT_GROWTH_THRESHOLD,
- DEFAULT_GROWTH_FACTOR,
- false
- };
-
-/* Information and lookup. */
-
-/* The following few functions provide information about the overall hash
- table organization: the number of entries, number of buckets and maximum
- length of buckets. */
-
-/* Return the number of buckets in the hash table. The table size, the total
- number of buckets (used plus unused), or the maximum number of slots, are
- the same quantity. */
-
-size_t
-hash_get_n_buckets (const Hash_table *table)
-{
- return table->n_buckets;
-}
-
-/* Return the number of slots in use (non-empty buckets). */
-
-size_t
-hash_get_n_buckets_used (const Hash_table *table)
-{
- return table->n_buckets_used;
-}
-
-/* Return the number of active entries. */
-
-size_t
-hash_get_n_entries (const Hash_table *table)
-{
- return table->n_entries;
-}
-
-/* Return the length of the longest chain (bucket). */
-
-size_t
-hash_get_max_bucket_length (const Hash_table *table)
-{
- struct hash_entry const *bucket;
- size_t max_bucket_length = 0;
-
- for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
- {
- if (bucket->data)
- {
- struct hash_entry const *cursor = bucket;
- size_t bucket_length = 1;
-
- while (cursor = cursor->next, cursor)
- bucket_length++;
-
- if (bucket_length > max_bucket_length)
- max_bucket_length = bucket_length;
- }
- }
-
- return max_bucket_length;
-}
-
-/* Do a mild validation of a hash table, by traversing it and checking two
- statistics. */
-
-bool
-hash_table_ok (const Hash_table *table)
-{
- struct hash_entry const *bucket;
- size_t n_buckets_used = 0;
- size_t n_entries = 0;
-
- for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
- {
- if (bucket->data)
- {
- struct hash_entry const *cursor = bucket;
-
- /* Count bucket head. */
- n_buckets_used++;
- n_entries++;
-
- /* Count bucket overflow. */
- while (cursor = cursor->next, cursor)
- n_entries++;
- }
- }
-
- if (n_buckets_used == table->n_buckets_used && n_entries == table->n_entries)
- return true;
-
- return false;
-}
-
-void
-hash_print_statistics (const Hash_table *table, FILE *stream)
-{
- size_t n_entries = hash_get_n_entries (table);
- size_t n_buckets = hash_get_n_buckets (table);
- size_t n_buckets_used = hash_get_n_buckets_used (table);
- size_t max_bucket_length = hash_get_max_bucket_length (table);
-
- fprintf (stream, "# entries: %lu\n", (unsigned long int) n_entries);
- fprintf (stream, "# buckets: %lu\n", (unsigned long int) n_buckets);
- fprintf (stream, "# buckets used: %lu (%.2f%%)\n",
- (unsigned long int) n_buckets_used,
- (100.0 * n_buckets_used) / n_buckets);
- fprintf (stream, "max bucket length: %lu\n",
- (unsigned long int) max_bucket_length);
-}
-
-/* Hash KEY and return a pointer to the selected bucket.
- If TABLE->hasher misbehaves, abort. */
-static struct hash_entry *
-safe_hasher (const Hash_table *table, const void *key)
-{
- size_t n = table->hasher (key, table->n_buckets);
- if (! (n < table->n_buckets))
- abort ();
- return table->bucket + n;
-}
-
-/* If ENTRY matches an entry already in the hash table, return the
- entry from the table. Otherwise, return NULL. */
-
-void *
-hash_lookup (const Hash_table *table, const void *entry)
-{
- struct hash_entry const *bucket = safe_hasher (table, entry);
- struct hash_entry const *cursor;
-
- if (bucket->data == NULL)
- return NULL;
-
- for (cursor = bucket; cursor; cursor = cursor->next)
- if (entry == cursor->data || table->comparator (entry, cursor->data))
- return cursor->data;
-
- return NULL;
-}
-
-/* Walking. */
-
-/* The functions in this page traverse the hash table and process the
- contained entries. For the traversal to work properly, the hash table
- should not be resized nor modified while any particular entry is being
- processed. In particular, entries should not be added, and an entry
- may be removed only if there is no shrink threshold and the entry being
- removed has already been passed to hash_get_next. */
-
-/* Return the first data in the table, or NULL if the table is empty. */
-
-void *
-hash_get_first (const Hash_table *table)
-{
- struct hash_entry const *bucket;
-
- if (table->n_entries == 0)
- return NULL;
-
- for (bucket = table->bucket; ; bucket++)
- if (! (bucket < table->bucket_limit))
- abort ();
- else if (bucket->data)
- return bucket->data;
-}
-
-/* Return the user data for the entry following ENTRY, where ENTRY has been
- returned by a previous call to either 'hash_get_first' or 'hash_get_next'.
- Return NULL if there are no more entries. */
-
-void *
-hash_get_next (const Hash_table *table, const void *entry)
-{
- struct hash_entry const *bucket = safe_hasher (table, entry);
- struct hash_entry const *cursor;
-
- /* Find next entry in the same bucket. */
- cursor = bucket;
- do
- {
- if (cursor->data == entry && cursor->next)
- return cursor->next->data;
- cursor = cursor->next;
- }
- while (cursor != NULL);
-
- /* Find first entry in any subsequent bucket. */
- while (++bucket < table->bucket_limit)
- if (bucket->data)
- return bucket->data;
-
- /* None found. */
- return NULL;
-}
-
-/* Fill BUFFER with pointers to active user entries in the hash table, then
- return the number of pointers copied. Do not copy more than BUFFER_SIZE
- pointers. */
-
-size_t
-hash_get_entries (const Hash_table *table, void **buffer,
- size_t buffer_size)
-{
- size_t counter = 0;
- struct hash_entry const *bucket;
- struct hash_entry const *cursor;
-
- for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
- {
- if (bucket->data)
- {
- for (cursor = bucket; cursor; cursor = cursor->next)
- {
- if (counter >= buffer_size)
- return counter;
- buffer[counter++] = cursor->data;
- }
- }
- }
-
- return counter;
-}
-
-/* Call a PROCESSOR function for each entry of a hash table, and return the
- number of entries for which the processor function returned success. A
- pointer to some PROCESSOR_DATA which will be made available to each call to
- the processor function. The PROCESSOR accepts two arguments: the first is
- the user entry being walked into, the second is the value of PROCESSOR_DATA
- as received. The walking continue for as long as the PROCESSOR function
- returns nonzero. When it returns zero, the walking is interrupted. */
-
-size_t
-hash_do_for_each (const Hash_table *table, Hash_processor processor,
- void *processor_data)
-{
- size_t counter = 0;
- struct hash_entry const *bucket;
- struct hash_entry const *cursor;
-
- for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
- {
- if (bucket->data)
- {
- for (cursor = bucket; cursor; cursor = cursor->next)
- {
- if (! processor (cursor->data, processor_data))
- return counter;
- counter++;
- }
- }
- }
-
- return counter;
-}
-
-/* Allocation and clean-up. */
-
-/* Return a hash index for a NUL-terminated STRING between 0 and N_BUCKETS-1.
- This is a convenience routine for constructing other hashing functions. */
-
-#if USE_DIFF_HASH
-
-/* About hashings, Paul Eggert writes to me (FP), on 1994-01-01: "Please see
- B. J. McKenzie, R. Harries & T. Bell, Selecting a hashing algorithm,
- Software--practice & experience 20, 2 (Feb 1990), 209-224. Good hash
- algorithms tend to be domain-specific, so what's good for [diffutils'] io.c
- may not be good for your application." */
-
-size_t
-hash_string (const char *string, size_t n_buckets)
-{
-# define HASH_ONE_CHAR(Value, Byte) \
- ((Byte) + rotl_sz (Value, 7))
-
- size_t value = 0;
- unsigned char ch;
-
- for (; (ch = *string); string++)
- value = HASH_ONE_CHAR (value, ch);
- return value % n_buckets;
-
-# undef HASH_ONE_CHAR
-}
-
-#else /* not USE_DIFF_HASH */
-
-/* This one comes from 'recode', and performs a bit better than the above as
- per a few experiments. It is inspired from a hashing routine found in the
- very old Cyber 'snoop', itself written in typical Greg Mansfield style.
- (By the way, what happened to this excellent man? Is he still alive?) */
-
-size_t
-hash_string (const char *string, size_t n_buckets)
-{
- size_t value = 0;
- unsigned char ch;
-
- for (; (ch = *string); string++)
- value = (value * 31 + ch) % n_buckets;
- return value;
-}
-
-#endif /* not USE_DIFF_HASH */
-
-/* Return true if CANDIDATE is a prime number. CANDIDATE should be an odd
- number at least equal to 11. */
-
-static bool _GL_ATTRIBUTE_CONST
-is_prime (size_t candidate)
-{
- size_t divisor = 3;
- size_t square = divisor * divisor;
-
- while (square < candidate && (candidate % divisor))
- {
- divisor++;
- square += 4 * divisor;
- divisor++;
- }
-
- return (candidate % divisor ? true : false);
-}
-
-/* Round a given CANDIDATE number up to the nearest prime, and return that
- prime. Primes lower than 10 are merely skipped. */
-
-static size_t _GL_ATTRIBUTE_CONST
-next_prime (size_t candidate)
-{
- /* Skip small primes. */
- if (candidate < 10)
- candidate = 10;
-
- /* Make it definitely odd. */
- candidate |= 1;
-
- while (SIZE_MAX != candidate && !is_prime (candidate))
- candidate += 2;
-
- return candidate;
-}
-
-void
-hash_reset_tuning (Hash_tuning *tuning)
-{
- *tuning = default_tuning;
-}
-
-/* If the user passes a NULL hasher, we hash the raw pointer. */
-static size_t
-raw_hasher (const void *data, size_t n)
-{
- /* When hashing unique pointers, it is often the case that they were
- generated by malloc and thus have the property that the low-order
- bits are 0. As this tends to give poorer performance with small
- tables, we rotate the pointer value before performing division,
- in an attempt to improve hash quality. */
- size_t val = rotr_sz ((size_t) data, 3);
- return val % n;
-}
-
-/* If the user passes a NULL comparator, we use pointer comparison. */
-static bool
-raw_comparator (const void *a, const void *b)
-{
- return a == b;
-}
-
-
-/* For the given hash TABLE, check the user supplied tuning structure for
- reasonable values, and return true if there is no gross error with it.
- Otherwise, definitively reset the TUNING field to some acceptable default
- in the hash table (that is, the user loses the right of further modifying
- tuning arguments), and return false. */
-
-static bool
-check_tuning (Hash_table *table)
-{
- const Hash_tuning *tuning = table->tuning;
- float epsilon;
- if (tuning == &default_tuning)
- return true;
-
- /* Be a bit stricter than mathematics would require, so that
- rounding errors in size calculations do not cause allocations to
- fail to grow or shrink as they should. The smallest allocation
- is 11 (due to next_prime's algorithm), so an epsilon of 0.1
- should be good enough. */
- epsilon = 0.1f;
-
- if (epsilon < tuning->growth_threshold
- && tuning->growth_threshold < 1 - epsilon
- && 1 + epsilon < tuning->growth_factor
- && 0 <= tuning->shrink_threshold
- && tuning->shrink_threshold + epsilon < tuning->shrink_factor
- && tuning->shrink_factor <= 1
- && tuning->shrink_threshold + epsilon < tuning->growth_threshold)
- return true;
-
- table->tuning = &default_tuning;
- return false;
-}
-
-/* Compute the size of the bucket array for the given CANDIDATE and
- TUNING, or return 0 if there is no possible way to allocate that
- many entries. */
-
-static size_t _GL_ATTRIBUTE_PURE
-compute_bucket_size (size_t candidate, const Hash_tuning *tuning)
-{
- if (!tuning->is_n_buckets)
- {
- float new_candidate = candidate / tuning->growth_threshold;
- if (SIZE_MAX <= new_candidate)
- return 0;
- candidate = new_candidate;
- }
- candidate = next_prime (candidate);
- if (xalloc_oversized (candidate, sizeof (struct hash_entry *)))
- return 0;
- return candidate;
-}
-
-/* Allocate and return a new hash table, or NULL upon failure. The initial
- number of buckets is automatically selected so as to _guarantee_ that you
- may insert at least CANDIDATE different user entries before any growth of
- the hash table size occurs. So, if have a reasonably tight a-priori upper
- bound on the number of entries you intend to insert in the hash table, you
- may save some table memory and insertion time, by specifying it here. If
- the IS_N_BUCKETS field of the TUNING structure is true, the CANDIDATE
- argument has its meaning changed to the wanted number of buckets.
-
- TUNING points to a structure of user-supplied values, in case some fine
- tuning is wanted over the default behavior of the hasher. If TUNING is
- NULL, the default tuning parameters are used instead. If TUNING is
- provided but the values requested are out of bounds or might cause
- rounding errors, return NULL.
-
- The user-supplied HASHER function, when not NULL, accepts two
- arguments ENTRY and TABLE_SIZE. It computes, by hashing ENTRY contents, a
- slot number for that entry which should be in the range 0..TABLE_SIZE-1.
- This slot number is then returned.
-
- The user-supplied COMPARATOR function, when not NULL, accepts two
- arguments pointing to user data, it then returns true for a pair of entries
- that compare equal, or false otherwise. This function is internally called
- on entries which are already known to hash to the same bucket index,
- but which are distinct pointers.
-
- The user-supplied DATA_FREER function, when not NULL, may be later called
- with the user data as an argument, just before the entry containing the
- data gets freed. This happens from within 'hash_free' or 'hash_clear'.
- You should specify this function only if you want these functions to free
- all of your 'data' data. This is typically the case when your data is
- simply an auxiliary struct that you have malloc'd to aggregate several
- values. */
-
-Hash_table *
-hash_initialize (size_t candidate, const Hash_tuning *tuning,
- Hash_hasher hasher, Hash_comparator comparator,
- Hash_data_freer data_freer)
-{
- Hash_table *table;
-
- if (hasher == NULL)
- hasher = raw_hasher;
- if (comparator == NULL)
- comparator = raw_comparator;
-
- table = malloc (sizeof *table);
- if (table == NULL)
- return NULL;
-
- if (!tuning)
- tuning = &default_tuning;
- table->tuning = tuning;
- if (!check_tuning (table))
- {
- /* Fail if the tuning options are invalid. This is the only occasion
- when the user gets some feedback about it. Once the table is created,
- if the user provides invalid tuning options, we silently revert to
- using the defaults, and ignore further request to change the tuning
- options. */
- goto fail;
- }
-
- table->n_buckets = compute_bucket_size (candidate, tuning);
- if (!table->n_buckets)
- goto fail;
-
- table->bucket = calloc (table->n_buckets, sizeof *table->bucket);
- if (table->bucket == NULL)
- goto fail;
- table->bucket_limit = table->bucket + table->n_buckets;
- table->n_buckets_used = 0;
- table->n_entries = 0;
-
- table->hasher = hasher;
- table->comparator = comparator;
- table->data_freer = data_freer;
-
- table->free_entry_list = NULL;
-#if USE_OBSTACK
- obstack_init (&table->entry_stack);
-#endif
- return table;
-
- fail:
- free (table);
- return NULL;
-}
-
-/* Make all buckets empty, placing any chained entries on the free list.
- Apply the user-specified function data_freer (if any) to the datas of any
- affected entries. */
-
-void
-hash_clear (Hash_table *table)
-{
- struct hash_entry *bucket;
-
- for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
- {
- if (bucket->data)
- {
- struct hash_entry *cursor;
- struct hash_entry *next;
-
- /* Free the bucket overflow. */
- for (cursor = bucket->next; cursor; cursor = next)
- {
- if (table->data_freer)
- table->data_freer (cursor->data);
- cursor->data = NULL;
-
- next = cursor->next;
- /* Relinking is done one entry at a time, as it is to be expected
- that overflows are either rare or short. */
- cursor->next = table->free_entry_list;
- table->free_entry_list = cursor;
- }
-
- /* Free the bucket head. */
- if (table->data_freer)
- table->data_freer (bucket->data);
- bucket->data = NULL;
- bucket->next = NULL;
- }
- }
-
- table->n_buckets_used = 0;
- table->n_entries = 0;
-}
-
-/* Reclaim all storage associated with a hash table. If a data_freer
- function has been supplied by the user when the hash table was created,
- this function applies it to the data of each entry before freeing that
- entry. */
-
-void
-hash_free (Hash_table *table)
-{
- struct hash_entry *bucket;
- struct hash_entry *cursor;
- struct hash_entry *next;
-
- /* Call the user data_freer function. */
- if (table->data_freer && table->n_entries)
- {
- for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
- {
- if (bucket->data)
- {
- for (cursor = bucket; cursor; cursor = cursor->next)
- table->data_freer (cursor->data);
- }
- }
- }
-
-#if USE_OBSTACK
-
- obstack_free (&table->entry_stack, NULL);
-
-#else
-
- /* Free all bucket overflowed entries. */
- for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
- {
- for (cursor = bucket->next; cursor; cursor = next)
- {
- next = cursor->next;
- free (cursor);
- }
- }
-
- /* Also reclaim the internal list of previously freed entries. */
- for (cursor = table->free_entry_list; cursor; cursor = next)
- {
- next = cursor->next;
- free (cursor);
- }
-
-#endif
-
- /* Free the remainder of the hash table structure. */
- free (table->bucket);
- free (table);
-}
-
-/* Insertion and deletion. */
-
-/* Get a new hash entry for a bucket overflow, possibly by recycling a
- previously freed one. If this is not possible, allocate a new one. */
-
-static struct hash_entry *
-allocate_entry (Hash_table *table)
-{
- struct hash_entry *new;
-
- if (table->free_entry_list)
- {
- new = table->free_entry_list;
- table->free_entry_list = new->next;
- }
- else
- {
-#if USE_OBSTACK
- new = obstack_alloc (&table->entry_stack, sizeof *new);
-#else
- new = malloc (sizeof *new);
-#endif
- }
-
- return new;
-}
-
-/* Free a hash entry which was part of some bucket overflow,
- saving it for later recycling. */
-
-static void
-free_entry (Hash_table *table, struct hash_entry *entry)
-{
- entry->data = NULL;
- entry->next = table->free_entry_list;
- table->free_entry_list = entry;
-}
-
-/* This private function is used to help with insertion and deletion. When
- ENTRY matches an entry in the table, return a pointer to the corresponding
- user data and set *BUCKET_HEAD to the head of the selected bucket.
- Otherwise, return NULL. When DELETE is true and ENTRY matches an entry in
- the table, unlink the matching entry. */
-
-static void *
-hash_find_entry (Hash_table *table, const void *entry,
- struct hash_entry **bucket_head, bool delete)
-{
- struct hash_entry *bucket = safe_hasher (table, entry);
- struct hash_entry *cursor;
-
- *bucket_head = bucket;
-
- /* Test for empty bucket. */
- if (bucket->data == NULL)
- return NULL;
-
- /* See if the entry is the first in the bucket. */
- if (entry == bucket->data || table->comparator (entry, bucket->data))
- {
- void *data = bucket->data;
-
- if (delete)
- {
- if (bucket->next)
- {
- struct hash_entry *next = bucket->next;
-
- /* Bump the first overflow entry into the bucket head, then save
- the previous first overflow entry for later recycling. */
- *bucket = *next;
- free_entry (table, next);
- }
- else
- {
- bucket->data = NULL;
- }
- }
-
- return data;
- }
-
- /* Scan the bucket overflow. */
- for (cursor = bucket; cursor->next; cursor = cursor->next)
- {
- if (entry == cursor->next->data
- || table->comparator (entry, cursor->next->data))
- {
- void *data = cursor->next->data;
-
- if (delete)
- {
- struct hash_entry *next = cursor->next;
-
- /* Unlink the entry to delete, then save the freed entry for later
- recycling. */
- cursor->next = next->next;
- free_entry (table, next);
- }
-
- return data;
- }
- }
-
- /* No entry found. */
- return NULL;
-}
-
-/* Internal helper, to move entries from SRC to DST. Both tables must
- share the same free entry list. If SAFE, only move overflow
- entries, saving bucket heads for later, so that no allocations will
- occur. Return false if the free entry list is exhausted and an
- allocation fails. */
-
-static bool
-transfer_entries (Hash_table *dst, Hash_table *src, bool safe)
-{
- struct hash_entry *bucket;
- struct hash_entry *cursor;
- struct hash_entry *next;
- for (bucket = src->bucket; bucket < src->bucket_limit; bucket++)
- if (bucket->data)
- {
- void *data;
- struct hash_entry *new_bucket;
-
- /* Within each bucket, transfer overflow entries first and
- then the bucket head, to minimize memory pressure. After
- all, the only time we might allocate is when moving the
- bucket head, but moving overflow entries first may create
- free entries that can be recycled by the time we finally
- get to the bucket head. */
- for (cursor = bucket->next; cursor; cursor = next)
- {
- data = cursor->data;
- new_bucket = safe_hasher (dst, data);
-
- next = cursor->next;
-
- if (new_bucket->data)
- {
- /* Merely relink an existing entry, when moving from a
- bucket overflow into a bucket overflow. */
- cursor->next = new_bucket->next;
- new_bucket->next = cursor;
- }
- else
- {
- /* Free an existing entry, when moving from a bucket
- overflow into a bucket header. */
- new_bucket->data = data;
- dst->n_buckets_used++;
- free_entry (dst, cursor);
- }
- }
- /* Now move the bucket head. Be sure that if we fail due to
- allocation failure that the src table is in a consistent
- state. */
- data = bucket->data;
- bucket->next = NULL;
- if (safe)
- continue;
- new_bucket = safe_hasher (dst, data);
-
- if (new_bucket->data)
- {
- /* Allocate or recycle an entry, when moving from a bucket
- header into a bucket overflow. */
- struct hash_entry *new_entry = allocate_entry (dst);
-
- if (new_entry == NULL)
- return false;
-
- new_entry->data = data;
- new_entry->next = new_bucket->next;
- new_bucket->next = new_entry;
- }
- else
- {
- /* Move from one bucket header to another. */
- new_bucket->data = data;
- dst->n_buckets_used++;
- }
- bucket->data = NULL;
- src->n_buckets_used--;
- }
- return true;
-}
-
-/* For an already existing hash table, change the number of buckets through
- specifying CANDIDATE. The contents of the hash table are preserved. The
- new number of buckets is automatically selected so as to _guarantee_ that
- the table may receive at least CANDIDATE different user entries, including
- those already in the table, before any other growth of the hash table size
- occurs. If TUNING->IS_N_BUCKETS is true, then CANDIDATE specifies the
- exact number of buckets desired. Return true iff the rehash succeeded. */
-
-bool
-hash_rehash (Hash_table *table, size_t candidate)
-{
- Hash_table storage;
- Hash_table *new_table;
- size_t new_size = compute_bucket_size (candidate, table->tuning);
-
- if (!new_size)
- return false;
- if (new_size == table->n_buckets)
- return true;
- new_table = &storage;
- new_table->bucket = calloc (new_size, sizeof *new_table->bucket);
- if (new_table->bucket == NULL)
- return false;
- new_table->n_buckets = new_size;
- new_table->bucket_limit = new_table->bucket + new_size;
- new_table->n_buckets_used = 0;
- new_table->n_entries = 0;
- new_table->tuning = table->tuning;
- new_table->hasher = table->hasher;
- new_table->comparator = table->comparator;
- new_table->data_freer = table->data_freer;
-
- /* In order for the transfer to successfully complete, we need
- additional overflow entries when distinct buckets in the old
- table collide into a common bucket in the new table. The worst
- case possible is a hasher that gives a good spread with the old
- size, but returns a constant with the new size; if we were to
- guarantee table->n_buckets_used-1 free entries in advance, then
- the transfer would be guaranteed to not allocate memory.
- However, for large tables, a guarantee of no further allocation
- introduces a lot of extra memory pressure, all for an unlikely
- corner case (most rehashes reduce, rather than increase, the
- number of overflow entries needed). So, we instead ensure that
- the transfer process can be reversed if we hit a memory
- allocation failure mid-transfer. */
-
- /* Merely reuse the extra old space into the new table. */
-#if USE_OBSTACK
- new_table->entry_stack = table->entry_stack;
-#endif
- new_table->free_entry_list = table->free_entry_list;
-
- if (transfer_entries (new_table, table, false))
- {
- /* Entries transferred successfully; tie up the loose ends. */
- free (table->bucket);
- table->bucket = new_table->bucket;
- table->bucket_limit = new_table->bucket_limit;
- table->n_buckets = new_table->n_buckets;
- table->n_buckets_used = new_table->n_buckets_used;
- table->free_entry_list = new_table->free_entry_list;
- /* table->n_entries and table->entry_stack already hold their value. */
- return true;
- }
-
- /* We've allocated new_table->bucket (and possibly some entries),
- exhausted the free list, and moved some but not all entries into
- new_table. We must undo the partial move before returning
- failure. The only way to get into this situation is if new_table
- uses fewer buckets than the old table, so we will reclaim some
- free entries as overflows in the new table are put back into
- distinct buckets in the old table.
-
- There are some pathological cases where a single pass through the
- table requires more intermediate overflow entries than using two
- passes. Two passes give worse cache performance and takes
- longer, but at this point, we're already out of memory, so slow
- and safe is better than failure. */
- table->free_entry_list = new_table->free_entry_list;
- if (! (transfer_entries (table, new_table, true)
- && transfer_entries (table, new_table, false)))
- abort ();
- /* table->n_entries already holds its value. */
- free (new_table->bucket);
- return false;
-}
-
-/* Insert ENTRY into hash TABLE if there is not already a matching entry.
-
- Return -1 upon memory allocation failure.
- Return 1 if insertion succeeded.
- Return 0 if there is already a matching entry in the table,
- and in that case, if MATCHED_ENT is non-NULL, set *MATCHED_ENT
- to that entry.
-
- This interface is easier to use than hash_insert when you must
- distinguish between the latter two cases. More importantly,
- hash_insert is unusable for some types of ENTRY values. When using
- hash_insert, the only way to distinguish those cases is to compare
- the return value and ENTRY. That works only when you can have two
- different ENTRY values that point to data that compares "equal". Thus,
- when the ENTRY value is a simple scalar, you must use
- hash_insert_if_absent. ENTRY must not be NULL. */
-int
-hash_insert_if_absent (Hash_table *table, void const *entry,
- void const **matched_ent)
-{
- void *data;
- struct hash_entry *bucket;
-
- /* The caller cannot insert a NULL entry, since hash_lookup returns NULL
- to indicate "not found", and hash_find_entry uses "bucket->data == NULL"
- to indicate an empty bucket. */
- if (! entry)
- abort ();
-
- /* If there's a matching entry already in the table, return that. */
- if ((data = hash_find_entry (table, entry, &bucket, false)) != NULL)
- {
- if (matched_ent)
- *matched_ent = data;
- return 0;
- }
-
- /* If the growth threshold of the buckets in use has been reached, increase
- the table size and rehash. There's no point in checking the number of
- entries: if the hashing function is ill-conditioned, rehashing is not
- likely to improve it. */
-
- if (table->n_buckets_used
- > table->tuning->growth_threshold * table->n_buckets)
- {
- /* Check more fully, before starting real work. If tuning arguments
- became invalid, the second check will rely on proper defaults. */
- check_tuning (table);
- if (table->n_buckets_used
- > table->tuning->growth_threshold * table->n_buckets)
- {
- const Hash_tuning *tuning = table->tuning;
- float candidate =
- (tuning->is_n_buckets
- ? (table->n_buckets * tuning->growth_factor)
- : (table->n_buckets * tuning->growth_factor
- * tuning->growth_threshold));
-
- if (SIZE_MAX <= candidate)
- return -1;
-
- /* If the rehash fails, arrange to return NULL. */
- if (!hash_rehash (table, candidate))
- return -1;
-
- /* Update the bucket we are interested in. */
- if (hash_find_entry (table, entry, &bucket, false) != NULL)
- abort ();
- }
- }
-
- /* ENTRY is not matched, it should be inserted. */
-
- if (bucket->data)
- {
- struct hash_entry *new_entry = allocate_entry (table);
-
- if (new_entry == NULL)
- return -1;
-
- /* Add ENTRY in the overflow of the bucket. */
-
- new_entry->data = (void *) entry;
- new_entry->next = bucket->next;
- bucket->next = new_entry;
- table->n_entries++;
- return 1;
- }
-
- /* Add ENTRY right in the bucket head. */
-
- bucket->data = (void *) entry;
- table->n_entries++;
- table->n_buckets_used++;
-
- return 1;
-}
-
-/* hash_insert0 is the deprecated name for hash_insert_if_absent.
- . */
-int
-hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent)
-{
- return hash_insert_if_absent (table, entry, matched_ent);
-}
-
-/* If ENTRY matches an entry already in the hash table, return the pointer
- to the entry from the table. Otherwise, insert ENTRY and return ENTRY.
- Return NULL if the storage required for insertion cannot be allocated.
- This implementation does not support duplicate entries or insertion of
- NULL. */
-
-void *
-hash_insert (Hash_table *table, void const *entry)
-{
- void const *matched_ent;
- int err = hash_insert_if_absent (table, entry, &matched_ent);
- return (err == -1
- ? NULL
- : (void *) (err == 0 ? matched_ent : entry));
-}
-
-/* If ENTRY is already in the table, remove it and return the just-deleted
- data (the user may want to deallocate its storage). If ENTRY is not in the
- table, don't modify the table and return NULL. */
-
-void *
-hash_delete (Hash_table *table, const void *entry)
-{
- void *data;
- struct hash_entry *bucket;
-
- data = hash_find_entry (table, entry, &bucket, true);
- if (!data)
- return NULL;
-
- table->n_entries--;
- if (!bucket->data)
- {
- table->n_buckets_used--;
-
- /* If the shrink threshold of the buckets in use has been reached,
- rehash into a smaller table. */
-
- if (table->n_buckets_used
- < table->tuning->shrink_threshold * table->n_buckets)
- {
- /* Check more fully, before starting real work. If tuning arguments
- became invalid, the second check will rely on proper defaults. */
- check_tuning (table);
- if (table->n_buckets_used
- < table->tuning->shrink_threshold * table->n_buckets)
- {
- const Hash_tuning *tuning = table->tuning;
- size_t candidate =
- (tuning->is_n_buckets
- ? table->n_buckets * tuning->shrink_factor
- : (table->n_buckets * tuning->shrink_factor
- * tuning->growth_threshold));
-
- if (!hash_rehash (table, candidate))
- {
- /* Failure to allocate memory in an attempt to
- shrink the table is not fatal. But since memory
- is low, we can at least be kind and free any
- spare entries, rather than keeping them tied up
- in the free entry list. */
-#if ! USE_OBSTACK
- struct hash_entry *cursor = table->free_entry_list;
- struct hash_entry *next;
- while (cursor)
- {
- next = cursor->next;
- free (cursor);
- cursor = next;
- }
- table->free_entry_list = NULL;
-#endif
- }
- }
- }
- }
-
- return data;
-}
-
-/* Testing. */
-
-#if TESTING
-
-void
-hash_print (const Hash_table *table)
-{
- struct hash_entry *bucket = (struct hash_entry *) table->bucket;
-
- for ( ; bucket < table->bucket_limit; bucket++)
- {
- struct hash_entry *cursor;
-
- if (bucket)
- printf ("%lu:\n", (unsigned long int) (bucket - table->bucket));
-
- for (cursor = bucket; cursor; cursor = cursor->next)
- {
- char const *s = cursor->data;
- /* FIXME */
- if (s)
- printf (" %s\n", s);
- }
- }
-}
-
-#endif /* TESTING */
+/* hash - hashing table processing.
+
+ Copyright (C) 1998-2004, 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ Written by Jim Meyering, 1992.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* A generic hash table package. */
+
+/* Define USE_OBSTACK to 1 if you want the allocator to use obstacks instead
+ of malloc. If you change USE_OBSTACK, you have to recompile! */
+
+#include <config.h>
+
+#include "hash.h"
+
+#include "bitrotate.h"
+#include "xalloc-oversized.h"
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if USE_OBSTACK
+# include "obstack.h"
+# ifndef obstack_chunk_alloc
+# define obstack_chunk_alloc malloc
+# endif
+# ifndef obstack_chunk_free
+# define obstack_chunk_free free
+# endif
+#endif
+
+struct hash_entry
+ {
+ void *data;
+ struct hash_entry *next;
+ };
+
+struct hash_table
+ {
+ /* The array of buckets starts at BUCKET and extends to BUCKET_LIMIT-1,
+ for a possibility of N_BUCKETS. Among those, N_BUCKETS_USED buckets
+ are not empty, there are N_ENTRIES active entries in the table. */
+ struct hash_entry *bucket;
+ struct hash_entry const *bucket_limit;
+ size_t n_buckets;
+ size_t n_buckets_used;
+ size_t n_entries;
+
+ /* Tuning arguments, kept in a physically separate structure. */
+ const Hash_tuning *tuning;
+
+ /* Three functions are given to 'hash_initialize', see the documentation
+ block for this function. In a word, HASHER randomizes a user entry
+ into a number up from 0 up to some maximum minus 1; COMPARATOR returns
+ true if two user entries compare equally; and DATA_FREER is the cleanup
+ function for a user entry. */
+ Hash_hasher hasher;
+ Hash_comparator comparator;
+ Hash_data_freer data_freer;
+
+ /* A linked list of freed struct hash_entry structs. */
+ struct hash_entry *free_entry_list;
+
+#if USE_OBSTACK
+ /* Whenever obstacks are used, it is possible to allocate all overflowed
+ entries into a single stack, so they all can be freed in a single
+ operation. It is not clear if the speedup is worth the trouble. */
+ struct obstack entry_stack;
+#endif
+ };
+
+/* A hash table contains many internal entries, each holding a pointer to
+ some user-provided data (also called a user entry). An entry indistinctly
+ refers to both the internal entry and its associated user entry. A user
+ entry contents may be hashed by a randomization function (the hashing
+ function, or just "hasher" for short) into a number (or "slot") between 0
+ and the current table size. At each slot position in the hash table,
+ starts a linked chain of entries for which the user data all hash to this
+ slot. A bucket is the collection of all entries hashing to the same slot.
+
+ A good "hasher" function will distribute entries rather evenly in buckets.
+ In the ideal case, the length of each bucket is roughly the number of
+ entries divided by the table size. Finding the slot for a data is usually
+ done in constant time by the "hasher", and the later finding of a precise
+ entry is linear in time with the size of the bucket. Consequently, a
+ larger hash table size (that is, a larger number of buckets) is prone to
+ yielding shorter chains, *given* the "hasher" function behaves properly.
+
+ Long buckets slow down the lookup algorithm. One might use big hash table
+ sizes in hope to reduce the average length of buckets, but this might
+ become inordinate, as unused slots in the hash table take some space. The
+ best bet is to make sure you are using a good "hasher" function (beware
+ that those are not that easy to write! :-), and to use a table size
+ larger than the actual number of entries. */
+
+/* If an insertion makes the ratio of nonempty buckets to table size larger
+ than the growth threshold (a number between 0.0 and 1.0), then increase
+ the table size by multiplying by the growth factor (a number greater than
+ 1.0). The growth threshold defaults to 0.8, and the growth factor
+ defaults to 1.414, meaning that the table will have doubled its size
+ every second time 80% of the buckets get used. */
+#define DEFAULT_GROWTH_THRESHOLD 0.8f
+#define DEFAULT_GROWTH_FACTOR 1.414f
+
+/* If a deletion empties a bucket and causes the ratio of used buckets to
+ table size to become smaller than the shrink threshold (a number between
+ 0.0 and 1.0), then shrink the table by multiplying by the shrink factor (a
+ number greater than the shrink threshold but smaller than 1.0). The shrink
+ threshold and factor default to 0.0 and 1.0, meaning that the table never
+ shrinks. */
+#define DEFAULT_SHRINK_THRESHOLD 0.0f
+#define DEFAULT_SHRINK_FACTOR 1.0f
+
+/* Use this to initialize or reset a TUNING structure to
+ some sensible values. */
+static const Hash_tuning default_tuning =
+ {
+ DEFAULT_SHRINK_THRESHOLD,
+ DEFAULT_SHRINK_FACTOR,
+ DEFAULT_GROWTH_THRESHOLD,
+ DEFAULT_GROWTH_FACTOR,
+ false
+ };
+
+/* Information and lookup. */
+
+/* The following few functions provide information about the overall hash
+ table organization: the number of entries, number of buckets and maximum
+ length of buckets. */
+
+/* Return the number of buckets in the hash table. The table size, the total
+ number of buckets (used plus unused), or the maximum number of slots, are
+ the same quantity. */
+
+size_t
+hash_get_n_buckets (const Hash_table *table)
+{
+ return table->n_buckets;
+}
+
+/* Return the number of slots in use (non-empty buckets). */
+
+size_t
+hash_get_n_buckets_used (const Hash_table *table)
+{
+ return table->n_buckets_used;
+}
+
+/* Return the number of active entries. */
+
+size_t
+hash_get_n_entries (const Hash_table *table)
+{
+ return table->n_entries;
+}
+
+/* Return the length of the longest chain (bucket). */
+
+size_t
+hash_get_max_bucket_length (const Hash_table *table)
+{
+ struct hash_entry const *bucket;
+ size_t max_bucket_length = 0;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ struct hash_entry const *cursor = bucket;
+ size_t bucket_length = 1;
+
+ while (cursor = cursor->next, cursor)
+ bucket_length++;
+
+ if (bucket_length > max_bucket_length)
+ max_bucket_length = bucket_length;
+ }
+ }
+
+ return max_bucket_length;
+}
+
+/* Do a mild validation of a hash table, by traversing it and checking two
+ statistics. */
+
+bool
+hash_table_ok (const Hash_table *table)
+{
+ struct hash_entry const *bucket;
+ size_t n_buckets_used = 0;
+ size_t n_entries = 0;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ struct hash_entry const *cursor = bucket;
+
+ /* Count bucket head. */
+ n_buckets_used++;
+ n_entries++;
+
+ /* Count bucket overflow. */
+ while (cursor = cursor->next, cursor)
+ n_entries++;
+ }
+ }
+
+ if (n_buckets_used == table->n_buckets_used && n_entries == table->n_entries)
+ return true;
+
+ return false;
+}
+
+void
+hash_print_statistics (const Hash_table *table, FILE *stream)
+{
+ size_t n_entries = hash_get_n_entries (table);
+ size_t n_buckets = hash_get_n_buckets (table);
+ size_t n_buckets_used = hash_get_n_buckets_used (table);
+ size_t max_bucket_length = hash_get_max_bucket_length (table);
+
+ fprintf (stream, "# entries: %lu\n", (unsigned long int) n_entries);
+ fprintf (stream, "# buckets: %lu\n", (unsigned long int) n_buckets);
+ fprintf (stream, "# buckets used: %lu (%.2f%%)\n",
+ (unsigned long int) n_buckets_used,
+ (100.0 * n_buckets_used) / n_buckets);
+ fprintf (stream, "max bucket length: %lu\n",
+ (unsigned long int) max_bucket_length);
+}
+
+/* Hash KEY and return a pointer to the selected bucket.
+ If TABLE->hasher misbehaves, abort. */
+static struct hash_entry *
+safe_hasher (const Hash_table *table, const void *key)
+{
+ size_t n = table->hasher (key, table->n_buckets);
+ if (! (n < table->n_buckets))
+ abort ();
+ return table->bucket + n;
+}
+
+/* If ENTRY matches an entry already in the hash table, return the
+ entry from the table. Otherwise, return NULL. */
+
+void *
+hash_lookup (const Hash_table *table, const void *entry)
+{
+ struct hash_entry const *bucket = safe_hasher (table, entry);
+ struct hash_entry const *cursor;
+
+ if (bucket->data == NULL)
+ return NULL;
+
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ if (entry == cursor->data || table->comparator (entry, cursor->data))
+ return cursor->data;
+
+ return NULL;
+}
+
+/* Walking. */
+
+/* The functions in this page traverse the hash table and process the
+ contained entries. For the traversal to work properly, the hash table
+ should not be resized nor modified while any particular entry is being
+ processed. In particular, entries should not be added, and an entry
+ may be removed only if there is no shrink threshold and the entry being
+ removed has already been passed to hash_get_next. */
+
+/* Return the first data in the table, or NULL if the table is empty. */
+
+void *
+hash_get_first (const Hash_table *table)
+{
+ struct hash_entry const *bucket;
+
+ if (table->n_entries == 0)
+ return NULL;
+
+ for (bucket = table->bucket; ; bucket++)
+ if (! (bucket < table->bucket_limit))
+ abort ();
+ else if (bucket->data)
+ return bucket->data;
+}
+
+/* Return the user data for the entry following ENTRY, where ENTRY has been
+ returned by a previous call to either 'hash_get_first' or 'hash_get_next'.
+ Return NULL if there are no more entries. */
+
+void *
+hash_get_next (const Hash_table *table, const void *entry)
+{
+ struct hash_entry const *bucket = safe_hasher (table, entry);
+ struct hash_entry const *cursor;
+
+ /* Find next entry in the same bucket. */
+ cursor = bucket;
+ do
+ {
+ if (cursor->data == entry && cursor->next)
+ return cursor->next->data;
+ cursor = cursor->next;
+ }
+ while (cursor != NULL);
+
+ /* Find first entry in any subsequent bucket. */
+ while (++bucket < table->bucket_limit)
+ if (bucket->data)
+ return bucket->data;
+
+ /* None found. */
+ return NULL;
+}
+
+/* Fill BUFFER with pointers to active user entries in the hash table, then
+ return the number of pointers copied. Do not copy more than BUFFER_SIZE
+ pointers. */
+
+size_t
+hash_get_entries (const Hash_table *table, void **buffer,
+ size_t buffer_size)
+{
+ size_t counter = 0;
+ struct hash_entry const *bucket;
+ struct hash_entry const *cursor;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ {
+ if (counter >= buffer_size)
+ return counter;
+ buffer[counter++] = cursor->data;
+ }
+ }
+ }
+
+ return counter;
+}
+
+/* Call a PROCESSOR function for each entry of a hash table, and return the
+ number of entries for which the processor function returned success. A
+ pointer to some PROCESSOR_DATA which will be made available to each call to
+ the processor function. The PROCESSOR accepts two arguments: the first is
+ the user entry being walked into, the second is the value of PROCESSOR_DATA
+ as received. The walking continue for as long as the PROCESSOR function
+ returns nonzero. When it returns zero, the walking is interrupted. */
+
+size_t
+hash_do_for_each (const Hash_table *table, Hash_processor processor,
+ void *processor_data)
+{
+ size_t counter = 0;
+ struct hash_entry const *bucket;
+ struct hash_entry const *cursor;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ {
+ if (! processor (cursor->data, processor_data))
+ return counter;
+ counter++;
+ }
+ }
+ }
+
+ return counter;
+}
+
+/* Allocation and clean-up. */
+
+/* Return a hash index for a NUL-terminated STRING between 0 and N_BUCKETS-1.
+ This is a convenience routine for constructing other hashing functions. */
+
+#if USE_DIFF_HASH
+
+/* About hashings, Paul Eggert writes to me (FP), on 1994-01-01: "Please see
+ B. J. McKenzie, R. Harries & T. Bell, Selecting a hashing algorithm,
+ Software--practice & experience 20, 2 (Feb 1990), 209-224. Good hash
+ algorithms tend to be domain-specific, so what's good for [diffutils'] io.c
+ may not be good for your application." */
+
+size_t
+hash_string (const char *string, size_t n_buckets)
+{
+# define HASH_ONE_CHAR(Value, Byte) \
+ ((Byte) + rotl_sz (Value, 7))
+
+ size_t value = 0;
+ unsigned char ch;
+
+ for (; (ch = *string); string++)
+ value = HASH_ONE_CHAR (value, ch);
+ return value % n_buckets;
+
+# undef HASH_ONE_CHAR
+}
+
+#else /* not USE_DIFF_HASH */
+
+/* This one comes from 'recode', and performs a bit better than the above as
+ per a few experiments. It is inspired from a hashing routine found in the
+ very old Cyber 'snoop', itself written in typical Greg Mansfield style.
+ (By the way, what happened to this excellent man? Is he still alive?) */
+
+size_t
+hash_string (const char *string, size_t n_buckets)
+{
+ size_t value = 0;
+ unsigned char ch;
+
+ for (; (ch = *string); string++)
+ value = (value * 31 + ch) % n_buckets;
+ return value;
+}
+
+#endif /* not USE_DIFF_HASH */
+
+/* Return true if CANDIDATE is a prime number. CANDIDATE should be an odd
+ number at least equal to 11. */
+
+static bool _GL_ATTRIBUTE_CONST
+is_prime (size_t candidate)
+{
+ size_t divisor = 3;
+ size_t square = divisor * divisor;
+
+ while (square < candidate && (candidate % divisor))
+ {
+ divisor++;
+ square += 4 * divisor;
+ divisor++;
+ }
+
+ return (candidate % divisor ? true : false);
+}
+
+/* Round a given CANDIDATE number up to the nearest prime, and return that
+ prime. Primes lower than 10 are merely skipped. */
+
+static size_t _GL_ATTRIBUTE_CONST
+next_prime (size_t candidate)
+{
+ /* Skip small primes. */
+ if (candidate < 10)
+ candidate = 10;
+
+ /* Make it definitely odd. */
+ candidate |= 1;
+
+ while (SIZE_MAX != candidate && !is_prime (candidate))
+ candidate += 2;
+
+ return candidate;
+}
+
+void
+hash_reset_tuning (Hash_tuning *tuning)
+{
+ *tuning = default_tuning;
+}
+
+/* If the user passes a NULL hasher, we hash the raw pointer. */
+static size_t
+raw_hasher (const void *data, size_t n)
+{
+ /* When hashing unique pointers, it is often the case that they were
+ generated by malloc and thus have the property that the low-order
+ bits are 0. As this tends to give poorer performance with small
+ tables, we rotate the pointer value before performing division,
+ in an attempt to improve hash quality. */
+ size_t val = rotr_sz ((size_t) data, 3);
+ return val % n;
+}
+
+/* If the user passes a NULL comparator, we use pointer comparison. */
+static bool
+raw_comparator (const void *a, const void *b)
+{
+ return a == b;
+}
+
+
+/* For the given hash TABLE, check the user supplied tuning structure for
+ reasonable values, and return true if there is no gross error with it.
+ Otherwise, definitively reset the TUNING field to some acceptable default
+ in the hash table (that is, the user loses the right of further modifying
+ tuning arguments), and return false. */
+
+static bool
+check_tuning (Hash_table *table)
+{
+ const Hash_tuning *tuning = table->tuning;
+ float epsilon;
+ if (tuning == &default_tuning)
+ return true;
+
+ /* Be a bit stricter than mathematics would require, so that
+ rounding errors in size calculations do not cause allocations to
+ fail to grow or shrink as they should. The smallest allocation
+ is 11 (due to next_prime's algorithm), so an epsilon of 0.1
+ should be good enough. */
+ epsilon = 0.1f;
+
+ if (epsilon < tuning->growth_threshold
+ && tuning->growth_threshold < 1 - epsilon
+ && 1 + epsilon < tuning->growth_factor
+ && 0 <= tuning->shrink_threshold
+ && tuning->shrink_threshold + epsilon < tuning->shrink_factor
+ && tuning->shrink_factor <= 1
+ && tuning->shrink_threshold + epsilon < tuning->growth_threshold)
+ return true;
+
+ table->tuning = &default_tuning;
+ return false;
+}
+
+/* Compute the size of the bucket array for the given CANDIDATE and
+ TUNING, or return 0 if there is no possible way to allocate that
+ many entries. */
+
+static size_t _GL_ATTRIBUTE_PURE
+compute_bucket_size (size_t candidate, const Hash_tuning *tuning)
+{
+ if (!tuning->is_n_buckets)
+ {
+ float new_candidate = candidate / tuning->growth_threshold;
+ if (SIZE_MAX <= new_candidate)
+ return 0;
+ candidate = new_candidate;
+ }
+ candidate = next_prime (candidate);
+ if (xalloc_oversized (candidate, sizeof (struct hash_entry *)))
+ return 0;
+ return candidate;
+}
+
+/* Allocate and return a new hash table, or NULL upon failure. The initial
+ number of buckets is automatically selected so as to _guarantee_ that you
+ may insert at least CANDIDATE different user entries before any growth of
+ the hash table size occurs. So, if have a reasonably tight a-priori upper
+ bound on the number of entries you intend to insert in the hash table, you
+ may save some table memory and insertion time, by specifying it here. If
+ the IS_N_BUCKETS field of the TUNING structure is true, the CANDIDATE
+ argument has its meaning changed to the wanted number of buckets.
+
+ TUNING points to a structure of user-supplied values, in case some fine
+ tuning is wanted over the default behavior of the hasher. If TUNING is
+ NULL, the default tuning parameters are used instead. If TUNING is
+ provided but the values requested are out of bounds or might cause
+ rounding errors, return NULL.
+
+ The user-supplied HASHER function, when not NULL, accepts two
+ arguments ENTRY and TABLE_SIZE. It computes, by hashing ENTRY contents, a
+ slot number for that entry which should be in the range 0..TABLE_SIZE-1.
+ This slot number is then returned.
+
+ The user-supplied COMPARATOR function, when not NULL, accepts two
+ arguments pointing to user data, it then returns true for a pair of entries
+ that compare equal, or false otherwise. This function is internally called
+ on entries which are already known to hash to the same bucket index,
+ but which are distinct pointers.
+
+ The user-supplied DATA_FREER function, when not NULL, may be later called
+ with the user data as an argument, just before the entry containing the
+ data gets freed. This happens from within 'hash_free' or 'hash_clear'.
+ You should specify this function only if you want these functions to free
+ all of your 'data' data. This is typically the case when your data is
+ simply an auxiliary struct that you have malloc'd to aggregate several
+ values. */
+
+Hash_table *
+hash_initialize (size_t candidate, const Hash_tuning *tuning,
+ Hash_hasher hasher, Hash_comparator comparator,
+ Hash_data_freer data_freer)
+{
+ Hash_table *table;
+
+ if (hasher == NULL)
+ hasher = raw_hasher;
+ if (comparator == NULL)
+ comparator = raw_comparator;
+
+ table = malloc (sizeof *table);
+ if (table == NULL)
+ return NULL;
+
+ if (!tuning)
+ tuning = &default_tuning;
+ table->tuning = tuning;
+ if (!check_tuning (table))
+ {
+ /* Fail if the tuning options are invalid. This is the only occasion
+ when the user gets some feedback about it. Once the table is created,
+ if the user provides invalid tuning options, we silently revert to
+ using the defaults, and ignore further request to change the tuning
+ options. */
+ goto fail;
+ }
+
+ table->n_buckets = compute_bucket_size (candidate, tuning);
+ if (!table->n_buckets)
+ goto fail;
+
+ table->bucket = calloc (table->n_buckets, sizeof *table->bucket);
+ if (table->bucket == NULL)
+ goto fail;
+ table->bucket_limit = table->bucket + table->n_buckets;
+ table->n_buckets_used = 0;
+ table->n_entries = 0;
+
+ table->hasher = hasher;
+ table->comparator = comparator;
+ table->data_freer = data_freer;
+
+ table->free_entry_list = NULL;
+#if USE_OBSTACK
+ obstack_init (&table->entry_stack);
+#endif
+ return table;
+
+ fail:
+ free (table);
+ return NULL;
+}
+
+/* Make all buckets empty, placing any chained entries on the free list.
+ Apply the user-specified function data_freer (if any) to the datas of any
+ affected entries. */
+
+void
+hash_clear (Hash_table *table)
+{
+ struct hash_entry *bucket;
+
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ struct hash_entry *cursor;
+ struct hash_entry *next;
+
+ /* Free the bucket overflow. */
+ for (cursor = bucket->next; cursor; cursor = next)
+ {
+ if (table->data_freer)
+ table->data_freer (cursor->data);
+ cursor->data = NULL;
+
+ next = cursor->next;
+ /* Relinking is done one entry at a time, as it is to be expected
+ that overflows are either rare or short. */
+ cursor->next = table->free_entry_list;
+ table->free_entry_list = cursor;
+ }
+
+ /* Free the bucket head. */
+ if (table->data_freer)
+ table->data_freer (bucket->data);
+ bucket->data = NULL;
+ bucket->next = NULL;
+ }
+ }
+
+ table->n_buckets_used = 0;
+ table->n_entries = 0;
+}
+
+/* Reclaim all storage associated with a hash table. If a data_freer
+ function has been supplied by the user when the hash table was created,
+ this function applies it to the data of each entry before freeing that
+ entry. */
+
+void
+hash_free (Hash_table *table)
+{
+ struct hash_entry *bucket;
+ struct hash_entry *cursor;
+ struct hash_entry *next;
+
+ /* Call the user data_freer function. */
+ if (table->data_freer && table->n_entries)
+ {
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ if (bucket->data)
+ {
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ table->data_freer (cursor->data);
+ }
+ }
+ }
+
+#if USE_OBSTACK
+
+ obstack_free (&table->entry_stack, NULL);
+
+#else
+
+ /* Free all bucket overflowed entries. */
+ for (bucket = table->bucket; bucket < table->bucket_limit; bucket++)
+ {
+ for (cursor = bucket->next; cursor; cursor = next)
+ {
+ next = cursor->next;
+ free (cursor);
+ }
+ }
+
+ /* Also reclaim the internal list of previously freed entries. */
+ for (cursor = table->free_entry_list; cursor; cursor = next)
+ {
+ next = cursor->next;
+ free (cursor);
+ }
+
+#endif
+
+ /* Free the remainder of the hash table structure. */
+ free (table->bucket);
+ free (table);
+}
+
+/* Insertion and deletion. */
+
+/* Get a new hash entry for a bucket overflow, possibly by recycling a
+ previously freed one. If this is not possible, allocate a new one. */
+
+static struct hash_entry *
+allocate_entry (Hash_table *table)
+{
+ struct hash_entry *new;
+
+ if (table->free_entry_list)
+ {
+ new = table->free_entry_list;
+ table->free_entry_list = new->next;
+ }
+ else
+ {
+#if USE_OBSTACK
+ new = obstack_alloc (&table->entry_stack, sizeof *new);
+#else
+ new = malloc (sizeof *new);
+#endif
+ }
+
+ return new;
+}
+
+/* Free a hash entry which was part of some bucket overflow,
+ saving it for later recycling. */
+
+static void
+free_entry (Hash_table *table, struct hash_entry *entry)
+{
+ entry->data = NULL;
+ entry->next = table->free_entry_list;
+ table->free_entry_list = entry;
+}
+
+/* This private function is used to help with insertion and deletion. When
+ ENTRY matches an entry in the table, return a pointer to the corresponding
+ user data and set *BUCKET_HEAD to the head of the selected bucket.
+ Otherwise, return NULL. When DELETE is true and ENTRY matches an entry in
+ the table, unlink the matching entry. */
+
+static void *
+hash_find_entry (Hash_table *table, const void *entry,
+ struct hash_entry **bucket_head, bool delete)
+{
+ struct hash_entry *bucket = safe_hasher (table, entry);
+ struct hash_entry *cursor;
+
+ *bucket_head = bucket;
+
+ /* Test for empty bucket. */
+ if (bucket->data == NULL)
+ return NULL;
+
+ /* See if the entry is the first in the bucket. */
+ if (entry == bucket->data || table->comparator (entry, bucket->data))
+ {
+ void *data = bucket->data;
+
+ if (delete)
+ {
+ if (bucket->next)
+ {
+ struct hash_entry *next = bucket->next;
+
+ /* Bump the first overflow entry into the bucket head, then save
+ the previous first overflow entry for later recycling. */
+ *bucket = *next;
+ free_entry (table, next);
+ }
+ else
+ {
+ bucket->data = NULL;
+ }
+ }
+
+ return data;
+ }
+
+ /* Scan the bucket overflow. */
+ for (cursor = bucket; cursor->next; cursor = cursor->next)
+ {
+ if (entry == cursor->next->data
+ || table->comparator (entry, cursor->next->data))
+ {
+ void *data = cursor->next->data;
+
+ if (delete)
+ {
+ struct hash_entry *next = cursor->next;
+
+ /* Unlink the entry to delete, then save the freed entry for later
+ recycling. */
+ cursor->next = next->next;
+ free_entry (table, next);
+ }
+
+ return data;
+ }
+ }
+
+ /* No entry found. */
+ return NULL;
+}
+
+/* Internal helper, to move entries from SRC to DST. Both tables must
+ share the same free entry list. If SAFE, only move overflow
+ entries, saving bucket heads for later, so that no allocations will
+ occur. Return false if the free entry list is exhausted and an
+ allocation fails. */
+
+static bool
+transfer_entries (Hash_table *dst, Hash_table *src, bool safe)
+{
+ struct hash_entry *bucket;
+ struct hash_entry *cursor;
+ struct hash_entry *next;
+ for (bucket = src->bucket; bucket < src->bucket_limit; bucket++)
+ if (bucket->data)
+ {
+ void *data;
+ struct hash_entry *new_bucket;
+
+ /* Within each bucket, transfer overflow entries first and
+ then the bucket head, to minimize memory pressure. After
+ all, the only time we might allocate is when moving the
+ bucket head, but moving overflow entries first may create
+ free entries that can be recycled by the time we finally
+ get to the bucket head. */
+ for (cursor = bucket->next; cursor; cursor = next)
+ {
+ data = cursor->data;
+ new_bucket = safe_hasher (dst, data);
+
+ next = cursor->next;
+
+ if (new_bucket->data)
+ {
+ /* Merely relink an existing entry, when moving from a
+ bucket overflow into a bucket overflow. */
+ cursor->next = new_bucket->next;
+ new_bucket->next = cursor;
+ }
+ else
+ {
+ /* Free an existing entry, when moving from a bucket
+ overflow into a bucket header. */
+ new_bucket->data = data;
+ dst->n_buckets_used++;
+ free_entry (dst, cursor);
+ }
+ }
+ /* Now move the bucket head. Be sure that if we fail due to
+ allocation failure that the src table is in a consistent
+ state. */
+ data = bucket->data;
+ bucket->next = NULL;
+ if (safe)
+ continue;
+ new_bucket = safe_hasher (dst, data);
+
+ if (new_bucket->data)
+ {
+ /* Allocate or recycle an entry, when moving from a bucket
+ header into a bucket overflow. */
+ struct hash_entry *new_entry = allocate_entry (dst);
+
+ if (new_entry == NULL)
+ return false;
+
+ new_entry->data = data;
+ new_entry->next = new_bucket->next;
+ new_bucket->next = new_entry;
+ }
+ else
+ {
+ /* Move from one bucket header to another. */
+ new_bucket->data = data;
+ dst->n_buckets_used++;
+ }
+ bucket->data = NULL;
+ src->n_buckets_used--;
+ }
+ return true;
+}
+
+/* For an already existing hash table, change the number of buckets through
+ specifying CANDIDATE. The contents of the hash table are preserved. The
+ new number of buckets is automatically selected so as to _guarantee_ that
+ the table may receive at least CANDIDATE different user entries, including
+ those already in the table, before any other growth of the hash table size
+ occurs. If TUNING->IS_N_BUCKETS is true, then CANDIDATE specifies the
+ exact number of buckets desired. Return true iff the rehash succeeded. */
+
+bool
+hash_rehash (Hash_table *table, size_t candidate)
+{
+ Hash_table storage;
+ Hash_table *new_table;
+ size_t new_size = compute_bucket_size (candidate, table->tuning);
+
+ if (!new_size)
+ return false;
+ if (new_size == table->n_buckets)
+ return true;
+ new_table = &storage;
+ new_table->bucket = calloc (new_size, sizeof *new_table->bucket);
+ if (new_table->bucket == NULL)
+ return false;
+ new_table->n_buckets = new_size;
+ new_table->bucket_limit = new_table->bucket + new_size;
+ new_table->n_buckets_used = 0;
+ new_table->n_entries = 0;
+ new_table->tuning = table->tuning;
+ new_table->hasher = table->hasher;
+ new_table->comparator = table->comparator;
+ new_table->data_freer = table->data_freer;
+
+ /* In order for the transfer to successfully complete, we need
+ additional overflow entries when distinct buckets in the old
+ table collide into a common bucket in the new table. The worst
+ case possible is a hasher that gives a good spread with the old
+ size, but returns a constant with the new size; if we were to
+ guarantee table->n_buckets_used-1 free entries in advance, then
+ the transfer would be guaranteed to not allocate memory.
+ However, for large tables, a guarantee of no further allocation
+ introduces a lot of extra memory pressure, all for an unlikely
+ corner case (most rehashes reduce, rather than increase, the
+ number of overflow entries needed). So, we instead ensure that
+ the transfer process can be reversed if we hit a memory
+ allocation failure mid-transfer. */
+
+ /* Merely reuse the extra old space into the new table. */
+#if USE_OBSTACK
+ new_table->entry_stack = table->entry_stack;
+#endif
+ new_table->free_entry_list = table->free_entry_list;
+
+ if (transfer_entries (new_table, table, false))
+ {
+ /* Entries transferred successfully; tie up the loose ends. */
+ free (table->bucket);
+ table->bucket = new_table->bucket;
+ table->bucket_limit = new_table->bucket_limit;
+ table->n_buckets = new_table->n_buckets;
+ table->n_buckets_used = new_table->n_buckets_used;
+ table->free_entry_list = new_table->free_entry_list;
+ /* table->n_entries and table->entry_stack already hold their value. */
+ return true;
+ }
+
+ /* We've allocated new_table->bucket (and possibly some entries),
+ exhausted the free list, and moved some but not all entries into
+ new_table. We must undo the partial move before returning
+ failure. The only way to get into this situation is if new_table
+ uses fewer buckets than the old table, so we will reclaim some
+ free entries as overflows in the new table are put back into
+ distinct buckets in the old table.
+
+ There are some pathological cases where a single pass through the
+ table requires more intermediate overflow entries than using two
+ passes. Two passes give worse cache performance and takes
+ longer, but at this point, we're already out of memory, so slow
+ and safe is better than failure. */
+ table->free_entry_list = new_table->free_entry_list;
+ if (! (transfer_entries (table, new_table, true)
+ && transfer_entries (table, new_table, false)))
+ abort ();
+ /* table->n_entries already holds its value. */
+ free (new_table->bucket);
+ return false;
+}
+
+/* Insert ENTRY into hash TABLE if there is not already a matching entry.
+
+ Return -1 upon memory allocation failure.
+ Return 1 if insertion succeeded.
+ Return 0 if there is already a matching entry in the table,
+ and in that case, if MATCHED_ENT is non-NULL, set *MATCHED_ENT
+ to that entry.
+
+ This interface is easier to use than hash_insert when you must
+ distinguish between the latter two cases. More importantly,
+ hash_insert is unusable for some types of ENTRY values. When using
+ hash_insert, the only way to distinguish those cases is to compare
+ the return value and ENTRY. That works only when you can have two
+ different ENTRY values that point to data that compares "equal". Thus,
+ when the ENTRY value is a simple scalar, you must use
+ hash_insert_if_absent. ENTRY must not be NULL. */
+int
+hash_insert_if_absent (Hash_table *table, void const *entry,
+ void const **matched_ent)
+{
+ void *data;
+ struct hash_entry *bucket;
+
+ /* The caller cannot insert a NULL entry, since hash_lookup returns NULL
+ to indicate "not found", and hash_find_entry uses "bucket->data == NULL"
+ to indicate an empty bucket. */
+ if (! entry)
+ abort ();
+
+ /* If there's a matching entry already in the table, return that. */
+ if ((data = hash_find_entry (table, entry, &bucket, false)) != NULL)
+ {
+ if (matched_ent)
+ *matched_ent = data;
+ return 0;
+ }
+
+ /* If the growth threshold of the buckets in use has been reached, increase
+ the table size and rehash. There's no point in checking the number of
+ entries: if the hashing function is ill-conditioned, rehashing is not
+ likely to improve it. */
+
+ if (table->n_buckets_used
+ > table->tuning->growth_threshold * table->n_buckets)
+ {
+ /* Check more fully, before starting real work. If tuning arguments
+ became invalid, the second check will rely on proper defaults. */
+ check_tuning (table);
+ if (table->n_buckets_used
+ > table->tuning->growth_threshold * table->n_buckets)
+ {
+ const Hash_tuning *tuning = table->tuning;
+ float candidate =
+ (tuning->is_n_buckets
+ ? (table->n_buckets * tuning->growth_factor)
+ : (table->n_buckets * tuning->growth_factor
+ * tuning->growth_threshold));
+
+ if (SIZE_MAX <= candidate)
+ return -1;
+
+ /* If the rehash fails, arrange to return NULL. */
+ if (!hash_rehash (table, candidate))
+ return -1;
+
+ /* Update the bucket we are interested in. */
+ if (hash_find_entry (table, entry, &bucket, false) != NULL)
+ abort ();
+ }
+ }
+
+ /* ENTRY is not matched, it should be inserted. */
+
+ if (bucket->data)
+ {
+ struct hash_entry *new_entry = allocate_entry (table);
+
+ if (new_entry == NULL)
+ return -1;
+
+ /* Add ENTRY in the overflow of the bucket. */
+
+ new_entry->data = (void *) entry;
+ new_entry->next = bucket->next;
+ bucket->next = new_entry;
+ table->n_entries++;
+ return 1;
+ }
+
+ /* Add ENTRY right in the bucket head. */
+
+ bucket->data = (void *) entry;
+ table->n_entries++;
+ table->n_buckets_used++;
+
+ return 1;
+}
+
+/* hash_insert0 is the deprecated name for hash_insert_if_absent.
+ . */
+int
+hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent)
+{
+ return hash_insert_if_absent (table, entry, matched_ent);
+}
+
+/* If ENTRY matches an entry already in the hash table, return the pointer
+ to the entry from the table. Otherwise, insert ENTRY and return ENTRY.
+ Return NULL if the storage required for insertion cannot be allocated.
+ This implementation does not support duplicate entries or insertion of
+ NULL. */
+
+void *
+hash_insert (Hash_table *table, void const *entry)
+{
+ void const *matched_ent;
+ int err = hash_insert_if_absent (table, entry, &matched_ent);
+ return (err == -1
+ ? NULL
+ : (void *) (err == 0 ? matched_ent : entry));
+}
+
+/* If ENTRY is already in the table, remove it and return the just-deleted
+ data (the user may want to deallocate its storage). If ENTRY is not in the
+ table, don't modify the table and return NULL. */
+
+void *
+hash_delete (Hash_table *table, const void *entry)
+{
+ void *data;
+ struct hash_entry *bucket;
+
+ data = hash_find_entry (table, entry, &bucket, true);
+ if (!data)
+ return NULL;
+
+ table->n_entries--;
+ if (!bucket->data)
+ {
+ table->n_buckets_used--;
+
+ /* If the shrink threshold of the buckets in use has been reached,
+ rehash into a smaller table. */
+
+ if (table->n_buckets_used
+ < table->tuning->shrink_threshold * table->n_buckets)
+ {
+ /* Check more fully, before starting real work. If tuning arguments
+ became invalid, the second check will rely on proper defaults. */
+ check_tuning (table);
+ if (table->n_buckets_used
+ < table->tuning->shrink_threshold * table->n_buckets)
+ {
+ const Hash_tuning *tuning = table->tuning;
+ size_t candidate =
+ (tuning->is_n_buckets
+ ? table->n_buckets * tuning->shrink_factor
+ : (table->n_buckets * tuning->shrink_factor
+ * tuning->growth_threshold));
+
+ if (!hash_rehash (table, candidate))
+ {
+ /* Failure to allocate memory in an attempt to
+ shrink the table is not fatal. But since memory
+ is low, we can at least be kind and free any
+ spare entries, rather than keeping them tied up
+ in the free entry list. */
+#if ! USE_OBSTACK
+ struct hash_entry *cursor = table->free_entry_list;
+ struct hash_entry *next;
+ while (cursor)
+ {
+ next = cursor->next;
+ free (cursor);
+ cursor = next;
+ }
+ table->free_entry_list = NULL;
+#endif
+ }
+ }
+ }
+ }
+
+ return data;
+}
+
+/* Testing. */
+
+#if TESTING
+
+void
+hash_print (const Hash_table *table)
+{
+ struct hash_entry *bucket = (struct hash_entry *) table->bucket;
+
+ for ( ; bucket < table->bucket_limit; bucket++)
+ {
+ struct hash_entry *cursor;
+
+ if (bucket)
+ printf ("%lu:\n", (unsigned long int) (bucket - table->bucket));
+
+ for (cursor = bucket; cursor; cursor = cursor->next)
+ {
+ char const *s = cursor->data;
+ /* FIXME */
+ if (s)
+ printf (" %s\n", s);
+ }
+ }
+}
+
+#endif /* TESTING */
diff --git a/contrib/tools/bison/gnulib/src/hash.h b/contrib/tools/bison/gnulib/src/hash.h
index bcd0d1d96b..5554663adb 100644
--- a/contrib/tools/bison/gnulib/src/hash.h
+++ b/contrib/tools/bison/gnulib/src/hash.h
@@ -1,107 +1,107 @@
-/* hash - hashing table processing.
- Copyright (C) 1998-1999, 2001, 2003, 2009-2013 Free Software Foundation,
- Inc.
- Written by Jim Meyering <meyering@ascend.com>, 1998.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* A generic hash table package. */
-
-/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
- obstacks instead of malloc, and recompile 'hash.c' with same setting. */
-
-#ifndef HASH_H_
-# define HASH_H_
-
-# include <stdio.h>
-# include <stdbool.h>
-
-/* The __attribute__ feature is available in gcc versions 2.5 and later.
- The warn_unused_result attribute appeared first in gcc-3.4.0. */
-# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
-# define _GL_ATTRIBUTE_WUR __attribute__ ((__warn_unused_result__))
-# else
-# define _GL_ATTRIBUTE_WUR /* empty */
-# endif
-
-# ifndef _GL_ATTRIBUTE_DEPRECATED
-/* The __attribute__((__deprecated__)) feature
- is available in gcc versions 3.1 and newer. */
-# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
-# define _GL_ATTRIBUTE_DEPRECATED /* empty */
-# else
-# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
-# endif
-# endif
-
-typedef size_t (*Hash_hasher) (const void *, size_t);
-typedef bool (*Hash_comparator) (const void *, const void *);
-typedef void (*Hash_data_freer) (void *);
-typedef bool (*Hash_processor) (void *, void *);
-
-struct hash_tuning
- {
- /* This structure is mainly used for 'hash_initialize', see the block
- documentation of 'hash_reset_tuning' for more complete comments. */
-
- float shrink_threshold; /* ratio of used buckets to trigger a shrink */
- float shrink_factor; /* ratio of new smaller size to original size */
- float growth_threshold; /* ratio of used buckets to trigger a growth */
- float growth_factor; /* ratio of new bigger size to original size */
- bool is_n_buckets; /* if CANDIDATE really means table size */
- };
-
-typedef struct hash_tuning Hash_tuning;
-
-struct hash_table;
-
-typedef struct hash_table Hash_table;
-
-/* Information and lookup. */
-size_t hash_get_n_buckets (const Hash_table *) _GL_ATTRIBUTE_PURE;
-size_t hash_get_n_buckets_used (const Hash_table *) _GL_ATTRIBUTE_PURE;
-size_t hash_get_n_entries (const Hash_table *) _GL_ATTRIBUTE_PURE;
-size_t hash_get_max_bucket_length (const Hash_table *) _GL_ATTRIBUTE_PURE;
-bool hash_table_ok (const Hash_table *) _GL_ATTRIBUTE_PURE;
-void hash_print_statistics (const Hash_table *, FILE *);
-void *hash_lookup (const Hash_table *, const void *);
-
-/* Walking. */
-void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE;
-void *hash_get_next (const Hash_table *, const void *);
-size_t hash_get_entries (const Hash_table *, void **, size_t);
-size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
-
-/* Allocation and clean-up. */
-size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE;
-void hash_reset_tuning (Hash_tuning *);
-Hash_table *hash_initialize (size_t, const Hash_tuning *,
- Hash_hasher, Hash_comparator,
- Hash_data_freer) _GL_ATTRIBUTE_WUR;
-void hash_clear (Hash_table *);
-void hash_free (Hash_table *);
-
-/* Insertion and deletion. */
-bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_WUR;
-void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_WUR;
-
-/* Deprecate this interface. It has been renamed to hash_insert_if_absent. */
-int hash_insert0 (Hash_table *table, /* FIXME: remove in 2013 */
- const void *entry,
- const void **matched_ent) _GL_ATTRIBUTE_DEPRECATED;
-int hash_insert_if_absent (Hash_table *table, const void *entry,
- const void **matched_ent);
-void *hash_delete (Hash_table *, const void *);
-
-#endif
+/* hash - hashing table processing.
+ Copyright (C) 1998-1999, 2001, 2003, 2009-2013 Free Software Foundation,
+ Inc.
+ Written by Jim Meyering <meyering@ascend.com>, 1998.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* A generic hash table package. */
+
+/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
+ obstacks instead of malloc, and recompile 'hash.c' with same setting. */
+
+#ifndef HASH_H_
+# define HASH_H_
+
+# include <stdio.h>
+# include <stdbool.h>
+
+/* The __attribute__ feature is available in gcc versions 2.5 and later.
+ The warn_unused_result attribute appeared first in gcc-3.4.0. */
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+# define _GL_ATTRIBUTE_WUR __attribute__ ((__warn_unused_result__))
+# else
+# define _GL_ATTRIBUTE_WUR /* empty */
+# endif
+
+# ifndef _GL_ATTRIBUTE_DEPRECATED
+/* The __attribute__((__deprecated__)) feature
+ is available in gcc versions 3.1 and newer. */
+# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
+# define _GL_ATTRIBUTE_DEPRECATED /* empty */
+# else
+# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
+# endif
+# endif
+
+typedef size_t (*Hash_hasher) (const void *, size_t);
+typedef bool (*Hash_comparator) (const void *, const void *);
+typedef void (*Hash_data_freer) (void *);
+typedef bool (*Hash_processor) (void *, void *);
+
+struct hash_tuning
+ {
+ /* This structure is mainly used for 'hash_initialize', see the block
+ documentation of 'hash_reset_tuning' for more complete comments. */
+
+ float shrink_threshold; /* ratio of used buckets to trigger a shrink */
+ float shrink_factor; /* ratio of new smaller size to original size */
+ float growth_threshold; /* ratio of used buckets to trigger a growth */
+ float growth_factor; /* ratio of new bigger size to original size */
+ bool is_n_buckets; /* if CANDIDATE really means table size */
+ };
+
+typedef struct hash_tuning Hash_tuning;
+
+struct hash_table;
+
+typedef struct hash_table Hash_table;
+
+/* Information and lookup. */
+size_t hash_get_n_buckets (const Hash_table *) _GL_ATTRIBUTE_PURE;
+size_t hash_get_n_buckets_used (const Hash_table *) _GL_ATTRIBUTE_PURE;
+size_t hash_get_n_entries (const Hash_table *) _GL_ATTRIBUTE_PURE;
+size_t hash_get_max_bucket_length (const Hash_table *) _GL_ATTRIBUTE_PURE;
+bool hash_table_ok (const Hash_table *) _GL_ATTRIBUTE_PURE;
+void hash_print_statistics (const Hash_table *, FILE *);
+void *hash_lookup (const Hash_table *, const void *);
+
+/* Walking. */
+void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE;
+void *hash_get_next (const Hash_table *, const void *);
+size_t hash_get_entries (const Hash_table *, void **, size_t);
+size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
+
+/* Allocation and clean-up. */
+size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE;
+void hash_reset_tuning (Hash_tuning *);
+Hash_table *hash_initialize (size_t, const Hash_tuning *,
+ Hash_hasher, Hash_comparator,
+ Hash_data_freer) _GL_ATTRIBUTE_WUR;
+void hash_clear (Hash_table *);
+void hash_free (Hash_table *);
+
+/* Insertion and deletion. */
+bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_WUR;
+void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_WUR;
+
+/* Deprecate this interface. It has been renamed to hash_insert_if_absent. */
+int hash_insert0 (Hash_table *table, /* FIXME: remove in 2013 */
+ const void *entry,
+ const void **matched_ent) _GL_ATTRIBUTE_DEPRECATED;
+int hash_insert_if_absent (Hash_table *table, const void *entry,
+ const void **matched_ent);
+void *hash_delete (Hash_table *, const void *);
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/ignore-value.h b/contrib/tools/bison/gnulib/src/ignore-value.h
index ebd6bf42f5..931f96bff9 100644
--- a/contrib/tools/bison/gnulib/src/ignore-value.h
+++ b/contrib/tools/bison/gnulib/src/ignore-value.h
@@ -1,48 +1,48 @@
-/* ignore a function return without a compiler warning
-
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering, Eric Blake and Pádraig Brady. */
-
-/* Use "ignore_value" to avoid a warning when using a function declared with
- gcc's warn_unused_result attribute, but for which you really do want to
- ignore the result. Traditionally, people have used a "(void)" cast to
- indicate that a function's return value is deliberately unused. However,
- if the function is declared with __attribute__((warn_unused_result)),
- gcc issues a warning even with the cast.
-
- Caution: most of the time, you really should heed gcc's warning, and
- check the return value. However, in those exceptional cases in which
- you're sure you know what you're doing, use this function.
-
- For the record, here's one of the ignorable warnings:
- "copy.c:233: warning: ignoring return value of 'fchown',
- declared with attribute warn_unused_result". */
-
-#ifndef _GL_IGNORE_VALUE_H
-#define _GL_IGNORE_VALUE_H
-
-/* The __attribute__((__warn_unused_result__)) feature
- is available in gcc versions 3.4 and newer,
- while the typeof feature has been available since 2.7 at least. */
-#if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
-# define ignore_value(x) \
- (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
-#else
-# define ignore_value(x) ((void) (x))
-#endif
-
-#endif
+/* ignore a function return without a compiler warning
+
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering, Eric Blake and Pádraig Brady. */
+
+/* Use "ignore_value" to avoid a warning when using a function declared with
+ gcc's warn_unused_result attribute, but for which you really do want to
+ ignore the result. Traditionally, people have used a "(void)" cast to
+ indicate that a function's return value is deliberately unused. However,
+ if the function is declared with __attribute__((warn_unused_result)),
+ gcc issues a warning even with the cast.
+
+ Caution: most of the time, you really should heed gcc's warning, and
+ check the return value. However, in those exceptional cases in which
+ you're sure you know what you're doing, use this function.
+
+ For the record, here's one of the ignorable warnings:
+ "copy.c:233: warning: ignoring return value of 'fchown',
+ declared with attribute warn_unused_result". */
+
+#ifndef _GL_IGNORE_VALUE_H
+#define _GL_IGNORE_VALUE_H
+
+/* The __attribute__((__warn_unused_result__)) feature
+ is available in gcc versions 3.4 and newer,
+ while the typeof feature has been available since 2.7 at least. */
+#if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
+# define ignore_value(x) \
+ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
+#else
+# define ignore_value(x) ((void) (x))
+#endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/intprops.h b/contrib/tools/bison/gnulib/src/intprops.h
index f57f9b4dda..3f33ee1363 100644
--- a/contrib/tools/bison/gnulib/src/intprops.h
+++ b/contrib/tools/bison/gnulib/src/intprops.h
@@ -1,319 +1,319 @@
-/* intprops.h -- properties of integer types
-
- Copyright (C) 2001-2005, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#ifndef _GL_INTPROPS_H
-#define _GL_INTPROPS_H
-
-#include <limits.h>
-
-/* Return an integer value, converted to the same type as the integer
- expression E after integer type promotion. V is the unconverted value. */
-#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
-
-/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
- <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */
-#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v))
-
-/* The extra casts in the following macros work around compiler bugs,
- e.g., in Cray C 5.0.3.0. */
-
-/* True if the arithmetic type T is an integer type. bool counts as
- an integer. */
-#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
-
-/* True if negative values of the signed integer type T use two's
- complement, ones' complement, or signed magnitude representation,
- respectively. Much GNU code assumes two's complement, but some
- people like to be portable to all possible C hosts. */
-#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
-#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
-#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
-
-/* True if the signed integer expression E uses two's complement. */
-#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1)
-
-/* True if the arithmetic type T is signed. */
-#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
-
-/* Return 1 if the integer expression E, after integer promotion, has
- a signed type. */
-#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
-
-
-/* Minimum and maximum values for integer types and expressions. These
- macros have undefined behavior if T is signed and has padding bits.
- If this is a problem for you, please let us know how to fix it for
- your host. */
-
-/* The maximum and minimum values for the integer type T. */
-#define TYPE_MINIMUM(t) \
- ((t) (! TYPE_SIGNED (t) \
- ? (t) 0 \
- : TYPE_SIGNED_MAGNITUDE (t) \
- ? ~ (t) 0 \
- : ~ TYPE_MAXIMUM (t)))
-#define TYPE_MAXIMUM(t) \
- ((t) (! TYPE_SIGNED (t) \
- ? (t) -1 \
- : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
-
-/* The maximum and minimum values for the type of the expression E,
- after integer promotion. E should not have side effects. */
-#define _GL_INT_MINIMUM(e) \
- (_GL_INT_SIGNED (e) \
- ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \
- : _GL_INT_CONVERT (e, 0))
-#define _GL_INT_MAXIMUM(e) \
- (_GL_INT_SIGNED (e) \
- ? _GL_SIGNED_INT_MAXIMUM (e) \
- : _GL_INT_NEGATE_CONVERT (e, 1))
-#define _GL_SIGNED_INT_MAXIMUM(e) \
- (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
-
-
-/* Return 1 if the __typeof__ keyword works. This could be done by
- 'configure', but for now it's easier to do it by hand. */
-#if 2 <= __GNUC__ || defined __IBM__TYPEOF__ || 0x5110 <= __SUNPRO_C
-# define _GL_HAVE___TYPEOF__ 1
-#else
-# define _GL_HAVE___TYPEOF__ 0
-#endif
-
-/* Return 1 if the integer type or expression T might be signed. Return 0
- if it is definitely unsigned. This macro does not evaluate its argument,
- and expands to an integer constant expression. */
-#if _GL_HAVE___TYPEOF__
-# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
-#else
-# define _GL_SIGNED_TYPE_OR_EXPR(t) 1
-#endif
-
-/* Bound on length of the string representing an unsigned integer
- value representable in B bits. log10 (2.0) < 146/485. The
- smallest value of B where this bound is not tight is 2621. */
-#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
-
-/* Bound on length of the string representing an integer type or expression T.
- Subtract 1 for the sign bit if T is signed, and then add 1 more for
- a minus sign if needed.
-
- Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is
- signed, this macro may overestimate the true bound by one byte when
- applied to unsigned types of size 2, 4, 16, ... bytes. */
-#define INT_STRLEN_BOUND(t) \
- (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \
- - _GL_SIGNED_TYPE_OR_EXPR (t)) \
- + _GL_SIGNED_TYPE_OR_EXPR (t))
-
-/* Bound on buffer size needed to represent an integer type or expression T,
- including the terminating null. */
-#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
-
-
-/* Range overflow checks.
-
- The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C
- operators might not yield numerically correct answers due to
- arithmetic overflow. They do not rely on undefined or
- implementation-defined behavior. Their implementations are simple
- and straightforward, but they are a bit harder to use than the
- INT_<op>_OVERFLOW macros described below.
-
- Example usage:
-
- long int i = ...;
- long int j = ...;
- if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX))
- printf ("multiply would overflow");
- else
- printf ("product is %ld", i * j);
-
- Restrictions on *_RANGE_OVERFLOW macros:
-
- These macros do not check for all possible numerical problems or
- undefined or unspecified behavior: they do not check for division
- by zero, for bad shift counts, or for shifting negative numbers.
-
- These macros may evaluate their arguments zero or multiple times,
- so the arguments should not have side effects. The arithmetic
- arguments (including the MIN and MAX arguments) must be of the same
- integer type after the usual arithmetic conversions, and the type
- must have minimum value MIN and maximum MAX. Unsigned types should
- use a zero MIN of the proper type.
-
- These macros are tuned for constant MIN and MAX. For commutative
- operations such as A + B, they are also tuned for constant B. */
-
-/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic.
- See above for restrictions. */
-#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \
- ((b) < 0 \
- ? (a) < (min) - (b) \
- : (max) - (b) < (a))
-
-/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic.
- See above for restrictions. */
-#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \
- ((b) < 0 \
- ? (max) + (b) < (a) \
- : (a) < (min) + (b))
-
-/* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
- See above for restrictions. */
-#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \
- ((min) < 0 \
- ? (a) < - (max) \
- : 0 < (a))
-
-/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
- See above for restrictions. Avoid && and || as they tickle
- bugs in Sun C 5.11 2010/08/13 and other compilers; see
- <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>. */
-#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
- ((b) < 0 \
- ? ((a) < 0 \
- ? (a) < (max) / (b) \
- : (b) == -1 \
- ? 0 \
- : (min) / (b) < (a)) \
- : (b) == 0 \
- ? 0 \
- : ((a) < 0 \
- ? (a) < (min) / (b) \
- : (max) / (b) < (a)))
-
-/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic.
- See above for restrictions. Do not check for division by zero. */
-#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \
- ((min) < 0 && (b) == -1 && (a) < - (max))
-
-/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic.
- See above for restrictions. Do not check for division by zero.
- Mathematically, % should never overflow, but on x86-like hosts
- INT_MIN % -1 traps, and the C standard permits this, so treat this
- as an overflow too. */
-#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \
- INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max)
-
-/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic.
- See above for restrictions. Here, MIN and MAX are for A only, and B need
- not be of the same type as the other arguments. The C standard says that
- behavior is undefined for shifts unless 0 <= B < wordwidth, and that when
- A is negative then A << B has undefined behavior and A >> B has
- implementation-defined behavior, but do not check these other
- restrictions. */
-#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \
- ((a) < 0 \
- ? (a) < (min) >> (b) \
- : (max) >> (b) < (a))
-
-
-/* The _GL*_OVERFLOW macros have the same restrictions as the
- *_RANGE_OVERFLOW macros, except that they do not assume that operands
- (e.g., A and B) have the same type as MIN and MAX. Instead, they assume
- that the result (e.g., A + B) has that type. */
-#define _GL_ADD_OVERFLOW(a, b, min, max) \
- ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
- : (a) < 0 ? (b) <= (a) + (b) \
- : (b) < 0 ? (a) <= (a) + (b) \
- : (a) + (b) < (b))
-#define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
- ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
- : (a) < 0 ? 1 \
- : (b) < 0 ? (a) - (b) <= (a) \
- : (a) < (b))
-#define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
- (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
- || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
-#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \
- ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
- : (a) < 0 ? (b) <= (a) + (b) - 1 \
- : (b) < 0 && (a) + (b) <= (a))
-#define _GL_REMAINDER_OVERFLOW(a, b, min, max) \
- ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
- : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \
- : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max))
-
-/* Return a nonzero value if A is a mathematical multiple of B, where
- A is unsigned, B is negative, and MAX is the maximum value of A's
- type. A's type must be the same as (A % B)'s type. Normally (A %
- -B == 0) suffices, but things get tricky if -B would overflow. */
-#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \
- (((b) < -_GL_SIGNED_INT_MAXIMUM (b) \
- ? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \
- ? (a) \
- : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1)) \
- : (a) % - (b)) \
- == 0)
-
-
-/* Integer overflow checks.
-
- The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators
- might not yield numerically correct answers due to arithmetic overflow.
- They work correctly on all known practical hosts, and do not rely
- on undefined behavior due to signed arithmetic overflow.
-
- Example usage:
-
- long int i = ...;
- long int j = ...;
- if (INT_MULTIPLY_OVERFLOW (i, j))
- printf ("multiply would overflow");
- else
- printf ("product is %ld", i * j);
-
- These macros do not check for all possible numerical problems or
- undefined or unspecified behavior: they do not check for division
- by zero, for bad shift counts, or for shifting negative numbers.
-
- These macros may evaluate their arguments zero or multiple times, so the
- arguments should not have side effects.
-
- These macros are tuned for their last argument being a constant.
-
- Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
- A % B, and A << B would overflow, respectively. */
-
-#define INT_ADD_OVERFLOW(a, b) \
- _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
-#define INT_SUBTRACT_OVERFLOW(a, b) \
- _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
-#define INT_NEGATE_OVERFLOW(a) \
- INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
-#define INT_MULTIPLY_OVERFLOW(a, b) \
- _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
-#define INT_DIVIDE_OVERFLOW(a, b) \
- _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW)
-#define INT_REMAINDER_OVERFLOW(a, b) \
- _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW)
-#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
- INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
- _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
-
-/* Return 1 if the expression A <op> B would overflow,
- where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test,
- assuming MIN and MAX are the minimum and maximum for the result type.
- Arguments should be free of side effects. */
-#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
- op_result_overflow (a, b, \
- _GL_INT_MINIMUM (0 * (b) + (a)), \
- _GL_INT_MAXIMUM (0 * (b) + (a)))
-
-#endif /* _GL_INTPROPS_H */
+/* intprops.h -- properties of integer types
+
+ Copyright (C) 2001-2005, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#ifndef _GL_INTPROPS_H
+#define _GL_INTPROPS_H
+
+#include <limits.h>
+
+/* Return an integer value, converted to the same type as the integer
+ expression E after integer type promotion. V is the unconverted value. */
+#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
+
+/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
+ <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */
+#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v))
+
+/* The extra casts in the following macros work around compiler bugs,
+ e.g., in Cray C 5.0.3.0. */
+
+/* True if the arithmetic type T is an integer type. bool counts as
+ an integer. */
+#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
+
+/* True if negative values of the signed integer type T use two's
+ complement, ones' complement, or signed magnitude representation,
+ respectively. Much GNU code assumes two's complement, but some
+ people like to be portable to all possible C hosts. */
+#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
+#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
+#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
+
+/* True if the signed integer expression E uses two's complement. */
+#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1)
+
+/* True if the arithmetic type T is signed. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* Return 1 if the integer expression E, after integer promotion, has
+ a signed type. */
+#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
+
+
+/* Minimum and maximum values for integer types and expressions. These
+ macros have undefined behavior if T is signed and has padding bits.
+ If this is a problem for you, please let us know how to fix it for
+ your host. */
+
+/* The maximum and minimum values for the integer type T. */
+#define TYPE_MINIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) 0 \
+ : TYPE_SIGNED_MAGNITUDE (t) \
+ ? ~ (t) 0 \
+ : ~ TYPE_MAXIMUM (t)))
+#define TYPE_MAXIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) -1 \
+ : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
+
+/* The maximum and minimum values for the type of the expression E,
+ after integer promotion. E should not have side effects. */
+#define _GL_INT_MINIMUM(e) \
+ (_GL_INT_SIGNED (e) \
+ ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \
+ : _GL_INT_CONVERT (e, 0))
+#define _GL_INT_MAXIMUM(e) \
+ (_GL_INT_SIGNED (e) \
+ ? _GL_SIGNED_INT_MAXIMUM (e) \
+ : _GL_INT_NEGATE_CONVERT (e, 1))
+#define _GL_SIGNED_INT_MAXIMUM(e) \
+ (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
+
+
+/* Return 1 if the __typeof__ keyword works. This could be done by
+ 'configure', but for now it's easier to do it by hand. */
+#if 2 <= __GNUC__ || defined __IBM__TYPEOF__ || 0x5110 <= __SUNPRO_C
+# define _GL_HAVE___TYPEOF__ 1
+#else
+# define _GL_HAVE___TYPEOF__ 0
+#endif
+
+/* Return 1 if the integer type or expression T might be signed. Return 0
+ if it is definitely unsigned. This macro does not evaluate its argument,
+ and expands to an integer constant expression. */
+#if _GL_HAVE___TYPEOF__
+# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
+#else
+# define _GL_SIGNED_TYPE_OR_EXPR(t) 1
+#endif
+
+/* Bound on length of the string representing an unsigned integer
+ value representable in B bits. log10 (2.0) < 146/485. The
+ smallest value of B where this bound is not tight is 2621. */
+#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
+
+/* Bound on length of the string representing an integer type or expression T.
+ Subtract 1 for the sign bit if T is signed, and then add 1 more for
+ a minus sign if needed.
+
+ Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is
+ signed, this macro may overestimate the true bound by one byte when
+ applied to unsigned types of size 2, 4, 16, ... bytes. */
+#define INT_STRLEN_BOUND(t) \
+ (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \
+ - _GL_SIGNED_TYPE_OR_EXPR (t)) \
+ + _GL_SIGNED_TYPE_OR_EXPR (t))
+
+/* Bound on buffer size needed to represent an integer type or expression T,
+ including the terminating null. */
+#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
+
+
+/* Range overflow checks.
+
+ The INT_<op>_RANGE_OVERFLOW macros return 1 if the corresponding C
+ operators might not yield numerically correct answers due to
+ arithmetic overflow. They do not rely on undefined or
+ implementation-defined behavior. Their implementations are simple
+ and straightforward, but they are a bit harder to use than the
+ INT_<op>_OVERFLOW macros described below.
+
+ Example usage:
+
+ long int i = ...;
+ long int j = ...;
+ if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX))
+ printf ("multiply would overflow");
+ else
+ printf ("product is %ld", i * j);
+
+ Restrictions on *_RANGE_OVERFLOW macros:
+
+ These macros do not check for all possible numerical problems or
+ undefined or unspecified behavior: they do not check for division
+ by zero, for bad shift counts, or for shifting negative numbers.
+
+ These macros may evaluate their arguments zero or multiple times,
+ so the arguments should not have side effects. The arithmetic
+ arguments (including the MIN and MAX arguments) must be of the same
+ integer type after the usual arithmetic conversions, and the type
+ must have minimum value MIN and maximum MAX. Unsigned types should
+ use a zero MIN of the proper type.
+
+ These macros are tuned for constant MIN and MAX. For commutative
+ operations such as A + B, they are also tuned for constant B. */
+
+/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic.
+ See above for restrictions. */
+#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \
+ ((b) < 0 \
+ ? (a) < (min) - (b) \
+ : (max) - (b) < (a))
+
+/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic.
+ See above for restrictions. */
+#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \
+ ((b) < 0 \
+ ? (max) + (b) < (a) \
+ : (a) < (min) + (b))
+
+/* Return 1 if - A would overflow in [MIN,MAX] arithmetic.
+ See above for restrictions. */
+#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \
+ ((min) < 0 \
+ ? (a) < - (max) \
+ : 0 < (a))
+
+/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
+ See above for restrictions. Avoid && and || as they tickle
+ bugs in Sun C 5.11 2010/08/13 and other compilers; see
+ <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00401.html>. */
+#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
+ ((b) < 0 \
+ ? ((a) < 0 \
+ ? (a) < (max) / (b) \
+ : (b) == -1 \
+ ? 0 \
+ : (min) / (b) < (a)) \
+ : (b) == 0 \
+ ? 0 \
+ : ((a) < 0 \
+ ? (a) < (min) / (b) \
+ : (max) / (b) < (a)))
+
+/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic.
+ See above for restrictions. Do not check for division by zero. */
+#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \
+ ((min) < 0 && (b) == -1 && (a) < - (max))
+
+/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic.
+ See above for restrictions. Do not check for division by zero.
+ Mathematically, % should never overflow, but on x86-like hosts
+ INT_MIN % -1 traps, and the C standard permits this, so treat this
+ as an overflow too. */
+#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \
+ INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max)
+
+/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic.
+ See above for restrictions. Here, MIN and MAX are for A only, and B need
+ not be of the same type as the other arguments. The C standard says that
+ behavior is undefined for shifts unless 0 <= B < wordwidth, and that when
+ A is negative then A << B has undefined behavior and A >> B has
+ implementation-defined behavior, but do not check these other
+ restrictions. */
+#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \
+ ((a) < 0 \
+ ? (a) < (min) >> (b) \
+ : (max) >> (b) < (a))
+
+
+/* The _GL*_OVERFLOW macros have the same restrictions as the
+ *_RANGE_OVERFLOW macros, except that they do not assume that operands
+ (e.g., A and B) have the same type as MIN and MAX. Instead, they assume
+ that the result (e.g., A + B) has that type. */
+#define _GL_ADD_OVERFLOW(a, b, min, max) \
+ ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
+ : (a) < 0 ? (b) <= (a) + (b) \
+ : (b) < 0 ? (a) <= (a) + (b) \
+ : (a) + (b) < (b))
+#define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
+ ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
+ : (a) < 0 ? 1 \
+ : (b) < 0 ? (a) - (b) <= (a) \
+ : (a) < (b))
+#define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
+ (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
+ || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
+#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \
+ ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
+ : (a) < 0 ? (b) <= (a) + (b) - 1 \
+ : (b) < 0 && (a) + (b) <= (a))
+#define _GL_REMAINDER_OVERFLOW(a, b, min, max) \
+ ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
+ : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \
+ : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max))
+
+/* Return a nonzero value if A is a mathematical multiple of B, where
+ A is unsigned, B is negative, and MAX is the maximum value of A's
+ type. A's type must be the same as (A % B)'s type. Normally (A %
+ -B == 0) suffices, but things get tricky if -B would overflow. */
+#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \
+ (((b) < -_GL_SIGNED_INT_MAXIMUM (b) \
+ ? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \
+ ? (a) \
+ : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1)) \
+ : (a) % - (b)) \
+ == 0)
+
+
+/* Integer overflow checks.
+
+ The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators
+ might not yield numerically correct answers due to arithmetic overflow.
+ They work correctly on all known practical hosts, and do not rely
+ on undefined behavior due to signed arithmetic overflow.
+
+ Example usage:
+
+ long int i = ...;
+ long int j = ...;
+ if (INT_MULTIPLY_OVERFLOW (i, j))
+ printf ("multiply would overflow");
+ else
+ printf ("product is %ld", i * j);
+
+ These macros do not check for all possible numerical problems or
+ undefined or unspecified behavior: they do not check for division
+ by zero, for bad shift counts, or for shifting negative numbers.
+
+ These macros may evaluate their arguments zero or multiple times, so the
+ arguments should not have side effects.
+
+ These macros are tuned for their last argument being a constant.
+
+ Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
+ A % B, and A << B would overflow, respectively. */
+
+#define INT_ADD_OVERFLOW(a, b) \
+ _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
+#define INT_SUBTRACT_OVERFLOW(a, b) \
+ _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
+#define INT_NEGATE_OVERFLOW(a) \
+ INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
+#define INT_MULTIPLY_OVERFLOW(a, b) \
+ _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
+#define INT_DIVIDE_OVERFLOW(a, b) \
+ _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW)
+#define INT_REMAINDER_OVERFLOW(a, b) \
+ _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW)
+#define INT_LEFT_SHIFT_OVERFLOW(a, b) \
+ INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \
+ _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
+
+/* Return 1 if the expression A <op> B would overflow,
+ where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test,
+ assuming MIN and MAX are the minimum and maximum for the result type.
+ Arguments should be free of side effects. */
+#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
+ op_result_overflow (a, b, \
+ _GL_INT_MINIMUM (0 * (b) + (a)), \
+ _GL_INT_MAXIMUM (0 * (b) + (a)))
+
+#endif /* _GL_INTPROPS_H */
diff --git a/contrib/tools/bison/gnulib/src/isnan.c b/contrib/tools/bison/gnulib/src/isnan.c
index d95e4bac77..d1a29d5aca 100644
--- a/contrib/tools/bison/gnulib/src/isnan.c
+++ b/contrib/tools/bison/gnulib/src/isnan.c
@@ -1,177 +1,177 @@
-/* Test for NaN that does not need libm.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
-
-#include <config.h>
-
-/* Specification. */
-#ifdef USE_LONG_DOUBLE
-/* Specification found in math.h or isnanl-nolibm.h. */
-extern int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
-#elif ! defined USE_FLOAT
-/* Specification found in math.h or isnand-nolibm.h. */
-extern int rpl_isnand (double x);
-#else /* defined USE_FLOAT */
-/* Specification found in math.h or isnanf-nolibm.h. */
-extern int rpl_isnanf (float x);
-#endif
-
-#include <float.h>
-#include <string.h>
-
-#include "float+.h"
-
-#ifdef USE_LONG_DOUBLE
-# define FUNC rpl_isnanl
-# define DOUBLE long double
-# define MAX_EXP LDBL_MAX_EXP
-# define MIN_EXP LDBL_MIN_EXP
-# if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
-# define KNOWN_EXPBIT0_LOCATION
-# define EXPBIT0_WORD LDBL_EXPBIT0_WORD
-# define EXPBIT0_BIT LDBL_EXPBIT0_BIT
-# endif
-# define SIZE SIZEOF_LDBL
-# define L_(literal) literal##L
-#elif ! defined USE_FLOAT
-# define FUNC rpl_isnand
-# define DOUBLE double
-# define MAX_EXP DBL_MAX_EXP
-# define MIN_EXP DBL_MIN_EXP
-# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
-# define KNOWN_EXPBIT0_LOCATION
-# define EXPBIT0_WORD DBL_EXPBIT0_WORD
-# define EXPBIT0_BIT DBL_EXPBIT0_BIT
-# endif
-# define SIZE SIZEOF_DBL
-# define L_(literal) literal
-#else /* defined USE_FLOAT */
-# define FUNC rpl_isnanf
-# define DOUBLE float
-# define MAX_EXP FLT_MAX_EXP
-# define MIN_EXP FLT_MIN_EXP
-# if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
-# define KNOWN_EXPBIT0_LOCATION
-# define EXPBIT0_WORD FLT_EXPBIT0_WORD
-# define EXPBIT0_BIT FLT_EXPBIT0_BIT
-# endif
-# define SIZE SIZEOF_FLT
-# define L_(literal) literal##f
-#endif
-
-#define EXP_MASK ((MAX_EXP - MIN_EXP) | 7)
-
-#define NWORDS \
- ((sizeof (DOUBLE) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
-typedef union { DOUBLE value; unsigned int word[NWORDS]; } memory_double;
-
-int
-FUNC (DOUBLE x)
-{
-#ifdef KNOWN_EXPBIT0_LOCATION
-# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
- /* Special CPU dependent code is needed to treat bit patterns outside the
- IEEE 754 specification (such as Pseudo-NaNs, Pseudo-Infinities,
- Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals) as NaNs.
- These bit patterns are:
- - exponent = 0x0001..0x7FFF, mantissa bit 63 = 0,
- - exponent = 0x0000, mantissa bit 63 = 1.
- The NaN bit pattern is:
- - exponent = 0x7FFF, mantissa >= 0x8000000000000001. */
- memory_double m;
- unsigned int exponent;
-
- m.value = x;
- exponent = (m.word[EXPBIT0_WORD] >> EXPBIT0_BIT) & EXP_MASK;
-# ifdef WORDS_BIGENDIAN
- /* Big endian: EXPBIT0_WORD = 0, EXPBIT0_BIT = 16. */
- if (exponent == 0)
- return 1 & (m.word[0] >> 15);
- else if (exponent == EXP_MASK)
- return (((m.word[0] ^ 0x8000U) << 16) | m.word[1] | (m.word[2] >> 16)) != 0;
- else
- return 1 & ~(m.word[0] >> 15);
-# else
- /* Little endian: EXPBIT0_WORD = 2, EXPBIT0_BIT = 0. */
- if (exponent == 0)
- return (m.word[1] >> 31);
- else if (exponent == EXP_MASK)
- return ((m.word[1] ^ 0x80000000U) | m.word[0]) != 0;
- else
- return (m.word[1] >> 31) ^ 1;
-# endif
-# else
- /* Be careful to not do any floating-point operation on x, such as x == x,
- because x may be a signaling NaN. */
-# if defined __SUNPRO_C || defined __ICC || defined _MSC_VER \
- || defined __DECC || defined __TINYC__ \
- || (defined __sgi && !defined __GNUC__)
- /* The Sun C 5.0, Intel ICC 10.0, Microsoft Visual C/C++ 9.0, Compaq (ex-DEC)
- 6.4, and TinyCC compilers don't recognize the initializers as constant
- expressions. The Compaq compiler also fails when constant-folding
- 0.0 / 0.0 even when constant-folding is not required. The Microsoft
- Visual C/C++ compiler also fails when constant-folding 1.0 / 0.0 even
- when constant-folding is not required. The SGI MIPSpro C compiler
- complains about "floating-point operation result is out of range". */
- static DOUBLE zero = L_(0.0);
- memory_double nan;
- DOUBLE plus_inf = L_(1.0) / zero;
- DOUBLE minus_inf = -L_(1.0) / zero;
- nan.value = zero / zero;
-# else
- static memory_double nan = { L_(0.0) / L_(0.0) };
- static DOUBLE plus_inf = L_(1.0) / L_(0.0);
- static DOUBLE minus_inf = -L_(1.0) / L_(0.0);
-# endif
- {
- memory_double m;
-
- /* A NaN can be recognized through its exponent. But exclude +Infinity and
- -Infinity, which have the same exponent. */
- m.value = x;
- if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
- & (EXP_MASK << EXPBIT0_BIT))
- == 0)
- return (memcmp (&m.value, &plus_inf, SIZE) != 0
- && memcmp (&m.value, &minus_inf, SIZE) != 0);
- else
- return 0;
- }
-# endif
-#else
- /* The configuration did not find sufficient information. Give up about
- the signaling NaNs, handle only the quiet NaNs. */
- if (x == x)
- {
-# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
- /* Detect any special bit patterns that pass ==; see comment above. */
- memory_double m1;
- memory_double m2;
-
- memset (&m1.value, 0, SIZE);
- memset (&m2.value, 0, SIZE);
- m1.value = x;
- m2.value = x + (x ? 0.0L : -0.0L);
- if (memcmp (&m1.value, &m2.value, SIZE) != 0)
- return 1;
-# endif
- return 0;
- }
- else
- return 1;
-#endif
-}
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
+
+#include <config.h>
+
+/* Specification. */
+#ifdef USE_LONG_DOUBLE
+/* Specification found in math.h or isnanl-nolibm.h. */
+extern int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
+#elif ! defined USE_FLOAT
+/* Specification found in math.h or isnand-nolibm.h. */
+extern int rpl_isnand (double x);
+#else /* defined USE_FLOAT */
+/* Specification found in math.h or isnanf-nolibm.h. */
+extern int rpl_isnanf (float x);
+#endif
+
+#include <float.h>
+#include <string.h>
+
+#include "float+.h"
+
+#ifdef USE_LONG_DOUBLE
+# define FUNC rpl_isnanl
+# define DOUBLE long double
+# define MAX_EXP LDBL_MAX_EXP
+# define MIN_EXP LDBL_MIN_EXP
+# if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
+# define KNOWN_EXPBIT0_LOCATION
+# define EXPBIT0_WORD LDBL_EXPBIT0_WORD
+# define EXPBIT0_BIT LDBL_EXPBIT0_BIT
+# endif
+# define SIZE SIZEOF_LDBL
+# define L_(literal) literal##L
+#elif ! defined USE_FLOAT
+# define FUNC rpl_isnand
+# define DOUBLE double
+# define MAX_EXP DBL_MAX_EXP
+# define MIN_EXP DBL_MIN_EXP
+# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+# define KNOWN_EXPBIT0_LOCATION
+# define EXPBIT0_WORD DBL_EXPBIT0_WORD
+# define EXPBIT0_BIT DBL_EXPBIT0_BIT
+# endif
+# define SIZE SIZEOF_DBL
+# define L_(literal) literal
+#else /* defined USE_FLOAT */
+# define FUNC rpl_isnanf
+# define DOUBLE float
+# define MAX_EXP FLT_MAX_EXP
+# define MIN_EXP FLT_MIN_EXP
+# if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
+# define KNOWN_EXPBIT0_LOCATION
+# define EXPBIT0_WORD FLT_EXPBIT0_WORD
+# define EXPBIT0_BIT FLT_EXPBIT0_BIT
+# endif
+# define SIZE SIZEOF_FLT
+# define L_(literal) literal##f
+#endif
+
+#define EXP_MASK ((MAX_EXP - MIN_EXP) | 7)
+
+#define NWORDS \
+ ((sizeof (DOUBLE) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+typedef union { DOUBLE value; unsigned int word[NWORDS]; } memory_double;
+
+int
+FUNC (DOUBLE x)
+{
+#ifdef KNOWN_EXPBIT0_LOCATION
+# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+ /* Special CPU dependent code is needed to treat bit patterns outside the
+ IEEE 754 specification (such as Pseudo-NaNs, Pseudo-Infinities,
+ Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals) as NaNs.
+ These bit patterns are:
+ - exponent = 0x0001..0x7FFF, mantissa bit 63 = 0,
+ - exponent = 0x0000, mantissa bit 63 = 1.
+ The NaN bit pattern is:
+ - exponent = 0x7FFF, mantissa >= 0x8000000000000001. */
+ memory_double m;
+ unsigned int exponent;
+
+ m.value = x;
+ exponent = (m.word[EXPBIT0_WORD] >> EXPBIT0_BIT) & EXP_MASK;
+# ifdef WORDS_BIGENDIAN
+ /* Big endian: EXPBIT0_WORD = 0, EXPBIT0_BIT = 16. */
+ if (exponent == 0)
+ return 1 & (m.word[0] >> 15);
+ else if (exponent == EXP_MASK)
+ return (((m.word[0] ^ 0x8000U) << 16) | m.word[1] | (m.word[2] >> 16)) != 0;
+ else
+ return 1 & ~(m.word[0] >> 15);
+# else
+ /* Little endian: EXPBIT0_WORD = 2, EXPBIT0_BIT = 0. */
+ if (exponent == 0)
+ return (m.word[1] >> 31);
+ else if (exponent == EXP_MASK)
+ return ((m.word[1] ^ 0x80000000U) | m.word[0]) != 0;
+ else
+ return (m.word[1] >> 31) ^ 1;
+# endif
+# else
+ /* Be careful to not do any floating-point operation on x, such as x == x,
+ because x may be a signaling NaN. */
+# if defined __SUNPRO_C || defined __ICC || defined _MSC_VER \
+ || defined __DECC || defined __TINYC__ \
+ || (defined __sgi && !defined __GNUC__)
+ /* The Sun C 5.0, Intel ICC 10.0, Microsoft Visual C/C++ 9.0, Compaq (ex-DEC)
+ 6.4, and TinyCC compilers don't recognize the initializers as constant
+ expressions. The Compaq compiler also fails when constant-folding
+ 0.0 / 0.0 even when constant-folding is not required. The Microsoft
+ Visual C/C++ compiler also fails when constant-folding 1.0 / 0.0 even
+ when constant-folding is not required. The SGI MIPSpro C compiler
+ complains about "floating-point operation result is out of range". */
+ static DOUBLE zero = L_(0.0);
+ memory_double nan;
+ DOUBLE plus_inf = L_(1.0) / zero;
+ DOUBLE minus_inf = -L_(1.0) / zero;
+ nan.value = zero / zero;
+# else
+ static memory_double nan = { L_(0.0) / L_(0.0) };
+ static DOUBLE plus_inf = L_(1.0) / L_(0.0);
+ static DOUBLE minus_inf = -L_(1.0) / L_(0.0);
+# endif
+ {
+ memory_double m;
+
+ /* A NaN can be recognized through its exponent. But exclude +Infinity and
+ -Infinity, which have the same exponent. */
+ m.value = x;
+ if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
+ & (EXP_MASK << EXPBIT0_BIT))
+ == 0)
+ return (memcmp (&m.value, &plus_inf, SIZE) != 0
+ && memcmp (&m.value, &minus_inf, SIZE) != 0);
+ else
+ return 0;
+ }
+# endif
+#else
+ /* The configuration did not find sufficient information. Give up about
+ the signaling NaNs, handle only the quiet NaNs. */
+ if (x == x)
+ {
+# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+ /* Detect any special bit patterns that pass ==; see comment above. */
+ memory_double m1;
+ memory_double m2;
+
+ memset (&m1.value, 0, SIZE);
+ memset (&m2.value, 0, SIZE);
+ m1.value = x;
+ m2.value = x + (x ? 0.0L : -0.0L);
+ if (memcmp (&m1.value, &m2.value, SIZE) != 0)
+ return 1;
+# endif
+ return 0;
+ }
+ else
+ return 1;
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/isnand-nolibm.h b/contrib/tools/bison/gnulib/src/isnand-nolibm.h
index 8a84ff8140..c9390631d0 100644
--- a/contrib/tools/bison/gnulib/src/isnand-nolibm.h
+++ b/contrib/tools/bison/gnulib/src/isnand-nolibm.h
@@ -1,33 +1,33 @@
-/* Test for NaN that does not need libm.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if HAVE_ISNAND_IN_LIBC
-/* Get declaration of isnan macro. */
-# include <math.h>
-# if __GNUC__ >= 4
- /* GCC 4.0 and newer provides three built-ins for isnan. */
-# undef isnand
-# define isnand(x) __builtin_isnan ((double)(x))
-# else
-# undef isnand
-# define isnand(x) isnan ((double)(x))
-# endif
-#else
-/* Test whether X is a NaN. */
-# undef isnand
-# define isnand rpl_isnand
-extern int isnand (double x);
-#endif
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if HAVE_ISNAND_IN_LIBC
+/* Get declaration of isnan macro. */
+# include <math.h>
+# if __GNUC__ >= 4
+ /* GCC 4.0 and newer provides three built-ins for isnan. */
+# undef isnand
+# define isnand(x) __builtin_isnan ((double)(x))
+# else
+# undef isnand
+# define isnand(x) isnan ((double)(x))
+# endif
+#else
+/* Test whether X is a NaN. */
+# undef isnand
+# define isnand rpl_isnand
+extern int isnand (double x);
+#endif
diff --git a/contrib/tools/bison/gnulib/src/isnand.c b/contrib/tools/bison/gnulib/src/isnand.c
index cbad17b583..a087ae590b 100644
--- a/contrib/tools/bison/gnulib/src/isnand.c
+++ b/contrib/tools/bison/gnulib/src/isnand.c
@@ -1,19 +1,19 @@
-/* Test for NaN that does not need libm.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2008. */
-
-#include "isnan.c"
+/* Test for NaN that does not need libm.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2008. */
+
+#include "isnan.c"
diff --git a/contrib/tools/bison/gnulib/src/isnanf-nolibm.h b/contrib/tools/bison/gnulib/src/isnanf-nolibm.h
index 804c65f06c..f4102017a6 100644
--- a/contrib/tools/bison/gnulib/src/isnanf-nolibm.h
+++ b/contrib/tools/bison/gnulib/src/isnanf-nolibm.h
@@ -1,40 +1,40 @@
-/* Test for NaN that does not need libm.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if HAVE_ISNANF_IN_LIBC
-/* Get declaration of isnan macro or (older) isnanf function. */
-# include <math.h>
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if HAVE_ISNANF_IN_LIBC
+/* Get declaration of isnan macro or (older) isnanf function. */
+# include <math.h>
# if __GNUC__ >= 4 && !__clang__
- /* GCC 4.0 and newer provides three built-ins for isnan. */
-# undef isnanf
-# define isnanf(x) __builtin_isnanf ((float)(x))
-# elif defined isnan
-# undef isnanf
-# define isnanf(x) isnan ((float)(x))
-# else
- /* Get declaration of isnanf(), if not declared in <math.h>. */
-# if defined __sgi
- /* We can't include <ieeefp.h>, because it conflicts with our definition of
- isnand. Therefore declare isnanf separately. */
-extern int isnanf (float x);
-# endif
-# endif
-#else
-/* Test whether X is a NaN. */
-# undef isnanf
-# define isnanf rpl_isnanf
-extern int isnanf (float x);
-#endif
+ /* GCC 4.0 and newer provides three built-ins for isnan. */
+# undef isnanf
+# define isnanf(x) __builtin_isnanf ((float)(x))
+# elif defined isnan
+# undef isnanf
+# define isnanf(x) isnan ((float)(x))
+# else
+ /* Get declaration of isnanf(), if not declared in <math.h>. */
+# if defined __sgi
+ /* We can't include <ieeefp.h>, because it conflicts with our definition of
+ isnand. Therefore declare isnanf separately. */
+extern int isnanf (float x);
+# endif
+# endif
+#else
+/* Test whether X is a NaN. */
+# undef isnanf
+# define isnanf rpl_isnanf
+extern int isnanf (float x);
+#endif
diff --git a/contrib/tools/bison/gnulib/src/isnanf.c b/contrib/tools/bison/gnulib/src/isnanf.c
index 946cb69ce0..0ad4591f32 100644
--- a/contrib/tools/bison/gnulib/src/isnanf.c
+++ b/contrib/tools/bison/gnulib/src/isnanf.c
@@ -1,20 +1,20 @@
-/* Test for NaN that does not need libm.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
-
-#define USE_FLOAT
-#include "isnan.c"
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
+
+#define USE_FLOAT
+#include "isnan.c"
diff --git a/contrib/tools/bison/gnulib/src/isnanl-nolibm.h b/contrib/tools/bison/gnulib/src/isnanl-nolibm.h
index a011374da7..1adafb9815 100644
--- a/contrib/tools/bison/gnulib/src/isnanl-nolibm.h
+++ b/contrib/tools/bison/gnulib/src/isnanl-nolibm.h
@@ -1,33 +1,33 @@
-/* Test for NaN that does not need libm.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if HAVE_ISNANL_IN_LIBC
-/* Get declaration of isnan macro or (older) isnanl function. */
-# include <math.h>
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if HAVE_ISNANL_IN_LIBC
+/* Get declaration of isnan macro or (older) isnanl function. */
+# include <math.h>
# if __GNUC__ >= 4 && !__clang__
- /* GCC 4.0 and newer provides three built-ins for isnan. */
-# undef isnanl
-# define isnanl(x) __builtin_isnanl ((long double)(x))
-# elif defined isnan
-# undef isnanl
-# define isnanl(x) isnan ((long double)(x))
-# endif
-#else
-/* Test whether X is a NaN. */
-# undef isnanl
-# define isnanl rpl_isnanl
-extern int isnanl (long double x);
-#endif
+ /* GCC 4.0 and newer provides three built-ins for isnan. */
+# undef isnanl
+# define isnanl(x) __builtin_isnanl ((long double)(x))
+# elif defined isnan
+# undef isnanl
+# define isnanl(x) isnan ((long double)(x))
+# endif
+#else
+/* Test whether X is a NaN. */
+# undef isnanl
+# define isnanl rpl_isnanl
+extern int isnanl (long double x);
+#endif
diff --git a/contrib/tools/bison/gnulib/src/isnanl.c b/contrib/tools/bison/gnulib/src/isnanl.c
index 9d9d84b974..b223b3420d 100644
--- a/contrib/tools/bison/gnulib/src/isnanl.c
+++ b/contrib/tools/bison/gnulib/src/isnanl.c
@@ -1,20 +1,20 @@
-/* Test for NaN that does not need libm.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
-
-#define USE_LONG_DOUBLE
-#include "isnan.c"
+/* Test for NaN that does not need libm.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
+
+#define USE_LONG_DOUBLE
+#include "isnan.c"
diff --git a/contrib/tools/bison/gnulib/src/itold.c b/contrib/tools/bison/gnulib/src/itold.c
index 9aabc7e464..432f677f62 100644
--- a/contrib/tools/bison/gnulib/src/itold.c
+++ b/contrib/tools/bison/gnulib/src/itold.c
@@ -1,28 +1,28 @@
-/* Replacement for 'int' to 'long double' conversion routine.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2011.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <float.h>
-
-void
-_Qp_itoq (long double *result, int a)
-{
- /* Convert from 'int' to 'double', then from 'double' to 'long double'. */
- *result = (double) a;
-}
+/* Replacement for 'int' to 'long double' conversion routine.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <float.h>
+
+void
+_Qp_itoq (long double *result, int a)
+{
+ /* Convert from 'int' to 'double', then from 'double' to 'long double'. */
+ *result = (double) a;
+}
diff --git a/contrib/tools/bison/gnulib/src/lbitset.c b/contrib/tools/bison/gnulib/src/lbitset.c
index 7a638c6f9b..aa801a1afe 100644
--- a/contrib/tools/bison/gnulib/src/lbitset.c
+++ b/contrib/tools/bison/gnulib/src/lbitset.c
@@ -1,1401 +1,1401 @@
-/* Functions to support link list bitsets.
-
- Copyright (C) 2002-2004, 2006, 2009-2013 Free Software Foundation,
- Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "lbitset.h"
-
-#include "obstack.h"
-#include <stddef.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-/* This file implements linked-list bitsets. These bitsets can be of
- arbitrary length and are more efficient than arrays of bits for
- large sparse sets.
-
- Usually if all the bits in an element are zero we remove the element
- from the list. However, a side effect of the bit caching is that we
- do not always notice when an element becomes zero. Hence the
- lbitset_weed function which removes zero elements. */
-
-
-/* Number of words to use for each element. The larger the value the
- greater the size of the cache and the shorter the time to find a given bit
- but the more memory wasted for sparse bitsets and the longer the time
- to search for set bits.
-
- The routines that dominate timing profiles are lbitset_elt_find
- and lbitset_elt_link, especially when accessing the bits randomly. */
-
-#define LBITSET_ELT_WORDS 2
-
-typedef bitset_word lbitset_word;
-
-#define LBITSET_WORD_BITS BITSET_WORD_BITS
-
-/* Number of bits stored in each element. */
-#define LBITSET_ELT_BITS \
- ((unsigned int) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS))
-
-/* Lbitset element. We use an array of bits for each element.
- These are linked together in a doubly-linked list. */
-typedef struct lbitset_elt_struct
-{
- struct lbitset_elt_struct *next; /* Next element. */
- struct lbitset_elt_struct *prev; /* Previous element. */
- bitset_windex index; /* bitno / BITSET_WORD_BITS. */
- bitset_word words[LBITSET_ELT_WORDS]; /* Bits that are set. */
-}
-lbitset_elt;
-
-
-enum lbitset_find_mode
- { LBITSET_FIND, LBITSET_CREATE, LBITSET_SUBST };
-
-static lbitset_elt lbitset_zero_elts[3]; /* Elements of all zero bits. */
-
-/* Obstack to allocate bitset elements from. */
-static struct obstack lbitset_obstack;
-static bool lbitset_obstack_init = false;
-static lbitset_elt *lbitset_free_list; /* Free list of bitset elements. */
-
-extern void debug_lbitset (bitset);
-
-#define LBITSET_CURRENT1(X) \
- ((lbitset_elt *) (void *) ((char *) (X) - offsetof (lbitset_elt, words)))
-
-#define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
-
-#define LBITSET_HEAD(X) ((X)->l.head)
-#define LBITSET_TAIL(X) ((X)->l.tail)
-
-/* Allocate a lbitset element. The bits are not cleared. */
-static inline lbitset_elt *
-lbitset_elt_alloc (void)
-{
- lbitset_elt *elt;
-
- if (lbitset_free_list != 0)
- {
- elt = lbitset_free_list;
- lbitset_free_list = elt->next;
- }
- else
- {
- if (!lbitset_obstack_init)
- {
- lbitset_obstack_init = true;
-
- /* Let particular systems override the size of a chunk. */
-
-#ifndef OBSTACK_CHUNK_SIZE
-#define OBSTACK_CHUNK_SIZE 0
-#endif
-
- /* Let them override the alloc and free routines too. */
-
-#ifndef OBSTACK_CHUNK_ALLOC
-#define OBSTACK_CHUNK_ALLOC xmalloc
-#endif
-
-#ifndef OBSTACK_CHUNK_FREE
-#define OBSTACK_CHUNK_FREE free
-#endif
-
-#if ! defined __GNUC__ || __GNUC__ < 2
-#define __alignof__(type) 0
-#endif
-
- obstack_specify_allocation (&lbitset_obstack, OBSTACK_CHUNK_SIZE,
- __alignof__ (lbitset_elt),
- OBSTACK_CHUNK_ALLOC,
- OBSTACK_CHUNK_FREE);
- }
-
- /* Perhaps we should add a number of new elements to the free
- list. */
- elt = (lbitset_elt *) obstack_alloc (&lbitset_obstack,
- sizeof (lbitset_elt));
- }
-
- return elt;
-}
-
-
-/* Allocate a lbitset element. The bits are cleared. */
-static inline lbitset_elt *
-lbitset_elt_calloc (void)
-{
- lbitset_elt *elt;
-
- elt = lbitset_elt_alloc ();
- memset (elt->words, 0, sizeof (elt->words));
- return elt;
-}
-
-
-static inline void
-lbitset_elt_free (lbitset_elt *elt)
-{
- elt->next = lbitset_free_list;
- lbitset_free_list = elt;
-}
-
-
-/* Unlink element ELT from bitset BSET. */
-static inline void
-lbitset_elt_unlink (bitset bset, lbitset_elt *elt)
-{
- lbitset_elt *next = elt->next;
- lbitset_elt *prev = elt->prev;
-
- if (prev)
- prev->next = next;
-
- if (next)
- next->prev = prev;
-
- if (LBITSET_HEAD (bset) == elt)
- LBITSET_HEAD (bset) = next;
- if (LBITSET_TAIL (bset) == elt)
- LBITSET_TAIL (bset) = prev;
-
- /* Update cache pointer. Since the first thing we try is to insert
- before current, make current the next entry in preference to the
- previous. */
- if (LBITSET_CURRENT (bset) == elt)
- {
- if (next)
- {
- bset->b.cdata = next->words;
- bset->b.cindex = next->index;
- }
- else if (prev)
- {
- bset->b.cdata = prev->words;
- bset->b.cindex = prev->index;
- }
- else
- {
- bset->b.csize = 0;
- bset->b.cdata = 0;
- }
- }
-
- lbitset_elt_free (elt);
-}
-
-
-/* Cut the chain of bitset BSET before element ELT and free the
- elements. */
-static inline void
-lbitset_prune (bitset bset, lbitset_elt *elt)
-{
- lbitset_elt *next;
-
- if (!elt)
- return;
-
- if (elt->prev)
- {
- LBITSET_TAIL (bset) = elt->prev;
- bset->b.cdata = elt->prev->words;
- bset->b.cindex = elt->prev->index;
- elt->prev->next = 0;
- }
- else
- {
- LBITSET_HEAD (bset) = 0;
- LBITSET_TAIL (bset) = 0;
- bset->b.cdata = 0;
- bset->b.csize = 0;
- }
-
- for (; elt; elt = next)
- {
- next = elt->next;
- lbitset_elt_free (elt);
- }
-}
-
-
-/* Are all bits in an element zero? */
-static inline bool
-lbitset_elt_zero_p (lbitset_elt *elt)
-{
- int i;
-
- for (i = 0; i < LBITSET_ELT_WORDS; i++)
- if (elt->words[i])
- return false;
-
- return true;
-}
-
-
-/* Link the bitset element into the current bitset linked list. */
-static inline void
-lbitset_elt_link (bitset bset, lbitset_elt *elt)
-{
- bitset_windex windex = elt->index;
- lbitset_elt *ptr;
- lbitset_elt *current;
-
- if (bset->b.csize)
- current = LBITSET_CURRENT (bset);
- else
- current = LBITSET_HEAD (bset);
-
- /* If this is the first and only element, add it in. */
- if (LBITSET_HEAD (bset) == 0)
- {
- elt->next = elt->prev = 0;
- LBITSET_HEAD (bset) = elt;
- LBITSET_TAIL (bset) = elt;
- }
-
- /* If this index is less than that of the current element, it goes
- somewhere before the current element. */
- else if (windex < bset->b.cindex)
- {
- for (ptr = current;
- ptr->prev && ptr->prev->index > windex; ptr = ptr->prev)
- continue;
-
- if (ptr->prev)
- ptr->prev->next = elt;
- else
- LBITSET_HEAD (bset) = elt;
-
- elt->prev = ptr->prev;
- elt->next = ptr;
- ptr->prev = elt;
- }
-
- /* Otherwise, it must go somewhere after the current element. */
- else
- {
- for (ptr = current;
- ptr->next && ptr->next->index < windex; ptr = ptr->next)
- continue;
-
- if (ptr->next)
- ptr->next->prev = elt;
- else
- LBITSET_TAIL (bset) = elt;
-
- elt->next = ptr->next;
- elt->prev = ptr;
- ptr->next = elt;
- }
-
- /* Set up so this is the first element searched. */
- bset->b.cindex = windex;
- bset->b.csize = LBITSET_ELT_WORDS;
- bset->b.cdata = elt->words;
-}
-
-
-static lbitset_elt *
-lbitset_elt_find (bitset bset, bitset_windex windex,
- enum lbitset_find_mode mode)
-{
- lbitset_elt *elt;
- lbitset_elt *current;
-
- if (bset->b.csize)
- {
- current = LBITSET_CURRENT (bset);
- /* Check if element is the cached element. */
- if ((windex - bset->b.cindex) < bset->b.csize)
- return current;
- }
- else
- {
- current = LBITSET_HEAD (bset);
- }
-
- if (current)
- {
- if (windex < bset->b.cindex)
- {
- for (elt = current;
- elt->prev && elt->index > windex; elt = elt->prev)
- continue;
- }
- else
- {
- for (elt = current;
- elt->next && (elt->index + LBITSET_ELT_WORDS - 1) < windex;
- elt = elt->next)
- continue;
- }
-
- /* ELT is the nearest to the one we want. If it's not the one
- we want, the one we want does not exist. */
- if (windex - elt->index < LBITSET_ELT_WORDS)
- {
- bset->b.cindex = elt->index;
- bset->b.csize = LBITSET_ELT_WORDS;
- bset->b.cdata = elt->words;
- return elt;
- }
- }
-
- switch (mode)
- {
- default:
- abort ();
-
- case LBITSET_FIND:
- return 0;
-
- case LBITSET_CREATE:
- windex -= windex % LBITSET_ELT_WORDS;
-
- elt = lbitset_elt_calloc ();
- elt->index = windex;
- lbitset_elt_link (bset, elt);
- return elt;
-
- case LBITSET_SUBST:
- return &lbitset_zero_elts[0];
- }
-}
-
-
-/* Weed out the zero elements from the list. */
-static inline void
-lbitset_weed (bitset bset)
-{
- lbitset_elt *elt;
- lbitset_elt *next;
-
- for (elt = LBITSET_HEAD (bset); elt; elt = next)
- {
- next = elt->next;
- if (lbitset_elt_zero_p (elt))
- lbitset_elt_unlink (bset, elt);
- }
-}
-
-
-/* Set all bits in the bitset to zero. */
-static void
-lbitset_zero (bitset bset)
-{
- lbitset_elt *head;
-
- head = LBITSET_HEAD (bset);
- if (!head)
- return;
-
- /* Clear a bitset by freeing the linked list at the head element. */
- lbitset_prune (bset, head);
-}
-
-
-/* Is DST == SRC? */
-static inline bool
-lbitset_equal_p (bitset dst, bitset src)
-{
- lbitset_elt *selt;
- lbitset_elt *delt;
- int j;
-
- if (src == dst)
- return true;
-
- lbitset_weed (src);
- lbitset_weed (dst);
- for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst);
- selt && delt; selt = selt->next, delt = delt->next)
- {
- if (selt->index != delt->index)
- return false;
-
- for (j = 0; j < LBITSET_ELT_WORDS; j++)
- if (delt->words[j] != selt->words[j])
- return false;
- }
- return !selt && !delt;
-}
-
-
-/* Copy bits from bitset SRC to bitset DST. */
-static inline void
-lbitset_copy (bitset dst, bitset src)
-{
- lbitset_elt *elt;
- lbitset_elt *head;
- lbitset_elt *prev;
- lbitset_elt *tmp;
-
- if (src == dst)
- return;
-
- lbitset_zero (dst);
-
- head = LBITSET_HEAD (src);
- if (!head)
- return;
-
- prev = 0;
- for (elt = head; elt; elt = elt->next)
- {
- tmp = lbitset_elt_alloc ();
- tmp->index = elt->index;
- tmp->prev = prev;
- tmp->next = 0;
- if (prev)
- prev->next = tmp;
- else
- LBITSET_HEAD (dst) = tmp;
- prev = tmp;
-
- memcpy (tmp->words, elt->words, sizeof (elt->words));
- }
- LBITSET_TAIL (dst) = tmp;
-
- dst->b.csize = LBITSET_ELT_WORDS;
- dst->b.cdata = LBITSET_HEAD (dst)->words;
- dst->b.cindex = LBITSET_HEAD (dst)->index;
-}
-
-
-/* Copy bits from bitset SRC to bitset DST. Return true if
- bitsets different. */
-static inline bool
-lbitset_copy_cmp (bitset dst, bitset src)
-{
- if (src == dst)
- return false;
-
- if (!LBITSET_HEAD (dst))
- {
- lbitset_copy (dst, src);
- return LBITSET_HEAD (src) != 0;
- }
-
- if (lbitset_equal_p (dst, src))
- return false;
-
- lbitset_copy (dst, src);
- return true;
-}
-
-
-static bitset_bindex
-lbitset_resize (bitset src, bitset_bindex size)
-{
- BITSET_NBITS_ (src) = size;
-
- /* Need to prune any excess bits. FIXME. */
- return size;
-}
-
-/* Set bit BITNO in bitset DST. */
-static void
-lbitset_set (bitset dst, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
-
- lbitset_elt_find (dst, windex, LBITSET_CREATE);
-
- dst->b.cdata[windex - dst->b.cindex] |=
- (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
-}
-
-
-/* Reset bit BITNO in bitset DST. */
-static void
-lbitset_reset (bitset dst, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
-
- if (!lbitset_elt_find (dst, windex, LBITSET_FIND))
- return;
-
- dst->b.cdata[windex - dst->b.cindex] &=
- ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
-
- /* If all the data is zero, perhaps we should unlink it now... */
-}
-
-
-/* Test bit BITNO in bitset SRC. */
-static bool
-lbitset_test (bitset src, bitset_bindex bitno)
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
-
- return (lbitset_elt_find (src, windex, LBITSET_FIND)
- && ((src->b.cdata[windex - src->b.cindex]
- >> (bitno % BITSET_WORD_BITS))
- & 1));
-}
-
-
-static void
-lbitset_free (bitset bset)
-{
- lbitset_zero (bset);
-}
-
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT and store in array LIST. Return with actual number of bits
- found and with *NEXT indicating where search stopped. */
-static bitset_bindex
-lbitset_list_reverse (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex rbitno;
- bitset_bindex bitno;
- unsigned int bcount;
- bitset_bindex boffset;
- bitset_windex windex;
- bitset_bindex count;
- lbitset_elt *elt;
- bitset_word word;
- bitset_bindex n_bits;
-
- elt = LBITSET_TAIL (bset);
- if (!elt)
- return 0;
-
- n_bits = (elt->index + LBITSET_ELT_WORDS) * BITSET_WORD_BITS;
- rbitno = *next;
-
- if (rbitno >= n_bits)
- return 0;
-
- bitno = n_bits - (rbitno + 1);
-
- windex = bitno / BITSET_WORD_BITS;
-
- /* Skip back to starting element. */
- for (; elt && elt->index > windex; elt = elt->prev)
- continue;
-
- if (!elt)
- return 0;
-
- if (windex >= elt->index + LBITSET_ELT_WORDS)
- {
- /* We are trying to start in no-mans land so start
- at end of current elt. */
- bcount = BITSET_WORD_BITS - 1;
- windex = elt->index + LBITSET_ELT_WORDS - 1;
- }
- else
- {
- bcount = bitno % BITSET_WORD_BITS;
- }
-
- count = 0;
- boffset = windex * BITSET_WORD_BITS;
-
- /* If num is 1, we could speed things up with a binary search
- of the word of interest. */
-
- while (elt)
- {
- bitset_word *srcp = elt->words;
-
- for (; (windex - elt->index) < LBITSET_ELT_WORDS;
- windex--, boffset -= BITSET_WORD_BITS,
- bcount = BITSET_WORD_BITS - 1)
- {
- word =
- srcp[windex - elt->index] << (BITSET_WORD_BITS - 1 - bcount);
-
- for (; word; bcount--)
- {
- if (word & BITSET_MSB)
- {
- list[count++] = boffset + bcount;
- if (count >= num)
- {
- *next = n_bits - (boffset + bcount);
- return count;
- }
- }
- word <<= 1;
- }
- }
-
- elt = elt->prev;
- if (elt)
- {
- windex = elt->index + LBITSET_ELT_WORDS - 1;
- boffset = windex * BITSET_WORD_BITS;
- }
- }
-
- *next = n_bits - (boffset + 1);
- return count;
-}
-
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT and store in array LIST. Return with actual number of bits
- found and with *NEXT indicating where search stopped. */
-static bitset_bindex
-lbitset_list (bitset bset, bitset_bindex *list,
- bitset_bindex num, bitset_bindex *next)
-{
- bitset_bindex bitno;
- bitset_windex windex;
- bitset_bindex count;
- lbitset_elt *elt;
- lbitset_elt *head;
- bitset_word word;
-
- head = LBITSET_HEAD (bset);
- if (!head)
- return 0;
-
- bitno = *next;
- count = 0;
-
- if (!bitno)
- {
- /* This is the most common case. */
-
- /* Start with the first element. */
- elt = head;
- windex = elt->index;
- bitno = windex * BITSET_WORD_BITS;
- }
- else
- {
- windex = bitno / BITSET_WORD_BITS;
-
- /* Skip to starting element. */
- for (elt = head;
- elt && (elt->index + LBITSET_ELT_WORDS - 1) < windex;
- elt = elt->next)
- continue;
-
- if (!elt)
- return 0;
-
- if (windex < elt->index)
- {
- windex = elt->index;
- bitno = windex * BITSET_WORD_BITS;
- }
- else
- {
- bitset_word *srcp = elt->words;
-
- /* We are starting within an element. */
-
- for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++)
- {
- word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS);
-
- for (; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- bitno = (windex + 1) * BITSET_WORD_BITS;
- }
-
- elt = elt->next;
- if (elt)
- {
- windex = elt->index;
- bitno = windex * BITSET_WORD_BITS;
- }
- }
- }
-
-
- /* If num is 1, we could speed things up with a binary search
- of the word of interest. */
-
- while (elt)
- {
- int i;
- bitset_word *srcp = elt->words;
-
- if ((count + LBITSET_ELT_BITS) < num)
- {
- /* The coast is clear, plant boot! */
-
-#if LBITSET_ELT_WORDS == 2
- word = srcp[0];
- if (word)
- {
- if (!(word & 0xffff))
- {
- word >>= 16;
- bitno += 16;
- }
- if (!(word & 0xff))
- {
- word >>= 8;
- bitno += 8;
- }
- for (; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- windex++;
- bitno = windex * BITSET_WORD_BITS;
-
- word = srcp[1];
- if (word)
- {
- if (!(word & 0xffff))
- {
- word >>= 16;
- bitno += 16;
- }
- for (; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- windex++;
- bitno = windex * BITSET_WORD_BITS;
-#else
- for (i = 0; i < LBITSET_ELT_WORDS; i++)
- {
- word = srcp[i];
- if (word)
- {
- if (!(word & 0xffff))
- {
- word >>= 16;
- bitno += 16;
- }
- if (!(word & 0xff))
- {
- word >>= 8;
- bitno += 8;
- }
- for (; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- windex++;
- bitno = windex * BITSET_WORD_BITS;
- }
-#endif
- }
- else
- {
- /* Tread more carefully since we need to check
- if array overflows. */
-
- for (i = 0; i < LBITSET_ELT_WORDS; i++)
- {
- for (word = srcp[i]; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- windex++;
- bitno = windex * BITSET_WORD_BITS;
- }
- }
-
- elt = elt->next;
- if (elt)
- {
- windex = elt->index;
- bitno = windex * BITSET_WORD_BITS;
- }
- }
-
- *next = bitno;
- return count;
-}
-
-
-static bool
-lbitset_empty_p (bitset dst)
-{
- lbitset_elt *elt;
- lbitset_elt *next;
-
- for (elt = LBITSET_HEAD (dst); elt; elt = next)
- {
- next = elt->next;
- if (!lbitset_elt_zero_p (elt))
- return 0;
- /* Weed as we go. */
- lbitset_elt_unlink (dst, elt);
- }
-
- return 1;
-}
-
-
-/* Ensure that any unused bits within the last element are clear. */
-static inline void
-lbitset_unused_clear (bitset dst)
-{
- unsigned int last_bit;
- bitset_bindex n_bits;
-
- n_bits = BITSET_SIZE_ (dst);
- last_bit = n_bits % LBITSET_ELT_BITS;
-
- if (last_bit)
- {
- lbitset_elt *elt;
- bitset_windex windex;
- bitset_word *srcp;
-
- elt = LBITSET_TAIL (dst);
- srcp = elt->words;
- windex = n_bits / BITSET_WORD_BITS;
-
- srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1;
- windex++;
-
- for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++)
- srcp[windex - elt->index] = 0;
- }
-}
-
-
-static void
-lbitset_ones (bitset dst)
-{
- bitset_windex i;
- bitset_windex windex;
- lbitset_elt *elt;
-
- /* This is a decidedly unfriendly operation for a linked list
- bitset! It makes a sparse bitset become dense. An alternative
- is to have a flag that indicates that the bitset stores the
- complement of what it indicates. */
-
- windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS;
-
- for (i = 0; i < windex; i += LBITSET_ELT_WORDS)
- {
- /* Create new elements if they cannot be found. */
- elt = lbitset_elt_find (dst, i, LBITSET_CREATE);
- memset (elt->words, -1, sizeof (elt->words));
- }
-
- lbitset_unused_clear (dst);
-}
-
-
-static void
-lbitset_not (bitset dst, bitset src)
-{
- lbitset_elt *selt;
- lbitset_elt *delt;
- bitset_windex i;
- unsigned int j;
- bitset_windex windex;
-
- windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS;
-
- for (i = 0; i < windex; i += LBITSET_ELT_WORDS)
- {
- /* Create new elements for dst if they cannot be found
- or substitute zero elements if src elements not found. */
- selt = lbitset_elt_find (src, i, LBITSET_SUBST);
- delt = lbitset_elt_find (dst, i, LBITSET_CREATE);
-
- for (j = 0; j < LBITSET_ELT_WORDS; j++)
- delt->words[j] = ~selt->words[j];
- }
- lbitset_unused_clear (dst);
- lbitset_weed (dst);
- return;
-}
-
-
-/* Is DST == DST | SRC? */
-static bool
-lbitset_subset_p (bitset dst, bitset src)
-{
- lbitset_elt *selt;
- lbitset_elt *delt;
- unsigned int j;
-
- for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst);
- selt || delt; selt = selt->next, delt = delt->next)
- {
- if (!selt)
- selt = &lbitset_zero_elts[0];
- else if (!delt)
- delt = &lbitset_zero_elts[0];
- else if (selt->index != delt->index)
- {
- if (selt->index < delt->index)
- {
- lbitset_zero_elts[2].next = delt;
- delt = &lbitset_zero_elts[2];
- }
- else
- {
- lbitset_zero_elts[1].next = selt;
- selt = &lbitset_zero_elts[1];
- }
- }
-
- for (j = 0; j < LBITSET_ELT_WORDS; j++)
- if (delt->words[j] != (selt->words[j] | delt->words[j]))
- return false;
- }
- return true;
-}
-
-
-/* Is DST & SRC == 0? */
-static bool
-lbitset_disjoint_p (bitset dst, bitset src)
-{
- lbitset_elt *selt;
- lbitset_elt *delt;
- unsigned int j;
-
- for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst);
- selt && delt; selt = selt->next, delt = delt->next)
- {
- if (selt->index != delt->index)
- {
- if (selt->index < delt->index)
- {
- lbitset_zero_elts[2].next = delt;
- delt = &lbitset_zero_elts[2];
- }
- else
- {
- lbitset_zero_elts[1].next = selt;
- selt = &lbitset_zero_elts[1];
- }
- /* Since the elements are different, there is no
- intersection of these elements. */
- continue;
- }
-
- for (j = 0; j < LBITSET_ELT_WORDS; j++)
- if (selt->words[j] & delt->words[j])
- return false;
- }
- return true;
-}
-
-
-static bool
-lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
-{
- lbitset_elt *selt1 = LBITSET_HEAD (src1);
- lbitset_elt *selt2 = LBITSET_HEAD (src2);
- lbitset_elt *delt = LBITSET_HEAD (dst);
- bitset_windex windex1;
- bitset_windex windex2;
- bitset_windex windex;
- lbitset_elt *stmp1;
- lbitset_elt *stmp2;
- lbitset_elt *dtmp;
- bitset_word *srcp1;
- bitset_word *srcp2;
- bitset_word *dstp;
- bool changed = false;
- unsigned int i;
-
- LBITSET_HEAD (dst) = 0;
- dst->b.csize = 0;
-
- windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX;
- windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX;
-
- while (selt1 || selt2)
- {
- /* Figure out whether we need to substitute zero elements for
- missing links. */
- if (windex1 == windex2)
- {
- windex = windex1;
- stmp1 = selt1;
- stmp2 = selt2;
- selt1 = selt1->next;
- windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX;
- selt2 = selt2->next;
- windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX;
- }
- else if (windex1 < windex2)
- {
- windex = windex1;
- stmp1 = selt1;
- stmp2 = &lbitset_zero_elts[0];
- selt1 = selt1->next;
- windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX;
- }
- else
- {
- windex = windex2;
- stmp1 = &lbitset_zero_elts[0];
- stmp2 = selt2;
- selt2 = selt2->next;
- windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX;
- }
-
- /* Find the appropriate element from DST. Begin by discarding
- elements that we've skipped. */
- while (delt && delt->index < windex)
- {
- changed = true;
- dtmp = delt;
- delt = delt->next;
- lbitset_elt_free (dtmp);
- }
- if (delt && delt->index == windex)
- {
- dtmp = delt;
- delt = delt->next;
- }
- else
- dtmp = lbitset_elt_calloc ();
-
- /* Do the operation, and if any bits are set, link it into the
- linked list. */
- srcp1 = stmp1->words;
- srcp2 = stmp2->words;
- dstp = dtmp->words;
- switch (op)
- {
- default:
- abort ();
-
- case BITSET_OP_OR:
- for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ | *srcp2++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
-
- case BITSET_OP_AND:
- for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ & *srcp2++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
-
- case BITSET_OP_XOR:
- for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ ^ *srcp2++;
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
-
- case BITSET_OP_ANDN:
- for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
- {
- bitset_word tmp = *srcp1++ & ~(*srcp2++);
-
- if (*dstp != tmp)
- {
- changed = true;
- *dstp = tmp;
- }
- }
- break;
- }
-
- if (!lbitset_elt_zero_p (dtmp))
- {
- dtmp->index = windex;
- /* Perhaps this could be optimised... */
- lbitset_elt_link (dst, dtmp);
- }
- else
- {
- lbitset_elt_free (dtmp);
- }
- }
-
- /* If we have elements of DST left over, free them all. */
- if (delt)
- {
- changed = true;
- lbitset_prune (dst, delt);
- }
-
- return changed;
-}
-
-
-static bool
-lbitset_and_cmp (bitset dst, bitset src1, bitset src2)
-{
- lbitset_elt *selt1 = LBITSET_HEAD (src1);
- lbitset_elt *selt2 = LBITSET_HEAD (src2);
- bool changed;
-
- if (!selt2)
- {
- lbitset_weed (dst);
- changed = !LBITSET_HEAD (dst);
- lbitset_zero (dst);
- return changed;
- }
- else if (!selt1)
- {
- lbitset_weed (dst);
- changed = !LBITSET_HEAD (dst);
- lbitset_zero (dst);
- return changed;
- }
- return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
-}
-
-
-static void
-lbitset_and (bitset dst, bitset src1, bitset src2)
-{
- lbitset_and_cmp (dst, src1, src2);
-}
-
-
-static bool
-lbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
-{
- lbitset_elt *selt1 = LBITSET_HEAD (src1);
- lbitset_elt *selt2 = LBITSET_HEAD (src2);
- bool changed;
-
- if (!selt2)
- {
- return lbitset_copy_cmp (dst, src1);
- }
- else if (!selt1)
- {
- lbitset_weed (dst);
- changed = !LBITSET_HEAD (dst);
- lbitset_zero (dst);
- return changed;
- }
- return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
-}
-
-
-static void
-lbitset_andn (bitset dst, bitset src1, bitset src2)
-{
- lbitset_andn_cmp (dst, src1, src2);
-}
-
-
-static bool
-lbitset_or_cmp (bitset dst, bitset src1, bitset src2)
-{
- lbitset_elt *selt1 = LBITSET_HEAD (src1);
- lbitset_elt *selt2 = LBITSET_HEAD (src2);
-
- if (!selt2)
- {
- return lbitset_copy_cmp (dst, src1);
- }
- else if (!selt1)
- {
- return lbitset_copy_cmp (dst, src2);
- }
- return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
-}
-
-
-static void
-lbitset_or (bitset dst, bitset src1, bitset src2)
-{
- lbitset_or_cmp (dst, src1, src2);
-}
-
-
-static bool
-lbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
-{
- lbitset_elt *selt1 = LBITSET_HEAD (src1);
- lbitset_elt *selt2 = LBITSET_HEAD (src2);
-
- if (!selt2)
- {
- return lbitset_copy_cmp (dst, src1);
- }
- else if (!selt1)
- {
- return lbitset_copy_cmp (dst, src2);
- }
- return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
-}
-
-
-static void
-lbitset_xor (bitset dst, bitset src1, bitset src2)
-{
- lbitset_xor_cmp (dst, src1, src2);
-}
-
-
-
-/* Vector of operations for linked-list bitsets. */
-struct bitset_vtable lbitset_vtable = {
- lbitset_set,
- lbitset_reset,
- bitset_toggle_,
- lbitset_test,
- lbitset_resize,
- bitset_size_,
- bitset_count_,
- lbitset_empty_p,
- lbitset_ones,
- lbitset_zero,
- lbitset_copy,
- lbitset_disjoint_p,
- lbitset_equal_p,
- lbitset_not,
- lbitset_subset_p,
- lbitset_and,
- lbitset_and_cmp,
- lbitset_andn,
- lbitset_andn_cmp,
- lbitset_or,
- lbitset_or_cmp,
- lbitset_xor,
- lbitset_xor_cmp,
- bitset_and_or_,
- bitset_and_or_cmp_,
- bitset_andn_or_,
- bitset_andn_or_cmp_,
- bitset_or_and_,
- bitset_or_and_cmp_,
- lbitset_list,
- lbitset_list_reverse,
- lbitset_free,
- BITSET_LIST
-};
-
-
-/* Return size of initial structure. */
-size_t
-lbitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED)
-{
- return sizeof (struct lbitset_struct);
-}
-
-
-/* Initialize a bitset. */
-bitset
-lbitset_init (bitset bset, bitset_bindex n_bits ATTRIBUTE_UNUSED)
-{
- BITSET_NBITS_ (bset) = n_bits;
- bset->b.vtable = &lbitset_vtable;
- return bset;
-}
-
-
-void
-lbitset_release_memory (void)
-{
- lbitset_free_list = 0;
- if (lbitset_obstack_init)
- {
- lbitset_obstack_init = false;
- obstack_free (&lbitset_obstack, NULL);
- }
-}
-
-
-/* Function to be called from debugger to debug lbitset. */
-void
-debug_lbitset (bitset bset)
-{
- lbitset_elt *elt;
- unsigned int i;
-
- if (!bset)
- return;
-
- for (elt = LBITSET_HEAD (bset); elt; elt = elt->next)
- {
- fprintf (stderr, "Elt %lu\n", (unsigned long int) elt->index);
- for (i = 0; i < LBITSET_ELT_WORDS; i++)
- {
- unsigned int j;
- bitset_word word;
-
- word = elt->words[i];
-
- fprintf (stderr, " Word %u:", i);
- for (j = 0; j < LBITSET_WORD_BITS; j++)
- if ((word & ((bitset_word) 1 << j)))
- fprintf (stderr, " %u", j);
- fprintf (stderr, "\n");
- }
- }
-}
+/* Functions to support link list bitsets.
+
+ Copyright (C) 2002-2004, 2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "lbitset.h"
+
+#include "obstack.h"
+#include <stddef.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* This file implements linked-list bitsets. These bitsets can be of
+ arbitrary length and are more efficient than arrays of bits for
+ large sparse sets.
+
+ Usually if all the bits in an element are zero we remove the element
+ from the list. However, a side effect of the bit caching is that we
+ do not always notice when an element becomes zero. Hence the
+ lbitset_weed function which removes zero elements. */
+
+
+/* Number of words to use for each element. The larger the value the
+ greater the size of the cache and the shorter the time to find a given bit
+ but the more memory wasted for sparse bitsets and the longer the time
+ to search for set bits.
+
+ The routines that dominate timing profiles are lbitset_elt_find
+ and lbitset_elt_link, especially when accessing the bits randomly. */
+
+#define LBITSET_ELT_WORDS 2
+
+typedef bitset_word lbitset_word;
+
+#define LBITSET_WORD_BITS BITSET_WORD_BITS
+
+/* Number of bits stored in each element. */
+#define LBITSET_ELT_BITS \
+ ((unsigned int) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS))
+
+/* Lbitset element. We use an array of bits for each element.
+ These are linked together in a doubly-linked list. */
+typedef struct lbitset_elt_struct
+{
+ struct lbitset_elt_struct *next; /* Next element. */
+ struct lbitset_elt_struct *prev; /* Previous element. */
+ bitset_windex index; /* bitno / BITSET_WORD_BITS. */
+ bitset_word words[LBITSET_ELT_WORDS]; /* Bits that are set. */
+}
+lbitset_elt;
+
+
+enum lbitset_find_mode
+ { LBITSET_FIND, LBITSET_CREATE, LBITSET_SUBST };
+
+static lbitset_elt lbitset_zero_elts[3]; /* Elements of all zero bits. */
+
+/* Obstack to allocate bitset elements from. */
+static struct obstack lbitset_obstack;
+static bool lbitset_obstack_init = false;
+static lbitset_elt *lbitset_free_list; /* Free list of bitset elements. */
+
+extern void debug_lbitset (bitset);
+
+#define LBITSET_CURRENT1(X) \
+ ((lbitset_elt *) (void *) ((char *) (X) - offsetof (lbitset_elt, words)))
+
+#define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
+
+#define LBITSET_HEAD(X) ((X)->l.head)
+#define LBITSET_TAIL(X) ((X)->l.tail)
+
+/* Allocate a lbitset element. The bits are not cleared. */
+static inline lbitset_elt *
+lbitset_elt_alloc (void)
+{
+ lbitset_elt *elt;
+
+ if (lbitset_free_list != 0)
+ {
+ elt = lbitset_free_list;
+ lbitset_free_list = elt->next;
+ }
+ else
+ {
+ if (!lbitset_obstack_init)
+ {
+ lbitset_obstack_init = true;
+
+ /* Let particular systems override the size of a chunk. */
+
+#ifndef OBSTACK_CHUNK_SIZE
+#define OBSTACK_CHUNK_SIZE 0
+#endif
+
+ /* Let them override the alloc and free routines too. */
+
+#ifndef OBSTACK_CHUNK_ALLOC
+#define OBSTACK_CHUNK_ALLOC xmalloc
+#endif
+
+#ifndef OBSTACK_CHUNK_FREE
+#define OBSTACK_CHUNK_FREE free
+#endif
+
+#if ! defined __GNUC__ || __GNUC__ < 2
+#define __alignof__(type) 0
+#endif
+
+ obstack_specify_allocation (&lbitset_obstack, OBSTACK_CHUNK_SIZE,
+ __alignof__ (lbitset_elt),
+ OBSTACK_CHUNK_ALLOC,
+ OBSTACK_CHUNK_FREE);
+ }
+
+ /* Perhaps we should add a number of new elements to the free
+ list. */
+ elt = (lbitset_elt *) obstack_alloc (&lbitset_obstack,
+ sizeof (lbitset_elt));
+ }
+
+ return elt;
+}
+
+
+/* Allocate a lbitset element. The bits are cleared. */
+static inline lbitset_elt *
+lbitset_elt_calloc (void)
+{
+ lbitset_elt *elt;
+
+ elt = lbitset_elt_alloc ();
+ memset (elt->words, 0, sizeof (elt->words));
+ return elt;
+}
+
+
+static inline void
+lbitset_elt_free (lbitset_elt *elt)
+{
+ elt->next = lbitset_free_list;
+ lbitset_free_list = elt;
+}
+
+
+/* Unlink element ELT from bitset BSET. */
+static inline void
+lbitset_elt_unlink (bitset bset, lbitset_elt *elt)
+{
+ lbitset_elt *next = elt->next;
+ lbitset_elt *prev = elt->prev;
+
+ if (prev)
+ prev->next = next;
+
+ if (next)
+ next->prev = prev;
+
+ if (LBITSET_HEAD (bset) == elt)
+ LBITSET_HEAD (bset) = next;
+ if (LBITSET_TAIL (bset) == elt)
+ LBITSET_TAIL (bset) = prev;
+
+ /* Update cache pointer. Since the first thing we try is to insert
+ before current, make current the next entry in preference to the
+ previous. */
+ if (LBITSET_CURRENT (bset) == elt)
+ {
+ if (next)
+ {
+ bset->b.cdata = next->words;
+ bset->b.cindex = next->index;
+ }
+ else if (prev)
+ {
+ bset->b.cdata = prev->words;
+ bset->b.cindex = prev->index;
+ }
+ else
+ {
+ bset->b.csize = 0;
+ bset->b.cdata = 0;
+ }
+ }
+
+ lbitset_elt_free (elt);
+}
+
+
+/* Cut the chain of bitset BSET before element ELT and free the
+ elements. */
+static inline void
+lbitset_prune (bitset bset, lbitset_elt *elt)
+{
+ lbitset_elt *next;
+
+ if (!elt)
+ return;
+
+ if (elt->prev)
+ {
+ LBITSET_TAIL (bset) = elt->prev;
+ bset->b.cdata = elt->prev->words;
+ bset->b.cindex = elt->prev->index;
+ elt->prev->next = 0;
+ }
+ else
+ {
+ LBITSET_HEAD (bset) = 0;
+ LBITSET_TAIL (bset) = 0;
+ bset->b.cdata = 0;
+ bset->b.csize = 0;
+ }
+
+ for (; elt; elt = next)
+ {
+ next = elt->next;
+ lbitset_elt_free (elt);
+ }
+}
+
+
+/* Are all bits in an element zero? */
+static inline bool
+lbitset_elt_zero_p (lbitset_elt *elt)
+{
+ int i;
+
+ for (i = 0; i < LBITSET_ELT_WORDS; i++)
+ if (elt->words[i])
+ return false;
+
+ return true;
+}
+
+
+/* Link the bitset element into the current bitset linked list. */
+static inline void
+lbitset_elt_link (bitset bset, lbitset_elt *elt)
+{
+ bitset_windex windex = elt->index;
+ lbitset_elt *ptr;
+ lbitset_elt *current;
+
+ if (bset->b.csize)
+ current = LBITSET_CURRENT (bset);
+ else
+ current = LBITSET_HEAD (bset);
+
+ /* If this is the first and only element, add it in. */
+ if (LBITSET_HEAD (bset) == 0)
+ {
+ elt->next = elt->prev = 0;
+ LBITSET_HEAD (bset) = elt;
+ LBITSET_TAIL (bset) = elt;
+ }
+
+ /* If this index is less than that of the current element, it goes
+ somewhere before the current element. */
+ else if (windex < bset->b.cindex)
+ {
+ for (ptr = current;
+ ptr->prev && ptr->prev->index > windex; ptr = ptr->prev)
+ continue;
+
+ if (ptr->prev)
+ ptr->prev->next = elt;
+ else
+ LBITSET_HEAD (bset) = elt;
+
+ elt->prev = ptr->prev;
+ elt->next = ptr;
+ ptr->prev = elt;
+ }
+
+ /* Otherwise, it must go somewhere after the current element. */
+ else
+ {
+ for (ptr = current;
+ ptr->next && ptr->next->index < windex; ptr = ptr->next)
+ continue;
+
+ if (ptr->next)
+ ptr->next->prev = elt;
+ else
+ LBITSET_TAIL (bset) = elt;
+
+ elt->next = ptr->next;
+ elt->prev = ptr;
+ ptr->next = elt;
+ }
+
+ /* Set up so this is the first element searched. */
+ bset->b.cindex = windex;
+ bset->b.csize = LBITSET_ELT_WORDS;
+ bset->b.cdata = elt->words;
+}
+
+
+static lbitset_elt *
+lbitset_elt_find (bitset bset, bitset_windex windex,
+ enum lbitset_find_mode mode)
+{
+ lbitset_elt *elt;
+ lbitset_elt *current;
+
+ if (bset->b.csize)
+ {
+ current = LBITSET_CURRENT (bset);
+ /* Check if element is the cached element. */
+ if ((windex - bset->b.cindex) < bset->b.csize)
+ return current;
+ }
+ else
+ {
+ current = LBITSET_HEAD (bset);
+ }
+
+ if (current)
+ {
+ if (windex < bset->b.cindex)
+ {
+ for (elt = current;
+ elt->prev && elt->index > windex; elt = elt->prev)
+ continue;
+ }
+ else
+ {
+ for (elt = current;
+ elt->next && (elt->index + LBITSET_ELT_WORDS - 1) < windex;
+ elt = elt->next)
+ continue;
+ }
+
+ /* ELT is the nearest to the one we want. If it's not the one
+ we want, the one we want does not exist. */
+ if (windex - elt->index < LBITSET_ELT_WORDS)
+ {
+ bset->b.cindex = elt->index;
+ bset->b.csize = LBITSET_ELT_WORDS;
+ bset->b.cdata = elt->words;
+ return elt;
+ }
+ }
+
+ switch (mode)
+ {
+ default:
+ abort ();
+
+ case LBITSET_FIND:
+ return 0;
+
+ case LBITSET_CREATE:
+ windex -= windex % LBITSET_ELT_WORDS;
+
+ elt = lbitset_elt_calloc ();
+ elt->index = windex;
+ lbitset_elt_link (bset, elt);
+ return elt;
+
+ case LBITSET_SUBST:
+ return &lbitset_zero_elts[0];
+ }
+}
+
+
+/* Weed out the zero elements from the list. */
+static inline void
+lbitset_weed (bitset bset)
+{
+ lbitset_elt *elt;
+ lbitset_elt *next;
+
+ for (elt = LBITSET_HEAD (bset); elt; elt = next)
+ {
+ next = elt->next;
+ if (lbitset_elt_zero_p (elt))
+ lbitset_elt_unlink (bset, elt);
+ }
+}
+
+
+/* Set all bits in the bitset to zero. */
+static void
+lbitset_zero (bitset bset)
+{
+ lbitset_elt *head;
+
+ head = LBITSET_HEAD (bset);
+ if (!head)
+ return;
+
+ /* Clear a bitset by freeing the linked list at the head element. */
+ lbitset_prune (bset, head);
+}
+
+
+/* Is DST == SRC? */
+static inline bool
+lbitset_equal_p (bitset dst, bitset src)
+{
+ lbitset_elt *selt;
+ lbitset_elt *delt;
+ int j;
+
+ if (src == dst)
+ return true;
+
+ lbitset_weed (src);
+ lbitset_weed (dst);
+ for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst);
+ selt && delt; selt = selt->next, delt = delt->next)
+ {
+ if (selt->index != delt->index)
+ return false;
+
+ for (j = 0; j < LBITSET_ELT_WORDS; j++)
+ if (delt->words[j] != selt->words[j])
+ return false;
+ }
+ return !selt && !delt;
+}
+
+
+/* Copy bits from bitset SRC to bitset DST. */
+static inline void
+lbitset_copy (bitset dst, bitset src)
+{
+ lbitset_elt *elt;
+ lbitset_elt *head;
+ lbitset_elt *prev;
+ lbitset_elt *tmp;
+
+ if (src == dst)
+ return;
+
+ lbitset_zero (dst);
+
+ head = LBITSET_HEAD (src);
+ if (!head)
+ return;
+
+ prev = 0;
+ for (elt = head; elt; elt = elt->next)
+ {
+ tmp = lbitset_elt_alloc ();
+ tmp->index = elt->index;
+ tmp->prev = prev;
+ tmp->next = 0;
+ if (prev)
+ prev->next = tmp;
+ else
+ LBITSET_HEAD (dst) = tmp;
+ prev = tmp;
+
+ memcpy (tmp->words, elt->words, sizeof (elt->words));
+ }
+ LBITSET_TAIL (dst) = tmp;
+
+ dst->b.csize = LBITSET_ELT_WORDS;
+ dst->b.cdata = LBITSET_HEAD (dst)->words;
+ dst->b.cindex = LBITSET_HEAD (dst)->index;
+}
+
+
+/* Copy bits from bitset SRC to bitset DST. Return true if
+ bitsets different. */
+static inline bool
+lbitset_copy_cmp (bitset dst, bitset src)
+{
+ if (src == dst)
+ return false;
+
+ if (!LBITSET_HEAD (dst))
+ {
+ lbitset_copy (dst, src);
+ return LBITSET_HEAD (src) != 0;
+ }
+
+ if (lbitset_equal_p (dst, src))
+ return false;
+
+ lbitset_copy (dst, src);
+ return true;
+}
+
+
+static bitset_bindex
+lbitset_resize (bitset src, bitset_bindex size)
+{
+ BITSET_NBITS_ (src) = size;
+
+ /* Need to prune any excess bits. FIXME. */
+ return size;
+}
+
+/* Set bit BITNO in bitset DST. */
+static void
+lbitset_set (bitset dst, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+
+ lbitset_elt_find (dst, windex, LBITSET_CREATE);
+
+ dst->b.cdata[windex - dst->b.cindex] |=
+ (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
+}
+
+
+/* Reset bit BITNO in bitset DST. */
+static void
+lbitset_reset (bitset dst, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+
+ if (!lbitset_elt_find (dst, windex, LBITSET_FIND))
+ return;
+
+ dst->b.cdata[windex - dst->b.cindex] &=
+ ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
+
+ /* If all the data is zero, perhaps we should unlink it now... */
+}
+
+
+/* Test bit BITNO in bitset SRC. */
+static bool
+lbitset_test (bitset src, bitset_bindex bitno)
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+
+ return (lbitset_elt_find (src, windex, LBITSET_FIND)
+ && ((src->b.cdata[windex - src->b.cindex]
+ >> (bitno % BITSET_WORD_BITS))
+ & 1));
+}
+
+
+static void
+lbitset_free (bitset bset)
+{
+ lbitset_zero (bset);
+}
+
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT and store in array LIST. Return with actual number of bits
+ found and with *NEXT indicating where search stopped. */
+static bitset_bindex
+lbitset_list_reverse (bitset bset, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex rbitno;
+ bitset_bindex bitno;
+ unsigned int bcount;
+ bitset_bindex boffset;
+ bitset_windex windex;
+ bitset_bindex count;
+ lbitset_elt *elt;
+ bitset_word word;
+ bitset_bindex n_bits;
+
+ elt = LBITSET_TAIL (bset);
+ if (!elt)
+ return 0;
+
+ n_bits = (elt->index + LBITSET_ELT_WORDS) * BITSET_WORD_BITS;
+ rbitno = *next;
+
+ if (rbitno >= n_bits)
+ return 0;
+
+ bitno = n_bits - (rbitno + 1);
+
+ windex = bitno / BITSET_WORD_BITS;
+
+ /* Skip back to starting element. */
+ for (; elt && elt->index > windex; elt = elt->prev)
+ continue;
+
+ if (!elt)
+ return 0;
+
+ if (windex >= elt->index + LBITSET_ELT_WORDS)
+ {
+ /* We are trying to start in no-mans land so start
+ at end of current elt. */
+ bcount = BITSET_WORD_BITS - 1;
+ windex = elt->index + LBITSET_ELT_WORDS - 1;
+ }
+ else
+ {
+ bcount = bitno % BITSET_WORD_BITS;
+ }
+
+ count = 0;
+ boffset = windex * BITSET_WORD_BITS;
+
+ /* If num is 1, we could speed things up with a binary search
+ of the word of interest. */
+
+ while (elt)
+ {
+ bitset_word *srcp = elt->words;
+
+ for (; (windex - elt->index) < LBITSET_ELT_WORDS;
+ windex--, boffset -= BITSET_WORD_BITS,
+ bcount = BITSET_WORD_BITS - 1)
+ {
+ word =
+ srcp[windex - elt->index] << (BITSET_WORD_BITS - 1 - bcount);
+
+ for (; word; bcount--)
+ {
+ if (word & BITSET_MSB)
+ {
+ list[count++] = boffset + bcount;
+ if (count >= num)
+ {
+ *next = n_bits - (boffset + bcount);
+ return count;
+ }
+ }
+ word <<= 1;
+ }
+ }
+
+ elt = elt->prev;
+ if (elt)
+ {
+ windex = elt->index + LBITSET_ELT_WORDS - 1;
+ boffset = windex * BITSET_WORD_BITS;
+ }
+ }
+
+ *next = n_bits - (boffset + 1);
+ return count;
+}
+
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT and store in array LIST. Return with actual number of bits
+ found and with *NEXT indicating where search stopped. */
+static bitset_bindex
+lbitset_list (bitset bset, bitset_bindex *list,
+ bitset_bindex num, bitset_bindex *next)
+{
+ bitset_bindex bitno;
+ bitset_windex windex;
+ bitset_bindex count;
+ lbitset_elt *elt;
+ lbitset_elt *head;
+ bitset_word word;
+
+ head = LBITSET_HEAD (bset);
+ if (!head)
+ return 0;
+
+ bitno = *next;
+ count = 0;
+
+ if (!bitno)
+ {
+ /* This is the most common case. */
+
+ /* Start with the first element. */
+ elt = head;
+ windex = elt->index;
+ bitno = windex * BITSET_WORD_BITS;
+ }
+ else
+ {
+ windex = bitno / BITSET_WORD_BITS;
+
+ /* Skip to starting element. */
+ for (elt = head;
+ elt && (elt->index + LBITSET_ELT_WORDS - 1) < windex;
+ elt = elt->next)
+ continue;
+
+ if (!elt)
+ return 0;
+
+ if (windex < elt->index)
+ {
+ windex = elt->index;
+ bitno = windex * BITSET_WORD_BITS;
+ }
+ else
+ {
+ bitset_word *srcp = elt->words;
+
+ /* We are starting within an element. */
+
+ for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++)
+ {
+ word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS);
+
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ bitno = (windex + 1) * BITSET_WORD_BITS;
+ }
+
+ elt = elt->next;
+ if (elt)
+ {
+ windex = elt->index;
+ bitno = windex * BITSET_WORD_BITS;
+ }
+ }
+ }
+
+
+ /* If num is 1, we could speed things up with a binary search
+ of the word of interest. */
+
+ while (elt)
+ {
+ int i;
+ bitset_word *srcp = elt->words;
+
+ if ((count + LBITSET_ELT_BITS) < num)
+ {
+ /* The coast is clear, plant boot! */
+
+#if LBITSET_ELT_WORDS == 2
+ word = srcp[0];
+ if (word)
+ {
+ if (!(word & 0xffff))
+ {
+ word >>= 16;
+ bitno += 16;
+ }
+ if (!(word & 0xff))
+ {
+ word >>= 8;
+ bitno += 8;
+ }
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ windex++;
+ bitno = windex * BITSET_WORD_BITS;
+
+ word = srcp[1];
+ if (word)
+ {
+ if (!(word & 0xffff))
+ {
+ word >>= 16;
+ bitno += 16;
+ }
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ windex++;
+ bitno = windex * BITSET_WORD_BITS;
+#else
+ for (i = 0; i < LBITSET_ELT_WORDS; i++)
+ {
+ word = srcp[i];
+ if (word)
+ {
+ if (!(word & 0xffff))
+ {
+ word >>= 16;
+ bitno += 16;
+ }
+ if (!(word & 0xff))
+ {
+ word >>= 8;
+ bitno += 8;
+ }
+ for (; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ windex++;
+ bitno = windex * BITSET_WORD_BITS;
+ }
+#endif
+ }
+ else
+ {
+ /* Tread more carefully since we need to check
+ if array overflows. */
+
+ for (i = 0; i < LBITSET_ELT_WORDS; i++)
+ {
+ for (word = srcp[i]; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ windex++;
+ bitno = windex * BITSET_WORD_BITS;
+ }
+ }
+
+ elt = elt->next;
+ if (elt)
+ {
+ windex = elt->index;
+ bitno = windex * BITSET_WORD_BITS;
+ }
+ }
+
+ *next = bitno;
+ return count;
+}
+
+
+static bool
+lbitset_empty_p (bitset dst)
+{
+ lbitset_elt *elt;
+ lbitset_elt *next;
+
+ for (elt = LBITSET_HEAD (dst); elt; elt = next)
+ {
+ next = elt->next;
+ if (!lbitset_elt_zero_p (elt))
+ return 0;
+ /* Weed as we go. */
+ lbitset_elt_unlink (dst, elt);
+ }
+
+ return 1;
+}
+
+
+/* Ensure that any unused bits within the last element are clear. */
+static inline void
+lbitset_unused_clear (bitset dst)
+{
+ unsigned int last_bit;
+ bitset_bindex n_bits;
+
+ n_bits = BITSET_SIZE_ (dst);
+ last_bit = n_bits % LBITSET_ELT_BITS;
+
+ if (last_bit)
+ {
+ lbitset_elt *elt;
+ bitset_windex windex;
+ bitset_word *srcp;
+
+ elt = LBITSET_TAIL (dst);
+ srcp = elt->words;
+ windex = n_bits / BITSET_WORD_BITS;
+
+ srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1;
+ windex++;
+
+ for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++)
+ srcp[windex - elt->index] = 0;
+ }
+}
+
+
+static void
+lbitset_ones (bitset dst)
+{
+ bitset_windex i;
+ bitset_windex windex;
+ lbitset_elt *elt;
+
+ /* This is a decidedly unfriendly operation for a linked list
+ bitset! It makes a sparse bitset become dense. An alternative
+ is to have a flag that indicates that the bitset stores the
+ complement of what it indicates. */
+
+ windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS;
+
+ for (i = 0; i < windex; i += LBITSET_ELT_WORDS)
+ {
+ /* Create new elements if they cannot be found. */
+ elt = lbitset_elt_find (dst, i, LBITSET_CREATE);
+ memset (elt->words, -1, sizeof (elt->words));
+ }
+
+ lbitset_unused_clear (dst);
+}
+
+
+static void
+lbitset_not (bitset dst, bitset src)
+{
+ lbitset_elt *selt;
+ lbitset_elt *delt;
+ bitset_windex i;
+ unsigned int j;
+ bitset_windex windex;
+
+ windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS;
+
+ for (i = 0; i < windex; i += LBITSET_ELT_WORDS)
+ {
+ /* Create new elements for dst if they cannot be found
+ or substitute zero elements if src elements not found. */
+ selt = lbitset_elt_find (src, i, LBITSET_SUBST);
+ delt = lbitset_elt_find (dst, i, LBITSET_CREATE);
+
+ for (j = 0; j < LBITSET_ELT_WORDS; j++)
+ delt->words[j] = ~selt->words[j];
+ }
+ lbitset_unused_clear (dst);
+ lbitset_weed (dst);
+ return;
+}
+
+
+/* Is DST == DST | SRC? */
+static bool
+lbitset_subset_p (bitset dst, bitset src)
+{
+ lbitset_elt *selt;
+ lbitset_elt *delt;
+ unsigned int j;
+
+ for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst);
+ selt || delt; selt = selt->next, delt = delt->next)
+ {
+ if (!selt)
+ selt = &lbitset_zero_elts[0];
+ else if (!delt)
+ delt = &lbitset_zero_elts[0];
+ else if (selt->index != delt->index)
+ {
+ if (selt->index < delt->index)
+ {
+ lbitset_zero_elts[2].next = delt;
+ delt = &lbitset_zero_elts[2];
+ }
+ else
+ {
+ lbitset_zero_elts[1].next = selt;
+ selt = &lbitset_zero_elts[1];
+ }
+ }
+
+ for (j = 0; j < LBITSET_ELT_WORDS; j++)
+ if (delt->words[j] != (selt->words[j] | delt->words[j]))
+ return false;
+ }
+ return true;
+}
+
+
+/* Is DST & SRC == 0? */
+static bool
+lbitset_disjoint_p (bitset dst, bitset src)
+{
+ lbitset_elt *selt;
+ lbitset_elt *delt;
+ unsigned int j;
+
+ for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst);
+ selt && delt; selt = selt->next, delt = delt->next)
+ {
+ if (selt->index != delt->index)
+ {
+ if (selt->index < delt->index)
+ {
+ lbitset_zero_elts[2].next = delt;
+ delt = &lbitset_zero_elts[2];
+ }
+ else
+ {
+ lbitset_zero_elts[1].next = selt;
+ selt = &lbitset_zero_elts[1];
+ }
+ /* Since the elements are different, there is no
+ intersection of these elements. */
+ continue;
+ }
+
+ for (j = 0; j < LBITSET_ELT_WORDS; j++)
+ if (selt->words[j] & delt->words[j])
+ return false;
+ }
+ return true;
+}
+
+
+static bool
+lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
+{
+ lbitset_elt *selt1 = LBITSET_HEAD (src1);
+ lbitset_elt *selt2 = LBITSET_HEAD (src2);
+ lbitset_elt *delt = LBITSET_HEAD (dst);
+ bitset_windex windex1;
+ bitset_windex windex2;
+ bitset_windex windex;
+ lbitset_elt *stmp1;
+ lbitset_elt *stmp2;
+ lbitset_elt *dtmp;
+ bitset_word *srcp1;
+ bitset_word *srcp2;
+ bitset_word *dstp;
+ bool changed = false;
+ unsigned int i;
+
+ LBITSET_HEAD (dst) = 0;
+ dst->b.csize = 0;
+
+ windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX;
+ windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX;
+
+ while (selt1 || selt2)
+ {
+ /* Figure out whether we need to substitute zero elements for
+ missing links. */
+ if (windex1 == windex2)
+ {
+ windex = windex1;
+ stmp1 = selt1;
+ stmp2 = selt2;
+ selt1 = selt1->next;
+ windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX;
+ selt2 = selt2->next;
+ windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX;
+ }
+ else if (windex1 < windex2)
+ {
+ windex = windex1;
+ stmp1 = selt1;
+ stmp2 = &lbitset_zero_elts[0];
+ selt1 = selt1->next;
+ windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX;
+ }
+ else
+ {
+ windex = windex2;
+ stmp1 = &lbitset_zero_elts[0];
+ stmp2 = selt2;
+ selt2 = selt2->next;
+ windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX;
+ }
+
+ /* Find the appropriate element from DST. Begin by discarding
+ elements that we've skipped. */
+ while (delt && delt->index < windex)
+ {
+ changed = true;
+ dtmp = delt;
+ delt = delt->next;
+ lbitset_elt_free (dtmp);
+ }
+ if (delt && delt->index == windex)
+ {
+ dtmp = delt;
+ delt = delt->next;
+ }
+ else
+ dtmp = lbitset_elt_calloc ();
+
+ /* Do the operation, and if any bits are set, link it into the
+ linked list. */
+ srcp1 = stmp1->words;
+ srcp2 = stmp2->words;
+ dstp = dtmp->words;
+ switch (op)
+ {
+ default:
+ abort ();
+
+ case BITSET_OP_OR:
+ for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ | *srcp2++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+
+ case BITSET_OP_AND:
+ for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ & *srcp2++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+
+ case BITSET_OP_XOR:
+ for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ ^ *srcp2++;
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+
+ case BITSET_OP_ANDN:
+ for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++)
+ {
+ bitset_word tmp = *srcp1++ & ~(*srcp2++);
+
+ if (*dstp != tmp)
+ {
+ changed = true;
+ *dstp = tmp;
+ }
+ }
+ break;
+ }
+
+ if (!lbitset_elt_zero_p (dtmp))
+ {
+ dtmp->index = windex;
+ /* Perhaps this could be optimised... */
+ lbitset_elt_link (dst, dtmp);
+ }
+ else
+ {
+ lbitset_elt_free (dtmp);
+ }
+ }
+
+ /* If we have elements of DST left over, free them all. */
+ if (delt)
+ {
+ changed = true;
+ lbitset_prune (dst, delt);
+ }
+
+ return changed;
+}
+
+
+static bool
+lbitset_and_cmp (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_elt *selt1 = LBITSET_HEAD (src1);
+ lbitset_elt *selt2 = LBITSET_HEAD (src2);
+ bool changed;
+
+ if (!selt2)
+ {
+ lbitset_weed (dst);
+ changed = !LBITSET_HEAD (dst);
+ lbitset_zero (dst);
+ return changed;
+ }
+ else if (!selt1)
+ {
+ lbitset_weed (dst);
+ changed = !LBITSET_HEAD (dst);
+ lbitset_zero (dst);
+ return changed;
+ }
+ return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
+}
+
+
+static void
+lbitset_and (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_and_cmp (dst, src1, src2);
+}
+
+
+static bool
+lbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_elt *selt1 = LBITSET_HEAD (src1);
+ lbitset_elt *selt2 = LBITSET_HEAD (src2);
+ bool changed;
+
+ if (!selt2)
+ {
+ return lbitset_copy_cmp (dst, src1);
+ }
+ else if (!selt1)
+ {
+ lbitset_weed (dst);
+ changed = !LBITSET_HEAD (dst);
+ lbitset_zero (dst);
+ return changed;
+ }
+ return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
+}
+
+
+static void
+lbitset_andn (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_andn_cmp (dst, src1, src2);
+}
+
+
+static bool
+lbitset_or_cmp (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_elt *selt1 = LBITSET_HEAD (src1);
+ lbitset_elt *selt2 = LBITSET_HEAD (src2);
+
+ if (!selt2)
+ {
+ return lbitset_copy_cmp (dst, src1);
+ }
+ else if (!selt1)
+ {
+ return lbitset_copy_cmp (dst, src2);
+ }
+ return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
+}
+
+
+static void
+lbitset_or (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_or_cmp (dst, src1, src2);
+}
+
+
+static bool
+lbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_elt *selt1 = LBITSET_HEAD (src1);
+ lbitset_elt *selt2 = LBITSET_HEAD (src2);
+
+ if (!selt2)
+ {
+ return lbitset_copy_cmp (dst, src1);
+ }
+ else if (!selt1)
+ {
+ return lbitset_copy_cmp (dst, src2);
+ }
+ return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
+}
+
+
+static void
+lbitset_xor (bitset dst, bitset src1, bitset src2)
+{
+ lbitset_xor_cmp (dst, src1, src2);
+}
+
+
+
+/* Vector of operations for linked-list bitsets. */
+struct bitset_vtable lbitset_vtable = {
+ lbitset_set,
+ lbitset_reset,
+ bitset_toggle_,
+ lbitset_test,
+ lbitset_resize,
+ bitset_size_,
+ bitset_count_,
+ lbitset_empty_p,
+ lbitset_ones,
+ lbitset_zero,
+ lbitset_copy,
+ lbitset_disjoint_p,
+ lbitset_equal_p,
+ lbitset_not,
+ lbitset_subset_p,
+ lbitset_and,
+ lbitset_and_cmp,
+ lbitset_andn,
+ lbitset_andn_cmp,
+ lbitset_or,
+ lbitset_or_cmp,
+ lbitset_xor,
+ lbitset_xor_cmp,
+ bitset_and_or_,
+ bitset_and_or_cmp_,
+ bitset_andn_or_,
+ bitset_andn_or_cmp_,
+ bitset_or_and_,
+ bitset_or_and_cmp_,
+ lbitset_list,
+ lbitset_list_reverse,
+ lbitset_free,
+ BITSET_LIST
+};
+
+
+/* Return size of initial structure. */
+size_t
+lbitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED)
+{
+ return sizeof (struct lbitset_struct);
+}
+
+
+/* Initialize a bitset. */
+bitset
+lbitset_init (bitset bset, bitset_bindex n_bits ATTRIBUTE_UNUSED)
+{
+ BITSET_NBITS_ (bset) = n_bits;
+ bset->b.vtable = &lbitset_vtable;
+ return bset;
+}
+
+
+void
+lbitset_release_memory (void)
+{
+ lbitset_free_list = 0;
+ if (lbitset_obstack_init)
+ {
+ lbitset_obstack_init = false;
+ obstack_free (&lbitset_obstack, NULL);
+ }
+}
+
+
+/* Function to be called from debugger to debug lbitset. */
+void
+debug_lbitset (bitset bset)
+{
+ lbitset_elt *elt;
+ unsigned int i;
+
+ if (!bset)
+ return;
+
+ for (elt = LBITSET_HEAD (bset); elt; elt = elt->next)
+ {
+ fprintf (stderr, "Elt %lu\n", (unsigned long int) elt->index);
+ for (i = 0; i < LBITSET_ELT_WORDS; i++)
+ {
+ unsigned int j;
+ bitset_word word;
+
+ word = elt->words[i];
+
+ fprintf (stderr, " Word %u:", i);
+ for (j = 0; j < LBITSET_WORD_BITS; j++)
+ if ((word & ((bitset_word) 1 << j)))
+ fprintf (stderr, " %u", j);
+ fprintf (stderr, "\n");
+ }
+ }
+}
diff --git a/contrib/tools/bison/gnulib/src/lbitset.h b/contrib/tools/bison/gnulib/src/lbitset.h
index 8ccaca74da..fd50fd7c7a 100644
--- a/contrib/tools/bison/gnulib/src/lbitset.h
+++ b/contrib/tools/bison/gnulib/src/lbitset.h
@@ -1,31 +1,31 @@
-/* Functions to support lbitsets.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LBITSET_H
-#define _LBITSET_H
-
-#include "bitset.h"
-
-extern size_t lbitset_bytes (bitset_bindex);
-
-extern bitset lbitset_init (bitset, bitset_bindex);
-
-extern void lbitset_release_memory (void);
-
-#endif
+/* Functions to support lbitsets.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LBITSET_H
+#define _LBITSET_H
+
+#include "bitset.h"
+
+extern size_t lbitset_bytes (bitset_bindex);
+
+extern bitset lbitset_init (bitset, bitset_bindex);
+
+extern void lbitset_release_memory (void);
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/ldexpl.c b/contrib/tools/bison/gnulib/src/ldexpl.c
index f560053dca..d7e4a50d9d 100644
--- a/contrib/tools/bison/gnulib/src/ldexpl.c
+++ b/contrib/tools/bison/gnulib/src/ldexpl.c
@@ -1,89 +1,89 @@
-/* Emulation for ldexpl.
- Contributed by Paolo Bonzini
-
- Copyright 2002-2003, 2007-2013 Free Software Foundation, Inc.
-
- This file is part of gnulib.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <math.h>
-
-#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
-
-long double
-ldexpl (long double x, int exp)
-{
- return ldexp (x, exp);
-}
-
-#else
-
-# include <float.h>
-# include "fpucw.h"
-
-long double
-ldexpl (long double x, int exp)
-{
- long double factor;
- int bit;
- DECL_LONG_DOUBLE_ROUNDING
-
- BEGIN_LONG_DOUBLE_ROUNDING ();
-
- /* Check for zero, nan and infinity. */
- if (!(isnanl (x) || x + x == x))
- {
- if (exp < 0)
- {
- exp = -exp;
- factor = 0.5L;
- }
- else
- factor = 2.0L;
-
- if (exp > 0)
- for (bit = 1;;)
- {
- /* Invariant: Here bit = 2^i, factor = 2^-2^i or = 2^2^i,
- and bit <= exp. */
- if (exp & bit)
- x *= factor;
- bit <<= 1;
- if (bit > exp)
- break;
- factor = factor * factor;
- }
- }
-
- END_LONG_DOUBLE_ROUNDING ();
-
- return x;
-}
-
-#endif
-
-#if 0
-int
-main (void)
-{
- long double x;
- int y;
- for (y = 0; y < 29; y++)
- printf ("%5d %.16Lg %.16Lg\n", y, ldexpl (0.8L, y), ldexpl (0.8L, -y) * ldexpl (0.8L, y));
-}
-#endif
+/* Emulation for ldexpl.
+ Contributed by Paolo Bonzini
+
+ Copyright 2002-2003, 2007-2013 Free Software Foundation, Inc.
+
+ This file is part of gnulib.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <math.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+long double
+ldexpl (long double x, int exp)
+{
+ return ldexp (x, exp);
+}
+
+#else
+
+# include <float.h>
+# include "fpucw.h"
+
+long double
+ldexpl (long double x, int exp)
+{
+ long double factor;
+ int bit;
+ DECL_LONG_DOUBLE_ROUNDING
+
+ BEGIN_LONG_DOUBLE_ROUNDING ();
+
+ /* Check for zero, nan and infinity. */
+ if (!(isnanl (x) || x + x == x))
+ {
+ if (exp < 0)
+ {
+ exp = -exp;
+ factor = 0.5L;
+ }
+ else
+ factor = 2.0L;
+
+ if (exp > 0)
+ for (bit = 1;;)
+ {
+ /* Invariant: Here bit = 2^i, factor = 2^-2^i or = 2^2^i,
+ and bit <= exp. */
+ if (exp & bit)
+ x *= factor;
+ bit <<= 1;
+ if (bit > exp)
+ break;
+ factor = factor * factor;
+ }
+ }
+
+ END_LONG_DOUBLE_ROUNDING ();
+
+ return x;
+}
+
+#endif
+
+#if 0
+int
+main (void)
+{
+ long double x;
+ int y;
+ for (y = 0; y < 29; y++)
+ printf ("%5d %.16Lg %.16Lg\n", y, ldexpl (0.8L, y), ldexpl (0.8L, -y) * ldexpl (0.8L, y));
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/libiberty.h b/contrib/tools/bison/gnulib/src/libiberty.h
index ec1467c59b..5fb0687331 100644
--- a/contrib/tools/bison/gnulib/src/libiberty.h
+++ b/contrib/tools/bison/gnulib/src/libiberty.h
@@ -1,36 +1,36 @@
-/* Fake libiberty.h for Bison.
-
- Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-/* Bison depends on libiberty's implementation of bitsets, which
- requires a 'libiberty.h' file. This file provides the minimum
- services. */
-
-#ifndef BISON_LIBIBERTY_H_
-# define BISON_LIBIBERTY_H_ 1
-
-# ifndef __attribute__
-# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
-# define __attribute__(x)
-# endif
-# endif
-
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-
-# include "xalloc.h"
-
-#endif /* ! BISON_LIBIBERTY_H_ */
+/* Fake libiberty.h for Bison.
+
+ Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+/* Bison depends on libiberty's implementation of bitsets, which
+ requires a 'libiberty.h' file. This file provides the minimum
+ services. */
+
+#ifndef BISON_LIBIBERTY_H_
+# define BISON_LIBIBERTY_H_ 1
+
+# ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
+# define __attribute__(x)
+# endif
+# endif
+
+# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+
+# include "xalloc.h"
+
+#endif /* ! BISON_LIBIBERTY_H_ */
diff --git a/contrib/tools/bison/gnulib/src/localcharset.c b/contrib/tools/bison/gnulib/src/localcharset.c
index a225a2ead8..2f96630b5b 100644
--- a/contrib/tools/bison/gnulib/src/localcharset.c
+++ b/contrib/tools/bison/gnulib/src/localcharset.c
@@ -1,558 +1,558 @@
-/* Determine a canonical name for the current locale's character encoding.
-
- Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "localcharset.h"
-
-#include <fcntl.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
-# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
-#endif
-
-#if defined _WIN32 || defined __WIN32__
-# define WINDOWS_NATIVE
-#endif
-
-#if defined __EMX__
-/* Assume EMX program runs on OS/2, even if compiled under DOS. */
-# ifndef OS2
-# define OS2
-# endif
-#endif
-
-#if !defined WINDOWS_NATIVE
-# include <unistd.h>
-# if HAVE_LANGINFO_CODESET
-# include <langinfo.h>
-# else
-# if 0 /* see comment below */
-# include <locale.h>
-# endif
-# endif
-# ifdef __CYGWIN__
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-# endif
-#elif defined WINDOWS_NATIVE
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-#endif
-#if defined OS2
-# define INCL_DOS
-# include <os2.h>
-#endif
-
-/* For MB_CUR_MAX_L */
-#if defined DARWIN7
-# include <xlocale.h>
-#endif
-
-#if ENABLE_RELOCATABLE
-# include "relocatable.h"
-#else
-# define relocate(pathname) (pathname)
-#endif
-
-/* Get LIBDIR. */
-#ifndef LIBDIR
-# include "configmake.h"
-#endif
-
-/* Define O_NOFOLLOW to 0 on platforms where it does not exist. */
-#ifndef O_NOFOLLOW
-# define O_NOFOLLOW 0
-#endif
-
-#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
- /* Native Windows, Cygwin, OS/2, DOS */
-# define ISSLASH(C) ((C) == '/' || (C) == '\\')
-#endif
-
-#ifndef DIRECTORY_SEPARATOR
-# define DIRECTORY_SEPARATOR '/'
-#endif
-
-#ifndef ISSLASH
-# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
-#endif
-
-#if HAVE_DECL_GETC_UNLOCKED
-# undef getc
-# define getc getc_unlocked
-#endif
-
-/* The following static variable is declared 'volatile' to avoid a
- possible multithread problem in the function get_charset_aliases. If we
- are running in a threaded environment, and if two threads initialize
- 'charset_aliases' simultaneously, both will produce the same value,
- and everything will be ok if the two assignments to 'charset_aliases'
- are atomic. But I don't know what will happen if the two assignments mix. */
-#if __STDC__ != 1
-# define volatile /* empty */
-#endif
-/* Pointer to the contents of the charset.alias file, if it has already been
- read, else NULL. Its format is:
- ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */
-static const char * volatile charset_aliases;
-
-/* Return a pointer to the contents of the charset.alias file. */
-static const char *
-get_charset_aliases (void)
-{
- const char *cp;
-
- cp = charset_aliases;
- if (cp == NULL)
- {
-#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__)
- const char *dir;
- const char *base = "charset.alias";
- char *file_name;
-
- /* Make it possible to override the charset.alias location. This is
- necessary for running the testsuite before "make install". */
- dir = getenv ("CHARSETALIASDIR");
- if (dir == NULL || dir[0] == '\0')
- dir = relocate (LIBDIR);
-
- /* Concatenate dir and base into freshly allocated file_name. */
- {
- size_t dir_len = strlen (dir);
- size_t base_len = strlen (base);
- int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
- file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
- if (file_name != NULL)
- {
- memcpy (file_name, dir, dir_len);
- if (add_slash)
- file_name[dir_len] = DIRECTORY_SEPARATOR;
- memcpy (file_name + dir_len + add_slash, base, base_len + 1);
- }
- }
-
- if (file_name == NULL)
- /* Out of memory. Treat the file as empty. */
- cp = "";
- else
- {
- int fd;
-
- /* Open the file. Reject symbolic links on platforms that support
- O_NOFOLLOW. This is a security feature. Without it, an attacker
- could retrieve parts of the contents (namely, the tail of the
- first line that starts with "* ") of an arbitrary file by placing
- a symbolic link to that file under the name "charset.alias" in
- some writable directory and defining the environment variable
- CHARSETALIASDIR to point to that directory. */
- fd = open (file_name,
- O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0));
- if (fd < 0)
- /* File not found. Treat it as empty. */
- cp = "";
- else
- {
- FILE *fp;
-
- fp = fdopen (fd, "r");
- if (fp == NULL)
- {
- /* Out of memory. Treat the file as empty. */
- close (fd);
- cp = "";
- }
- else
- {
- /* Parse the file's contents. */
- char *res_ptr = NULL;
- size_t res_size = 0;
-
- for (;;)
- {
- int c;
- char buf1[50+1];
- char buf2[50+1];
- size_t l1, l2;
- char *old_res_ptr;
-
- c = getc (fp);
- if (c == EOF)
- break;
- if (c == '\n' || c == ' ' || c == '\t')
- continue;
- if (c == '#')
- {
- /* Skip comment, to end of line. */
- do
- c = getc (fp);
- while (!(c == EOF || c == '\n'));
- if (c == EOF)
- break;
- continue;
- }
- ungetc (c, fp);
- if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
- break;
- l1 = strlen (buf1);
- l2 = strlen (buf2);
- old_res_ptr = res_ptr;
- if (res_size == 0)
- {
- res_size = l1 + 1 + l2 + 1;
- res_ptr = (char *) malloc (res_size + 1);
- }
- else
- {
- res_size += l1 + 1 + l2 + 1;
- res_ptr = (char *) realloc (res_ptr, res_size + 1);
- }
- if (res_ptr == NULL)
- {
- /* Out of memory. */
- res_size = 0;
- free (old_res_ptr);
- break;
- }
- strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
- strcpy (res_ptr + res_size - (l2 + 1), buf2);
- }
- fclose (fp);
- if (res_size == 0)
- cp = "";
- else
- {
- *(res_ptr + res_size) = '\0';
- cp = res_ptr;
- }
- }
- }
-
- free (file_name);
- }
-
-#else
-
-# if defined DARWIN7
- /* To avoid the trouble of installing a file that is shared by many
- GNU packages -- many packaging systems have problems with this --,
- simply inline the aliases here. */
- cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
- "ISO8859-2" "\0" "ISO-8859-2" "\0"
- "ISO8859-4" "\0" "ISO-8859-4" "\0"
- "ISO8859-5" "\0" "ISO-8859-5" "\0"
- "ISO8859-7" "\0" "ISO-8859-7" "\0"
- "ISO8859-9" "\0" "ISO-8859-9" "\0"
- "ISO8859-13" "\0" "ISO-8859-13" "\0"
- "ISO8859-15" "\0" "ISO-8859-15" "\0"
- "KOI8-R" "\0" "KOI8-R" "\0"
- "KOI8-U" "\0" "KOI8-U" "\0"
- "CP866" "\0" "CP866" "\0"
- "CP949" "\0" "CP949" "\0"
- "CP1131" "\0" "CP1131" "\0"
- "CP1251" "\0" "CP1251" "\0"
- "eucCN" "\0" "GB2312" "\0"
- "GB2312" "\0" "GB2312" "\0"
- "eucJP" "\0" "EUC-JP" "\0"
- "eucKR" "\0" "EUC-KR" "\0"
- "Big5" "\0" "BIG5" "\0"
- "Big5HKSCS" "\0" "BIG5-HKSCS" "\0"
- "GBK" "\0" "GBK" "\0"
- "GB18030" "\0" "GB18030" "\0"
- "SJIS" "\0" "SHIFT_JIS" "\0"
- "ARMSCII-8" "\0" "ARMSCII-8" "\0"
- "PT154" "\0" "PT154" "\0"
- /*"ISCII-DEV" "\0" "?" "\0"*/
- "*" "\0" "UTF-8" "\0";
-# endif
-
-# if defined VMS
- /* To avoid the troubles of an extra file charset.alias_vms in the
- sources of many GNU packages, simply inline the aliases here. */
- /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
- "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
- section 10.7 "Handling Different Character Sets". */
- cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
- "ISO8859-2" "\0" "ISO-8859-2" "\0"
- "ISO8859-5" "\0" "ISO-8859-5" "\0"
- "ISO8859-7" "\0" "ISO-8859-7" "\0"
- "ISO8859-8" "\0" "ISO-8859-8" "\0"
- "ISO8859-9" "\0" "ISO-8859-9" "\0"
- /* Japanese */
- "eucJP" "\0" "EUC-JP" "\0"
- "SJIS" "\0" "SHIFT_JIS" "\0"
- "DECKANJI" "\0" "DEC-KANJI" "\0"
- "SDECKANJI" "\0" "EUC-JP" "\0"
- /* Chinese */
- "eucTW" "\0" "EUC-TW" "\0"
- "DECHANYU" "\0" "DEC-HANYU" "\0"
- "DECHANZI" "\0" "GB2312" "\0"
- /* Korean */
- "DECKOREAN" "\0" "EUC-KR" "\0";
-# endif
-
-# if defined WINDOWS_NATIVE || defined __CYGWIN__
- /* To avoid the troubles of installing a separate file in the same
- directory as the DLL and of retrieving the DLL's directory at
- runtime, simply inline the aliases here. */
-
- cp = "CP936" "\0" "GBK" "\0"
- "CP1361" "\0" "JOHAB" "\0"
- "CP20127" "\0" "ASCII" "\0"
- "CP20866" "\0" "KOI8-R" "\0"
- "CP20936" "\0" "GB2312" "\0"
- "CP21866" "\0" "KOI8-RU" "\0"
- "CP28591" "\0" "ISO-8859-1" "\0"
- "CP28592" "\0" "ISO-8859-2" "\0"
- "CP28593" "\0" "ISO-8859-3" "\0"
- "CP28594" "\0" "ISO-8859-4" "\0"
- "CP28595" "\0" "ISO-8859-5" "\0"
- "CP28596" "\0" "ISO-8859-6" "\0"
- "CP28597" "\0" "ISO-8859-7" "\0"
- "CP28598" "\0" "ISO-8859-8" "\0"
- "CP28599" "\0" "ISO-8859-9" "\0"
- "CP28605" "\0" "ISO-8859-15" "\0"
- "CP38598" "\0" "ISO-8859-8" "\0"
- "CP51932" "\0" "EUC-JP" "\0"
- "CP51936" "\0" "GB2312" "\0"
- "CP51949" "\0" "EUC-KR" "\0"
- "CP51950" "\0" "EUC-TW" "\0"
- "CP54936" "\0" "GB18030" "\0"
- "CP65001" "\0" "UTF-8" "\0";
-# endif
-#endif
-
- charset_aliases = cp;
- }
-
- return cp;
-}
-
-/* Determine the current locale's character encoding, and canonicalize it
- into one of the canonical names listed in config.charset.
- The result must not be freed; it is statically allocated.
- If the canonical name cannot be determined, the result is a non-canonical
- name. */
-
-#ifdef STATIC
-STATIC
-#endif
-const char *
-locale_charset (void)
-{
- const char *codeset;
- const char *aliases;
-
-#if !(defined WINDOWS_NATIVE || defined OS2)
-
-# if HAVE_LANGINFO_CODESET
-
- /* Most systems support nl_langinfo (CODESET) nowadays. */
- codeset = nl_langinfo (CODESET);
-
-# ifdef __CYGWIN__
- /* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always
- returns "US-ASCII". Return the suffix of the locale name from the
- environment variables (if present) or the codepage as a number. */
- if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
- {
- const char *locale;
- static char buf[2 + 10 + 1];
-
- locale = getenv ("LC_ALL");
- if (locale == NULL || locale[0] == '\0')
- {
- locale = getenv ("LC_CTYPE");
- if (locale == NULL || locale[0] == '\0')
- locale = getenv ("LANG");
- }
- if (locale != NULL && locale[0] != '\0')
- {
- /* If the locale name contains an encoding after the dot, return
- it. */
- const char *dot = strchr (locale, '.');
-
- if (dot != NULL)
- {
- const char *modifier;
-
- dot++;
- /* Look for the possible @... trailer and remove it, if any. */
- modifier = strchr (dot, '@');
- if (modifier == NULL)
- return dot;
- if (modifier - dot < sizeof (buf))
- {
- memcpy (buf, dot, modifier - dot);
- buf [modifier - dot] = '\0';
- return buf;
- }
- }
- }
-
- /* The Windows API has a function returning the locale's codepage as a
- number: GetACP(). This encoding is used by Cygwin, unless the user
- has set the environment variable CYGWIN=codepage:oem (which very few
- people do).
- Output directed to console windows needs to be converted (to
- GetOEMCP() if the console is using a raster font, or to
- GetConsoleOutputCP() if it is using a TrueType font). Cygwin does
- this conversion transparently (see winsup/cygwin/fhandler_console.cc),
- converting to GetConsoleOutputCP(). This leads to correct results,
- except when SetConsoleOutputCP has been called and a raster font is
- in use. */
- sprintf (buf, "CP%u", GetACP ());
- codeset = buf;
- }
-# endif
-
-# else
-
- /* On old systems which lack it, use setlocale or getenv. */
- const char *locale = NULL;
-
- /* But most old systems don't have a complete set of locales. Some
- (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't
- use setlocale here; it would return "C" when it doesn't support the
- locale name the user has set. */
-# if 0
- locale = setlocale (LC_CTYPE, NULL);
-# endif
- if (locale == NULL || locale[0] == '\0')
- {
- locale = getenv ("LC_ALL");
- if (locale == NULL || locale[0] == '\0')
- {
- locale = getenv ("LC_CTYPE");
- if (locale == NULL || locale[0] == '\0')
- locale = getenv ("LANG");
- }
- }
-
- /* On some old systems, one used to set locale = "iso8859_1". On others,
- you set it to "language_COUNTRY.charset". In any case, we resolve it
- through the charset.alias file. */
- codeset = locale;
-
-# endif
-
-#elif defined WINDOWS_NATIVE
-
- static char buf[2 + 10 + 1];
-
- /* The Windows API has a function returning the locale's codepage as a
- number: GetACP().
- When the output goes to a console window, it needs to be provided in
- GetOEMCP() encoding if the console is using a raster font, or in
- GetConsoleOutputCP() encoding if it is using a TrueType font.
- But in GUI programs and for output sent to files and pipes, GetACP()
- encoding is the best bet. */
- sprintf (buf, "CP%u", GetACP ());
- codeset = buf;
-
-#elif defined OS2
-
- const char *locale;
- static char buf[2 + 10 + 1];
- ULONG cp[3];
- ULONG cplen;
-
- /* Allow user to override the codeset, as set in the operating system,
- with standard language environment variables. */
- locale = getenv ("LC_ALL");
- if (locale == NULL || locale[0] == '\0')
- {
- locale = getenv ("LC_CTYPE");
- if (locale == NULL || locale[0] == '\0')
- locale = getenv ("LANG");
- }
- if (locale != NULL && locale[0] != '\0')
- {
- /* If the locale name contains an encoding after the dot, return it. */
- const char *dot = strchr (locale, '.');
-
- if (dot != NULL)
- {
- const char *modifier;
-
- dot++;
- /* Look for the possible @... trailer and remove it, if any. */
- modifier = strchr (dot, '@');
- if (modifier == NULL)
- return dot;
- if (modifier - dot < sizeof (buf))
- {
- memcpy (buf, dot, modifier - dot);
- buf [modifier - dot] = '\0';
- return buf;
- }
- }
-
- /* Resolve through the charset.alias file. */
- codeset = locale;
- }
- else
- {
- /* OS/2 has a function returning the locale's codepage as a number. */
- if (DosQueryCp (sizeof (cp), cp, &cplen))
- codeset = "";
- else
- {
- sprintf (buf, "CP%u", cp[0]);
- codeset = buf;
- }
- }
-
-#endif
-
- if (codeset == NULL)
- /* The canonical name cannot be determined. */
- codeset = "";
-
- /* Resolve alias. */
- for (aliases = get_charset_aliases ();
- *aliases != '\0';
- aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
- if (strcmp (codeset, aliases) == 0
- || (aliases[0] == '*' && aliases[1] == '\0'))
- {
- codeset = aliases + strlen (aliases) + 1;
- break;
- }
-
- /* Don't return an empty string. GNU libc and GNU libiconv interpret
- the empty string as denoting "the locale's character encoding",
- thus GNU libiconv would call this function a second time. */
- if (codeset[0] == '\0')
- codeset = "ASCII";
-
-#ifdef DARWIN7
- /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8"
- (the default codeset) does not work when MB_CUR_MAX is 1. */
- if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1)
- codeset = "ASCII";
-#endif
-
- return codeset;
-}
+/* Determine a canonical name for the current locale's character encoding.
+
+ Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "localcharset.h"
+
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
+# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
+#endif
+
+#if defined _WIN32 || defined __WIN32__
+# define WINDOWS_NATIVE
+#endif
+
+#if defined __EMX__
+/* Assume EMX program runs on OS/2, even if compiled under DOS. */
+# ifndef OS2
+# define OS2
+# endif
+#endif
+
+#if !defined WINDOWS_NATIVE
+# include <unistd.h>
+# if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+# else
+# if 0 /* see comment below */
+# include <locale.h>
+# endif
+# endif
+# ifdef __CYGWIN__
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# endif
+#elif defined WINDOWS_NATIVE
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+#if defined OS2
+# define INCL_DOS
+# include <os2.h>
+#endif
+
+/* For MB_CUR_MAX_L */
+#if defined DARWIN7
+# include <xlocale.h>
+#endif
+
+#if ENABLE_RELOCATABLE
+# include "relocatable.h"
+#else
+# define relocate(pathname) (pathname)
+#endif
+
+/* Get LIBDIR. */
+#ifndef LIBDIR
+# include "configmake.h"
+#endif
+
+/* Define O_NOFOLLOW to 0 on platforms where it does not exist. */
+#ifndef O_NOFOLLOW
+# define O_NOFOLLOW 0
+#endif
+
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+ /* Native Windows, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#endif
+
+#ifndef DIRECTORY_SEPARATOR
+# define DIRECTORY_SEPARATOR '/'
+#endif
+
+#ifndef ISSLASH
+# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
+#endif
+
+#if HAVE_DECL_GETC_UNLOCKED
+# undef getc
+# define getc getc_unlocked
+#endif
+
+/* The following static variable is declared 'volatile' to avoid a
+ possible multithread problem in the function get_charset_aliases. If we
+ are running in a threaded environment, and if two threads initialize
+ 'charset_aliases' simultaneously, both will produce the same value,
+ and everything will be ok if the two assignments to 'charset_aliases'
+ are atomic. But I don't know what will happen if the two assignments mix. */
+#if __STDC__ != 1
+# define volatile /* empty */
+#endif
+/* Pointer to the contents of the charset.alias file, if it has already been
+ read, else NULL. Its format is:
+ ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0' */
+static const char * volatile charset_aliases;
+
+/* Return a pointer to the contents of the charset.alias file. */
+static const char *
+get_charset_aliases (void)
+{
+ const char *cp;
+
+ cp = charset_aliases;
+ if (cp == NULL)
+ {
+#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__)
+ const char *dir;
+ const char *base = "charset.alias";
+ char *file_name;
+
+ /* Make it possible to override the charset.alias location. This is
+ necessary for running the testsuite before "make install". */
+ dir = getenv ("CHARSETALIASDIR");
+ if (dir == NULL || dir[0] == '\0')
+ dir = relocate (LIBDIR);
+
+ /* Concatenate dir and base into freshly allocated file_name. */
+ {
+ size_t dir_len = strlen (dir);
+ size_t base_len = strlen (base);
+ int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
+ file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
+ if (file_name != NULL)
+ {
+ memcpy (file_name, dir, dir_len);
+ if (add_slash)
+ file_name[dir_len] = DIRECTORY_SEPARATOR;
+ memcpy (file_name + dir_len + add_slash, base, base_len + 1);
+ }
+ }
+
+ if (file_name == NULL)
+ /* Out of memory. Treat the file as empty. */
+ cp = "";
+ else
+ {
+ int fd;
+
+ /* Open the file. Reject symbolic links on platforms that support
+ O_NOFOLLOW. This is a security feature. Without it, an attacker
+ could retrieve parts of the contents (namely, the tail of the
+ first line that starts with "* ") of an arbitrary file by placing
+ a symbolic link to that file under the name "charset.alias" in
+ some writable directory and defining the environment variable
+ CHARSETALIASDIR to point to that directory. */
+ fd = open (file_name,
+ O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0));
+ if (fd < 0)
+ /* File not found. Treat it as empty. */
+ cp = "";
+ else
+ {
+ FILE *fp;
+
+ fp = fdopen (fd, "r");
+ if (fp == NULL)
+ {
+ /* Out of memory. Treat the file as empty. */
+ close (fd);
+ cp = "";
+ }
+ else
+ {
+ /* Parse the file's contents. */
+ char *res_ptr = NULL;
+ size_t res_size = 0;
+
+ for (;;)
+ {
+ int c;
+ char buf1[50+1];
+ char buf2[50+1];
+ size_t l1, l2;
+ char *old_res_ptr;
+
+ c = getc (fp);
+ if (c == EOF)
+ break;
+ if (c == '\n' || c == ' ' || c == '\t')
+ continue;
+ if (c == '#')
+ {
+ /* Skip comment, to end of line. */
+ do
+ c = getc (fp);
+ while (!(c == EOF || c == '\n'));
+ if (c == EOF)
+ break;
+ continue;
+ }
+ ungetc (c, fp);
+ if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
+ break;
+ l1 = strlen (buf1);
+ l2 = strlen (buf2);
+ old_res_ptr = res_ptr;
+ if (res_size == 0)
+ {
+ res_size = l1 + 1 + l2 + 1;
+ res_ptr = (char *) malloc (res_size + 1);
+ }
+ else
+ {
+ res_size += l1 + 1 + l2 + 1;
+ res_ptr = (char *) realloc (res_ptr, res_size + 1);
+ }
+ if (res_ptr == NULL)
+ {
+ /* Out of memory. */
+ res_size = 0;
+ free (old_res_ptr);
+ break;
+ }
+ strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
+ strcpy (res_ptr + res_size - (l2 + 1), buf2);
+ }
+ fclose (fp);
+ if (res_size == 0)
+ cp = "";
+ else
+ {
+ *(res_ptr + res_size) = '\0';
+ cp = res_ptr;
+ }
+ }
+ }
+
+ free (file_name);
+ }
+
+#else
+
+# if defined DARWIN7
+ /* To avoid the trouble of installing a file that is shared by many
+ GNU packages -- many packaging systems have problems with this --,
+ simply inline the aliases here. */
+ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
+ "ISO8859-2" "\0" "ISO-8859-2" "\0"
+ "ISO8859-4" "\0" "ISO-8859-4" "\0"
+ "ISO8859-5" "\0" "ISO-8859-5" "\0"
+ "ISO8859-7" "\0" "ISO-8859-7" "\0"
+ "ISO8859-9" "\0" "ISO-8859-9" "\0"
+ "ISO8859-13" "\0" "ISO-8859-13" "\0"
+ "ISO8859-15" "\0" "ISO-8859-15" "\0"
+ "KOI8-R" "\0" "KOI8-R" "\0"
+ "KOI8-U" "\0" "KOI8-U" "\0"
+ "CP866" "\0" "CP866" "\0"
+ "CP949" "\0" "CP949" "\0"
+ "CP1131" "\0" "CP1131" "\0"
+ "CP1251" "\0" "CP1251" "\0"
+ "eucCN" "\0" "GB2312" "\0"
+ "GB2312" "\0" "GB2312" "\0"
+ "eucJP" "\0" "EUC-JP" "\0"
+ "eucKR" "\0" "EUC-KR" "\0"
+ "Big5" "\0" "BIG5" "\0"
+ "Big5HKSCS" "\0" "BIG5-HKSCS" "\0"
+ "GBK" "\0" "GBK" "\0"
+ "GB18030" "\0" "GB18030" "\0"
+ "SJIS" "\0" "SHIFT_JIS" "\0"
+ "ARMSCII-8" "\0" "ARMSCII-8" "\0"
+ "PT154" "\0" "PT154" "\0"
+ /*"ISCII-DEV" "\0" "?" "\0"*/
+ "*" "\0" "UTF-8" "\0";
+# endif
+
+# if defined VMS
+ /* To avoid the troubles of an extra file charset.alias_vms in the
+ sources of many GNU packages, simply inline the aliases here. */
+ /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
+ "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
+ section 10.7 "Handling Different Character Sets". */
+ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
+ "ISO8859-2" "\0" "ISO-8859-2" "\0"
+ "ISO8859-5" "\0" "ISO-8859-5" "\0"
+ "ISO8859-7" "\0" "ISO-8859-7" "\0"
+ "ISO8859-8" "\0" "ISO-8859-8" "\0"
+ "ISO8859-9" "\0" "ISO-8859-9" "\0"
+ /* Japanese */
+ "eucJP" "\0" "EUC-JP" "\0"
+ "SJIS" "\0" "SHIFT_JIS" "\0"
+ "DECKANJI" "\0" "DEC-KANJI" "\0"
+ "SDECKANJI" "\0" "EUC-JP" "\0"
+ /* Chinese */
+ "eucTW" "\0" "EUC-TW" "\0"
+ "DECHANYU" "\0" "DEC-HANYU" "\0"
+ "DECHANZI" "\0" "GB2312" "\0"
+ /* Korean */
+ "DECKOREAN" "\0" "EUC-KR" "\0";
+# endif
+
+# if defined WINDOWS_NATIVE || defined __CYGWIN__
+ /* To avoid the troubles of installing a separate file in the same
+ directory as the DLL and of retrieving the DLL's directory at
+ runtime, simply inline the aliases here. */
+
+ cp = "CP936" "\0" "GBK" "\0"
+ "CP1361" "\0" "JOHAB" "\0"
+ "CP20127" "\0" "ASCII" "\0"
+ "CP20866" "\0" "KOI8-R" "\0"
+ "CP20936" "\0" "GB2312" "\0"
+ "CP21866" "\0" "KOI8-RU" "\0"
+ "CP28591" "\0" "ISO-8859-1" "\0"
+ "CP28592" "\0" "ISO-8859-2" "\0"
+ "CP28593" "\0" "ISO-8859-3" "\0"
+ "CP28594" "\0" "ISO-8859-4" "\0"
+ "CP28595" "\0" "ISO-8859-5" "\0"
+ "CP28596" "\0" "ISO-8859-6" "\0"
+ "CP28597" "\0" "ISO-8859-7" "\0"
+ "CP28598" "\0" "ISO-8859-8" "\0"
+ "CP28599" "\0" "ISO-8859-9" "\0"
+ "CP28605" "\0" "ISO-8859-15" "\0"
+ "CP38598" "\0" "ISO-8859-8" "\0"
+ "CP51932" "\0" "EUC-JP" "\0"
+ "CP51936" "\0" "GB2312" "\0"
+ "CP51949" "\0" "EUC-KR" "\0"
+ "CP51950" "\0" "EUC-TW" "\0"
+ "CP54936" "\0" "GB18030" "\0"
+ "CP65001" "\0" "UTF-8" "\0";
+# endif
+#endif
+
+ charset_aliases = cp;
+ }
+
+ return cp;
+}
+
+/* Determine the current locale's character encoding, and canonicalize it
+ into one of the canonical names listed in config.charset.
+ The result must not be freed; it is statically allocated.
+ If the canonical name cannot be determined, the result is a non-canonical
+ name. */
+
+#ifdef STATIC
+STATIC
+#endif
+const char *
+locale_charset (void)
+{
+ const char *codeset;
+ const char *aliases;
+
+#if !(defined WINDOWS_NATIVE || defined OS2)
+
+# if HAVE_LANGINFO_CODESET
+
+ /* Most systems support nl_langinfo (CODESET) nowadays. */
+ codeset = nl_langinfo (CODESET);
+
+# ifdef __CYGWIN__
+ /* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always
+ returns "US-ASCII". Return the suffix of the locale name from the
+ environment variables (if present) or the codepage as a number. */
+ if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
+ {
+ const char *locale;
+ static char buf[2 + 10 + 1];
+
+ locale = getenv ("LC_ALL");
+ if (locale == NULL || locale[0] == '\0')
+ {
+ locale = getenv ("LC_CTYPE");
+ if (locale == NULL || locale[0] == '\0')
+ locale = getenv ("LANG");
+ }
+ if (locale != NULL && locale[0] != '\0')
+ {
+ /* If the locale name contains an encoding after the dot, return
+ it. */
+ const char *dot = strchr (locale, '.');
+
+ if (dot != NULL)
+ {
+ const char *modifier;
+
+ dot++;
+ /* Look for the possible @... trailer and remove it, if any. */
+ modifier = strchr (dot, '@');
+ if (modifier == NULL)
+ return dot;
+ if (modifier - dot < sizeof (buf))
+ {
+ memcpy (buf, dot, modifier - dot);
+ buf [modifier - dot] = '\0';
+ return buf;
+ }
+ }
+ }
+
+ /* The Windows API has a function returning the locale's codepage as a
+ number: GetACP(). This encoding is used by Cygwin, unless the user
+ has set the environment variable CYGWIN=codepage:oem (which very few
+ people do).
+ Output directed to console windows needs to be converted (to
+ GetOEMCP() if the console is using a raster font, or to
+ GetConsoleOutputCP() if it is using a TrueType font). Cygwin does
+ this conversion transparently (see winsup/cygwin/fhandler_console.cc),
+ converting to GetConsoleOutputCP(). This leads to correct results,
+ except when SetConsoleOutputCP has been called and a raster font is
+ in use. */
+ sprintf (buf, "CP%u", GetACP ());
+ codeset = buf;
+ }
+# endif
+
+# else
+
+ /* On old systems which lack it, use setlocale or getenv. */
+ const char *locale = NULL;
+
+ /* But most old systems don't have a complete set of locales. Some
+ (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't
+ use setlocale here; it would return "C" when it doesn't support the
+ locale name the user has set. */
+# if 0
+ locale = setlocale (LC_CTYPE, NULL);
+# endif
+ if (locale == NULL || locale[0] == '\0')
+ {
+ locale = getenv ("LC_ALL");
+ if (locale == NULL || locale[0] == '\0')
+ {
+ locale = getenv ("LC_CTYPE");
+ if (locale == NULL || locale[0] == '\0')
+ locale = getenv ("LANG");
+ }
+ }
+
+ /* On some old systems, one used to set locale = "iso8859_1". On others,
+ you set it to "language_COUNTRY.charset". In any case, we resolve it
+ through the charset.alias file. */
+ codeset = locale;
+
+# endif
+
+#elif defined WINDOWS_NATIVE
+
+ static char buf[2 + 10 + 1];
+
+ /* The Windows API has a function returning the locale's codepage as a
+ number: GetACP().
+ When the output goes to a console window, it needs to be provided in
+ GetOEMCP() encoding if the console is using a raster font, or in
+ GetConsoleOutputCP() encoding if it is using a TrueType font.
+ But in GUI programs and for output sent to files and pipes, GetACP()
+ encoding is the best bet. */
+ sprintf (buf, "CP%u", GetACP ());
+ codeset = buf;
+
+#elif defined OS2
+
+ const char *locale;
+ static char buf[2 + 10 + 1];
+ ULONG cp[3];
+ ULONG cplen;
+
+ /* Allow user to override the codeset, as set in the operating system,
+ with standard language environment variables. */
+ locale = getenv ("LC_ALL");
+ if (locale == NULL || locale[0] == '\0')
+ {
+ locale = getenv ("LC_CTYPE");
+ if (locale == NULL || locale[0] == '\0')
+ locale = getenv ("LANG");
+ }
+ if (locale != NULL && locale[0] != '\0')
+ {
+ /* If the locale name contains an encoding after the dot, return it. */
+ const char *dot = strchr (locale, '.');
+
+ if (dot != NULL)
+ {
+ const char *modifier;
+
+ dot++;
+ /* Look for the possible @... trailer and remove it, if any. */
+ modifier = strchr (dot, '@');
+ if (modifier == NULL)
+ return dot;
+ if (modifier - dot < sizeof (buf))
+ {
+ memcpy (buf, dot, modifier - dot);
+ buf [modifier - dot] = '\0';
+ return buf;
+ }
+ }
+
+ /* Resolve through the charset.alias file. */
+ codeset = locale;
+ }
+ else
+ {
+ /* OS/2 has a function returning the locale's codepage as a number. */
+ if (DosQueryCp (sizeof (cp), cp, &cplen))
+ codeset = "";
+ else
+ {
+ sprintf (buf, "CP%u", cp[0]);
+ codeset = buf;
+ }
+ }
+
+#endif
+
+ if (codeset == NULL)
+ /* The canonical name cannot be determined. */
+ codeset = "";
+
+ /* Resolve alias. */
+ for (aliases = get_charset_aliases ();
+ *aliases != '\0';
+ aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
+ if (strcmp (codeset, aliases) == 0
+ || (aliases[0] == '*' && aliases[1] == '\0'))
+ {
+ codeset = aliases + strlen (aliases) + 1;
+ break;
+ }
+
+ /* Don't return an empty string. GNU libc and GNU libiconv interpret
+ the empty string as denoting "the locale's character encoding",
+ thus GNU libiconv would call this function a second time. */
+ if (codeset[0] == '\0')
+ codeset = "ASCII";
+
+#ifdef DARWIN7
+ /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8"
+ (the default codeset) does not work when MB_CUR_MAX is 1. */
+ if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1)
+ codeset = "ASCII";
+#endif
+
+ return codeset;
+}
diff --git a/contrib/tools/bison/gnulib/src/localcharset.h b/contrib/tools/bison/gnulib/src/localcharset.h
index c209829867..10d83fbeee 100644
--- a/contrib/tools/bison/gnulib/src/localcharset.h
+++ b/contrib/tools/bison/gnulib/src/localcharset.h
@@ -1,40 +1,40 @@
-/* Determine a canonical name for the current locale's character encoding.
- Copyright (C) 2000-2003, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU CHARSET Library.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LOCALCHARSET_H
-#define _LOCALCHARSET_H
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Determine the current locale's character encoding, and canonicalize it
- into one of the canonical names listed in config.charset.
- The result must not be freed; it is statically allocated.
- If the canonical name cannot be determined, the result is a non-canonical
- name. */
-extern const char * locale_charset (void);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _LOCALCHARSET_H */
+/* Determine a canonical name for the current locale's character encoding.
+ Copyright (C) 2000-2003, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU CHARSET Library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LOCALCHARSET_H
+#define _LOCALCHARSET_H
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Determine the current locale's character encoding, and canonicalize it
+ into one of the canonical names listed in config.charset.
+ The result must not be freed; it is statically allocated.
+ If the canonical name cannot be determined, the result is a non-canonical
+ name. */
+extern const char * locale_charset (void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _LOCALCHARSET_H */
diff --git a/contrib/tools/bison/gnulib/src/localeconv.c b/contrib/tools/bison/gnulib/src/localeconv.c
index 7c7c77cfd4..245c06cb2a 100644
--- a/contrib/tools/bison/gnulib/src/localeconv.c
+++ b/contrib/tools/bison/gnulib/src/localeconv.c
@@ -1,103 +1,103 @@
-/* Query locale dependent information for formatting numbers.
- Copyright (C) 2012-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <locale.h>
-
-#if HAVE_STRUCT_LCONV_DECIMAL_POINT
-
-/* Override for platforms where 'struct lconv' lacks the int_p_*, int_n_*
- members. */
-
-struct lconv *
-localeconv (void)
-{
- static struct lconv result;
-# undef lconv
-# undef localeconv
- struct lconv *sys_result = localeconv ();
-
- result.decimal_point = sys_result->decimal_point;
- result.thousands_sep = sys_result->thousands_sep;
- result.grouping = sys_result->grouping;
- result.mon_decimal_point = sys_result->mon_decimal_point;
- result.mon_thousands_sep = sys_result->mon_thousands_sep;
- result.mon_grouping = sys_result->mon_grouping;
- result.positive_sign = sys_result->positive_sign;
- result.negative_sign = sys_result->negative_sign;
- result.currency_symbol = sys_result->currency_symbol;
- result.frac_digits = sys_result->frac_digits;
- result.p_cs_precedes = sys_result->p_cs_precedes;
- result.p_sign_posn = sys_result->p_sign_posn;
- result.p_sep_by_space = sys_result->p_sep_by_space;
- result.n_cs_precedes = sys_result->n_cs_precedes;
- result.n_sign_posn = sys_result->n_sign_posn;
- result.n_sep_by_space = sys_result->n_sep_by_space;
- result.int_curr_symbol = sys_result->int_curr_symbol;
- result.int_frac_digits = sys_result->int_frac_digits;
- result.int_p_cs_precedes = sys_result->p_cs_precedes;
- result.int_p_sign_posn = sys_result->p_sign_posn;
- result.int_p_sep_by_space = sys_result->p_sep_by_space;
- result.int_n_cs_precedes = sys_result->n_cs_precedes;
- result.int_n_sign_posn = sys_result->n_sign_posn;
- result.int_n_sep_by_space = sys_result->n_sep_by_space;
-
- return &result;
-}
-
-#else
-
-/* Override for platforms where 'struct lconv' is a dummy. */
-
-# include <limits.h>
-
-struct lconv *
-localeconv (void)
-{
- static /*const*/ struct lconv result =
- {
- /* decimal_point */ ".",
- /* thousands_sep */ "",
- /* grouping */ "",
- /* mon_decimal_point */ "",
- /* mon_thousands_sep */ "",
- /* mon_grouping */ "",
- /* positive_sign */ "",
- /* negative_sign */ "",
- /* currency_symbol */ "",
- /* frac_digits */ CHAR_MAX,
- /* p_cs_precedes */ CHAR_MAX,
- /* p_sign_posn */ CHAR_MAX,
- /* p_sep_by_space */ CHAR_MAX,
- /* n_cs_precedes */ CHAR_MAX,
- /* n_sign_posn */ CHAR_MAX,
- /* n_sep_by_space */ CHAR_MAX,
- /* int_curr_symbol */ "",
- /* int_frac_digits */ CHAR_MAX,
- /* int_p_cs_precedes */ CHAR_MAX,
- /* int_p_sign_posn */ CHAR_MAX,
- /* int_p_sep_by_space */ CHAR_MAX,
- /* int_n_cs_precedes */ CHAR_MAX,
- /* int_n_sign_posn */ CHAR_MAX,
- /* int_n_sep_by_space */ CHAR_MAX
- };
-
- return &result;
-}
-
-#endif
+/* Query locale dependent information for formatting numbers.
+ Copyright (C) 2012-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <locale.h>
+
+#if HAVE_STRUCT_LCONV_DECIMAL_POINT
+
+/* Override for platforms where 'struct lconv' lacks the int_p_*, int_n_*
+ members. */
+
+struct lconv *
+localeconv (void)
+{
+ static struct lconv result;
+# undef lconv
+# undef localeconv
+ struct lconv *sys_result = localeconv ();
+
+ result.decimal_point = sys_result->decimal_point;
+ result.thousands_sep = sys_result->thousands_sep;
+ result.grouping = sys_result->grouping;
+ result.mon_decimal_point = sys_result->mon_decimal_point;
+ result.mon_thousands_sep = sys_result->mon_thousands_sep;
+ result.mon_grouping = sys_result->mon_grouping;
+ result.positive_sign = sys_result->positive_sign;
+ result.negative_sign = sys_result->negative_sign;
+ result.currency_symbol = sys_result->currency_symbol;
+ result.frac_digits = sys_result->frac_digits;
+ result.p_cs_precedes = sys_result->p_cs_precedes;
+ result.p_sign_posn = sys_result->p_sign_posn;
+ result.p_sep_by_space = sys_result->p_sep_by_space;
+ result.n_cs_precedes = sys_result->n_cs_precedes;
+ result.n_sign_posn = sys_result->n_sign_posn;
+ result.n_sep_by_space = sys_result->n_sep_by_space;
+ result.int_curr_symbol = sys_result->int_curr_symbol;
+ result.int_frac_digits = sys_result->int_frac_digits;
+ result.int_p_cs_precedes = sys_result->p_cs_precedes;
+ result.int_p_sign_posn = sys_result->p_sign_posn;
+ result.int_p_sep_by_space = sys_result->p_sep_by_space;
+ result.int_n_cs_precedes = sys_result->n_cs_precedes;
+ result.int_n_sign_posn = sys_result->n_sign_posn;
+ result.int_n_sep_by_space = sys_result->n_sep_by_space;
+
+ return &result;
+}
+
+#else
+
+/* Override for platforms where 'struct lconv' is a dummy. */
+
+# include <limits.h>
+
+struct lconv *
+localeconv (void)
+{
+ static /*const*/ struct lconv result =
+ {
+ /* decimal_point */ ".",
+ /* thousands_sep */ "",
+ /* grouping */ "",
+ /* mon_decimal_point */ "",
+ /* mon_thousands_sep */ "",
+ /* mon_grouping */ "",
+ /* positive_sign */ "",
+ /* negative_sign */ "",
+ /* currency_symbol */ "",
+ /* frac_digits */ CHAR_MAX,
+ /* p_cs_precedes */ CHAR_MAX,
+ /* p_sign_posn */ CHAR_MAX,
+ /* p_sep_by_space */ CHAR_MAX,
+ /* n_cs_precedes */ CHAR_MAX,
+ /* n_sign_posn */ CHAR_MAX,
+ /* n_sep_by_space */ CHAR_MAX,
+ /* int_curr_symbol */ "",
+ /* int_frac_digits */ CHAR_MAX,
+ /* int_p_cs_precedes */ CHAR_MAX,
+ /* int_p_sign_posn */ CHAR_MAX,
+ /* int_p_sep_by_space */ CHAR_MAX,
+ /* int_n_cs_precedes */ CHAR_MAX,
+ /* int_n_sign_posn */ CHAR_MAX,
+ /* int_n_sep_by_space */ CHAR_MAX
+ };
+
+ return &result;
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/lseek.c b/contrib/tools/bison/gnulib/src/lseek.c
index fa7440d151..a198d98063 100644
--- a/contrib/tools/bison/gnulib/src/lseek.c
+++ b/contrib/tools/bison/gnulib/src/lseek.c
@@ -1,67 +1,67 @@
-/* An lseek() function that detects pipes.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <unistd.h>
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Windows platforms. */
-/* Get GetFileType. */
-# include <windows.h>
-/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
-#else
-# include <sys/stat.h>
-#endif
-#include <errno.h>
-
-#undef lseek
-
-off_t
-rpl_lseek (int fd, off_t offset, int whence)
-{
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */
- HANDLE h = (HANDLE) _get_osfhandle (fd);
- if (h == INVALID_HANDLE_VALUE)
- {
- errno = EBADF;
- return -1;
- }
- if (GetFileType (h) != FILE_TYPE_DISK)
- {
- errno = ESPIPE;
- return -1;
- }
-#else
- /* BeOS lseek mistakenly succeeds on pipes... */
- struct stat statbuf;
- if (fstat (fd, &statbuf) < 0)
- return -1;
- if (!S_ISREG (statbuf.st_mode))
- {
- errno = ESPIPE;
- return -1;
- }
-#endif
-#if _GL_WINDOWS_64_BIT_OFF_T
- return _lseeki64 (fd, offset, whence);
-#else
- return lseek (fd, offset, whence);
-#endif
-}
+/* An lseek() function that detects pipes.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Windows platforms. */
+/* Get GetFileType. */
+# include <windows.h>
+/* Get _get_osfhandle. */
+# include "msvc-nothrow.h"
+#else
+# include <sys/stat.h>
+#endif
+#include <errno.h>
+
+#undef lseek
+
+off_t
+rpl_lseek (int fd, off_t offset, int whence)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ /* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */
+ HANDLE h = (HANDLE) _get_osfhandle (fd);
+ if (h == INVALID_HANDLE_VALUE)
+ {
+ errno = EBADF;
+ return -1;
+ }
+ if (GetFileType (h) != FILE_TYPE_DISK)
+ {
+ errno = ESPIPE;
+ return -1;
+ }
+#else
+ /* BeOS lseek mistakenly succeeds on pipes... */
+ struct stat statbuf;
+ if (fstat (fd, &statbuf) < 0)
+ return -1;
+ if (!S_ISREG (statbuf.st_mode))
+ {
+ errno = ESPIPE;
+ return -1;
+ }
+#endif
+#if _GL_WINDOWS_64_BIT_OFF_T
+ return _lseeki64 (fd, offset, whence);
+#else
+ return lseek (fd, offset, whence);
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/lstat.c b/contrib/tools/bison/gnulib/src/lstat.c
index 1a613a89c8..376a51b11e 100644
--- a/contrib/tools/bison/gnulib/src/lstat.c
+++ b/contrib/tools/bison/gnulib/src/lstat.c
@@ -1,97 +1,97 @@
-/* Work around a bug of lstat on some systems
-
- Copyright (C) 1997-2006, 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Jim Meyering */
-
-/* If the user's config.h happens to include <sys/stat.h>, let it include only
- the system's <sys/stat.h> here, so that orig_lstat doesn't recurse to
- rpl_lstat. */
-#define __need_system_sys_stat_h
-#include <config.h>
-
-#if !HAVE_LSTAT
-/* On systems that lack symlinks, our replacement <sys/stat.h> already
- defined lstat as stat, so there is nothing further to do other than
- avoid an empty file. */
-typedef int dummy;
-#else /* HAVE_LSTAT */
-
-/* Get the original definition of lstat. It might be defined as a macro. */
-# include <sys/types.h>
-# include <sys/stat.h>
-# undef __need_system_sys_stat_h
-
-static int
-orig_lstat (const char *filename, struct stat *buf)
-{
- return lstat (filename, buf);
-}
-
-/* Specification. */
-/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
- eliminates this include because of the preliminary #include <sys/stat.h>
- above. */
-# include "sys/stat.h"
-
-# include <string.h>
-# include <errno.h>
-
-/* lstat works differently on Linux and Solaris systems. POSIX (see
- "pathname resolution" in the glossary) requires that programs like
- 'ls' take into consideration the fact that FILE has a trailing slash
- when FILE is a symbolic link. On Linux and Solaris 10 systems, the
- lstat function already has the desired semantics (in treating
- 'lstat ("symlink/", sbuf)' just like 'lstat ("symlink/.", sbuf)',
- but on Solaris 9 and earlier it does not.
-
- If FILE has a trailing slash and specifies a symbolic link,
- then use stat() to get more info on the referent of FILE.
- If the referent is a non-directory, then set errno to ENOTDIR
- and return -1. Otherwise, return stat's result. */
-
-int
-rpl_lstat (const char *file, struct stat *sbuf)
-{
- size_t len;
- int lstat_result = orig_lstat (file, sbuf);
-
- if (lstat_result != 0)
- return lstat_result;
-
- /* This replacement file can blindly check against '/' rather than
- using the ISSLASH macro, because all platforms with '\\' either
- lack symlinks (mingw) or have working lstat (cygwin) and thus do
- not compile this file. 0 len should have already been filtered
- out above, with a failure return of ENOENT. */
- len = strlen (file);
- if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode))
- return 0;
-
- /* At this point, a trailing slash is only permitted on
- symlink-to-dir; but it should have found information on the
- directory, not the symlink. Call stat() to get info about the
- link's referent. Our replacement stat guarantees valid results,
- even if the symlink is not pointing to a directory. */
- if (!S_ISLNK (sbuf->st_mode))
- {
- errno = ENOTDIR;
- return -1;
- }
- return stat (file, sbuf);
-}
-
-#endif /* HAVE_LSTAT */
+/* Work around a bug of lstat on some systems
+
+ Copyright (C) 1997-2006, 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Jim Meyering */
+
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
+ the system's <sys/stat.h> here, so that orig_lstat doesn't recurse to
+ rpl_lstat. */
+#define __need_system_sys_stat_h
+#include <config.h>
+
+#if !HAVE_LSTAT
+/* On systems that lack symlinks, our replacement <sys/stat.h> already
+ defined lstat as stat, so there is nothing further to do other than
+ avoid an empty file. */
+typedef int dummy;
+#else /* HAVE_LSTAT */
+
+/* Get the original definition of lstat. It might be defined as a macro. */
+# include <sys/types.h>
+# include <sys/stat.h>
+# undef __need_system_sys_stat_h
+
+static int
+orig_lstat (const char *filename, struct stat *buf)
+{
+ return lstat (filename, buf);
+}
+
+/* Specification. */
+/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
+ eliminates this include because of the preliminary #include <sys/stat.h>
+ above. */
+# include "sys/stat.h"
+
+# include <string.h>
+# include <errno.h>
+
+/* lstat works differently on Linux and Solaris systems. POSIX (see
+ "pathname resolution" in the glossary) requires that programs like
+ 'ls' take into consideration the fact that FILE has a trailing slash
+ when FILE is a symbolic link. On Linux and Solaris 10 systems, the
+ lstat function already has the desired semantics (in treating
+ 'lstat ("symlink/", sbuf)' just like 'lstat ("symlink/.", sbuf)',
+ but on Solaris 9 and earlier it does not.
+
+ If FILE has a trailing slash and specifies a symbolic link,
+ then use stat() to get more info on the referent of FILE.
+ If the referent is a non-directory, then set errno to ENOTDIR
+ and return -1. Otherwise, return stat's result. */
+
+int
+rpl_lstat (const char *file, struct stat *sbuf)
+{
+ size_t len;
+ int lstat_result = orig_lstat (file, sbuf);
+
+ if (lstat_result != 0)
+ return lstat_result;
+
+ /* This replacement file can blindly check against '/' rather than
+ using the ISSLASH macro, because all platforms with '\\' either
+ lack symlinks (mingw) or have working lstat (cygwin) and thus do
+ not compile this file. 0 len should have already been filtered
+ out above, with a failure return of ENOENT. */
+ len = strlen (file);
+ if (file[len - 1] != '/' || S_ISDIR (sbuf->st_mode))
+ return 0;
+
+ /* At this point, a trailing slash is only permitted on
+ symlink-to-dir; but it should have found information on the
+ directory, not the symlink. Call stat() to get info about the
+ link's referent. Our replacement stat guarantees valid results,
+ even if the symlink is not pointing to a directory. */
+ if (!S_ISLNK (sbuf->st_mode))
+ {
+ errno = ENOTDIR;
+ return -1;
+ }
+ return stat (file, sbuf);
+}
+
+#endif /* HAVE_LSTAT */
diff --git a/contrib/tools/bison/gnulib/src/malloc.c b/contrib/tools/bison/gnulib/src/malloc.c
index 908735d278..f4c2314eb7 100644
--- a/contrib/tools/bison/gnulib/src/malloc.c
+++ b/contrib/tools/bison/gnulib/src/malloc.c
@@ -1,56 +1,56 @@
-/* malloc() function that is glibc compatible.
-
- Copyright (C) 1997-1998, 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Jim Meyering and Bruno Haible */
-
-#define _GL_USE_STDLIB_ALLOC 1
-#include <config.h>
-/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
-#ifdef malloc
-# define NEED_MALLOC_GNU 1
-# undef malloc
-/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */
-#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU
-# define NEED_MALLOC_GNU 1
-#endif
-
-#include <stdlib.h>
-
-#include <errno.h>
-
-/* Allocate an N-byte block of memory from the heap.
- If N is zero, allocate a 1-byte block. */
-
-void *
-rpl_malloc (size_t n)
-{
- void *result;
-
-#if NEED_MALLOC_GNU
- if (n == 0)
- n = 1;
-#endif
-
- result = malloc (n);
-
-#if !HAVE_MALLOC_POSIX
- if (result == NULL)
- errno = ENOMEM;
-#endif
-
- return result;
-}
+/* malloc() function that is glibc compatible.
+
+ Copyright (C) 1997-1998, 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Jim Meyering and Bruno Haible */
+
+#define _GL_USE_STDLIB_ALLOC 1
+#include <config.h>
+/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
+#ifdef malloc
+# define NEED_MALLOC_GNU 1
+# undef malloc
+/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */
+#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU
+# define NEED_MALLOC_GNU 1
+#endif
+
+#include <stdlib.h>
+
+#include <errno.h>
+
+/* Allocate an N-byte block of memory from the heap.
+ If N is zero, allocate a 1-byte block. */
+
+void *
+rpl_malloc (size_t n)
+{
+ void *result;
+
+#if NEED_MALLOC_GNU
+ if (n == 0)
+ n = 1;
+#endif
+
+ result = malloc (n);
+
+#if !HAVE_MALLOC_POSIX
+ if (result == NULL)
+ errno = ENOMEM;
+#endif
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/malloca.c b/contrib/tools/bison/gnulib/src/malloca.c
index 311be569bc..610819637c 100644
--- a/contrib/tools/bison/gnulib/src/malloca.c
+++ b/contrib/tools/bison/gnulib/src/malloca.c
@@ -1,149 +1,149 @@
-/* Safe automatic memory allocation.
- Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2003.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#define _GL_USE_STDLIB_ALLOC 1
-#include <config.h>
-
-/* Specification. */
-#include "malloca.h"
-
-#include <stdint.h>
-
-#include "verify.h"
-
-/* The speed critical point in this file is freea() applied to an alloca()
- result: it must be fast, to match the speed of alloca(). The speed of
- mmalloca() and freea() in the other case are not critical, because they
- are only invoked for big memory sizes. */
-
-#if HAVE_ALLOCA
-
-/* Store the mmalloca() results in a hash table. This is needed to reliably
- distinguish a mmalloca() result and an alloca() result.
-
- Although it is possible that the same pointer is returned by alloca() and
- by mmalloca() at different times in the same application, it does not lead
- to a bug in freea(), because:
- - Before a pointer returned by alloca() can point into malloc()ed memory,
- the function must return, and once this has happened the programmer must
- not call freea() on it anyway.
- - Before a pointer returned by mmalloca() can point into the stack, it
- must be freed. The only function that can free it is freea(), and
- when freea() frees it, it also removes it from the hash table. */
-
-#define MAGIC_NUMBER 0x1415fb4a
-#define MAGIC_SIZE sizeof (int)
-/* This is how the header info would look like without any alignment
- considerations. */
-struct preliminary_header { void *next; int magic; };
-/* But the header's size must be a multiple of sa_alignment_max. */
-#define HEADER_SIZE \
- (((sizeof (struct preliminary_header) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max)
-union header {
- void *next;
- struct {
- char room[HEADER_SIZE - MAGIC_SIZE];
- int word;
- } magic;
-};
-verify (HEADER_SIZE == sizeof (union header));
-/* We make the hash table quite big, so that during lookups the probability
- of empty hash buckets is quite high. There is no need to make the hash
- table resizable, because when the hash table gets filled so much that the
- lookup becomes slow, it means that the application has memory leaks. */
-#define HASH_TABLE_SIZE 257
-static void * mmalloca_results[HASH_TABLE_SIZE];
-
-#endif
-
-void *
-mmalloca (size_t n)
-{
-#if HAVE_ALLOCA
- /* Allocate one more word, that serves as an indicator for malloc()ed
- memory, so that freea() of an alloca() result is fast. */
- size_t nplus = n + HEADER_SIZE;
-
- if (nplus >= n)
- {
- void *p = malloc (nplus);
-
- if (p != NULL)
- {
- size_t slot;
- union header *h = p;
-
- p = h + 1;
-
- /* Put a magic number into the indicator word. */
- h->magic.word = MAGIC_NUMBER;
-
- /* Enter p into the hash table. */
- slot = (uintptr_t) p % HASH_TABLE_SIZE;
- h->next = mmalloca_results[slot];
- mmalloca_results[slot] = p;
-
- return p;
- }
- }
- /* Out of memory. */
- return NULL;
-#else
-# if !MALLOC_0_IS_NONNULL
- if (n == 0)
- n = 1;
-# endif
- return malloc (n);
-#endif
-}
-
-#if HAVE_ALLOCA
-void
-freea (void *p)
-{
- /* mmalloca() may have returned NULL. */
- if (p != NULL)
- {
- /* Attempt to quickly distinguish the mmalloca() result - which has
- a magic indicator word - and the alloca() result - which has an
- uninitialized indicator word. It is for this test that sa_increment
- additional bytes are allocated in the alloca() case. */
- if (((int *) p)[-1] == MAGIC_NUMBER)
- {
- /* Looks like a mmalloca() result. To see whether it really is one,
- perform a lookup in the hash table. */
- size_t slot = (uintptr_t) p % HASH_TABLE_SIZE;
- void **chain = &mmalloca_results[slot];
- for (; *chain != NULL;)
- {
- union header *h = p;
- if (*chain == p)
- {
- /* Found it. Remove it from the hash table and free it. */
- union header *p_begin = h - 1;
- *chain = p_begin->next;
- free (p_begin);
- return;
- }
- h = *chain;
- chain = &h[-1].next;
- }
- }
- /* At this point, we know it was not a mmalloca() result. */
- }
-}
-#endif
+/* Safe automatic memory allocation.
+ Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#define _GL_USE_STDLIB_ALLOC 1
+#include <config.h>
+
+/* Specification. */
+#include "malloca.h"
+
+#include <stdint.h>
+
+#include "verify.h"
+
+/* The speed critical point in this file is freea() applied to an alloca()
+ result: it must be fast, to match the speed of alloca(). The speed of
+ mmalloca() and freea() in the other case are not critical, because they
+ are only invoked for big memory sizes. */
+
+#if HAVE_ALLOCA
+
+/* Store the mmalloca() results in a hash table. This is needed to reliably
+ distinguish a mmalloca() result and an alloca() result.
+
+ Although it is possible that the same pointer is returned by alloca() and
+ by mmalloca() at different times in the same application, it does not lead
+ to a bug in freea(), because:
+ - Before a pointer returned by alloca() can point into malloc()ed memory,
+ the function must return, and once this has happened the programmer must
+ not call freea() on it anyway.
+ - Before a pointer returned by mmalloca() can point into the stack, it
+ must be freed. The only function that can free it is freea(), and
+ when freea() frees it, it also removes it from the hash table. */
+
+#define MAGIC_NUMBER 0x1415fb4a
+#define MAGIC_SIZE sizeof (int)
+/* This is how the header info would look like without any alignment
+ considerations. */
+struct preliminary_header { void *next; int magic; };
+/* But the header's size must be a multiple of sa_alignment_max. */
+#define HEADER_SIZE \
+ (((sizeof (struct preliminary_header) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max)
+union header {
+ void *next;
+ struct {
+ char room[HEADER_SIZE - MAGIC_SIZE];
+ int word;
+ } magic;
+};
+verify (HEADER_SIZE == sizeof (union header));
+/* We make the hash table quite big, so that during lookups the probability
+ of empty hash buckets is quite high. There is no need to make the hash
+ table resizable, because when the hash table gets filled so much that the
+ lookup becomes slow, it means that the application has memory leaks. */
+#define HASH_TABLE_SIZE 257
+static void * mmalloca_results[HASH_TABLE_SIZE];
+
+#endif
+
+void *
+mmalloca (size_t n)
+{
+#if HAVE_ALLOCA
+ /* Allocate one more word, that serves as an indicator for malloc()ed
+ memory, so that freea() of an alloca() result is fast. */
+ size_t nplus = n + HEADER_SIZE;
+
+ if (nplus >= n)
+ {
+ void *p = malloc (nplus);
+
+ if (p != NULL)
+ {
+ size_t slot;
+ union header *h = p;
+
+ p = h + 1;
+
+ /* Put a magic number into the indicator word. */
+ h->magic.word = MAGIC_NUMBER;
+
+ /* Enter p into the hash table. */
+ slot = (uintptr_t) p % HASH_TABLE_SIZE;
+ h->next = mmalloca_results[slot];
+ mmalloca_results[slot] = p;
+
+ return p;
+ }
+ }
+ /* Out of memory. */
+ return NULL;
+#else
+# if !MALLOC_0_IS_NONNULL
+ if (n == 0)
+ n = 1;
+# endif
+ return malloc (n);
+#endif
+}
+
+#if HAVE_ALLOCA
+void
+freea (void *p)
+{
+ /* mmalloca() may have returned NULL. */
+ if (p != NULL)
+ {
+ /* Attempt to quickly distinguish the mmalloca() result - which has
+ a magic indicator word - and the alloca() result - which has an
+ uninitialized indicator word. It is for this test that sa_increment
+ additional bytes are allocated in the alloca() case. */
+ if (((int *) p)[-1] == MAGIC_NUMBER)
+ {
+ /* Looks like a mmalloca() result. To see whether it really is one,
+ perform a lookup in the hash table. */
+ size_t slot = (uintptr_t) p % HASH_TABLE_SIZE;
+ void **chain = &mmalloca_results[slot];
+ for (; *chain != NULL;)
+ {
+ union header *h = p;
+ if (*chain == p)
+ {
+ /* Found it. Remove it from the hash table and free it. */
+ union header *p_begin = h - 1;
+ *chain = p_begin->next;
+ free (p_begin);
+ return;
+ }
+ h = *chain;
+ chain = &h[-1].next;
+ }
+ }
+ /* At this point, we know it was not a mmalloca() result. */
+ }
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/malloca.h b/contrib/tools/bison/gnulib/src/malloca.h
index 8ec4465dc7..921edcb63d 100644
--- a/contrib/tools/bison/gnulib/src/malloca.h
+++ b/contrib/tools/bison/gnulib/src/malloca.h
@@ -1,133 +1,133 @@
-/* Safe automatic memory allocation.
- Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2003.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _MALLOCA_H
-#define _MALLOCA_H
-
+/* Safe automatic memory allocation.
+ Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _MALLOCA_H
+#define _MALLOCA_H
+
#include "palloca.h"
-#include <stddef.h>
-#include <stdlib.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* safe_alloca(N) is equivalent to alloca(N) when it is safe to call
- alloca(N); otherwise it returns NULL. It either returns N bytes of
- memory allocated on the stack, that lasts until the function returns,
- or NULL.
- Use of safe_alloca should be avoided:
- - inside arguments of function calls - undefined behaviour,
- - in inline functions - the allocation may actually last until the
- calling function returns.
-*/
-#if HAVE_ALLOCA
-/* The OS usually guarantees only one guard page at the bottom of the stack,
- and a page size can be as small as 4096 bytes. So we cannot safely
- allocate anything larger than 4096 bytes. Also care for the possibility
- of a few compiler-allocated temporary stack slots.
- This must be a macro, not a function. */
-# define safe_alloca(N) ((N) < 4032 ? alloca (N) : NULL)
-#else
-# define safe_alloca(N) ((void) (N), NULL)
-#endif
-
-/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
- memory allocated on the stack, that must be freed using freea() before
- the function returns. Upon failure, it returns NULL. */
-#if HAVE_ALLOCA
-# define malloca(N) \
- ((N) < 4032 - sa_increment \
- ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \
- : mmalloca (N))
-#else
-# define malloca(N) \
- mmalloca (N)
-#endif
-extern void * mmalloca (size_t n);
-
-/* Free a block of memory allocated through malloca(). */
-#if HAVE_ALLOCA
-extern void freea (void *p);
-#else
-# define freea free
-#endif
-
-/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
- It allocates an array of N objects, each with S bytes of memory,
- on the stack. S must be positive and N must be nonnegative.
- The array must be freed using freea() before the function returns. */
-#if 1
-/* Cf. the definition of xalloc_oversized. */
-# define nmalloca(n, s) \
- ((n) > (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) \
- ? NULL \
- : malloca ((n) * (s)))
-#else
-extern void * nmalloca (size_t n, size_t s);
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-/* ------------------- Auxiliary, non-public definitions ------------------- */
-
-/* Determine the alignment of a type at compile time. */
-#if defined __GNUC__ || defined __IBM__ALIGNOF__
-# define sa_alignof __alignof__
-#elif defined __cplusplus
- template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
-# define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
-#elif defined __hpux
- /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
- values. */
-# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
-#elif defined _AIX
- /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
- values. */
-# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
-#else
-# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
-#endif
-
-enum
-{
-/* The desired alignment of memory allocations is the maximum alignment
- among all elementary types. */
- sa_alignment_long = sa_alignof (long),
- sa_alignment_double = sa_alignof (double),
-#if HAVE_LONG_LONG_INT
- sa_alignment_longlong = sa_alignof (long long),
-#endif
- sa_alignment_longdouble = sa_alignof (long double),
- sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
-#if HAVE_LONG_LONG_INT
- | (sa_alignment_longlong - 1)
-#endif
- | (sa_alignment_longdouble - 1)
- ) + 1,
-/* The increment that guarantees room for a magic word must be >= sizeof (int)
- and a multiple of sa_alignment_max. */
- sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max
-};
-
-#endif /* _MALLOCA_H */
+#include <stddef.h>
+#include <stdlib.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* safe_alloca(N) is equivalent to alloca(N) when it is safe to call
+ alloca(N); otherwise it returns NULL. It either returns N bytes of
+ memory allocated on the stack, that lasts until the function returns,
+ or NULL.
+ Use of safe_alloca should be avoided:
+ - inside arguments of function calls - undefined behaviour,
+ - in inline functions - the allocation may actually last until the
+ calling function returns.
+*/
+#if HAVE_ALLOCA
+/* The OS usually guarantees only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ allocate anything larger than 4096 bytes. Also care for the possibility
+ of a few compiler-allocated temporary stack slots.
+ This must be a macro, not a function. */
+# define safe_alloca(N) ((N) < 4032 ? alloca (N) : NULL)
+#else
+# define safe_alloca(N) ((void) (N), NULL)
+#endif
+
+/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
+ memory allocated on the stack, that must be freed using freea() before
+ the function returns. Upon failure, it returns NULL. */
+#if HAVE_ALLOCA
+# define malloca(N) \
+ ((N) < 4032 - sa_increment \
+ ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \
+ : mmalloca (N))
+#else
+# define malloca(N) \
+ mmalloca (N)
+#endif
+extern void * mmalloca (size_t n);
+
+/* Free a block of memory allocated through malloca(). */
+#if HAVE_ALLOCA
+extern void freea (void *p);
+#else
+# define freea free
+#endif
+
+/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
+ It allocates an array of N objects, each with S bytes of memory,
+ on the stack. S must be positive and N must be nonnegative.
+ The array must be freed using freea() before the function returns. */
+#if 1
+/* Cf. the definition of xalloc_oversized. */
+# define nmalloca(n, s) \
+ ((n) > (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) \
+ ? NULL \
+ : malloca ((n) * (s)))
+#else
+extern void * nmalloca (size_t n, size_t s);
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+/* ------------------- Auxiliary, non-public definitions ------------------- */
+
+/* Determine the alignment of a type at compile time. */
+#if defined __GNUC__ || defined __IBM__ALIGNOF__
+# define sa_alignof __alignof__
+#elif defined __cplusplus
+ template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
+# define sa_alignof(type) offsetof (sa_alignof_helper<type>, __slot2)
+#elif defined __hpux
+ /* Work around a HP-UX 10.20 cc bug with enums constants defined as offsetof
+ values. */
+# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
+#elif defined _AIX
+ /* Work around an AIX 3.2.5 xlc bug with enums constants defined as offsetof
+ values. */
+# define sa_alignof(type) (sizeof (type) <= 4 ? 4 : 8)
+#else
+# define sa_alignof(type) offsetof (struct { char __slot1; type __slot2; }, __slot2)
+#endif
+
+enum
+{
+/* The desired alignment of memory allocations is the maximum alignment
+ among all elementary types. */
+ sa_alignment_long = sa_alignof (long),
+ sa_alignment_double = sa_alignof (double),
+#if HAVE_LONG_LONG_INT
+ sa_alignment_longlong = sa_alignof (long long),
+#endif
+ sa_alignment_longdouble = sa_alignof (long double),
+ sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
+#if HAVE_LONG_LONG_INT
+ | (sa_alignment_longlong - 1)
+#endif
+ | (sa_alignment_longdouble - 1)
+ ) + 1,
+/* The increment that guarantees room for a magic word must be >= sizeof (int)
+ and a multiple of sa_alignment_max. */
+ sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max
+};
+
+#endif /* _MALLOCA_H */
diff --git a/contrib/tools/bison/gnulib/src/math.c b/contrib/tools/bison/gnulib/src/math.c
index ddb2ded530..b4c5c18c79 100644
--- a/contrib/tools/bison/gnulib/src/math.c
+++ b/contrib/tools/bison/gnulib/src/math.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define _GL_MATH_INLINE _GL_EXTERN_INLINE
-#include "math.h"
+#include <config.h>
+#define _GL_MATH_INLINE _GL_EXTERN_INLINE
+#include "math.h"
diff --git a/contrib/tools/bison/gnulib/src/mbrtowc.c b/contrib/tools/bison/gnulib/src/mbrtowc.c
index 5ee44aea48..9fcfcaca36 100644
--- a/contrib/tools/bison/gnulib/src/mbrtowc.c
+++ b/contrib/tools/bison/gnulib/src/mbrtowc.c
@@ -1,402 +1,402 @@
-/* Convert multibyte character to wide character.
- Copyright (C) 1999-2002, 2005-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2008.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <wchar.h>
-
-#if GNULIB_defined_mbstate_t
-/* Implement mbrtowc() on top of mbtowc(). */
-
-# include <errno.h>
-# include <stdlib.h>
-
-# include "localcharset.h"
-# include "streq.h"
-# include "verify.h"
-
-
-verify (sizeof (mbstate_t) >= 4);
-
-static char internal_state[4];
-
-size_t
-mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
-{
- char *pstate = (char *)ps;
-
- if (s == NULL)
- {
- pwc = NULL;
- s = "";
- n = 1;
- }
-
- if (n == 0)
- return (size_t)(-2);
-
- /* Here n > 0. */
-
- if (pstate == NULL)
- pstate = internal_state;
-
- {
- size_t nstate = pstate[0];
- char buf[4];
- const char *p;
- size_t m;
-
- switch (nstate)
- {
- case 0:
- p = s;
- m = n;
- break;
- case 3:
- buf[2] = pstate[3];
- /*FALLTHROUGH*/
- case 2:
- buf[1] = pstate[2];
- /*FALLTHROUGH*/
- case 1:
- buf[0] = pstate[1];
- p = buf;
- m = nstate;
- buf[m++] = s[0];
- if (n >= 2 && m < 4)
- {
- buf[m++] = s[1];
- if (n >= 3 && m < 4)
- buf[m++] = s[2];
- }
- break;
- default:
- errno = EINVAL;
- return (size_t)(-1);
- }
-
- /* Here m > 0. */
-
-# if __GLIBC__ || defined __UCLIBC__
- /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
- mbtowc (NULL, NULL, 0);
-# endif
- {
- int res = mbtowc (pwc, p, m);
-
- if (res >= 0)
- {
- if (pwc != NULL && ((*pwc == 0) != (res == 0)))
- abort ();
- if (nstate >= (res > 0 ? res : 1))
- abort ();
- res -= nstate;
- pstate[0] = 0;
- return res;
- }
-
- /* mbtowc does not distinguish between invalid and incomplete multibyte
- sequences. But mbrtowc needs to make this distinction.
- There are two possible approaches:
- - Use iconv() and its return value.
- - Use built-in knowledge about the possible encodings.
- Given the low quality of implementation of iconv() on the systems that
- lack mbrtowc(), we use the second approach.
- The possible encodings are:
- - 8-bit encodings,
- - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
- - UTF-8.
- Use specialized code for each. */
- if (m >= 4 || m >= MB_CUR_MAX)
- goto invalid;
- /* Here MB_CUR_MAX > 1 and 0 < m < 4. */
- {
- const char *encoding = locale_charset ();
-
- if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
- {
- /* Cf. unistr/u8-mblen.c. */
- unsigned char c = (unsigned char) p[0];
-
- if (c >= 0xc2)
- {
- if (c < 0xe0)
- {
- if (m == 1)
- goto incomplete;
- }
- else if (c < 0xf0)
- {
- if (m == 1)
- goto incomplete;
- if (m == 2)
- {
- unsigned char c2 = (unsigned char) p[1];
-
- if ((c2 ^ 0x80) < 0x40
- && (c >= 0xe1 || c2 >= 0xa0)
- && (c != 0xed || c2 < 0xa0))
- goto incomplete;
- }
- }
- else if (c <= 0xf4)
- {
- if (m == 1)
- goto incomplete;
- else /* m == 2 || m == 3 */
- {
- unsigned char c2 = (unsigned char) p[1];
-
- if ((c2 ^ 0x80) < 0x40
- && (c >= 0xf1 || c2 >= 0x90)
- && (c < 0xf4 || (c == 0xf4 && c2 < 0x90)))
- {
- if (m == 2)
- goto incomplete;
- else /* m == 3 */
- {
- unsigned char c3 = (unsigned char) p[2];
-
- if ((c3 ^ 0x80) < 0x40)
- goto incomplete;
- }
- }
- }
- }
- }
- goto invalid;
- }
-
- /* As a reference for this code, you can use the GNU libiconv
- implementation. Look for uses of the RET_TOOFEW macro. */
-
- if (STREQ_OPT (encoding,
- "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
- {
- if (m == 1)
- {
- unsigned char c = (unsigned char) p[0];
-
- if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
- goto incomplete;
- }
- if (m == 2)
- {
- unsigned char c = (unsigned char) p[0];
-
- if (c == 0x8f)
- {
- unsigned char c2 = (unsigned char) p[1];
-
- if (c2 >= 0xa1 && c2 < 0xff)
- goto incomplete;
- }
- }
- goto invalid;
- }
- if (STREQ_OPT (encoding,
- "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
- || STREQ_OPT (encoding,
- "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
- || STREQ_OPT (encoding,
- "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
- {
- if (m == 1)
- {
- unsigned char c = (unsigned char) p[0];
-
- if (c >= 0xa1 && c < 0xff)
- goto incomplete;
- }
- goto invalid;
- }
- if (STREQ_OPT (encoding,
- "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
- {
- if (m == 1)
- {
- unsigned char c = (unsigned char) p[0];
-
- if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
- goto incomplete;
- }
- else /* m == 2 || m == 3 */
- {
- unsigned char c = (unsigned char) p[0];
-
- if (c == 0x8e)
- goto incomplete;
- }
- goto invalid;
- }
- if (STREQ_OPT (encoding,
- "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
- {
- if (m == 1)
- {
- unsigned char c = (unsigned char) p[0];
-
- if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
- goto incomplete;
- }
- else /* m == 2 || m == 3 */
- {
- unsigned char c = (unsigned char) p[0];
-
- if (c >= 0x90 && c <= 0xe3)
- {
- unsigned char c2 = (unsigned char) p[1];
-
- if (c2 >= 0x30 && c2 <= 0x39)
- {
- if (m == 2)
- goto incomplete;
- else /* m == 3 */
- {
- unsigned char c3 = (unsigned char) p[2];
-
- if (c3 >= 0x81 && c3 <= 0xfe)
- goto incomplete;
- }
- }
- }
- }
- goto invalid;
- }
- if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
- {
- if (m == 1)
- {
- unsigned char c = (unsigned char) p[0];
-
- if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
- || (c >= 0xf0 && c <= 0xf9))
- goto incomplete;
- }
- goto invalid;
- }
-
- /* An unknown multibyte encoding. */
- goto incomplete;
- }
-
- incomplete:
- {
- size_t k = nstate;
- /* Here 0 <= k < m < 4. */
- pstate[++k] = s[0];
- if (k < m)
- {
- pstate[++k] = s[1];
- if (k < m)
- pstate[++k] = s[2];
- }
- if (k != m)
- abort ();
- }
- pstate[0] = m;
- return (size_t)(-2);
-
- invalid:
- errno = EILSEQ;
- /* The conversion state is undefined, says POSIX. */
- return (size_t)(-1);
- }
- }
-}
-
-#else
-/* Override the system's mbrtowc() function. */
-
-# undef mbrtowc
-
-size_t
-rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
-{
-# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG
- if (s == NULL)
- {
- pwc = NULL;
- s = "";
- n = 1;
- }
-# endif
-
-# if MBRTOWC_RETVAL_BUG
- {
- static mbstate_t internal_state;
-
- /* Override mbrtowc's internal state. We cannot call mbsinit() on the
- hidden internal state, but we can call it on our variable. */
- if (ps == NULL)
- ps = &internal_state;
-
- if (!mbsinit (ps))
- {
- /* Parse the rest of the multibyte character byte for byte. */
- size_t count = 0;
- for (; n > 0; s++, n--)
- {
- wchar_t wc;
- size_t ret = mbrtowc (&wc, s, 1, ps);
-
- if (ret == (size_t)(-1))
- return (size_t)(-1);
- count++;
- if (ret != (size_t)(-2))
- {
- /* The multibyte character has been completed. */
- if (pwc != NULL)
- *pwc = wc;
- return (wc == 0 ? 0 : count);
- }
- }
- return (size_t)(-2);
- }
- }
-# endif
-
-# if MBRTOWC_NUL_RETVAL_BUG
- {
- wchar_t wc;
- size_t ret = mbrtowc (&wc, s, n, ps);
-
- if (ret != (size_t)(-1) && ret != (size_t)(-2))
- {
- if (pwc != NULL)
- *pwc = wc;
- if (wc == 0)
- ret = 0;
- }
- return ret;
- }
-# else
- {
-# if MBRTOWC_NULL_ARG1_BUG
- wchar_t dummy;
-
- if (pwc == NULL)
- pwc = &dummy;
-# endif
-
- return mbrtowc (pwc, s, n, ps);
- }
-# endif
-}
-
-#endif
+/* Convert multibyte character to wide character.
+ Copyright (C) 1999-2002, 2005-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+#if GNULIB_defined_mbstate_t
+/* Implement mbrtowc() on top of mbtowc(). */
+
+# include <errno.h>
+# include <stdlib.h>
+
+# include "localcharset.h"
+# include "streq.h"
+# include "verify.h"
+
+
+verify (sizeof (mbstate_t) >= 4);
+
+static char internal_state[4];
+
+size_t
+mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+ char *pstate = (char *)ps;
+
+ if (s == NULL)
+ {
+ pwc = NULL;
+ s = "";
+ n = 1;
+ }
+
+ if (n == 0)
+ return (size_t)(-2);
+
+ /* Here n > 0. */
+
+ if (pstate == NULL)
+ pstate = internal_state;
+
+ {
+ size_t nstate = pstate[0];
+ char buf[4];
+ const char *p;
+ size_t m;
+
+ switch (nstate)
+ {
+ case 0:
+ p = s;
+ m = n;
+ break;
+ case 3:
+ buf[2] = pstate[3];
+ /*FALLTHROUGH*/
+ case 2:
+ buf[1] = pstate[2];
+ /*FALLTHROUGH*/
+ case 1:
+ buf[0] = pstate[1];
+ p = buf;
+ m = nstate;
+ buf[m++] = s[0];
+ if (n >= 2 && m < 4)
+ {
+ buf[m++] = s[1];
+ if (n >= 3 && m < 4)
+ buf[m++] = s[2];
+ }
+ break;
+ default:
+ errno = EINVAL;
+ return (size_t)(-1);
+ }
+
+ /* Here m > 0. */
+
+# if __GLIBC__ || defined __UCLIBC__
+ /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
+ mbtowc (NULL, NULL, 0);
+# endif
+ {
+ int res = mbtowc (pwc, p, m);
+
+ if (res >= 0)
+ {
+ if (pwc != NULL && ((*pwc == 0) != (res == 0)))
+ abort ();
+ if (nstate >= (res > 0 ? res : 1))
+ abort ();
+ res -= nstate;
+ pstate[0] = 0;
+ return res;
+ }
+
+ /* mbtowc does not distinguish between invalid and incomplete multibyte
+ sequences. But mbrtowc needs to make this distinction.
+ There are two possible approaches:
+ - Use iconv() and its return value.
+ - Use built-in knowledge about the possible encodings.
+ Given the low quality of implementation of iconv() on the systems that
+ lack mbrtowc(), we use the second approach.
+ The possible encodings are:
+ - 8-bit encodings,
+ - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
+ - UTF-8.
+ Use specialized code for each. */
+ if (m >= 4 || m >= MB_CUR_MAX)
+ goto invalid;
+ /* Here MB_CUR_MAX > 1 and 0 < m < 4. */
+ {
+ const char *encoding = locale_charset ();
+
+ if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
+ {
+ /* Cf. unistr/u8-mblen.c. */
+ unsigned char c = (unsigned char) p[0];
+
+ if (c >= 0xc2)
+ {
+ if (c < 0xe0)
+ {
+ if (m == 1)
+ goto incomplete;
+ }
+ else if (c < 0xf0)
+ {
+ if (m == 1)
+ goto incomplete;
+ if (m == 2)
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if ((c2 ^ 0x80) < 0x40
+ && (c >= 0xe1 || c2 >= 0xa0)
+ && (c != 0xed || c2 < 0xa0))
+ goto incomplete;
+ }
+ }
+ else if (c <= 0xf4)
+ {
+ if (m == 1)
+ goto incomplete;
+ else /* m == 2 || m == 3 */
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if ((c2 ^ 0x80) < 0x40
+ && (c >= 0xf1 || c2 >= 0x90)
+ && (c < 0xf4 || (c == 0xf4 && c2 < 0x90)))
+ {
+ if (m == 2)
+ goto incomplete;
+ else /* m == 3 */
+ {
+ unsigned char c3 = (unsigned char) p[2];
+
+ if ((c3 ^ 0x80) < 0x40)
+ goto incomplete;
+ }
+ }
+ }
+ }
+ }
+ goto invalid;
+ }
+
+ /* As a reference for this code, you can use the GNU libiconv
+ implementation. Look for uses of the RET_TOOFEW macro. */
+
+ if (STREQ_OPT (encoding,
+ "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
+ goto incomplete;
+ }
+ if (m == 2)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c == 0x8f)
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if (c2 >= 0xa1 && c2 < 0xff)
+ goto incomplete;
+ }
+ }
+ goto invalid;
+ }
+ if (STREQ_OPT (encoding,
+ "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+ || STREQ_OPT (encoding,
+ "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
+ || STREQ_OPT (encoding,
+ "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c >= 0xa1 && c < 0xff)
+ goto incomplete;
+ }
+ goto invalid;
+ }
+ if (STREQ_OPT (encoding,
+ "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
+ goto incomplete;
+ }
+ else /* m == 2 || m == 3 */
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c == 0x8e)
+ goto incomplete;
+ }
+ goto invalid;
+ }
+ if (STREQ_OPT (encoding,
+ "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
+ goto incomplete;
+ }
+ else /* m == 2 || m == 3 */
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c >= 0x90 && c <= 0xe3)
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if (c2 >= 0x30 && c2 <= 0x39)
+ {
+ if (m == 2)
+ goto incomplete;
+ else /* m == 3 */
+ {
+ unsigned char c3 = (unsigned char) p[2];
+
+ if (c3 >= 0x81 && c3 <= 0xfe)
+ goto incomplete;
+ }
+ }
+ }
+ }
+ goto invalid;
+ }
+ if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
+ || (c >= 0xf0 && c <= 0xf9))
+ goto incomplete;
+ }
+ goto invalid;
+ }
+
+ /* An unknown multibyte encoding. */
+ goto incomplete;
+ }
+
+ incomplete:
+ {
+ size_t k = nstate;
+ /* Here 0 <= k < m < 4. */
+ pstate[++k] = s[0];
+ if (k < m)
+ {
+ pstate[++k] = s[1];
+ if (k < m)
+ pstate[++k] = s[2];
+ }
+ if (k != m)
+ abort ();
+ }
+ pstate[0] = m;
+ return (size_t)(-2);
+
+ invalid:
+ errno = EILSEQ;
+ /* The conversion state is undefined, says POSIX. */
+ return (size_t)(-1);
+ }
+ }
+}
+
+#else
+/* Override the system's mbrtowc() function. */
+
+# undef mbrtowc
+
+size_t
+rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG
+ if (s == NULL)
+ {
+ pwc = NULL;
+ s = "";
+ n = 1;
+ }
+# endif
+
+# if MBRTOWC_RETVAL_BUG
+ {
+ static mbstate_t internal_state;
+
+ /* Override mbrtowc's internal state. We cannot call mbsinit() on the
+ hidden internal state, but we can call it on our variable. */
+ if (ps == NULL)
+ ps = &internal_state;
+
+ if (!mbsinit (ps))
+ {
+ /* Parse the rest of the multibyte character byte for byte. */
+ size_t count = 0;
+ for (; n > 0; s++, n--)
+ {
+ wchar_t wc;
+ size_t ret = mbrtowc (&wc, s, 1, ps);
+
+ if (ret == (size_t)(-1))
+ return (size_t)(-1);
+ count++;
+ if (ret != (size_t)(-2))
+ {
+ /* The multibyte character has been completed. */
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == 0 ? 0 : count);
+ }
+ }
+ return (size_t)(-2);
+ }
+ }
+# endif
+
+# if MBRTOWC_NUL_RETVAL_BUG
+ {
+ wchar_t wc;
+ size_t ret = mbrtowc (&wc, s, n, ps);
+
+ if (ret != (size_t)(-1) && ret != (size_t)(-2))
+ {
+ if (pwc != NULL)
+ *pwc = wc;
+ if (wc == 0)
+ ret = 0;
+ }
+ return ret;
+ }
+# else
+ {
+# if MBRTOWC_NULL_ARG1_BUG
+ wchar_t dummy;
+
+ if (pwc == NULL)
+ pwc = &dummy;
+# endif
+
+ return mbrtowc (pwc, s, n, ps);
+ }
+# endif
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/mbswidth.c b/contrib/tools/bison/gnulib/src/mbswidth.c
index 6571037592..c986504ca3 100644
--- a/contrib/tools/bison/gnulib/src/mbswidth.c
+++ b/contrib/tools/bison/gnulib/src/mbswidth.c
@@ -1,193 +1,193 @@
-/* Determine the number of screen columns needed for a string.
- Copyright (C) 2000-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <haible@clisp.cons.org>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "mbswidth.h"
-
-/* Get MB_CUR_MAX. */
-#include <stdlib.h>
-
-#include <string.h>
-
-/* Get isprint(). */
-#include <ctype.h>
-
-/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */
+/* Determine the number of screen columns needed for a string.
+ Copyright (C) 2000-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <haible@clisp.cons.org>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "mbswidth.h"
+
+/* Get MB_CUR_MAX. */
+#include <stdlib.h>
+
+#include <string.h>
+
+/* Get isprint(). */
+#include <ctype.h>
+
+/* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth(). */
#include "wchar--.h"
-
-/* Get iswcntrl(). */
-#include <wctype.h>
-
-/* Get INT_MAX. */
-#include <limits.h>
-
-/* Returns the number of columns needed to represent the multibyte
- character string pointed to by STRING. If a non-printable character
- occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned.
- With flags = MBSW_REJECT_INVALID | MBSW_REJECT_UNPRINTABLE, this is
- the multibyte analogue of the wcswidth function. */
-int
-mbswidth (const char *string, int flags)
-{
- return mbsnwidth (string, strlen (string), flags);
-}
-
-/* Returns the number of columns needed to represent the multibyte
- character string pointed to by STRING of length NBYTES. If a
- non-printable character occurs, and MBSW_REJECT_UNPRINTABLE is
- specified, -1 is returned. */
-int
-mbsnwidth (const char *string, size_t nbytes, int flags)
-{
- const char *p = string;
- const char *plimit = p + nbytes;
- int width;
-
- width = 0;
- if (MB_CUR_MAX > 1)
- {
- while (p < plimit)
- switch (*p)
- {
- case ' ': case '!': case '"': case '#': case '%':
- case '&': case '\'': case '(': case ')': case '*':
- case '+': case ',': case '-': case '.': case '/':
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- case ':': case ';': case '<': case '=': case '>':
- case '?':
- case 'A': case 'B': case 'C': case 'D': case 'E':
- case 'F': case 'G': case 'H': case 'I': case 'J':
- case 'K': case 'L': case 'M': case 'N': case 'O':
- case 'P': case 'Q': case 'R': case 'S': case 'T':
- case 'U': case 'V': case 'W': case 'X': case 'Y':
- case 'Z':
- case '[': case '\\': case ']': case '^': case '_':
- case 'a': case 'b': case 'c': case 'd': case 'e':
- case 'f': case 'g': case 'h': case 'i': case 'j':
- case 'k': case 'l': case 'm': case 'n': case 'o':
- case 'p': case 'q': case 'r': case 's': case 't':
- case 'u': case 'v': case 'w': case 'x': case 'y':
- case 'z': case '{': case '|': case '}': case '~':
- /* These characters are printable ASCII characters. */
- p++;
- width++;
- break;
- default:
- /* If we have a multibyte sequence, scan it up to its end. */
- {
- mbstate_t mbstate;
- memset (&mbstate, 0, sizeof mbstate);
- do
- {
- wchar_t wc;
- size_t bytes;
- int w;
-
- bytes = mbrtowc (&wc, p, plimit - p, &mbstate);
-
- if (bytes == (size_t) -1)
- /* An invalid multibyte sequence was encountered. */
- {
- if (!(flags & MBSW_REJECT_INVALID))
- {
- p++;
- width++;
- break;
- }
- else
- return -1;
- }
-
- if (bytes == (size_t) -2)
- /* An incomplete multibyte character at the end. */
- {
- if (!(flags & MBSW_REJECT_INVALID))
- {
- p = plimit;
- width++;
- break;
- }
- else
- return -1;
- }
-
- if (bytes == 0)
- /* A null wide character was encountered. */
- bytes = 1;
-
- w = wcwidth (wc);
- if (w >= 0)
- /* A printable multibyte character. */
- {
- if (w > INT_MAX - width)
- goto overflow;
- width += w;
- }
- else
- /* An unprintable multibyte character. */
- if (!(flags & MBSW_REJECT_UNPRINTABLE))
- {
- if (!iswcntrl (wc))
- {
- if (width == INT_MAX)
- goto overflow;
- width++;
- }
- }
- else
- return -1;
-
- p += bytes;
- }
- while (! mbsinit (&mbstate));
- }
- break;
- }
- return width;
- }
-
- while (p < plimit)
- {
- unsigned char c = (unsigned char) *p++;
-
- if (isprint (c))
- {
- if (width == INT_MAX)
- goto overflow;
- width++;
- }
- else if (!(flags & MBSW_REJECT_UNPRINTABLE))
- {
- if (!iscntrl (c))
- {
- if (width == INT_MAX)
- goto overflow;
- width++;
- }
- }
- else
- return -1;
- }
- return width;
-
- overflow:
- return INT_MAX;
-}
+
+/* Get iswcntrl(). */
+#include <wctype.h>
+
+/* Get INT_MAX. */
+#include <limits.h>
+
+/* Returns the number of columns needed to represent the multibyte
+ character string pointed to by STRING. If a non-printable character
+ occurs, and MBSW_REJECT_UNPRINTABLE is specified, -1 is returned.
+ With flags = MBSW_REJECT_INVALID | MBSW_REJECT_UNPRINTABLE, this is
+ the multibyte analogue of the wcswidth function. */
+int
+mbswidth (const char *string, int flags)
+{
+ return mbsnwidth (string, strlen (string), flags);
+}
+
+/* Returns the number of columns needed to represent the multibyte
+ character string pointed to by STRING of length NBYTES. If a
+ non-printable character occurs, and MBSW_REJECT_UNPRINTABLE is
+ specified, -1 is returned. */
+int
+mbsnwidth (const char *string, size_t nbytes, int flags)
+{
+ const char *p = string;
+ const char *plimit = p + nbytes;
+ int width;
+
+ width = 0;
+ if (MB_CUR_MAX > 1)
+ {
+ while (p < plimit)
+ switch (*p)
+ {
+ case ' ': case '!': case '"': case '#': case '%':
+ case '&': case '\'': case '(': case ')': case '*':
+ case '+': case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ case ':': case ';': case '<': case '=': case '>':
+ case '?':
+ case 'A': case 'B': case 'C': case 'D': case 'E':
+ case 'F': case 'G': case 'H': case 'I': case 'J':
+ case 'K': case 'L': case 'M': case 'N': case 'O':
+ case 'P': case 'Q': case 'R': case 'S': case 'T':
+ case 'U': case 'V': case 'W': case 'X': case 'Y':
+ case 'Z':
+ case '[': case '\\': case ']': case '^': case '_':
+ case 'a': case 'b': case 'c': case 'd': case 'e':
+ case 'f': case 'g': case 'h': case 'i': case 'j':
+ case 'k': case 'l': case 'm': case 'n': case 'o':
+ case 'p': case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x': case 'y':
+ case 'z': case '{': case '|': case '}': case '~':
+ /* These characters are printable ASCII characters. */
+ p++;
+ width++;
+ break;
+ default:
+ /* If we have a multibyte sequence, scan it up to its end. */
+ {
+ mbstate_t mbstate;
+ memset (&mbstate, 0, sizeof mbstate);
+ do
+ {
+ wchar_t wc;
+ size_t bytes;
+ int w;
+
+ bytes = mbrtowc (&wc, p, plimit - p, &mbstate);
+
+ if (bytes == (size_t) -1)
+ /* An invalid multibyte sequence was encountered. */
+ {
+ if (!(flags & MBSW_REJECT_INVALID))
+ {
+ p++;
+ width++;
+ break;
+ }
+ else
+ return -1;
+ }
+
+ if (bytes == (size_t) -2)
+ /* An incomplete multibyte character at the end. */
+ {
+ if (!(flags & MBSW_REJECT_INVALID))
+ {
+ p = plimit;
+ width++;
+ break;
+ }
+ else
+ return -1;
+ }
+
+ if (bytes == 0)
+ /* A null wide character was encountered. */
+ bytes = 1;
+
+ w = wcwidth (wc);
+ if (w >= 0)
+ /* A printable multibyte character. */
+ {
+ if (w > INT_MAX - width)
+ goto overflow;
+ width += w;
+ }
+ else
+ /* An unprintable multibyte character. */
+ if (!(flags & MBSW_REJECT_UNPRINTABLE))
+ {
+ if (!iswcntrl (wc))
+ {
+ if (width == INT_MAX)
+ goto overflow;
+ width++;
+ }
+ }
+ else
+ return -1;
+
+ p += bytes;
+ }
+ while (! mbsinit (&mbstate));
+ }
+ break;
+ }
+ return width;
+ }
+
+ while (p < plimit)
+ {
+ unsigned char c = (unsigned char) *p++;
+
+ if (isprint (c))
+ {
+ if (width == INT_MAX)
+ goto overflow;
+ width++;
+ }
+ else if (!(flags & MBSW_REJECT_UNPRINTABLE))
+ {
+ if (!iscntrl (c))
+ {
+ if (width == INT_MAX)
+ goto overflow;
+ width++;
+ }
+ }
+ else
+ return -1;
+ }
+ return width;
+
+ overflow:
+ return INT_MAX;
+}
diff --git a/contrib/tools/bison/gnulib/src/mbswidth.h b/contrib/tools/bison/gnulib/src/mbswidth.h
index e9c0b03938..9231c8efd4 100644
--- a/contrib/tools/bison/gnulib/src/mbswidth.h
+++ b/contrib/tools/bison/gnulib/src/mbswidth.h
@@ -1,60 +1,60 @@
-/* Determine the number of screen columns needed for a string.
- Copyright (C) 2000-2004, 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <stddef.h>
-
-/* Avoid a clash of our mbswidth() with a function of the same name defined
- in UnixWare 7.1.1 <wchar.h>. We need this #include before the #define
- below.
- However, we don't want to #include <wchar.h> on all platforms because
- - Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
- <wchar.h>.
- - BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
- <wchar.h>. */
-#if HAVE_DECL_MBSWIDTH_IN_WCHAR_H
-# include <wchar.h>
-#endif
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Optional flags to influence mbswidth/mbsnwidth behavior. */
-
-/* If this bit is set, return -1 upon finding an invalid or incomplete
- character. Otherwise, assume invalid characters have width 1. */
-#define MBSW_REJECT_INVALID 1
-
-/* If this bit is set, return -1 upon finding a non-printable character.
- Otherwise, assume unprintable characters have width 0 if they are
- control characters and 1 otherwise. */
-#define MBSW_REJECT_UNPRINTABLE 2
-
-
-/* Returns the number of screen columns needed for STRING. */
-#define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */
-extern int mbswidth (const char *string, int flags);
-
-/* Returns the number of screen columns needed for the NBYTES bytes
- starting at BUF. */
-extern int mbsnwidth (const char *buf, size_t nbytes, int flags);
-
-
-#ifdef __cplusplus
-}
-#endif
+/* Determine the number of screen columns needed for a string.
+ Copyright (C) 2000-2004, 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+
+/* Avoid a clash of our mbswidth() with a function of the same name defined
+ in UnixWare 7.1.1 <wchar.h>. We need this #include before the #define
+ below.
+ However, we don't want to #include <wchar.h> on all platforms because
+ - Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ - BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
+ <wchar.h>. */
+#if HAVE_DECL_MBSWIDTH_IN_WCHAR_H
+# include <wchar.h>
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Optional flags to influence mbswidth/mbsnwidth behavior. */
+
+/* If this bit is set, return -1 upon finding an invalid or incomplete
+ character. Otherwise, assume invalid characters have width 1. */
+#define MBSW_REJECT_INVALID 1
+
+/* If this bit is set, return -1 upon finding a non-printable character.
+ Otherwise, assume unprintable characters have width 0 if they are
+ control characters and 1 otherwise. */
+#define MBSW_REJECT_UNPRINTABLE 2
+
+
+/* Returns the number of screen columns needed for STRING. */
+#define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */
+extern int mbswidth (const char *string, int flags);
+
+/* Returns the number of screen columns needed for the NBYTES bytes
+ starting at BUF. */
+extern int mbsnwidth (const char *buf, size_t nbytes, int flags);
+
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/mbtowc-impl.h b/contrib/tools/bison/gnulib/src/mbtowc-impl.h
index 767ab397ce..0c14eacbbc 100644
--- a/contrib/tools/bison/gnulib/src/mbtowc-impl.h
+++ b/contrib/tools/bison/gnulib/src/mbtowc-impl.h
@@ -1,44 +1,44 @@
-/* Convert multibyte character to wide character.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2011.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* We don't need a static internal state, because the encoding is not state
- dependent, and when mbrtowc returns (size_t)(-2). we throw the result
- away. */
-
-int
-mbtowc (wchar_t *pwc, const char *s, size_t n)
-{
- if (s == NULL)
- return 0;
- else
- {
- mbstate_t state;
- wchar_t wc;
- size_t result;
-
- memset (&state, 0, sizeof (mbstate_t));
- result = mbrtowc (&wc, s, n, &state);
- if (result == (size_t)-1 || result == (size_t)-2)
- {
- errno = EILSEQ;
- return -1;
- }
- if (pwc != NULL)
- *pwc = wc;
- return (wc == 0 ? 0 : result);
- }
-}
+/* Convert multibyte character to wide character.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* We don't need a static internal state, because the encoding is not state
+ dependent, and when mbrtowc returns (size_t)(-2). we throw the result
+ away. */
+
+int
+mbtowc (wchar_t *pwc, const char *s, size_t n)
+{
+ if (s == NULL)
+ return 0;
+ else
+ {
+ mbstate_t state;
+ wchar_t wc;
+ size_t result;
+
+ memset (&state, 0, sizeof (mbstate_t));
+ result = mbrtowc (&wc, s, n, &state);
+ if (result == (size_t)-1 || result == (size_t)-2)
+ {
+ errno = EILSEQ;
+ return -1;
+ }
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == 0 ? 0 : result);
+ }
+}
diff --git a/contrib/tools/bison/gnulib/src/mbtowc.c b/contrib/tools/bison/gnulib/src/mbtowc.c
index 632f2e1db8..8904fa393d 100644
--- a/contrib/tools/bison/gnulib/src/mbtowc.c
+++ b/contrib/tools/bison/gnulib/src/mbtowc.c
@@ -1,26 +1,26 @@
-/* Convert multibyte character to wide character.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2011.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include <stdlib.h>
-
-#include <errno.h>
-#include <string.h>
-#include <wchar.h>
-
-#include "mbtowc-impl.h"
+/* Convert multibyte character to wide character.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#include <errno.h>
+#include <string.h>
+#include <wchar.h>
+
+#include "mbtowc-impl.h"
diff --git a/contrib/tools/bison/gnulib/src/memchr.c b/contrib/tools/bison/gnulib/src/memchr.c
index 3db38a94cd..0e90a114e7 100644
--- a/contrib/tools/bison/gnulib/src/memchr.c
+++ b/contrib/tools/bison/gnulib/src/memchr.c
@@ -1,172 +1,172 @@
-/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2013
- Free Software Foundation, Inc.
-
- Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
- with help from Dan Sahlin (dan@sics.se) and
- commentary by Jim Blandy (jimb@ai.mit.edu);
- adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
- and implemented by Roland McGrath (roland@ai.mit.edu).
-
-NOTE: The canonical source of this file is maintained with the GNU C Library.
-Bugs can be reported to bug-glibc@prep.ai.mit.edu.
-
-This program is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 3 of the License, or any
-later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC
-# include <config.h>
-#endif
-
-#include <string.h>
-
-#include <stddef.h>
-
-#if defined _LIBC
-# include <memcopy.h>
-#else
-# define reg_char char
-#endif
-
-#include <limits.h>
-
-#if HAVE_BP_SYM_H || defined _LIBC
-# include <bp-sym.h>
-#else
-# define BP_SYM(sym) sym
-#endif
-
-#undef __memchr
-#ifdef _LIBC
-# undef memchr
-#endif
-
-#ifndef weak_alias
-# define __memchr memchr
-#endif
-
-/* Search no more than N bytes of S for C. */
-void *
-__memchr (void const *s, int c_in, size_t n)
-{
- /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
- long instead of a 64-bit uintmax_t tends to give better
- performance. On 64-bit hardware, unsigned long is generally 64
- bits already. Change this typedef to experiment with
- performance. */
- typedef unsigned long int longword;
-
- const unsigned char *char_ptr;
- const longword *longword_ptr;
- longword repeated_one;
- longword repeated_c;
- unsigned reg_char c;
-
- c = (unsigned char) c_in;
-
- /* Handle the first few bytes by reading one byte at a time.
- Do this until CHAR_PTR is aligned on a longword boundary. */
- for (char_ptr = (const unsigned char *) s;
- n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
- --n, ++char_ptr)
- if (*char_ptr == c)
- return (void *) char_ptr;
-
- longword_ptr = (const longword *) char_ptr;
-
- /* All these elucidatory comments refer to 4-byte longwords,
- but the theory applies equally well to any size longwords. */
-
- /* Compute auxiliary longword values:
- repeated_one is a value which has a 1 in every byte.
- repeated_c has c in every byte. */
- repeated_one = 0x01010101;
- repeated_c = c | (c << 8);
- repeated_c |= repeated_c << 16;
- if (0xffffffffU < (longword) -1)
- {
- repeated_one |= repeated_one << 31 << 1;
- repeated_c |= repeated_c << 31 << 1;
- if (8 < sizeof (longword))
- {
- size_t i;
-
- for (i = 64; i < sizeof (longword) * 8; i *= 2)
- {
- repeated_one |= repeated_one << i;
- repeated_c |= repeated_c << i;
- }
- }
- }
-
- /* Instead of the traditional loop which tests each byte, we will test a
- longword at a time. The tricky part is testing if *any of the four*
- bytes in the longword in question are equal to c. We first use an xor
- with repeated_c. This reduces the task to testing whether *any of the
- four* bytes in longword1 is zero.
-
- We compute tmp =
- ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
- That is, we perform the following operations:
- 1. Subtract repeated_one.
- 2. & ~longword1.
- 3. & a mask consisting of 0x80 in every byte.
- Consider what happens in each byte:
- - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
- and step 3 transforms it into 0x80. A carry can also be propagated
- to more significant bytes.
- - If a byte of longword1 is nonzero, let its lowest 1 bit be at
- position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
- the byte ends in a single bit of value 0 and k bits of value 1.
- After step 2, the result is just k bits of value 1: 2^k - 1. After
- step 3, the result is 0. And no carry is produced.
- So, if longword1 has only non-zero bytes, tmp is zero.
- Whereas if longword1 has a zero byte, call j the position of the least
- significant zero byte. Then the result has a zero at positions 0, ...,
- j-1 and a 0x80 at position j. We cannot predict the result at the more
- significant bytes (positions j+1..3), but it does not matter since we
- already have a non-zero bit at position 8*j+7.
-
- So, the test whether any byte in longword1 is zero is equivalent to
- testing whether tmp is nonzero. */
-
- while (n >= sizeof (longword))
- {
- longword longword1 = *longword_ptr ^ repeated_c;
-
- if ((((longword1 - repeated_one) & ~longword1)
- & (repeated_one << 7)) != 0)
- break;
- longword_ptr++;
- n -= sizeof (longword);
- }
-
- char_ptr = (const unsigned char *) longword_ptr;
-
- /* At this point, we know that either n < sizeof (longword), or one of the
- sizeof (longword) bytes starting at char_ptr is == c. On little-endian
- machines, we could determine the first such byte without any further
- memory accesses, just by looking at the tmp result from the last loop
- iteration. But this does not work on big-endian machines. Choose code
- that works in both cases. */
-
- for (; n > 0; --n, ++char_ptr)
- {
- if (*char_ptr == c)
- return (void *) char_ptr;
- }
-
- return NULL;
-}
-#ifdef weak_alias
-weak_alias (__memchr, BP_SYM (memchr))
-#endif
+/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2013
+ Free Software Foundation, Inc.
+
+ Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
+ with help from Dan Sahlin (dan@sics.se) and
+ commentary by Jim Blandy (jimb@ai.mit.edu);
+ adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
+ and implemented by Roland McGrath (roland@ai.mit.edu).
+
+NOTE: The canonical source of this file is maintained with the GNU C Library.
+Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LIBC
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#include <stddef.h>
+
+#if defined _LIBC
+# include <memcopy.h>
+#else
+# define reg_char char
+#endif
+
+#include <limits.h>
+
+#if HAVE_BP_SYM_H || defined _LIBC
+# include <bp-sym.h>
+#else
+# define BP_SYM(sym) sym
+#endif
+
+#undef __memchr
+#ifdef _LIBC
+# undef memchr
+#endif
+
+#ifndef weak_alias
+# define __memchr memchr
+#endif
+
+/* Search no more than N bytes of S for C. */
+void *
+__memchr (void const *s, int c_in, size_t n)
+{
+ /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
+ long instead of a 64-bit uintmax_t tends to give better
+ performance. On 64-bit hardware, unsigned long is generally 64
+ bits already. Change this typedef to experiment with
+ performance. */
+ typedef unsigned long int longword;
+
+ const unsigned char *char_ptr;
+ const longword *longword_ptr;
+ longword repeated_one;
+ longword repeated_c;
+ unsigned reg_char c;
+
+ c = (unsigned char) c_in;
+
+ /* Handle the first few bytes by reading one byte at a time.
+ Do this until CHAR_PTR is aligned on a longword boundary. */
+ for (char_ptr = (const unsigned char *) s;
+ n > 0 && (size_t) char_ptr % sizeof (longword) != 0;
+ --n, ++char_ptr)
+ if (*char_ptr == c)
+ return (void *) char_ptr;
+
+ longword_ptr = (const longword *) char_ptr;
+
+ /* All these elucidatory comments refer to 4-byte longwords,
+ but the theory applies equally well to any size longwords. */
+
+ /* Compute auxiliary longword values:
+ repeated_one is a value which has a 1 in every byte.
+ repeated_c has c in every byte. */
+ repeated_one = 0x01010101;
+ repeated_c = c | (c << 8);
+ repeated_c |= repeated_c << 16;
+ if (0xffffffffU < (longword) -1)
+ {
+ repeated_one |= repeated_one << 31 << 1;
+ repeated_c |= repeated_c << 31 << 1;
+ if (8 < sizeof (longword))
+ {
+ size_t i;
+
+ for (i = 64; i < sizeof (longword) * 8; i *= 2)
+ {
+ repeated_one |= repeated_one << i;
+ repeated_c |= repeated_c << i;
+ }
+ }
+ }
+
+ /* Instead of the traditional loop which tests each byte, we will test a
+ longword at a time. The tricky part is testing if *any of the four*
+ bytes in the longword in question are equal to c. We first use an xor
+ with repeated_c. This reduces the task to testing whether *any of the
+ four* bytes in longword1 is zero.
+
+ We compute tmp =
+ ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+ That is, we perform the following operations:
+ 1. Subtract repeated_one.
+ 2. & ~longword1.
+ 3. & a mask consisting of 0x80 in every byte.
+ Consider what happens in each byte:
+ - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+ and step 3 transforms it into 0x80. A carry can also be propagated
+ to more significant bytes.
+ - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+ position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
+ the byte ends in a single bit of value 0 and k bits of value 1.
+ After step 2, the result is just k bits of value 1: 2^k - 1. After
+ step 3, the result is 0. And no carry is produced.
+ So, if longword1 has only non-zero bytes, tmp is zero.
+ Whereas if longword1 has a zero byte, call j the position of the least
+ significant zero byte. Then the result has a zero at positions 0, ...,
+ j-1 and a 0x80 at position j. We cannot predict the result at the more
+ significant bytes (positions j+1..3), but it does not matter since we
+ already have a non-zero bit at position 8*j+7.
+
+ So, the test whether any byte in longword1 is zero is equivalent to
+ testing whether tmp is nonzero. */
+
+ while (n >= sizeof (longword))
+ {
+ longword longword1 = *longword_ptr ^ repeated_c;
+
+ if ((((longword1 - repeated_one) & ~longword1)
+ & (repeated_one << 7)) != 0)
+ break;
+ longword_ptr++;
+ n -= sizeof (longword);
+ }
+
+ char_ptr = (const unsigned char *) longword_ptr;
+
+ /* At this point, we know that either n < sizeof (longword), or one of the
+ sizeof (longword) bytes starting at char_ptr is == c. On little-endian
+ machines, we could determine the first such byte without any further
+ memory accesses, just by looking at the tmp result from the last loop
+ iteration. But this does not work on big-endian machines. Choose code
+ that works in both cases. */
+
+ for (; n > 0; --n, ++char_ptr)
+ {
+ if (*char_ptr == c)
+ return (void *) char_ptr;
+ }
+
+ return NULL;
+}
+#ifdef weak_alias
+weak_alias (__memchr, BP_SYM (memchr))
+#endif
diff --git a/contrib/tools/bison/gnulib/src/memchr2.c b/contrib/tools/bison/gnulib/src/memchr2.c
index 8b105b7f27..d99cc693b2 100644
--- a/contrib/tools/bison/gnulib/src/memchr2.c
+++ b/contrib/tools/bison/gnulib/src/memchr2.c
@@ -1,169 +1,169 @@
-/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2013
- Free Software Foundation, Inc.
-
- Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
- with help from Dan Sahlin (dan@sics.se) and
- commentary by Jim Blandy (jimb@ai.mit.edu);
- adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
- and implemented in glibc by Roland McGrath (roland@ai.mit.edu).
- Extension to memchr2 implemented by Eric Blake (ebb9@byu.net).
-
-This program is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 3 of the License, or any
-later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "memchr2.h"
-
-#include <limits.h>
-#include <stdint.h>
-#include <string.h>
-
-/* Return the first address of either C1 or C2 (treated as unsigned
- char) that occurs within N bytes of the memory region S. If
- neither byte appears, return NULL. */
-void *
-memchr2 (void const *s, int c1_in, int c2_in, size_t n)
-{
- /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
- long instead of a 64-bit uintmax_t tends to give better
- performance. On 64-bit hardware, unsigned long is generally 64
- bits already. Change this typedef to experiment with
- performance. */
- typedef unsigned long int longword;
-
- const unsigned char *char_ptr;
- void const *void_ptr;
- const longword *longword_ptr;
- longword repeated_one;
- longword repeated_c1;
- longword repeated_c2;
- unsigned char c1;
- unsigned char c2;
-
- c1 = (unsigned char) c1_in;
- c2 = (unsigned char) c2_in;
-
- if (c1 == c2)
- return memchr (s, c1, n);
-
- /* Handle the first few bytes by reading one byte at a time.
- Do this until VOID_PTR is aligned on a longword boundary. */
- for (void_ptr = s;
- n > 0 && (uintptr_t) void_ptr % sizeof (longword) != 0;
- --n)
- {
- char_ptr = void_ptr;
- if (*char_ptr == c1 || *char_ptr == c2)
- return (void *) void_ptr;
- void_ptr = char_ptr + 1;
- }
-
- longword_ptr = void_ptr;
-
- /* All these elucidatory comments refer to 4-byte longwords,
- but the theory applies equally well to any size longwords. */
-
- /* Compute auxiliary longword values:
- repeated_one is a value which has a 1 in every byte.
- repeated_c1 has c1 in every byte.
- repeated_c2 has c2 in every byte. */
- repeated_one = 0x01010101;
- repeated_c1 = c1 | (c1 << 8);
- repeated_c2 = c2 | (c2 << 8);
- repeated_c1 |= repeated_c1 << 16;
- repeated_c2 |= repeated_c2 << 16;
- if (0xffffffffU < (longword) -1)
- {
- repeated_one |= repeated_one << 31 << 1;
- repeated_c1 |= repeated_c1 << 31 << 1;
- repeated_c2 |= repeated_c2 << 31 << 1;
- if (8 < sizeof (longword))
- {
- size_t i;
-
- for (i = 64; i < sizeof (longword) * 8; i *= 2)
- {
- repeated_one |= repeated_one << i;
- repeated_c1 |= repeated_c1 << i;
- repeated_c2 |= repeated_c2 << i;
- }
- }
- }
-
- /* Instead of the traditional loop which tests each byte, we will test a
- longword at a time. The tricky part is testing if *any of the four*
- bytes in the longword in question are equal to c1 or c2. We first use
- an xor with repeated_c1 and repeated_c2, respectively. This reduces
- the task to testing whether *any of the four* bytes in longword1 or
- longword2 is zero.
-
- Let's consider longword1. We compute tmp1 =
- ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
- That is, we perform the following operations:
- 1. Subtract repeated_one.
- 2. & ~longword1.
- 3. & a mask consisting of 0x80 in every byte.
- Consider what happens in each byte:
- - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
- and step 3 transforms it into 0x80. A carry can also be propagated
- to more significant bytes.
- - If a byte of longword1 is nonzero, let its lowest 1 bit be at
- position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
- the byte ends in a single bit of value 0 and k bits of value 1.
- After step 2, the result is just k bits of value 1: 2^k - 1. After
- step 3, the result is 0. And no carry is produced.
- So, if longword1 has only non-zero bytes, tmp1 is zero.
- Whereas if longword1 has a zero byte, call j the position of the least
- significant zero byte. Then the result has a zero at positions 0, ...,
- j-1 and a 0x80 at position j. We cannot predict the result at the more
- significant bytes (positions j+1..3), but it does not matter since we
- already have a non-zero bit at position 8*j+7.
-
- Similarly, we compute tmp2 =
- ((longword2 - repeated_one) & ~longword2) & (repeated_one << 7).
-
- The test whether any byte in longword1 or longword2 is zero is equivalent
- to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine
- this into a single test, whether (tmp1 | tmp2) is nonzero. */
-
- while (n >= sizeof (longword))
- {
- longword longword1 = *longword_ptr ^ repeated_c1;
- longword longword2 = *longword_ptr ^ repeated_c2;
-
- if (((((longword1 - repeated_one) & ~longword1)
- | ((longword2 - repeated_one) & ~longword2))
- & (repeated_one << 7)) != 0)
- break;
- longword_ptr++;
- n -= sizeof (longword);
- }
-
- char_ptr = (const unsigned char *) longword_ptr;
-
- /* At this point, we know that either n < sizeof (longword), or one of the
- sizeof (longword) bytes starting at char_ptr is == c1 or == c2. On
- little-endian machines, we could determine the first such byte without
- any further memory accesses, just by looking at the (tmp1 | tmp2) result
- from the last loop iteration. But this does not work on big-endian
- machines. Choose code that works in both cases. */
-
- for (; n > 0; --n, ++char_ptr)
- {
- if (*char_ptr == c1 || *char_ptr == c2)
- return (void *) char_ptr;
- }
-
- return NULL;
-}
+/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2013
+ Free Software Foundation, Inc.
+
+ Based on strlen implementation by Torbjorn Granlund (tege@sics.se),
+ with help from Dan Sahlin (dan@sics.se) and
+ commentary by Jim Blandy (jimb@ai.mit.edu);
+ adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
+ and implemented in glibc by Roland McGrath (roland@ai.mit.edu).
+ Extension to memchr2 implemented by Eric Blake (ebb9@byu.net).
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or any
+later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "memchr2.h"
+
+#include <limits.h>
+#include <stdint.h>
+#include <string.h>
+
+/* Return the first address of either C1 or C2 (treated as unsigned
+ char) that occurs within N bytes of the memory region S. If
+ neither byte appears, return NULL. */
+void *
+memchr2 (void const *s, int c1_in, int c2_in, size_t n)
+{
+ /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
+ long instead of a 64-bit uintmax_t tends to give better
+ performance. On 64-bit hardware, unsigned long is generally 64
+ bits already. Change this typedef to experiment with
+ performance. */
+ typedef unsigned long int longword;
+
+ const unsigned char *char_ptr;
+ void const *void_ptr;
+ const longword *longword_ptr;
+ longword repeated_one;
+ longword repeated_c1;
+ longword repeated_c2;
+ unsigned char c1;
+ unsigned char c2;
+
+ c1 = (unsigned char) c1_in;
+ c2 = (unsigned char) c2_in;
+
+ if (c1 == c2)
+ return memchr (s, c1, n);
+
+ /* Handle the first few bytes by reading one byte at a time.
+ Do this until VOID_PTR is aligned on a longword boundary. */
+ for (void_ptr = s;
+ n > 0 && (uintptr_t) void_ptr % sizeof (longword) != 0;
+ --n)
+ {
+ char_ptr = void_ptr;
+ if (*char_ptr == c1 || *char_ptr == c2)
+ return (void *) void_ptr;
+ void_ptr = char_ptr + 1;
+ }
+
+ longword_ptr = void_ptr;
+
+ /* All these elucidatory comments refer to 4-byte longwords,
+ but the theory applies equally well to any size longwords. */
+
+ /* Compute auxiliary longword values:
+ repeated_one is a value which has a 1 in every byte.
+ repeated_c1 has c1 in every byte.
+ repeated_c2 has c2 in every byte. */
+ repeated_one = 0x01010101;
+ repeated_c1 = c1 | (c1 << 8);
+ repeated_c2 = c2 | (c2 << 8);
+ repeated_c1 |= repeated_c1 << 16;
+ repeated_c2 |= repeated_c2 << 16;
+ if (0xffffffffU < (longword) -1)
+ {
+ repeated_one |= repeated_one << 31 << 1;
+ repeated_c1 |= repeated_c1 << 31 << 1;
+ repeated_c2 |= repeated_c2 << 31 << 1;
+ if (8 < sizeof (longword))
+ {
+ size_t i;
+
+ for (i = 64; i < sizeof (longword) * 8; i *= 2)
+ {
+ repeated_one |= repeated_one << i;
+ repeated_c1 |= repeated_c1 << i;
+ repeated_c2 |= repeated_c2 << i;
+ }
+ }
+ }
+
+ /* Instead of the traditional loop which tests each byte, we will test a
+ longword at a time. The tricky part is testing if *any of the four*
+ bytes in the longword in question are equal to c1 or c2. We first use
+ an xor with repeated_c1 and repeated_c2, respectively. This reduces
+ the task to testing whether *any of the four* bytes in longword1 or
+ longword2 is zero.
+
+ Let's consider longword1. We compute tmp1 =
+ ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+ That is, we perform the following operations:
+ 1. Subtract repeated_one.
+ 2. & ~longword1.
+ 3. & a mask consisting of 0x80 in every byte.
+ Consider what happens in each byte:
+ - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+ and step 3 transforms it into 0x80. A carry can also be propagated
+ to more significant bytes.
+ - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+ position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
+ the byte ends in a single bit of value 0 and k bits of value 1.
+ After step 2, the result is just k bits of value 1: 2^k - 1. After
+ step 3, the result is 0. And no carry is produced.
+ So, if longword1 has only non-zero bytes, tmp1 is zero.
+ Whereas if longword1 has a zero byte, call j the position of the least
+ significant zero byte. Then the result has a zero at positions 0, ...,
+ j-1 and a 0x80 at position j. We cannot predict the result at the more
+ significant bytes (positions j+1..3), but it does not matter since we
+ already have a non-zero bit at position 8*j+7.
+
+ Similarly, we compute tmp2 =
+ ((longword2 - repeated_one) & ~longword2) & (repeated_one << 7).
+
+ The test whether any byte in longword1 or longword2 is zero is equivalent
+ to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine
+ this into a single test, whether (tmp1 | tmp2) is nonzero. */
+
+ while (n >= sizeof (longword))
+ {
+ longword longword1 = *longword_ptr ^ repeated_c1;
+ longword longword2 = *longword_ptr ^ repeated_c2;
+
+ if (((((longword1 - repeated_one) & ~longword1)
+ | ((longword2 - repeated_one) & ~longword2))
+ & (repeated_one << 7)) != 0)
+ break;
+ longword_ptr++;
+ n -= sizeof (longword);
+ }
+
+ char_ptr = (const unsigned char *) longword_ptr;
+
+ /* At this point, we know that either n < sizeof (longword), or one of the
+ sizeof (longword) bytes starting at char_ptr is == c1 or == c2. On
+ little-endian machines, we could determine the first such byte without
+ any further memory accesses, just by looking at the (tmp1 | tmp2) result
+ from the last loop iteration. But this does not work on big-endian
+ machines. Choose code that works in both cases. */
+
+ for (; n > 0; --n, ++char_ptr)
+ {
+ if (*char_ptr == c1 || *char_ptr == c2)
+ return (void *) char_ptr;
+ }
+
+ return NULL;
+}
diff --git a/contrib/tools/bison/gnulib/src/memchr2.h b/contrib/tools/bison/gnulib/src/memchr2.h
index cc04889f12..cb6e1934e4 100644
--- a/contrib/tools/bison/gnulib/src/memchr2.h
+++ b/contrib/tools/bison/gnulib/src/memchr2.h
@@ -1,32 +1,32 @@
-/* Scan memory for the first of two bytes.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Return the first address of either C1 or C2 (treated as unsigned
- char) that occurs within N bytes of the memory region S. If
- neither byte appears, return NULL. */
-
-extern void *memchr2 (void const *s, int c1, int c2, size_t n)
- _GL_ATTRIBUTE_PURE;
-
-#ifdef __cplusplus
-}
-#endif
+/* Scan memory for the first of two bytes.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Return the first address of either C1 or C2 (treated as unsigned
+ char) that occurs within N bytes of the memory region S. If
+ neither byte appears, return NULL. */
+
+extern void *memchr2 (void const *s, int c1, int c2, size_t n)
+ _GL_ATTRIBUTE_PURE;
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/mkdtemp.c b/contrib/tools/bison/gnulib/src/mkdtemp.c
index 6ba8b65d52..5ad8ca997e 100644
--- a/contrib/tools/bison/gnulib/src/mkdtemp.c
+++ b/contrib/tools/bison/gnulib/src/mkdtemp.c
@@ -1,39 +1,39 @@
-/* Copyright (C) 1999, 2001-2003, 2006-2007, 2009-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Extracted from misc/mkdtemp.c. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdlib.h>
-
-#include "tempname.h"
-
-/* Generate a unique temporary directory from XTEMPLATE.
- The last six characters of XTEMPLATE must be "XXXXXX";
- they are replaced with a string that makes the filename unique.
- The directory is created, mode 700, and its name is returned.
- (This function comes from OpenBSD.) */
-char *
-mkdtemp (char *xtemplate)
-{
- if (gen_tempname (xtemplate, 0, 0, GT_DIR))
- return NULL;
- else
- return xtemplate;
-}
+/* Copyright (C) 1999, 2001-2003, 2006-2007, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Extracted from misc/mkdtemp.c. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdlib.h>
+
+#include "tempname.h"
+
+/* Generate a unique temporary directory from XTEMPLATE.
+ The last six characters of XTEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the filename unique.
+ The directory is created, mode 700, and its name is returned.
+ (This function comes from OpenBSD.) */
+char *
+mkdtemp (char *xtemplate)
+{
+ if (gen_tempname (xtemplate, 0, 0, GT_DIR))
+ return NULL;
+ else
+ return xtemplate;
+}
diff --git a/contrib/tools/bison/gnulib/src/mkstemp-safer.c b/contrib/tools/bison/gnulib/src/mkstemp-safer.c
index 9ddf86fb60..0793f4de75 100644
--- a/contrib/tools/bison/gnulib/src/mkstemp-safer.c
+++ b/contrib/tools/bison/gnulib/src/mkstemp-safer.c
@@ -1,64 +1,64 @@
-/* Invoke mkstemp, but avoid some glitches.
-
- Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <config.h>
-
-#include "stdlib-safer.h"
-
+/* Invoke mkstemp, but avoid some glitches.
+
+ Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <config.h>
+
+#include "stdlib-safer.h"
+
#include "stdlib--.h"
-#include "unistd-safer.h"
-
-
-/* Like mkstemp, but do not return STDIN_FILENO, STDOUT_FILENO, or
- STDERR_FILENO. */
-
-int
-mkstemp_safer (char *templ)
-{
- return fd_safer (mkstemp (templ));
-}
-
-#if GNULIB_MKOSTEMP
-/* Like mkostemp, but do not return STDIN_FILENO, STDOUT_FILENO, or
- STDERR_FILENO. */
-int
-mkostemp_safer (char *templ, int flags)
-{
- return fd_safer_flag (mkostemp (templ, flags), flags);
-}
-#endif
-
-#if GNULIB_MKOSTEMPS
-/* Like mkostemps, but do not return STDIN_FILENO, STDOUT_FILENO, or
- STDERR_FILENO. */
-int
-mkostemps_safer (char *templ, int suffixlen, int flags)
-{
- return fd_safer_flag (mkostemps (templ, suffixlen, flags), flags);
-}
-#endif
+#include "unistd-safer.h"
+
-#if GNULIB_MKSTEMPS
-/* Like mkstemps, but do not return STDIN_FILENO, STDOUT_FILENO, or
- STDERR_FILENO. */
-int mkstemps_safer (char *templ, int suffixlen)
-{
- return fd_safer (mkstemps (templ, suffixlen));
-}
-#endif
+/* Like mkstemp, but do not return STDIN_FILENO, STDOUT_FILENO, or
+ STDERR_FILENO. */
+
+int
+mkstemp_safer (char *templ)
+{
+ return fd_safer (mkstemp (templ));
+}
+
+#if GNULIB_MKOSTEMP
+/* Like mkostemp, but do not return STDIN_FILENO, STDOUT_FILENO, or
+ STDERR_FILENO. */
+int
+mkostemp_safer (char *templ, int flags)
+{
+ return fd_safer_flag (mkostemp (templ, flags), flags);
+}
+#endif
+
+#if GNULIB_MKOSTEMPS
+/* Like mkostemps, but do not return STDIN_FILENO, STDOUT_FILENO, or
+ STDERR_FILENO. */
+int
+mkostemps_safer (char *templ, int suffixlen, int flags)
+{
+ return fd_safer_flag (mkostemps (templ, suffixlen, flags), flags);
+}
+#endif
+
+#if GNULIB_MKSTEMPS
+/* Like mkstemps, but do not return STDIN_FILENO, STDOUT_FILENO, or
+ STDERR_FILENO. */
+int mkstemps_safer (char *templ, int suffixlen)
+{
+ return fd_safer (mkstemps (templ, suffixlen));
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/mkstemp.c b/contrib/tools/bison/gnulib/src/mkstemp.c
index 7a9af6c8cc..e36b1a3357 100644
--- a/contrib/tools/bison/gnulib/src/mkstemp.c
+++ b/contrib/tools/bison/gnulib/src/mkstemp.c
@@ -1,50 +1,50 @@
-/* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2013 Free Software
- Foundation, Inc.
- This file is derived from the one in the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if !_LIBC
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-
-#if !_LIBC
-# include "tempname.h"
-# define __gen_tempname gen_tempname
-# ifndef __GT_FILE
-# define __GT_FILE GT_FILE
-# endif
-#endif
-
-#include <stdio.h>
-
-#ifndef __GT_FILE
-# define __GT_FILE 0
-#endif
-
-/* Generate a unique temporary file name from XTEMPLATE.
- The last six characters of XTEMPLATE must be "XXXXXX";
- they are replaced with a string that makes the file name unique.
- Then open the file and return a fd.
-
- If you are creating temporary files which will later be removed,
- consider using the clean-temp module, which avoids several pitfalls
- of using mkstemp directly. */
-int
-mkstemp (char *xtemplate)
-{
- return __gen_tempname (xtemplate, 0, 0, __GT_FILE);
-}
+/* Copyright (C) 1998-1999, 2001, 2005-2007, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is derived from the one in the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if !_LIBC
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#if !_LIBC
+# include "tempname.h"
+# define __gen_tempname gen_tempname
+# ifndef __GT_FILE
+# define __GT_FILE GT_FILE
+# endif
+#endif
+
+#include <stdio.h>
+
+#ifndef __GT_FILE
+# define __GT_FILE 0
+#endif
+
+/* Generate a unique temporary file name from XTEMPLATE.
+ The last six characters of XTEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the file name unique.
+ Then open the file and return a fd.
+
+ If you are creating temporary files which will later be removed,
+ consider using the clean-temp module, which avoids several pitfalls
+ of using mkstemp directly. */
+int
+mkstemp (char *xtemplate)
+{
+ return __gen_tempname (xtemplate, 0, 0, __GT_FILE);
+}
diff --git a/contrib/tools/bison/gnulib/src/msvc-inval.c b/contrib/tools/bison/gnulib/src/msvc-inval.c
index 396031e4c2..44da6d49a6 100644
--- a/contrib/tools/bison/gnulib/src/msvc-inval.c
+++ b/contrib/tools/bison/gnulib/src/msvc-inval.c
@@ -1,129 +1,129 @@
-/* Invalid parameter handler for MSVC runtime libraries.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "msvc-inval.h"
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
- && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
-
-/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
- declaration. */
-# include <stdlib.h>
-
-# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
-
-static void __cdecl
-gl_msvc_invalid_parameter_handler (const wchar_t *expression,
- const wchar_t *function,
- const wchar_t *file,
- unsigned int line,
- uintptr_t dummy)
-{
-}
-
-# else
-
-/* Get declarations of the native Windows API functions. */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-
-# if defined _MSC_VER
-
-static void __cdecl
-gl_msvc_invalid_parameter_handler (const wchar_t *expression,
- const wchar_t *function,
- const wchar_t *file,
- unsigned int line,
- uintptr_t dummy)
-{
- RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
-}
-
-# else
-
-/* An index to thread-local storage. */
-static DWORD tls_index;
-static int tls_initialized /* = 0 */;
-
-/* Used as a fallback only. */
-static struct gl_msvc_inval_per_thread not_per_thread;
-
-struct gl_msvc_inval_per_thread *
-gl_msvc_inval_current (void)
-{
- if (!tls_initialized)
- {
- tls_index = TlsAlloc ();
- tls_initialized = 1;
- }
- if (tls_index == TLS_OUT_OF_INDEXES)
- /* TlsAlloc had failed. */
- return &not_per_thread;
- else
- {
- struct gl_msvc_inval_per_thread *pointer =
- (struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
- if (pointer == NULL)
- {
- /* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */
- pointer =
- (struct gl_msvc_inval_per_thread *)
- malloc (sizeof (struct gl_msvc_inval_per_thread));
- if (pointer == NULL)
- /* Could not allocate memory. Use the global storage. */
- pointer = &not_per_thread;
- TlsSetValue (tls_index, pointer);
- }
- return pointer;
- }
-}
-
-static void __cdecl
-gl_msvc_invalid_parameter_handler (const wchar_t *expression,
- const wchar_t *function,
- const wchar_t *file,
- unsigned int line,
- uintptr_t dummy)
-{
- struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
- if (current->restart_valid)
- longjmp (current->restart, 1);
- else
- /* An invalid parameter notification from outside the gnulib code.
- Give the caller a chance to intervene. */
- RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
-}
-
-# endif
-
-# endif
-
-static int gl_msvc_inval_initialized /* = 0 */;
-
-void
-gl_msvc_inval_ensure_handler (void)
-{
- if (gl_msvc_inval_initialized == 0)
- {
- _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
- gl_msvc_inval_initialized = 1;
- }
-}
-
-#endif
+/* Invalid parameter handler for MSVC runtime libraries.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "msvc-inval.h"
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+ && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
+
+/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
+ declaration. */
+# include <stdlib.h>
+
+# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+
+static void __cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+ const wchar_t *function,
+ const wchar_t *file,
+ unsigned int line,
+ uintptr_t dummy)
+{
+}
+
+# else
+
+/* Get declarations of the native Windows API functions. */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+# if defined _MSC_VER
+
+static void __cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+ const wchar_t *function,
+ const wchar_t *file,
+ unsigned int line,
+ uintptr_t dummy)
+{
+ RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
+}
+
+# else
+
+/* An index to thread-local storage. */
+static DWORD tls_index;
+static int tls_initialized /* = 0 */;
+
+/* Used as a fallback only. */
+static struct gl_msvc_inval_per_thread not_per_thread;
+
+struct gl_msvc_inval_per_thread *
+gl_msvc_inval_current (void)
+{
+ if (!tls_initialized)
+ {
+ tls_index = TlsAlloc ();
+ tls_initialized = 1;
+ }
+ if (tls_index == TLS_OUT_OF_INDEXES)
+ /* TlsAlloc had failed. */
+ return &not_per_thread;
+ else
+ {
+ struct gl_msvc_inval_per_thread *pointer =
+ (struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
+ if (pointer == NULL)
+ {
+ /* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */
+ pointer =
+ (struct gl_msvc_inval_per_thread *)
+ malloc (sizeof (struct gl_msvc_inval_per_thread));
+ if (pointer == NULL)
+ /* Could not allocate memory. Use the global storage. */
+ pointer = &not_per_thread;
+ TlsSetValue (tls_index, pointer);
+ }
+ return pointer;
+ }
+}
+
+static void __cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+ const wchar_t *function,
+ const wchar_t *file,
+ unsigned int line,
+ uintptr_t dummy)
+{
+ struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
+ if (current->restart_valid)
+ longjmp (current->restart, 1);
+ else
+ /* An invalid parameter notification from outside the gnulib code.
+ Give the caller a chance to intervene. */
+ RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
+}
+
+# endif
+
+# endif
+
+static int gl_msvc_inval_initialized /* = 0 */;
+
+void
+gl_msvc_inval_ensure_handler (void)
+{
+ if (gl_msvc_inval_initialized == 0)
+ {
+ _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
+ gl_msvc_inval_initialized = 1;
+ }
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/msvc-inval.h b/contrib/tools/bison/gnulib/src/msvc-inval.h
index dcb0353dcd..0f37dd570e 100644
--- a/contrib/tools/bison/gnulib/src/msvc-inval.h
+++ b/contrib/tools/bison/gnulib/src/msvc-inval.h
@@ -1,222 +1,222 @@
-/* Invalid parameter handler for MSVC runtime libraries.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _MSVC_INVAL_H
-#define _MSVC_INVAL_H
-
-/* With MSVC runtime libraries with the "invalid parameter handler" concept,
- functions like fprintf(), dup2(), or close() crash when the caller passes
- an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
- instead.
- This file defines macros that turn such an invalid parameter notification
- into a non-local exit. An error code can then be produced at the target
- of this exit. You can thus write code like
-
- TRY_MSVC_INVAL
- {
- <Code that can trigger an invalid parameter notification
- but does not do 'return', 'break', 'continue', nor 'goto'.>
- }
- CATCH_MSVC_INVAL
- {
- <Code that handles an invalid parameter notification
- but does not do 'return', 'break', 'continue', nor 'goto'.>
- }
- DONE_MSVC_INVAL;
-
- This entire block expands to a single statement.
-
- The handling of invalid parameters can be done in three ways:
-
- * The default way, which is reasonable for programs (not libraries):
- AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING])
-
- * The way for libraries that make "hairy" calls (like close(-1), or
- fclose(fp) where fileno(fp) is closed, or simply getdtablesize()):
- AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING])
-
- * The way for libraries that make no "hairy" calls:
- AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING])
- */
-
-#define DEFAULT_HANDLING 0
-#define HAIRY_LIBRARY_HANDLING 1
-#define SANE_LIBRARY_HANDLING 2
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
- && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
-/* A native Windows platform with the "invalid parameter handler" concept,
- and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING. */
-
-# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
-/* Default handling. */
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-/* Ensure that the invalid parameter handler in installed that just returns.
- Because we assume no other part of the program installs a different
- invalid parameter handler, this solution is multithread-safe. */
-extern void gl_msvc_inval_ensure_handler (void);
-
-# ifdef __cplusplus
-}
-# endif
-
-# define TRY_MSVC_INVAL \
- do \
- { \
- gl_msvc_inval_ensure_handler (); \
- if (1)
-# define CATCH_MSVC_INVAL \
- else
-# define DONE_MSVC_INVAL \
- } \
- while (0)
-
-# else
-/* Handling for hairy libraries. */
-
-# include <excpt.h>
-
-/* Gnulib can define its own status codes, as described in the page
- "Raising Software Exceptions" on microsoft.com
- <http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
- Our status codes are composed of
- - 0xE0000000, mandatory for all user-defined status codes,
- - 0x474E550, a API identifier ("GNU"),
- - 0, 1, 2, ..., used to distinguish different status codes from the
- same API. */
-# define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
-
-# if defined _MSC_VER
-/* A compiler that supports __try/__except, as described in the page
- "try-except statement" on microsoft.com
- <http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
- With __try/__except, we can use the multithread-safe exception handling. */
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-/* Ensure that the invalid parameter handler in installed that raises a
- software exception with code STATUS_GNULIB_INVALID_PARAMETER.
- Because we assume no other part of the program installs a different
- invalid parameter handler, this solution is multithread-safe. */
-extern void gl_msvc_inval_ensure_handler (void);
-
-# ifdef __cplusplus
-}
-# endif
-
-# define TRY_MSVC_INVAL \
- do \
- { \
- gl_msvc_inval_ensure_handler (); \
- __try
-# define CATCH_MSVC_INVAL \
- __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER \
- ? EXCEPTION_EXECUTE_HANDLER \
- : EXCEPTION_CONTINUE_SEARCH)
-# define DONE_MSVC_INVAL \
- } \
- while (0)
-
-# else
-/* Any compiler.
- We can only use setjmp/longjmp. */
-
-# include <setjmp.h>
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-struct gl_msvc_inval_per_thread
-{
- /* The restart that will resume execution at the code between
- CATCH_MSVC_INVAL and DONE_MSVC_INVAL. It is enabled only between
- TRY_MSVC_INVAL and CATCH_MSVC_INVAL. */
- jmp_buf restart;
-
- /* Tells whether the contents of restart is valid. */
- int restart_valid;
-};
-
-/* Ensure that the invalid parameter handler in installed that passes
- control to the gl_msvc_inval_restart if it is valid, or raises a
- software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise.
- Because we assume no other part of the program installs a different
- invalid parameter handler, this solution is multithread-safe. */
-extern void gl_msvc_inval_ensure_handler (void);
-
-/* Return a pointer to the per-thread data for the current thread. */
-extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
-
-# ifdef __cplusplus
-}
-# endif
-
-# define TRY_MSVC_INVAL \
- do \
- { \
- struct gl_msvc_inval_per_thread *msvc_inval_current; \
- gl_msvc_inval_ensure_handler (); \
- msvc_inval_current = gl_msvc_inval_current (); \
- /* First, initialize gl_msvc_inval_restart. */ \
- if (setjmp (msvc_inval_current->restart) == 0) \
- { \
- /* Then, mark it as valid. */ \
- msvc_inval_current->restart_valid = 1;
-# define CATCH_MSVC_INVAL \
- /* Execution completed. \
- Mark gl_msvc_inval_restart as invalid. */ \
- msvc_inval_current->restart_valid = 0; \
- } \
- else \
- { \
- /* Execution triggered an invalid parameter notification. \
- Mark gl_msvc_inval_restart as invalid. */ \
- msvc_inval_current->restart_valid = 0;
-# define DONE_MSVC_INVAL \
- } \
- } \
- while (0)
-
-# endif
-
-# endif
-
-#else
-/* A platform that does not need to the invalid parameter handler,
- or when SANE_LIBRARY_HANDLING is desired. */
-
-/* The braces here avoid GCC warnings like
- "warning: suggest explicit braces to avoid ambiguous 'else'". */
-# define TRY_MSVC_INVAL \
- do \
- { \
- if (1)
-# define CATCH_MSVC_INVAL \
- else
-# define DONE_MSVC_INVAL \
- } \
- while (0)
-
-#endif
-
-#endif /* _MSVC_INVAL_H */
+/* Invalid parameter handler for MSVC runtime libraries.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _MSVC_INVAL_H
+#define _MSVC_INVAL_H
+
+/* With MSVC runtime libraries with the "invalid parameter handler" concept,
+ functions like fprintf(), dup2(), or close() crash when the caller passes
+ an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
+ instead.
+ This file defines macros that turn such an invalid parameter notification
+ into a non-local exit. An error code can then be produced at the target
+ of this exit. You can thus write code like
+
+ TRY_MSVC_INVAL
+ {
+ <Code that can trigger an invalid parameter notification
+ but does not do 'return', 'break', 'continue', nor 'goto'.>
+ }
+ CATCH_MSVC_INVAL
+ {
+ <Code that handles an invalid parameter notification
+ but does not do 'return', 'break', 'continue', nor 'goto'.>
+ }
+ DONE_MSVC_INVAL;
+
+ This entire block expands to a single statement.
+
+ The handling of invalid parameters can be done in three ways:
+
+ * The default way, which is reasonable for programs (not libraries):
+ AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING])
+
+ * The way for libraries that make "hairy" calls (like close(-1), or
+ fclose(fp) where fileno(fp) is closed, or simply getdtablesize()):
+ AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING])
+
+ * The way for libraries that make no "hairy" calls:
+ AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING])
+ */
+
+#define DEFAULT_HANDLING 0
+#define HAIRY_LIBRARY_HANDLING 1
+#define SANE_LIBRARY_HANDLING 2
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+ && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
+/* A native Windows platform with the "invalid parameter handler" concept,
+ and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING. */
+
+# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+/* Default handling. */
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* Ensure that the invalid parameter handler in installed that just returns.
+ Because we assume no other part of the program installs a different
+ invalid parameter handler, this solution is multithread-safe. */
+extern void gl_msvc_inval_ensure_handler (void);
+
+# ifdef __cplusplus
+}
+# endif
+
+# define TRY_MSVC_INVAL \
+ do \
+ { \
+ gl_msvc_inval_ensure_handler (); \
+ if (1)
+# define CATCH_MSVC_INVAL \
+ else
+# define DONE_MSVC_INVAL \
+ } \
+ while (0)
+
+# else
+/* Handling for hairy libraries. */
+
+# include <excpt.h>
+
+/* Gnulib can define its own status codes, as described in the page
+ "Raising Software Exceptions" on microsoft.com
+ <http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
+ Our status codes are composed of
+ - 0xE0000000, mandatory for all user-defined status codes,
+ - 0x474E550, a API identifier ("GNU"),
+ - 0, 1, 2, ..., used to distinguish different status codes from the
+ same API. */
+# define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
+
+# if defined _MSC_VER
+/* A compiler that supports __try/__except, as described in the page
+ "try-except statement" on microsoft.com
+ <http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
+ With __try/__except, we can use the multithread-safe exception handling. */
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* Ensure that the invalid parameter handler in installed that raises a
+ software exception with code STATUS_GNULIB_INVALID_PARAMETER.
+ Because we assume no other part of the program installs a different
+ invalid parameter handler, this solution is multithread-safe. */
+extern void gl_msvc_inval_ensure_handler (void);
+
+# ifdef __cplusplus
+}
+# endif
+
+# define TRY_MSVC_INVAL \
+ do \
+ { \
+ gl_msvc_inval_ensure_handler (); \
+ __try
+# define CATCH_MSVC_INVAL \
+ __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER \
+ ? EXCEPTION_EXECUTE_HANDLER \
+ : EXCEPTION_CONTINUE_SEARCH)
+# define DONE_MSVC_INVAL \
+ } \
+ while (0)
+
+# else
+/* Any compiler.
+ We can only use setjmp/longjmp. */
+
+# include <setjmp.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+struct gl_msvc_inval_per_thread
+{
+ /* The restart that will resume execution at the code between
+ CATCH_MSVC_INVAL and DONE_MSVC_INVAL. It is enabled only between
+ TRY_MSVC_INVAL and CATCH_MSVC_INVAL. */
+ jmp_buf restart;
+
+ /* Tells whether the contents of restart is valid. */
+ int restart_valid;
+};
+
+/* Ensure that the invalid parameter handler in installed that passes
+ control to the gl_msvc_inval_restart if it is valid, or raises a
+ software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise.
+ Because we assume no other part of the program installs a different
+ invalid parameter handler, this solution is multithread-safe. */
+extern void gl_msvc_inval_ensure_handler (void);
+
+/* Return a pointer to the per-thread data for the current thread. */
+extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
+
+# ifdef __cplusplus
+}
+# endif
+
+# define TRY_MSVC_INVAL \
+ do \
+ { \
+ struct gl_msvc_inval_per_thread *msvc_inval_current; \
+ gl_msvc_inval_ensure_handler (); \
+ msvc_inval_current = gl_msvc_inval_current (); \
+ /* First, initialize gl_msvc_inval_restart. */ \
+ if (setjmp (msvc_inval_current->restart) == 0) \
+ { \
+ /* Then, mark it as valid. */ \
+ msvc_inval_current->restart_valid = 1;
+# define CATCH_MSVC_INVAL \
+ /* Execution completed. \
+ Mark gl_msvc_inval_restart as invalid. */ \
+ msvc_inval_current->restart_valid = 0; \
+ } \
+ else \
+ { \
+ /* Execution triggered an invalid parameter notification. \
+ Mark gl_msvc_inval_restart as invalid. */ \
+ msvc_inval_current->restart_valid = 0;
+# define DONE_MSVC_INVAL \
+ } \
+ } \
+ while (0)
+
+# endif
+
+# endif
+
+#else
+/* A platform that does not need to the invalid parameter handler,
+ or when SANE_LIBRARY_HANDLING is desired. */
+
+/* The braces here avoid GCC warnings like
+ "warning: suggest explicit braces to avoid ambiguous 'else'". */
+# define TRY_MSVC_INVAL \
+ do \
+ { \
+ if (1)
+# define CATCH_MSVC_INVAL \
+ else
+# define DONE_MSVC_INVAL \
+ } \
+ while (0)
+
+#endif
+
+#endif /* _MSVC_INVAL_H */
diff --git a/contrib/tools/bison/gnulib/src/msvc-nothrow.c b/contrib/tools/bison/gnulib/src/msvc-nothrow.c
index 8d65472a82..dce718e9c6 100644
--- a/contrib/tools/bison/gnulib/src/msvc-nothrow.c
+++ b/contrib/tools/bison/gnulib/src/msvc-nothrow.c
@@ -1,49 +1,49 @@
-/* Wrappers that don't throw invalid parameter notifications
- with MSVC runtime libraries.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "msvc-nothrow.h"
-
-/* Get declarations of the native Windows API functions. */
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-#include "msvc-inval.h"
-
-#undef _get_osfhandle
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-intptr_t
-_gl_nothrow_get_osfhandle (int fd)
-{
- intptr_t result;
-
- TRY_MSVC_INVAL
- {
- result = _get_osfhandle (fd);
- }
- CATCH_MSVC_INVAL
- {
- result = (intptr_t) INVALID_HANDLE_VALUE;
- }
- DONE_MSVC_INVAL;
-
- return result;
-}
-#endif
+/* Wrappers that don't throw invalid parameter notifications
+ with MSVC runtime libraries.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "msvc-nothrow.h"
+
+/* Get declarations of the native Windows API functions. */
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "msvc-inval.h"
+
+#undef _get_osfhandle
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+intptr_t
+_gl_nothrow_get_osfhandle (int fd)
+{
+ intptr_t result;
+
+ TRY_MSVC_INVAL
+ {
+ result = _get_osfhandle (fd);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = (intptr_t) INVALID_HANDLE_VALUE;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/msvc-nothrow.h b/contrib/tools/bison/gnulib/src/msvc-nothrow.h
index 5f521813df..b607475e74 100644
--- a/contrib/tools/bison/gnulib/src/msvc-nothrow.h
+++ b/contrib/tools/bison/gnulib/src/msvc-nothrow.h
@@ -1,43 +1,43 @@
-/* Wrappers that don't throw invalid parameter notifications
- with MSVC runtime libraries.
- Copyright (C) 2011-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _MSVC_NOTHROW_H
-#define _MSVC_NOTHROW_H
-
-/* With MSVC runtime libraries with the "invalid parameter handler" concept,
- functions like fprintf(), dup2(), or close() crash when the caller passes
- an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
- instead.
- This file defines wrappers that turn such an invalid parameter notification
- into an error code. */
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* Get original declaration of _get_osfhandle. */
-# include <io.h>
-
-# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-
-/* Override _get_osfhandle. */
-extern intptr_t _gl_nothrow_get_osfhandle (int fd);
-# define _get_osfhandle _gl_nothrow_get_osfhandle
-
-# endif
-
-#endif
-
-#endif /* _MSVC_NOTHROW_H */
+/* Wrappers that don't throw invalid parameter notifications
+ with MSVC runtime libraries.
+ Copyright (C) 2011-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _MSVC_NOTHROW_H
+#define _MSVC_NOTHROW_H
+
+/* With MSVC runtime libraries with the "invalid parameter handler" concept,
+ functions like fprintf(), dup2(), or close() crash when the caller passes
+ an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF)
+ instead.
+ This file defines wrappers that turn such an invalid parameter notification
+ into an error code. */
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Get original declaration of _get_osfhandle. */
+# include <io.h>
+
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+
+/* Override _get_osfhandle. */
+extern intptr_t _gl_nothrow_get_osfhandle (int fd);
+# define _get_osfhandle _gl_nothrow_get_osfhandle
+
+# endif
+
+#endif
+
+#endif /* _MSVC_NOTHROW_H */
diff --git a/contrib/tools/bison/gnulib/src/nl_langinfo.c b/contrib/tools/bison/gnulib/src/nl_langinfo.c
index 771c9533ae..0a2234fa48 100644
--- a/contrib/tools/bison/gnulib/src/nl_langinfo.c
+++ b/contrib/tools/bison/gnulib/src/nl_langinfo.c
@@ -1,271 +1,271 @@
-/* nl_langinfo() replacement: query locale dependent information.
-
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <langinfo.h>
-
-#if REPLACE_NL_LANGINFO
-
-/* Override nl_langinfo with support for added nl_item values. */
-
-# include <locale.h>
-# include <string.h>
-
-# undef nl_langinfo
-
-char *
-rpl_nl_langinfo (nl_item item)
-{
- switch (item)
- {
-# if GNULIB_defined_CODESET
- case CODESET:
- {
- const char *locale;
- static char buf[2 + 10 + 1];
-
- locale = setlocale (LC_CTYPE, NULL);
- if (locale != NULL && locale[0] != '\0')
- {
- /* If the locale name contains an encoding after the dot, return
- it. */
- const char *dot = strchr (locale, '.');
-
- if (dot != NULL)
- {
- const char *modifier;
-
- dot++;
- /* Look for the possible @... trailer and remove it, if any. */
- modifier = strchr (dot, '@');
- if (modifier == NULL)
- return dot;
- if (modifier - dot < sizeof (buf))
- {
- memcpy (buf, dot, modifier - dot);
- buf [modifier - dot] = '\0';
- return buf;
- }
- }
- }
- return "";
- }
-# endif
-# if GNULIB_defined_T_FMT_AMPM
- case T_FMT_AMPM:
- return "%I:%M:%S %p";
-# endif
-# if GNULIB_defined_ERA
- case ERA:
- /* The format is not standardized. In glibc it is a sequence of strings
- of the form "direction:offset:start_date:end_date:era_name:era_format"
- with an empty string at the end. */
- return "";
- case ERA_D_FMT:
- /* The %Ex conversion in strftime behaves like %x if the locale does not
- have an alternative time format. */
- item = D_FMT;
- break;
- case ERA_D_T_FMT:
- /* The %Ec conversion in strftime behaves like %c if the locale does not
- have an alternative time format. */
- item = D_T_FMT;
- break;
- case ERA_T_FMT:
- /* The %EX conversion in strftime behaves like %X if the locale does not
- have an alternative time format. */
- item = T_FMT;
- break;
- case ALT_DIGITS:
- /* The format is not standardized. In glibc it is a sequence of 10
- strings, appended in memory. */
- return "\0\0\0\0\0\0\0\0\0\0";
-# endif
-# if GNULIB_defined_YESEXPR || !FUNC_NL_LANGINFO_YESEXPR_WORKS
- case YESEXPR:
- return "^[yY]";
- case NOEXPR:
- return "^[nN]";
-# endif
- default:
- break;
- }
- return nl_langinfo (item);
-}
-
-#else
-
-/* Provide nl_langinfo from scratch. */
-
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* Native Windows platforms. */
-
-# define WIN32_LEAN_AND_MEAN /* avoid including junk */
-# include <windows.h>
-
-# include <stdio.h>
-
-# else
-
-/* An old Unix platform without locales, such as Linux libc5 or BeOS. */
-
-# endif
-
-# include <locale.h>
-
-char *
-nl_langinfo (nl_item item)
-{
- switch (item)
- {
- /* nl_langinfo items of the LC_CTYPE category */
- case CODESET:
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- {
- static char buf[2 + 10 + 1];
-
- /* The Windows API has a function returning the locale's codepage as
- a number. */
- sprintf (buf, "CP%u", GetACP ());
- return buf;
- }
-# elif defined __BEOS__
- return "UTF-8";
-# else
- return "ISO-8859-1";
-# endif
- /* nl_langinfo items of the LC_NUMERIC category */
- case RADIXCHAR:
- return localeconv () ->decimal_point;
- case THOUSEP:
- return localeconv () ->thousands_sep;
- /* nl_langinfo items of the LC_TIME category.
- TODO: Really use the locale. */
- case D_T_FMT:
- case ERA_D_T_FMT:
- return "%a %b %e %H:%M:%S %Y";
- case D_FMT:
- case ERA_D_FMT:
- return "%m/%d/%y";
- case T_FMT:
- case ERA_T_FMT:
- return "%H:%M:%S";
- case T_FMT_AMPM:
- return "%I:%M:%S %p";
- case AM_STR:
- return "AM";
- case PM_STR:
- return "PM";
- case DAY_1:
- return "Sunday";
- case DAY_2:
- return "Monday";
- case DAY_3:
- return "Tuesday";
- case DAY_4:
- return "Wednesday";
- case DAY_5:
- return "Thursday";
- case DAY_6:
- return "Friday";
- case DAY_7:
- return "Saturday";
- case ABDAY_1:
- return "Sun";
- case ABDAY_2:
- return "Mon";
- case ABDAY_3:
- return "Tue";
- case ABDAY_4:
- return "Wed";
- case ABDAY_5:
- return "Thu";
- case ABDAY_6:
- return "Fri";
- case ABDAY_7:
- return "Sat";
- case MON_1:
- return "January";
- case MON_2:
- return "February";
- case MON_3:
- return "March";
- case MON_4:
- return "April";
- case MON_5:
- return "May";
- case MON_6:
- return "June";
- case MON_7:
- return "July";
- case MON_8:
- return "August";
- case MON_9:
- return "September";
- case MON_10:
- return "October";
- case MON_11:
- return "November";
- case MON_12:
- return "December";
- case ABMON_1:
- return "Jan";
- case ABMON_2:
- return "Feb";
- case ABMON_3:
- return "Mar";
- case ABMON_4:
- return "Apr";
- case ABMON_5:
- return "May";
- case ABMON_6:
- return "Jun";
- case ABMON_7:
- return "Jul";
- case ABMON_8:
- return "Aug";
- case ABMON_9:
- return "Sep";
- case ABMON_10:
- return "Oct";
- case ABMON_11:
- return "Nov";
- case ABMON_12:
- return "Dec";
- case ERA:
- return "";
- case ALT_DIGITS:
- return "\0\0\0\0\0\0\0\0\0\0";
- /* nl_langinfo items of the LC_MONETARY category
- TODO: Really use the locale. */
- case CRNCYSTR:
- return "-";
- /* nl_langinfo items of the LC_MESSAGES category
- TODO: Really use the locale. */
- case YESEXPR:
- return "^[yY]";
- case NOEXPR:
- return "^[nN]";
- default:
- return "";
- }
-}
-
-#endif
+/* nl_langinfo() replacement: query locale dependent information.
+
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <langinfo.h>
+
+#if REPLACE_NL_LANGINFO
+
+/* Override nl_langinfo with support for added nl_item values. */
+
+# include <locale.h>
+# include <string.h>
+
+# undef nl_langinfo
+
+char *
+rpl_nl_langinfo (nl_item item)
+{
+ switch (item)
+ {
+# if GNULIB_defined_CODESET
+ case CODESET:
+ {
+ const char *locale;
+ static char buf[2 + 10 + 1];
+
+ locale = setlocale (LC_CTYPE, NULL);
+ if (locale != NULL && locale[0] != '\0')
+ {
+ /* If the locale name contains an encoding after the dot, return
+ it. */
+ const char *dot = strchr (locale, '.');
+
+ if (dot != NULL)
+ {
+ const char *modifier;
+
+ dot++;
+ /* Look for the possible @... trailer and remove it, if any. */
+ modifier = strchr (dot, '@');
+ if (modifier == NULL)
+ return dot;
+ if (modifier - dot < sizeof (buf))
+ {
+ memcpy (buf, dot, modifier - dot);
+ buf [modifier - dot] = '\0';
+ return buf;
+ }
+ }
+ }
+ return "";
+ }
+# endif
+# if GNULIB_defined_T_FMT_AMPM
+ case T_FMT_AMPM:
+ return "%I:%M:%S %p";
+# endif
+# if GNULIB_defined_ERA
+ case ERA:
+ /* The format is not standardized. In glibc it is a sequence of strings
+ of the form "direction:offset:start_date:end_date:era_name:era_format"
+ with an empty string at the end. */
+ return "";
+ case ERA_D_FMT:
+ /* The %Ex conversion in strftime behaves like %x if the locale does not
+ have an alternative time format. */
+ item = D_FMT;
+ break;
+ case ERA_D_T_FMT:
+ /* The %Ec conversion in strftime behaves like %c if the locale does not
+ have an alternative time format. */
+ item = D_T_FMT;
+ break;
+ case ERA_T_FMT:
+ /* The %EX conversion in strftime behaves like %X if the locale does not
+ have an alternative time format. */
+ item = T_FMT;
+ break;
+ case ALT_DIGITS:
+ /* The format is not standardized. In glibc it is a sequence of 10
+ strings, appended in memory. */
+ return "\0\0\0\0\0\0\0\0\0\0";
+# endif
+# if GNULIB_defined_YESEXPR || !FUNC_NL_LANGINFO_YESEXPR_WORKS
+ case YESEXPR:
+ return "^[yY]";
+ case NOEXPR:
+ return "^[nN]";
+# endif
+ default:
+ break;
+ }
+ return nl_langinfo (item);
+}
+
+#else
+
+/* Provide nl_langinfo from scratch. */
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Native Windows platforms. */
+
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+
+# include <stdio.h>
+
+# else
+
+/* An old Unix platform without locales, such as Linux libc5 or BeOS. */
+
+# endif
+
+# include <locale.h>
+
+char *
+nl_langinfo (nl_item item)
+{
+ switch (item)
+ {
+ /* nl_langinfo items of the LC_CTYPE category */
+ case CODESET:
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ {
+ static char buf[2 + 10 + 1];
+
+ /* The Windows API has a function returning the locale's codepage as
+ a number. */
+ sprintf (buf, "CP%u", GetACP ());
+ return buf;
+ }
+# elif defined __BEOS__
+ return "UTF-8";
+# else
+ return "ISO-8859-1";
+# endif
+ /* nl_langinfo items of the LC_NUMERIC category */
+ case RADIXCHAR:
+ return localeconv () ->decimal_point;
+ case THOUSEP:
+ return localeconv () ->thousands_sep;
+ /* nl_langinfo items of the LC_TIME category.
+ TODO: Really use the locale. */
+ case D_T_FMT:
+ case ERA_D_T_FMT:
+ return "%a %b %e %H:%M:%S %Y";
+ case D_FMT:
+ case ERA_D_FMT:
+ return "%m/%d/%y";
+ case T_FMT:
+ case ERA_T_FMT:
+ return "%H:%M:%S";
+ case T_FMT_AMPM:
+ return "%I:%M:%S %p";
+ case AM_STR:
+ return "AM";
+ case PM_STR:
+ return "PM";
+ case DAY_1:
+ return "Sunday";
+ case DAY_2:
+ return "Monday";
+ case DAY_3:
+ return "Tuesday";
+ case DAY_4:
+ return "Wednesday";
+ case DAY_5:
+ return "Thursday";
+ case DAY_6:
+ return "Friday";
+ case DAY_7:
+ return "Saturday";
+ case ABDAY_1:
+ return "Sun";
+ case ABDAY_2:
+ return "Mon";
+ case ABDAY_3:
+ return "Tue";
+ case ABDAY_4:
+ return "Wed";
+ case ABDAY_5:
+ return "Thu";
+ case ABDAY_6:
+ return "Fri";
+ case ABDAY_7:
+ return "Sat";
+ case MON_1:
+ return "January";
+ case MON_2:
+ return "February";
+ case MON_3:
+ return "March";
+ case MON_4:
+ return "April";
+ case MON_5:
+ return "May";
+ case MON_6:
+ return "June";
+ case MON_7:
+ return "July";
+ case MON_8:
+ return "August";
+ case MON_9:
+ return "September";
+ case MON_10:
+ return "October";
+ case MON_11:
+ return "November";
+ case MON_12:
+ return "December";
+ case ABMON_1:
+ return "Jan";
+ case ABMON_2:
+ return "Feb";
+ case ABMON_3:
+ return "Mar";
+ case ABMON_4:
+ return "Apr";
+ case ABMON_5:
+ return "May";
+ case ABMON_6:
+ return "Jun";
+ case ABMON_7:
+ return "Jul";
+ case ABMON_8:
+ return "Aug";
+ case ABMON_9:
+ return "Sep";
+ case ABMON_10:
+ return "Oct";
+ case ABMON_11:
+ return "Nov";
+ case ABMON_12:
+ return "Dec";
+ case ERA:
+ return "";
+ case ALT_DIGITS:
+ return "\0\0\0\0\0\0\0\0\0\0";
+ /* nl_langinfo items of the LC_MONETARY category
+ TODO: Really use the locale. */
+ case CRNCYSTR:
+ return "-";
+ /* nl_langinfo items of the LC_MESSAGES category
+ TODO: Really use the locale. */
+ case YESEXPR:
+ return "^[yY]";
+ case NOEXPR:
+ return "^[nN]";
+ default:
+ return "";
+ }
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/obstack.c b/contrib/tools/bison/gnulib/src/obstack.c
index 9b2883e4ac..edbd75397d 100644
--- a/contrib/tools/bison/gnulib/src/obstack.c
+++ b/contrib/tools/bison/gnulib/src/obstack.c
@@ -1,420 +1,420 @@
-/* obstack.c - subroutines used implicitly by object stack macros
-
- Copyright (C) 1988-1994, 1996-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifdef _LIBC
-# include <obstack.h>
-# include <shlib-compat.h>
-#else
-# include <config.h>
-# include "obstack.h"
-#endif
-
-/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
- incremented whenever callers compiled using an old obstack.h can no
- longer properly call the functions in this obstack.c. */
-#define OBSTACK_INTERFACE_VERSION 1
-
-/* Comment out all this code if we are using the GNU C Library, and are not
- actually compiling the library itself, and the installed library
- supports the same library interface we do. This code is part of the GNU
- C Library, but also included in many other GNU distributions. Compiling
- and linking in this code is a waste when using the GNU C library
- (especially if it is a shared library). Rather than having every GNU
- program understand 'configure --with-gnu-libc' and omit the object
- files, it is simpler to just do this in the source for each such file. */
-
-#include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */
-#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
-# include <gnu-versions.h>
-# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
-# define ELIDE_CODE
-# endif
-#endif
-
-#include <stddef.h>
-
-#ifndef ELIDE_CODE
-
-# include <stdint.h>
-
-/* Determine default alignment. */
-union fooround
-{
- uintmax_t i;
- long double d;
- void *p;
-};
-struct fooalign
-{
- char c;
- union fooround u;
-};
-/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
- But in fact it might be less smart and round addresses to as much as
- DEFAULT_ROUNDING. So we prepare for it to do that. */
-enum
- {
- DEFAULT_ALIGNMENT = offsetof (struct fooalign, u),
- DEFAULT_ROUNDING = sizeof (union fooround)
- };
-
-/* When we copy a long block of data, this is the unit to do it with.
- On some machines, copying successive ints does not work;
- in such a case, redefine COPYING_UNIT to 'long' (if that works)
- or 'char' as a last resort. */
-# ifndef COPYING_UNIT
-# define COPYING_UNIT int
-# endif
-
-
-/* The functions allocating more room by calling 'obstack_chunk_alloc'
- jump to the handler pointed to by 'obstack_alloc_failed_handler'.
- This can be set to a user defined function which should either
- abort gracefully or use longjump - but shouldn't return. This
- variable by default points to the internal function
- 'print_and_abort'. */
-static _Noreturn void print_and_abort (void);
-void (*obstack_alloc_failed_handler) (void) = print_and_abort;
-
-/* Exit value used when 'print_and_abort' is used. */
-# include <stdlib.h>
-# ifdef _LIBC
-int obstack_exit_failure = EXIT_FAILURE;
-# else
-# include "exitfail.h"
-# define obstack_exit_failure exit_failure
-# endif
-
-# ifdef _LIBC
-# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
-/* A looong time ago (before 1994, anyway; we're not sure) this global variable
- was used by non-GNU-C macros to avoid multiple evaluation. The GNU C
- library still exports it because somebody might use it. */
-struct obstack *_obstack_compat;
-compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
-# endif
-# endif
-
-/* Define a macro that either calls functions with the traditional malloc/free
- calling interface, or calls functions with the mmalloc/mfree interface
- (that adds an extra first argument), based on the state of use_extra_arg.
- For free, do not use ?:, since some compilers, like the MIPS compilers,
- do not allow (expr) ? void : void. */
-
-# define CALL_CHUNKFUN(h, size) \
- (((h) -> use_extra_arg) \
- ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
- : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
-
-# define CALL_FREEFUN(h, old_chunk) \
- do { \
- if ((h) -> use_extra_arg) \
- (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
- else \
- (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
- } while (0)
-
-
-/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default).
- Objects start on multiples of ALIGNMENT (0 means use default).
- CHUNKFUN is the function to use to allocate chunks,
- and FREEFUN the function to free them.
-
- Return nonzero if successful, calls obstack_alloc_failed_handler if
- allocation fails. */
-
-int
-_obstack_begin (struct obstack *h,
- int size, int alignment,
- void *(*chunkfun) (long),
- void (*freefun) (void *))
-{
+/* obstack.c - subroutines used implicitly by object stack macros
+
+ Copyright (C) 1988-1994, 1996-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef _LIBC
+# include <obstack.h>
+# include <shlib-compat.h>
+#else
+# include <config.h>
+# include "obstack.h"
+#endif
+
+/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
+ incremented whenever callers compiled using an old obstack.h can no
+ longer properly call the functions in this obstack.c. */
+#define OBSTACK_INTERFACE_VERSION 1
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+ actually compiling the library itself, and the installed library
+ supports the same library interface we do. This code is part of the GNU
+ C Library, but also included in many other GNU distributions. Compiling
+ and linking in this code is a waste when using the GNU C library
+ (especially if it is a shared library). Rather than having every GNU
+ program understand 'configure --with-gnu-libc' and omit the object
+ files, it is simpler to just do this in the source for each such file. */
+
+#include <stdio.h> /* Random thing to get __GNU_LIBRARY__. */
+#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
+# include <gnu-versions.h>
+# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
+# define ELIDE_CODE
+# endif
+#endif
+
+#include <stddef.h>
+
+#ifndef ELIDE_CODE
+
+# include <stdint.h>
+
+/* Determine default alignment. */
+union fooround
+{
+ uintmax_t i;
+ long double d;
+ void *p;
+};
+struct fooalign
+{
+ char c;
+ union fooround u;
+};
+/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
+ But in fact it might be less smart and round addresses to as much as
+ DEFAULT_ROUNDING. So we prepare for it to do that. */
+enum
+ {
+ DEFAULT_ALIGNMENT = offsetof (struct fooalign, u),
+ DEFAULT_ROUNDING = sizeof (union fooround)
+ };
+
+/* When we copy a long block of data, this is the unit to do it with.
+ On some machines, copying successive ints does not work;
+ in such a case, redefine COPYING_UNIT to 'long' (if that works)
+ or 'char' as a last resort. */
+# ifndef COPYING_UNIT
+# define COPYING_UNIT int
+# endif
+
+
+/* The functions allocating more room by calling 'obstack_chunk_alloc'
+ jump to the handler pointed to by 'obstack_alloc_failed_handler'.
+ This can be set to a user defined function which should either
+ abort gracefully or use longjump - but shouldn't return. This
+ variable by default points to the internal function
+ 'print_and_abort'. */
+static _Noreturn void print_and_abort (void);
+void (*obstack_alloc_failed_handler) (void) = print_and_abort;
+
+/* Exit value used when 'print_and_abort' is used. */
+# include <stdlib.h>
+# ifdef _LIBC
+int obstack_exit_failure = EXIT_FAILURE;
+# else
+# include "exitfail.h"
+# define obstack_exit_failure exit_failure
+# endif
+
+# ifdef _LIBC
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
+/* A looong time ago (before 1994, anyway; we're not sure) this global variable
+ was used by non-GNU-C macros to avoid multiple evaluation. The GNU C
+ library still exports it because somebody might use it. */
+struct obstack *_obstack_compat;
+compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
+# endif
+# endif
+
+/* Define a macro that either calls functions with the traditional malloc/free
+ calling interface, or calls functions with the mmalloc/mfree interface
+ (that adds an extra first argument), based on the state of use_extra_arg.
+ For free, do not use ?:, since some compilers, like the MIPS compilers,
+ do not allow (expr) ? void : void. */
+
+# define CALL_CHUNKFUN(h, size) \
+ (((h) -> use_extra_arg) \
+ ? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
+ : (*(struct _obstack_chunk *(*) (long)) (h)->chunkfun) ((size)))
+
+# define CALL_FREEFUN(h, old_chunk) \
+ do { \
+ if ((h) -> use_extra_arg) \
+ (*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
+ else \
+ (*(void (*) (void *)) (h)->freefun) ((old_chunk)); \
+ } while (0)
+
+
+/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default).
+ Objects start on multiples of ALIGNMENT (0 means use default).
+ CHUNKFUN is the function to use to allocate chunks,
+ and FREEFUN the function to free them.
+
+ Return nonzero if successful, calls obstack_alloc_failed_handler if
+ allocation fails. */
+
+int
+_obstack_begin (struct obstack *h,
+ int size, int alignment,
+ void *(*chunkfun) (long),
+ void (*freefun) (void *))
+{
struct _obstack_chunk *chunk; /* points to new chunk */
-
- if (alignment == 0)
- alignment = DEFAULT_ALIGNMENT;
- if (size == 0)
- /* Default size is what GNU malloc can fit in a 4096-byte block. */
- {
- /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
- Use the values for range checking, because if range checking is off,
- the extra bytes won't be missed terribly, but if range checking is on
- and we used a larger request, a whole extra 4096 bytes would be
- allocated.
-
- These number are irrelevant to the new GNU malloc. I suspect it is
- less sensitive to the size of the request. */
- int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
- + 4 + DEFAULT_ROUNDING - 1)
- & ~(DEFAULT_ROUNDING - 1));
- size = 4096 - extra;
- }
-
- h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
- h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
- h->chunk_size = size;
- h->alignment_mask = alignment - 1;
- h->use_extra_arg = 0;
-
- chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
- if (!chunk)
- (*obstack_alloc_failed_handler) ();
- h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
- alignment - 1);
- h->chunk_limit = chunk->limit
- = (char *) chunk + h->chunk_size;
- chunk->prev = 0;
- /* The initial chunk now contains no empty object. */
- h->maybe_empty_object = 0;
- h->alloc_failed = 0;
- return 1;
-}
-
-int
-_obstack_begin_1 (struct obstack *h, int size, int alignment,
- void *(*chunkfun) (void *, long),
- void (*freefun) (void *, void *),
- void *arg)
-{
+
+ if (alignment == 0)
+ alignment = DEFAULT_ALIGNMENT;
+ if (size == 0)
+ /* Default size is what GNU malloc can fit in a 4096-byte block. */
+ {
+ /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
+ Use the values for range checking, because if range checking is off,
+ the extra bytes won't be missed terribly, but if range checking is on
+ and we used a larger request, a whole extra 4096 bytes would be
+ allocated.
+
+ These number are irrelevant to the new GNU malloc. I suspect it is
+ less sensitive to the size of the request. */
+ int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
+ + 4 + DEFAULT_ROUNDING - 1)
+ & ~(DEFAULT_ROUNDING - 1));
+ size = 4096 - extra;
+ }
+
+ h->chunkfun = (struct _obstack_chunk * (*)(void *, long)) chunkfun;
+ h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+ h->chunk_size = size;
+ h->alignment_mask = alignment - 1;
+ h->use_extra_arg = 0;
+
+ chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+ if (!chunk)
+ (*obstack_alloc_failed_handler) ();
+ h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
+ alignment - 1);
+ h->chunk_limit = chunk->limit
+ = (char *) chunk + h->chunk_size;
+ chunk->prev = 0;
+ /* The initial chunk now contains no empty object. */
+ h->maybe_empty_object = 0;
+ h->alloc_failed = 0;
+ return 1;
+}
+
+int
+_obstack_begin_1 (struct obstack *h, int size, int alignment,
+ void *(*chunkfun) (void *, long),
+ void (*freefun) (void *, void *),
+ void *arg)
+{
struct _obstack_chunk *chunk; /* points to new chunk */
-
- if (alignment == 0)
- alignment = DEFAULT_ALIGNMENT;
- if (size == 0)
- /* Default size is what GNU malloc can fit in a 4096-byte block. */
- {
- /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
- Use the values for range checking, because if range checking is off,
- the extra bytes won't be missed terribly, but if range checking is on
- and we used a larger request, a whole extra 4096 bytes would be
- allocated.
-
- These number are irrelevant to the new GNU malloc. I suspect it is
- less sensitive to the size of the request. */
- int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
- + 4 + DEFAULT_ROUNDING - 1)
- & ~(DEFAULT_ROUNDING - 1));
- size = 4096 - extra;
- }
-
- h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
- h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
- h->chunk_size = size;
- h->alignment_mask = alignment - 1;
- h->extra_arg = arg;
- h->use_extra_arg = 1;
-
- chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
- if (!chunk)
- (*obstack_alloc_failed_handler) ();
- h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
- alignment - 1);
- h->chunk_limit = chunk->limit
- = (char *) chunk + h->chunk_size;
- chunk->prev = 0;
- /* The initial chunk now contains no empty object. */
- h->maybe_empty_object = 0;
- h->alloc_failed = 0;
- return 1;
-}
-
-/* Allocate a new current chunk for the obstack *H
- on the assumption that LENGTH bytes need to be added
- to the current object, or a new object of length LENGTH allocated.
- Copies any partial object from the end of the old chunk
- to the beginning of the new one. */
-
-void
-_obstack_newchunk (struct obstack *h, int length)
-{
+
+ if (alignment == 0)
+ alignment = DEFAULT_ALIGNMENT;
+ if (size == 0)
+ /* Default size is what GNU malloc can fit in a 4096-byte block. */
+ {
+ /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
+ Use the values for range checking, because if range checking is off,
+ the extra bytes won't be missed terribly, but if range checking is on
+ and we used a larger request, a whole extra 4096 bytes would be
+ allocated.
+
+ These number are irrelevant to the new GNU malloc. I suspect it is
+ less sensitive to the size of the request. */
+ int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
+ + 4 + DEFAULT_ROUNDING - 1)
+ & ~(DEFAULT_ROUNDING - 1));
+ size = 4096 - extra;
+ }
+
+ h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
+ h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+ h->chunk_size = size;
+ h->alignment_mask = alignment - 1;
+ h->extra_arg = arg;
+ h->use_extra_arg = 1;
+
+ chunk = h->chunk = CALL_CHUNKFUN (h, h -> chunk_size);
+ if (!chunk)
+ (*obstack_alloc_failed_handler) ();
+ h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
+ alignment - 1);
+ h->chunk_limit = chunk->limit
+ = (char *) chunk + h->chunk_size;
+ chunk->prev = 0;
+ /* The initial chunk now contains no empty object. */
+ h->maybe_empty_object = 0;
+ h->alloc_failed = 0;
+ return 1;
+}
+
+/* Allocate a new current chunk for the obstack *H
+ on the assumption that LENGTH bytes need to be added
+ to the current object, or a new object of length LENGTH allocated.
+ Copies any partial object from the end of the old chunk
+ to the beginning of the new one. */
+
+void
+_obstack_newchunk (struct obstack *h, int length)
+{
struct _obstack_chunk *old_chunk = h->chunk;
struct _obstack_chunk *new_chunk;
long new_size;
long obj_size = h->next_free - h->object_base;
long i;
- long already;
- char *object_base;
-
- /* Compute size for new chunk. */
- new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100;
- if (new_size < h->chunk_size)
- new_size = h->chunk_size;
-
- /* Allocate and initialize the new chunk. */
- new_chunk = CALL_CHUNKFUN (h, new_size);
- if (!new_chunk)
- (*obstack_alloc_failed_handler) ();
- h->chunk = new_chunk;
- new_chunk->prev = old_chunk;
- new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
-
- /* Compute an aligned object_base in the new chunk */
- object_base =
- __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
-
- /* Move the existing object to the new chunk.
- Word at a time is fast and is safe if the object
- is sufficiently aligned. */
- if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
- {
- for (i = obj_size / sizeof (COPYING_UNIT) - 1;
- i >= 0; i--)
- ((COPYING_UNIT *)object_base)[i]
- = ((COPYING_UNIT *)h->object_base)[i];
- /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
- but that can cross a page boundary on a machine
- which does not do strict alignment for COPYING_UNITS. */
- already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
- }
- else
- already = 0;
- /* Copy remaining bytes one by one. */
- for (i = already; i < obj_size; i++)
- object_base[i] = h->object_base[i];
-
- /* If the object just copied was the only data in OLD_CHUNK,
- free that chunk and remove it from the chain.
- But not if that chunk might contain an empty object. */
- if (! h->maybe_empty_object
- && (h->object_base
- == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents,
- h->alignment_mask)))
- {
- new_chunk->prev = old_chunk->prev;
- CALL_FREEFUN (h, old_chunk);
- }
-
- h->object_base = object_base;
- h->next_free = h->object_base + obj_size;
- /* The new chunk certainly contains no empty object yet. */
- h->maybe_empty_object = 0;
-}
-# ifdef _LIBC
-libc_hidden_def (_obstack_newchunk)
-# endif
-
-/* Return nonzero if object OBJ has been allocated from obstack H.
- This is here for debugging.
- If you use it in a program, you are probably losing. */
-
-/* Suppress -Wmissing-prototypes warning. We don't want to declare this in
- obstack.h because it is just for debugging. */
-int _obstack_allocated_p (struct obstack *h, void *obj);
-
-int
-_obstack_allocated_p (struct obstack *h, void *obj)
-{
+ long already;
+ char *object_base;
+
+ /* Compute size for new chunk. */
+ new_size = (obj_size + length) + (obj_size >> 3) + h->alignment_mask + 100;
+ if (new_size < h->chunk_size)
+ new_size = h->chunk_size;
+
+ /* Allocate and initialize the new chunk. */
+ new_chunk = CALL_CHUNKFUN (h, new_size);
+ if (!new_chunk)
+ (*obstack_alloc_failed_handler) ();
+ h->chunk = new_chunk;
+ new_chunk->prev = old_chunk;
+ new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size;
+
+ /* Compute an aligned object_base in the new chunk */
+ object_base =
+ __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
+
+ /* Move the existing object to the new chunk.
+ Word at a time is fast and is safe if the object
+ is sufficiently aligned. */
+ if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
+ {
+ for (i = obj_size / sizeof (COPYING_UNIT) - 1;
+ i >= 0; i--)
+ ((COPYING_UNIT *)object_base)[i]
+ = ((COPYING_UNIT *)h->object_base)[i];
+ /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
+ but that can cross a page boundary on a machine
+ which does not do strict alignment for COPYING_UNITS. */
+ already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
+ }
+ else
+ already = 0;
+ /* Copy remaining bytes one by one. */
+ for (i = already; i < obj_size; i++)
+ object_base[i] = h->object_base[i];
+
+ /* If the object just copied was the only data in OLD_CHUNK,
+ free that chunk and remove it from the chain.
+ But not if that chunk might contain an empty object. */
+ if (! h->maybe_empty_object
+ && (h->object_base
+ == __PTR_ALIGN ((char *) old_chunk, old_chunk->contents,
+ h->alignment_mask)))
+ {
+ new_chunk->prev = old_chunk->prev;
+ CALL_FREEFUN (h, old_chunk);
+ }
+
+ h->object_base = object_base;
+ h->next_free = h->object_base + obj_size;
+ /* The new chunk certainly contains no empty object yet. */
+ h->maybe_empty_object = 0;
+}
+# ifdef _LIBC
+libc_hidden_def (_obstack_newchunk)
+# endif
+
+/* Return nonzero if object OBJ has been allocated from obstack H.
+ This is here for debugging.
+ If you use it in a program, you are probably losing. */
+
+/* Suppress -Wmissing-prototypes warning. We don't want to declare this in
+ obstack.h because it is just for debugging. */
+int _obstack_allocated_p (struct obstack *h, void *obj);
+
+int
+_obstack_allocated_p (struct obstack *h, void *obj)
+{
struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
struct _obstack_chunk *plp; /* point to previous chunk if any */
-
- lp = (h)->chunk;
- /* We use >= rather than > since the object cannot be exactly at
- the beginning of the chunk but might be an empty object exactly
- at the end of an adjacent chunk. */
- while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
- {
- plp = lp->prev;
- lp = plp;
- }
- return lp != 0;
-}
-
-/* Free objects in obstack H, including OBJ and everything allocate
- more recently than OBJ. If OBJ is zero, free everything in H. */
-
-# undef obstack_free
-
-void
-__obstack_free (struct obstack *h, void *obj)
-{
+
+ lp = (h)->chunk;
+ /* We use >= rather than > since the object cannot be exactly at
+ the beginning of the chunk but might be an empty object exactly
+ at the end of an adjacent chunk. */
+ while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+ {
+ plp = lp->prev;
+ lp = plp;
+ }
+ return lp != 0;
+}
+
+/* Free objects in obstack H, including OBJ and everything allocate
+ more recently than OBJ. If OBJ is zero, free everything in H. */
+
+# undef obstack_free
+
+void
+__obstack_free (struct obstack *h, void *obj)
+{
struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
struct _obstack_chunk *plp; /* point to previous chunk if any */
-
- lp = h->chunk;
- /* We use >= because there cannot be an object at the beginning of a chunk.
- But there can be an empty object at that address
- at the end of another chunk. */
- while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
- {
- plp = lp->prev;
- CALL_FREEFUN (h, lp);
- lp = plp;
- /* If we switch chunks, we can't tell whether the new current
- chunk contains an empty object, so assume that it may. */
- h->maybe_empty_object = 1;
- }
- if (lp)
- {
- h->object_base = h->next_free = (char *) (obj);
- h->chunk_limit = lp->limit;
- h->chunk = lp;
- }
- else if (obj != 0)
- /* obj is not in any of the chunks! */
- abort ();
-}
-
-# ifdef _LIBC
-/* Older versions of libc used a function _obstack_free intended to be
- called by non-GCC compilers. */
-strong_alias (obstack_free, _obstack_free)
-# endif
-
-int
-_obstack_memory_used (struct obstack *h)
-{
+
+ lp = h->chunk;
+ /* We use >= because there cannot be an object at the beginning of a chunk.
+ But there can be an empty object at that address
+ at the end of another chunk. */
+ while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
+ {
+ plp = lp->prev;
+ CALL_FREEFUN (h, lp);
+ lp = plp;
+ /* If we switch chunks, we can't tell whether the new current
+ chunk contains an empty object, so assume that it may. */
+ h->maybe_empty_object = 1;
+ }
+ if (lp)
+ {
+ h->object_base = h->next_free = (char *) (obj);
+ h->chunk_limit = lp->limit;
+ h->chunk = lp;
+ }
+ else if (obj != 0)
+ /* obj is not in any of the chunks! */
+ abort ();
+}
+
+# ifdef _LIBC
+/* Older versions of libc used a function _obstack_free intended to be
+ called by non-GCC compilers. */
+strong_alias (obstack_free, _obstack_free)
+# endif
+
+int
+_obstack_memory_used (struct obstack *h)
+{
struct _obstack_chunk* lp;
int nbytes = 0;
-
- for (lp = h->chunk; lp != 0; lp = lp->prev)
- {
- nbytes += lp->limit - (char *) lp;
- }
- return nbytes;
-}
-
-/* Define the error handler. */
-# ifdef _LIBC
-# include <libintl.h>
-# else
-# include "gettext.h"
-# endif
-# ifndef _
-# define _(msgid) gettext (msgid)
-# endif
-
-# ifdef _LIBC
-# include <libio/iolibio.h>
-# endif
-
-static _Noreturn void
-print_and_abort (void)
-{
- /* Don't change any of these strings. Yes, it would be possible to add
- the newline to the string and use fputs or so. But this must not
- happen because the "memory exhausted" message appears in other places
- like this and the translation should be reused instead of creating
- a very similar string which requires a separate translation. */
-# ifdef _LIBC
- (void) __fxprintf (NULL, "%s\n", _("memory exhausted"));
-# else
- fprintf (stderr, "%s\n", _("memory exhausted"));
-# endif
- exit (obstack_exit_failure);
-}
-
-#endif /* !ELIDE_CODE */
+
+ for (lp = h->chunk; lp != 0; lp = lp->prev)
+ {
+ nbytes += lp->limit - (char *) lp;
+ }
+ return nbytes;
+}
+
+/* Define the error handler. */
+# ifdef _LIBC
+# include <libintl.h>
+# else
+# include "gettext.h"
+# endif
+# ifndef _
+# define _(msgid) gettext (msgid)
+# endif
+
+# ifdef _LIBC
+# include <libio/iolibio.h>
+# endif
+
+static _Noreturn void
+print_and_abort (void)
+{
+ /* Don't change any of these strings. Yes, it would be possible to add
+ the newline to the string and use fputs or so. But this must not
+ happen because the "memory exhausted" message appears in other places
+ like this and the translation should be reused instead of creating
+ a very similar string which requires a separate translation. */
+# ifdef _LIBC
+ (void) __fxprintf (NULL, "%s\n", _("memory exhausted"));
+# else
+ fprintf (stderr, "%s\n", _("memory exhausted"));
+# endif
+ exit (obstack_exit_failure);
+}
+
+#endif /* !ELIDE_CODE */
diff --git a/contrib/tools/bison/gnulib/src/obstack.h b/contrib/tools/bison/gnulib/src/obstack.h
index c57cc57b92..4248a79676 100644
--- a/contrib/tools/bison/gnulib/src/obstack.h
+++ b/contrib/tools/bison/gnulib/src/obstack.h
@@ -1,518 +1,518 @@
-/* obstack.h - object stack macros
- Copyright (C) 1988-1994, 1996-1999, 2003-2006, 2009-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Summary:
-
-All the apparent functions defined here are macros. The idea
-is that you would use these pre-tested macros to solve a
-very specific set of problems, and they would run fast.
-Caution: no side-effects in arguments please!! They may be
-evaluated MANY times!!
-
-These macros operate a stack of objects. Each object starts life
-small, and may grow to maturity. (Consider building a word syllable
-by syllable.) An object can move while it is growing. Once it has
-been "finished" it never changes address again. So the "top of the
-stack" is typically an immature growing object, while the rest of the
-stack is of mature, fixed size and fixed address objects.
-
-These routines grab large chunks of memory, using a function you
-supply, called 'obstack_chunk_alloc'. On occasion, they free chunks,
-by calling 'obstack_chunk_free'. You must define them and declare
-them before using any obstack macros.
-
-Each independent stack is represented by a 'struct obstack'.
-Each of the obstack macros expects a pointer to such a structure
-as the first argument.
-
-One motivation for this package is the problem of growing char strings
-in symbol tables. Unless you are "fascist pig with a read-only mind"
---Gosper's immortal quote from HAKMEM item 154, out of context--you
-would not like to put any arbitrary upper limit on the length of your
-symbols.
-
-In practice this often means you will build many short symbols and a
-few long symbols. At the time you are reading a symbol you don't know
-how long it is. One traditional method is to read a symbol into a
-buffer, realloc()ating the buffer every time you try to read a symbol
-that is longer than the buffer. This is beaut, but you still will
-want to copy the symbol from the buffer to a more permanent
-symbol-table entry say about half the time.
-
-With obstacks, you can work differently. Use one obstack for all symbol
-names. As you read a symbol, grow the name in the obstack gradually.
-When the name is complete, finalize it. Then, if the symbol exists already,
-free the newly read name.
-
-The way we do this is to take a large chunk, allocating memory from
-low addresses. When you want to build a symbol in the chunk you just
-add chars above the current "high water mark" in the chunk. When you
-have finished adding chars, because you got to the end of the symbol,
-you know how long the chars are, and you can create a new object.
-Mostly the chars will not burst over the highest address of the chunk,
-because you would typically expect a chunk to be (say) 100 times as
-long as an average object.
-
-In case that isn't clear, when we have enough chars to make up
-the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed)
-so we just point to it where it lies. No moving of chars is
-needed and this is the second win: potentially long strings need
-never be explicitly shuffled. Once an object is formed, it does not
-change its address during its lifetime.
-
-When the chars burst over a chunk boundary, we allocate a larger
-chunk, and then copy the partly formed object from the end of the old
-chunk to the beginning of the new larger chunk. We then carry on
-accreting characters to the end of the object as we normally would.
-
-A special macro is provided to add a single char at a time to a
-growing object. This allows the use of register variables, which
-break the ordinary 'growth' macro.
-
-Summary:
- We allocate large chunks.
- We carve out one object at a time from the current chunk.
- Once carved, an object never moves.
- We are free to append data of any size to the currently
- growing object.
- Exactly one object is growing in an obstack at any one time.
- You can run one obstack per control block.
- You may have as many control blocks as you dare.
- Because of the way we do it, you can "unwind" an obstack
- back to a previous state. (You may remove objects much
- as you would with a stack.)
-*/
-
-
-/* Don't do the contents of this file more than once. */
-
-#ifndef _OBSTACK_H
-#define _OBSTACK_H 1
-
-/* We need the type of a pointer subtraction. If __PTRDIFF_TYPE__ is
- defined, as with GNU C, use that; that way we don't pollute the
- namespace with <stddef.h>'s symbols. Otherwise, include <stddef.h>
- and use ptrdiff_t. */
-
-#ifdef __PTRDIFF_TYPE__
-# define PTR_INT_TYPE __PTRDIFF_TYPE__
-#else
-# include <stddef.h>
-# define PTR_INT_TYPE ptrdiff_t
-#endif
-
-/* If B is the base of an object addressed by P, return the result of
- aligning P to the next multiple of A + 1. B and P must be of type
- char *. A + 1 must be a power of 2. */
-
-#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
-
-/* Similar to _BPTR_ALIGN (B, P, A), except optimize the common case
- where pointers can be converted to integers, aligned as integers,
- and converted back again. If PTR_INT_TYPE is narrower than a
- pointer (e.g., the AS/400), play it safe and compute the alignment
- relative to B. Otherwise, use the faster strategy of computing the
- alignment relative to 0. */
-
-#define __PTR_ALIGN(B, P, A) \
- __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
- P, A)
-
-#include <string.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct _obstack_chunk /* Lives at front of each chunk. */
-{
- char *limit; /* 1 past end of this chunk */
- struct _obstack_chunk *prev; /* address of prior chunk or NULL */
- char contents[4]; /* objects begin here */
-};
-
-struct obstack /* control current object in current chunk */
-{
- long chunk_size; /* preferred size to allocate chunks in */
- struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */
- char *object_base; /* address of object we are building */
- char *next_free; /* where to add next char to current object */
- char *chunk_limit; /* address of char after current chunk */
- union
- {
- PTR_INT_TYPE tempint;
- void *tempptr;
- } temp; /* Temporary for some macros. */
- int alignment_mask; /* Mask of alignment for each object. */
- /* These prototypes vary based on 'use_extra_arg', and we use
- casts to the prototypeless function type in all assignments,
- but having prototypes here quiets -Wstrict-prototypes. */
- struct _obstack_chunk *(*chunkfun) (void *, long);
- void (*freefun) (void *, struct _obstack_chunk *);
- void *extra_arg; /* first arg for chunk alloc/dealloc funcs */
- unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */
- unsigned maybe_empty_object:1;/* There is a possibility that the current
- chunk contains a zero-length object. This
- prevents freeing the chunk if we allocate
- a bigger chunk to replace it. */
- unsigned alloc_failed:1; /* No longer used, as we now call the failed
- handler on error, but retained for binary
- compatibility. */
-};
-
-/* Declare the external functions we use; they are in obstack.c. */
-
-extern void _obstack_newchunk (struct obstack *, int);
-extern int _obstack_begin (struct obstack *, int, int,
- void *(*) (long), void (*) (void *));
-extern int _obstack_begin_1 (struct obstack *, int, int,
- void *(*) (void *, long),
- void (*) (void *, void *), void *);
-extern int _obstack_memory_used (struct obstack *);
-
-/* The default name of the function for freeing a chunk is 'obstack_free',
- but gnulib users can override this by defining '__obstack_free'. */
-#ifndef __obstack_free
-# define __obstack_free obstack_free
-#endif
-extern void __obstack_free (struct obstack *obstack, void *block);
-
-
-/* Error handler called when 'obstack_chunk_alloc' failed to allocate
- more memory. This can be set to a user defined function which
- should either abort gracefully or use longjump - but shouldn't
- return. The default action is to print a message and abort. */
-extern void (*obstack_alloc_failed_handler) (void);
-
-/* Exit value used when 'print_and_abort' is used. */
-extern int obstack_exit_failure;
-
-/* Pointer to beginning of object being allocated or to be allocated next.
- Note that this might not be the final address of the object
- because a new chunk might be needed to hold the final size. */
-
-#define obstack_base(h) ((void *) (h)->object_base)
-
-/* Size for allocating ordinary chunks. */
-
-#define obstack_chunk_size(h) ((h)->chunk_size)
-
-/* Pointer to next byte not yet allocated in current chunk. */
-
-#define obstack_next_free(h) ((h)->next_free)
-
-/* Mask specifying low bits that should be clear in address of an object. */
-
-#define obstack_alignment_mask(h) ((h)->alignment_mask)
-
-/* To prevent prototype warnings provide complete argument list. */
-#define obstack_init(h) \
- _obstack_begin ((h), 0, 0, \
- (void *(*) (long)) obstack_chunk_alloc, \
- (void (*) (void *)) obstack_chunk_free)
-
-#define obstack_begin(h, size) \
- _obstack_begin ((h), (size), 0, \
- (void *(*) (long)) obstack_chunk_alloc, \
- (void (*) (void *)) obstack_chunk_free)
-
-#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
- _obstack_begin ((h), (size), (alignment), \
- (void *(*) (long)) (chunkfun), \
- (void (*) (void *)) (freefun))
-
-#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
- _obstack_begin_1 ((h), (size), (alignment), \
- (void *(*) (void *, long)) (chunkfun), \
- (void (*) (void *, void *)) (freefun), (arg))
-
-#define obstack_chunkfun(h, newchunkfun) \
- ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
-
-#define obstack_freefun(h, newfreefun) \
- ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
-
-#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
-
-#define obstack_blank_fast(h,n) ((h)->next_free += (n))
-
-#define obstack_memory_used(h) _obstack_memory_used (h)
-
-#if defined __GNUC__
-/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
- does not implement __extension__. But that compiler doesn't define
- __GNUC_MINOR__. */
-# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
-# define __extension__
-# endif
-
-/* For GNU C, if not -traditional,
- we can define these macros to compute all args only once
- without using a global variable.
- Also, we can avoid using the 'temp' slot, to make faster code. */
-
-# define obstack_object_size(OBSTACK) \
- __extension__ \
- ({ struct obstack const *__o = (OBSTACK); \
- (unsigned) (__o->next_free - __o->object_base); })
-
-# define obstack_room(OBSTACK) \
- __extension__ \
- ({ struct obstack const *__o = (OBSTACK); \
- (unsigned) (__o->chunk_limit - __o->next_free); })
-
-# define obstack_make_room(OBSTACK,length) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- int __len = (length); \
- if (__o->chunk_limit - __o->next_free < __len) \
- _obstack_newchunk (__o, __len); \
- (void) 0; })
-
-# define obstack_empty_p(OBSTACK) \
- __extension__ \
- ({ struct obstack const *__o = (OBSTACK); \
- (__o->chunk->prev == 0 \
- && __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \
- __o->chunk->contents, \
- __o->alignment_mask)); })
-
-# define obstack_grow(OBSTACK,where,length) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- int __len = (length); \
- if (__o->next_free + __len > __o->chunk_limit) \
- _obstack_newchunk (__o, __len); \
- memcpy (__o->next_free, where, __len); \
- __o->next_free += __len; \
- (void) 0; })
-
-# define obstack_grow0(OBSTACK,where,length) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- int __len = (length); \
- if (__o->next_free + __len + 1 > __o->chunk_limit) \
- _obstack_newchunk (__o, __len + 1); \
- memcpy (__o->next_free, where, __len); \
- __o->next_free += __len; \
- *(__o->next_free)++ = 0; \
- (void) 0; })
-
-# define obstack_1grow(OBSTACK,datum) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- if (__o->next_free + 1 > __o->chunk_limit) \
- _obstack_newchunk (__o, 1); \
- obstack_1grow_fast (__o, datum); \
- (void) 0; })
-
-/* These assume that the obstack alignment is good enough for pointers
- or ints, and that the data added so far to the current object
- shares that much alignment. */
-
-# define obstack_ptr_grow(OBSTACK,datum) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
- _obstack_newchunk (__o, sizeof (void *)); \
- obstack_ptr_grow_fast (__o, datum); }) \
-
-# define obstack_int_grow(OBSTACK,datum) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- if (__o->next_free + sizeof (int) > __o->chunk_limit) \
- _obstack_newchunk (__o, sizeof (int)); \
- obstack_int_grow_fast (__o, datum); })
-
-# define obstack_ptr_grow_fast(OBSTACK,aptr) \
-__extension__ \
-({ struct obstack *__o1 = (OBSTACK); \
- void *__p1 = __o1->next_free; \
- *(const void **) __p1 = (aptr); \
- __o1->next_free += sizeof (const void *); \
- (void) 0; })
-
-# define obstack_int_grow_fast(OBSTACK,aint) \
-__extension__ \
-({ struct obstack *__o1 = (OBSTACK); \
- void *__p1 = __o1->next_free; \
- *(int *) __p1 = (aint); \
- __o1->next_free += sizeof (int); \
- (void) 0; })
-
-# define obstack_blank(OBSTACK,length) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- int __len = (length); \
- if (__o->chunk_limit - __o->next_free < __len) \
- _obstack_newchunk (__o, __len); \
- obstack_blank_fast (__o, __len); \
- (void) 0; })
-
-# define obstack_alloc(OBSTACK,length) \
-__extension__ \
-({ struct obstack *__h = (OBSTACK); \
- obstack_blank (__h, (length)); \
- obstack_finish (__h); })
-
-# define obstack_copy(OBSTACK,where,length) \
-__extension__ \
-({ struct obstack *__h = (OBSTACK); \
- obstack_grow (__h, (where), (length)); \
- obstack_finish (__h); })
-
-# define obstack_copy0(OBSTACK,where,length) \
-__extension__ \
-({ struct obstack *__h = (OBSTACK); \
- obstack_grow0 (__h, (where), (length)); \
- obstack_finish (__h); })
-
-/* The local variable is named __o1 to avoid a name conflict
- when obstack_blank is called. */
-# define obstack_finish(OBSTACK) \
-__extension__ \
-({ struct obstack *__o1 = (OBSTACK); \
- void *__value = (void *) __o1->object_base; \
- if (__o1->next_free == __value) \
- __o1->maybe_empty_object = 1; \
- __o1->next_free \
- = __PTR_ALIGN (__o1->object_base, __o1->next_free, \
- __o1->alignment_mask); \
- if (__o1->next_free - (char *)__o1->chunk \
- > __o1->chunk_limit - (char *)__o1->chunk) \
- __o1->next_free = __o1->chunk_limit; \
- __o1->object_base = __o1->next_free; \
- __value; })
-
-# define obstack_free(OBSTACK, OBJ) \
-__extension__ \
-({ struct obstack *__o = (OBSTACK); \
- void *__obj = (OBJ); \
- if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
- __o->next_free = __o->object_base = (char *)__obj; \
- else (__obstack_free) (__o, __obj); })
-
-#else /* not __GNUC__ */
-
-# define obstack_object_size(h) \
- (unsigned) ((h)->next_free - (h)->object_base)
-
-# define obstack_room(h) \
- (unsigned) ((h)->chunk_limit - (h)->next_free)
-
-# define obstack_empty_p(h) \
- ((h)->chunk->prev == 0 \
- && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \
- (h)->chunk->contents, \
- (h)->alignment_mask))
-
-/* Note that the call to _obstack_newchunk is enclosed in (..., 0)
- so that we can avoid having void expressions
- in the arms of the conditional expression.
- Casting the third operand to void was tried before,
- but some compilers won't accept it. */
-
-# define obstack_make_room(h,length) \
-( (h)->temp.tempint = (length), \
- (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
- ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
-
-# define obstack_grow(h,where,length) \
-( (h)->temp.tempint = (length), \
- (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
- ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
- memcpy ((h)->next_free, where, (h)->temp.tempint), \
- (h)->next_free += (h)->temp.tempint)
-
-# define obstack_grow0(h,where,length) \
-( (h)->temp.tempint = (length), \
- (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \
- ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \
- memcpy ((h)->next_free, where, (h)->temp.tempint), \
- (h)->next_free += (h)->temp.tempint, \
- *((h)->next_free)++ = 0)
-
-# define obstack_1grow(h,datum) \
-( (((h)->next_free + 1 > (h)->chunk_limit) \
- ? (_obstack_newchunk ((h), 1), 0) : 0), \
- obstack_1grow_fast (h, datum))
-
-# define obstack_ptr_grow(h,datum) \
-( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
- ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
- obstack_ptr_grow_fast (h, datum))
-
-# define obstack_int_grow(h,datum) \
-( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
- ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
- obstack_int_grow_fast (h, datum))
-
-# define obstack_ptr_grow_fast(h,aptr) \
- (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
-
-# define obstack_int_grow_fast(h,aint) \
- (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
-
-# define obstack_blank(h,length) \
-( (h)->temp.tempint = (length), \
- (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \
- ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
- obstack_blank_fast (h, (h)->temp.tempint))
-
-# define obstack_alloc(h,length) \
- (obstack_blank ((h), (length)), obstack_finish ((h)))
-
-# define obstack_copy(h,where,length) \
- (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
-
-# define obstack_copy0(h,where,length) \
- (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
-
-# define obstack_finish(h) \
-( ((h)->next_free == (h)->object_base \
- ? (((h)->maybe_empty_object = 1), 0) \
- : 0), \
- (h)->temp.tempptr = (h)->object_base, \
- (h)->next_free \
- = __PTR_ALIGN ((h)->object_base, (h)->next_free, \
- (h)->alignment_mask), \
- (((h)->next_free - (char *) (h)->chunk \
- > (h)->chunk_limit - (char *) (h)->chunk) \
- ? ((h)->next_free = (h)->chunk_limit) : 0), \
- (h)->object_base = (h)->next_free, \
- (h)->temp.tempptr)
-
-# define obstack_free(h,obj) \
-( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
- ((((h)->temp.tempint > 0 \
- && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
- ? (int) ((h)->next_free = (h)->object_base \
- = (h)->temp.tempint + (char *) (h)->chunk) \
- : (((__obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
-
-#endif /* not __GNUC__ */
-
-#ifdef __cplusplus
-} /* C++ */
-#endif
-
+/* obstack.h - object stack macros
+ Copyright (C) 1988-1994, 1996-1999, 2003-2006, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Summary:
+
+All the apparent functions defined here are macros. The idea
+is that you would use these pre-tested macros to solve a
+very specific set of problems, and they would run fast.
+Caution: no side-effects in arguments please!! They may be
+evaluated MANY times!!
+
+These macros operate a stack of objects. Each object starts life
+small, and may grow to maturity. (Consider building a word syllable
+by syllable.) An object can move while it is growing. Once it has
+been "finished" it never changes address again. So the "top of the
+stack" is typically an immature growing object, while the rest of the
+stack is of mature, fixed size and fixed address objects.
+
+These routines grab large chunks of memory, using a function you
+supply, called 'obstack_chunk_alloc'. On occasion, they free chunks,
+by calling 'obstack_chunk_free'. You must define them and declare
+them before using any obstack macros.
+
+Each independent stack is represented by a 'struct obstack'.
+Each of the obstack macros expects a pointer to such a structure
+as the first argument.
+
+One motivation for this package is the problem of growing char strings
+in symbol tables. Unless you are "fascist pig with a read-only mind"
+--Gosper's immortal quote from HAKMEM item 154, out of context--you
+would not like to put any arbitrary upper limit on the length of your
+symbols.
+
+In practice this often means you will build many short symbols and a
+few long symbols. At the time you are reading a symbol you don't know
+how long it is. One traditional method is to read a symbol into a
+buffer, realloc()ating the buffer every time you try to read a symbol
+that is longer than the buffer. This is beaut, but you still will
+want to copy the symbol from the buffer to a more permanent
+symbol-table entry say about half the time.
+
+With obstacks, you can work differently. Use one obstack for all symbol
+names. As you read a symbol, grow the name in the obstack gradually.
+When the name is complete, finalize it. Then, if the symbol exists already,
+free the newly read name.
+
+The way we do this is to take a large chunk, allocating memory from
+low addresses. When you want to build a symbol in the chunk you just
+add chars above the current "high water mark" in the chunk. When you
+have finished adding chars, because you got to the end of the symbol,
+you know how long the chars are, and you can create a new object.
+Mostly the chars will not burst over the highest address of the chunk,
+because you would typically expect a chunk to be (say) 100 times as
+long as an average object.
+
+In case that isn't clear, when we have enough chars to make up
+the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed)
+so we just point to it where it lies. No moving of chars is
+needed and this is the second win: potentially long strings need
+never be explicitly shuffled. Once an object is formed, it does not
+change its address during its lifetime.
+
+When the chars burst over a chunk boundary, we allocate a larger
+chunk, and then copy the partly formed object from the end of the old
+chunk to the beginning of the new larger chunk. We then carry on
+accreting characters to the end of the object as we normally would.
+
+A special macro is provided to add a single char at a time to a
+growing object. This allows the use of register variables, which
+break the ordinary 'growth' macro.
+
+Summary:
+ We allocate large chunks.
+ We carve out one object at a time from the current chunk.
+ Once carved, an object never moves.
+ We are free to append data of any size to the currently
+ growing object.
+ Exactly one object is growing in an obstack at any one time.
+ You can run one obstack per control block.
+ You may have as many control blocks as you dare.
+ Because of the way we do it, you can "unwind" an obstack
+ back to a previous state. (You may remove objects much
+ as you would with a stack.)
+*/
+
+
+/* Don't do the contents of this file more than once. */
+
+#ifndef _OBSTACK_H
+#define _OBSTACK_H 1
+
+/* We need the type of a pointer subtraction. If __PTRDIFF_TYPE__ is
+ defined, as with GNU C, use that; that way we don't pollute the
+ namespace with <stddef.h>'s symbols. Otherwise, include <stddef.h>
+ and use ptrdiff_t. */
+
+#ifdef __PTRDIFF_TYPE__
+# define PTR_INT_TYPE __PTRDIFF_TYPE__
+#else
+# include <stddef.h>
+# define PTR_INT_TYPE ptrdiff_t
+#endif
+
+/* If B is the base of an object addressed by P, return the result of
+ aligning P to the next multiple of A + 1. B and P must be of type
+ char *. A + 1 must be a power of 2. */
+
+#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
+
+/* Similar to _BPTR_ALIGN (B, P, A), except optimize the common case
+ where pointers can be converted to integers, aligned as integers,
+ and converted back again. If PTR_INT_TYPE is narrower than a
+ pointer (e.g., the AS/400), play it safe and compute the alignment
+ relative to B. Otherwise, use the faster strategy of computing the
+ alignment relative to 0. */
+
+#define __PTR_ALIGN(B, P, A) \
+ __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
+ P, A)
+
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _obstack_chunk /* Lives at front of each chunk. */
+{
+ char *limit; /* 1 past end of this chunk */
+ struct _obstack_chunk *prev; /* address of prior chunk or NULL */
+ char contents[4]; /* objects begin here */
+};
+
+struct obstack /* control current object in current chunk */
+{
+ long chunk_size; /* preferred size to allocate chunks in */
+ struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */
+ char *object_base; /* address of object we are building */
+ char *next_free; /* where to add next char to current object */
+ char *chunk_limit; /* address of char after current chunk */
+ union
+ {
+ PTR_INT_TYPE tempint;
+ void *tempptr;
+ } temp; /* Temporary for some macros. */
+ int alignment_mask; /* Mask of alignment for each object. */
+ /* These prototypes vary based on 'use_extra_arg', and we use
+ casts to the prototypeless function type in all assignments,
+ but having prototypes here quiets -Wstrict-prototypes. */
+ struct _obstack_chunk *(*chunkfun) (void *, long);
+ void (*freefun) (void *, struct _obstack_chunk *);
+ void *extra_arg; /* first arg for chunk alloc/dealloc funcs */
+ unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */
+ unsigned maybe_empty_object:1;/* There is a possibility that the current
+ chunk contains a zero-length object. This
+ prevents freeing the chunk if we allocate
+ a bigger chunk to replace it. */
+ unsigned alloc_failed:1; /* No longer used, as we now call the failed
+ handler on error, but retained for binary
+ compatibility. */
+};
+
+/* Declare the external functions we use; they are in obstack.c. */
+
+extern void _obstack_newchunk (struct obstack *, int);
+extern int _obstack_begin (struct obstack *, int, int,
+ void *(*) (long), void (*) (void *));
+extern int _obstack_begin_1 (struct obstack *, int, int,
+ void *(*) (void *, long),
+ void (*) (void *, void *), void *);
+extern int _obstack_memory_used (struct obstack *);
+
+/* The default name of the function for freeing a chunk is 'obstack_free',
+ but gnulib users can override this by defining '__obstack_free'. */
+#ifndef __obstack_free
+# define __obstack_free obstack_free
+#endif
+extern void __obstack_free (struct obstack *obstack, void *block);
+
+
+/* Error handler called when 'obstack_chunk_alloc' failed to allocate
+ more memory. This can be set to a user defined function which
+ should either abort gracefully or use longjump - but shouldn't
+ return. The default action is to print a message and abort. */
+extern void (*obstack_alloc_failed_handler) (void);
+
+/* Exit value used when 'print_and_abort' is used. */
+extern int obstack_exit_failure;
+
+/* Pointer to beginning of object being allocated or to be allocated next.
+ Note that this might not be the final address of the object
+ because a new chunk might be needed to hold the final size. */
+
+#define obstack_base(h) ((void *) (h)->object_base)
+
+/* Size for allocating ordinary chunks. */
+
+#define obstack_chunk_size(h) ((h)->chunk_size)
+
+/* Pointer to next byte not yet allocated in current chunk. */
+
+#define obstack_next_free(h) ((h)->next_free)
+
+/* Mask specifying low bits that should be clear in address of an object. */
+
+#define obstack_alignment_mask(h) ((h)->alignment_mask)
+
+/* To prevent prototype warnings provide complete argument list. */
+#define obstack_init(h) \
+ _obstack_begin ((h), 0, 0, \
+ (void *(*) (long)) obstack_chunk_alloc, \
+ (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_begin(h, size) \
+ _obstack_begin ((h), (size), 0, \
+ (void *(*) (long)) obstack_chunk_alloc, \
+ (void (*) (void *)) obstack_chunk_free)
+
+#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
+ _obstack_begin ((h), (size), (alignment), \
+ (void *(*) (long)) (chunkfun), \
+ (void (*) (void *)) (freefun))
+
+#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
+ _obstack_begin_1 ((h), (size), (alignment), \
+ (void *(*) (void *, long)) (chunkfun), \
+ (void (*) (void *, void *)) (freefun), (arg))
+
+#define obstack_chunkfun(h, newchunkfun) \
+ ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun))
+
+#define obstack_freefun(h, newfreefun) \
+ ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun))
+
+#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
+
+#define obstack_blank_fast(h,n) ((h)->next_free += (n))
+
+#define obstack_memory_used(h) _obstack_memory_used (h)
+
+#if defined __GNUC__
+/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
+ does not implement __extension__. But that compiler doesn't define
+ __GNUC_MINOR__. */
+# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
+# define __extension__
+# endif
+
+/* For GNU C, if not -traditional,
+ we can define these macros to compute all args only once
+ without using a global variable.
+ Also, we can avoid using the 'temp' slot, to make faster code. */
+
+# define obstack_object_size(OBSTACK) \
+ __extension__ \
+ ({ struct obstack const *__o = (OBSTACK); \
+ (unsigned) (__o->next_free - __o->object_base); })
+
+# define obstack_room(OBSTACK) \
+ __extension__ \
+ ({ struct obstack const *__o = (OBSTACK); \
+ (unsigned) (__o->chunk_limit - __o->next_free); })
+
+# define obstack_make_room(OBSTACK,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->chunk_limit - __o->next_free < __len) \
+ _obstack_newchunk (__o, __len); \
+ (void) 0; })
+
+# define obstack_empty_p(OBSTACK) \
+ __extension__ \
+ ({ struct obstack const *__o = (OBSTACK); \
+ (__o->chunk->prev == 0 \
+ && __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \
+ __o->chunk->contents, \
+ __o->alignment_mask)); })
+
+# define obstack_grow(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->next_free + __len > __o->chunk_limit) \
+ _obstack_newchunk (__o, __len); \
+ memcpy (__o->next_free, where, __len); \
+ __o->next_free += __len; \
+ (void) 0; })
+
+# define obstack_grow0(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->next_free + __len + 1 > __o->chunk_limit) \
+ _obstack_newchunk (__o, __len + 1); \
+ memcpy (__o->next_free, where, __len); \
+ __o->next_free += __len; \
+ *(__o->next_free)++ = 0; \
+ (void) 0; })
+
+# define obstack_1grow(OBSTACK,datum) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ if (__o->next_free + 1 > __o->chunk_limit) \
+ _obstack_newchunk (__o, 1); \
+ obstack_1grow_fast (__o, datum); \
+ (void) 0; })
+
+/* These assume that the obstack alignment is good enough for pointers
+ or ints, and that the data added so far to the current object
+ shares that much alignment. */
+
+# define obstack_ptr_grow(OBSTACK,datum) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
+ _obstack_newchunk (__o, sizeof (void *)); \
+ obstack_ptr_grow_fast (__o, datum); }) \
+
+# define obstack_int_grow(OBSTACK,datum) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ if (__o->next_free + sizeof (int) > __o->chunk_limit) \
+ _obstack_newchunk (__o, sizeof (int)); \
+ obstack_int_grow_fast (__o, datum); })
+
+# define obstack_ptr_grow_fast(OBSTACK,aptr) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ void *__p1 = __o1->next_free; \
+ *(const void **) __p1 = (aptr); \
+ __o1->next_free += sizeof (const void *); \
+ (void) 0; })
+
+# define obstack_int_grow_fast(OBSTACK,aint) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ void *__p1 = __o1->next_free; \
+ *(int *) __p1 = (aint); \
+ __o1->next_free += sizeof (int); \
+ (void) 0; })
+
+# define obstack_blank(OBSTACK,length) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ int __len = (length); \
+ if (__o->chunk_limit - __o->next_free < __len) \
+ _obstack_newchunk (__o, __len); \
+ obstack_blank_fast (__o, __len); \
+ (void) 0; })
+
+# define obstack_alloc(OBSTACK,length) \
+__extension__ \
+({ struct obstack *__h = (OBSTACK); \
+ obstack_blank (__h, (length)); \
+ obstack_finish (__h); })
+
+# define obstack_copy(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__h = (OBSTACK); \
+ obstack_grow (__h, (where), (length)); \
+ obstack_finish (__h); })
+
+# define obstack_copy0(OBSTACK,where,length) \
+__extension__ \
+({ struct obstack *__h = (OBSTACK); \
+ obstack_grow0 (__h, (where), (length)); \
+ obstack_finish (__h); })
+
+/* The local variable is named __o1 to avoid a name conflict
+ when obstack_blank is called. */
+# define obstack_finish(OBSTACK) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ void *__value = (void *) __o1->object_base; \
+ if (__o1->next_free == __value) \
+ __o1->maybe_empty_object = 1; \
+ __o1->next_free \
+ = __PTR_ALIGN (__o1->object_base, __o1->next_free, \
+ __o1->alignment_mask); \
+ if (__o1->next_free - (char *)__o1->chunk \
+ > __o1->chunk_limit - (char *)__o1->chunk) \
+ __o1->next_free = __o1->chunk_limit; \
+ __o1->object_base = __o1->next_free; \
+ __value; })
+
+# define obstack_free(OBSTACK, OBJ) \
+__extension__ \
+({ struct obstack *__o = (OBSTACK); \
+ void *__obj = (OBJ); \
+ if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
+ __o->next_free = __o->object_base = (char *)__obj; \
+ else (__obstack_free) (__o, __obj); })
+
+#else /* not __GNUC__ */
+
+# define obstack_object_size(h) \
+ (unsigned) ((h)->next_free - (h)->object_base)
+
+# define obstack_room(h) \
+ (unsigned) ((h)->chunk_limit - (h)->next_free)
+
+# define obstack_empty_p(h) \
+ ((h)->chunk->prev == 0 \
+ && (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \
+ (h)->chunk->contents, \
+ (h)->alignment_mask))
+
+/* Note that the call to _obstack_newchunk is enclosed in (..., 0)
+ so that we can avoid having void expressions
+ in the arms of the conditional expression.
+ Casting the third operand to void was tried before,
+ but some compilers won't accept it. */
+
+# define obstack_make_room(h,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
+
+# define obstack_grow(h,where,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
+ memcpy ((h)->next_free, where, (h)->temp.tempint), \
+ (h)->next_free += (h)->temp.tempint)
+
+# define obstack_grow0(h,where,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \
+ memcpy ((h)->next_free, where, (h)->temp.tempint), \
+ (h)->next_free += (h)->temp.tempint, \
+ *((h)->next_free)++ = 0)
+
+# define obstack_1grow(h,datum) \
+( (((h)->next_free + 1 > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), 1), 0) : 0), \
+ obstack_1grow_fast (h, datum))
+
+# define obstack_ptr_grow(h,datum) \
+( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
+ obstack_ptr_grow_fast (h, datum))
+
+# define obstack_int_grow(h,datum) \
+( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
+ ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
+ obstack_int_grow_fast (h, datum))
+
+# define obstack_ptr_grow_fast(h,aptr) \
+ (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
+
+# define obstack_int_grow_fast(h,aint) \
+ (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
+
+# define obstack_blank(h,length) \
+( (h)->temp.tempint = (length), \
+ (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \
+ ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
+ obstack_blank_fast (h, (h)->temp.tempint))
+
+# define obstack_alloc(h,length) \
+ (obstack_blank ((h), (length)), obstack_finish ((h)))
+
+# define obstack_copy(h,where,length) \
+ (obstack_grow ((h), (where), (length)), obstack_finish ((h)))
+
+# define obstack_copy0(h,where,length) \
+ (obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
+
+# define obstack_finish(h) \
+( ((h)->next_free == (h)->object_base \
+ ? (((h)->maybe_empty_object = 1), 0) \
+ : 0), \
+ (h)->temp.tempptr = (h)->object_base, \
+ (h)->next_free \
+ = __PTR_ALIGN ((h)->object_base, (h)->next_free, \
+ (h)->alignment_mask), \
+ (((h)->next_free - (char *) (h)->chunk \
+ > (h)->chunk_limit - (char *) (h)->chunk) \
+ ? ((h)->next_free = (h)->chunk_limit) : 0), \
+ (h)->object_base = (h)->next_free, \
+ (h)->temp.tempptr)
+
+# define obstack_free(h,obj) \
+( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
+ ((((h)->temp.tempint > 0 \
+ && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
+ ? (int) ((h)->next_free = (h)->object_base \
+ = (h)->temp.tempint + (char *) (h)->chunk) \
+ : (((__obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
+
+#endif /* not __GNUC__ */
+
+#ifdef __cplusplus
+} /* C++ */
+#endif
+
#if defined(_WIN32)
int obstack_printf(struct obstack *obs, const char *format, ...);
#endif
-#endif /* obstack.h */
+#endif /* obstack.h */
diff --git a/contrib/tools/bison/gnulib/src/obstack_printf.c b/contrib/tools/bison/gnulib/src/obstack_printf.c
index 291dcd52a4..441e93dc8a 100644
--- a/contrib/tools/bison/gnulib/src/obstack_printf.c
+++ b/contrib/tools/bison/gnulib/src/obstack_printf.c
@@ -1,93 +1,93 @@
-/* Formatted output to obstacks.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-#include "obstack.h"
-#include "vasnprintf.h"
-
-#include <errno.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
+/* Formatted output to obstacks.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+#include "obstack.h"
+#include "vasnprintf.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
int obstack_vprintf(struct obstack *obs, const char *format, va_list args);
-/* Grow an obstack with formatted output. Return the number of bytes
- added to OBS. No trailing nul byte is added, and the object should
- be closed with obstack_finish before use.
-
- Upon memory allocation error, call obstack_alloc_failed_handler.
- Upon other error, return -1. */
-int
-obstack_printf (struct obstack *obs, const char *format, ...)
-{
- va_list args;
- int result;
-
- va_start (args, format);
- result = obstack_vprintf (obs, format, args);
- va_end (args);
- return result;
-}
-
-/* Grow an obstack with formatted output. Return the number of bytes
- added to OBS. No trailing nul byte is added, and the object should
- be closed with obstack_finish before use.
-
- Upon memory allocation error, call obstack_alloc_failed_handler.
- Upon other error, return -1. */
-int
-obstack_vprintf (struct obstack *obs, const char *format, va_list args)
-{
- /* If we are close to the end of the current obstack chunk, use a
- stack-allocated buffer and copy, to reduce the likelihood of a
- small-size malloc. Otherwise, print directly into the
- obstack. */
- enum { CUTOFF = 1024 };
- char buf[CUTOFF];
- char *base = obstack_next_free (obs);
- size_t len = obstack_room (obs);
- char *str;
-
- if (len < CUTOFF)
- {
- base = buf;
- len = CUTOFF;
- }
- str = vasnprintf (base, &len, format, args);
- if (!str)
- {
- if (errno == ENOMEM)
- obstack_alloc_failed_handler ();
- return -1;
- }
- if (str == base && str != buf)
- /* The output was already computed in place, but we need to
- account for its size. */
- obstack_blank_fast (obs, len);
- else
- {
- /* The output exceeded available obstack space or we used buf;
- copy the resulting string. */
- obstack_grow (obs, str, len);
- if (str != buf)
- free (str);
- }
- return len;
-}
+/* Grow an obstack with formatted output. Return the number of bytes
+ added to OBS. No trailing nul byte is added, and the object should
+ be closed with obstack_finish before use.
+
+ Upon memory allocation error, call obstack_alloc_failed_handler.
+ Upon other error, return -1. */
+int
+obstack_printf (struct obstack *obs, const char *format, ...)
+{
+ va_list args;
+ int result;
+
+ va_start (args, format);
+ result = obstack_vprintf (obs, format, args);
+ va_end (args);
+ return result;
+}
+
+/* Grow an obstack with formatted output. Return the number of bytes
+ added to OBS. No trailing nul byte is added, and the object should
+ be closed with obstack_finish before use.
+
+ Upon memory allocation error, call obstack_alloc_failed_handler.
+ Upon other error, return -1. */
+int
+obstack_vprintf (struct obstack *obs, const char *format, va_list args)
+{
+ /* If we are close to the end of the current obstack chunk, use a
+ stack-allocated buffer and copy, to reduce the likelihood of a
+ small-size malloc. Otherwise, print directly into the
+ obstack. */
+ enum { CUTOFF = 1024 };
+ char buf[CUTOFF];
+ char *base = obstack_next_free (obs);
+ size_t len = obstack_room (obs);
+ char *str;
+
+ if (len < CUTOFF)
+ {
+ base = buf;
+ len = CUTOFF;
+ }
+ str = vasnprintf (base, &len, format, args);
+ if (!str)
+ {
+ if (errno == ENOMEM)
+ obstack_alloc_failed_handler ();
+ return -1;
+ }
+ if (str == base && str != buf)
+ /* The output was already computed in place, but we need to
+ account for its size. */
+ obstack_blank_fast (obs, len);
+ else
+ {
+ /* The output exceeded available obstack space or we used buf;
+ copy the resulting string. */
+ obstack_grow (obs, str, len);
+ if (str != buf)
+ free (str);
+ }
+ return len;
+}
diff --git a/contrib/tools/bison/gnulib/src/open.c b/contrib/tools/bison/gnulib/src/open.c
index a0c43eadf9..c4bfaf23c2 100644
--- a/contrib/tools/bison/gnulib/src/open.c
+++ b/contrib/tools/bison/gnulib/src/open.c
@@ -1,181 +1,181 @@
-/* Open a descriptor to a file.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
-
-/* If the user's config.h happens to include <fcntl.h>, let it include only
- the system's <fcntl.h> here, so that orig_open doesn't recurse to
- rpl_open. */
-#define __need_system_fcntl_h
-#include <config.h>
-
-/* Get the original definition of open. It might be defined as a macro. */
-#include <fcntl.h>
-#include <sys/types.h>
-#undef __need_system_fcntl_h
-
-static int
-orig_open (const char *filename, int flags, mode_t mode)
-{
- return open (filename, flags, mode);
-}
-
-/* Specification. */
-/* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates
- this include because of the preliminary #include <fcntl.h> above. */
-#include "fcntl.h"
-
-#include <errno.h>
-#include <stdarg.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#ifndef REPLACE_OPEN_DIRECTORY
-# define REPLACE_OPEN_DIRECTORY 0
-#endif
-
-int
-open (const char *filename, int flags, ...)
-{
- mode_t mode;
- int fd;
-
- mode = 0;
- if (flags & O_CREAT)
- {
- va_list arg;
- va_start (arg, flags);
-
- /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
- creates crashing code when 'mode_t' is smaller than 'int'. */
- mode = va_arg (arg, PROMOTED_MODE_T);
-
- va_end (arg);
- }
-
-#if GNULIB_defined_O_NONBLOCK
- /* The only known platform that lacks O_NONBLOCK is mingw, but it
- also lacks named pipes and Unix sockets, which are the only two
- file types that require non-blocking handling in open().
- Therefore, it is safe to ignore O_NONBLOCK here. It is handy
- that mingw also lacks openat(), so that is also covered here. */
- flags &= ~O_NONBLOCK;
-#endif
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- if (strcmp (filename, "/dev/null") == 0)
- filename = "NUL";
-#endif
-
-#if OPEN_TRAILING_SLASH_BUG
- /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
- is specified, then fail.
- Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
- says that
- "A pathname that contains at least one non-slash character and that
- ends with one or more trailing slashes shall be resolved as if a
- single dot character ( '.' ) were appended to the pathname."
- and
- "The special filename dot shall refer to the directory specified by
- its predecessor."
- If the named file already exists as a directory, then
- - if O_CREAT is specified, open() must fail because of the semantics
- of O_CREAT,
- - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX
- <http://www.opengroup.org/susv3/functions/open.html> says that it
- fails with errno = EISDIR in this case.
- If the named file does not exist or does not name a directory, then
- - if O_CREAT is specified, open() must fail since open() cannot create
- directories,
- - if O_WRONLY or O_RDWR is specified, open() must fail because the
- file does not contain a '.' directory. */
- if (flags & (O_CREAT | O_WRONLY | O_RDWR))
- {
- size_t len = strlen (filename);
- if (len > 0 && filename[len - 1] == '/')
- {
- errno = EISDIR;
- return -1;
- }
- }
-#endif
-
- fd = orig_open (filename, flags, mode);
-
-#if REPLACE_FCHDIR
- /* Implementing fchdir and fdopendir requires the ability to open a
- directory file descriptor. If open doesn't support that (as on
- mingw), we use a dummy file that behaves the same as directories
- on Linux (ie. always reports EOF on attempts to read()), and
- override fstat() in fchdir.c to hide the fact that we have a
- dummy. */
- if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
- && ((flags & O_ACCMODE) == O_RDONLY
- || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH)))
- {
- struct stat statbuf;
- if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
- {
- /* Maximum recursion depth of 1. */
- fd = open ("/dev/null", flags, mode);
- if (0 <= fd)
- fd = _gl_register_fd (fd, filename);
- }
- else
- errno = EACCES;
- }
-#endif
-
-#if OPEN_TRAILING_SLASH_BUG
- /* If the filename ends in a slash and fd does not refer to a directory,
- then fail.
- Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
- says that
- "A pathname that contains at least one non-slash character and that
- ends with one or more trailing slashes shall be resolved as if a
- single dot character ( '.' ) were appended to the pathname."
- and
- "The special filename dot shall refer to the directory specified by
- its predecessor."
- If the named file without the slash is not a directory, open() must fail
- with ENOTDIR. */
- if (fd >= 0)
- {
- /* We know len is positive, since open did not fail with ENOENT. */
- size_t len = strlen (filename);
- if (filename[len - 1] == '/')
- {
- struct stat statbuf;
-
- if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
- {
- close (fd);
- errno = ENOTDIR;
- return -1;
- }
- }
- }
-#endif
-
-#if REPLACE_FCHDIR
- if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
- fd = _gl_register_fd (fd, filename);
-#endif
-
- return fd;
-}
+/* Open a descriptor to a file.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007. */
+
+/* If the user's config.h happens to include <fcntl.h>, let it include only
+ the system's <fcntl.h> here, so that orig_open doesn't recurse to
+ rpl_open. */
+#define __need_system_fcntl_h
+#include <config.h>
+
+/* Get the original definition of open. It might be defined as a macro. */
+#include <fcntl.h>
+#include <sys/types.h>
+#undef __need_system_fcntl_h
+
+static int
+orig_open (const char *filename, int flags, mode_t mode)
+{
+ return open (filename, flags, mode);
+}
+
+/* Specification. */
+/* Write "fcntl.h" here, not <fcntl.h>, otherwise OSF/1 5.1 DTK cc eliminates
+ this include because of the preliminary #include <fcntl.h> above. */
+#include "fcntl.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#ifndef REPLACE_OPEN_DIRECTORY
+# define REPLACE_OPEN_DIRECTORY 0
+#endif
+
+int
+open (const char *filename, int flags, ...)
+{
+ mode_t mode;
+ int fd;
+
+ mode = 0;
+ if (flags & O_CREAT)
+ {
+ va_list arg;
+ va_start (arg, flags);
+
+ /* We have to use PROMOTED_MODE_T instead of mode_t, otherwise GCC 4
+ creates crashing code when 'mode_t' is smaller than 'int'. */
+ mode = va_arg (arg, PROMOTED_MODE_T);
+
+ va_end (arg);
+ }
+
+#if GNULIB_defined_O_NONBLOCK
+ /* The only known platform that lacks O_NONBLOCK is mingw, but it
+ also lacks named pipes and Unix sockets, which are the only two
+ file types that require non-blocking handling in open().
+ Therefore, it is safe to ignore O_NONBLOCK here. It is handy
+ that mingw also lacks openat(), so that is also covered here. */
+ flags &= ~O_NONBLOCK;
+#endif
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ if (strcmp (filename, "/dev/null") == 0)
+ filename = "NUL";
+#endif
+
+#if OPEN_TRAILING_SLASH_BUG
+ /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
+ is specified, then fail.
+ Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
+ says that
+ "A pathname that contains at least one non-slash character and that
+ ends with one or more trailing slashes shall be resolved as if a
+ single dot character ( '.' ) were appended to the pathname."
+ and
+ "The special filename dot shall refer to the directory specified by
+ its predecessor."
+ If the named file already exists as a directory, then
+ - if O_CREAT is specified, open() must fail because of the semantics
+ of O_CREAT,
+ - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX
+ <http://www.opengroup.org/susv3/functions/open.html> says that it
+ fails with errno = EISDIR in this case.
+ If the named file does not exist or does not name a directory, then
+ - if O_CREAT is specified, open() must fail since open() cannot create
+ directories,
+ - if O_WRONLY or O_RDWR is specified, open() must fail because the
+ file does not contain a '.' directory. */
+ if (flags & (O_CREAT | O_WRONLY | O_RDWR))
+ {
+ size_t len = strlen (filename);
+ if (len > 0 && filename[len - 1] == '/')
+ {
+ errno = EISDIR;
+ return -1;
+ }
+ }
+#endif
+
+ fd = orig_open (filename, flags, mode);
+
+#if REPLACE_FCHDIR
+ /* Implementing fchdir and fdopendir requires the ability to open a
+ directory file descriptor. If open doesn't support that (as on
+ mingw), we use a dummy file that behaves the same as directories
+ on Linux (ie. always reports EOF on attempts to read()), and
+ override fstat() in fchdir.c to hide the fact that we have a
+ dummy. */
+ if (REPLACE_OPEN_DIRECTORY && fd < 0 && errno == EACCES
+ && ((flags & O_ACCMODE) == O_RDONLY
+ || (O_SEARCH != O_RDONLY && (flags & O_ACCMODE) == O_SEARCH)))
+ {
+ struct stat statbuf;
+ if (stat (filename, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
+ {
+ /* Maximum recursion depth of 1. */
+ fd = open ("/dev/null", flags, mode);
+ if (0 <= fd)
+ fd = _gl_register_fd (fd, filename);
+ }
+ else
+ errno = EACCES;
+ }
+#endif
+
+#if OPEN_TRAILING_SLASH_BUG
+ /* If the filename ends in a slash and fd does not refer to a directory,
+ then fail.
+ Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
+ says that
+ "A pathname that contains at least one non-slash character and that
+ ends with one or more trailing slashes shall be resolved as if a
+ single dot character ( '.' ) were appended to the pathname."
+ and
+ "The special filename dot shall refer to the directory specified by
+ its predecessor."
+ If the named file without the slash is not a directory, open() must fail
+ with ENOTDIR. */
+ if (fd >= 0)
+ {
+ /* We know len is positive, since open did not fail with ENOENT. */
+ size_t len = strlen (filename);
+ if (filename[len - 1] == '/')
+ {
+ struct stat statbuf;
+
+ if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
+ {
+ close (fd);
+ errno = ENOTDIR;
+ return -1;
+ }
+ }
+ }
+#endif
+
+#if REPLACE_FCHDIR
+ if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
+ fd = _gl_register_fd (fd, filename);
+#endif
+
+ return fd;
+}
diff --git a/contrib/tools/bison/gnulib/src/pathmax.h b/contrib/tools/bison/gnulib/src/pathmax.h
index a9ddc33d17..4c3ad51ed5 100644
--- a/contrib/tools/bison/gnulib/src/pathmax.h
+++ b/contrib/tools/bison/gnulib/src/pathmax.h
@@ -1,83 +1,83 @@
-/* Define PATH_MAX somehow. Requires sys/types.h.
- Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _PATHMAX_H
-# define _PATHMAX_H
-
-/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
- including the terminating NUL byte.
- <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
- PATH_MAX is not defined on systems which have no limit on filename length,
- such as GNU/Hurd.
-
- This file does *not* define PATH_MAX always. Programs that use this file
- can handle the GNU/Hurd case in several ways:
- - Either with a package-wide handling, or with a per-file handling,
- - Either through a
- #ifdef PATH_MAX
- or through a fallback like
- #ifndef PATH_MAX
- # define PATH_MAX 8192
- #endif
- or through a fallback like
- #ifndef PATH_MAX
- # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
- #endif
- */
-
-# include <unistd.h>
-
-# include <limits.h>
-
-# ifndef _POSIX_PATH_MAX
-# define _POSIX_PATH_MAX 256
-# endif
-
-/* Don't include sys/param.h if it already has been. */
-# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
-# include <sys/param.h>
-# endif
-
-# if !defined PATH_MAX && defined MAXPATHLEN
-# define PATH_MAX MAXPATHLEN
-# endif
-
-# ifdef __hpux
-/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
- *not* including the terminating NUL byte, and is set to 1023.
- Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
- not defined at all any more. */
-# undef PATH_MAX
-# define PATH_MAX 1024
-# endif
-
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
- section "Maximum Path Length Limitation",
- <http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath>
- explains that the maximum size of a filename, including the terminating
- NUL byte, is 260 = 3 + 256 + 1.
- This is the same value as
- - FILENAME_MAX in <stdio.h>,
- - _MAX_PATH in <stdlib.h>,
- - MAX_PATH in <windef.h>.
- Undefine the original value, because mingw's <limits.h> gets it wrong. */
-# undef PATH_MAX
-# define PATH_MAX 260
-# endif
-
-#endif /* _PATHMAX_H */
+/* Define PATH_MAX somehow. Requires sys/types.h.
+ Copyright (C) 1992, 1999, 2001, 2003, 2005, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _PATHMAX_H
+# define _PATHMAX_H
+
+/* POSIX:2008 defines PATH_MAX to be the maximum number of bytes in a filename,
+ including the terminating NUL byte.
+ <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
+ PATH_MAX is not defined on systems which have no limit on filename length,
+ such as GNU/Hurd.
+
+ This file does *not* define PATH_MAX always. Programs that use this file
+ can handle the GNU/Hurd case in several ways:
+ - Either with a package-wide handling, or with a per-file handling,
+ - Either through a
+ #ifdef PATH_MAX
+ or through a fallback like
+ #ifndef PATH_MAX
+ # define PATH_MAX 8192
+ #endif
+ or through a fallback like
+ #ifndef PATH_MAX
+ # define PATH_MAX pathconf ("/", _PC_PATH_MAX)
+ #endif
+ */
+
+# include <unistd.h>
+
+# include <limits.h>
+
+# ifndef _POSIX_PATH_MAX
+# define _POSIX_PATH_MAX 256
+# endif
+
+/* Don't include sys/param.h if it already has been. */
+# if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
+# include <sys/param.h>
+# endif
+
+# if !defined PATH_MAX && defined MAXPATHLEN
+# define PATH_MAX MAXPATHLEN
+# endif
+
+# ifdef __hpux
+/* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename,
+ *not* including the terminating NUL byte, and is set to 1023.
+ Additionally, when _XOPEN_SOURCE is defined to 500 or more, PATH_MAX is
+ not defined at all any more. */
+# undef PATH_MAX
+# define PATH_MAX 1024
+# endif
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* The page "Naming Files, Paths, and Namespaces" on msdn.microsoft.com,
+ section "Maximum Path Length Limitation",
+ <http://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#maxpath>
+ explains that the maximum size of a filename, including the terminating
+ NUL byte, is 260 = 3 + 256 + 1.
+ This is the same value as
+ - FILENAME_MAX in <stdio.h>,
+ - _MAX_PATH in <stdlib.h>,
+ - MAX_PATH in <windef.h>.
+ Undefine the original value, because mingw's <limits.h> gets it wrong. */
+# undef PATH_MAX
+# define PATH_MAX 260
+# endif
+
+#endif /* _PATHMAX_H */
diff --git a/contrib/tools/bison/gnulib/src/perror.c b/contrib/tools/bison/gnulib/src/perror.c
index 74e088cc73..51e827b5ed 100644
--- a/contrib/tools/bison/gnulib/src/perror.c
+++ b/contrib/tools/bison/gnulib/src/perror.c
@@ -1,32 +1,32 @@
-/* Print a message describing error code.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible and Simon Josefsson.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-void
-perror (const char *string)
-{
- if (string != NULL && *string != '\0')
+/* Print a message describing error code.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible and Simon Josefsson.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+void
+perror (const char *string)
+{
+ if (string != NULL && *string != '\0')
fprintf (stderr, "%s\n", string);
-}
+}
diff --git a/contrib/tools/bison/gnulib/src/pipe-safer.c b/contrib/tools/bison/gnulib/src/pipe-safer.c
index f2e0ad6fb0..19d961c90c 100644
--- a/contrib/tools/bison/gnulib/src/pipe-safer.c
+++ b/contrib/tools/bison/gnulib/src/pipe-safer.c
@@ -1,56 +1,56 @@
-/* Invoke pipe, but avoid some glitches.
- Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#include <config.h>
-
-#include "unistd-safer.h"
-
-#include <unistd.h>
-#include <errno.h>
-
-/* Like pipe, but ensure that neither of the file descriptors is
- STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. Fail with ENOSYS on
- platforms that lack pipe. */
-
-int
-pipe_safer (int fd[2])
-{
-#if HAVE_PIPE
- if (pipe (fd) == 0)
- {
- int i;
- for (i = 0; i < 2; i++)
- {
- fd[i] = fd_safer (fd[i]);
- if (fd[i] < 0)
- {
- int e = errno;
- close (fd[1 - i]);
- errno = e;
- return -1;
- }
- }
-
- return 0;
- }
-#else
- errno = ENOSYS;
-#endif
-
- return -1;
-}
+/* Invoke pipe, but avoid some glitches.
+ Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#include <config.h>
+
+#include "unistd-safer.h"
+
+#include <unistd.h>
+#include <errno.h>
+
+/* Like pipe, but ensure that neither of the file descriptors is
+ STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. Fail with ENOSYS on
+ platforms that lack pipe. */
+
+int
+pipe_safer (int fd[2])
+{
+#if HAVE_PIPE
+ if (pipe (fd) == 0)
+ {
+ int i;
+ for (i = 0; i < 2; i++)
+ {
+ fd[i] = fd_safer (fd[i]);
+ if (fd[i] < 0)
+ {
+ int e = errno;
+ close (fd[1 - i]);
+ errno = e;
+ return -1;
+ }
+ }
+
+ return 0;
+ }
+#else
+ errno = ENOSYS;
+#endif
+
+ return -1;
+}
diff --git a/contrib/tools/bison/gnulib/src/pipe2-safer.c b/contrib/tools/bison/gnulib/src/pipe2-safer.c
index e831d0c6c1..cd1ebb3c0e 100644
--- a/contrib/tools/bison/gnulib/src/pipe2-safer.c
+++ b/contrib/tools/bison/gnulib/src/pipe2-safer.c
@@ -1,52 +1,52 @@
-/* Invoke pipe2, but avoid some glitches.
- Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Eric Blake. */
-
-#include <config.h>
-
-/* Specification. */
-#include "unistd-safer.h"
-
-#include <unistd.h>
-#include <errno.h>
-
-/* Like pipe2, but ensure that neither of the file descriptors is
- STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */
-
-int
-pipe2_safer (int fd[2], int flags)
-{
- /* This is a generalization of the pipe_safer implementation. */
- if (pipe2 (fd, flags) == 0)
- {
- int i;
- for (i = 0; i < 2; i++)
- {
- fd[i] = fd_safer_flag (fd[i], flags);
- if (fd[i] < 0)
- {
- int e = errno;
- close (fd[1 - i]);
- errno = e;
- return -1;
- }
- }
-
- return 0;
- }
- return -1;
-}
+/* Invoke pipe2, but avoid some glitches.
+ Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake. */
+
+#include <config.h>
+
+/* Specification. */
+#include "unistd-safer.h"
+
+#include <unistd.h>
+#include <errno.h>
+
+/* Like pipe2, but ensure that neither of the file descriptors is
+ STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */
+
+int
+pipe2_safer (int fd[2], int flags)
+{
+ /* This is a generalization of the pipe_safer implementation. */
+ if (pipe2 (fd, flags) == 0)
+ {
+ int i;
+ for (i = 0; i < 2; i++)
+ {
+ fd[i] = fd_safer_flag (fd[i], flags);
+ if (fd[i] < 0)
+ {
+ int e = errno;
+ close (fd[1 - i]);
+ errno = e;
+ return -1;
+ }
+ }
+
+ return 0;
+ }
+ return -1;
+}
diff --git a/contrib/tools/bison/gnulib/src/pipe2.c b/contrib/tools/bison/gnulib/src/pipe2.c
index 211d75545c..1a84151d37 100644
--- a/contrib/tools/bison/gnulib/src/pipe2.c
+++ b/contrib/tools/bison/gnulib/src/pipe2.c
@@ -1,168 +1,168 @@
-/* Create a pipe, with specific opening flags.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <unistd.h>
-
-#include <errno.h>
-#include <fcntl.h>
-
-#include "binary-io.h"
-#include "verify.h"
-
-#if GNULIB_defined_O_NONBLOCK
-# include "nonblocking.h"
-#endif
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Native Windows API. */
-
-# include <io.h>
-
-#endif
-
-int
-pipe2 (int fd[2], int flags)
-{
- /* Mingw _pipe() corrupts fd on failure; also, if we succeed at
- creating the pipe but later fail at changing fcntl, we want
- to leave fd unchanged: http://austingroupbugs.net/view.php?id=467 */
- int tmp[2];
- tmp[0] = fd[0];
- tmp[1] = fd[1];
-
-#if HAVE_PIPE2
-# undef pipe2
- /* Try the system call first, if it exists. (We may be running with a glibc
- that has the function but with an older kernel that lacks it.) */
- {
- /* Cache the information whether the system call really exists. */
- static int have_pipe2_really; /* 0 = unknown, 1 = yes, -1 = no */
- if (have_pipe2_really >= 0)
- {
- int result = pipe2 (fd, flags);
- if (!(result < 0 && errno == ENOSYS))
- {
- have_pipe2_really = 1;
- return result;
- }
- have_pipe2_really = -1;
- }
- }
-#endif
-
- /* Check the supported flags. */
- if ((flags & ~(O_CLOEXEC | O_NONBLOCK | O_BINARY | O_TEXT)) != 0)
- {
- errno = EINVAL;
- return -1;
- }
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Native Windows API. */
-
- if (_pipe (fd, 4096, flags & ~O_NONBLOCK) < 0)
- {
- fd[0] = tmp[0];
- fd[1] = tmp[1];
- return -1;
- }
-
- /* O_NONBLOCK handling.
- On native Windows platforms, O_NONBLOCK is defined by gnulib. Use the
- functions defined by the gnulib module 'nonblocking'. */
-# if GNULIB_defined_O_NONBLOCK
- if (flags & O_NONBLOCK)
- {
- if (set_nonblocking_flag (fd[0], true) != 0
- || set_nonblocking_flag (fd[1], true) != 0)
- goto fail;
- }
-# else
- {
- verify (O_NONBLOCK == 0);
- }
-# endif
-
- return 0;
-
-#else
-/* Unix API. */
-
- if (pipe (fd) < 0)
- return -1;
-
- /* POSIX <http://www.opengroup.org/onlinepubs/9699919799/functions/pipe.html>
- says that initially, the O_NONBLOCK and FD_CLOEXEC flags are cleared on
- both fd[0] and fd[1]. */
-
- /* O_NONBLOCK handling.
- On Unix platforms, O_NONBLOCK is defined by the system. Use fcntl(). */
- if (flags & O_NONBLOCK)
- {
- int fcntl_flags;
-
- if ((fcntl_flags = fcntl (fd[1], F_GETFL, 0)) < 0
- || fcntl (fd[1], F_SETFL, fcntl_flags | O_NONBLOCK) == -1
- || (fcntl_flags = fcntl (fd[0], F_GETFL, 0)) < 0
- || fcntl (fd[0], F_SETFL, fcntl_flags | O_NONBLOCK) == -1)
- goto fail;
- }
-
- if (flags & O_CLOEXEC)
- {
- int fcntl_flags;
-
- if ((fcntl_flags = fcntl (fd[1], F_GETFD, 0)) < 0
- || fcntl (fd[1], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1
- || (fcntl_flags = fcntl (fd[0], F_GETFD, 0)) < 0
- || fcntl (fd[0], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1)
- goto fail;
- }
-
-# if O_BINARY
- if (flags & O_BINARY)
- {
- set_binary_mode (fd[1], O_BINARY);
- set_binary_mode (fd[0], O_BINARY);
- }
- else if (flags & O_TEXT)
- {
- set_binary_mode (fd[1], O_TEXT);
- set_binary_mode (fd[0], O_TEXT);
- }
-# endif
-
- return 0;
-
-#endif
-
-#if GNULIB_defined_O_NONBLOCK || \
- !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
- fail:
- {
- int saved_errno = errno;
- close (fd[0]);
- close (fd[1]);
- fd[0] = tmp[0];
- fd[1] = tmp[1];
- errno = saved_errno;
- return -1;
- }
-#endif
-}
+/* Create a pipe, with specific opening flags.
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#include <errno.h>
+#include <fcntl.h>
+
+#include "binary-io.h"
+#include "verify.h"
+
+#if GNULIB_defined_O_NONBLOCK
+# include "nonblocking.h"
+#endif
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Native Windows API. */
+
+# include <io.h>
+
+#endif
+
+int
+pipe2 (int fd[2], int flags)
+{
+ /* Mingw _pipe() corrupts fd on failure; also, if we succeed at
+ creating the pipe but later fail at changing fcntl, we want
+ to leave fd unchanged: http://austingroupbugs.net/view.php?id=467 */
+ int tmp[2];
+ tmp[0] = fd[0];
+ tmp[1] = fd[1];
+
+#if HAVE_PIPE2
+# undef pipe2
+ /* Try the system call first, if it exists. (We may be running with a glibc
+ that has the function but with an older kernel that lacks it.) */
+ {
+ /* Cache the information whether the system call really exists. */
+ static int have_pipe2_really; /* 0 = unknown, 1 = yes, -1 = no */
+ if (have_pipe2_really >= 0)
+ {
+ int result = pipe2 (fd, flags);
+ if (!(result < 0 && errno == ENOSYS))
+ {
+ have_pipe2_really = 1;
+ return result;
+ }
+ have_pipe2_really = -1;
+ }
+ }
+#endif
+
+ /* Check the supported flags. */
+ if ((flags & ~(O_CLOEXEC | O_NONBLOCK | O_BINARY | O_TEXT)) != 0)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Native Windows API. */
+
+ if (_pipe (fd, 4096, flags & ~O_NONBLOCK) < 0)
+ {
+ fd[0] = tmp[0];
+ fd[1] = tmp[1];
+ return -1;
+ }
+
+ /* O_NONBLOCK handling.
+ On native Windows platforms, O_NONBLOCK is defined by gnulib. Use the
+ functions defined by the gnulib module 'nonblocking'. */
+# if GNULIB_defined_O_NONBLOCK
+ if (flags & O_NONBLOCK)
+ {
+ if (set_nonblocking_flag (fd[0], true) != 0
+ || set_nonblocking_flag (fd[1], true) != 0)
+ goto fail;
+ }
+# else
+ {
+ verify (O_NONBLOCK == 0);
+ }
+# endif
+
+ return 0;
+
+#else
+/* Unix API. */
+
+ if (pipe (fd) < 0)
+ return -1;
+
+ /* POSIX <http://www.opengroup.org/onlinepubs/9699919799/functions/pipe.html>
+ says that initially, the O_NONBLOCK and FD_CLOEXEC flags are cleared on
+ both fd[0] and fd[1]. */
+
+ /* O_NONBLOCK handling.
+ On Unix platforms, O_NONBLOCK is defined by the system. Use fcntl(). */
+ if (flags & O_NONBLOCK)
+ {
+ int fcntl_flags;
+
+ if ((fcntl_flags = fcntl (fd[1], F_GETFL, 0)) < 0
+ || fcntl (fd[1], F_SETFL, fcntl_flags | O_NONBLOCK) == -1
+ || (fcntl_flags = fcntl (fd[0], F_GETFL, 0)) < 0
+ || fcntl (fd[0], F_SETFL, fcntl_flags | O_NONBLOCK) == -1)
+ goto fail;
+ }
+
+ if (flags & O_CLOEXEC)
+ {
+ int fcntl_flags;
+
+ if ((fcntl_flags = fcntl (fd[1], F_GETFD, 0)) < 0
+ || fcntl (fd[1], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1
+ || (fcntl_flags = fcntl (fd[0], F_GETFD, 0)) < 0
+ || fcntl (fd[0], F_SETFD, fcntl_flags | FD_CLOEXEC) == -1)
+ goto fail;
+ }
+
+# if O_BINARY
+ if (flags & O_BINARY)
+ {
+ set_binary_mode (fd[1], O_BINARY);
+ set_binary_mode (fd[0], O_BINARY);
+ }
+ else if (flags & O_TEXT)
+ {
+ set_binary_mode (fd[1], O_TEXT);
+ set_binary_mode (fd[0], O_TEXT);
+ }
+# endif
+
+ return 0;
+
+#endif
+
+#if GNULIB_defined_O_NONBLOCK || \
+ !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
+ fail:
+ {
+ int saved_errno = errno;
+ close (fd[0]);
+ close (fd[1]);
+ fd[0] = tmp[0];
+ fd[1] = tmp[1];
+ errno = saved_errno;
+ return -1;
+ }
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/printf-args.c b/contrib/tools/bison/gnulib/src/printf-args.c
index c27e6bc6b7..d561a940c2 100644
--- a/contrib/tools/bison/gnulib/src/printf-args.c
+++ b/contrib/tools/bison/gnulib/src/printf-args.c
@@ -1,187 +1,187 @@
-/* Decomposed printf argument list.
- Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* This file can be parametrized with the following macros:
- ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
- PRINTF_FETCHARGS Name of the function to be defined.
- STATIC Set to 'static' to declare the function static. */
-
-#ifndef PRINTF_FETCHARGS
-# include <config.h>
-#endif
-
-/* Specification. */
-#ifndef PRINTF_FETCHARGS
-# include "printf-args.h"
-#endif
-
-#ifdef STATIC
-STATIC
-#endif
-int
-PRINTF_FETCHARGS (va_list args, arguments *a)
-{
- size_t i;
- argument *ap;
-
- for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
- switch (ap->type)
- {
- case TYPE_SCHAR:
- ap->a.a_schar = va_arg (args, /*signed char*/ int);
- break;
- case TYPE_UCHAR:
- ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
- break;
- case TYPE_SHORT:
- ap->a.a_short = va_arg (args, /*short*/ int);
- break;
- case TYPE_USHORT:
- ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
- break;
- case TYPE_INT:
- ap->a.a_int = va_arg (args, int);
- break;
- case TYPE_UINT:
- ap->a.a_uint = va_arg (args, unsigned int);
- break;
- case TYPE_LONGINT:
- ap->a.a_longint = va_arg (args, long int);
- break;
- case TYPE_ULONGINT:
- ap->a.a_ulongint = va_arg (args, unsigned long int);
- break;
-#if HAVE_LONG_LONG_INT
- case TYPE_LONGLONGINT:
- ap->a.a_longlongint = va_arg (args, long long int);
- break;
- case TYPE_ULONGLONGINT:
- ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
- break;
-#endif
- case TYPE_DOUBLE:
- ap->a.a_double = va_arg (args, double);
- break;
- case TYPE_LONGDOUBLE:
- ap->a.a_longdouble = va_arg (args, long double);
- break;
- case TYPE_CHAR:
- ap->a.a_char = va_arg (args, int);
- break;
-#if HAVE_WINT_T
- case TYPE_WIDE_CHAR:
- /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
- default argument promotions", this is not the case in mingw32,
- where wint_t is 'unsigned short'. */
- ap->a.a_wide_char =
- (sizeof (wint_t) < sizeof (int)
- ? (wint_t) va_arg (args, int)
- : va_arg (args, wint_t));
- break;
-#endif
- case TYPE_STRING:
- ap->a.a_string = va_arg (args, const char *);
- /* A null pointer is an invalid argument for "%s", but in practice
- it occurs quite frequently in printf statements that produce
- debug output. Use a fallback in this case. */
- if (ap->a.a_string == NULL)
- ap->a.a_string = "(NULL)";
- break;
-#if HAVE_WCHAR_T
- case TYPE_WIDE_STRING:
- ap->a.a_wide_string = va_arg (args, const wchar_t *);
- /* A null pointer is an invalid argument for "%ls", but in practice
- it occurs quite frequently in printf statements that produce
- debug output. Use a fallback in this case. */
- if (ap->a.a_wide_string == NULL)
- {
- static const wchar_t wide_null_string[] =
- {
- (wchar_t)'(',
- (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
- (wchar_t)')',
- (wchar_t)0
- };
- ap->a.a_wide_string = wide_null_string;
- }
- break;
-#endif
- case TYPE_POINTER:
- ap->a.a_pointer = va_arg (args, void *);
- break;
- case TYPE_COUNT_SCHAR_POINTER:
- ap->a.a_count_schar_pointer = va_arg (args, signed char *);
- break;
- case TYPE_COUNT_SHORT_POINTER:
- ap->a.a_count_short_pointer = va_arg (args, short *);
- break;
- case TYPE_COUNT_INT_POINTER:
- ap->a.a_count_int_pointer = va_arg (args, int *);
- break;
- case TYPE_COUNT_LONGINT_POINTER:
- ap->a.a_count_longint_pointer = va_arg (args, long int *);
- break;
-#if HAVE_LONG_LONG_INT
- case TYPE_COUNT_LONGLONGINT_POINTER:
- ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
- break;
-#endif
-#if ENABLE_UNISTDIO
- /* The unistdio extensions. */
- case TYPE_U8_STRING:
- ap->a.a_u8_string = va_arg (args, const uint8_t *);
- /* A null pointer is an invalid argument for "%U", but in practice
- it occurs quite frequently in printf statements that produce
- debug output. Use a fallback in this case. */
- if (ap->a.a_u8_string == NULL)
- {
- static const uint8_t u8_null_string[] =
- { '(', 'N', 'U', 'L', 'L', ')', 0 };
- ap->a.a_u8_string = u8_null_string;
- }
- break;
- case TYPE_U16_STRING:
- ap->a.a_u16_string = va_arg (args, const uint16_t *);
- /* A null pointer is an invalid argument for "%lU", but in practice
- it occurs quite frequently in printf statements that produce
- debug output. Use a fallback in this case. */
- if (ap->a.a_u16_string == NULL)
- {
- static const uint16_t u16_null_string[] =
- { '(', 'N', 'U', 'L', 'L', ')', 0 };
- ap->a.a_u16_string = u16_null_string;
- }
- break;
- case TYPE_U32_STRING:
- ap->a.a_u32_string = va_arg (args, const uint32_t *);
- /* A null pointer is an invalid argument for "%llU", but in practice
- it occurs quite frequently in printf statements that produce
- debug output. Use a fallback in this case. */
- if (ap->a.a_u32_string == NULL)
- {
- static const uint32_t u32_null_string[] =
- { '(', 'N', 'U', 'L', 'L', ')', 0 };
- ap->a.a_u32_string = u32_null_string;
- }
- break;
-#endif
- default:
- /* Unknown type. */
- return -1;
- }
- return 0;
-}
+/* Decomposed printf argument list.
+ Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* This file can be parametrized with the following macros:
+ ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
+ PRINTF_FETCHARGS Name of the function to be defined.
+ STATIC Set to 'static' to declare the function static. */
+
+#ifndef PRINTF_FETCHARGS
+# include <config.h>
+#endif
+
+/* Specification. */
+#ifndef PRINTF_FETCHARGS
+# include "printf-args.h"
+#endif
+
+#ifdef STATIC
+STATIC
+#endif
+int
+PRINTF_FETCHARGS (va_list args, arguments *a)
+{
+ size_t i;
+ argument *ap;
+
+ for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
+ switch (ap->type)
+ {
+ case TYPE_SCHAR:
+ ap->a.a_schar = va_arg (args, /*signed char*/ int);
+ break;
+ case TYPE_UCHAR:
+ ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
+ break;
+ case TYPE_SHORT:
+ ap->a.a_short = va_arg (args, /*short*/ int);
+ break;
+ case TYPE_USHORT:
+ ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
+ break;
+ case TYPE_INT:
+ ap->a.a_int = va_arg (args, int);
+ break;
+ case TYPE_UINT:
+ ap->a.a_uint = va_arg (args, unsigned int);
+ break;
+ case TYPE_LONGINT:
+ ap->a.a_longint = va_arg (args, long int);
+ break;
+ case TYPE_ULONGINT:
+ ap->a.a_ulongint = va_arg (args, unsigned long int);
+ break;
+#if HAVE_LONG_LONG_INT
+ case TYPE_LONGLONGINT:
+ ap->a.a_longlongint = va_arg (args, long long int);
+ break;
+ case TYPE_ULONGLONGINT:
+ ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
+ break;
+#endif
+ case TYPE_DOUBLE:
+ ap->a.a_double = va_arg (args, double);
+ break;
+ case TYPE_LONGDOUBLE:
+ ap->a.a_longdouble = va_arg (args, long double);
+ break;
+ case TYPE_CHAR:
+ ap->a.a_char = va_arg (args, int);
+ break;
+#if HAVE_WINT_T
+ case TYPE_WIDE_CHAR:
+ /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
+ default argument promotions", this is not the case in mingw32,
+ where wint_t is 'unsigned short'. */
+ ap->a.a_wide_char =
+ (sizeof (wint_t) < sizeof (int)
+ ? (wint_t) va_arg (args, int)
+ : va_arg (args, wint_t));
+ break;
+#endif
+ case TYPE_STRING:
+ ap->a.a_string = va_arg (args, const char *);
+ /* A null pointer is an invalid argument for "%s", but in practice
+ it occurs quite frequently in printf statements that produce
+ debug output. Use a fallback in this case. */
+ if (ap->a.a_string == NULL)
+ ap->a.a_string = "(NULL)";
+ break;
+#if HAVE_WCHAR_T
+ case TYPE_WIDE_STRING:
+ ap->a.a_wide_string = va_arg (args, const wchar_t *);
+ /* A null pointer is an invalid argument for "%ls", but in practice
+ it occurs quite frequently in printf statements that produce
+ debug output. Use a fallback in this case. */
+ if (ap->a.a_wide_string == NULL)
+ {
+ static const wchar_t wide_null_string[] =
+ {
+ (wchar_t)'(',
+ (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
+ (wchar_t)')',
+ (wchar_t)0
+ };
+ ap->a.a_wide_string = wide_null_string;
+ }
+ break;
+#endif
+ case TYPE_POINTER:
+ ap->a.a_pointer = va_arg (args, void *);
+ break;
+ case TYPE_COUNT_SCHAR_POINTER:
+ ap->a.a_count_schar_pointer = va_arg (args, signed char *);
+ break;
+ case TYPE_COUNT_SHORT_POINTER:
+ ap->a.a_count_short_pointer = va_arg (args, short *);
+ break;
+ case TYPE_COUNT_INT_POINTER:
+ ap->a.a_count_int_pointer = va_arg (args, int *);
+ break;
+ case TYPE_COUNT_LONGINT_POINTER:
+ ap->a.a_count_longint_pointer = va_arg (args, long int *);
+ break;
+#if HAVE_LONG_LONG_INT
+ case TYPE_COUNT_LONGLONGINT_POINTER:
+ ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
+ break;
+#endif
+#if ENABLE_UNISTDIO
+ /* The unistdio extensions. */
+ case TYPE_U8_STRING:
+ ap->a.a_u8_string = va_arg (args, const uint8_t *);
+ /* A null pointer is an invalid argument for "%U", but in practice
+ it occurs quite frequently in printf statements that produce
+ debug output. Use a fallback in this case. */
+ if (ap->a.a_u8_string == NULL)
+ {
+ static const uint8_t u8_null_string[] =
+ { '(', 'N', 'U', 'L', 'L', ')', 0 };
+ ap->a.a_u8_string = u8_null_string;
+ }
+ break;
+ case TYPE_U16_STRING:
+ ap->a.a_u16_string = va_arg (args, const uint16_t *);
+ /* A null pointer is an invalid argument for "%lU", but in practice
+ it occurs quite frequently in printf statements that produce
+ debug output. Use a fallback in this case. */
+ if (ap->a.a_u16_string == NULL)
+ {
+ static const uint16_t u16_null_string[] =
+ { '(', 'N', 'U', 'L', 'L', ')', 0 };
+ ap->a.a_u16_string = u16_null_string;
+ }
+ break;
+ case TYPE_U32_STRING:
+ ap->a.a_u32_string = va_arg (args, const uint32_t *);
+ /* A null pointer is an invalid argument for "%llU", but in practice
+ it occurs quite frequently in printf statements that produce
+ debug output. Use a fallback in this case. */
+ if (ap->a.a_u32_string == NULL)
+ {
+ static const uint32_t u32_null_string[] =
+ { '(', 'N', 'U', 'L', 'L', ')', 0 };
+ ap->a.a_u32_string = u32_null_string;
+ }
+ break;
+#endif
+ default:
+ /* Unknown type. */
+ return -1;
+ }
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/printf-args.h b/contrib/tools/bison/gnulib/src/printf-args.h
index 2a9c2a3f87..5b0f9fa0cf 100644
--- a/contrib/tools/bison/gnulib/src/printf-args.h
+++ b/contrib/tools/bison/gnulib/src/printf-args.h
@@ -1,158 +1,158 @@
-/* Decomposed printf argument list.
- Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2013 Free Software
- Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _PRINTF_ARGS_H
-#define _PRINTF_ARGS_H
-
-/* This file can be parametrized with the following macros:
- ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
- PRINTF_FETCHARGS Name of the function to be declared.
- STATIC Set to 'static' to declare the function static. */
-
-/* Default parameters. */
-#ifndef PRINTF_FETCHARGS
-# define PRINTF_FETCHARGS printf_fetchargs
-#endif
-
-/* Get size_t. */
-#include <stddef.h>
-
-/* Get wchar_t. */
-#if HAVE_WCHAR_T
-# include <stddef.h>
-#endif
-
-/* Get wint_t. */
-#if HAVE_WINT_T
-# include <wchar.h>
-#endif
-
-/* Get va_list. */
-#include <stdarg.h>
-
-
-/* Argument types */
-typedef enum
-{
- TYPE_NONE,
- TYPE_SCHAR,
- TYPE_UCHAR,
- TYPE_SHORT,
- TYPE_USHORT,
- TYPE_INT,
- TYPE_UINT,
- TYPE_LONGINT,
- TYPE_ULONGINT,
-#if HAVE_LONG_LONG_INT
- TYPE_LONGLONGINT,
- TYPE_ULONGLONGINT,
-#endif
- TYPE_DOUBLE,
- TYPE_LONGDOUBLE,
- TYPE_CHAR,
-#if HAVE_WINT_T
- TYPE_WIDE_CHAR,
-#endif
- TYPE_STRING,
-#if HAVE_WCHAR_T
- TYPE_WIDE_STRING,
-#endif
- TYPE_POINTER,
- TYPE_COUNT_SCHAR_POINTER,
- TYPE_COUNT_SHORT_POINTER,
- TYPE_COUNT_INT_POINTER,
- TYPE_COUNT_LONGINT_POINTER
-#if HAVE_LONG_LONG_INT
-, TYPE_COUNT_LONGLONGINT_POINTER
-#endif
-#if ENABLE_UNISTDIO
- /* The unistdio extensions. */
-, TYPE_U8_STRING
-, TYPE_U16_STRING
-, TYPE_U32_STRING
-#endif
-} arg_type;
-
-/* Polymorphic argument */
-typedef struct
-{
- arg_type type;
- union
- {
- signed char a_schar;
- unsigned char a_uchar;
- short a_short;
- unsigned short a_ushort;
- int a_int;
- unsigned int a_uint;
- long int a_longint;
- unsigned long int a_ulongint;
-#if HAVE_LONG_LONG_INT
- long long int a_longlongint;
- unsigned long long int a_ulonglongint;
-#endif
- float a_float;
- double a_double;
- long double a_longdouble;
- int a_char;
-#if HAVE_WINT_T
- wint_t a_wide_char;
-#endif
- const char* a_string;
-#if HAVE_WCHAR_T
- const wchar_t* a_wide_string;
-#endif
- void* a_pointer;
- signed char * a_count_schar_pointer;
- short * a_count_short_pointer;
- int * a_count_int_pointer;
- long int * a_count_longint_pointer;
-#if HAVE_LONG_LONG_INT
- long long int * a_count_longlongint_pointer;
-#endif
-#if ENABLE_UNISTDIO
- /* The unistdio extensions. */
- const uint8_t * a_u8_string;
- const uint16_t * a_u16_string;
- const uint32_t * a_u32_string;
-#endif
- }
- a;
-}
-argument;
-
-/* Number of directly allocated arguments (no malloc() needed). */
-#define N_DIRECT_ALLOC_ARGUMENTS 7
-
-typedef struct
-{
- size_t count;
- argument *arg;
- argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
-}
-arguments;
-
-
-/* Fetch the arguments, putting them into a. */
-#ifdef STATIC
-STATIC
-#else
-extern
-#endif
-int PRINTF_FETCHARGS (va_list args, arguments *a);
-
-#endif /* _PRINTF_ARGS_H */
+/* Decomposed printf argument list.
+ Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _PRINTF_ARGS_H
+#define _PRINTF_ARGS_H
+
+/* This file can be parametrized with the following macros:
+ ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
+ PRINTF_FETCHARGS Name of the function to be declared.
+ STATIC Set to 'static' to declare the function static. */
+
+/* Default parameters. */
+#ifndef PRINTF_FETCHARGS
+# define PRINTF_FETCHARGS printf_fetchargs
+#endif
+
+/* Get size_t. */
+#include <stddef.h>
+
+/* Get wchar_t. */
+#if HAVE_WCHAR_T
+# include <stddef.h>
+#endif
+
+/* Get wint_t. */
+#if HAVE_WINT_T
+# include <wchar.h>
+#endif
+
+/* Get va_list. */
+#include <stdarg.h>
+
+
+/* Argument types */
+typedef enum
+{
+ TYPE_NONE,
+ TYPE_SCHAR,
+ TYPE_UCHAR,
+ TYPE_SHORT,
+ TYPE_USHORT,
+ TYPE_INT,
+ TYPE_UINT,
+ TYPE_LONGINT,
+ TYPE_ULONGINT,
+#if HAVE_LONG_LONG_INT
+ TYPE_LONGLONGINT,
+ TYPE_ULONGLONGINT,
+#endif
+ TYPE_DOUBLE,
+ TYPE_LONGDOUBLE,
+ TYPE_CHAR,
+#if HAVE_WINT_T
+ TYPE_WIDE_CHAR,
+#endif
+ TYPE_STRING,
+#if HAVE_WCHAR_T
+ TYPE_WIDE_STRING,
+#endif
+ TYPE_POINTER,
+ TYPE_COUNT_SCHAR_POINTER,
+ TYPE_COUNT_SHORT_POINTER,
+ TYPE_COUNT_INT_POINTER,
+ TYPE_COUNT_LONGINT_POINTER
+#if HAVE_LONG_LONG_INT
+, TYPE_COUNT_LONGLONGINT_POINTER
+#endif
+#if ENABLE_UNISTDIO
+ /* The unistdio extensions. */
+, TYPE_U8_STRING
+, TYPE_U16_STRING
+, TYPE_U32_STRING
+#endif
+} arg_type;
+
+/* Polymorphic argument */
+typedef struct
+{
+ arg_type type;
+ union
+ {
+ signed char a_schar;
+ unsigned char a_uchar;
+ short a_short;
+ unsigned short a_ushort;
+ int a_int;
+ unsigned int a_uint;
+ long int a_longint;
+ unsigned long int a_ulongint;
+#if HAVE_LONG_LONG_INT
+ long long int a_longlongint;
+ unsigned long long int a_ulonglongint;
+#endif
+ float a_float;
+ double a_double;
+ long double a_longdouble;
+ int a_char;
+#if HAVE_WINT_T
+ wint_t a_wide_char;
+#endif
+ const char* a_string;
+#if HAVE_WCHAR_T
+ const wchar_t* a_wide_string;
+#endif
+ void* a_pointer;
+ signed char * a_count_schar_pointer;
+ short * a_count_short_pointer;
+ int * a_count_int_pointer;
+ long int * a_count_longint_pointer;
+#if HAVE_LONG_LONG_INT
+ long long int * a_count_longlongint_pointer;
+#endif
+#if ENABLE_UNISTDIO
+ /* The unistdio extensions. */
+ const uint8_t * a_u8_string;
+ const uint16_t * a_u16_string;
+ const uint32_t * a_u32_string;
+#endif
+ }
+ a;
+}
+argument;
+
+/* Number of directly allocated arguments (no malloc() needed). */
+#define N_DIRECT_ALLOC_ARGUMENTS 7
+
+typedef struct
+{
+ size_t count;
+ argument *arg;
+ argument direct_alloc_arg[N_DIRECT_ALLOC_ARGUMENTS];
+}
+arguments;
+
+
+/* Fetch the arguments, putting them into a. */
+#ifdef STATIC
+STATIC
+#else
+extern
+#endif
+int PRINTF_FETCHARGS (va_list args, arguments *a);
+
+#endif /* _PRINTF_ARGS_H */
diff --git a/contrib/tools/bison/gnulib/src/printf-frexp.c b/contrib/tools/bison/gnulib/src/printf-frexp.c
index 1a7b0c438e..a9d2b931f4 100644
--- a/contrib/tools/bison/gnulib/src/printf-frexp.c
+++ b/contrib/tools/bison/gnulib/src/printf-frexp.c
@@ -1,190 +1,190 @@
-/* Split a double into fraction and mantissa, for hexadecimal printf.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if ! defined USE_LONG_DOUBLE
-# include <config.h>
-#endif
-
-/* Specification. */
-#ifdef USE_LONG_DOUBLE
-# include "printf-frexpl.h"
-#else
-# include "printf-frexp.h"
-#endif
-
-#include <float.h>
-#include <math.h>
-#ifdef USE_LONG_DOUBLE
-# include "fpucw.h"
-#endif
-
-/* This file assumes FLT_RADIX = 2. If FLT_RADIX is a power of 2 greater
- than 2, or not even a power of 2, some rounding errors can occur, so that
- then the returned mantissa is only guaranteed to be <= 2.0, not < 2.0. */
-
-#ifdef USE_LONG_DOUBLE
-# define FUNC printf_frexpl
-# define DOUBLE long double
-# define MIN_EXP LDBL_MIN_EXP
-# if HAVE_FREXPL_IN_LIBC && HAVE_LDEXPL_IN_LIBC
-# define USE_FREXP_LDEXP
-# define FREXP frexpl
-# define LDEXP ldexpl
-# endif
-# define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING
-# define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING ()
-# define END_ROUNDING() END_LONG_DOUBLE_ROUNDING ()
-# define L_(literal) literal##L
-#else
-# define FUNC printf_frexp
-# define DOUBLE double
-# define MIN_EXP DBL_MIN_EXP
-# if HAVE_FREXP_IN_LIBC && HAVE_LDEXP_IN_LIBC
-# define USE_FREXP_LDEXP
-# define FREXP frexp
-# define LDEXP ldexp
-# endif
-# define DECL_ROUNDING
-# define BEGIN_ROUNDING()
-# define END_ROUNDING()
-# define L_(literal) literal
-#endif
-
-DOUBLE
-FUNC (DOUBLE x, int *expptr)
-{
- int exponent;
- DECL_ROUNDING
-
- BEGIN_ROUNDING ();
-
-#ifdef USE_FREXP_LDEXP
- /* frexp and ldexp are usually faster than the loop below. */
- x = FREXP (x, &exponent);
-
- x = x + x;
- exponent -= 1;
-
- if (exponent < MIN_EXP - 1)
- {
- x = LDEXP (x, exponent - (MIN_EXP - 1));
- exponent = MIN_EXP - 1;
- }
-#else
- {
- /* Since the exponent is an 'int', it fits in 64 bits. Therefore the
- loops are executed no more than 64 times. */
- DOUBLE pow2[64]; /* pow2[i] = 2^2^i */
- DOUBLE powh[64]; /* powh[i] = 2^-2^i */
- int i;
-
- exponent = 0;
- if (x >= L_(1.0))
- {
- /* A nonnegative exponent. */
- {
- DOUBLE pow2_i; /* = pow2[i] */
- DOUBLE powh_i; /* = powh[i] */
-
- /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
- x * 2^exponent = argument, x >= 1.0. */
- for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
- ;
- i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
- {
- if (x >= pow2_i)
- {
- exponent += (1 << i);
- x *= powh_i;
- }
- else
- break;
-
- pow2[i] = pow2_i;
- powh[i] = powh_i;
- }
- }
- /* Here 1.0 <= x < 2^2^i. */
- }
- else
- {
- /* A negative exponent. */
- {
- DOUBLE pow2_i; /* = pow2[i] */
- DOUBLE powh_i; /* = powh[i] */
-
- /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
- x * 2^exponent = argument, x < 1.0, exponent >= MIN_EXP - 1. */
- for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
- ;
- i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
- {
- if (exponent - (1 << i) < MIN_EXP - 1)
- break;
-
- exponent -= (1 << i);
- x *= pow2_i;
- if (x >= L_(1.0))
- break;
-
- pow2[i] = pow2_i;
- powh[i] = powh_i;
- }
- }
- /* Here either x < 1.0 and exponent - 2^i < MIN_EXP - 1 <= exponent,
- or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
-
- if (x < L_(1.0))
- /* Invariants: x * 2^exponent = argument, x < 1.0 and
- exponent - 2^i < MIN_EXP - 1 <= exponent. */
- while (i > 0)
- {
- i--;
- if (exponent - (1 << i) >= MIN_EXP - 1)
- {
- exponent -= (1 << i);
- x *= pow2[i];
- if (x >= L_(1.0))
- break;
- }
- }
-
- /* Here either x < 1.0 and exponent = MIN_EXP - 1,
- or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
- }
-
- /* Invariants: x * 2^exponent = argument, and
- either x < 1.0 and exponent = MIN_EXP - 1,
- or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
- while (i > 0)
- {
- i--;
- if (x >= pow2[i])
- {
- exponent += (1 << i);
- x *= powh[i];
- }
- }
- /* Here either x < 1.0 and exponent = MIN_EXP - 1,
- or 1.0 <= x < 2.0 and exponent >= MIN_EXP - 1. */
- }
-#endif
-
- END_ROUNDING ();
-
- *expptr = exponent;
- return x;
-}
+/* Split a double into fraction and mantissa, for hexadecimal printf.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if ! defined USE_LONG_DOUBLE
+# include <config.h>
+#endif
+
+/* Specification. */
+#ifdef USE_LONG_DOUBLE
+# include "printf-frexpl.h"
+#else
+# include "printf-frexp.h"
+#endif
+
+#include <float.h>
+#include <math.h>
+#ifdef USE_LONG_DOUBLE
+# include "fpucw.h"
+#endif
+
+/* This file assumes FLT_RADIX = 2. If FLT_RADIX is a power of 2 greater
+ than 2, or not even a power of 2, some rounding errors can occur, so that
+ then the returned mantissa is only guaranteed to be <= 2.0, not < 2.0. */
+
+#ifdef USE_LONG_DOUBLE
+# define FUNC printf_frexpl
+# define DOUBLE long double
+# define MIN_EXP LDBL_MIN_EXP
+# if HAVE_FREXPL_IN_LIBC && HAVE_LDEXPL_IN_LIBC
+# define USE_FREXP_LDEXP
+# define FREXP frexpl
+# define LDEXP ldexpl
+# endif
+# define DECL_ROUNDING DECL_LONG_DOUBLE_ROUNDING
+# define BEGIN_ROUNDING() BEGIN_LONG_DOUBLE_ROUNDING ()
+# define END_ROUNDING() END_LONG_DOUBLE_ROUNDING ()
+# define L_(literal) literal##L
+#else
+# define FUNC printf_frexp
+# define DOUBLE double
+# define MIN_EXP DBL_MIN_EXP
+# if HAVE_FREXP_IN_LIBC && HAVE_LDEXP_IN_LIBC
+# define USE_FREXP_LDEXP
+# define FREXP frexp
+# define LDEXP ldexp
+# endif
+# define DECL_ROUNDING
+# define BEGIN_ROUNDING()
+# define END_ROUNDING()
+# define L_(literal) literal
+#endif
+
+DOUBLE
+FUNC (DOUBLE x, int *expptr)
+{
+ int exponent;
+ DECL_ROUNDING
+
+ BEGIN_ROUNDING ();
+
+#ifdef USE_FREXP_LDEXP
+ /* frexp and ldexp are usually faster than the loop below. */
+ x = FREXP (x, &exponent);
+
+ x = x + x;
+ exponent -= 1;
+
+ if (exponent < MIN_EXP - 1)
+ {
+ x = LDEXP (x, exponent - (MIN_EXP - 1));
+ exponent = MIN_EXP - 1;
+ }
+#else
+ {
+ /* Since the exponent is an 'int', it fits in 64 bits. Therefore the
+ loops are executed no more than 64 times. */
+ DOUBLE pow2[64]; /* pow2[i] = 2^2^i */
+ DOUBLE powh[64]; /* powh[i] = 2^-2^i */
+ int i;
+
+ exponent = 0;
+ if (x >= L_(1.0))
+ {
+ /* A nonnegative exponent. */
+ {
+ DOUBLE pow2_i; /* = pow2[i] */
+ DOUBLE powh_i; /* = powh[i] */
+
+ /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
+ x * 2^exponent = argument, x >= 1.0. */
+ for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
+ ;
+ i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
+ {
+ if (x >= pow2_i)
+ {
+ exponent += (1 << i);
+ x *= powh_i;
+ }
+ else
+ break;
+
+ pow2[i] = pow2_i;
+ powh[i] = powh_i;
+ }
+ }
+ /* Here 1.0 <= x < 2^2^i. */
+ }
+ else
+ {
+ /* A negative exponent. */
+ {
+ DOUBLE pow2_i; /* = pow2[i] */
+ DOUBLE powh_i; /* = powh[i] */
+
+ /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i,
+ x * 2^exponent = argument, x < 1.0, exponent >= MIN_EXP - 1. */
+ for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5);
+ ;
+ i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i)
+ {
+ if (exponent - (1 << i) < MIN_EXP - 1)
+ break;
+
+ exponent -= (1 << i);
+ x *= pow2_i;
+ if (x >= L_(1.0))
+ break;
+
+ pow2[i] = pow2_i;
+ powh[i] = powh_i;
+ }
+ }
+ /* Here either x < 1.0 and exponent - 2^i < MIN_EXP - 1 <= exponent,
+ or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
+
+ if (x < L_(1.0))
+ /* Invariants: x * 2^exponent = argument, x < 1.0 and
+ exponent - 2^i < MIN_EXP - 1 <= exponent. */
+ while (i > 0)
+ {
+ i--;
+ if (exponent - (1 << i) >= MIN_EXP - 1)
+ {
+ exponent -= (1 << i);
+ x *= pow2[i];
+ if (x >= L_(1.0))
+ break;
+ }
+ }
+
+ /* Here either x < 1.0 and exponent = MIN_EXP - 1,
+ or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
+ }
+
+ /* Invariants: x * 2^exponent = argument, and
+ either x < 1.0 and exponent = MIN_EXP - 1,
+ or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */
+ while (i > 0)
+ {
+ i--;
+ if (x >= pow2[i])
+ {
+ exponent += (1 << i);
+ x *= powh[i];
+ }
+ }
+ /* Here either x < 1.0 and exponent = MIN_EXP - 1,
+ or 1.0 <= x < 2.0 and exponent >= MIN_EXP - 1. */
+ }
+#endif
+
+ END_ROUNDING ();
+
+ *expptr = exponent;
+ return x;
+}
diff --git a/contrib/tools/bison/gnulib/src/printf-frexp.h b/contrib/tools/bison/gnulib/src/printf-frexp.h
index 3976b73686..435fec5f98 100644
--- a/contrib/tools/bison/gnulib/src/printf-frexp.h
+++ b/contrib/tools/bison/gnulib/src/printf-frexp.h
@@ -1,23 +1,23 @@
-/* Split a double into fraction and mantissa, for hexadecimal printf.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Write a finite, positive number x as
- x = mantissa * 2^exp
- where exp >= DBL_MIN_EXP - 1,
- mantissa < 2.0,
- if x is not a denormalized number then mantissa >= 1.0.
- Store exp in *EXPPTR and return mantissa. */
-extern double printf_frexp (double x, int *expptr);
+/* Split a double into fraction and mantissa, for hexadecimal printf.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Write a finite, positive number x as
+ x = mantissa * 2^exp
+ where exp >= DBL_MIN_EXP - 1,
+ mantissa < 2.0,
+ if x is not a denormalized number then mantissa >= 1.0.
+ Store exp in *EXPPTR and return mantissa. */
+extern double printf_frexp (double x, int *expptr);
diff --git a/contrib/tools/bison/gnulib/src/printf-frexpl.c b/contrib/tools/bison/gnulib/src/printf-frexpl.c
index 26987a7bd1..89d7be09dd 100644
--- a/contrib/tools/bison/gnulib/src/printf-frexpl.c
+++ b/contrib/tools/bison/gnulib/src/printf-frexpl.c
@@ -1,37 +1,37 @@
-/* Split a 'long double' into fraction and mantissa, for hexadecimal printf.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
-
-/* Specification. */
-# include "printf-frexpl.h"
-
-# include "printf-frexp.h"
-
-long double
-printf_frexpl (long double x, int *expptr)
-{
- return printf_frexp (x, expptr);
-}
-
-#else
-
-# define USE_LONG_DOUBLE
-# include "printf-frexp.c"
-
-#endif
+/* Split a 'long double' into fraction and mantissa, for hexadecimal printf.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+/* Specification. */
+# include "printf-frexpl.h"
+
+# include "printf-frexp.h"
+
+long double
+printf_frexpl (long double x, int *expptr)
+{
+ return printf_frexp (x, expptr);
+}
+
+#else
+
+# define USE_LONG_DOUBLE
+# include "printf-frexp.c"
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/printf-frexpl.h b/contrib/tools/bison/gnulib/src/printf-frexpl.h
index 3768b0915e..cffe3f9879 100644
--- a/contrib/tools/bison/gnulib/src/printf-frexpl.h
+++ b/contrib/tools/bison/gnulib/src/printf-frexpl.h
@@ -1,23 +1,23 @@
-/* Split a 'long double' into fraction and mantissa, for hexadecimal printf.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Write a finite, positive number x as
- x = mantissa * 2^exp
- where exp >= LDBL_MIN_EXP - 1,
- mantissa < 2.0,
- if x is not a denormalized number then mantissa >= 1.0.
- Store exp in *EXPPTR and return mantissa. */
-extern long double printf_frexpl (long double x, int *expptr);
+/* Split a 'long double' into fraction and mantissa, for hexadecimal printf.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Write a finite, positive number x as
+ x = mantissa * 2^exp
+ where exp >= LDBL_MIN_EXP - 1,
+ mantissa < 2.0,
+ if x is not a denormalized number then mantissa >= 1.0.
+ Store exp in *EXPPTR and return mantissa. */
+extern long double printf_frexpl (long double x, int *expptr);
diff --git a/contrib/tools/bison/gnulib/src/printf-parse.c b/contrib/tools/bison/gnulib/src/printf-parse.c
index 23cacc1dab..2baf1cd128 100644
--- a/contrib/tools/bison/gnulib/src/printf-parse.c
+++ b/contrib/tools/bison/gnulib/src/printf-parse.c
@@ -1,638 +1,638 @@
-/* Formatted output to strings.
- Copyright (C) 1999-2000, 2002-2003, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* This file can be parametrized with the following macros:
- CHAR_T The element type of the format string.
- CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
- in the format string are ASCII.
- DIRECTIVE Structure denoting a format directive.
- Depends on CHAR_T.
- DIRECTIVES Structure denoting the set of format directives of a
- format string. Depends on CHAR_T.
- PRINTF_PARSE Function that parses a format string.
- Depends on CHAR_T.
- STATIC Set to 'static' to declare the function static.
- ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */
-
-#ifndef PRINTF_PARSE
-# include <config.h>
-#endif
-
-/* Specification. */
-#ifndef PRINTF_PARSE
-# include "printf-parse.h"
-#endif
-
-/* Default parameters. */
-#ifndef PRINTF_PARSE
-# define PRINTF_PARSE printf_parse
-# define CHAR_T char
-# define DIRECTIVE char_directive
-# define DIRECTIVES char_directives
-#endif
-
-/* Get size_t, NULL. */
-#include <stddef.h>
-
-/* Get intmax_t. */
-#if defined IN_LIBINTL || defined IN_LIBASPRINTF
-# if HAVE_STDINT_H_WITH_UINTMAX
-# include <stdint.h>
-# endif
-# if HAVE_INTTYPES_H_WITH_UINTMAX
-# include <inttypes.h>
-# endif
-#else
-# include <stdint.h>
-#endif
-
-/* malloc(), realloc(), free(). */
-#include <stdlib.h>
-
-/* memcpy(). */
-#include <string.h>
-
-/* errno. */
-#include <errno.h>
-
-/* Checked size_t computations. */
-#include "xsize.h"
-
-#if CHAR_T_ONLY_ASCII
-/* c_isascii(). */
-# include "c-ctype.h"
-#endif
-
-#ifdef STATIC
-STATIC
-#endif
-int
-PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
-{
- const CHAR_T *cp = format; /* pointer into format */
- size_t arg_posn = 0; /* number of regular arguments consumed */
- size_t d_allocated; /* allocated elements of d->dir */
- size_t a_allocated; /* allocated elements of a->arg */
- size_t max_width_length = 0;
- size_t max_precision_length = 0;
-
- d->count = 0;
- d_allocated = N_DIRECT_ALLOC_DIRECTIVES;
- d->dir = d->direct_alloc_dir;
-
- a->count = 0;
- a_allocated = N_DIRECT_ALLOC_ARGUMENTS;
- a->arg = a->direct_alloc_arg;
-
-#define REGISTER_ARG(_index_,_type_) \
- { \
- size_t n = (_index_); \
- if (n >= a_allocated) \
- { \
- size_t memory_size; \
- argument *memory; \
- \
- a_allocated = xtimes (a_allocated, 2); \
- if (a_allocated <= n) \
- a_allocated = xsum (n, 1); \
- memory_size = xtimes (a_allocated, sizeof (argument)); \
- if (size_overflow_p (memory_size)) \
- /* Overflow, would lead to out of memory. */ \
- goto out_of_memory; \
- memory = (argument *) (a->arg != a->direct_alloc_arg \
- ? realloc (a->arg, memory_size) \
- : malloc (memory_size)); \
- if (memory == NULL) \
- /* Out of memory. */ \
- goto out_of_memory; \
- if (a->arg == a->direct_alloc_arg) \
- memcpy (memory, a->arg, a->count * sizeof (argument)); \
- a->arg = memory; \
- } \
- while (a->count <= n) \
- a->arg[a->count++].type = TYPE_NONE; \
- if (a->arg[n].type == TYPE_NONE) \
- a->arg[n].type = (_type_); \
- else if (a->arg[n].type != (_type_)) \
- /* Ambiguous type for positional argument. */ \
- goto error; \
- }
-
- while (*cp != '\0')
- {
- CHAR_T c = *cp++;
- if (c == '%')
- {
- size_t arg_index = ARG_NONE;
- DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */
-
- /* Initialize the next directive. */
- dp->dir_start = cp - 1;
- dp->flags = 0;
- dp->width_start = NULL;
- dp->width_end = NULL;
- dp->width_arg_index = ARG_NONE;
- dp->precision_start = NULL;
- dp->precision_end = NULL;
- dp->precision_arg_index = ARG_NONE;
- dp->arg_index = ARG_NONE;
-
- /* Test for positional argument. */
- if (*cp >= '0' && *cp <= '9')
- {
- const CHAR_T *np;
-
- for (np = cp; *np >= '0' && *np <= '9'; np++)
- ;
- if (*np == '$')
- {
- size_t n = 0;
-
- for (np = cp; *np >= '0' && *np <= '9'; np++)
- n = xsum (xtimes (n, 10), *np - '0');
- if (n == 0)
- /* Positional argument 0. */
- goto error;
- if (size_overflow_p (n))
- /* n too large, would lead to out of memory later. */
- goto error;
- arg_index = n - 1;
- cp = np + 1;
- }
- }
-
- /* Read the flags. */
- for (;;)
- {
- if (*cp == '\'')
- {
- dp->flags |= FLAG_GROUP;
- cp++;
- }
- else if (*cp == '-')
- {
- dp->flags |= FLAG_LEFT;
- cp++;
- }
- else if (*cp == '+')
- {
- dp->flags |= FLAG_SHOWSIGN;
- cp++;
- }
- else if (*cp == ' ')
- {
- dp->flags |= FLAG_SPACE;
- cp++;
- }
- else if (*cp == '#')
- {
- dp->flags |= FLAG_ALT;
- cp++;
- }
- else if (*cp == '0')
- {
- dp->flags |= FLAG_ZERO;
- cp++;
- }
-#if __GLIBC__ >= 2 && !defined __UCLIBC__
- else if (*cp == 'I')
- {
- dp->flags |= FLAG_LOCALIZED;
- cp++;
- }
-#endif
- else
- break;
- }
-
- /* Parse the field width. */
- if (*cp == '*')
- {
- dp->width_start = cp;
- cp++;
- dp->width_end = cp;
- if (max_width_length < 1)
- max_width_length = 1;
-
- /* Test for positional argument. */
- if (*cp >= '0' && *cp <= '9')
- {
- const CHAR_T *np;
-
- for (np = cp; *np >= '0' && *np <= '9'; np++)
- ;
- if (*np == '$')
- {
- size_t n = 0;
-
- for (np = cp; *np >= '0' && *np <= '9'; np++)
- n = xsum (xtimes (n, 10), *np - '0');
- if (n == 0)
- /* Positional argument 0. */
- goto error;
- if (size_overflow_p (n))
- /* n too large, would lead to out of memory later. */
- goto error;
- dp->width_arg_index = n - 1;
- cp = np + 1;
- }
- }
- if (dp->width_arg_index == ARG_NONE)
- {
- dp->width_arg_index = arg_posn++;
- if (dp->width_arg_index == ARG_NONE)
- /* arg_posn wrapped around. */
- goto error;
- }
- REGISTER_ARG (dp->width_arg_index, TYPE_INT);
- }
- else if (*cp >= '0' && *cp <= '9')
- {
- size_t width_length;
-
- dp->width_start = cp;
- for (; *cp >= '0' && *cp <= '9'; cp++)
- ;
- dp->width_end = cp;
- width_length = dp->width_end - dp->width_start;
- if (max_width_length < width_length)
- max_width_length = width_length;
- }
-
- /* Parse the precision. */
- if (*cp == '.')
- {
- cp++;
- if (*cp == '*')
- {
- dp->precision_start = cp - 1;
- cp++;
- dp->precision_end = cp;
- if (max_precision_length < 2)
- max_precision_length = 2;
-
- /* Test for positional argument. */
- if (*cp >= '0' && *cp <= '9')
- {
- const CHAR_T *np;
-
- for (np = cp; *np >= '0' && *np <= '9'; np++)
- ;
- if (*np == '$')
- {
- size_t n = 0;
-
- for (np = cp; *np >= '0' && *np <= '9'; np++)
- n = xsum (xtimes (n, 10), *np - '0');
- if (n == 0)
- /* Positional argument 0. */
- goto error;
- if (size_overflow_p (n))
- /* n too large, would lead to out of memory
- later. */
- goto error;
- dp->precision_arg_index = n - 1;
- cp = np + 1;
- }
- }
- if (dp->precision_arg_index == ARG_NONE)
- {
- dp->precision_arg_index = arg_posn++;
- if (dp->precision_arg_index == ARG_NONE)
- /* arg_posn wrapped around. */
- goto error;
- }
- REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
- }
- else
- {
- size_t precision_length;
-
- dp->precision_start = cp - 1;
- for (; *cp >= '0' && *cp <= '9'; cp++)
- ;
- dp->precision_end = cp;
- precision_length = dp->precision_end - dp->precision_start;
- if (max_precision_length < precision_length)
- max_precision_length = precision_length;
- }
- }
-
- {
- arg_type type;
-
- /* Parse argument type/size specifiers. */
- {
- int flags = 0;
-
- for (;;)
- {
- if (*cp == 'h')
- {
- flags |= (1 << (flags & 1));
- cp++;
- }
- else if (*cp == 'L')
- {
- flags |= 4;
- cp++;
- }
- else if (*cp == 'l')
- {
- flags += 8;
- cp++;
- }
- else if (*cp == 'j')
- {
- if (sizeof (intmax_t) > sizeof (long))
- {
- /* intmax_t = long long */
- flags += 16;
- }
- else if (sizeof (intmax_t) > sizeof (int))
- {
- /* intmax_t = long */
- flags += 8;
- }
- cp++;
- }
- else if (*cp == 'z' || *cp == 'Z')
- {
- /* 'z' is standardized in ISO C 99, but glibc uses 'Z'
- because the warning facility in gcc-2.95.2 understands
- only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
- if (sizeof (size_t) > sizeof (long))
- {
- /* size_t = long long */
- flags += 16;
- }
- else if (sizeof (size_t) > sizeof (int))
- {
- /* size_t = long */
- flags += 8;
- }
- cp++;
- }
- else if (*cp == 't')
- {
- if (sizeof (ptrdiff_t) > sizeof (long))
- {
- /* ptrdiff_t = long long */
- flags += 16;
- }
- else if (sizeof (ptrdiff_t) > sizeof (int))
- {
- /* ptrdiff_t = long */
- flags += 8;
- }
- cp++;
- }
-#if defined __APPLE__ && defined __MACH__
- /* On Mac OS X 10.3, PRIdMAX is defined as "qd".
- We cannot change it to "lld" because PRIdMAX must also
- be understood by the system's printf routines. */
- else if (*cp == 'q')
- {
- if (64 / 8 > sizeof (long))
- {
- /* int64_t = long long */
- flags += 16;
- }
- else
- {
- /* int64_t = long */
- flags += 8;
- }
- cp++;
- }
-#endif
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- /* On native Windows, PRIdMAX is defined as "I64d".
- We cannot change it to "lld" because PRIdMAX must also
- be understood by the system's printf routines. */
- else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
- {
- if (64 / 8 > sizeof (long))
- {
- /* __int64 = long long */
- flags += 16;
- }
- else
- {
- /* __int64 = long */
- flags += 8;
- }
- cp += 3;
- }
-#endif
- else
- break;
- }
-
- /* Read the conversion character. */
- c = *cp++;
- switch (c)
- {
- case 'd': case 'i':
-#if HAVE_LONG_LONG_INT
- /* If 'long long' exists and is larger than 'long': */
- if (flags >= 16 || (flags & 4))
- type = TYPE_LONGLONGINT;
- else
-#endif
- /* If 'long long' exists and is the same as 'long', we parse
- "lld" into TYPE_LONGINT. */
- if (flags >= 8)
- type = TYPE_LONGINT;
- else if (flags & 2)
- type = TYPE_SCHAR;
- else if (flags & 1)
- type = TYPE_SHORT;
- else
- type = TYPE_INT;
- break;
- case 'o': case 'u': case 'x': case 'X':
-#if HAVE_LONG_LONG_INT
- /* If 'long long' exists and is larger than 'long': */
- if (flags >= 16 || (flags & 4))
- type = TYPE_ULONGLONGINT;
- else
-#endif
- /* If 'unsigned long long' exists and is the same as
- 'unsigned long', we parse "llu" into TYPE_ULONGINT. */
- if (flags >= 8)
- type = TYPE_ULONGINT;
- else if (flags & 2)
- type = TYPE_UCHAR;
- else if (flags & 1)
- type = TYPE_USHORT;
- else
- type = TYPE_UINT;
- break;
- case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
- case 'a': case 'A':
- if (flags >= 16 || (flags & 4))
- type = TYPE_LONGDOUBLE;
- else
- type = TYPE_DOUBLE;
- break;
- case 'c':
- if (flags >= 8)
-#if HAVE_WINT_T
- type = TYPE_WIDE_CHAR;
-#else
- goto error;
-#endif
- else
- type = TYPE_CHAR;
- break;
-#if HAVE_WINT_T
- case 'C':
- type = TYPE_WIDE_CHAR;
- c = 'c';
- break;
-#endif
- case 's':
- if (flags >= 8)
-#if HAVE_WCHAR_T
- type = TYPE_WIDE_STRING;
-#else
- goto error;
-#endif
- else
- type = TYPE_STRING;
- break;
-#if HAVE_WCHAR_T
- case 'S':
- type = TYPE_WIDE_STRING;
- c = 's';
- break;
-#endif
- case 'p':
- type = TYPE_POINTER;
- break;
- case 'n':
-#if HAVE_LONG_LONG_INT
- /* If 'long long' exists and is larger than 'long': */
- if (flags >= 16 || (flags & 4))
- type = TYPE_COUNT_LONGLONGINT_POINTER;
- else
-#endif
- /* If 'long long' exists and is the same as 'long', we parse
- "lln" into TYPE_COUNT_LONGINT_POINTER. */
- if (flags >= 8)
- type = TYPE_COUNT_LONGINT_POINTER;
- else if (flags & 2)
- type = TYPE_COUNT_SCHAR_POINTER;
- else if (flags & 1)
- type = TYPE_COUNT_SHORT_POINTER;
- else
- type = TYPE_COUNT_INT_POINTER;
- break;
-#if ENABLE_UNISTDIO
- /* The unistdio extensions. */
- case 'U':
- if (flags >= 16)
- type = TYPE_U32_STRING;
- else if (flags >= 8)
- type = TYPE_U16_STRING;
- else
- type = TYPE_U8_STRING;
- break;
-#endif
- case '%':
- type = TYPE_NONE;
- break;
- default:
- /* Unknown conversion character. */
- goto error;
- }
- }
-
- if (type != TYPE_NONE)
- {
- dp->arg_index = arg_index;
- if (dp->arg_index == ARG_NONE)
- {
- dp->arg_index = arg_posn++;
- if (dp->arg_index == ARG_NONE)
- /* arg_posn wrapped around. */
- goto error;
- }
- REGISTER_ARG (dp->arg_index, type);
- }
- dp->conversion = c;
- dp->dir_end = cp;
- }
-
- d->count++;
- if (d->count >= d_allocated)
- {
- size_t memory_size;
- DIRECTIVE *memory;
-
- d_allocated = xtimes (d_allocated, 2);
- memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
- if (size_overflow_p (memory_size))
- /* Overflow, would lead to out of memory. */
- goto out_of_memory;
- memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
- ? realloc (d->dir, memory_size)
- : malloc (memory_size));
- if (memory == NULL)
- /* Out of memory. */
- goto out_of_memory;
- if (d->dir == d->direct_alloc_dir)
- memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE));
- d->dir = memory;
- }
- }
-#if CHAR_T_ONLY_ASCII
- else if (!c_isascii (c))
- {
- /* Non-ASCII character. Not supported. */
- goto error;
- }
-#endif
- }
- d->dir[d->count].dir_start = cp;
-
- d->max_width_length = max_width_length;
- d->max_precision_length = max_precision_length;
- return 0;
-
-error:
- if (a->arg != a->direct_alloc_arg)
- free (a->arg);
- if (d->dir != d->direct_alloc_dir)
- free (d->dir);
- errno = EINVAL;
- return -1;
-
-out_of_memory:
- if (a->arg != a->direct_alloc_arg)
- free (a->arg);
- if (d->dir != d->direct_alloc_dir)
- free (d->dir);
- errno = ENOMEM;
- return -1;
-}
-
-#undef PRINTF_PARSE
-#undef DIRECTIVES
-#undef DIRECTIVE
-#undef CHAR_T_ONLY_ASCII
-#undef CHAR_T
+/* Formatted output to strings.
+ Copyright (C) 1999-2000, 2002-2003, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* This file can be parametrized with the following macros:
+ CHAR_T The element type of the format string.
+ CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
+ in the format string are ASCII.
+ DIRECTIVE Structure denoting a format directive.
+ Depends on CHAR_T.
+ DIRECTIVES Structure denoting the set of format directives of a
+ format string. Depends on CHAR_T.
+ PRINTF_PARSE Function that parses a format string.
+ Depends on CHAR_T.
+ STATIC Set to 'static' to declare the function static.
+ ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */
+
+#ifndef PRINTF_PARSE
+# include <config.h>
+#endif
+
+/* Specification. */
+#ifndef PRINTF_PARSE
+# include "printf-parse.h"
+#endif
+
+/* Default parameters. */
+#ifndef PRINTF_PARSE
+# define PRINTF_PARSE printf_parse
+# define CHAR_T char
+# define DIRECTIVE char_directive
+# define DIRECTIVES char_directives
+#endif
+
+/* Get size_t, NULL. */
+#include <stddef.h>
+
+/* Get intmax_t. */
+#if defined IN_LIBINTL || defined IN_LIBASPRINTF
+# if HAVE_STDINT_H_WITH_UINTMAX
+# include <stdint.h>
+# endif
+# if HAVE_INTTYPES_H_WITH_UINTMAX
+# include <inttypes.h>
+# endif
+#else
+# include <stdint.h>
+#endif
+
+/* malloc(), realloc(), free(). */
+#include <stdlib.h>
+
+/* memcpy(). */
+#include <string.h>
+
+/* errno. */
+#include <errno.h>
+
+/* Checked size_t computations. */
+#include "xsize.h"
+
+#if CHAR_T_ONLY_ASCII
+/* c_isascii(). */
+# include "c-ctype.h"
+#endif
+
+#ifdef STATIC
+STATIC
+#endif
+int
+PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
+{
+ const CHAR_T *cp = format; /* pointer into format */
+ size_t arg_posn = 0; /* number of regular arguments consumed */
+ size_t d_allocated; /* allocated elements of d->dir */
+ size_t a_allocated; /* allocated elements of a->arg */
+ size_t max_width_length = 0;
+ size_t max_precision_length = 0;
+
+ d->count = 0;
+ d_allocated = N_DIRECT_ALLOC_DIRECTIVES;
+ d->dir = d->direct_alloc_dir;
+
+ a->count = 0;
+ a_allocated = N_DIRECT_ALLOC_ARGUMENTS;
+ a->arg = a->direct_alloc_arg;
+
+#define REGISTER_ARG(_index_,_type_) \
+ { \
+ size_t n = (_index_); \
+ if (n >= a_allocated) \
+ { \
+ size_t memory_size; \
+ argument *memory; \
+ \
+ a_allocated = xtimes (a_allocated, 2); \
+ if (a_allocated <= n) \
+ a_allocated = xsum (n, 1); \
+ memory_size = xtimes (a_allocated, sizeof (argument)); \
+ if (size_overflow_p (memory_size)) \
+ /* Overflow, would lead to out of memory. */ \
+ goto out_of_memory; \
+ memory = (argument *) (a->arg != a->direct_alloc_arg \
+ ? realloc (a->arg, memory_size) \
+ : malloc (memory_size)); \
+ if (memory == NULL) \
+ /* Out of memory. */ \
+ goto out_of_memory; \
+ if (a->arg == a->direct_alloc_arg) \
+ memcpy (memory, a->arg, a->count * sizeof (argument)); \
+ a->arg = memory; \
+ } \
+ while (a->count <= n) \
+ a->arg[a->count++].type = TYPE_NONE; \
+ if (a->arg[n].type == TYPE_NONE) \
+ a->arg[n].type = (_type_); \
+ else if (a->arg[n].type != (_type_)) \
+ /* Ambiguous type for positional argument. */ \
+ goto error; \
+ }
+
+ while (*cp != '\0')
+ {
+ CHAR_T c = *cp++;
+ if (c == '%')
+ {
+ size_t arg_index = ARG_NONE;
+ DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */
+
+ /* Initialize the next directive. */
+ dp->dir_start = cp - 1;
+ dp->flags = 0;
+ dp->width_start = NULL;
+ dp->width_end = NULL;
+ dp->width_arg_index = ARG_NONE;
+ dp->precision_start = NULL;
+ dp->precision_end = NULL;
+ dp->precision_arg_index = ARG_NONE;
+ dp->arg_index = ARG_NONE;
+
+ /* Test for positional argument. */
+ if (*cp >= '0' && *cp <= '9')
+ {
+ const CHAR_T *np;
+
+ for (np = cp; *np >= '0' && *np <= '9'; np++)
+ ;
+ if (*np == '$')
+ {
+ size_t n = 0;
+
+ for (np = cp; *np >= '0' && *np <= '9'; np++)
+ n = xsum (xtimes (n, 10), *np - '0');
+ if (n == 0)
+ /* Positional argument 0. */
+ goto error;
+ if (size_overflow_p (n))
+ /* n too large, would lead to out of memory later. */
+ goto error;
+ arg_index = n - 1;
+ cp = np + 1;
+ }
+ }
+
+ /* Read the flags. */
+ for (;;)
+ {
+ if (*cp == '\'')
+ {
+ dp->flags |= FLAG_GROUP;
+ cp++;
+ }
+ else if (*cp == '-')
+ {
+ dp->flags |= FLAG_LEFT;
+ cp++;
+ }
+ else if (*cp == '+')
+ {
+ dp->flags |= FLAG_SHOWSIGN;
+ cp++;
+ }
+ else if (*cp == ' ')
+ {
+ dp->flags |= FLAG_SPACE;
+ cp++;
+ }
+ else if (*cp == '#')
+ {
+ dp->flags |= FLAG_ALT;
+ cp++;
+ }
+ else if (*cp == '0')
+ {
+ dp->flags |= FLAG_ZERO;
+ cp++;
+ }
+#if __GLIBC__ >= 2 && !defined __UCLIBC__
+ else if (*cp == 'I')
+ {
+ dp->flags |= FLAG_LOCALIZED;
+ cp++;
+ }
+#endif
+ else
+ break;
+ }
+
+ /* Parse the field width. */
+ if (*cp == '*')
+ {
+ dp->width_start = cp;
+ cp++;
+ dp->width_end = cp;
+ if (max_width_length < 1)
+ max_width_length = 1;
+
+ /* Test for positional argument. */
+ if (*cp >= '0' && *cp <= '9')
+ {
+ const CHAR_T *np;
+
+ for (np = cp; *np >= '0' && *np <= '9'; np++)
+ ;
+ if (*np == '$')
+ {
+ size_t n = 0;
+
+ for (np = cp; *np >= '0' && *np <= '9'; np++)
+ n = xsum (xtimes (n, 10), *np - '0');
+ if (n == 0)
+ /* Positional argument 0. */
+ goto error;
+ if (size_overflow_p (n))
+ /* n too large, would lead to out of memory later. */
+ goto error;
+ dp->width_arg_index = n - 1;
+ cp = np + 1;
+ }
+ }
+ if (dp->width_arg_index == ARG_NONE)
+ {
+ dp->width_arg_index = arg_posn++;
+ if (dp->width_arg_index == ARG_NONE)
+ /* arg_posn wrapped around. */
+ goto error;
+ }
+ REGISTER_ARG (dp->width_arg_index, TYPE_INT);
+ }
+ else if (*cp >= '0' && *cp <= '9')
+ {
+ size_t width_length;
+
+ dp->width_start = cp;
+ for (; *cp >= '0' && *cp <= '9'; cp++)
+ ;
+ dp->width_end = cp;
+ width_length = dp->width_end - dp->width_start;
+ if (max_width_length < width_length)
+ max_width_length = width_length;
+ }
+
+ /* Parse the precision. */
+ if (*cp == '.')
+ {
+ cp++;
+ if (*cp == '*')
+ {
+ dp->precision_start = cp - 1;
+ cp++;
+ dp->precision_end = cp;
+ if (max_precision_length < 2)
+ max_precision_length = 2;
+
+ /* Test for positional argument. */
+ if (*cp >= '0' && *cp <= '9')
+ {
+ const CHAR_T *np;
+
+ for (np = cp; *np >= '0' && *np <= '9'; np++)
+ ;
+ if (*np == '$')
+ {
+ size_t n = 0;
+
+ for (np = cp; *np >= '0' && *np <= '9'; np++)
+ n = xsum (xtimes (n, 10), *np - '0');
+ if (n == 0)
+ /* Positional argument 0. */
+ goto error;
+ if (size_overflow_p (n))
+ /* n too large, would lead to out of memory
+ later. */
+ goto error;
+ dp->precision_arg_index = n - 1;
+ cp = np + 1;
+ }
+ }
+ if (dp->precision_arg_index == ARG_NONE)
+ {
+ dp->precision_arg_index = arg_posn++;
+ if (dp->precision_arg_index == ARG_NONE)
+ /* arg_posn wrapped around. */
+ goto error;
+ }
+ REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
+ }
+ else
+ {
+ size_t precision_length;
+
+ dp->precision_start = cp - 1;
+ for (; *cp >= '0' && *cp <= '9'; cp++)
+ ;
+ dp->precision_end = cp;
+ precision_length = dp->precision_end - dp->precision_start;
+ if (max_precision_length < precision_length)
+ max_precision_length = precision_length;
+ }
+ }
+
+ {
+ arg_type type;
+
+ /* Parse argument type/size specifiers. */
+ {
+ int flags = 0;
+
+ for (;;)
+ {
+ if (*cp == 'h')
+ {
+ flags |= (1 << (flags & 1));
+ cp++;
+ }
+ else if (*cp == 'L')
+ {
+ flags |= 4;
+ cp++;
+ }
+ else if (*cp == 'l')
+ {
+ flags += 8;
+ cp++;
+ }
+ else if (*cp == 'j')
+ {
+ if (sizeof (intmax_t) > sizeof (long))
+ {
+ /* intmax_t = long long */
+ flags += 16;
+ }
+ else if (sizeof (intmax_t) > sizeof (int))
+ {
+ /* intmax_t = long */
+ flags += 8;
+ }
+ cp++;
+ }
+ else if (*cp == 'z' || *cp == 'Z')
+ {
+ /* 'z' is standardized in ISO C 99, but glibc uses 'Z'
+ because the warning facility in gcc-2.95.2 understands
+ only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
+ if (sizeof (size_t) > sizeof (long))
+ {
+ /* size_t = long long */
+ flags += 16;
+ }
+ else if (sizeof (size_t) > sizeof (int))
+ {
+ /* size_t = long */
+ flags += 8;
+ }
+ cp++;
+ }
+ else if (*cp == 't')
+ {
+ if (sizeof (ptrdiff_t) > sizeof (long))
+ {
+ /* ptrdiff_t = long long */
+ flags += 16;
+ }
+ else if (sizeof (ptrdiff_t) > sizeof (int))
+ {
+ /* ptrdiff_t = long */
+ flags += 8;
+ }
+ cp++;
+ }
+#if defined __APPLE__ && defined __MACH__
+ /* On Mac OS X 10.3, PRIdMAX is defined as "qd".
+ We cannot change it to "lld" because PRIdMAX must also
+ be understood by the system's printf routines. */
+ else if (*cp == 'q')
+ {
+ if (64 / 8 > sizeof (long))
+ {
+ /* int64_t = long long */
+ flags += 16;
+ }
+ else
+ {
+ /* int64_t = long */
+ flags += 8;
+ }
+ cp++;
+ }
+#endif
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ /* On native Windows, PRIdMAX is defined as "I64d".
+ We cannot change it to "lld" because PRIdMAX must also
+ be understood by the system's printf routines. */
+ else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
+ {
+ if (64 / 8 > sizeof (long))
+ {
+ /* __int64 = long long */
+ flags += 16;
+ }
+ else
+ {
+ /* __int64 = long */
+ flags += 8;
+ }
+ cp += 3;
+ }
+#endif
+ else
+ break;
+ }
+
+ /* Read the conversion character. */
+ c = *cp++;
+ switch (c)
+ {
+ case 'd': case 'i':
+#if HAVE_LONG_LONG_INT
+ /* If 'long long' exists and is larger than 'long': */
+ if (flags >= 16 || (flags & 4))
+ type = TYPE_LONGLONGINT;
+ else
+#endif
+ /* If 'long long' exists and is the same as 'long', we parse
+ "lld" into TYPE_LONGINT. */
+ if (flags >= 8)
+ type = TYPE_LONGINT;
+ else if (flags & 2)
+ type = TYPE_SCHAR;
+ else if (flags & 1)
+ type = TYPE_SHORT;
+ else
+ type = TYPE_INT;
+ break;
+ case 'o': case 'u': case 'x': case 'X':
+#if HAVE_LONG_LONG_INT
+ /* If 'long long' exists and is larger than 'long': */
+ if (flags >= 16 || (flags & 4))
+ type = TYPE_ULONGLONGINT;
+ else
+#endif
+ /* If 'unsigned long long' exists and is the same as
+ 'unsigned long', we parse "llu" into TYPE_ULONGINT. */
+ if (flags >= 8)
+ type = TYPE_ULONGINT;
+ else if (flags & 2)
+ type = TYPE_UCHAR;
+ else if (flags & 1)
+ type = TYPE_USHORT;
+ else
+ type = TYPE_UINT;
+ break;
+ case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
+ case 'a': case 'A':
+ if (flags >= 16 || (flags & 4))
+ type = TYPE_LONGDOUBLE;
+ else
+ type = TYPE_DOUBLE;
+ break;
+ case 'c':
+ if (flags >= 8)
+#if HAVE_WINT_T
+ type = TYPE_WIDE_CHAR;
+#else
+ goto error;
+#endif
+ else
+ type = TYPE_CHAR;
+ break;
+#if HAVE_WINT_T
+ case 'C':
+ type = TYPE_WIDE_CHAR;
+ c = 'c';
+ break;
+#endif
+ case 's':
+ if (flags >= 8)
+#if HAVE_WCHAR_T
+ type = TYPE_WIDE_STRING;
+#else
+ goto error;
+#endif
+ else
+ type = TYPE_STRING;
+ break;
+#if HAVE_WCHAR_T
+ case 'S':
+ type = TYPE_WIDE_STRING;
+ c = 's';
+ break;
+#endif
+ case 'p':
+ type = TYPE_POINTER;
+ break;
+ case 'n':
+#if HAVE_LONG_LONG_INT
+ /* If 'long long' exists and is larger than 'long': */
+ if (flags >= 16 || (flags & 4))
+ type = TYPE_COUNT_LONGLONGINT_POINTER;
+ else
+#endif
+ /* If 'long long' exists and is the same as 'long', we parse
+ "lln" into TYPE_COUNT_LONGINT_POINTER. */
+ if (flags >= 8)
+ type = TYPE_COUNT_LONGINT_POINTER;
+ else if (flags & 2)
+ type = TYPE_COUNT_SCHAR_POINTER;
+ else if (flags & 1)
+ type = TYPE_COUNT_SHORT_POINTER;
+ else
+ type = TYPE_COUNT_INT_POINTER;
+ break;
+#if ENABLE_UNISTDIO
+ /* The unistdio extensions. */
+ case 'U':
+ if (flags >= 16)
+ type = TYPE_U32_STRING;
+ else if (flags >= 8)
+ type = TYPE_U16_STRING;
+ else
+ type = TYPE_U8_STRING;
+ break;
+#endif
+ case '%':
+ type = TYPE_NONE;
+ break;
+ default:
+ /* Unknown conversion character. */
+ goto error;
+ }
+ }
+
+ if (type != TYPE_NONE)
+ {
+ dp->arg_index = arg_index;
+ if (dp->arg_index == ARG_NONE)
+ {
+ dp->arg_index = arg_posn++;
+ if (dp->arg_index == ARG_NONE)
+ /* arg_posn wrapped around. */
+ goto error;
+ }
+ REGISTER_ARG (dp->arg_index, type);
+ }
+ dp->conversion = c;
+ dp->dir_end = cp;
+ }
+
+ d->count++;
+ if (d->count >= d_allocated)
+ {
+ size_t memory_size;
+ DIRECTIVE *memory;
+
+ d_allocated = xtimes (d_allocated, 2);
+ memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
+ if (size_overflow_p (memory_size))
+ /* Overflow, would lead to out of memory. */
+ goto out_of_memory;
+ memory = (DIRECTIVE *) (d->dir != d->direct_alloc_dir
+ ? realloc (d->dir, memory_size)
+ : malloc (memory_size));
+ if (memory == NULL)
+ /* Out of memory. */
+ goto out_of_memory;
+ if (d->dir == d->direct_alloc_dir)
+ memcpy (memory, d->dir, d->count * sizeof (DIRECTIVE));
+ d->dir = memory;
+ }
+ }
+#if CHAR_T_ONLY_ASCII
+ else if (!c_isascii (c))
+ {
+ /* Non-ASCII character. Not supported. */
+ goto error;
+ }
+#endif
+ }
+ d->dir[d->count].dir_start = cp;
+
+ d->max_width_length = max_width_length;
+ d->max_precision_length = max_precision_length;
+ return 0;
+
+error:
+ if (a->arg != a->direct_alloc_arg)
+ free (a->arg);
+ if (d->dir != d->direct_alloc_dir)
+ free (d->dir);
+ errno = EINVAL;
+ return -1;
+
+out_of_memory:
+ if (a->arg != a->direct_alloc_arg)
+ free (a->arg);
+ if (d->dir != d->direct_alloc_dir)
+ free (d->dir);
+ errno = ENOMEM;
+ return -1;
+}
+
+#undef PRINTF_PARSE
+#undef DIRECTIVES
+#undef DIRECTIVE
+#undef CHAR_T_ONLY_ASCII
+#undef CHAR_T
diff --git a/contrib/tools/bison/gnulib/src/printf-parse.h b/contrib/tools/bison/gnulib/src/printf-parse.h
index d8474bee15..a1d1fb1851 100644
--- a/contrib/tools/bison/gnulib/src/printf-parse.h
+++ b/contrib/tools/bison/gnulib/src/printf-parse.h
@@ -1,193 +1,193 @@
-/* Parse printf format string.
- Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2013 Free Software
- Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _PRINTF_PARSE_H
-#define _PRINTF_PARSE_H
-
-/* This file can be parametrized with the following macros:
- ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
- STATIC Set to 'static' to declare the function static. */
-
-#if HAVE_FEATURES_H
-# include <features.h> /* for __GLIBC__, __UCLIBC__ */
-#endif
-
-#include "printf-args.h"
-
-
-/* Flags */
-#define FLAG_GROUP 1 /* ' flag */
-#define FLAG_LEFT 2 /* - flag */
-#define FLAG_SHOWSIGN 4 /* + flag */
-#define FLAG_SPACE 8 /* space flag */
-#define FLAG_ALT 16 /* # flag */
-#define FLAG_ZERO 32
-#if __GLIBC__ >= 2 && !defined __UCLIBC__
-# define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
-#endif
-
-/* arg_index value indicating that no argument is consumed. */
-#define ARG_NONE (~(size_t)0)
-
-/* xxx_directive: A parsed directive.
- xxx_directives: A parsed format string. */
-
-/* Number of directly allocated directives (no malloc() needed). */
-#define N_DIRECT_ALLOC_DIRECTIVES 7
-
-/* A parsed directive. */
-typedef struct
-{
- const char* dir_start;
- const char* dir_end;
- int flags;
- const char* width_start;
- const char* width_end;
- size_t width_arg_index;
- const char* precision_start;
- const char* precision_end;
- size_t precision_arg_index;
- char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
- size_t arg_index;
-}
-char_directive;
-
-/* A parsed format string. */
-typedef struct
-{
- size_t count;
- char_directive *dir;
- size_t max_width_length;
- size_t max_precision_length;
- char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
-}
-char_directives;
-
-#if ENABLE_UNISTDIO
-
-/* A parsed directive. */
-typedef struct
-{
- const uint8_t* dir_start;
- const uint8_t* dir_end;
- int flags;
- const uint8_t* width_start;
- const uint8_t* width_end;
- size_t width_arg_index;
- const uint8_t* precision_start;
- const uint8_t* precision_end;
- size_t precision_arg_index;
- uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
- size_t arg_index;
-}
-u8_directive;
-
-/* A parsed format string. */
-typedef struct
-{
- size_t count;
- u8_directive *dir;
- size_t max_width_length;
- size_t max_precision_length;
- u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
-}
-u8_directives;
-
-/* A parsed directive. */
-typedef struct
-{
- const uint16_t* dir_start;
- const uint16_t* dir_end;
- int flags;
- const uint16_t* width_start;
- const uint16_t* width_end;
- size_t width_arg_index;
- const uint16_t* precision_start;
- const uint16_t* precision_end;
- size_t precision_arg_index;
- uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
- size_t arg_index;
-}
-u16_directive;
-
-/* A parsed format string. */
-typedef struct
-{
- size_t count;
- u16_directive *dir;
- size_t max_width_length;
- size_t max_precision_length;
- u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
-}
-u16_directives;
-
-/* A parsed directive. */
-typedef struct
-{
- const uint32_t* dir_start;
- const uint32_t* dir_end;
- int flags;
- const uint32_t* width_start;
- const uint32_t* width_end;
- size_t width_arg_index;
- const uint32_t* precision_start;
- const uint32_t* precision_end;
- size_t precision_arg_index;
- uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
- size_t arg_index;
-}
-u32_directive;
-
-/* A parsed format string. */
-typedef struct
-{
- size_t count;
- u32_directive *dir;
- size_t max_width_length;
- size_t max_precision_length;
- u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
-}
-u32_directives;
-
-#endif
-
-
-/* Parses the format string. Fills in the number N of directives, and fills
- in directives[0], ..., directives[N-1], and sets directives[N].dir_start
- to the end of the format string. Also fills in the arg_type fields of the
- arguments and the needed count of arguments. */
-#if ENABLE_UNISTDIO
-extern int
- ulc_printf_parse (const char *format, char_directives *d, arguments *a);
-extern int
- u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
-extern int
- u16_printf_parse (const uint16_t *format, u16_directives *d,
- arguments *a);
-extern int
- u32_printf_parse (const uint32_t *format, u32_directives *d,
- arguments *a);
-#else
-# ifdef STATIC
-STATIC
-# else
-extern
-# endif
-int printf_parse (const char *format, char_directives *d, arguments *a);
-#endif
-
-#endif /* _PRINTF_PARSE_H */
+/* Parse printf format string.
+ Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _PRINTF_PARSE_H
+#define _PRINTF_PARSE_H
+
+/* This file can be parametrized with the following macros:
+ ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
+ STATIC Set to 'static' to declare the function static. */
+
+#if HAVE_FEATURES_H
+# include <features.h> /* for __GLIBC__, __UCLIBC__ */
+#endif
+
+#include "printf-args.h"
+
+
+/* Flags */
+#define FLAG_GROUP 1 /* ' flag */
+#define FLAG_LEFT 2 /* - flag */
+#define FLAG_SHOWSIGN 4 /* + flag */
+#define FLAG_SPACE 8 /* space flag */
+#define FLAG_ALT 16 /* # flag */
+#define FLAG_ZERO 32
+#if __GLIBC__ >= 2 && !defined __UCLIBC__
+# define FLAG_LOCALIZED 64 /* I flag, uses localized digits */
+#endif
+
+/* arg_index value indicating that no argument is consumed. */
+#define ARG_NONE (~(size_t)0)
+
+/* xxx_directive: A parsed directive.
+ xxx_directives: A parsed format string. */
+
+/* Number of directly allocated directives (no malloc() needed). */
+#define N_DIRECT_ALLOC_DIRECTIVES 7
+
+/* A parsed directive. */
+typedef struct
+{
+ const char* dir_start;
+ const char* dir_end;
+ int flags;
+ const char* width_start;
+ const char* width_end;
+ size_t width_arg_index;
+ const char* precision_start;
+ const char* precision_end;
+ size_t precision_arg_index;
+ char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
+ size_t arg_index;
+}
+char_directive;
+
+/* A parsed format string. */
+typedef struct
+{
+ size_t count;
+ char_directive *dir;
+ size_t max_width_length;
+ size_t max_precision_length;
+ char_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
+}
+char_directives;
+
+#if ENABLE_UNISTDIO
+
+/* A parsed directive. */
+typedef struct
+{
+ const uint8_t* dir_start;
+ const uint8_t* dir_end;
+ int flags;
+ const uint8_t* width_start;
+ const uint8_t* width_end;
+ size_t width_arg_index;
+ const uint8_t* precision_start;
+ const uint8_t* precision_end;
+ size_t precision_arg_index;
+ uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
+ size_t arg_index;
+}
+u8_directive;
+
+/* A parsed format string. */
+typedef struct
+{
+ size_t count;
+ u8_directive *dir;
+ size_t max_width_length;
+ size_t max_precision_length;
+ u8_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
+}
+u8_directives;
+
+/* A parsed directive. */
+typedef struct
+{
+ const uint16_t* dir_start;
+ const uint16_t* dir_end;
+ int flags;
+ const uint16_t* width_start;
+ const uint16_t* width_end;
+ size_t width_arg_index;
+ const uint16_t* precision_start;
+ const uint16_t* precision_end;
+ size_t precision_arg_index;
+ uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
+ size_t arg_index;
+}
+u16_directive;
+
+/* A parsed format string. */
+typedef struct
+{
+ size_t count;
+ u16_directive *dir;
+ size_t max_width_length;
+ size_t max_precision_length;
+ u16_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
+}
+u16_directives;
+
+/* A parsed directive. */
+typedef struct
+{
+ const uint32_t* dir_start;
+ const uint32_t* dir_end;
+ int flags;
+ const uint32_t* width_start;
+ const uint32_t* width_end;
+ size_t width_arg_index;
+ const uint32_t* precision_start;
+ const uint32_t* precision_end;
+ size_t precision_arg_index;
+ uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
+ size_t arg_index;
+}
+u32_directive;
+
+/* A parsed format string. */
+typedef struct
+{
+ size_t count;
+ u32_directive *dir;
+ size_t max_width_length;
+ size_t max_precision_length;
+ u32_directive direct_alloc_dir[N_DIRECT_ALLOC_DIRECTIVES];
+}
+u32_directives;
+
+#endif
+
+
+/* Parses the format string. Fills in the number N of directives, and fills
+ in directives[0], ..., directives[N-1], and sets directives[N].dir_start
+ to the end of the format string. Also fills in the arg_type fields of the
+ arguments and the needed count of arguments. */
+#if ENABLE_UNISTDIO
+extern int
+ ulc_printf_parse (const char *format, char_directives *d, arguments *a);
+extern int
+ u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
+extern int
+ u16_printf_parse (const uint16_t *format, u16_directives *d,
+ arguments *a);
+extern int
+ u32_printf_parse (const uint32_t *format, u32_directives *d,
+ arguments *a);
+#else
+# ifdef STATIC
+STATIC
+# else
+extern
+# endif
+int printf_parse (const char *format, char_directives *d, arguments *a);
+#endif
+
+#endif /* _PRINTF_PARSE_H */
diff --git a/contrib/tools/bison/gnulib/src/printf.c b/contrib/tools/bison/gnulib/src/printf.c
index 7f682497cc..633dbd848b 100644
--- a/contrib/tools/bison/gnulib/src/printf.c
+++ b/contrib/tools/bison/gnulib/src/printf.c
@@ -1,40 +1,40 @@
-/* Formatted output to a stream.
- Copyright (C) 2007, 2010-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if 1
-# include <config.h>
-#endif
-
-/* Specification. */
-#include <stdio.h>
-
-#include <stdarg.h>
-
-/* Print formatted output to standard output.
- Return string length of formatted string. On error, return a negative
- value. */
-int
-printf (const char *format, ...)
-{
- int retval;
- va_list args;
-
- va_start (args, format);
- retval = vfprintf (stdout, format, args);
- va_end (args);
-
- return retval;
-}
+/* Formatted output to a stream.
+ Copyright (C) 2007, 2010-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if 1
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <stdio.h>
+
+#include <stdarg.h>
+
+/* Print formatted output to standard output.
+ Return string length of formatted string. On error, return a negative
+ value. */
+int
+printf (const char *format, ...)
+{
+ int retval;
+ va_list args;
+
+ va_start (args, format);
+ retval = vfprintf (stdout, format, args);
+ va_end (args);
+
+ return retval;
+}
diff --git a/contrib/tools/bison/gnulib/src/progname.c b/contrib/tools/bison/gnulib/src/progname.c
index 0c195e521a..236ab518d0 100644
--- a/contrib/tools/bison/gnulib/src/progname.c
+++ b/contrib/tools/bison/gnulib/src/progname.c
@@ -1,92 +1,92 @@
-/* Program name management.
- Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#include <config.h>
-
-/* Specification. */
-#undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */
-#include "progname.h"
-
-#include <errno.h> /* get program_invocation_name declaration */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-/* String containing name the program is called with.
- To be initialized by main(). */
-const char *program_name = NULL;
-
-/* Set program_name, based on argv[0].
- argv0 must be a string allocated with indefinite extent, and must not be
- modified after this call. */
-void
-set_program_name (const char *argv0)
-{
- /* libtool creates a temporary executable whose name is sometimes prefixed
- with "lt-" (depends on the platform). It also makes argv[0] absolute.
- But the name of the temporary executable is a detail that should not be
- visible to the end user and to the test suite.
- Remove this "<dirname>/.libs/" or "<dirname>/.libs/lt-" prefix here. */
- const char *slash;
- const char *base;
-
- /* Sanity check. POSIX requires the invoking process to pass a non-NULL
- argv[0]. */
- if (argv0 == NULL)
- {
- /* It's a bug in the invoking program. Help diagnosing it. */
- fputs ("A NULL argv[0] was passed through an exec system call.\n",
- stderr);
- abort ();
- }
-
- slash = strrchr (argv0, '/');
- base = (slash != NULL ? slash + 1 : argv0);
- if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
- {
- argv0 = base;
- if (strncmp (base, "lt-", 3) == 0)
- {
- argv0 = base + 3;
- /* On glibc systems, remove the "lt-" prefix from the variable
- program_invocation_short_name. */
-#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
- program_invocation_short_name = (char *) argv0;
-#endif
- }
- }
-
- /* But don't strip off a leading <dirname>/ in general, because when the user
- runs
- /some/hidden/place/bin/cp foo foo
- he should get the error message
- /some/hidden/place/bin/cp: `foo' and `foo' are the same file
- not
- cp: `foo' and `foo' are the same file
- */
-
- program_name = argv0;
-
- /* On glibc systems, the error() function comes from libc and uses the
- variable program_invocation_name, not program_name. So set this variable
- as well. */
-#if HAVE_DECL_PROGRAM_INVOCATION_NAME
- program_invocation_name = (char *) argv0;
-#endif
-}
+/* Program name management.
+ Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include <config.h>
+
+/* Specification. */
+#undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */
+#include "progname.h"
+
+#include <errno.h> /* get program_invocation_name declaration */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/* String containing name the program is called with.
+ To be initialized by main(). */
+const char *program_name = NULL;
+
+/* Set program_name, based on argv[0].
+ argv0 must be a string allocated with indefinite extent, and must not be
+ modified after this call. */
+void
+set_program_name (const char *argv0)
+{
+ /* libtool creates a temporary executable whose name is sometimes prefixed
+ with "lt-" (depends on the platform). It also makes argv[0] absolute.
+ But the name of the temporary executable is a detail that should not be
+ visible to the end user and to the test suite.
+ Remove this "<dirname>/.libs/" or "<dirname>/.libs/lt-" prefix here. */
+ const char *slash;
+ const char *base;
+
+ /* Sanity check. POSIX requires the invoking process to pass a non-NULL
+ argv[0]. */
+ if (argv0 == NULL)
+ {
+ /* It's a bug in the invoking program. Help diagnosing it. */
+ fputs ("A NULL argv[0] was passed through an exec system call.\n",
+ stderr);
+ abort ();
+ }
+
+ slash = strrchr (argv0, '/');
+ base = (slash != NULL ? slash + 1 : argv0);
+ if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
+ {
+ argv0 = base;
+ if (strncmp (base, "lt-", 3) == 0)
+ {
+ argv0 = base + 3;
+ /* On glibc systems, remove the "lt-" prefix from the variable
+ program_invocation_short_name. */
+#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+ program_invocation_short_name = (char *) argv0;
+#endif
+ }
+ }
+
+ /* But don't strip off a leading <dirname>/ in general, because when the user
+ runs
+ /some/hidden/place/bin/cp foo foo
+ he should get the error message
+ /some/hidden/place/bin/cp: `foo' and `foo' are the same file
+ not
+ cp: `foo' and `foo' are the same file
+ */
+
+ program_name = argv0;
+
+ /* On glibc systems, the error() function comes from libc and uses the
+ variable program_invocation_name, not program_name. So set this variable
+ as well. */
+#if HAVE_DECL_PROGRAM_INVOCATION_NAME
+ program_invocation_name = (char *) argv0;
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/progname.h b/contrib/tools/bison/gnulib/src/progname.h
index b4f3c2778a..f24c823286 100644
--- a/contrib/tools/bison/gnulib/src/progname.h
+++ b/contrib/tools/bison/gnulib/src/progname.h
@@ -1,62 +1,62 @@
-/* Program name management.
- Copyright (C) 2001-2004, 2006, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _PROGNAME_H
-#define _PROGNAME_H
-
-/* Programs using this file should do the following in main():
- set_program_name (argv[0]);
- */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* String containing name the program is called with. */
-extern const char *program_name;
-
-/* Set program_name, based on argv[0].
- argv0 must be a string allocated with indefinite extent, and must not be
- modified after this call. */
-extern void set_program_name (const char *argv0);
-
-#if ENABLE_RELOCATABLE
-
-/* Set program_name, based on argv[0], and original installation prefix and
- directory, for relocatability. */
-extern void set_program_name_and_installdir (const char *argv0,
- const char *orig_installprefix,
- const char *orig_installdir);
-#undef set_program_name
-#define set_program_name(ARG0) \
- set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR)
-
-/* Return the full pathname of the current executable, based on the earlier
- call to set_program_name_and_installdir. Return NULL if unknown. */
-extern char *get_full_program_name (void);
-
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _PROGNAME_H */
+/* Program name management.
+ Copyright (C) 2001-2004, 2006, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _PROGNAME_H
+#define _PROGNAME_H
+
+/* Programs using this file should do the following in main():
+ set_program_name (argv[0]);
+ */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* String containing name the program is called with. */
+extern const char *program_name;
+
+/* Set program_name, based on argv[0].
+ argv0 must be a string allocated with indefinite extent, and must not be
+ modified after this call. */
+extern void set_program_name (const char *argv0);
+
+#if ENABLE_RELOCATABLE
+
+/* Set program_name, based on argv[0], and original installation prefix and
+ directory, for relocatability. */
+extern void set_program_name_and_installdir (const char *argv0,
+ const char *orig_installprefix,
+ const char *orig_installdir);
+#undef set_program_name
+#define set_program_name(ARG0) \
+ set_program_name_and_installdir (ARG0, INSTALLPREFIX, INSTALLDIR)
+
+/* Return the full pathname of the current executable, based on the earlier
+ call to set_program_name_and_installdir. Return NULL if unknown. */
+extern char *get_full_program_name (void);
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _PROGNAME_H */
diff --git a/contrib/tools/bison/gnulib/src/quote.h b/contrib/tools/bison/gnulib/src/quote.h
index 1679796763..a2cdf2d463 100644
--- a/contrib/tools/bison/gnulib/src/quote.h
+++ b/contrib/tools/bison/gnulib/src/quote.h
@@ -1,46 +1,46 @@
-/* quote.h - prototypes for quote.c
-
- Copyright (C) 1998-2001, 2003, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef QUOTE_H_
-# define QUOTE_H_ 1
-
-# include <stddef.h>
-
-/* The quoting options used by quote_n and quote. Its type is incomplete,
- so it's useful only in expressions like '&quote_quoting_options'. */
-extern struct quoting_options quote_quoting_options;
-
-/* Return an unambiguous printable representation of ARG (of size
- ARGSIZE), allocated in slot N, suitable for diagnostics. If
- ARGSIZE is SIZE_MAX, use the string length of the argument for
- ARGSIZE. */
-char const *quote_n_mem (int n, char const *arg, size_t argsize);
-
-/* Return an unambiguous printable representation of ARG (of size
- ARGSIZE), suitable for diagnostics. If ARGSIZE is SIZE_MAX, use
- the string length of the argument for ARGSIZE. */
-char const *quote_mem (char const *arg, size_t argsize);
-
-/* Return an unambiguous printable representation of ARG, allocated in
- slot N, suitable for diagnostics. */
-char const *quote_n (int n, char const *arg);
-
-/* Return an unambiguous printable representation of ARG, suitable for
- diagnostics. */
-char const *quote (char const *arg);
-
-#endif /* !QUOTE_H_ */
+/* quote.h - prototypes for quote.c
+
+ Copyright (C) 1998-2001, 2003, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef QUOTE_H_
+# define QUOTE_H_ 1
+
+# include <stddef.h>
+
+/* The quoting options used by quote_n and quote. Its type is incomplete,
+ so it's useful only in expressions like '&quote_quoting_options'. */
+extern struct quoting_options quote_quoting_options;
+
+/* Return an unambiguous printable representation of ARG (of size
+ ARGSIZE), allocated in slot N, suitable for diagnostics. If
+ ARGSIZE is SIZE_MAX, use the string length of the argument for
+ ARGSIZE. */
+char const *quote_n_mem (int n, char const *arg, size_t argsize);
+
+/* Return an unambiguous printable representation of ARG (of size
+ ARGSIZE), suitable for diagnostics. If ARGSIZE is SIZE_MAX, use
+ the string length of the argument for ARGSIZE. */
+char const *quote_mem (char const *arg, size_t argsize);
+
+/* Return an unambiguous printable representation of ARG, allocated in
+ slot N, suitable for diagnostics. */
+char const *quote_n (int n, char const *arg);
+
+/* Return an unambiguous printable representation of ARG, suitable for
+ diagnostics. */
+char const *quote (char const *arg);
+
+#endif /* !QUOTE_H_ */
diff --git a/contrib/tools/bison/gnulib/src/quotearg.c b/contrib/tools/bison/gnulib/src/quotearg.c
index 40114d7fbd..d06ef51a18 100644
--- a/contrib/tools/bison/gnulib/src/quotearg.c
+++ b/contrib/tools/bison/gnulib/src/quotearg.c
@@ -1,968 +1,968 @@
-/* quotearg.c - quote arguments for output
-
- Copyright (C) 1998-2002, 2004-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert <eggert@twinsun.com> */
-
-/* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that
- the quoting_options_from_style function might be candidate for
- attribute 'pure' */
-#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
-# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
-#endif
-
-#include <config.h>
-
-#include "quotearg.h"
-#include "quote.h"
-
-#include "xalloc.h"
-#include "c-strcaseeq.h"
-#include "localcharset.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <wchar.h>
-#include <wctype.h>
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-#define INT_BITS (sizeof (int) * CHAR_BIT)
-
-struct quoting_options
-{
- /* Basic quoting style. */
- enum quoting_style style;
-
- /* Additional flags. Bitwise combination of enum quoting_flags. */
- int flags;
-
- /* Quote the characters indicated by this bit vector even if the
- quoting style would not normally require them to be quoted. */
- unsigned int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
-
- /* The left quote for custom_quoting_style. */
- char const *left_quote;
-
- /* The right quote for custom_quoting_style. */
- char const *right_quote;
-};
-
-/* Names of quoting styles. */
-char const *const quoting_style_args[] =
-{
- "literal",
- "shell",
- "shell-always",
- "c",
- "c-maybe",
- "escape",
- "locale",
- "clocale",
- 0
-};
-
-/* Correspondences to quoting style names. */
-enum quoting_style const quoting_style_vals[] =
-{
- literal_quoting_style,
- shell_quoting_style,
- shell_always_quoting_style,
- c_quoting_style,
- c_maybe_quoting_style,
- escape_quoting_style,
- locale_quoting_style,
- clocale_quoting_style
-};
-
-/* The default quoting options. */
-static struct quoting_options default_quoting_options;
-
-/* Allocate a new set of quoting options, with contents initially identical
- to O if O is not null, or to the default if O is null.
- It is the caller's responsibility to free the result. */
-struct quoting_options *
-clone_quoting_options (struct quoting_options *o)
-{
- int e = errno;
- struct quoting_options *p = xmemdup (o ? o : &default_quoting_options,
- sizeof *o);
- errno = e;
- return p;
-}
-
-/* Get the value of O's quoting style. If O is null, use the default. */
-enum quoting_style
-get_quoting_style (struct quoting_options *o)
-{
- return (o ? o : &default_quoting_options)->style;
-}
-
-/* In O (or in the default if O is null),
- set the value of the quoting style to S. */
-void
-set_quoting_style (struct quoting_options *o, enum quoting_style s)
-{
- (o ? o : &default_quoting_options)->style = s;
-}
-
-/* In O (or in the default if O is null),
- set the value of the quoting options for character C to I.
- Return the old value. Currently, the only values defined for I are
- 0 (the default) and 1 (which means to quote the character even if
- it would not otherwise be quoted). */
-int
-set_char_quoting (struct quoting_options *o, char c, int i)
-{
- unsigned char uc = c;
- unsigned int *p =
- (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
- int shift = uc % INT_BITS;
- int r = (*p >> shift) & 1;
- *p ^= ((i & 1) ^ r) << shift;
- return r;
-}
-
-/* In O (or in the default if O is null),
- set the value of the quoting options flag to I, which can be a
- bitwise combination of enum quoting_flags, or 0 for default
- behavior. Return the old value. */
-int
-set_quoting_flags (struct quoting_options *o, int i)
-{
- int r;
- if (!o)
- o = &default_quoting_options;
- r = o->flags;
- o->flags = i;
- return r;
-}
-
-void
-set_custom_quoting (struct quoting_options *o,
- char const *left_quote, char const *right_quote)
-{
- if (!o)
- o = &default_quoting_options;
- o->style = custom_quoting_style;
- if (!left_quote || !right_quote)
- abort ();
- o->left_quote = left_quote;
- o->right_quote = right_quote;
-}
-
-/* Return quoting options for STYLE, with no extra quoting. */
-static struct quoting_options /* NOT PURE!! */
-quoting_options_from_style (enum quoting_style style)
-{
- struct quoting_options o = { 0, 0, { 0 }, NULL, NULL };
- if (style == custom_quoting_style)
- abort ();
- o.style = style;
- return o;
-}
-
-/* MSGID approximates a quotation mark. Return its translation if it
- has one; otherwise, return either it or "\"", depending on S.
-
- S is either clocale_quoting_style or locale_quoting_style. */
-static char const *
-gettext_quote (char const *msgid, enum quoting_style s)
-{
- char const *translation = _(msgid);
- char const *locale_code;
-
- if (translation != msgid)
- return translation;
-
- /* For UTF-8 and GB-18030, use single quotes U+2018 and U+2019.
- Here is a list of other locales that include U+2018 and U+2019:
-
- ISO-8859-7 0xA1 KOI8-T 0x91
- CP869 0x8B CP874 0x91
- CP932 0x81 0x65 CP936 0xA1 0xAE
- CP949 0xA1 0xAE CP950 0xA1 0xA5
- CP1250 0x91 CP1251 0x91
- CP1252 0x91 CP1253 0x91
- CP1254 0x91 CP1255 0x91
- CP1256 0x91 CP1257 0x91
- EUC-JP 0xA1 0xC6 EUC-KR 0xA1 0xAE
- EUC-TW 0xA1 0xE4 BIG5 0xA1 0xA5
- BIG5-HKSCS 0xA1 0xA5 EUC-CN 0xA1 0xAE
- GBK 0xA1 0xAE Georgian-PS 0x91
- PT154 0x91
-
- None of these is still in wide use; using iconv is overkill. */
- locale_code = locale_charset ();
- if (STRCASEEQ (locale_code, "UTF-8", 'U','T','F','-','8',0,0,0,0))
- return msgid[0] == '`' ? "\xe2\x80\x98": "\xe2\x80\x99";
- if (STRCASEEQ (locale_code, "GB18030", 'G','B','1','8','0','3','0',0,0))
- return msgid[0] == '`' ? "\xa1\ae": "\xa1\xaf";
-
- return (s == clocale_quoting_style ? "\"" : "'");
-}
-
-/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
- argument ARG (of size ARGSIZE), using QUOTING_STYLE, FLAGS, and
- QUOTE_THESE_TOO to control quoting.
- Terminate the output with a null character, and return the written
- size of the output, not counting the terminating null.
- If BUFFERSIZE is too small to store the output string, return the
- value that would have been returned had BUFFERSIZE been large enough.
- If ARGSIZE is SIZE_MAX, use the string length of the argument for ARGSIZE.
-
- This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
- ARGSIZE, O), except it breaks O into its component pieces and is
- not careful about errno. */
-
-static size_t
-quotearg_buffer_restyled (char *buffer, size_t buffersize,
- char const *arg, size_t argsize,
- enum quoting_style quoting_style, int flags,
- unsigned int const *quote_these_too,
- char const *left_quote,
- char const *right_quote)
-{
- size_t i;
- size_t len = 0;
- char const *quote_string = 0;
- size_t quote_string_len = 0;
- bool backslash_escapes = false;
- bool unibyte_locale = MB_CUR_MAX == 1;
- bool elide_outer_quotes = (flags & QA_ELIDE_OUTER_QUOTES) != 0;
-
-#define STORE(c) \
- do \
- { \
- if (len < buffersize) \
- buffer[len] = (c); \
- len++; \
- } \
- while (0)
-
- switch (quoting_style)
- {
- case c_maybe_quoting_style:
- quoting_style = c_quoting_style;
- elide_outer_quotes = true;
- /* Fall through. */
- case c_quoting_style:
- if (!elide_outer_quotes)
- STORE ('"');
- backslash_escapes = true;
- quote_string = "\"";
- quote_string_len = 1;
- break;
-
- case escape_quoting_style:
- backslash_escapes = true;
- elide_outer_quotes = false;
- break;
-
- case locale_quoting_style:
- case clocale_quoting_style:
- case custom_quoting_style:
- {
- if (quoting_style != custom_quoting_style)
- {
- /* TRANSLATORS:
- Get translations for open and closing quotation marks.
- The message catalog should translate "`" to a left
- quotation mark suitable for the locale, and similarly for
- "'". For example, a French Unicode local should translate
- these to U+00AB (LEFT-POINTING DOUBLE ANGLE
- QUOTATION MARK), and U+00BB (RIGHT-POINTING DOUBLE ANGLE
- QUOTATION MARK), respectively.
-
- If the catalog has no translation, we will try to
- use Unicode U+2018 (LEFT SINGLE QUOTATION MARK) and
- Unicode U+2019 (RIGHT SINGLE QUOTATION MARK). If the
- current locale is not Unicode, locale_quoting_style
- will quote 'like this', and clocale_quoting_style will
- quote "like this". You should always include translations
- for "`" and "'" even if U+2018 and U+2019 are appropriate
- for your locale.
-
- If you don't know what to put here, please see
- <http://en.wikipedia.org/wiki/Quotation_marks_in_other_languages>
- and use glyphs suitable for your language. */
- left_quote = gettext_quote (N_("`"), quoting_style);
- right_quote = gettext_quote (N_("'"), quoting_style);
- }
- if (!elide_outer_quotes)
- for (quote_string = left_quote; *quote_string; quote_string++)
- STORE (*quote_string);
- backslash_escapes = true;
- quote_string = right_quote;
- quote_string_len = strlen (quote_string);
- }
- break;
-
- case shell_quoting_style:
- quoting_style = shell_always_quoting_style;
- elide_outer_quotes = true;
- /* Fall through. */
- case shell_always_quoting_style:
- if (!elide_outer_quotes)
- STORE ('\'');
- quote_string = "'";
- quote_string_len = 1;
- break;
-
- case literal_quoting_style:
- elide_outer_quotes = false;
- break;
-
- default:
- abort ();
- }
-
- for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++)
- {
- unsigned char c;
- unsigned char esc;
- bool is_right_quote = false;
-
- if (backslash_escapes
- && quote_string_len
- && (i + quote_string_len
- <= (argsize == SIZE_MAX && 1 < quote_string_len
- /* Use strlen only if we must: when argsize is SIZE_MAX,
- and when the quote string is more than 1 byte long.
- If we do call strlen, save the result. */
- ? (argsize = strlen (arg)) : argsize))
- && memcmp (arg + i, quote_string, quote_string_len) == 0)
- {
- if (elide_outer_quotes)
- goto force_outer_quoting_style;
- is_right_quote = true;
- }
-
- c = arg[i];
- switch (c)
- {
- case '\0':
- if (backslash_escapes)
- {
- if (elide_outer_quotes)
- goto force_outer_quoting_style;
- STORE ('\\');
- /* If quote_string were to begin with digits, we'd need to
- test for the end of the arg as well. However, it's
- hard to imagine any locale that would use digits in
- quotes, and set_custom_quoting is documented not to
- accept them. */
- if (i + 1 < argsize && '0' <= arg[i + 1] && arg[i + 1] <= '9')
- {
- STORE ('0');
- STORE ('0');
- }
- c = '0';
- /* We don't have to worry that this last '0' will be
- backslash-escaped because, again, quote_string should
- not start with it and because quote_these_too is
- documented as not accepting it. */
- }
- else if (flags & QA_ELIDE_NULL_BYTES)
- continue;
- break;
-
- case '?':
- switch (quoting_style)
- {
- case shell_always_quoting_style:
- if (elide_outer_quotes)
- goto force_outer_quoting_style;
- break;
-
- case c_quoting_style:
- if ((flags & QA_SPLIT_TRIGRAPHS)
- && i + 2 < argsize && arg[i + 1] == '?')
- switch (arg[i + 2])
- {
- case '!': case '\'':
- case '(': case ')': case '-': case '/':
- case '<': case '=': case '>':
- /* Escape the second '?' in what would otherwise be
- a trigraph. */
- if (elide_outer_quotes)
- goto force_outer_quoting_style;
- c = arg[i + 2];
- i += 2;
- STORE ('?');
- STORE ('"');
- STORE ('"');
- STORE ('?');
- break;
-
- default:
- break;
- }
- break;
-
- default:
- break;
- }
- break;
-
- case '\a': esc = 'a'; goto c_escape;
- case '\b': esc = 'b'; goto c_escape;
- case '\f': esc = 'f'; goto c_escape;
- case '\n': esc = 'n'; goto c_and_shell_escape;
- case '\r': esc = 'r'; goto c_and_shell_escape;
- case '\t': esc = 't'; goto c_and_shell_escape;
- case '\v': esc = 'v'; goto c_escape;
- case '\\': esc = c;
- /* No need to escape the escape if we are trying to elide
- outer quotes and nothing else is problematic. */
- if (backslash_escapes && elide_outer_quotes && quote_string_len)
- goto store_c;
-
- c_and_shell_escape:
- if (quoting_style == shell_always_quoting_style
- && elide_outer_quotes)
- goto force_outer_quoting_style;
- /* Fall through. */
- c_escape:
- if (backslash_escapes)
- {
- c = esc;
- goto store_escape;
- }
- break;
-
- case '{': case '}': /* sometimes special if isolated */
- if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
- break;
- /* Fall through. */
- case '#': case '~':
- if (i != 0)
- break;
- /* Fall through. */
- case ' ':
- case '!': /* special in bash */
- case '"': case '$': case '&':
- case '(': case ')': case '*': case ';':
- case '<':
- case '=': /* sometimes special in 0th or (with "set -k") later args */
- case '>': case '[':
- case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
- case '`': case '|':
- /* A shell special character. In theory, '$' and '`' could
- be the first bytes of multibyte characters, which means
- we should check them with mbrtowc, but in practice this
- doesn't happen so it's not worth worrying about. */
- if (quoting_style == shell_always_quoting_style
- && elide_outer_quotes)
- goto force_outer_quoting_style;
- break;
-
- case '\'':
- if (quoting_style == shell_always_quoting_style)
- {
- if (elide_outer_quotes)
- goto force_outer_quoting_style;
- STORE ('\'');
- STORE ('\\');
- STORE ('\'');
- }
- break;
-
- case '%': case '+': case ',': case '-': case '.': case '/':
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9': case ':':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
- case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
- case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
- case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
- case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
- case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
- case 'o': case 'p': case 'q': case 'r': case 's': case 't':
- case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
- /* These characters don't cause problems, no matter what the
- quoting style is. They cannot start multibyte sequences.
- A digit or a special letter would cause trouble if it
- appeared at the beginning of quote_string because we'd then
- escape by prepending a backslash. However, it's hard to
- imagine any locale that would use digits or letters as
- quotes, and set_custom_quoting is documented not to accept
- them. Also, a digit or a special letter would cause
- trouble if it appeared in quote_these_too, but that's also
- documented as not accepting them. */
- break;
-
- default:
- /* If we have a multibyte sequence, copy it until we reach
- its end, find an error, or come back to the initial shift
- state. For C-like styles, if the sequence has
- unprintable characters, escape the whole sequence, since
- we can't easily escape single characters within it. */
- {
- /* Length of multibyte sequence found so far. */
- size_t m;
-
- bool printable;
-
- if (unibyte_locale)
- {
- m = 1;
- printable = isprint (c) != 0;
- }
- else
- {
- mbstate_t mbstate;
- memset (&mbstate, 0, sizeof mbstate);
-
- m = 0;
- printable = true;
- if (argsize == SIZE_MAX)
- argsize = strlen (arg);
-
- do
- {
- wchar_t w;
- size_t bytes = mbrtowc (&w, &arg[i + m],
- argsize - (i + m), &mbstate);
- if (bytes == 0)
- break;
- else if (bytes == (size_t) -1)
- {
- printable = false;
- break;
- }
- else if (bytes == (size_t) -2)
- {
- printable = false;
- while (i + m < argsize && arg[i + m])
- m++;
- break;
- }
- else
- {
- /* Work around a bug with older shells that "see" a '\'
- that is really the 2nd byte of a multibyte character.
- In practice the problem is limited to ASCII
- chars >= '@' that are shell special chars. */
- if ('[' == 0x5b && elide_outer_quotes
- && quoting_style == shell_always_quoting_style)
- {
- size_t j;
- for (j = 1; j < bytes; j++)
- switch (arg[i + m + j])
- {
- case '[': case '\\': case '^':
- case '`': case '|':
- goto force_outer_quoting_style;
-
- default:
- break;
- }
- }
-
- if (! iswprint (w))
- printable = false;
- m += bytes;
- }
- }
- while (! mbsinit (&mbstate));
- }
-
- if (1 < m || (backslash_escapes && ! printable))
- {
- /* Output a multibyte sequence, or an escaped
- unprintable unibyte character. */
- size_t ilim = i + m;
-
- for (;;)
- {
- if (backslash_escapes && ! printable)
- {
- if (elide_outer_quotes)
- goto force_outer_quoting_style;
- STORE ('\\');
- STORE ('0' + (c >> 6));
- STORE ('0' + ((c >> 3) & 7));
- c = '0' + (c & 7);
- }
- else if (is_right_quote)
- {
- STORE ('\\');
- is_right_quote = false;
- }
- if (ilim <= i + 1)
- break;
- STORE (c);
- c = arg[++i];
- }
-
- goto store_c;
- }
- }
- }
-
- if (! ((backslash_escapes || elide_outer_quotes)
- && quote_these_too
- && quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS)))
- && !is_right_quote)
- goto store_c;
-
- store_escape:
- if (elide_outer_quotes)
- goto force_outer_quoting_style;
- STORE ('\\');
-
- store_c:
- STORE (c);
- }
-
- if (len == 0 && quoting_style == shell_always_quoting_style
- && elide_outer_quotes)
- goto force_outer_quoting_style;
-
- if (quote_string && !elide_outer_quotes)
- for (; *quote_string; quote_string++)
- STORE (*quote_string);
-
- if (len < buffersize)
- buffer[len] = '\0';
- return len;
-
- force_outer_quoting_style:
- /* Don't reuse quote_these_too, since the addition of outer quotes
- sufficiently quotes the specified characters. */
- return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
- quoting_style,
- flags & ~QA_ELIDE_OUTER_QUOTES, NULL,
- left_quote, right_quote);
-}
-
-/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
- argument ARG (of size ARGSIZE), using O to control quoting.
- If O is null, use the default.
- Terminate the output with a null character, and return the written
- size of the output, not counting the terminating null.
- If BUFFERSIZE is too small to store the output string, return the
- value that would have been returned had BUFFERSIZE been large enough.
- If ARGSIZE is SIZE_MAX, use the string length of the argument for
- ARGSIZE. */
-size_t
-quotearg_buffer (char *buffer, size_t buffersize,
- char const *arg, size_t argsize,
- struct quoting_options const *o)
-{
- struct quoting_options const *p = o ? o : &default_quoting_options;
- int e = errno;
- size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
- p->style, p->flags, p->quote_these_too,
- p->left_quote, p->right_quote);
- errno = e;
- return r;
-}
-
-/* Equivalent to quotearg_alloc (ARG, ARGSIZE, NULL, O). */
-char *
-quotearg_alloc (char const *arg, size_t argsize,
- struct quoting_options const *o)
-{
- return quotearg_alloc_mem (arg, argsize, NULL, o);
-}
-
-/* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly
- allocated storage containing the quoted string, and store the
- resulting size into *SIZE, if non-NULL. The result can contain
- embedded null bytes only if ARGSIZE is not SIZE_MAX, SIZE is not
- NULL, and set_quoting_flags has not set the null byte elision
- flag. */
-char *
-quotearg_alloc_mem (char const *arg, size_t argsize, size_t *size,
- struct quoting_options const *o)
-{
- struct quoting_options const *p = o ? o : &default_quoting_options;
- int e = errno;
- /* Elide embedded null bytes if we can't return a size. */
- int flags = p->flags | (size ? 0 : QA_ELIDE_NULL_BYTES);
- size_t bufsize = quotearg_buffer_restyled (0, 0, arg, argsize, p->style,
- flags, p->quote_these_too,
- p->left_quote,
- p->right_quote) + 1;
- char *buf = xcharalloc (bufsize);
- quotearg_buffer_restyled (buf, bufsize, arg, argsize, p->style, flags,
- p->quote_these_too,
- p->left_quote, p->right_quote);
- errno = e;
- if (size)
- *size = bufsize - 1;
- return buf;
-}
-
-/* A storage slot with size and pointer to a value. */
-struct slotvec
-{
- size_t size;
- char *val;
-};
-
-/* Preallocate a slot 0 buffer, so that the caller can always quote
- one small component of a "memory exhausted" message in slot 0. */
-static char slot0[256];
-static unsigned int nslots = 1;
-static struct slotvec slotvec0 = {sizeof slot0, slot0};
-static struct slotvec *slotvec = &slotvec0;
-
-void
-quotearg_free (void)
-{
- struct slotvec *sv = slotvec;
- unsigned int i;
- for (i = 1; i < nslots; i++)
- free (sv[i].val);
- if (sv[0].val != slot0)
- {
- free (sv[0].val);
- slotvec0.size = sizeof slot0;
- slotvec0.val = slot0;
- }
- if (sv != &slotvec0)
- {
- free (sv);
- slotvec = &slotvec0;
- }
- nslots = 1;
-}
-
-/* Use storage slot N to return a quoted version of argument ARG.
- ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a
- null-terminated string.
- OPTIONS specifies the quoting options.
- The returned value points to static storage that can be
- reused by the next call to this function with the same value of N.
- N must be nonnegative. N is deliberately declared with type "int"
- to allow for future extensions (using negative values). */
-static char *
-quotearg_n_options (int n, char const *arg, size_t argsize,
- struct quoting_options const *options)
-{
- int e = errno;
-
- unsigned int n0 = n;
- struct slotvec *sv = slotvec;
-
- if (n < 0)
- abort ();
-
- if (nslots <= n0)
- {
- /* FIXME: technically, the type of n1 should be 'unsigned int',
- but that evokes an unsuppressible warning from gcc-4.0.1 and
- older. If gcc ever provides an option to suppress that warning,
- revert to the original type, so that the test in xalloc_oversized
- is once again performed only at compile time. */
- size_t n1 = n0 + 1;
- bool preallocated = (sv == &slotvec0);
-
- if (xalloc_oversized (n1, sizeof *sv))
- xalloc_die ();
-
- slotvec = sv = xrealloc (preallocated ? NULL : sv, n1 * sizeof *sv);
- if (preallocated)
- *sv = slotvec0;
- memset (sv + nslots, 0, (n1 - nslots) * sizeof *sv);
- nslots = n1;
- }
-
- {
- size_t size = sv[n].size;
- char *val = sv[n].val;
- /* Elide embedded null bytes since we don't return a size. */
- int flags = options->flags | QA_ELIDE_NULL_BYTES;
- size_t qsize = quotearg_buffer_restyled (val, size, arg, argsize,
- options->style, flags,
- options->quote_these_too,
- options->left_quote,
- options->right_quote);
-
- if (size <= qsize)
- {
- sv[n].size = size = qsize + 1;
- if (val != slot0)
- free (val);
- sv[n].val = val = xcharalloc (size);
- quotearg_buffer_restyled (val, size, arg, argsize, options->style,
- flags, options->quote_these_too,
- options->left_quote,
- options->right_quote);
- }
-
- errno = e;
- return val;
- }
-}
-
-char *
-quotearg_n (int n, char const *arg)
-{
- return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);
-}
-
-char *
-quotearg_n_mem (int n, char const *arg, size_t argsize)
-{
- return quotearg_n_options (n, arg, argsize, &default_quoting_options);
-}
-
-char *
-quotearg (char const *arg)
-{
- return quotearg_n (0, arg);
-}
-
-char *
-quotearg_mem (char const *arg, size_t argsize)
-{
- return quotearg_n_mem (0, arg, argsize);
-}
-
-char *
-quotearg_n_style (int n, enum quoting_style s, char const *arg)
-{
- struct quoting_options const o = quoting_options_from_style (s);
- return quotearg_n_options (n, arg, SIZE_MAX, &o);
-}
-
-char *
-quotearg_n_style_mem (int n, enum quoting_style s,
- char const *arg, size_t argsize)
-{
- struct quoting_options const o = quoting_options_from_style (s);
- return quotearg_n_options (n, arg, argsize, &o);
-}
-
-char *
-quotearg_style (enum quoting_style s, char const *arg)
-{
- return quotearg_n_style (0, s, arg);
-}
-
-char *
-quotearg_style_mem (enum quoting_style s, char const *arg, size_t argsize)
-{
- return quotearg_n_style_mem (0, s, arg, argsize);
-}
-
-char *
-quotearg_char_mem (char const *arg, size_t argsize, char ch)
-{
- struct quoting_options options;
- options = default_quoting_options;
- set_char_quoting (&options, ch, 1);
- return quotearg_n_options (0, arg, argsize, &options);
-}
-
-char *
-quotearg_char (char const *arg, char ch)
-{
- return quotearg_char_mem (arg, SIZE_MAX, ch);
-}
-
-char *
-quotearg_colon (char const *arg)
-{
- return quotearg_char (arg, ':');
-}
-
-char *
-quotearg_colon_mem (char const *arg, size_t argsize)
-{
- return quotearg_char_mem (arg, argsize, ':');
-}
-
-char *
-quotearg_n_custom (int n, char const *left_quote,
- char const *right_quote, char const *arg)
-{
- return quotearg_n_custom_mem (n, left_quote, right_quote, arg,
- SIZE_MAX);
-}
-
-char *
-quotearg_n_custom_mem (int n, char const *left_quote,
- char const *right_quote,
- char const *arg, size_t argsize)
-{
- struct quoting_options o = default_quoting_options;
- set_custom_quoting (&o, left_quote, right_quote);
- return quotearg_n_options (n, arg, argsize, &o);
-}
-
-char *
-quotearg_custom (char const *left_quote, char const *right_quote,
- char const *arg)
-{
- return quotearg_n_custom (0, left_quote, right_quote, arg);
-}
-
-char *
-quotearg_custom_mem (char const *left_quote, char const *right_quote,
- char const *arg, size_t argsize)
-{
- return quotearg_n_custom_mem (0, left_quote, right_quote, arg,
- argsize);
-}
-
-
-/* The quoting option used by the functions of quote.h. */
-struct quoting_options quote_quoting_options =
- {
- locale_quoting_style,
- 0,
- { 0 },
- NULL, NULL
- };
-
-char const *
-quote_n_mem (int n, char const *arg, size_t argsize)
-{
- return quotearg_n_options (n, arg, argsize, &quote_quoting_options);
-}
-
-char const *
-quote_mem (char const *arg, size_t argsize)
-{
- return quote_n_mem (0, arg, argsize);
-}
-
-char const *
-quote_n (int n, char const *arg)
-{
- return quote_n_mem (n, arg, SIZE_MAX);
-}
-
-char const *
-quote (char const *arg)
-{
- return quote_n (0, arg);
-}
+/* quotearg.c - quote arguments for output
+
+ Copyright (C) 1998-2002, 2004-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+/* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that
+ the quoting_options_from_style function might be candidate for
+ attribute 'pure' */
+#if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+#endif
+
+#include <config.h>
+
+#include "quotearg.h"
+#include "quote.h"
+
+#include "xalloc.h"
+#include "c-strcaseeq.h"
+#include "localcharset.h"
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+#include <wctype.h>
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+
+#define INT_BITS (sizeof (int) * CHAR_BIT)
+
+struct quoting_options
+{
+ /* Basic quoting style. */
+ enum quoting_style style;
+
+ /* Additional flags. Bitwise combination of enum quoting_flags. */
+ int flags;
+
+ /* Quote the characters indicated by this bit vector even if the
+ quoting style would not normally require them to be quoted. */
+ unsigned int quote_these_too[(UCHAR_MAX / INT_BITS) + 1];
+
+ /* The left quote for custom_quoting_style. */
+ char const *left_quote;
+
+ /* The right quote for custom_quoting_style. */
+ char const *right_quote;
+};
+
+/* Names of quoting styles. */
+char const *const quoting_style_args[] =
+{
+ "literal",
+ "shell",
+ "shell-always",
+ "c",
+ "c-maybe",
+ "escape",
+ "locale",
+ "clocale",
+ 0
+};
+
+/* Correspondences to quoting style names. */
+enum quoting_style const quoting_style_vals[] =
+{
+ literal_quoting_style,
+ shell_quoting_style,
+ shell_always_quoting_style,
+ c_quoting_style,
+ c_maybe_quoting_style,
+ escape_quoting_style,
+ locale_quoting_style,
+ clocale_quoting_style
+};
+
+/* The default quoting options. */
+static struct quoting_options default_quoting_options;
+
+/* Allocate a new set of quoting options, with contents initially identical
+ to O if O is not null, or to the default if O is null.
+ It is the caller's responsibility to free the result. */
+struct quoting_options *
+clone_quoting_options (struct quoting_options *o)
+{
+ int e = errno;
+ struct quoting_options *p = xmemdup (o ? o : &default_quoting_options,
+ sizeof *o);
+ errno = e;
+ return p;
+}
+
+/* Get the value of O's quoting style. If O is null, use the default. */
+enum quoting_style
+get_quoting_style (struct quoting_options *o)
+{
+ return (o ? o : &default_quoting_options)->style;
+}
+
+/* In O (or in the default if O is null),
+ set the value of the quoting style to S. */
+void
+set_quoting_style (struct quoting_options *o, enum quoting_style s)
+{
+ (o ? o : &default_quoting_options)->style = s;
+}
+
+/* In O (or in the default if O is null),
+ set the value of the quoting options for character C to I.
+ Return the old value. Currently, the only values defined for I are
+ 0 (the default) and 1 (which means to quote the character even if
+ it would not otherwise be quoted). */
+int
+set_char_quoting (struct quoting_options *o, char c, int i)
+{
+ unsigned char uc = c;
+ unsigned int *p =
+ (o ? o : &default_quoting_options)->quote_these_too + uc / INT_BITS;
+ int shift = uc % INT_BITS;
+ int r = (*p >> shift) & 1;
+ *p ^= ((i & 1) ^ r) << shift;
+ return r;
+}
+
+/* In O (or in the default if O is null),
+ set the value of the quoting options flag to I, which can be a
+ bitwise combination of enum quoting_flags, or 0 for default
+ behavior. Return the old value. */
+int
+set_quoting_flags (struct quoting_options *o, int i)
+{
+ int r;
+ if (!o)
+ o = &default_quoting_options;
+ r = o->flags;
+ o->flags = i;
+ return r;
+}
+
+void
+set_custom_quoting (struct quoting_options *o,
+ char const *left_quote, char const *right_quote)
+{
+ if (!o)
+ o = &default_quoting_options;
+ o->style = custom_quoting_style;
+ if (!left_quote || !right_quote)
+ abort ();
+ o->left_quote = left_quote;
+ o->right_quote = right_quote;
+}
+
+/* Return quoting options for STYLE, with no extra quoting. */
+static struct quoting_options /* NOT PURE!! */
+quoting_options_from_style (enum quoting_style style)
+{
+ struct quoting_options o = { 0, 0, { 0 }, NULL, NULL };
+ if (style == custom_quoting_style)
+ abort ();
+ o.style = style;
+ return o;
+}
+
+/* MSGID approximates a quotation mark. Return its translation if it
+ has one; otherwise, return either it or "\"", depending on S.
+
+ S is either clocale_quoting_style or locale_quoting_style. */
+static char const *
+gettext_quote (char const *msgid, enum quoting_style s)
+{
+ char const *translation = _(msgid);
+ char const *locale_code;
+
+ if (translation != msgid)
+ return translation;
+
+ /* For UTF-8 and GB-18030, use single quotes U+2018 and U+2019.
+ Here is a list of other locales that include U+2018 and U+2019:
+
+ ISO-8859-7 0xA1 KOI8-T 0x91
+ CP869 0x8B CP874 0x91
+ CP932 0x81 0x65 CP936 0xA1 0xAE
+ CP949 0xA1 0xAE CP950 0xA1 0xA5
+ CP1250 0x91 CP1251 0x91
+ CP1252 0x91 CP1253 0x91
+ CP1254 0x91 CP1255 0x91
+ CP1256 0x91 CP1257 0x91
+ EUC-JP 0xA1 0xC6 EUC-KR 0xA1 0xAE
+ EUC-TW 0xA1 0xE4 BIG5 0xA1 0xA5
+ BIG5-HKSCS 0xA1 0xA5 EUC-CN 0xA1 0xAE
+ GBK 0xA1 0xAE Georgian-PS 0x91
+ PT154 0x91
+
+ None of these is still in wide use; using iconv is overkill. */
+ locale_code = locale_charset ();
+ if (STRCASEEQ (locale_code, "UTF-8", 'U','T','F','-','8',0,0,0,0))
+ return msgid[0] == '`' ? "\xe2\x80\x98": "\xe2\x80\x99";
+ if (STRCASEEQ (locale_code, "GB18030", 'G','B','1','8','0','3','0',0,0))
+ return msgid[0] == '`' ? "\xa1\ae": "\xa1\xaf";
+
+ return (s == clocale_quoting_style ? "\"" : "'");
+}
+
+/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
+ argument ARG (of size ARGSIZE), using QUOTING_STYLE, FLAGS, and
+ QUOTE_THESE_TOO to control quoting.
+ Terminate the output with a null character, and return the written
+ size of the output, not counting the terminating null.
+ If BUFFERSIZE is too small to store the output string, return the
+ value that would have been returned had BUFFERSIZE been large enough.
+ If ARGSIZE is SIZE_MAX, use the string length of the argument for ARGSIZE.
+
+ This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG,
+ ARGSIZE, O), except it breaks O into its component pieces and is
+ not careful about errno. */
+
+static size_t
+quotearg_buffer_restyled (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ enum quoting_style quoting_style, int flags,
+ unsigned int const *quote_these_too,
+ char const *left_quote,
+ char const *right_quote)
+{
+ size_t i;
+ size_t len = 0;
+ char const *quote_string = 0;
+ size_t quote_string_len = 0;
+ bool backslash_escapes = false;
+ bool unibyte_locale = MB_CUR_MAX == 1;
+ bool elide_outer_quotes = (flags & QA_ELIDE_OUTER_QUOTES) != 0;
+
+#define STORE(c) \
+ do \
+ { \
+ if (len < buffersize) \
+ buffer[len] = (c); \
+ len++; \
+ } \
+ while (0)
+
+ switch (quoting_style)
+ {
+ case c_maybe_quoting_style:
+ quoting_style = c_quoting_style;
+ elide_outer_quotes = true;
+ /* Fall through. */
+ case c_quoting_style:
+ if (!elide_outer_quotes)
+ STORE ('"');
+ backslash_escapes = true;
+ quote_string = "\"";
+ quote_string_len = 1;
+ break;
+
+ case escape_quoting_style:
+ backslash_escapes = true;
+ elide_outer_quotes = false;
+ break;
+
+ case locale_quoting_style:
+ case clocale_quoting_style:
+ case custom_quoting_style:
+ {
+ if (quoting_style != custom_quoting_style)
+ {
+ /* TRANSLATORS:
+ Get translations for open and closing quotation marks.
+ The message catalog should translate "`" to a left
+ quotation mark suitable for the locale, and similarly for
+ "'". For example, a French Unicode local should translate
+ these to U+00AB (LEFT-POINTING DOUBLE ANGLE
+ QUOTATION MARK), and U+00BB (RIGHT-POINTING DOUBLE ANGLE
+ QUOTATION MARK), respectively.
+
+ If the catalog has no translation, we will try to
+ use Unicode U+2018 (LEFT SINGLE QUOTATION MARK) and
+ Unicode U+2019 (RIGHT SINGLE QUOTATION MARK). If the
+ current locale is not Unicode, locale_quoting_style
+ will quote 'like this', and clocale_quoting_style will
+ quote "like this". You should always include translations
+ for "`" and "'" even if U+2018 and U+2019 are appropriate
+ for your locale.
+
+ If you don't know what to put here, please see
+ <http://en.wikipedia.org/wiki/Quotation_marks_in_other_languages>
+ and use glyphs suitable for your language. */
+ left_quote = gettext_quote (N_("`"), quoting_style);
+ right_quote = gettext_quote (N_("'"), quoting_style);
+ }
+ if (!elide_outer_quotes)
+ for (quote_string = left_quote; *quote_string; quote_string++)
+ STORE (*quote_string);
+ backslash_escapes = true;
+ quote_string = right_quote;
+ quote_string_len = strlen (quote_string);
+ }
+ break;
+
+ case shell_quoting_style:
+ quoting_style = shell_always_quoting_style;
+ elide_outer_quotes = true;
+ /* Fall through. */
+ case shell_always_quoting_style:
+ if (!elide_outer_quotes)
+ STORE ('\'');
+ quote_string = "'";
+ quote_string_len = 1;
+ break;
+
+ case literal_quoting_style:
+ elide_outer_quotes = false;
+ break;
+
+ default:
+ abort ();
+ }
+
+ for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++)
+ {
+ unsigned char c;
+ unsigned char esc;
+ bool is_right_quote = false;
+
+ if (backslash_escapes
+ && quote_string_len
+ && (i + quote_string_len
+ <= (argsize == SIZE_MAX && 1 < quote_string_len
+ /* Use strlen only if we must: when argsize is SIZE_MAX,
+ and when the quote string is more than 1 byte long.
+ If we do call strlen, save the result. */
+ ? (argsize = strlen (arg)) : argsize))
+ && memcmp (arg + i, quote_string, quote_string_len) == 0)
+ {
+ if (elide_outer_quotes)
+ goto force_outer_quoting_style;
+ is_right_quote = true;
+ }
+
+ c = arg[i];
+ switch (c)
+ {
+ case '\0':
+ if (backslash_escapes)
+ {
+ if (elide_outer_quotes)
+ goto force_outer_quoting_style;
+ STORE ('\\');
+ /* If quote_string were to begin with digits, we'd need to
+ test for the end of the arg as well. However, it's
+ hard to imagine any locale that would use digits in
+ quotes, and set_custom_quoting is documented not to
+ accept them. */
+ if (i + 1 < argsize && '0' <= arg[i + 1] && arg[i + 1] <= '9')
+ {
+ STORE ('0');
+ STORE ('0');
+ }
+ c = '0';
+ /* We don't have to worry that this last '0' will be
+ backslash-escaped because, again, quote_string should
+ not start with it and because quote_these_too is
+ documented as not accepting it. */
+ }
+ else if (flags & QA_ELIDE_NULL_BYTES)
+ continue;
+ break;
+
+ case '?':
+ switch (quoting_style)
+ {
+ case shell_always_quoting_style:
+ if (elide_outer_quotes)
+ goto force_outer_quoting_style;
+ break;
+
+ case c_quoting_style:
+ if ((flags & QA_SPLIT_TRIGRAPHS)
+ && i + 2 < argsize && arg[i + 1] == '?')
+ switch (arg[i + 2])
+ {
+ case '!': case '\'':
+ case '(': case ')': case '-': case '/':
+ case '<': case '=': case '>':
+ /* Escape the second '?' in what would otherwise be
+ a trigraph. */
+ if (elide_outer_quotes)
+ goto force_outer_quoting_style;
+ c = arg[i + 2];
+ i += 2;
+ STORE ('?');
+ STORE ('"');
+ STORE ('"');
+ STORE ('?');
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case '\a': esc = 'a'; goto c_escape;
+ case '\b': esc = 'b'; goto c_escape;
+ case '\f': esc = 'f'; goto c_escape;
+ case '\n': esc = 'n'; goto c_and_shell_escape;
+ case '\r': esc = 'r'; goto c_and_shell_escape;
+ case '\t': esc = 't'; goto c_and_shell_escape;
+ case '\v': esc = 'v'; goto c_escape;
+ case '\\': esc = c;
+ /* No need to escape the escape if we are trying to elide
+ outer quotes and nothing else is problematic. */
+ if (backslash_escapes && elide_outer_quotes && quote_string_len)
+ goto store_c;
+
+ c_and_shell_escape:
+ if (quoting_style == shell_always_quoting_style
+ && elide_outer_quotes)
+ goto force_outer_quoting_style;
+ /* Fall through. */
+ c_escape:
+ if (backslash_escapes)
+ {
+ c = esc;
+ goto store_escape;
+ }
+ break;
+
+ case '{': case '}': /* sometimes special if isolated */
+ if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1))
+ break;
+ /* Fall through. */
+ case '#': case '~':
+ if (i != 0)
+ break;
+ /* Fall through. */
+ case ' ':
+ case '!': /* special in bash */
+ case '"': case '$': case '&':
+ case '(': case ')': case '*': case ';':
+ case '<':
+ case '=': /* sometimes special in 0th or (with "set -k") later args */
+ case '>': case '[':
+ case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */
+ case '`': case '|':
+ /* A shell special character. In theory, '$' and '`' could
+ be the first bytes of multibyte characters, which means
+ we should check them with mbrtowc, but in practice this
+ doesn't happen so it's not worth worrying about. */
+ if (quoting_style == shell_always_quoting_style
+ && elide_outer_quotes)
+ goto force_outer_quoting_style;
+ break;
+
+ case '\'':
+ if (quoting_style == shell_always_quoting_style)
+ {
+ if (elide_outer_quotes)
+ goto force_outer_quoting_style;
+ STORE ('\'');
+ STORE ('\\');
+ STORE ('\'');
+ }
+ break;
+
+ case '%': case '+': case ',': case '-': case '.': case '/':
+ case '0': case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9': case ':':
+ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+ case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
+ case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
+ case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
+ case 'Y': case 'Z': case ']': case '_': case 'a': case 'b':
+ case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
+ case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
+ case 'o': case 'p': case 'q': case 'r': case 's': case 't':
+ case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
+ /* These characters don't cause problems, no matter what the
+ quoting style is. They cannot start multibyte sequences.
+ A digit or a special letter would cause trouble if it
+ appeared at the beginning of quote_string because we'd then
+ escape by prepending a backslash. However, it's hard to
+ imagine any locale that would use digits or letters as
+ quotes, and set_custom_quoting is documented not to accept
+ them. Also, a digit or a special letter would cause
+ trouble if it appeared in quote_these_too, but that's also
+ documented as not accepting them. */
+ break;
+
+ default:
+ /* If we have a multibyte sequence, copy it until we reach
+ its end, find an error, or come back to the initial shift
+ state. For C-like styles, if the sequence has
+ unprintable characters, escape the whole sequence, since
+ we can't easily escape single characters within it. */
+ {
+ /* Length of multibyte sequence found so far. */
+ size_t m;
+
+ bool printable;
+
+ if (unibyte_locale)
+ {
+ m = 1;
+ printable = isprint (c) != 0;
+ }
+ else
+ {
+ mbstate_t mbstate;
+ memset (&mbstate, 0, sizeof mbstate);
+
+ m = 0;
+ printable = true;
+ if (argsize == SIZE_MAX)
+ argsize = strlen (arg);
+
+ do
+ {
+ wchar_t w;
+ size_t bytes = mbrtowc (&w, &arg[i + m],
+ argsize - (i + m), &mbstate);
+ if (bytes == 0)
+ break;
+ else if (bytes == (size_t) -1)
+ {
+ printable = false;
+ break;
+ }
+ else if (bytes == (size_t) -2)
+ {
+ printable = false;
+ while (i + m < argsize && arg[i + m])
+ m++;
+ break;
+ }
+ else
+ {
+ /* Work around a bug with older shells that "see" a '\'
+ that is really the 2nd byte of a multibyte character.
+ In practice the problem is limited to ASCII
+ chars >= '@' that are shell special chars. */
+ if ('[' == 0x5b && elide_outer_quotes
+ && quoting_style == shell_always_quoting_style)
+ {
+ size_t j;
+ for (j = 1; j < bytes; j++)
+ switch (arg[i + m + j])
+ {
+ case '[': case '\\': case '^':
+ case '`': case '|':
+ goto force_outer_quoting_style;
+
+ default:
+ break;
+ }
+ }
+
+ if (! iswprint (w))
+ printable = false;
+ m += bytes;
+ }
+ }
+ while (! mbsinit (&mbstate));
+ }
+
+ if (1 < m || (backslash_escapes && ! printable))
+ {
+ /* Output a multibyte sequence, or an escaped
+ unprintable unibyte character. */
+ size_t ilim = i + m;
+
+ for (;;)
+ {
+ if (backslash_escapes && ! printable)
+ {
+ if (elide_outer_quotes)
+ goto force_outer_quoting_style;
+ STORE ('\\');
+ STORE ('0' + (c >> 6));
+ STORE ('0' + ((c >> 3) & 7));
+ c = '0' + (c & 7);
+ }
+ else if (is_right_quote)
+ {
+ STORE ('\\');
+ is_right_quote = false;
+ }
+ if (ilim <= i + 1)
+ break;
+ STORE (c);
+ c = arg[++i];
+ }
+
+ goto store_c;
+ }
+ }
+ }
+
+ if (! ((backslash_escapes || elide_outer_quotes)
+ && quote_these_too
+ && quote_these_too[c / INT_BITS] & (1 << (c % INT_BITS)))
+ && !is_right_quote)
+ goto store_c;
+
+ store_escape:
+ if (elide_outer_quotes)
+ goto force_outer_quoting_style;
+ STORE ('\\');
+
+ store_c:
+ STORE (c);
+ }
+
+ if (len == 0 && quoting_style == shell_always_quoting_style
+ && elide_outer_quotes)
+ goto force_outer_quoting_style;
+
+ if (quote_string && !elide_outer_quotes)
+ for (; *quote_string; quote_string++)
+ STORE (*quote_string);
+
+ if (len < buffersize)
+ buffer[len] = '\0';
+ return len;
+
+ force_outer_quoting_style:
+ /* Don't reuse quote_these_too, since the addition of outer quotes
+ sufficiently quotes the specified characters. */
+ return quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
+ quoting_style,
+ flags & ~QA_ELIDE_OUTER_QUOTES, NULL,
+ left_quote, right_quote);
+}
+
+/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
+ argument ARG (of size ARGSIZE), using O to control quoting.
+ If O is null, use the default.
+ Terminate the output with a null character, and return the written
+ size of the output, not counting the terminating null.
+ If BUFFERSIZE is too small to store the output string, return the
+ value that would have been returned had BUFFERSIZE been large enough.
+ If ARGSIZE is SIZE_MAX, use the string length of the argument for
+ ARGSIZE. */
+size_t
+quotearg_buffer (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ struct quoting_options const *o)
+{
+ struct quoting_options const *p = o ? o : &default_quoting_options;
+ int e = errno;
+ size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
+ p->style, p->flags, p->quote_these_too,
+ p->left_quote, p->right_quote);
+ errno = e;
+ return r;
+}
+
+/* Equivalent to quotearg_alloc (ARG, ARGSIZE, NULL, O). */
+char *
+quotearg_alloc (char const *arg, size_t argsize,
+ struct quoting_options const *o)
+{
+ return quotearg_alloc_mem (arg, argsize, NULL, o);
+}
+
+/* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly
+ allocated storage containing the quoted string, and store the
+ resulting size into *SIZE, if non-NULL. The result can contain
+ embedded null bytes only if ARGSIZE is not SIZE_MAX, SIZE is not
+ NULL, and set_quoting_flags has not set the null byte elision
+ flag. */
+char *
+quotearg_alloc_mem (char const *arg, size_t argsize, size_t *size,
+ struct quoting_options const *o)
+{
+ struct quoting_options const *p = o ? o : &default_quoting_options;
+ int e = errno;
+ /* Elide embedded null bytes if we can't return a size. */
+ int flags = p->flags | (size ? 0 : QA_ELIDE_NULL_BYTES);
+ size_t bufsize = quotearg_buffer_restyled (0, 0, arg, argsize, p->style,
+ flags, p->quote_these_too,
+ p->left_quote,
+ p->right_quote) + 1;
+ char *buf = xcharalloc (bufsize);
+ quotearg_buffer_restyled (buf, bufsize, arg, argsize, p->style, flags,
+ p->quote_these_too,
+ p->left_quote, p->right_quote);
+ errno = e;
+ if (size)
+ *size = bufsize - 1;
+ return buf;
+}
+
+/* A storage slot with size and pointer to a value. */
+struct slotvec
+{
+ size_t size;
+ char *val;
+};
+
+/* Preallocate a slot 0 buffer, so that the caller can always quote
+ one small component of a "memory exhausted" message in slot 0. */
+static char slot0[256];
+static unsigned int nslots = 1;
+static struct slotvec slotvec0 = {sizeof slot0, slot0};
+static struct slotvec *slotvec = &slotvec0;
+
+void
+quotearg_free (void)
+{
+ struct slotvec *sv = slotvec;
+ unsigned int i;
+ for (i = 1; i < nslots; i++)
+ free (sv[i].val);
+ if (sv[0].val != slot0)
+ {
+ free (sv[0].val);
+ slotvec0.size = sizeof slot0;
+ slotvec0.val = slot0;
+ }
+ if (sv != &slotvec0)
+ {
+ free (sv);
+ slotvec = &slotvec0;
+ }
+ nslots = 1;
+}
+
+/* Use storage slot N to return a quoted version of argument ARG.
+ ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a
+ null-terminated string.
+ OPTIONS specifies the quoting options.
+ The returned value points to static storage that can be
+ reused by the next call to this function with the same value of N.
+ N must be nonnegative. N is deliberately declared with type "int"
+ to allow for future extensions (using negative values). */
+static char *
+quotearg_n_options (int n, char const *arg, size_t argsize,
+ struct quoting_options const *options)
+{
+ int e = errno;
+
+ unsigned int n0 = n;
+ struct slotvec *sv = slotvec;
+
+ if (n < 0)
+ abort ();
+
+ if (nslots <= n0)
+ {
+ /* FIXME: technically, the type of n1 should be 'unsigned int',
+ but that evokes an unsuppressible warning from gcc-4.0.1 and
+ older. If gcc ever provides an option to suppress that warning,
+ revert to the original type, so that the test in xalloc_oversized
+ is once again performed only at compile time. */
+ size_t n1 = n0 + 1;
+ bool preallocated = (sv == &slotvec0);
+
+ if (xalloc_oversized (n1, sizeof *sv))
+ xalloc_die ();
+
+ slotvec = sv = xrealloc (preallocated ? NULL : sv, n1 * sizeof *sv);
+ if (preallocated)
+ *sv = slotvec0;
+ memset (sv + nslots, 0, (n1 - nslots) * sizeof *sv);
+ nslots = n1;
+ }
+
+ {
+ size_t size = sv[n].size;
+ char *val = sv[n].val;
+ /* Elide embedded null bytes since we don't return a size. */
+ int flags = options->flags | QA_ELIDE_NULL_BYTES;
+ size_t qsize = quotearg_buffer_restyled (val, size, arg, argsize,
+ options->style, flags,
+ options->quote_these_too,
+ options->left_quote,
+ options->right_quote);
+
+ if (size <= qsize)
+ {
+ sv[n].size = size = qsize + 1;
+ if (val != slot0)
+ free (val);
+ sv[n].val = val = xcharalloc (size);
+ quotearg_buffer_restyled (val, size, arg, argsize, options->style,
+ flags, options->quote_these_too,
+ options->left_quote,
+ options->right_quote);
+ }
+
+ errno = e;
+ return val;
+ }
+}
+
+char *
+quotearg_n (int n, char const *arg)
+{
+ return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);
+}
+
+char *
+quotearg_n_mem (int n, char const *arg, size_t argsize)
+{
+ return quotearg_n_options (n, arg, argsize, &default_quoting_options);
+}
+
+char *
+quotearg (char const *arg)
+{
+ return quotearg_n (0, arg);
+}
+
+char *
+quotearg_mem (char const *arg, size_t argsize)
+{
+ return quotearg_n_mem (0, arg, argsize);
+}
+
+char *
+quotearg_n_style (int n, enum quoting_style s, char const *arg)
+{
+ struct quoting_options const o = quoting_options_from_style (s);
+ return quotearg_n_options (n, arg, SIZE_MAX, &o);
+}
+
+char *
+quotearg_n_style_mem (int n, enum quoting_style s,
+ char const *arg, size_t argsize)
+{
+ struct quoting_options const o = quoting_options_from_style (s);
+ return quotearg_n_options (n, arg, argsize, &o);
+}
+
+char *
+quotearg_style (enum quoting_style s, char const *arg)
+{
+ return quotearg_n_style (0, s, arg);
+}
+
+char *
+quotearg_style_mem (enum quoting_style s, char const *arg, size_t argsize)
+{
+ return quotearg_n_style_mem (0, s, arg, argsize);
+}
+
+char *
+quotearg_char_mem (char const *arg, size_t argsize, char ch)
+{
+ struct quoting_options options;
+ options = default_quoting_options;
+ set_char_quoting (&options, ch, 1);
+ return quotearg_n_options (0, arg, argsize, &options);
+}
+
+char *
+quotearg_char (char const *arg, char ch)
+{
+ return quotearg_char_mem (arg, SIZE_MAX, ch);
+}
+
+char *
+quotearg_colon (char const *arg)
+{
+ return quotearg_char (arg, ':');
+}
+
+char *
+quotearg_colon_mem (char const *arg, size_t argsize)
+{
+ return quotearg_char_mem (arg, argsize, ':');
+}
+
+char *
+quotearg_n_custom (int n, char const *left_quote,
+ char const *right_quote, char const *arg)
+{
+ return quotearg_n_custom_mem (n, left_quote, right_quote, arg,
+ SIZE_MAX);
+}
+
+char *
+quotearg_n_custom_mem (int n, char const *left_quote,
+ char const *right_quote,
+ char const *arg, size_t argsize)
+{
+ struct quoting_options o = default_quoting_options;
+ set_custom_quoting (&o, left_quote, right_quote);
+ return quotearg_n_options (n, arg, argsize, &o);
+}
+
+char *
+quotearg_custom (char const *left_quote, char const *right_quote,
+ char const *arg)
+{
+ return quotearg_n_custom (0, left_quote, right_quote, arg);
+}
+
+char *
+quotearg_custom_mem (char const *left_quote, char const *right_quote,
+ char const *arg, size_t argsize)
+{
+ return quotearg_n_custom_mem (0, left_quote, right_quote, arg,
+ argsize);
+}
+
+
+/* The quoting option used by the functions of quote.h. */
+struct quoting_options quote_quoting_options =
+ {
+ locale_quoting_style,
+ 0,
+ { 0 },
+ NULL, NULL
+ };
+
+char const *
+quote_n_mem (int n, char const *arg, size_t argsize)
+{
+ return quotearg_n_options (n, arg, argsize, &quote_quoting_options);
+}
+
+char const *
+quote_mem (char const *arg, size_t argsize)
+{
+ return quote_n_mem (0, arg, argsize);
+}
+
+char const *
+quote_n (int n, char const *arg)
+{
+ return quote_n_mem (n, arg, SIZE_MAX);
+}
+
+char const *
+quote (char const *arg)
+{
+ return quote_n (0, arg);
+}
diff --git a/contrib/tools/bison/gnulib/src/quotearg.h b/contrib/tools/bison/gnulib/src/quotearg.h
index 58ee3f6089..413fb83f1c 100644
--- a/contrib/tools/bison/gnulib/src/quotearg.h
+++ b/contrib/tools/bison/gnulib/src/quotearg.h
@@ -1,391 +1,391 @@
-/* quotearg.h - quote arguments for output
-
- Copyright (C) 1998-2002, 2004, 2006, 2008-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert <eggert@twinsun.com> */
-
-#ifndef QUOTEARG_H_
-# define QUOTEARG_H_ 1
-
-# include <stddef.h>
-
-/* Basic quoting styles. For each style, an example is given on the
- input strings "simple", "\0 \t\n'\"\033?""?/\\", and "a:b", using
- quotearg_buffer, quotearg_mem, and quotearg_colon_mem with that
- style and the default flags and quoted characters. Note that the
- examples are shown here as valid C strings rather than what
- displays on a terminal (with "??/" as a trigraph for "\\"). */
-enum quoting_style
- {
- /* Output names as-is (ls --quoting-style=literal). Can result in
- embedded null bytes if QA_ELIDE_NULL_BYTES is not in
- effect.
-
- quotearg_buffer:
- "simple", "\0 \t\n'\"\033??/\\", "a:b"
- quotearg:
- "simple", " \t\n'\"\033??/\\", "a:b"
- quotearg_colon:
- "simple", " \t\n'\"\033??/\\", "a:b"
- */
- literal_quoting_style,
-
- /* Quote names for the shell if they contain shell metacharacters
- or would cause ambiguous output (ls --quoting-style=shell).
- Can result in embedded null bytes if QA_ELIDE_NULL_BYTES is not
- in effect.
-
- quotearg_buffer:
- "simple", "'\0 \t\n'\\''\"\033??/\\'", "a:b"
- quotearg:
- "simple", "' \t\n'\\''\"\033??/\\'", "a:b"
- quotearg_colon:
- "simple", "' \t\n'\\''\"\033??/\\'", "'a:b'"
- */
- shell_quoting_style,
-
- /* Quote names for the shell, even if they would normally not
- require quoting (ls --quoting-style=shell-always). Can result
- in embedded null bytes if QA_ELIDE_NULL_BYTES is not in effect.
- Behaves like shell_quoting_style if QA_ELIDE_OUTER_QUOTES is in
- effect.
-
- quotearg_buffer:
- "'simple'", "'\0 \t\n'\\''\"\033??/\\'", "'a:b'"
- quotearg:
- "'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
- quotearg_colon:
- "'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
- */
- shell_always_quoting_style,
-
- /* Quote names as for a C language string (ls --quoting-style=c).
- Behaves like c_maybe_quoting_style if QA_ELIDE_OUTER_QUOTES is
- in effect. Split into consecutive strings if
- QA_SPLIT_TRIGRAPHS.
-
- quotearg_buffer:
- "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
- quotearg:
- "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
- quotearg_colon:
- "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
- */
- c_quoting_style,
-
- /* Like c_quoting_style except omit the surrounding double-quote
- characters if no quoted characters are encountered.
-
- quotearg_buffer:
- "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
- quotearg:
- "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
- quotearg_colon:
- "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
- */
- c_maybe_quoting_style,
-
- /* Like c_quoting_style except always omit the surrounding
- double-quote characters and ignore QA_SPLIT_TRIGRAPHS
- (ls --quoting-style=escape).
-
- quotearg_buffer:
- "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
- quotearg:
- "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
- quotearg_colon:
- "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a\\:b"
- */
- escape_quoting_style,
-
- /* Like clocale_quoting_style, but use single quotes in the
- default C locale or if the program does not use gettext
- (ls --quoting-style=locale). For UTF-8 locales, quote
- characters will use Unicode.
-
- LC_MESSAGES=C
- quotearg_buffer:
- "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
- quotearg:
- "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
- quotearg_colon:
- "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a\\:b'"
-
- LC_MESSAGES=pt_PT.utf8
- quotearg_buffer:
- "\302\253simple\302\273",
- "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
- quotearg:
- "\302\253simple\302\273",
- "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
- quotearg_colon:
- "\302\253simple\302\273",
- "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
- */
- locale_quoting_style,
-
- /* Like c_quoting_style except use quotation marks appropriate for
- the locale and ignore QA_SPLIT_TRIGRAPHS
- (ls --quoting-style=clocale).
-
- LC_MESSAGES=C
- quotearg_buffer:
- "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
- quotearg:
- "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
- quotearg_colon:
- "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
-
- LC_MESSAGES=pt_PT.utf8
- quotearg_buffer:
- "\302\253simple\302\273",
- "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
- quotearg:
- "\302\253simple\302\273",
- "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
- quotearg_colon:
- "\302\253simple\302\273",
- "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
- */
- clocale_quoting_style,
-
- /* Like clocale_quoting_style except use the custom quotation marks
- set by set_custom_quoting. If custom quotation marks are not
- set, the behavior is undefined.
-
- left_quote = right_quote = "'"
- quotearg_buffer:
- "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a:b'"
- quotearg:
- "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a:b'"
- quotearg_colon:
- "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a\\:b'"
-
- left_quote = "(" and right_quote = ")"
- quotearg_buffer:
- "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a:b)"
- quotearg:
- "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a:b)"
- quotearg_colon:
- "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a\\:b)"
-
- left_quote = ":" and right_quote = " "
- quotearg_buffer:
- ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a:b "
- quotearg:
- ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a:b "
- quotearg_colon:
- ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a\\:b "
-
- left_quote = "\"'" and right_quote = "'\""
- Notice that this is treated as a single level of quotes or two
- levels where the outer quote need not be escaped within the inner
- quotes. For two levels where the outer quote must be escaped
- within the inner quotes, you must use separate quotearg
- invocations.
- quotearg_buffer:
- "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a:b'\""
- quotearg:
- "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a:b'\""
- quotearg_colon:
- "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a\\:b'\""
- */
- custom_quoting_style
- };
-
-/* Flags for use in set_quoting_flags. */
-enum quoting_flags
- {
- /* Always elide null bytes from styles that do not quote them,
- even when the length of the result is available to the
- caller. */
- QA_ELIDE_NULL_BYTES = 0x01,
-
- /* Omit the surrounding quote characters if no escaped characters
- are encountered. Note that if no other character needs
- escaping, then neither does the escape character. */
- QA_ELIDE_OUTER_QUOTES = 0x02,
-
- /* In the c_quoting_style and c_maybe_quoting_style, split ANSI
- trigraph sequences into concatenated strings (for example,
- "?""?/" rather than "??/", which could be confused with
- "\\"). */
- QA_SPLIT_TRIGRAPHS = 0x04
- };
-
-/* For now, --quoting-style=literal is the default, but this may change. */
-# ifndef DEFAULT_QUOTING_STYLE
-# define DEFAULT_QUOTING_STYLE literal_quoting_style
-# endif
-
-/* Names of quoting styles and their corresponding values. */
-extern char const *const quoting_style_args[];
-extern enum quoting_style const quoting_style_vals[];
-
-struct quoting_options;
-
-/* The functions listed below set and use a hidden variable
- that contains the default quoting style options. */
-
-/* Allocate a new set of quoting options, with contents initially identical
- to O if O is not null, or to the default if O is null.
- It is the caller's responsibility to free the result. */
-struct quoting_options *clone_quoting_options (struct quoting_options *o);
-
-/* Get the value of O's quoting style. If O is null, use the default. */
-enum quoting_style get_quoting_style (struct quoting_options *o);
-
-/* In O (or in the default if O is null),
- set the value of the quoting style to S. */
-void set_quoting_style (struct quoting_options *o, enum quoting_style s);
-
-/* In O (or in the default if O is null),
- set the value of the quoting options for character C to I.
- Return the old value. Currently, the only values defined for I are
- 0 (the default) and 1 (which means to quote the character even if
- it would not otherwise be quoted). C must never be a digit or a
- letter that has special meaning after a backslash (for example, "\t"
- for tab). */
-int set_char_quoting (struct quoting_options *o, char c, int i);
-
-/* In O (or in the default if O is null),
- set the value of the quoting options flag to I, which can be a
- bitwise combination of enum quoting_flags, or 0 for default
- behavior. Return the old value. */
-int set_quoting_flags (struct quoting_options *o, int i);
-
-/* In O (or in the default if O is null),
- set the value of the quoting style to custom_quoting_style,
- set the left quote to LEFT_QUOTE, and set the right quote to
- RIGHT_QUOTE. Each of LEFT_QUOTE and RIGHT_QUOTE must be
- null-terminated and can be the empty string. Because backslashes are
- used for escaping, it does not make sense for RIGHT_QUOTE to contain
- a backslash. RIGHT_QUOTE must not begin with a digit or a letter
- that has special meaning after a backslash (for example, "\t" for
- tab). */
-void set_custom_quoting (struct quoting_options *o,
- char const *left_quote,
- char const *right_quote);
-
-/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
- argument ARG (of size ARGSIZE), using O to control quoting.
- If O is null, use the default.
- Terminate the output with a null character, and return the written
- size of the output, not counting the terminating null.
- If BUFFERSIZE is too small to store the output string, return the
- value that would have been returned had BUFFERSIZE been large enough.
- If ARGSIZE is -1, use the string length of the argument for ARGSIZE.
- On output, BUFFER might contain embedded null bytes if ARGSIZE was
- not -1, the style of O does not use backslash escapes, and the
- flags of O do not request elision of null bytes.*/
-size_t quotearg_buffer (char *buffer, size_t buffersize,
- char const *arg, size_t argsize,
- struct quoting_options const *o);
-
-/* Like quotearg_buffer, except return the result in a newly allocated
- buffer. It is the caller's responsibility to free the result. The
- result will not contain embedded null bytes. */
-char *quotearg_alloc (char const *arg, size_t argsize,
- struct quoting_options const *o);
-
-/* Like quotearg_alloc, except that the length of the result,
- excluding the terminating null byte, is stored into SIZE if it is
- non-NULL. The result might contain embedded null bytes if ARGSIZE
- was not -1, SIZE was not NULL, the style of O does not use
- backslash escapes, and the flags of O do not request elision of
- null bytes.*/
-char *quotearg_alloc_mem (char const *arg, size_t argsize,
- size_t *size, struct quoting_options const *o);
-
-/* Use storage slot N to return a quoted version of the string ARG.
- Use the default quoting options.
- The returned value points to static storage that can be
- reused by the next call to this function with the same value of N.
- N must be nonnegative. The output of all functions in the
- quotearg_n family are guaranteed to not contain embedded null
- bytes.*/
-char *quotearg_n (int n, char const *arg);
-
-/* Equivalent to quotearg_n (0, ARG). */
-char *quotearg (char const *arg);
-
-/* Use storage slot N to return a quoted version of the argument ARG
- of size ARGSIZE. This is like quotearg_n (N, ARG), except it can
- quote null bytes. */
-char *quotearg_n_mem (int n, char const *arg, size_t argsize);
-
-/* Equivalent to quotearg_n_mem (0, ARG, ARGSIZE). */
-char *quotearg_mem (char const *arg, size_t argsize);
-
-/* Use style S and storage slot N to return a quoted version of the string ARG.
- This is like quotearg_n (N, ARG), except that it uses S with no other
- options to specify the quoting method. */
-char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
-
-/* Use style S and storage slot N to return a quoted version of the
- argument ARG of size ARGSIZE. This is like quotearg_n_style
- (N, S, ARG), except it can quote null bytes. */
-char *quotearg_n_style_mem (int n, enum quoting_style s,
- char const *arg, size_t argsize);
-
-/* Equivalent to quotearg_n_style (0, S, ARG). */
-char *quotearg_style (enum quoting_style s, char const *arg);
-
-/* Equivalent to quotearg_n_style_mem (0, S, ARG, ARGSIZE). */
-char *quotearg_style_mem (enum quoting_style s,
- char const *arg, size_t argsize);
-
-/* Like quotearg (ARG), except also quote any instances of CH.
- See set_char_quoting for a description of acceptable CH values. */
-char *quotearg_char (char const *arg, char ch);
-
-/* Like quotearg_char (ARG, CH), except it can quote null bytes. */
-char *quotearg_char_mem (char const *arg, size_t argsize, char ch);
-
-/* Equivalent to quotearg_char (ARG, ':'). */
-char *quotearg_colon (char const *arg);
-
-/* Like quotearg_colon (ARG), except it can quote null bytes. */
-char *quotearg_colon_mem (char const *arg, size_t argsize);
-
-/* Like quotearg_n_style (N, S, ARG) but with S as custom_quoting_style
- with left quote as LEFT_QUOTE and right quote as RIGHT_QUOTE. See
- set_custom_quoting for a description of acceptable LEFT_QUOTE and
- RIGHT_QUOTE values. */
-char *quotearg_n_custom (int n, char const *left_quote,
- char const *right_quote, char const *arg);
-
-/* Like quotearg_n_custom (N, LEFT_QUOTE, RIGHT_QUOTE, ARG) except it
- can quote null bytes. */
-char *quotearg_n_custom_mem (int n, char const *left_quote,
- char const *right_quote,
- char const *arg, size_t argsize);
-
-/* Equivalent to quotearg_n_custom (0, LEFT_QUOTE, RIGHT_QUOTE, ARG). */
-char *quotearg_custom (char const *left_quote, char const *right_quote,
- char const *arg);
-
-/* Equivalent to quotearg_n_custom_mem (0, LEFT_QUOTE, RIGHT_QUOTE, ARG,
- ARGSIZE). */
-char *quotearg_custom_mem (char const *left_quote,
- char const *right_quote,
- char const *arg, size_t argsize);
-
-/* Free any dynamically allocated memory. */
-void quotearg_free (void);
-
-#endif /* !QUOTEARG_H_ */
+/* quotearg.h - quote arguments for output
+
+ Copyright (C) 1998-2002, 2004, 2006, 2008-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert <eggert@twinsun.com> */
+
+#ifndef QUOTEARG_H_
+# define QUOTEARG_H_ 1
+
+# include <stddef.h>
+
+/* Basic quoting styles. For each style, an example is given on the
+ input strings "simple", "\0 \t\n'\"\033?""?/\\", and "a:b", using
+ quotearg_buffer, quotearg_mem, and quotearg_colon_mem with that
+ style and the default flags and quoted characters. Note that the
+ examples are shown here as valid C strings rather than what
+ displays on a terminal (with "??/" as a trigraph for "\\"). */
+enum quoting_style
+ {
+ /* Output names as-is (ls --quoting-style=literal). Can result in
+ embedded null bytes if QA_ELIDE_NULL_BYTES is not in
+ effect.
+
+ quotearg_buffer:
+ "simple", "\0 \t\n'\"\033??/\\", "a:b"
+ quotearg:
+ "simple", " \t\n'\"\033??/\\", "a:b"
+ quotearg_colon:
+ "simple", " \t\n'\"\033??/\\", "a:b"
+ */
+ literal_quoting_style,
+
+ /* Quote names for the shell if they contain shell metacharacters
+ or would cause ambiguous output (ls --quoting-style=shell).
+ Can result in embedded null bytes if QA_ELIDE_NULL_BYTES is not
+ in effect.
+
+ quotearg_buffer:
+ "simple", "'\0 \t\n'\\''\"\033??/\\'", "a:b"
+ quotearg:
+ "simple", "' \t\n'\\''\"\033??/\\'", "a:b"
+ quotearg_colon:
+ "simple", "' \t\n'\\''\"\033??/\\'", "'a:b'"
+ */
+ shell_quoting_style,
+
+ /* Quote names for the shell, even if they would normally not
+ require quoting (ls --quoting-style=shell-always). Can result
+ in embedded null bytes if QA_ELIDE_NULL_BYTES is not in effect.
+ Behaves like shell_quoting_style if QA_ELIDE_OUTER_QUOTES is in
+ effect.
+
+ quotearg_buffer:
+ "'simple'", "'\0 \t\n'\\''\"\033??/\\'", "'a:b'"
+ quotearg:
+ "'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
+ quotearg_colon:
+ "'simple'", "' \t\n'\\''\"\033??/\\'", "'a:b'"
+ */
+ shell_always_quoting_style,
+
+ /* Quote names as for a C language string (ls --quoting-style=c).
+ Behaves like c_maybe_quoting_style if QA_ELIDE_OUTER_QUOTES is
+ in effect. Split into consecutive strings if
+ QA_SPLIT_TRIGRAPHS.
+
+ quotearg_buffer:
+ "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
+ quotearg:
+ "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
+ quotearg_colon:
+ "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
+ */
+ c_quoting_style,
+
+ /* Like c_quoting_style except omit the surrounding double-quote
+ characters if no quoted characters are encountered.
+
+ quotearg_buffer:
+ "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
+ quotearg:
+ "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "a:b"
+ quotearg_colon:
+ "simple", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
+ */
+ c_maybe_quoting_style,
+
+ /* Like c_quoting_style except always omit the surrounding
+ double-quote characters and ignore QA_SPLIT_TRIGRAPHS
+ (ls --quoting-style=escape).
+
+ quotearg_buffer:
+ "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
+ quotearg:
+ "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a:b"
+ quotearg_colon:
+ "simple", "\\0 \\t\\n'\"\\033??/\\\\", "a\\:b"
+ */
+ escape_quoting_style,
+
+ /* Like clocale_quoting_style, but use single quotes in the
+ default C locale or if the program does not use gettext
+ (ls --quoting-style=locale). For UTF-8 locales, quote
+ characters will use Unicode.
+
+ LC_MESSAGES=C
+ quotearg_buffer:
+ "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
+ quotearg:
+ "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a:b'"
+ quotearg_colon:
+ "`simple'", "`\\0 \\t\\n\\'\"\\033??/\\\\'", "`a\\:b'"
+
+ LC_MESSAGES=pt_PT.utf8
+ quotearg_buffer:
+ "\302\253simple\302\273",
+ "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
+ quotearg:
+ "\302\253simple\302\273",
+ "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
+ quotearg_colon:
+ "\302\253simple\302\273",
+ "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
+ */
+ locale_quoting_style,
+
+ /* Like c_quoting_style except use quotation marks appropriate for
+ the locale and ignore QA_SPLIT_TRIGRAPHS
+ (ls --quoting-style=clocale).
+
+ LC_MESSAGES=C
+ quotearg_buffer:
+ "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
+ quotearg:
+ "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a:b\""
+ quotearg_colon:
+ "\"simple\"", "\"\\0 \\t\\n'\\\"\\033??/\\\\\"", "\"a\\:b\""
+
+ LC_MESSAGES=pt_PT.utf8
+ quotearg_buffer:
+ "\302\253simple\302\273",
+ "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
+ quotearg:
+ "\302\253simple\302\273",
+ "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a:b\302\273"
+ quotearg_colon:
+ "\302\253simple\302\273",
+ "\302\253\\0 \\t\\n'\"\\033??/\\\\\302\253", "\302\253a\\:b\302\273"
+ */
+ clocale_quoting_style,
+
+ /* Like clocale_quoting_style except use the custom quotation marks
+ set by set_custom_quoting. If custom quotation marks are not
+ set, the behavior is undefined.
+
+ left_quote = right_quote = "'"
+ quotearg_buffer:
+ "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a:b'"
+ quotearg:
+ "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a:b'"
+ quotearg_colon:
+ "'simple'", "'\\0 \\t\\n\\'\"\\033??/\\\\'", "'a\\:b'"
+
+ left_quote = "(" and right_quote = ")"
+ quotearg_buffer:
+ "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a:b)"
+ quotearg:
+ "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a:b)"
+ quotearg_colon:
+ "(simple)", "(\\0 \\t\\n'\"\\033??/\\\\)", "(a\\:b)"
+
+ left_quote = ":" and right_quote = " "
+ quotearg_buffer:
+ ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a:b "
+ quotearg:
+ ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a:b "
+ quotearg_colon:
+ ":simple ", ":\\0\\ \\t\\n'\"\\033??/\\\\ ", ":a\\:b "
+
+ left_quote = "\"'" and right_quote = "'\""
+ Notice that this is treated as a single level of quotes or two
+ levels where the outer quote need not be escaped within the inner
+ quotes. For two levels where the outer quote must be escaped
+ within the inner quotes, you must use separate quotearg
+ invocations.
+ quotearg_buffer:
+ "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a:b'\""
+ quotearg:
+ "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a:b'\""
+ quotearg_colon:
+ "\"'simple'\"", "\"'\\0 \\t\\n\\'\"\\033??/\\\\'\"", "\"'a\\:b'\""
+ */
+ custom_quoting_style
+ };
+
+/* Flags for use in set_quoting_flags. */
+enum quoting_flags
+ {
+ /* Always elide null bytes from styles that do not quote them,
+ even when the length of the result is available to the
+ caller. */
+ QA_ELIDE_NULL_BYTES = 0x01,
+
+ /* Omit the surrounding quote characters if no escaped characters
+ are encountered. Note that if no other character needs
+ escaping, then neither does the escape character. */
+ QA_ELIDE_OUTER_QUOTES = 0x02,
+
+ /* In the c_quoting_style and c_maybe_quoting_style, split ANSI
+ trigraph sequences into concatenated strings (for example,
+ "?""?/" rather than "??/", which could be confused with
+ "\\"). */
+ QA_SPLIT_TRIGRAPHS = 0x04
+ };
+
+/* For now, --quoting-style=literal is the default, but this may change. */
+# ifndef DEFAULT_QUOTING_STYLE
+# define DEFAULT_QUOTING_STYLE literal_quoting_style
+# endif
+
+/* Names of quoting styles and their corresponding values. */
+extern char const *const quoting_style_args[];
+extern enum quoting_style const quoting_style_vals[];
+
+struct quoting_options;
+
+/* The functions listed below set and use a hidden variable
+ that contains the default quoting style options. */
+
+/* Allocate a new set of quoting options, with contents initially identical
+ to O if O is not null, or to the default if O is null.
+ It is the caller's responsibility to free the result. */
+struct quoting_options *clone_quoting_options (struct quoting_options *o);
+
+/* Get the value of O's quoting style. If O is null, use the default. */
+enum quoting_style get_quoting_style (struct quoting_options *o);
+
+/* In O (or in the default if O is null),
+ set the value of the quoting style to S. */
+void set_quoting_style (struct quoting_options *o, enum quoting_style s);
+
+/* In O (or in the default if O is null),
+ set the value of the quoting options for character C to I.
+ Return the old value. Currently, the only values defined for I are
+ 0 (the default) and 1 (which means to quote the character even if
+ it would not otherwise be quoted). C must never be a digit or a
+ letter that has special meaning after a backslash (for example, "\t"
+ for tab). */
+int set_char_quoting (struct quoting_options *o, char c, int i);
+
+/* In O (or in the default if O is null),
+ set the value of the quoting options flag to I, which can be a
+ bitwise combination of enum quoting_flags, or 0 for default
+ behavior. Return the old value. */
+int set_quoting_flags (struct quoting_options *o, int i);
+
+/* In O (or in the default if O is null),
+ set the value of the quoting style to custom_quoting_style,
+ set the left quote to LEFT_QUOTE, and set the right quote to
+ RIGHT_QUOTE. Each of LEFT_QUOTE and RIGHT_QUOTE must be
+ null-terminated and can be the empty string. Because backslashes are
+ used for escaping, it does not make sense for RIGHT_QUOTE to contain
+ a backslash. RIGHT_QUOTE must not begin with a digit or a letter
+ that has special meaning after a backslash (for example, "\t" for
+ tab). */
+void set_custom_quoting (struct quoting_options *o,
+ char const *left_quote,
+ char const *right_quote);
+
+/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
+ argument ARG (of size ARGSIZE), using O to control quoting.
+ If O is null, use the default.
+ Terminate the output with a null character, and return the written
+ size of the output, not counting the terminating null.
+ If BUFFERSIZE is too small to store the output string, return the
+ value that would have been returned had BUFFERSIZE been large enough.
+ If ARGSIZE is -1, use the string length of the argument for ARGSIZE.
+ On output, BUFFER might contain embedded null bytes if ARGSIZE was
+ not -1, the style of O does not use backslash escapes, and the
+ flags of O do not request elision of null bytes.*/
+size_t quotearg_buffer (char *buffer, size_t buffersize,
+ char const *arg, size_t argsize,
+ struct quoting_options const *o);
+
+/* Like quotearg_buffer, except return the result in a newly allocated
+ buffer. It is the caller's responsibility to free the result. The
+ result will not contain embedded null bytes. */
+char *quotearg_alloc (char const *arg, size_t argsize,
+ struct quoting_options const *o);
+
+/* Like quotearg_alloc, except that the length of the result,
+ excluding the terminating null byte, is stored into SIZE if it is
+ non-NULL. The result might contain embedded null bytes if ARGSIZE
+ was not -1, SIZE was not NULL, the style of O does not use
+ backslash escapes, and the flags of O do not request elision of
+ null bytes.*/
+char *quotearg_alloc_mem (char const *arg, size_t argsize,
+ size_t *size, struct quoting_options const *o);
+
+/* Use storage slot N to return a quoted version of the string ARG.
+ Use the default quoting options.
+ The returned value points to static storage that can be
+ reused by the next call to this function with the same value of N.
+ N must be nonnegative. The output of all functions in the
+ quotearg_n family are guaranteed to not contain embedded null
+ bytes.*/
+char *quotearg_n (int n, char const *arg);
+
+/* Equivalent to quotearg_n (0, ARG). */
+char *quotearg (char const *arg);
+
+/* Use storage slot N to return a quoted version of the argument ARG
+ of size ARGSIZE. This is like quotearg_n (N, ARG), except it can
+ quote null bytes. */
+char *quotearg_n_mem (int n, char const *arg, size_t argsize);
+
+/* Equivalent to quotearg_n_mem (0, ARG, ARGSIZE). */
+char *quotearg_mem (char const *arg, size_t argsize);
+
+/* Use style S and storage slot N to return a quoted version of the string ARG.
+ This is like quotearg_n (N, ARG), except that it uses S with no other
+ options to specify the quoting method. */
+char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
+
+/* Use style S and storage slot N to return a quoted version of the
+ argument ARG of size ARGSIZE. This is like quotearg_n_style
+ (N, S, ARG), except it can quote null bytes. */
+char *quotearg_n_style_mem (int n, enum quoting_style s,
+ char const *arg, size_t argsize);
+
+/* Equivalent to quotearg_n_style (0, S, ARG). */
+char *quotearg_style (enum quoting_style s, char const *arg);
+
+/* Equivalent to quotearg_n_style_mem (0, S, ARG, ARGSIZE). */
+char *quotearg_style_mem (enum quoting_style s,
+ char const *arg, size_t argsize);
+
+/* Like quotearg (ARG), except also quote any instances of CH.
+ See set_char_quoting for a description of acceptable CH values. */
+char *quotearg_char (char const *arg, char ch);
+
+/* Like quotearg_char (ARG, CH), except it can quote null bytes. */
+char *quotearg_char_mem (char const *arg, size_t argsize, char ch);
+
+/* Equivalent to quotearg_char (ARG, ':'). */
+char *quotearg_colon (char const *arg);
+
+/* Like quotearg_colon (ARG), except it can quote null bytes. */
+char *quotearg_colon_mem (char const *arg, size_t argsize);
+
+/* Like quotearg_n_style (N, S, ARG) but with S as custom_quoting_style
+ with left quote as LEFT_QUOTE and right quote as RIGHT_QUOTE. See
+ set_custom_quoting for a description of acceptable LEFT_QUOTE and
+ RIGHT_QUOTE values. */
+char *quotearg_n_custom (int n, char const *left_quote,
+ char const *right_quote, char const *arg);
+
+/* Like quotearg_n_custom (N, LEFT_QUOTE, RIGHT_QUOTE, ARG) except it
+ can quote null bytes. */
+char *quotearg_n_custom_mem (int n, char const *left_quote,
+ char const *right_quote,
+ char const *arg, size_t argsize);
+
+/* Equivalent to quotearg_n_custom (0, LEFT_QUOTE, RIGHT_QUOTE, ARG). */
+char *quotearg_custom (char const *left_quote, char const *right_quote,
+ char const *arg);
+
+/* Equivalent to quotearg_n_custom_mem (0, LEFT_QUOTE, RIGHT_QUOTE, ARG,
+ ARGSIZE). */
+char *quotearg_custom_mem (char const *left_quote,
+ char const *right_quote,
+ char const *arg, size_t argsize);
+
+/* Free any dynamically allocated memory. */
+void quotearg_free (void);
+
+#endif /* !QUOTEARG_H_ */
diff --git a/contrib/tools/bison/gnulib/src/raise.c b/contrib/tools/bison/gnulib/src/raise.c
index 5b546d2b8d..79fb17d995 100644
--- a/contrib/tools/bison/gnulib/src/raise.c
+++ b/contrib/tools/bison/gnulib/src/raise.c
@@ -1,79 +1,79 @@
-/* Provide a non-threads replacement for the POSIX raise function.
-
- Copyright (C) 2002-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Jim Meyering and Bruno Haible */
-
-#include <config.h>
-
-/* Specification. */
-#include <signal.h>
-
-#if HAVE_RAISE
-/* Native Windows platform. */
-
-# include <errno.h>
-
-# include "msvc-inval.h"
-
-# undef raise
-
-# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-raise_nothrow (int sig)
-{
- int result;
-
- TRY_MSVC_INVAL
- {
- result = raise (sig);
- }
- CATCH_MSVC_INVAL
- {
- result = -1;
- errno = EINVAL;
- }
- DONE_MSVC_INVAL;
-
- return result;
-}
-# else
-# define raise_nothrow raise
-# endif
-
-#else
-/* An old Unix platform. */
-
-# include <unistd.h>
-
-# define rpl_raise raise
-
-#endif
-
-int
-rpl_raise (int sig)
-{
-#if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE
- if (sig == SIGPIPE)
- return _gl_raise_SIGPIPE ();
-#endif
-
-#if HAVE_RAISE
- return raise_nothrow (sig);
-#else
- return kill (getpid (), sig);
-#endif
-}
+/* Provide a non-threads replacement for the POSIX raise function.
+
+ Copyright (C) 2002-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Jim Meyering and Bruno Haible */
+
+#include <config.h>
+
+/* Specification. */
+#include <signal.h>
+
+#if HAVE_RAISE
+/* Native Windows platform. */
+
+# include <errno.h>
+
+# include "msvc-inval.h"
+
+# undef raise
+
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+raise_nothrow (int sig)
+{
+ int result;
+
+ TRY_MSVC_INVAL
+ {
+ result = raise (sig);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = -1;
+ errno = EINVAL;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+# else
+# define raise_nothrow raise
+# endif
+
+#else
+/* An old Unix platform. */
+
+# include <unistd.h>
+
+# define rpl_raise raise
+
+#endif
+
+int
+rpl_raise (int sig)
+{
+#if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE
+ if (sig == SIGPIPE)
+ return _gl_raise_SIGPIPE ();
+#endif
+
+#if HAVE_RAISE
+ return raise_nothrow (sig);
+#else
+ return kill (getpid (), sig);
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/rawmemchr.c b/contrib/tools/bison/gnulib/src/rawmemchr.c
index a0298ce64e..b0f4f4d044 100644
--- a/contrib/tools/bison/gnulib/src/rawmemchr.c
+++ b/contrib/tools/bison/gnulib/src/rawmemchr.c
@@ -1,136 +1,136 @@
-/* Searching in a string.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <string.h>
-
-/* Find the first occurrence of C in S. */
-void *
-rawmemchr (const void *s, int c_in)
-{
- /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
- long instead of a 64-bit uintmax_t tends to give better
- performance. On 64-bit hardware, unsigned long is generally 64
- bits already. Change this typedef to experiment with
- performance. */
- typedef unsigned long int longword;
-
- const unsigned char *char_ptr;
- const longword *longword_ptr;
- longword repeated_one;
- longword repeated_c;
- unsigned char c;
-
- c = (unsigned char) c_in;
-
- /* Handle the first few bytes by reading one byte at a time.
- Do this until CHAR_PTR is aligned on a longword boundary. */
- for (char_ptr = (const unsigned char *) s;
- (size_t) char_ptr % sizeof (longword) != 0;
- ++char_ptr)
- if (*char_ptr == c)
- return (void *) char_ptr;
-
- longword_ptr = (const longword *) char_ptr;
-
- /* All these elucidatory comments refer to 4-byte longwords,
- but the theory applies equally well to any size longwords. */
-
- /* Compute auxiliary longword values:
- repeated_one is a value which has a 1 in every byte.
- repeated_c has c in every byte. */
- repeated_one = 0x01010101;
- repeated_c = c | (c << 8);
- repeated_c |= repeated_c << 16;
- if (0xffffffffU < (longword) -1)
- {
- repeated_one |= repeated_one << 31 << 1;
- repeated_c |= repeated_c << 31 << 1;
- if (8 < sizeof (longword))
- {
- size_t i;
-
- for (i = 64; i < sizeof (longword) * 8; i *= 2)
- {
- repeated_one |= repeated_one << i;
- repeated_c |= repeated_c << i;
- }
- }
- }
-
- /* Instead of the traditional loop which tests each byte, we will
- test a longword at a time. The tricky part is testing if *any of
- the four* bytes in the longword in question are equal to NUL or
- c. We first use an xor with repeated_c. This reduces the task
- to testing whether *any of the four* bytes in longword1 is zero.
-
- We compute tmp =
- ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
- That is, we perform the following operations:
- 1. Subtract repeated_one.
- 2. & ~longword1.
- 3. & a mask consisting of 0x80 in every byte.
- Consider what happens in each byte:
- - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
- and step 3 transforms it into 0x80. A carry can also be propagated
- to more significant bytes.
- - If a byte of longword1 is nonzero, let its lowest 1 bit be at
- position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
- the byte ends in a single bit of value 0 and k bits of value 1.
- After step 2, the result is just k bits of value 1: 2^k - 1. After
- step 3, the result is 0. And no carry is produced.
- So, if longword1 has only non-zero bytes, tmp is zero.
- Whereas if longword1 has a zero byte, call j the position of the least
- significant zero byte. Then the result has a zero at positions 0, ...,
- j-1 and a 0x80 at position j. We cannot predict the result at the more
- significant bytes (positions j+1..3), but it does not matter since we
- already have a non-zero bit at position 8*j+7.
-
- The test whether any byte in longword1 is zero is equivalent
- to testing whether tmp is nonzero.
-
- This test can read beyond the end of a string, depending on where
- C_IN is encountered. However, this is considered safe since the
- initialization phase ensured that the read will be aligned,
- therefore, the read will not cross page boundaries and will not
- cause a fault. */
-
- while (1)
- {
- longword longword1 = *longword_ptr ^ repeated_c;
-
- if ((((longword1 - repeated_one) & ~longword1)
- & (repeated_one << 7)) != 0)
- break;
- longword_ptr++;
- }
-
- char_ptr = (const unsigned char *) longword_ptr;
-
- /* At this point, we know that one of the sizeof (longword) bytes
- starting at char_ptr is == c. On little-endian machines, we
- could determine the first such byte without any further memory
- accesses, just by looking at the tmp result from the last loop
- iteration. But this does not work on big-endian machines.
- Choose code that works in both cases. */
-
- char_ptr = (unsigned char *) longword_ptr;
- while (*char_ptr != c)
- char_ptr++;
- return (void *) char_ptr;
-}
+/* Searching in a string.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <string.h>
+
+/* Find the first occurrence of C in S. */
+void *
+rawmemchr (const void *s, int c_in)
+{
+ /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
+ long instead of a 64-bit uintmax_t tends to give better
+ performance. On 64-bit hardware, unsigned long is generally 64
+ bits already. Change this typedef to experiment with
+ performance. */
+ typedef unsigned long int longword;
+
+ const unsigned char *char_ptr;
+ const longword *longword_ptr;
+ longword repeated_one;
+ longword repeated_c;
+ unsigned char c;
+
+ c = (unsigned char) c_in;
+
+ /* Handle the first few bytes by reading one byte at a time.
+ Do this until CHAR_PTR is aligned on a longword boundary. */
+ for (char_ptr = (const unsigned char *) s;
+ (size_t) char_ptr % sizeof (longword) != 0;
+ ++char_ptr)
+ if (*char_ptr == c)
+ return (void *) char_ptr;
+
+ longword_ptr = (const longword *) char_ptr;
+
+ /* All these elucidatory comments refer to 4-byte longwords,
+ but the theory applies equally well to any size longwords. */
+
+ /* Compute auxiliary longword values:
+ repeated_one is a value which has a 1 in every byte.
+ repeated_c has c in every byte. */
+ repeated_one = 0x01010101;
+ repeated_c = c | (c << 8);
+ repeated_c |= repeated_c << 16;
+ if (0xffffffffU < (longword) -1)
+ {
+ repeated_one |= repeated_one << 31 << 1;
+ repeated_c |= repeated_c << 31 << 1;
+ if (8 < sizeof (longword))
+ {
+ size_t i;
+
+ for (i = 64; i < sizeof (longword) * 8; i *= 2)
+ {
+ repeated_one |= repeated_one << i;
+ repeated_c |= repeated_c << i;
+ }
+ }
+ }
+
+ /* Instead of the traditional loop which tests each byte, we will
+ test a longword at a time. The tricky part is testing if *any of
+ the four* bytes in the longword in question are equal to NUL or
+ c. We first use an xor with repeated_c. This reduces the task
+ to testing whether *any of the four* bytes in longword1 is zero.
+
+ We compute tmp =
+ ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+ That is, we perform the following operations:
+ 1. Subtract repeated_one.
+ 2. & ~longword1.
+ 3. & a mask consisting of 0x80 in every byte.
+ Consider what happens in each byte:
+ - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+ and step 3 transforms it into 0x80. A carry can also be propagated
+ to more significant bytes.
+ - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+ position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
+ the byte ends in a single bit of value 0 and k bits of value 1.
+ After step 2, the result is just k bits of value 1: 2^k - 1. After
+ step 3, the result is 0. And no carry is produced.
+ So, if longword1 has only non-zero bytes, tmp is zero.
+ Whereas if longword1 has a zero byte, call j the position of the least
+ significant zero byte. Then the result has a zero at positions 0, ...,
+ j-1 and a 0x80 at position j. We cannot predict the result at the more
+ significant bytes (positions j+1..3), but it does not matter since we
+ already have a non-zero bit at position 8*j+7.
+
+ The test whether any byte in longword1 is zero is equivalent
+ to testing whether tmp is nonzero.
+
+ This test can read beyond the end of a string, depending on where
+ C_IN is encountered. However, this is considered safe since the
+ initialization phase ensured that the read will be aligned,
+ therefore, the read will not cross page boundaries and will not
+ cause a fault. */
+
+ while (1)
+ {
+ longword longword1 = *longword_ptr ^ repeated_c;
+
+ if ((((longword1 - repeated_one) & ~longword1)
+ & (repeated_one << 7)) != 0)
+ break;
+ longword_ptr++;
+ }
+
+ char_ptr = (const unsigned char *) longword_ptr;
+
+ /* At this point, we know that one of the sizeof (longword) bytes
+ starting at char_ptr is == c. On little-endian machines, we
+ could determine the first such byte without any further memory
+ accesses, just by looking at the tmp result from the last loop
+ iteration. But this does not work on big-endian machines.
+ Choose code that works in both cases. */
+
+ char_ptr = (unsigned char *) longword_ptr;
+ while (*char_ptr != c)
+ char_ptr++;
+ return (void *) char_ptr;
+}
diff --git a/contrib/tools/bison/gnulib/src/readlink.c b/contrib/tools/bison/gnulib/src/readlink.c
index f83a1e0123..ae9203361b 100644
--- a/contrib/tools/bison/gnulib/src/readlink.c
+++ b/contrib/tools/bison/gnulib/src/readlink.c
@@ -1,74 +1,74 @@
-/* Stub for readlink().
- Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <unistd.h>
-
-#include <errno.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#if !HAVE_READLINK
-
-/* readlink() substitute for systems that don't have a readlink() function,
- such as DJGPP 2.03 and mingw32. */
-
-ssize_t
-readlink (const char *name, char *buf _GL_UNUSED,
- size_t bufsize _GL_UNUSED)
-{
- struct stat statbuf;
-
- /* In general we should use lstat() here, not stat(). But on platforms
- without symbolic links, lstat() - if it exists - would be equivalent to
- stat(), therefore we can use stat(). This saves us a configure check. */
- if (stat (name, &statbuf) >= 0)
- errno = EINVAL;
- return -1;
-}
-
-#else /* HAVE_READLINK */
-
-# undef readlink
-
-/* readlink() wrapper that uses correct types, for systems like cygwin
- 1.5.x where readlink returns int, and which rejects trailing slash,
- for Solaris 9. */
-
-ssize_t
-rpl_readlink (const char *name, char *buf, size_t bufsize)
-{
-# if READLINK_TRAILING_SLASH_BUG
- size_t len = strlen (name);
- if (len && name[len - 1] == '/')
- {
- /* Even if name without the slash is a symlink to a directory,
- both lstat() and stat() must resolve the trailing slash to
- the directory rather than the symlink. We can therefore
- safely use stat() to distinguish between EINVAL and
- ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */
- struct stat st;
- if (stat (name, &st) == 0)
- errno = EINVAL;
- return -1;
- }
-# endif /* READLINK_TRAILING_SLASH_BUG */
- return readlink (name, buf, bufsize);
-}
-
-#endif /* HAVE_READLINK */
+/* Stub for readlink().
+ Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <unistd.h>
+
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#if !HAVE_READLINK
+
+/* readlink() substitute for systems that don't have a readlink() function,
+ such as DJGPP 2.03 and mingw32. */
+
+ssize_t
+readlink (const char *name, char *buf _GL_UNUSED,
+ size_t bufsize _GL_UNUSED)
+{
+ struct stat statbuf;
+
+ /* In general we should use lstat() here, not stat(). But on platforms
+ without symbolic links, lstat() - if it exists - would be equivalent to
+ stat(), therefore we can use stat(). This saves us a configure check. */
+ if (stat (name, &statbuf) >= 0)
+ errno = EINVAL;
+ return -1;
+}
+
+#else /* HAVE_READLINK */
+
+# undef readlink
+
+/* readlink() wrapper that uses correct types, for systems like cygwin
+ 1.5.x where readlink returns int, and which rejects trailing slash,
+ for Solaris 9. */
+
+ssize_t
+rpl_readlink (const char *name, char *buf, size_t bufsize)
+{
+# if READLINK_TRAILING_SLASH_BUG
+ size_t len = strlen (name);
+ if (len && name[len - 1] == '/')
+ {
+ /* Even if name without the slash is a symlink to a directory,
+ both lstat() and stat() must resolve the trailing slash to
+ the directory rather than the symlink. We can therefore
+ safely use stat() to distinguish between EINVAL and
+ ENOTDIR/ENOENT, avoiding extra overhead of rpl_lstat(). */
+ struct stat st;
+ if (stat (name, &st) == 0)
+ errno = EINVAL;
+ return -1;
+ }
+# endif /* READLINK_TRAILING_SLASH_BUG */
+ return readlink (name, buf, bufsize);
+}
+
+#endif /* HAVE_READLINK */
diff --git a/contrib/tools/bison/gnulib/src/realloc.c b/contrib/tools/bison/gnulib/src/realloc.c
index b51010a621..83be163408 100644
--- a/contrib/tools/bison/gnulib/src/realloc.c
+++ b/contrib/tools/bison/gnulib/src/realloc.c
@@ -1,79 +1,79 @@
-/* realloc() function that is glibc compatible.
-
- Copyright (C) 1997, 2003-2004, 2006-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Jim Meyering and Bruno Haible */
-
-#define _GL_USE_STDLIB_ALLOC 1
-#include <config.h>
-
-/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h. */
-#ifdef realloc
-# define NEED_REALLOC_GNU 1
-/* Whereas the gnulib module 'realloc-gnu' defines HAVE_REALLOC_GNU. */
-#elif GNULIB_REALLOC_GNU && !HAVE_REALLOC_GNU
-# define NEED_REALLOC_GNU 1
-#endif
-
-/* Infer the properties of the system's malloc function.
- The gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */
-#if GNULIB_MALLOC_GNU && HAVE_MALLOC_GNU
-# define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
-#endif
-
-#include <stdlib.h>
-
-#include <errno.h>
-
-/* Change the size of an allocated block of memory P to N bytes,
- with error checking. If N is zero, change it to 1. If P is NULL,
- use malloc. */
-
-void *
-rpl_realloc (void *p, size_t n)
-{
- void *result;
-
-#if NEED_REALLOC_GNU
- if (n == 0)
- {
- n = 1;
-
- /* In theory realloc might fail, so don't rely on it to free. */
- free (p);
- p = NULL;
- }
-#endif
-
- if (p == NULL)
- {
-#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE
- if (n == 0)
- n = 1;
-#endif
- result = malloc (n);
- }
- else
- result = realloc (p, n);
-
-#if !HAVE_REALLOC_POSIX
- if (result == NULL)
- errno = ENOMEM;
-#endif
-
- return result;
-}
+/* realloc() function that is glibc compatible.
+
+ Copyright (C) 1997, 2003-2004, 2006-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Jim Meyering and Bruno Haible */
+
+#define _GL_USE_STDLIB_ALLOC 1
+#include <config.h>
+
+/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h. */
+#ifdef realloc
+# define NEED_REALLOC_GNU 1
+/* Whereas the gnulib module 'realloc-gnu' defines HAVE_REALLOC_GNU. */
+#elif GNULIB_REALLOC_GNU && !HAVE_REALLOC_GNU
+# define NEED_REALLOC_GNU 1
+#endif
+
+/* Infer the properties of the system's malloc function.
+ The gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */
+#if GNULIB_MALLOC_GNU && HAVE_MALLOC_GNU
+# define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
+#endif
+
+#include <stdlib.h>
+
+#include <errno.h>
+
+/* Change the size of an allocated block of memory P to N bytes,
+ with error checking. If N is zero, change it to 1. If P is NULL,
+ use malloc. */
+
+void *
+rpl_realloc (void *p, size_t n)
+{
+ void *result;
+
+#if NEED_REALLOC_GNU
+ if (n == 0)
+ {
+ n = 1;
+
+ /* In theory realloc might fail, so don't rely on it to free. */
+ free (p);
+ p = NULL;
+ }
+#endif
+
+ if (p == NULL)
+ {
+#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE
+ if (n == 0)
+ n = 1;
+#endif
+ result = malloc (n);
+ }
+ else
+ result = realloc (p, n);
+
+#if !HAVE_REALLOC_POSIX
+ if (result == NULL)
+ errno = ENOMEM;
+#endif
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/regcomp.c b/contrib/tools/bison/gnulib/src/regcomp.c
index f0b2e52216..12ea666015 100644
--- a/contrib/tools/bison/gnulib/src/regcomp.c
+++ b/contrib/tools/bison/gnulib/src/regcomp.c
@@ -1,3922 +1,3922 @@
-/* Extended regular expression matching and search library.
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
- size_t length, reg_syntax_t syntax);
-static void re_compile_fastmap_iter (regex_t *bufp,
- const re_dfastate_t *init_state,
- char *fastmap);
-static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len);
-#ifdef RE_ENABLE_I18N
-static void free_charset (re_charset_t *cset);
-#endif /* RE_ENABLE_I18N */
-static void free_workarea_compile (regex_t *preg);
-static reg_errcode_t create_initial_state (re_dfa_t *dfa);
-#ifdef RE_ENABLE_I18N
-static void optimize_utf8 (re_dfa_t *dfa);
-#endif
-static reg_errcode_t analyze (regex_t *preg);
-static reg_errcode_t preorder (bin_tree_t *root,
- reg_errcode_t (fn (void *, bin_tree_t *)),
- void *extra);
-static reg_errcode_t postorder (bin_tree_t *root,
- reg_errcode_t (fn (void *, bin_tree_t *)),
- void *extra);
-static reg_errcode_t optimize_subexps (void *extra, bin_tree_t *node);
-static reg_errcode_t lower_subexps (void *extra, bin_tree_t *node);
-static bin_tree_t *lower_subexp (reg_errcode_t *err, regex_t *preg,
- bin_tree_t *node);
-static reg_errcode_t calc_first (void *extra, bin_tree_t *node);
-static reg_errcode_t calc_next (void *extra, bin_tree_t *node);
-static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node);
-static Idx duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint);
-static Idx search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
- unsigned int constraint);
-static reg_errcode_t calc_eclosure (re_dfa_t *dfa);
-static reg_errcode_t calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa,
- Idx node, bool root);
-static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
-static Idx fetch_number (re_string_t *input, re_token_t *token,
- reg_syntax_t syntax);
-static int peek_token (re_token_t *token, re_string_t *input,
- reg_syntax_t syntax) internal_function;
-static bin_tree_t *parse (re_string_t *regexp, regex_t *preg,
- reg_syntax_t syntax, reg_errcode_t *err);
-static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
- re_token_t *token, reg_syntax_t syntax,
- Idx nest, reg_errcode_t *err);
-static bin_tree_t *parse_branch (re_string_t *regexp, regex_t *preg,
- re_token_t *token, reg_syntax_t syntax,
- Idx nest, reg_errcode_t *err);
-static bin_tree_t *parse_expression (re_string_t *regexp, regex_t *preg,
- re_token_t *token, reg_syntax_t syntax,
- Idx nest, reg_errcode_t *err);
-static bin_tree_t *parse_sub_exp (re_string_t *regexp, regex_t *preg,
- re_token_t *token, reg_syntax_t syntax,
- Idx nest, reg_errcode_t *err);
-static bin_tree_t *parse_dup_op (bin_tree_t *dup_elem, re_string_t *regexp,
- re_dfa_t *dfa, re_token_t *token,
- reg_syntax_t syntax, reg_errcode_t *err);
-static bin_tree_t *parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa,
- re_token_t *token, reg_syntax_t syntax,
- reg_errcode_t *err);
-static reg_errcode_t parse_bracket_element (bracket_elem_t *elem,
- re_string_t *regexp,
- re_token_t *token, int token_len,
- re_dfa_t *dfa,
- reg_syntax_t syntax,
- bool accept_hyphen);
-static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
- re_string_t *regexp,
- re_token_t *token);
-#ifdef RE_ENABLE_I18N
-static reg_errcode_t build_equiv_class (bitset_t sbcset,
- re_charset_t *mbcset,
- Idx *equiv_class_alloc,
- const unsigned char *name);
-static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
- bitset_t sbcset,
- re_charset_t *mbcset,
- Idx *char_class_alloc,
- const char *class_name,
- reg_syntax_t syntax);
-#else /* not RE_ENABLE_I18N */
-static reg_errcode_t build_equiv_class (bitset_t sbcset,
- const unsigned char *name);
-static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
- bitset_t sbcset,
- const char *class_name,
- reg_syntax_t syntax);
-#endif /* not RE_ENABLE_I18N */
-static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
- RE_TRANSLATE_TYPE trans,
- const char *class_name,
- const char *extra,
- bool non_match, reg_errcode_t *err);
-static bin_tree_t *create_tree (re_dfa_t *dfa,
- bin_tree_t *left, bin_tree_t *right,
- re_token_type_t type);
-static bin_tree_t *create_token_tree (re_dfa_t *dfa,
- bin_tree_t *left, bin_tree_t *right,
- const re_token_t *token);
-static bin_tree_t *duplicate_tree (const bin_tree_t *src, re_dfa_t *dfa);
-static void free_token (re_token_t *node);
-static reg_errcode_t free_tree (void *extra, bin_tree_t *node);
-static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node);
-
-/* This table gives an error message for each of the error codes listed
- in regex.h. Obviously the order here has to be same as there.
- POSIX doesn't require that we do anything for REG_NOERROR,
- but why not be nice? */
-
-static const char __re_error_msgid[] =
- {
-#define REG_NOERROR_IDX 0
- gettext_noop ("Success") /* REG_NOERROR */
- "\0"
-#define REG_NOMATCH_IDX (REG_NOERROR_IDX + sizeof "Success")
- gettext_noop ("No match") /* REG_NOMATCH */
- "\0"
-#define REG_BADPAT_IDX (REG_NOMATCH_IDX + sizeof "No match")
- gettext_noop ("Invalid regular expression") /* REG_BADPAT */
- "\0"
-#define REG_ECOLLATE_IDX (REG_BADPAT_IDX + sizeof "Invalid regular expression")
- gettext_noop ("Invalid collation character") /* REG_ECOLLATE */
- "\0"
-#define REG_ECTYPE_IDX (REG_ECOLLATE_IDX + sizeof "Invalid collation character")
- gettext_noop ("Invalid character class name") /* REG_ECTYPE */
- "\0"
-#define REG_EESCAPE_IDX (REG_ECTYPE_IDX + sizeof "Invalid character class name")
- gettext_noop ("Trailing backslash") /* REG_EESCAPE */
- "\0"
-#define REG_ESUBREG_IDX (REG_EESCAPE_IDX + sizeof "Trailing backslash")
- gettext_noop ("Invalid back reference") /* REG_ESUBREG */
- "\0"
-#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference")
- gettext_noop ("Unmatched [ or [^") /* REG_EBRACK */
- "\0"
-#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^")
- gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */
- "\0"
-#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")
- gettext_noop ("Unmatched \\{") /* REG_EBRACE */
- "\0"
-#define REG_BADBR_IDX (REG_EBRACE_IDX + sizeof "Unmatched \\{")
- gettext_noop ("Invalid content of \\{\\}") /* REG_BADBR */
- "\0"
-#define REG_ERANGE_IDX (REG_BADBR_IDX + sizeof "Invalid content of \\{\\}")
- gettext_noop ("Invalid range end") /* REG_ERANGE */
- "\0"
-#define REG_ESPACE_IDX (REG_ERANGE_IDX + sizeof "Invalid range end")
- gettext_noop ("Memory exhausted") /* REG_ESPACE */
- "\0"
-#define REG_BADRPT_IDX (REG_ESPACE_IDX + sizeof "Memory exhausted")
- gettext_noop ("Invalid preceding regular expression") /* REG_BADRPT */
- "\0"
-#define REG_EEND_IDX (REG_BADRPT_IDX + sizeof "Invalid preceding regular expression")
- gettext_noop ("Premature end of regular expression") /* REG_EEND */
- "\0"
-#define REG_ESIZE_IDX (REG_EEND_IDX + sizeof "Premature end of regular expression")
- gettext_noop ("Regular expression too big") /* REG_ESIZE */
- "\0"
-#define REG_ERPAREN_IDX (REG_ESIZE_IDX + sizeof "Regular expression too big")
- gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */
- };
-
-static const size_t __re_error_msgid_idx[] =
- {
- REG_NOERROR_IDX,
- REG_NOMATCH_IDX,
- REG_BADPAT_IDX,
- REG_ECOLLATE_IDX,
- REG_ECTYPE_IDX,
- REG_EESCAPE_IDX,
- REG_ESUBREG_IDX,
- REG_EBRACK_IDX,
- REG_EPAREN_IDX,
- REG_EBRACE_IDX,
- REG_BADBR_IDX,
- REG_ERANGE_IDX,
- REG_ESPACE_IDX,
- REG_BADRPT_IDX,
- REG_EEND_IDX,
- REG_ESIZE_IDX,
- REG_ERPAREN_IDX
- };
-
-/* Entry points for GNU code. */
-
-/* re_compile_pattern is the GNU regular expression compiler: it
- compiles PATTERN (of length LENGTH) and puts the result in BUFP.
- Returns 0 if the pattern was valid, otherwise an error string.
-
- Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields
- are set in BUFP on entry. */
-
-#ifdef _LIBC
-const char *
-re_compile_pattern (pattern, length, bufp)
- const char *pattern;
- size_t length;
- struct re_pattern_buffer *bufp;
-#else /* size_t might promote */
-const char *
-re_compile_pattern (const char *pattern, size_t length,
- struct re_pattern_buffer *bufp)
-#endif
-{
- reg_errcode_t ret;
-
- /* And GNU code determines whether or not to get register information
- by passing null for the REGS argument to re_match, etc., not by
- setting no_sub, unless RE_NO_SUB is set. */
- bufp->no_sub = !!(re_syntax_options & RE_NO_SUB);
-
- /* Match anchors at newline. */
- bufp->newline_anchor = 1;
-
- ret = re_compile_internal (bufp, pattern, length, re_syntax_options);
-
- if (!ret)
- return NULL;
- return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
-}
-#ifdef _LIBC
-weak_alias (__re_compile_pattern, re_compile_pattern)
-#endif
-
-/* Set by 're_set_syntax' to the current regexp syntax to recognize. Can
- also be assigned to arbitrarily: each pattern buffer stores its own
- syntax, so it can be changed between regex compilations. */
-/* This has no initializer because initialized variables in Emacs
- become read-only after dumping. */
-reg_syntax_t re_syntax_options;
-
-
-/* Specify the precise syntax of regexps for compilation. This provides
- for compatibility for various utilities which historically have
- different, incompatible syntaxes.
-
- The argument SYNTAX is a bit mask comprised of the various bits
- defined in regex.h. We return the old syntax. */
-
-reg_syntax_t
-re_set_syntax (syntax)
- reg_syntax_t syntax;
-{
- reg_syntax_t ret = re_syntax_options;
-
- re_syntax_options = syntax;
- return ret;
-}
-#ifdef _LIBC
-weak_alias (__re_set_syntax, re_set_syntax)
-#endif
-
-int
-re_compile_fastmap (bufp)
- struct re_pattern_buffer *bufp;
-{
- re_dfa_t *dfa = bufp->buffer;
- char *fastmap = bufp->fastmap;
-
- memset (fastmap, '\0', sizeof (char) * SBC_MAX);
- re_compile_fastmap_iter (bufp, dfa->init_state, fastmap);
- if (dfa->init_state != dfa->init_state_word)
- re_compile_fastmap_iter (bufp, dfa->init_state_word, fastmap);
- if (dfa->init_state != dfa->init_state_nl)
- re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap);
- if (dfa->init_state != dfa->init_state_begbuf)
- re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap);
- bufp->fastmap_accurate = 1;
- return 0;
-}
-#ifdef _LIBC
-weak_alias (__re_compile_fastmap, re_compile_fastmap)
-#endif
-
-static inline void
-__attribute__ ((always_inline))
-re_set_fastmap (char *fastmap, bool icase, int ch)
-{
- fastmap[ch] = 1;
- if (icase)
- fastmap[tolower (ch)] = 1;
-}
-
-/* Helper function for re_compile_fastmap.
- Compile fastmap for the initial_state INIT_STATE. */
-
-static void
-re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
- char *fastmap)
-{
- re_dfa_t *dfa = bufp->buffer;
- Idx node_cnt;
- bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
- for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
- {
- Idx node = init_state->nodes.elems[node_cnt];
- re_token_type_t type = dfa->nodes[node].type;
-
- if (type == CHARACTER)
- {
- re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
-#ifdef RE_ENABLE_I18N
- if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
- {
- unsigned char buf[MB_LEN_MAX];
- unsigned char *p;
- wchar_t wc;
- mbstate_t state;
-
- p = buf;
- *p++ = dfa->nodes[node].opr.c;
- while (++node < dfa->nodes_len
- && dfa->nodes[node].type == CHARACTER
- && dfa->nodes[node].mb_partial)
- *p++ = dfa->nodes[node].opr.c;
- memset (&state, '\0', sizeof (state));
- if (__mbrtowc (&wc, (const char *) buf, p - buf,
- &state) == p - buf
- && (__wcrtomb ((char *) buf, towlower (wc), &state)
- != (size_t) -1))
- re_set_fastmap (fastmap, false, buf[0]);
- }
-#endif
- }
- else if (type == SIMPLE_BRACKET)
- {
- int i, ch;
- for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
- {
- int j;
- bitset_word_t w = dfa->nodes[node].opr.sbcset[i];
- for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
- if (w & ((bitset_word_t) 1 << j))
- re_set_fastmap (fastmap, icase, ch);
- }
- }
-#ifdef RE_ENABLE_I18N
- else if (type == COMPLEX_BRACKET)
- {
- re_charset_t *cset = dfa->nodes[node].opr.mbcset;
- Idx i;
-
-# ifdef _LIBC
- /* See if we have to try all bytes which start multiple collation
- elements.
- e.g. In da_DK, we want to catch 'a' since "aa" is a valid
- collation element, and don't catch 'b' since 'b' is
- the only collation element which starts from 'b' (and
- it is caught by SIMPLE_BRACKET). */
- if (_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES) != 0
- && (cset->ncoll_syms || cset->nranges))
- {
- const int32_t *table = (const int32_t *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
- for (i = 0; i < SBC_MAX; ++i)
- if (table[i] < 0)
- re_set_fastmap (fastmap, icase, i);
- }
-# endif /* _LIBC */
-
- /* See if we have to start the match at all multibyte characters,
- i.e. where we would not find an invalid sequence. This only
- applies to multibyte character sets; for single byte character
- sets, the SIMPLE_BRACKET again suffices. */
- if (dfa->mb_cur_max > 1
- && (cset->nchar_classes || cset->non_match || cset->nranges
-# ifdef _LIBC
- || cset->nequiv_classes
-# endif /* _LIBC */
- ))
- {
- unsigned char c = 0;
- do
- {
- mbstate_t mbs;
- memset (&mbs, 0, sizeof (mbs));
- if (__mbrtowc (NULL, (char *) &c, 1, &mbs) == (size_t) -2)
- re_set_fastmap (fastmap, false, (int) c);
- }
- while (++c != 0);
- }
-
- else
- {
- /* ... Else catch all bytes which can start the mbchars. */
- for (i = 0; i < cset->nmbchars; ++i)
- {
- char buf[256];
- mbstate_t state;
- memset (&state, '\0', sizeof (state));
- if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1)
- re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
- if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
- {
- if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state)
- != (size_t) -1)
- re_set_fastmap (fastmap, false, *(unsigned char *) buf);
- }
- }
- }
- }
-#endif /* RE_ENABLE_I18N */
- else if (type == OP_PERIOD
-#ifdef RE_ENABLE_I18N
- || type == OP_UTF8_PERIOD
-#endif /* RE_ENABLE_I18N */
- || type == END_OF_RE)
- {
- memset (fastmap, '\1', sizeof (char) * SBC_MAX);
- if (type == END_OF_RE)
- bufp->can_be_null = 1;
- return;
- }
- }
-}
-
-/* Entry point for POSIX code. */
-/* regcomp takes a regular expression as a string and compiles it.
-
- PREG is a regex_t *. We do not expect any fields to be initialized,
- since POSIX says we shouldn't. Thus, we set
-
- 'buffer' to the compiled pattern;
- 'used' to the length of the compiled pattern;
- 'syntax' to RE_SYNTAX_POSIX_EXTENDED if the
- REG_EXTENDED bit in CFLAGS is set; otherwise, to
- RE_SYNTAX_POSIX_BASIC;
- 'newline_anchor' to REG_NEWLINE being set in CFLAGS;
- 'fastmap' to an allocated space for the fastmap;
- 'fastmap_accurate' to zero;
- 're_nsub' to the number of subexpressions in PATTERN.
-
- PATTERN is the address of the pattern string.
-
- CFLAGS is a series of bits which affect compilation.
-
- If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
- use POSIX basic syntax.
-
- If REG_NEWLINE is set, then . and [^...] don't match newline.
- Also, regexec will try a match beginning after every newline.
-
- If REG_ICASE is set, then we considers upper- and lowercase
- versions of letters to be equivalent when matching.
-
- If REG_NOSUB is set, then when PREG is passed to regexec, that
- routine will report only success or failure, and nothing about the
- registers.
-
- It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
- the return codes and their meanings.) */
-
-int
-regcomp (preg, pattern, cflags)
- regex_t *_Restrict_ preg;
- const char *_Restrict_ pattern;
- int cflags;
-{
- reg_errcode_t ret;
- reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
- : RE_SYNTAX_POSIX_BASIC);
-
- preg->buffer = NULL;
- preg->allocated = 0;
- preg->used = 0;
-
- /* Try to allocate space for the fastmap. */
- preg->fastmap = re_malloc (char, SBC_MAX);
- if (BE (preg->fastmap == NULL, 0))
- return REG_ESPACE;
-
- syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
-
- /* If REG_NEWLINE is set, newlines are treated differently. */
- if (cflags & REG_NEWLINE)
- { /* REG_NEWLINE implies neither . nor [^...] match newline. */
- syntax &= ~RE_DOT_NEWLINE;
- syntax |= RE_HAT_LISTS_NOT_NEWLINE;
- /* It also changes the matching behavior. */
- preg->newline_anchor = 1;
- }
- else
- preg->newline_anchor = 0;
- preg->no_sub = !!(cflags & REG_NOSUB);
- preg->translate = NULL;
-
- ret = re_compile_internal (preg, pattern, strlen (pattern), syntax);
-
- /* POSIX doesn't distinguish between an unmatched open-group and an
- unmatched close-group: both are REG_EPAREN. */
- if (ret == REG_ERPAREN)
- ret = REG_EPAREN;
-
- /* We have already checked preg->fastmap != NULL. */
- if (BE (ret == REG_NOERROR, 1))
- /* Compute the fastmap now, since regexec cannot modify the pattern
- buffer. This function never fails in this implementation. */
- (void) re_compile_fastmap (preg);
- else
- {
- /* Some error occurred while compiling the expression. */
- re_free (preg->fastmap);
- preg->fastmap = NULL;
- }
-
- return (int) ret;
-}
-#ifdef _LIBC
-weak_alias (__regcomp, regcomp)
-#endif
-
-/* Returns a message corresponding to an error code, ERRCODE, returned
- from either regcomp or regexec. We don't use PREG here. */
-
-#ifdef _LIBC
-size_t
-regerror (errcode, preg, errbuf, errbuf_size)
- int errcode;
- const regex_t *_Restrict_ preg;
- char *_Restrict_ errbuf;
- size_t errbuf_size;
-#else /* size_t might promote */
-size_t
-regerror (int errcode, const regex_t *_Restrict_ preg,
- char *_Restrict_ errbuf, size_t errbuf_size)
-#endif
-{
- const char *msg;
- size_t msg_size;
-
- if (BE (errcode < 0
- || errcode >= (int) (sizeof (__re_error_msgid_idx)
- / sizeof (__re_error_msgid_idx[0])), 0))
- /* Only error codes returned by the rest of the code should be passed
- to this routine. If we are given anything else, or if other regex
- code generates an invalid error code, then the program has a bug.
- Dump core so we can fix it. */
- abort ();
-
- msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]);
-
- msg_size = strlen (msg) + 1; /* Includes the null. */
-
- if (BE (errbuf_size != 0, 1))
- {
- size_t cpy_size = msg_size;
- if (BE (msg_size > errbuf_size, 0))
- {
- cpy_size = errbuf_size - 1;
- errbuf[cpy_size] = '\0';
- }
- memcpy (errbuf, msg, cpy_size);
- }
-
- return msg_size;
-}
-#ifdef _LIBC
-weak_alias (__regerror, regerror)
-#endif
-
-
-#ifdef RE_ENABLE_I18N
-/* This static array is used for the map to single-byte characters when
- UTF-8 is used. Otherwise we would allocate memory just to initialize
- it the same all the time. UTF-8 is the preferred encoding so this is
- a worthwhile optimization. */
-static const bitset_t utf8_sb_map =
-{
- /* Set the first 128 bits. */
-# if defined __GNUC__ && !defined __STRICT_ANSI__
- [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX
-# else
-# if 4 * BITSET_WORD_BITS < ASCII_CHARS
-# error "bitset_word_t is narrower than 32 bits"
-# elif 3 * BITSET_WORD_BITS < ASCII_CHARS
- BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX,
-# elif 2 * BITSET_WORD_BITS < ASCII_CHARS
- BITSET_WORD_MAX, BITSET_WORD_MAX,
-# elif 1 * BITSET_WORD_BITS < ASCII_CHARS
- BITSET_WORD_MAX,
-# endif
- (BITSET_WORD_MAX
- >> (SBC_MAX % BITSET_WORD_BITS == 0
- ? 0
- : BITSET_WORD_BITS - SBC_MAX % BITSET_WORD_BITS))
-# endif
-};
-#endif
-
-
-static void
-free_dfa_content (re_dfa_t *dfa)
-{
- Idx i, j;
-
- if (dfa->nodes)
- for (i = 0; i < dfa->nodes_len; ++i)
- free_token (dfa->nodes + i);
- re_free (dfa->nexts);
- for (i = 0; i < dfa->nodes_len; ++i)
- {
- if (dfa->eclosures != NULL)
- re_node_set_free (dfa->eclosures + i);
- if (dfa->inveclosures != NULL)
- re_node_set_free (dfa->inveclosures + i);
- if (dfa->edests != NULL)
- re_node_set_free (dfa->edests + i);
- }
- re_free (dfa->edests);
- re_free (dfa->eclosures);
- re_free (dfa->inveclosures);
- re_free (dfa->nodes);
-
- if (dfa->state_table)
- for (i = 0; i <= dfa->state_hash_mask; ++i)
- {
- struct re_state_table_entry *entry = dfa->state_table + i;
- for (j = 0; j < entry->num; ++j)
- {
- re_dfastate_t *state = entry->array[j];
- free_state (state);
- }
- re_free (entry->array);
- }
- re_free (dfa->state_table);
-#ifdef RE_ENABLE_I18N
- if (dfa->sb_char != utf8_sb_map)
- re_free (dfa->sb_char);
-#endif
- re_free (dfa->subexp_map);
-#ifdef DEBUG
- re_free (dfa->re_str);
-#endif
-
- re_free (dfa);
-}
-
-
-/* Free dynamically allocated space used by PREG. */
-
-void
-regfree (preg)
- regex_t *preg;
-{
- re_dfa_t *dfa = preg->buffer;
- if (BE (dfa != NULL, 1))
- {
- lock_fini (dfa->lock);
- free_dfa_content (dfa);
- }
- preg->buffer = NULL;
- preg->allocated = 0;
-
- re_free (preg->fastmap);
- preg->fastmap = NULL;
-
- re_free (preg->translate);
- preg->translate = NULL;
-}
-#ifdef _LIBC
-weak_alias (__regfree, regfree)
-#endif
-
-/* Entry points compatible with 4.2 BSD regex library. We don't define
- them unless specifically requested. */
-
-#if defined _REGEX_RE_COMP || defined _LIBC
-
-/* BSD has one and only one pattern buffer. */
-static struct re_pattern_buffer re_comp_buf;
-
-char *
-# ifdef _LIBC
-/* Make these definitions weak in libc, so POSIX programs can redefine
- these names if they don't use our functions, and still use
- regcomp/regexec above without link errors. */
-weak_function
-# endif
-re_comp (s)
- const char *s;
-{
- reg_errcode_t ret;
- char *fastmap;
-
- if (!s)
- {
- if (!re_comp_buf.buffer)
- return gettext ("No previous regular expression");
- return 0;
- }
-
- if (re_comp_buf.buffer)
- {
- fastmap = re_comp_buf.fastmap;
- re_comp_buf.fastmap = NULL;
- __regfree (&re_comp_buf);
- memset (&re_comp_buf, '\0', sizeof (re_comp_buf));
- re_comp_buf.fastmap = fastmap;
- }
-
- if (re_comp_buf.fastmap == NULL)
- {
- re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
- if (re_comp_buf.fastmap == NULL)
- return (char *) gettext (__re_error_msgid
- + __re_error_msgid_idx[(int) REG_ESPACE]);
- }
-
- /* Since 're_exec' always passes NULL for the 'regs' argument, we
- don't need to initialize the pattern buffer fields which affect it. */
-
- /* Match anchors at newlines. */
- re_comp_buf.newline_anchor = 1;
-
- ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options);
-
- if (!ret)
- return NULL;
-
- /* Yes, we're discarding 'const' here if !HAVE_LIBINTL. */
- return (char *) gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
-}
-
-#ifdef _LIBC
-libc_freeres_fn (free_mem)
-{
- __regfree (&re_comp_buf);
-}
-#endif
-
-#endif /* _REGEX_RE_COMP */
-
-/* Internal entry point.
- Compile the regular expression PATTERN, whose length is LENGTH.
- SYNTAX indicate regular expression's syntax. */
-
-static reg_errcode_t
-re_compile_internal (regex_t *preg, const char * pattern, size_t length,
- reg_syntax_t syntax)
-{
- reg_errcode_t err = REG_NOERROR;
- re_dfa_t *dfa;
- re_string_t regexp;
-
- /* Initialize the pattern buffer. */
- preg->fastmap_accurate = 0;
- preg->syntax = syntax;
- preg->not_bol = preg->not_eol = 0;
- preg->used = 0;
- preg->re_nsub = 0;
- preg->can_be_null = 0;
- preg->regs_allocated = REGS_UNALLOCATED;
-
- /* Initialize the dfa. */
- dfa = preg->buffer;
- if (BE (preg->allocated < sizeof (re_dfa_t), 0))
- {
- /* If zero allocated, but buffer is non-null, try to realloc
- enough space. This loses if buffer's address is bogus, but
- that is the user's responsibility. If ->buffer is NULL this
- is a simple allocation. */
- dfa = re_realloc (preg->buffer, re_dfa_t, 1);
- if (dfa == NULL)
- return REG_ESPACE;
- preg->allocated = sizeof (re_dfa_t);
- preg->buffer = dfa;
- }
- preg->used = sizeof (re_dfa_t);
-
- err = init_dfa (dfa, length);
- if (BE (err == REG_NOERROR && lock_init (dfa->lock) != 0, 0))
- err = REG_ESPACE;
- if (BE (err != REG_NOERROR, 0))
- {
- free_dfa_content (dfa);
- preg->buffer = NULL;
- preg->allocated = 0;
- return err;
- }
-#ifdef DEBUG
- /* Note: length+1 will not overflow since it is checked in init_dfa. */
- dfa->re_str = re_malloc (char, length + 1);
- strncpy (dfa->re_str, pattern, length + 1);
-#endif
-
- err = re_string_construct (&regexp, pattern, length, preg->translate,
- (syntax & RE_ICASE) != 0, dfa);
- if (BE (err != REG_NOERROR, 0))
- {
- re_compile_internal_free_return:
- free_workarea_compile (preg);
- re_string_destruct (&regexp);
- lock_fini (dfa->lock);
- free_dfa_content (dfa);
- preg->buffer = NULL;
- preg->allocated = 0;
- return err;
- }
-
- /* Parse the regular expression, and build a structure tree. */
- preg->re_nsub = 0;
- dfa->str_tree = parse (&regexp, preg, syntax, &err);
- if (BE (dfa->str_tree == NULL, 0))
- goto re_compile_internal_free_return;
-
- /* Analyze the tree and create the nfa. */
- err = analyze (preg);
- if (BE (err != REG_NOERROR, 0))
- goto re_compile_internal_free_return;
-
-#ifdef RE_ENABLE_I18N
- /* If possible, do searching in single byte encoding to speed things up. */
- if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL)
- optimize_utf8 (dfa);
-#endif
-
- /* Then create the initial state of the dfa. */
- err = create_initial_state (dfa);
-
- /* Release work areas. */
- free_workarea_compile (preg);
- re_string_destruct (&regexp);
-
- if (BE (err != REG_NOERROR, 0))
- {
- lock_fini (dfa->lock);
- free_dfa_content (dfa);
- preg->buffer = NULL;
- preg->allocated = 0;
- }
-
- return err;
-}
-
-/* Initialize DFA. We use the length of the regular expression PAT_LEN
- as the initial length of some arrays. */
-
-static reg_errcode_t
-init_dfa (re_dfa_t *dfa, size_t pat_len)
-{
- __re_size_t table_size;
-#ifndef _LIBC
- const char *codeset_name;
-#endif
-#ifdef RE_ENABLE_I18N
- size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
-#else
- size_t max_i18n_object_size = 0;
-#endif
- size_t max_object_size =
- MAX (sizeof (struct re_state_table_entry),
- MAX (sizeof (re_token_t),
- MAX (sizeof (re_node_set),
- MAX (sizeof (regmatch_t),
- max_i18n_object_size))));
-
- memset (dfa, '\0', sizeof (re_dfa_t));
-
- /* Force allocation of str_tree_storage the first time. */
- dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
-
- /* Avoid overflows. The extra "/ 2" is for the table_size doubling
- calculation below, and for similar doubling calculations
- elsewhere. And it's <= rather than <, because some of the
- doubling calculations add 1 afterwards. */
- if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2 <= pat_len, 0))
- return REG_ESPACE;
-
- dfa->nodes_alloc = pat_len + 1;
- dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
-
- /* table_size = 2 ^ ceil(log pat_len) */
- for (table_size = 1; ; table_size <<= 1)
- if (table_size > pat_len)
- break;
-
- dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
- dfa->state_hash_mask = table_size - 1;
-
- dfa->mb_cur_max = MB_CUR_MAX;
-#ifdef _LIBC
- if (dfa->mb_cur_max == 6
- && strcmp (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_CODESET_NAME), "UTF-8") == 0)
- dfa->is_utf8 = 1;
- dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII)
- != 0);
-#else
- codeset_name = nl_langinfo (CODESET);
- if ((codeset_name[0] == 'U' || codeset_name[0] == 'u')
- && (codeset_name[1] == 'T' || codeset_name[1] == 't')
- && (codeset_name[2] == 'F' || codeset_name[2] == 'f')
- && strcmp (codeset_name + 3 + (codeset_name[3] == '-'), "8") == 0)
- dfa->is_utf8 = 1;
-
- /* We check exhaustively in the loop below if this charset is a
- superset of ASCII. */
- dfa->map_notascii = 0;
-#endif
-
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- {
- if (dfa->is_utf8)
- dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map;
- else
- {
- int i, j, ch;
-
- dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
- if (BE (dfa->sb_char == NULL, 0))
- return REG_ESPACE;
-
- /* Set the bits corresponding to single byte chars. */
- for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
- for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
- {
- wint_t wch = __btowc (ch);
- if (wch != WEOF)
- dfa->sb_char[i] |= (bitset_word_t) 1 << j;
-# ifndef _LIBC
- if (isascii (ch) && wch != ch)
- dfa->map_notascii = 1;
-# endif
- }
- }
- }
-#endif
-
- if (BE (dfa->nodes == NULL || dfa->state_table == NULL, 0))
- return REG_ESPACE;
- return REG_NOERROR;
-}
-
-/* Initialize WORD_CHAR table, which indicate which character is
- "word". In this case "word" means that it is the word construction
- character used by some operators like "\<", "\>", etc. */
-
-static void
-internal_function
-init_word_char (re_dfa_t *dfa)
-{
- int i = 0;
- int j;
- int ch = 0;
- dfa->word_ops_used = 1;
- if (BE (dfa->map_notascii == 0, 1))
- {
- bitset_word_t bits0 = 0x00000000;
- bitset_word_t bits1 = 0x03ff0000;
- bitset_word_t bits2 = 0x87fffffe;
- bitset_word_t bits3 = 0x07fffffe;
- if (BITSET_WORD_BITS == 64)
- {
- dfa->word_char[0] = bits1 << 31 << 1 | bits0;
- dfa->word_char[1] = bits3 << 31 << 1 | bits2;
- i = 2;
- }
- else if (BITSET_WORD_BITS == 32)
- {
- dfa->word_char[0] = bits0;
- dfa->word_char[1] = bits1;
- dfa->word_char[2] = bits2;
- dfa->word_char[3] = bits3;
- i = 4;
- }
- else
- goto general_case;
- ch = 128;
-
- if (BE (dfa->is_utf8, 1))
- {
- memset (&dfa->word_char[i], '\0', (SBC_MAX - ch) / 8);
- return;
- }
- }
-
- general_case:
- for (; i < BITSET_WORDS; ++i)
- for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
- if (isalnum (ch) || ch == '_')
- dfa->word_char[i] |= (bitset_word_t) 1 << j;
-}
-
-/* Free the work area which are only used while compiling. */
-
-static void
-free_workarea_compile (regex_t *preg)
-{
- re_dfa_t *dfa = preg->buffer;
- bin_tree_storage_t *storage, *next;
- for (storage = dfa->str_tree_storage; storage; storage = next)
- {
- next = storage->next;
- re_free (storage);
- }
- dfa->str_tree_storage = NULL;
- dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
- dfa->str_tree = NULL;
- re_free (dfa->org_indices);
- dfa->org_indices = NULL;
-}
-
-/* Create initial states for all contexts. */
-
-static reg_errcode_t
-create_initial_state (re_dfa_t *dfa)
-{
- Idx first, i;
- reg_errcode_t err;
- re_node_set init_nodes;
-
- /* Initial states have the epsilon closure of the node which is
- the first node of the regular expression. */
- first = dfa->str_tree->first->node_idx;
- dfa->init_node = first;
- err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- /* The back-references which are in initial states can epsilon transit,
- since in this case all of the subexpressions can be null.
- Then we add epsilon closures of the nodes which are the next nodes of
- the back-references. */
- if (dfa->nbackref > 0)
- for (i = 0; i < init_nodes.nelem; ++i)
- {
- Idx node_idx = init_nodes.elems[i];
- re_token_type_t type = dfa->nodes[node_idx].type;
-
- Idx clexp_idx;
- if (type != OP_BACK_REF)
- continue;
- for (clexp_idx = 0; clexp_idx < init_nodes.nelem; ++clexp_idx)
- {
- re_token_t *clexp_node;
- clexp_node = dfa->nodes + init_nodes.elems[clexp_idx];
- if (clexp_node->type == OP_CLOSE_SUBEXP
- && clexp_node->opr.idx == dfa->nodes[node_idx].opr.idx)
- break;
- }
- if (clexp_idx == init_nodes.nelem)
- continue;
-
- if (type == OP_BACK_REF)
- {
- Idx dest_idx = dfa->edests[node_idx].elems[0];
- if (!re_node_set_contains (&init_nodes, dest_idx))
- {
- reg_errcode_t merge_err
- = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx);
- if (merge_err != REG_NOERROR)
- return merge_err;
- i = 0;
- }
- }
- }
-
- /* It must be the first time to invoke acquire_state. */
- dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0);
- /* We don't check ERR here, since the initial state must not be NULL. */
- if (BE (dfa->init_state == NULL, 0))
- return err;
- if (dfa->init_state->has_constraint)
- {
- dfa->init_state_word = re_acquire_state_context (&err, dfa, &init_nodes,
- CONTEXT_WORD);
- dfa->init_state_nl = re_acquire_state_context (&err, dfa, &init_nodes,
- CONTEXT_NEWLINE);
- dfa->init_state_begbuf = re_acquire_state_context (&err, dfa,
- &init_nodes,
- CONTEXT_NEWLINE
- | CONTEXT_BEGBUF);
- if (BE (dfa->init_state_word == NULL || dfa->init_state_nl == NULL
- || dfa->init_state_begbuf == NULL, 0))
- return err;
- }
- else
- dfa->init_state_word = dfa->init_state_nl
- = dfa->init_state_begbuf = dfa->init_state;
-
- re_node_set_free (&init_nodes);
- return REG_NOERROR;
-}
-
-#ifdef RE_ENABLE_I18N
-/* If it is possible to do searching in single byte encoding instead of UTF-8
- to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change
- DFA nodes where needed. */
-
-static void
-optimize_utf8 (re_dfa_t *dfa)
-{
- Idx node;
- int i;
- bool mb_chars = false;
- bool has_period = false;
-
- for (node = 0; node < dfa->nodes_len; ++node)
- switch (dfa->nodes[node].type)
- {
- case CHARACTER:
- if (dfa->nodes[node].opr.c >= ASCII_CHARS)
- mb_chars = true;
- break;
- case ANCHOR:
- switch (dfa->nodes[node].opr.ctx_type)
- {
- case LINE_FIRST:
- case LINE_LAST:
- case BUF_FIRST:
- case BUF_LAST:
- break;
- default:
- /* Word anchors etc. cannot be handled. It's okay to test
- opr.ctx_type since constraints (for all DFA nodes) are
- created by ORing one or more opr.ctx_type values. */
- return;
- }
- break;
- case OP_PERIOD:
- has_period = true;
- break;
- case OP_BACK_REF:
- case OP_ALT:
- case END_OF_RE:
- case OP_DUP_ASTERISK:
- case OP_OPEN_SUBEXP:
- case OP_CLOSE_SUBEXP:
- break;
- case COMPLEX_BRACKET:
- return;
- case SIMPLE_BRACKET:
- /* Just double check. */
- {
- int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0
- ? 0
- : BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS);
- for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
- {
- if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0)
- return;
- rshift = 0;
- }
- }
- break;
- default:
- abort ();
- }
-
- if (mb_chars || has_period)
- for (node = 0; node < dfa->nodes_len; ++node)
- {
- if (dfa->nodes[node].type == CHARACTER
- && dfa->nodes[node].opr.c >= ASCII_CHARS)
- dfa->nodes[node].mb_partial = 0;
- else if (dfa->nodes[node].type == OP_PERIOD)
- dfa->nodes[node].type = OP_UTF8_PERIOD;
- }
-
- /* The search can be in single byte locale. */
- dfa->mb_cur_max = 1;
- dfa->is_utf8 = 0;
- dfa->has_mb_node = dfa->nbackref > 0 || has_period;
-}
-#endif
-
-/* Analyze the structure tree, and calculate "first", "next", "edest",
- "eclosure", and "inveclosure". */
-
-static reg_errcode_t
-analyze (regex_t *preg)
-{
- re_dfa_t *dfa = preg->buffer;
- reg_errcode_t ret;
-
- /* Allocate arrays. */
- dfa->nexts = re_malloc (Idx, dfa->nodes_alloc);
- dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
- dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
- dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
- if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL
- || dfa->eclosures == NULL, 0))
- return REG_ESPACE;
-
- dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
- if (dfa->subexp_map != NULL)
- {
- Idx i;
- for (i = 0; i < preg->re_nsub; i++)
- dfa->subexp_map[i] = i;
- preorder (dfa->str_tree, optimize_subexps, dfa);
- for (i = 0; i < preg->re_nsub; i++)
- if (dfa->subexp_map[i] != i)
- break;
- if (i == preg->re_nsub)
- {
- free (dfa->subexp_map);
- dfa->subexp_map = NULL;
- }
- }
-
- ret = postorder (dfa->str_tree, lower_subexps, preg);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- ret = postorder (dfa->str_tree, calc_first, dfa);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- preorder (dfa->str_tree, calc_next, dfa);
- ret = preorder (dfa->str_tree, link_nfa_nodes, dfa);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- ret = calc_eclosure (dfa);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
-
- /* We only need this during the prune_impossible_nodes pass in regexec.c;
- skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */
- if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
- || dfa->nbackref)
- {
- dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
- if (BE (dfa->inveclosures == NULL, 0))
- return REG_ESPACE;
- ret = calc_inveclosure (dfa);
- }
-
- return ret;
-}
-
-/* Our parse trees are very unbalanced, so we cannot use a stack to
- implement parse tree visits. Instead, we use parent pointers and
- some hairy code in these two functions. */
-static reg_errcode_t
-postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
- void *extra)
-{
- bin_tree_t *node, *prev;
-
- for (node = root; ; )
- {
- /* Descend down the tree, preferably to the left (or to the right
- if that's the only child). */
- while (node->left || node->right)
- if (node->left)
- node = node->left;
- else
- node = node->right;
-
- do
- {
- reg_errcode_t err = fn (extra, node);
- if (BE (err != REG_NOERROR, 0))
- return err;
- if (node->parent == NULL)
- return REG_NOERROR;
- prev = node;
- node = node->parent;
- }
- /* Go up while we have a node that is reached from the right. */
- while (node->right == prev || node->right == NULL);
- node = node->right;
- }
-}
-
-static reg_errcode_t
-preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
- void *extra)
-{
- bin_tree_t *node;
-
- for (node = root; ; )
- {
- reg_errcode_t err = fn (extra, node);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- /* Go to the left node, or up and to the right. */
- if (node->left)
- node = node->left;
- else
- {
- bin_tree_t *prev = NULL;
- while (node->right == prev || node->right == NULL)
- {
- prev = node;
- node = node->parent;
- if (!node)
- return REG_NOERROR;
- }
- node = node->right;
- }
- }
-}
-
-/* Optimization pass: if a SUBEXP is entirely contained, strip it and tell
- re_search_internal to map the inner one's opr.idx to this one's. Adjust
- backreferences as well. Requires a preorder visit. */
-static reg_errcode_t
-optimize_subexps (void *extra, bin_tree_t *node)
-{
- re_dfa_t *dfa = (re_dfa_t *) extra;
-
- if (node->token.type == OP_BACK_REF && dfa->subexp_map)
- {
- int idx = node->token.opr.idx;
- node->token.opr.idx = dfa->subexp_map[idx];
- dfa->used_bkref_map |= 1 << node->token.opr.idx;
- }
-
- else if (node->token.type == SUBEXP
- && node->left && node->left->token.type == SUBEXP)
- {
- Idx other_idx = node->left->token.opr.idx;
-
- node->left = node->left->left;
- if (node->left)
- node->left->parent = node;
-
- dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
- if (other_idx < BITSET_WORD_BITS)
- dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx);
- }
-
- return REG_NOERROR;
-}
-
-/* Lowering pass: Turn each SUBEXP node into the appropriate concatenation
- of OP_OPEN_SUBEXP, the body of the SUBEXP (if any) and OP_CLOSE_SUBEXP. */
-static reg_errcode_t
-lower_subexps (void *extra, bin_tree_t *node)
-{
- regex_t *preg = (regex_t *) extra;
- reg_errcode_t err = REG_NOERROR;
-
- if (node->left && node->left->token.type == SUBEXP)
- {
- node->left = lower_subexp (&err, preg, node->left);
- if (node->left)
- node->left->parent = node;
- }
- if (node->right && node->right->token.type == SUBEXP)
- {
- node->right = lower_subexp (&err, preg, node->right);
- if (node->right)
- node->right->parent = node;
- }
-
- return err;
-}
-
-static bin_tree_t *
-lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
-{
- re_dfa_t *dfa = preg->buffer;
- bin_tree_t *body = node->left;
- bin_tree_t *op, *cls, *tree1, *tree;
-
- if (preg->no_sub
- /* We do not optimize empty subexpressions, because otherwise we may
- have bad CONCAT nodes with NULL children. This is obviously not
- very common, so we do not lose much. An example that triggers
- this case is the sed "script" /\(\)/x. */
- && node->left != NULL
- && (node->token.opr.idx >= BITSET_WORD_BITS
- || !(dfa->used_bkref_map
- & ((bitset_word_t) 1 << node->token.opr.idx))))
- return node->left;
-
- /* Convert the SUBEXP node to the concatenation of an
- OP_OPEN_SUBEXP, the contents, and an OP_CLOSE_SUBEXP. */
- op = create_tree (dfa, NULL, NULL, OP_OPEN_SUBEXP);
- cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP);
- tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls;
- tree = create_tree (dfa, op, tree1, CONCAT);
- if (BE (tree == NULL || tree1 == NULL || op == NULL || cls == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
-
- op->token.opr.idx = cls->token.opr.idx = node->token.opr.idx;
- op->token.opt_subexp = cls->token.opt_subexp = node->token.opt_subexp;
- return tree;
-}
-
-/* Pass 1 in building the NFA: compute FIRST and create unlinked automaton
- nodes. Requires a postorder visit. */
-static reg_errcode_t
-calc_first (void *extra, bin_tree_t *node)
-{
- re_dfa_t *dfa = (re_dfa_t *) extra;
- if (node->token.type == CONCAT)
- {
- node->first = node->left->first;
- node->node_idx = node->left->node_idx;
- }
- else
- {
- node->first = node;
- node->node_idx = re_dfa_add_node (dfa, node->token);
- if (BE (node->node_idx == REG_MISSING, 0))
- return REG_ESPACE;
- if (node->token.type == ANCHOR)
- dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type;
- }
- return REG_NOERROR;
-}
-
-/* Pass 2: compute NEXT on the tree. Preorder visit. */
-static reg_errcode_t
-calc_next (void *extra, bin_tree_t *node)
-{
- switch (node->token.type)
- {
- case OP_DUP_ASTERISK:
- node->left->next = node;
- break;
- case CONCAT:
- node->left->next = node->right->first;
- node->right->next = node->next;
- break;
- default:
- if (node->left)
- node->left->next = node->next;
- if (node->right)
- node->right->next = node->next;
- break;
- }
- return REG_NOERROR;
-}
-
-/* Pass 3: link all DFA nodes to their NEXT node (any order will do). */
-static reg_errcode_t
-link_nfa_nodes (void *extra, bin_tree_t *node)
-{
- re_dfa_t *dfa = (re_dfa_t *) extra;
- Idx idx = node->node_idx;
- reg_errcode_t err = REG_NOERROR;
-
- switch (node->token.type)
- {
- case CONCAT:
- break;
-
- case END_OF_RE:
- assert (node->next == NULL);
- break;
-
- case OP_DUP_ASTERISK:
- case OP_ALT:
- {
- Idx left, right;
- dfa->has_plural_match = 1;
- if (node->left != NULL)
- left = node->left->first->node_idx;
- else
- left = node->next->node_idx;
- if (node->right != NULL)
- right = node->right->first->node_idx;
- else
- right = node->next->node_idx;
- assert (REG_VALID_INDEX (left));
- assert (REG_VALID_INDEX (right));
- err = re_node_set_init_2 (dfa->edests + idx, left, right);
- }
- break;
-
- case ANCHOR:
- case OP_OPEN_SUBEXP:
- case OP_CLOSE_SUBEXP:
- err = re_node_set_init_1 (dfa->edests + idx, node->next->node_idx);
- break;
-
- case OP_BACK_REF:
- dfa->nexts[idx] = node->next->node_idx;
- if (node->token.type == OP_BACK_REF)
- err = re_node_set_init_1 (dfa->edests + idx, dfa->nexts[idx]);
- break;
-
- default:
- assert (!IS_EPSILON_NODE (node->token.type));
- dfa->nexts[idx] = node->next->node_idx;
- break;
- }
-
- return err;
-}
-
-/* Duplicate the epsilon closure of the node ROOT_NODE.
- Note that duplicated nodes have constraint INIT_CONSTRAINT in addition
- to their own constraint. */
-
-static reg_errcode_t
-internal_function
-duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
- Idx root_node, unsigned int init_constraint)
-{
- Idx org_node, clone_node;
- bool ok;
- unsigned int constraint = init_constraint;
- for (org_node = top_org_node, clone_node = top_clone_node;;)
- {
- Idx org_dest, clone_dest;
- if (dfa->nodes[org_node].type == OP_BACK_REF)
- {
- /* If the back reference epsilon-transit, its destination must
- also have the constraint. Then duplicate the epsilon closure
- of the destination of the back reference, and store it in
- edests of the back reference. */
- org_dest = dfa->nexts[org_node];
- re_node_set_empty (dfa->edests + clone_node);
- clone_dest = duplicate_node (dfa, org_dest, constraint);
- if (BE (clone_dest == REG_MISSING, 0))
- return REG_ESPACE;
- dfa->nexts[clone_node] = dfa->nexts[org_node];
- ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
- else if (dfa->edests[org_node].nelem == 0)
- {
- /* In case of the node can't epsilon-transit, don't duplicate the
- destination and store the original destination as the
- destination of the node. */
- dfa->nexts[clone_node] = dfa->nexts[org_node];
- break;
- }
- else if (dfa->edests[org_node].nelem == 1)
- {
- /* In case of the node can epsilon-transit, and it has only one
- destination. */
- org_dest = dfa->edests[org_node].elems[0];
- re_node_set_empty (dfa->edests + clone_node);
- /* If the node is root_node itself, it means the epsilon closure
- has a loop. Then tie it to the destination of the root_node. */
- if (org_node == root_node && clone_node != org_node)
- {
- ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
- if (BE (! ok, 0))
- return REG_ESPACE;
- break;
- }
- /* In case the node has another constraint, append it. */
- constraint |= dfa->nodes[org_node].constraint;
- clone_dest = duplicate_node (dfa, org_dest, constraint);
- if (BE (clone_dest == REG_MISSING, 0))
- return REG_ESPACE;
- ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
- else /* dfa->edests[org_node].nelem == 2 */
- {
- /* In case of the node can epsilon-transit, and it has two
- destinations. In the bin_tree_t and DFA, that's '|' and '*'. */
- org_dest = dfa->edests[org_node].elems[0];
- re_node_set_empty (dfa->edests + clone_node);
- /* Search for a duplicated node which satisfies the constraint. */
- clone_dest = search_duplicated_node (dfa, org_dest, constraint);
- if (clone_dest == REG_MISSING)
- {
- /* There is no such duplicated node, create a new one. */
- reg_errcode_t err;
- clone_dest = duplicate_node (dfa, org_dest, constraint);
- if (BE (clone_dest == REG_MISSING, 0))
- return REG_ESPACE;
- ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (! ok, 0))
- return REG_ESPACE;
- err = duplicate_node_closure (dfa, org_dest, clone_dest,
- root_node, constraint);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- else
- {
- /* There is a duplicated node which satisfies the constraint,
- use it to avoid infinite loop. */
- ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
-
- org_dest = dfa->edests[org_node].elems[1];
- clone_dest = duplicate_node (dfa, org_dest, constraint);
- if (BE (clone_dest == REG_MISSING, 0))
- return REG_ESPACE;
- ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
- org_node = org_dest;
- clone_node = clone_dest;
- }
- return REG_NOERROR;
-}
-
-/* Search for a node which is duplicated from the node ORG_NODE, and
- satisfies the constraint CONSTRAINT. */
-
-static Idx
-search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
- unsigned int constraint)
-{
- Idx idx;
- for (idx = dfa->nodes_len - 1; dfa->nodes[idx].duplicated && idx > 0; --idx)
- {
- if (org_node == dfa->org_indices[idx]
- && constraint == dfa->nodes[idx].constraint)
- return idx; /* Found. */
- }
- return REG_MISSING; /* Not found. */
-}
-
-/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT.
- Return the index of the new node, or REG_MISSING if insufficient storage is
- available. */
-
-static Idx
-duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint)
-{
- Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
- if (BE (dup_idx != REG_MISSING, 1))
- {
- dfa->nodes[dup_idx].constraint = constraint;
- dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint;
- dfa->nodes[dup_idx].duplicated = 1;
-
- /* Store the index of the original node. */
- dfa->org_indices[dup_idx] = org_idx;
- }
- return dup_idx;
-}
-
-static reg_errcode_t
-calc_inveclosure (re_dfa_t *dfa)
-{
- Idx src, idx;
- bool ok;
- for (idx = 0; idx < dfa->nodes_len; ++idx)
- re_node_set_init_empty (dfa->inveclosures + idx);
-
- for (src = 0; src < dfa->nodes_len; ++src)
- {
- Idx *elems = dfa->eclosures[src].elems;
- for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx)
- {
- ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
- }
-
- return REG_NOERROR;
-}
-
-/* Calculate "eclosure" for all the node in DFA. */
-
-static reg_errcode_t
-calc_eclosure (re_dfa_t *dfa)
-{
- Idx node_idx;
- bool incomplete;
-#ifdef DEBUG
- assert (dfa->nodes_len > 0);
-#endif
- incomplete = false;
- /* For each nodes, calculate epsilon closure. */
- for (node_idx = 0; ; ++node_idx)
- {
- reg_errcode_t err;
- re_node_set eclosure_elem;
- if (node_idx == dfa->nodes_len)
- {
- if (!incomplete)
- break;
- incomplete = false;
- node_idx = 0;
- }
-
-#ifdef DEBUG
- assert (dfa->eclosures[node_idx].nelem != REG_MISSING);
-#endif
-
- /* If we have already calculated, skip it. */
- if (dfa->eclosures[node_idx].nelem != 0)
- continue;
- /* Calculate epsilon closure of 'node_idx'. */
- err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- if (dfa->eclosures[node_idx].nelem == 0)
- {
- incomplete = true;
- re_node_set_free (&eclosure_elem);
- }
- }
- return REG_NOERROR;
-}
-
-/* Calculate epsilon closure of NODE. */
-
-static reg_errcode_t
-calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
-{
- reg_errcode_t err;
- Idx i;
- re_node_set eclosure;
- bool ok;
- bool incomplete = false;
- err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- /* This indicates that we are calculating this node now.
- We reference this value to avoid infinite loop. */
- dfa->eclosures[node].nelem = REG_MISSING;
-
- /* If the current node has constraints, duplicate all nodes
- since they must inherit the constraints. */
- if (dfa->nodes[node].constraint
- && dfa->edests[node].nelem
- && !dfa->nodes[dfa->edests[node].elems[0]].duplicated)
- {
- err = duplicate_node_closure (dfa, node, node, node,
- dfa->nodes[node].constraint);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
-
- /* Expand each epsilon destination nodes. */
- if (IS_EPSILON_NODE(dfa->nodes[node].type))
- for (i = 0; i < dfa->edests[node].nelem; ++i)
- {
- re_node_set eclosure_elem;
- Idx edest = dfa->edests[node].elems[i];
- /* If calculating the epsilon closure of 'edest' is in progress,
- return intermediate result. */
- if (dfa->eclosures[edest].nelem == REG_MISSING)
- {
- incomplete = true;
- continue;
- }
- /* If we haven't calculated the epsilon closure of 'edest' yet,
- calculate now. Otherwise use calculated epsilon closure. */
- if (dfa->eclosures[edest].nelem == 0)
- {
- err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- else
- eclosure_elem = dfa->eclosures[edest];
- /* Merge the epsilon closure of 'edest'. */
- err = re_node_set_merge (&eclosure, &eclosure_elem);
- if (BE (err != REG_NOERROR, 0))
- return err;
- /* If the epsilon closure of 'edest' is incomplete,
- the epsilon closure of this node is also incomplete. */
- if (dfa->eclosures[edest].nelem == 0)
- {
- incomplete = true;
- re_node_set_free (&eclosure_elem);
- }
- }
-
- /* An epsilon closure includes itself. */
- ok = re_node_set_insert (&eclosure, node);
- if (BE (! ok, 0))
- return REG_ESPACE;
- if (incomplete && !root)
- dfa->eclosures[node].nelem = 0;
- else
- dfa->eclosures[node] = eclosure;
- *new_set = eclosure;
- return REG_NOERROR;
-}
-
-/* Functions for token which are used in the parser. */
-
-/* Fetch a token from INPUT.
- We must not use this function inside bracket expressions. */
-
-static void
-internal_function
-fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
-{
- re_string_skip_bytes (input, peek_token (result, input, syntax));
-}
-
-/* Peek a token from INPUT, and return the length of the token.
- We must not use this function inside bracket expressions. */
-
-static int
-internal_function
-peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
-{
- unsigned char c;
-
- if (re_string_eoi (input))
- {
- token->type = END_OF_RE;
- return 0;
- }
-
- c = re_string_peek_byte (input, 0);
- token->opr.c = c;
-
- token->word_char = 0;
-#ifdef RE_ENABLE_I18N
- token->mb_partial = 0;
- if (input->mb_cur_max > 1 &&
- !re_string_first_byte (input, re_string_cur_idx (input)))
- {
- token->type = CHARACTER;
- token->mb_partial = 1;
- return 1;
- }
-#endif
- if (c == '\\')
- {
- unsigned char c2;
- if (re_string_cur_idx (input) + 1 >= re_string_length (input))
- {
- token->type = BACK_SLASH;
- return 1;
- }
-
- c2 = re_string_peek_byte_case (input, 1);
- token->opr.c = c2;
- token->type = CHARACTER;
-#ifdef RE_ENABLE_I18N
- if (input->mb_cur_max > 1)
- {
- wint_t wc = re_string_wchar_at (input,
- re_string_cur_idx (input) + 1);
- token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
- }
- else
-#endif
- token->word_char = IS_WORD_CHAR (c2) != 0;
-
- switch (c2)
- {
- case '|':
- if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR))
- token->type = OP_ALT;
- break;
- case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- if (!(syntax & RE_NO_BK_REFS))
- {
- token->type = OP_BACK_REF;
- token->opr.idx = c2 - '1';
- }
- break;
- case '<':
- if (!(syntax & RE_NO_GNU_OPS))
- {
- token->type = ANCHOR;
- token->opr.ctx_type = WORD_FIRST;
- }
- break;
- case '>':
- if (!(syntax & RE_NO_GNU_OPS))
- {
- token->type = ANCHOR;
- token->opr.ctx_type = WORD_LAST;
- }
- break;
- case 'b':
- if (!(syntax & RE_NO_GNU_OPS))
- {
- token->type = ANCHOR;
- token->opr.ctx_type = WORD_DELIM;
- }
- break;
- case 'B':
- if (!(syntax & RE_NO_GNU_OPS))
- {
- token->type = ANCHOR;
- token->opr.ctx_type = NOT_WORD_DELIM;
- }
- break;
- case 'w':
- if (!(syntax & RE_NO_GNU_OPS))
- token->type = OP_WORD;
- break;
- case 'W':
- if (!(syntax & RE_NO_GNU_OPS))
- token->type = OP_NOTWORD;
- break;
- case 's':
- if (!(syntax & RE_NO_GNU_OPS))
- token->type = OP_SPACE;
- break;
- case 'S':
- if (!(syntax & RE_NO_GNU_OPS))
- token->type = OP_NOTSPACE;
- break;
- case '`':
- if (!(syntax & RE_NO_GNU_OPS))
- {
- token->type = ANCHOR;
- token->opr.ctx_type = BUF_FIRST;
- }
- break;
- case '\'':
- if (!(syntax & RE_NO_GNU_OPS))
- {
- token->type = ANCHOR;
- token->opr.ctx_type = BUF_LAST;
- }
- break;
- case '(':
- if (!(syntax & RE_NO_BK_PARENS))
- token->type = OP_OPEN_SUBEXP;
- break;
- case ')':
- if (!(syntax & RE_NO_BK_PARENS))
- token->type = OP_CLOSE_SUBEXP;
- break;
- case '+':
- if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
- token->type = OP_DUP_PLUS;
- break;
- case '?':
- if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
- token->type = OP_DUP_QUESTION;
- break;
- case '{':
- if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
- token->type = OP_OPEN_DUP_NUM;
- break;
- case '}':
- if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
- token->type = OP_CLOSE_DUP_NUM;
- break;
- default:
- break;
- }
- return 2;
- }
-
- token->type = CHARACTER;
-#ifdef RE_ENABLE_I18N
- if (input->mb_cur_max > 1)
- {
- wint_t wc = re_string_wchar_at (input, re_string_cur_idx (input));
- token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
- }
- else
-#endif
- token->word_char = IS_WORD_CHAR (token->opr.c);
-
- switch (c)
- {
- case '\n':
- if (syntax & RE_NEWLINE_ALT)
- token->type = OP_ALT;
- break;
- case '|':
- if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR))
- token->type = OP_ALT;
- break;
- case '*':
- token->type = OP_DUP_ASTERISK;
- break;
- case '+':
- if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
- token->type = OP_DUP_PLUS;
- break;
- case '?':
- if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
- token->type = OP_DUP_QUESTION;
- break;
- case '{':
- if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
- token->type = OP_OPEN_DUP_NUM;
- break;
- case '}':
- if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
- token->type = OP_CLOSE_DUP_NUM;
- break;
- case '(':
- if (syntax & RE_NO_BK_PARENS)
- token->type = OP_OPEN_SUBEXP;
- break;
- case ')':
- if (syntax & RE_NO_BK_PARENS)
- token->type = OP_CLOSE_SUBEXP;
- break;
- case '[':
- token->type = OP_OPEN_BRACKET;
- break;
- case '.':
- token->type = OP_PERIOD;
- break;
- case '^':
- if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) &&
- re_string_cur_idx (input) != 0)
- {
- char prev = re_string_peek_byte (input, -1);
- if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
- break;
- }
- token->type = ANCHOR;
- token->opr.ctx_type = LINE_FIRST;
- break;
- case '$':
- if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) &&
- re_string_cur_idx (input) + 1 != re_string_length (input))
- {
- re_token_t next;
- re_string_skip_bytes (input, 1);
- peek_token (&next, input, syntax);
- re_string_skip_bytes (input, -1);
- if (next.type != OP_ALT && next.type != OP_CLOSE_SUBEXP)
- break;
- }
- token->type = ANCHOR;
- token->opr.ctx_type = LINE_LAST;
- break;
- default:
- break;
- }
- return 1;
-}
-
-/* Peek a token from INPUT, and return the length of the token.
- We must not use this function out of bracket expressions. */
-
-static int
-internal_function
-peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
-{
- unsigned char c;
- if (re_string_eoi (input))
- {
- token->type = END_OF_RE;
- return 0;
- }
- c = re_string_peek_byte (input, 0);
- token->opr.c = c;
-
-#ifdef RE_ENABLE_I18N
- if (input->mb_cur_max > 1 &&
- !re_string_first_byte (input, re_string_cur_idx (input)))
- {
- token->type = CHARACTER;
- return 1;
- }
-#endif /* RE_ENABLE_I18N */
-
- if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS)
- && re_string_cur_idx (input) + 1 < re_string_length (input))
- {
- /* In this case, '\' escape a character. */
- unsigned char c2;
- re_string_skip_bytes (input, 1);
- c2 = re_string_peek_byte (input, 0);
- token->opr.c = c2;
- token->type = CHARACTER;
- return 1;
- }
- if (c == '[') /* '[' is a special char in a bracket exps. */
- {
- unsigned char c2;
- int token_len;
- if (re_string_cur_idx (input) + 1 < re_string_length (input))
- c2 = re_string_peek_byte (input, 1);
- else
- c2 = 0;
- token->opr.c = c2;
- token_len = 2;
- switch (c2)
- {
- case '.':
- token->type = OP_OPEN_COLL_ELEM;
- break;
- case '=':
- token->type = OP_OPEN_EQUIV_CLASS;
- break;
- case ':':
- if (syntax & RE_CHAR_CLASSES)
- {
- token->type = OP_OPEN_CHAR_CLASS;
- break;
- }
- /* else fall through. */
- default:
- token->type = CHARACTER;
- token->opr.c = c;
- token_len = 1;
- break;
- }
- return token_len;
- }
- switch (c)
- {
- case '-':
- token->type = OP_CHARSET_RANGE;
- break;
- case ']':
- token->type = OP_CLOSE_BRACKET;
- break;
- case '^':
- token->type = OP_NON_MATCH_LIST;
- break;
- default:
- token->type = CHARACTER;
- }
- return 1;
-}
-
-/* Functions for parser. */
-
-/* Entry point of the parser.
- Parse the regular expression REGEXP and return the structure tree.
- If an error occurs, ERR is set by error code, and return NULL.
- This function build the following tree, from regular expression <reg_exp>:
- CAT
- / \
- / \
- <reg_exp> EOR
-
- CAT means concatenation.
- EOR means end of regular expression. */
-
-static bin_tree_t *
-parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
- reg_errcode_t *err)
-{
- re_dfa_t *dfa = preg->buffer;
- bin_tree_t *tree, *eor, *root;
- re_token_t current_token;
- dfa->syntax = syntax;
- fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
- tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
- eor = create_tree (dfa, NULL, NULL, END_OF_RE);
- if (tree != NULL)
- root = create_tree (dfa, tree, eor, CONCAT);
- else
- root = eor;
- if (BE (eor == NULL || root == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- return root;
-}
-
-/* This function build the following tree, from regular expression
- <branch1>|<branch2>:
- ALT
- / \
- / \
- <branch1> <branch2>
-
- ALT means alternative, which represents the operator '|'. */
-
-static bin_tree_t *
-parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
- reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
-{
- re_dfa_t *dfa = preg->buffer;
- bin_tree_t *tree, *branch = NULL;
- tree = parse_branch (regexp, preg, token, syntax, nest, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
-
- while (token->type == OP_ALT)
- {
- fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
- if (token->type != OP_ALT && token->type != END_OF_RE
- && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
- {
- branch = parse_branch (regexp, preg, token, syntax, nest, err);
- if (BE (*err != REG_NOERROR && branch == NULL, 0))
- return NULL;
- }
- else
- branch = NULL;
- tree = create_tree (dfa, tree, branch, OP_ALT);
- if (BE (tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- }
- return tree;
-}
-
-/* This function build the following tree, from regular expression
- <exp1><exp2>:
- CAT
- / \
- / \
- <exp1> <exp2>
-
- CAT means concatenation. */
-
-static bin_tree_t *
-parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
- reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
-{
- bin_tree_t *tree, *expr;
- re_dfa_t *dfa = preg->buffer;
- tree = parse_expression (regexp, preg, token, syntax, nest, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
-
- while (token->type != OP_ALT && token->type != END_OF_RE
- && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
- {
- expr = parse_expression (regexp, preg, token, syntax, nest, err);
- if (BE (*err != REG_NOERROR && expr == NULL, 0))
- {
- if (tree != NULL)
- postorder (tree, free_tree, NULL);
- return NULL;
- }
- if (tree != NULL && expr != NULL)
- {
- bin_tree_t *newtree = create_tree (dfa, tree, expr, CONCAT);
- if (newtree == NULL)
- {
- postorder (expr, free_tree, NULL);
- postorder (tree, free_tree, NULL);
- *err = REG_ESPACE;
- return NULL;
- }
- tree = newtree;
- }
- else if (tree == NULL)
- tree = expr;
- /* Otherwise expr == NULL, we don't need to create new tree. */
- }
- return tree;
-}
-
-/* This function build the following tree, from regular expression a*:
- *
- |
- a
-*/
-
-static bin_tree_t *
-parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
- reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
-{
- re_dfa_t *dfa = preg->buffer;
- bin_tree_t *tree;
- switch (token->type)
- {
- case CHARACTER:
- tree = create_token_tree (dfa, NULL, NULL, token);
- if (BE (tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- {
- while (!re_string_eoi (regexp)
- && !re_string_first_byte (regexp, re_string_cur_idx (regexp)))
- {
- bin_tree_t *mbc_remain;
- fetch_token (token, regexp, syntax);
- mbc_remain = create_token_tree (dfa, NULL, NULL, token);
- tree = create_tree (dfa, tree, mbc_remain, CONCAT);
- if (BE (mbc_remain == NULL || tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- }
- }
-#endif
- break;
- case OP_OPEN_SUBEXP:
- tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
- break;
- case OP_OPEN_BRACKET:
- tree = parse_bracket_exp (regexp, dfa, token, syntax, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
- break;
- case OP_BACK_REF:
- if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1))
- {
- *err = REG_ESUBREG;
- return NULL;
- }
- dfa->used_bkref_map |= 1 << token->opr.idx;
- tree = create_token_tree (dfa, NULL, NULL, token);
- if (BE (tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- ++dfa->nbackref;
- dfa->has_mb_node = 1;
- break;
- case OP_OPEN_DUP_NUM:
- if (syntax & RE_CONTEXT_INVALID_DUP)
- {
- *err = REG_BADRPT;
- return NULL;
- }
- /* FALLTHROUGH */
- case OP_DUP_ASTERISK:
- case OP_DUP_PLUS:
- case OP_DUP_QUESTION:
- if (syntax & RE_CONTEXT_INVALID_OPS)
- {
- *err = REG_BADRPT;
- return NULL;
- }
- else if (syntax & RE_CONTEXT_INDEP_OPS)
- {
- fetch_token (token, regexp, syntax);
- return parse_expression (regexp, preg, token, syntax, nest, err);
- }
- /* else fall through */
- case OP_CLOSE_SUBEXP:
- if ((token->type == OP_CLOSE_SUBEXP) &&
- !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
- {
- *err = REG_ERPAREN;
- return NULL;
- }
- /* else fall through */
- case OP_CLOSE_DUP_NUM:
- /* We treat it as a normal character. */
-
- /* Then we can these characters as normal characters. */
- token->type = CHARACTER;
- /* mb_partial and word_char bits should be initialized already
- by peek_token. */
- tree = create_token_tree (dfa, NULL, NULL, token);
- if (BE (tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- break;
- case ANCHOR:
- if ((token->opr.ctx_type
- & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST))
- && dfa->word_ops_used == 0)
- init_word_char (dfa);
- if (token->opr.ctx_type == WORD_DELIM
- || token->opr.ctx_type == NOT_WORD_DELIM)
- {
- bin_tree_t *tree_first, *tree_last;
- if (token->opr.ctx_type == WORD_DELIM)
- {
- token->opr.ctx_type = WORD_FIRST;
- tree_first = create_token_tree (dfa, NULL, NULL, token);
- token->opr.ctx_type = WORD_LAST;
- }
- else
- {
- token->opr.ctx_type = INSIDE_WORD;
- tree_first = create_token_tree (dfa, NULL, NULL, token);
- token->opr.ctx_type = INSIDE_NOTWORD;
- }
- tree_last = create_token_tree (dfa, NULL, NULL, token);
- tree = create_tree (dfa, tree_first, tree_last, OP_ALT);
- if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- }
- else
- {
- tree = create_token_tree (dfa, NULL, NULL, token);
- if (BE (tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- }
- /* We must return here, since ANCHORs can't be followed
- by repetition operators.
- eg. RE"^*" is invalid or "<ANCHOR(^)><CHAR(*)>",
- it must not be "<ANCHOR(^)><REPEAT(*)>". */
- fetch_token (token, regexp, syntax);
- return tree;
- case OP_PERIOD:
- tree = create_token_tree (dfa, NULL, NULL, token);
- if (BE (tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- if (dfa->mb_cur_max > 1)
- dfa->has_mb_node = 1;
- break;
- case OP_WORD:
- case OP_NOTWORD:
- tree = build_charclass_op (dfa, regexp->trans,
- "alnum",
- "_",
- token->type == OP_NOTWORD, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
- break;
- case OP_SPACE:
- case OP_NOTSPACE:
- tree = build_charclass_op (dfa, regexp->trans,
- "space",
- "",
- token->type == OP_NOTSPACE, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
- break;
- case OP_ALT:
- case END_OF_RE:
- return NULL;
- case BACK_SLASH:
- *err = REG_EESCAPE;
- return NULL;
- default:
- /* Must not happen? */
-#ifdef DEBUG
- assert (0);
-#endif
- return NULL;
- }
- fetch_token (token, regexp, syntax);
-
- while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS
- || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM)
- {
- tree = parse_dup_op (tree, regexp, dfa, token, syntax, err);
- if (BE (*err != REG_NOERROR && tree == NULL, 0))
- return NULL;
- /* In BRE consecutive duplications are not allowed. */
- if ((syntax & RE_CONTEXT_INVALID_DUP)
- && (token->type == OP_DUP_ASTERISK
- || token->type == OP_OPEN_DUP_NUM))
- {
- *err = REG_BADRPT;
- return NULL;
- }
- }
-
- return tree;
-}
-
-/* This function build the following tree, from regular expression
- (<reg_exp>):
- SUBEXP
- |
- <reg_exp>
-*/
-
-static bin_tree_t *
-parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
- reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
-{
- re_dfa_t *dfa = preg->buffer;
- bin_tree_t *tree;
- size_t cur_nsub;
- cur_nsub = preg->re_nsub++;
-
- fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
-
- /* The subexpression may be a null string. */
- if (token->type == OP_CLOSE_SUBEXP)
- tree = NULL;
- else
- {
- tree = parse_reg_exp (regexp, preg, token, syntax, nest, err);
- if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0))
- {
- if (tree != NULL)
- postorder (tree, free_tree, NULL);
- *err = REG_EPAREN;
- }
- if (BE (*err != REG_NOERROR, 0))
- return NULL;
- }
-
- if (cur_nsub <= '9' - '1')
- dfa->completed_bkref_map |= 1 << cur_nsub;
-
- tree = create_tree (dfa, tree, NULL, SUBEXP);
- if (BE (tree == NULL, 0))
- {
- *err = REG_ESPACE;
- return NULL;
- }
- tree->token.opr.idx = cur_nsub;
- return tree;
-}
-
-/* This function parse repetition operators like "*", "+", "{1,3}" etc. */
-
-static bin_tree_t *
-parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
- re_token_t *token, reg_syntax_t syntax, reg_errcode_t *err)
-{
- bin_tree_t *tree = NULL, *old_tree = NULL;
- Idx i, start, end, start_idx = re_string_cur_idx (regexp);
- re_token_t start_token = *token;
-
- if (token->type == OP_OPEN_DUP_NUM)
- {
- end = 0;
- start = fetch_number (regexp, token, syntax);
- if (start == REG_MISSING)
- {
- if (token->type == CHARACTER && token->opr.c == ',')
- start = 0; /* We treat "{,m}" as "{0,m}". */
- else
- {
- *err = REG_BADBR; /* <re>{} is invalid. */
- return NULL;
- }
- }
- if (BE (start != REG_ERROR, 1))
- {
- /* We treat "{n}" as "{n,n}". */
- end = ((token->type == OP_CLOSE_DUP_NUM) ? start
- : ((token->type == CHARACTER && token->opr.c == ',')
- ? fetch_number (regexp, token, syntax) : REG_ERROR));
- }
- if (BE (start == REG_ERROR || end == REG_ERROR, 0))
- {
- /* Invalid sequence. */
- if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0))
- {
- if (token->type == END_OF_RE)
- *err = REG_EBRACE;
- else
- *err = REG_BADBR;
-
- return NULL;
- }
-
- /* If the syntax bit is set, rollback. */
- re_string_set_index (regexp, start_idx);
- *token = start_token;
- token->type = CHARACTER;
- /* mb_partial and word_char bits should be already initialized by
- peek_token. */
- return elem;
- }
-
- if (BE ((end != REG_MISSING && start > end)
- || token->type != OP_CLOSE_DUP_NUM, 0))
- {
- /* First number greater than second. */
- *err = REG_BADBR;
- return NULL;
- }
-
- if (BE (RE_DUP_MAX < (end == REG_MISSING ? start : end), 0))
- {
- *err = REG_ESIZE;
- return NULL;
- }
- }
- else
- {
- start = (token->type == OP_DUP_PLUS) ? 1 : 0;
- end = (token->type == OP_DUP_QUESTION) ? 1 : REG_MISSING;
- }
-
- fetch_token (token, regexp, syntax);
-
- if (BE (elem == NULL, 0))
- return NULL;
- if (BE (start == 0 && end == 0, 0))
- {
- postorder (elem, free_tree, NULL);
- return NULL;
- }
-
- /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */
- if (BE (start > 0, 0))
- {
- tree = elem;
- for (i = 2; i <= start; ++i)
- {
- elem = duplicate_tree (elem, dfa);
- tree = create_tree (dfa, tree, elem, CONCAT);
- if (BE (elem == NULL || tree == NULL, 0))
- goto parse_dup_op_espace;
- }
-
- if (start == end)
- return tree;
-
- /* Duplicate ELEM before it is marked optional. */
- elem = duplicate_tree (elem, dfa);
- old_tree = tree;
- }
- else
- old_tree = NULL;
-
- if (elem->token.type == SUBEXP)
- {
- uintptr_t subidx = elem->token.opr.idx;
- postorder (elem, mark_opt_subexp, (void *) subidx);
- }
-
- tree = create_tree (dfa, elem, NULL,
- (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT));
- if (BE (tree == NULL, 0))
- goto parse_dup_op_espace;
-
-/* From gnulib's "intprops.h":
- True if the arithmetic type T is signed. */
-#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
-
- /* This loop is actually executed only when end != REG_MISSING,
- to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have
- already created the start+1-th copy. */
- if (TYPE_SIGNED (Idx) || end != REG_MISSING)
- for (i = start + 2; i <= end; ++i)
- {
- elem = duplicate_tree (elem, dfa);
- tree = create_tree (dfa, tree, elem, CONCAT);
- if (BE (elem == NULL || tree == NULL, 0))
- goto parse_dup_op_espace;
-
- tree = create_tree (dfa, tree, NULL, OP_ALT);
- if (BE (tree == NULL, 0))
- goto parse_dup_op_espace;
- }
-
- if (old_tree)
- tree = create_tree (dfa, old_tree, tree, CONCAT);
-
- return tree;
-
- parse_dup_op_espace:
- *err = REG_ESPACE;
- return NULL;
-}
-
-/* Size of the names for collating symbol/equivalence_class/character_class.
- I'm not sure, but maybe enough. */
-#define BRACKET_NAME_BUF_SIZE 32
-
-#ifndef _LIBC
- /* Local function for parse_bracket_exp only used in case of NOT _LIBC.
- Build the range expression which starts from START_ELEM, and ends
- at END_ELEM. The result are written to MBCSET and SBCSET.
- RANGE_ALLOC is the allocated size of mbcset->range_starts, and
- mbcset->range_ends, is a pointer argument since we may
- update it. */
-
-static reg_errcode_t
-internal_function
-# ifdef RE_ENABLE_I18N
-build_range_exp (const reg_syntax_t syntax,
- bitset_t sbcset,
- re_charset_t *mbcset,
- Idx *range_alloc,
- const bracket_elem_t *start_elem,
- const bracket_elem_t *end_elem)
-# else /* not RE_ENABLE_I18N */
-build_range_exp (const reg_syntax_t syntax,
- bitset_t sbcset,
- const bracket_elem_t *start_elem,
- const bracket_elem_t *end_elem)
-# endif /* not RE_ENABLE_I18N */
-{
- unsigned int start_ch, end_ch;
- /* Equivalence Classes and Character Classes can't be a range start/end. */
- if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
- || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS,
- 0))
- return REG_ERANGE;
-
- /* We can handle no multi character collating elements without libc
- support. */
- if (BE ((start_elem->type == COLL_SYM
- && strlen ((char *) start_elem->opr.name) > 1)
- || (end_elem->type == COLL_SYM
- && strlen ((char *) end_elem->opr.name) > 1), 0))
- return REG_ECOLLATE;
-
-# ifdef RE_ENABLE_I18N
- {
- wchar_t wc;
- wint_t start_wc;
- wint_t end_wc;
-
- start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
- : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
- : 0));
- end_ch = ((end_elem->type == SB_CHAR) ? end_elem->opr.ch
- : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
- : 0));
- start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM)
- ? __btowc (start_ch) : start_elem->opr.wch);
- end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM)
- ? __btowc (end_ch) : end_elem->opr.wch);
- if (start_wc == WEOF || end_wc == WEOF)
- return REG_ECOLLATE;
- else if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc, 0))
- return REG_ERANGE;
-
- /* Got valid collation sequence values, add them as a new entry.
- However, for !_LIBC we have no collation elements: if the
- character set is single byte, the single byte character set
- that we build below suffices. parse_bracket_exp passes
- no MBCSET if dfa->mb_cur_max == 1. */
- if (mbcset)
- {
- /* Check the space of the arrays. */
- if (BE (*range_alloc == mbcset->nranges, 0))
- {
- /* There is not enough space, need realloc. */
- wchar_t *new_array_start, *new_array_end;
- Idx new_nranges;
-
- /* +1 in case of mbcset->nranges is 0. */
- new_nranges = 2 * mbcset->nranges + 1;
- /* Use realloc since mbcset->range_starts and mbcset->range_ends
- are NULL if *range_alloc == 0. */
- new_array_start = re_realloc (mbcset->range_starts, wchar_t,
- new_nranges);
- new_array_end = re_realloc (mbcset->range_ends, wchar_t,
- new_nranges);
-
- if (BE (new_array_start == NULL || new_array_end == NULL, 0))
- return REG_ESPACE;
-
- mbcset->range_starts = new_array_start;
- mbcset->range_ends = new_array_end;
- *range_alloc = new_nranges;
- }
-
- mbcset->range_starts[mbcset->nranges] = start_wc;
- mbcset->range_ends[mbcset->nranges++] = end_wc;
- }
-
- /* Build the table for single byte characters. */
- for (wc = 0; wc < SBC_MAX; ++wc)
- {
- if (start_wc <= wc && wc <= end_wc)
- bitset_set (sbcset, wc);
- }
- }
-# else /* not RE_ENABLE_I18N */
- {
- unsigned int ch;
- start_ch = ((start_elem->type == SB_CHAR ) ? start_elem->opr.ch
- : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
- : 0));
- end_ch = ((end_elem->type == SB_CHAR ) ? end_elem->opr.ch
- : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
- : 0));
- if (start_ch > end_ch)
- return REG_ERANGE;
- /* Build the table for single byte characters. */
- for (ch = 0; ch < SBC_MAX; ++ch)
- if (start_ch <= ch && ch <= end_ch)
- bitset_set (sbcset, ch);
- }
-# endif /* not RE_ENABLE_I18N */
- return REG_NOERROR;
-}
-#endif /* not _LIBC */
-
-#ifndef _LIBC
-/* Helper function for parse_bracket_exp only used in case of NOT _LIBC..
- Build the collating element which is represented by NAME.
- The result are written to MBCSET and SBCSET.
- COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
- pointer argument since we may update it. */
-
-static reg_errcode_t
-internal_function
-# ifdef RE_ENABLE_I18N
-build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
- Idx *coll_sym_alloc, const unsigned char *name)
-# else /* not RE_ENABLE_I18N */
-build_collating_symbol (bitset_t sbcset, const unsigned char *name)
-# endif /* not RE_ENABLE_I18N */
-{
- size_t name_len = strlen ((const char *) name);
- if (BE (name_len != 1, 0))
- return REG_ECOLLATE;
- else
- {
- bitset_set (sbcset, name[0]);
- return REG_NOERROR;
- }
-}
-#endif /* not _LIBC */
-
-/* This function parse bracket expression like "[abc]", "[a-c]",
- "[[.a-a.]]" etc. */
-
-static bin_tree_t *
-parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
- reg_syntax_t syntax, reg_errcode_t *err)
-{
-#ifdef _LIBC
- const unsigned char *collseqmb;
- const char *collseqwc;
- uint32_t nrules;
- int32_t table_size;
- const int32_t *symb_table;
- const unsigned char *extra;
-
- /* Local function for parse_bracket_exp used in _LIBC environment.
- Seek the collating symbol entry corresponding to NAME.
- Return the index of the symbol in the SYMB_TABLE,
- or -1 if not found. */
-
- auto inline int32_t
- __attribute__ ((always_inline))
- seek_collating_symbol_entry (const unsigned char *name, size_t name_len)
- {
- int32_t elem;
-
- for (elem = 0; elem < table_size; elem++)
- if (symb_table[2 * elem] != 0)
- {
- int32_t idx = symb_table[2 * elem + 1];
- /* Skip the name of collating element name. */
- idx += 1 + extra[idx];
- if (/* Compare the length of the name. */
- name_len == extra[idx]
- /* Compare the name. */
- && memcmp (name, &extra[idx + 1], name_len) == 0)
- /* Yep, this is the entry. */
- return elem;
- }
- return -1;
- }
-
- /* Local function for parse_bracket_exp used in _LIBC environment.
- Look up the collation sequence value of BR_ELEM.
- Return the value if succeeded, UINT_MAX otherwise. */
-
- auto inline unsigned int
- __attribute__ ((always_inline))
- lookup_collation_sequence_value (bracket_elem_t *br_elem)
- {
- if (br_elem->type == SB_CHAR)
- {
- /*
- if (MB_CUR_MAX == 1)
- */
- if (nrules == 0)
- return collseqmb[br_elem->opr.ch];
- else
- {
- wint_t wc = __btowc (br_elem->opr.ch);
- return __collseq_table_lookup (collseqwc, wc);
- }
- }
- else if (br_elem->type == MB_CHAR)
- {
- if (nrules != 0)
- return __collseq_table_lookup (collseqwc, br_elem->opr.wch);
- }
- else if (br_elem->type == COLL_SYM)
- {
- size_t sym_name_len = strlen ((char *) br_elem->opr.name);
- if (nrules != 0)
- {
- int32_t elem, idx;
- elem = seek_collating_symbol_entry (br_elem->opr.name,
- sym_name_len);
- if (elem != -1)
- {
- /* We found the entry. */
- idx = symb_table[2 * elem + 1];
- /* Skip the name of collating element name. */
- idx += 1 + extra[idx];
- /* Skip the byte sequence of the collating element. */
- idx += 1 + extra[idx];
- /* Adjust for the alignment. */
- idx = (idx + 3) & ~3;
- /* Skip the multibyte collation sequence value. */
- idx += sizeof (unsigned int);
- /* Skip the wide char sequence of the collating element. */
- idx += sizeof (unsigned int) *
- (1 + *(unsigned int *) (extra + idx));
- /* Return the collation sequence value. */
- return *(unsigned int *) (extra + idx);
- }
- else if (sym_name_len == 1)
- {
- /* No valid character. Match it as a single byte
- character. */
- return collseqmb[br_elem->opr.name[0]];
- }
- }
- else if (sym_name_len == 1)
- return collseqmb[br_elem->opr.name[0]];
- }
- return UINT_MAX;
- }
-
- /* Local function for parse_bracket_exp used in _LIBC environment.
- Build the range expression which starts from START_ELEM, and ends
- at END_ELEM. The result are written to MBCSET and SBCSET.
- RANGE_ALLOC is the allocated size of mbcset->range_starts, and
- mbcset->range_ends, is a pointer argument since we may
- update it. */
-
- auto inline reg_errcode_t
- __attribute__ ((always_inline))
- build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc,
- bracket_elem_t *start_elem, bracket_elem_t *end_elem)
- {
- unsigned int ch;
- uint32_t start_collseq;
- uint32_t end_collseq;
-
- /* Equivalence Classes and Character Classes can't be a range
- start/end. */
- if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
- || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS,
- 0))
- return REG_ERANGE;
-
- /* FIXME: Implement rational ranges here, too. */
- start_collseq = lookup_collation_sequence_value (start_elem);
- end_collseq = lookup_collation_sequence_value (end_elem);
- /* Check start/end collation sequence values. */
- if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0))
- return REG_ECOLLATE;
- if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
- return REG_ERANGE;
-
- /* Got valid collation sequence values, add them as a new entry.
- However, if we have no collation elements, and the character set
- is single byte, the single byte character set that we
- build below suffices. */
- if (nrules > 0 || dfa->mb_cur_max > 1)
- {
- /* Check the space of the arrays. */
- if (BE (*range_alloc == mbcset->nranges, 0))
- {
- /* There is not enough space, need realloc. */
- uint32_t *new_array_start;
- uint32_t *new_array_end;
- Idx new_nranges;
-
- /* +1 in case of mbcset->nranges is 0. */
- new_nranges = 2 * mbcset->nranges + 1;
- new_array_start = re_realloc (mbcset->range_starts, uint32_t,
- new_nranges);
- new_array_end = re_realloc (mbcset->range_ends, uint32_t,
- new_nranges);
-
- if (BE (new_array_start == NULL || new_array_end == NULL, 0))
- return REG_ESPACE;
-
- mbcset->range_starts = new_array_start;
- mbcset->range_ends = new_array_end;
- *range_alloc = new_nranges;
- }
-
- mbcset->range_starts[mbcset->nranges] = start_collseq;
- mbcset->range_ends[mbcset->nranges++] = end_collseq;
- }
-
- /* Build the table for single byte characters. */
- for (ch = 0; ch < SBC_MAX; ch++)
- {
- uint32_t ch_collseq;
- /*
- if (MB_CUR_MAX == 1)
- */
- if (nrules == 0)
- ch_collseq = collseqmb[ch];
- else
- ch_collseq = __collseq_table_lookup (collseqwc, __btowc (ch));
- if (start_collseq <= ch_collseq && ch_collseq <= end_collseq)
- bitset_set (sbcset, ch);
- }
- return REG_NOERROR;
- }
-
- /* Local function for parse_bracket_exp used in _LIBC environment.
- Build the collating element which is represented by NAME.
- The result are written to MBCSET and SBCSET.
- COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
- pointer argument since we may update it. */
-
- auto inline reg_errcode_t
- __attribute__ ((always_inline))
- build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
- Idx *coll_sym_alloc, const unsigned char *name)
- {
- int32_t elem, idx;
- size_t name_len = strlen ((const char *) name);
- if (nrules != 0)
- {
- elem = seek_collating_symbol_entry (name, name_len);
- if (elem != -1)
- {
- /* We found the entry. */
- idx = symb_table[2 * elem + 1];
- /* Skip the name of collating element name. */
- idx += 1 + extra[idx];
- }
- else if (name_len == 1)
- {
- /* No valid character, treat it as a normal
- character. */
- bitset_set (sbcset, name[0]);
- return REG_NOERROR;
- }
- else
- return REG_ECOLLATE;
-
- /* Got valid collation sequence, add it as a new entry. */
- /* Check the space of the arrays. */
- if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0))
- {
- /* Not enough, realloc it. */
- /* +1 in case of mbcset->ncoll_syms is 0. */
- Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
- /* Use realloc since mbcset->coll_syms is NULL
- if *alloc == 0. */
- int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
- new_coll_sym_alloc);
- if (BE (new_coll_syms == NULL, 0))
- return REG_ESPACE;
- mbcset->coll_syms = new_coll_syms;
- *coll_sym_alloc = new_coll_sym_alloc;
- }
- mbcset->coll_syms[mbcset->ncoll_syms++] = idx;
- return REG_NOERROR;
- }
- else
- {
- if (BE (name_len != 1, 0))
- return REG_ECOLLATE;
- else
- {
- bitset_set (sbcset, name[0]);
- return REG_NOERROR;
- }
- }
- }
-#endif
-
- re_token_t br_token;
- re_bitset_ptr_t sbcset;
-#ifdef RE_ENABLE_I18N
- re_charset_t *mbcset;
- Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0;
- Idx equiv_class_alloc = 0, char_class_alloc = 0;
-#endif /* not RE_ENABLE_I18N */
- bool non_match = false;
- bin_tree_t *work_tree;
- int token_len;
- bool first_round = true;
-#ifdef _LIBC
- collseqmb = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
- nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
- if (nrules)
- {
- /*
- if (MB_CUR_MAX > 1)
- */
- collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
- table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB);
- symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE,
- _NL_COLLATE_SYMB_TABLEMB);
- extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
- _NL_COLLATE_SYMB_EXTRAMB);
- }
-#endif
- sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
-#ifdef RE_ENABLE_I18N
- mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
-#endif /* RE_ENABLE_I18N */
-#ifdef RE_ENABLE_I18N
- if (BE (sbcset == NULL || mbcset == NULL, 0))
-#else
- if (BE (sbcset == NULL, 0))
-#endif /* RE_ENABLE_I18N */
- {
- re_free (sbcset);
-#ifdef RE_ENABLE_I18N
- re_free (mbcset);
-#endif
- *err = REG_ESPACE;
- return NULL;
- }
-
- token_len = peek_token_bracket (token, regexp, syntax);
- if (BE (token->type == END_OF_RE, 0))
- {
- *err = REG_BADPAT;
- goto parse_bracket_exp_free_return;
- }
- if (token->type == OP_NON_MATCH_LIST)
- {
-#ifdef RE_ENABLE_I18N
- mbcset->non_match = 1;
-#endif /* not RE_ENABLE_I18N */
- non_match = true;
- if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
- bitset_set (sbcset, '\n');
- re_string_skip_bytes (regexp, token_len); /* Skip a token. */
- token_len = peek_token_bracket (token, regexp, syntax);
- if (BE (token->type == END_OF_RE, 0))
- {
- *err = REG_BADPAT;
- goto parse_bracket_exp_free_return;
- }
- }
-
- /* We treat the first ']' as a normal character. */
- if (token->type == OP_CLOSE_BRACKET)
- token->type = CHARACTER;
-
- while (1)
- {
- bracket_elem_t start_elem, end_elem;
- unsigned char start_name_buf[BRACKET_NAME_BUF_SIZE];
- unsigned char end_name_buf[BRACKET_NAME_BUF_SIZE];
- reg_errcode_t ret;
- int token_len2 = 0;
- bool is_range_exp = false;
- re_token_t token2;
-
- start_elem.opr.name = start_name_buf;
- ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa,
- syntax, first_round);
- if (BE (ret != REG_NOERROR, 0))
- {
- *err = ret;
- goto parse_bracket_exp_free_return;
- }
- first_round = false;
-
- /* Get information about the next token. We need it in any case. */
- token_len = peek_token_bracket (token, regexp, syntax);
-
- /* Do not check for ranges if we know they are not allowed. */
- if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS)
- {
- if (BE (token->type == END_OF_RE, 0))
- {
- *err = REG_EBRACK;
- goto parse_bracket_exp_free_return;
- }
- if (token->type == OP_CHARSET_RANGE)
- {
- re_string_skip_bytes (regexp, token_len); /* Skip '-'. */
- token_len2 = peek_token_bracket (&token2, regexp, syntax);
- if (BE (token2.type == END_OF_RE, 0))
- {
- *err = REG_EBRACK;
- goto parse_bracket_exp_free_return;
- }
- if (token2.type == OP_CLOSE_BRACKET)
- {
- /* We treat the last '-' as a normal character. */
- re_string_skip_bytes (regexp, -token_len);
- token->type = CHARACTER;
- }
- else
- is_range_exp = true;
- }
- }
-
- if (is_range_exp == true)
- {
- end_elem.opr.name = end_name_buf;
- ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2,
- dfa, syntax, true);
- if (BE (ret != REG_NOERROR, 0))
- {
- *err = ret;
- goto parse_bracket_exp_free_return;
- }
-
- token_len = peek_token_bracket (token, regexp, syntax);
-
-#ifdef _LIBC
- *err = build_range_exp (sbcset, mbcset, &range_alloc,
- &start_elem, &end_elem);
-#else
-# ifdef RE_ENABLE_I18N
- *err = build_range_exp (syntax, sbcset,
- dfa->mb_cur_max > 1 ? mbcset : NULL,
- &range_alloc, &start_elem, &end_elem);
-# else
- *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem);
-# endif
-#endif /* RE_ENABLE_I18N */
- if (BE (*err != REG_NOERROR, 0))
- goto parse_bracket_exp_free_return;
- }
- else
- {
- switch (start_elem.type)
- {
- case SB_CHAR:
- bitset_set (sbcset, start_elem.opr.ch);
- break;
-#ifdef RE_ENABLE_I18N
- case MB_CHAR:
- /* Check whether the array has enough space. */
- if (BE (mbchar_alloc == mbcset->nmbchars, 0))
- {
- wchar_t *new_mbchars;
- /* Not enough, realloc it. */
- /* +1 in case of mbcset->nmbchars is 0. */
- mbchar_alloc = 2 * mbcset->nmbchars + 1;
- /* Use realloc since array is NULL if *alloc == 0. */
- new_mbchars = re_realloc (mbcset->mbchars, wchar_t,
- mbchar_alloc);
- if (BE (new_mbchars == NULL, 0))
- goto parse_bracket_exp_espace;
- mbcset->mbchars = new_mbchars;
- }
- mbcset->mbchars[mbcset->nmbchars++] = start_elem.opr.wch;
- break;
-#endif /* RE_ENABLE_I18N */
- case EQUIV_CLASS:
- *err = build_equiv_class (sbcset,
-#ifdef RE_ENABLE_I18N
- mbcset, &equiv_class_alloc,
-#endif /* RE_ENABLE_I18N */
- start_elem.opr.name);
- if (BE (*err != REG_NOERROR, 0))
- goto parse_bracket_exp_free_return;
- break;
- case COLL_SYM:
- *err = build_collating_symbol (sbcset,
-#ifdef RE_ENABLE_I18N
- mbcset, &coll_sym_alloc,
-#endif /* RE_ENABLE_I18N */
- start_elem.opr.name);
- if (BE (*err != REG_NOERROR, 0))
- goto parse_bracket_exp_free_return;
- break;
- case CHAR_CLASS:
- *err = build_charclass (regexp->trans, sbcset,
-#ifdef RE_ENABLE_I18N
- mbcset, &char_class_alloc,
-#endif /* RE_ENABLE_I18N */
- (const char *) start_elem.opr.name,
- syntax);
- if (BE (*err != REG_NOERROR, 0))
- goto parse_bracket_exp_free_return;
- break;
- default:
- assert (0);
- break;
- }
- }
- if (BE (token->type == END_OF_RE, 0))
- {
- *err = REG_EBRACK;
- goto parse_bracket_exp_free_return;
- }
- if (token->type == OP_CLOSE_BRACKET)
- break;
- }
-
- re_string_skip_bytes (regexp, token_len); /* Skip a token. */
-
- /* If it is non-matching list. */
- if (non_match)
- bitset_not (sbcset);
-
-#ifdef RE_ENABLE_I18N
- /* Ensure only single byte characters are set. */
- if (dfa->mb_cur_max > 1)
- bitset_mask (sbcset, dfa->sb_char);
-
- if (mbcset->nmbchars || mbcset->ncoll_syms || mbcset->nequiv_classes
- || mbcset->nranges || (dfa->mb_cur_max > 1 && (mbcset->nchar_classes
- || mbcset->non_match)))
- {
- bin_tree_t *mbc_tree;
- int sbc_idx;
- /* Build a tree for complex bracket. */
- dfa->has_mb_node = 1;
- br_token.type = COMPLEX_BRACKET;
- br_token.opr.mbcset = mbcset;
- mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
- if (BE (mbc_tree == NULL, 0))
- goto parse_bracket_exp_espace;
- for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx)
- if (sbcset[sbc_idx])
- break;
- /* If there are no bits set in sbcset, there is no point
- of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */
- if (sbc_idx < BITSET_WORDS)
- {
- /* Build a tree for simple bracket. */
- br_token.type = SIMPLE_BRACKET;
- br_token.opr.sbcset = sbcset;
- work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
- if (BE (work_tree == NULL, 0))
- goto parse_bracket_exp_espace;
-
- /* Then join them by ALT node. */
- work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT);
- if (BE (work_tree == NULL, 0))
- goto parse_bracket_exp_espace;
- }
- else
- {
- re_free (sbcset);
- work_tree = mbc_tree;
- }
- }
- else
-#endif /* not RE_ENABLE_I18N */
- {
-#ifdef RE_ENABLE_I18N
- free_charset (mbcset);
-#endif
- /* Build a tree for simple bracket. */
- br_token.type = SIMPLE_BRACKET;
- br_token.opr.sbcset = sbcset;
- work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
- if (BE (work_tree == NULL, 0))
- goto parse_bracket_exp_espace;
- }
- return work_tree;
-
- parse_bracket_exp_espace:
- *err = REG_ESPACE;
- parse_bracket_exp_free_return:
- re_free (sbcset);
-#ifdef RE_ENABLE_I18N
- free_charset (mbcset);
-#endif /* RE_ENABLE_I18N */
- return NULL;
-}
-
-/* Parse an element in the bracket expression. */
-
-static reg_errcode_t
-parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
- re_token_t *token, int token_len, re_dfa_t *dfa,
- reg_syntax_t syntax, bool accept_hyphen)
-{
-#ifdef RE_ENABLE_I18N
- int cur_char_size;
- cur_char_size = re_string_char_size_at (regexp, re_string_cur_idx (regexp));
- if (cur_char_size > 1)
- {
- elem->type = MB_CHAR;
- elem->opr.wch = re_string_wchar_at (regexp, re_string_cur_idx (regexp));
- re_string_skip_bytes (regexp, cur_char_size);
- return REG_NOERROR;
- }
-#endif /* RE_ENABLE_I18N */
- re_string_skip_bytes (regexp, token_len); /* Skip a token. */
- if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS
- || token->type == OP_OPEN_EQUIV_CLASS)
- return parse_bracket_symbol (elem, regexp, token);
- if (BE (token->type == OP_CHARSET_RANGE, 0) && !accept_hyphen)
- {
- /* A '-' must only appear as anything but a range indicator before
- the closing bracket. Everything else is an error. */
- re_token_t token2;
- (void) peek_token_bracket (&token2, regexp, syntax);
- if (token2.type != OP_CLOSE_BRACKET)
- /* The actual error value is not standardized since this whole
- case is undefined. But ERANGE makes good sense. */
- return REG_ERANGE;
- }
- elem->type = SB_CHAR;
- elem->opr.ch = token->opr.c;
- return REG_NOERROR;
-}
-
-/* Parse a bracket symbol in the bracket expression. Bracket symbols are
- such as [:<character_class>:], [.<collating_element>.], and
- [=<equivalent_class>=]. */
-
-static reg_errcode_t
-parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
- re_token_t *token)
-{
- unsigned char ch, delim = token->opr.c;
- int i = 0;
- if (re_string_eoi(regexp))
- return REG_EBRACK;
- for (;; ++i)
- {
- if (i >= BRACKET_NAME_BUF_SIZE)
- return REG_EBRACK;
- if (token->type == OP_OPEN_CHAR_CLASS)
- ch = re_string_fetch_byte_case (regexp);
- else
- ch = re_string_fetch_byte (regexp);
- if (re_string_eoi(regexp))
- return REG_EBRACK;
- if (ch == delim && re_string_peek_byte (regexp, 0) == ']')
- break;
- elem->opr.name[i] = ch;
- }
- re_string_skip_bytes (regexp, 1);
- elem->opr.name[i] = '\0';
- switch (token->type)
- {
- case OP_OPEN_COLL_ELEM:
- elem->type = COLL_SYM;
- break;
- case OP_OPEN_EQUIV_CLASS:
- elem->type = EQUIV_CLASS;
- break;
- case OP_OPEN_CHAR_CLASS:
- elem->type = CHAR_CLASS;
- break;
- default:
- break;
- }
- return REG_NOERROR;
-}
-
- /* Helper function for parse_bracket_exp.
- Build the equivalence class which is represented by NAME.
- The result are written to MBCSET and SBCSET.
- EQUIV_CLASS_ALLOC is the allocated size of mbcset->equiv_classes,
- is a pointer argument since we may update it. */
-
-static reg_errcode_t
-#ifdef RE_ENABLE_I18N
-build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
- Idx *equiv_class_alloc, const unsigned char *name)
-#else /* not RE_ENABLE_I18N */
-build_equiv_class (bitset_t sbcset, const unsigned char *name)
-#endif /* not RE_ENABLE_I18N */
-{
-#ifdef _LIBC
- uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
- if (nrules != 0)
- {
- const int32_t *table, *indirect;
- const unsigned char *weights, *extra, *cp;
- unsigned char char_buf[2];
- int32_t idx1, idx2;
- unsigned int ch;
- size_t len;
- /* This #include defines a local function! */
-# include <locale/weight.h>
- /* Calculate the index for equivalence class. */
- cp = name;
- table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
- weights = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
- _NL_COLLATE_WEIGHTMB);
- extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
- _NL_COLLATE_EXTRAMB);
- indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
- _NL_COLLATE_INDIRECTMB);
- idx1 = findidx (&cp, -1);
- if (BE (idx1 == 0 || *cp != '\0', 0))
- /* This isn't a valid character. */
- return REG_ECOLLATE;
-
- /* Build single byte matching table for this equivalence class. */
- len = weights[idx1 & 0xffffff];
- for (ch = 0; ch < SBC_MAX; ++ch)
- {
- char_buf[0] = ch;
- cp = char_buf;
- idx2 = findidx (&cp, 1);
-/*
- idx2 = table[ch];
-*/
- if (idx2 == 0)
- /* This isn't a valid character. */
- continue;
- /* Compare only if the length matches and the collation rule
- index is the same. */
- if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24))
- {
- int cnt = 0;
-
- while (cnt <= len &&
- weights[(idx1 & 0xffffff) + 1 + cnt]
- == weights[(idx2 & 0xffffff) + 1 + cnt])
- ++cnt;
-
- if (cnt > len)
- bitset_set (sbcset, ch);
- }
- }
- /* Check whether the array has enough space. */
- if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0))
- {
- /* Not enough, realloc it. */
- /* +1 in case of mbcset->nequiv_classes is 0. */
- Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1;
- /* Use realloc since the array is NULL if *alloc == 0. */
- int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
- int32_t,
- new_equiv_class_alloc);
- if (BE (new_equiv_classes == NULL, 0))
- return REG_ESPACE;
- mbcset->equiv_classes = new_equiv_classes;
- *equiv_class_alloc = new_equiv_class_alloc;
- }
- mbcset->equiv_classes[mbcset->nequiv_classes++] = idx1;
- }
- else
-#endif /* _LIBC */
- {
- if (BE (strlen ((const char *) name) != 1, 0))
- return REG_ECOLLATE;
- bitset_set (sbcset, *name);
- }
- return REG_NOERROR;
-}
-
- /* Helper function for parse_bracket_exp.
- Build the character class which is represented by NAME.
- The result are written to MBCSET and SBCSET.
- CHAR_CLASS_ALLOC is the allocated size of mbcset->char_classes,
- is a pointer argument since we may update it. */
-
-static reg_errcode_t
-#ifdef RE_ENABLE_I18N
-build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
- re_charset_t *mbcset, Idx *char_class_alloc,
- const char *class_name, reg_syntax_t syntax)
-#else /* not RE_ENABLE_I18N */
-build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
- const char *class_name, reg_syntax_t syntax)
-#endif /* not RE_ENABLE_I18N */
-{
- int i;
- const char *name = class_name;
-
- /* In case of REG_ICASE "upper" and "lower" match the both of
- upper and lower cases. */
- if ((syntax & RE_ICASE)
- && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0))
- name = "alpha";
-
-#ifdef RE_ENABLE_I18N
- /* Check the space of the arrays. */
- if (BE (*char_class_alloc == mbcset->nchar_classes, 0))
- {
- /* Not enough, realloc it. */
- /* +1 in case of mbcset->nchar_classes is 0. */
- Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1;
- /* Use realloc since array is NULL if *alloc == 0. */
- wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
- new_char_class_alloc);
- if (BE (new_char_classes == NULL, 0))
- return REG_ESPACE;
- mbcset->char_classes = new_char_classes;
- *char_class_alloc = new_char_class_alloc;
- }
- mbcset->char_classes[mbcset->nchar_classes++] = __wctype (name);
-#endif /* RE_ENABLE_I18N */
-
-#define BUILD_CHARCLASS_LOOP(ctype_func) \
- do { \
- if (BE (trans != NULL, 0)) \
- { \
- for (i = 0; i < SBC_MAX; ++i) \
- if (ctype_func (i)) \
- bitset_set (sbcset, trans[i]); \
- } \
- else \
- { \
- for (i = 0; i < SBC_MAX; ++i) \
- if (ctype_func (i)) \
- bitset_set (sbcset, i); \
- } \
- } while (0)
-
- if (strcmp (name, "alnum") == 0)
- BUILD_CHARCLASS_LOOP (isalnum);
- else if (strcmp (name, "cntrl") == 0)
- BUILD_CHARCLASS_LOOP (iscntrl);
- else if (strcmp (name, "lower") == 0)
- BUILD_CHARCLASS_LOOP (islower);
- else if (strcmp (name, "space") == 0)
- BUILD_CHARCLASS_LOOP (isspace);
- else if (strcmp (name, "alpha") == 0)
- BUILD_CHARCLASS_LOOP (isalpha);
- else if (strcmp (name, "digit") == 0)
- BUILD_CHARCLASS_LOOP (isdigit);
- else if (strcmp (name, "print") == 0)
- BUILD_CHARCLASS_LOOP (isprint);
- else if (strcmp (name, "upper") == 0)
- BUILD_CHARCLASS_LOOP (isupper);
- else if (strcmp (name, "blank") == 0)
- BUILD_CHARCLASS_LOOP (isblank);
- else if (strcmp (name, "graph") == 0)
- BUILD_CHARCLASS_LOOP (isgraph);
- else if (strcmp (name, "punct") == 0)
- BUILD_CHARCLASS_LOOP (ispunct);
- else if (strcmp (name, "xdigit") == 0)
- BUILD_CHARCLASS_LOOP (isxdigit);
- else
- return REG_ECTYPE;
-
- return REG_NOERROR;
-}
-
-static bin_tree_t *
-build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
- const char *class_name,
- const char *extra, bool non_match,
- reg_errcode_t *err)
-{
- re_bitset_ptr_t sbcset;
-#ifdef RE_ENABLE_I18N
- re_charset_t *mbcset;
- Idx alloc = 0;
-#endif /* not RE_ENABLE_I18N */
- reg_errcode_t ret;
- re_token_t br_token;
- bin_tree_t *tree;
-
- sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
-#ifdef RE_ENABLE_I18N
- mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
-#endif /* RE_ENABLE_I18N */
-
-#ifdef RE_ENABLE_I18N
- if (BE (sbcset == NULL || mbcset == NULL, 0))
-#else /* not RE_ENABLE_I18N */
- if (BE (sbcset == NULL, 0))
-#endif /* not RE_ENABLE_I18N */
- {
- *err = REG_ESPACE;
- return NULL;
- }
-
- if (non_match)
- {
-#ifdef RE_ENABLE_I18N
- mbcset->non_match = 1;
-#endif /* not RE_ENABLE_I18N */
- }
-
- /* We don't care the syntax in this case. */
- ret = build_charclass (trans, sbcset,
-#ifdef RE_ENABLE_I18N
- mbcset, &alloc,
-#endif /* RE_ENABLE_I18N */
- class_name, 0);
-
- if (BE (ret != REG_NOERROR, 0))
- {
- re_free (sbcset);
-#ifdef RE_ENABLE_I18N
- free_charset (mbcset);
-#endif /* RE_ENABLE_I18N */
- *err = ret;
- return NULL;
- }
- /* \w match '_' also. */
- for (; *extra; extra++)
- bitset_set (sbcset, *extra);
-
- /* If it is non-matching list. */
- if (non_match)
- bitset_not (sbcset);
-
-#ifdef RE_ENABLE_I18N
- /* Ensure only single byte characters are set. */
- if (dfa->mb_cur_max > 1)
- bitset_mask (sbcset, dfa->sb_char);
-#endif
-
- /* Build a tree for simple bracket. */
- br_token.type = SIMPLE_BRACKET;
- br_token.opr.sbcset = sbcset;
- tree = create_token_tree (dfa, NULL, NULL, &br_token);
- if (BE (tree == NULL, 0))
- goto build_word_op_espace;
-
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- {
- bin_tree_t *mbc_tree;
- /* Build a tree for complex bracket. */
- br_token.type = COMPLEX_BRACKET;
- br_token.opr.mbcset = mbcset;
- dfa->has_mb_node = 1;
- mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
- if (BE (mbc_tree == NULL, 0))
- goto build_word_op_espace;
- /* Then join them by ALT node. */
- tree = create_tree (dfa, tree, mbc_tree, OP_ALT);
- if (BE (mbc_tree != NULL, 1))
- return tree;
- }
- else
- {
- free_charset (mbcset);
- return tree;
- }
-#else /* not RE_ENABLE_I18N */
- return tree;
-#endif /* not RE_ENABLE_I18N */
-
- build_word_op_espace:
- re_free (sbcset);
-#ifdef RE_ENABLE_I18N
- free_charset (mbcset);
-#endif /* RE_ENABLE_I18N */
- *err = REG_ESPACE;
- return NULL;
-}
-
-/* This is intended for the expressions like "a{1,3}".
- Fetch a number from 'input', and return the number.
- Return REG_MISSING if the number field is empty like "{,1}".
- Return RE_DUP_MAX + 1 if the number field is too large.
- Return REG_ERROR if an error occurred. */
-
-static Idx
-fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
-{
- Idx num = REG_MISSING;
- unsigned char c;
- while (1)
- {
- fetch_token (token, input, syntax);
- c = token->opr.c;
- if (BE (token->type == END_OF_RE, 0))
- return REG_ERROR;
- if (token->type == OP_CLOSE_DUP_NUM || c == ',')
- break;
- num = ((token->type != CHARACTER || c < '0' || '9' < c
- || num == REG_ERROR)
- ? REG_ERROR
- : num == REG_MISSING
- ? c - '0'
- : MIN (RE_DUP_MAX + 1, num * 10 + c - '0'));
- }
- return num;
-}
-
-#ifdef RE_ENABLE_I18N
-static void
-free_charset (re_charset_t *cset)
-{
- re_free (cset->mbchars);
-# ifdef _LIBC
- re_free (cset->coll_syms);
- re_free (cset->equiv_classes);
- re_free (cset->range_starts);
- re_free (cset->range_ends);
-# endif
- re_free (cset->char_classes);
- re_free (cset);
-}
-#endif /* RE_ENABLE_I18N */
-
-/* Functions for binary tree operation. */
-
-/* Create a tree node. */
-
-static bin_tree_t *
-create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
- re_token_type_t type)
-{
- re_token_t t;
- t.type = type;
- return create_token_tree (dfa, left, right, &t);
-}
-
-static bin_tree_t *
-create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
- const re_token_t *token)
-{
- bin_tree_t *tree;
- if (BE (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE, 0))
- {
- bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1);
-
- if (storage == NULL)
- return NULL;
- storage->next = dfa->str_tree_storage;
- dfa->str_tree_storage = storage;
- dfa->str_tree_storage_idx = 0;
- }
- tree = &dfa->str_tree_storage->data[dfa->str_tree_storage_idx++];
-
- tree->parent = NULL;
- tree->left = left;
- tree->right = right;
- tree->token = *token;
- tree->token.duplicated = 0;
- tree->token.opt_subexp = 0;
- tree->first = NULL;
- tree->next = NULL;
- tree->node_idx = REG_MISSING;
-
- if (left != NULL)
- left->parent = tree;
- if (right != NULL)
- right->parent = tree;
- return tree;
-}
-
-/* Mark the tree SRC as an optional subexpression.
- To be called from preorder or postorder. */
-
-static reg_errcode_t
-mark_opt_subexp (void *extra, bin_tree_t *node)
-{
- Idx idx = (uintptr_t) extra;
- if (node->token.type == SUBEXP && node->token.opr.idx == idx)
- node->token.opt_subexp = 1;
-
- return REG_NOERROR;
-}
-
-/* Free the allocated memory inside NODE. */
-
-static void
-free_token (re_token_t *node)
-{
-#ifdef RE_ENABLE_I18N
- if (node->type == COMPLEX_BRACKET && node->duplicated == 0)
- free_charset (node->opr.mbcset);
- else
-#endif /* RE_ENABLE_I18N */
- if (node->type == SIMPLE_BRACKET && node->duplicated == 0)
- re_free (node->opr.sbcset);
-}
-
-/* Worker function for tree walking. Free the allocated memory inside NODE
- and its children. */
-
-static reg_errcode_t
-free_tree (void *extra, bin_tree_t *node)
-{
- free_token (&node->token);
- return REG_NOERROR;
-}
-
-
-/* Duplicate the node SRC, and return new node. This is a preorder
- visit similar to the one implemented by the generic visitor, but
- we need more infrastructure to maintain two parallel trees --- so,
- it's easier to duplicate. */
-
-static bin_tree_t *
-duplicate_tree (const bin_tree_t *root, re_dfa_t *dfa)
-{
- const bin_tree_t *node;
- bin_tree_t *dup_root;
- bin_tree_t **p_new = &dup_root, *dup_node = root->parent;
-
- for (node = root; ; )
- {
- /* Create a new tree and link it back to the current parent. */
- *p_new = create_token_tree (dfa, NULL, NULL, &node->token);
- if (*p_new == NULL)
- return NULL;
- (*p_new)->parent = dup_node;
- (*p_new)->token.duplicated = 1;
- dup_node = *p_new;
-
- /* Go to the left node, or up and to the right. */
- if (node->left)
- {
- node = node->left;
- p_new = &dup_node->left;
- }
- else
- {
- const bin_tree_t *prev = NULL;
- while (node->right == prev || node->right == NULL)
- {
- prev = node;
- node = node->parent;
- dup_node = dup_node->parent;
- if (!node)
- return dup_root;
- }
- node = node->right;
- p_new = &dup_node->right;
- }
- }
-}
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
+ size_t length, reg_syntax_t syntax);
+static void re_compile_fastmap_iter (regex_t *bufp,
+ const re_dfastate_t *init_state,
+ char *fastmap);
+static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len);
+#ifdef RE_ENABLE_I18N
+static void free_charset (re_charset_t *cset);
+#endif /* RE_ENABLE_I18N */
+static void free_workarea_compile (regex_t *preg);
+static reg_errcode_t create_initial_state (re_dfa_t *dfa);
+#ifdef RE_ENABLE_I18N
+static void optimize_utf8 (re_dfa_t *dfa);
+#endif
+static reg_errcode_t analyze (regex_t *preg);
+static reg_errcode_t preorder (bin_tree_t *root,
+ reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra);
+static reg_errcode_t postorder (bin_tree_t *root,
+ reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra);
+static reg_errcode_t optimize_subexps (void *extra, bin_tree_t *node);
+static reg_errcode_t lower_subexps (void *extra, bin_tree_t *node);
+static bin_tree_t *lower_subexp (reg_errcode_t *err, regex_t *preg,
+ bin_tree_t *node);
+static reg_errcode_t calc_first (void *extra, bin_tree_t *node);
+static reg_errcode_t calc_next (void *extra, bin_tree_t *node);
+static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node);
+static Idx duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint);
+static Idx search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
+ unsigned int constraint);
+static reg_errcode_t calc_eclosure (re_dfa_t *dfa);
+static reg_errcode_t calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa,
+ Idx node, bool root);
+static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
+static Idx fetch_number (re_string_t *input, re_token_t *token,
+ reg_syntax_t syntax);
+static int peek_token (re_token_t *token, re_string_t *input,
+ reg_syntax_t syntax) internal_function;
+static bin_tree_t *parse (re_string_t *regexp, regex_t *preg,
+ reg_syntax_t syntax, reg_errcode_t *err);
+static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_branch (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_expression (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_sub_exp (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_dup_op (bin_tree_t *dup_elem, re_string_t *regexp,
+ re_dfa_t *dfa, re_token_t *token,
+ reg_syntax_t syntax, reg_errcode_t *err);
+static bin_tree_t *parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa,
+ re_token_t *token, reg_syntax_t syntax,
+ reg_errcode_t *err);
+static reg_errcode_t parse_bracket_element (bracket_elem_t *elem,
+ re_string_t *regexp,
+ re_token_t *token, int token_len,
+ re_dfa_t *dfa,
+ reg_syntax_t syntax,
+ bool accept_hyphen);
+static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
+ re_string_t *regexp,
+ re_token_t *token);
+#ifdef RE_ENABLE_I18N
+static reg_errcode_t build_equiv_class (bitset_t sbcset,
+ re_charset_t *mbcset,
+ Idx *equiv_class_alloc,
+ const unsigned char *name);
+static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
+ bitset_t sbcset,
+ re_charset_t *mbcset,
+ Idx *char_class_alloc,
+ const char *class_name,
+ reg_syntax_t syntax);
+#else /* not RE_ENABLE_I18N */
+static reg_errcode_t build_equiv_class (bitset_t sbcset,
+ const unsigned char *name);
+static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
+ bitset_t sbcset,
+ const char *class_name,
+ reg_syntax_t syntax);
+#endif /* not RE_ENABLE_I18N */
+static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
+ RE_TRANSLATE_TYPE trans,
+ const char *class_name,
+ const char *extra,
+ bool non_match, reg_errcode_t *err);
+static bin_tree_t *create_tree (re_dfa_t *dfa,
+ bin_tree_t *left, bin_tree_t *right,
+ re_token_type_t type);
+static bin_tree_t *create_token_tree (re_dfa_t *dfa,
+ bin_tree_t *left, bin_tree_t *right,
+ const re_token_t *token);
+static bin_tree_t *duplicate_tree (const bin_tree_t *src, re_dfa_t *dfa);
+static void free_token (re_token_t *node);
+static reg_errcode_t free_tree (void *extra, bin_tree_t *node);
+static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node);
+
+/* This table gives an error message for each of the error codes listed
+ in regex.h. Obviously the order here has to be same as there.
+ POSIX doesn't require that we do anything for REG_NOERROR,
+ but why not be nice? */
+
+static const char __re_error_msgid[] =
+ {
+#define REG_NOERROR_IDX 0
+ gettext_noop ("Success") /* REG_NOERROR */
+ "\0"
+#define REG_NOMATCH_IDX (REG_NOERROR_IDX + sizeof "Success")
+ gettext_noop ("No match") /* REG_NOMATCH */
+ "\0"
+#define REG_BADPAT_IDX (REG_NOMATCH_IDX + sizeof "No match")
+ gettext_noop ("Invalid regular expression") /* REG_BADPAT */
+ "\0"
+#define REG_ECOLLATE_IDX (REG_BADPAT_IDX + sizeof "Invalid regular expression")
+ gettext_noop ("Invalid collation character") /* REG_ECOLLATE */
+ "\0"
+#define REG_ECTYPE_IDX (REG_ECOLLATE_IDX + sizeof "Invalid collation character")
+ gettext_noop ("Invalid character class name") /* REG_ECTYPE */
+ "\0"
+#define REG_EESCAPE_IDX (REG_ECTYPE_IDX + sizeof "Invalid character class name")
+ gettext_noop ("Trailing backslash") /* REG_EESCAPE */
+ "\0"
+#define REG_ESUBREG_IDX (REG_EESCAPE_IDX + sizeof "Trailing backslash")
+ gettext_noop ("Invalid back reference") /* REG_ESUBREG */
+ "\0"
+#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference")
+ gettext_noop ("Unmatched [ or [^") /* REG_EBRACK */
+ "\0"
+#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^")
+ gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */
+ "\0"
+#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")
+ gettext_noop ("Unmatched \\{") /* REG_EBRACE */
+ "\0"
+#define REG_BADBR_IDX (REG_EBRACE_IDX + sizeof "Unmatched \\{")
+ gettext_noop ("Invalid content of \\{\\}") /* REG_BADBR */
+ "\0"
+#define REG_ERANGE_IDX (REG_BADBR_IDX + sizeof "Invalid content of \\{\\}")
+ gettext_noop ("Invalid range end") /* REG_ERANGE */
+ "\0"
+#define REG_ESPACE_IDX (REG_ERANGE_IDX + sizeof "Invalid range end")
+ gettext_noop ("Memory exhausted") /* REG_ESPACE */
+ "\0"
+#define REG_BADRPT_IDX (REG_ESPACE_IDX + sizeof "Memory exhausted")
+ gettext_noop ("Invalid preceding regular expression") /* REG_BADRPT */
+ "\0"
+#define REG_EEND_IDX (REG_BADRPT_IDX + sizeof "Invalid preceding regular expression")
+ gettext_noop ("Premature end of regular expression") /* REG_EEND */
+ "\0"
+#define REG_ESIZE_IDX (REG_EEND_IDX + sizeof "Premature end of regular expression")
+ gettext_noop ("Regular expression too big") /* REG_ESIZE */
+ "\0"
+#define REG_ERPAREN_IDX (REG_ESIZE_IDX + sizeof "Regular expression too big")
+ gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */
+ };
+
+static const size_t __re_error_msgid_idx[] =
+ {
+ REG_NOERROR_IDX,
+ REG_NOMATCH_IDX,
+ REG_BADPAT_IDX,
+ REG_ECOLLATE_IDX,
+ REG_ECTYPE_IDX,
+ REG_EESCAPE_IDX,
+ REG_ESUBREG_IDX,
+ REG_EBRACK_IDX,
+ REG_EPAREN_IDX,
+ REG_EBRACE_IDX,
+ REG_BADBR_IDX,
+ REG_ERANGE_IDX,
+ REG_ESPACE_IDX,
+ REG_BADRPT_IDX,
+ REG_EEND_IDX,
+ REG_ESIZE_IDX,
+ REG_ERPAREN_IDX
+ };
+
+/* Entry points for GNU code. */
+
+/* re_compile_pattern is the GNU regular expression compiler: it
+ compiles PATTERN (of length LENGTH) and puts the result in BUFP.
+ Returns 0 if the pattern was valid, otherwise an error string.
+
+ Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields
+ are set in BUFP on entry. */
+
+#ifdef _LIBC
+const char *
+re_compile_pattern (pattern, length, bufp)
+ const char *pattern;
+ size_t length;
+ struct re_pattern_buffer *bufp;
+#else /* size_t might promote */
+const char *
+re_compile_pattern (const char *pattern, size_t length,
+ struct re_pattern_buffer *bufp)
+#endif
+{
+ reg_errcode_t ret;
+
+ /* And GNU code determines whether or not to get register information
+ by passing null for the REGS argument to re_match, etc., not by
+ setting no_sub, unless RE_NO_SUB is set. */
+ bufp->no_sub = !!(re_syntax_options & RE_NO_SUB);
+
+ /* Match anchors at newline. */
+ bufp->newline_anchor = 1;
+
+ ret = re_compile_internal (bufp, pattern, length, re_syntax_options);
+
+ if (!ret)
+ return NULL;
+ return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
+}
+#ifdef _LIBC
+weak_alias (__re_compile_pattern, re_compile_pattern)
+#endif
+
+/* Set by 're_set_syntax' to the current regexp syntax to recognize. Can
+ also be assigned to arbitrarily: each pattern buffer stores its own
+ syntax, so it can be changed between regex compilations. */
+/* This has no initializer because initialized variables in Emacs
+ become read-only after dumping. */
+reg_syntax_t re_syntax_options;
+
+
+/* Specify the precise syntax of regexps for compilation. This provides
+ for compatibility for various utilities which historically have
+ different, incompatible syntaxes.
+
+ The argument SYNTAX is a bit mask comprised of the various bits
+ defined in regex.h. We return the old syntax. */
+
+reg_syntax_t
+re_set_syntax (syntax)
+ reg_syntax_t syntax;
+{
+ reg_syntax_t ret = re_syntax_options;
+
+ re_syntax_options = syntax;
+ return ret;
+}
+#ifdef _LIBC
+weak_alias (__re_set_syntax, re_set_syntax)
+#endif
+
+int
+re_compile_fastmap (bufp)
+ struct re_pattern_buffer *bufp;
+{
+ re_dfa_t *dfa = bufp->buffer;
+ char *fastmap = bufp->fastmap;
+
+ memset (fastmap, '\0', sizeof (char) * SBC_MAX);
+ re_compile_fastmap_iter (bufp, dfa->init_state, fastmap);
+ if (dfa->init_state != dfa->init_state_word)
+ re_compile_fastmap_iter (bufp, dfa->init_state_word, fastmap);
+ if (dfa->init_state != dfa->init_state_nl)
+ re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap);
+ if (dfa->init_state != dfa->init_state_begbuf)
+ re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap);
+ bufp->fastmap_accurate = 1;
+ return 0;
+}
+#ifdef _LIBC
+weak_alias (__re_compile_fastmap, re_compile_fastmap)
+#endif
+
+static inline void
+__attribute__ ((always_inline))
+re_set_fastmap (char *fastmap, bool icase, int ch)
+{
+ fastmap[ch] = 1;
+ if (icase)
+ fastmap[tolower (ch)] = 1;
+}
+
+/* Helper function for re_compile_fastmap.
+ Compile fastmap for the initial_state INIT_STATE. */
+
+static void
+re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
+ char *fastmap)
+{
+ re_dfa_t *dfa = bufp->buffer;
+ Idx node_cnt;
+ bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
+ for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
+ {
+ Idx node = init_state->nodes.elems[node_cnt];
+ re_token_type_t type = dfa->nodes[node].type;
+
+ if (type == CHARACTER)
+ {
+ re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
+#ifdef RE_ENABLE_I18N
+ if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
+ {
+ unsigned char buf[MB_LEN_MAX];
+ unsigned char *p;
+ wchar_t wc;
+ mbstate_t state;
+
+ p = buf;
+ *p++ = dfa->nodes[node].opr.c;
+ while (++node < dfa->nodes_len
+ && dfa->nodes[node].type == CHARACTER
+ && dfa->nodes[node].mb_partial)
+ *p++ = dfa->nodes[node].opr.c;
+ memset (&state, '\0', sizeof (state));
+ if (__mbrtowc (&wc, (const char *) buf, p - buf,
+ &state) == p - buf
+ && (__wcrtomb ((char *) buf, towlower (wc), &state)
+ != (size_t) -1))
+ re_set_fastmap (fastmap, false, buf[0]);
+ }
+#endif
+ }
+ else if (type == SIMPLE_BRACKET)
+ {
+ int i, ch;
+ for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
+ {
+ int j;
+ bitset_word_t w = dfa->nodes[node].opr.sbcset[i];
+ for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+ if (w & ((bitset_word_t) 1 << j))
+ re_set_fastmap (fastmap, icase, ch);
+ }
+ }
+#ifdef RE_ENABLE_I18N
+ else if (type == COMPLEX_BRACKET)
+ {
+ re_charset_t *cset = dfa->nodes[node].opr.mbcset;
+ Idx i;
+
+# ifdef _LIBC
+ /* See if we have to try all bytes which start multiple collation
+ elements.
+ e.g. In da_DK, we want to catch 'a' since "aa" is a valid
+ collation element, and don't catch 'b' since 'b' is
+ the only collation element which starts from 'b' (and
+ it is caught by SIMPLE_BRACKET). */
+ if (_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES) != 0
+ && (cset->ncoll_syms || cset->nranges))
+ {
+ const int32_t *table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ for (i = 0; i < SBC_MAX; ++i)
+ if (table[i] < 0)
+ re_set_fastmap (fastmap, icase, i);
+ }
+# endif /* _LIBC */
+
+ /* See if we have to start the match at all multibyte characters,
+ i.e. where we would not find an invalid sequence. This only
+ applies to multibyte character sets; for single byte character
+ sets, the SIMPLE_BRACKET again suffices. */
+ if (dfa->mb_cur_max > 1
+ && (cset->nchar_classes || cset->non_match || cset->nranges
+# ifdef _LIBC
+ || cset->nequiv_classes
+# endif /* _LIBC */
+ ))
+ {
+ unsigned char c = 0;
+ do
+ {
+ mbstate_t mbs;
+ memset (&mbs, 0, sizeof (mbs));
+ if (__mbrtowc (NULL, (char *) &c, 1, &mbs) == (size_t) -2)
+ re_set_fastmap (fastmap, false, (int) c);
+ }
+ while (++c != 0);
+ }
+
+ else
+ {
+ /* ... Else catch all bytes which can start the mbchars. */
+ for (i = 0; i < cset->nmbchars; ++i)
+ {
+ char buf[256];
+ mbstate_t state;
+ memset (&state, '\0', sizeof (state));
+ if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1)
+ re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
+ if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
+ {
+ if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state)
+ != (size_t) -1)
+ re_set_fastmap (fastmap, false, *(unsigned char *) buf);
+ }
+ }
+ }
+ }
+#endif /* RE_ENABLE_I18N */
+ else if (type == OP_PERIOD
+#ifdef RE_ENABLE_I18N
+ || type == OP_UTF8_PERIOD
+#endif /* RE_ENABLE_I18N */
+ || type == END_OF_RE)
+ {
+ memset (fastmap, '\1', sizeof (char) * SBC_MAX);
+ if (type == END_OF_RE)
+ bufp->can_be_null = 1;
+ return;
+ }
+ }
+}
+
+/* Entry point for POSIX code. */
+/* regcomp takes a regular expression as a string and compiles it.
+
+ PREG is a regex_t *. We do not expect any fields to be initialized,
+ since POSIX says we shouldn't. Thus, we set
+
+ 'buffer' to the compiled pattern;
+ 'used' to the length of the compiled pattern;
+ 'syntax' to RE_SYNTAX_POSIX_EXTENDED if the
+ REG_EXTENDED bit in CFLAGS is set; otherwise, to
+ RE_SYNTAX_POSIX_BASIC;
+ 'newline_anchor' to REG_NEWLINE being set in CFLAGS;
+ 'fastmap' to an allocated space for the fastmap;
+ 'fastmap_accurate' to zero;
+ 're_nsub' to the number of subexpressions in PATTERN.
+
+ PATTERN is the address of the pattern string.
+
+ CFLAGS is a series of bits which affect compilation.
+
+ If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
+ use POSIX basic syntax.
+
+ If REG_NEWLINE is set, then . and [^...] don't match newline.
+ Also, regexec will try a match beginning after every newline.
+
+ If REG_ICASE is set, then we considers upper- and lowercase
+ versions of letters to be equivalent when matching.
+
+ If REG_NOSUB is set, then when PREG is passed to regexec, that
+ routine will report only success or failure, and nothing about the
+ registers.
+
+ It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
+ the return codes and their meanings.) */
+
+int
+regcomp (preg, pattern, cflags)
+ regex_t *_Restrict_ preg;
+ const char *_Restrict_ pattern;
+ int cflags;
+{
+ reg_errcode_t ret;
+ reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
+ : RE_SYNTAX_POSIX_BASIC);
+
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ preg->used = 0;
+
+ /* Try to allocate space for the fastmap. */
+ preg->fastmap = re_malloc (char, SBC_MAX);
+ if (BE (preg->fastmap == NULL, 0))
+ return REG_ESPACE;
+
+ syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
+
+ /* If REG_NEWLINE is set, newlines are treated differently. */
+ if (cflags & REG_NEWLINE)
+ { /* REG_NEWLINE implies neither . nor [^...] match newline. */
+ syntax &= ~RE_DOT_NEWLINE;
+ syntax |= RE_HAT_LISTS_NOT_NEWLINE;
+ /* It also changes the matching behavior. */
+ preg->newline_anchor = 1;
+ }
+ else
+ preg->newline_anchor = 0;
+ preg->no_sub = !!(cflags & REG_NOSUB);
+ preg->translate = NULL;
+
+ ret = re_compile_internal (preg, pattern, strlen (pattern), syntax);
+
+ /* POSIX doesn't distinguish between an unmatched open-group and an
+ unmatched close-group: both are REG_EPAREN. */
+ if (ret == REG_ERPAREN)
+ ret = REG_EPAREN;
+
+ /* We have already checked preg->fastmap != NULL. */
+ if (BE (ret == REG_NOERROR, 1))
+ /* Compute the fastmap now, since regexec cannot modify the pattern
+ buffer. This function never fails in this implementation. */
+ (void) re_compile_fastmap (preg);
+ else
+ {
+ /* Some error occurred while compiling the expression. */
+ re_free (preg->fastmap);
+ preg->fastmap = NULL;
+ }
+
+ return (int) ret;
+}
+#ifdef _LIBC
+weak_alias (__regcomp, regcomp)
+#endif
+
+/* Returns a message corresponding to an error code, ERRCODE, returned
+ from either regcomp or regexec. We don't use PREG here. */
+
+#ifdef _LIBC
+size_t
+regerror (errcode, preg, errbuf, errbuf_size)
+ int errcode;
+ const regex_t *_Restrict_ preg;
+ char *_Restrict_ errbuf;
+ size_t errbuf_size;
+#else /* size_t might promote */
+size_t
+regerror (int errcode, const regex_t *_Restrict_ preg,
+ char *_Restrict_ errbuf, size_t errbuf_size)
+#endif
+{
+ const char *msg;
+ size_t msg_size;
+
+ if (BE (errcode < 0
+ || errcode >= (int) (sizeof (__re_error_msgid_idx)
+ / sizeof (__re_error_msgid_idx[0])), 0))
+ /* Only error codes returned by the rest of the code should be passed
+ to this routine. If we are given anything else, or if other regex
+ code generates an invalid error code, then the program has a bug.
+ Dump core so we can fix it. */
+ abort ();
+
+ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]);
+
+ msg_size = strlen (msg) + 1; /* Includes the null. */
+
+ if (BE (errbuf_size != 0, 1))
+ {
+ size_t cpy_size = msg_size;
+ if (BE (msg_size > errbuf_size, 0))
+ {
+ cpy_size = errbuf_size - 1;
+ errbuf[cpy_size] = '\0';
+ }
+ memcpy (errbuf, msg, cpy_size);
+ }
+
+ return msg_size;
+}
+#ifdef _LIBC
+weak_alias (__regerror, regerror)
+#endif
+
+
+#ifdef RE_ENABLE_I18N
+/* This static array is used for the map to single-byte characters when
+ UTF-8 is used. Otherwise we would allocate memory just to initialize
+ it the same all the time. UTF-8 is the preferred encoding so this is
+ a worthwhile optimization. */
+static const bitset_t utf8_sb_map =
+{
+ /* Set the first 128 bits. */
+# if defined __GNUC__ && !defined __STRICT_ANSI__
+ [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX
+# else
+# if 4 * BITSET_WORD_BITS < ASCII_CHARS
+# error "bitset_word_t is narrower than 32 bits"
+# elif 3 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX,
+# elif 2 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX, BITSET_WORD_MAX,
+# elif 1 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX,
+# endif
+ (BITSET_WORD_MAX
+ >> (SBC_MAX % BITSET_WORD_BITS == 0
+ ? 0
+ : BITSET_WORD_BITS - SBC_MAX % BITSET_WORD_BITS))
+# endif
+};
+#endif
+
+
+static void
+free_dfa_content (re_dfa_t *dfa)
+{
+ Idx i, j;
+
+ if (dfa->nodes)
+ for (i = 0; i < dfa->nodes_len; ++i)
+ free_token (dfa->nodes + i);
+ re_free (dfa->nexts);
+ for (i = 0; i < dfa->nodes_len; ++i)
+ {
+ if (dfa->eclosures != NULL)
+ re_node_set_free (dfa->eclosures + i);
+ if (dfa->inveclosures != NULL)
+ re_node_set_free (dfa->inveclosures + i);
+ if (dfa->edests != NULL)
+ re_node_set_free (dfa->edests + i);
+ }
+ re_free (dfa->edests);
+ re_free (dfa->eclosures);
+ re_free (dfa->inveclosures);
+ re_free (dfa->nodes);
+
+ if (dfa->state_table)
+ for (i = 0; i <= dfa->state_hash_mask; ++i)
+ {
+ struct re_state_table_entry *entry = dfa->state_table + i;
+ for (j = 0; j < entry->num; ++j)
+ {
+ re_dfastate_t *state = entry->array[j];
+ free_state (state);
+ }
+ re_free (entry->array);
+ }
+ re_free (dfa->state_table);
+#ifdef RE_ENABLE_I18N
+ if (dfa->sb_char != utf8_sb_map)
+ re_free (dfa->sb_char);
+#endif
+ re_free (dfa->subexp_map);
+#ifdef DEBUG
+ re_free (dfa->re_str);
+#endif
+
+ re_free (dfa);
+}
+
+
+/* Free dynamically allocated space used by PREG. */
+
+void
+regfree (preg)
+ regex_t *preg;
+{
+ re_dfa_t *dfa = preg->buffer;
+ if (BE (dfa != NULL, 1))
+ {
+ lock_fini (dfa->lock);
+ free_dfa_content (dfa);
+ }
+ preg->buffer = NULL;
+ preg->allocated = 0;
+
+ re_free (preg->fastmap);
+ preg->fastmap = NULL;
+
+ re_free (preg->translate);
+ preg->translate = NULL;
+}
+#ifdef _LIBC
+weak_alias (__regfree, regfree)
+#endif
+
+/* Entry points compatible with 4.2 BSD regex library. We don't define
+ them unless specifically requested. */
+
+#if defined _REGEX_RE_COMP || defined _LIBC
+
+/* BSD has one and only one pattern buffer. */
+static struct re_pattern_buffer re_comp_buf;
+
+char *
+# ifdef _LIBC
+/* Make these definitions weak in libc, so POSIX programs can redefine
+ these names if they don't use our functions, and still use
+ regcomp/regexec above without link errors. */
+weak_function
+# endif
+re_comp (s)
+ const char *s;
+{
+ reg_errcode_t ret;
+ char *fastmap;
+
+ if (!s)
+ {
+ if (!re_comp_buf.buffer)
+ return gettext ("No previous regular expression");
+ return 0;
+ }
+
+ if (re_comp_buf.buffer)
+ {
+ fastmap = re_comp_buf.fastmap;
+ re_comp_buf.fastmap = NULL;
+ __regfree (&re_comp_buf);
+ memset (&re_comp_buf, '\0', sizeof (re_comp_buf));
+ re_comp_buf.fastmap = fastmap;
+ }
+
+ if (re_comp_buf.fastmap == NULL)
+ {
+ re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
+ if (re_comp_buf.fastmap == NULL)
+ return (char *) gettext (__re_error_msgid
+ + __re_error_msgid_idx[(int) REG_ESPACE]);
+ }
+
+ /* Since 're_exec' always passes NULL for the 'regs' argument, we
+ don't need to initialize the pattern buffer fields which affect it. */
+
+ /* Match anchors at newlines. */
+ re_comp_buf.newline_anchor = 1;
+
+ ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options);
+
+ if (!ret)
+ return NULL;
+
+ /* Yes, we're discarding 'const' here if !HAVE_LIBINTL. */
+ return (char *) gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
+}
+
+#ifdef _LIBC
+libc_freeres_fn (free_mem)
+{
+ __regfree (&re_comp_buf);
+}
+#endif
+
+#endif /* _REGEX_RE_COMP */
+
+/* Internal entry point.
+ Compile the regular expression PATTERN, whose length is LENGTH.
+ SYNTAX indicate regular expression's syntax. */
+
+static reg_errcode_t
+re_compile_internal (regex_t *preg, const char * pattern, size_t length,
+ reg_syntax_t syntax)
+{
+ reg_errcode_t err = REG_NOERROR;
+ re_dfa_t *dfa;
+ re_string_t regexp;
+
+ /* Initialize the pattern buffer. */
+ preg->fastmap_accurate = 0;
+ preg->syntax = syntax;
+ preg->not_bol = preg->not_eol = 0;
+ preg->used = 0;
+ preg->re_nsub = 0;
+ preg->can_be_null = 0;
+ preg->regs_allocated = REGS_UNALLOCATED;
+
+ /* Initialize the dfa. */
+ dfa = preg->buffer;
+ if (BE (preg->allocated < sizeof (re_dfa_t), 0))
+ {
+ /* If zero allocated, but buffer is non-null, try to realloc
+ enough space. This loses if buffer's address is bogus, but
+ that is the user's responsibility. If ->buffer is NULL this
+ is a simple allocation. */
+ dfa = re_realloc (preg->buffer, re_dfa_t, 1);
+ if (dfa == NULL)
+ return REG_ESPACE;
+ preg->allocated = sizeof (re_dfa_t);
+ preg->buffer = dfa;
+ }
+ preg->used = sizeof (re_dfa_t);
+
+ err = init_dfa (dfa, length);
+ if (BE (err == REG_NOERROR && lock_init (dfa->lock) != 0, 0))
+ err = REG_ESPACE;
+ if (BE (err != REG_NOERROR, 0))
+ {
+ free_dfa_content (dfa);
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ return err;
+ }
+#ifdef DEBUG
+ /* Note: length+1 will not overflow since it is checked in init_dfa. */
+ dfa->re_str = re_malloc (char, length + 1);
+ strncpy (dfa->re_str, pattern, length + 1);
+#endif
+
+ err = re_string_construct (&regexp, pattern, length, preg->translate,
+ (syntax & RE_ICASE) != 0, dfa);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_compile_internal_free_return:
+ free_workarea_compile (preg);
+ re_string_destruct (&regexp);
+ lock_fini (dfa->lock);
+ free_dfa_content (dfa);
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ return err;
+ }
+
+ /* Parse the regular expression, and build a structure tree. */
+ preg->re_nsub = 0;
+ dfa->str_tree = parse (&regexp, preg, syntax, &err);
+ if (BE (dfa->str_tree == NULL, 0))
+ goto re_compile_internal_free_return;
+
+ /* Analyze the tree and create the nfa. */
+ err = analyze (preg);
+ if (BE (err != REG_NOERROR, 0))
+ goto re_compile_internal_free_return;
+
+#ifdef RE_ENABLE_I18N
+ /* If possible, do searching in single byte encoding to speed things up. */
+ if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL)
+ optimize_utf8 (dfa);
+#endif
+
+ /* Then create the initial state of the dfa. */
+ err = create_initial_state (dfa);
+
+ /* Release work areas. */
+ free_workarea_compile (preg);
+ re_string_destruct (&regexp);
+
+ if (BE (err != REG_NOERROR, 0))
+ {
+ lock_fini (dfa->lock);
+ free_dfa_content (dfa);
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ }
+
+ return err;
+}
+
+/* Initialize DFA. We use the length of the regular expression PAT_LEN
+ as the initial length of some arrays. */
+
+static reg_errcode_t
+init_dfa (re_dfa_t *dfa, size_t pat_len)
+{
+ __re_size_t table_size;
+#ifndef _LIBC
+ const char *codeset_name;
+#endif
+#ifdef RE_ENABLE_I18N
+ size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
+#else
+ size_t max_i18n_object_size = 0;
+#endif
+ size_t max_object_size =
+ MAX (sizeof (struct re_state_table_entry),
+ MAX (sizeof (re_token_t),
+ MAX (sizeof (re_node_set),
+ MAX (sizeof (regmatch_t),
+ max_i18n_object_size))));
+
+ memset (dfa, '\0', sizeof (re_dfa_t));
+
+ /* Force allocation of str_tree_storage the first time. */
+ dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
+
+ /* Avoid overflows. The extra "/ 2" is for the table_size doubling
+ calculation below, and for similar doubling calculations
+ elsewhere. And it's <= rather than <, because some of the
+ doubling calculations add 1 afterwards. */
+ if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2 <= pat_len, 0))
+ return REG_ESPACE;
+
+ dfa->nodes_alloc = pat_len + 1;
+ dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
+
+ /* table_size = 2 ^ ceil(log pat_len) */
+ for (table_size = 1; ; table_size <<= 1)
+ if (table_size > pat_len)
+ break;
+
+ dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
+ dfa->state_hash_mask = table_size - 1;
+
+ dfa->mb_cur_max = MB_CUR_MAX;
+#ifdef _LIBC
+ if (dfa->mb_cur_max == 6
+ && strcmp (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_CODESET_NAME), "UTF-8") == 0)
+ dfa->is_utf8 = 1;
+ dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII)
+ != 0);
+#else
+ codeset_name = nl_langinfo (CODESET);
+ if ((codeset_name[0] == 'U' || codeset_name[0] == 'u')
+ && (codeset_name[1] == 'T' || codeset_name[1] == 't')
+ && (codeset_name[2] == 'F' || codeset_name[2] == 'f')
+ && strcmp (codeset_name + 3 + (codeset_name[3] == '-'), "8") == 0)
+ dfa->is_utf8 = 1;
+
+ /* We check exhaustively in the loop below if this charset is a
+ superset of ASCII. */
+ dfa->map_notascii = 0;
+#endif
+
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ if (dfa->is_utf8)
+ dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map;
+ else
+ {
+ int i, j, ch;
+
+ dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
+ if (BE (dfa->sb_char == NULL, 0))
+ return REG_ESPACE;
+
+ /* Set the bits corresponding to single byte chars. */
+ for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
+ for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+ {
+ wint_t wch = __btowc (ch);
+ if (wch != WEOF)
+ dfa->sb_char[i] |= (bitset_word_t) 1 << j;
+# ifndef _LIBC
+ if (isascii (ch) && wch != ch)
+ dfa->map_notascii = 1;
+# endif
+ }
+ }
+ }
+#endif
+
+ if (BE (dfa->nodes == NULL || dfa->state_table == NULL, 0))
+ return REG_ESPACE;
+ return REG_NOERROR;
+}
+
+/* Initialize WORD_CHAR table, which indicate which character is
+ "word". In this case "word" means that it is the word construction
+ character used by some operators like "\<", "\>", etc. */
+
+static void
+internal_function
+init_word_char (re_dfa_t *dfa)
+{
+ int i = 0;
+ int j;
+ int ch = 0;
+ dfa->word_ops_used = 1;
+ if (BE (dfa->map_notascii == 0, 1))
+ {
+ bitset_word_t bits0 = 0x00000000;
+ bitset_word_t bits1 = 0x03ff0000;
+ bitset_word_t bits2 = 0x87fffffe;
+ bitset_word_t bits3 = 0x07fffffe;
+ if (BITSET_WORD_BITS == 64)
+ {
+ dfa->word_char[0] = bits1 << 31 << 1 | bits0;
+ dfa->word_char[1] = bits3 << 31 << 1 | bits2;
+ i = 2;
+ }
+ else if (BITSET_WORD_BITS == 32)
+ {
+ dfa->word_char[0] = bits0;
+ dfa->word_char[1] = bits1;
+ dfa->word_char[2] = bits2;
+ dfa->word_char[3] = bits3;
+ i = 4;
+ }
+ else
+ goto general_case;
+ ch = 128;
+
+ if (BE (dfa->is_utf8, 1))
+ {
+ memset (&dfa->word_char[i], '\0', (SBC_MAX - ch) / 8);
+ return;
+ }
+ }
+
+ general_case:
+ for (; i < BITSET_WORDS; ++i)
+ for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+ if (isalnum (ch) || ch == '_')
+ dfa->word_char[i] |= (bitset_word_t) 1 << j;
+}
+
+/* Free the work area which are only used while compiling. */
+
+static void
+free_workarea_compile (regex_t *preg)
+{
+ re_dfa_t *dfa = preg->buffer;
+ bin_tree_storage_t *storage, *next;
+ for (storage = dfa->str_tree_storage; storage; storage = next)
+ {
+ next = storage->next;
+ re_free (storage);
+ }
+ dfa->str_tree_storage = NULL;
+ dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
+ dfa->str_tree = NULL;
+ re_free (dfa->org_indices);
+ dfa->org_indices = NULL;
+}
+
+/* Create initial states for all contexts. */
+
+static reg_errcode_t
+create_initial_state (re_dfa_t *dfa)
+{
+ Idx first, i;
+ reg_errcode_t err;
+ re_node_set init_nodes;
+
+ /* Initial states have the epsilon closure of the node which is
+ the first node of the regular expression. */
+ first = dfa->str_tree->first->node_idx;
+ dfa->init_node = first;
+ err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* The back-references which are in initial states can epsilon transit,
+ since in this case all of the subexpressions can be null.
+ Then we add epsilon closures of the nodes which are the next nodes of
+ the back-references. */
+ if (dfa->nbackref > 0)
+ for (i = 0; i < init_nodes.nelem; ++i)
+ {
+ Idx node_idx = init_nodes.elems[i];
+ re_token_type_t type = dfa->nodes[node_idx].type;
+
+ Idx clexp_idx;
+ if (type != OP_BACK_REF)
+ continue;
+ for (clexp_idx = 0; clexp_idx < init_nodes.nelem; ++clexp_idx)
+ {
+ re_token_t *clexp_node;
+ clexp_node = dfa->nodes + init_nodes.elems[clexp_idx];
+ if (clexp_node->type == OP_CLOSE_SUBEXP
+ && clexp_node->opr.idx == dfa->nodes[node_idx].opr.idx)
+ break;
+ }
+ if (clexp_idx == init_nodes.nelem)
+ continue;
+
+ if (type == OP_BACK_REF)
+ {
+ Idx dest_idx = dfa->edests[node_idx].elems[0];
+ if (!re_node_set_contains (&init_nodes, dest_idx))
+ {
+ reg_errcode_t merge_err
+ = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx);
+ if (merge_err != REG_NOERROR)
+ return merge_err;
+ i = 0;
+ }
+ }
+ }
+
+ /* It must be the first time to invoke acquire_state. */
+ dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0);
+ /* We don't check ERR here, since the initial state must not be NULL. */
+ if (BE (dfa->init_state == NULL, 0))
+ return err;
+ if (dfa->init_state->has_constraint)
+ {
+ dfa->init_state_word = re_acquire_state_context (&err, dfa, &init_nodes,
+ CONTEXT_WORD);
+ dfa->init_state_nl = re_acquire_state_context (&err, dfa, &init_nodes,
+ CONTEXT_NEWLINE);
+ dfa->init_state_begbuf = re_acquire_state_context (&err, dfa,
+ &init_nodes,
+ CONTEXT_NEWLINE
+ | CONTEXT_BEGBUF);
+ if (BE (dfa->init_state_word == NULL || dfa->init_state_nl == NULL
+ || dfa->init_state_begbuf == NULL, 0))
+ return err;
+ }
+ else
+ dfa->init_state_word = dfa->init_state_nl
+ = dfa->init_state_begbuf = dfa->init_state;
+
+ re_node_set_free (&init_nodes);
+ return REG_NOERROR;
+}
+
+#ifdef RE_ENABLE_I18N
+/* If it is possible to do searching in single byte encoding instead of UTF-8
+ to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change
+ DFA nodes where needed. */
+
+static void
+optimize_utf8 (re_dfa_t *dfa)
+{
+ Idx node;
+ int i;
+ bool mb_chars = false;
+ bool has_period = false;
+
+ for (node = 0; node < dfa->nodes_len; ++node)
+ switch (dfa->nodes[node].type)
+ {
+ case CHARACTER:
+ if (dfa->nodes[node].opr.c >= ASCII_CHARS)
+ mb_chars = true;
+ break;
+ case ANCHOR:
+ switch (dfa->nodes[node].opr.ctx_type)
+ {
+ case LINE_FIRST:
+ case LINE_LAST:
+ case BUF_FIRST:
+ case BUF_LAST:
+ break;
+ default:
+ /* Word anchors etc. cannot be handled. It's okay to test
+ opr.ctx_type since constraints (for all DFA nodes) are
+ created by ORing one or more opr.ctx_type values. */
+ return;
+ }
+ break;
+ case OP_PERIOD:
+ has_period = true;
+ break;
+ case OP_BACK_REF:
+ case OP_ALT:
+ case END_OF_RE:
+ case OP_DUP_ASTERISK:
+ case OP_OPEN_SUBEXP:
+ case OP_CLOSE_SUBEXP:
+ break;
+ case COMPLEX_BRACKET:
+ return;
+ case SIMPLE_BRACKET:
+ /* Just double check. */
+ {
+ int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0
+ ? 0
+ : BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS);
+ for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
+ {
+ if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0)
+ return;
+ rshift = 0;
+ }
+ }
+ break;
+ default:
+ abort ();
+ }
+
+ if (mb_chars || has_period)
+ for (node = 0; node < dfa->nodes_len; ++node)
+ {
+ if (dfa->nodes[node].type == CHARACTER
+ && dfa->nodes[node].opr.c >= ASCII_CHARS)
+ dfa->nodes[node].mb_partial = 0;
+ else if (dfa->nodes[node].type == OP_PERIOD)
+ dfa->nodes[node].type = OP_UTF8_PERIOD;
+ }
+
+ /* The search can be in single byte locale. */
+ dfa->mb_cur_max = 1;
+ dfa->is_utf8 = 0;
+ dfa->has_mb_node = dfa->nbackref > 0 || has_period;
+}
+#endif
+
+/* Analyze the structure tree, and calculate "first", "next", "edest",
+ "eclosure", and "inveclosure". */
+
+static reg_errcode_t
+analyze (regex_t *preg)
+{
+ re_dfa_t *dfa = preg->buffer;
+ reg_errcode_t ret;
+
+ /* Allocate arrays. */
+ dfa->nexts = re_malloc (Idx, dfa->nodes_alloc);
+ dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
+ dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
+ dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
+ if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL
+ || dfa->eclosures == NULL, 0))
+ return REG_ESPACE;
+
+ dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
+ if (dfa->subexp_map != NULL)
+ {
+ Idx i;
+ for (i = 0; i < preg->re_nsub; i++)
+ dfa->subexp_map[i] = i;
+ preorder (dfa->str_tree, optimize_subexps, dfa);
+ for (i = 0; i < preg->re_nsub; i++)
+ if (dfa->subexp_map[i] != i)
+ break;
+ if (i == preg->re_nsub)
+ {
+ free (dfa->subexp_map);
+ dfa->subexp_map = NULL;
+ }
+ }
+
+ ret = postorder (dfa->str_tree, lower_subexps, preg);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ ret = postorder (dfa->str_tree, calc_first, dfa);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ preorder (dfa->str_tree, calc_next, dfa);
+ ret = preorder (dfa->str_tree, link_nfa_nodes, dfa);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ ret = calc_eclosure (dfa);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+
+ /* We only need this during the prune_impossible_nodes pass in regexec.c;
+ skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */
+ if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
+ || dfa->nbackref)
+ {
+ dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
+ if (BE (dfa->inveclosures == NULL, 0))
+ return REG_ESPACE;
+ ret = calc_inveclosure (dfa);
+ }
+
+ return ret;
+}
+
+/* Our parse trees are very unbalanced, so we cannot use a stack to
+ implement parse tree visits. Instead, we use parent pointers and
+ some hairy code in these two functions. */
+static reg_errcode_t
+postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra)
+{
+ bin_tree_t *node, *prev;
+
+ for (node = root; ; )
+ {
+ /* Descend down the tree, preferably to the left (or to the right
+ if that's the only child). */
+ while (node->left || node->right)
+ if (node->left)
+ node = node->left;
+ else
+ node = node->right;
+
+ do
+ {
+ reg_errcode_t err = fn (extra, node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ if (node->parent == NULL)
+ return REG_NOERROR;
+ prev = node;
+ node = node->parent;
+ }
+ /* Go up while we have a node that is reached from the right. */
+ while (node->right == prev || node->right == NULL);
+ node = node->right;
+ }
+}
+
+static reg_errcode_t
+preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra)
+{
+ bin_tree_t *node;
+
+ for (node = root; ; )
+ {
+ reg_errcode_t err = fn (extra, node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* Go to the left node, or up and to the right. */
+ if (node->left)
+ node = node->left;
+ else
+ {
+ bin_tree_t *prev = NULL;
+ while (node->right == prev || node->right == NULL)
+ {
+ prev = node;
+ node = node->parent;
+ if (!node)
+ return REG_NOERROR;
+ }
+ node = node->right;
+ }
+ }
+}
+
+/* Optimization pass: if a SUBEXP is entirely contained, strip it and tell
+ re_search_internal to map the inner one's opr.idx to this one's. Adjust
+ backreferences as well. Requires a preorder visit. */
+static reg_errcode_t
+optimize_subexps (void *extra, bin_tree_t *node)
+{
+ re_dfa_t *dfa = (re_dfa_t *) extra;
+
+ if (node->token.type == OP_BACK_REF && dfa->subexp_map)
+ {
+ int idx = node->token.opr.idx;
+ node->token.opr.idx = dfa->subexp_map[idx];
+ dfa->used_bkref_map |= 1 << node->token.opr.idx;
+ }
+
+ else if (node->token.type == SUBEXP
+ && node->left && node->left->token.type == SUBEXP)
+ {
+ Idx other_idx = node->left->token.opr.idx;
+
+ node->left = node->left->left;
+ if (node->left)
+ node->left->parent = node;
+
+ dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
+ if (other_idx < BITSET_WORD_BITS)
+ dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx);
+ }
+
+ return REG_NOERROR;
+}
+
+/* Lowering pass: Turn each SUBEXP node into the appropriate concatenation
+ of OP_OPEN_SUBEXP, the body of the SUBEXP (if any) and OP_CLOSE_SUBEXP. */
+static reg_errcode_t
+lower_subexps (void *extra, bin_tree_t *node)
+{
+ regex_t *preg = (regex_t *) extra;
+ reg_errcode_t err = REG_NOERROR;
+
+ if (node->left && node->left->token.type == SUBEXP)
+ {
+ node->left = lower_subexp (&err, preg, node->left);
+ if (node->left)
+ node->left->parent = node;
+ }
+ if (node->right && node->right->token.type == SUBEXP)
+ {
+ node->right = lower_subexp (&err, preg, node->right);
+ if (node->right)
+ node->right->parent = node;
+ }
+
+ return err;
+}
+
+static bin_tree_t *
+lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
+{
+ re_dfa_t *dfa = preg->buffer;
+ bin_tree_t *body = node->left;
+ bin_tree_t *op, *cls, *tree1, *tree;
+
+ if (preg->no_sub
+ /* We do not optimize empty subexpressions, because otherwise we may
+ have bad CONCAT nodes with NULL children. This is obviously not
+ very common, so we do not lose much. An example that triggers
+ this case is the sed "script" /\(\)/x. */
+ && node->left != NULL
+ && (node->token.opr.idx >= BITSET_WORD_BITS
+ || !(dfa->used_bkref_map
+ & ((bitset_word_t) 1 << node->token.opr.idx))))
+ return node->left;
+
+ /* Convert the SUBEXP node to the concatenation of an
+ OP_OPEN_SUBEXP, the contents, and an OP_CLOSE_SUBEXP. */
+ op = create_tree (dfa, NULL, NULL, OP_OPEN_SUBEXP);
+ cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP);
+ tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls;
+ tree = create_tree (dfa, op, tree1, CONCAT);
+ if (BE (tree == NULL || tree1 == NULL || op == NULL || cls == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ op->token.opr.idx = cls->token.opr.idx = node->token.opr.idx;
+ op->token.opt_subexp = cls->token.opt_subexp = node->token.opt_subexp;
+ return tree;
+}
+
+/* Pass 1 in building the NFA: compute FIRST and create unlinked automaton
+ nodes. Requires a postorder visit. */
+static reg_errcode_t
+calc_first (void *extra, bin_tree_t *node)
+{
+ re_dfa_t *dfa = (re_dfa_t *) extra;
+ if (node->token.type == CONCAT)
+ {
+ node->first = node->left->first;
+ node->node_idx = node->left->node_idx;
+ }
+ else
+ {
+ node->first = node;
+ node->node_idx = re_dfa_add_node (dfa, node->token);
+ if (BE (node->node_idx == REG_MISSING, 0))
+ return REG_ESPACE;
+ if (node->token.type == ANCHOR)
+ dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type;
+ }
+ return REG_NOERROR;
+}
+
+/* Pass 2: compute NEXT on the tree. Preorder visit. */
+static reg_errcode_t
+calc_next (void *extra, bin_tree_t *node)
+{
+ switch (node->token.type)
+ {
+ case OP_DUP_ASTERISK:
+ node->left->next = node;
+ break;
+ case CONCAT:
+ node->left->next = node->right->first;
+ node->right->next = node->next;
+ break;
+ default:
+ if (node->left)
+ node->left->next = node->next;
+ if (node->right)
+ node->right->next = node->next;
+ break;
+ }
+ return REG_NOERROR;
+}
+
+/* Pass 3: link all DFA nodes to their NEXT node (any order will do). */
+static reg_errcode_t
+link_nfa_nodes (void *extra, bin_tree_t *node)
+{
+ re_dfa_t *dfa = (re_dfa_t *) extra;
+ Idx idx = node->node_idx;
+ reg_errcode_t err = REG_NOERROR;
+
+ switch (node->token.type)
+ {
+ case CONCAT:
+ break;
+
+ case END_OF_RE:
+ assert (node->next == NULL);
+ break;
+
+ case OP_DUP_ASTERISK:
+ case OP_ALT:
+ {
+ Idx left, right;
+ dfa->has_plural_match = 1;
+ if (node->left != NULL)
+ left = node->left->first->node_idx;
+ else
+ left = node->next->node_idx;
+ if (node->right != NULL)
+ right = node->right->first->node_idx;
+ else
+ right = node->next->node_idx;
+ assert (REG_VALID_INDEX (left));
+ assert (REG_VALID_INDEX (right));
+ err = re_node_set_init_2 (dfa->edests + idx, left, right);
+ }
+ break;
+
+ case ANCHOR:
+ case OP_OPEN_SUBEXP:
+ case OP_CLOSE_SUBEXP:
+ err = re_node_set_init_1 (dfa->edests + idx, node->next->node_idx);
+ break;
+
+ case OP_BACK_REF:
+ dfa->nexts[idx] = node->next->node_idx;
+ if (node->token.type == OP_BACK_REF)
+ err = re_node_set_init_1 (dfa->edests + idx, dfa->nexts[idx]);
+ break;
+
+ default:
+ assert (!IS_EPSILON_NODE (node->token.type));
+ dfa->nexts[idx] = node->next->node_idx;
+ break;
+ }
+
+ return err;
+}
+
+/* Duplicate the epsilon closure of the node ROOT_NODE.
+ Note that duplicated nodes have constraint INIT_CONSTRAINT in addition
+ to their own constraint. */
+
+static reg_errcode_t
+internal_function
+duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
+ Idx root_node, unsigned int init_constraint)
+{
+ Idx org_node, clone_node;
+ bool ok;
+ unsigned int constraint = init_constraint;
+ for (org_node = top_org_node, clone_node = top_clone_node;;)
+ {
+ Idx org_dest, clone_dest;
+ if (dfa->nodes[org_node].type == OP_BACK_REF)
+ {
+ /* If the back reference epsilon-transit, its destination must
+ also have the constraint. Then duplicate the epsilon closure
+ of the destination of the back reference, and store it in
+ edests of the back reference. */
+ org_dest = dfa->nexts[org_node];
+ re_node_set_empty (dfa->edests + clone_node);
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ dfa->nexts[clone_node] = dfa->nexts[org_node];
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ else if (dfa->edests[org_node].nelem == 0)
+ {
+ /* In case of the node can't epsilon-transit, don't duplicate the
+ destination and store the original destination as the
+ destination of the node. */
+ dfa->nexts[clone_node] = dfa->nexts[org_node];
+ break;
+ }
+ else if (dfa->edests[org_node].nelem == 1)
+ {
+ /* In case of the node can epsilon-transit, and it has only one
+ destination. */
+ org_dest = dfa->edests[org_node].elems[0];
+ re_node_set_empty (dfa->edests + clone_node);
+ /* If the node is root_node itself, it means the epsilon closure
+ has a loop. Then tie it to the destination of the root_node. */
+ if (org_node == root_node && clone_node != org_node)
+ {
+ ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ break;
+ }
+ /* In case the node has another constraint, append it. */
+ constraint |= dfa->nodes[org_node].constraint;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ else /* dfa->edests[org_node].nelem == 2 */
+ {
+ /* In case of the node can epsilon-transit, and it has two
+ destinations. In the bin_tree_t and DFA, that's '|' and '*'. */
+ org_dest = dfa->edests[org_node].elems[0];
+ re_node_set_empty (dfa->edests + clone_node);
+ /* Search for a duplicated node which satisfies the constraint. */
+ clone_dest = search_duplicated_node (dfa, org_dest, constraint);
+ if (clone_dest == REG_MISSING)
+ {
+ /* There is no such duplicated node, create a new one. */
+ reg_errcode_t err;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ err = duplicate_node_closure (dfa, org_dest, clone_dest,
+ root_node, constraint);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ else
+ {
+ /* There is a duplicated node which satisfies the constraint,
+ use it to avoid infinite loop. */
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+
+ org_dest = dfa->edests[org_node].elems[1];
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ org_node = org_dest;
+ clone_node = clone_dest;
+ }
+ return REG_NOERROR;
+}
+
+/* Search for a node which is duplicated from the node ORG_NODE, and
+ satisfies the constraint CONSTRAINT. */
+
+static Idx
+search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
+ unsigned int constraint)
+{
+ Idx idx;
+ for (idx = dfa->nodes_len - 1; dfa->nodes[idx].duplicated && idx > 0; --idx)
+ {
+ if (org_node == dfa->org_indices[idx]
+ && constraint == dfa->nodes[idx].constraint)
+ return idx; /* Found. */
+ }
+ return REG_MISSING; /* Not found. */
+}
+
+/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT.
+ Return the index of the new node, or REG_MISSING if insufficient storage is
+ available. */
+
+static Idx
+duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint)
+{
+ Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
+ if (BE (dup_idx != REG_MISSING, 1))
+ {
+ dfa->nodes[dup_idx].constraint = constraint;
+ dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint;
+ dfa->nodes[dup_idx].duplicated = 1;
+
+ /* Store the index of the original node. */
+ dfa->org_indices[dup_idx] = org_idx;
+ }
+ return dup_idx;
+}
+
+static reg_errcode_t
+calc_inveclosure (re_dfa_t *dfa)
+{
+ Idx src, idx;
+ bool ok;
+ for (idx = 0; idx < dfa->nodes_len; ++idx)
+ re_node_set_init_empty (dfa->inveclosures + idx);
+
+ for (src = 0; src < dfa->nodes_len; ++src)
+ {
+ Idx *elems = dfa->eclosures[src].elems;
+ for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx)
+ {
+ ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ }
+
+ return REG_NOERROR;
+}
+
+/* Calculate "eclosure" for all the node in DFA. */
+
+static reg_errcode_t
+calc_eclosure (re_dfa_t *dfa)
+{
+ Idx node_idx;
+ bool incomplete;
+#ifdef DEBUG
+ assert (dfa->nodes_len > 0);
+#endif
+ incomplete = false;
+ /* For each nodes, calculate epsilon closure. */
+ for (node_idx = 0; ; ++node_idx)
+ {
+ reg_errcode_t err;
+ re_node_set eclosure_elem;
+ if (node_idx == dfa->nodes_len)
+ {
+ if (!incomplete)
+ break;
+ incomplete = false;
+ node_idx = 0;
+ }
+
+#ifdef DEBUG
+ assert (dfa->eclosures[node_idx].nelem != REG_MISSING);
+#endif
+
+ /* If we have already calculated, skip it. */
+ if (dfa->eclosures[node_idx].nelem != 0)
+ continue;
+ /* Calculate epsilon closure of 'node_idx'. */
+ err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ if (dfa->eclosures[node_idx].nelem == 0)
+ {
+ incomplete = true;
+ re_node_set_free (&eclosure_elem);
+ }
+ }
+ return REG_NOERROR;
+}
+
+/* Calculate epsilon closure of NODE. */
+
+static reg_errcode_t
+calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
+{
+ reg_errcode_t err;
+ Idx i;
+ re_node_set eclosure;
+ bool ok;
+ bool incomplete = false;
+ err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* This indicates that we are calculating this node now.
+ We reference this value to avoid infinite loop. */
+ dfa->eclosures[node].nelem = REG_MISSING;
+
+ /* If the current node has constraints, duplicate all nodes
+ since they must inherit the constraints. */
+ if (dfa->nodes[node].constraint
+ && dfa->edests[node].nelem
+ && !dfa->nodes[dfa->edests[node].elems[0]].duplicated)
+ {
+ err = duplicate_node_closure (dfa, node, node, node,
+ dfa->nodes[node].constraint);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ /* Expand each epsilon destination nodes. */
+ if (IS_EPSILON_NODE(dfa->nodes[node].type))
+ for (i = 0; i < dfa->edests[node].nelem; ++i)
+ {
+ re_node_set eclosure_elem;
+ Idx edest = dfa->edests[node].elems[i];
+ /* If calculating the epsilon closure of 'edest' is in progress,
+ return intermediate result. */
+ if (dfa->eclosures[edest].nelem == REG_MISSING)
+ {
+ incomplete = true;
+ continue;
+ }
+ /* If we haven't calculated the epsilon closure of 'edest' yet,
+ calculate now. Otherwise use calculated epsilon closure. */
+ if (dfa->eclosures[edest].nelem == 0)
+ {
+ err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ else
+ eclosure_elem = dfa->eclosures[edest];
+ /* Merge the epsilon closure of 'edest'. */
+ err = re_node_set_merge (&eclosure, &eclosure_elem);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ /* If the epsilon closure of 'edest' is incomplete,
+ the epsilon closure of this node is also incomplete. */
+ if (dfa->eclosures[edest].nelem == 0)
+ {
+ incomplete = true;
+ re_node_set_free (&eclosure_elem);
+ }
+ }
+
+ /* An epsilon closure includes itself. */
+ ok = re_node_set_insert (&eclosure, node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ if (incomplete && !root)
+ dfa->eclosures[node].nelem = 0;
+ else
+ dfa->eclosures[node] = eclosure;
+ *new_set = eclosure;
+ return REG_NOERROR;
+}
+
+/* Functions for token which are used in the parser. */
+
+/* Fetch a token from INPUT.
+ We must not use this function inside bracket expressions. */
+
+static void
+internal_function
+fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
+{
+ re_string_skip_bytes (input, peek_token (result, input, syntax));
+}
+
+/* Peek a token from INPUT, and return the length of the token.
+ We must not use this function inside bracket expressions. */
+
+static int
+internal_function
+peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
+{
+ unsigned char c;
+
+ if (re_string_eoi (input))
+ {
+ token->type = END_OF_RE;
+ return 0;
+ }
+
+ c = re_string_peek_byte (input, 0);
+ token->opr.c = c;
+
+ token->word_char = 0;
+#ifdef RE_ENABLE_I18N
+ token->mb_partial = 0;
+ if (input->mb_cur_max > 1 &&
+ !re_string_first_byte (input, re_string_cur_idx (input)))
+ {
+ token->type = CHARACTER;
+ token->mb_partial = 1;
+ return 1;
+ }
+#endif
+ if (c == '\\')
+ {
+ unsigned char c2;
+ if (re_string_cur_idx (input) + 1 >= re_string_length (input))
+ {
+ token->type = BACK_SLASH;
+ return 1;
+ }
+
+ c2 = re_string_peek_byte_case (input, 1);
+ token->opr.c = c2;
+ token->type = CHARACTER;
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1)
+ {
+ wint_t wc = re_string_wchar_at (input,
+ re_string_cur_idx (input) + 1);
+ token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
+ }
+ else
+#endif
+ token->word_char = IS_WORD_CHAR (c2) != 0;
+
+ switch (c2)
+ {
+ case '|':
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR))
+ token->type = OP_ALT;
+ break;
+ case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ if (!(syntax & RE_NO_BK_REFS))
+ {
+ token->type = OP_BACK_REF;
+ token->opr.idx = c2 - '1';
+ }
+ break;
+ case '<':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = WORD_FIRST;
+ }
+ break;
+ case '>':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = WORD_LAST;
+ }
+ break;
+ case 'b':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = WORD_DELIM;
+ }
+ break;
+ case 'B':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = NOT_WORD_DELIM;
+ }
+ break;
+ case 'w':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_WORD;
+ break;
+ case 'W':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_NOTWORD;
+ break;
+ case 's':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_SPACE;
+ break;
+ case 'S':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_NOTSPACE;
+ break;
+ case '`':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = BUF_FIRST;
+ }
+ break;
+ case '\'':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = BUF_LAST;
+ }
+ break;
+ case '(':
+ if (!(syntax & RE_NO_BK_PARENS))
+ token->type = OP_OPEN_SUBEXP;
+ break;
+ case ')':
+ if (!(syntax & RE_NO_BK_PARENS))
+ token->type = OP_CLOSE_SUBEXP;
+ break;
+ case '+':
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_PLUS;
+ break;
+ case '?':
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_QUESTION;
+ break;
+ case '{':
+ if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
+ token->type = OP_OPEN_DUP_NUM;
+ break;
+ case '}':
+ if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
+ token->type = OP_CLOSE_DUP_NUM;
+ break;
+ default:
+ break;
+ }
+ return 2;
+ }
+
+ token->type = CHARACTER;
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1)
+ {
+ wint_t wc = re_string_wchar_at (input, re_string_cur_idx (input));
+ token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
+ }
+ else
+#endif
+ token->word_char = IS_WORD_CHAR (token->opr.c);
+
+ switch (c)
+ {
+ case '\n':
+ if (syntax & RE_NEWLINE_ALT)
+ token->type = OP_ALT;
+ break;
+ case '|':
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR))
+ token->type = OP_ALT;
+ break;
+ case '*':
+ token->type = OP_DUP_ASTERISK;
+ break;
+ case '+':
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_PLUS;
+ break;
+ case '?':
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_QUESTION;
+ break;
+ case '{':
+ if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
+ token->type = OP_OPEN_DUP_NUM;
+ break;
+ case '}':
+ if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
+ token->type = OP_CLOSE_DUP_NUM;
+ break;
+ case '(':
+ if (syntax & RE_NO_BK_PARENS)
+ token->type = OP_OPEN_SUBEXP;
+ break;
+ case ')':
+ if (syntax & RE_NO_BK_PARENS)
+ token->type = OP_CLOSE_SUBEXP;
+ break;
+ case '[':
+ token->type = OP_OPEN_BRACKET;
+ break;
+ case '.':
+ token->type = OP_PERIOD;
+ break;
+ case '^':
+ if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) &&
+ re_string_cur_idx (input) != 0)
+ {
+ char prev = re_string_peek_byte (input, -1);
+ if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
+ break;
+ }
+ token->type = ANCHOR;
+ token->opr.ctx_type = LINE_FIRST;
+ break;
+ case '$':
+ if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) &&
+ re_string_cur_idx (input) + 1 != re_string_length (input))
+ {
+ re_token_t next;
+ re_string_skip_bytes (input, 1);
+ peek_token (&next, input, syntax);
+ re_string_skip_bytes (input, -1);
+ if (next.type != OP_ALT && next.type != OP_CLOSE_SUBEXP)
+ break;
+ }
+ token->type = ANCHOR;
+ token->opr.ctx_type = LINE_LAST;
+ break;
+ default:
+ break;
+ }
+ return 1;
+}
+
+/* Peek a token from INPUT, and return the length of the token.
+ We must not use this function out of bracket expressions. */
+
+static int
+internal_function
+peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
+{
+ unsigned char c;
+ if (re_string_eoi (input))
+ {
+ token->type = END_OF_RE;
+ return 0;
+ }
+ c = re_string_peek_byte (input, 0);
+ token->opr.c = c;
+
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1 &&
+ !re_string_first_byte (input, re_string_cur_idx (input)))
+ {
+ token->type = CHARACTER;
+ return 1;
+ }
+#endif /* RE_ENABLE_I18N */
+
+ if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS)
+ && re_string_cur_idx (input) + 1 < re_string_length (input))
+ {
+ /* In this case, '\' escape a character. */
+ unsigned char c2;
+ re_string_skip_bytes (input, 1);
+ c2 = re_string_peek_byte (input, 0);
+ token->opr.c = c2;
+ token->type = CHARACTER;
+ return 1;
+ }
+ if (c == '[') /* '[' is a special char in a bracket exps. */
+ {
+ unsigned char c2;
+ int token_len;
+ if (re_string_cur_idx (input) + 1 < re_string_length (input))
+ c2 = re_string_peek_byte (input, 1);
+ else
+ c2 = 0;
+ token->opr.c = c2;
+ token_len = 2;
+ switch (c2)
+ {
+ case '.':
+ token->type = OP_OPEN_COLL_ELEM;
+ break;
+ case '=':
+ token->type = OP_OPEN_EQUIV_CLASS;
+ break;
+ case ':':
+ if (syntax & RE_CHAR_CLASSES)
+ {
+ token->type = OP_OPEN_CHAR_CLASS;
+ break;
+ }
+ /* else fall through. */
+ default:
+ token->type = CHARACTER;
+ token->opr.c = c;
+ token_len = 1;
+ break;
+ }
+ return token_len;
+ }
+ switch (c)
+ {
+ case '-':
+ token->type = OP_CHARSET_RANGE;
+ break;
+ case ']':
+ token->type = OP_CLOSE_BRACKET;
+ break;
+ case '^':
+ token->type = OP_NON_MATCH_LIST;
+ break;
+ default:
+ token->type = CHARACTER;
+ }
+ return 1;
+}
+
+/* Functions for parser. */
+
+/* Entry point of the parser.
+ Parse the regular expression REGEXP and return the structure tree.
+ If an error occurs, ERR is set by error code, and return NULL.
+ This function build the following tree, from regular expression <reg_exp>:
+ CAT
+ / \
+ / \
+ <reg_exp> EOR
+
+ CAT means concatenation.
+ EOR means end of regular expression. */
+
+static bin_tree_t *
+parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
+ reg_errcode_t *err)
+{
+ re_dfa_t *dfa = preg->buffer;
+ bin_tree_t *tree, *eor, *root;
+ re_token_t current_token;
+ dfa->syntax = syntax;
+ fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+ tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ eor = create_tree (dfa, NULL, NULL, END_OF_RE);
+ if (tree != NULL)
+ root = create_tree (dfa, tree, eor, CONCAT);
+ else
+ root = eor;
+ if (BE (eor == NULL || root == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ return root;
+}
+
+/* This function build the following tree, from regular expression
+ <branch1>|<branch2>:
+ ALT
+ / \
+ / \
+ <branch1> <branch2>
+
+ ALT means alternative, which represents the operator '|'. */
+
+static bin_tree_t *
+parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ re_dfa_t *dfa = preg->buffer;
+ bin_tree_t *tree, *branch = NULL;
+ tree = parse_branch (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+
+ while (token->type == OP_ALT)
+ {
+ fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+ if (token->type != OP_ALT && token->type != END_OF_RE
+ && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
+ {
+ branch = parse_branch (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && branch == NULL, 0))
+ return NULL;
+ }
+ else
+ branch = NULL;
+ tree = create_tree (dfa, tree, branch, OP_ALT);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ return tree;
+}
+
+/* This function build the following tree, from regular expression
+ <exp1><exp2>:
+ CAT
+ / \
+ / \
+ <exp1> <exp2>
+
+ CAT means concatenation. */
+
+static bin_tree_t *
+parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ bin_tree_t *tree, *expr;
+ re_dfa_t *dfa = preg->buffer;
+ tree = parse_expression (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+
+ while (token->type != OP_ALT && token->type != END_OF_RE
+ && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
+ {
+ expr = parse_expression (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && expr == NULL, 0))
+ {
+ if (tree != NULL)
+ postorder (tree, free_tree, NULL);
+ return NULL;
+ }
+ if (tree != NULL && expr != NULL)
+ {
+ bin_tree_t *newtree = create_tree (dfa, tree, expr, CONCAT);
+ if (newtree == NULL)
+ {
+ postorder (expr, free_tree, NULL);
+ postorder (tree, free_tree, NULL);
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ tree = newtree;
+ }
+ else if (tree == NULL)
+ tree = expr;
+ /* Otherwise expr == NULL, we don't need to create new tree. */
+ }
+ return tree;
+}
+
+/* This function build the following tree, from regular expression a*:
+ *
+ |
+ a
+*/
+
+static bin_tree_t *
+parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ re_dfa_t *dfa = preg->buffer;
+ bin_tree_t *tree;
+ switch (token->type)
+ {
+ case CHARACTER:
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ while (!re_string_eoi (regexp)
+ && !re_string_first_byte (regexp, re_string_cur_idx (regexp)))
+ {
+ bin_tree_t *mbc_remain;
+ fetch_token (token, regexp, syntax);
+ mbc_remain = create_token_tree (dfa, NULL, NULL, token);
+ tree = create_tree (dfa, tree, mbc_remain, CONCAT);
+ if (BE (mbc_remain == NULL || tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ }
+#endif
+ break;
+ case OP_OPEN_SUBEXP:
+ tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_OPEN_BRACKET:
+ tree = parse_bracket_exp (regexp, dfa, token, syntax, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_BACK_REF:
+ if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1))
+ {
+ *err = REG_ESUBREG;
+ return NULL;
+ }
+ dfa->used_bkref_map |= 1 << token->opr.idx;
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ ++dfa->nbackref;
+ dfa->has_mb_node = 1;
+ break;
+ case OP_OPEN_DUP_NUM:
+ if (syntax & RE_CONTEXT_INVALID_DUP)
+ {
+ *err = REG_BADRPT;
+ return NULL;
+ }
+ /* FALLTHROUGH */
+ case OP_DUP_ASTERISK:
+ case OP_DUP_PLUS:
+ case OP_DUP_QUESTION:
+ if (syntax & RE_CONTEXT_INVALID_OPS)
+ {
+ *err = REG_BADRPT;
+ return NULL;
+ }
+ else if (syntax & RE_CONTEXT_INDEP_OPS)
+ {
+ fetch_token (token, regexp, syntax);
+ return parse_expression (regexp, preg, token, syntax, nest, err);
+ }
+ /* else fall through */
+ case OP_CLOSE_SUBEXP:
+ if ((token->type == OP_CLOSE_SUBEXP) &&
+ !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
+ {
+ *err = REG_ERPAREN;
+ return NULL;
+ }
+ /* else fall through */
+ case OP_CLOSE_DUP_NUM:
+ /* We treat it as a normal character. */
+
+ /* Then we can these characters as normal characters. */
+ token->type = CHARACTER;
+ /* mb_partial and word_char bits should be initialized already
+ by peek_token. */
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ break;
+ case ANCHOR:
+ if ((token->opr.ctx_type
+ & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST))
+ && dfa->word_ops_used == 0)
+ init_word_char (dfa);
+ if (token->opr.ctx_type == WORD_DELIM
+ || token->opr.ctx_type == NOT_WORD_DELIM)
+ {
+ bin_tree_t *tree_first, *tree_last;
+ if (token->opr.ctx_type == WORD_DELIM)
+ {
+ token->opr.ctx_type = WORD_FIRST;
+ tree_first = create_token_tree (dfa, NULL, NULL, token);
+ token->opr.ctx_type = WORD_LAST;
+ }
+ else
+ {
+ token->opr.ctx_type = INSIDE_WORD;
+ tree_first = create_token_tree (dfa, NULL, NULL, token);
+ token->opr.ctx_type = INSIDE_NOTWORD;
+ }
+ tree_last = create_token_tree (dfa, NULL, NULL, token);
+ tree = create_tree (dfa, tree_first, tree_last, OP_ALT);
+ if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ else
+ {
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ /* We must return here, since ANCHORs can't be followed
+ by repetition operators.
+ eg. RE"^*" is invalid or "<ANCHOR(^)><CHAR(*)>",
+ it must not be "<ANCHOR(^)><REPEAT(*)>". */
+ fetch_token (token, regexp, syntax);
+ return tree;
+ case OP_PERIOD:
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ if (dfa->mb_cur_max > 1)
+ dfa->has_mb_node = 1;
+ break;
+ case OP_WORD:
+ case OP_NOTWORD:
+ tree = build_charclass_op (dfa, regexp->trans,
+ "alnum",
+ "_",
+ token->type == OP_NOTWORD, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_SPACE:
+ case OP_NOTSPACE:
+ tree = build_charclass_op (dfa, regexp->trans,
+ "space",
+ "",
+ token->type == OP_NOTSPACE, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_ALT:
+ case END_OF_RE:
+ return NULL;
+ case BACK_SLASH:
+ *err = REG_EESCAPE;
+ return NULL;
+ default:
+ /* Must not happen? */
+#ifdef DEBUG
+ assert (0);
+#endif
+ return NULL;
+ }
+ fetch_token (token, regexp, syntax);
+
+ while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS
+ || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM)
+ {
+ tree = parse_dup_op (tree, regexp, dfa, token, syntax, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ /* In BRE consecutive duplications are not allowed. */
+ if ((syntax & RE_CONTEXT_INVALID_DUP)
+ && (token->type == OP_DUP_ASTERISK
+ || token->type == OP_OPEN_DUP_NUM))
+ {
+ *err = REG_BADRPT;
+ return NULL;
+ }
+ }
+
+ return tree;
+}
+
+/* This function build the following tree, from regular expression
+ (<reg_exp>):
+ SUBEXP
+ |
+ <reg_exp>
+*/
+
+static bin_tree_t *
+parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ re_dfa_t *dfa = preg->buffer;
+ bin_tree_t *tree;
+ size_t cur_nsub;
+ cur_nsub = preg->re_nsub++;
+
+ fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+
+ /* The subexpression may be a null string. */
+ if (token->type == OP_CLOSE_SUBEXP)
+ tree = NULL;
+ else
+ {
+ tree = parse_reg_exp (regexp, preg, token, syntax, nest, err);
+ if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0))
+ {
+ if (tree != NULL)
+ postorder (tree, free_tree, NULL);
+ *err = REG_EPAREN;
+ }
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ }
+
+ if (cur_nsub <= '9' - '1')
+ dfa->completed_bkref_map |= 1 << cur_nsub;
+
+ tree = create_tree (dfa, tree, NULL, SUBEXP);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ tree->token.opr.idx = cur_nsub;
+ return tree;
+}
+
+/* This function parse repetition operators like "*", "+", "{1,3}" etc. */
+
+static bin_tree_t *
+parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
+ re_token_t *token, reg_syntax_t syntax, reg_errcode_t *err)
+{
+ bin_tree_t *tree = NULL, *old_tree = NULL;
+ Idx i, start, end, start_idx = re_string_cur_idx (regexp);
+ re_token_t start_token = *token;
+
+ if (token->type == OP_OPEN_DUP_NUM)
+ {
+ end = 0;
+ start = fetch_number (regexp, token, syntax);
+ if (start == REG_MISSING)
+ {
+ if (token->type == CHARACTER && token->opr.c == ',')
+ start = 0; /* We treat "{,m}" as "{0,m}". */
+ else
+ {
+ *err = REG_BADBR; /* <re>{} is invalid. */
+ return NULL;
+ }
+ }
+ if (BE (start != REG_ERROR, 1))
+ {
+ /* We treat "{n}" as "{n,n}". */
+ end = ((token->type == OP_CLOSE_DUP_NUM) ? start
+ : ((token->type == CHARACTER && token->opr.c == ',')
+ ? fetch_number (regexp, token, syntax) : REG_ERROR));
+ }
+ if (BE (start == REG_ERROR || end == REG_ERROR, 0))
+ {
+ /* Invalid sequence. */
+ if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0))
+ {
+ if (token->type == END_OF_RE)
+ *err = REG_EBRACE;
+ else
+ *err = REG_BADBR;
+
+ return NULL;
+ }
+
+ /* If the syntax bit is set, rollback. */
+ re_string_set_index (regexp, start_idx);
+ *token = start_token;
+ token->type = CHARACTER;
+ /* mb_partial and word_char bits should be already initialized by
+ peek_token. */
+ return elem;
+ }
+
+ if (BE ((end != REG_MISSING && start > end)
+ || token->type != OP_CLOSE_DUP_NUM, 0))
+ {
+ /* First number greater than second. */
+ *err = REG_BADBR;
+ return NULL;
+ }
+
+ if (BE (RE_DUP_MAX < (end == REG_MISSING ? start : end), 0))
+ {
+ *err = REG_ESIZE;
+ return NULL;
+ }
+ }
+ else
+ {
+ start = (token->type == OP_DUP_PLUS) ? 1 : 0;
+ end = (token->type == OP_DUP_QUESTION) ? 1 : REG_MISSING;
+ }
+
+ fetch_token (token, regexp, syntax);
+
+ if (BE (elem == NULL, 0))
+ return NULL;
+ if (BE (start == 0 && end == 0, 0))
+ {
+ postorder (elem, free_tree, NULL);
+ return NULL;
+ }
+
+ /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */
+ if (BE (start > 0, 0))
+ {
+ tree = elem;
+ for (i = 2; i <= start; ++i)
+ {
+ elem = duplicate_tree (elem, dfa);
+ tree = create_tree (dfa, tree, elem, CONCAT);
+ if (BE (elem == NULL || tree == NULL, 0))
+ goto parse_dup_op_espace;
+ }
+
+ if (start == end)
+ return tree;
+
+ /* Duplicate ELEM before it is marked optional. */
+ elem = duplicate_tree (elem, dfa);
+ old_tree = tree;
+ }
+ else
+ old_tree = NULL;
+
+ if (elem->token.type == SUBEXP)
+ {
+ uintptr_t subidx = elem->token.opr.idx;
+ postorder (elem, mark_opt_subexp, (void *) subidx);
+ }
+
+ tree = create_tree (dfa, elem, NULL,
+ (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT));
+ if (BE (tree == NULL, 0))
+ goto parse_dup_op_espace;
+
+/* From gnulib's "intprops.h":
+ True if the arithmetic type T is signed. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+ /* This loop is actually executed only when end != REG_MISSING,
+ to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have
+ already created the start+1-th copy. */
+ if (TYPE_SIGNED (Idx) || end != REG_MISSING)
+ for (i = start + 2; i <= end; ++i)
+ {
+ elem = duplicate_tree (elem, dfa);
+ tree = create_tree (dfa, tree, elem, CONCAT);
+ if (BE (elem == NULL || tree == NULL, 0))
+ goto parse_dup_op_espace;
+
+ tree = create_tree (dfa, tree, NULL, OP_ALT);
+ if (BE (tree == NULL, 0))
+ goto parse_dup_op_espace;
+ }
+
+ if (old_tree)
+ tree = create_tree (dfa, old_tree, tree, CONCAT);
+
+ return tree;
+
+ parse_dup_op_espace:
+ *err = REG_ESPACE;
+ return NULL;
+}
+
+/* Size of the names for collating symbol/equivalence_class/character_class.
+ I'm not sure, but maybe enough. */
+#define BRACKET_NAME_BUF_SIZE 32
+
+#ifndef _LIBC
+ /* Local function for parse_bracket_exp only used in case of NOT _LIBC.
+ Build the range expression which starts from START_ELEM, and ends
+ at END_ELEM. The result are written to MBCSET and SBCSET.
+ RANGE_ALLOC is the allocated size of mbcset->range_starts, and
+ mbcset->range_ends, is a pointer argument since we may
+ update it. */
+
+static reg_errcode_t
+internal_function
+# ifdef RE_ENABLE_I18N
+build_range_exp (const reg_syntax_t syntax,
+ bitset_t sbcset,
+ re_charset_t *mbcset,
+ Idx *range_alloc,
+ const bracket_elem_t *start_elem,
+ const bracket_elem_t *end_elem)
+# else /* not RE_ENABLE_I18N */
+build_range_exp (const reg_syntax_t syntax,
+ bitset_t sbcset,
+ const bracket_elem_t *start_elem,
+ const bracket_elem_t *end_elem)
+# endif /* not RE_ENABLE_I18N */
+{
+ unsigned int start_ch, end_ch;
+ /* Equivalence Classes and Character Classes can't be a range start/end. */
+ if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
+ || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS,
+ 0))
+ return REG_ERANGE;
+
+ /* We can handle no multi character collating elements without libc
+ support. */
+ if (BE ((start_elem->type == COLL_SYM
+ && strlen ((char *) start_elem->opr.name) > 1)
+ || (end_elem->type == COLL_SYM
+ && strlen ((char *) end_elem->opr.name) > 1), 0))
+ return REG_ECOLLATE;
+
+# ifdef RE_ENABLE_I18N
+ {
+ wchar_t wc;
+ wint_t start_wc;
+ wint_t end_wc;
+
+ start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
+ : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
+ : 0));
+ end_ch = ((end_elem->type == SB_CHAR) ? end_elem->opr.ch
+ : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
+ : 0));
+ start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM)
+ ? __btowc (start_ch) : start_elem->opr.wch);
+ end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM)
+ ? __btowc (end_ch) : end_elem->opr.wch);
+ if (start_wc == WEOF || end_wc == WEOF)
+ return REG_ECOLLATE;
+ else if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc, 0))
+ return REG_ERANGE;
+
+ /* Got valid collation sequence values, add them as a new entry.
+ However, for !_LIBC we have no collation elements: if the
+ character set is single byte, the single byte character set
+ that we build below suffices. parse_bracket_exp passes
+ no MBCSET if dfa->mb_cur_max == 1. */
+ if (mbcset)
+ {
+ /* Check the space of the arrays. */
+ if (BE (*range_alloc == mbcset->nranges, 0))
+ {
+ /* There is not enough space, need realloc. */
+ wchar_t *new_array_start, *new_array_end;
+ Idx new_nranges;
+
+ /* +1 in case of mbcset->nranges is 0. */
+ new_nranges = 2 * mbcset->nranges + 1;
+ /* Use realloc since mbcset->range_starts and mbcset->range_ends
+ are NULL if *range_alloc == 0. */
+ new_array_start = re_realloc (mbcset->range_starts, wchar_t,
+ new_nranges);
+ new_array_end = re_realloc (mbcset->range_ends, wchar_t,
+ new_nranges);
+
+ if (BE (new_array_start == NULL || new_array_end == NULL, 0))
+ return REG_ESPACE;
+
+ mbcset->range_starts = new_array_start;
+ mbcset->range_ends = new_array_end;
+ *range_alloc = new_nranges;
+ }
+
+ mbcset->range_starts[mbcset->nranges] = start_wc;
+ mbcset->range_ends[mbcset->nranges++] = end_wc;
+ }
+
+ /* Build the table for single byte characters. */
+ for (wc = 0; wc < SBC_MAX; ++wc)
+ {
+ if (start_wc <= wc && wc <= end_wc)
+ bitset_set (sbcset, wc);
+ }
+ }
+# else /* not RE_ENABLE_I18N */
+ {
+ unsigned int ch;
+ start_ch = ((start_elem->type == SB_CHAR ) ? start_elem->opr.ch
+ : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
+ : 0));
+ end_ch = ((end_elem->type == SB_CHAR ) ? end_elem->opr.ch
+ : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
+ : 0));
+ if (start_ch > end_ch)
+ return REG_ERANGE;
+ /* Build the table for single byte characters. */
+ for (ch = 0; ch < SBC_MAX; ++ch)
+ if (start_ch <= ch && ch <= end_ch)
+ bitset_set (sbcset, ch);
+ }
+# endif /* not RE_ENABLE_I18N */
+ return REG_NOERROR;
+}
+#endif /* not _LIBC */
+
+#ifndef _LIBC
+/* Helper function for parse_bracket_exp only used in case of NOT _LIBC..
+ Build the collating element which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
+ pointer argument since we may update it. */
+
+static reg_errcode_t
+internal_function
+# ifdef RE_ENABLE_I18N
+build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
+ Idx *coll_sym_alloc, const unsigned char *name)
+# else /* not RE_ENABLE_I18N */
+build_collating_symbol (bitset_t sbcset, const unsigned char *name)
+# endif /* not RE_ENABLE_I18N */
+{
+ size_t name_len = strlen ((const char *) name);
+ if (BE (name_len != 1, 0))
+ return REG_ECOLLATE;
+ else
+ {
+ bitset_set (sbcset, name[0]);
+ return REG_NOERROR;
+ }
+}
+#endif /* not _LIBC */
+
+/* This function parse bracket expression like "[abc]", "[a-c]",
+ "[[.a-a.]]" etc. */
+
+static bin_tree_t *
+parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
+ reg_syntax_t syntax, reg_errcode_t *err)
+{
+#ifdef _LIBC
+ const unsigned char *collseqmb;
+ const char *collseqwc;
+ uint32_t nrules;
+ int32_t table_size;
+ const int32_t *symb_table;
+ const unsigned char *extra;
+
+ /* Local function for parse_bracket_exp used in _LIBC environment.
+ Seek the collating symbol entry corresponding to NAME.
+ Return the index of the symbol in the SYMB_TABLE,
+ or -1 if not found. */
+
+ auto inline int32_t
+ __attribute__ ((always_inline))
+ seek_collating_symbol_entry (const unsigned char *name, size_t name_len)
+ {
+ int32_t elem;
+
+ for (elem = 0; elem < table_size; elem++)
+ if (symb_table[2 * elem] != 0)
+ {
+ int32_t idx = symb_table[2 * elem + 1];
+ /* Skip the name of collating element name. */
+ idx += 1 + extra[idx];
+ if (/* Compare the length of the name. */
+ name_len == extra[idx]
+ /* Compare the name. */
+ && memcmp (name, &extra[idx + 1], name_len) == 0)
+ /* Yep, this is the entry. */
+ return elem;
+ }
+ return -1;
+ }
+
+ /* Local function for parse_bracket_exp used in _LIBC environment.
+ Look up the collation sequence value of BR_ELEM.
+ Return the value if succeeded, UINT_MAX otherwise. */
+
+ auto inline unsigned int
+ __attribute__ ((always_inline))
+ lookup_collation_sequence_value (bracket_elem_t *br_elem)
+ {
+ if (br_elem->type == SB_CHAR)
+ {
+ /*
+ if (MB_CUR_MAX == 1)
+ */
+ if (nrules == 0)
+ return collseqmb[br_elem->opr.ch];
+ else
+ {
+ wint_t wc = __btowc (br_elem->opr.ch);
+ return __collseq_table_lookup (collseqwc, wc);
+ }
+ }
+ else if (br_elem->type == MB_CHAR)
+ {
+ if (nrules != 0)
+ return __collseq_table_lookup (collseqwc, br_elem->opr.wch);
+ }
+ else if (br_elem->type == COLL_SYM)
+ {
+ size_t sym_name_len = strlen ((char *) br_elem->opr.name);
+ if (nrules != 0)
+ {
+ int32_t elem, idx;
+ elem = seek_collating_symbol_entry (br_elem->opr.name,
+ sym_name_len);
+ if (elem != -1)
+ {
+ /* We found the entry. */
+ idx = symb_table[2 * elem + 1];
+ /* Skip the name of collating element name. */
+ idx += 1 + extra[idx];
+ /* Skip the byte sequence of the collating element. */
+ idx += 1 + extra[idx];
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
+ /* Skip the multibyte collation sequence value. */
+ idx += sizeof (unsigned int);
+ /* Skip the wide char sequence of the collating element. */
+ idx += sizeof (unsigned int) *
+ (1 + *(unsigned int *) (extra + idx));
+ /* Return the collation sequence value. */
+ return *(unsigned int *) (extra + idx);
+ }
+ else if (sym_name_len == 1)
+ {
+ /* No valid character. Match it as a single byte
+ character. */
+ return collseqmb[br_elem->opr.name[0]];
+ }
+ }
+ else if (sym_name_len == 1)
+ return collseqmb[br_elem->opr.name[0]];
+ }
+ return UINT_MAX;
+ }
+
+ /* Local function for parse_bracket_exp used in _LIBC environment.
+ Build the range expression which starts from START_ELEM, and ends
+ at END_ELEM. The result are written to MBCSET and SBCSET.
+ RANGE_ALLOC is the allocated size of mbcset->range_starts, and
+ mbcset->range_ends, is a pointer argument since we may
+ update it. */
+
+ auto inline reg_errcode_t
+ __attribute__ ((always_inline))
+ build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc,
+ bracket_elem_t *start_elem, bracket_elem_t *end_elem)
+ {
+ unsigned int ch;
+ uint32_t start_collseq;
+ uint32_t end_collseq;
+
+ /* Equivalence Classes and Character Classes can't be a range
+ start/end. */
+ if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
+ || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS,
+ 0))
+ return REG_ERANGE;
+
+ /* FIXME: Implement rational ranges here, too. */
+ start_collseq = lookup_collation_sequence_value (start_elem);
+ end_collseq = lookup_collation_sequence_value (end_elem);
+ /* Check start/end collation sequence values. */
+ if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0))
+ return REG_ECOLLATE;
+ if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
+ return REG_ERANGE;
+
+ /* Got valid collation sequence values, add them as a new entry.
+ However, if we have no collation elements, and the character set
+ is single byte, the single byte character set that we
+ build below suffices. */
+ if (nrules > 0 || dfa->mb_cur_max > 1)
+ {
+ /* Check the space of the arrays. */
+ if (BE (*range_alloc == mbcset->nranges, 0))
+ {
+ /* There is not enough space, need realloc. */
+ uint32_t *new_array_start;
+ uint32_t *new_array_end;
+ Idx new_nranges;
+
+ /* +1 in case of mbcset->nranges is 0. */
+ new_nranges = 2 * mbcset->nranges + 1;
+ new_array_start = re_realloc (mbcset->range_starts, uint32_t,
+ new_nranges);
+ new_array_end = re_realloc (mbcset->range_ends, uint32_t,
+ new_nranges);
+
+ if (BE (new_array_start == NULL || new_array_end == NULL, 0))
+ return REG_ESPACE;
+
+ mbcset->range_starts = new_array_start;
+ mbcset->range_ends = new_array_end;
+ *range_alloc = new_nranges;
+ }
+
+ mbcset->range_starts[mbcset->nranges] = start_collseq;
+ mbcset->range_ends[mbcset->nranges++] = end_collseq;
+ }
+
+ /* Build the table for single byte characters. */
+ for (ch = 0; ch < SBC_MAX; ch++)
+ {
+ uint32_t ch_collseq;
+ /*
+ if (MB_CUR_MAX == 1)
+ */
+ if (nrules == 0)
+ ch_collseq = collseqmb[ch];
+ else
+ ch_collseq = __collseq_table_lookup (collseqwc, __btowc (ch));
+ if (start_collseq <= ch_collseq && ch_collseq <= end_collseq)
+ bitset_set (sbcset, ch);
+ }
+ return REG_NOERROR;
+ }
+
+ /* Local function for parse_bracket_exp used in _LIBC environment.
+ Build the collating element which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
+ pointer argument since we may update it. */
+
+ auto inline reg_errcode_t
+ __attribute__ ((always_inline))
+ build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
+ Idx *coll_sym_alloc, const unsigned char *name)
+ {
+ int32_t elem, idx;
+ size_t name_len = strlen ((const char *) name);
+ if (nrules != 0)
+ {
+ elem = seek_collating_symbol_entry (name, name_len);
+ if (elem != -1)
+ {
+ /* We found the entry. */
+ idx = symb_table[2 * elem + 1];
+ /* Skip the name of collating element name. */
+ idx += 1 + extra[idx];
+ }
+ else if (name_len == 1)
+ {
+ /* No valid character, treat it as a normal
+ character. */
+ bitset_set (sbcset, name[0]);
+ return REG_NOERROR;
+ }
+ else
+ return REG_ECOLLATE;
+
+ /* Got valid collation sequence, add it as a new entry. */
+ /* Check the space of the arrays. */
+ if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0))
+ {
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->ncoll_syms is 0. */
+ Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
+ /* Use realloc since mbcset->coll_syms is NULL
+ if *alloc == 0. */
+ int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
+ new_coll_sym_alloc);
+ if (BE (new_coll_syms == NULL, 0))
+ return REG_ESPACE;
+ mbcset->coll_syms = new_coll_syms;
+ *coll_sym_alloc = new_coll_sym_alloc;
+ }
+ mbcset->coll_syms[mbcset->ncoll_syms++] = idx;
+ return REG_NOERROR;
+ }
+ else
+ {
+ if (BE (name_len != 1, 0))
+ return REG_ECOLLATE;
+ else
+ {
+ bitset_set (sbcset, name[0]);
+ return REG_NOERROR;
+ }
+ }
+ }
+#endif
+
+ re_token_t br_token;
+ re_bitset_ptr_t sbcset;
+#ifdef RE_ENABLE_I18N
+ re_charset_t *mbcset;
+ Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0;
+ Idx equiv_class_alloc = 0, char_class_alloc = 0;
+#endif /* not RE_ENABLE_I18N */
+ bool non_match = false;
+ bin_tree_t *work_tree;
+ int token_len;
+ bool first_round = true;
+#ifdef _LIBC
+ collseqmb = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
+ nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules)
+ {
+ /*
+ if (MB_CUR_MAX > 1)
+ */
+ collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
+ table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB);
+ symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_TABLEMB);
+ extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_EXTRAMB);
+ }
+#endif
+ sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
+#ifdef RE_ENABLE_I18N
+ mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
+#endif /* RE_ENABLE_I18N */
+#ifdef RE_ENABLE_I18N
+ if (BE (sbcset == NULL || mbcset == NULL, 0))
+#else
+ if (BE (sbcset == NULL, 0))
+#endif /* RE_ENABLE_I18N */
+ {
+ re_free (sbcset);
+#ifdef RE_ENABLE_I18N
+ re_free (mbcset);
+#endif
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ token_len = peek_token_bracket (token, regexp, syntax);
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_BADPAT;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token->type == OP_NON_MATCH_LIST)
+ {
+#ifdef RE_ENABLE_I18N
+ mbcset->non_match = 1;
+#endif /* not RE_ENABLE_I18N */
+ non_match = true;
+ if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
+ bitset_set (sbcset, '\n');
+ re_string_skip_bytes (regexp, token_len); /* Skip a token. */
+ token_len = peek_token_bracket (token, regexp, syntax);
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_BADPAT;
+ goto parse_bracket_exp_free_return;
+ }
+ }
+
+ /* We treat the first ']' as a normal character. */
+ if (token->type == OP_CLOSE_BRACKET)
+ token->type = CHARACTER;
+
+ while (1)
+ {
+ bracket_elem_t start_elem, end_elem;
+ unsigned char start_name_buf[BRACKET_NAME_BUF_SIZE];
+ unsigned char end_name_buf[BRACKET_NAME_BUF_SIZE];
+ reg_errcode_t ret;
+ int token_len2 = 0;
+ bool is_range_exp = false;
+ re_token_t token2;
+
+ start_elem.opr.name = start_name_buf;
+ ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa,
+ syntax, first_round);
+ if (BE (ret != REG_NOERROR, 0))
+ {
+ *err = ret;
+ goto parse_bracket_exp_free_return;
+ }
+ first_round = false;
+
+ /* Get information about the next token. We need it in any case. */
+ token_len = peek_token_bracket (token, regexp, syntax);
+
+ /* Do not check for ranges if we know they are not allowed. */
+ if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS)
+ {
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_EBRACK;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token->type == OP_CHARSET_RANGE)
+ {
+ re_string_skip_bytes (regexp, token_len); /* Skip '-'. */
+ token_len2 = peek_token_bracket (&token2, regexp, syntax);
+ if (BE (token2.type == END_OF_RE, 0))
+ {
+ *err = REG_EBRACK;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token2.type == OP_CLOSE_BRACKET)
+ {
+ /* We treat the last '-' as a normal character. */
+ re_string_skip_bytes (regexp, -token_len);
+ token->type = CHARACTER;
+ }
+ else
+ is_range_exp = true;
+ }
+ }
+
+ if (is_range_exp == true)
+ {
+ end_elem.opr.name = end_name_buf;
+ ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2,
+ dfa, syntax, true);
+ if (BE (ret != REG_NOERROR, 0))
+ {
+ *err = ret;
+ goto parse_bracket_exp_free_return;
+ }
+
+ token_len = peek_token_bracket (token, regexp, syntax);
+
+#ifdef _LIBC
+ *err = build_range_exp (sbcset, mbcset, &range_alloc,
+ &start_elem, &end_elem);
+#else
+# ifdef RE_ENABLE_I18N
+ *err = build_range_exp (syntax, sbcset,
+ dfa->mb_cur_max > 1 ? mbcset : NULL,
+ &range_alloc, &start_elem, &end_elem);
+# else
+ *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem);
+# endif
+#endif /* RE_ENABLE_I18N */
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ }
+ else
+ {
+ switch (start_elem.type)
+ {
+ case SB_CHAR:
+ bitset_set (sbcset, start_elem.opr.ch);
+ break;
+#ifdef RE_ENABLE_I18N
+ case MB_CHAR:
+ /* Check whether the array has enough space. */
+ if (BE (mbchar_alloc == mbcset->nmbchars, 0))
+ {
+ wchar_t *new_mbchars;
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->nmbchars is 0. */
+ mbchar_alloc = 2 * mbcset->nmbchars + 1;
+ /* Use realloc since array is NULL if *alloc == 0. */
+ new_mbchars = re_realloc (mbcset->mbchars, wchar_t,
+ mbchar_alloc);
+ if (BE (new_mbchars == NULL, 0))
+ goto parse_bracket_exp_espace;
+ mbcset->mbchars = new_mbchars;
+ }
+ mbcset->mbchars[mbcset->nmbchars++] = start_elem.opr.wch;
+ break;
+#endif /* RE_ENABLE_I18N */
+ case EQUIV_CLASS:
+ *err = build_equiv_class (sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &equiv_class_alloc,
+#endif /* RE_ENABLE_I18N */
+ start_elem.opr.name);
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ break;
+ case COLL_SYM:
+ *err = build_collating_symbol (sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &coll_sym_alloc,
+#endif /* RE_ENABLE_I18N */
+ start_elem.opr.name);
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ break;
+ case CHAR_CLASS:
+ *err = build_charclass (regexp->trans, sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &char_class_alloc,
+#endif /* RE_ENABLE_I18N */
+ (const char *) start_elem.opr.name,
+ syntax);
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ break;
+ default:
+ assert (0);
+ break;
+ }
+ }
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_EBRACK;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token->type == OP_CLOSE_BRACKET)
+ break;
+ }
+
+ re_string_skip_bytes (regexp, token_len); /* Skip a token. */
+
+ /* If it is non-matching list. */
+ if (non_match)
+ bitset_not (sbcset);
+
+#ifdef RE_ENABLE_I18N
+ /* Ensure only single byte characters are set. */
+ if (dfa->mb_cur_max > 1)
+ bitset_mask (sbcset, dfa->sb_char);
+
+ if (mbcset->nmbchars || mbcset->ncoll_syms || mbcset->nequiv_classes
+ || mbcset->nranges || (dfa->mb_cur_max > 1 && (mbcset->nchar_classes
+ || mbcset->non_match)))
+ {
+ bin_tree_t *mbc_tree;
+ int sbc_idx;
+ /* Build a tree for complex bracket. */
+ dfa->has_mb_node = 1;
+ br_token.type = COMPLEX_BRACKET;
+ br_token.opr.mbcset = mbcset;
+ mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (mbc_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+ for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx)
+ if (sbcset[sbc_idx])
+ break;
+ /* If there are no bits set in sbcset, there is no point
+ of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */
+ if (sbc_idx < BITSET_WORDS)
+ {
+ /* Build a tree for simple bracket. */
+ br_token.type = SIMPLE_BRACKET;
+ br_token.opr.sbcset = sbcset;
+ work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (work_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+
+ /* Then join them by ALT node. */
+ work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT);
+ if (BE (work_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+ }
+ else
+ {
+ re_free (sbcset);
+ work_tree = mbc_tree;
+ }
+ }
+ else
+#endif /* not RE_ENABLE_I18N */
+ {
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif
+ /* Build a tree for simple bracket. */
+ br_token.type = SIMPLE_BRACKET;
+ br_token.opr.sbcset = sbcset;
+ work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (work_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+ }
+ return work_tree;
+
+ parse_bracket_exp_espace:
+ *err = REG_ESPACE;
+ parse_bracket_exp_free_return:
+ re_free (sbcset);
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif /* RE_ENABLE_I18N */
+ return NULL;
+}
+
+/* Parse an element in the bracket expression. */
+
+static reg_errcode_t
+parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
+ re_token_t *token, int token_len, re_dfa_t *dfa,
+ reg_syntax_t syntax, bool accept_hyphen)
+{
+#ifdef RE_ENABLE_I18N
+ int cur_char_size;
+ cur_char_size = re_string_char_size_at (regexp, re_string_cur_idx (regexp));
+ if (cur_char_size > 1)
+ {
+ elem->type = MB_CHAR;
+ elem->opr.wch = re_string_wchar_at (regexp, re_string_cur_idx (regexp));
+ re_string_skip_bytes (regexp, cur_char_size);
+ return REG_NOERROR;
+ }
+#endif /* RE_ENABLE_I18N */
+ re_string_skip_bytes (regexp, token_len); /* Skip a token. */
+ if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS
+ || token->type == OP_OPEN_EQUIV_CLASS)
+ return parse_bracket_symbol (elem, regexp, token);
+ if (BE (token->type == OP_CHARSET_RANGE, 0) && !accept_hyphen)
+ {
+ /* A '-' must only appear as anything but a range indicator before
+ the closing bracket. Everything else is an error. */
+ re_token_t token2;
+ (void) peek_token_bracket (&token2, regexp, syntax);
+ if (token2.type != OP_CLOSE_BRACKET)
+ /* The actual error value is not standardized since this whole
+ case is undefined. But ERANGE makes good sense. */
+ return REG_ERANGE;
+ }
+ elem->type = SB_CHAR;
+ elem->opr.ch = token->opr.c;
+ return REG_NOERROR;
+}
+
+/* Parse a bracket symbol in the bracket expression. Bracket symbols are
+ such as [:<character_class>:], [.<collating_element>.], and
+ [=<equivalent_class>=]. */
+
+static reg_errcode_t
+parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
+ re_token_t *token)
+{
+ unsigned char ch, delim = token->opr.c;
+ int i = 0;
+ if (re_string_eoi(regexp))
+ return REG_EBRACK;
+ for (;; ++i)
+ {
+ if (i >= BRACKET_NAME_BUF_SIZE)
+ return REG_EBRACK;
+ if (token->type == OP_OPEN_CHAR_CLASS)
+ ch = re_string_fetch_byte_case (regexp);
+ else
+ ch = re_string_fetch_byte (regexp);
+ if (re_string_eoi(regexp))
+ return REG_EBRACK;
+ if (ch == delim && re_string_peek_byte (regexp, 0) == ']')
+ break;
+ elem->opr.name[i] = ch;
+ }
+ re_string_skip_bytes (regexp, 1);
+ elem->opr.name[i] = '\0';
+ switch (token->type)
+ {
+ case OP_OPEN_COLL_ELEM:
+ elem->type = COLL_SYM;
+ break;
+ case OP_OPEN_EQUIV_CLASS:
+ elem->type = EQUIV_CLASS;
+ break;
+ case OP_OPEN_CHAR_CLASS:
+ elem->type = CHAR_CLASS;
+ break;
+ default:
+ break;
+ }
+ return REG_NOERROR;
+}
+
+ /* Helper function for parse_bracket_exp.
+ Build the equivalence class which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ EQUIV_CLASS_ALLOC is the allocated size of mbcset->equiv_classes,
+ is a pointer argument since we may update it. */
+
+static reg_errcode_t
+#ifdef RE_ENABLE_I18N
+build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
+ Idx *equiv_class_alloc, const unsigned char *name)
+#else /* not RE_ENABLE_I18N */
+build_equiv_class (bitset_t sbcset, const unsigned char *name)
+#endif /* not RE_ENABLE_I18N */
+{
+#ifdef _LIBC
+ uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules != 0)
+ {
+ const int32_t *table, *indirect;
+ const unsigned char *weights, *extra, *cp;
+ unsigned char char_buf[2];
+ int32_t idx1, idx2;
+ unsigned int ch;
+ size_t len;
+ /* This #include defines a local function! */
+# include <locale/weight.h>
+ /* Calculate the index for equivalence class. */
+ cp = name;
+ table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ weights = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_WEIGHTMB);
+ extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_EXTRAMB);
+ indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_INDIRECTMB);
+ idx1 = findidx (&cp, -1);
+ if (BE (idx1 == 0 || *cp != '\0', 0))
+ /* This isn't a valid character. */
+ return REG_ECOLLATE;
+
+ /* Build single byte matching table for this equivalence class. */
+ len = weights[idx1 & 0xffffff];
+ for (ch = 0; ch < SBC_MAX; ++ch)
+ {
+ char_buf[0] = ch;
+ cp = char_buf;
+ idx2 = findidx (&cp, 1);
+/*
+ idx2 = table[ch];
+*/
+ if (idx2 == 0)
+ /* This isn't a valid character. */
+ continue;
+ /* Compare only if the length matches and the collation rule
+ index is the same. */
+ if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24))
+ {
+ int cnt = 0;
+
+ while (cnt <= len &&
+ weights[(idx1 & 0xffffff) + 1 + cnt]
+ == weights[(idx2 & 0xffffff) + 1 + cnt])
+ ++cnt;
+
+ if (cnt > len)
+ bitset_set (sbcset, ch);
+ }
+ }
+ /* Check whether the array has enough space. */
+ if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0))
+ {
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->nequiv_classes is 0. */
+ Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1;
+ /* Use realloc since the array is NULL if *alloc == 0. */
+ int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
+ int32_t,
+ new_equiv_class_alloc);
+ if (BE (new_equiv_classes == NULL, 0))
+ return REG_ESPACE;
+ mbcset->equiv_classes = new_equiv_classes;
+ *equiv_class_alloc = new_equiv_class_alloc;
+ }
+ mbcset->equiv_classes[mbcset->nequiv_classes++] = idx1;
+ }
+ else
+#endif /* _LIBC */
+ {
+ if (BE (strlen ((const char *) name) != 1, 0))
+ return REG_ECOLLATE;
+ bitset_set (sbcset, *name);
+ }
+ return REG_NOERROR;
+}
+
+ /* Helper function for parse_bracket_exp.
+ Build the character class which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ CHAR_CLASS_ALLOC is the allocated size of mbcset->char_classes,
+ is a pointer argument since we may update it. */
+
+static reg_errcode_t
+#ifdef RE_ENABLE_I18N
+build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
+ re_charset_t *mbcset, Idx *char_class_alloc,
+ const char *class_name, reg_syntax_t syntax)
+#else /* not RE_ENABLE_I18N */
+build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
+ const char *class_name, reg_syntax_t syntax)
+#endif /* not RE_ENABLE_I18N */
+{
+ int i;
+ const char *name = class_name;
+
+ /* In case of REG_ICASE "upper" and "lower" match the both of
+ upper and lower cases. */
+ if ((syntax & RE_ICASE)
+ && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0))
+ name = "alpha";
+
+#ifdef RE_ENABLE_I18N
+ /* Check the space of the arrays. */
+ if (BE (*char_class_alloc == mbcset->nchar_classes, 0))
+ {
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->nchar_classes is 0. */
+ Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1;
+ /* Use realloc since array is NULL if *alloc == 0. */
+ wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
+ new_char_class_alloc);
+ if (BE (new_char_classes == NULL, 0))
+ return REG_ESPACE;
+ mbcset->char_classes = new_char_classes;
+ *char_class_alloc = new_char_class_alloc;
+ }
+ mbcset->char_classes[mbcset->nchar_classes++] = __wctype (name);
+#endif /* RE_ENABLE_I18N */
+
+#define BUILD_CHARCLASS_LOOP(ctype_func) \
+ do { \
+ if (BE (trans != NULL, 0)) \
+ { \
+ for (i = 0; i < SBC_MAX; ++i) \
+ if (ctype_func (i)) \
+ bitset_set (sbcset, trans[i]); \
+ } \
+ else \
+ { \
+ for (i = 0; i < SBC_MAX; ++i) \
+ if (ctype_func (i)) \
+ bitset_set (sbcset, i); \
+ } \
+ } while (0)
+
+ if (strcmp (name, "alnum") == 0)
+ BUILD_CHARCLASS_LOOP (isalnum);
+ else if (strcmp (name, "cntrl") == 0)
+ BUILD_CHARCLASS_LOOP (iscntrl);
+ else if (strcmp (name, "lower") == 0)
+ BUILD_CHARCLASS_LOOP (islower);
+ else if (strcmp (name, "space") == 0)
+ BUILD_CHARCLASS_LOOP (isspace);
+ else if (strcmp (name, "alpha") == 0)
+ BUILD_CHARCLASS_LOOP (isalpha);
+ else if (strcmp (name, "digit") == 0)
+ BUILD_CHARCLASS_LOOP (isdigit);
+ else if (strcmp (name, "print") == 0)
+ BUILD_CHARCLASS_LOOP (isprint);
+ else if (strcmp (name, "upper") == 0)
+ BUILD_CHARCLASS_LOOP (isupper);
+ else if (strcmp (name, "blank") == 0)
+ BUILD_CHARCLASS_LOOP (isblank);
+ else if (strcmp (name, "graph") == 0)
+ BUILD_CHARCLASS_LOOP (isgraph);
+ else if (strcmp (name, "punct") == 0)
+ BUILD_CHARCLASS_LOOP (ispunct);
+ else if (strcmp (name, "xdigit") == 0)
+ BUILD_CHARCLASS_LOOP (isxdigit);
+ else
+ return REG_ECTYPE;
+
+ return REG_NOERROR;
+}
+
+static bin_tree_t *
+build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
+ const char *class_name,
+ const char *extra, bool non_match,
+ reg_errcode_t *err)
+{
+ re_bitset_ptr_t sbcset;
+#ifdef RE_ENABLE_I18N
+ re_charset_t *mbcset;
+ Idx alloc = 0;
+#endif /* not RE_ENABLE_I18N */
+ reg_errcode_t ret;
+ re_token_t br_token;
+ bin_tree_t *tree;
+
+ sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
+#ifdef RE_ENABLE_I18N
+ mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
+#endif /* RE_ENABLE_I18N */
+
+#ifdef RE_ENABLE_I18N
+ if (BE (sbcset == NULL || mbcset == NULL, 0))
+#else /* not RE_ENABLE_I18N */
+ if (BE (sbcset == NULL, 0))
+#endif /* not RE_ENABLE_I18N */
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ if (non_match)
+ {
+#ifdef RE_ENABLE_I18N
+ mbcset->non_match = 1;
+#endif /* not RE_ENABLE_I18N */
+ }
+
+ /* We don't care the syntax in this case. */
+ ret = build_charclass (trans, sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &alloc,
+#endif /* RE_ENABLE_I18N */
+ class_name, 0);
+
+ if (BE (ret != REG_NOERROR, 0))
+ {
+ re_free (sbcset);
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif /* RE_ENABLE_I18N */
+ *err = ret;
+ return NULL;
+ }
+ /* \w match '_' also. */
+ for (; *extra; extra++)
+ bitset_set (sbcset, *extra);
+
+ /* If it is non-matching list. */
+ if (non_match)
+ bitset_not (sbcset);
+
+#ifdef RE_ENABLE_I18N
+ /* Ensure only single byte characters are set. */
+ if (dfa->mb_cur_max > 1)
+ bitset_mask (sbcset, dfa->sb_char);
+#endif
+
+ /* Build a tree for simple bracket. */
+ br_token.type = SIMPLE_BRACKET;
+ br_token.opr.sbcset = sbcset;
+ tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (tree == NULL, 0))
+ goto build_word_op_espace;
+
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ bin_tree_t *mbc_tree;
+ /* Build a tree for complex bracket. */
+ br_token.type = COMPLEX_BRACKET;
+ br_token.opr.mbcset = mbcset;
+ dfa->has_mb_node = 1;
+ mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (mbc_tree == NULL, 0))
+ goto build_word_op_espace;
+ /* Then join them by ALT node. */
+ tree = create_tree (dfa, tree, mbc_tree, OP_ALT);
+ if (BE (mbc_tree != NULL, 1))
+ return tree;
+ }
+ else
+ {
+ free_charset (mbcset);
+ return tree;
+ }
+#else /* not RE_ENABLE_I18N */
+ return tree;
+#endif /* not RE_ENABLE_I18N */
+
+ build_word_op_espace:
+ re_free (sbcset);
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif /* RE_ENABLE_I18N */
+ *err = REG_ESPACE;
+ return NULL;
+}
+
+/* This is intended for the expressions like "a{1,3}".
+ Fetch a number from 'input', and return the number.
+ Return REG_MISSING if the number field is empty like "{,1}".
+ Return RE_DUP_MAX + 1 if the number field is too large.
+ Return REG_ERROR if an error occurred. */
+
+static Idx
+fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
+{
+ Idx num = REG_MISSING;
+ unsigned char c;
+ while (1)
+ {
+ fetch_token (token, input, syntax);
+ c = token->opr.c;
+ if (BE (token->type == END_OF_RE, 0))
+ return REG_ERROR;
+ if (token->type == OP_CLOSE_DUP_NUM || c == ',')
+ break;
+ num = ((token->type != CHARACTER || c < '0' || '9' < c
+ || num == REG_ERROR)
+ ? REG_ERROR
+ : num == REG_MISSING
+ ? c - '0'
+ : MIN (RE_DUP_MAX + 1, num * 10 + c - '0'));
+ }
+ return num;
+}
+
+#ifdef RE_ENABLE_I18N
+static void
+free_charset (re_charset_t *cset)
+{
+ re_free (cset->mbchars);
+# ifdef _LIBC
+ re_free (cset->coll_syms);
+ re_free (cset->equiv_classes);
+ re_free (cset->range_starts);
+ re_free (cset->range_ends);
+# endif
+ re_free (cset->char_classes);
+ re_free (cset);
+}
+#endif /* RE_ENABLE_I18N */
+
+/* Functions for binary tree operation. */
+
+/* Create a tree node. */
+
+static bin_tree_t *
+create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
+ re_token_type_t type)
+{
+ re_token_t t;
+ t.type = type;
+ return create_token_tree (dfa, left, right, &t);
+}
+
+static bin_tree_t *
+create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
+ const re_token_t *token)
+{
+ bin_tree_t *tree;
+ if (BE (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE, 0))
+ {
+ bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1);
+
+ if (storage == NULL)
+ return NULL;
+ storage->next = dfa->str_tree_storage;
+ dfa->str_tree_storage = storage;
+ dfa->str_tree_storage_idx = 0;
+ }
+ tree = &dfa->str_tree_storage->data[dfa->str_tree_storage_idx++];
+
+ tree->parent = NULL;
+ tree->left = left;
+ tree->right = right;
+ tree->token = *token;
+ tree->token.duplicated = 0;
+ tree->token.opt_subexp = 0;
+ tree->first = NULL;
+ tree->next = NULL;
+ tree->node_idx = REG_MISSING;
+
+ if (left != NULL)
+ left->parent = tree;
+ if (right != NULL)
+ right->parent = tree;
+ return tree;
+}
+
+/* Mark the tree SRC as an optional subexpression.
+ To be called from preorder or postorder. */
+
+static reg_errcode_t
+mark_opt_subexp (void *extra, bin_tree_t *node)
+{
+ Idx idx = (uintptr_t) extra;
+ if (node->token.type == SUBEXP && node->token.opr.idx == idx)
+ node->token.opt_subexp = 1;
+
+ return REG_NOERROR;
+}
+
+/* Free the allocated memory inside NODE. */
+
+static void
+free_token (re_token_t *node)
+{
+#ifdef RE_ENABLE_I18N
+ if (node->type == COMPLEX_BRACKET && node->duplicated == 0)
+ free_charset (node->opr.mbcset);
+ else
+#endif /* RE_ENABLE_I18N */
+ if (node->type == SIMPLE_BRACKET && node->duplicated == 0)
+ re_free (node->opr.sbcset);
+}
+
+/* Worker function for tree walking. Free the allocated memory inside NODE
+ and its children. */
+
+static reg_errcode_t
+free_tree (void *extra, bin_tree_t *node)
+{
+ free_token (&node->token);
+ return REG_NOERROR;
+}
+
+
+/* Duplicate the node SRC, and return new node. This is a preorder
+ visit similar to the one implemented by the generic visitor, but
+ we need more infrastructure to maintain two parallel trees --- so,
+ it's easier to duplicate. */
+
+static bin_tree_t *
+duplicate_tree (const bin_tree_t *root, re_dfa_t *dfa)
+{
+ const bin_tree_t *node;
+ bin_tree_t *dup_root;
+ bin_tree_t **p_new = &dup_root, *dup_node = root->parent;
+
+ for (node = root; ; )
+ {
+ /* Create a new tree and link it back to the current parent. */
+ *p_new = create_token_tree (dfa, NULL, NULL, &node->token);
+ if (*p_new == NULL)
+ return NULL;
+ (*p_new)->parent = dup_node;
+ (*p_new)->token.duplicated = 1;
+ dup_node = *p_new;
+
+ /* Go to the left node, or up and to the right. */
+ if (node->left)
+ {
+ node = node->left;
+ p_new = &dup_node->left;
+ }
+ else
+ {
+ const bin_tree_t *prev = NULL;
+ while (node->right == prev || node->right == NULL)
+ {
+ prev = node;
+ node = node->parent;
+ dup_node = dup_node->parent;
+ if (!node)
+ return dup_root;
+ }
+ node = node->right;
+ p_new = &dup_node->right;
+ }
+ }
+}
diff --git a/contrib/tools/bison/gnulib/src/regex.c b/contrib/tools/bison/gnulib/src/regex.c
index 5a0332e003..bc569584c9 100644
--- a/contrib/tools/bison/gnulib/src/regex.c
+++ b/contrib/tools/bison/gnulib/src/regex.c
@@ -1,81 +1,81 @@
-/* Extended regular expression matching and search library.
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC
-# include <config.h>
-
-# if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
-# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
-# endif
-# if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
-# pragma GCC diagnostic ignored "-Wold-style-definition"
-# pragma GCC diagnostic ignored "-Wtype-limits"
-# endif
-#endif
-
-/* Make sure no one compiles this code with a C++ compiler. */
-#if defined __cplusplus && defined _LIBC
-# error "This is C code, use a C compiler"
-#endif
-
-#ifdef _LIBC
-/* We have to keep the namespace clean. */
-# define regfree(preg) __regfree (preg)
-# define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
-# define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
-# define regerror(errcode, preg, errbuf, errbuf_size) \
- __regerror(errcode, preg, errbuf, errbuf_size)
-# define re_set_registers(bu, re, nu, st, en) \
- __re_set_registers (bu, re, nu, st, en)
-# define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
- __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
-# define re_match(bufp, string, size, pos, regs) \
- __re_match (bufp, string, size, pos, regs)
-# define re_search(bufp, string, size, startpos, range, regs) \
- __re_search (bufp, string, size, startpos, range, regs)
-# define re_compile_pattern(pattern, length, bufp) \
- __re_compile_pattern (pattern, length, bufp)
-# define re_set_syntax(syntax) __re_set_syntax (syntax)
-# define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
- __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
-# define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
-
-# include "../locale/localeinfo.h"
-#endif
-
-/* On some systems, limits.h sets RE_DUP_MAX to a lower value than
- GNU regex allows. Include it before <regex.h>, which correctly
- #undefs RE_DUP_MAX and sets it to the right value. */
-#include <limits.h>
-
-#include <regex.h>
-#include "regex_internal.h"
-
-#include "regex_internal.c"
-#include "regcomp.c"
-#include "regexec.c"
-
-/* Binary backward compatibility. */
-#if _LIBC
-# include <shlib-compat.h>
-# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
-link_warning (re_max_failures, "the 're_max_failures' variable is obsolete and will go away.")
-int re_max_failures = 2000;
-# endif
-#endif
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _LIBC
+# include <config.h>
+
+# if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+# endif
+# if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wold-style-definition"
+# pragma GCC diagnostic ignored "-Wtype-limits"
+# endif
+#endif
+
+/* Make sure no one compiles this code with a C++ compiler. */
+#if defined __cplusplus && defined _LIBC
+# error "This is C code, use a C compiler"
+#endif
+
+#ifdef _LIBC
+/* We have to keep the namespace clean. */
+# define regfree(preg) __regfree (preg)
+# define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
+# define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
+# define regerror(errcode, preg, errbuf, errbuf_size) \
+ __regerror(errcode, preg, errbuf, errbuf_size)
+# define re_set_registers(bu, re, nu, st, en) \
+ __re_set_registers (bu, re, nu, st, en)
+# define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
+ __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
+# define re_match(bufp, string, size, pos, regs) \
+ __re_match (bufp, string, size, pos, regs)
+# define re_search(bufp, string, size, startpos, range, regs) \
+ __re_search (bufp, string, size, startpos, range, regs)
+# define re_compile_pattern(pattern, length, bufp) \
+ __re_compile_pattern (pattern, length, bufp)
+# define re_set_syntax(syntax) __re_set_syntax (syntax)
+# define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
+ __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
+# define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
+
+# include "../locale/localeinfo.h"
+#endif
+
+/* On some systems, limits.h sets RE_DUP_MAX to a lower value than
+ GNU regex allows. Include it before <regex.h>, which correctly
+ #undefs RE_DUP_MAX and sets it to the right value. */
+#include <limits.h>
+
+#include <regex.h>
+#include "regex_internal.h"
+
+#include "regex_internal.c"
+#include "regcomp.c"
+#include "regexec.c"
+
+/* Binary backward compatibility. */
+#if _LIBC
+# include <shlib-compat.h>
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
+link_warning (re_max_failures, "the 're_max_failures' variable is obsolete and will go away.")
+int re_max_failures = 2000;
+# endif
+#endif
diff --git a/contrib/tools/bison/gnulib/src/regex.h b/contrib/tools/bison/gnulib/src/regex.h
index 854c6edaf7..1aca73e5ee 100644
--- a/contrib/tools/bison/gnulib/src/regex.h
+++ b/contrib/tools/bison/gnulib/src/regex.h
@@ -1,667 +1,667 @@
-/* Definitions for data structures and routines for the regular
- expression library.
- Copyright (C) 1985, 1989-1993, 1995-1998, 2000-2003, 2005-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-#ifndef _REGEX_H
-#define _REGEX_H 1
-
-#include <sys/types.h>
-
-/* Allow the use in C++ code. */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Define __USE_GNU to declare GNU extensions that violate the
- POSIX name space rules. */
-#ifdef _GNU_SOURCE
-# define __USE_GNU 1
-#endif
-
-#ifdef _REGEX_LARGE_OFFSETS
-
-/* Use types and values that are wide enough to represent signed and
- unsigned byte offsets in memory. This currently works only when
- the regex code is used outside of the GNU C library; it is not yet
- supported within glibc itself, and glibc users should not define
- _REGEX_LARGE_OFFSETS. */
-
-/* The type of nonnegative object indexes. Traditionally, GNU regex
- uses 'int' for these. Code that uses __re_idx_t should work
- regardless of whether the type is signed. */
-typedef size_t __re_idx_t;
-
-/* The type of object sizes. */
-typedef size_t __re_size_t;
-
-/* The type of object sizes, in places where the traditional code
- uses unsigned long int. */
-typedef size_t __re_long_size_t;
-
-#else
-
-/* The traditional GNU regex implementation mishandles strings longer
- than INT_MAX. */
-typedef int __re_idx_t;
-typedef unsigned int __re_size_t;
-typedef unsigned long int __re_long_size_t;
-
-#endif
-
-/* The following two types have to be signed and unsigned integer type
- wide enough to hold a value of a pointer. For most ANSI compilers
- ptrdiff_t and size_t should be likely OK. Still size of these two
- types is 2 for Microsoft C. Ugh... */
-typedef long int s_reg_t;
-typedef unsigned long int active_reg_t;
-
-/* The following bits are used to determine the regexp syntax we
- recognize. The set/not-set meanings are chosen so that Emacs syntax
- remains the value 0. The bits are given in alphabetical order, and
- the definitions shifted by one from the previous bit; thus, when we
- add or remove a bit, only one other definition need change. */
-typedef unsigned long int reg_syntax_t;
-
-#ifdef __USE_GNU
-/* If this bit is not set, then \ inside a bracket expression is literal.
- If set, then such a \ quotes the following character. */
-# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
-
-/* If this bit is not set, then + and ? are operators, and \+ and \? are
- literals.
- If set, then \+ and \? are operators and + and ? are literals. */
-# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
-
-/* If this bit is set, then character classes are supported. They are:
- [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
- [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
- If not set, then character classes are not supported. */
-# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
-
-/* If this bit is set, then ^ and $ are always anchors (outside bracket
- expressions, of course).
- If this bit is not set, then it depends:
- ^ is an anchor if it is at the beginning of a regular
- expression or after an open-group or an alternation operator;
- $ is an anchor if it is at the end of a regular expression, or
- before a close-group or an alternation operator.
-
- This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
- POSIX draft 11.2 says that * etc. in leading positions is undefined.
- We already implemented a previous draft which made those constructs
- invalid, though, so we haven't changed the code back. */
-# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
-
-/* If this bit is set, then special characters are always special
- regardless of where they are in the pattern.
- If this bit is not set, then special characters are special only in
- some contexts; otherwise they are ordinary. Specifically,
- * + ? and intervals are only special when not after the beginning,
- open-group, or alternation operator. */
-# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
-
-/* If this bit is set, then *, +, ?, and { cannot be first in an re or
- immediately after an alternation or begin-group operator. */
-# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
-
-/* If this bit is set, then . matches newline.
- If not set, then it doesn't. */
-# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
-
-/* If this bit is set, then . doesn't match NUL.
- If not set, then it does. */
-# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
-
-/* If this bit is set, nonmatching lists [^...] do not match newline.
- If not set, they do. */
-# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
-
-/* If this bit is set, either \{...\} or {...} defines an
- interval, depending on RE_NO_BK_BRACES.
- If not set, \{, \}, {, and } are literals. */
-# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
-
-/* If this bit is set, +, ? and | aren't recognized as operators.
- If not set, they are. */
-# define RE_LIMITED_OPS (RE_INTERVALS << 1)
-
-/* If this bit is set, newline is an alternation operator.
- If not set, newline is literal. */
-# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
-
-/* If this bit is set, then '{...}' defines an interval, and \{ and \}
- are literals.
- If not set, then '\{...\}' defines an interval. */
-# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
-
-/* If this bit is set, (...) defines a group, and \( and \) are literals.
- If not set, \(...\) defines a group, and ( and ) are literals. */
-# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
-
-/* If this bit is set, then \<digit> matches <digit>.
- If not set, then \<digit> is a back-reference. */
-# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
-
-/* If this bit is set, then | is an alternation operator, and \| is literal.
- If not set, then \| is an alternation operator, and | is literal. */
-# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
-
-/* If this bit is set, then an ending range point collating higher
- than the starting range point, as in [z-a], is invalid.
- If not set, then when ending range point collates higher than the
- starting range point, the range is ignored. */
-# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
-
-/* If this bit is set, then an unmatched ) is ordinary.
- If not set, then an unmatched ) is invalid. */
-# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
-
-/* If this bit is set, succeed as soon as we match the whole pattern,
- without further backtracking. */
-# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
-
-/* If this bit is set, do not process the GNU regex operators.
- If not set, then the GNU regex operators are recognized. */
-# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
-
-/* If this bit is set, turn on internal regex debugging.
- If not set, and debugging was on, turn it off.
- This only works if regex.c is compiled -DDEBUG.
- We define this bit always, so that all that's needed to turn on
- debugging is to recompile regex.c; the calling code can always have
- this bit set, and it won't affect anything in the normal case. */
-# define RE_DEBUG (RE_NO_GNU_OPS << 1)
-
-/* If this bit is set, a syntactically invalid interval is treated as
- a string of ordinary characters. For example, the ERE 'a{1' is
- treated as 'a\{1'. */
-# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
-
-/* If this bit is set, then ignore case when matching.
- If not set, then case is significant. */
-# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
-
-/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
- for ^, because it is difficult to scan the regex backwards to find
- whether ^ should be special. */
-# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
-
-/* If this bit is set, then \{ cannot be first in a regex or
- immediately after an alternation, open-group or \} operator. */
-# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
-
-/* If this bit is set, then no_sub will be set to 1 during
- re_compile_pattern. */
-# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
-#endif
-
-/* This global variable defines the particular regexp syntax to use (for
- some interfaces). When a regexp is compiled, the syntax used is
- stored in the pattern buffer, so changing this does not affect
- already-compiled regexps. */
-extern reg_syntax_t re_syntax_options;
-
-#ifdef __USE_GNU
-/* Define combinations of the above bits for the standard possibilities.
- (The [[[ comments delimit what gets put into the Texinfo file, so
- don't delete them!) */
-/* [[[begin syntaxes]]] */
-# define RE_SYNTAX_EMACS 0
-
-# define RE_SYNTAX_AWK \
- (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
- | RE_NO_BK_PARENS | RE_NO_BK_REFS \
- | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
- | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
- | RE_CHAR_CLASSES \
- | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
-
-# define RE_SYNTAX_GNU_AWK \
- ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
- | RE_INVALID_INTERVAL_ORD) \
- & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS \
- | RE_CONTEXT_INVALID_OPS ))
-
-# define RE_SYNTAX_POSIX_AWK \
- (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
- | RE_INTERVALS | RE_NO_GNU_OPS \
- | RE_INVALID_INTERVAL_ORD)
-
-# define RE_SYNTAX_GREP \
- (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
- | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
- | RE_NEWLINE_ALT)
-
-# define RE_SYNTAX_EGREP \
- (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
- | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
- | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
- | RE_NO_BK_VBAR)
-
-# define RE_SYNTAX_POSIX_EGREP \
- (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
- | RE_INVALID_INTERVAL_ORD)
-
-/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
-# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
-
-# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
-
-/* Syntax bits common to both basic and extended POSIX regex syntax. */
-# define _RE_SYNTAX_POSIX_COMMON \
- (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
- | RE_INTERVALS | RE_NO_EMPTY_RANGES)
-
-# define RE_SYNTAX_POSIX_BASIC \
- (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
-
-/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
- RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
- isn't minimal, since other operators, such as \`, aren't disabled. */
-# define RE_SYNTAX_POSIX_MINIMAL_BASIC \
- (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
-
-# define RE_SYNTAX_POSIX_EXTENDED \
- (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
- | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
- | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
- | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
-
-/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
- removed and RE_NO_BK_REFS is added. */
-# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
- (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
- | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
- | RE_NO_BK_PARENS | RE_NO_BK_REFS \
- | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
-/* [[[end syntaxes]]] */
-
-/* Maximum number of duplicates an interval can allow. POSIX-conforming
- systems might define this in <limits.h>, but we want our
- value, so remove any previous define. */
-# ifdef _REGEX_INCLUDE_LIMITS_H
-# include <limits.h>
-# endif
-# ifdef RE_DUP_MAX
-# undef RE_DUP_MAX
-# endif
-
-/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
- the counter as a 2-byte signed integer. This is no longer true, so
- RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
- ((SIZE_MAX - 9) / 10) if _REGEX_LARGE_OFFSETS is defined.
- However, there would be a huge performance problem if someone
- actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
- its historical value. */
-# define RE_DUP_MAX (0x7fff)
-#endif
-
-
-/* POSIX 'cflags' bits (i.e., information for 'regcomp'). */
-
-/* If this bit is set, then use extended regular expression syntax.
- If not set, then use basic regular expression syntax. */
-#define REG_EXTENDED 1
-
-/* If this bit is set, then ignore case when matching.
- If not set, then case is significant. */
-#define REG_ICASE (1 << 1)
-
-/* If this bit is set, then anchors do not match at newline
- characters in the string.
- If not set, then anchors do match at newlines. */
-#define REG_NEWLINE (1 << 2)
-
-/* If this bit is set, then report only success or fail in regexec.
- If not set, then returns differ between not matching and errors. */
-#define REG_NOSUB (1 << 3)
-
-
-/* POSIX 'eflags' bits (i.e., information for regexec). */
-
-/* If this bit is set, then the beginning-of-line operator doesn't match
- the beginning of the string (presumably because it's not the
- beginning of a line).
- If not set, then the beginning-of-line operator does match the
- beginning of the string. */
-#define REG_NOTBOL 1
-
-/* Like REG_NOTBOL, except for the end-of-line. */
-#define REG_NOTEOL (1 << 1)
-
-/* Use PMATCH[0] to delimit the start and end of the search in the
- buffer. */
-#define REG_STARTEND (1 << 2)
-
-
-/* If any error codes are removed, changed, or added, update the
- '__re_error_msgid' table in regcomp.c. */
-
-typedef enum
-{
- _REG_ENOSYS = -1, /* This will never happen for this implementation. */
- _REG_NOERROR = 0, /* Success. */
- _REG_NOMATCH, /* Didn't find a match (for regexec). */
-
- /* POSIX regcomp return error codes. (In the order listed in the
- standard.) */
- _REG_BADPAT, /* Invalid pattern. */
- _REG_ECOLLATE, /* Invalid collating element. */
- _REG_ECTYPE, /* Invalid character class name. */
- _REG_EESCAPE, /* Trailing backslash. */
- _REG_ESUBREG, /* Invalid back reference. */
- _REG_EBRACK, /* Unmatched left bracket. */
- _REG_EPAREN, /* Parenthesis imbalance. */
- _REG_EBRACE, /* Unmatched \{. */
- _REG_BADBR, /* Invalid contents of \{\}. */
- _REG_ERANGE, /* Invalid range end. */
- _REG_ESPACE, /* Ran out of memory. */
- _REG_BADRPT, /* No preceding re for repetition op. */
-
- /* Error codes we've added. */
- _REG_EEND, /* Premature end. */
- _REG_ESIZE, /* Too large (e.g., repeat count too large). */
- _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
-} reg_errcode_t;
-
-#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
-# define REG_ENOSYS _REG_ENOSYS
-#endif
-#define REG_NOERROR _REG_NOERROR
-#define REG_NOMATCH _REG_NOMATCH
-#define REG_BADPAT _REG_BADPAT
-#define REG_ECOLLATE _REG_ECOLLATE
-#define REG_ECTYPE _REG_ECTYPE
-#define REG_EESCAPE _REG_EESCAPE
-#define REG_ESUBREG _REG_ESUBREG
-#define REG_EBRACK _REG_EBRACK
-#define REG_EPAREN _REG_EPAREN
-#define REG_EBRACE _REG_EBRACE
-#define REG_BADBR _REG_BADBR
-#define REG_ERANGE _REG_ERANGE
-#define REG_ESPACE _REG_ESPACE
-#define REG_BADRPT _REG_BADRPT
-#define REG_EEND _REG_EEND
-#define REG_ESIZE _REG_ESIZE
-#define REG_ERPAREN _REG_ERPAREN
-
-/* This data structure represents a compiled pattern. Before calling
- the pattern compiler, the fields 'buffer', 'allocated', 'fastmap',
- and 'translate' can be set. After the pattern has been compiled,
- the fields 're_nsub', 'not_bol' and 'not_eol' are available. All
- other fields are private to the regex routines. */
-
-#ifndef RE_TRANSLATE_TYPE
-# define __RE_TRANSLATE_TYPE unsigned char *
-# ifdef __USE_GNU
-# define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE
-# endif
-#endif
-
-#ifdef __USE_GNU
-# define __REPB_PREFIX(name) name
-#else
-# define __REPB_PREFIX(name) __##name
-#endif
-
-struct re_pattern_buffer
-{
- /* Space that holds the compiled pattern. The type
- 'struct re_dfa_t' is private and is not declared here. */
- struct re_dfa_t *__REPB_PREFIX(buffer);
-
- /* Number of bytes to which 'buffer' points. */
- __re_long_size_t __REPB_PREFIX(allocated);
-
- /* Number of bytes actually used in 'buffer'. */
- __re_long_size_t __REPB_PREFIX(used);
-
- /* Syntax setting with which the pattern was compiled. */
- reg_syntax_t __REPB_PREFIX(syntax);
-
- /* Pointer to a fastmap, if any, otherwise zero. re_search uses the
- fastmap, if there is one, to skip over impossible starting points
- for matches. */
- char *__REPB_PREFIX(fastmap);
-
- /* Either a translate table to apply to all characters before
- comparing them, or zero for no translation. The translation is
- applied to a pattern when it is compiled and to a string when it
- is matched. */
- __RE_TRANSLATE_TYPE __REPB_PREFIX(translate);
-
- /* Number of subexpressions found by the compiler. */
- size_t re_nsub;
-
- /* Zero if this pattern cannot match the empty string, one else.
- Well, in truth it's used only in 're_search_2', to see whether or
- not we should use the fastmap, so we don't set this absolutely
- perfectly; see 're_compile_fastmap' (the "duplicate" case). */
- unsigned __REPB_PREFIX(can_be_null) : 1;
-
- /* If REGS_UNALLOCATED, allocate space in the 'regs' structure
- for 'max (RE_NREGS, re_nsub + 1)' groups.
- If REGS_REALLOCATE, reallocate space if necessary.
- If REGS_FIXED, use what's there. */
-#ifdef __USE_GNU
-# define REGS_UNALLOCATED 0
-# define REGS_REALLOCATE 1
-# define REGS_FIXED 2
-#endif
- unsigned __REPB_PREFIX(regs_allocated) : 2;
-
- /* Set to zero when 're_compile_pattern' compiles a pattern; set to
- one by 're_compile_fastmap' if it updates the fastmap. */
- unsigned __REPB_PREFIX(fastmap_accurate) : 1;
-
- /* If set, 're_match_2' does not return information about
- subexpressions. */
- unsigned __REPB_PREFIX(no_sub) : 1;
-
- /* If set, a beginning-of-line anchor doesn't match at the beginning
- of the string. */
- unsigned __REPB_PREFIX(not_bol) : 1;
-
- /* Similarly for an end-of-line anchor. */
- unsigned __REPB_PREFIX(not_eol) : 1;
-
- /* If true, an anchor at a newline matches. */
- unsigned __REPB_PREFIX(newline_anchor) : 1;
-};
-
-typedef struct re_pattern_buffer regex_t;
-
-/* Type for byte offsets within the string. POSIX mandates this. */
-#ifdef _REGEX_LARGE_OFFSETS
-/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as
- ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t
- is wider than ssize_t, so ssize_t is safe. */
-typedef ssize_t regoff_t;
-#else
-/* The traditional GNU regex implementation mishandles strings longer
- than INT_MAX. */
-typedef int regoff_t;
-#endif
-
-
-#ifdef __USE_GNU
-/* This is the structure we store register match data in. See
- regex.texinfo for a full description of what registers match. */
-struct re_registers
-{
- __re_size_t num_regs;
- regoff_t *start;
- regoff_t *end;
-};
-
-
-/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
- 're_match_2' returns information about at least this many registers
- the first time a 'regs' structure is passed. */
-# ifndef RE_NREGS
-# define RE_NREGS 30
-# endif
-#endif
-
-
-/* POSIX specification for registers. Aside from the different names than
- 're_registers', POSIX uses an array of structures, instead of a
- structure of arrays. */
-typedef struct
-{
- regoff_t rm_so; /* Byte offset from string's start to substring's start. */
- regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
-} regmatch_t;
-
-/* Declarations for routines. */
-
-#ifdef __USE_GNU
-/* Sets the current default syntax to SYNTAX, and return the old syntax.
- You can also simply assign to the 're_syntax_options' variable. */
-extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
-
-/* Compile the regular expression PATTERN, with length LENGTH
- and syntax given by the global 're_syntax_options', into the buffer
- BUFFER. Return NULL if successful, and an error string if not.
-
- To free the allocated storage, you must call 'regfree' on BUFFER.
- Note that the translate table must either have been initialised by
- 'regcomp', with a malloc'ed value, or set to NULL before calling
- 'regfree'. */
-extern const char *re_compile_pattern (const char *__pattern, size_t __length,
- struct re_pattern_buffer *__buffer);
-
-
-/* Compile a fastmap for the compiled pattern in BUFFER; used to
- accelerate searches. Return 0 if successful and -2 if was an
- internal error. */
-extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
-
-
-/* Search in the string STRING (with length LENGTH) for the pattern
- compiled into BUFFER. Start searching at position START, for RANGE
- characters. Return the starting position of the match, -1 for no
- match, or -2 for an internal error. Also return register
- information in REGS (if REGS and BUFFER->no_sub are nonzero). */
-extern regoff_t re_search (struct re_pattern_buffer *__buffer,
- const char *__string, __re_idx_t __length,
- __re_idx_t __start, regoff_t __range,
- struct re_registers *__regs);
-
-
-/* Like 're_search', but search in the concatenation of STRING1 and
- STRING2. Also, stop searching at index START + STOP. */
-extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
- const char *__string1, __re_idx_t __length1,
- const char *__string2, __re_idx_t __length2,
- __re_idx_t __start, regoff_t __range,
- struct re_registers *__regs,
- __re_idx_t __stop);
-
-
-/* Like 're_search', but return how many characters in STRING the regexp
- in BUFFER matched, starting at position START. */
-extern regoff_t re_match (struct re_pattern_buffer *__buffer,
- const char *__string, __re_idx_t __length,
- __re_idx_t __start, struct re_registers *__regs);
-
-
-/* Relates to 're_match' as 're_search_2' relates to 're_search'. */
-extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
- const char *__string1, __re_idx_t __length1,
- const char *__string2, __re_idx_t __length2,
- __re_idx_t __start, struct re_registers *__regs,
- __re_idx_t __stop);
-
-
-/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
- ENDS. Subsequent matches using BUFFER and REGS will use this memory
- for recording register information. STARTS and ENDS must be
- allocated with malloc, and must each be at least 'NUM_REGS * sizeof
- (regoff_t)' bytes long.
-
- If NUM_REGS == 0, then subsequent matches should allocate their own
- register data.
-
- Unless this function is called, the first search or match using
- BUFFER will allocate its own register data, without
- freeing the old data. */
-extern void re_set_registers (struct re_pattern_buffer *__buffer,
- struct re_registers *__regs,
- __re_size_t __num_regs,
- regoff_t *__starts, regoff_t *__ends);
-#endif /* Use GNU */
-
-#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_BSD)
-# ifndef _CRAY
-/* 4.2 bsd compatibility. */
-extern char *re_comp (const char *);
-extern int re_exec (const char *);
-# endif
-#endif
-
-/* GCC 2.95 and later have "__restrict"; C99 compilers have
- "restrict", and "configure" may have defined "restrict".
- Other compilers use __restrict, __restrict__, and _Restrict, and
- 'configure' might #define 'restrict' to those words, so pick a
- different name. */
-#ifndef _Restrict_
-# if 199901L <= __STDC_VERSION__
-# define _Restrict_ restrict
-# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
-# define _Restrict_ __restrict
-# else
-# define _Restrict_
-# endif
-#endif
-/* gcc 3.1 and up support the [restrict] syntax. Don't trust
- sys/cdefs.h's definition of __restrict_arr, though, as it
- mishandles gcc -ansi -pedantic. */
-#ifndef _Restrict_arr_
-# if ((199901L <= __STDC_VERSION__ \
- || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \
- && !defined __STRICT_ANSI__)) \
- && !defined __GNUG__)
-# define _Restrict_arr_ _Restrict_
-# else
-# define _Restrict_arr_
-# endif
-#endif
-
-/* POSIX compatibility. */
-extern int regcomp (regex_t *_Restrict_ __preg,
- const char *_Restrict_ __pattern,
- int __cflags);
-
-extern int regexec (const regex_t *_Restrict_ __preg,
- const char *_Restrict_ __string, size_t __nmatch,
- regmatch_t __pmatch[_Restrict_arr_],
- int __eflags);
-
-extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
- char *_Restrict_ __errbuf, size_t __errbuf_size);
-
-extern void regfree (regex_t *__preg);
-
-
-#ifdef __cplusplus
-}
-#endif /* C++ */
-
-#endif /* regex.h */
+/* Definitions for data structures and routines for the regular
+ expression library.
+ Copyright (C) 1985, 1989-1993, 1995-1998, 2000-2003, 2005-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _REGEX_H
+#define _REGEX_H 1
+
+#include <sys/types.h>
+
+/* Allow the use in C++ code. */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Define __USE_GNU to declare GNU extensions that violate the
+ POSIX name space rules. */
+#ifdef _GNU_SOURCE
+# define __USE_GNU 1
+#endif
+
+#ifdef _REGEX_LARGE_OFFSETS
+
+/* Use types and values that are wide enough to represent signed and
+ unsigned byte offsets in memory. This currently works only when
+ the regex code is used outside of the GNU C library; it is not yet
+ supported within glibc itself, and glibc users should not define
+ _REGEX_LARGE_OFFSETS. */
+
+/* The type of nonnegative object indexes. Traditionally, GNU regex
+ uses 'int' for these. Code that uses __re_idx_t should work
+ regardless of whether the type is signed. */
+typedef size_t __re_idx_t;
+
+/* The type of object sizes. */
+typedef size_t __re_size_t;
+
+/* The type of object sizes, in places where the traditional code
+ uses unsigned long int. */
+typedef size_t __re_long_size_t;
+
+#else
+
+/* The traditional GNU regex implementation mishandles strings longer
+ than INT_MAX. */
+typedef int __re_idx_t;
+typedef unsigned int __re_size_t;
+typedef unsigned long int __re_long_size_t;
+
+#endif
+
+/* The following two types have to be signed and unsigned integer type
+ wide enough to hold a value of a pointer. For most ANSI compilers
+ ptrdiff_t and size_t should be likely OK. Still size of these two
+ types is 2 for Microsoft C. Ugh... */
+typedef long int s_reg_t;
+typedef unsigned long int active_reg_t;
+
+/* The following bits are used to determine the regexp syntax we
+ recognize. The set/not-set meanings are chosen so that Emacs syntax
+ remains the value 0. The bits are given in alphabetical order, and
+ the definitions shifted by one from the previous bit; thus, when we
+ add or remove a bit, only one other definition need change. */
+typedef unsigned long int reg_syntax_t;
+
+#ifdef __USE_GNU
+/* If this bit is not set, then \ inside a bracket expression is literal.
+ If set, then such a \ quotes the following character. */
+# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
+
+/* If this bit is not set, then + and ? are operators, and \+ and \? are
+ literals.
+ If set, then \+ and \? are operators and + and ? are literals. */
+# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
+
+/* If this bit is set, then character classes are supported. They are:
+ [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
+ [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
+ If not set, then character classes are not supported. */
+# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
+
+/* If this bit is set, then ^ and $ are always anchors (outside bracket
+ expressions, of course).
+ If this bit is not set, then it depends:
+ ^ is an anchor if it is at the beginning of a regular
+ expression or after an open-group or an alternation operator;
+ $ is an anchor if it is at the end of a regular expression, or
+ before a close-group or an alternation operator.
+
+ This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
+ POSIX draft 11.2 says that * etc. in leading positions is undefined.
+ We already implemented a previous draft which made those constructs
+ invalid, though, so we haven't changed the code back. */
+# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
+
+/* If this bit is set, then special characters are always special
+ regardless of where they are in the pattern.
+ If this bit is not set, then special characters are special only in
+ some contexts; otherwise they are ordinary. Specifically,
+ * + ? and intervals are only special when not after the beginning,
+ open-group, or alternation operator. */
+# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
+
+/* If this bit is set, then *, +, ?, and { cannot be first in an re or
+ immediately after an alternation or begin-group operator. */
+# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
+
+/* If this bit is set, then . matches newline.
+ If not set, then it doesn't. */
+# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
+
+/* If this bit is set, then . doesn't match NUL.
+ If not set, then it does. */
+# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
+
+/* If this bit is set, nonmatching lists [^...] do not match newline.
+ If not set, they do. */
+# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
+
+/* If this bit is set, either \{...\} or {...} defines an
+ interval, depending on RE_NO_BK_BRACES.
+ If not set, \{, \}, {, and } are literals. */
+# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
+
+/* If this bit is set, +, ? and | aren't recognized as operators.
+ If not set, they are. */
+# define RE_LIMITED_OPS (RE_INTERVALS << 1)
+
+/* If this bit is set, newline is an alternation operator.
+ If not set, newline is literal. */
+# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
+
+/* If this bit is set, then '{...}' defines an interval, and \{ and \}
+ are literals.
+ If not set, then '\{...\}' defines an interval. */
+# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
+
+/* If this bit is set, (...) defines a group, and \( and \) are literals.
+ If not set, \(...\) defines a group, and ( and ) are literals. */
+# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
+
+/* If this bit is set, then \<digit> matches <digit>.
+ If not set, then \<digit> is a back-reference. */
+# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
+
+/* If this bit is set, then | is an alternation operator, and \| is literal.
+ If not set, then \| is an alternation operator, and | is literal. */
+# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
+
+/* If this bit is set, then an ending range point collating higher
+ than the starting range point, as in [z-a], is invalid.
+ If not set, then when ending range point collates higher than the
+ starting range point, the range is ignored. */
+# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
+
+/* If this bit is set, then an unmatched ) is ordinary.
+ If not set, then an unmatched ) is invalid. */
+# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
+
+/* If this bit is set, succeed as soon as we match the whole pattern,
+ without further backtracking. */
+# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
+
+/* If this bit is set, do not process the GNU regex operators.
+ If not set, then the GNU regex operators are recognized. */
+# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
+
+/* If this bit is set, turn on internal regex debugging.
+ If not set, and debugging was on, turn it off.
+ This only works if regex.c is compiled -DDEBUG.
+ We define this bit always, so that all that's needed to turn on
+ debugging is to recompile regex.c; the calling code can always have
+ this bit set, and it won't affect anything in the normal case. */
+# define RE_DEBUG (RE_NO_GNU_OPS << 1)
+
+/* If this bit is set, a syntactically invalid interval is treated as
+ a string of ordinary characters. For example, the ERE 'a{1' is
+ treated as 'a\{1'. */
+# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
+
+/* If this bit is set, then ignore case when matching.
+ If not set, then case is significant. */
+# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
+
+/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
+ for ^, because it is difficult to scan the regex backwards to find
+ whether ^ should be special. */
+# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
+
+/* If this bit is set, then \{ cannot be first in a regex or
+ immediately after an alternation, open-group or \} operator. */
+# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
+
+/* If this bit is set, then no_sub will be set to 1 during
+ re_compile_pattern. */
+# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
+#endif
+
+/* This global variable defines the particular regexp syntax to use (for
+ some interfaces). When a regexp is compiled, the syntax used is
+ stored in the pattern buffer, so changing this does not affect
+ already-compiled regexps. */
+extern reg_syntax_t re_syntax_options;
+
+#ifdef __USE_GNU
+/* Define combinations of the above bits for the standard possibilities.
+ (The [[[ comments delimit what gets put into the Texinfo file, so
+ don't delete them!) */
+/* [[[begin syntaxes]]] */
+# define RE_SYNTAX_EMACS 0
+
+# define RE_SYNTAX_AWK \
+ (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
+ | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CHAR_CLASSES \
+ | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
+
+# define RE_SYNTAX_GNU_AWK \
+ ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
+ | RE_INVALID_INTERVAL_ORD) \
+ & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS \
+ | RE_CONTEXT_INVALID_OPS ))
+
+# define RE_SYNTAX_POSIX_AWK \
+ (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
+ | RE_INTERVALS | RE_NO_GNU_OPS \
+ | RE_INVALID_INTERVAL_ORD)
+
+# define RE_SYNTAX_GREP \
+ (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
+ | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
+ | RE_NEWLINE_ALT)
+
+# define RE_SYNTAX_EGREP \
+ (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
+ | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
+ | RE_NO_BK_VBAR)
+
+# define RE_SYNTAX_POSIX_EGREP \
+ (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
+ | RE_INVALID_INTERVAL_ORD)
+
+/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
+# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
+
+# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
+
+/* Syntax bits common to both basic and extended POSIX regex syntax. */
+# define _RE_SYNTAX_POSIX_COMMON \
+ (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
+ | RE_INTERVALS | RE_NO_EMPTY_RANGES)
+
+# define RE_SYNTAX_POSIX_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
+
+/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
+ RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
+ isn't minimal, since other operators, such as \`, aren't disabled. */
+# define RE_SYNTAX_POSIX_MINIMAL_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
+
+# define RE_SYNTAX_POSIX_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
+ | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
+
+/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
+ removed and RE_NO_BK_REFS is added. */
+# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
+/* [[[end syntaxes]]] */
+
+/* Maximum number of duplicates an interval can allow. POSIX-conforming
+ systems might define this in <limits.h>, but we want our
+ value, so remove any previous define. */
+# ifdef _REGEX_INCLUDE_LIMITS_H
+# include <limits.h>
+# endif
+# ifdef RE_DUP_MAX
+# undef RE_DUP_MAX
+# endif
+
+/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
+ the counter as a 2-byte signed integer. This is no longer true, so
+ RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
+ ((SIZE_MAX - 9) / 10) if _REGEX_LARGE_OFFSETS is defined.
+ However, there would be a huge performance problem if someone
+ actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
+ its historical value. */
+# define RE_DUP_MAX (0x7fff)
+#endif
+
+
+/* POSIX 'cflags' bits (i.e., information for 'regcomp'). */
+
+/* If this bit is set, then use extended regular expression syntax.
+ If not set, then use basic regular expression syntax. */
+#define REG_EXTENDED 1
+
+/* If this bit is set, then ignore case when matching.
+ If not set, then case is significant. */
+#define REG_ICASE (1 << 1)
+
+/* If this bit is set, then anchors do not match at newline
+ characters in the string.
+ If not set, then anchors do match at newlines. */
+#define REG_NEWLINE (1 << 2)
+
+/* If this bit is set, then report only success or fail in regexec.
+ If not set, then returns differ between not matching and errors. */
+#define REG_NOSUB (1 << 3)
+
+
+/* POSIX 'eflags' bits (i.e., information for regexec). */
+
+/* If this bit is set, then the beginning-of-line operator doesn't match
+ the beginning of the string (presumably because it's not the
+ beginning of a line).
+ If not set, then the beginning-of-line operator does match the
+ beginning of the string. */
+#define REG_NOTBOL 1
+
+/* Like REG_NOTBOL, except for the end-of-line. */
+#define REG_NOTEOL (1 << 1)
+
+/* Use PMATCH[0] to delimit the start and end of the search in the
+ buffer. */
+#define REG_STARTEND (1 << 2)
+
+
+/* If any error codes are removed, changed, or added, update the
+ '__re_error_msgid' table in regcomp.c. */
+
+typedef enum
+{
+ _REG_ENOSYS = -1, /* This will never happen for this implementation. */
+ _REG_NOERROR = 0, /* Success. */
+ _REG_NOMATCH, /* Didn't find a match (for regexec). */
+
+ /* POSIX regcomp return error codes. (In the order listed in the
+ standard.) */
+ _REG_BADPAT, /* Invalid pattern. */
+ _REG_ECOLLATE, /* Invalid collating element. */
+ _REG_ECTYPE, /* Invalid character class name. */
+ _REG_EESCAPE, /* Trailing backslash. */
+ _REG_ESUBREG, /* Invalid back reference. */
+ _REG_EBRACK, /* Unmatched left bracket. */
+ _REG_EPAREN, /* Parenthesis imbalance. */
+ _REG_EBRACE, /* Unmatched \{. */
+ _REG_BADBR, /* Invalid contents of \{\}. */
+ _REG_ERANGE, /* Invalid range end. */
+ _REG_ESPACE, /* Ran out of memory. */
+ _REG_BADRPT, /* No preceding re for repetition op. */
+
+ /* Error codes we've added. */
+ _REG_EEND, /* Premature end. */
+ _REG_ESIZE, /* Too large (e.g., repeat count too large). */
+ _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
+} reg_errcode_t;
+
+#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
+# define REG_ENOSYS _REG_ENOSYS
+#endif
+#define REG_NOERROR _REG_NOERROR
+#define REG_NOMATCH _REG_NOMATCH
+#define REG_BADPAT _REG_BADPAT
+#define REG_ECOLLATE _REG_ECOLLATE
+#define REG_ECTYPE _REG_ECTYPE
+#define REG_EESCAPE _REG_EESCAPE
+#define REG_ESUBREG _REG_ESUBREG
+#define REG_EBRACK _REG_EBRACK
+#define REG_EPAREN _REG_EPAREN
+#define REG_EBRACE _REG_EBRACE
+#define REG_BADBR _REG_BADBR
+#define REG_ERANGE _REG_ERANGE
+#define REG_ESPACE _REG_ESPACE
+#define REG_BADRPT _REG_BADRPT
+#define REG_EEND _REG_EEND
+#define REG_ESIZE _REG_ESIZE
+#define REG_ERPAREN _REG_ERPAREN
+
+/* This data structure represents a compiled pattern. Before calling
+ the pattern compiler, the fields 'buffer', 'allocated', 'fastmap',
+ and 'translate' can be set. After the pattern has been compiled,
+ the fields 're_nsub', 'not_bol' and 'not_eol' are available. All
+ other fields are private to the regex routines. */
+
+#ifndef RE_TRANSLATE_TYPE
+# define __RE_TRANSLATE_TYPE unsigned char *
+# ifdef __USE_GNU
+# define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE
+# endif
+#endif
+
+#ifdef __USE_GNU
+# define __REPB_PREFIX(name) name
+#else
+# define __REPB_PREFIX(name) __##name
+#endif
+
+struct re_pattern_buffer
+{
+ /* Space that holds the compiled pattern. The type
+ 'struct re_dfa_t' is private and is not declared here. */
+ struct re_dfa_t *__REPB_PREFIX(buffer);
+
+ /* Number of bytes to which 'buffer' points. */
+ __re_long_size_t __REPB_PREFIX(allocated);
+
+ /* Number of bytes actually used in 'buffer'. */
+ __re_long_size_t __REPB_PREFIX(used);
+
+ /* Syntax setting with which the pattern was compiled. */
+ reg_syntax_t __REPB_PREFIX(syntax);
+
+ /* Pointer to a fastmap, if any, otherwise zero. re_search uses the
+ fastmap, if there is one, to skip over impossible starting points
+ for matches. */
+ char *__REPB_PREFIX(fastmap);
+
+ /* Either a translate table to apply to all characters before
+ comparing them, or zero for no translation. The translation is
+ applied to a pattern when it is compiled and to a string when it
+ is matched. */
+ __RE_TRANSLATE_TYPE __REPB_PREFIX(translate);
+
+ /* Number of subexpressions found by the compiler. */
+ size_t re_nsub;
+
+ /* Zero if this pattern cannot match the empty string, one else.
+ Well, in truth it's used only in 're_search_2', to see whether or
+ not we should use the fastmap, so we don't set this absolutely
+ perfectly; see 're_compile_fastmap' (the "duplicate" case). */
+ unsigned __REPB_PREFIX(can_be_null) : 1;
+
+ /* If REGS_UNALLOCATED, allocate space in the 'regs' structure
+ for 'max (RE_NREGS, re_nsub + 1)' groups.
+ If REGS_REALLOCATE, reallocate space if necessary.
+ If REGS_FIXED, use what's there. */
+#ifdef __USE_GNU
+# define REGS_UNALLOCATED 0
+# define REGS_REALLOCATE 1
+# define REGS_FIXED 2
+#endif
+ unsigned __REPB_PREFIX(regs_allocated) : 2;
+
+ /* Set to zero when 're_compile_pattern' compiles a pattern; set to
+ one by 're_compile_fastmap' if it updates the fastmap. */
+ unsigned __REPB_PREFIX(fastmap_accurate) : 1;
+
+ /* If set, 're_match_2' does not return information about
+ subexpressions. */
+ unsigned __REPB_PREFIX(no_sub) : 1;
+
+ /* If set, a beginning-of-line anchor doesn't match at the beginning
+ of the string. */
+ unsigned __REPB_PREFIX(not_bol) : 1;
+
+ /* Similarly for an end-of-line anchor. */
+ unsigned __REPB_PREFIX(not_eol) : 1;
+
+ /* If true, an anchor at a newline matches. */
+ unsigned __REPB_PREFIX(newline_anchor) : 1;
+};
+
+typedef struct re_pattern_buffer regex_t;
+
+/* Type for byte offsets within the string. POSIX mandates this. */
+#ifdef _REGEX_LARGE_OFFSETS
+/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as
+ ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t
+ is wider than ssize_t, so ssize_t is safe. */
+typedef ssize_t regoff_t;
+#else
+/* The traditional GNU regex implementation mishandles strings longer
+ than INT_MAX. */
+typedef int regoff_t;
+#endif
+
+
+#ifdef __USE_GNU
+/* This is the structure we store register match data in. See
+ regex.texinfo for a full description of what registers match. */
+struct re_registers
+{
+ __re_size_t num_regs;
+ regoff_t *start;
+ regoff_t *end;
+};
+
+
+/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
+ 're_match_2' returns information about at least this many registers
+ the first time a 'regs' structure is passed. */
+# ifndef RE_NREGS
+# define RE_NREGS 30
+# endif
+#endif
+
+
+/* POSIX specification for registers. Aside from the different names than
+ 're_registers', POSIX uses an array of structures, instead of a
+ structure of arrays. */
+typedef struct
+{
+ regoff_t rm_so; /* Byte offset from string's start to substring's start. */
+ regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
+} regmatch_t;
+
+/* Declarations for routines. */
+
+#ifdef __USE_GNU
+/* Sets the current default syntax to SYNTAX, and return the old syntax.
+ You can also simply assign to the 're_syntax_options' variable. */
+extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
+
+/* Compile the regular expression PATTERN, with length LENGTH
+ and syntax given by the global 're_syntax_options', into the buffer
+ BUFFER. Return NULL if successful, and an error string if not.
+
+ To free the allocated storage, you must call 'regfree' on BUFFER.
+ Note that the translate table must either have been initialised by
+ 'regcomp', with a malloc'ed value, or set to NULL before calling
+ 'regfree'. */
+extern const char *re_compile_pattern (const char *__pattern, size_t __length,
+ struct re_pattern_buffer *__buffer);
+
+
+/* Compile a fastmap for the compiled pattern in BUFFER; used to
+ accelerate searches. Return 0 if successful and -2 if was an
+ internal error. */
+extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
+
+
+/* Search in the string STRING (with length LENGTH) for the pattern
+ compiled into BUFFER. Start searching at position START, for RANGE
+ characters. Return the starting position of the match, -1 for no
+ match, or -2 for an internal error. Also return register
+ information in REGS (if REGS and BUFFER->no_sub are nonzero). */
+extern regoff_t re_search (struct re_pattern_buffer *__buffer,
+ const char *__string, __re_idx_t __length,
+ __re_idx_t __start, regoff_t __range,
+ struct re_registers *__regs);
+
+
+/* Like 're_search', but search in the concatenation of STRING1 and
+ STRING2. Also, stop searching at index START + STOP. */
+extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
+ const char *__string1, __re_idx_t __length1,
+ const char *__string2, __re_idx_t __length2,
+ __re_idx_t __start, regoff_t __range,
+ struct re_registers *__regs,
+ __re_idx_t __stop);
+
+
+/* Like 're_search', but return how many characters in STRING the regexp
+ in BUFFER matched, starting at position START. */
+extern regoff_t re_match (struct re_pattern_buffer *__buffer,
+ const char *__string, __re_idx_t __length,
+ __re_idx_t __start, struct re_registers *__regs);
+
+
+/* Relates to 're_match' as 're_search_2' relates to 're_search'. */
+extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
+ const char *__string1, __re_idx_t __length1,
+ const char *__string2, __re_idx_t __length2,
+ __re_idx_t __start, struct re_registers *__regs,
+ __re_idx_t __stop);
+
+
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
+ ENDS. Subsequent matches using BUFFER and REGS will use this memory
+ for recording register information. STARTS and ENDS must be
+ allocated with malloc, and must each be at least 'NUM_REGS * sizeof
+ (regoff_t)' bytes long.
+
+ If NUM_REGS == 0, then subsequent matches should allocate their own
+ register data.
+
+ Unless this function is called, the first search or match using
+ BUFFER will allocate its own register data, without
+ freeing the old data. */
+extern void re_set_registers (struct re_pattern_buffer *__buffer,
+ struct re_registers *__regs,
+ __re_size_t __num_regs,
+ regoff_t *__starts, regoff_t *__ends);
+#endif /* Use GNU */
+
+#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_BSD)
+# ifndef _CRAY
+/* 4.2 bsd compatibility. */
+extern char *re_comp (const char *);
+extern int re_exec (const char *);
+# endif
+#endif
+
+/* GCC 2.95 and later have "__restrict"; C99 compilers have
+ "restrict", and "configure" may have defined "restrict".
+ Other compilers use __restrict, __restrict__, and _Restrict, and
+ 'configure' might #define 'restrict' to those words, so pick a
+ different name. */
+#ifndef _Restrict_
+# if 199901L <= __STDC_VERSION__
+# define _Restrict_ restrict
+# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
+# define _Restrict_ __restrict
+# else
+# define _Restrict_
+# endif
+#endif
+/* gcc 3.1 and up support the [restrict] syntax. Don't trust
+ sys/cdefs.h's definition of __restrict_arr, though, as it
+ mishandles gcc -ansi -pedantic. */
+#ifndef _Restrict_arr_
+# if ((199901L <= __STDC_VERSION__ \
+ || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \
+ && !defined __STRICT_ANSI__)) \
+ && !defined __GNUG__)
+# define _Restrict_arr_ _Restrict_
+# else
+# define _Restrict_arr_
+# endif
+#endif
+
+/* POSIX compatibility. */
+extern int regcomp (regex_t *_Restrict_ __preg,
+ const char *_Restrict_ __pattern,
+ int __cflags);
+
+extern int regexec (const regex_t *_Restrict_ __preg,
+ const char *_Restrict_ __string, size_t __nmatch,
+ regmatch_t __pmatch[_Restrict_arr_],
+ int __eflags);
+
+extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
+ char *_Restrict_ __errbuf, size_t __errbuf_size);
+
+extern void regfree (regex_t *__preg);
+
+
+#ifdef __cplusplus
+}
+#endif /* C++ */
+
+#endif /* regex.h */
diff --git a/contrib/tools/bison/gnulib/src/regex_internal.c b/contrib/tools/bison/gnulib/src/regex_internal.c
index 899b0ae67e..5401026eb2 100644
--- a/contrib/tools/bison/gnulib/src/regex_internal.c
+++ b/contrib/tools/bison/gnulib/src/regex_internal.c
@@ -1,1741 +1,1741 @@
-/* Extended regular expression matching and search library.
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-static void re_string_construct_common (const char *str, Idx len,
- re_string_t *pstr,
- RE_TRANSLATE_TYPE trans, bool icase,
- const re_dfa_t *dfa) internal_function;
-static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
- const re_node_set *nodes,
- re_hashval_t hash) internal_function;
-static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
- const re_node_set *nodes,
- unsigned int context,
- re_hashval_t hash) internal_function;
-
-/* Functions for string operation. */
-
-/* This function allocate the buffers. It is necessary to call
- re_string_reconstruct before using the object. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
- RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
-{
- reg_errcode_t ret;
- Idx init_buf_len;
-
- /* Ensure at least one character fits into the buffers. */
- if (init_len < dfa->mb_cur_max)
- init_len = dfa->mb_cur_max;
- init_buf_len = (len + 1 < init_len) ? len + 1: init_len;
- re_string_construct_common (str, len, pstr, trans, icase, dfa);
-
- ret = re_string_realloc_buffers (pstr, init_buf_len);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
-
- pstr->word_char = dfa->word_char;
- pstr->word_ops_used = dfa->word_ops_used;
- pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
- pstr->valid_len = (pstr->mbs_allocated || dfa->mb_cur_max > 1) ? 0 : len;
- pstr->valid_raw_len = pstr->valid_len;
- return REG_NOERROR;
-}
-
-/* This function allocate the buffers, and initialize them. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_string_construct (re_string_t *pstr, const char *str, Idx len,
- RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
-{
- reg_errcode_t ret;
- memset (pstr, '\0', sizeof (re_string_t));
- re_string_construct_common (str, len, pstr, trans, icase, dfa);
-
- if (len > 0)
- {
- ret = re_string_realloc_buffers (pstr, len + 1);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- }
- pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
-
- if (icase)
- {
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- {
- while (1)
- {
- ret = build_wcs_upper_buffer (pstr);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- if (pstr->valid_raw_len >= len)
- break;
- if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max)
- break;
- ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- }
- }
- else
-#endif /* RE_ENABLE_I18N */
- build_upper_buffer (pstr);
- }
- else
- {
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- build_wcs_buffer (pstr);
- else
-#endif /* RE_ENABLE_I18N */
- {
- if (trans != NULL)
- re_string_translate_buffer (pstr);
- else
- {
- pstr->valid_len = pstr->bufs_len;
- pstr->valid_raw_len = pstr->bufs_len;
- }
- }
- }
-
- return REG_NOERROR;
-}
-
-/* Helper functions for re_string_allocate, and re_string_construct. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
-{
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1)
- {
- wint_t *new_wcs;
-
- /* Avoid overflow in realloc. */
- const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
- if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_buf_len, 0))
- return REG_ESPACE;
-
- new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
- if (BE (new_wcs == NULL, 0))
- return REG_ESPACE;
- pstr->wcs = new_wcs;
- if (pstr->offsets != NULL)
- {
- Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
- if (BE (new_offsets == NULL, 0))
- return REG_ESPACE;
- pstr->offsets = new_offsets;
- }
- }
-#endif /* RE_ENABLE_I18N */
- if (pstr->mbs_allocated)
- {
- unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char,
- new_buf_len);
- if (BE (new_mbs == NULL, 0))
- return REG_ESPACE;
- pstr->mbs = new_mbs;
- }
- pstr->bufs_len = new_buf_len;
- return REG_NOERROR;
-}
-
-
-static void
-internal_function
-re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
- RE_TRANSLATE_TYPE trans, bool icase,
- const re_dfa_t *dfa)
-{
- pstr->raw_mbs = (const unsigned char *) str;
- pstr->len = len;
- pstr->raw_len = len;
- pstr->trans = trans;
- pstr->icase = icase;
- pstr->mbs_allocated = (trans != NULL || icase);
- pstr->mb_cur_max = dfa->mb_cur_max;
- pstr->is_utf8 = dfa->is_utf8;
- pstr->map_notascii = dfa->map_notascii;
- pstr->stop = pstr->len;
- pstr->raw_stop = pstr->stop;
-}
-
-#ifdef RE_ENABLE_I18N
-
-/* Build wide character buffer PSTR->WCS.
- If the byte sequence of the string are:
- <mb1>(0), <mb1>(1), <mb2>(0), <mb2>(1), <sb3>
- Then wide character buffer will be:
- <wc1> , WEOF , <wc2> , WEOF , <wc3>
- We use WEOF for padding, they indicate that the position isn't
- a first byte of a multibyte character.
-
- Note that this function assumes PSTR->VALID_LEN elements are already
- built and starts from PSTR->VALID_LEN. */
-
-static void
-internal_function
-build_wcs_buffer (re_string_t *pstr)
-{
-#ifdef _LIBC
- unsigned char buf[MB_LEN_MAX];
- assert (MB_LEN_MAX >= pstr->mb_cur_max);
-#else
- unsigned char buf[64];
-#endif
- mbstate_t prev_st;
- Idx byte_idx, end_idx, remain_len;
- size_t mbclen;
-
- /* Build the buffers from pstr->valid_len to either pstr->len or
- pstr->bufs_len. */
- end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
- for (byte_idx = pstr->valid_len; byte_idx < end_idx;)
- {
- wchar_t wc;
- const char *p;
-
- remain_len = end_idx - byte_idx;
- prev_st = pstr->cur_state;
- /* Apply the translation if we need. */
- if (BE (pstr->trans != NULL, 0))
- {
- int i, ch;
-
- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
- {
- ch = pstr->raw_mbs [pstr->raw_mbs_idx + byte_idx + i];
- buf[i] = pstr->mbs[byte_idx + i] = pstr->trans[ch];
- }
- p = (const char *) buf;
- }
- else
- p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx;
- mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
- if (BE (mbclen == (size_t) -1 || mbclen == 0
- || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len), 0))
- {
- /* We treat these cases as a singlebyte character. */
- mbclen = 1;
- wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
- if (BE (pstr->trans != NULL, 0))
- wc = pstr->trans[wc];
- pstr->cur_state = prev_st;
- }
- else if (BE (mbclen == (size_t) -2, 0))
- {
- /* The buffer doesn't have enough space, finish to build. */
- pstr->cur_state = prev_st;
- break;
- }
-
- /* Write wide character and padding. */
- pstr->wcs[byte_idx++] = wc;
- /* Write paddings. */
- for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
- pstr->wcs[byte_idx++] = WEOF;
- }
- pstr->valid_len = byte_idx;
- pstr->valid_raw_len = byte_idx;
-}
-
-/* Build wide character buffer PSTR->WCS like build_wcs_buffer,
- but for REG_ICASE. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-build_wcs_upper_buffer (re_string_t *pstr)
-{
- mbstate_t prev_st;
- Idx src_idx, byte_idx, end_idx, remain_len;
- size_t mbclen;
-#ifdef _LIBC
- char buf[MB_LEN_MAX];
- assert (MB_LEN_MAX >= pstr->mb_cur_max);
-#else
- char buf[64];
-#endif
-
- byte_idx = pstr->valid_len;
- end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
-
- /* The following optimization assumes that ASCII characters can be
- mapped to wide characters with a simple cast. */
- if (! pstr->map_notascii && pstr->trans == NULL && !pstr->offsets_needed)
- {
- while (byte_idx < end_idx)
- {
- wchar_t wc;
-
- if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx])
- && mbsinit (&pstr->cur_state))
- {
- /* In case of a singlebyte character. */
- pstr->mbs[byte_idx]
- = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]);
- /* The next step uses the assumption that wchar_t is encoded
- ASCII-safe: all ASCII values can be converted like this. */
- pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx];
- ++byte_idx;
- continue;
- }
-
- remain_len = end_idx - byte_idx;
- prev_st = pstr->cur_state;
- mbclen = __mbrtowc (&wc,
- ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
- + byte_idx), remain_len, &pstr->cur_state);
- if (BE (mbclen < (size_t) -2, 1))
- {
- wchar_t wcu = wc;
- if (iswlower (wc))
- {
- size_t mbcdlen;
-
- wcu = towupper (wc);
- mbcdlen = wcrtomb (buf, wcu, &prev_st);
- if (BE (mbclen == mbcdlen, 1))
- memcpy (pstr->mbs + byte_idx, buf, mbclen);
- else
- {
- src_idx = byte_idx;
- goto offsets_needed;
- }
- }
- else
- memcpy (pstr->mbs + byte_idx,
- pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx, mbclen);
- pstr->wcs[byte_idx++] = wcu;
- /* Write paddings. */
- for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
- pstr->wcs[byte_idx++] = WEOF;
- }
- else if (mbclen == (size_t) -1 || mbclen == 0
- || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len))
- {
- /* It is an invalid character, an incomplete character
- at the end of the string, or '\0'. Just use the byte. */
- int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
- pstr->mbs[byte_idx] = ch;
- /* And also cast it to wide char. */
- pstr->wcs[byte_idx++] = (wchar_t) ch;
- if (BE (mbclen == (size_t) -1, 0))
- pstr->cur_state = prev_st;
- }
- else
- {
- /* The buffer doesn't have enough space, finish to build. */
- pstr->cur_state = prev_st;
- break;
- }
- }
- pstr->valid_len = byte_idx;
- pstr->valid_raw_len = byte_idx;
- return REG_NOERROR;
- }
- else
- for (src_idx = pstr->valid_raw_len; byte_idx < end_idx;)
- {
- wchar_t wc;
- const char *p;
- offsets_needed:
- remain_len = end_idx - byte_idx;
- prev_st = pstr->cur_state;
- if (BE (pstr->trans != NULL, 0))
- {
- int i, ch;
-
- for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
- {
- ch = pstr->raw_mbs [pstr->raw_mbs_idx + src_idx + i];
- buf[i] = pstr->trans[ch];
- }
- p = (const char *) buf;
- }
- else
- p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
- mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
- if (BE (mbclen < (size_t) -2, 1))
- {
- wchar_t wcu = wc;
- if (iswlower (wc))
- {
- size_t mbcdlen;
-
- wcu = towupper (wc);
- mbcdlen = wcrtomb ((char *) buf, wcu, &prev_st);
- if (BE (mbclen == mbcdlen, 1))
- memcpy (pstr->mbs + byte_idx, buf, mbclen);
- else if (mbcdlen != (size_t) -1)
- {
- size_t i;
-
- if (byte_idx + mbcdlen > pstr->bufs_len)
- {
- pstr->cur_state = prev_st;
- break;
- }
-
- if (pstr->offsets == NULL)
- {
- pstr->offsets = re_malloc (Idx, pstr->bufs_len);
-
- if (pstr->offsets == NULL)
- return REG_ESPACE;
- }
- if (!pstr->offsets_needed)
- {
- for (i = 0; i < (size_t) byte_idx; ++i)
- pstr->offsets[i] = i;
- pstr->offsets_needed = 1;
- }
-
- memcpy (pstr->mbs + byte_idx, buf, mbcdlen);
- pstr->wcs[byte_idx] = wcu;
- pstr->offsets[byte_idx] = src_idx;
- for (i = 1; i < mbcdlen; ++i)
- {
- pstr->offsets[byte_idx + i]
- = src_idx + (i < mbclen ? i : mbclen - 1);
- pstr->wcs[byte_idx + i] = WEOF;
- }
- pstr->len += mbcdlen - mbclen;
- if (pstr->raw_stop > src_idx)
- pstr->stop += mbcdlen - mbclen;
- end_idx = (pstr->bufs_len > pstr->len)
- ? pstr->len : pstr->bufs_len;
- byte_idx += mbcdlen;
- src_idx += mbclen;
- continue;
- }
- else
- memcpy (pstr->mbs + byte_idx, p, mbclen);
- }
- else
- memcpy (pstr->mbs + byte_idx, p, mbclen);
-
- if (BE (pstr->offsets_needed != 0, 0))
- {
- size_t i;
- for (i = 0; i < mbclen; ++i)
- pstr->offsets[byte_idx + i] = src_idx + i;
- }
- src_idx += mbclen;
-
- pstr->wcs[byte_idx++] = wcu;
- /* Write paddings. */
- for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
- pstr->wcs[byte_idx++] = WEOF;
- }
- else if (mbclen == (size_t) -1 || mbclen == 0
- || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len))
- {
- /* It is an invalid character or '\0'. Just use the byte. */
- int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx];
-
- if (BE (pstr->trans != NULL, 0))
- ch = pstr->trans [ch];
- pstr->mbs[byte_idx] = ch;
-
- if (BE (pstr->offsets_needed != 0, 0))
- pstr->offsets[byte_idx] = src_idx;
- ++src_idx;
-
- /* And also cast it to wide char. */
- pstr->wcs[byte_idx++] = (wchar_t) ch;
- if (BE (mbclen == (size_t) -1, 0))
- pstr->cur_state = prev_st;
- }
- else
- {
- /* The buffer doesn't have enough space, finish to build. */
- pstr->cur_state = prev_st;
- break;
- }
- }
- pstr->valid_len = byte_idx;
- pstr->valid_raw_len = src_idx;
- return REG_NOERROR;
-}
-
-/* Skip characters until the index becomes greater than NEW_RAW_IDX.
- Return the index. */
-
-static Idx
-internal_function
-re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
-{
- mbstate_t prev_st;
- Idx rawbuf_idx;
- size_t mbclen;
- wint_t wc = WEOF;
-
- /* Skip the characters which are not necessary to check. */
- for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len;
- rawbuf_idx < new_raw_idx;)
- {
- wchar_t wc2;
- Idx remain_len = pstr->raw_len - rawbuf_idx;
- prev_st = pstr->cur_state;
- mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
- remain_len, &pstr->cur_state);
- if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0))
- {
- /* We treat these cases as a single byte character. */
- if (mbclen == 0 || remain_len == 0)
- wc = L'\0';
- else
- wc = *(unsigned char *) (pstr->raw_mbs + rawbuf_idx);
- mbclen = 1;
- pstr->cur_state = prev_st;
- }
- else
- wc = wc2;
- /* Then proceed the next character. */
- rawbuf_idx += mbclen;
- }
- *last_wc = wc;
- return rawbuf_idx;
-}
-#endif /* RE_ENABLE_I18N */
-
-/* Build the buffer PSTR->MBS, and apply the translation if we need.
- This function is used in case of REG_ICASE. */
-
-static void
-internal_function
-build_upper_buffer (re_string_t *pstr)
-{
- Idx char_idx, end_idx;
- end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
-
- for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx)
- {
- int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx];
- if (BE (pstr->trans != NULL, 0))
- ch = pstr->trans[ch];
- if (islower (ch))
- pstr->mbs[char_idx] = toupper (ch);
- else
- pstr->mbs[char_idx] = ch;
- }
- pstr->valid_len = char_idx;
- pstr->valid_raw_len = char_idx;
-}
-
-/* Apply TRANS to the buffer in PSTR. */
-
-static void
-internal_function
-re_string_translate_buffer (re_string_t *pstr)
-{
- Idx buf_idx, end_idx;
- end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
-
- for (buf_idx = pstr->valid_len; buf_idx < end_idx; ++buf_idx)
- {
- int ch = pstr->raw_mbs[pstr->raw_mbs_idx + buf_idx];
- pstr->mbs[buf_idx] = pstr->trans[ch];
- }
-
- pstr->valid_len = buf_idx;
- pstr->valid_raw_len = buf_idx;
-}
-
-/* This function re-construct the buffers.
- Concretely, convert to wide character in case of pstr->mb_cur_max > 1,
- convert to upper case in case of REG_ICASE, apply translation. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
-{
- Idx offset;
-
- if (BE (pstr->raw_mbs_idx <= idx, 0))
- offset = idx - pstr->raw_mbs_idx;
- else
- {
- /* Reset buffer. */
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1)
- memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
-#endif /* RE_ENABLE_I18N */
- pstr->len = pstr->raw_len;
- pstr->stop = pstr->raw_stop;
- pstr->valid_len = 0;
- pstr->raw_mbs_idx = 0;
- pstr->valid_raw_len = 0;
- pstr->offsets_needed = 0;
- pstr->tip_context = ((eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
- : CONTEXT_NEWLINE | CONTEXT_BEGBUF);
- if (!pstr->mbs_allocated)
- pstr->mbs = (unsigned char *) pstr->raw_mbs;
- offset = idx;
- }
-
- if (BE (offset != 0, 1))
- {
- /* Should the already checked characters be kept? */
- if (BE (offset < pstr->valid_raw_len, 1))
- {
- /* Yes, move them to the front of the buffer. */
-#ifdef RE_ENABLE_I18N
- if (BE (pstr->offsets_needed, 0))
- {
- Idx low = 0, high = pstr->valid_len, mid;
- do
- {
- mid = (high + low) / 2;
- if (pstr->offsets[mid] > offset)
- high = mid;
- else if (pstr->offsets[mid] < offset)
- low = mid + 1;
- else
- break;
- }
- while (low < high);
- if (pstr->offsets[mid] < offset)
- ++mid;
- pstr->tip_context = re_string_context_at (pstr, mid - 1,
- eflags);
- /* This can be quite complicated, so handle specially
- only the common and easy case where the character with
- different length representation of lower and upper
- case is present at or after offset. */
- if (pstr->valid_len > offset
- && mid == offset && pstr->offsets[mid] == offset)
- {
- memmove (pstr->wcs, pstr->wcs + offset,
- (pstr->valid_len - offset) * sizeof (wint_t));
- memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset);
- pstr->valid_len -= offset;
- pstr->valid_raw_len -= offset;
- for (low = 0; low < pstr->valid_len; low++)
- pstr->offsets[low] = pstr->offsets[low + offset] - offset;
- }
- else
- {
- /* Otherwise, just find out how long the partial multibyte
- character at offset is and fill it with WEOF/255. */
- pstr->len = pstr->raw_len - idx + offset;
- pstr->stop = pstr->raw_stop - idx + offset;
- pstr->offsets_needed = 0;
- while (mid > 0 && pstr->offsets[mid - 1] == offset)
- --mid;
- while (mid < pstr->valid_len)
- if (pstr->wcs[mid] != WEOF)
- break;
- else
- ++mid;
- if (mid == pstr->valid_len)
- pstr->valid_len = 0;
- else
- {
- pstr->valid_len = pstr->offsets[mid] - offset;
- if (pstr->valid_len)
- {
- for (low = 0; low < pstr->valid_len; ++low)
- pstr->wcs[low] = WEOF;
- memset (pstr->mbs, 255, pstr->valid_len);
- }
- }
- pstr->valid_raw_len = pstr->valid_len;
- }
- }
- else
-#endif
- {
- pstr->tip_context = re_string_context_at (pstr, offset - 1,
- eflags);
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1)
- memmove (pstr->wcs, pstr->wcs + offset,
- (pstr->valid_len - offset) * sizeof (wint_t));
-#endif /* RE_ENABLE_I18N */
- if (BE (pstr->mbs_allocated, 0))
- memmove (pstr->mbs, pstr->mbs + offset,
- pstr->valid_len - offset);
- pstr->valid_len -= offset;
- pstr->valid_raw_len -= offset;
-#if DEBUG
- assert (pstr->valid_len > 0);
-#endif
- }
- }
- else
- {
-#ifdef RE_ENABLE_I18N
- /* No, skip all characters until IDX. */
- Idx prev_valid_len = pstr->valid_len;
-
- if (BE (pstr->offsets_needed, 0))
- {
- pstr->len = pstr->raw_len - idx + offset;
- pstr->stop = pstr->raw_stop - idx + offset;
- pstr->offsets_needed = 0;
- }
-#endif
- pstr->valid_len = 0;
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1)
- {
- Idx wcs_idx;
- wint_t wc = WEOF;
-
- if (pstr->is_utf8)
- {
- const unsigned char *raw, *p, *end;
-
- /* Special case UTF-8. Multi-byte chars start with any
- byte other than 0x80 - 0xbf. */
- raw = pstr->raw_mbs + pstr->raw_mbs_idx;
- end = raw + (offset - pstr->mb_cur_max);
- if (end < pstr->raw_mbs)
- end = pstr->raw_mbs;
- p = raw + offset - 1;
-#ifdef _LIBC
- /* We know the wchar_t encoding is UCS4, so for the simple
- case, ASCII characters, skip the conversion step. */
- if (isascii (*p) && BE (pstr->trans == NULL, 1))
- {
- memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
- /* pstr->valid_len = 0; */
- wc = (wchar_t) *p;
- }
- else
-#endif
- for (; p >= end; --p)
- if ((*p & 0xc0) != 0x80)
- {
- mbstate_t cur_state;
- wchar_t wc2;
- Idx mlen = raw + pstr->len - p;
- unsigned char buf[6];
- size_t mbclen;
-
- const unsigned char *pp = p;
- if (BE (pstr->trans != NULL, 0))
- {
- int i = mlen < 6 ? mlen : 6;
- while (--i >= 0)
- buf[i] = pstr->trans[p[i]];
- pp = buf;
- }
- /* XXX Don't use mbrtowc, we know which conversion
- to use (UTF-8 -> UCS4). */
- memset (&cur_state, 0, sizeof (cur_state));
- mbclen = __mbrtowc (&wc2, (const char *) pp, mlen,
- &cur_state);
- if (raw + offset - p <= mbclen
- && mbclen < (size_t) -2)
- {
- memset (&pstr->cur_state, '\0',
- sizeof (mbstate_t));
- pstr->valid_len = mbclen - (raw + offset - p);
- wc = wc2;
- }
- break;
- }
- }
-
- if (wc == WEOF)
- pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx;
- if (wc == WEOF)
- pstr->tip_context
- = re_string_context_at (pstr, prev_valid_len - 1, eflags);
- else
- pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0)
- && IS_WIDE_WORD_CHAR (wc))
- ? CONTEXT_WORD
- : ((IS_WIDE_NEWLINE (wc)
- && pstr->newline_anchor)
- ? CONTEXT_NEWLINE : 0));
- if (BE (pstr->valid_len, 0))
- {
- for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx)
- pstr->wcs[wcs_idx] = WEOF;
- if (pstr->mbs_allocated)
- memset (pstr->mbs, 255, pstr->valid_len);
- }
- pstr->valid_raw_len = pstr->valid_len;
- }
- else
-#endif /* RE_ENABLE_I18N */
- {
- int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1];
- pstr->valid_raw_len = 0;
- if (pstr->trans)
- c = pstr->trans[c];
- pstr->tip_context = (bitset_contain (pstr->word_char, c)
- ? CONTEXT_WORD
- : ((IS_NEWLINE (c) && pstr->newline_anchor)
- ? CONTEXT_NEWLINE : 0));
- }
- }
- if (!BE (pstr->mbs_allocated, 0))
- pstr->mbs += offset;
- }
- pstr->raw_mbs_idx = idx;
- pstr->len -= offset;
- pstr->stop -= offset;
-
- /* Then build the buffers. */
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1)
- {
- if (pstr->icase)
- {
- reg_errcode_t ret = build_wcs_upper_buffer (pstr);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- }
- else
- build_wcs_buffer (pstr);
- }
- else
-#endif /* RE_ENABLE_I18N */
- if (BE (pstr->mbs_allocated, 0))
- {
- if (pstr->icase)
- build_upper_buffer (pstr);
- else if (pstr->trans != NULL)
- re_string_translate_buffer (pstr);
- }
- else
- pstr->valid_len = pstr->len;
-
- pstr->cur_idx = 0;
- return REG_NOERROR;
-}
-
-static unsigned char
-internal_function __attribute__ ((pure))
-re_string_peek_byte_case (const re_string_t *pstr, Idx idx)
-{
- int ch;
- Idx off;
-
- /* Handle the common (easiest) cases first. */
- if (BE (!pstr->mbs_allocated, 1))
- return re_string_peek_byte (pstr, idx);
-
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1
- && ! re_string_is_single_byte_char (pstr, pstr->cur_idx + idx))
- return re_string_peek_byte (pstr, idx);
-#endif
-
- off = pstr->cur_idx + idx;
-#ifdef RE_ENABLE_I18N
- if (pstr->offsets_needed)
- off = pstr->offsets[off];
-#endif
-
- ch = pstr->raw_mbs[pstr->raw_mbs_idx + off];
-
-#ifdef RE_ENABLE_I18N
- /* Ensure that e.g. for tr_TR.UTF-8 BACKSLASH DOTLESS SMALL LETTER I
- this function returns CAPITAL LETTER I instead of first byte of
- DOTLESS SMALL LETTER I. The latter would confuse the parser,
- since peek_byte_case doesn't advance cur_idx in any way. */
- if (pstr->offsets_needed && !isascii (ch))
- return re_string_peek_byte (pstr, idx);
-#endif
-
- return ch;
-}
-
-static unsigned char
-internal_function
-re_string_fetch_byte_case (re_string_t *pstr)
-{
- if (BE (!pstr->mbs_allocated, 1))
- return re_string_fetch_byte (pstr);
-
-#ifdef RE_ENABLE_I18N
- if (pstr->offsets_needed)
- {
- Idx off;
- int ch;
-
- /* For tr_TR.UTF-8 [[:islower:]] there is
- [[: CAPITAL LETTER I WITH DOT lower:]] in mbs. Skip
- in that case the whole multi-byte character and return
- the original letter. On the other side, with
- [[: DOTLESS SMALL LETTER I return [[:I, as doing
- anything else would complicate things too much. */
-
- if (!re_string_first_byte (pstr, pstr->cur_idx))
- return re_string_fetch_byte (pstr);
-
- off = pstr->offsets[pstr->cur_idx];
- ch = pstr->raw_mbs[pstr->raw_mbs_idx + off];
-
- if (! isascii (ch))
- return re_string_fetch_byte (pstr);
-
- re_string_skip_bytes (pstr,
- re_string_char_size_at (pstr, pstr->cur_idx));
- return ch;
- }
-#endif
-
- return pstr->raw_mbs[pstr->raw_mbs_idx + pstr->cur_idx++];
-}
-
-static void
-internal_function
-re_string_destruct (re_string_t *pstr)
-{
-#ifdef RE_ENABLE_I18N
- re_free (pstr->wcs);
- re_free (pstr->offsets);
-#endif /* RE_ENABLE_I18N */
- if (pstr->mbs_allocated)
- re_free (pstr->mbs);
-}
-
-/* Return the context at IDX in INPUT. */
-
-static unsigned int
-internal_function
-re_string_context_at (const re_string_t *input, Idx idx, int eflags)
-{
- int c;
- if (BE (! REG_VALID_INDEX (idx), 0))
- /* In this case, we use the value stored in input->tip_context,
- since we can't know the character in input->mbs[-1] here. */
- return input->tip_context;
- if (BE (idx == input->len, 0))
- return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF
- : CONTEXT_NEWLINE | CONTEXT_ENDBUF);
-#ifdef RE_ENABLE_I18N
- if (input->mb_cur_max > 1)
- {
- wint_t wc;
- Idx wc_idx = idx;
- while(input->wcs[wc_idx] == WEOF)
- {
-#ifdef DEBUG
- /* It must not happen. */
- assert (REG_VALID_INDEX (wc_idx));
-#endif
- --wc_idx;
- if (! REG_VALID_INDEX (wc_idx))
- return input->tip_context;
- }
- wc = input->wcs[wc_idx];
- if (BE (input->word_ops_used != 0, 0) && IS_WIDE_WORD_CHAR (wc))
- return CONTEXT_WORD;
- return (IS_WIDE_NEWLINE (wc) && input->newline_anchor
- ? CONTEXT_NEWLINE : 0);
- }
- else
-#endif
- {
- c = re_string_byte_at (input, idx);
- if (bitset_contain (input->word_char, c))
- return CONTEXT_WORD;
- return IS_NEWLINE (c) && input->newline_anchor ? CONTEXT_NEWLINE : 0;
- }
-}
-
-/* Functions for set operation. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_node_set_alloc (re_node_set *set, Idx size)
-{
- set->alloc = size;
- set->nelem = 0;
- set->elems = re_malloc (Idx, size);
- if (BE (set->elems == NULL, 0) && (MALLOC_0_IS_NONNULL || size != 0))
- return REG_ESPACE;
- return REG_NOERROR;
-}
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_node_set_init_1 (re_node_set *set, Idx elem)
-{
- set->alloc = 1;
- set->nelem = 1;
- set->elems = re_malloc (Idx, 1);
- if (BE (set->elems == NULL, 0))
- {
- set->alloc = set->nelem = 0;
- return REG_ESPACE;
- }
- set->elems[0] = elem;
- return REG_NOERROR;
-}
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
-{
- set->alloc = 2;
- set->elems = re_malloc (Idx, 2);
- if (BE (set->elems == NULL, 0))
- return REG_ESPACE;
- if (elem1 == elem2)
- {
- set->nelem = 1;
- set->elems[0] = elem1;
- }
- else
- {
- set->nelem = 2;
- if (elem1 < elem2)
- {
- set->elems[0] = elem1;
- set->elems[1] = elem2;
- }
- else
- {
- set->elems[0] = elem2;
- set->elems[1] = elem1;
- }
- }
- return REG_NOERROR;
-}
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
-{
- dest->nelem = src->nelem;
- if (src->nelem > 0)
- {
- dest->alloc = dest->nelem;
- dest->elems = re_malloc (Idx, dest->alloc);
- if (BE (dest->elems == NULL, 0))
- {
- dest->alloc = dest->nelem = 0;
- return REG_ESPACE;
- }
- memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
- }
- else
- re_node_set_init_empty (dest);
- return REG_NOERROR;
-}
-
-/* Calculate the intersection of the sets SRC1 and SRC2. And merge it to
- DEST. Return value indicate the error code or REG_NOERROR if succeeded.
- Note: We assume dest->elems is NULL, when dest->alloc is 0. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
- const re_node_set *src2)
-{
- Idx i1, i2, is, id, delta, sbase;
- if (src1->nelem == 0 || src2->nelem == 0)
- return REG_NOERROR;
-
- /* We need dest->nelem + 2 * elems_in_intersection; this is a
- conservative estimate. */
- if (src1->nelem + src2->nelem + dest->nelem > dest->alloc)
- {
- Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
- Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
- if (BE (new_elems == NULL, 0))
- return REG_ESPACE;
- dest->elems = new_elems;
- dest->alloc = new_alloc;
- }
-
- /* Find the items in the intersection of SRC1 and SRC2, and copy
- into the top of DEST those that are not already in DEST itself. */
- sbase = dest->nelem + src1->nelem + src2->nelem;
- i1 = src1->nelem - 1;
- i2 = src2->nelem - 1;
- id = dest->nelem - 1;
- for (;;)
- {
- if (src1->elems[i1] == src2->elems[i2])
- {
- /* Try to find the item in DEST. Maybe we could binary search? */
- while (REG_VALID_INDEX (id) && dest->elems[id] > src1->elems[i1])
- --id;
-
- if (! REG_VALID_INDEX (id) || dest->elems[id] != src1->elems[i1])
- dest->elems[--sbase] = src1->elems[i1];
-
- if (! REG_VALID_INDEX (--i1) || ! REG_VALID_INDEX (--i2))
- break;
- }
-
- /* Lower the highest of the two items. */
- else if (src1->elems[i1] < src2->elems[i2])
- {
- if (! REG_VALID_INDEX (--i2))
- break;
- }
- else
- {
- if (! REG_VALID_INDEX (--i1))
- break;
- }
- }
-
- id = dest->nelem - 1;
- is = dest->nelem + src1->nelem + src2->nelem - 1;
- delta = is - sbase + 1;
-
- /* Now copy. When DELTA becomes zero, the remaining
- DEST elements are already in place; this is more or
- less the same loop that is in re_node_set_merge. */
- dest->nelem += delta;
- if (delta > 0 && REG_VALID_INDEX (id))
- for (;;)
- {
- if (dest->elems[is] > dest->elems[id])
- {
- /* Copy from the top. */
- dest->elems[id + delta--] = dest->elems[is--];
- if (delta == 0)
- break;
- }
- else
- {
- /* Slide from the bottom. */
- dest->elems[id + delta] = dest->elems[id];
- if (! REG_VALID_INDEX (--id))
- break;
- }
- }
-
- /* Copy remaining SRC elements. */
- memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx));
-
- return REG_NOERROR;
-}
-
-/* Calculate the union set of the sets SRC1 and SRC2. And store it to
- DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
- const re_node_set *src2)
-{
- Idx i1, i2, id;
- if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0)
- {
- dest->alloc = src1->nelem + src2->nelem;
- dest->elems = re_malloc (Idx, dest->alloc);
- if (BE (dest->elems == NULL, 0))
- return REG_ESPACE;
- }
- else
- {
- if (src1 != NULL && src1->nelem > 0)
- return re_node_set_init_copy (dest, src1);
- else if (src2 != NULL && src2->nelem > 0)
- return re_node_set_init_copy (dest, src2);
- else
- re_node_set_init_empty (dest);
- return REG_NOERROR;
- }
- for (i1 = i2 = id = 0 ; i1 < src1->nelem && i2 < src2->nelem ;)
- {
- if (src1->elems[i1] > src2->elems[i2])
- {
- dest->elems[id++] = src2->elems[i2++];
- continue;
- }
- if (src1->elems[i1] == src2->elems[i2])
- ++i2;
- dest->elems[id++] = src1->elems[i1++];
- }
- if (i1 < src1->nelem)
- {
- memcpy (dest->elems + id, src1->elems + i1,
- (src1->nelem - i1) * sizeof (Idx));
- id += src1->nelem - i1;
- }
- else if (i2 < src2->nelem)
- {
- memcpy (dest->elems + id, src2->elems + i2,
- (src2->nelem - i2) * sizeof (Idx));
- id += src2->nelem - i2;
- }
- dest->nelem = id;
- return REG_NOERROR;
-}
-
-/* Calculate the union set of the sets DEST and SRC. And store it to
- DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-re_node_set_merge (re_node_set *dest, const re_node_set *src)
-{
- Idx is, id, sbase, delta;
- if (src == NULL || src->nelem == 0)
- return REG_NOERROR;
- if (dest->alloc < 2 * src->nelem + dest->nelem)
- {
- Idx new_alloc = 2 * (src->nelem + dest->alloc);
- Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
- if (BE (new_buffer == NULL, 0))
- return REG_ESPACE;
- dest->elems = new_buffer;
- dest->alloc = new_alloc;
- }
-
- if (BE (dest->nelem == 0, 0))
- {
- dest->nelem = src->nelem;
- memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
- return REG_NOERROR;
- }
-
- /* Copy into the top of DEST the items of SRC that are not
- found in DEST. Maybe we could binary search in DEST? */
- for (sbase = dest->nelem + 2 * src->nelem,
- is = src->nelem - 1, id = dest->nelem - 1;
- REG_VALID_INDEX (is) && REG_VALID_INDEX (id); )
- {
- if (dest->elems[id] == src->elems[is])
- is--, id--;
- else if (dest->elems[id] < src->elems[is])
- dest->elems[--sbase] = src->elems[is--];
- else /* if (dest->elems[id] > src->elems[is]) */
- --id;
- }
-
- if (REG_VALID_INDEX (is))
- {
- /* If DEST is exhausted, the remaining items of SRC must be unique. */
- sbase -= is + 1;
- memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx));
- }
-
- id = dest->nelem - 1;
- is = dest->nelem + 2 * src->nelem - 1;
- delta = is - sbase + 1;
- if (delta == 0)
- return REG_NOERROR;
-
- /* Now copy. When DELTA becomes zero, the remaining
- DEST elements are already in place. */
- dest->nelem += delta;
- for (;;)
- {
- if (dest->elems[is] > dest->elems[id])
- {
- /* Copy from the top. */
- dest->elems[id + delta--] = dest->elems[is--];
- if (delta == 0)
- break;
- }
- else
- {
- /* Slide from the bottom. */
- dest->elems[id + delta] = dest->elems[id];
- if (! REG_VALID_INDEX (--id))
- {
- /* Copy remaining SRC elements. */
- memcpy (dest->elems, dest->elems + sbase,
- delta * sizeof (Idx));
- break;
- }
- }
- }
-
- return REG_NOERROR;
-}
-
-/* Insert the new element ELEM to the re_node_set* SET.
- SET should not already have ELEM.
- Return true if successful. */
-
-static bool
-internal_function __attribute_warn_unused_result__
-re_node_set_insert (re_node_set *set, Idx elem)
-{
- Idx idx;
- /* In case the set is empty. */
- if (set->alloc == 0)
- return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1);
-
- if (BE (set->nelem, 0) == 0)
- {
- /* We already guaranteed above that set->alloc != 0. */
- set->elems[0] = elem;
- ++set->nelem;
- return true;
- }
-
- /* Realloc if we need. */
- if (set->alloc == set->nelem)
- {
- Idx *new_elems;
- set->alloc = set->alloc * 2;
- new_elems = re_realloc (set->elems, Idx, set->alloc);
- if (BE (new_elems == NULL, 0))
- return false;
- set->elems = new_elems;
- }
-
- /* Move the elements which follows the new element. Test the
- first element separately to skip a check in the inner loop. */
- if (elem < set->elems[0])
- {
- idx = 0;
- for (idx = set->nelem; idx > 0; idx--)
- set->elems[idx] = set->elems[idx - 1];
- }
- else
- {
- for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
- set->elems[idx] = set->elems[idx - 1];
- }
-
- /* Insert the new element. */
- set->elems[idx] = elem;
- ++set->nelem;
- return true;
-}
-
-/* Insert the new element ELEM to the re_node_set* SET.
- SET should not already have any element greater than or equal to ELEM.
- Return true if successful. */
-
-static bool
-internal_function __attribute_warn_unused_result__
-re_node_set_insert_last (re_node_set *set, Idx elem)
-{
- /* Realloc if we need. */
- if (set->alloc == set->nelem)
- {
- Idx *new_elems;
- set->alloc = (set->alloc + 1) * 2;
- new_elems = re_realloc (set->elems, Idx, set->alloc);
- if (BE (new_elems == NULL, 0))
- return false;
- set->elems = new_elems;
- }
-
- /* Insert the new element. */
- set->elems[set->nelem++] = elem;
- return true;
-}
-
-/* Compare two node sets SET1 and SET2.
- Return true if SET1 and SET2 are equivalent. */
-
-static bool
-internal_function __attribute__ ((pure))
-re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
-{
- Idx i;
- if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem)
- return false;
- for (i = set1->nelem ; REG_VALID_INDEX (--i) ; )
- if (set1->elems[i] != set2->elems[i])
- return false;
- return true;
-}
-
-/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */
-
-static Idx
-internal_function __attribute__ ((pure))
-re_node_set_contains (const re_node_set *set, Idx elem)
-{
- __re_size_t idx, right, mid;
- if (! REG_VALID_NONZERO_INDEX (set->nelem))
- return 0;
-
- /* Binary search the element. */
- idx = 0;
- right = set->nelem - 1;
- while (idx < right)
- {
- mid = (idx + right) / 2;
- if (set->elems[mid] < elem)
- idx = mid + 1;
- else
- right = mid;
- }
- return set->elems[idx] == elem ? idx + 1 : 0;
-}
-
-static void
-internal_function
-re_node_set_remove_at (re_node_set *set, Idx idx)
-{
- if (idx < 0 || idx >= set->nelem)
- return;
- --set->nelem;
- for (; idx < set->nelem; idx++)
- set->elems[idx] = set->elems[idx + 1];
-}
-
-
-/* Add the token TOKEN to dfa->nodes, and return the index of the token.
- Or return REG_MISSING if an error occurred. */
-
-static Idx
-internal_function
-re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
-{
- if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0))
- {
- size_t new_nodes_alloc = dfa->nodes_alloc * 2;
- Idx *new_nexts, *new_indices;
- re_node_set *new_edests, *new_eclosures;
- re_token_t *new_nodes;
-
- /* Avoid overflows in realloc. */
- const size_t max_object_size = MAX (sizeof (re_token_t),
- MAX (sizeof (re_node_set),
- sizeof (Idx)));
- if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_nodes_alloc, 0))
- return REG_MISSING;
-
- new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
- if (BE (new_nodes == NULL, 0))
- return REG_MISSING;
- dfa->nodes = new_nodes;
- new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
- new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
- new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
- new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
- if (BE (new_nexts == NULL || new_indices == NULL
- || new_edests == NULL || new_eclosures == NULL, 0))
- return REG_MISSING;
- dfa->nexts = new_nexts;
- dfa->org_indices = new_indices;
- dfa->edests = new_edests;
- dfa->eclosures = new_eclosures;
- dfa->nodes_alloc = new_nodes_alloc;
- }
- dfa->nodes[dfa->nodes_len] = token;
- dfa->nodes[dfa->nodes_len].constraint = 0;
-#ifdef RE_ENABLE_I18N
- dfa->nodes[dfa->nodes_len].accept_mb =
- ((token.type == OP_PERIOD && dfa->mb_cur_max > 1)
- || token.type == COMPLEX_BRACKET);
-#endif
- dfa->nexts[dfa->nodes_len] = REG_MISSING;
- re_node_set_init_empty (dfa->edests + dfa->nodes_len);
- re_node_set_init_empty (dfa->eclosures + dfa->nodes_len);
- return dfa->nodes_len++;
-}
-
-static re_hashval_t
-internal_function
-calc_state_hash (const re_node_set *nodes, unsigned int context)
-{
- re_hashval_t hash = nodes->nelem + context;
- Idx i;
- for (i = 0 ; i < nodes->nelem ; i++)
- hash += nodes->elems[i];
- return hash;
-}
-
-/* Search for the state whose node_set is equivalent to NODES.
- Return the pointer to the state, if we found it in the DFA.
- Otherwise create the new one and return it. In case of an error
- return NULL and set the error code in ERR.
- Note: - We assume NULL as the invalid state, then it is possible that
- return value is NULL and ERR is REG_NOERROR.
- - We never return non-NULL value in case of any errors, it is for
- optimization. */
-
-static re_dfastate_t *
-internal_function __attribute_warn_unused_result__
-re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
- const re_node_set *nodes)
-{
- re_hashval_t hash;
- re_dfastate_t *new_state;
- struct re_state_table_entry *spot;
- Idx i;
-#ifdef lint
- /* Suppress bogus uninitialized-variable warnings. */
- *err = REG_NOERROR;
-#endif
- if (BE (nodes->nelem == 0, 0))
- {
- *err = REG_NOERROR;
- return NULL;
- }
- hash = calc_state_hash (nodes, 0);
- spot = dfa->state_table + (hash & dfa->state_hash_mask);
-
- for (i = 0 ; i < spot->num ; i++)
- {
- re_dfastate_t *state = spot->array[i];
- if (hash != state->hash)
- continue;
- if (re_node_set_compare (&state->nodes, nodes))
- return state;
- }
-
- /* There are no appropriate state in the dfa, create the new one. */
- new_state = create_ci_newstate (dfa, nodes, hash);
- if (BE (new_state == NULL, 0))
- *err = REG_ESPACE;
-
- return new_state;
-}
-
-/* Search for the state whose node_set is equivalent to NODES and
- whose context is equivalent to CONTEXT.
- Return the pointer to the state, if we found it in the DFA.
- Otherwise create the new one and return it. In case of an error
- return NULL and set the error code in ERR.
- Note: - We assume NULL as the invalid state, then it is possible that
- return value is NULL and ERR is REG_NOERROR.
- - We never return non-NULL value in case of any errors, it is for
- optimization. */
-
-static re_dfastate_t *
-internal_function __attribute_warn_unused_result__
-re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
- const re_node_set *nodes, unsigned int context)
-{
- re_hashval_t hash;
- re_dfastate_t *new_state;
- struct re_state_table_entry *spot;
- Idx i;
-#ifdef lint
- /* Suppress bogus uninitialized-variable warnings. */
- *err = REG_NOERROR;
-#endif
- if (nodes->nelem == 0)
- {
- *err = REG_NOERROR;
- return NULL;
- }
- hash = calc_state_hash (nodes, context);
- spot = dfa->state_table + (hash & dfa->state_hash_mask);
-
- for (i = 0 ; i < spot->num ; i++)
- {
- re_dfastate_t *state = spot->array[i];
- if (state->hash == hash
- && state->context == context
- && re_node_set_compare (state->entrance_nodes, nodes))
- return state;
- }
- /* There are no appropriate state in 'dfa', create the new one. */
- new_state = create_cd_newstate (dfa, nodes, context, hash);
- if (BE (new_state == NULL, 0))
- *err = REG_ESPACE;
-
- return new_state;
-}
-
-/* Finish initialization of the new state NEWSTATE, and using its hash value
- HASH put in the appropriate bucket of DFA's state table. Return value
- indicates the error code if failed. */
-
-static reg_errcode_t
-__attribute_warn_unused_result__
-register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
- re_hashval_t hash)
-{
- struct re_state_table_entry *spot;
- reg_errcode_t err;
- Idx i;
-
- newstate->hash = hash;
- err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem);
- if (BE (err != REG_NOERROR, 0))
- return REG_ESPACE;
- for (i = 0; i < newstate->nodes.nelem; i++)
- {
- Idx elem = newstate->nodes.elems[i];
- if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
- if (! re_node_set_insert_last (&newstate->non_eps_nodes, elem))
- return REG_ESPACE;
- }
-
- spot = dfa->state_table + (hash & dfa->state_hash_mask);
- if (BE (spot->alloc <= spot->num, 0))
- {
- Idx new_alloc = 2 * spot->num + 2;
- re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
- new_alloc);
- if (BE (new_array == NULL, 0))
- return REG_ESPACE;
- spot->array = new_array;
- spot->alloc = new_alloc;
- }
- spot->array[spot->num++] = newstate;
- return REG_NOERROR;
-}
-
-static void
-free_state (re_dfastate_t *state)
-{
- re_node_set_free (&state->non_eps_nodes);
- re_node_set_free (&state->inveclosure);
- if (state->entrance_nodes != &state->nodes)
- {
- re_node_set_free (state->entrance_nodes);
- re_free (state->entrance_nodes);
- }
- re_node_set_free (&state->nodes);
- re_free (state->word_trtable);
- re_free (state->trtable);
- re_free (state);
-}
-
-/* Create the new state which is independent of contexts.
- Return the new state if succeeded, otherwise return NULL. */
-
-static re_dfastate_t *
-internal_function __attribute_warn_unused_result__
-create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
- re_hashval_t hash)
-{
- Idx i;
- reg_errcode_t err;
- re_dfastate_t *newstate;
-
- newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
- if (BE (newstate == NULL, 0))
- return NULL;
- err = re_node_set_init_copy (&newstate->nodes, nodes);
- if (BE (err != REG_NOERROR, 0))
- {
- re_free (newstate);
- return NULL;
- }
-
- newstate->entrance_nodes = &newstate->nodes;
- for (i = 0 ; i < nodes->nelem ; i++)
- {
- re_token_t *node = dfa->nodes + nodes->elems[i];
- re_token_type_t type = node->type;
- if (type == CHARACTER && !node->constraint)
- continue;
-#ifdef RE_ENABLE_I18N
- newstate->accept_mb |= node->accept_mb;
-#endif /* RE_ENABLE_I18N */
-
- /* If the state has the halt node, the state is a halt state. */
- if (type == END_OF_RE)
- newstate->halt = 1;
- else if (type == OP_BACK_REF)
- newstate->has_backref = 1;
- else if (type == ANCHOR || node->constraint)
- newstate->has_constraint = 1;
- }
- err = register_state (dfa, newstate, hash);
- if (BE (err != REG_NOERROR, 0))
- {
- free_state (newstate);
- newstate = NULL;
- }
- return newstate;
-}
-
-/* Create the new state which is depend on the context CONTEXT.
- Return the new state if succeeded, otherwise return NULL. */
-
-static re_dfastate_t *
-internal_function __attribute_warn_unused_result__
-create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
- unsigned int context, re_hashval_t hash)
-{
- Idx i, nctx_nodes = 0;
- reg_errcode_t err;
- re_dfastate_t *newstate;
-
- newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
- if (BE (newstate == NULL, 0))
- return NULL;
- err = re_node_set_init_copy (&newstate->nodes, nodes);
- if (BE (err != REG_NOERROR, 0))
- {
- re_free (newstate);
- return NULL;
- }
-
- newstate->context = context;
- newstate->entrance_nodes = &newstate->nodes;
-
- for (i = 0 ; i < nodes->nelem ; i++)
- {
- re_token_t *node = dfa->nodes + nodes->elems[i];
- re_token_type_t type = node->type;
- unsigned int constraint = node->constraint;
-
- if (type == CHARACTER && !constraint)
- continue;
-#ifdef RE_ENABLE_I18N
- newstate->accept_mb |= node->accept_mb;
-#endif /* RE_ENABLE_I18N */
-
- /* If the state has the halt node, the state is a halt state. */
- if (type == END_OF_RE)
- newstate->halt = 1;
- else if (type == OP_BACK_REF)
- newstate->has_backref = 1;
-
- if (constraint)
- {
- if (newstate->entrance_nodes == &newstate->nodes)
- {
- newstate->entrance_nodes = re_malloc (re_node_set, 1);
- if (BE (newstate->entrance_nodes == NULL, 0))
- {
- free_state (newstate);
- return NULL;
- }
- if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
- != REG_NOERROR)
- return NULL;
- nctx_nodes = 0;
- newstate->has_constraint = 1;
- }
-
- if (NOT_SATISFY_PREV_CONSTRAINT (constraint,context))
- {
- re_node_set_remove_at (&newstate->nodes, i - nctx_nodes);
- ++nctx_nodes;
- }
- }
- }
- err = register_state (dfa, newstate, hash);
- if (BE (err != REG_NOERROR, 0))
- {
- free_state (newstate);
- newstate = NULL;
- }
- return newstate;
-}
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+static void re_string_construct_common (const char *str, Idx len,
+ re_string_t *pstr,
+ RE_TRANSLATE_TYPE trans, bool icase,
+ const re_dfa_t *dfa) internal_function;
+static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
+ const re_node_set *nodes,
+ re_hashval_t hash) internal_function;
+static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
+ const re_node_set *nodes,
+ unsigned int context,
+ re_hashval_t hash) internal_function;
+
+/* Functions for string operation. */
+
+/* This function allocate the buffers. It is necessary to call
+ re_string_reconstruct before using the object. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
+ RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
+{
+ reg_errcode_t ret;
+ Idx init_buf_len;
+
+ /* Ensure at least one character fits into the buffers. */
+ if (init_len < dfa->mb_cur_max)
+ init_len = dfa->mb_cur_max;
+ init_buf_len = (len + 1 < init_len) ? len + 1: init_len;
+ re_string_construct_common (str, len, pstr, trans, icase, dfa);
+
+ ret = re_string_realloc_buffers (pstr, init_buf_len);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+
+ pstr->word_char = dfa->word_char;
+ pstr->word_ops_used = dfa->word_ops_used;
+ pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
+ pstr->valid_len = (pstr->mbs_allocated || dfa->mb_cur_max > 1) ? 0 : len;
+ pstr->valid_raw_len = pstr->valid_len;
+ return REG_NOERROR;
+}
+
+/* This function allocate the buffers, and initialize them. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_construct (re_string_t *pstr, const char *str, Idx len,
+ RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
+{
+ reg_errcode_t ret;
+ memset (pstr, '\0', sizeof (re_string_t));
+ re_string_construct_common (str, len, pstr, trans, icase, dfa);
+
+ if (len > 0)
+ {
+ ret = re_string_realloc_buffers (pstr, len + 1);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
+
+ if (icase)
+ {
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ while (1)
+ {
+ ret = build_wcs_upper_buffer (pstr);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ if (pstr->valid_raw_len >= len)
+ break;
+ if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max)
+ break;
+ ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ build_upper_buffer (pstr);
+ }
+ else
+ {
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ build_wcs_buffer (pstr);
+ else
+#endif /* RE_ENABLE_I18N */
+ {
+ if (trans != NULL)
+ re_string_translate_buffer (pstr);
+ else
+ {
+ pstr->valid_len = pstr->bufs_len;
+ pstr->valid_raw_len = pstr->bufs_len;
+ }
+ }
+ }
+
+ return REG_NOERROR;
+}
+
+/* Helper functions for re_string_allocate, and re_string_construct. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
+{
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ wint_t *new_wcs;
+
+ /* Avoid overflow in realloc. */
+ const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
+ if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_buf_len, 0))
+ return REG_ESPACE;
+
+ new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
+ if (BE (new_wcs == NULL, 0))
+ return REG_ESPACE;
+ pstr->wcs = new_wcs;
+ if (pstr->offsets != NULL)
+ {
+ Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
+ if (BE (new_offsets == NULL, 0))
+ return REG_ESPACE;
+ pstr->offsets = new_offsets;
+ }
+ }
+#endif /* RE_ENABLE_I18N */
+ if (pstr->mbs_allocated)
+ {
+ unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char,
+ new_buf_len);
+ if (BE (new_mbs == NULL, 0))
+ return REG_ESPACE;
+ pstr->mbs = new_mbs;
+ }
+ pstr->bufs_len = new_buf_len;
+ return REG_NOERROR;
+}
+
+
+static void
+internal_function
+re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
+ RE_TRANSLATE_TYPE trans, bool icase,
+ const re_dfa_t *dfa)
+{
+ pstr->raw_mbs = (const unsigned char *) str;
+ pstr->len = len;
+ pstr->raw_len = len;
+ pstr->trans = trans;
+ pstr->icase = icase;
+ pstr->mbs_allocated = (trans != NULL || icase);
+ pstr->mb_cur_max = dfa->mb_cur_max;
+ pstr->is_utf8 = dfa->is_utf8;
+ pstr->map_notascii = dfa->map_notascii;
+ pstr->stop = pstr->len;
+ pstr->raw_stop = pstr->stop;
+}
+
+#ifdef RE_ENABLE_I18N
+
+/* Build wide character buffer PSTR->WCS.
+ If the byte sequence of the string are:
+ <mb1>(0), <mb1>(1), <mb2>(0), <mb2>(1), <sb3>
+ Then wide character buffer will be:
+ <wc1> , WEOF , <wc2> , WEOF , <wc3>
+ We use WEOF for padding, they indicate that the position isn't
+ a first byte of a multibyte character.
+
+ Note that this function assumes PSTR->VALID_LEN elements are already
+ built and starts from PSTR->VALID_LEN. */
+
+static void
+internal_function
+build_wcs_buffer (re_string_t *pstr)
+{
+#ifdef _LIBC
+ unsigned char buf[MB_LEN_MAX];
+ assert (MB_LEN_MAX >= pstr->mb_cur_max);
+#else
+ unsigned char buf[64];
+#endif
+ mbstate_t prev_st;
+ Idx byte_idx, end_idx, remain_len;
+ size_t mbclen;
+
+ /* Build the buffers from pstr->valid_len to either pstr->len or
+ pstr->bufs_len. */
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+ for (byte_idx = pstr->valid_len; byte_idx < end_idx;)
+ {
+ wchar_t wc;
+ const char *p;
+
+ remain_len = end_idx - byte_idx;
+ prev_st = pstr->cur_state;
+ /* Apply the translation if we need. */
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i, ch;
+
+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
+ {
+ ch = pstr->raw_mbs [pstr->raw_mbs_idx + byte_idx + i];
+ buf[i] = pstr->mbs[byte_idx + i] = pstr->trans[ch];
+ }
+ p = (const char *) buf;
+ }
+ else
+ p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx;
+ mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
+ if (BE (mbclen == (size_t) -1 || mbclen == 0
+ || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len), 0))
+ {
+ /* We treat these cases as a singlebyte character. */
+ mbclen = 1;
+ wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
+ if (BE (pstr->trans != NULL, 0))
+ wc = pstr->trans[wc];
+ pstr->cur_state = prev_st;
+ }
+ else if (BE (mbclen == (size_t) -2, 0))
+ {
+ /* The buffer doesn't have enough space, finish to build. */
+ pstr->cur_state = prev_st;
+ break;
+ }
+
+ /* Write wide character and padding. */
+ pstr->wcs[byte_idx++] = wc;
+ /* Write paddings. */
+ for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
+ pstr->wcs[byte_idx++] = WEOF;
+ }
+ pstr->valid_len = byte_idx;
+ pstr->valid_raw_len = byte_idx;
+}
+
+/* Build wide character buffer PSTR->WCS like build_wcs_buffer,
+ but for REG_ICASE. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+build_wcs_upper_buffer (re_string_t *pstr)
+{
+ mbstate_t prev_st;
+ Idx src_idx, byte_idx, end_idx, remain_len;
+ size_t mbclen;
+#ifdef _LIBC
+ char buf[MB_LEN_MAX];
+ assert (MB_LEN_MAX >= pstr->mb_cur_max);
+#else
+ char buf[64];
+#endif
+
+ byte_idx = pstr->valid_len;
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+
+ /* The following optimization assumes that ASCII characters can be
+ mapped to wide characters with a simple cast. */
+ if (! pstr->map_notascii && pstr->trans == NULL && !pstr->offsets_needed)
+ {
+ while (byte_idx < end_idx)
+ {
+ wchar_t wc;
+
+ if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx])
+ && mbsinit (&pstr->cur_state))
+ {
+ /* In case of a singlebyte character. */
+ pstr->mbs[byte_idx]
+ = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]);
+ /* The next step uses the assumption that wchar_t is encoded
+ ASCII-safe: all ASCII values can be converted like this. */
+ pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx];
+ ++byte_idx;
+ continue;
+ }
+
+ remain_len = end_idx - byte_idx;
+ prev_st = pstr->cur_state;
+ mbclen = __mbrtowc (&wc,
+ ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
+ + byte_idx), remain_len, &pstr->cur_state);
+ if (BE (mbclen < (size_t) -2, 1))
+ {
+ wchar_t wcu = wc;
+ if (iswlower (wc))
+ {
+ size_t mbcdlen;
+
+ wcu = towupper (wc);
+ mbcdlen = wcrtomb (buf, wcu, &prev_st);
+ if (BE (mbclen == mbcdlen, 1))
+ memcpy (pstr->mbs + byte_idx, buf, mbclen);
+ else
+ {
+ src_idx = byte_idx;
+ goto offsets_needed;
+ }
+ }
+ else
+ memcpy (pstr->mbs + byte_idx,
+ pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx, mbclen);
+ pstr->wcs[byte_idx++] = wcu;
+ /* Write paddings. */
+ for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
+ pstr->wcs[byte_idx++] = WEOF;
+ }
+ else if (mbclen == (size_t) -1 || mbclen == 0
+ || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len))
+ {
+ /* It is an invalid character, an incomplete character
+ at the end of the string, or '\0'. Just use the byte. */
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
+ pstr->mbs[byte_idx] = ch;
+ /* And also cast it to wide char. */
+ pstr->wcs[byte_idx++] = (wchar_t) ch;
+ if (BE (mbclen == (size_t) -1, 0))
+ pstr->cur_state = prev_st;
+ }
+ else
+ {
+ /* The buffer doesn't have enough space, finish to build. */
+ pstr->cur_state = prev_st;
+ break;
+ }
+ }
+ pstr->valid_len = byte_idx;
+ pstr->valid_raw_len = byte_idx;
+ return REG_NOERROR;
+ }
+ else
+ for (src_idx = pstr->valid_raw_len; byte_idx < end_idx;)
+ {
+ wchar_t wc;
+ const char *p;
+ offsets_needed:
+ remain_len = end_idx - byte_idx;
+ prev_st = pstr->cur_state;
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i, ch;
+
+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
+ {
+ ch = pstr->raw_mbs [pstr->raw_mbs_idx + src_idx + i];
+ buf[i] = pstr->trans[ch];
+ }
+ p = (const char *) buf;
+ }
+ else
+ p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
+ mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
+ if (BE (mbclen < (size_t) -2, 1))
+ {
+ wchar_t wcu = wc;
+ if (iswlower (wc))
+ {
+ size_t mbcdlen;
+
+ wcu = towupper (wc);
+ mbcdlen = wcrtomb ((char *) buf, wcu, &prev_st);
+ if (BE (mbclen == mbcdlen, 1))
+ memcpy (pstr->mbs + byte_idx, buf, mbclen);
+ else if (mbcdlen != (size_t) -1)
+ {
+ size_t i;
+
+ if (byte_idx + mbcdlen > pstr->bufs_len)
+ {
+ pstr->cur_state = prev_st;
+ break;
+ }
+
+ if (pstr->offsets == NULL)
+ {
+ pstr->offsets = re_malloc (Idx, pstr->bufs_len);
+
+ if (pstr->offsets == NULL)
+ return REG_ESPACE;
+ }
+ if (!pstr->offsets_needed)
+ {
+ for (i = 0; i < (size_t) byte_idx; ++i)
+ pstr->offsets[i] = i;
+ pstr->offsets_needed = 1;
+ }
+
+ memcpy (pstr->mbs + byte_idx, buf, mbcdlen);
+ pstr->wcs[byte_idx] = wcu;
+ pstr->offsets[byte_idx] = src_idx;
+ for (i = 1; i < mbcdlen; ++i)
+ {
+ pstr->offsets[byte_idx + i]
+ = src_idx + (i < mbclen ? i : mbclen - 1);
+ pstr->wcs[byte_idx + i] = WEOF;
+ }
+ pstr->len += mbcdlen - mbclen;
+ if (pstr->raw_stop > src_idx)
+ pstr->stop += mbcdlen - mbclen;
+ end_idx = (pstr->bufs_len > pstr->len)
+ ? pstr->len : pstr->bufs_len;
+ byte_idx += mbcdlen;
+ src_idx += mbclen;
+ continue;
+ }
+ else
+ memcpy (pstr->mbs + byte_idx, p, mbclen);
+ }
+ else
+ memcpy (pstr->mbs + byte_idx, p, mbclen);
+
+ if (BE (pstr->offsets_needed != 0, 0))
+ {
+ size_t i;
+ for (i = 0; i < mbclen; ++i)
+ pstr->offsets[byte_idx + i] = src_idx + i;
+ }
+ src_idx += mbclen;
+
+ pstr->wcs[byte_idx++] = wcu;
+ /* Write paddings. */
+ for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
+ pstr->wcs[byte_idx++] = WEOF;
+ }
+ else if (mbclen == (size_t) -1 || mbclen == 0
+ || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len))
+ {
+ /* It is an invalid character or '\0'. Just use the byte. */
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx];
+
+ if (BE (pstr->trans != NULL, 0))
+ ch = pstr->trans [ch];
+ pstr->mbs[byte_idx] = ch;
+
+ if (BE (pstr->offsets_needed != 0, 0))
+ pstr->offsets[byte_idx] = src_idx;
+ ++src_idx;
+
+ /* And also cast it to wide char. */
+ pstr->wcs[byte_idx++] = (wchar_t) ch;
+ if (BE (mbclen == (size_t) -1, 0))
+ pstr->cur_state = prev_st;
+ }
+ else
+ {
+ /* The buffer doesn't have enough space, finish to build. */
+ pstr->cur_state = prev_st;
+ break;
+ }
+ }
+ pstr->valid_len = byte_idx;
+ pstr->valid_raw_len = src_idx;
+ return REG_NOERROR;
+}
+
+/* Skip characters until the index becomes greater than NEW_RAW_IDX.
+ Return the index. */
+
+static Idx
+internal_function
+re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
+{
+ mbstate_t prev_st;
+ Idx rawbuf_idx;
+ size_t mbclen;
+ wint_t wc = WEOF;
+
+ /* Skip the characters which are not necessary to check. */
+ for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len;
+ rawbuf_idx < new_raw_idx;)
+ {
+ wchar_t wc2;
+ Idx remain_len = pstr->raw_len - rawbuf_idx;
+ prev_st = pstr->cur_state;
+ mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
+ remain_len, &pstr->cur_state);
+ if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0))
+ {
+ /* We treat these cases as a single byte character. */
+ if (mbclen == 0 || remain_len == 0)
+ wc = L'\0';
+ else
+ wc = *(unsigned char *) (pstr->raw_mbs + rawbuf_idx);
+ mbclen = 1;
+ pstr->cur_state = prev_st;
+ }
+ else
+ wc = wc2;
+ /* Then proceed the next character. */
+ rawbuf_idx += mbclen;
+ }
+ *last_wc = wc;
+ return rawbuf_idx;
+}
+#endif /* RE_ENABLE_I18N */
+
+/* Build the buffer PSTR->MBS, and apply the translation if we need.
+ This function is used in case of REG_ICASE. */
+
+static void
+internal_function
+build_upper_buffer (re_string_t *pstr)
+{
+ Idx char_idx, end_idx;
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+
+ for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx)
+ {
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx];
+ if (BE (pstr->trans != NULL, 0))
+ ch = pstr->trans[ch];
+ if (islower (ch))
+ pstr->mbs[char_idx] = toupper (ch);
+ else
+ pstr->mbs[char_idx] = ch;
+ }
+ pstr->valid_len = char_idx;
+ pstr->valid_raw_len = char_idx;
+}
+
+/* Apply TRANS to the buffer in PSTR. */
+
+static void
+internal_function
+re_string_translate_buffer (re_string_t *pstr)
+{
+ Idx buf_idx, end_idx;
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+
+ for (buf_idx = pstr->valid_len; buf_idx < end_idx; ++buf_idx)
+ {
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + buf_idx];
+ pstr->mbs[buf_idx] = pstr->trans[ch];
+ }
+
+ pstr->valid_len = buf_idx;
+ pstr->valid_raw_len = buf_idx;
+}
+
+/* This function re-construct the buffers.
+ Concretely, convert to wide character in case of pstr->mb_cur_max > 1,
+ convert to upper case in case of REG_ICASE, apply translation. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
+{
+ Idx offset;
+
+ if (BE (pstr->raw_mbs_idx <= idx, 0))
+ offset = idx - pstr->raw_mbs_idx;
+ else
+ {
+ /* Reset buffer. */
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
+#endif /* RE_ENABLE_I18N */
+ pstr->len = pstr->raw_len;
+ pstr->stop = pstr->raw_stop;
+ pstr->valid_len = 0;
+ pstr->raw_mbs_idx = 0;
+ pstr->valid_raw_len = 0;
+ pstr->offsets_needed = 0;
+ pstr->tip_context = ((eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
+ : CONTEXT_NEWLINE | CONTEXT_BEGBUF);
+ if (!pstr->mbs_allocated)
+ pstr->mbs = (unsigned char *) pstr->raw_mbs;
+ offset = idx;
+ }
+
+ if (BE (offset != 0, 1))
+ {
+ /* Should the already checked characters be kept? */
+ if (BE (offset < pstr->valid_raw_len, 1))
+ {
+ /* Yes, move them to the front of the buffer. */
+#ifdef RE_ENABLE_I18N
+ if (BE (pstr->offsets_needed, 0))
+ {
+ Idx low = 0, high = pstr->valid_len, mid;
+ do
+ {
+ mid = (high + low) / 2;
+ if (pstr->offsets[mid] > offset)
+ high = mid;
+ else if (pstr->offsets[mid] < offset)
+ low = mid + 1;
+ else
+ break;
+ }
+ while (low < high);
+ if (pstr->offsets[mid] < offset)
+ ++mid;
+ pstr->tip_context = re_string_context_at (pstr, mid - 1,
+ eflags);
+ /* This can be quite complicated, so handle specially
+ only the common and easy case where the character with
+ different length representation of lower and upper
+ case is present at or after offset. */
+ if (pstr->valid_len > offset
+ && mid == offset && pstr->offsets[mid] == offset)
+ {
+ memmove (pstr->wcs, pstr->wcs + offset,
+ (pstr->valid_len - offset) * sizeof (wint_t));
+ memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset);
+ pstr->valid_len -= offset;
+ pstr->valid_raw_len -= offset;
+ for (low = 0; low < pstr->valid_len; low++)
+ pstr->offsets[low] = pstr->offsets[low + offset] - offset;
+ }
+ else
+ {
+ /* Otherwise, just find out how long the partial multibyte
+ character at offset is and fill it with WEOF/255. */
+ pstr->len = pstr->raw_len - idx + offset;
+ pstr->stop = pstr->raw_stop - idx + offset;
+ pstr->offsets_needed = 0;
+ while (mid > 0 && pstr->offsets[mid - 1] == offset)
+ --mid;
+ while (mid < pstr->valid_len)
+ if (pstr->wcs[mid] != WEOF)
+ break;
+ else
+ ++mid;
+ if (mid == pstr->valid_len)
+ pstr->valid_len = 0;
+ else
+ {
+ pstr->valid_len = pstr->offsets[mid] - offset;
+ if (pstr->valid_len)
+ {
+ for (low = 0; low < pstr->valid_len; ++low)
+ pstr->wcs[low] = WEOF;
+ memset (pstr->mbs, 255, pstr->valid_len);
+ }
+ }
+ pstr->valid_raw_len = pstr->valid_len;
+ }
+ }
+ else
+#endif
+ {
+ pstr->tip_context = re_string_context_at (pstr, offset - 1,
+ eflags);
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ memmove (pstr->wcs, pstr->wcs + offset,
+ (pstr->valid_len - offset) * sizeof (wint_t));
+#endif /* RE_ENABLE_I18N */
+ if (BE (pstr->mbs_allocated, 0))
+ memmove (pstr->mbs, pstr->mbs + offset,
+ pstr->valid_len - offset);
+ pstr->valid_len -= offset;
+ pstr->valid_raw_len -= offset;
+#if DEBUG
+ assert (pstr->valid_len > 0);
+#endif
+ }
+ }
+ else
+ {
+#ifdef RE_ENABLE_I18N
+ /* No, skip all characters until IDX. */
+ Idx prev_valid_len = pstr->valid_len;
+
+ if (BE (pstr->offsets_needed, 0))
+ {
+ pstr->len = pstr->raw_len - idx + offset;
+ pstr->stop = pstr->raw_stop - idx + offset;
+ pstr->offsets_needed = 0;
+ }
+#endif
+ pstr->valid_len = 0;
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ Idx wcs_idx;
+ wint_t wc = WEOF;
+
+ if (pstr->is_utf8)
+ {
+ const unsigned char *raw, *p, *end;
+
+ /* Special case UTF-8. Multi-byte chars start with any
+ byte other than 0x80 - 0xbf. */
+ raw = pstr->raw_mbs + pstr->raw_mbs_idx;
+ end = raw + (offset - pstr->mb_cur_max);
+ if (end < pstr->raw_mbs)
+ end = pstr->raw_mbs;
+ p = raw + offset - 1;
+#ifdef _LIBC
+ /* We know the wchar_t encoding is UCS4, so for the simple
+ case, ASCII characters, skip the conversion step. */
+ if (isascii (*p) && BE (pstr->trans == NULL, 1))
+ {
+ memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
+ /* pstr->valid_len = 0; */
+ wc = (wchar_t) *p;
+ }
+ else
+#endif
+ for (; p >= end; --p)
+ if ((*p & 0xc0) != 0x80)
+ {
+ mbstate_t cur_state;
+ wchar_t wc2;
+ Idx mlen = raw + pstr->len - p;
+ unsigned char buf[6];
+ size_t mbclen;
+
+ const unsigned char *pp = p;
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i = mlen < 6 ? mlen : 6;
+ while (--i >= 0)
+ buf[i] = pstr->trans[p[i]];
+ pp = buf;
+ }
+ /* XXX Don't use mbrtowc, we know which conversion
+ to use (UTF-8 -> UCS4). */
+ memset (&cur_state, 0, sizeof (cur_state));
+ mbclen = __mbrtowc (&wc2, (const char *) pp, mlen,
+ &cur_state);
+ if (raw + offset - p <= mbclen
+ && mbclen < (size_t) -2)
+ {
+ memset (&pstr->cur_state, '\0',
+ sizeof (mbstate_t));
+ pstr->valid_len = mbclen - (raw + offset - p);
+ wc = wc2;
+ }
+ break;
+ }
+ }
+
+ if (wc == WEOF)
+ pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx;
+ if (wc == WEOF)
+ pstr->tip_context
+ = re_string_context_at (pstr, prev_valid_len - 1, eflags);
+ else
+ pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0)
+ && IS_WIDE_WORD_CHAR (wc))
+ ? CONTEXT_WORD
+ : ((IS_WIDE_NEWLINE (wc)
+ && pstr->newline_anchor)
+ ? CONTEXT_NEWLINE : 0));
+ if (BE (pstr->valid_len, 0))
+ {
+ for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx)
+ pstr->wcs[wcs_idx] = WEOF;
+ if (pstr->mbs_allocated)
+ memset (pstr->mbs, 255, pstr->valid_len);
+ }
+ pstr->valid_raw_len = pstr->valid_len;
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ {
+ int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1];
+ pstr->valid_raw_len = 0;
+ if (pstr->trans)
+ c = pstr->trans[c];
+ pstr->tip_context = (bitset_contain (pstr->word_char, c)
+ ? CONTEXT_WORD
+ : ((IS_NEWLINE (c) && pstr->newline_anchor)
+ ? CONTEXT_NEWLINE : 0));
+ }
+ }
+ if (!BE (pstr->mbs_allocated, 0))
+ pstr->mbs += offset;
+ }
+ pstr->raw_mbs_idx = idx;
+ pstr->len -= offset;
+ pstr->stop -= offset;
+
+ /* Then build the buffers. */
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ if (pstr->icase)
+ {
+ reg_errcode_t ret = build_wcs_upper_buffer (pstr);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ else
+ build_wcs_buffer (pstr);
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ if (BE (pstr->mbs_allocated, 0))
+ {
+ if (pstr->icase)
+ build_upper_buffer (pstr);
+ else if (pstr->trans != NULL)
+ re_string_translate_buffer (pstr);
+ }
+ else
+ pstr->valid_len = pstr->len;
+
+ pstr->cur_idx = 0;
+ return REG_NOERROR;
+}
+
+static unsigned char
+internal_function __attribute__ ((pure))
+re_string_peek_byte_case (const re_string_t *pstr, Idx idx)
+{
+ int ch;
+ Idx off;
+
+ /* Handle the common (easiest) cases first. */
+ if (BE (!pstr->mbs_allocated, 1))
+ return re_string_peek_byte (pstr, idx);
+
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1
+ && ! re_string_is_single_byte_char (pstr, pstr->cur_idx + idx))
+ return re_string_peek_byte (pstr, idx);
+#endif
+
+ off = pstr->cur_idx + idx;
+#ifdef RE_ENABLE_I18N
+ if (pstr->offsets_needed)
+ off = pstr->offsets[off];
+#endif
+
+ ch = pstr->raw_mbs[pstr->raw_mbs_idx + off];
+
+#ifdef RE_ENABLE_I18N
+ /* Ensure that e.g. for tr_TR.UTF-8 BACKSLASH DOTLESS SMALL LETTER I
+ this function returns CAPITAL LETTER I instead of first byte of
+ DOTLESS SMALL LETTER I. The latter would confuse the parser,
+ since peek_byte_case doesn't advance cur_idx in any way. */
+ if (pstr->offsets_needed && !isascii (ch))
+ return re_string_peek_byte (pstr, idx);
+#endif
+
+ return ch;
+}
+
+static unsigned char
+internal_function
+re_string_fetch_byte_case (re_string_t *pstr)
+{
+ if (BE (!pstr->mbs_allocated, 1))
+ return re_string_fetch_byte (pstr);
+
+#ifdef RE_ENABLE_I18N
+ if (pstr->offsets_needed)
+ {
+ Idx off;
+ int ch;
+
+ /* For tr_TR.UTF-8 [[:islower:]] there is
+ [[: CAPITAL LETTER I WITH DOT lower:]] in mbs. Skip
+ in that case the whole multi-byte character and return
+ the original letter. On the other side, with
+ [[: DOTLESS SMALL LETTER I return [[:I, as doing
+ anything else would complicate things too much. */
+
+ if (!re_string_first_byte (pstr, pstr->cur_idx))
+ return re_string_fetch_byte (pstr);
+
+ off = pstr->offsets[pstr->cur_idx];
+ ch = pstr->raw_mbs[pstr->raw_mbs_idx + off];
+
+ if (! isascii (ch))
+ return re_string_fetch_byte (pstr);
+
+ re_string_skip_bytes (pstr,
+ re_string_char_size_at (pstr, pstr->cur_idx));
+ return ch;
+ }
+#endif
+
+ return pstr->raw_mbs[pstr->raw_mbs_idx + pstr->cur_idx++];
+}
+
+static void
+internal_function
+re_string_destruct (re_string_t *pstr)
+{
+#ifdef RE_ENABLE_I18N
+ re_free (pstr->wcs);
+ re_free (pstr->offsets);
+#endif /* RE_ENABLE_I18N */
+ if (pstr->mbs_allocated)
+ re_free (pstr->mbs);
+}
+
+/* Return the context at IDX in INPUT. */
+
+static unsigned int
+internal_function
+re_string_context_at (const re_string_t *input, Idx idx, int eflags)
+{
+ int c;
+ if (BE (! REG_VALID_INDEX (idx), 0))
+ /* In this case, we use the value stored in input->tip_context,
+ since we can't know the character in input->mbs[-1] here. */
+ return input->tip_context;
+ if (BE (idx == input->len, 0))
+ return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF
+ : CONTEXT_NEWLINE | CONTEXT_ENDBUF);
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1)
+ {
+ wint_t wc;
+ Idx wc_idx = idx;
+ while(input->wcs[wc_idx] == WEOF)
+ {
+#ifdef DEBUG
+ /* It must not happen. */
+ assert (REG_VALID_INDEX (wc_idx));
+#endif
+ --wc_idx;
+ if (! REG_VALID_INDEX (wc_idx))
+ return input->tip_context;
+ }
+ wc = input->wcs[wc_idx];
+ if (BE (input->word_ops_used != 0, 0) && IS_WIDE_WORD_CHAR (wc))
+ return CONTEXT_WORD;
+ return (IS_WIDE_NEWLINE (wc) && input->newline_anchor
+ ? CONTEXT_NEWLINE : 0);
+ }
+ else
+#endif
+ {
+ c = re_string_byte_at (input, idx);
+ if (bitset_contain (input->word_char, c))
+ return CONTEXT_WORD;
+ return IS_NEWLINE (c) && input->newline_anchor ? CONTEXT_NEWLINE : 0;
+ }
+}
+
+/* Functions for set operation. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_alloc (re_node_set *set, Idx size)
+{
+ set->alloc = size;
+ set->nelem = 0;
+ set->elems = re_malloc (Idx, size);
+ if (BE (set->elems == NULL, 0) && (MALLOC_0_IS_NONNULL || size != 0))
+ return REG_ESPACE;
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_1 (re_node_set *set, Idx elem)
+{
+ set->alloc = 1;
+ set->nelem = 1;
+ set->elems = re_malloc (Idx, 1);
+ if (BE (set->elems == NULL, 0))
+ {
+ set->alloc = set->nelem = 0;
+ return REG_ESPACE;
+ }
+ set->elems[0] = elem;
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
+{
+ set->alloc = 2;
+ set->elems = re_malloc (Idx, 2);
+ if (BE (set->elems == NULL, 0))
+ return REG_ESPACE;
+ if (elem1 == elem2)
+ {
+ set->nelem = 1;
+ set->elems[0] = elem1;
+ }
+ else
+ {
+ set->nelem = 2;
+ if (elem1 < elem2)
+ {
+ set->elems[0] = elem1;
+ set->elems[1] = elem2;
+ }
+ else
+ {
+ set->elems[0] = elem2;
+ set->elems[1] = elem1;
+ }
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
+{
+ dest->nelem = src->nelem;
+ if (src->nelem > 0)
+ {
+ dest->alloc = dest->nelem;
+ dest->elems = re_malloc (Idx, dest->alloc);
+ if (BE (dest->elems == NULL, 0))
+ {
+ dest->alloc = dest->nelem = 0;
+ return REG_ESPACE;
+ }
+ memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
+ }
+ else
+ re_node_set_init_empty (dest);
+ return REG_NOERROR;
+}
+
+/* Calculate the intersection of the sets SRC1 and SRC2. And merge it to
+ DEST. Return value indicate the error code or REG_NOERROR if succeeded.
+ Note: We assume dest->elems is NULL, when dest->alloc is 0. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
+ const re_node_set *src2)
+{
+ Idx i1, i2, is, id, delta, sbase;
+ if (src1->nelem == 0 || src2->nelem == 0)
+ return REG_NOERROR;
+
+ /* We need dest->nelem + 2 * elems_in_intersection; this is a
+ conservative estimate. */
+ if (src1->nelem + src2->nelem + dest->nelem > dest->alloc)
+ {
+ Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
+ Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
+ if (BE (new_elems == NULL, 0))
+ return REG_ESPACE;
+ dest->elems = new_elems;
+ dest->alloc = new_alloc;
+ }
+
+ /* Find the items in the intersection of SRC1 and SRC2, and copy
+ into the top of DEST those that are not already in DEST itself. */
+ sbase = dest->nelem + src1->nelem + src2->nelem;
+ i1 = src1->nelem - 1;
+ i2 = src2->nelem - 1;
+ id = dest->nelem - 1;
+ for (;;)
+ {
+ if (src1->elems[i1] == src2->elems[i2])
+ {
+ /* Try to find the item in DEST. Maybe we could binary search? */
+ while (REG_VALID_INDEX (id) && dest->elems[id] > src1->elems[i1])
+ --id;
+
+ if (! REG_VALID_INDEX (id) || dest->elems[id] != src1->elems[i1])
+ dest->elems[--sbase] = src1->elems[i1];
+
+ if (! REG_VALID_INDEX (--i1) || ! REG_VALID_INDEX (--i2))
+ break;
+ }
+
+ /* Lower the highest of the two items. */
+ else if (src1->elems[i1] < src2->elems[i2])
+ {
+ if (! REG_VALID_INDEX (--i2))
+ break;
+ }
+ else
+ {
+ if (! REG_VALID_INDEX (--i1))
+ break;
+ }
+ }
+
+ id = dest->nelem - 1;
+ is = dest->nelem + src1->nelem + src2->nelem - 1;
+ delta = is - sbase + 1;
+
+ /* Now copy. When DELTA becomes zero, the remaining
+ DEST elements are already in place; this is more or
+ less the same loop that is in re_node_set_merge. */
+ dest->nelem += delta;
+ if (delta > 0 && REG_VALID_INDEX (id))
+ for (;;)
+ {
+ if (dest->elems[is] > dest->elems[id])
+ {
+ /* Copy from the top. */
+ dest->elems[id + delta--] = dest->elems[is--];
+ if (delta == 0)
+ break;
+ }
+ else
+ {
+ /* Slide from the bottom. */
+ dest->elems[id + delta] = dest->elems[id];
+ if (! REG_VALID_INDEX (--id))
+ break;
+ }
+ }
+
+ /* Copy remaining SRC elements. */
+ memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx));
+
+ return REG_NOERROR;
+}
+
+/* Calculate the union set of the sets SRC1 and SRC2. And store it to
+ DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
+ const re_node_set *src2)
+{
+ Idx i1, i2, id;
+ if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0)
+ {
+ dest->alloc = src1->nelem + src2->nelem;
+ dest->elems = re_malloc (Idx, dest->alloc);
+ if (BE (dest->elems == NULL, 0))
+ return REG_ESPACE;
+ }
+ else
+ {
+ if (src1 != NULL && src1->nelem > 0)
+ return re_node_set_init_copy (dest, src1);
+ else if (src2 != NULL && src2->nelem > 0)
+ return re_node_set_init_copy (dest, src2);
+ else
+ re_node_set_init_empty (dest);
+ return REG_NOERROR;
+ }
+ for (i1 = i2 = id = 0 ; i1 < src1->nelem && i2 < src2->nelem ;)
+ {
+ if (src1->elems[i1] > src2->elems[i2])
+ {
+ dest->elems[id++] = src2->elems[i2++];
+ continue;
+ }
+ if (src1->elems[i1] == src2->elems[i2])
+ ++i2;
+ dest->elems[id++] = src1->elems[i1++];
+ }
+ if (i1 < src1->nelem)
+ {
+ memcpy (dest->elems + id, src1->elems + i1,
+ (src1->nelem - i1) * sizeof (Idx));
+ id += src1->nelem - i1;
+ }
+ else if (i2 < src2->nelem)
+ {
+ memcpy (dest->elems + id, src2->elems + i2,
+ (src2->nelem - i2) * sizeof (Idx));
+ id += src2->nelem - i2;
+ }
+ dest->nelem = id;
+ return REG_NOERROR;
+}
+
+/* Calculate the union set of the sets DEST and SRC. And store it to
+ DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_merge (re_node_set *dest, const re_node_set *src)
+{
+ Idx is, id, sbase, delta;
+ if (src == NULL || src->nelem == 0)
+ return REG_NOERROR;
+ if (dest->alloc < 2 * src->nelem + dest->nelem)
+ {
+ Idx new_alloc = 2 * (src->nelem + dest->alloc);
+ Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
+ if (BE (new_buffer == NULL, 0))
+ return REG_ESPACE;
+ dest->elems = new_buffer;
+ dest->alloc = new_alloc;
+ }
+
+ if (BE (dest->nelem == 0, 0))
+ {
+ dest->nelem = src->nelem;
+ memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
+ return REG_NOERROR;
+ }
+
+ /* Copy into the top of DEST the items of SRC that are not
+ found in DEST. Maybe we could binary search in DEST? */
+ for (sbase = dest->nelem + 2 * src->nelem,
+ is = src->nelem - 1, id = dest->nelem - 1;
+ REG_VALID_INDEX (is) && REG_VALID_INDEX (id); )
+ {
+ if (dest->elems[id] == src->elems[is])
+ is--, id--;
+ else if (dest->elems[id] < src->elems[is])
+ dest->elems[--sbase] = src->elems[is--];
+ else /* if (dest->elems[id] > src->elems[is]) */
+ --id;
+ }
+
+ if (REG_VALID_INDEX (is))
+ {
+ /* If DEST is exhausted, the remaining items of SRC must be unique. */
+ sbase -= is + 1;
+ memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx));
+ }
+
+ id = dest->nelem - 1;
+ is = dest->nelem + 2 * src->nelem - 1;
+ delta = is - sbase + 1;
+ if (delta == 0)
+ return REG_NOERROR;
+
+ /* Now copy. When DELTA becomes zero, the remaining
+ DEST elements are already in place. */
+ dest->nelem += delta;
+ for (;;)
+ {
+ if (dest->elems[is] > dest->elems[id])
+ {
+ /* Copy from the top. */
+ dest->elems[id + delta--] = dest->elems[is--];
+ if (delta == 0)
+ break;
+ }
+ else
+ {
+ /* Slide from the bottom. */
+ dest->elems[id + delta] = dest->elems[id];
+ if (! REG_VALID_INDEX (--id))
+ {
+ /* Copy remaining SRC elements. */
+ memcpy (dest->elems, dest->elems + sbase,
+ delta * sizeof (Idx));
+ break;
+ }
+ }
+ }
+
+ return REG_NOERROR;
+}
+
+/* Insert the new element ELEM to the re_node_set* SET.
+ SET should not already have ELEM.
+ Return true if successful. */
+
+static bool
+internal_function __attribute_warn_unused_result__
+re_node_set_insert (re_node_set *set, Idx elem)
+{
+ Idx idx;
+ /* In case the set is empty. */
+ if (set->alloc == 0)
+ return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1);
+
+ if (BE (set->nelem, 0) == 0)
+ {
+ /* We already guaranteed above that set->alloc != 0. */
+ set->elems[0] = elem;
+ ++set->nelem;
+ return true;
+ }
+
+ /* Realloc if we need. */
+ if (set->alloc == set->nelem)
+ {
+ Idx *new_elems;
+ set->alloc = set->alloc * 2;
+ new_elems = re_realloc (set->elems, Idx, set->alloc);
+ if (BE (new_elems == NULL, 0))
+ return false;
+ set->elems = new_elems;
+ }
+
+ /* Move the elements which follows the new element. Test the
+ first element separately to skip a check in the inner loop. */
+ if (elem < set->elems[0])
+ {
+ idx = 0;
+ for (idx = set->nelem; idx > 0; idx--)
+ set->elems[idx] = set->elems[idx - 1];
+ }
+ else
+ {
+ for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
+ set->elems[idx] = set->elems[idx - 1];
+ }
+
+ /* Insert the new element. */
+ set->elems[idx] = elem;
+ ++set->nelem;
+ return true;
+}
+
+/* Insert the new element ELEM to the re_node_set* SET.
+ SET should not already have any element greater than or equal to ELEM.
+ Return true if successful. */
+
+static bool
+internal_function __attribute_warn_unused_result__
+re_node_set_insert_last (re_node_set *set, Idx elem)
+{
+ /* Realloc if we need. */
+ if (set->alloc == set->nelem)
+ {
+ Idx *new_elems;
+ set->alloc = (set->alloc + 1) * 2;
+ new_elems = re_realloc (set->elems, Idx, set->alloc);
+ if (BE (new_elems == NULL, 0))
+ return false;
+ set->elems = new_elems;
+ }
+
+ /* Insert the new element. */
+ set->elems[set->nelem++] = elem;
+ return true;
+}
+
+/* Compare two node sets SET1 and SET2.
+ Return true if SET1 and SET2 are equivalent. */
+
+static bool
+internal_function __attribute__ ((pure))
+re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
+{
+ Idx i;
+ if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem)
+ return false;
+ for (i = set1->nelem ; REG_VALID_INDEX (--i) ; )
+ if (set1->elems[i] != set2->elems[i])
+ return false;
+ return true;
+}
+
+/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */
+
+static Idx
+internal_function __attribute__ ((pure))
+re_node_set_contains (const re_node_set *set, Idx elem)
+{
+ __re_size_t idx, right, mid;
+ if (! REG_VALID_NONZERO_INDEX (set->nelem))
+ return 0;
+
+ /* Binary search the element. */
+ idx = 0;
+ right = set->nelem - 1;
+ while (idx < right)
+ {
+ mid = (idx + right) / 2;
+ if (set->elems[mid] < elem)
+ idx = mid + 1;
+ else
+ right = mid;
+ }
+ return set->elems[idx] == elem ? idx + 1 : 0;
+}
+
+static void
+internal_function
+re_node_set_remove_at (re_node_set *set, Idx idx)
+{
+ if (idx < 0 || idx >= set->nelem)
+ return;
+ --set->nelem;
+ for (; idx < set->nelem; idx++)
+ set->elems[idx] = set->elems[idx + 1];
+}
+
+
+/* Add the token TOKEN to dfa->nodes, and return the index of the token.
+ Or return REG_MISSING if an error occurred. */
+
+static Idx
+internal_function
+re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
+{
+ if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0))
+ {
+ size_t new_nodes_alloc = dfa->nodes_alloc * 2;
+ Idx *new_nexts, *new_indices;
+ re_node_set *new_edests, *new_eclosures;
+ re_token_t *new_nodes;
+
+ /* Avoid overflows in realloc. */
+ const size_t max_object_size = MAX (sizeof (re_token_t),
+ MAX (sizeof (re_node_set),
+ sizeof (Idx)));
+ if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_nodes_alloc, 0))
+ return REG_MISSING;
+
+ new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
+ if (BE (new_nodes == NULL, 0))
+ return REG_MISSING;
+ dfa->nodes = new_nodes;
+ new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
+ new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
+ new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
+ new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
+ if (BE (new_nexts == NULL || new_indices == NULL
+ || new_edests == NULL || new_eclosures == NULL, 0))
+ return REG_MISSING;
+ dfa->nexts = new_nexts;
+ dfa->org_indices = new_indices;
+ dfa->edests = new_edests;
+ dfa->eclosures = new_eclosures;
+ dfa->nodes_alloc = new_nodes_alloc;
+ }
+ dfa->nodes[dfa->nodes_len] = token;
+ dfa->nodes[dfa->nodes_len].constraint = 0;
+#ifdef RE_ENABLE_I18N
+ dfa->nodes[dfa->nodes_len].accept_mb =
+ ((token.type == OP_PERIOD && dfa->mb_cur_max > 1)
+ || token.type == COMPLEX_BRACKET);
+#endif
+ dfa->nexts[dfa->nodes_len] = REG_MISSING;
+ re_node_set_init_empty (dfa->edests + dfa->nodes_len);
+ re_node_set_init_empty (dfa->eclosures + dfa->nodes_len);
+ return dfa->nodes_len++;
+}
+
+static re_hashval_t
+internal_function
+calc_state_hash (const re_node_set *nodes, unsigned int context)
+{
+ re_hashval_t hash = nodes->nelem + context;
+ Idx i;
+ for (i = 0 ; i < nodes->nelem ; i++)
+ hash += nodes->elems[i];
+ return hash;
+}
+
+/* Search for the state whose node_set is equivalent to NODES.
+ Return the pointer to the state, if we found it in the DFA.
+ Otherwise create the new one and return it. In case of an error
+ return NULL and set the error code in ERR.
+ Note: - We assume NULL as the invalid state, then it is possible that
+ return value is NULL and ERR is REG_NOERROR.
+ - We never return non-NULL value in case of any errors, it is for
+ optimization. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
+ const re_node_set *nodes)
+{
+ re_hashval_t hash;
+ re_dfastate_t *new_state;
+ struct re_state_table_entry *spot;
+ Idx i;
+#ifdef lint
+ /* Suppress bogus uninitialized-variable warnings. */
+ *err = REG_NOERROR;
+#endif
+ if (BE (nodes->nelem == 0, 0))
+ {
+ *err = REG_NOERROR;
+ return NULL;
+ }
+ hash = calc_state_hash (nodes, 0);
+ spot = dfa->state_table + (hash & dfa->state_hash_mask);
+
+ for (i = 0 ; i < spot->num ; i++)
+ {
+ re_dfastate_t *state = spot->array[i];
+ if (hash != state->hash)
+ continue;
+ if (re_node_set_compare (&state->nodes, nodes))
+ return state;
+ }
+
+ /* There are no appropriate state in the dfa, create the new one. */
+ new_state = create_ci_newstate (dfa, nodes, hash);
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
+}
+
+/* Search for the state whose node_set is equivalent to NODES and
+ whose context is equivalent to CONTEXT.
+ Return the pointer to the state, if we found it in the DFA.
+ Otherwise create the new one and return it. In case of an error
+ return NULL and set the error code in ERR.
+ Note: - We assume NULL as the invalid state, then it is possible that
+ return value is NULL and ERR is REG_NOERROR.
+ - We never return non-NULL value in case of any errors, it is for
+ optimization. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
+ const re_node_set *nodes, unsigned int context)
+{
+ re_hashval_t hash;
+ re_dfastate_t *new_state;
+ struct re_state_table_entry *spot;
+ Idx i;
+#ifdef lint
+ /* Suppress bogus uninitialized-variable warnings. */
+ *err = REG_NOERROR;
+#endif
+ if (nodes->nelem == 0)
+ {
+ *err = REG_NOERROR;
+ return NULL;
+ }
+ hash = calc_state_hash (nodes, context);
+ spot = dfa->state_table + (hash & dfa->state_hash_mask);
+
+ for (i = 0 ; i < spot->num ; i++)
+ {
+ re_dfastate_t *state = spot->array[i];
+ if (state->hash == hash
+ && state->context == context
+ && re_node_set_compare (state->entrance_nodes, nodes))
+ return state;
+ }
+ /* There are no appropriate state in 'dfa', create the new one. */
+ new_state = create_cd_newstate (dfa, nodes, context, hash);
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
+}
+
+/* Finish initialization of the new state NEWSTATE, and using its hash value
+ HASH put in the appropriate bucket of DFA's state table. Return value
+ indicates the error code if failed. */
+
+static reg_errcode_t
+__attribute_warn_unused_result__
+register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
+ re_hashval_t hash)
+{
+ struct re_state_table_entry *spot;
+ reg_errcode_t err;
+ Idx i;
+
+ newstate->hash = hash;
+ err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem);
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ESPACE;
+ for (i = 0; i < newstate->nodes.nelem; i++)
+ {
+ Idx elem = newstate->nodes.elems[i];
+ if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
+ if (! re_node_set_insert_last (&newstate->non_eps_nodes, elem))
+ return REG_ESPACE;
+ }
+
+ spot = dfa->state_table + (hash & dfa->state_hash_mask);
+ if (BE (spot->alloc <= spot->num, 0))
+ {
+ Idx new_alloc = 2 * spot->num + 2;
+ re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
+ new_alloc);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ spot->array = new_array;
+ spot->alloc = new_alloc;
+ }
+ spot->array[spot->num++] = newstate;
+ return REG_NOERROR;
+}
+
+static void
+free_state (re_dfastate_t *state)
+{
+ re_node_set_free (&state->non_eps_nodes);
+ re_node_set_free (&state->inveclosure);
+ if (state->entrance_nodes != &state->nodes)
+ {
+ re_node_set_free (state->entrance_nodes);
+ re_free (state->entrance_nodes);
+ }
+ re_node_set_free (&state->nodes);
+ re_free (state->word_trtable);
+ re_free (state->trtable);
+ re_free (state);
+}
+
+/* Create the new state which is independent of contexts.
+ Return the new state if succeeded, otherwise return NULL. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
+ re_hashval_t hash)
+{
+ Idx i;
+ reg_errcode_t err;
+ re_dfastate_t *newstate;
+
+ newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
+ if (BE (newstate == NULL, 0))
+ return NULL;
+ err = re_node_set_init_copy (&newstate->nodes, nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_free (newstate);
+ return NULL;
+ }
+
+ newstate->entrance_nodes = &newstate->nodes;
+ for (i = 0 ; i < nodes->nelem ; i++)
+ {
+ re_token_t *node = dfa->nodes + nodes->elems[i];
+ re_token_type_t type = node->type;
+ if (type == CHARACTER && !node->constraint)
+ continue;
+#ifdef RE_ENABLE_I18N
+ newstate->accept_mb |= node->accept_mb;
+#endif /* RE_ENABLE_I18N */
+
+ /* If the state has the halt node, the state is a halt state. */
+ if (type == END_OF_RE)
+ newstate->halt = 1;
+ else if (type == OP_BACK_REF)
+ newstate->has_backref = 1;
+ else if (type == ANCHOR || node->constraint)
+ newstate->has_constraint = 1;
+ }
+ err = register_state (dfa, newstate, hash);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ free_state (newstate);
+ newstate = NULL;
+ }
+ return newstate;
+}
+
+/* Create the new state which is depend on the context CONTEXT.
+ Return the new state if succeeded, otherwise return NULL. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
+ unsigned int context, re_hashval_t hash)
+{
+ Idx i, nctx_nodes = 0;
+ reg_errcode_t err;
+ re_dfastate_t *newstate;
+
+ newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
+ if (BE (newstate == NULL, 0))
+ return NULL;
+ err = re_node_set_init_copy (&newstate->nodes, nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_free (newstate);
+ return NULL;
+ }
+
+ newstate->context = context;
+ newstate->entrance_nodes = &newstate->nodes;
+
+ for (i = 0 ; i < nodes->nelem ; i++)
+ {
+ re_token_t *node = dfa->nodes + nodes->elems[i];
+ re_token_type_t type = node->type;
+ unsigned int constraint = node->constraint;
+
+ if (type == CHARACTER && !constraint)
+ continue;
+#ifdef RE_ENABLE_I18N
+ newstate->accept_mb |= node->accept_mb;
+#endif /* RE_ENABLE_I18N */
+
+ /* If the state has the halt node, the state is a halt state. */
+ if (type == END_OF_RE)
+ newstate->halt = 1;
+ else if (type == OP_BACK_REF)
+ newstate->has_backref = 1;
+
+ if (constraint)
+ {
+ if (newstate->entrance_nodes == &newstate->nodes)
+ {
+ newstate->entrance_nodes = re_malloc (re_node_set, 1);
+ if (BE (newstate->entrance_nodes == NULL, 0))
+ {
+ free_state (newstate);
+ return NULL;
+ }
+ if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
+ != REG_NOERROR)
+ return NULL;
+ nctx_nodes = 0;
+ newstate->has_constraint = 1;
+ }
+
+ if (NOT_SATISFY_PREV_CONSTRAINT (constraint,context))
+ {
+ re_node_set_remove_at (&newstate->nodes, i - nctx_nodes);
+ ++nctx_nodes;
+ }
+ }
+ }
+ err = register_state (dfa, newstate, hash);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ free_state (newstate);
+ newstate = NULL;
+ }
+ return newstate;
+}
diff --git a/contrib/tools/bison/gnulib/src/regex_internal.h b/contrib/tools/bison/gnulib/src/regex_internal.h
index 6205dbe726..95a88a9abb 100644
--- a/contrib/tools/bison/gnulib/src/regex_internal.h
+++ b/contrib/tools/bison/gnulib/src/regex_internal.h
@@ -1,909 +1,909 @@
-/* Extended regular expression matching and search library.
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-#ifndef _REGEX_INTERNAL_H
-#define _REGEX_INTERNAL_H 1
-
-#include <assert.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <langinfo.h>
-#include <locale.h>
-#include <wchar.h>
-#include <wctype.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#ifdef _LIBC
-# include <bits/libc-lock.h>
-# define lock_define(name) __libc_lock_define (, name)
-# define lock_init(lock) (__libc_lock_init (lock), 0)
-# define lock_fini(lock) 0
-# define lock_lock(lock) __libc_lock_lock (lock)
-# define lock_unlock(lock) __libc_lock_unlock (lock)
-#elif defined GNULIB_LOCK
-# include "glthread/lock.h"
- /* Use gl_lock_define if empty macro arguments are known to work.
- Otherwise, fall back on less-portable substitutes. */
-# if ((defined __GNUC__ && !defined __STRICT_ANSI__) \
- || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))
-# define lock_define(name) gl_lock_define (, name)
-# elif USE_POSIX_THREADS
-# define lock_define(name) pthread_mutex_t name;
-# elif USE_PTH_THREADS
-# define lock_define(name) pth_mutex_t name;
-# elif USE_SOLARIS_THREADS
-# define lock_define(name) mutex_t name;
-# elif USE_WINDOWS_THREADS
-# define lock_define(name) gl_lock_t name;
-# else
-# define lock_define(name)
-# endif
-# define lock_init(lock) glthread_lock_init (&(lock))
-# define lock_fini(lock) glthread_lock_destroy (&(lock))
-# define lock_lock(lock) glthread_lock_lock (&(lock))
-# define lock_unlock(lock) glthread_lock_unlock (&(lock))
-#elif defined GNULIB_PTHREAD
-# include <pthread.h>
-# define lock_define(name) pthread_mutex_t name;
-# define lock_init(lock) pthread_mutex_init (&(lock), 0)
-# define lock_fini(lock) pthread_mutex_destroy (&(lock))
-# define lock_lock(lock) pthread_mutex_lock (&(lock))
-# define lock_unlock(lock) pthread_mutex_unlock (&(lock))
-#else
-# define lock_define(name)
-# define lock_init(lock) 0
-# define lock_fini(lock) ((void) 0)
- /* The 'dfa' avoids an "unused variable 'dfa'" warning from GCC. */
-# define lock_lock(lock) ((void) dfa)
-# define lock_unlock(lock) ((void) 0)
-#endif
-
-/* In case that the system doesn't have isblank(). */
-#if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
-# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
-#endif
-
-#ifdef _LIBC
-# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
-# define _RE_DEFINE_LOCALE_FUNCTIONS 1
-# include <locale/localeinfo.h>
-# include <locale/elem-hash.h>
-# include <locale/coll-lookup.h>
-# endif
-#endif
-
-/* This is for other GNU distributions with internationalized messages. */
-#if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
-# include <libintl.h>
-# ifdef _LIBC
-# undef gettext
-# define gettext(msgid) \
- __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES)
-# endif
-#else
-# define gettext(msgid) (msgid)
-#endif
-
-#ifndef gettext_noop
-/* This define is so xgettext can find the internationalizable
- strings. */
-# define gettext_noop(String) String
-#endif
-
-#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCSCOLL) || _LIBC
-# define RE_ENABLE_I18N
-#endif
-
-#if __GNUC__ >= 3
-# define BE(expr, val) __builtin_expect (expr, val)
-#else
-# define BE(expr, val) (expr)
-#endif
-
-/* Number of ASCII characters. */
-#define ASCII_CHARS 0x80
-
-/* Number of single byte characters. */
-#define SBC_MAX (UCHAR_MAX + 1)
-
-#define COLL_ELEM_LEN_MAX 8
-
-/* The character which represents newline. */
-#define NEWLINE_CHAR '\n'
-#define WIDE_NEWLINE_CHAR L'\n'
-
-/* Rename to standard API for using out of glibc. */
-#ifndef _LIBC
-# undef __wctype
-# undef __iswctype
-# define __wctype wctype
-# define __iswctype iswctype
-# define __btowc btowc
-# define __mbrtowc mbrtowc
-# define __wcrtomb wcrtomb
-# define __regfree regfree
-# define attribute_hidden
-#endif /* not _LIBC */
-
-#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1)
-# define __attribute__(arg)
-#endif
-
-typedef __re_idx_t Idx;
-#ifdef _REGEX_LARGE_OFFSETS
-# define IDX_MAX (SIZE_MAX - 2)
-#else
-# define IDX_MAX INT_MAX
-#endif
-
-/* Special return value for failure to match. */
-#define REG_MISSING ((Idx) -1)
-
-/* Special return value for internal error. */
-#define REG_ERROR ((Idx) -2)
-
-/* Test whether N is a valid index, and is not one of the above. */
-#ifdef _REGEX_LARGE_OFFSETS
-# define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR)
-#else
-# define REG_VALID_INDEX(n) (0 <= (n))
-#endif
-
-/* Test whether N is a valid nonzero index. */
-#ifdef _REGEX_LARGE_OFFSETS
-# define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1))
-#else
-# define REG_VALID_NONZERO_INDEX(n) (0 < (n))
-#endif
-
-/* A hash value, suitable for computing hash tables. */
-typedef __re_size_t re_hashval_t;
-
-/* An integer used to represent a set of bits. It must be unsigned,
- and must be at least as wide as unsigned int. */
-typedef unsigned long int bitset_word_t;
-/* All bits set in a bitset_word_t. */
-#define BITSET_WORD_MAX ULONG_MAX
-
-/* Number of bits in a bitset_word_t. For portability to hosts with
- padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
- instead, deduce it directly from BITSET_WORD_MAX. Avoid
- greater-than-32-bit integers and unconditional shifts by more than
- 31 bits, as they're not portable. */
-#if BITSET_WORD_MAX == 0xffffffffUL
-# define BITSET_WORD_BITS 32
-#elif BITSET_WORD_MAX >> 31 >> 4 == 1
-# define BITSET_WORD_BITS 36
-#elif BITSET_WORD_MAX >> 31 >> 16 == 1
-# define BITSET_WORD_BITS 48
-#elif BITSET_WORD_MAX >> 31 >> 28 == 1
-# define BITSET_WORD_BITS 60
-#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
-# define BITSET_WORD_BITS 64
-#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
-# define BITSET_WORD_BITS 72
-#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
-# define BITSET_WORD_BITS 128
-#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
-# define BITSET_WORD_BITS 256
-#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
-# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
-# if BITSET_WORD_BITS <= SBC_MAX
-# error "Invalid SBC_MAX"
-# endif
-#else
-# error "Add case for new bitset_word_t size"
-#endif
-
-/* Number of bitset_word_t values in a bitset_t. */
-#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
-
-typedef bitset_word_t bitset_t[BITSET_WORDS];
-typedef bitset_word_t *re_bitset_ptr_t;
-typedef const bitset_word_t *re_const_bitset_ptr_t;
-
-#define PREV_WORD_CONSTRAINT 0x0001
-#define PREV_NOTWORD_CONSTRAINT 0x0002
-#define NEXT_WORD_CONSTRAINT 0x0004
-#define NEXT_NOTWORD_CONSTRAINT 0x0008
-#define PREV_NEWLINE_CONSTRAINT 0x0010
-#define NEXT_NEWLINE_CONSTRAINT 0x0020
-#define PREV_BEGBUF_CONSTRAINT 0x0040
-#define NEXT_ENDBUF_CONSTRAINT 0x0080
-#define WORD_DELIM_CONSTRAINT 0x0100
-#define NOT_WORD_DELIM_CONSTRAINT 0x0200
-
-typedef enum
-{
- INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
- WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
- WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
- INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
- LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
- LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
- BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
- BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
- WORD_DELIM = WORD_DELIM_CONSTRAINT,
- NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT
-} re_context_type;
-
-typedef struct
-{
- Idx alloc;
- Idx nelem;
- Idx *elems;
-} re_node_set;
-
-typedef enum
-{
- NON_TYPE = 0,
-
- /* Node type, These are used by token, node, tree. */
- CHARACTER = 1,
- END_OF_RE = 2,
- SIMPLE_BRACKET = 3,
- OP_BACK_REF = 4,
- OP_PERIOD = 5,
-#ifdef RE_ENABLE_I18N
- COMPLEX_BRACKET = 6,
- OP_UTF8_PERIOD = 7,
-#endif /* RE_ENABLE_I18N */
-
- /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
- when the debugger shows values of this enum type. */
-#define EPSILON_BIT 8
- OP_OPEN_SUBEXP = EPSILON_BIT | 0,
- OP_CLOSE_SUBEXP = EPSILON_BIT | 1,
- OP_ALT = EPSILON_BIT | 2,
- OP_DUP_ASTERISK = EPSILON_BIT | 3,
- ANCHOR = EPSILON_BIT | 4,
-
- /* Tree type, these are used only by tree. */
- CONCAT = 16,
- SUBEXP = 17,
-
- /* Token type, these are used only by token. */
- OP_DUP_PLUS = 18,
- OP_DUP_QUESTION,
- OP_OPEN_BRACKET,
- OP_CLOSE_BRACKET,
- OP_CHARSET_RANGE,
- OP_OPEN_DUP_NUM,
- OP_CLOSE_DUP_NUM,
- OP_NON_MATCH_LIST,
- OP_OPEN_COLL_ELEM,
- OP_CLOSE_COLL_ELEM,
- OP_OPEN_EQUIV_CLASS,
- OP_CLOSE_EQUIV_CLASS,
- OP_OPEN_CHAR_CLASS,
- OP_CLOSE_CHAR_CLASS,
- OP_WORD,
- OP_NOTWORD,
- OP_SPACE,
- OP_NOTSPACE,
- BACK_SLASH
-
-} re_token_type_t;
-
-#ifdef RE_ENABLE_I18N
-typedef struct
-{
- /* Multibyte characters. */
- wchar_t *mbchars;
-
- /* Collating symbols. */
-# ifdef _LIBC
- int32_t *coll_syms;
-# endif
-
- /* Equivalence classes. */
-# ifdef _LIBC
- int32_t *equiv_classes;
-# endif
-
- /* Range expressions. */
-# ifdef _LIBC
- uint32_t *range_starts;
- uint32_t *range_ends;
-# else /* not _LIBC */
- wchar_t *range_starts;
- wchar_t *range_ends;
-# endif /* not _LIBC */
-
- /* Character classes. */
- wctype_t *char_classes;
-
- /* If this character set is the non-matching list. */
- unsigned int non_match : 1;
-
- /* # of multibyte characters. */
- Idx nmbchars;
-
- /* # of collating symbols. */
- Idx ncoll_syms;
-
- /* # of equivalence classes. */
- Idx nequiv_classes;
-
- /* # of range expressions. */
- Idx nranges;
-
- /* # of character classes. */
- Idx nchar_classes;
-} re_charset_t;
-#endif /* RE_ENABLE_I18N */
-
-typedef struct
-{
- union
- {
- unsigned char c; /* for CHARACTER */
- re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */
-#ifdef RE_ENABLE_I18N
- re_charset_t *mbcset; /* for COMPLEX_BRACKET */
-#endif /* RE_ENABLE_I18N */
- Idx idx; /* for BACK_REF */
- re_context_type ctx_type; /* for ANCHOR */
- } opr;
-#if __GNUC__ >= 2 && !defined __STRICT_ANSI__
- re_token_type_t type : 8;
-#else
- re_token_type_t type;
-#endif
- unsigned int constraint : 10; /* context constraint */
- unsigned int duplicated : 1;
- unsigned int opt_subexp : 1;
-#ifdef RE_ENABLE_I18N
- unsigned int accept_mb : 1;
- /* These 2 bits can be moved into the union if needed (e.g. if running out
- of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */
- unsigned int mb_partial : 1;
-#endif
- unsigned int word_char : 1;
-} re_token_t;
-
-#define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT)
-
-struct re_string_t
-{
- /* Indicate the raw buffer which is the original string passed as an
- argument of regexec(), re_search(), etc.. */
- const unsigned char *raw_mbs;
- /* Store the multibyte string. In case of "case insensitive mode" like
- REG_ICASE, upper cases of the string are stored, otherwise MBS points
- the same address that RAW_MBS points. */
- unsigned char *mbs;
-#ifdef RE_ENABLE_I18N
- /* Store the wide character string which is corresponding to MBS. */
- wint_t *wcs;
- Idx *offsets;
- mbstate_t cur_state;
-#endif
- /* Index in RAW_MBS. Each character mbs[i] corresponds to
- raw_mbs[raw_mbs_idx + i]. */
- Idx raw_mbs_idx;
- /* The length of the valid characters in the buffers. */
- Idx valid_len;
- /* The corresponding number of bytes in raw_mbs array. */
- Idx valid_raw_len;
- /* The length of the buffers MBS and WCS. */
- Idx bufs_len;
- /* The index in MBS, which is updated by re_string_fetch_byte. */
- Idx cur_idx;
- /* length of RAW_MBS array. */
- Idx raw_len;
- /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN. */
- Idx len;
- /* End of the buffer may be shorter than its length in the cases such
- as re_match_2, re_search_2. Then, we use STOP for end of the buffer
- instead of LEN. */
- Idx raw_stop;
- /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS. */
- Idx stop;
-
- /* The context of mbs[0]. We store the context independently, since
- the context of mbs[0] may be different from raw_mbs[0], which is
- the beginning of the input string. */
- unsigned int tip_context;
- /* The translation passed as a part of an argument of re_compile_pattern. */
- RE_TRANSLATE_TYPE trans;
- /* Copy of re_dfa_t's word_char. */
- re_const_bitset_ptr_t word_char;
- /* true if REG_ICASE. */
- unsigned char icase;
- unsigned char is_utf8;
- unsigned char map_notascii;
- unsigned char mbs_allocated;
- unsigned char offsets_needed;
- unsigned char newline_anchor;
- unsigned char word_ops_used;
- int mb_cur_max;
-};
-typedef struct re_string_t re_string_t;
-
-
-struct re_dfa_t;
-typedef struct re_dfa_t re_dfa_t;
-
-#ifndef _LIBC
-# define internal_function
-#endif
-
-#ifndef NOT_IN_libc
-static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
- Idx new_buf_len)
- internal_function;
-# ifdef RE_ENABLE_I18N
-static void build_wcs_buffer (re_string_t *pstr) internal_function;
-static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
- internal_function;
-# endif /* RE_ENABLE_I18N */
-static void build_upper_buffer (re_string_t *pstr) internal_function;
-static void re_string_translate_buffer (re_string_t *pstr) internal_function;
-static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
- int eflags)
- internal_function __attribute__ ((pure));
-#endif
-#define re_string_peek_byte(pstr, offset) \
- ((pstr)->mbs[(pstr)->cur_idx + offset])
-#define re_string_fetch_byte(pstr) \
- ((pstr)->mbs[(pstr)->cur_idx++])
-#define re_string_first_byte(pstr, idx) \
- ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF)
-#define re_string_is_single_byte_char(pstr, idx) \
- ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \
- || (pstr)->wcs[(idx) + 1] != WEOF))
-#define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
-#define re_string_cur_idx(pstr) ((pstr)->cur_idx)
-#define re_string_get_buffer(pstr) ((pstr)->mbs)
-#define re_string_length(pstr) ((pstr)->len)
-#define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
-#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
-#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
-
-#if defined _LIBC || HAVE_ALLOCA
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifndef _REGEX_INTERNAL_H
+#define _REGEX_INTERNAL_H 1
+
+#include <assert.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <langinfo.h>
+#include <locale.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#ifdef _LIBC
+# include <bits/libc-lock.h>
+# define lock_define(name) __libc_lock_define (, name)
+# define lock_init(lock) (__libc_lock_init (lock), 0)
+# define lock_fini(lock) 0
+# define lock_lock(lock) __libc_lock_lock (lock)
+# define lock_unlock(lock) __libc_lock_unlock (lock)
+#elif defined GNULIB_LOCK
+# include "glthread/lock.h"
+ /* Use gl_lock_define if empty macro arguments are known to work.
+ Otherwise, fall back on less-portable substitutes. */
+# if ((defined __GNUC__ && !defined __STRICT_ANSI__) \
+ || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))
+# define lock_define(name) gl_lock_define (, name)
+# elif USE_POSIX_THREADS
+# define lock_define(name) pthread_mutex_t name;
+# elif USE_PTH_THREADS
+# define lock_define(name) pth_mutex_t name;
+# elif USE_SOLARIS_THREADS
+# define lock_define(name) mutex_t name;
+# elif USE_WINDOWS_THREADS
+# define lock_define(name) gl_lock_t name;
+# else
+# define lock_define(name)
+# endif
+# define lock_init(lock) glthread_lock_init (&(lock))
+# define lock_fini(lock) glthread_lock_destroy (&(lock))
+# define lock_lock(lock) glthread_lock_lock (&(lock))
+# define lock_unlock(lock) glthread_lock_unlock (&(lock))
+#elif defined GNULIB_PTHREAD
+# include <pthread.h>
+# define lock_define(name) pthread_mutex_t name;
+# define lock_init(lock) pthread_mutex_init (&(lock), 0)
+# define lock_fini(lock) pthread_mutex_destroy (&(lock))
+# define lock_lock(lock) pthread_mutex_lock (&(lock))
+# define lock_unlock(lock) pthread_mutex_unlock (&(lock))
+#else
+# define lock_define(name)
+# define lock_init(lock) 0
+# define lock_fini(lock) ((void) 0)
+ /* The 'dfa' avoids an "unused variable 'dfa'" warning from GCC. */
+# define lock_lock(lock) ((void) dfa)
+# define lock_unlock(lock) ((void) 0)
+#endif
+
+/* In case that the system doesn't have isblank(). */
+#if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
+# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
+#endif
+
+#ifdef _LIBC
+# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
+# define _RE_DEFINE_LOCALE_FUNCTIONS 1
+# include <locale/localeinfo.h>
+# include <locale/elem-hash.h>
+# include <locale/coll-lookup.h>
+# endif
+#endif
+
+/* This is for other GNU distributions with internationalized messages. */
+#if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
+# include <libintl.h>
+# ifdef _LIBC
+# undef gettext
+# define gettext(msgid) \
+ __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES)
+# endif
+#else
+# define gettext(msgid) (msgid)
+#endif
+
+#ifndef gettext_noop
+/* This define is so xgettext can find the internationalizable
+ strings. */
+# define gettext_noop(String) String
+#endif
+
+#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCSCOLL) || _LIBC
+# define RE_ENABLE_I18N
+#endif
+
+#if __GNUC__ >= 3
+# define BE(expr, val) __builtin_expect (expr, val)
+#else
+# define BE(expr, val) (expr)
+#endif
+
+/* Number of ASCII characters. */
+#define ASCII_CHARS 0x80
+
+/* Number of single byte characters. */
+#define SBC_MAX (UCHAR_MAX + 1)
+
+#define COLL_ELEM_LEN_MAX 8
+
+/* The character which represents newline. */
+#define NEWLINE_CHAR '\n'
+#define WIDE_NEWLINE_CHAR L'\n'
+
+/* Rename to standard API for using out of glibc. */
+#ifndef _LIBC
+# undef __wctype
+# undef __iswctype
+# define __wctype wctype
+# define __iswctype iswctype
+# define __btowc btowc
+# define __mbrtowc mbrtowc
+# define __wcrtomb wcrtomb
+# define __regfree regfree
+# define attribute_hidden
+#endif /* not _LIBC */
+
+#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1)
+# define __attribute__(arg)
+#endif
+
+typedef __re_idx_t Idx;
+#ifdef _REGEX_LARGE_OFFSETS
+# define IDX_MAX (SIZE_MAX - 2)
+#else
+# define IDX_MAX INT_MAX
+#endif
+
+/* Special return value for failure to match. */
+#define REG_MISSING ((Idx) -1)
+
+/* Special return value for internal error. */
+#define REG_ERROR ((Idx) -2)
+
+/* Test whether N is a valid index, and is not one of the above. */
+#ifdef _REGEX_LARGE_OFFSETS
+# define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR)
+#else
+# define REG_VALID_INDEX(n) (0 <= (n))
+#endif
+
+/* Test whether N is a valid nonzero index. */
+#ifdef _REGEX_LARGE_OFFSETS
+# define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1))
+#else
+# define REG_VALID_NONZERO_INDEX(n) (0 < (n))
+#endif
+
+/* A hash value, suitable for computing hash tables. */
+typedef __re_size_t re_hashval_t;
+
+/* An integer used to represent a set of bits. It must be unsigned,
+ and must be at least as wide as unsigned int. */
+typedef unsigned long int bitset_word_t;
+/* All bits set in a bitset_word_t. */
+#define BITSET_WORD_MAX ULONG_MAX
+
+/* Number of bits in a bitset_word_t. For portability to hosts with
+ padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
+ instead, deduce it directly from BITSET_WORD_MAX. Avoid
+ greater-than-32-bit integers and unconditional shifts by more than
+ 31 bits, as they're not portable. */
+#if BITSET_WORD_MAX == 0xffffffffUL
+# define BITSET_WORD_BITS 32
+#elif BITSET_WORD_MAX >> 31 >> 4 == 1
+# define BITSET_WORD_BITS 36
+#elif BITSET_WORD_MAX >> 31 >> 16 == 1
+# define BITSET_WORD_BITS 48
+#elif BITSET_WORD_MAX >> 31 >> 28 == 1
+# define BITSET_WORD_BITS 60
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
+# define BITSET_WORD_BITS 64
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
+# define BITSET_WORD_BITS 72
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
+# define BITSET_WORD_BITS 128
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
+# define BITSET_WORD_BITS 256
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
+# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
+# if BITSET_WORD_BITS <= SBC_MAX
+# error "Invalid SBC_MAX"
+# endif
+#else
+# error "Add case for new bitset_word_t size"
+#endif
+
+/* Number of bitset_word_t values in a bitset_t. */
+#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
+
+typedef bitset_word_t bitset_t[BITSET_WORDS];
+typedef bitset_word_t *re_bitset_ptr_t;
+typedef const bitset_word_t *re_const_bitset_ptr_t;
+
+#define PREV_WORD_CONSTRAINT 0x0001
+#define PREV_NOTWORD_CONSTRAINT 0x0002
+#define NEXT_WORD_CONSTRAINT 0x0004
+#define NEXT_NOTWORD_CONSTRAINT 0x0008
+#define PREV_NEWLINE_CONSTRAINT 0x0010
+#define NEXT_NEWLINE_CONSTRAINT 0x0020
+#define PREV_BEGBUF_CONSTRAINT 0x0040
+#define NEXT_ENDBUF_CONSTRAINT 0x0080
+#define WORD_DELIM_CONSTRAINT 0x0100
+#define NOT_WORD_DELIM_CONSTRAINT 0x0200
+
+typedef enum
+{
+ INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
+ WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
+ WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
+ INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
+ LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
+ LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
+ BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
+ BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
+ WORD_DELIM = WORD_DELIM_CONSTRAINT,
+ NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT
+} re_context_type;
+
+typedef struct
+{
+ Idx alloc;
+ Idx nelem;
+ Idx *elems;
+} re_node_set;
+
+typedef enum
+{
+ NON_TYPE = 0,
+
+ /* Node type, These are used by token, node, tree. */
+ CHARACTER = 1,
+ END_OF_RE = 2,
+ SIMPLE_BRACKET = 3,
+ OP_BACK_REF = 4,
+ OP_PERIOD = 5,
+#ifdef RE_ENABLE_I18N
+ COMPLEX_BRACKET = 6,
+ OP_UTF8_PERIOD = 7,
+#endif /* RE_ENABLE_I18N */
+
+ /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
+ when the debugger shows values of this enum type. */
+#define EPSILON_BIT 8
+ OP_OPEN_SUBEXP = EPSILON_BIT | 0,
+ OP_CLOSE_SUBEXP = EPSILON_BIT | 1,
+ OP_ALT = EPSILON_BIT | 2,
+ OP_DUP_ASTERISK = EPSILON_BIT | 3,
+ ANCHOR = EPSILON_BIT | 4,
+
+ /* Tree type, these are used only by tree. */
+ CONCAT = 16,
+ SUBEXP = 17,
+
+ /* Token type, these are used only by token. */
+ OP_DUP_PLUS = 18,
+ OP_DUP_QUESTION,
+ OP_OPEN_BRACKET,
+ OP_CLOSE_BRACKET,
+ OP_CHARSET_RANGE,
+ OP_OPEN_DUP_NUM,
+ OP_CLOSE_DUP_NUM,
+ OP_NON_MATCH_LIST,
+ OP_OPEN_COLL_ELEM,
+ OP_CLOSE_COLL_ELEM,
+ OP_OPEN_EQUIV_CLASS,
+ OP_CLOSE_EQUIV_CLASS,
+ OP_OPEN_CHAR_CLASS,
+ OP_CLOSE_CHAR_CLASS,
+ OP_WORD,
+ OP_NOTWORD,
+ OP_SPACE,
+ OP_NOTSPACE,
+ BACK_SLASH
+
+} re_token_type_t;
+
+#ifdef RE_ENABLE_I18N
+typedef struct
+{
+ /* Multibyte characters. */
+ wchar_t *mbchars;
+
+ /* Collating symbols. */
+# ifdef _LIBC
+ int32_t *coll_syms;
+# endif
+
+ /* Equivalence classes. */
+# ifdef _LIBC
+ int32_t *equiv_classes;
+# endif
+
+ /* Range expressions. */
+# ifdef _LIBC
+ uint32_t *range_starts;
+ uint32_t *range_ends;
+# else /* not _LIBC */
+ wchar_t *range_starts;
+ wchar_t *range_ends;
+# endif /* not _LIBC */
+
+ /* Character classes. */
+ wctype_t *char_classes;
+
+ /* If this character set is the non-matching list. */
+ unsigned int non_match : 1;
+
+ /* # of multibyte characters. */
+ Idx nmbchars;
+
+ /* # of collating symbols. */
+ Idx ncoll_syms;
+
+ /* # of equivalence classes. */
+ Idx nequiv_classes;
+
+ /* # of range expressions. */
+ Idx nranges;
+
+ /* # of character classes. */
+ Idx nchar_classes;
+} re_charset_t;
+#endif /* RE_ENABLE_I18N */
+
+typedef struct
+{
+ union
+ {
+ unsigned char c; /* for CHARACTER */
+ re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */
+#ifdef RE_ENABLE_I18N
+ re_charset_t *mbcset; /* for COMPLEX_BRACKET */
+#endif /* RE_ENABLE_I18N */
+ Idx idx; /* for BACK_REF */
+ re_context_type ctx_type; /* for ANCHOR */
+ } opr;
+#if __GNUC__ >= 2 && !defined __STRICT_ANSI__
+ re_token_type_t type : 8;
+#else
+ re_token_type_t type;
+#endif
+ unsigned int constraint : 10; /* context constraint */
+ unsigned int duplicated : 1;
+ unsigned int opt_subexp : 1;
+#ifdef RE_ENABLE_I18N
+ unsigned int accept_mb : 1;
+ /* These 2 bits can be moved into the union if needed (e.g. if running out
+ of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */
+ unsigned int mb_partial : 1;
+#endif
+ unsigned int word_char : 1;
+} re_token_t;
+
+#define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT)
+
+struct re_string_t
+{
+ /* Indicate the raw buffer which is the original string passed as an
+ argument of regexec(), re_search(), etc.. */
+ const unsigned char *raw_mbs;
+ /* Store the multibyte string. In case of "case insensitive mode" like
+ REG_ICASE, upper cases of the string are stored, otherwise MBS points
+ the same address that RAW_MBS points. */
+ unsigned char *mbs;
+#ifdef RE_ENABLE_I18N
+ /* Store the wide character string which is corresponding to MBS. */
+ wint_t *wcs;
+ Idx *offsets;
+ mbstate_t cur_state;
+#endif
+ /* Index in RAW_MBS. Each character mbs[i] corresponds to
+ raw_mbs[raw_mbs_idx + i]. */
+ Idx raw_mbs_idx;
+ /* The length of the valid characters in the buffers. */
+ Idx valid_len;
+ /* The corresponding number of bytes in raw_mbs array. */
+ Idx valid_raw_len;
+ /* The length of the buffers MBS and WCS. */
+ Idx bufs_len;
+ /* The index in MBS, which is updated by re_string_fetch_byte. */
+ Idx cur_idx;
+ /* length of RAW_MBS array. */
+ Idx raw_len;
+ /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN. */
+ Idx len;
+ /* End of the buffer may be shorter than its length in the cases such
+ as re_match_2, re_search_2. Then, we use STOP for end of the buffer
+ instead of LEN. */
+ Idx raw_stop;
+ /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS. */
+ Idx stop;
+
+ /* The context of mbs[0]. We store the context independently, since
+ the context of mbs[0] may be different from raw_mbs[0], which is
+ the beginning of the input string. */
+ unsigned int tip_context;
+ /* The translation passed as a part of an argument of re_compile_pattern. */
+ RE_TRANSLATE_TYPE trans;
+ /* Copy of re_dfa_t's word_char. */
+ re_const_bitset_ptr_t word_char;
+ /* true if REG_ICASE. */
+ unsigned char icase;
+ unsigned char is_utf8;
+ unsigned char map_notascii;
+ unsigned char mbs_allocated;
+ unsigned char offsets_needed;
+ unsigned char newline_anchor;
+ unsigned char word_ops_used;
+ int mb_cur_max;
+};
+typedef struct re_string_t re_string_t;
+
+
+struct re_dfa_t;
+typedef struct re_dfa_t re_dfa_t;
+
+#ifndef _LIBC
+# define internal_function
+#endif
+
+#ifndef NOT_IN_libc
+static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
+ Idx new_buf_len)
+ internal_function;
+# ifdef RE_ENABLE_I18N
+static void build_wcs_buffer (re_string_t *pstr) internal_function;
+static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
+ internal_function;
+# endif /* RE_ENABLE_I18N */
+static void build_upper_buffer (re_string_t *pstr) internal_function;
+static void re_string_translate_buffer (re_string_t *pstr) internal_function;
+static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
+ int eflags)
+ internal_function __attribute__ ((pure));
+#endif
+#define re_string_peek_byte(pstr, offset) \
+ ((pstr)->mbs[(pstr)->cur_idx + offset])
+#define re_string_fetch_byte(pstr) \
+ ((pstr)->mbs[(pstr)->cur_idx++])
+#define re_string_first_byte(pstr, idx) \
+ ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF)
+#define re_string_is_single_byte_char(pstr, idx) \
+ ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \
+ || (pstr)->wcs[(idx) + 1] != WEOF))
+#define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
+#define re_string_cur_idx(pstr) ((pstr)->cur_idx)
+#define re_string_get_buffer(pstr) ((pstr)->mbs)
+#define re_string_length(pstr) ((pstr)->len)
+#define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
+#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
+#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
+
+#if defined _LIBC || HAVE_ALLOCA
# include "palloca.h"
-#endif
-
-#ifndef _LIBC
-# if HAVE_ALLOCA
-/* The OS usually guarantees only one guard page at the bottom of the stack,
- and a page size can be as small as 4096 bytes. So we cannot safely
- allocate anything larger than 4096 bytes. Also care for the possibility
- of a few compiler-allocated temporary stack slots. */
-# define __libc_use_alloca(n) ((n) < 4032)
-# else
-/* alloca is implemented with malloc, so just use malloc. */
-# define __libc_use_alloca(n) 0
-# undef alloca
-# define alloca(n) malloc (n)
-# endif
-#endif
-
-#ifdef _LIBC
-# define MALLOC_0_IS_NONNULL 1
-#elif !defined MALLOC_0_IS_NONNULL
-# define MALLOC_0_IS_NONNULL 0
-#endif
-
-#ifndef MAX
-# define MAX(a,b) ((a) < (b) ? (b) : (a))
-#endif
-#ifndef MIN
-# define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
-#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
-#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
-#define re_free(p) free (p)
-
-struct bin_tree_t
-{
- struct bin_tree_t *parent;
- struct bin_tree_t *left;
- struct bin_tree_t *right;
- struct bin_tree_t *first;
- struct bin_tree_t *next;
-
- re_token_t token;
-
- /* 'node_idx' is the index in dfa->nodes, if 'type' == 0.
- Otherwise 'type' indicate the type of this node. */
- Idx node_idx;
-};
-typedef struct bin_tree_t bin_tree_t;
-
-#define BIN_TREE_STORAGE_SIZE \
- ((1024 - sizeof (void *)) / sizeof (bin_tree_t))
-
-struct bin_tree_storage_t
-{
- struct bin_tree_storage_t *next;
- bin_tree_t data[BIN_TREE_STORAGE_SIZE];
-};
-typedef struct bin_tree_storage_t bin_tree_storage_t;
-
-#define CONTEXT_WORD 1
-#define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
-#define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
-#define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
-
-#define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
-#define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
-#define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
-#define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
-#define IS_ORDINARY_CONTEXT(c) ((c) == 0)
-
-#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
-#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
-#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_')
-#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
-
-#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
- ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
- || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
- || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
- || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
-
-#define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
- ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
- || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
- || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
- || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
-
-struct re_dfastate_t
-{
- re_hashval_t hash;
- re_node_set nodes;
- re_node_set non_eps_nodes;
- re_node_set inveclosure;
- re_node_set *entrance_nodes;
- struct re_dfastate_t **trtable, **word_trtable;
- unsigned int context : 4;
- unsigned int halt : 1;
- /* If this state can accept "multi byte".
- Note that we refer to multibyte characters, and multi character
- collating elements as "multi byte". */
- unsigned int accept_mb : 1;
- /* If this state has backreference node(s). */
- unsigned int has_backref : 1;
- unsigned int has_constraint : 1;
-};
-typedef struct re_dfastate_t re_dfastate_t;
-
-struct re_state_table_entry
-{
- Idx num;
- Idx alloc;
- re_dfastate_t **array;
-};
-
-/* Array type used in re_sub_match_last_t and re_sub_match_top_t. */
-
-typedef struct
-{
- Idx next_idx;
- Idx alloc;
- re_dfastate_t **array;
-} state_array_t;
-
-/* Store information about the node NODE whose type is OP_CLOSE_SUBEXP. */
-
-typedef struct
-{
- Idx node;
- Idx str_idx; /* The position NODE match at. */
- state_array_t path;
-} re_sub_match_last_t;
-
-/* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
- And information about the node, whose type is OP_CLOSE_SUBEXP,
- corresponding to NODE is stored in LASTS. */
-
-typedef struct
-{
- Idx str_idx;
- Idx node;
- state_array_t *path;
- Idx alasts; /* Allocation size of LASTS. */
- Idx nlasts; /* The number of LASTS. */
- re_sub_match_last_t **lasts;
-} re_sub_match_top_t;
-
-struct re_backref_cache_entry
-{
- Idx node;
- Idx str_idx;
- Idx subexp_from;
- Idx subexp_to;
- char more;
- char unused;
- unsigned short int eps_reachable_subexps_map;
-};
-
-typedef struct
-{
- /* The string object corresponding to the input string. */
- re_string_t input;
-#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
- const re_dfa_t *const dfa;
-#else
- const re_dfa_t *dfa;
-#endif
- /* EFLAGS of the argument of regexec. */
- int eflags;
- /* Where the matching ends. */
- Idx match_last;
- Idx last_node;
- /* The state log used by the matcher. */
- re_dfastate_t **state_log;
- Idx state_log_top;
- /* Back reference cache. */
- Idx nbkref_ents;
- Idx abkref_ents;
- struct re_backref_cache_entry *bkref_ents;
- int max_mb_elem_len;
- Idx nsub_tops;
- Idx asub_tops;
- re_sub_match_top_t **sub_tops;
-} re_match_context_t;
-
-typedef struct
-{
- re_dfastate_t **sifted_states;
- re_dfastate_t **limited_states;
- Idx last_node;
- Idx last_str_idx;
- re_node_set limits;
-} re_sift_context_t;
-
-struct re_fail_stack_ent_t
-{
- Idx idx;
- Idx node;
- regmatch_t *regs;
- re_node_set eps_via_nodes;
-};
-
-struct re_fail_stack_t
-{
- Idx num;
- Idx alloc;
- struct re_fail_stack_ent_t *stack;
-};
-
-struct re_dfa_t
-{
- re_token_t *nodes;
- size_t nodes_alloc;
- size_t nodes_len;
- Idx *nexts;
- Idx *org_indices;
- re_node_set *edests;
- re_node_set *eclosures;
- re_node_set *inveclosures;
- struct re_state_table_entry *state_table;
- re_dfastate_t *init_state;
- re_dfastate_t *init_state_word;
- re_dfastate_t *init_state_nl;
- re_dfastate_t *init_state_begbuf;
- bin_tree_t *str_tree;
- bin_tree_storage_t *str_tree_storage;
- re_bitset_ptr_t sb_char;
- int str_tree_storage_idx;
-
- /* number of subexpressions 're_nsub' is in regex_t. */
- re_hashval_t state_hash_mask;
- Idx init_node;
- Idx nbackref; /* The number of backreference in this dfa. */
-
- /* Bitmap expressing which backreference is used. */
- bitset_word_t used_bkref_map;
- bitset_word_t completed_bkref_map;
-
- unsigned int has_plural_match : 1;
- /* If this dfa has "multibyte node", which is a backreference or
- a node which can accept multibyte character or multi character
- collating element. */
- unsigned int has_mb_node : 1;
- unsigned int is_utf8 : 1;
- unsigned int map_notascii : 1;
- unsigned int word_ops_used : 1;
- int mb_cur_max;
- bitset_t word_char;
- reg_syntax_t syntax;
- Idx *subexp_map;
-#ifdef DEBUG
- char* re_str;
-#endif
- lock_define (lock)
-};
-
-#define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
-#define re_node_set_remove(set,id) \
- (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
-#define re_node_set_empty(p) ((p)->nelem = 0)
-#define re_node_set_free(set) re_free ((set)->elems)
-
-
-typedef enum
-{
- SB_CHAR,
- MB_CHAR,
- EQUIV_CLASS,
- COLL_SYM,
- CHAR_CLASS
-} bracket_elem_type;
-
-typedef struct
-{
- bracket_elem_type type;
- union
- {
- unsigned char ch;
- unsigned char *name;
- wchar_t wch;
- } opr;
-} bracket_elem_t;
-
-
-/* Functions for bitset_t operation. */
-
-static void
-bitset_set (bitset_t set, Idx i)
-{
- set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
-}
-
-static void
-bitset_clear (bitset_t set, Idx i)
-{
- set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
-}
-
-static bool
-bitset_contain (const bitset_t set, Idx i)
-{
- return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
-}
-
-static void
-bitset_empty (bitset_t set)
-{
- memset (set, '\0', sizeof (bitset_t));
-}
-
-static void
-bitset_set_all (bitset_t set)
-{
- memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
- if (SBC_MAX % BITSET_WORD_BITS != 0)
- set[BITSET_WORDS - 1] =
- ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
-}
-
-static void
-bitset_copy (bitset_t dest, const bitset_t src)
-{
- memcpy (dest, src, sizeof (bitset_t));
-}
-
-static void __attribute__ ((unused))
-bitset_not (bitset_t set)
-{
- int bitset_i;
- for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
- set[bitset_i] = ~set[bitset_i];
- if (SBC_MAX % BITSET_WORD_BITS != 0)
- set[BITSET_WORDS - 1] =
- ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
- & ~set[BITSET_WORDS - 1]);
-}
-
-static void __attribute__ ((unused))
-bitset_merge (bitset_t dest, const bitset_t src)
-{
- int bitset_i;
- for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
- dest[bitset_i] |= src[bitset_i];
-}
-
-static void __attribute__ ((unused))
-bitset_mask (bitset_t dest, const bitset_t src)
-{
- int bitset_i;
- for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
- dest[bitset_i] &= src[bitset_i];
-}
-
-#ifdef RE_ENABLE_I18N
-/* Functions for re_string. */
-static int
-internal_function __attribute__ ((pure, unused))
-re_string_char_size_at (const re_string_t *pstr, Idx idx)
-{
- int byte_idx;
- if (pstr->mb_cur_max == 1)
- return 1;
- for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx)
- if (pstr->wcs[idx + byte_idx] != WEOF)
- break;
- return byte_idx;
-}
-
-static wint_t
-internal_function __attribute__ ((pure, unused))
-re_string_wchar_at (const re_string_t *pstr, Idx idx)
-{
- if (pstr->mb_cur_max == 1)
- return (wint_t) pstr->mbs[idx];
- return (wint_t) pstr->wcs[idx];
-}
-
-# ifndef NOT_IN_libc
-static int
-internal_function __attribute__ ((pure, unused))
-re_string_elem_size_at (const re_string_t *pstr, Idx idx)
-{
-# ifdef _LIBC
- const unsigned char *p, *extra;
- const int32_t *table, *indirect;
-# include <locale/weight.h>
- uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
-
- if (nrules != 0)
- {
- table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
- extra = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
- indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
- _NL_COLLATE_INDIRECTMB);
- p = pstr->mbs + idx;
- findidx (&p, pstr->len - idx);
- return p - pstr->mbs - idx;
- }
- else
-# endif /* _LIBC */
- return 1;
-}
-# endif
-#endif /* RE_ENABLE_I18N */
-
-#ifndef __GNUC_PREREQ
-# if defined __GNUC__ && defined __GNUC_MINOR__
-# define __GNUC_PREREQ(maj, min) \
- ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
-# else
-# define __GNUC_PREREQ(maj, min) 0
-# endif
-#endif
-
-#if __GNUC_PREREQ (3,4)
-# undef __attribute_warn_unused_result__
-# define __attribute_warn_unused_result__ \
- __attribute__ ((__warn_unused_result__))
-#else
-# define __attribute_warn_unused_result__ /* empty */
-#endif
-
-#endif /* _REGEX_INTERNAL_H */
+#endif
+
+#ifndef _LIBC
+# if HAVE_ALLOCA
+/* The OS usually guarantees only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ allocate anything larger than 4096 bytes. Also care for the possibility
+ of a few compiler-allocated temporary stack slots. */
+# define __libc_use_alloca(n) ((n) < 4032)
+# else
+/* alloca is implemented with malloc, so just use malloc. */
+# define __libc_use_alloca(n) 0
+# undef alloca
+# define alloca(n) malloc (n)
+# endif
+#endif
+
+#ifdef _LIBC
+# define MALLOC_0_IS_NONNULL 1
+#elif !defined MALLOC_0_IS_NONNULL
+# define MALLOC_0_IS_NONNULL 0
+#endif
+
+#ifndef MAX
+# define MAX(a,b) ((a) < (b) ? (b) : (a))
+#endif
+#ifndef MIN
+# define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+
+#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
+#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
+#define re_free(p) free (p)
+
+struct bin_tree_t
+{
+ struct bin_tree_t *parent;
+ struct bin_tree_t *left;
+ struct bin_tree_t *right;
+ struct bin_tree_t *first;
+ struct bin_tree_t *next;
+
+ re_token_t token;
+
+ /* 'node_idx' is the index in dfa->nodes, if 'type' == 0.
+ Otherwise 'type' indicate the type of this node. */
+ Idx node_idx;
+};
+typedef struct bin_tree_t bin_tree_t;
+
+#define BIN_TREE_STORAGE_SIZE \
+ ((1024 - sizeof (void *)) / sizeof (bin_tree_t))
+
+struct bin_tree_storage_t
+{
+ struct bin_tree_storage_t *next;
+ bin_tree_t data[BIN_TREE_STORAGE_SIZE];
+};
+typedef struct bin_tree_storage_t bin_tree_storage_t;
+
+#define CONTEXT_WORD 1
+#define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
+#define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
+#define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
+
+#define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
+#define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
+#define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
+#define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
+#define IS_ORDINARY_CONTEXT(c) ((c) == 0)
+
+#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
+#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
+#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_')
+#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
+
+#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
+ ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
+ || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
+ || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
+ || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
+
+#define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
+ ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
+ || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
+ || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
+ || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
+
+struct re_dfastate_t
+{
+ re_hashval_t hash;
+ re_node_set nodes;
+ re_node_set non_eps_nodes;
+ re_node_set inveclosure;
+ re_node_set *entrance_nodes;
+ struct re_dfastate_t **trtable, **word_trtable;
+ unsigned int context : 4;
+ unsigned int halt : 1;
+ /* If this state can accept "multi byte".
+ Note that we refer to multibyte characters, and multi character
+ collating elements as "multi byte". */
+ unsigned int accept_mb : 1;
+ /* If this state has backreference node(s). */
+ unsigned int has_backref : 1;
+ unsigned int has_constraint : 1;
+};
+typedef struct re_dfastate_t re_dfastate_t;
+
+struct re_state_table_entry
+{
+ Idx num;
+ Idx alloc;
+ re_dfastate_t **array;
+};
+
+/* Array type used in re_sub_match_last_t and re_sub_match_top_t. */
+
+typedef struct
+{
+ Idx next_idx;
+ Idx alloc;
+ re_dfastate_t **array;
+} state_array_t;
+
+/* Store information about the node NODE whose type is OP_CLOSE_SUBEXP. */
+
+typedef struct
+{
+ Idx node;
+ Idx str_idx; /* The position NODE match at. */
+ state_array_t path;
+} re_sub_match_last_t;
+
+/* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
+ And information about the node, whose type is OP_CLOSE_SUBEXP,
+ corresponding to NODE is stored in LASTS. */
+
+typedef struct
+{
+ Idx str_idx;
+ Idx node;
+ state_array_t *path;
+ Idx alasts; /* Allocation size of LASTS. */
+ Idx nlasts; /* The number of LASTS. */
+ re_sub_match_last_t **lasts;
+} re_sub_match_top_t;
+
+struct re_backref_cache_entry
+{
+ Idx node;
+ Idx str_idx;
+ Idx subexp_from;
+ Idx subexp_to;
+ char more;
+ char unused;
+ unsigned short int eps_reachable_subexps_map;
+};
+
+typedef struct
+{
+ /* The string object corresponding to the input string. */
+ re_string_t input;
+#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
+ const re_dfa_t *const dfa;
+#else
+ const re_dfa_t *dfa;
+#endif
+ /* EFLAGS of the argument of regexec. */
+ int eflags;
+ /* Where the matching ends. */
+ Idx match_last;
+ Idx last_node;
+ /* The state log used by the matcher. */
+ re_dfastate_t **state_log;
+ Idx state_log_top;
+ /* Back reference cache. */
+ Idx nbkref_ents;
+ Idx abkref_ents;
+ struct re_backref_cache_entry *bkref_ents;
+ int max_mb_elem_len;
+ Idx nsub_tops;
+ Idx asub_tops;
+ re_sub_match_top_t **sub_tops;
+} re_match_context_t;
+
+typedef struct
+{
+ re_dfastate_t **sifted_states;
+ re_dfastate_t **limited_states;
+ Idx last_node;
+ Idx last_str_idx;
+ re_node_set limits;
+} re_sift_context_t;
+
+struct re_fail_stack_ent_t
+{
+ Idx idx;
+ Idx node;
+ regmatch_t *regs;
+ re_node_set eps_via_nodes;
+};
+
+struct re_fail_stack_t
+{
+ Idx num;
+ Idx alloc;
+ struct re_fail_stack_ent_t *stack;
+};
+
+struct re_dfa_t
+{
+ re_token_t *nodes;
+ size_t nodes_alloc;
+ size_t nodes_len;
+ Idx *nexts;
+ Idx *org_indices;
+ re_node_set *edests;
+ re_node_set *eclosures;
+ re_node_set *inveclosures;
+ struct re_state_table_entry *state_table;
+ re_dfastate_t *init_state;
+ re_dfastate_t *init_state_word;
+ re_dfastate_t *init_state_nl;
+ re_dfastate_t *init_state_begbuf;
+ bin_tree_t *str_tree;
+ bin_tree_storage_t *str_tree_storage;
+ re_bitset_ptr_t sb_char;
+ int str_tree_storage_idx;
+
+ /* number of subexpressions 're_nsub' is in regex_t. */
+ re_hashval_t state_hash_mask;
+ Idx init_node;
+ Idx nbackref; /* The number of backreference in this dfa. */
+
+ /* Bitmap expressing which backreference is used. */
+ bitset_word_t used_bkref_map;
+ bitset_word_t completed_bkref_map;
+
+ unsigned int has_plural_match : 1;
+ /* If this dfa has "multibyte node", which is a backreference or
+ a node which can accept multibyte character or multi character
+ collating element. */
+ unsigned int has_mb_node : 1;
+ unsigned int is_utf8 : 1;
+ unsigned int map_notascii : 1;
+ unsigned int word_ops_used : 1;
+ int mb_cur_max;
+ bitset_t word_char;
+ reg_syntax_t syntax;
+ Idx *subexp_map;
+#ifdef DEBUG
+ char* re_str;
+#endif
+ lock_define (lock)
+};
+
+#define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
+#define re_node_set_remove(set,id) \
+ (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
+#define re_node_set_empty(p) ((p)->nelem = 0)
+#define re_node_set_free(set) re_free ((set)->elems)
+
+
+typedef enum
+{
+ SB_CHAR,
+ MB_CHAR,
+ EQUIV_CLASS,
+ COLL_SYM,
+ CHAR_CLASS
+} bracket_elem_type;
+
+typedef struct
+{
+ bracket_elem_type type;
+ union
+ {
+ unsigned char ch;
+ unsigned char *name;
+ wchar_t wch;
+ } opr;
+} bracket_elem_t;
+
+
+/* Functions for bitset_t operation. */
+
+static void
+bitset_set (bitset_t set, Idx i)
+{
+ set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
+}
+
+static void
+bitset_clear (bitset_t set, Idx i)
+{
+ set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
+}
+
+static bool
+bitset_contain (const bitset_t set, Idx i)
+{
+ return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
+}
+
+static void
+bitset_empty (bitset_t set)
+{
+ memset (set, '\0', sizeof (bitset_t));
+}
+
+static void
+bitset_set_all (bitset_t set)
+{
+ memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
+ if (SBC_MAX % BITSET_WORD_BITS != 0)
+ set[BITSET_WORDS - 1] =
+ ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
+}
+
+static void
+bitset_copy (bitset_t dest, const bitset_t src)
+{
+ memcpy (dest, src, sizeof (bitset_t));
+}
+
+static void __attribute__ ((unused))
+bitset_not (bitset_t set)
+{
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
+ set[bitset_i] = ~set[bitset_i];
+ if (SBC_MAX % BITSET_WORD_BITS != 0)
+ set[BITSET_WORDS - 1] =
+ ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
+ & ~set[BITSET_WORDS - 1]);
+}
+
+static void __attribute__ ((unused))
+bitset_merge (bitset_t dest, const bitset_t src)
+{
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
+ dest[bitset_i] |= src[bitset_i];
+}
+
+static void __attribute__ ((unused))
+bitset_mask (bitset_t dest, const bitset_t src)
+{
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
+ dest[bitset_i] &= src[bitset_i];
+}
+
+#ifdef RE_ENABLE_I18N
+/* Functions for re_string. */
+static int
+internal_function __attribute__ ((pure, unused))
+re_string_char_size_at (const re_string_t *pstr, Idx idx)
+{
+ int byte_idx;
+ if (pstr->mb_cur_max == 1)
+ return 1;
+ for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx)
+ if (pstr->wcs[idx + byte_idx] != WEOF)
+ break;
+ return byte_idx;
+}
+
+static wint_t
+internal_function __attribute__ ((pure, unused))
+re_string_wchar_at (const re_string_t *pstr, Idx idx)
+{
+ if (pstr->mb_cur_max == 1)
+ return (wint_t) pstr->mbs[idx];
+ return (wint_t) pstr->wcs[idx];
+}
+
+# ifndef NOT_IN_libc
+static int
+internal_function __attribute__ ((pure, unused))
+re_string_elem_size_at (const re_string_t *pstr, Idx idx)
+{
+# ifdef _LIBC
+ const unsigned char *p, *extra;
+ const int32_t *table, *indirect;
+# include <locale/weight.h>
+ uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+
+ if (nrules != 0)
+ {
+ table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
+ indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_INDIRECTMB);
+ p = pstr->mbs + idx;
+ findidx (&p, pstr->len - idx);
+ return p - pstr->mbs - idx;
+ }
+ else
+# endif /* _LIBC */
+ return 1;
+}
+# endif
+#endif /* RE_ENABLE_I18N */
+
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+# define __GNUC_PREREQ(maj, min) \
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+# define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
+#if __GNUC_PREREQ (3,4)
+# undef __attribute_warn_unused_result__
+# define __attribute_warn_unused_result__ \
+ __attribute__ ((__warn_unused_result__))
+#else
+# define __attribute_warn_unused_result__ /* empty */
+#endif
+
+#endif /* _REGEX_INTERNAL_H */
diff --git a/contrib/tools/bison/gnulib/src/regexec.c b/contrib/tools/bison/gnulib/src/regexec.c
index d29d442baf..ab98a4835f 100644
--- a/contrib/tools/bison/gnulib/src/regexec.c
+++ b/contrib/tools/bison/gnulib/src/regexec.c
@@ -1,4410 +1,4410 @@
-/* Extended regular expression matching and search library.
- Copyright (C) 2002-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
- Idx n) internal_function;
-static void match_ctx_clean (re_match_context_t *mctx) internal_function;
-static void match_ctx_free (re_match_context_t *cache) internal_function;
-static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node,
- Idx str_idx, Idx from, Idx to)
- internal_function;
-static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
- internal_function;
-static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node,
- Idx str_idx) internal_function;
-static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop,
- Idx node, Idx str_idx)
- internal_function;
-static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
- re_dfastate_t **limited_sts, Idx last_node,
- Idx last_str_idx)
- internal_function;
-static reg_errcode_t re_search_internal (const regex_t *preg,
- const char *string, Idx length,
- Idx start, Idx last_start, Idx stop,
- size_t nmatch, regmatch_t pmatch[],
- int eflags) internal_function;
-static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp,
- const char *string1, Idx length1,
- const char *string2, Idx length2,
- Idx start, regoff_t range,
- struct re_registers *regs,
- Idx stop, bool ret_len) internal_function;
-static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
- const char *string, Idx length, Idx start,
- regoff_t range, Idx stop,
- struct re_registers *regs,
- bool ret_len) internal_function;
-static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
- Idx nregs, int regs_allocated) internal_function;
-static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
- internal_function;
-static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
- Idx *p_match_first) internal_function;
-static Idx check_halt_state_context (const re_match_context_t *mctx,
- const re_dfastate_t *state, Idx idx)
- internal_function;
-static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
- regmatch_t *prev_idx_match, Idx cur_node,
- Idx cur_idx, Idx nmatch) internal_function;
-static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
- Idx str_idx, Idx dest_node, Idx nregs,
- regmatch_t *regs,
- re_node_set *eps_via_nodes)
- internal_function;
-static reg_errcode_t set_regs (const regex_t *preg,
- const re_match_context_t *mctx,
- size_t nmatch, regmatch_t *pmatch,
- bool fl_backtrack) internal_function;
-static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs)
- internal_function;
-
-#ifdef RE_ENABLE_I18N
-static int sift_states_iter_mb (const re_match_context_t *mctx,
- re_sift_context_t *sctx,
- Idx node_idx, Idx str_idx, Idx max_str_idx)
- internal_function;
-#endif /* RE_ENABLE_I18N */
-static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
- re_sift_context_t *sctx)
- internal_function;
-static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
- re_sift_context_t *sctx, Idx str_idx,
- re_node_set *cur_dest)
- internal_function;
-static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
- re_sift_context_t *sctx,
- Idx str_idx,
- re_node_set *dest_nodes)
- internal_function;
-static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
- re_node_set *dest_nodes,
- const re_node_set *candidates)
- internal_function;
-static bool check_dst_limits (const re_match_context_t *mctx,
- const re_node_set *limits,
- Idx dst_node, Idx dst_idx, Idx src_node,
- Idx src_idx) internal_function;
-static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
- int boundaries, Idx subexp_idx,
- Idx from_node, Idx bkref_idx)
- internal_function;
-static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
- Idx limit, Idx subexp_idx,
- Idx node, Idx str_idx,
- Idx bkref_idx) internal_function;
-static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
- re_node_set *dest_nodes,
- const re_node_set *candidates,
- re_node_set *limits,
- struct re_backref_cache_entry *bkref_ents,
- Idx str_idx) internal_function;
-static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
- re_sift_context_t *sctx,
- Idx str_idx, const re_node_set *candidates)
- internal_function;
-static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
- re_dfastate_t **dst,
- re_dfastate_t **src, Idx num)
- internal_function;
-static re_dfastate_t *find_recover_state (reg_errcode_t *err,
- re_match_context_t *mctx) internal_function;
-static re_dfastate_t *transit_state (reg_errcode_t *err,
- re_match_context_t *mctx,
- re_dfastate_t *state) internal_function;
-static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
- re_match_context_t *mctx,
- re_dfastate_t *next_state)
- internal_function;
-static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
- re_node_set *cur_nodes,
- Idx str_idx) internal_function;
-#if 0
-static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
- re_match_context_t *mctx,
- re_dfastate_t *pstate)
- internal_function;
-#endif
-#ifdef RE_ENABLE_I18N
-static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
- re_dfastate_t *pstate)
- internal_function;
-#endif /* RE_ENABLE_I18N */
-static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
- const re_node_set *nodes)
- internal_function;
-static reg_errcode_t get_subexp (re_match_context_t *mctx,
- Idx bkref_node, Idx bkref_str_idx)
- internal_function;
-static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
- const re_sub_match_top_t *sub_top,
- re_sub_match_last_t *sub_last,
- Idx bkref_node, Idx bkref_str)
- internal_function;
-static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
- Idx subexp_idx, int type) internal_function;
-static reg_errcode_t check_arrival (re_match_context_t *mctx,
- state_array_t *path, Idx top_node,
- Idx top_str, Idx last_node, Idx last_str,
- int type) internal_function;
-static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
- Idx str_idx,
- re_node_set *cur_nodes,
- re_node_set *next_nodes)
- internal_function;
-static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
- re_node_set *cur_nodes,
- Idx ex_subexp, int type)
- internal_function;
-static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
- re_node_set *dst_nodes,
- Idx target, Idx ex_subexp,
- int type) internal_function;
-static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
- re_node_set *cur_nodes, Idx cur_str,
- Idx subexp_num, int type)
- internal_function;
-static bool build_trtable (const re_dfa_t *dfa,
- re_dfastate_t *state) internal_function;
-#ifdef RE_ENABLE_I18N
-static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
- const re_string_t *input, Idx idx)
- internal_function;
-# ifdef _LIBC
-static unsigned int find_collation_sequence_value (const unsigned char *mbs,
- size_t name_len)
- internal_function;
-# endif /* _LIBC */
-#endif /* RE_ENABLE_I18N */
-static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
- const re_dfastate_t *state,
- re_node_set *states_node,
- bitset_t *states_ch) internal_function;
-static bool check_node_accept (const re_match_context_t *mctx,
- const re_token_t *node, Idx idx)
- internal_function;
-static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
- internal_function;
-
-/* Entry point for POSIX code. */
-
-/* regexec searches for a given pattern, specified by PREG, in the
- string STRING.
-
- If NMATCH is zero or REG_NOSUB was set in the cflags argument to
- 'regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
- least NMATCH elements, and we set them to the offsets of the
- corresponding matched substrings.
-
- EFLAGS specifies "execution flags" which affect matching: if
- REG_NOTBOL is set, then ^ does not match at the beginning of the
- string; if REG_NOTEOL is set, then $ does not match at the end.
-
- We return 0 if we find a match and REG_NOMATCH if not. */
-
-int
-regexec (preg, string, nmatch, pmatch, eflags)
- const regex_t *_Restrict_ preg;
- const char *_Restrict_ string;
- size_t nmatch;
- regmatch_t pmatch[_Restrict_arr_];
- int eflags;
-{
- reg_errcode_t err;
- Idx start, length;
- re_dfa_t *dfa = preg->buffer;
-
- if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
- return REG_BADPAT;
-
- if (eflags & REG_STARTEND)
- {
- start = pmatch[0].rm_so;
- length = pmatch[0].rm_eo;
- }
- else
- {
- start = 0;
- length = strlen (string);
- }
-
- lock_lock (dfa->lock);
- if (preg->no_sub)
- err = re_search_internal (preg, string, length, start, length,
- length, 0, NULL, eflags);
- else
- err = re_search_internal (preg, string, length, start, length,
- length, nmatch, pmatch, eflags);
- lock_unlock (dfa->lock);
- return err != REG_NOERROR;
-}
-
-#ifdef _LIBC
-# include <shlib-compat.h>
-versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4);
-
-# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
-__typeof__ (__regexec) __compat_regexec;
-
-int
-attribute_compat_text_section
-__compat_regexec (const regex_t *_Restrict_ preg,
- const char *_Restrict_ string, size_t nmatch,
- regmatch_t pmatch[], int eflags)
-{
- return regexec (preg, string, nmatch, pmatch,
- eflags & (REG_NOTBOL | REG_NOTEOL));
-}
-compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
-# endif
-#endif
-
-/* Entry points for GNU code. */
-
-/* re_match, re_search, re_match_2, re_search_2
-
- The former two functions operate on STRING with length LENGTH,
- while the later two operate on concatenation of STRING1 and STRING2
- with lengths LENGTH1 and LENGTH2, respectively.
-
- re_match() matches the compiled pattern in BUFP against the string,
- starting at index START.
-
- re_search() first tries matching at index START, then it tries to match
- starting from index START + 1, and so on. The last start position tried
- is START + RANGE. (Thus RANGE = 0 forces re_search to operate the same
- way as re_match().)
-
- The parameter STOP of re_{match,search}_2 specifies that no match exceeding
- the first STOP characters of the concatenation of the strings should be
- concerned.
-
- If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match
- and all groups is stored in REGS. (For the "_2" variants, the offsets are
- computed relative to the concatenation, not relative to the individual
- strings.)
-
- On success, re_match* functions return the length of the match, re_search*
- return the position of the start of the match. Return value -1 means no
- match was found and -2 indicates an internal error. */
-
-regoff_t
-re_match (bufp, string, length, start, regs)
- struct re_pattern_buffer *bufp;
- const char *string;
- Idx length, start;
- struct re_registers *regs;
-{
- return re_search_stub (bufp, string, length, start, 0, length, regs, true);
-}
-#ifdef _LIBC
-weak_alias (__re_match, re_match)
-#endif
-
-regoff_t
-re_search (bufp, string, length, start, range, regs)
- struct re_pattern_buffer *bufp;
- const char *string;
- Idx length, start;
- regoff_t range;
- struct re_registers *regs;
-{
- return re_search_stub (bufp, string, length, start, range, length, regs,
- false);
-}
-#ifdef _LIBC
-weak_alias (__re_search, re_search)
-#endif
-
-regoff_t
-re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop)
- struct re_pattern_buffer *bufp;
- const char *string1, *string2;
- Idx length1, length2, start, stop;
- struct re_registers *regs;
-{
- return re_search_2_stub (bufp, string1, length1, string2, length2,
- start, 0, regs, stop, true);
-}
-#ifdef _LIBC
-weak_alias (__re_match_2, re_match_2)
-#endif
-
-regoff_t
-re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop)
- struct re_pattern_buffer *bufp;
- const char *string1, *string2;
- Idx length1, length2, start, stop;
- regoff_t range;
- struct re_registers *regs;
-{
- return re_search_2_stub (bufp, string1, length1, string2, length2,
- start, range, regs, stop, false);
-}
-#ifdef _LIBC
-weak_alias (__re_search_2, re_search_2)
-#endif
-
-static regoff_t
-re_search_2_stub (struct re_pattern_buffer *bufp,
- const char *string1, Idx length1,
- const char *string2, Idx length2,
- Idx start, regoff_t range, struct re_registers *regs,
- Idx stop, bool ret_len)
-{
- const char *str;
- regoff_t rval;
- Idx len = length1 + length2;
- char *s = NULL;
-
- if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0))
- return -2;
-
- /* Concatenate the strings. */
- if (length2 > 0)
- if (length1 > 0)
- {
- s = re_malloc (char, len);
-
- if (BE (s == NULL, 0))
- return -2;
-#ifdef _LIBC
- memcpy (__mempcpy (s, string1, length1), string2, length2);
-#else
- memcpy (s, string1, length1);
- memcpy (s + length1, string2, length2);
-#endif
- str = s;
- }
- else
- str = string2;
- else
- str = string1;
-
- rval = re_search_stub (bufp, str, len, start, range, stop, regs,
- ret_len);
- re_free (s);
- return rval;
-}
-
-/* The parameters have the same meaning as those of re_search.
- Additional parameters:
- If RET_LEN is true the length of the match is returned (re_match style);
- otherwise the position of the match is returned. */
-
-static regoff_t
-re_search_stub (struct re_pattern_buffer *bufp,
- const char *string, Idx length,
- Idx start, regoff_t range, Idx stop, struct re_registers *regs,
- bool ret_len)
-{
- reg_errcode_t result;
- regmatch_t *pmatch;
- Idx nregs;
- regoff_t rval;
- int eflags = 0;
- re_dfa_t *dfa = bufp->buffer;
- Idx last_start = start + range;
-
- /* Check for out-of-range. */
- if (BE (start < 0 || start > length, 0))
- return -1;
- if (BE (length < last_start || (0 <= range && last_start < start), 0))
- last_start = length;
- else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0))
- last_start = 0;
-
- lock_lock (dfa->lock);
-
- eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
- eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
-
- /* Compile fastmap if we haven't yet. */
- if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
- re_compile_fastmap (bufp);
-
- if (BE (bufp->no_sub, 0))
- regs = NULL;
-
- /* We need at least 1 register. */
- if (regs == NULL)
- nregs = 1;
- else if (BE (bufp->regs_allocated == REGS_FIXED
- && regs->num_regs <= bufp->re_nsub, 0))
- {
- nregs = regs->num_regs;
- if (BE (nregs < 1, 0))
- {
- /* Nothing can be copied to regs. */
- regs = NULL;
- nregs = 1;
- }
- }
- else
- nregs = bufp->re_nsub + 1;
- pmatch = re_malloc (regmatch_t, nregs);
- if (BE (pmatch == NULL, 0))
- {
- rval = -2;
- goto out;
- }
-
- result = re_search_internal (bufp, string, length, start, last_start, stop,
- nregs, pmatch, eflags);
-
- rval = 0;
-
- /* I hope we needn't fill their regs with -1's when no match was found. */
- if (result != REG_NOERROR)
- rval = result == REG_NOMATCH ? -1 : -2;
- else if (regs != NULL)
- {
- /* If caller wants register contents data back, copy them. */
- bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
- bufp->regs_allocated);
- if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0))
- rval = -2;
- }
-
- if (BE (rval == 0, 1))
- {
- if (ret_len)
- {
- assert (pmatch[0].rm_so == start);
- rval = pmatch[0].rm_eo - start;
- }
- else
- rval = pmatch[0].rm_so;
- }
- re_free (pmatch);
- out:
- lock_unlock (dfa->lock);
- return rval;
-}
-
-static unsigned
-re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
- int regs_allocated)
-{
- int rval = REGS_REALLOCATE;
- Idx i;
- Idx need_regs = nregs + 1;
- /* We need one extra element beyond 'num_regs' for the '-1' marker GNU code
- uses. */
-
- /* Have the register data arrays been allocated? */
- if (regs_allocated == REGS_UNALLOCATED)
- { /* No. So allocate them with malloc. */
- regs->start = re_malloc (regoff_t, need_regs);
- if (BE (regs->start == NULL, 0))
- return REGS_UNALLOCATED;
- regs->end = re_malloc (regoff_t, need_regs);
- if (BE (regs->end == NULL, 0))
- {
- re_free (regs->start);
- return REGS_UNALLOCATED;
- }
- regs->num_regs = need_regs;
- }
- else if (regs_allocated == REGS_REALLOCATE)
- { /* Yes. If we need more elements than were already
- allocated, reallocate them. If we need fewer, just
- leave it alone. */
- if (BE (need_regs > regs->num_regs, 0))
- {
- regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
- regoff_t *new_end;
- if (BE (new_start == NULL, 0))
- return REGS_UNALLOCATED;
- new_end = re_realloc (regs->end, regoff_t, need_regs);
- if (BE (new_end == NULL, 0))
- {
- re_free (new_start);
- return REGS_UNALLOCATED;
- }
- regs->start = new_start;
- regs->end = new_end;
- regs->num_regs = need_regs;
- }
- }
- else
- {
- assert (regs_allocated == REGS_FIXED);
- /* This function may not be called with REGS_FIXED and nregs too big. */
- assert (regs->num_regs >= nregs);
- rval = REGS_FIXED;
- }
-
- /* Copy the regs. */
- for (i = 0; i < nregs; ++i)
- {
- regs->start[i] = pmatch[i].rm_so;
- regs->end[i] = pmatch[i].rm_eo;
- }
- for ( ; i < regs->num_regs; ++i)
- regs->start[i] = regs->end[i] = -1;
-
- return rval;
-}
-
-/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
- ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
- this memory for recording register information. STARTS and ENDS
- must be allocated using the malloc library routine, and must each
- be at least NUM_REGS * sizeof (regoff_t) bytes long.
-
- If NUM_REGS == 0, then subsequent matches should allocate their own
- register data.
-
- Unless this function is called, the first search or match using
- PATTERN_BUFFER will allocate its own register data, without
- freeing the old data. */
-
-void
-re_set_registers (bufp, regs, num_regs, starts, ends)
- struct re_pattern_buffer *bufp;
- struct re_registers *regs;
- __re_size_t num_regs;
- regoff_t *starts, *ends;
-{
- if (num_regs)
- {
- bufp->regs_allocated = REGS_REALLOCATE;
- regs->num_regs = num_regs;
- regs->start = starts;
- regs->end = ends;
- }
- else
- {
- bufp->regs_allocated = REGS_UNALLOCATED;
- regs->num_regs = 0;
- regs->start = regs->end = NULL;
- }
-}
-#ifdef _LIBC
-weak_alias (__re_set_registers, re_set_registers)
-#endif
-
-/* Entry points compatible with 4.2 BSD regex library. We don't define
- them unless specifically requested. */
-
-#if defined _REGEX_RE_COMP || defined _LIBC
-int
-# ifdef _LIBC
-weak_function
-# endif
-re_exec (s)
- const char *s;
-{
- return 0 == regexec (&re_comp_buf, s, 0, NULL, 0);
-}
-#endif /* _REGEX_RE_COMP */
-
-/* Internal entry point. */
-
-/* Searches for a compiled pattern PREG in the string STRING, whose
- length is LENGTH. NMATCH, PMATCH, and EFLAGS have the same
- meaning as with regexec. LAST_START is START + RANGE, where
- START and RANGE have the same meaning as with re_search.
- Return REG_NOERROR if we find a match, and REG_NOMATCH if not,
- otherwise return the error code.
- Note: We assume front end functions already check ranges.
- (0 <= LAST_START && LAST_START <= LENGTH) */
-
-static reg_errcode_t
-__attribute_warn_unused_result__
-re_search_internal (const regex_t *preg,
- const char *string, Idx length,
- Idx start, Idx last_start, Idx stop,
- size_t nmatch, regmatch_t pmatch[],
- int eflags)
-{
- reg_errcode_t err;
- const re_dfa_t *dfa = preg->buffer;
- Idx left_lim, right_lim;
- int incr;
- bool fl_longest_match;
- int match_kind;
- Idx match_first;
- Idx match_last = REG_MISSING;
- Idx extra_nmatch;
- bool sb;
- int ch;
-#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
- re_match_context_t mctx = { .dfa = dfa };
-#else
- re_match_context_t mctx;
-#endif
- char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
- && start != last_start && !preg->can_be_null)
- ? preg->fastmap : NULL);
- RE_TRANSLATE_TYPE t = preg->translate;
-
-#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
- memset (&mctx, '\0', sizeof (re_match_context_t));
- mctx.dfa = dfa;
-#endif
-
- extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
- nmatch -= extra_nmatch;
-
- /* Check if the DFA haven't been compiled. */
- if (BE (preg->used == 0 || dfa->init_state == NULL
- || dfa->init_state_word == NULL || dfa->init_state_nl == NULL
- || dfa->init_state_begbuf == NULL, 0))
- return REG_NOMATCH;
-
-#ifdef DEBUG
- /* We assume front-end functions already check them. */
- assert (0 <= last_start && last_start <= length);
-#endif
-
- /* If initial states with non-begbuf contexts have no elements,
- the regex must be anchored. If preg->newline_anchor is set,
- we'll never use init_state_nl, so do not check it. */
- if (dfa->init_state->nodes.nelem == 0
- && dfa->init_state_word->nodes.nelem == 0
- && (dfa->init_state_nl->nodes.nelem == 0
- || !preg->newline_anchor))
- {
- if (start != 0 && last_start != 0)
- return REG_NOMATCH;
- start = last_start = 0;
- }
-
- /* We must check the longest matching, if nmatch > 0. */
- fl_longest_match = (nmatch != 0 || dfa->nbackref);
-
- err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
- preg->translate, (preg->syntax & RE_ICASE) != 0,
- dfa);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- mctx.input.stop = stop;
- mctx.input.raw_stop = stop;
- mctx.input.newline_anchor = preg->newline_anchor;
-
- err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
-
- /* We will log all the DFA states through which the dfa pass,
- if nmatch > 1, or this dfa has "multibyte node", which is a
- back-reference or a node which can accept multibyte character or
- multi character collating element. */
- if (nmatch > 1 || dfa->has_mb_node)
- {
- /* Avoid overflow. */
- if (BE ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
- <= mctx.input.bufs_len), 0))
- {
- err = REG_ESPACE;
- goto free_return;
- }
-
- mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
- if (BE (mctx.state_log == NULL, 0))
- {
- err = REG_ESPACE;
- goto free_return;
- }
- }
- else
- mctx.state_log = NULL;
-
- match_first = start;
- mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
- : CONTEXT_NEWLINE | CONTEXT_BEGBUF;
-
- /* Check incrementally whether the input string matches. */
- incr = (last_start < start) ? -1 : 1;
- left_lim = (last_start < start) ? last_start : start;
- right_lim = (last_start < start) ? start : last_start;
- sb = dfa->mb_cur_max == 1;
- match_kind =
- (fastmap
- ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0)
- | (start <= last_start ? 2 : 0)
- | (t != NULL ? 1 : 0))
- : 8);
-
- for (;; match_first += incr)
- {
- err = REG_NOMATCH;
- if (match_first < left_lim || right_lim < match_first)
- goto free_return;
-
- /* Advance as rapidly as possible through the string, until we
- find a plausible place to start matching. This may be done
- with varying efficiency, so there are various possibilities:
- only the most common of them are specialized, in order to
- save on code size. We use a switch statement for speed. */
- switch (match_kind)
- {
- case 8:
- /* No fastmap. */
- break;
-
- case 7:
- /* Fastmap with single-byte translation, match forward. */
- while (BE (match_first < right_lim, 1)
- && !fastmap[t[(unsigned char) string[match_first]]])
- ++match_first;
- goto forward_match_found_start_or_reached_end;
-
- case 6:
- /* Fastmap without translation, match forward. */
- while (BE (match_first < right_lim, 1)
- && !fastmap[(unsigned char) string[match_first]])
- ++match_first;
-
- forward_match_found_start_or_reached_end:
- if (BE (match_first == right_lim, 0))
- {
- ch = match_first >= length
- ? 0 : (unsigned char) string[match_first];
- if (!fastmap[t ? t[ch] : ch])
- goto free_return;
- }
- break;
-
- case 4:
- case 5:
- /* Fastmap without multi-byte translation, match backwards. */
- while (match_first >= left_lim)
- {
- ch = match_first >= length
- ? 0 : (unsigned char) string[match_first];
- if (fastmap[t ? t[ch] : ch])
- break;
- --match_first;
- }
- if (match_first < left_lim)
- goto free_return;
- break;
-
- default:
- /* In this case, we can't determine easily the current byte,
- since it might be a component byte of a multibyte
- character. Then we use the constructed buffer instead. */
- for (;;)
- {
- /* If MATCH_FIRST is out of the valid range, reconstruct the
- buffers. */
- __re_size_t offset = match_first - mctx.input.raw_mbs_idx;
- if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0))
- {
- err = re_string_reconstruct (&mctx.input, match_first,
- eflags);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
-
- offset = match_first - mctx.input.raw_mbs_idx;
- }
- /* If MATCH_FIRST is out of the buffer, leave it as '\0'.
- Note that MATCH_FIRST must not be smaller than 0. */
- ch = (match_first >= length
- ? 0 : re_string_byte_at (&mctx.input, offset));
- if (fastmap[ch])
- break;
- match_first += incr;
- if (match_first < left_lim || match_first > right_lim)
- {
- err = REG_NOMATCH;
- goto free_return;
- }
- }
- break;
- }
-
- /* Reconstruct the buffers so that the matcher can assume that
- the matching starts from the beginning of the buffer. */
- err = re_string_reconstruct (&mctx.input, match_first, eflags);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
-
-#ifdef RE_ENABLE_I18N
- /* Don't consider this char as a possible match start if it part,
- yet isn't the head, of a multibyte character. */
- if (!sb && !re_string_first_byte (&mctx.input, 0))
- continue;
-#endif
-
- /* It seems to be appropriate one, then use the matcher. */
- /* We assume that the matching starts from 0. */
- mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0;
- match_last = check_matching (&mctx, fl_longest_match,
- start <= last_start ? &match_first : NULL);
- if (match_last != REG_MISSING)
- {
- if (BE (match_last == REG_ERROR, 0))
- {
- err = REG_ESPACE;
- goto free_return;
- }
- else
- {
- mctx.match_last = match_last;
- if ((!preg->no_sub && nmatch > 1) || dfa->nbackref)
- {
- re_dfastate_t *pstate = mctx.state_log[match_last];
- mctx.last_node = check_halt_state_context (&mctx, pstate,
- match_last);
- }
- if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match)
- || dfa->nbackref)
- {
- err = prune_impossible_nodes (&mctx);
- if (err == REG_NOERROR)
- break;
- if (BE (err != REG_NOMATCH, 0))
- goto free_return;
- match_last = REG_MISSING;
- }
- else
- break; /* We found a match. */
- }
- }
-
- match_ctx_clean (&mctx);
- }
-
-#ifdef DEBUG
- assert (match_last != REG_MISSING);
- assert (err == REG_NOERROR);
-#endif
-
- /* Set pmatch[] if we need. */
- if (nmatch > 0)
- {
- Idx reg_idx;
-
- /* Initialize registers. */
- for (reg_idx = 1; reg_idx < nmatch; ++reg_idx)
- pmatch[reg_idx].rm_so = pmatch[reg_idx].rm_eo = -1;
-
- /* Set the points where matching start/end. */
- pmatch[0].rm_so = 0;
- pmatch[0].rm_eo = mctx.match_last;
- /* FIXME: This function should fail if mctx.match_last exceeds
- the maximum possible regoff_t value. We need a new error
- code REG_OVERFLOW. */
-
- if (!preg->no_sub && nmatch > 1)
- {
- err = set_regs (preg, &mctx, nmatch, pmatch,
- dfa->has_plural_match && dfa->nbackref > 0);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- }
-
- /* At last, add the offset to each register, since we slid
- the buffers so that we could assume that the matching starts
- from 0. */
- for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
- if (pmatch[reg_idx].rm_so != -1)
- {
-#ifdef RE_ENABLE_I18N
- if (BE (mctx.input.offsets_needed != 0, 0))
- {
- pmatch[reg_idx].rm_so =
- (pmatch[reg_idx].rm_so == mctx.input.valid_len
- ? mctx.input.valid_raw_len
- : mctx.input.offsets[pmatch[reg_idx].rm_so]);
- pmatch[reg_idx].rm_eo =
- (pmatch[reg_idx].rm_eo == mctx.input.valid_len
- ? mctx.input.valid_raw_len
- : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
- }
-#else
- assert (mctx.input.offsets_needed == 0);
-#endif
- pmatch[reg_idx].rm_so += match_first;
- pmatch[reg_idx].rm_eo += match_first;
- }
- for (reg_idx = 0; reg_idx < extra_nmatch; ++reg_idx)
- {
- pmatch[nmatch + reg_idx].rm_so = -1;
- pmatch[nmatch + reg_idx].rm_eo = -1;
- }
-
- if (dfa->subexp_map)
- for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++)
- if (dfa->subexp_map[reg_idx] != reg_idx)
- {
- pmatch[reg_idx + 1].rm_so
- = pmatch[dfa->subexp_map[reg_idx] + 1].rm_so;
- pmatch[reg_idx + 1].rm_eo
- = pmatch[dfa->subexp_map[reg_idx] + 1].rm_eo;
- }
- }
-
- free_return:
- re_free (mctx.state_log);
- if (dfa->nbackref)
- match_ctx_free (&mctx);
- re_string_destruct (&mctx.input);
- return err;
-}
-
-static reg_errcode_t
-__attribute_warn_unused_result__
-prune_impossible_nodes (re_match_context_t *mctx)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- Idx halt_node, match_last;
- reg_errcode_t ret;
- re_dfastate_t **sifted_states;
- re_dfastate_t **lim_states = NULL;
- re_sift_context_t sctx;
-#ifdef DEBUG
- assert (mctx->state_log != NULL);
-#endif
- match_last = mctx->match_last;
- halt_node = mctx->last_node;
-
- /* Avoid overflow. */
- if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) <= match_last, 0))
- return REG_ESPACE;
-
- sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
- if (BE (sifted_states == NULL, 0))
- {
- ret = REG_ESPACE;
- goto free_return;
- }
- if (dfa->nbackref)
- {
- lim_states = re_malloc (re_dfastate_t *, match_last + 1);
- if (BE (lim_states == NULL, 0))
- {
- ret = REG_ESPACE;
- goto free_return;
- }
- while (1)
- {
- memset (lim_states, '\0',
- sizeof (re_dfastate_t *) * (match_last + 1));
- sift_ctx_init (&sctx, sifted_states, lim_states, halt_node,
- match_last);
- ret = sift_states_backward (mctx, &sctx);
- re_node_set_free (&sctx.limits);
- if (BE (ret != REG_NOERROR, 0))
- goto free_return;
- if (sifted_states[0] != NULL || lim_states[0] != NULL)
- break;
- do
- {
- --match_last;
- if (! REG_VALID_INDEX (match_last))
- {
- ret = REG_NOMATCH;
- goto free_return;
- }
- } while (mctx->state_log[match_last] == NULL
- || !mctx->state_log[match_last]->halt);
- halt_node = check_halt_state_context (mctx,
- mctx->state_log[match_last],
- match_last);
- }
- ret = merge_state_array (dfa, sifted_states, lim_states,
- match_last + 1);
- re_free (lim_states);
- lim_states = NULL;
- if (BE (ret != REG_NOERROR, 0))
- goto free_return;
- }
- else
- {
- sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last);
- ret = sift_states_backward (mctx, &sctx);
- re_node_set_free (&sctx.limits);
- if (BE (ret != REG_NOERROR, 0))
- goto free_return;
- if (sifted_states[0] == NULL)
- {
- ret = REG_NOMATCH;
- goto free_return;
- }
- }
- re_free (mctx->state_log);
- mctx->state_log = sifted_states;
- sifted_states = NULL;
- mctx->last_node = halt_node;
- mctx->match_last = match_last;
- ret = REG_NOERROR;
- free_return:
- re_free (sifted_states);
- re_free (lim_states);
- return ret;
-}
-
-/* Acquire an initial state and return it.
- We must select appropriate initial state depending on the context,
- since initial states may have constraints like "\<", "^", etc.. */
-
-static inline re_dfastate_t *
-__attribute__ ((always_inline)) internal_function
-acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
- Idx idx)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- if (dfa->init_state->has_constraint)
- {
- unsigned int context;
- context = re_string_context_at (&mctx->input, idx - 1, mctx->eflags);
- if (IS_WORD_CONTEXT (context))
- return dfa->init_state_word;
- else if (IS_ORDINARY_CONTEXT (context))
- return dfa->init_state;
- else if (IS_BEGBUF_CONTEXT (context) && IS_NEWLINE_CONTEXT (context))
- return dfa->init_state_begbuf;
- else if (IS_NEWLINE_CONTEXT (context))
- return dfa->init_state_nl;
- else if (IS_BEGBUF_CONTEXT (context))
- {
- /* It is relatively rare case, then calculate on demand. */
- return re_acquire_state_context (err, dfa,
- dfa->init_state->entrance_nodes,
- context);
- }
- else
- /* Must not happen? */
- return dfa->init_state;
- }
- else
- return dfa->init_state;
-}
-
-/* Check whether the regular expression match input string INPUT or not,
- and return the index where the matching end. Return REG_MISSING if
- there is no match, and return REG_ERROR in case of an error.
- FL_LONGEST_MATCH means we want the POSIX longest matching.
- If P_MATCH_FIRST is not NULL, and the match fails, it is set to the
- next place where we may want to try matching.
- Note that the matcher assumes that the matching starts from the current
- index of the buffer. */
-
-static Idx
-internal_function __attribute_warn_unused_result__
-check_matching (re_match_context_t *mctx, bool fl_longest_match,
- Idx *p_match_first)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err;
- Idx match = 0;
- Idx match_last = REG_MISSING;
- Idx cur_str_idx = re_string_cur_idx (&mctx->input);
- re_dfastate_t *cur_state;
- bool at_init_state = p_match_first != NULL;
- Idx next_start_idx = cur_str_idx;
-
- err = REG_NOERROR;
- cur_state = acquire_init_state_context (&err, mctx, cur_str_idx);
- /* An initial state must not be NULL (invalid). */
- if (BE (cur_state == NULL, 0))
- {
- assert (err == REG_ESPACE);
- return REG_ERROR;
- }
-
- if (mctx->state_log != NULL)
- {
- mctx->state_log[cur_str_idx] = cur_state;
-
- /* Check OP_OPEN_SUBEXP in the initial state in case that we use them
- later. E.g. Processing back references. */
- if (BE (dfa->nbackref, 0))
- {
- at_init_state = false;
- err = check_subexp_matching_top (mctx, &cur_state->nodes, 0);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- if (cur_state->has_backref)
- {
- err = transit_state_bkref (mctx, &cur_state->nodes);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- }
- }
-
- /* If the RE accepts NULL string. */
- if (BE (cur_state->halt, 0))
- {
- if (!cur_state->has_constraint
- || check_halt_state_context (mctx, cur_state, cur_str_idx))
- {
- if (!fl_longest_match)
- return cur_str_idx;
- else
- {
- match_last = cur_str_idx;
- match = 1;
- }
- }
- }
-
- while (!re_string_eoi (&mctx->input))
- {
- re_dfastate_t *old_state = cur_state;
- Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
-
- if ((BE (next_char_idx >= mctx->input.bufs_len, 0)
- && mctx->input.bufs_len < mctx->input.len)
- || (BE (next_char_idx >= mctx->input.valid_len, 0)
- && mctx->input.valid_len < mctx->input.len))
- {
- err = extend_buffers (mctx, next_char_idx + 1);
- if (BE (err != REG_NOERROR, 0))
- {
- assert (err == REG_ESPACE);
- return REG_ERROR;
- }
- }
-
- cur_state = transit_state (&err, mctx, cur_state);
- if (mctx->state_log != NULL)
- cur_state = merge_state_with_log (&err, mctx, cur_state);
-
- if (cur_state == NULL)
- {
- /* Reached the invalid state or an error. Try to recover a valid
- state using the state log, if available and if we have not
- already found a valid (even if not the longest) match. */
- if (BE (err != REG_NOERROR, 0))
- return REG_ERROR;
-
- if (mctx->state_log == NULL
- || (match && !fl_longest_match)
- || (cur_state = find_recover_state (&err, mctx)) == NULL)
- break;
- }
-
- if (BE (at_init_state, 0))
- {
- if (old_state == cur_state)
- next_start_idx = next_char_idx;
- else
- at_init_state = false;
- }
-
- if (cur_state->halt)
- {
- /* Reached a halt state.
- Check the halt state can satisfy the current context. */
- if (!cur_state->has_constraint
- || check_halt_state_context (mctx, cur_state,
- re_string_cur_idx (&mctx->input)))
- {
- /* We found an appropriate halt state. */
- match_last = re_string_cur_idx (&mctx->input);
- match = 1;
-
- /* We found a match, do not modify match_first below. */
- p_match_first = NULL;
- if (!fl_longest_match)
- break;
- }
- }
- }
-
- if (p_match_first)
- *p_match_first += next_start_idx;
-
- return match_last;
-}
-
-/* Check NODE match the current context. */
-
-static bool
-internal_function
-check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
-{
- re_token_type_t type = dfa->nodes[node].type;
- unsigned int constraint = dfa->nodes[node].constraint;
- if (type != END_OF_RE)
- return false;
- if (!constraint)
- return true;
- if (NOT_SATISFY_NEXT_CONSTRAINT (constraint, context))
- return false;
- return true;
-}
-
-/* Check the halt state STATE match the current context.
- Return 0 if not match, if the node, STATE has, is a halt node and
- match the context, return the node. */
-
-static Idx
-internal_function
-check_halt_state_context (const re_match_context_t *mctx,
- const re_dfastate_t *state, Idx idx)
-{
- Idx i;
- unsigned int context;
-#ifdef DEBUG
- assert (state->halt);
-#endif
- context = re_string_context_at (&mctx->input, idx, mctx->eflags);
- for (i = 0; i < state->nodes.nelem; ++i)
- if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context))
- return state->nodes.elems[i];
- return 0;
-}
-
-/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA
- corresponding to the DFA).
- Return the destination node, and update EPS_VIA_NODES;
- return REG_MISSING in case of errors. */
-
-static Idx
-internal_function
-proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
- Idx *pidx, Idx node, re_node_set *eps_via_nodes,
- struct re_fail_stack_t *fs)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- Idx i;
- bool ok;
- if (IS_EPSILON_NODE (dfa->nodes[node].type))
- {
- re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
- re_node_set *edests = &dfa->edests[node];
- Idx dest_node;
- ok = re_node_set_insert (eps_via_nodes, node);
- if (BE (! ok, 0))
- return REG_ERROR;
- /* Pick up a valid destination, or return REG_MISSING if none
- is found. */
- for (dest_node = REG_MISSING, i = 0; i < edests->nelem; ++i)
- {
- Idx candidate = edests->elems[i];
- if (!re_node_set_contains (cur_nodes, candidate))
- continue;
- if (dest_node == REG_MISSING)
- dest_node = candidate;
-
- else
- {
- /* In order to avoid infinite loop like "(a*)*", return the second
- epsilon-transition if the first was already considered. */
- if (re_node_set_contains (eps_via_nodes, dest_node))
- return candidate;
-
- /* Otherwise, push the second epsilon-transition on the fail stack. */
- else if (fs != NULL
- && push_fail_stack (fs, *pidx, candidate, nregs, regs,
- eps_via_nodes))
- return REG_ERROR;
-
- /* We know we are going to exit. */
- break;
- }
- }
- return dest_node;
- }
- else
- {
- Idx naccepted = 0;
- re_token_type_t type = dfa->nodes[node].type;
-
-#ifdef RE_ENABLE_I18N
- if (dfa->nodes[node].accept_mb)
- naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx);
- else
-#endif /* RE_ENABLE_I18N */
- if (type == OP_BACK_REF)
- {
- Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
- naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
- if (fs != NULL)
- {
- if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1)
- return REG_MISSING;
- else if (naccepted)
- {
- char *buf = (char *) re_string_get_buffer (&mctx->input);
- if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
- naccepted) != 0)
- return REG_MISSING;
- }
- }
-
- if (naccepted == 0)
- {
- Idx dest_node;
- ok = re_node_set_insert (eps_via_nodes, node);
- if (BE (! ok, 0))
- return REG_ERROR;
- dest_node = dfa->edests[node].elems[0];
- if (re_node_set_contains (&mctx->state_log[*pidx]->nodes,
- dest_node))
- return dest_node;
- }
- }
-
- if (naccepted != 0
- || check_node_accept (mctx, dfa->nodes + node, *pidx))
- {
- Idx dest_node = dfa->nexts[node];
- *pidx = (naccepted == 0) ? *pidx + 1 : *pidx + naccepted;
- if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL
- || !re_node_set_contains (&mctx->state_log[*pidx]->nodes,
- dest_node)))
- return REG_MISSING;
- re_node_set_empty (eps_via_nodes);
- return dest_node;
- }
- }
- return REG_MISSING;
-}
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
- Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
-{
- reg_errcode_t err;
- Idx num = fs->num++;
- if (fs->num == fs->alloc)
- {
- struct re_fail_stack_ent_t *new_array;
- new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
- * fs->alloc * 2));
- if (new_array == NULL)
- return REG_ESPACE;
- fs->alloc *= 2;
- fs->stack = new_array;
- }
- fs->stack[num].idx = str_idx;
- fs->stack[num].node = dest_node;
- fs->stack[num].regs = re_malloc (regmatch_t, nregs);
- if (fs->stack[num].regs == NULL)
- return REG_ESPACE;
- memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
- err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes);
- return err;
-}
-
-static Idx
-internal_function
-pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
- regmatch_t *regs, re_node_set *eps_via_nodes)
-{
- Idx num = --fs->num;
- assert (REG_VALID_INDEX (num));
- *pidx = fs->stack[num].idx;
- memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs);
- re_node_set_free (eps_via_nodes);
- re_free (fs->stack[num].regs);
- *eps_via_nodes = fs->stack[num].eps_via_nodes;
- return fs->stack[num].node;
-}
-
-/* Set the positions where the subexpressions are starts/ends to registers
- PMATCH.
- Note: We assume that pmatch[0] is already set, and
- pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
- regmatch_t *pmatch, bool fl_backtrack)
-{
- const re_dfa_t *dfa = preg->buffer;
- Idx idx, cur_node;
- re_node_set eps_via_nodes;
- struct re_fail_stack_t *fs;
- struct re_fail_stack_t fs_body = { 0, 2, NULL };
- regmatch_t *prev_idx_match;
- bool prev_idx_match_malloced = false;
-
-#ifdef DEBUG
- assert (nmatch > 1);
- assert (mctx->state_log != NULL);
-#endif
- if (fl_backtrack)
- {
- fs = &fs_body;
- fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc);
- if (fs->stack == NULL)
- return REG_ESPACE;
- }
- else
- fs = NULL;
-
- cur_node = dfa->init_node;
- re_node_set_init_empty (&eps_via_nodes);
-
- if (__libc_use_alloca (nmatch * sizeof (regmatch_t)))
- prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
- else
- {
- prev_idx_match = re_malloc (regmatch_t, nmatch);
- if (prev_idx_match == NULL)
- {
- free_fail_stack_return (fs);
- return REG_ESPACE;
- }
- prev_idx_match_malloced = true;
- }
- memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
-
- for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
- {
- update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch);
-
- if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
- {
- Idx reg_idx;
- if (fs)
- {
- for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
- if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1)
- break;
- if (reg_idx == nmatch)
- {
- re_node_set_free (&eps_via_nodes);
- if (prev_idx_match_malloced)
- re_free (prev_idx_match);
- return free_fail_stack_return (fs);
- }
- cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
- &eps_via_nodes);
- }
- else
- {
- re_node_set_free (&eps_via_nodes);
- if (prev_idx_match_malloced)
- re_free (prev_idx_match);
- return REG_NOERROR;
- }
- }
-
- /* Proceed to next node. */
- cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node,
- &eps_via_nodes, fs);
-
- if (BE (! REG_VALID_INDEX (cur_node), 0))
- {
- if (BE (cur_node == REG_ERROR, 0))
- {
- re_node_set_free (&eps_via_nodes);
- if (prev_idx_match_malloced)
- re_free (prev_idx_match);
- free_fail_stack_return (fs);
- return REG_ESPACE;
- }
- if (fs)
- cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
- &eps_via_nodes);
- else
- {
- re_node_set_free (&eps_via_nodes);
- if (prev_idx_match_malloced)
- re_free (prev_idx_match);
- return REG_NOMATCH;
- }
- }
- }
- re_node_set_free (&eps_via_nodes);
- if (prev_idx_match_malloced)
- re_free (prev_idx_match);
- return free_fail_stack_return (fs);
-}
-
-static reg_errcode_t
-internal_function
-free_fail_stack_return (struct re_fail_stack_t *fs)
-{
- if (fs)
- {
- Idx fs_idx;
- for (fs_idx = 0; fs_idx < fs->num; ++fs_idx)
- {
- re_node_set_free (&fs->stack[fs_idx].eps_via_nodes);
- re_free (fs->stack[fs_idx].regs);
- }
- re_free (fs->stack);
- }
- return REG_NOERROR;
-}
-
-static void
-internal_function
-update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
- regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
-{
- int type = dfa->nodes[cur_node].type;
- if (type == OP_OPEN_SUBEXP)
- {
- Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
-
- /* We are at the first node of this sub expression. */
- if (reg_num < nmatch)
- {
- pmatch[reg_num].rm_so = cur_idx;
- pmatch[reg_num].rm_eo = -1;
- }
- }
- else if (type == OP_CLOSE_SUBEXP)
- {
- Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
- if (reg_num < nmatch)
- {
- /* We are at the last node of this sub expression. */
- if (pmatch[reg_num].rm_so < cur_idx)
- {
- pmatch[reg_num].rm_eo = cur_idx;
- /* This is a non-empty match or we are not inside an optional
- subexpression. Accept this right away. */
- memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
- }
- else
- {
- if (dfa->nodes[cur_node].opt_subexp
- && prev_idx_match[reg_num].rm_so != -1)
- /* We transited through an empty match for an optional
- subexpression, like (a?)*, and this is not the subexp's
- first match. Copy back the old content of the registers
- so that matches of an inner subexpression are undone as
- well, like in ((a?))*. */
- memcpy (pmatch, prev_idx_match, sizeof (regmatch_t) * nmatch);
- else
- /* We completed a subexpression, but it may be part of
- an optional one, so do not update PREV_IDX_MATCH. */
- pmatch[reg_num].rm_eo = cur_idx;
- }
- }
- }
-}
-
-/* This function checks the STATE_LOG from the SCTX->last_str_idx to 0
- and sift the nodes in each states according to the following rules.
- Updated state_log will be wrote to STATE_LOG.
-
- Rules: We throw away the Node 'a' in the STATE_LOG[STR_IDX] if...
- 1. When STR_IDX == MATCH_LAST(the last index in the state_log):
- If 'a' isn't the LAST_NODE and 'a' can't epsilon transit to
- the LAST_NODE, we throw away the node 'a'.
- 2. When 0 <= STR_IDX < MATCH_LAST and 'a' accepts
- string 's' and transit to 'b':
- i. If 'b' isn't in the STATE_LOG[STR_IDX+strlen('s')], we throw
- away the node 'a'.
- ii. If 'b' is in the STATE_LOG[STR_IDX+strlen('s')] but 'b' is
- thrown away, we throw away the node 'a'.
- 3. When 0 <= STR_IDX < MATCH_LAST and 'a' epsilon transit to 'b':
- i. If 'b' isn't in the STATE_LOG[STR_IDX], we throw away the
- node 'a'.
- ii. If 'b' is in the STATE_LOG[STR_IDX] but 'b' is thrown away,
- we throw away the node 'a'. */
-
-#define STATE_NODE_CONTAINS(state,node) \
- ((state) != NULL && re_node_set_contains (&(state)->nodes, node))
-
-static reg_errcode_t
-internal_function
-sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
-{
- reg_errcode_t err;
- int null_cnt = 0;
- Idx str_idx = sctx->last_str_idx;
- re_node_set cur_dest;
-
-#ifdef DEBUG
- assert (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL);
-#endif
-
- /* Build sifted state_log[str_idx]. It has the nodes which can epsilon
- transit to the last_node and the last_node itself. */
- err = re_node_set_init_1 (&cur_dest, sctx->last_node);
- if (BE (err != REG_NOERROR, 0))
- return err;
- err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
-
- /* Then check each states in the state_log. */
- while (str_idx > 0)
- {
- /* Update counters. */
- null_cnt = (sctx->sifted_states[str_idx] == NULL) ? null_cnt + 1 : 0;
- if (null_cnt > mctx->max_mb_elem_len)
- {
- memset (sctx->sifted_states, '\0',
- sizeof (re_dfastate_t *) * str_idx);
- re_node_set_free (&cur_dest);
- return REG_NOERROR;
- }
- re_node_set_empty (&cur_dest);
- --str_idx;
-
- if (mctx->state_log[str_idx])
- {
- err = build_sifted_states (mctx, sctx, str_idx, &cur_dest);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- }
-
- /* Add all the nodes which satisfy the following conditions:
- - It can epsilon transit to a node in CUR_DEST.
- - It is in CUR_SRC.
- And update state_log. */
- err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- }
- err = REG_NOERROR;
- free_return:
- re_node_set_free (&cur_dest);
- return err;
-}
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
- Idx str_idx, re_node_set *cur_dest)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
- Idx i;
-
- /* Then build the next sifted state.
- We build the next sifted state on 'cur_dest', and update
- 'sifted_states[str_idx]' with 'cur_dest'.
- Note:
- 'cur_dest' is the sifted state from 'state_log[str_idx + 1]'.
- 'cur_src' points the node_set of the old 'state_log[str_idx]'
- (with the epsilon nodes pre-filtered out). */
- for (i = 0; i < cur_src->nelem; i++)
- {
- Idx prev_node = cur_src->elems[i];
- int naccepted = 0;
- bool ok;
-
-#ifdef DEBUG
- re_token_type_t type = dfa->nodes[prev_node].type;
- assert (!IS_EPSILON_NODE (type));
-#endif
-#ifdef RE_ENABLE_I18N
- /* If the node may accept "multi byte". */
- if (dfa->nodes[prev_node].accept_mb)
- naccepted = sift_states_iter_mb (mctx, sctx, prev_node,
- str_idx, sctx->last_str_idx);
-#endif /* RE_ENABLE_I18N */
-
- /* We don't check backreferences here.
- See update_cur_sifted_state(). */
- if (!naccepted
- && check_node_accept (mctx, dfa->nodes + prev_node, str_idx)
- && STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + 1],
- dfa->nexts[prev_node]))
- naccepted = 1;
-
- if (naccepted == 0)
- continue;
-
- if (sctx->limits.nelem)
- {
- Idx to_idx = str_idx + naccepted;
- if (check_dst_limits (mctx, &sctx->limits,
- dfa->nexts[prev_node], to_idx,
- prev_node, str_idx))
- continue;
- }
- ok = re_node_set_insert (cur_dest, prev_node);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
-
- return REG_NOERROR;
-}
-
-/* Helper functions. */
-
-static reg_errcode_t
-internal_function
-clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
-{
- Idx top = mctx->state_log_top;
-
- if ((next_state_log_idx >= mctx->input.bufs_len
- && mctx->input.bufs_len < mctx->input.len)
- || (next_state_log_idx >= mctx->input.valid_len
- && mctx->input.valid_len < mctx->input.len))
- {
- reg_errcode_t err;
- err = extend_buffers (mctx, next_state_log_idx + 1);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
-
- if (top < next_state_log_idx)
- {
- memset (mctx->state_log + top + 1, '\0',
- sizeof (re_dfastate_t *) * (next_state_log_idx - top));
- mctx->state_log_top = next_state_log_idx;
- }
- return REG_NOERROR;
-}
-
-static reg_errcode_t
-internal_function
-merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
- re_dfastate_t **src, Idx num)
-{
- Idx st_idx;
- reg_errcode_t err;
- for (st_idx = 0; st_idx < num; ++st_idx)
- {
- if (dst[st_idx] == NULL)
- dst[st_idx] = src[st_idx];
- else if (src[st_idx] != NULL)
- {
- re_node_set merged_set;
- err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes,
- &src[st_idx]->nodes);
- if (BE (err != REG_NOERROR, 0))
- return err;
- dst[st_idx] = re_acquire_state (&err, dfa, &merged_set);
- re_node_set_free (&merged_set);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- }
- return REG_NOERROR;
-}
-
-static reg_errcode_t
-internal_function
-update_cur_sifted_state (const re_match_context_t *mctx,
- re_sift_context_t *sctx, Idx str_idx,
- re_node_set *dest_nodes)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err = REG_NOERROR;
- const re_node_set *candidates;
- candidates = ((mctx->state_log[str_idx] == NULL) ? NULL
- : &mctx->state_log[str_idx]->nodes);
-
- if (dest_nodes->nelem == 0)
- sctx->sifted_states[str_idx] = NULL;
- else
- {
- if (candidates)
- {
- /* At first, add the nodes which can epsilon transit to a node in
- DEST_NODE. */
- err = add_epsilon_src_nodes (dfa, dest_nodes, candidates);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- /* Then, check the limitations in the current sift_context. */
- if (sctx->limits.nelem)
- {
- err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits,
- mctx->bkref_ents, str_idx);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- }
-
- sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
-
- if (candidates && mctx->state_log[str_idx]->has_backref)
- {
- err = sift_states_bkref (mctx, sctx, str_idx, candidates);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- return REG_NOERROR;
-}
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
- const re_node_set *candidates)
-{
- reg_errcode_t err = REG_NOERROR;
- Idx i;
-
- re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- if (!state->inveclosure.alloc)
- {
- err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem);
- if (BE (err != REG_NOERROR, 0))
- return REG_ESPACE;
- for (i = 0; i < dest_nodes->nelem; i++)
- {
- err = re_node_set_merge (&state->inveclosure,
- dfa->inveclosures + dest_nodes->elems[i]);
- if (BE (err != REG_NOERROR, 0))
- return REG_ESPACE;
- }
- }
- return re_node_set_add_intersect (dest_nodes, candidates,
- &state->inveclosure);
-}
-
-static reg_errcode_t
-internal_function
-sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
- const re_node_set *candidates)
-{
- Idx ecl_idx;
- reg_errcode_t err;
- re_node_set *inv_eclosure = dfa->inveclosures + node;
- re_node_set except_nodes;
- re_node_set_init_empty (&except_nodes);
- for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
- {
- Idx cur_node = inv_eclosure->elems[ecl_idx];
- if (cur_node == node)
- continue;
- if (IS_EPSILON_NODE (dfa->nodes[cur_node].type))
- {
- Idx edst1 = dfa->edests[cur_node].elems[0];
- Idx edst2 = ((dfa->edests[cur_node].nelem > 1)
- ? dfa->edests[cur_node].elems[1] : REG_MISSING);
- if ((!re_node_set_contains (inv_eclosure, edst1)
- && re_node_set_contains (dest_nodes, edst1))
- || (REG_VALID_NONZERO_INDEX (edst2)
- && !re_node_set_contains (inv_eclosure, edst2)
- && re_node_set_contains (dest_nodes, edst2)))
- {
- err = re_node_set_add_intersect (&except_nodes, candidates,
- dfa->inveclosures + cur_node);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&except_nodes);
- return err;
- }
- }
- }
- }
- for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
- {
- Idx cur_node = inv_eclosure->elems[ecl_idx];
- if (!re_node_set_contains (&except_nodes, cur_node))
- {
- Idx idx = re_node_set_contains (dest_nodes, cur_node) - 1;
- re_node_set_remove_at (dest_nodes, idx);
- }
- }
- re_node_set_free (&except_nodes);
- return REG_NOERROR;
-}
-
-static bool
-internal_function
-check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
- Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- Idx lim_idx, src_pos, dst_pos;
-
- Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
- Idx src_bkref_idx = search_cur_bkref_entry (mctx, src_idx);
- for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
- {
- Idx subexp_idx;
- struct re_backref_cache_entry *ent;
- ent = mctx->bkref_ents + limits->elems[lim_idx];
- subexp_idx = dfa->nodes[ent->node].opr.idx;
-
- dst_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx],
- subexp_idx, dst_node, dst_idx,
- dst_bkref_idx);
- src_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx],
- subexp_idx, src_node, src_idx,
- src_bkref_idx);
-
- /* In case of:
- <src> <dst> ( <subexp> )
- ( <subexp> ) <src> <dst>
- ( <subexp1> <src> <subexp2> <dst> <subexp3> ) */
- if (src_pos == dst_pos)
- continue; /* This is unrelated limitation. */
- else
- return true;
- }
- return false;
-}
-
-static int
-internal_function
-check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
- Idx subexp_idx, Idx from_node, Idx bkref_idx)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- const re_node_set *eclosures = dfa->eclosures + from_node;
- Idx node_idx;
-
- /* Else, we are on the boundary: examine the nodes on the epsilon
- closure. */
- for (node_idx = 0; node_idx < eclosures->nelem; ++node_idx)
- {
- Idx node = eclosures->elems[node_idx];
- switch (dfa->nodes[node].type)
- {
- case OP_BACK_REF:
- if (bkref_idx != REG_MISSING)
- {
- struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx;
- do
- {
- Idx dst;
- int cpos;
-
- if (ent->node != node)
- continue;
-
- if (subexp_idx < BITSET_WORD_BITS
- && !(ent->eps_reachable_subexps_map
- & ((bitset_word_t) 1 << subexp_idx)))
- continue;
-
- /* Recurse trying to reach the OP_OPEN_SUBEXP and
- OP_CLOSE_SUBEXP cases below. But, if the
- destination node is the same node as the source
- node, don't recurse because it would cause an
- infinite loop: a regex that exhibits this behavior
- is ()\1*\1* */
- dst = dfa->edests[node].elems[0];
- if (dst == from_node)
- {
- if (boundaries & 1)
- return -1;
- else /* if (boundaries & 2) */
- return 0;
- }
-
- cpos =
- check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx,
- dst, bkref_idx);
- if (cpos == -1 /* && (boundaries & 1) */)
- return -1;
- if (cpos == 0 && (boundaries & 2))
- return 0;
-
- if (subexp_idx < BITSET_WORD_BITS)
- ent->eps_reachable_subexps_map
- &= ~((bitset_word_t) 1 << subexp_idx);
- }
- while (ent++->more);
- }
- break;
-
- case OP_OPEN_SUBEXP:
- if ((boundaries & 1) && subexp_idx == dfa->nodes[node].opr.idx)
- return -1;
- break;
-
- case OP_CLOSE_SUBEXP:
- if ((boundaries & 2) && subexp_idx == dfa->nodes[node].opr.idx)
- return 0;
- break;
-
- default:
- break;
- }
- }
-
- return (boundaries & 2) ? 1 : 0;
-}
-
-static int
-internal_function
-check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
- Idx subexp_idx, Idx from_node, Idx str_idx,
- Idx bkref_idx)
-{
- struct re_backref_cache_entry *lim = mctx->bkref_ents + limit;
- int boundaries;
-
- /* If we are outside the range of the subexpression, return -1 or 1. */
- if (str_idx < lim->subexp_from)
- return -1;
-
- if (lim->subexp_to < str_idx)
- return 1;
-
- /* If we are within the subexpression, return 0. */
- boundaries = (str_idx == lim->subexp_from);
- boundaries |= (str_idx == lim->subexp_to) << 1;
- if (boundaries == 0)
- return 0;
-
- /* Else, examine epsilon closure. */
- return check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx,
- from_node, bkref_idx);
-}
-
-/* Check the limitations of sub expressions LIMITS, and remove the nodes
- which are against limitations from DEST_NODES. */
-
-static reg_errcode_t
-internal_function
-check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
- const re_node_set *candidates, re_node_set *limits,
- struct re_backref_cache_entry *bkref_ents, Idx str_idx)
-{
- reg_errcode_t err;
- Idx node_idx, lim_idx;
-
- for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
- {
- Idx subexp_idx;
- struct re_backref_cache_entry *ent;
- ent = bkref_ents + limits->elems[lim_idx];
-
- if (str_idx <= ent->subexp_from || ent->str_idx < str_idx)
- continue; /* This is unrelated limitation. */
-
- subexp_idx = dfa->nodes[ent->node].opr.idx;
- if (ent->subexp_to == str_idx)
- {
- Idx ops_node = REG_MISSING;
- Idx cls_node = REG_MISSING;
- for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
- {
- Idx node = dest_nodes->elems[node_idx];
- re_token_type_t type = dfa->nodes[node].type;
- if (type == OP_OPEN_SUBEXP
- && subexp_idx == dfa->nodes[node].opr.idx)
- ops_node = node;
- else if (type == OP_CLOSE_SUBEXP
- && subexp_idx == dfa->nodes[node].opr.idx)
- cls_node = node;
- }
-
- /* Check the limitation of the open subexpression. */
- /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */
- if (REG_VALID_INDEX (ops_node))
- {
- err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes,
- candidates);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
-
- /* Check the limitation of the close subexpression. */
- if (REG_VALID_INDEX (cls_node))
- for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
- {
- Idx node = dest_nodes->elems[node_idx];
- if (!re_node_set_contains (dfa->inveclosures + node,
- cls_node)
- && !re_node_set_contains (dfa->eclosures + node,
- cls_node))
- {
- /* It is against this limitation.
- Remove it form the current sifted state. */
- err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
- candidates);
- if (BE (err != REG_NOERROR, 0))
- return err;
- --node_idx;
- }
- }
- }
- else /* (ent->subexp_to != str_idx) */
- {
- for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
- {
- Idx node = dest_nodes->elems[node_idx];
- re_token_type_t type = dfa->nodes[node].type;
- if (type == OP_CLOSE_SUBEXP || type == OP_OPEN_SUBEXP)
- {
- if (subexp_idx != dfa->nodes[node].opr.idx)
- continue;
- /* It is against this limitation.
- Remove it form the current sifted state. */
- err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
- candidates);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- }
- }
- }
- return REG_NOERROR;
-}
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
- Idx str_idx, const re_node_set *candidates)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err;
- Idx node_idx, node;
- re_sift_context_t local_sctx;
- Idx first_idx = search_cur_bkref_entry (mctx, str_idx);
-
- if (first_idx == REG_MISSING)
- return REG_NOERROR;
-
- local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */
-
- for (node_idx = 0; node_idx < candidates->nelem; ++node_idx)
- {
- Idx enabled_idx;
- re_token_type_t type;
- struct re_backref_cache_entry *entry;
- node = candidates->elems[node_idx];
- type = dfa->nodes[node].type;
- /* Avoid infinite loop for the REs like "()\1+". */
- if (node == sctx->last_node && str_idx == sctx->last_str_idx)
- continue;
- if (type != OP_BACK_REF)
- continue;
-
- entry = mctx->bkref_ents + first_idx;
- enabled_idx = first_idx;
- do
- {
- Idx subexp_len;
- Idx to_idx;
- Idx dst_node;
- bool ok;
- re_dfastate_t *cur_state;
-
- if (entry->node != node)
- continue;
- subexp_len = entry->subexp_to - entry->subexp_from;
- to_idx = str_idx + subexp_len;
- dst_node = (subexp_len ? dfa->nexts[node]
- : dfa->edests[node].elems[0]);
-
- if (to_idx > sctx->last_str_idx
- || sctx->sifted_states[to_idx] == NULL
- || !STATE_NODE_CONTAINS (sctx->sifted_states[to_idx], dst_node)
- || check_dst_limits (mctx, &sctx->limits, node,
- str_idx, dst_node, to_idx))
- continue;
-
- if (local_sctx.sifted_states == NULL)
- {
- local_sctx = *sctx;
- err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- }
- local_sctx.last_node = node;
- local_sctx.last_str_idx = str_idx;
- ok = re_node_set_insert (&local_sctx.limits, enabled_idx);
- if (BE (! ok, 0))
- {
- err = REG_ESPACE;
- goto free_return;
- }
- cur_state = local_sctx.sifted_states[str_idx];
- err = sift_states_backward (mctx, &local_sctx);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- if (sctx->limited_states != NULL)
- {
- err = merge_state_array (dfa, sctx->limited_states,
- local_sctx.sifted_states,
- str_idx + 1);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- }
- local_sctx.sifted_states[str_idx] = cur_state;
- re_node_set_remove (&local_sctx.limits, enabled_idx);
-
- /* mctx->bkref_ents may have changed, reload the pointer. */
- entry = mctx->bkref_ents + enabled_idx;
- }
- while (enabled_idx++, entry++->more);
- }
- err = REG_NOERROR;
- free_return:
- if (local_sctx.sifted_states != NULL)
- {
- re_node_set_free (&local_sctx.limits);
- }
-
- return err;
-}
-
-
-#ifdef RE_ENABLE_I18N
-static int
-internal_function
-sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
- Idx node_idx, Idx str_idx, Idx max_str_idx)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- int naccepted;
- /* Check the node can accept "multi byte". */
- naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
- if (naccepted > 0 && str_idx + naccepted <= max_str_idx &&
- !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted],
- dfa->nexts[node_idx]))
- /* The node can't accept the "multi byte", or the
- destination was already thrown away, then the node
- could't accept the current input "multi byte". */
- naccepted = 0;
- /* Otherwise, it is sure that the node could accept
- 'naccepted' bytes input. */
- return naccepted;
-}
-#endif /* RE_ENABLE_I18N */
-
-
-/* Functions for state transition. */
-
-/* Return the next state to which the current state STATE will transit by
- accepting the current input byte, and update STATE_LOG if necessary.
- If STATE can accept a multibyte char/collating element/back reference
- update the destination of STATE_LOG. */
-
-static re_dfastate_t *
-internal_function __attribute_warn_unused_result__
-transit_state (reg_errcode_t *err, re_match_context_t *mctx,
- re_dfastate_t *state)
-{
- re_dfastate_t **trtable;
- unsigned char ch;
-
-#ifdef RE_ENABLE_I18N
- /* If the current state can accept multibyte. */
- if (BE (state->accept_mb, 0))
- {
- *err = transit_state_mb (mctx, state);
- if (BE (*err != REG_NOERROR, 0))
- return NULL;
- }
-#endif /* RE_ENABLE_I18N */
-
- /* Then decide the next state with the single byte. */
-#if 0
- if (0)
- /* don't use transition table */
- return transit_state_sb (err, mctx, state);
-#endif
-
- /* Use transition table */
- ch = re_string_fetch_byte (&mctx->input);
- for (;;)
- {
- trtable = state->trtable;
- if (BE (trtable != NULL, 1))
- return trtable[ch];
-
- trtable = state->word_trtable;
- if (BE (trtable != NULL, 1))
- {
- unsigned int context;
- context
- = re_string_context_at (&mctx->input,
- re_string_cur_idx (&mctx->input) - 1,
- mctx->eflags);
- if (IS_WORD_CONTEXT (context))
- return trtable[ch + SBC_MAX];
- else
- return trtable[ch];
- }
-
- if (!build_trtable (mctx->dfa, state))
- {
- *err = REG_ESPACE;
- return NULL;
- }
-
- /* Retry, we now have a transition table. */
- }
-}
-
-/* Update the state_log if we need */
-static re_dfastate_t *
-internal_function
-merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
- re_dfastate_t *next_state)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- Idx cur_idx = re_string_cur_idx (&mctx->input);
-
- if (cur_idx > mctx->state_log_top)
- {
- mctx->state_log[cur_idx] = next_state;
- mctx->state_log_top = cur_idx;
- }
- else if (mctx->state_log[cur_idx] == 0)
- {
- mctx->state_log[cur_idx] = next_state;
- }
- else
- {
- re_dfastate_t *pstate;
- unsigned int context;
- re_node_set next_nodes, *log_nodes, *table_nodes = NULL;
- /* If (state_log[cur_idx] != 0), it implies that cur_idx is
- the destination of a multibyte char/collating element/
- back reference. Then the next state is the union set of
- these destinations and the results of the transition table. */
- pstate = mctx->state_log[cur_idx];
- log_nodes = pstate->entrance_nodes;
- if (next_state != NULL)
- {
- table_nodes = next_state->entrance_nodes;
- *err = re_node_set_init_union (&next_nodes, table_nodes,
- log_nodes);
- if (BE (*err != REG_NOERROR, 0))
- return NULL;
- }
- else
- next_nodes = *log_nodes;
- /* Note: We already add the nodes of the initial state,
- then we don't need to add them here. */
-
- context = re_string_context_at (&mctx->input,
- re_string_cur_idx (&mctx->input) - 1,
- mctx->eflags);
- next_state = mctx->state_log[cur_idx]
- = re_acquire_state_context (err, dfa, &next_nodes, context);
- /* We don't need to check errors here, since the return value of
- this function is next_state and ERR is already set. */
-
- if (table_nodes != NULL)
- re_node_set_free (&next_nodes);
- }
-
- if (BE (dfa->nbackref, 0) && next_state != NULL)
- {
- /* Check OP_OPEN_SUBEXP in the current state in case that we use them
- later. We must check them here, since the back references in the
- next state might use them. */
- *err = check_subexp_matching_top (mctx, &next_state->nodes,
- cur_idx);
- if (BE (*err != REG_NOERROR, 0))
- return NULL;
-
- /* If the next state has back references. */
- if (next_state->has_backref)
- {
- *err = transit_state_bkref (mctx, &next_state->nodes);
- if (BE (*err != REG_NOERROR, 0))
- return NULL;
- next_state = mctx->state_log[cur_idx];
- }
- }
-
- return next_state;
-}
-
-/* Skip bytes in the input that correspond to part of a
- multi-byte match, then look in the log for a state
- from which to restart matching. */
-static re_dfastate_t *
-internal_function
-find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
-{
- re_dfastate_t *cur_state;
- do
- {
- Idx max = mctx->state_log_top;
- Idx cur_str_idx = re_string_cur_idx (&mctx->input);
-
- do
- {
- if (++cur_str_idx > max)
- return NULL;
- re_string_skip_bytes (&mctx->input, 1);
- }
- while (mctx->state_log[cur_str_idx] == NULL);
-
- cur_state = merge_state_with_log (err, mctx, NULL);
- }
- while (*err == REG_NOERROR && cur_state == NULL);
- return cur_state;
-}
-
-/* Helper functions for transit_state. */
-
-/* From the node set CUR_NODES, pick up the nodes whose types are
- OP_OPEN_SUBEXP and which have corresponding back references in the regular
- expression. And register them to use them later for evaluating the
- corresponding back references. */
-
-static reg_errcode_t
-internal_function
-check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
- Idx str_idx)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- Idx node_idx;
- reg_errcode_t err;
-
- /* TODO: This isn't efficient.
- Because there might be more than one nodes whose types are
- OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all
- nodes.
- E.g. RE: (a){2} */
- for (node_idx = 0; node_idx < cur_nodes->nelem; ++node_idx)
- {
- Idx node = cur_nodes->elems[node_idx];
- if (dfa->nodes[node].type == OP_OPEN_SUBEXP
- && dfa->nodes[node].opr.idx < BITSET_WORD_BITS
- && (dfa->used_bkref_map
- & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx)))
- {
- err = match_ctx_add_subtop (mctx, node, str_idx);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- }
- return REG_NOERROR;
-}
-
-#if 0
-/* Return the next state to which the current state STATE will transit by
- accepting the current input byte. */
-
-static re_dfastate_t *
-transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
- re_dfastate_t *state)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- re_node_set next_nodes;
- re_dfastate_t *next_state;
- Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
- unsigned int context;
-
- *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1);
- if (BE (*err != REG_NOERROR, 0))
- return NULL;
- for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt)
- {
- Idx cur_node = state->nodes.elems[node_cnt];
- if (check_node_accept (mctx, dfa->nodes + cur_node, cur_str_idx))
- {
- *err = re_node_set_merge (&next_nodes,
- dfa->eclosures + dfa->nexts[cur_node]);
- if (BE (*err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return NULL;
- }
- }
- }
- context = re_string_context_at (&mctx->input, cur_str_idx, mctx->eflags);
- next_state = re_acquire_state_context (err, dfa, &next_nodes, context);
- /* We don't need to check errors here, since the return value of
- this function is next_state and ERR is already set. */
-
- re_node_set_free (&next_nodes);
- re_string_skip_bytes (&mctx->input, 1);
- return next_state;
-}
-#endif
-
-#ifdef RE_ENABLE_I18N
-static reg_errcode_t
-internal_function
-transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err;
- Idx i;
-
- for (i = 0; i < pstate->nodes.nelem; ++i)
- {
- re_node_set dest_nodes, *new_nodes;
- Idx cur_node_idx = pstate->nodes.elems[i];
- int naccepted;
- Idx dest_idx;
- unsigned int context;
- re_dfastate_t *dest_state;
-
- if (!dfa->nodes[cur_node_idx].accept_mb)
- continue;
-
- if (dfa->nodes[cur_node_idx].constraint)
- {
- context = re_string_context_at (&mctx->input,
- re_string_cur_idx (&mctx->input),
- mctx->eflags);
- if (NOT_SATISFY_NEXT_CONSTRAINT (dfa->nodes[cur_node_idx].constraint,
- context))
- continue;
- }
-
- /* How many bytes the node can accept? */
- naccepted = check_node_accept_bytes (dfa, cur_node_idx, &mctx->input,
- re_string_cur_idx (&mctx->input));
- if (naccepted == 0)
- continue;
-
- /* The node can accepts 'naccepted' bytes. */
- dest_idx = re_string_cur_idx (&mctx->input) + naccepted;
- mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
- : mctx->max_mb_elem_len);
- err = clean_state_log_if_needed (mctx, dest_idx);
- if (BE (err != REG_NOERROR, 0))
- return err;
-#ifdef DEBUG
- assert (dfa->nexts[cur_node_idx] != REG_MISSING);
-#endif
- new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx];
-
- dest_state = mctx->state_log[dest_idx];
- if (dest_state == NULL)
- dest_nodes = *new_nodes;
- else
- {
- err = re_node_set_init_union (&dest_nodes,
- dest_state->entrance_nodes, new_nodes);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- context = re_string_context_at (&mctx->input, dest_idx - 1,
- mctx->eflags);
- mctx->state_log[dest_idx]
- = re_acquire_state_context (&err, dfa, &dest_nodes, context);
- if (dest_state != NULL)
- re_node_set_free (&dest_nodes);
- if (BE (mctx->state_log[dest_idx] == NULL && err != REG_NOERROR, 0))
- return err;
- }
- return REG_NOERROR;
-}
-#endif /* RE_ENABLE_I18N */
-
-static reg_errcode_t
-internal_function
-transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err;
- Idx i;
- Idx cur_str_idx = re_string_cur_idx (&mctx->input);
-
- for (i = 0; i < nodes->nelem; ++i)
- {
- Idx dest_str_idx, prev_nelem, bkc_idx;
- Idx node_idx = nodes->elems[i];
- unsigned int context;
- const re_token_t *node = dfa->nodes + node_idx;
- re_node_set *new_dest_nodes;
-
- /* Check whether 'node' is a backreference or not. */
- if (node->type != OP_BACK_REF)
- continue;
-
- if (node->constraint)
- {
- context = re_string_context_at (&mctx->input, cur_str_idx,
- mctx->eflags);
- if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
- continue;
- }
-
- /* 'node' is a backreference.
- Check the substring which the substring matched. */
- bkc_idx = mctx->nbkref_ents;
- err = get_subexp (mctx, node_idx, cur_str_idx);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
-
- /* And add the epsilon closures (which is 'new_dest_nodes') of
- the backreference to appropriate state_log. */
-#ifdef DEBUG
- assert (dfa->nexts[node_idx] != REG_MISSING);
-#endif
- for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx)
- {
- Idx subexp_len;
- re_dfastate_t *dest_state;
- struct re_backref_cache_entry *bkref_ent;
- bkref_ent = mctx->bkref_ents + bkc_idx;
- if (bkref_ent->node != node_idx || bkref_ent->str_idx != cur_str_idx)
- continue;
- subexp_len = bkref_ent->subexp_to - bkref_ent->subexp_from;
- new_dest_nodes = (subexp_len == 0
- ? dfa->eclosures + dfa->edests[node_idx].elems[0]
- : dfa->eclosures + dfa->nexts[node_idx]);
- dest_str_idx = (cur_str_idx + bkref_ent->subexp_to
- - bkref_ent->subexp_from);
- context = re_string_context_at (&mctx->input, dest_str_idx - 1,
- mctx->eflags);
- dest_state = mctx->state_log[dest_str_idx];
- prev_nelem = ((mctx->state_log[cur_str_idx] == NULL) ? 0
- : mctx->state_log[cur_str_idx]->nodes.nelem);
- /* Add 'new_dest_node' to state_log. */
- if (dest_state == NULL)
- {
- mctx->state_log[dest_str_idx]
- = re_acquire_state_context (&err, dfa, new_dest_nodes,
- context);
- if (BE (mctx->state_log[dest_str_idx] == NULL
- && err != REG_NOERROR, 0))
- goto free_return;
- }
- else
- {
- re_node_set dest_nodes;
- err = re_node_set_init_union (&dest_nodes,
- dest_state->entrance_nodes,
- new_dest_nodes);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&dest_nodes);
- goto free_return;
- }
- mctx->state_log[dest_str_idx]
- = re_acquire_state_context (&err, dfa, &dest_nodes, context);
- re_node_set_free (&dest_nodes);
- if (BE (mctx->state_log[dest_str_idx] == NULL
- && err != REG_NOERROR, 0))
- goto free_return;
- }
- /* We need to check recursively if the backreference can epsilon
- transit. */
- if (subexp_len == 0
- && mctx->state_log[cur_str_idx]->nodes.nelem > prev_nelem)
- {
- err = check_subexp_matching_top (mctx, new_dest_nodes,
- cur_str_idx);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- err = transit_state_bkref (mctx, new_dest_nodes);
- if (BE (err != REG_NOERROR, 0))
- goto free_return;
- }
- }
- }
- err = REG_NOERROR;
- free_return:
- return err;
-}
-
-/* Enumerate all the candidates which the backreference BKREF_NODE can match
- at BKREF_STR_IDX, and register them by match_ctx_add_entry().
- Note that we might collect inappropriate candidates here.
- However, the cost of checking them strictly here is too high, then we
- delay these checking for prune_impossible_nodes(). */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- Idx subexp_num, sub_top_idx;
- const char *buf = (const char *) re_string_get_buffer (&mctx->input);
- /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
- Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
- if (cache_idx != REG_MISSING)
- {
- const struct re_backref_cache_entry *entry
- = mctx->bkref_ents + cache_idx;
- do
- if (entry->node == bkref_node)
- return REG_NOERROR; /* We already checked it. */
- while (entry++->more);
- }
-
- subexp_num = dfa->nodes[bkref_node].opr.idx;
-
- /* For each sub expression */
- for (sub_top_idx = 0; sub_top_idx < mctx->nsub_tops; ++sub_top_idx)
- {
- reg_errcode_t err;
- re_sub_match_top_t *sub_top = mctx->sub_tops[sub_top_idx];
- re_sub_match_last_t *sub_last;
- Idx sub_last_idx, sl_str, bkref_str_off;
-
- if (dfa->nodes[sub_top->node].opr.idx != subexp_num)
- continue; /* It isn't related. */
-
- sl_str = sub_top->str_idx;
- bkref_str_off = bkref_str_idx;
- /* At first, check the last node of sub expressions we already
- evaluated. */
- for (sub_last_idx = 0; sub_last_idx < sub_top->nlasts; ++sub_last_idx)
- {
- regoff_t sl_str_diff;
- sub_last = sub_top->lasts[sub_last_idx];
- sl_str_diff = sub_last->str_idx - sl_str;
- /* The matched string by the sub expression match with the substring
- at the back reference? */
- if (sl_str_diff > 0)
- {
- if (BE (bkref_str_off + sl_str_diff > mctx->input.valid_len, 0))
- {
- /* Not enough chars for a successful match. */
- if (bkref_str_off + sl_str_diff > mctx->input.len)
- break;
-
- err = clean_state_log_if_needed (mctx,
- bkref_str_off
- + sl_str_diff);
- if (BE (err != REG_NOERROR, 0))
- return err;
- buf = (const char *) re_string_get_buffer (&mctx->input);
- }
- if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0)
- /* We don't need to search this sub expression any more. */
- break;
- }
- bkref_str_off += sl_str_diff;
- sl_str += sl_str_diff;
- err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
- bkref_str_idx);
-
- /* Reload buf, since the preceding call might have reallocated
- the buffer. */
- buf = (const char *) re_string_get_buffer (&mctx->input);
-
- if (err == REG_NOMATCH)
- continue;
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
-
- if (sub_last_idx < sub_top->nlasts)
- continue;
- if (sub_last_idx > 0)
- ++sl_str;
- /* Then, search for the other last nodes of the sub expression. */
- for (; sl_str <= bkref_str_idx; ++sl_str)
- {
- Idx cls_node;
- regoff_t sl_str_off;
- const re_node_set *nodes;
- sl_str_off = sl_str - sub_top->str_idx;
- /* The matched string by the sub expression match with the substring
- at the back reference? */
- if (sl_str_off > 0)
- {
- if (BE (bkref_str_off >= mctx->input.valid_len, 0))
- {
- /* If we are at the end of the input, we cannot match. */
- if (bkref_str_off >= mctx->input.len)
- break;
-
- err = extend_buffers (mctx, bkref_str_off + 1);
- if (BE (err != REG_NOERROR, 0))
- return err;
-
- buf = (const char *) re_string_get_buffer (&mctx->input);
- }
- if (buf [bkref_str_off++] != buf[sl_str - 1])
- break; /* We don't need to search this sub expression
- any more. */
- }
- if (mctx->state_log[sl_str] == NULL)
- continue;
- /* Does this state have a ')' of the sub expression? */
- nodes = &mctx->state_log[sl_str]->nodes;
- cls_node = find_subexp_node (dfa, nodes, subexp_num,
- OP_CLOSE_SUBEXP);
- if (cls_node == REG_MISSING)
- continue; /* No. */
- if (sub_top->path == NULL)
- {
- sub_top->path = calloc (sizeof (state_array_t),
- sl_str - sub_top->str_idx + 1);
- if (sub_top->path == NULL)
- return REG_ESPACE;
- }
- /* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node
- in the current context? */
- err = check_arrival (mctx, sub_top->path, sub_top->node,
- sub_top->str_idx, cls_node, sl_str,
- OP_CLOSE_SUBEXP);
- if (err == REG_NOMATCH)
- continue;
- if (BE (err != REG_NOERROR, 0))
- return err;
- sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str);
- if (BE (sub_last == NULL, 0))
- return REG_ESPACE;
- err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
- bkref_str_idx);
- if (err == REG_NOMATCH)
- continue;
- }
- }
- return REG_NOERROR;
-}
-
-/* Helper functions for get_subexp(). */
-
-/* Check SUB_LAST can arrive to the back reference BKREF_NODE at BKREF_STR.
- If it can arrive, register the sub expression expressed with SUB_TOP
- and SUB_LAST. */
-
-static reg_errcode_t
-internal_function
-get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
- re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str)
-{
- reg_errcode_t err;
- Idx to_idx;
- /* Can the subexpression arrive the back reference? */
- err = check_arrival (mctx, &sub_last->path, sub_last->node,
- sub_last->str_idx, bkref_node, bkref_str,
- OP_OPEN_SUBEXP);
- if (err != REG_NOERROR)
- return err;
- err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
- sub_last->str_idx);
- if (BE (err != REG_NOERROR, 0))
- return err;
- to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx;
- return clean_state_log_if_needed (mctx, to_idx);
-}
-
-/* Find the first node which is '(' or ')' and whose index is SUBEXP_IDX.
- Search '(' if FL_OPEN, or search ')' otherwise.
- TODO: This function isn't efficient...
- Because there might be more than one nodes whose types are
- OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all
- nodes.
- E.g. RE: (a){2} */
-
-static Idx
-internal_function
-find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
- Idx subexp_idx, int type)
-{
- Idx cls_idx;
- for (cls_idx = 0; cls_idx < nodes->nelem; ++cls_idx)
- {
- Idx cls_node = nodes->elems[cls_idx];
- const re_token_t *node = dfa->nodes + cls_node;
- if (node->type == type
- && node->opr.idx == subexp_idx)
- return cls_node;
- }
- return REG_MISSING;
-}
-
-/* Check whether the node TOP_NODE at TOP_STR can arrive to the node
- LAST_NODE at LAST_STR. We record the path onto PATH since it will be
- heavily reused.
- Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
- Idx top_str, Idx last_node, Idx last_str, int type)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err = REG_NOERROR;
- Idx subexp_num, backup_cur_idx, str_idx, null_cnt;
- re_dfastate_t *cur_state = NULL;
- re_node_set *cur_nodes, next_nodes;
- re_dfastate_t **backup_state_log;
- unsigned int context;
-
- subexp_num = dfa->nodes[top_node].opr.idx;
- /* Extend the buffer if we need. */
- if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0))
- {
- re_dfastate_t **new_array;
- Idx old_alloc = path->alloc;
- Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1;
- Idx new_alloc;
- if (BE (IDX_MAX - old_alloc < incr_alloc, 0))
- return REG_ESPACE;
- new_alloc = old_alloc + incr_alloc;
- if (BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0))
- return REG_ESPACE;
- new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
- if (BE (new_array == NULL, 0))
- return REG_ESPACE;
- path->array = new_array;
- path->alloc = new_alloc;
- memset (new_array + old_alloc, '\0',
- sizeof (re_dfastate_t *) * (path->alloc - old_alloc));
- }
-
- str_idx = path->next_idx ? path->next_idx : top_str;
-
- /* Temporary modify MCTX. */
- backup_state_log = mctx->state_log;
- backup_cur_idx = mctx->input.cur_idx;
- mctx->state_log = path->array;
- mctx->input.cur_idx = str_idx;
-
- /* Setup initial node set. */
- context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
- if (str_idx == top_str)
- {
- err = re_node_set_init_1 (&next_nodes, top_node);
- if (BE (err != REG_NOERROR, 0))
- return err;
- err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- }
- else
- {
- cur_state = mctx->state_log[str_idx];
- if (cur_state && cur_state->has_backref)
- {
- err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- else
- re_node_set_init_empty (&next_nodes);
- }
- if (str_idx == top_str || (cur_state && cur_state->has_backref))
- {
- if (next_nodes.nelem)
- {
- err = expand_bkref_cache (mctx, &next_nodes, str_idx,
- subexp_num, type);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- }
- cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
- if (BE (cur_state == NULL && err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- mctx->state_log[str_idx] = cur_state;
- }
-
- for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;)
- {
- re_node_set_empty (&next_nodes);
- if (mctx->state_log[str_idx + 1])
- {
- err = re_node_set_merge (&next_nodes,
- &mctx->state_log[str_idx + 1]->nodes);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- }
- if (cur_state)
- {
- err = check_arrival_add_next_nodes (mctx, str_idx,
- &cur_state->non_eps_nodes,
- &next_nodes);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- }
- ++str_idx;
- if (next_nodes.nelem)
- {
- err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- err = expand_bkref_cache (mctx, &next_nodes, str_idx,
- subexp_num, type);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- }
- context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
- cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
- if (BE (cur_state == NULL && err != REG_NOERROR, 0))
- {
- re_node_set_free (&next_nodes);
- return err;
- }
- mctx->state_log[str_idx] = cur_state;
- null_cnt = cur_state == NULL ? null_cnt + 1 : 0;
- }
- re_node_set_free (&next_nodes);
- cur_nodes = (mctx->state_log[last_str] == NULL ? NULL
- : &mctx->state_log[last_str]->nodes);
- path->next_idx = str_idx;
-
- /* Fix MCTX. */
- mctx->state_log = backup_state_log;
- mctx->input.cur_idx = backup_cur_idx;
-
- /* Then check the current node set has the node LAST_NODE. */
- if (cur_nodes != NULL && re_node_set_contains (cur_nodes, last_node))
- return REG_NOERROR;
-
- return REG_NOMATCH;
-}
-
-/* Helper functions for check_arrival. */
-
-/* Calculate the destination nodes of CUR_NODES at STR_IDX, and append them
- to NEXT_NODES.
- TODO: This function is similar to the functions transit_state*(),
- however this function has many additional works.
- Can't we unify them? */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
- re_node_set *cur_nodes, re_node_set *next_nodes)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- bool ok;
- Idx cur_idx;
-#ifdef RE_ENABLE_I18N
- reg_errcode_t err = REG_NOERROR;
-#endif
- re_node_set union_set;
- re_node_set_init_empty (&union_set);
- for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
- {
- int naccepted = 0;
- Idx cur_node = cur_nodes->elems[cur_idx];
-#ifdef DEBUG
- re_token_type_t type = dfa->nodes[cur_node].type;
- assert (!IS_EPSILON_NODE (type));
-#endif
-#ifdef RE_ENABLE_I18N
- /* If the node may accept "multi byte". */
- if (dfa->nodes[cur_node].accept_mb)
- {
- naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input,
- str_idx);
- if (naccepted > 1)
- {
- re_dfastate_t *dest_state;
- Idx next_node = dfa->nexts[cur_node];
- Idx next_idx = str_idx + naccepted;
- dest_state = mctx->state_log[next_idx];
- re_node_set_empty (&union_set);
- if (dest_state)
- {
- err = re_node_set_merge (&union_set, &dest_state->nodes);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&union_set);
- return err;
- }
- }
- ok = re_node_set_insert (&union_set, next_node);
- if (BE (! ok, 0))
- {
- re_node_set_free (&union_set);
- return REG_ESPACE;
- }
- mctx->state_log[next_idx] = re_acquire_state (&err, dfa,
- &union_set);
- if (BE (mctx->state_log[next_idx] == NULL
- && err != REG_NOERROR, 0))
- {
- re_node_set_free (&union_set);
- return err;
- }
- }
- }
-#endif /* RE_ENABLE_I18N */
- if (naccepted
- || check_node_accept (mctx, dfa->nodes + cur_node, str_idx))
- {
- ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
- if (BE (! ok, 0))
- {
- re_node_set_free (&union_set);
- return REG_ESPACE;
- }
- }
- }
- re_node_set_free (&union_set);
- return REG_NOERROR;
-}
-
-/* For all the nodes in CUR_NODES, add the epsilon closures of them to
- CUR_NODES, however exclude the nodes which are:
- - inside the sub expression whose number is EX_SUBEXP, if FL_OPEN.
- - out of the sub expression whose number is EX_SUBEXP, if !FL_OPEN.
-*/
-
-static reg_errcode_t
-internal_function
-check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
- Idx ex_subexp, int type)
-{
- reg_errcode_t err;
- Idx idx, outside_node;
- re_node_set new_nodes;
-#ifdef DEBUG
- assert (cur_nodes->nelem);
-#endif
- err = re_node_set_alloc (&new_nodes, cur_nodes->nelem);
- if (BE (err != REG_NOERROR, 0))
- return err;
- /* Create a new node set NEW_NODES with the nodes which are epsilon
- closures of the node in CUR_NODES. */
-
- for (idx = 0; idx < cur_nodes->nelem; ++idx)
- {
- Idx cur_node = cur_nodes->elems[idx];
- const re_node_set *eclosure = dfa->eclosures + cur_node;
- outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
- if (outside_node == REG_MISSING)
- {
- /* There are no problematic nodes, just merge them. */
- err = re_node_set_merge (&new_nodes, eclosure);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&new_nodes);
- return err;
- }
- }
- else
- {
- /* There are problematic nodes, re-calculate incrementally. */
- err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node,
- ex_subexp, type);
- if (BE (err != REG_NOERROR, 0))
- {
- re_node_set_free (&new_nodes);
- return err;
- }
- }
- }
- re_node_set_free (cur_nodes);
- *cur_nodes = new_nodes;
- return REG_NOERROR;
-}
-
-/* Helper function for check_arrival_expand_ecl.
- Check incrementally the epsilon closure of TARGET, and if it isn't
- problematic append it to DST_NODES. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
- Idx target, Idx ex_subexp, int type)
-{
- Idx cur_node;
- for (cur_node = target; !re_node_set_contains (dst_nodes, cur_node);)
- {
- bool ok;
-
- if (dfa->nodes[cur_node].type == type
- && dfa->nodes[cur_node].opr.idx == ex_subexp)
- {
- if (type == OP_CLOSE_SUBEXP)
- {
- ok = re_node_set_insert (dst_nodes, cur_node);
- if (BE (! ok, 0))
- return REG_ESPACE;
- }
- break;
- }
- ok = re_node_set_insert (dst_nodes, cur_node);
- if (BE (! ok, 0))
- return REG_ESPACE;
- if (dfa->edests[cur_node].nelem == 0)
- break;
- if (dfa->edests[cur_node].nelem == 2)
- {
- reg_errcode_t err;
- err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
- dfa->edests[cur_node].elems[1],
- ex_subexp, type);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- cur_node = dfa->edests[cur_node].elems[0];
- }
- return REG_NOERROR;
-}
-
-
-/* For all the back references in the current state, calculate the
- destination of the back references by the appropriate entry
- in MCTX->BKREF_ENTS. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
- Idx cur_str, Idx subexp_num, int type)
-{
- const re_dfa_t *const dfa = mctx->dfa;
- reg_errcode_t err;
- Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
- struct re_backref_cache_entry *ent;
-
- if (cache_idx_start == REG_MISSING)
- return REG_NOERROR;
-
- restart:
- ent = mctx->bkref_ents + cache_idx_start;
- do
- {
- Idx to_idx, next_node;
-
- /* Is this entry ENT is appropriate? */
- if (!re_node_set_contains (cur_nodes, ent->node))
- continue; /* No. */
-
- to_idx = cur_str + ent->subexp_to - ent->subexp_from;
- /* Calculate the destination of the back reference, and append it
- to MCTX->STATE_LOG. */
- if (to_idx == cur_str)
- {
- /* The backreference did epsilon transit, we must re-check all the
- node in the current state. */
- re_node_set new_dests;
- reg_errcode_t err2, err3;
- next_node = dfa->edests[ent->node].elems[0];
- if (re_node_set_contains (cur_nodes, next_node))
- continue;
- err = re_node_set_init_1 (&new_dests, next_node);
- err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type);
- err3 = re_node_set_merge (cur_nodes, &new_dests);
- re_node_set_free (&new_dests);
- if (BE (err != REG_NOERROR || err2 != REG_NOERROR
- || err3 != REG_NOERROR, 0))
- {
- err = (err != REG_NOERROR ? err
- : (err2 != REG_NOERROR ? err2 : err3));
- return err;
- }
- /* TODO: It is still inefficient... */
- goto restart;
- }
- else
- {
- re_node_set union_set;
- next_node = dfa->nexts[ent->node];
- if (mctx->state_log[to_idx])
- {
- bool ok;
- if (re_node_set_contains (&mctx->state_log[to_idx]->nodes,
- next_node))
- continue;
- err = re_node_set_init_copy (&union_set,
- &mctx->state_log[to_idx]->nodes);
- ok = re_node_set_insert (&union_set, next_node);
- if (BE (err != REG_NOERROR || ! ok, 0))
- {
- re_node_set_free (&union_set);
- err = err != REG_NOERROR ? err : REG_ESPACE;
- return err;
- }
- }
- else
- {
- err = re_node_set_init_1 (&union_set, next_node);
- if (BE (err != REG_NOERROR, 0))
- return err;
- }
- mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set);
- re_node_set_free (&union_set);
- if (BE (mctx->state_log[to_idx] == NULL
- && err != REG_NOERROR, 0))
- return err;
- }
- }
- while (ent++->more);
- return REG_NOERROR;
-}
-
-/* Build transition table for the state.
- Return true if successful. */
-
-static bool
-internal_function
-build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
-{
- reg_errcode_t err;
- Idx i, j;
- int ch;
- bool need_word_trtable = false;
- bitset_word_t elem, mask;
- bool dests_node_malloced = false;
- bool dest_states_malloced = false;
- Idx ndests; /* Number of the destination states from 'state'. */
- re_dfastate_t **trtable;
- re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
- re_node_set follows, *dests_node;
- bitset_t *dests_ch;
- bitset_t acceptable;
-
- struct dests_alloc
- {
- re_node_set dests_node[SBC_MAX];
- bitset_t dests_ch[SBC_MAX];
- } *dests_alloc;
-
- /* We build DFA states which corresponds to the destination nodes
- from 'state'. 'dests_node[i]' represents the nodes which i-th
- destination state contains, and 'dests_ch[i]' represents the
- characters which i-th destination state accepts. */
- if (__libc_use_alloca (sizeof (struct dests_alloc)))
- dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc));
- else
- {
- dests_alloc = re_malloc (struct dests_alloc, 1);
- if (BE (dests_alloc == NULL, 0))
- return false;
- dests_node_malloced = true;
- }
- dests_node = dests_alloc->dests_node;
- dests_ch = dests_alloc->dests_ch;
-
- /* Initialize transition table. */
- state->word_trtable = state->trtable = NULL;
-
- /* At first, group all nodes belonging to 'state' into several
- destinations. */
- ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch);
- if (BE (! REG_VALID_NONZERO_INDEX (ndests), 0))
- {
- if (dests_node_malloced)
- free (dests_alloc);
- /* Return false in case of an error, true otherwise. */
- if (ndests == 0)
- {
- state->trtable = (re_dfastate_t **)
- calloc (sizeof (re_dfastate_t *), SBC_MAX);
- if (BE (state->trtable == NULL, 0))
- return false;
- return true;
- }
- return false;
- }
-
- err = re_node_set_alloc (&follows, ndests + 1);
- if (BE (err != REG_NOERROR, 0))
- goto out_free;
-
- /* Avoid arithmetic overflow in size calculation. */
- if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX)
- / (3 * sizeof (re_dfastate_t *)))
- < ndests),
- 0))
- goto out_free;
-
- if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX
- + ndests * 3 * sizeof (re_dfastate_t *)))
- dest_states = (re_dfastate_t **)
- alloca (ndests * 3 * sizeof (re_dfastate_t *));
- else
- {
- dest_states = (re_dfastate_t **)
- malloc (ndests * 3 * sizeof (re_dfastate_t *));
- if (BE (dest_states == NULL, 0))
- {
-out_free:
- if (dest_states_malloced)
- free (dest_states);
- re_node_set_free (&follows);
- for (i = 0; i < ndests; ++i)
- re_node_set_free (dests_node + i);
- if (dests_node_malloced)
- free (dests_alloc);
- return false;
- }
- dest_states_malloced = true;
- }
- dest_states_word = dest_states + ndests;
- dest_states_nl = dest_states_word + ndests;
- bitset_empty (acceptable);
-
- /* Then build the states for all destinations. */
- for (i = 0; i < ndests; ++i)
- {
- Idx next_node;
- re_node_set_empty (&follows);
- /* Merge the follows of this destination states. */
- for (j = 0; j < dests_node[i].nelem; ++j)
- {
- next_node = dfa->nexts[dests_node[i].elems[j]];
- if (next_node != REG_MISSING)
- {
- err = re_node_set_merge (&follows, dfa->eclosures + next_node);
- if (BE (err != REG_NOERROR, 0))
- goto out_free;
- }
- }
- dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0);
- if (BE (dest_states[i] == NULL && err != REG_NOERROR, 0))
- goto out_free;
- /* If the new state has context constraint,
- build appropriate states for these contexts. */
- if (dest_states[i]->has_constraint)
- {
- dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows,
- CONTEXT_WORD);
- if (BE (dest_states_word[i] == NULL && err != REG_NOERROR, 0))
- goto out_free;
-
- if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1)
- need_word_trtable = true;
-
- dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows,
- CONTEXT_NEWLINE);
- if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0))
- goto out_free;
- }
- else
- {
- dest_states_word[i] = dest_states[i];
- dest_states_nl[i] = dest_states[i];
- }
- bitset_merge (acceptable, dests_ch[i]);
- }
-
- if (!BE (need_word_trtable, 0))
- {
- /* We don't care about whether the following character is a word
- character, or we are in a single-byte character set so we can
- discern by looking at the character code: allocate a
- 256-entry transition table. */
- trtable = state->trtable =
- (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
- if (BE (trtable == NULL, 0))
- goto out_free;
-
- /* For all characters ch...: */
- for (i = 0; i < BITSET_WORDS; ++i)
- for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
- elem;
- mask <<= 1, elem >>= 1, ++ch)
- if (BE (elem & 1, 0))
- {
- /* There must be exactly one destination which accepts
- character ch. See group_nodes_into_DFAstates. */
- for (j = 0; (dests_ch[j][i] & mask) == 0; ++j)
- ;
-
- /* j-th destination accepts the word character ch. */
- if (dfa->word_char[i] & mask)
- trtable[ch] = dest_states_word[j];
- else
- trtable[ch] = dest_states[j];
- }
- }
- else
- {
- /* We care about whether the following character is a word
- character, and we are in a multi-byte character set: discern
- by looking at the character code: build two 256-entry
- transition tables, one starting at trtable[0] and one
- starting at trtable[SBC_MAX]. */
- trtable = state->word_trtable =
- (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
- if (BE (trtable == NULL, 0))
- goto out_free;
-
- /* For all characters ch...: */
- for (i = 0; i < BITSET_WORDS; ++i)
- for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
- elem;
- mask <<= 1, elem >>= 1, ++ch)
- if (BE (elem & 1, 0))
- {
- /* There must be exactly one destination which accepts
- character ch. See group_nodes_into_DFAstates. */
- for (j = 0; (dests_ch[j][i] & mask) == 0; ++j)
- ;
-
- /* j-th destination accepts the word character ch. */
- trtable[ch] = dest_states[j];
- trtable[ch + SBC_MAX] = dest_states_word[j];
- }
- }
-
- /* new line */
- if (bitset_contain (acceptable, NEWLINE_CHAR))
- {
- /* The current state accepts newline character. */
- for (j = 0; j < ndests; ++j)
- if (bitset_contain (dests_ch[j], NEWLINE_CHAR))
- {
- /* k-th destination accepts newline character. */
- trtable[NEWLINE_CHAR] = dest_states_nl[j];
- if (need_word_trtable)
- trtable[NEWLINE_CHAR + SBC_MAX] = dest_states_nl[j];
- /* There must be only one destination which accepts
- newline. See group_nodes_into_DFAstates. */
- break;
- }
- }
-
- if (dest_states_malloced)
- free (dest_states);
-
- re_node_set_free (&follows);
- for (i = 0; i < ndests; ++i)
- re_node_set_free (dests_node + i);
-
- if (dests_node_malloced)
- free (dests_alloc);
-
- return true;
-}
-
-/* Group all nodes belonging to STATE into several destinations.
- Then for all destinations, set the nodes belonging to the destination
- to DESTS_NODE[i] and set the characters accepted by the destination
- to DEST_CH[i]. This function return the number of destinations. */
-
-static Idx
-internal_function
-group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
- re_node_set *dests_node, bitset_t *dests_ch)
-{
- reg_errcode_t err;
- bool ok;
- Idx i, j, k;
- Idx ndests; /* Number of the destinations from 'state'. */
- bitset_t accepts; /* Characters a node can accept. */
- const re_node_set *cur_nodes = &state->nodes;
- bitset_empty (accepts);
- ndests = 0;
-
- /* For all the nodes belonging to 'state', */
- for (i = 0; i < cur_nodes->nelem; ++i)
- {
- re_token_t *node = &dfa->nodes[cur_nodes->elems[i]];
- re_token_type_t type = node->type;
- unsigned int constraint = node->constraint;
-
- /* Enumerate all single byte character this node can accept. */
- if (type == CHARACTER)
- bitset_set (accepts, node->opr.c);
- else if (type == SIMPLE_BRACKET)
- {
- bitset_merge (accepts, node->opr.sbcset);
- }
- else if (type == OP_PERIOD)
- {
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- bitset_merge (accepts, dfa->sb_char);
- else
-#endif
- bitset_set_all (accepts);
- if (!(dfa->syntax & RE_DOT_NEWLINE))
- bitset_clear (accepts, '\n');
- if (dfa->syntax & RE_DOT_NOT_NULL)
- bitset_clear (accepts, '\0');
- }
-#ifdef RE_ENABLE_I18N
- else if (type == OP_UTF8_PERIOD)
- {
- if (ASCII_CHARS % BITSET_WORD_BITS == 0)
- memset (accepts, -1, ASCII_CHARS / CHAR_BIT);
- else
- bitset_merge (accepts, utf8_sb_map);
- if (!(dfa->syntax & RE_DOT_NEWLINE))
- bitset_clear (accepts, '\n');
- if (dfa->syntax & RE_DOT_NOT_NULL)
- bitset_clear (accepts, '\0');
- }
-#endif
- else
- continue;
-
- /* Check the 'accepts' and sift the characters which are not
- match it the context. */
- if (constraint)
- {
- if (constraint & NEXT_NEWLINE_CONSTRAINT)
- {
- bool accepts_newline = bitset_contain (accepts, NEWLINE_CHAR);
- bitset_empty (accepts);
- if (accepts_newline)
- bitset_set (accepts, NEWLINE_CHAR);
- else
- continue;
- }
- if (constraint & NEXT_ENDBUF_CONSTRAINT)
- {
- bitset_empty (accepts);
- continue;
- }
-
- if (constraint & NEXT_WORD_CONSTRAINT)
- {
- bitset_word_t any_set = 0;
- if (type == CHARACTER && !node->word_char)
- {
- bitset_empty (accepts);
- continue;
- }
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- for (j = 0; j < BITSET_WORDS; ++j)
- any_set |= (accepts[j] &= (dfa->word_char[j] | ~dfa->sb_char[j]));
- else
-#endif
- for (j = 0; j < BITSET_WORDS; ++j)
- any_set |= (accepts[j] &= dfa->word_char[j]);
- if (!any_set)
- continue;
- }
- if (constraint & NEXT_NOTWORD_CONSTRAINT)
- {
- bitset_word_t any_set = 0;
- if (type == CHARACTER && node->word_char)
- {
- bitset_empty (accepts);
- continue;
- }
-#ifdef RE_ENABLE_I18N
- if (dfa->mb_cur_max > 1)
- for (j = 0; j < BITSET_WORDS; ++j)
- any_set |= (accepts[j] &= ~(dfa->word_char[j] & dfa->sb_char[j]));
- else
-#endif
- for (j = 0; j < BITSET_WORDS; ++j)
- any_set |= (accepts[j] &= ~dfa->word_char[j]);
- if (!any_set)
- continue;
- }
- }
-
- /* Then divide 'accepts' into DFA states, or create a new
- state. Above, we make sure that accepts is not empty. */
- for (j = 0; j < ndests; ++j)
- {
- bitset_t intersec; /* Intersection sets, see below. */
- bitset_t remains;
- /* Flags, see below. */
- bitset_word_t has_intersec, not_subset, not_consumed;
-
- /* Optimization, skip if this state doesn't accept the character. */
- if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c))
- continue;
-
- /* Enumerate the intersection set of this state and 'accepts'. */
- has_intersec = 0;
- for (k = 0; k < BITSET_WORDS; ++k)
- has_intersec |= intersec[k] = accepts[k] & dests_ch[j][k];
- /* And skip if the intersection set is empty. */
- if (!has_intersec)
- continue;
-
- /* Then check if this state is a subset of 'accepts'. */
- not_subset = not_consumed = 0;
- for (k = 0; k < BITSET_WORDS; ++k)
- {
- not_subset |= remains[k] = ~accepts[k] & dests_ch[j][k];
- not_consumed |= accepts[k] = accepts[k] & ~dests_ch[j][k];
- }
-
- /* If this state isn't a subset of 'accepts', create a
- new group state, which has the 'remains'. */
- if (not_subset)
- {
- bitset_copy (dests_ch[ndests], remains);
- bitset_copy (dests_ch[j], intersec);
- err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]);
- if (BE (err != REG_NOERROR, 0))
- goto error_return;
- ++ndests;
- }
-
- /* Put the position in the current group. */
- ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
- if (BE (! ok, 0))
- goto error_return;
-
- /* If all characters are consumed, go to next node. */
- if (!not_consumed)
- break;
- }
- /* Some characters remain, create a new group. */
- if (j == ndests)
- {
- bitset_copy (dests_ch[ndests], accepts);
- err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]);
- if (BE (err != REG_NOERROR, 0))
- goto error_return;
- ++ndests;
- bitset_empty (accepts);
- }
- }
- return ndests;
- error_return:
- for (j = 0; j < ndests; ++j)
- re_node_set_free (dests_node + j);
- return REG_MISSING;
-}
-
-#ifdef RE_ENABLE_I18N
-/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts.
- Return the number of the bytes the node accepts.
- STR_IDX is the current index of the input string.
-
- This function handles the nodes which can accept one character, or
- one collating element like '.', '[a-z]', opposite to the other nodes
- can only accept one byte. */
-
-static int
-internal_function
-check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
- const re_string_t *input, Idx str_idx)
-{
- const re_token_t *node = dfa->nodes + node_idx;
- int char_len, elem_len;
- Idx i;
-
- if (BE (node->type == OP_UTF8_PERIOD, 0))
- {
- unsigned char c = re_string_byte_at (input, str_idx), d;
- if (BE (c < 0xc2, 1))
- return 0;
-
- if (str_idx + 2 > input->len)
- return 0;
-
- d = re_string_byte_at (input, str_idx + 1);
- if (c < 0xe0)
- return (d < 0x80 || d > 0xbf) ? 0 : 2;
- else if (c < 0xf0)
- {
- char_len = 3;
- if (c == 0xe0 && d < 0xa0)
- return 0;
- }
- else if (c < 0xf8)
- {
- char_len = 4;
- if (c == 0xf0 && d < 0x90)
- return 0;
- }
- else if (c < 0xfc)
- {
- char_len = 5;
- if (c == 0xf8 && d < 0x88)
- return 0;
- }
- else if (c < 0xfe)
- {
- char_len = 6;
- if (c == 0xfc && d < 0x84)
- return 0;
- }
- else
- return 0;
-
- if (str_idx + char_len > input->len)
- return 0;
-
- for (i = 1; i < char_len; ++i)
- {
- d = re_string_byte_at (input, str_idx + i);
- if (d < 0x80 || d > 0xbf)
- return 0;
- }
- return char_len;
- }
-
- char_len = re_string_char_size_at (input, str_idx);
- if (node->type == OP_PERIOD)
- {
- if (char_len <= 1)
- return 0;
- /* FIXME: I don't think this if is needed, as both '\n'
- and '\0' are char_len == 1. */
- /* '.' accepts any one character except the following two cases. */
- if ((!(dfa->syntax & RE_DOT_NEWLINE) &&
- re_string_byte_at (input, str_idx) == '\n') ||
- ((dfa->syntax & RE_DOT_NOT_NULL) &&
- re_string_byte_at (input, str_idx) == '\0'))
- return 0;
- return char_len;
- }
-
- elem_len = re_string_elem_size_at (input, str_idx);
- if ((elem_len <= 1 && char_len <= 1) || char_len == 0)
- return 0;
-
- if (node->type == COMPLEX_BRACKET)
- {
- const re_charset_t *cset = node->opr.mbcset;
-# ifdef _LIBC
- const unsigned char *pin
- = ((const unsigned char *) re_string_get_buffer (input) + str_idx);
- Idx j;
- uint32_t nrules;
-# endif /* _LIBC */
- int match_len = 0;
- wchar_t wc = ((cset->nranges || cset->nchar_classes || cset->nmbchars)
- ? re_string_wchar_at (input, str_idx) : 0);
-
- /* match with multibyte character? */
- for (i = 0; i < cset->nmbchars; ++i)
- if (wc == cset->mbchars[i])
- {
- match_len = char_len;
- goto check_node_accept_bytes_match;
- }
- /* match with character_class? */
- for (i = 0; i < cset->nchar_classes; ++i)
- {
- wctype_t wt = cset->char_classes[i];
- if (__iswctype (wc, wt))
- {
- match_len = char_len;
- goto check_node_accept_bytes_match;
- }
- }
-
-# ifdef _LIBC
- nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
- if (nrules != 0)
- {
- unsigned int in_collseq = 0;
- const int32_t *table, *indirect;
- const unsigned char *weights, *extra;
- const char *collseqwc;
- /* This #include defines a local function! */
-# include <locale/weight.h>
-
- /* match with collating_symbol? */
- if (cset->ncoll_syms)
- extra = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
- for (i = 0; i < cset->ncoll_syms; ++i)
- {
- const unsigned char *coll_sym = extra + cset->coll_syms[i];
- /* Compare the length of input collating element and
- the length of current collating element. */
- if (*coll_sym != elem_len)
- continue;
- /* Compare each bytes. */
- for (j = 0; j < *coll_sym; j++)
- if (pin[j] != coll_sym[1 + j])
- break;
- if (j == *coll_sym)
- {
- /* Match if every bytes is equal. */
- match_len = j;
- goto check_node_accept_bytes_match;
- }
- }
-
- if (cset->nranges)
- {
- if (elem_len <= char_len)
- {
- collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
- in_collseq = __collseq_table_lookup (collseqwc, wc);
- }
- else
- in_collseq = find_collation_sequence_value (pin, elem_len);
- }
- /* match with range expression? */
- /* FIXME: Implement rational ranges here, too. */
- for (i = 0; i < cset->nranges; ++i)
- if (cset->range_starts[i] <= in_collseq
- && in_collseq <= cset->range_ends[i])
- {
- match_len = elem_len;
- goto check_node_accept_bytes_match;
- }
-
- /* match with equivalence_class? */
- if (cset->nequiv_classes)
- {
- const unsigned char *cp = pin;
- table = (const int32_t *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
- weights = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB);
- extra = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
- indirect = (const int32_t *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
- int32_t idx = findidx (&cp, elem_len);
- if (idx > 0)
- for (i = 0; i < cset->nequiv_classes; ++i)
- {
- int32_t equiv_class_idx = cset->equiv_classes[i];
- size_t weight_len = weights[idx & 0xffffff];
- if (weight_len == weights[equiv_class_idx & 0xffffff]
- && (idx >> 24) == (equiv_class_idx >> 24))
- {
- Idx cnt = 0;
-
- idx &= 0xffffff;
- equiv_class_idx &= 0xffffff;
-
- while (cnt <= weight_len
- && (weights[equiv_class_idx + 1 + cnt]
- == weights[idx + 1 + cnt]))
- ++cnt;
- if (cnt > weight_len)
- {
- match_len = elem_len;
- goto check_node_accept_bytes_match;
- }
- }
- }
- }
- }
- else
-# endif /* _LIBC */
- {
- /* match with range expression? */
- for (i = 0; i < cset->nranges; ++i)
- {
- if (cset->range_starts[i] <= wc && wc <= cset->range_ends[i])
- {
- match_len = char_len;
- goto check_node_accept_bytes_match;
- }
- }
- }
- check_node_accept_bytes_match:
- if (!cset->non_match)
- return match_len;
- else
- {
- if (match_len > 0)
- return 0;
- else
- return (elem_len > char_len) ? elem_len : char_len;
- }
- }
- return 0;
-}
-
-# ifdef _LIBC
-static unsigned int
-internal_function
-find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
-{
- uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
- if (nrules == 0)
- {
- if (mbs_len == 1)
- {
- /* No valid character. Match it as a single byte character. */
- const unsigned char *collseq = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
- return collseq[mbs[0]];
- }
- return UINT_MAX;
- }
- else
- {
- int32_t idx;
- const unsigned char *extra = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
- int32_t extrasize = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB + 1) - extra;
-
- for (idx = 0; idx < extrasize;)
- {
- int mbs_cnt;
- bool found = false;
- int32_t elem_mbs_len;
- /* Skip the name of collating element name. */
- idx = idx + extra[idx] + 1;
- elem_mbs_len = extra[idx++];
- if (mbs_len == elem_mbs_len)
- {
- for (mbs_cnt = 0; mbs_cnt < elem_mbs_len; ++mbs_cnt)
- if (extra[idx + mbs_cnt] != mbs[mbs_cnt])
- break;
- if (mbs_cnt == elem_mbs_len)
- /* Found the entry. */
- found = true;
- }
- /* Skip the byte sequence of the collating element. */
- idx += elem_mbs_len;
- /* Adjust for the alignment. */
- idx = (idx + 3) & ~3;
- /* Skip the collation sequence value. */
- idx += sizeof (uint32_t);
- /* Skip the wide char sequence of the collating element. */
- idx = idx + sizeof (uint32_t) * (*(int32_t *) (extra + idx) + 1);
- /* If we found the entry, return the sequence value. */
- if (found)
- return *(uint32_t *) (extra + idx);
- /* Skip the collation sequence value. */
- idx += sizeof (uint32_t);
- }
- return UINT_MAX;
- }
-}
-# endif /* _LIBC */
-#endif /* RE_ENABLE_I18N */
-
-/* Check whether the node accepts the byte which is IDX-th
- byte of the INPUT. */
-
-static bool
-internal_function
-check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
- Idx idx)
-{
- unsigned char ch;
- ch = re_string_byte_at (&mctx->input, idx);
- switch (node->type)
- {
- case CHARACTER:
- if (node->opr.c != ch)
- return false;
- break;
-
- case SIMPLE_BRACKET:
- if (!bitset_contain (node->opr.sbcset, ch))
- return false;
- break;
-
-#ifdef RE_ENABLE_I18N
- case OP_UTF8_PERIOD:
- if (ch >= ASCII_CHARS)
- return false;
- /* FALLTHROUGH */
-#endif
- case OP_PERIOD:
- if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
- || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
- return false;
- break;
-
- default:
- return false;
- }
-
- if (node->constraint)
- {
- /* The node has constraints. Check whether the current context
- satisfies the constraints. */
- unsigned int context = re_string_context_at (&mctx->input, idx,
- mctx->eflags);
- if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
- return false;
- }
-
- return true;
-}
-
-/* Extend the buffers, if the buffers have run out. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-extend_buffers (re_match_context_t *mctx, int min_len)
-{
- reg_errcode_t ret;
- re_string_t *pstr = &mctx->input;
-
- /* Avoid overflow. */
- if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2
- <= pstr->bufs_len, 0))
- return REG_ESPACE;
-
- /* Double the lengths of the buffers, but allocate at least MIN_LEN. */
- ret = re_string_realloc_buffers (pstr,
- MAX (min_len,
- MIN (pstr->len, pstr->bufs_len * 2)));
- if (BE (ret != REG_NOERROR, 0))
- return ret;
-
- if (mctx->state_log != NULL)
- {
- /* And double the length of state_log. */
- /* XXX We have no indication of the size of this buffer. If this
- allocation fail we have no indication that the state_log array
- does not have the right size. */
- re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *,
- pstr->bufs_len + 1);
- if (BE (new_array == NULL, 0))
- return REG_ESPACE;
- mctx->state_log = new_array;
- }
-
- /* Then reconstruct the buffers. */
- if (pstr->icase)
- {
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1)
- {
- ret = build_wcs_upper_buffer (pstr);
- if (BE (ret != REG_NOERROR, 0))
- return ret;
- }
- else
-#endif /* RE_ENABLE_I18N */
- build_upper_buffer (pstr);
- }
- else
- {
-#ifdef RE_ENABLE_I18N
- if (pstr->mb_cur_max > 1)
- build_wcs_buffer (pstr);
- else
-#endif /* RE_ENABLE_I18N */
- {
- if (pstr->trans != NULL)
- re_string_translate_buffer (pstr);
- }
- }
- return REG_NOERROR;
-}
-
-
-/* Functions for matching context. */
-
-/* Initialize MCTX. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
-{
- mctx->eflags = eflags;
- mctx->match_last = REG_MISSING;
- if (n > 0)
- {
- /* Avoid overflow. */
- size_t max_object_size =
- MAX (sizeof (struct re_backref_cache_entry),
- sizeof (re_sub_match_top_t *));
- if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n, 0))
- return REG_ESPACE;
-
- mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
- mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
- if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0))
- return REG_ESPACE;
- }
- /* Already zero-ed by the caller.
- else
- mctx->bkref_ents = NULL;
- mctx->nbkref_ents = 0;
- mctx->nsub_tops = 0; */
- mctx->abkref_ents = n;
- mctx->max_mb_elem_len = 1;
- mctx->asub_tops = n;
- return REG_NOERROR;
-}
-
-/* Clean the entries which depend on the current input in MCTX.
- This function must be invoked when the matcher changes the start index
- of the input, or changes the input string. */
-
-static void
-internal_function
-match_ctx_clean (re_match_context_t *mctx)
-{
- Idx st_idx;
- for (st_idx = 0; st_idx < mctx->nsub_tops; ++st_idx)
- {
- Idx sl_idx;
- re_sub_match_top_t *top = mctx->sub_tops[st_idx];
- for (sl_idx = 0; sl_idx < top->nlasts; ++sl_idx)
- {
- re_sub_match_last_t *last = top->lasts[sl_idx];
- re_free (last->path.array);
- re_free (last);
- }
- re_free (top->lasts);
- if (top->path)
- {
- re_free (top->path->array);
- re_free (top->path);
- }
- free (top);
- }
-
- mctx->nsub_tops = 0;
- mctx->nbkref_ents = 0;
-}
-
-/* Free all the memory associated with MCTX. */
-
-static void
-internal_function
-match_ctx_free (re_match_context_t *mctx)
-{
- /* First, free all the memory associated with MCTX->SUB_TOPS. */
- match_ctx_clean (mctx);
- re_free (mctx->sub_tops);
- re_free (mctx->bkref_ents);
-}
-
-/* Add a new backreference entry to MCTX.
- Note that we assume that caller never call this function with duplicate
- entry, and call with STR_IDX which isn't smaller than any existing entry.
-*/
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
- Idx to)
-{
- if (mctx->nbkref_ents >= mctx->abkref_ents)
- {
- struct re_backref_cache_entry* new_entry;
- new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry,
- mctx->abkref_ents * 2);
- if (BE (new_entry == NULL, 0))
- {
- re_free (mctx->bkref_ents);
- return REG_ESPACE;
- }
- mctx->bkref_ents = new_entry;
- memset (mctx->bkref_ents + mctx->nbkref_ents, '\0',
- sizeof (struct re_backref_cache_entry) * mctx->abkref_ents);
- mctx->abkref_ents *= 2;
- }
- if (mctx->nbkref_ents > 0
- && mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx)
- mctx->bkref_ents[mctx->nbkref_ents - 1].more = 1;
-
- mctx->bkref_ents[mctx->nbkref_ents].node = node;
- mctx->bkref_ents[mctx->nbkref_ents].str_idx = str_idx;
- mctx->bkref_ents[mctx->nbkref_ents].subexp_from = from;
- mctx->bkref_ents[mctx->nbkref_ents].subexp_to = to;
-
- /* This is a cache that saves negative results of check_dst_limits_calc_pos.
- If bit N is clear, means that this entry won't epsilon-transition to
- an OP_OPEN_SUBEXP or OP_CLOSE_SUBEXP for the N+1-th subexpression. If
- it is set, check_dst_limits_calc_pos_1 will recurse and try to find one
- such node.
-
- A backreference does not epsilon-transition unless it is empty, so set
- to all zeros if FROM != TO. */
- mctx->bkref_ents[mctx->nbkref_ents].eps_reachable_subexps_map
- = (from == to ? -1 : 0);
-
- mctx->bkref_ents[mctx->nbkref_ents++].more = 0;
- if (mctx->max_mb_elem_len < to - from)
- mctx->max_mb_elem_len = to - from;
- return REG_NOERROR;
-}
-
-/* Return the first entry with the same str_idx, or REG_MISSING if none is
- found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */
-
-static Idx
-internal_function
-search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
-{
- Idx left, right, mid, last;
- last = right = mctx->nbkref_ents;
- for (left = 0; left < right;)
- {
- mid = (left + right) / 2;
- if (mctx->bkref_ents[mid].str_idx < str_idx)
- left = mid + 1;
- else
- right = mid;
- }
- if (left < last && mctx->bkref_ents[left].str_idx == str_idx)
- return left;
- else
- return REG_MISSING;
-}
-
-/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches
- at STR_IDX. */
-
-static reg_errcode_t
-internal_function __attribute_warn_unused_result__
-match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
-{
-#ifdef DEBUG
- assert (mctx->sub_tops != NULL);
- assert (mctx->asub_tops > 0);
-#endif
- if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
- {
- Idx new_asub_tops = mctx->asub_tops * 2;
- re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
- re_sub_match_top_t *,
- new_asub_tops);
- if (BE (new_array == NULL, 0))
- return REG_ESPACE;
- mctx->sub_tops = new_array;
- mctx->asub_tops = new_asub_tops;
- }
- mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t));
- if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0))
- return REG_ESPACE;
- mctx->sub_tops[mctx->nsub_tops]->node = node;
- mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx;
- return REG_NOERROR;
-}
-
-/* Register the node NODE, whose type is OP_CLOSE_SUBEXP, and which matches
- at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP. */
-
-static re_sub_match_last_t *
-internal_function
-match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
-{
- re_sub_match_last_t *new_entry;
- if (BE (subtop->nlasts == subtop->alasts, 0))
- {
- Idx new_alasts = 2 * subtop->alasts + 1;
- re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
- re_sub_match_last_t *,
- new_alasts);
- if (BE (new_array == NULL, 0))
- return NULL;
- subtop->lasts = new_array;
- subtop->alasts = new_alasts;
- }
- new_entry = calloc (1, sizeof (re_sub_match_last_t));
- if (BE (new_entry != NULL, 1))
- {
- subtop->lasts[subtop->nlasts] = new_entry;
- new_entry->node = node;
- new_entry->str_idx = str_idx;
- ++subtop->nlasts;
- }
- return new_entry;
-}
-
-static void
-internal_function
-sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
- re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
-{
- sctx->sifted_states = sifted_sts;
- sctx->limited_states = limited_sts;
- sctx->last_node = last_node;
- sctx->last_str_idx = last_str_idx;
- re_node_set_init_empty (&sctx->limits);
-}
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
+ Idx n) internal_function;
+static void match_ctx_clean (re_match_context_t *mctx) internal_function;
+static void match_ctx_free (re_match_context_t *cache) internal_function;
+static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node,
+ Idx str_idx, Idx from, Idx to)
+ internal_function;
+static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
+ internal_function;
+static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node,
+ Idx str_idx) internal_function;
+static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop,
+ Idx node, Idx str_idx)
+ internal_function;
+static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
+ re_dfastate_t **limited_sts, Idx last_node,
+ Idx last_str_idx)
+ internal_function;
+static reg_errcode_t re_search_internal (const regex_t *preg,
+ const char *string, Idx length,
+ Idx start, Idx last_start, Idx stop,
+ size_t nmatch, regmatch_t pmatch[],
+ int eflags) internal_function;
+static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp,
+ const char *string1, Idx length1,
+ const char *string2, Idx length2,
+ Idx start, regoff_t range,
+ struct re_registers *regs,
+ Idx stop, bool ret_len) internal_function;
+static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
+ const char *string, Idx length, Idx start,
+ regoff_t range, Idx stop,
+ struct re_registers *regs,
+ bool ret_len) internal_function;
+static unsigned re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
+ Idx nregs, int regs_allocated) internal_function;
+static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
+ internal_function;
+static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
+ Idx *p_match_first) internal_function;
+static Idx check_halt_state_context (const re_match_context_t *mctx,
+ const re_dfastate_t *state, Idx idx)
+ internal_function;
+static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
+ regmatch_t *prev_idx_match, Idx cur_node,
+ Idx cur_idx, Idx nmatch) internal_function;
+static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
+ Idx str_idx, Idx dest_node, Idx nregs,
+ regmatch_t *regs,
+ re_node_set *eps_via_nodes)
+ internal_function;
+static reg_errcode_t set_regs (const regex_t *preg,
+ const re_match_context_t *mctx,
+ size_t nmatch, regmatch_t *pmatch,
+ bool fl_backtrack) internal_function;
+static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs)
+ internal_function;
+
+#ifdef RE_ENABLE_I18N
+static int sift_states_iter_mb (const re_match_context_t *mctx,
+ re_sift_context_t *sctx,
+ Idx node_idx, Idx str_idx, Idx max_str_idx)
+ internal_function;
+#endif /* RE_ENABLE_I18N */
+static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
+ re_sift_context_t *sctx)
+ internal_function;
+static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
+ re_sift_context_t *sctx, Idx str_idx,
+ re_node_set *cur_dest)
+ internal_function;
+static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
+ re_sift_context_t *sctx,
+ Idx str_idx,
+ re_node_set *dest_nodes)
+ internal_function;
+static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
+ re_node_set *dest_nodes,
+ const re_node_set *candidates)
+ internal_function;
+static bool check_dst_limits (const re_match_context_t *mctx,
+ const re_node_set *limits,
+ Idx dst_node, Idx dst_idx, Idx src_node,
+ Idx src_idx) internal_function;
+static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
+ int boundaries, Idx subexp_idx,
+ Idx from_node, Idx bkref_idx)
+ internal_function;
+static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
+ Idx limit, Idx subexp_idx,
+ Idx node, Idx str_idx,
+ Idx bkref_idx) internal_function;
+static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
+ re_node_set *dest_nodes,
+ const re_node_set *candidates,
+ re_node_set *limits,
+ struct re_backref_cache_entry *bkref_ents,
+ Idx str_idx) internal_function;
+static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
+ re_sift_context_t *sctx,
+ Idx str_idx, const re_node_set *candidates)
+ internal_function;
+static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
+ re_dfastate_t **dst,
+ re_dfastate_t **src, Idx num)
+ internal_function;
+static re_dfastate_t *find_recover_state (reg_errcode_t *err,
+ re_match_context_t *mctx) internal_function;
+static re_dfastate_t *transit_state (reg_errcode_t *err,
+ re_match_context_t *mctx,
+ re_dfastate_t *state) internal_function;
+static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
+ re_match_context_t *mctx,
+ re_dfastate_t *next_state)
+ internal_function;
+static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
+ re_node_set *cur_nodes,
+ Idx str_idx) internal_function;
+#if 0
+static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
+ re_match_context_t *mctx,
+ re_dfastate_t *pstate)
+ internal_function;
+#endif
+#ifdef RE_ENABLE_I18N
+static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
+ re_dfastate_t *pstate)
+ internal_function;
+#endif /* RE_ENABLE_I18N */
+static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
+ const re_node_set *nodes)
+ internal_function;
+static reg_errcode_t get_subexp (re_match_context_t *mctx,
+ Idx bkref_node, Idx bkref_str_idx)
+ internal_function;
+static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
+ const re_sub_match_top_t *sub_top,
+ re_sub_match_last_t *sub_last,
+ Idx bkref_node, Idx bkref_str)
+ internal_function;
+static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
+ Idx subexp_idx, int type) internal_function;
+static reg_errcode_t check_arrival (re_match_context_t *mctx,
+ state_array_t *path, Idx top_node,
+ Idx top_str, Idx last_node, Idx last_str,
+ int type) internal_function;
+static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
+ Idx str_idx,
+ re_node_set *cur_nodes,
+ re_node_set *next_nodes)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
+ re_node_set *cur_nodes,
+ Idx ex_subexp, int type)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
+ re_node_set *dst_nodes,
+ Idx target, Idx ex_subexp,
+ int type) internal_function;
+static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
+ re_node_set *cur_nodes, Idx cur_str,
+ Idx subexp_num, int type)
+ internal_function;
+static bool build_trtable (const re_dfa_t *dfa,
+ re_dfastate_t *state) internal_function;
+#ifdef RE_ENABLE_I18N
+static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
+ const re_string_t *input, Idx idx)
+ internal_function;
+# ifdef _LIBC
+static unsigned int find_collation_sequence_value (const unsigned char *mbs,
+ size_t name_len)
+ internal_function;
+# endif /* _LIBC */
+#endif /* RE_ENABLE_I18N */
+static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
+ const re_dfastate_t *state,
+ re_node_set *states_node,
+ bitset_t *states_ch) internal_function;
+static bool check_node_accept (const re_match_context_t *mctx,
+ const re_token_t *node, Idx idx)
+ internal_function;
+static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len)
+ internal_function;
+
+/* Entry point for POSIX code. */
+
+/* regexec searches for a given pattern, specified by PREG, in the
+ string STRING.
+
+ If NMATCH is zero or REG_NOSUB was set in the cflags argument to
+ 'regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
+ least NMATCH elements, and we set them to the offsets of the
+ corresponding matched substrings.
+
+ EFLAGS specifies "execution flags" which affect matching: if
+ REG_NOTBOL is set, then ^ does not match at the beginning of the
+ string; if REG_NOTEOL is set, then $ does not match at the end.
+
+ We return 0 if we find a match and REG_NOMATCH if not. */
+
+int
+regexec (preg, string, nmatch, pmatch, eflags)
+ const regex_t *_Restrict_ preg;
+ const char *_Restrict_ string;
+ size_t nmatch;
+ regmatch_t pmatch[_Restrict_arr_];
+ int eflags;
+{
+ reg_errcode_t err;
+ Idx start, length;
+ re_dfa_t *dfa = preg->buffer;
+
+ if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
+ return REG_BADPAT;
+
+ if (eflags & REG_STARTEND)
+ {
+ start = pmatch[0].rm_so;
+ length = pmatch[0].rm_eo;
+ }
+ else
+ {
+ start = 0;
+ length = strlen (string);
+ }
+
+ lock_lock (dfa->lock);
+ if (preg->no_sub)
+ err = re_search_internal (preg, string, length, start, length,
+ length, 0, NULL, eflags);
+ else
+ err = re_search_internal (preg, string, length, start, length,
+ length, nmatch, pmatch, eflags);
+ lock_unlock (dfa->lock);
+ return err != REG_NOERROR;
+}
+
+#ifdef _LIBC
+# include <shlib-compat.h>
+versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4);
+
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
+__typeof__ (__regexec) __compat_regexec;
+
+int
+attribute_compat_text_section
+__compat_regexec (const regex_t *_Restrict_ preg,
+ const char *_Restrict_ string, size_t nmatch,
+ regmatch_t pmatch[], int eflags)
+{
+ return regexec (preg, string, nmatch, pmatch,
+ eflags & (REG_NOTBOL | REG_NOTEOL));
+}
+compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
+# endif
+#endif
+
+/* Entry points for GNU code. */
+
+/* re_match, re_search, re_match_2, re_search_2
+
+ The former two functions operate on STRING with length LENGTH,
+ while the later two operate on concatenation of STRING1 and STRING2
+ with lengths LENGTH1 and LENGTH2, respectively.
+
+ re_match() matches the compiled pattern in BUFP against the string,
+ starting at index START.
+
+ re_search() first tries matching at index START, then it tries to match
+ starting from index START + 1, and so on. The last start position tried
+ is START + RANGE. (Thus RANGE = 0 forces re_search to operate the same
+ way as re_match().)
+
+ The parameter STOP of re_{match,search}_2 specifies that no match exceeding
+ the first STOP characters of the concatenation of the strings should be
+ concerned.
+
+ If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match
+ and all groups is stored in REGS. (For the "_2" variants, the offsets are
+ computed relative to the concatenation, not relative to the individual
+ strings.)
+
+ On success, re_match* functions return the length of the match, re_search*
+ return the position of the start of the match. Return value -1 means no
+ match was found and -2 indicates an internal error. */
+
+regoff_t
+re_match (bufp, string, length, start, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ Idx length, start;
+ struct re_registers *regs;
+{
+ return re_search_stub (bufp, string, length, start, 0, length, regs, true);
+}
+#ifdef _LIBC
+weak_alias (__re_match, re_match)
+#endif
+
+regoff_t
+re_search (bufp, string, length, start, range, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ Idx length, start;
+ regoff_t range;
+ struct re_registers *regs;
+{
+ return re_search_stub (bufp, string, length, start, range, length, regs,
+ false);
+}
+#ifdef _LIBC
+weak_alias (__re_search, re_search)
+#endif
+
+regoff_t
+re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ Idx length1, length2, start, stop;
+ struct re_registers *regs;
+{
+ return re_search_2_stub (bufp, string1, length1, string2, length2,
+ start, 0, regs, stop, true);
+}
+#ifdef _LIBC
+weak_alias (__re_match_2, re_match_2)
+#endif
+
+regoff_t
+re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ Idx length1, length2, start, stop;
+ regoff_t range;
+ struct re_registers *regs;
+{
+ return re_search_2_stub (bufp, string1, length1, string2, length2,
+ start, range, regs, stop, false);
+}
+#ifdef _LIBC
+weak_alias (__re_search_2, re_search_2)
+#endif
+
+static regoff_t
+re_search_2_stub (struct re_pattern_buffer *bufp,
+ const char *string1, Idx length1,
+ const char *string2, Idx length2,
+ Idx start, regoff_t range, struct re_registers *regs,
+ Idx stop, bool ret_len)
+{
+ const char *str;
+ regoff_t rval;
+ Idx len = length1 + length2;
+ char *s = NULL;
+
+ if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0))
+ return -2;
+
+ /* Concatenate the strings. */
+ if (length2 > 0)
+ if (length1 > 0)
+ {
+ s = re_malloc (char, len);
+
+ if (BE (s == NULL, 0))
+ return -2;
+#ifdef _LIBC
+ memcpy (__mempcpy (s, string1, length1), string2, length2);
+#else
+ memcpy (s, string1, length1);
+ memcpy (s + length1, string2, length2);
+#endif
+ str = s;
+ }
+ else
+ str = string2;
+ else
+ str = string1;
+
+ rval = re_search_stub (bufp, str, len, start, range, stop, regs,
+ ret_len);
+ re_free (s);
+ return rval;
+}
+
+/* The parameters have the same meaning as those of re_search.
+ Additional parameters:
+ If RET_LEN is true the length of the match is returned (re_match style);
+ otherwise the position of the match is returned. */
+
+static regoff_t
+re_search_stub (struct re_pattern_buffer *bufp,
+ const char *string, Idx length,
+ Idx start, regoff_t range, Idx stop, struct re_registers *regs,
+ bool ret_len)
+{
+ reg_errcode_t result;
+ regmatch_t *pmatch;
+ Idx nregs;
+ regoff_t rval;
+ int eflags = 0;
+ re_dfa_t *dfa = bufp->buffer;
+ Idx last_start = start + range;
+
+ /* Check for out-of-range. */
+ if (BE (start < 0 || start > length, 0))
+ return -1;
+ if (BE (length < last_start || (0 <= range && last_start < start), 0))
+ last_start = length;
+ else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0))
+ last_start = 0;
+
+ lock_lock (dfa->lock);
+
+ eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
+ eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
+
+ /* Compile fastmap if we haven't yet. */
+ if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
+ re_compile_fastmap (bufp);
+
+ if (BE (bufp->no_sub, 0))
+ regs = NULL;
+
+ /* We need at least 1 register. */
+ if (regs == NULL)
+ nregs = 1;
+ else if (BE (bufp->regs_allocated == REGS_FIXED
+ && regs->num_regs <= bufp->re_nsub, 0))
+ {
+ nregs = regs->num_regs;
+ if (BE (nregs < 1, 0))
+ {
+ /* Nothing can be copied to regs. */
+ regs = NULL;
+ nregs = 1;
+ }
+ }
+ else
+ nregs = bufp->re_nsub + 1;
+ pmatch = re_malloc (regmatch_t, nregs);
+ if (BE (pmatch == NULL, 0))
+ {
+ rval = -2;
+ goto out;
+ }
+
+ result = re_search_internal (bufp, string, length, start, last_start, stop,
+ nregs, pmatch, eflags);
+
+ rval = 0;
+
+ /* I hope we needn't fill their regs with -1's when no match was found. */
+ if (result != REG_NOERROR)
+ rval = result == REG_NOMATCH ? -1 : -2;
+ else if (regs != NULL)
+ {
+ /* If caller wants register contents data back, copy them. */
+ bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
+ bufp->regs_allocated);
+ if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0))
+ rval = -2;
+ }
+
+ if (BE (rval == 0, 1))
+ {
+ if (ret_len)
+ {
+ assert (pmatch[0].rm_so == start);
+ rval = pmatch[0].rm_eo - start;
+ }
+ else
+ rval = pmatch[0].rm_so;
+ }
+ re_free (pmatch);
+ out:
+ lock_unlock (dfa->lock);
+ return rval;
+}
+
+static unsigned
+re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
+ int regs_allocated)
+{
+ int rval = REGS_REALLOCATE;
+ Idx i;
+ Idx need_regs = nregs + 1;
+ /* We need one extra element beyond 'num_regs' for the '-1' marker GNU code
+ uses. */
+
+ /* Have the register data arrays been allocated? */
+ if (regs_allocated == REGS_UNALLOCATED)
+ { /* No. So allocate them with malloc. */
+ regs->start = re_malloc (regoff_t, need_regs);
+ if (BE (regs->start == NULL, 0))
+ return REGS_UNALLOCATED;
+ regs->end = re_malloc (regoff_t, need_regs);
+ if (BE (regs->end == NULL, 0))
+ {
+ re_free (regs->start);
+ return REGS_UNALLOCATED;
+ }
+ regs->num_regs = need_regs;
+ }
+ else if (regs_allocated == REGS_REALLOCATE)
+ { /* Yes. If we need more elements than were already
+ allocated, reallocate them. If we need fewer, just
+ leave it alone. */
+ if (BE (need_regs > regs->num_regs, 0))
+ {
+ regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
+ regoff_t *new_end;
+ if (BE (new_start == NULL, 0))
+ return REGS_UNALLOCATED;
+ new_end = re_realloc (regs->end, regoff_t, need_regs);
+ if (BE (new_end == NULL, 0))
+ {
+ re_free (new_start);
+ return REGS_UNALLOCATED;
+ }
+ regs->start = new_start;
+ regs->end = new_end;
+ regs->num_regs = need_regs;
+ }
+ }
+ else
+ {
+ assert (regs_allocated == REGS_FIXED);
+ /* This function may not be called with REGS_FIXED and nregs too big. */
+ assert (regs->num_regs >= nregs);
+ rval = REGS_FIXED;
+ }
+
+ /* Copy the regs. */
+ for (i = 0; i < nregs; ++i)
+ {
+ regs->start[i] = pmatch[i].rm_so;
+ regs->end[i] = pmatch[i].rm_eo;
+ }
+ for ( ; i < regs->num_regs; ++i)
+ regs->start[i] = regs->end[i] = -1;
+
+ return rval;
+}
+
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
+ ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
+ this memory for recording register information. STARTS and ENDS
+ must be allocated using the malloc library routine, and must each
+ be at least NUM_REGS * sizeof (regoff_t) bytes long.
+
+ If NUM_REGS == 0, then subsequent matches should allocate their own
+ register data.
+
+ Unless this function is called, the first search or match using
+ PATTERN_BUFFER will allocate its own register data, without
+ freeing the old data. */
+
+void
+re_set_registers (bufp, regs, num_regs, starts, ends)
+ struct re_pattern_buffer *bufp;
+ struct re_registers *regs;
+ __re_size_t num_regs;
+ regoff_t *starts, *ends;
+{
+ if (num_regs)
+ {
+ bufp->regs_allocated = REGS_REALLOCATE;
+ regs->num_regs = num_regs;
+ regs->start = starts;
+ regs->end = ends;
+ }
+ else
+ {
+ bufp->regs_allocated = REGS_UNALLOCATED;
+ regs->num_regs = 0;
+ regs->start = regs->end = NULL;
+ }
+}
+#ifdef _LIBC
+weak_alias (__re_set_registers, re_set_registers)
+#endif
+
+/* Entry points compatible with 4.2 BSD regex library. We don't define
+ them unless specifically requested. */
+
+#if defined _REGEX_RE_COMP || defined _LIBC
+int
+# ifdef _LIBC
+weak_function
+# endif
+re_exec (s)
+ const char *s;
+{
+ return 0 == regexec (&re_comp_buf, s, 0, NULL, 0);
+}
+#endif /* _REGEX_RE_COMP */
+
+/* Internal entry point. */
+
+/* Searches for a compiled pattern PREG in the string STRING, whose
+ length is LENGTH. NMATCH, PMATCH, and EFLAGS have the same
+ meaning as with regexec. LAST_START is START + RANGE, where
+ START and RANGE have the same meaning as with re_search.
+ Return REG_NOERROR if we find a match, and REG_NOMATCH if not,
+ otherwise return the error code.
+ Note: We assume front end functions already check ranges.
+ (0 <= LAST_START && LAST_START <= LENGTH) */
+
+static reg_errcode_t
+__attribute_warn_unused_result__
+re_search_internal (const regex_t *preg,
+ const char *string, Idx length,
+ Idx start, Idx last_start, Idx stop,
+ size_t nmatch, regmatch_t pmatch[],
+ int eflags)
+{
+ reg_errcode_t err;
+ const re_dfa_t *dfa = preg->buffer;
+ Idx left_lim, right_lim;
+ int incr;
+ bool fl_longest_match;
+ int match_kind;
+ Idx match_first;
+ Idx match_last = REG_MISSING;
+ Idx extra_nmatch;
+ bool sb;
+ int ch;
+#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
+ re_match_context_t mctx = { .dfa = dfa };
+#else
+ re_match_context_t mctx;
+#endif
+ char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
+ && start != last_start && !preg->can_be_null)
+ ? preg->fastmap : NULL);
+ RE_TRANSLATE_TYPE t = preg->translate;
+
+#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
+ memset (&mctx, '\0', sizeof (re_match_context_t));
+ mctx.dfa = dfa;
+#endif
+
+ extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
+ nmatch -= extra_nmatch;
+
+ /* Check if the DFA haven't been compiled. */
+ if (BE (preg->used == 0 || dfa->init_state == NULL
+ || dfa->init_state_word == NULL || dfa->init_state_nl == NULL
+ || dfa->init_state_begbuf == NULL, 0))
+ return REG_NOMATCH;
+
+#ifdef DEBUG
+ /* We assume front-end functions already check them. */
+ assert (0 <= last_start && last_start <= length);
+#endif
+
+ /* If initial states with non-begbuf contexts have no elements,
+ the regex must be anchored. If preg->newline_anchor is set,
+ we'll never use init_state_nl, so do not check it. */
+ if (dfa->init_state->nodes.nelem == 0
+ && dfa->init_state_word->nodes.nelem == 0
+ && (dfa->init_state_nl->nodes.nelem == 0
+ || !preg->newline_anchor))
+ {
+ if (start != 0 && last_start != 0)
+ return REG_NOMATCH;
+ start = last_start = 0;
+ }
+
+ /* We must check the longest matching, if nmatch > 0. */
+ fl_longest_match = (nmatch != 0 || dfa->nbackref);
+
+ err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
+ preg->translate, (preg->syntax & RE_ICASE) != 0,
+ dfa);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ mctx.input.stop = stop;
+ mctx.input.raw_stop = stop;
+ mctx.input.newline_anchor = preg->newline_anchor;
+
+ err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ /* We will log all the DFA states through which the dfa pass,
+ if nmatch > 1, or this dfa has "multibyte node", which is a
+ back-reference or a node which can accept multibyte character or
+ multi character collating element. */
+ if (nmatch > 1 || dfa->has_mb_node)
+ {
+ /* Avoid overflow. */
+ if (BE ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
+ <= mctx.input.bufs_len), 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+
+ mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
+ if (BE (mctx.state_log == NULL, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+ }
+ else
+ mctx.state_log = NULL;
+
+ match_first = start;
+ mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
+ : CONTEXT_NEWLINE | CONTEXT_BEGBUF;
+
+ /* Check incrementally whether the input string matches. */
+ incr = (last_start < start) ? -1 : 1;
+ left_lim = (last_start < start) ? last_start : start;
+ right_lim = (last_start < start) ? start : last_start;
+ sb = dfa->mb_cur_max == 1;
+ match_kind =
+ (fastmap
+ ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0)
+ | (start <= last_start ? 2 : 0)
+ | (t != NULL ? 1 : 0))
+ : 8);
+
+ for (;; match_first += incr)
+ {
+ err = REG_NOMATCH;
+ if (match_first < left_lim || right_lim < match_first)
+ goto free_return;
+
+ /* Advance as rapidly as possible through the string, until we
+ find a plausible place to start matching. This may be done
+ with varying efficiency, so there are various possibilities:
+ only the most common of them are specialized, in order to
+ save on code size. We use a switch statement for speed. */
+ switch (match_kind)
+ {
+ case 8:
+ /* No fastmap. */
+ break;
+
+ case 7:
+ /* Fastmap with single-byte translation, match forward. */
+ while (BE (match_first < right_lim, 1)
+ && !fastmap[t[(unsigned char) string[match_first]]])
+ ++match_first;
+ goto forward_match_found_start_or_reached_end;
+
+ case 6:
+ /* Fastmap without translation, match forward. */
+ while (BE (match_first < right_lim, 1)
+ && !fastmap[(unsigned char) string[match_first]])
+ ++match_first;
+
+ forward_match_found_start_or_reached_end:
+ if (BE (match_first == right_lim, 0))
+ {
+ ch = match_first >= length
+ ? 0 : (unsigned char) string[match_first];
+ if (!fastmap[t ? t[ch] : ch])
+ goto free_return;
+ }
+ break;
+
+ case 4:
+ case 5:
+ /* Fastmap without multi-byte translation, match backwards. */
+ while (match_first >= left_lim)
+ {
+ ch = match_first >= length
+ ? 0 : (unsigned char) string[match_first];
+ if (fastmap[t ? t[ch] : ch])
+ break;
+ --match_first;
+ }
+ if (match_first < left_lim)
+ goto free_return;
+ break;
+
+ default:
+ /* In this case, we can't determine easily the current byte,
+ since it might be a component byte of a multibyte
+ character. Then we use the constructed buffer instead. */
+ for (;;)
+ {
+ /* If MATCH_FIRST is out of the valid range, reconstruct the
+ buffers. */
+ __re_size_t offset = match_first - mctx.input.raw_mbs_idx;
+ if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0))
+ {
+ err = re_string_reconstruct (&mctx.input, match_first,
+ eflags);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ offset = match_first - mctx.input.raw_mbs_idx;
+ }
+ /* If MATCH_FIRST is out of the buffer, leave it as '\0'.
+ Note that MATCH_FIRST must not be smaller than 0. */
+ ch = (match_first >= length
+ ? 0 : re_string_byte_at (&mctx.input, offset));
+ if (fastmap[ch])
+ break;
+ match_first += incr;
+ if (match_first < left_lim || match_first > right_lim)
+ {
+ err = REG_NOMATCH;
+ goto free_return;
+ }
+ }
+ break;
+ }
+
+ /* Reconstruct the buffers so that the matcher can assume that
+ the matching starts from the beginning of the buffer. */
+ err = re_string_reconstruct (&mctx.input, match_first, eflags);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+#ifdef RE_ENABLE_I18N
+ /* Don't consider this char as a possible match start if it part,
+ yet isn't the head, of a multibyte character. */
+ if (!sb && !re_string_first_byte (&mctx.input, 0))
+ continue;
+#endif
+
+ /* It seems to be appropriate one, then use the matcher. */
+ /* We assume that the matching starts from 0. */
+ mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0;
+ match_last = check_matching (&mctx, fl_longest_match,
+ start <= last_start ? &match_first : NULL);
+ if (match_last != REG_MISSING)
+ {
+ if (BE (match_last == REG_ERROR, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+ else
+ {
+ mctx.match_last = match_last;
+ if ((!preg->no_sub && nmatch > 1) || dfa->nbackref)
+ {
+ re_dfastate_t *pstate = mctx.state_log[match_last];
+ mctx.last_node = check_halt_state_context (&mctx, pstate,
+ match_last);
+ }
+ if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match)
+ || dfa->nbackref)
+ {
+ err = prune_impossible_nodes (&mctx);
+ if (err == REG_NOERROR)
+ break;
+ if (BE (err != REG_NOMATCH, 0))
+ goto free_return;
+ match_last = REG_MISSING;
+ }
+ else
+ break; /* We found a match. */
+ }
+ }
+
+ match_ctx_clean (&mctx);
+ }
+
+#ifdef DEBUG
+ assert (match_last != REG_MISSING);
+ assert (err == REG_NOERROR);
+#endif
+
+ /* Set pmatch[] if we need. */
+ if (nmatch > 0)
+ {
+ Idx reg_idx;
+
+ /* Initialize registers. */
+ for (reg_idx = 1; reg_idx < nmatch; ++reg_idx)
+ pmatch[reg_idx].rm_so = pmatch[reg_idx].rm_eo = -1;
+
+ /* Set the points where matching start/end. */
+ pmatch[0].rm_so = 0;
+ pmatch[0].rm_eo = mctx.match_last;
+ /* FIXME: This function should fail if mctx.match_last exceeds
+ the maximum possible regoff_t value. We need a new error
+ code REG_OVERFLOW. */
+
+ if (!preg->no_sub && nmatch > 1)
+ {
+ err = set_regs (preg, &mctx, nmatch, pmatch,
+ dfa->has_plural_match && dfa->nbackref > 0);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+
+ /* At last, add the offset to each register, since we slid
+ the buffers so that we could assume that the matching starts
+ from 0. */
+ for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
+ if (pmatch[reg_idx].rm_so != -1)
+ {
+#ifdef RE_ENABLE_I18N
+ if (BE (mctx.input.offsets_needed != 0, 0))
+ {
+ pmatch[reg_idx].rm_so =
+ (pmatch[reg_idx].rm_so == mctx.input.valid_len
+ ? mctx.input.valid_raw_len
+ : mctx.input.offsets[pmatch[reg_idx].rm_so]);
+ pmatch[reg_idx].rm_eo =
+ (pmatch[reg_idx].rm_eo == mctx.input.valid_len
+ ? mctx.input.valid_raw_len
+ : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
+ }
+#else
+ assert (mctx.input.offsets_needed == 0);
+#endif
+ pmatch[reg_idx].rm_so += match_first;
+ pmatch[reg_idx].rm_eo += match_first;
+ }
+ for (reg_idx = 0; reg_idx < extra_nmatch; ++reg_idx)
+ {
+ pmatch[nmatch + reg_idx].rm_so = -1;
+ pmatch[nmatch + reg_idx].rm_eo = -1;
+ }
+
+ if (dfa->subexp_map)
+ for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++)
+ if (dfa->subexp_map[reg_idx] != reg_idx)
+ {
+ pmatch[reg_idx + 1].rm_so
+ = pmatch[dfa->subexp_map[reg_idx] + 1].rm_so;
+ pmatch[reg_idx + 1].rm_eo
+ = pmatch[dfa->subexp_map[reg_idx] + 1].rm_eo;
+ }
+ }
+
+ free_return:
+ re_free (mctx.state_log);
+ if (dfa->nbackref)
+ match_ctx_free (&mctx);
+ re_string_destruct (&mctx.input);
+ return err;
+}
+
+static reg_errcode_t
+__attribute_warn_unused_result__
+prune_impossible_nodes (re_match_context_t *mctx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx halt_node, match_last;
+ reg_errcode_t ret;
+ re_dfastate_t **sifted_states;
+ re_dfastate_t **lim_states = NULL;
+ re_sift_context_t sctx;
+#ifdef DEBUG
+ assert (mctx->state_log != NULL);
+#endif
+ match_last = mctx->match_last;
+ halt_node = mctx->last_node;
+
+ /* Avoid overflow. */
+ if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) <= match_last, 0))
+ return REG_ESPACE;
+
+ sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
+ if (BE (sifted_states == NULL, 0))
+ {
+ ret = REG_ESPACE;
+ goto free_return;
+ }
+ if (dfa->nbackref)
+ {
+ lim_states = re_malloc (re_dfastate_t *, match_last + 1);
+ if (BE (lim_states == NULL, 0))
+ {
+ ret = REG_ESPACE;
+ goto free_return;
+ }
+ while (1)
+ {
+ memset (lim_states, '\0',
+ sizeof (re_dfastate_t *) * (match_last + 1));
+ sift_ctx_init (&sctx, sifted_states, lim_states, halt_node,
+ match_last);
+ ret = sift_states_backward (mctx, &sctx);
+ re_node_set_free (&sctx.limits);
+ if (BE (ret != REG_NOERROR, 0))
+ goto free_return;
+ if (sifted_states[0] != NULL || lim_states[0] != NULL)
+ break;
+ do
+ {
+ --match_last;
+ if (! REG_VALID_INDEX (match_last))
+ {
+ ret = REG_NOMATCH;
+ goto free_return;
+ }
+ } while (mctx->state_log[match_last] == NULL
+ || !mctx->state_log[match_last]->halt);
+ halt_node = check_halt_state_context (mctx,
+ mctx->state_log[match_last],
+ match_last);
+ }
+ ret = merge_state_array (dfa, sifted_states, lim_states,
+ match_last + 1);
+ re_free (lim_states);
+ lim_states = NULL;
+ if (BE (ret != REG_NOERROR, 0))
+ goto free_return;
+ }
+ else
+ {
+ sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last);
+ ret = sift_states_backward (mctx, &sctx);
+ re_node_set_free (&sctx.limits);
+ if (BE (ret != REG_NOERROR, 0))
+ goto free_return;
+ if (sifted_states[0] == NULL)
+ {
+ ret = REG_NOMATCH;
+ goto free_return;
+ }
+ }
+ re_free (mctx->state_log);
+ mctx->state_log = sifted_states;
+ sifted_states = NULL;
+ mctx->last_node = halt_node;
+ mctx->match_last = match_last;
+ ret = REG_NOERROR;
+ free_return:
+ re_free (sifted_states);
+ re_free (lim_states);
+ return ret;
+}
+
+/* Acquire an initial state and return it.
+ We must select appropriate initial state depending on the context,
+ since initial states may have constraints like "\<", "^", etc.. */
+
+static inline re_dfastate_t *
+__attribute__ ((always_inline)) internal_function
+acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
+ Idx idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ if (dfa->init_state->has_constraint)
+ {
+ unsigned int context;
+ context = re_string_context_at (&mctx->input, idx - 1, mctx->eflags);
+ if (IS_WORD_CONTEXT (context))
+ return dfa->init_state_word;
+ else if (IS_ORDINARY_CONTEXT (context))
+ return dfa->init_state;
+ else if (IS_BEGBUF_CONTEXT (context) && IS_NEWLINE_CONTEXT (context))
+ return dfa->init_state_begbuf;
+ else if (IS_NEWLINE_CONTEXT (context))
+ return dfa->init_state_nl;
+ else if (IS_BEGBUF_CONTEXT (context))
+ {
+ /* It is relatively rare case, then calculate on demand. */
+ return re_acquire_state_context (err, dfa,
+ dfa->init_state->entrance_nodes,
+ context);
+ }
+ else
+ /* Must not happen? */
+ return dfa->init_state;
+ }
+ else
+ return dfa->init_state;
+}
+
+/* Check whether the regular expression match input string INPUT or not,
+ and return the index where the matching end. Return REG_MISSING if
+ there is no match, and return REG_ERROR in case of an error.
+ FL_LONGEST_MATCH means we want the POSIX longest matching.
+ If P_MATCH_FIRST is not NULL, and the match fails, it is set to the
+ next place where we may want to try matching.
+ Note that the matcher assumes that the matching starts from the current
+ index of the buffer. */
+
+static Idx
+internal_function __attribute_warn_unused_result__
+check_matching (re_match_context_t *mctx, bool fl_longest_match,
+ Idx *p_match_first)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx match = 0;
+ Idx match_last = REG_MISSING;
+ Idx cur_str_idx = re_string_cur_idx (&mctx->input);
+ re_dfastate_t *cur_state;
+ bool at_init_state = p_match_first != NULL;
+ Idx next_start_idx = cur_str_idx;
+
+ err = REG_NOERROR;
+ cur_state = acquire_init_state_context (&err, mctx, cur_str_idx);
+ /* An initial state must not be NULL (invalid). */
+ if (BE (cur_state == NULL, 0))
+ {
+ assert (err == REG_ESPACE);
+ return REG_ERROR;
+ }
+
+ if (mctx->state_log != NULL)
+ {
+ mctx->state_log[cur_str_idx] = cur_state;
+
+ /* Check OP_OPEN_SUBEXP in the initial state in case that we use them
+ later. E.g. Processing back references. */
+ if (BE (dfa->nbackref, 0))
+ {
+ at_init_state = false;
+ err = check_subexp_matching_top (mctx, &cur_state->nodes, 0);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ if (cur_state->has_backref)
+ {
+ err = transit_state_bkref (mctx, &cur_state->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ }
+
+ /* If the RE accepts NULL string. */
+ if (BE (cur_state->halt, 0))
+ {
+ if (!cur_state->has_constraint
+ || check_halt_state_context (mctx, cur_state, cur_str_idx))
+ {
+ if (!fl_longest_match)
+ return cur_str_idx;
+ else
+ {
+ match_last = cur_str_idx;
+ match = 1;
+ }
+ }
+ }
+
+ while (!re_string_eoi (&mctx->input))
+ {
+ re_dfastate_t *old_state = cur_state;
+ Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
+
+ if ((BE (next_char_idx >= mctx->input.bufs_len, 0)
+ && mctx->input.bufs_len < mctx->input.len)
+ || (BE (next_char_idx >= mctx->input.valid_len, 0)
+ && mctx->input.valid_len < mctx->input.len))
+ {
+ err = extend_buffers (mctx, next_char_idx + 1);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ assert (err == REG_ESPACE);
+ return REG_ERROR;
+ }
+ }
+
+ cur_state = transit_state (&err, mctx, cur_state);
+ if (mctx->state_log != NULL)
+ cur_state = merge_state_with_log (&err, mctx, cur_state);
+
+ if (cur_state == NULL)
+ {
+ /* Reached the invalid state or an error. Try to recover a valid
+ state using the state log, if available and if we have not
+ already found a valid (even if not the longest) match. */
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ERROR;
+
+ if (mctx->state_log == NULL
+ || (match && !fl_longest_match)
+ || (cur_state = find_recover_state (&err, mctx)) == NULL)
+ break;
+ }
+
+ if (BE (at_init_state, 0))
+ {
+ if (old_state == cur_state)
+ next_start_idx = next_char_idx;
+ else
+ at_init_state = false;
+ }
+
+ if (cur_state->halt)
+ {
+ /* Reached a halt state.
+ Check the halt state can satisfy the current context. */
+ if (!cur_state->has_constraint
+ || check_halt_state_context (mctx, cur_state,
+ re_string_cur_idx (&mctx->input)))
+ {
+ /* We found an appropriate halt state. */
+ match_last = re_string_cur_idx (&mctx->input);
+ match = 1;
+
+ /* We found a match, do not modify match_first below. */
+ p_match_first = NULL;
+ if (!fl_longest_match)
+ break;
+ }
+ }
+ }
+
+ if (p_match_first)
+ *p_match_first += next_start_idx;
+
+ return match_last;
+}
+
+/* Check NODE match the current context. */
+
+static bool
+internal_function
+check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
+{
+ re_token_type_t type = dfa->nodes[node].type;
+ unsigned int constraint = dfa->nodes[node].constraint;
+ if (type != END_OF_RE)
+ return false;
+ if (!constraint)
+ return true;
+ if (NOT_SATISFY_NEXT_CONSTRAINT (constraint, context))
+ return false;
+ return true;
+}
+
+/* Check the halt state STATE match the current context.
+ Return 0 if not match, if the node, STATE has, is a halt node and
+ match the context, return the node. */
+
+static Idx
+internal_function
+check_halt_state_context (const re_match_context_t *mctx,
+ const re_dfastate_t *state, Idx idx)
+{
+ Idx i;
+ unsigned int context;
+#ifdef DEBUG
+ assert (state->halt);
+#endif
+ context = re_string_context_at (&mctx->input, idx, mctx->eflags);
+ for (i = 0; i < state->nodes.nelem; ++i)
+ if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context))
+ return state->nodes.elems[i];
+ return 0;
+}
+
+/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA
+ corresponding to the DFA).
+ Return the destination node, and update EPS_VIA_NODES;
+ return REG_MISSING in case of errors. */
+
+static Idx
+internal_function
+proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
+ Idx *pidx, Idx node, re_node_set *eps_via_nodes,
+ struct re_fail_stack_t *fs)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx i;
+ bool ok;
+ if (IS_EPSILON_NODE (dfa->nodes[node].type))
+ {
+ re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
+ re_node_set *edests = &dfa->edests[node];
+ Idx dest_node;
+ ok = re_node_set_insert (eps_via_nodes, node);
+ if (BE (! ok, 0))
+ return REG_ERROR;
+ /* Pick up a valid destination, or return REG_MISSING if none
+ is found. */
+ for (dest_node = REG_MISSING, i = 0; i < edests->nelem; ++i)
+ {
+ Idx candidate = edests->elems[i];
+ if (!re_node_set_contains (cur_nodes, candidate))
+ continue;
+ if (dest_node == REG_MISSING)
+ dest_node = candidate;
+
+ else
+ {
+ /* In order to avoid infinite loop like "(a*)*", return the second
+ epsilon-transition if the first was already considered. */
+ if (re_node_set_contains (eps_via_nodes, dest_node))
+ return candidate;
+
+ /* Otherwise, push the second epsilon-transition on the fail stack. */
+ else if (fs != NULL
+ && push_fail_stack (fs, *pidx, candidate, nregs, regs,
+ eps_via_nodes))
+ return REG_ERROR;
+
+ /* We know we are going to exit. */
+ break;
+ }
+ }
+ return dest_node;
+ }
+ else
+ {
+ Idx naccepted = 0;
+ re_token_type_t type = dfa->nodes[node].type;
+
+#ifdef RE_ENABLE_I18N
+ if (dfa->nodes[node].accept_mb)
+ naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx);
+ else
+#endif /* RE_ENABLE_I18N */
+ if (type == OP_BACK_REF)
+ {
+ Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
+ naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
+ if (fs != NULL)
+ {
+ if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1)
+ return REG_MISSING;
+ else if (naccepted)
+ {
+ char *buf = (char *) re_string_get_buffer (&mctx->input);
+ if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
+ naccepted) != 0)
+ return REG_MISSING;
+ }
+ }
+
+ if (naccepted == 0)
+ {
+ Idx dest_node;
+ ok = re_node_set_insert (eps_via_nodes, node);
+ if (BE (! ok, 0))
+ return REG_ERROR;
+ dest_node = dfa->edests[node].elems[0];
+ if (re_node_set_contains (&mctx->state_log[*pidx]->nodes,
+ dest_node))
+ return dest_node;
+ }
+ }
+
+ if (naccepted != 0
+ || check_node_accept (mctx, dfa->nodes + node, *pidx))
+ {
+ Idx dest_node = dfa->nexts[node];
+ *pidx = (naccepted == 0) ? *pidx + 1 : *pidx + naccepted;
+ if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL
+ || !re_node_set_contains (&mctx->state_log[*pidx]->nodes,
+ dest_node)))
+ return REG_MISSING;
+ re_node_set_empty (eps_via_nodes);
+ return dest_node;
+ }
+ }
+ return REG_MISSING;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
+ Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
+{
+ reg_errcode_t err;
+ Idx num = fs->num++;
+ if (fs->num == fs->alloc)
+ {
+ struct re_fail_stack_ent_t *new_array;
+ new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
+ * fs->alloc * 2));
+ if (new_array == NULL)
+ return REG_ESPACE;
+ fs->alloc *= 2;
+ fs->stack = new_array;
+ }
+ fs->stack[num].idx = str_idx;
+ fs->stack[num].node = dest_node;
+ fs->stack[num].regs = re_malloc (regmatch_t, nregs);
+ if (fs->stack[num].regs == NULL)
+ return REG_ESPACE;
+ memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
+ err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes);
+ return err;
+}
+
+static Idx
+internal_function
+pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
+ regmatch_t *regs, re_node_set *eps_via_nodes)
+{
+ Idx num = --fs->num;
+ assert (REG_VALID_INDEX (num));
+ *pidx = fs->stack[num].idx;
+ memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs);
+ re_node_set_free (eps_via_nodes);
+ re_free (fs->stack[num].regs);
+ *eps_via_nodes = fs->stack[num].eps_via_nodes;
+ return fs->stack[num].node;
+}
+
+/* Set the positions where the subexpressions are starts/ends to registers
+ PMATCH.
+ Note: We assume that pmatch[0] is already set, and
+ pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
+ regmatch_t *pmatch, bool fl_backtrack)
+{
+ const re_dfa_t *dfa = preg->buffer;
+ Idx idx, cur_node;
+ re_node_set eps_via_nodes;
+ struct re_fail_stack_t *fs;
+ struct re_fail_stack_t fs_body = { 0, 2, NULL };
+ regmatch_t *prev_idx_match;
+ bool prev_idx_match_malloced = false;
+
+#ifdef DEBUG
+ assert (nmatch > 1);
+ assert (mctx->state_log != NULL);
+#endif
+ if (fl_backtrack)
+ {
+ fs = &fs_body;
+ fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc);
+ if (fs->stack == NULL)
+ return REG_ESPACE;
+ }
+ else
+ fs = NULL;
+
+ cur_node = dfa->init_node;
+ re_node_set_init_empty (&eps_via_nodes);
+
+ if (__libc_use_alloca (nmatch * sizeof (regmatch_t)))
+ prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
+ else
+ {
+ prev_idx_match = re_malloc (regmatch_t, nmatch);
+ if (prev_idx_match == NULL)
+ {
+ free_fail_stack_return (fs);
+ return REG_ESPACE;
+ }
+ prev_idx_match_malloced = true;
+ }
+ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
+
+ for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
+ {
+ update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch);
+
+ if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
+ {
+ Idx reg_idx;
+ if (fs)
+ {
+ for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
+ if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1)
+ break;
+ if (reg_idx == nmatch)
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return free_fail_stack_return (fs);
+ }
+ cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
+ &eps_via_nodes);
+ }
+ else
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return REG_NOERROR;
+ }
+ }
+
+ /* Proceed to next node. */
+ cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node,
+ &eps_via_nodes, fs);
+
+ if (BE (! REG_VALID_INDEX (cur_node), 0))
+ {
+ if (BE (cur_node == REG_ERROR, 0))
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ free_fail_stack_return (fs);
+ return REG_ESPACE;
+ }
+ if (fs)
+ cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
+ &eps_via_nodes);
+ else
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return REG_NOMATCH;
+ }
+ }
+ }
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return free_fail_stack_return (fs);
+}
+
+static reg_errcode_t
+internal_function
+free_fail_stack_return (struct re_fail_stack_t *fs)
+{
+ if (fs)
+ {
+ Idx fs_idx;
+ for (fs_idx = 0; fs_idx < fs->num; ++fs_idx)
+ {
+ re_node_set_free (&fs->stack[fs_idx].eps_via_nodes);
+ re_free (fs->stack[fs_idx].regs);
+ }
+ re_free (fs->stack);
+ }
+ return REG_NOERROR;
+}
+
+static void
+internal_function
+update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
+ regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
+{
+ int type = dfa->nodes[cur_node].type;
+ if (type == OP_OPEN_SUBEXP)
+ {
+ Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
+
+ /* We are at the first node of this sub expression. */
+ if (reg_num < nmatch)
+ {
+ pmatch[reg_num].rm_so = cur_idx;
+ pmatch[reg_num].rm_eo = -1;
+ }
+ }
+ else if (type == OP_CLOSE_SUBEXP)
+ {
+ Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
+ if (reg_num < nmatch)
+ {
+ /* We are at the last node of this sub expression. */
+ if (pmatch[reg_num].rm_so < cur_idx)
+ {
+ pmatch[reg_num].rm_eo = cur_idx;
+ /* This is a non-empty match or we are not inside an optional
+ subexpression. Accept this right away. */
+ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
+ }
+ else
+ {
+ if (dfa->nodes[cur_node].opt_subexp
+ && prev_idx_match[reg_num].rm_so != -1)
+ /* We transited through an empty match for an optional
+ subexpression, like (a?)*, and this is not the subexp's
+ first match. Copy back the old content of the registers
+ so that matches of an inner subexpression are undone as
+ well, like in ((a?))*. */
+ memcpy (pmatch, prev_idx_match, sizeof (regmatch_t) * nmatch);
+ else
+ /* We completed a subexpression, but it may be part of
+ an optional one, so do not update PREV_IDX_MATCH. */
+ pmatch[reg_num].rm_eo = cur_idx;
+ }
+ }
+ }
+}
+
+/* This function checks the STATE_LOG from the SCTX->last_str_idx to 0
+ and sift the nodes in each states according to the following rules.
+ Updated state_log will be wrote to STATE_LOG.
+
+ Rules: We throw away the Node 'a' in the STATE_LOG[STR_IDX] if...
+ 1. When STR_IDX == MATCH_LAST(the last index in the state_log):
+ If 'a' isn't the LAST_NODE and 'a' can't epsilon transit to
+ the LAST_NODE, we throw away the node 'a'.
+ 2. When 0 <= STR_IDX < MATCH_LAST and 'a' accepts
+ string 's' and transit to 'b':
+ i. If 'b' isn't in the STATE_LOG[STR_IDX+strlen('s')], we throw
+ away the node 'a'.
+ ii. If 'b' is in the STATE_LOG[STR_IDX+strlen('s')] but 'b' is
+ thrown away, we throw away the node 'a'.
+ 3. When 0 <= STR_IDX < MATCH_LAST and 'a' epsilon transit to 'b':
+ i. If 'b' isn't in the STATE_LOG[STR_IDX], we throw away the
+ node 'a'.
+ ii. If 'b' is in the STATE_LOG[STR_IDX] but 'b' is thrown away,
+ we throw away the node 'a'. */
+
+#define STATE_NODE_CONTAINS(state,node) \
+ ((state) != NULL && re_node_set_contains (&(state)->nodes, node))
+
+static reg_errcode_t
+internal_function
+sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
+{
+ reg_errcode_t err;
+ int null_cnt = 0;
+ Idx str_idx = sctx->last_str_idx;
+ re_node_set cur_dest;
+
+#ifdef DEBUG
+ assert (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL);
+#endif
+
+ /* Build sifted state_log[str_idx]. It has the nodes which can epsilon
+ transit to the last_node and the last_node itself. */
+ err = re_node_set_init_1 (&cur_dest, sctx->last_node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ /* Then check each states in the state_log. */
+ while (str_idx > 0)
+ {
+ /* Update counters. */
+ null_cnt = (sctx->sifted_states[str_idx] == NULL) ? null_cnt + 1 : 0;
+ if (null_cnt > mctx->max_mb_elem_len)
+ {
+ memset (sctx->sifted_states, '\0',
+ sizeof (re_dfastate_t *) * str_idx);
+ re_node_set_free (&cur_dest);
+ return REG_NOERROR;
+ }
+ re_node_set_empty (&cur_dest);
+ --str_idx;
+
+ if (mctx->state_log[str_idx])
+ {
+ err = build_sifted_states (mctx, sctx, str_idx, &cur_dest);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+
+ /* Add all the nodes which satisfy the following conditions:
+ - It can epsilon transit to a node in CUR_DEST.
+ - It is in CUR_SRC.
+ And update state_log. */
+ err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ err = REG_NOERROR;
+ free_return:
+ re_node_set_free (&cur_dest);
+ return err;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
+ Idx str_idx, re_node_set *cur_dest)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
+ Idx i;
+
+ /* Then build the next sifted state.
+ We build the next sifted state on 'cur_dest', and update
+ 'sifted_states[str_idx]' with 'cur_dest'.
+ Note:
+ 'cur_dest' is the sifted state from 'state_log[str_idx + 1]'.
+ 'cur_src' points the node_set of the old 'state_log[str_idx]'
+ (with the epsilon nodes pre-filtered out). */
+ for (i = 0; i < cur_src->nelem; i++)
+ {
+ Idx prev_node = cur_src->elems[i];
+ int naccepted = 0;
+ bool ok;
+
+#ifdef DEBUG
+ re_token_type_t type = dfa->nodes[prev_node].type;
+ assert (!IS_EPSILON_NODE (type));
+#endif
+#ifdef RE_ENABLE_I18N
+ /* If the node may accept "multi byte". */
+ if (dfa->nodes[prev_node].accept_mb)
+ naccepted = sift_states_iter_mb (mctx, sctx, prev_node,
+ str_idx, sctx->last_str_idx);
+#endif /* RE_ENABLE_I18N */
+
+ /* We don't check backreferences here.
+ See update_cur_sifted_state(). */
+ if (!naccepted
+ && check_node_accept (mctx, dfa->nodes + prev_node, str_idx)
+ && STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + 1],
+ dfa->nexts[prev_node]))
+ naccepted = 1;
+
+ if (naccepted == 0)
+ continue;
+
+ if (sctx->limits.nelem)
+ {
+ Idx to_idx = str_idx + naccepted;
+ if (check_dst_limits (mctx, &sctx->limits,
+ dfa->nexts[prev_node], to_idx,
+ prev_node, str_idx))
+ continue;
+ }
+ ok = re_node_set_insert (cur_dest, prev_node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+
+ return REG_NOERROR;
+}
+
+/* Helper functions. */
+
+static reg_errcode_t
+internal_function
+clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
+{
+ Idx top = mctx->state_log_top;
+
+ if ((next_state_log_idx >= mctx->input.bufs_len
+ && mctx->input.bufs_len < mctx->input.len)
+ || (next_state_log_idx >= mctx->input.valid_len
+ && mctx->input.valid_len < mctx->input.len))
+ {
+ reg_errcode_t err;
+ err = extend_buffers (mctx, next_state_log_idx + 1);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ if (top < next_state_log_idx)
+ {
+ memset (mctx->state_log + top + 1, '\0',
+ sizeof (re_dfastate_t *) * (next_state_log_idx - top));
+ mctx->state_log_top = next_state_log_idx;
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function
+merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
+ re_dfastate_t **src, Idx num)
+{
+ Idx st_idx;
+ reg_errcode_t err;
+ for (st_idx = 0; st_idx < num; ++st_idx)
+ {
+ if (dst[st_idx] == NULL)
+ dst[st_idx] = src[st_idx];
+ else if (src[st_idx] != NULL)
+ {
+ re_node_set merged_set;
+ err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes,
+ &src[st_idx]->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ dst[st_idx] = re_acquire_state (&err, dfa, &merged_set);
+ re_node_set_free (&merged_set);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function
+update_cur_sifted_state (const re_match_context_t *mctx,
+ re_sift_context_t *sctx, Idx str_idx,
+ re_node_set *dest_nodes)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err = REG_NOERROR;
+ const re_node_set *candidates;
+ candidates = ((mctx->state_log[str_idx] == NULL) ? NULL
+ : &mctx->state_log[str_idx]->nodes);
+
+ if (dest_nodes->nelem == 0)
+ sctx->sifted_states[str_idx] = NULL;
+ else
+ {
+ if (candidates)
+ {
+ /* At first, add the nodes which can epsilon transit to a node in
+ DEST_NODE. */
+ err = add_epsilon_src_nodes (dfa, dest_nodes, candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* Then, check the limitations in the current sift_context. */
+ if (sctx->limits.nelem)
+ {
+ err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits,
+ mctx->bkref_ents, str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+
+ sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ if (candidates && mctx->state_log[str_idx]->has_backref)
+ {
+ err = sift_states_bkref (mctx, sctx, str_idx, candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
+ const re_node_set *candidates)
+{
+ reg_errcode_t err = REG_NOERROR;
+ Idx i;
+
+ re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ if (!state->inveclosure.alloc)
+ {
+ err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem);
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ESPACE;
+ for (i = 0; i < dest_nodes->nelem; i++)
+ {
+ err = re_node_set_merge (&state->inveclosure,
+ dfa->inveclosures + dest_nodes->elems[i]);
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ESPACE;
+ }
+ }
+ return re_node_set_add_intersect (dest_nodes, candidates,
+ &state->inveclosure);
+}
+
+static reg_errcode_t
+internal_function
+sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
+ const re_node_set *candidates)
+{
+ Idx ecl_idx;
+ reg_errcode_t err;
+ re_node_set *inv_eclosure = dfa->inveclosures + node;
+ re_node_set except_nodes;
+ re_node_set_init_empty (&except_nodes);
+ for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
+ {
+ Idx cur_node = inv_eclosure->elems[ecl_idx];
+ if (cur_node == node)
+ continue;
+ if (IS_EPSILON_NODE (dfa->nodes[cur_node].type))
+ {
+ Idx edst1 = dfa->edests[cur_node].elems[0];
+ Idx edst2 = ((dfa->edests[cur_node].nelem > 1)
+ ? dfa->edests[cur_node].elems[1] : REG_MISSING);
+ if ((!re_node_set_contains (inv_eclosure, edst1)
+ && re_node_set_contains (dest_nodes, edst1))
+ || (REG_VALID_NONZERO_INDEX (edst2)
+ && !re_node_set_contains (inv_eclosure, edst2)
+ && re_node_set_contains (dest_nodes, edst2)))
+ {
+ err = re_node_set_add_intersect (&except_nodes, candidates,
+ dfa->inveclosures + cur_node);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&except_nodes);
+ return err;
+ }
+ }
+ }
+ }
+ for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
+ {
+ Idx cur_node = inv_eclosure->elems[ecl_idx];
+ if (!re_node_set_contains (&except_nodes, cur_node))
+ {
+ Idx idx = re_node_set_contains (dest_nodes, cur_node) - 1;
+ re_node_set_remove_at (dest_nodes, idx);
+ }
+ }
+ re_node_set_free (&except_nodes);
+ return REG_NOERROR;
+}
+
+static bool
+internal_function
+check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
+ Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx lim_idx, src_pos, dst_pos;
+
+ Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
+ Idx src_bkref_idx = search_cur_bkref_entry (mctx, src_idx);
+ for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
+ {
+ Idx subexp_idx;
+ struct re_backref_cache_entry *ent;
+ ent = mctx->bkref_ents + limits->elems[lim_idx];
+ subexp_idx = dfa->nodes[ent->node].opr.idx;
+
+ dst_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx],
+ subexp_idx, dst_node, dst_idx,
+ dst_bkref_idx);
+ src_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx],
+ subexp_idx, src_node, src_idx,
+ src_bkref_idx);
+
+ /* In case of:
+ <src> <dst> ( <subexp> )
+ ( <subexp> ) <src> <dst>
+ ( <subexp1> <src> <subexp2> <dst> <subexp3> ) */
+ if (src_pos == dst_pos)
+ continue; /* This is unrelated limitation. */
+ else
+ return true;
+ }
+ return false;
+}
+
+static int
+internal_function
+check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
+ Idx subexp_idx, Idx from_node, Idx bkref_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *eclosures = dfa->eclosures + from_node;
+ Idx node_idx;
+
+ /* Else, we are on the boundary: examine the nodes on the epsilon
+ closure. */
+ for (node_idx = 0; node_idx < eclosures->nelem; ++node_idx)
+ {
+ Idx node = eclosures->elems[node_idx];
+ switch (dfa->nodes[node].type)
+ {
+ case OP_BACK_REF:
+ if (bkref_idx != REG_MISSING)
+ {
+ struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx;
+ do
+ {
+ Idx dst;
+ int cpos;
+
+ if (ent->node != node)
+ continue;
+
+ if (subexp_idx < BITSET_WORD_BITS
+ && !(ent->eps_reachable_subexps_map
+ & ((bitset_word_t) 1 << subexp_idx)))
+ continue;
+
+ /* Recurse trying to reach the OP_OPEN_SUBEXP and
+ OP_CLOSE_SUBEXP cases below. But, if the
+ destination node is the same node as the source
+ node, don't recurse because it would cause an
+ infinite loop: a regex that exhibits this behavior
+ is ()\1*\1* */
+ dst = dfa->edests[node].elems[0];
+ if (dst == from_node)
+ {
+ if (boundaries & 1)
+ return -1;
+ else /* if (boundaries & 2) */
+ return 0;
+ }
+
+ cpos =
+ check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx,
+ dst, bkref_idx);
+ if (cpos == -1 /* && (boundaries & 1) */)
+ return -1;
+ if (cpos == 0 && (boundaries & 2))
+ return 0;
+
+ if (subexp_idx < BITSET_WORD_BITS)
+ ent->eps_reachable_subexps_map
+ &= ~((bitset_word_t) 1 << subexp_idx);
+ }
+ while (ent++->more);
+ }
+ break;
+
+ case OP_OPEN_SUBEXP:
+ if ((boundaries & 1) && subexp_idx == dfa->nodes[node].opr.idx)
+ return -1;
+ break;
+
+ case OP_CLOSE_SUBEXP:
+ if ((boundaries & 2) && subexp_idx == dfa->nodes[node].opr.idx)
+ return 0;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return (boundaries & 2) ? 1 : 0;
+}
+
+static int
+internal_function
+check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
+ Idx subexp_idx, Idx from_node, Idx str_idx,
+ Idx bkref_idx)
+{
+ struct re_backref_cache_entry *lim = mctx->bkref_ents + limit;
+ int boundaries;
+
+ /* If we are outside the range of the subexpression, return -1 or 1. */
+ if (str_idx < lim->subexp_from)
+ return -1;
+
+ if (lim->subexp_to < str_idx)
+ return 1;
+
+ /* If we are within the subexpression, return 0. */
+ boundaries = (str_idx == lim->subexp_from);
+ boundaries |= (str_idx == lim->subexp_to) << 1;
+ if (boundaries == 0)
+ return 0;
+
+ /* Else, examine epsilon closure. */
+ return check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx,
+ from_node, bkref_idx);
+}
+
+/* Check the limitations of sub expressions LIMITS, and remove the nodes
+ which are against limitations from DEST_NODES. */
+
+static reg_errcode_t
+internal_function
+check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
+ const re_node_set *candidates, re_node_set *limits,
+ struct re_backref_cache_entry *bkref_ents, Idx str_idx)
+{
+ reg_errcode_t err;
+ Idx node_idx, lim_idx;
+
+ for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
+ {
+ Idx subexp_idx;
+ struct re_backref_cache_entry *ent;
+ ent = bkref_ents + limits->elems[lim_idx];
+
+ if (str_idx <= ent->subexp_from || ent->str_idx < str_idx)
+ continue; /* This is unrelated limitation. */
+
+ subexp_idx = dfa->nodes[ent->node].opr.idx;
+ if (ent->subexp_to == str_idx)
+ {
+ Idx ops_node = REG_MISSING;
+ Idx cls_node = REG_MISSING;
+ for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
+ {
+ Idx node = dest_nodes->elems[node_idx];
+ re_token_type_t type = dfa->nodes[node].type;
+ if (type == OP_OPEN_SUBEXP
+ && subexp_idx == dfa->nodes[node].opr.idx)
+ ops_node = node;
+ else if (type == OP_CLOSE_SUBEXP
+ && subexp_idx == dfa->nodes[node].opr.idx)
+ cls_node = node;
+ }
+
+ /* Check the limitation of the open subexpression. */
+ /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */
+ if (REG_VALID_INDEX (ops_node))
+ {
+ err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes,
+ candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ /* Check the limitation of the close subexpression. */
+ if (REG_VALID_INDEX (cls_node))
+ for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
+ {
+ Idx node = dest_nodes->elems[node_idx];
+ if (!re_node_set_contains (dfa->inveclosures + node,
+ cls_node)
+ && !re_node_set_contains (dfa->eclosures + node,
+ cls_node))
+ {
+ /* It is against this limitation.
+ Remove it form the current sifted state. */
+ err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
+ candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ --node_idx;
+ }
+ }
+ }
+ else /* (ent->subexp_to != str_idx) */
+ {
+ for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
+ {
+ Idx node = dest_nodes->elems[node_idx];
+ re_token_type_t type = dfa->nodes[node].type;
+ if (type == OP_CLOSE_SUBEXP || type == OP_OPEN_SUBEXP)
+ {
+ if (subexp_idx != dfa->nodes[node].opr.idx)
+ continue;
+ /* It is against this limitation.
+ Remove it form the current sifted state. */
+ err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
+ candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ }
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
+ Idx str_idx, const re_node_set *candidates)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx node_idx, node;
+ re_sift_context_t local_sctx;
+ Idx first_idx = search_cur_bkref_entry (mctx, str_idx);
+
+ if (first_idx == REG_MISSING)
+ return REG_NOERROR;
+
+ local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */
+
+ for (node_idx = 0; node_idx < candidates->nelem; ++node_idx)
+ {
+ Idx enabled_idx;
+ re_token_type_t type;
+ struct re_backref_cache_entry *entry;
+ node = candidates->elems[node_idx];
+ type = dfa->nodes[node].type;
+ /* Avoid infinite loop for the REs like "()\1+". */
+ if (node == sctx->last_node && str_idx == sctx->last_str_idx)
+ continue;
+ if (type != OP_BACK_REF)
+ continue;
+
+ entry = mctx->bkref_ents + first_idx;
+ enabled_idx = first_idx;
+ do
+ {
+ Idx subexp_len;
+ Idx to_idx;
+ Idx dst_node;
+ bool ok;
+ re_dfastate_t *cur_state;
+
+ if (entry->node != node)
+ continue;
+ subexp_len = entry->subexp_to - entry->subexp_from;
+ to_idx = str_idx + subexp_len;
+ dst_node = (subexp_len ? dfa->nexts[node]
+ : dfa->edests[node].elems[0]);
+
+ if (to_idx > sctx->last_str_idx
+ || sctx->sifted_states[to_idx] == NULL
+ || !STATE_NODE_CONTAINS (sctx->sifted_states[to_idx], dst_node)
+ || check_dst_limits (mctx, &sctx->limits, node,
+ str_idx, dst_node, to_idx))
+ continue;
+
+ if (local_sctx.sifted_states == NULL)
+ {
+ local_sctx = *sctx;
+ err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ local_sctx.last_node = node;
+ local_sctx.last_str_idx = str_idx;
+ ok = re_node_set_insert (&local_sctx.limits, enabled_idx);
+ if (BE (! ok, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+ cur_state = local_sctx.sifted_states[str_idx];
+ err = sift_states_backward (mctx, &local_sctx);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ if (sctx->limited_states != NULL)
+ {
+ err = merge_state_array (dfa, sctx->limited_states,
+ local_sctx.sifted_states,
+ str_idx + 1);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ local_sctx.sifted_states[str_idx] = cur_state;
+ re_node_set_remove (&local_sctx.limits, enabled_idx);
+
+ /* mctx->bkref_ents may have changed, reload the pointer. */
+ entry = mctx->bkref_ents + enabled_idx;
+ }
+ while (enabled_idx++, entry++->more);
+ }
+ err = REG_NOERROR;
+ free_return:
+ if (local_sctx.sifted_states != NULL)
+ {
+ re_node_set_free (&local_sctx.limits);
+ }
+
+ return err;
+}
+
+
+#ifdef RE_ENABLE_I18N
+static int
+internal_function
+sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
+ Idx node_idx, Idx str_idx, Idx max_str_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ int naccepted;
+ /* Check the node can accept "multi byte". */
+ naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
+ if (naccepted > 0 && str_idx + naccepted <= max_str_idx &&
+ !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted],
+ dfa->nexts[node_idx]))
+ /* The node can't accept the "multi byte", or the
+ destination was already thrown away, then the node
+ could't accept the current input "multi byte". */
+ naccepted = 0;
+ /* Otherwise, it is sure that the node could accept
+ 'naccepted' bytes input. */
+ return naccepted;
+}
+#endif /* RE_ENABLE_I18N */
+
+
+/* Functions for state transition. */
+
+/* Return the next state to which the current state STATE will transit by
+ accepting the current input byte, and update STATE_LOG if necessary.
+ If STATE can accept a multibyte char/collating element/back reference
+ update the destination of STATE_LOG. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+transit_state (reg_errcode_t *err, re_match_context_t *mctx,
+ re_dfastate_t *state)
+{
+ re_dfastate_t **trtable;
+ unsigned char ch;
+
+#ifdef RE_ENABLE_I18N
+ /* If the current state can accept multibyte. */
+ if (BE (state->accept_mb, 0))
+ {
+ *err = transit_state_mb (mctx, state);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ }
+#endif /* RE_ENABLE_I18N */
+
+ /* Then decide the next state with the single byte. */
+#if 0
+ if (0)
+ /* don't use transition table */
+ return transit_state_sb (err, mctx, state);
+#endif
+
+ /* Use transition table */
+ ch = re_string_fetch_byte (&mctx->input);
+ for (;;)
+ {
+ trtable = state->trtable;
+ if (BE (trtable != NULL, 1))
+ return trtable[ch];
+
+ trtable = state->word_trtable;
+ if (BE (trtable != NULL, 1))
+ {
+ unsigned int context;
+ context
+ = re_string_context_at (&mctx->input,
+ re_string_cur_idx (&mctx->input) - 1,
+ mctx->eflags);
+ if (IS_WORD_CONTEXT (context))
+ return trtable[ch + SBC_MAX];
+ else
+ return trtable[ch];
+ }
+
+ if (!build_trtable (mctx->dfa, state))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ /* Retry, we now have a transition table. */
+ }
+}
+
+/* Update the state_log if we need */
+static re_dfastate_t *
+internal_function
+merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
+ re_dfastate_t *next_state)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx cur_idx = re_string_cur_idx (&mctx->input);
+
+ if (cur_idx > mctx->state_log_top)
+ {
+ mctx->state_log[cur_idx] = next_state;
+ mctx->state_log_top = cur_idx;
+ }
+ else if (mctx->state_log[cur_idx] == 0)
+ {
+ mctx->state_log[cur_idx] = next_state;
+ }
+ else
+ {
+ re_dfastate_t *pstate;
+ unsigned int context;
+ re_node_set next_nodes, *log_nodes, *table_nodes = NULL;
+ /* If (state_log[cur_idx] != 0), it implies that cur_idx is
+ the destination of a multibyte char/collating element/
+ back reference. Then the next state is the union set of
+ these destinations and the results of the transition table. */
+ pstate = mctx->state_log[cur_idx];
+ log_nodes = pstate->entrance_nodes;
+ if (next_state != NULL)
+ {
+ table_nodes = next_state->entrance_nodes;
+ *err = re_node_set_init_union (&next_nodes, table_nodes,
+ log_nodes);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ }
+ else
+ next_nodes = *log_nodes;
+ /* Note: We already add the nodes of the initial state,
+ then we don't need to add them here. */
+
+ context = re_string_context_at (&mctx->input,
+ re_string_cur_idx (&mctx->input) - 1,
+ mctx->eflags);
+ next_state = mctx->state_log[cur_idx]
+ = re_acquire_state_context (err, dfa, &next_nodes, context);
+ /* We don't need to check errors here, since the return value of
+ this function is next_state and ERR is already set. */
+
+ if (table_nodes != NULL)
+ re_node_set_free (&next_nodes);
+ }
+
+ if (BE (dfa->nbackref, 0) && next_state != NULL)
+ {
+ /* Check OP_OPEN_SUBEXP in the current state in case that we use them
+ later. We must check them here, since the back references in the
+ next state might use them. */
+ *err = check_subexp_matching_top (mctx, &next_state->nodes,
+ cur_idx);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+
+ /* If the next state has back references. */
+ if (next_state->has_backref)
+ {
+ *err = transit_state_bkref (mctx, &next_state->nodes);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ next_state = mctx->state_log[cur_idx];
+ }
+ }
+
+ return next_state;
+}
+
+/* Skip bytes in the input that correspond to part of a
+ multi-byte match, then look in the log for a state
+ from which to restart matching. */
+static re_dfastate_t *
+internal_function
+find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
+{
+ re_dfastate_t *cur_state;
+ do
+ {
+ Idx max = mctx->state_log_top;
+ Idx cur_str_idx = re_string_cur_idx (&mctx->input);
+
+ do
+ {
+ if (++cur_str_idx > max)
+ return NULL;
+ re_string_skip_bytes (&mctx->input, 1);
+ }
+ while (mctx->state_log[cur_str_idx] == NULL);
+
+ cur_state = merge_state_with_log (err, mctx, NULL);
+ }
+ while (*err == REG_NOERROR && cur_state == NULL);
+ return cur_state;
+}
+
+/* Helper functions for transit_state. */
+
+/* From the node set CUR_NODES, pick up the nodes whose types are
+ OP_OPEN_SUBEXP and which have corresponding back references in the regular
+ expression. And register them to use them later for evaluating the
+ corresponding back references. */
+
+static reg_errcode_t
+internal_function
+check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
+ Idx str_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx node_idx;
+ reg_errcode_t err;
+
+ /* TODO: This isn't efficient.
+ Because there might be more than one nodes whose types are
+ OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all
+ nodes.
+ E.g. RE: (a){2} */
+ for (node_idx = 0; node_idx < cur_nodes->nelem; ++node_idx)
+ {
+ Idx node = cur_nodes->elems[node_idx];
+ if (dfa->nodes[node].type == OP_OPEN_SUBEXP
+ && dfa->nodes[node].opr.idx < BITSET_WORD_BITS
+ && (dfa->used_bkref_map
+ & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx)))
+ {
+ err = match_ctx_add_subtop (mctx, node, str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ return REG_NOERROR;
+}
+
+#if 0
+/* Return the next state to which the current state STATE will transit by
+ accepting the current input byte. */
+
+static re_dfastate_t *
+transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
+ re_dfastate_t *state)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ re_node_set next_nodes;
+ re_dfastate_t *next_state;
+ Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
+ unsigned int context;
+
+ *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt)
+ {
+ Idx cur_node = state->nodes.elems[node_cnt];
+ if (check_node_accept (mctx, dfa->nodes + cur_node, cur_str_idx))
+ {
+ *err = re_node_set_merge (&next_nodes,
+ dfa->eclosures + dfa->nexts[cur_node]);
+ if (BE (*err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return NULL;
+ }
+ }
+ }
+ context = re_string_context_at (&mctx->input, cur_str_idx, mctx->eflags);
+ next_state = re_acquire_state_context (err, dfa, &next_nodes, context);
+ /* We don't need to check errors here, since the return value of
+ this function is next_state and ERR is already set. */
+
+ re_node_set_free (&next_nodes);
+ re_string_skip_bytes (&mctx->input, 1);
+ return next_state;
+}
+#endif
+
+#ifdef RE_ENABLE_I18N
+static reg_errcode_t
+internal_function
+transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx i;
+
+ for (i = 0; i < pstate->nodes.nelem; ++i)
+ {
+ re_node_set dest_nodes, *new_nodes;
+ Idx cur_node_idx = pstate->nodes.elems[i];
+ int naccepted;
+ Idx dest_idx;
+ unsigned int context;
+ re_dfastate_t *dest_state;
+
+ if (!dfa->nodes[cur_node_idx].accept_mb)
+ continue;
+
+ if (dfa->nodes[cur_node_idx].constraint)
+ {
+ context = re_string_context_at (&mctx->input,
+ re_string_cur_idx (&mctx->input),
+ mctx->eflags);
+ if (NOT_SATISFY_NEXT_CONSTRAINT (dfa->nodes[cur_node_idx].constraint,
+ context))
+ continue;
+ }
+
+ /* How many bytes the node can accept? */
+ naccepted = check_node_accept_bytes (dfa, cur_node_idx, &mctx->input,
+ re_string_cur_idx (&mctx->input));
+ if (naccepted == 0)
+ continue;
+
+ /* The node can accepts 'naccepted' bytes. */
+ dest_idx = re_string_cur_idx (&mctx->input) + naccepted;
+ mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
+ : mctx->max_mb_elem_len);
+ err = clean_state_log_if_needed (mctx, dest_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+#ifdef DEBUG
+ assert (dfa->nexts[cur_node_idx] != REG_MISSING);
+#endif
+ new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx];
+
+ dest_state = mctx->state_log[dest_idx];
+ if (dest_state == NULL)
+ dest_nodes = *new_nodes;
+ else
+ {
+ err = re_node_set_init_union (&dest_nodes,
+ dest_state->entrance_nodes, new_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ context = re_string_context_at (&mctx->input, dest_idx - 1,
+ mctx->eflags);
+ mctx->state_log[dest_idx]
+ = re_acquire_state_context (&err, dfa, &dest_nodes, context);
+ if (dest_state != NULL)
+ re_node_set_free (&dest_nodes);
+ if (BE (mctx->state_log[dest_idx] == NULL && err != REG_NOERROR, 0))
+ return err;
+ }
+ return REG_NOERROR;
+}
+#endif /* RE_ENABLE_I18N */
+
+static reg_errcode_t
+internal_function
+transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx i;
+ Idx cur_str_idx = re_string_cur_idx (&mctx->input);
+
+ for (i = 0; i < nodes->nelem; ++i)
+ {
+ Idx dest_str_idx, prev_nelem, bkc_idx;
+ Idx node_idx = nodes->elems[i];
+ unsigned int context;
+ const re_token_t *node = dfa->nodes + node_idx;
+ re_node_set *new_dest_nodes;
+
+ /* Check whether 'node' is a backreference or not. */
+ if (node->type != OP_BACK_REF)
+ continue;
+
+ if (node->constraint)
+ {
+ context = re_string_context_at (&mctx->input, cur_str_idx,
+ mctx->eflags);
+ if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
+ continue;
+ }
+
+ /* 'node' is a backreference.
+ Check the substring which the substring matched. */
+ bkc_idx = mctx->nbkref_ents;
+ err = get_subexp (mctx, node_idx, cur_str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ /* And add the epsilon closures (which is 'new_dest_nodes') of
+ the backreference to appropriate state_log. */
+#ifdef DEBUG
+ assert (dfa->nexts[node_idx] != REG_MISSING);
+#endif
+ for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx)
+ {
+ Idx subexp_len;
+ re_dfastate_t *dest_state;
+ struct re_backref_cache_entry *bkref_ent;
+ bkref_ent = mctx->bkref_ents + bkc_idx;
+ if (bkref_ent->node != node_idx || bkref_ent->str_idx != cur_str_idx)
+ continue;
+ subexp_len = bkref_ent->subexp_to - bkref_ent->subexp_from;
+ new_dest_nodes = (subexp_len == 0
+ ? dfa->eclosures + dfa->edests[node_idx].elems[0]
+ : dfa->eclosures + dfa->nexts[node_idx]);
+ dest_str_idx = (cur_str_idx + bkref_ent->subexp_to
+ - bkref_ent->subexp_from);
+ context = re_string_context_at (&mctx->input, dest_str_idx - 1,
+ mctx->eflags);
+ dest_state = mctx->state_log[dest_str_idx];
+ prev_nelem = ((mctx->state_log[cur_str_idx] == NULL) ? 0
+ : mctx->state_log[cur_str_idx]->nodes.nelem);
+ /* Add 'new_dest_node' to state_log. */
+ if (dest_state == NULL)
+ {
+ mctx->state_log[dest_str_idx]
+ = re_acquire_state_context (&err, dfa, new_dest_nodes,
+ context);
+ if (BE (mctx->state_log[dest_str_idx] == NULL
+ && err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ else
+ {
+ re_node_set dest_nodes;
+ err = re_node_set_init_union (&dest_nodes,
+ dest_state->entrance_nodes,
+ new_dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&dest_nodes);
+ goto free_return;
+ }
+ mctx->state_log[dest_str_idx]
+ = re_acquire_state_context (&err, dfa, &dest_nodes, context);
+ re_node_set_free (&dest_nodes);
+ if (BE (mctx->state_log[dest_str_idx] == NULL
+ && err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ /* We need to check recursively if the backreference can epsilon
+ transit. */
+ if (subexp_len == 0
+ && mctx->state_log[cur_str_idx]->nodes.nelem > prev_nelem)
+ {
+ err = check_subexp_matching_top (mctx, new_dest_nodes,
+ cur_str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ err = transit_state_bkref (mctx, new_dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ }
+ }
+ err = REG_NOERROR;
+ free_return:
+ return err;
+}
+
+/* Enumerate all the candidates which the backreference BKREF_NODE can match
+ at BKREF_STR_IDX, and register them by match_ctx_add_entry().
+ Note that we might collect inappropriate candidates here.
+ However, the cost of checking them strictly here is too high, then we
+ delay these checking for prune_impossible_nodes(). */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx subexp_num, sub_top_idx;
+ const char *buf = (const char *) re_string_get_buffer (&mctx->input);
+ /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
+ Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
+ if (cache_idx != REG_MISSING)
+ {
+ const struct re_backref_cache_entry *entry
+ = mctx->bkref_ents + cache_idx;
+ do
+ if (entry->node == bkref_node)
+ return REG_NOERROR; /* We already checked it. */
+ while (entry++->more);
+ }
+
+ subexp_num = dfa->nodes[bkref_node].opr.idx;
+
+ /* For each sub expression */
+ for (sub_top_idx = 0; sub_top_idx < mctx->nsub_tops; ++sub_top_idx)
+ {
+ reg_errcode_t err;
+ re_sub_match_top_t *sub_top = mctx->sub_tops[sub_top_idx];
+ re_sub_match_last_t *sub_last;
+ Idx sub_last_idx, sl_str, bkref_str_off;
+
+ if (dfa->nodes[sub_top->node].opr.idx != subexp_num)
+ continue; /* It isn't related. */
+
+ sl_str = sub_top->str_idx;
+ bkref_str_off = bkref_str_idx;
+ /* At first, check the last node of sub expressions we already
+ evaluated. */
+ for (sub_last_idx = 0; sub_last_idx < sub_top->nlasts; ++sub_last_idx)
+ {
+ regoff_t sl_str_diff;
+ sub_last = sub_top->lasts[sub_last_idx];
+ sl_str_diff = sub_last->str_idx - sl_str;
+ /* The matched string by the sub expression match with the substring
+ at the back reference? */
+ if (sl_str_diff > 0)
+ {
+ if (BE (bkref_str_off + sl_str_diff > mctx->input.valid_len, 0))
+ {
+ /* Not enough chars for a successful match. */
+ if (bkref_str_off + sl_str_diff > mctx->input.len)
+ break;
+
+ err = clean_state_log_if_needed (mctx,
+ bkref_str_off
+ + sl_str_diff);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ buf = (const char *) re_string_get_buffer (&mctx->input);
+ }
+ if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0)
+ /* We don't need to search this sub expression any more. */
+ break;
+ }
+ bkref_str_off += sl_str_diff;
+ sl_str += sl_str_diff;
+ err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
+ bkref_str_idx);
+
+ /* Reload buf, since the preceding call might have reallocated
+ the buffer. */
+ buf = (const char *) re_string_get_buffer (&mctx->input);
+
+ if (err == REG_NOMATCH)
+ continue;
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ if (sub_last_idx < sub_top->nlasts)
+ continue;
+ if (sub_last_idx > 0)
+ ++sl_str;
+ /* Then, search for the other last nodes of the sub expression. */
+ for (; sl_str <= bkref_str_idx; ++sl_str)
+ {
+ Idx cls_node;
+ regoff_t sl_str_off;
+ const re_node_set *nodes;
+ sl_str_off = sl_str - sub_top->str_idx;
+ /* The matched string by the sub expression match with the substring
+ at the back reference? */
+ if (sl_str_off > 0)
+ {
+ if (BE (bkref_str_off >= mctx->input.valid_len, 0))
+ {
+ /* If we are at the end of the input, we cannot match. */
+ if (bkref_str_off >= mctx->input.len)
+ break;
+
+ err = extend_buffers (mctx, bkref_str_off + 1);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ buf = (const char *) re_string_get_buffer (&mctx->input);
+ }
+ if (buf [bkref_str_off++] != buf[sl_str - 1])
+ break; /* We don't need to search this sub expression
+ any more. */
+ }
+ if (mctx->state_log[sl_str] == NULL)
+ continue;
+ /* Does this state have a ')' of the sub expression? */
+ nodes = &mctx->state_log[sl_str]->nodes;
+ cls_node = find_subexp_node (dfa, nodes, subexp_num,
+ OP_CLOSE_SUBEXP);
+ if (cls_node == REG_MISSING)
+ continue; /* No. */
+ if (sub_top->path == NULL)
+ {
+ sub_top->path = calloc (sizeof (state_array_t),
+ sl_str - sub_top->str_idx + 1);
+ if (sub_top->path == NULL)
+ return REG_ESPACE;
+ }
+ /* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node
+ in the current context? */
+ err = check_arrival (mctx, sub_top->path, sub_top->node,
+ sub_top->str_idx, cls_node, sl_str,
+ OP_CLOSE_SUBEXP);
+ if (err == REG_NOMATCH)
+ continue;
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str);
+ if (BE (sub_last == NULL, 0))
+ return REG_ESPACE;
+ err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
+ bkref_str_idx);
+ if (err == REG_NOMATCH)
+ continue;
+ }
+ }
+ return REG_NOERROR;
+}
+
+/* Helper functions for get_subexp(). */
+
+/* Check SUB_LAST can arrive to the back reference BKREF_NODE at BKREF_STR.
+ If it can arrive, register the sub expression expressed with SUB_TOP
+ and SUB_LAST. */
+
+static reg_errcode_t
+internal_function
+get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
+ re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str)
+{
+ reg_errcode_t err;
+ Idx to_idx;
+ /* Can the subexpression arrive the back reference? */
+ err = check_arrival (mctx, &sub_last->path, sub_last->node,
+ sub_last->str_idx, bkref_node, bkref_str,
+ OP_OPEN_SUBEXP);
+ if (err != REG_NOERROR)
+ return err;
+ err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
+ sub_last->str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx;
+ return clean_state_log_if_needed (mctx, to_idx);
+}
+
+/* Find the first node which is '(' or ')' and whose index is SUBEXP_IDX.
+ Search '(' if FL_OPEN, or search ')' otherwise.
+ TODO: This function isn't efficient...
+ Because there might be more than one nodes whose types are
+ OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all
+ nodes.
+ E.g. RE: (a){2} */
+
+static Idx
+internal_function
+find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
+ Idx subexp_idx, int type)
+{
+ Idx cls_idx;
+ for (cls_idx = 0; cls_idx < nodes->nelem; ++cls_idx)
+ {
+ Idx cls_node = nodes->elems[cls_idx];
+ const re_token_t *node = dfa->nodes + cls_node;
+ if (node->type == type
+ && node->opr.idx == subexp_idx)
+ return cls_node;
+ }
+ return REG_MISSING;
+}
+
+/* Check whether the node TOP_NODE at TOP_STR can arrive to the node
+ LAST_NODE at LAST_STR. We record the path onto PATH since it will be
+ heavily reused.
+ Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
+ Idx top_str, Idx last_node, Idx last_str, int type)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err = REG_NOERROR;
+ Idx subexp_num, backup_cur_idx, str_idx, null_cnt;
+ re_dfastate_t *cur_state = NULL;
+ re_node_set *cur_nodes, next_nodes;
+ re_dfastate_t **backup_state_log;
+ unsigned int context;
+
+ subexp_num = dfa->nodes[top_node].opr.idx;
+ /* Extend the buffer if we need. */
+ if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0))
+ {
+ re_dfastate_t **new_array;
+ Idx old_alloc = path->alloc;
+ Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1;
+ Idx new_alloc;
+ if (BE (IDX_MAX - old_alloc < incr_alloc, 0))
+ return REG_ESPACE;
+ new_alloc = old_alloc + incr_alloc;
+ if (BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0))
+ return REG_ESPACE;
+ new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ path->array = new_array;
+ path->alloc = new_alloc;
+ memset (new_array + old_alloc, '\0',
+ sizeof (re_dfastate_t *) * (path->alloc - old_alloc));
+ }
+
+ str_idx = path->next_idx ? path->next_idx : top_str;
+
+ /* Temporary modify MCTX. */
+ backup_state_log = mctx->state_log;
+ backup_cur_idx = mctx->input.cur_idx;
+ mctx->state_log = path->array;
+ mctx->input.cur_idx = str_idx;
+
+ /* Setup initial node set. */
+ context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
+ if (str_idx == top_str)
+ {
+ err = re_node_set_init_1 (&next_nodes, top_node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ else
+ {
+ cur_state = mctx->state_log[str_idx];
+ if (cur_state && cur_state->has_backref)
+ {
+ err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ else
+ re_node_set_init_empty (&next_nodes);
+ }
+ if (str_idx == top_str || (cur_state && cur_state->has_backref))
+ {
+ if (next_nodes.nelem)
+ {
+ err = expand_bkref_cache (mctx, &next_nodes, str_idx,
+ subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
+ if (BE (cur_state == NULL && err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ mctx->state_log[str_idx] = cur_state;
+ }
+
+ for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;)
+ {
+ re_node_set_empty (&next_nodes);
+ if (mctx->state_log[str_idx + 1])
+ {
+ err = re_node_set_merge (&next_nodes,
+ &mctx->state_log[str_idx + 1]->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ if (cur_state)
+ {
+ err = check_arrival_add_next_nodes (mctx, str_idx,
+ &cur_state->non_eps_nodes,
+ &next_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ ++str_idx;
+ if (next_nodes.nelem)
+ {
+ err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ err = expand_bkref_cache (mctx, &next_nodes, str_idx,
+ subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
+ cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
+ if (BE (cur_state == NULL && err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ mctx->state_log[str_idx] = cur_state;
+ null_cnt = cur_state == NULL ? null_cnt + 1 : 0;
+ }
+ re_node_set_free (&next_nodes);
+ cur_nodes = (mctx->state_log[last_str] == NULL ? NULL
+ : &mctx->state_log[last_str]->nodes);
+ path->next_idx = str_idx;
+
+ /* Fix MCTX. */
+ mctx->state_log = backup_state_log;
+ mctx->input.cur_idx = backup_cur_idx;
+
+ /* Then check the current node set has the node LAST_NODE. */
+ if (cur_nodes != NULL && re_node_set_contains (cur_nodes, last_node))
+ return REG_NOERROR;
+
+ return REG_NOMATCH;
+}
+
+/* Helper functions for check_arrival. */
+
+/* Calculate the destination nodes of CUR_NODES at STR_IDX, and append them
+ to NEXT_NODES.
+ TODO: This function is similar to the functions transit_state*(),
+ however this function has many additional works.
+ Can't we unify them? */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
+ re_node_set *cur_nodes, re_node_set *next_nodes)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ bool ok;
+ Idx cur_idx;
+#ifdef RE_ENABLE_I18N
+ reg_errcode_t err = REG_NOERROR;
+#endif
+ re_node_set union_set;
+ re_node_set_init_empty (&union_set);
+ for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
+ {
+ int naccepted = 0;
+ Idx cur_node = cur_nodes->elems[cur_idx];
+#ifdef DEBUG
+ re_token_type_t type = dfa->nodes[cur_node].type;
+ assert (!IS_EPSILON_NODE (type));
+#endif
+#ifdef RE_ENABLE_I18N
+ /* If the node may accept "multi byte". */
+ if (dfa->nodes[cur_node].accept_mb)
+ {
+ naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input,
+ str_idx);
+ if (naccepted > 1)
+ {
+ re_dfastate_t *dest_state;
+ Idx next_node = dfa->nexts[cur_node];
+ Idx next_idx = str_idx + naccepted;
+ dest_state = mctx->state_log[next_idx];
+ re_node_set_empty (&union_set);
+ if (dest_state)
+ {
+ err = re_node_set_merge (&union_set, &dest_state->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&union_set);
+ return err;
+ }
+ }
+ ok = re_node_set_insert (&union_set, next_node);
+ if (BE (! ok, 0))
+ {
+ re_node_set_free (&union_set);
+ return REG_ESPACE;
+ }
+ mctx->state_log[next_idx] = re_acquire_state (&err, dfa,
+ &union_set);
+ if (BE (mctx->state_log[next_idx] == NULL
+ && err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&union_set);
+ return err;
+ }
+ }
+ }
+#endif /* RE_ENABLE_I18N */
+ if (naccepted
+ || check_node_accept (mctx, dfa->nodes + cur_node, str_idx))
+ {
+ ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
+ if (BE (! ok, 0))
+ {
+ re_node_set_free (&union_set);
+ return REG_ESPACE;
+ }
+ }
+ }
+ re_node_set_free (&union_set);
+ return REG_NOERROR;
+}
+
+/* For all the nodes in CUR_NODES, add the epsilon closures of them to
+ CUR_NODES, however exclude the nodes which are:
+ - inside the sub expression whose number is EX_SUBEXP, if FL_OPEN.
+ - out of the sub expression whose number is EX_SUBEXP, if !FL_OPEN.
+*/
+
+static reg_errcode_t
+internal_function
+check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
+ Idx ex_subexp, int type)
+{
+ reg_errcode_t err;
+ Idx idx, outside_node;
+ re_node_set new_nodes;
+#ifdef DEBUG
+ assert (cur_nodes->nelem);
+#endif
+ err = re_node_set_alloc (&new_nodes, cur_nodes->nelem);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ /* Create a new node set NEW_NODES with the nodes which are epsilon
+ closures of the node in CUR_NODES. */
+
+ for (idx = 0; idx < cur_nodes->nelem; ++idx)
+ {
+ Idx cur_node = cur_nodes->elems[idx];
+ const re_node_set *eclosure = dfa->eclosures + cur_node;
+ outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
+ if (outside_node == REG_MISSING)
+ {
+ /* There are no problematic nodes, just merge them. */
+ err = re_node_set_merge (&new_nodes, eclosure);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&new_nodes);
+ return err;
+ }
+ }
+ else
+ {
+ /* There are problematic nodes, re-calculate incrementally. */
+ err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node,
+ ex_subexp, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&new_nodes);
+ return err;
+ }
+ }
+ }
+ re_node_set_free (cur_nodes);
+ *cur_nodes = new_nodes;
+ return REG_NOERROR;
+}
+
+/* Helper function for check_arrival_expand_ecl.
+ Check incrementally the epsilon closure of TARGET, and if it isn't
+ problematic append it to DST_NODES. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
+ Idx target, Idx ex_subexp, int type)
+{
+ Idx cur_node;
+ for (cur_node = target; !re_node_set_contains (dst_nodes, cur_node);)
+ {
+ bool ok;
+
+ if (dfa->nodes[cur_node].type == type
+ && dfa->nodes[cur_node].opr.idx == ex_subexp)
+ {
+ if (type == OP_CLOSE_SUBEXP)
+ {
+ ok = re_node_set_insert (dst_nodes, cur_node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ break;
+ }
+ ok = re_node_set_insert (dst_nodes, cur_node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ if (dfa->edests[cur_node].nelem == 0)
+ break;
+ if (dfa->edests[cur_node].nelem == 2)
+ {
+ reg_errcode_t err;
+ err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
+ dfa->edests[cur_node].elems[1],
+ ex_subexp, type);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ cur_node = dfa->edests[cur_node].elems[0];
+ }
+ return REG_NOERROR;
+}
+
+
+/* For all the back references in the current state, calculate the
+ destination of the back references by the appropriate entry
+ in MCTX->BKREF_ENTS. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
+ Idx cur_str, Idx subexp_num, int type)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
+ struct re_backref_cache_entry *ent;
+
+ if (cache_idx_start == REG_MISSING)
+ return REG_NOERROR;
+
+ restart:
+ ent = mctx->bkref_ents + cache_idx_start;
+ do
+ {
+ Idx to_idx, next_node;
+
+ /* Is this entry ENT is appropriate? */
+ if (!re_node_set_contains (cur_nodes, ent->node))
+ continue; /* No. */
+
+ to_idx = cur_str + ent->subexp_to - ent->subexp_from;
+ /* Calculate the destination of the back reference, and append it
+ to MCTX->STATE_LOG. */
+ if (to_idx == cur_str)
+ {
+ /* The backreference did epsilon transit, we must re-check all the
+ node in the current state. */
+ re_node_set new_dests;
+ reg_errcode_t err2, err3;
+ next_node = dfa->edests[ent->node].elems[0];
+ if (re_node_set_contains (cur_nodes, next_node))
+ continue;
+ err = re_node_set_init_1 (&new_dests, next_node);
+ err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type);
+ err3 = re_node_set_merge (cur_nodes, &new_dests);
+ re_node_set_free (&new_dests);
+ if (BE (err != REG_NOERROR || err2 != REG_NOERROR
+ || err3 != REG_NOERROR, 0))
+ {
+ err = (err != REG_NOERROR ? err
+ : (err2 != REG_NOERROR ? err2 : err3));
+ return err;
+ }
+ /* TODO: It is still inefficient... */
+ goto restart;
+ }
+ else
+ {
+ re_node_set union_set;
+ next_node = dfa->nexts[ent->node];
+ if (mctx->state_log[to_idx])
+ {
+ bool ok;
+ if (re_node_set_contains (&mctx->state_log[to_idx]->nodes,
+ next_node))
+ continue;
+ err = re_node_set_init_copy (&union_set,
+ &mctx->state_log[to_idx]->nodes);
+ ok = re_node_set_insert (&union_set, next_node);
+ if (BE (err != REG_NOERROR || ! ok, 0))
+ {
+ re_node_set_free (&union_set);
+ err = err != REG_NOERROR ? err : REG_ESPACE;
+ return err;
+ }
+ }
+ else
+ {
+ err = re_node_set_init_1 (&union_set, next_node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set);
+ re_node_set_free (&union_set);
+ if (BE (mctx->state_log[to_idx] == NULL
+ && err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ while (ent++->more);
+ return REG_NOERROR;
+}
+
+/* Build transition table for the state.
+ Return true if successful. */
+
+static bool
+internal_function
+build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
+{
+ reg_errcode_t err;
+ Idx i, j;
+ int ch;
+ bool need_word_trtable = false;
+ bitset_word_t elem, mask;
+ bool dests_node_malloced = false;
+ bool dest_states_malloced = false;
+ Idx ndests; /* Number of the destination states from 'state'. */
+ re_dfastate_t **trtable;
+ re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
+ re_node_set follows, *dests_node;
+ bitset_t *dests_ch;
+ bitset_t acceptable;
+
+ struct dests_alloc
+ {
+ re_node_set dests_node[SBC_MAX];
+ bitset_t dests_ch[SBC_MAX];
+ } *dests_alloc;
+
+ /* We build DFA states which corresponds to the destination nodes
+ from 'state'. 'dests_node[i]' represents the nodes which i-th
+ destination state contains, and 'dests_ch[i]' represents the
+ characters which i-th destination state accepts. */
+ if (__libc_use_alloca (sizeof (struct dests_alloc)))
+ dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc));
+ else
+ {
+ dests_alloc = re_malloc (struct dests_alloc, 1);
+ if (BE (dests_alloc == NULL, 0))
+ return false;
+ dests_node_malloced = true;
+ }
+ dests_node = dests_alloc->dests_node;
+ dests_ch = dests_alloc->dests_ch;
+
+ /* Initialize transition table. */
+ state->word_trtable = state->trtable = NULL;
+
+ /* At first, group all nodes belonging to 'state' into several
+ destinations. */
+ ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch);
+ if (BE (! REG_VALID_NONZERO_INDEX (ndests), 0))
+ {
+ if (dests_node_malloced)
+ free (dests_alloc);
+ /* Return false in case of an error, true otherwise. */
+ if (ndests == 0)
+ {
+ state->trtable = (re_dfastate_t **)
+ calloc (sizeof (re_dfastate_t *), SBC_MAX);
+ if (BE (state->trtable == NULL, 0))
+ return false;
+ return true;
+ }
+ return false;
+ }
+
+ err = re_node_set_alloc (&follows, ndests + 1);
+ if (BE (err != REG_NOERROR, 0))
+ goto out_free;
+
+ /* Avoid arithmetic overflow in size calculation. */
+ if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX)
+ / (3 * sizeof (re_dfastate_t *)))
+ < ndests),
+ 0))
+ goto out_free;
+
+ if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX
+ + ndests * 3 * sizeof (re_dfastate_t *)))
+ dest_states = (re_dfastate_t **)
+ alloca (ndests * 3 * sizeof (re_dfastate_t *));
+ else
+ {
+ dest_states = (re_dfastate_t **)
+ malloc (ndests * 3 * sizeof (re_dfastate_t *));
+ if (BE (dest_states == NULL, 0))
+ {
+out_free:
+ if (dest_states_malloced)
+ free (dest_states);
+ re_node_set_free (&follows);
+ for (i = 0; i < ndests; ++i)
+ re_node_set_free (dests_node + i);
+ if (dests_node_malloced)
+ free (dests_alloc);
+ return false;
+ }
+ dest_states_malloced = true;
+ }
+ dest_states_word = dest_states + ndests;
+ dest_states_nl = dest_states_word + ndests;
+ bitset_empty (acceptable);
+
+ /* Then build the states for all destinations. */
+ for (i = 0; i < ndests; ++i)
+ {
+ Idx next_node;
+ re_node_set_empty (&follows);
+ /* Merge the follows of this destination states. */
+ for (j = 0; j < dests_node[i].nelem; ++j)
+ {
+ next_node = dfa->nexts[dests_node[i].elems[j]];
+ if (next_node != REG_MISSING)
+ {
+ err = re_node_set_merge (&follows, dfa->eclosures + next_node);
+ if (BE (err != REG_NOERROR, 0))
+ goto out_free;
+ }
+ }
+ dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0);
+ if (BE (dest_states[i] == NULL && err != REG_NOERROR, 0))
+ goto out_free;
+ /* If the new state has context constraint,
+ build appropriate states for these contexts. */
+ if (dest_states[i]->has_constraint)
+ {
+ dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows,
+ CONTEXT_WORD);
+ if (BE (dest_states_word[i] == NULL && err != REG_NOERROR, 0))
+ goto out_free;
+
+ if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1)
+ need_word_trtable = true;
+
+ dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows,
+ CONTEXT_NEWLINE);
+ if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0))
+ goto out_free;
+ }
+ else
+ {
+ dest_states_word[i] = dest_states[i];
+ dest_states_nl[i] = dest_states[i];
+ }
+ bitset_merge (acceptable, dests_ch[i]);
+ }
+
+ if (!BE (need_word_trtable, 0))
+ {
+ /* We don't care about whether the following character is a word
+ character, or we are in a single-byte character set so we can
+ discern by looking at the character code: allocate a
+ 256-entry transition table. */
+ trtable = state->trtable =
+ (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
+ if (BE (trtable == NULL, 0))
+ goto out_free;
+
+ /* For all characters ch...: */
+ for (i = 0; i < BITSET_WORDS; ++i)
+ for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
+ elem;
+ mask <<= 1, elem >>= 1, ++ch)
+ if (BE (elem & 1, 0))
+ {
+ /* There must be exactly one destination which accepts
+ character ch. See group_nodes_into_DFAstates. */
+ for (j = 0; (dests_ch[j][i] & mask) == 0; ++j)
+ ;
+
+ /* j-th destination accepts the word character ch. */
+ if (dfa->word_char[i] & mask)
+ trtable[ch] = dest_states_word[j];
+ else
+ trtable[ch] = dest_states[j];
+ }
+ }
+ else
+ {
+ /* We care about whether the following character is a word
+ character, and we are in a multi-byte character set: discern
+ by looking at the character code: build two 256-entry
+ transition tables, one starting at trtable[0] and one
+ starting at trtable[SBC_MAX]. */
+ trtable = state->word_trtable =
+ (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
+ if (BE (trtable == NULL, 0))
+ goto out_free;
+
+ /* For all characters ch...: */
+ for (i = 0; i < BITSET_WORDS; ++i)
+ for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
+ elem;
+ mask <<= 1, elem >>= 1, ++ch)
+ if (BE (elem & 1, 0))
+ {
+ /* There must be exactly one destination which accepts
+ character ch. See group_nodes_into_DFAstates. */
+ for (j = 0; (dests_ch[j][i] & mask) == 0; ++j)
+ ;
+
+ /* j-th destination accepts the word character ch. */
+ trtable[ch] = dest_states[j];
+ trtable[ch + SBC_MAX] = dest_states_word[j];
+ }
+ }
+
+ /* new line */
+ if (bitset_contain (acceptable, NEWLINE_CHAR))
+ {
+ /* The current state accepts newline character. */
+ for (j = 0; j < ndests; ++j)
+ if (bitset_contain (dests_ch[j], NEWLINE_CHAR))
+ {
+ /* k-th destination accepts newline character. */
+ trtable[NEWLINE_CHAR] = dest_states_nl[j];
+ if (need_word_trtable)
+ trtable[NEWLINE_CHAR + SBC_MAX] = dest_states_nl[j];
+ /* There must be only one destination which accepts
+ newline. See group_nodes_into_DFAstates. */
+ break;
+ }
+ }
+
+ if (dest_states_malloced)
+ free (dest_states);
+
+ re_node_set_free (&follows);
+ for (i = 0; i < ndests; ++i)
+ re_node_set_free (dests_node + i);
+
+ if (dests_node_malloced)
+ free (dests_alloc);
+
+ return true;
+}
+
+/* Group all nodes belonging to STATE into several destinations.
+ Then for all destinations, set the nodes belonging to the destination
+ to DESTS_NODE[i] and set the characters accepted by the destination
+ to DEST_CH[i]. This function return the number of destinations. */
+
+static Idx
+internal_function
+group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
+ re_node_set *dests_node, bitset_t *dests_ch)
+{
+ reg_errcode_t err;
+ bool ok;
+ Idx i, j, k;
+ Idx ndests; /* Number of the destinations from 'state'. */
+ bitset_t accepts; /* Characters a node can accept. */
+ const re_node_set *cur_nodes = &state->nodes;
+ bitset_empty (accepts);
+ ndests = 0;
+
+ /* For all the nodes belonging to 'state', */
+ for (i = 0; i < cur_nodes->nelem; ++i)
+ {
+ re_token_t *node = &dfa->nodes[cur_nodes->elems[i]];
+ re_token_type_t type = node->type;
+ unsigned int constraint = node->constraint;
+
+ /* Enumerate all single byte character this node can accept. */
+ if (type == CHARACTER)
+ bitset_set (accepts, node->opr.c);
+ else if (type == SIMPLE_BRACKET)
+ {
+ bitset_merge (accepts, node->opr.sbcset);
+ }
+ else if (type == OP_PERIOD)
+ {
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ bitset_merge (accepts, dfa->sb_char);
+ else
+#endif
+ bitset_set_all (accepts);
+ if (!(dfa->syntax & RE_DOT_NEWLINE))
+ bitset_clear (accepts, '\n');
+ if (dfa->syntax & RE_DOT_NOT_NULL)
+ bitset_clear (accepts, '\0');
+ }
+#ifdef RE_ENABLE_I18N
+ else if (type == OP_UTF8_PERIOD)
+ {
+ if (ASCII_CHARS % BITSET_WORD_BITS == 0)
+ memset (accepts, -1, ASCII_CHARS / CHAR_BIT);
+ else
+ bitset_merge (accepts, utf8_sb_map);
+ if (!(dfa->syntax & RE_DOT_NEWLINE))
+ bitset_clear (accepts, '\n');
+ if (dfa->syntax & RE_DOT_NOT_NULL)
+ bitset_clear (accepts, '\0');
+ }
+#endif
+ else
+ continue;
+
+ /* Check the 'accepts' and sift the characters which are not
+ match it the context. */
+ if (constraint)
+ {
+ if (constraint & NEXT_NEWLINE_CONSTRAINT)
+ {
+ bool accepts_newline = bitset_contain (accepts, NEWLINE_CHAR);
+ bitset_empty (accepts);
+ if (accepts_newline)
+ bitset_set (accepts, NEWLINE_CHAR);
+ else
+ continue;
+ }
+ if (constraint & NEXT_ENDBUF_CONSTRAINT)
+ {
+ bitset_empty (accepts);
+ continue;
+ }
+
+ if (constraint & NEXT_WORD_CONSTRAINT)
+ {
+ bitset_word_t any_set = 0;
+ if (type == CHARACTER && !node->word_char)
+ {
+ bitset_empty (accepts);
+ continue;
+ }
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= (dfa->word_char[j] | ~dfa->sb_char[j]));
+ else
+#endif
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= dfa->word_char[j]);
+ if (!any_set)
+ continue;
+ }
+ if (constraint & NEXT_NOTWORD_CONSTRAINT)
+ {
+ bitset_word_t any_set = 0;
+ if (type == CHARACTER && node->word_char)
+ {
+ bitset_empty (accepts);
+ continue;
+ }
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= ~(dfa->word_char[j] & dfa->sb_char[j]));
+ else
+#endif
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= ~dfa->word_char[j]);
+ if (!any_set)
+ continue;
+ }
+ }
+
+ /* Then divide 'accepts' into DFA states, or create a new
+ state. Above, we make sure that accepts is not empty. */
+ for (j = 0; j < ndests; ++j)
+ {
+ bitset_t intersec; /* Intersection sets, see below. */
+ bitset_t remains;
+ /* Flags, see below. */
+ bitset_word_t has_intersec, not_subset, not_consumed;
+
+ /* Optimization, skip if this state doesn't accept the character. */
+ if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c))
+ continue;
+
+ /* Enumerate the intersection set of this state and 'accepts'. */
+ has_intersec = 0;
+ for (k = 0; k < BITSET_WORDS; ++k)
+ has_intersec |= intersec[k] = accepts[k] & dests_ch[j][k];
+ /* And skip if the intersection set is empty. */
+ if (!has_intersec)
+ continue;
+
+ /* Then check if this state is a subset of 'accepts'. */
+ not_subset = not_consumed = 0;
+ for (k = 0; k < BITSET_WORDS; ++k)
+ {
+ not_subset |= remains[k] = ~accepts[k] & dests_ch[j][k];
+ not_consumed |= accepts[k] = accepts[k] & ~dests_ch[j][k];
+ }
+
+ /* If this state isn't a subset of 'accepts', create a
+ new group state, which has the 'remains'. */
+ if (not_subset)
+ {
+ bitset_copy (dests_ch[ndests], remains);
+ bitset_copy (dests_ch[j], intersec);
+ err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]);
+ if (BE (err != REG_NOERROR, 0))
+ goto error_return;
+ ++ndests;
+ }
+
+ /* Put the position in the current group. */
+ ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
+ if (BE (! ok, 0))
+ goto error_return;
+
+ /* If all characters are consumed, go to next node. */
+ if (!not_consumed)
+ break;
+ }
+ /* Some characters remain, create a new group. */
+ if (j == ndests)
+ {
+ bitset_copy (dests_ch[ndests], accepts);
+ err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]);
+ if (BE (err != REG_NOERROR, 0))
+ goto error_return;
+ ++ndests;
+ bitset_empty (accepts);
+ }
+ }
+ return ndests;
+ error_return:
+ for (j = 0; j < ndests; ++j)
+ re_node_set_free (dests_node + j);
+ return REG_MISSING;
+}
+
+#ifdef RE_ENABLE_I18N
+/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts.
+ Return the number of the bytes the node accepts.
+ STR_IDX is the current index of the input string.
+
+ This function handles the nodes which can accept one character, or
+ one collating element like '.', '[a-z]', opposite to the other nodes
+ can only accept one byte. */
+
+static int
+internal_function
+check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
+ const re_string_t *input, Idx str_idx)
+{
+ const re_token_t *node = dfa->nodes + node_idx;
+ int char_len, elem_len;
+ Idx i;
+
+ if (BE (node->type == OP_UTF8_PERIOD, 0))
+ {
+ unsigned char c = re_string_byte_at (input, str_idx), d;
+ if (BE (c < 0xc2, 1))
+ return 0;
+
+ if (str_idx + 2 > input->len)
+ return 0;
+
+ d = re_string_byte_at (input, str_idx + 1);
+ if (c < 0xe0)
+ return (d < 0x80 || d > 0xbf) ? 0 : 2;
+ else if (c < 0xf0)
+ {
+ char_len = 3;
+ if (c == 0xe0 && d < 0xa0)
+ return 0;
+ }
+ else if (c < 0xf8)
+ {
+ char_len = 4;
+ if (c == 0xf0 && d < 0x90)
+ return 0;
+ }
+ else if (c < 0xfc)
+ {
+ char_len = 5;
+ if (c == 0xf8 && d < 0x88)
+ return 0;
+ }
+ else if (c < 0xfe)
+ {
+ char_len = 6;
+ if (c == 0xfc && d < 0x84)
+ return 0;
+ }
+ else
+ return 0;
+
+ if (str_idx + char_len > input->len)
+ return 0;
+
+ for (i = 1; i < char_len; ++i)
+ {
+ d = re_string_byte_at (input, str_idx + i);
+ if (d < 0x80 || d > 0xbf)
+ return 0;
+ }
+ return char_len;
+ }
+
+ char_len = re_string_char_size_at (input, str_idx);
+ if (node->type == OP_PERIOD)
+ {
+ if (char_len <= 1)
+ return 0;
+ /* FIXME: I don't think this if is needed, as both '\n'
+ and '\0' are char_len == 1. */
+ /* '.' accepts any one character except the following two cases. */
+ if ((!(dfa->syntax & RE_DOT_NEWLINE) &&
+ re_string_byte_at (input, str_idx) == '\n') ||
+ ((dfa->syntax & RE_DOT_NOT_NULL) &&
+ re_string_byte_at (input, str_idx) == '\0'))
+ return 0;
+ return char_len;
+ }
+
+ elem_len = re_string_elem_size_at (input, str_idx);
+ if ((elem_len <= 1 && char_len <= 1) || char_len == 0)
+ return 0;
+
+ if (node->type == COMPLEX_BRACKET)
+ {
+ const re_charset_t *cset = node->opr.mbcset;
+# ifdef _LIBC
+ const unsigned char *pin
+ = ((const unsigned char *) re_string_get_buffer (input) + str_idx);
+ Idx j;
+ uint32_t nrules;
+# endif /* _LIBC */
+ int match_len = 0;
+ wchar_t wc = ((cset->nranges || cset->nchar_classes || cset->nmbchars)
+ ? re_string_wchar_at (input, str_idx) : 0);
+
+ /* match with multibyte character? */
+ for (i = 0; i < cset->nmbchars; ++i)
+ if (wc == cset->mbchars[i])
+ {
+ match_len = char_len;
+ goto check_node_accept_bytes_match;
+ }
+ /* match with character_class? */
+ for (i = 0; i < cset->nchar_classes; ++i)
+ {
+ wctype_t wt = cset->char_classes[i];
+ if (__iswctype (wc, wt))
+ {
+ match_len = char_len;
+ goto check_node_accept_bytes_match;
+ }
+ }
+
+# ifdef _LIBC
+ nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules != 0)
+ {
+ unsigned int in_collseq = 0;
+ const int32_t *table, *indirect;
+ const unsigned char *weights, *extra;
+ const char *collseqwc;
+ /* This #include defines a local function! */
+# include <locale/weight.h>
+
+ /* match with collating_symbol? */
+ if (cset->ncoll_syms)
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
+ for (i = 0; i < cset->ncoll_syms; ++i)
+ {
+ const unsigned char *coll_sym = extra + cset->coll_syms[i];
+ /* Compare the length of input collating element and
+ the length of current collating element. */
+ if (*coll_sym != elem_len)
+ continue;
+ /* Compare each bytes. */
+ for (j = 0; j < *coll_sym; j++)
+ if (pin[j] != coll_sym[1 + j])
+ break;
+ if (j == *coll_sym)
+ {
+ /* Match if every bytes is equal. */
+ match_len = j;
+ goto check_node_accept_bytes_match;
+ }
+ }
+
+ if (cset->nranges)
+ {
+ if (elem_len <= char_len)
+ {
+ collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
+ in_collseq = __collseq_table_lookup (collseqwc, wc);
+ }
+ else
+ in_collseq = find_collation_sequence_value (pin, elem_len);
+ }
+ /* match with range expression? */
+ /* FIXME: Implement rational ranges here, too. */
+ for (i = 0; i < cset->nranges; ++i)
+ if (cset->range_starts[i] <= in_collseq
+ && in_collseq <= cset->range_ends[i])
+ {
+ match_len = elem_len;
+ goto check_node_accept_bytes_match;
+ }
+
+ /* match with equivalence_class? */
+ if (cset->nequiv_classes)
+ {
+ const unsigned char *cp = pin;
+ table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ weights = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB);
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
+ indirect = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
+ int32_t idx = findidx (&cp, elem_len);
+ if (idx > 0)
+ for (i = 0; i < cset->nequiv_classes; ++i)
+ {
+ int32_t equiv_class_idx = cset->equiv_classes[i];
+ size_t weight_len = weights[idx & 0xffffff];
+ if (weight_len == weights[equiv_class_idx & 0xffffff]
+ && (idx >> 24) == (equiv_class_idx >> 24))
+ {
+ Idx cnt = 0;
+
+ idx &= 0xffffff;
+ equiv_class_idx &= 0xffffff;
+
+ while (cnt <= weight_len
+ && (weights[equiv_class_idx + 1 + cnt]
+ == weights[idx + 1 + cnt]))
+ ++cnt;
+ if (cnt > weight_len)
+ {
+ match_len = elem_len;
+ goto check_node_accept_bytes_match;
+ }
+ }
+ }
+ }
+ }
+ else
+# endif /* _LIBC */
+ {
+ /* match with range expression? */
+ for (i = 0; i < cset->nranges; ++i)
+ {
+ if (cset->range_starts[i] <= wc && wc <= cset->range_ends[i])
+ {
+ match_len = char_len;
+ goto check_node_accept_bytes_match;
+ }
+ }
+ }
+ check_node_accept_bytes_match:
+ if (!cset->non_match)
+ return match_len;
+ else
+ {
+ if (match_len > 0)
+ return 0;
+ else
+ return (elem_len > char_len) ? elem_len : char_len;
+ }
+ }
+ return 0;
+}
+
+# ifdef _LIBC
+static unsigned int
+internal_function
+find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
+{
+ uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules == 0)
+ {
+ if (mbs_len == 1)
+ {
+ /* No valid character. Match it as a single byte character. */
+ const unsigned char *collseq = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
+ return collseq[mbs[0]];
+ }
+ return UINT_MAX;
+ }
+ else
+ {
+ int32_t idx;
+ const unsigned char *extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
+ int32_t extrasize = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB + 1) - extra;
+
+ for (idx = 0; idx < extrasize;)
+ {
+ int mbs_cnt;
+ bool found = false;
+ int32_t elem_mbs_len;
+ /* Skip the name of collating element name. */
+ idx = idx + extra[idx] + 1;
+ elem_mbs_len = extra[idx++];
+ if (mbs_len == elem_mbs_len)
+ {
+ for (mbs_cnt = 0; mbs_cnt < elem_mbs_len; ++mbs_cnt)
+ if (extra[idx + mbs_cnt] != mbs[mbs_cnt])
+ break;
+ if (mbs_cnt == elem_mbs_len)
+ /* Found the entry. */
+ found = true;
+ }
+ /* Skip the byte sequence of the collating element. */
+ idx += elem_mbs_len;
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
+ /* Skip the collation sequence value. */
+ idx += sizeof (uint32_t);
+ /* Skip the wide char sequence of the collating element. */
+ idx = idx + sizeof (uint32_t) * (*(int32_t *) (extra + idx) + 1);
+ /* If we found the entry, return the sequence value. */
+ if (found)
+ return *(uint32_t *) (extra + idx);
+ /* Skip the collation sequence value. */
+ idx += sizeof (uint32_t);
+ }
+ return UINT_MAX;
+ }
+}
+# endif /* _LIBC */
+#endif /* RE_ENABLE_I18N */
+
+/* Check whether the node accepts the byte which is IDX-th
+ byte of the INPUT. */
+
+static bool
+internal_function
+check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
+ Idx idx)
+{
+ unsigned char ch;
+ ch = re_string_byte_at (&mctx->input, idx);
+ switch (node->type)
+ {
+ case CHARACTER:
+ if (node->opr.c != ch)
+ return false;
+ break;
+
+ case SIMPLE_BRACKET:
+ if (!bitset_contain (node->opr.sbcset, ch))
+ return false;
+ break;
+
+#ifdef RE_ENABLE_I18N
+ case OP_UTF8_PERIOD:
+ if (ch >= ASCII_CHARS)
+ return false;
+ /* FALLTHROUGH */
+#endif
+ case OP_PERIOD:
+ if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
+ || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
+ return false;
+ break;
+
+ default:
+ return false;
+ }
+
+ if (node->constraint)
+ {
+ /* The node has constraints. Check whether the current context
+ satisfies the constraints. */
+ unsigned int context = re_string_context_at (&mctx->input, idx,
+ mctx->eflags);
+ if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
+ return false;
+ }
+
+ return true;
+}
+
+/* Extend the buffers, if the buffers have run out. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+extend_buffers (re_match_context_t *mctx, int min_len)
+{
+ reg_errcode_t ret;
+ re_string_t *pstr = &mctx->input;
+
+ /* Avoid overflow. */
+ if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2
+ <= pstr->bufs_len, 0))
+ return REG_ESPACE;
+
+ /* Double the lengths of the buffers, but allocate at least MIN_LEN. */
+ ret = re_string_realloc_buffers (pstr,
+ MAX (min_len,
+ MIN (pstr->len, pstr->bufs_len * 2)));
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+
+ if (mctx->state_log != NULL)
+ {
+ /* And double the length of state_log. */
+ /* XXX We have no indication of the size of this buffer. If this
+ allocation fail we have no indication that the state_log array
+ does not have the right size. */
+ re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *,
+ pstr->bufs_len + 1);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ mctx->state_log = new_array;
+ }
+
+ /* Then reconstruct the buffers. */
+ if (pstr->icase)
+ {
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ ret = build_wcs_upper_buffer (pstr);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ build_upper_buffer (pstr);
+ }
+ else
+ {
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ build_wcs_buffer (pstr);
+ else
+#endif /* RE_ENABLE_I18N */
+ {
+ if (pstr->trans != NULL)
+ re_string_translate_buffer (pstr);
+ }
+ }
+ return REG_NOERROR;
+}
+
+
+/* Functions for matching context. */
+
+/* Initialize MCTX. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
+{
+ mctx->eflags = eflags;
+ mctx->match_last = REG_MISSING;
+ if (n > 0)
+ {
+ /* Avoid overflow. */
+ size_t max_object_size =
+ MAX (sizeof (struct re_backref_cache_entry),
+ sizeof (re_sub_match_top_t *));
+ if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n, 0))
+ return REG_ESPACE;
+
+ mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
+ mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
+ if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0))
+ return REG_ESPACE;
+ }
+ /* Already zero-ed by the caller.
+ else
+ mctx->bkref_ents = NULL;
+ mctx->nbkref_ents = 0;
+ mctx->nsub_tops = 0; */
+ mctx->abkref_ents = n;
+ mctx->max_mb_elem_len = 1;
+ mctx->asub_tops = n;
+ return REG_NOERROR;
+}
+
+/* Clean the entries which depend on the current input in MCTX.
+ This function must be invoked when the matcher changes the start index
+ of the input, or changes the input string. */
+
+static void
+internal_function
+match_ctx_clean (re_match_context_t *mctx)
+{
+ Idx st_idx;
+ for (st_idx = 0; st_idx < mctx->nsub_tops; ++st_idx)
+ {
+ Idx sl_idx;
+ re_sub_match_top_t *top = mctx->sub_tops[st_idx];
+ for (sl_idx = 0; sl_idx < top->nlasts; ++sl_idx)
+ {
+ re_sub_match_last_t *last = top->lasts[sl_idx];
+ re_free (last->path.array);
+ re_free (last);
+ }
+ re_free (top->lasts);
+ if (top->path)
+ {
+ re_free (top->path->array);
+ re_free (top->path);
+ }
+ free (top);
+ }
+
+ mctx->nsub_tops = 0;
+ mctx->nbkref_ents = 0;
+}
+
+/* Free all the memory associated with MCTX. */
+
+static void
+internal_function
+match_ctx_free (re_match_context_t *mctx)
+{
+ /* First, free all the memory associated with MCTX->SUB_TOPS. */
+ match_ctx_clean (mctx);
+ re_free (mctx->sub_tops);
+ re_free (mctx->bkref_ents);
+}
+
+/* Add a new backreference entry to MCTX.
+ Note that we assume that caller never call this function with duplicate
+ entry, and call with STR_IDX which isn't smaller than any existing entry.
+*/
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
+ Idx to)
+{
+ if (mctx->nbkref_ents >= mctx->abkref_ents)
+ {
+ struct re_backref_cache_entry* new_entry;
+ new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry,
+ mctx->abkref_ents * 2);
+ if (BE (new_entry == NULL, 0))
+ {
+ re_free (mctx->bkref_ents);
+ return REG_ESPACE;
+ }
+ mctx->bkref_ents = new_entry;
+ memset (mctx->bkref_ents + mctx->nbkref_ents, '\0',
+ sizeof (struct re_backref_cache_entry) * mctx->abkref_ents);
+ mctx->abkref_ents *= 2;
+ }
+ if (mctx->nbkref_ents > 0
+ && mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx)
+ mctx->bkref_ents[mctx->nbkref_ents - 1].more = 1;
+
+ mctx->bkref_ents[mctx->nbkref_ents].node = node;
+ mctx->bkref_ents[mctx->nbkref_ents].str_idx = str_idx;
+ mctx->bkref_ents[mctx->nbkref_ents].subexp_from = from;
+ mctx->bkref_ents[mctx->nbkref_ents].subexp_to = to;
+
+ /* This is a cache that saves negative results of check_dst_limits_calc_pos.
+ If bit N is clear, means that this entry won't epsilon-transition to
+ an OP_OPEN_SUBEXP or OP_CLOSE_SUBEXP for the N+1-th subexpression. If
+ it is set, check_dst_limits_calc_pos_1 will recurse and try to find one
+ such node.
+
+ A backreference does not epsilon-transition unless it is empty, so set
+ to all zeros if FROM != TO. */
+ mctx->bkref_ents[mctx->nbkref_ents].eps_reachable_subexps_map
+ = (from == to ? -1 : 0);
+
+ mctx->bkref_ents[mctx->nbkref_ents++].more = 0;
+ if (mctx->max_mb_elem_len < to - from)
+ mctx->max_mb_elem_len = to - from;
+ return REG_NOERROR;
+}
+
+/* Return the first entry with the same str_idx, or REG_MISSING if none is
+ found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */
+
+static Idx
+internal_function
+search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
+{
+ Idx left, right, mid, last;
+ last = right = mctx->nbkref_ents;
+ for (left = 0; left < right;)
+ {
+ mid = (left + right) / 2;
+ if (mctx->bkref_ents[mid].str_idx < str_idx)
+ left = mid + 1;
+ else
+ right = mid;
+ }
+ if (left < last && mctx->bkref_ents[left].str_idx == str_idx)
+ return left;
+ else
+ return REG_MISSING;
+}
+
+/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches
+ at STR_IDX. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
+{
+#ifdef DEBUG
+ assert (mctx->sub_tops != NULL);
+ assert (mctx->asub_tops > 0);
+#endif
+ if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
+ {
+ Idx new_asub_tops = mctx->asub_tops * 2;
+ re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
+ re_sub_match_top_t *,
+ new_asub_tops);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ mctx->sub_tops = new_array;
+ mctx->asub_tops = new_asub_tops;
+ }
+ mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t));
+ if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0))
+ return REG_ESPACE;
+ mctx->sub_tops[mctx->nsub_tops]->node = node;
+ mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx;
+ return REG_NOERROR;
+}
+
+/* Register the node NODE, whose type is OP_CLOSE_SUBEXP, and which matches
+ at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP. */
+
+static re_sub_match_last_t *
+internal_function
+match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
+{
+ re_sub_match_last_t *new_entry;
+ if (BE (subtop->nlasts == subtop->alasts, 0))
+ {
+ Idx new_alasts = 2 * subtop->alasts + 1;
+ re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
+ re_sub_match_last_t *,
+ new_alasts);
+ if (BE (new_array == NULL, 0))
+ return NULL;
+ subtop->lasts = new_array;
+ subtop->alasts = new_alasts;
+ }
+ new_entry = calloc (1, sizeof (re_sub_match_last_t));
+ if (BE (new_entry != NULL, 1))
+ {
+ subtop->lasts[subtop->nlasts] = new_entry;
+ new_entry->node = node;
+ new_entry->str_idx = str_idx;
+ ++subtop->nlasts;
+ }
+ return new_entry;
+}
+
+static void
+internal_function
+sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
+ re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
+{
+ sctx->sifted_states = sifted_sts;
+ sctx->limited_states = limited_sts;
+ sctx->last_node = last_node;
+ sctx->last_str_idx = last_str_idx;
+ re_node_set_init_empty (&sctx->limits);
+}
diff --git a/contrib/tools/bison/gnulib/src/rename.c b/contrib/tools/bison/gnulib/src/rename.c
index 3e463ea86a..306000d9c6 100644
--- a/contrib/tools/bison/gnulib/src/rename.c
+++ b/contrib/tools/bison/gnulib/src/rename.c
@@ -1,473 +1,473 @@
-/* Work around rename bugs in some systems.
-
- Copyright (C) 2001-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Volker Borchert, Eric Blake. */
-
-#include <config.h>
-
-#include <stdio.h>
-
-#undef rename
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* The mingw rename has problems with trailing slashes; it also
- requires use of native Windows calls to allow atomic renames over
- existing files. */
-
-# include <errno.h>
-# include <stdbool.h>
-# include <stdlib.h>
-# include <sys/stat.h>
-# include <unistd.h>
-
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-
-# include "dirname.h"
-
-/* Rename the file SRC to DST. This replacement is necessary on
- Windows, on which the system rename function will not replace
- an existing DST. */
-int
-rpl_rename (char const *src, char const *dst)
-{
- int error;
- size_t src_len = strlen (src);
- size_t dst_len = strlen (dst);
- char *src_base = last_component (src);
- char *dst_base = last_component (dst);
- bool src_slash;
- bool dst_slash;
- bool dst_exists;
- struct stat src_st;
- struct stat dst_st;
-
- /* Filter out dot as last component. */
- if (!src_len || !dst_len)
- {
- errno = ENOENT;
- return -1;
- }
- if (*src_base == '.')
- {
- size_t len = base_len (src_base);
- if (len == 1 || (len == 2 && src_base[1] == '.'))
- {
- errno = EINVAL;
- return -1;
- }
- }
- if (*dst_base == '.')
- {
- size_t len = base_len (dst_base);
- if (len == 1 || (len == 2 && dst_base[1] == '.'))
- {
- errno = EINVAL;
- return -1;
- }
- }
-
- /* Presence of a trailing slash requires directory semantics. If
- the source does not exist, or if the destination cannot be turned
- into a directory, give up now. Otherwise, strip trailing slashes
- before calling rename. There are no symlinks on mingw, so stat
- works instead of lstat. */
- src_slash = ISSLASH (src[src_len - 1]);
- dst_slash = ISSLASH (dst[dst_len - 1]);
- if (stat (src, &src_st))
- return -1;
- if (stat (dst, &dst_st))
- {
- if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash))
- return -1;
- dst_exists = false;
- }
- else
- {
- if (S_ISDIR (dst_st.st_mode) != S_ISDIR (src_st.st_mode))
- {
- errno = S_ISDIR (dst_st.st_mode) ? EISDIR : ENOTDIR;
- return -1;
- }
- dst_exists = true;
- }
-
- /* There are no symlinks, so if a file existed with a trailing
- slash, it must be a directory, and we don't have to worry about
- stripping strip trailing slash. However, mingw refuses to
- replace an existing empty directory, so we have to help it out.
- And canonicalize_file_name is not yet ported to mingw; however,
- for directories, getcwd works as a viable alternative. Ensure
- that we can get back to where we started before using it; later
- attempts to return are fatal. Note that we can end up losing a
- directory if rename then fails, but it was empty, so not much
- damage was done. */
- if (dst_exists && S_ISDIR (dst_st.st_mode))
- {
- char *cwd = getcwd (NULL, 0);
- char *src_temp;
- char *dst_temp;
- if (!cwd || chdir (cwd))
- return -1;
- if (IS_ABSOLUTE_FILE_NAME (src))
- {
- dst_temp = chdir (dst) ? NULL : getcwd (NULL, 0);
- src_temp = chdir (src) ? NULL : getcwd (NULL, 0);
- }
- else
- {
- src_temp = chdir (src) ? NULL : getcwd (NULL, 0);
- if (!IS_ABSOLUTE_FILE_NAME (dst) && chdir (cwd))
- abort ();
- dst_temp = chdir (dst) ? NULL : getcwd (NULL, 0);
- }
- if (chdir (cwd))
- abort ();
- free (cwd);
- if (!src_temp || !dst_temp)
- {
- free (src_temp);
- free (dst_temp);
- errno = ENOMEM;
- return -1;
- }
- src_len = strlen (src_temp);
- if (strncmp (src_temp, dst_temp, src_len) == 0
- && (ISSLASH (dst_temp[src_len]) || dst_temp[src_len] == '\0'))
- {
- error = dst_temp[src_len];
- free (src_temp);
- free (dst_temp);
- if (error)
- {
- errno = EINVAL;
- return -1;
- }
- return 0;
- }
- if (rmdir (dst))
- {
- error = errno;
- free (src_temp);
- free (dst_temp);
- errno = error;
- return -1;
- }
- free (src_temp);
- free (dst_temp);
- }
-
- /* MoveFileEx works if SRC is a directory without any flags, but
- fails with MOVEFILE_REPLACE_EXISTING, so try without flags first.
- Thankfully, MoveFileEx handles hard links correctly, even though
- rename() does not. */
- if (MoveFileEx (src, dst, 0))
- return 0;
-
- /* Retry with MOVEFILE_REPLACE_EXISTING if the move failed
- due to the destination already existing. */
- error = GetLastError ();
- if (error == ERROR_FILE_EXISTS || error == ERROR_ALREADY_EXISTS)
- {
- if (MoveFileEx (src, dst, MOVEFILE_REPLACE_EXISTING))
- return 0;
-
- error = GetLastError ();
- }
-
- switch (error)
- {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- case ERROR_BAD_PATHNAME:
- case ERROR_DIRECTORY:
- errno = ENOENT;
- break;
-
- case ERROR_ACCESS_DENIED:
- case ERROR_SHARING_VIOLATION:
- errno = EACCES;
- break;
-
- case ERROR_OUTOFMEMORY:
- errno = ENOMEM;
- break;
-
- case ERROR_CURRENT_DIRECTORY:
- errno = EBUSY;
- break;
-
- case ERROR_NOT_SAME_DEVICE:
- errno = EXDEV;
- break;
-
- case ERROR_WRITE_PROTECT:
- errno = EROFS;
- break;
-
- case ERROR_WRITE_FAULT:
- case ERROR_READ_FAULT:
- case ERROR_GEN_FAILURE:
- errno = EIO;
- break;
-
- case ERROR_HANDLE_DISK_FULL:
- case ERROR_DISK_FULL:
- case ERROR_DISK_TOO_FRAGMENTED:
- errno = ENOSPC;
- break;
-
- case ERROR_FILE_EXISTS:
- case ERROR_ALREADY_EXISTS:
- errno = EEXIST;
- break;
-
- case ERROR_BUFFER_OVERFLOW:
- case ERROR_FILENAME_EXCED_RANGE:
- errno = ENAMETOOLONG;
- break;
-
- case ERROR_INVALID_NAME:
- case ERROR_DELETE_PENDING:
- errno = EPERM; /* ? */
- break;
-
-# ifndef ERROR_FILE_TOO_LARGE
-/* This value is documented but not defined in all versions of windows.h. */
-# define ERROR_FILE_TOO_LARGE 223
-# endif
- case ERROR_FILE_TOO_LARGE:
- errno = EFBIG;
- break;
-
- default:
- errno = EINVAL;
- break;
- }
-
- return -1;
-}
-
-#else /* ! W32 platform */
-
-# include <errno.h>
-# include <stdio.h>
-# include <stdlib.h>
-# include <string.h>
-# include <sys/stat.h>
-# include <unistd.h>
-
-# include "dirname.h"
-# include "same-inode.h"
-
-/* Rename the file SRC to DST, fixing any trailing slash bugs. */
-
-int
-rpl_rename (char const *src, char const *dst)
-{
- size_t src_len = strlen (src);
- size_t dst_len = strlen (dst);
- char *src_temp = (char *) src;
- char *dst_temp = (char *) dst;
- bool src_slash;
- bool dst_slash;
- bool dst_exists;
- int ret_val = -1;
- int rename_errno = ENOTDIR;
- struct stat src_st;
- struct stat dst_st;
-
- if (!src_len || !dst_len)
- return rename (src, dst); /* Let strace see the ENOENT failure. */
-
-# if RENAME_DEST_EXISTS_BUG
- {
- char *src_base = last_component (src);
- char *dst_base = last_component (dst);
- if (*src_base == '.')
- {
- size_t len = base_len (src_base);
- if (len == 1 || (len == 2 && src_base[1] == '.'))
- {
- errno = EINVAL;
- return -1;
- }
- }
- if (*dst_base == '.')
- {
- size_t len = base_len (dst_base);
- if (len == 1 || (len == 2 && dst_base[1] == '.'))
- {
- errno = EINVAL;
- return -1;
- }
- }
- }
-# endif /* RENAME_DEST_EXISTS_BUG */
-
- src_slash = src[src_len - 1] == '/';
- dst_slash = dst[dst_len - 1] == '/';
-
-# if !RENAME_HARD_LINK_BUG && !RENAME_DEST_EXISTS_BUG
- /* If there are no trailing slashes, then trust the native
- implementation unless we also suspect issues with hard link
- detection or file/directory conflicts. */
- if (!src_slash && !dst_slash)
- return rename (src, dst);
-# endif /* !RENAME_HARD_LINK_BUG && !RENAME_DEST_EXISTS_BUG */
-
- /* Presence of a trailing slash requires directory semantics. If
- the source does not exist, or if the destination cannot be turned
- into a directory, give up now. Otherwise, strip trailing slashes
- before calling rename. */
- if (lstat (src, &src_st))
- return -1;
- if (lstat (dst, &dst_st))
- {
- if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash))
- return -1;
- dst_exists = false;
- }
- else
- {
- if (S_ISDIR (dst_st.st_mode) != S_ISDIR (src_st.st_mode))
- {
- errno = S_ISDIR (dst_st.st_mode) ? EISDIR : ENOTDIR;
- return -1;
- }
-# if RENAME_HARD_LINK_BUG
- if (SAME_INODE (src_st, dst_st))
- return 0;
-# endif /* RENAME_HARD_LINK_BUG */
- dst_exists = true;
- }
-
-# if (RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG \
- || RENAME_HARD_LINK_BUG)
- /* If the only bug was that a trailing slash was allowed on a
- non-existing file destination, as in Solaris 10, then we've
- already covered that situation. But if there is any problem with
- a trailing slash on an existing source or destination, as in
- Solaris 9, or if a directory can overwrite a symlink, as on
- Cygwin 1.5, or if directories cannot be created with trailing
- slash, as on NetBSD 1.6, then we must strip the offending slash
- and check that we have not encountered a symlink instead of a
- directory.
-
- Stripping a trailing slash interferes with POSIX semantics, where
- rename behavior on a symlink with a trailing slash operates on
- the corresponding target directory. We prefer the GNU semantics
- of rejecting any use of a symlink with trailing slash, but do not
- enforce them, since Solaris 10 is able to obey POSIX semantics
- and there might be clients expecting it, as counter-intuitive as
- those semantics are.
-
- Technically, we could also follow the POSIX behavior by chasing a
- readlink trail, but that is harder to implement. */
- if (src_slash)
- {
- src_temp = strdup (src);
- if (!src_temp)
- {
- /* Rather than rely on strdup-posix, we set errno ourselves. */
- rename_errno = ENOMEM;
- goto out;
- }
- strip_trailing_slashes (src_temp);
- if (lstat (src_temp, &src_st))
- {
- rename_errno = errno;
- goto out;
- }
- if (S_ISLNK (src_st.st_mode))
- goto out;
- }
- if (dst_slash)
- {
- dst_temp = strdup (dst);
- if (!dst_temp)
- {
- rename_errno = ENOMEM;
- goto out;
- }
- strip_trailing_slashes (dst_temp);
- if (lstat (dst_temp, &dst_st))
- {
- if (errno != ENOENT)
- {
- rename_errno = errno;
- goto out;
- }
- }
- else if (S_ISLNK (dst_st.st_mode))
- goto out;
- }
-# endif /* RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG
- || RENAME_HARD_LINK_BUG */
-
-# if RENAME_DEST_EXISTS_BUG
- /* Cygwin 1.5 sometimes behaves oddly when moving a non-empty
- directory on top of an empty one (the old directory name can
- reappear if the new directory tree is removed). Work around this
- by removing the target first, but don't remove the target if it
- is a subdirectory of the source. Note that we can end up losing
- a directory if rename then fails, but it was empty, so not much
- damage was done. */
- if (dst_exists && S_ISDIR (dst_st.st_mode))
- {
- if (src_st.st_dev != dst_st.st_dev)
- {
- rename_errno = EXDEV;
- goto out;
- }
- if (src_temp != src)
- free (src_temp);
- src_temp = canonicalize_file_name (src);
- if (dst_temp != dst)
- free (dst_temp);
- dst_temp = canonicalize_file_name (dst);
- if (!src_temp || !dst_temp)
- {
- rename_errno = ENOMEM;
- goto out;
- }
- src_len = strlen (src_temp);
- if (strncmp (src_temp, dst_temp, src_len) == 0
- && dst_temp[src_len] == '/')
- {
- rename_errno = EINVAL;
- goto out;
- }
- if (rmdir (dst))
- {
- rename_errno = errno;
- goto out;
- }
- }
-# endif /* RENAME_DEST_EXISTS_BUG */
-
- ret_val = rename (src_temp, dst_temp);
- rename_errno = errno;
- out:
- if (src_temp != src)
- free (src_temp);
- if (dst_temp != dst)
- free (dst_temp);
- errno = rename_errno;
- return ret_val;
-}
-#endif /* ! W32 platform */
+/* Work around rename bugs in some systems.
+
+ Copyright (C) 2001-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Volker Borchert, Eric Blake. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#undef rename
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* The mingw rename has problems with trailing slashes; it also
+ requires use of native Windows calls to allow atomic renames over
+ existing files. */
+
+# include <errno.h>
+# include <stdbool.h>
+# include <stdlib.h>
+# include <sys/stat.h>
+# include <unistd.h>
+
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+# include "dirname.h"
+
+/* Rename the file SRC to DST. This replacement is necessary on
+ Windows, on which the system rename function will not replace
+ an existing DST. */
+int
+rpl_rename (char const *src, char const *dst)
+{
+ int error;
+ size_t src_len = strlen (src);
+ size_t dst_len = strlen (dst);
+ char *src_base = last_component (src);
+ char *dst_base = last_component (dst);
+ bool src_slash;
+ bool dst_slash;
+ bool dst_exists;
+ struct stat src_st;
+ struct stat dst_st;
+
+ /* Filter out dot as last component. */
+ if (!src_len || !dst_len)
+ {
+ errno = ENOENT;
+ return -1;
+ }
+ if (*src_base == '.')
+ {
+ size_t len = base_len (src_base);
+ if (len == 1 || (len == 2 && src_base[1] == '.'))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ if (*dst_base == '.')
+ {
+ size_t len = base_len (dst_base);
+ if (len == 1 || (len == 2 && dst_base[1] == '.'))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
+ /* Presence of a trailing slash requires directory semantics. If
+ the source does not exist, or if the destination cannot be turned
+ into a directory, give up now. Otherwise, strip trailing slashes
+ before calling rename. There are no symlinks on mingw, so stat
+ works instead of lstat. */
+ src_slash = ISSLASH (src[src_len - 1]);
+ dst_slash = ISSLASH (dst[dst_len - 1]);
+ if (stat (src, &src_st))
+ return -1;
+ if (stat (dst, &dst_st))
+ {
+ if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash))
+ return -1;
+ dst_exists = false;
+ }
+ else
+ {
+ if (S_ISDIR (dst_st.st_mode) != S_ISDIR (src_st.st_mode))
+ {
+ errno = S_ISDIR (dst_st.st_mode) ? EISDIR : ENOTDIR;
+ return -1;
+ }
+ dst_exists = true;
+ }
+
+ /* There are no symlinks, so if a file existed with a trailing
+ slash, it must be a directory, and we don't have to worry about
+ stripping strip trailing slash. However, mingw refuses to
+ replace an existing empty directory, so we have to help it out.
+ And canonicalize_file_name is not yet ported to mingw; however,
+ for directories, getcwd works as a viable alternative. Ensure
+ that we can get back to where we started before using it; later
+ attempts to return are fatal. Note that we can end up losing a
+ directory if rename then fails, but it was empty, so not much
+ damage was done. */
+ if (dst_exists && S_ISDIR (dst_st.st_mode))
+ {
+ char *cwd = getcwd (NULL, 0);
+ char *src_temp;
+ char *dst_temp;
+ if (!cwd || chdir (cwd))
+ return -1;
+ if (IS_ABSOLUTE_FILE_NAME (src))
+ {
+ dst_temp = chdir (dst) ? NULL : getcwd (NULL, 0);
+ src_temp = chdir (src) ? NULL : getcwd (NULL, 0);
+ }
+ else
+ {
+ src_temp = chdir (src) ? NULL : getcwd (NULL, 0);
+ if (!IS_ABSOLUTE_FILE_NAME (dst) && chdir (cwd))
+ abort ();
+ dst_temp = chdir (dst) ? NULL : getcwd (NULL, 0);
+ }
+ if (chdir (cwd))
+ abort ();
+ free (cwd);
+ if (!src_temp || !dst_temp)
+ {
+ free (src_temp);
+ free (dst_temp);
+ errno = ENOMEM;
+ return -1;
+ }
+ src_len = strlen (src_temp);
+ if (strncmp (src_temp, dst_temp, src_len) == 0
+ && (ISSLASH (dst_temp[src_len]) || dst_temp[src_len] == '\0'))
+ {
+ error = dst_temp[src_len];
+ free (src_temp);
+ free (dst_temp);
+ if (error)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ return 0;
+ }
+ if (rmdir (dst))
+ {
+ error = errno;
+ free (src_temp);
+ free (dst_temp);
+ errno = error;
+ return -1;
+ }
+ free (src_temp);
+ free (dst_temp);
+ }
+
+ /* MoveFileEx works if SRC is a directory without any flags, but
+ fails with MOVEFILE_REPLACE_EXISTING, so try without flags first.
+ Thankfully, MoveFileEx handles hard links correctly, even though
+ rename() does not. */
+ if (MoveFileEx (src, dst, 0))
+ return 0;
+
+ /* Retry with MOVEFILE_REPLACE_EXISTING if the move failed
+ due to the destination already existing. */
+ error = GetLastError ();
+ if (error == ERROR_FILE_EXISTS || error == ERROR_ALREADY_EXISTS)
+ {
+ if (MoveFileEx (src, dst, MOVEFILE_REPLACE_EXISTING))
+ return 0;
+
+ error = GetLastError ();
+ }
+
+ switch (error)
+ {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ case ERROR_BAD_PATHNAME:
+ case ERROR_DIRECTORY:
+ errno = ENOENT;
+ break;
+
+ case ERROR_ACCESS_DENIED:
+ case ERROR_SHARING_VIOLATION:
+ errno = EACCES;
+ break;
+
+ case ERROR_OUTOFMEMORY:
+ errno = ENOMEM;
+ break;
+
+ case ERROR_CURRENT_DIRECTORY:
+ errno = EBUSY;
+ break;
+
+ case ERROR_NOT_SAME_DEVICE:
+ errno = EXDEV;
+ break;
+
+ case ERROR_WRITE_PROTECT:
+ errno = EROFS;
+ break;
+
+ case ERROR_WRITE_FAULT:
+ case ERROR_READ_FAULT:
+ case ERROR_GEN_FAILURE:
+ errno = EIO;
+ break;
+
+ case ERROR_HANDLE_DISK_FULL:
+ case ERROR_DISK_FULL:
+ case ERROR_DISK_TOO_FRAGMENTED:
+ errno = ENOSPC;
+ break;
+
+ case ERROR_FILE_EXISTS:
+ case ERROR_ALREADY_EXISTS:
+ errno = EEXIST;
+ break;
+
+ case ERROR_BUFFER_OVERFLOW:
+ case ERROR_FILENAME_EXCED_RANGE:
+ errno = ENAMETOOLONG;
+ break;
+
+ case ERROR_INVALID_NAME:
+ case ERROR_DELETE_PENDING:
+ errno = EPERM; /* ? */
+ break;
+
+# ifndef ERROR_FILE_TOO_LARGE
+/* This value is documented but not defined in all versions of windows.h. */
+# define ERROR_FILE_TOO_LARGE 223
+# endif
+ case ERROR_FILE_TOO_LARGE:
+ errno = EFBIG;
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+
+ return -1;
+}
+
+#else /* ! W32 platform */
+
+# include <errno.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+# include <sys/stat.h>
+# include <unistd.h>
+
+# include "dirname.h"
+# include "same-inode.h"
+
+/* Rename the file SRC to DST, fixing any trailing slash bugs. */
+
+int
+rpl_rename (char const *src, char const *dst)
+{
+ size_t src_len = strlen (src);
+ size_t dst_len = strlen (dst);
+ char *src_temp = (char *) src;
+ char *dst_temp = (char *) dst;
+ bool src_slash;
+ bool dst_slash;
+ bool dst_exists;
+ int ret_val = -1;
+ int rename_errno = ENOTDIR;
+ struct stat src_st;
+ struct stat dst_st;
+
+ if (!src_len || !dst_len)
+ return rename (src, dst); /* Let strace see the ENOENT failure. */
+
+# if RENAME_DEST_EXISTS_BUG
+ {
+ char *src_base = last_component (src);
+ char *dst_base = last_component (dst);
+ if (*src_base == '.')
+ {
+ size_t len = base_len (src_base);
+ if (len == 1 || (len == 2 && src_base[1] == '.'))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ if (*dst_base == '.')
+ {
+ size_t len = base_len (dst_base);
+ if (len == 1 || (len == 2 && dst_base[1] == '.'))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ }
+ }
+# endif /* RENAME_DEST_EXISTS_BUG */
+
+ src_slash = src[src_len - 1] == '/';
+ dst_slash = dst[dst_len - 1] == '/';
+
+# if !RENAME_HARD_LINK_BUG && !RENAME_DEST_EXISTS_BUG
+ /* If there are no trailing slashes, then trust the native
+ implementation unless we also suspect issues with hard link
+ detection or file/directory conflicts. */
+ if (!src_slash && !dst_slash)
+ return rename (src, dst);
+# endif /* !RENAME_HARD_LINK_BUG && !RENAME_DEST_EXISTS_BUG */
+
+ /* Presence of a trailing slash requires directory semantics. If
+ the source does not exist, or if the destination cannot be turned
+ into a directory, give up now. Otherwise, strip trailing slashes
+ before calling rename. */
+ if (lstat (src, &src_st))
+ return -1;
+ if (lstat (dst, &dst_st))
+ {
+ if (errno != ENOENT || (!S_ISDIR (src_st.st_mode) && dst_slash))
+ return -1;
+ dst_exists = false;
+ }
+ else
+ {
+ if (S_ISDIR (dst_st.st_mode) != S_ISDIR (src_st.st_mode))
+ {
+ errno = S_ISDIR (dst_st.st_mode) ? EISDIR : ENOTDIR;
+ return -1;
+ }
+# if RENAME_HARD_LINK_BUG
+ if (SAME_INODE (src_st, dst_st))
+ return 0;
+# endif /* RENAME_HARD_LINK_BUG */
+ dst_exists = true;
+ }
+
+# if (RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG \
+ || RENAME_HARD_LINK_BUG)
+ /* If the only bug was that a trailing slash was allowed on a
+ non-existing file destination, as in Solaris 10, then we've
+ already covered that situation. But if there is any problem with
+ a trailing slash on an existing source or destination, as in
+ Solaris 9, or if a directory can overwrite a symlink, as on
+ Cygwin 1.5, or if directories cannot be created with trailing
+ slash, as on NetBSD 1.6, then we must strip the offending slash
+ and check that we have not encountered a symlink instead of a
+ directory.
+
+ Stripping a trailing slash interferes with POSIX semantics, where
+ rename behavior on a symlink with a trailing slash operates on
+ the corresponding target directory. We prefer the GNU semantics
+ of rejecting any use of a symlink with trailing slash, but do not
+ enforce them, since Solaris 10 is able to obey POSIX semantics
+ and there might be clients expecting it, as counter-intuitive as
+ those semantics are.
+
+ Technically, we could also follow the POSIX behavior by chasing a
+ readlink trail, but that is harder to implement. */
+ if (src_slash)
+ {
+ src_temp = strdup (src);
+ if (!src_temp)
+ {
+ /* Rather than rely on strdup-posix, we set errno ourselves. */
+ rename_errno = ENOMEM;
+ goto out;
+ }
+ strip_trailing_slashes (src_temp);
+ if (lstat (src_temp, &src_st))
+ {
+ rename_errno = errno;
+ goto out;
+ }
+ if (S_ISLNK (src_st.st_mode))
+ goto out;
+ }
+ if (dst_slash)
+ {
+ dst_temp = strdup (dst);
+ if (!dst_temp)
+ {
+ rename_errno = ENOMEM;
+ goto out;
+ }
+ strip_trailing_slashes (dst_temp);
+ if (lstat (dst_temp, &dst_st))
+ {
+ if (errno != ENOENT)
+ {
+ rename_errno = errno;
+ goto out;
+ }
+ }
+ else if (S_ISLNK (dst_st.st_mode))
+ goto out;
+ }
+# endif /* RENAME_TRAILING_SLASH_SOURCE_BUG || RENAME_DEST_EXISTS_BUG
+ || RENAME_HARD_LINK_BUG */
+
+# if RENAME_DEST_EXISTS_BUG
+ /* Cygwin 1.5 sometimes behaves oddly when moving a non-empty
+ directory on top of an empty one (the old directory name can
+ reappear if the new directory tree is removed). Work around this
+ by removing the target first, but don't remove the target if it
+ is a subdirectory of the source. Note that we can end up losing
+ a directory if rename then fails, but it was empty, so not much
+ damage was done. */
+ if (dst_exists && S_ISDIR (dst_st.st_mode))
+ {
+ if (src_st.st_dev != dst_st.st_dev)
+ {
+ rename_errno = EXDEV;
+ goto out;
+ }
+ if (src_temp != src)
+ free (src_temp);
+ src_temp = canonicalize_file_name (src);
+ if (dst_temp != dst)
+ free (dst_temp);
+ dst_temp = canonicalize_file_name (dst);
+ if (!src_temp || !dst_temp)
+ {
+ rename_errno = ENOMEM;
+ goto out;
+ }
+ src_len = strlen (src_temp);
+ if (strncmp (src_temp, dst_temp, src_len) == 0
+ && dst_temp[src_len] == '/')
+ {
+ rename_errno = EINVAL;
+ goto out;
+ }
+ if (rmdir (dst))
+ {
+ rename_errno = errno;
+ goto out;
+ }
+ }
+# endif /* RENAME_DEST_EXISTS_BUG */
+
+ ret_val = rename (src_temp, dst_temp);
+ rename_errno = errno;
+ out:
+ if (src_temp != src)
+ free (src_temp);
+ if (dst_temp != dst)
+ free (dst_temp);
+ errno = rename_errno;
+ return ret_val;
+}
+#endif /* ! W32 platform */
diff --git a/contrib/tools/bison/gnulib/src/rmdir.c b/contrib/tools/bison/gnulib/src/rmdir.c
index a8d907ebf0..d7756f64da 100644
--- a/contrib/tools/bison/gnulib/src/rmdir.c
+++ b/contrib/tools/bison/gnulib/src/rmdir.c
@@ -1,53 +1,53 @@
-/* Work around rmdir bugs.
-
- Copyright (C) 1988, 1990, 1999, 2003-2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include <unistd.h>
-
-#include <errno.h>
-#include <string.h>
-
-#include "dosname.h"
-
-#undef rmdir
-
-/* Remove directory DIR.
- Return 0 if successful, -1 if not. */
-
-int
-rpl_rmdir (char const *dir)
-{
- /* Work around cygwin 1.5.x bug where rmdir("dir/./") succeeds. */
- size_t len = strlen (dir);
- int result;
- while (len && ISSLASH (dir[len - 1]))
- len--;
- if (len && dir[len - 1] == '.' && (1 == len || ISSLASH (dir[len - 2])))
- {
- errno = EINVAL;
- return -1;
- }
- result = rmdir (dir);
- /* Work around mingw bug, where rmdir("file/") fails with EINVAL
- instead of ENOTDIR. We've already filtered out trailing ., the
- only reason allowed by POSIX for EINVAL. */
- if (result == -1 && errno == EINVAL)
- errno = ENOTDIR;
- return result;
-}
+/* Work around rmdir bugs.
+
+ Copyright (C) 1988, 1990, 1999, 2003-2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include <errno.h>
+#include <string.h>
+
+#include "dosname.h"
+
+#undef rmdir
+
+/* Remove directory DIR.
+ Return 0 if successful, -1 if not. */
+
+int
+rpl_rmdir (char const *dir)
+{
+ /* Work around cygwin 1.5.x bug where rmdir("dir/./") succeeds. */
+ size_t len = strlen (dir);
+ int result;
+ while (len && ISSLASH (dir[len - 1]))
+ len--;
+ if (len && dir[len - 1] == '.' && (1 == len || ISSLASH (dir[len - 2])))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ result = rmdir (dir);
+ /* Work around mingw bug, where rmdir("file/") fails with EINVAL
+ instead of ENOTDIR. We've already filtered out trailing ., the
+ only reason allowed by POSIX for EINVAL. */
+ if (result == -1 && errno == EINVAL)
+ errno = ENOTDIR;
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/same-inode.h b/contrib/tools/bison/gnulib/src/same-inode.h
index 3843b07078..5acec44032 100644
--- a/contrib/tools/bison/gnulib/src/same-inode.h
+++ b/contrib/tools/bison/gnulib/src/same-inode.h
@@ -1,33 +1,33 @@
-/* Determine whether two stat buffers refer to the same file.
-
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SAME_INODE_H
-# define SAME_INODE_H 1
-
-# ifdef __VMS
-# define SAME_INODE(a, b) \
- ((a).st_ino[0] == (b).st_ino[0] \
- && (a).st_ino[1] == (b).st_ino[1] \
- && (a).st_ino[2] == (b).st_ino[2] \
- && (a).st_dev == (b).st_dev)
-# else
-# define SAME_INODE(a, b) \
- ((a).st_ino == (b).st_ino \
- && (a).st_dev == (b).st_dev)
-# endif
-
-#endif
+/* Determine whether two stat buffers refer to the same file.
+
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SAME_INODE_H
+# define SAME_INODE_H 1
+
+# ifdef __VMS
+# define SAME_INODE(a, b) \
+ ((a).st_ino[0] == (b).st_ino[0] \
+ && (a).st_ino[1] == (b).st_ino[1] \
+ && (a).st_ino[2] == (b).st_ino[2] \
+ && (a).st_dev == (b).st_dev)
+# else
+# define SAME_INODE(a, b) \
+ ((a).st_ino == (b).st_ino \
+ && (a).st_dev == (b).st_dev)
+# endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/secure_getenv.c b/contrib/tools/bison/gnulib/src/secure_getenv.c
index 6c11c5e0ed..f54883e8de 100644
--- a/contrib/tools/bison/gnulib/src/secure_getenv.c
+++ b/contrib/tools/bison/gnulib/src/secure_getenv.c
@@ -1,41 +1,41 @@
-/* Look up an environment variable more securely.
-
- Copyright 2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include <stdlib.h>
-
-#if !HAVE___SECURE_GETENV
-# if HAVE_ISSETUGID
-# include <unistd.h>
-# else
-# undef issetugid
-# define issetugid() 1
-# endif
-#endif
-
-char *
-secure_getenv (char const *name)
-{
-#if HAVE___SECURE_GETENV
- return __secure_getenv (name);
-#else
- if (issetugid ())
- return 0;
- return getenv (name);
-#endif
-}
+/* Look up an environment variable more securely.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#if !HAVE___SECURE_GETENV
+# if HAVE_ISSETUGID
+# include <unistd.h>
+# else
+# undef issetugid
+# define issetugid() 1
+# endif
+#endif
+
+char *
+secure_getenv (char const *name)
+{
+#if HAVE___SECURE_GETENV
+ return __secure_getenv (name);
+#else
+ if (issetugid ())
+ return 0;
+ return getenv (name);
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/sig-handler.c b/contrib/tools/bison/gnulib/src/sig-handler.c
index 52c36217e5..22bd1b70f7 100644
--- a/contrib/tools/bison/gnulib/src/sig-handler.c
+++ b/contrib/tools/bison/gnulib/src/sig-handler.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define SIG_HANDLER_INLINE _GL_EXTERN_INLINE
-#include "sig-handler.h"
+#include <config.h>
+#define SIG_HANDLER_INLINE _GL_EXTERN_INLINE
+#include "sig-handler.h"
diff --git a/contrib/tools/bison/gnulib/src/sig-handler.h b/contrib/tools/bison/gnulib/src/sig-handler.h
index 67d061d599..ec3272dbb6 100644
--- a/contrib/tools/bison/gnulib/src/sig-handler.h
+++ b/contrib/tools/bison/gnulib/src/sig-handler.h
@@ -1,54 +1,54 @@
-/* Convenience declarations when working with <signal.h>.
-
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _GL_SIG_HANDLER_H
-#define _GL_SIG_HANDLER_H
-
-#include <signal.h>
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef SIG_HANDLER_INLINE
-# define SIG_HANDLER_INLINE _GL_INLINE
-#endif
-
-/* Convenience type when working with signal handlers. */
-typedef void (*sa_handler_t) (int);
-
-/* Return the handler of a signal, as a sa_handler_t value regardless
- of its true type. The resulting function can be compared to
- special values like SIG_IGN but it is not portable to call it. */
-SIG_HANDLER_INLINE sa_handler_t
-get_handler (struct sigaction const *a)
-{
-#ifdef SA_SIGINFO
- /* POSIX says that special values like SIG_IGN can only occur when
- action.sa_flags does not contain SA_SIGINFO. But in Linux 2.4,
- for example, sa_sigaction and sa_handler are aliases and a signal
- is ignored if sa_sigaction (after casting) equals SIG_IGN. So
- use (and cast) sa_sigaction in that case. */
- if (a->sa_flags & SA_SIGINFO)
- return (sa_handler_t) a->sa_sigaction;
-#endif
- return a->sa_handler;
-}
-
-_GL_INLINE_HEADER_END
-
-#endif /* _GL_SIG_HANDLER_H */
+/* Convenience declarations when working with <signal.h>.
+
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _GL_SIG_HANDLER_H
+#define _GL_SIG_HANDLER_H
+
+#include <signal.h>
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef SIG_HANDLER_INLINE
+# define SIG_HANDLER_INLINE _GL_INLINE
+#endif
+
+/* Convenience type when working with signal handlers. */
+typedef void (*sa_handler_t) (int);
+
+/* Return the handler of a signal, as a sa_handler_t value regardless
+ of its true type. The resulting function can be compared to
+ special values like SIG_IGN but it is not portable to call it. */
+SIG_HANDLER_INLINE sa_handler_t
+get_handler (struct sigaction const *a)
+{
+#ifdef SA_SIGINFO
+ /* POSIX says that special values like SIG_IGN can only occur when
+ action.sa_flags does not contain SA_SIGINFO. But in Linux 2.4,
+ for example, sa_sigaction and sa_handler are aliases and a signal
+ is ignored if sa_sigaction (after casting) equals SIG_IGN. So
+ use (and cast) sa_sigaction in that case. */
+ if (a->sa_flags & SA_SIGINFO)
+ return (sa_handler_t) a->sa_sigaction;
+#endif
+ return a->sa_handler;
+}
+
+_GL_INLINE_HEADER_END
+
+#endif /* _GL_SIG_HANDLER_H */
diff --git a/contrib/tools/bison/gnulib/src/sigaction.c b/contrib/tools/bison/gnulib/src/sigaction.c
index 97eb76d92e..e12d95c9cf 100644
--- a/contrib/tools/bison/gnulib/src/sigaction.c
+++ b/contrib/tools/bison/gnulib/src/sigaction.c
@@ -1,204 +1,204 @@
-/* POSIX compatible signal blocking.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
- Written by Eric Blake <ebb9@byu.net>, 2008.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <signal.h>
-
-#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-/* This implementation of sigaction is tailored to native Windows behavior:
- signal() has SysV semantics (ie. the handler is uninstalled before
- it is invoked). This is an inherent data race if an asynchronous
- signal is sent twice in a row before we can reinstall our handler,
- but there's nothing we can do about it. Meanwhile, sigprocmask()
- is not present, and while we can use the gnulib replacement to
- provide critical sections, it too suffers from potential data races
- in the face of an ill-timed asynchronous signal. And we compound
- the situation by reading static storage in a signal handler, which
- POSIX warns is not generically async-signal-safe. Oh well.
-
- Additionally:
- - We don't implement SA_NOCLDSTOP or SA_NOCLDWAIT, because SIGCHLD
- is not defined.
- - We don't implement SA_ONSTACK, because sigaltstack() is not present.
- - We ignore SA_RESTART, because blocking native Windows API calls are
- not interrupted anyway when an asynchronous signal occurs, and the
- MSVCRT runtime never sets errno to EINTR.
- - We don't implement SA_SIGINFO because it is impossible to do so
- portably.
-
- POSIX states that an application should not mix signal() and
- sigaction(). We support the use of signal() within the gnulib
- sigprocmask() substitute, but all other application code linked
- with this module should stick with only sigaction(). */
-
-/* Check some of our assumptions. */
-#if defined SIGCHLD || defined HAVE_SIGALTSTACK || defined HAVE_SIGINTERRUPT
-# error "Revisit the assumptions made in the sigaction module"
-#endif
-
-/* Out-of-range substitutes make a good fallback for uncatchable
- signals. */
-#ifndef SIGKILL
-# define SIGKILL (-1)
-#endif
-#ifndef SIGSTOP
-# define SIGSTOP (-1)
-#endif
-
-/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
- for the signal SIGABRT. Only one signal handler is stored for both
- SIGABRT and SIGABRT_COMPAT. SIGABRT_COMPAT is not a signal of its own. */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-# undef SIGABRT_COMPAT
-# define SIGABRT_COMPAT 6
-#endif
-
-/* A signal handler. */
-typedef void (*handler_t) (int signal);
-
-/* Set of current actions. If sa_handler for an entry is NULL, then
- that signal is not currently handled by the sigaction handler. */
-static struct sigaction volatile action_array[NSIG] /* = 0 */;
-
-/* Signal handler that is installed for signals. */
-static void
-sigaction_handler (int sig)
-{
- handler_t handler;
- sigset_t mask;
- sigset_t oldmask;
- int saved_errno = errno;
- if (sig < 0 || NSIG <= sig || !action_array[sig].sa_handler)
- {
- /* Unexpected situation; be careful to avoid recursive abort. */
- if (sig == SIGABRT)
- signal (SIGABRT, SIG_DFL);
- abort ();
- }
-
- /* Reinstall the signal handler when required; otherwise update the
- bookkeeping so that the user's handler may call sigaction and get
- accurate results. We know the signal isn't currently blocked, or
- we wouldn't be in its handler, therefore we know that we are not
- interrupting a sigaction() call. There is a race where any
- asynchronous instance of the same signal occurring before we
- reinstall the handler will trigger the default handler; oh
- well. */
- handler = action_array[sig].sa_handler;
- if ((action_array[sig].sa_flags & SA_RESETHAND) == 0)
- signal (sig, sigaction_handler);
- else
- action_array[sig].sa_handler = NULL;
-
- /* Block appropriate signals. */
- mask = action_array[sig].sa_mask;
- if ((action_array[sig].sa_flags & SA_NODEFER) == 0)
- sigaddset (&mask, sig);
- sigprocmask (SIG_BLOCK, &mask, &oldmask);
-
- /* Invoke the user's handler, then restore prior mask. */
- errno = saved_errno;
- handler (sig);
- saved_errno = errno;
- sigprocmask (SIG_SETMASK, &oldmask, NULL);
- errno = saved_errno;
-}
-
-/* Change and/or query the action that will be taken on delivery of
- signal SIG. If not NULL, ACT describes the new behavior. If not
- NULL, OACT is set to the prior behavior. Return 0 on success, or
- set errno and return -1 on failure. */
-int
-sigaction (int sig, const struct sigaction *restrict act,
- struct sigaction *restrict oact)
-{
- sigset_t mask;
- sigset_t oldmask;
- int saved_errno;
-
- if (sig < 0 || NSIG <= sig || sig == SIGKILL || sig == SIGSTOP
- || (act && act->sa_handler == SIG_ERR))
- {
- errno = EINVAL;
- return -1;
- }
-
-#ifdef SIGABRT_COMPAT
- if (sig == SIGABRT_COMPAT)
- sig = SIGABRT;
-#endif
-
- /* POSIX requires sigaction() to be async-signal-safe. In other
- words, if an asynchronous signal can occur while we are anywhere
- inside this function, the user's handler could then call
- sigaction() recursively and expect consistent results. We meet
- this rule by using sigprocmask to block all signals before
- modifying any data structure that could be read from a signal
- handler; this works since we know that the gnulib sigprocmask
- replacement does not try to use sigaction() from its handler. */
- if (!act && !oact)
- return 0;
- sigfillset (&mask);
- sigprocmask (SIG_BLOCK, &mask, &oldmask);
- if (oact)
- {
- if (action_array[sig].sa_handler)
- *oact = action_array[sig];
- else
- {
- /* Safe to change the handler at will here, since all
- signals are currently blocked. */
- oact->sa_handler = signal (sig, SIG_DFL);
- if (oact->sa_handler == SIG_ERR)
- goto failure;
- signal (sig, oact->sa_handler);
- oact->sa_flags = SA_RESETHAND | SA_NODEFER;
- sigemptyset (&oact->sa_mask);
- }
- }
-
- if (act)
- {
- /* Safe to install the handler before updating action_array,
- since all signals are currently blocked. */
- if (act->sa_handler == SIG_DFL || act->sa_handler == SIG_IGN)
- {
- if (signal (sig, act->sa_handler) == SIG_ERR)
- goto failure;
- action_array[sig].sa_handler = NULL;
- }
- else
- {
- if (signal (sig, sigaction_handler) == SIG_ERR)
- goto failure;
- action_array[sig] = *act;
- }
- }
- sigprocmask (SIG_SETMASK, &oldmask, NULL);
- return 0;
-
- failure:
- saved_errno = errno;
- sigprocmask (SIG_SETMASK, &oldmask, NULL);
- errno = saved_errno;
- return -1;
-}
+/* POSIX compatible signal blocking.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Written by Eric Blake <ebb9@byu.net>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <signal.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/* This implementation of sigaction is tailored to native Windows behavior:
+ signal() has SysV semantics (ie. the handler is uninstalled before
+ it is invoked). This is an inherent data race if an asynchronous
+ signal is sent twice in a row before we can reinstall our handler,
+ but there's nothing we can do about it. Meanwhile, sigprocmask()
+ is not present, and while we can use the gnulib replacement to
+ provide critical sections, it too suffers from potential data races
+ in the face of an ill-timed asynchronous signal. And we compound
+ the situation by reading static storage in a signal handler, which
+ POSIX warns is not generically async-signal-safe. Oh well.
+
+ Additionally:
+ - We don't implement SA_NOCLDSTOP or SA_NOCLDWAIT, because SIGCHLD
+ is not defined.
+ - We don't implement SA_ONSTACK, because sigaltstack() is not present.
+ - We ignore SA_RESTART, because blocking native Windows API calls are
+ not interrupted anyway when an asynchronous signal occurs, and the
+ MSVCRT runtime never sets errno to EINTR.
+ - We don't implement SA_SIGINFO because it is impossible to do so
+ portably.
+
+ POSIX states that an application should not mix signal() and
+ sigaction(). We support the use of signal() within the gnulib
+ sigprocmask() substitute, but all other application code linked
+ with this module should stick with only sigaction(). */
+
+/* Check some of our assumptions. */
+#if defined SIGCHLD || defined HAVE_SIGALTSTACK || defined HAVE_SIGINTERRUPT
+# error "Revisit the assumptions made in the sigaction module"
+#endif
+
+/* Out-of-range substitutes make a good fallback for uncatchable
+ signals. */
+#ifndef SIGKILL
+# define SIGKILL (-1)
+#endif
+#ifndef SIGSTOP
+# define SIGSTOP (-1)
+#endif
+
+/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
+ for the signal SIGABRT. Only one signal handler is stored for both
+ SIGABRT and SIGABRT_COMPAT. SIGABRT_COMPAT is not a signal of its own. */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# undef SIGABRT_COMPAT
+# define SIGABRT_COMPAT 6
+#endif
+
+/* A signal handler. */
+typedef void (*handler_t) (int signal);
+
+/* Set of current actions. If sa_handler for an entry is NULL, then
+ that signal is not currently handled by the sigaction handler. */
+static struct sigaction volatile action_array[NSIG] /* = 0 */;
+
+/* Signal handler that is installed for signals. */
+static void
+sigaction_handler (int sig)
+{
+ handler_t handler;
+ sigset_t mask;
+ sigset_t oldmask;
+ int saved_errno = errno;
+ if (sig < 0 || NSIG <= sig || !action_array[sig].sa_handler)
+ {
+ /* Unexpected situation; be careful to avoid recursive abort. */
+ if (sig == SIGABRT)
+ signal (SIGABRT, SIG_DFL);
+ abort ();
+ }
+
+ /* Reinstall the signal handler when required; otherwise update the
+ bookkeeping so that the user's handler may call sigaction and get
+ accurate results. We know the signal isn't currently blocked, or
+ we wouldn't be in its handler, therefore we know that we are not
+ interrupting a sigaction() call. There is a race where any
+ asynchronous instance of the same signal occurring before we
+ reinstall the handler will trigger the default handler; oh
+ well. */
+ handler = action_array[sig].sa_handler;
+ if ((action_array[sig].sa_flags & SA_RESETHAND) == 0)
+ signal (sig, sigaction_handler);
+ else
+ action_array[sig].sa_handler = NULL;
+
+ /* Block appropriate signals. */
+ mask = action_array[sig].sa_mask;
+ if ((action_array[sig].sa_flags & SA_NODEFER) == 0)
+ sigaddset (&mask, sig);
+ sigprocmask (SIG_BLOCK, &mask, &oldmask);
+
+ /* Invoke the user's handler, then restore prior mask. */
+ errno = saved_errno;
+ handler (sig);
+ saved_errno = errno;
+ sigprocmask (SIG_SETMASK, &oldmask, NULL);
+ errno = saved_errno;
+}
+
+/* Change and/or query the action that will be taken on delivery of
+ signal SIG. If not NULL, ACT describes the new behavior. If not
+ NULL, OACT is set to the prior behavior. Return 0 on success, or
+ set errno and return -1 on failure. */
+int
+sigaction (int sig, const struct sigaction *restrict act,
+ struct sigaction *restrict oact)
+{
+ sigset_t mask;
+ sigset_t oldmask;
+ int saved_errno;
+
+ if (sig < 0 || NSIG <= sig || sig == SIGKILL || sig == SIGSTOP
+ || (act && act->sa_handler == SIG_ERR))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+#ifdef SIGABRT_COMPAT
+ if (sig == SIGABRT_COMPAT)
+ sig = SIGABRT;
+#endif
+
+ /* POSIX requires sigaction() to be async-signal-safe. In other
+ words, if an asynchronous signal can occur while we are anywhere
+ inside this function, the user's handler could then call
+ sigaction() recursively and expect consistent results. We meet
+ this rule by using sigprocmask to block all signals before
+ modifying any data structure that could be read from a signal
+ handler; this works since we know that the gnulib sigprocmask
+ replacement does not try to use sigaction() from its handler. */
+ if (!act && !oact)
+ return 0;
+ sigfillset (&mask);
+ sigprocmask (SIG_BLOCK, &mask, &oldmask);
+ if (oact)
+ {
+ if (action_array[sig].sa_handler)
+ *oact = action_array[sig];
+ else
+ {
+ /* Safe to change the handler at will here, since all
+ signals are currently blocked. */
+ oact->sa_handler = signal (sig, SIG_DFL);
+ if (oact->sa_handler == SIG_ERR)
+ goto failure;
+ signal (sig, oact->sa_handler);
+ oact->sa_flags = SA_RESETHAND | SA_NODEFER;
+ sigemptyset (&oact->sa_mask);
+ }
+ }
+
+ if (act)
+ {
+ /* Safe to install the handler before updating action_array,
+ since all signals are currently blocked. */
+ if (act->sa_handler == SIG_DFL || act->sa_handler == SIG_IGN)
+ {
+ if (signal (sig, act->sa_handler) == SIG_ERR)
+ goto failure;
+ action_array[sig].sa_handler = NULL;
+ }
+ else
+ {
+ if (signal (sig, sigaction_handler) == SIG_ERR)
+ goto failure;
+ action_array[sig] = *act;
+ }
+ }
+ sigprocmask (SIG_SETMASK, &oldmask, NULL);
+ return 0;
+
+ failure:
+ saved_errno = errno;
+ sigprocmask (SIG_SETMASK, &oldmask, NULL);
+ errno = saved_errno;
+ return -1;
+}
diff --git a/contrib/tools/bison/gnulib/src/siglist.h b/contrib/tools/bison/gnulib/src/siglist.h
index 7817c95b31..d01b9ed6a5 100644
--- a/contrib/tools/bison/gnulib/src/siglist.h
+++ b/contrib/tools/bison/gnulib/src/siglist.h
@@ -1,132 +1,132 @@
-/* Canonical list of all signal names.
- Copyright (C) 1996-1999, 2008-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* This file should be usable for any platform, since it just associates
- the SIG* macros with text names and descriptions. The actual values
- come from <bits/signum.h> (via <signal.h>). For any signal macros do not
- exist on every platform, we can use #ifdef tests here and still use
- this single common file for all platforms. */
-
-/* This file is included multiple times. */
-
-/* Duplicate values (such as SIGBUS==SIGSEGV on Haiku) favor the last
- list entry. */
-
-/* Standard signals */
-#ifdef SIGHUP
- init_sig (SIGHUP, "HUP", N_("Hangup"))
-#endif
-#ifdef SIGINT
- init_sig (SIGINT, "INT", N_("Interrupt"))
-#endif
-#ifdef SIGQUIT
- init_sig (SIGQUIT, "QUIT", N_("Quit"))
-#endif
-#ifdef SIGILL
- init_sig (SIGILL, "ILL", N_("Illegal instruction"))
-#endif
-#ifdef SIGTRAP
- init_sig (SIGTRAP, "TRAP", N_("Trace/breakpoint trap"))
-#endif
-#ifdef SIGABRT
- init_sig (SIGABRT, "ABRT", N_("Aborted"))
-#endif
-#ifdef SIGFPE
- init_sig (SIGFPE, "FPE", N_("Floating point exception"))
-#endif
-#ifdef SIGKILL
- init_sig (SIGKILL, "KILL", N_("Killed"))
-#endif
-#ifdef SIGBUS
- init_sig (SIGBUS, "BUS", N_("Bus error"))
-#endif
-#ifdef SIGSEGV
- init_sig (SIGSEGV, "SEGV", N_("Segmentation fault"))
-#endif
-#ifdef SIGPIPE
- init_sig (SIGPIPE, "PIPE", N_("Broken pipe"))
-#endif
-#ifdef SIGALRM
- init_sig (SIGALRM, "ALRM", N_("Alarm clock"))
-#endif
-#ifdef SIGTERM
- init_sig (SIGTERM, "TERM", N_("Terminated"))
-#endif
-#ifdef SIGURG
- init_sig (SIGURG, "URG", N_("Urgent I/O condition"))
-#endif
-#ifdef SIGSTOP
- init_sig (SIGSTOP, "STOP", N_("Stopped (signal)"))
-#endif
-#ifdef SIGTSTP
- init_sig (SIGTSTP, "TSTP", N_("Stopped"))
-#endif
-#ifdef SIGCONT
- init_sig (SIGCONT, "CONT", N_("Continued"))
-#endif
-#ifdef SIGCHLD
- init_sig (SIGCHLD, "CHLD", N_("Child exited"))
-#endif
-#ifdef SIGTTIN
- init_sig (SIGTTIN, "TTIN", N_("Stopped (tty input)"))
-#endif
-#ifdef SIGTTOU
- init_sig (SIGTTOU, "TTOU", N_("Stopped (tty output)"))
-#endif
-#ifdef SIGIO
- init_sig (SIGIO, "IO", N_("I/O possible"))
-#endif
-#ifdef SIGXCPU
- init_sig (SIGXCPU, "XCPU", N_("CPU time limit exceeded"))
-#endif
-#ifdef SIGXFSZ
- init_sig (SIGXFSZ, "XFSZ", N_("File size limit exceeded"))
-#endif
-#ifdef SIGVTALRM
- init_sig (SIGVTALRM, "VTALRM", N_("Virtual timer expired"))
-#endif
-#ifdef SIGPROF
- init_sig (SIGPROF, "PROF", N_("Profiling timer expired"))
-#endif
-#ifdef SIGWINCH
- init_sig (SIGWINCH, "WINCH", N_("Window changed"))
-#endif
-#ifdef SIGUSR1
- init_sig (SIGUSR1, "USR1", N_("User defined signal 1"))
-#endif
-#ifdef SIGUSR2
- init_sig (SIGUSR2, "USR2", N_("User defined signal 2"))
-#endif
-
-/* Variations */
-#ifdef SIGEMT
- init_sig (SIGEMT, "EMT", N_("EMT trap"))
-#endif
-#ifdef SIGSYS
- init_sig (SIGSYS, "SYS", N_("Bad system call"))
-#endif
-#ifdef SIGSTKFLT
- init_sig (SIGSTKFLT, "STKFLT", N_("Stack fault"))
-#endif
-#ifdef SIGINFO
- init_sig (SIGINFO, "INFO", N_("Information request"))
-#elif defined(SIGPWR) && (!defined(SIGLOST) || (SIGPWR != SIGLOST))
- init_sig (SIGPWR, "PWR", N_("Power failure"))
-#endif
-#ifdef SIGLOST
- init_sig (SIGLOST, "LOST", N_("Resource lost"))
-#endif
+/* Canonical list of all signal names.
+ Copyright (C) 1996-1999, 2008-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* This file should be usable for any platform, since it just associates
+ the SIG* macros with text names and descriptions. The actual values
+ come from <bits/signum.h> (via <signal.h>). For any signal macros do not
+ exist on every platform, we can use #ifdef tests here and still use
+ this single common file for all platforms. */
+
+/* This file is included multiple times. */
+
+/* Duplicate values (such as SIGBUS==SIGSEGV on Haiku) favor the last
+ list entry. */
+
+/* Standard signals */
+#ifdef SIGHUP
+ init_sig (SIGHUP, "HUP", N_("Hangup"))
+#endif
+#ifdef SIGINT
+ init_sig (SIGINT, "INT", N_("Interrupt"))
+#endif
+#ifdef SIGQUIT
+ init_sig (SIGQUIT, "QUIT", N_("Quit"))
+#endif
+#ifdef SIGILL
+ init_sig (SIGILL, "ILL", N_("Illegal instruction"))
+#endif
+#ifdef SIGTRAP
+ init_sig (SIGTRAP, "TRAP", N_("Trace/breakpoint trap"))
+#endif
+#ifdef SIGABRT
+ init_sig (SIGABRT, "ABRT", N_("Aborted"))
+#endif
+#ifdef SIGFPE
+ init_sig (SIGFPE, "FPE", N_("Floating point exception"))
+#endif
+#ifdef SIGKILL
+ init_sig (SIGKILL, "KILL", N_("Killed"))
+#endif
+#ifdef SIGBUS
+ init_sig (SIGBUS, "BUS", N_("Bus error"))
+#endif
+#ifdef SIGSEGV
+ init_sig (SIGSEGV, "SEGV", N_("Segmentation fault"))
+#endif
+#ifdef SIGPIPE
+ init_sig (SIGPIPE, "PIPE", N_("Broken pipe"))
+#endif
+#ifdef SIGALRM
+ init_sig (SIGALRM, "ALRM", N_("Alarm clock"))
+#endif
+#ifdef SIGTERM
+ init_sig (SIGTERM, "TERM", N_("Terminated"))
+#endif
+#ifdef SIGURG
+ init_sig (SIGURG, "URG", N_("Urgent I/O condition"))
+#endif
+#ifdef SIGSTOP
+ init_sig (SIGSTOP, "STOP", N_("Stopped (signal)"))
+#endif
+#ifdef SIGTSTP
+ init_sig (SIGTSTP, "TSTP", N_("Stopped"))
+#endif
+#ifdef SIGCONT
+ init_sig (SIGCONT, "CONT", N_("Continued"))
+#endif
+#ifdef SIGCHLD
+ init_sig (SIGCHLD, "CHLD", N_("Child exited"))
+#endif
+#ifdef SIGTTIN
+ init_sig (SIGTTIN, "TTIN", N_("Stopped (tty input)"))
+#endif
+#ifdef SIGTTOU
+ init_sig (SIGTTOU, "TTOU", N_("Stopped (tty output)"))
+#endif
+#ifdef SIGIO
+ init_sig (SIGIO, "IO", N_("I/O possible"))
+#endif
+#ifdef SIGXCPU
+ init_sig (SIGXCPU, "XCPU", N_("CPU time limit exceeded"))
+#endif
+#ifdef SIGXFSZ
+ init_sig (SIGXFSZ, "XFSZ", N_("File size limit exceeded"))
+#endif
+#ifdef SIGVTALRM
+ init_sig (SIGVTALRM, "VTALRM", N_("Virtual timer expired"))
+#endif
+#ifdef SIGPROF
+ init_sig (SIGPROF, "PROF", N_("Profiling timer expired"))
+#endif
+#ifdef SIGWINCH
+ init_sig (SIGWINCH, "WINCH", N_("Window changed"))
+#endif
+#ifdef SIGUSR1
+ init_sig (SIGUSR1, "USR1", N_("User defined signal 1"))
+#endif
+#ifdef SIGUSR2
+ init_sig (SIGUSR2, "USR2", N_("User defined signal 2"))
+#endif
+
+/* Variations */
+#ifdef SIGEMT
+ init_sig (SIGEMT, "EMT", N_("EMT trap"))
+#endif
+#ifdef SIGSYS
+ init_sig (SIGSYS, "SYS", N_("Bad system call"))
+#endif
+#ifdef SIGSTKFLT
+ init_sig (SIGSTKFLT, "STKFLT", N_("Stack fault"))
+#endif
+#ifdef SIGINFO
+ init_sig (SIGINFO, "INFO", N_("Information request"))
+#elif defined(SIGPWR) && (!defined(SIGLOST) || (SIGPWR != SIGLOST))
+ init_sig (SIGPWR, "PWR", N_("Power failure"))
+#endif
+#ifdef SIGLOST
+ init_sig (SIGLOST, "LOST", N_("Resource lost"))
+#endif
diff --git a/contrib/tools/bison/gnulib/src/signbitd.c b/contrib/tools/bison/gnulib/src/signbitd.c
index 7a434f8eea..4f71f020f8 100644
--- a/contrib/tools/bison/gnulib/src/signbitd.c
+++ b/contrib/tools/bison/gnulib/src/signbitd.c
@@ -1,64 +1,64 @@
-/* signbit() macro: Determine the sign bit of a floating-point number.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <math.h>
-
-#include <string.h>
-#include "isnand-nolibm.h"
-#include "float+.h"
-
-#ifdef gl_signbitd_OPTIMIZED_MACRO
-# undef gl_signbitd
-#endif
-
-int
-gl_signbitd (double arg)
-{
-#if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
- /* The use of a union to extract the bits of the representation of a
- 'long double' is safe in practice, despite of the "aliasing rules" of
- C99, because the GCC docs say
- "Even with '-fstrict-aliasing', type-punning is allowed, provided the
- memory is accessed through the union type."
- and similarly for other compilers. */
-# define NWORDS \
- ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
- union { double value; unsigned int word[NWORDS]; } m;
- m.value = arg;
- return (m.word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;
-#elif HAVE_COPYSIGN_IN_LIBC
- return copysign (1.0, arg) < 0;
-#else
- /* This does not do the right thing for NaN, but this is irrelevant for
- most use cases. */
- if (isnand (arg))
- return 0;
- if (arg < 0.0)
- return 1;
- else if (arg == 0.0)
- {
- /* Distinguish 0.0 and -0.0. */
- static double plus_zero = 0.0;
- double arg_mem = arg;
- return (memcmp (&plus_zero, &arg_mem, SIZEOF_DBL) != 0);
- }
- else
- return 0;
-#endif
-}
+/* signbit() macro: Determine the sign bit of a floating-point number.
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <math.h>
+
+#include <string.h>
+#include "isnand-nolibm.h"
+#include "float+.h"
+
+#ifdef gl_signbitd_OPTIMIZED_MACRO
+# undef gl_signbitd
+#endif
+
+int
+gl_signbitd (double arg)
+{
+#if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT
+ /* The use of a union to extract the bits of the representation of a
+ 'long double' is safe in practice, despite of the "aliasing rules" of
+ C99, because the GCC docs say
+ "Even with '-fstrict-aliasing', type-punning is allowed, provided the
+ memory is accessed through the union type."
+ and similarly for other compilers. */
+# define NWORDS \
+ ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+ union { double value; unsigned int word[NWORDS]; } m;
+ m.value = arg;
+ return (m.word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1;
+#elif HAVE_COPYSIGN_IN_LIBC
+ return copysign (1.0, arg) < 0;
+#else
+ /* This does not do the right thing for NaN, but this is irrelevant for
+ most use cases. */
+ if (isnand (arg))
+ return 0;
+ if (arg < 0.0)
+ return 1;
+ else if (arg == 0.0)
+ {
+ /* Distinguish 0.0 and -0.0. */
+ static double plus_zero = 0.0;
+ double arg_mem = arg;
+ return (memcmp (&plus_zero, &arg_mem, SIZEOF_DBL) != 0);
+ }
+ else
+ return 0;
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/signbitf.c b/contrib/tools/bison/gnulib/src/signbitf.c
index f133be57f5..fc88fa2677 100644
--- a/contrib/tools/bison/gnulib/src/signbitf.c
+++ b/contrib/tools/bison/gnulib/src/signbitf.c
@@ -1,64 +1,64 @@
-/* signbit() macro: Determine the sign bit of a floating-point number.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <math.h>
-
-#include <string.h>
-#include "isnanf-nolibm.h"
-#include "float+.h"
-
-#ifdef gl_signbitf_OPTIMIZED_MACRO
-# undef gl_signbitf
-#endif
-
-int
-gl_signbitf (float arg)
-{
-#if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
- /* The use of a union to extract the bits of the representation of a
- 'long double' is safe in practice, despite of the "aliasing rules" of
- C99, because the GCC docs say
- "Even with '-fstrict-aliasing', type-punning is allowed, provided the
- memory is accessed through the union type."
- and similarly for other compilers. */
-# define NWORDS \
- ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
- union { float value; unsigned int word[NWORDS]; } m;
- m.value = arg;
- return (m.word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;
-#elif HAVE_COPYSIGNF_IN_LIBC
- return copysignf (1.0f, arg) < 0;
-#else
- /* This does not do the right thing for NaN, but this is irrelevant for
- most use cases. */
- if (isnanf (arg))
- return 0;
- if (arg < 0.0f)
- return 1;
- else if (arg == 0.0f)
- {
- /* Distinguish 0.0f and -0.0f. */
- static float plus_zero = 0.0f;
- float arg_mem = arg;
- return (memcmp (&plus_zero, &arg_mem, SIZEOF_FLT) != 0);
- }
- else
- return 0;
-#endif
-}
+/* signbit() macro: Determine the sign bit of a floating-point number.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <math.h>
+
+#include <string.h>
+#include "isnanf-nolibm.h"
+#include "float+.h"
+
+#ifdef gl_signbitf_OPTIMIZED_MACRO
+# undef gl_signbitf
+#endif
+
+int
+gl_signbitf (float arg)
+{
+#if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT
+ /* The use of a union to extract the bits of the representation of a
+ 'long double' is safe in practice, despite of the "aliasing rules" of
+ C99, because the GCC docs say
+ "Even with '-fstrict-aliasing', type-punning is allowed, provided the
+ memory is accessed through the union type."
+ and similarly for other compilers. */
+# define NWORDS \
+ ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+ union { float value; unsigned int word[NWORDS]; } m;
+ m.value = arg;
+ return (m.word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1;
+#elif HAVE_COPYSIGNF_IN_LIBC
+ return copysignf (1.0f, arg) < 0;
+#else
+ /* This does not do the right thing for NaN, but this is irrelevant for
+ most use cases. */
+ if (isnanf (arg))
+ return 0;
+ if (arg < 0.0f)
+ return 1;
+ else if (arg == 0.0f)
+ {
+ /* Distinguish 0.0f and -0.0f. */
+ static float plus_zero = 0.0f;
+ float arg_mem = arg;
+ return (memcmp (&plus_zero, &arg_mem, SIZEOF_FLT) != 0);
+ }
+ else
+ return 0;
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/signbitl.c b/contrib/tools/bison/gnulib/src/signbitl.c
index 9e1e900e16..f23831233f 100644
--- a/contrib/tools/bison/gnulib/src/signbitl.c
+++ b/contrib/tools/bison/gnulib/src/signbitl.c
@@ -1,64 +1,64 @@
-/* signbit() macro: Determine the sign bit of a floating-point number.
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <math.h>
-
-#include <string.h>
-#include "isnanl-nolibm.h"
-#include "float+.h"
-
-#ifdef gl_signbitl_OPTIMIZED_MACRO
-# undef gl_signbitl
-#endif
-
-int
-gl_signbitl (long double arg)
-{
-#if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
- /* The use of a union to extract the bits of the representation of a
- 'long double' is safe in practice, despite of the "aliasing rules" of
- C99, because the GCC docs say
- "Even with '-fstrict-aliasing', type-punning is allowed, provided the
- memory is accessed through the union type."
- and similarly for other compilers. */
-# define NWORDS \
- ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
- union { long double value; unsigned int word[NWORDS]; } m;
- m.value = arg;
- return (m.word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;
-#elif HAVE_COPYSIGNL_IN_LIBC
- return copysignl (1.0L, arg) < 0;
-#else
- /* This does not do the right thing for NaN, but this is irrelevant for
- most use cases. */
- if (isnanl (arg))
- return 0;
- if (arg < 0.0L)
- return 1;
- else if (arg == 0.0L)
- {
- /* Distinguish 0.0L and -0.0L. */
- static long double plus_zero = 0.0L;
- long double arg_mem = arg;
- return (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0);
- }
- else
- return 0;
-#endif
-}
+/* signbit() macro: Determine the sign bit of a floating-point number.
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <math.h>
+
+#include <string.h>
+#include "isnanl-nolibm.h"
+#include "float+.h"
+
+#ifdef gl_signbitl_OPTIMIZED_MACRO
+# undef gl_signbitl
+#endif
+
+int
+gl_signbitl (long double arg)
+{
+#if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT
+ /* The use of a union to extract the bits of the representation of a
+ 'long double' is safe in practice, despite of the "aliasing rules" of
+ C99, because the GCC docs say
+ "Even with '-fstrict-aliasing', type-punning is allowed, provided the
+ memory is accessed through the union type."
+ and similarly for other compilers. */
+# define NWORDS \
+ ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+ union { long double value; unsigned int word[NWORDS]; } m;
+ m.value = arg;
+ return (m.word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1;
+#elif HAVE_COPYSIGNL_IN_LIBC
+ return copysignl (1.0L, arg) < 0;
+#else
+ /* This does not do the right thing for NaN, but this is irrelevant for
+ most use cases. */
+ if (isnanl (arg))
+ return 0;
+ if (arg < 0.0L)
+ return 1;
+ else if (arg == 0.0L)
+ {
+ /* Distinguish 0.0L and -0.0L. */
+ static long double plus_zero = 0.0L;
+ long double arg_mem = arg;
+ return (memcmp (&plus_zero, &arg_mem, SIZEOF_LDBL) != 0);
+ }
+ else
+ return 0;
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/sigprocmask.c b/contrib/tools/bison/gnulib/src/sigprocmask.c
index 8de3777db3..55f81e2cb1 100644
--- a/contrib/tools/bison/gnulib/src/sigprocmask.c
+++ b/contrib/tools/bison/gnulib/src/sigprocmask.c
@@ -1,349 +1,349 @@
-/* POSIX compatible signal blocking.
- Copyright (C) 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2006.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <signal.h>
-
-#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-# include "msvc-inval.h"
-#endif
-
-/* We assume that a platform without POSIX signal blocking functions
- also does not have the POSIX sigaction() function, only the
- signal() function. We also assume signal() has SysV semantics,
- where any handler is uninstalled prior to being invoked. This is
- true for native Windows platforms. */
-
-/* We use raw signal(), but also provide a wrapper rpl_signal() so
- that applications can query or change a blocked signal. */
-#undef signal
-
-/* Provide invalid signal numbers as fallbacks if the uncatchable
- signals are not defined. */
-#ifndef SIGKILL
-# define SIGKILL (-1)
-#endif
-#ifndef SIGSTOP
-# define SIGSTOP (-1)
-#endif
-
-/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
- for the signal SIGABRT. Only one signal handler is stored for both
- SIGABRT and SIGABRT_COMPAT. SIGABRT_COMPAT is not a signal of its own. */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-# undef SIGABRT_COMPAT
-# define SIGABRT_COMPAT 6
-#endif
-#ifdef SIGABRT_COMPAT
-# define SIGABRT_COMPAT_MASK (1U << SIGABRT_COMPAT)
-#else
-# define SIGABRT_COMPAT_MASK 0
-#endif
-
-typedef void (*handler_t) (int);
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static handler_t
-signal_nothrow (int sig, handler_t handler)
-{
- handler_t result;
-
- TRY_MSVC_INVAL
- {
- result = signal (sig, handler);
- }
- CATCH_MSVC_INVAL
- {
- result = SIG_ERR;
- errno = EINVAL;
- }
- DONE_MSVC_INVAL;
-
- return result;
-}
-# define signal signal_nothrow
-#endif
-
-/* Handling of gnulib defined signals. */
-
-#if GNULIB_defined_SIGPIPE
-static handler_t SIGPIPE_handler = SIG_DFL;
-#endif
-
-#if GNULIB_defined_SIGPIPE
-static handler_t
-ext_signal (int sig, handler_t handler)
-{
- switch (sig)
- {
- case SIGPIPE:
- {
- handler_t old_handler = SIGPIPE_handler;
- SIGPIPE_handler = handler;
- return old_handler;
- }
- default: /* System defined signal */
- return signal (sig, handler);
- }
-}
-# undef signal
-# define signal ext_signal
-#endif
-
-int
-sigismember (const sigset_t *set, int sig)
-{
- if (sig >= 0 && sig < NSIG)
- {
- #ifdef SIGABRT_COMPAT
- if (sig == SIGABRT_COMPAT)
- sig = SIGABRT;
- #endif
-
- return (*set >> sig) & 1;
- }
- else
- return 0;
-}
-
-int
-sigemptyset (sigset_t *set)
-{
- *set = 0;
- return 0;
-}
-
-int
-sigaddset (sigset_t *set, int sig)
-{
- if (sig >= 0 && sig < NSIG)
- {
- #ifdef SIGABRT_COMPAT
- if (sig == SIGABRT_COMPAT)
- sig = SIGABRT;
- #endif
-
- *set |= 1U << sig;
- return 0;
- }
- else
- {
- errno = EINVAL;
- return -1;
- }
-}
-
-int
-sigdelset (sigset_t *set, int sig)
-{
- if (sig >= 0 && sig < NSIG)
- {
- #ifdef SIGABRT_COMPAT
- if (sig == SIGABRT_COMPAT)
- sig = SIGABRT;
- #endif
-
- *set &= ~(1U << sig);
- return 0;
- }
- else
- {
- errno = EINVAL;
- return -1;
- }
-}
-
-
-int
-sigfillset (sigset_t *set)
-{
- *set = ((2U << (NSIG - 1)) - 1) & ~ SIGABRT_COMPAT_MASK;
- return 0;
-}
-
-/* Set of currently blocked signals. */
-static volatile sigset_t blocked_set /* = 0 */;
-
-/* Set of currently blocked and pending signals. */
-static volatile sig_atomic_t pending_array[NSIG] /* = { 0 } */;
-
-/* Signal handler that is installed for blocked signals. */
-static void
-blocked_handler (int sig)
-{
- /* Reinstall the handler, in case the signal occurs multiple times
- while blocked. There is an inherent race where an asynchronous
- signal in between when the kernel uninstalled the handler and
- when we reinstall it will trigger the default handler; oh
- well. */
- signal (sig, blocked_handler);
- if (sig >= 0 && sig < NSIG)
- pending_array[sig] = 1;
-}
-
-int
-sigpending (sigset_t *set)
-{
- sigset_t pending = 0;
- int sig;
-
- for (sig = 0; sig < NSIG; sig++)
- if (pending_array[sig])
- pending |= 1U << sig;
- *set = pending;
- return 0;
-}
-
-/* The previous signal handlers.
- Only the array elements corresponding to blocked signals are relevant. */
-static volatile handler_t old_handlers[NSIG];
-
-int
-sigprocmask (int operation, const sigset_t *set, sigset_t *old_set)
-{
- if (old_set != NULL)
- *old_set = blocked_set;
-
- if (set != NULL)
- {
- sigset_t new_blocked_set;
- sigset_t to_unblock;
- sigset_t to_block;
-
- switch (operation)
- {
- case SIG_BLOCK:
- new_blocked_set = blocked_set | *set;
- break;
- case SIG_SETMASK:
- new_blocked_set = *set;
- break;
- case SIG_UNBLOCK:
- new_blocked_set = blocked_set & ~*set;
- break;
- default:
- errno = EINVAL;
- return -1;
- }
- to_unblock = blocked_set & ~new_blocked_set;
- to_block = new_blocked_set & ~blocked_set;
-
- if (to_block != 0)
- {
- int sig;
-
- for (sig = 0; sig < NSIG; sig++)
- if ((to_block >> sig) & 1)
- {
- pending_array[sig] = 0;
- if ((old_handlers[sig] = signal (sig, blocked_handler)) != SIG_ERR)
- blocked_set |= 1U << sig;
- }
- }
-
- if (to_unblock != 0)
- {
- sig_atomic_t received[NSIG];
- int sig;
-
- for (sig = 0; sig < NSIG; sig++)
- if ((to_unblock >> sig) & 1)
- {
- if (signal (sig, old_handlers[sig]) != blocked_handler)
- /* The application changed a signal handler while the signal
- was blocked, bypassing our rpl_signal replacement.
- We don't support this. */
- abort ();
- received[sig] = pending_array[sig];
- blocked_set &= ~(1U << sig);
- pending_array[sig] = 0;
- }
- else
- received[sig] = 0;
-
- for (sig = 0; sig < NSIG; sig++)
- if (received[sig])
- raise (sig);
- }
- }
- return 0;
-}
-
-/* Install the handler FUNC for signal SIG, and return the previous
- handler. */
-handler_t
-rpl_signal (int sig, handler_t handler)
-{
- /* We must provide a wrapper, so that a user can query what handler
- they installed even if that signal is currently blocked. */
- if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP
- && handler != SIG_ERR)
- {
- #ifdef SIGABRT_COMPAT
- if (sig == SIGABRT_COMPAT)
- sig = SIGABRT;
- #endif
-
- if (blocked_set & (1U << sig))
- {
- /* POSIX states that sigprocmask and signal are both
- async-signal-safe. This is not true of our
- implementation - there is a slight data race where an
- asynchronous interrupt on signal A can occur after we
- install blocked_handler but before we have updated
- old_handlers for signal B, such that handler A can see
- stale information if it calls signal(B). Oh well -
- signal handlers really shouldn't try to manipulate the
- installed handlers of unrelated signals. */
- handler_t result = old_handlers[sig];
- old_handlers[sig] = handler;
- return result;
- }
- else
- return signal (sig, handler);
- }
- else
- {
- errno = EINVAL;
- return SIG_ERR;
- }
-}
-
-#if GNULIB_defined_SIGPIPE
-/* Raise the signal SIGPIPE. */
-int
-_gl_raise_SIGPIPE (void)
-{
- if (blocked_set & (1U << SIGPIPE))
- pending_array[SIGPIPE] = 1;
- else
- {
- handler_t handler = SIGPIPE_handler;
- if (handler == SIG_DFL)
- exit (128 + SIGPIPE);
- else if (handler != SIG_IGN)
- (*handler) (SIGPIPE);
- }
- return 0;
-}
-#endif
+/* POSIX compatible signal blocking.
+ Copyright (C) 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2006.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <signal.h>
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+/* We assume that a platform without POSIX signal blocking functions
+ also does not have the POSIX sigaction() function, only the
+ signal() function. We also assume signal() has SysV semantics,
+ where any handler is uninstalled prior to being invoked. This is
+ true for native Windows platforms. */
+
+/* We use raw signal(), but also provide a wrapper rpl_signal() so
+ that applications can query or change a blocked signal. */
+#undef signal
+
+/* Provide invalid signal numbers as fallbacks if the uncatchable
+ signals are not defined. */
+#ifndef SIGKILL
+# define SIGKILL (-1)
+#endif
+#ifndef SIGSTOP
+# define SIGSTOP (-1)
+#endif
+
+/* On native Windows, as of 2008, the signal SIGABRT_COMPAT is an alias
+ for the signal SIGABRT. Only one signal handler is stored for both
+ SIGABRT and SIGABRT_COMPAT. SIGABRT_COMPAT is not a signal of its own. */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# undef SIGABRT_COMPAT
+# define SIGABRT_COMPAT 6
+#endif
+#ifdef SIGABRT_COMPAT
+# define SIGABRT_COMPAT_MASK (1U << SIGABRT_COMPAT)
+#else
+# define SIGABRT_COMPAT_MASK 0
+#endif
+
+typedef void (*handler_t) (int);
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static handler_t
+signal_nothrow (int sig, handler_t handler)
+{
+ handler_t result;
+
+ TRY_MSVC_INVAL
+ {
+ result = signal (sig, handler);
+ }
+ CATCH_MSVC_INVAL
+ {
+ result = SIG_ERR;
+ errno = EINVAL;
+ }
+ DONE_MSVC_INVAL;
+
+ return result;
+}
+# define signal signal_nothrow
+#endif
+
+/* Handling of gnulib defined signals. */
+
+#if GNULIB_defined_SIGPIPE
+static handler_t SIGPIPE_handler = SIG_DFL;
+#endif
+
+#if GNULIB_defined_SIGPIPE
+static handler_t
+ext_signal (int sig, handler_t handler)
+{
+ switch (sig)
+ {
+ case SIGPIPE:
+ {
+ handler_t old_handler = SIGPIPE_handler;
+ SIGPIPE_handler = handler;
+ return old_handler;
+ }
+ default: /* System defined signal */
+ return signal (sig, handler);
+ }
+}
+# undef signal
+# define signal ext_signal
+#endif
+
+int
+sigismember (const sigset_t *set, int sig)
+{
+ if (sig >= 0 && sig < NSIG)
+ {
+ #ifdef SIGABRT_COMPAT
+ if (sig == SIGABRT_COMPAT)
+ sig = SIGABRT;
+ #endif
+
+ return (*set >> sig) & 1;
+ }
+ else
+ return 0;
+}
+
+int
+sigemptyset (sigset_t *set)
+{
+ *set = 0;
+ return 0;
+}
+
+int
+sigaddset (sigset_t *set, int sig)
+{
+ if (sig >= 0 && sig < NSIG)
+ {
+ #ifdef SIGABRT_COMPAT
+ if (sig == SIGABRT_COMPAT)
+ sig = SIGABRT;
+ #endif
+
+ *set |= 1U << sig;
+ return 0;
+ }
+ else
+ {
+ errno = EINVAL;
+ return -1;
+ }
+}
+
+int
+sigdelset (sigset_t *set, int sig)
+{
+ if (sig >= 0 && sig < NSIG)
+ {
+ #ifdef SIGABRT_COMPAT
+ if (sig == SIGABRT_COMPAT)
+ sig = SIGABRT;
+ #endif
+
+ *set &= ~(1U << sig);
+ return 0;
+ }
+ else
+ {
+ errno = EINVAL;
+ return -1;
+ }
+}
+
+
+int
+sigfillset (sigset_t *set)
+{
+ *set = ((2U << (NSIG - 1)) - 1) & ~ SIGABRT_COMPAT_MASK;
+ return 0;
+}
+
+/* Set of currently blocked signals. */
+static volatile sigset_t blocked_set /* = 0 */;
+
+/* Set of currently blocked and pending signals. */
+static volatile sig_atomic_t pending_array[NSIG] /* = { 0 } */;
+
+/* Signal handler that is installed for blocked signals. */
+static void
+blocked_handler (int sig)
+{
+ /* Reinstall the handler, in case the signal occurs multiple times
+ while blocked. There is an inherent race where an asynchronous
+ signal in between when the kernel uninstalled the handler and
+ when we reinstall it will trigger the default handler; oh
+ well. */
+ signal (sig, blocked_handler);
+ if (sig >= 0 && sig < NSIG)
+ pending_array[sig] = 1;
+}
+
+int
+sigpending (sigset_t *set)
+{
+ sigset_t pending = 0;
+ int sig;
+
+ for (sig = 0; sig < NSIG; sig++)
+ if (pending_array[sig])
+ pending |= 1U << sig;
+ *set = pending;
+ return 0;
+}
+
+/* The previous signal handlers.
+ Only the array elements corresponding to blocked signals are relevant. */
+static volatile handler_t old_handlers[NSIG];
+
+int
+sigprocmask (int operation, const sigset_t *set, sigset_t *old_set)
+{
+ if (old_set != NULL)
+ *old_set = blocked_set;
+
+ if (set != NULL)
+ {
+ sigset_t new_blocked_set;
+ sigset_t to_unblock;
+ sigset_t to_block;
+
+ switch (operation)
+ {
+ case SIG_BLOCK:
+ new_blocked_set = blocked_set | *set;
+ break;
+ case SIG_SETMASK:
+ new_blocked_set = *set;
+ break;
+ case SIG_UNBLOCK:
+ new_blocked_set = blocked_set & ~*set;
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+ to_unblock = blocked_set & ~new_blocked_set;
+ to_block = new_blocked_set & ~blocked_set;
+
+ if (to_block != 0)
+ {
+ int sig;
+
+ for (sig = 0; sig < NSIG; sig++)
+ if ((to_block >> sig) & 1)
+ {
+ pending_array[sig] = 0;
+ if ((old_handlers[sig] = signal (sig, blocked_handler)) != SIG_ERR)
+ blocked_set |= 1U << sig;
+ }
+ }
+
+ if (to_unblock != 0)
+ {
+ sig_atomic_t received[NSIG];
+ int sig;
+
+ for (sig = 0; sig < NSIG; sig++)
+ if ((to_unblock >> sig) & 1)
+ {
+ if (signal (sig, old_handlers[sig]) != blocked_handler)
+ /* The application changed a signal handler while the signal
+ was blocked, bypassing our rpl_signal replacement.
+ We don't support this. */
+ abort ();
+ received[sig] = pending_array[sig];
+ blocked_set &= ~(1U << sig);
+ pending_array[sig] = 0;
+ }
+ else
+ received[sig] = 0;
+
+ for (sig = 0; sig < NSIG; sig++)
+ if (received[sig])
+ raise (sig);
+ }
+ }
+ return 0;
+}
+
+/* Install the handler FUNC for signal SIG, and return the previous
+ handler. */
+handler_t
+rpl_signal (int sig, handler_t handler)
+{
+ /* We must provide a wrapper, so that a user can query what handler
+ they installed even if that signal is currently blocked. */
+ if (sig >= 0 && sig < NSIG && sig != SIGKILL && sig != SIGSTOP
+ && handler != SIG_ERR)
+ {
+ #ifdef SIGABRT_COMPAT
+ if (sig == SIGABRT_COMPAT)
+ sig = SIGABRT;
+ #endif
+
+ if (blocked_set & (1U << sig))
+ {
+ /* POSIX states that sigprocmask and signal are both
+ async-signal-safe. This is not true of our
+ implementation - there is a slight data race where an
+ asynchronous interrupt on signal A can occur after we
+ install blocked_handler but before we have updated
+ old_handlers for signal B, such that handler A can see
+ stale information if it calls signal(B). Oh well -
+ signal handlers really shouldn't try to manipulate the
+ installed handlers of unrelated signals. */
+ handler_t result = old_handlers[sig];
+ old_handlers[sig] = handler;
+ return result;
+ }
+ else
+ return signal (sig, handler);
+ }
+ else
+ {
+ errno = EINVAL;
+ return SIG_ERR;
+ }
+}
+
+#if GNULIB_defined_SIGPIPE
+/* Raise the signal SIGPIPE. */
+int
+_gl_raise_SIGPIPE (void)
+{
+ if (blocked_set & (1U << SIGPIPE))
+ pending_array[SIGPIPE] = 1;
+ else
+ {
+ handler_t handler = SIGPIPE_handler;
+ if (handler == SIG_DFL)
+ exit (128 + SIGPIPE);
+ else if (handler != SIG_IGN)
+ (*handler) (SIGPIPE);
+ }
+ return 0;
+}
+#endif
diff --git a/contrib/tools/bison/gnulib/src/size_max.h b/contrib/tools/bison/gnulib/src/size_max.h
index 5f3312404b..6ba9aee6ab 100644
--- a/contrib/tools/bison/gnulib/src/size_max.h
+++ b/contrib/tools/bison/gnulib/src/size_max.h
@@ -1,30 +1,30 @@
-/* size_max.h -- declare SIZE_MAX through system headers
- Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
- Written by Simon Josefsson.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef GNULIB_SIZE_MAX_H
-#define GNULIB_SIZE_MAX_H
-
-/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */
-# include <limits.h>
-/* Get SIZE_MAX declaration on systems like glibc 2. */
-# if HAVE_STDINT_H
-# include <stdint.h>
-# endif
-/* On systems where these include files don't define it, SIZE_MAX is defined
- in config.h. */
-
-#endif /* GNULIB_SIZE_MAX_H */
+/* size_max.h -- declare SIZE_MAX through system headers
+ Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GNULIB_SIZE_MAX_H
+#define GNULIB_SIZE_MAX_H
+
+/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */
+# include <limits.h>
+/* Get SIZE_MAX declaration on systems like glibc 2. */
+# if HAVE_STDINT_H
+# include <stdint.h>
+# endif
+/* On systems where these include files don't define it, SIZE_MAX is defined
+ in config.h. */
+
+#endif /* GNULIB_SIZE_MAX_H */
diff --git a/contrib/tools/bison/gnulib/src/snprintf.c b/contrib/tools/bison/gnulib/src/snprintf.c
index 9c34de3bb2..2a01ad2125 100644
--- a/contrib/tools/bison/gnulib/src/snprintf.c
+++ b/contrib/tools/bison/gnulib/src/snprintf.c
@@ -1,76 +1,76 @@
-/* Formatted output to strings.
- Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
- Written by Simon Josefsson and Paul Eggert.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "vasnprintf.h"
-
+/* Formatted output to strings.
+ Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
+ Written by Simon Josefsson and Paul Eggert.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "vasnprintf.h"
+
#if defined(_MSC_VER) && _MSC_VER < 1900
-/* Print formatted output to string STR. Similar to sprintf, but
- additional length SIZE limit how much is written into STR. Returns
- string length of formatted string (which may be larger than SIZE).
- STR may be NULL, in which case nothing will be written. On error,
- return a negative value. */
-int
-snprintf (char *str, size_t size, const char *format, ...)
-{
- char *output;
- size_t len;
- size_t lenbuf = size;
- va_list args;
-
- va_start (args, format);
- output = vasnprintf (str, &lenbuf, format, args);
- len = lenbuf;
- va_end (args);
-
- if (!output)
- return -1;
-
- if (output != str)
- {
- if (size)
- {
- size_t pruned_len = (len < size ? len : size - 1);
- memcpy (str, output, pruned_len);
- str[pruned_len] = '\0';
- }
-
- free (output);
- }
-
- if (INT_MAX < len)
- {
+/* Print formatted output to string STR. Similar to sprintf, but
+ additional length SIZE limit how much is written into STR. Returns
+ string length of formatted string (which may be larger than SIZE).
+ STR may be NULL, in which case nothing will be written. On error,
+ return a negative value. */
+int
+snprintf (char *str, size_t size, const char *format, ...)
+{
+ char *output;
+ size_t len;
+ size_t lenbuf = size;
+ va_list args;
+
+ va_start (args, format);
+ output = vasnprintf (str, &lenbuf, format, args);
+ len = lenbuf;
+ va_end (args);
+
+ if (!output)
+ return -1;
+
+ if (output != str)
+ {
+ if (size)
+ {
+ size_t pruned_len = (len < size ? len : size - 1);
+ memcpy (str, output, pruned_len);
+ str[pruned_len] = '\0';
+ }
+
+ free (output);
+ }
+
+ if (INT_MAX < len)
+ {
#if (defined _MSC_VER) && (MSC_VER < 1800)
#else
- errno = EOVERFLOW;
+ errno = EOVERFLOW;
#endif
- return -1;
- }
-
- return len;
-}
+ return -1;
+ }
+
+ return len;
+}
#endif
diff --git a/contrib/tools/bison/gnulib/src/spawn-pipe.c b/contrib/tools/bison/gnulib/src/spawn-pipe.c
index 86b929a7f4..b2cfe946c4 100644
--- a/contrib/tools/bison/gnulib/src/spawn-pipe.c
+++ b/contrib/tools/bison/gnulib/src/spawn-pipe.c
@@ -1,453 +1,453 @@
-/* Creation of subprocesses, communicating via pipes.
- Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#include <config.h>
-
-/* Specification. */
-#include "spawn-pipe.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
-
+/* Creation of subprocesses, communicating via pipes.
+ Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include <config.h>
+
+/* Specification. */
+#include "spawn-pipe.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
#include "penviron.h"
-#include "error.h"
-#include "fatal-signal.h"
-#include "unistd-safer.h"
-#include "wait-process.h"
-#include "gettext.h"
-
-#define _(str) gettext (str)
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* Native Windows API. */
-# include <process.h>
-# include "w32spawn.h"
-
-#else
-
-/* Unix API. */
-# include <spawn.h>
-
-#endif
-
-/* The results of open() in this file are not used with fchdir,
- therefore save some unnecessary work in fchdir.c. */
-#undef open
-#undef close
-
-
-#ifdef EINTR
-
-/* EINTR handling for close().
- These functions can return -1/EINTR even though we don't have any
- signal handlers set up, namely when we get interrupted via SIGSTOP. */
-
-static int
-nonintr_close (int fd)
-{
- int retval;
-
- do
- retval = close (fd);
- while (retval < 0 && errno == EINTR);
-
- return retval;
-}
-#define close nonintr_close
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-static int
-nonintr_open (const char *pathname, int oflag, mode_t mode)
-{
- int retval;
-
- do
- retval = open (pathname, oflag, mode);
- while (retval < 0 && errno == EINTR);
-
- return retval;
-}
-# undef open /* avoid warning on VMS */
-# define open nonintr_open
-#endif
-
-#endif
-
-
-/* Open a pipe connected to a child process.
- *
- * write system read
- * parent -> fd[1] -> STDIN_FILENO -> child if pipe_stdin
- * parent <- fd[0] <- STDOUT_FILENO <- child if pipe_stdout
- * read system write
- *
- * At least one of pipe_stdin, pipe_stdout must be true.
- * pipe_stdin and prog_stdin together determine the child's standard input.
- * pipe_stdout and prog_stdout together determine the child's standard output.
- * If pipe_stdin is true, prog_stdin is ignored.
- * If pipe_stdout is true, prog_stdout is ignored.
- */
-static pid_t
-create_pipe (const char *progname,
- const char *prog_path, char **prog_argv,
- bool pipe_stdin, bool pipe_stdout,
- const char *prog_stdin, const char *prog_stdout,
- bool null_stderr,
- bool slave_process, bool exit_on_error,
- int fd[2])
-{
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
- /* Native Windows API.
- This uses _pipe(), dup2(), and spawnv(). It could also be implemented
- using the low-level functions CreatePipe(), DuplicateHandle(),
- CreateProcess() and _open_osfhandle(); see the GNU make and GNU clisp
- and cvs source code. */
- int ifd[2];
- int ofd[2];
- int orig_stdin;
- int orig_stdout;
- int orig_stderr;
- int child;
- int nulloutfd;
- int stdinfd;
- int stdoutfd;
- int saved_errno;
-
- /* FIXME: Need to free memory allocated by prepare_spawn. */
- prog_argv = prepare_spawn (prog_argv);
-
- if (pipe_stdout)
- if (pipe2_safer (ifd, O_BINARY | O_CLOEXEC) < 0)
- error (EXIT_FAILURE, errno, _("cannot create pipe"));
- if (pipe_stdin)
- if (pipe2_safer (ofd, O_BINARY | O_CLOEXEC) < 0)
- error (EXIT_FAILURE, errno, _("cannot create pipe"));
-/* Data flow diagram:
- *
- * write system read
- * parent -> ofd[1] -> ofd[0] -> child if pipe_stdin
- * parent <- ifd[0] <- ifd[1] <- child if pipe_stdout
- * read system write
- *
- */
-
- /* Save standard file handles of parent process. */
- if (pipe_stdin || prog_stdin != NULL)
- orig_stdin = dup_safer_noinherit (STDIN_FILENO);
- if (pipe_stdout || prog_stdout != NULL)
- orig_stdout = dup_safer_noinherit (STDOUT_FILENO);
- if (null_stderr)
- orig_stderr = dup_safer_noinherit (STDERR_FILENO);
- child = -1;
-
- /* Create standard file handles of child process. */
- nulloutfd = -1;
- stdinfd = -1;
- stdoutfd = -1;
- if ((!pipe_stdin || dup2 (ofd[0], STDIN_FILENO) >= 0)
- && (!pipe_stdout || dup2 (ifd[1], STDOUT_FILENO) >= 0)
- && (!null_stderr
- || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
- && (nulloutfd == STDERR_FILENO
- || (dup2 (nulloutfd, STDERR_FILENO) >= 0
- && close (nulloutfd) >= 0))))
- && (pipe_stdin
- || prog_stdin == NULL
- || ((stdinfd = open (prog_stdin, O_RDONLY, 0)) >= 0
- && (stdinfd == STDIN_FILENO
- || (dup2 (stdinfd, STDIN_FILENO) >= 0
- && close (stdinfd) >= 0))))
- && (pipe_stdout
- || prog_stdout == NULL
- || ((stdoutfd = open (prog_stdout, O_WRONLY, 0)) >= 0
- && (stdoutfd == STDOUT_FILENO
- || (dup2 (stdoutfd, STDOUT_FILENO) >= 0
- && close (stdoutfd) >= 0)))))
- /* The child process doesn't inherit ifd[0], ifd[1], ofd[0], ofd[1],
- but it inherits all open()ed or dup2()ed file handles (which is what
- we want in the case of STD*_FILENO). */
- /* Use spawnvpe and pass the environment explicitly. This is needed if
- the program has modified the environment using putenv() or [un]setenv().
- On Windows, programs have two environments, one in the "environment
- block" of the process and managed through SetEnvironmentVariable(), and
- one inside the process, in the location retrieved by the 'environ'
- macro. When using spawnvp() without 'e', the child process inherits a
- copy of the environment block - ignoring the effects of putenv() and
- [un]setenv(). */
- {
- child = spawnvpe (P_NOWAIT, prog_path, (const char **) prog_argv,
- (const char **) environ);
- if (child < 0 && errno == ENOEXEC)
- {
- /* prog is not a native executable. Try to execute it as a
- shell script. Note that prepare_spawn() has already prepended
- a hidden element "sh.exe" to prog_argv. */
- --prog_argv;
- child = spawnvpe (P_NOWAIT, prog_argv[0], (const char **) prog_argv,
- (const char **) environ);
- }
- }
- if (child == -1)
- saved_errno = errno;
- if (stdinfd >= 0)
- close (stdinfd);
- if (stdoutfd >= 0)
- close (stdoutfd);
- if (nulloutfd >= 0)
- close (nulloutfd);
-
- /* Restore standard file handles of parent process. */
- if (null_stderr)
- undup_safer_noinherit (orig_stderr, STDERR_FILENO);
- if (pipe_stdout || prog_stdout != NULL)
- undup_safer_noinherit (orig_stdout, STDOUT_FILENO);
- if (pipe_stdin || prog_stdin != NULL)
- undup_safer_noinherit (orig_stdin, STDIN_FILENO);
-
- if (pipe_stdin)
- close (ofd[0]);
- if (pipe_stdout)
- close (ifd[1]);
- if (child == -1)
- {
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, saved_errno,
- _("%s subprocess failed"), progname);
- if (pipe_stdout)
- close (ifd[0]);
- if (pipe_stdin)
- close (ofd[1]);
- errno = saved_errno;
- return -1;
- }
-
- if (pipe_stdout)
- fd[0] = ifd[0];
- if (pipe_stdin)
- fd[1] = ofd[1];
- return child;
-
-#else
-
- /* Unix API. */
- int ifd[2];
- int ofd[2];
- sigset_t blocked_signals;
- posix_spawn_file_actions_t actions;
- bool actions_allocated;
- posix_spawnattr_t attrs;
- bool attrs_allocated;
- int err;
- pid_t child;
-
- if (pipe_stdout)
- if (pipe_safer (ifd) < 0)
- error (EXIT_FAILURE, errno, _("cannot create pipe"));
- if (pipe_stdin)
- if (pipe_safer (ofd) < 0)
- error (EXIT_FAILURE, errno, _("cannot create pipe"));
-/* Data flow diagram:
- *
- * write system read
- * parent -> ofd[1] -> ofd[0] -> child if pipe_stdin
- * parent <- ifd[0] <- ifd[1] <- child if pipe_stdout
- * read system write
- *
- */
-
- if (slave_process)
- {
- sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
- block_fatal_signals ();
- }
- actions_allocated = false;
- attrs_allocated = false;
- if ((err = posix_spawn_file_actions_init (&actions)) != 0
- || (actions_allocated = true,
- (pipe_stdin
- && (err = posix_spawn_file_actions_adddup2 (&actions,
- ofd[0], STDIN_FILENO))
- != 0)
- || (pipe_stdout
- && (err = posix_spawn_file_actions_adddup2 (&actions,
- ifd[1], STDOUT_FILENO))
- != 0)
- || (pipe_stdin
- && (err = posix_spawn_file_actions_addclose (&actions, ofd[0]))
- != 0)
- || (pipe_stdout
- && (err = posix_spawn_file_actions_addclose (&actions, ifd[1]))
- != 0)
- || (pipe_stdin
- && (err = posix_spawn_file_actions_addclose (&actions, ofd[1]))
- != 0)
- || (pipe_stdout
- && (err = posix_spawn_file_actions_addclose (&actions, ifd[0]))
- != 0)
- || (null_stderr
- && (err = posix_spawn_file_actions_addopen (&actions,
- STDERR_FILENO,
- "/dev/null", O_RDWR,
- 0))
- != 0)
- || (!pipe_stdin
- && prog_stdin != NULL
- && (err = posix_spawn_file_actions_addopen (&actions,
- STDIN_FILENO,
- prog_stdin, O_RDONLY,
- 0))
- != 0)
- || (!pipe_stdout
- && prog_stdout != NULL
- && (err = posix_spawn_file_actions_addopen (&actions,
- STDOUT_FILENO,
- prog_stdout, O_WRONLY,
- 0))
- != 0)
- || (slave_process
- && ((err = posix_spawnattr_init (&attrs)) != 0
- || (attrs_allocated = true,
- (err = posix_spawnattr_setsigmask (&attrs,
- &blocked_signals))
- != 0
- || (err = posix_spawnattr_setflags (&attrs,
- POSIX_SPAWN_SETSIGMASK))
- != 0)))
- || (err = posix_spawnp (&child, prog_path, &actions,
- attrs_allocated ? &attrs : NULL, prog_argv,
- environ))
- != 0))
- {
- if (actions_allocated)
- posix_spawn_file_actions_destroy (&actions);
- if (attrs_allocated)
- posix_spawnattr_destroy (&attrs);
- if (slave_process)
- unblock_fatal_signals ();
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, err,
- _("%s subprocess failed"), progname);
- if (pipe_stdout)
- {
- close (ifd[0]);
- close (ifd[1]);
- }
- if (pipe_stdin)
- {
- close (ofd[0]);
- close (ofd[1]);
- }
- errno = err;
- return -1;
- }
- posix_spawn_file_actions_destroy (&actions);
- if (attrs_allocated)
- posix_spawnattr_destroy (&attrs);
- if (slave_process)
- {
- register_slave_subprocess (child);
- unblock_fatal_signals ();
- }
- if (pipe_stdin)
- close (ofd[0]);
- if (pipe_stdout)
- close (ifd[1]);
-
- if (pipe_stdout)
- fd[0] = ifd[0];
- if (pipe_stdin)
- fd[1] = ofd[1];
- return child;
-
-#endif
-}
-
-/* Open a bidirectional pipe.
- *
- * write system read
- * parent -> fd[1] -> STDIN_FILENO -> child
- * parent <- fd[0] <- STDOUT_FILENO <- child
- * read system write
- *
- */
-pid_t
-create_pipe_bidi (const char *progname,
- const char *prog_path, char **prog_argv,
- bool null_stderr,
- bool slave_process, bool exit_on_error,
- int fd[2])
-{
- pid_t result = create_pipe (progname, prog_path, prog_argv,
- true, true, NULL, NULL,
- null_stderr, slave_process, exit_on_error,
- fd);
- return result;
-}
-
-/* Open a pipe for input from a child process.
- * The child's stdin comes from a file.
- *
- * read system write
- * parent <- fd[0] <- STDOUT_FILENO <- child
- *
- */
-pid_t
-create_pipe_in (const char *progname,
- const char *prog_path, char **prog_argv,
- const char *prog_stdin, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int fd[1])
-{
- int iofd[2];
- pid_t result = create_pipe (progname, prog_path, prog_argv,
- false, true, prog_stdin, NULL,
- null_stderr, slave_process, exit_on_error,
- iofd);
- if (result != -1)
- fd[0] = iofd[0];
- return result;
-}
-
-/* Open a pipe for output to a child process.
- * The child's stdout goes to a file.
- *
- * write system read
- * parent -> fd[0] -> STDIN_FILENO -> child
- *
- */
-pid_t
-create_pipe_out (const char *progname,
- const char *prog_path, char **prog_argv,
- const char *prog_stdout, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int fd[1])
-{
- int iofd[2];
- pid_t result = create_pipe (progname, prog_path, prog_argv,
- true, false, NULL, prog_stdout,
- null_stderr, slave_process, exit_on_error,
- iofd);
- if (result != -1)
- fd[0] = iofd[1];
- return result;
-}
+#include "error.h"
+#include "fatal-signal.h"
+#include "unistd-safer.h"
+#include "wait-process.h"
+#include "gettext.h"
+
+#define _(str) gettext (str)
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Native Windows API. */
+# include <process.h>
+# include "w32spawn.h"
+
+#else
+
+/* Unix API. */
+# include <spawn.h>
+
+#endif
+
+/* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+#undef open
+#undef close
+
+
+#ifdef EINTR
+
+/* EINTR handling for close().
+ These functions can return -1/EINTR even though we don't have any
+ signal handlers set up, namely when we get interrupted via SIGSTOP. */
+
+static int
+nonintr_close (int fd)
+{
+ int retval;
+
+ do
+ retval = close (fd);
+ while (retval < 0 && errno == EINTR);
+
+ return retval;
+}
+#define close nonintr_close
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+static int
+nonintr_open (const char *pathname, int oflag, mode_t mode)
+{
+ int retval;
+
+ do
+ retval = open (pathname, oflag, mode);
+ while (retval < 0 && errno == EINTR);
+
+ return retval;
+}
+# undef open /* avoid warning on VMS */
+# define open nonintr_open
+#endif
+
+#endif
+
+
+/* Open a pipe connected to a child process.
+ *
+ * write system read
+ * parent -> fd[1] -> STDIN_FILENO -> child if pipe_stdin
+ * parent <- fd[0] <- STDOUT_FILENO <- child if pipe_stdout
+ * read system write
+ *
+ * At least one of pipe_stdin, pipe_stdout must be true.
+ * pipe_stdin and prog_stdin together determine the child's standard input.
+ * pipe_stdout and prog_stdout together determine the child's standard output.
+ * If pipe_stdin is true, prog_stdin is ignored.
+ * If pipe_stdout is true, prog_stdout is ignored.
+ */
+static pid_t
+create_pipe (const char *progname,
+ const char *prog_path, char **prog_argv,
+ bool pipe_stdin, bool pipe_stdout,
+ const char *prog_stdin, const char *prog_stdout,
+ bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int fd[2])
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+ /* Native Windows API.
+ This uses _pipe(), dup2(), and spawnv(). It could also be implemented
+ using the low-level functions CreatePipe(), DuplicateHandle(),
+ CreateProcess() and _open_osfhandle(); see the GNU make and GNU clisp
+ and cvs source code. */
+ int ifd[2];
+ int ofd[2];
+ int orig_stdin;
+ int orig_stdout;
+ int orig_stderr;
+ int child;
+ int nulloutfd;
+ int stdinfd;
+ int stdoutfd;
+ int saved_errno;
+
+ /* FIXME: Need to free memory allocated by prepare_spawn. */
+ prog_argv = prepare_spawn (prog_argv);
+
+ if (pipe_stdout)
+ if (pipe2_safer (ifd, O_BINARY | O_CLOEXEC) < 0)
+ error (EXIT_FAILURE, errno, _("cannot create pipe"));
+ if (pipe_stdin)
+ if (pipe2_safer (ofd, O_BINARY | O_CLOEXEC) < 0)
+ error (EXIT_FAILURE, errno, _("cannot create pipe"));
+/* Data flow diagram:
+ *
+ * write system read
+ * parent -> ofd[1] -> ofd[0] -> child if pipe_stdin
+ * parent <- ifd[0] <- ifd[1] <- child if pipe_stdout
+ * read system write
+ *
+ */
+
+ /* Save standard file handles of parent process. */
+ if (pipe_stdin || prog_stdin != NULL)
+ orig_stdin = dup_safer_noinherit (STDIN_FILENO);
+ if (pipe_stdout || prog_stdout != NULL)
+ orig_stdout = dup_safer_noinherit (STDOUT_FILENO);
+ if (null_stderr)
+ orig_stderr = dup_safer_noinherit (STDERR_FILENO);
+ child = -1;
+
+ /* Create standard file handles of child process. */
+ nulloutfd = -1;
+ stdinfd = -1;
+ stdoutfd = -1;
+ if ((!pipe_stdin || dup2 (ofd[0], STDIN_FILENO) >= 0)
+ && (!pipe_stdout || dup2 (ifd[1], STDOUT_FILENO) >= 0)
+ && (!null_stderr
+ || ((nulloutfd = open ("NUL", O_RDWR, 0)) >= 0
+ && (nulloutfd == STDERR_FILENO
+ || (dup2 (nulloutfd, STDERR_FILENO) >= 0
+ && close (nulloutfd) >= 0))))
+ && (pipe_stdin
+ || prog_stdin == NULL
+ || ((stdinfd = open (prog_stdin, O_RDONLY, 0)) >= 0
+ && (stdinfd == STDIN_FILENO
+ || (dup2 (stdinfd, STDIN_FILENO) >= 0
+ && close (stdinfd) >= 0))))
+ && (pipe_stdout
+ || prog_stdout == NULL
+ || ((stdoutfd = open (prog_stdout, O_WRONLY, 0)) >= 0
+ && (stdoutfd == STDOUT_FILENO
+ || (dup2 (stdoutfd, STDOUT_FILENO) >= 0
+ && close (stdoutfd) >= 0)))))
+ /* The child process doesn't inherit ifd[0], ifd[1], ofd[0], ofd[1],
+ but it inherits all open()ed or dup2()ed file handles (which is what
+ we want in the case of STD*_FILENO). */
+ /* Use spawnvpe and pass the environment explicitly. This is needed if
+ the program has modified the environment using putenv() or [un]setenv().
+ On Windows, programs have two environments, one in the "environment
+ block" of the process and managed through SetEnvironmentVariable(), and
+ one inside the process, in the location retrieved by the 'environ'
+ macro. When using spawnvp() without 'e', the child process inherits a
+ copy of the environment block - ignoring the effects of putenv() and
+ [un]setenv(). */
+ {
+ child = spawnvpe (P_NOWAIT, prog_path, (const char **) prog_argv,
+ (const char **) environ);
+ if (child < 0 && errno == ENOEXEC)
+ {
+ /* prog is not a native executable. Try to execute it as a
+ shell script. Note that prepare_spawn() has already prepended
+ a hidden element "sh.exe" to prog_argv. */
+ --prog_argv;
+ child = spawnvpe (P_NOWAIT, prog_argv[0], (const char **) prog_argv,
+ (const char **) environ);
+ }
+ }
+ if (child == -1)
+ saved_errno = errno;
+ if (stdinfd >= 0)
+ close (stdinfd);
+ if (stdoutfd >= 0)
+ close (stdoutfd);
+ if (nulloutfd >= 0)
+ close (nulloutfd);
+
+ /* Restore standard file handles of parent process. */
+ if (null_stderr)
+ undup_safer_noinherit (orig_stderr, STDERR_FILENO);
+ if (pipe_stdout || prog_stdout != NULL)
+ undup_safer_noinherit (orig_stdout, STDOUT_FILENO);
+ if (pipe_stdin || prog_stdin != NULL)
+ undup_safer_noinherit (orig_stdin, STDIN_FILENO);
+
+ if (pipe_stdin)
+ close (ofd[0]);
+ if (pipe_stdout)
+ close (ifd[1]);
+ if (child == -1)
+ {
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, saved_errno,
+ _("%s subprocess failed"), progname);
+ if (pipe_stdout)
+ close (ifd[0]);
+ if (pipe_stdin)
+ close (ofd[1]);
+ errno = saved_errno;
+ return -1;
+ }
+
+ if (pipe_stdout)
+ fd[0] = ifd[0];
+ if (pipe_stdin)
+ fd[1] = ofd[1];
+ return child;
+
+#else
+
+ /* Unix API. */
+ int ifd[2];
+ int ofd[2];
+ sigset_t blocked_signals;
+ posix_spawn_file_actions_t actions;
+ bool actions_allocated;
+ posix_spawnattr_t attrs;
+ bool attrs_allocated;
+ int err;
+ pid_t child;
+
+ if (pipe_stdout)
+ if (pipe_safer (ifd) < 0)
+ error (EXIT_FAILURE, errno, _("cannot create pipe"));
+ if (pipe_stdin)
+ if (pipe_safer (ofd) < 0)
+ error (EXIT_FAILURE, errno, _("cannot create pipe"));
+/* Data flow diagram:
+ *
+ * write system read
+ * parent -> ofd[1] -> ofd[0] -> child if pipe_stdin
+ * parent <- ifd[0] <- ifd[1] <- child if pipe_stdout
+ * read system write
+ *
+ */
+
+ if (slave_process)
+ {
+ sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
+ block_fatal_signals ();
+ }
+ actions_allocated = false;
+ attrs_allocated = false;
+ if ((err = posix_spawn_file_actions_init (&actions)) != 0
+ || (actions_allocated = true,
+ (pipe_stdin
+ && (err = posix_spawn_file_actions_adddup2 (&actions,
+ ofd[0], STDIN_FILENO))
+ != 0)
+ || (pipe_stdout
+ && (err = posix_spawn_file_actions_adddup2 (&actions,
+ ifd[1], STDOUT_FILENO))
+ != 0)
+ || (pipe_stdin
+ && (err = posix_spawn_file_actions_addclose (&actions, ofd[0]))
+ != 0)
+ || (pipe_stdout
+ && (err = posix_spawn_file_actions_addclose (&actions, ifd[1]))
+ != 0)
+ || (pipe_stdin
+ && (err = posix_spawn_file_actions_addclose (&actions, ofd[1]))
+ != 0)
+ || (pipe_stdout
+ && (err = posix_spawn_file_actions_addclose (&actions, ifd[0]))
+ != 0)
+ || (null_stderr
+ && (err = posix_spawn_file_actions_addopen (&actions,
+ STDERR_FILENO,
+ "/dev/null", O_RDWR,
+ 0))
+ != 0)
+ || (!pipe_stdin
+ && prog_stdin != NULL
+ && (err = posix_spawn_file_actions_addopen (&actions,
+ STDIN_FILENO,
+ prog_stdin, O_RDONLY,
+ 0))
+ != 0)
+ || (!pipe_stdout
+ && prog_stdout != NULL
+ && (err = posix_spawn_file_actions_addopen (&actions,
+ STDOUT_FILENO,
+ prog_stdout, O_WRONLY,
+ 0))
+ != 0)
+ || (slave_process
+ && ((err = posix_spawnattr_init (&attrs)) != 0
+ || (attrs_allocated = true,
+ (err = posix_spawnattr_setsigmask (&attrs,
+ &blocked_signals))
+ != 0
+ || (err = posix_spawnattr_setflags (&attrs,
+ POSIX_SPAWN_SETSIGMASK))
+ != 0)))
+ || (err = posix_spawnp (&child, prog_path, &actions,
+ attrs_allocated ? &attrs : NULL, prog_argv,
+ environ))
+ != 0))
+ {
+ if (actions_allocated)
+ posix_spawn_file_actions_destroy (&actions);
+ if (attrs_allocated)
+ posix_spawnattr_destroy (&attrs);
+ if (slave_process)
+ unblock_fatal_signals ();
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, err,
+ _("%s subprocess failed"), progname);
+ if (pipe_stdout)
+ {
+ close (ifd[0]);
+ close (ifd[1]);
+ }
+ if (pipe_stdin)
+ {
+ close (ofd[0]);
+ close (ofd[1]);
+ }
+ errno = err;
+ return -1;
+ }
+ posix_spawn_file_actions_destroy (&actions);
+ if (attrs_allocated)
+ posix_spawnattr_destroy (&attrs);
+ if (slave_process)
+ {
+ register_slave_subprocess (child);
+ unblock_fatal_signals ();
+ }
+ if (pipe_stdin)
+ close (ofd[0]);
+ if (pipe_stdout)
+ close (ifd[1]);
+
+ if (pipe_stdout)
+ fd[0] = ifd[0];
+ if (pipe_stdin)
+ fd[1] = ofd[1];
+ return child;
+
+#endif
+}
+
+/* Open a bidirectional pipe.
+ *
+ * write system read
+ * parent -> fd[1] -> STDIN_FILENO -> child
+ * parent <- fd[0] <- STDOUT_FILENO <- child
+ * read system write
+ *
+ */
+pid_t
+create_pipe_bidi (const char *progname,
+ const char *prog_path, char **prog_argv,
+ bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int fd[2])
+{
+ pid_t result = create_pipe (progname, prog_path, prog_argv,
+ true, true, NULL, NULL,
+ null_stderr, slave_process, exit_on_error,
+ fd);
+ return result;
+}
+
+/* Open a pipe for input from a child process.
+ * The child's stdin comes from a file.
+ *
+ * read system write
+ * parent <- fd[0] <- STDOUT_FILENO <- child
+ *
+ */
+pid_t
+create_pipe_in (const char *progname,
+ const char *prog_path, char **prog_argv,
+ const char *prog_stdin, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int fd[1])
+{
+ int iofd[2];
+ pid_t result = create_pipe (progname, prog_path, prog_argv,
+ false, true, prog_stdin, NULL,
+ null_stderr, slave_process, exit_on_error,
+ iofd);
+ if (result != -1)
+ fd[0] = iofd[0];
+ return result;
+}
+
+/* Open a pipe for output to a child process.
+ * The child's stdout goes to a file.
+ *
+ * write system read
+ * parent -> fd[0] -> STDIN_FILENO -> child
+ *
+ */
+pid_t
+create_pipe_out (const char *progname,
+ const char *prog_path, char **prog_argv,
+ const char *prog_stdout, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int fd[1])
+{
+ int iofd[2];
+ pid_t result = create_pipe (progname, prog_path, prog_argv,
+ true, false, NULL, prog_stdout,
+ null_stderr, slave_process, exit_on_error,
+ iofd);
+ if (result != -1)
+ fd[0] = iofd[1];
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/spawn-pipe.h b/contrib/tools/bison/gnulib/src/spawn-pipe.h
index ea8284f268..5274e9d8dd 100644
--- a/contrib/tools/bison/gnulib/src/spawn-pipe.h
+++ b/contrib/tools/bison/gnulib/src/spawn-pipe.h
@@ -1,147 +1,147 @@
-/* Creation of subprocesses, communicating via pipes.
- Copyright (C) 2001-2003, 2006, 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _SPAWN_PIPE_H
-#define _SPAWN_PIPE_H
-
-/* Get pid_t. */
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include <stdbool.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* All these functions create a subprocess and don't wait for its termination.
- They return the process id of the subprocess. They also return in fd[]
- one or two file descriptors for communication with the subprocess.
- If the subprocess creation fails: if exit_on_error is true, the main
- process exits with an error message; otherwise, an error message is given
- if null_stderr is false, then -1 is returned, with errno set, and fd[]
- remain uninitialized.
-
- After finishing communication, the caller should call wait_subprocess()
- to get rid of the subprocess in the process table.
-
- If slave_process is true, the child process will be terminated when its
- creator receives a catchable fatal signal or exits normally. If
- slave_process is false, the child process will continue running in this
- case, until it is lucky enough to attempt to communicate with its creator
- and thus get a SIGPIPE signal.
-
- If exit_on_error is false, a child process id of -1 should be treated the
- same way as a subprocess which accepts no input, produces no output and
- terminates with exit code 127. Why? Some errors during posix_spawnp()
- cause the function posix_spawnp() to return an error code; some other
- errors cause the subprocess to exit with return code 127. It is
- implementation dependent which error is reported which way. The caller
- must treat both cases as equivalent.
-
- It is recommended that no signal is blocked or ignored (i.e. have a
- signal handler with value SIG_IGN) while any of these functions is called.
- The reason is that child processes inherit the mask of blocked signals
- from their parent (both through posix_spawn() and fork()/exec());
- likewise, signals ignored in the parent are also ignored in the child
- (except possibly for SIGCHLD). And POSIX:2001 says [in the description
- of exec()]:
- "it should be noted that many existing applications wrongly
- assume that they start with certain signals set to the default
- action and/or unblocked. In particular, applications written
- with a simpler signal model that does not include blocking of
- signals, such as the one in the ISO C standard, may not behave
- properly if invoked with some signals blocked. Therefore, it is
- best not to block or ignore signals across execs without explicit
- reason to do so, and especially not to block signals across execs
- of arbitrary (not closely co-operating) programs." */
-
-/* Open a pipe for output to a child process.
- * The child's stdout goes to a file.
- *
- * write system read
- * parent -> fd[0] -> STDIN_FILENO -> child
- *
- * Note: When writing to a child process, it is useful to ignore the SIGPIPE
- * signal and the EPIPE error code.
- */
-extern pid_t create_pipe_out (const char *progname,
- const char *prog_path, char **prog_argv,
- const char *prog_stdout, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int fd[1]);
-
-/* Open a pipe for input from a child process.
- * The child's stdin comes from a file.
- *
- * read system write
- * parent <- fd[0] <- STDOUT_FILENO <- child
- *
- */
-extern pid_t create_pipe_in (const char *progname,
- const char *prog_path, char **prog_argv,
- const char *prog_stdin, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int fd[1]);
-
-/* Open a bidirectional pipe.
- *
- * write system read
- * parent -> fd[1] -> STDIN_FILENO -> child
- * parent <- fd[0] <- STDOUT_FILENO <- child
- * read system write
- *
- * Note: When writing to a child process, it is useful to ignore the SIGPIPE
- * signal and the EPIPE error code.
- *
- * Note: The parent process must be careful to avoid deadlock.
- * 1) If you write more than PIPE_MAX bytes or, more generally, if you write
- * more bytes than the subprocess can handle at once, the subprocess
- * may write its data and wait on you to read it, but you are currently
- * busy writing.
- * 2) When you don't know ahead of time how many bytes the subprocess
- * will produce, the usual technique of calling read (fd, buf, BUFSIZ)
- * with a fixed BUFSIZ will, on Linux 2.2.17 and on BSD systems, cause
- * the read() call to block until *all* of the buffer has been filled.
- * But the subprocess cannot produce more data until you gave it more
- * input. But you are currently busy reading from it.
- */
-extern pid_t create_pipe_bidi (const char *progname,
- const char *prog_path, char **prog_argv,
- bool null_stderr,
- bool slave_process, bool exit_on_error,
- int fd[2]);
-
-/* The name of the "always silent" device. */
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Native Windows API. */
-# define DEV_NULL "NUL"
-#else
-/* Unix API. */
-# define DEV_NULL "/dev/null"
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _SPAWN_PIPE_H */
+/* Creation of subprocesses, communicating via pipes.
+ Copyright (C) 2001-2003, 2006, 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _SPAWN_PIPE_H
+#define _SPAWN_PIPE_H
+
+/* Get pid_t. */
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <stdbool.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* All these functions create a subprocess and don't wait for its termination.
+ They return the process id of the subprocess. They also return in fd[]
+ one or two file descriptors for communication with the subprocess.
+ If the subprocess creation fails: if exit_on_error is true, the main
+ process exits with an error message; otherwise, an error message is given
+ if null_stderr is false, then -1 is returned, with errno set, and fd[]
+ remain uninitialized.
+
+ After finishing communication, the caller should call wait_subprocess()
+ to get rid of the subprocess in the process table.
+
+ If slave_process is true, the child process will be terminated when its
+ creator receives a catchable fatal signal or exits normally. If
+ slave_process is false, the child process will continue running in this
+ case, until it is lucky enough to attempt to communicate with its creator
+ and thus get a SIGPIPE signal.
+
+ If exit_on_error is false, a child process id of -1 should be treated the
+ same way as a subprocess which accepts no input, produces no output and
+ terminates with exit code 127. Why? Some errors during posix_spawnp()
+ cause the function posix_spawnp() to return an error code; some other
+ errors cause the subprocess to exit with return code 127. It is
+ implementation dependent which error is reported which way. The caller
+ must treat both cases as equivalent.
+
+ It is recommended that no signal is blocked or ignored (i.e. have a
+ signal handler with value SIG_IGN) while any of these functions is called.
+ The reason is that child processes inherit the mask of blocked signals
+ from their parent (both through posix_spawn() and fork()/exec());
+ likewise, signals ignored in the parent are also ignored in the child
+ (except possibly for SIGCHLD). And POSIX:2001 says [in the description
+ of exec()]:
+ "it should be noted that many existing applications wrongly
+ assume that they start with certain signals set to the default
+ action and/or unblocked. In particular, applications written
+ with a simpler signal model that does not include blocking of
+ signals, such as the one in the ISO C standard, may not behave
+ properly if invoked with some signals blocked. Therefore, it is
+ best not to block or ignore signals across execs without explicit
+ reason to do so, and especially not to block signals across execs
+ of arbitrary (not closely co-operating) programs." */
+
+/* Open a pipe for output to a child process.
+ * The child's stdout goes to a file.
+ *
+ * write system read
+ * parent -> fd[0] -> STDIN_FILENO -> child
+ *
+ * Note: When writing to a child process, it is useful to ignore the SIGPIPE
+ * signal and the EPIPE error code.
+ */
+extern pid_t create_pipe_out (const char *progname,
+ const char *prog_path, char **prog_argv,
+ const char *prog_stdout, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int fd[1]);
+
+/* Open a pipe for input from a child process.
+ * The child's stdin comes from a file.
+ *
+ * read system write
+ * parent <- fd[0] <- STDOUT_FILENO <- child
+ *
+ */
+extern pid_t create_pipe_in (const char *progname,
+ const char *prog_path, char **prog_argv,
+ const char *prog_stdin, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int fd[1]);
+
+/* Open a bidirectional pipe.
+ *
+ * write system read
+ * parent -> fd[1] -> STDIN_FILENO -> child
+ * parent <- fd[0] <- STDOUT_FILENO <- child
+ * read system write
+ *
+ * Note: When writing to a child process, it is useful to ignore the SIGPIPE
+ * signal and the EPIPE error code.
+ *
+ * Note: The parent process must be careful to avoid deadlock.
+ * 1) If you write more than PIPE_MAX bytes or, more generally, if you write
+ * more bytes than the subprocess can handle at once, the subprocess
+ * may write its data and wait on you to read it, but you are currently
+ * busy writing.
+ * 2) When you don't know ahead of time how many bytes the subprocess
+ * will produce, the usual technique of calling read (fd, buf, BUFSIZ)
+ * with a fixed BUFSIZ will, on Linux 2.2.17 and on BSD systems, cause
+ * the read() call to block until *all* of the buffer has been filled.
+ * But the subprocess cannot produce more data until you gave it more
+ * input. But you are currently busy reading from it.
+ */
+extern pid_t create_pipe_bidi (const char *progname,
+ const char *prog_path, char **prog_argv,
+ bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int fd[2]);
+
+/* The name of the "always silent" device. */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Native Windows API. */
+# define DEV_NULL "NUL"
+#else
+/* Unix API. */
+# define DEV_NULL "/dev/null"
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _SPAWN_PIPE_H */
diff --git a/contrib/tools/bison/gnulib/src/spawn_faction_addclose.c b/contrib/tools/bison/gnulib/src/spawn_faction_addclose.c
index 86a9aba2e7..962872420b 100644
--- a/contrib/tools/bison/gnulib/src/spawn_faction_addclose.c
+++ b/contrib/tools/bison/gnulib/src/spawn_faction_addclose.c
@@ -1,69 +1,69 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <errno.h>
-#include <unistd.h>
-
-#if !_LIBC
-# define __sysconf(open_max) getdtablesize ()
-#endif
-
-#if !HAVE_WORKING_POSIX_SPAWN
-# include "spawn_int.h"
-#endif
-
-/* Add an action to FILE-ACTIONS which tells the implementation to call
- 'close' for the given file descriptor during the 'spawn' call. */
-int
-posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *file_actions,
- int fd)
-#undef posix_spawn_file_actions_addclose
-{
- int maxfd = __sysconf (_SC_OPEN_MAX);
-
- /* Test for the validity of the file descriptor. */
- if (fd < 0 || fd >= maxfd)
- return EBADF;
-
-#if HAVE_WORKING_POSIX_SPAWN
- return posix_spawn_file_actions_addclose (file_actions, fd);
-#else
- /* Allocate more memory if needed. */
- if (file_actions->_used == file_actions->_allocated
- && __posix_spawn_file_actions_realloc (file_actions) != 0)
- /* This can only mean we ran out of memory. */
- return ENOMEM;
-
- {
- struct __spawn_action *rec;
-
- /* Add the new value. */
- rec = &file_actions->_actions[file_actions->_used];
- rec->tag = spawn_do_close;
- rec->action.open_action.fd = fd;
-
- /* Account for the new entry. */
- ++file_actions->_used;
-
- return 0;
- }
-#endif
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#if !_LIBC
+# define __sysconf(open_max) getdtablesize ()
+#endif
+
+#if !HAVE_WORKING_POSIX_SPAWN
+# include "spawn_int.h"
+#endif
+
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+ 'close' for the given file descriptor during the 'spawn' call. */
+int
+posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *file_actions,
+ int fd)
+#undef posix_spawn_file_actions_addclose
+{
+ int maxfd = __sysconf (_SC_OPEN_MAX);
+
+ /* Test for the validity of the file descriptor. */
+ if (fd < 0 || fd >= maxfd)
+ return EBADF;
+
+#if HAVE_WORKING_POSIX_SPAWN
+ return posix_spawn_file_actions_addclose (file_actions, fd);
+#else
+ /* Allocate more memory if needed. */
+ if (file_actions->_used == file_actions->_allocated
+ && __posix_spawn_file_actions_realloc (file_actions) != 0)
+ /* This can only mean we ran out of memory. */
+ return ENOMEM;
+
+ {
+ struct __spawn_action *rec;
+
+ /* Add the new value. */
+ rec = &file_actions->_actions[file_actions->_used];
+ rec->tag = spawn_do_close;
+ rec->action.open_action.fd = fd;
+
+ /* Account for the new entry. */
+ ++file_actions->_used;
+
+ return 0;
+ }
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/spawn_faction_adddup2.c b/contrib/tools/bison/gnulib/src/spawn_faction_adddup2.c
index 56ff1ecc18..6cd001b22a 100644
--- a/contrib/tools/bison/gnulib/src/spawn_faction_adddup2.c
+++ b/contrib/tools/bison/gnulib/src/spawn_faction_adddup2.c
@@ -1,70 +1,70 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <errno.h>
-#include <unistd.h>
-
-#if !_LIBC
-# define __sysconf(open_max) getdtablesize ()
-#endif
-
-#if !HAVE_WORKING_POSIX_SPAWN
-# include "spawn_int.h"
-#endif
-
-/* Add an action to FILE-ACTIONS which tells the implementation to call
- 'dup2' for the given file descriptors during the 'spawn' call. */
-int
-posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *file_actions,
- int fd, int newfd)
-#undef posix_spawn_file_actions_adddup2
-{
- int maxfd = __sysconf (_SC_OPEN_MAX);
-
- /* Test for the validity of the file descriptor. */
- if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd)
- return EBADF;
-
-#if HAVE_WORKING_POSIX_SPAWN
- return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd);
-#else
- /* Allocate more memory if needed. */
- if (file_actions->_used == file_actions->_allocated
- && __posix_spawn_file_actions_realloc (file_actions) != 0)
- /* This can only mean we ran out of memory. */
- return ENOMEM;
-
- {
- struct __spawn_action *rec;
-
- /* Add the new value. */
- rec = &file_actions->_actions[file_actions->_used];
- rec->tag = spawn_do_dup2;
- rec->action.dup2_action.fd = fd;
- rec->action.dup2_action.newfd = newfd;
-
- /* Account for the new entry. */
- ++file_actions->_used;
-
- return 0;
- }
-#endif
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#if !_LIBC
+# define __sysconf(open_max) getdtablesize ()
+#endif
+
+#if !HAVE_WORKING_POSIX_SPAWN
+# include "spawn_int.h"
+#endif
+
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+ 'dup2' for the given file descriptors during the 'spawn' call. */
+int
+posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *file_actions,
+ int fd, int newfd)
+#undef posix_spawn_file_actions_adddup2
+{
+ int maxfd = __sysconf (_SC_OPEN_MAX);
+
+ /* Test for the validity of the file descriptor. */
+ if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd)
+ return EBADF;
+
+#if HAVE_WORKING_POSIX_SPAWN
+ return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd);
+#else
+ /* Allocate more memory if needed. */
+ if (file_actions->_used == file_actions->_allocated
+ && __posix_spawn_file_actions_realloc (file_actions) != 0)
+ /* This can only mean we ran out of memory. */
+ return ENOMEM;
+
+ {
+ struct __spawn_action *rec;
+
+ /* Add the new value. */
+ rec = &file_actions->_actions[file_actions->_used];
+ rec->tag = spawn_do_dup2;
+ rec->action.dup2_action.fd = fd;
+ rec->action.dup2_action.newfd = newfd;
+
+ /* Account for the new entry. */
+ ++file_actions->_used;
+
+ return 0;
+ }
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/spawn_faction_addopen.c b/contrib/tools/bison/gnulib/src/spawn_faction_addopen.c
index 8aaeca6a50..ea8bf5ea9d 100644
--- a/contrib/tools/bison/gnulib/src/spawn_faction_addopen.c
+++ b/contrib/tools/bison/gnulib/src/spawn_faction_addopen.c
@@ -1,73 +1,73 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <errno.h>
-#include <unistd.h>
-
-#if !_LIBC
-# define __sysconf(open_max) getdtablesize ()
-#endif
-
-#if !HAVE_WORKING_POSIX_SPAWN
-# include "spawn_int.h"
-#endif
-
-/* Add an action to FILE-ACTIONS which tells the implementation to call
- 'open' for the given file during the 'spawn' call. */
-int
-posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
- int fd, const char *path, int oflag,
- mode_t mode)
-#undef posix_spawn_file_actions_addopen
-{
- int maxfd = __sysconf (_SC_OPEN_MAX);
-
- /* Test for the validity of the file descriptor. */
- if (fd < 0 || fd >= maxfd)
- return EBADF;
-
-#if HAVE_WORKING_POSIX_SPAWN
- return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode);
-#else
- /* Allocate more memory if needed. */
- if (file_actions->_used == file_actions->_allocated
- && __posix_spawn_file_actions_realloc (file_actions) != 0)
- /* This can only mean we ran out of memory. */
- return ENOMEM;
-
- {
- struct __spawn_action *rec;
-
- /* Add the new value. */
- rec = &file_actions->_actions[file_actions->_used];
- rec->tag = spawn_do_open;
- rec->action.open_action.fd = fd;
- rec->action.open_action.path = path;
- rec->action.open_action.oflag = oflag;
- rec->action.open_action.mode = mode;
-
- /* Account for the new entry. */
- ++file_actions->_used;
-
- return 0;
- }
-#endif
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#if !_LIBC
+# define __sysconf(open_max) getdtablesize ()
+#endif
+
+#if !HAVE_WORKING_POSIX_SPAWN
+# include "spawn_int.h"
+#endif
+
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+ 'open' for the given file during the 'spawn' call. */
+int
+posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
+ int fd, const char *path, int oflag,
+ mode_t mode)
+#undef posix_spawn_file_actions_addopen
+{
+ int maxfd = __sysconf (_SC_OPEN_MAX);
+
+ /* Test for the validity of the file descriptor. */
+ if (fd < 0 || fd >= maxfd)
+ return EBADF;
+
+#if HAVE_WORKING_POSIX_SPAWN
+ return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode);
+#else
+ /* Allocate more memory if needed. */
+ if (file_actions->_used == file_actions->_allocated
+ && __posix_spawn_file_actions_realloc (file_actions) != 0)
+ /* This can only mean we ran out of memory. */
+ return ENOMEM;
+
+ {
+ struct __spawn_action *rec;
+
+ /* Add the new value. */
+ rec = &file_actions->_actions[file_actions->_used];
+ rec->tag = spawn_do_open;
+ rec->action.open_action.fd = fd;
+ rec->action.open_action.path = path;
+ rec->action.open_action.oflag = oflag;
+ rec->action.open_action.mode = mode;
+
+ /* Account for the new entry. */
+ ++file_actions->_used;
+
+ return 0;
+ }
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/spawn_faction_destroy.c b/contrib/tools/bison/gnulib/src/spawn_faction_destroy.c
index 942733dc6b..550b691154 100644
--- a/contrib/tools/bison/gnulib/src/spawn_faction_destroy.c
+++ b/contrib/tools/bison/gnulib/src/spawn_faction_destroy.c
@@ -1,31 +1,31 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <stdlib.h>
-
-/* Initialize data structure for file attribute for 'spawn' call. */
-int
-posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions)
-{
- /* Free the memory allocated. */
- free (file_actions->_actions);
- return 0;
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <stdlib.h>
+
+/* Initialize data structure for file attribute for 'spawn' call. */
+int
+posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions)
+{
+ /* Free the memory allocated. */
+ free (file_actions->_actions);
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/spawn_faction_init.c b/contrib/tools/bison/gnulib/src/spawn_faction_init.c
index cf1d0a6adc..70c65d5e6f 100644
--- a/contrib/tools/bison/gnulib/src/spawn_faction_init.c
+++ b/contrib/tools/bison/gnulib/src/spawn_faction_init.c
@@ -1,56 +1,56 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "spawn_int.h"
-
-
-/* Function used to increase the size of the allocated array. This
- function is called from the 'add'-functions. */
-int
-__posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions)
-{
- int newalloc = file_actions->_allocated + 8;
- void *newmem = realloc (file_actions->_actions,
- newalloc * sizeof (struct __spawn_action));
-
- if (newmem == NULL)
- /* Not enough memory. */
- return ENOMEM;
-
- file_actions->_actions = (struct __spawn_action *) newmem;
- file_actions->_allocated = newalloc;
-
- return 0;
-}
-
-
-/* Initialize data structure for file attribute for 'spawn' call. */
-int
-posix_spawn_file_actions_init (posix_spawn_file_actions_t *file_actions)
-{
- /* Simply clear all the elements. */
- memset (file_actions, '\0', sizeof (*file_actions));
- return 0;
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "spawn_int.h"
+
+
+/* Function used to increase the size of the allocated array. This
+ function is called from the 'add'-functions. */
+int
+__posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *file_actions)
+{
+ int newalloc = file_actions->_allocated + 8;
+ void *newmem = realloc (file_actions->_actions,
+ newalloc * sizeof (struct __spawn_action));
+
+ if (newmem == NULL)
+ /* Not enough memory. */
+ return ENOMEM;
+
+ file_actions->_actions = (struct __spawn_action *) newmem;
+ file_actions->_allocated = newalloc;
+
+ return 0;
+}
+
+
+/* Initialize data structure for file attribute for 'spawn' call. */
+int
+posix_spawn_file_actions_init (posix_spawn_file_actions_t *file_actions)
+{
+ /* Simply clear all the elements. */
+ memset (file_actions, '\0', sizeof (*file_actions));
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/spawn_int.h b/contrib/tools/bison/gnulib/src/spawn_int.h
index f22a659fbe..4e435ee435 100644
--- a/contrib/tools/bison/gnulib/src/spawn_int.h
+++ b/contrib/tools/bison/gnulib/src/spawn_int.h
@@ -1,62 +1,62 @@
-/* Copyright (C) 2000, 2008-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <sys/types.h>
-
-/* Data structure to contain the action information. */
-struct __spawn_action
-{
- enum
- {
- spawn_do_close,
- spawn_do_dup2,
- spawn_do_open
- } tag;
-
- union
- {
- struct
- {
- int fd;
- } close_action;
- struct
- {
- int fd;
- int newfd;
- } dup2_action;
- struct
- {
- int fd;
- const char *path;
- int oflag;
- mode_t mode;
- } open_action;
- } action;
-};
-
-#if !_LIBC
-# define __posix_spawn_file_actions_realloc gl_posix_spawn_file_actions_realloc
-#endif
-extern int __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *
- file_actions);
-
-#if !_LIBC
-# define __spawni gl_posix_spawn_internal
-#endif
-extern int __spawni (pid_t *pid, const char *path,
- const posix_spawn_file_actions_t *file_actions,
- const posix_spawnattr_t *attrp, char *const argv[],
- char *const envp[], int use_path);
+/* Copyright (C) 2000, 2008-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <sys/types.h>
+
+/* Data structure to contain the action information. */
+struct __spawn_action
+{
+ enum
+ {
+ spawn_do_close,
+ spawn_do_dup2,
+ spawn_do_open
+ } tag;
+
+ union
+ {
+ struct
+ {
+ int fd;
+ } close_action;
+ struct
+ {
+ int fd;
+ int newfd;
+ } dup2_action;
+ struct
+ {
+ int fd;
+ const char *path;
+ int oflag;
+ mode_t mode;
+ } open_action;
+ } action;
+};
+
+#if !_LIBC
+# define __posix_spawn_file_actions_realloc gl_posix_spawn_file_actions_realloc
+#endif
+extern int __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *
+ file_actions);
+
+#if !_LIBC
+# define __spawni gl_posix_spawn_internal
+#endif
+extern int __spawni (pid_t *pid, const char *path,
+ const posix_spawn_file_actions_t *file_actions,
+ const posix_spawnattr_t *attrp, char *const argv[],
+ char *const envp[], int use_path);
diff --git a/contrib/tools/bison/gnulib/src/spawnattr_destroy.c b/contrib/tools/bison/gnulib/src/spawnattr_destroy.c
index ec6c7cf003..59715d1da4 100644
--- a/contrib/tools/bison/gnulib/src/spawnattr_destroy.c
+++ b/contrib/tools/bison/gnulib/src/spawnattr_destroy.c
@@ -1,28 +1,28 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-/* Initialize data structure for file attribute for 'spawn' call. */
-int
-posix_spawnattr_destroy (posix_spawnattr_t *attr)
-{
- /* Nothing to do in the moment. */
- return 0;
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+/* Initialize data structure for file attribute for 'spawn' call. */
+int
+posix_spawnattr_destroy (posix_spawnattr_t *attr)
+{
+ /* Nothing to do in the moment. */
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/spawnattr_init.c b/contrib/tools/bison/gnulib/src/spawnattr_init.c
index b050fb4ab7..d3621503c2 100644
--- a/contrib/tools/bison/gnulib/src/spawnattr_init.c
+++ b/contrib/tools/bison/gnulib/src/spawnattr_init.c
@@ -1,33 +1,33 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <string.h>
-
-/* Initialize data structure for file attribute for 'spawn' call. */
-int
-posix_spawnattr_init (posix_spawnattr_t *attr)
-{
- /* All elements have to be initialized to the default values which
- is generally zero. */
- memset (attr, '\0', sizeof (*attr));
-
- return 0;
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <string.h>
+
+/* Initialize data structure for file attribute for 'spawn' call. */
+int
+posix_spawnattr_init (posix_spawnattr_t *attr)
+{
+ /* All elements have to be initialized to the default values which
+ is generally zero. */
+ memset (attr, '\0', sizeof (*attr));
+
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/spawnattr_setflags.c b/contrib/tools/bison/gnulib/src/spawnattr_setflags.c
index babbb19593..a1f03d6f13 100644
--- a/contrib/tools/bison/gnulib/src/spawnattr_setflags.c
+++ b/contrib/tools/bison/gnulib/src/spawnattr_setflags.c
@@ -1,45 +1,45 @@
-/* Copyright (C) 2000, 2004, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <errno.h>
-#include <string.h>
-
-#define ALL_FLAGS (POSIX_SPAWN_RESETIDS \
- | POSIX_SPAWN_SETPGROUP \
- | POSIX_SPAWN_SETSIGDEF \
- | POSIX_SPAWN_SETSIGMASK \
- | POSIX_SPAWN_SETSCHEDPARAM \
- | POSIX_SPAWN_SETSCHEDULER \
- | POSIX_SPAWN_USEVFORK)
-
-/* Store flags in the attribute structure. */
-int
-posix_spawnattr_setflags (posix_spawnattr_t *attr, short int flags)
-{
- /* Check no invalid bits are set. */
- if (flags & ~ALL_FLAGS)
- return EINVAL;
-
- /* Store the flag word. */
- attr->_flags = flags;
-
- return 0;
-}
+/* Copyright (C) 2000, 2004, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <errno.h>
+#include <string.h>
+
+#define ALL_FLAGS (POSIX_SPAWN_RESETIDS \
+ | POSIX_SPAWN_SETPGROUP \
+ | POSIX_SPAWN_SETSIGDEF \
+ | POSIX_SPAWN_SETSIGMASK \
+ | POSIX_SPAWN_SETSCHEDPARAM \
+ | POSIX_SPAWN_SETSCHEDULER \
+ | POSIX_SPAWN_USEVFORK)
+
+/* Store flags in the attribute structure. */
+int
+posix_spawnattr_setflags (posix_spawnattr_t *attr, short int flags)
+{
+ /* Check no invalid bits are set. */
+ if (flags & ~ALL_FLAGS)
+ return EINVAL;
+
+ /* Store the flag word. */
+ attr->_flags = flags;
+
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/spawnattr_setsigmask.c b/contrib/tools/bison/gnulib/src/spawnattr_setsigmask.c
index 8aa6da9437..678b434a81 100644
--- a/contrib/tools/bison/gnulib/src/spawnattr_setsigmask.c
+++ b/contrib/tools/bison/gnulib/src/spawnattr_setsigmask.c
@@ -1,33 +1,33 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include <string.h>
-
-/* Set signal mask for the new process in ATTR to SIGMASK. */
-int
-posix_spawnattr_setsigmask (posix_spawnattr_t *attr,
- const sigset_t *sigmask)
-{
- /* Copy the sigset_t data to the user buffer. */
- memcpy (&attr->_ss, sigmask, sizeof (sigset_t));
-
- return 0;
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include <string.h>
+
+/* Set signal mask for the new process in ATTR to SIGMASK. */
+int
+posix_spawnattr_setsigmask (posix_spawnattr_t *attr,
+ const sigset_t *sigmask)
+{
+ /* Copy the sigset_t data to the user buffer. */
+ memcpy (&attr->_ss, sigmask, sizeof (sigset_t));
+
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/spawni.c b/contrib/tools/bison/gnulib/src/spawni.c
index e2f7b45b60..720c2bd2e8 100644
--- a/contrib/tools/bison/gnulib/src/spawni.c
+++ b/contrib/tools/bison/gnulib/src/spawni.c
@@ -1,374 +1,374 @@
-/* Guts of POSIX spawn interface. Generic POSIX.1 version.
- Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-#include "spawn_int.h"
-
+/* Guts of POSIX spawn interface. Generic POSIX.1 version.
+ Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+#include "spawn_int.h"
+
#include "palloca.h"
-#include <errno.h>
-
-#include <fcntl.h>
-#ifndef O_LARGEFILE
-# define O_LARGEFILE 0
-#endif
-
-#if _LIBC || HAVE_PATHS_H
-# include <paths.h>
-#else
-# define _PATH_BSHELL "/bin/sh"
-#endif
-
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#if _LIBC
-# include <not-cancel.h>
-#else
-# define close_not_cancel close
-# define open_not_cancel open
-#endif
-
-#if _LIBC
-# include <local-setxid.h>
-#else
-# if !HAVE_SETEUID
-# define seteuid(id) setresuid (-1, id, -1)
-# endif
-# if !HAVE_SETEGID
-# define setegid(id) setresgid (-1, id, -1)
-# endif
-# define local_seteuid(id) seteuid (id)
-# define local_setegid(id) setegid (id)
-#endif
-
-#if _LIBC
-# define alloca __alloca
-# define execve __execve
-# define dup2 __dup2
-# define fork __fork
-# define getgid __getgid
-# define getuid __getuid
-# define sched_setparam __sched_setparam
-# define sched_setscheduler __sched_setscheduler
-# define setpgid __setpgid
-# define sigaction __sigaction
-# define sigismember __sigismember
-# define sigprocmask __sigprocmask
-# define strchrnul __strchrnul
-# define vfork __vfork
-#else
-# undef internal_function
-# define internal_function /* empty */
-#endif
-
-
-/* The Unix standard contains a long explanation of the way to signal
- an error after the fork() was successful. Since no new wait status
- was wanted there is no way to signal an error using one of the
- available methods. The committee chose to signal an error by a
- normal program exit with the exit code 127. */
-#define SPAWN_ERROR 127
-
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-/* Native Windows API. */
-int
-__spawni (pid_t *pid, const char *file,
- const posix_spawn_file_actions_t *file_actions,
- const posix_spawnattr_t *attrp, char *const argv[],
- char *const envp[], int use_path)
-{
- /* Not yet implemented. */
- return ENOSYS;
-}
-
-#else
-
-
-/* The file is accessible but it is not an executable file. Invoke
- the shell to interpret it as a script. */
-static void
-internal_function
-script_execute (const char *file, char *const argv[], char *const envp[])
-{
- /* Count the arguments. */
- int argc = 0;
- while (argv[argc++])
- ;
-
- /* Construct an argument list for the shell. */
- {
- char **new_argv = (char **) alloca ((argc + 1) * sizeof (char *));
- new_argv[0] = (char *) _PATH_BSHELL;
- new_argv[1] = (char *) file;
- while (argc > 1)
- {
- new_argv[argc] = argv[argc - 1];
- --argc;
- }
-
- /* Execute the shell. */
- execve (new_argv[0], new_argv, envp);
- }
-}
-
-
-/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
- Before running the process perform the actions described in FILE-ACTIONS. */
-int
-__spawni (pid_t *pid, const char *file,
- const posix_spawn_file_actions_t *file_actions,
- const posix_spawnattr_t *attrp, char *const argv[],
- char *const envp[], int use_path)
-{
- pid_t new_pid;
- char *path, *p, *name;
- size_t len;
- size_t pathlen;
-
- /* Do this once. */
- short int flags = attrp == NULL ? 0 : attrp->_flags;
-
- /* Avoid gcc warning
- "variable 'flags' might be clobbered by 'longjmp' or 'vfork'" */
- (void) &flags;
-
- /* Generate the new process. */
-#if HAVE_VFORK
- if ((flags & POSIX_SPAWN_USEVFORK) != 0
- /* If no major work is done, allow using vfork. Note that we
- might perform the path searching. But this would be done by
- a call to execvp(), too, and such a call must be OK according
- to POSIX. */
- || ((flags & (POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF
- | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER
- | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS)) == 0
- && file_actions == NULL))
- new_pid = vfork ();
- else
-#endif
- new_pid = fork ();
-
- if (new_pid != 0)
- {
- if (new_pid < 0)
- return errno;
-
- /* The call was successful. Store the PID if necessary. */
- if (pid != NULL)
- *pid = new_pid;
-
- return 0;
- }
-
- /* Set signal mask. */
- if ((flags & POSIX_SPAWN_SETSIGMASK) != 0
- && sigprocmask (SIG_SETMASK, &attrp->_ss, NULL) != 0)
- _exit (SPAWN_ERROR);
-
- /* Set signal default action. */
- if ((flags & POSIX_SPAWN_SETSIGDEF) != 0)
- {
- /* We have to iterate over all signals. This could possibly be
- done better but it requires system specific solutions since
- the sigset_t data type can be very different on different
- architectures. */
- int sig;
- struct sigaction sa;
-
- memset (&sa, '\0', sizeof (sa));
- sa.sa_handler = SIG_DFL;
-
- for (sig = 1; sig <= NSIG; ++sig)
- if (sigismember (&attrp->_sd, sig) != 0
- && sigaction (sig, &sa, NULL) != 0)
- _exit (SPAWN_ERROR);
-
- }
-
-#if (_LIBC ? defined _POSIX_PRIORITY_SCHEDULING : HAVE_SCHED_SETPARAM && HAVE_SCHED_SETSCHEDULER)
- /* Set the scheduling algorithm and parameters. */
- if ((flags & (POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER))
- == POSIX_SPAWN_SETSCHEDPARAM)
- {
- if (sched_setparam (0, &attrp->_sp) == -1)
- _exit (SPAWN_ERROR);
- }
- else if ((flags & POSIX_SPAWN_SETSCHEDULER) != 0)
- {
- if (sched_setscheduler (0, attrp->_policy,
- (flags & POSIX_SPAWN_SETSCHEDPARAM) != 0
- ? &attrp->_sp : NULL) == -1)
- _exit (SPAWN_ERROR);
- }
-#endif
-
- /* Set the process group ID. */
- if ((flags & POSIX_SPAWN_SETPGROUP) != 0
- && setpgid (0, attrp->_pgrp) != 0)
- _exit (SPAWN_ERROR);
-
- /* Set the effective user and group IDs. */
- if ((flags & POSIX_SPAWN_RESETIDS) != 0
- && (local_seteuid (getuid ()) != 0
- || local_setegid (getgid ()) != 0))
- _exit (SPAWN_ERROR);
-
- /* Execute the file actions. */
- if (file_actions != NULL)
- {
- int cnt;
-
- for (cnt = 0; cnt < file_actions->_used; ++cnt)
- {
- struct __spawn_action *action = &file_actions->_actions[cnt];
-
- switch (action->tag)
- {
- case spawn_do_close:
- if (close_not_cancel (action->action.close_action.fd) != 0)
- /* Signal the error. */
- _exit (SPAWN_ERROR);
- break;
-
- case spawn_do_open:
- {
- int new_fd = open_not_cancel (action->action.open_action.path,
- action->action.open_action.oflag
- | O_LARGEFILE,
- action->action.open_action.mode);
-
- if (new_fd == -1)
- /* The 'open' call failed. */
- _exit (SPAWN_ERROR);
-
- /* Make sure the desired file descriptor is used. */
- if (new_fd != action->action.open_action.fd)
- {
- if (dup2 (new_fd, action->action.open_action.fd)
- != action->action.open_action.fd)
- /* The 'dup2' call failed. */
- _exit (SPAWN_ERROR);
-
- if (close_not_cancel (new_fd) != 0)
- /* The 'close' call failed. */
- _exit (SPAWN_ERROR);
- }
- }
- break;
-
- case spawn_do_dup2:
- if (dup2 (action->action.dup2_action.fd,
- action->action.dup2_action.newfd)
- != action->action.dup2_action.newfd)
- /* The 'dup2' call failed. */
- _exit (SPAWN_ERROR);
- break;
- }
- }
- }
-
- if (! use_path || strchr (file, '/') != NULL)
- {
- /* The FILE parameter is actually a path. */
- execve (file, argv, envp);
-
- if (errno == ENOEXEC)
- script_execute (file, argv, envp);
-
- /* Oh, oh. 'execve' returns. This is bad. */
- _exit (SPAWN_ERROR);
- }
-
- /* We have to search for FILE on the path. */
- path = getenv ("PATH");
- if (path == NULL)
- {
-#if HAVE_CONFSTR
- /* There is no 'PATH' in the environment.
- The default search path is the current directory
- followed by the path 'confstr' returns for '_CS_PATH'. */
- len = confstr (_CS_PATH, (char *) NULL, 0);
- path = (char *) alloca (1 + len);
- path[0] = ':';
- (void) confstr (_CS_PATH, path + 1, len);
-#else
- /* Pretend that the PATH contains only the current directory. */
- path = "";
-#endif
- }
-
- len = strlen (file) + 1;
- pathlen = strlen (path);
- name = alloca (pathlen + len + 1);
- /* Copy the file name at the top. */
- name = (char *) memcpy (name + pathlen + 1, file, len);
- /* And add the slash. */
- *--name = '/';
-
- p = path;
- do
- {
- char *startp;
-
- path = p;
- p = strchrnul (path, ':');
-
- if (p == path)
- /* Two adjacent colons, or a colon at the beginning or the end
- of 'PATH' means to search the current directory. */
- startp = name + 1;
- else
- startp = (char *) memcpy (name - (p - path), path, p - path);
-
- /* Try to execute this name. If it works, execv will not return. */
- execve (startp, argv, envp);
-
- if (errno == ENOEXEC)
- script_execute (startp, argv, envp);
-
- switch (errno)
- {
- case EACCES:
- case ENOENT:
- case ESTALE:
- case ENOTDIR:
- /* Those errors indicate the file is missing or not executable
- by us, in which case we want to just try the next path
- directory. */
- break;
-
- default:
- /* Some other error means we found an executable file, but
- something went wrong executing it; return the error to our
- caller. */
- _exit (SPAWN_ERROR);
- }
- }
- while (*p++ != '\0');
-
- /* Return with an error. */
- _exit (SPAWN_ERROR);
-}
-
-#endif
+#include <errno.h>
+
+#include <fcntl.h>
+#ifndef O_LARGEFILE
+# define O_LARGEFILE 0
+#endif
+
+#if _LIBC || HAVE_PATHS_H
+# include <paths.h>
+#else
+# define _PATH_BSHELL "/bin/sh"
+#endif
+
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#if _LIBC
+# include <not-cancel.h>
+#else
+# define close_not_cancel close
+# define open_not_cancel open
+#endif
+
+#if _LIBC
+# include <local-setxid.h>
+#else
+# if !HAVE_SETEUID
+# define seteuid(id) setresuid (-1, id, -1)
+# endif
+# if !HAVE_SETEGID
+# define setegid(id) setresgid (-1, id, -1)
+# endif
+# define local_seteuid(id) seteuid (id)
+# define local_setegid(id) setegid (id)
+#endif
+
+#if _LIBC
+# define alloca __alloca
+# define execve __execve
+# define dup2 __dup2
+# define fork __fork
+# define getgid __getgid
+# define getuid __getuid
+# define sched_setparam __sched_setparam
+# define sched_setscheduler __sched_setscheduler
+# define setpgid __setpgid
+# define sigaction __sigaction
+# define sigismember __sigismember
+# define sigprocmask __sigprocmask
+# define strchrnul __strchrnul
+# define vfork __vfork
+#else
+# undef internal_function
+# define internal_function /* empty */
+#endif
+
+
+/* The Unix standard contains a long explanation of the way to signal
+ an error after the fork() was successful. Since no new wait status
+ was wanted there is no way to signal an error using one of the
+ available methods. The committee chose to signal an error by a
+ normal program exit with the exit code 127. */
+#define SPAWN_ERROR 127
+
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Native Windows API. */
+int
+__spawni (pid_t *pid, const char *file,
+ const posix_spawn_file_actions_t *file_actions,
+ const posix_spawnattr_t *attrp, char *const argv[],
+ char *const envp[], int use_path)
+{
+ /* Not yet implemented. */
+ return ENOSYS;
+}
+
+#else
+
+
+/* The file is accessible but it is not an executable file. Invoke
+ the shell to interpret it as a script. */
+static void
+internal_function
+script_execute (const char *file, char *const argv[], char *const envp[])
+{
+ /* Count the arguments. */
+ int argc = 0;
+ while (argv[argc++])
+ ;
+
+ /* Construct an argument list for the shell. */
+ {
+ char **new_argv = (char **) alloca ((argc + 1) * sizeof (char *));
+ new_argv[0] = (char *) _PATH_BSHELL;
+ new_argv[1] = (char *) file;
+ while (argc > 1)
+ {
+ new_argv[argc] = argv[argc - 1];
+ --argc;
+ }
+
+ /* Execute the shell. */
+ execve (new_argv[0], new_argv, envp);
+ }
+}
+
+
+/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
+ Before running the process perform the actions described in FILE-ACTIONS. */
+int
+__spawni (pid_t *pid, const char *file,
+ const posix_spawn_file_actions_t *file_actions,
+ const posix_spawnattr_t *attrp, char *const argv[],
+ char *const envp[], int use_path)
+{
+ pid_t new_pid;
+ char *path, *p, *name;
+ size_t len;
+ size_t pathlen;
+
+ /* Do this once. */
+ short int flags = attrp == NULL ? 0 : attrp->_flags;
+
+ /* Avoid gcc warning
+ "variable 'flags' might be clobbered by 'longjmp' or 'vfork'" */
+ (void) &flags;
+
+ /* Generate the new process. */
+#if HAVE_VFORK
+ if ((flags & POSIX_SPAWN_USEVFORK) != 0
+ /* If no major work is done, allow using vfork. Note that we
+ might perform the path searching. But this would be done by
+ a call to execvp(), too, and such a call must be OK according
+ to POSIX. */
+ || ((flags & (POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF
+ | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER
+ | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_RESETIDS)) == 0
+ && file_actions == NULL))
+ new_pid = vfork ();
+ else
+#endif
+ new_pid = fork ();
+
+ if (new_pid != 0)
+ {
+ if (new_pid < 0)
+ return errno;
+
+ /* The call was successful. Store the PID if necessary. */
+ if (pid != NULL)
+ *pid = new_pid;
+
+ return 0;
+ }
+
+ /* Set signal mask. */
+ if ((flags & POSIX_SPAWN_SETSIGMASK) != 0
+ && sigprocmask (SIG_SETMASK, &attrp->_ss, NULL) != 0)
+ _exit (SPAWN_ERROR);
+
+ /* Set signal default action. */
+ if ((flags & POSIX_SPAWN_SETSIGDEF) != 0)
+ {
+ /* We have to iterate over all signals. This could possibly be
+ done better but it requires system specific solutions since
+ the sigset_t data type can be very different on different
+ architectures. */
+ int sig;
+ struct sigaction sa;
+
+ memset (&sa, '\0', sizeof (sa));
+ sa.sa_handler = SIG_DFL;
+
+ for (sig = 1; sig <= NSIG; ++sig)
+ if (sigismember (&attrp->_sd, sig) != 0
+ && sigaction (sig, &sa, NULL) != 0)
+ _exit (SPAWN_ERROR);
+
+ }
+
+#if (_LIBC ? defined _POSIX_PRIORITY_SCHEDULING : HAVE_SCHED_SETPARAM && HAVE_SCHED_SETSCHEDULER)
+ /* Set the scheduling algorithm and parameters. */
+ if ((flags & (POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER))
+ == POSIX_SPAWN_SETSCHEDPARAM)
+ {
+ if (sched_setparam (0, &attrp->_sp) == -1)
+ _exit (SPAWN_ERROR);
+ }
+ else if ((flags & POSIX_SPAWN_SETSCHEDULER) != 0)
+ {
+ if (sched_setscheduler (0, attrp->_policy,
+ (flags & POSIX_SPAWN_SETSCHEDPARAM) != 0
+ ? &attrp->_sp : NULL) == -1)
+ _exit (SPAWN_ERROR);
+ }
+#endif
+
+ /* Set the process group ID. */
+ if ((flags & POSIX_SPAWN_SETPGROUP) != 0
+ && setpgid (0, attrp->_pgrp) != 0)
+ _exit (SPAWN_ERROR);
+
+ /* Set the effective user and group IDs. */
+ if ((flags & POSIX_SPAWN_RESETIDS) != 0
+ && (local_seteuid (getuid ()) != 0
+ || local_setegid (getgid ()) != 0))
+ _exit (SPAWN_ERROR);
+
+ /* Execute the file actions. */
+ if (file_actions != NULL)
+ {
+ int cnt;
+
+ for (cnt = 0; cnt < file_actions->_used; ++cnt)
+ {
+ struct __spawn_action *action = &file_actions->_actions[cnt];
+
+ switch (action->tag)
+ {
+ case spawn_do_close:
+ if (close_not_cancel (action->action.close_action.fd) != 0)
+ /* Signal the error. */
+ _exit (SPAWN_ERROR);
+ break;
+
+ case spawn_do_open:
+ {
+ int new_fd = open_not_cancel (action->action.open_action.path,
+ action->action.open_action.oflag
+ | O_LARGEFILE,
+ action->action.open_action.mode);
+
+ if (new_fd == -1)
+ /* The 'open' call failed. */
+ _exit (SPAWN_ERROR);
+
+ /* Make sure the desired file descriptor is used. */
+ if (new_fd != action->action.open_action.fd)
+ {
+ if (dup2 (new_fd, action->action.open_action.fd)
+ != action->action.open_action.fd)
+ /* The 'dup2' call failed. */
+ _exit (SPAWN_ERROR);
+
+ if (close_not_cancel (new_fd) != 0)
+ /* The 'close' call failed. */
+ _exit (SPAWN_ERROR);
+ }
+ }
+ break;
+
+ case spawn_do_dup2:
+ if (dup2 (action->action.dup2_action.fd,
+ action->action.dup2_action.newfd)
+ != action->action.dup2_action.newfd)
+ /* The 'dup2' call failed. */
+ _exit (SPAWN_ERROR);
+ break;
+ }
+ }
+ }
+
+ if (! use_path || strchr (file, '/') != NULL)
+ {
+ /* The FILE parameter is actually a path. */
+ execve (file, argv, envp);
+
+ if (errno == ENOEXEC)
+ script_execute (file, argv, envp);
+
+ /* Oh, oh. 'execve' returns. This is bad. */
+ _exit (SPAWN_ERROR);
+ }
+
+ /* We have to search for FILE on the path. */
+ path = getenv ("PATH");
+ if (path == NULL)
+ {
+#if HAVE_CONFSTR
+ /* There is no 'PATH' in the environment.
+ The default search path is the current directory
+ followed by the path 'confstr' returns for '_CS_PATH'. */
+ len = confstr (_CS_PATH, (char *) NULL, 0);
+ path = (char *) alloca (1 + len);
+ path[0] = ':';
+ (void) confstr (_CS_PATH, path + 1, len);
+#else
+ /* Pretend that the PATH contains only the current directory. */
+ path = "";
+#endif
+ }
+
+ len = strlen (file) + 1;
+ pathlen = strlen (path);
+ name = alloca (pathlen + len + 1);
+ /* Copy the file name at the top. */
+ name = (char *) memcpy (name + pathlen + 1, file, len);
+ /* And add the slash. */
+ *--name = '/';
+
+ p = path;
+ do
+ {
+ char *startp;
+
+ path = p;
+ p = strchrnul (path, ':');
+
+ if (p == path)
+ /* Two adjacent colons, or a colon at the beginning or the end
+ of 'PATH' means to search the current directory. */
+ startp = name + 1;
+ else
+ startp = (char *) memcpy (name - (p - path), path, p - path);
+
+ /* Try to execute this name. If it works, execv will not return. */
+ execve (startp, argv, envp);
+
+ if (errno == ENOEXEC)
+ script_execute (startp, argv, envp);
+
+ switch (errno)
+ {
+ case EACCES:
+ case ENOENT:
+ case ESTALE:
+ case ENOTDIR:
+ /* Those errors indicate the file is missing or not executable
+ by us, in which case we want to just try the next path
+ directory. */
+ break;
+
+ default:
+ /* Some other error means we found an executable file, but
+ something went wrong executing it; return the error to our
+ caller. */
+ _exit (SPAWN_ERROR);
+ }
+ }
+ while (*p++ != '\0');
+
+ /* Return with an error. */
+ _exit (SPAWN_ERROR);
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/spawnp.c b/contrib/tools/bison/gnulib/src/spawnp.c
index 8bc5f99aca..504403c765 100644
--- a/contrib/tools/bison/gnulib/src/spawnp.c
+++ b/contrib/tools/bison/gnulib/src/spawnp.c
@@ -1,33 +1,33 @@
-/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <spawn.h>
-
-#include "spawn_int.h"
-
-/* Spawn a new process executing FILE with the attributes describes in *ATTRP.
- Before running the process perform the actions described in FILE-ACTIONS. */
-int
-posix_spawnp (pid_t *pid, const char *file,
- const posix_spawn_file_actions_t *file_actions,
- const posix_spawnattr_t *attrp, char *const argv[],
- char *const envp[])
-{
- return __spawni (pid, file, file_actions, attrp, argv, envp, 1);
-}
+/* Copyright (C) 2000, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <spawn.h>
+
+#include "spawn_int.h"
+
+/* Spawn a new process executing FILE with the attributes describes in *ATTRP.
+ Before running the process perform the actions described in FILE-ACTIONS. */
+int
+posix_spawnp (pid_t *pid, const char *file,
+ const posix_spawn_file_actions_t *file_actions,
+ const posix_spawnattr_t *attrp, char *const argv[],
+ char *const envp[])
+{
+ return __spawni (pid, file, file_actions, attrp, argv, envp, 1);
+}
diff --git a/contrib/tools/bison/gnulib/src/sprintf.c b/contrib/tools/bison/gnulib/src/sprintf.c
index 9f24cd7f7a..580c058310 100644
--- a/contrib/tools/bison/gnulib/src/sprintf.c
+++ b/contrib/tools/bison/gnulib/src/sprintf.c
@@ -1,80 +1,80 @@
-/* Formatted output to strings.
- Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if 1
-# include <config.h>
-#endif
-
-/* Specification. */
-#include <stdio.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#include "vasnprintf.h"
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-/* Print formatted output to string STR.
- Return string length of formatted string. On error, return a negative
- value. */
-int
-sprintf (char *str, const char *format, ...)
-{
- char *output;
- size_t len;
- size_t lenbuf;
- va_list args;
-
- /* vasnprintf fails with EOVERFLOW when the buffer size argument is larger
- than INT_MAX (if that fits into a 'size_t' at all).
- Also note that glibc's iconv fails with E2BIG when we pass a length that
- is so large that str + lenbuf wraps around, i.e.
- (uintptr_t) (str + lenbuf) < (uintptr_t) str.
- Therefore set lenbuf = min (SIZE_MAX, INT_MAX, - (uintptr_t) str - 1). */
- lenbuf = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX);
- if (lenbuf > ~ (uintptr_t) str)
- lenbuf = ~ (uintptr_t) str;
-
- va_start (args, format);
- output = vasnprintf (str, &lenbuf, format, args);
- len = lenbuf;
- va_end (args);
-
- if (!output)
- return -1;
-
- if (output != str)
- {
- /* len is near SIZE_MAX. */
- free (output);
- errno = EOVERFLOW;
- return -1;
- }
-
- if (len > INT_MAX)
- {
- errno = EOVERFLOW;
- return -1;
- }
-
- return len;
-}
+/* Formatted output to strings.
+ Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if 1
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "vasnprintf.h"
+
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+
+/* Print formatted output to string STR.
+ Return string length of formatted string. On error, return a negative
+ value. */
+int
+sprintf (char *str, const char *format, ...)
+{
+ char *output;
+ size_t len;
+ size_t lenbuf;
+ va_list args;
+
+ /* vasnprintf fails with EOVERFLOW when the buffer size argument is larger
+ than INT_MAX (if that fits into a 'size_t' at all).
+ Also note that glibc's iconv fails with E2BIG when we pass a length that
+ is so large that str + lenbuf wraps around, i.e.
+ (uintptr_t) (str + lenbuf) < (uintptr_t) str.
+ Therefore set lenbuf = min (SIZE_MAX, INT_MAX, - (uintptr_t) str - 1). */
+ lenbuf = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX);
+ if (lenbuf > ~ (uintptr_t) str)
+ lenbuf = ~ (uintptr_t) str;
+
+ va_start (args, format);
+ output = vasnprintf (str, &lenbuf, format, args);
+ len = lenbuf;
+ va_end (args);
+
+ if (!output)
+ return -1;
+
+ if (output != str)
+ {
+ /* len is near SIZE_MAX. */
+ free (output);
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ if (len > INT_MAX)
+ {
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ return len;
+}
diff --git a/contrib/tools/bison/gnulib/src/stat.c b/contrib/tools/bison/gnulib/src/stat.c
index f888130d26..d282567412 100644
--- a/contrib/tools/bison/gnulib/src/stat.c
+++ b/contrib/tools/bison/gnulib/src/stat.c
@@ -1,138 +1,138 @@
-/* Work around platform bugs in stat.
- Copyright (C) 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* written by Eric Blake */
-
-/* If the user's config.h happens to include <sys/stat.h>, let it include only
- the system's <sys/stat.h> here, so that orig_stat doesn't recurse to
- rpl_stat. */
-#define __need_system_sys_stat_h
-#include <config.h>
-
-/* Get the original definition of stat. It might be defined as a macro. */
-#include <sys/types.h>
-#include <sys/stat.h>
-#undef __need_system_sys_stat_h
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-# if _GL_WINDOWS_64_BIT_ST_SIZE
-# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
-# define stat _stati64
-# define REPLACE_FUNC_STAT_DIR 1
-# undef REPLACE_FUNC_STAT_FILE
-# elif REPLACE_FUNC_STAT_FILE
-/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a.
- Bypass it. */
-# define stat _stat
-# define REPLACE_FUNC_STAT_DIR 1
-# undef REPLACE_FUNC_STAT_FILE
-# endif
-#endif
-
-static int
-orig_stat (const char *filename, struct stat *buf)
-{
- return stat (filename, buf);
-}
-
-/* Specification. */
-/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
- eliminates this include because of the preliminary #include <sys/stat.h>
- above. */
-#include "sys/stat.h"
-
-#include <errno.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <string.h>
-#include "dosname.h"
-#include "verify.h"
-
-#if REPLACE_FUNC_STAT_DIR
-# include "pathmax.h"
- /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
- have a constant PATH_MAX. */
-# ifndef PATH_MAX
-# error "Please port this replacement to your platform"
-# endif
-#endif
-
-/* Store information about NAME into ST. Work around bugs with
- trailing slashes. Mingw has other bugs (such as st_ino always
- being 0 on success) which this wrapper does not work around. But
- at least this implementation provides the ability to emulate fchdir
- correctly. */
-
-int
-rpl_stat (char const *name, struct stat *st)
-{
- int result = orig_stat (name, st);
-#if REPLACE_FUNC_STAT_FILE
- /* Solaris 9 mistakenly succeeds when given a non-directory with a
- trailing slash. */
- if (result == 0 && !S_ISDIR (st->st_mode))
- {
- size_t len = strlen (name);
- if (ISSLASH (name[len - 1]))
- {
- errno = ENOTDIR;
- return -1;
- }
- }
-#endif /* REPLACE_FUNC_STAT_FILE */
-#if REPLACE_FUNC_STAT_DIR
-
- if (result == -1 && errno == ENOENT)
- {
- /* Due to mingw's oddities, there are some directories (like
- c:\) where stat() only succeeds with a trailing slash, and
- other directories (like c:\windows) where stat() only
- succeeds without a trailing slash. But we want the two to be
- synonymous, since chdir() manages either style. Likewise, Mingw also
- reports ENOENT for names longer than PATH_MAX, when we want
- ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
- Fortunately, mingw PATH_MAX is small enough for stack
- allocation. */
- char fixed_name[PATH_MAX + 1] = {0};
- size_t len = strlen (name);
- bool check_dir = false;
- verify (PATH_MAX <= 4096);
- if (PATH_MAX <= len)
- errno = ENAMETOOLONG;
- else if (len)
- {
- strcpy (fixed_name, name);
- if (ISSLASH (fixed_name[len - 1]))
- {
- check_dir = true;
- while (len && ISSLASH (fixed_name[len - 1]))
- fixed_name[--len] = '\0';
- if (!len)
- fixed_name[0] = '/';
- }
- else
- fixed_name[len++] = '/';
- result = orig_stat (fixed_name, st);
- if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
- {
- result = -1;
- errno = ENOTDIR;
- }
- }
- }
-#endif /* REPLACE_FUNC_STAT_DIR */
- return result;
-}
+/* Work around platform bugs in stat.
+ Copyright (C) 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* written by Eric Blake */
+
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
+ the system's <sys/stat.h> here, so that orig_stat doesn't recurse to
+ rpl_stat. */
+#define __need_system_sys_stat_h
+#include <config.h>
+
+/* Get the original definition of stat. It might be defined as a macro. */
+#include <sys/types.h>
+#include <sys/stat.h>
+#undef __need_system_sys_stat_h
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# if _GL_WINDOWS_64_BIT_ST_SIZE
+# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
+# define stat _stati64
+# define REPLACE_FUNC_STAT_DIR 1
+# undef REPLACE_FUNC_STAT_FILE
+# elif REPLACE_FUNC_STAT_FILE
+/* mingw64 has a broken stat() function, based on _stat(), in libmingwex.a.
+ Bypass it. */
+# define stat _stat
+# define REPLACE_FUNC_STAT_DIR 1
+# undef REPLACE_FUNC_STAT_FILE
+# endif
+#endif
+
+static int
+orig_stat (const char *filename, struct stat *buf)
+{
+ return stat (filename, buf);
+}
+
+/* Specification. */
+/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
+ eliminates this include because of the preliminary #include <sys/stat.h>
+ above. */
+#include "sys/stat.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <string.h>
+#include "dosname.h"
+#include "verify.h"
+
+#if REPLACE_FUNC_STAT_DIR
+# include "pathmax.h"
+ /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
+ have a constant PATH_MAX. */
+# ifndef PATH_MAX
+# error "Please port this replacement to your platform"
+# endif
+#endif
+
+/* Store information about NAME into ST. Work around bugs with
+ trailing slashes. Mingw has other bugs (such as st_ino always
+ being 0 on success) which this wrapper does not work around. But
+ at least this implementation provides the ability to emulate fchdir
+ correctly. */
+
+int
+rpl_stat (char const *name, struct stat *st)
+{
+ int result = orig_stat (name, st);
+#if REPLACE_FUNC_STAT_FILE
+ /* Solaris 9 mistakenly succeeds when given a non-directory with a
+ trailing slash. */
+ if (result == 0 && !S_ISDIR (st->st_mode))
+ {
+ size_t len = strlen (name);
+ if (ISSLASH (name[len - 1]))
+ {
+ errno = ENOTDIR;
+ return -1;
+ }
+ }
+#endif /* REPLACE_FUNC_STAT_FILE */
+#if REPLACE_FUNC_STAT_DIR
+
+ if (result == -1 && errno == ENOENT)
+ {
+ /* Due to mingw's oddities, there are some directories (like
+ c:\) where stat() only succeeds with a trailing slash, and
+ other directories (like c:\windows) where stat() only
+ succeeds without a trailing slash. But we want the two to be
+ synonymous, since chdir() manages either style. Likewise, Mingw also
+ reports ENOENT for names longer than PATH_MAX, when we want
+ ENAMETOOLONG, and for stat("file/"), when we want ENOTDIR.
+ Fortunately, mingw PATH_MAX is small enough for stack
+ allocation. */
+ char fixed_name[PATH_MAX + 1] = {0};
+ size_t len = strlen (name);
+ bool check_dir = false;
+ verify (PATH_MAX <= 4096);
+ if (PATH_MAX <= len)
+ errno = ENAMETOOLONG;
+ else if (len)
+ {
+ strcpy (fixed_name, name);
+ if (ISSLASH (fixed_name[len - 1]))
+ {
+ check_dir = true;
+ while (len && ISSLASH (fixed_name[len - 1]))
+ fixed_name[--len] = '\0';
+ if (!len)
+ fixed_name[0] = '/';
+ }
+ else
+ fixed_name[len++] = '/';
+ result = orig_stat (fixed_name, st);
+ if (result == 0 && check_dir && !S_ISDIR (st->st_mode))
+ {
+ result = -1;
+ errno = ENOTDIR;
+ }
+ }
+ }
+#endif /* REPLACE_FUNC_STAT_DIR */
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/stdio--.h b/contrib/tools/bison/gnulib/src/stdio--.h
index 5d9b19b50a..244b2f5bf3 100644
--- a/contrib/tools/bison/gnulib/src/stdio--.h
+++ b/contrib/tools/bison/gnulib/src/stdio--.h
@@ -1,48 +1,48 @@
-/* Like stdio.h, but redefine some names to avoid glitches.
-
- Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <stdio.h>
+/* Like stdio.h, but redefine some names to avoid glitches.
+
+ Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <stdio.h>
#include <unistd.h>
-#include "stdio-safer.h"
-
+#include "stdio-safer.h"
+
#if defined(_WIN32)
int fpurge(FILE *stream);
int fseeko(FILE *stream, off_t offset, int whence);
off_t ftello(FILE *stream);
#endif
-#if GNULIB_FOPEN_SAFER
-# undef fopen
-# define fopen fopen_safer
-#endif
-
-#if GNULIB_FREOPEN_SAFER
-# undef freopen
-# define freopen freopen_safer
-#endif
-
-#if GNULIB_TMPFILE_SAFER
-# undef tmpfile
-# define tmpfile tmpfile_safer
-#endif
-
-#if GNULIB_POPEN_SAFER
-# undef popen
-# define popen popen_safer
-#endif
+#if GNULIB_FOPEN_SAFER
+# undef fopen
+# define fopen fopen_safer
+#endif
+
+#if GNULIB_FREOPEN_SAFER
+# undef freopen
+# define freopen freopen_safer
+#endif
+
+#if GNULIB_TMPFILE_SAFER
+# undef tmpfile
+# define tmpfile tmpfile_safer
+#endif
+
+#if GNULIB_POPEN_SAFER
+# undef popen
+# define popen popen_safer
+#endif
diff --git a/contrib/tools/bison/gnulib/src/stdio-impl.h b/contrib/tools/bison/gnulib/src/stdio-impl.h
index 45291cf3ba..0e282293ca 100644
--- a/contrib/tools/bison/gnulib/src/stdio-impl.h
+++ b/contrib/tools/bison/gnulib/src/stdio-impl.h
@@ -1,112 +1,112 @@
-/* Implementation details of FILE streams.
- Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Many stdio implementations have the same logic and therefore can share
- the same implementation of stdio extension API, except that some fields
- have different naming conventions, or their access requires some casts. */
-
-
-/* BSD stdio derived implementations. */
-
-#if defined __NetBSD__ /* NetBSD */
-/* Get __NetBSD_Version__. */
-# include <sys/param.h>
-#endif
-
-#include <errno.h> /* For detecting Plan9. */
-
-#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
-
-# if defined __DragonFly__ /* DragonFly */
- /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
-# define fp_ ((struct { struct __FILE_public pub; \
- struct { unsigned char *_base; int _size; } _bf; \
- void *cookie; \
- void *_close; \
- void *_read; \
- void *_seek; \
- void *_write; \
- struct { unsigned char *_base; int _size; } _ub; \
- int _ur; \
- unsigned char _ubuf[3]; \
- unsigned char _nbuf[1]; \
- struct { unsigned char *_base; int _size; } _lb; \
- int _blksize; \
- fpos_t _offset; \
- /* More fields, not relevant here. */ \
- } *) fp)
- /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
-# define _p pub._p
-# define _flags pub._flags
-# define _r pub._r
-# define _w pub._w
-# else
-# define fp_ fp
-# endif
-
-# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Android */
- /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
- and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
- struct __sfileext
- {
- struct __sbuf _ub; /* ungetc buffer */
- /* More fields, not relevant here. */
- };
-# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
-# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
-# define fp_ub fp_->_ub
-# endif
-
-# define HASUB(fp) (fp_ub._base != NULL)
-
-#endif
-
-
-/* SystemV derived implementations. */
-
-#ifdef __TANDEM /* NonStop Kernel */
-# ifndef _IOERR
-/* These values were determined by the program 'stdioext-flags' at
- <http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
-# define _IOERR 0x40
-# define _IOREAD 0x80
-# define _IOWRT 0x4
-# define _IORW 0x100
-# endif
-#endif
-
-#if defined _IOERR
-
-# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
-# define fp_ ((struct { unsigned char *_ptr; \
- unsigned char *_base; \
- unsigned char *_end; \
- long _cnt; \
- int _file; \
- unsigned int _flag; \
- } *) fp)
-# else
-# define fp_ fp
-# endif
-
-# if defined _SCO_DS /* OpenServer */
-# define _cnt __cnt
-# define _ptr __ptr
-# define _base __base
-# define _flag __flag
-# endif
-
-#endif
+/* Implementation details of FILE streams.
+ Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Many stdio implementations have the same logic and therefore can share
+ the same implementation of stdio extension API, except that some fields
+ have different naming conventions, or their access requires some casts. */
+
+
+/* BSD stdio derived implementations. */
+
+#if defined __NetBSD__ /* NetBSD */
+/* Get __NetBSD_Version__. */
+# include <sys/param.h>
+#endif
+
+#include <errno.h> /* For detecting Plan9. */
+
+#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
+
+# if defined __DragonFly__ /* DragonFly */
+ /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
+# define fp_ ((struct { struct __FILE_public pub; \
+ struct { unsigned char *_base; int _size; } _bf; \
+ void *cookie; \
+ void *_close; \
+ void *_read; \
+ void *_seek; \
+ void *_write; \
+ struct { unsigned char *_base; int _size; } _ub; \
+ int _ur; \
+ unsigned char _ubuf[3]; \
+ unsigned char _nbuf[1]; \
+ struct { unsigned char *_base; int _size; } _lb; \
+ int _blksize; \
+ fpos_t _offset; \
+ /* More fields, not relevant here. */ \
+ } *) fp)
+ /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
+# define _p pub._p
+# define _flags pub._flags
+# define _r pub._r
+# define _w pub._w
+# else
+# define fp_ fp
+# endif
+
+# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Android */
+ /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
+ and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
+ struct __sfileext
+ {
+ struct __sbuf _ub; /* ungetc buffer */
+ /* More fields, not relevant here. */
+ };
+# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
+# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
+# define fp_ub fp_->_ub
+# endif
+
+# define HASUB(fp) (fp_ub._base != NULL)
+
+#endif
+
+
+/* SystemV derived implementations. */
+
+#ifdef __TANDEM /* NonStop Kernel */
+# ifndef _IOERR
+/* These values were determined by the program 'stdioext-flags' at
+ <http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
+# define _IOERR 0x40
+# define _IOREAD 0x80
+# define _IOWRT 0x4
+# define _IORW 0x100
+# endif
+#endif
+
+#if defined _IOERR
+
+# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
+# define fp_ ((struct { unsigned char *_ptr; \
+ unsigned char *_base; \
+ unsigned char *_end; \
+ long _cnt; \
+ int _file; \
+ unsigned int _flag; \
+ } *) fp)
+# else
+# define fp_ fp
+# endif
+
+# if defined _SCO_DS /* OpenServer */
+# define _cnt __cnt
+# define _ptr __ptr
+# define _base __base
+# define _flag __flag
+# endif
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/stdio-safer.h b/contrib/tools/bison/gnulib/src/stdio-safer.h
index 7b67ae059d..0b2af90750 100644
--- a/contrib/tools/bison/gnulib/src/stdio-safer.h
+++ b/contrib/tools/bison/gnulib/src/stdio-safer.h
@@ -1,36 +1,36 @@
-/* Invoke stdio functions, but avoid some glitches.
-
- Copyright (C) 2001, 2003, 2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <stdio.h>
-
-#if GNULIB_FOPEN_SAFER
-FILE *fopen_safer (char const *, char const *);
-#endif
-
-#if GNULIB_FREOPEN_SAFER
-FILE *freopen_safer (char const *, char const *, FILE *);
-#endif
-
-#if GNULIB_POPEN_SAFER
-FILE *popen_safer (char const *, char const *);
-#endif
-
-#if GNULIB_TMPFILE_SAFER
-FILE *tmpfile_safer (void);
-#endif
+/* Invoke stdio functions, but avoid some glitches.
+
+ Copyright (C) 2001, 2003, 2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <stdio.h>
+
+#if GNULIB_FOPEN_SAFER
+FILE *fopen_safer (char const *, char const *);
+#endif
+
+#if GNULIB_FREOPEN_SAFER
+FILE *freopen_safer (char const *, char const *, FILE *);
+#endif
+
+#if GNULIB_POPEN_SAFER
+FILE *popen_safer (char const *, char const *);
+#endif
+
+#if GNULIB_TMPFILE_SAFER
+FILE *tmpfile_safer (void);
+#endif
diff --git a/contrib/tools/bison/gnulib/src/stdio-write.c b/contrib/tools/bison/gnulib/src/stdio-write.c
index 68d54ce93e..08cb5e620a 100644
--- a/contrib/tools/bison/gnulib/src/stdio-write.c
+++ b/contrib/tools/bison/gnulib/src/stdio-write.c
@@ -1,198 +1,198 @@
-/* POSIX compatible FILE stream write function.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2008.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <stdio.h>
-
-/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
- requested. */
-#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
-
-/* On native Windows platforms, SIGPIPE does not exist. When write() is
- called on a pipe with no readers, WriteFile() fails with error
- GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
- error EINVAL. This write() function is at the basis of the function
- which flushes the buffer of a FILE stream. */
-
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-
-# include <errno.h>
-# include <signal.h>
-# include <io.h>
-
-# define WIN32_LEAN_AND_MEAN /* avoid including junk */
-# include <windows.h>
-
-# include "msvc-nothrow.h"
-
-# if GNULIB_NONBLOCKING
-# define CLEAR_ERRNO \
- errno = 0;
-# define HANDLE_ENOSPC \
- if (errno == ENOSPC && ferror (stream)) \
- { \
- int fd = fileno (stream); \
- if (fd >= 0) \
- { \
- HANDLE h = (HANDLE) _get_osfhandle (fd); \
- if (GetFileType (h) == FILE_TYPE_PIPE) \
- { \
- /* h is a pipe or socket. */ \
- DWORD state; \
- if (GetNamedPipeHandleState (h, &state, NULL, NULL, \
- NULL, NULL, 0) \
- && (state & PIPE_NOWAIT) != 0) \
- /* h is a pipe in non-blocking mode. \
- Change errno from ENOSPC to EAGAIN. */ \
- errno = EAGAIN; \
- } \
- } \
- } \
- else
-# else
-# define CLEAR_ERRNO
-# define HANDLE_ENOSPC
-# endif
-
-# if GNULIB_SIGPIPE
-# define CLEAR_LastError \
- SetLastError (0);
-# define HANDLE_ERROR_NO_DATA \
- if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \
- { \
- int fd = fileno (stream); \
- if (fd >= 0 \
- && GetFileType ((HANDLE) _get_osfhandle (fd)) \
- == FILE_TYPE_PIPE) \
- { \
- /* Try to raise signal SIGPIPE. */ \
- raise (SIGPIPE); \
- /* If it is currently blocked or ignored, change errno from \
- EINVAL to EPIPE. */ \
- errno = EPIPE; \
- } \
- } \
- else
-# else
-# define CLEAR_LastError
-# define HANDLE_ERROR_NO_DATA
-# endif
-
-# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
- if (ferror (stream)) \
- return (EXPRESSION); \
- else \
- { \
- RETTYPE ret; \
- CLEAR_ERRNO \
- CLEAR_LastError \
- ret = (EXPRESSION); \
- if (FAILED) \
- { \
- HANDLE_ENOSPC \
- HANDLE_ERROR_NO_DATA \
- ; \
- } \
- return ret; \
- }
-
-# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
-int
-printf (const char *format, ...)
-{
- int retval;
- va_list args;
-
- va_start (args, format);
- retval = vfprintf (stdout, format, args);
- va_end (args);
-
- return retval;
-}
-# endif
-
-# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
-int
-fprintf (FILE *stream, const char *format, ...)
-{
- int retval;
- va_list args;
-
- va_start (args, format);
- retval = vfprintf (stream, format, args);
- va_end (args);
-
- return retval;
-}
-# endif
-
-# if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
-int
-vprintf (const char *format, va_list args)
-{
- return vfprintf (stdout, format, args);
-}
-# endif
-
-# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
-int
-vfprintf (FILE *stream, const char *format, va_list args)
-#undef vfprintf
-{
- CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
-}
-# endif
-
-int
-putchar (int c)
-{
- return fputc (c, stdout);
-}
-
-int
-fputc (int c, FILE *stream)
-#undef fputc
-{
- CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
-}
-
-int
-fputs (const char *string, FILE *stream)
-#undef fputs
-{
- CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
-}
-
-int
-puts (const char *string)
-#undef puts
-{
- FILE *stream = stdout;
- CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
-}
-
-size_t
-fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
-#undef fwrite
-{
- CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
-}
-
-# endif
-#endif
+/* POSIX compatible FILE stream write function.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+/* Replace these functions only if module 'nonblocking' or module 'sigpipe' is
+ requested. */
+#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE
+
+/* On native Windows platforms, SIGPIPE does not exist. When write() is
+ called on a pipe with no readers, WriteFile() fails with error
+ GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
+ error EINVAL. This write() function is at the basis of the function
+ which flushes the buffer of a FILE stream. */
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+# include <errno.h>
+# include <signal.h>
+# include <io.h>
+
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+
+# include "msvc-nothrow.h"
+
+# if GNULIB_NONBLOCKING
+# define CLEAR_ERRNO \
+ errno = 0;
+# define HANDLE_ENOSPC \
+ if (errno == ENOSPC && ferror (stream)) \
+ { \
+ int fd = fileno (stream); \
+ if (fd >= 0) \
+ { \
+ HANDLE h = (HANDLE) _get_osfhandle (fd); \
+ if (GetFileType (h) == FILE_TYPE_PIPE) \
+ { \
+ /* h is a pipe or socket. */ \
+ DWORD state; \
+ if (GetNamedPipeHandleState (h, &state, NULL, NULL, \
+ NULL, NULL, 0) \
+ && (state & PIPE_NOWAIT) != 0) \
+ /* h is a pipe in non-blocking mode. \
+ Change errno from ENOSPC to EAGAIN. */ \
+ errno = EAGAIN; \
+ } \
+ } \
+ } \
+ else
+# else
+# define CLEAR_ERRNO
+# define HANDLE_ENOSPC
+# endif
+
+# if GNULIB_SIGPIPE
+# define CLEAR_LastError \
+ SetLastError (0);
+# define HANDLE_ERROR_NO_DATA \
+ if (GetLastError () == ERROR_NO_DATA && ferror (stream)) \
+ { \
+ int fd = fileno (stream); \
+ if (fd >= 0 \
+ && GetFileType ((HANDLE) _get_osfhandle (fd)) \
+ == FILE_TYPE_PIPE) \
+ { \
+ /* Try to raise signal SIGPIPE. */ \
+ raise (SIGPIPE); \
+ /* If it is currently blocked or ignored, change errno from \
+ EINVAL to EPIPE. */ \
+ errno = EPIPE; \
+ } \
+ } \
+ else
+# else
+# define CLEAR_LastError
+# define HANDLE_ERROR_NO_DATA
+# endif
+
+# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
+ if (ferror (stream)) \
+ return (EXPRESSION); \
+ else \
+ { \
+ RETTYPE ret; \
+ CLEAR_ERRNO \
+ CLEAR_LastError \
+ ret = (EXPRESSION); \
+ if (FAILED) \
+ { \
+ HANDLE_ENOSPC \
+ HANDLE_ERROR_NO_DATA \
+ ; \
+ } \
+ return ret; \
+ }
+
+# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
+int
+printf (const char *format, ...)
+{
+ int retval;
+ va_list args;
+
+ va_start (args, format);
+ retval = vfprintf (stdout, format, args);
+ va_end (args);
+
+ return retval;
+}
+# endif
+
+# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
+int
+fprintf (FILE *stream, const char *format, ...)
+{
+ int retval;
+ va_list args;
+
+ va_start (args, format);
+ retval = vfprintf (stream, format, args);
+ va_end (args);
+
+ return retval;
+}
+# endif
+
+# if !REPLACE_VPRINTF_POSIX /* avoid collision with vprintf.c */
+int
+vprintf (const char *format, va_list args)
+{
+ return vfprintf (stdout, format, args);
+}
+# endif
+
+# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vfprintf.c */
+int
+vfprintf (FILE *stream, const char *format, va_list args)
+#undef vfprintf
+{
+ CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
+}
+# endif
+
+int
+putchar (int c)
+{
+ return fputc (c, stdout);
+}
+
+int
+fputc (int c, FILE *stream)
+#undef fputc
+{
+ CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
+}
+
+int
+fputs (const char *string, FILE *stream)
+#undef fputs
+{
+ CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
+}
+
+int
+puts (const char *string)
+#undef puts
+{
+ FILE *stream = stdout;
+ CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
+}
+
+size_t
+fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
+#undef fwrite
+{
+ CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
+}
+
+# endif
+#endif
diff --git a/contrib/tools/bison/gnulib/src/stdlib--.h b/contrib/tools/bison/gnulib/src/stdlib--.h
index 28360a2707..b6bc796e0b 100644
--- a/contrib/tools/bison/gnulib/src/stdlib--.h
+++ b/contrib/tools/bison/gnulib/src/stdlib--.h
@@ -1,42 +1,42 @@
-/* Like stdlib.h, but redefine some names to avoid glitches.
-
- Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <stdlib.h>
-#include "stdlib-safer.h"
-
+/* Like stdlib.h, but redefine some names to avoid glitches.
+
+ Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <stdlib.h>
+#include "stdlib-safer.h"
+
#if defined(_WIN32)
char *mkdtemp(char *template);
int mkstemp(char*);
char *secure_getenv(const char *name);
#endif
-#undef mkstemp
-#define mkstemp mkstemp_safer
-
-#if GNULIB_MKOSTEMP
-# define mkostemp mkostemp_safer
-#endif
-
-#if GNULIB_MKOSTEMPS
-# define mkostemps mkostemps_safer
-#endif
-
-#if GNULIB_MKSTEMPS
-# define mkstemps mkstemps_safer
-#endif
+#undef mkstemp
+#define mkstemp mkstemp_safer
+
+#if GNULIB_MKOSTEMP
+# define mkostemp mkostemp_safer
+#endif
+
+#if GNULIB_MKOSTEMPS
+# define mkostemps mkostemps_safer
+#endif
+
+#if GNULIB_MKSTEMPS
+# define mkstemps mkstemps_safer
+#endif
diff --git a/contrib/tools/bison/gnulib/src/stdlib-safer.h b/contrib/tools/bison/gnulib/src/stdlib-safer.h
index 1e3149370e..8f359f0e1d 100644
--- a/contrib/tools/bison/gnulib/src/stdlib-safer.h
+++ b/contrib/tools/bison/gnulib/src/stdlib-safer.h
@@ -1,32 +1,32 @@
-/* Invoke stdlib.h functions, but avoid some glitches.
-
- Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-int mkstemp_safer (char *);
-
-#if GNULIB_MKOSTEMP
-int mkostemp_safer (char *, int);
-#endif
-
-#if GNULIB_MKOSTEMPS
-int mkostemps_safer (char *, int, int);
-#endif
-
-#if GNULIB_MKSTEMPS
-int mkstemps_safer (char *, int);
-#endif
+/* Invoke stdlib.h functions, but avoid some glitches.
+
+ Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+int mkstemp_safer (char *);
+
+#if GNULIB_MKOSTEMP
+int mkostemp_safer (char *, int);
+#endif
+
+#if GNULIB_MKOSTEMPS
+int mkostemps_safer (char *, int, int);
+#endif
+
+#if GNULIB_MKSTEMPS
+int mkstemps_safer (char *, int);
+#endif
diff --git a/contrib/tools/bison/gnulib/src/stpcpy.c b/contrib/tools/bison/gnulib/src/stpcpy.c
index f5aa8d67e9..e7c504e8eb 100644
--- a/contrib/tools/bison/gnulib/src/stpcpy.c
+++ b/contrib/tools/bison/gnulib/src/stpcpy.c
@@ -1,50 +1,50 @@
-/* stpcpy.c -- copy a string and return pointer to end of new string
- Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2013 Free Software
- Foundation, Inc.
-
- NOTE: The canonical source of this file is maintained with the GNU C Library.
- Bugs can be reported to bug-glibc@prep.ai.mit.edu.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or any
- later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include <string.h>
+/* stpcpy.c -- copy a string and return pointer to end of new string
+ Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ NOTE: The canonical source of this file is maintained with the GNU C Library.
+ Bugs can be reported to bug-glibc@prep.ai.mit.edu.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <string.h>
#include <stdlib.h>
-
-#undef __stpcpy
+
+#undef __stpcpy
#if defined(_LIBC) || (defined(__MACH__) && defined(stpcpy))
-# undef stpcpy
-#endif
-
-#ifndef weak_alias
-# define __stpcpy stpcpy
-#endif
-
-/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
-char *
-__stpcpy (char *dest, const char *src)
-{
+# undef stpcpy
+#endif
+
+#ifndef weak_alias
+# define __stpcpy stpcpy
+#endif
+
+/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
+char *
+__stpcpy (char *dest, const char *src)
+{
char *d = dest;
const char *s = src;
-
- do
- *d++ = *s;
- while (*s++ != '\0');
-
- return d - 1;
-}
-#ifdef weak_alias
-weak_alias (__stpcpy, stpcpy)
-#endif
+
+ do
+ *d++ = *s;
+ while (*s++ != '\0');
+
+ return d - 1;
+}
+#ifdef weak_alias
+weak_alias (__stpcpy, stpcpy)
+#endif
diff --git a/contrib/tools/bison/gnulib/src/str-two-way.h b/contrib/tools/bison/gnulib/src/str-two-way.h
index 707145dbdd..a745edd490 100644
--- a/contrib/tools/bison/gnulib/src/str-two-way.h
+++ b/contrib/tools/bison/gnulib/src/str-two-way.h
@@ -1,452 +1,452 @@
-/* Byte-wise substring search, using the Two-Way algorithm.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Written by Eric Blake <ebb9@byu.net>, 2008.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* Before including this file, you need to include <config.h> and
- <string.h>, and define:
- RESULT_TYPE A macro that expands to the return type.
- AVAILABLE(h, h_l, j, n_l)
- A macro that returns nonzero if there are
- at least N_L bytes left starting at H[J].
- H is 'unsigned char *', H_L, J, and N_L
- are 'size_t'; H_L is an lvalue. For
- NUL-terminated searches, H_L can be
- modified each iteration to avoid having
- to compute the end of H up front.
-
- For case-insensitivity, you may optionally define:
- CMP_FUNC(p1, p2, l) A macro that returns 0 iff the first L
- characters of P1 and P2 are equal.
- CANON_ELEMENT(c) A macro that canonicalizes an element right after
- it has been fetched from one of the two strings.
- The argument is an 'unsigned char'; the result
- must be an 'unsigned char' as well.
-
- This file undefines the macros documented above, and defines
- LONG_NEEDLE_THRESHOLD.
-*/
-
-#include <limits.h>
-#include <stdint.h>
-
-/* We use the Two-Way string matching algorithm (also known as
- Chrochemore-Perrin), which guarantees linear complexity with
- constant space. Additionally, for long needles, we also use a bad
- character shift table similar to the Boyer-Moore algorithm to
- achieve improved (potentially sub-linear) performance.
-
- See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260,
- http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm,
- http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.34.6641&rep=rep1&type=pdf
-*/
-
-/* Point at which computing a bad-byte shift table is likely to be
- worthwhile. Small needles should not compute a table, since it
- adds (1 << CHAR_BIT) + NEEDLE_LEN computations of preparation for a
- speedup no greater than a factor of NEEDLE_LEN. The larger the
- needle, the better the potential performance gain. On the other
- hand, on non-POSIX systems with CHAR_BIT larger than eight, the
- memory required for the table is prohibitive. */
-#if CHAR_BIT < 10
-# define LONG_NEEDLE_THRESHOLD 32U
-#else
-# define LONG_NEEDLE_THRESHOLD SIZE_MAX
-#endif
-
-#ifndef MAX
-# define MAX(a, b) ((a < b) ? (b) : (a))
-#endif
-
-#ifndef CANON_ELEMENT
-# define CANON_ELEMENT(c) c
-#endif
-#ifndef CMP_FUNC
-# define CMP_FUNC memcmp
-#endif
-
-/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
- Return the index of the first byte in the right half, and set
- *PERIOD to the global period of the right half.
-
- The global period of a string is the smallest index (possibly its
- length) at which all remaining bytes in the string are repetitions
- of the prefix (the last repetition may be a subset of the prefix).
-
- When NEEDLE is factored into two halves, a local period is the
- length of the smallest word that shares a suffix with the left half
- and shares a prefix with the right half. All factorizations of a
- non-empty NEEDLE have a local period of at least 1 and no greater
- than NEEDLE_LEN.
-
- A critical factorization has the property that the local period
- equals the global period. All strings have at least one critical
- factorization with the left half smaller than the global period.
- And while some strings have more than one critical factorization,
- it is provable that with an ordered alphabet, at least one of the
- critical factorizations corresponds to a maximal suffix.
-
- Given an ordered alphabet, a critical factorization can be computed
- in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
- shorter of two ordered maximal suffixes. The ordered maximal
- suffixes are determined by lexicographic comparison while tracking
- periodicity. */
-static size_t
-critical_factorization (const unsigned char *needle, size_t needle_len,
- size_t *period)
-{
- /* Index of last byte of left half, or SIZE_MAX. */
- size_t max_suffix, max_suffix_rev;
- size_t j; /* Index into NEEDLE for current candidate suffix. */
- size_t k; /* Offset into current period. */
- size_t p; /* Intermediate period. */
- unsigned char a, b; /* Current comparison bytes. */
-
- /* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered
- out 0-length needles. */
- if (needle_len < 3)
- {
- *period = 1;
- return needle_len - 1;
- }
-
- /* Invariants:
- 0 <= j < NEEDLE_LEN - 1
- -1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed)
- min(max_suffix, max_suffix_rev) < global period of NEEDLE
- 1 <= p <= global period of NEEDLE
- p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
- 1 <= k <= p
- */
-
- /* Perform lexicographic search. */
- max_suffix = SIZE_MAX;
- j = 0;
- k = p = 1;
- while (j + k < needle_len)
- {
- a = CANON_ELEMENT (needle[j + k]);
- b = CANON_ELEMENT (needle[max_suffix + k]);
- if (a < b)
- {
- /* Suffix is smaller, period is entire prefix so far. */
- j += k;
- k = 1;
- p = j - max_suffix;
- }
- else if (a == b)
- {
- /* Advance through repetition of the current period. */
- if (k != p)
- ++k;
- else
- {
- j += p;
- k = 1;
- }
- }
- else /* b < a */
- {
- /* Suffix is larger, start over from current location. */
- max_suffix = j++;
- k = p = 1;
- }
- }
- *period = p;
-
- /* Perform reverse lexicographic search. */
- max_suffix_rev = SIZE_MAX;
- j = 0;
- k = p = 1;
- while (j + k < needle_len)
- {
- a = CANON_ELEMENT (needle[j + k]);
- b = CANON_ELEMENT (needle[max_suffix_rev + k]);
- if (b < a)
- {
- /* Suffix is smaller, period is entire prefix so far. */
- j += k;
- k = 1;
- p = j - max_suffix_rev;
- }
- else if (a == b)
- {
- /* Advance through repetition of the current period. */
- if (k != p)
- ++k;
- else
- {
- j += p;
- k = 1;
- }
- }
- else /* a < b */
- {
- /* Suffix is larger, start over from current location. */
- max_suffix_rev = j++;
- k = p = 1;
- }
- }
-
- /* Choose the shorter suffix. Return the index of the first byte of
- the right half, rather than the last byte of the left half.
-
- For some examples, 'banana' has two critical factorizations, both
- exposed by the two lexicographic extreme suffixes of 'anana' and
- 'nana', where both suffixes have a period of 2. On the other
- hand, with 'aab' and 'bba', both strings have a single critical
- factorization of the last byte, with the suffix having a period
- of 1. While the maximal lexicographic suffix of 'aab' is 'b',
- the maximal lexicographic suffix of 'bba' is 'ba', which is not a
- critical factorization. Conversely, the maximal reverse
- lexicographic suffix of 'a' works for 'bba', but not 'ab' for
- 'aab'. The shorter suffix of the two will always be a critical
- factorization. */
- if (max_suffix_rev + 1 < max_suffix + 1)
- return max_suffix + 1;
- *period = p;
- return max_suffix_rev + 1;
-}
-
-/* Return the first location of non-empty NEEDLE within HAYSTACK, or
- NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
- method is optimized for NEEDLE_LEN < LONG_NEEDLE_THRESHOLD.
- Performance is guaranteed to be linear, with an initialization cost
- of 2 * NEEDLE_LEN comparisons.
-
- If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
- most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching.
- If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
- HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */
-static RETURN_TYPE
-two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
- const unsigned char *needle, size_t needle_len)
-{
- size_t i; /* Index into current byte of NEEDLE. */
- size_t j; /* Index into current window of HAYSTACK. */
- size_t period; /* The period of the right half of needle. */
- size_t suffix; /* The index of the right half of needle. */
-
- /* Factor the needle into two halves, such that the left half is
- smaller than the global period, and the right half is
- periodic (with a period as large as NEEDLE_LEN - suffix). */
- suffix = critical_factorization (needle, needle_len, &period);
-
- /* Perform the search. Each iteration compares the right half
- first. */
- if (CMP_FUNC (needle, needle + period, suffix) == 0)
- {
- /* Entire needle is periodic; a mismatch in the left half can
- only advance by the period, so use memory to avoid rescanning
- known occurrences of the period in the right half. */
- size_t memory = 0;
- j = 0;
- while (AVAILABLE (haystack, haystack_len, j, needle_len))
- {
- /* Scan for matches in right half. */
- i = MAX (suffix, memory);
- while (i < needle_len && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- ++i;
- if (needle_len <= i)
- {
- /* Scan for matches in left half. */
- i = suffix - 1;
- while (memory < i + 1 && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- --i;
- if (i + 1 < memory + 1)
- return (RETURN_TYPE) (haystack + j);
- /* No match, so remember how many repetitions of period
- on the right half were scanned. */
- j += period;
- memory = needle_len - period;
- }
- else
- {
- j += i - suffix + 1;
- memory = 0;
- }
- }
- }
- else
- {
- /* The two halves of needle are distinct; no extra memory is
- required, and any mismatch results in a maximal shift. */
- period = MAX (suffix, needle_len - suffix) + 1;
- j = 0;
- while (AVAILABLE (haystack, haystack_len, j, needle_len))
- {
- /* Scan for matches in right half. */
- i = suffix;
- while (i < needle_len && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- ++i;
- if (needle_len <= i)
- {
- /* Scan for matches in left half. */
- i = suffix - 1;
- while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- --i;
- if (i == SIZE_MAX)
- return (RETURN_TYPE) (haystack + j);
- j += period;
- }
- else
- j += i - suffix + 1;
- }
- }
- return NULL;
-}
-
-/* Return the first location of non-empty NEEDLE within HAYSTACK, or
- NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
- method is optimized for LONG_NEEDLE_THRESHOLD <= NEEDLE_LEN.
- Performance is guaranteed to be linear, with an initialization cost
- of 3 * NEEDLE_LEN + (1 << CHAR_BIT) operations.
-
- If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
- most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching,
- and sublinear performance O(HAYSTACK_LEN / NEEDLE_LEN) is possible.
- If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
- HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and
- sublinear performance is not possible. */
-static RETURN_TYPE
-two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
- const unsigned char *needle, size_t needle_len)
-{
- size_t i; /* Index into current byte of NEEDLE. */
- size_t j; /* Index into current window of HAYSTACK. */
- size_t period; /* The period of the right half of needle. */
- size_t suffix; /* The index of the right half of needle. */
- size_t shift_table[1U << CHAR_BIT]; /* See below. */
-
- /* Factor the needle into two halves, such that the left half is
- smaller than the global period, and the right half is
- periodic (with a period as large as NEEDLE_LEN - suffix). */
- suffix = critical_factorization (needle, needle_len, &period);
-
- /* Populate shift_table. For each possible byte value c,
- shift_table[c] is the distance from the last occurrence of c to
- the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE.
- shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */
- for (i = 0; i < 1U << CHAR_BIT; i++)
- shift_table[i] = needle_len;
- for (i = 0; i < needle_len; i++)
- shift_table[CANON_ELEMENT (needle[i])] = needle_len - i - 1;
-
- /* Perform the search. Each iteration compares the right half
- first. */
- if (CMP_FUNC (needle, needle + period, suffix) == 0)
- {
- /* Entire needle is periodic; a mismatch in the left half can
- only advance by the period, so use memory to avoid rescanning
- known occurrences of the period in the right half. */
- size_t memory = 0;
- size_t shift;
- j = 0;
- while (AVAILABLE (haystack, haystack_len, j, needle_len))
- {
- /* Check the last byte first; if it does not match, then
- shift to the next possible match location. */
- shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
- if (0 < shift)
- {
- if (memory && shift < period)
- {
- /* Since needle is periodic, but the last period has
- a byte out of place, there can be no match until
- after the mismatch. */
- shift = needle_len - period;
- }
- memory = 0;
- j += shift;
- continue;
- }
- /* Scan for matches in right half. The last byte has
- already been matched, by virtue of the shift table. */
- i = MAX (suffix, memory);
- while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- ++i;
- if (needle_len - 1 <= i)
- {
- /* Scan for matches in left half. */
- i = suffix - 1;
- while (memory < i + 1 && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- --i;
- if (i + 1 < memory + 1)
- return (RETURN_TYPE) (haystack + j);
- /* No match, so remember how many repetitions of period
- on the right half were scanned. */
- j += period;
- memory = needle_len - period;
- }
- else
- {
- j += i - suffix + 1;
- memory = 0;
- }
- }
- }
- else
- {
- /* The two halves of needle are distinct; no extra memory is
- required, and any mismatch results in a maximal shift. */
- size_t shift;
- period = MAX (suffix, needle_len - suffix) + 1;
- j = 0;
- while (AVAILABLE (haystack, haystack_len, j, needle_len))
- {
- /* Check the last byte first; if it does not match, then
- shift to the next possible match location. */
- shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
- if (0 < shift)
- {
- j += shift;
- continue;
- }
- /* Scan for matches in right half. The last byte has
- already been matched, by virtue of the shift table. */
- i = suffix;
- while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- ++i;
- if (needle_len - 1 <= i)
- {
- /* Scan for matches in left half. */
- i = suffix - 1;
- while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
- == CANON_ELEMENT (haystack[i + j])))
- --i;
- if (i == SIZE_MAX)
- return (RETURN_TYPE) (haystack + j);
- j += period;
- }
- else
- j += i - suffix + 1;
- }
- }
- return NULL;
-}
-
-#undef AVAILABLE
-#undef CANON_ELEMENT
-#undef CMP_FUNC
-#undef MAX
-#undef RETURN_TYPE
+/* Byte-wise substring search, using the Two-Way algorithm.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Eric Blake <ebb9@byu.net>, 2008.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* Before including this file, you need to include <config.h> and
+ <string.h>, and define:
+ RESULT_TYPE A macro that expands to the return type.
+ AVAILABLE(h, h_l, j, n_l)
+ A macro that returns nonzero if there are
+ at least N_L bytes left starting at H[J].
+ H is 'unsigned char *', H_L, J, and N_L
+ are 'size_t'; H_L is an lvalue. For
+ NUL-terminated searches, H_L can be
+ modified each iteration to avoid having
+ to compute the end of H up front.
+
+ For case-insensitivity, you may optionally define:
+ CMP_FUNC(p1, p2, l) A macro that returns 0 iff the first L
+ characters of P1 and P2 are equal.
+ CANON_ELEMENT(c) A macro that canonicalizes an element right after
+ it has been fetched from one of the two strings.
+ The argument is an 'unsigned char'; the result
+ must be an 'unsigned char' as well.
+
+ This file undefines the macros documented above, and defines
+ LONG_NEEDLE_THRESHOLD.
+*/
+
+#include <limits.h>
+#include <stdint.h>
+
+/* We use the Two-Way string matching algorithm (also known as
+ Chrochemore-Perrin), which guarantees linear complexity with
+ constant space. Additionally, for long needles, we also use a bad
+ character shift table similar to the Boyer-Moore algorithm to
+ achieve improved (potentially sub-linear) performance.
+
+ See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260,
+ http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm,
+ http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.34.6641&rep=rep1&type=pdf
+*/
+
+/* Point at which computing a bad-byte shift table is likely to be
+ worthwhile. Small needles should not compute a table, since it
+ adds (1 << CHAR_BIT) + NEEDLE_LEN computations of preparation for a
+ speedup no greater than a factor of NEEDLE_LEN. The larger the
+ needle, the better the potential performance gain. On the other
+ hand, on non-POSIX systems with CHAR_BIT larger than eight, the
+ memory required for the table is prohibitive. */
+#if CHAR_BIT < 10
+# define LONG_NEEDLE_THRESHOLD 32U
+#else
+# define LONG_NEEDLE_THRESHOLD SIZE_MAX
+#endif
+
+#ifndef MAX
+# define MAX(a, b) ((a < b) ? (b) : (a))
+#endif
+
+#ifndef CANON_ELEMENT
+# define CANON_ELEMENT(c) c
+#endif
+#ifndef CMP_FUNC
+# define CMP_FUNC memcmp
+#endif
+
+/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
+ Return the index of the first byte in the right half, and set
+ *PERIOD to the global period of the right half.
+
+ The global period of a string is the smallest index (possibly its
+ length) at which all remaining bytes in the string are repetitions
+ of the prefix (the last repetition may be a subset of the prefix).
+
+ When NEEDLE is factored into two halves, a local period is the
+ length of the smallest word that shares a suffix with the left half
+ and shares a prefix with the right half. All factorizations of a
+ non-empty NEEDLE have a local period of at least 1 and no greater
+ than NEEDLE_LEN.
+
+ A critical factorization has the property that the local period
+ equals the global period. All strings have at least one critical
+ factorization with the left half smaller than the global period.
+ And while some strings have more than one critical factorization,
+ it is provable that with an ordered alphabet, at least one of the
+ critical factorizations corresponds to a maximal suffix.
+
+ Given an ordered alphabet, a critical factorization can be computed
+ in linear time, with 2 * NEEDLE_LEN comparisons, by computing the
+ shorter of two ordered maximal suffixes. The ordered maximal
+ suffixes are determined by lexicographic comparison while tracking
+ periodicity. */
+static size_t
+critical_factorization (const unsigned char *needle, size_t needle_len,
+ size_t *period)
+{
+ /* Index of last byte of left half, or SIZE_MAX. */
+ size_t max_suffix, max_suffix_rev;
+ size_t j; /* Index into NEEDLE for current candidate suffix. */
+ size_t k; /* Offset into current period. */
+ size_t p; /* Intermediate period. */
+ unsigned char a, b; /* Current comparison bytes. */
+
+ /* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered
+ out 0-length needles. */
+ if (needle_len < 3)
+ {
+ *period = 1;
+ return needle_len - 1;
+ }
+
+ /* Invariants:
+ 0 <= j < NEEDLE_LEN - 1
+ -1 <= max_suffix{,_rev} < j (treating SIZE_MAX as if it were signed)
+ min(max_suffix, max_suffix_rev) < global period of NEEDLE
+ 1 <= p <= global period of NEEDLE
+ p == global period of the substring NEEDLE[max_suffix{,_rev}+1...j]
+ 1 <= k <= p
+ */
+
+ /* Perform lexicographic search. */
+ max_suffix = SIZE_MAX;
+ j = 0;
+ k = p = 1;
+ while (j + k < needle_len)
+ {
+ a = CANON_ELEMENT (needle[j + k]);
+ b = CANON_ELEMENT (needle[max_suffix + k]);
+ if (a < b)
+ {
+ /* Suffix is smaller, period is entire prefix so far. */
+ j += k;
+ k = 1;
+ p = j - max_suffix;
+ }
+ else if (a == b)
+ {
+ /* Advance through repetition of the current period. */
+ if (k != p)
+ ++k;
+ else
+ {
+ j += p;
+ k = 1;
+ }
+ }
+ else /* b < a */
+ {
+ /* Suffix is larger, start over from current location. */
+ max_suffix = j++;
+ k = p = 1;
+ }
+ }
+ *period = p;
+
+ /* Perform reverse lexicographic search. */
+ max_suffix_rev = SIZE_MAX;
+ j = 0;
+ k = p = 1;
+ while (j + k < needle_len)
+ {
+ a = CANON_ELEMENT (needle[j + k]);
+ b = CANON_ELEMENT (needle[max_suffix_rev + k]);
+ if (b < a)
+ {
+ /* Suffix is smaller, period is entire prefix so far. */
+ j += k;
+ k = 1;
+ p = j - max_suffix_rev;
+ }
+ else if (a == b)
+ {
+ /* Advance through repetition of the current period. */
+ if (k != p)
+ ++k;
+ else
+ {
+ j += p;
+ k = 1;
+ }
+ }
+ else /* a < b */
+ {
+ /* Suffix is larger, start over from current location. */
+ max_suffix_rev = j++;
+ k = p = 1;
+ }
+ }
+
+ /* Choose the shorter suffix. Return the index of the first byte of
+ the right half, rather than the last byte of the left half.
+
+ For some examples, 'banana' has two critical factorizations, both
+ exposed by the two lexicographic extreme suffixes of 'anana' and
+ 'nana', where both suffixes have a period of 2. On the other
+ hand, with 'aab' and 'bba', both strings have a single critical
+ factorization of the last byte, with the suffix having a period
+ of 1. While the maximal lexicographic suffix of 'aab' is 'b',
+ the maximal lexicographic suffix of 'bba' is 'ba', which is not a
+ critical factorization. Conversely, the maximal reverse
+ lexicographic suffix of 'a' works for 'bba', but not 'ab' for
+ 'aab'. The shorter suffix of the two will always be a critical
+ factorization. */
+ if (max_suffix_rev + 1 < max_suffix + 1)
+ return max_suffix + 1;
+ *period = p;
+ return max_suffix_rev + 1;
+}
+
+/* Return the first location of non-empty NEEDLE within HAYSTACK, or
+ NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
+ method is optimized for NEEDLE_LEN < LONG_NEEDLE_THRESHOLD.
+ Performance is guaranteed to be linear, with an initialization cost
+ of 2 * NEEDLE_LEN comparisons.
+
+ If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
+ most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching.
+ If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
+ HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching. */
+static RETURN_TYPE
+two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
+ const unsigned char *needle, size_t needle_len)
+{
+ size_t i; /* Index into current byte of NEEDLE. */
+ size_t j; /* Index into current window of HAYSTACK. */
+ size_t period; /* The period of the right half of needle. */
+ size_t suffix; /* The index of the right half of needle. */
+
+ /* Factor the needle into two halves, such that the left half is
+ smaller than the global period, and the right half is
+ periodic (with a period as large as NEEDLE_LEN - suffix). */
+ suffix = critical_factorization (needle, needle_len, &period);
+
+ /* Perform the search. Each iteration compares the right half
+ first. */
+ if (CMP_FUNC (needle, needle + period, suffix) == 0)
+ {
+ /* Entire needle is periodic; a mismatch in the left half can
+ only advance by the period, so use memory to avoid rescanning
+ known occurrences of the period in the right half. */
+ size_t memory = 0;
+ j = 0;
+ while (AVAILABLE (haystack, haystack_len, j, needle_len))
+ {
+ /* Scan for matches in right half. */
+ i = MAX (suffix, memory);
+ while (i < needle_len && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ ++i;
+ if (needle_len <= i)
+ {
+ /* Scan for matches in left half. */
+ i = suffix - 1;
+ while (memory < i + 1 && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ --i;
+ if (i + 1 < memory + 1)
+ return (RETURN_TYPE) (haystack + j);
+ /* No match, so remember how many repetitions of period
+ on the right half were scanned. */
+ j += period;
+ memory = needle_len - period;
+ }
+ else
+ {
+ j += i - suffix + 1;
+ memory = 0;
+ }
+ }
+ }
+ else
+ {
+ /* The two halves of needle are distinct; no extra memory is
+ required, and any mismatch results in a maximal shift. */
+ period = MAX (suffix, needle_len - suffix) + 1;
+ j = 0;
+ while (AVAILABLE (haystack, haystack_len, j, needle_len))
+ {
+ /* Scan for matches in right half. */
+ i = suffix;
+ while (i < needle_len && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ ++i;
+ if (needle_len <= i)
+ {
+ /* Scan for matches in left half. */
+ i = suffix - 1;
+ while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ --i;
+ if (i == SIZE_MAX)
+ return (RETURN_TYPE) (haystack + j);
+ j += period;
+ }
+ else
+ j += i - suffix + 1;
+ }
+ }
+ return NULL;
+}
+
+/* Return the first location of non-empty NEEDLE within HAYSTACK, or
+ NULL. HAYSTACK_LEN is the minimum known length of HAYSTACK. This
+ method is optimized for LONG_NEEDLE_THRESHOLD <= NEEDLE_LEN.
+ Performance is guaranteed to be linear, with an initialization cost
+ of 3 * NEEDLE_LEN + (1 << CHAR_BIT) operations.
+
+ If AVAILABLE does not modify HAYSTACK_LEN (as in memmem), then at
+ most 2 * HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching,
+ and sublinear performance O(HAYSTACK_LEN / NEEDLE_LEN) is possible.
+ If AVAILABLE modifies HAYSTACK_LEN (as in strstr), then at most 3 *
+ HAYSTACK_LEN - NEEDLE_LEN comparisons occur in searching, and
+ sublinear performance is not possible. */
+static RETURN_TYPE
+two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
+ const unsigned char *needle, size_t needle_len)
+{
+ size_t i; /* Index into current byte of NEEDLE. */
+ size_t j; /* Index into current window of HAYSTACK. */
+ size_t period; /* The period of the right half of needle. */
+ size_t suffix; /* The index of the right half of needle. */
+ size_t shift_table[1U << CHAR_BIT]; /* See below. */
+
+ /* Factor the needle into two halves, such that the left half is
+ smaller than the global period, and the right half is
+ periodic (with a period as large as NEEDLE_LEN - suffix). */
+ suffix = critical_factorization (needle, needle_len, &period);
+
+ /* Populate shift_table. For each possible byte value c,
+ shift_table[c] is the distance from the last occurrence of c to
+ the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE.
+ shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */
+ for (i = 0; i < 1U << CHAR_BIT; i++)
+ shift_table[i] = needle_len;
+ for (i = 0; i < needle_len; i++)
+ shift_table[CANON_ELEMENT (needle[i])] = needle_len - i - 1;
+
+ /* Perform the search. Each iteration compares the right half
+ first. */
+ if (CMP_FUNC (needle, needle + period, suffix) == 0)
+ {
+ /* Entire needle is periodic; a mismatch in the left half can
+ only advance by the period, so use memory to avoid rescanning
+ known occurrences of the period in the right half. */
+ size_t memory = 0;
+ size_t shift;
+ j = 0;
+ while (AVAILABLE (haystack, haystack_len, j, needle_len))
+ {
+ /* Check the last byte first; if it does not match, then
+ shift to the next possible match location. */
+ shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
+ if (0 < shift)
+ {
+ if (memory && shift < period)
+ {
+ /* Since needle is periodic, but the last period has
+ a byte out of place, there can be no match until
+ after the mismatch. */
+ shift = needle_len - period;
+ }
+ memory = 0;
+ j += shift;
+ continue;
+ }
+ /* Scan for matches in right half. The last byte has
+ already been matched, by virtue of the shift table. */
+ i = MAX (suffix, memory);
+ while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ ++i;
+ if (needle_len - 1 <= i)
+ {
+ /* Scan for matches in left half. */
+ i = suffix - 1;
+ while (memory < i + 1 && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ --i;
+ if (i + 1 < memory + 1)
+ return (RETURN_TYPE) (haystack + j);
+ /* No match, so remember how many repetitions of period
+ on the right half were scanned. */
+ j += period;
+ memory = needle_len - period;
+ }
+ else
+ {
+ j += i - suffix + 1;
+ memory = 0;
+ }
+ }
+ }
+ else
+ {
+ /* The two halves of needle are distinct; no extra memory is
+ required, and any mismatch results in a maximal shift. */
+ size_t shift;
+ period = MAX (suffix, needle_len - suffix) + 1;
+ j = 0;
+ while (AVAILABLE (haystack, haystack_len, j, needle_len))
+ {
+ /* Check the last byte first; if it does not match, then
+ shift to the next possible match location. */
+ shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])];
+ if (0 < shift)
+ {
+ j += shift;
+ continue;
+ }
+ /* Scan for matches in right half. The last byte has
+ already been matched, by virtue of the shift table. */
+ i = suffix;
+ while (i < needle_len - 1 && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ ++i;
+ if (needle_len - 1 <= i)
+ {
+ /* Scan for matches in left half. */
+ i = suffix - 1;
+ while (i != SIZE_MAX && (CANON_ELEMENT (needle[i])
+ == CANON_ELEMENT (haystack[i + j])))
+ --i;
+ if (i == SIZE_MAX)
+ return (RETURN_TYPE) (haystack + j);
+ j += period;
+ }
+ else
+ j += i - suffix + 1;
+ }
+ }
+ return NULL;
+}
+
+#undef AVAILABLE
+#undef CANON_ELEMENT
+#undef CMP_FUNC
+#undef MAX
+#undef RETURN_TYPE
diff --git a/contrib/tools/bison/gnulib/src/strchrnul.c b/contrib/tools/bison/gnulib/src/strchrnul.c
index 4308889950..35784f1f74 100644
--- a/contrib/tools/bison/gnulib/src/strchrnul.c
+++ b/contrib/tools/bison/gnulib/src/strchrnul.c
@@ -1,142 +1,142 @@
-/* Searching in a string.
- Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
+/* Searching in a string.
+ Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
#include "string--.h"
-
-/* Find the first occurrence of C in S or the final NUL byte. */
-char *
-strchrnul (const char *s, int c_in)
-{
- /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
- long instead of a 64-bit uintmax_t tends to give better
- performance. On 64-bit hardware, unsigned long is generally 64
- bits already. Change this typedef to experiment with
- performance. */
- typedef unsigned long int longword;
-
- const unsigned char *char_ptr;
- const longword *longword_ptr;
- longword repeated_one;
- longword repeated_c;
- unsigned char c;
-
- c = (unsigned char) c_in;
- if (!c)
- return rawmemchr (s, 0);
-
- /* Handle the first few bytes by reading one byte at a time.
- Do this until CHAR_PTR is aligned on a longword boundary. */
- for (char_ptr = (const unsigned char *) s;
- (size_t) char_ptr % sizeof (longword) != 0;
- ++char_ptr)
- if (!*char_ptr || *char_ptr == c)
- return (char *) char_ptr;
-
- longword_ptr = (const longword *) char_ptr;
-
- /* All these elucidatory comments refer to 4-byte longwords,
- but the theory applies equally well to any size longwords. */
-
- /* Compute auxiliary longword values:
- repeated_one is a value which has a 1 in every byte.
- repeated_c has c in every byte. */
- repeated_one = 0x01010101;
- repeated_c = c | (c << 8);
- repeated_c |= repeated_c << 16;
- if (0xffffffffU < (longword) -1)
- {
- repeated_one |= repeated_one << 31 << 1;
- repeated_c |= repeated_c << 31 << 1;
- if (8 < sizeof (longword))
- {
- size_t i;
-
- for (i = 64; i < sizeof (longword) * 8; i *= 2)
- {
- repeated_one |= repeated_one << i;
- repeated_c |= repeated_c << i;
- }
- }
- }
-
- /* Instead of the traditional loop which tests each byte, we will
- test a longword at a time. The tricky part is testing if *any of
- the four* bytes in the longword in question are equal to NUL or
- c. We first use an xor with repeated_c. This reduces the task
- to testing whether *any of the four* bytes in longword1 or
- longword2 is zero.
-
- Let's consider longword1. We compute tmp =
- ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
- That is, we perform the following operations:
- 1. Subtract repeated_one.
- 2. & ~longword1.
- 3. & a mask consisting of 0x80 in every byte.
- Consider what happens in each byte:
- - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
- and step 3 transforms it into 0x80. A carry can also be propagated
- to more significant bytes.
- - If a byte of longword1 is nonzero, let its lowest 1 bit be at
- position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
- the byte ends in a single bit of value 0 and k bits of value 1.
- After step 2, the result is just k bits of value 1: 2^k - 1. After
- step 3, the result is 0. And no carry is produced.
- So, if longword1 has only non-zero bytes, tmp is zero.
- Whereas if longword1 has a zero byte, call j the position of the least
- significant zero byte. Then the result has a zero at positions 0, ...,
- j-1 and a 0x80 at position j. We cannot predict the result at the more
- significant bytes (positions j+1..3), but it does not matter since we
- already have a non-zero bit at position 8*j+7.
-
- The test whether any byte in longword1 or longword2 is zero is equivalent
- to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine
- this into a single test, whether (tmp1 | tmp2) is nonzero.
-
- This test can read more than one byte beyond the end of a string,
- depending on where the terminating NUL is encountered. However,
- this is considered safe since the initialization phase ensured
- that the read will be aligned, therefore, the read will not cross
- page boundaries and will not cause a fault. */
-
- while (1)
- {
- longword longword1 = *longword_ptr ^ repeated_c;
- longword longword2 = *longword_ptr;
-
- if (((((longword1 - repeated_one) & ~longword1)
- | ((longword2 - repeated_one) & ~longword2))
- & (repeated_one << 7)) != 0)
- break;
- longword_ptr++;
- }
-
- char_ptr = (const unsigned char *) longword_ptr;
-
- /* At this point, we know that one of the sizeof (longword) bytes
- starting at char_ptr is == 0 or == c. On little-endian machines,
- we could determine the first such byte without any further memory
- accesses, just by looking at the tmp result from the last loop
- iteration. But this does not work on big-endian machines.
- Choose code that works in both cases. */
-
- char_ptr = (unsigned char *) longword_ptr;
- while (*char_ptr && (*char_ptr != c))
- char_ptr++;
- return (char *) char_ptr;
-}
+
+/* Find the first occurrence of C in S or the final NUL byte. */
+char *
+strchrnul (const char *s, int c_in)
+{
+ /* On 32-bit hardware, choosing longword to be a 32-bit unsigned
+ long instead of a 64-bit uintmax_t tends to give better
+ performance. On 64-bit hardware, unsigned long is generally 64
+ bits already. Change this typedef to experiment with
+ performance. */
+ typedef unsigned long int longword;
+
+ const unsigned char *char_ptr;
+ const longword *longword_ptr;
+ longword repeated_one;
+ longword repeated_c;
+ unsigned char c;
+
+ c = (unsigned char) c_in;
+ if (!c)
+ return rawmemchr (s, 0);
+
+ /* Handle the first few bytes by reading one byte at a time.
+ Do this until CHAR_PTR is aligned on a longword boundary. */
+ for (char_ptr = (const unsigned char *) s;
+ (size_t) char_ptr % sizeof (longword) != 0;
+ ++char_ptr)
+ if (!*char_ptr || *char_ptr == c)
+ return (char *) char_ptr;
+
+ longword_ptr = (const longword *) char_ptr;
+
+ /* All these elucidatory comments refer to 4-byte longwords,
+ but the theory applies equally well to any size longwords. */
+
+ /* Compute auxiliary longword values:
+ repeated_one is a value which has a 1 in every byte.
+ repeated_c has c in every byte. */
+ repeated_one = 0x01010101;
+ repeated_c = c | (c << 8);
+ repeated_c |= repeated_c << 16;
+ if (0xffffffffU < (longword) -1)
+ {
+ repeated_one |= repeated_one << 31 << 1;
+ repeated_c |= repeated_c << 31 << 1;
+ if (8 < sizeof (longword))
+ {
+ size_t i;
+
+ for (i = 64; i < sizeof (longword) * 8; i *= 2)
+ {
+ repeated_one |= repeated_one << i;
+ repeated_c |= repeated_c << i;
+ }
+ }
+ }
+
+ /* Instead of the traditional loop which tests each byte, we will
+ test a longword at a time. The tricky part is testing if *any of
+ the four* bytes in the longword in question are equal to NUL or
+ c. We first use an xor with repeated_c. This reduces the task
+ to testing whether *any of the four* bytes in longword1 or
+ longword2 is zero.
+
+ Let's consider longword1. We compute tmp =
+ ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7).
+ That is, we perform the following operations:
+ 1. Subtract repeated_one.
+ 2. & ~longword1.
+ 3. & a mask consisting of 0x80 in every byte.
+ Consider what happens in each byte:
+ - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff,
+ and step 3 transforms it into 0x80. A carry can also be propagated
+ to more significant bytes.
+ - If a byte of longword1 is nonzero, let its lowest 1 bit be at
+ position k (0 <= k <= 7); so the lowest k bits are 0. After step 1,
+ the byte ends in a single bit of value 0 and k bits of value 1.
+ After step 2, the result is just k bits of value 1: 2^k - 1. After
+ step 3, the result is 0. And no carry is produced.
+ So, if longword1 has only non-zero bytes, tmp is zero.
+ Whereas if longword1 has a zero byte, call j the position of the least
+ significant zero byte. Then the result has a zero at positions 0, ...,
+ j-1 and a 0x80 at position j. We cannot predict the result at the more
+ significant bytes (positions j+1..3), but it does not matter since we
+ already have a non-zero bit at position 8*j+7.
+
+ The test whether any byte in longword1 or longword2 is zero is equivalent
+ to testing whether tmp1 is nonzero or tmp2 is nonzero. We can combine
+ this into a single test, whether (tmp1 | tmp2) is nonzero.
+
+ This test can read more than one byte beyond the end of a string,
+ depending on where the terminating NUL is encountered. However,
+ this is considered safe since the initialization phase ensured
+ that the read will be aligned, therefore, the read will not cross
+ page boundaries and will not cause a fault. */
+
+ while (1)
+ {
+ longword longword1 = *longword_ptr ^ repeated_c;
+ longword longword2 = *longword_ptr;
+
+ if (((((longword1 - repeated_one) & ~longword1)
+ | ((longword2 - repeated_one) & ~longword2))
+ & (repeated_one << 7)) != 0)
+ break;
+ longword_ptr++;
+ }
+
+ char_ptr = (const unsigned char *) longword_ptr;
+
+ /* At this point, we know that one of the sizeof (longword) bytes
+ starting at char_ptr is == 0 or == c. On little-endian machines,
+ we could determine the first such byte without any further memory
+ accesses, just by looking at the tmp result from the last loop
+ iteration. But this does not work on big-endian machines.
+ Choose code that works in both cases. */
+
+ char_ptr = (unsigned char *) longword_ptr;
+ while (*char_ptr && (*char_ptr != c))
+ char_ptr++;
+ return (char *) char_ptr;
+}
diff --git a/contrib/tools/bison/gnulib/src/strdup.c b/contrib/tools/bison/gnulib/src/strdup.c
index 5826ab02af..e88f9aa6f9 100644
--- a/contrib/tools/bison/gnulib/src/strdup.c
+++ b/contrib/tools/bison/gnulib/src/strdup.c
@@ -1,54 +1,54 @@
-/* Copyright (C) 1991, 1996-1998, 2002-2004, 2006-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of the GNU C Library.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC
-# include <config.h>
-#endif
-
-/* Get specification. */
-#include <string.h>
-
-#include <stdlib.h>
-
-#undef __strdup
-#ifdef _LIBC
-# undef strdup
-#endif
-
-#ifndef weak_alias
-# define __strdup strdup
-#endif
-
-/* Duplicate S, returning an identical malloc'd string. */
-char *
-__strdup (const char *s)
-{
- size_t len = strlen (s) + 1;
- void *new = malloc (len);
-
- if (new == NULL)
- return NULL;
-
- return (char *) memcpy (new, s, len);
-}
-#ifdef libc_hidden_def
-libc_hidden_def (__strdup)
-#endif
-#ifdef weak_alias
-weak_alias (__strdup, strdup)
-#endif
+/* Copyright (C) 1991, 1996-1998, 2002-2004, 2006-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of the GNU C Library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LIBC
+# include <config.h>
+#endif
+
+/* Get specification. */
+#include <string.h>
+
+#include <stdlib.h>
+
+#undef __strdup
+#ifdef _LIBC
+# undef strdup
+#endif
+
+#ifndef weak_alias
+# define __strdup strdup
+#endif
+
+/* Duplicate S, returning an identical malloc'd string. */
+char *
+__strdup (const char *s)
+{
+ size_t len = strlen (s) + 1;
+ void *new = malloc (len);
+
+ if (new == NULL)
+ return NULL;
+
+ return (char *) memcpy (new, s, len);
+}
+#ifdef libc_hidden_def
+libc_hidden_def (__strdup)
+#endif
+#ifdef weak_alias
+weak_alias (__strdup, strdup)
+#endif
diff --git a/contrib/tools/bison/gnulib/src/streq.h b/contrib/tools/bison/gnulib/src/streq.h
index 12c1867c83..626bd5ab05 100644
--- a/contrib/tools/bison/gnulib/src/streq.h
+++ b/contrib/tools/bison/gnulib/src/streq.h
@@ -1,176 +1,176 @@
-/* Optimized string comparison.
- Copyright (C) 2001-2002, 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <bruno@clisp.org>. */
-
-#ifndef _GL_STREQ_H
-#define _GL_STREQ_H
-
-#include <string.h>
-
-/* STREQ_OPT allows to optimize string comparison with a small literal string.
- STREQ_OPT (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
- is semantically equivalent to
- strcmp (s, "EUC-KR") == 0
- just faster. */
-
-/* Help GCC to generate good code for string comparisons with
- immediate strings. */
-#if defined (__GNUC__) && defined (__OPTIMIZE__)
-
-static inline int
-streq9 (const char *s1, const char *s2)
-{
- return strcmp (s1 + 9, s2 + 9) == 0;
-}
-
-static inline int
-streq8 (const char *s1, const char *s2, char s28)
-{
- if (s1[8] == s28)
- {
- if (s28 == 0)
- return 1;
- else
- return streq9 (s1, s2);
- }
- else
- return 0;
-}
-
-static inline int
-streq7 (const char *s1, const char *s2, char s27, char s28)
-{
- if (s1[7] == s27)
- {
- if (s27 == 0)
- return 1;
- else
- return streq8 (s1, s2, s28);
- }
- else
- return 0;
-}
-
-static inline int
-streq6 (const char *s1, const char *s2, char s26, char s27, char s28)
-{
- if (s1[6] == s26)
- {
- if (s26 == 0)
- return 1;
- else
- return streq7 (s1, s2, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
-{
- if (s1[5] == s25)
- {
- if (s25 == 0)
- return 1;
- else
- return streq6 (s1, s2, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
-{
- if (s1[4] == s24)
- {
- if (s24 == 0)
- return 1;
- else
- return streq5 (s1, s2, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (s1[3] == s23)
- {
- if (s23 == 0)
- return 1;
- else
- return streq4 (s1, s2, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (s1[2] == s22)
- {
- if (s22 == 0)
- return 1;
- else
- return streq3 (s1, s2, s23, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (s1[1] == s21)
- {
- if (s21 == 0)
- return 1;
- else
- return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-static inline int
-streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
-{
- if (s1[0] == s20)
- {
- if (s20 == 0)
- return 1;
- else
- return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
- }
- else
- return 0;
-}
-
-#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
- streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
-
-#else
-
-#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
- (strcmp (s1, s2) == 0)
-
-#endif
-
-#endif /* _GL_STREQ_H */
+/* Optimized string comparison.
+ Copyright (C) 2001-2002, 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>. */
+
+#ifndef _GL_STREQ_H
+#define _GL_STREQ_H
+
+#include <string.h>
+
+/* STREQ_OPT allows to optimize string comparison with a small literal string.
+ STREQ_OPT (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+ is semantically equivalent to
+ strcmp (s, "EUC-KR") == 0
+ just faster. */
+
+/* Help GCC to generate good code for string comparisons with
+ immediate strings. */
+#if defined (__GNUC__) && defined (__OPTIMIZE__)
+
+static inline int
+streq9 (const char *s1, const char *s2)
+{
+ return strcmp (s1 + 9, s2 + 9) == 0;
+}
+
+static inline int
+streq8 (const char *s1, const char *s2, char s28)
+{
+ if (s1[8] == s28)
+ {
+ if (s28 == 0)
+ return 1;
+ else
+ return streq9 (s1, s2);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq7 (const char *s1, const char *s2, char s27, char s28)
+{
+ if (s1[7] == s27)
+ {
+ if (s27 == 0)
+ return 1;
+ else
+ return streq8 (s1, s2, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq6 (const char *s1, const char *s2, char s26, char s27, char s28)
+{
+ if (s1[6] == s26)
+ {
+ if (s26 == 0)
+ return 1;
+ else
+ return streq7 (s1, s2, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
+{
+ if (s1[5] == s25)
+ {
+ if (s25 == 0)
+ return 1;
+ else
+ return streq6 (s1, s2, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[4] == s24)
+ {
+ if (s24 == 0)
+ return 1;
+ else
+ return streq5 (s1, s2, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[3] == s23)
+ {
+ if (s23 == 0)
+ return 1;
+ else
+ return streq4 (s1, s2, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[2] == s22)
+ {
+ if (s22 == 0)
+ return 1;
+ else
+ return streq3 (s1, s2, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[1] == s21)
+ {
+ if (s21 == 0)
+ return 1;
+ else
+ return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[0] == s20)
+ {
+ if (s20 == 0)
+ return 1;
+ else
+ return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+ streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
+
+#else
+
+#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+ (strcmp (s1, s2) == 0)
+
+#endif
+
+#endif /* _GL_STREQ_H */
diff --git a/contrib/tools/bison/gnulib/src/stripslash.c b/contrib/tools/bison/gnulib/src/stripslash.c
index 0e452a95ef..129298ec29 100644
--- a/contrib/tools/bison/gnulib/src/stripslash.c
+++ b/contrib/tools/bison/gnulib/src/stripslash.c
@@ -1,45 +1,45 @@
-/* stripslash.c -- remove redundant trailing slashes from a file name
-
- Copyright (C) 1990, 2001, 2003-2006, 2009-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "dirname.h"
-
-/* Remove trailing slashes from FILE. Return true if a trailing slash
- was removed. This is useful when using file name completion from a
- shell that adds a "/" after directory names (such as tcsh and
- bash), because on symlinks to directories, several system calls
- have different semantics according to whether a trailing slash is
- present. */
-
-bool
-strip_trailing_slashes (char *file)
-{
- char *base = last_component (file);
- char *base_lim;
- bool had_slash;
-
- /* last_component returns "" for file system roots, but we need to turn
- "///" into "/". */
- if (! *base)
- base = file;
- base_lim = base + base_len (base);
- had_slash = (*base_lim != '\0');
- *base_lim = '\0';
- return had_slash;
-}
+/* stripslash.c -- remove redundant trailing slashes from a file name
+
+ Copyright (C) 1990, 2001, 2003-2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "dirname.h"
+
+/* Remove trailing slashes from FILE. Return true if a trailing slash
+ was removed. This is useful when using file name completion from a
+ shell that adds a "/" after directory names (such as tcsh and
+ bash), because on symlinks to directories, several system calls
+ have different semantics according to whether a trailing slash is
+ present. */
+
+bool
+strip_trailing_slashes (char *file)
+{
+ char *base = last_component (file);
+ char *base_lim;
+ bool had_slash;
+
+ /* last_component returns "" for file system roots, but we need to turn
+ "///" into "/". */
+ if (! *base)
+ base = file;
+ base_lim = base + base_len (base);
+ had_slash = (*base_lim != '\0');
+ *base_lim = '\0';
+ return had_slash;
+}
diff --git a/contrib/tools/bison/gnulib/src/strndup.c b/contrib/tools/bison/gnulib/src/strndup.c
index e60268b86e..8391652db4 100644
--- a/contrib/tools/bison/gnulib/src/strndup.c
+++ b/contrib/tools/bison/gnulib/src/strndup.c
@@ -1,36 +1,36 @@
-/* A replacement function, for systems that lack strndup.
-
- Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3, or (at your option) any
- later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include <string.h>
-
-#include <stdlib.h>
-
-char *
-strndup (char const *s, size_t n)
-{
- size_t len = strnlen (s, n);
- char *new = malloc (len + 1);
-
- if (new == NULL)
- return NULL;
-
- new[len] = '\0';
- return memcpy (new, s, len);
-}
+/* A replacement function, for systems that lack strndup.
+
+ Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <string.h>
+
+#include <stdlib.h>
+
+char *
+strndup (char const *s, size_t n)
+{
+ size_t len = strnlen (s, n);
+ char *new = malloc (len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return memcpy (new, s, len);
+}
diff --git a/contrib/tools/bison/gnulib/src/strnlen.c b/contrib/tools/bison/gnulib/src/strnlen.c
index 57fdfe7700..41b5b82cdb 100644
--- a/contrib/tools/bison/gnulib/src/strnlen.c
+++ b/contrib/tools/bison/gnulib/src/strnlen.c
@@ -1,30 +1,30 @@
-/* Find the length of STRING, but scan at most MAXLEN characters.
- Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Simon Josefsson.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include <string.h>
-
-/* Find the length of STRING, but scan at most MAXLEN characters.
- If no '\0' terminator is found in that many characters, return MAXLEN. */
-
-size_t
-strnlen (const char *string, size_t maxlen)
-{
- const char *end = memchr (string, '\0', maxlen);
- return end ? (size_t) (end - string) : maxlen;
-}
+/* Find the length of STRING, but scan at most MAXLEN characters.
+ Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <string.h>
+
+/* Find the length of STRING, but scan at most MAXLEN characters.
+ If no '\0' terminator is found in that many characters, return MAXLEN. */
+
+size_t
+strnlen (const char *string, size_t maxlen)
+{
+ const char *end = memchr (string, '\0', maxlen);
+ return end ? (size_t) (end - string) : maxlen;
+}
diff --git a/contrib/tools/bison/gnulib/src/strsignal.c b/contrib/tools/bison/gnulib/src/strsignal.c
index 20d604ff38..3180d2c5cf 100644
--- a/contrib/tools/bison/gnulib/src/strsignal.c
+++ b/contrib/tools/bison/gnulib/src/strsignal.c
@@ -1,204 +1,204 @@
-/* Copyright (C) 1991, 1994-2002, 2005, 2008-2013 Free Software Foundation,
- Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _LIBC
-# include <config.h>
-#endif
-
-/* Specification. */
-#include <string.h>
-
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef _LIBC
-# include <libintl.h>
-#else /* !_LIBC */
-# include "gettext.h"
-# define _(msgid) gettext (msgid)
-# define N_(msgid) gettext_noop (msgid)
-#endif /* _LIBC */
-
-#ifdef _LIBC
-# include <bits/libc-lock.h>
-#else /* !_LIBC */
-# include "glthread/lock.h"
-# include "glthread/tls.h"
-# define __libc_once_define(CLASS, NAME) gl_once_define (CLASS, NAME)
-# define __libc_once(NAME, INIT) gl_once ((NAME), (INIT))
-# define __libc_key_t gl_tls_key_t
-# define __libc_getspecific(NAME) gl_tls_get ((NAME))
-# define __libc_setspecific(NAME, POINTER) gl_tls_set ((NAME), (POINTER))
+/* Copyright (C) 1991, 1994-2002, 2005, 2008-2013 Free Software Foundation,
+ Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _LIBC
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <string.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef _LIBC
+# include <libintl.h>
+#else /* !_LIBC */
+# include "gettext.h"
+# define _(msgid) gettext (msgid)
+# define N_(msgid) gettext_noop (msgid)
+#endif /* _LIBC */
+
+#ifdef _LIBC
+# include <bits/libc-lock.h>
+#else /* !_LIBC */
+# include "glthread/lock.h"
+# include "glthread/tls.h"
+# define __libc_once_define(CLASS, NAME) gl_once_define (CLASS, NAME)
+# define __libc_once(NAME, INIT) gl_once ((NAME), (INIT))
+# define __libc_key_t gl_tls_key_t
+# define __libc_getspecific(NAME) gl_tls_get ((NAME))
+# define __libc_setspecific(NAME, POINTER) gl_tls_set ((NAME), (POINTER))
#if defined(_MSC_VER)
# define __snprintf _snprintf
#else
-# define __snprintf snprintf
-#endif
-#endif /* _LIBC */
-
-#ifdef _LIBC
-
-/* Defined in siglist.c. */
-extern const char *const _sys_siglist[];
-extern const char *const _sys_siglist_internal[] attribute_hidden;
-
-#else /* !_LIBC */
-
-/* NetBSD declares sys_siglist in unistd.h. */
-# if HAVE_UNISTD_H
-# include <unistd.h>
-# endif
-
-# define INTUSE(x) (x)
-
-# if HAVE_DECL_SYS_SIGLIST
-# undef _sys_siglist
-# define _sys_siglist sys_siglist
-# else /* !HAVE_DECL_SYS_SIGLIST */
-# ifndef NSIG
-# define NSIG 32
-# endif /* NSIG */
-# if !HAVE_DECL__SYS_SIGLIST
-static const char *_sys_siglist[NSIG];
-# endif
-# endif /* !HAVE_DECL_SYS_SIGLIST */
-
-#endif /* _LIBC */
-
-static __libc_key_t key;
-
-/* If nonzero the key allocation failed and we should better use a
- static buffer than fail. */
-#define BUFFERSIZ 100
-static char local_buf[BUFFERSIZ];
-static char *static_buf;
-
-/* Destructor for the thread-specific data. */
-static void init (void);
-static void free_key_mem (void *mem);
-static char *getbuffer (void);
-
-
-/* Return a string describing the meaning of the signal number SIGNUM. */
-char *
-strsignal (int signum)
-{
- const char *desc;
- __libc_once_define (static, once);
-
- /* If we have not yet initialized the buffer do it now. */
- __libc_once (once, init);
-
- if (
-#ifdef SIGRTMIN
- (signum >= SIGRTMIN && signum <= SIGRTMAX) ||
-#endif
- signum < 0 || signum >= NSIG
- || (desc = INTUSE(_sys_siglist)[signum]) == NULL)
- {
- char *buffer = getbuffer ();
- int len;
-#ifdef SIGRTMIN
- if (signum >= SIGRTMIN && signum <= SIGRTMAX)
- len = __snprintf (buffer, BUFFERSIZ - 1, _("Real-time signal %d"),
- signum - (int) SIGRTMIN);
- else
+# define __snprintf snprintf
#endif
- len = __snprintf (buffer, BUFFERSIZ - 1, _("Unknown signal %d"),
- signum);
- if (len >= BUFFERSIZ)
- buffer = NULL;
- else
- buffer[len] = '\0';
-
- return buffer;
- }
-
- return (char *) _(desc);
-}
-
-
-/* Initialize buffer. */
-static void
-init (void)
-{
-#ifdef _LIBC
- if (__libc_key_create (&key, free_key_mem))
- /* Creating the key failed. This means something really went
- wrong. In any case use a static buffer which is better than
- nothing. */
- static_buf = local_buf;
-#else /* !_LIBC */
- gl_tls_key_init (key, free_key_mem);
-
-# if !HAVE_DECL_SYS_SIGLIST
- memset (_sys_siglist, 0, NSIG * sizeof *_sys_siglist);
-
- /* No need to use a do {} while (0) here since init_sig(...) must expand
- to a complete statement. (We cannot use the ISO C99 designated array
- initializer syntax since it is not supported by ANSI C compilers and
- since some signal numbers might exceed NSIG.) */
-# define init_sig(sig, abbrev, desc) \
- if (sig >= 0 && sig < NSIG) \
- _sys_siglist[sig] = desc;
-
-# include "siglist.h"
-
-# undef init_sig
-
-# endif /* !HAVE_DECL_SYS_SIGLIST */
-#endif /* !_LIBC */
-}
-
-
-/* Free the thread specific data, this is done if a thread terminates. */
-static void
-free_key_mem (void *mem)
-{
- free (mem);
- __libc_setspecific (key, NULL);
-}
-
-
-/* Return the buffer to be used. */
-static char *
-getbuffer (void)
-{
- char *result;
-
- if (static_buf != NULL)
- result = static_buf;
- else
- {
- /* We don't use the static buffer and so we have a key. Use it
- to get the thread-specific buffer. */
- result = __libc_getspecific (key);
- if (result == NULL)
- {
- /* No buffer allocated so far. */
- result = malloc (BUFFERSIZ);
- if (result == NULL)
- /* No more memory available. We use the static buffer. */
- result = local_buf;
- else
- __libc_setspecific (key, result);
- }
- }
-
- return result;
-}
+#endif /* _LIBC */
+
+#ifdef _LIBC
+
+/* Defined in siglist.c. */
+extern const char *const _sys_siglist[];
+extern const char *const _sys_siglist_internal[] attribute_hidden;
+
+#else /* !_LIBC */
+
+/* NetBSD declares sys_siglist in unistd.h. */
+# if HAVE_UNISTD_H
+# include <unistd.h>
+# endif
+
+# define INTUSE(x) (x)
+
+# if HAVE_DECL_SYS_SIGLIST
+# undef _sys_siglist
+# define _sys_siglist sys_siglist
+# else /* !HAVE_DECL_SYS_SIGLIST */
+# ifndef NSIG
+# define NSIG 32
+# endif /* NSIG */
+# if !HAVE_DECL__SYS_SIGLIST
+static const char *_sys_siglist[NSIG];
+# endif
+# endif /* !HAVE_DECL_SYS_SIGLIST */
+
+#endif /* _LIBC */
+
+static __libc_key_t key;
+
+/* If nonzero the key allocation failed and we should better use a
+ static buffer than fail. */
+#define BUFFERSIZ 100
+static char local_buf[BUFFERSIZ];
+static char *static_buf;
+
+/* Destructor for the thread-specific data. */
+static void init (void);
+static void free_key_mem (void *mem);
+static char *getbuffer (void);
+
+
+/* Return a string describing the meaning of the signal number SIGNUM. */
+char *
+strsignal (int signum)
+{
+ const char *desc;
+ __libc_once_define (static, once);
+
+ /* If we have not yet initialized the buffer do it now. */
+ __libc_once (once, init);
+
+ if (
+#ifdef SIGRTMIN
+ (signum >= SIGRTMIN && signum <= SIGRTMAX) ||
+#endif
+ signum < 0 || signum >= NSIG
+ || (desc = INTUSE(_sys_siglist)[signum]) == NULL)
+ {
+ char *buffer = getbuffer ();
+ int len;
+#ifdef SIGRTMIN
+ if (signum >= SIGRTMIN && signum <= SIGRTMAX)
+ len = __snprintf (buffer, BUFFERSIZ - 1, _("Real-time signal %d"),
+ signum - (int) SIGRTMIN);
+ else
+#endif
+ len = __snprintf (buffer, BUFFERSIZ - 1, _("Unknown signal %d"),
+ signum);
+ if (len >= BUFFERSIZ)
+ buffer = NULL;
+ else
+ buffer[len] = '\0';
+
+ return buffer;
+ }
+
+ return (char *) _(desc);
+}
+
+
+/* Initialize buffer. */
+static void
+init (void)
+{
+#ifdef _LIBC
+ if (__libc_key_create (&key, free_key_mem))
+ /* Creating the key failed. This means something really went
+ wrong. In any case use a static buffer which is better than
+ nothing. */
+ static_buf = local_buf;
+#else /* !_LIBC */
+ gl_tls_key_init (key, free_key_mem);
+
+# if !HAVE_DECL_SYS_SIGLIST
+ memset (_sys_siglist, 0, NSIG * sizeof *_sys_siglist);
+
+ /* No need to use a do {} while (0) here since init_sig(...) must expand
+ to a complete statement. (We cannot use the ISO C99 designated array
+ initializer syntax since it is not supported by ANSI C compilers and
+ since some signal numbers might exceed NSIG.) */
+# define init_sig(sig, abbrev, desc) \
+ if (sig >= 0 && sig < NSIG) \
+ _sys_siglist[sig] = desc;
+
+# include "siglist.h"
+
+# undef init_sig
+
+# endif /* !HAVE_DECL_SYS_SIGLIST */
+#endif /* !_LIBC */
+}
+
+
+/* Free the thread specific data, this is done if a thread terminates. */
+static void
+free_key_mem (void *mem)
+{
+ free (mem);
+ __libc_setspecific (key, NULL);
+}
+
+
+/* Return the buffer to be used. */
+static char *
+getbuffer (void)
+{
+ char *result;
+
+ if (static_buf != NULL)
+ result = static_buf;
+ else
+ {
+ /* We don't use the static buffer and so we have a key. Use it
+ to get the thread-specific buffer. */
+ result = __libc_getspecific (key);
+ if (result == NULL)
+ {
+ /* No buffer allocated so far. */
+ result = malloc (BUFFERSIZ);
+ if (result == NULL)
+ /* No more memory available. We use the static buffer. */
+ result = local_buf;
+ else
+ __libc_setspecific (key, result);
+ }
+ }
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/strstr.c b/contrib/tools/bison/gnulib/src/strstr.c
index b91acec7c8..80998f3e0c 100644
--- a/contrib/tools/bison/gnulib/src/strstr.c
+++ b/contrib/tools/bison/gnulib/src/strstr.c
@@ -1,82 +1,82 @@
-/* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* This particular implementation was written by Eric Blake, 2008. */
-
-#ifndef _LIBC
-# include <config.h>
-#endif
-
-/* Specification of strstr. */
-#include <string.h>
-
-#include <stdbool.h>
-
-#ifndef _LIBC
-# define __builtin_expect(expr, val) (expr)
-#endif
-
-#define RETURN_TYPE char *
-#define AVAILABLE(h, h_l, j, n_l) \
- (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
- && ((h_l) = (j) + (n_l)))
-#include "str-two-way.h"
-
-/* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK
- if NEEDLE is empty, otherwise NULL if NEEDLE is not found in
- HAYSTACK. */
-char *
-strstr (const char *haystack_start, const char *needle_start)
-{
- const char *haystack = haystack_start;
- const char *needle = needle_start;
- size_t needle_len; /* Length of NEEDLE. */
- size_t haystack_len; /* Known minimum length of HAYSTACK. */
- bool ok = true; /* True if NEEDLE is prefix of HAYSTACK. */
-
- /* Determine length of NEEDLE, and in the process, make sure
- HAYSTACK is at least as long (no point processing all of a long
- NEEDLE if HAYSTACK is too short). */
- while (*haystack && *needle)
- ok &= *haystack++ == *needle++;
- if (*needle)
- return NULL;
- if (ok)
- return (char *) haystack_start;
-
- /* Reduce the size of haystack using strchr, since it has a smaller
- linear coefficient than the Two-Way algorithm. */
- needle_len = needle - needle_start;
- haystack = strchr (haystack_start + 1, *needle_start);
- if (!haystack || __builtin_expect (needle_len == 1, 0))
- return (char *) haystack;
- needle -= needle_len;
- haystack_len = (haystack > haystack_start + needle_len ? 1
- : needle_len + haystack_start - haystack);
-
- /* Perform the search. Abstract memory is considered to be an array
- of 'unsigned char' values, not an array of 'char' values. See
- ISO C 99 section 6.2.6.1. */
- if (needle_len < LONG_NEEDLE_THRESHOLD)
- return two_way_short_needle ((const unsigned char *) haystack,
- haystack_len,
- (const unsigned char *) needle, needle_len);
- return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
- (const unsigned char *) needle, needle_len);
-}
-
-#undef LONG_NEEDLE_THRESHOLD
+/* Copyright (C) 1991-1994, 1996-1998, 2000, 2004, 2007-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* This particular implementation was written by Eric Blake, 2008. */
+
+#ifndef _LIBC
+# include <config.h>
+#endif
+
+/* Specification of strstr. */
+#include <string.h>
+
+#include <stdbool.h>
+
+#ifndef _LIBC
+# define __builtin_expect(expr, val) (expr)
+#endif
+
+#define RETURN_TYPE char *
+#define AVAILABLE(h, h_l, j, n_l) \
+ (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
+ && ((h_l) = (j) + (n_l)))
+#include "str-two-way.h"
+
+/* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK
+ if NEEDLE is empty, otherwise NULL if NEEDLE is not found in
+ HAYSTACK. */
+char *
+strstr (const char *haystack_start, const char *needle_start)
+{
+ const char *haystack = haystack_start;
+ const char *needle = needle_start;
+ size_t needle_len; /* Length of NEEDLE. */
+ size_t haystack_len; /* Known minimum length of HAYSTACK. */
+ bool ok = true; /* True if NEEDLE is prefix of HAYSTACK. */
+
+ /* Determine length of NEEDLE, and in the process, make sure
+ HAYSTACK is at least as long (no point processing all of a long
+ NEEDLE if HAYSTACK is too short). */
+ while (*haystack && *needle)
+ ok &= *haystack++ == *needle++;
+ if (*needle)
+ return NULL;
+ if (ok)
+ return (char *) haystack_start;
+
+ /* Reduce the size of haystack using strchr, since it has a smaller
+ linear coefficient than the Two-Way algorithm. */
+ needle_len = needle - needle_start;
+ haystack = strchr (haystack_start + 1, *needle_start);
+ if (!haystack || __builtin_expect (needle_len == 1, 0))
+ return (char *) haystack;
+ needle -= needle_len;
+ haystack_len = (haystack > haystack_start + needle_len ? 1
+ : needle_len + haystack_start - haystack);
+
+ /* Perform the search. Abstract memory is considered to be an array
+ of 'unsigned char' values, not an array of 'char' values. See
+ ISO C 99 section 6.2.6.1. */
+ if (needle_len < LONG_NEEDLE_THRESHOLD)
+ return two_way_short_needle ((const unsigned char *) haystack,
+ haystack_len,
+ (const unsigned char *) needle, needle_len);
+ return two_way_long_needle ((const unsigned char *) haystack, haystack_len,
+ (const unsigned char *) needle, needle_len);
+}
+
+#undef LONG_NEEDLE_THRESHOLD
diff --git a/contrib/tools/bison/gnulib/src/strtol.c b/contrib/tools/bison/gnulib/src/strtol.c
index 2962505554..20f980615f 100644
--- a/contrib/tools/bison/gnulib/src/strtol.c
+++ b/contrib/tools/bison/gnulib/src/strtol.c
@@ -1,433 +1,433 @@
-/* Convert string representation of a number into an integer value.
-
- Copyright (C) 1991-1992, 1994-1999, 2003, 2005-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- NOTE: The canonical source of this file is maintained with the GNU C
- Library. Bugs can be reported to bug-glibc@gnu.org.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or any
- later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifdef _LIBC
-# define USE_NUMBER_GROUPING
-#else
-# include <config.h>
-#endif
-
-#include <ctype.h>
-#include <errno.h>
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
-
-#include <limits.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef USE_NUMBER_GROUPING
-# include "../locale/localeinfo.h"
-#endif
-
-/* Nonzero if we are defining 'strtoul' or 'strtoull', operating on
- unsigned integers. */
-#ifndef UNSIGNED
-# define UNSIGNED 0
-# define INT LONG int
-#else
-# define INT unsigned LONG int
-#endif
-
-/* Determine the name. */
-#ifdef USE_IN_EXTENDED_LOCALE_MODEL
-# if UNSIGNED
-# ifdef USE_WIDE_CHAR
-# ifdef QUAD
-# define strtol __wcstoull_l
-# else
-# define strtol __wcstoul_l
-# endif
-# else
-# ifdef QUAD
-# define strtol __strtoull_l
-# else
-# define strtol __strtoul_l
-# endif
-# endif
-# else
-# ifdef USE_WIDE_CHAR
-# ifdef QUAD
-# define strtol __wcstoll_l
-# else
-# define strtol __wcstol_l
-# endif
-# else
-# ifdef QUAD
-# define strtol __strtoll_l
-# else
-# define strtol __strtol_l
-# endif
-# endif
-# endif
-#else
-# if UNSIGNED
-# ifdef USE_WIDE_CHAR
-# ifdef QUAD
-# define strtol wcstoull
-# else
-# define strtol wcstoul
-# endif
-# else
-# ifdef QUAD
-# define strtol strtoull
-# else
-# define strtol strtoul
-# endif
-# endif
-# else
-# ifdef USE_WIDE_CHAR
-# ifdef QUAD
-# define strtol wcstoll
-# else
-# define strtol wcstol
-# endif
-# else
-# ifdef QUAD
-# define strtol strtoll
-# endif
-# endif
-# endif
-#endif
-
-/* If QUAD is defined, we are defining 'strtoll' or 'strtoull',
- operating on 'long long int's. */
-#ifdef QUAD
-# define LONG long long
-# define STRTOL_LONG_MIN LLONG_MIN
-# define STRTOL_LONG_MAX LLONG_MAX
-# define STRTOL_ULONG_MAX ULLONG_MAX
-
-/* The extra casts in the following macros work around compiler bugs,
- e.g., in Cray C 5.0.3.0. */
-
-/* True if negative values of the signed integer type T use two's
- complement, ones' complement, or signed magnitude representation,
- respectively. Much GNU code assumes two's complement, but some
- people like to be portable to all possible C hosts. */
-# define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
-# define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
-# define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
-
-/* True if the arithmetic type T is signed. */
-# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
-
-/* The maximum and minimum values for the integer type T. These
- macros have undefined behavior if T is signed and has padding bits.
- If this is a problem for you, please let us know how to fix it for
- your host. */
-# define TYPE_MINIMUM(t) \
- ((t) (! TYPE_SIGNED (t) \
- ? (t) 0 \
- : TYPE_SIGNED_MAGNITUDE (t) \
- ? ~ (t) 0 \
- : ~ TYPE_MAXIMUM (t)))
-# define TYPE_MAXIMUM(t) \
- ((t) (! TYPE_SIGNED (t) \
- ? (t) -1 \
- : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
-
-# ifndef ULLONG_MAX
-# define ULLONG_MAX TYPE_MAXIMUM (unsigned long long)
-# endif
-# ifndef LLONG_MAX
-# define LLONG_MAX TYPE_MAXIMUM (long long int)
-# endif
-# ifndef LLONG_MIN
-# define LLONG_MIN TYPE_MINIMUM (long long int)
-# endif
-
-# if __GNUC__ == 2 && __GNUC_MINOR__ < 7
- /* Work around gcc bug with using this constant. */
- static const unsigned long long int maxquad = ULLONG_MAX;
-# undef STRTOL_ULONG_MAX
-# define STRTOL_ULONG_MAX maxquad
-# endif
-#else
-# define LONG long
-# define STRTOL_LONG_MIN LONG_MIN
-# define STRTOL_LONG_MAX LONG_MAX
-# define STRTOL_ULONG_MAX ULONG_MAX
-#endif
-
-
-/* We use this code also for the extended locale handling where the
- function gets as an additional argument the locale which has to be
- used. To access the values we have to redefine the _NL_CURRENT
- macro. */
-#ifdef USE_IN_EXTENDED_LOCALE_MODEL
-# undef _NL_CURRENT
-# define _NL_CURRENT(category, item) \
- (current->values[_NL_ITEM_INDEX (item)].string)
-# define LOCALE_PARAM , loc
-# define LOCALE_PARAM_PROTO , __locale_t loc
-#else
-# define LOCALE_PARAM
-# define LOCALE_PARAM_PROTO
-#endif
-
-#ifdef USE_WIDE_CHAR
-# include <wchar.h>
-# include <wctype.h>
-# define L_(Ch) L##Ch
-# define UCHAR_TYPE wint_t
-# define STRING_TYPE wchar_t
-# ifdef USE_IN_EXTENDED_LOCALE_MODEL
-# define ISSPACE(Ch) __iswspace_l ((Ch), loc)
-# define ISALPHA(Ch) __iswalpha_l ((Ch), loc)
-# define TOUPPER(Ch) __towupper_l ((Ch), loc)
-# else
-# define ISSPACE(Ch) iswspace (Ch)
-# define ISALPHA(Ch) iswalpha (Ch)
-# define TOUPPER(Ch) towupper (Ch)
-# endif
-#else
-# define L_(Ch) Ch
-# define UCHAR_TYPE unsigned char
-# define STRING_TYPE char
-# ifdef USE_IN_EXTENDED_LOCALE_MODEL
-# define ISSPACE(Ch) __isspace_l ((Ch), loc)
-# define ISALPHA(Ch) __isalpha_l ((Ch), loc)
-# define TOUPPER(Ch) __toupper_l ((Ch), loc)
-# else
-# define ISSPACE(Ch) isspace (Ch)
-# define ISALPHA(Ch) isalpha (Ch)
-# define TOUPPER(Ch) toupper (Ch)
-# endif
-#endif
-
-#define INTERNAL(X) INTERNAL1(X)
-#define INTERNAL1(X) __##X##_internal
-#define WEAKNAME(X) WEAKNAME1(X)
-
-#ifdef USE_NUMBER_GROUPING
-/* This file defines a function to check for correct grouping. */
-# include "grouping.h"
-#endif
-
-
-
-/* Convert NPTR to an 'unsigned long int' or 'long int' in base BASE.
- If BASE is 0 the base is determined by the presence of a leading
- zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal.
- If BASE is < 2 or > 36, it is reset to 10.
- If ENDPTR is not NULL, a pointer to the character after the last
- one converted is stored in *ENDPTR. */
-
-INT
-INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
- int base, int group LOCALE_PARAM_PROTO)
-{
- int negative;
+/* Convert string representation of a number into an integer value.
+
+ Copyright (C) 1991-1992, 1994-1999, 2003, 2005-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ NOTE: The canonical source of this file is maintained with the GNU C
+ Library. Bugs can be reported to bug-glibc@gnu.org.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef _LIBC
+# define USE_NUMBER_GROUPING
+#else
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+#ifndef __set_errno
+# define __set_errno(Val) errno = (Val)
+#endif
+
+#include <limits.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef USE_NUMBER_GROUPING
+# include "../locale/localeinfo.h"
+#endif
+
+/* Nonzero if we are defining 'strtoul' or 'strtoull', operating on
+ unsigned integers. */
+#ifndef UNSIGNED
+# define UNSIGNED 0
+# define INT LONG int
+#else
+# define INT unsigned LONG int
+#endif
+
+/* Determine the name. */
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# if UNSIGNED
+# ifdef USE_WIDE_CHAR
+# ifdef QUAD
+# define strtol __wcstoull_l
+# else
+# define strtol __wcstoul_l
+# endif
+# else
+# ifdef QUAD
+# define strtol __strtoull_l
+# else
+# define strtol __strtoul_l
+# endif
+# endif
+# else
+# ifdef USE_WIDE_CHAR
+# ifdef QUAD
+# define strtol __wcstoll_l
+# else
+# define strtol __wcstol_l
+# endif
+# else
+# ifdef QUAD
+# define strtol __strtoll_l
+# else
+# define strtol __strtol_l
+# endif
+# endif
+# endif
+#else
+# if UNSIGNED
+# ifdef USE_WIDE_CHAR
+# ifdef QUAD
+# define strtol wcstoull
+# else
+# define strtol wcstoul
+# endif
+# else
+# ifdef QUAD
+# define strtol strtoull
+# else
+# define strtol strtoul
+# endif
+# endif
+# else
+# ifdef USE_WIDE_CHAR
+# ifdef QUAD
+# define strtol wcstoll
+# else
+# define strtol wcstol
+# endif
+# else
+# ifdef QUAD
+# define strtol strtoll
+# endif
+# endif
+# endif
+#endif
+
+/* If QUAD is defined, we are defining 'strtoll' or 'strtoull',
+ operating on 'long long int's. */
+#ifdef QUAD
+# define LONG long long
+# define STRTOL_LONG_MIN LLONG_MIN
+# define STRTOL_LONG_MAX LLONG_MAX
+# define STRTOL_ULONG_MAX ULLONG_MAX
+
+/* The extra casts in the following macros work around compiler bugs,
+ e.g., in Cray C 5.0.3.0. */
+
+/* True if negative values of the signed integer type T use two's
+ complement, ones' complement, or signed magnitude representation,
+ respectively. Much GNU code assumes two's complement, but some
+ people like to be portable to all possible C hosts. */
+# define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
+# define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
+# define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
+
+/* True if the arithmetic type T is signed. */
+# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* The maximum and minimum values for the integer type T. These
+ macros have undefined behavior if T is signed and has padding bits.
+ If this is a problem for you, please let us know how to fix it for
+ your host. */
+# define TYPE_MINIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) 0 \
+ : TYPE_SIGNED_MAGNITUDE (t) \
+ ? ~ (t) 0 \
+ : ~ TYPE_MAXIMUM (t)))
+# define TYPE_MAXIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) -1 \
+ : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
+
+# ifndef ULLONG_MAX
+# define ULLONG_MAX TYPE_MAXIMUM (unsigned long long)
+# endif
+# ifndef LLONG_MAX
+# define LLONG_MAX TYPE_MAXIMUM (long long int)
+# endif
+# ifndef LLONG_MIN
+# define LLONG_MIN TYPE_MINIMUM (long long int)
+# endif
+
+# if __GNUC__ == 2 && __GNUC_MINOR__ < 7
+ /* Work around gcc bug with using this constant. */
+ static const unsigned long long int maxquad = ULLONG_MAX;
+# undef STRTOL_ULONG_MAX
+# define STRTOL_ULONG_MAX maxquad
+# endif
+#else
+# define LONG long
+# define STRTOL_LONG_MIN LONG_MIN
+# define STRTOL_LONG_MAX LONG_MAX
+# define STRTOL_ULONG_MAX ULONG_MAX
+#endif
+
+
+/* We use this code also for the extended locale handling where the
+ function gets as an additional argument the locale which has to be
+ used. To access the values we have to redefine the _NL_CURRENT
+ macro. */
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# undef _NL_CURRENT
+# define _NL_CURRENT(category, item) \
+ (current->values[_NL_ITEM_INDEX (item)].string)
+# define LOCALE_PARAM , loc
+# define LOCALE_PARAM_PROTO , __locale_t loc
+#else
+# define LOCALE_PARAM
+# define LOCALE_PARAM_PROTO
+#endif
+
+#ifdef USE_WIDE_CHAR
+# include <wchar.h>
+# include <wctype.h>
+# define L_(Ch) L##Ch
+# define UCHAR_TYPE wint_t
+# define STRING_TYPE wchar_t
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# define ISSPACE(Ch) __iswspace_l ((Ch), loc)
+# define ISALPHA(Ch) __iswalpha_l ((Ch), loc)
+# define TOUPPER(Ch) __towupper_l ((Ch), loc)
+# else
+# define ISSPACE(Ch) iswspace (Ch)
+# define ISALPHA(Ch) iswalpha (Ch)
+# define TOUPPER(Ch) towupper (Ch)
+# endif
+#else
+# define L_(Ch) Ch
+# define UCHAR_TYPE unsigned char
+# define STRING_TYPE char
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# define ISSPACE(Ch) __isspace_l ((Ch), loc)
+# define ISALPHA(Ch) __isalpha_l ((Ch), loc)
+# define TOUPPER(Ch) __toupper_l ((Ch), loc)
+# else
+# define ISSPACE(Ch) isspace (Ch)
+# define ISALPHA(Ch) isalpha (Ch)
+# define TOUPPER(Ch) toupper (Ch)
+# endif
+#endif
+
+#define INTERNAL(X) INTERNAL1(X)
+#define INTERNAL1(X) __##X##_internal
+#define WEAKNAME(X) WEAKNAME1(X)
+
+#ifdef USE_NUMBER_GROUPING
+/* This file defines a function to check for correct grouping. */
+# include "grouping.h"
+#endif
+
+
+
+/* Convert NPTR to an 'unsigned long int' or 'long int' in base BASE.
+ If BASE is 0 the base is determined by the presence of a leading
+ zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal.
+ If BASE is < 2 or > 36, it is reset to 10.
+ If ENDPTR is not NULL, a pointer to the character after the last
+ one converted is stored in *ENDPTR. */
+
+INT
+INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
+ int base, int group LOCALE_PARAM_PROTO)
+{
+ int negative;
unsigned LONG int cutoff;
unsigned int cutlim;
unsigned LONG int i;
const STRING_TYPE *s;
UCHAR_TYPE c;
- const STRING_TYPE *save, *end;
- int overflow;
-
-#ifdef USE_NUMBER_GROUPING
-# ifdef USE_IN_EXTENDED_LOCALE_MODEL
- struct locale_data *current = loc->__locales[LC_NUMERIC];
-# endif
- /* The thousands character of the current locale. */
- wchar_t thousands = L'\0';
- /* The numeric grouping specification of the current locale,
- in the format described in <locale.h>. */
- const char *grouping;
-
- if (group)
- {
- grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
- if (*grouping <= 0 || *grouping == CHAR_MAX)
- grouping = NULL;
- else
- {
- /* Figure out the thousands separator character. */
-# if defined _LIBC || defined _HAVE_BTOWC
- thousands = __btowc (*_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP));
- if (thousands == WEOF)
- thousands = L'\0';
-# endif
- if (thousands == L'\0')
- grouping = NULL;
- }
- }
- else
- grouping = NULL;
-#endif
-
- if (base < 0 || base == 1 || base > 36)
- {
- __set_errno (EINVAL);
- return 0;
- }
-
- save = s = nptr;
-
- /* Skip white space. */
- while (ISSPACE (*s))
- ++s;
- if (*s == L_('\0'))
- goto noconv;
-
- /* Check for a sign. */
- if (*s == L_('-'))
- {
- negative = 1;
- ++s;
- }
- else if (*s == L_('+'))
- {
- negative = 0;
- ++s;
- }
- else
- negative = 0;
-
- /* Recognize number prefix and if BASE is zero, figure it out ourselves. */
- if (*s == L_('0'))
- {
- if ((base == 0 || base == 16) && TOUPPER (s[1]) == L_('X'))
- {
- s += 2;
- base = 16;
- }
- else if (base == 0)
- base = 8;
- }
- else if (base == 0)
- base = 10;
-
- /* Save the pointer so we can check later if anything happened. */
- save = s;
-
-#ifdef USE_NUMBER_GROUPING
- if (group)
- {
- /* Find the end of the digit string and check its grouping. */
- end = s;
- for (c = *end; c != L_('\0'); c = *++end)
- if ((wchar_t) c != thousands
- && ((wchar_t) c < L_('0') || (wchar_t) c > L_('9'))
- && (!ISALPHA (c) || (int) (TOUPPER (c) - L_('A') + 10) >= base))
- break;
- if (*s == thousands)
- end = s;
- else
- end = correctly_grouped_prefix (s, end, thousands, grouping);
- }
- else
-#endif
- end = NULL;
-
- cutoff = STRTOL_ULONG_MAX / (unsigned LONG int) base;
- cutlim = STRTOL_ULONG_MAX % (unsigned LONG int) base;
-
- overflow = 0;
- i = 0;
- for (c = *s; c != L_('\0'); c = *++s)
- {
- if (s == end)
- break;
- if (c >= L_('0') && c <= L_('9'))
- c -= L_('0');
- else if (ISALPHA (c))
- c = TOUPPER (c) - L_('A') + 10;
- else
- break;
- if ((int) c >= base)
- break;
- /* Check for overflow. */
- if (i > cutoff || (i == cutoff && c > cutlim))
- overflow = 1;
- else
- {
- i *= (unsigned LONG int) base;
- i += c;
- }
- }
-
- /* Check if anything actually happened. */
- if (s == save)
- goto noconv;
-
- /* Store in ENDPTR the address of one character
- past the last character we converted. */
- if (endptr != NULL)
- *endptr = (STRING_TYPE *) s;
-
-#if !UNSIGNED
- /* Check for a value that is within the range of
- 'unsigned LONG int', but outside the range of 'LONG int'. */
- if (overflow == 0
- && i > (negative
- ? -((unsigned LONG int) (STRTOL_LONG_MIN + 1)) + 1
- : (unsigned LONG int) STRTOL_LONG_MAX))
- overflow = 1;
-#endif
-
- if (overflow)
- {
- __set_errno (ERANGE);
-#if UNSIGNED
- return STRTOL_ULONG_MAX;
-#else
- return negative ? STRTOL_LONG_MIN : STRTOL_LONG_MAX;
-#endif
- }
-
- /* Return the result of the appropriate sign. */
- return negative ? -i : i;
-
-noconv:
- /* We must handle a special case here: the base is 0 or 16 and the
- first two characters are '0' and 'x', but the rest are no
- hexadecimal digits. This is no error case. We return 0 and
- ENDPTR points to the 'x'. */
- if (endptr != NULL)
- {
- if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X')
- && save[-2] == L_('0'))
- *endptr = (STRING_TYPE *) &save[-1];
- else
- /* There was no number to convert. */
- *endptr = (STRING_TYPE *) nptr;
- }
-
- return 0L;
-}
-
-/* External user entry point. */
-
-
-INT
-#ifdef weak_function
-weak_function
-#endif
-strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr,
- int base LOCALE_PARAM_PROTO)
-{
- return INTERNAL (strtol) (nptr, endptr, base, 0 LOCALE_PARAM);
-}
+ const STRING_TYPE *save, *end;
+ int overflow;
+
+#ifdef USE_NUMBER_GROUPING
+# ifdef USE_IN_EXTENDED_LOCALE_MODEL
+ struct locale_data *current = loc->__locales[LC_NUMERIC];
+# endif
+ /* The thousands character of the current locale. */
+ wchar_t thousands = L'\0';
+ /* The numeric grouping specification of the current locale,
+ in the format described in <locale.h>. */
+ const char *grouping;
+
+ if (group)
+ {
+ grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
+ if (*grouping <= 0 || *grouping == CHAR_MAX)
+ grouping = NULL;
+ else
+ {
+ /* Figure out the thousands separator character. */
+# if defined _LIBC || defined _HAVE_BTOWC
+ thousands = __btowc (*_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP));
+ if (thousands == WEOF)
+ thousands = L'\0';
+# endif
+ if (thousands == L'\0')
+ grouping = NULL;
+ }
+ }
+ else
+ grouping = NULL;
+#endif
+
+ if (base < 0 || base == 1 || base > 36)
+ {
+ __set_errno (EINVAL);
+ return 0;
+ }
+
+ save = s = nptr;
+
+ /* Skip white space. */
+ while (ISSPACE (*s))
+ ++s;
+ if (*s == L_('\0'))
+ goto noconv;
+
+ /* Check for a sign. */
+ if (*s == L_('-'))
+ {
+ negative = 1;
+ ++s;
+ }
+ else if (*s == L_('+'))
+ {
+ negative = 0;
+ ++s;
+ }
+ else
+ negative = 0;
+
+ /* Recognize number prefix and if BASE is zero, figure it out ourselves. */
+ if (*s == L_('0'))
+ {
+ if ((base == 0 || base == 16) && TOUPPER (s[1]) == L_('X'))
+ {
+ s += 2;
+ base = 16;
+ }
+ else if (base == 0)
+ base = 8;
+ }
+ else if (base == 0)
+ base = 10;
+
+ /* Save the pointer so we can check later if anything happened. */
+ save = s;
+
+#ifdef USE_NUMBER_GROUPING
+ if (group)
+ {
+ /* Find the end of the digit string and check its grouping. */
+ end = s;
+ for (c = *end; c != L_('\0'); c = *++end)
+ if ((wchar_t) c != thousands
+ && ((wchar_t) c < L_('0') || (wchar_t) c > L_('9'))
+ && (!ISALPHA (c) || (int) (TOUPPER (c) - L_('A') + 10) >= base))
+ break;
+ if (*s == thousands)
+ end = s;
+ else
+ end = correctly_grouped_prefix (s, end, thousands, grouping);
+ }
+ else
+#endif
+ end = NULL;
+
+ cutoff = STRTOL_ULONG_MAX / (unsigned LONG int) base;
+ cutlim = STRTOL_ULONG_MAX % (unsigned LONG int) base;
+
+ overflow = 0;
+ i = 0;
+ for (c = *s; c != L_('\0'); c = *++s)
+ {
+ if (s == end)
+ break;
+ if (c >= L_('0') && c <= L_('9'))
+ c -= L_('0');
+ else if (ISALPHA (c))
+ c = TOUPPER (c) - L_('A') + 10;
+ else
+ break;
+ if ((int) c >= base)
+ break;
+ /* Check for overflow. */
+ if (i > cutoff || (i == cutoff && c > cutlim))
+ overflow = 1;
+ else
+ {
+ i *= (unsigned LONG int) base;
+ i += c;
+ }
+ }
+
+ /* Check if anything actually happened. */
+ if (s == save)
+ goto noconv;
+
+ /* Store in ENDPTR the address of one character
+ past the last character we converted. */
+ if (endptr != NULL)
+ *endptr = (STRING_TYPE *) s;
+
+#if !UNSIGNED
+ /* Check for a value that is within the range of
+ 'unsigned LONG int', but outside the range of 'LONG int'. */
+ if (overflow == 0
+ && i > (negative
+ ? -((unsigned LONG int) (STRTOL_LONG_MIN + 1)) + 1
+ : (unsigned LONG int) STRTOL_LONG_MAX))
+ overflow = 1;
+#endif
+
+ if (overflow)
+ {
+ __set_errno (ERANGE);
+#if UNSIGNED
+ return STRTOL_ULONG_MAX;
+#else
+ return negative ? STRTOL_LONG_MIN : STRTOL_LONG_MAX;
+#endif
+ }
+
+ /* Return the result of the appropriate sign. */
+ return negative ? -i : i;
+
+noconv:
+ /* We must handle a special case here: the base is 0 or 16 and the
+ first two characters are '0' and 'x', but the rest are no
+ hexadecimal digits. This is no error case. We return 0 and
+ ENDPTR points to the 'x'. */
+ if (endptr != NULL)
+ {
+ if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X')
+ && save[-2] == L_('0'))
+ *endptr = (STRING_TYPE *) &save[-1];
+ else
+ /* There was no number to convert. */
+ *endptr = (STRING_TYPE *) nptr;
+ }
+
+ return 0L;
+}
+
+/* External user entry point. */
+
+
+INT
+#ifdef weak_function
+weak_function
+#endif
+strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr,
+ int base LOCALE_PARAM_PROTO)
+{
+ return INTERNAL (strtol) (nptr, endptr, base, 0 LOCALE_PARAM);
+}
diff --git a/contrib/tools/bison/gnulib/src/strtoul.c b/contrib/tools/bison/gnulib/src/strtoul.c
index a0ca376cda..2922411717 100644
--- a/contrib/tools/bison/gnulib/src/strtoul.c
+++ b/contrib/tools/bison/gnulib/src/strtoul.c
@@ -1,19 +1,19 @@
-/* Copyright (C) 1991, 1997, 2009-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#define UNSIGNED 1
-
-#include "strtol.c"
+/* Copyright (C) 1991, 1997, 2009-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#define UNSIGNED 1
+
+#include "strtol.c"
diff --git a/contrib/tools/bison/gnulib/src/strverscmp.c b/contrib/tools/bison/gnulib/src/strverscmp.c
index db4f1edc70..ec0066af27 100644
--- a/contrib/tools/bison/gnulib/src/strverscmp.c
+++ b/contrib/tools/bison/gnulib/src/strverscmp.c
@@ -1,131 +1,131 @@
-/* Compare strings while treating digits characters numerically.
- Copyright (C) 1997, 2000, 2002, 2004, 2006, 2009-2013 Free Software
- Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#if !_LIBC
-# include <config.h>
-#endif
-
-#include <string.h>
-#include <ctype.h>
-
-/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
- fractional parts, S_Z: idem but with leading Zeroes only */
-#define S_N 0x0
-#define S_I 0x4
-#define S_F 0x8
-#define S_Z 0xC
-
-/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
-#define CMP 2
-#define LEN 3
-
-
-/* ISDIGIT differs from isdigit, as follows:
- - Its arg may be any int or unsigned int; it need not be an unsigned char
- or EOF.
- - It's typically faster.
- POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
- isdigit unless it's important to use the locale's definition
- of "digit" even when the host does not conform to POSIX. */
-#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
-
-#undef __strverscmp
-#undef strverscmp
-
-#ifndef weak_alias
-# define __strverscmp strverscmp
-#endif
-
-/* Compare S1 and S2 as strings holding indices/version numbers,
- returning less than, equal to or greater than zero if S1 is less than,
- equal to or greater than S2 (for more info, see the texinfo doc).
-*/
-
-int
-__strverscmp (const char *s1, const char *s2)
-{
- const unsigned char *p1 = (const unsigned char *) s1;
- const unsigned char *p2 = (const unsigned char *) s2;
- unsigned char c1, c2;
- int state;
- int diff;
-
- /* Symbol(s) 0 [1-9] others (padding)
- Transition (10) 0 (01) d (00) x (11) - */
- static const unsigned int next_state[] =
- {
- /* state x d 0 - */
- /* S_N */ S_N, S_I, S_Z, S_N,
- /* S_I */ S_N, S_I, S_I, S_I,
- /* S_F */ S_N, S_F, S_F, S_F,
- /* S_Z */ S_N, S_F, S_Z, S_Z
- };
-
- static const int result_type[] =
- {
- /* state x/x x/d x/0 x/- d/x d/d d/0 d/-
- 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
-
- /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
- CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
- /* S_I */ CMP, -1, -1, CMP, 1, LEN, LEN, CMP,
- 1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
- /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
- CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
- /* S_Z */ CMP, 1, 1, CMP, -1, CMP, CMP, CMP,
- -1, CMP, CMP, CMP
- };
-
- if (p1 == p2)
- return 0;
-
- c1 = *p1++;
- c2 = *p2++;
- /* Hint: '0' is a digit too. */
- state = S_N | ((c1 == '0') + (ISDIGIT (c1) != 0));
-
- while ((diff = c1 - c2) == 0 && c1 != '\0')
- {
- state = next_state[state];
- c1 = *p1++;
- c2 = *p2++;
- state |= (c1 == '0') + (ISDIGIT (c1) != 0);
- }
-
- state = result_type[state << 2 | ((c2 == '0') + (ISDIGIT (c2) != 0))];
-
- switch (state)
- {
- case CMP:
- return diff;
-
- case LEN:
- while (ISDIGIT (*p1++))
- if (!ISDIGIT (*p2++))
- return 1;
-
- return ISDIGIT (*p2) ? -1 : diff;
-
- default:
- return state;
- }
-}
-#ifdef weak_alias
-weak_alias (__strverscmp, strverscmp)
-#endif
+/* Compare strings while treating digits characters numerically.
+ Copyright (C) 1997, 2000, 2002, 2004, 2006, 2009-2013 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#if !_LIBC
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <ctype.h>
+
+/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
+ fractional parts, S_Z: idem but with leading Zeroes only */
+#define S_N 0x0
+#define S_I 0x4
+#define S_F 0x8
+#define S_Z 0xC
+
+/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
+#define CMP 2
+#define LEN 3
+
+
+/* ISDIGIT differs from isdigit, as follows:
+ - Its arg may be any int or unsigned int; it need not be an unsigned char
+ or EOF.
+ - It's typically faster.
+ POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
+ isdigit unless it's important to use the locale's definition
+ of "digit" even when the host does not conform to POSIX. */
+#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
+
+#undef __strverscmp
+#undef strverscmp
+
+#ifndef weak_alias
+# define __strverscmp strverscmp
+#endif
+
+/* Compare S1 and S2 as strings holding indices/version numbers,
+ returning less than, equal to or greater than zero if S1 is less than,
+ equal to or greater than S2 (for more info, see the texinfo doc).
+*/
+
+int
+__strverscmp (const char *s1, const char *s2)
+{
+ const unsigned char *p1 = (const unsigned char *) s1;
+ const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+ int state;
+ int diff;
+
+ /* Symbol(s) 0 [1-9] others (padding)
+ Transition (10) 0 (01) d (00) x (11) - */
+ static const unsigned int next_state[] =
+ {
+ /* state x d 0 - */
+ /* S_N */ S_N, S_I, S_Z, S_N,
+ /* S_I */ S_N, S_I, S_I, S_I,
+ /* S_F */ S_N, S_F, S_F, S_F,
+ /* S_Z */ S_N, S_F, S_Z, S_Z
+ };
+
+ static const int result_type[] =
+ {
+ /* state x/x x/d x/0 x/- d/x d/d d/0 d/-
+ 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
+
+ /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+ /* S_I */ CMP, -1, -1, CMP, 1, LEN, LEN, CMP,
+ 1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
+ /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
+ CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
+ /* S_Z */ CMP, 1, 1, CMP, -1, CMP, CMP, CMP,
+ -1, CMP, CMP, CMP
+ };
+
+ if (p1 == p2)
+ return 0;
+
+ c1 = *p1++;
+ c2 = *p2++;
+ /* Hint: '0' is a digit too. */
+ state = S_N | ((c1 == '0') + (ISDIGIT (c1) != 0));
+
+ while ((diff = c1 - c2) == 0 && c1 != '\0')
+ {
+ state = next_state[state];
+ c1 = *p1++;
+ c2 = *p2++;
+ state |= (c1 == '0') + (ISDIGIT (c1) != 0);
+ }
+
+ state = result_type[state << 2 | ((c2 == '0') + (ISDIGIT (c2) != 0))];
+
+ switch (state)
+ {
+ case CMP:
+ return diff;
+
+ case LEN:
+ while (ISDIGIT (*p1++))
+ if (!ISDIGIT (*p2++))
+ return 1;
+
+ return ISDIGIT (*p2) ? -1 : diff;
+
+ default:
+ return state;
+ }
+}
+#ifdef weak_alias
+weak_alias (__strverscmp, strverscmp)
+#endif
diff --git a/contrib/tools/bison/gnulib/src/tempname.c b/contrib/tools/bison/gnulib/src/tempname.c
index 9975449a89..baad8984d8 100644
--- a/contrib/tools/bison/gnulib/src/tempname.c
+++ b/contrib/tools/bison/gnulib/src/tempname.c
@@ -1,306 +1,306 @@
-/* tempname.c - generate the name of a temporary file.
-
- Copyright (C) 1991-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Extracted from glibc sysdeps/posix/tempname.c. See also tmpdir.c. */
-
-#if !_LIBC
-# include <config.h>
-# include "tempname.h"
-#endif
-
-#include <sys/types.h>
-#include <assert.h>
-
-#include <errno.h>
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
-
-#include <stdio.h>
-#ifndef P_tmpdir
-# define P_tmpdir "/tmp"
-#endif
-#ifndef TMP_MAX
-# define TMP_MAX 238328
-#endif
-#ifndef __GT_FILE
-# define __GT_FILE 0
-# define __GT_DIR 1
-# define __GT_NOCREATE 2
-#endif
-#if !_LIBC && (GT_FILE != __GT_FILE || GT_DIR != __GT_DIR \
- || GT_NOCREATE != __GT_NOCREATE)
-# error report this to bug-gnulib@gnu.org
-#endif
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <fcntl.h>
-#include <sys/time.h>
-#include <stdint.h>
+/* tempname.c - generate the name of a temporary file.
+
+ Copyright (C) 1991-2003, 2005-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Extracted from glibc sysdeps/posix/tempname.c. See also tmpdir.c. */
+
+#if !_LIBC
+# include <config.h>
+# include "tempname.h"
+#endif
+
+#include <sys/types.h>
+#include <assert.h>
+
+#include <errno.h>
+#ifndef __set_errno
+# define __set_errno(Val) errno = (Val)
+#endif
+
+#include <stdio.h>
+#ifndef P_tmpdir
+# define P_tmpdir "/tmp"
+#endif
+#ifndef TMP_MAX
+# define TMP_MAX 238328
+#endif
+#ifndef __GT_FILE
+# define __GT_FILE 0
+# define __GT_DIR 1
+# define __GT_NOCREATE 2
+#endif
+#if !_LIBC && (GT_FILE != __GT_FILE || GT_DIR != __GT_DIR \
+ || GT_NOCREATE != __GT_NOCREATE)
+# error report this to bug-gnulib@gnu.org
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fcntl.h>
+#include <sys/time.h>
+#include <stdint.h>
#include "unistd--.h"
-
-#include <sys/stat.h>
-
-#if _LIBC
-# define struct_stat64 struct stat64
-#else
-# define struct_stat64 struct stat
-# define __gen_tempname gen_tempname
-# define __getpid getpid
-# define __gettimeofday gettimeofday
-# define __mkdir mkdir
-# define __open open
-# define __lxstat64(version, file, buf) lstat (file, buf)
-# define __secure_getenv secure_getenv
-#endif
-
-#ifdef _LIBC
-# include <hp-timing.h>
-# if HP_TIMING_AVAIL
-# define RANDOM_BITS(Var) \
- if (__builtin_expect (value == UINT64_C (0), 0)) \
- { \
- /* If this is the first time this function is used initialize \
- the variable we accumulate the value in to some somewhat \
- random value. If we'd not do this programs at startup time \
- might have a reduced set of possible names, at least on slow \
- machines. */ \
- struct timeval tv; \
- __gettimeofday (&tv, NULL); \
- value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; \
- } \
- HP_TIMING_NOW (Var)
-# endif
-#endif
-
-/* Use the widest available unsigned type if uint64_t is not
- available. The algorithm below extracts a number less than 62**6
- (approximately 2**35.725) from uint64_t, so ancient hosts where
- uintmax_t is only 32 bits lose about 3.725 bits of randomness,
- which is better than not having mkstemp at all. */
-#if !defined UINT64_MAX && !defined uint64_t
-# define uint64_t uintmax_t
-#endif
-
-#if _LIBC
-/* Return nonzero if DIR is an existent directory. */
-static int
-direxists (const char *dir)
-{
- struct_stat64 buf;
- return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
-}
-
-/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
- non-null and exists, uses it; otherwise uses the first of $TMPDIR,
- P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
- for use with mk[s]temp. Will fail (-1) if DIR is non-null and
- doesn't exist, none of the searched dirs exists, or there's not
- enough space in TMPL. */
-int
-__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
- int try_tmpdir)
-{
- const char *d;
- size_t dlen, plen;
-
- if (!pfx || !pfx[0])
- {
- pfx = "file";
- plen = 4;
- }
- else
- {
- plen = strlen (pfx);
- if (plen > 5)
- plen = 5;
- }
-
- if (try_tmpdir)
- {
- d = __secure_getenv ("TMPDIR");
- if (d != NULL && direxists (d))
- dir = d;
- else if (dir != NULL && direxists (dir))
- /* nothing */ ;
- else
- dir = NULL;
- }
- if (dir == NULL)
- {
- if (direxists (P_tmpdir))
- dir = P_tmpdir;
- else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
- dir = "/tmp";
- else
- {
- __set_errno (ENOENT);
- return -1;
- }
- }
-
- dlen = strlen (dir);
- while (dlen > 1 && dir[dlen - 1] == '/')
- dlen--; /* remove trailing slashes */
-
- /* check we have room for "${dir}/${pfx}XXXXXX\0" */
- if (tmpl_len < dlen + 1 + plen + 6 + 1)
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx);
- return 0;
-}
-#endif /* _LIBC */
-
-/* These are the characters used in temporary file names. */
-static const char letters[] =
-"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-
-/* Generate a temporary file name based on TMPL. TMPL must match the
- rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
- The name constructed does not exist at the time of the call to
- __gen_tempname. TMPL is overwritten with the result.
-
- KIND may be one of:
- __GT_NOCREATE: simply verify that the name does not exist
- at the time of the call.
- __GT_FILE: create the file using open(O_CREAT|O_EXCL)
- and return a read-write fd. The file is mode 0600.
- __GT_DIR: create a directory, which will be mode 0700.
-
- We use a clever algorithm to get hard-to-predict names. */
-int
-__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
-{
- int len;
- char *XXXXXX;
- static uint64_t value;
- uint64_t random_time_bits;
- unsigned int count;
- int fd = -1;
- int save_errno = errno;
- struct_stat64 st;
-
- /* A lower bound on the number of temporary files to attempt to
- generate. The maximum total number of temporary file names that
- can exist for a given template is 62**6. It should never be
- necessary to try all of these combinations. Instead if a reasonable
- number of names is tried (we define reasonable as 62**3) fail to
- give the system administrator the chance to remove the problems. */
-#define ATTEMPTS_MIN (62 * 62 * 62)
-
- /* The number of times to attempt to generate a temporary file. To
- conform to POSIX, this must be no smaller than TMP_MAX. */
-#if ATTEMPTS_MIN < TMP_MAX
- unsigned int attempts = TMP_MAX;
-#else
- unsigned int attempts = ATTEMPTS_MIN;
-#endif
-
- len = strlen (tmpl);
- if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6))
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- /* This is where the Xs start. */
- XXXXXX = &tmpl[len - 6 - suffixlen];
-
- /* Get some more or less random data. */
-#ifdef RANDOM_BITS
- RANDOM_BITS (random_time_bits);
-#else
- {
- struct timeval tv;
- __gettimeofday (&tv, NULL);
- random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
- }
-#endif
- value += random_time_bits ^ __getpid ();
-
- for (count = 0; count < attempts; value += 7777, ++count)
- {
- uint64_t v = value;
-
- /* Fill in the random bits. */
- XXXXXX[0] = letters[v % 62];
- v /= 62;
- XXXXXX[1] = letters[v % 62];
- v /= 62;
- XXXXXX[2] = letters[v % 62];
- v /= 62;
- XXXXXX[3] = letters[v % 62];
- v /= 62;
- XXXXXX[4] = letters[v % 62];
- v /= 62;
- XXXXXX[5] = letters[v % 62];
-
- switch (kind)
- {
- case __GT_FILE:
- fd = __open (tmpl,
- (flags & ~O_ACCMODE)
- | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
- break;
-
- case __GT_DIR:
- fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
- break;
-
- case __GT_NOCREATE:
- /* This case is backward from the other three. __gen_tempname
- succeeds if __xstat fails because the name does not exist.
- Note the continue to bypass the common logic at the bottom
- of the loop. */
- if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
- {
- if (errno == ENOENT)
- {
- __set_errno (save_errno);
- return 0;
- }
- else
- /* Give up now. */
- return -1;
- }
- continue;
-
- default:
- assert (! "invalid KIND in __gen_tempname");
- abort ();
- }
-
- if (fd >= 0)
- {
- __set_errno (save_errno);
- return fd;
- }
- else if (errno != EEXIST)
- return -1;
- }
-
- /* We got out of the loop because we ran out of combinations to try. */
- __set_errno (EEXIST);
- return -1;
-}
+
+#include <sys/stat.h>
+
+#if _LIBC
+# define struct_stat64 struct stat64
+#else
+# define struct_stat64 struct stat
+# define __gen_tempname gen_tempname
+# define __getpid getpid
+# define __gettimeofday gettimeofday
+# define __mkdir mkdir
+# define __open open
+# define __lxstat64(version, file, buf) lstat (file, buf)
+# define __secure_getenv secure_getenv
+#endif
+
+#ifdef _LIBC
+# include <hp-timing.h>
+# if HP_TIMING_AVAIL
+# define RANDOM_BITS(Var) \
+ if (__builtin_expect (value == UINT64_C (0), 0)) \
+ { \
+ /* If this is the first time this function is used initialize \
+ the variable we accumulate the value in to some somewhat \
+ random value. If we'd not do this programs at startup time \
+ might have a reduced set of possible names, at least on slow \
+ machines. */ \
+ struct timeval tv; \
+ __gettimeofday (&tv, NULL); \
+ value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; \
+ } \
+ HP_TIMING_NOW (Var)
+# endif
+#endif
+
+/* Use the widest available unsigned type if uint64_t is not
+ available. The algorithm below extracts a number less than 62**6
+ (approximately 2**35.725) from uint64_t, so ancient hosts where
+ uintmax_t is only 32 bits lose about 3.725 bits of randomness,
+ which is better than not having mkstemp at all. */
+#if !defined UINT64_MAX && !defined uint64_t
+# define uint64_t uintmax_t
+#endif
+
+#if _LIBC
+/* Return nonzero if DIR is an existent directory. */
+static int
+direxists (const char *dir)
+{
+ struct_stat64 buf;
+ return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
+}
+
+/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
+ non-null and exists, uses it; otherwise uses the first of $TMPDIR,
+ P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
+ for use with mk[s]temp. Will fail (-1) if DIR is non-null and
+ doesn't exist, none of the searched dirs exists, or there's not
+ enough space in TMPL. */
+int
+__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
+ int try_tmpdir)
+{
+ const char *d;
+ size_t dlen, plen;
+
+ if (!pfx || !pfx[0])
+ {
+ pfx = "file";
+ plen = 4;
+ }
+ else
+ {
+ plen = strlen (pfx);
+ if (plen > 5)
+ plen = 5;
+ }
+
+ if (try_tmpdir)
+ {
+ d = __secure_getenv ("TMPDIR");
+ if (d != NULL && direxists (d))
+ dir = d;
+ else if (dir != NULL && direxists (dir))
+ /* nothing */ ;
+ else
+ dir = NULL;
+ }
+ if (dir == NULL)
+ {
+ if (direxists (P_tmpdir))
+ dir = P_tmpdir;
+ else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
+ dir = "/tmp";
+ else
+ {
+ __set_errno (ENOENT);
+ return -1;
+ }
+ }
+
+ dlen = strlen (dir);
+ while (dlen > 1 && dir[dlen - 1] == '/')
+ dlen--; /* remove trailing slashes */
+
+ /* check we have room for "${dir}/${pfx}XXXXXX\0" */
+ if (tmpl_len < dlen + 1 + plen + 6 + 1)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx);
+ return 0;
+}
+#endif /* _LIBC */
+
+/* These are the characters used in temporary file names. */
+static const char letters[] =
+"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+
+/* Generate a temporary file name based on TMPL. TMPL must match the
+ rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
+ The name constructed does not exist at the time of the call to
+ __gen_tempname. TMPL is overwritten with the result.
+
+ KIND may be one of:
+ __GT_NOCREATE: simply verify that the name does not exist
+ at the time of the call.
+ __GT_FILE: create the file using open(O_CREAT|O_EXCL)
+ and return a read-write fd. The file is mode 0600.
+ __GT_DIR: create a directory, which will be mode 0700.
+
+ We use a clever algorithm to get hard-to-predict names. */
+int
+__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
+{
+ int len;
+ char *XXXXXX;
+ static uint64_t value;
+ uint64_t random_time_bits;
+ unsigned int count;
+ int fd = -1;
+ int save_errno = errno;
+ struct_stat64 st;
+
+ /* A lower bound on the number of temporary files to attempt to
+ generate. The maximum total number of temporary file names that
+ can exist for a given template is 62**6. It should never be
+ necessary to try all of these combinations. Instead if a reasonable
+ number of names is tried (we define reasonable as 62**3) fail to
+ give the system administrator the chance to remove the problems. */
+#define ATTEMPTS_MIN (62 * 62 * 62)
+
+ /* The number of times to attempt to generate a temporary file. To
+ conform to POSIX, this must be no smaller than TMP_MAX. */
+#if ATTEMPTS_MIN < TMP_MAX
+ unsigned int attempts = TMP_MAX;
+#else
+ unsigned int attempts = ATTEMPTS_MIN;
+#endif
+
+ len = strlen (tmpl);
+ if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6))
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ /* This is where the Xs start. */
+ XXXXXX = &tmpl[len - 6 - suffixlen];
+
+ /* Get some more or less random data. */
+#ifdef RANDOM_BITS
+ RANDOM_BITS (random_time_bits);
+#else
+ {
+ struct timeval tv;
+ __gettimeofday (&tv, NULL);
+ random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
+ }
+#endif
+ value += random_time_bits ^ __getpid ();
+
+ for (count = 0; count < attempts; value += 7777, ++count)
+ {
+ uint64_t v = value;
+
+ /* Fill in the random bits. */
+ XXXXXX[0] = letters[v % 62];
+ v /= 62;
+ XXXXXX[1] = letters[v % 62];
+ v /= 62;
+ XXXXXX[2] = letters[v % 62];
+ v /= 62;
+ XXXXXX[3] = letters[v % 62];
+ v /= 62;
+ XXXXXX[4] = letters[v % 62];
+ v /= 62;
+ XXXXXX[5] = letters[v % 62];
+
+ switch (kind)
+ {
+ case __GT_FILE:
+ fd = __open (tmpl,
+ (flags & ~O_ACCMODE)
+ | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+ break;
+
+ case __GT_DIR:
+ fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
+ break;
+
+ case __GT_NOCREATE:
+ /* This case is backward from the other three. __gen_tempname
+ succeeds if __xstat fails because the name does not exist.
+ Note the continue to bypass the common logic at the bottom
+ of the loop. */
+ if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
+ {
+ if (errno == ENOENT)
+ {
+ __set_errno (save_errno);
+ return 0;
+ }
+ else
+ /* Give up now. */
+ return -1;
+ }
+ continue;
+
+ default:
+ assert (! "invalid KIND in __gen_tempname");
+ abort ();
+ }
+
+ if (fd >= 0)
+ {
+ __set_errno (save_errno);
+ return fd;
+ }
+ else if (errno != EEXIST)
+ return -1;
+ }
+
+ /* We got out of the loop because we ran out of combinations to try. */
+ __set_errno (EEXIST);
+ return -1;
+}
diff --git a/contrib/tools/bison/gnulib/src/tempname.h b/contrib/tools/bison/gnulib/src/tempname.h
index 333267dfd0..1920661b41 100644
--- a/contrib/tools/bison/gnulib/src/tempname.h
+++ b/contrib/tools/bison/gnulib/src/tempname.h
@@ -1,50 +1,50 @@
-/* Create a temporary file or directory.
-
- Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* header written by Eric Blake */
-
-#ifndef GL_TEMPNAME_H
-# define GL_TEMPNAME_H
-
-# include <stdio.h>
-
-# ifdef __GT_FILE
-# define GT_FILE __GT_FILE
-# define GT_DIR __GT_DIR
-# define GT_NOCREATE __GT_NOCREATE
-# else
-# define GT_FILE 0
-# define GT_DIR 1
-# define GT_NOCREATE 2
-# endif
-
-/* Generate a temporary file name based on TMPL. TMPL must match the
- rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
- The name constructed does not exist at the time of the call to
- gen_tempname. TMPL is overwritten with the result.
-
- KIND may be one of:
- GT_NOCREATE: simply verify that the name does not exist
- at the time of the call.
- GT_FILE: create a large file using open(O_CREAT|O_EXCL)
- and return a read-write fd. The file is mode 0600.
- GT_DIR: create a directory, which will be mode 0700.
-
- We use a clever algorithm to get hard-to-predict names. */
-extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
-
-#endif /* GL_TEMPNAME_H */
+/* Create a temporary file or directory.
+
+ Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* header written by Eric Blake */
+
+#ifndef GL_TEMPNAME_H
+# define GL_TEMPNAME_H
+
+# include <stdio.h>
+
+# ifdef __GT_FILE
+# define GT_FILE __GT_FILE
+# define GT_DIR __GT_DIR
+# define GT_NOCREATE __GT_NOCREATE
+# else
+# define GT_FILE 0
+# define GT_DIR 1
+# define GT_NOCREATE 2
+# endif
+
+/* Generate a temporary file name based on TMPL. TMPL must match the
+ rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
+ The name constructed does not exist at the time of the call to
+ gen_tempname. TMPL is overwritten with the result.
+
+ KIND may be one of:
+ GT_NOCREATE: simply verify that the name does not exist
+ at the time of the call.
+ GT_FILE: create a large file using open(O_CREAT|O_EXCL)
+ and return a read-write fd. The file is mode 0600.
+ GT_DIR: create a directory, which will be mode 0700.
+
+ We use a clever algorithm to get hard-to-predict names. */
+extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
+
+#endif /* GL_TEMPNAME_H */
diff --git a/contrib/tools/bison/gnulib/src/timevar.c b/contrib/tools/bison/gnulib/src/timevar.c
index a9dbdbdee5..53301e7058 100644
--- a/contrib/tools/bison/gnulib/src/timevar.c
+++ b/contrib/tools/bison/gnulib/src/timevar.c
@@ -1,571 +1,571 @@
-/* Timing variables for measuring compiler performance.
-
- Copyright (C) 2000, 2002, 2004, 2006, 2009-2013 Free Software
- Foundation, Inc.
-
- Contributed by Alex Samuel <samuel@codesourcery.com>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#if IN_GCC
-
-#include "system.h"
-#include "intl.h"
-#include "rtl.h"
-
-#else
-
+/* Timing variables for measuring compiler performance.
+
+ Copyright (C) 2000, 2002, 2004, 2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ Contributed by Alex Samuel <samuel@codesourcery.com>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#if IN_GCC
+
+#include "system.h"
+#include "intl.h"
+#include "rtl.h"
+
+#else
+
#if defined(_musl_)
#define HAVE_SYS_TIMES_H 1
#define HAVE_STRUCT_TMS 1
#define HAVE_CLOCK_T 1
#endif
-/* This source file is taken from the GCC source code, with slight
- modifications that are under control of the IN_GCC preprocessor
- variable. The !IN_GCC part of this file is specific to Bison. */
-
-# include "bison-system.h"
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# endif
-int timevar_report = 0;
-
-#endif
-
-
-#ifdef HAVE_SYS_TIMES_H
-# include <sys/times.h>
-#endif
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-
-#ifndef HAVE_CLOCK_T
-typedef int clock_t;
-#endif
-
-#ifndef HAVE_STRUCT_TMS
-struct tms
-{
- clock_t tms_utime;
- clock_t tms_stime;
- clock_t tms_cutime;
- clock_t tms_cstime;
-};
-#endif
-
-#if defined HAVE_DECL_GETRUSAGE && !HAVE_DECL_GETRUSAGE
-extern int getrusage (int, struct rusage *);
-#endif
-#if defined HAVE_DECL_TIMES && !HAVE_DECL_TIMES
-extern clock_t times (struct tms *);
-#endif
-#if defined HAVE_DECL_CLOCK && !HAVE_DECL_CLOCK
-extern clock_t clock (void);
-#endif
-
-#ifndef RUSAGE_SELF
-# define RUSAGE_SELF 0
-#endif
-
-/* Calculation of scale factor to convert ticks to microseconds.
- We mustn't use CLOCKS_PER_SEC except with clock(). */
-#if HAVE_SYSCONF && defined _SC_CLK_TCK
-# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
-#else
-# ifdef CLK_TCK
-# define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
-# else
-# ifdef HZ
-# define TICKS_PER_SECOND HZ /* traditional UNIX */
-# else
-# define TICKS_PER_SECOND 100 /* often the correct value */
-# endif
-# endif
-#endif
-
-/* Prefer times to getrusage to clock (each gives successively less
- information). */
-#ifdef HAVE_TIMES
-# define USE_TIMES
-# define HAVE_USER_TIME
-# define HAVE_SYS_TIME
-# define HAVE_WALL_TIME
-#else
-#ifdef HAVE_GETRUSAGE
-# define USE_GETRUSAGE
-# define HAVE_USER_TIME
-# define HAVE_SYS_TIME
-#else
-#ifdef HAVE_CLOCK
-# define USE_CLOCK
-# define HAVE_USER_TIME
-#endif
-#endif
-#endif
-
-/* libc is very likely to have snuck a call to sysconf() into one of
- the underlying constants, and that can be very slow, so we have to
- precompute them. Whose wonderful idea was it to make all those
- _constants_ variable at run time, anyway? */
-#ifdef USE_TIMES
-static float ticks_to_msec;
-#define TICKS_TO_MSEC (1.0 / TICKS_PER_SECOND)
-#endif
-
-#ifdef USE_CLOCK
-static float clocks_to_msec;
-#define CLOCKS_TO_MSEC (1.0 / CLOCKS_PER_SEC)
-#endif
-
-#if IN_GCC
-#include "flags.h"
-#endif
-#include "timevar.h"
-
-/* See timevar.h for an explanation of timing variables. */
-
-/* This macro evaluates to nonzero if timing variables are enabled. */
-#define TIMEVAR_ENABLE (timevar_report)
-
-/* A timing variable. */
-
-struct timevar_def
-{
- /* Elapsed time for this variable. */
- struct timevar_time_def elapsed;
-
- /* If this variable is timed independently of the timing stack,
- using timevar_start, this contains the start time. */
- struct timevar_time_def start_time;
-
- /* The name of this timing variable. */
- const char *name;
-
- /* Non-zero if this timing variable is running as a standalone
- timer. */
- unsigned standalone : 1;
-
- /* Non-zero if this timing variable was ever started or pushed onto
- the timing stack. */
- unsigned used : 1;
-};
-
-/* An element on the timing stack. Elapsed time is attributed to the
- topmost timing variable on the stack. */
-
-struct timevar_stack_def
-{
- /* The timing variable at this stack level. */
- struct timevar_def *timevar;
-
- /* The next lower timing variable context in the stack. */
- struct timevar_stack_def *next;
-};
-
-/* Declared timing variables. Constructed from the contents of
- timevar.def. */
-static struct timevar_def timevars[TIMEVAR_LAST];
-
-/* The top of the timing stack. */
-static struct timevar_stack_def *stack;
-
-/* A list of unused (i.e. allocated and subsequently popped)
- timevar_stack_def instances. */
-static struct timevar_stack_def *unused_stack_instances;
-
-/* The time at which the topmost element on the timing stack was
- pushed. Time elapsed since then is attributed to the topmost
- element. */
-static struct timevar_time_def start_time;
-
-static void get_time (struct timevar_time_def *);
-static void timevar_accumulate (struct timevar_time_def *,
- struct timevar_time_def *,
- struct timevar_time_def *);
-
-/* Fill the current times into TIME. The definition of this function
- also defines any or all of the HAVE_USER_TIME, HAVE_SYS_TIME, and
- HAVE_WALL_TIME macros. */
-
-static void
-get_time (now)
- struct timevar_time_def *now;
-{
- now->user = 0;
- now->sys = 0;
- now->wall = 0;
-
- if (!TIMEVAR_ENABLE)
- return;
-
- {
-#ifdef USE_TIMES
- struct tms tms;
- now->wall = times (&tms) * ticks_to_msec;
-#if IN_GCC
- now->user = tms.tms_utime * ticks_to_msec;
- now->sys = tms.tms_stime * ticks_to_msec;
-#else
- now->user = (tms.tms_utime + tms.tms_cutime) * ticks_to_msec;
- now->sys = (tms.tms_stime + tms.tms_cstime) * ticks_to_msec;
-#endif
-#endif
-#ifdef USE_GETRUSAGE
- struct rusage rusage;
-#if IN_GCC
- getrusage (RUSAGE_SELF, &rusage);
-#else
- getrusage (RUSAGE_CHILDREN, &rusage);
-#endif
- now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
- now->sys = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
-#endif
-#ifdef USE_CLOCK
- now->user = clock () * clocks_to_msec;
-#endif
- }
-}
-
-/* Add the difference between STOP and START to TIMER. */
-
-static void
-timevar_accumulate (timer, start, stop)
- struct timevar_time_def *timer;
- struct timevar_time_def *start;
- struct timevar_time_def *stop;
-{
- timer->user += stop->user - start->user;
- timer->sys += stop->sys - start->sys;
- timer->wall += stop->wall - start->wall;
-}
-
-/* Initialize timing variables. */
-
-void
-init_timevar ()
-{
- if (!TIMEVAR_ENABLE)
- return;
-
- /* Zero all elapsed times. */
- memset ((void *) timevars, 0, sizeof (timevars));
-
- /* Initialize the names of timing variables. */
-#define DEFTIMEVAR(identifier__, name__) \
- timevars[identifier__].name = name__;
-#include "timevar.def"
-#undef DEFTIMEVAR
-
-#ifdef USE_TIMES
- ticks_to_msec = TICKS_TO_MSEC;
-#endif
-#ifdef USE_CLOCK
- clocks_to_msec = CLOCKS_TO_MSEC;
-#endif
-}
-
-/* Push TIMEVAR onto the timing stack. No further elapsed time is
- attributed to the previous topmost timing variable on the stack;
- subsequent elapsed time is attributed to TIMEVAR, until it is
- popped or another element is pushed on top.
-
- TIMEVAR cannot be running as a standalone timer. */
-
-void
-timevar_push (timevar)
- timevar_id_t timevar;
-{
- struct timevar_def *tv = &timevars[timevar];
- struct timevar_stack_def *context;
- struct timevar_time_def now;
-
- if (!TIMEVAR_ENABLE)
- return;
-
- /* Mark this timing variable as used. */
- tv->used = 1;
-
- /* Can't push a standalone timer. */
- if (tv->standalone)
- abort ();
-
- /* What time is it? */
- get_time (&now);
-
- /* If the stack isn't empty, attribute the current elapsed time to
- the old topmost element. */
- if (stack)
- timevar_accumulate (&stack->timevar->elapsed, &start_time, &now);
-
- /* Reset the start time; from now on, time is attributed to
- TIMEVAR. */
- start_time = now;
-
- /* See if we have a previously-allocated stack instance. If so,
- take it off the list. If not, malloc a new one. */
- if (unused_stack_instances != NULL)
- {
- context = unused_stack_instances;
- unused_stack_instances = unused_stack_instances->next;
- }
- else
- context = (struct timevar_stack_def *)
- xmalloc (sizeof (struct timevar_stack_def));
-
- /* Fill it in and put it on the stack. */
- context->timevar = tv;
- context->next = stack;
- stack = context;
-}
-
-/* Pop the topmost timing variable element off the timing stack. The
- popped variable must be TIMEVAR. Elapsed time since the that
- element was pushed on, or since it was last exposed on top of the
- stack when the element above it was popped off, is credited to that
- timing variable. */
-
-void
-timevar_pop (timevar)
- timevar_id_t timevar;
-{
- struct timevar_time_def now;
- struct timevar_stack_def *popped = stack;
-
- if (!TIMEVAR_ENABLE)
- return;
-
- if (&timevars[timevar] != stack->timevar)
- abort ();
-
- /* What time is it? */
- get_time (&now);
-
- /* Attribute the elapsed time to the element we're popping. */
- timevar_accumulate (&popped->timevar->elapsed, &start_time, &now);
-
- /* Reset the start time; from now on, time is attributed to the
- element just exposed on the stack. */
- start_time = now;
-
- /* Take the item off the stack. */
- stack = stack->next;
-
- /* Don't delete the stack element; instead, add it to the list of
- unused elements for later use. */
- popped->next = unused_stack_instances;
- unused_stack_instances = popped;
-}
-
-/* Start timing TIMEVAR independently of the timing stack. Elapsed
- time until timevar_stop is called for the same timing variable is
- attributed to TIMEVAR. */
-
-void
-timevar_start (timevar)
- timevar_id_t timevar;
-{
- struct timevar_def *tv = &timevars[timevar];
-
- if (!TIMEVAR_ENABLE)
- return;
-
- /* Mark this timing variable as used. */
- tv->used = 1;
-
- /* Don't allow the same timing variable to be started more than
- once. */
- if (tv->standalone)
- abort ();
- tv->standalone = 1;
-
- get_time (&tv->start_time);
-}
-
-/* Stop timing TIMEVAR. Time elapsed since timevar_start was called
- is attributed to it. */
-
-void
-timevar_stop (timevar)
- timevar_id_t timevar;
-{
- struct timevar_def *tv = &timevars[timevar];
- struct timevar_time_def now;
-
- if (!TIMEVAR_ENABLE)
- return;
-
- /* TIMEVAR must have been started via timevar_start. */
- if (!tv->standalone)
- abort ();
-
- get_time (&now);
- timevar_accumulate (&tv->elapsed, &tv->start_time, &now);
-}
-
-/* Fill the elapsed time for TIMEVAR into ELAPSED. Returns
- update-to-date information even if TIMEVAR is currently running. */
-
-void
-timevar_get (timevar, elapsed)
- timevar_id_t timevar;
- struct timevar_time_def *elapsed;
-{
- struct timevar_def *tv = &timevars[timevar];
- struct timevar_time_def now;
-
- *elapsed = tv->elapsed;
-
- /* Is TIMEVAR currently running as a standalone timer? */
- if (tv->standalone)
- {
- get_time (&now);
- timevar_accumulate (elapsed, &tv->start_time, &now);
- }
- /* Or is TIMEVAR at the top of the timer stack? */
- else if (stack->timevar == tv)
- {
- get_time (&now);
- timevar_accumulate (elapsed, &start_time, &now);
- }
-}
-
-/* Summarize timing variables to FP. The timing variable TV_TOTAL has
- a special meaning -- it's considered to be the total elapsed time,
- for normalizing the others, and is displayed last. */
-
-void
-timevar_print (fp)
- FILE *fp;
-{
- /* Only print stuff if we have some sort of time information. */
-#if defined HAVE_USER_TIME || defined HAVE_SYS_TIME || defined HAVE_WALL_TIME
- unsigned int /* timevar_id_t */ id;
- struct timevar_time_def *total = &timevars[TV_TOTAL].elapsed;
- struct timevar_time_def now;
-
- if (!TIMEVAR_ENABLE)
- return;
-
- /* Update timing information in case we're calling this from GDB. */
-
- if (fp == 0)
- fp = stderr;
-
- /* What time is it? */
- get_time (&now);
-
- /* If the stack isn't empty, attribute the current elapsed time to
- the old topmost element. */
- if (stack)
- timevar_accumulate (&stack->timevar->elapsed, &start_time, &now);
-
- /* Reset the start time; from now on, time is attributed to
- TIMEVAR. */
- start_time = now;
-
- fputs (_("\nExecution times (seconds)\n"), fp);
- for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
- {
- struct timevar_def *tv = &timevars[(timevar_id_t) id];
- const float tiny = 5e-3;
-
- /* Don't print the total execution time here; that goes at the
- end. */
- if ((timevar_id_t) id == TV_TOTAL)
- continue;
-
- /* Don't print timing variables that were never used. */
- if (!tv->used)
- continue;
-
- /* Don't print timing variables if we're going to get a row of
- zeroes. */
- if (tv->elapsed.user < tiny
- && tv->elapsed.sys < tiny
- && tv->elapsed.wall < tiny)
- continue;
-
- /* The timing variable name. */
- fprintf (fp, " %-22s:", tv->name);
-
-#ifdef HAVE_USER_TIME
- /* Print user-mode time for this process. */
- fprintf (fp, "%7.2f (%2.0f%%) usr",
- tv->elapsed.user,
- (total->user == 0 ? 0 : tv->elapsed.user / total->user) * 100);
-#endif /* HAVE_USER_TIME */
-
-#ifdef HAVE_SYS_TIME
- /* Print system-mode time for this process. */
- fprintf (fp, "%7.2f (%2.0f%%) sys",
- tv->elapsed.sys,
- (total->sys == 0 ? 0 : tv->elapsed.sys / total->sys) * 100);
-#endif /* HAVE_SYS_TIME */
-
-#ifdef HAVE_WALL_TIME
- /* Print wall clock time elapsed. */
- fprintf (fp, "%7.2f (%2.0f%%) wall",
- tv->elapsed.wall,
- (total->wall == 0 ? 0 : tv->elapsed.wall / total->wall) * 100);
-#endif /* HAVE_WALL_TIME */
-
- putc ('\n', fp);
- }
-
- /* Print total time. */
- fputs (_(" TOTAL :"), fp);
-#ifdef HAVE_USER_TIME
- fprintf (fp, "%7.2f ", total->user);
-#endif
-#ifdef HAVE_SYS_TIME
- fprintf (fp, "%7.2f ", total->sys);
-#endif
-#ifdef HAVE_WALL_TIME
- fprintf (fp, "%7.2f\n", total->wall);
-#endif
-
-#endif /* defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME)
- || defined (HAVE_WALL_TIME) */
-}
-
-/* Returns time (user + system) used so far by the compiler process,
- in microseconds. */
-
-long
-get_run_time ()
-{
- struct timevar_time_def total_elapsed;
- timevar_get (TV_TOTAL, &total_elapsed);
- return total_elapsed.user + total_elapsed.sys;
-}
-
-/* Prints a message to stderr stating that time elapsed in STR is
- TOTAL (given in microseconds). */
-
-void
-print_time (str, total)
- const char *str;
- long total;
-{
- long all_time = get_run_time ();
- fprintf (stderr,
- _("time in %s: %ld.%06ld (%ld%%)\n"),
- str, total / 1000000, total % 1000000,
- all_time == 0 ? 0
- : (long) (((100.0 * (double) total) / (double) all_time) + .5));
-}
+/* This source file is taken from the GCC source code, with slight
+ modifications that are under control of the IN_GCC preprocessor
+ variable. The !IN_GCC part of this file is specific to Bison. */
+
+# include "bison-system.h"
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# endif
+int timevar_report = 0;
+
+#endif
+
+
+#ifdef HAVE_SYS_TIMES_H
+# include <sys/times.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
+#ifndef HAVE_CLOCK_T
+typedef int clock_t;
+#endif
+
+#ifndef HAVE_STRUCT_TMS
+struct tms
+{
+ clock_t tms_utime;
+ clock_t tms_stime;
+ clock_t tms_cutime;
+ clock_t tms_cstime;
+};
+#endif
+
+#if defined HAVE_DECL_GETRUSAGE && !HAVE_DECL_GETRUSAGE
+extern int getrusage (int, struct rusage *);
+#endif
+#if defined HAVE_DECL_TIMES && !HAVE_DECL_TIMES
+extern clock_t times (struct tms *);
+#endif
+#if defined HAVE_DECL_CLOCK && !HAVE_DECL_CLOCK
+extern clock_t clock (void);
+#endif
+
+#ifndef RUSAGE_SELF
+# define RUSAGE_SELF 0
+#endif
+
+/* Calculation of scale factor to convert ticks to microseconds.
+ We mustn't use CLOCKS_PER_SEC except with clock(). */
+#if HAVE_SYSCONF && defined _SC_CLK_TCK
+# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
+#else
+# ifdef CLK_TCK
+# define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
+# else
+# ifdef HZ
+# define TICKS_PER_SECOND HZ /* traditional UNIX */
+# else
+# define TICKS_PER_SECOND 100 /* often the correct value */
+# endif
+# endif
+#endif
+
+/* Prefer times to getrusage to clock (each gives successively less
+ information). */
+#ifdef HAVE_TIMES
+# define USE_TIMES
+# define HAVE_USER_TIME
+# define HAVE_SYS_TIME
+# define HAVE_WALL_TIME
+#else
+#ifdef HAVE_GETRUSAGE
+# define USE_GETRUSAGE
+# define HAVE_USER_TIME
+# define HAVE_SYS_TIME
+#else
+#ifdef HAVE_CLOCK
+# define USE_CLOCK
+# define HAVE_USER_TIME
+#endif
+#endif
+#endif
+
+/* libc is very likely to have snuck a call to sysconf() into one of
+ the underlying constants, and that can be very slow, so we have to
+ precompute them. Whose wonderful idea was it to make all those
+ _constants_ variable at run time, anyway? */
+#ifdef USE_TIMES
+static float ticks_to_msec;
+#define TICKS_TO_MSEC (1.0 / TICKS_PER_SECOND)
+#endif
+
+#ifdef USE_CLOCK
+static float clocks_to_msec;
+#define CLOCKS_TO_MSEC (1.0 / CLOCKS_PER_SEC)
+#endif
+
+#if IN_GCC
+#include "flags.h"
+#endif
+#include "timevar.h"
+
+/* See timevar.h for an explanation of timing variables. */
+
+/* This macro evaluates to nonzero if timing variables are enabled. */
+#define TIMEVAR_ENABLE (timevar_report)
+
+/* A timing variable. */
+
+struct timevar_def
+{
+ /* Elapsed time for this variable. */
+ struct timevar_time_def elapsed;
+
+ /* If this variable is timed independently of the timing stack,
+ using timevar_start, this contains the start time. */
+ struct timevar_time_def start_time;
+
+ /* The name of this timing variable. */
+ const char *name;
+
+ /* Non-zero if this timing variable is running as a standalone
+ timer. */
+ unsigned standalone : 1;
+
+ /* Non-zero if this timing variable was ever started or pushed onto
+ the timing stack. */
+ unsigned used : 1;
+};
+
+/* An element on the timing stack. Elapsed time is attributed to the
+ topmost timing variable on the stack. */
+
+struct timevar_stack_def
+{
+ /* The timing variable at this stack level. */
+ struct timevar_def *timevar;
+
+ /* The next lower timing variable context in the stack. */
+ struct timevar_stack_def *next;
+};
+
+/* Declared timing variables. Constructed from the contents of
+ timevar.def. */
+static struct timevar_def timevars[TIMEVAR_LAST];
+
+/* The top of the timing stack. */
+static struct timevar_stack_def *stack;
+
+/* A list of unused (i.e. allocated and subsequently popped)
+ timevar_stack_def instances. */
+static struct timevar_stack_def *unused_stack_instances;
+
+/* The time at which the topmost element on the timing stack was
+ pushed. Time elapsed since then is attributed to the topmost
+ element. */
+static struct timevar_time_def start_time;
+
+static void get_time (struct timevar_time_def *);
+static void timevar_accumulate (struct timevar_time_def *,
+ struct timevar_time_def *,
+ struct timevar_time_def *);
+
+/* Fill the current times into TIME. The definition of this function
+ also defines any or all of the HAVE_USER_TIME, HAVE_SYS_TIME, and
+ HAVE_WALL_TIME macros. */
+
+static void
+get_time (now)
+ struct timevar_time_def *now;
+{
+ now->user = 0;
+ now->sys = 0;
+ now->wall = 0;
+
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ {
+#ifdef USE_TIMES
+ struct tms tms;
+ now->wall = times (&tms) * ticks_to_msec;
+#if IN_GCC
+ now->user = tms.tms_utime * ticks_to_msec;
+ now->sys = tms.tms_stime * ticks_to_msec;
+#else
+ now->user = (tms.tms_utime + tms.tms_cutime) * ticks_to_msec;
+ now->sys = (tms.tms_stime + tms.tms_cstime) * ticks_to_msec;
+#endif
+#endif
+#ifdef USE_GETRUSAGE
+ struct rusage rusage;
+#if IN_GCC
+ getrusage (RUSAGE_SELF, &rusage);
+#else
+ getrusage (RUSAGE_CHILDREN, &rusage);
+#endif
+ now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
+ now->sys = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
+#endif
+#ifdef USE_CLOCK
+ now->user = clock () * clocks_to_msec;
+#endif
+ }
+}
+
+/* Add the difference between STOP and START to TIMER. */
+
+static void
+timevar_accumulate (timer, start, stop)
+ struct timevar_time_def *timer;
+ struct timevar_time_def *start;
+ struct timevar_time_def *stop;
+{
+ timer->user += stop->user - start->user;
+ timer->sys += stop->sys - start->sys;
+ timer->wall += stop->wall - start->wall;
+}
+
+/* Initialize timing variables. */
+
+void
+init_timevar ()
+{
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ /* Zero all elapsed times. */
+ memset ((void *) timevars, 0, sizeof (timevars));
+
+ /* Initialize the names of timing variables. */
+#define DEFTIMEVAR(identifier__, name__) \
+ timevars[identifier__].name = name__;
+#include "timevar.def"
+#undef DEFTIMEVAR
+
+#ifdef USE_TIMES
+ ticks_to_msec = TICKS_TO_MSEC;
+#endif
+#ifdef USE_CLOCK
+ clocks_to_msec = CLOCKS_TO_MSEC;
+#endif
+}
+
+/* Push TIMEVAR onto the timing stack. No further elapsed time is
+ attributed to the previous topmost timing variable on the stack;
+ subsequent elapsed time is attributed to TIMEVAR, until it is
+ popped or another element is pushed on top.
+
+ TIMEVAR cannot be running as a standalone timer. */
+
+void
+timevar_push (timevar)
+ timevar_id_t timevar;
+{
+ struct timevar_def *tv = &timevars[timevar];
+ struct timevar_stack_def *context;
+ struct timevar_time_def now;
+
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ /* Mark this timing variable as used. */
+ tv->used = 1;
+
+ /* Can't push a standalone timer. */
+ if (tv->standalone)
+ abort ();
+
+ /* What time is it? */
+ get_time (&now);
+
+ /* If the stack isn't empty, attribute the current elapsed time to
+ the old topmost element. */
+ if (stack)
+ timevar_accumulate (&stack->timevar->elapsed, &start_time, &now);
+
+ /* Reset the start time; from now on, time is attributed to
+ TIMEVAR. */
+ start_time = now;
+
+ /* See if we have a previously-allocated stack instance. If so,
+ take it off the list. If not, malloc a new one. */
+ if (unused_stack_instances != NULL)
+ {
+ context = unused_stack_instances;
+ unused_stack_instances = unused_stack_instances->next;
+ }
+ else
+ context = (struct timevar_stack_def *)
+ xmalloc (sizeof (struct timevar_stack_def));
+
+ /* Fill it in and put it on the stack. */
+ context->timevar = tv;
+ context->next = stack;
+ stack = context;
+}
+
+/* Pop the topmost timing variable element off the timing stack. The
+ popped variable must be TIMEVAR. Elapsed time since the that
+ element was pushed on, or since it was last exposed on top of the
+ stack when the element above it was popped off, is credited to that
+ timing variable. */
+
+void
+timevar_pop (timevar)
+ timevar_id_t timevar;
+{
+ struct timevar_time_def now;
+ struct timevar_stack_def *popped = stack;
+
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ if (&timevars[timevar] != stack->timevar)
+ abort ();
+
+ /* What time is it? */
+ get_time (&now);
+
+ /* Attribute the elapsed time to the element we're popping. */
+ timevar_accumulate (&popped->timevar->elapsed, &start_time, &now);
+
+ /* Reset the start time; from now on, time is attributed to the
+ element just exposed on the stack. */
+ start_time = now;
+
+ /* Take the item off the stack. */
+ stack = stack->next;
+
+ /* Don't delete the stack element; instead, add it to the list of
+ unused elements for later use. */
+ popped->next = unused_stack_instances;
+ unused_stack_instances = popped;
+}
+
+/* Start timing TIMEVAR independently of the timing stack. Elapsed
+ time until timevar_stop is called for the same timing variable is
+ attributed to TIMEVAR. */
+
+void
+timevar_start (timevar)
+ timevar_id_t timevar;
+{
+ struct timevar_def *tv = &timevars[timevar];
+
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ /* Mark this timing variable as used. */
+ tv->used = 1;
+
+ /* Don't allow the same timing variable to be started more than
+ once. */
+ if (tv->standalone)
+ abort ();
+ tv->standalone = 1;
+
+ get_time (&tv->start_time);
+}
+
+/* Stop timing TIMEVAR. Time elapsed since timevar_start was called
+ is attributed to it. */
+
+void
+timevar_stop (timevar)
+ timevar_id_t timevar;
+{
+ struct timevar_def *tv = &timevars[timevar];
+ struct timevar_time_def now;
+
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ /* TIMEVAR must have been started via timevar_start. */
+ if (!tv->standalone)
+ abort ();
+
+ get_time (&now);
+ timevar_accumulate (&tv->elapsed, &tv->start_time, &now);
+}
+
+/* Fill the elapsed time for TIMEVAR into ELAPSED. Returns
+ update-to-date information even if TIMEVAR is currently running. */
+
+void
+timevar_get (timevar, elapsed)
+ timevar_id_t timevar;
+ struct timevar_time_def *elapsed;
+{
+ struct timevar_def *tv = &timevars[timevar];
+ struct timevar_time_def now;
+
+ *elapsed = tv->elapsed;
+
+ /* Is TIMEVAR currently running as a standalone timer? */
+ if (tv->standalone)
+ {
+ get_time (&now);
+ timevar_accumulate (elapsed, &tv->start_time, &now);
+ }
+ /* Or is TIMEVAR at the top of the timer stack? */
+ else if (stack->timevar == tv)
+ {
+ get_time (&now);
+ timevar_accumulate (elapsed, &start_time, &now);
+ }
+}
+
+/* Summarize timing variables to FP. The timing variable TV_TOTAL has
+ a special meaning -- it's considered to be the total elapsed time,
+ for normalizing the others, and is displayed last. */
+
+void
+timevar_print (fp)
+ FILE *fp;
+{
+ /* Only print stuff if we have some sort of time information. */
+#if defined HAVE_USER_TIME || defined HAVE_SYS_TIME || defined HAVE_WALL_TIME
+ unsigned int /* timevar_id_t */ id;
+ struct timevar_time_def *total = &timevars[TV_TOTAL].elapsed;
+ struct timevar_time_def now;
+
+ if (!TIMEVAR_ENABLE)
+ return;
+
+ /* Update timing information in case we're calling this from GDB. */
+
+ if (fp == 0)
+ fp = stderr;
+
+ /* What time is it? */
+ get_time (&now);
+
+ /* If the stack isn't empty, attribute the current elapsed time to
+ the old topmost element. */
+ if (stack)
+ timevar_accumulate (&stack->timevar->elapsed, &start_time, &now);
+
+ /* Reset the start time; from now on, time is attributed to
+ TIMEVAR. */
+ start_time = now;
+
+ fputs (_("\nExecution times (seconds)\n"), fp);
+ for (id = 0; id < (unsigned int) TIMEVAR_LAST; ++id)
+ {
+ struct timevar_def *tv = &timevars[(timevar_id_t) id];
+ const float tiny = 5e-3;
+
+ /* Don't print the total execution time here; that goes at the
+ end. */
+ if ((timevar_id_t) id == TV_TOTAL)
+ continue;
+
+ /* Don't print timing variables that were never used. */
+ if (!tv->used)
+ continue;
+
+ /* Don't print timing variables if we're going to get a row of
+ zeroes. */
+ if (tv->elapsed.user < tiny
+ && tv->elapsed.sys < tiny
+ && tv->elapsed.wall < tiny)
+ continue;
+
+ /* The timing variable name. */
+ fprintf (fp, " %-22s:", tv->name);
+
+#ifdef HAVE_USER_TIME
+ /* Print user-mode time for this process. */
+ fprintf (fp, "%7.2f (%2.0f%%) usr",
+ tv->elapsed.user,
+ (total->user == 0 ? 0 : tv->elapsed.user / total->user) * 100);
+#endif /* HAVE_USER_TIME */
+
+#ifdef HAVE_SYS_TIME
+ /* Print system-mode time for this process. */
+ fprintf (fp, "%7.2f (%2.0f%%) sys",
+ tv->elapsed.sys,
+ (total->sys == 0 ? 0 : tv->elapsed.sys / total->sys) * 100);
+#endif /* HAVE_SYS_TIME */
+
+#ifdef HAVE_WALL_TIME
+ /* Print wall clock time elapsed. */
+ fprintf (fp, "%7.2f (%2.0f%%) wall",
+ tv->elapsed.wall,
+ (total->wall == 0 ? 0 : tv->elapsed.wall / total->wall) * 100);
+#endif /* HAVE_WALL_TIME */
+
+ putc ('\n', fp);
+ }
+
+ /* Print total time. */
+ fputs (_(" TOTAL :"), fp);
+#ifdef HAVE_USER_TIME
+ fprintf (fp, "%7.2f ", total->user);
+#endif
+#ifdef HAVE_SYS_TIME
+ fprintf (fp, "%7.2f ", total->sys);
+#endif
+#ifdef HAVE_WALL_TIME
+ fprintf (fp, "%7.2f\n", total->wall);
+#endif
+
+#endif /* defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME)
+ || defined (HAVE_WALL_TIME) */
+}
+
+/* Returns time (user + system) used so far by the compiler process,
+ in microseconds. */
+
+long
+get_run_time ()
+{
+ struct timevar_time_def total_elapsed;
+ timevar_get (TV_TOTAL, &total_elapsed);
+ return total_elapsed.user + total_elapsed.sys;
+}
+
+/* Prints a message to stderr stating that time elapsed in STR is
+ TOTAL (given in microseconds). */
+
+void
+print_time (str, total)
+ const char *str;
+ long total;
+{
+ long all_time = get_run_time ();
+ fprintf (stderr,
+ _("time in %s: %ld.%06ld (%ld%%)\n"),
+ str, total / 1000000, total % 1000000,
+ all_time == 0 ? 0
+ : (long) (((100.0 * (double) total) / (double) all_time) + .5));
+}
diff --git a/contrib/tools/bison/gnulib/src/timevar.def b/contrib/tools/bison/gnulib/src/timevar.def
index 484fe35f7b..89ef9740bf 100644
--- a/contrib/tools/bison/gnulib/src/timevar.def
+++ b/contrib/tools/bison/gnulib/src/timevar.def
@@ -1,61 +1,61 @@
-/* This file contains the definitions for timing variables used to -*- C -*-
- measure run-time performance of the compiler.
-
- Copyright (C) 2002, 2007, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Akim Demaille <akim@freefriends.org>.
-
- This file is part of Bison, the GNU Compiler Compiler.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* This file contains timing variable definitions, used by timevar.h
- and timevar.c.
-
- Syntax:
-
- DEFTIMEVAR (id, name)
-
- where ID is the enumeral value used to identify the timing
- variable, and NAME is a character string describing its purpose. */
-
-/* The total execution time. */
-DEFTIMEVAR (TV_TOTAL , "total time")
-
-/* Time spent in the reader. */
-DEFTIMEVAR (TV_READER , "reader")
-DEFTIMEVAR (TV_SCANNING , "scanner")
-DEFTIMEVAR (TV_PARSING , "parser")
-
-/* Time spent handling the grammar. */
-DEFTIMEVAR (TV_REDUCE , "reducing the grammar")
-DEFTIMEVAR (TV_SETS , "computing the sets")
-DEFTIMEVAR (TV_LR0 , "LR(0)")
-DEFTIMEVAR (TV_LALR , "LALR(1)")
-DEFTIMEVAR (TV_IELR_PHASE1 , "IELR(1) Phase 1")
-DEFTIMEVAR (TV_IELR_PHASE2 , "IELR(1) Phase 2")
-DEFTIMEVAR (TV_IELR_PHASE3 , "IELR(1) Phase 3")
-DEFTIMEVAR (TV_IELR_PHASE4 , "IELR(1) Phase 4")
-DEFTIMEVAR (TV_CONFLICTS , "conflicts")
-
-/* Time spent outputing results. */
-DEFTIMEVAR (TV_REPORT , "outputing report")
-DEFTIMEVAR (TV_GRAPH , "outputing graph")
-DEFTIMEVAR (TV_XML , "outputing xml")
-DEFTIMEVAR (TV_ACTIONS , "parser action tables")
-DEFTIMEVAR (TV_PARSER , "outputing parser")
-DEFTIMEVAR (TV_M4 , "running m4")
-
-/* Time spent by freeing the memory :). */
-DEFTIMEVAR (TV_FREE , "freeing")
+/* This file contains the definitions for timing variables used to -*- C -*-
+ measure run-time performance of the compiler.
+
+ Copyright (C) 2002, 2007, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Akim Demaille <akim@freefriends.org>.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* This file contains timing variable definitions, used by timevar.h
+ and timevar.c.
+
+ Syntax:
+
+ DEFTIMEVAR (id, name)
+
+ where ID is the enumeral value used to identify the timing
+ variable, and NAME is a character string describing its purpose. */
+
+/* The total execution time. */
+DEFTIMEVAR (TV_TOTAL , "total time")
+
+/* Time spent in the reader. */
+DEFTIMEVAR (TV_READER , "reader")
+DEFTIMEVAR (TV_SCANNING , "scanner")
+DEFTIMEVAR (TV_PARSING , "parser")
+
+/* Time spent handling the grammar. */
+DEFTIMEVAR (TV_REDUCE , "reducing the grammar")
+DEFTIMEVAR (TV_SETS , "computing the sets")
+DEFTIMEVAR (TV_LR0 , "LR(0)")
+DEFTIMEVAR (TV_LALR , "LALR(1)")
+DEFTIMEVAR (TV_IELR_PHASE1 , "IELR(1) Phase 1")
+DEFTIMEVAR (TV_IELR_PHASE2 , "IELR(1) Phase 2")
+DEFTIMEVAR (TV_IELR_PHASE3 , "IELR(1) Phase 3")
+DEFTIMEVAR (TV_IELR_PHASE4 , "IELR(1) Phase 4")
+DEFTIMEVAR (TV_CONFLICTS , "conflicts")
+
+/* Time spent outputing results. */
+DEFTIMEVAR (TV_REPORT , "outputing report")
+DEFTIMEVAR (TV_GRAPH , "outputing graph")
+DEFTIMEVAR (TV_XML , "outputing xml")
+DEFTIMEVAR (TV_ACTIONS , "parser action tables")
+DEFTIMEVAR (TV_PARSER , "outputing parser")
+DEFTIMEVAR (TV_M4 , "running m4")
+
+/* Time spent by freeing the memory :). */
+DEFTIMEVAR (TV_FREE , "freeing")
diff --git a/contrib/tools/bison/gnulib/src/timevar.h b/contrib/tools/bison/gnulib/src/timevar.h
index d397bd7ff0..e46a3b6074 100644
--- a/contrib/tools/bison/gnulib/src/timevar.h
+++ b/contrib/tools/bison/gnulib/src/timevar.h
@@ -1,92 +1,92 @@
-/* Timing variables for measuring compiler performance.
-
- Copyright (C) 2000, 2002, 2004, 2009-2013 Free Software Foundation,
- Inc.
-
- Contributed by Alex Samuel <samuel@codesourcery.com>
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef GCC_TIMEVAR_H
-#define GCC_TIMEVAR_H
-
-/* Timing variables are used to measure elapsed time in various
- portions of the compiler. Each measures elapsed user, system, and
- wall-clock time, as appropriate to and supported by the host
- system.
-
- Timing variables are defined using the DEFTIMEVAR macro in
- timevar.def. Each has an enumeral identifier, used when referring
- to the timing variable in code, and a character string name.
-
- Timing variables can be used in two ways:
-
- - On the timing stack, using timevar_push and timevar_pop.
- Timing variables may be pushed onto the stack; elapsed time is
- attributed to the topmost timing variable on the stack. When
- another variable is pushed on, the previous topmost variable is
- 'paused' until the pushed variable is popped back off.
-
- - As a standalone timer, using timevar_start and timevar_stop.
- All time elapsed between the two calls is attributed to the
- variable.
-*/
-
-/* This structure stores the various varieties of time that can be
- measured. Times are stored in seconds. The time may be an
- absolute time or a time difference; in the former case, the time
- base is undefined, except that the difference between two times
- produces a valid time difference. */
-
-struct timevar_time_def
-{
- /* User time in this process. */
- float user;
-
- /* System time (if applicable for this host platform) in this
- process. */
- float sys;
-
- /* Wall clock time. */
- float wall;
-};
-
-/* An enumeration of timing variable identifiers. Constructed from
- the contents of timevar.def. */
-
-#define DEFTIMEVAR(identifier__, name__) \
- identifier__,
-typedef enum
-{
-#include "timevar.def"
- TIMEVAR_LAST
-}
-timevar_id_t;
-#undef DEFTIMEVAR
-
-extern void init_timevar (void);
-extern void timevar_push (timevar_id_t);
-extern void timevar_pop (timevar_id_t);
-extern void timevar_start (timevar_id_t);
-extern void timevar_stop (timevar_id_t);
-extern void timevar_get (timevar_id_t, struct timevar_time_def *);
-extern void timevar_print (FILE *);
-
-/* Provided for backward compatibility. */
-extern long get_run_time (void);
-extern void print_time (const char *, long);
-
-extern int timevar_report;
-
-#endif /* ! GCC_TIMEVAR_H */
+/* Timing variables for measuring compiler performance.
+
+ Copyright (C) 2000, 2002, 2004, 2009-2013 Free Software Foundation,
+ Inc.
+
+ Contributed by Alex Samuel <samuel@codesourcery.com>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GCC_TIMEVAR_H
+#define GCC_TIMEVAR_H
+
+/* Timing variables are used to measure elapsed time in various
+ portions of the compiler. Each measures elapsed user, system, and
+ wall-clock time, as appropriate to and supported by the host
+ system.
+
+ Timing variables are defined using the DEFTIMEVAR macro in
+ timevar.def. Each has an enumeral identifier, used when referring
+ to the timing variable in code, and a character string name.
+
+ Timing variables can be used in two ways:
+
+ - On the timing stack, using timevar_push and timevar_pop.
+ Timing variables may be pushed onto the stack; elapsed time is
+ attributed to the topmost timing variable on the stack. When
+ another variable is pushed on, the previous topmost variable is
+ 'paused' until the pushed variable is popped back off.
+
+ - As a standalone timer, using timevar_start and timevar_stop.
+ All time elapsed between the two calls is attributed to the
+ variable.
+*/
+
+/* This structure stores the various varieties of time that can be
+ measured. Times are stored in seconds. The time may be an
+ absolute time or a time difference; in the former case, the time
+ base is undefined, except that the difference between two times
+ produces a valid time difference. */
+
+struct timevar_time_def
+{
+ /* User time in this process. */
+ float user;
+
+ /* System time (if applicable for this host platform) in this
+ process. */
+ float sys;
+
+ /* Wall clock time. */
+ float wall;
+};
+
+/* An enumeration of timing variable identifiers. Constructed from
+ the contents of timevar.def. */
+
+#define DEFTIMEVAR(identifier__, name__) \
+ identifier__,
+typedef enum
+{
+#include "timevar.def"
+ TIMEVAR_LAST
+}
+timevar_id_t;
+#undef DEFTIMEVAR
+
+extern void init_timevar (void);
+extern void timevar_push (timevar_id_t);
+extern void timevar_pop (timevar_id_t);
+extern void timevar_start (timevar_id_t);
+extern void timevar_stop (timevar_id_t);
+extern void timevar_get (timevar_id_t, struct timevar_time_def *);
+extern void timevar_print (FILE *);
+
+/* Provided for backward compatibility. */
+extern long get_run_time (void);
+extern void print_time (const char *, long);
+
+extern int timevar_report;
+
+#endif /* ! GCC_TIMEVAR_H */
diff --git a/contrib/tools/bison/gnulib/src/tmpdir.c b/contrib/tools/bison/gnulib/src/tmpdir.c
index 1b3fb023a0..6fdb52a126 100644
--- a/contrib/tools/bison/gnulib/src/tmpdir.c
+++ b/contrib/tools/bison/gnulib/src/tmpdir.c
@@ -1,159 +1,159 @@
-/* Copyright (C) 1999, 2001-2002, 2006, 2009-2013 Free Software Foundation,
- Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Extracted from sysdeps/posix/tempname.c. */
-
-#include <config.h>
-
-/* Specification. */
-#include "tmpdir.h"
-
-#include <stdbool.h>
+/* Copyright (C) 1999, 2001-2002, 2006, 2009-2013 Free Software Foundation,
+ Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Extracted from sysdeps/posix/tempname.c. */
+
+#include <config.h>
+
+/* Specification. */
+#include "tmpdir.h"
+
+#include <stdbool.h>
#include "stdlib--.h"
-#include <string.h>
-
-#include <errno.h>
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
-
-#include <stdio.h>
-#ifndef P_tmpdir
-# ifdef _P_tmpdir /* native Windows */
-# define P_tmpdir _P_tmpdir
-# else
-# define P_tmpdir "/tmp"
-# endif
-#endif
-
-#include <sys/stat.h>
-
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-# define WIN32_LEAN_AND_MEAN /* avoid including junk */
-# include <windows.h>
-#endif
-
-#include "pathmax.h"
-
-#if _LIBC
-# define struct_stat64 struct stat64
-#else
-# define struct_stat64 struct stat
-# define __libc_secure_getenv secure_getenv
-# define __xstat64(version, path, buf) stat (path, buf)
-#endif
-
-/* Pathname support.
- ISSLASH(C) tests whether C is a directory separator character.
- */
-#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
- /* Native Windows, Cygwin, OS/2, DOS */
-# define ISSLASH(C) ((C) == '/' || (C) == '\\')
-#else
- /* Unix */
-# define ISSLASH(C) ((C) == '/')
-#endif
-
-
-/* Return nonzero if DIR is an existent directory. */
-static bool
-direxists (const char *dir)
-{
- struct_stat64 buf;
- return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
-}
-
-/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
- non-null and exists, uses it; otherwise uses the first of $TMPDIR,
- P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
- for use with mk[s]temp. Will fail (-1) if DIR is non-null and
- doesn't exist, none of the searched dirs exists, or there's not
- enough space in TMPL. */
-int
-path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
- bool try_tmpdir)
-{
- const char *d;
- size_t dlen, plen;
- bool add_slash;
-
- if (!pfx || !pfx[0])
- {
- pfx = "file";
- plen = 4;
- }
- else
- {
- plen = strlen (pfx);
- if (plen > 5)
- plen = 5;
- }
-
- if (try_tmpdir)
- {
- d = __libc_secure_getenv ("TMPDIR");
- if (d != NULL && direxists (d))
- dir = d;
- else if (dir != NULL && direxists (dir))
- /* nothing */ ;
- else
- dir = NULL;
- }
- if (dir == NULL)
- {
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- char dirbuf[PATH_MAX];
- DWORD retval;
-
- /* Find Windows temporary file directory.
- We try this before P_tmpdir because Windows defines P_tmpdir to "\\"
- and will therefore try to put all temporary files in the root
- directory (unless $TMPDIR is set). */
- retval = GetTempPath (PATH_MAX, dirbuf);
- if (retval > 0 && retval < PATH_MAX && direxists (dirbuf))
- dir = dirbuf;
- else
-#endif
- if (direxists (P_tmpdir))
- dir = P_tmpdir;
- else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
- dir = "/tmp";
- else
- {
- __set_errno (ENOENT);
- return -1;
- }
- }
-
- dlen = strlen (dir);
-#ifdef __VMS
- add_slash = 0;
-#else
- add_slash = dlen != 0 && !ISSLASH (dir[dlen - 1]);
-#endif
-
- /* check we have room for "${dir}/${pfx}XXXXXX\0" */
- if (tmpl_len < dlen + add_slash + plen + 6 + 1)
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- memcpy (tmpl, dir, dlen);
- sprintf (tmpl + dlen, &"/%.*sXXXXXX"[!add_slash], (int) plen, pfx);
- return 0;
-}
+#include <string.h>
+
+#include <errno.h>
+#ifndef __set_errno
+# define __set_errno(Val) errno = (Val)
+#endif
+
+#include <stdio.h>
+#ifndef P_tmpdir
+# ifdef _P_tmpdir /* native Windows */
+# define P_tmpdir _P_tmpdir
+# else
+# define P_tmpdir "/tmp"
+# endif
+#endif
+
+#include <sys/stat.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+#endif
+
+#include "pathmax.h"
+
+#if _LIBC
+# define struct_stat64 struct stat64
+#else
+# define struct_stat64 struct stat
+# define __libc_secure_getenv secure_getenv
+# define __xstat64(version, path, buf) stat (path, buf)
+#endif
+
+/* Pathname support.
+ ISSLASH(C) tests whether C is a directory separator character.
+ */
+#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
+ /* Native Windows, Cygwin, OS/2, DOS */
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#else
+ /* Unix */
+# define ISSLASH(C) ((C) == '/')
+#endif
+
+
+/* Return nonzero if DIR is an existent directory. */
+static bool
+direxists (const char *dir)
+{
+ struct_stat64 buf;
+ return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
+}
+
+/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
+ non-null and exists, uses it; otherwise uses the first of $TMPDIR,
+ P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
+ for use with mk[s]temp. Will fail (-1) if DIR is non-null and
+ doesn't exist, none of the searched dirs exists, or there's not
+ enough space in TMPL. */
+int
+path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
+ bool try_tmpdir)
+{
+ const char *d;
+ size_t dlen, plen;
+ bool add_slash;
+
+ if (!pfx || !pfx[0])
+ {
+ pfx = "file";
+ plen = 4;
+ }
+ else
+ {
+ plen = strlen (pfx);
+ if (plen > 5)
+ plen = 5;
+ }
+
+ if (try_tmpdir)
+ {
+ d = __libc_secure_getenv ("TMPDIR");
+ if (d != NULL && direxists (d))
+ dir = d;
+ else if (dir != NULL && direxists (dir))
+ /* nothing */ ;
+ else
+ dir = NULL;
+ }
+ if (dir == NULL)
+ {
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ char dirbuf[PATH_MAX];
+ DWORD retval;
+
+ /* Find Windows temporary file directory.
+ We try this before P_tmpdir because Windows defines P_tmpdir to "\\"
+ and will therefore try to put all temporary files in the root
+ directory (unless $TMPDIR is set). */
+ retval = GetTempPath (PATH_MAX, dirbuf);
+ if (retval > 0 && retval < PATH_MAX && direxists (dirbuf))
+ dir = dirbuf;
+ else
+#endif
+ if (direxists (P_tmpdir))
+ dir = P_tmpdir;
+ else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
+ dir = "/tmp";
+ else
+ {
+ __set_errno (ENOENT);
+ return -1;
+ }
+ }
+
+ dlen = strlen (dir);
+#ifdef __VMS
+ add_slash = 0;
+#else
+ add_slash = dlen != 0 && !ISSLASH (dir[dlen - 1]);
+#endif
+
+ /* check we have room for "${dir}/${pfx}XXXXXX\0" */
+ if (tmpl_len < dlen + add_slash + plen + 6 + 1)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ memcpy (tmpl, dir, dlen);
+ sprintf (tmpl + dlen, &"/%.*sXXXXXX"[!add_slash], (int) plen, pfx);
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/tmpdir.h b/contrib/tools/bison/gnulib/src/tmpdir.h
index ff7c70f346..40d119fc5c 100644
--- a/contrib/tools/bison/gnulib/src/tmpdir.h
+++ b/contrib/tools/bison/gnulib/src/tmpdir.h
@@ -1,26 +1,26 @@
-/* Determine a temporary directory.
- Copyright (C) 2001-2002, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <stdbool.h>
-#include <stddef.h>
-
-/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
- non-null and exists, uses it; otherwise uses the first of $TMPDIR,
- P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
- for use with mk[s]temp. Will fail (-1) if DIR is non-null and
- doesn't exist, none of the searched dirs exists, or there's not
- enough space in TMPL. */
-extern int path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, bool try_tmpdir);
+/* Determine a temporary directory.
+ Copyright (C) 2001-2002, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdbool.h>
+#include <stddef.h>
+
+/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
+ non-null and exists, uses it; otherwise uses the first of $TMPDIR,
+ P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
+ for use with mk[s]temp. Will fail (-1) if DIR is non-null and
+ doesn't exist, none of the searched dirs exists, or there's not
+ enough space in TMPL. */
+extern int path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, bool try_tmpdir);
diff --git a/contrib/tools/bison/gnulib/src/unistd--.h b/contrib/tools/bison/gnulib/src/unistd--.h
index fee7ecf03d..eaa1440f95 100644
--- a/contrib/tools/bison/gnulib/src/unistd--.h
+++ b/contrib/tools/bison/gnulib/src/unistd--.h
@@ -1,36 +1,36 @@
-/* Like unistd.h, but redefine some names to avoid glitches.
-
- Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert. */
-
-#include <unistd.h>
-#include "unistd-safer.h"
-
+/* Like unistd.h, but redefine some names to avoid glitches.
+
+ Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert. */
+
+#include <unistd.h>
+#include "unistd-safer.h"
+
#if defined(_WIN32)
# include <process.h>
#endif
-#undef dup
-#define dup dup_safer
-
-#undef pipe
-#define pipe pipe_safer
-
-#if GNULIB_PIPE2_SAFER
-# undef pipe2
-# define pipe2 pipe2_safer
-#endif
+#undef dup
+#define dup dup_safer
+
+#undef pipe
+#define pipe pipe_safer
+
+#if GNULIB_PIPE2_SAFER
+# undef pipe2
+# define pipe2 pipe2_safer
+#endif
diff --git a/contrib/tools/bison/gnulib/src/unistd-safer.h b/contrib/tools/bison/gnulib/src/unistd-safer.h
index 5c2b55ae2f..c9ad8cdaef 100644
--- a/contrib/tools/bison/gnulib/src/unistd-safer.h
+++ b/contrib/tools/bison/gnulib/src/unistd-safer.h
@@ -1,31 +1,31 @@
-/* Invoke unistd-like functions, but avoid some glitches.
-
- Copyright (C) 2001, 2003, 2005, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert and Eric Blake. */
-
-int dup_safer (int);
-int fd_safer (int);
-int pipe_safer (int[2]);
-
-#if GNULIB_FD_SAFER_FLAG
-int dup_safer_flag (int, int);
-int fd_safer_flag (int, int);
-#endif
-
-#if GNULIB_PIPE2_SAFER
-int pipe2_safer (int[2], int);
-#endif
+/* Invoke unistd-like functions, but avoid some glitches.
+
+ Copyright (C) 2001, 2003, 2005, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert and Eric Blake. */
+
+int dup_safer (int);
+int fd_safer (int);
+int pipe_safer (int[2]);
+
+#if GNULIB_FD_SAFER_FLAG
+int dup_safer_flag (int, int);
+int fd_safer_flag (int, int);
+#endif
+
+#if GNULIB_PIPE2_SAFER
+int pipe2_safer (int[2], int);
+#endif
diff --git a/contrib/tools/bison/gnulib/src/unistd.c b/contrib/tools/bison/gnulib/src/unistd.c
index 6c6a8e268c..e2532214a7 100644
--- a/contrib/tools/bison/gnulib/src/unistd.c
+++ b/contrib/tools/bison/gnulib/src/unistd.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
-#include "unistd.h"
+#include <config.h>
+#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
+#include "unistd.h"
diff --git a/contrib/tools/bison/gnulib/src/uniwidth/cjk.h b/contrib/tools/bison/gnulib/src/uniwidth/cjk.h
index 11b14dfec5..0c2238a19a 100644
--- a/contrib/tools/bison/gnulib/src/uniwidth/cjk.h
+++ b/contrib/tools/bison/gnulib/src/uniwidth/cjk.h
@@ -1,37 +1,37 @@
-/* Test for CJK encoding.
- Copyright (C) 2001-2002, 2005-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2002.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "streq.h"
-
-static int
-is_cjk_encoding (const char *encoding)
-{
- if (0
- /* Legacy Japanese encodings */
- || STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)
- /* Legacy Chinese encodings */
- || STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
- || STREQ_OPT (encoding, "GBK", 'G', 'B', 'K', 0, 0, 0, 0, 0, 0)
- || STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)
- || STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)
- /* Legacy Korean encodings */
- || STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
- || STREQ_OPT (encoding, "CP949", 'C', 'P', '9', '4', '9', 0, 0, 0, 0)
- || STREQ_OPT (encoding, "JOHAB", 'J', 'O', 'H', 'A', 'B', 0, 0, 0, 0))
- return 1;
- return 0;
-}
+/* Test for CJK encoding.
+ Copyright (C) 2001-2002, 2005-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2002.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "streq.h"
+
+static int
+is_cjk_encoding (const char *encoding)
+{
+ if (0
+ /* Legacy Japanese encodings */
+ || STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)
+ /* Legacy Chinese encodings */
+ || STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
+ || STREQ_OPT (encoding, "GBK", 'G', 'B', 'K', 0, 0, 0, 0, 0, 0)
+ || STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)
+ || STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)
+ /* Legacy Korean encodings */
+ || STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+ || STREQ_OPT (encoding, "CP949", 'C', 'P', '9', '4', '9', 0, 0, 0, 0)
+ || STREQ_OPT (encoding, "JOHAB", 'J', 'O', 'H', 'A', 'B', 0, 0, 0, 0))
+ return 1;
+ return 0;
+}
diff --git a/contrib/tools/bison/gnulib/src/uniwidth/width.c b/contrib/tools/bison/gnulib/src/uniwidth/width.c
index 173d0872c7..bccfa9696a 100644
--- a/contrib/tools/bison/gnulib/src/uniwidth/width.c
+++ b/contrib/tools/bison/gnulib/src/uniwidth/width.c
@@ -1,368 +1,368 @@
-/* Determine display width of Unicode character.
- Copyright (C) 2001-2002, 2006-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2002.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "uniwidth.h"
-
-#include "cjk.h"
-
-/*
- * Non-spacing attribute table.
- * Consists of:
- * - Non-spacing characters; generated from PropList.txt or
- * "grep '^[^;]*;[^;]*;[^;]*;[^;]*;NSM;' UnicodeData.txt"
- * - Format control characters; generated from
- * "grep '^[^;]*;[^;]*;Cf;' UnicodeData.txt"
- * - Zero width characters; generated from
- * "grep '^[^;]*;ZERO WIDTH ' UnicodeData.txt"
- */
-static const unsigned char nonspacing_table_data[27*64] = {
- /* 0x0000-0x01ff */
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0x0000-0x003f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x0040-0x007f */
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x20, 0x00, 0x00, /* 0x0080-0x00bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c0-0x00ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0100-0x013f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0140-0x017f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0180-0x01bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x01c0-0x01ff */
- /* 0x0200-0x03ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0200-0x023f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0240-0x027f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0280-0x02bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c0-0x02ff */
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x0300-0x033f */
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, /* 0x0340-0x037f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0380-0x03bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x03c0-0x03ff */
- /* 0x0400-0x05ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0400-0x043f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0440-0x047f */
- 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0480-0x04bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x04c0-0x04ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0500-0x053f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0540-0x057f */
- 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xbf, /* 0x0580-0x05bf */
- 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05c0-0x05ff */
- /* 0x0600-0x07ff */
- 0x0f, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, /* 0x0600-0x063f */
- 0x00, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x01, 0x00, /* 0x0640-0x067f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0680-0x06bf */
- 0x00, 0x00, 0xc0, 0xbf, 0x9f, 0x3d, 0x00, 0x00, /* 0x06c0-0x06ff */
- 0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, /* 0x0700-0x073f */
- 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0740-0x077f */
- 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, /* 0x0780-0x07bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x07c0-0x07ff */
- /* 0x0800-0x09ff */
- 0x00, 0x00, 0xc0, 0xfb, 0xef, 0x3e, 0x00, 0x00, /* 0x0800-0x083f */
- 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, /* 0x0840-0x087f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0880-0x08bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08c0-0x08ff */
- 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, /* 0x0900-0x093f */
- 0xfe, 0x21, 0xfe, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0940-0x097f */
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0980-0x09bf */
- 0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x09c0-0x09ff */
- /* 0x0a00-0x0bff */
- 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a00-0x0a3f */
- 0x86, 0x39, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, /* 0x0a40-0x0a7f */
- 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a80-0x0abf */
- 0xbe, 0x21, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0ac0-0x0aff */
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, /* 0x0b00-0x0b3f */
- 0x1e, 0x20, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0b40-0x0b7f */
- 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0b80-0x0bbf */
- 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0bc0-0x0bff */
- /* 0x0c00-0x0dff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, /* 0x0c00-0x0c3f */
- 0xc1, 0x3d, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0c40-0x0c7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0c80-0x0cbf */
- 0x00, 0x30, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0cc0-0x0cff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d00-0x0d3f */
- 0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0d40-0x0d7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d80-0x0dbf */
- 0x00, 0x04, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0dc0-0x0dff */
- /* 0x0e00-0x0fff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x07, /* 0x0e00-0x0e3f */
- 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0e40-0x0e7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x1b, /* 0x0e80-0x0ebf */
- 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0ec0-0x0eff */
- 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xa0, 0x02, /* 0x0f00-0x0f3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, /* 0x0f40-0x0f7f */
- 0xdf, 0xe0, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x1f, /* 0x0f80-0x0fbf */
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0fc0-0x0fff */
- /* 0x1000-0x11ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x66, /* 0x1000-0x103f */
- 0x00, 0x00, 0x00, 0xc3, 0x01, 0x00, 0x1e, 0x00, /* 0x1040-0x107f */
- 0x64, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x1080-0x10bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c0-0x10ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1100-0x113f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1140-0x117f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1180-0x11bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11c0-0x11ff */
- /* 0x1200-0x13ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1200-0x123f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1240-0x127f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1280-0x12bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x12c0-0x12ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1300-0x133f */
- 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, /* 0x1340-0x137f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1380-0x13bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13c0-0x13ff */
- /* 0x1600-0x17ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1600-0x163f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1640-0x167f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1680-0x16bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16c0-0x16ff */
- 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, /* 0x1700-0x173f */
- 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, /* 0x1740-0x177f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x3f, /* 0x1780-0x17bf */
- 0x40, 0xfe, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x17c0-0x17ff */
- /* 0x1800-0x19ff */
- 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1800-0x183f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1840-0x187f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x1880-0x18bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18c0-0x18ff */
- 0x00, 0x00, 0x00, 0x00, 0x87, 0x01, 0x04, 0x0e, /* 0x1900-0x193f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1940-0x197f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1980-0x19bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x19c0-0x19ff */
- /* 0x1a00-0x1bff */
- 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, /* 0x1a00-0x1a3f */
- 0x00, 0x00, 0x40, 0x7f, 0xe5, 0x1f, 0xf8, 0x9f, /* 0x1a40-0x1a7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1a80-0x1abf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ac0-0x1aff */
- 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x17, /* 0x1b00-0x1b3f */
- 0x04, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x1b40-0x1b7f */
- 0x03, 0x00, 0x00, 0x00, 0x3c, 0x03, 0x00, 0x00, /* 0x1b80-0x1bbf */
- 0x00, 0x00, 0x00, 0x00, 0x40, 0xa3, 0x03, 0x00, /* 0x1bc0-0x1bff */
- /* 0x1c00-0x1dff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xcf, 0x00, /* 0x1c00-0x1c3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c40-0x1c7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c80-0x1cbf */
- 0x00, 0x00, 0xf7, 0xff, 0xfd, 0x21, 0x00, 0x00, /* 0x1cc0-0x1cff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d00-0x1d3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d40-0x1d7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d80-0x1dbf */
- 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, /* 0x1dc0-0x1dff */
- /* 0x2000-0x21ff */
- 0x00, 0xf8, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, /* 0x2000-0x203f */
- 0x00, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, /* 0x2040-0x207f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2080-0x20bf */
- 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, /* 0x20c0-0x20ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2100-0x213f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2140-0x217f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2180-0x21bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x21c0-0x21ff */
- /* 0x2c00-0x2dff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c00-0x2c3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c40-0x2c7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c80-0x2cbf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, /* 0x2cc0-0x2cff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d00-0x2d3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x2d40-0x2d7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d80-0x2dbf */
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, /* 0x2dc0-0x2dff */
- /* 0x3000-0x31ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, /* 0x3000-0x303f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3040-0x307f */
- 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, /* 0x3080-0x30bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30c0-0x30ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3100-0x313f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3140-0x317f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3180-0x31bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x31c0-0x31ff */
- /* 0xa600-0xa7ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa600-0xa63f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x30, /* 0xa640-0xa67f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa680-0xa6bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, /* 0xa6c0-0xa6ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa700-0xa73f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa740-0xa77f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa780-0xa7bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa7c0-0xa7ff */
- /* 0xa800-0xa9ff */
- 0x44, 0x08, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, /* 0xa800-0xa83f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa840-0xa87f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa880-0xa8bf */
- 0x10, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00, /* 0xa8c0-0xa8ff */
- 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, /* 0xa900-0xa93f */
- 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa940-0xa97f */
- 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x13, /* 0xa980-0xa9bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa9c0-0xa9ff */
- /* 0xaa00-0xabff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x66, 0x00, /* 0xaa00-0xaa3f */
- 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaa40-0xaa7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0xc1, /* 0xaa80-0xaabf */
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaac0-0xaaff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab00-0xab3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab40-0xab7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab80-0xabbf */
- 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x00, /* 0xabc0-0xabff */
- /* 0xfa00-0xfbff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa00-0xfa3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa40-0xfa7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa80-0xfabf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfac0-0xfaff */
- 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, /* 0xfb00-0xfb3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb40-0xfb7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb80-0xfbbf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfbc0-0xfbff */
- /* 0xfe00-0xffff */
- 0xff, 0xff, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, /* 0xfe00-0xfe3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe40-0xfe7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe80-0xfebf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0xfec0-0xfeff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff00-0xff3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff40-0xff7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff80-0xffbf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, /* 0xffc0-0xffff */
- /* 0x10000-0x101ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10000-0x1003f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10040-0x1007f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10080-0x100bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x100c0-0x100ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10100-0x1013f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10140-0x1017f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10180-0x101bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, /* 0x101c0-0x101ff */
- /* 0x10a00-0x10bff */
- 0x6e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, /* 0x10a00-0x10a3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a40-0x10a7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a80-0x10abf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10ac0-0x10aff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b00-0x10b3f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b40-0x10b7f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b80-0x10bbf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10bc0-0x10bff */
- /* 0x11000-0x111ff */
- 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 0x11000-0x1103f */
- 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11040-0x1107f */
- 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x26, /* 0x11080-0x110bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x110c0-0x110ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11100-0x1113f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11140-0x1117f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11180-0x111bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x111c0-0x111ff */
- /* 0x1d000-0x1d1ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d000-0x1d03f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d040-0x1d07f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d080-0x1d0bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d0c0-0x1d0ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d100-0x1d13f */
- 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xf8, 0xff, /* 0x1d140-0x1d17f */
- 0xe7, 0x0f, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, /* 0x1d180-0x1d1bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d1c0-0x1d1ff */
- /* 0x1d200-0x1d3ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d200-0x1d23f */
- 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d240-0x1d27f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d280-0x1d2bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d2c0-0x1d2ff */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d300-0x1d33f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d340-0x1d37f */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d380-0x1d3bf */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0x1d3c0-0x1d3ff */
-};
-static const signed char nonspacing_table_ind[240] = {
- 0, 1, 2, 3, 4, 5, 6, 7, /* 0x0000-0x0fff */
- 8, 9, -1, 10, 11, 12, 13, -1, /* 0x1000-0x1fff */
- 14, -1, -1, -1, -1, -1, 15, -1, /* 0x2000-0x2fff */
- 16, -1, -1, -1, -1, -1, -1, -1, /* 0x3000-0x3fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x4000-0x4fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x5000-0x5fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x6000-0x6fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x7000-0x7fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x8000-0x8fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x9000-0x9fff */
- -1, -1, -1, 17, 18, 19, -1, -1, /* 0xa000-0xafff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb000-0xbfff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc000-0xcfff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd000-0xdfff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe000-0xefff */
- -1, -1, -1, -1, -1, 20, -1, 21, /* 0xf000-0xffff */
- 22, -1, -1, -1, -1, 23, -1, -1, /* 0x10000-0x10fff */
- 24, -1, -1, -1, -1, -1, -1, -1, /* 0x11000-0x11fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x12000-0x12fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x13000-0x13fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x14000-0x14fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x15000-0x15fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x16000-0x16fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x17000-0x17fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x18000-0x18fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x19000-0x19fff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1a000-0x1afff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1b000-0x1bfff */
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1c000-0x1cfff */
- 25, 26, -1, -1, -1, -1, -1, -1 /* 0x1d000-0x1dfff */
-};
-
-/* Determine number of column positions required for UC. */
-int
-uc_width (ucs4_t uc, const char *encoding)
-{
- /* Test for non-spacing or control character. */
- if ((uc >> 9) < 240)
- {
- int ind = nonspacing_table_ind[uc >> 9];
- if (ind >= 0)
- if ((nonspacing_table_data[64*ind + ((uc >> 3) & 63)] >> (uc & 7)) & 1)
- {
- if (uc > 0 && uc < 0xa0)
- return -1;
- else
- return 0;
- }
- }
- else if ((uc >> 9) == (0xe0000 >> 9))
- {
- if (uc >= 0xe0100)
- {
- if (uc <= 0xe01ef)
- return 0;
- }
- else
- {
- if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001)
- return 0;
- }
- }
- /* Test for double-width character.
- * Generated from "grep '^[^;]\{4,5\};[WF]' EastAsianWidth.txt"
- * and "grep '^[^;]\{4,5\};[^WF]' EastAsianWidth.txt"
- */
- if (uc >= 0x1100
- && ((uc < 0x1160) /* Hangul Jamo */
- || (uc >= 0x2329 && uc < 0x232b) /* Angle Brackets */
- || (uc >= 0x2e80 && uc < 0xa4d0 /* CJK ... Yi */
- && !(uc == 0x303f) && !(uc >= 0x4dc0 && uc < 0x4e00))
- || (uc >= 0xac00 && uc < 0xd7a4) /* Hangul Syllables */
- || (uc >= 0xf900 && uc < 0xfb00) /* CJK Compatibility Ideographs */
- || (uc >= 0xfe10 && uc < 0xfe20) /* Presentation Forms for Vertical */
- || (uc >= 0xfe30 && uc < 0xfe70) /* CJK Compatibility Forms */
- || (uc >= 0xff00 && uc < 0xff61) /* Fullwidth Forms */
- || (uc >= 0xffe0 && uc < 0xffe7) /* Fullwidth Signs */
- || (uc >= 0x20000 && uc <= 0x2ffff) /* Supplementary Ideographic Plane */
- || (uc >= 0x30000 && uc <= 0x3ffff) /* Tertiary Ideographic Plane */
- ) )
- return 2;
- /* In ancient CJK encodings, Cyrillic and most other characters are
- double-width as well. */
- if (uc >= 0x00A1 && uc < 0xFF61 && uc != 0x20A9
- && is_cjk_encoding (encoding))
- return 2;
- return 1;
-}
+/* Determine display width of Unicode character.
+ Copyright (C) 2001-2002, 2006-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2002.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "uniwidth.h"
+
+#include "cjk.h"
+
+/*
+ * Non-spacing attribute table.
+ * Consists of:
+ * - Non-spacing characters; generated from PropList.txt or
+ * "grep '^[^;]*;[^;]*;[^;]*;[^;]*;NSM;' UnicodeData.txt"
+ * - Format control characters; generated from
+ * "grep '^[^;]*;[^;]*;Cf;' UnicodeData.txt"
+ * - Zero width characters; generated from
+ * "grep '^[^;]*;ZERO WIDTH ' UnicodeData.txt"
+ */
+static const unsigned char nonspacing_table_data[27*64] = {
+ /* 0x0000-0x01ff */
+ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, /* 0x0000-0x003f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x0040-0x007f */
+ 0xff, 0xff, 0xff, 0xff, 0x00, 0x20, 0x00, 0x00, /* 0x0080-0x00bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c0-0x00ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0100-0x013f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0140-0x017f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0180-0x01bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x01c0-0x01ff */
+ /* 0x0200-0x03ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0200-0x023f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0240-0x027f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0280-0x02bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c0-0x02ff */
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x0300-0x033f */
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, /* 0x0340-0x037f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0380-0x03bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x03c0-0x03ff */
+ /* 0x0400-0x05ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0400-0x043f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0440-0x047f */
+ 0xf8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0480-0x04bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x04c0-0x04ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0500-0x053f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0540-0x057f */
+ 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xbf, /* 0x0580-0x05bf */
+ 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05c0-0x05ff */
+ /* 0x0600-0x07ff */
+ 0x0f, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, /* 0x0600-0x063f */
+ 0x00, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x01, 0x00, /* 0x0640-0x067f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0680-0x06bf */
+ 0x00, 0x00, 0xc0, 0xbf, 0x9f, 0x3d, 0x00, 0x00, /* 0x06c0-0x06ff */
+ 0x00, 0x80, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, /* 0x0700-0x073f */
+ 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0740-0x077f */
+ 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x01, 0x00, /* 0x0780-0x07bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x07c0-0x07ff */
+ /* 0x0800-0x09ff */
+ 0x00, 0x00, 0xc0, 0xfb, 0xef, 0x3e, 0x00, 0x00, /* 0x0800-0x083f */
+ 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, /* 0x0840-0x087f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0880-0x08bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08c0-0x08ff */
+ 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, /* 0x0900-0x093f */
+ 0xfe, 0x21, 0xfe, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0940-0x097f */
+ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0980-0x09bf */
+ 0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x09c0-0x09ff */
+ /* 0x0a00-0x0bff */
+ 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a00-0x0a3f */
+ 0x86, 0x39, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, /* 0x0a40-0x0a7f */
+ 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0a80-0x0abf */
+ 0xbe, 0x21, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0ac0-0x0aff */
+ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, /* 0x0b00-0x0b3f */
+ 0x1e, 0x20, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0b40-0x0b7f */
+ 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0b80-0x0bbf */
+ 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0bc0-0x0bff */
+ /* 0x0c00-0x0dff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, /* 0x0c00-0x0c3f */
+ 0xc1, 0x3d, 0x60, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0c40-0x0c7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, /* 0x0c80-0x0cbf */
+ 0x00, 0x30, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0cc0-0x0cff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d00-0x0d3f */
+ 0x1e, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, /* 0x0d40-0x0d7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0d80-0x0dbf */
+ 0x00, 0x04, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0dc0-0x0dff */
+ /* 0x0e00-0x0fff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x07, /* 0x0e00-0x0e3f */
+ 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0e40-0x0e7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x1b, /* 0x0e80-0x0ebf */
+ 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0ec0-0x0eff */
+ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xa0, 0x02, /* 0x0f00-0x0f3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, /* 0x0f40-0x0f7f */
+ 0xdf, 0xe0, 0xff, 0xfe, 0xff, 0xff, 0xff, 0x1f, /* 0x0f80-0x0fbf */
+ 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0fc0-0x0fff */
+ /* 0x1000-0x11ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x66, /* 0x1000-0x103f */
+ 0x00, 0x00, 0x00, 0xc3, 0x01, 0x00, 0x1e, 0x00, /* 0x1040-0x107f */
+ 0x64, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x1080-0x10bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10c0-0x10ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1100-0x113f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1140-0x117f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1180-0x11bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11c0-0x11ff */
+ /* 0x1200-0x13ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1200-0x123f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1240-0x127f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1280-0x12bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x12c0-0x12ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1300-0x133f */
+ 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, /* 0x1340-0x137f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1380-0x13bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x13c0-0x13ff */
+ /* 0x1600-0x17ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1600-0x163f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1640-0x167f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1680-0x16bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x16c0-0x16ff */
+ 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1c, 0x00, /* 0x1700-0x173f */
+ 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, /* 0x1740-0x177f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x3f, /* 0x1780-0x17bf */
+ 0x40, 0xfe, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x00, /* 0x17c0-0x17ff */
+ /* 0x1800-0x19ff */
+ 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1800-0x183f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1840-0x187f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* 0x1880-0x18bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18c0-0x18ff */
+ 0x00, 0x00, 0x00, 0x00, 0x87, 0x01, 0x04, 0x0e, /* 0x1900-0x193f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1940-0x197f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1980-0x19bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x19c0-0x19ff */
+ /* 0x1a00-0x1bff */
+ 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, /* 0x1a00-0x1a3f */
+ 0x00, 0x00, 0x40, 0x7f, 0xe5, 0x1f, 0xf8, 0x9f, /* 0x1a40-0x1a7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1a80-0x1abf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1ac0-0x1aff */
+ 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x17, /* 0x1b00-0x1b3f */
+ 0x04, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x0f, 0x00, /* 0x1b40-0x1b7f */
+ 0x03, 0x00, 0x00, 0x00, 0x3c, 0x03, 0x00, 0x00, /* 0x1b80-0x1bbf */
+ 0x00, 0x00, 0x00, 0x00, 0x40, 0xa3, 0x03, 0x00, /* 0x1bc0-0x1bff */
+ /* 0x1c00-0x1dff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xcf, 0x00, /* 0x1c00-0x1c3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c40-0x1c7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1c80-0x1cbf */
+ 0x00, 0x00, 0xf7, 0xff, 0xfd, 0x21, 0x00, 0x00, /* 0x1cc0-0x1cff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d00-0x1d3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d40-0x1d7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d80-0x1dbf */
+ 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, /* 0x1dc0-0x1dff */
+ /* 0x2000-0x21ff */
+ 0x00, 0xf8, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, /* 0x2000-0x203f */
+ 0x00, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x00, /* 0x2040-0x207f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2080-0x20bf */
+ 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, /* 0x20c0-0x20ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2100-0x213f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2140-0x217f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2180-0x21bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x21c0-0x21ff */
+ /* 0x2c00-0x2dff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c00-0x2c3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c40-0x2c7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2c80-0x2cbf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, /* 0x2cc0-0x2cff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d00-0x2d3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0x2d40-0x2d7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2d80-0x2dbf */
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, /* 0x2dc0-0x2dff */
+ /* 0x3000-0x31ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, /* 0x3000-0x303f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3040-0x307f */
+ 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, /* 0x3080-0x30bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30c0-0x30ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3100-0x313f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3140-0x317f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x3180-0x31bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x31c0-0x31ff */
+ /* 0xa600-0xa7ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa600-0xa63f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x30, /* 0xa640-0xa67f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa680-0xa6bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, /* 0xa6c0-0xa6ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa700-0xa73f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa740-0xa77f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa780-0xa7bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa7c0-0xa7ff */
+ /* 0xa800-0xa9ff */
+ 0x44, 0x08, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, /* 0xa800-0xa83f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa840-0xa87f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa880-0xa8bf */
+ 0x10, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00, /* 0xa8c0-0xa8ff */
+ 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, /* 0xa900-0xa93f */
+ 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa940-0xa97f */
+ 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x13, /* 0xa980-0xa9bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa9c0-0xa9ff */
+ /* 0xaa00-0xabff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x66, 0x00, /* 0xaa00-0xaa3f */
+ 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaa40-0xaa7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0xc1, /* 0xaa80-0xaabf */
+ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xaac0-0xaaff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab00-0xab3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab40-0xab7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xab80-0xabbf */
+ 0x00, 0x00, 0x00, 0x00, 0x20, 0x21, 0x00, 0x00, /* 0xabc0-0xabff */
+ /* 0xfa00-0xfbff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa00-0xfa3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa40-0xfa7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfa80-0xfabf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfac0-0xfaff */
+ 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, /* 0xfb00-0xfb3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb40-0xfb7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfb80-0xfbbf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfbc0-0xfbff */
+ /* 0xfe00-0xffff */
+ 0xff, 0xff, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, /* 0xfe00-0xfe3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe40-0xfe7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xfe80-0xfebf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, /* 0xfec0-0xfeff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff00-0xff3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff40-0xff7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xff80-0xffbf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, /* 0xffc0-0xffff */
+ /* 0x10000-0x101ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10000-0x1003f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10040-0x1007f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10080-0x100bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x100c0-0x100ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10100-0x1013f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10140-0x1017f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10180-0x101bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, /* 0x101c0-0x101ff */
+ /* 0x10a00-0x10bff */
+ 0x6e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, /* 0x10a00-0x10a3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a40-0x10a7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10a80-0x10abf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10ac0-0x10aff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b00-0x10b3f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b40-0x10b7f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10b80-0x10bbf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10bc0-0x10bff */
+ /* 0x11000-0x111ff */
+ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 0x11000-0x1103f */
+ 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11040-0x1107f */
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x26, /* 0x11080-0x110bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x110c0-0x110ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11100-0x1113f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11140-0x1117f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x11180-0x111bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x111c0-0x111ff */
+ /* 0x1d000-0x1d1ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d000-0x1d03f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d040-0x1d07f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d080-0x1d0bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d0c0-0x1d0ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d100-0x1d13f */
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0xf8, 0xff, /* 0x1d140-0x1d17f */
+ 0xe7, 0x0f, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, /* 0x1d180-0x1d1bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d1c0-0x1d1ff */
+ /* 0x1d200-0x1d3ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d200-0x1d23f */
+ 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d240-0x1d27f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d280-0x1d2bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d2c0-0x1d2ff */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d300-0x1d33f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d340-0x1d37f */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x1d380-0x1d3bf */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0x1d3c0-0x1d3ff */
+};
+static const signed char nonspacing_table_ind[240] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, /* 0x0000-0x0fff */
+ 8, 9, -1, 10, 11, 12, 13, -1, /* 0x1000-0x1fff */
+ 14, -1, -1, -1, -1, -1, 15, -1, /* 0x2000-0x2fff */
+ 16, -1, -1, -1, -1, -1, -1, -1, /* 0x3000-0x3fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x4000-0x4fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x5000-0x5fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x6000-0x6fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x7000-0x7fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x8000-0x8fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x9000-0x9fff */
+ -1, -1, -1, 17, 18, 19, -1, -1, /* 0xa000-0xafff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0xb000-0xbfff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0xc000-0xcfff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0xd000-0xdfff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0xe000-0xefff */
+ -1, -1, -1, -1, -1, 20, -1, 21, /* 0xf000-0xffff */
+ 22, -1, -1, -1, -1, 23, -1, -1, /* 0x10000-0x10fff */
+ 24, -1, -1, -1, -1, -1, -1, -1, /* 0x11000-0x11fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x12000-0x12fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x13000-0x13fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x14000-0x14fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x15000-0x15fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x16000-0x16fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x17000-0x17fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x18000-0x18fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x19000-0x19fff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1a000-0x1afff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1b000-0x1bfff */
+ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1c000-0x1cfff */
+ 25, 26, -1, -1, -1, -1, -1, -1 /* 0x1d000-0x1dfff */
+};
+
+/* Determine number of column positions required for UC. */
+int
+uc_width (ucs4_t uc, const char *encoding)
+{
+ /* Test for non-spacing or control character. */
+ if ((uc >> 9) < 240)
+ {
+ int ind = nonspacing_table_ind[uc >> 9];
+ if (ind >= 0)
+ if ((nonspacing_table_data[64*ind + ((uc >> 3) & 63)] >> (uc & 7)) & 1)
+ {
+ if (uc > 0 && uc < 0xa0)
+ return -1;
+ else
+ return 0;
+ }
+ }
+ else if ((uc >> 9) == (0xe0000 >> 9))
+ {
+ if (uc >= 0xe0100)
+ {
+ if (uc <= 0xe01ef)
+ return 0;
+ }
+ else
+ {
+ if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001)
+ return 0;
+ }
+ }
+ /* Test for double-width character.
+ * Generated from "grep '^[^;]\{4,5\};[WF]' EastAsianWidth.txt"
+ * and "grep '^[^;]\{4,5\};[^WF]' EastAsianWidth.txt"
+ */
+ if (uc >= 0x1100
+ && ((uc < 0x1160) /* Hangul Jamo */
+ || (uc >= 0x2329 && uc < 0x232b) /* Angle Brackets */
+ || (uc >= 0x2e80 && uc < 0xa4d0 /* CJK ... Yi */
+ && !(uc == 0x303f) && !(uc >= 0x4dc0 && uc < 0x4e00))
+ || (uc >= 0xac00 && uc < 0xd7a4) /* Hangul Syllables */
+ || (uc >= 0xf900 && uc < 0xfb00) /* CJK Compatibility Ideographs */
+ || (uc >= 0xfe10 && uc < 0xfe20) /* Presentation Forms for Vertical */
+ || (uc >= 0xfe30 && uc < 0xfe70) /* CJK Compatibility Forms */
+ || (uc >= 0xff00 && uc < 0xff61) /* Fullwidth Forms */
+ || (uc >= 0xffe0 && uc < 0xffe7) /* Fullwidth Signs */
+ || (uc >= 0x20000 && uc <= 0x2ffff) /* Supplementary Ideographic Plane */
+ || (uc >= 0x30000 && uc <= 0x3ffff) /* Tertiary Ideographic Plane */
+ ) )
+ return 2;
+ /* In ancient CJK encodings, Cyrillic and most other characters are
+ double-width as well. */
+ if (uc >= 0x00A1 && uc < 0xFF61 && uc != 0x20A9
+ && is_cjk_encoding (encoding))
+ return 2;
+ return 1;
+}
diff --git a/contrib/tools/bison/gnulib/src/unlocked-io.h b/contrib/tools/bison/gnulib/src/unlocked-io.h
index df3e13911e..c352d294ad 100644
--- a/contrib/tools/bison/gnulib/src/unlocked-io.h
+++ b/contrib/tools/bison/gnulib/src/unlocked-io.h
@@ -1,136 +1,136 @@
-/* Prefer faster, non-thread-safe stdio functions if available.
-
- Copyright (C) 2001-2004, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#ifndef UNLOCKED_IO_H
-# define UNLOCKED_IO_H 1
-
-/* These are wrappers for functions/macros from the GNU C library, and
- from other C libraries supporting POSIX's optional thread-safe functions.
-
- The standard I/O functions are thread-safe. These *_unlocked ones are
- more efficient but not thread-safe. That they're not thread-safe is
- fine since all of the applications in this package are single threaded.
-
- Also, some code that is shared with the GNU C library may invoke
- the *_unlocked functions directly. On hosts that lack those
- functions, invoke the non-thread-safe versions instead. */
-
-# include <stdio.h>
-
-# if HAVE_DECL_CLEARERR_UNLOCKED
-# undef clearerr
-# define clearerr(x) clearerr_unlocked (x)
-# else
-# define clearerr_unlocked(x) clearerr (x)
-# endif
-
-# if HAVE_DECL_FEOF_UNLOCKED
-# undef feof
-# define feof(x) feof_unlocked (x)
-# else
-# define feof_unlocked(x) feof (x)
-# endif
-
-# if HAVE_DECL_FERROR_UNLOCKED
-# undef ferror
-# define ferror(x) ferror_unlocked (x)
-# else
-# define ferror_unlocked(x) ferror (x)
-# endif
-
-# if HAVE_DECL_FFLUSH_UNLOCKED
-# undef fflush
-# define fflush(x) fflush_unlocked (x)
-# else
-# define fflush_unlocked(x) fflush (x)
-# endif
-
-# if HAVE_DECL_FGETS_UNLOCKED
-# undef fgets
-# define fgets(x,y,z) fgets_unlocked (x,y,z)
-# else
-# define fgets_unlocked(x,y,z) fgets (x,y,z)
-# endif
-
-# if HAVE_DECL_FPUTC_UNLOCKED
-# undef fputc
-# define fputc(x,y) fputc_unlocked (x,y)
-# else
-# define fputc_unlocked(x,y) fputc (x,y)
-# endif
-
-# if HAVE_DECL_FPUTS_UNLOCKED
-# undef fputs
-# define fputs(x,y) fputs_unlocked (x,y)
-# else
-# define fputs_unlocked(x,y) fputs (x,y)
-# endif
-
-# if HAVE_DECL_FREAD_UNLOCKED
-# undef fread
-# define fread(w,x,y,z) fread_unlocked (w,x,y,z)
-# else
-# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
-# endif
-
-# if HAVE_DECL_FWRITE_UNLOCKED
-# undef fwrite
-# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
-# else
-# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
-# endif
-
-# if HAVE_DECL_GETC_UNLOCKED
-# undef getc
-# define getc(x) getc_unlocked (x)
-# else
-# define getc_unlocked(x) getc (x)
-# endif
-
-# if HAVE_DECL_GETCHAR_UNLOCKED
-# undef getchar
-# define getchar() getchar_unlocked ()
-# else
-# define getchar_unlocked() getchar ()
-# endif
-
-# if HAVE_DECL_PUTC_UNLOCKED
-# undef putc
-# define putc(x,y) putc_unlocked (x,y)
-# else
-# define putc_unlocked(x,y) putc (x,y)
-# endif
-
-# if HAVE_DECL_PUTCHAR_UNLOCKED
-# undef putchar
-# define putchar(x) putchar_unlocked (x)
-# else
-# define putchar_unlocked(x) putchar (x)
-# endif
-
-# undef flockfile
-# define flockfile(x) ((void) 0)
-
-# undef ftrylockfile
-# define ftrylockfile(x) 0
-
-# undef funlockfile
-# define funlockfile(x) ((void) 0)
-
-#endif /* UNLOCKED_IO_H */
+/* Prefer faster, non-thread-safe stdio functions if available.
+
+ Copyright (C) 2001-2004, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#ifndef UNLOCKED_IO_H
+# define UNLOCKED_IO_H 1
+
+/* These are wrappers for functions/macros from the GNU C library, and
+ from other C libraries supporting POSIX's optional thread-safe functions.
+
+ The standard I/O functions are thread-safe. These *_unlocked ones are
+ more efficient but not thread-safe. That they're not thread-safe is
+ fine since all of the applications in this package are single threaded.
+
+ Also, some code that is shared with the GNU C library may invoke
+ the *_unlocked functions directly. On hosts that lack those
+ functions, invoke the non-thread-safe versions instead. */
+
+# include <stdio.h>
+
+# if HAVE_DECL_CLEARERR_UNLOCKED
+# undef clearerr
+# define clearerr(x) clearerr_unlocked (x)
+# else
+# define clearerr_unlocked(x) clearerr (x)
+# endif
+
+# if HAVE_DECL_FEOF_UNLOCKED
+# undef feof
+# define feof(x) feof_unlocked (x)
+# else
+# define feof_unlocked(x) feof (x)
+# endif
+
+# if HAVE_DECL_FERROR_UNLOCKED
+# undef ferror
+# define ferror(x) ferror_unlocked (x)
+# else
+# define ferror_unlocked(x) ferror (x)
+# endif
+
+# if HAVE_DECL_FFLUSH_UNLOCKED
+# undef fflush
+# define fflush(x) fflush_unlocked (x)
+# else
+# define fflush_unlocked(x) fflush (x)
+# endif
+
+# if HAVE_DECL_FGETS_UNLOCKED
+# undef fgets
+# define fgets(x,y,z) fgets_unlocked (x,y,z)
+# else
+# define fgets_unlocked(x,y,z) fgets (x,y,z)
+# endif
+
+# if HAVE_DECL_FPUTC_UNLOCKED
+# undef fputc
+# define fputc(x,y) fputc_unlocked (x,y)
+# else
+# define fputc_unlocked(x,y) fputc (x,y)
+# endif
+
+# if HAVE_DECL_FPUTS_UNLOCKED
+# undef fputs
+# define fputs(x,y) fputs_unlocked (x,y)
+# else
+# define fputs_unlocked(x,y) fputs (x,y)
+# endif
+
+# if HAVE_DECL_FREAD_UNLOCKED
+# undef fread
+# define fread(w,x,y,z) fread_unlocked (w,x,y,z)
+# else
+# define fread_unlocked(w,x,y,z) fread (w,x,y,z)
+# endif
+
+# if HAVE_DECL_FWRITE_UNLOCKED
+# undef fwrite
+# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z)
+# else
+# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
+# endif
+
+# if HAVE_DECL_GETC_UNLOCKED
+# undef getc
+# define getc(x) getc_unlocked (x)
+# else
+# define getc_unlocked(x) getc (x)
+# endif
+
+# if HAVE_DECL_GETCHAR_UNLOCKED
+# undef getchar
+# define getchar() getchar_unlocked ()
+# else
+# define getchar_unlocked() getchar ()
+# endif
+
+# if HAVE_DECL_PUTC_UNLOCKED
+# undef putc
+# define putc(x,y) putc_unlocked (x,y)
+# else
+# define putc_unlocked(x,y) putc (x,y)
+# endif
+
+# if HAVE_DECL_PUTCHAR_UNLOCKED
+# undef putchar
+# define putchar(x) putchar_unlocked (x)
+# else
+# define putchar_unlocked(x) putchar (x)
+# endif
+
+# undef flockfile
+# define flockfile(x) ((void) 0)
+
+# undef ftrylockfile
+# define ftrylockfile(x) 0
+
+# undef funlockfile
+# define funlockfile(x) ((void) 0)
+
+#endif /* UNLOCKED_IO_H */
diff --git a/contrib/tools/bison/gnulib/src/unsetenv.c b/contrib/tools/bison/gnulib/src/unsetenv.c
index c58c82f4f4..4ba66bf20d 100644
--- a/contrib/tools/bison/gnulib/src/unsetenv.c
+++ b/contrib/tools/bison/gnulib/src/unsetenv.c
@@ -1,127 +1,127 @@
-/* Copyright (C) 1992, 1995-2002, 2005-2013 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
- optimizes away the name == NULL test below. */
-#define _GL_ARG_NONNULL(params)
-
-#include <config.h>
-
-/* Specification. */
-#include <stdlib.h>
-
-#include <errno.h>
-#if !_LIBC
-# define __set_errno(ev) ((errno) = (ev))
-#endif
-
-#include <string.h>
-#include <unistd.h>
-
-#if !_LIBC
-# define __environ environ
-#endif
-
-#if _LIBC
-/* This lock protects against simultaneous modifications of 'environ'. */
-# include <bits/libc-lock.h>
-__libc_lock_define_initialized (static, envlock)
-# define LOCK __libc_lock_lock (envlock)
-# define UNLOCK __libc_lock_unlock (envlock)
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-/* In the GNU C library we must keep the namespace clean. */
-#ifdef _LIBC
-# define unsetenv __unsetenv
-#endif
-
-#if _LIBC || !HAVE_UNSETENV
-
-int
-unsetenv (const char *name)
-{
- size_t len;
- char **ep;
-
- if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- len = strlen (name);
-
- LOCK;
-
- ep = __environ;
- while (*ep != NULL)
- if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
- {
- /* Found it. Remove this pointer by moving later ones back. */
- char **dp = ep;
-
- do
- dp[0] = dp[1];
- while (*dp++);
- /* Continue the loop in case NAME appears again. */
- }
- else
- ++ep;
-
- UNLOCK;
-
- return 0;
-}
-
-#ifdef _LIBC
-# undef unsetenv
-weak_alias (__unsetenv, unsetenv)
-#endif
-
-#else /* HAVE_UNSETENV */
-
-# undef unsetenv
-# if !HAVE_DECL_UNSETENV
-# if VOID_UNSETENV
-extern void unsetenv (const char *);
-# else
-extern int unsetenv (const char *);
-# endif
-# endif
-
-/* Call the underlying unsetenv, in case there is hidden bookkeeping
- that needs updating beyond just modifying environ. */
-int
-rpl_unsetenv (const char *name)
-{
- int result = 0;
- if (!name || !*name || strchr (name, '='))
- {
- errno = EINVAL;
- return -1;
- }
- while (getenv (name))
-# if !VOID_UNSETENV
- result =
-# endif
- unsetenv (name);
- return result;
-}
-
-#endif /* HAVE_UNSETENV */
+/* Copyright (C) 1992, 1995-2002, 2005-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
+ optimizes away the name == NULL test below. */
+#define _GL_ARG_NONNULL(params)
+
+#include <config.h>
+
+/* Specification. */
+#include <stdlib.h>
+
+#include <errno.h>
+#if !_LIBC
+# define __set_errno(ev) ((errno) = (ev))
+#endif
+
+#include <string.h>
+#include <unistd.h>
+
+#if !_LIBC
+# define __environ environ
+#endif
+
+#if _LIBC
+/* This lock protects against simultaneous modifications of 'environ'. */
+# include <bits/libc-lock.h>
+__libc_lock_define_initialized (static, envlock)
+# define LOCK __libc_lock_lock (envlock)
+# define UNLOCK __libc_lock_unlock (envlock)
+#else
+# define LOCK
+# define UNLOCK
+#endif
+
+/* In the GNU C library we must keep the namespace clean. */
+#ifdef _LIBC
+# define unsetenv __unsetenv
+#endif
+
+#if _LIBC || !HAVE_UNSETENV
+
+int
+unsetenv (const char *name)
+{
+ size_t len;
+ char **ep;
+
+ if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+
+ len = strlen (name);
+
+ LOCK;
+
+ ep = __environ;
+ while (*ep != NULL)
+ if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
+ {
+ /* Found it. Remove this pointer by moving later ones back. */
+ char **dp = ep;
+
+ do
+ dp[0] = dp[1];
+ while (*dp++);
+ /* Continue the loop in case NAME appears again. */
+ }
+ else
+ ++ep;
+
+ UNLOCK;
+
+ return 0;
+}
+
+#ifdef _LIBC
+# undef unsetenv
+weak_alias (__unsetenv, unsetenv)
+#endif
+
+#else /* HAVE_UNSETENV */
+
+# undef unsetenv
+# if !HAVE_DECL_UNSETENV
+# if VOID_UNSETENV
+extern void unsetenv (const char *);
+# else
+extern int unsetenv (const char *);
+# endif
+# endif
+
+/* Call the underlying unsetenv, in case there is hidden bookkeeping
+ that needs updating beyond just modifying environ. */
+int
+rpl_unsetenv (const char *name)
+{
+ int result = 0;
+ if (!name || !*name || strchr (name, '='))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ while (getenv (name))
+# if !VOID_UNSETENV
+ result =
+# endif
+ unsetenv (name);
+ return result;
+}
+
+#endif /* HAVE_UNSETENV */
diff --git a/contrib/tools/bison/gnulib/src/vasnprintf.c b/contrib/tools/bison/gnulib/src/vasnprintf.c
index 4de22819fa..e6a118d1ef 100644
--- a/contrib/tools/bison/gnulib/src/vasnprintf.c
+++ b/contrib/tools/bison/gnulib/src/vasnprintf.c
@@ -1,5610 +1,5610 @@
-/* vsprintf with automatic memory allocation.
- Copyright (C) 1999, 2002-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-/* This file can be parametrized with the following macros:
- VASNPRINTF The name of the function being defined.
- FCHAR_T The element type of the format string.
- DCHAR_T The element type of the destination (result) string.
- FCHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
- in the format string are ASCII. MUST be set if
- FCHAR_T and DCHAR_T are not the same type.
- DIRECTIVE Structure denoting a format directive.
- Depends on FCHAR_T.
- DIRECTIVES Structure denoting the set of format directives of a
- format string. Depends on FCHAR_T.
- PRINTF_PARSE Function that parses a format string.
- Depends on FCHAR_T.
- DCHAR_CPY memcpy like function for DCHAR_T[] arrays.
- DCHAR_SET memset like function for DCHAR_T[] arrays.
- DCHAR_MBSNLEN mbsnlen like function for DCHAR_T[] arrays.
- SNPRINTF The system's snprintf (or similar) function.
- This may be either snprintf or swprintf.
- TCHAR_T The element type of the argument and result string
- of the said SNPRINTF function. This may be either
- char or wchar_t. The code exploits that
- sizeof (TCHAR_T) | sizeof (DCHAR_T) and
- alignof (TCHAR_T) <= alignof (DCHAR_T).
- DCHAR_IS_TCHAR Set to 1 if DCHAR_T and TCHAR_T are the same type.
- DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[].
- DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t.
- DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t.
- DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */
-
-/* Tell glibc's <stdio.h> to provide a prototype for snprintf().
- This must come before <config.h> because <config.h> may include
- <features.h>, and once <features.h> has been included, it's too late. */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
-
-#ifndef VASNPRINTF
-# include <config.h>
-#endif
-#ifndef IN_LIBINTL
+/* vsprintf with automatic memory allocation.
+ Copyright (C) 1999, 2002-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+/* This file can be parametrized with the following macros:
+ VASNPRINTF The name of the function being defined.
+ FCHAR_T The element type of the format string.
+ DCHAR_T The element type of the destination (result) string.
+ FCHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
+ in the format string are ASCII. MUST be set if
+ FCHAR_T and DCHAR_T are not the same type.
+ DIRECTIVE Structure denoting a format directive.
+ Depends on FCHAR_T.
+ DIRECTIVES Structure denoting the set of format directives of a
+ format string. Depends on FCHAR_T.
+ PRINTF_PARSE Function that parses a format string.
+ Depends on FCHAR_T.
+ DCHAR_CPY memcpy like function for DCHAR_T[] arrays.
+ DCHAR_SET memset like function for DCHAR_T[] arrays.
+ DCHAR_MBSNLEN mbsnlen like function for DCHAR_T[] arrays.
+ SNPRINTF The system's snprintf (or similar) function.
+ This may be either snprintf or swprintf.
+ TCHAR_T The element type of the argument and result string
+ of the said SNPRINTF function. This may be either
+ char or wchar_t. The code exploits that
+ sizeof (TCHAR_T) | sizeof (DCHAR_T) and
+ alignof (TCHAR_T) <= alignof (DCHAR_T).
+ DCHAR_IS_TCHAR Set to 1 if DCHAR_T and TCHAR_T are the same type.
+ DCHAR_CONV_FROM_ENCODING A function to convert from char[] to DCHAR[].
+ DCHAR_IS_UINT8_T Set to 1 if DCHAR_T is uint8_t.
+ DCHAR_IS_UINT16_T Set to 1 if DCHAR_T is uint16_t.
+ DCHAR_IS_UINT32_T Set to 1 if DCHAR_T is uint32_t. */
+
+/* Tell glibc's <stdio.h> to provide a prototype for snprintf().
+ This must come before <config.h> because <config.h> may include
+ <features.h>, and once <features.h> has been included, it's too late. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+#ifndef VASNPRINTF
+# include <config.h>
+#endif
+#ifndef IN_LIBINTL
# include "palloca.h"
-#endif
-
-/* Specification. */
-#ifndef VASNPRINTF
-# if WIDE_CHAR_VERSION
-# include "vasnwprintf.h"
-# else
-# include "vasnprintf.h"
-# endif
-#endif
-
-#include <locale.h> /* localeconv() */
-#include <stdio.h> /* snprintf(), sprintf() */
-#include <stdlib.h> /* abort(), malloc(), realloc(), free() */
-#include <string.h> /* memcpy(), strlen() */
-#include <errno.h> /* errno */
-#include <limits.h> /* CHAR_BIT */
-#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
-#if HAVE_NL_LANGINFO
-# include <langinfo.h>
-#endif
-#ifndef VASNPRINTF
-# if WIDE_CHAR_VERSION
-# include "wprintf-parse.h"
-# else
-# include "printf-parse.h"
-# endif
-#endif
-
-/* Checked size_t computations. */
-#include "xsize.h"
-
-#include "verify.h"
-
-#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
-# include <math.h>
-# include "float+.h"
-#endif
-
-#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
-# include <math.h>
-# include "isnand-nolibm.h"
-#endif
-
-#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) && !defined IN_LIBINTL
-# include <math.h>
-# include "isnanl-nolibm.h"
-# include "fpucw.h"
-#endif
-
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
-# include <math.h>
-# include "isnand-nolibm.h"
-# include "printf-frexp.h"
-#endif
-
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
-# include <math.h>
-# include "isnanl-nolibm.h"
-# include "printf-frexpl.h"
-# include "fpucw.h"
-#endif
-
-/* Default parameters. */
-#ifndef VASNPRINTF
-# if WIDE_CHAR_VERSION
-# define VASNPRINTF vasnwprintf
-# define FCHAR_T wchar_t
-# define DCHAR_T wchar_t
-# define TCHAR_T wchar_t
-# define DCHAR_IS_TCHAR 1
-# define DIRECTIVE wchar_t_directive
-# define DIRECTIVES wchar_t_directives
-# define PRINTF_PARSE wprintf_parse
-# define DCHAR_CPY wmemcpy
-# define DCHAR_SET wmemset
-# else
-# define VASNPRINTF vasnprintf
-# define FCHAR_T char
-# define DCHAR_T char
-# define TCHAR_T char
-# define DCHAR_IS_TCHAR 1
-# define DIRECTIVE char_directive
-# define DIRECTIVES char_directives
-# define PRINTF_PARSE printf_parse
-# define DCHAR_CPY memcpy
-# define DCHAR_SET memset
-# endif
-#endif
-#if WIDE_CHAR_VERSION
- /* TCHAR_T is wchar_t. */
-# define USE_SNPRINTF 1
-# if HAVE_DECL__SNWPRINTF
- /* On Windows, the function swprintf() has a different signature than
- on Unix; we use the function _snwprintf() or - on mingw - snwprintf()
- instead. The mingw function snwprintf() has fewer bugs than the
- MSVCRT function _snwprintf(), so prefer that. */
-# if defined __MINGW32__
-# define SNPRINTF snwprintf
-# else
-# define SNPRINTF _snwprintf
-# endif
-# else
- /* Unix. */
-# define SNPRINTF swprintf
-# endif
-#else
- /* TCHAR_T is char. */
- /* Use snprintf if it exists under the name 'snprintf' or '_snprintf'.
- But don't use it on BeOS, since BeOS snprintf produces no output if the
- size argument is >= 0x3000000.
- Also don't use it on Linux libc5, since there snprintf with size = 1
- writes any output without bounds, like sprintf. */
-# if (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) && !defined __BEOS__ && !(__GNU_LIBRARY__ == 1)
-# define USE_SNPRINTF 1
-# else
-# define USE_SNPRINTF 0
-# endif
-# if HAVE_DECL__SNPRINTF
- /* Windows. The mingw function snprintf() has fewer bugs than the MSVCRT
- function _snprintf(), so prefer that. */
-# if defined __MINGW32__
-# define SNPRINTF snprintf
- /* Here we need to call the native snprintf, not rpl_snprintf. */
-# undef snprintf
-# else
-# define SNPRINTF _snprintf
-# endif
-# else
- /* Unix. */
-# define SNPRINTF snprintf
- /* Here we need to call the native snprintf, not rpl_snprintf. */
-# undef snprintf
-# endif
-#endif
-/* Here we need to call the native sprintf, not rpl_sprintf. */
-#undef sprintf
-
-/* GCC >= 4.0 with -Wall emits unjustified "... may be used uninitialized"
- warnings in this file. Use -Dlint to suppress them. */
-#ifdef lint
-# define IF_LINT(Code) Code
-#else
-# define IF_LINT(Code) /* empty */
-#endif
-
-/* Avoid some warnings from "gcc -Wshadow".
- This file doesn't use the exp() and remainder() functions. */
-#undef exp
-#define exp expo
-#undef remainder
-#define remainder rem
-
-#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && !WIDE_CHAR_VERSION
-# if (HAVE_STRNLEN && !defined _AIX)
-# define local_strnlen strnlen
-# else
-# ifndef local_strnlen_defined
-# define local_strnlen_defined 1
-static size_t
-local_strnlen (const char *string, size_t maxlen)
-{
- const char *end = memchr (string, '\0', maxlen);
- return end ? (size_t) (end - string) : maxlen;
-}
-# endif
-# endif
-#endif
-
-#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
-# if HAVE_WCSLEN
-# define local_wcslen wcslen
-# else
- /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
- a dependency towards this library, here is a local substitute.
- Define this substitute only once, even if this file is included
- twice in the same compilation unit. */
-# ifndef local_wcslen_defined
-# define local_wcslen_defined 1
-static size_t
-local_wcslen (const wchar_t *s)
-{
- const wchar_t *ptr;
-
- for (ptr = s; *ptr != (wchar_t) 0; ptr++)
- ;
- return ptr - s;
-}
-# endif
-# endif
-#endif
-
-#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
-# if HAVE_WCSNLEN
-# define local_wcsnlen wcsnlen
-# else
-# ifndef local_wcsnlen_defined
-# define local_wcsnlen_defined 1
-static size_t
-local_wcsnlen (const wchar_t *s, size_t maxlen)
-{
- const wchar_t *ptr;
-
- for (ptr = s; maxlen > 0 && *ptr != (wchar_t) 0; ptr++, maxlen--)
- ;
- return ptr - s;
-}
-# endif
-# endif
-#endif
-
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
-/* Determine the decimal-point character according to the current locale. */
-# ifndef decimal_point_char_defined
-# define decimal_point_char_defined 1
-static char
-decimal_point_char (void)
-{
- const char *point;
- /* Determine it in a multithread-safe way. We know nl_langinfo is
- multithread-safe on glibc systems and Mac OS X systems, but is not required
- to be multithread-safe by POSIX. sprintf(), however, is multithread-safe.
- localeconv() is rarely multithread-safe. */
-# if HAVE_NL_LANGINFO && (__GLIBC__ || defined __UCLIBC__ || (defined __APPLE__ && defined __MACH__))
- point = nl_langinfo (RADIXCHAR);
-# elif 1
- char pointbuf[5];
- sprintf (pointbuf, "%#.0f", 1.0);
- point = &pointbuf[1];
-# else
- point = localeconv () -> decimal_point;
-# endif
- /* The decimal point is always a single byte: either '.' or ','. */
- return (point[0] != '\0' ? point[0] : '.');
-}
-# endif
-#endif
-
-#if NEED_PRINTF_INFINITE_DOUBLE && !NEED_PRINTF_DOUBLE && !defined IN_LIBINTL
-
-/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */
-static int
-is_infinite_or_zero (double x)
-{
- return isnand (x) || x + x == x;
-}
-
-#endif
-
-#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL
-
-/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */
-static int
-is_infinite_or_zerol (long double x)
-{
- return isnanl (x) || x + x == x;
-}
-
-#endif
-
-#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
-
-/* Converting 'long double' to decimal without rare rounding bugs requires
- real bignums. We use the naming conventions of GNU gmp, but vastly simpler
- (and slower) algorithms. */
-
-typedef unsigned int mp_limb_t;
-# define GMP_LIMB_BITS 32
-verify (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS);
-
-typedef unsigned long long mp_twolimb_t;
-# define GMP_TWOLIMB_BITS 64
-verify (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS);
-
-/* Representation of a bignum >= 0. */
-typedef struct
-{
- size_t nlimbs;
- mp_limb_t *limbs; /* Bits in little-endian order, allocated with malloc(). */
-} mpn_t;
-
-/* Compute the product of two bignums >= 0.
- Return the allocated memory in case of success, NULL in case of memory
- allocation failure. */
-static void *
-multiply (mpn_t src1, mpn_t src2, mpn_t *dest)
-{
- const mp_limb_t *p1;
- const mp_limb_t *p2;
- size_t len1;
- size_t len2;
-
- if (src1.nlimbs <= src2.nlimbs)
- {
- len1 = src1.nlimbs;
- p1 = src1.limbs;
- len2 = src2.nlimbs;
- p2 = src2.limbs;
- }
- else
- {
- len1 = src2.nlimbs;
- p1 = src2.limbs;
- len2 = src1.nlimbs;
- p2 = src1.limbs;
- }
- /* Now 0 <= len1 <= len2. */
- if (len1 == 0)
- {
- /* src1 or src2 is zero. */
- dest->nlimbs = 0;
- dest->limbs = (mp_limb_t *) malloc (1);
- }
- else
- {
- /* Here 1 <= len1 <= len2. */
- size_t dlen;
- mp_limb_t *dp;
- size_t k, i, j;
-
- dlen = len1 + len2;
- dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t));
- if (dp == NULL)
- return NULL;
- for (k = len2; k > 0; )
- dp[--k] = 0;
- for (i = 0; i < len1; i++)
- {
- mp_limb_t digit1 = p1[i];
- mp_twolimb_t carry = 0;
- for (j = 0; j < len2; j++)
- {
- mp_limb_t digit2 = p2[j];
- carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
- carry += dp[i + j];
- dp[i + j] = (mp_limb_t) carry;
- carry = carry >> GMP_LIMB_BITS;
- }
- dp[i + len2] = (mp_limb_t) carry;
- }
- /* Normalise. */
- while (dlen > 0 && dp[dlen - 1] == 0)
- dlen--;
- dest->nlimbs = dlen;
- dest->limbs = dp;
- }
- return dest->limbs;
-}
-
-/* Compute the quotient of a bignum a >= 0 and a bignum b > 0.
- a is written as a = q * b + r with 0 <= r < b. q is the quotient, r
- the remainder.
- Finally, round-to-even is performed: If r > b/2 or if r = b/2 and q is odd,
- q is incremented.
- Return the allocated memory in case of success, NULL in case of memory
- allocation failure. */
-static void *
-divide (mpn_t a, mpn_t b, mpn_t *q)
-{
- /* Algorithm:
- First normalise a and b: a=[a[m-1],...,a[0]], b=[b[n-1],...,b[0]]
- with m>=0 and n>0 (in base beta = 2^GMP_LIMB_BITS).
- If m<n, then q:=0 and r:=a.
- If m>=n=1, perform a single-precision division:
- r:=0, j:=m,
- while j>0 do
- {Here (q[m-1]*beta^(m-1)+...+q[j]*beta^j) * b[0] + r*beta^j =
- = a[m-1]*beta^(m-1)+...+a[j]*beta^j und 0<=r<b[0]<beta}
- j:=j-1, r:=r*beta+a[j], q[j]:=floor(r/b[0]), r:=r-b[0]*q[j].
- Normalise [q[m-1],...,q[0]], yields q.
- If m>=n>1, perform a multiple-precision division:
- We have a/b < beta^(m-n+1).
- s:=intDsize-1-(highest bit in b[n-1]), 0<=s<intDsize.
- Shift a and b left by s bits, copying them. r:=a.
- r=[r[m],...,r[0]], b=[b[n-1],...,b[0]] with b[n-1]>=beta/2.
- For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).}
- Compute q* :
- q* := floor((r[j+n]*beta+r[j+n-1])/b[n-1]).
- In case of overflow (q* >= beta) set q* := beta-1.
- Compute c2 := ((r[j+n]*beta+r[j+n-1]) - q* * b[n-1])*beta + r[j+n-2]
- and c3 := b[n-2] * q*.
- {We have 0 <= c2 < 2*beta^2, even 0 <= c2 < beta^2 if no overflow
- occurred. Furthermore 0 <= c3 < beta^2.
- If there was overflow and
- r[j+n]*beta+r[j+n-1] - q* * b[n-1] >= beta, i.e. c2 >= beta^2,
- the next test can be skipped.}
- While c3 > c2, {Here 0 <= c2 < c3 < beta^2}
- Put q* := q* - 1, c2 := c2 + b[n-1]*beta, c3 := c3 - b[n-2].
- If q* > 0:
- Put r := r - b * q* * beta^j. In detail:
- [r[n+j],...,r[j]] := [r[n+j],...,r[j]] - q* * [b[n-1],...,b[0]].
- hence: u:=0, for i:=0 to n-1 do
- u := u + q* * b[i],
- r[j+i]:=r[j+i]-(u mod beta) (+ beta, if carry),
- u:=u div beta (+ 1, if carry in subtraction)
- r[n+j]:=r[n+j]-u.
- {Since always u = (q* * [b[i-1],...,b[0]] div beta^i) + 1
- < q* + 1 <= beta,
- the carry u does not overflow.}
- If a negative carry occurs, put q* := q* - 1
- and [r[n+j],...,r[j]] := [r[n+j],...,r[j]] + [0,b[n-1],...,b[0]].
- Set q[j] := q*.
- Normalise [q[m-n],..,q[0]]; this yields the quotient q.
- Shift [r[n-1],...,r[0]] right by s bits and normalise; this yields the
- rest r.
- The room for q[j] can be allocated at the memory location of r[n+j].
- Finally, round-to-even:
- Shift r left by 1 bit.
- If r > b or if r = b and q[0] is odd, q := q+1.
- */
- const mp_limb_t *a_ptr = a.limbs;
- size_t a_len = a.nlimbs;
- const mp_limb_t *b_ptr = b.limbs;
- size_t b_len = b.nlimbs;
- mp_limb_t *roomptr;
- mp_limb_t *tmp_roomptr = NULL;
- mp_limb_t *q_ptr;
- size_t q_len;
- mp_limb_t *r_ptr;
- size_t r_len;
-
- /* Allocate room for a_len+2 digits.
- (Need a_len+1 digits for the real division and 1 more digit for the
- final rounding of q.) */
- roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t));
- if (roomptr == NULL)
- return NULL;
-
- /* Normalise a. */
- while (a_len > 0 && a_ptr[a_len - 1] == 0)
- a_len--;
-
- /* Normalise b. */
- for (;;)
- {
- if (b_len == 0)
- /* Division by zero. */
- abort ();
- if (b_ptr[b_len - 1] == 0)
- b_len--;
- else
- break;
- }
-
- /* Here m = a_len >= 0 and n = b_len > 0. */
-
- if (a_len < b_len)
- {
- /* m<n: trivial case. q=0, r := copy of a. */
- r_ptr = roomptr;
- r_len = a_len;
- memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t));
- q_ptr = roomptr + a_len;
- q_len = 0;
- }
- else if (b_len == 1)
- {
- /* n=1: single precision division.
- beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */
- r_ptr = roomptr;
- q_ptr = roomptr + 1;
- {
- mp_limb_t den = b_ptr[0];
- mp_limb_t remainder = 0;
- const mp_limb_t *sourceptr = a_ptr + a_len;
- mp_limb_t *destptr = q_ptr + a_len;
- size_t count;
- for (count = a_len; count > 0; count--)
- {
- mp_twolimb_t num =
- ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr;
- *--destptr = num / den;
- remainder = num % den;
- }
- /* Normalise and store r. */
- if (remainder > 0)
- {
- r_ptr[0] = remainder;
- r_len = 1;
- }
- else
- r_len = 0;
- /* Normalise q. */
- q_len = a_len;
- if (q_ptr[q_len - 1] == 0)
- q_len--;
- }
- }
- else
- {
- /* n>1: multiple precision division.
- beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==>
- beta^(m-n-1) <= a/b < beta^(m-n+1). */
- /* Determine s. */
- size_t s;
- {
- mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
- /* Determine s = GMP_LIMB_BITS - integer_length (msd).
- Code copied from gnulib's integer_length.c. */
-# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
- s = __builtin_clz (msd);
-# else
-# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
- if (GMP_LIMB_BITS <= DBL_MANT_BIT)
- {
- /* Use 'double' operations.
- Assumes an IEEE 754 'double' implementation. */
-# define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
-# define DBL_EXP_BIAS (DBL_EXP_MASK / 2 - 1)
-# define NWORDS \
- ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
- union { double value; unsigned int word[NWORDS]; } m;
-
- /* Use a single integer to floating-point conversion. */
- m.value = msd;
-
- s = GMP_LIMB_BITS
- - (((m.word[DBL_EXPBIT0_WORD] >> DBL_EXPBIT0_BIT) & DBL_EXP_MASK)
- - DBL_EXP_BIAS);
- }
- else
-# undef NWORDS
-# endif
- {
- s = 31;
- if (msd >= 0x10000)
- {
- msd = msd >> 16;
- s -= 16;
- }
- if (msd >= 0x100)
- {
- msd = msd >> 8;
- s -= 8;
- }
- if (msd >= 0x10)
- {
- msd = msd >> 4;
- s -= 4;
- }
- if (msd >= 0x4)
- {
- msd = msd >> 2;
- s -= 2;
- }
- if (msd >= 0x2)
- {
- msd = msd >> 1;
- s -= 1;
- }
- }
-# endif
- }
- /* 0 <= s < GMP_LIMB_BITS.
- Copy b, shifting it left by s bits. */
- if (s > 0)
- {
- tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t));
- if (tmp_roomptr == NULL)
- {
- free (roomptr);
- return NULL;
- }
- {
- const mp_limb_t *sourceptr = b_ptr;
- mp_limb_t *destptr = tmp_roomptr;
- mp_twolimb_t accu = 0;
- size_t count;
- for (count = b_len; count > 0; count--)
- {
- accu += (mp_twolimb_t) *sourceptr++ << s;
- *destptr++ = (mp_limb_t) accu;
- accu = accu >> GMP_LIMB_BITS;
- }
- /* accu must be zero, since that was how s was determined. */
- if (accu != 0)
- abort ();
- }
- b_ptr = tmp_roomptr;
- }
- /* Copy a, shifting it left by s bits, yields r.
- Memory layout:
- At the beginning: r = roomptr[0..a_len],
- at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */
- r_ptr = roomptr;
- if (s == 0)
- {
- memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t));
- r_ptr[a_len] = 0;
- }
- else
- {
- const mp_limb_t *sourceptr = a_ptr;
- mp_limb_t *destptr = r_ptr;
- mp_twolimb_t accu = 0;
- size_t count;
- for (count = a_len; count > 0; count--)
- {
- accu += (mp_twolimb_t) *sourceptr++ << s;
- *destptr++ = (mp_limb_t) accu;
- accu = accu >> GMP_LIMB_BITS;
- }
- *destptr++ = (mp_limb_t) accu;
- }
- q_ptr = roomptr + b_len;
- q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */
- {
- size_t j = a_len - b_len; /* m-n */
- mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */
- mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */
- mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */
- ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd;
- /* Division loop, traversed m-n+1 times.
- j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */
- for (;;)
- {
- mp_limb_t q_star;
- mp_limb_t c1;
- if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */
- {
- /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */
- mp_twolimb_t num =
- ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS)
- | r_ptr[j + b_len - 1];
- q_star = num / b_msd;
- c1 = num % b_msd;
- }
- else
- {
- /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */
- q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */
- /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta
- <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta
- <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta)
- {<= beta !}.
- If yes, jump directly to the subtraction loop.
- (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta
- <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */
- if (r_ptr[j + b_len] > b_msd
- || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd)
- /* r[j+n] >= b[n-1]+1 or
- r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a
- carry. */
- goto subtract;
- }
- /* q_star = q*,
- c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, <beta). */
- {
- mp_twolimb_t c2 = /* c1*beta+r[j+n-2] */
- ((mp_twolimb_t) c1 << GMP_LIMB_BITS) | r_ptr[j + b_len - 2];
- mp_twolimb_t c3 = /* b[n-2] * q* */
- (mp_twolimb_t) b_2msd * (mp_twolimb_t) q_star;
- /* While c2 < c3, increase c2 and decrease c3.
- Consider c3-c2. While it is > 0, decrease it by
- b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2
- this can happen only twice. */
- if (c3 > c2)
- {
- q_star = q_star - 1; /* q* := q* - 1 */
- if (c3 - c2 > b_msdd)
- q_star = q_star - 1; /* q* := q* - 1 */
- }
- }
- if (q_star > 0)
- subtract:
- {
- /* Subtract r := r - b * q* * beta^j. */
- mp_limb_t cr;
- {
- const mp_limb_t *sourceptr = b_ptr;
- mp_limb_t *destptr = r_ptr + j;
- mp_twolimb_t carry = 0;
- size_t count;
- for (count = b_len; count > 0; count--)
- {
- /* Here 0 <= carry <= q*. */
- carry =
- carry
- + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++
- + (mp_limb_t) ~(*destptr);
- /* Here 0 <= carry <= beta*q* + beta-1. */
- *destptr++ = ~(mp_limb_t) carry;
- carry = carry >> GMP_LIMB_BITS; /* <= q* */
- }
- cr = (mp_limb_t) carry;
- }
- /* Subtract cr from r_ptr[j + b_len], then forget about
- r_ptr[j + b_len]. */
- if (cr > r_ptr[j + b_len])
- {
- /* Subtraction gave a carry. */
- q_star = q_star - 1; /* q* := q* - 1 */
- /* Add b back. */
- {
- const mp_limb_t *sourceptr = b_ptr;
- mp_limb_t *destptr = r_ptr + j;
- mp_limb_t carry = 0;
- size_t count;
- for (count = b_len; count > 0; count--)
- {
- mp_limb_t source1 = *sourceptr++;
- mp_limb_t source2 = *destptr;
- *destptr++ = source1 + source2 + carry;
- carry =
- (carry
- ? source1 >= (mp_limb_t) ~source2
- : source1 > (mp_limb_t) ~source2);
- }
- }
- /* Forget about the carry and about r[j+n]. */
- }
- }
- /* q* is determined. Store it as q[j]. */
- q_ptr[j] = q_star;
- if (j == 0)
- break;
- j--;
- }
- }
- r_len = b_len;
- /* Normalise q. */
- if (q_ptr[q_len - 1] == 0)
- q_len--;
-# if 0 /* Not needed here, since we need r only to compare it with b/2, and
- b is shifted left by s bits. */
- /* Shift r right by s bits. */
- if (s > 0)
- {
- mp_limb_t ptr = r_ptr + r_len;
- mp_twolimb_t accu = 0;
- size_t count;
- for (count = r_len; count > 0; count--)
- {
- accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS;
- accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s);
- *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS);
- }
- }
-# endif
- /* Normalise r. */
- while (r_len > 0 && r_ptr[r_len - 1] == 0)
- r_len--;
- }
- /* Compare r << 1 with b. */
- if (r_len > b_len)
- goto increment_q;
- {
- size_t i;
- for (i = b_len;;)
- {
- mp_limb_t r_i =
- (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0)
- | (i < r_len ? r_ptr[i] << 1 : 0);
- mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0);
- if (r_i > b_i)
- goto increment_q;
- if (r_i < b_i)
- goto keep_q;
- if (i == 0)
- break;
- i--;
- }
- }
- if (q_len > 0 && ((q_ptr[0] & 1) != 0))
- /* q is odd. */
- increment_q:
- {
- size_t i;
- for (i = 0; i < q_len; i++)
- if (++(q_ptr[i]) != 0)
- goto keep_q;
- q_ptr[q_len++] = 1;
- }
- keep_q:
- if (tmp_roomptr != NULL)
- free (tmp_roomptr);
- q->limbs = q_ptr;
- q->nlimbs = q_len;
- return roomptr;
-}
-
-/* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal
- representation.
- Destroys the contents of a.
- Return the allocated memory - containing the decimal digits in low-to-high
- order, terminated with a NUL character - in case of success, NULL in case
- of memory allocation failure. */
-static char *
-convert_to_decimal (mpn_t a, size_t extra_zeroes)
-{
- mp_limb_t *a_ptr = a.limbs;
- size_t a_len = a.nlimbs;
- /* 0.03345 is slightly larger than log(2)/(9*log(10)). */
- size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1);
- char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes));
- if (c_ptr != NULL)
- {
- char *d_ptr = c_ptr;
- for (; extra_zeroes > 0; extra_zeroes--)
- *d_ptr++ = '0';
- while (a_len > 0)
- {
- /* Divide a by 10^9, in-place. */
- mp_limb_t remainder = 0;
- mp_limb_t *ptr = a_ptr + a_len;
- size_t count;
- for (count = a_len; count > 0; count--)
- {
- mp_twolimb_t num =
- ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr;
- *ptr = num / 1000000000;
- remainder = num % 1000000000;
- }
- /* Store the remainder as 9 decimal digits. */
- for (count = 9; count > 0; count--)
- {
- *d_ptr++ = '0' + (remainder % 10);
- remainder = remainder / 10;
- }
- /* Normalize a. */
- if (a_ptr[a_len - 1] == 0)
- a_len--;
- }
- /* Remove leading zeroes. */
- while (d_ptr > c_ptr && d_ptr[-1] == '0')
- d_ptr--;
- /* But keep at least one zero. */
- if (d_ptr == c_ptr)
- *d_ptr++ = '0';
- /* Terminate the string. */
- *d_ptr = '\0';
- }
- return c_ptr;
-}
-
-# if NEED_PRINTF_LONG_DOUBLE
-
-/* Assuming x is finite and >= 0:
- write x as x = 2^e * m, where m is a bignum.
- Return the allocated memory in case of success, NULL in case of memory
- allocation failure. */
-static void *
-decode_long_double (long double x, int *ep, mpn_t *mp)
-{
- mpn_t m;
- int exp;
- long double y;
- size_t i;
-
- /* Allocate memory for result. */
- m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
- m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
- if (m.limbs == NULL)
- return NULL;
- /* Split into exponential part and mantissa. */
- y = frexpl (x, &exp);
- if (!(y >= 0.0L && y < 1.0L))
- abort ();
- /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * 2^LDBL_MANT_BIT), and the
- latter is an integer. */
- /* Convert the mantissa (y * 2^LDBL_MANT_BIT) to a sequence of limbs.
- I'm not sure whether it's safe to cast a 'long double' value between
- 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
- 'long double' values between 0 and 2^16 (to 'unsigned int' or 'int',
- doesn't matter). */
-# if (LDBL_MANT_BIT % GMP_LIMB_BITS) != 0
-# if (LDBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2
- {
- mp_limb_t hi, lo;
- y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % (GMP_LIMB_BITS / 2));
- hi = (int) y;
- y -= hi;
- if (!(y >= 0.0L && y < 1.0L))
- abort ();
- y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
- lo = (int) y;
- y -= lo;
- if (!(y >= 0.0L && y < 1.0L))
- abort ();
- m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
- }
-# else
- {
- mp_limb_t d;
- y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % GMP_LIMB_BITS);
- d = (int) y;
- y -= d;
- if (!(y >= 0.0L && y < 1.0L))
- abort ();
- m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d;
- }
-# endif
-# endif
- for (i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
- {
- mp_limb_t hi, lo;
- y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
- hi = (int) y;
- y -= hi;
- if (!(y >= 0.0L && y < 1.0L))
- abort ();
- y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
- lo = (int) y;
- y -= lo;
- if (!(y >= 0.0L && y < 1.0L))
- abort ();
- m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
- }
-# if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
- precision. */
- if (!(y == 0.0L))
- abort ();
-# endif
- /* Normalise. */
- while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
- m.nlimbs--;
- *mp = m;
- *ep = exp - LDBL_MANT_BIT;
- return m.limbs;
-}
-
-# endif
-
-# if NEED_PRINTF_DOUBLE
-
-/* Assuming x is finite and >= 0:
- write x as x = 2^e * m, where m is a bignum.
- Return the allocated memory in case of success, NULL in case of memory
- allocation failure. */
-static void *
-decode_double (double x, int *ep, mpn_t *mp)
-{
- mpn_t m;
- int exp;
- double y;
- size_t i;
-
- /* Allocate memory for result. */
- m.nlimbs = (DBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
- m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
- if (m.limbs == NULL)
- return NULL;
- /* Split into exponential part and mantissa. */
- y = frexp (x, &exp);
- if (!(y >= 0.0 && y < 1.0))
- abort ();
- /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * 2^DBL_MANT_BIT), and the
- latter is an integer. */
- /* Convert the mantissa (y * 2^DBL_MANT_BIT) to a sequence of limbs.
- I'm not sure whether it's safe to cast a 'double' value between
- 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
- 'double' values between 0 and 2^16 (to 'unsigned int' or 'int',
- doesn't matter). */
-# if (DBL_MANT_BIT % GMP_LIMB_BITS) != 0
-# if (DBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2
- {
- mp_limb_t hi, lo;
- y *= (mp_limb_t) 1 << (DBL_MANT_BIT % (GMP_LIMB_BITS / 2));
- hi = (int) y;
- y -= hi;
- if (!(y >= 0.0 && y < 1.0))
- abort ();
- y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
- lo = (int) y;
- y -= lo;
- if (!(y >= 0.0 && y < 1.0))
- abort ();
- m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
- }
-# else
- {
- mp_limb_t d;
- y *= (mp_limb_t) 1 << (DBL_MANT_BIT % GMP_LIMB_BITS);
- d = (int) y;
- y -= d;
- if (!(y >= 0.0 && y < 1.0))
- abort ();
- m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d;
- }
-# endif
-# endif
- for (i = DBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
- {
- mp_limb_t hi, lo;
- y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
- hi = (int) y;
- y -= hi;
- if (!(y >= 0.0 && y < 1.0))
- abort ();
- y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
- lo = (int) y;
- y -= lo;
- if (!(y >= 0.0 && y < 1.0))
- abort ();
- m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
- }
- if (!(y == 0.0))
- abort ();
- /* Normalise. */
- while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
- m.nlimbs--;
- *mp = m;
- *ep = exp - DBL_MANT_BIT;
- return m.limbs;
-}
-
-# endif
-
-/* Assuming x = 2^e * m is finite and >= 0, and n is an integer:
- Returns the decimal representation of round (x * 10^n).
- Return the allocated memory - containing the decimal digits in low-to-high
- order, terminated with a NUL character - in case of success, NULL in case
- of memory allocation failure. */
-static char *
-scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
-{
- int s;
- size_t extra_zeroes;
- unsigned int abs_n;
- unsigned int abs_s;
- mp_limb_t *pow5_ptr;
- size_t pow5_len;
- unsigned int s_limbs;
- unsigned int s_bits;
- mpn_t pow5;
- mpn_t z;
- void *z_memory;
- char *digits;
-
- if (memory == NULL)
- return NULL;
- /* x = 2^e * m, hence
- y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m)
- = round (2^s * 5^n * m). */
- s = e + n;
- extra_zeroes = 0;
- /* Factor out a common power of 10 if possible. */
- if (s > 0 && n > 0)
- {
- extra_zeroes = (s < n ? s : n);
- s -= extra_zeroes;
- n -= extra_zeroes;
- }
- /* Here y = round (2^s * 5^n * m) * 10^extra_zeroes.
- Before converting to decimal, we need to compute
- z = round (2^s * 5^n * m). */
- /* Compute 5^|n|, possibly shifted by |s| bits if n and s have the same
- sign. 2.322 is slightly larger than log(5)/log(2). */
- abs_n = (n >= 0 ? n : -n);
- abs_s = (s >= 0 ? s : -s);
- pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1
- + abs_s / GMP_LIMB_BITS + 1)
- * sizeof (mp_limb_t));
- if (pow5_ptr == NULL)
- {
- free (memory);
- return NULL;
- }
- /* Initialize with 1. */
- pow5_ptr[0] = 1;
- pow5_len = 1;
- /* Multiply with 5^|n|. */
- if (abs_n > 0)
- {
- static mp_limb_t const small_pow5[13 + 1] =
- {
- 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625,
- 48828125, 244140625, 1220703125
- };
- unsigned int n13;
- for (n13 = 0; n13 <= abs_n; n13 += 13)
- {
- mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13];
- size_t j;
- mp_twolimb_t carry = 0;
- for (j = 0; j < pow5_len; j++)
- {
- mp_limb_t digit2 = pow5_ptr[j];
- carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
- pow5_ptr[j] = (mp_limb_t) carry;
- carry = carry >> GMP_LIMB_BITS;
- }
- if (carry > 0)
- pow5_ptr[pow5_len++] = (mp_limb_t) carry;
- }
- }
- s_limbs = abs_s / GMP_LIMB_BITS;
- s_bits = abs_s % GMP_LIMB_BITS;
- if (n >= 0 ? s >= 0 : s <= 0)
- {
- /* Multiply with 2^|s|. */
- if (s_bits > 0)
- {
- mp_limb_t *ptr = pow5_ptr;
- mp_twolimb_t accu = 0;
- size_t count;
- for (count = pow5_len; count > 0; count--)
- {
- accu += (mp_twolimb_t) *ptr << s_bits;
- *ptr++ = (mp_limb_t) accu;
- accu = accu >> GMP_LIMB_BITS;
- }
- if (accu > 0)
- {
- *ptr = (mp_limb_t) accu;
- pow5_len++;
- }
- }
- if (s_limbs > 0)
- {
- size_t count;
- for (count = pow5_len; count > 0;)
- {
- count--;
- pow5_ptr[s_limbs + count] = pow5_ptr[count];
- }
- for (count = s_limbs; count > 0;)
- {
- count--;
- pow5_ptr[count] = 0;
- }
- pow5_len += s_limbs;
- }
- pow5.limbs = pow5_ptr;
- pow5.nlimbs = pow5_len;
- if (n >= 0)
- {
- /* Multiply m with pow5. No division needed. */
- z_memory = multiply (m, pow5, &z);
- }
- else
- {
- /* Divide m by pow5 and round. */
- z_memory = divide (m, pow5, &z);
- }
- }
- else
- {
- pow5.limbs = pow5_ptr;
- pow5.nlimbs = pow5_len;
- if (n >= 0)
- {
- /* n >= 0, s < 0.
- Multiply m with pow5, then divide by 2^|s|. */
- mpn_t numerator;
- mpn_t denominator;
- void *tmp_memory;
- tmp_memory = multiply (m, pow5, &numerator);
- if (tmp_memory == NULL)
- {
- free (pow5_ptr);
- free (memory);
- return NULL;
- }
- /* Construct 2^|s|. */
- {
- mp_limb_t *ptr = pow5_ptr + pow5_len;
- size_t i;
- for (i = 0; i < s_limbs; i++)
- ptr[i] = 0;
- ptr[s_limbs] = (mp_limb_t) 1 << s_bits;
- denominator.limbs = ptr;
- denominator.nlimbs = s_limbs + 1;
- }
- z_memory = divide (numerator, denominator, &z);
- free (tmp_memory);
- }
- else
- {
- /* n < 0, s > 0.
- Multiply m with 2^s, then divide by pow5. */
- mpn_t numerator;
- mp_limb_t *num_ptr;
- num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1)
- * sizeof (mp_limb_t));
- if (num_ptr == NULL)
- {
- free (pow5_ptr);
- free (memory);
- return NULL;
- }
- {
- mp_limb_t *destptr = num_ptr;
- {
- size_t i;
- for (i = 0; i < s_limbs; i++)
- *destptr++ = 0;
- }
- if (s_bits > 0)
- {
- const mp_limb_t *sourceptr = m.limbs;
- mp_twolimb_t accu = 0;
- size_t count;
- for (count = m.nlimbs; count > 0; count--)
- {
- accu += (mp_twolimb_t) *sourceptr++ << s_bits;
- *destptr++ = (mp_limb_t) accu;
- accu = accu >> GMP_LIMB_BITS;
- }
- if (accu > 0)
- *destptr++ = (mp_limb_t) accu;
- }
- else
- {
- const mp_limb_t *sourceptr = m.limbs;
- size_t count;
- for (count = m.nlimbs; count > 0; count--)
- *destptr++ = *sourceptr++;
- }
- numerator.limbs = num_ptr;
- numerator.nlimbs = destptr - num_ptr;
- }
- z_memory = divide (numerator, pow5, &z);
- free (num_ptr);
- }
- }
- free (pow5_ptr);
- free (memory);
-
- /* Here y = round (x * 10^n) = z * 10^extra_zeroes. */
-
- if (z_memory == NULL)
- return NULL;
- digits = convert_to_decimal (z, extra_zeroes);
- free (z_memory);
- return digits;
-}
-
-# if NEED_PRINTF_LONG_DOUBLE
-
-/* Assuming x is finite and >= 0, and n is an integer:
- Returns the decimal representation of round (x * 10^n).
- Return the allocated memory - containing the decimal digits in low-to-high
- order, terminated with a NUL character - in case of success, NULL in case
- of memory allocation failure. */
-static char *
-scale10_round_decimal_long_double (long double x, int n)
-{
- int e IF_LINT(= 0);
- mpn_t m;
- void *memory = decode_long_double (x, &e, &m);
- return scale10_round_decimal_decoded (e, m, memory, n);
-}
-
-# endif
-
-# if NEED_PRINTF_DOUBLE
-
-/* Assuming x is finite and >= 0, and n is an integer:
- Returns the decimal representation of round (x * 10^n).
- Return the allocated memory - containing the decimal digits in low-to-high
- order, terminated with a NUL character - in case of success, NULL in case
- of memory allocation failure. */
-static char *
-scale10_round_decimal_double (double x, int n)
-{
- int e IF_LINT(= 0);
- mpn_t m;
- void *memory = decode_double (x, &e, &m);
- return scale10_round_decimal_decoded (e, m, memory, n);
-}
-
-# endif
-
-# if NEED_PRINTF_LONG_DOUBLE
-
-/* Assuming x is finite and > 0:
- Return an approximation for n with 10^n <= x < 10^(n+1).
- The approximation is usually the right n, but may be off by 1 sometimes. */
-static int
-floorlog10l (long double x)
-{
- int exp;
- long double y;
- double z;
- double l;
-
- /* Split into exponential part and mantissa. */
- y = frexpl (x, &exp);
- if (!(y >= 0.0L && y < 1.0L))
- abort ();
- if (y == 0.0L)
- return INT_MIN;
- if (y < 0.5L)
- {
- while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
- {
- y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
- exp -= GMP_LIMB_BITS;
- }
- if (y < (1.0L / (1 << 16)))
- {
- y *= 1.0L * (1 << 16);
- exp -= 16;
- }
- if (y < (1.0L / (1 << 8)))
- {
- y *= 1.0L * (1 << 8);
- exp -= 8;
- }
- if (y < (1.0L / (1 << 4)))
- {
- y *= 1.0L * (1 << 4);
- exp -= 4;
- }
- if (y < (1.0L / (1 << 2)))
- {
- y *= 1.0L * (1 << 2);
- exp -= 2;
- }
- if (y < (1.0L / (1 << 1)))
- {
- y *= 1.0L * (1 << 1);
- exp -= 1;
- }
- }
- if (!(y >= 0.5L && y < 1.0L))
- abort ();
- /* Compute an approximation for l = log2(x) = exp + log2(y). */
- l = exp;
- z = y;
- if (z < 0.70710678118654752444)
- {
- z *= 1.4142135623730950488;
- l -= 0.5;
- }
- if (z < 0.8408964152537145431)
- {
- z *= 1.1892071150027210667;
- l -= 0.25;
- }
- if (z < 0.91700404320467123175)
- {
- z *= 1.0905077326652576592;
- l -= 0.125;
- }
- if (z < 0.9576032806985736469)
- {
- z *= 1.0442737824274138403;
- l -= 0.0625;
- }
- /* Now 0.95 <= z <= 1.01. */
- z = 1 - z;
- /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...)
- Four terms are enough to get an approximation with error < 10^-7. */
- l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
- /* Finally multiply with log(2)/log(10), yields an approximation for
- log10(x). */
- l *= 0.30102999566398119523;
- /* Round down to the next integer. */
- return (int) l + (l < 0 ? -1 : 0);
-}
-
-# endif
-
-# if NEED_PRINTF_DOUBLE
-
-/* Assuming x is finite and > 0:
- Return an approximation for n with 10^n <= x < 10^(n+1).
- The approximation is usually the right n, but may be off by 1 sometimes. */
-static int
-floorlog10 (double x)
-{
- int exp;
- double y;
- double z;
- double l;
-
- /* Split into exponential part and mantissa. */
- y = frexp (x, &exp);
- if (!(y >= 0.0 && y < 1.0))
- abort ();
- if (y == 0.0)
- return INT_MIN;
- if (y < 0.5)
- {
- while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
- {
- y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
- exp -= GMP_LIMB_BITS;
- }
- if (y < (1.0 / (1 << 16)))
- {
- y *= 1.0 * (1 << 16);
- exp -= 16;
- }
- if (y < (1.0 / (1 << 8)))
- {
- y *= 1.0 * (1 << 8);
- exp -= 8;
- }
- if (y < (1.0 / (1 << 4)))
- {
- y *= 1.0 * (1 << 4);
- exp -= 4;
- }
- if (y < (1.0 / (1 << 2)))
- {
- y *= 1.0 * (1 << 2);
- exp -= 2;
- }
- if (y < (1.0 / (1 << 1)))
- {
- y *= 1.0 * (1 << 1);
- exp -= 1;
- }
- }
- if (!(y >= 0.5 && y < 1.0))
- abort ();
- /* Compute an approximation for l = log2(x) = exp + log2(y). */
- l = exp;
- z = y;
- if (z < 0.70710678118654752444)
- {
- z *= 1.4142135623730950488;
- l -= 0.5;
- }
- if (z < 0.8408964152537145431)
- {
- z *= 1.1892071150027210667;
- l -= 0.25;
- }
- if (z < 0.91700404320467123175)
- {
- z *= 1.0905077326652576592;
- l -= 0.125;
- }
- if (z < 0.9576032806985736469)
- {
- z *= 1.0442737824274138403;
- l -= 0.0625;
- }
- /* Now 0.95 <= z <= 1.01. */
- z = 1 - z;
- /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...)
- Four terms are enough to get an approximation with error < 10^-7. */
- l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
- /* Finally multiply with log(2)/log(10), yields an approximation for
- log10(x). */
- l *= 0.30102999566398119523;
- /* Round down to the next integer. */
- return (int) l + (l < 0 ? -1 : 0);
-}
-
-# endif
-
-/* Tests whether a string of digits consists of exactly PRECISION zeroes and
- a single '1' digit. */
-static int
-is_borderline (const char *digits, size_t precision)
-{
- for (; precision > 0; precision--, digits++)
- if (*digits != '0')
- return 0;
- if (*digits != '1')
- return 0;
- digits++;
- return *digits == '\0';
-}
-
-#endif
-
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99
-
-/* Use a different function name, to make it possible that the 'wchar_t'
- parametrization and the 'char' parametrization get compiled in the same
- translation unit. */
-# if WIDE_CHAR_VERSION
-# define MAX_ROOM_NEEDED wmax_room_needed
-# else
-# define MAX_ROOM_NEEDED max_room_needed
-# endif
-
-/* Returns the number of TCHAR_T units needed as temporary space for the result
- of sprintf or SNPRINTF of a single conversion directive. */
-static size_t
-MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
- arg_type type, int flags, size_t width, int has_precision,
- size_t precision, int pad_ourselves)
-{
- size_t tmp_length;
-
- switch (conversion)
- {
- case 'd': case 'i': case 'u':
-# if HAVE_LONG_LONG_INT
- if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
- tmp_length =
- (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
- * 0.30103 /* binary -> decimal */
- )
- + 1; /* turn floor into ceil */
- else
-# endif
- if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
- tmp_length =
- (unsigned int) (sizeof (unsigned long) * CHAR_BIT
- * 0.30103 /* binary -> decimal */
- )
- + 1; /* turn floor into ceil */
- else
- tmp_length =
- (unsigned int) (sizeof (unsigned int) * CHAR_BIT
- * 0.30103 /* binary -> decimal */
- )
- + 1; /* turn floor into ceil */
- if (tmp_length < precision)
- tmp_length = precision;
- /* Multiply by 2, as an estimate for FLAG_GROUP. */
- tmp_length = xsum (tmp_length, tmp_length);
- /* Add 1, to account for a leading sign. */
- tmp_length = xsum (tmp_length, 1);
- break;
-
- case 'o':
-# if HAVE_LONG_LONG_INT
- if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
- tmp_length =
- (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
- * 0.333334 /* binary -> octal */
- )
- + 1; /* turn floor into ceil */
- else
-# endif
- if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
- tmp_length =
- (unsigned int) (sizeof (unsigned long) * CHAR_BIT
- * 0.333334 /* binary -> octal */
- )
- + 1; /* turn floor into ceil */
- else
- tmp_length =
- (unsigned int) (sizeof (unsigned int) * CHAR_BIT
- * 0.333334 /* binary -> octal */
- )
- + 1; /* turn floor into ceil */
- if (tmp_length < precision)
- tmp_length = precision;
- /* Add 1, to account for a leading sign. */
- tmp_length = xsum (tmp_length, 1);
- break;
-
- case 'x': case 'X':
-# if HAVE_LONG_LONG_INT
- if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
- tmp_length =
- (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
- * 0.25 /* binary -> hexadecimal */
- )
- + 1; /* turn floor into ceil */
- else
-# endif
- if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
- tmp_length =
- (unsigned int) (sizeof (unsigned long) * CHAR_BIT
- * 0.25 /* binary -> hexadecimal */
- )
- + 1; /* turn floor into ceil */
- else
- tmp_length =
- (unsigned int) (sizeof (unsigned int) * CHAR_BIT
- * 0.25 /* binary -> hexadecimal */
- )
- + 1; /* turn floor into ceil */
- if (tmp_length < precision)
- tmp_length = precision;
- /* Add 2, to account for a leading sign or alternate form. */
- tmp_length = xsum (tmp_length, 2);
- break;
-
- case 'f': case 'F':
- if (type == TYPE_LONGDOUBLE)
- tmp_length =
- (unsigned int) (LDBL_MAX_EXP
- * 0.30103 /* binary -> decimal */
- * 2 /* estimate for FLAG_GROUP */
- )
- + 1 /* turn floor into ceil */
- + 10; /* sign, decimal point etc. */
- else
- tmp_length =
- (unsigned int) (DBL_MAX_EXP
- * 0.30103 /* binary -> decimal */
- * 2 /* estimate for FLAG_GROUP */
- )
- + 1 /* turn floor into ceil */
- + 10; /* sign, decimal point etc. */
- tmp_length = xsum (tmp_length, precision);
- break;
-
- case 'e': case 'E': case 'g': case 'G':
- tmp_length =
- 12; /* sign, decimal point, exponent etc. */
- tmp_length = xsum (tmp_length, precision);
- break;
-
- case 'a': case 'A':
- if (type == TYPE_LONGDOUBLE)
- tmp_length =
- (unsigned int) (LDBL_DIG
- * 0.831 /* decimal -> hexadecimal */
- )
- + 1; /* turn floor into ceil */
- else
- tmp_length =
- (unsigned int) (DBL_DIG
- * 0.831 /* decimal -> hexadecimal */
- )
- + 1; /* turn floor into ceil */
- if (tmp_length < precision)
- tmp_length = precision;
- /* Account for sign, decimal point etc. */
- tmp_length = xsum (tmp_length, 12);
- break;
-
- case 'c':
-# if HAVE_WINT_T && !WIDE_CHAR_VERSION
- if (type == TYPE_WIDE_CHAR)
- tmp_length = MB_CUR_MAX;
- else
-# endif
- tmp_length = 1;
- break;
-
- case 's':
-# if HAVE_WCHAR_T
- if (type == TYPE_WIDE_STRING)
- {
-# if WIDE_CHAR_VERSION
- /* ISO C says about %ls in fwprintf:
- "If the precision is not specified or is greater than the size
- of the array, the array shall contain a null wide character."
- So if there is a precision, we must not use wcslen. */
- const wchar_t *arg = ap->arg[arg_index].a.a_wide_string;
-
- if (has_precision)
- tmp_length = local_wcsnlen (arg, precision);
- else
- tmp_length = local_wcslen (arg);
-# else
- /* ISO C says about %ls in fprintf:
- "If a precision is specified, no more than that many bytes are
- written (including shift sequences, if any), and the array
- shall contain a null wide character if, to equal the multibyte
- character sequence length given by the precision, the function
- would need to access a wide character one past the end of the
- array."
- So if there is a precision, we must not use wcslen. */
- /* This case has already been handled separately in VASNPRINTF. */
- abort ();
-# endif
- }
- else
-# endif
- {
-# if WIDE_CHAR_VERSION
- /* ISO C says about %s in fwprintf:
- "If the precision is not specified or is greater than the size
- of the converted array, the converted array shall contain a
- null wide character."
- So if there is a precision, we must not use strlen. */
- /* This case has already been handled separately in VASNPRINTF. */
- abort ();
-# else
- /* ISO C says about %s in fprintf:
- "If the precision is not specified or greater than the size of
- the array, the array shall contain a null character."
- So if there is a precision, we must not use strlen. */
- const char *arg = ap->arg[arg_index].a.a_string;
-
- if (has_precision)
- tmp_length = local_strnlen (arg, precision);
- else
- tmp_length = strlen (arg);
-# endif
- }
- break;
-
- case 'p':
- tmp_length =
- (unsigned int) (sizeof (void *) * CHAR_BIT
- * 0.25 /* binary -> hexadecimal */
- )
- + 1 /* turn floor into ceil */
- + 2; /* account for leading 0x */
- break;
-
- default:
- abort ();
- }
-
- if (!pad_ourselves)
- {
-# if ENABLE_UNISTDIO
- /* Padding considers the number of characters, therefore the number of
- elements after padding may be
- > max (tmp_length, width)
- but is certainly
- <= tmp_length + width. */
- tmp_length = xsum (tmp_length, width);
-# else
- /* Padding considers the number of elements, says POSIX. */
- if (tmp_length < width)
- tmp_length = width;
-# endif
- }
-
- tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
-
- return tmp_length;
-}
-
-#endif
-
-DCHAR_T *
-VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
- const FCHAR_T *format, va_list args)
-{
- DIRECTIVES d;
- arguments a;
-
- if (PRINTF_PARSE (format, &d, &a) < 0)
- /* errno is already set. */
- return NULL;
-
-#define CLEANUP() \
- if (d.dir != d.direct_alloc_dir) \
- free (d.dir); \
- if (a.arg != a.direct_alloc_arg) \
- free (a.arg);
-
- if (PRINTF_FETCHARGS (args, &a) < 0)
- {
- CLEANUP ();
- errno = EINVAL;
- return NULL;
- }
-
- {
- size_t buf_neededlength;
- TCHAR_T *buf;
- TCHAR_T *buf_malloced;
- const FCHAR_T *cp;
- size_t i;
- DIRECTIVE *dp;
- /* Output string accumulator. */
- DCHAR_T *result;
- size_t allocated;
- size_t length;
-
- /* Allocate a small buffer that will hold a directive passed to
- sprintf or snprintf. */
- buf_neededlength =
- xsum4 (7, d.max_width_length, d.max_precision_length, 6);
-#if HAVE_ALLOCA
- if (buf_neededlength < 4000 / sizeof (TCHAR_T))
- {
- buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T));
- buf_malloced = NULL;
- }
- else
-#endif
- {
- size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T));
- if (size_overflow_p (buf_memsize))
- goto out_of_memory_1;
- buf = (TCHAR_T *) malloc (buf_memsize);
- if (buf == NULL)
- goto out_of_memory_1;
- buf_malloced = buf;
- }
-
- if (resultbuf != NULL)
- {
- result = resultbuf;
- allocated = *lengthp;
- }
- else
- {
- result = NULL;
- allocated = 0;
- }
- length = 0;
- /* Invariants:
- result is either == resultbuf or == NULL or malloc-allocated.
- If length > 0, then result != NULL. */
-
- /* Ensures that allocated >= needed. Aborts through a jump to
- out_of_memory if needed is SIZE_MAX or otherwise too big. */
-#define ENSURE_ALLOCATION(needed) \
- if ((needed) > allocated) \
- { \
- size_t memory_size; \
- DCHAR_T *memory; \
- \
- allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \
- if ((needed) > allocated) \
- allocated = (needed); \
- memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
- if (size_overflow_p (memory_size)) \
- goto out_of_memory; \
- if (result == resultbuf || result == NULL) \
- memory = (DCHAR_T *) malloc (memory_size); \
- else \
- memory = (DCHAR_T *) realloc (result, memory_size); \
- if (memory == NULL) \
- goto out_of_memory; \
- if (result == resultbuf && length > 0) \
- DCHAR_CPY (memory, result, length); \
- result = memory; \
- }
-
- for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
- {
- if (cp != dp->dir_start)
- {
- size_t n = dp->dir_start - cp;
- size_t augmented_length = xsum (length, n);
-
- ENSURE_ALLOCATION (augmented_length);
- /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we
- need that the format string contains only ASCII characters
- if FCHAR_T and DCHAR_T are not the same type. */
- if (sizeof (FCHAR_T) == sizeof (DCHAR_T))
- {
- DCHAR_CPY (result + length, (const DCHAR_T *) cp, n);
- length = augmented_length;
- }
- else
- {
- do
- result[length++] = (unsigned char) *cp++;
- while (--n > 0);
- }
- }
- if (i == d.count)
- break;
-
- /* Execute a single directive. */
- if (dp->conversion == '%')
- {
- size_t augmented_length;
-
- if (!(dp->arg_index == ARG_NONE))
- abort ();
- augmented_length = xsum (length, 1);
- ENSURE_ALLOCATION (augmented_length);
- result[length] = '%';
- length = augmented_length;
- }
- else
- {
- if (!(dp->arg_index != ARG_NONE))
- abort ();
-
- if (dp->conversion == 'n')
- {
- switch (a.arg[dp->arg_index].type)
- {
- case TYPE_COUNT_SCHAR_POINTER:
- *a.arg[dp->arg_index].a.a_count_schar_pointer = length;
- break;
- case TYPE_COUNT_SHORT_POINTER:
- *a.arg[dp->arg_index].a.a_count_short_pointer = length;
- break;
- case TYPE_COUNT_INT_POINTER:
- *a.arg[dp->arg_index].a.a_count_int_pointer = length;
- break;
- case TYPE_COUNT_LONGINT_POINTER:
- *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
- break;
-#if HAVE_LONG_LONG_INT
- case TYPE_COUNT_LONGLONGINT_POINTER:
- *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
- break;
-#endif
- default:
- abort ();
- }
- }
-#if ENABLE_UNISTDIO
- /* The unistdio extensions. */
- else if (dp->conversion == 'U')
- {
- arg_type type = a.arg[dp->arg_index].type;
- int flags = dp->flags;
- int has_width;
- size_t width;
- int has_precision;
- size_t precision;
-
- has_width = 0;
- width = 0;
- if (dp->width_start != dp->width_end)
- {
- if (dp->width_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->width_arg_index].a.a_int;
- if (arg < 0)
- {
- /* "A negative field width is taken as a '-' flag
- followed by a positive field width." */
- flags |= FLAG_LEFT;
- width = (unsigned int) (-arg);
- }
- else
- width = arg;
- }
- else
- {
- const FCHAR_T *digitp = dp->width_start;
-
- do
- width = xsum (xtimes (width, 10), *digitp++ - '0');
- while (digitp != dp->width_end);
- }
- has_width = 1;
- }
-
- has_precision = 0;
- precision = 0;
- if (dp->precision_start != dp->precision_end)
- {
- if (dp->precision_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->precision_arg_index].a.a_int;
- /* "A negative precision is taken as if the precision
- were omitted." */
- if (arg >= 0)
- {
- precision = arg;
- has_precision = 1;
- }
- }
- else
- {
- const FCHAR_T *digitp = dp->precision_start + 1;
-
- precision = 0;
- while (digitp != dp->precision_end)
- precision = xsum (xtimes (precision, 10), *digitp++ - '0');
- has_precision = 1;
- }
- }
-
- switch (type)
- {
- case TYPE_U8_STRING:
- {
- const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string;
- const uint8_t *arg_end;
- size_t characters;
-
- if (has_precision)
- {
- /* Use only PRECISION characters, from the left. */
- arg_end = arg;
- characters = 0;
- for (; precision > 0; precision--)
- {
- int count = u8_strmblen (arg_end);
- if (count == 0)
- break;
- if (count < 0)
- {
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else if (has_width)
- {
- /* Use the entire string, and count the number of
- characters. */
- arg_end = arg;
- characters = 0;
- for (;;)
- {
- int count = u8_strmblen (arg_end);
- if (count == 0)
- break;
- if (count < 0)
- {
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else
- {
- /* Use the entire string. */
- arg_end = arg + u8_strlen (arg);
- /* The number of characters doesn't matter. */
- characters = 0;
- }
-
- if (has_width && width > characters
- && !(dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
-
-# if DCHAR_IS_UINT8_T
- {
- size_t n = arg_end - arg;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_CPY (result + length, arg, n);
- length += n;
- }
-# else
- { /* Convert. */
- DCHAR_T *converted = result + length;
- size_t converted_len = allocated - length;
-# if DCHAR_IS_TCHAR
- /* Convert from UTF-8 to locale encoding. */
- converted =
- u8_conv_to_encoding (locale_charset (),
- iconveh_question_mark,
- arg, arg_end - arg, NULL,
- converted, &converted_len);
-# else
- /* Convert from UTF-8 to UTF-16/UTF-32. */
- converted =
- U8_TO_DCHAR (arg, arg_end - arg,
- converted, &converted_len);
-# endif
- if (converted == NULL)
- {
- int saved_errno = errno;
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = saved_errno;
- return NULL;
- }
- if (converted != result + length)
- {
- ENSURE_ALLOCATION (xsum (length, converted_len));
- DCHAR_CPY (result + length, converted, converted_len);
- free (converted);
- }
- length += converted_len;
- }
-# endif
-
- if (has_width && width > characters
- && (dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
- }
- break;
-
- case TYPE_U16_STRING:
- {
- const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string;
- const uint16_t *arg_end;
- size_t characters;
-
- if (has_precision)
- {
- /* Use only PRECISION characters, from the left. */
- arg_end = arg;
- characters = 0;
- for (; precision > 0; precision--)
- {
- int count = u16_strmblen (arg_end);
- if (count == 0)
- break;
- if (count < 0)
- {
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else if (has_width)
- {
- /* Use the entire string, and count the number of
- characters. */
- arg_end = arg;
- characters = 0;
- for (;;)
- {
- int count = u16_strmblen (arg_end);
- if (count == 0)
- break;
- if (count < 0)
- {
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else
- {
- /* Use the entire string. */
- arg_end = arg + u16_strlen (arg);
- /* The number of characters doesn't matter. */
- characters = 0;
- }
-
- if (has_width && width > characters
- && !(dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
-
-# if DCHAR_IS_UINT16_T
- {
- size_t n = arg_end - arg;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_CPY (result + length, arg, n);
- length += n;
- }
-# else
- { /* Convert. */
- DCHAR_T *converted = result + length;
- size_t converted_len = allocated - length;
-# if DCHAR_IS_TCHAR
- /* Convert from UTF-16 to locale encoding. */
- converted =
- u16_conv_to_encoding (locale_charset (),
- iconveh_question_mark,
- arg, arg_end - arg, NULL,
- converted, &converted_len);
-# else
- /* Convert from UTF-16 to UTF-8/UTF-32. */
- converted =
- U16_TO_DCHAR (arg, arg_end - arg,
- converted, &converted_len);
-# endif
- if (converted == NULL)
- {
- int saved_errno = errno;
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = saved_errno;
- return NULL;
- }
- if (converted != result + length)
- {
- ENSURE_ALLOCATION (xsum (length, converted_len));
- DCHAR_CPY (result + length, converted, converted_len);
- free (converted);
- }
- length += converted_len;
- }
-# endif
-
- if (has_width && width > characters
- && (dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
- }
- break;
-
- case TYPE_U32_STRING:
- {
- const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string;
- const uint32_t *arg_end;
- size_t characters;
-
- if (has_precision)
- {
- /* Use only PRECISION characters, from the left. */
- arg_end = arg;
- characters = 0;
- for (; precision > 0; precision--)
- {
- int count = u32_strmblen (arg_end);
- if (count == 0)
- break;
- if (count < 0)
- {
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else if (has_width)
- {
- /* Use the entire string, and count the number of
- characters. */
- arg_end = arg;
- characters = 0;
- for (;;)
- {
- int count = u32_strmblen (arg_end);
- if (count == 0)
- break;
- if (count < 0)
- {
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else
- {
- /* Use the entire string. */
- arg_end = arg + u32_strlen (arg);
- /* The number of characters doesn't matter. */
- characters = 0;
- }
-
- if (has_width && width > characters
- && !(dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
-
-# if DCHAR_IS_UINT32_T
- {
- size_t n = arg_end - arg;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_CPY (result + length, arg, n);
- length += n;
- }
-# else
- { /* Convert. */
- DCHAR_T *converted = result + length;
- size_t converted_len = allocated - length;
-# if DCHAR_IS_TCHAR
- /* Convert from UTF-32 to locale encoding. */
- converted =
- u32_conv_to_encoding (locale_charset (),
- iconveh_question_mark,
- arg, arg_end - arg, NULL,
- converted, &converted_len);
-# else
- /* Convert from UTF-32 to UTF-8/UTF-16. */
- converted =
- U32_TO_DCHAR (arg, arg_end - arg,
- converted, &converted_len);
-# endif
- if (converted == NULL)
- {
- int saved_errno = errno;
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = saved_errno;
- return NULL;
- }
- if (converted != result + length)
- {
- ENSURE_ALLOCATION (xsum (length, converted_len));
- DCHAR_CPY (result + length, converted, converted_len);
- free (converted);
- }
- length += converted_len;
- }
-# endif
-
- if (has_width && width > characters
- && (dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
- }
- break;
-
- default:
- abort ();
- }
- }
-#endif
-#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T
- else if (dp->conversion == 's'
-# if WIDE_CHAR_VERSION
- && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
-# else
- && a.arg[dp->arg_index].type == TYPE_WIDE_STRING
-# endif
- )
- {
- /* The normal handling of the 's' directive below requires
- allocating a temporary buffer. The determination of its
- length (tmp_length), in the case when a precision is
- specified, below requires a conversion between a char[]
- string and a wchar_t[] wide string. It could be done, but
- we have no guarantee that the implementation of sprintf will
- use the exactly same algorithm. Without this guarantee, it
- is possible to have buffer overrun bugs. In order to avoid
- such bugs, we implement the entire processing of the 's'
- directive ourselves. */
- int flags = dp->flags;
- int has_width;
- size_t width;
- int has_precision;
- size_t precision;
-
- has_width = 0;
- width = 0;
- if (dp->width_start != dp->width_end)
- {
- if (dp->width_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->width_arg_index].a.a_int;
- if (arg < 0)
- {
- /* "A negative field width is taken as a '-' flag
- followed by a positive field width." */
- flags |= FLAG_LEFT;
- width = (unsigned int) (-arg);
- }
- else
- width = arg;
- }
- else
- {
- const FCHAR_T *digitp = dp->width_start;
-
- do
- width = xsum (xtimes (width, 10), *digitp++ - '0');
- while (digitp != dp->width_end);
- }
- has_width = 1;
- }
-
- has_precision = 0;
- precision = 6;
- if (dp->precision_start != dp->precision_end)
- {
- if (dp->precision_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->precision_arg_index].a.a_int;
- /* "A negative precision is taken as if the precision
- were omitted." */
- if (arg >= 0)
- {
- precision = arg;
- has_precision = 1;
- }
- }
- else
- {
- const FCHAR_T *digitp = dp->precision_start + 1;
-
- precision = 0;
- while (digitp != dp->precision_end)
- precision = xsum (xtimes (precision, 10), *digitp++ - '0');
- has_precision = 1;
- }
- }
-
-# if WIDE_CHAR_VERSION
- /* %s in vasnwprintf. See the specification of fwprintf. */
- {
- const char *arg = a.arg[dp->arg_index].a.a_string;
- const char *arg_end;
- size_t characters;
-
- if (has_precision)
- {
- /* Use only as many bytes as needed to produce PRECISION
- wide characters, from the left. */
-# if HAVE_MBRTOWC
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- arg_end = arg;
- characters = 0;
- for (; precision > 0; precision--)
- {
- int count;
-# if HAVE_MBRTOWC
- count = mbrlen (arg_end, MB_CUR_MAX, &state);
-# else
- count = mblen (arg_end, MB_CUR_MAX);
-# endif
- if (count == 0)
- /* Found the terminating NUL. */
- break;
- if (count < 0)
- {
- /* Invalid or incomplete multibyte character. */
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else if (has_width)
- {
- /* Use the entire string, and count the number of wide
- characters. */
-# if HAVE_MBRTOWC
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- arg_end = arg;
- characters = 0;
- for (;;)
- {
- int count;
-# if HAVE_MBRTOWC
- count = mbrlen (arg_end, MB_CUR_MAX, &state);
-# else
- count = mblen (arg_end, MB_CUR_MAX);
-# endif
- if (count == 0)
- /* Found the terminating NUL. */
- break;
- if (count < 0)
- {
- /* Invalid or incomplete multibyte character. */
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end += count;
- characters++;
- }
- }
- else
- {
- /* Use the entire string. */
- arg_end = arg + strlen (arg);
- /* The number of characters doesn't matter. */
- characters = 0;
- }
-
- if (has_width && width > characters
- && !(dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
-
- if (has_precision || has_width)
- {
- /* We know the number of wide characters in advance. */
- size_t remaining;
-# if HAVE_MBRTOWC
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- ENSURE_ALLOCATION (xsum (length, characters));
- for (remaining = characters; remaining > 0; remaining--)
- {
- wchar_t wc;
- int count;
-# if HAVE_MBRTOWC
- count = mbrtowc (&wc, arg, arg_end - arg, &state);
-# else
- count = mbtowc (&wc, arg, arg_end - arg);
-# endif
- if (count <= 0)
- /* mbrtowc not consistent with mbrlen, or mbtowc
- not consistent with mblen. */
- abort ();
- result[length++] = wc;
- arg += count;
- }
- if (!(arg == arg_end))
- abort ();
- }
- else
- {
-# if HAVE_MBRTOWC
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- while (arg < arg_end)
- {
- wchar_t wc;
- int count;
-# if HAVE_MBRTOWC
- count = mbrtowc (&wc, arg, arg_end - arg, &state);
-# else
- count = mbtowc (&wc, arg, arg_end - arg);
-# endif
- if (count <= 0)
- /* mbrtowc not consistent with mbrlen, or mbtowc
- not consistent with mblen. */
- abort ();
- ENSURE_ALLOCATION (xsum (length, 1));
- result[length++] = wc;
- arg += count;
- }
- }
-
- if (has_width && width > characters
- && (dp->flags & FLAG_LEFT))
- {
- size_t n = width - characters;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
- }
-# else
- /* %ls in vasnprintf. See the specification of fprintf. */
- {
- const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
- const wchar_t *arg_end;
- size_t characters;
-# if !DCHAR_IS_TCHAR
- /* This code assumes that TCHAR_T is 'char'. */
- verify (sizeof (TCHAR_T) == 1);
- TCHAR_T *tmpsrc;
- DCHAR_T *tmpdst;
- size_t tmpdst_len;
-# endif
- size_t w;
-
- if (has_precision)
- {
- /* Use only as many wide characters as needed to produce
- at most PRECISION bytes, from the left. */
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- arg_end = arg;
- characters = 0;
- while (precision > 0)
- {
- char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
- int count;
-
- if (*arg_end == 0)
- /* Found the terminating null wide character. */
- break;
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- count = wcrtomb (cbuf, *arg_end, &state);
-# else
- count = wctomb (cbuf, *arg_end);
-# endif
- if (count < 0)
- {
- /* Cannot convert. */
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- if (precision < count)
- break;
- arg_end++;
- characters += count;
- precision -= count;
- }
- }
-# if DCHAR_IS_TCHAR
- else if (has_width)
-# else
- else
-# endif
- {
- /* Use the entire string, and count the number of
- bytes. */
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- arg_end = arg;
- characters = 0;
- for (;;)
- {
- char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
- int count;
-
- if (*arg_end == 0)
- /* Found the terminating null wide character. */
- break;
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- count = wcrtomb (cbuf, *arg_end, &state);
-# else
- count = wctomb (cbuf, *arg_end);
-# endif
- if (count < 0)
- {
- /* Cannot convert. */
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- arg_end++;
- characters += count;
- }
- }
-# if DCHAR_IS_TCHAR
- else
- {
- /* Use the entire string. */
- arg_end = arg + local_wcslen (arg);
- /* The number of bytes doesn't matter. */
- characters = 0;
- }
-# endif
-
-# if !DCHAR_IS_TCHAR
- /* Convert the string into a piece of temporary memory. */
- tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T));
- if (tmpsrc == NULL)
- goto out_of_memory;
- {
- TCHAR_T *tmpptr = tmpsrc;
- size_t remaining;
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- for (remaining = characters; remaining > 0; )
- {
- char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
- int count;
-
- if (*arg == 0)
- abort ();
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- count = wcrtomb (cbuf, *arg, &state);
-# else
- count = wctomb (cbuf, *arg);
-# endif
- if (count <= 0)
- /* Inconsistency. */
- abort ();
- memcpy (tmpptr, cbuf, count);
- tmpptr += count;
- arg++;
- remaining -= count;
- }
- if (!(arg == arg_end))
- abort ();
- }
-
- /* Convert from TCHAR_T[] to DCHAR_T[]. */
- tmpdst =
- DCHAR_CONV_FROM_ENCODING (locale_charset (),
- iconveh_question_mark,
- tmpsrc, characters,
- NULL,
- NULL, &tmpdst_len);
- if (tmpdst == NULL)
- {
- int saved_errno = errno;
- free (tmpsrc);
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = saved_errno;
- return NULL;
- }
- free (tmpsrc);
-# endif
-
- if (has_width)
- {
-# if ENABLE_UNISTDIO
- /* Outside POSIX, it's preferable to compare the width
- against the number of _characters_ of the converted
- value. */
- w = DCHAR_MBSNLEN (result + length, characters);
-# else
- /* The width is compared against the number of _bytes_
- of the converted value, says POSIX. */
- w = characters;
-# endif
- }
- else
- /* w doesn't matter. */
- w = 0;
-
- if (has_width && width > w
- && !(dp->flags & FLAG_LEFT))
- {
- size_t n = width - w;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
-
-# if DCHAR_IS_TCHAR
- if (has_precision || has_width)
- {
- /* We know the number of bytes in advance. */
- size_t remaining;
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- ENSURE_ALLOCATION (xsum (length, characters));
- for (remaining = characters; remaining > 0; )
- {
- char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
- int count;
-
- if (*arg == 0)
- abort ();
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- count = wcrtomb (cbuf, *arg, &state);
-# else
- count = wctomb (cbuf, *arg);
-# endif
- if (count <= 0)
- /* Inconsistency. */
- abort ();
- memcpy (result + length, cbuf, count);
- length += count;
- arg++;
- remaining -= count;
- }
- if (!(arg == arg_end))
- abort ();
- }
- else
- {
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- mbstate_t state;
- memset (&state, '\0', sizeof (mbstate_t));
-# endif
- while (arg < arg_end)
- {
- char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
- int count;
-
- if (*arg == 0)
- abort ();
-# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
- count = wcrtomb (cbuf, *arg, &state);
-# else
- count = wctomb (cbuf, *arg);
-# endif
- if (count <= 0)
- {
- /* Cannot convert. */
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = EILSEQ;
- return NULL;
- }
- ENSURE_ALLOCATION (xsum (length, count));
- memcpy (result + length, cbuf, count);
- length += count;
- arg++;
- }
- }
-# else
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
- DCHAR_CPY (result + length, tmpdst, tmpdst_len);
- free (tmpdst);
- length += tmpdst_len;
-# endif
-
- if (has_width && width > w
- && (dp->flags & FLAG_LEFT))
- {
- size_t n = width - w;
- ENSURE_ALLOCATION (xsum (length, n));
- DCHAR_SET (result + length, ' ', n);
- length += n;
- }
- }
-# endif
- }
-#endif
-#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
- else if ((dp->conversion == 'a' || dp->conversion == 'A')
-# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
- && (0
-# if NEED_PRINTF_DOUBLE
- || a.arg[dp->arg_index].type == TYPE_DOUBLE
-# endif
-# if NEED_PRINTF_LONG_DOUBLE
- || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
-# endif
- )
-# endif
- )
- {
- arg_type type = a.arg[dp->arg_index].type;
- int flags = dp->flags;
- int has_width;
- size_t width;
- int has_precision;
- size_t precision;
- size_t tmp_length;
- DCHAR_T tmpbuf[700];
- DCHAR_T *tmp;
- DCHAR_T *pad_ptr;
- DCHAR_T *p;
-
- has_width = 0;
- width = 0;
- if (dp->width_start != dp->width_end)
- {
- if (dp->width_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->width_arg_index].a.a_int;
- if (arg < 0)
- {
- /* "A negative field width is taken as a '-' flag
- followed by a positive field width." */
- flags |= FLAG_LEFT;
- width = (unsigned int) (-arg);
- }
- else
- width = arg;
- }
- else
- {
- const FCHAR_T *digitp = dp->width_start;
-
- do
- width = xsum (xtimes (width, 10), *digitp++ - '0');
- while (digitp != dp->width_end);
- }
- has_width = 1;
- }
-
- has_precision = 0;
- precision = 0;
- if (dp->precision_start != dp->precision_end)
- {
- if (dp->precision_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->precision_arg_index].a.a_int;
- /* "A negative precision is taken as if the precision
- were omitted." */
- if (arg >= 0)
- {
- precision = arg;
- has_precision = 1;
- }
- }
- else
- {
- const FCHAR_T *digitp = dp->precision_start + 1;
-
- precision = 0;
- while (digitp != dp->precision_end)
- precision = xsum (xtimes (precision, 10), *digitp++ - '0');
- has_precision = 1;
- }
- }
-
- /* Allocate a temporary buffer of sufficient size. */
- if (type == TYPE_LONGDOUBLE)
- tmp_length =
- (unsigned int) ((LDBL_DIG + 1)
- * 0.831 /* decimal -> hexadecimal */
- )
- + 1; /* turn floor into ceil */
- else
- tmp_length =
- (unsigned int) ((DBL_DIG + 1)
- * 0.831 /* decimal -> hexadecimal */
- )
- + 1; /* turn floor into ceil */
- if (tmp_length < precision)
- tmp_length = precision;
- /* Account for sign, decimal point etc. */
- tmp_length = xsum (tmp_length, 12);
-
- if (tmp_length < width)
- tmp_length = width;
-
- tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
-
- if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
- tmp = tmpbuf;
- else
- {
- size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
-
- if (size_overflow_p (tmp_memsize))
- /* Overflow, would lead to out of memory. */
- goto out_of_memory;
- tmp = (DCHAR_T *) malloc (tmp_memsize);
- if (tmp == NULL)
- /* Out of memory. */
- goto out_of_memory;
- }
-
- pad_ptr = NULL;
- p = tmp;
- if (type == TYPE_LONGDOUBLE)
- {
-# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE
- long double arg = a.arg[dp->arg_index].a.a_longdouble;
-
- if (isnanl (arg))
- {
- if (dp->conversion == 'A')
- {
- *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
- }
- else
- {
- *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
- }
- }
- else
- {
- int sign = 0;
- DECL_LONG_DOUBLE_ROUNDING
-
- BEGIN_LONG_DOUBLE_ROUNDING ();
-
- if (signbit (arg)) /* arg < 0.0L or negative zero */
- {
- sign = -1;
- arg = -arg;
- }
-
- if (sign < 0)
- *p++ = '-';
- else if (flags & FLAG_SHOWSIGN)
- *p++ = '+';
- else if (flags & FLAG_SPACE)
- *p++ = ' ';
-
- if (arg > 0.0L && arg + arg == arg)
- {
- if (dp->conversion == 'A')
- {
- *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
- }
- else
- {
- *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
- }
- }
- else
- {
- int exponent;
- long double mantissa;
-
- if (arg > 0.0L)
- mantissa = printf_frexpl (arg, &exponent);
- else
- {
- exponent = 0;
- mantissa = 0.0L;
- }
-
- if (has_precision
- && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1)
- {
- /* Round the mantissa. */
- long double tail = mantissa;
- size_t q;
-
- for (q = precision; ; q--)
- {
- int digit = (int) tail;
- tail -= digit;
- if (q == 0)
- {
- if (digit & 1 ? tail >= 0.5L : tail > 0.5L)
- tail = 1 - tail;
- else
- tail = - tail;
- break;
- }
- tail *= 16.0L;
- }
- if (tail != 0.0L)
- for (q = precision; q > 0; q--)
- tail *= 0.0625L;
- mantissa += tail;
- }
-
- *p++ = '0';
- *p++ = dp->conversion - 'A' + 'X';
- pad_ptr = p;
- {
- int digit;
-
- digit = (int) mantissa;
- mantissa -= digit;
- *p++ = '0' + digit;
- if ((flags & FLAG_ALT)
- || mantissa > 0.0L || precision > 0)
- {
- *p++ = decimal_point_char ();
- /* This loop terminates because we assume
- that FLT_RADIX is a power of 2. */
- while (mantissa > 0.0L)
- {
- mantissa *= 16.0L;
- digit = (int) mantissa;
- mantissa -= digit;
- *p++ = digit
- + (digit < 10
- ? '0'
- : dp->conversion - 10);
- if (precision > 0)
- precision--;
- }
- while (precision > 0)
- {
- *p++ = '0';
- precision--;
- }
- }
- }
- *p++ = dp->conversion - 'A' + 'P';
-# if WIDE_CHAR_VERSION
- {
- static const wchar_t decimal_format[] =
- { '%', '+', 'd', '\0' };
- SNPRINTF (p, 6 + 1, decimal_format, exponent);
- }
- while (*p != '\0')
- p++;
-# else
- if (sizeof (DCHAR_T) == 1)
- {
- sprintf ((char *) p, "%+d", exponent);
- while (*p != '\0')
- p++;
- }
- else
- {
- char expbuf[6 + 1];
- const char *ep;
- sprintf (expbuf, "%+d", exponent);
- for (ep = expbuf; (*p = *ep) != '\0'; ep++)
- p++;
- }
-# endif
- }
-
- END_LONG_DOUBLE_ROUNDING ();
- }
-# else
- abort ();
-# endif
- }
- else
- {
-# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE
- double arg = a.arg[dp->arg_index].a.a_double;
-
- if (isnand (arg))
- {
- if (dp->conversion == 'A')
- {
- *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
- }
- else
- {
- *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
- }
- }
- else
- {
- int sign = 0;
-
- if (signbit (arg)) /* arg < 0.0 or negative zero */
- {
- sign = -1;
- arg = -arg;
- }
-
- if (sign < 0)
- *p++ = '-';
- else if (flags & FLAG_SHOWSIGN)
- *p++ = '+';
- else if (flags & FLAG_SPACE)
- *p++ = ' ';
-
- if (arg > 0.0 && arg + arg == arg)
- {
- if (dp->conversion == 'A')
- {
- *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
- }
- else
- {
- *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
- }
- }
- else
- {
- int exponent;
- double mantissa;
-
- if (arg > 0.0)
- mantissa = printf_frexp (arg, &exponent);
- else
- {
- exponent = 0;
- mantissa = 0.0;
- }
-
- if (has_precision
- && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1)
- {
- /* Round the mantissa. */
- double tail = mantissa;
- size_t q;
-
- for (q = precision; ; q--)
- {
- int digit = (int) tail;
- tail -= digit;
- if (q == 0)
- {
- if (digit & 1 ? tail >= 0.5 : tail > 0.5)
- tail = 1 - tail;
- else
- tail = - tail;
- break;
- }
- tail *= 16.0;
- }
- if (tail != 0.0)
- for (q = precision; q > 0; q--)
- tail *= 0.0625;
- mantissa += tail;
- }
-
- *p++ = '0';
- *p++ = dp->conversion - 'A' + 'X';
- pad_ptr = p;
- {
- int digit;
-
- digit = (int) mantissa;
- mantissa -= digit;
- *p++ = '0' + digit;
- if ((flags & FLAG_ALT)
- || mantissa > 0.0 || precision > 0)
- {
- *p++ = decimal_point_char ();
- /* This loop terminates because we assume
- that FLT_RADIX is a power of 2. */
- while (mantissa > 0.0)
- {
- mantissa *= 16.0;
- digit = (int) mantissa;
- mantissa -= digit;
- *p++ = digit
- + (digit < 10
- ? '0'
- : dp->conversion - 10);
- if (precision > 0)
- precision--;
- }
- while (precision > 0)
- {
- *p++ = '0';
- precision--;
- }
- }
- }
- *p++ = dp->conversion - 'A' + 'P';
-# if WIDE_CHAR_VERSION
- {
- static const wchar_t decimal_format[] =
- { '%', '+', 'd', '\0' };
- SNPRINTF (p, 6 + 1, decimal_format, exponent);
- }
- while (*p != '\0')
- p++;
-# else
- if (sizeof (DCHAR_T) == 1)
- {
- sprintf ((char *) p, "%+d", exponent);
- while (*p != '\0')
- p++;
- }
- else
- {
- char expbuf[6 + 1];
- const char *ep;
- sprintf (expbuf, "%+d", exponent);
- for (ep = expbuf; (*p = *ep) != '\0'; ep++)
- p++;
- }
-# endif
- }
- }
-# else
- abort ();
-# endif
- }
- /* The generated string now extends from tmp to p, with the
- zero padding insertion point being at pad_ptr. */
- if (has_width && p - tmp < width)
- {
- size_t pad = width - (p - tmp);
- DCHAR_T *end = p + pad;
-
- if (flags & FLAG_LEFT)
- {
- /* Pad with spaces on the right. */
- for (; pad > 0; pad--)
- *p++ = ' ';
- }
- else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
- {
- /* Pad with zeroes. */
- DCHAR_T *q = end;
-
- while (p > pad_ptr)
- *--q = *--p;
- for (; pad > 0; pad--)
- *p++ = '0';
- }
- else
- {
- /* Pad with spaces on the left. */
- DCHAR_T *q = end;
-
- while (p > tmp)
- *--q = *--p;
- for (; pad > 0; pad--)
- *p++ = ' ';
- }
-
- p = end;
- }
-
- {
- size_t count = p - tmp;
-
- if (count >= tmp_length)
- /* tmp_length was incorrectly calculated - fix the
- code above! */
- abort ();
-
- /* Make room for the result. */
- if (count >= allocated - length)
- {
- size_t n = xsum (length, count);
-
- ENSURE_ALLOCATION (n);
- }
-
- /* Append the result. */
- memcpy (result + length, tmp, count * sizeof (DCHAR_T));
- if (tmp != tmpbuf)
- free (tmp);
- length += count;
- }
- }
-#endif
-#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
- else if ((dp->conversion == 'f' || dp->conversion == 'F'
- || dp->conversion == 'e' || dp->conversion == 'E'
- || dp->conversion == 'g' || dp->conversion == 'G'
- || dp->conversion == 'a' || dp->conversion == 'A')
- && (0
-# if NEED_PRINTF_DOUBLE
- || a.arg[dp->arg_index].type == TYPE_DOUBLE
-# elif NEED_PRINTF_INFINITE_DOUBLE
- || (a.arg[dp->arg_index].type == TYPE_DOUBLE
- /* The systems (mingw) which produce wrong output
- for Inf, -Inf, and NaN also do so for -0.0.
- Therefore we treat this case here as well. */
- && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double))
-# endif
-# if NEED_PRINTF_LONG_DOUBLE
- || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
-# elif NEED_PRINTF_INFINITE_LONG_DOUBLE
- || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
- /* Some systems produce wrong output for Inf,
- -Inf, and NaN. Some systems in this category
- (IRIX 5.3) also do so for -0.0. Therefore we
- treat this case here as well. */
- && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble))
-# endif
- ))
- {
-# if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE)
- arg_type type = a.arg[dp->arg_index].type;
-# endif
- int flags = dp->flags;
- int has_width;
- size_t width;
- int has_precision;
- size_t precision;
- size_t tmp_length;
- DCHAR_T tmpbuf[700];
- DCHAR_T *tmp;
- DCHAR_T *pad_ptr;
- DCHAR_T *p;
-
- has_width = 0;
- width = 0;
- if (dp->width_start != dp->width_end)
- {
- if (dp->width_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->width_arg_index].a.a_int;
- if (arg < 0)
- {
- /* "A negative field width is taken as a '-' flag
- followed by a positive field width." */
- flags |= FLAG_LEFT;
- width = (unsigned int) (-arg);
- }
- else
- width = arg;
- }
- else
- {
- const FCHAR_T *digitp = dp->width_start;
-
- do
- width = xsum (xtimes (width, 10), *digitp++ - '0');
- while (digitp != dp->width_end);
- }
- has_width = 1;
- }
-
- has_precision = 0;
- precision = 0;
- if (dp->precision_start != dp->precision_end)
- {
- if (dp->precision_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->precision_arg_index].a.a_int;
- /* "A negative precision is taken as if the precision
- were omitted." */
- if (arg >= 0)
- {
- precision = arg;
- has_precision = 1;
- }
- }
- else
- {
- const FCHAR_T *digitp = dp->precision_start + 1;
-
- precision = 0;
- while (digitp != dp->precision_end)
- precision = xsum (xtimes (precision, 10), *digitp++ - '0');
- has_precision = 1;
- }
- }
-
- /* POSIX specifies the default precision to be 6 for %f, %F,
- %e, %E, but not for %g, %G. Implementations appear to use
- the same default precision also for %g, %G. But for %a, %A,
- the default precision is 0. */
- if (!has_precision)
- if (!(dp->conversion == 'a' || dp->conversion == 'A'))
- precision = 6;
-
- /* Allocate a temporary buffer of sufficient size. */
-# if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE
- tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1);
-# elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE
- tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0);
-# elif NEED_PRINTF_LONG_DOUBLE
- tmp_length = LDBL_DIG + 1;
-# elif NEED_PRINTF_DOUBLE
- tmp_length = DBL_DIG + 1;
-# else
- tmp_length = 0;
-# endif
- if (tmp_length < precision)
- tmp_length = precision;
-# if NEED_PRINTF_LONG_DOUBLE
-# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
- if (type == TYPE_LONGDOUBLE)
-# endif
- if (dp->conversion == 'f' || dp->conversion == 'F')
- {
- long double arg = a.arg[dp->arg_index].a.a_longdouble;
- if (!(isnanl (arg) || arg + arg == arg))
- {
- /* arg is finite and nonzero. */
- int exponent = floorlog10l (arg < 0 ? -arg : arg);
- if (exponent >= 0 && tmp_length < exponent + precision)
- tmp_length = exponent + precision;
- }
- }
-# endif
-# if NEED_PRINTF_DOUBLE
-# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
- if (type == TYPE_DOUBLE)
-# endif
- if (dp->conversion == 'f' || dp->conversion == 'F')
- {
- double arg = a.arg[dp->arg_index].a.a_double;
- if (!(isnand (arg) || arg + arg == arg))
- {
- /* arg is finite and nonzero. */
- int exponent = floorlog10 (arg < 0 ? -arg : arg);
- if (exponent >= 0 && tmp_length < exponent + precision)
- tmp_length = exponent + precision;
- }
- }
-# endif
- /* Account for sign, decimal point etc. */
- tmp_length = xsum (tmp_length, 12);
-
- if (tmp_length < width)
- tmp_length = width;
-
- tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
-
- if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
- tmp = tmpbuf;
- else
- {
- size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
-
- if (size_overflow_p (tmp_memsize))
- /* Overflow, would lead to out of memory. */
- goto out_of_memory;
- tmp = (DCHAR_T *) malloc (tmp_memsize);
- if (tmp == NULL)
- /* Out of memory. */
- goto out_of_memory;
- }
-
- pad_ptr = NULL;
- p = tmp;
-
-# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
-# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
- if (type == TYPE_LONGDOUBLE)
-# endif
- {
- long double arg = a.arg[dp->arg_index].a.a_longdouble;
-
- if (isnanl (arg))
- {
- if (dp->conversion >= 'A' && dp->conversion <= 'Z')
- {
- *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
- }
- else
- {
- *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
- }
- }
- else
- {
- int sign = 0;
- DECL_LONG_DOUBLE_ROUNDING
-
- BEGIN_LONG_DOUBLE_ROUNDING ();
-
- if (signbit (arg)) /* arg < 0.0L or negative zero */
- {
- sign = -1;
- arg = -arg;
- }
-
- if (sign < 0)
- *p++ = '-';
- else if (flags & FLAG_SHOWSIGN)
- *p++ = '+';
- else if (flags & FLAG_SPACE)
- *p++ = ' ';
-
- if (arg > 0.0L && arg + arg == arg)
- {
- if (dp->conversion >= 'A' && dp->conversion <= 'Z')
- {
- *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
- }
- else
- {
- *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
- }
- }
- else
- {
-# if NEED_PRINTF_LONG_DOUBLE
- pad_ptr = p;
-
- if (dp->conversion == 'f' || dp->conversion == 'F')
- {
- char *digits;
- size_t ndigits;
-
- digits =
- scale10_round_decimal_long_double (arg, precision);
- if (digits == NULL)
- {
- END_LONG_DOUBLE_ROUNDING ();
- goto out_of_memory;
- }
- ndigits = strlen (digits);
-
- if (ndigits > precision)
- do
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- while (ndigits > precision);
- else
- *p++ = '0';
- /* Here ndigits <= precision. */
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > ndigits; precision--)
- *p++ = '0';
- while (ndigits > 0)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
-
- free (digits);
- }
- else if (dp->conversion == 'e' || dp->conversion == 'E')
- {
- int exponent;
-
- if (arg == 0.0L)
- {
- exponent = 0;
- *p++ = '0';
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > 0; precision--)
- *p++ = '0';
- }
- }
- else
- {
- /* arg > 0.0L. */
- int adjusted;
- char *digits;
- size_t ndigits;
-
- exponent = floorlog10l (arg);
- adjusted = 0;
- for (;;)
- {
- digits =
- scale10_round_decimal_long_double (arg,
- (int)precision - exponent);
- if (digits == NULL)
- {
- END_LONG_DOUBLE_ROUNDING ();
- goto out_of_memory;
- }
- ndigits = strlen (digits);
-
- if (ndigits == precision + 1)
- break;
- if (ndigits < precision
- || ndigits > precision + 2)
- /* The exponent was not guessed
- precisely enough. */
- abort ();
- if (adjusted)
- /* None of two values of exponent is
- the right one. Prevent an endless
- loop. */
- abort ();
- free (digits);
- if (ndigits == precision)
- exponent -= 1;
- else
- exponent += 1;
- adjusted = 1;
- }
- /* Here ndigits = precision+1. */
- if (is_borderline (digits, precision))
- {
- /* Maybe the exponent guess was too high
- and a smaller exponent can be reached
- by turning a 10...0 into 9...9x. */
- char *digits2 =
- scale10_round_decimal_long_double (arg,
- (int)precision - exponent + 1);
- if (digits2 == NULL)
- {
- free (digits);
- END_LONG_DOUBLE_ROUNDING ();
- goto out_of_memory;
- }
- if (strlen (digits2) == precision + 1)
- {
- free (digits);
- digits = digits2;
- exponent -= 1;
- }
- else
- free (digits2);
- }
- /* Here ndigits = precision+1. */
-
- *p++ = digits[--ndigits];
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- while (ndigits > 0)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
-
- free (digits);
- }
-
- *p++ = dp->conversion; /* 'e' or 'E' */
-# if WIDE_CHAR_VERSION
- {
- static const wchar_t decimal_format[] =
- { '%', '+', '.', '2', 'd', '\0' };
- SNPRINTF (p, 6 + 1, decimal_format, exponent);
- }
- while (*p != '\0')
- p++;
-# else
- if (sizeof (DCHAR_T) == 1)
- {
- sprintf ((char *) p, "%+.2d", exponent);
- while (*p != '\0')
- p++;
- }
- else
- {
- char expbuf[6 + 1];
- const char *ep;
- sprintf (expbuf, "%+.2d", exponent);
- for (ep = expbuf; (*p = *ep) != '\0'; ep++)
- p++;
- }
-# endif
- }
- else if (dp->conversion == 'g' || dp->conversion == 'G')
- {
- if (precision == 0)
- precision = 1;
- /* precision >= 1. */
-
- if (arg == 0.0L)
- /* The exponent is 0, >= -4, < precision.
- Use fixed-point notation. */
- {
- size_t ndigits = precision;
- /* Number of trailing zeroes that have to be
- dropped. */
- size_t nzeroes =
- (flags & FLAG_ALT ? 0 : precision - 1);
-
- --ndigits;
- *p++ = '0';
- if ((flags & FLAG_ALT) || ndigits > nzeroes)
- {
- *p++ = decimal_point_char ();
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = '0';
- }
- }
- }
- else
- {
- /* arg > 0.0L. */
- int exponent;
- int adjusted;
- char *digits;
- size_t ndigits;
- size_t nzeroes;
-
- exponent = floorlog10l (arg);
- adjusted = 0;
- for (;;)
- {
- digits =
- scale10_round_decimal_long_double (arg,
- (int)(precision - 1) - exponent);
- if (digits == NULL)
- {
- END_LONG_DOUBLE_ROUNDING ();
- goto out_of_memory;
- }
- ndigits = strlen (digits);
-
- if (ndigits == precision)
- break;
- if (ndigits < precision - 1
- || ndigits > precision + 1)
- /* The exponent was not guessed
- precisely enough. */
- abort ();
- if (adjusted)
- /* None of two values of exponent is
- the right one. Prevent an endless
- loop. */
- abort ();
- free (digits);
- if (ndigits < precision)
- exponent -= 1;
- else
- exponent += 1;
- adjusted = 1;
- }
- /* Here ndigits = precision. */
- if (is_borderline (digits, precision - 1))
- {
- /* Maybe the exponent guess was too high
- and a smaller exponent can be reached
- by turning a 10...0 into 9...9x. */
- char *digits2 =
- scale10_round_decimal_long_double (arg,
- (int)(precision - 1) - exponent + 1);
- if (digits2 == NULL)
- {
- free (digits);
- END_LONG_DOUBLE_ROUNDING ();
- goto out_of_memory;
- }
- if (strlen (digits2) == precision)
- {
- free (digits);
- digits = digits2;
- exponent -= 1;
- }
- else
- free (digits2);
- }
- /* Here ndigits = precision. */
-
- /* Determine the number of trailing zeroes
- that have to be dropped. */
- nzeroes = 0;
- if ((flags & FLAG_ALT) == 0)
- while (nzeroes < ndigits
- && digits[nzeroes] == '0')
- nzeroes++;
-
- /* The exponent is now determined. */
- if (exponent >= -4
- && exponent < (long)precision)
- {
- /* Fixed-point notation:
- max(exponent,0)+1 digits, then the
- decimal point, then the remaining
- digits without trailing zeroes. */
- if (exponent >= 0)
- {
- size_t count = exponent + 1;
- /* Note: count <= precision = ndigits. */
- for (; count > 0; count--)
- *p++ = digits[--ndigits];
- if ((flags & FLAG_ALT) || ndigits > nzeroes)
- {
- *p++ = decimal_point_char ();
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
- }
- else
- {
- size_t count = -exponent - 1;
- *p++ = '0';
- *p++ = decimal_point_char ();
- for (; count > 0; count--)
- *p++ = '0';
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
- }
- else
- {
- /* Exponential notation. */
- *p++ = digits[--ndigits];
- if ((flags & FLAG_ALT) || ndigits > nzeroes)
- {
- *p++ = decimal_point_char ();
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
- *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
-# if WIDE_CHAR_VERSION
- {
- static const wchar_t decimal_format[] =
- { '%', '+', '.', '2', 'd', '\0' };
- SNPRINTF (p, 6 + 1, decimal_format, exponent);
- }
- while (*p != '\0')
- p++;
-# else
- if (sizeof (DCHAR_T) == 1)
- {
- sprintf ((char *) p, "%+.2d", exponent);
- while (*p != '\0')
- p++;
- }
- else
- {
- char expbuf[6 + 1];
- const char *ep;
- sprintf (expbuf, "%+.2d", exponent);
- for (ep = expbuf; (*p = *ep) != '\0'; ep++)
- p++;
- }
-# endif
- }
-
- free (digits);
- }
- }
- else
- abort ();
-# else
- /* arg is finite. */
- if (!(arg == 0.0L))
- abort ();
-
- pad_ptr = p;
-
- if (dp->conversion == 'f' || dp->conversion == 'F')
- {
- *p++ = '0';
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > 0; precision--)
- *p++ = '0';
- }
- }
- else if (dp->conversion == 'e' || dp->conversion == 'E')
- {
- *p++ = '0';
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > 0; precision--)
- *p++ = '0';
- }
- *p++ = dp->conversion; /* 'e' or 'E' */
- *p++ = '+';
- *p++ = '0';
- *p++ = '0';
- }
- else if (dp->conversion == 'g' || dp->conversion == 'G')
- {
- *p++ = '0';
- if (flags & FLAG_ALT)
- {
- size_t ndigits =
- (precision > 0 ? precision - 1 : 0);
- *p++ = decimal_point_char ();
- for (; ndigits > 0; --ndigits)
- *p++ = '0';
- }
- }
- else if (dp->conversion == 'a' || dp->conversion == 'A')
- {
- *p++ = '0';
- *p++ = dp->conversion - 'A' + 'X';
- pad_ptr = p;
- *p++ = '0';
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > 0; precision--)
- *p++ = '0';
- }
- *p++ = dp->conversion - 'A' + 'P';
- *p++ = '+';
- *p++ = '0';
- }
- else
- abort ();
-# endif
- }
-
- END_LONG_DOUBLE_ROUNDING ();
- }
- }
-# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
- else
-# endif
-# endif
-# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
- {
- double arg = a.arg[dp->arg_index].a.a_double;
-
- if (isnand (arg))
- {
- if (dp->conversion >= 'A' && dp->conversion <= 'Z')
- {
- *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
- }
- else
- {
- *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
- }
- }
- else
- {
- int sign = 0;
-
- if (signbit (arg)) /* arg < 0.0 or negative zero */
- {
- sign = -1;
- arg = -arg;
- }
-
- if (sign < 0)
- *p++ = '-';
- else if (flags & FLAG_SHOWSIGN)
- *p++ = '+';
- else if (flags & FLAG_SPACE)
- *p++ = ' ';
-
- if (arg > 0.0 && arg + arg == arg)
- {
- if (dp->conversion >= 'A' && dp->conversion <= 'Z')
- {
- *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
- }
- else
- {
- *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
- }
- }
- else
- {
-# if NEED_PRINTF_DOUBLE
- pad_ptr = p;
-
- if (dp->conversion == 'f' || dp->conversion == 'F')
- {
- char *digits;
- size_t ndigits;
-
- digits =
- scale10_round_decimal_double (arg, precision);
- if (digits == NULL)
- goto out_of_memory;
- ndigits = strlen (digits);
-
- if (ndigits > precision)
- do
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- while (ndigits > precision);
- else
- *p++ = '0';
- /* Here ndigits <= precision. */
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > ndigits; precision--)
- *p++ = '0';
- while (ndigits > 0)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
-
- free (digits);
- }
- else if (dp->conversion == 'e' || dp->conversion == 'E')
- {
- int exponent;
-
- if (arg == 0.0)
- {
- exponent = 0;
- *p++ = '0';
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > 0; precision--)
- *p++ = '0';
- }
- }
- else
- {
- /* arg > 0.0. */
- int adjusted;
- char *digits;
- size_t ndigits;
-
- exponent = floorlog10 (arg);
- adjusted = 0;
- for (;;)
- {
- digits =
- scale10_round_decimal_double (arg,
- (int)precision - exponent);
- if (digits == NULL)
- goto out_of_memory;
- ndigits = strlen (digits);
-
- if (ndigits == precision + 1)
- break;
- if (ndigits < precision
- || ndigits > precision + 2)
- /* The exponent was not guessed
- precisely enough. */
- abort ();
- if (adjusted)
- /* None of two values of exponent is
- the right one. Prevent an endless
- loop. */
- abort ();
- free (digits);
- if (ndigits == precision)
- exponent -= 1;
- else
- exponent += 1;
- adjusted = 1;
- }
- /* Here ndigits = precision+1. */
- if (is_borderline (digits, precision))
- {
- /* Maybe the exponent guess was too high
- and a smaller exponent can be reached
- by turning a 10...0 into 9...9x. */
- char *digits2 =
- scale10_round_decimal_double (arg,
- (int)precision - exponent + 1);
- if (digits2 == NULL)
- {
- free (digits);
- goto out_of_memory;
- }
- if (strlen (digits2) == precision + 1)
- {
- free (digits);
- digits = digits2;
- exponent -= 1;
- }
- else
- free (digits2);
- }
- /* Here ndigits = precision+1. */
-
- *p++ = digits[--ndigits];
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- while (ndigits > 0)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
-
- free (digits);
- }
-
- *p++ = dp->conversion; /* 'e' or 'E' */
-# if WIDE_CHAR_VERSION
- {
- static const wchar_t decimal_format[] =
- /* Produce the same number of exponent digits
- as the native printf implementation. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- { '%', '+', '.', '3', 'd', '\0' };
-# else
- { '%', '+', '.', '2', 'd', '\0' };
-# endif
- SNPRINTF (p, 6 + 1, decimal_format, exponent);
- }
- while (*p != '\0')
- p++;
-# else
- {
- static const char decimal_format[] =
- /* Produce the same number of exponent digits
- as the native printf implementation. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- "%+.3d";
-# else
- "%+.2d";
-# endif
- if (sizeof (DCHAR_T) == 1)
- {
- sprintf ((char *) p, decimal_format, exponent);
- while (*p != '\0')
- p++;
- }
- else
- {
- char expbuf[6 + 1];
- const char *ep;
- sprintf (expbuf, decimal_format, exponent);
- for (ep = expbuf; (*p = *ep) != '\0'; ep++)
- p++;
- }
- }
-# endif
- }
- else if (dp->conversion == 'g' || dp->conversion == 'G')
- {
- if (precision == 0)
- precision = 1;
- /* precision >= 1. */
-
- if (arg == 0.0)
- /* The exponent is 0, >= -4, < precision.
- Use fixed-point notation. */
- {
- size_t ndigits = precision;
- /* Number of trailing zeroes that have to be
- dropped. */
- size_t nzeroes =
- (flags & FLAG_ALT ? 0 : precision - 1);
-
- --ndigits;
- *p++ = '0';
- if ((flags & FLAG_ALT) || ndigits > nzeroes)
- {
- *p++ = decimal_point_char ();
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = '0';
- }
- }
- }
- else
- {
- /* arg > 0.0. */
- int exponent;
- int adjusted;
- char *digits;
- size_t ndigits;
- size_t nzeroes;
-
- exponent = floorlog10 (arg);
- adjusted = 0;
- for (;;)
- {
- digits =
- scale10_round_decimal_double (arg,
- (int)(precision - 1) - exponent);
- if (digits == NULL)
- goto out_of_memory;
- ndigits = strlen (digits);
-
- if (ndigits == precision)
- break;
- if (ndigits < precision - 1
- || ndigits > precision + 1)
- /* The exponent was not guessed
- precisely enough. */
- abort ();
- if (adjusted)
- /* None of two values of exponent is
- the right one. Prevent an endless
- loop. */
- abort ();
- free (digits);
- if (ndigits < precision)
- exponent -= 1;
- else
- exponent += 1;
- adjusted = 1;
- }
- /* Here ndigits = precision. */
- if (is_borderline (digits, precision - 1))
- {
- /* Maybe the exponent guess was too high
- and a smaller exponent can be reached
- by turning a 10...0 into 9...9x. */
- char *digits2 =
- scale10_round_decimal_double (arg,
- (int)(precision - 1) - exponent + 1);
- if (digits2 == NULL)
- {
- free (digits);
- goto out_of_memory;
- }
- if (strlen (digits2) == precision)
- {
- free (digits);
- digits = digits2;
- exponent -= 1;
- }
- else
- free (digits2);
- }
- /* Here ndigits = precision. */
-
- /* Determine the number of trailing zeroes
- that have to be dropped. */
- nzeroes = 0;
- if ((flags & FLAG_ALT) == 0)
- while (nzeroes < ndigits
- && digits[nzeroes] == '0')
- nzeroes++;
-
- /* The exponent is now determined. */
- if (exponent >= -4
- && exponent < (long)precision)
- {
- /* Fixed-point notation:
- max(exponent,0)+1 digits, then the
- decimal point, then the remaining
- digits without trailing zeroes. */
- if (exponent >= 0)
- {
- size_t count = exponent + 1;
- /* Note: count <= precision = ndigits. */
- for (; count > 0; count--)
- *p++ = digits[--ndigits];
- if ((flags & FLAG_ALT) || ndigits > nzeroes)
- {
- *p++ = decimal_point_char ();
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
- }
- else
- {
- size_t count = -exponent - 1;
- *p++ = '0';
- *p++ = decimal_point_char ();
- for (; count > 0; count--)
- *p++ = '0';
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
- }
- else
- {
- /* Exponential notation. */
- *p++ = digits[--ndigits];
- if ((flags & FLAG_ALT) || ndigits > nzeroes)
- {
- *p++ = decimal_point_char ();
- while (ndigits > nzeroes)
- {
- --ndigits;
- *p++ = digits[ndigits];
- }
- }
- *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
-# if WIDE_CHAR_VERSION
- {
- static const wchar_t decimal_format[] =
- /* Produce the same number of exponent digits
- as the native printf implementation. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- { '%', '+', '.', '3', 'd', '\0' };
-# else
- { '%', '+', '.', '2', 'd', '\0' };
-# endif
- SNPRINTF (p, 6 + 1, decimal_format, exponent);
- }
- while (*p != '\0')
- p++;
-# else
- {
- static const char decimal_format[] =
- /* Produce the same number of exponent digits
- as the native printf implementation. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- "%+.3d";
-# else
- "%+.2d";
-# endif
- if (sizeof (DCHAR_T) == 1)
- {
- sprintf ((char *) p, decimal_format, exponent);
- while (*p != '\0')
- p++;
- }
- else
- {
- char expbuf[6 + 1];
- const char *ep;
- sprintf (expbuf, decimal_format, exponent);
- for (ep = expbuf; (*p = *ep) != '\0'; ep++)
- p++;
- }
- }
-# endif
- }
-
- free (digits);
- }
- }
- else
- abort ();
-# else
- /* arg is finite. */
- if (!(arg == 0.0))
- abort ();
-
- pad_ptr = p;
-
- if (dp->conversion == 'f' || dp->conversion == 'F')
- {
- *p++ = '0';
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > 0; precision--)
- *p++ = '0';
- }
- }
- else if (dp->conversion == 'e' || dp->conversion == 'E')
- {
- *p++ = '0';
- if ((flags & FLAG_ALT) || precision > 0)
- {
- *p++ = decimal_point_char ();
- for (; precision > 0; precision--)
- *p++ = '0';
- }
- *p++ = dp->conversion; /* 'e' or 'E' */
- *p++ = '+';
- /* Produce the same number of exponent digits as
- the native printf implementation. */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- *p++ = '0';
-# endif
- *p++ = '0';
- *p++ = '0';
- }
- else if (dp->conversion == 'g' || dp->conversion == 'G')
- {
- *p++ = '0';
- if (flags & FLAG_ALT)
- {
- size_t ndigits =
- (precision > 0 ? precision - 1 : 0);
- *p++ = decimal_point_char ();
- for (; ndigits > 0; --ndigits)
- *p++ = '0';
- }
- }
- else
- abort ();
-# endif
- }
- }
- }
-# endif
-
- /* The generated string now extends from tmp to p, with the
- zero padding insertion point being at pad_ptr. */
- if (has_width && p - tmp < width)
- {
- size_t pad = width - (p - tmp);
- DCHAR_T *end = p + pad;
-
- if (flags & FLAG_LEFT)
- {
- /* Pad with spaces on the right. */
- for (; pad > 0; pad--)
- *p++ = ' ';
- }
- else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
- {
- /* Pad with zeroes. */
- DCHAR_T *q = end;
-
- while (p > pad_ptr)
- *--q = *--p;
- for (; pad > 0; pad--)
- *p++ = '0';
- }
- else
- {
- /* Pad with spaces on the left. */
- DCHAR_T *q = end;
-
- while (p > tmp)
- *--q = *--p;
- for (; pad > 0; pad--)
- *p++ = ' ';
- }
-
- p = end;
- }
-
- {
- size_t count = p - tmp;
-
- if (count >= tmp_length)
- /* tmp_length was incorrectly calculated - fix the
- code above! */
- abort ();
-
- /* Make room for the result. */
- if (count >= allocated - length)
- {
- size_t n = xsum (length, count);
-
- ENSURE_ALLOCATION (n);
- }
-
- /* Append the result. */
- memcpy (result + length, tmp, count * sizeof (DCHAR_T));
- if (tmp != tmpbuf)
- free (tmp);
- length += count;
- }
- }
-#endif
- else
- {
- arg_type type = a.arg[dp->arg_index].type;
- int flags = dp->flags;
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
- int has_width;
- size_t width;
-#endif
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION
- int has_precision;
- size_t precision;
-#endif
-#if NEED_PRINTF_UNBOUNDED_PRECISION
- int prec_ourselves;
-#else
-# define prec_ourselves 0
-#endif
-#if NEED_PRINTF_FLAG_LEFTADJUST
-# define pad_ourselves 1
-#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
- int pad_ourselves;
-#else
-# define pad_ourselves 0
-#endif
- TCHAR_T *fbp;
- unsigned int prefix_count;
- int prefixes[2] IF_LINT (= { 0 });
- int orig_errno;
-#if !USE_SNPRINTF
- size_t tmp_length;
- TCHAR_T tmpbuf[700];
- TCHAR_T *tmp;
-#endif
-
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
- has_width = 0;
- width = 0;
- if (dp->width_start != dp->width_end)
- {
- if (dp->width_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->width_arg_index].a.a_int;
- if (arg < 0)
- {
- /* "A negative field width is taken as a '-' flag
- followed by a positive field width." */
- flags |= FLAG_LEFT;
- width = (unsigned int) (-arg);
- }
- else
- width = arg;
- }
- else
- {
- const FCHAR_T *digitp = dp->width_start;
-
- do
- width = xsum (xtimes (width, 10), *digitp++ - '0');
- while (digitp != dp->width_end);
- }
- has_width = 1;
- }
-#endif
-
-#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION
- has_precision = 0;
- precision = 6;
- if (dp->precision_start != dp->precision_end)
- {
- if (dp->precision_arg_index != ARG_NONE)
- {
- int arg;
-
- if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
- abort ();
- arg = a.arg[dp->precision_arg_index].a.a_int;
- /* "A negative precision is taken as if the precision
- were omitted." */
- if (arg >= 0)
- {
- precision = arg;
- has_precision = 1;
- }
- }
- else
- {
- const FCHAR_T *digitp = dp->precision_start + 1;
-
- precision = 0;
- while (digitp != dp->precision_end)
- precision = xsum (xtimes (precision, 10), *digitp++ - '0');
- has_precision = 1;
- }
- }
-#endif
-
- /* Decide whether to handle the precision ourselves. */
-#if NEED_PRINTF_UNBOUNDED_PRECISION
- switch (dp->conversion)
- {
- case 'd': case 'i': case 'u':
- case 'o':
- case 'x': case 'X': case 'p':
- prec_ourselves = has_precision && (precision > 0);
- break;
- default:
- prec_ourselves = 0;
- break;
- }
-#endif
-
- /* Decide whether to perform the padding ourselves. */
-#if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION)
- switch (dp->conversion)
- {
-# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
- /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need
- to perform the padding after this conversion. Functions
- with unistdio extensions perform the padding based on
- character count rather than element count. */
- case 'c': case 's':
-# endif
-# if NEED_PRINTF_FLAG_ZERO
- case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
- case 'a': case 'A':
-# endif
- pad_ourselves = 1;
- break;
- default:
- pad_ourselves = prec_ourselves;
- break;
- }
-#endif
-
-#if !USE_SNPRINTF
- /* Allocate a temporary buffer of sufficient size for calling
- sprintf. */
- tmp_length =
- MAX_ROOM_NEEDED (&a, dp->arg_index, dp->conversion, type,
- flags, width, has_precision, precision,
- pad_ourselves);
-
- if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T))
- tmp = tmpbuf;
- else
- {
- size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T));
-
- if (size_overflow_p (tmp_memsize))
- /* Overflow, would lead to out of memory. */
- goto out_of_memory;
- tmp = (TCHAR_T *) malloc (tmp_memsize);
- if (tmp == NULL)
- /* Out of memory. */
- goto out_of_memory;
- }
-#endif
-
- /* Construct the format string for calling snprintf or
- sprintf. */
- fbp = buf;
- *fbp++ = '%';
-#if NEED_PRINTF_FLAG_GROUPING
- /* The underlying implementation doesn't support the ' flag.
- Produce no grouping characters in this case; this is
- acceptable because the grouping is locale dependent. */
-#else
- if (flags & FLAG_GROUP)
- *fbp++ = '\'';
-#endif
- if (flags & FLAG_LEFT)
- *fbp++ = '-';
- if (flags & FLAG_SHOWSIGN)
- *fbp++ = '+';
- if (flags & FLAG_SPACE)
- *fbp++ = ' ';
- if (flags & FLAG_ALT)
- *fbp++ = '#';
-#if __GLIBC__ >= 2 && !defined __UCLIBC__
- if (flags & FLAG_LOCALIZED)
- *fbp++ = 'I';
-#endif
- if (!pad_ourselves)
- {
- if (flags & FLAG_ZERO)
- *fbp++ = '0';
- if (dp->width_start != dp->width_end)
- {
- size_t n = dp->width_end - dp->width_start;
- /* The width specification is known to consist only
- of standard ASCII characters. */
- if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
- {
- memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T));
- fbp += n;
- }
- else
- {
- const FCHAR_T *mp = dp->width_start;
- do
- *fbp++ = (unsigned char) *mp++;
- while (--n > 0);
- }
- }
- }
- if (!prec_ourselves)
- {
- if (dp->precision_start != dp->precision_end)
- {
- size_t n = dp->precision_end - dp->precision_start;
- /* The precision specification is known to consist only
- of standard ASCII characters. */
- if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
- {
- memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T));
- fbp += n;
- }
- else
- {
- const FCHAR_T *mp = dp->precision_start;
- do
- *fbp++ = (unsigned char) *mp++;
- while (--n > 0);
- }
- }
- }
-
- switch (type)
- {
-#if HAVE_LONG_LONG_INT
- case TYPE_LONGLONGINT:
- case TYPE_ULONGLONGINT:
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
- *fbp++ = 'I';
- *fbp++ = '6';
- *fbp++ = '4';
- break;
-# else
- *fbp++ = 'l';
- /*FALLTHROUGH*/
-# endif
-#endif
- case TYPE_LONGINT:
- case TYPE_ULONGINT:
-#if HAVE_WINT_T
- case TYPE_WIDE_CHAR:
-#endif
-#if HAVE_WCHAR_T
- case TYPE_WIDE_STRING:
-#endif
- *fbp++ = 'l';
- break;
- case TYPE_LONGDOUBLE:
- *fbp++ = 'L';
- break;
- default:
- break;
- }
-#if NEED_PRINTF_DIRECTIVE_F
- if (dp->conversion == 'F')
- *fbp = 'f';
- else
-#endif
- *fbp = dp->conversion;
-#if USE_SNPRINTF
+#endif
+
+/* Specification. */
+#ifndef VASNPRINTF
+# if WIDE_CHAR_VERSION
+# include "vasnwprintf.h"
+# else
+# include "vasnprintf.h"
+# endif
+#endif
+
+#include <locale.h> /* localeconv() */
+#include <stdio.h> /* snprintf(), sprintf() */
+#include <stdlib.h> /* abort(), malloc(), realloc(), free() */
+#include <string.h> /* memcpy(), strlen() */
+#include <errno.h> /* errno */
+#include <limits.h> /* CHAR_BIT */
+#include <float.h> /* DBL_MAX_EXP, LDBL_MAX_EXP */
+#if HAVE_NL_LANGINFO
+# include <langinfo.h>
+#endif
+#ifndef VASNPRINTF
+# if WIDE_CHAR_VERSION
+# include "wprintf-parse.h"
+# else
+# include "printf-parse.h"
+# endif
+#endif
+
+/* Checked size_t computations. */
+#include "xsize.h"
+
+#include "verify.h"
+
+#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
+# include <math.h>
+# include "float+.h"
+#endif
+
+#if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
+# include <math.h>
+# include "isnand-nolibm.h"
+#endif
+
+#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) && !defined IN_LIBINTL
+# include <math.h>
+# include "isnanl-nolibm.h"
+# include "fpucw.h"
+#endif
+
+#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
+# include <math.h>
+# include "isnand-nolibm.h"
+# include "printf-frexp.h"
+#endif
+
+#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
+# include <math.h>
+# include "isnanl-nolibm.h"
+# include "printf-frexpl.h"
+# include "fpucw.h"
+#endif
+
+/* Default parameters. */
+#ifndef VASNPRINTF
+# if WIDE_CHAR_VERSION
+# define VASNPRINTF vasnwprintf
+# define FCHAR_T wchar_t
+# define DCHAR_T wchar_t
+# define TCHAR_T wchar_t
+# define DCHAR_IS_TCHAR 1
+# define DIRECTIVE wchar_t_directive
+# define DIRECTIVES wchar_t_directives
+# define PRINTF_PARSE wprintf_parse
+# define DCHAR_CPY wmemcpy
+# define DCHAR_SET wmemset
+# else
+# define VASNPRINTF vasnprintf
+# define FCHAR_T char
+# define DCHAR_T char
+# define TCHAR_T char
+# define DCHAR_IS_TCHAR 1
+# define DIRECTIVE char_directive
+# define DIRECTIVES char_directives
+# define PRINTF_PARSE printf_parse
+# define DCHAR_CPY memcpy
+# define DCHAR_SET memset
+# endif
+#endif
+#if WIDE_CHAR_VERSION
+ /* TCHAR_T is wchar_t. */
+# define USE_SNPRINTF 1
+# if HAVE_DECL__SNWPRINTF
+ /* On Windows, the function swprintf() has a different signature than
+ on Unix; we use the function _snwprintf() or - on mingw - snwprintf()
+ instead. The mingw function snwprintf() has fewer bugs than the
+ MSVCRT function _snwprintf(), so prefer that. */
+# if defined __MINGW32__
+# define SNPRINTF snwprintf
+# else
+# define SNPRINTF _snwprintf
+# endif
+# else
+ /* Unix. */
+# define SNPRINTF swprintf
+# endif
+#else
+ /* TCHAR_T is char. */
+ /* Use snprintf if it exists under the name 'snprintf' or '_snprintf'.
+ But don't use it on BeOS, since BeOS snprintf produces no output if the
+ size argument is >= 0x3000000.
+ Also don't use it on Linux libc5, since there snprintf with size = 1
+ writes any output without bounds, like sprintf. */
+# if (HAVE_DECL__SNPRINTF || HAVE_SNPRINTF) && !defined __BEOS__ && !(__GNU_LIBRARY__ == 1)
+# define USE_SNPRINTF 1
+# else
+# define USE_SNPRINTF 0
+# endif
+# if HAVE_DECL__SNPRINTF
+ /* Windows. The mingw function snprintf() has fewer bugs than the MSVCRT
+ function _snprintf(), so prefer that. */
+# if defined __MINGW32__
+# define SNPRINTF snprintf
+ /* Here we need to call the native snprintf, not rpl_snprintf. */
+# undef snprintf
+# else
+# define SNPRINTF _snprintf
+# endif
+# else
+ /* Unix. */
+# define SNPRINTF snprintf
+ /* Here we need to call the native snprintf, not rpl_snprintf. */
+# undef snprintf
+# endif
+#endif
+/* Here we need to call the native sprintf, not rpl_sprintf. */
+#undef sprintf
+
+/* GCC >= 4.0 with -Wall emits unjustified "... may be used uninitialized"
+ warnings in this file. Use -Dlint to suppress them. */
+#ifdef lint
+# define IF_LINT(Code) Code
+#else
+# define IF_LINT(Code) /* empty */
+#endif
+
+/* Avoid some warnings from "gcc -Wshadow".
+ This file doesn't use the exp() and remainder() functions. */
+#undef exp
+#define exp expo
+#undef remainder
+#define remainder rem
+
+#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && !WIDE_CHAR_VERSION
+# if (HAVE_STRNLEN && !defined _AIX)
+# define local_strnlen strnlen
+# else
+# ifndef local_strnlen_defined
+# define local_strnlen_defined 1
+static size_t
+local_strnlen (const char *string, size_t maxlen)
+{
+ const char *end = memchr (string, '\0', maxlen);
+ return end ? (size_t) (end - string) : maxlen;
+}
+# endif
+# endif
+#endif
+
+#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T
+# if HAVE_WCSLEN
+# define local_wcslen wcslen
+# else
+ /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid
+ a dependency towards this library, here is a local substitute.
+ Define this substitute only once, even if this file is included
+ twice in the same compilation unit. */
+# ifndef local_wcslen_defined
+# define local_wcslen_defined 1
+static size_t
+local_wcslen (const wchar_t *s)
+{
+ const wchar_t *ptr;
+
+ for (ptr = s; *ptr != (wchar_t) 0; ptr++)
+ ;
+ return ptr - s;
+}
+# endif
+# endif
+#endif
+
+#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && HAVE_WCHAR_T && WIDE_CHAR_VERSION
+# if HAVE_WCSNLEN
+# define local_wcsnlen wcsnlen
+# else
+# ifndef local_wcsnlen_defined
+# define local_wcsnlen_defined 1
+static size_t
+local_wcsnlen (const wchar_t *s, size_t maxlen)
+{
+ const wchar_t *ptr;
+
+ for (ptr = s; maxlen > 0 && *ptr != (wchar_t) 0; ptr++, maxlen--)
+ ;
+ return ptr - s;
+}
+# endif
+# endif
+#endif
+
+#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && !defined IN_LIBINTL
+/* Determine the decimal-point character according to the current locale. */
+# ifndef decimal_point_char_defined
+# define decimal_point_char_defined 1
+static char
+decimal_point_char (void)
+{
+ const char *point;
+ /* Determine it in a multithread-safe way. We know nl_langinfo is
+ multithread-safe on glibc systems and Mac OS X systems, but is not required
+ to be multithread-safe by POSIX. sprintf(), however, is multithread-safe.
+ localeconv() is rarely multithread-safe. */
+# if HAVE_NL_LANGINFO && (__GLIBC__ || defined __UCLIBC__ || (defined __APPLE__ && defined __MACH__))
+ point = nl_langinfo (RADIXCHAR);
+# elif 1
+ char pointbuf[5];
+ sprintf (pointbuf, "%#.0f", 1.0);
+ point = &pointbuf[1];
+# else
+ point = localeconv () -> decimal_point;
+# endif
+ /* The decimal point is always a single byte: either '.' or ','. */
+ return (point[0] != '\0' ? point[0] : '.');
+}
+# endif
+#endif
+
+#if NEED_PRINTF_INFINITE_DOUBLE && !NEED_PRINTF_DOUBLE && !defined IN_LIBINTL
+
+/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */
+static int
+is_infinite_or_zero (double x)
+{
+ return isnand (x) || x + x == x;
+}
+
+#endif
+
+#if NEED_PRINTF_INFINITE_LONG_DOUBLE && !NEED_PRINTF_LONG_DOUBLE && !defined IN_LIBINTL
+
+/* Equivalent to !isfinite(x) || x == 0, but does not require libm. */
+static int
+is_infinite_or_zerol (long double x)
+{
+ return isnanl (x) || x + x == x;
+}
+
+#endif
+
+#if (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
+
+/* Converting 'long double' to decimal without rare rounding bugs requires
+ real bignums. We use the naming conventions of GNU gmp, but vastly simpler
+ (and slower) algorithms. */
+
+typedef unsigned int mp_limb_t;
+# define GMP_LIMB_BITS 32
+verify (sizeof (mp_limb_t) * CHAR_BIT == GMP_LIMB_BITS);
+
+typedef unsigned long long mp_twolimb_t;
+# define GMP_TWOLIMB_BITS 64
+verify (sizeof (mp_twolimb_t) * CHAR_BIT == GMP_TWOLIMB_BITS);
+
+/* Representation of a bignum >= 0. */
+typedef struct
+{
+ size_t nlimbs;
+ mp_limb_t *limbs; /* Bits in little-endian order, allocated with malloc(). */
+} mpn_t;
+
+/* Compute the product of two bignums >= 0.
+ Return the allocated memory in case of success, NULL in case of memory
+ allocation failure. */
+static void *
+multiply (mpn_t src1, mpn_t src2, mpn_t *dest)
+{
+ const mp_limb_t *p1;
+ const mp_limb_t *p2;
+ size_t len1;
+ size_t len2;
+
+ if (src1.nlimbs <= src2.nlimbs)
+ {
+ len1 = src1.nlimbs;
+ p1 = src1.limbs;
+ len2 = src2.nlimbs;
+ p2 = src2.limbs;
+ }
+ else
+ {
+ len1 = src2.nlimbs;
+ p1 = src2.limbs;
+ len2 = src1.nlimbs;
+ p2 = src1.limbs;
+ }
+ /* Now 0 <= len1 <= len2. */
+ if (len1 == 0)
+ {
+ /* src1 or src2 is zero. */
+ dest->nlimbs = 0;
+ dest->limbs = (mp_limb_t *) malloc (1);
+ }
+ else
+ {
+ /* Here 1 <= len1 <= len2. */
+ size_t dlen;
+ mp_limb_t *dp;
+ size_t k, i, j;
+
+ dlen = len1 + len2;
+ dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t));
+ if (dp == NULL)
+ return NULL;
+ for (k = len2; k > 0; )
+ dp[--k] = 0;
+ for (i = 0; i < len1; i++)
+ {
+ mp_limb_t digit1 = p1[i];
+ mp_twolimb_t carry = 0;
+ for (j = 0; j < len2; j++)
+ {
+ mp_limb_t digit2 = p2[j];
+ carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
+ carry += dp[i + j];
+ dp[i + j] = (mp_limb_t) carry;
+ carry = carry >> GMP_LIMB_BITS;
+ }
+ dp[i + len2] = (mp_limb_t) carry;
+ }
+ /* Normalise. */
+ while (dlen > 0 && dp[dlen - 1] == 0)
+ dlen--;
+ dest->nlimbs = dlen;
+ dest->limbs = dp;
+ }
+ return dest->limbs;
+}
+
+/* Compute the quotient of a bignum a >= 0 and a bignum b > 0.
+ a is written as a = q * b + r with 0 <= r < b. q is the quotient, r
+ the remainder.
+ Finally, round-to-even is performed: If r > b/2 or if r = b/2 and q is odd,
+ q is incremented.
+ Return the allocated memory in case of success, NULL in case of memory
+ allocation failure. */
+static void *
+divide (mpn_t a, mpn_t b, mpn_t *q)
+{
+ /* Algorithm:
+ First normalise a and b: a=[a[m-1],...,a[0]], b=[b[n-1],...,b[0]]
+ with m>=0 and n>0 (in base beta = 2^GMP_LIMB_BITS).
+ If m<n, then q:=0 and r:=a.
+ If m>=n=1, perform a single-precision division:
+ r:=0, j:=m,
+ while j>0 do
+ {Here (q[m-1]*beta^(m-1)+...+q[j]*beta^j) * b[0] + r*beta^j =
+ = a[m-1]*beta^(m-1)+...+a[j]*beta^j und 0<=r<b[0]<beta}
+ j:=j-1, r:=r*beta+a[j], q[j]:=floor(r/b[0]), r:=r-b[0]*q[j].
+ Normalise [q[m-1],...,q[0]], yields q.
+ If m>=n>1, perform a multiple-precision division:
+ We have a/b < beta^(m-n+1).
+ s:=intDsize-1-(highest bit in b[n-1]), 0<=s<intDsize.
+ Shift a and b left by s bits, copying them. r:=a.
+ r=[r[m],...,r[0]], b=[b[n-1],...,b[0]] with b[n-1]>=beta/2.
+ For j=m-n,...,0: {Here 0 <= r < b*beta^(j+1).}
+ Compute q* :
+ q* := floor((r[j+n]*beta+r[j+n-1])/b[n-1]).
+ In case of overflow (q* >= beta) set q* := beta-1.
+ Compute c2 := ((r[j+n]*beta+r[j+n-1]) - q* * b[n-1])*beta + r[j+n-2]
+ and c3 := b[n-2] * q*.
+ {We have 0 <= c2 < 2*beta^2, even 0 <= c2 < beta^2 if no overflow
+ occurred. Furthermore 0 <= c3 < beta^2.
+ If there was overflow and
+ r[j+n]*beta+r[j+n-1] - q* * b[n-1] >= beta, i.e. c2 >= beta^2,
+ the next test can be skipped.}
+ While c3 > c2, {Here 0 <= c2 < c3 < beta^2}
+ Put q* := q* - 1, c2 := c2 + b[n-1]*beta, c3 := c3 - b[n-2].
+ If q* > 0:
+ Put r := r - b * q* * beta^j. In detail:
+ [r[n+j],...,r[j]] := [r[n+j],...,r[j]] - q* * [b[n-1],...,b[0]].
+ hence: u:=0, for i:=0 to n-1 do
+ u := u + q* * b[i],
+ r[j+i]:=r[j+i]-(u mod beta) (+ beta, if carry),
+ u:=u div beta (+ 1, if carry in subtraction)
+ r[n+j]:=r[n+j]-u.
+ {Since always u = (q* * [b[i-1],...,b[0]] div beta^i) + 1
+ < q* + 1 <= beta,
+ the carry u does not overflow.}
+ If a negative carry occurs, put q* := q* - 1
+ and [r[n+j],...,r[j]] := [r[n+j],...,r[j]] + [0,b[n-1],...,b[0]].
+ Set q[j] := q*.
+ Normalise [q[m-n],..,q[0]]; this yields the quotient q.
+ Shift [r[n-1],...,r[0]] right by s bits and normalise; this yields the
+ rest r.
+ The room for q[j] can be allocated at the memory location of r[n+j].
+ Finally, round-to-even:
+ Shift r left by 1 bit.
+ If r > b or if r = b and q[0] is odd, q := q+1.
+ */
+ const mp_limb_t *a_ptr = a.limbs;
+ size_t a_len = a.nlimbs;
+ const mp_limb_t *b_ptr = b.limbs;
+ size_t b_len = b.nlimbs;
+ mp_limb_t *roomptr;
+ mp_limb_t *tmp_roomptr = NULL;
+ mp_limb_t *q_ptr;
+ size_t q_len;
+ mp_limb_t *r_ptr;
+ size_t r_len;
+
+ /* Allocate room for a_len+2 digits.
+ (Need a_len+1 digits for the real division and 1 more digit for the
+ final rounding of q.) */
+ roomptr = (mp_limb_t *) malloc ((a_len + 2) * sizeof (mp_limb_t));
+ if (roomptr == NULL)
+ return NULL;
+
+ /* Normalise a. */
+ while (a_len > 0 && a_ptr[a_len - 1] == 0)
+ a_len--;
+
+ /* Normalise b. */
+ for (;;)
+ {
+ if (b_len == 0)
+ /* Division by zero. */
+ abort ();
+ if (b_ptr[b_len - 1] == 0)
+ b_len--;
+ else
+ break;
+ }
+
+ /* Here m = a_len >= 0 and n = b_len > 0. */
+
+ if (a_len < b_len)
+ {
+ /* m<n: trivial case. q=0, r := copy of a. */
+ r_ptr = roomptr;
+ r_len = a_len;
+ memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t));
+ q_ptr = roomptr + a_len;
+ q_len = 0;
+ }
+ else if (b_len == 1)
+ {
+ /* n=1: single precision division.
+ beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */
+ r_ptr = roomptr;
+ q_ptr = roomptr + 1;
+ {
+ mp_limb_t den = b_ptr[0];
+ mp_limb_t remainder = 0;
+ const mp_limb_t *sourceptr = a_ptr + a_len;
+ mp_limb_t *destptr = q_ptr + a_len;
+ size_t count;
+ for (count = a_len; count > 0; count--)
+ {
+ mp_twolimb_t num =
+ ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr;
+ *--destptr = num / den;
+ remainder = num % den;
+ }
+ /* Normalise and store r. */
+ if (remainder > 0)
+ {
+ r_ptr[0] = remainder;
+ r_len = 1;
+ }
+ else
+ r_len = 0;
+ /* Normalise q. */
+ q_len = a_len;
+ if (q_ptr[q_len - 1] == 0)
+ q_len--;
+ }
+ }
+ else
+ {
+ /* n>1: multiple precision division.
+ beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==>
+ beta^(m-n-1) <= a/b < beta^(m-n+1). */
+ /* Determine s. */
+ size_t s;
+ {
+ mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
+ /* Determine s = GMP_LIMB_BITS - integer_length (msd).
+ Code copied from gnulib's integer_length.c. */
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+ s = __builtin_clz (msd);
+# else
+# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+ if (GMP_LIMB_BITS <= DBL_MANT_BIT)
+ {
+ /* Use 'double' operations.
+ Assumes an IEEE 754 'double' implementation. */
+# define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
+# define DBL_EXP_BIAS (DBL_EXP_MASK / 2 - 1)
+# define NWORDS \
+ ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+ union { double value; unsigned int word[NWORDS]; } m;
+
+ /* Use a single integer to floating-point conversion. */
+ m.value = msd;
+
+ s = GMP_LIMB_BITS
+ - (((m.word[DBL_EXPBIT0_WORD] >> DBL_EXPBIT0_BIT) & DBL_EXP_MASK)
+ - DBL_EXP_BIAS);
+ }
+ else
+# undef NWORDS
+# endif
+ {
+ s = 31;
+ if (msd >= 0x10000)
+ {
+ msd = msd >> 16;
+ s -= 16;
+ }
+ if (msd >= 0x100)
+ {
+ msd = msd >> 8;
+ s -= 8;
+ }
+ if (msd >= 0x10)
+ {
+ msd = msd >> 4;
+ s -= 4;
+ }
+ if (msd >= 0x4)
+ {
+ msd = msd >> 2;
+ s -= 2;
+ }
+ if (msd >= 0x2)
+ {
+ msd = msd >> 1;
+ s -= 1;
+ }
+ }
+# endif
+ }
+ /* 0 <= s < GMP_LIMB_BITS.
+ Copy b, shifting it left by s bits. */
+ if (s > 0)
+ {
+ tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t));
+ if (tmp_roomptr == NULL)
+ {
+ free (roomptr);
+ return NULL;
+ }
+ {
+ const mp_limb_t *sourceptr = b_ptr;
+ mp_limb_t *destptr = tmp_roomptr;
+ mp_twolimb_t accu = 0;
+ size_t count;
+ for (count = b_len; count > 0; count--)
+ {
+ accu += (mp_twolimb_t) *sourceptr++ << s;
+ *destptr++ = (mp_limb_t) accu;
+ accu = accu >> GMP_LIMB_BITS;
+ }
+ /* accu must be zero, since that was how s was determined. */
+ if (accu != 0)
+ abort ();
+ }
+ b_ptr = tmp_roomptr;
+ }
+ /* Copy a, shifting it left by s bits, yields r.
+ Memory layout:
+ At the beginning: r = roomptr[0..a_len],
+ at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */
+ r_ptr = roomptr;
+ if (s == 0)
+ {
+ memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t));
+ r_ptr[a_len] = 0;
+ }
+ else
+ {
+ const mp_limb_t *sourceptr = a_ptr;
+ mp_limb_t *destptr = r_ptr;
+ mp_twolimb_t accu = 0;
+ size_t count;
+ for (count = a_len; count > 0; count--)
+ {
+ accu += (mp_twolimb_t) *sourceptr++ << s;
+ *destptr++ = (mp_limb_t) accu;
+ accu = accu >> GMP_LIMB_BITS;
+ }
+ *destptr++ = (mp_limb_t) accu;
+ }
+ q_ptr = roomptr + b_len;
+ q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */
+ {
+ size_t j = a_len - b_len; /* m-n */
+ mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */
+ mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */
+ mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */
+ ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd;
+ /* Division loop, traversed m-n+1 times.
+ j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */
+ for (;;)
+ {
+ mp_limb_t q_star;
+ mp_limb_t c1;
+ if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */
+ {
+ /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */
+ mp_twolimb_t num =
+ ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS)
+ | r_ptr[j + b_len - 1];
+ q_star = num / b_msd;
+ c1 = num % b_msd;
+ }
+ else
+ {
+ /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */
+ q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */
+ /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta
+ <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta
+ <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta)
+ {<= beta !}.
+ If yes, jump directly to the subtraction loop.
+ (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta
+ <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */
+ if (r_ptr[j + b_len] > b_msd
+ || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd)
+ /* r[j+n] >= b[n-1]+1 or
+ r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a
+ carry. */
+ goto subtract;
+ }
+ /* q_star = q*,
+ c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, <beta). */
+ {
+ mp_twolimb_t c2 = /* c1*beta+r[j+n-2] */
+ ((mp_twolimb_t) c1 << GMP_LIMB_BITS) | r_ptr[j + b_len - 2];
+ mp_twolimb_t c3 = /* b[n-2] * q* */
+ (mp_twolimb_t) b_2msd * (mp_twolimb_t) q_star;
+ /* While c2 < c3, increase c2 and decrease c3.
+ Consider c3-c2. While it is > 0, decrease it by
+ b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2
+ this can happen only twice. */
+ if (c3 > c2)
+ {
+ q_star = q_star - 1; /* q* := q* - 1 */
+ if (c3 - c2 > b_msdd)
+ q_star = q_star - 1; /* q* := q* - 1 */
+ }
+ }
+ if (q_star > 0)
+ subtract:
+ {
+ /* Subtract r := r - b * q* * beta^j. */
+ mp_limb_t cr;
+ {
+ const mp_limb_t *sourceptr = b_ptr;
+ mp_limb_t *destptr = r_ptr + j;
+ mp_twolimb_t carry = 0;
+ size_t count;
+ for (count = b_len; count > 0; count--)
+ {
+ /* Here 0 <= carry <= q*. */
+ carry =
+ carry
+ + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++
+ + (mp_limb_t) ~(*destptr);
+ /* Here 0 <= carry <= beta*q* + beta-1. */
+ *destptr++ = ~(mp_limb_t) carry;
+ carry = carry >> GMP_LIMB_BITS; /* <= q* */
+ }
+ cr = (mp_limb_t) carry;
+ }
+ /* Subtract cr from r_ptr[j + b_len], then forget about
+ r_ptr[j + b_len]. */
+ if (cr > r_ptr[j + b_len])
+ {
+ /* Subtraction gave a carry. */
+ q_star = q_star - 1; /* q* := q* - 1 */
+ /* Add b back. */
+ {
+ const mp_limb_t *sourceptr = b_ptr;
+ mp_limb_t *destptr = r_ptr + j;
+ mp_limb_t carry = 0;
+ size_t count;
+ for (count = b_len; count > 0; count--)
+ {
+ mp_limb_t source1 = *sourceptr++;
+ mp_limb_t source2 = *destptr;
+ *destptr++ = source1 + source2 + carry;
+ carry =
+ (carry
+ ? source1 >= (mp_limb_t) ~source2
+ : source1 > (mp_limb_t) ~source2);
+ }
+ }
+ /* Forget about the carry and about r[j+n]. */
+ }
+ }
+ /* q* is determined. Store it as q[j]. */
+ q_ptr[j] = q_star;
+ if (j == 0)
+ break;
+ j--;
+ }
+ }
+ r_len = b_len;
+ /* Normalise q. */
+ if (q_ptr[q_len - 1] == 0)
+ q_len--;
+# if 0 /* Not needed here, since we need r only to compare it with b/2, and
+ b is shifted left by s bits. */
+ /* Shift r right by s bits. */
+ if (s > 0)
+ {
+ mp_limb_t ptr = r_ptr + r_len;
+ mp_twolimb_t accu = 0;
+ size_t count;
+ for (count = r_len; count > 0; count--)
+ {
+ accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS;
+ accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s);
+ *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS);
+ }
+ }
+# endif
+ /* Normalise r. */
+ while (r_len > 0 && r_ptr[r_len - 1] == 0)
+ r_len--;
+ }
+ /* Compare r << 1 with b. */
+ if (r_len > b_len)
+ goto increment_q;
+ {
+ size_t i;
+ for (i = b_len;;)
+ {
+ mp_limb_t r_i =
+ (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0)
+ | (i < r_len ? r_ptr[i] << 1 : 0);
+ mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0);
+ if (r_i > b_i)
+ goto increment_q;
+ if (r_i < b_i)
+ goto keep_q;
+ if (i == 0)
+ break;
+ i--;
+ }
+ }
+ if (q_len > 0 && ((q_ptr[0] & 1) != 0))
+ /* q is odd. */
+ increment_q:
+ {
+ size_t i;
+ for (i = 0; i < q_len; i++)
+ if (++(q_ptr[i]) != 0)
+ goto keep_q;
+ q_ptr[q_len++] = 1;
+ }
+ keep_q:
+ if (tmp_roomptr != NULL)
+ free (tmp_roomptr);
+ q->limbs = q_ptr;
+ q->nlimbs = q_len;
+ return roomptr;
+}
+
+/* Convert a bignum a >= 0, multiplied with 10^extra_zeroes, to decimal
+ representation.
+ Destroys the contents of a.
+ Return the allocated memory - containing the decimal digits in low-to-high
+ order, terminated with a NUL character - in case of success, NULL in case
+ of memory allocation failure. */
+static char *
+convert_to_decimal (mpn_t a, size_t extra_zeroes)
+{
+ mp_limb_t *a_ptr = a.limbs;
+ size_t a_len = a.nlimbs;
+ /* 0.03345 is slightly larger than log(2)/(9*log(10)). */
+ size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1);
+ char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes));
+ if (c_ptr != NULL)
+ {
+ char *d_ptr = c_ptr;
+ for (; extra_zeroes > 0; extra_zeroes--)
+ *d_ptr++ = '0';
+ while (a_len > 0)
+ {
+ /* Divide a by 10^9, in-place. */
+ mp_limb_t remainder = 0;
+ mp_limb_t *ptr = a_ptr + a_len;
+ size_t count;
+ for (count = a_len; count > 0; count--)
+ {
+ mp_twolimb_t num =
+ ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr;
+ *ptr = num / 1000000000;
+ remainder = num % 1000000000;
+ }
+ /* Store the remainder as 9 decimal digits. */
+ for (count = 9; count > 0; count--)
+ {
+ *d_ptr++ = '0' + (remainder % 10);
+ remainder = remainder / 10;
+ }
+ /* Normalize a. */
+ if (a_ptr[a_len - 1] == 0)
+ a_len--;
+ }
+ /* Remove leading zeroes. */
+ while (d_ptr > c_ptr && d_ptr[-1] == '0')
+ d_ptr--;
+ /* But keep at least one zero. */
+ if (d_ptr == c_ptr)
+ *d_ptr++ = '0';
+ /* Terminate the string. */
+ *d_ptr = '\0';
+ }
+ return c_ptr;
+}
+
+# if NEED_PRINTF_LONG_DOUBLE
+
+/* Assuming x is finite and >= 0:
+ write x as x = 2^e * m, where m is a bignum.
+ Return the allocated memory in case of success, NULL in case of memory
+ allocation failure. */
+static void *
+decode_long_double (long double x, int *ep, mpn_t *mp)
+{
+ mpn_t m;
+ int exp;
+ long double y;
+ size_t i;
+
+ /* Allocate memory for result. */
+ m.nlimbs = (LDBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
+ m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
+ if (m.limbs == NULL)
+ return NULL;
+ /* Split into exponential part and mantissa. */
+ y = frexpl (x, &exp);
+ if (!(y >= 0.0L && y < 1.0L))
+ abort ();
+ /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * 2^LDBL_MANT_BIT), and the
+ latter is an integer. */
+ /* Convert the mantissa (y * 2^LDBL_MANT_BIT) to a sequence of limbs.
+ I'm not sure whether it's safe to cast a 'long double' value between
+ 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
+ 'long double' values between 0 and 2^16 (to 'unsigned int' or 'int',
+ doesn't matter). */
+# if (LDBL_MANT_BIT % GMP_LIMB_BITS) != 0
+# if (LDBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2
+ {
+ mp_limb_t hi, lo;
+ y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % (GMP_LIMB_BITS / 2));
+ hi = (int) y;
+ y -= hi;
+ if (!(y >= 0.0L && y < 1.0L))
+ abort ();
+ y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
+ lo = (int) y;
+ y -= lo;
+ if (!(y >= 0.0L && y < 1.0L))
+ abort ();
+ m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
+ }
+# else
+ {
+ mp_limb_t d;
+ y *= (mp_limb_t) 1 << (LDBL_MANT_BIT % GMP_LIMB_BITS);
+ d = (int) y;
+ y -= d;
+ if (!(y >= 0.0L && y < 1.0L))
+ abort ();
+ m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d;
+ }
+# endif
+# endif
+ for (i = LDBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
+ {
+ mp_limb_t hi, lo;
+ y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
+ hi = (int) y;
+ y -= hi;
+ if (!(y >= 0.0L && y < 1.0L))
+ abort ();
+ y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
+ lo = (int) y;
+ y -= lo;
+ if (!(y >= 0.0L && y < 1.0L))
+ abort ();
+ m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
+ }
+# if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess
+ precision. */
+ if (!(y == 0.0L))
+ abort ();
+# endif
+ /* Normalise. */
+ while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
+ m.nlimbs--;
+ *mp = m;
+ *ep = exp - LDBL_MANT_BIT;
+ return m.limbs;
+}
+
+# endif
+
+# if NEED_PRINTF_DOUBLE
+
+/* Assuming x is finite and >= 0:
+ write x as x = 2^e * m, where m is a bignum.
+ Return the allocated memory in case of success, NULL in case of memory
+ allocation failure. */
+static void *
+decode_double (double x, int *ep, mpn_t *mp)
+{
+ mpn_t m;
+ int exp;
+ double y;
+ size_t i;
+
+ /* Allocate memory for result. */
+ m.nlimbs = (DBL_MANT_BIT + GMP_LIMB_BITS - 1) / GMP_LIMB_BITS;
+ m.limbs = (mp_limb_t *) malloc (m.nlimbs * sizeof (mp_limb_t));
+ if (m.limbs == NULL)
+ return NULL;
+ /* Split into exponential part and mantissa. */
+ y = frexp (x, &exp);
+ if (!(y >= 0.0 && y < 1.0))
+ abort ();
+ /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * 2^DBL_MANT_BIT), and the
+ latter is an integer. */
+ /* Convert the mantissa (y * 2^DBL_MANT_BIT) to a sequence of limbs.
+ I'm not sure whether it's safe to cast a 'double' value between
+ 2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
+ 'double' values between 0 and 2^16 (to 'unsigned int' or 'int',
+ doesn't matter). */
+# if (DBL_MANT_BIT % GMP_LIMB_BITS) != 0
+# if (DBL_MANT_BIT % GMP_LIMB_BITS) > GMP_LIMB_BITS / 2
+ {
+ mp_limb_t hi, lo;
+ y *= (mp_limb_t) 1 << (DBL_MANT_BIT % (GMP_LIMB_BITS / 2));
+ hi = (int) y;
+ y -= hi;
+ if (!(y >= 0.0 && y < 1.0))
+ abort ();
+ y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
+ lo = (int) y;
+ y -= lo;
+ if (!(y >= 0.0 && y < 1.0))
+ abort ();
+ m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo;
+ }
+# else
+ {
+ mp_limb_t d;
+ y *= (mp_limb_t) 1 << (DBL_MANT_BIT % GMP_LIMB_BITS);
+ d = (int) y;
+ y -= d;
+ if (!(y >= 0.0 && y < 1.0))
+ abort ();
+ m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d;
+ }
+# endif
+# endif
+ for (i = DBL_MANT_BIT / GMP_LIMB_BITS; i > 0; )
+ {
+ mp_limb_t hi, lo;
+ y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
+ hi = (int) y;
+ y -= hi;
+ if (!(y >= 0.0 && y < 1.0))
+ abort ();
+ y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2);
+ lo = (int) y;
+ y -= lo;
+ if (!(y >= 0.0 && y < 1.0))
+ abort ();
+ m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo;
+ }
+ if (!(y == 0.0))
+ abort ();
+ /* Normalise. */
+ while (m.nlimbs > 0 && m.limbs[m.nlimbs - 1] == 0)
+ m.nlimbs--;
+ *mp = m;
+ *ep = exp - DBL_MANT_BIT;
+ return m.limbs;
+}
+
+# endif
+
+/* Assuming x = 2^e * m is finite and >= 0, and n is an integer:
+ Returns the decimal representation of round (x * 10^n).
+ Return the allocated memory - containing the decimal digits in low-to-high
+ order, terminated with a NUL character - in case of success, NULL in case
+ of memory allocation failure. */
+static char *
+scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n)
+{
+ int s;
+ size_t extra_zeroes;
+ unsigned int abs_n;
+ unsigned int abs_s;
+ mp_limb_t *pow5_ptr;
+ size_t pow5_len;
+ unsigned int s_limbs;
+ unsigned int s_bits;
+ mpn_t pow5;
+ mpn_t z;
+ void *z_memory;
+ char *digits;
+
+ if (memory == NULL)
+ return NULL;
+ /* x = 2^e * m, hence
+ y = round (2^e * 10^n * m) = round (2^(e+n) * 5^n * m)
+ = round (2^s * 5^n * m). */
+ s = e + n;
+ extra_zeroes = 0;
+ /* Factor out a common power of 10 if possible. */
+ if (s > 0 && n > 0)
+ {
+ extra_zeroes = (s < n ? s : n);
+ s -= extra_zeroes;
+ n -= extra_zeroes;
+ }
+ /* Here y = round (2^s * 5^n * m) * 10^extra_zeroes.
+ Before converting to decimal, we need to compute
+ z = round (2^s * 5^n * m). */
+ /* Compute 5^|n|, possibly shifted by |s| bits if n and s have the same
+ sign. 2.322 is slightly larger than log(5)/log(2). */
+ abs_n = (n >= 0 ? n : -n);
+ abs_s = (s >= 0 ? s : -s);
+ pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1
+ + abs_s / GMP_LIMB_BITS + 1)
+ * sizeof (mp_limb_t));
+ if (pow5_ptr == NULL)
+ {
+ free (memory);
+ return NULL;
+ }
+ /* Initialize with 1. */
+ pow5_ptr[0] = 1;
+ pow5_len = 1;
+ /* Multiply with 5^|n|. */
+ if (abs_n > 0)
+ {
+ static mp_limb_t const small_pow5[13 + 1] =
+ {
+ 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625,
+ 48828125, 244140625, 1220703125
+ };
+ unsigned int n13;
+ for (n13 = 0; n13 <= abs_n; n13 += 13)
+ {
+ mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13];
+ size_t j;
+ mp_twolimb_t carry = 0;
+ for (j = 0; j < pow5_len; j++)
+ {
+ mp_limb_t digit2 = pow5_ptr[j];
+ carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2;
+ pow5_ptr[j] = (mp_limb_t) carry;
+ carry = carry >> GMP_LIMB_BITS;
+ }
+ if (carry > 0)
+ pow5_ptr[pow5_len++] = (mp_limb_t) carry;
+ }
+ }
+ s_limbs = abs_s / GMP_LIMB_BITS;
+ s_bits = abs_s % GMP_LIMB_BITS;
+ if (n >= 0 ? s >= 0 : s <= 0)
+ {
+ /* Multiply with 2^|s|. */
+ if (s_bits > 0)
+ {
+ mp_limb_t *ptr = pow5_ptr;
+ mp_twolimb_t accu = 0;
+ size_t count;
+ for (count = pow5_len; count > 0; count--)
+ {
+ accu += (mp_twolimb_t) *ptr << s_bits;
+ *ptr++ = (mp_limb_t) accu;
+ accu = accu >> GMP_LIMB_BITS;
+ }
+ if (accu > 0)
+ {
+ *ptr = (mp_limb_t) accu;
+ pow5_len++;
+ }
+ }
+ if (s_limbs > 0)
+ {
+ size_t count;
+ for (count = pow5_len; count > 0;)
+ {
+ count--;
+ pow5_ptr[s_limbs + count] = pow5_ptr[count];
+ }
+ for (count = s_limbs; count > 0;)
+ {
+ count--;
+ pow5_ptr[count] = 0;
+ }
+ pow5_len += s_limbs;
+ }
+ pow5.limbs = pow5_ptr;
+ pow5.nlimbs = pow5_len;
+ if (n >= 0)
+ {
+ /* Multiply m with pow5. No division needed. */
+ z_memory = multiply (m, pow5, &z);
+ }
+ else
+ {
+ /* Divide m by pow5 and round. */
+ z_memory = divide (m, pow5, &z);
+ }
+ }
+ else
+ {
+ pow5.limbs = pow5_ptr;
+ pow5.nlimbs = pow5_len;
+ if (n >= 0)
+ {
+ /* n >= 0, s < 0.
+ Multiply m with pow5, then divide by 2^|s|. */
+ mpn_t numerator;
+ mpn_t denominator;
+ void *tmp_memory;
+ tmp_memory = multiply (m, pow5, &numerator);
+ if (tmp_memory == NULL)
+ {
+ free (pow5_ptr);
+ free (memory);
+ return NULL;
+ }
+ /* Construct 2^|s|. */
+ {
+ mp_limb_t *ptr = pow5_ptr + pow5_len;
+ size_t i;
+ for (i = 0; i < s_limbs; i++)
+ ptr[i] = 0;
+ ptr[s_limbs] = (mp_limb_t) 1 << s_bits;
+ denominator.limbs = ptr;
+ denominator.nlimbs = s_limbs + 1;
+ }
+ z_memory = divide (numerator, denominator, &z);
+ free (tmp_memory);
+ }
+ else
+ {
+ /* n < 0, s > 0.
+ Multiply m with 2^s, then divide by pow5. */
+ mpn_t numerator;
+ mp_limb_t *num_ptr;
+ num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1)
+ * sizeof (mp_limb_t));
+ if (num_ptr == NULL)
+ {
+ free (pow5_ptr);
+ free (memory);
+ return NULL;
+ }
+ {
+ mp_limb_t *destptr = num_ptr;
+ {
+ size_t i;
+ for (i = 0; i < s_limbs; i++)
+ *destptr++ = 0;
+ }
+ if (s_bits > 0)
+ {
+ const mp_limb_t *sourceptr = m.limbs;
+ mp_twolimb_t accu = 0;
+ size_t count;
+ for (count = m.nlimbs; count > 0; count--)
+ {
+ accu += (mp_twolimb_t) *sourceptr++ << s_bits;
+ *destptr++ = (mp_limb_t) accu;
+ accu = accu >> GMP_LIMB_BITS;
+ }
+ if (accu > 0)
+ *destptr++ = (mp_limb_t) accu;
+ }
+ else
+ {
+ const mp_limb_t *sourceptr = m.limbs;
+ size_t count;
+ for (count = m.nlimbs; count > 0; count--)
+ *destptr++ = *sourceptr++;
+ }
+ numerator.limbs = num_ptr;
+ numerator.nlimbs = destptr - num_ptr;
+ }
+ z_memory = divide (numerator, pow5, &z);
+ free (num_ptr);
+ }
+ }
+ free (pow5_ptr);
+ free (memory);
+
+ /* Here y = round (x * 10^n) = z * 10^extra_zeroes. */
+
+ if (z_memory == NULL)
+ return NULL;
+ digits = convert_to_decimal (z, extra_zeroes);
+ free (z_memory);
+ return digits;
+}
+
+# if NEED_PRINTF_LONG_DOUBLE
+
+/* Assuming x is finite and >= 0, and n is an integer:
+ Returns the decimal representation of round (x * 10^n).
+ Return the allocated memory - containing the decimal digits in low-to-high
+ order, terminated with a NUL character - in case of success, NULL in case
+ of memory allocation failure. */
+static char *
+scale10_round_decimal_long_double (long double x, int n)
+{
+ int e IF_LINT(= 0);
+ mpn_t m;
+ void *memory = decode_long_double (x, &e, &m);
+ return scale10_round_decimal_decoded (e, m, memory, n);
+}
+
+# endif
+
+# if NEED_PRINTF_DOUBLE
+
+/* Assuming x is finite and >= 0, and n is an integer:
+ Returns the decimal representation of round (x * 10^n).
+ Return the allocated memory - containing the decimal digits in low-to-high
+ order, terminated with a NUL character - in case of success, NULL in case
+ of memory allocation failure. */
+static char *
+scale10_round_decimal_double (double x, int n)
+{
+ int e IF_LINT(= 0);
+ mpn_t m;
+ void *memory = decode_double (x, &e, &m);
+ return scale10_round_decimal_decoded (e, m, memory, n);
+}
+
+# endif
+
+# if NEED_PRINTF_LONG_DOUBLE
+
+/* Assuming x is finite and > 0:
+ Return an approximation for n with 10^n <= x < 10^(n+1).
+ The approximation is usually the right n, but may be off by 1 sometimes. */
+static int
+floorlog10l (long double x)
+{
+ int exp;
+ long double y;
+ double z;
+ double l;
+
+ /* Split into exponential part and mantissa. */
+ y = frexpl (x, &exp);
+ if (!(y >= 0.0L && y < 1.0L))
+ abort ();
+ if (y == 0.0L)
+ return INT_MIN;
+ if (y < 0.5L)
+ {
+ while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
+ {
+ y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
+ exp -= GMP_LIMB_BITS;
+ }
+ if (y < (1.0L / (1 << 16)))
+ {
+ y *= 1.0L * (1 << 16);
+ exp -= 16;
+ }
+ if (y < (1.0L / (1 << 8)))
+ {
+ y *= 1.0L * (1 << 8);
+ exp -= 8;
+ }
+ if (y < (1.0L / (1 << 4)))
+ {
+ y *= 1.0L * (1 << 4);
+ exp -= 4;
+ }
+ if (y < (1.0L / (1 << 2)))
+ {
+ y *= 1.0L * (1 << 2);
+ exp -= 2;
+ }
+ if (y < (1.0L / (1 << 1)))
+ {
+ y *= 1.0L * (1 << 1);
+ exp -= 1;
+ }
+ }
+ if (!(y >= 0.5L && y < 1.0L))
+ abort ();
+ /* Compute an approximation for l = log2(x) = exp + log2(y). */
+ l = exp;
+ z = y;
+ if (z < 0.70710678118654752444)
+ {
+ z *= 1.4142135623730950488;
+ l -= 0.5;
+ }
+ if (z < 0.8408964152537145431)
+ {
+ z *= 1.1892071150027210667;
+ l -= 0.25;
+ }
+ if (z < 0.91700404320467123175)
+ {
+ z *= 1.0905077326652576592;
+ l -= 0.125;
+ }
+ if (z < 0.9576032806985736469)
+ {
+ z *= 1.0442737824274138403;
+ l -= 0.0625;
+ }
+ /* Now 0.95 <= z <= 1.01. */
+ z = 1 - z;
+ /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...)
+ Four terms are enough to get an approximation with error < 10^-7. */
+ l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
+ /* Finally multiply with log(2)/log(10), yields an approximation for
+ log10(x). */
+ l *= 0.30102999566398119523;
+ /* Round down to the next integer. */
+ return (int) l + (l < 0 ? -1 : 0);
+}
+
+# endif
+
+# if NEED_PRINTF_DOUBLE
+
+/* Assuming x is finite and > 0:
+ Return an approximation for n with 10^n <= x < 10^(n+1).
+ The approximation is usually the right n, but may be off by 1 sometimes. */
+static int
+floorlog10 (double x)
+{
+ int exp;
+ double y;
+ double z;
+ double l;
+
+ /* Split into exponential part and mantissa. */
+ y = frexp (x, &exp);
+ if (!(y >= 0.0 && y < 1.0))
+ abort ();
+ if (y == 0.0)
+ return INT_MIN;
+ if (y < 0.5)
+ {
+ while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2))))
+ {
+ y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2));
+ exp -= GMP_LIMB_BITS;
+ }
+ if (y < (1.0 / (1 << 16)))
+ {
+ y *= 1.0 * (1 << 16);
+ exp -= 16;
+ }
+ if (y < (1.0 / (1 << 8)))
+ {
+ y *= 1.0 * (1 << 8);
+ exp -= 8;
+ }
+ if (y < (1.0 / (1 << 4)))
+ {
+ y *= 1.0 * (1 << 4);
+ exp -= 4;
+ }
+ if (y < (1.0 / (1 << 2)))
+ {
+ y *= 1.0 * (1 << 2);
+ exp -= 2;
+ }
+ if (y < (1.0 / (1 << 1)))
+ {
+ y *= 1.0 * (1 << 1);
+ exp -= 1;
+ }
+ }
+ if (!(y >= 0.5 && y < 1.0))
+ abort ();
+ /* Compute an approximation for l = log2(x) = exp + log2(y). */
+ l = exp;
+ z = y;
+ if (z < 0.70710678118654752444)
+ {
+ z *= 1.4142135623730950488;
+ l -= 0.5;
+ }
+ if (z < 0.8408964152537145431)
+ {
+ z *= 1.1892071150027210667;
+ l -= 0.25;
+ }
+ if (z < 0.91700404320467123175)
+ {
+ z *= 1.0905077326652576592;
+ l -= 0.125;
+ }
+ if (z < 0.9576032806985736469)
+ {
+ z *= 1.0442737824274138403;
+ l -= 0.0625;
+ }
+ /* Now 0.95 <= z <= 1.01. */
+ z = 1 - z;
+ /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...)
+ Four terms are enough to get an approximation with error < 10^-7. */
+ l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
+ /* Finally multiply with log(2)/log(10), yields an approximation for
+ log10(x). */
+ l *= 0.30102999566398119523;
+ /* Round down to the next integer. */
+ return (int) l + (l < 0 ? -1 : 0);
+}
+
+# endif
+
+/* Tests whether a string of digits consists of exactly PRECISION zeroes and
+ a single '1' digit. */
+static int
+is_borderline (const char *digits, size_t precision)
+{
+ for (; precision > 0; precision--, digits++)
+ if (*digits != '0')
+ return 0;
+ if (*digits != '1')
+ return 0;
+ digits++;
+ return *digits == '\0';
+}
+
+#endif
+
+#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99
+
+/* Use a different function name, to make it possible that the 'wchar_t'
+ parametrization and the 'char' parametrization get compiled in the same
+ translation unit. */
+# if WIDE_CHAR_VERSION
+# define MAX_ROOM_NEEDED wmax_room_needed
+# else
+# define MAX_ROOM_NEEDED max_room_needed
+# endif
+
+/* Returns the number of TCHAR_T units needed as temporary space for the result
+ of sprintf or SNPRINTF of a single conversion directive. */
+static size_t
+MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
+ arg_type type, int flags, size_t width, int has_precision,
+ size_t precision, int pad_ourselves)
+{
+ size_t tmp_length;
+
+ switch (conversion)
+ {
+ case 'd': case 'i': case 'u':
+# if HAVE_LONG_LONG_INT
+ if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+ tmp_length =
+ (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
+ * 0.30103 /* binary -> decimal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+# endif
+ if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+ tmp_length =
+ (unsigned int) (sizeof (unsigned long) * CHAR_BIT
+ * 0.30103 /* binary -> decimal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+ tmp_length =
+ (unsigned int) (sizeof (unsigned int) * CHAR_BIT
+ * 0.30103 /* binary -> decimal */
+ )
+ + 1; /* turn floor into ceil */
+ if (tmp_length < precision)
+ tmp_length = precision;
+ /* Multiply by 2, as an estimate for FLAG_GROUP. */
+ tmp_length = xsum (tmp_length, tmp_length);
+ /* Add 1, to account for a leading sign. */
+ tmp_length = xsum (tmp_length, 1);
+ break;
+
+ case 'o':
+# if HAVE_LONG_LONG_INT
+ if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+ tmp_length =
+ (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
+ * 0.333334 /* binary -> octal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+# endif
+ if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+ tmp_length =
+ (unsigned int) (sizeof (unsigned long) * CHAR_BIT
+ * 0.333334 /* binary -> octal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+ tmp_length =
+ (unsigned int) (sizeof (unsigned int) * CHAR_BIT
+ * 0.333334 /* binary -> octal */
+ )
+ + 1; /* turn floor into ceil */
+ if (tmp_length < precision)
+ tmp_length = precision;
+ /* Add 1, to account for a leading sign. */
+ tmp_length = xsum (tmp_length, 1);
+ break;
+
+ case 'x': case 'X':
+# if HAVE_LONG_LONG_INT
+ if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+ tmp_length =
+ (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
+ * 0.25 /* binary -> hexadecimal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+# endif
+ if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+ tmp_length =
+ (unsigned int) (sizeof (unsigned long) * CHAR_BIT
+ * 0.25 /* binary -> hexadecimal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+ tmp_length =
+ (unsigned int) (sizeof (unsigned int) * CHAR_BIT
+ * 0.25 /* binary -> hexadecimal */
+ )
+ + 1; /* turn floor into ceil */
+ if (tmp_length < precision)
+ tmp_length = precision;
+ /* Add 2, to account for a leading sign or alternate form. */
+ tmp_length = xsum (tmp_length, 2);
+ break;
+
+ case 'f': case 'F':
+ if (type == TYPE_LONGDOUBLE)
+ tmp_length =
+ (unsigned int) (LDBL_MAX_EXP
+ * 0.30103 /* binary -> decimal */
+ * 2 /* estimate for FLAG_GROUP */
+ )
+ + 1 /* turn floor into ceil */
+ + 10; /* sign, decimal point etc. */
+ else
+ tmp_length =
+ (unsigned int) (DBL_MAX_EXP
+ * 0.30103 /* binary -> decimal */
+ * 2 /* estimate for FLAG_GROUP */
+ )
+ + 1 /* turn floor into ceil */
+ + 10; /* sign, decimal point etc. */
+ tmp_length = xsum (tmp_length, precision);
+ break;
+
+ case 'e': case 'E': case 'g': case 'G':
+ tmp_length =
+ 12; /* sign, decimal point, exponent etc. */
+ tmp_length = xsum (tmp_length, precision);
+ break;
+
+ case 'a': case 'A':
+ if (type == TYPE_LONGDOUBLE)
+ tmp_length =
+ (unsigned int) (LDBL_DIG
+ * 0.831 /* decimal -> hexadecimal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+ tmp_length =
+ (unsigned int) (DBL_DIG
+ * 0.831 /* decimal -> hexadecimal */
+ )
+ + 1; /* turn floor into ceil */
+ if (tmp_length < precision)
+ tmp_length = precision;
+ /* Account for sign, decimal point etc. */
+ tmp_length = xsum (tmp_length, 12);
+ break;
+
+ case 'c':
+# if HAVE_WINT_T && !WIDE_CHAR_VERSION
+ if (type == TYPE_WIDE_CHAR)
+ tmp_length = MB_CUR_MAX;
+ else
+# endif
+ tmp_length = 1;
+ break;
+
+ case 's':
+# if HAVE_WCHAR_T
+ if (type == TYPE_WIDE_STRING)
+ {
+# if WIDE_CHAR_VERSION
+ /* ISO C says about %ls in fwprintf:
+ "If the precision is not specified or is greater than the size
+ of the array, the array shall contain a null wide character."
+ So if there is a precision, we must not use wcslen. */
+ const wchar_t *arg = ap->arg[arg_index].a.a_wide_string;
+
+ if (has_precision)
+ tmp_length = local_wcsnlen (arg, precision);
+ else
+ tmp_length = local_wcslen (arg);
+# else
+ /* ISO C says about %ls in fprintf:
+ "If a precision is specified, no more than that many bytes are
+ written (including shift sequences, if any), and the array
+ shall contain a null wide character if, to equal the multibyte
+ character sequence length given by the precision, the function
+ would need to access a wide character one past the end of the
+ array."
+ So if there is a precision, we must not use wcslen. */
+ /* This case has already been handled separately in VASNPRINTF. */
+ abort ();
+# endif
+ }
+ else
+# endif
+ {
+# if WIDE_CHAR_VERSION
+ /* ISO C says about %s in fwprintf:
+ "If the precision is not specified or is greater than the size
+ of the converted array, the converted array shall contain a
+ null wide character."
+ So if there is a precision, we must not use strlen. */
+ /* This case has already been handled separately in VASNPRINTF. */
+ abort ();
+# else
+ /* ISO C says about %s in fprintf:
+ "If the precision is not specified or greater than the size of
+ the array, the array shall contain a null character."
+ So if there is a precision, we must not use strlen. */
+ const char *arg = ap->arg[arg_index].a.a_string;
+
+ if (has_precision)
+ tmp_length = local_strnlen (arg, precision);
+ else
+ tmp_length = strlen (arg);
+# endif
+ }
+ break;
+
+ case 'p':
+ tmp_length =
+ (unsigned int) (sizeof (void *) * CHAR_BIT
+ * 0.25 /* binary -> hexadecimal */
+ )
+ + 1 /* turn floor into ceil */
+ + 2; /* account for leading 0x */
+ break;
+
+ default:
+ abort ();
+ }
+
+ if (!pad_ourselves)
+ {
+# if ENABLE_UNISTDIO
+ /* Padding considers the number of characters, therefore the number of
+ elements after padding may be
+ > max (tmp_length, width)
+ but is certainly
+ <= tmp_length + width. */
+ tmp_length = xsum (tmp_length, width);
+# else
+ /* Padding considers the number of elements, says POSIX. */
+ if (tmp_length < width)
+ tmp_length = width;
+# endif
+ }
+
+ tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
+
+ return tmp_length;
+}
+
+#endif
+
+DCHAR_T *
+VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
+ const FCHAR_T *format, va_list args)
+{
+ DIRECTIVES d;
+ arguments a;
+
+ if (PRINTF_PARSE (format, &d, &a) < 0)
+ /* errno is already set. */
+ return NULL;
+
+#define CLEANUP() \
+ if (d.dir != d.direct_alloc_dir) \
+ free (d.dir); \
+ if (a.arg != a.direct_alloc_arg) \
+ free (a.arg);
+
+ if (PRINTF_FETCHARGS (args, &a) < 0)
+ {
+ CLEANUP ();
+ errno = EINVAL;
+ return NULL;
+ }
+
+ {
+ size_t buf_neededlength;
+ TCHAR_T *buf;
+ TCHAR_T *buf_malloced;
+ const FCHAR_T *cp;
+ size_t i;
+ DIRECTIVE *dp;
+ /* Output string accumulator. */
+ DCHAR_T *result;
+ size_t allocated;
+ size_t length;
+
+ /* Allocate a small buffer that will hold a directive passed to
+ sprintf or snprintf. */
+ buf_neededlength =
+ xsum4 (7, d.max_width_length, d.max_precision_length, 6);
+#if HAVE_ALLOCA
+ if (buf_neededlength < 4000 / sizeof (TCHAR_T))
+ {
+ buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T));
+ buf_malloced = NULL;
+ }
+ else
+#endif
+ {
+ size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T));
+ if (size_overflow_p (buf_memsize))
+ goto out_of_memory_1;
+ buf = (TCHAR_T *) malloc (buf_memsize);
+ if (buf == NULL)
+ goto out_of_memory_1;
+ buf_malloced = buf;
+ }
+
+ if (resultbuf != NULL)
+ {
+ result = resultbuf;
+ allocated = *lengthp;
+ }
+ else
+ {
+ result = NULL;
+ allocated = 0;
+ }
+ length = 0;
+ /* Invariants:
+ result is either == resultbuf or == NULL or malloc-allocated.
+ If length > 0, then result != NULL. */
+
+ /* Ensures that allocated >= needed. Aborts through a jump to
+ out_of_memory if needed is SIZE_MAX or otherwise too big. */
+#define ENSURE_ALLOCATION(needed) \
+ if ((needed) > allocated) \
+ { \
+ size_t memory_size; \
+ DCHAR_T *memory; \
+ \
+ allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \
+ if ((needed) > allocated) \
+ allocated = (needed); \
+ memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
+ if (size_overflow_p (memory_size)) \
+ goto out_of_memory; \
+ if (result == resultbuf || result == NULL) \
+ memory = (DCHAR_T *) malloc (memory_size); \
+ else \
+ memory = (DCHAR_T *) realloc (result, memory_size); \
+ if (memory == NULL) \
+ goto out_of_memory; \
+ if (result == resultbuf && length > 0) \
+ DCHAR_CPY (memory, result, length); \
+ result = memory; \
+ }
+
+ for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
+ {
+ if (cp != dp->dir_start)
+ {
+ size_t n = dp->dir_start - cp;
+ size_t augmented_length = xsum (length, n);
+
+ ENSURE_ALLOCATION (augmented_length);
+ /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we
+ need that the format string contains only ASCII characters
+ if FCHAR_T and DCHAR_T are not the same type. */
+ if (sizeof (FCHAR_T) == sizeof (DCHAR_T))
+ {
+ DCHAR_CPY (result + length, (const DCHAR_T *) cp, n);
+ length = augmented_length;
+ }
+ else
+ {
+ do
+ result[length++] = (unsigned char) *cp++;
+ while (--n > 0);
+ }
+ }
+ if (i == d.count)
+ break;
+
+ /* Execute a single directive. */
+ if (dp->conversion == '%')
+ {
+ size_t augmented_length;
+
+ if (!(dp->arg_index == ARG_NONE))
+ abort ();
+ augmented_length = xsum (length, 1);
+ ENSURE_ALLOCATION (augmented_length);
+ result[length] = '%';
+ length = augmented_length;
+ }
+ else
+ {
+ if (!(dp->arg_index != ARG_NONE))
+ abort ();
+
+ if (dp->conversion == 'n')
+ {
+ switch (a.arg[dp->arg_index].type)
+ {
+ case TYPE_COUNT_SCHAR_POINTER:
+ *a.arg[dp->arg_index].a.a_count_schar_pointer = length;
+ break;
+ case TYPE_COUNT_SHORT_POINTER:
+ *a.arg[dp->arg_index].a.a_count_short_pointer = length;
+ break;
+ case TYPE_COUNT_INT_POINTER:
+ *a.arg[dp->arg_index].a.a_count_int_pointer = length;
+ break;
+ case TYPE_COUNT_LONGINT_POINTER:
+ *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
+ break;
+#if HAVE_LONG_LONG_INT
+ case TYPE_COUNT_LONGLONGINT_POINTER:
+ *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
+ break;
+#endif
+ default:
+ abort ();
+ }
+ }
+#if ENABLE_UNISTDIO
+ /* The unistdio extensions. */
+ else if (dp->conversion == 'U')
+ {
+ arg_type type = a.arg[dp->arg_index].type;
+ int flags = dp->flags;
+ int has_width;
+ size_t width;
+ int has_precision;
+ size_t precision;
+
+ has_width = 0;
+ width = 0;
+ if (dp->width_start != dp->width_end)
+ {
+ if (dp->width_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->width_arg_index].a.a_int;
+ if (arg < 0)
+ {
+ /* "A negative field width is taken as a '-' flag
+ followed by a positive field width." */
+ flags |= FLAG_LEFT;
+ width = (unsigned int) (-arg);
+ }
+ else
+ width = arg;
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->width_start;
+
+ do
+ width = xsum (xtimes (width, 10), *digitp++ - '0');
+ while (digitp != dp->width_end);
+ }
+ has_width = 1;
+ }
+
+ has_precision = 0;
+ precision = 0;
+ if (dp->precision_start != dp->precision_end)
+ {
+ if (dp->precision_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->precision_arg_index].a.a_int;
+ /* "A negative precision is taken as if the precision
+ were omitted." */
+ if (arg >= 0)
+ {
+ precision = arg;
+ has_precision = 1;
+ }
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->precision_start + 1;
+
+ precision = 0;
+ while (digitp != dp->precision_end)
+ precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+ has_precision = 1;
+ }
+ }
+
+ switch (type)
+ {
+ case TYPE_U8_STRING:
+ {
+ const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string;
+ const uint8_t *arg_end;
+ size_t characters;
+
+ if (has_precision)
+ {
+ /* Use only PRECISION characters, from the left. */
+ arg_end = arg;
+ characters = 0;
+ for (; precision > 0; precision--)
+ {
+ int count = u8_strmblen (arg_end);
+ if (count == 0)
+ break;
+ if (count < 0)
+ {
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else if (has_width)
+ {
+ /* Use the entire string, and count the number of
+ characters. */
+ arg_end = arg;
+ characters = 0;
+ for (;;)
+ {
+ int count = u8_strmblen (arg_end);
+ if (count == 0)
+ break;
+ if (count < 0)
+ {
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else
+ {
+ /* Use the entire string. */
+ arg_end = arg + u8_strlen (arg);
+ /* The number of characters doesn't matter. */
+ characters = 0;
+ }
+
+ if (has_width && width > characters
+ && !(dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+
+# if DCHAR_IS_UINT8_T
+ {
+ size_t n = arg_end - arg;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_CPY (result + length, arg, n);
+ length += n;
+ }
+# else
+ { /* Convert. */
+ DCHAR_T *converted = result + length;
+ size_t converted_len = allocated - length;
+# if DCHAR_IS_TCHAR
+ /* Convert from UTF-8 to locale encoding. */
+ converted =
+ u8_conv_to_encoding (locale_charset (),
+ iconveh_question_mark,
+ arg, arg_end - arg, NULL,
+ converted, &converted_len);
+# else
+ /* Convert from UTF-8 to UTF-16/UTF-32. */
+ converted =
+ U8_TO_DCHAR (arg, arg_end - arg,
+ converted, &converted_len);
+# endif
+ if (converted == NULL)
+ {
+ int saved_errno = errno;
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = saved_errno;
+ return NULL;
+ }
+ if (converted != result + length)
+ {
+ ENSURE_ALLOCATION (xsum (length, converted_len));
+ DCHAR_CPY (result + length, converted, converted_len);
+ free (converted);
+ }
+ length += converted_len;
+ }
+# endif
+
+ if (has_width && width > characters
+ && (dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+ }
+ break;
+
+ case TYPE_U16_STRING:
+ {
+ const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string;
+ const uint16_t *arg_end;
+ size_t characters;
+
+ if (has_precision)
+ {
+ /* Use only PRECISION characters, from the left. */
+ arg_end = arg;
+ characters = 0;
+ for (; precision > 0; precision--)
+ {
+ int count = u16_strmblen (arg_end);
+ if (count == 0)
+ break;
+ if (count < 0)
+ {
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else if (has_width)
+ {
+ /* Use the entire string, and count the number of
+ characters. */
+ arg_end = arg;
+ characters = 0;
+ for (;;)
+ {
+ int count = u16_strmblen (arg_end);
+ if (count == 0)
+ break;
+ if (count < 0)
+ {
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else
+ {
+ /* Use the entire string. */
+ arg_end = arg + u16_strlen (arg);
+ /* The number of characters doesn't matter. */
+ characters = 0;
+ }
+
+ if (has_width && width > characters
+ && !(dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+
+# if DCHAR_IS_UINT16_T
+ {
+ size_t n = arg_end - arg;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_CPY (result + length, arg, n);
+ length += n;
+ }
+# else
+ { /* Convert. */
+ DCHAR_T *converted = result + length;
+ size_t converted_len = allocated - length;
+# if DCHAR_IS_TCHAR
+ /* Convert from UTF-16 to locale encoding. */
+ converted =
+ u16_conv_to_encoding (locale_charset (),
+ iconveh_question_mark,
+ arg, arg_end - arg, NULL,
+ converted, &converted_len);
+# else
+ /* Convert from UTF-16 to UTF-8/UTF-32. */
+ converted =
+ U16_TO_DCHAR (arg, arg_end - arg,
+ converted, &converted_len);
+# endif
+ if (converted == NULL)
+ {
+ int saved_errno = errno;
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = saved_errno;
+ return NULL;
+ }
+ if (converted != result + length)
+ {
+ ENSURE_ALLOCATION (xsum (length, converted_len));
+ DCHAR_CPY (result + length, converted, converted_len);
+ free (converted);
+ }
+ length += converted_len;
+ }
+# endif
+
+ if (has_width && width > characters
+ && (dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+ }
+ break;
+
+ case TYPE_U32_STRING:
+ {
+ const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string;
+ const uint32_t *arg_end;
+ size_t characters;
+
+ if (has_precision)
+ {
+ /* Use only PRECISION characters, from the left. */
+ arg_end = arg;
+ characters = 0;
+ for (; precision > 0; precision--)
+ {
+ int count = u32_strmblen (arg_end);
+ if (count == 0)
+ break;
+ if (count < 0)
+ {
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else if (has_width)
+ {
+ /* Use the entire string, and count the number of
+ characters. */
+ arg_end = arg;
+ characters = 0;
+ for (;;)
+ {
+ int count = u32_strmblen (arg_end);
+ if (count == 0)
+ break;
+ if (count < 0)
+ {
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else
+ {
+ /* Use the entire string. */
+ arg_end = arg + u32_strlen (arg);
+ /* The number of characters doesn't matter. */
+ characters = 0;
+ }
+
+ if (has_width && width > characters
+ && !(dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+
+# if DCHAR_IS_UINT32_T
+ {
+ size_t n = arg_end - arg;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_CPY (result + length, arg, n);
+ length += n;
+ }
+# else
+ { /* Convert. */
+ DCHAR_T *converted = result + length;
+ size_t converted_len = allocated - length;
+# if DCHAR_IS_TCHAR
+ /* Convert from UTF-32 to locale encoding. */
+ converted =
+ u32_conv_to_encoding (locale_charset (),
+ iconveh_question_mark,
+ arg, arg_end - arg, NULL,
+ converted, &converted_len);
+# else
+ /* Convert from UTF-32 to UTF-8/UTF-16. */
+ converted =
+ U32_TO_DCHAR (arg, arg_end - arg,
+ converted, &converted_len);
+# endif
+ if (converted == NULL)
+ {
+ int saved_errno = errno;
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = saved_errno;
+ return NULL;
+ }
+ if (converted != result + length)
+ {
+ ENSURE_ALLOCATION (xsum (length, converted_len));
+ DCHAR_CPY (result + length, converted, converted_len);
+ free (converted);
+ }
+ length += converted_len;
+ }
+# endif
+
+ if (has_width && width > characters
+ && (dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+ }
+ break;
+
+ default:
+ abort ();
+ }
+ }
+#endif
+#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T
+ else if (dp->conversion == 's'
+# if WIDE_CHAR_VERSION
+ && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
+# else
+ && a.arg[dp->arg_index].type == TYPE_WIDE_STRING
+# endif
+ )
+ {
+ /* The normal handling of the 's' directive below requires
+ allocating a temporary buffer. The determination of its
+ length (tmp_length), in the case when a precision is
+ specified, below requires a conversion between a char[]
+ string and a wchar_t[] wide string. It could be done, but
+ we have no guarantee that the implementation of sprintf will
+ use the exactly same algorithm. Without this guarantee, it
+ is possible to have buffer overrun bugs. In order to avoid
+ such bugs, we implement the entire processing of the 's'
+ directive ourselves. */
+ int flags = dp->flags;
+ int has_width;
+ size_t width;
+ int has_precision;
+ size_t precision;
+
+ has_width = 0;
+ width = 0;
+ if (dp->width_start != dp->width_end)
+ {
+ if (dp->width_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->width_arg_index].a.a_int;
+ if (arg < 0)
+ {
+ /* "A negative field width is taken as a '-' flag
+ followed by a positive field width." */
+ flags |= FLAG_LEFT;
+ width = (unsigned int) (-arg);
+ }
+ else
+ width = arg;
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->width_start;
+
+ do
+ width = xsum (xtimes (width, 10), *digitp++ - '0');
+ while (digitp != dp->width_end);
+ }
+ has_width = 1;
+ }
+
+ has_precision = 0;
+ precision = 6;
+ if (dp->precision_start != dp->precision_end)
+ {
+ if (dp->precision_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->precision_arg_index].a.a_int;
+ /* "A negative precision is taken as if the precision
+ were omitted." */
+ if (arg >= 0)
+ {
+ precision = arg;
+ has_precision = 1;
+ }
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->precision_start + 1;
+
+ precision = 0;
+ while (digitp != dp->precision_end)
+ precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+ has_precision = 1;
+ }
+ }
+
+# if WIDE_CHAR_VERSION
+ /* %s in vasnwprintf. See the specification of fwprintf. */
+ {
+ const char *arg = a.arg[dp->arg_index].a.a_string;
+ const char *arg_end;
+ size_t characters;
+
+ if (has_precision)
+ {
+ /* Use only as many bytes as needed to produce PRECISION
+ wide characters, from the left. */
+# if HAVE_MBRTOWC
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ arg_end = arg;
+ characters = 0;
+ for (; precision > 0; precision--)
+ {
+ int count;
+# if HAVE_MBRTOWC
+ count = mbrlen (arg_end, MB_CUR_MAX, &state);
+# else
+ count = mblen (arg_end, MB_CUR_MAX);
+# endif
+ if (count == 0)
+ /* Found the terminating NUL. */
+ break;
+ if (count < 0)
+ {
+ /* Invalid or incomplete multibyte character. */
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else if (has_width)
+ {
+ /* Use the entire string, and count the number of wide
+ characters. */
+# if HAVE_MBRTOWC
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ arg_end = arg;
+ characters = 0;
+ for (;;)
+ {
+ int count;
+# if HAVE_MBRTOWC
+ count = mbrlen (arg_end, MB_CUR_MAX, &state);
+# else
+ count = mblen (arg_end, MB_CUR_MAX);
+# endif
+ if (count == 0)
+ /* Found the terminating NUL. */
+ break;
+ if (count < 0)
+ {
+ /* Invalid or incomplete multibyte character. */
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end += count;
+ characters++;
+ }
+ }
+ else
+ {
+ /* Use the entire string. */
+ arg_end = arg + strlen (arg);
+ /* The number of characters doesn't matter. */
+ characters = 0;
+ }
+
+ if (has_width && width > characters
+ && !(dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+
+ if (has_precision || has_width)
+ {
+ /* We know the number of wide characters in advance. */
+ size_t remaining;
+# if HAVE_MBRTOWC
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ ENSURE_ALLOCATION (xsum (length, characters));
+ for (remaining = characters; remaining > 0; remaining--)
+ {
+ wchar_t wc;
+ int count;
+# if HAVE_MBRTOWC
+ count = mbrtowc (&wc, arg, arg_end - arg, &state);
+# else
+ count = mbtowc (&wc, arg, arg_end - arg);
+# endif
+ if (count <= 0)
+ /* mbrtowc not consistent with mbrlen, or mbtowc
+ not consistent with mblen. */
+ abort ();
+ result[length++] = wc;
+ arg += count;
+ }
+ if (!(arg == arg_end))
+ abort ();
+ }
+ else
+ {
+# if HAVE_MBRTOWC
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ while (arg < arg_end)
+ {
+ wchar_t wc;
+ int count;
+# if HAVE_MBRTOWC
+ count = mbrtowc (&wc, arg, arg_end - arg, &state);
+# else
+ count = mbtowc (&wc, arg, arg_end - arg);
+# endif
+ if (count <= 0)
+ /* mbrtowc not consistent with mbrlen, or mbtowc
+ not consistent with mblen. */
+ abort ();
+ ENSURE_ALLOCATION (xsum (length, 1));
+ result[length++] = wc;
+ arg += count;
+ }
+ }
+
+ if (has_width && width > characters
+ && (dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - characters;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+ }
+# else
+ /* %ls in vasnprintf. See the specification of fprintf. */
+ {
+ const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
+ const wchar_t *arg_end;
+ size_t characters;
+# if !DCHAR_IS_TCHAR
+ /* This code assumes that TCHAR_T is 'char'. */
+ verify (sizeof (TCHAR_T) == 1);
+ TCHAR_T *tmpsrc;
+ DCHAR_T *tmpdst;
+ size_t tmpdst_len;
+# endif
+ size_t w;
+
+ if (has_precision)
+ {
+ /* Use only as many wide characters as needed to produce
+ at most PRECISION bytes, from the left. */
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ arg_end = arg;
+ characters = 0;
+ while (precision > 0)
+ {
+ char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
+ int count;
+
+ if (*arg_end == 0)
+ /* Found the terminating null wide character. */
+ break;
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ count = wcrtomb (cbuf, *arg_end, &state);
+# else
+ count = wctomb (cbuf, *arg_end);
+# endif
+ if (count < 0)
+ {
+ /* Cannot convert. */
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ if (precision < count)
+ break;
+ arg_end++;
+ characters += count;
+ precision -= count;
+ }
+ }
+# if DCHAR_IS_TCHAR
+ else if (has_width)
+# else
+ else
+# endif
+ {
+ /* Use the entire string, and count the number of
+ bytes. */
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ arg_end = arg;
+ characters = 0;
+ for (;;)
+ {
+ char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
+ int count;
+
+ if (*arg_end == 0)
+ /* Found the terminating null wide character. */
+ break;
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ count = wcrtomb (cbuf, *arg_end, &state);
+# else
+ count = wctomb (cbuf, *arg_end);
+# endif
+ if (count < 0)
+ {
+ /* Cannot convert. */
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ arg_end++;
+ characters += count;
+ }
+ }
+# if DCHAR_IS_TCHAR
+ else
+ {
+ /* Use the entire string. */
+ arg_end = arg + local_wcslen (arg);
+ /* The number of bytes doesn't matter. */
+ characters = 0;
+ }
+# endif
+
+# if !DCHAR_IS_TCHAR
+ /* Convert the string into a piece of temporary memory. */
+ tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T));
+ if (tmpsrc == NULL)
+ goto out_of_memory;
+ {
+ TCHAR_T *tmpptr = tmpsrc;
+ size_t remaining;
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ for (remaining = characters; remaining > 0; )
+ {
+ char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
+ int count;
+
+ if (*arg == 0)
+ abort ();
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ count = wcrtomb (cbuf, *arg, &state);
+# else
+ count = wctomb (cbuf, *arg);
+# endif
+ if (count <= 0)
+ /* Inconsistency. */
+ abort ();
+ memcpy (tmpptr, cbuf, count);
+ tmpptr += count;
+ arg++;
+ remaining -= count;
+ }
+ if (!(arg == arg_end))
+ abort ();
+ }
+
+ /* Convert from TCHAR_T[] to DCHAR_T[]. */
+ tmpdst =
+ DCHAR_CONV_FROM_ENCODING (locale_charset (),
+ iconveh_question_mark,
+ tmpsrc, characters,
+ NULL,
+ NULL, &tmpdst_len);
+ if (tmpdst == NULL)
+ {
+ int saved_errno = errno;
+ free (tmpsrc);
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = saved_errno;
+ return NULL;
+ }
+ free (tmpsrc);
+# endif
+
+ if (has_width)
+ {
+# if ENABLE_UNISTDIO
+ /* Outside POSIX, it's preferable to compare the width
+ against the number of _characters_ of the converted
+ value. */
+ w = DCHAR_MBSNLEN (result + length, characters);
+# else
+ /* The width is compared against the number of _bytes_
+ of the converted value, says POSIX. */
+ w = characters;
+# endif
+ }
+ else
+ /* w doesn't matter. */
+ w = 0;
+
+ if (has_width && width > w
+ && !(dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - w;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+
+# if DCHAR_IS_TCHAR
+ if (has_precision || has_width)
+ {
+ /* We know the number of bytes in advance. */
+ size_t remaining;
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ ENSURE_ALLOCATION (xsum (length, characters));
+ for (remaining = characters; remaining > 0; )
+ {
+ char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
+ int count;
+
+ if (*arg == 0)
+ abort ();
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ count = wcrtomb (cbuf, *arg, &state);
+# else
+ count = wctomb (cbuf, *arg);
+# endif
+ if (count <= 0)
+ /* Inconsistency. */
+ abort ();
+ memcpy (result + length, cbuf, count);
+ length += count;
+ arg++;
+ remaining -= count;
+ }
+ if (!(arg == arg_end))
+ abort ();
+ }
+ else
+ {
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ mbstate_t state;
+ memset (&state, '\0', sizeof (mbstate_t));
+# endif
+ while (arg < arg_end)
+ {
+ char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
+ int count;
+
+ if (*arg == 0)
+ abort ();
+# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
+ count = wcrtomb (cbuf, *arg, &state);
+# else
+ count = wctomb (cbuf, *arg);
+# endif
+ if (count <= 0)
+ {
+ /* Cannot convert. */
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = EILSEQ;
+ return NULL;
+ }
+ ENSURE_ALLOCATION (xsum (length, count));
+ memcpy (result + length, cbuf, count);
+ length += count;
+ arg++;
+ }
+ }
+# else
+ ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ DCHAR_CPY (result + length, tmpdst, tmpdst_len);
+ free (tmpdst);
+ length += tmpdst_len;
+# endif
+
+ if (has_width && width > w
+ && (dp->flags & FLAG_LEFT))
+ {
+ size_t n = width - w;
+ ENSURE_ALLOCATION (xsum (length, n));
+ DCHAR_SET (result + length, ' ', n);
+ length += n;
+ }
+ }
+# endif
+ }
+#endif
+#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
+ else if ((dp->conversion == 'a' || dp->conversion == 'A')
+# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
+ && (0
+# if NEED_PRINTF_DOUBLE
+ || a.arg[dp->arg_index].type == TYPE_DOUBLE
+# endif
+# if NEED_PRINTF_LONG_DOUBLE
+ || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
+# endif
+ )
+# endif
+ )
+ {
+ arg_type type = a.arg[dp->arg_index].type;
+ int flags = dp->flags;
+ int has_width;
+ size_t width;
+ int has_precision;
+ size_t precision;
+ size_t tmp_length;
+ DCHAR_T tmpbuf[700];
+ DCHAR_T *tmp;
+ DCHAR_T *pad_ptr;
+ DCHAR_T *p;
+
+ has_width = 0;
+ width = 0;
+ if (dp->width_start != dp->width_end)
+ {
+ if (dp->width_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->width_arg_index].a.a_int;
+ if (arg < 0)
+ {
+ /* "A negative field width is taken as a '-' flag
+ followed by a positive field width." */
+ flags |= FLAG_LEFT;
+ width = (unsigned int) (-arg);
+ }
+ else
+ width = arg;
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->width_start;
+
+ do
+ width = xsum (xtimes (width, 10), *digitp++ - '0');
+ while (digitp != dp->width_end);
+ }
+ has_width = 1;
+ }
+
+ has_precision = 0;
+ precision = 0;
+ if (dp->precision_start != dp->precision_end)
+ {
+ if (dp->precision_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->precision_arg_index].a.a_int;
+ /* "A negative precision is taken as if the precision
+ were omitted." */
+ if (arg >= 0)
+ {
+ precision = arg;
+ has_precision = 1;
+ }
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->precision_start + 1;
+
+ precision = 0;
+ while (digitp != dp->precision_end)
+ precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+ has_precision = 1;
+ }
+ }
+
+ /* Allocate a temporary buffer of sufficient size. */
+ if (type == TYPE_LONGDOUBLE)
+ tmp_length =
+ (unsigned int) ((LDBL_DIG + 1)
+ * 0.831 /* decimal -> hexadecimal */
+ )
+ + 1; /* turn floor into ceil */
+ else
+ tmp_length =
+ (unsigned int) ((DBL_DIG + 1)
+ * 0.831 /* decimal -> hexadecimal */
+ )
+ + 1; /* turn floor into ceil */
+ if (tmp_length < precision)
+ tmp_length = precision;
+ /* Account for sign, decimal point etc. */
+ tmp_length = xsum (tmp_length, 12);
+
+ if (tmp_length < width)
+ tmp_length = width;
+
+ tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
+
+ if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
+ tmp = tmpbuf;
+ else
+ {
+ size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
+
+ if (size_overflow_p (tmp_memsize))
+ /* Overflow, would lead to out of memory. */
+ goto out_of_memory;
+ tmp = (DCHAR_T *) malloc (tmp_memsize);
+ if (tmp == NULL)
+ /* Out of memory. */
+ goto out_of_memory;
+ }
+
+ pad_ptr = NULL;
+ p = tmp;
+ if (type == TYPE_LONGDOUBLE)
+ {
+# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE
+ long double arg = a.arg[dp->arg_index].a.a_longdouble;
+
+ if (isnanl (arg))
+ {
+ if (dp->conversion == 'A')
+ {
+ *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
+ }
+ else
+ {
+ *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
+ }
+ }
+ else
+ {
+ int sign = 0;
+ DECL_LONG_DOUBLE_ROUNDING
+
+ BEGIN_LONG_DOUBLE_ROUNDING ();
+
+ if (signbit (arg)) /* arg < 0.0L or negative zero */
+ {
+ sign = -1;
+ arg = -arg;
+ }
+
+ if (sign < 0)
+ *p++ = '-';
+ else if (flags & FLAG_SHOWSIGN)
+ *p++ = '+';
+ else if (flags & FLAG_SPACE)
+ *p++ = ' ';
+
+ if (arg > 0.0L && arg + arg == arg)
+ {
+ if (dp->conversion == 'A')
+ {
+ *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
+ }
+ else
+ {
+ *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
+ }
+ }
+ else
+ {
+ int exponent;
+ long double mantissa;
+
+ if (arg > 0.0L)
+ mantissa = printf_frexpl (arg, &exponent);
+ else
+ {
+ exponent = 0;
+ mantissa = 0.0L;
+ }
+
+ if (has_precision
+ && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1)
+ {
+ /* Round the mantissa. */
+ long double tail = mantissa;
+ size_t q;
+
+ for (q = precision; ; q--)
+ {
+ int digit = (int) tail;
+ tail -= digit;
+ if (q == 0)
+ {
+ if (digit & 1 ? tail >= 0.5L : tail > 0.5L)
+ tail = 1 - tail;
+ else
+ tail = - tail;
+ break;
+ }
+ tail *= 16.0L;
+ }
+ if (tail != 0.0L)
+ for (q = precision; q > 0; q--)
+ tail *= 0.0625L;
+ mantissa += tail;
+ }
+
+ *p++ = '0';
+ *p++ = dp->conversion - 'A' + 'X';
+ pad_ptr = p;
+ {
+ int digit;
+
+ digit = (int) mantissa;
+ mantissa -= digit;
+ *p++ = '0' + digit;
+ if ((flags & FLAG_ALT)
+ || mantissa > 0.0L || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ /* This loop terminates because we assume
+ that FLT_RADIX is a power of 2. */
+ while (mantissa > 0.0L)
+ {
+ mantissa *= 16.0L;
+ digit = (int) mantissa;
+ mantissa -= digit;
+ *p++ = digit
+ + (digit < 10
+ ? '0'
+ : dp->conversion - 10);
+ if (precision > 0)
+ precision--;
+ }
+ while (precision > 0)
+ {
+ *p++ = '0';
+ precision--;
+ }
+ }
+ }
+ *p++ = dp->conversion - 'A' + 'P';
+# if WIDE_CHAR_VERSION
+ {
+ static const wchar_t decimal_format[] =
+ { '%', '+', 'd', '\0' };
+ SNPRINTF (p, 6 + 1, decimal_format, exponent);
+ }
+ while (*p != '\0')
+ p++;
+# else
+ if (sizeof (DCHAR_T) == 1)
+ {
+ sprintf ((char *) p, "%+d", exponent);
+ while (*p != '\0')
+ p++;
+ }
+ else
+ {
+ char expbuf[6 + 1];
+ const char *ep;
+ sprintf (expbuf, "%+d", exponent);
+ for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+ p++;
+ }
+# endif
+ }
+
+ END_LONG_DOUBLE_ROUNDING ();
+ }
+# else
+ abort ();
+# endif
+ }
+ else
+ {
+# if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE
+ double arg = a.arg[dp->arg_index].a.a_double;
+
+ if (isnand (arg))
+ {
+ if (dp->conversion == 'A')
+ {
+ *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
+ }
+ else
+ {
+ *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
+ }
+ }
+ else
+ {
+ int sign = 0;
+
+ if (signbit (arg)) /* arg < 0.0 or negative zero */
+ {
+ sign = -1;
+ arg = -arg;
+ }
+
+ if (sign < 0)
+ *p++ = '-';
+ else if (flags & FLAG_SHOWSIGN)
+ *p++ = '+';
+ else if (flags & FLAG_SPACE)
+ *p++ = ' ';
+
+ if (arg > 0.0 && arg + arg == arg)
+ {
+ if (dp->conversion == 'A')
+ {
+ *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
+ }
+ else
+ {
+ *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
+ }
+ }
+ else
+ {
+ int exponent;
+ double mantissa;
+
+ if (arg > 0.0)
+ mantissa = printf_frexp (arg, &exponent);
+ else
+ {
+ exponent = 0;
+ mantissa = 0.0;
+ }
+
+ if (has_precision
+ && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1)
+ {
+ /* Round the mantissa. */
+ double tail = mantissa;
+ size_t q;
+
+ for (q = precision; ; q--)
+ {
+ int digit = (int) tail;
+ tail -= digit;
+ if (q == 0)
+ {
+ if (digit & 1 ? tail >= 0.5 : tail > 0.5)
+ tail = 1 - tail;
+ else
+ tail = - tail;
+ break;
+ }
+ tail *= 16.0;
+ }
+ if (tail != 0.0)
+ for (q = precision; q > 0; q--)
+ tail *= 0.0625;
+ mantissa += tail;
+ }
+
+ *p++ = '0';
+ *p++ = dp->conversion - 'A' + 'X';
+ pad_ptr = p;
+ {
+ int digit;
+
+ digit = (int) mantissa;
+ mantissa -= digit;
+ *p++ = '0' + digit;
+ if ((flags & FLAG_ALT)
+ || mantissa > 0.0 || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ /* This loop terminates because we assume
+ that FLT_RADIX is a power of 2. */
+ while (mantissa > 0.0)
+ {
+ mantissa *= 16.0;
+ digit = (int) mantissa;
+ mantissa -= digit;
+ *p++ = digit
+ + (digit < 10
+ ? '0'
+ : dp->conversion - 10);
+ if (precision > 0)
+ precision--;
+ }
+ while (precision > 0)
+ {
+ *p++ = '0';
+ precision--;
+ }
+ }
+ }
+ *p++ = dp->conversion - 'A' + 'P';
+# if WIDE_CHAR_VERSION
+ {
+ static const wchar_t decimal_format[] =
+ { '%', '+', 'd', '\0' };
+ SNPRINTF (p, 6 + 1, decimal_format, exponent);
+ }
+ while (*p != '\0')
+ p++;
+# else
+ if (sizeof (DCHAR_T) == 1)
+ {
+ sprintf ((char *) p, "%+d", exponent);
+ while (*p != '\0')
+ p++;
+ }
+ else
+ {
+ char expbuf[6 + 1];
+ const char *ep;
+ sprintf (expbuf, "%+d", exponent);
+ for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+ p++;
+ }
+# endif
+ }
+ }
+# else
+ abort ();
+# endif
+ }
+ /* The generated string now extends from tmp to p, with the
+ zero padding insertion point being at pad_ptr. */
+ if (has_width && p - tmp < width)
+ {
+ size_t pad = width - (p - tmp);
+ DCHAR_T *end = p + pad;
+
+ if (flags & FLAG_LEFT)
+ {
+ /* Pad with spaces on the right. */
+ for (; pad > 0; pad--)
+ *p++ = ' ';
+ }
+ else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
+ {
+ /* Pad with zeroes. */
+ DCHAR_T *q = end;
+
+ while (p > pad_ptr)
+ *--q = *--p;
+ for (; pad > 0; pad--)
+ *p++ = '0';
+ }
+ else
+ {
+ /* Pad with spaces on the left. */
+ DCHAR_T *q = end;
+
+ while (p > tmp)
+ *--q = *--p;
+ for (; pad > 0; pad--)
+ *p++ = ' ';
+ }
+
+ p = end;
+ }
+
+ {
+ size_t count = p - tmp;
+
+ if (count >= tmp_length)
+ /* tmp_length was incorrectly calculated - fix the
+ code above! */
+ abort ();
+
+ /* Make room for the result. */
+ if (count >= allocated - length)
+ {
+ size_t n = xsum (length, count);
+
+ ENSURE_ALLOCATION (n);
+ }
+
+ /* Append the result. */
+ memcpy (result + length, tmp, count * sizeof (DCHAR_T));
+ if (tmp != tmpbuf)
+ free (tmp);
+ length += count;
+ }
+ }
+#endif
+#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
+ else if ((dp->conversion == 'f' || dp->conversion == 'F'
+ || dp->conversion == 'e' || dp->conversion == 'E'
+ || dp->conversion == 'g' || dp->conversion == 'G'
+ || dp->conversion == 'a' || dp->conversion == 'A')
+ && (0
+# if NEED_PRINTF_DOUBLE
+ || a.arg[dp->arg_index].type == TYPE_DOUBLE
+# elif NEED_PRINTF_INFINITE_DOUBLE
+ || (a.arg[dp->arg_index].type == TYPE_DOUBLE
+ /* The systems (mingw) which produce wrong output
+ for Inf, -Inf, and NaN also do so for -0.0.
+ Therefore we treat this case here as well. */
+ && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double))
+# endif
+# if NEED_PRINTF_LONG_DOUBLE
+ || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
+# elif NEED_PRINTF_INFINITE_LONG_DOUBLE
+ || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE
+ /* Some systems produce wrong output for Inf,
+ -Inf, and NaN. Some systems in this category
+ (IRIX 5.3) also do so for -0.0. Therefore we
+ treat this case here as well. */
+ && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble))
+# endif
+ ))
+ {
+# if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE)
+ arg_type type = a.arg[dp->arg_index].type;
+# endif
+ int flags = dp->flags;
+ int has_width;
+ size_t width;
+ int has_precision;
+ size_t precision;
+ size_t tmp_length;
+ DCHAR_T tmpbuf[700];
+ DCHAR_T *tmp;
+ DCHAR_T *pad_ptr;
+ DCHAR_T *p;
+
+ has_width = 0;
+ width = 0;
+ if (dp->width_start != dp->width_end)
+ {
+ if (dp->width_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->width_arg_index].a.a_int;
+ if (arg < 0)
+ {
+ /* "A negative field width is taken as a '-' flag
+ followed by a positive field width." */
+ flags |= FLAG_LEFT;
+ width = (unsigned int) (-arg);
+ }
+ else
+ width = arg;
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->width_start;
+
+ do
+ width = xsum (xtimes (width, 10), *digitp++ - '0');
+ while (digitp != dp->width_end);
+ }
+ has_width = 1;
+ }
+
+ has_precision = 0;
+ precision = 0;
+ if (dp->precision_start != dp->precision_end)
+ {
+ if (dp->precision_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->precision_arg_index].a.a_int;
+ /* "A negative precision is taken as if the precision
+ were omitted." */
+ if (arg >= 0)
+ {
+ precision = arg;
+ has_precision = 1;
+ }
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->precision_start + 1;
+
+ precision = 0;
+ while (digitp != dp->precision_end)
+ precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+ has_precision = 1;
+ }
+ }
+
+ /* POSIX specifies the default precision to be 6 for %f, %F,
+ %e, %E, but not for %g, %G. Implementations appear to use
+ the same default precision also for %g, %G. But for %a, %A,
+ the default precision is 0. */
+ if (!has_precision)
+ if (!(dp->conversion == 'a' || dp->conversion == 'A'))
+ precision = 6;
+
+ /* Allocate a temporary buffer of sufficient size. */
+# if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE
+ tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1);
+# elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE
+ tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0);
+# elif NEED_PRINTF_LONG_DOUBLE
+ tmp_length = LDBL_DIG + 1;
+# elif NEED_PRINTF_DOUBLE
+ tmp_length = DBL_DIG + 1;
+# else
+ tmp_length = 0;
+# endif
+ if (tmp_length < precision)
+ tmp_length = precision;
+# if NEED_PRINTF_LONG_DOUBLE
+# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
+ if (type == TYPE_LONGDOUBLE)
+# endif
+ if (dp->conversion == 'f' || dp->conversion == 'F')
+ {
+ long double arg = a.arg[dp->arg_index].a.a_longdouble;
+ if (!(isnanl (arg) || arg + arg == arg))
+ {
+ /* arg is finite and nonzero. */
+ int exponent = floorlog10l (arg < 0 ? -arg : arg);
+ if (exponent >= 0 && tmp_length < exponent + precision)
+ tmp_length = exponent + precision;
+ }
+ }
+# endif
+# if NEED_PRINTF_DOUBLE
+# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
+ if (type == TYPE_DOUBLE)
+# endif
+ if (dp->conversion == 'f' || dp->conversion == 'F')
+ {
+ double arg = a.arg[dp->arg_index].a.a_double;
+ if (!(isnand (arg) || arg + arg == arg))
+ {
+ /* arg is finite and nonzero. */
+ int exponent = floorlog10 (arg < 0 ? -arg : arg);
+ if (exponent >= 0 && tmp_length < exponent + precision)
+ tmp_length = exponent + precision;
+ }
+ }
+# endif
+ /* Account for sign, decimal point etc. */
+ tmp_length = xsum (tmp_length, 12);
+
+ if (tmp_length < width)
+ tmp_length = width;
+
+ tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */
+
+ if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
+ tmp = tmpbuf;
+ else
+ {
+ size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
+
+ if (size_overflow_p (tmp_memsize))
+ /* Overflow, would lead to out of memory. */
+ goto out_of_memory;
+ tmp = (DCHAR_T *) malloc (tmp_memsize);
+ if (tmp == NULL)
+ /* Out of memory. */
+ goto out_of_memory;
+ }
+
+ pad_ptr = NULL;
+ p = tmp;
+
+# if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE
+# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
+ if (type == TYPE_LONGDOUBLE)
+# endif
+ {
+ long double arg = a.arg[dp->arg_index].a.a_longdouble;
+
+ if (isnanl (arg))
+ {
+ if (dp->conversion >= 'A' && dp->conversion <= 'Z')
+ {
+ *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
+ }
+ else
+ {
+ *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
+ }
+ }
+ else
+ {
+ int sign = 0;
+ DECL_LONG_DOUBLE_ROUNDING
+
+ BEGIN_LONG_DOUBLE_ROUNDING ();
+
+ if (signbit (arg)) /* arg < 0.0L or negative zero */
+ {
+ sign = -1;
+ arg = -arg;
+ }
+
+ if (sign < 0)
+ *p++ = '-';
+ else if (flags & FLAG_SHOWSIGN)
+ *p++ = '+';
+ else if (flags & FLAG_SPACE)
+ *p++ = ' ';
+
+ if (arg > 0.0L && arg + arg == arg)
+ {
+ if (dp->conversion >= 'A' && dp->conversion <= 'Z')
+ {
+ *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
+ }
+ else
+ {
+ *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
+ }
+ }
+ else
+ {
+# if NEED_PRINTF_LONG_DOUBLE
+ pad_ptr = p;
+
+ if (dp->conversion == 'f' || dp->conversion == 'F')
+ {
+ char *digits;
+ size_t ndigits;
+
+ digits =
+ scale10_round_decimal_long_double (arg, precision);
+ if (digits == NULL)
+ {
+ END_LONG_DOUBLE_ROUNDING ();
+ goto out_of_memory;
+ }
+ ndigits = strlen (digits);
+
+ if (ndigits > precision)
+ do
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ while (ndigits > precision);
+ else
+ *p++ = '0';
+ /* Here ndigits <= precision. */
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > ndigits; precision--)
+ *p++ = '0';
+ while (ndigits > 0)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+
+ free (digits);
+ }
+ else if (dp->conversion == 'e' || dp->conversion == 'E')
+ {
+ int exponent;
+
+ if (arg == 0.0L)
+ {
+ exponent = 0;
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > 0; precision--)
+ *p++ = '0';
+ }
+ }
+ else
+ {
+ /* arg > 0.0L. */
+ int adjusted;
+ char *digits;
+ size_t ndigits;
+
+ exponent = floorlog10l (arg);
+ adjusted = 0;
+ for (;;)
+ {
+ digits =
+ scale10_round_decimal_long_double (arg,
+ (int)precision - exponent);
+ if (digits == NULL)
+ {
+ END_LONG_DOUBLE_ROUNDING ();
+ goto out_of_memory;
+ }
+ ndigits = strlen (digits);
+
+ if (ndigits == precision + 1)
+ break;
+ if (ndigits < precision
+ || ndigits > precision + 2)
+ /* The exponent was not guessed
+ precisely enough. */
+ abort ();
+ if (adjusted)
+ /* None of two values of exponent is
+ the right one. Prevent an endless
+ loop. */
+ abort ();
+ free (digits);
+ if (ndigits == precision)
+ exponent -= 1;
+ else
+ exponent += 1;
+ adjusted = 1;
+ }
+ /* Here ndigits = precision+1. */
+ if (is_borderline (digits, precision))
+ {
+ /* Maybe the exponent guess was too high
+ and a smaller exponent can be reached
+ by turning a 10...0 into 9...9x. */
+ char *digits2 =
+ scale10_round_decimal_long_double (arg,
+ (int)precision - exponent + 1);
+ if (digits2 == NULL)
+ {
+ free (digits);
+ END_LONG_DOUBLE_ROUNDING ();
+ goto out_of_memory;
+ }
+ if (strlen (digits2) == precision + 1)
+ {
+ free (digits);
+ digits = digits2;
+ exponent -= 1;
+ }
+ else
+ free (digits2);
+ }
+ /* Here ndigits = precision+1. */
+
+ *p++ = digits[--ndigits];
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > 0)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+
+ free (digits);
+ }
+
+ *p++ = dp->conversion; /* 'e' or 'E' */
+# if WIDE_CHAR_VERSION
+ {
+ static const wchar_t decimal_format[] =
+ { '%', '+', '.', '2', 'd', '\0' };
+ SNPRINTF (p, 6 + 1, decimal_format, exponent);
+ }
+ while (*p != '\0')
+ p++;
+# else
+ if (sizeof (DCHAR_T) == 1)
+ {
+ sprintf ((char *) p, "%+.2d", exponent);
+ while (*p != '\0')
+ p++;
+ }
+ else
+ {
+ char expbuf[6 + 1];
+ const char *ep;
+ sprintf (expbuf, "%+.2d", exponent);
+ for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+ p++;
+ }
+# endif
+ }
+ else if (dp->conversion == 'g' || dp->conversion == 'G')
+ {
+ if (precision == 0)
+ precision = 1;
+ /* precision >= 1. */
+
+ if (arg == 0.0L)
+ /* The exponent is 0, >= -4, < precision.
+ Use fixed-point notation. */
+ {
+ size_t ndigits = precision;
+ /* Number of trailing zeroes that have to be
+ dropped. */
+ size_t nzeroes =
+ (flags & FLAG_ALT ? 0 : precision - 1);
+
+ --ndigits;
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || ndigits > nzeroes)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = '0';
+ }
+ }
+ }
+ else
+ {
+ /* arg > 0.0L. */
+ int exponent;
+ int adjusted;
+ char *digits;
+ size_t ndigits;
+ size_t nzeroes;
+
+ exponent = floorlog10l (arg);
+ adjusted = 0;
+ for (;;)
+ {
+ digits =
+ scale10_round_decimal_long_double (arg,
+ (int)(precision - 1) - exponent);
+ if (digits == NULL)
+ {
+ END_LONG_DOUBLE_ROUNDING ();
+ goto out_of_memory;
+ }
+ ndigits = strlen (digits);
+
+ if (ndigits == precision)
+ break;
+ if (ndigits < precision - 1
+ || ndigits > precision + 1)
+ /* The exponent was not guessed
+ precisely enough. */
+ abort ();
+ if (adjusted)
+ /* None of two values of exponent is
+ the right one. Prevent an endless
+ loop. */
+ abort ();
+ free (digits);
+ if (ndigits < precision)
+ exponent -= 1;
+ else
+ exponent += 1;
+ adjusted = 1;
+ }
+ /* Here ndigits = precision. */
+ if (is_borderline (digits, precision - 1))
+ {
+ /* Maybe the exponent guess was too high
+ and a smaller exponent can be reached
+ by turning a 10...0 into 9...9x. */
+ char *digits2 =
+ scale10_round_decimal_long_double (arg,
+ (int)(precision - 1) - exponent + 1);
+ if (digits2 == NULL)
+ {
+ free (digits);
+ END_LONG_DOUBLE_ROUNDING ();
+ goto out_of_memory;
+ }
+ if (strlen (digits2) == precision)
+ {
+ free (digits);
+ digits = digits2;
+ exponent -= 1;
+ }
+ else
+ free (digits2);
+ }
+ /* Here ndigits = precision. */
+
+ /* Determine the number of trailing zeroes
+ that have to be dropped. */
+ nzeroes = 0;
+ if ((flags & FLAG_ALT) == 0)
+ while (nzeroes < ndigits
+ && digits[nzeroes] == '0')
+ nzeroes++;
+
+ /* The exponent is now determined. */
+ if (exponent >= -4
+ && exponent < (long)precision)
+ {
+ /* Fixed-point notation:
+ max(exponent,0)+1 digits, then the
+ decimal point, then the remaining
+ digits without trailing zeroes. */
+ if (exponent >= 0)
+ {
+ size_t count = exponent + 1;
+ /* Note: count <= precision = ndigits. */
+ for (; count > 0; count--)
+ *p++ = digits[--ndigits];
+ if ((flags & FLAG_ALT) || ndigits > nzeroes)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+ }
+ else
+ {
+ size_t count = -exponent - 1;
+ *p++ = '0';
+ *p++ = decimal_point_char ();
+ for (; count > 0; count--)
+ *p++ = '0';
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+ }
+ else
+ {
+ /* Exponential notation. */
+ *p++ = digits[--ndigits];
+ if ((flags & FLAG_ALT) || ndigits > nzeroes)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+ *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
+# if WIDE_CHAR_VERSION
+ {
+ static const wchar_t decimal_format[] =
+ { '%', '+', '.', '2', 'd', '\0' };
+ SNPRINTF (p, 6 + 1, decimal_format, exponent);
+ }
+ while (*p != '\0')
+ p++;
+# else
+ if (sizeof (DCHAR_T) == 1)
+ {
+ sprintf ((char *) p, "%+.2d", exponent);
+ while (*p != '\0')
+ p++;
+ }
+ else
+ {
+ char expbuf[6 + 1];
+ const char *ep;
+ sprintf (expbuf, "%+.2d", exponent);
+ for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+ p++;
+ }
+# endif
+ }
+
+ free (digits);
+ }
+ }
+ else
+ abort ();
+# else
+ /* arg is finite. */
+ if (!(arg == 0.0L))
+ abort ();
+
+ pad_ptr = p;
+
+ if (dp->conversion == 'f' || dp->conversion == 'F')
+ {
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > 0; precision--)
+ *p++ = '0';
+ }
+ }
+ else if (dp->conversion == 'e' || dp->conversion == 'E')
+ {
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > 0; precision--)
+ *p++ = '0';
+ }
+ *p++ = dp->conversion; /* 'e' or 'E' */
+ *p++ = '+';
+ *p++ = '0';
+ *p++ = '0';
+ }
+ else if (dp->conversion == 'g' || dp->conversion == 'G')
+ {
+ *p++ = '0';
+ if (flags & FLAG_ALT)
+ {
+ size_t ndigits =
+ (precision > 0 ? precision - 1 : 0);
+ *p++ = decimal_point_char ();
+ for (; ndigits > 0; --ndigits)
+ *p++ = '0';
+ }
+ }
+ else if (dp->conversion == 'a' || dp->conversion == 'A')
+ {
+ *p++ = '0';
+ *p++ = dp->conversion - 'A' + 'X';
+ pad_ptr = p;
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > 0; precision--)
+ *p++ = '0';
+ }
+ *p++ = dp->conversion - 'A' + 'P';
+ *p++ = '+';
+ *p++ = '0';
+ }
+ else
+ abort ();
+# endif
+ }
+
+ END_LONG_DOUBLE_ROUNDING ();
+ }
+ }
+# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
+ else
+# endif
+# endif
+# if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE
+ {
+ double arg = a.arg[dp->arg_index].a.a_double;
+
+ if (isnand (arg))
+ {
+ if (dp->conversion >= 'A' && dp->conversion <= 'Z')
+ {
+ *p++ = 'N'; *p++ = 'A'; *p++ = 'N';
+ }
+ else
+ {
+ *p++ = 'n'; *p++ = 'a'; *p++ = 'n';
+ }
+ }
+ else
+ {
+ int sign = 0;
+
+ if (signbit (arg)) /* arg < 0.0 or negative zero */
+ {
+ sign = -1;
+ arg = -arg;
+ }
+
+ if (sign < 0)
+ *p++ = '-';
+ else if (flags & FLAG_SHOWSIGN)
+ *p++ = '+';
+ else if (flags & FLAG_SPACE)
+ *p++ = ' ';
+
+ if (arg > 0.0 && arg + arg == arg)
+ {
+ if (dp->conversion >= 'A' && dp->conversion <= 'Z')
+ {
+ *p++ = 'I'; *p++ = 'N'; *p++ = 'F';
+ }
+ else
+ {
+ *p++ = 'i'; *p++ = 'n'; *p++ = 'f';
+ }
+ }
+ else
+ {
+# if NEED_PRINTF_DOUBLE
+ pad_ptr = p;
+
+ if (dp->conversion == 'f' || dp->conversion == 'F')
+ {
+ char *digits;
+ size_t ndigits;
+
+ digits =
+ scale10_round_decimal_double (arg, precision);
+ if (digits == NULL)
+ goto out_of_memory;
+ ndigits = strlen (digits);
+
+ if (ndigits > precision)
+ do
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ while (ndigits > precision);
+ else
+ *p++ = '0';
+ /* Here ndigits <= precision. */
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > ndigits; precision--)
+ *p++ = '0';
+ while (ndigits > 0)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+
+ free (digits);
+ }
+ else if (dp->conversion == 'e' || dp->conversion == 'E')
+ {
+ int exponent;
+
+ if (arg == 0.0)
+ {
+ exponent = 0;
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > 0; precision--)
+ *p++ = '0';
+ }
+ }
+ else
+ {
+ /* arg > 0.0. */
+ int adjusted;
+ char *digits;
+ size_t ndigits;
+
+ exponent = floorlog10 (arg);
+ adjusted = 0;
+ for (;;)
+ {
+ digits =
+ scale10_round_decimal_double (arg,
+ (int)precision - exponent);
+ if (digits == NULL)
+ goto out_of_memory;
+ ndigits = strlen (digits);
+
+ if (ndigits == precision + 1)
+ break;
+ if (ndigits < precision
+ || ndigits > precision + 2)
+ /* The exponent was not guessed
+ precisely enough. */
+ abort ();
+ if (adjusted)
+ /* None of two values of exponent is
+ the right one. Prevent an endless
+ loop. */
+ abort ();
+ free (digits);
+ if (ndigits == precision)
+ exponent -= 1;
+ else
+ exponent += 1;
+ adjusted = 1;
+ }
+ /* Here ndigits = precision+1. */
+ if (is_borderline (digits, precision))
+ {
+ /* Maybe the exponent guess was too high
+ and a smaller exponent can be reached
+ by turning a 10...0 into 9...9x. */
+ char *digits2 =
+ scale10_round_decimal_double (arg,
+ (int)precision - exponent + 1);
+ if (digits2 == NULL)
+ {
+ free (digits);
+ goto out_of_memory;
+ }
+ if (strlen (digits2) == precision + 1)
+ {
+ free (digits);
+ digits = digits2;
+ exponent -= 1;
+ }
+ else
+ free (digits2);
+ }
+ /* Here ndigits = precision+1. */
+
+ *p++ = digits[--ndigits];
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > 0)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+
+ free (digits);
+ }
+
+ *p++ = dp->conversion; /* 'e' or 'E' */
+# if WIDE_CHAR_VERSION
+ {
+ static const wchar_t decimal_format[] =
+ /* Produce the same number of exponent digits
+ as the native printf implementation. */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ { '%', '+', '.', '3', 'd', '\0' };
+# else
+ { '%', '+', '.', '2', 'd', '\0' };
+# endif
+ SNPRINTF (p, 6 + 1, decimal_format, exponent);
+ }
+ while (*p != '\0')
+ p++;
+# else
+ {
+ static const char decimal_format[] =
+ /* Produce the same number of exponent digits
+ as the native printf implementation. */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ "%+.3d";
+# else
+ "%+.2d";
+# endif
+ if (sizeof (DCHAR_T) == 1)
+ {
+ sprintf ((char *) p, decimal_format, exponent);
+ while (*p != '\0')
+ p++;
+ }
+ else
+ {
+ char expbuf[6 + 1];
+ const char *ep;
+ sprintf (expbuf, decimal_format, exponent);
+ for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+ p++;
+ }
+ }
+# endif
+ }
+ else if (dp->conversion == 'g' || dp->conversion == 'G')
+ {
+ if (precision == 0)
+ precision = 1;
+ /* precision >= 1. */
+
+ if (arg == 0.0)
+ /* The exponent is 0, >= -4, < precision.
+ Use fixed-point notation. */
+ {
+ size_t ndigits = precision;
+ /* Number of trailing zeroes that have to be
+ dropped. */
+ size_t nzeroes =
+ (flags & FLAG_ALT ? 0 : precision - 1);
+
+ --ndigits;
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || ndigits > nzeroes)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = '0';
+ }
+ }
+ }
+ else
+ {
+ /* arg > 0.0. */
+ int exponent;
+ int adjusted;
+ char *digits;
+ size_t ndigits;
+ size_t nzeroes;
+
+ exponent = floorlog10 (arg);
+ adjusted = 0;
+ for (;;)
+ {
+ digits =
+ scale10_round_decimal_double (arg,
+ (int)(precision - 1) - exponent);
+ if (digits == NULL)
+ goto out_of_memory;
+ ndigits = strlen (digits);
+
+ if (ndigits == precision)
+ break;
+ if (ndigits < precision - 1
+ || ndigits > precision + 1)
+ /* The exponent was not guessed
+ precisely enough. */
+ abort ();
+ if (adjusted)
+ /* None of two values of exponent is
+ the right one. Prevent an endless
+ loop. */
+ abort ();
+ free (digits);
+ if (ndigits < precision)
+ exponent -= 1;
+ else
+ exponent += 1;
+ adjusted = 1;
+ }
+ /* Here ndigits = precision. */
+ if (is_borderline (digits, precision - 1))
+ {
+ /* Maybe the exponent guess was too high
+ and a smaller exponent can be reached
+ by turning a 10...0 into 9...9x. */
+ char *digits2 =
+ scale10_round_decimal_double (arg,
+ (int)(precision - 1) - exponent + 1);
+ if (digits2 == NULL)
+ {
+ free (digits);
+ goto out_of_memory;
+ }
+ if (strlen (digits2) == precision)
+ {
+ free (digits);
+ digits = digits2;
+ exponent -= 1;
+ }
+ else
+ free (digits2);
+ }
+ /* Here ndigits = precision. */
+
+ /* Determine the number of trailing zeroes
+ that have to be dropped. */
+ nzeroes = 0;
+ if ((flags & FLAG_ALT) == 0)
+ while (nzeroes < ndigits
+ && digits[nzeroes] == '0')
+ nzeroes++;
+
+ /* The exponent is now determined. */
+ if (exponent >= -4
+ && exponent < (long)precision)
+ {
+ /* Fixed-point notation:
+ max(exponent,0)+1 digits, then the
+ decimal point, then the remaining
+ digits without trailing zeroes. */
+ if (exponent >= 0)
+ {
+ size_t count = exponent + 1;
+ /* Note: count <= precision = ndigits. */
+ for (; count > 0; count--)
+ *p++ = digits[--ndigits];
+ if ((flags & FLAG_ALT) || ndigits > nzeroes)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+ }
+ else
+ {
+ size_t count = -exponent - 1;
+ *p++ = '0';
+ *p++ = decimal_point_char ();
+ for (; count > 0; count--)
+ *p++ = '0';
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+ }
+ else
+ {
+ /* Exponential notation. */
+ *p++ = digits[--ndigits];
+ if ((flags & FLAG_ALT) || ndigits > nzeroes)
+ {
+ *p++ = decimal_point_char ();
+ while (ndigits > nzeroes)
+ {
+ --ndigits;
+ *p++ = digits[ndigits];
+ }
+ }
+ *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */
+# if WIDE_CHAR_VERSION
+ {
+ static const wchar_t decimal_format[] =
+ /* Produce the same number of exponent digits
+ as the native printf implementation. */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ { '%', '+', '.', '3', 'd', '\0' };
+# else
+ { '%', '+', '.', '2', 'd', '\0' };
+# endif
+ SNPRINTF (p, 6 + 1, decimal_format, exponent);
+ }
+ while (*p != '\0')
+ p++;
+# else
+ {
+ static const char decimal_format[] =
+ /* Produce the same number of exponent digits
+ as the native printf implementation. */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ "%+.3d";
+# else
+ "%+.2d";
+# endif
+ if (sizeof (DCHAR_T) == 1)
+ {
+ sprintf ((char *) p, decimal_format, exponent);
+ while (*p != '\0')
+ p++;
+ }
+ else
+ {
+ char expbuf[6 + 1];
+ const char *ep;
+ sprintf (expbuf, decimal_format, exponent);
+ for (ep = expbuf; (*p = *ep) != '\0'; ep++)
+ p++;
+ }
+ }
+# endif
+ }
+
+ free (digits);
+ }
+ }
+ else
+ abort ();
+# else
+ /* arg is finite. */
+ if (!(arg == 0.0))
+ abort ();
+
+ pad_ptr = p;
+
+ if (dp->conversion == 'f' || dp->conversion == 'F')
+ {
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > 0; precision--)
+ *p++ = '0';
+ }
+ }
+ else if (dp->conversion == 'e' || dp->conversion == 'E')
+ {
+ *p++ = '0';
+ if ((flags & FLAG_ALT) || precision > 0)
+ {
+ *p++ = decimal_point_char ();
+ for (; precision > 0; precision--)
+ *p++ = '0';
+ }
+ *p++ = dp->conversion; /* 'e' or 'E' */
+ *p++ = '+';
+ /* Produce the same number of exponent digits as
+ the native printf implementation. */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ *p++ = '0';
+# endif
+ *p++ = '0';
+ *p++ = '0';
+ }
+ else if (dp->conversion == 'g' || dp->conversion == 'G')
+ {
+ *p++ = '0';
+ if (flags & FLAG_ALT)
+ {
+ size_t ndigits =
+ (precision > 0 ? precision - 1 : 0);
+ *p++ = decimal_point_char ();
+ for (; ndigits > 0; --ndigits)
+ *p++ = '0';
+ }
+ }
+ else
+ abort ();
+# endif
+ }
+ }
+ }
+# endif
+
+ /* The generated string now extends from tmp to p, with the
+ zero padding insertion point being at pad_ptr. */
+ if (has_width && p - tmp < width)
+ {
+ size_t pad = width - (p - tmp);
+ DCHAR_T *end = p + pad;
+
+ if (flags & FLAG_LEFT)
+ {
+ /* Pad with spaces on the right. */
+ for (; pad > 0; pad--)
+ *p++ = ' ';
+ }
+ else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
+ {
+ /* Pad with zeroes. */
+ DCHAR_T *q = end;
+
+ while (p > pad_ptr)
+ *--q = *--p;
+ for (; pad > 0; pad--)
+ *p++ = '0';
+ }
+ else
+ {
+ /* Pad with spaces on the left. */
+ DCHAR_T *q = end;
+
+ while (p > tmp)
+ *--q = *--p;
+ for (; pad > 0; pad--)
+ *p++ = ' ';
+ }
+
+ p = end;
+ }
+
+ {
+ size_t count = p - tmp;
+
+ if (count >= tmp_length)
+ /* tmp_length was incorrectly calculated - fix the
+ code above! */
+ abort ();
+
+ /* Make room for the result. */
+ if (count >= allocated - length)
+ {
+ size_t n = xsum (length, count);
+
+ ENSURE_ALLOCATION (n);
+ }
+
+ /* Append the result. */
+ memcpy (result + length, tmp, count * sizeof (DCHAR_T));
+ if (tmp != tmpbuf)
+ free (tmp);
+ length += count;
+ }
+ }
+#endif
+ else
+ {
+ arg_type type = a.arg[dp->arg_index].type;
+ int flags = dp->flags;
+#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+ int has_width;
+ size_t width;
+#endif
+#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION
+ int has_precision;
+ size_t precision;
+#endif
+#if NEED_PRINTF_UNBOUNDED_PRECISION
+ int prec_ourselves;
+#else
+# define prec_ourselves 0
+#endif
+#if NEED_PRINTF_FLAG_LEFTADJUST
+# define pad_ourselves 1
+#elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+ int pad_ourselves;
+#else
+# define pad_ourselves 0
+#endif
+ TCHAR_T *fbp;
+ unsigned int prefix_count;
+ int prefixes[2] IF_LINT (= { 0 });
+ int orig_errno;
+#if !USE_SNPRINTF
+ size_t tmp_length;
+ TCHAR_T tmpbuf[700];
+ TCHAR_T *tmp;
+#endif
+
+#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+ has_width = 0;
+ width = 0;
+ if (dp->width_start != dp->width_end)
+ {
+ if (dp->width_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->width_arg_index].a.a_int;
+ if (arg < 0)
+ {
+ /* "A negative field width is taken as a '-' flag
+ followed by a positive field width." */
+ flags |= FLAG_LEFT;
+ width = (unsigned int) (-arg);
+ }
+ else
+ width = arg;
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->width_start;
+
+ do
+ width = xsum (xtimes (width, 10), *digitp++ - '0');
+ while (digitp != dp->width_end);
+ }
+ has_width = 1;
+ }
+#endif
+
+#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION
+ has_precision = 0;
+ precision = 6;
+ if (dp->precision_start != dp->precision_end)
+ {
+ if (dp->precision_arg_index != ARG_NONE)
+ {
+ int arg;
+
+ if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+ abort ();
+ arg = a.arg[dp->precision_arg_index].a.a_int;
+ /* "A negative precision is taken as if the precision
+ were omitted." */
+ if (arg >= 0)
+ {
+ precision = arg;
+ has_precision = 1;
+ }
+ }
+ else
+ {
+ const FCHAR_T *digitp = dp->precision_start + 1;
+
+ precision = 0;
+ while (digitp != dp->precision_end)
+ precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+ has_precision = 1;
+ }
+ }
+#endif
+
+ /* Decide whether to handle the precision ourselves. */
+#if NEED_PRINTF_UNBOUNDED_PRECISION
+ switch (dp->conversion)
+ {
+ case 'd': case 'i': case 'u':
+ case 'o':
+ case 'x': case 'X': case 'p':
+ prec_ourselves = has_precision && (precision > 0);
+ break;
+ default:
+ prec_ourselves = 0;
+ break;
+ }
+#endif
+
+ /* Decide whether to perform the padding ourselves. */
+#if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION)
+ switch (dp->conversion)
+ {
+# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
+ /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need
+ to perform the padding after this conversion. Functions
+ with unistdio extensions perform the padding based on
+ character count rather than element count. */
+ case 'c': case 's':
+# endif
+# if NEED_PRINTF_FLAG_ZERO
+ case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
+ case 'a': case 'A':
+# endif
+ pad_ourselves = 1;
+ break;
+ default:
+ pad_ourselves = prec_ourselves;
+ break;
+ }
+#endif
+
+#if !USE_SNPRINTF
+ /* Allocate a temporary buffer of sufficient size for calling
+ sprintf. */
+ tmp_length =
+ MAX_ROOM_NEEDED (&a, dp->arg_index, dp->conversion, type,
+ flags, width, has_precision, precision,
+ pad_ourselves);
+
+ if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T))
+ tmp = tmpbuf;
+ else
+ {
+ size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T));
+
+ if (size_overflow_p (tmp_memsize))
+ /* Overflow, would lead to out of memory. */
+ goto out_of_memory;
+ tmp = (TCHAR_T *) malloc (tmp_memsize);
+ if (tmp == NULL)
+ /* Out of memory. */
+ goto out_of_memory;
+ }
+#endif
+
+ /* Construct the format string for calling snprintf or
+ sprintf. */
+ fbp = buf;
+ *fbp++ = '%';
+#if NEED_PRINTF_FLAG_GROUPING
+ /* The underlying implementation doesn't support the ' flag.
+ Produce no grouping characters in this case; this is
+ acceptable because the grouping is locale dependent. */
+#else
+ if (flags & FLAG_GROUP)
+ *fbp++ = '\'';
+#endif
+ if (flags & FLAG_LEFT)
+ *fbp++ = '-';
+ if (flags & FLAG_SHOWSIGN)
+ *fbp++ = '+';
+ if (flags & FLAG_SPACE)
+ *fbp++ = ' ';
+ if (flags & FLAG_ALT)
+ *fbp++ = '#';
+#if __GLIBC__ >= 2 && !defined __UCLIBC__
+ if (flags & FLAG_LOCALIZED)
+ *fbp++ = 'I';
+#endif
+ if (!pad_ourselves)
+ {
+ if (flags & FLAG_ZERO)
+ *fbp++ = '0';
+ if (dp->width_start != dp->width_end)
+ {
+ size_t n = dp->width_end - dp->width_start;
+ /* The width specification is known to consist only
+ of standard ASCII characters. */
+ if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
+ {
+ memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T));
+ fbp += n;
+ }
+ else
+ {
+ const FCHAR_T *mp = dp->width_start;
+ do
+ *fbp++ = (unsigned char) *mp++;
+ while (--n > 0);
+ }
+ }
+ }
+ if (!prec_ourselves)
+ {
+ if (dp->precision_start != dp->precision_end)
+ {
+ size_t n = dp->precision_end - dp->precision_start;
+ /* The precision specification is known to consist only
+ of standard ASCII characters. */
+ if (sizeof (FCHAR_T) == sizeof (TCHAR_T))
+ {
+ memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T));
+ fbp += n;
+ }
+ else
+ {
+ const FCHAR_T *mp = dp->precision_start;
+ do
+ *fbp++ = (unsigned char) *mp++;
+ while (--n > 0);
+ }
+ }
+ }
+
+ switch (type)
+ {
+#if HAVE_LONG_LONG_INT
+ case TYPE_LONGLONGINT:
+ case TYPE_ULONGLONGINT:
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ *fbp++ = 'I';
+ *fbp++ = '6';
+ *fbp++ = '4';
+ break;
+# else
+ *fbp++ = 'l';
+ /*FALLTHROUGH*/
+# endif
+#endif
+ case TYPE_LONGINT:
+ case TYPE_ULONGINT:
+#if HAVE_WINT_T
+ case TYPE_WIDE_CHAR:
+#endif
+#if HAVE_WCHAR_T
+ case TYPE_WIDE_STRING:
+#endif
+ *fbp++ = 'l';
+ break;
+ case TYPE_LONGDOUBLE:
+ *fbp++ = 'L';
+ break;
+ default:
+ break;
+ }
+#if NEED_PRINTF_DIRECTIVE_F
+ if (dp->conversion == 'F')
+ *fbp = 'f';
+ else
+#endif
+ *fbp = dp->conversion;
+#if USE_SNPRINTF
# if !defined(__APPLE__) && !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
- fbp[1] = '%';
- fbp[2] = 'n';
- fbp[3] = '\0';
-# else
- /* On glibc2 systems from glibc >= 2.3 - probably also older
- ones - we know that snprintf's return value conforms to
- ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and
- gl_SNPRINTF_TRUNCATION_C99 pass.
- Therefore we can avoid using %n in this situation.
- On glibc2 systems from 2004-10-18 or newer, the use of %n
- in format strings in writable memory may crash the program
- (if compiled with _FORTIFY_SOURCE=2), so we should avoid it
- in this situation. */
- /* On native Windows systems (such as mingw), we can avoid using
- %n because:
- - Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
- snprintf does not write more than the specified number
- of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes
- '4', '5', '6' into buf, not '4', '5', '\0'.)
- - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf
- allows us to recognize the case of an insufficient
- buffer size: it returns -1 in this case.
- On native Windows systems (such as mingw) where the OS is
- Windows Vista, the use of %n in format strings by default
- crashes the program. See
- <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
- <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx>
- So we should avoid %n in this situation. */
- fbp[1] = '\0';
-# endif
-#else
- fbp[1] = '\0';
-#endif
-
- /* Construct the arguments for calling snprintf or sprintf. */
- prefix_count = 0;
- if (!pad_ourselves && dp->width_arg_index != ARG_NONE)
- {
- if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
- abort ();
- prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int;
- }
- if (!prec_ourselves && dp->precision_arg_index != ARG_NONE)
- {
- if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
- abort ();
- prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int;
- }
-
-#if USE_SNPRINTF
- /* The SNPRINTF result is appended after result[0..length].
- The latter is an array of DCHAR_T; SNPRINTF appends an
- array of TCHAR_T to it. This is possible because
- sizeof (TCHAR_T) divides sizeof (DCHAR_T) and
- alignof (TCHAR_T) <= alignof (DCHAR_T). */
-# define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T))
- /* Ensure that maxlen below will be >= 2. Needed on BeOS,
- where an snprintf() with maxlen==1 acts like sprintf(). */
- ENSURE_ALLOCATION (xsum (length,
- (2 + TCHARS_PER_DCHAR - 1)
- / TCHARS_PER_DCHAR));
- /* Prepare checking whether snprintf returns the count
- via %n. */
- *(TCHAR_T *) (result + length) = '\0';
-#endif
-
- orig_errno = errno;
-
- for (;;)
- {
- int count = -1;
-
-#if USE_SNPRINTF
- int retcount = 0;
- size_t maxlen = allocated - length;
- /* SNPRINTF can fail if its second argument is
- > INT_MAX. */
- if (maxlen > INT_MAX / TCHARS_PER_DCHAR)
- maxlen = INT_MAX / TCHARS_PER_DCHAR;
- maxlen = maxlen * TCHARS_PER_DCHAR;
-# define SNPRINTF_BUF(arg) \
- switch (prefix_count) \
- { \
- case 0: \
- retcount = SNPRINTF ((TCHAR_T *) (result + length), \
- maxlen, buf, \
- arg, &count); \
- break; \
- case 1: \
- retcount = SNPRINTF ((TCHAR_T *) (result + length), \
- maxlen, buf, \
- prefixes[0], arg, &count); \
- break; \
- case 2: \
- retcount = SNPRINTF ((TCHAR_T *) (result + length), \
- maxlen, buf, \
- prefixes[0], prefixes[1], arg, \
- &count); \
- break; \
- default: \
- abort (); \
- }
-#else
-# define SNPRINTF_BUF(arg) \
- switch (prefix_count) \
- { \
- case 0: \
- count = sprintf (tmp, buf, arg); \
- break; \
- case 1: \
- count = sprintf (tmp, buf, prefixes[0], arg); \
- break; \
- case 2: \
- count = sprintf (tmp, buf, prefixes[0], prefixes[1],\
- arg); \
- break; \
- default: \
- abort (); \
- }
-#endif
-
- errno = 0;
- switch (type)
- {
- case TYPE_SCHAR:
- {
- int arg = a.arg[dp->arg_index].a.a_schar;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_UCHAR:
- {
- unsigned int arg = a.arg[dp->arg_index].a.a_uchar;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_SHORT:
- {
- int arg = a.arg[dp->arg_index].a.a_short;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_USHORT:
- {
- unsigned int arg = a.arg[dp->arg_index].a.a_ushort;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_INT:
- {
- int arg = a.arg[dp->arg_index].a.a_int;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_UINT:
- {
- unsigned int arg = a.arg[dp->arg_index].a.a_uint;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_LONGINT:
- {
- long int arg = a.arg[dp->arg_index].a.a_longint;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_ULONGINT:
- {
- unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint;
- SNPRINTF_BUF (arg);
- }
- break;
-#if HAVE_LONG_LONG_INT
- case TYPE_LONGLONGINT:
- {
- long long int arg = a.arg[dp->arg_index].a.a_longlongint;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_ULONGLONGINT:
- {
- unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint;
- SNPRINTF_BUF (arg);
- }
- break;
-#endif
- case TYPE_DOUBLE:
- {
- double arg = a.arg[dp->arg_index].a.a_double;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_LONGDOUBLE:
- {
- long double arg = a.arg[dp->arg_index].a.a_longdouble;
- SNPRINTF_BUF (arg);
- }
- break;
- case TYPE_CHAR:
- {
- int arg = a.arg[dp->arg_index].a.a_char;
- SNPRINTF_BUF (arg);
- }
- break;
-#if HAVE_WINT_T
- case TYPE_WIDE_CHAR:
- {
- wint_t arg = a.arg[dp->arg_index].a.a_wide_char;
- SNPRINTF_BUF (arg);
- }
- break;
-#endif
- case TYPE_STRING:
- {
- const char *arg = a.arg[dp->arg_index].a.a_string;
- SNPRINTF_BUF (arg);
- }
- break;
-#if HAVE_WCHAR_T
- case TYPE_WIDE_STRING:
- {
- const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
- SNPRINTF_BUF (arg);
- }
- break;
-#endif
- case TYPE_POINTER:
- {
- void *arg = a.arg[dp->arg_index].a.a_pointer;
- SNPRINTF_BUF (arg);
- }
- break;
- default:
- abort ();
- }
-
-#if USE_SNPRINTF
- /* Portability: Not all implementations of snprintf()
- are ISO C 99 compliant. Determine the number of
- bytes that snprintf() has produced or would have
- produced. */
- if (count >= 0)
- {
- /* Verify that snprintf() has NUL-terminated its
- result. */
- if (count < maxlen
- && ((TCHAR_T *) (result + length)) [count] != '\0')
- abort ();
- /* Portability hack. */
- if (retcount > count)
- count = retcount;
- }
- else
- {
- /* snprintf() doesn't understand the '%n'
- directive. */
- if (fbp[1] != '\0')
- {
- /* Don't use the '%n' directive; instead, look
- at the snprintf() return value. */
- fbp[1] = '\0';
- continue;
- }
- else
- {
- /* Look at the snprintf() return value. */
- if (retcount < 0)
- {
-# if !HAVE_SNPRINTF_RETVAL_C99
- /* HP-UX 10.20 snprintf() is doubly deficient:
- It doesn't understand the '%n' directive,
- *and* it returns -1 (rather than the length
- that would have been required) when the
- buffer is too small.
- But a failure at this point can also come
- from other reasons than a too small buffer,
- such as an invalid wide string argument to
- the %ls directive, or possibly an invalid
- floating-point argument. */
- size_t tmp_length =
- MAX_ROOM_NEEDED (&a, dp->arg_index,
- dp->conversion, type, flags,
- has_width ? width : 0,
- has_precision,
- precision, pad_ourselves);
-
- if (maxlen < tmp_length)
- {
- /* Make more room. But try to do through
- this reallocation only once. */
- size_t bigger_need =
- xsum (length,
- xsum (tmp_length,
- TCHARS_PER_DCHAR - 1)
- / TCHARS_PER_DCHAR);
- /* And always grow proportionally.
- (There may be several arguments, each
- needing a little more room than the
- previous one.) */
- size_t bigger_need2 =
- xsum (xtimes (allocated, 2), 12);
- if (bigger_need < bigger_need2)
- bigger_need = bigger_need2;
- ENSURE_ALLOCATION (bigger_need);
- continue;
- }
-# endif
- }
- else
- count = retcount;
- }
- }
-#endif
-
- /* Attempt to handle failure. */
- if (count < 0)
- {
- /* SNPRINTF or sprintf failed. Save and use the errno
- that it has set, if any. */
- int saved_errno = errno;
-
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno =
- (saved_errno != 0
- ? saved_errno
- : (dp->conversion == 'c' || dp->conversion == 's'
- ? EILSEQ
- : EINVAL));
- return NULL;
- }
-
-#if USE_SNPRINTF
- /* Handle overflow of the allocated buffer.
- If such an overflow occurs, a C99 compliant snprintf()
- returns a count >= maxlen. However, a non-compliant
- snprintf() function returns only count = maxlen - 1. To
- cover both cases, test whether count >= maxlen - 1. */
- if ((unsigned int) count + 1 >= maxlen)
- {
- /* If maxlen already has attained its allowed maximum,
- allocating more memory will not increase maxlen.
- Instead of looping, bail out. */
- if (maxlen == INT_MAX / TCHARS_PER_DCHAR)
- goto overflow;
- else
- {
- /* Need at least (count + 1) * sizeof (TCHAR_T)
- bytes. (The +1 is for the trailing NUL.)
- But ask for (count + 2) * sizeof (TCHAR_T)
- bytes, so that in the next round, we likely get
- maxlen > (unsigned int) count + 1
- and so we don't get here again.
- And allocate proportionally, to avoid looping
- eternally if snprintf() reports a too small
- count. */
- size_t n =
- xmax (xsum (length,
- ((unsigned int) count + 2
- + TCHARS_PER_DCHAR - 1)
- / TCHARS_PER_DCHAR),
- xtimes (allocated, 2));
-
- ENSURE_ALLOCATION (n);
- continue;
- }
- }
-#endif
-
-#if NEED_PRINTF_UNBOUNDED_PRECISION
- if (prec_ourselves)
- {
- /* Handle the precision. */
- TCHAR_T *prec_ptr =
-# if USE_SNPRINTF
- (TCHAR_T *) (result + length);
-# else
- tmp;
-# endif
- size_t prefix_count;
- size_t move;
-
- prefix_count = 0;
- /* Put the additional zeroes after the sign. */
- if (count >= 1
- && (*prec_ptr == '-' || *prec_ptr == '+'
- || *prec_ptr == ' '))
- prefix_count = 1;
- /* Put the additional zeroes after the 0x prefix if
- (flags & FLAG_ALT) || (dp->conversion == 'p'). */
- else if (count >= 2
- && prec_ptr[0] == '0'
- && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X'))
- prefix_count = 2;
-
- move = count - prefix_count;
- if (precision > move)
- {
- /* Insert zeroes. */
- size_t insert = precision - move;
- TCHAR_T *prec_end;
-
-# if USE_SNPRINTF
- size_t n =
- xsum (length,
- (count + insert + TCHARS_PER_DCHAR - 1)
- / TCHARS_PER_DCHAR);
- length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
- ENSURE_ALLOCATION (n);
- length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
- prec_ptr = (TCHAR_T *) (result + length);
-# endif
-
- prec_end = prec_ptr + count;
- prec_ptr += prefix_count;
-
- while (prec_end > prec_ptr)
- {
- prec_end--;
- prec_end[insert] = prec_end[0];
- }
-
- prec_end += insert;
- do
- *--prec_end = '0';
- while (prec_end > prec_ptr);
-
- count += insert;
- }
- }
-#endif
-
-#if !USE_SNPRINTF
- if (count >= tmp_length)
- /* tmp_length was incorrectly calculated - fix the
- code above! */
- abort ();
-#endif
-
-#if !DCHAR_IS_TCHAR
- /* Convert from TCHAR_T[] to DCHAR_T[]. */
- if (dp->conversion == 'c' || dp->conversion == 's')
- {
- /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING
- TYPE_WIDE_STRING.
- The result string is not certainly ASCII. */
- const TCHAR_T *tmpsrc;
- DCHAR_T *tmpdst;
- size_t tmpdst_len;
- /* This code assumes that TCHAR_T is 'char'. */
- verify (sizeof (TCHAR_T) == 1);
-# if USE_SNPRINTF
- tmpsrc = (TCHAR_T *) (result + length);
-# else
- tmpsrc = tmp;
-# endif
- tmpdst =
- DCHAR_CONV_FROM_ENCODING (locale_charset (),
- iconveh_question_mark,
- tmpsrc, count,
- NULL,
- NULL, &tmpdst_len);
- if (tmpdst == NULL)
- {
- int saved_errno = errno;
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- errno = saved_errno;
- return NULL;
- }
- ENSURE_ALLOCATION (xsum (length, tmpdst_len));
- DCHAR_CPY (result + length, tmpdst, tmpdst_len);
- free (tmpdst);
- count = tmpdst_len;
- }
- else
- {
- /* The result string is ASCII.
- Simple 1:1 conversion. */
-# if USE_SNPRINTF
- /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a
- no-op conversion, in-place on the array starting
- at (result + length). */
- if (sizeof (DCHAR_T) != sizeof (TCHAR_T))
-# endif
- {
- const TCHAR_T *tmpsrc;
- DCHAR_T *tmpdst;
- size_t n;
-
-# if USE_SNPRINTF
- if (result == resultbuf)
- {
- tmpsrc = (TCHAR_T *) (result + length);
- /* ENSURE_ALLOCATION will not move tmpsrc
- (because it's part of resultbuf). */
- ENSURE_ALLOCATION (xsum (length, count));
- }
- else
- {
- /* ENSURE_ALLOCATION will move the array
- (because it uses realloc(). */
- ENSURE_ALLOCATION (xsum (length, count));
- tmpsrc = (TCHAR_T *) (result + length);
- }
-# else
- tmpsrc = tmp;
- ENSURE_ALLOCATION (xsum (length, count));
-# endif
- tmpdst = result + length;
- /* Copy backwards, because of overlapping. */
- tmpsrc += count;
- tmpdst += count;
- for (n = count; n > 0; n--)
- *--tmpdst = (unsigned char) *--tmpsrc;
- }
- }
-#endif
-
-#if DCHAR_IS_TCHAR && !USE_SNPRINTF
- /* Make room for the result. */
- if (count > allocated - length)
- {
- /* Need at least count elements. But allocate
- proportionally. */
- size_t n =
- xmax (xsum (length, count), xtimes (allocated, 2));
-
- ENSURE_ALLOCATION (n);
- }
-#endif
-
- /* Here count <= allocated - length. */
-
- /* Perform padding. */
-#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
- if (pad_ourselves && has_width)
- {
- size_t w;
-# if ENABLE_UNISTDIO
- /* Outside POSIX, it's preferable to compare the width
- against the number of _characters_ of the converted
- value. */
- w = DCHAR_MBSNLEN (result + length, count);
-# else
- /* The width is compared against the number of _bytes_
- of the converted value, says POSIX. */
- w = count;
-# endif
- if (w < width)
- {
- size_t pad = width - w;
-
- /* Make room for the result. */
- if (xsum (count, pad) > allocated - length)
- {
- /* Need at least count + pad elements. But
- allocate proportionally. */
- size_t n =
- xmax (xsum3 (length, count, pad),
- xtimes (allocated, 2));
-
-# if USE_SNPRINTF
- length += count;
- ENSURE_ALLOCATION (n);
- length -= count;
-# else
- ENSURE_ALLOCATION (n);
-# endif
- }
- /* Here count + pad <= allocated - length. */
-
- {
-# if !DCHAR_IS_TCHAR || USE_SNPRINTF
- DCHAR_T * const rp = result + length;
-# else
- DCHAR_T * const rp = tmp;
-# endif
- DCHAR_T *p = rp + count;
- DCHAR_T *end = p + pad;
- DCHAR_T *pad_ptr;
-# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
- if (dp->conversion == 'c'
- || dp->conversion == 's')
- /* No zero-padding for string directives. */
- pad_ptr = NULL;
- else
-# endif
- {
- pad_ptr = (*rp == '-' ? rp + 1 : rp);
- /* No zero-padding of "inf" and "nan". */
- if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z')
- || (*pad_ptr >= 'a' && *pad_ptr <= 'z'))
- pad_ptr = NULL;
- }
- /* The generated string now extends from rp to p,
- with the zero padding insertion point being at
- pad_ptr. */
-
- count = count + pad; /* = end - rp */
-
- if (flags & FLAG_LEFT)
- {
- /* Pad with spaces on the right. */
- for (; pad > 0; pad--)
- *p++ = ' ';
- }
- else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
- {
- /* Pad with zeroes. */
- DCHAR_T *q = end;
-
- while (p > pad_ptr)
- *--q = *--p;
- for (; pad > 0; pad--)
- *p++ = '0';
- }
- else
- {
- /* Pad with spaces on the left. */
- DCHAR_T *q = end;
-
- while (p > rp)
- *--q = *--p;
- for (; pad > 0; pad--)
- *p++ = ' ';
- }
- }
- }
- }
-#endif
-
- /* Here still count <= allocated - length. */
-
-#if !DCHAR_IS_TCHAR || USE_SNPRINTF
- /* The snprintf() result did fit. */
-#else
- /* Append the sprintf() result. */
- memcpy (result + length, tmp, count * sizeof (DCHAR_T));
-#endif
-#if !USE_SNPRINTF
- if (tmp != tmpbuf)
- free (tmp);
-#endif
-
-#if NEED_PRINTF_DIRECTIVE_F
- if (dp->conversion == 'F')
- {
- /* Convert the %f result to upper case for %F. */
- DCHAR_T *rp = result + length;
- size_t rc;
- for (rc = count; rc > 0; rc--, rp++)
- if (*rp >= 'a' && *rp <= 'z')
- *rp = *rp - 'a' + 'A';
- }
-#endif
-
- length += count;
- break;
- }
- errno = orig_errno;
-#undef pad_ourselves
-#undef prec_ourselves
- }
- }
- }
-
- /* Add the final NUL. */
- ENSURE_ALLOCATION (xsum (length, 1));
- result[length] = '\0';
-
- if (result != resultbuf && length + 1 < allocated)
- {
- /* Shrink the allocated memory if possible. */
- DCHAR_T *memory;
-
- memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T));
- if (memory != NULL)
- result = memory;
- }
-
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
- *lengthp = length;
- /* Note that we can produce a big string of a length > INT_MAX. POSIX
- says that snprintf() fails with errno = EOVERFLOW in this case, but
- that's only because snprintf() returns an 'int'. This function does
- not have this limitation. */
- return result;
-
-#if USE_SNPRINTF
- overflow:
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- CLEANUP ();
+ fbp[1] = '%';
+ fbp[2] = 'n';
+ fbp[3] = '\0';
+# else
+ /* On glibc2 systems from glibc >= 2.3 - probably also older
+ ones - we know that snprintf's return value conforms to
+ ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and
+ gl_SNPRINTF_TRUNCATION_C99 pass.
+ Therefore we can avoid using %n in this situation.
+ On glibc2 systems from 2004-10-18 or newer, the use of %n
+ in format strings in writable memory may crash the program
+ (if compiled with _FORTIFY_SOURCE=2), so we should avoid it
+ in this situation. */
+ /* On native Windows systems (such as mingw), we can avoid using
+ %n because:
+ - Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
+ snprintf does not write more than the specified number
+ of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes
+ '4', '5', '6' into buf, not '4', '5', '\0'.)
+ - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf
+ allows us to recognize the case of an insufficient
+ buffer size: it returns -1 in this case.
+ On native Windows systems (such as mingw) where the OS is
+ Windows Vista, the use of %n in format strings by default
+ crashes the program. See
+ <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
+ <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx>
+ So we should avoid %n in this situation. */
+ fbp[1] = '\0';
+# endif
+#else
+ fbp[1] = '\0';
+#endif
+
+ /* Construct the arguments for calling snprintf or sprintf. */
+ prefix_count = 0;
+ if (!pad_ourselves && dp->width_arg_index != ARG_NONE)
+ {
+ if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+ abort ();
+ prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int;
+ }
+ if (!prec_ourselves && dp->precision_arg_index != ARG_NONE)
+ {
+ if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+ abort ();
+ prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int;
+ }
+
+#if USE_SNPRINTF
+ /* The SNPRINTF result is appended after result[0..length].
+ The latter is an array of DCHAR_T; SNPRINTF appends an
+ array of TCHAR_T to it. This is possible because
+ sizeof (TCHAR_T) divides sizeof (DCHAR_T) and
+ alignof (TCHAR_T) <= alignof (DCHAR_T). */
+# define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T))
+ /* Ensure that maxlen below will be >= 2. Needed on BeOS,
+ where an snprintf() with maxlen==1 acts like sprintf(). */
+ ENSURE_ALLOCATION (xsum (length,
+ (2 + TCHARS_PER_DCHAR - 1)
+ / TCHARS_PER_DCHAR));
+ /* Prepare checking whether snprintf returns the count
+ via %n. */
+ *(TCHAR_T *) (result + length) = '\0';
+#endif
+
+ orig_errno = errno;
+
+ for (;;)
+ {
+ int count = -1;
+
+#if USE_SNPRINTF
+ int retcount = 0;
+ size_t maxlen = allocated - length;
+ /* SNPRINTF can fail if its second argument is
+ > INT_MAX. */
+ if (maxlen > INT_MAX / TCHARS_PER_DCHAR)
+ maxlen = INT_MAX / TCHARS_PER_DCHAR;
+ maxlen = maxlen * TCHARS_PER_DCHAR;
+# define SNPRINTF_BUF(arg) \
+ switch (prefix_count) \
+ { \
+ case 0: \
+ retcount = SNPRINTF ((TCHAR_T *) (result + length), \
+ maxlen, buf, \
+ arg, &count); \
+ break; \
+ case 1: \
+ retcount = SNPRINTF ((TCHAR_T *) (result + length), \
+ maxlen, buf, \
+ prefixes[0], arg, &count); \
+ break; \
+ case 2: \
+ retcount = SNPRINTF ((TCHAR_T *) (result + length), \
+ maxlen, buf, \
+ prefixes[0], prefixes[1], arg, \
+ &count); \
+ break; \
+ default: \
+ abort (); \
+ }
+#else
+# define SNPRINTF_BUF(arg) \
+ switch (prefix_count) \
+ { \
+ case 0: \
+ count = sprintf (tmp, buf, arg); \
+ break; \
+ case 1: \
+ count = sprintf (tmp, buf, prefixes[0], arg); \
+ break; \
+ case 2: \
+ count = sprintf (tmp, buf, prefixes[0], prefixes[1],\
+ arg); \
+ break; \
+ default: \
+ abort (); \
+ }
+#endif
+
+ errno = 0;
+ switch (type)
+ {
+ case TYPE_SCHAR:
+ {
+ int arg = a.arg[dp->arg_index].a.a_schar;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_UCHAR:
+ {
+ unsigned int arg = a.arg[dp->arg_index].a.a_uchar;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_SHORT:
+ {
+ int arg = a.arg[dp->arg_index].a.a_short;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_USHORT:
+ {
+ unsigned int arg = a.arg[dp->arg_index].a.a_ushort;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_INT:
+ {
+ int arg = a.arg[dp->arg_index].a.a_int;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_UINT:
+ {
+ unsigned int arg = a.arg[dp->arg_index].a.a_uint;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_LONGINT:
+ {
+ long int arg = a.arg[dp->arg_index].a.a_longint;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_ULONGINT:
+ {
+ unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+#if HAVE_LONG_LONG_INT
+ case TYPE_LONGLONGINT:
+ {
+ long long int arg = a.arg[dp->arg_index].a.a_longlongint;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_ULONGLONGINT:
+ {
+ unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+#endif
+ case TYPE_DOUBLE:
+ {
+ double arg = a.arg[dp->arg_index].a.a_double;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_LONGDOUBLE:
+ {
+ long double arg = a.arg[dp->arg_index].a.a_longdouble;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ case TYPE_CHAR:
+ {
+ int arg = a.arg[dp->arg_index].a.a_char;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+#if HAVE_WINT_T
+ case TYPE_WIDE_CHAR:
+ {
+ wint_t arg = a.arg[dp->arg_index].a.a_wide_char;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+#endif
+ case TYPE_STRING:
+ {
+ const char *arg = a.arg[dp->arg_index].a.a_string;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+#if HAVE_WCHAR_T
+ case TYPE_WIDE_STRING:
+ {
+ const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+#endif
+ case TYPE_POINTER:
+ {
+ void *arg = a.arg[dp->arg_index].a.a_pointer;
+ SNPRINTF_BUF (arg);
+ }
+ break;
+ default:
+ abort ();
+ }
+
+#if USE_SNPRINTF
+ /* Portability: Not all implementations of snprintf()
+ are ISO C 99 compliant. Determine the number of
+ bytes that snprintf() has produced or would have
+ produced. */
+ if (count >= 0)
+ {
+ /* Verify that snprintf() has NUL-terminated its
+ result. */
+ if (count < maxlen
+ && ((TCHAR_T *) (result + length)) [count] != '\0')
+ abort ();
+ /* Portability hack. */
+ if (retcount > count)
+ count = retcount;
+ }
+ else
+ {
+ /* snprintf() doesn't understand the '%n'
+ directive. */
+ if (fbp[1] != '\0')
+ {
+ /* Don't use the '%n' directive; instead, look
+ at the snprintf() return value. */
+ fbp[1] = '\0';
+ continue;
+ }
+ else
+ {
+ /* Look at the snprintf() return value. */
+ if (retcount < 0)
+ {
+# if !HAVE_SNPRINTF_RETVAL_C99
+ /* HP-UX 10.20 snprintf() is doubly deficient:
+ It doesn't understand the '%n' directive,
+ *and* it returns -1 (rather than the length
+ that would have been required) when the
+ buffer is too small.
+ But a failure at this point can also come
+ from other reasons than a too small buffer,
+ such as an invalid wide string argument to
+ the %ls directive, or possibly an invalid
+ floating-point argument. */
+ size_t tmp_length =
+ MAX_ROOM_NEEDED (&a, dp->arg_index,
+ dp->conversion, type, flags,
+ has_width ? width : 0,
+ has_precision,
+ precision, pad_ourselves);
+
+ if (maxlen < tmp_length)
+ {
+ /* Make more room. But try to do through
+ this reallocation only once. */
+ size_t bigger_need =
+ xsum (length,
+ xsum (tmp_length,
+ TCHARS_PER_DCHAR - 1)
+ / TCHARS_PER_DCHAR);
+ /* And always grow proportionally.
+ (There may be several arguments, each
+ needing a little more room than the
+ previous one.) */
+ size_t bigger_need2 =
+ xsum (xtimes (allocated, 2), 12);
+ if (bigger_need < bigger_need2)
+ bigger_need = bigger_need2;
+ ENSURE_ALLOCATION (bigger_need);
+ continue;
+ }
+# endif
+ }
+ else
+ count = retcount;
+ }
+ }
+#endif
+
+ /* Attempt to handle failure. */
+ if (count < 0)
+ {
+ /* SNPRINTF or sprintf failed. Save and use the errno
+ that it has set, if any. */
+ int saved_errno = errno;
+
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno =
+ (saved_errno != 0
+ ? saved_errno
+ : (dp->conversion == 'c' || dp->conversion == 's'
+ ? EILSEQ
+ : EINVAL));
+ return NULL;
+ }
+
+#if USE_SNPRINTF
+ /* Handle overflow of the allocated buffer.
+ If such an overflow occurs, a C99 compliant snprintf()
+ returns a count >= maxlen. However, a non-compliant
+ snprintf() function returns only count = maxlen - 1. To
+ cover both cases, test whether count >= maxlen - 1. */
+ if ((unsigned int) count + 1 >= maxlen)
+ {
+ /* If maxlen already has attained its allowed maximum,
+ allocating more memory will not increase maxlen.
+ Instead of looping, bail out. */
+ if (maxlen == INT_MAX / TCHARS_PER_DCHAR)
+ goto overflow;
+ else
+ {
+ /* Need at least (count + 1) * sizeof (TCHAR_T)
+ bytes. (The +1 is for the trailing NUL.)
+ But ask for (count + 2) * sizeof (TCHAR_T)
+ bytes, so that in the next round, we likely get
+ maxlen > (unsigned int) count + 1
+ and so we don't get here again.
+ And allocate proportionally, to avoid looping
+ eternally if snprintf() reports a too small
+ count. */
+ size_t n =
+ xmax (xsum (length,
+ ((unsigned int) count + 2
+ + TCHARS_PER_DCHAR - 1)
+ / TCHARS_PER_DCHAR),
+ xtimes (allocated, 2));
+
+ ENSURE_ALLOCATION (n);
+ continue;
+ }
+ }
+#endif
+
+#if NEED_PRINTF_UNBOUNDED_PRECISION
+ if (prec_ourselves)
+ {
+ /* Handle the precision. */
+ TCHAR_T *prec_ptr =
+# if USE_SNPRINTF
+ (TCHAR_T *) (result + length);
+# else
+ tmp;
+# endif
+ size_t prefix_count;
+ size_t move;
+
+ prefix_count = 0;
+ /* Put the additional zeroes after the sign. */
+ if (count >= 1
+ && (*prec_ptr == '-' || *prec_ptr == '+'
+ || *prec_ptr == ' '))
+ prefix_count = 1;
+ /* Put the additional zeroes after the 0x prefix if
+ (flags & FLAG_ALT) || (dp->conversion == 'p'). */
+ else if (count >= 2
+ && prec_ptr[0] == '0'
+ && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X'))
+ prefix_count = 2;
+
+ move = count - prefix_count;
+ if (precision > move)
+ {
+ /* Insert zeroes. */
+ size_t insert = precision - move;
+ TCHAR_T *prec_end;
+
+# if USE_SNPRINTF
+ size_t n =
+ xsum (length,
+ (count + insert + TCHARS_PER_DCHAR - 1)
+ / TCHARS_PER_DCHAR);
+ length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
+ ENSURE_ALLOCATION (n);
+ length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR;
+ prec_ptr = (TCHAR_T *) (result + length);
+# endif
+
+ prec_end = prec_ptr + count;
+ prec_ptr += prefix_count;
+
+ while (prec_end > prec_ptr)
+ {
+ prec_end--;
+ prec_end[insert] = prec_end[0];
+ }
+
+ prec_end += insert;
+ do
+ *--prec_end = '0';
+ while (prec_end > prec_ptr);
+
+ count += insert;
+ }
+ }
+#endif
+
+#if !USE_SNPRINTF
+ if (count >= tmp_length)
+ /* tmp_length was incorrectly calculated - fix the
+ code above! */
+ abort ();
+#endif
+
+#if !DCHAR_IS_TCHAR
+ /* Convert from TCHAR_T[] to DCHAR_T[]. */
+ if (dp->conversion == 'c' || dp->conversion == 's')
+ {
+ /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING
+ TYPE_WIDE_STRING.
+ The result string is not certainly ASCII. */
+ const TCHAR_T *tmpsrc;
+ DCHAR_T *tmpdst;
+ size_t tmpdst_len;
+ /* This code assumes that TCHAR_T is 'char'. */
+ verify (sizeof (TCHAR_T) == 1);
+# if USE_SNPRINTF
+ tmpsrc = (TCHAR_T *) (result + length);
+# else
+ tmpsrc = tmp;
+# endif
+ tmpdst =
+ DCHAR_CONV_FROM_ENCODING (locale_charset (),
+ iconveh_question_mark,
+ tmpsrc, count,
+ NULL,
+ NULL, &tmpdst_len);
+ if (tmpdst == NULL)
+ {
+ int saved_errno = errno;
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ errno = saved_errno;
+ return NULL;
+ }
+ ENSURE_ALLOCATION (xsum (length, tmpdst_len));
+ DCHAR_CPY (result + length, tmpdst, tmpdst_len);
+ free (tmpdst);
+ count = tmpdst_len;
+ }
+ else
+ {
+ /* The result string is ASCII.
+ Simple 1:1 conversion. */
+# if USE_SNPRINTF
+ /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a
+ no-op conversion, in-place on the array starting
+ at (result + length). */
+ if (sizeof (DCHAR_T) != sizeof (TCHAR_T))
+# endif
+ {
+ const TCHAR_T *tmpsrc;
+ DCHAR_T *tmpdst;
+ size_t n;
+
+# if USE_SNPRINTF
+ if (result == resultbuf)
+ {
+ tmpsrc = (TCHAR_T *) (result + length);
+ /* ENSURE_ALLOCATION will not move tmpsrc
+ (because it's part of resultbuf). */
+ ENSURE_ALLOCATION (xsum (length, count));
+ }
+ else
+ {
+ /* ENSURE_ALLOCATION will move the array
+ (because it uses realloc(). */
+ ENSURE_ALLOCATION (xsum (length, count));
+ tmpsrc = (TCHAR_T *) (result + length);
+ }
+# else
+ tmpsrc = tmp;
+ ENSURE_ALLOCATION (xsum (length, count));
+# endif
+ tmpdst = result + length;
+ /* Copy backwards, because of overlapping. */
+ tmpsrc += count;
+ tmpdst += count;
+ for (n = count; n > 0; n--)
+ *--tmpdst = (unsigned char) *--tmpsrc;
+ }
+ }
+#endif
+
+#if DCHAR_IS_TCHAR && !USE_SNPRINTF
+ /* Make room for the result. */
+ if (count > allocated - length)
+ {
+ /* Need at least count elements. But allocate
+ proportionally. */
+ size_t n =
+ xmax (xsum (length, count), xtimes (allocated, 2));
+
+ ENSURE_ALLOCATION (n);
+ }
+#endif
+
+ /* Here count <= allocated - length. */
+
+ /* Perform padding. */
+#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
+ if (pad_ourselves && has_width)
+ {
+ size_t w;
+# if ENABLE_UNISTDIO
+ /* Outside POSIX, it's preferable to compare the width
+ against the number of _characters_ of the converted
+ value. */
+ w = DCHAR_MBSNLEN (result + length, count);
+# else
+ /* The width is compared against the number of _bytes_
+ of the converted value, says POSIX. */
+ w = count;
+# endif
+ if (w < width)
+ {
+ size_t pad = width - w;
+
+ /* Make room for the result. */
+ if (xsum (count, pad) > allocated - length)
+ {
+ /* Need at least count + pad elements. But
+ allocate proportionally. */
+ size_t n =
+ xmax (xsum3 (length, count, pad),
+ xtimes (allocated, 2));
+
+# if USE_SNPRINTF
+ length += count;
+ ENSURE_ALLOCATION (n);
+ length -= count;
+# else
+ ENSURE_ALLOCATION (n);
+# endif
+ }
+ /* Here count + pad <= allocated - length. */
+
+ {
+# if !DCHAR_IS_TCHAR || USE_SNPRINTF
+ DCHAR_T * const rp = result + length;
+# else
+ DCHAR_T * const rp = tmp;
+# endif
+ DCHAR_T *p = rp + count;
+ DCHAR_T *end = p + pad;
+ DCHAR_T *pad_ptr;
+# if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO
+ if (dp->conversion == 'c'
+ || dp->conversion == 's')
+ /* No zero-padding for string directives. */
+ pad_ptr = NULL;
+ else
+# endif
+ {
+ pad_ptr = (*rp == '-' ? rp + 1 : rp);
+ /* No zero-padding of "inf" and "nan". */
+ if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z')
+ || (*pad_ptr >= 'a' && *pad_ptr <= 'z'))
+ pad_ptr = NULL;
+ }
+ /* The generated string now extends from rp to p,
+ with the zero padding insertion point being at
+ pad_ptr. */
+
+ count = count + pad; /* = end - rp */
+
+ if (flags & FLAG_LEFT)
+ {
+ /* Pad with spaces on the right. */
+ for (; pad > 0; pad--)
+ *p++ = ' ';
+ }
+ else if ((flags & FLAG_ZERO) && pad_ptr != NULL)
+ {
+ /* Pad with zeroes. */
+ DCHAR_T *q = end;
+
+ while (p > pad_ptr)
+ *--q = *--p;
+ for (; pad > 0; pad--)
+ *p++ = '0';
+ }
+ else
+ {
+ /* Pad with spaces on the left. */
+ DCHAR_T *q = end;
+
+ while (p > rp)
+ *--q = *--p;
+ for (; pad > 0; pad--)
+ *p++ = ' ';
+ }
+ }
+ }
+ }
+#endif
+
+ /* Here still count <= allocated - length. */
+
+#if !DCHAR_IS_TCHAR || USE_SNPRINTF
+ /* The snprintf() result did fit. */
+#else
+ /* Append the sprintf() result. */
+ memcpy (result + length, tmp, count * sizeof (DCHAR_T));
+#endif
+#if !USE_SNPRINTF
+ if (tmp != tmpbuf)
+ free (tmp);
+#endif
+
+#if NEED_PRINTF_DIRECTIVE_F
+ if (dp->conversion == 'F')
+ {
+ /* Convert the %f result to upper case for %F. */
+ DCHAR_T *rp = result + length;
+ size_t rc;
+ for (rc = count; rc > 0; rc--, rp++)
+ if (*rp >= 'a' && *rp <= 'z')
+ *rp = *rp - 'a' + 'A';
+ }
+#endif
+
+ length += count;
+ break;
+ }
+ errno = orig_errno;
+#undef pad_ourselves
+#undef prec_ourselves
+ }
+ }
+ }
+
+ /* Add the final NUL. */
+ ENSURE_ALLOCATION (xsum (length, 1));
+ result[length] = '\0';
+
+ if (result != resultbuf && length + 1 < allocated)
+ {
+ /* Shrink the allocated memory if possible. */
+ DCHAR_T *memory;
+
+ memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T));
+ if (memory != NULL)
+ result = memory;
+ }
+
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
+ *lengthp = length;
+ /* Note that we can produce a big string of a length > INT_MAX. POSIX
+ says that snprintf() fails with errno = EOVERFLOW in this case, but
+ that's only because snprintf() returns an 'int'. This function does
+ not have this limitation. */
+ return result;
+
+#if USE_SNPRINTF
+ overflow:
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ CLEANUP ();
#if (defined _MSC_VER) && (_MSC_VER < 1800)
#else
- errno = EOVERFLOW;
-#endif
- return NULL;
+ errno = EOVERFLOW;
#endif
-
- out_of_memory:
- if (!(result == resultbuf || result == NULL))
- free (result);
- if (buf_malloced != NULL)
- free (buf_malloced);
- out_of_memory_1:
- CLEANUP ();
- errno = ENOMEM;
- return NULL;
- }
-}
-
-#undef MAX_ROOM_NEEDED
-#undef TCHARS_PER_DCHAR
-#undef SNPRINTF
-#undef USE_SNPRINTF
-#undef DCHAR_SET
-#undef DCHAR_CPY
-#undef PRINTF_PARSE
-#undef DIRECTIVES
-#undef DIRECTIVE
-#undef DCHAR_IS_TCHAR
-#undef TCHAR_T
-#undef DCHAR_T
-#undef FCHAR_T
-#undef VASNPRINTF
+ return NULL;
+#endif
+
+ out_of_memory:
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ if (buf_malloced != NULL)
+ free (buf_malloced);
+ out_of_memory_1:
+ CLEANUP ();
+ errno = ENOMEM;
+ return NULL;
+ }
+}
+
+#undef MAX_ROOM_NEEDED
+#undef TCHARS_PER_DCHAR
+#undef SNPRINTF
+#undef USE_SNPRINTF
+#undef DCHAR_SET
+#undef DCHAR_CPY
+#undef PRINTF_PARSE
+#undef DIRECTIVES
+#undef DIRECTIVE
+#undef DCHAR_IS_TCHAR
+#undef TCHAR_T
+#undef DCHAR_T
+#undef FCHAR_T
+#undef VASNPRINTF
diff --git a/contrib/tools/bison/gnulib/src/vasnprintf.h b/contrib/tools/bison/gnulib/src/vasnprintf.h
index 7658f505e5..1bbb35dbf5 100644
--- a/contrib/tools/bison/gnulib/src/vasnprintf.h
+++ b/contrib/tools/bison/gnulib/src/vasnprintf.h
@@ -1,79 +1,79 @@
-/* vsprintf with automatic memory allocation.
- Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _VASNPRINTF_H
-#define _VASNPRINTF_H
-
-/* Get va_list. */
-#include <stdarg.h>
-
-/* Get size_t. */
-#include <stddef.h>
-
-/* The __attribute__ feature is available in gcc versions 2.5 and later.
- The __-protected variants of the attributes 'format' and 'printf' are
- accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
- gnulib and libintl do '#define printf __printf__' when they override
- the 'printf' function. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
-#else
-# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Write formatted output to a string dynamically allocated with malloc().
- You can pass a preallocated buffer for the result in RESULTBUF and its
- size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
- If successful, return the address of the string (this may be = RESULTBUF
- if no dynamic memory allocation was necessary) and set *LENGTHP to the
- number of resulting bytes, excluding the trailing NUL. Upon error, set
- errno and return NULL.
-
- When dynamic memory allocation occurs, the preallocated buffer is left
- alone (with possibly modified contents). This makes it possible to use
- a statically allocated or stack-allocated buffer, like this:
-
- char buf[100];
- size_t len = sizeof (buf);
- char *output = vasnprintf (buf, &len, format, args);
- if (output == NULL)
- ... error handling ...;
- else
- {
- ... use the output string ...;
- if (output != buf)
- free (output);
- }
- */
-#if REPLACE_VASNPRINTF
-# define asnprintf rpl_asnprintf
-# define vasnprintf rpl_vasnprintf
-#endif
-extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
-extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _VASNPRINTF_H */
+/* vsprintf with automatic memory allocation.
+ Copyright (C) 2002-2004, 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _VASNPRINTF_H
+#define _VASNPRINTF_H
+
+/* Get va_list. */
+#include <stdarg.h>
+
+/* Get size_t. */
+#include <stddef.h>
+
+/* The __attribute__ feature is available in gcc versions 2.5 and later.
+ The __-protected variants of the attributes 'format' and 'printf' are
+ accepted by gcc versions 2.6.4 (effectively 2.7) and later.
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
+ gnulib and libintl do '#define printf __printf__' when they override
+ the 'printf' function. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+#else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Write formatted output to a string dynamically allocated with malloc().
+ You can pass a preallocated buffer for the result in RESULTBUF and its
+ size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
+ If successful, return the address of the string (this may be = RESULTBUF
+ if no dynamic memory allocation was necessary) and set *LENGTHP to the
+ number of resulting bytes, excluding the trailing NUL. Upon error, set
+ errno and return NULL.
+
+ When dynamic memory allocation occurs, the preallocated buffer is left
+ alone (with possibly modified contents). This makes it possible to use
+ a statically allocated or stack-allocated buffer, like this:
+
+ char buf[100];
+ size_t len = sizeof (buf);
+ char *output = vasnprintf (buf, &len, format, args);
+ if (output == NULL)
+ ... error handling ...;
+ else
+ {
+ ... use the output string ...;
+ if (output != buf)
+ free (output);
+ }
+ */
+#if REPLACE_VASNPRINTF
+# define asnprintf rpl_asnprintf
+# define vasnprintf rpl_vasnprintf
+#endif
+extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
+extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _VASNPRINTF_H */
diff --git a/contrib/tools/bison/gnulib/src/vasprintf.c b/contrib/tools/bison/gnulib/src/vasprintf.c
index afc8056194..72553ed386 100644
--- a/contrib/tools/bison/gnulib/src/vasprintf.c
+++ b/contrib/tools/bison/gnulib/src/vasprintf.c
@@ -1,53 +1,53 @@
-/* Formatted output to strings.
- Copyright (C) 1999, 2002, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#ifdef IN_LIBASPRINTF
-# include "vasprintf.h"
-#else
-# include <stdio.h>
-#endif
-
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-
-#include "vasnprintf.h"
-
-int
-vasprintf (char **resultp, const char *format, va_list args)
-{
- size_t length;
- char *result = vasnprintf (NULL, &length, format, args);
- if (result == NULL)
- return -1;
-
- if (length > INT_MAX)
- {
- free (result);
+/* Formatted output to strings.
+ Copyright (C) 1999, 2002, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#ifdef IN_LIBASPRINTF
+# include "vasprintf.h"
+#else
+# include <stdio.h>
+#endif
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "vasnprintf.h"
+
+int
+vasprintf (char **resultp, const char *format, va_list args)
+{
+ size_t length;
+ char *result = vasnprintf (NULL, &length, format, args);
+ if (result == NULL)
+ return -1;
+
+ if (length > INT_MAX)
+ {
+ free (result);
#if (defined _MSC_VER) && (_MSC_VER < 1800)
#else
- errno = EOVERFLOW;
+ errno = EOVERFLOW;
#endif
- return -1;
- }
-
- *resultp = result;
- /* Return the number of resulting bytes, excluding the trailing NUL. */
- return length;
-}
+ return -1;
+ }
+
+ *resultp = result;
+ /* Return the number of resulting bytes, excluding the trailing NUL. */
+ return length;
+}
diff --git a/contrib/tools/bison/gnulib/src/vbitset.c b/contrib/tools/bison/gnulib/src/vbitset.c
index e7200cdaa5..dd79fdab7c 100644
--- a/contrib/tools/bison/gnulib/src/vbitset.c
+++ b/contrib/tools/bison/gnulib/src/vbitset.c
@@ -1,1140 +1,1140 @@
-/* Variable array bitsets.
-
- Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "vbitset.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-/* This file implements variable size bitsets stored as a variable
- length array of words. Any unused bits in the last word must be
- zero.
-
- Note that binary or ternary operations assume that each bitset operand
- has the same size.
-*/
-
-static void vbitset_unused_clear (bitset);
-
-static void vbitset_set (bitset, bitset_bindex);
-static void vbitset_reset (bitset, bitset_bindex);
-static bool vbitset_test (bitset, bitset_bindex);
-static bitset_bindex vbitset_list (bitset, bitset_bindex *,
- bitset_bindex, bitset_bindex *);
-static bitset_bindex vbitset_list_reverse (bitset, bitset_bindex *,
- bitset_bindex, bitset_bindex *);
-
-#define VBITSET_N_WORDS(N) (((N) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
-#define VBITSET_WORDS(X) ((X)->b.cdata)
-#define VBITSET_SIZE(X) ((X)->b.csize)
-#define VBITSET_ASIZE(X) ((X)->v.size)
-
-#undef min
-#undef max
-#define min(a, b) ((a) > (b) ? (b) : (a))
-#define max(a, b) ((a) > (b) ? (a) : (b))
-
-static bitset_bindex
-vbitset_resize (bitset src, bitset_bindex n_bits)
-{
- bitset_windex oldsize;
- bitset_windex newsize;
-
- if (n_bits == BITSET_NBITS_ (src))
- return n_bits;
-
- oldsize = VBITSET_SIZE (src);
- newsize = VBITSET_N_WORDS (n_bits);
-
- if (oldsize < newsize)
- {
- bitset_windex size;
-
- /* The bitset needs to grow. If we already have enough memory
- allocated, then just zero what we need. */
- if (newsize > VBITSET_ASIZE (src))
- {
- /* We need to allocate more memory. When oldsize is
- non-zero this means that we are changing the size, so
- grow the bitset 25% larger than requested to reduce
- number of reallocations. */
-
- if (oldsize == 0)
- size = newsize;
- else
- size = newsize + newsize / 4;
-
- VBITSET_WORDS (src)
- = realloc (VBITSET_WORDS (src), size * sizeof (bitset_word));
- VBITSET_ASIZE (src) = size;
- }
-
- memset (VBITSET_WORDS (src) + oldsize, 0,
- (newsize - oldsize) * sizeof (bitset_word));
- VBITSET_SIZE (src) = newsize;
- }
- else
- {
- /* The bitset needs to shrink. There's no point deallocating
- the memory unless it is shrinking by a reasonable amount. */
- if ((oldsize - newsize) >= oldsize / 2)
- {
- VBITSET_WORDS (src)
- = realloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word));
- VBITSET_ASIZE (src) = newsize;
- }
-
- /* Need to prune any excess bits. FIXME. */
-
- VBITSET_SIZE (src) = newsize;
- }
-
- BITSET_NBITS_ (src) = n_bits;
- return n_bits;
-}
-
-
-/* Set bit BITNO in bitset DST. */
-static void
-vbitset_set (dst, bitno)
- bitset dst;
- bitset_bindex bitno;
-{
- bitset_windex windex = bitno / BITSET_WORD_BITS;
-
- /* Perhaps we should abort. The user should explicitly call
- bitset_resize since this will not catch the case when we set a
- bit larger than the current size but smaller than the allocated
- size. */
- vbitset_resize (dst, bitno);
-
- dst->b.cdata[windex - dst->b.cindex] |=
- (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
-}
-
-
-/* Reset bit BITNO in bitset DST. */
-static void
-vbitset_reset (dst, bitno)
- bitset dst ATTRIBUTE_UNUSED;
- bitset_bindex bitno ATTRIBUTE_UNUSED;
-{
- /* We must be accessing outside the cache so the bit is
- zero anyway. */
-}
-
-
-/* Test bit BITNO in bitset SRC. */
-static bool
-vbitset_test (src, bitno)
- bitset src ATTRIBUTE_UNUSED;
- bitset_bindex bitno ATTRIBUTE_UNUSED;
-{
- /* We must be accessing outside the cache so the bit is
- zero anyway. */
- return 0;
-}
-
-
-/* Find list of up to NUM bits set in BSET in reverse order, starting
- from and including NEXT and store in array LIST. Return with
- actual number of bits found and with *NEXT indicating where search
- stopped. */
-static bitset_bindex
-vbitset_list_reverse (src, list, num, next)
- bitset src;
- bitset_bindex *list;
- bitset_bindex num;
- bitset_bindex *next;
-{
- bitset_bindex bitno;
- bitset_bindex rbitno;
- bitset_bindex count;
- bitset_windex windex;
- unsigned int bitcnt;
- bitset_bindex bitoff;
- bitset_word *srcp = VBITSET_WORDS (src);
- bitset_bindex n_bits = BITSET_SIZE_ (src);
-
- rbitno = *next;
-
- /* If num is 1, we could speed things up with a binary search
- of the word of interest. */
-
- if (rbitno >= n_bits)
- return 0;
-
- count = 0;
-
- bitno = n_bits - (rbitno + 1);
-
- windex = bitno / BITSET_WORD_BITS;
- bitcnt = bitno % BITSET_WORD_BITS;
- bitoff = windex * BITSET_WORD_BITS;
-
- do
- {
- bitset_word word;
-
- word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt);
- for (; word; bitcnt--)
- {
- if (word & BITSET_MSB)
- {
- list[count++] = bitoff + bitcnt;
- if (count >= num)
- {
- *next = n_bits - (bitoff + bitcnt);
- return count;
- }
- }
- word <<= 1;
- }
- bitoff -= BITSET_WORD_BITS;
- bitcnt = BITSET_WORD_BITS - 1;
- }
- while (windex--);
-
- *next = n_bits - (bitoff + 1);
- return count;
-}
-
-
-/* Find list of up to NUM bits set in BSET starting from and including
- *NEXT and store in array LIST. Return with actual number of bits
- found and with *NEXT indicating where search stopped. */
-static bitset_bindex
-vbitset_list (src, list, num, next)
- bitset src;
- bitset_bindex *list;
- bitset_bindex num;
- bitset_bindex *next;
-{
- bitset_bindex bitno;
- bitset_bindex count;
- bitset_windex windex;
- bitset_bindex bitoff;
- bitset_windex size = VBITSET_SIZE (src);
- bitset_word *srcp = VBITSET_WORDS (src);
- bitset_word word;
-
- bitno = *next;
-
- count = 0;
- if (!bitno)
- {
- /* Many bitsets are zero, so make this common case fast. */
- for (windex = 0; windex < size && !srcp[windex]; windex++)
- continue;
- if (windex >= size)
- return 0;
-
- /* If num is 1, we could speed things up with a binary search
- of the current word. */
-
- bitoff = windex * BITSET_WORD_BITS;
- }
- else
- {
- if (bitno >= BITSET_SIZE_ (src))
- return 0;
-
- windex = bitno / BITSET_WORD_BITS;
- bitno = bitno % BITSET_WORD_BITS;
-
- if (bitno)
- {
- /* Handle the case where we start within a word.
- Most often, this is executed with large bitsets
- with many set bits where we filled the array
- on the previous call to this function. */
-
- bitoff = windex * BITSET_WORD_BITS;
- word = srcp[windex] >> bitno;
- for (bitno = bitoff + bitno; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- windex++;
- }
- bitoff = windex * BITSET_WORD_BITS;
- }
-
- for (; windex < size; windex++, bitoff += BITSET_WORD_BITS)
- {
- if (!(word = srcp[windex]))
- continue;
-
- if ((count + BITSET_WORD_BITS) < num)
- {
- for (bitno = bitoff; word; bitno++)
- {
- if (word & 1)
- list[count++] = bitno;
- word >>= 1;
- }
- }
- else
- {
- for (bitno = bitoff; word; bitno++)
- {
- if (word & 1)
- {
- list[count++] = bitno;
- if (count >= num)
- {
- *next = bitno + 1;
- return count;
- }
- }
- word >>= 1;
- }
- }
- }
-
- *next = bitoff;
- return count;
-}
-
-
-/* Ensure that any unused bits within the last word are clear. */
-static inline void
-vbitset_unused_clear (dst)
- bitset dst;
-{
- unsigned int last_bit;
-
- last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS;
- if (last_bit)
- VBITSET_WORDS (dst)[VBITSET_SIZE (dst) - 1] &=
- ((bitset_word) 1 << last_bit) - 1;
-}
-
-
-static void
-vbitset_ones (bitset dst)
-{
- bitset_word *dstp = VBITSET_WORDS (dst);
- unsigned int bytes;
-
- bytes = sizeof (bitset_word) * VBITSET_SIZE (dst);
-
- memset (dstp, -1, bytes);
- vbitset_unused_clear (dst);
-}
-
-
-static void
-vbitset_zero (bitset dst)
-{
- bitset_word *dstp = VBITSET_WORDS (dst);
- unsigned int bytes;
-
- bytes = sizeof (bitset_word) * VBITSET_SIZE (dst);
-
- memset (dstp, 0, bytes);
-}
-
-
-static bool
-vbitset_empty_p (bitset dst)
-{
- unsigned int i;
- bitset_word *dstp = VBITSET_WORDS (dst);
-
- for (i = 0; i < VBITSET_SIZE (dst); i++)
- if (dstp[i])
- return 0;
-
- return 1;
-}
-
-
-static void
-vbitset_copy1 (bitset dst, bitset src)
-{
- bitset_word *srcp;
- bitset_word *dstp;
- bitset_windex ssize;
- bitset_windex dsize;
-
- if (src == dst)
- return;
-
- vbitset_resize (dst, BITSET_SIZE_ (src));
-
- srcp = VBITSET_WORDS (src);
- dstp = VBITSET_WORDS (dst);
- ssize = VBITSET_SIZE (src);
- dsize = VBITSET_SIZE (dst);
-
- memcpy (dstp, srcp, sizeof (bitset_word) * ssize);
-
- memset (dstp + sizeof (bitset_word) * ssize, 0,
- sizeof (bitset_word) * (dsize - ssize));
-}
-
-
-static void
-vbitset_not (bitset dst, bitset src)
-{
- unsigned int i;
- bitset_word *srcp;
- bitset_word *dstp;
- bitset_windex ssize;
- bitset_windex dsize;
-
- vbitset_resize (dst, BITSET_SIZE_ (src));
-
- srcp = VBITSET_WORDS (src);
- dstp = VBITSET_WORDS (dst);
- ssize = VBITSET_SIZE (src);
- dsize = VBITSET_SIZE (dst);
-
- for (i = 0; i < ssize; i++)
- *dstp++ = ~(*srcp++);
-
- vbitset_unused_clear (dst);
- memset (dstp + sizeof (bitset_word) * ssize, 0,
- sizeof (bitset_word) * (dsize - ssize));
-}
-
-
-static bool
-vbitset_equal_p (bitset dst, bitset src)
-{
- unsigned int i;
- bitset_word *srcp = VBITSET_WORDS (src);
- bitset_word *dstp = VBITSET_WORDS (dst);
- bitset_windex ssize = VBITSET_SIZE (src);
- bitset_windex dsize = VBITSET_SIZE (dst);
-
- for (i = 0; i < min (ssize, dsize); i++)
- if (*srcp++ != *dstp++)
- return 0;
-
- if (ssize > dsize)
- {
- for (; i < ssize; i++)
- if (*srcp++)
- return 0;
- }
- else
- {
- for (; i < dsize; i++)
- if (*dstp++)
- return 0;
- }
-
- return 1;
-}
-
-
-static bool
-vbitset_subset_p (bitset dst, bitset src)
-{
- unsigned int i;
- bitset_word *srcp = VBITSET_WORDS (src);
- bitset_word *dstp = VBITSET_WORDS (dst);
- bitset_windex ssize = VBITSET_SIZE (src);
- bitset_windex dsize = VBITSET_SIZE (dst);
-
- for (i = 0; i < min (ssize, dsize); i++, dstp++, srcp++)
- if (*dstp != (*srcp | *dstp))
- return 0;
-
- if (ssize > dsize)
- {
- for (; i < ssize; i++)
- if (*srcp++)
- return 0;
- }
-
- return 1;
-}
-
-
-static bool
-vbitset_disjoint_p (bitset dst, bitset src)
-{
- unsigned int i;
- bitset_word *srcp = VBITSET_WORDS (src);
- bitset_word *dstp = VBITSET_WORDS (dst);
- bitset_windex ssize = VBITSET_SIZE (src);
- bitset_windex dsize = VBITSET_SIZE (dst);
-
- for (i = 0; i < min (ssize, dsize); i++)
- if (*srcp++ & *dstp++)
- return 0;
-
- return 1;
-}
-
-
-static void
-vbitset_and (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++)
- *dstp++ = *src1p++ & *src2p++;
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - min (ssize1, ssize2)));
-}
-
-
-static bool
-vbitset_and_cmp (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- int changed = 0;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
- {
- bitset_word tmp = *src1p++ & *src2p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
-
- if (ssize2 > ssize1)
- {
- src1p = src2p;
- ssize1 = ssize2;
- }
-
- for (; i < ssize1; i++, dstp++)
- {
- if (*dstp != 0)
- {
- changed = 1;
- *dstp = 0;
- }
- }
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
-
- return changed;
-}
-
-
-static void
-vbitset_andn (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++)
- *dstp++ = *src1p++ & ~(*src2p++);
-
- if (ssize2 > ssize1)
- {
- for (; i < ssize2; i++)
- *dstp++ = 0;
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize2));
- }
- else
- {
- for (; i < ssize1; i++)
- *dstp++ = *src1p++;
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
- }
-}
-
-
-static bool
-vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- int changed = 0;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
- {
- bitset_word tmp = *src1p++ & ~(*src2p++);
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
-
- if (ssize2 > ssize1)
- {
- for (; i < ssize2; i++, dstp++)
- {
- if (*dstp != 0)
- {
- changed = 1;
- *dstp = 0;
- }
- }
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize2));
- }
- else
- {
- for (; i < ssize1; i++, dstp++)
- {
- bitset_word tmp = *src1p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
- }
-
- return changed;
-}
-
-
-static void
-vbitset_or (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++)
- *dstp++ = *src1p++ | *src2p++;
-
- if (ssize2 > ssize1)
- {
- src1p = src2p;
- ssize1 = ssize2;
- }
-
- for (; i < ssize1; i++)
- *dstp++ = *src1p++;
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
-}
-
-
-static bool
-vbitset_or_cmp (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- int changed = 0;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
- {
- bitset_word tmp = *src1p++ | *src2p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
-
- if (ssize2 > ssize1)
- {
- src1p = src2p;
- ssize1 = ssize2;
- }
-
- for (; i < ssize1; i++, dstp++)
- {
- bitset_word tmp = *src1p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
-
- return changed;
-}
-
-
-static void
-vbitset_xor (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++)
- *dstp++ = *src1p++ ^ *src2p++;
-
- if (ssize2 > ssize1)
- {
- src1p = src2p;
- ssize1 = ssize2;
- }
-
- for (; i < ssize1; i++)
- *dstp++ = *src1p++;
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
-}
-
-
-static bool
-vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
-{
- unsigned int i;
- int changed = 0;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *dstp;
- bitset_windex ssize1;
- bitset_windex ssize2;
- bitset_windex dsize;
-
- vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
-
- dsize = VBITSET_SIZE (dst);
- ssize1 = VBITSET_SIZE (src1);
- ssize2 = VBITSET_SIZE (src2);
- dstp = VBITSET_WORDS (dst);
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
-
- for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
- {
- bitset_word tmp = *src1p++ ^ *src2p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
-
- if (ssize2 > ssize1)
- {
- src1p = src2p;
- ssize1 = ssize2;
- }
-
- for (; i < ssize1; i++, dstp++)
- {
- bitset_word tmp = *src1p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
-
- memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
-
- return changed;
-}
-
-
-/* FIXME, these operations need fixing for different size
- bitsets. */
-
-static void
-vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- unsigned int i;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *src3p;
- bitset_word *dstp;
- bitset_windex size;
-
- if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
- || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
- {
- bitset_and_or_ (dst, src1, src2, src3);
- return;
- }
-
- vbitset_resize (dst, BITSET_NBITS_ (src1));
-
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
- src3p = VBITSET_WORDS (src3);
- dstp = VBITSET_WORDS (dst);
- size = VBITSET_SIZE (dst);
-
- for (i = 0; i < size; i++)
- *dstp++ = (*src1p++ & *src2p++) | *src3p++;
-}
-
-
-static bool
-vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- unsigned int i;
- int changed = 0;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *src3p;
- bitset_word *dstp;
- bitset_windex size;
-
- if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
- || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
- return bitset_and_or_cmp_ (dst, src1, src2, src3);
-
- vbitset_resize (dst, BITSET_NBITS_ (src1));
-
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
- src3p = VBITSET_WORDS (src3);
- dstp = VBITSET_WORDS (dst);
- size = VBITSET_SIZE (dst);
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = (*src1p++ & *src2p++) | *src3p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- unsigned int i;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *src3p;
- bitset_word *dstp;
- bitset_windex size;
-
- if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
- || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
- {
- bitset_andn_or_ (dst, src1, src2, src3);
- return;
- }
-
- vbitset_resize (dst, BITSET_NBITS_ (src1));
-
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
- src3p = VBITSET_WORDS (src3);
- dstp = VBITSET_WORDS (dst);
- size = VBITSET_SIZE (dst);
-
- for (i = 0; i < size; i++)
- *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++;
-}
-
-
-static bool
-vbitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- unsigned int i;
- int changed = 0;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *src3p;
- bitset_word *dstp;
- bitset_windex size;
-
- if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
- || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
- return bitset_andn_or_cmp_ (dst, src1, src2, src3);
-
- vbitset_resize (dst, BITSET_NBITS_ (src1));
-
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
- src3p = VBITSET_WORDS (src3);
- dstp = VBITSET_WORDS (dst);
- size = VBITSET_SIZE (dst);
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-vbitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- unsigned int i;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *src3p;
- bitset_word *dstp;
- bitset_windex size;
-
- if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
- || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
- {
- bitset_or_and_ (dst, src1, src2, src3);
- return;
- }
-
- vbitset_resize (dst, BITSET_NBITS_ (src1));
-
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
- src3p = VBITSET_WORDS (src3);
- dstp = VBITSET_WORDS (dst);
- size = VBITSET_SIZE (dst);
-
- for (i = 0; i < size; i++)
- *dstp++ = (*src1p++ | *src2p++) & *src3p++;
-}
-
-
-static bool
-vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
-{
- unsigned int i;
- int changed = 0;
- bitset_word *src1p;
- bitset_word *src2p;
- bitset_word *src3p;
- bitset_word *dstp;
- bitset_windex size;
-
- if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
- || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
- return bitset_or_and_cmp_ (dst, src1, src2, src3);
-
- vbitset_resize (dst, BITSET_NBITS_ (src1));
-
- src1p = VBITSET_WORDS (src1);
- src2p = VBITSET_WORDS (src2);
- src3p = VBITSET_WORDS (src3);
- dstp = VBITSET_WORDS (dst);
- size = VBITSET_SIZE (dst);
-
- for (i = 0; i < size; i++, dstp++)
- {
- bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
-
- if (*dstp != tmp)
- {
- changed = 1;
- *dstp = tmp;
- }
- }
- return changed;
-}
-
-
-static void
-vbitset_copy (bitset dst, bitset src)
-{
- if (BITSET_COMPATIBLE_ (dst, src))
- vbitset_copy1 (dst, src);
- else
- bitset_copy_ (dst, src);
-}
-
-
-/* Vector of operations for multiple word bitsets. */
-struct bitset_vtable vbitset_vtable = {
- vbitset_set,
- vbitset_reset,
- bitset_toggle_,
- vbitset_test,
- vbitset_resize,
- bitset_size_,
- bitset_count_,
- vbitset_empty_p,
- vbitset_ones,
- vbitset_zero,
- vbitset_copy,
- vbitset_disjoint_p,
- vbitset_equal_p,
- vbitset_not,
- vbitset_subset_p,
- vbitset_and,
- vbitset_and_cmp,
- vbitset_andn,
- vbitset_andn_cmp,
- vbitset_or,
- vbitset_or_cmp,
- vbitset_xor,
- vbitset_xor_cmp,
- vbitset_and_or,
- vbitset_and_or_cmp,
- vbitset_andn_or,
- vbitset_andn_or_cmp,
- vbitset_or_and,
- vbitset_or_and_cmp,
- vbitset_list,
- vbitset_list_reverse,
- NULL,
- BITSET_VARRAY
-};
-
-
-size_t
-vbitset_bytes (n_bits)
- bitset_bindex n_bits ATTRIBUTE_UNUSED;
-{
- return sizeof (struct vbitset_struct);
-}
-
-
-bitset
-vbitset_init (bset, n_bits)
- bitset bset;
- bitset_bindex n_bits;
-{
- bset->b.vtable = &vbitset_vtable;
-
- bset->b.cindex = 0;
-
- VBITSET_SIZE (bset) = 0;
- vbitset_resize (bset, n_bits);
- return bset;
-}
+/* Variable array bitsets.
+
+ Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "vbitset.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/* This file implements variable size bitsets stored as a variable
+ length array of words. Any unused bits in the last word must be
+ zero.
+
+ Note that binary or ternary operations assume that each bitset operand
+ has the same size.
+*/
+
+static void vbitset_unused_clear (bitset);
+
+static void vbitset_set (bitset, bitset_bindex);
+static void vbitset_reset (bitset, bitset_bindex);
+static bool vbitset_test (bitset, bitset_bindex);
+static bitset_bindex vbitset_list (bitset, bitset_bindex *,
+ bitset_bindex, bitset_bindex *);
+static bitset_bindex vbitset_list_reverse (bitset, bitset_bindex *,
+ bitset_bindex, bitset_bindex *);
+
+#define VBITSET_N_WORDS(N) (((N) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
+#define VBITSET_WORDS(X) ((X)->b.cdata)
+#define VBITSET_SIZE(X) ((X)->b.csize)
+#define VBITSET_ASIZE(X) ((X)->v.size)
+
+#undef min
+#undef max
+#define min(a, b) ((a) > (b) ? (b) : (a))
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+static bitset_bindex
+vbitset_resize (bitset src, bitset_bindex n_bits)
+{
+ bitset_windex oldsize;
+ bitset_windex newsize;
+
+ if (n_bits == BITSET_NBITS_ (src))
+ return n_bits;
+
+ oldsize = VBITSET_SIZE (src);
+ newsize = VBITSET_N_WORDS (n_bits);
+
+ if (oldsize < newsize)
+ {
+ bitset_windex size;
+
+ /* The bitset needs to grow. If we already have enough memory
+ allocated, then just zero what we need. */
+ if (newsize > VBITSET_ASIZE (src))
+ {
+ /* We need to allocate more memory. When oldsize is
+ non-zero this means that we are changing the size, so
+ grow the bitset 25% larger than requested to reduce
+ number of reallocations. */
+
+ if (oldsize == 0)
+ size = newsize;
+ else
+ size = newsize + newsize / 4;
+
+ VBITSET_WORDS (src)
+ = realloc (VBITSET_WORDS (src), size * sizeof (bitset_word));
+ VBITSET_ASIZE (src) = size;
+ }
+
+ memset (VBITSET_WORDS (src) + oldsize, 0,
+ (newsize - oldsize) * sizeof (bitset_word));
+ VBITSET_SIZE (src) = newsize;
+ }
+ else
+ {
+ /* The bitset needs to shrink. There's no point deallocating
+ the memory unless it is shrinking by a reasonable amount. */
+ if ((oldsize - newsize) >= oldsize / 2)
+ {
+ VBITSET_WORDS (src)
+ = realloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word));
+ VBITSET_ASIZE (src) = newsize;
+ }
+
+ /* Need to prune any excess bits. FIXME. */
+
+ VBITSET_SIZE (src) = newsize;
+ }
+
+ BITSET_NBITS_ (src) = n_bits;
+ return n_bits;
+}
+
+
+/* Set bit BITNO in bitset DST. */
+static void
+vbitset_set (dst, bitno)
+ bitset dst;
+ bitset_bindex bitno;
+{
+ bitset_windex windex = bitno / BITSET_WORD_BITS;
+
+ /* Perhaps we should abort. The user should explicitly call
+ bitset_resize since this will not catch the case when we set a
+ bit larger than the current size but smaller than the allocated
+ size. */
+ vbitset_resize (dst, bitno);
+
+ dst->b.cdata[windex - dst->b.cindex] |=
+ (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
+}
+
+
+/* Reset bit BITNO in bitset DST. */
+static void
+vbitset_reset (dst, bitno)
+ bitset dst ATTRIBUTE_UNUSED;
+ bitset_bindex bitno ATTRIBUTE_UNUSED;
+{
+ /* We must be accessing outside the cache so the bit is
+ zero anyway. */
+}
+
+
+/* Test bit BITNO in bitset SRC. */
+static bool
+vbitset_test (src, bitno)
+ bitset src ATTRIBUTE_UNUSED;
+ bitset_bindex bitno ATTRIBUTE_UNUSED;
+{
+ /* We must be accessing outside the cache so the bit is
+ zero anyway. */
+ return 0;
+}
+
+
+/* Find list of up to NUM bits set in BSET in reverse order, starting
+ from and including NEXT and store in array LIST. Return with
+ actual number of bits found and with *NEXT indicating where search
+ stopped. */
+static bitset_bindex
+vbitset_list_reverse (src, list, num, next)
+ bitset src;
+ bitset_bindex *list;
+ bitset_bindex num;
+ bitset_bindex *next;
+{
+ bitset_bindex bitno;
+ bitset_bindex rbitno;
+ bitset_bindex count;
+ bitset_windex windex;
+ unsigned int bitcnt;
+ bitset_bindex bitoff;
+ bitset_word *srcp = VBITSET_WORDS (src);
+ bitset_bindex n_bits = BITSET_SIZE_ (src);
+
+ rbitno = *next;
+
+ /* If num is 1, we could speed things up with a binary search
+ of the word of interest. */
+
+ if (rbitno >= n_bits)
+ return 0;
+
+ count = 0;
+
+ bitno = n_bits - (rbitno + 1);
+
+ windex = bitno / BITSET_WORD_BITS;
+ bitcnt = bitno % BITSET_WORD_BITS;
+ bitoff = windex * BITSET_WORD_BITS;
+
+ do
+ {
+ bitset_word word;
+
+ word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt);
+ for (; word; bitcnt--)
+ {
+ if (word & BITSET_MSB)
+ {
+ list[count++] = bitoff + bitcnt;
+ if (count >= num)
+ {
+ *next = n_bits - (bitoff + bitcnt);
+ return count;
+ }
+ }
+ word <<= 1;
+ }
+ bitoff -= BITSET_WORD_BITS;
+ bitcnt = BITSET_WORD_BITS - 1;
+ }
+ while (windex--);
+
+ *next = n_bits - (bitoff + 1);
+ return count;
+}
+
+
+/* Find list of up to NUM bits set in BSET starting from and including
+ *NEXT and store in array LIST. Return with actual number of bits
+ found and with *NEXT indicating where search stopped. */
+static bitset_bindex
+vbitset_list (src, list, num, next)
+ bitset src;
+ bitset_bindex *list;
+ bitset_bindex num;
+ bitset_bindex *next;
+{
+ bitset_bindex bitno;
+ bitset_bindex count;
+ bitset_windex windex;
+ bitset_bindex bitoff;
+ bitset_windex size = VBITSET_SIZE (src);
+ bitset_word *srcp = VBITSET_WORDS (src);
+ bitset_word word;
+
+ bitno = *next;
+
+ count = 0;
+ if (!bitno)
+ {
+ /* Many bitsets are zero, so make this common case fast. */
+ for (windex = 0; windex < size && !srcp[windex]; windex++)
+ continue;
+ if (windex >= size)
+ return 0;
+
+ /* If num is 1, we could speed things up with a binary search
+ of the current word. */
+
+ bitoff = windex * BITSET_WORD_BITS;
+ }
+ else
+ {
+ if (bitno >= BITSET_SIZE_ (src))
+ return 0;
+
+ windex = bitno / BITSET_WORD_BITS;
+ bitno = bitno % BITSET_WORD_BITS;
+
+ if (bitno)
+ {
+ /* Handle the case where we start within a word.
+ Most often, this is executed with large bitsets
+ with many set bits where we filled the array
+ on the previous call to this function. */
+
+ bitoff = windex * BITSET_WORD_BITS;
+ word = srcp[windex] >> bitno;
+ for (bitno = bitoff + bitno; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ windex++;
+ }
+ bitoff = windex * BITSET_WORD_BITS;
+ }
+
+ for (; windex < size; windex++, bitoff += BITSET_WORD_BITS)
+ {
+ if (!(word = srcp[windex]))
+ continue;
+
+ if ((count + BITSET_WORD_BITS) < num)
+ {
+ for (bitno = bitoff; word; bitno++)
+ {
+ if (word & 1)
+ list[count++] = bitno;
+ word >>= 1;
+ }
+ }
+ else
+ {
+ for (bitno = bitoff; word; bitno++)
+ {
+ if (word & 1)
+ {
+ list[count++] = bitno;
+ if (count >= num)
+ {
+ *next = bitno + 1;
+ return count;
+ }
+ }
+ word >>= 1;
+ }
+ }
+ }
+
+ *next = bitoff;
+ return count;
+}
+
+
+/* Ensure that any unused bits within the last word are clear. */
+static inline void
+vbitset_unused_clear (dst)
+ bitset dst;
+{
+ unsigned int last_bit;
+
+ last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS;
+ if (last_bit)
+ VBITSET_WORDS (dst)[VBITSET_SIZE (dst) - 1] &=
+ ((bitset_word) 1 << last_bit) - 1;
+}
+
+
+static void
+vbitset_ones (bitset dst)
+{
+ bitset_word *dstp = VBITSET_WORDS (dst);
+ unsigned int bytes;
+
+ bytes = sizeof (bitset_word) * VBITSET_SIZE (dst);
+
+ memset (dstp, -1, bytes);
+ vbitset_unused_clear (dst);
+}
+
+
+static void
+vbitset_zero (bitset dst)
+{
+ bitset_word *dstp = VBITSET_WORDS (dst);
+ unsigned int bytes;
+
+ bytes = sizeof (bitset_word) * VBITSET_SIZE (dst);
+
+ memset (dstp, 0, bytes);
+}
+
+
+static bool
+vbitset_empty_p (bitset dst)
+{
+ unsigned int i;
+ bitset_word *dstp = VBITSET_WORDS (dst);
+
+ for (i = 0; i < VBITSET_SIZE (dst); i++)
+ if (dstp[i])
+ return 0;
+
+ return 1;
+}
+
+
+static void
+vbitset_copy1 (bitset dst, bitset src)
+{
+ bitset_word *srcp;
+ bitset_word *dstp;
+ bitset_windex ssize;
+ bitset_windex dsize;
+
+ if (src == dst)
+ return;
+
+ vbitset_resize (dst, BITSET_SIZE_ (src));
+
+ srcp = VBITSET_WORDS (src);
+ dstp = VBITSET_WORDS (dst);
+ ssize = VBITSET_SIZE (src);
+ dsize = VBITSET_SIZE (dst);
+
+ memcpy (dstp, srcp, sizeof (bitset_word) * ssize);
+
+ memset (dstp + sizeof (bitset_word) * ssize, 0,
+ sizeof (bitset_word) * (dsize - ssize));
+}
+
+
+static void
+vbitset_not (bitset dst, bitset src)
+{
+ unsigned int i;
+ bitset_word *srcp;
+ bitset_word *dstp;
+ bitset_windex ssize;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, BITSET_SIZE_ (src));
+
+ srcp = VBITSET_WORDS (src);
+ dstp = VBITSET_WORDS (dst);
+ ssize = VBITSET_SIZE (src);
+ dsize = VBITSET_SIZE (dst);
+
+ for (i = 0; i < ssize; i++)
+ *dstp++ = ~(*srcp++);
+
+ vbitset_unused_clear (dst);
+ memset (dstp + sizeof (bitset_word) * ssize, 0,
+ sizeof (bitset_word) * (dsize - ssize));
+}
+
+
+static bool
+vbitset_equal_p (bitset dst, bitset src)
+{
+ unsigned int i;
+ bitset_word *srcp = VBITSET_WORDS (src);
+ bitset_word *dstp = VBITSET_WORDS (dst);
+ bitset_windex ssize = VBITSET_SIZE (src);
+ bitset_windex dsize = VBITSET_SIZE (dst);
+
+ for (i = 0; i < min (ssize, dsize); i++)
+ if (*srcp++ != *dstp++)
+ return 0;
+
+ if (ssize > dsize)
+ {
+ for (; i < ssize; i++)
+ if (*srcp++)
+ return 0;
+ }
+ else
+ {
+ for (; i < dsize; i++)
+ if (*dstp++)
+ return 0;
+ }
+
+ return 1;
+}
+
+
+static bool
+vbitset_subset_p (bitset dst, bitset src)
+{
+ unsigned int i;
+ bitset_word *srcp = VBITSET_WORDS (src);
+ bitset_word *dstp = VBITSET_WORDS (dst);
+ bitset_windex ssize = VBITSET_SIZE (src);
+ bitset_windex dsize = VBITSET_SIZE (dst);
+
+ for (i = 0; i < min (ssize, dsize); i++, dstp++, srcp++)
+ if (*dstp != (*srcp | *dstp))
+ return 0;
+
+ if (ssize > dsize)
+ {
+ for (; i < ssize; i++)
+ if (*srcp++)
+ return 0;
+ }
+
+ return 1;
+}
+
+
+static bool
+vbitset_disjoint_p (bitset dst, bitset src)
+{
+ unsigned int i;
+ bitset_word *srcp = VBITSET_WORDS (src);
+ bitset_word *dstp = VBITSET_WORDS (dst);
+ bitset_windex ssize = VBITSET_SIZE (src);
+ bitset_windex dsize = VBITSET_SIZE (dst);
+
+ for (i = 0; i < min (ssize, dsize); i++)
+ if (*srcp++ & *dstp++)
+ return 0;
+
+ return 1;
+}
+
+
+static void
+vbitset_and (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++)
+ *dstp++ = *src1p++ & *src2p++;
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - min (ssize1, ssize2)));
+}
+
+
+static bool
+vbitset_and_cmp (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ int changed = 0;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ & *src2p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+
+ if (ssize2 > ssize1)
+ {
+ src1p = src2p;
+ ssize1 = ssize2;
+ }
+
+ for (; i < ssize1; i++, dstp++)
+ {
+ if (*dstp != 0)
+ {
+ changed = 1;
+ *dstp = 0;
+ }
+ }
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
+
+ return changed;
+}
+
+
+static void
+vbitset_andn (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++)
+ *dstp++ = *src1p++ & ~(*src2p++);
+
+ if (ssize2 > ssize1)
+ {
+ for (; i < ssize2; i++)
+ *dstp++ = 0;
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize2));
+ }
+ else
+ {
+ for (; i < ssize1; i++)
+ *dstp++ = *src1p++;
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
+ }
+}
+
+
+static bool
+vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ int changed = 0;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ & ~(*src2p++);
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+
+ if (ssize2 > ssize1)
+ {
+ for (; i < ssize2; i++, dstp++)
+ {
+ if (*dstp != 0)
+ {
+ changed = 1;
+ *dstp = 0;
+ }
+ }
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize2));
+ }
+ else
+ {
+ for (; i < ssize1; i++, dstp++)
+ {
+ bitset_word tmp = *src1p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
+ }
+
+ return changed;
+}
+
+
+static void
+vbitset_or (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++)
+ *dstp++ = *src1p++ | *src2p++;
+
+ if (ssize2 > ssize1)
+ {
+ src1p = src2p;
+ ssize1 = ssize2;
+ }
+
+ for (; i < ssize1; i++)
+ *dstp++ = *src1p++;
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
+}
+
+
+static bool
+vbitset_or_cmp (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ int changed = 0;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ | *src2p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+
+ if (ssize2 > ssize1)
+ {
+ src1p = src2p;
+ ssize1 = ssize2;
+ }
+
+ for (; i < ssize1; i++, dstp++)
+ {
+ bitset_word tmp = *src1p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
+
+ return changed;
+}
+
+
+static void
+vbitset_xor (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++)
+ *dstp++ = *src1p++ ^ *src2p++;
+
+ if (ssize2 > ssize1)
+ {
+ src1p = src2p;
+ ssize1 = ssize2;
+ }
+
+ for (; i < ssize1; i++)
+ *dstp++ = *src1p++;
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
+}
+
+
+static bool
+vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
+{
+ unsigned int i;
+ int changed = 0;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *dstp;
+ bitset_windex ssize1;
+ bitset_windex ssize2;
+ bitset_windex dsize;
+
+ vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
+
+ dsize = VBITSET_SIZE (dst);
+ ssize1 = VBITSET_SIZE (src1);
+ ssize2 = VBITSET_SIZE (src2);
+ dstp = VBITSET_WORDS (dst);
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+
+ for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
+ {
+ bitset_word tmp = *src1p++ ^ *src2p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+
+ if (ssize2 > ssize1)
+ {
+ src1p = src2p;
+ ssize1 = ssize2;
+ }
+
+ for (; i < ssize1; i++, dstp++)
+ {
+ bitset_word tmp = *src1p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+
+ memset (dstp, 0, sizeof (bitset_word) * (dsize - ssize1));
+
+ return changed;
+}
+
+
+/* FIXME, these operations need fixing for different size
+ bitsets. */
+
+static void
+vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ unsigned int i;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *src3p;
+ bitset_word *dstp;
+ bitset_windex size;
+
+ if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
+ || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
+ {
+ bitset_and_or_ (dst, src1, src2, src3);
+ return;
+ }
+
+ vbitset_resize (dst, BITSET_NBITS_ (src1));
+
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+ src3p = VBITSET_WORDS (src3);
+ dstp = VBITSET_WORDS (dst);
+ size = VBITSET_SIZE (dst);
+
+ for (i = 0; i < size; i++)
+ *dstp++ = (*src1p++ & *src2p++) | *src3p++;
+}
+
+
+static bool
+vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ unsigned int i;
+ int changed = 0;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *src3p;
+ bitset_word *dstp;
+ bitset_windex size;
+
+ if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
+ || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
+ return bitset_and_or_cmp_ (dst, src1, src2, src3);
+
+ vbitset_resize (dst, BITSET_NBITS_ (src1));
+
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+ src3p = VBITSET_WORDS (src3);
+ dstp = VBITSET_WORDS (dst);
+ size = VBITSET_SIZE (dst);
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = (*src1p++ & *src2p++) | *src3p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ unsigned int i;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *src3p;
+ bitset_word *dstp;
+ bitset_windex size;
+
+ if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
+ || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
+ {
+ bitset_andn_or_ (dst, src1, src2, src3);
+ return;
+ }
+
+ vbitset_resize (dst, BITSET_NBITS_ (src1));
+
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+ src3p = VBITSET_WORDS (src3);
+ dstp = VBITSET_WORDS (dst);
+ size = VBITSET_SIZE (dst);
+
+ for (i = 0; i < size; i++)
+ *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++;
+}
+
+
+static bool
+vbitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ unsigned int i;
+ int changed = 0;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *src3p;
+ bitset_word *dstp;
+ bitset_windex size;
+
+ if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
+ || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
+ return bitset_andn_or_cmp_ (dst, src1, src2, src3);
+
+ vbitset_resize (dst, BITSET_NBITS_ (src1));
+
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+ src3p = VBITSET_WORDS (src3);
+ dstp = VBITSET_WORDS (dst);
+ size = VBITSET_SIZE (dst);
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+vbitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ unsigned int i;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *src3p;
+ bitset_word *dstp;
+ bitset_windex size;
+
+ if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
+ || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
+ {
+ bitset_or_and_ (dst, src1, src2, src3);
+ return;
+ }
+
+ vbitset_resize (dst, BITSET_NBITS_ (src1));
+
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+ src3p = VBITSET_WORDS (src3);
+ dstp = VBITSET_WORDS (dst);
+ size = VBITSET_SIZE (dst);
+
+ for (i = 0; i < size; i++)
+ *dstp++ = (*src1p++ | *src2p++) & *src3p++;
+}
+
+
+static bool
+vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
+{
+ unsigned int i;
+ int changed = 0;
+ bitset_word *src1p;
+ bitset_word *src2p;
+ bitset_word *src3p;
+ bitset_word *dstp;
+ bitset_windex size;
+
+ if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
+ || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
+ return bitset_or_and_cmp_ (dst, src1, src2, src3);
+
+ vbitset_resize (dst, BITSET_NBITS_ (src1));
+
+ src1p = VBITSET_WORDS (src1);
+ src2p = VBITSET_WORDS (src2);
+ src3p = VBITSET_WORDS (src3);
+ dstp = VBITSET_WORDS (dst);
+ size = VBITSET_SIZE (dst);
+
+ for (i = 0; i < size; i++, dstp++)
+ {
+ bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
+
+ if (*dstp != tmp)
+ {
+ changed = 1;
+ *dstp = tmp;
+ }
+ }
+ return changed;
+}
+
+
+static void
+vbitset_copy (bitset dst, bitset src)
+{
+ if (BITSET_COMPATIBLE_ (dst, src))
+ vbitset_copy1 (dst, src);
+ else
+ bitset_copy_ (dst, src);
+}
+
+
+/* Vector of operations for multiple word bitsets. */
+struct bitset_vtable vbitset_vtable = {
+ vbitset_set,
+ vbitset_reset,
+ bitset_toggle_,
+ vbitset_test,
+ vbitset_resize,
+ bitset_size_,
+ bitset_count_,
+ vbitset_empty_p,
+ vbitset_ones,
+ vbitset_zero,
+ vbitset_copy,
+ vbitset_disjoint_p,
+ vbitset_equal_p,
+ vbitset_not,
+ vbitset_subset_p,
+ vbitset_and,
+ vbitset_and_cmp,
+ vbitset_andn,
+ vbitset_andn_cmp,
+ vbitset_or,
+ vbitset_or_cmp,
+ vbitset_xor,
+ vbitset_xor_cmp,
+ vbitset_and_or,
+ vbitset_and_or_cmp,
+ vbitset_andn_or,
+ vbitset_andn_or_cmp,
+ vbitset_or_and,
+ vbitset_or_and_cmp,
+ vbitset_list,
+ vbitset_list_reverse,
+ NULL,
+ BITSET_VARRAY
+};
+
+
+size_t
+vbitset_bytes (n_bits)
+ bitset_bindex n_bits ATTRIBUTE_UNUSED;
+{
+ return sizeof (struct vbitset_struct);
+}
+
+
+bitset
+vbitset_init (bset, n_bits)
+ bitset bset;
+ bitset_bindex n_bits;
+{
+ bset->b.vtable = &vbitset_vtable;
+
+ bset->b.cindex = 0;
+
+ VBITSET_SIZE (bset) = 0;
+ vbitset_resize (bset, n_bits);
+ return bset;
+}
diff --git a/contrib/tools/bison/gnulib/src/vbitset.h b/contrib/tools/bison/gnulib/src/vbitset.h
index b91019bcb1..29c75a3d3c 100644
--- a/contrib/tools/bison/gnulib/src/vbitset.h
+++ b/contrib/tools/bison/gnulib/src/vbitset.h
@@ -1,29 +1,29 @@
-/* Functions to support vbitsets.
-
- Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
-
- Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _VBITSET_H
-#define _VBITSET_H
-
-#include "bitset.h"
-
-extern size_t vbitset_bytes (bitset_bindex);
-
-extern bitset vbitset_init (bitset, bitset_bindex);
-
-#endif
+/* Functions to support vbitsets.
+
+ Copyright (C) 2002, 2004, 2009-2013 Free Software Foundation, Inc.
+
+ Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _VBITSET_H
+#define _VBITSET_H
+
+#include "bitset.h"
+
+extern size_t vbitset_bytes (bitset_bindex);
+
+extern bitset vbitset_init (bitset, bitset_bindex);
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/verify.h b/contrib/tools/bison/gnulib/src/verify.h
index d42d0750ee..c9057240da 100644
--- a/contrib/tools/bison/gnulib/src/verify.h
+++ b/contrib/tools/bison/gnulib/src/verify.h
@@ -1,255 +1,255 @@
-/* Compile-time assert-like macros.
-
- Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
-
-#ifndef _GL_VERIFY_H
-#define _GL_VERIFY_H
-
-
-/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11.
- This is supported by GCC 4.6.0 and later, in C mode, and its use
- here generates easier-to-read diagnostics when verify (R) fails.
-
- Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11.
- This will likely be supported by future GCC versions, in C++ mode.
-
- Use this only with GCC. If we were willing to slow 'configure'
- down we could also use it with other compilers, but since this
- affects only the quality of diagnostics, why bother? */
-#if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \
- && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \
- && !defined __cplusplus)
-# define _GL_HAVE__STATIC_ASSERT 1
-#endif
-/* The condition (99 < __GNUC__) is temporary, until we know about the
- first G++ release that supports static_assert. */
-#if (99 < __GNUC__) && defined __cplusplus
-# define _GL_HAVE_STATIC_ASSERT 1
-#endif
-
-/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
- system headers, defines a conflicting _Static_assert that is no
- better than ours; override it. */
-#ifndef _GL_HAVE_STATIC_ASSERT
-# include <stddef.h>
-# undef _Static_assert
-#endif
-
-/* Each of these macros verifies that its argument R is nonzero. To
- be portable, R should be an integer constant expression. Unlike
- assert (R), there is no run-time overhead.
-
- If _Static_assert works, verify (R) uses it directly. Similarly,
- _GL_VERIFY_TRUE works by packaging a _Static_assert inside a struct
- that is an operand of sizeof.
-
- The code below uses several ideas for C++ compilers, and for C
- compilers that do not support _Static_assert:
-
- * The first step is ((R) ? 1 : -1). Given an expression R, of
- integral or boolean or floating-point type, this yields an
- expression of integral type, whose value is later verified to be
- constant and nonnegative.
-
- * Next this expression W is wrapped in a type
- struct _gl_verify_type {
- unsigned int _gl_verify_error_if_negative: W;
- }.
- If W is negative, this yields a compile-time error. No compiler can
- deal with a bit-field of negative size.
-
- One might think that an array size check would have the same
- effect, that is, that the type struct { unsigned int dummy[W]; }
- would work as well. However, inside a function, some compilers
- (such as C++ compilers and GNU C) allow local parameters and
- variables inside array size expressions. With these compilers,
- an array size check would not properly diagnose this misuse of
- the verify macro:
-
- void function (int n) { verify (n < 0); }
-
- * For the verify macro, the struct _gl_verify_type will need to
- somehow be embedded into a declaration. To be portable, this
- declaration must declare an object, a constant, a function, or a
- typedef name. If the declared entity uses the type directly,
- such as in
-
- struct dummy {...};
- typedef struct {...} dummy;
- extern struct {...} *dummy;
- extern void dummy (struct {...} *);
- extern struct {...} *dummy (void);
-
- two uses of the verify macro would yield colliding declarations
- if the entity names are not disambiguated. A workaround is to
- attach the current line number to the entity name:
-
- #define _GL_CONCAT0(x, y) x##y
- #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
- extern struct {...} * _GL_CONCAT (dummy, __LINE__);
-
- But this has the problem that two invocations of verify from
- within the same macro would collide, since the __LINE__ value
- would be the same for both invocations. (The GCC __COUNTER__
- macro solves this problem, but is not portable.)
-
- A solution is to use the sizeof operator. It yields a number,
- getting rid of the identity of the type. Declarations like
-
- extern int dummy [sizeof (struct {...})];
- extern void dummy (int [sizeof (struct {...})]);
- extern int (*dummy (void)) [sizeof (struct {...})];
-
- can be repeated.
-
- * Should the implementation use a named struct or an unnamed struct?
- Which of the following alternatives can be used?
-
- extern int dummy [sizeof (struct {...})];
- extern int dummy [sizeof (struct _gl_verify_type {...})];
- extern void dummy (int [sizeof (struct {...})]);
- extern void dummy (int [sizeof (struct _gl_verify_type {...})]);
- extern int (*dummy (void)) [sizeof (struct {...})];
- extern int (*dummy (void)) [sizeof (struct _gl_verify_type {...})];
-
- In the second and sixth case, the struct type is exported to the
- outer scope; two such declarations therefore collide. GCC warns
- about the first, third, and fourth cases. So the only remaining
- possibility is the fifth case:
-
- extern int (*dummy (void)) [sizeof (struct {...})];
-
- * GCC warns about duplicate declarations of the dummy function if
- -Wredundant-decls is used. GCC 4.3 and later have a builtin
- __COUNTER__ macro that can let us generate unique identifiers for
- each dummy function, to suppress this warning.
-
- * This implementation exploits the fact that older versions of GCC,
- which do not support _Static_assert, also do not warn about the
- last declaration mentioned above.
-
- * GCC warns if -Wnested-externs is enabled and verify() is used
- within a function body; but inside a function, you can always
- arrange to use verify_expr() instead.
-
- * In C++, any struct definition inside sizeof is invalid.
- Use a template type to work around the problem. */
-
-/* Concatenate two preprocessor tokens. */
-#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
-#define _GL_CONCAT0(x, y) x##y
-
-/* _GL_COUNTER is an integer, preferably one that changes each time we
- use it. Use __COUNTER__ if it works, falling back on __LINE__
- otherwise. __LINE__ isn't perfect, but it's better than a
- constant. */
-#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
-# define _GL_COUNTER __COUNTER__
-#else
-# define _GL_COUNTER __LINE__
-#endif
-
-/* Generate a symbol with the given prefix, making it unique if
- possible. */
-#define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
-
-/* Verify requirement R at compile-time, as an integer constant expression
- that returns 1. If R is false, fail at compile-time, preferably
- with a diagnostic that includes the string-literal DIAGNOSTIC. */
-
-#define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
- (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
-
-#ifdef __cplusplus
-# if !GNULIB_defined_struct__gl_verify_type
-template <int w>
- struct _gl_verify_type {
- unsigned int _gl_verify_error_if_negative: w;
- };
-# define GNULIB_defined_struct__gl_verify_type 1
-# endif
-# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
- _gl_verify_type<(R) ? 1 : -1>
-#elif defined _GL_HAVE__STATIC_ASSERT
-# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
- struct { \
- _Static_assert (R, DIAGNOSTIC); \
- int _gl_dummy; \
- }
-#else
-# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
- struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
-#endif
-
-/* Verify requirement R at compile-time, as a declaration without a
- trailing ';'. If R is false, fail at compile-time, preferably
- with a diagnostic that includes the string-literal DIAGNOSTIC.
-
- Unfortunately, unlike C11, this implementation must appear as an
- ordinary declaration, and cannot appear inside struct { ... }. */
-
-#ifdef _GL_HAVE__STATIC_ASSERT
-# define _GL_VERIFY _Static_assert
-#else
-# define _GL_VERIFY(R, DIAGNOSTIC) \
- extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
- [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
-#endif
-
-/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
-#ifdef _GL_STATIC_ASSERT_H
-# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert
-# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC)
-# endif
-# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
-# define static_assert _Static_assert /* C11 requires this #define. */
-# endif
-#endif
-
-/* @assert.h omit start@ */
-
-/* Each of these macros verifies that its argument R is nonzero. To
- be portable, R should be an integer constant expression. Unlike
- assert (R), there is no run-time overhead.
-
- There are two macros, since no single macro can be used in all
- contexts in C. verify_true (R) is for scalar contexts, including
- integer constant expression contexts. verify (R) is for declaration
- contexts, e.g., the top level. */
-
-/* Verify requirement R at compile-time, as an integer constant expression.
- Return 1. This is equivalent to verify_expr (R, 1).
-
- verify_true is obsolescent; please use verify_expr instead. */
-
-#define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
-
-/* Verify requirement R at compile-time. Return the value of the
- expression E. */
-
-#define verify_expr(R, E) \
- (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
-
-/* Verify requirement R at compile-time, as a declaration without a
- trailing ';'. */
-
-#define verify(R) _GL_VERIFY (R, "verify (" #R ")")
-
-/* @assert.h omit end@ */
-
-#endif
+/* Compile-time assert-like macros.
+
+ Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
+
+#ifndef _GL_VERIFY_H
+#define _GL_VERIFY_H
+
+
+/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11.
+ This is supported by GCC 4.6.0 and later, in C mode, and its use
+ here generates easier-to-read diagnostics when verify (R) fails.
+
+ Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11.
+ This will likely be supported by future GCC versions, in C++ mode.
+
+ Use this only with GCC. If we were willing to slow 'configure'
+ down we could also use it with other compilers, but since this
+ affects only the quality of diagnostics, why bother? */
+#if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \
+ && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \
+ && !defined __cplusplus)
+# define _GL_HAVE__STATIC_ASSERT 1
+#endif
+/* The condition (99 < __GNUC__) is temporary, until we know about the
+ first G++ release that supports static_assert. */
+#if (99 < __GNUC__) && defined __cplusplus
+# define _GL_HAVE_STATIC_ASSERT 1
+#endif
+
+/* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other
+ system headers, defines a conflicting _Static_assert that is no
+ better than ours; override it. */
+#ifndef _GL_HAVE_STATIC_ASSERT
+# include <stddef.h>
+# undef _Static_assert
+#endif
+
+/* Each of these macros verifies that its argument R is nonzero. To
+ be portable, R should be an integer constant expression. Unlike
+ assert (R), there is no run-time overhead.
+
+ If _Static_assert works, verify (R) uses it directly. Similarly,
+ _GL_VERIFY_TRUE works by packaging a _Static_assert inside a struct
+ that is an operand of sizeof.
+
+ The code below uses several ideas for C++ compilers, and for C
+ compilers that do not support _Static_assert:
+
+ * The first step is ((R) ? 1 : -1). Given an expression R, of
+ integral or boolean or floating-point type, this yields an
+ expression of integral type, whose value is later verified to be
+ constant and nonnegative.
+
+ * Next this expression W is wrapped in a type
+ struct _gl_verify_type {
+ unsigned int _gl_verify_error_if_negative: W;
+ }.
+ If W is negative, this yields a compile-time error. No compiler can
+ deal with a bit-field of negative size.
+
+ One might think that an array size check would have the same
+ effect, that is, that the type struct { unsigned int dummy[W]; }
+ would work as well. However, inside a function, some compilers
+ (such as C++ compilers and GNU C) allow local parameters and
+ variables inside array size expressions. With these compilers,
+ an array size check would not properly diagnose this misuse of
+ the verify macro:
+
+ void function (int n) { verify (n < 0); }
+
+ * For the verify macro, the struct _gl_verify_type will need to
+ somehow be embedded into a declaration. To be portable, this
+ declaration must declare an object, a constant, a function, or a
+ typedef name. If the declared entity uses the type directly,
+ such as in
+
+ struct dummy {...};
+ typedef struct {...} dummy;
+ extern struct {...} *dummy;
+ extern void dummy (struct {...} *);
+ extern struct {...} *dummy (void);
+
+ two uses of the verify macro would yield colliding declarations
+ if the entity names are not disambiguated. A workaround is to
+ attach the current line number to the entity name:
+
+ #define _GL_CONCAT0(x, y) x##y
+ #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
+ extern struct {...} * _GL_CONCAT (dummy, __LINE__);
+
+ But this has the problem that two invocations of verify from
+ within the same macro would collide, since the __LINE__ value
+ would be the same for both invocations. (The GCC __COUNTER__
+ macro solves this problem, but is not portable.)
+
+ A solution is to use the sizeof operator. It yields a number,
+ getting rid of the identity of the type. Declarations like
+
+ extern int dummy [sizeof (struct {...})];
+ extern void dummy (int [sizeof (struct {...})]);
+ extern int (*dummy (void)) [sizeof (struct {...})];
+
+ can be repeated.
+
+ * Should the implementation use a named struct or an unnamed struct?
+ Which of the following alternatives can be used?
+
+ extern int dummy [sizeof (struct {...})];
+ extern int dummy [sizeof (struct _gl_verify_type {...})];
+ extern void dummy (int [sizeof (struct {...})]);
+ extern void dummy (int [sizeof (struct _gl_verify_type {...})]);
+ extern int (*dummy (void)) [sizeof (struct {...})];
+ extern int (*dummy (void)) [sizeof (struct _gl_verify_type {...})];
+
+ In the second and sixth case, the struct type is exported to the
+ outer scope; two such declarations therefore collide. GCC warns
+ about the first, third, and fourth cases. So the only remaining
+ possibility is the fifth case:
+
+ extern int (*dummy (void)) [sizeof (struct {...})];
+
+ * GCC warns about duplicate declarations of the dummy function if
+ -Wredundant-decls is used. GCC 4.3 and later have a builtin
+ __COUNTER__ macro that can let us generate unique identifiers for
+ each dummy function, to suppress this warning.
+
+ * This implementation exploits the fact that older versions of GCC,
+ which do not support _Static_assert, also do not warn about the
+ last declaration mentioned above.
+
+ * GCC warns if -Wnested-externs is enabled and verify() is used
+ within a function body; but inside a function, you can always
+ arrange to use verify_expr() instead.
+
+ * In C++, any struct definition inside sizeof is invalid.
+ Use a template type to work around the problem. */
+
+/* Concatenate two preprocessor tokens. */
+#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
+#define _GL_CONCAT0(x, y) x##y
+
+/* _GL_COUNTER is an integer, preferably one that changes each time we
+ use it. Use __COUNTER__ if it works, falling back on __LINE__
+ otherwise. __LINE__ isn't perfect, but it's better than a
+ constant. */
+#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
+# define _GL_COUNTER __COUNTER__
+#else
+# define _GL_COUNTER __LINE__
+#endif
+
+/* Generate a symbol with the given prefix, making it unique if
+ possible. */
+#define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
+
+/* Verify requirement R at compile-time, as an integer constant expression
+ that returns 1. If R is false, fail at compile-time, preferably
+ with a diagnostic that includes the string-literal DIAGNOSTIC. */
+
+#define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \
+ (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC)))
+
+#ifdef __cplusplus
+# if !GNULIB_defined_struct__gl_verify_type
+template <int w>
+ struct _gl_verify_type {
+ unsigned int _gl_verify_error_if_negative: w;
+ };
+# define GNULIB_defined_struct__gl_verify_type 1
+# endif
+# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+ _gl_verify_type<(R) ? 1 : -1>
+#elif defined _GL_HAVE__STATIC_ASSERT
+# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+ struct { \
+ _Static_assert (R, DIAGNOSTIC); \
+ int _gl_dummy; \
+ }
+#else
+# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
+ struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; }
+#endif
+
+/* Verify requirement R at compile-time, as a declaration without a
+ trailing ';'. If R is false, fail at compile-time, preferably
+ with a diagnostic that includes the string-literal DIAGNOSTIC.
+
+ Unfortunately, unlike C11, this implementation must appear as an
+ ordinary declaration, and cannot appear inside struct { ... }. */
+
+#ifdef _GL_HAVE__STATIC_ASSERT
+# define _GL_VERIFY _Static_assert
+#else
+# define _GL_VERIFY(R, DIAGNOSTIC) \
+ extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
+ [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
+#endif
+
+/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
+#ifdef _GL_STATIC_ASSERT_H
+# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert
+# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC)
+# endif
+# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert
+# define static_assert _Static_assert /* C11 requires this #define. */
+# endif
+#endif
+
+/* @assert.h omit start@ */
+
+/* Each of these macros verifies that its argument R is nonzero. To
+ be portable, R should be an integer constant expression. Unlike
+ assert (R), there is no run-time overhead.
+
+ There are two macros, since no single macro can be used in all
+ contexts in C. verify_true (R) is for scalar contexts, including
+ integer constant expression contexts. verify (R) is for declaration
+ contexts, e.g., the top level. */
+
+/* Verify requirement R at compile-time, as an integer constant expression.
+ Return 1. This is equivalent to verify_expr (R, 1).
+
+ verify_true is obsolescent; please use verify_expr instead. */
+
+#define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")")
+
+/* Verify requirement R at compile-time. Return the value of the
+ expression E. */
+
+#define verify_expr(R, E) \
+ (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
+
+/* Verify requirement R at compile-time, as a declaration without a
+ trailing ';'. */
+
+#define verify(R) _GL_VERIFY (R, "verify (" #R ")")
+
+/* @assert.h omit end@ */
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/verror.c b/contrib/tools/bison/gnulib/src/verror.c
index 5f899c1b7a..fbb5ba6429 100644
--- a/contrib/tools/bison/gnulib/src/verror.c
+++ b/contrib/tools/bison/gnulib/src/verror.c
@@ -1,77 +1,77 @@
-/* va_list error handler for noninteractive utilities
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Eric Blake. */
-
-#include <config.h>
-
-#include "verror.h"
-#include "xvasprintf.h"
-
-#include <errno.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
-#if ENABLE_NLS
-# include "gettext.h"
-# define _(msgid) gettext (msgid)
-#endif
-
-#ifndef _
-# define _(String) String
-#endif
-
-/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
- if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
- If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
- Use the globals error_print_progname and error_message_count similarly
- to error(). */
-void
-verror (int status, int errnum, const char *format, va_list args)
-{
- verror_at_line (status, errnum, NULL, 0, format, args);
-}
-
-/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
- if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
- If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
- If FNAME is not NULL, prepend the message with "FNAME:LINENO:".
- Use the globals error_print_progname, error_message_count, and
- error_one_per_line similarly to error_at_line(). */
-void
-verror_at_line (int status, int errnum, const char *file,
- unsigned int line_number, const char *format, va_list args)
-{
- char *message = xvasprintf (format, args);
- if (message)
- {
- /* Until http://sourceware.org/bugzilla/show_bug.cgi?id=2997 is fixed,
- glibc violates GNU Coding Standards when the file argument to
- error_at_line is NULL. */
- if (file)
- error_at_line (status, errnum, file, line_number, "%s", message);
- else
- error (status, errnum, "%s", message);
- }
- else
- {
- /* EOVERFLOW, EINVAL, and EILSEQ from xvasprintf are signs of
- serious programmer errors. */
- error (0, errno, _("unable to display error message"));
- abort ();
- }
- free (message);
-}
+/* va_list error handler for noninteractive utilities
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake. */
+
+#include <config.h>
+
+#include "verror.h"
+#include "xvasprintf.h"
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#if ENABLE_NLS
+# include "gettext.h"
+# define _(msgid) gettext (msgid)
+#endif
+
+#ifndef _
+# define _(String) String
+#endif
+
+/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
+ if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+ If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
+ Use the globals error_print_progname and error_message_count similarly
+ to error(). */
+void
+verror (int status, int errnum, const char *format, va_list args)
+{
+ verror_at_line (status, errnum, NULL, 0, format, args);
+}
+
+/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
+ if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+ If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
+ If FNAME is not NULL, prepend the message with "FNAME:LINENO:".
+ Use the globals error_print_progname, error_message_count, and
+ error_one_per_line similarly to error_at_line(). */
+void
+verror_at_line (int status, int errnum, const char *file,
+ unsigned int line_number, const char *format, va_list args)
+{
+ char *message = xvasprintf (format, args);
+ if (message)
+ {
+ /* Until http://sourceware.org/bugzilla/show_bug.cgi?id=2997 is fixed,
+ glibc violates GNU Coding Standards when the file argument to
+ error_at_line is NULL. */
+ if (file)
+ error_at_line (status, errnum, file, line_number, "%s", message);
+ else
+ error (status, errnum, "%s", message);
+ }
+ else
+ {
+ /* EOVERFLOW, EINVAL, and EILSEQ from xvasprintf are signs of
+ serious programmer errors. */
+ error (0, errno, _("unable to display error message"));
+ abort ();
+ }
+ free (message);
+}
diff --git a/contrib/tools/bison/gnulib/src/verror.h b/contrib/tools/bison/gnulib/src/verror.h
index 7e7284ad82..5988dd02de 100644
--- a/contrib/tools/bison/gnulib/src/verror.h
+++ b/contrib/tools/bison/gnulib/src/verror.h
@@ -1,54 +1,54 @@
-/* Declaration for va_list error-reporting function
- Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _VERROR_H
-#define _VERROR_H 1
-
-#include <stdarg.h>
-
-#include "error.h" /* for _GL_ATTRIBUTE_FORMAT */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
- if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
- If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
- Use the globals error_print_progname and error_message_count similarly
- to error(). */
-
-extern void verror (int __status, int __errnum, const char *__format,
- va_list __args)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
-
-/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
- if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
- If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
- If FNAME is not NULL, prepend the message with "FNAME:LINENO:".
- Use the globals error_print_progname, error_message_count, and
- error_one_per_line similarly to error_at_line(). */
-
-extern void verror_at_line (int __status, int __errnum, const char *__fname,
- unsigned int __lineno, const char *__format,
- va_list __args)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 0));
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* verror.h */
+/* Declaration for va_list error-reporting function
+ Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _VERROR_H
+#define _VERROR_H 1
+
+#include <stdarg.h>
+
+#include "error.h" /* for _GL_ATTRIBUTE_FORMAT */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
+ if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+ If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
+ Use the globals error_print_progname and error_message_count similarly
+ to error(). */
+
+extern void verror (int __status, int __errnum, const char *__format,
+ va_list __args)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
+
+/* Print a message with 'vfprintf (stderr, FORMAT, ARGS)';
+ if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
+ If STATUS is nonzero, terminate the program with 'exit (STATUS)'.
+ If FNAME is not NULL, prepend the message with "FNAME:LINENO:".
+ Use the globals error_print_progname, error_message_count, and
+ error_one_per_line similarly to error_at_line(). */
+
+extern void verror_at_line (int __status, int __errnum, const char *__fname,
+ unsigned int __lineno, const char *__format,
+ va_list __args)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 0));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* verror.h */
diff --git a/contrib/tools/bison/gnulib/src/version-etc-fsf.c b/contrib/tools/bison/gnulib/src/version-etc-fsf.c
index e1c69da94a..f712e7b2e9 100644
--- a/contrib/tools/bison/gnulib/src/version-etc-fsf.c
+++ b/contrib/tools/bison/gnulib/src/version-etc-fsf.c
@@ -1,30 +1,30 @@
-/* Variable with FSF copyright information, for version-etc.
- Copyright (C) 1999-2006, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#include <config.h>
-
-/* Specification. */
-#include "version-etc.h"
-
-/* Default copyright goes to the FSF. */
-
-const char version_etc_copyright[] =
- /* Do *not* mark this string for translation. %s is a copyright
- symbol suitable for this locale, and %d is the copyright
- year. */
- "Copyright %s %d Free Software Foundation, Inc.";
+/* Variable with FSF copyright information, for version-etc.
+ Copyright (C) 1999-2006, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#include <config.h>
+
+/* Specification. */
+#include "version-etc.h"
+
+/* Default copyright goes to the FSF. */
+
+const char version_etc_copyright[] =
+ /* Do *not* mark this string for translation. %s is a copyright
+ symbol suitable for this locale, and %d is the copyright
+ year. */
+ "Copyright %s %d Free Software Foundation, Inc.";
diff --git a/contrib/tools/bison/gnulib/src/version-etc.c b/contrib/tools/bison/gnulib/src/version-etc.c
index b7d23ab597..ba8dd0388e 100644
--- a/contrib/tools/bison/gnulib/src/version-etc.c
+++ b/contrib/tools/bison/gnulib/src/version-etc.c
@@ -1,258 +1,258 @@
-/* Print --version and bug-reporting information in a consistent format.
- Copyright (C) 1999-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#include <config.h>
-
-/* Specification. */
-#include "version-etc.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
-/* If you use AM_INIT_AUTOMAKE's no-define option,
- PACKAGE is not defined. Use PACKAGE_TARNAME instead. */
-#if ! defined PACKAGE && defined PACKAGE_TARNAME
-# define PACKAGE PACKAGE_TARNAME
-#endif
-
-enum { COPYRIGHT_YEAR = 2013 };
-
-/* The three functions below display the --version information the
- standard way.
-
- If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
- the program. The formats are therefore:
-
- PACKAGE VERSION
-
- or
-
- COMMAND_NAME (PACKAGE) VERSION.
-
- The functions differ in the way they are passed author names. */
-
-/* Display the --version information the standard way.
-
- Author names are given in the array AUTHORS. N_AUTHORS is the
- number of elements in the array. */
-void
-version_etc_arn (FILE *stream,
- const char *command_name, const char *package,
- const char *version,
- const char * const * authors, size_t n_authors)
-{
- if (command_name)
- fprintf (stream, "%s (%s) %s\n", command_name, package, version);
- else
- fprintf (stream, "%s %s\n", package, version);
-
-#ifdef PACKAGE_PACKAGER
-# ifdef PACKAGE_PACKAGER_VERSION
- fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
- PACKAGE_PACKAGER_VERSION);
-# else
- fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
-# endif
-#endif
-
- /* TRANSLATORS: Translate "(C)" to the copyright symbol
- (C-in-a-circle), if this symbol is available in the user's
- locale. Otherwise, do not translate "(C)"; leave it as-is. */
- fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
-
- fputs (_("\
-\n\
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
-This is free software: you are free to change and redistribute it.\n\
-There is NO WARRANTY, to the extent permitted by law.\n\
-\n\
-"),
- stream);
-
- switch (n_authors)
- {
- case 0:
- /* The caller must provide at least one author name. */
- abort ();
- case 1:
- /* TRANSLATORS: %s denotes an author name. */
- fprintf (stream, _("Written by %s.\n"), authors[0]);
- break;
- case 2:
- /* TRANSLATORS: Each %s denotes an author name. */
- fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]);
- break;
- case 3:
- /* TRANSLATORS: Each %s denotes an author name. */
- fprintf (stream, _("Written by %s, %s, and %s.\n"),
- authors[0], authors[1], authors[2]);
- break;
- case 4:
- /* TRANSLATORS: Each %s denotes an author name.
- You can use line breaks, estimating that each author name occupies
- ca. 16 screen columns and that a screen line has ca. 80 columns. */
- fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"),
- authors[0], authors[1], authors[2], authors[3]);
- break;
- case 5:
- /* TRANSLATORS: Each %s denotes an author name.
- You can use line breaks, estimating that each author name occupies
- ca. 16 screen columns and that a screen line has ca. 80 columns. */
- fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"),
- authors[0], authors[1], authors[2], authors[3], authors[4]);
- break;
- case 6:
- /* TRANSLATORS: Each %s denotes an author name.
- You can use line breaks, estimating that each author name occupies
- ca. 16 screen columns and that a screen line has ca. 80 columns. */
- fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
- authors[0], authors[1], authors[2], authors[3], authors[4],
- authors[5]);
- break;
- case 7:
- /* TRANSLATORS: Each %s denotes an author name.
- You can use line breaks, estimating that each author name occupies
- ca. 16 screen columns and that a screen line has ca. 80 columns. */
- fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
- authors[0], authors[1], authors[2], authors[3], authors[4],
- authors[5], authors[6]);
- break;
- case 8:
- /* TRANSLATORS: Each %s denotes an author name.
- You can use line breaks, estimating that each author name occupies
- ca. 16 screen columns and that a screen line has ca. 80 columns. */
- fprintf (stream, _("\
-Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
- authors[0], authors[1], authors[2], authors[3], authors[4],
- authors[5], authors[6], authors[7]);
- break;
- case 9:
- /* TRANSLATORS: Each %s denotes an author name.
- You can use line breaks, estimating that each author name occupies
- ca. 16 screen columns and that a screen line has ca. 80 columns. */
- fprintf (stream, _("\
-Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
- authors[0], authors[1], authors[2], authors[3], authors[4],
- authors[5], authors[6], authors[7], authors[8]);
- break;
- default:
- /* 10 or more authors. Use an abbreviation, since the human reader
- will probably not want to read the entire list anyway. */
- /* TRANSLATORS: Each %s denotes an author name.
- You can use line breaks, estimating that each author name occupies
- ca. 16 screen columns and that a screen line has ca. 80 columns. */
- fprintf (stream, _("\
-Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
- authors[0], authors[1], authors[2], authors[3], authors[4],
- authors[5], authors[6], authors[7], authors[8]);
- break;
- }
-}
-
-/* Display the --version information the standard way. See the initial
- comment to this module, for more information.
-
- Author names are given in the NULL-terminated array AUTHORS. */
-void
-version_etc_ar (FILE *stream,
- const char *command_name, const char *package,
- const char *version, const char * const * authors)
-{
- size_t n_authors;
-
- for (n_authors = 0; authors[n_authors]; n_authors++)
- ;
- version_etc_arn (stream, command_name, package, version, authors, n_authors);
-}
-
-/* Display the --version information the standard way. See the initial
- comment to this module, for more information.
-
- Author names are given in the NULL-terminated va_list AUTHORS. */
-void
-version_etc_va (FILE *stream,
- const char *command_name, const char *package,
- const char *version, va_list authors)
-{
- size_t n_authors;
- const char *authtab[10];
-
- for (n_authors = 0;
- n_authors < 10
- && (authtab[n_authors] = va_arg (authors, const char *)) != NULL;
- n_authors++)
- ;
- version_etc_arn (stream, command_name, package, version,
- authtab, n_authors);
-}
-
-
-/* Display the --version information the standard way.
-
- If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
- the program. The formats are therefore:
-
- PACKAGE VERSION
-
- or
-
- COMMAND_NAME (PACKAGE) VERSION.
-
- The authors names are passed as separate arguments, with an additional
- NULL argument at the end. */
-void
-version_etc (FILE *stream,
- const char *command_name, const char *package,
- const char *version, /* const char *author1, ...*/ ...)
-{
- va_list authors;
-
- va_start (authors, version);
- version_etc_va (stream, command_name, package, version, authors);
- va_end (authors);
-}
-
-void
-emit_bug_reporting_address (void)
-{
- /* TRANSLATORS: The placeholder indicates the bug-reporting address
- for this package. Please add _another line_ saying
- "Report translation bugs to <...>\n" with the address for translation
- bugs (typically your translation team's web or email address). */
- printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT);
-#ifdef PACKAGE_PACKAGER_BUG_REPORTS
- printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
- PACKAGE_PACKAGER_BUG_REPORTS);
-#endif
-#ifdef PACKAGE_URL
- printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
-#else
- printf (_("%s home page: <http://www.gnu.org/software/%s/>\n"),
- PACKAGE_NAME, PACKAGE);
-#endif
- fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
- stdout);
-}
+/* Print --version and bug-reporting information in a consistent format.
+ Copyright (C) 1999-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#include <config.h>
+
+/* Specification. */
+#include "version-etc.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+/* If you use AM_INIT_AUTOMAKE's no-define option,
+ PACKAGE is not defined. Use PACKAGE_TARNAME instead. */
+#if ! defined PACKAGE && defined PACKAGE_TARNAME
+# define PACKAGE PACKAGE_TARNAME
+#endif
+
+enum { COPYRIGHT_YEAR = 2013 };
+
+/* The three functions below display the --version information the
+ standard way.
+
+ If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
+ the program. The formats are therefore:
+
+ PACKAGE VERSION
+
+ or
+
+ COMMAND_NAME (PACKAGE) VERSION.
+
+ The functions differ in the way they are passed author names. */
+
+/* Display the --version information the standard way.
+
+ Author names are given in the array AUTHORS. N_AUTHORS is the
+ number of elements in the array. */
+void
+version_etc_arn (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version,
+ const char * const * authors, size_t n_authors)
+{
+ if (command_name)
+ fprintf (stream, "%s (%s) %s\n", command_name, package, version);
+ else
+ fprintf (stream, "%s %s\n", package, version);
+
+#ifdef PACKAGE_PACKAGER
+# ifdef PACKAGE_PACKAGER_VERSION
+ fprintf (stream, _("Packaged by %s (%s)\n"), PACKAGE_PACKAGER,
+ PACKAGE_PACKAGER_VERSION);
+# else
+ fprintf (stream, _("Packaged by %s\n"), PACKAGE_PACKAGER);
+# endif
+#endif
+
+ /* TRANSLATORS: Translate "(C)" to the copyright symbol
+ (C-in-a-circle), if this symbol is available in the user's
+ locale. Otherwise, do not translate "(C)"; leave it as-is. */
+ fprintf (stream, version_etc_copyright, _("(C)"), COPYRIGHT_YEAR);
+
+ fputs (_("\
+\n\
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\
+This is free software: you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law.\n\
+\n\
+"),
+ stream);
+
+ switch (n_authors)
+ {
+ case 0:
+ /* The caller must provide at least one author name. */
+ abort ();
+ case 1:
+ /* TRANSLATORS: %s denotes an author name. */
+ fprintf (stream, _("Written by %s.\n"), authors[0]);
+ break;
+ case 2:
+ /* TRANSLATORS: Each %s denotes an author name. */
+ fprintf (stream, _("Written by %s and %s.\n"), authors[0], authors[1]);
+ break;
+ case 3:
+ /* TRANSLATORS: Each %s denotes an author name. */
+ fprintf (stream, _("Written by %s, %s, and %s.\n"),
+ authors[0], authors[1], authors[2]);
+ break;
+ case 4:
+ /* TRANSLATORS: Each %s denotes an author name.
+ You can use line breaks, estimating that each author name occupies
+ ca. 16 screen columns and that a screen line has ca. 80 columns. */
+ fprintf (stream, _("Written by %s, %s, %s,\nand %s.\n"),
+ authors[0], authors[1], authors[2], authors[3]);
+ break;
+ case 5:
+ /* TRANSLATORS: Each %s denotes an author name.
+ You can use line breaks, estimating that each author name occupies
+ ca. 16 screen columns and that a screen line has ca. 80 columns. */
+ fprintf (stream, _("Written by %s, %s, %s,\n%s, and %s.\n"),
+ authors[0], authors[1], authors[2], authors[3], authors[4]);
+ break;
+ case 6:
+ /* TRANSLATORS: Each %s denotes an author name.
+ You can use line breaks, estimating that each author name occupies
+ ca. 16 screen columns and that a screen line has ca. 80 columns. */
+ fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, and %s.\n"),
+ authors[0], authors[1], authors[2], authors[3], authors[4],
+ authors[5]);
+ break;
+ case 7:
+ /* TRANSLATORS: Each %s denotes an author name.
+ You can use line breaks, estimating that each author name occupies
+ ca. 16 screen columns and that a screen line has ca. 80 columns. */
+ fprintf (stream, _("Written by %s, %s, %s,\n%s, %s, %s, and %s.\n"),
+ authors[0], authors[1], authors[2], authors[3], authors[4],
+ authors[5], authors[6]);
+ break;
+ case 8:
+ /* TRANSLATORS: Each %s denotes an author name.
+ You can use line breaks, estimating that each author name occupies
+ ca. 16 screen columns and that a screen line has ca. 80 columns. */
+ fprintf (stream, _("\
+Written by %s, %s, %s,\n%s, %s, %s, %s,\nand %s.\n"),
+ authors[0], authors[1], authors[2], authors[3], authors[4],
+ authors[5], authors[6], authors[7]);
+ break;
+ case 9:
+ /* TRANSLATORS: Each %s denotes an author name.
+ You can use line breaks, estimating that each author name occupies
+ ca. 16 screen columns and that a screen line has ca. 80 columns. */
+ fprintf (stream, _("\
+Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, and %s.\n"),
+ authors[0], authors[1], authors[2], authors[3], authors[4],
+ authors[5], authors[6], authors[7], authors[8]);
+ break;
+ default:
+ /* 10 or more authors. Use an abbreviation, since the human reader
+ will probably not want to read the entire list anyway. */
+ /* TRANSLATORS: Each %s denotes an author name.
+ You can use line breaks, estimating that each author name occupies
+ ca. 16 screen columns and that a screen line has ca. 80 columns. */
+ fprintf (stream, _("\
+Written by %s, %s, %s,\n%s, %s, %s, %s,\n%s, %s, and others.\n"),
+ authors[0], authors[1], authors[2], authors[3], authors[4],
+ authors[5], authors[6], authors[7], authors[8]);
+ break;
+ }
+}
+
+/* Display the --version information the standard way. See the initial
+ comment to this module, for more information.
+
+ Author names are given in the NULL-terminated array AUTHORS. */
+void
+version_etc_ar (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version, const char * const * authors)
+{
+ size_t n_authors;
+
+ for (n_authors = 0; authors[n_authors]; n_authors++)
+ ;
+ version_etc_arn (stream, command_name, package, version, authors, n_authors);
+}
+
+/* Display the --version information the standard way. See the initial
+ comment to this module, for more information.
+
+ Author names are given in the NULL-terminated va_list AUTHORS. */
+void
+version_etc_va (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version, va_list authors)
+{
+ size_t n_authors;
+ const char *authtab[10];
+
+ for (n_authors = 0;
+ n_authors < 10
+ && (authtab[n_authors] = va_arg (authors, const char *)) != NULL;
+ n_authors++)
+ ;
+ version_etc_arn (stream, command_name, package, version,
+ authtab, n_authors);
+}
+
+
+/* Display the --version information the standard way.
+
+ If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
+ the program. The formats are therefore:
+
+ PACKAGE VERSION
+
+ or
+
+ COMMAND_NAME (PACKAGE) VERSION.
+
+ The authors names are passed as separate arguments, with an additional
+ NULL argument at the end. */
+void
+version_etc (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version, /* const char *author1, ...*/ ...)
+{
+ va_list authors;
+
+ va_start (authors, version);
+ version_etc_va (stream, command_name, package, version, authors);
+ va_end (authors);
+}
+
+void
+emit_bug_reporting_address (void)
+{
+ /* TRANSLATORS: The placeholder indicates the bug-reporting address
+ for this package. Please add _another line_ saying
+ "Report translation bugs to <...>\n" with the address for translation
+ bugs (typically your translation team's web or email address). */
+ printf (_("\nReport bugs to: %s\n"), PACKAGE_BUGREPORT);
+#ifdef PACKAGE_PACKAGER_BUG_REPORTS
+ printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
+ PACKAGE_PACKAGER_BUG_REPORTS);
+#endif
+#ifdef PACKAGE_URL
+ printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
+#else
+ printf (_("%s home page: <http://www.gnu.org/software/%s/>\n"),
+ PACKAGE_NAME, PACKAGE);
+#endif
+ fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
+ stdout);
+}
diff --git a/contrib/tools/bison/gnulib/src/version-etc.h b/contrib/tools/bison/gnulib/src/version-etc.h
index 6c3d08431c..a5d4a66886 100644
--- a/contrib/tools/bison/gnulib/src/version-etc.h
+++ b/contrib/tools/bison/gnulib/src/version-etc.h
@@ -1,78 +1,78 @@
-/* Print --version and bug-reporting information in a consistent format.
- Copyright (C) 1999, 2003, 2005, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Jim Meyering. */
-
-#ifndef VERSION_ETC_H
-# define VERSION_ETC_H 1
-
-# include <stdarg.h>
-# include <stdio.h>
-
-/* The 'sentinel' attribute was added in gcc 4.0. */
-#ifndef _GL_ATTRIBUTE_SENTINEL
-# if 4 <= __GNUC__
-# define _GL_ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
-# else
-# define _GL_ATTRIBUTE_SENTINEL /* empty */
-# endif
-#endif
-
-extern const char version_etc_copyright[];
-
-/* The three functions below display the --version information in the
- standard way: command and package names, package version, followed
- by a short GPLv3+ notice and a list of up to 10 author names.
-
- If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
- the program. The formats are therefore:
-
- PACKAGE VERSION
-
- or
-
- COMMAND_NAME (PACKAGE) VERSION.
-
- The functions differ in the way they are passed author names: */
-
-/* N_AUTHORS names are supplied in array AUTHORS. */
-extern void version_etc_arn (FILE *stream,
- const char *command_name, const char *package,
- const char *version,
- const char * const * authors, size_t n_authors);
-
-/* Names are passed in the NULL-terminated array AUTHORS. */
-extern void version_etc_ar (FILE *stream,
- const char *command_name, const char *package,
- const char *version, const char * const * authors);
-
-/* Names are passed in the NULL-terminated va_list. */
-extern void version_etc_va (FILE *stream,
- const char *command_name, const char *package,
- const char *version, va_list authors);
-
-/* Names are passed as separate arguments, with an additional
- NULL argument at the end. */
-extern void version_etc (FILE *stream,
- const char *command_name, const char *package,
- const char *version,
- /* const char *author1, ..., NULL */ ...)
- _GL_ATTRIBUTE_SENTINEL;
-
-/* Display the usual "Report bugs to" stanza. */
-extern void emit_bug_reporting_address (void);
-
-#endif /* VERSION_ETC_H */
+/* Print --version and bug-reporting information in a consistent format.
+ Copyright (C) 1999, 2003, 2005, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering. */
+
+#ifndef VERSION_ETC_H
+# define VERSION_ETC_H 1
+
+# include <stdarg.h>
+# include <stdio.h>
+
+/* The 'sentinel' attribute was added in gcc 4.0. */
+#ifndef _GL_ATTRIBUTE_SENTINEL
+# if 4 <= __GNUC__
+# define _GL_ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
+# else
+# define _GL_ATTRIBUTE_SENTINEL /* empty */
+# endif
+#endif
+
+extern const char version_etc_copyright[];
+
+/* The three functions below display the --version information in the
+ standard way: command and package names, package version, followed
+ by a short GPLv3+ notice and a list of up to 10 author names.
+
+ If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
+ the program. The formats are therefore:
+
+ PACKAGE VERSION
+
+ or
+
+ COMMAND_NAME (PACKAGE) VERSION.
+
+ The functions differ in the way they are passed author names: */
+
+/* N_AUTHORS names are supplied in array AUTHORS. */
+extern void version_etc_arn (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version,
+ const char * const * authors, size_t n_authors);
+
+/* Names are passed in the NULL-terminated array AUTHORS. */
+extern void version_etc_ar (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version, const char * const * authors);
+
+/* Names are passed in the NULL-terminated va_list. */
+extern void version_etc_va (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version, va_list authors);
+
+/* Names are passed as separate arguments, with an additional
+ NULL argument at the end. */
+extern void version_etc (FILE *stream,
+ const char *command_name, const char *package,
+ const char *version,
+ /* const char *author1, ..., NULL */ ...)
+ _GL_ATTRIBUTE_SENTINEL;
+
+/* Display the usual "Report bugs to" stanza. */
+extern void emit_bug_reporting_address (void);
+
+#endif /* VERSION_ETC_H */
diff --git a/contrib/tools/bison/gnulib/src/vfprintf.c b/contrib/tools/bison/gnulib/src/vfprintf.c
index 635e36eb59..7922ce6521 100644
--- a/contrib/tools/bison/gnulib/src/vfprintf.c
+++ b/contrib/tools/bison/gnulib/src/vfprintf.c
@@ -1,74 +1,74 @@
-/* Formatted output to a stream.
- Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if 1
-# include <config.h>
-#endif
-
-/* Specification. */
-#include <stdio.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
-#include "fseterr.h"
-#include "vasnprintf.h"
-
-/* Print formatted output to the stream FP.
- Return string length of formatted string. On error, return a negative
- value. */
-int
-vfprintf (FILE *fp, const char *format, va_list args)
-{
- char buf[2000];
- char *output;
- size_t len;
- size_t lenbuf = sizeof (buf);
-
- output = vasnprintf (buf, &lenbuf, format, args);
- len = lenbuf;
-
- if (!output)
- {
- fseterr (fp);
- return -1;
- }
-
- if (fwrite (output, 1, len, fp) < len)
- {
- if (output != buf)
- {
- int saved_errno = errno;
- free (output);
- errno = saved_errno;
- }
- return -1;
- }
-
- if (output != buf)
- free (output);
-
- if (len > INT_MAX)
- {
- errno = EOVERFLOW;
- fseterr (fp);
- return -1;
- }
-
- return len;
-}
+/* Formatted output to a stream.
+ Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if 1
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "fseterr.h"
+#include "vasnprintf.h"
+
+/* Print formatted output to the stream FP.
+ Return string length of formatted string. On error, return a negative
+ value. */
+int
+vfprintf (FILE *fp, const char *format, va_list args)
+{
+ char buf[2000];
+ char *output;
+ size_t len;
+ size_t lenbuf = sizeof (buf);
+
+ output = vasnprintf (buf, &lenbuf, format, args);
+ len = lenbuf;
+
+ if (!output)
+ {
+ fseterr (fp);
+ return -1;
+ }
+
+ if (fwrite (output, 1, len, fp) < len)
+ {
+ if (output != buf)
+ {
+ int saved_errno = errno;
+ free (output);
+ errno = saved_errno;
+ }
+ return -1;
+ }
+
+ if (output != buf)
+ free (output);
+
+ if (len > INT_MAX)
+ {
+ errno = EOVERFLOW;
+ fseterr (fp);
+ return -1;
+ }
+
+ return len;
+}
diff --git a/contrib/tools/bison/gnulib/src/vsprintf.c b/contrib/tools/bison/gnulib/src/vsprintf.c
index 759b1f52fc..ccb2db27e7 100644
--- a/contrib/tools/bison/gnulib/src/vsprintf.c
+++ b/contrib/tools/bison/gnulib/src/vsprintf.c
@@ -1,77 +1,77 @@
-/* Formatted output to strings.
- Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#if 1
-# include <config.h>
-#endif
-
-/* Specification. */
-#include <stdio.h>
-
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#include "vasnprintf.h"
-
-#ifndef SIZE_MAX
-# define SIZE_MAX ((size_t) -1)
-#endif
-
-/* Print formatted output to string STR.
- Return string length of formatted string. On error, return a negative
- value. */
-int
-vsprintf (char *str, const char *format, va_list args)
-{
- char *output;
- size_t len;
- size_t lenbuf;
-
- /* vasnprintf fails with EOVERFLOW when the buffer size argument is larger
- than INT_MAX (if that fits into a 'size_t' at all).
- Also note that glibc's iconv fails with E2BIG when we pass a length that
- is so large that str + lenbuf wraps around, i.e.
- (uintptr_t) (str + lenbuf) < (uintptr_t) str.
- Therefore set lenbuf = min (SIZE_MAX, INT_MAX, - (uintptr_t) str - 1). */
- lenbuf = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX);
- if (lenbuf > ~ (uintptr_t) str)
- lenbuf = ~ (uintptr_t) str;
-
- output = vasnprintf (str, &lenbuf, format, args);
- len = lenbuf;
-
- if (!output)
- return -1;
-
- if (output != str)
- {
- /* len is near SIZE_MAX. */
- free (output);
- errno = EOVERFLOW;
- return -1;
- }
-
- if (len > INT_MAX)
- {
- errno = EOVERFLOW;
- return -1;
- }
-
- return len;
-}
+/* Formatted output to strings.
+ Copyright (C) 2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if 1
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "vasnprintf.h"
+
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+
+/* Print formatted output to string STR.
+ Return string length of formatted string. On error, return a negative
+ value. */
+int
+vsprintf (char *str, const char *format, va_list args)
+{
+ char *output;
+ size_t len;
+ size_t lenbuf;
+
+ /* vasnprintf fails with EOVERFLOW when the buffer size argument is larger
+ than INT_MAX (if that fits into a 'size_t' at all).
+ Also note that glibc's iconv fails with E2BIG when we pass a length that
+ is so large that str + lenbuf wraps around, i.e.
+ (uintptr_t) (str + lenbuf) < (uintptr_t) str.
+ Therefore set lenbuf = min (SIZE_MAX, INT_MAX, - (uintptr_t) str - 1). */
+ lenbuf = (SIZE_MAX < INT_MAX ? SIZE_MAX : INT_MAX);
+ if (lenbuf > ~ (uintptr_t) str)
+ lenbuf = ~ (uintptr_t) str;
+
+ output = vasnprintf (str, &lenbuf, format, args);
+ len = lenbuf;
+
+ if (!output)
+ return -1;
+
+ if (output != str)
+ {
+ /* len is near SIZE_MAX. */
+ free (output);
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ if (len > INT_MAX)
+ {
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ return len;
+}
diff --git a/contrib/tools/bison/gnulib/src/w32spawn.h b/contrib/tools/bison/gnulib/src/w32spawn.h
index 3b5c08afcd..531333e668 100644
--- a/contrib/tools/bison/gnulib/src/w32spawn.h
+++ b/contrib/tools/bison/gnulib/src/w32spawn.h
@@ -1,222 +1,222 @@
-/* Auxiliary functions for the creation of subprocesses. Native Windows API.
- Copyright (C) 2001, 2003-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2003.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Get declarations of the native Windows API functions. */
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-/* Get _open_osfhandle(). */
-#include <io.h>
-
-#include <stdbool.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-/* Get _get_osfhandle(). */
-#include "msvc-nothrow.h"
-
-#include "cloexec.h"
-#include "xalloc.h"
-
-/* Duplicates a file handle, making the copy uninheritable.
- Returns -1 for a file handle that is equivalent to closed. */
-static int
-dup_noinherit (int fd)
-{
- fd = dup_cloexec (fd);
- if (fd < 0 && errno == EMFILE)
- error (EXIT_FAILURE, errno, _("_open_osfhandle failed"));
-
- return fd;
-}
-
-/* Returns a file descriptor equivalent to FD, except that the resulting file
- descriptor is none of STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO.
- FD must be open and non-inheritable. The result will be non-inheritable as
- well.
- If FD < 0, FD itself is returned. */
-static int
-fd_safer_noinherit (int fd)
-{
- if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
- {
- /* The recursion depth is at most 3. */
- int nfd = fd_safer_noinherit (dup_noinherit (fd));
- int saved_errno = errno;
- close (fd);
- errno = saved_errno;
- return nfd;
- }
- return fd;
-}
-
-/* Duplicates a file handle, making the copy uninheritable and ensuring the
- result is none of STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO.
- Returns -1 for a file handle that is equivalent to closed. */
-static int
-dup_safer_noinherit (int fd)
-{
- return fd_safer_noinherit (dup_noinherit (fd));
-}
-
-/* Undoes the effect of TEMPFD = dup_safer_noinherit (ORIGFD); */
-static void
-undup_safer_noinherit (int tempfd, int origfd)
-{
- if (tempfd >= 0)
- {
- if (dup2 (tempfd, origfd) < 0)
- error (EXIT_FAILURE, errno, _("cannot restore fd %d: dup2 failed"),
- origfd);
- close (tempfd);
- }
- else
- {
- /* origfd was closed or open to no handle at all. Set it to a closed
- state. This is (nearly) equivalent to the original state. */
- close (origfd);
- }
-}
-
-/* Prepares an argument vector before calling spawn().
- Note that spawn() does not by itself call the command interpreter
- (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
- ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&v);
- v.dwPlatformId == VER_PLATFORM_WIN32_NT;
- }) ? "cmd.exe" : "command.com").
- Instead it simply concatenates the arguments, separated by ' ', and calls
- CreateProcess(). We must quote the arguments since Windows CreateProcess()
- interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
- special way:
- - Space and tab are interpreted as delimiters. They are not treated as
- delimiters if they are surrounded by double quotes: "...".
- - Unescaped double quotes are removed from the input. Their only effect is
- that within double quotes, space and tab are treated like normal
- characters.
- - Backslashes not followed by double quotes are not special.
- - But 2*n+1 backslashes followed by a double quote become
- n backslashes followed by a double quote (n >= 0):
- \" -> "
- \\\" -> \"
- \\\\\" -> \\"
- - '*', '?' characters may get expanded through wildcard expansion in the
- callee: By default, in the callee, the initialization code before main()
- takes the result of GetCommandLine(), wildcard-expands it, and passes it
- to main(). The exceptions to this rule are:
- - programs that inspect GetCommandLine() and ignore argv,
- - mingw programs that have a global variable 'int _CRT_glob = 0;',
- - Cygwin programs, when invoked from a Cygwin program.
- */
-#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037*?"
-#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
-static char **
-prepare_spawn (char **argv)
-{
- size_t argc;
- char **new_argv;
- size_t i;
-
- /* Count number of arguments. */
- for (argc = 0; argv[argc] != NULL; argc++)
- ;
-
- /* Allocate new argument vector. */
- new_argv = XNMALLOC (1 + argc + 1, char *);
-
- /* Add an element upfront that can be used when argv[0] turns out to be a
- script, not a program.
- On Unix, this would be "/bin/sh". On native Windows, "sh" is actually
- "sh.exe". We have to omit the directory part and rely on the search in
- PATH, because the mingw "mount points" are not visible inside Windows
- CreateProcess(). */
- *new_argv++ = "sh.exe";
-
- /* Put quoted arguments into the new argument vector. */
- for (i = 0; i < argc; i++)
- {
- const char *string = argv[i];
-
- if (string[0] == '\0')
- new_argv[i] = xstrdup ("\"\"");
- else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
- {
- bool quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
- size_t length;
- unsigned int backslashes;
- const char *s;
- char *quoted_string;
- char *p;
-
- length = 0;
- backslashes = 0;
- if (quote_around)
- length++;
- for (s = string; *s != '\0'; s++)
- {
- char c = *s;
- if (c == '"')
- length += backslashes + 1;
- length++;
- if (c == '\\')
- backslashes++;
- else
- backslashes = 0;
- }
- if (quote_around)
- length += backslashes + 1;
-
- quoted_string = (char *) xmalloc (length + 1);
-
- p = quoted_string;
- backslashes = 0;
- if (quote_around)
- *p++ = '"';
- for (s = string; *s != '\0'; s++)
- {
- char c = *s;
- if (c == '"')
- {
- unsigned int j;
- for (j = backslashes + 1; j > 0; j--)
- *p++ = '\\';
- }
- *p++ = c;
- if (c == '\\')
- backslashes++;
- else
- backslashes = 0;
- }
- if (quote_around)
- {
- unsigned int j;
- for (j = backslashes; j > 0; j--)
- *p++ = '\\';
- *p++ = '"';
- }
- *p = '\0';
-
- new_argv[i] = quoted_string;
- }
- else
- new_argv[i] = (char *) string;
- }
- new_argv[argc] = NULL;
-
- return new_argv;
-}
+/* Auxiliary functions for the creation of subprocesses. Native Windows API.
+ Copyright (C) 2001, 2003-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Get declarations of the native Windows API functions. */
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+/* Get _open_osfhandle(). */
+#include <io.h>
+
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+/* Get _get_osfhandle(). */
+#include "msvc-nothrow.h"
+
+#include "cloexec.h"
+#include "xalloc.h"
+
+/* Duplicates a file handle, making the copy uninheritable.
+ Returns -1 for a file handle that is equivalent to closed. */
+static int
+dup_noinherit (int fd)
+{
+ fd = dup_cloexec (fd);
+ if (fd < 0 && errno == EMFILE)
+ error (EXIT_FAILURE, errno, _("_open_osfhandle failed"));
+
+ return fd;
+}
+
+/* Returns a file descriptor equivalent to FD, except that the resulting file
+ descriptor is none of STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO.
+ FD must be open and non-inheritable. The result will be non-inheritable as
+ well.
+ If FD < 0, FD itself is returned. */
+static int
+fd_safer_noinherit (int fd)
+{
+ if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
+ {
+ /* The recursion depth is at most 3. */
+ int nfd = fd_safer_noinherit (dup_noinherit (fd));
+ int saved_errno = errno;
+ close (fd);
+ errno = saved_errno;
+ return nfd;
+ }
+ return fd;
+}
+
+/* Duplicates a file handle, making the copy uninheritable and ensuring the
+ result is none of STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO.
+ Returns -1 for a file handle that is equivalent to closed. */
+static int
+dup_safer_noinherit (int fd)
+{
+ return fd_safer_noinherit (dup_noinherit (fd));
+}
+
+/* Undoes the effect of TEMPFD = dup_safer_noinherit (ORIGFD); */
+static void
+undup_safer_noinherit (int tempfd, int origfd)
+{
+ if (tempfd >= 0)
+ {
+ if (dup2 (tempfd, origfd) < 0)
+ error (EXIT_FAILURE, errno, _("cannot restore fd %d: dup2 failed"),
+ origfd);
+ close (tempfd);
+ }
+ else
+ {
+ /* origfd was closed or open to no handle at all. Set it to a closed
+ state. This is (nearly) equivalent to the original state. */
+ close (origfd);
+ }
+}
+
+/* Prepares an argument vector before calling spawn().
+ Note that spawn() does not by itself call the command interpreter
+ (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
+ ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&v);
+ v.dwPlatformId == VER_PLATFORM_WIN32_NT;
+ }) ? "cmd.exe" : "command.com").
+ Instead it simply concatenates the arguments, separated by ' ', and calls
+ CreateProcess(). We must quote the arguments since Windows CreateProcess()
+ interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
+ special way:
+ - Space and tab are interpreted as delimiters. They are not treated as
+ delimiters if they are surrounded by double quotes: "...".
+ - Unescaped double quotes are removed from the input. Their only effect is
+ that within double quotes, space and tab are treated like normal
+ characters.
+ - Backslashes not followed by double quotes are not special.
+ - But 2*n+1 backslashes followed by a double quote become
+ n backslashes followed by a double quote (n >= 0):
+ \" -> "
+ \\\" -> \"
+ \\\\\" -> \\"
+ - '*', '?' characters may get expanded through wildcard expansion in the
+ callee: By default, in the callee, the initialization code before main()
+ takes the result of GetCommandLine(), wildcard-expands it, and passes it
+ to main(). The exceptions to this rule are:
+ - programs that inspect GetCommandLine() and ignore argv,
+ - mingw programs that have a global variable 'int _CRT_glob = 0;',
+ - Cygwin programs, when invoked from a Cygwin program.
+ */
+#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037*?"
+#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+static char **
+prepare_spawn (char **argv)
+{
+ size_t argc;
+ char **new_argv;
+ size_t i;
+
+ /* Count number of arguments. */
+ for (argc = 0; argv[argc] != NULL; argc++)
+ ;
+
+ /* Allocate new argument vector. */
+ new_argv = XNMALLOC (1 + argc + 1, char *);
+
+ /* Add an element upfront that can be used when argv[0] turns out to be a
+ script, not a program.
+ On Unix, this would be "/bin/sh". On native Windows, "sh" is actually
+ "sh.exe". We have to omit the directory part and rely on the search in
+ PATH, because the mingw "mount points" are not visible inside Windows
+ CreateProcess(). */
+ *new_argv++ = "sh.exe";
+
+ /* Put quoted arguments into the new argument vector. */
+ for (i = 0; i < argc; i++)
+ {
+ const char *string = argv[i];
+
+ if (string[0] == '\0')
+ new_argv[i] = xstrdup ("\"\"");
+ else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
+ {
+ bool quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
+ size_t length;
+ unsigned int backslashes;
+ const char *s;
+ char *quoted_string;
+ char *p;
+
+ length = 0;
+ backslashes = 0;
+ if (quote_around)
+ length++;
+ for (s = string; *s != '\0'; s++)
+ {
+ char c = *s;
+ if (c == '"')
+ length += backslashes + 1;
+ length++;
+ if (c == '\\')
+ backslashes++;
+ else
+ backslashes = 0;
+ }
+ if (quote_around)
+ length += backslashes + 1;
+
+ quoted_string = (char *) xmalloc (length + 1);
+
+ p = quoted_string;
+ backslashes = 0;
+ if (quote_around)
+ *p++ = '"';
+ for (s = string; *s != '\0'; s++)
+ {
+ char c = *s;
+ if (c == '"')
+ {
+ unsigned int j;
+ for (j = backslashes + 1; j > 0; j--)
+ *p++ = '\\';
+ }
+ *p++ = c;
+ if (c == '\\')
+ backslashes++;
+ else
+ backslashes = 0;
+ }
+ if (quote_around)
+ {
+ unsigned int j;
+ for (j = backslashes; j > 0; j--)
+ *p++ = '\\';
+ *p++ = '"';
+ }
+ *p = '\0';
+
+ new_argv[i] = quoted_string;
+ }
+ else
+ new_argv[i] = (char *) string;
+ }
+ new_argv[argc] = NULL;
+
+ return new_argv;
+}
diff --git a/contrib/tools/bison/gnulib/src/wait-process.c b/contrib/tools/bison/gnulib/src/wait-process.c
index 17a2430f91..22b5b1df16 100644
--- a/contrib/tools/bison/gnulib/src/wait-process.c
+++ b/contrib/tools/bison/gnulib/src/wait-process.c
@@ -1,361 +1,361 @@
-/* Waiting for a subprocess to finish.
- Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#include <config.h>
-
-/* Specification. */
-#include "wait-process.h"
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include "error.h"
-#include "fatal-signal.h"
-#include "xalloc.h"
-#include "gettext.h"
-
-#define _(str) gettext (str)
-
-#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
-
-
-#if defined _MSC_VER || defined __MINGW32__
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-/* The return value of spawnvp() is really a process handle as returned
- by CreateProcess(). Therefore we can kill it using TerminateProcess. */
-#define kill(pid,sig) TerminateProcess ((HANDLE) (pid), sig)
-
-#endif
-
-
-/* Type of an entry in the slaves array.
- The 'used' bit determines whether this entry is currently in use.
- (If pid_t was an atomic type like sig_atomic_t, we could just set the
- 'child' field to 0 when unregistering a slave process, and wouldn't need
- the 'used' field.)
- The 'used' and 'child' fields are accessed from within the cleanup_slaves()
- action, therefore we mark them as 'volatile'. */
-typedef struct
-{
- volatile sig_atomic_t used;
- volatile pid_t child;
-}
-slaves_entry_t;
-
-/* The registered slave subprocesses. */
-static slaves_entry_t static_slaves[32];
-static slaves_entry_t * volatile slaves = static_slaves;
-static sig_atomic_t volatile slaves_count = 0;
-static size_t slaves_allocated = SIZEOF (static_slaves);
-
-/* The termination signal for slave subprocesses.
- 2003-10-07: Terminator becomes Governator. */
-#ifdef SIGHUP
-# define TERMINATOR SIGHUP
-#else
-# define TERMINATOR SIGTERM
-#endif
-
-/* The cleanup action. It gets called asynchronously. */
-static void
-cleanup_slaves (void)
-{
- for (;;)
- {
- /* Get the last registered slave. */
- size_t n = slaves_count;
- if (n == 0)
- break;
- n--;
- slaves_count = n;
- /* Skip unused entries in the slaves array. */
- if (slaves[n].used)
- {
- pid_t slave = slaves[n].child;
-
- /* Kill the slave. */
- kill (slave, TERMINATOR);
- }
- }
-}
-
-/* Register a subprocess as being a slave process. This means that the
- subprocess will be terminated when its creator receives a catchable fatal
- signal or exits normally. Registration ends when wait_subprocess()
- notices that the subprocess has exited. */
-void
-register_slave_subprocess (pid_t child)
-{
- static bool cleanup_slaves_registered = false;
- if (!cleanup_slaves_registered)
- {
- atexit (cleanup_slaves);
- at_fatal_signal (cleanup_slaves);
- cleanup_slaves_registered = true;
- }
-
- /* Try to store the new slave in an unused entry of the slaves array. */
- {
- slaves_entry_t *s = slaves;
- slaves_entry_t *s_end = s + slaves_count;
-
- for (; s < s_end; s++)
- if (!s->used)
- {
- /* The two uses of 'volatile' in the slaves_entry_t type above
- (and ISO C 99 section 5.1.2.3.(5)) ensure that we mark the
- entry as used only after the child pid has been written to the
- memory location s->child. */
- s->child = child;
- s->used = 1;
- return;
- }
- }
-
- if (slaves_count == slaves_allocated)
- {
- /* Extend the slaves array. Note that we cannot use xrealloc(),
- because then the cleanup_slaves() function could access an already
- deallocated array. */
- slaves_entry_t *old_slaves = slaves;
- size_t new_slaves_allocated = 2 * slaves_allocated;
- slaves_entry_t *new_slaves =
- (slaves_entry_t *)
- malloc (new_slaves_allocated * sizeof (slaves_entry_t));
- if (new_slaves == NULL)
- {
- /* xalloc_die() will call exit() which will invoke cleanup_slaves().
- Additionally we need to kill child, because it's not yet among
- the slaves list. */
- kill (child, TERMINATOR);
- xalloc_die ();
- }
- memcpy (new_slaves, old_slaves,
- slaves_allocated * sizeof (slaves_entry_t));
- slaves = new_slaves;
- slaves_allocated = new_slaves_allocated;
- /* Now we can free the old slaves array. */
- if (old_slaves != static_slaves)
- free (old_slaves);
- }
- /* The three uses of 'volatile' in the types above (and ISO C 99 section
- 5.1.2.3.(5)) ensure that we increment the slaves_count only after the
- new slave and its 'used' bit have been written to the memory locations
- that make up slaves[slaves_count]. */
- slaves[slaves_count].child = child;
- slaves[slaves_count].used = 1;
- slaves_count++;
-}
-
-/* Unregister a child from the list of slave subprocesses. */
-static void
-unregister_slave_subprocess (pid_t child)
-{
- /* The easiest way to remove an entry from a list that can be used by
- an asynchronous signal handler is just to mark it as unused. For this,
- we rely on sig_atomic_t. */
- slaves_entry_t *s = slaves;
- slaves_entry_t *s_end = s + slaves_count;
-
- for (; s < s_end; s++)
- if (s->used && s->child == child)
- s->used = 0;
-}
-
-
-/* Wait for a subprocess to finish. Return its exit code.
- If it didn't terminate correctly, exit if exit_on_error is true, otherwise
- return 127. */
-int
-wait_subprocess (pid_t child, const char *progname,
- bool ignore_sigpipe, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int *termsigp)
-{
-#if HAVE_WAITID && defined WNOWAIT && 0
- /* Commented out because waitid() without WEXITED and with WNOWAIT doesn't
- work: On Solaris 7 and OSF/1 4.0, it returns -1 and sets errno = ECHILD,
- and on HP-UX 10.20 it just hangs. */
- /* Use of waitid() with WNOWAIT avoids a race condition: If slave_process is
- true, and this process sleeps a very long time between the return from
- waitpid() and the execution of unregister_slave_subprocess(), and
- meanwhile another process acquires the same PID as child, and then - still
- before unregister_slave_subprocess() - this process gets a fatal signal,
- it would kill the other totally unrelated process. */
- siginfo_t info;
-
- if (termsigp != NULL)
- *termsigp = 0;
- for (;;)
- {
- if (waitid (P_PID, child, &info, WEXITED | (slave_process ? WNOWAIT : 0))
- < 0)
- {
-# ifdef EINTR
- if (errno == EINTR)
- continue;
-# endif
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, errno,
- _("%s subprocess"), progname);
- return 127;
- }
-
- /* info.si_code is set to one of CLD_EXITED, CLD_KILLED, CLD_DUMPED,
- CLD_TRAPPED, CLD_STOPPED, CLD_CONTINUED. Loop until the program
- terminates. */
- if (info.si_code == CLD_EXITED
- || info.si_code == CLD_KILLED || info.si_code == CLD_DUMPED)
- break;
- }
-
- /* The child process has exited or was signalled. */
-
- if (slave_process)
- {
- /* Unregister the child from the list of slave subprocesses, so that
- later, when we exit, we don't kill a totally unrelated process which
- may have acquired the same pid. */
- unregister_slave_subprocess (child);
-
- /* Now remove the zombie from the process list. */
- for (;;)
- {
- if (waitid (P_PID, child, &info, WEXITED) < 0)
- {
-# ifdef EINTR
- if (errno == EINTR)
- continue;
-# endif
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, errno,
- _("%s subprocess"), progname);
- return 127;
- }
- break;
- }
- }
-
- switch (info.si_code)
- {
- case CLD_KILLED:
- case CLD_DUMPED:
- if (termsigp != NULL)
- *termsigp = info.si_status; /* TODO: or info.si_signo? */
-# ifdef SIGPIPE
- if (info.si_status == SIGPIPE && ignore_sigpipe)
- return 0;
-# endif
- if (exit_on_error || (!null_stderr && termsigp == NULL))
- error (exit_on_error ? EXIT_FAILURE : 0, 0,
- _("%s subprocess got fatal signal %d"),
- progname, info.si_status);
- return 127;
- case CLD_EXITED:
- if (info.si_status == 127)
- {
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, 0,
- _("%s subprocess failed"), progname);
- return 127;
- }
- return info.si_status;
- default:
- abort ();
- }
-#else
- /* waitpid() is just as portable as wait() nowadays. */
- int status;
-
- if (termsigp != NULL)
- *termsigp = 0;
- status = 0;
- for (;;)
- {
- int result = waitpid (child, &status, 0);
-
- if (result != child)
- {
-# ifdef EINTR
- if (errno == EINTR)
- continue;
-# endif
-# if 0 /* defined ECHILD */
- if (errno == ECHILD)
- {
- /* Child process nonexistent?! Assume it terminated
- successfully. */
- status = 0;
- break;
- }
-# endif
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, errno,
- _("%s subprocess"), progname);
- return 127;
- }
-
- /* One of WIFSIGNALED (status), WIFEXITED (status), WIFSTOPPED (status)
- must always be true, since we did not specify WCONTINUED in the
- waitpid() call. Loop until the program terminates. */
- if (!WIFSTOPPED (status))
- break;
- }
-
- /* The child process has exited or was signalled. */
-
- if (slave_process)
- /* Unregister the child from the list of slave subprocesses, so that
- later, when we exit, we don't kill a totally unrelated process which
- may have acquired the same pid. */
- unregister_slave_subprocess (child);
-
- if (WIFSIGNALED (status))
- {
- if (termsigp != NULL)
- *termsigp = WTERMSIG (status);
-# ifdef SIGPIPE
- if (WTERMSIG (status) == SIGPIPE && ignore_sigpipe)
- return 0;
-# endif
- if (exit_on_error || (!null_stderr && termsigp == NULL))
- error (exit_on_error ? EXIT_FAILURE : 0, 0,
- _("%s subprocess got fatal signal %d"),
- progname, (int) WTERMSIG (status));
- return 127;
- }
- if (!WIFEXITED (status))
- abort ();
- if (WEXITSTATUS (status) == 127)
- {
- if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, 0,
- _("%s subprocess failed"), progname);
- return 127;
- }
- return WEXITSTATUS (status);
-#endif
-}
+/* Waiting for a subprocess to finish.
+ Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include <config.h>
+
+/* Specification. */
+#include "wait-process.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "error.h"
+#include "fatal-signal.h"
+#include "xalloc.h"
+#include "gettext.h"
+
+#define _(str) gettext (str)
+
+#define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
+
+
+#if defined _MSC_VER || defined __MINGW32__
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+/* The return value of spawnvp() is really a process handle as returned
+ by CreateProcess(). Therefore we can kill it using TerminateProcess. */
+#define kill(pid,sig) TerminateProcess ((HANDLE) (pid), sig)
+
+#endif
+
+
+/* Type of an entry in the slaves array.
+ The 'used' bit determines whether this entry is currently in use.
+ (If pid_t was an atomic type like sig_atomic_t, we could just set the
+ 'child' field to 0 when unregistering a slave process, and wouldn't need
+ the 'used' field.)
+ The 'used' and 'child' fields are accessed from within the cleanup_slaves()
+ action, therefore we mark them as 'volatile'. */
+typedef struct
+{
+ volatile sig_atomic_t used;
+ volatile pid_t child;
+}
+slaves_entry_t;
+
+/* The registered slave subprocesses. */
+static slaves_entry_t static_slaves[32];
+static slaves_entry_t * volatile slaves = static_slaves;
+static sig_atomic_t volatile slaves_count = 0;
+static size_t slaves_allocated = SIZEOF (static_slaves);
+
+/* The termination signal for slave subprocesses.
+ 2003-10-07: Terminator becomes Governator. */
+#ifdef SIGHUP
+# define TERMINATOR SIGHUP
+#else
+# define TERMINATOR SIGTERM
+#endif
+
+/* The cleanup action. It gets called asynchronously. */
+static void
+cleanup_slaves (void)
+{
+ for (;;)
+ {
+ /* Get the last registered slave. */
+ size_t n = slaves_count;
+ if (n == 0)
+ break;
+ n--;
+ slaves_count = n;
+ /* Skip unused entries in the slaves array. */
+ if (slaves[n].used)
+ {
+ pid_t slave = slaves[n].child;
+
+ /* Kill the slave. */
+ kill (slave, TERMINATOR);
+ }
+ }
+}
+
+/* Register a subprocess as being a slave process. This means that the
+ subprocess will be terminated when its creator receives a catchable fatal
+ signal or exits normally. Registration ends when wait_subprocess()
+ notices that the subprocess has exited. */
+void
+register_slave_subprocess (pid_t child)
+{
+ static bool cleanup_slaves_registered = false;
+ if (!cleanup_slaves_registered)
+ {
+ atexit (cleanup_slaves);
+ at_fatal_signal (cleanup_slaves);
+ cleanup_slaves_registered = true;
+ }
+
+ /* Try to store the new slave in an unused entry of the slaves array. */
+ {
+ slaves_entry_t *s = slaves;
+ slaves_entry_t *s_end = s + slaves_count;
+
+ for (; s < s_end; s++)
+ if (!s->used)
+ {
+ /* The two uses of 'volatile' in the slaves_entry_t type above
+ (and ISO C 99 section 5.1.2.3.(5)) ensure that we mark the
+ entry as used only after the child pid has been written to the
+ memory location s->child. */
+ s->child = child;
+ s->used = 1;
+ return;
+ }
+ }
+
+ if (slaves_count == slaves_allocated)
+ {
+ /* Extend the slaves array. Note that we cannot use xrealloc(),
+ because then the cleanup_slaves() function could access an already
+ deallocated array. */
+ slaves_entry_t *old_slaves = slaves;
+ size_t new_slaves_allocated = 2 * slaves_allocated;
+ slaves_entry_t *new_slaves =
+ (slaves_entry_t *)
+ malloc (new_slaves_allocated * sizeof (slaves_entry_t));
+ if (new_slaves == NULL)
+ {
+ /* xalloc_die() will call exit() which will invoke cleanup_slaves().
+ Additionally we need to kill child, because it's not yet among
+ the slaves list. */
+ kill (child, TERMINATOR);
+ xalloc_die ();
+ }
+ memcpy (new_slaves, old_slaves,
+ slaves_allocated * sizeof (slaves_entry_t));
+ slaves = new_slaves;
+ slaves_allocated = new_slaves_allocated;
+ /* Now we can free the old slaves array. */
+ if (old_slaves != static_slaves)
+ free (old_slaves);
+ }
+ /* The three uses of 'volatile' in the types above (and ISO C 99 section
+ 5.1.2.3.(5)) ensure that we increment the slaves_count only after the
+ new slave and its 'used' bit have been written to the memory locations
+ that make up slaves[slaves_count]. */
+ slaves[slaves_count].child = child;
+ slaves[slaves_count].used = 1;
+ slaves_count++;
+}
+
+/* Unregister a child from the list of slave subprocesses. */
+static void
+unregister_slave_subprocess (pid_t child)
+{
+ /* The easiest way to remove an entry from a list that can be used by
+ an asynchronous signal handler is just to mark it as unused. For this,
+ we rely on sig_atomic_t. */
+ slaves_entry_t *s = slaves;
+ slaves_entry_t *s_end = s + slaves_count;
+
+ for (; s < s_end; s++)
+ if (s->used && s->child == child)
+ s->used = 0;
+}
+
+
+/* Wait for a subprocess to finish. Return its exit code.
+ If it didn't terminate correctly, exit if exit_on_error is true, otherwise
+ return 127. */
+int
+wait_subprocess (pid_t child, const char *progname,
+ bool ignore_sigpipe, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int *termsigp)
+{
+#if HAVE_WAITID && defined WNOWAIT && 0
+ /* Commented out because waitid() without WEXITED and with WNOWAIT doesn't
+ work: On Solaris 7 and OSF/1 4.0, it returns -1 and sets errno = ECHILD,
+ and on HP-UX 10.20 it just hangs. */
+ /* Use of waitid() with WNOWAIT avoids a race condition: If slave_process is
+ true, and this process sleeps a very long time between the return from
+ waitpid() and the execution of unregister_slave_subprocess(), and
+ meanwhile another process acquires the same PID as child, and then - still
+ before unregister_slave_subprocess() - this process gets a fatal signal,
+ it would kill the other totally unrelated process. */
+ siginfo_t info;
+
+ if (termsigp != NULL)
+ *termsigp = 0;
+ for (;;)
+ {
+ if (waitid (P_PID, child, &info, WEXITED | (slave_process ? WNOWAIT : 0))
+ < 0)
+ {
+# ifdef EINTR
+ if (errno == EINTR)
+ continue;
+# endif
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, errno,
+ _("%s subprocess"), progname);
+ return 127;
+ }
+
+ /* info.si_code is set to one of CLD_EXITED, CLD_KILLED, CLD_DUMPED,
+ CLD_TRAPPED, CLD_STOPPED, CLD_CONTINUED. Loop until the program
+ terminates. */
+ if (info.si_code == CLD_EXITED
+ || info.si_code == CLD_KILLED || info.si_code == CLD_DUMPED)
+ break;
+ }
+
+ /* The child process has exited or was signalled. */
+
+ if (slave_process)
+ {
+ /* Unregister the child from the list of slave subprocesses, so that
+ later, when we exit, we don't kill a totally unrelated process which
+ may have acquired the same pid. */
+ unregister_slave_subprocess (child);
+
+ /* Now remove the zombie from the process list. */
+ for (;;)
+ {
+ if (waitid (P_PID, child, &info, WEXITED) < 0)
+ {
+# ifdef EINTR
+ if (errno == EINTR)
+ continue;
+# endif
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, errno,
+ _("%s subprocess"), progname);
+ return 127;
+ }
+ break;
+ }
+ }
+
+ switch (info.si_code)
+ {
+ case CLD_KILLED:
+ case CLD_DUMPED:
+ if (termsigp != NULL)
+ *termsigp = info.si_status; /* TODO: or info.si_signo? */
+# ifdef SIGPIPE
+ if (info.si_status == SIGPIPE && ignore_sigpipe)
+ return 0;
+# endif
+ if (exit_on_error || (!null_stderr && termsigp == NULL))
+ error (exit_on_error ? EXIT_FAILURE : 0, 0,
+ _("%s subprocess got fatal signal %d"),
+ progname, info.si_status);
+ return 127;
+ case CLD_EXITED:
+ if (info.si_status == 127)
+ {
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, 0,
+ _("%s subprocess failed"), progname);
+ return 127;
+ }
+ return info.si_status;
+ default:
+ abort ();
+ }
+#else
+ /* waitpid() is just as portable as wait() nowadays. */
+ int status;
+
+ if (termsigp != NULL)
+ *termsigp = 0;
+ status = 0;
+ for (;;)
+ {
+ int result = waitpid (child, &status, 0);
+
+ if (result != child)
+ {
+# ifdef EINTR
+ if (errno == EINTR)
+ continue;
+# endif
+# if 0 /* defined ECHILD */
+ if (errno == ECHILD)
+ {
+ /* Child process nonexistent?! Assume it terminated
+ successfully. */
+ status = 0;
+ break;
+ }
+# endif
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, errno,
+ _("%s subprocess"), progname);
+ return 127;
+ }
+
+ /* One of WIFSIGNALED (status), WIFEXITED (status), WIFSTOPPED (status)
+ must always be true, since we did not specify WCONTINUED in the
+ waitpid() call. Loop until the program terminates. */
+ if (!WIFSTOPPED (status))
+ break;
+ }
+
+ /* The child process has exited or was signalled. */
+
+ if (slave_process)
+ /* Unregister the child from the list of slave subprocesses, so that
+ later, when we exit, we don't kill a totally unrelated process which
+ may have acquired the same pid. */
+ unregister_slave_subprocess (child);
+
+ if (WIFSIGNALED (status))
+ {
+ if (termsigp != NULL)
+ *termsigp = WTERMSIG (status);
+# ifdef SIGPIPE
+ if (WTERMSIG (status) == SIGPIPE && ignore_sigpipe)
+ return 0;
+# endif
+ if (exit_on_error || (!null_stderr && termsigp == NULL))
+ error (exit_on_error ? EXIT_FAILURE : 0, 0,
+ _("%s subprocess got fatal signal %d"),
+ progname, (int) WTERMSIG (status));
+ return 127;
+ }
+ if (!WIFEXITED (status))
+ abort ();
+ if (WEXITSTATUS (status) == 127)
+ {
+ if (exit_on_error || !null_stderr)
+ error (exit_on_error ? EXIT_FAILURE : 0, 0,
+ _("%s subprocess failed"), progname);
+ return 127;
+ }
+ return WEXITSTATUS (status);
+#endif
+}
diff --git a/contrib/tools/bison/gnulib/src/wait-process.h b/contrib/tools/bison/gnulib/src/wait-process.h
index 6d8f0d2b94..14aec0c194 100644
--- a/contrib/tools/bison/gnulib/src/wait-process.h
+++ b/contrib/tools/bison/gnulib/src/wait-process.h
@@ -1,74 +1,74 @@
-/* Waiting for a subprocess to finish.
- Copyright (C) 2001-2003, 2006, 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <haible@clisp.cons.org>, 2001.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _WAIT_PROCESS_H
-#define _WAIT_PROCESS_H
-
-/* Get pid_t. */
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include <stdbool.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Wait for a subprocess to finish. Return its exit code.
- If it didn't terminate correctly, exit if exit_on_error is true, otherwise
- return 127.
- Arguments:
- - child is the pid of the subprocess.
- - progname is the name of the program executed by the subprocess, used for
- error messages.
- - If ignore_sigpipe is true, consider a subprocess termination due to
- SIGPIPE as equivalent to a success. This is suitable for processes whose
- only purpose is to write to standard output. This flag can be safely set
- to false when the process' standard output is known to go to DEV_NULL.
- - If null_stderr is true, the usual error message to stderr will be omitted.
- This is suitable when the subprocess does not fulfill an important task.
- - slave_process should be set to true if the process has been launched as a
- slave process.
- - If exit_on_error is true, any error will cause the main process to exit
- with an error status.
- - If termsigp is not NULL: *termsig will be set to the signal that
- terminated the subprocess (if supported by the platform: not on native
- Windows platforms), otherwise 0, and the error message about the signal
- that terminated the subprocess will be omitted.
- Prerequisites: The signal handler for SIGCHLD should not be set to SIG_IGN,
- otherwise this function will not work. */
-extern int wait_subprocess (pid_t child, const char *progname,
- bool ignore_sigpipe, bool null_stderr,
- bool slave_process, bool exit_on_error,
- int *termsigp);
-
-/* Register a subprocess as being a slave process. This means that the
- subprocess will be terminated when its creator receives a catchable fatal
- signal or exits normally. Registration ends when wait_subprocess()
- notices that the subprocess has exited. */
-extern void register_slave_subprocess (pid_t child);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _WAIT_PROCESS_H */
+/* Waiting for a subprocess to finish.
+ Copyright (C) 2001-2003, 2006, 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <haible@clisp.cons.org>, 2001.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _WAIT_PROCESS_H
+#define _WAIT_PROCESS_H
+
+/* Get pid_t. */
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <stdbool.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Wait for a subprocess to finish. Return its exit code.
+ If it didn't terminate correctly, exit if exit_on_error is true, otherwise
+ return 127.
+ Arguments:
+ - child is the pid of the subprocess.
+ - progname is the name of the program executed by the subprocess, used for
+ error messages.
+ - If ignore_sigpipe is true, consider a subprocess termination due to
+ SIGPIPE as equivalent to a success. This is suitable for processes whose
+ only purpose is to write to standard output. This flag can be safely set
+ to false when the process' standard output is known to go to DEV_NULL.
+ - If null_stderr is true, the usual error message to stderr will be omitted.
+ This is suitable when the subprocess does not fulfill an important task.
+ - slave_process should be set to true if the process has been launched as a
+ slave process.
+ - If exit_on_error is true, any error will cause the main process to exit
+ with an error status.
+ - If termsigp is not NULL: *termsig will be set to the signal that
+ terminated the subprocess (if supported by the platform: not on native
+ Windows platforms), otherwise 0, and the error message about the signal
+ that terminated the subprocess will be omitted.
+ Prerequisites: The signal handler for SIGCHLD should not be set to SIG_IGN,
+ otherwise this function will not work. */
+extern int wait_subprocess (pid_t child, const char *progname,
+ bool ignore_sigpipe, bool null_stderr,
+ bool slave_process, bool exit_on_error,
+ int *termsigp);
+
+/* Register a subprocess as being a slave process. This means that the
+ subprocess will be terminated when its creator receives a catchable fatal
+ signal or exits normally. Registration ends when wait_subprocess()
+ notices that the subprocess has exited. */
+extern void register_slave_subprocess (pid_t child);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _WAIT_PROCESS_H */
diff --git a/contrib/tools/bison/gnulib/src/waitpid.c b/contrib/tools/bison/gnulib/src/waitpid.c
index d28a70b3ea..76327c66cd 100644
--- a/contrib/tools/bison/gnulib/src/waitpid.c
+++ b/contrib/tools/bison/gnulib/src/waitpid.c
@@ -1,30 +1,30 @@
-/* Wait for process state change.
- Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <sys/wait.h>
-
-/* Implementation for native Windows systems. */
-
-#include <process.h> /* for _cwait, WAIT_CHILD */
-
-pid_t
-waitpid (pid_t pid, int *statusp, int options)
-{
- return _cwait (statusp, pid, WAIT_CHILD);
-}
+/* Wait for process state change.
+ Copyright (C) 2001-2003, 2005-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <sys/wait.h>
+
+/* Implementation for native Windows systems. */
+
+#include <process.h> /* for _cwait, WAIT_CHILD */
+
+pid_t
+waitpid (pid_t pid, int *statusp, int options)
+{
+ return _cwait (statusp, pid, WAIT_CHILD);
+}
diff --git a/contrib/tools/bison/gnulib/src/wcrtomb.c b/contrib/tools/bison/gnulib/src/wcrtomb.c
index c3cda35803..7bab1ba5ba 100644
--- a/contrib/tools/bison/gnulib/src/wcrtomb.c
+++ b/contrib/tools/bison/gnulib/src/wcrtomb.c
@@ -1,56 +1,56 @@
-/* Convert wide character to multibyte character.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2008.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <wchar.h>
-
-#include <errno.h>
-#include <stdlib.h>
-
-
+/* Convert wide character to multibyte character.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+#include <errno.h>
+#include <stdlib.h>
+
+
// wcrtomb is defined for msvs 2017 15.7
#if _MSC_VER < 1914
-size_t
-wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
-{
- /* This implementation of wcrtomb on top of wctomb() supports only
- stateless encodings. ps must be in the initial state. */
- if (ps != NULL && !mbsinit (ps))
- {
- errno = EINVAL;
- return (size_t)(-1);
- }
-
- if (s == NULL)
- /* We know the NUL wide character corresponds to the NUL character. */
- return 1;
- else
- {
- int ret = wctomb (s, wc);
-
- if (ret >= 0)
- return ret;
- else
- {
- errno = EILSEQ;
- return (size_t)(-1);
- }
- }
-}
+size_t
+wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
+{
+ /* This implementation of wcrtomb on top of wctomb() supports only
+ stateless encodings. ps must be in the initial state. */
+ if (ps != NULL && !mbsinit (ps))
+ {
+ errno = EINVAL;
+ return (size_t)(-1);
+ }
+
+ if (s == NULL)
+ /* We know the NUL wide character corresponds to the NUL character. */
+ return 1;
+ else
+ {
+ int ret = wctomb (s, wc);
+
+ if (ret >= 0)
+ return ret;
+ else
+ {
+ errno = EILSEQ;
+ return (size_t)(-1);
+ }
+ }
+}
#endif
diff --git a/contrib/tools/bison/gnulib/src/wctype-h.c b/contrib/tools/bison/gnulib/src/wctype-h.c
index bb5f847e33..94af461438 100644
--- a/contrib/tools/bison/gnulib/src/wctype-h.c
+++ b/contrib/tools/bison/gnulib/src/wctype-h.c
@@ -1,4 +1,4 @@
-/* Normally this would be wctype.c, but that name's already taken. */
-#include <config.h>
-#define _GL_WCTYPE_INLINE _GL_EXTERN_INLINE
-#include "wctype.h"
+/* Normally this would be wctype.c, but that name's already taken. */
+#include <config.h>
+#define _GL_WCTYPE_INLINE _GL_EXTERN_INLINE
+#include "wctype.h"
diff --git a/contrib/tools/bison/gnulib/src/wcwidth.c b/contrib/tools/bison/gnulib/src/wcwidth.c
index 253fcaa656..3d00542db7 100644
--- a/contrib/tools/bison/gnulib/src/wcwidth.c
+++ b/contrib/tools/bison/gnulib/src/wcwidth.c
@@ -1,50 +1,50 @@
-/* Determine the number of screen columns needed for a character.
- Copyright (C) 2006-2007, 2010-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include <wchar.h>
-
-/* Get iswprint. */
-#include <wctype.h>
-
-#include "localcharset.h"
-#include "streq.h"
-#include "uniwidth.h"
-
-int
-wcwidth (wchar_t wc)
-#undef wcwidth
-{
- /* In UTF-8 locales, use a Unicode aware width function. */
- const char *encoding = locale_charset ();
- if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0))
- {
- /* We assume that in a UTF-8 locale, a wide character is the same as a
- Unicode character. */
- return uc_width (wc, encoding);
- }
- else
- {
- /* Otherwise, fall back to the system's wcwidth function. */
-#if HAVE_WCWIDTH
- return wcwidth (wc);
-#else
- return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
-#endif
- }
-}
+/* Determine the number of screen columns needed for a character.
+ Copyright (C) 2006-2007, 2010-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+/* Get iswprint. */
+#include <wctype.h>
+
+#include "localcharset.h"
+#include "streq.h"
+#include "uniwidth.h"
+
+int
+wcwidth (wchar_t wc)
+#undef wcwidth
+{
+ /* In UTF-8 locales, use a Unicode aware width function. */
+ const char *encoding = locale_charset ();
+ if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0))
+ {
+ /* We assume that in a UTF-8 locale, a wide character is the same as a
+ Unicode character. */
+ return uc_width (wc, encoding);
+ }
+ else
+ {
+ /* Otherwise, fall back to the system's wcwidth function. */
+#if HAVE_WCWIDTH
+ return wcwidth (wc);
+#else
+ return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
+#endif
+ }
+}
diff --git a/contrib/tools/bison/gnulib/src/xalloc-die.c b/contrib/tools/bison/gnulib/src/xalloc-die.c
index daa403b9c8..0cb3b4a274 100644
--- a/contrib/tools/bison/gnulib/src/xalloc-die.c
+++ b/contrib/tools/bison/gnulib/src/xalloc-die.c
@@ -1,41 +1,41 @@
-/* Report a memory allocation failure and exit.
-
- Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2013 Free Software
- Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "xalloc.h"
-
-#include <stdlib.h>
-
-#include "error.h"
-#include "exitfail.h"
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
-void
-xalloc_die (void)
-{
- error (exit_failure, 0, "%s", _("memory exhausted"));
-
- /* _Noreturn cannot be given to error, since it may return if
- its first argument is 0. To help compilers understand the
- xalloc_die does not return, call abort. Also, the abort is a
- safety feature if exit_failure is 0 (which shouldn't happen). */
- abort ();
-}
+/* Report a memory allocation failure and exit.
+
+ Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "xalloc.h"
+
+#include <stdlib.h>
+
+#include "error.h"
+#include "exitfail.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+void
+xalloc_die (void)
+{
+ error (exit_failure, 0, "%s", _("memory exhausted"));
+
+ /* _Noreturn cannot be given to error, since it may return if
+ its first argument is 0. To help compilers understand the
+ xalloc_die does not return, call abort. Also, the abort is a
+ safety feature if exit_failure is 0 (which shouldn't happen). */
+ abort ();
+}
diff --git a/contrib/tools/bison/gnulib/src/xalloc-oversized.h b/contrib/tools/bison/gnulib/src/xalloc-oversized.h
index a971c78ad3..5b97cedb2e 100644
--- a/contrib/tools/bison/gnulib/src/xalloc-oversized.h
+++ b/contrib/tools/bison/gnulib/src/xalloc-oversized.h
@@ -1,38 +1,38 @@
-/* xalloc-oversized.h -- memory allocation size checking
-
- Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef XALLOC_OVERSIZED_H_
-# define XALLOC_OVERSIZED_H_
-
-# include <stddef.h>
-
-/* Return 1 if an array of N objects, each of size S, cannot exist due
- to size arithmetic overflow. S must be positive and N must be
- nonnegative. This is a macro, not a function, so that it
- works correctly even when SIZE_MAX < N.
-
- By gnulib convention, SIZE_MAX represents overflow in size
- calculations, so the conservative dividend to use here is
- SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
- However, malloc (SIZE_MAX) fails on all known hosts where
- sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
- exactly-SIZE_MAX allocations on such hosts; this avoids a test and
- branch when S is known to be 1. */
-# define xalloc_oversized(n, s) \
- ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
-
-#endif /* !XALLOC_OVERSIZED_H_ */
+/* xalloc-oversized.h -- memory allocation size checking
+
+ Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef XALLOC_OVERSIZED_H_
+# define XALLOC_OVERSIZED_H_
+
+# include <stddef.h>
+
+/* Return 1 if an array of N objects, each of size S, cannot exist due
+ to size arithmetic overflow. S must be positive and N must be
+ nonnegative. This is a macro, not a function, so that it
+ works correctly even when SIZE_MAX < N.
+
+ By gnulib convention, SIZE_MAX represents overflow in size
+ calculations, so the conservative dividend to use here is
+ SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
+ However, malloc (SIZE_MAX) fails on all known hosts where
+ sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
+ exactly-SIZE_MAX allocations on such hosts; this avoids a test and
+ branch when S is known to be 1. */
+# define xalloc_oversized(n, s) \
+ ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
+
+#endif /* !XALLOC_OVERSIZED_H_ */
diff --git a/contrib/tools/bison/gnulib/src/xalloc.h b/contrib/tools/bison/gnulib/src/xalloc.h
index 6c9b53bf6f..8a841082a1 100644
--- a/contrib/tools/bison/gnulib/src/xalloc.h
+++ b/contrib/tools/bison/gnulib/src/xalloc.h
@@ -1,263 +1,263 @@
-/* xalloc.h -- malloc with out-of-memory checking
-
- Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef XALLOC_H_
-#define XALLOC_H_
-
-#include <stddef.h>
-
-#include "xalloc-oversized.h"
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef XALLOC_INLINE
-# define XALLOC_INLINE _GL_INLINE
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#if __GNUC__ >= 3
-# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
-#else
-# define _GL_ATTRIBUTE_MALLOC
-#endif
-
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
-# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
-#else
-# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
-#endif
-
-/* This function is always triggered when memory is exhausted.
- It must be defined by the application, either explicitly
- or by using gnulib's xalloc-die module. This is the
- function to call when one wants the program to die because of a
- memory allocation failure. */
-extern _Noreturn void xalloc_die (void);
-
-void *xmalloc (size_t s)
- _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
-void *xzalloc (size_t s)
- _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
-void *xcalloc (size_t n, size_t s)
- _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
-void *xrealloc (void *p, size_t s)
- _GL_ATTRIBUTE_ALLOC_SIZE ((2));
-void *x2realloc (void *p, size_t *pn);
-void *xmemdup (void const *p, size_t s)
- _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2));
-char *xstrdup (char const *str)
- _GL_ATTRIBUTE_MALLOC;
-
-/* In the following macros, T must be an elementary or structure/union or
- typedef'ed type, or a pointer to such a type. To apply one of the
- following macros to a function pointer or array type, you need to typedef
- it first and use the typedef name. */
-
-/* Allocate an object of type T dynamically, with error checking. */
-/* extern t *XMALLOC (typename t); */
-#define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
-
-/* Allocate memory for N elements of type T, with error checking. */
-/* extern t *XNMALLOC (size_t n, typename t); */
-#define XNMALLOC(n, t) \
- ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
-
-/* Allocate an object of type T dynamically, with error checking,
- and zero it. */
-/* extern t *XZALLOC (typename t); */
-#define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
-
-/* Allocate memory for N elements of type T, with error checking,
- and zero it. */
-/* extern t *XCALLOC (size_t n, typename t); */
-#define XCALLOC(n, t) \
- ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
-
-
-/* Allocate an array of N objects, each with S bytes of memory,
- dynamically, with error checking. S must be nonzero. */
-
-XALLOC_INLINE void *xnmalloc (size_t n, size_t s)
- _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
-XALLOC_INLINE void *
-xnmalloc (size_t n, size_t s)
-{
- if (xalloc_oversized (n, s))
- xalloc_die ();
- return xmalloc (n * s);
-}
-
-/* Change the size of an allocated block of memory P to an array of N
- objects each of S bytes, with error checking. S must be nonzero. */
-
-XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s)
- _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
-XALLOC_INLINE void *
-xnrealloc (void *p, size_t n, size_t s)
-{
- if (xalloc_oversized (n, s))
- xalloc_die ();
- return xrealloc (p, n * s);
-}
-
-/* If P is null, allocate a block of at least *PN such objects;
- otherwise, reallocate P so that it contains more than *PN objects
- each of S bytes. *PN must be nonzero unless P is null, and S must
- be nonzero. Set *PN to the new number of objects, and return the
- pointer to the new block. *PN is never set to zero, and the
- returned pointer is never null.
-
- Repeated reallocations are guaranteed to make progress, either by
- allocating an initial block with a nonzero size, or by allocating a
- larger block.
-
- In the following implementation, nonzero sizes are increased by a
- factor of approximately 1.5 so that repeated reallocations have
- O(N) overall cost rather than O(N**2) cost, but the
- specification for this function does not guarantee that rate.
-
- Here is an example of use:
-
- int *p = NULL;
- size_t used = 0;
- size_t allocated = 0;
-
- void
- append_int (int value)
- {
- if (used == allocated)
- p = x2nrealloc (p, &allocated, sizeof *p);
- p[used++] = value;
- }
-
- This causes x2nrealloc to allocate a block of some nonzero size the
- first time it is called.
-
- To have finer-grained control over the initial size, set *PN to a
- nonzero value before calling this function with P == NULL. For
- example:
-
- int *p = NULL;
- size_t used = 0;
- size_t allocated = 0;
- size_t allocated1 = 1000;
-
- void
- append_int (int value)
- {
- if (used == allocated)
- {
- p = x2nrealloc (p, &allocated1, sizeof *p);
- allocated = allocated1;
- }
- p[used++] = value;
- }
-
- */
-
-XALLOC_INLINE void *
-x2nrealloc (void *p, size_t *pn, size_t s)
-{
- size_t n = *pn;
-
- if (! p)
- {
- if (! n)
- {
- /* The approximate size to use for initial small allocation
- requests, when the invoking code specifies an old size of
- zero. This is the largest "small" request for the GNU C
- library malloc. */
- enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
-
- n = DEFAULT_MXFAST / s;
- n += !n;
- }
- }
- else
- {
- /* Set N = ceil (1.5 * N) so that progress is made if N == 1.
- Check for overflow, so that N * S stays in size_t range.
- The check is slightly conservative, but an exact check isn't
- worth the trouble. */
- if ((size_t) -1 / 3 * 2 / s <= n)
- xalloc_die ();
- n += (n + 1) / 2;
- }
-
- *pn = n;
- return xrealloc (p, n * s);
-}
-
-/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
- except it returns char *. */
-
-XALLOC_INLINE char *xcharalloc (size_t n)
- _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
-XALLOC_INLINE char *
-xcharalloc (size_t n)
-{
- return XNMALLOC (n, char);
-}
-
-#ifdef __cplusplus
-}
-
-/* C++ does not allow conversions from void * to other pointer types
- without a cast. Use templates to work around the problem when
- possible. */
-
-template <typename T> inline T *
-xrealloc (T *p, size_t s)
-{
- return (T *) xrealloc ((void *) p, s);
-}
-
-template <typename T> inline T *
-xnrealloc (T *p, size_t n, size_t s)
-{
- return (T *) xnrealloc ((void *) p, n, s);
-}
-
-template <typename T> inline T *
-x2realloc (T *p, size_t *pn)
-{
- return (T *) x2realloc ((void *) p, pn);
-}
-
-template <typename T> inline T *
-x2nrealloc (T *p, size_t *pn, size_t s)
-{
- return (T *) x2nrealloc ((void *) p, pn, s);
-}
-
-template <typename T> inline T *
-xmemdup (T const *p, size_t s)
-{
- return (T *) xmemdup ((void const *) p, s);
-}
-
-#endif
-
-
-#endif /* !XALLOC_H_ */
+/* xalloc.h -- malloc with out-of-memory checking
+
+ Copyright (C) 1990-2000, 2003-2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef XALLOC_H_
+#define XALLOC_H_
+
+#include <stddef.h>
+
+#include "xalloc-oversized.h"
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef XALLOC_INLINE
+# define XALLOC_INLINE _GL_INLINE
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if __GNUC__ >= 3
+# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
+#else
+# define _GL_ATTRIBUTE_MALLOC
+#endif
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
+#else
+# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
+#endif
+
+/* This function is always triggered when memory is exhausted.
+ It must be defined by the application, either explicitly
+ or by using gnulib's xalloc-die module. This is the
+ function to call when one wants the program to die because of a
+ memory allocation failure. */
+extern _Noreturn void xalloc_die (void);
+
+void *xmalloc (size_t s)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
+void *xzalloc (size_t s)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
+void *xcalloc (size_t n, size_t s)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
+void *xrealloc (void *p, size_t s)
+ _GL_ATTRIBUTE_ALLOC_SIZE ((2));
+void *x2realloc (void *p, size_t *pn);
+void *xmemdup (void const *p, size_t s)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2));
+char *xstrdup (char const *str)
+ _GL_ATTRIBUTE_MALLOC;
+
+/* In the following macros, T must be an elementary or structure/union or
+ typedef'ed type, or a pointer to such a type. To apply one of the
+ following macros to a function pointer or array type, you need to typedef
+ it first and use the typedef name. */
+
+/* Allocate an object of type T dynamically, with error checking. */
+/* extern t *XMALLOC (typename t); */
+#define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
+
+/* Allocate memory for N elements of type T, with error checking. */
+/* extern t *XNMALLOC (size_t n, typename t); */
+#define XNMALLOC(n, t) \
+ ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
+
+/* Allocate an object of type T dynamically, with error checking,
+ and zero it. */
+/* extern t *XZALLOC (typename t); */
+#define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
+
+/* Allocate memory for N elements of type T, with error checking,
+ and zero it. */
+/* extern t *XCALLOC (size_t n, typename t); */
+#define XCALLOC(n, t) \
+ ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
+
+
+/* Allocate an array of N objects, each with S bytes of memory,
+ dynamically, with error checking. S must be nonzero. */
+
+XALLOC_INLINE void *xnmalloc (size_t n, size_t s)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
+XALLOC_INLINE void *
+xnmalloc (size_t n, size_t s)
+{
+ if (xalloc_oversized (n, s))
+ xalloc_die ();
+ return xmalloc (n * s);
+}
+
+/* Change the size of an allocated block of memory P to an array of N
+ objects each of S bytes, with error checking. S must be nonzero. */
+
+XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s)
+ _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
+XALLOC_INLINE void *
+xnrealloc (void *p, size_t n, size_t s)
+{
+ if (xalloc_oversized (n, s))
+ xalloc_die ();
+ return xrealloc (p, n * s);
+}
+
+/* If P is null, allocate a block of at least *PN such objects;
+ otherwise, reallocate P so that it contains more than *PN objects
+ each of S bytes. *PN must be nonzero unless P is null, and S must
+ be nonzero. Set *PN to the new number of objects, and return the
+ pointer to the new block. *PN is never set to zero, and the
+ returned pointer is never null.
+
+ Repeated reallocations are guaranteed to make progress, either by
+ allocating an initial block with a nonzero size, or by allocating a
+ larger block.
+
+ In the following implementation, nonzero sizes are increased by a
+ factor of approximately 1.5 so that repeated reallocations have
+ O(N) overall cost rather than O(N**2) cost, but the
+ specification for this function does not guarantee that rate.
+
+ Here is an example of use:
+
+ int *p = NULL;
+ size_t used = 0;
+ size_t allocated = 0;
+
+ void
+ append_int (int value)
+ {
+ if (used == allocated)
+ p = x2nrealloc (p, &allocated, sizeof *p);
+ p[used++] = value;
+ }
+
+ This causes x2nrealloc to allocate a block of some nonzero size the
+ first time it is called.
+
+ To have finer-grained control over the initial size, set *PN to a
+ nonzero value before calling this function with P == NULL. For
+ example:
+
+ int *p = NULL;
+ size_t used = 0;
+ size_t allocated = 0;
+ size_t allocated1 = 1000;
+
+ void
+ append_int (int value)
+ {
+ if (used == allocated)
+ {
+ p = x2nrealloc (p, &allocated1, sizeof *p);
+ allocated = allocated1;
+ }
+ p[used++] = value;
+ }
+
+ */
+
+XALLOC_INLINE void *
+x2nrealloc (void *p, size_t *pn, size_t s)
+{
+ size_t n = *pn;
+
+ if (! p)
+ {
+ if (! n)
+ {
+ /* The approximate size to use for initial small allocation
+ requests, when the invoking code specifies an old size of
+ zero. This is the largest "small" request for the GNU C
+ library malloc. */
+ enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
+
+ n = DEFAULT_MXFAST / s;
+ n += !n;
+ }
+ }
+ else
+ {
+ /* Set N = ceil (1.5 * N) so that progress is made if N == 1.
+ Check for overflow, so that N * S stays in size_t range.
+ The check is slightly conservative, but an exact check isn't
+ worth the trouble. */
+ if ((size_t) -1 / 3 * 2 / s <= n)
+ xalloc_die ();
+ n += (n + 1) / 2;
+ }
+
+ *pn = n;
+ return xrealloc (p, n * s);
+}
+
+/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
+ except it returns char *. */
+
+XALLOC_INLINE char *xcharalloc (size_t n)
+ _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
+XALLOC_INLINE char *
+xcharalloc (size_t n)
+{
+ return XNMALLOC (n, char);
+}
+
+#ifdef __cplusplus
+}
+
+/* C++ does not allow conversions from void * to other pointer types
+ without a cast. Use templates to work around the problem when
+ possible. */
+
+template <typename T> inline T *
+xrealloc (T *p, size_t s)
+{
+ return (T *) xrealloc ((void *) p, s);
+}
+
+template <typename T> inline T *
+xnrealloc (T *p, size_t n, size_t s)
+{
+ return (T *) xnrealloc ((void *) p, n, s);
+}
+
+template <typename T> inline T *
+x2realloc (T *p, size_t *pn)
+{
+ return (T *) x2realloc ((void *) p, pn);
+}
+
+template <typename T> inline T *
+x2nrealloc (T *p, size_t *pn, size_t s)
+{
+ return (T *) x2nrealloc ((void *) p, pn, s);
+}
+
+template <typename T> inline T *
+xmemdup (T const *p, size_t s)
+{
+ return (T *) xmemdup ((void const *) p, s);
+}
+
+#endif
+
+
+#endif /* !XALLOC_H_ */
diff --git a/contrib/tools/bison/gnulib/src/xasprintf.c b/contrib/tools/bison/gnulib/src/xasprintf.c
index 1808b70182..07869ce179 100644
--- a/contrib/tools/bison/gnulib/src/xasprintf.c
+++ b/contrib/tools/bison/gnulib/src/xasprintf.c
@@ -1,34 +1,34 @@
-/* vasprintf and asprintf with out-of-memory checking.
- Copyright (C) 1999, 2002-2004, 2006, 2009-2013 Free Software Foundation,
- Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "xvasprintf.h"
-
-char *
-xasprintf (const char *format, ...)
-{
- va_list args;
- char *result;
-
- va_start (args, format);
- result = xvasprintf (format, args);
- va_end (args);
-
- return result;
-}
+/* vasprintf and asprintf with out-of-memory checking.
+ Copyright (C) 1999, 2002-2004, 2006, 2009-2013 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "xvasprintf.h"
+
+char *
+xasprintf (const char *format, ...)
+{
+ va_list args;
+ char *result;
+
+ va_start (args, format);
+ result = xvasprintf (format, args);
+ va_end (args);
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/xconcat-filename.c b/contrib/tools/bison/gnulib/src/xconcat-filename.c
index eb2f8a9fb1..547a9b750c 100644
--- a/contrib/tools/bison/gnulib/src/xconcat-filename.c
+++ b/contrib/tools/bison/gnulib/src/xconcat-filename.c
@@ -1,41 +1,41 @@
-/* Construct a full filename from a directory and a relative filename.
- Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or any
- later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Bruno Haible <haible@clisp.cons.org>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "concat-filename.h"
-
-#include "xalloc.h"
-
-/* Concatenate a directory filename, a relative filename and an optional
- suffix. The directory may end with the directory separator. The second
- argument may not start with the directory separator (it is relative).
- Return a freshly allocated filename. */
-char *
-xconcatenated_filename (const char *directory, const char *filename,
- const char *suffix)
-{
- char *result;
-
- result = concatenated_filename (directory, filename, suffix);
- if (result == NULL)
- xalloc_die ();
-
- return result;
-}
+/* Construct a full filename from a directory and a relative filename.
+ Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <haible@clisp.cons.org>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "concat-filename.h"
+
+#include "xalloc.h"
+
+/* Concatenate a directory filename, a relative filename and an optional
+ suffix. The directory may end with the directory separator. The second
+ argument may not start with the directory separator (it is relative).
+ Return a freshly allocated filename. */
+char *
+xconcatenated_filename (const char *directory, const char *filename,
+ const char *suffix)
+{
+ char *result;
+
+ result = concatenated_filename (directory, filename, suffix);
+ if (result == NULL)
+ xalloc_die ();
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/xmalloc.c b/contrib/tools/bison/gnulib/src/xmalloc.c
index 57e34b7cdb..a69a78aec5 100644
--- a/contrib/tools/bison/gnulib/src/xmalloc.c
+++ b/contrib/tools/bison/gnulib/src/xmalloc.c
@@ -1,122 +1,122 @@
-/* xmalloc.c -- malloc with out of memory checking
-
- Copyright (C) 1990-2000, 2002-2006, 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#define XALLOC_INLINE _GL_EXTERN_INLINE
-
-#include "xalloc.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-/* 1 if calloc is known to be compatible with GNU calloc. This
- matters if we are not also using the calloc module, which defines
- HAVE_CALLOC_GNU and supports the GNU API even on non-GNU platforms. */
-#if defined HAVE_CALLOC_GNU || (defined __GLIBC__ && !defined __UCLIBC__)
-enum { HAVE_GNU_CALLOC = 1 };
-#else
-enum { HAVE_GNU_CALLOC = 0 };
-#endif
-
-/* Allocate N bytes of memory dynamically, with error checking. */
-
-void *
-xmalloc (size_t n)
-{
- void *p = malloc (n);
- if (!p && n != 0)
- xalloc_die ();
- return p;
-}
-
-/* Change the size of an allocated block of memory P to N bytes,
- with error checking. */
-
-void *
-xrealloc (void *p, size_t n)
-{
- if (!n && p)
- {
- /* The GNU and C99 realloc behaviors disagree here. Act like
- GNU, even if the underlying realloc is C99. */
- free (p);
- return NULL;
- }
-
- p = realloc (p, n);
- if (!p && n)
- xalloc_die ();
- return p;
-}
-
-/* If P is null, allocate a block of at least *PN bytes; otherwise,
- reallocate P so that it contains more than *PN bytes. *PN must be
- nonzero unless P is null. Set *PN to the new block's size, and
- return the pointer to the new block. *PN is never set to zero, and
- the returned pointer is never null. */
-
-void *
-x2realloc (void *p, size_t *pn)
-{
- return x2nrealloc (p, pn, 1);
-}
-
-/* Allocate S bytes of zeroed memory dynamically, with error checking.
- There's no need for xnzalloc (N, S), since it would be equivalent
- to xcalloc (N, S). */
-
-void *
-xzalloc (size_t s)
-{
- return memset (xmalloc (s), 0, s);
-}
-
-/* Allocate zeroed memory for N elements of S bytes, with error
- checking. S must be nonzero. */
-
-void *
-xcalloc (size_t n, size_t s)
-{
- void *p;
- /* Test for overflow, since some calloc implementations don't have
- proper overflow checks. But omit overflow and size-zero tests if
- HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
- returns NULL if successful. */
- if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s))
- || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
- xalloc_die ();
- return p;
-}
-
-/* Clone an object P of size S, with error checking. There's no need
- for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
- need for an arithmetic overflow check. */
-
-void *
-xmemdup (void const *p, size_t s)
-{
- return memcpy (xmalloc (s), p, s);
-}
-
-/* Clone STRING. */
-
-char *
-xstrdup (char const *string)
-{
- return xmemdup (string, strlen (string) + 1);
-}
+/* xmalloc.c -- malloc with out of memory checking
+
+ Copyright (C) 1990-2000, 2002-2006, 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#define XALLOC_INLINE _GL_EXTERN_INLINE
+
+#include "xalloc.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/* 1 if calloc is known to be compatible with GNU calloc. This
+ matters if we are not also using the calloc module, which defines
+ HAVE_CALLOC_GNU and supports the GNU API even on non-GNU platforms. */
+#if defined HAVE_CALLOC_GNU || (defined __GLIBC__ && !defined __UCLIBC__)
+enum { HAVE_GNU_CALLOC = 1 };
+#else
+enum { HAVE_GNU_CALLOC = 0 };
+#endif
+
+/* Allocate N bytes of memory dynamically, with error checking. */
+
+void *
+xmalloc (size_t n)
+{
+ void *p = malloc (n);
+ if (!p && n != 0)
+ xalloc_die ();
+ return p;
+}
+
+/* Change the size of an allocated block of memory P to N bytes,
+ with error checking. */
+
+void *
+xrealloc (void *p, size_t n)
+{
+ if (!n && p)
+ {
+ /* The GNU and C99 realloc behaviors disagree here. Act like
+ GNU, even if the underlying realloc is C99. */
+ free (p);
+ return NULL;
+ }
+
+ p = realloc (p, n);
+ if (!p && n)
+ xalloc_die ();
+ return p;
+}
+
+/* If P is null, allocate a block of at least *PN bytes; otherwise,
+ reallocate P so that it contains more than *PN bytes. *PN must be
+ nonzero unless P is null. Set *PN to the new block's size, and
+ return the pointer to the new block. *PN is never set to zero, and
+ the returned pointer is never null. */
+
+void *
+x2realloc (void *p, size_t *pn)
+{
+ return x2nrealloc (p, pn, 1);
+}
+
+/* Allocate S bytes of zeroed memory dynamically, with error checking.
+ There's no need for xnzalloc (N, S), since it would be equivalent
+ to xcalloc (N, S). */
+
+void *
+xzalloc (size_t s)
+{
+ return memset (xmalloc (s), 0, s);
+}
+
+/* Allocate zeroed memory for N elements of S bytes, with error
+ checking. S must be nonzero. */
+
+void *
+xcalloc (size_t n, size_t s)
+{
+ void *p;
+ /* Test for overflow, since some calloc implementations don't have
+ proper overflow checks. But omit overflow and size-zero tests if
+ HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
+ returns NULL if successful. */
+ if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s))
+ || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
+ xalloc_die ();
+ return p;
+}
+
+/* Clone an object P of size S, with error checking. There's no need
+ for xnmemdup (P, N, S), since xmemdup (P, N * S) works without any
+ need for an arithmetic overflow check. */
+
+void *
+xmemdup (void const *p, size_t s)
+{
+ return memcpy (xmalloc (s), p, s);
+}
+
+/* Clone STRING. */
+
+char *
+xstrdup (char const *string)
+{
+ return xmemdup (string, strlen (string) + 1);
+}
diff --git a/contrib/tools/bison/gnulib/src/xmalloca.c b/contrib/tools/bison/gnulib/src/xmalloca.c
index 50ee4807fb..b250eb2ee2 100644
--- a/contrib/tools/bison/gnulib/src/xmalloca.c
+++ b/contrib/tools/bison/gnulib/src/xmalloca.c
@@ -1,38 +1,38 @@
-/* Safe automatic memory allocation with out of memory checking.
- Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2003.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "xmalloca.h"
-
-#include "xalloc.h"
-
-#if HAVE_ALLOCA
-
-void *
-xmmalloca (size_t n)
-{
- void *p;
-
- p = mmalloca (n);
- if (p == NULL)
- xalloc_die ();
- return p;
-}
-
-#endif
+/* Safe automatic memory allocation with out of memory checking.
+ Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "xmalloca.h"
+
+#include "xalloc.h"
+
+#if HAVE_ALLOCA
+
+void *
+xmmalloca (size_t n)
+{
+ void *p;
+
+ p = mmalloca (n);
+ if (p == NULL)
+ xalloc_die ();
+ return p;
+}
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/xmalloca.h b/contrib/tools/bison/gnulib/src/xmalloca.h
index 2f7567d498..343e5b1b36 100644
--- a/contrib/tools/bison/gnulib/src/xmalloca.h
+++ b/contrib/tools/bison/gnulib/src/xmalloca.h
@@ -1,64 +1,64 @@
-/* Safe automatic memory allocation with out of memory checking.
- Copyright (C) 2003, 2005, 2007, 2009-2013 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2003.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _XMALLOCA_H
-#define _XMALLOCA_H
-
-#include "malloca.h"
-#include "xalloc.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* xmalloca(N) is a checking safe variant of alloca(N). It allocates N bytes
- of memory allocated on the stack, that must be freed using freea() before
- the function returns. Upon failure, it exits with an error message. */
-#if HAVE_ALLOCA
-# define xmalloca(N) \
- ((N) < 4032 - sa_increment \
- ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \
- : xmmalloca (N))
-extern void * xmmalloca (size_t n);
-#else
-# define xmalloca(N) \
- xmalloc (N)
-#endif
-
-/* xnmalloca(N,S) is an overflow-safe variant of xmalloca (N * S).
- It allocates an array of N objects, each with S bytes of memory,
- on the stack. S must be positive and N must be nonnegative.
- The array must be freed using freea() before the function returns.
- Upon failure, it exits with an error message. */
-#if HAVE_ALLOCA
-/* Rely on xmalloca (SIZE_MAX) calling xalloc_die (). */
-# define xnmalloca(n, s) \
- xmalloca (xalloc_oversized ((n), (s)) ? (size_t) (-1) : (n) * (s))
-#else
-# define xnmalloca(n, s) \
- xnmalloc ((n), (s))
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* _XMALLOCA_H */
+/* Safe automatic memory allocation with out of memory checking.
+ Copyright (C) 2003, 2005, 2007, 2009-2013 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2003.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _XMALLOCA_H
+#define _XMALLOCA_H
+
+#include "malloca.h"
+#include "xalloc.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* xmalloca(N) is a checking safe variant of alloca(N). It allocates N bytes
+ of memory allocated on the stack, that must be freed using freea() before
+ the function returns. Upon failure, it exits with an error message. */
+#if HAVE_ALLOCA
+# define xmalloca(N) \
+ ((N) < 4032 - sa_increment \
+ ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \
+ : xmmalloca (N))
+extern void * xmmalloca (size_t n);
+#else
+# define xmalloca(N) \
+ xmalloc (N)
+#endif
+
+/* xnmalloca(N,S) is an overflow-safe variant of xmalloca (N * S).
+ It allocates an array of N objects, each with S bytes of memory,
+ on the stack. S must be positive and N must be nonnegative.
+ The array must be freed using freea() before the function returns.
+ Upon failure, it exits with an error message. */
+#if HAVE_ALLOCA
+/* Rely on xmalloca (SIZE_MAX) calling xalloc_die (). */
+# define xnmalloca(n, s) \
+ xmalloca (xalloc_oversized ((n), (s)) ? (size_t) (-1) : (n) * (s))
+#else
+# define xnmalloca(n, s) \
+ xnmalloc ((n), (s))
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _XMALLOCA_H */
diff --git a/contrib/tools/bison/gnulib/src/xmemdup0.c b/contrib/tools/bison/gnulib/src/xmemdup0.c
index c070fa6343..be8165bcbc 100644
--- a/contrib/tools/bison/gnulib/src/xmemdup0.c
+++ b/contrib/tools/bison/gnulib/src/xmemdup0.c
@@ -1,44 +1,44 @@
-/* xmemdup0.c -- copy a block of arbitrary bytes, plus a trailing NUL
-
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "xmemdup0.h"
-#include "xalloc.h"
-
-#include <string.h>
-
-/* Clone an arbitrary block of bytes P of size S, with error checking,
- and include a terminating NUL byte. P is of type 'void const *',
- to make it easier to use this with other mem* functions that return
- 'void *', but since appending a NUL byte only makes sense on bytes,
- the return type is 'char *'.
-
- The terminating NUL makes it safe to use strlen or rawmemchr to
- check for embedded NUL; it also speeds up algorithms such as escape
- sequence processing on arbitrary memory, by making it always safe
- to read the byte after the escape character rather than having to
- check if each escape character is the last byte in the object. */
-
-char *
-xmemdup0 (void const *p, size_t s)
-{
- char *result = xcharalloc (s + 1);
- memcpy (result, p, s);
- result[s] = 0;
- return result;
-}
+/* xmemdup0.c -- copy a block of arbitrary bytes, plus a trailing NUL
+
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "xmemdup0.h"
+#include "xalloc.h"
+
+#include <string.h>
+
+/* Clone an arbitrary block of bytes P of size S, with error checking,
+ and include a terminating NUL byte. P is of type 'void const *',
+ to make it easier to use this with other mem* functions that return
+ 'void *', but since appending a NUL byte only makes sense on bytes,
+ the return type is 'char *'.
+
+ The terminating NUL makes it safe to use strlen or rawmemchr to
+ check for embedded NUL; it also speeds up algorithms such as escape
+ sequence processing on arbitrary memory, by making it always safe
+ to read the byte after the escape character rather than having to
+ check if each escape character is the last byte in the object. */
+
+char *
+xmemdup0 (void const *p, size_t s)
+{
+ char *result = xcharalloc (s + 1);
+ memcpy (result, p, s);
+ result[s] = 0;
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/xmemdup0.h b/contrib/tools/bison/gnulib/src/xmemdup0.h
index 9ec827107a..33dced662b 100644
--- a/contrib/tools/bison/gnulib/src/xmemdup0.h
+++ b/contrib/tools/bison/gnulib/src/xmemdup0.h
@@ -1,41 +1,41 @@
-/* xmemdup0.h -- copy a block of arbitrary bytes, plus a trailing NUL
-
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef XMEMDUP_H_
-# define XMEMDUP_H_
-
-# include <stddef.h>
-
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-/* This function is always triggered when memory is exhausted.
- It must be defined by the application, either explicitly
- or by using gnulib's xalloc-die module. This is the
- function to call when one wants the program to die because of a
- memory allocation failure. */
-extern _Noreturn void xalloc_die (void);
-
-char *xmemdup0 (void const *p, size_t s);
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif /* !XMEMDUP0_H_ */
+/* xmemdup0.h -- copy a block of arbitrary bytes, plus a trailing NUL
+
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef XMEMDUP_H_
+# define XMEMDUP_H_
+
+# include <stddef.h>
+
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* This function is always triggered when memory is exhausted.
+ It must be defined by the application, either explicitly
+ or by using gnulib's xalloc-die module. This is the
+ function to call when one wants the program to die because of a
+ memory allocation failure. */
+extern _Noreturn void xalloc_die (void);
+
+char *xmemdup0 (void const *p, size_t s);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif /* !XMEMDUP0_H_ */
diff --git a/contrib/tools/bison/gnulib/src/xprintf.c b/contrib/tools/bison/gnulib/src/xprintf.c
index e24b4f1875..e94785f35b 100644
--- a/contrib/tools/bison/gnulib/src/xprintf.c
+++ b/contrib/tools/bison/gnulib/src/xprintf.c
@@ -1,79 +1,79 @@
-/* printf wrappers that fail immediately for non-file-related errors
- Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-#include "xprintf.h"
-
-#include <errno.h>
-
-#include "error.h"
-#include "exitfail.h"
-#include "gettext.h"
-
-/* written by Jim Meyering */
-
-/* Just like printf, but call error if it fails without setting the
- stream's error indicator. */
-int
-xprintf (char const *restrict format, ...)
-{
- va_list args;
- int retval;
- va_start (args, format);
- retval = xvprintf (format, args);
- va_end (args);
-
- return retval;
-}
-
-/* Just like vprintf, but call error if it fails without setting the
- stream's error indicator. */
-int
-xvprintf (char const *restrict format, va_list args)
-{
- int retval = vprintf (format, args);
- if (retval < 0 && ! ferror (stdout))
- error (exit_failure, errno, gettext ("cannot perform formatted output"));
-
- return retval;
-}
-
-/* Just like fprintf, but call error if it fails without setting the
- stream's error indicator. */
-int
-xfprintf (FILE *restrict stream, char const *restrict format, ...)
-{
- va_list args;
- int retval;
- va_start (args, format);
- retval = xvfprintf (stream, format, args);
- va_end (args);
-
- return retval;
-}
-
-/* Just like vfprintf, but call error if it fails without setting the
- stream's error indicator. */
-int
-xvfprintf (FILE *restrict stream, char const *restrict format, va_list args)
-{
- int retval = vfprintf (stream, format, args);
- if (retval < 0 && ! ferror (stream))
- error (exit_failure, errno, gettext ("cannot perform formatted output"));
-
- return retval;
-}
+/* printf wrappers that fail immediately for non-file-related errors
+ Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "xprintf.h"
+
+#include <errno.h>
+
+#include "error.h"
+#include "exitfail.h"
+#include "gettext.h"
+
+/* written by Jim Meyering */
+
+/* Just like printf, but call error if it fails without setting the
+ stream's error indicator. */
+int
+xprintf (char const *restrict format, ...)
+{
+ va_list args;
+ int retval;
+ va_start (args, format);
+ retval = xvprintf (format, args);
+ va_end (args);
+
+ return retval;
+}
+
+/* Just like vprintf, but call error if it fails without setting the
+ stream's error indicator. */
+int
+xvprintf (char const *restrict format, va_list args)
+{
+ int retval = vprintf (format, args);
+ if (retval < 0 && ! ferror (stdout))
+ error (exit_failure, errno, gettext ("cannot perform formatted output"));
+
+ return retval;
+}
+
+/* Just like fprintf, but call error if it fails without setting the
+ stream's error indicator. */
+int
+xfprintf (FILE *restrict stream, char const *restrict format, ...)
+{
+ va_list args;
+ int retval;
+ va_start (args, format);
+ retval = xvfprintf (stream, format, args);
+ va_end (args);
+
+ return retval;
+}
+
+/* Just like vfprintf, but call error if it fails without setting the
+ stream's error indicator. */
+int
+xvfprintf (FILE *restrict stream, char const *restrict format, va_list args)
+{
+ int retval = vfprintf (stream, format, args);
+ if (retval < 0 && ! ferror (stream))
+ error (exit_failure, errno, gettext ("cannot perform formatted output"));
+
+ return retval;
+}
diff --git a/contrib/tools/bison/gnulib/src/xprintf.h b/contrib/tools/bison/gnulib/src/xprintf.h
index 62986a8cee..c827f1293a 100644
--- a/contrib/tools/bison/gnulib/src/xprintf.h
+++ b/contrib/tools/bison/gnulib/src/xprintf.h
@@ -1,45 +1,45 @@
-/* printf wrappers that fail immediately for non-file-related errors
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _XPRINTF_H
-#define _XPRINTF_H
-
-#include <stdarg.h>
-#include <stdio.h>
-
-/* The __attribute__ feature is available in gcc versions 2.5 and later.
- The __-protected variants of the attributes 'format' and 'printf' are
- accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
- gnulib and libintl do '#define printf __printf__' when they override
- the 'printf' function. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
-#else
-# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
-#endif
-
-extern int xprintf (char const *restrict format, ...)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2));
-extern int xvprintf (char const *restrict format, va_list args)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0));
-extern int xfprintf (FILE *restrict stream, char const *restrict format, ...)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3));
-extern int xvfprintf (FILE *restrict stream, char const *restrict format,
- va_list args)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 0));
-
-#endif
+/* printf wrappers that fail immediately for non-file-related errors
+ Copyright (C) 2007-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _XPRINTF_H
+#define _XPRINTF_H
+
+#include <stdarg.h>
+#include <stdio.h>
+
+/* The __attribute__ feature is available in gcc versions 2.5 and later.
+ The __-protected variants of the attributes 'format' and 'printf' are
+ accepted by gcc versions 2.6.4 (effectively 2.7) and later.
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
+ gnulib and libintl do '#define printf __printf__' when they override
+ the 'printf' function. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+#else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
+#endif
+
+extern int xprintf (char const *restrict format, ...)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2));
+extern int xvprintf (char const *restrict format, va_list args)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0));
+extern int xfprintf (FILE *restrict stream, char const *restrict format, ...)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3));
+extern int xvfprintf (FILE *restrict stream, char const *restrict format,
+ va_list args)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 0));
+
+#endif
diff --git a/contrib/tools/bison/gnulib/src/xsize.c b/contrib/tools/bison/gnulib/src/xsize.c
index 4b4914c2ca..76226378a6 100644
--- a/contrib/tools/bison/gnulib/src/xsize.c
+++ b/contrib/tools/bison/gnulib/src/xsize.c
@@ -1,3 +1,3 @@
-#include <config.h>
-#define XSIZE_INLINE _GL_EXTERN_INLINE
-#include "xsize.h"
+#include <config.h>
+#define XSIZE_INLINE _GL_EXTERN_INLINE
+#include "xsize.h"
diff --git a/contrib/tools/bison/gnulib/src/xsize.h b/contrib/tools/bison/gnulib/src/xsize.h
index 5675593f54..34c5cb3daf 100644
--- a/contrib/tools/bison/gnulib/src/xsize.h
+++ b/contrib/tools/bison/gnulib/src/xsize.h
@@ -1,117 +1,117 @@
-/* xsize.h -- Checked size_t computations.
-
- Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _XSIZE_H
-#define _XSIZE_H
-
-/* Get size_t. */
-#include <stddef.h>
-
-/* Get SIZE_MAX. */
-#include <limits.h>
-#if HAVE_STDINT_H
-# include <stdint.h>
-#endif
-
-#ifndef _GL_INLINE_HEADER_BEGIN
- #error "Please include config.h first."
-#endif
-_GL_INLINE_HEADER_BEGIN
-#ifndef XSIZE_INLINE
-# define XSIZE_INLINE _GL_INLINE
-#endif
-
-/* The size of memory objects is often computed through expressions of
- type size_t. Example:
- void* p = malloc (header_size + n * element_size).
- These computations can lead to overflow. When this happens, malloc()
- returns a piece of memory that is way too small, and the program then
- crashes while attempting to fill the memory.
- To avoid this, the functions and macros in this file check for overflow.
- The convention is that SIZE_MAX represents overflow.
- malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc
- implementation that uses mmap --, it's recommended to use size_overflow_p()
- or size_in_bounds_p() before invoking malloc().
- The example thus becomes:
- size_t size = xsum (header_size, xtimes (n, element_size));
- void *p = (size_in_bounds_p (size) ? malloc (size) : NULL);
-*/
-
-/* Convert an arbitrary value >= 0 to type size_t. */
-#define xcast_size_t(N) \
- ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
-
-/* Sum of two sizes, with overflow check. */
-XSIZE_INLINE size_t
-#if __GNUC__ >= 3
-__attribute__ ((__pure__))
-#endif
-xsum (size_t size1, size_t size2)
-{
- size_t sum = size1 + size2;
- return (sum >= size1 ? sum : SIZE_MAX);
-}
-
-/* Sum of three sizes, with overflow check. */
-XSIZE_INLINE size_t
-#if __GNUC__ >= 3
-__attribute__ ((__pure__))
-#endif
-xsum3 (size_t size1, size_t size2, size_t size3)
-{
- return xsum (xsum (size1, size2), size3);
-}
-
-/* Sum of four sizes, with overflow check. */
-XSIZE_INLINE size_t
-#if __GNUC__ >= 3
-__attribute__ ((__pure__))
-#endif
-xsum4 (size_t size1, size_t size2, size_t size3, size_t size4)
-{
- return xsum (xsum (xsum (size1, size2), size3), size4);
-}
-
-/* Maximum of two sizes, with overflow check. */
-XSIZE_INLINE size_t
-#if __GNUC__ >= 3
-__attribute__ ((__pure__))
-#endif
-xmax (size_t size1, size_t size2)
-{
- /* No explicit check is needed here, because for any n:
- max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */
- return (size1 >= size2 ? size1 : size2);
-}
-
-/* Multiplication of a count with an element size, with overflow check.
- The count must be >= 0 and the element size must be > 0.
- This is a macro, not a function, so that it works correctly even
- when N is of a wider type and N > SIZE_MAX. */
-#define xtimes(N, ELSIZE) \
- ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
-
-/* Check for overflow. */
-#define size_overflow_p(SIZE) \
- ((SIZE) == SIZE_MAX)
-/* Check against overflow. */
-#define size_in_bounds_p(SIZE) \
- ((SIZE) != SIZE_MAX)
-
-_GL_INLINE_HEADER_END
-
-#endif /* _XSIZE_H */
+/* xsize.h -- Checked size_t computations.
+
+ Copyright (C) 2003, 2008-2013 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _XSIZE_H
+#define _XSIZE_H
+
+/* Get size_t. */
+#include <stddef.h>
+
+/* Get SIZE_MAX. */
+#include <limits.h>
+#if HAVE_STDINT_H
+# include <stdint.h>
+#endif
+
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef XSIZE_INLINE
+# define XSIZE_INLINE _GL_INLINE
+#endif
+
+/* The size of memory objects is often computed through expressions of
+ type size_t. Example:
+ void* p = malloc (header_size + n * element_size).
+ These computations can lead to overflow. When this happens, malloc()
+ returns a piece of memory that is way too small, and the program then
+ crashes while attempting to fill the memory.
+ To avoid this, the functions and macros in this file check for overflow.
+ The convention is that SIZE_MAX represents overflow.
+ malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc
+ implementation that uses mmap --, it's recommended to use size_overflow_p()
+ or size_in_bounds_p() before invoking malloc().
+ The example thus becomes:
+ size_t size = xsum (header_size, xtimes (n, element_size));
+ void *p = (size_in_bounds_p (size) ? malloc (size) : NULL);
+*/
+
+/* Convert an arbitrary value >= 0 to type size_t. */
+#define xcast_size_t(N) \
+ ((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
+
+/* Sum of two sizes, with overflow check. */
+XSIZE_INLINE size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xsum (size_t size1, size_t size2)
+{
+ size_t sum = size1 + size2;
+ return (sum >= size1 ? sum : SIZE_MAX);
+}
+
+/* Sum of three sizes, with overflow check. */
+XSIZE_INLINE size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xsum3 (size_t size1, size_t size2, size_t size3)
+{
+ return xsum (xsum (size1, size2), size3);
+}
+
+/* Sum of four sizes, with overflow check. */
+XSIZE_INLINE size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xsum4 (size_t size1, size_t size2, size_t size3, size_t size4)
+{
+ return xsum (xsum (xsum (size1, size2), size3), size4);
+}
+
+/* Maximum of two sizes, with overflow check. */
+XSIZE_INLINE size_t
+#if __GNUC__ >= 3
+__attribute__ ((__pure__))
+#endif
+xmax (size_t size1, size_t size2)
+{
+ /* No explicit check is needed here, because for any n:
+ max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */
+ return (size1 >= size2 ? size1 : size2);
+}
+
+/* Multiplication of a count with an element size, with overflow check.
+ The count must be >= 0 and the element size must be > 0.
+ This is a macro, not a function, so that it works correctly even
+ when N is of a wider type and N > SIZE_MAX. */
+#define xtimes(N, ELSIZE) \
+ ((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
+
+/* Check for overflow. */
+#define size_overflow_p(SIZE) \
+ ((SIZE) == SIZE_MAX)
+/* Check against overflow. */
+#define size_in_bounds_p(SIZE) \
+ ((SIZE) != SIZE_MAX)
+
+_GL_INLINE_HEADER_END
+
+#endif /* _XSIZE_H */
diff --git a/contrib/tools/bison/gnulib/src/xstrndup.c b/contrib/tools/bison/gnulib/src/xstrndup.c
index 741d5a1b05..4b7bccce8d 100644
--- a/contrib/tools/bison/gnulib/src/xstrndup.c
+++ b/contrib/tools/bison/gnulib/src/xstrndup.c
@@ -1,30 +1,30 @@
-/* Duplicate a bounded initial segment of a string, with out-of-memory
- checking.
- Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "xstrndup.h"
-
-#include <string.h>
+/* Duplicate a bounded initial segment of a string, with out-of-memory
+ checking.
+ Copyright (C) 2003, 2006-2007, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "xstrndup.h"
+
+#include <string.h>
#include <stdlib.h>
-#include "xalloc.h"
-
+#include "xalloc.h"
+
#if defined(_MSC_VER)
static char *
strndup(char const *s, size_t n)
@@ -40,14 +40,14 @@ strndup(char const *s, size_t n)
}
#endif
-/* Return a newly allocated copy of at most N bytes of STRING.
- In other words, return a copy of the initial segment of length N of
- STRING. */
-char *
-xstrndup (const char *string, size_t n)
-{
- char *s = strndup (string, n);
- if (! s)
- xalloc_die ();
- return s;
-}
+/* Return a newly allocated copy of at most N bytes of STRING.
+ In other words, return a copy of the initial segment of length N of
+ STRING. */
+char *
+xstrndup (const char *string, size_t n)
+{
+ char *s = strndup (string, n);
+ if (! s)
+ xalloc_die ();
+ return s;
+}
diff --git a/contrib/tools/bison/gnulib/src/xstrndup.h b/contrib/tools/bison/gnulib/src/xstrndup.h
index 59673b0489..8555d2beaa 100644
--- a/contrib/tools/bison/gnulib/src/xstrndup.h
+++ b/contrib/tools/bison/gnulib/src/xstrndup.h
@@ -1,23 +1,23 @@
-/* Duplicate a bounded initial segment of a string, with out-of-memory
- checking.
- Copyright (C) 2003, 2009-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <stddef.h>
-
-/* Return a newly allocated copy of at most N bytes of STRING.
- In other words, return a copy of the initial segment of length N of
- STRING. */
-extern char *xstrndup (const char *string, size_t n);
+/* Duplicate a bounded initial segment of a string, with out-of-memory
+ checking.
+ Copyright (C) 2003, 2009-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+
+/* Return a newly allocated copy of at most N bytes of STRING.
+ In other words, return a copy of the initial segment of length N of
+ STRING. */
+extern char *xstrndup (const char *string, size_t n);
diff --git a/contrib/tools/bison/gnulib/src/xvasprintf.c b/contrib/tools/bison/gnulib/src/xvasprintf.c
index 9c93492b80..693274411d 100644
--- a/contrib/tools/bison/gnulib/src/xvasprintf.c
+++ b/contrib/tools/bison/gnulib/src/xvasprintf.c
@@ -1,117 +1,117 @@
-/* vasprintf and asprintf with out-of-memory checking.
- Copyright (C) 1999, 2002-2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include <config.h>
-
-/* Specification. */
-#include "xvasprintf.h"
-
-#include <errno.h>
-#include <limits.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "xalloc.h"
-
-/* Checked size_t computations. */
-#include "xsize.h"
-
-static char *
-xstrcat (size_t argcount, va_list args)
-{
- char *result;
- va_list ap;
- size_t totalsize;
- size_t i;
- char *p;
-
- /* Determine the total size. */
- totalsize = 0;
- va_copy (ap, args);
- for (i = argcount; i > 0; i--)
- {
- const char *next = va_arg (ap, const char *);
- totalsize = xsum (totalsize, strlen (next));
- }
- va_end (ap);
-
- /* Test for overflow in the summing pass above or in (totalsize + 1) below.
- Also, don't return a string longer than INT_MAX, for consistency with
- vasprintf(). */
- if (totalsize == SIZE_MAX || totalsize > INT_MAX)
- {
+/* vasprintf and asprintf with out-of-memory checking.
+ Copyright (C) 1999, 2002-2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include "xvasprintf.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xalloc.h"
+
+/* Checked size_t computations. */
+#include "xsize.h"
+
+static char *
+xstrcat (size_t argcount, va_list args)
+{
+ char *result;
+ va_list ap;
+ size_t totalsize;
+ size_t i;
+ char *p;
+
+ /* Determine the total size. */
+ totalsize = 0;
+ va_copy (ap, args);
+ for (i = argcount; i > 0; i--)
+ {
+ const char *next = va_arg (ap, const char *);
+ totalsize = xsum (totalsize, strlen (next));
+ }
+ va_end (ap);
+
+ /* Test for overflow in the summing pass above or in (totalsize + 1) below.
+ Also, don't return a string longer than INT_MAX, for consistency with
+ vasprintf(). */
+ if (totalsize == SIZE_MAX || totalsize > INT_MAX)
+ {
#if (defined _MSC_VER) && (_MSC_VER < 1800)
#else
- errno = EOVERFLOW;
+ errno = EOVERFLOW;
#endif
- return NULL;
- }
-
- /* Allocate and fill the result string. */
- result = XNMALLOC (totalsize + 1, char);
- p = result;
- for (i = argcount; i > 0; i--)
- {
- const char *next = va_arg (args, const char *);
- size_t len = strlen (next);
- memcpy (p, next, len);
- p += len;
- }
- *p = '\0';
-
- return result;
-}
-
+ return NULL;
+ }
+
+ /* Allocate and fill the result string. */
+ result = XNMALLOC (totalsize + 1, char);
+ p = result;
+ for (i = argcount; i > 0; i--)
+ {
+ const char *next = va_arg (args, const char *);
+ size_t len = strlen (next);
+ memcpy (p, next, len);
+ p += len;
+ }
+ *p = '\0';
+
+ return result;
+}
+
#if defined(_MSC_VER)
int vasprintf(char **resultp, const char *format, va_list args);
#endif
-char *
-xvasprintf (const char *format, va_list args)
-{
- char *result;
-
- /* Recognize the special case format = "%s...%s". It is a frequently used
- idiom for string concatenation and needs to be fast. We don't want to
- have a separate function xstrcat() for this purpose. */
- {
- size_t argcount = 0;
- const char *f;
-
- for (f = format;;)
- {
- if (*f == '\0')
- /* Recognized the special case of string concatenation. */
- return xstrcat (argcount, args);
- if (*f != '%')
- break;
- f++;
- if (*f != 's')
- break;
- f++;
- argcount++;
- }
- }
-
- if (vasprintf (&result, format, args) < 0)
- {
- if (errno == ENOMEM)
- xalloc_die ();
- return NULL;
- }
-
- return result;
-}
+char *
+xvasprintf (const char *format, va_list args)
+{
+ char *result;
+
+ /* Recognize the special case format = "%s...%s". It is a frequently used
+ idiom for string concatenation and needs to be fast. We don't want to
+ have a separate function xstrcat() for this purpose. */
+ {
+ size_t argcount = 0;
+ const char *f;
+
+ for (f = format;;)
+ {
+ if (*f == '\0')
+ /* Recognized the special case of string concatenation. */
+ return xstrcat (argcount, args);
+ if (*f != '%')
+ break;
+ f++;
+ if (*f != 's')
+ break;
+ f++;
+ argcount++;
+ }
+ }
+
+ if (vasprintf (&result, format, args) < 0)
+ {
+ if (errno == ENOMEM)
+ xalloc_die ();
+ return NULL;
+ }
+
+ return result;
+}
diff --git a/contrib/tools/bison/gnulib/src/xvasprintf.h b/contrib/tools/bison/gnulib/src/xvasprintf.h
index 1208fa193c..86721daa87 100644
--- a/contrib/tools/bison/gnulib/src/xvasprintf.h
+++ b/contrib/tools/bison/gnulib/src/xvasprintf.h
@@ -1,55 +1,55 @@
-/* vasprintf and asprintf with out-of-memory checking.
- Copyright (C) 2002-2004, 2006-2013 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef _XVASPRINTF_H
-#define _XVASPRINTF_H
-
-/* Get va_list. */
-#include <stdarg.h>
-
-/* The __attribute__ feature is available in gcc versions 2.5 and later.
- The __-protected variants of the attributes 'format' and 'printf' are
- accepted by gcc versions 2.6.4 (effectively 2.7) and later.
- We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
- gnulib and libintl do '#define printf __printf__' when they override
- the 'printf' function. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
-# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
-#else
-# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Write formatted output to a string dynamically allocated with malloc(),
- and return it. Upon [ENOMEM] memory allocation error, call xalloc_die.
- On some other error
- - [EOVERFLOW] resulting string length is > INT_MAX,
- - [EINVAL] invalid format string,
- - [EILSEQ] error during conversion between wide and multibyte characters,
- return NULL. */
-extern char *xasprintf (const char *format, ...)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2));
-extern char *xvasprintf (const char *format, va_list args)
- _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0));
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _XVASPRINTF_H */
+/* vasprintf and asprintf with out-of-memory checking.
+ Copyright (C) 2002-2004, 2006-2013 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _XVASPRINTF_H
+#define _XVASPRINTF_H
+
+/* Get va_list. */
+#include <stdarg.h>
+
+/* The __attribute__ feature is available in gcc versions 2.5 and later.
+ The __-protected variants of the attributes 'format' and 'printf' are
+ accepted by gcc versions 2.6.4 (effectively 2.7) and later.
+ We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
+ gnulib and libintl do '#define printf __printf__' when they override
+ the 'printf' function. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+#else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Write formatted output to a string dynamically allocated with malloc(),
+ and return it. Upon [ENOMEM] memory allocation error, call xalloc_die.
+ On some other error
+ - [EOVERFLOW] resulting string length is > INT_MAX,
+ - [EINVAL] invalid format string,
+ - [EILSEQ] error during conversion between wide and multibyte characters,
+ return NULL. */
+extern char *xasprintf (const char *format, ...)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2));
+extern char *xvasprintf (const char *format, va_list args)
+ _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _XVASPRINTF_H */
diff --git a/contrib/tools/bison/gnulib/ya.make b/contrib/tools/bison/gnulib/ya.make
index b674fd9ada..085f75cb21 100644
--- a/contrib/tools/bison/gnulib/ya.make
+++ b/contrib/tools/bison/gnulib/ya.make
@@ -1,7 +1,7 @@
OWNER(g:contrib)
-LIBRARY()
-
+LIBRARY()
+
LICENSE(
BSD-3-Clause AND
GPL-3.0-or-later AND
@@ -14,12 +14,12 @@ IF (NOT MUSL)
NO_RUNTIME()
ENDIF()
-NO_COMPILER_WARNINGS()
-
+NO_COMPILER_WARNINGS()
+
ADDINCL(
GLOBAL contrib/tools/bison/gnulib/src
)
-
+
IF (OS_WINDOWS)
ADDINCL(
GLOBAL contrib/tools/bison/gnulib/platform/win64
@@ -29,7 +29,7 @@ ELSE()
GLOBAL contrib/tools/bison/gnulib/platform/posix
)
ENDIF()
-
+
IF (OS_DARWIN)
CFLAGS(
-D_XOPEN_SOURCE=600
@@ -45,129 +45,129 @@ IF (NOT OS_WINDOWS)
)
ENDIF()
-SRCS(
- src/abitset.c
- src/argmatch.c
- src/asnprintf.c
- src/basename-lgpl.c
- src/basename.c
- src/binary-io.c
- src/bitrotate.c
- src/bitset.c
- src/bitset_stats.c
- src/bitsetv-print.c
- src/bitsetv.c
- src/c-ctype.c
- src/c-stack.c
- src/c-strcasecmp.c
- src/c-strncasecmp.c
- src/calloc.c
- src/clean-temp.c
- src/cloexec.c
- src/close-stream.c
- src/close.c
- src/closein.c
- src/closeout.c
- src/concat-filename.c
- src/dirname-lgpl.c
- src/dirname.c
- src/dup-safer-flag.c
- src/dup-safer.c
- src/dup2.c
- src/ebitset.c
- src/error.c
- src/execute.c
- src/exitfail.c
- src/fatal-signal.c
- src/fclose.c
- src/fcntl.c
- src/fd-hook.c
- src/fd-safer-flag.c
- src/fd-safer.c
- src/fflush.c
- src/filenamecat-lgpl.c
- src/filenamecat.c
- src/float.c
- src/fopen-safer.c
- src/fpurge.c
- src/freading.c
- src/fstat.c
- src/get-errno.c
- src/getdtablesize.c
- src/getopt.c
- src/getopt1.c
- src/gl_avltree_oset.c
- src/gl_linkedhash_list.c
- src/gl_list.c
- src/gl_oset.c
- src/gl_xlist.c
- src/gl_xoset.c
- src/hash.c
- src/isnand.c
- src/isnanf.c
- src/isnanl.c
- src/itold.c
- src/lbitset.c
- src/localcharset.c
- src/lseek.c
- src/lstat.c
- src/malloc.c
- src/malloca.c
- src/mbrtowc.c
- src/mbswidth.c
- src/memchr2.c
- src/mkstemp-safer.c
- src/nl_langinfo.c
- src/pipe-safer.c
- src/pipe2-safer.c
- src/printf-args.c
- src/printf-frexp.c
- src/printf-frexpl.c
- src/printf-parse.c
- src/progname.c
- src/quotearg.c
- src/raise.c
- src/rawmemchr.c
- src/readlink.c
- src/realloc.c
- src/regex.c
- src/rename.c
- src/rmdir.c
- src/secure_getenv.c
- src/sig-handler.c
- src/signbitd.c
- src/signbitf.c
- src/signbitl.c
- src/spawn-pipe.c
- src/stat.c
- src/stpcpy.c
- src/strchrnul.c
- src/strdup.c
- src/stripslash.c
- src/tempname.c
- src/timevar.c
- src/tmpdir.c
- src/unistd.c
- src/unsetenv.c
- src/vasnprintf.c
- src/vbitset.c
- src/verror.c
- src/version-etc-fsf.c
- src/version-etc.c
- src/wait-process.c
- src/wctype-h.c
- src/xalloc-die.c
- src/xasprintf.c
- src/xconcat-filename.c
- src/xmalloc.c
- src/xmalloca.c
- src/xmemdup0.c
- src/xprintf.c
- src/xsize.c
- src/xstrndup.c
- src/xvasprintf.c
-)
-
+SRCS(
+ src/abitset.c
+ src/argmatch.c
+ src/asnprintf.c
+ src/basename-lgpl.c
+ src/basename.c
+ src/binary-io.c
+ src/bitrotate.c
+ src/bitset.c
+ src/bitset_stats.c
+ src/bitsetv-print.c
+ src/bitsetv.c
+ src/c-ctype.c
+ src/c-stack.c
+ src/c-strcasecmp.c
+ src/c-strncasecmp.c
+ src/calloc.c
+ src/clean-temp.c
+ src/cloexec.c
+ src/close-stream.c
+ src/close.c
+ src/closein.c
+ src/closeout.c
+ src/concat-filename.c
+ src/dirname-lgpl.c
+ src/dirname.c
+ src/dup-safer-flag.c
+ src/dup-safer.c
+ src/dup2.c
+ src/ebitset.c
+ src/error.c
+ src/execute.c
+ src/exitfail.c
+ src/fatal-signal.c
+ src/fclose.c
+ src/fcntl.c
+ src/fd-hook.c
+ src/fd-safer-flag.c
+ src/fd-safer.c
+ src/fflush.c
+ src/filenamecat-lgpl.c
+ src/filenamecat.c
+ src/float.c
+ src/fopen-safer.c
+ src/fpurge.c
+ src/freading.c
+ src/fstat.c
+ src/get-errno.c
+ src/getdtablesize.c
+ src/getopt.c
+ src/getopt1.c
+ src/gl_avltree_oset.c
+ src/gl_linkedhash_list.c
+ src/gl_list.c
+ src/gl_oset.c
+ src/gl_xlist.c
+ src/gl_xoset.c
+ src/hash.c
+ src/isnand.c
+ src/isnanf.c
+ src/isnanl.c
+ src/itold.c
+ src/lbitset.c
+ src/localcharset.c
+ src/lseek.c
+ src/lstat.c
+ src/malloc.c
+ src/malloca.c
+ src/mbrtowc.c
+ src/mbswidth.c
+ src/memchr2.c
+ src/mkstemp-safer.c
+ src/nl_langinfo.c
+ src/pipe-safer.c
+ src/pipe2-safer.c
+ src/printf-args.c
+ src/printf-frexp.c
+ src/printf-frexpl.c
+ src/printf-parse.c
+ src/progname.c
+ src/quotearg.c
+ src/raise.c
+ src/rawmemchr.c
+ src/readlink.c
+ src/realloc.c
+ src/regex.c
+ src/rename.c
+ src/rmdir.c
+ src/secure_getenv.c
+ src/sig-handler.c
+ src/signbitd.c
+ src/signbitf.c
+ src/signbitl.c
+ src/spawn-pipe.c
+ src/stat.c
+ src/stpcpy.c
+ src/strchrnul.c
+ src/strdup.c
+ src/stripslash.c
+ src/tempname.c
+ src/timevar.c
+ src/tmpdir.c
+ src/unistd.c
+ src/unsetenv.c
+ src/vasnprintf.c
+ src/vbitset.c
+ src/verror.c
+ src/version-etc-fsf.c
+ src/version-etc.c
+ src/wait-process.c
+ src/wctype-h.c
+ src/xalloc-die.c
+ src/xasprintf.c
+ src/xconcat-filename.c
+ src/xmalloc.c
+ src/xmalloca.c
+ src/xmemdup0.c
+ src/xprintf.c
+ src/xsize.c
+ src/xstrndup.c
+ src/xvasprintf.c
+)
+
IF (NOT MUSL)
SRCS(
src/freadahead.c
@@ -226,8 +226,8 @@ IF (OS_WINDOWS)
src/wcwidth.c
src/uniwidth/width.c
)
-ENDIF()
-
+ENDIF()
+
IF (NOT OS_LINUX OR MUSL)
SRCS(
src/obstack.c
@@ -243,4 +243,4 @@ ELSE()
)
ENDIF()
-END()
+END()
diff --git a/contrib/tools/bison/m4/src/Makefile.am b/contrib/tools/bison/m4/src/Makefile.am
index 29e05c0def..c3b94da5ca 100644
--- a/contrib/tools/bison/m4/src/Makefile.am
+++ b/contrib/tools/bison/m4/src/Makefile.am
@@ -1,29 +1,29 @@
-## Makefile.am - template for generating Makefile via Automake
-##
-## Copyright (C) 2006-2013 Free Software Foundation, Inc.
-##
-## This file is part of GNU M4.
-##
-## GNU M4 is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## GNU M4 is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program. If not, see <http://www.gnu.org/licenses/>.
-##
-## This file written by Eric Blake <ebb9@byu.net>
-
-AUTOMAKE_OPTIONS = nostdinc
-AM_CPPFLAGS = -I$(top_srcdir)/lib -I../lib
-AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
-bin_PROGRAMS = m4
-noinst_HEADERS = m4.h
-m4_SOURCES = m4.c builtin.c debug.c eval.c format.c freeze.c input.c \
-macro.c output.c path.c symtab.c
-m4_LDADD = ../lib/libm4.a $(LIBM4_LIBDEPS) $(LIBCSTACK) $(LIBTHREAD)
+## Makefile.am - template for generating Makefile via Automake
+##
+## Copyright (C) 2006-2013 Free Software Foundation, Inc.
+##
+## This file is part of GNU M4.
+##
+## GNU M4 is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## GNU M4 is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <http://www.gnu.org/licenses/>.
+##
+## This file written by Eric Blake <ebb9@byu.net>
+
+AUTOMAKE_OPTIONS = nostdinc
+AM_CPPFLAGS = -I$(top_srcdir)/lib -I../lib
+AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
+bin_PROGRAMS = m4
+noinst_HEADERS = m4.h
+m4_SOURCES = m4.c builtin.c debug.c eval.c format.c freeze.c input.c \
+macro.c output.c path.c symtab.c
+m4_LDADD = ../lib/libm4.a $(LIBM4_LIBDEPS) $(LIBCSTACK) $(LIBTHREAD)
diff --git a/contrib/tools/bison/m4/src/builtin.c b/contrib/tools/bison/m4/src/builtin.c
index 01ede38017..3b867da712 100644
--- a/contrib/tools/bison/m4/src/builtin.c
+++ b/contrib/tools/bison/m4/src/builtin.c
@@ -1,2258 +1,2258 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2000, 2004, 2006-2013 Free Software
- Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* Code for all builtin macros, initialization of symbol table, and
- expansion of user defined macros. */
-
-#include "m4.h"
-
-#include "execute.h"
-#include "memchr2.h"
-#include "progname.h"
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2000, 2004, 2006-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Code for all builtin macros, initialization of symbol table, and
+ expansion of user defined macros. */
+
+#include "m4.h"
+
+#include "execute.h"
+#include "memchr2.h"
+#include "progname.h"
#include <contrib/tools/bison/gnulib/src/regex.h>
-#include "spawn-pipe.h"
-#include "wait-process.h"
-
-#define ARG(i) (argc > (i) ? TOKEN_DATA_TEXT (argv[i]) : "")
-
-/* Initialization of builtin and predefined macros. The table
- "builtin_tab" is both used for initialization, and by the "builtin"
- builtin. */
-
-#define DECLARE(name) \
- static void name (struct obstack *, int, token_data **)
-
-DECLARE (m4___file__);
-DECLARE (m4___line__);
-DECLARE (m4___program__);
-DECLARE (m4_builtin);
-DECLARE (m4_changecom);
-DECLARE (m4_changequote);
-#ifdef ENABLE_CHANGEWORD
-DECLARE (m4_changeword);
-#endif
-DECLARE (m4_debugmode);
-DECLARE (m4_debugfile);
-DECLARE (m4_decr);
-DECLARE (m4_define);
-DECLARE (m4_defn);
-DECLARE (m4_divert);
-DECLARE (m4_divnum);
-DECLARE (m4_dnl);
-DECLARE (m4_dumpdef);
-DECLARE (m4_errprint);
-DECLARE (m4_esyscmd);
-DECLARE (m4_eval);
-DECLARE (m4_format);
-DECLARE (m4_ifdef);
-DECLARE (m4_ifelse);
-DECLARE (m4_include);
-DECLARE (m4_incr);
-DECLARE (m4_index);
-DECLARE (m4_indir);
-DECLARE (m4_len);
-DECLARE (m4_m4exit);
-DECLARE (m4_m4wrap);
-DECLARE (m4_maketemp);
-DECLARE (m4_mkstemp);
-DECLARE (m4_patsubst);
-DECLARE (m4_popdef);
-DECLARE (m4_pushdef);
-DECLARE (m4_regexp);
-DECLARE (m4_shift);
-DECLARE (m4_sinclude);
-DECLARE (m4_substr);
-DECLARE (m4_syscmd);
-DECLARE (m4_sysval);
-DECLARE (m4_traceoff);
-DECLARE (m4_traceon);
-DECLARE (m4_translit);
-DECLARE (m4_undefine);
-DECLARE (m4_undivert);
-
-#undef DECLARE
-
-static builtin const builtin_tab[] =
-{
-
- /* name GNUext macros blind function */
-
- { "__file__", true, false, false, m4___file__ },
- { "__line__", true, false, false, m4___line__ },
- { "__program__", true, false, false, m4___program__ },
- { "builtin", true, true, true, m4_builtin },
- { "changecom", false, false, false, m4_changecom },
- { "changequote", false, false, false, m4_changequote },
-#ifdef ENABLE_CHANGEWORD
- { "changeword", true, false, true, m4_changeword },
-#endif
- { "debugmode", true, false, false, m4_debugmode },
- { "debugfile", true, false, false, m4_debugfile },
- { "decr", false, false, true, m4_decr },
- { "define", false, true, true, m4_define },
- { "defn", false, false, true, m4_defn },
- { "divert", false, false, false, m4_divert },
- { "divnum", false, false, false, m4_divnum },
- { "dnl", false, false, false, m4_dnl },
- { "dumpdef", false, false, false, m4_dumpdef },
- { "errprint", false, false, true, m4_errprint },
- { "esyscmd", true, false, true, m4_esyscmd },
- { "eval", false, false, true, m4_eval },
- { "format", true, false, true, m4_format },
- { "ifdef", false, false, true, m4_ifdef },
- { "ifelse", false, false, true, m4_ifelse },
- { "include", false, false, true, m4_include },
- { "incr", false, false, true, m4_incr },
- { "index", false, false, true, m4_index },
- { "indir", true, true, true, m4_indir },
- { "len", false, false, true, m4_len },
- { "m4exit", false, false, false, m4_m4exit },
- { "m4wrap", false, false, true, m4_m4wrap },
- { "maketemp", false, false, true, m4_maketemp },
- { "mkstemp", false, false, true, m4_mkstemp },
- { "patsubst", true, false, true, m4_patsubst },
- { "popdef", false, false, true, m4_popdef },
- { "pushdef", false, true, true, m4_pushdef },
- { "regexp", true, false, true, m4_regexp },
- { "shift", false, false, true, m4_shift },
- { "sinclude", false, false, true, m4_sinclude },
- { "substr", false, false, true, m4_substr },
- { "syscmd", false, false, true, m4_syscmd },
- { "sysval", false, false, false, m4_sysval },
- { "traceoff", false, false, false, m4_traceoff },
- { "traceon", false, false, false, m4_traceon },
- { "translit", false, false, true, m4_translit },
- { "undefine", false, false, true, m4_undefine },
- { "undivert", false, false, false, m4_undivert },
-
- { 0, false, false, false, 0 },
-
- /* placeholder is intentionally stuck after the table end delimiter,
- so that we can easily find it, while not treating it as a real
- builtin. */
- { "placeholder", true, false, false, m4_placeholder },
-};
-
-static predefined const predefined_tab[] =
-{
-#if UNIX
- { "unix", "__unix__", "" },
-#endif
-#if W32_NATIVE
- { "windows", "__windows__", "" },
-#endif
-#if OS2
- { "os2", "__os2__", "" },
-#endif
-#if !UNIX && !W32_NATIVE && !OS2
-# warning Platform macro not provided
-#endif
- { NULL, "__gnu__", "" },
-
- { NULL, NULL, NULL },
-};
-
-/*----------------------------------------.
-| Find the builtin, which lives on ADDR. |
-`----------------------------------------*/
-
-const builtin * M4_GNUC_PURE
-find_builtin_by_addr (builtin_func *func)
-{
- const builtin *bp;
-
- for (bp = &builtin_tab[0]; bp->name != NULL; bp++)
- if (bp->func == func)
- return bp;
- if (func == m4_placeholder)
- return bp + 1;
- return NULL;
-}
-
-/*----------------------------------------------------------.
-| Find the builtin, which has NAME. On failure, return the |
-| placeholder builtin. |
-`----------------------------------------------------------*/
-
-const builtin * M4_GNUC_PURE
-find_builtin_by_name (const char *name)
-{
- const builtin *bp;
-
- for (bp = &builtin_tab[0]; bp->name != NULL; bp++)
- if (STREQ (bp->name, name))
- return bp;
- return bp + 1;
-}
-
-/*----------------------------------------------------------------.
-| Install a builtin macro with name NAME, bound to the C function |
-| given in BP. MODE is SYMBOL_INSERT or SYMBOL_PUSHDEF. |
-`----------------------------------------------------------------*/
-
-void
-define_builtin (const char *name, const builtin *bp, symbol_lookup mode)
-{
- symbol *sym;
-
- sym = lookup_symbol (name, mode);
- SYMBOL_TYPE (sym) = TOKEN_FUNC;
- SYMBOL_MACRO_ARGS (sym) = bp->groks_macro_args;
- SYMBOL_BLIND_NO_ARGS (sym) = bp->blind_if_no_args;
- SYMBOL_FUNC (sym) = bp->func;
-}
-
-/* Storage for the compiled regular expression of
- --warn-macro-sequence. */
-static struct re_pattern_buffer macro_sequence_buf;
-
-/* Storage for the matches of --warn-macro-sequence. */
-static struct re_registers macro_sequence_regs;
-
-/* True if --warn-macro-sequence is in effect. */
-static bool macro_sequence_inuse;
-
-/*----------------------------------------.
-| Clean up regular expression variables. |
-`----------------------------------------*/
-
-static void
-free_pattern_buffer (struct re_pattern_buffer *buf, struct re_registers *regs)
-{
- regfree (buf);
- free (regs->start);
- free (regs->end);
-}
-
-/*-----------------------------------------------------------------.
-| Set the regular expression of --warn-macro-sequence that will be |
-| checked during define and pushdef. Exit on failure. |
-`-----------------------------------------------------------------*/
-void
-set_macro_sequence (const char *regexp)
-{
- const char *msg;
-
- if (! regexp)
- regexp = DEFAULT_MACRO_SEQUENCE;
- else if (regexp[0] == '\0')
- {
- macro_sequence_inuse = false;
- return;
- }
-
- msg = re_compile_pattern (regexp, strlen (regexp), &macro_sequence_buf);
- if (msg != NULL)
- {
- M4ERROR ((EXIT_FAILURE, 0,
- "--warn-macro-sequence: bad regular expression `%s': %s",
- regexp, msg));
- }
- re_set_registers (&macro_sequence_buf, &macro_sequence_regs,
- macro_sequence_regs.num_regs,
- macro_sequence_regs.start, macro_sequence_regs.end);
- macro_sequence_inuse = true;
-}
-
-/*-----------------------------------------------------------.
-| Free dynamic memory utilized by the macro sequence regular |
-| expression during the define builtin. |
-`-----------------------------------------------------------*/
-void
-free_macro_sequence (void)
-{
- free_pattern_buffer (&macro_sequence_buf, &macro_sequence_regs);
-}
-
-/*-----------------------------------------------------------------.
-| Define a predefined or user-defined macro, with name NAME, and |
-| expansion TEXT. MODE destinguishes between the "define" and the |
-| "pushdef" case. It is also used from main. |
-`-----------------------------------------------------------------*/
-
-void
-define_user_macro (const char *name, const char *text, symbol_lookup mode)
-{
- symbol *s;
- char *defn = xstrdup (text ? text : "");
-
- s = lookup_symbol (name, mode);
- if (SYMBOL_TYPE (s) == TOKEN_TEXT)
- free (SYMBOL_TEXT (s));
-
- SYMBOL_TYPE (s) = TOKEN_TEXT;
- SYMBOL_TEXT (s) = defn;
-
- /* Implement --warn-macro-sequence. */
- if (macro_sequence_inuse && text)
- {
- regoff_t offset = 0;
- size_t len = strlen (defn);
-
- while ((offset = re_search (&macro_sequence_buf, defn, len, offset,
- len - offset, &macro_sequence_regs)) >= 0)
- {
- /* Skip empty matches. */
- if (macro_sequence_regs.start[0] == macro_sequence_regs.end[0])
- offset++;
- else
- {
- char tmp;
- offset = macro_sequence_regs.end[0];
- tmp = defn[offset];
- defn[offset] = '\0';
- M4ERROR ((warning_status, 0,
- "Warning: definition of `%s' contains sequence `%s'",
- name, defn + macro_sequence_regs.start[0]));
- defn[offset] = tmp;
- }
- }
- if (offset == -2)
- M4ERROR ((warning_status, 0,
- "error checking --warn-macro-sequence for macro `%s'",
- name));
- }
-}
-
-/*-----------------------------------------------.
-| Initialize all builtin and predefined macros. |
-`-----------------------------------------------*/
-
-void
-builtin_init (void)
-{
- const builtin *bp;
- const predefined *pp;
- char *string;
-
- for (bp = &builtin_tab[0]; bp->name != NULL; bp++)
- if (!no_gnu_extensions || !bp->gnu_extension)
- {
- if (prefix_all_builtins)
- {
- string = (char *) xmalloc (strlen (bp->name) + 4);
- strcpy (string, "m4_");
- strcat (string, bp->name);
- define_builtin (string, bp, SYMBOL_INSERT);
- free (string);
- }
- else
- define_builtin (bp->name, bp, SYMBOL_INSERT);
- }
-
- for (pp = &predefined_tab[0]; pp->func != NULL; pp++)
- if (no_gnu_extensions)
- {
- if (pp->unix_name != NULL)
- define_user_macro (pp->unix_name, pp->func, SYMBOL_INSERT);
- }
- else
- {
- if (pp->gnu_name != NULL)
- define_user_macro (pp->gnu_name, pp->func, SYMBOL_INSERT);
- }
-}
-
-/*-------------------------------------------------------------------.
-| Give friendly warnings if a builtin macro is passed an |
-| inappropriate number of arguments. NAME is the macro name for |
-| messages, ARGC is actual number of arguments, MIN is the minimum |
-| number of acceptable arguments, negative if not applicable, MAX is |
-| the maximum number, negative if not applicable. |
-`-------------------------------------------------------------------*/
-
-static bool
-bad_argc (token_data *name, int argc, int min, int max)
-{
- bool isbad = false;
-
- if (min > 0 && argc < min)
- {
- if (!suppress_warnings)
- M4ERROR ((warning_status, 0,
- "Warning: too few arguments to builtin `%s'",
- TOKEN_DATA_TEXT (name)));
- isbad = true;
- }
- else if (max > 0 && argc > max && !suppress_warnings)
- M4ERROR ((warning_status, 0,
- "Warning: excess arguments to builtin `%s' ignored",
- TOKEN_DATA_TEXT (name)));
-
- return isbad;
-}
-
-/*-----------------------------------------------------------------.
-| The function numeric_arg () converts ARG to an int pointed to by |
-| VALUEP. If the conversion fails, print error message for macro |
-| MACRO. Return true iff conversion succeeds. |
-`-----------------------------------------------------------------*/
-
-static bool
-numeric_arg (token_data *macro, const char *arg, int *valuep)
-{
- char *endp;
-
- if (*arg == '\0')
- {
- *valuep = 0;
- M4ERROR ((warning_status, 0,
- "empty string treated as 0 in builtin `%s'",
- TOKEN_DATA_TEXT (macro)));
- }
- else
- {
- errno = 0;
- *valuep = strtol (arg, &endp, 10);
- if (*endp != '\0')
- {
- M4ERROR ((warning_status, 0,
- "non-numeric argument to builtin `%s'",
- TOKEN_DATA_TEXT (macro)));
- return false;
- }
- if (isspace (to_uchar (*arg)))
- M4ERROR ((warning_status, 0,
- "leading whitespace ignored in builtin `%s'",
- TOKEN_DATA_TEXT (macro)));
- else if (errno == ERANGE)
- M4ERROR ((warning_status, 0,
- "numeric overflow detected in builtin `%s'",
- TOKEN_DATA_TEXT (macro)));
- }
- return true;
-}
-
-/*------------------------------------------------------.
-| The function ntoa () converts VALUE to a signed ASCII |
-| representation in radix RADIX. |
-`------------------------------------------------------*/
-
-/* Digits for number to ASCII conversions. */
-static char const digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
-
-const char *
-ntoa (int32_t value, int radix)
-{
- bool negative;
- uint32_t uvalue;
- static char str[256];
- char *s = &str[sizeof str];
-
- *--s = '\0';
-
- if (value < 0)
- {
- negative = true;
- uvalue = -(uint32_t) value;
- }
- else
- {
- negative = false;
- uvalue = (uint32_t) value;
- }
-
- do
- {
- *--s = digits[uvalue % radix];
- uvalue /= radix;
- }
- while (uvalue > 0);
-
- if (negative)
- *--s = '-';
- return s;
-}
-
-/*---------------------------------------------------------------.
-| Format an int VAL, and stuff it into an obstack OBS. Used for |
-| macros expanding to numbers. |
-`---------------------------------------------------------------*/
-
-static void
-shipout_int (struct obstack *obs, int val)
-{
- const char *s;
-
- s = ntoa ((int32_t) val, 10);
- obstack_grow (obs, s, strlen (s));
-}
-
-/*-------------------------------------------------------------------.
-| Print ARGC arguments from the table ARGV to obstack OBS, separated |
-| by SEP, and quoted by the current quotes if QUOTED is true. |
-`-------------------------------------------------------------------*/
-
-static void
-dump_args (struct obstack *obs, int argc, token_data **argv,
- const char *sep, bool quoted)
-{
- int i;
- size_t len = strlen (sep);
-
- for (i = 1; i < argc; i++)
- {
- if (i > 1)
- obstack_grow (obs, sep, len);
- if (quoted)
- obstack_grow (obs, lquote.string, lquote.length);
- obstack_grow (obs, TOKEN_DATA_TEXT (argv[i]),
- strlen (TOKEN_DATA_TEXT (argv[i])));
- if (quoted)
- obstack_grow (obs, rquote.string, rquote.length);
- }
-}
-
-/* The rest of this file is code for builtins and expansion of user
- defined macros. All the functions for builtins have a prototype as:
-
- void m4_MACRONAME (struct obstack *obs, int argc, char *argv[]);
-
- The function are expected to leave their expansion on the obstack OBS,
- as an unfinished object. ARGV is a table of ARGC pointers to the
- individual arguments to the macro. Please note that in general
- argv[argc] != NULL. */
-
-/* The first section are macros for definining, undefining, examining,
- changing, ... other macros. */
-
-/*-------------------------------------------------------------------.
-| The function define_macro is common for the builtins "define", |
-| "undefine", "pushdef" and "popdef". ARGC and ARGV is as for the |
-| caller, and MODE argument determines how the macro name is entered |
-| into the symbol table. |
-`-------------------------------------------------------------------*/
-
-static void
-define_macro (int argc, token_data **argv, symbol_lookup mode)
-{
- const builtin *bp;
-
- if (bad_argc (argv[0], argc, 2, 3))
- return;
-
- if (TOKEN_DATA_TYPE (argv[1]) != TOKEN_TEXT)
- {
- M4ERROR ((warning_status, 0,
- "Warning: %s: invalid macro name ignored", ARG (0)));
- return;
- }
-
- if (argc == 2)
- {
- define_user_macro (ARG (1), "", mode);
- return;
- }
-
- switch (TOKEN_DATA_TYPE (argv[2]))
- {
- case TOKEN_TEXT:
- define_user_macro (ARG (1), ARG (2), mode);
- break;
-
- case TOKEN_FUNC:
- bp = find_builtin_by_addr (TOKEN_DATA_FUNC (argv[2]));
- if (bp == NULL)
- return;
- else
- define_builtin (ARG (1), bp, mode);
- break;
-
- case TOKEN_VOID:
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad token data type in define_macro ()"));
- abort ();
- }
-}
-
-static void
-m4_define (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- define_macro (argc, argv, SYMBOL_INSERT);
-}
-
-static void
-m4_undefine (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- int i;
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- for (i = 1; i < argc; i++)
- lookup_symbol (ARG (i), SYMBOL_DELETE);
-}
-
-static void
-m4_pushdef (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- define_macro (argc, argv, SYMBOL_PUSHDEF);
-}
-
-static void
-m4_popdef (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- int i;
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- for (i = 1; i < argc; i++)
- lookup_symbol (ARG (i), SYMBOL_POPDEF);
-}
-
-/*---------------------.
-| Conditionals of m4. |
-`---------------------*/
-
-static void
-m4_ifdef (struct obstack *obs, int argc, token_data **argv)
-{
- symbol *s;
- const char *result;
-
- if (bad_argc (argv[0], argc, 3, 4))
- return;
- s = lookup_symbol (ARG (1), SYMBOL_LOOKUP);
-
- if (s != NULL && SYMBOL_TYPE (s) != TOKEN_VOID)
- result = ARG (2);
- else if (argc >= 4)
- result = ARG (3);
- else
- result = NULL;
-
- if (result != NULL)
- obstack_grow (obs, result, strlen (result));
-}
-
-static void
-m4_ifelse (struct obstack *obs, int argc, token_data **argv)
-{
- const char *result;
- token_data *me = argv[0];
-
- if (argc == 2)
- return;
-
- if (bad_argc (me, argc, 4, -1))
- return;
- else
- /* Diagnose excess arguments if 5, 8, 11, etc., actual arguments. */
- bad_argc (me, (argc + 2) % 3, -1, 1);
-
- argv++;
- argc--;
-
- result = NULL;
- while (result == NULL)
-
- if (STREQ (ARG (0), ARG (1)))
- result = ARG (2);
-
- else
- switch (argc)
- {
- case 3:
- return;
-
- case 4:
- case 5:
- result = ARG (3);
- break;
-
- default:
- argc -= 3;
- argv += 3;
- }
-
- obstack_grow (obs, result, strlen (result));
-}
-
-/*-------------------------------------------------------------------.
-| The function dump_symbol () is for use by "dumpdef". It builds up |
-| a table of all defined, un-shadowed, symbols. |
-`-------------------------------------------------------------------*/
-
-/* The structure dump_symbol_data is used to pass the information needed
- from call to call to dump_symbol. */
-
-struct dump_symbol_data
-{
- struct obstack *obs; /* obstack for table */
- symbol **base; /* base of table */
- int size; /* size of table */
-};
-
-static void
-dump_symbol (symbol *sym, void *arg)
-{
- struct dump_symbol_data *data = (struct dump_symbol_data *) arg;
- if (!SYMBOL_SHADOWED (sym) && SYMBOL_TYPE (sym) != TOKEN_VOID)
- {
- obstack_blank (data->obs, sizeof (symbol *));
- data->base = (symbol **) obstack_base (data->obs);
- data->base[data->size++] = sym;
- }
-}
-
-/*------------------------------------------------------------------------.
-| qsort comparison routine, for sorting the table made in m4_dumpdef (). |
-`------------------------------------------------------------------------*/
-
-static int
-dumpdef_cmp (const void *s1, const void *s2)
-{
- return strcmp (SYMBOL_NAME (* (symbol *const *) s1),
- SYMBOL_NAME (* (symbol *const *) s2));
-}
-
-/*-------------------------------------------------------------.
-| Implementation of "dumpdef" itself. It builds up a table of |
-| pointers to symbols, sorts it and prints the sorted table. |
-`-------------------------------------------------------------*/
-
-static void
-m4_dumpdef (struct obstack *obs, int argc, token_data **argv)
-{
- symbol *s;
- int i;
- struct dump_symbol_data data;
- const builtin *bp;
-
- data.obs = obs;
- data.base = (symbol **) obstack_base (obs);
- data.size = 0;
-
- if (argc == 1)
- {
- hack_all_symbols (dump_symbol, &data);
- }
- else
- {
- for (i = 1; i < argc; i++)
- {
- s = lookup_symbol (TOKEN_DATA_TEXT (argv[i]), SYMBOL_LOOKUP);
- if (s != NULL && SYMBOL_TYPE (s) != TOKEN_VOID)
- dump_symbol (s, &data);
- else
- M4ERROR ((warning_status, 0,
- "undefined macro `%s'", TOKEN_DATA_TEXT (argv[i])));
- }
- }
-
- /* Make table of symbols invisible to expand_macro (). */
-
- obstack_finish (obs);
-
- qsort (data.base, data.size, sizeof (symbol *), dumpdef_cmp);
-
- for (; data.size > 0; --data.size, data.base++)
- {
- DEBUG_PRINT1 ("%s:\t", SYMBOL_NAME (data.base[0]));
-
- switch (SYMBOL_TYPE (data.base[0]))
- {
- case TOKEN_TEXT:
- if (debug_level & DEBUG_TRACE_QUOTE)
- DEBUG_PRINT3 ("%s%s%s\n",
- lquote.string, SYMBOL_TEXT (data.base[0]), rquote.string);
- else
- DEBUG_PRINT1 ("%s\n", SYMBOL_TEXT (data.base[0]));
- break;
-
- case TOKEN_FUNC:
- bp = find_builtin_by_addr (SYMBOL_FUNC (data.base[0]));
- if (bp == NULL)
- {
- M4ERROR ((warning_status, 0, "\
-INTERNAL ERROR: builtin not found in builtin table"));
- abort ();
- }
- DEBUG_PRINT1 ("<%s>\n", bp->name);
- break;
-
- case TOKEN_VOID:
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad token data type in m4_dumpdef ()"));
- abort ();
- break;
- }
- }
-}
-
-/*-----------------------------------------------------------------.
-| The builtin "builtin" allows calls to builtin macros, even if |
-| their definition has been overridden or shadowed. It is thus |
-| possible to redefine builtins, and still access their original |
-| definition. This macro is not available in compatibility mode. |
-`-----------------------------------------------------------------*/
-
-static void
-m4_builtin (struct obstack *obs, int argc, token_data **argv)
-{
- const builtin *bp;
- const char *name;
-
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- if (TOKEN_DATA_TYPE (argv[1]) != TOKEN_TEXT)
- {
- M4ERROR ((warning_status, 0,
- "Warning: %s: invalid macro name ignored", ARG (0)));
- return;
- }
-
- name = ARG (1);
- bp = find_builtin_by_name (name);
- if (bp->func == m4_placeholder)
- M4ERROR ((warning_status, 0,
- "undefined builtin `%s'", name));
- else
- {
- int i;
- if (! bp->groks_macro_args)
- for (i = 2; i < argc; i++)
- if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT)
- {
- TOKEN_DATA_TYPE (argv[i]) = TOKEN_TEXT;
- TOKEN_DATA_TEXT (argv[i]) = (char *) "";
- }
- bp->func (obs, argc - 1, argv + 1);
- }
-}
-
-/*-------------------------------------------------------------------.
-| The builtin "indir" allows indirect calls to macros, even if their |
-| name is not a proper macro name. It is thus possible to define |
-| macros with ill-formed names for internal use in larger macro |
-| packages. This macro is not available in compatibility mode. |
-`-------------------------------------------------------------------*/
-
-static void
-m4_indir (struct obstack *obs, int argc, token_data **argv)
-{
- symbol *s;
- const char *name;
-
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- if (TOKEN_DATA_TYPE (argv[1]) != TOKEN_TEXT)
- {
- M4ERROR ((warning_status, 0,
- "Warning: %s: invalid macro name ignored", ARG (0)));
- return;
- }
-
- name = ARG (1);
- s = lookup_symbol (name, SYMBOL_LOOKUP);
- if (s == NULL || SYMBOL_TYPE (s) == TOKEN_VOID)
- M4ERROR ((warning_status, 0,
- "undefined macro `%s'", name));
- else
- {
- int i;
- if (! SYMBOL_MACRO_ARGS (s))
- for (i = 2; i < argc; i++)
- if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT)
- {
- TOKEN_DATA_TYPE (argv[i]) = TOKEN_TEXT;
- TOKEN_DATA_TEXT (argv[i]) = (char *) "";
- }
- call_macro (s, argc - 1, argv + 1, obs);
- }
-}
-
-/*------------------------------------------------------------------.
-| The macro "defn" returns the quoted definition of the macro named |
-| by the first argument. If the macro is builtin, it will push a |
-| special macro-definition token on the input stack. |
-`------------------------------------------------------------------*/
-
-static void
-m4_defn (struct obstack *obs, int argc, token_data **argv)
-{
- symbol *s;
- builtin_func *b;
- unsigned int i;
-
- if (bad_argc (argv[0], argc, 2, -1))
- return;
-
- assert (0 < argc);
- for (i = 1; i < (unsigned) argc; i++)
- {
- const char *arg = ARG((int) i);
- s = lookup_symbol (arg, SYMBOL_LOOKUP);
- if (s == NULL)
- continue;
-
- switch (SYMBOL_TYPE (s))
- {
- case TOKEN_TEXT:
- obstack_grow (obs, lquote.string, lquote.length);
- obstack_grow (obs, SYMBOL_TEXT (s), strlen (SYMBOL_TEXT (s)));
- obstack_grow (obs, rquote.string, rquote.length);
- break;
-
- case TOKEN_FUNC:
- b = SYMBOL_FUNC (s);
- if (b == m4_placeholder)
- M4ERROR ((warning_status, 0, "\
-builtin `%s' requested by frozen file is not supported", arg));
- else if (argc != 2)
- M4ERROR ((warning_status, 0,
- "Warning: cannot concatenate builtin `%s'",
- arg));
- else
- push_macro (b);
- break;
-
- case TOKEN_VOID:
- /* Nothing to do for traced but undefined macro. */
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad symbol type in m4_defn ()"));
- abort ();
- }
- }
-}
-
-/*--------------------------------------------------------------.
-| This section contains macros to handle the builtins "syscmd", |
-| "esyscmd" and "sysval". "esyscmd" is GNU specific. |
-`--------------------------------------------------------------*/
-
-/* Exit code from last "syscmd" command. */
-static int sysval;
-
-static void
-m4_syscmd (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- const char *cmd = ARG (1);
- int status;
- int sig_status;
- const char *prog_args[4] = { "sh", "-c" };
- if (bad_argc (argv[0], argc, 2, 2) || !*cmd)
- {
- /* The empty command is successful. */
- sysval = 0;
- return;
- }
-
- debug_flush_files ();
-#if W32_NATIVE
- if (strstr (SYSCMD_SHELL, "cmd"))
- {
- prog_args[0] = "cmd";
- prog_args[1] = "/c";
- }
-#endif
- prog_args[2] = cmd;
- errno = 0;
- status = execute (ARG (0), SYSCMD_SHELL, (char **) prog_args, false,
- false, false, false, true, false, &sig_status);
- if (sig_status)
- {
- assert (status == 127);
- sysval = sig_status << 8;
- }
- else
- {
- if (status == 127 && errno)
- M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
- sysval = status;
- }
-}
-
-static void
-m4_esyscmd (struct obstack *obs, int argc, token_data **argv)
-{
- const char *cmd = ARG (1);
- const char *prog_args[4] = { "sh", "-c" };
- pid_t child;
- int fd;
- FILE *pin;
- int status;
- int sig_status;
-
- if (bad_argc (argv[0], argc, 2, 2) || !*cmd)
- {
- /* The empty command is successful. */
- sysval = 0;
- return;
- }
-
- debug_flush_files ();
-#if W32_NATIVE
- if (strstr (SYSCMD_SHELL, "cmd"))
- {
- prog_args[0] = "cmd";
- prog_args[1] = "/c";
- }
-#endif
- prog_args[2] = cmd;
- errno = 0;
- child = create_pipe_in (ARG (0), SYSCMD_SHELL, (char **) prog_args,
- NULL, false, true, false, &fd);
- if (child == -1)
- {
- M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
- sysval = 127;
- return;
- }
- pin = fdopen (fd, "r");
- if (pin == NULL)
- {
- M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
- sysval = 127;
- close (fd);
- return;
- }
- while (1)
- {
- size_t avail = obstack_room (obs);
- size_t len;
- if (!avail)
- {
- int ch = getc (pin);
- if (ch == EOF)
- break;
- obstack_1grow (obs, ch);
- continue;
- }
- len = fread (obstack_next_free (obs), 1, avail, pin);
- if (len <= 0)
- break;
- obstack_blank_fast (obs, len);
- }
- if (ferror (pin) || fclose (pin))
- M4ERROR ((EXIT_FAILURE, errno, "cannot read pipe"));
- errno = 0;
- status = wait_subprocess (child, ARG (0), false, true, true, false,
- &sig_status);
- if (sig_status)
- {
- assert (status == 127);
- sysval = sig_status << 8;
- }
- else
- {
- if (status == 127 && errno)
- M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
- sysval = status;
- }
-}
-
-static void
-m4_sysval (struct obstack *obs, int argc M4_GNUC_UNUSED,
- token_data **argv M4_GNUC_UNUSED)
-{
- shipout_int (obs, sysval);
-}
-
-/*------------------------------------------------------------------.
-| This section contains the top level code for the "eval" builtin. |
-| The actual work is done in the function evaluate (), which lives |
-| in eval.c. |
-`------------------------------------------------------------------*/
-
-static void
-m4_eval (struct obstack *obs, int argc, token_data **argv)
-{
- int32_t value = 0;
- int radix = 10;
- int min = 1;
- const char *s;
-
- if (bad_argc (argv[0], argc, 2, 4))
- return;
-
- if (*ARG (2) && !numeric_arg (argv[0], ARG (2), &radix))
- return;
-
- if (radix < 1 || radix > (int) strlen (digits))
- {
- M4ERROR ((warning_status, 0,
- "radix %d in builtin `%s' out of range",
- radix, ARG (0)));
- return;
- }
-
- if (argc >= 4 && !numeric_arg (argv[0], ARG (3), &min))
- return;
- if (min < 0)
- {
- M4ERROR ((warning_status, 0,
- "negative width to builtin `%s'", ARG (0)));
- return;
- }
-
- if (!*ARG (1))
- M4ERROR ((warning_status, 0,
- "empty string treated as 0 in builtin `%s'", ARG (0)));
- else if (evaluate (ARG (1), &value))
- return;
-
- if (radix == 1)
- {
- if (value < 0)
- {
- obstack_1grow (obs, '-');
- value = -value;
- }
- /* This assumes 2's-complement for correctly handling INT_MIN. */
- while (min-- - value > 0)
- obstack_1grow (obs, '0');
- while (value-- != 0)
- obstack_1grow (obs, '1');
- obstack_1grow (obs, '\0');
- return;
- }
-
- s = ntoa (value, radix);
-
- if (*s == '-')
- {
- obstack_1grow (obs, '-');
- s++;
- }
- for (min -= strlen (s); --min >= 0;)
- obstack_1grow (obs, '0');
-
- obstack_grow (obs, s, strlen (s));
-}
-
-static void
-m4_incr (struct obstack *obs, int argc, token_data **argv)
-{
- int value;
-
- if (bad_argc (argv[0], argc, 2, 2))
- return;
-
- if (!numeric_arg (argv[0], ARG (1), &value))
- return;
-
- shipout_int (obs, value + 1);
-}
-
-static void
-m4_decr (struct obstack *obs, int argc, token_data **argv)
-{
- int value;
-
- if (bad_argc (argv[0], argc, 2, 2))
- return;
-
- if (!numeric_arg (argv[0], ARG (1), &value))
- return;
-
- shipout_int (obs, value - 1);
-}
-
-/* This section contains the macros "divert", "undivert" and "divnum" for
- handling diversion. The utility functions used lives in output.c. */
-
-/*-----------------------------------------------------------------.
-| Divert further output to the diversion given by ARGV[1]. Out of |
-| range means discard further output. |
-`-----------------------------------------------------------------*/
-
-static void
-m4_divert (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- int i = 0;
-
- if (bad_argc (argv[0], argc, 1, 2))
- return;
-
- if (argc >= 2 && !numeric_arg (argv[0], ARG (1), &i))
- return;
-
- make_diversion (i);
-}
-
-/*-----------------------------------------------------.
-| Expand to the current diversion number, -1 if none. |
-`-----------------------------------------------------*/
-
-static void
-m4_divnum (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 1))
- return;
- shipout_int (obs, current_diversion);
-}
-
-/*------------------------------------------------------------------.
-| Bring back the diversion given by the argument list. If none is |
-| specified, bring back all diversions. GNU specific is the option |
-| of undiverting named files, by passing a non-numeric argument to |
-| undivert (). |
-`------------------------------------------------------------------*/
-
-static void
-m4_undivert (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- int i, file;
- FILE *fp;
- char *endp;
-
- if (argc == 1)
- undivert_all ();
- else
- for (i = 1; i < argc; i++)
- {
- file = strtol (ARG (i), &endp, 10);
- if (*endp == '\0' && !isspace (to_uchar (*ARG (i))))
- insert_diversion (file);
- else if (no_gnu_extensions)
- M4ERROR ((warning_status, 0,
- "non-numeric argument to builtin `%s'", ARG (0)));
- else
- {
- fp = m4_path_search (ARG (i), NULL);
- if (fp != NULL)
- {
- insert_file (fp);
- if (fclose (fp) == EOF)
- M4ERROR ((warning_status, errno,
- "error undiverting `%s'", ARG (i)));
- }
- else
- M4ERROR ((warning_status, errno,
- "cannot undivert `%s'", ARG (i)));
- }
- }
-}
-
-/* This section contains various macros, which does not fall into any
- specific group. These are "dnl", "shift", "changequote", "changecom"
- and "changeword". */
-
-/*-----------------------------------------------------------.
-| Delete all subsequent whitespace from input. The function |
-| skip_line () lives in input.c. |
-`-----------------------------------------------------------*/
-
-static void
-m4_dnl (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 1))
- return;
-
- skip_line ();
-}
-
-/*--------------------------------------------------------------------.
-| Shift all arguments one to the left, discarding the first |
-| argument. Each output argument is quoted with the current quotes. |
-`--------------------------------------------------------------------*/
-
-static void
-m4_shift (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- dump_args (obs, argc - 1, argv + 1, ",", true);
-}
-
-/*--------------------------------------------------------------------------.
-| Change the current quotes. The function set_quotes () lives in input.c. |
-`--------------------------------------------------------------------------*/
-
-static void
-m4_changequote (struct obstack *obs M4_GNUC_UNUSED, int argc,
- token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 3))
- return;
-
- /* Explicit NULL distinguishes between empty and missing argument. */
- set_quotes ((argc >= 2) ? TOKEN_DATA_TEXT (argv[1]) : NULL,
- (argc >= 3) ? TOKEN_DATA_TEXT (argv[2]) : NULL);
-}
-
-/*-----------------------------------------------------------------.
-| Change the current comment delimiters. The function set_comment |
-| () lives in input.c. |
-`-----------------------------------------------------------------*/
-
-static void
-m4_changecom (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 3))
- return;
-
- /* Explicit NULL distinguishes between empty and missing argument. */
- set_comment ((argc >= 2) ? TOKEN_DATA_TEXT (argv[1]) : NULL,
- (argc >= 3) ? TOKEN_DATA_TEXT (argv[2]) : NULL);
-}
-
-#ifdef ENABLE_CHANGEWORD
-
-/*---------------------------------------------------------------.
-| Change the regular expression used for breaking the input into |
-| words. The function set_word_regexp () lives in input.c. |
-`---------------------------------------------------------------*/
-
-static void
-m4_changeword (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, 2))
- return;
-
- set_word_regexp (TOKEN_DATA_TEXT (argv[1]));
-}
-
-#endif /* ENABLE_CHANGEWORD */
-
-/* This section contains macros for inclusion of other files -- "include"
- and "sinclude". This differs from bringing back diversions, in that
- the input is scanned before being copied to the output. */
-
-/*---------------------------------------------------------------.
-| Generic include function. Include the file given by the first |
-| argument, if it exists. Complain about inaccessible files iff |
-| SILENT is false. |
-`---------------------------------------------------------------*/
-
-static void
-include (int argc, token_data **argv, bool silent)
-{
- FILE *fp;
- char *name;
-
- if (bad_argc (argv[0], argc, 2, 2))
- return;
-
- fp = m4_path_search (ARG (1), &name);
- if (fp == NULL)
- {
- if (!silent)
- {
- M4ERROR ((warning_status, errno, "cannot open `%s'", ARG (1)));
- retcode = EXIT_FAILURE;
- }
- return;
- }
-
- push_file (fp, name, true);
- free (name);
-}
-
-/*------------------------------------------------.
-| Include a file, complaining in case of errors. |
-`------------------------------------------------*/
-
-static void
-m4_include (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- include (argc, argv, false);
-}
-
-/*----------------------------------.
-| Include a file, ignoring errors. |
-`----------------------------------*/
-
-static void
-m4_sinclude (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- include (argc, argv, true);
-}
-
-/* More miscellaneous builtins -- "maketemp", "errprint", "__file__",
- "__line__", and "__program__". The last three are GNU specific. */
-
-/*------------------------------------------------------------------.
-| Use the first argument as at template for a temporary file name. |
-`------------------------------------------------------------------*/
-
-/* Add trailing 'X' to PATTERN of length LEN as necessary, then
- securely create the file, and place the quoted new file name on
- OBS. Report errors on behalf of ME. */
-static void
-mkstemp_helper (struct obstack *obs, const char *me, const char *pattern,
- size_t len)
-{
- int fd;
- size_t i;
- char *name;
-
- /* Guarantee that there are six trailing 'X' characters, even if the
- user forgot to supply them. Output must be quoted if
- successful. */
- obstack_grow (obs, lquote.string, lquote.length);
- obstack_grow (obs, pattern, len);
- for (i = 0; len > 0 && i < 6; i++)
- if (pattern[len - i - 1] != 'X')
- break;
- obstack_grow0 (obs, "XXXXXX", 6 - i);
- name = (char *) obstack_base (obs) + lquote.length;
-
- errno = 0;
- fd = mkstemp (name);
- if (fd < 0)
- {
- M4ERROR ((0, errno, "%s: cannot create tempfile `%s'", me, pattern));
- obstack_free (obs, obstack_finish (obs));
- }
- else
- {
- close (fd);
- /* Remove NUL, then finish quote. */
- obstack_blank (obs, -1);
- obstack_grow (obs, rquote.string, rquote.length);
- }
-}
-
-static void
-m4_maketemp (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, 2))
- return;
- if (no_gnu_extensions)
- {
- /* POSIX states "any trailing 'X' characters [are] replaced with
- the current process ID as a string", without referencing the
- file system. Horribly insecure, but we have to do it when we
- are in traditional mode.
-
- For reference, Solaris m4 does:
- maketemp() -> `'
- maketemp(X) -> `X'
- maketemp(XX) -> `Xn', where n is last digit of pid
- maketemp(XXXXXXXX) -> `X00nnnnn', where nnnnn is 16-bit pid
- */
- const char *str = ARG (1);
- int len = strlen (str);
- int i;
- int len2;
-
- M4ERROR ((warning_status, 0, "recommend using mkstemp instead"));
- for (i = len; i > 1; i--)
- if (str[i - 1] != 'X')
- break;
- obstack_grow (obs, str, i);
- str = ntoa ((int32_t) getpid (), 10);
- len2 = strlen (str);
- if (len2 > len - i)
- obstack_grow0 (obs, str + len2 - (len - i), len - i);
- else
- {
- while (i++ < len - len2)
- obstack_1grow (obs, '0');
- obstack_grow0 (obs, str, len2);
- }
- }
- else
- mkstemp_helper (obs, ARG (0), ARG (1), strlen (ARG (1)));
-}
-
-static void
-m4_mkstemp (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, 2))
- return;
- mkstemp_helper (obs, ARG (0), ARG (1), strlen (ARG (1)));
-}
-
-/*----------------------------------------.
-| Print all arguments on standard error. |
-`----------------------------------------*/
-
-static void
-m4_errprint (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- dump_args (obs, argc, argv, " ", false);
- obstack_1grow (obs, '\0');
- debug_flush_files ();
- xfprintf (stderr, "%s", (char *) obstack_finish (obs));
- fflush (stderr);
-}
-
-static void
-m4___file__ (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 1))
- return;
- obstack_grow (obs, lquote.string, lquote.length);
- obstack_grow (obs, current_file, strlen (current_file));
- obstack_grow (obs, rquote.string, rquote.length);
-}
-
-static void
-m4___line__ (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 1))
- return;
- shipout_int (obs, current_line);
-}
-
-static void
-m4___program__ (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 1))
- return;
- obstack_grow (obs, lquote.string, lquote.length);
- obstack_grow (obs, program_name, strlen (program_name));
- obstack_grow (obs, rquote.string, rquote.length);
-}
-
-/* This section contains various macros for exiting, saving input until
- EOF is seen, and tracing macro calls. That is: "m4exit", "m4wrap",
- "traceon" and "traceoff". */
-
-/*----------------------------------------------------------.
-| Exit immediately, with exit status specified by the first |
-| argument, or 0 if no arguments are present. |
-`----------------------------------------------------------*/
-
-static void M4_GNUC_NORETURN
-m4_m4exit (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- int exit_code = EXIT_SUCCESS;
-
- /* Warn on bad arguments, but still exit. */
- bad_argc (argv[0], argc, 1, 2);
- if (argc >= 2 && !numeric_arg (argv[0], ARG (1), &exit_code))
- exit_code = EXIT_FAILURE;
- if (exit_code < 0 || exit_code > 255)
- {
- M4ERROR ((warning_status, 0,
- "exit status out of range: `%d'", exit_code));
- exit_code = EXIT_FAILURE;
- }
- /* Change debug stream back to stderr, to force flushing debug stream and
- detect any errors it might have encountered. */
- debug_set_output (NULL);
- debug_flush_files ();
- if (exit_code == EXIT_SUCCESS && retcode != EXIT_SUCCESS)
- exit_code = retcode;
- /* Propagate non-zero status to atexit handlers. */
- if (exit_code != EXIT_SUCCESS)
- exit_failure = exit_code;
- exit (exit_code);
-}
-
-/*------------------------------------------------------------------.
-| Save the argument text until EOF has been seen, allowing for user |
-| specified cleanup action. GNU version saves all arguments, the |
-| standard version only the first. |
-`------------------------------------------------------------------*/
-
-static void
-m4_m4wrap (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- if (no_gnu_extensions)
- obstack_grow (obs, ARG (1), strlen (ARG (1)));
- else
- dump_args (obs, argc, argv, " ", false);
- obstack_1grow (obs, '\0');
- push_wrapup ((char *) obstack_finish (obs));
-}
-
-/* Enable tracing of all specified macros, or all, if none is specified.
- Tracing is disabled by default, when a macro is defined. This can be
- overridden by the "t" debug flag. */
-
-/*------------------------------------------------------------------.
-| Set_trace () is used by "traceon" and "traceoff" to enable and |
-| disable tracing of a macro. It disables tracing if DATA is NULL, |
-| otherwise it enables tracing. |
-`------------------------------------------------------------------*/
-
-static void
-set_trace (symbol *sym, void *data)
-{
- SYMBOL_TRACED (sym) = data != NULL;
- /* Remove placeholder from table if macro is undefined and untraced. */
- if (SYMBOL_TYPE (sym) == TOKEN_VOID && data == NULL)
- lookup_symbol (SYMBOL_NAME (sym), SYMBOL_POPDEF);
-}
-
-static void
-m4_traceon (struct obstack *obs, int argc, token_data **argv)
-{
- symbol *s;
- int i;
-
- if (argc == 1)
- hack_all_symbols (set_trace, obs);
- else
- for (i = 1; i < argc; i++)
- {
- s = lookup_symbol (ARG (i), SYMBOL_LOOKUP);
- if (!s)
- s = lookup_symbol (ARG (i), SYMBOL_INSERT);
- set_trace (s, obs);
- }
-}
-
-/*------------------------------------------------------------------------.
-| Disable tracing of all specified macros, or all, if none is specified. |
-`------------------------------------------------------------------------*/
-
-static void
-m4_traceoff (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- symbol *s;
- int i;
-
- if (argc == 1)
- hack_all_symbols (set_trace, NULL);
- else
- for (i = 1; i < argc; i++)
- {
- s = lookup_symbol (TOKEN_DATA_TEXT (argv[i]), SYMBOL_LOOKUP);
- if (s != NULL)
- set_trace (s, NULL);
- }
-}
-
-/*------------------------------------------------------------------.
-| On-the-fly control of the format of the tracing output. It takes |
-| one argument, which is a character string like given to the -d |
-| option, or none in which case the debug_level is zeroed. |
-`------------------------------------------------------------------*/
-
-static void
-m4_debugmode (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- int new_debug_level;
- int change_flag;
-
- if (bad_argc (argv[0], argc, 1, 2))
- return;
-
- if (argc == 1)
- debug_level = 0;
- else
- {
- if (ARG (1)[0] == '+' || ARG (1)[0] == '-')
- {
- change_flag = ARG (1)[0];
- new_debug_level = debug_decode (ARG (1) + 1);
- }
- else
- {
- change_flag = 0;
- new_debug_level = debug_decode (ARG (1));
- }
-
- if (new_debug_level < 0)
- M4ERROR ((warning_status, 0,
- "Debugmode: bad debug flags: `%s'", ARG (1)));
- else
- {
- switch (change_flag)
- {
- case 0:
- debug_level = new_debug_level;
- break;
-
- case '+':
- debug_level |= new_debug_level;
- break;
-
- case '-':
- debug_level &= ~new_debug_level;
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad flag in m4_debugmode ()"));
- abort ();
- }
- }
- }
-}
-
-/*-------------------------------------------------------------------------.
-| Specify the destination of the debugging output. With one argument, the |
-| argument is taken as a file name, with no arguments, revert to stderr. |
-`-------------------------------------------------------------------------*/
-
-static void
-m4_debugfile (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 1, 2))
- return;
-
- if (argc == 1)
- debug_set_output (NULL);
- else if (!debug_set_output (ARG (1)))
- M4ERROR ((warning_status, errno,
- "cannot set debug file `%s'", ARG (1)));
-}
-
-/* This section contains text processing macros: "len", "index",
- "substr", "translit", "format", "regexp" and "patsubst". The last
- three are GNU specific. */
-
-/*---------------------------------------------.
-| Expand to the length of the first argument. |
-`---------------------------------------------*/
-
-static void
-m4_len (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, 2))
- return;
- shipout_int (obs, strlen (ARG (1)));
-}
-
-/*-------------------------------------------------------------------.
-| The macro expands to the first index of the second argument in the |
-| first argument. |
-`-------------------------------------------------------------------*/
-
-static void
-m4_index (struct obstack *obs, int argc, token_data **argv)
-{
- const char *haystack;
- const char *result;
- int retval;
-
- if (bad_argc (argv[0], argc, 3, 3))
- {
- /* builtin(`index') is blank, but index(`abc') is 0. */
- if (argc == 2)
- shipout_int (obs, 0);
- return;
- }
-
- haystack = ARG (1);
- result = strstr (haystack, ARG (2));
- retval = result ? result - haystack : -1;
-
- shipout_int (obs, retval);
-}
-
-/*-----------------------------------------------------------------.
-| The macro "substr" extracts substrings from the first argument, |
-| starting from the index given by the second argument, extending |
-| for a length given by the third argument. If the third argument |
-| is missing, the substring extends to the end of the first |
-| argument. |
-`-----------------------------------------------------------------*/
-
-static void
-m4_substr (struct obstack *obs, int argc, token_data **argv)
-{
- int start = 0;
- int length, avail;
-
- if (bad_argc (argv[0], argc, 3, 4))
- {
- /* builtin(`substr') is blank, but substr(`abc') is abc. */
- if (argc == 2)
- obstack_grow (obs, ARG (1), strlen (ARG (1)));
- return;
- }
-
- length = avail = strlen (ARG (1));
- if (!numeric_arg (argv[0], ARG (2), &start))
- return;
-
- if (argc >= 4 && !numeric_arg (argv[0], ARG (3), &length))
- return;
-
- if (start < 0 || length <= 0 || start >= avail)
- return;
-
- if (start + length > avail)
- length = avail - start;
- obstack_grow (obs, ARG (1) + start, length);
-}
-
-/*------------------------------------------------------------------.
-| For "translit", ranges are allowed in the second and third |
-| argument. They are expanded in the following function, and the |
-| expanded strings, without any ranges left, are used to translate |
-| the characters of the first argument. A single - (dash) can be |
-| included in the strings by being the first or the last character |
-| in the string. If the first character in a range is after the |
-| first in the character set, the range is made backwards, thus 9-0 |
-| is the string 9876543210. |
-`------------------------------------------------------------------*/
-
-static const char *
-expand_ranges (const char *s, struct obstack *obs)
-{
- unsigned char from;
- unsigned char to;
-
- for (from = '\0'; *s != '\0'; from = to_uchar (*s++))
- {
- if (*s == '-' && from != '\0')
- {
- to = to_uchar (*++s);
- if (to == '\0')
- {
- /* trailing dash */
- obstack_1grow (obs, '-');
- break;
- }
- else if (from <= to)
- {
- while (from++ < to)
- obstack_1grow (obs, from);
- }
- else
- {
- while (--from >= to)
- obstack_1grow (obs, from);
- }
- }
- else
- obstack_1grow (obs, *s);
- }
- obstack_1grow (obs, '\0');
- return (char *) obstack_finish (obs);
-}
-
-/*-----------------------------------------------------------------.
-| The macro "translit" translates all characters in the first |
-| argument, which are present in the second argument, into the |
-| corresponding character from the third argument. If the third |
-| argument is shorter than the second, the extra characters in the |
-| second argument are deleted from the first. |
-`-----------------------------------------------------------------*/
-
-static void
-m4_translit (struct obstack *obs, int argc, token_data **argv)
-{
- const char *data = ARG (1);
- const char *from = ARG (2);
- const char *to;
- char map[UCHAR_MAX + 1];
- char found[UCHAR_MAX + 1];
- unsigned char ch;
-
- if (bad_argc (argv[0], argc, 3, 4) || !*data || !*from)
- {
- /* builtin(`translit') is blank, but translit(`abc') is abc. */
- if (2 <= argc)
- obstack_grow (obs, data, strlen (data));
- return;
- }
-
- to = ARG (3);
- if (strchr (to, '-') != NULL)
- {
- to = expand_ranges (to, obs);
- assert (to && *to);
- }
-
- /* If there are only one or two bytes to replace, it is faster to
- use memchr2. Using expand_ranges does nothing unless there are
- at least three bytes. */
- if (!from[1] || !from[2])
- {
- const char *p;
- size_t len = strlen (data);
- while ((p = (char *) memchr2 (data, from[0], from[1], len)))
- {
- obstack_grow (obs, data, p - data);
- len -= p - data;
- if (!len)
- return;
- data = p + 1;
- len--;
- if (*p == from[0] && to[0])
- obstack_1grow (obs, to[0]);
- else if (*p == from[1] && to[0] && to[1])
- obstack_1grow (obs, to[1]);
- }
- obstack_grow (obs, data, len);
- return;
- }
-
- if (strchr (from, '-') != NULL)
- {
- from = expand_ranges (from, obs);
- assert (from && *from);
- }
-
- /* Calling strchr(from) for each character in data is quadratic,
- since both strings can be arbitrarily long. Instead, create a
- from-to mapping in one pass of from, then use that map in one
- pass of data, for linear behavior. Traditional behavior is that
- only the first instance of a character in from is consulted,
- hence the found map. */
- memset (map, 0, sizeof map);
- memset (found, 0, sizeof found);
- for ( ; (ch = *from) != '\0'; from++)
- {
- if (! found[ch])
- {
- found[ch] = 1;
- map[ch] = *to;
- }
- if (*to != '\0')
- to++;
- }
-
- for (data = ARG (1); (ch = *data) != '\0'; data++)
- {
- if (! found[ch])
- obstack_1grow (obs, ch);
- else if (map[ch])
- obstack_1grow (obs, map[ch]);
- }
-}
-
-/*-------------------------------------------------------------------.
-| Frontend for printf like formatting. The function format () lives |
-| in the file format.c. |
-`-------------------------------------------------------------------*/
-
-static void
-m4_format (struct obstack *obs, int argc, token_data **argv)
-{
- if (bad_argc (argv[0], argc, 2, -1))
- return;
- expand_format (obs, argc - 1, argv + 1);
-}
-
-/*------------------------------------------------------------------.
-| Function to perform substitution by regular expressions. Used by |
-| the builtins regexp and patsubst. The changed text is placed on |
-| the obstack. The substitution is REPL, with \& substituted by |
-| this part of VICTIM matched by the last whole regular expression, |
-| taken from REGS[0], and \N substituted by the text matched by the |
-| Nth parenthesized sub-expression, taken from REGS[N]. |
-`------------------------------------------------------------------*/
-
-static int substitute_warned = 0;
-
-static void
-substitute (struct obstack *obs, const char *victim, const char *repl,
- struct re_registers *regs)
-{
- int ch;
- __re_size_t ind;
- while (1)
- {
- const char *backslash = strchr (repl, '\\');
- if (!backslash)
- {
- obstack_grow (obs, repl, strlen (repl));
- return;
- }
- obstack_grow (obs, repl, backslash - repl);
- repl = backslash;
- ch = *++repl;
- switch (ch)
- {
- case '0':
- if (!substitute_warned)
- {
- M4ERROR ((warning_status, 0, "\
-Warning: \\0 will disappear, use \\& instead in replacements"));
- substitute_warned = 1;
- }
- /* Fall through. */
-
- case '&':
- obstack_grow (obs, victim + regs->start[0],
- regs->end[0] - regs->start[0]);
- repl++;
- break;
-
- case '1': case '2': case '3': case '4': case '5': case '6':
- case '7': case '8': case '9':
- ind = ch -= '0';
- if (regs->num_regs - 1 <= ind)
- M4ERROR ((warning_status, 0,
- "Warning: sub-expression %d not present", ch));
- else if (regs->end[ch] > 0)
- obstack_grow (obs, victim + regs->start[ch],
- regs->end[ch] - regs->start[ch]);
- repl++;
- break;
-
- case '\0':
- M4ERROR ((warning_status, 0,
- "Warning: trailing \\ ignored in replacement"));
- return;
-
- default:
- obstack_1grow (obs, ch);
- repl++;
- break;
- }
- }
-}
-
-/*------------------------------------------.
-| Initialize regular expression variables. |
-`------------------------------------------*/
-
-void
-init_pattern_buffer (struct re_pattern_buffer *buf, struct re_registers *regs)
-{
- buf->translate = NULL;
- buf->fastmap = NULL;
- buf->buffer = NULL;
- buf->allocated = 0;
- if (regs)
- {
- regs->start = NULL;
- regs->end = NULL;
- }
-}
-
-/*------------------------------------------------------------------.
-| Regular expression version of index. Given two arguments, expand |
-| to the index of the first match of the second argument (a regexp) |
-| in the first. Expand to -1 if here is no match. Given a third |
-| argument, it changes the expansion to this argument. |
-`------------------------------------------------------------------*/
-
-static void
-m4_regexp (struct obstack *obs, int argc, token_data **argv)
-{
- const char *victim; /* first argument */
- const char *regexp; /* regular expression */
- const char *repl; /* replacement string */
-
- struct re_pattern_buffer buf; /* compiled regular expression */
- struct re_registers regs; /* for subexpression matches */
- const char *msg; /* error message from re_compile_pattern */
- int startpos; /* start position of match */
- int length; /* length of first argument */
-
- if (bad_argc (argv[0], argc, 3, 4))
- {
- /* builtin(`regexp') is blank, but regexp(`abc') is 0. */
- if (argc == 2)
- shipout_int (obs, 0);
- return;
- }
-
- victim = TOKEN_DATA_TEXT (argv[1]);
- regexp = TOKEN_DATA_TEXT (argv[2]);
-
- init_pattern_buffer (&buf, &regs);
- msg = re_compile_pattern (regexp, strlen (regexp), &buf);
-
- if (msg != NULL)
- {
- M4ERROR ((warning_status, 0,
- "bad regular expression: `%s': %s", regexp, msg));
- free_pattern_buffer (&buf, &regs);
- return;
- }
-
- length = strlen (victim);
- /* Avoid overhead of allocating regs if we won't use it. */
- startpos = re_search (&buf, victim, length, 0, length,
- argc == 3 ? NULL : &regs);
-
- if (startpos == -2)
- M4ERROR ((warning_status, 0,
- "error matching regular expression `%s'", regexp));
- else if (argc == 3)
- shipout_int (obs, startpos);
- else if (startpos >= 0)
- {
- repl = TOKEN_DATA_TEXT (argv[3]);
- substitute (obs, victim, repl, &regs);
- }
-
- free_pattern_buffer (&buf, &regs);
-}
-
-/*--------------------------------------------------------------------------.
-| Substitute all matches of a regexp occuring in a string. Each match of |
-| the second argument (a regexp) in the first argument is changed to the |
-| third argument, with \& substituted by the matched text, and \N |
-| substituted by the text matched by the Nth parenthesized sub-expression. |
-`--------------------------------------------------------------------------*/
-
-static void
-m4_patsubst (struct obstack *obs, int argc, token_data **argv)
-{
- const char *victim; /* first argument */
- const char *regexp; /* regular expression */
-
- struct re_pattern_buffer buf; /* compiled regular expression */
- struct re_registers regs; /* for subexpression matches */
- const char *msg; /* error message from re_compile_pattern */
- int matchpos; /* start position of match */
- int offset; /* current match offset */
- int length; /* length of first argument */
-
- if (bad_argc (argv[0], argc, 3, 4))
- {
- /* builtin(`patsubst') is blank, but patsubst(`abc') is abc. */
- if (argc == 2)
- obstack_grow (obs, ARG (1), strlen (ARG (1)));
- return;
- }
-
- regexp = TOKEN_DATA_TEXT (argv[2]);
-
- init_pattern_buffer (&buf, &regs);
- msg = re_compile_pattern (regexp, strlen (regexp), &buf);
-
- if (msg != NULL)
- {
- M4ERROR ((warning_status, 0,
- "bad regular expression `%s': %s", regexp, msg));
- free (buf.buffer);
- return;
- }
-
- victim = TOKEN_DATA_TEXT (argv[1]);
- length = strlen (victim);
-
- offset = 0;
- while (offset <= length)
- {
- matchpos = re_search (&buf, victim, length,
- offset, length - offset, &regs);
- if (matchpos < 0)
- {
-
- /* Match failed -- either error or there is no match in the
- rest of the string, in which case the rest of the string is
- copied verbatim. */
-
- if (matchpos == -2)
- M4ERROR ((warning_status, 0,
- "error matching regular expression `%s'", regexp));
- else if (offset < length)
- obstack_grow (obs, victim + offset, length - offset);
- break;
- }
-
- /* Copy the part of the string that was skipped by re_search (). */
-
- if (matchpos > offset)
- obstack_grow (obs, victim + offset, matchpos - offset);
-
- /* Handle the part of the string that was covered by the match. */
-
- substitute (obs, victim, ARG (3), &regs);
-
- /* Update the offset to the end of the match. If the regexp
- matched a null string, advance offset one more, to avoid
- infinite loops. */
-
- offset = regs.end[0];
- if (regs.start[0] == regs.end[0])
- obstack_1grow (obs, victim[offset++]);
- }
- obstack_1grow (obs, '\0');
-
- free_pattern_buffer (&buf, &regs);
-}
-
-/* Finally, a placeholder builtin. This builtin is not installed by
- default, but when reading back frozen files, this is associated
- with any builtin we don't recognize (for example, if the frozen
- file was created with a changeword capable m4, but is then loaded
- by a different m4 that does not support changeword). This way, we
- can keep 'm4 -R' quiet in the common case that the user did not
- know or care about the builtin when the frozen file was created,
- while still flagging it as a potential error if an attempt is made
- to actually use the builtin. */
-
-/*--------------------------------------------------------------------.
-| Issue a warning that this macro is a placeholder for an unsupported |
-| builtin that was requested while reloading a frozen file. |
-`--------------------------------------------------------------------*/
-
-void
-m4_placeholder (struct obstack *obs M4_GNUC_UNUSED, int argc,
- token_data **argv)
-{
- M4ERROR ((warning_status, 0, "\
-builtin `%s' requested by frozen file is not supported", ARG (0)));
-}
-
-/*-------------------------------------------------------------------.
-| This function handles all expansion of user defined and predefined |
-| macros. It is called with an obstack OBS, where the macros |
-| expansion will be placed, as an unfinished object. SYM points to |
-| the macro definition, giving the expansion text. ARGC and ARGV |
-| are the arguments, as usual. |
-`-------------------------------------------------------------------*/
-
-void
-expand_user_macro (struct obstack *obs, symbol *sym,
- int argc, token_data **argv)
-{
- const char *text = SYMBOL_TEXT (sym);
- int i;
- while (1)
- {
- const char *dollar = strchr (text, '$');
- if (!dollar)
- {
- obstack_grow (obs, text, strlen (text));
- return;
- }
- obstack_grow (obs, text, dollar - text);
- text = dollar;
- switch (*++text)
- {
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- if (no_gnu_extensions)
- {
- i = *text++ - '0';
- }
- else
- {
- for (i = 0; isdigit (to_uchar (*text)); text++)
- i = i*10 + (*text - '0');
- }
- if (i < argc)
- obstack_grow (obs, TOKEN_DATA_TEXT (argv[i]),
- strlen (TOKEN_DATA_TEXT (argv[i])));
- break;
-
- case '#': /* number of arguments */
- shipout_int (obs, argc - 1);
- text++;
- break;
-
- case '*': /* all arguments */
- case '@': /* ... same, but quoted */
- dump_args (obs, argc, argv, ",", *text == '@');
- text++;
- break;
-
- default:
- obstack_1grow (obs, '$');
- break;
- }
- }
-}
+#include "spawn-pipe.h"
+#include "wait-process.h"
+
+#define ARG(i) (argc > (i) ? TOKEN_DATA_TEXT (argv[i]) : "")
+
+/* Initialization of builtin and predefined macros. The table
+ "builtin_tab" is both used for initialization, and by the "builtin"
+ builtin. */
+
+#define DECLARE(name) \
+ static void name (struct obstack *, int, token_data **)
+
+DECLARE (m4___file__);
+DECLARE (m4___line__);
+DECLARE (m4___program__);
+DECLARE (m4_builtin);
+DECLARE (m4_changecom);
+DECLARE (m4_changequote);
+#ifdef ENABLE_CHANGEWORD
+DECLARE (m4_changeword);
+#endif
+DECLARE (m4_debugmode);
+DECLARE (m4_debugfile);
+DECLARE (m4_decr);
+DECLARE (m4_define);
+DECLARE (m4_defn);
+DECLARE (m4_divert);
+DECLARE (m4_divnum);
+DECLARE (m4_dnl);
+DECLARE (m4_dumpdef);
+DECLARE (m4_errprint);
+DECLARE (m4_esyscmd);
+DECLARE (m4_eval);
+DECLARE (m4_format);
+DECLARE (m4_ifdef);
+DECLARE (m4_ifelse);
+DECLARE (m4_include);
+DECLARE (m4_incr);
+DECLARE (m4_index);
+DECLARE (m4_indir);
+DECLARE (m4_len);
+DECLARE (m4_m4exit);
+DECLARE (m4_m4wrap);
+DECLARE (m4_maketemp);
+DECLARE (m4_mkstemp);
+DECLARE (m4_patsubst);
+DECLARE (m4_popdef);
+DECLARE (m4_pushdef);
+DECLARE (m4_regexp);
+DECLARE (m4_shift);
+DECLARE (m4_sinclude);
+DECLARE (m4_substr);
+DECLARE (m4_syscmd);
+DECLARE (m4_sysval);
+DECLARE (m4_traceoff);
+DECLARE (m4_traceon);
+DECLARE (m4_translit);
+DECLARE (m4_undefine);
+DECLARE (m4_undivert);
+
+#undef DECLARE
+
+static builtin const builtin_tab[] =
+{
+
+ /* name GNUext macros blind function */
+
+ { "__file__", true, false, false, m4___file__ },
+ { "__line__", true, false, false, m4___line__ },
+ { "__program__", true, false, false, m4___program__ },
+ { "builtin", true, true, true, m4_builtin },
+ { "changecom", false, false, false, m4_changecom },
+ { "changequote", false, false, false, m4_changequote },
+#ifdef ENABLE_CHANGEWORD
+ { "changeword", true, false, true, m4_changeword },
+#endif
+ { "debugmode", true, false, false, m4_debugmode },
+ { "debugfile", true, false, false, m4_debugfile },
+ { "decr", false, false, true, m4_decr },
+ { "define", false, true, true, m4_define },
+ { "defn", false, false, true, m4_defn },
+ { "divert", false, false, false, m4_divert },
+ { "divnum", false, false, false, m4_divnum },
+ { "dnl", false, false, false, m4_dnl },
+ { "dumpdef", false, false, false, m4_dumpdef },
+ { "errprint", false, false, true, m4_errprint },
+ { "esyscmd", true, false, true, m4_esyscmd },
+ { "eval", false, false, true, m4_eval },
+ { "format", true, false, true, m4_format },
+ { "ifdef", false, false, true, m4_ifdef },
+ { "ifelse", false, false, true, m4_ifelse },
+ { "include", false, false, true, m4_include },
+ { "incr", false, false, true, m4_incr },
+ { "index", false, false, true, m4_index },
+ { "indir", true, true, true, m4_indir },
+ { "len", false, false, true, m4_len },
+ { "m4exit", false, false, false, m4_m4exit },
+ { "m4wrap", false, false, true, m4_m4wrap },
+ { "maketemp", false, false, true, m4_maketemp },
+ { "mkstemp", false, false, true, m4_mkstemp },
+ { "patsubst", true, false, true, m4_patsubst },
+ { "popdef", false, false, true, m4_popdef },
+ { "pushdef", false, true, true, m4_pushdef },
+ { "regexp", true, false, true, m4_regexp },
+ { "shift", false, false, true, m4_shift },
+ { "sinclude", false, false, true, m4_sinclude },
+ { "substr", false, false, true, m4_substr },
+ { "syscmd", false, false, true, m4_syscmd },
+ { "sysval", false, false, false, m4_sysval },
+ { "traceoff", false, false, false, m4_traceoff },
+ { "traceon", false, false, false, m4_traceon },
+ { "translit", false, false, true, m4_translit },
+ { "undefine", false, false, true, m4_undefine },
+ { "undivert", false, false, false, m4_undivert },
+
+ { 0, false, false, false, 0 },
+
+ /* placeholder is intentionally stuck after the table end delimiter,
+ so that we can easily find it, while not treating it as a real
+ builtin. */
+ { "placeholder", true, false, false, m4_placeholder },
+};
+
+static predefined const predefined_tab[] =
+{
+#if UNIX
+ { "unix", "__unix__", "" },
+#endif
+#if W32_NATIVE
+ { "windows", "__windows__", "" },
+#endif
+#if OS2
+ { "os2", "__os2__", "" },
+#endif
+#if !UNIX && !W32_NATIVE && !OS2
+# warning Platform macro not provided
+#endif
+ { NULL, "__gnu__", "" },
+
+ { NULL, NULL, NULL },
+};
+
+/*----------------------------------------.
+| Find the builtin, which lives on ADDR. |
+`----------------------------------------*/
+
+const builtin * M4_GNUC_PURE
+find_builtin_by_addr (builtin_func *func)
+{
+ const builtin *bp;
+
+ for (bp = &builtin_tab[0]; bp->name != NULL; bp++)
+ if (bp->func == func)
+ return bp;
+ if (func == m4_placeholder)
+ return bp + 1;
+ return NULL;
+}
+
+/*----------------------------------------------------------.
+| Find the builtin, which has NAME. On failure, return the |
+| placeholder builtin. |
+`----------------------------------------------------------*/
+
+const builtin * M4_GNUC_PURE
+find_builtin_by_name (const char *name)
+{
+ const builtin *bp;
+
+ for (bp = &builtin_tab[0]; bp->name != NULL; bp++)
+ if (STREQ (bp->name, name))
+ return bp;
+ return bp + 1;
+}
+
+/*----------------------------------------------------------------.
+| Install a builtin macro with name NAME, bound to the C function |
+| given in BP. MODE is SYMBOL_INSERT or SYMBOL_PUSHDEF. |
+`----------------------------------------------------------------*/
+
+void
+define_builtin (const char *name, const builtin *bp, symbol_lookup mode)
+{
+ symbol *sym;
+
+ sym = lookup_symbol (name, mode);
+ SYMBOL_TYPE (sym) = TOKEN_FUNC;
+ SYMBOL_MACRO_ARGS (sym) = bp->groks_macro_args;
+ SYMBOL_BLIND_NO_ARGS (sym) = bp->blind_if_no_args;
+ SYMBOL_FUNC (sym) = bp->func;
+}
+
+/* Storage for the compiled regular expression of
+ --warn-macro-sequence. */
+static struct re_pattern_buffer macro_sequence_buf;
+
+/* Storage for the matches of --warn-macro-sequence. */
+static struct re_registers macro_sequence_regs;
+
+/* True if --warn-macro-sequence is in effect. */
+static bool macro_sequence_inuse;
+
+/*----------------------------------------.
+| Clean up regular expression variables. |
+`----------------------------------------*/
+
+static void
+free_pattern_buffer (struct re_pattern_buffer *buf, struct re_registers *regs)
+{
+ regfree (buf);
+ free (regs->start);
+ free (regs->end);
+}
+
+/*-----------------------------------------------------------------.
+| Set the regular expression of --warn-macro-sequence that will be |
+| checked during define and pushdef. Exit on failure. |
+`-----------------------------------------------------------------*/
+void
+set_macro_sequence (const char *regexp)
+{
+ const char *msg;
+
+ if (! regexp)
+ regexp = DEFAULT_MACRO_SEQUENCE;
+ else if (regexp[0] == '\0')
+ {
+ macro_sequence_inuse = false;
+ return;
+ }
+
+ msg = re_compile_pattern (regexp, strlen (regexp), &macro_sequence_buf);
+ if (msg != NULL)
+ {
+ M4ERROR ((EXIT_FAILURE, 0,
+ "--warn-macro-sequence: bad regular expression `%s': %s",
+ regexp, msg));
+ }
+ re_set_registers (&macro_sequence_buf, &macro_sequence_regs,
+ macro_sequence_regs.num_regs,
+ macro_sequence_regs.start, macro_sequence_regs.end);
+ macro_sequence_inuse = true;
+}
+
+/*-----------------------------------------------------------.
+| Free dynamic memory utilized by the macro sequence regular |
+| expression during the define builtin. |
+`-----------------------------------------------------------*/
+void
+free_macro_sequence (void)
+{
+ free_pattern_buffer (&macro_sequence_buf, &macro_sequence_regs);
+}
+
+/*-----------------------------------------------------------------.
+| Define a predefined or user-defined macro, with name NAME, and |
+| expansion TEXT. MODE destinguishes between the "define" and the |
+| "pushdef" case. It is also used from main. |
+`-----------------------------------------------------------------*/
+
+void
+define_user_macro (const char *name, const char *text, symbol_lookup mode)
+{
+ symbol *s;
+ char *defn = xstrdup (text ? text : "");
+
+ s = lookup_symbol (name, mode);
+ if (SYMBOL_TYPE (s) == TOKEN_TEXT)
+ free (SYMBOL_TEXT (s));
+
+ SYMBOL_TYPE (s) = TOKEN_TEXT;
+ SYMBOL_TEXT (s) = defn;
+
+ /* Implement --warn-macro-sequence. */
+ if (macro_sequence_inuse && text)
+ {
+ regoff_t offset = 0;
+ size_t len = strlen (defn);
+
+ while ((offset = re_search (&macro_sequence_buf, defn, len, offset,
+ len - offset, &macro_sequence_regs)) >= 0)
+ {
+ /* Skip empty matches. */
+ if (macro_sequence_regs.start[0] == macro_sequence_regs.end[0])
+ offset++;
+ else
+ {
+ char tmp;
+ offset = macro_sequence_regs.end[0];
+ tmp = defn[offset];
+ defn[offset] = '\0';
+ M4ERROR ((warning_status, 0,
+ "Warning: definition of `%s' contains sequence `%s'",
+ name, defn + macro_sequence_regs.start[0]));
+ defn[offset] = tmp;
+ }
+ }
+ if (offset == -2)
+ M4ERROR ((warning_status, 0,
+ "error checking --warn-macro-sequence for macro `%s'",
+ name));
+ }
+}
+
+/*-----------------------------------------------.
+| Initialize all builtin and predefined macros. |
+`-----------------------------------------------*/
+
+void
+builtin_init (void)
+{
+ const builtin *bp;
+ const predefined *pp;
+ char *string;
+
+ for (bp = &builtin_tab[0]; bp->name != NULL; bp++)
+ if (!no_gnu_extensions || !bp->gnu_extension)
+ {
+ if (prefix_all_builtins)
+ {
+ string = (char *) xmalloc (strlen (bp->name) + 4);
+ strcpy (string, "m4_");
+ strcat (string, bp->name);
+ define_builtin (string, bp, SYMBOL_INSERT);
+ free (string);
+ }
+ else
+ define_builtin (bp->name, bp, SYMBOL_INSERT);
+ }
+
+ for (pp = &predefined_tab[0]; pp->func != NULL; pp++)
+ if (no_gnu_extensions)
+ {
+ if (pp->unix_name != NULL)
+ define_user_macro (pp->unix_name, pp->func, SYMBOL_INSERT);
+ }
+ else
+ {
+ if (pp->gnu_name != NULL)
+ define_user_macro (pp->gnu_name, pp->func, SYMBOL_INSERT);
+ }
+}
+
+/*-------------------------------------------------------------------.
+| Give friendly warnings if a builtin macro is passed an |
+| inappropriate number of arguments. NAME is the macro name for |
+| messages, ARGC is actual number of arguments, MIN is the minimum |
+| number of acceptable arguments, negative if not applicable, MAX is |
+| the maximum number, negative if not applicable. |
+`-------------------------------------------------------------------*/
+
+static bool
+bad_argc (token_data *name, int argc, int min, int max)
+{
+ bool isbad = false;
+
+ if (min > 0 && argc < min)
+ {
+ if (!suppress_warnings)
+ M4ERROR ((warning_status, 0,
+ "Warning: too few arguments to builtin `%s'",
+ TOKEN_DATA_TEXT (name)));
+ isbad = true;
+ }
+ else if (max > 0 && argc > max && !suppress_warnings)
+ M4ERROR ((warning_status, 0,
+ "Warning: excess arguments to builtin `%s' ignored",
+ TOKEN_DATA_TEXT (name)));
+
+ return isbad;
+}
+
+/*-----------------------------------------------------------------.
+| The function numeric_arg () converts ARG to an int pointed to by |
+| VALUEP. If the conversion fails, print error message for macro |
+| MACRO. Return true iff conversion succeeds. |
+`-----------------------------------------------------------------*/
+
+static bool
+numeric_arg (token_data *macro, const char *arg, int *valuep)
+{
+ char *endp;
+
+ if (*arg == '\0')
+ {
+ *valuep = 0;
+ M4ERROR ((warning_status, 0,
+ "empty string treated as 0 in builtin `%s'",
+ TOKEN_DATA_TEXT (macro)));
+ }
+ else
+ {
+ errno = 0;
+ *valuep = strtol (arg, &endp, 10);
+ if (*endp != '\0')
+ {
+ M4ERROR ((warning_status, 0,
+ "non-numeric argument to builtin `%s'",
+ TOKEN_DATA_TEXT (macro)));
+ return false;
+ }
+ if (isspace (to_uchar (*arg)))
+ M4ERROR ((warning_status, 0,
+ "leading whitespace ignored in builtin `%s'",
+ TOKEN_DATA_TEXT (macro)));
+ else if (errno == ERANGE)
+ M4ERROR ((warning_status, 0,
+ "numeric overflow detected in builtin `%s'",
+ TOKEN_DATA_TEXT (macro)));
+ }
+ return true;
+}
+
+/*------------------------------------------------------.
+| The function ntoa () converts VALUE to a signed ASCII |
+| representation in radix RADIX. |
+`------------------------------------------------------*/
+
+/* Digits for number to ASCII conversions. */
+static char const digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+const char *
+ntoa (int32_t value, int radix)
+{
+ bool negative;
+ uint32_t uvalue;
+ static char str[256];
+ char *s = &str[sizeof str];
+
+ *--s = '\0';
+
+ if (value < 0)
+ {
+ negative = true;
+ uvalue = -(uint32_t) value;
+ }
+ else
+ {
+ negative = false;
+ uvalue = (uint32_t) value;
+ }
+
+ do
+ {
+ *--s = digits[uvalue % radix];
+ uvalue /= radix;
+ }
+ while (uvalue > 0);
+
+ if (negative)
+ *--s = '-';
+ return s;
+}
+
+/*---------------------------------------------------------------.
+| Format an int VAL, and stuff it into an obstack OBS. Used for |
+| macros expanding to numbers. |
+`---------------------------------------------------------------*/
+
+static void
+shipout_int (struct obstack *obs, int val)
+{
+ const char *s;
+
+ s = ntoa ((int32_t) val, 10);
+ obstack_grow (obs, s, strlen (s));
+}
+
+/*-------------------------------------------------------------------.
+| Print ARGC arguments from the table ARGV to obstack OBS, separated |
+| by SEP, and quoted by the current quotes if QUOTED is true. |
+`-------------------------------------------------------------------*/
+
+static void
+dump_args (struct obstack *obs, int argc, token_data **argv,
+ const char *sep, bool quoted)
+{
+ int i;
+ size_t len = strlen (sep);
+
+ for (i = 1; i < argc; i++)
+ {
+ if (i > 1)
+ obstack_grow (obs, sep, len);
+ if (quoted)
+ obstack_grow (obs, lquote.string, lquote.length);
+ obstack_grow (obs, TOKEN_DATA_TEXT (argv[i]),
+ strlen (TOKEN_DATA_TEXT (argv[i])));
+ if (quoted)
+ obstack_grow (obs, rquote.string, rquote.length);
+ }
+}
+
+/* The rest of this file is code for builtins and expansion of user
+ defined macros. All the functions for builtins have a prototype as:
+
+ void m4_MACRONAME (struct obstack *obs, int argc, char *argv[]);
+
+ The function are expected to leave their expansion on the obstack OBS,
+ as an unfinished object. ARGV is a table of ARGC pointers to the
+ individual arguments to the macro. Please note that in general
+ argv[argc] != NULL. */
+
+/* The first section are macros for definining, undefining, examining,
+ changing, ... other macros. */
+
+/*-------------------------------------------------------------------.
+| The function define_macro is common for the builtins "define", |
+| "undefine", "pushdef" and "popdef". ARGC and ARGV is as for the |
+| caller, and MODE argument determines how the macro name is entered |
+| into the symbol table. |
+`-------------------------------------------------------------------*/
+
+static void
+define_macro (int argc, token_data **argv, symbol_lookup mode)
+{
+ const builtin *bp;
+
+ if (bad_argc (argv[0], argc, 2, 3))
+ return;
+
+ if (TOKEN_DATA_TYPE (argv[1]) != TOKEN_TEXT)
+ {
+ M4ERROR ((warning_status, 0,
+ "Warning: %s: invalid macro name ignored", ARG (0)));
+ return;
+ }
+
+ if (argc == 2)
+ {
+ define_user_macro (ARG (1), "", mode);
+ return;
+ }
+
+ switch (TOKEN_DATA_TYPE (argv[2]))
+ {
+ case TOKEN_TEXT:
+ define_user_macro (ARG (1), ARG (2), mode);
+ break;
+
+ case TOKEN_FUNC:
+ bp = find_builtin_by_addr (TOKEN_DATA_FUNC (argv[2]));
+ if (bp == NULL)
+ return;
+ else
+ define_builtin (ARG (1), bp, mode);
+ break;
+
+ case TOKEN_VOID:
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad token data type in define_macro ()"));
+ abort ();
+ }
+}
+
+static void
+m4_define (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ define_macro (argc, argv, SYMBOL_INSERT);
+}
+
+static void
+m4_undefine (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ int i;
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ for (i = 1; i < argc; i++)
+ lookup_symbol (ARG (i), SYMBOL_DELETE);
+}
+
+static void
+m4_pushdef (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ define_macro (argc, argv, SYMBOL_PUSHDEF);
+}
+
+static void
+m4_popdef (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ int i;
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ for (i = 1; i < argc; i++)
+ lookup_symbol (ARG (i), SYMBOL_POPDEF);
+}
+
+/*---------------------.
+| Conditionals of m4. |
+`---------------------*/
+
+static void
+m4_ifdef (struct obstack *obs, int argc, token_data **argv)
+{
+ symbol *s;
+ const char *result;
+
+ if (bad_argc (argv[0], argc, 3, 4))
+ return;
+ s = lookup_symbol (ARG (1), SYMBOL_LOOKUP);
+
+ if (s != NULL && SYMBOL_TYPE (s) != TOKEN_VOID)
+ result = ARG (2);
+ else if (argc >= 4)
+ result = ARG (3);
+ else
+ result = NULL;
+
+ if (result != NULL)
+ obstack_grow (obs, result, strlen (result));
+}
+
+static void
+m4_ifelse (struct obstack *obs, int argc, token_data **argv)
+{
+ const char *result;
+ token_data *me = argv[0];
+
+ if (argc == 2)
+ return;
+
+ if (bad_argc (me, argc, 4, -1))
+ return;
+ else
+ /* Diagnose excess arguments if 5, 8, 11, etc., actual arguments. */
+ bad_argc (me, (argc + 2) % 3, -1, 1);
+
+ argv++;
+ argc--;
+
+ result = NULL;
+ while (result == NULL)
+
+ if (STREQ (ARG (0), ARG (1)))
+ result = ARG (2);
+
+ else
+ switch (argc)
+ {
+ case 3:
+ return;
+
+ case 4:
+ case 5:
+ result = ARG (3);
+ break;
+
+ default:
+ argc -= 3;
+ argv += 3;
+ }
+
+ obstack_grow (obs, result, strlen (result));
+}
+
+/*-------------------------------------------------------------------.
+| The function dump_symbol () is for use by "dumpdef". It builds up |
+| a table of all defined, un-shadowed, symbols. |
+`-------------------------------------------------------------------*/
+
+/* The structure dump_symbol_data is used to pass the information needed
+ from call to call to dump_symbol. */
+
+struct dump_symbol_data
+{
+ struct obstack *obs; /* obstack for table */
+ symbol **base; /* base of table */
+ int size; /* size of table */
+};
+
+static void
+dump_symbol (symbol *sym, void *arg)
+{
+ struct dump_symbol_data *data = (struct dump_symbol_data *) arg;
+ if (!SYMBOL_SHADOWED (sym) && SYMBOL_TYPE (sym) != TOKEN_VOID)
+ {
+ obstack_blank (data->obs, sizeof (symbol *));
+ data->base = (symbol **) obstack_base (data->obs);
+ data->base[data->size++] = sym;
+ }
+}
+
+/*------------------------------------------------------------------------.
+| qsort comparison routine, for sorting the table made in m4_dumpdef (). |
+`------------------------------------------------------------------------*/
+
+static int
+dumpdef_cmp (const void *s1, const void *s2)
+{
+ return strcmp (SYMBOL_NAME (* (symbol *const *) s1),
+ SYMBOL_NAME (* (symbol *const *) s2));
+}
+
+/*-------------------------------------------------------------.
+| Implementation of "dumpdef" itself. It builds up a table of |
+| pointers to symbols, sorts it and prints the sorted table. |
+`-------------------------------------------------------------*/
+
+static void
+m4_dumpdef (struct obstack *obs, int argc, token_data **argv)
+{
+ symbol *s;
+ int i;
+ struct dump_symbol_data data;
+ const builtin *bp;
+
+ data.obs = obs;
+ data.base = (symbol **) obstack_base (obs);
+ data.size = 0;
+
+ if (argc == 1)
+ {
+ hack_all_symbols (dump_symbol, &data);
+ }
+ else
+ {
+ for (i = 1; i < argc; i++)
+ {
+ s = lookup_symbol (TOKEN_DATA_TEXT (argv[i]), SYMBOL_LOOKUP);
+ if (s != NULL && SYMBOL_TYPE (s) != TOKEN_VOID)
+ dump_symbol (s, &data);
+ else
+ M4ERROR ((warning_status, 0,
+ "undefined macro `%s'", TOKEN_DATA_TEXT (argv[i])));
+ }
+ }
+
+ /* Make table of symbols invisible to expand_macro (). */
+
+ obstack_finish (obs);
+
+ qsort (data.base, data.size, sizeof (symbol *), dumpdef_cmp);
+
+ for (; data.size > 0; --data.size, data.base++)
+ {
+ DEBUG_PRINT1 ("%s:\t", SYMBOL_NAME (data.base[0]));
+
+ switch (SYMBOL_TYPE (data.base[0]))
+ {
+ case TOKEN_TEXT:
+ if (debug_level & DEBUG_TRACE_QUOTE)
+ DEBUG_PRINT3 ("%s%s%s\n",
+ lquote.string, SYMBOL_TEXT (data.base[0]), rquote.string);
+ else
+ DEBUG_PRINT1 ("%s\n", SYMBOL_TEXT (data.base[0]));
+ break;
+
+ case TOKEN_FUNC:
+ bp = find_builtin_by_addr (SYMBOL_FUNC (data.base[0]));
+ if (bp == NULL)
+ {
+ M4ERROR ((warning_status, 0, "\
+INTERNAL ERROR: builtin not found in builtin table"));
+ abort ();
+ }
+ DEBUG_PRINT1 ("<%s>\n", bp->name);
+ break;
+
+ case TOKEN_VOID:
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad token data type in m4_dumpdef ()"));
+ abort ();
+ break;
+ }
+ }
+}
+
+/*-----------------------------------------------------------------.
+| The builtin "builtin" allows calls to builtin macros, even if |
+| their definition has been overridden or shadowed. It is thus |
+| possible to redefine builtins, and still access their original |
+| definition. This macro is not available in compatibility mode. |
+`-----------------------------------------------------------------*/
+
+static void
+m4_builtin (struct obstack *obs, int argc, token_data **argv)
+{
+ const builtin *bp;
+ const char *name;
+
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ if (TOKEN_DATA_TYPE (argv[1]) != TOKEN_TEXT)
+ {
+ M4ERROR ((warning_status, 0,
+ "Warning: %s: invalid macro name ignored", ARG (0)));
+ return;
+ }
+
+ name = ARG (1);
+ bp = find_builtin_by_name (name);
+ if (bp->func == m4_placeholder)
+ M4ERROR ((warning_status, 0,
+ "undefined builtin `%s'", name));
+ else
+ {
+ int i;
+ if (! bp->groks_macro_args)
+ for (i = 2; i < argc; i++)
+ if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT)
+ {
+ TOKEN_DATA_TYPE (argv[i]) = TOKEN_TEXT;
+ TOKEN_DATA_TEXT (argv[i]) = (char *) "";
+ }
+ bp->func (obs, argc - 1, argv + 1);
+ }
+}
+
+/*-------------------------------------------------------------------.
+| The builtin "indir" allows indirect calls to macros, even if their |
+| name is not a proper macro name. It is thus possible to define |
+| macros with ill-formed names for internal use in larger macro |
+| packages. This macro is not available in compatibility mode. |
+`-------------------------------------------------------------------*/
+
+static void
+m4_indir (struct obstack *obs, int argc, token_data **argv)
+{
+ symbol *s;
+ const char *name;
+
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ if (TOKEN_DATA_TYPE (argv[1]) != TOKEN_TEXT)
+ {
+ M4ERROR ((warning_status, 0,
+ "Warning: %s: invalid macro name ignored", ARG (0)));
+ return;
+ }
+
+ name = ARG (1);
+ s = lookup_symbol (name, SYMBOL_LOOKUP);
+ if (s == NULL || SYMBOL_TYPE (s) == TOKEN_VOID)
+ M4ERROR ((warning_status, 0,
+ "undefined macro `%s'", name));
+ else
+ {
+ int i;
+ if (! SYMBOL_MACRO_ARGS (s))
+ for (i = 2; i < argc; i++)
+ if (TOKEN_DATA_TYPE (argv[i]) != TOKEN_TEXT)
+ {
+ TOKEN_DATA_TYPE (argv[i]) = TOKEN_TEXT;
+ TOKEN_DATA_TEXT (argv[i]) = (char *) "";
+ }
+ call_macro (s, argc - 1, argv + 1, obs);
+ }
+}
+
+/*------------------------------------------------------------------.
+| The macro "defn" returns the quoted definition of the macro named |
+| by the first argument. If the macro is builtin, it will push a |
+| special macro-definition token on the input stack. |
+`------------------------------------------------------------------*/
+
+static void
+m4_defn (struct obstack *obs, int argc, token_data **argv)
+{
+ symbol *s;
+ builtin_func *b;
+ unsigned int i;
+
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+
+ assert (0 < argc);
+ for (i = 1; i < (unsigned) argc; i++)
+ {
+ const char *arg = ARG((int) i);
+ s = lookup_symbol (arg, SYMBOL_LOOKUP);
+ if (s == NULL)
+ continue;
+
+ switch (SYMBOL_TYPE (s))
+ {
+ case TOKEN_TEXT:
+ obstack_grow (obs, lquote.string, lquote.length);
+ obstack_grow (obs, SYMBOL_TEXT (s), strlen (SYMBOL_TEXT (s)));
+ obstack_grow (obs, rquote.string, rquote.length);
+ break;
+
+ case TOKEN_FUNC:
+ b = SYMBOL_FUNC (s);
+ if (b == m4_placeholder)
+ M4ERROR ((warning_status, 0, "\
+builtin `%s' requested by frozen file is not supported", arg));
+ else if (argc != 2)
+ M4ERROR ((warning_status, 0,
+ "Warning: cannot concatenate builtin `%s'",
+ arg));
+ else
+ push_macro (b);
+ break;
+
+ case TOKEN_VOID:
+ /* Nothing to do for traced but undefined macro. */
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad symbol type in m4_defn ()"));
+ abort ();
+ }
+ }
+}
+
+/*--------------------------------------------------------------.
+| This section contains macros to handle the builtins "syscmd", |
+| "esyscmd" and "sysval". "esyscmd" is GNU specific. |
+`--------------------------------------------------------------*/
+
+/* Exit code from last "syscmd" command. */
+static int sysval;
+
+static void
+m4_syscmd (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ const char *cmd = ARG (1);
+ int status;
+ int sig_status;
+ const char *prog_args[4] = { "sh", "-c" };
+ if (bad_argc (argv[0], argc, 2, 2) || !*cmd)
+ {
+ /* The empty command is successful. */
+ sysval = 0;
+ return;
+ }
+
+ debug_flush_files ();
+#if W32_NATIVE
+ if (strstr (SYSCMD_SHELL, "cmd"))
+ {
+ prog_args[0] = "cmd";
+ prog_args[1] = "/c";
+ }
+#endif
+ prog_args[2] = cmd;
+ errno = 0;
+ status = execute (ARG (0), SYSCMD_SHELL, (char **) prog_args, false,
+ false, false, false, true, false, &sig_status);
+ if (sig_status)
+ {
+ assert (status == 127);
+ sysval = sig_status << 8;
+ }
+ else
+ {
+ if (status == 127 && errno)
+ M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
+ sysval = status;
+ }
+}
+
+static void
+m4_esyscmd (struct obstack *obs, int argc, token_data **argv)
+{
+ const char *cmd = ARG (1);
+ const char *prog_args[4] = { "sh", "-c" };
+ pid_t child;
+ int fd;
+ FILE *pin;
+ int status;
+ int sig_status;
+
+ if (bad_argc (argv[0], argc, 2, 2) || !*cmd)
+ {
+ /* The empty command is successful. */
+ sysval = 0;
+ return;
+ }
+
+ debug_flush_files ();
+#if W32_NATIVE
+ if (strstr (SYSCMD_SHELL, "cmd"))
+ {
+ prog_args[0] = "cmd";
+ prog_args[1] = "/c";
+ }
+#endif
+ prog_args[2] = cmd;
+ errno = 0;
+ child = create_pipe_in (ARG (0), SYSCMD_SHELL, (char **) prog_args,
+ NULL, false, true, false, &fd);
+ if (child == -1)
+ {
+ M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
+ sysval = 127;
+ return;
+ }
+ pin = fdopen (fd, "r");
+ if (pin == NULL)
+ {
+ M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
+ sysval = 127;
+ close (fd);
+ return;
+ }
+ while (1)
+ {
+ size_t avail = obstack_room (obs);
+ size_t len;
+ if (!avail)
+ {
+ int ch = getc (pin);
+ if (ch == EOF)
+ break;
+ obstack_1grow (obs, ch);
+ continue;
+ }
+ len = fread (obstack_next_free (obs), 1, avail, pin);
+ if (len <= 0)
+ break;
+ obstack_blank_fast (obs, len);
+ }
+ if (ferror (pin) || fclose (pin))
+ M4ERROR ((EXIT_FAILURE, errno, "cannot read pipe"));
+ errno = 0;
+ status = wait_subprocess (child, ARG (0), false, true, true, false,
+ &sig_status);
+ if (sig_status)
+ {
+ assert (status == 127);
+ sysval = sig_status << 8;
+ }
+ else
+ {
+ if (status == 127 && errno)
+ M4ERROR ((warning_status, errno, "cannot run command `%s'", cmd));
+ sysval = status;
+ }
+}
+
+static void
+m4_sysval (struct obstack *obs, int argc M4_GNUC_UNUSED,
+ token_data **argv M4_GNUC_UNUSED)
+{
+ shipout_int (obs, sysval);
+}
+
+/*------------------------------------------------------------------.
+| This section contains the top level code for the "eval" builtin. |
+| The actual work is done in the function evaluate (), which lives |
+| in eval.c. |
+`------------------------------------------------------------------*/
+
+static void
+m4_eval (struct obstack *obs, int argc, token_data **argv)
+{
+ int32_t value = 0;
+ int radix = 10;
+ int min = 1;
+ const char *s;
+
+ if (bad_argc (argv[0], argc, 2, 4))
+ return;
+
+ if (*ARG (2) && !numeric_arg (argv[0], ARG (2), &radix))
+ return;
+
+ if (radix < 1 || radix > (int) strlen (digits))
+ {
+ M4ERROR ((warning_status, 0,
+ "radix %d in builtin `%s' out of range",
+ radix, ARG (0)));
+ return;
+ }
+
+ if (argc >= 4 && !numeric_arg (argv[0], ARG (3), &min))
+ return;
+ if (min < 0)
+ {
+ M4ERROR ((warning_status, 0,
+ "negative width to builtin `%s'", ARG (0)));
+ return;
+ }
+
+ if (!*ARG (1))
+ M4ERROR ((warning_status, 0,
+ "empty string treated as 0 in builtin `%s'", ARG (0)));
+ else if (evaluate (ARG (1), &value))
+ return;
+
+ if (radix == 1)
+ {
+ if (value < 0)
+ {
+ obstack_1grow (obs, '-');
+ value = -value;
+ }
+ /* This assumes 2's-complement for correctly handling INT_MIN. */
+ while (min-- - value > 0)
+ obstack_1grow (obs, '0');
+ while (value-- != 0)
+ obstack_1grow (obs, '1');
+ obstack_1grow (obs, '\0');
+ return;
+ }
+
+ s = ntoa (value, radix);
+
+ if (*s == '-')
+ {
+ obstack_1grow (obs, '-');
+ s++;
+ }
+ for (min -= strlen (s); --min >= 0;)
+ obstack_1grow (obs, '0');
+
+ obstack_grow (obs, s, strlen (s));
+}
+
+static void
+m4_incr (struct obstack *obs, int argc, token_data **argv)
+{
+ int value;
+
+ if (bad_argc (argv[0], argc, 2, 2))
+ return;
+
+ if (!numeric_arg (argv[0], ARG (1), &value))
+ return;
+
+ shipout_int (obs, value + 1);
+}
+
+static void
+m4_decr (struct obstack *obs, int argc, token_data **argv)
+{
+ int value;
+
+ if (bad_argc (argv[0], argc, 2, 2))
+ return;
+
+ if (!numeric_arg (argv[0], ARG (1), &value))
+ return;
+
+ shipout_int (obs, value - 1);
+}
+
+/* This section contains the macros "divert", "undivert" and "divnum" for
+ handling diversion. The utility functions used lives in output.c. */
+
+/*-----------------------------------------------------------------.
+| Divert further output to the diversion given by ARGV[1]. Out of |
+| range means discard further output. |
+`-----------------------------------------------------------------*/
+
+static void
+m4_divert (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ int i = 0;
+
+ if (bad_argc (argv[0], argc, 1, 2))
+ return;
+
+ if (argc >= 2 && !numeric_arg (argv[0], ARG (1), &i))
+ return;
+
+ make_diversion (i);
+}
+
+/*-----------------------------------------------------.
+| Expand to the current diversion number, -1 if none. |
+`-----------------------------------------------------*/
+
+static void
+m4_divnum (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 1))
+ return;
+ shipout_int (obs, current_diversion);
+}
+
+/*------------------------------------------------------------------.
+| Bring back the diversion given by the argument list. If none is |
+| specified, bring back all diversions. GNU specific is the option |
+| of undiverting named files, by passing a non-numeric argument to |
+| undivert (). |
+`------------------------------------------------------------------*/
+
+static void
+m4_undivert (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ int i, file;
+ FILE *fp;
+ char *endp;
+
+ if (argc == 1)
+ undivert_all ();
+ else
+ for (i = 1; i < argc; i++)
+ {
+ file = strtol (ARG (i), &endp, 10);
+ if (*endp == '\0' && !isspace (to_uchar (*ARG (i))))
+ insert_diversion (file);
+ else if (no_gnu_extensions)
+ M4ERROR ((warning_status, 0,
+ "non-numeric argument to builtin `%s'", ARG (0)));
+ else
+ {
+ fp = m4_path_search (ARG (i), NULL);
+ if (fp != NULL)
+ {
+ insert_file (fp);
+ if (fclose (fp) == EOF)
+ M4ERROR ((warning_status, errno,
+ "error undiverting `%s'", ARG (i)));
+ }
+ else
+ M4ERROR ((warning_status, errno,
+ "cannot undivert `%s'", ARG (i)));
+ }
+ }
+}
+
+/* This section contains various macros, which does not fall into any
+ specific group. These are "dnl", "shift", "changequote", "changecom"
+ and "changeword". */
+
+/*-----------------------------------------------------------.
+| Delete all subsequent whitespace from input. The function |
+| skip_line () lives in input.c. |
+`-----------------------------------------------------------*/
+
+static void
+m4_dnl (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 1))
+ return;
+
+ skip_line ();
+}
+
+/*--------------------------------------------------------------------.
+| Shift all arguments one to the left, discarding the first |
+| argument. Each output argument is quoted with the current quotes. |
+`--------------------------------------------------------------------*/
+
+static void
+m4_shift (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ dump_args (obs, argc - 1, argv + 1, ",", true);
+}
+
+/*--------------------------------------------------------------------------.
+| Change the current quotes. The function set_quotes () lives in input.c. |
+`--------------------------------------------------------------------------*/
+
+static void
+m4_changequote (struct obstack *obs M4_GNUC_UNUSED, int argc,
+ token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 3))
+ return;
+
+ /* Explicit NULL distinguishes between empty and missing argument. */
+ set_quotes ((argc >= 2) ? TOKEN_DATA_TEXT (argv[1]) : NULL,
+ (argc >= 3) ? TOKEN_DATA_TEXT (argv[2]) : NULL);
+}
+
+/*-----------------------------------------------------------------.
+| Change the current comment delimiters. The function set_comment |
+| () lives in input.c. |
+`-----------------------------------------------------------------*/
+
+static void
+m4_changecom (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 3))
+ return;
+
+ /* Explicit NULL distinguishes between empty and missing argument. */
+ set_comment ((argc >= 2) ? TOKEN_DATA_TEXT (argv[1]) : NULL,
+ (argc >= 3) ? TOKEN_DATA_TEXT (argv[2]) : NULL);
+}
+
+#ifdef ENABLE_CHANGEWORD
+
+/*---------------------------------------------------------------.
+| Change the regular expression used for breaking the input into |
+| words. The function set_word_regexp () lives in input.c. |
+`---------------------------------------------------------------*/
+
+static void
+m4_changeword (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, 2))
+ return;
+
+ set_word_regexp (TOKEN_DATA_TEXT (argv[1]));
+}
+
+#endif /* ENABLE_CHANGEWORD */
+
+/* This section contains macros for inclusion of other files -- "include"
+ and "sinclude". This differs from bringing back diversions, in that
+ the input is scanned before being copied to the output. */
+
+/*---------------------------------------------------------------.
+| Generic include function. Include the file given by the first |
+| argument, if it exists. Complain about inaccessible files iff |
+| SILENT is false. |
+`---------------------------------------------------------------*/
+
+static void
+include (int argc, token_data **argv, bool silent)
+{
+ FILE *fp;
+ char *name;
+
+ if (bad_argc (argv[0], argc, 2, 2))
+ return;
+
+ fp = m4_path_search (ARG (1), &name);
+ if (fp == NULL)
+ {
+ if (!silent)
+ {
+ M4ERROR ((warning_status, errno, "cannot open `%s'", ARG (1)));
+ retcode = EXIT_FAILURE;
+ }
+ return;
+ }
+
+ push_file (fp, name, true);
+ free (name);
+}
+
+/*------------------------------------------------.
+| Include a file, complaining in case of errors. |
+`------------------------------------------------*/
+
+static void
+m4_include (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ include (argc, argv, false);
+}
+
+/*----------------------------------.
+| Include a file, ignoring errors. |
+`----------------------------------*/
+
+static void
+m4_sinclude (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ include (argc, argv, true);
+}
+
+/* More miscellaneous builtins -- "maketemp", "errprint", "__file__",
+ "__line__", and "__program__". The last three are GNU specific. */
+
+/*------------------------------------------------------------------.
+| Use the first argument as at template for a temporary file name. |
+`------------------------------------------------------------------*/
+
+/* Add trailing 'X' to PATTERN of length LEN as necessary, then
+ securely create the file, and place the quoted new file name on
+ OBS. Report errors on behalf of ME. */
+static void
+mkstemp_helper (struct obstack *obs, const char *me, const char *pattern,
+ size_t len)
+{
+ int fd;
+ size_t i;
+ char *name;
+
+ /* Guarantee that there are six trailing 'X' characters, even if the
+ user forgot to supply them. Output must be quoted if
+ successful. */
+ obstack_grow (obs, lquote.string, lquote.length);
+ obstack_grow (obs, pattern, len);
+ for (i = 0; len > 0 && i < 6; i++)
+ if (pattern[len - i - 1] != 'X')
+ break;
+ obstack_grow0 (obs, "XXXXXX", 6 - i);
+ name = (char *) obstack_base (obs) + lquote.length;
+
+ errno = 0;
+ fd = mkstemp (name);
+ if (fd < 0)
+ {
+ M4ERROR ((0, errno, "%s: cannot create tempfile `%s'", me, pattern));
+ obstack_free (obs, obstack_finish (obs));
+ }
+ else
+ {
+ close (fd);
+ /* Remove NUL, then finish quote. */
+ obstack_blank (obs, -1);
+ obstack_grow (obs, rquote.string, rquote.length);
+ }
+}
+
+static void
+m4_maketemp (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, 2))
+ return;
+ if (no_gnu_extensions)
+ {
+ /* POSIX states "any trailing 'X' characters [are] replaced with
+ the current process ID as a string", without referencing the
+ file system. Horribly insecure, but we have to do it when we
+ are in traditional mode.
+
+ For reference, Solaris m4 does:
+ maketemp() -> `'
+ maketemp(X) -> `X'
+ maketemp(XX) -> `Xn', where n is last digit of pid
+ maketemp(XXXXXXXX) -> `X00nnnnn', where nnnnn is 16-bit pid
+ */
+ const char *str = ARG (1);
+ int len = strlen (str);
+ int i;
+ int len2;
+
+ M4ERROR ((warning_status, 0, "recommend using mkstemp instead"));
+ for (i = len; i > 1; i--)
+ if (str[i - 1] != 'X')
+ break;
+ obstack_grow (obs, str, i);
+ str = ntoa ((int32_t) getpid (), 10);
+ len2 = strlen (str);
+ if (len2 > len - i)
+ obstack_grow0 (obs, str + len2 - (len - i), len - i);
+ else
+ {
+ while (i++ < len - len2)
+ obstack_1grow (obs, '0');
+ obstack_grow0 (obs, str, len2);
+ }
+ }
+ else
+ mkstemp_helper (obs, ARG (0), ARG (1), strlen (ARG (1)));
+}
+
+static void
+m4_mkstemp (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, 2))
+ return;
+ mkstemp_helper (obs, ARG (0), ARG (1), strlen (ARG (1)));
+}
+
+/*----------------------------------------.
+| Print all arguments on standard error. |
+`----------------------------------------*/
+
+static void
+m4_errprint (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ dump_args (obs, argc, argv, " ", false);
+ obstack_1grow (obs, '\0');
+ debug_flush_files ();
+ xfprintf (stderr, "%s", (char *) obstack_finish (obs));
+ fflush (stderr);
+}
+
+static void
+m4___file__ (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 1))
+ return;
+ obstack_grow (obs, lquote.string, lquote.length);
+ obstack_grow (obs, current_file, strlen (current_file));
+ obstack_grow (obs, rquote.string, rquote.length);
+}
+
+static void
+m4___line__ (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 1))
+ return;
+ shipout_int (obs, current_line);
+}
+
+static void
+m4___program__ (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 1))
+ return;
+ obstack_grow (obs, lquote.string, lquote.length);
+ obstack_grow (obs, program_name, strlen (program_name));
+ obstack_grow (obs, rquote.string, rquote.length);
+}
+
+/* This section contains various macros for exiting, saving input until
+ EOF is seen, and tracing macro calls. That is: "m4exit", "m4wrap",
+ "traceon" and "traceoff". */
+
+/*----------------------------------------------------------.
+| Exit immediately, with exit status specified by the first |
+| argument, or 0 if no arguments are present. |
+`----------------------------------------------------------*/
+
+static void M4_GNUC_NORETURN
+m4_m4exit (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ int exit_code = EXIT_SUCCESS;
+
+ /* Warn on bad arguments, but still exit. */
+ bad_argc (argv[0], argc, 1, 2);
+ if (argc >= 2 && !numeric_arg (argv[0], ARG (1), &exit_code))
+ exit_code = EXIT_FAILURE;
+ if (exit_code < 0 || exit_code > 255)
+ {
+ M4ERROR ((warning_status, 0,
+ "exit status out of range: `%d'", exit_code));
+ exit_code = EXIT_FAILURE;
+ }
+ /* Change debug stream back to stderr, to force flushing debug stream and
+ detect any errors it might have encountered. */
+ debug_set_output (NULL);
+ debug_flush_files ();
+ if (exit_code == EXIT_SUCCESS && retcode != EXIT_SUCCESS)
+ exit_code = retcode;
+ /* Propagate non-zero status to atexit handlers. */
+ if (exit_code != EXIT_SUCCESS)
+ exit_failure = exit_code;
+ exit (exit_code);
+}
+
+/*------------------------------------------------------------------.
+| Save the argument text until EOF has been seen, allowing for user |
+| specified cleanup action. GNU version saves all arguments, the |
+| standard version only the first. |
+`------------------------------------------------------------------*/
+
+static void
+m4_m4wrap (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ if (no_gnu_extensions)
+ obstack_grow (obs, ARG (1), strlen (ARG (1)));
+ else
+ dump_args (obs, argc, argv, " ", false);
+ obstack_1grow (obs, '\0');
+ push_wrapup ((char *) obstack_finish (obs));
+}
+
+/* Enable tracing of all specified macros, or all, if none is specified.
+ Tracing is disabled by default, when a macro is defined. This can be
+ overridden by the "t" debug flag. */
+
+/*------------------------------------------------------------------.
+| Set_trace () is used by "traceon" and "traceoff" to enable and |
+| disable tracing of a macro. It disables tracing if DATA is NULL, |
+| otherwise it enables tracing. |
+`------------------------------------------------------------------*/
+
+static void
+set_trace (symbol *sym, void *data)
+{
+ SYMBOL_TRACED (sym) = data != NULL;
+ /* Remove placeholder from table if macro is undefined and untraced. */
+ if (SYMBOL_TYPE (sym) == TOKEN_VOID && data == NULL)
+ lookup_symbol (SYMBOL_NAME (sym), SYMBOL_POPDEF);
+}
+
+static void
+m4_traceon (struct obstack *obs, int argc, token_data **argv)
+{
+ symbol *s;
+ int i;
+
+ if (argc == 1)
+ hack_all_symbols (set_trace, obs);
+ else
+ for (i = 1; i < argc; i++)
+ {
+ s = lookup_symbol (ARG (i), SYMBOL_LOOKUP);
+ if (!s)
+ s = lookup_symbol (ARG (i), SYMBOL_INSERT);
+ set_trace (s, obs);
+ }
+}
+
+/*------------------------------------------------------------------------.
+| Disable tracing of all specified macros, or all, if none is specified. |
+`------------------------------------------------------------------------*/
+
+static void
+m4_traceoff (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ symbol *s;
+ int i;
+
+ if (argc == 1)
+ hack_all_symbols (set_trace, NULL);
+ else
+ for (i = 1; i < argc; i++)
+ {
+ s = lookup_symbol (TOKEN_DATA_TEXT (argv[i]), SYMBOL_LOOKUP);
+ if (s != NULL)
+ set_trace (s, NULL);
+ }
+}
+
+/*------------------------------------------------------------------.
+| On-the-fly control of the format of the tracing output. It takes |
+| one argument, which is a character string like given to the -d |
+| option, or none in which case the debug_level is zeroed. |
+`------------------------------------------------------------------*/
+
+static void
+m4_debugmode (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ int new_debug_level;
+ int change_flag;
+
+ if (bad_argc (argv[0], argc, 1, 2))
+ return;
+
+ if (argc == 1)
+ debug_level = 0;
+ else
+ {
+ if (ARG (1)[0] == '+' || ARG (1)[0] == '-')
+ {
+ change_flag = ARG (1)[0];
+ new_debug_level = debug_decode (ARG (1) + 1);
+ }
+ else
+ {
+ change_flag = 0;
+ new_debug_level = debug_decode (ARG (1));
+ }
+
+ if (new_debug_level < 0)
+ M4ERROR ((warning_status, 0,
+ "Debugmode: bad debug flags: `%s'", ARG (1)));
+ else
+ {
+ switch (change_flag)
+ {
+ case 0:
+ debug_level = new_debug_level;
+ break;
+
+ case '+':
+ debug_level |= new_debug_level;
+ break;
+
+ case '-':
+ debug_level &= ~new_debug_level;
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad flag in m4_debugmode ()"));
+ abort ();
+ }
+ }
+ }
+}
+
+/*-------------------------------------------------------------------------.
+| Specify the destination of the debugging output. With one argument, the |
+| argument is taken as a file name, with no arguments, revert to stderr. |
+`-------------------------------------------------------------------------*/
+
+static void
+m4_debugfile (struct obstack *obs M4_GNUC_UNUSED, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 1, 2))
+ return;
+
+ if (argc == 1)
+ debug_set_output (NULL);
+ else if (!debug_set_output (ARG (1)))
+ M4ERROR ((warning_status, errno,
+ "cannot set debug file `%s'", ARG (1)));
+}
+
+/* This section contains text processing macros: "len", "index",
+ "substr", "translit", "format", "regexp" and "patsubst". The last
+ three are GNU specific. */
+
+/*---------------------------------------------.
+| Expand to the length of the first argument. |
+`---------------------------------------------*/
+
+static void
+m4_len (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, 2))
+ return;
+ shipout_int (obs, strlen (ARG (1)));
+}
+
+/*-------------------------------------------------------------------.
+| The macro expands to the first index of the second argument in the |
+| first argument. |
+`-------------------------------------------------------------------*/
+
+static void
+m4_index (struct obstack *obs, int argc, token_data **argv)
+{
+ const char *haystack;
+ const char *result;
+ int retval;
+
+ if (bad_argc (argv[0], argc, 3, 3))
+ {
+ /* builtin(`index') is blank, but index(`abc') is 0. */
+ if (argc == 2)
+ shipout_int (obs, 0);
+ return;
+ }
+
+ haystack = ARG (1);
+ result = strstr (haystack, ARG (2));
+ retval = result ? result - haystack : -1;
+
+ shipout_int (obs, retval);
+}
+
+/*-----------------------------------------------------------------.
+| The macro "substr" extracts substrings from the first argument, |
+| starting from the index given by the second argument, extending |
+| for a length given by the third argument. If the third argument |
+| is missing, the substring extends to the end of the first |
+| argument. |
+`-----------------------------------------------------------------*/
+
+static void
+m4_substr (struct obstack *obs, int argc, token_data **argv)
+{
+ int start = 0;
+ int length, avail;
+
+ if (bad_argc (argv[0], argc, 3, 4))
+ {
+ /* builtin(`substr') is blank, but substr(`abc') is abc. */
+ if (argc == 2)
+ obstack_grow (obs, ARG (1), strlen (ARG (1)));
+ return;
+ }
+
+ length = avail = strlen (ARG (1));
+ if (!numeric_arg (argv[0], ARG (2), &start))
+ return;
+
+ if (argc >= 4 && !numeric_arg (argv[0], ARG (3), &length))
+ return;
+
+ if (start < 0 || length <= 0 || start >= avail)
+ return;
+
+ if (start + length > avail)
+ length = avail - start;
+ obstack_grow (obs, ARG (1) + start, length);
+}
+
+/*------------------------------------------------------------------.
+| For "translit", ranges are allowed in the second and third |
+| argument. They are expanded in the following function, and the |
+| expanded strings, without any ranges left, are used to translate |
+| the characters of the first argument. A single - (dash) can be |
+| included in the strings by being the first or the last character |
+| in the string. If the first character in a range is after the |
+| first in the character set, the range is made backwards, thus 9-0 |
+| is the string 9876543210. |
+`------------------------------------------------------------------*/
+
+static const char *
+expand_ranges (const char *s, struct obstack *obs)
+{
+ unsigned char from;
+ unsigned char to;
+
+ for (from = '\0'; *s != '\0'; from = to_uchar (*s++))
+ {
+ if (*s == '-' && from != '\0')
+ {
+ to = to_uchar (*++s);
+ if (to == '\0')
+ {
+ /* trailing dash */
+ obstack_1grow (obs, '-');
+ break;
+ }
+ else if (from <= to)
+ {
+ while (from++ < to)
+ obstack_1grow (obs, from);
+ }
+ else
+ {
+ while (--from >= to)
+ obstack_1grow (obs, from);
+ }
+ }
+ else
+ obstack_1grow (obs, *s);
+ }
+ obstack_1grow (obs, '\0');
+ return (char *) obstack_finish (obs);
+}
+
+/*-----------------------------------------------------------------.
+| The macro "translit" translates all characters in the first |
+| argument, which are present in the second argument, into the |
+| corresponding character from the third argument. If the third |
+| argument is shorter than the second, the extra characters in the |
+| second argument are deleted from the first. |
+`-----------------------------------------------------------------*/
+
+static void
+m4_translit (struct obstack *obs, int argc, token_data **argv)
+{
+ const char *data = ARG (1);
+ const char *from = ARG (2);
+ const char *to;
+ char map[UCHAR_MAX + 1];
+ char found[UCHAR_MAX + 1];
+ unsigned char ch;
+
+ if (bad_argc (argv[0], argc, 3, 4) || !*data || !*from)
+ {
+ /* builtin(`translit') is blank, but translit(`abc') is abc. */
+ if (2 <= argc)
+ obstack_grow (obs, data, strlen (data));
+ return;
+ }
+
+ to = ARG (3);
+ if (strchr (to, '-') != NULL)
+ {
+ to = expand_ranges (to, obs);
+ assert (to && *to);
+ }
+
+ /* If there are only one or two bytes to replace, it is faster to
+ use memchr2. Using expand_ranges does nothing unless there are
+ at least three bytes. */
+ if (!from[1] || !from[2])
+ {
+ const char *p;
+ size_t len = strlen (data);
+ while ((p = (char *) memchr2 (data, from[0], from[1], len)))
+ {
+ obstack_grow (obs, data, p - data);
+ len -= p - data;
+ if (!len)
+ return;
+ data = p + 1;
+ len--;
+ if (*p == from[0] && to[0])
+ obstack_1grow (obs, to[0]);
+ else if (*p == from[1] && to[0] && to[1])
+ obstack_1grow (obs, to[1]);
+ }
+ obstack_grow (obs, data, len);
+ return;
+ }
+
+ if (strchr (from, '-') != NULL)
+ {
+ from = expand_ranges (from, obs);
+ assert (from && *from);
+ }
+
+ /* Calling strchr(from) for each character in data is quadratic,
+ since both strings can be arbitrarily long. Instead, create a
+ from-to mapping in one pass of from, then use that map in one
+ pass of data, for linear behavior. Traditional behavior is that
+ only the first instance of a character in from is consulted,
+ hence the found map. */
+ memset (map, 0, sizeof map);
+ memset (found, 0, sizeof found);
+ for ( ; (ch = *from) != '\0'; from++)
+ {
+ if (! found[ch])
+ {
+ found[ch] = 1;
+ map[ch] = *to;
+ }
+ if (*to != '\0')
+ to++;
+ }
+
+ for (data = ARG (1); (ch = *data) != '\0'; data++)
+ {
+ if (! found[ch])
+ obstack_1grow (obs, ch);
+ else if (map[ch])
+ obstack_1grow (obs, map[ch]);
+ }
+}
+
+/*-------------------------------------------------------------------.
+| Frontend for printf like formatting. The function format () lives |
+| in the file format.c. |
+`-------------------------------------------------------------------*/
+
+static void
+m4_format (struct obstack *obs, int argc, token_data **argv)
+{
+ if (bad_argc (argv[0], argc, 2, -1))
+ return;
+ expand_format (obs, argc - 1, argv + 1);
+}
+
+/*------------------------------------------------------------------.
+| Function to perform substitution by regular expressions. Used by |
+| the builtins regexp and patsubst. The changed text is placed on |
+| the obstack. The substitution is REPL, with \& substituted by |
+| this part of VICTIM matched by the last whole regular expression, |
+| taken from REGS[0], and \N substituted by the text matched by the |
+| Nth parenthesized sub-expression, taken from REGS[N]. |
+`------------------------------------------------------------------*/
+
+static int substitute_warned = 0;
+
+static void
+substitute (struct obstack *obs, const char *victim, const char *repl,
+ struct re_registers *regs)
+{
+ int ch;
+ __re_size_t ind;
+ while (1)
+ {
+ const char *backslash = strchr (repl, '\\');
+ if (!backslash)
+ {
+ obstack_grow (obs, repl, strlen (repl));
+ return;
+ }
+ obstack_grow (obs, repl, backslash - repl);
+ repl = backslash;
+ ch = *++repl;
+ switch (ch)
+ {
+ case '0':
+ if (!substitute_warned)
+ {
+ M4ERROR ((warning_status, 0, "\
+Warning: \\0 will disappear, use \\& instead in replacements"));
+ substitute_warned = 1;
+ }
+ /* Fall through. */
+
+ case '&':
+ obstack_grow (obs, victim + regs->start[0],
+ regs->end[0] - regs->start[0]);
+ repl++;
+ break;
+
+ case '1': case '2': case '3': case '4': case '5': case '6':
+ case '7': case '8': case '9':
+ ind = ch -= '0';
+ if (regs->num_regs - 1 <= ind)
+ M4ERROR ((warning_status, 0,
+ "Warning: sub-expression %d not present", ch));
+ else if (regs->end[ch] > 0)
+ obstack_grow (obs, victim + regs->start[ch],
+ regs->end[ch] - regs->start[ch]);
+ repl++;
+ break;
+
+ case '\0':
+ M4ERROR ((warning_status, 0,
+ "Warning: trailing \\ ignored in replacement"));
+ return;
+
+ default:
+ obstack_1grow (obs, ch);
+ repl++;
+ break;
+ }
+ }
+}
+
+/*------------------------------------------.
+| Initialize regular expression variables. |
+`------------------------------------------*/
+
+void
+init_pattern_buffer (struct re_pattern_buffer *buf, struct re_registers *regs)
+{
+ buf->translate = NULL;
+ buf->fastmap = NULL;
+ buf->buffer = NULL;
+ buf->allocated = 0;
+ if (regs)
+ {
+ regs->start = NULL;
+ regs->end = NULL;
+ }
+}
+
+/*------------------------------------------------------------------.
+| Regular expression version of index. Given two arguments, expand |
+| to the index of the first match of the second argument (a regexp) |
+| in the first. Expand to -1 if here is no match. Given a third |
+| argument, it changes the expansion to this argument. |
+`------------------------------------------------------------------*/
+
+static void
+m4_regexp (struct obstack *obs, int argc, token_data **argv)
+{
+ const char *victim; /* first argument */
+ const char *regexp; /* regular expression */
+ const char *repl; /* replacement string */
+
+ struct re_pattern_buffer buf; /* compiled regular expression */
+ struct re_registers regs; /* for subexpression matches */
+ const char *msg; /* error message from re_compile_pattern */
+ int startpos; /* start position of match */
+ int length; /* length of first argument */
+
+ if (bad_argc (argv[0], argc, 3, 4))
+ {
+ /* builtin(`regexp') is blank, but regexp(`abc') is 0. */
+ if (argc == 2)
+ shipout_int (obs, 0);
+ return;
+ }
+
+ victim = TOKEN_DATA_TEXT (argv[1]);
+ regexp = TOKEN_DATA_TEXT (argv[2]);
+
+ init_pattern_buffer (&buf, &regs);
+ msg = re_compile_pattern (regexp, strlen (regexp), &buf);
+
+ if (msg != NULL)
+ {
+ M4ERROR ((warning_status, 0,
+ "bad regular expression: `%s': %s", regexp, msg));
+ free_pattern_buffer (&buf, &regs);
+ return;
+ }
+
+ length = strlen (victim);
+ /* Avoid overhead of allocating regs if we won't use it. */
+ startpos = re_search (&buf, victim, length, 0, length,
+ argc == 3 ? NULL : &regs);
+
+ if (startpos == -2)
+ M4ERROR ((warning_status, 0,
+ "error matching regular expression `%s'", regexp));
+ else if (argc == 3)
+ shipout_int (obs, startpos);
+ else if (startpos >= 0)
+ {
+ repl = TOKEN_DATA_TEXT (argv[3]);
+ substitute (obs, victim, repl, &regs);
+ }
+
+ free_pattern_buffer (&buf, &regs);
+}
+
+/*--------------------------------------------------------------------------.
+| Substitute all matches of a regexp occuring in a string. Each match of |
+| the second argument (a regexp) in the first argument is changed to the |
+| third argument, with \& substituted by the matched text, and \N |
+| substituted by the text matched by the Nth parenthesized sub-expression. |
+`--------------------------------------------------------------------------*/
+
+static void
+m4_patsubst (struct obstack *obs, int argc, token_data **argv)
+{
+ const char *victim; /* first argument */
+ const char *regexp; /* regular expression */
+
+ struct re_pattern_buffer buf; /* compiled regular expression */
+ struct re_registers regs; /* for subexpression matches */
+ const char *msg; /* error message from re_compile_pattern */
+ int matchpos; /* start position of match */
+ int offset; /* current match offset */
+ int length; /* length of first argument */
+
+ if (bad_argc (argv[0], argc, 3, 4))
+ {
+ /* builtin(`patsubst') is blank, but patsubst(`abc') is abc. */
+ if (argc == 2)
+ obstack_grow (obs, ARG (1), strlen (ARG (1)));
+ return;
+ }
+
+ regexp = TOKEN_DATA_TEXT (argv[2]);
+
+ init_pattern_buffer (&buf, &regs);
+ msg = re_compile_pattern (regexp, strlen (regexp), &buf);
+
+ if (msg != NULL)
+ {
+ M4ERROR ((warning_status, 0,
+ "bad regular expression `%s': %s", regexp, msg));
+ free (buf.buffer);
+ return;
+ }
+
+ victim = TOKEN_DATA_TEXT (argv[1]);
+ length = strlen (victim);
+
+ offset = 0;
+ while (offset <= length)
+ {
+ matchpos = re_search (&buf, victim, length,
+ offset, length - offset, &regs);
+ if (matchpos < 0)
+ {
+
+ /* Match failed -- either error or there is no match in the
+ rest of the string, in which case the rest of the string is
+ copied verbatim. */
+
+ if (matchpos == -2)
+ M4ERROR ((warning_status, 0,
+ "error matching regular expression `%s'", regexp));
+ else if (offset < length)
+ obstack_grow (obs, victim + offset, length - offset);
+ break;
+ }
+
+ /* Copy the part of the string that was skipped by re_search (). */
+
+ if (matchpos > offset)
+ obstack_grow (obs, victim + offset, matchpos - offset);
+
+ /* Handle the part of the string that was covered by the match. */
+
+ substitute (obs, victim, ARG (3), &regs);
+
+ /* Update the offset to the end of the match. If the regexp
+ matched a null string, advance offset one more, to avoid
+ infinite loops. */
+
+ offset = regs.end[0];
+ if (regs.start[0] == regs.end[0])
+ obstack_1grow (obs, victim[offset++]);
+ }
+ obstack_1grow (obs, '\0');
+
+ free_pattern_buffer (&buf, &regs);
+}
+
+/* Finally, a placeholder builtin. This builtin is not installed by
+ default, but when reading back frozen files, this is associated
+ with any builtin we don't recognize (for example, if the frozen
+ file was created with a changeword capable m4, but is then loaded
+ by a different m4 that does not support changeword). This way, we
+ can keep 'm4 -R' quiet in the common case that the user did not
+ know or care about the builtin when the frozen file was created,
+ while still flagging it as a potential error if an attempt is made
+ to actually use the builtin. */
+
+/*--------------------------------------------------------------------.
+| Issue a warning that this macro is a placeholder for an unsupported |
+| builtin that was requested while reloading a frozen file. |
+`--------------------------------------------------------------------*/
+
+void
+m4_placeholder (struct obstack *obs M4_GNUC_UNUSED, int argc,
+ token_data **argv)
+{
+ M4ERROR ((warning_status, 0, "\
+builtin `%s' requested by frozen file is not supported", ARG (0)));
+}
+
+/*-------------------------------------------------------------------.
+| This function handles all expansion of user defined and predefined |
+| macros. It is called with an obstack OBS, where the macros |
+| expansion will be placed, as an unfinished object. SYM points to |
+| the macro definition, giving the expansion text. ARGC and ARGV |
+| are the arguments, as usual. |
+`-------------------------------------------------------------------*/
+
+void
+expand_user_macro (struct obstack *obs, symbol *sym,
+ int argc, token_data **argv)
+{
+ const char *text = SYMBOL_TEXT (sym);
+ int i;
+ while (1)
+ {
+ const char *dollar = strchr (text, '$');
+ if (!dollar)
+ {
+ obstack_grow (obs, text, strlen (text));
+ return;
+ }
+ obstack_grow (obs, text, dollar - text);
+ text = dollar;
+ switch (*++text)
+ {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ if (no_gnu_extensions)
+ {
+ i = *text++ - '0';
+ }
+ else
+ {
+ for (i = 0; isdigit (to_uchar (*text)); text++)
+ i = i*10 + (*text - '0');
+ }
+ if (i < argc)
+ obstack_grow (obs, TOKEN_DATA_TEXT (argv[i]),
+ strlen (TOKEN_DATA_TEXT (argv[i])));
+ break;
+
+ case '#': /* number of arguments */
+ shipout_int (obs, argc - 1);
+ text++;
+ break;
+
+ case '*': /* all arguments */
+ case '@': /* ... same, but quoted */
+ dump_args (obs, argc, argv, ",", *text == '@');
+ text++;
+ break;
+
+ default:
+ obstack_1grow (obs, '$');
+ break;
+ }
+ }
+}
diff --git a/contrib/tools/bison/m4/src/cpp.cpp b/contrib/tools/bison/m4/src/cpp.cpp
index 19c4a90e13..bca2763991 100644
--- a/contrib/tools/bison/m4/src/cpp.cpp
+++ b/contrib/tools/bison/m4/src/cpp.cpp
@@ -1,3 +1,3 @@
-// Just include a C++ header to tell stupid MSVC to link in C++ runtime providing wctype().
-
-#include <cassert>
+// Just include a C++ header to tell stupid MSVC to link in C++ runtime providing wctype().
+
+#include <cassert>
diff --git a/contrib/tools/bison/m4/src/debug.c b/contrib/tools/bison/m4/src/debug.c
index c13a205b89..8c4b2cf589 100644
--- a/contrib/tools/bison/m4/src/debug.c
+++ b/contrib/tools/bison/m4/src/debug.c
@@ -1,442 +1,442 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1991-1994, 2004, 2006-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "m4.h"
-
-#include <stdarg.h>
-#include <sys/stat.h>
-
-/* File for debugging output. */
-FILE *debug = NULL;
-
-/* Obstack for trace messages. */
-static struct obstack trace;
-
-static void debug_set_file (FILE *);
-
-/*----------------------------------.
-| Initialise the debugging module. |
-`----------------------------------*/
-
-void
-debug_init (void)
-{
- debug_set_file (stderr);
- obstack_init (&trace);
-}
-
-/*-----------------------------------------------------------------.
-| Function to decode the debugging flags OPTS. Used by main while |
-| processing option -d, and by the builtin debugmode (). |
-`-----------------------------------------------------------------*/
-
-int
-debug_decode (const char *opts)
-{
- int level;
-
- if (opts == NULL || *opts == '\0')
- level = DEBUG_TRACE_DEFAULT;
- else
- {
- for (level = 0; *opts; opts++)
- {
- switch (*opts)
- {
- case 'a':
- level |= DEBUG_TRACE_ARGS;
- break;
-
- case 'e':
- level |= DEBUG_TRACE_EXPANSION;
- break;
-
- case 'q':
- level |= DEBUG_TRACE_QUOTE;
- break;
-
- case 't':
- level |= DEBUG_TRACE_ALL;
- break;
-
- case 'l':
- level |= DEBUG_TRACE_LINE;
- break;
-
- case 'f':
- level |= DEBUG_TRACE_FILE;
- break;
-
- case 'p':
- level |= DEBUG_TRACE_PATH;
- break;
-
- case 'c':
- level |= DEBUG_TRACE_CALL;
- break;
-
- case 'i':
- level |= DEBUG_TRACE_INPUT;
- break;
-
- case 'x':
- level |= DEBUG_TRACE_CALLID;
- break;
-
- case 'V':
- level |= DEBUG_TRACE_VERBOSE;
- break;
-
- default:
- return -1;
- }
- }
- }
-
- /* This is to avoid screwing up the trace output due to changes in the
- debug_level. */
-
- obstack_free (&trace, obstack_finish (&trace));
-
- return level;
-}
-
-/*-----------------------------------------------------------------.
-| Change the debug output stream to FP. If the underlying file is |
-| the same as stdout, use stdout instead so that debug messages |
-| appear in the correct relative position. |
-`-----------------------------------------------------------------*/
-
-static void
-debug_set_file (FILE *fp)
-{
- struct stat stdout_stat, debug_stat;
-
- if (debug != NULL && debug != stderr && debug != stdout
- && close_stream (debug) != 0)
- {
- M4ERROR ((warning_status, errno, "error writing to debug stream"));
- retcode = EXIT_FAILURE;
- }
- debug = fp;
-
- if (debug != NULL && debug != stdout)
- {
- if (fstat (STDOUT_FILENO, &stdout_stat) < 0)
- return;
- if (fstat (fileno (debug), &debug_stat) < 0)
- return;
-
- /* mingw has a bug where fstat on a regular file reports st_ino
- of 0. On normal system, st_ino should never be 0. */
- if (stdout_stat.st_ino == debug_stat.st_ino
- && stdout_stat.st_dev == debug_stat.st_dev
- && stdout_stat.st_ino != 0)
- {
- if (debug != stderr && close_stream (debug) != 0)
- {
- M4ERROR ((warning_status, errno,
- "error writing to debug stream"));
- retcode = EXIT_FAILURE;
- }
- debug = stdout;
- }
- }
-}
-
-/*-----------------------------------------------------------.
-| Serialize files. Used before executing a system command. |
-`-----------------------------------------------------------*/
-
-void
-debug_flush_files (void)
-{
- fflush (stdout);
- fflush (stderr);
- if (debug != NULL && debug != stdout && debug != stderr)
- fflush (debug);
- /* POSIX requires that if m4 doesn't consume all input, but stdin is
- opened on a seekable file, that the file pointer be left at the
- next character on exit (but places no restrictions on the file
- pointer location on a non-seekable file). It also requires that
- fflush() followed by fseeko() on an input file set the underlying
- file pointer, and gnulib guarantees these semantics. However,
- fflush() on a non-seekable file can lose buffered data, which we
- might otherwise want to process after syscmd. Hence, we must
- check whether stdin is seekable. We must also be tolerant of
- operating with stdin closed, so we don't report any failures in
- this attempt. The stdio-safer module and friends are essential,
- so that if stdin was closed, this lseek is not on some other file
- that we have since opened. */
- if (lseek (STDIN_FILENO, 0, SEEK_CUR) >= 0
- && fflush (stdin) == 0)
- {
- fseeko (stdin, 0, SEEK_CUR);
- }
-}
-
-/*--------------------------------------------------------------.
-| Change the debug output to file NAME. If NAME is NULL, debug |
-| output is reverted to stderr, and if empty, debug output is |
-| discarded. Return true iff the output stream was changed. |
-`--------------------------------------------------------------*/
-
-bool
-debug_set_output (const char *name)
-{
- FILE *fp;
-
- if (name == NULL)
- debug_set_file (stderr);
- else if (*name == '\0')
- debug_set_file (NULL);
- else
- {
- fp = fopen (name, "a");
- if (fp == NULL)
- return false;
-
- if (set_cloexec_flag (fileno (fp), true) != 0)
- M4ERROR ((warning_status, errno,
- "Warning: cannot protect debug file across forks"));
- debug_set_file (fp);
- }
- return true;
-}
-
-/*--------------------------------------------------------------.
-| Print the header of a one-line debug message, starting by "m4 |
-| debug". |
-`--------------------------------------------------------------*/
-
-void
-debug_message_prefix (void)
-{
- xfprintf (debug, "m4debug:");
- if (current_line)
- {
- if (debug_level & DEBUG_TRACE_FILE)
- xfprintf (debug, "%s:", current_file);
- if (debug_level & DEBUG_TRACE_LINE)
- xfprintf (debug, "%d:", current_line);
- }
- putc (' ', debug);
-}
-
-/* The rest of this file contains the functions for macro tracing output.
- All tracing output for a macro call is collected on an obstack TRACE,
- and printed whenever the line is complete. This prevents tracing
- output from interfering with other debug messages generated by the
- various builtins. */
-
-/*------------------------------------------------------------------.
-| Tracing output is formatted here, by a simplified |
-| printf-to-obstack function trace_format (). Understands only %S, |
-| %s, %d, %l (optional left quote) and %r (optional right quote). |
-`------------------------------------------------------------------*/
-
-static void
-trace_format (const char *fmt, ...)
-{
- va_list args;
- char ch;
-
- int d;
- const char *s;
- int slen;
- int maxlen;
-
- va_start (args, fmt);
-
- while (true)
- {
- while ((ch = *fmt++) != '\0' && ch != '%')
- obstack_1grow (&trace, ch);
-
- if (ch == '\0')
- break;
-
- maxlen = 0;
- switch (*fmt++)
- {
- case 'S':
- maxlen = max_debug_argument_length;
- /* fall through */
-
- case 's':
- s = va_arg (args, const char *);
- break;
-
- case 'l':
- s = (debug_level & DEBUG_TRACE_QUOTE) ? lquote.string : "";
- break;
-
- case 'r':
- s = (debug_level & DEBUG_TRACE_QUOTE) ? rquote.string : "";
- break;
-
- case 'd':
- d = va_arg (args, int);
- s = ntoa (d, 10);
- break;
-
- default:
- s = "";
- break;
- }
-
- slen = strlen (s);
- if (maxlen == 0 || maxlen > slen)
- obstack_grow (&trace, s, slen);
- else
- {
- obstack_grow (&trace, s, maxlen);
- obstack_grow (&trace, "...", 3);
- }
- }
-
- va_end (args);
-}
-
-/*------------------------------------------------------------------.
-| Format the standard header attached to all tracing output lines. |
-`------------------------------------------------------------------*/
-
-static void
-trace_header (int id)
-{
- trace_format ("m4trace:");
- if (current_line)
- {
- if (debug_level & DEBUG_TRACE_FILE)
- trace_format ("%s:", current_file);
- if (debug_level & DEBUG_TRACE_LINE)
- trace_format ("%d:", current_line);
- }
- trace_format (" -%d- ", expansion_level);
- if (debug_level & DEBUG_TRACE_CALLID)
- trace_format ("id %d: ", id);
-}
-
-/*----------------------------------------------------.
-| Print current tracing line, and clear the obstack. |
-`----------------------------------------------------*/
-
-static void
-trace_flush (void)
-{
- char *line;
-
- obstack_1grow (&trace, '\0');
- line = (char *) obstack_finish (&trace);
- DEBUG_PRINT1 ("%s\n", line);
- obstack_free (&trace, line);
-}
-
-/*-------------------------------------------------------------.
-| Do pre-argument-collction tracing for macro NAME. Used from |
-| expand_macro (). |
-`-------------------------------------------------------------*/
-
-void
-trace_prepre (const char *name, int id)
-{
- trace_header (id);
- trace_format ("%s ...", name);
- trace_flush ();
-}
-
-/*--------------------------------------------------------------.
-| Format the parts of a trace line, that can be made before the |
-| macro is actually expanded. Used from expand_macro (). |
-`--------------------------------------------------------------*/
-
-void
-trace_pre (const char *name, int id, int argc, token_data **argv)
-{
- int i;
- const builtin *bp;
-
- trace_header (id);
- trace_format ("%s", name);
-
- if (argc > 1 && (debug_level & DEBUG_TRACE_ARGS))
- {
- trace_format ("(");
-
- for (i = 1; i < argc; i++)
- {
- if (i != 1)
- trace_format (", ");
-
- switch (TOKEN_DATA_TYPE (argv[i]))
- {
- case TOKEN_TEXT:
- trace_format ("%l%S%r", TOKEN_DATA_TEXT (argv[i]));
- break;
-
- case TOKEN_FUNC:
- bp = find_builtin_by_addr (TOKEN_DATA_FUNC (argv[i]));
- if (bp == NULL)
- {
- M4ERROR ((warning_status, 0, "\
-INTERNAL ERROR: builtin not found in builtin table! (trace_pre ())"));
- abort ();
- }
- trace_format ("<%s>", bp->name);
- break;
-
- case TOKEN_VOID:
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad token data type (trace_pre ())"));
- abort ();
- }
-
- }
- trace_format (")");
- }
-
- if (debug_level & DEBUG_TRACE_CALL)
- {
- trace_format (" -> ???");
- trace_flush ();
- }
-}
-
-/*-------------------------------------------------------------------.
-| Format the final part of a trace line and print it all. Used from |
-| expand_macro (). |
-`-------------------------------------------------------------------*/
-
-void
-trace_post (const char *name, int id, int argc, const char *expanded)
-{
- if (debug_level & DEBUG_TRACE_CALL)
- {
- trace_header (id);
- trace_format ("%s%s", name, (argc > 1) ? "(...)" : "");
- }
-
- if (expanded && (debug_level & DEBUG_TRACE_EXPANSION))
- trace_format (" -> %l%S%r", expanded);
- trace_flush ();
-}
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1991-1994, 2004, 2006-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "m4.h"
+
+#include <stdarg.h>
+#include <sys/stat.h>
+
+/* File for debugging output. */
+FILE *debug = NULL;
+
+/* Obstack for trace messages. */
+static struct obstack trace;
+
+static void debug_set_file (FILE *);
+
+/*----------------------------------.
+| Initialise the debugging module. |
+`----------------------------------*/
+
+void
+debug_init (void)
+{
+ debug_set_file (stderr);
+ obstack_init (&trace);
+}
+
+/*-----------------------------------------------------------------.
+| Function to decode the debugging flags OPTS. Used by main while |
+| processing option -d, and by the builtin debugmode (). |
+`-----------------------------------------------------------------*/
+
+int
+debug_decode (const char *opts)
+{
+ int level;
+
+ if (opts == NULL || *opts == '\0')
+ level = DEBUG_TRACE_DEFAULT;
+ else
+ {
+ for (level = 0; *opts; opts++)
+ {
+ switch (*opts)
+ {
+ case 'a':
+ level |= DEBUG_TRACE_ARGS;
+ break;
+
+ case 'e':
+ level |= DEBUG_TRACE_EXPANSION;
+ break;
+
+ case 'q':
+ level |= DEBUG_TRACE_QUOTE;
+ break;
+
+ case 't':
+ level |= DEBUG_TRACE_ALL;
+ break;
+
+ case 'l':
+ level |= DEBUG_TRACE_LINE;
+ break;
+
+ case 'f':
+ level |= DEBUG_TRACE_FILE;
+ break;
+
+ case 'p':
+ level |= DEBUG_TRACE_PATH;
+ break;
+
+ case 'c':
+ level |= DEBUG_TRACE_CALL;
+ break;
+
+ case 'i':
+ level |= DEBUG_TRACE_INPUT;
+ break;
+
+ case 'x':
+ level |= DEBUG_TRACE_CALLID;
+ break;
+
+ case 'V':
+ level |= DEBUG_TRACE_VERBOSE;
+ break;
+
+ default:
+ return -1;
+ }
+ }
+ }
+
+ /* This is to avoid screwing up the trace output due to changes in the
+ debug_level. */
+
+ obstack_free (&trace, obstack_finish (&trace));
+
+ return level;
+}
+
+/*-----------------------------------------------------------------.
+| Change the debug output stream to FP. If the underlying file is |
+| the same as stdout, use stdout instead so that debug messages |
+| appear in the correct relative position. |
+`-----------------------------------------------------------------*/
+
+static void
+debug_set_file (FILE *fp)
+{
+ struct stat stdout_stat, debug_stat;
+
+ if (debug != NULL && debug != stderr && debug != stdout
+ && close_stream (debug) != 0)
+ {
+ M4ERROR ((warning_status, errno, "error writing to debug stream"));
+ retcode = EXIT_FAILURE;
+ }
+ debug = fp;
+
+ if (debug != NULL && debug != stdout)
+ {
+ if (fstat (STDOUT_FILENO, &stdout_stat) < 0)
+ return;
+ if (fstat (fileno (debug), &debug_stat) < 0)
+ return;
+
+ /* mingw has a bug where fstat on a regular file reports st_ino
+ of 0. On normal system, st_ino should never be 0. */
+ if (stdout_stat.st_ino == debug_stat.st_ino
+ && stdout_stat.st_dev == debug_stat.st_dev
+ && stdout_stat.st_ino != 0)
+ {
+ if (debug != stderr && close_stream (debug) != 0)
+ {
+ M4ERROR ((warning_status, errno,
+ "error writing to debug stream"));
+ retcode = EXIT_FAILURE;
+ }
+ debug = stdout;
+ }
+ }
+}
+
+/*-----------------------------------------------------------.
+| Serialize files. Used before executing a system command. |
+`-----------------------------------------------------------*/
+
+void
+debug_flush_files (void)
+{
+ fflush (stdout);
+ fflush (stderr);
+ if (debug != NULL && debug != stdout && debug != stderr)
+ fflush (debug);
+ /* POSIX requires that if m4 doesn't consume all input, but stdin is
+ opened on a seekable file, that the file pointer be left at the
+ next character on exit (but places no restrictions on the file
+ pointer location on a non-seekable file). It also requires that
+ fflush() followed by fseeko() on an input file set the underlying
+ file pointer, and gnulib guarantees these semantics. However,
+ fflush() on a non-seekable file can lose buffered data, which we
+ might otherwise want to process after syscmd. Hence, we must
+ check whether stdin is seekable. We must also be tolerant of
+ operating with stdin closed, so we don't report any failures in
+ this attempt. The stdio-safer module and friends are essential,
+ so that if stdin was closed, this lseek is not on some other file
+ that we have since opened. */
+ if (lseek (STDIN_FILENO, 0, SEEK_CUR) >= 0
+ && fflush (stdin) == 0)
+ {
+ fseeko (stdin, 0, SEEK_CUR);
+ }
+}
+
+/*--------------------------------------------------------------.
+| Change the debug output to file NAME. If NAME is NULL, debug |
+| output is reverted to stderr, and if empty, debug output is |
+| discarded. Return true iff the output stream was changed. |
+`--------------------------------------------------------------*/
+
+bool
+debug_set_output (const char *name)
+{
+ FILE *fp;
+
+ if (name == NULL)
+ debug_set_file (stderr);
+ else if (*name == '\0')
+ debug_set_file (NULL);
+ else
+ {
+ fp = fopen (name, "a");
+ if (fp == NULL)
+ return false;
+
+ if (set_cloexec_flag (fileno (fp), true) != 0)
+ M4ERROR ((warning_status, errno,
+ "Warning: cannot protect debug file across forks"));
+ debug_set_file (fp);
+ }
+ return true;
+}
+
+/*--------------------------------------------------------------.
+| Print the header of a one-line debug message, starting by "m4 |
+| debug". |
+`--------------------------------------------------------------*/
+
+void
+debug_message_prefix (void)
+{
+ xfprintf (debug, "m4debug:");
+ if (current_line)
+ {
+ if (debug_level & DEBUG_TRACE_FILE)
+ xfprintf (debug, "%s:", current_file);
+ if (debug_level & DEBUG_TRACE_LINE)
+ xfprintf (debug, "%d:", current_line);
+ }
+ putc (' ', debug);
+}
+
+/* The rest of this file contains the functions for macro tracing output.
+ All tracing output for a macro call is collected on an obstack TRACE,
+ and printed whenever the line is complete. This prevents tracing
+ output from interfering with other debug messages generated by the
+ various builtins. */
+
+/*------------------------------------------------------------------.
+| Tracing output is formatted here, by a simplified |
+| printf-to-obstack function trace_format (). Understands only %S, |
+| %s, %d, %l (optional left quote) and %r (optional right quote). |
+`------------------------------------------------------------------*/
+
+static void
+trace_format (const char *fmt, ...)
+{
+ va_list args;
+ char ch;
+
+ int d;
+ const char *s;
+ int slen;
+ int maxlen;
+
+ va_start (args, fmt);
+
+ while (true)
+ {
+ while ((ch = *fmt++) != '\0' && ch != '%')
+ obstack_1grow (&trace, ch);
+
+ if (ch == '\0')
+ break;
+
+ maxlen = 0;
+ switch (*fmt++)
+ {
+ case 'S':
+ maxlen = max_debug_argument_length;
+ /* fall through */
+
+ case 's':
+ s = va_arg (args, const char *);
+ break;
+
+ case 'l':
+ s = (debug_level & DEBUG_TRACE_QUOTE) ? lquote.string : "";
+ break;
+
+ case 'r':
+ s = (debug_level & DEBUG_TRACE_QUOTE) ? rquote.string : "";
+ break;
+
+ case 'd':
+ d = va_arg (args, int);
+ s = ntoa (d, 10);
+ break;
+
+ default:
+ s = "";
+ break;
+ }
+
+ slen = strlen (s);
+ if (maxlen == 0 || maxlen > slen)
+ obstack_grow (&trace, s, slen);
+ else
+ {
+ obstack_grow (&trace, s, maxlen);
+ obstack_grow (&trace, "...", 3);
+ }
+ }
+
+ va_end (args);
+}
+
+/*------------------------------------------------------------------.
+| Format the standard header attached to all tracing output lines. |
+`------------------------------------------------------------------*/
+
+static void
+trace_header (int id)
+{
+ trace_format ("m4trace:");
+ if (current_line)
+ {
+ if (debug_level & DEBUG_TRACE_FILE)
+ trace_format ("%s:", current_file);
+ if (debug_level & DEBUG_TRACE_LINE)
+ trace_format ("%d:", current_line);
+ }
+ trace_format (" -%d- ", expansion_level);
+ if (debug_level & DEBUG_TRACE_CALLID)
+ trace_format ("id %d: ", id);
+}
+
+/*----------------------------------------------------.
+| Print current tracing line, and clear the obstack. |
+`----------------------------------------------------*/
+
+static void
+trace_flush (void)
+{
+ char *line;
+
+ obstack_1grow (&trace, '\0');
+ line = (char *) obstack_finish (&trace);
+ DEBUG_PRINT1 ("%s\n", line);
+ obstack_free (&trace, line);
+}
+
+/*-------------------------------------------------------------.
+| Do pre-argument-collction tracing for macro NAME. Used from |
+| expand_macro (). |
+`-------------------------------------------------------------*/
+
+void
+trace_prepre (const char *name, int id)
+{
+ trace_header (id);
+ trace_format ("%s ...", name);
+ trace_flush ();
+}
+
+/*--------------------------------------------------------------.
+| Format the parts of a trace line, that can be made before the |
+| macro is actually expanded. Used from expand_macro (). |
+`--------------------------------------------------------------*/
+
+void
+trace_pre (const char *name, int id, int argc, token_data **argv)
+{
+ int i;
+ const builtin *bp;
+
+ trace_header (id);
+ trace_format ("%s", name);
+
+ if (argc > 1 && (debug_level & DEBUG_TRACE_ARGS))
+ {
+ trace_format ("(");
+
+ for (i = 1; i < argc; i++)
+ {
+ if (i != 1)
+ trace_format (", ");
+
+ switch (TOKEN_DATA_TYPE (argv[i]))
+ {
+ case TOKEN_TEXT:
+ trace_format ("%l%S%r", TOKEN_DATA_TEXT (argv[i]));
+ break;
+
+ case TOKEN_FUNC:
+ bp = find_builtin_by_addr (TOKEN_DATA_FUNC (argv[i]));
+ if (bp == NULL)
+ {
+ M4ERROR ((warning_status, 0, "\
+INTERNAL ERROR: builtin not found in builtin table! (trace_pre ())"));
+ abort ();
+ }
+ trace_format ("<%s>", bp->name);
+ break;
+
+ case TOKEN_VOID:
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad token data type (trace_pre ())"));
+ abort ();
+ }
+
+ }
+ trace_format (")");
+ }
+
+ if (debug_level & DEBUG_TRACE_CALL)
+ {
+ trace_format (" -> ???");
+ trace_flush ();
+ }
+}
+
+/*-------------------------------------------------------------------.
+| Format the final part of a trace line and print it all. Used from |
+| expand_macro (). |
+`-------------------------------------------------------------------*/
+
+void
+trace_post (const char *name, int id, int argc, const char *expanded)
+{
+ if (debug_level & DEBUG_TRACE_CALL)
+ {
+ trace_header (id);
+ trace_format ("%s%s", name, (argc > 1) ? "(...)" : "");
+ }
+
+ if (expanded && (debug_level & DEBUG_TRACE_EXPANSION))
+ trace_format (" -> %l%S%r", expanded);
+ trace_flush ();
+}
diff --git a/contrib/tools/bison/m4/src/eval.c b/contrib/tools/bison/m4/src/eval.c
index 8b4b05afb1..3f08626619 100644
--- a/contrib/tools/bison/m4/src/eval.c
+++ b/contrib/tools/bison/m4/src/eval.c
@@ -1,855 +1,855 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2006-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* This file contains the functions to evaluate integer expressions for
- the "eval" macro. It is a little, fairly self-contained module, with
- its own scanner, and a recursive descent parser. The only entry point
- is evaluate (). */
-
-#include "m4.h"
-
-/* Evaluates token types. */
-
-typedef enum eval_token
- {
- ERROR, BADOP,
- PLUS, MINUS,
- EXPONENT,
- TIMES, DIVIDE, MODULO,
- ASSIGN, EQ, NOTEQ, GT, GTEQ, LS, LSEQ,
- LSHIFT, RSHIFT,
- LNOT, LAND, LOR,
- NOT, AND, OR, XOR,
- LEFTP, RIGHTP,
- NUMBER, EOTEXT
- }
-eval_token;
-
-/* Error types. */
-
-typedef enum eval_error
- {
- NO_ERROR,
- DIVIDE_ZERO,
- MODULO_ZERO,
- NEGATIVE_EXPONENT,
- /* All errors prior to SYNTAX_ERROR can be ignored in a dead
- branch of && and ||. All errors after are just more details
- about a syntax error. */
- SYNTAX_ERROR,
- MISSING_RIGHT,
- UNKNOWN_INPUT,
- EXCESS_INPUT,
- INVALID_OPERATOR
- }
-eval_error;
-
-static eval_error logical_or_term (eval_token, int32_t *);
-static eval_error logical_and_term (eval_token, int32_t *);
-static eval_error or_term (eval_token, int32_t *);
-static eval_error xor_term (eval_token, int32_t *);
-static eval_error and_term (eval_token, int32_t *);
-static eval_error equality_term (eval_token, int32_t *);
-static eval_error cmp_term (eval_token, int32_t *);
-static eval_error shift_term (eval_token, int32_t *);
-static eval_error add_term (eval_token, int32_t *);
-static eval_error mult_term (eval_token, int32_t *);
-static eval_error exp_term (eval_token, int32_t *);
-static eval_error unary_term (eval_token, int32_t *);
-static eval_error simple_term (eval_token, int32_t *);
-
-/*--------------------.
-| Lexical functions. |
-`--------------------*/
-
-/* Pointer to next character of input text. */
-static const char *eval_text;
-
-/* Value of eval_text, from before last call of eval_lex (). This is so we
- can back up, if we have read too much. */
-static const char *last_text;
-
-static void
-eval_init_lex (const char *text)
-{
- eval_text = text;
- last_text = NULL;
-}
-
-static void
-eval_undo (void)
-{
- eval_text = last_text;
-}
-
-/* VAL is numerical value, if any. */
-
-static eval_token
-eval_lex (int32_t *val)
-{
- while (isspace (to_uchar (*eval_text)))
- eval_text++;
-
- last_text = eval_text;
-
- if (*eval_text == '\0')
- return EOTEXT;
-
- if (isdigit (to_uchar (*eval_text)))
- {
- int base, digit;
-
- if (*eval_text == '0')
- {
- eval_text++;
- switch (*eval_text)
- {
- case 'x':
- case 'X':
- base = 16;
- eval_text++;
- break;
-
- case 'b':
- case 'B':
- base = 2;
- eval_text++;
- break;
-
- case 'r':
- case 'R':
- base = 0;
- eval_text++;
- while (isdigit (to_uchar (*eval_text)) && base <= 36)
- base = 10 * base + *eval_text++ - '0';
- if (base == 0 || base > 36 || *eval_text != ':')
- return ERROR;
- eval_text++;
- break;
-
- default:
- base = 8;
- }
- }
- else
- base = 10;
-
- /* FIXME - this calculation can overflow. Consider xstrtol. */
- *val = 0;
- for (; *eval_text; eval_text++)
- {
- if (isdigit (to_uchar (*eval_text)))
- digit = *eval_text - '0';
- else if (islower (to_uchar (*eval_text)))
- digit = *eval_text - 'a' + 10;
- else if (isupper (to_uchar (*eval_text)))
- digit = *eval_text - 'A' + 10;
- else
- break;
-
- if (base == 1)
- {
- if (digit == 1)
- (*val)++;
- else if (digit == 0 && !*val)
- continue;
- else
- break;
- }
- else if (digit >= base)
- break;
- else
- *val = *val * base + digit;
- }
- return NUMBER;
- }
-
- switch (*eval_text++)
- {
- case '+':
- if (*eval_text == '+' || *eval_text == '=')
- return BADOP;
- return PLUS;
- case '-':
- if (*eval_text == '-' || *eval_text == '=')
- return BADOP;
- return MINUS;
- case '*':
- if (*eval_text == '*')
- {
- eval_text++;
- return EXPONENT;
- }
- else if (*eval_text == '=')
- return BADOP;
- return TIMES;
- case '/':
- if (*eval_text == '=')
- return BADOP;
- return DIVIDE;
- case '%':
- if (*eval_text == '=')
- return BADOP;
- return MODULO;
- case '=':
- if (*eval_text == '=')
- {
- eval_text++;
- return EQ;
- }
- return ASSIGN;
- case '!':
- if (*eval_text == '=')
- {
- eval_text++;
- return NOTEQ;
- }
- return LNOT;
- case '>':
- if (*eval_text == '=')
- {
- eval_text++;
- return GTEQ;
- }
- else if (*eval_text == '>')
- {
- if (*++eval_text == '=')
- return BADOP;
- return RSHIFT;
- }
- return GT;
- case '<':
- if (*eval_text == '=')
- {
- eval_text++;
- return LSEQ;
- }
- else if (*eval_text == '<')
- {
- if (*++eval_text == '=')
- return BADOP;
- return LSHIFT;
- }
- return LS;
- case '^':
- if (*eval_text == '=')
- return BADOP;
- return XOR;
- case '~':
- return NOT;
- case '&':
- if (*eval_text == '&')
- {
- eval_text++;
- return LAND;
- }
- else if (*eval_text == '=')
- return BADOP;
- return AND;
- case '|':
- if (*eval_text == '|')
- {
- eval_text++;
- return LOR;
- }
- else if (*eval_text == '=')
- return BADOP;
- return OR;
- case '(':
- return LEFTP;
- case ')':
- return RIGHTP;
- default:
- return ERROR;
- }
-}
-
-/*---------------------------------------.
-| Main entry point, called from "eval". |
-`---------------------------------------*/
-
-bool
-evaluate (const char *expr, int32_t *val)
-{
- eval_token et;
- eval_error err;
-
- eval_init_lex (expr);
- et = eval_lex (val);
- err = logical_or_term (et, val);
-
- if (err == NO_ERROR && *eval_text != '\0')
- {
- if (eval_lex (val) == BADOP)
- err = INVALID_OPERATOR;
- else
- err = EXCESS_INPUT;
- }
-
- switch (err)
- {
- case NO_ERROR:
- break;
-
- case MISSING_RIGHT:
- M4ERROR ((warning_status, 0,
- "bad expression in eval (missing right parenthesis): %s",
- expr));
- break;
-
- case SYNTAX_ERROR:
- M4ERROR ((warning_status, 0,
- "bad expression in eval: %s", expr));
- break;
-
- case UNKNOWN_INPUT:
- M4ERROR ((warning_status, 0,
- "bad expression in eval (bad input): %s", expr));
- break;
-
- case EXCESS_INPUT:
- M4ERROR ((warning_status, 0,
- "bad expression in eval (excess input): %s", expr));
- break;
-
- case INVALID_OPERATOR:
- M4ERROR ((warning_status, 0,
- "invalid operator in eval: %s", expr));
- retcode = EXIT_FAILURE;
- break;
-
- case DIVIDE_ZERO:
- M4ERROR ((warning_status, 0,
- "divide by zero in eval: %s", expr));
- break;
-
- case MODULO_ZERO:
- M4ERROR ((warning_status, 0,
- "modulo by zero in eval: %s", expr));
- break;
-
- case NEGATIVE_EXPONENT:
- M4ERROR ((warning_status, 0,
- "negative exponent in eval: %s", expr));
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad error code in evaluate ()"));
- abort ();
- }
-
- return err != NO_ERROR;
-}
-
-/*---------------------------.
-| Recursive descent parser. |
-`---------------------------*/
-
-static eval_error
-logical_or_term (eval_token et, int32_t *v1)
-{
- int32_t v2;
- eval_error er;
-
- if ((er = logical_and_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((et = eval_lex (&v2)) == LOR)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- /* Implement short-circuiting of valid syntax. */
- er = logical_and_term (et, &v2);
- if (er == NO_ERROR)
- *v1 = *v1 || v2;
- else if (*v1 != 0 && er < SYNTAX_ERROR)
- *v1 = 1;
- else
- return er;
- }
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-logical_and_term (eval_token et, int32_t *v1)
-{
- int32_t v2;
- eval_error er;
-
- if ((er = or_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((et = eval_lex (&v2)) == LAND)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- /* Implement short-circuiting of valid syntax. */
- er = or_term (et, &v2);
- if (er == NO_ERROR)
- *v1 = *v1 && v2;
- else if (*v1 == 0 && er < SYNTAX_ERROR)
- ; /* v1 is already 0 */
- else
- return er;
- }
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-or_term (eval_token et, int32_t *v1)
-{
- int32_t v2;
- eval_error er;
-
- if ((er = xor_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((et = eval_lex (&v2)) == OR)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = xor_term (et, &v2)) != NO_ERROR)
- return er;
-
- *v1 |= v2;
- }
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-xor_term (eval_token et, int32_t *v1)
-{
- int32_t v2;
- eval_error er;
-
- if ((er = and_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((et = eval_lex (&v2)) == XOR)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = and_term (et, &v2)) != NO_ERROR)
- return er;
-
- *v1 ^= v2;
- }
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-and_term (eval_token et, int32_t *v1)
-{
- int32_t v2;
- eval_error er;
-
- if ((er = equality_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((et = eval_lex (&v2)) == AND)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = equality_term (et, &v2)) != NO_ERROR)
- return er;
-
- *v1 &= v2;
- }
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-equality_term (eval_token et, int32_t *v1)
-{
- eval_token op;
- int32_t v2;
- eval_error er;
-
- if ((er = cmp_term (et, v1)) != NO_ERROR)
- return er;
-
- /* In the 1.4.x series, we maintain the traditional behavior that
- '=' is a synonym for '=='; however, this is contrary to POSIX and
- we hope to convert '=' to mean assignment in 2.0. */
- while ((op = eval_lex (&v2)) == EQ || op == NOTEQ || op == ASSIGN)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = cmp_term (et, &v2)) != NO_ERROR)
- return er;
-
- if (op == ASSIGN)
- {
- M4ERROR ((warning_status, 0, "\
-Warning: recommend ==, not =, for equality operator"));
- op = EQ;
- }
- *v1 = (op == EQ) == (*v1 == v2);
- }
- if (op == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-cmp_term (eval_token et, int32_t *v1)
-{
- eval_token op;
- int32_t v2;
- eval_error er;
-
- if ((er = shift_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((op = eval_lex (&v2)) == GT || op == GTEQ
- || op == LS || op == LSEQ)
- {
-
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = shift_term (et, &v2)) != NO_ERROR)
- return er;
-
- switch (op)
- {
- case GT:
- *v1 = *v1 > v2;
- break;
-
- case GTEQ:
- *v1 = *v1 >= v2;
- break;
-
- case LS:
- *v1 = *v1 < v2;
- break;
-
- case LSEQ:
- *v1 = *v1 <= v2;
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad comparison operator in cmp_term ()"));
- abort ();
- }
- }
- if (op == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-shift_term (eval_token et, int32_t *v1)
-{
- eval_token op;
- int32_t v2;
- uint32_t u1;
- eval_error er;
-
- if ((er = add_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((op = eval_lex (&v2)) == LSHIFT || op == RSHIFT)
- {
-
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = add_term (et, &v2)) != NO_ERROR)
- return er;
-
- /* Minimize undefined C behavior (shifting by a negative number,
- shifting by the width or greater, left shift overflow, or
- right shift of a negative number). Implement Java 32-bit
- wrap-around semantics. This code assumes that the
- implementation-defined overflow when casting unsigned to
- signed is a silent twos-complement wrap-around. */
- switch (op)
- {
- case LSHIFT:
- u1 = *v1;
- u1 <<= (uint32_t) (v2 & 0x1f);
- *v1 = u1;
- break;
-
- case RSHIFT:
- u1 = *v1 < 0 ? ~*v1 : *v1;
- u1 >>= (uint32_t) (v2 & 0x1f);
- *v1 = *v1 < 0 ? ~u1 : u1;
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad shift operator in shift_term ()"));
- abort ();
- }
- }
- if (op == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-add_term (eval_token et, int32_t *v1)
-{
- eval_token op;
- int32_t v2;
- eval_error er;
-
- if ((er = mult_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((op = eval_lex (&v2)) == PLUS || op == MINUS)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = mult_term (et, &v2)) != NO_ERROR)
- return er;
-
- /* Minimize undefined C behavior on overflow. This code assumes
- that the implementation-defined overflow when casting
- unsigned to signed is a silent twos-complement
- wrap-around. */
- if (op == PLUS)
- *v1 = (int32_t) ((uint32_t) *v1 + (uint32_t) v2);
- else
- *v1 = (int32_t) ((uint32_t) *v1 - (uint32_t) v2);
- }
- if (op == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-mult_term (eval_token et, int32_t *v1)
-{
- eval_token op;
- int32_t v2;
- eval_error er;
-
- if ((er = exp_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((op = eval_lex (&v2)) == TIMES || op == DIVIDE || op == MODULO)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = exp_term (et, &v2)) != NO_ERROR)
- return er;
-
- /* Minimize undefined C behavior on overflow. This code assumes
- that the implementation-defined overflow when casting
- unsigned to signed is a silent twos-complement
- wrap-around. */
- switch (op)
- {
- case TIMES:
- *v1 = (int32_t) ((uint32_t) *v1 * (uint32_t) v2);
- break;
-
- case DIVIDE:
- if (v2 == 0)
- return DIVIDE_ZERO;
- else if (v2 == -1)
- /* Avoid overflow, and the x86 SIGFPE on INT_MIN / -1. */
- *v1 = (int32_t) -(uint32_t) *v1;
- else
- *v1 /= v2;
- break;
-
- case MODULO:
- if (v2 == 0)
- return MODULO_ZERO;
- else if (v2 == -1)
- /* Avoid the x86 SIGFPE on INT_MIN % -1. */
- *v1 = 0;
- else
- *v1 %= v2;
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad operator in mult_term ()"));
- abort ();
- }
- }
- if (op == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-exp_term (eval_token et, int32_t *v1)
-{
- uint32_t result;
- int32_t v2;
- eval_error er;
-
- if ((er = unary_term (et, v1)) != NO_ERROR)
- return er;
-
- while ((et = eval_lex (&v2)) == EXPONENT)
- {
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = exp_term (et, &v2)) != NO_ERROR)
- return er;
-
- /* Minimize undefined C behavior on overflow. This code assumes
- that the implementation-defined overflow when casting
- unsigned to signed is a silent twos-complement
- wrap-around. */
- result = 1;
- if (v2 < 0)
- return NEGATIVE_EXPONENT;
- if (*v1 == 0 && v2 == 0)
- return DIVIDE_ZERO;
- while (v2-- > 0)
- result *= (uint32_t) *v1;
- *v1 = result;
- }
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- eval_undo ();
- return NO_ERROR;
-}
-
-static eval_error
-unary_term (eval_token et, int32_t *v1)
-{
- eval_error er;
-
- if (et == PLUS || et == MINUS || et == NOT || et == LNOT)
- {
- eval_token et2 = eval_lex (v1);
- if (et2 == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = unary_term (et2, v1)) != NO_ERROR)
- return er;
-
- /* Minimize undefined C behavior on overflow. This code assumes
- that the implementation-defined overflow when casting
- unsigned to signed is a silent twos-complement
- wrap-around. */
- if (et == MINUS)
- *v1 = (int32_t) -(uint32_t) *v1;
- else if (et == NOT)
- *v1 = ~*v1;
- else if (et == LNOT)
- *v1 = *v1 == 0 ? 1 : 0;
- }
- else if ((er = simple_term (et, v1)) != NO_ERROR)
- return er;
-
- return NO_ERROR;
-}
-
-static eval_error
-simple_term (eval_token et, int32_t *v1)
-{
- int32_t v2;
- eval_error er;
-
- switch (et)
- {
- case LEFTP:
- et = eval_lex (v1);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if ((er = logical_or_term (et, v1)) != NO_ERROR)
- return er;
-
- et = eval_lex (&v2);
- if (et == ERROR)
- return UNKNOWN_INPUT;
-
- if (et != RIGHTP)
- return MISSING_RIGHT;
-
- break;
-
- case NUMBER:
- break;
-
- case BADOP:
- return INVALID_OPERATOR;
-
- default:
- return SYNTAX_ERROR;
- }
- return NO_ERROR;
-}
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2006-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* This file contains the functions to evaluate integer expressions for
+ the "eval" macro. It is a little, fairly self-contained module, with
+ its own scanner, and a recursive descent parser. The only entry point
+ is evaluate (). */
+
+#include "m4.h"
+
+/* Evaluates token types. */
+
+typedef enum eval_token
+ {
+ ERROR, BADOP,
+ PLUS, MINUS,
+ EXPONENT,
+ TIMES, DIVIDE, MODULO,
+ ASSIGN, EQ, NOTEQ, GT, GTEQ, LS, LSEQ,
+ LSHIFT, RSHIFT,
+ LNOT, LAND, LOR,
+ NOT, AND, OR, XOR,
+ LEFTP, RIGHTP,
+ NUMBER, EOTEXT
+ }
+eval_token;
+
+/* Error types. */
+
+typedef enum eval_error
+ {
+ NO_ERROR,
+ DIVIDE_ZERO,
+ MODULO_ZERO,
+ NEGATIVE_EXPONENT,
+ /* All errors prior to SYNTAX_ERROR can be ignored in a dead
+ branch of && and ||. All errors after are just more details
+ about a syntax error. */
+ SYNTAX_ERROR,
+ MISSING_RIGHT,
+ UNKNOWN_INPUT,
+ EXCESS_INPUT,
+ INVALID_OPERATOR
+ }
+eval_error;
+
+static eval_error logical_or_term (eval_token, int32_t *);
+static eval_error logical_and_term (eval_token, int32_t *);
+static eval_error or_term (eval_token, int32_t *);
+static eval_error xor_term (eval_token, int32_t *);
+static eval_error and_term (eval_token, int32_t *);
+static eval_error equality_term (eval_token, int32_t *);
+static eval_error cmp_term (eval_token, int32_t *);
+static eval_error shift_term (eval_token, int32_t *);
+static eval_error add_term (eval_token, int32_t *);
+static eval_error mult_term (eval_token, int32_t *);
+static eval_error exp_term (eval_token, int32_t *);
+static eval_error unary_term (eval_token, int32_t *);
+static eval_error simple_term (eval_token, int32_t *);
+
+/*--------------------.
+| Lexical functions. |
+`--------------------*/
+
+/* Pointer to next character of input text. */
+static const char *eval_text;
+
+/* Value of eval_text, from before last call of eval_lex (). This is so we
+ can back up, if we have read too much. */
+static const char *last_text;
+
+static void
+eval_init_lex (const char *text)
+{
+ eval_text = text;
+ last_text = NULL;
+}
+
+static void
+eval_undo (void)
+{
+ eval_text = last_text;
+}
+
+/* VAL is numerical value, if any. */
+
+static eval_token
+eval_lex (int32_t *val)
+{
+ while (isspace (to_uchar (*eval_text)))
+ eval_text++;
+
+ last_text = eval_text;
+
+ if (*eval_text == '\0')
+ return EOTEXT;
+
+ if (isdigit (to_uchar (*eval_text)))
+ {
+ int base, digit;
+
+ if (*eval_text == '0')
+ {
+ eval_text++;
+ switch (*eval_text)
+ {
+ case 'x':
+ case 'X':
+ base = 16;
+ eval_text++;
+ break;
+
+ case 'b':
+ case 'B':
+ base = 2;
+ eval_text++;
+ break;
+
+ case 'r':
+ case 'R':
+ base = 0;
+ eval_text++;
+ while (isdigit (to_uchar (*eval_text)) && base <= 36)
+ base = 10 * base + *eval_text++ - '0';
+ if (base == 0 || base > 36 || *eval_text != ':')
+ return ERROR;
+ eval_text++;
+ break;
+
+ default:
+ base = 8;
+ }
+ }
+ else
+ base = 10;
+
+ /* FIXME - this calculation can overflow. Consider xstrtol. */
+ *val = 0;
+ for (; *eval_text; eval_text++)
+ {
+ if (isdigit (to_uchar (*eval_text)))
+ digit = *eval_text - '0';
+ else if (islower (to_uchar (*eval_text)))
+ digit = *eval_text - 'a' + 10;
+ else if (isupper (to_uchar (*eval_text)))
+ digit = *eval_text - 'A' + 10;
+ else
+ break;
+
+ if (base == 1)
+ {
+ if (digit == 1)
+ (*val)++;
+ else if (digit == 0 && !*val)
+ continue;
+ else
+ break;
+ }
+ else if (digit >= base)
+ break;
+ else
+ *val = *val * base + digit;
+ }
+ return NUMBER;
+ }
+
+ switch (*eval_text++)
+ {
+ case '+':
+ if (*eval_text == '+' || *eval_text == '=')
+ return BADOP;
+ return PLUS;
+ case '-':
+ if (*eval_text == '-' || *eval_text == '=')
+ return BADOP;
+ return MINUS;
+ case '*':
+ if (*eval_text == '*')
+ {
+ eval_text++;
+ return EXPONENT;
+ }
+ else if (*eval_text == '=')
+ return BADOP;
+ return TIMES;
+ case '/':
+ if (*eval_text == '=')
+ return BADOP;
+ return DIVIDE;
+ case '%':
+ if (*eval_text == '=')
+ return BADOP;
+ return MODULO;
+ case '=':
+ if (*eval_text == '=')
+ {
+ eval_text++;
+ return EQ;
+ }
+ return ASSIGN;
+ case '!':
+ if (*eval_text == '=')
+ {
+ eval_text++;
+ return NOTEQ;
+ }
+ return LNOT;
+ case '>':
+ if (*eval_text == '=')
+ {
+ eval_text++;
+ return GTEQ;
+ }
+ else if (*eval_text == '>')
+ {
+ if (*++eval_text == '=')
+ return BADOP;
+ return RSHIFT;
+ }
+ return GT;
+ case '<':
+ if (*eval_text == '=')
+ {
+ eval_text++;
+ return LSEQ;
+ }
+ else if (*eval_text == '<')
+ {
+ if (*++eval_text == '=')
+ return BADOP;
+ return LSHIFT;
+ }
+ return LS;
+ case '^':
+ if (*eval_text == '=')
+ return BADOP;
+ return XOR;
+ case '~':
+ return NOT;
+ case '&':
+ if (*eval_text == '&')
+ {
+ eval_text++;
+ return LAND;
+ }
+ else if (*eval_text == '=')
+ return BADOP;
+ return AND;
+ case '|':
+ if (*eval_text == '|')
+ {
+ eval_text++;
+ return LOR;
+ }
+ else if (*eval_text == '=')
+ return BADOP;
+ return OR;
+ case '(':
+ return LEFTP;
+ case ')':
+ return RIGHTP;
+ default:
+ return ERROR;
+ }
+}
+
+/*---------------------------------------.
+| Main entry point, called from "eval". |
+`---------------------------------------*/
+
+bool
+evaluate (const char *expr, int32_t *val)
+{
+ eval_token et;
+ eval_error err;
+
+ eval_init_lex (expr);
+ et = eval_lex (val);
+ err = logical_or_term (et, val);
+
+ if (err == NO_ERROR && *eval_text != '\0')
+ {
+ if (eval_lex (val) == BADOP)
+ err = INVALID_OPERATOR;
+ else
+ err = EXCESS_INPUT;
+ }
+
+ switch (err)
+ {
+ case NO_ERROR:
+ break;
+
+ case MISSING_RIGHT:
+ M4ERROR ((warning_status, 0,
+ "bad expression in eval (missing right parenthesis): %s",
+ expr));
+ break;
+
+ case SYNTAX_ERROR:
+ M4ERROR ((warning_status, 0,
+ "bad expression in eval: %s", expr));
+ break;
+
+ case UNKNOWN_INPUT:
+ M4ERROR ((warning_status, 0,
+ "bad expression in eval (bad input): %s", expr));
+ break;
+
+ case EXCESS_INPUT:
+ M4ERROR ((warning_status, 0,
+ "bad expression in eval (excess input): %s", expr));
+ break;
+
+ case INVALID_OPERATOR:
+ M4ERROR ((warning_status, 0,
+ "invalid operator in eval: %s", expr));
+ retcode = EXIT_FAILURE;
+ break;
+
+ case DIVIDE_ZERO:
+ M4ERROR ((warning_status, 0,
+ "divide by zero in eval: %s", expr));
+ break;
+
+ case MODULO_ZERO:
+ M4ERROR ((warning_status, 0,
+ "modulo by zero in eval: %s", expr));
+ break;
+
+ case NEGATIVE_EXPONENT:
+ M4ERROR ((warning_status, 0,
+ "negative exponent in eval: %s", expr));
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad error code in evaluate ()"));
+ abort ();
+ }
+
+ return err != NO_ERROR;
+}
+
+/*---------------------------.
+| Recursive descent parser. |
+`---------------------------*/
+
+static eval_error
+logical_or_term (eval_token et, int32_t *v1)
+{
+ int32_t v2;
+ eval_error er;
+
+ if ((er = logical_and_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((et = eval_lex (&v2)) == LOR)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ /* Implement short-circuiting of valid syntax. */
+ er = logical_and_term (et, &v2);
+ if (er == NO_ERROR)
+ *v1 = *v1 || v2;
+ else if (*v1 != 0 && er < SYNTAX_ERROR)
+ *v1 = 1;
+ else
+ return er;
+ }
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+logical_and_term (eval_token et, int32_t *v1)
+{
+ int32_t v2;
+ eval_error er;
+
+ if ((er = or_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((et = eval_lex (&v2)) == LAND)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ /* Implement short-circuiting of valid syntax. */
+ er = or_term (et, &v2);
+ if (er == NO_ERROR)
+ *v1 = *v1 && v2;
+ else if (*v1 == 0 && er < SYNTAX_ERROR)
+ ; /* v1 is already 0 */
+ else
+ return er;
+ }
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+or_term (eval_token et, int32_t *v1)
+{
+ int32_t v2;
+ eval_error er;
+
+ if ((er = xor_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((et = eval_lex (&v2)) == OR)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = xor_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ *v1 |= v2;
+ }
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+xor_term (eval_token et, int32_t *v1)
+{
+ int32_t v2;
+ eval_error er;
+
+ if ((er = and_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((et = eval_lex (&v2)) == XOR)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = and_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ *v1 ^= v2;
+ }
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+and_term (eval_token et, int32_t *v1)
+{
+ int32_t v2;
+ eval_error er;
+
+ if ((er = equality_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((et = eval_lex (&v2)) == AND)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = equality_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ *v1 &= v2;
+ }
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+equality_term (eval_token et, int32_t *v1)
+{
+ eval_token op;
+ int32_t v2;
+ eval_error er;
+
+ if ((er = cmp_term (et, v1)) != NO_ERROR)
+ return er;
+
+ /* In the 1.4.x series, we maintain the traditional behavior that
+ '=' is a synonym for '=='; however, this is contrary to POSIX and
+ we hope to convert '=' to mean assignment in 2.0. */
+ while ((op = eval_lex (&v2)) == EQ || op == NOTEQ || op == ASSIGN)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = cmp_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ if (op == ASSIGN)
+ {
+ M4ERROR ((warning_status, 0, "\
+Warning: recommend ==, not =, for equality operator"));
+ op = EQ;
+ }
+ *v1 = (op == EQ) == (*v1 == v2);
+ }
+ if (op == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+cmp_term (eval_token et, int32_t *v1)
+{
+ eval_token op;
+ int32_t v2;
+ eval_error er;
+
+ if ((er = shift_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((op = eval_lex (&v2)) == GT || op == GTEQ
+ || op == LS || op == LSEQ)
+ {
+
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = shift_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ switch (op)
+ {
+ case GT:
+ *v1 = *v1 > v2;
+ break;
+
+ case GTEQ:
+ *v1 = *v1 >= v2;
+ break;
+
+ case LS:
+ *v1 = *v1 < v2;
+ break;
+
+ case LSEQ:
+ *v1 = *v1 <= v2;
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad comparison operator in cmp_term ()"));
+ abort ();
+ }
+ }
+ if (op == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+shift_term (eval_token et, int32_t *v1)
+{
+ eval_token op;
+ int32_t v2;
+ uint32_t u1;
+ eval_error er;
+
+ if ((er = add_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((op = eval_lex (&v2)) == LSHIFT || op == RSHIFT)
+ {
+
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = add_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ /* Minimize undefined C behavior (shifting by a negative number,
+ shifting by the width or greater, left shift overflow, or
+ right shift of a negative number). Implement Java 32-bit
+ wrap-around semantics. This code assumes that the
+ implementation-defined overflow when casting unsigned to
+ signed is a silent twos-complement wrap-around. */
+ switch (op)
+ {
+ case LSHIFT:
+ u1 = *v1;
+ u1 <<= (uint32_t) (v2 & 0x1f);
+ *v1 = u1;
+ break;
+
+ case RSHIFT:
+ u1 = *v1 < 0 ? ~*v1 : *v1;
+ u1 >>= (uint32_t) (v2 & 0x1f);
+ *v1 = *v1 < 0 ? ~u1 : u1;
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad shift operator in shift_term ()"));
+ abort ();
+ }
+ }
+ if (op == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+add_term (eval_token et, int32_t *v1)
+{
+ eval_token op;
+ int32_t v2;
+ eval_error er;
+
+ if ((er = mult_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((op = eval_lex (&v2)) == PLUS || op == MINUS)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = mult_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ /* Minimize undefined C behavior on overflow. This code assumes
+ that the implementation-defined overflow when casting
+ unsigned to signed is a silent twos-complement
+ wrap-around. */
+ if (op == PLUS)
+ *v1 = (int32_t) ((uint32_t) *v1 + (uint32_t) v2);
+ else
+ *v1 = (int32_t) ((uint32_t) *v1 - (uint32_t) v2);
+ }
+ if (op == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+mult_term (eval_token et, int32_t *v1)
+{
+ eval_token op;
+ int32_t v2;
+ eval_error er;
+
+ if ((er = exp_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((op = eval_lex (&v2)) == TIMES || op == DIVIDE || op == MODULO)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = exp_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ /* Minimize undefined C behavior on overflow. This code assumes
+ that the implementation-defined overflow when casting
+ unsigned to signed is a silent twos-complement
+ wrap-around. */
+ switch (op)
+ {
+ case TIMES:
+ *v1 = (int32_t) ((uint32_t) *v1 * (uint32_t) v2);
+ break;
+
+ case DIVIDE:
+ if (v2 == 0)
+ return DIVIDE_ZERO;
+ else if (v2 == -1)
+ /* Avoid overflow, and the x86 SIGFPE on INT_MIN / -1. */
+ *v1 = (int32_t) -(uint32_t) *v1;
+ else
+ *v1 /= v2;
+ break;
+
+ case MODULO:
+ if (v2 == 0)
+ return MODULO_ZERO;
+ else if (v2 == -1)
+ /* Avoid the x86 SIGFPE on INT_MIN % -1. */
+ *v1 = 0;
+ else
+ *v1 %= v2;
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad operator in mult_term ()"));
+ abort ();
+ }
+ }
+ if (op == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+exp_term (eval_token et, int32_t *v1)
+{
+ uint32_t result;
+ int32_t v2;
+ eval_error er;
+
+ if ((er = unary_term (et, v1)) != NO_ERROR)
+ return er;
+
+ while ((et = eval_lex (&v2)) == EXPONENT)
+ {
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = exp_term (et, &v2)) != NO_ERROR)
+ return er;
+
+ /* Minimize undefined C behavior on overflow. This code assumes
+ that the implementation-defined overflow when casting
+ unsigned to signed is a silent twos-complement
+ wrap-around. */
+ result = 1;
+ if (v2 < 0)
+ return NEGATIVE_EXPONENT;
+ if (*v1 == 0 && v2 == 0)
+ return DIVIDE_ZERO;
+ while (v2-- > 0)
+ result *= (uint32_t) *v1;
+ *v1 = result;
+ }
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ eval_undo ();
+ return NO_ERROR;
+}
+
+static eval_error
+unary_term (eval_token et, int32_t *v1)
+{
+ eval_error er;
+
+ if (et == PLUS || et == MINUS || et == NOT || et == LNOT)
+ {
+ eval_token et2 = eval_lex (v1);
+ if (et2 == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = unary_term (et2, v1)) != NO_ERROR)
+ return er;
+
+ /* Minimize undefined C behavior on overflow. This code assumes
+ that the implementation-defined overflow when casting
+ unsigned to signed is a silent twos-complement
+ wrap-around. */
+ if (et == MINUS)
+ *v1 = (int32_t) -(uint32_t) *v1;
+ else if (et == NOT)
+ *v1 = ~*v1;
+ else if (et == LNOT)
+ *v1 = *v1 == 0 ? 1 : 0;
+ }
+ else if ((er = simple_term (et, v1)) != NO_ERROR)
+ return er;
+
+ return NO_ERROR;
+}
+
+static eval_error
+simple_term (eval_token et, int32_t *v1)
+{
+ int32_t v2;
+ eval_error er;
+
+ switch (et)
+ {
+ case LEFTP:
+ et = eval_lex (v1);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if ((er = logical_or_term (et, v1)) != NO_ERROR)
+ return er;
+
+ et = eval_lex (&v2);
+ if (et == ERROR)
+ return UNKNOWN_INPUT;
+
+ if (et != RIGHTP)
+ return MISSING_RIGHT;
+
+ break;
+
+ case NUMBER:
+ break;
+
+ case BADOP:
+ return INVALID_OPERATOR;
+
+ default:
+ return SYNTAX_ERROR;
+ }
+ return NO_ERROR;
+}
diff --git a/contrib/tools/bison/m4/src/format.c b/contrib/tools/bison/m4/src/format.c
index fd8830ed7c..9114004f97 100644
--- a/contrib/tools/bison/m4/src/format.c
+++ b/contrib/tools/bison/m4/src/format.c
@@ -1,394 +1,394 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2006-2013 Free Software Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* printf like formatting for m4. */
-
-#include "m4.h"
-#include "xvasprintf.h"
-
-/* Simple varargs substitute. We assume int and unsigned int are the
- same size; likewise for long and unsigned long. */
-
-/* Parse STR as an integer, reporting warnings. */
-static int
-arg_int (const char *str)
-{
- char *endp;
- long value;
- size_t len = strlen (str);
-
- if (!len)
- {
- M4ERROR ((warning_status, 0, _("empty string treated as 0")));
- return 0;
- }
- errno = 0;
- value = strtol (str, &endp, 10);
- if (endp - str - len)
- M4ERROR ((warning_status, 0, _("non-numeric argument %s"), str));
- else if (isspace (to_uchar (*str)))
- M4ERROR ((warning_status, 0, _("leading whitespace ignored")));
- else if (errno == ERANGE || (int) value != value)
- M4ERROR ((warning_status, 0, _("numeric overflow detected")));
- return value;
-}
-
-/* Parse STR as a long, reporting warnings. */
-static long
-arg_long (const char *str)
-{
- char *endp;
- long value;
- size_t len = strlen (str);
-
- if (!len)
- {
- M4ERROR ((warning_status, 0, _("empty string treated as 0")));
- return 0L;
- }
- errno = 0;
- value = strtol (str, &endp, 10);
- if (endp - str - len)
- M4ERROR ((warning_status, 0, _("non-numeric argument %s"), str));
- else if (isspace (to_uchar (*str)))
- M4ERROR ((warning_status, 0, _("leading whitespace ignored")));
- else if (errno == ERANGE)
- M4ERROR ((warning_status, 0, _("numeric overflow detected")));
- return value;
-}
-
-/* Parse STR as a double, reporting warnings. */
-static double
-arg_double (const char *str)
-{
- char *endp;
- double value;
- size_t len = strlen (str);
-
- if (!len)
- {
- M4ERROR ((warning_status, 0, _("empty string treated as 0")));
- return 0.0;
- }
- errno = 0;
- value = strtod (str, &endp);
- if (endp - str - len)
- M4ERROR ((warning_status, 0, _("non-numeric argument %s"), str));
- else if (isspace (to_uchar (*str)))
- M4ERROR ((warning_status, 0, _("leading whitespace ignored")));
- else if (errno == ERANGE)
- M4ERROR ((warning_status, 0, _("numeric overflow detected")));
- return value;
-}
-
-#define ARG_INT(argc, argv) \
- ((argc == 0) ? 0 : \
- (--argc, argv++, arg_int (TOKEN_DATA_TEXT (argv[-1]))))
-
-#define ARG_LONG(argc, argv) \
- ((argc == 0) ? 0 : \
- (--argc, argv++, arg_long (TOKEN_DATA_TEXT (argv[-1]))))
-
-#define ARG_STR(argc, argv) \
- ((argc == 0) ? "" : \
- (--argc, argv++, TOKEN_DATA_TEXT (argv[-1])))
-
-#define ARG_DOUBLE(argc, argv) \
- ((argc == 0) ? 0 : \
- (--argc, argv++, arg_double (TOKEN_DATA_TEXT (argv[-1]))))
-
-
-/*------------------------------------------------------------------.
-| The main formatting function. Output is placed on the obstack |
-| OBS, the first argument in ARGV is the formatting string, and the |
-| rest is arguments for the string. Warn rather than invoke |
-| unspecified behavior in the underlying printf when we do not |
-| recognize a format. |
-`------------------------------------------------------------------*/
-
-void
-expand_format (struct obstack *obs, int argc, token_data **argv)
-{
- const char *f; /* format control string */
- const char *fmt; /* position within f */
- char fstart[] = "%'+- 0#*.*hhd"; /* current format spec */
- char *p; /* position within fstart */
- unsigned char c; /* a simple character */
-
- /* Flags. */
- char flags; /* flags to use in fstart */
- enum {
- THOUSANDS = 0x01, /* ' */
- PLUS = 0x02, /* + */
- MINUS = 0x04, /* - */
- SPACE = 0x08, /* */
- ZERO = 0x10, /* 0 */
- ALT = 0x20, /* # */
- DONE = 0x40 /* no more flags */
- };
-
- /* Precision specifiers. */
- int width; /* minimum field width */
- int prec; /* precision */
- char lflag; /* long flag */
-
- /* Specifiers we are willing to accept. ok['x'] implies %x is ok.
- Various modifiers reduce the set, in order to avoid undefined
- behavior in printf. */
- char ok[128];
-
- /* Buffer and stuff. */
- char *str; /* malloc'd buffer of formatted text */
- enum {CHAR, INT, LONG, DOUBLE, STR} datatype;
-
- f = fmt = ARG_STR (argc, argv);
- memset (ok, 0, sizeof ok);
- while (1)
- {
- const char *percent = strchr (fmt, '%');
- if (!percent)
- {
- obstack_grow (obs, fmt, strlen (fmt));
- return;
- }
- obstack_grow (obs, fmt, percent - fmt);
- fmt = percent + 1;
-
- if (*fmt == '%')
- {
- obstack_1grow (obs, '%');
- fmt++;
- continue;
- }
-
- p = fstart + 1; /* % */
- lflag = 0;
- ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E']
- = ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o']
- = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 1;
-
- /* Parse flags. */
- flags = 0;
- do
- {
- switch (*fmt)
- {
- case '\'': /* thousands separator */
- ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E']
- = ok['o'] = ok['s'] = ok['x'] = ok['X'] = 0;
- flags |= THOUSANDS;
- break;
-
- case '+': /* mandatory sign */
- ok['c'] = ok['o'] = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 0;
- flags |= PLUS;
- break;
-
- case ' ': /* space instead of positive sign */
- ok['c'] = ok['o'] = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 0;
- flags |= SPACE;
- break;
-
- case '0': /* zero padding */
- ok['c'] = ok['s'] = 0;
- flags |= ZERO;
- break;
-
- case '#': /* alternate output */
- ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = 0;
- flags |= ALT;
- break;
-
- case '-': /* left justification */
- flags |= MINUS;
- break;
-
- default:
- flags |= DONE;
- break;
- }
- }
- while (!(flags & DONE) && fmt++);
- if (flags & THOUSANDS)
- *p++ = '\'';
- if (flags & PLUS)
- *p++ = '+';
- if (flags & MINUS)
- *p++ = '-';
- if (flags & SPACE)
- *p++ = ' ';
- if (flags & ZERO)
- *p++ = '0';
- if (flags & ALT)
- *p++ = '#';
-
- /* Minimum field width; an explicit 0 is the same as not giving
- the width. */
- width = 0;
- *p++ = '*';
- if (*fmt == '*')
- {
- width = ARG_INT (argc, argv);
- fmt++;
- }
- else
- while (isdigit (to_uchar (*fmt)))
- {
- width = 10 * width + *fmt - '0';
- fmt++;
- }
-
- /* Maximum precision; an explicit negative precision is the same
- as not giving the precision. A lone '.' is a precision of 0. */
- prec = -1;
- *p++ = '.';
- *p++ = '*';
- if (*fmt == '.')
- {
- ok['c'] = 0;
- if (*(++fmt) == '*')
- {
- prec = ARG_INT (argc, argv);
- ++fmt;
- }
- else
- {
- prec = 0;
- while (isdigit (to_uchar (*fmt)))
- {
- prec = 10 * prec + *fmt - '0';
- fmt++;
- }
- }
- }
-
- /* Length modifiers. We don't yet recognize ll, j, t, or z. */
- if (*fmt == 'l')
- {
- *p++ = 'l';
- lflag = 1;
- fmt++;
- ok['c'] = ok['s'] = 0;
- }
- else if (*fmt == 'h')
- {
- *p++ = 'h';
- fmt++;
- if (*fmt == 'h')
- {
- *p++ = 'h';
- fmt++;
- }
- ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] = ok['f'] = ok['F']
- = ok['g'] = ok['G'] = ok['s'] = 0;
- }
-
- c = *fmt++;
- if (sizeof ok <= c || !ok[c])
- {
- M4ERROR ((warning_status, 0,
- "Warning: unrecognized specifier in `%s'", f));
- if (c == '\0')
- fmt--;
- continue;
- }
-
- /* Specifiers. We don't yet recognize C, S, n, or p. */
- switch (c)
- {
- case 'c':
- datatype = CHAR;
- p -= 2; /* %.*c is undefined, so undo the '.*'. */
- break;
-
- case 's':
- datatype = STR;
- break;
-
- case 'd':
- case 'i':
- case 'o':
- case 'x':
- case 'X':
- case 'u':
- datatype = lflag ? LONG : INT;
- break;
-
- case 'a':
- case 'A':
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- datatype = DOUBLE;
- break;
-
- default:
- abort ();
- }
- *p++ = c;
- *p = '\0';
-
- /* Our constructed format string in fstart is safe. */
-#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
-
- switch (datatype)
- {
- case CHAR:
- str = xasprintf (fstart, width, ARG_INT(argc, argv));
- break;
-
- case INT:
- str = xasprintf (fstart, width, prec, ARG_INT(argc, argv));
- break;
-
- case LONG:
- str = xasprintf (fstart, width, prec, ARG_LONG(argc, argv));
- break;
-
- case DOUBLE:
- str = xasprintf (fstart, width, prec, ARG_DOUBLE(argc, argv));
- break;
-
- case STR:
- str = xasprintf (fstart, width, prec, ARG_STR(argc, argv));
- break;
-
- default:
- abort();
- }
-#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
-# pragma GCC diagnostic pop
-#endif
-
- /* NULL was returned on failure, such as invalid format string. For
- now, just silently ignore that bad specifier. */
- if (str == NULL)
- continue;
-
- obstack_grow (obs, str, strlen (str));
- free (str);
- }
-}
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2006-2013 Free Software Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* printf like formatting for m4. */
+
+#include "m4.h"
+#include "xvasprintf.h"
+
+/* Simple varargs substitute. We assume int and unsigned int are the
+ same size; likewise for long and unsigned long. */
+
+/* Parse STR as an integer, reporting warnings. */
+static int
+arg_int (const char *str)
+{
+ char *endp;
+ long value;
+ size_t len = strlen (str);
+
+ if (!len)
+ {
+ M4ERROR ((warning_status, 0, _("empty string treated as 0")));
+ return 0;
+ }
+ errno = 0;
+ value = strtol (str, &endp, 10);
+ if (endp - str - len)
+ M4ERROR ((warning_status, 0, _("non-numeric argument %s"), str));
+ else if (isspace (to_uchar (*str)))
+ M4ERROR ((warning_status, 0, _("leading whitespace ignored")));
+ else if (errno == ERANGE || (int) value != value)
+ M4ERROR ((warning_status, 0, _("numeric overflow detected")));
+ return value;
+}
+
+/* Parse STR as a long, reporting warnings. */
+static long
+arg_long (const char *str)
+{
+ char *endp;
+ long value;
+ size_t len = strlen (str);
+
+ if (!len)
+ {
+ M4ERROR ((warning_status, 0, _("empty string treated as 0")));
+ return 0L;
+ }
+ errno = 0;
+ value = strtol (str, &endp, 10);
+ if (endp - str - len)
+ M4ERROR ((warning_status, 0, _("non-numeric argument %s"), str));
+ else if (isspace (to_uchar (*str)))
+ M4ERROR ((warning_status, 0, _("leading whitespace ignored")));
+ else if (errno == ERANGE)
+ M4ERROR ((warning_status, 0, _("numeric overflow detected")));
+ return value;
+}
+
+/* Parse STR as a double, reporting warnings. */
+static double
+arg_double (const char *str)
+{
+ char *endp;
+ double value;
+ size_t len = strlen (str);
+
+ if (!len)
+ {
+ M4ERROR ((warning_status, 0, _("empty string treated as 0")));
+ return 0.0;
+ }
+ errno = 0;
+ value = strtod (str, &endp);
+ if (endp - str - len)
+ M4ERROR ((warning_status, 0, _("non-numeric argument %s"), str));
+ else if (isspace (to_uchar (*str)))
+ M4ERROR ((warning_status, 0, _("leading whitespace ignored")));
+ else if (errno == ERANGE)
+ M4ERROR ((warning_status, 0, _("numeric overflow detected")));
+ return value;
+}
+
+#define ARG_INT(argc, argv) \
+ ((argc == 0) ? 0 : \
+ (--argc, argv++, arg_int (TOKEN_DATA_TEXT (argv[-1]))))
+
+#define ARG_LONG(argc, argv) \
+ ((argc == 0) ? 0 : \
+ (--argc, argv++, arg_long (TOKEN_DATA_TEXT (argv[-1]))))
+
+#define ARG_STR(argc, argv) \
+ ((argc == 0) ? "" : \
+ (--argc, argv++, TOKEN_DATA_TEXT (argv[-1])))
+
+#define ARG_DOUBLE(argc, argv) \
+ ((argc == 0) ? 0 : \
+ (--argc, argv++, arg_double (TOKEN_DATA_TEXT (argv[-1]))))
+
+
+/*------------------------------------------------------------------.
+| The main formatting function. Output is placed on the obstack |
+| OBS, the first argument in ARGV is the formatting string, and the |
+| rest is arguments for the string. Warn rather than invoke |
+| unspecified behavior in the underlying printf when we do not |
+| recognize a format. |
+`------------------------------------------------------------------*/
+
+void
+expand_format (struct obstack *obs, int argc, token_data **argv)
+{
+ const char *f; /* format control string */
+ const char *fmt; /* position within f */
+ char fstart[] = "%'+- 0#*.*hhd"; /* current format spec */
+ char *p; /* position within fstart */
+ unsigned char c; /* a simple character */
+
+ /* Flags. */
+ char flags; /* flags to use in fstart */
+ enum {
+ THOUSANDS = 0x01, /* ' */
+ PLUS = 0x02, /* + */
+ MINUS = 0x04, /* - */
+ SPACE = 0x08, /* */
+ ZERO = 0x10, /* 0 */
+ ALT = 0x20, /* # */
+ DONE = 0x40 /* no more flags */
+ };
+
+ /* Precision specifiers. */
+ int width; /* minimum field width */
+ int prec; /* precision */
+ char lflag; /* long flag */
+
+ /* Specifiers we are willing to accept. ok['x'] implies %x is ok.
+ Various modifiers reduce the set, in order to avoid undefined
+ behavior in printf. */
+ char ok[128];
+
+ /* Buffer and stuff. */
+ char *str; /* malloc'd buffer of formatted text */
+ enum {CHAR, INT, LONG, DOUBLE, STR} datatype;
+
+ f = fmt = ARG_STR (argc, argv);
+ memset (ok, 0, sizeof ok);
+ while (1)
+ {
+ const char *percent = strchr (fmt, '%');
+ if (!percent)
+ {
+ obstack_grow (obs, fmt, strlen (fmt));
+ return;
+ }
+ obstack_grow (obs, fmt, percent - fmt);
+ fmt = percent + 1;
+
+ if (*fmt == '%')
+ {
+ obstack_1grow (obs, '%');
+ fmt++;
+ continue;
+ }
+
+ p = fstart + 1; /* % */
+ lflag = 0;
+ ok['a'] = ok['A'] = ok['c'] = ok['d'] = ok['e'] = ok['E']
+ = ok['f'] = ok['F'] = ok['g'] = ok['G'] = ok['i'] = ok['o']
+ = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 1;
+
+ /* Parse flags. */
+ flags = 0;
+ do
+ {
+ switch (*fmt)
+ {
+ case '\'': /* thousands separator */
+ ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E']
+ = ok['o'] = ok['s'] = ok['x'] = ok['X'] = 0;
+ flags |= THOUSANDS;
+ break;
+
+ case '+': /* mandatory sign */
+ ok['c'] = ok['o'] = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 0;
+ flags |= PLUS;
+ break;
+
+ case ' ': /* space instead of positive sign */
+ ok['c'] = ok['o'] = ok['s'] = ok['u'] = ok['x'] = ok['X'] = 0;
+ flags |= SPACE;
+ break;
+
+ case '0': /* zero padding */
+ ok['c'] = ok['s'] = 0;
+ flags |= ZERO;
+ break;
+
+ case '#': /* alternate output */
+ ok['c'] = ok['d'] = ok['i'] = ok['s'] = ok['u'] = 0;
+ flags |= ALT;
+ break;
+
+ case '-': /* left justification */
+ flags |= MINUS;
+ break;
+
+ default:
+ flags |= DONE;
+ break;
+ }
+ }
+ while (!(flags & DONE) && fmt++);
+ if (flags & THOUSANDS)
+ *p++ = '\'';
+ if (flags & PLUS)
+ *p++ = '+';
+ if (flags & MINUS)
+ *p++ = '-';
+ if (flags & SPACE)
+ *p++ = ' ';
+ if (flags & ZERO)
+ *p++ = '0';
+ if (flags & ALT)
+ *p++ = '#';
+
+ /* Minimum field width; an explicit 0 is the same as not giving
+ the width. */
+ width = 0;
+ *p++ = '*';
+ if (*fmt == '*')
+ {
+ width = ARG_INT (argc, argv);
+ fmt++;
+ }
+ else
+ while (isdigit (to_uchar (*fmt)))
+ {
+ width = 10 * width + *fmt - '0';
+ fmt++;
+ }
+
+ /* Maximum precision; an explicit negative precision is the same
+ as not giving the precision. A lone '.' is a precision of 0. */
+ prec = -1;
+ *p++ = '.';
+ *p++ = '*';
+ if (*fmt == '.')
+ {
+ ok['c'] = 0;
+ if (*(++fmt) == '*')
+ {
+ prec = ARG_INT (argc, argv);
+ ++fmt;
+ }
+ else
+ {
+ prec = 0;
+ while (isdigit (to_uchar (*fmt)))
+ {
+ prec = 10 * prec + *fmt - '0';
+ fmt++;
+ }
+ }
+ }
+
+ /* Length modifiers. We don't yet recognize ll, j, t, or z. */
+ if (*fmt == 'l')
+ {
+ *p++ = 'l';
+ lflag = 1;
+ fmt++;
+ ok['c'] = ok['s'] = 0;
+ }
+ else if (*fmt == 'h')
+ {
+ *p++ = 'h';
+ fmt++;
+ if (*fmt == 'h')
+ {
+ *p++ = 'h';
+ fmt++;
+ }
+ ok['a'] = ok['A'] = ok['c'] = ok['e'] = ok['E'] = ok['f'] = ok['F']
+ = ok['g'] = ok['G'] = ok['s'] = 0;
+ }
+
+ c = *fmt++;
+ if (sizeof ok <= c || !ok[c])
+ {
+ M4ERROR ((warning_status, 0,
+ "Warning: unrecognized specifier in `%s'", f));
+ if (c == '\0')
+ fmt--;
+ continue;
+ }
+
+ /* Specifiers. We don't yet recognize C, S, n, or p. */
+ switch (c)
+ {
+ case 'c':
+ datatype = CHAR;
+ p -= 2; /* %.*c is undefined, so undo the '.*'. */
+ break;
+
+ case 's':
+ datatype = STR;
+ break;
+
+ case 'd':
+ case 'i':
+ case 'o':
+ case 'x':
+ case 'X':
+ case 'u':
+ datatype = lflag ? LONG : INT;
+ break;
+
+ case 'a':
+ case 'A':
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'F':
+ case 'g':
+ case 'G':
+ datatype = DOUBLE;
+ break;
+
+ default:
+ abort ();
+ }
+ *p++ = c;
+ *p = '\0';
+
+ /* Our constructed format string in fstart is safe. */
+#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
+
+ switch (datatype)
+ {
+ case CHAR:
+ str = xasprintf (fstart, width, ARG_INT(argc, argv));
+ break;
+
+ case INT:
+ str = xasprintf (fstart, width, prec, ARG_INT(argc, argv));
+ break;
+
+ case LONG:
+ str = xasprintf (fstart, width, prec, ARG_LONG(argc, argv));
+ break;
+
+ case DOUBLE:
+ str = xasprintf (fstart, width, prec, ARG_DOUBLE(argc, argv));
+ break;
+
+ case STR:
+ str = xasprintf (fstart, width, prec, ARG_STR(argc, argv));
+ break;
+
+ default:
+ abort();
+ }
+#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
+# pragma GCC diagnostic pop
+#endif
+
+ /* NULL was returned on failure, such as invalid format string. For
+ now, just silently ignore that bad specifier. */
+ if (str == NULL)
+ continue;
+
+ obstack_grow (obs, str, strlen (str));
+ free (str);
+ }
+}
diff --git a/contrib/tools/bison/m4/src/freeze.c b/contrib/tools/bison/m4/src/freeze.c
index edc0568b96..7016be4eae 100644
--- a/contrib/tools/bison/m4/src/freeze.c
+++ b/contrib/tools/bison/m4/src/freeze.c
@@ -1,398 +1,398 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2006-2013 Free Software Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* This module handles frozen files. */
-
-#include "m4.h"
-
-/*-------------------------------------------------------------------.
-| Destructively reverse a symbol list and return the reversed list. |
-`-------------------------------------------------------------------*/
-
-static symbol *
-reverse_symbol_list (symbol *sym)
-{
- symbol *result;
- symbol *next;
-
- result = NULL;
- while (sym)
- {
- next = SYMBOL_NEXT (sym);
- SYMBOL_NEXT (sym) = result;
- result = sym;
- sym = next;
- }
- return result;
-}
-
-/*------------------------------------------------.
-| Produce a frozen state to the given file NAME. |
-`------------------------------------------------*/
-
-void
-produce_frozen_state (const char *name)
-{
- FILE *file;
- size_t h;
- symbol *sym;
- const builtin *bp;
-
- file = fopen (name, O_BINARY ? "wb" : "w");
- if (!file)
- {
- M4ERROR ((EXIT_FAILURE, errno, "cannot open `%s'", name));
- return;
- }
-
- /* Write a recognizable header. */
-
- xfprintf (file, "# This is a frozen state file generated by %s\n",
- PACKAGE_STRING);
- xfprintf (file, "V1\n");
-
- /* Dump quote delimiters. */
-
- if (strcmp (lquote.string, DEF_LQUOTE) || strcmp (rquote.string, DEF_RQUOTE))
- {
- xfprintf (file, "Q%d,%d\n", (int) lquote.length, (int) rquote.length);
- fputs (lquote.string, file);
- fputs (rquote.string, file);
- fputc ('\n', file);
- }
-
- /* Dump comment delimiters. */
-
- if (strcmp (bcomm.string, DEF_BCOMM) || strcmp (ecomm.string, DEF_ECOMM))
- {
- xfprintf (file, "C%d,%d\n", (int) bcomm.length, (int) ecomm.length);
- fputs (bcomm.string, file);
- fputs (ecomm.string, file);
- fputc ('\n', file);
- }
-
- /* Dump all symbols. */
-
- for (h = 0; h < hash_table_size; h++)
- {
-
- /* Process all entries in one bucket, from the last to the first.
- This order ensures that, at reload time, pushdef's will be
- executed with the oldest definitions first. */
-
- symtab[h] = reverse_symbol_list (symtab[h]);
- for (sym = symtab[h]; sym; sym = SYMBOL_NEXT (sym))
- {
- switch (SYMBOL_TYPE (sym))
- {
- case TOKEN_TEXT:
- xfprintf (file, "T%d,%d\n",
- (int) strlen (SYMBOL_NAME (sym)),
- (int) strlen (SYMBOL_TEXT (sym)));
- fputs (SYMBOL_NAME (sym), file);
- fputs (SYMBOL_TEXT (sym), file);
- fputc ('\n', file);
- break;
-
- case TOKEN_FUNC:
- bp = find_builtin_by_addr (SYMBOL_FUNC (sym));
- if (bp == NULL)
- {
- M4ERROR ((warning_status, 0, "\
-INTERNAL ERROR: builtin not found in builtin table!"));
- abort ();
- }
- xfprintf (file, "F%d,%d\n",
- (int) strlen (SYMBOL_NAME (sym)),
- (int) strlen (bp->name));
- fputs (SYMBOL_NAME (sym), file);
- fputs (bp->name, file);
- fputc ('\n', file);
- break;
-
- case TOKEN_VOID:
- /* Ignore placeholder tokens that exist due to traceon. */
- break;
-
- default:
- M4ERROR ((warning_status, 0, "\
-INTERNAL ERROR: bad token data type in freeze_one_symbol ()"));
- abort ();
- break;
- }
- }
-
- /* Reverse the bucket once more, putting it back as it was. */
-
- symtab[h] = reverse_symbol_list (symtab[h]);
- }
-
- /* Let diversions be issued from output.c module, its cleaner to have this
- piece of code there. */
-
- freeze_diversions (file);
-
- /* All done. */
-
- fputs ("# End of frozen state file\n", file);
- if (close_stream (file) != 0)
- M4ERROR ((EXIT_FAILURE, errno, "unable to create frozen state"));
-}
-
-/*----------------------------------------------------------------------.
-| Issue a message saying that some character is an EXPECTED character. |
-`----------------------------------------------------------------------*/
-
-static void
-issue_expect_message (int expected)
-{
- if (expected == '\n')
- M4ERROR ((EXIT_FAILURE, 0, "expecting line feed in frozen file"));
- else
- M4ERROR ((EXIT_FAILURE, 0, "expecting character `%c' in frozen file",
- expected));
-}
-
-/*-------------------------------------------------.
-| Reload a frozen state from the given file NAME. |
-`-------------------------------------------------*/
-
-/* We are seeking speed, here. */
-
-void
-reload_frozen_state (const char *name)
-{
- FILE *file;
- int character;
- int operation;
- char *string[2];
- int allocated[2];
- int number[2];
- const builtin *bp;
- bool advance_line = true;
-
-#define GET_CHARACTER \
- do \
- { \
- if (advance_line) \
- { \
- current_line++; \
- advance_line = false; \
- } \
- (character = getc (file)); \
- if (character == '\n') \
- advance_line = true; \
- } \
- while (0)
-
-#define GET_NUMBER(Number, AllowNeg) \
- do \
- { \
- unsigned int n = 0; \
- while (isdigit (character) && n <= INT_MAX / 10U) \
- { \
- n = 10 * n + character - '0'; \
- GET_CHARACTER; \
- } \
- if (((AllowNeg) ? INT_MIN : INT_MAX) + 0U < n \
- || isdigit (character)) \
- m4_error (EXIT_FAILURE, 0, \
- _("integer overflow in frozen file")); \
- (Number) = n; \
- } \
- while (0)
-
-#define VALIDATE(Expected) \
- do \
- { \
- if (character != (Expected)) \
- issue_expect_message (Expected); \
- } \
- while (0)
-
- /* Skip comments (`#' at beginning of line) and blank lines, setting
- character to the next directive or to EOF. */
-
-#define GET_DIRECTIVE \
- do \
- { \
- GET_CHARACTER; \
- if (character == '#') \
- { \
- while (character != EOF && character != '\n') \
- GET_CHARACTER; \
- VALIDATE ('\n'); \
- } \
- } \
- while (character == '\n')
-
-#define GET_STRING(i) \
- do \
- { \
- void *tmp; \
- char *p; \
- if (number[(i)] + 1 > allocated[(i)]) \
- { \
- free (string[(i)]); \
- allocated[(i)] = number[(i)] + 1; \
- string[(i)] = xcharalloc ((size_t) allocated[(i)]); \
- } \
- if (number[(i)] > 0 \
- && !fread (string[(i)], (size_t) number[(i)], 1, file)) \
- m4_error (EXIT_FAILURE, 0, \
- _("premature end of frozen file")); \
- string[(i)][number[(i)]] = '\0'; \
- p = string[(i)]; \
- while ((tmp = memchr(p, '\n', number[(i)] - (p - string[(i)])))) \
- { \
- current_line++; \
- p = (char *) tmp + 1; \
- } \
- } \
- while (0)
-
- file = m4_path_search (name, NULL);
- if (file == NULL)
- M4ERROR ((EXIT_FAILURE, errno, "cannot open %s", name));
- current_file = name;
-
- allocated[0] = 100;
- string[0] = xcharalloc ((size_t) allocated[0]);
- allocated[1] = 100;
- string[1] = xcharalloc ((size_t) allocated[1]);
-
- /* Validate format version. Only `1' is acceptable for now. */
- GET_DIRECTIVE;
- VALIDATE ('V');
- GET_CHARACTER;
- GET_NUMBER (number[0], false);
- if (number[0] > 1)
- M4ERROR ((EXIT_MISMATCH, 0,
- "frozen file version %d greater than max supported of 1",
- number[0]));
- else if (number[0] < 1)
- M4ERROR ((EXIT_FAILURE, 0,
- "ill-formed frozen file, version directive expected"));
- VALIDATE ('\n');
-
- GET_DIRECTIVE;
- while (character != EOF)
- {
- switch (character)
- {
- default:
- M4ERROR ((EXIT_FAILURE, 0, "ill-formed frozen file"));
-
- case 'C':
- case 'D':
- case 'F':
- case 'T':
- case 'Q':
- operation = character;
- GET_CHARACTER;
-
- /* Get string lengths. Accept a negative diversion number. */
-
- if (operation == 'D' && character == '-')
- {
- GET_CHARACTER;
- GET_NUMBER (number[0], true);
- number[0] = -number[0];
- }
- else
- GET_NUMBER (number[0], false);
- VALIDATE (',');
- GET_CHARACTER;
- GET_NUMBER (number[1], false);
- VALIDATE ('\n');
-
- if (operation != 'D')
- GET_STRING (0);
- GET_STRING (1);
- GET_CHARACTER;
- VALIDATE ('\n');
-
- /* Act according to operation letter. */
-
- switch (operation)
- {
- case 'C':
-
- /* Change comment strings. */
-
- set_comment (string[0], string[1]);
- break;
-
- case 'D':
-
- /* Select a diversion and add a string to it. */
-
- make_diversion (number[0]);
- if (number[1] > 0)
- output_text (string[1], number[1]);
- break;
-
- case 'F':
-
- /* Enter a macro having a builtin function as a definition. */
-
- bp = find_builtin_by_name (string[1]);
- define_builtin (string[0], bp, SYMBOL_PUSHDEF);
- break;
-
- case 'T':
-
- /* Enter a macro having an expansion text as a definition. */
-
- define_user_macro (string[0], string[1], SYMBOL_PUSHDEF);
- break;
-
- case 'Q':
-
- /* Change quote strings. */
-
- set_quotes (string[0], string[1]);
- break;
-
- default:
-
- /* Cannot happen. */
-
- break;
- }
- break;
-
- }
- GET_DIRECTIVE;
- }
-
- free (string[0]);
- free (string[1]);
- if (close_stream (file) != 0)
- m4_error (EXIT_FAILURE, errno, _("unable to read frozen state"));
- current_file = NULL;
- current_line = 0;
-
-#undef GET_CHARACTER
-#undef GET_DIRECTIVE
-#undef GET_NUMBER
-#undef VALIDATE
-#undef GET_STRING
-}
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2006-2013 Free Software Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* This module handles frozen files. */
+
+#include "m4.h"
+
+/*-------------------------------------------------------------------.
+| Destructively reverse a symbol list and return the reversed list. |
+`-------------------------------------------------------------------*/
+
+static symbol *
+reverse_symbol_list (symbol *sym)
+{
+ symbol *result;
+ symbol *next;
+
+ result = NULL;
+ while (sym)
+ {
+ next = SYMBOL_NEXT (sym);
+ SYMBOL_NEXT (sym) = result;
+ result = sym;
+ sym = next;
+ }
+ return result;
+}
+
+/*------------------------------------------------.
+| Produce a frozen state to the given file NAME. |
+`------------------------------------------------*/
+
+void
+produce_frozen_state (const char *name)
+{
+ FILE *file;
+ size_t h;
+ symbol *sym;
+ const builtin *bp;
+
+ file = fopen (name, O_BINARY ? "wb" : "w");
+ if (!file)
+ {
+ M4ERROR ((EXIT_FAILURE, errno, "cannot open `%s'", name));
+ return;
+ }
+
+ /* Write a recognizable header. */
+
+ xfprintf (file, "# This is a frozen state file generated by %s\n",
+ PACKAGE_STRING);
+ xfprintf (file, "V1\n");
+
+ /* Dump quote delimiters. */
+
+ if (strcmp (lquote.string, DEF_LQUOTE) || strcmp (rquote.string, DEF_RQUOTE))
+ {
+ xfprintf (file, "Q%d,%d\n", (int) lquote.length, (int) rquote.length);
+ fputs (lquote.string, file);
+ fputs (rquote.string, file);
+ fputc ('\n', file);
+ }
+
+ /* Dump comment delimiters. */
+
+ if (strcmp (bcomm.string, DEF_BCOMM) || strcmp (ecomm.string, DEF_ECOMM))
+ {
+ xfprintf (file, "C%d,%d\n", (int) bcomm.length, (int) ecomm.length);
+ fputs (bcomm.string, file);
+ fputs (ecomm.string, file);
+ fputc ('\n', file);
+ }
+
+ /* Dump all symbols. */
+
+ for (h = 0; h < hash_table_size; h++)
+ {
+
+ /* Process all entries in one bucket, from the last to the first.
+ This order ensures that, at reload time, pushdef's will be
+ executed with the oldest definitions first. */
+
+ symtab[h] = reverse_symbol_list (symtab[h]);
+ for (sym = symtab[h]; sym; sym = SYMBOL_NEXT (sym))
+ {
+ switch (SYMBOL_TYPE (sym))
+ {
+ case TOKEN_TEXT:
+ xfprintf (file, "T%d,%d\n",
+ (int) strlen (SYMBOL_NAME (sym)),
+ (int) strlen (SYMBOL_TEXT (sym)));
+ fputs (SYMBOL_NAME (sym), file);
+ fputs (SYMBOL_TEXT (sym), file);
+ fputc ('\n', file);
+ break;
+
+ case TOKEN_FUNC:
+ bp = find_builtin_by_addr (SYMBOL_FUNC (sym));
+ if (bp == NULL)
+ {
+ M4ERROR ((warning_status, 0, "\
+INTERNAL ERROR: builtin not found in builtin table!"));
+ abort ();
+ }
+ xfprintf (file, "F%d,%d\n",
+ (int) strlen (SYMBOL_NAME (sym)),
+ (int) strlen (bp->name));
+ fputs (SYMBOL_NAME (sym), file);
+ fputs (bp->name, file);
+ fputc ('\n', file);
+ break;
+
+ case TOKEN_VOID:
+ /* Ignore placeholder tokens that exist due to traceon. */
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0, "\
+INTERNAL ERROR: bad token data type in freeze_one_symbol ()"));
+ abort ();
+ break;
+ }
+ }
+
+ /* Reverse the bucket once more, putting it back as it was. */
+
+ symtab[h] = reverse_symbol_list (symtab[h]);
+ }
+
+ /* Let diversions be issued from output.c module, its cleaner to have this
+ piece of code there. */
+
+ freeze_diversions (file);
+
+ /* All done. */
+
+ fputs ("# End of frozen state file\n", file);
+ if (close_stream (file) != 0)
+ M4ERROR ((EXIT_FAILURE, errno, "unable to create frozen state"));
+}
+
+/*----------------------------------------------------------------------.
+| Issue a message saying that some character is an EXPECTED character. |
+`----------------------------------------------------------------------*/
+
+static void
+issue_expect_message (int expected)
+{
+ if (expected == '\n')
+ M4ERROR ((EXIT_FAILURE, 0, "expecting line feed in frozen file"));
+ else
+ M4ERROR ((EXIT_FAILURE, 0, "expecting character `%c' in frozen file",
+ expected));
+}
+
+/*-------------------------------------------------.
+| Reload a frozen state from the given file NAME. |
+`-------------------------------------------------*/
+
+/* We are seeking speed, here. */
+
+void
+reload_frozen_state (const char *name)
+{
+ FILE *file;
+ int character;
+ int operation;
+ char *string[2];
+ int allocated[2];
+ int number[2];
+ const builtin *bp;
+ bool advance_line = true;
+
+#define GET_CHARACTER \
+ do \
+ { \
+ if (advance_line) \
+ { \
+ current_line++; \
+ advance_line = false; \
+ } \
+ (character = getc (file)); \
+ if (character == '\n') \
+ advance_line = true; \
+ } \
+ while (0)
+
+#define GET_NUMBER(Number, AllowNeg) \
+ do \
+ { \
+ unsigned int n = 0; \
+ while (isdigit (character) && n <= INT_MAX / 10U) \
+ { \
+ n = 10 * n + character - '0'; \
+ GET_CHARACTER; \
+ } \
+ if (((AllowNeg) ? INT_MIN : INT_MAX) + 0U < n \
+ || isdigit (character)) \
+ m4_error (EXIT_FAILURE, 0, \
+ _("integer overflow in frozen file")); \
+ (Number) = n; \
+ } \
+ while (0)
+
+#define VALIDATE(Expected) \
+ do \
+ { \
+ if (character != (Expected)) \
+ issue_expect_message (Expected); \
+ } \
+ while (0)
+
+ /* Skip comments (`#' at beginning of line) and blank lines, setting
+ character to the next directive or to EOF. */
+
+#define GET_DIRECTIVE \
+ do \
+ { \
+ GET_CHARACTER; \
+ if (character == '#') \
+ { \
+ while (character != EOF && character != '\n') \
+ GET_CHARACTER; \
+ VALIDATE ('\n'); \
+ } \
+ } \
+ while (character == '\n')
+
+#define GET_STRING(i) \
+ do \
+ { \
+ void *tmp; \
+ char *p; \
+ if (number[(i)] + 1 > allocated[(i)]) \
+ { \
+ free (string[(i)]); \
+ allocated[(i)] = number[(i)] + 1; \
+ string[(i)] = xcharalloc ((size_t) allocated[(i)]); \
+ } \
+ if (number[(i)] > 0 \
+ && !fread (string[(i)], (size_t) number[(i)], 1, file)) \
+ m4_error (EXIT_FAILURE, 0, \
+ _("premature end of frozen file")); \
+ string[(i)][number[(i)]] = '\0'; \
+ p = string[(i)]; \
+ while ((tmp = memchr(p, '\n', number[(i)] - (p - string[(i)])))) \
+ { \
+ current_line++; \
+ p = (char *) tmp + 1; \
+ } \
+ } \
+ while (0)
+
+ file = m4_path_search (name, NULL);
+ if (file == NULL)
+ M4ERROR ((EXIT_FAILURE, errno, "cannot open %s", name));
+ current_file = name;
+
+ allocated[0] = 100;
+ string[0] = xcharalloc ((size_t) allocated[0]);
+ allocated[1] = 100;
+ string[1] = xcharalloc ((size_t) allocated[1]);
+
+ /* Validate format version. Only `1' is acceptable for now. */
+ GET_DIRECTIVE;
+ VALIDATE ('V');
+ GET_CHARACTER;
+ GET_NUMBER (number[0], false);
+ if (number[0] > 1)
+ M4ERROR ((EXIT_MISMATCH, 0,
+ "frozen file version %d greater than max supported of 1",
+ number[0]));
+ else if (number[0] < 1)
+ M4ERROR ((EXIT_FAILURE, 0,
+ "ill-formed frozen file, version directive expected"));
+ VALIDATE ('\n');
+
+ GET_DIRECTIVE;
+ while (character != EOF)
+ {
+ switch (character)
+ {
+ default:
+ M4ERROR ((EXIT_FAILURE, 0, "ill-formed frozen file"));
+
+ case 'C':
+ case 'D':
+ case 'F':
+ case 'T':
+ case 'Q':
+ operation = character;
+ GET_CHARACTER;
+
+ /* Get string lengths. Accept a negative diversion number. */
+
+ if (operation == 'D' && character == '-')
+ {
+ GET_CHARACTER;
+ GET_NUMBER (number[0], true);
+ number[0] = -number[0];
+ }
+ else
+ GET_NUMBER (number[0], false);
+ VALIDATE (',');
+ GET_CHARACTER;
+ GET_NUMBER (number[1], false);
+ VALIDATE ('\n');
+
+ if (operation != 'D')
+ GET_STRING (0);
+ GET_STRING (1);
+ GET_CHARACTER;
+ VALIDATE ('\n');
+
+ /* Act according to operation letter. */
+
+ switch (operation)
+ {
+ case 'C':
+
+ /* Change comment strings. */
+
+ set_comment (string[0], string[1]);
+ break;
+
+ case 'D':
+
+ /* Select a diversion and add a string to it. */
+
+ make_diversion (number[0]);
+ if (number[1] > 0)
+ output_text (string[1], number[1]);
+ break;
+
+ case 'F':
+
+ /* Enter a macro having a builtin function as a definition. */
+
+ bp = find_builtin_by_name (string[1]);
+ define_builtin (string[0], bp, SYMBOL_PUSHDEF);
+ break;
+
+ case 'T':
+
+ /* Enter a macro having an expansion text as a definition. */
+
+ define_user_macro (string[0], string[1], SYMBOL_PUSHDEF);
+ break;
+
+ case 'Q':
+
+ /* Change quote strings. */
+
+ set_quotes (string[0], string[1]);
+ break;
+
+ default:
+
+ /* Cannot happen. */
+
+ break;
+ }
+ break;
+
+ }
+ GET_DIRECTIVE;
+ }
+
+ free (string[0]);
+ free (string[1]);
+ if (close_stream (file) != 0)
+ m4_error (EXIT_FAILURE, errno, _("unable to read frozen state"));
+ current_file = NULL;
+ current_line = 0;
+
+#undef GET_CHARACTER
+#undef GET_DIRECTIVE
+#undef GET_NUMBER
+#undef VALIDATE
+#undef GET_STRING
+}
diff --git a/contrib/tools/bison/m4/src/input.c b/contrib/tools/bison/m4/src/input.c
index 836d706489..5c8d3c835f 100644
--- a/contrib/tools/bison/m4/src/input.c
+++ b/contrib/tools/bison/m4/src/input.c
@@ -1,1156 +1,1156 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* Handling of different input sources, and lexical analysis. */
-
-#include "m4.h"
-
-#include "memchr2.h"
-
-/* Unread input can be either files, that should be read (eg. included
- files), strings, which should be rescanned (eg. macro expansion text),
- or quoted macro definitions (as returned by the builtin "defn").
- Unread input are organised in a stack, implemented with an obstack.
- Each input source is described by a "struct input_block". The obstack
- is "current_input". The top of the input stack is "isp".
-
- The macro "m4wrap" places the text to be saved on another input
- stack, on the obstack "wrapup_stack", whose top is "wsp". When EOF
- is seen on normal input (eg, when "current_input" is empty), input is
- switched over to "wrapup_stack", and the original "current_input" is
- freed. A new stack is allocated for "wrapup_stack", which will
- accept any text produced by calls to "m4wrap" from within the
- wrapped text. This process of shuffling "wrapup_stack" to
- "current_input" can continue indefinitely, even generating infinite
- loops (e.g. "define(`f',`m4wrap(`f')')f"), without memory leaks.
-
- Pushing new input on the input stack is done by push_file (),
- push_string (), push_wrapup () (for wrapup text), and push_macro ()
- (for macro definitions). Because macro expansion needs direct access
- to the current input obstack (for optimisation), push_string () are
- split in two functions, push_string_init (), which returns a pointer
- to the current input stack, and push_string_finish (), which return a
- pointer to the final text. The input_block *next is used to manage
- the coordination between the different push routines.
-
- The current file and line number are stored in two global
- variables, for use by the error handling functions in m4.c. Macro
- expansion wants to report the line where a macro name was detected,
- rather than where it finished collecting arguments. This also
- applies to text resulting from macro expansions. So each input
- block maintains its own notion of the current file and line, and
- swapping between input blocks updates the global variables
- accordingly. */
-
-#ifdef ENABLE_CHANGEWORD
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Handling of different input sources, and lexical analysis. */
+
+#include "m4.h"
+
+#include "memchr2.h"
+
+/* Unread input can be either files, that should be read (eg. included
+ files), strings, which should be rescanned (eg. macro expansion text),
+ or quoted macro definitions (as returned by the builtin "defn").
+ Unread input are organised in a stack, implemented with an obstack.
+ Each input source is described by a "struct input_block". The obstack
+ is "current_input". The top of the input stack is "isp".
+
+ The macro "m4wrap" places the text to be saved on another input
+ stack, on the obstack "wrapup_stack", whose top is "wsp". When EOF
+ is seen on normal input (eg, when "current_input" is empty), input is
+ switched over to "wrapup_stack", and the original "current_input" is
+ freed. A new stack is allocated for "wrapup_stack", which will
+ accept any text produced by calls to "m4wrap" from within the
+ wrapped text. This process of shuffling "wrapup_stack" to
+ "current_input" can continue indefinitely, even generating infinite
+ loops (e.g. "define(`f',`m4wrap(`f')')f"), without memory leaks.
+
+ Pushing new input on the input stack is done by push_file (),
+ push_string (), push_wrapup () (for wrapup text), and push_macro ()
+ (for macro definitions). Because macro expansion needs direct access
+ to the current input obstack (for optimisation), push_string () are
+ split in two functions, push_string_init (), which returns a pointer
+ to the current input stack, and push_string_finish (), which return a
+ pointer to the final text. The input_block *next is used to manage
+ the coordination between the different push routines.
+
+ The current file and line number are stored in two global
+ variables, for use by the error handling functions in m4.c. Macro
+ expansion wants to report the line where a macro name was detected,
+ rather than where it finished collecting arguments. This also
+ applies to text resulting from macro expansions. So each input
+ block maintains its own notion of the current file and line, and
+ swapping between input blocks updates the global variables
+ accordingly. */
+
+#ifdef ENABLE_CHANGEWORD
#include <contrib/tools/bison/gnulib/src/regex.h>
-#endif
-
-enum input_type
-{
- INPUT_STRING, /* String resulting from macro expansion. */
- INPUT_FILE, /* File from command line or include. */
- INPUT_MACRO /* Builtin resulting from defn. */
-};
-
-typedef enum input_type input_type;
-
-struct input_block
-{
- struct input_block *prev; /* previous input_block on the input stack */
- input_type type; /* see enum values */
- const char *file; /* file where this input is from */
- int line; /* line where this input is from */
- union
- {
- struct
- {
- char *string; /* remaining string value */
- char *end; /* terminating NUL of string */
- }
- u_s; /* INPUT_STRING */
- struct
- {
- FILE *fp; /* input file handle */
- bool_bitfield end : 1; /* true if peek has seen EOF */
- bool_bitfield close : 1; /* true if we should close file on pop */
- bool_bitfield advance : 1; /* track previous start_of_input_line */
- }
- u_f; /* INPUT_FILE */
- builtin_func *func; /* pointer to macro's function */
- }
- u;
-};
-
-typedef struct input_block input_block;
-
-
-/* Current input file name. */
-const char *current_file;
-
-/* Current input line number. */
-int current_line;
-
-/* Obstack for storing individual tokens. */
-static struct obstack token_stack;
-
-/* Obstack for storing file names. */
-static struct obstack file_names;
-
-/* Wrapup input stack. */
-static struct obstack *wrapup_stack;
-
-/* Current stack, from input or wrapup. */
-static struct obstack *current_input;
-
-/* Bottom of token_stack, for obstack_free. */
-static void *token_bottom;
-
-/* Pointer to top of current_input. */
-static input_block *isp;
-
-/* Pointer to top of wrapup_stack. */
-static input_block *wsp;
-
-/* Aux. for handling split push_string (). */
-static input_block *next;
-
-/* Flag for next_char () to increment current_line. */
-static bool start_of_input_line;
-
-/* Flag for next_char () to recognize change in input block. */
-static bool input_change;
-
-#define CHAR_EOF 256 /* character return on EOF */
-#define CHAR_MACRO 257 /* character return for MACRO token */
-
-/* Quote chars. */
-STRING rquote;
-STRING lquote;
-
-/* Comment chars. */
-STRING bcomm;
-STRING ecomm;
-
-#ifdef ENABLE_CHANGEWORD
-
-# define DEFAULT_WORD_REGEXP "[_a-zA-Z][_a-zA-Z0-9]*"
-
-static struct re_pattern_buffer word_regexp;
-static int default_word_regexp;
-static struct re_registers regs;
-
-#else /* ! ENABLE_CHANGEWORD */
-# define default_word_regexp 1
-#endif /* ! ENABLE_CHANGEWORD */
-
-#ifdef DEBUG_INPUT
-static const char *token_type_string (token_type);
-#endif
-
-
-/*-------------------------------------------------------------------.
-| push_file () pushes an input file on the input stack, saving the |
-| current file name and line number. If next is non-NULL, this push |
-| invalidates a call to push_string_init (), whose storage is |
-| consequently released. If CLOSE_WHEN_DONE, then close FP after |
-| EOF is detected. |
-`-------------------------------------------------------------------*/
-
-void
-push_file (FILE *fp, const char *title, bool close_when_done)
-{
- input_block *i;
-
- if (next != NULL)
- {
- obstack_free (current_input, next);
- next = NULL;
- }
-
- if (debug_level & DEBUG_TRACE_INPUT)
- DEBUG_MESSAGE1 ("input read from %s", title);
-
- i = (input_block *) obstack_alloc (current_input,
- sizeof (struct input_block));
- i->type = INPUT_FILE;
- i->file = (char *) obstack_copy0 (&file_names, title, strlen (title));
- i->line = 1;
- input_change = true;
-
- i->u.u_f.fp = fp;
- i->u.u_f.end = false;
- i->u.u_f.close = close_when_done;
- i->u.u_f.advance = start_of_input_line;
- output_current_line = -1;
-
- i->prev = isp;
- isp = i;
-}
-
-/*---------------------------------------------------------------.
-| push_macro () pushes a builtin macro's definition on the input |
-| stack. If next is non-NULL, this push invalidates a call to |
-| push_string_init (), whose storage is consequently released. |
-`---------------------------------------------------------------*/
-
-void
-push_macro (builtin_func *func)
-{
- input_block *i;
-
- if (next != NULL)
- {
- obstack_free (current_input, next);
- next = NULL;
- }
-
- i = (input_block *) obstack_alloc (current_input,
- sizeof (struct input_block));
- i->type = INPUT_MACRO;
- i->file = current_file;
- i->line = current_line;
- input_change = true;
-
- i->u.func = func;
- i->prev = isp;
- isp = i;
-}
-
-/*------------------------------------------------------------------.
-| First half of push_string (). The pointer next points to the new |
-| input_block. |
-`------------------------------------------------------------------*/
-
-struct obstack *
-push_string_init (void)
-{
- if (next != NULL)
- {
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: recursive push_string!"));
- abort ();
- }
-
- next = (input_block *) obstack_alloc (current_input,
- sizeof (struct input_block));
- next->type = INPUT_STRING;
- next->file = current_file;
- next->line = current_line;
-
- return current_input;
-}
-
-/*-------------------------------------------------------------------.
-| Last half of push_string (). If next is now NULL, a call to |
-| push_file () has invalidated the previous call to push_string_init |
-| (), so we just give up. If the new object is void, we do not push |
-| it. The function push_string_finish () returns a pointer to the |
-| finished object. This pointer is only for temporary use, since |
-| reading the next token might release the memory used for the |
-| object. |
-`-------------------------------------------------------------------*/
-
-const char *
-push_string_finish (void)
-{
- const char *ret = NULL;
-
- if (next == NULL)
- return NULL;
-
- if (obstack_object_size (current_input) > 0)
- {
- size_t len = obstack_object_size (current_input);
- obstack_1grow (current_input, '\0');
- next->u.u_s.string = (char *) obstack_finish (current_input);
- next->u.u_s.end = next->u.u_s.string + len;
- next->prev = isp;
- isp = next;
- ret = isp->u.u_s.string; /* for immediate use only */
- input_change = true;
- }
- else
- obstack_free (current_input, next); /* people might leave garbage on it. */
- next = NULL;
- return ret;
-}
-
-/*------------------------------------------------------------------.
-| The function push_wrapup () pushes a string on the wrapup stack. |
-| When the normal input stack gets empty, the wrapup stack will |
-| become the input stack, and push_string () and push_file () will |
-| operate on wrapup_stack. Push_wrapup should be done as |
-| push_string (), but this will suffice, as long as arguments to |
-| m4_m4wrap () are moderate in size. |
-`------------------------------------------------------------------*/
-
-void
-push_wrapup (const char *s)
-{
- size_t len = strlen (s);
- input_block *i;
- i = (input_block *) obstack_alloc (wrapup_stack,
- sizeof (struct input_block));
- i->prev = wsp;
- i->type = INPUT_STRING;
- i->file = current_file;
- i->line = current_line;
- i->u.u_s.string = (char *) obstack_copy0 (wrapup_stack, s, len);
- i->u.u_s.end = i->u.u_s.string + len;
- wsp = i;
-}
-
-
-/*-------------------------------------------------------------------.
-| The function pop_input () pops one level of input sources. If the |
-| popped input_block is a file, current_file and current_line are |
-| reset to the saved values before the memory for the input_block is |
-| released. |
-`-------------------------------------------------------------------*/
-
-static void
-pop_input (void)
-{
- input_block *tmp = isp->prev;
-
- switch (isp->type)
- {
- case INPUT_STRING:
- case INPUT_MACRO:
- break;
-
- case INPUT_FILE:
- if (debug_level & DEBUG_TRACE_INPUT)
- {
- if (tmp)
- DEBUG_MESSAGE2 ("input reverted to %s, line %d",
- tmp->file, tmp->line);
- else
- DEBUG_MESSAGE ("input exhausted");
- }
-
- if (ferror (isp->u.u_f.fp))
- {
- M4ERROR ((warning_status, 0, "read error"));
- if (isp->u.u_f.close)
- fclose (isp->u.u_f.fp);
- retcode = EXIT_FAILURE;
- }
- else if (isp->u.u_f.close && fclose (isp->u.u_f.fp) == EOF)
- {
- M4ERROR ((warning_status, errno, "error reading file"));
- retcode = EXIT_FAILURE;
- }
- start_of_input_line = isp->u.u_f.advance;
- output_current_line = -1;
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: input stack botch in pop_input ()"));
- abort ();
- }
- obstack_free (current_input, isp);
- next = NULL; /* might be set in push_string_init () */
-
- isp = tmp;
- input_change = true;
-}
-
-/*-------------------------------------------------------------------.
-| To switch input over to the wrapup stack, main calls pop_wrapup |
-| (). Since wrapup text can install new wrapup text, pop_wrapup () |
-| returns false when there is no wrapup text on the stack, and true |
-| otherwise. |
-`-------------------------------------------------------------------*/
-
-bool
-pop_wrapup (void)
-{
- next = NULL;
- obstack_free (current_input, NULL);
- free (current_input);
-
- if (wsp == NULL)
- {
- /* End of the program. Free all memory even though we are about
- to exit, since it makes leak detection easier. */
- obstack_free (&token_stack, NULL);
- obstack_free (&file_names, NULL);
- obstack_free (wrapup_stack, NULL);
- free (wrapup_stack);
-#ifdef ENABLE_CHANGEWORD
- regfree (&word_regexp);
-#endif /* ENABLE_CHANGEWORD */
- return false;
- }
-
- current_input = wrapup_stack;
- wrapup_stack = (struct obstack *) xmalloc (sizeof (struct obstack));
- obstack_init (wrapup_stack);
-
- isp = wsp;
- wsp = NULL;
- input_change = true;
-
- return true;
-}
-
-/*-------------------------------------------------------------------.
-| When a MACRO token is seen, next_token () uses init_macro_token () |
-| to retrieve the value of the function pointer. |
-`-------------------------------------------------------------------*/
-
-static void
-init_macro_token (token_data *td)
-{
- if (isp->type != INPUT_MACRO)
- {
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad call to init_macro_token ()"));
- abort ();
- }
-
- TOKEN_DATA_TYPE (td) = TOKEN_FUNC;
- TOKEN_DATA_FUNC (td) = isp->u.func;
-}
-
-
-/*-----------------------------------------------------------------.
-| Low level input is done a character at a time. The function |
-| peek_input () is used to look at the next character in the input |
-| stream. At any given time, it reads from the input_block on the |
-| top of the current input stack. |
-`-----------------------------------------------------------------*/
-
-static int
-peek_input (void)
-{
- int ch;
- input_block *block = isp;
-
- while (1)
- {
- if (block == NULL)
- return CHAR_EOF;
-
- switch (block->type)
- {
- case INPUT_STRING:
- ch = to_uchar (block->u.u_s.string[0]);
- if (ch != '\0')
- return ch;
- break;
-
- case INPUT_FILE:
- ch = getc (block->u.u_f.fp);
- if (ch != EOF)
- {
- ungetc (ch, block->u.u_f.fp);
- return ch;
- }
- block->u.u_f.end = true;
- break;
-
- case INPUT_MACRO:
- return CHAR_MACRO;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: input stack botch in peek_input ()"));
- abort ();
- }
- block = block->prev;
- }
-}
-
-/*-------------------------------------------------------------------.
-| The function next_char () is used to read and advance the input to |
-| the next character. It also manages line numbers for error |
-| messages, so they do not get wrong, due to lookahead. The token |
-| consisting of a newline alone is taken as belonging to the line it |
-| ends, and the current line number is not incremented until the |
-| next character is read. 99.9% of all calls will read from a |
-| string, so factor that out into a macro for speed. |
-`-------------------------------------------------------------------*/
-
-#define next_char() \
- (isp && isp->type == INPUT_STRING && isp->u.u_s.string[0] \
- && !input_change \
- ? to_uchar (*isp->u.u_s.string++) \
- : next_char_1 ())
-
-static int
-next_char_1 (void)
-{
- int ch;
-
- while (1)
- {
- if (isp == NULL)
- {
- current_file = "";
- current_line = 0;
- return CHAR_EOF;
- }
-
- if (input_change)
- {
- current_file = isp->file;
- current_line = isp->line;
- input_change = false;
- }
-
- switch (isp->type)
- {
- case INPUT_STRING:
- ch = to_uchar (*isp->u.u_s.string++);
- if (ch != '\0')
- return ch;
- break;
-
- case INPUT_FILE:
- if (start_of_input_line)
- {
- start_of_input_line = false;
- current_line = ++isp->line;
- }
-
- /* If stdin is a terminal, calling getc after peek_input
- already called it would make the user have to hit ^D
- twice to quit. */
- ch = isp->u.u_f.end ? EOF : getc (isp->u.u_f.fp);
- if (ch != EOF)
- {
- if (ch == '\n')
- start_of_input_line = true;
- return ch;
- }
- break;
-
- case INPUT_MACRO:
- pop_input (); /* INPUT_MACRO input sources has only one token */
- return CHAR_MACRO;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: input stack botch in next_char ()"));
- abort ();
- }
-
- /* End of input source --- pop one level. */
- pop_input ();
- }
-}
-
-/*-------------------------------------------------------------------.
-| skip_line () simply discards all immediately following characters, |
-| upto the first newline. It is only used from m4_dnl (). |
-`-------------------------------------------------------------------*/
-
-void
-skip_line (void)
-{
- int ch;
- const char *file = current_file;
- int line = current_line;
-
- while ((ch = next_char ()) != CHAR_EOF && ch != '\n')
- ;
- if (ch == CHAR_EOF)
- /* current_file changed to "" if we see CHAR_EOF, use the
- previous value we stored earlier. */
- M4ERROR_AT_LINE ((warning_status, 0, file, line,
- "Warning: end of file treated as newline"));
- /* On the rare occasion that dnl crosses include file boundaries
- (either the input file did not end in a newline, or changeword
- was used), calling next_char can update current_file and
- current_line, and that update will be undone as we return to
- expand_macro. This informs next_char to fix things again. */
- if (file != current_file || line != current_line)
- input_change = true;
-}
-
-
-/*------------------------------------------------------------------.
-| This function is for matching a string against a prefix of the |
-| input stream. If the string matches the input and consume is |
-| true, the input is discarded; otherwise any characters read are |
-| pushed back again. The function is used only when multicharacter |
-| quotes or comment delimiters are used. |
-`------------------------------------------------------------------*/
-
-static bool
-match_input (const char *s, bool consume)
-{
- int n; /* number of characters matched */
- int ch; /* input character */
- const char *t;
- bool result = false;
-
- ch = peek_input ();
- if (ch != to_uchar (*s))
- return false; /* fail */
-
- if (s[1] == '\0')
- {
- if (consume)
- next_char ();
- return true; /* short match */
- }
-
- next_char ();
- for (n = 1, t = s++; peek_input () == to_uchar (*s++); )
- {
- next_char ();
- n++;
- if (*s == '\0') /* long match */
- {
- if (consume)
- return true;
- result = true;
- break;
- }
- }
-
- /* Failed or shouldn't consume, push back input. */
- {
- struct obstack *h = push_string_init ();
-
- /* `obstack_grow' may be macro evaluating its arg 1 several times. */
- obstack_grow (h, t, n);
- }
- push_string_finish ();
- return result;
-}
-
-/*--------------------------------------------------------------------.
-| The macro MATCH() is used to match a string S against the input. |
-| The first character is handled inline, for speed. Hopefully, this |
-| will not hurt efficiency too much when single character quotes and |
-| comment delimiters are used. If CONSUME, then CH is the result of |
-| next_char, and a successful match will discard the matched string. |
-| Otherwise, CH is the result of peek_char, and the input stream is |
-| effectively unchanged. |
-`--------------------------------------------------------------------*/
-
-#define MATCH(ch, s, consume) \
- (to_uchar ((s)[0]) == (ch) \
- && (ch) != '\0' \
- && ((s)[1] == '\0' || (match_input ((s) + (consume), consume))))
-
-
-/*--------------------------------------------------------.
-| Initialize input stacks, and quote/comment characters. |
-`--------------------------------------------------------*/
-
-void
-input_init (void)
-{
- current_file = "";
- current_line = 0;
-
- current_input = (struct obstack *) xmalloc (sizeof (struct obstack));
- obstack_init (current_input);
- wrapup_stack = (struct obstack *) xmalloc (sizeof (struct obstack));
- obstack_init (wrapup_stack);
-
- obstack_init (&file_names);
-
- /* Allocate an object in the current chunk, so that obstack_free
- will always work even if the first token parsed spills to a new
- chunk. */
- obstack_init (&token_stack);
- obstack_alloc (&token_stack, 1);
- token_bottom = obstack_base (&token_stack);
-
- isp = NULL;
- wsp = NULL;
- next = NULL;
-
- start_of_input_line = false;
-
- lquote.string = xstrdup (DEF_LQUOTE);
- lquote.length = strlen (lquote.string);
- rquote.string = xstrdup (DEF_RQUOTE);
- rquote.length = strlen (rquote.string);
- bcomm.string = xstrdup (DEF_BCOMM);
- bcomm.length = strlen (bcomm.string);
- ecomm.string = xstrdup (DEF_ECOMM);
- ecomm.length = strlen (ecomm.string);
-
-#ifdef ENABLE_CHANGEWORD
- set_word_regexp (user_word_regexp);
-#endif
-}
-
-
-/*------------------------------------------------------------------.
-| Functions for setting quotes and comment delimiters. Used by |
-| m4_changecom () and m4_changequote (). Pass NULL if the argument |
-| was not present, to distinguish from an explicit empty string. |
-`------------------------------------------------------------------*/
-
-void
-set_quotes (const char *lq, const char *rq)
-{
- free (lquote.string);
- free (rquote.string);
-
- /* POSIX states that with 0 arguments, the default quotes are used.
- POSIX XCU ERN 112 states that behavior is implementation-defined
- if there was only one argument, or if there is an empty string in
- either position when there are two arguments. We allow an empty
- left quote to disable quoting, but a non-empty left quote will
- always create a non-empty right quote. See the texinfo for what
- some other implementations do. */
- if (!lq)
- {
- lq = DEF_LQUOTE;
- rq = DEF_RQUOTE;
- }
- else if (!rq || (*lq && !*rq))
- rq = DEF_RQUOTE;
-
- lquote.string = xstrdup (lq);
- lquote.length = strlen (lquote.string);
- rquote.string = xstrdup (rq);
- rquote.length = strlen (rquote.string);
-}
-
-void
-set_comment (const char *bc, const char *ec)
-{
- free (bcomm.string);
- free (ecomm.string);
-
- /* POSIX requires no arguments to disable comments. It requires
- empty arguments to be used as-is, but this is counter to
- traditional behavior, because a non-null begin and null end makes
- it impossible to end a comment. An aardvark has been filed:
- http://www.opengroup.org/austin/mailarchives/ag-review/msg02168.html
- This implementation assumes the aardvark will be approved. See
- the texinfo for what some other implementations do. */
- if (!bc)
- bc = ec = "";
- else if (!ec || (*bc && !*ec))
- ec = DEF_ECOMM;
-
- bcomm.string = xstrdup (bc);
- bcomm.length = strlen (bcomm.string);
- ecomm.string = xstrdup (ec);
- ecomm.length = strlen (ecomm.string);
-}
-
-#ifdef ENABLE_CHANGEWORD
-
-void
-set_word_regexp (const char *regexp)
-{
- const char *msg;
- struct re_pattern_buffer new_word_regexp;
-
- if (!*regexp || STREQ (regexp, DEFAULT_WORD_REGEXP))
- {
- default_word_regexp = true;
- return;
- }
-
- /* Dry run to see whether the new expression is compilable. */
- init_pattern_buffer (&new_word_regexp, NULL);
- msg = re_compile_pattern (regexp, strlen (regexp), &new_word_regexp);
- regfree (&new_word_regexp);
-
- if (msg != NULL)
- {
- M4ERROR ((warning_status, 0,
- "bad regular expression `%s': %s", regexp, msg));
- return;
- }
-
- /* If compilation worked, retry using the word_regexp struct. We
- can't rely on struct assigns working, so redo the compilation.
- The fastmap can be reused between compilations, and will be freed
- by the final regfree. */
- if (!word_regexp.fastmap)
- word_regexp.fastmap = xcharalloc (UCHAR_MAX + 1);
- msg = re_compile_pattern (regexp, strlen (regexp), &word_regexp);
- assert (!msg);
- re_set_registers (&word_regexp, &regs, regs.num_regs, regs.start, regs.end);
- if (re_compile_fastmap (&word_regexp))
- assert (false);
-
- default_word_regexp = false;
-}
-
-#endif /* ENABLE_CHANGEWORD */
-
-
-/*--------------------------------------------------------------------.
-| Parse and return a single token from the input stream. A token |
-| can either be TOKEN_EOF, if the input_stack is empty; it can be |
-| TOKEN_STRING for a quoted string; TOKEN_WORD for something that is |
-| a potential macro name; and TOKEN_SIMPLE for any single character |
-| that is not a part of any of the previous types. If LINE is not |
-| NULL, set *LINE to the line where the token starts. |
-| |
-| Next_token () return the token type, and passes back a pointer to |
-| the token data through TD. The token text is collected on the |
-| obstack token_stack, which never contains more than one token text |
-| at a time. The storage pointed to by the fields in TD is |
-| therefore subject to change the next time next_token () is called. |
-`--------------------------------------------------------------------*/
-
-token_type
-next_token (token_data *td, int *line)
-{
- int ch;
- int quote_level;
- token_type type;
-#ifdef ENABLE_CHANGEWORD
- int startpos;
- char *orig_text = NULL;
-#endif
- const char *file;
- int dummy;
-
- obstack_free (&token_stack, token_bottom);
- if (!line)
- line = &dummy;
-
- /* Can't consume character until after CHAR_MACRO is handled. */
- ch = peek_input ();
- if (ch == CHAR_EOF)
- {
-#ifdef DEBUG_INPUT
- xfprintf (stderr, "next_token -> EOF\n");
-#endif
- next_char ();
- return TOKEN_EOF;
- }
- if (ch == CHAR_MACRO)
- {
- init_macro_token (td);
- next_char ();
-#ifdef DEBUG_INPUT
- xfprintf (stderr, "next_token -> MACDEF (%s)\n",
- find_builtin_by_addr (TOKEN_DATA_FUNC (td))->name);
-#endif
- return TOKEN_MACDEF;
- }
-
- next_char (); /* Consume character we already peeked at. */
- file = current_file;
- *line = current_line;
- if (MATCH (ch, bcomm.string, true))
- {
- obstack_grow (&token_stack, bcomm.string, bcomm.length);
- while ((ch = next_char ()) != CHAR_EOF
- && !MATCH (ch, ecomm.string, true))
- obstack_1grow (&token_stack, ch);
- if (ch != CHAR_EOF)
- obstack_grow (&token_stack, ecomm.string, ecomm.length);
- else
- /* current_file changed to "" if we see CHAR_EOF, use the
- previous value we stored earlier. */
- M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
- "ERROR: end of file in comment"));
-
- type = TOKEN_STRING;
- }
- else if (default_word_regexp && (isalpha (ch) || ch == '_'))
- {
- obstack_1grow (&token_stack, ch);
- while ((ch = peek_input ()) != CHAR_EOF && (isalnum (ch) || ch == '_'))
- {
- obstack_1grow (&token_stack, ch);
- next_char ();
- }
- type = TOKEN_WORD;
- }
-
-#ifdef ENABLE_CHANGEWORD
-
- else if (!default_word_regexp && word_regexp.fastmap[ch])
- {
- obstack_1grow (&token_stack, ch);
- while (1)
- {
- ch = peek_input ();
- if (ch == CHAR_EOF)
- break;
- obstack_1grow (&token_stack, ch);
- startpos = re_search (&word_regexp,
- (char *) obstack_base (&token_stack),
- obstack_object_size (&token_stack), 0, 0,
- &regs);
- if (startpos ||
- regs.end [0] != (regoff_t) obstack_object_size (&token_stack))
- {
- *(((char *) obstack_base (&token_stack)
- + obstack_object_size (&token_stack)) - 1) = '\0';
- break;
- }
- next_char ();
- }
-
- obstack_1grow (&token_stack, '\0');
- orig_text = (char *) obstack_finish (&token_stack);
-
- if (regs.start[1] != -1)
- obstack_grow (&token_stack,orig_text + regs.start[1],
- regs.end[1] - regs.start[1]);
- else
- obstack_grow (&token_stack, orig_text,regs.end[0]);
-
- type = TOKEN_WORD;
- }
-
-#endif /* ENABLE_CHANGEWORD */
-
- else if (!MATCH (ch, lquote.string, true))
- {
- switch (ch)
- {
- case '(':
- type = TOKEN_OPEN;
- break;
- case ',':
- type = TOKEN_COMMA;
- break;
- case ')':
- type = TOKEN_CLOSE;
- break;
- default:
- type = TOKEN_SIMPLE;
- break;
- }
- obstack_1grow (&token_stack, ch);
- }
- else
- {
- bool fast = lquote.length == 1 && rquote.length == 1;
- quote_level = 1;
- while (1)
- {
- /* Try scanning a buffer first. */
- const char *buffer = (isp && isp->type == INPUT_STRING
- ? isp->u.u_s.string : NULL);
- if (buffer && *buffer)
- {
- size_t len = isp->u.u_s.end - buffer;
- const char *p = buffer;
- do
- {
- p = (char *) memchr2 (p, *lquote.string, *rquote.string,
- buffer + len - p);
- }
- while (p && fast && (*p++ == *rquote.string
- ? --quote_level : ++quote_level));
- if (p)
- {
- if (fast)
- {
- assert (!quote_level);
- obstack_grow (&token_stack, buffer, p - buffer - 1);
- isp->u.u_s.string += p - buffer;
- break;
- }
- obstack_grow (&token_stack, buffer, p - buffer);
- ch = to_uchar (*p);
- isp->u.u_s.string += p - buffer + 1;
- }
- else
- {
- obstack_grow (&token_stack, buffer, len);
- isp->u.u_s.string += len;
- continue;
- }
- }
- /* Fall back to a byte. */
- else
- ch = next_char ();
- if (ch == CHAR_EOF)
- /* current_file changed to "" if we see CHAR_EOF, use
- the previous value we stored earlier. */
- M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
- "ERROR: end of file in string"));
-
- if (MATCH (ch, rquote.string, true))
- {
- if (--quote_level == 0)
- break;
- obstack_grow (&token_stack, rquote.string, rquote.length);
- }
- else if (MATCH (ch, lquote.string, true))
- {
- quote_level++;
- obstack_grow (&token_stack, lquote.string, lquote.length);
- }
- else
- obstack_1grow (&token_stack, ch);
- }
- type = TOKEN_STRING;
- }
-
- obstack_1grow (&token_stack, '\0');
-
- TOKEN_DATA_TYPE (td) = TOKEN_TEXT;
- TOKEN_DATA_TEXT (td) = (char *) obstack_finish (&token_stack);
-#ifdef ENABLE_CHANGEWORD
- if (orig_text == NULL)
- orig_text = TOKEN_DATA_TEXT (td);
- TOKEN_DATA_ORIG_TEXT (td) = orig_text;
-#endif
-#ifdef DEBUG_INPUT
- xfprintf (stderr, "next_token -> %s (%s)\n",
- token_type_string (type), TOKEN_DATA_TEXT (td));
-#endif
- return type;
-}
-
-/*-----------------------------------------------.
-| Peek at the next token from the input stream. |
-`-----------------------------------------------*/
-
-token_type
-peek_token (void)
-{
- token_type result;
- int ch = peek_input ();
-
- if (ch == CHAR_EOF)
- {
- result = TOKEN_EOF;
- }
- else if (ch == CHAR_MACRO)
- {
- result = TOKEN_MACDEF;
- }
- else if (MATCH (ch, bcomm.string, false))
- {
- result = TOKEN_STRING;
- }
- else if ((default_word_regexp && (isalpha (ch) || ch == '_'))
-#ifdef ENABLE_CHANGEWORD
- || (! default_word_regexp && word_regexp.fastmap[ch])
-#endif /* ENABLE_CHANGEWORD */
- )
- {
- result = TOKEN_WORD;
- }
- else if (MATCH (ch, lquote.string, false))
- {
- result = TOKEN_STRING;
- }
- else
- switch (ch)
- {
- case '(':
- result = TOKEN_OPEN;
- break;
- case ',':
- result = TOKEN_COMMA;
- break;
- case ')':
- result = TOKEN_CLOSE;
- break;
- default:
- result = TOKEN_SIMPLE;
- }
-
-#ifdef DEBUG_INPUT
- xfprintf (stderr, "peek_token -> %s\n", token_type_string (result));
-#endif /* DEBUG_INPUT */
- return result;
-}
-
-
-#ifdef DEBUG_INPUT
-
-static const char *
-token_type_string (token_type t)
-{
- switch (t)
- { /* TOKSW */
- case TOKEN_EOF:
- return "EOF";
- case TOKEN_STRING:
- return "STRING";
- case TOKEN_WORD:
- return "WORD";
- case TOKEN_OPEN:
- return "OPEN";
- case TOKEN_COMMA:
- return "COMMA";
- case TOKEN_CLOSE:
- return "CLOSE";
- case TOKEN_SIMPLE:
- return "SIMPLE";
- case TOKEN_MACDEF:
- return "MACDEF";
- default:
- abort ();
- }
- }
-
-static void
-print_token (const char *s, token_type t, token_data *td)
-{
- xfprintf (stderr, "%s: ", s);
- switch (t)
- { /* TOKSW */
- case TOKEN_OPEN:
- case TOKEN_COMMA:
- case TOKEN_CLOSE:
- case TOKEN_SIMPLE:
- xfprintf (stderr, "char:");
- break;
-
- case TOKEN_WORD:
- xfprintf (stderr, "word:");
- break;
-
- case TOKEN_STRING:
- xfprintf (stderr, "string:");
- break;
-
- case TOKEN_MACDEF:
- xfprintf (stderr, "macro: %p\n", TOKEN_DATA_FUNC (td));
- break;
-
- case TOKEN_EOF:
- xfprintf (stderr, "eof\n");
- break;
- }
- xfprintf (stderr, "\t\"%s\"\n", TOKEN_DATA_TEXT (td));
-}
-
-static void M4_GNUC_UNUSED
-lex_debug (void)
-{
- token_type t;
- token_data td;
-
- while ((t = next_token (&td, NULL)) != TOKEN_EOF)
- print_token ("lex", t, &td);
-}
-#endif /* DEBUG_INPUT */
+#endif
+
+enum input_type
+{
+ INPUT_STRING, /* String resulting from macro expansion. */
+ INPUT_FILE, /* File from command line or include. */
+ INPUT_MACRO /* Builtin resulting from defn. */
+};
+
+typedef enum input_type input_type;
+
+struct input_block
+{
+ struct input_block *prev; /* previous input_block on the input stack */
+ input_type type; /* see enum values */
+ const char *file; /* file where this input is from */
+ int line; /* line where this input is from */
+ union
+ {
+ struct
+ {
+ char *string; /* remaining string value */
+ char *end; /* terminating NUL of string */
+ }
+ u_s; /* INPUT_STRING */
+ struct
+ {
+ FILE *fp; /* input file handle */
+ bool_bitfield end : 1; /* true if peek has seen EOF */
+ bool_bitfield close : 1; /* true if we should close file on pop */
+ bool_bitfield advance : 1; /* track previous start_of_input_line */
+ }
+ u_f; /* INPUT_FILE */
+ builtin_func *func; /* pointer to macro's function */
+ }
+ u;
+};
+
+typedef struct input_block input_block;
+
+
+/* Current input file name. */
+const char *current_file;
+
+/* Current input line number. */
+int current_line;
+
+/* Obstack for storing individual tokens. */
+static struct obstack token_stack;
+
+/* Obstack for storing file names. */
+static struct obstack file_names;
+
+/* Wrapup input stack. */
+static struct obstack *wrapup_stack;
+
+/* Current stack, from input or wrapup. */
+static struct obstack *current_input;
+
+/* Bottom of token_stack, for obstack_free. */
+static void *token_bottom;
+
+/* Pointer to top of current_input. */
+static input_block *isp;
+
+/* Pointer to top of wrapup_stack. */
+static input_block *wsp;
+
+/* Aux. for handling split push_string (). */
+static input_block *next;
+
+/* Flag for next_char () to increment current_line. */
+static bool start_of_input_line;
+
+/* Flag for next_char () to recognize change in input block. */
+static bool input_change;
+
+#define CHAR_EOF 256 /* character return on EOF */
+#define CHAR_MACRO 257 /* character return for MACRO token */
+
+/* Quote chars. */
+STRING rquote;
+STRING lquote;
+
+/* Comment chars. */
+STRING bcomm;
+STRING ecomm;
+
+#ifdef ENABLE_CHANGEWORD
+
+# define DEFAULT_WORD_REGEXP "[_a-zA-Z][_a-zA-Z0-9]*"
+
+static struct re_pattern_buffer word_regexp;
+static int default_word_regexp;
+static struct re_registers regs;
+
+#else /* ! ENABLE_CHANGEWORD */
+# define default_word_regexp 1
+#endif /* ! ENABLE_CHANGEWORD */
+
+#ifdef DEBUG_INPUT
+static const char *token_type_string (token_type);
+#endif
+
+
+/*-------------------------------------------------------------------.
+| push_file () pushes an input file on the input stack, saving the |
+| current file name and line number. If next is non-NULL, this push |
+| invalidates a call to push_string_init (), whose storage is |
+| consequently released. If CLOSE_WHEN_DONE, then close FP after |
+| EOF is detected. |
+`-------------------------------------------------------------------*/
+
+void
+push_file (FILE *fp, const char *title, bool close_when_done)
+{
+ input_block *i;
+
+ if (next != NULL)
+ {
+ obstack_free (current_input, next);
+ next = NULL;
+ }
+
+ if (debug_level & DEBUG_TRACE_INPUT)
+ DEBUG_MESSAGE1 ("input read from %s", title);
+
+ i = (input_block *) obstack_alloc (current_input,
+ sizeof (struct input_block));
+ i->type = INPUT_FILE;
+ i->file = (char *) obstack_copy0 (&file_names, title, strlen (title));
+ i->line = 1;
+ input_change = true;
+
+ i->u.u_f.fp = fp;
+ i->u.u_f.end = false;
+ i->u.u_f.close = close_when_done;
+ i->u.u_f.advance = start_of_input_line;
+ output_current_line = -1;
+
+ i->prev = isp;
+ isp = i;
+}
+
+/*---------------------------------------------------------------.
+| push_macro () pushes a builtin macro's definition on the input |
+| stack. If next is non-NULL, this push invalidates a call to |
+| push_string_init (), whose storage is consequently released. |
+`---------------------------------------------------------------*/
+
+void
+push_macro (builtin_func *func)
+{
+ input_block *i;
+
+ if (next != NULL)
+ {
+ obstack_free (current_input, next);
+ next = NULL;
+ }
+
+ i = (input_block *) obstack_alloc (current_input,
+ sizeof (struct input_block));
+ i->type = INPUT_MACRO;
+ i->file = current_file;
+ i->line = current_line;
+ input_change = true;
+
+ i->u.func = func;
+ i->prev = isp;
+ isp = i;
+}
+
+/*------------------------------------------------------------------.
+| First half of push_string (). The pointer next points to the new |
+| input_block. |
+`------------------------------------------------------------------*/
+
+struct obstack *
+push_string_init (void)
+{
+ if (next != NULL)
+ {
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: recursive push_string!"));
+ abort ();
+ }
+
+ next = (input_block *) obstack_alloc (current_input,
+ sizeof (struct input_block));
+ next->type = INPUT_STRING;
+ next->file = current_file;
+ next->line = current_line;
+
+ return current_input;
+}
+
+/*-------------------------------------------------------------------.
+| Last half of push_string (). If next is now NULL, a call to |
+| push_file () has invalidated the previous call to push_string_init |
+| (), so we just give up. If the new object is void, we do not push |
+| it. The function push_string_finish () returns a pointer to the |
+| finished object. This pointer is only for temporary use, since |
+| reading the next token might release the memory used for the |
+| object. |
+`-------------------------------------------------------------------*/
+
+const char *
+push_string_finish (void)
+{
+ const char *ret = NULL;
+
+ if (next == NULL)
+ return NULL;
+
+ if (obstack_object_size (current_input) > 0)
+ {
+ size_t len = obstack_object_size (current_input);
+ obstack_1grow (current_input, '\0');
+ next->u.u_s.string = (char *) obstack_finish (current_input);
+ next->u.u_s.end = next->u.u_s.string + len;
+ next->prev = isp;
+ isp = next;
+ ret = isp->u.u_s.string; /* for immediate use only */
+ input_change = true;
+ }
+ else
+ obstack_free (current_input, next); /* people might leave garbage on it. */
+ next = NULL;
+ return ret;
+}
+
+/*------------------------------------------------------------------.
+| The function push_wrapup () pushes a string on the wrapup stack. |
+| When the normal input stack gets empty, the wrapup stack will |
+| become the input stack, and push_string () and push_file () will |
+| operate on wrapup_stack. Push_wrapup should be done as |
+| push_string (), but this will suffice, as long as arguments to |
+| m4_m4wrap () are moderate in size. |
+`------------------------------------------------------------------*/
+
+void
+push_wrapup (const char *s)
+{
+ size_t len = strlen (s);
+ input_block *i;
+ i = (input_block *) obstack_alloc (wrapup_stack,
+ sizeof (struct input_block));
+ i->prev = wsp;
+ i->type = INPUT_STRING;
+ i->file = current_file;
+ i->line = current_line;
+ i->u.u_s.string = (char *) obstack_copy0 (wrapup_stack, s, len);
+ i->u.u_s.end = i->u.u_s.string + len;
+ wsp = i;
+}
+
+
+/*-------------------------------------------------------------------.
+| The function pop_input () pops one level of input sources. If the |
+| popped input_block is a file, current_file and current_line are |
+| reset to the saved values before the memory for the input_block is |
+| released. |
+`-------------------------------------------------------------------*/
+
+static void
+pop_input (void)
+{
+ input_block *tmp = isp->prev;
+
+ switch (isp->type)
+ {
+ case INPUT_STRING:
+ case INPUT_MACRO:
+ break;
+
+ case INPUT_FILE:
+ if (debug_level & DEBUG_TRACE_INPUT)
+ {
+ if (tmp)
+ DEBUG_MESSAGE2 ("input reverted to %s, line %d",
+ tmp->file, tmp->line);
+ else
+ DEBUG_MESSAGE ("input exhausted");
+ }
+
+ if (ferror (isp->u.u_f.fp))
+ {
+ M4ERROR ((warning_status, 0, "read error"));
+ if (isp->u.u_f.close)
+ fclose (isp->u.u_f.fp);
+ retcode = EXIT_FAILURE;
+ }
+ else if (isp->u.u_f.close && fclose (isp->u.u_f.fp) == EOF)
+ {
+ M4ERROR ((warning_status, errno, "error reading file"));
+ retcode = EXIT_FAILURE;
+ }
+ start_of_input_line = isp->u.u_f.advance;
+ output_current_line = -1;
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: input stack botch in pop_input ()"));
+ abort ();
+ }
+ obstack_free (current_input, isp);
+ next = NULL; /* might be set in push_string_init () */
+
+ isp = tmp;
+ input_change = true;
+}
+
+/*-------------------------------------------------------------------.
+| To switch input over to the wrapup stack, main calls pop_wrapup |
+| (). Since wrapup text can install new wrapup text, pop_wrapup () |
+| returns false when there is no wrapup text on the stack, and true |
+| otherwise. |
+`-------------------------------------------------------------------*/
+
+bool
+pop_wrapup (void)
+{
+ next = NULL;
+ obstack_free (current_input, NULL);
+ free (current_input);
+
+ if (wsp == NULL)
+ {
+ /* End of the program. Free all memory even though we are about
+ to exit, since it makes leak detection easier. */
+ obstack_free (&token_stack, NULL);
+ obstack_free (&file_names, NULL);
+ obstack_free (wrapup_stack, NULL);
+ free (wrapup_stack);
+#ifdef ENABLE_CHANGEWORD
+ regfree (&word_regexp);
+#endif /* ENABLE_CHANGEWORD */
+ return false;
+ }
+
+ current_input = wrapup_stack;
+ wrapup_stack = (struct obstack *) xmalloc (sizeof (struct obstack));
+ obstack_init (wrapup_stack);
+
+ isp = wsp;
+ wsp = NULL;
+ input_change = true;
+
+ return true;
+}
+
+/*-------------------------------------------------------------------.
+| When a MACRO token is seen, next_token () uses init_macro_token () |
+| to retrieve the value of the function pointer. |
+`-------------------------------------------------------------------*/
+
+static void
+init_macro_token (token_data *td)
+{
+ if (isp->type != INPUT_MACRO)
+ {
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad call to init_macro_token ()"));
+ abort ();
+ }
+
+ TOKEN_DATA_TYPE (td) = TOKEN_FUNC;
+ TOKEN_DATA_FUNC (td) = isp->u.func;
+}
+
+
+/*-----------------------------------------------------------------.
+| Low level input is done a character at a time. The function |
+| peek_input () is used to look at the next character in the input |
+| stream. At any given time, it reads from the input_block on the |
+| top of the current input stack. |
+`-----------------------------------------------------------------*/
+
+static int
+peek_input (void)
+{
+ int ch;
+ input_block *block = isp;
+
+ while (1)
+ {
+ if (block == NULL)
+ return CHAR_EOF;
+
+ switch (block->type)
+ {
+ case INPUT_STRING:
+ ch = to_uchar (block->u.u_s.string[0]);
+ if (ch != '\0')
+ return ch;
+ break;
+
+ case INPUT_FILE:
+ ch = getc (block->u.u_f.fp);
+ if (ch != EOF)
+ {
+ ungetc (ch, block->u.u_f.fp);
+ return ch;
+ }
+ block->u.u_f.end = true;
+ break;
+
+ case INPUT_MACRO:
+ return CHAR_MACRO;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: input stack botch in peek_input ()"));
+ abort ();
+ }
+ block = block->prev;
+ }
+}
+
+/*-------------------------------------------------------------------.
+| The function next_char () is used to read and advance the input to |
+| the next character. It also manages line numbers for error |
+| messages, so they do not get wrong, due to lookahead. The token |
+| consisting of a newline alone is taken as belonging to the line it |
+| ends, and the current line number is not incremented until the |
+| next character is read. 99.9% of all calls will read from a |
+| string, so factor that out into a macro for speed. |
+`-------------------------------------------------------------------*/
+
+#define next_char() \
+ (isp && isp->type == INPUT_STRING && isp->u.u_s.string[0] \
+ && !input_change \
+ ? to_uchar (*isp->u.u_s.string++) \
+ : next_char_1 ())
+
+static int
+next_char_1 (void)
+{
+ int ch;
+
+ while (1)
+ {
+ if (isp == NULL)
+ {
+ current_file = "";
+ current_line = 0;
+ return CHAR_EOF;
+ }
+
+ if (input_change)
+ {
+ current_file = isp->file;
+ current_line = isp->line;
+ input_change = false;
+ }
+
+ switch (isp->type)
+ {
+ case INPUT_STRING:
+ ch = to_uchar (*isp->u.u_s.string++);
+ if (ch != '\0')
+ return ch;
+ break;
+
+ case INPUT_FILE:
+ if (start_of_input_line)
+ {
+ start_of_input_line = false;
+ current_line = ++isp->line;
+ }
+
+ /* If stdin is a terminal, calling getc after peek_input
+ already called it would make the user have to hit ^D
+ twice to quit. */
+ ch = isp->u.u_f.end ? EOF : getc (isp->u.u_f.fp);
+ if (ch != EOF)
+ {
+ if (ch == '\n')
+ start_of_input_line = true;
+ return ch;
+ }
+ break;
+
+ case INPUT_MACRO:
+ pop_input (); /* INPUT_MACRO input sources has only one token */
+ return CHAR_MACRO;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: input stack botch in next_char ()"));
+ abort ();
+ }
+
+ /* End of input source --- pop one level. */
+ pop_input ();
+ }
+}
+
+/*-------------------------------------------------------------------.
+| skip_line () simply discards all immediately following characters, |
+| upto the first newline. It is only used from m4_dnl (). |
+`-------------------------------------------------------------------*/
+
+void
+skip_line (void)
+{
+ int ch;
+ const char *file = current_file;
+ int line = current_line;
+
+ while ((ch = next_char ()) != CHAR_EOF && ch != '\n')
+ ;
+ if (ch == CHAR_EOF)
+ /* current_file changed to "" if we see CHAR_EOF, use the
+ previous value we stored earlier. */
+ M4ERROR_AT_LINE ((warning_status, 0, file, line,
+ "Warning: end of file treated as newline"));
+ /* On the rare occasion that dnl crosses include file boundaries
+ (either the input file did not end in a newline, or changeword
+ was used), calling next_char can update current_file and
+ current_line, and that update will be undone as we return to
+ expand_macro. This informs next_char to fix things again. */
+ if (file != current_file || line != current_line)
+ input_change = true;
+}
+
+
+/*------------------------------------------------------------------.
+| This function is for matching a string against a prefix of the |
+| input stream. If the string matches the input and consume is |
+| true, the input is discarded; otherwise any characters read are |
+| pushed back again. The function is used only when multicharacter |
+| quotes or comment delimiters are used. |
+`------------------------------------------------------------------*/
+
+static bool
+match_input (const char *s, bool consume)
+{
+ int n; /* number of characters matched */
+ int ch; /* input character */
+ const char *t;
+ bool result = false;
+
+ ch = peek_input ();
+ if (ch != to_uchar (*s))
+ return false; /* fail */
+
+ if (s[1] == '\0')
+ {
+ if (consume)
+ next_char ();
+ return true; /* short match */
+ }
+
+ next_char ();
+ for (n = 1, t = s++; peek_input () == to_uchar (*s++); )
+ {
+ next_char ();
+ n++;
+ if (*s == '\0') /* long match */
+ {
+ if (consume)
+ return true;
+ result = true;
+ break;
+ }
+ }
+
+ /* Failed or shouldn't consume, push back input. */
+ {
+ struct obstack *h = push_string_init ();
+
+ /* `obstack_grow' may be macro evaluating its arg 1 several times. */
+ obstack_grow (h, t, n);
+ }
+ push_string_finish ();
+ return result;
+}
+
+/*--------------------------------------------------------------------.
+| The macro MATCH() is used to match a string S against the input. |
+| The first character is handled inline, for speed. Hopefully, this |
+| will not hurt efficiency too much when single character quotes and |
+| comment delimiters are used. If CONSUME, then CH is the result of |
+| next_char, and a successful match will discard the matched string. |
+| Otherwise, CH is the result of peek_char, and the input stream is |
+| effectively unchanged. |
+`--------------------------------------------------------------------*/
+
+#define MATCH(ch, s, consume) \
+ (to_uchar ((s)[0]) == (ch) \
+ && (ch) != '\0' \
+ && ((s)[1] == '\0' || (match_input ((s) + (consume), consume))))
+
+
+/*--------------------------------------------------------.
+| Initialize input stacks, and quote/comment characters. |
+`--------------------------------------------------------*/
+
+void
+input_init (void)
+{
+ current_file = "";
+ current_line = 0;
+
+ current_input = (struct obstack *) xmalloc (sizeof (struct obstack));
+ obstack_init (current_input);
+ wrapup_stack = (struct obstack *) xmalloc (sizeof (struct obstack));
+ obstack_init (wrapup_stack);
+
+ obstack_init (&file_names);
+
+ /* Allocate an object in the current chunk, so that obstack_free
+ will always work even if the first token parsed spills to a new
+ chunk. */
+ obstack_init (&token_stack);
+ obstack_alloc (&token_stack, 1);
+ token_bottom = obstack_base (&token_stack);
+
+ isp = NULL;
+ wsp = NULL;
+ next = NULL;
+
+ start_of_input_line = false;
+
+ lquote.string = xstrdup (DEF_LQUOTE);
+ lquote.length = strlen (lquote.string);
+ rquote.string = xstrdup (DEF_RQUOTE);
+ rquote.length = strlen (rquote.string);
+ bcomm.string = xstrdup (DEF_BCOMM);
+ bcomm.length = strlen (bcomm.string);
+ ecomm.string = xstrdup (DEF_ECOMM);
+ ecomm.length = strlen (ecomm.string);
+
+#ifdef ENABLE_CHANGEWORD
+ set_word_regexp (user_word_regexp);
+#endif
+}
+
+
+/*------------------------------------------------------------------.
+| Functions for setting quotes and comment delimiters. Used by |
+| m4_changecom () and m4_changequote (). Pass NULL if the argument |
+| was not present, to distinguish from an explicit empty string. |
+`------------------------------------------------------------------*/
+
+void
+set_quotes (const char *lq, const char *rq)
+{
+ free (lquote.string);
+ free (rquote.string);
+
+ /* POSIX states that with 0 arguments, the default quotes are used.
+ POSIX XCU ERN 112 states that behavior is implementation-defined
+ if there was only one argument, or if there is an empty string in
+ either position when there are two arguments. We allow an empty
+ left quote to disable quoting, but a non-empty left quote will
+ always create a non-empty right quote. See the texinfo for what
+ some other implementations do. */
+ if (!lq)
+ {
+ lq = DEF_LQUOTE;
+ rq = DEF_RQUOTE;
+ }
+ else if (!rq || (*lq && !*rq))
+ rq = DEF_RQUOTE;
+
+ lquote.string = xstrdup (lq);
+ lquote.length = strlen (lquote.string);
+ rquote.string = xstrdup (rq);
+ rquote.length = strlen (rquote.string);
+}
+
+void
+set_comment (const char *bc, const char *ec)
+{
+ free (bcomm.string);
+ free (ecomm.string);
+
+ /* POSIX requires no arguments to disable comments. It requires
+ empty arguments to be used as-is, but this is counter to
+ traditional behavior, because a non-null begin and null end makes
+ it impossible to end a comment. An aardvark has been filed:
+ http://www.opengroup.org/austin/mailarchives/ag-review/msg02168.html
+ This implementation assumes the aardvark will be approved. See
+ the texinfo for what some other implementations do. */
+ if (!bc)
+ bc = ec = "";
+ else if (!ec || (*bc && !*ec))
+ ec = DEF_ECOMM;
+
+ bcomm.string = xstrdup (bc);
+ bcomm.length = strlen (bcomm.string);
+ ecomm.string = xstrdup (ec);
+ ecomm.length = strlen (ecomm.string);
+}
+
+#ifdef ENABLE_CHANGEWORD
+
+void
+set_word_regexp (const char *regexp)
+{
+ const char *msg;
+ struct re_pattern_buffer new_word_regexp;
+
+ if (!*regexp || STREQ (regexp, DEFAULT_WORD_REGEXP))
+ {
+ default_word_regexp = true;
+ return;
+ }
+
+ /* Dry run to see whether the new expression is compilable. */
+ init_pattern_buffer (&new_word_regexp, NULL);
+ msg = re_compile_pattern (regexp, strlen (regexp), &new_word_regexp);
+ regfree (&new_word_regexp);
+
+ if (msg != NULL)
+ {
+ M4ERROR ((warning_status, 0,
+ "bad regular expression `%s': %s", regexp, msg));
+ return;
+ }
+
+ /* If compilation worked, retry using the word_regexp struct. We
+ can't rely on struct assigns working, so redo the compilation.
+ The fastmap can be reused between compilations, and will be freed
+ by the final regfree. */
+ if (!word_regexp.fastmap)
+ word_regexp.fastmap = xcharalloc (UCHAR_MAX + 1);
+ msg = re_compile_pattern (regexp, strlen (regexp), &word_regexp);
+ assert (!msg);
+ re_set_registers (&word_regexp, &regs, regs.num_regs, regs.start, regs.end);
+ if (re_compile_fastmap (&word_regexp))
+ assert (false);
+
+ default_word_regexp = false;
+}
+
+#endif /* ENABLE_CHANGEWORD */
+
+
+/*--------------------------------------------------------------------.
+| Parse and return a single token from the input stream. A token |
+| can either be TOKEN_EOF, if the input_stack is empty; it can be |
+| TOKEN_STRING for a quoted string; TOKEN_WORD for something that is |
+| a potential macro name; and TOKEN_SIMPLE for any single character |
+| that is not a part of any of the previous types. If LINE is not |
+| NULL, set *LINE to the line where the token starts. |
+| |
+| Next_token () return the token type, and passes back a pointer to |
+| the token data through TD. The token text is collected on the |
+| obstack token_stack, which never contains more than one token text |
+| at a time. The storage pointed to by the fields in TD is |
+| therefore subject to change the next time next_token () is called. |
+`--------------------------------------------------------------------*/
+
+token_type
+next_token (token_data *td, int *line)
+{
+ int ch;
+ int quote_level;
+ token_type type;
+#ifdef ENABLE_CHANGEWORD
+ int startpos;
+ char *orig_text = NULL;
+#endif
+ const char *file;
+ int dummy;
+
+ obstack_free (&token_stack, token_bottom);
+ if (!line)
+ line = &dummy;
+
+ /* Can't consume character until after CHAR_MACRO is handled. */
+ ch = peek_input ();
+ if (ch == CHAR_EOF)
+ {
+#ifdef DEBUG_INPUT
+ xfprintf (stderr, "next_token -> EOF\n");
+#endif
+ next_char ();
+ return TOKEN_EOF;
+ }
+ if (ch == CHAR_MACRO)
+ {
+ init_macro_token (td);
+ next_char ();
+#ifdef DEBUG_INPUT
+ xfprintf (stderr, "next_token -> MACDEF (%s)\n",
+ find_builtin_by_addr (TOKEN_DATA_FUNC (td))->name);
+#endif
+ return TOKEN_MACDEF;
+ }
+
+ next_char (); /* Consume character we already peeked at. */
+ file = current_file;
+ *line = current_line;
+ if (MATCH (ch, bcomm.string, true))
+ {
+ obstack_grow (&token_stack, bcomm.string, bcomm.length);
+ while ((ch = next_char ()) != CHAR_EOF
+ && !MATCH (ch, ecomm.string, true))
+ obstack_1grow (&token_stack, ch);
+ if (ch != CHAR_EOF)
+ obstack_grow (&token_stack, ecomm.string, ecomm.length);
+ else
+ /* current_file changed to "" if we see CHAR_EOF, use the
+ previous value we stored earlier. */
+ M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
+ "ERROR: end of file in comment"));
+
+ type = TOKEN_STRING;
+ }
+ else if (default_word_regexp && (isalpha (ch) || ch == '_'))
+ {
+ obstack_1grow (&token_stack, ch);
+ while ((ch = peek_input ()) != CHAR_EOF && (isalnum (ch) || ch == '_'))
+ {
+ obstack_1grow (&token_stack, ch);
+ next_char ();
+ }
+ type = TOKEN_WORD;
+ }
+
+#ifdef ENABLE_CHANGEWORD
+
+ else if (!default_word_regexp && word_regexp.fastmap[ch])
+ {
+ obstack_1grow (&token_stack, ch);
+ while (1)
+ {
+ ch = peek_input ();
+ if (ch == CHAR_EOF)
+ break;
+ obstack_1grow (&token_stack, ch);
+ startpos = re_search (&word_regexp,
+ (char *) obstack_base (&token_stack),
+ obstack_object_size (&token_stack), 0, 0,
+ &regs);
+ if (startpos ||
+ regs.end [0] != (regoff_t) obstack_object_size (&token_stack))
+ {
+ *(((char *) obstack_base (&token_stack)
+ + obstack_object_size (&token_stack)) - 1) = '\0';
+ break;
+ }
+ next_char ();
+ }
+
+ obstack_1grow (&token_stack, '\0');
+ orig_text = (char *) obstack_finish (&token_stack);
+
+ if (regs.start[1] != -1)
+ obstack_grow (&token_stack,orig_text + regs.start[1],
+ regs.end[1] - regs.start[1]);
+ else
+ obstack_grow (&token_stack, orig_text,regs.end[0]);
+
+ type = TOKEN_WORD;
+ }
+
+#endif /* ENABLE_CHANGEWORD */
+
+ else if (!MATCH (ch, lquote.string, true))
+ {
+ switch (ch)
+ {
+ case '(':
+ type = TOKEN_OPEN;
+ break;
+ case ',':
+ type = TOKEN_COMMA;
+ break;
+ case ')':
+ type = TOKEN_CLOSE;
+ break;
+ default:
+ type = TOKEN_SIMPLE;
+ break;
+ }
+ obstack_1grow (&token_stack, ch);
+ }
+ else
+ {
+ bool fast = lquote.length == 1 && rquote.length == 1;
+ quote_level = 1;
+ while (1)
+ {
+ /* Try scanning a buffer first. */
+ const char *buffer = (isp && isp->type == INPUT_STRING
+ ? isp->u.u_s.string : NULL);
+ if (buffer && *buffer)
+ {
+ size_t len = isp->u.u_s.end - buffer;
+ const char *p = buffer;
+ do
+ {
+ p = (char *) memchr2 (p, *lquote.string, *rquote.string,
+ buffer + len - p);
+ }
+ while (p && fast && (*p++ == *rquote.string
+ ? --quote_level : ++quote_level));
+ if (p)
+ {
+ if (fast)
+ {
+ assert (!quote_level);
+ obstack_grow (&token_stack, buffer, p - buffer - 1);
+ isp->u.u_s.string += p - buffer;
+ break;
+ }
+ obstack_grow (&token_stack, buffer, p - buffer);
+ ch = to_uchar (*p);
+ isp->u.u_s.string += p - buffer + 1;
+ }
+ else
+ {
+ obstack_grow (&token_stack, buffer, len);
+ isp->u.u_s.string += len;
+ continue;
+ }
+ }
+ /* Fall back to a byte. */
+ else
+ ch = next_char ();
+ if (ch == CHAR_EOF)
+ /* current_file changed to "" if we see CHAR_EOF, use
+ the previous value we stored earlier. */
+ M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
+ "ERROR: end of file in string"));
+
+ if (MATCH (ch, rquote.string, true))
+ {
+ if (--quote_level == 0)
+ break;
+ obstack_grow (&token_stack, rquote.string, rquote.length);
+ }
+ else if (MATCH (ch, lquote.string, true))
+ {
+ quote_level++;
+ obstack_grow (&token_stack, lquote.string, lquote.length);
+ }
+ else
+ obstack_1grow (&token_stack, ch);
+ }
+ type = TOKEN_STRING;
+ }
+
+ obstack_1grow (&token_stack, '\0');
+
+ TOKEN_DATA_TYPE (td) = TOKEN_TEXT;
+ TOKEN_DATA_TEXT (td) = (char *) obstack_finish (&token_stack);
+#ifdef ENABLE_CHANGEWORD
+ if (orig_text == NULL)
+ orig_text = TOKEN_DATA_TEXT (td);
+ TOKEN_DATA_ORIG_TEXT (td) = orig_text;
+#endif
+#ifdef DEBUG_INPUT
+ xfprintf (stderr, "next_token -> %s (%s)\n",
+ token_type_string (type), TOKEN_DATA_TEXT (td));
+#endif
+ return type;
+}
+
+/*-----------------------------------------------.
+| Peek at the next token from the input stream. |
+`-----------------------------------------------*/
+
+token_type
+peek_token (void)
+{
+ token_type result;
+ int ch = peek_input ();
+
+ if (ch == CHAR_EOF)
+ {
+ result = TOKEN_EOF;
+ }
+ else if (ch == CHAR_MACRO)
+ {
+ result = TOKEN_MACDEF;
+ }
+ else if (MATCH (ch, bcomm.string, false))
+ {
+ result = TOKEN_STRING;
+ }
+ else if ((default_word_regexp && (isalpha (ch) || ch == '_'))
+#ifdef ENABLE_CHANGEWORD
+ || (! default_word_regexp && word_regexp.fastmap[ch])
+#endif /* ENABLE_CHANGEWORD */
+ )
+ {
+ result = TOKEN_WORD;
+ }
+ else if (MATCH (ch, lquote.string, false))
+ {
+ result = TOKEN_STRING;
+ }
+ else
+ switch (ch)
+ {
+ case '(':
+ result = TOKEN_OPEN;
+ break;
+ case ',':
+ result = TOKEN_COMMA;
+ break;
+ case ')':
+ result = TOKEN_CLOSE;
+ break;
+ default:
+ result = TOKEN_SIMPLE;
+ }
+
+#ifdef DEBUG_INPUT
+ xfprintf (stderr, "peek_token -> %s\n", token_type_string (result));
+#endif /* DEBUG_INPUT */
+ return result;
+}
+
+
+#ifdef DEBUG_INPUT
+
+static const char *
+token_type_string (token_type t)
+{
+ switch (t)
+ { /* TOKSW */
+ case TOKEN_EOF:
+ return "EOF";
+ case TOKEN_STRING:
+ return "STRING";
+ case TOKEN_WORD:
+ return "WORD";
+ case TOKEN_OPEN:
+ return "OPEN";
+ case TOKEN_COMMA:
+ return "COMMA";
+ case TOKEN_CLOSE:
+ return "CLOSE";
+ case TOKEN_SIMPLE:
+ return "SIMPLE";
+ case TOKEN_MACDEF:
+ return "MACDEF";
+ default:
+ abort ();
+ }
+ }
+
+static void
+print_token (const char *s, token_type t, token_data *td)
+{
+ xfprintf (stderr, "%s: ", s);
+ switch (t)
+ { /* TOKSW */
+ case TOKEN_OPEN:
+ case TOKEN_COMMA:
+ case TOKEN_CLOSE:
+ case TOKEN_SIMPLE:
+ xfprintf (stderr, "char:");
+ break;
+
+ case TOKEN_WORD:
+ xfprintf (stderr, "word:");
+ break;
+
+ case TOKEN_STRING:
+ xfprintf (stderr, "string:");
+ break;
+
+ case TOKEN_MACDEF:
+ xfprintf (stderr, "macro: %p\n", TOKEN_DATA_FUNC (td));
+ break;
+
+ case TOKEN_EOF:
+ xfprintf (stderr, "eof\n");
+ break;
+ }
+ xfprintf (stderr, "\t\"%s\"\n", TOKEN_DATA_TEXT (td));
+}
+
+static void M4_GNUC_UNUSED
+lex_debug (void)
+{
+ token_type t;
+ token_data td;
+
+ while ((t = next_token (&td, NULL)) != TOKEN_EOF)
+ print_token ("lex", t, &td);
+}
+#endif /* DEBUG_INPUT */
diff --git a/contrib/tools/bison/m4/src/m4.c b/contrib/tools/bison/m4/src/m4.c
index 2c03154471..65707d2f6b 100644
--- a/contrib/tools/bison/m4/src/m4.c
+++ b/contrib/tools/bison/m4/src/m4.c
@@ -1,695 +1,695 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "m4.h"
-
-#include <getopt.h>
-#include <limits.h>
-#include <signal.h>
-
-#include "c-stack.h"
-#include "ignore-value.h"
-#include "progname.h"
-#include "version-etc.h"
-
-#ifdef DEBUG_STKOVF
-# include "assert.h"
-#endif
-
-#define AUTHORS "Rene' Seindal"
-
-static void usage (int) M4_GNUC_NORETURN;
-
-/* Enable sync output for /lib/cpp (-s). */
-int sync_output = 0;
-
-/* Debug (-d[flags]). */
-int debug_level = 0;
-
-/* Hash table size (should be a prime) (-Hsize). */
-size_t hash_table_size = HASHMAX;
-
-/* Disable GNU extensions (-G). */
-int no_gnu_extensions = 0;
-
-/* Prefix all builtin functions by `m4_'. */
-int prefix_all_builtins = 0;
-
-/* Max length of arguments in trace output (-lsize). */
-int max_debug_argument_length = 0;
-
-/* Suppress warnings about missing arguments. */
-int suppress_warnings = 0;
-
-/* If true, then warnings affect exit status. */
-static bool fatal_warnings = false;
-
-/* If not zero, then value of exit status for warning diagnostics. */
-int warning_status = 0;
-
-/* Artificial limit for expansion_level in macro.c. */
-int nesting_limit = 1024;
-
-#ifdef ENABLE_CHANGEWORD
-/* User provided regexp for describing m4 words. */
-const char *user_word_regexp = "";
-#endif
-
-/* Global catchall for any errors that should affect final error status, but
- where we try to continue execution in the meantime. */
-int retcode;
-
-struct macro_definition
-{
- struct macro_definition *next;
- int code; /* D, U, s, t, '\1', or DEBUGFILE_OPTION. */
- const char *arg;
-};
-typedef struct macro_definition macro_definition;
-
-/* Error handling functions. */
-
-/*-----------------------.
-| Wrapper around error. |
-`-----------------------*/
-
-void
-m4_error (int status, int errnum, const char *format, ...)
-{
- va_list args;
- va_start (args, format);
- verror_at_line (status, errnum, current_line ? current_file : NULL,
- current_line, format, args);
- if (fatal_warnings && ! retcode)
- retcode = EXIT_FAILURE;
- va_end (args);
-}
-
-/*-------------------------------.
-| Wrapper around error_at_line. |
-`-------------------------------*/
-
-void
-m4_error_at_line (int status, int errnum, const char *file, int line,
- const char *format, ...)
-{
- va_list args;
- va_start (args, format);
- verror_at_line (status, errnum, line ? file : NULL, line, format, args);
- if (fatal_warnings && ! retcode)
- retcode = EXIT_FAILURE;
- va_end (args);
-}
-
-#ifndef SIGBUS
-# define SIGBUS SIGILL
-#endif
-
-#ifndef NSIG
-# ifndef MAX
-# define MAX(a,b) ((a) < (b) ? (b) : (a))
-# endif
-# define NSIG (MAX (SIGABRT, MAX (SIGILL, MAX (SIGFPE, \
- MAX (SIGSEGV, SIGBUS)))) + 1)
-#endif
-
-/* Pre-translated messages for program errors. Do not translate in
- the signal handler, since gettext and strsignal are not
- async-signal-safe. */
-static const char * volatile program_error_message;
-static const char * volatile signal_message[NSIG];
-
-/* Print a nicer message about any programmer errors, then exit. This
- must be aysnc-signal safe, since it is executed as a signal
- handler. If SIGNO is zero, this represents a stack overflow; in
- that case, we return to allow c_stack_action to handle things. */
-static void M4_GNUC_PURE
-fault_handler (int signo)
-{
- if (signo)
- {
- /* POSIX states that reading static memory is, in general, not
- async-safe. However, the static variables that we read are
- never modified once this handler is installed, so this
- particular usage is safe. And it seems an oversight that
- POSIX claims strlen is not async-safe. Ignore write
- failures, since we will exit with non-zero status anyway. */
-#define WRITE(f, b, l) ignore_value (write (f, b, l))
- WRITE (STDERR_FILENO, program_name, strlen (program_name));
- WRITE (STDERR_FILENO, ": ", 2);
- WRITE (STDERR_FILENO, program_error_message,
- strlen (program_error_message));
- if (signal_message[signo])
- {
- WRITE (STDERR_FILENO, ": ", 2);
- WRITE (STDERR_FILENO, signal_message[signo],
- strlen (signal_message[signo]));
- }
- WRITE (STDERR_FILENO, "\n", 1);
-#undef WRITE
- _exit (EXIT_INTERNAL_ERROR);
- }
-}
-
-
-/*---------------------------------------------.
-| Print a usage message and exit with STATUS. |
-`---------------------------------------------*/
-
-static void
-usage (int status)
-{
- if (status != EXIT_SUCCESS)
- xfprintf (stderr, "Try `%s --help' for more information.\n", program_name);
- else
- {
- xprintf ("Usage: %s [OPTION]... [FILE]...\n", program_name);
- fputs ("\
-Process macros in FILEs. If no FILE or if FILE is `-', standard input\n\
-is read.\n\
-", stdout);
- fputs ("\
-\n\
-Mandatory or optional arguments to long options are mandatory or optional\n\
-for short options too.\n\
-\n\
-Operation modes:\n\
- --help display this help and exit\n\
- --version output version information and exit\n\
-", stdout);
- xprintf ("\
- -E, --fatal-warnings once: warnings become errors, twice: stop\n\
- execution at first error\n\
- -i, --interactive unbuffer output, ignore interrupts\n\
- -P, --prefix-builtins force a `m4_' prefix to all builtins\n\
- -Q, --quiet, --silent suppress some warnings for builtins\n\
- --warn-macro-sequence[=REGEXP]\n\
- warn if macro definition matches REGEXP,\n\
- default %s\n\
-", DEFAULT_MACRO_SEQUENCE);
-#ifdef ENABLE_CHANGEWORD
- fputs ("\
- -W, --word-regexp=REGEXP use REGEXP for macro name syntax\n\
-", stdout);
-#endif
- fputs ("\
-\n\
-Preprocessor features:\n\
- -D, --define=NAME[=VALUE] define NAME as having VALUE, or empty\n\
- -I, --include=DIRECTORY append DIRECTORY to include path\n\
- -s, --synclines generate `#line NUM \"FILE\"' lines\n\
- -U, --undefine=NAME undefine NAME\n\
-", stdout);
- puts ("");
- xprintf (_("\
-Limits control:\n\
- -g, --gnu override -G to re-enable GNU extensions\n\
- -G, --traditional suppress all GNU extensions\n\
- -H, --hashsize=PRIME set symbol lookup hash table size [509]\n\
- -L, --nesting-limit=NUMBER change nesting limit, 0 for unlimited [%d]\n\
-"), nesting_limit);
- puts ("");
- fputs ("\
-Frozen state files:\n\
- -F, --freeze-state=FILE produce a frozen state on FILE at end\n\
- -R, --reload-state=FILE reload a frozen state from FILE at start\n\
-", stdout);
- fputs ("\
-\n\
-Debugging:\n\
- -d, --debug[=FLAGS] set debug level (no FLAGS implies `aeq')\n\
- --debugfile[=FILE] redirect debug and trace output to FILE\n\
- (default stderr, discard if empty string)\n\
- -l, --arglength=NUM restrict macro tracing size\n\
- -t, --trace=NAME trace NAME when it is defined\n\
-", stdout);
- fputs ("\
-\n\
-FLAGS is any of:\n\
- a show actual arguments\n\
- c show before collect, after collect and after call\n\
- e show expansion\n\
- f say current input file name\n\
- i show changes in input files\n\
- l say current input line number\n\
- p show results of path searches\n\
- q quote values as necessary, with a or e flag\n\
- t trace for all macro calls, not only traceon'ed\n\
- x add a unique macro call id, useful with c flag\n\
- V shorthand for all of the above flags\n\
-", stdout);
- fputs ("\
-\n\
-If defined, the environment variable `M4PATH' is a colon-separated list\n\
-of directories included after any specified by `-I'.\n\
-", stdout);
- fputs ("\
-\n\
-Exit status is 0 for success, 1 for failure, 63 for frozen file version\n\
-mismatch, or whatever value was passed to the m4exit macro.\n\
-", stdout);
- emit_bug_reporting_address ();
- }
- exit (status);
-}
-
-/*--------------------------------------.
-| Decode options and launch execution. |
-`--------------------------------------*/
-
-/* For long options that have no equivalent short option, use a
- non-character as a pseudo short option, starting with CHAR_MAX + 1. */
-enum
-{
- DEBUGFILE_OPTION = CHAR_MAX + 1, /* no short opt */
- DIVERSIONS_OPTION, /* not quite -N, because of message */
- WARN_MACRO_SEQUENCE_OPTION, /* no short opt */
-
- HELP_OPTION, /* no short opt */
- VERSION_OPTION /* no short opt */
-};
-
-static const struct option long_options[] =
-{
- {"arglength", required_argument, NULL, 'l'},
- {"debug", optional_argument, NULL, 'd'},
- {"define", required_argument, NULL, 'D'},
- {"error-output", required_argument, NULL, 'o'}, /* FIXME: deprecate in 2.0 */
- {"fatal-warnings", no_argument, NULL, 'E'},
- {"freeze-state", required_argument, NULL, 'F'},
- {"gnu", no_argument, NULL, 'g'},
- {"hashsize", required_argument, NULL, 'H'},
- {"include", required_argument, NULL, 'I'},
- {"interactive", no_argument, NULL, 'i'},
- {"nesting-limit", required_argument, NULL, 'L'},
- {"prefix-builtins", no_argument, NULL, 'P'},
- {"quiet", no_argument, NULL, 'Q'},
- {"reload-state", required_argument, NULL, 'R'},
- {"silent", no_argument, NULL, 'Q'},
- {"synclines", no_argument, NULL, 's'},
- {"trace", required_argument, NULL, 't'},
- {"traditional", no_argument, NULL, 'G'},
- {"undefine", required_argument, NULL, 'U'},
- {"word-regexp", required_argument, NULL, 'W'},
-
- {"debugfile", optional_argument, NULL, DEBUGFILE_OPTION},
- {"diversions", required_argument, NULL, DIVERSIONS_OPTION},
- {"warn-macro-sequence", optional_argument, NULL, WARN_MACRO_SEQUENCE_OPTION},
-
- {"help", no_argument, NULL, HELP_OPTION},
- {"version", no_argument, NULL, VERSION_OPTION},
-
- { NULL, 0, NULL, 0 },
-};
-
-/* Process a command line file NAME, and return true only if it was
- stdin. */
-static void
-process_file (const char *name)
-{
- if (STREQ (name, "-"))
- {
- /* If stdin is a terminal, we want to allow 'm4 - file -'
- to read input from stdin twice, like GNU cat. Besides,
- there is no point closing stdin before wrapped text, to
- minimize bugs in syscmd called from wrapped text. */
- push_file (stdin, "stdin", false);
- }
- else
- {
- char *full_name;
- FILE *fp = m4_path_search (name, &full_name);
- if (fp == NULL)
- {
- error (0, errno, _("cannot open `%s'"), name);
- /* Set the status to EXIT_FAILURE, even though we
- continue to process files after a missing file. */
- retcode = EXIT_FAILURE;
- return;
- }
- push_file (fp, full_name, true);
- free (full_name);
- }
- expand_input ();
-}
-
-/* POSIX requires only -D, -U, and -s; and says that the first two
- must be recognized when interspersed with file names. Traditional
- behavior also handles -s between files. Starting OPTSTRING with
- '-' forces getopt_long to hand back file names as arguments to opt
- '\1', rather than reordering the command line. */
-#ifdef ENABLE_CHANGEWORD
-#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:W:d::egil:o:st:"
-#else
-#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:d::egil:o:st:"
-#endif
-
-int
-main (int argc, char *const *argv)
-{
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "m4.h"
+
+#include <getopt.h>
+#include <limits.h>
+#include <signal.h>
+
+#include "c-stack.h"
+#include "ignore-value.h"
+#include "progname.h"
+#include "version-etc.h"
+
+#ifdef DEBUG_STKOVF
+# include "assert.h"
+#endif
+
+#define AUTHORS "Rene' Seindal"
+
+static void usage (int) M4_GNUC_NORETURN;
+
+/* Enable sync output for /lib/cpp (-s). */
+int sync_output = 0;
+
+/* Debug (-d[flags]). */
+int debug_level = 0;
+
+/* Hash table size (should be a prime) (-Hsize). */
+size_t hash_table_size = HASHMAX;
+
+/* Disable GNU extensions (-G). */
+int no_gnu_extensions = 0;
+
+/* Prefix all builtin functions by `m4_'. */
+int prefix_all_builtins = 0;
+
+/* Max length of arguments in trace output (-lsize). */
+int max_debug_argument_length = 0;
+
+/* Suppress warnings about missing arguments. */
+int suppress_warnings = 0;
+
+/* If true, then warnings affect exit status. */
+static bool fatal_warnings = false;
+
+/* If not zero, then value of exit status for warning diagnostics. */
+int warning_status = 0;
+
+/* Artificial limit for expansion_level in macro.c. */
+int nesting_limit = 1024;
+
+#ifdef ENABLE_CHANGEWORD
+/* User provided regexp for describing m4 words. */
+const char *user_word_regexp = "";
+#endif
+
+/* Global catchall for any errors that should affect final error status, but
+ where we try to continue execution in the meantime. */
+int retcode;
+
+struct macro_definition
+{
+ struct macro_definition *next;
+ int code; /* D, U, s, t, '\1', or DEBUGFILE_OPTION. */
+ const char *arg;
+};
+typedef struct macro_definition macro_definition;
+
+/* Error handling functions. */
+
+/*-----------------------.
+| Wrapper around error. |
+`-----------------------*/
+
+void
+m4_error (int status, int errnum, const char *format, ...)
+{
+ va_list args;
+ va_start (args, format);
+ verror_at_line (status, errnum, current_line ? current_file : NULL,
+ current_line, format, args);
+ if (fatal_warnings && ! retcode)
+ retcode = EXIT_FAILURE;
+ va_end (args);
+}
+
+/*-------------------------------.
+| Wrapper around error_at_line. |
+`-------------------------------*/
+
+void
+m4_error_at_line (int status, int errnum, const char *file, int line,
+ const char *format, ...)
+{
+ va_list args;
+ va_start (args, format);
+ verror_at_line (status, errnum, line ? file : NULL, line, format, args);
+ if (fatal_warnings && ! retcode)
+ retcode = EXIT_FAILURE;
+ va_end (args);
+}
+
+#ifndef SIGBUS
+# define SIGBUS SIGILL
+#endif
+
+#ifndef NSIG
+# ifndef MAX
+# define MAX(a,b) ((a) < (b) ? (b) : (a))
+# endif
+# define NSIG (MAX (SIGABRT, MAX (SIGILL, MAX (SIGFPE, \
+ MAX (SIGSEGV, SIGBUS)))) + 1)
+#endif
+
+/* Pre-translated messages for program errors. Do not translate in
+ the signal handler, since gettext and strsignal are not
+ async-signal-safe. */
+static const char * volatile program_error_message;
+static const char * volatile signal_message[NSIG];
+
+/* Print a nicer message about any programmer errors, then exit. This
+ must be aysnc-signal safe, since it is executed as a signal
+ handler. If SIGNO is zero, this represents a stack overflow; in
+ that case, we return to allow c_stack_action to handle things. */
+static void M4_GNUC_PURE
+fault_handler (int signo)
+{
+ if (signo)
+ {
+ /* POSIX states that reading static memory is, in general, not
+ async-safe. However, the static variables that we read are
+ never modified once this handler is installed, so this
+ particular usage is safe. And it seems an oversight that
+ POSIX claims strlen is not async-safe. Ignore write
+ failures, since we will exit with non-zero status anyway. */
+#define WRITE(f, b, l) ignore_value (write (f, b, l))
+ WRITE (STDERR_FILENO, program_name, strlen (program_name));
+ WRITE (STDERR_FILENO, ": ", 2);
+ WRITE (STDERR_FILENO, program_error_message,
+ strlen (program_error_message));
+ if (signal_message[signo])
+ {
+ WRITE (STDERR_FILENO, ": ", 2);
+ WRITE (STDERR_FILENO, signal_message[signo],
+ strlen (signal_message[signo]));
+ }
+ WRITE (STDERR_FILENO, "\n", 1);
+#undef WRITE
+ _exit (EXIT_INTERNAL_ERROR);
+ }
+}
+
+
+/*---------------------------------------------.
+| Print a usage message and exit with STATUS. |
+`---------------------------------------------*/
+
+static void
+usage (int status)
+{
+ if (status != EXIT_SUCCESS)
+ xfprintf (stderr, "Try `%s --help' for more information.\n", program_name);
+ else
+ {
+ xprintf ("Usage: %s [OPTION]... [FILE]...\n", program_name);
+ fputs ("\
+Process macros in FILEs. If no FILE or if FILE is `-', standard input\n\
+is read.\n\
+", stdout);
+ fputs ("\
+\n\
+Mandatory or optional arguments to long options are mandatory or optional\n\
+for short options too.\n\
+\n\
+Operation modes:\n\
+ --help display this help and exit\n\
+ --version output version information and exit\n\
+", stdout);
+ xprintf ("\
+ -E, --fatal-warnings once: warnings become errors, twice: stop\n\
+ execution at first error\n\
+ -i, --interactive unbuffer output, ignore interrupts\n\
+ -P, --prefix-builtins force a `m4_' prefix to all builtins\n\
+ -Q, --quiet, --silent suppress some warnings for builtins\n\
+ --warn-macro-sequence[=REGEXP]\n\
+ warn if macro definition matches REGEXP,\n\
+ default %s\n\
+", DEFAULT_MACRO_SEQUENCE);
+#ifdef ENABLE_CHANGEWORD
+ fputs ("\
+ -W, --word-regexp=REGEXP use REGEXP for macro name syntax\n\
+", stdout);
+#endif
+ fputs ("\
+\n\
+Preprocessor features:\n\
+ -D, --define=NAME[=VALUE] define NAME as having VALUE, or empty\n\
+ -I, --include=DIRECTORY append DIRECTORY to include path\n\
+ -s, --synclines generate `#line NUM \"FILE\"' lines\n\
+ -U, --undefine=NAME undefine NAME\n\
+", stdout);
+ puts ("");
+ xprintf (_("\
+Limits control:\n\
+ -g, --gnu override -G to re-enable GNU extensions\n\
+ -G, --traditional suppress all GNU extensions\n\
+ -H, --hashsize=PRIME set symbol lookup hash table size [509]\n\
+ -L, --nesting-limit=NUMBER change nesting limit, 0 for unlimited [%d]\n\
+"), nesting_limit);
+ puts ("");
+ fputs ("\
+Frozen state files:\n\
+ -F, --freeze-state=FILE produce a frozen state on FILE at end\n\
+ -R, --reload-state=FILE reload a frozen state from FILE at start\n\
+", stdout);
+ fputs ("\
+\n\
+Debugging:\n\
+ -d, --debug[=FLAGS] set debug level (no FLAGS implies `aeq')\n\
+ --debugfile[=FILE] redirect debug and trace output to FILE\n\
+ (default stderr, discard if empty string)\n\
+ -l, --arglength=NUM restrict macro tracing size\n\
+ -t, --trace=NAME trace NAME when it is defined\n\
+", stdout);
+ fputs ("\
+\n\
+FLAGS is any of:\n\
+ a show actual arguments\n\
+ c show before collect, after collect and after call\n\
+ e show expansion\n\
+ f say current input file name\n\
+ i show changes in input files\n\
+ l say current input line number\n\
+ p show results of path searches\n\
+ q quote values as necessary, with a or e flag\n\
+ t trace for all macro calls, not only traceon'ed\n\
+ x add a unique macro call id, useful with c flag\n\
+ V shorthand for all of the above flags\n\
+", stdout);
+ fputs ("\
+\n\
+If defined, the environment variable `M4PATH' is a colon-separated list\n\
+of directories included after any specified by `-I'.\n\
+", stdout);
+ fputs ("\
+\n\
+Exit status is 0 for success, 1 for failure, 63 for frozen file version\n\
+mismatch, or whatever value was passed to the m4exit macro.\n\
+", stdout);
+ emit_bug_reporting_address ();
+ }
+ exit (status);
+}
+
+/*--------------------------------------.
+| Decode options and launch execution. |
+`--------------------------------------*/
+
+/* For long options that have no equivalent short option, use a
+ non-character as a pseudo short option, starting with CHAR_MAX + 1. */
+enum
+{
+ DEBUGFILE_OPTION = CHAR_MAX + 1, /* no short opt */
+ DIVERSIONS_OPTION, /* not quite -N, because of message */
+ WARN_MACRO_SEQUENCE_OPTION, /* no short opt */
+
+ HELP_OPTION, /* no short opt */
+ VERSION_OPTION /* no short opt */
+};
+
+static const struct option long_options[] =
+{
+ {"arglength", required_argument, NULL, 'l'},
+ {"debug", optional_argument, NULL, 'd'},
+ {"define", required_argument, NULL, 'D'},
+ {"error-output", required_argument, NULL, 'o'}, /* FIXME: deprecate in 2.0 */
+ {"fatal-warnings", no_argument, NULL, 'E'},
+ {"freeze-state", required_argument, NULL, 'F'},
+ {"gnu", no_argument, NULL, 'g'},
+ {"hashsize", required_argument, NULL, 'H'},
+ {"include", required_argument, NULL, 'I'},
+ {"interactive", no_argument, NULL, 'i'},
+ {"nesting-limit", required_argument, NULL, 'L'},
+ {"prefix-builtins", no_argument, NULL, 'P'},
+ {"quiet", no_argument, NULL, 'Q'},
+ {"reload-state", required_argument, NULL, 'R'},
+ {"silent", no_argument, NULL, 'Q'},
+ {"synclines", no_argument, NULL, 's'},
+ {"trace", required_argument, NULL, 't'},
+ {"traditional", no_argument, NULL, 'G'},
+ {"undefine", required_argument, NULL, 'U'},
+ {"word-regexp", required_argument, NULL, 'W'},
+
+ {"debugfile", optional_argument, NULL, DEBUGFILE_OPTION},
+ {"diversions", required_argument, NULL, DIVERSIONS_OPTION},
+ {"warn-macro-sequence", optional_argument, NULL, WARN_MACRO_SEQUENCE_OPTION},
+
+ {"help", no_argument, NULL, HELP_OPTION},
+ {"version", no_argument, NULL, VERSION_OPTION},
+
+ { NULL, 0, NULL, 0 },
+};
+
+/* Process a command line file NAME, and return true only if it was
+ stdin. */
+static void
+process_file (const char *name)
+{
+ if (STREQ (name, "-"))
+ {
+ /* If stdin is a terminal, we want to allow 'm4 - file -'
+ to read input from stdin twice, like GNU cat. Besides,
+ there is no point closing stdin before wrapped text, to
+ minimize bugs in syscmd called from wrapped text. */
+ push_file (stdin, "stdin", false);
+ }
+ else
+ {
+ char *full_name;
+ FILE *fp = m4_path_search (name, &full_name);
+ if (fp == NULL)
+ {
+ error (0, errno, _("cannot open `%s'"), name);
+ /* Set the status to EXIT_FAILURE, even though we
+ continue to process files after a missing file. */
+ retcode = EXIT_FAILURE;
+ return;
+ }
+ push_file (fp, full_name, true);
+ free (full_name);
+ }
+ expand_input ();
+}
+
+/* POSIX requires only -D, -U, and -s; and says that the first two
+ must be recognized when interspersed with file names. Traditional
+ behavior also handles -s between files. Starting OPTSTRING with
+ '-' forces getopt_long to hand back file names as arguments to opt
+ '\1', rather than reordering the command line. */
+#ifdef ENABLE_CHANGEWORD
+#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:W:d::egil:o:st:"
+#else
+#define OPTSTRING "-B:D:EF:GH:I:L:N:PQR:S:T:U:d::egil:o:st:"
+#endif
+
+int
+main (int argc, char *const *argv)
+{
#if !defined(_WIN32) && !defined(_WIN64)
- struct sigaction act;
+ struct sigaction act;
#endif
- macro_definition *head; /* head of deferred argument list */
- macro_definition *tail;
- macro_definition *defn;
- int optchar; /* option character */
-
- macro_definition *defines;
- bool interactive = false;
- bool seen_file = false;
- const char *debugfile = NULL;
- const char *frozen_file_to_read = NULL;
- const char *frozen_file_to_write = NULL;
- const char *macro_sequence = "";
-
- set_program_name (argv[0]);
- retcode = EXIT_SUCCESS;
- atexit (close_stdin);
-
- include_init ();
- debug_init ();
-
- /* Stack overflow and program error handling. Ignore failure to
- install a handler, since this is merely for improved output on
- crash, and we should never crash ;). We install SIGBUS and
- SIGSEGV handlers prior to using the c-stack module; depending on
- the platform, c-stack will then override none, SIGSEGV, or both
- handlers. */
- program_error_message
- = xasprintf (_("internal error detected; please report this bug to <%s>"),
- PACKAGE_BUGREPORT);
- signal_message[SIGSEGV] = xstrdup (strsignal (SIGSEGV));
- signal_message[SIGABRT] = xstrdup (strsignal (SIGABRT));
- signal_message[SIGILL] = xstrdup (strsignal (SIGILL));
- signal_message[SIGFPE] = xstrdup (strsignal (SIGFPE));
- if (SIGBUS != SIGILL && SIGBUS != SIGSEGV)
- signal_message[SIGBUS] = xstrdup (strsignal (SIGBUS));
+ macro_definition *head; /* head of deferred argument list */
+ macro_definition *tail;
+ macro_definition *defn;
+ int optchar; /* option character */
+
+ macro_definition *defines;
+ bool interactive = false;
+ bool seen_file = false;
+ const char *debugfile = NULL;
+ const char *frozen_file_to_read = NULL;
+ const char *frozen_file_to_write = NULL;
+ const char *macro_sequence = "";
+
+ set_program_name (argv[0]);
+ retcode = EXIT_SUCCESS;
+ atexit (close_stdin);
+
+ include_init ();
+ debug_init ();
+
+ /* Stack overflow and program error handling. Ignore failure to
+ install a handler, since this is merely for improved output on
+ crash, and we should never crash ;). We install SIGBUS and
+ SIGSEGV handlers prior to using the c-stack module; depending on
+ the platform, c-stack will then override none, SIGSEGV, or both
+ handlers. */
+ program_error_message
+ = xasprintf (_("internal error detected; please report this bug to <%s>"),
+ PACKAGE_BUGREPORT);
+ signal_message[SIGSEGV] = xstrdup (strsignal (SIGSEGV));
+ signal_message[SIGABRT] = xstrdup (strsignal (SIGABRT));
+ signal_message[SIGILL] = xstrdup (strsignal (SIGILL));
+ signal_message[SIGFPE] = xstrdup (strsignal (SIGFPE));
+ if (SIGBUS != SIGILL && SIGBUS != SIGSEGV)
+ signal_message[SIGBUS] = xstrdup (strsignal (SIGBUS));
#if !defined(_WIN32) && !defined(_WIN64)
// No such signals on Windows
sigemptyset(&act.sa_mask);
- /* One-shot - if we fault while handling a fault, we want to revert
- to default signal behavior. */
- act.sa_flags = SA_NODEFER | SA_RESETHAND;
- act.sa_handler = fault_handler;
- sigaction (SIGSEGV, &act, NULL);
- sigaction (SIGABRT, &act, NULL);
- sigaction (SIGILL, &act, NULL);
- sigaction (SIGFPE, &act, NULL);
- sigaction (SIGBUS, &act, NULL);
-#endif
- if (c_stack_action (fault_handler) == 0)
- nesting_limit = 0;
-
-#ifdef DEBUG_STKOVF
- /* Make it easier to test our fault handlers. Exporting M4_CRASH=0
- attempts a SIGSEGV, exporting it as 1 attempts an assertion
- failure with a fallback to abort. */
- {
- char *crash = getenv ("M4_CRASH");
- if (crash)
- {
- if (!strtol (crash, NULL, 10))
- ++*(int *) 8;
- assert (false);
- abort ();
- }
- }
-#endif /* DEBUG_STKOVF */
-
- /* First, we decode the arguments, to size up tables and stuff. */
- head = tail = NULL;
-
- while ((optchar = getopt_long (argc, (char **) argv, OPTSTRING,
- long_options, NULL)) != -1)
- switch (optchar)
- {
- default:
- usage (EXIT_FAILURE);
-
- case 'B':
- case 'S':
- case 'T':
- /* Compatibility junk: options that other implementations
- support, but which we ignore as no-ops and don't list in
- --help. */
- error (0, 0, _("warning: `m4 -%c' may be removed in a future release"),
- optchar);
- break;
-
- case 'N':
- case DIVERSIONS_OPTION:
- /* -N became an obsolete no-op in 1.4.x. */
- error (0, 0, _("warning: `m4 %s' is deprecated"),
- optchar == 'N' ? "-N" : "--diversions");
- break;
-
- case 'D':
- case 'U':
- case 's':
- case 't':
- case '\1':
- case DEBUGFILE_OPTION:
- /* Arguments that cannot be handled until later are accumulated. */
-
- defn = (macro_definition *) xmalloc (sizeof (macro_definition));
- defn->code = optchar;
- defn->arg = optarg;
- defn->next = NULL;
-
- if (head == NULL)
- head = defn;
- else
- tail->next = defn;
- tail = defn;
-
- break;
-
- case 'E':
- if (! fatal_warnings)
- fatal_warnings = true;
- else
- warning_status = EXIT_FAILURE;
- break;
-
- case 'F':
- frozen_file_to_write = optarg;
- break;
-
- case 'G':
- no_gnu_extensions = 1;
- break;
-
- case 'H':
- hash_table_size = strtol (optarg, NULL, 10);
- if (hash_table_size == 0)
- hash_table_size = HASHMAX;
- break;
-
- case 'I':
- add_include_directory (optarg);
- break;
-
- case 'L':
- nesting_limit = strtol (optarg, NULL, 10);
- break;
-
- case 'P':
- prefix_all_builtins = 1;
- break;
-
- case 'Q':
- suppress_warnings = 1;
- break;
-
- case 'R':
- frozen_file_to_read = optarg;
- break;
-
-#ifdef ENABLE_CHANGEWORD
- case 'W':
- user_word_regexp = optarg;
- break;
-#endif
-
- case 'd':
- debug_level = debug_decode (optarg);
- if (debug_level < 0)
- {
- error (0, 0, _("bad debug flags: `%s'"), optarg);
- debug_level = 0;
- }
- break;
-
- case 'e':
- error (0, 0, _("warning: `m4 -e' is deprecated, use `-i' instead"));
- /* fall through */
- case 'i':
- interactive = true;
- break;
-
- case 'g':
- no_gnu_extensions = 0;
- break;
-
- case 'l':
- max_debug_argument_length = strtol (optarg, NULL, 10);
- if (max_debug_argument_length <= 0)
- max_debug_argument_length = 0;
- break;
-
- case 'o':
- /* -o/--error-output are deprecated synonyms of --debugfile,
- but don't issue a deprecation warning until autoconf 2.61
- or later is more widely established, as such a warning
- would interfere with all earlier versions of autoconf. */
- /* Don't call debug_set_output here, as it has side effects. */
- debugfile = optarg;
- break;
-
- case WARN_MACRO_SEQUENCE_OPTION:
- /* Don't call set_macro_sequence here, as it can exit.
- --warn-macro-sequence sets optarg to NULL (which uses the
- default regexp); --warn-macro-sequence= sets optarg to ""
- (which disables these warnings). */
- macro_sequence = optarg;
- break;
-
- case VERSION_OPTION:
- version_etc (stdout, PACKAGE, PACKAGE_NAME, VERSION, AUTHORS, NULL);
- exit (EXIT_SUCCESS);
- break;
-
- case HELP_OPTION:
- usage (EXIT_SUCCESS);
- break;
- }
-
- defines = head;
-
- /* Do the basic initializations. */
- if (debugfile && !debug_set_output (debugfile))
- M4ERROR ((warning_status, errno, "cannot set debug file `%s'", debugfile));
-
- input_init ();
- output_init ();
- symtab_init ();
- set_macro_sequence (macro_sequence);
- include_env_init ();
-
- if (frozen_file_to_read)
- reload_frozen_state (frozen_file_to_read);
- else
- builtin_init ();
-
- /* Interactive mode means unbuffered output, and interrupts ignored. */
-
- if (interactive)
- {
- signal (SIGINT, SIG_IGN);
- setbuf (stdout, (char *) NULL);
- }
-
- /* Handle deferred command line macro definitions. Must come after
- initialization of the symbol table. */
-
- while (defines != NULL)
- {
- macro_definition *next;
- symbol *sym;
-
- switch (defines->code)
- {
- case 'D':
- {
- /* defines->arg is read-only, so we need a copy. */
- char *macro_name = xstrdup (defines->arg);
- char *macro_value = strchr (macro_name, '=');
- if (macro_value)
- *macro_value++ = '\0';
- define_user_macro (macro_name, macro_value, SYMBOL_INSERT);
- free (macro_name);
- }
- break;
-
- case 'U':
- lookup_symbol (defines->arg, SYMBOL_DELETE);
- break;
-
- case 't':
- sym = lookup_symbol (defines->arg, SYMBOL_INSERT);
- SYMBOL_TRACED (sym) = true;
- break;
-
- case 's':
- sync_output = 1;
- break;
-
- case '\1':
- seen_file = true;
- process_file (defines->arg);
- break;
-
- case DEBUGFILE_OPTION:
- if (!debug_set_output (defines->arg))
- M4ERROR ((warning_status, errno, "cannot set debug file `%s'",
- debugfile ? debugfile : _("stderr")));
- break;
-
- default:
- M4ERROR ((0, 0, "INTERNAL ERROR: bad code in deferred arguments"));
- abort ();
- }
-
- next = defines->next;
- free (defines);
- defines = next;
- }
-
- /* Handle remaining input files. Each file is pushed on the input,
- and the input read. Wrapup text is handled separately later. */
-
- if (optind == argc && !seen_file)
- process_file ("-");
- else
- for (; optind < argc; optind++)
- process_file (argv[optind]);
-
- /* Now handle wrapup text. */
-
- while (pop_wrapup ())
- expand_input ();
-
- /* Change debug stream back to stderr, to force flushing the debug
- stream and detect any errors it might have encountered. The
- three standard streams are closed by close_stdin. */
- debug_set_output (NULL);
-
- if (frozen_file_to_write)
- produce_frozen_state (frozen_file_to_write);
- else
- {
- make_diversion (0);
- undivert_all ();
- }
- output_exit ();
- free_macro_sequence ();
- exit (retcode);
-}
+ /* One-shot - if we fault while handling a fault, we want to revert
+ to default signal behavior. */
+ act.sa_flags = SA_NODEFER | SA_RESETHAND;
+ act.sa_handler = fault_handler;
+ sigaction (SIGSEGV, &act, NULL);
+ sigaction (SIGABRT, &act, NULL);
+ sigaction (SIGILL, &act, NULL);
+ sigaction (SIGFPE, &act, NULL);
+ sigaction (SIGBUS, &act, NULL);
+#endif
+ if (c_stack_action (fault_handler) == 0)
+ nesting_limit = 0;
+
+#ifdef DEBUG_STKOVF
+ /* Make it easier to test our fault handlers. Exporting M4_CRASH=0
+ attempts a SIGSEGV, exporting it as 1 attempts an assertion
+ failure with a fallback to abort. */
+ {
+ char *crash = getenv ("M4_CRASH");
+ if (crash)
+ {
+ if (!strtol (crash, NULL, 10))
+ ++*(int *) 8;
+ assert (false);
+ abort ();
+ }
+ }
+#endif /* DEBUG_STKOVF */
+
+ /* First, we decode the arguments, to size up tables and stuff. */
+ head = tail = NULL;
+
+ while ((optchar = getopt_long (argc, (char **) argv, OPTSTRING,
+ long_options, NULL)) != -1)
+ switch (optchar)
+ {
+ default:
+ usage (EXIT_FAILURE);
+
+ case 'B':
+ case 'S':
+ case 'T':
+ /* Compatibility junk: options that other implementations
+ support, but which we ignore as no-ops and don't list in
+ --help. */
+ error (0, 0, _("warning: `m4 -%c' may be removed in a future release"),
+ optchar);
+ break;
+
+ case 'N':
+ case DIVERSIONS_OPTION:
+ /* -N became an obsolete no-op in 1.4.x. */
+ error (0, 0, _("warning: `m4 %s' is deprecated"),
+ optchar == 'N' ? "-N" : "--diversions");
+ break;
+
+ case 'D':
+ case 'U':
+ case 's':
+ case 't':
+ case '\1':
+ case DEBUGFILE_OPTION:
+ /* Arguments that cannot be handled until later are accumulated. */
+
+ defn = (macro_definition *) xmalloc (sizeof (macro_definition));
+ defn->code = optchar;
+ defn->arg = optarg;
+ defn->next = NULL;
+
+ if (head == NULL)
+ head = defn;
+ else
+ tail->next = defn;
+ tail = defn;
+
+ break;
+
+ case 'E':
+ if (! fatal_warnings)
+ fatal_warnings = true;
+ else
+ warning_status = EXIT_FAILURE;
+ break;
+
+ case 'F':
+ frozen_file_to_write = optarg;
+ break;
+
+ case 'G':
+ no_gnu_extensions = 1;
+ break;
+
+ case 'H':
+ hash_table_size = strtol (optarg, NULL, 10);
+ if (hash_table_size == 0)
+ hash_table_size = HASHMAX;
+ break;
+
+ case 'I':
+ add_include_directory (optarg);
+ break;
+
+ case 'L':
+ nesting_limit = strtol (optarg, NULL, 10);
+ break;
+
+ case 'P':
+ prefix_all_builtins = 1;
+ break;
+
+ case 'Q':
+ suppress_warnings = 1;
+ break;
+
+ case 'R':
+ frozen_file_to_read = optarg;
+ break;
+
+#ifdef ENABLE_CHANGEWORD
+ case 'W':
+ user_word_regexp = optarg;
+ break;
+#endif
+
+ case 'd':
+ debug_level = debug_decode (optarg);
+ if (debug_level < 0)
+ {
+ error (0, 0, _("bad debug flags: `%s'"), optarg);
+ debug_level = 0;
+ }
+ break;
+
+ case 'e':
+ error (0, 0, _("warning: `m4 -e' is deprecated, use `-i' instead"));
+ /* fall through */
+ case 'i':
+ interactive = true;
+ break;
+
+ case 'g':
+ no_gnu_extensions = 0;
+ break;
+
+ case 'l':
+ max_debug_argument_length = strtol (optarg, NULL, 10);
+ if (max_debug_argument_length <= 0)
+ max_debug_argument_length = 0;
+ break;
+
+ case 'o':
+ /* -o/--error-output are deprecated synonyms of --debugfile,
+ but don't issue a deprecation warning until autoconf 2.61
+ or later is more widely established, as such a warning
+ would interfere with all earlier versions of autoconf. */
+ /* Don't call debug_set_output here, as it has side effects. */
+ debugfile = optarg;
+ break;
+
+ case WARN_MACRO_SEQUENCE_OPTION:
+ /* Don't call set_macro_sequence here, as it can exit.
+ --warn-macro-sequence sets optarg to NULL (which uses the
+ default regexp); --warn-macro-sequence= sets optarg to ""
+ (which disables these warnings). */
+ macro_sequence = optarg;
+ break;
+
+ case VERSION_OPTION:
+ version_etc (stdout, PACKAGE, PACKAGE_NAME, VERSION, AUTHORS, NULL);
+ exit (EXIT_SUCCESS);
+ break;
+
+ case HELP_OPTION:
+ usage (EXIT_SUCCESS);
+ break;
+ }
+
+ defines = head;
+
+ /* Do the basic initializations. */
+ if (debugfile && !debug_set_output (debugfile))
+ M4ERROR ((warning_status, errno, "cannot set debug file `%s'", debugfile));
+
+ input_init ();
+ output_init ();
+ symtab_init ();
+ set_macro_sequence (macro_sequence);
+ include_env_init ();
+
+ if (frozen_file_to_read)
+ reload_frozen_state (frozen_file_to_read);
+ else
+ builtin_init ();
+
+ /* Interactive mode means unbuffered output, and interrupts ignored. */
+
+ if (interactive)
+ {
+ signal (SIGINT, SIG_IGN);
+ setbuf (stdout, (char *) NULL);
+ }
+
+ /* Handle deferred command line macro definitions. Must come after
+ initialization of the symbol table. */
+
+ while (defines != NULL)
+ {
+ macro_definition *next;
+ symbol *sym;
+
+ switch (defines->code)
+ {
+ case 'D':
+ {
+ /* defines->arg is read-only, so we need a copy. */
+ char *macro_name = xstrdup (defines->arg);
+ char *macro_value = strchr (macro_name, '=');
+ if (macro_value)
+ *macro_value++ = '\0';
+ define_user_macro (macro_name, macro_value, SYMBOL_INSERT);
+ free (macro_name);
+ }
+ break;
+
+ case 'U':
+ lookup_symbol (defines->arg, SYMBOL_DELETE);
+ break;
+
+ case 't':
+ sym = lookup_symbol (defines->arg, SYMBOL_INSERT);
+ SYMBOL_TRACED (sym) = true;
+ break;
+
+ case 's':
+ sync_output = 1;
+ break;
+
+ case '\1':
+ seen_file = true;
+ process_file (defines->arg);
+ break;
+
+ case DEBUGFILE_OPTION:
+ if (!debug_set_output (defines->arg))
+ M4ERROR ((warning_status, errno, "cannot set debug file `%s'",
+ debugfile ? debugfile : _("stderr")));
+ break;
+
+ default:
+ M4ERROR ((0, 0, "INTERNAL ERROR: bad code in deferred arguments"));
+ abort ();
+ }
+
+ next = defines->next;
+ free (defines);
+ defines = next;
+ }
+
+ /* Handle remaining input files. Each file is pushed on the input,
+ and the input read. Wrapup text is handled separately later. */
+
+ if (optind == argc && !seen_file)
+ process_file ("-");
+ else
+ for (; optind < argc; optind++)
+ process_file (argv[optind]);
+
+ /* Now handle wrapup text. */
+
+ while (pop_wrapup ())
+ expand_input ();
+
+ /* Change debug stream back to stderr, to force flushing the debug
+ stream and detect any errors it might have encountered. The
+ three standard streams are closed by close_stdin. */
+ debug_set_output (NULL);
+
+ if (frozen_file_to_write)
+ produce_frozen_state (frozen_file_to_write);
+ else
+ {
+ make_diversion (0);
+ undivert_all ();
+ }
+ output_exit ();
+ free_macro_sequence ();
+ exit (retcode);
+}
diff --git a/contrib/tools/bison/m4/src/m4.h b/contrib/tools/bison/m4/src/m4.h
index eb2a96784f..00e0dd8c83 100644
--- a/contrib/tools/bison/m4/src/m4.h
+++ b/contrib/tools/bison/m4/src/m4.h
@@ -1,491 +1,491 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* We use <config.h> instead of "config.h" so that a compilation
- using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
- (which it would do because it found this file in $srcdir). */
-
-#include <config.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdint.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include "binary-io.h"
-#include "clean-temp.h"
-#include "cloexec.h"
-#include "close-stream.h"
-#include "closein.h"
-#include "dirname.h"
-#include "error.h"
-#include "exitfail.h"
-#include "filenamecat.h"
-#include "obstack.h"
-#include "stdio--.h"
-#include "stdlib--.h"
-#include "unistd--.h"
-#include "verror.h"
-#include "xalloc.h"
-#include "xprintf.h"
-#include "xvasprintf.h"
-
-/* Canonicalize UNIX recognition macros. */
-#if defined unix || defined __unix || defined __unix__ \
- || defined _POSIX_VERSION || defined _POSIX2_VERSION \
- || defined __NetBSD__ || defined __OpenBSD__ \
- || defined __APPLE__ || defined __APPLE_CC__
-# define UNIX 1
-#endif
-
-/* Canonicalize Windows recognition macros. */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
-# define W32_NATIVE 1
-#endif
-
-/* Canonicalize OS/2 recognition macro. */
-#ifdef __EMX__
-# define OS2 1
-# undef UNIX
-#endif
-
-/* Used if any programmer error is detected (not possible, right?) */
-#define EXIT_INTERNAL_ERROR 2
-
-/* Used for version mismatch, when -R detects a frozen file it can't parse. */
-#define EXIT_MISMATCH 63
-
-/* No-op, for future gettext compatibility. */
-#define _(ARG) ARG
-
-/* Various declarations. */
-
-struct string
- {
- char *string; /* characters of the string */
- size_t length; /* length of the string */
- };
-typedef struct string STRING;
-
-/* Memory allocation. */
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
-
-/* Those must come first. */
-typedef struct token_data token_data;
-typedef void builtin_func (struct obstack *, int, token_data **);
-
-/* Gnulib's stdbool doesn't work with bool bitfields. For nicer
- debugging, use bool when we know it works, but use the more
- portable unsigned int elsewhere. */
-#if __GNUC__ > 2
-typedef bool bool_bitfield;
-#else
-typedef unsigned int bool_bitfield;
-#endif /* ! __GNUC__ */
-
-/* Take advantage of GNU C compiler source level optimization hints,
- using portable macros. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 6)
-# define M4_GNUC_ATTRIBUTE(args) __attribute__ (args)
-#else
-# define M4_GNUC_ATTRIBUTE(args)
-#endif /* __GNUC__ */
-
-#define M4_GNUC_UNUSED M4_GNUC_ATTRIBUTE ((__unused__))
-#define M4_GNUC_PRINTF(fmt, arg) \
- M4_GNUC_ATTRIBUTE ((__format__ (__printf__, fmt, arg)))
-#define M4_GNUC_NORETURN M4_GNUC_ATTRIBUTE ((__noreturn__))
-#define M4_GNUC_PURE M4_GNUC_ATTRIBUTE ((__pure__))
-
-/* File: m4.c --- global definitions. */
-
-/* Option flags. */
-extern int sync_output; /* -s */
-extern int debug_level; /* -d */
-extern size_t hash_table_size; /* -H */
-extern int no_gnu_extensions; /* -G */
-extern int prefix_all_builtins; /* -P */
-extern int max_debug_argument_length; /* -l */
-extern int suppress_warnings; /* -Q */
-extern int warning_status; /* -E */
-extern int nesting_limit; /* -L */
-#ifdef ENABLE_CHANGEWORD
-extern const char *user_word_regexp; /* -W */
-#endif
-
-/* Error handling. */
-extern int retcode;
-
-extern void m4_error (int, int, const char *, ...) M4_GNUC_PRINTF(3, 4);
-extern void m4_error_at_line (int, int, const char *, int,
- const char *, ...) M4_GNUC_PRINTF(5, 6);
-
-#define M4ERROR(Arglist) (m4_error Arglist)
-#define M4ERROR_AT_LINE(Arglist) (m4_error_at_line Arglist)
-
-
-/* File: debug.c --- debugging and tracing function. */
-
-extern FILE *debug;
-
-/* The value of debug_level is a bitmask of the following. */
-
-/* a: show arglist in trace output */
-#define DEBUG_TRACE_ARGS 1
-/* e: show expansion in trace output */
-#define DEBUG_TRACE_EXPANSION 2
-/* q: quote args and expansion in trace output */
-#define DEBUG_TRACE_QUOTE 4
-/* t: trace all macros -- overrides trace{on,off} */
-#define DEBUG_TRACE_ALL 8
-/* l: add line numbers to trace output */
-#define DEBUG_TRACE_LINE 16
-/* f: add file name to trace output */
-#define DEBUG_TRACE_FILE 32
-/* p: trace path search of include files */
-#define DEBUG_TRACE_PATH 64
-/* c: show macro call before args collection */
-#define DEBUG_TRACE_CALL 128
-/* i: trace changes of input files */
-#define DEBUG_TRACE_INPUT 256
-/* x: add call id to trace output */
-#define DEBUG_TRACE_CALLID 512
-
-/* V: very verbose -- print everything */
-#define DEBUG_TRACE_VERBOSE 1023
-/* default flags -- equiv: aeq */
-#define DEBUG_TRACE_DEFAULT 7
-
-#define DEBUG_PRINT1(Fmt, Arg1) \
- do \
- { \
- if (debug != NULL) \
- xfprintf (debug, Fmt, Arg1); \
- } \
- while (0)
-
-#define DEBUG_PRINT3(Fmt, Arg1, Arg2, Arg3) \
- do \
- { \
- if (debug != NULL) \
- xfprintf (debug, Fmt, Arg1, Arg2, Arg3); \
- } \
- while (0)
-
-#define DEBUG_MESSAGE(Fmt) \
- do \
- { \
- if (debug != NULL) \
- { \
- debug_message_prefix (); \
- xfprintf (debug, Fmt); \
- putc ('\n', debug); \
- } \
- } \
- while (0)
-
-#define DEBUG_MESSAGE1(Fmt, Arg1) \
- do \
- { \
- if (debug != NULL) \
- { \
- debug_message_prefix (); \
- xfprintf (debug, Fmt, Arg1); \
- putc ('\n', debug); \
- } \
- } \
- while (0)
-
-#define DEBUG_MESSAGE2(Fmt, Arg1, Arg2) \
- do \
- { \
- if (debug != NULL) \
- { \
- debug_message_prefix (); \
- xfprintf (debug, Fmt, Arg1, Arg2); \
- putc ('\n', debug); \
- } \
- } \
- while (0)
-
-extern void debug_init (void);
-extern int debug_decode (const char *);
-extern void debug_flush_files (void);
-extern bool debug_set_output (const char *);
-extern void debug_message_prefix (void);
-
-extern void trace_prepre (const char *, int);
-extern void trace_pre (const char *, int, int, token_data **);
-extern void trace_post (const char *, int, int, const char *);
-
-/* File: input.c --- lexical definitions. */
-
-/* Various different token types. */
-enum token_type
-{
- TOKEN_EOF, /* end of file */
- TOKEN_STRING, /* a quoted string or comment */
- TOKEN_WORD, /* an identifier */
- TOKEN_OPEN, /* ( */
- TOKEN_COMMA, /* , */
- TOKEN_CLOSE, /* ) */
- TOKEN_SIMPLE, /* any other single character */
- TOKEN_MACDEF /* a macro's definition (see "defn") */
-};
-
-/* The data for a token, a macro argument, and a macro definition. */
-enum token_data_type
-{
- TOKEN_VOID,
- TOKEN_TEXT,
- TOKEN_FUNC
-};
-
-struct token_data
-{
- enum token_data_type type;
- union
- {
- struct
- {
- char *text;
-#ifdef ENABLE_CHANGEWORD
- char *original_text;
-#endif
- }
- u_t;
- builtin_func *func;
- }
- u;
-};
-
-#define TOKEN_DATA_TYPE(Td) ((Td)->type)
-#define TOKEN_DATA_TEXT(Td) ((Td)->u.u_t.text)
-#ifdef ENABLE_CHANGEWORD
-# define TOKEN_DATA_ORIG_TEXT(Td) ((Td)->u.u_t.original_text)
-#endif
-#define TOKEN_DATA_FUNC(Td) ((Td)->u.func)
-
-typedef enum token_type token_type;
-typedef enum token_data_type token_data_type;
-
-extern void input_init (void);
-extern token_type peek_token (void);
-extern token_type next_token (token_data *, int *);
-extern void skip_line (void);
-
-/* push back input */
-extern void push_file (FILE *, const char *, bool);
-extern void push_macro (builtin_func *);
-extern struct obstack *push_string_init (void);
-extern const char *push_string_finish (void);
-extern void push_wrapup (const char *);
-extern bool pop_wrapup (void);
-
-/* current input file, and line */
-extern const char *current_file;
-extern int current_line;
-
-/* left and right quote, begin and end comment */
-extern STRING bcomm;
-extern STRING ecomm;
-extern STRING lquote;
-extern STRING rquote;
-
-#define DEF_LQUOTE "`"
-#define DEF_RQUOTE "\'"
-#define DEF_BCOMM "#"
-#define DEF_ECOMM "\n"
-
-extern void set_quotes (const char *, const char *);
-extern void set_comment (const char *, const char *);
-#ifdef ENABLE_CHANGEWORD
-extern void set_word_regexp (const char *);
-#endif
-
-/* File: output.c --- output functions. */
-extern int current_diversion;
-extern int output_current_line;
-
-extern void output_init (void);
-extern void output_exit (void);
-extern void output_text (const char *, int);
-extern void shipout_text (struct obstack *, const char *, int, int);
-extern void make_diversion (int);
-extern void insert_diversion (int);
-extern void insert_file (FILE *);
-extern void freeze_diversions (FILE *);
-
-/* File symtab.c --- symbol table definitions. */
-
-/* Operation modes for lookup_symbol (). */
-enum symbol_lookup
-{
- SYMBOL_LOOKUP,
- SYMBOL_INSERT,
- SYMBOL_DELETE,
- SYMBOL_PUSHDEF,
- SYMBOL_POPDEF
-};
-
-/* Symbol table entry. */
-struct symbol
-{
- struct symbol *next;
- bool_bitfield traced : 1;
- bool_bitfield shadowed : 1;
- bool_bitfield macro_args : 1;
- bool_bitfield blind_no_args : 1;
- bool_bitfield deleted : 1;
- int pending_expansions;
-
- char *name;
- token_data data;
-};
-
-#define SYMBOL_NEXT(S) ((S)->next)
-#define SYMBOL_TRACED(S) ((S)->traced)
-#define SYMBOL_SHADOWED(S) ((S)->shadowed)
-#define SYMBOL_MACRO_ARGS(S) ((S)->macro_args)
-#define SYMBOL_BLIND_NO_ARGS(S) ((S)->blind_no_args)
-#define SYMBOL_DELETED(S) ((S)->deleted)
-#define SYMBOL_PENDING_EXPANSIONS(S) ((S)->pending_expansions)
-#define SYMBOL_NAME(S) ((S)->name)
-#define SYMBOL_TYPE(S) (TOKEN_DATA_TYPE (&(S)->data))
-#define SYMBOL_TEXT(S) (TOKEN_DATA_TEXT (&(S)->data))
-#define SYMBOL_FUNC(S) (TOKEN_DATA_FUNC (&(S)->data))
-
-typedef enum symbol_lookup symbol_lookup;
-typedef struct symbol symbol;
-typedef void hack_symbol (symbol *, void *);
-
-#define HASHMAX 509 /* default, overridden by -Hsize */
-
-extern symbol **symtab;
-
-extern void free_symbol (symbol *sym);
-extern void symtab_init (void);
-extern symbol *lookup_symbol (const char *, symbol_lookup);
-extern void hack_all_symbols (hack_symbol *, void *);
-
-/* File: macro.c --- macro expansion. */
-
-extern int expansion_level;
-
-extern void expand_input (void);
-extern void call_macro (symbol *, int, token_data **, struct obstack *);
-
-/* File: builtin.c --- builtins. */
-
-struct builtin
-{
- const char *name;
- bool_bitfield gnu_extension : 1;
- bool_bitfield groks_macro_args : 1;
- bool_bitfield blind_if_no_args : 1;
- builtin_func *func;
-};
-
-struct predefined
-{
- const char *unix_name;
- const char *gnu_name;
- const char *func;
-};
-
-typedef struct builtin builtin;
-typedef struct predefined predefined;
-struct re_pattern_buffer;
-struct re_registers;
-
-/* The default sequence detects multi-digit parameters (obsolete after
- 1.4.x), and any use of extended arguments with the default ${}
- syntax (new in 2.0). */
-#define DEFAULT_MACRO_SEQUENCE "\\$\\({[^}]*}\\|[0-9][0-9]+\\)"
-
-extern void builtin_init (void);
-extern void define_builtin (const char *, const builtin *, symbol_lookup);
-extern void set_macro_sequence (const char *);
-extern void free_macro_sequence (void);
-extern void define_user_macro (const char *, const char *, symbol_lookup);
-extern void undivert_all (void);
-extern void expand_user_macro (struct obstack *, symbol *, int, token_data **);
-extern void m4_placeholder (struct obstack *, int, token_data **);
-extern void init_pattern_buffer (struct re_pattern_buffer *,
- struct re_registers *);
-extern const char *ntoa (int32_t, int);
-
-extern const builtin *find_builtin_by_addr (builtin_func *);
-extern const builtin *find_builtin_by_name (const char *);
-
-/* File: path.c --- path search for include files. */
-
-extern void include_init (void);
-extern void include_env_init (void);
-extern void add_include_directory (const char *);
-extern FILE *m4_path_search (const char *, char **);
-
-/* File: eval.c --- expression evaluation. */
-
-extern bool evaluate (const char *, int32_t *);
-
-/* File: format.c --- printf like formatting. */
-
-extern void expand_format (struct obstack *, int, token_data **);
-
-/* File: freeze.c --- frozen state files. */
-
-extern void produce_frozen_state (const char *);
-extern void reload_frozen_state (const char *);
-
-/* Debugging the memory allocator. */
-
-#ifdef WITH_DMALLOC
-# define DMALLOC_FUNC_CHECK
-# include <dmalloc.h>
-#endif
-
-/* Other debug stuff. */
-
-#ifdef DEBUG
-# define DEBUG_INCL 1
-# define DEBUG_INPUT 1
-# define DEBUG_MACRO 1
-# define DEBUG_OUTPUT 1
-# define DEBUG_STKOVF 1
-# define DEBUG_SYM 1
-#endif
-
-/* Convert a possibly-signed character to an unsigned character. This is
- a bit safer than casting to unsigned char, since it catches some type
- errors that the cast doesn't. */
-#if HAVE_INLINE
-static inline unsigned char to_uchar (char ch) { return ch; }
-#else
-# define to_uchar(C) ((unsigned char) (C))
-#endif
-
-/* Avoid negative logic when comparing two strings. */
-#define STREQ(a, b) (strcmp (a, b) == 0)
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* We use <config.h> instead of "config.h" so that a compilation
+ using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+ (which it would do because it found this file in $srcdir). */
+
+#include <config.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "binary-io.h"
+#include "clean-temp.h"
+#include "cloexec.h"
+#include "close-stream.h"
+#include "closein.h"
+#include "dirname.h"
+#include "error.h"
+#include "exitfail.h"
+#include "filenamecat.h"
+#include "obstack.h"
+#include "stdio--.h"
+#include "stdlib--.h"
+#include "unistd--.h"
+#include "verror.h"
+#include "xalloc.h"
+#include "xprintf.h"
+#include "xvasprintf.h"
+
+/* Canonicalize UNIX recognition macros. */
+#if defined unix || defined __unix || defined __unix__ \
+ || defined _POSIX_VERSION || defined _POSIX2_VERSION \
+ || defined __NetBSD__ || defined __OpenBSD__ \
+ || defined __APPLE__ || defined __APPLE_CC__
+# define UNIX 1
+#endif
+
+/* Canonicalize Windows recognition macros. */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+# define W32_NATIVE 1
+#endif
+
+/* Canonicalize OS/2 recognition macro. */
+#ifdef __EMX__
+# define OS2 1
+# undef UNIX
+#endif
+
+/* Used if any programmer error is detected (not possible, right?) */
+#define EXIT_INTERNAL_ERROR 2
+
+/* Used for version mismatch, when -R detects a frozen file it can't parse. */
+#define EXIT_MISMATCH 63
+
+/* No-op, for future gettext compatibility. */
+#define _(ARG) ARG
+
+/* Various declarations. */
+
+struct string
+ {
+ char *string; /* characters of the string */
+ size_t length; /* length of the string */
+ };
+typedef struct string STRING;
+
+/* Memory allocation. */
+#define obstack_chunk_alloc xmalloc
+#define obstack_chunk_free free
+
+/* Those must come first. */
+typedef struct token_data token_data;
+typedef void builtin_func (struct obstack *, int, token_data **);
+
+/* Gnulib's stdbool doesn't work with bool bitfields. For nicer
+ debugging, use bool when we know it works, but use the more
+ portable unsigned int elsewhere. */
+#if __GNUC__ > 2
+typedef bool bool_bitfield;
+#else
+typedef unsigned int bool_bitfield;
+#endif /* ! __GNUC__ */
+
+/* Take advantage of GNU C compiler source level optimization hints,
+ using portable macros. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 6)
+# define M4_GNUC_ATTRIBUTE(args) __attribute__ (args)
+#else
+# define M4_GNUC_ATTRIBUTE(args)
+#endif /* __GNUC__ */
+
+#define M4_GNUC_UNUSED M4_GNUC_ATTRIBUTE ((__unused__))
+#define M4_GNUC_PRINTF(fmt, arg) \
+ M4_GNUC_ATTRIBUTE ((__format__ (__printf__, fmt, arg)))
+#define M4_GNUC_NORETURN M4_GNUC_ATTRIBUTE ((__noreturn__))
+#define M4_GNUC_PURE M4_GNUC_ATTRIBUTE ((__pure__))
+
+/* File: m4.c --- global definitions. */
+
+/* Option flags. */
+extern int sync_output; /* -s */
+extern int debug_level; /* -d */
+extern size_t hash_table_size; /* -H */
+extern int no_gnu_extensions; /* -G */
+extern int prefix_all_builtins; /* -P */
+extern int max_debug_argument_length; /* -l */
+extern int suppress_warnings; /* -Q */
+extern int warning_status; /* -E */
+extern int nesting_limit; /* -L */
+#ifdef ENABLE_CHANGEWORD
+extern const char *user_word_regexp; /* -W */
+#endif
+
+/* Error handling. */
+extern int retcode;
+
+extern void m4_error (int, int, const char *, ...) M4_GNUC_PRINTF(3, 4);
+extern void m4_error_at_line (int, int, const char *, int,
+ const char *, ...) M4_GNUC_PRINTF(5, 6);
+
+#define M4ERROR(Arglist) (m4_error Arglist)
+#define M4ERROR_AT_LINE(Arglist) (m4_error_at_line Arglist)
+
+
+/* File: debug.c --- debugging and tracing function. */
+
+extern FILE *debug;
+
+/* The value of debug_level is a bitmask of the following. */
+
+/* a: show arglist in trace output */
+#define DEBUG_TRACE_ARGS 1
+/* e: show expansion in trace output */
+#define DEBUG_TRACE_EXPANSION 2
+/* q: quote args and expansion in trace output */
+#define DEBUG_TRACE_QUOTE 4
+/* t: trace all macros -- overrides trace{on,off} */
+#define DEBUG_TRACE_ALL 8
+/* l: add line numbers to trace output */
+#define DEBUG_TRACE_LINE 16
+/* f: add file name to trace output */
+#define DEBUG_TRACE_FILE 32
+/* p: trace path search of include files */
+#define DEBUG_TRACE_PATH 64
+/* c: show macro call before args collection */
+#define DEBUG_TRACE_CALL 128
+/* i: trace changes of input files */
+#define DEBUG_TRACE_INPUT 256
+/* x: add call id to trace output */
+#define DEBUG_TRACE_CALLID 512
+
+/* V: very verbose -- print everything */
+#define DEBUG_TRACE_VERBOSE 1023
+/* default flags -- equiv: aeq */
+#define DEBUG_TRACE_DEFAULT 7
+
+#define DEBUG_PRINT1(Fmt, Arg1) \
+ do \
+ { \
+ if (debug != NULL) \
+ xfprintf (debug, Fmt, Arg1); \
+ } \
+ while (0)
+
+#define DEBUG_PRINT3(Fmt, Arg1, Arg2, Arg3) \
+ do \
+ { \
+ if (debug != NULL) \
+ xfprintf (debug, Fmt, Arg1, Arg2, Arg3); \
+ } \
+ while (0)
+
+#define DEBUG_MESSAGE(Fmt) \
+ do \
+ { \
+ if (debug != NULL) \
+ { \
+ debug_message_prefix (); \
+ xfprintf (debug, Fmt); \
+ putc ('\n', debug); \
+ } \
+ } \
+ while (0)
+
+#define DEBUG_MESSAGE1(Fmt, Arg1) \
+ do \
+ { \
+ if (debug != NULL) \
+ { \
+ debug_message_prefix (); \
+ xfprintf (debug, Fmt, Arg1); \
+ putc ('\n', debug); \
+ } \
+ } \
+ while (0)
+
+#define DEBUG_MESSAGE2(Fmt, Arg1, Arg2) \
+ do \
+ { \
+ if (debug != NULL) \
+ { \
+ debug_message_prefix (); \
+ xfprintf (debug, Fmt, Arg1, Arg2); \
+ putc ('\n', debug); \
+ } \
+ } \
+ while (0)
+
+extern void debug_init (void);
+extern int debug_decode (const char *);
+extern void debug_flush_files (void);
+extern bool debug_set_output (const char *);
+extern void debug_message_prefix (void);
+
+extern void trace_prepre (const char *, int);
+extern void trace_pre (const char *, int, int, token_data **);
+extern void trace_post (const char *, int, int, const char *);
+
+/* File: input.c --- lexical definitions. */
+
+/* Various different token types. */
+enum token_type
+{
+ TOKEN_EOF, /* end of file */
+ TOKEN_STRING, /* a quoted string or comment */
+ TOKEN_WORD, /* an identifier */
+ TOKEN_OPEN, /* ( */
+ TOKEN_COMMA, /* , */
+ TOKEN_CLOSE, /* ) */
+ TOKEN_SIMPLE, /* any other single character */
+ TOKEN_MACDEF /* a macro's definition (see "defn") */
+};
+
+/* The data for a token, a macro argument, and a macro definition. */
+enum token_data_type
+{
+ TOKEN_VOID,
+ TOKEN_TEXT,
+ TOKEN_FUNC
+};
+
+struct token_data
+{
+ enum token_data_type type;
+ union
+ {
+ struct
+ {
+ char *text;
+#ifdef ENABLE_CHANGEWORD
+ char *original_text;
+#endif
+ }
+ u_t;
+ builtin_func *func;
+ }
+ u;
+};
+
+#define TOKEN_DATA_TYPE(Td) ((Td)->type)
+#define TOKEN_DATA_TEXT(Td) ((Td)->u.u_t.text)
+#ifdef ENABLE_CHANGEWORD
+# define TOKEN_DATA_ORIG_TEXT(Td) ((Td)->u.u_t.original_text)
+#endif
+#define TOKEN_DATA_FUNC(Td) ((Td)->u.func)
+
+typedef enum token_type token_type;
+typedef enum token_data_type token_data_type;
+
+extern void input_init (void);
+extern token_type peek_token (void);
+extern token_type next_token (token_data *, int *);
+extern void skip_line (void);
+
+/* push back input */
+extern void push_file (FILE *, const char *, bool);
+extern void push_macro (builtin_func *);
+extern struct obstack *push_string_init (void);
+extern const char *push_string_finish (void);
+extern void push_wrapup (const char *);
+extern bool pop_wrapup (void);
+
+/* current input file, and line */
+extern const char *current_file;
+extern int current_line;
+
+/* left and right quote, begin and end comment */
+extern STRING bcomm;
+extern STRING ecomm;
+extern STRING lquote;
+extern STRING rquote;
+
+#define DEF_LQUOTE "`"
+#define DEF_RQUOTE "\'"
+#define DEF_BCOMM "#"
+#define DEF_ECOMM "\n"
+
+extern void set_quotes (const char *, const char *);
+extern void set_comment (const char *, const char *);
+#ifdef ENABLE_CHANGEWORD
+extern void set_word_regexp (const char *);
+#endif
+
+/* File: output.c --- output functions. */
+extern int current_diversion;
+extern int output_current_line;
+
+extern void output_init (void);
+extern void output_exit (void);
+extern void output_text (const char *, int);
+extern void shipout_text (struct obstack *, const char *, int, int);
+extern void make_diversion (int);
+extern void insert_diversion (int);
+extern void insert_file (FILE *);
+extern void freeze_diversions (FILE *);
+
+/* File symtab.c --- symbol table definitions. */
+
+/* Operation modes for lookup_symbol (). */
+enum symbol_lookup
+{
+ SYMBOL_LOOKUP,
+ SYMBOL_INSERT,
+ SYMBOL_DELETE,
+ SYMBOL_PUSHDEF,
+ SYMBOL_POPDEF
+};
+
+/* Symbol table entry. */
+struct symbol
+{
+ struct symbol *next;
+ bool_bitfield traced : 1;
+ bool_bitfield shadowed : 1;
+ bool_bitfield macro_args : 1;
+ bool_bitfield blind_no_args : 1;
+ bool_bitfield deleted : 1;
+ int pending_expansions;
+
+ char *name;
+ token_data data;
+};
+
+#define SYMBOL_NEXT(S) ((S)->next)
+#define SYMBOL_TRACED(S) ((S)->traced)
+#define SYMBOL_SHADOWED(S) ((S)->shadowed)
+#define SYMBOL_MACRO_ARGS(S) ((S)->macro_args)
+#define SYMBOL_BLIND_NO_ARGS(S) ((S)->blind_no_args)
+#define SYMBOL_DELETED(S) ((S)->deleted)
+#define SYMBOL_PENDING_EXPANSIONS(S) ((S)->pending_expansions)
+#define SYMBOL_NAME(S) ((S)->name)
+#define SYMBOL_TYPE(S) (TOKEN_DATA_TYPE (&(S)->data))
+#define SYMBOL_TEXT(S) (TOKEN_DATA_TEXT (&(S)->data))
+#define SYMBOL_FUNC(S) (TOKEN_DATA_FUNC (&(S)->data))
+
+typedef enum symbol_lookup symbol_lookup;
+typedef struct symbol symbol;
+typedef void hack_symbol (symbol *, void *);
+
+#define HASHMAX 509 /* default, overridden by -Hsize */
+
+extern symbol **symtab;
+
+extern void free_symbol (symbol *sym);
+extern void symtab_init (void);
+extern symbol *lookup_symbol (const char *, symbol_lookup);
+extern void hack_all_symbols (hack_symbol *, void *);
+
+/* File: macro.c --- macro expansion. */
+
+extern int expansion_level;
+
+extern void expand_input (void);
+extern void call_macro (symbol *, int, token_data **, struct obstack *);
+
+/* File: builtin.c --- builtins. */
+
+struct builtin
+{
+ const char *name;
+ bool_bitfield gnu_extension : 1;
+ bool_bitfield groks_macro_args : 1;
+ bool_bitfield blind_if_no_args : 1;
+ builtin_func *func;
+};
+
+struct predefined
+{
+ const char *unix_name;
+ const char *gnu_name;
+ const char *func;
+};
+
+typedef struct builtin builtin;
+typedef struct predefined predefined;
+struct re_pattern_buffer;
+struct re_registers;
+
+/* The default sequence detects multi-digit parameters (obsolete after
+ 1.4.x), and any use of extended arguments with the default ${}
+ syntax (new in 2.0). */
+#define DEFAULT_MACRO_SEQUENCE "\\$\\({[^}]*}\\|[0-9][0-9]+\\)"
+
+extern void builtin_init (void);
+extern void define_builtin (const char *, const builtin *, symbol_lookup);
+extern void set_macro_sequence (const char *);
+extern void free_macro_sequence (void);
+extern void define_user_macro (const char *, const char *, symbol_lookup);
+extern void undivert_all (void);
+extern void expand_user_macro (struct obstack *, symbol *, int, token_data **);
+extern void m4_placeholder (struct obstack *, int, token_data **);
+extern void init_pattern_buffer (struct re_pattern_buffer *,
+ struct re_registers *);
+extern const char *ntoa (int32_t, int);
+
+extern const builtin *find_builtin_by_addr (builtin_func *);
+extern const builtin *find_builtin_by_name (const char *);
+
+/* File: path.c --- path search for include files. */
+
+extern void include_init (void);
+extern void include_env_init (void);
+extern void add_include_directory (const char *);
+extern FILE *m4_path_search (const char *, char **);
+
+/* File: eval.c --- expression evaluation. */
+
+extern bool evaluate (const char *, int32_t *);
+
+/* File: format.c --- printf like formatting. */
+
+extern void expand_format (struct obstack *, int, token_data **);
+
+/* File: freeze.c --- frozen state files. */
+
+extern void produce_frozen_state (const char *);
+extern void reload_frozen_state (const char *);
+
+/* Debugging the memory allocator. */
+
+#ifdef WITH_DMALLOC
+# define DMALLOC_FUNC_CHECK
+# include <dmalloc.h>
+#endif
+
+/* Other debug stuff. */
+
+#ifdef DEBUG
+# define DEBUG_INCL 1
+# define DEBUG_INPUT 1
+# define DEBUG_MACRO 1
+# define DEBUG_OUTPUT 1
+# define DEBUG_STKOVF 1
+# define DEBUG_SYM 1
+#endif
+
+/* Convert a possibly-signed character to an unsigned character. This is
+ a bit safer than casting to unsigned char, since it catches some type
+ errors that the cast doesn't. */
+#if HAVE_INLINE
+static inline unsigned char to_uchar (char ch) { return ch; }
+#else
+# define to_uchar(C) ((unsigned char) (C))
+#endif
+
+/* Avoid negative logic when comparing two strings. */
+#define STREQ(a, b) (strcmp (a, b) == 0)
diff --git a/contrib/tools/bison/m4/src/macro.c b/contrib/tools/bison/m4/src/macro.c
index 0e7624372e..78908f5b04 100644
--- a/contrib/tools/bison/m4/src/macro.c
+++ b/contrib/tools/bison/m4/src/macro.c
@@ -1,391 +1,391 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2006-2007, 2009-2013 Free Software
- Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* This file contains the functions, that performs the basic argument
- parsing and macro expansion. */
-
-#include "m4.h"
-
-static void expand_macro (symbol *);
-static void expand_token (struct obstack *, token_type, token_data *, int);
-
-/* Current recursion level in expand_macro (). */
-int expansion_level = 0;
-
-/* The number of the current call of expand_macro (). */
-static int macro_call_id = 0;
-
-/* The shared stack of collected arguments for macro calls; as each
- argument is collected, it is finished and its location stored in
- argv_stack. Normally, this stack can be used simultaneously by
- multiple macro calls; the exception is when an outer macro has
- generated some text, then calls a nested macro, in which case the
- nested macro must use a local stack to leave the unfinished text
- alone. Too bad obstack.h does not provide an easy way to reopen a
- finished object for further growth, but in practice this does not
- hurt us too much. */
-static struct obstack argc_stack;
-
-/* The shared stack of pointers to collected arguments for macro
- calls. This object is never finished; we exploit the fact that
- obstack_blank is documented to take a negative size to reduce the
- size again. */
-static struct obstack argv_stack;
-
-/*----------------------------------------------------------------------.
-| This function read all input, and expands each token, one at a time. |
-`----------------------------------------------------------------------*/
-
-void
-expand_input (void)
-{
- token_type t;
- token_data td;
- int line;
-
- obstack_init (&argc_stack);
- obstack_init (&argv_stack);
-
- while ((t = next_token (&td, &line)) != TOKEN_EOF)
- expand_token ((struct obstack *) NULL, t, &td, line);
-
- obstack_free (&argc_stack, NULL);
- obstack_free (&argv_stack, NULL);
-}
-
-
-/*----------------------------------------------------------------.
-| Expand one token, according to its type. Potential macro names |
-| (TOKEN_WORD) are looked up in the symbol table, to see if they |
-| have a macro definition. If they have, they are expanded as |
-| macros, otherwise the text is just copied to the output. |
-`----------------------------------------------------------------*/
-
-static void
-expand_token (struct obstack *obs, token_type t, token_data *td, int line)
-{
- symbol *sym;
-
- switch (t)
- { /* TOKSW */
- case TOKEN_EOF:
- case TOKEN_MACDEF:
- break;
-
- case TOKEN_OPEN:
- case TOKEN_COMMA:
- case TOKEN_CLOSE:
- case TOKEN_SIMPLE:
- case TOKEN_STRING:
- shipout_text (obs, TOKEN_DATA_TEXT (td), strlen (TOKEN_DATA_TEXT (td)),
- line);
- break;
-
- case TOKEN_WORD:
- sym = lookup_symbol (TOKEN_DATA_TEXT (td), SYMBOL_LOOKUP);
- if (sym == NULL || SYMBOL_TYPE (sym) == TOKEN_VOID
- || (SYMBOL_TYPE (sym) == TOKEN_FUNC
- && SYMBOL_BLIND_NO_ARGS (sym)
- && peek_token () != TOKEN_OPEN))
- {
-#ifdef ENABLE_CHANGEWORD
- shipout_text (obs, TOKEN_DATA_ORIG_TEXT (td),
- strlen (TOKEN_DATA_ORIG_TEXT (td)), line);
-#else
- shipout_text (obs, TOKEN_DATA_TEXT (td),
- strlen (TOKEN_DATA_TEXT (td)), line);
-#endif
- }
- else
- expand_macro (sym);
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad token type in expand_token ()"));
- abort ();
- }
-}
-
-
-/*-------------------------------------------------------------------.
-| This function parses one argument to a macro call. It expects the |
-| first left parenthesis, or the separating comma, to have been read |
-| by the caller. It skips leading whitespace, and reads and expands |
-| tokens, until it finds a comma or an right parenthesis at the same |
-| level of parentheses. It returns a flag indicating whether the |
-| argument read is the last for the active macro call. The argument |
-| is built on the obstack OBS, indirectly through expand_token (). |
-`-------------------------------------------------------------------*/
-
-static bool
-expand_argument (struct obstack *obs, token_data *argp)
-{
- token_type t;
- token_data td;
- char *text;
- int paren_level;
- const char *file = current_file;
- int line = current_line;
-
- TOKEN_DATA_TYPE (argp) = TOKEN_VOID;
-
- /* Skip leading white space. */
- do
- {
- t = next_token (&td, NULL);
- }
- while (t == TOKEN_SIMPLE && isspace (to_uchar (*TOKEN_DATA_TEXT (&td))));
-
- paren_level = 0;
-
- while (1)
- {
-
- switch (t)
- { /* TOKSW */
- case TOKEN_COMMA:
- case TOKEN_CLOSE:
- if (paren_level == 0)
- {
- /* The argument MUST be finished, whether we want it or not. */
- obstack_1grow (obs, '\0');
- text = (char *) obstack_finish (obs);
-
- if (TOKEN_DATA_TYPE (argp) == TOKEN_VOID)
- {
- TOKEN_DATA_TYPE (argp) = TOKEN_TEXT;
- TOKEN_DATA_TEXT (argp) = text;
- }
- return t == TOKEN_COMMA;
- }
- /* fallthru */
- case TOKEN_OPEN:
- case TOKEN_SIMPLE:
- text = TOKEN_DATA_TEXT (&td);
-
- if (*text == '(')
- paren_level++;
- else if (*text == ')')
- paren_level--;
- expand_token (obs, t, &td, line);
- break;
-
- case TOKEN_EOF:
- /* current_file changed to "" if we see TOKEN_EOF, use the
- previous value we stored earlier. */
- M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, line,
- "ERROR: end of file in argument list"));
- break;
-
- case TOKEN_WORD:
- case TOKEN_STRING:
- expand_token (obs, t, &td, line);
- break;
-
- case TOKEN_MACDEF:
- if (obstack_object_size (obs) == 0)
- {
- TOKEN_DATA_TYPE (argp) = TOKEN_FUNC;
- TOKEN_DATA_FUNC (argp) = TOKEN_DATA_FUNC (&td);
- }
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad token type in expand_argument ()"));
- abort ();
- }
-
- t = next_token (&td, NULL);
- }
-}
-
-/*-------------------------------------------------------------.
-| Collect all the arguments to a call of the macro SYM. The |
-| arguments are stored on the obstack ARGUMENTS and a table of |
-| pointers to the arguments on the obstack ARGPTR. |
-`-------------------------------------------------------------*/
-
-static void
-collect_arguments (symbol *sym, struct obstack *argptr,
- struct obstack *arguments)
-{
- token_data td;
- token_data *tdp;
- bool more_args;
- bool groks_macro_args = SYMBOL_MACRO_ARGS (sym);
-
- TOKEN_DATA_TYPE (&td) = TOKEN_TEXT;
- TOKEN_DATA_TEXT (&td) = SYMBOL_NAME (sym);
- tdp = (token_data *) obstack_copy (arguments, &td, sizeof td);
- obstack_ptr_grow (argptr, tdp);
-
- if (peek_token () == TOKEN_OPEN)
- {
- next_token (&td, NULL); /* gobble parenthesis */
- do
- {
- more_args = expand_argument (arguments, &td);
-
- if (!groks_macro_args && TOKEN_DATA_TYPE (&td) == TOKEN_FUNC)
- {
- TOKEN_DATA_TYPE (&td) = TOKEN_TEXT;
- TOKEN_DATA_TEXT (&td) = (char *) "";
- }
- tdp = (token_data *) obstack_copy (arguments, &td, sizeof td);
- obstack_ptr_grow (argptr, tdp);
- }
- while (more_args);
- }
-}
-
-
-/*-------------------------------------------------------------------.
-| The actual call of a macro is handled by call_macro (). |
-| call_macro () is passed a symbol SYM, whose type is used to call |
-| either a builtin function, or the user macro expansion function |
-| expand_user_macro () (lives in builtin.c). There are ARGC |
-| arguments to the call, stored in the ARGV table. The expansion is |
-| left on the obstack EXPANSION. Macro tracing is also handled |
-| here. |
-`-------------------------------------------------------------------*/
-
-void
-call_macro (symbol *sym, int argc, token_data **argv,
- struct obstack *expansion)
-{
- switch (SYMBOL_TYPE (sym))
- {
- case TOKEN_FUNC:
- (*SYMBOL_FUNC (sym)) (expansion, argc, argv);
- break;
-
- case TOKEN_TEXT:
- expand_user_macro (expansion, sym, argc, argv);
- break;
-
- case TOKEN_VOID:
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: bad symbol type in call_macro ()"));
- abort ();
- }
-}
-
-/*-------------------------------------------------------------------.
-| The macro expansion is handled by expand_macro (). It parses the |
-| arguments, using collect_arguments (), and builds a table of |
-| pointers to the arguments. The arguments themselves are stored on |
-| a local obstack. Expand_macro () uses call_macro () to do the |
-| call of the macro. |
-| |
-| Expand_macro () is potentially recursive, since it calls |
-| expand_argument (), which might call expand_token (), which might |
-| call expand_macro (). |
-`-------------------------------------------------------------------*/
-
-static void
-expand_macro (symbol *sym)
-{
- struct obstack arguments; /* Alternate obstack if argc_stack is busy. */
- unsigned argv_base; /* Size of argv_stack on entry. */
- bool use_argc_stack = true; /* Whether argc_stack is safe. */
- token_data **argv;
- int argc;
- struct obstack *expansion;
- const char *expanded;
- bool traced;
- int my_call_id;
-
- /* Report errors at the location where the open parenthesis (if any)
- was found, but after expansion, restore global state back to the
- location of the close parenthesis. This is safe since we
- guarantee that macro expansion does not alter the state of
- current_file/current_line (dnl, include, and sinclude are special
- cased in the input engine to ensure this fact). */
- const char *loc_open_file = current_file;
- int loc_open_line = current_line;
- const char *loc_close_file;
- int loc_close_line;
-
- SYMBOL_PENDING_EXPANSIONS (sym)++;
- expansion_level++;
- if (nesting_limit > 0 && expansion_level > nesting_limit)
- M4ERROR ((EXIT_FAILURE, 0,
- "recursion limit of %d exceeded, use -L<N> to change it",
- nesting_limit));
-
- macro_call_id++;
- my_call_id = macro_call_id;
-
- traced = (debug_level & DEBUG_TRACE_ALL) || SYMBOL_TRACED (sym);
-
- argv_base = obstack_object_size (&argv_stack);
- if (obstack_object_size (&argc_stack) > 0)
- {
- /* We cannot use argc_stack if this is a nested invocation, and an
- outer invocation has an unfinished argument being
- collected. */
- obstack_init (&arguments);
- use_argc_stack = false;
- }
-
- if (traced && (debug_level & DEBUG_TRACE_CALL))
- trace_prepre (SYMBOL_NAME (sym), my_call_id);
-
- collect_arguments (sym, &argv_stack,
- use_argc_stack ? &argc_stack : &arguments);
-
- argc = ((obstack_object_size (&argv_stack) - argv_base)
- / sizeof (token_data *));
- argv = (token_data **) ((char *) obstack_base (&argv_stack) + argv_base);
-
- loc_close_file = current_file;
- loc_close_line = current_line;
- current_file = loc_open_file;
- current_line = loc_open_line;
-
- if (traced)
- trace_pre (SYMBOL_NAME (sym), my_call_id, argc, argv);
-
- expansion = push_string_init ();
- call_macro (sym, argc, argv, expansion);
- expanded = push_string_finish ();
-
- if (traced)
- trace_post (SYMBOL_NAME (sym), my_call_id, argc, expanded);
-
- current_file = loc_close_file;
- current_line = loc_close_line;
-
- --expansion_level;
- --SYMBOL_PENDING_EXPANSIONS (sym);
-
- if (SYMBOL_DELETED (sym))
- free_symbol (sym);
-
- if (use_argc_stack)
- obstack_free (&argc_stack, argv[0]);
- else
- obstack_free (&arguments, NULL);
- obstack_blank (&argv_stack, -argc * sizeof (token_data *));
-}
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2006-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* This file contains the functions, that performs the basic argument
+ parsing and macro expansion. */
+
+#include "m4.h"
+
+static void expand_macro (symbol *);
+static void expand_token (struct obstack *, token_type, token_data *, int);
+
+/* Current recursion level in expand_macro (). */
+int expansion_level = 0;
+
+/* The number of the current call of expand_macro (). */
+static int macro_call_id = 0;
+
+/* The shared stack of collected arguments for macro calls; as each
+ argument is collected, it is finished and its location stored in
+ argv_stack. Normally, this stack can be used simultaneously by
+ multiple macro calls; the exception is when an outer macro has
+ generated some text, then calls a nested macro, in which case the
+ nested macro must use a local stack to leave the unfinished text
+ alone. Too bad obstack.h does not provide an easy way to reopen a
+ finished object for further growth, but in practice this does not
+ hurt us too much. */
+static struct obstack argc_stack;
+
+/* The shared stack of pointers to collected arguments for macro
+ calls. This object is never finished; we exploit the fact that
+ obstack_blank is documented to take a negative size to reduce the
+ size again. */
+static struct obstack argv_stack;
+
+/*----------------------------------------------------------------------.
+| This function read all input, and expands each token, one at a time. |
+`----------------------------------------------------------------------*/
+
+void
+expand_input (void)
+{
+ token_type t;
+ token_data td;
+ int line;
+
+ obstack_init (&argc_stack);
+ obstack_init (&argv_stack);
+
+ while ((t = next_token (&td, &line)) != TOKEN_EOF)
+ expand_token ((struct obstack *) NULL, t, &td, line);
+
+ obstack_free (&argc_stack, NULL);
+ obstack_free (&argv_stack, NULL);
+}
+
+
+/*----------------------------------------------------------------.
+| Expand one token, according to its type. Potential macro names |
+| (TOKEN_WORD) are looked up in the symbol table, to see if they |
+| have a macro definition. If they have, they are expanded as |
+| macros, otherwise the text is just copied to the output. |
+`----------------------------------------------------------------*/
+
+static void
+expand_token (struct obstack *obs, token_type t, token_data *td, int line)
+{
+ symbol *sym;
+
+ switch (t)
+ { /* TOKSW */
+ case TOKEN_EOF:
+ case TOKEN_MACDEF:
+ break;
+
+ case TOKEN_OPEN:
+ case TOKEN_COMMA:
+ case TOKEN_CLOSE:
+ case TOKEN_SIMPLE:
+ case TOKEN_STRING:
+ shipout_text (obs, TOKEN_DATA_TEXT (td), strlen (TOKEN_DATA_TEXT (td)),
+ line);
+ break;
+
+ case TOKEN_WORD:
+ sym = lookup_symbol (TOKEN_DATA_TEXT (td), SYMBOL_LOOKUP);
+ if (sym == NULL || SYMBOL_TYPE (sym) == TOKEN_VOID
+ || (SYMBOL_TYPE (sym) == TOKEN_FUNC
+ && SYMBOL_BLIND_NO_ARGS (sym)
+ && peek_token () != TOKEN_OPEN))
+ {
+#ifdef ENABLE_CHANGEWORD
+ shipout_text (obs, TOKEN_DATA_ORIG_TEXT (td),
+ strlen (TOKEN_DATA_ORIG_TEXT (td)), line);
+#else
+ shipout_text (obs, TOKEN_DATA_TEXT (td),
+ strlen (TOKEN_DATA_TEXT (td)), line);
+#endif
+ }
+ else
+ expand_macro (sym);
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad token type in expand_token ()"));
+ abort ();
+ }
+}
+
+
+/*-------------------------------------------------------------------.
+| This function parses one argument to a macro call. It expects the |
+| first left parenthesis, or the separating comma, to have been read |
+| by the caller. It skips leading whitespace, and reads and expands |
+| tokens, until it finds a comma or an right parenthesis at the same |
+| level of parentheses. It returns a flag indicating whether the |
+| argument read is the last for the active macro call. The argument |
+| is built on the obstack OBS, indirectly through expand_token (). |
+`-------------------------------------------------------------------*/
+
+static bool
+expand_argument (struct obstack *obs, token_data *argp)
+{
+ token_type t;
+ token_data td;
+ char *text;
+ int paren_level;
+ const char *file = current_file;
+ int line = current_line;
+
+ TOKEN_DATA_TYPE (argp) = TOKEN_VOID;
+
+ /* Skip leading white space. */
+ do
+ {
+ t = next_token (&td, NULL);
+ }
+ while (t == TOKEN_SIMPLE && isspace (to_uchar (*TOKEN_DATA_TEXT (&td))));
+
+ paren_level = 0;
+
+ while (1)
+ {
+
+ switch (t)
+ { /* TOKSW */
+ case TOKEN_COMMA:
+ case TOKEN_CLOSE:
+ if (paren_level == 0)
+ {
+ /* The argument MUST be finished, whether we want it or not. */
+ obstack_1grow (obs, '\0');
+ text = (char *) obstack_finish (obs);
+
+ if (TOKEN_DATA_TYPE (argp) == TOKEN_VOID)
+ {
+ TOKEN_DATA_TYPE (argp) = TOKEN_TEXT;
+ TOKEN_DATA_TEXT (argp) = text;
+ }
+ return t == TOKEN_COMMA;
+ }
+ /* fallthru */
+ case TOKEN_OPEN:
+ case TOKEN_SIMPLE:
+ text = TOKEN_DATA_TEXT (&td);
+
+ if (*text == '(')
+ paren_level++;
+ else if (*text == ')')
+ paren_level--;
+ expand_token (obs, t, &td, line);
+ break;
+
+ case TOKEN_EOF:
+ /* current_file changed to "" if we see TOKEN_EOF, use the
+ previous value we stored earlier. */
+ M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, line,
+ "ERROR: end of file in argument list"));
+ break;
+
+ case TOKEN_WORD:
+ case TOKEN_STRING:
+ expand_token (obs, t, &td, line);
+ break;
+
+ case TOKEN_MACDEF:
+ if (obstack_object_size (obs) == 0)
+ {
+ TOKEN_DATA_TYPE (argp) = TOKEN_FUNC;
+ TOKEN_DATA_FUNC (argp) = TOKEN_DATA_FUNC (&td);
+ }
+ break;
+
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad token type in expand_argument ()"));
+ abort ();
+ }
+
+ t = next_token (&td, NULL);
+ }
+}
+
+/*-------------------------------------------------------------.
+| Collect all the arguments to a call of the macro SYM. The |
+| arguments are stored on the obstack ARGUMENTS and a table of |
+| pointers to the arguments on the obstack ARGPTR. |
+`-------------------------------------------------------------*/
+
+static void
+collect_arguments (symbol *sym, struct obstack *argptr,
+ struct obstack *arguments)
+{
+ token_data td;
+ token_data *tdp;
+ bool more_args;
+ bool groks_macro_args = SYMBOL_MACRO_ARGS (sym);
+
+ TOKEN_DATA_TYPE (&td) = TOKEN_TEXT;
+ TOKEN_DATA_TEXT (&td) = SYMBOL_NAME (sym);
+ tdp = (token_data *) obstack_copy (arguments, &td, sizeof td);
+ obstack_ptr_grow (argptr, tdp);
+
+ if (peek_token () == TOKEN_OPEN)
+ {
+ next_token (&td, NULL); /* gobble parenthesis */
+ do
+ {
+ more_args = expand_argument (arguments, &td);
+
+ if (!groks_macro_args && TOKEN_DATA_TYPE (&td) == TOKEN_FUNC)
+ {
+ TOKEN_DATA_TYPE (&td) = TOKEN_TEXT;
+ TOKEN_DATA_TEXT (&td) = (char *) "";
+ }
+ tdp = (token_data *) obstack_copy (arguments, &td, sizeof td);
+ obstack_ptr_grow (argptr, tdp);
+ }
+ while (more_args);
+ }
+}
+
+
+/*-------------------------------------------------------------------.
+| The actual call of a macro is handled by call_macro (). |
+| call_macro () is passed a symbol SYM, whose type is used to call |
+| either a builtin function, or the user macro expansion function |
+| expand_user_macro () (lives in builtin.c). There are ARGC |
+| arguments to the call, stored in the ARGV table. The expansion is |
+| left on the obstack EXPANSION. Macro tracing is also handled |
+| here. |
+`-------------------------------------------------------------------*/
+
+void
+call_macro (symbol *sym, int argc, token_data **argv,
+ struct obstack *expansion)
+{
+ switch (SYMBOL_TYPE (sym))
+ {
+ case TOKEN_FUNC:
+ (*SYMBOL_FUNC (sym)) (expansion, argc, argv);
+ break;
+
+ case TOKEN_TEXT:
+ expand_user_macro (expansion, sym, argc, argv);
+ break;
+
+ case TOKEN_VOID:
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: bad symbol type in call_macro ()"));
+ abort ();
+ }
+}
+
+/*-------------------------------------------------------------------.
+| The macro expansion is handled by expand_macro (). It parses the |
+| arguments, using collect_arguments (), and builds a table of |
+| pointers to the arguments. The arguments themselves are stored on |
+| a local obstack. Expand_macro () uses call_macro () to do the |
+| call of the macro. |
+| |
+| Expand_macro () is potentially recursive, since it calls |
+| expand_argument (), which might call expand_token (), which might |
+| call expand_macro (). |
+`-------------------------------------------------------------------*/
+
+static void
+expand_macro (symbol *sym)
+{
+ struct obstack arguments; /* Alternate obstack if argc_stack is busy. */
+ unsigned argv_base; /* Size of argv_stack on entry. */
+ bool use_argc_stack = true; /* Whether argc_stack is safe. */
+ token_data **argv;
+ int argc;
+ struct obstack *expansion;
+ const char *expanded;
+ bool traced;
+ int my_call_id;
+
+ /* Report errors at the location where the open parenthesis (if any)
+ was found, but after expansion, restore global state back to the
+ location of the close parenthesis. This is safe since we
+ guarantee that macro expansion does not alter the state of
+ current_file/current_line (dnl, include, and sinclude are special
+ cased in the input engine to ensure this fact). */
+ const char *loc_open_file = current_file;
+ int loc_open_line = current_line;
+ const char *loc_close_file;
+ int loc_close_line;
+
+ SYMBOL_PENDING_EXPANSIONS (sym)++;
+ expansion_level++;
+ if (nesting_limit > 0 && expansion_level > nesting_limit)
+ M4ERROR ((EXIT_FAILURE, 0,
+ "recursion limit of %d exceeded, use -L<N> to change it",
+ nesting_limit));
+
+ macro_call_id++;
+ my_call_id = macro_call_id;
+
+ traced = (debug_level & DEBUG_TRACE_ALL) || SYMBOL_TRACED (sym);
+
+ argv_base = obstack_object_size (&argv_stack);
+ if (obstack_object_size (&argc_stack) > 0)
+ {
+ /* We cannot use argc_stack if this is a nested invocation, and an
+ outer invocation has an unfinished argument being
+ collected. */
+ obstack_init (&arguments);
+ use_argc_stack = false;
+ }
+
+ if (traced && (debug_level & DEBUG_TRACE_CALL))
+ trace_prepre (SYMBOL_NAME (sym), my_call_id);
+
+ collect_arguments (sym, &argv_stack,
+ use_argc_stack ? &argc_stack : &arguments);
+
+ argc = ((obstack_object_size (&argv_stack) - argv_base)
+ / sizeof (token_data *));
+ argv = (token_data **) ((char *) obstack_base (&argv_stack) + argv_base);
+
+ loc_close_file = current_file;
+ loc_close_line = current_line;
+ current_file = loc_open_file;
+ current_line = loc_open_line;
+
+ if (traced)
+ trace_pre (SYMBOL_NAME (sym), my_call_id, argc, argv);
+
+ expansion = push_string_init ();
+ call_macro (sym, argc, argv, expansion);
+ expanded = push_string_finish ();
+
+ if (traced)
+ trace_post (SYMBOL_NAME (sym), my_call_id, argc, expanded);
+
+ current_file = loc_close_file;
+ current_line = loc_close_line;
+
+ --expansion_level;
+ --SYMBOL_PENDING_EXPANSIONS (sym);
+
+ if (SYMBOL_DELETED (sym))
+ free_symbol (sym);
+
+ if (use_argc_stack)
+ obstack_free (&argc_stack, argv[0]);
+ else
+ obstack_free (&arguments, NULL);
+ obstack_blank (&argv_stack, -argc * sizeof (token_data *));
+}
diff --git a/contrib/tools/bison/m4/src/output.c b/contrib/tools/bison/m4/src/output.c
index c378afebdb..213d3bbba6 100644
--- a/contrib/tools/bison/m4/src/output.c
+++ b/contrib/tools/bison/m4/src/output.c
@@ -1,1017 +1,1017 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "m4.h"
-
-#include <limits.h>
-#include <sys/stat.h>
-
-#include "gl_avltree_oset.h"
-#include "gl_xoset.h"
-
-/* Size of initial in-memory buffer size for diversions. Small diversions
- would usually fit in. */
-#define INITIAL_BUFFER_SIZE 512
-
-/* Maximum value for the total of all in-memory buffer sizes for
- diversions. */
-#define MAXIMUM_TOTAL_SIZE (512 * 1024)
-
-/* Size of buffer size to use while copying files. */
-#define COPY_BUFFER_SIZE (32 * 512)
-
-/* Output functions. Most of the complexity is for handling cpp like
- sync lines.
-
- This code is fairly entangled with the code in input.c, and maybe it
- belongs there? */
-
-typedef struct temp_dir m4_temp_dir;
-
-/* When part of diversion_table, each struct m4_diversion either
- represents an open file (zero size, non-NULL u.file), an in-memory
- buffer (non-zero size, non-NULL u.buffer), or an unused placeholder
- diversion (zero size, u is NULL, non-zero used indicates that a
- file has been created). When not part of diversion_table, u.next
- is a pointer to the free_list chain. */
-
-typedef struct m4_diversion m4_diversion;
-
-struct m4_diversion
- {
- union
- {
- FILE *file; /* Diversion file on disk. */
- char *buffer; /* Malloc'd diversion buffer. */
- m4_diversion *next; /* Free-list pointer */
- } u;
- int divnum; /* Which diversion this represents. */
- int size; /* Usable size before reallocation. */
- int used; /* Used buffer length, or tmp file exists. */
- };
-
-/* Table of diversions 1 through INT_MAX. */
-static gl_oset_t diversion_table;
-
-/* Diversion 0 (not part of diversion_table). */
-static m4_diversion div0;
-
-/* Linked list of reclaimed diversion storage. */
-static m4_diversion *free_list;
-
-/* Obstack from which diversion storage is allocated. */
-static struct obstack diversion_storage;
-
-/* Total size of all in-memory buffer sizes. */
-static int total_buffer_size;
-
-/* The number of the currently active diversion. This variable is
- maintained for the `divnum' builtin function. */
-int current_diversion;
-
-/* Current output diversion, NULL if output is being currently
- discarded. output_diversion->u is guaranteed non-NULL except when
- the diversion has never been used; use size to determine if it is a
- malloc'd buffer or a FILE. output_diversion->used is 0 if u.file
- is stdout, and non-zero if this is a malloc'd buffer or a temporary
- diversion file. */
-static m4_diversion *output_diversion;
-
-/* Cache of output_diversion->u.file, only valid when
- output_diversion->size is 0. */
-static FILE *output_file;
-
-/* Cache of output_diversion->u.buffer + output_diversion->used, only
- valid when output_diversion->size is non-zero. */
-static char *output_cursor;
-
-/* Cache of output_diversion->size - output_diversion->used, only
- valid when output_diversion->size is non-zero. */
-static int output_unused;
-
-/* Number of input line we are generating output for. */
-int output_current_line;
-
-/* Temporary directory holding all spilled diversion files. */
-static m4_temp_dir *output_temp_dir;
-
-/* Cache of most recently used spilled diversion files. */
-static FILE *tmp_file1;
-static FILE *tmp_file2;
-
-/* Diversions that own tmp_file, or 0. */
-static int tmp_file1_owner;
-static int tmp_file2_owner;
-
-/* True if tmp_file2 is more recently used. */
-static bool tmp_file2_recent;
-
-
-/* Internal routines. */
-
-/* Callback for comparing list elements ELT1 and ELT2 for order in
- diversion_table. */
-static int
-cmp_diversion_CB (const void *elt1, const void *elt2)
-{
- const m4_diversion *d1 = (const m4_diversion *) elt1;
- const m4_diversion *d2 = (const m4_diversion *) elt2;
- /* No need to worry about overflow, since we don't create diversions
- with negative divnum. */
- return d1->divnum - d2->divnum;
-}
-
-/* Callback for comparing list element ELT against THRESHOLD. */
-static bool
-threshold_diversion_CB (const void *elt, const void *threshold)
-{
- const m4_diversion *diversion = (const m4_diversion *) elt;
- /* No need to worry about overflow, since we don't create diversions
- with negative divnum. */
- return diversion->divnum >= *(const int *) threshold;
-}
-
-/* Clean up any temporary directory. Designed for use as an atexit
- handler, where it is not safe to call exit() recursively; so this
- calls _exit if a problem is encountered. */
-static void
-cleanup_tmpfile (void)
-{
- /* Close any open diversions. */
- bool fail = false;
-
- if (diversion_table)
- {
- const void *elt;
- gl_oset_iterator_t iter = gl_oset_iterator (diversion_table);
- while (gl_oset_iterator_next (&iter, &elt))
- {
- m4_diversion *diversion = (m4_diversion *) elt;
- if (!diversion->size && diversion->u.file
- && close_stream_temp (diversion->u.file) != 0)
- {
- M4ERROR ((0, errno,
- "cannot clean temporary file for diversion"));
- fail = true;
- }
- }
- gl_oset_iterator_free (&iter);
- }
-
- /* Clean up the temporary directory. */
- if (cleanup_temp_dir (output_temp_dir) != 0)
- fail = true;
- if (fail)
- _exit (exit_failure);
-}
-
-/* Convert DIVNUM into a temporary file name for use in m4_tmp*. */
-static const char *
-m4_tmpname (int divnum)
-{
- static char *buffer;
- static char *tail;
- if (buffer == NULL)
- {
- tail = xasprintf ("%s/m4-%d", output_temp_dir->dir_name, INT_MAX);
- buffer = (char *) obstack_copy0 (&diversion_storage, tail,
- strlen (tail));
- free (tail);
- tail = strrchr (buffer, '-') + 1;
- }
- assert (0 < divnum);
- sprintf (tail, "%d", divnum);
- return buffer;
-}
-
-/* Create a temporary file for diversion DIVNUM open for reading and
- writing in a secure temp directory. The file will be automatically
- closed and deleted on a fatal signal. The file can be closed and
- reopened with m4_tmpclose and m4_tmpopen, or moved with
- m4_tmprename; when finally done with the file, close it with
- m4_tmpremove. Exits on failure, so the return value is always an
- open file. */
-static FILE *
-m4_tmpfile (int divnum)
-{
- const char *name;
- FILE *file;
-
- if (output_temp_dir == NULL)
- {
- output_temp_dir = create_temp_dir ("m4-", NULL, true);
- if (output_temp_dir == NULL)
- M4ERROR ((EXIT_FAILURE, errno,
- "cannot create temporary file for diversion"));
- atexit (cleanup_tmpfile);
- }
- name = m4_tmpname (divnum);
- register_temp_file (output_temp_dir, name);
- file = fopen_temp (name, O_BINARY ? "wb+" : "w+");
- if (file == NULL)
- {
- unregister_temp_file (output_temp_dir, name);
- M4ERROR ((EXIT_FAILURE, errno,
- "cannot create temporary file for diversion"));
- }
- else if (set_cloexec_flag (fileno (file), true) != 0)
- M4ERROR ((warning_status, errno,
- "Warning: cannot protect diversion across forks"));
- return file;
-}
-
-/* Reopen a temporary file for diversion DIVNUM for reading and
- writing in a secure temp directory. If REREAD, the file is
- positioned at offset 0, otherwise the file is positioned at the
- end. Exits on failure, so the return value is always an open
- file. */
-static FILE *
-m4_tmpopen (int divnum, bool reread)
-{
- const char *name;
- FILE *file;
-
- if (tmp_file1_owner == divnum)
- {
- if (reread && fseeko (tmp_file1, 0, SEEK_SET) != 0)
- m4_error (EXIT_FAILURE, errno,
- _("cannot seek within diversion"));
- tmp_file2_recent = false;
- return tmp_file1;
- }
- else if (tmp_file2_owner == divnum)
- {
- if (reread && fseeko (tmp_file2, 0, SEEK_SET) != 0)
- m4_error (EXIT_FAILURE, errno,
- _("cannot seek within diversion"));
- tmp_file2_recent = true;
- return tmp_file2;
- }
- name = m4_tmpname (divnum);
- /* We need update mode, to avoid truncation. */
- file = fopen_temp (name, O_BINARY ? "rb+" : "r+");
- if (file == NULL)
- M4ERROR ((EXIT_FAILURE, errno,
- "cannot create temporary file for diversion"));
- else if (set_cloexec_flag (fileno (file), true) != 0)
- m4_error (0, errno, _("cannot protect diversion across forks"));
- /* Update mode starts at the beginning of the stream, but sometimes
- we want the end. */
- else if (!reread && fseeko (file, 0, SEEK_END) != 0)
- m4_error (EXIT_FAILURE, errno,
- _("cannot seek within diversion"));
- return file;
-}
-
-/* Close, but don't delete, a temporary FILE for diversion DIVNUM. To
- reduce the I/O overhead of repeatedly opening and closing the same
- file, this implementation caches the most recent spilled diversion.
- On the other hand, keeping every spilled diversion open would run
- into EMFILE limits. */
-static int
-m4_tmpclose (FILE *file, int divnum)
-{
- int result = 0;
- if (divnum != tmp_file1_owner && divnum != tmp_file2_owner)
- {
- if (tmp_file2_recent)
- {
- if (tmp_file1_owner)
- result = close_stream_temp (tmp_file1);
- tmp_file1 = file;
- tmp_file1_owner = divnum;
- }
- else
- {
- if (tmp_file2_owner)
- result = close_stream_temp (tmp_file2);
- tmp_file2 = file;
- tmp_file2_owner = divnum;
- }
- }
- return result;
-}
-
-/* Delete a closed temporary FILE for diversion DIVNUM. */
-static int
-m4_tmpremove (int divnum)
-{
- if (divnum == tmp_file1_owner)
- {
- int result = close_stream_temp (tmp_file1);
- if (result)
- return result;
- tmp_file1_owner = 0;
- }
- else if (divnum == tmp_file2_owner)
- {
- int result = close_stream_temp (tmp_file2);
- if (result)
- return result;
- tmp_file2_owner = 0;
- }
- return cleanup_temp_file (output_temp_dir, m4_tmpname (divnum));
-}
-
-/* Transfer the temporary file for diversion OLDNUM to the previously
- unused diversion NEWNUM. Return an open stream visiting the new
- temporary file, positioned at the end, or exit on failure. */
-static FILE*
-m4_tmprename (int oldnum, int newnum)
-{
- /* m4_tmpname reuses its return buffer. */
- char *oldname = xstrdup (m4_tmpname (oldnum));
- const char *newname = m4_tmpname (newnum);
- register_temp_file (output_temp_dir, newname);
- if (oldnum == tmp_file1_owner)
- {
- /* Be careful of mingw, which can't rename an open file. */
- if (RENAME_OPEN_FILE_WORKS)
- tmp_file1_owner = newnum;
- else
- {
- if (close_stream_temp (tmp_file1))
- m4_error (EXIT_FAILURE, errno,
- _("cannot close temporary file for diversion"));
- tmp_file1_owner = 0;
- }
- }
- else if (oldnum == tmp_file2_owner)
- {
- /* Be careful of mingw, which can't rename an open file. */
- if (RENAME_OPEN_FILE_WORKS)
- tmp_file2_owner = newnum;
- else
- {
- if (close_stream_temp (tmp_file2))
- m4_error (EXIT_FAILURE, errno,
- _("cannot close temporary file for diversion"));
- tmp_file2_owner = 0;
- }
- }
- /* Either it is safe to rename an open file, or no one should have
- oldname open at this point. */
- if (rename (oldname, newname))
- m4_error (EXIT_FAILURE, errno,
- _("cannot create temporary file for diversion"));
- unregister_temp_file (output_temp_dir, oldname);
- free (oldname);
- return m4_tmpopen (newnum, false);
-}
-
-
-/*------------------------.
-| Output initialization. |
-`------------------------*/
-
-void
-output_init (void)
-{
- diversion_table = gl_oset_create_empty (GL_AVLTREE_OSET, cmp_diversion_CB,
- NULL);
- div0.u.file = stdout;
- output_diversion = &div0;
- output_file = stdout;
- obstack_init (&diversion_storage);
-}
-
-void
-output_exit (void)
-{
- /* Order is important, since we may have registered cleanup_tmpfile
- as an atexit handler, and it must not traverse stale memory. */
- gl_oset_t table = diversion_table;
- if (tmp_file1_owner)
- m4_tmpremove (tmp_file1_owner);
- if (tmp_file2_owner)
- m4_tmpremove (tmp_file2_owner);
- diversion_table = NULL;
- gl_oset_free (table);
- obstack_free (&diversion_storage, NULL);
-}
-
-/*----------------------------------------------------------------.
-| Reorganize in-memory diversion buffers so the current diversion |
-| can accomodate LENGTH more characters without further |
-| reorganization. The current diversion buffer is made bigger if |
-| possible. But to make room for a bigger buffer, one of the |
-| in-memory diversion buffers might have to be flushed to a newly |
-| created temporary file. This flushed buffer might well be the |
-| current one. |
-`----------------------------------------------------------------*/
-
-static void
-make_room_for (int length)
-{
- int wanted_size;
- m4_diversion *selected_diversion = NULL;
-
- /* Compute needed size for in-memory buffer. Diversions in-memory
- buffers start at 0 bytes, then 512, then keep doubling until it is
- decided to flush them to disk. */
-
- output_diversion->used = output_diversion->size - output_unused;
-
- for (wanted_size = output_diversion->size;
- wanted_size < output_diversion->used + length;
- wanted_size = wanted_size == 0 ? INITIAL_BUFFER_SIZE : wanted_size * 2)
- ;
-
- /* Check if we are exceeding the maximum amount of buffer memory. */
-
- if (total_buffer_size - output_diversion->size + wanted_size
- > MAXIMUM_TOTAL_SIZE)
- {
- int selected_used;
- char *selected_buffer;
- m4_diversion *diversion;
- int count;
- gl_oset_iterator_t iter;
- const void *elt;
-
- /* Find out the buffer having most data, in view of flushing it to
- disk. Fake the current buffer as having already received the
- projected data, while making the selection. So, if it is
- selected indeed, we will flush it smaller, before it grows. */
-
- selected_diversion = output_diversion;
- selected_used = output_diversion->used + length;
-
- iter = gl_oset_iterator (diversion_table);
- while (gl_oset_iterator_next (&iter, &elt))
- {
- diversion = (m4_diversion *) elt;
- if (diversion->used > selected_used)
- {
- selected_diversion = diversion;
- selected_used = diversion->used;
- }
- }
- gl_oset_iterator_free (&iter);
-
- /* Create a temporary file, write the in-memory buffer of the
- diversion to this file, then release the buffer. Zero the
- diversion before doing anything that can exit () (including
- m4_tmpfile), so that the atexit handler doesn't try to close
- a garbage pointer as a file. */
-
- selected_buffer = selected_diversion->u.buffer;
- total_buffer_size -= selected_diversion->size;
- selected_diversion->size = 0;
- selected_diversion->u.file = NULL;
- selected_diversion->u.file = m4_tmpfile (selected_diversion->divnum);
-
- if (selected_diversion->used > 0)
- {
- count = fwrite (selected_buffer, (size_t) selected_diversion->used,
- 1, selected_diversion->u.file);
- if (count != 1)
- M4ERROR ((EXIT_FAILURE, errno,
- "ERROR: cannot flush diversion to temporary file"));
- }
-
- /* Reclaim the buffer space for other diversions. */
-
- free (selected_buffer);
- selected_diversion->used = 1;
- }
-
- /* Reload output_file, just in case the flushed diversion was current. */
-
- if (output_diversion == selected_diversion)
- {
- /* The flushed diversion was current indeed. */
-
- output_file = output_diversion->u.file;
- output_cursor = NULL;
- output_unused = 0;
- }
- else
- {
- /* Close any selected file since it is not the current diversion. */
- if (selected_diversion)
- {
- FILE *file = selected_diversion->u.file;
- selected_diversion->u.file = NULL;
- if (m4_tmpclose (file, selected_diversion->divnum) != 0)
- m4_error (0, errno,
- _("cannot close temporary file for diversion"));
- }
-
- /* The current buffer may be safely reallocated. */
- {
- char *buffer = output_diversion->u.buffer;
- output_diversion->u.buffer = xcharalloc ((size_t) wanted_size);
- memcpy (output_diversion->u.buffer, buffer, output_diversion->used);
- free (buffer);
- }
-
- total_buffer_size += wanted_size - output_diversion->size;
- output_diversion->size = wanted_size;
-
- output_cursor = output_diversion->u.buffer + output_diversion->used;
- output_unused = wanted_size - output_diversion->used;
- }
-}
-
-/*--------------------------------------------------------------.
-| Output one character CHAR, when it is known that it goes to a |
-| diversion file or an in-memory diversion buffer. |
-`--------------------------------------------------------------*/
-
-#define OUTPUT_CHARACTER(Char) \
- if (output_file) \
- putc ((Char), output_file); \
- else if (output_unused == 0) \
- output_character_helper ((Char)); \
- else \
- (output_unused--, *output_cursor++ = (Char))
-
-static void
-output_character_helper (int character)
-{
- make_room_for (1);
-
- if (output_file)
- putc (character, output_file);
- else
- {
- *output_cursor++ = character;
- output_unused--;
- }
-}
-
-/*-------------------------------------------------------------------.
-| Output one TEXT having LENGTH characters, when it is known that it |
-| goes to a diversion file or an in-memory diversion buffer. |
-`-------------------------------------------------------------------*/
-
-void
-output_text (const char *text, int length)
-{
- int count;
-
- if (!output_diversion || !length)
- return;
-
- if (!output_file && length > output_unused)
- make_room_for (length);
-
- if (output_file)
- {
- count = fwrite (text, length, 1, output_file);
- if (count != 1)
- M4ERROR ((EXIT_FAILURE, errno, "ERROR: copying inserted file"));
- }
- else
- {
- memcpy (output_cursor, text, (size_t) length);
- output_cursor += length;
- output_unused -= length;
- }
-}
-
-/*--------------------------------------------------------------------.
-| Add some text into an obstack OBS, taken from TEXT, having LENGTH |
-| characters. If OBS is NULL, output the text to an external file |
-| or an in-memory diversion buffer instead. If OBS is NULL, and |
-| there is no output file, the text is discarded. LINE is the line |
-| where the token starts (not necessarily current_line, in the case |
-| of multiline tokens). |
-| |
-| If we are generating sync lines, the output has to be examined, |
-| because we need to know how much output each input line generates. |
-| In general, sync lines are output whenever a single input lines |
-| generates several output lines, or when several input lines do not |
-| generate any output. |
-`--------------------------------------------------------------------*/
-
-void
-shipout_text (struct obstack *obs, const char *text, int length, int line)
-{
- static bool start_of_output_line = true;
- const char *cursor;
-
- /* If output goes to an obstack, merely add TEXT to it. */
-
- if (obs != NULL)
- {
- obstack_grow (obs, text, length);
- return;
- }
-
- /* Do nothing if TEXT should be discarded. */
-
- if (output_diversion == NULL)
- return;
-
- /* Output TEXT to a file, or in-memory diversion buffer. */
-
- if (!sync_output)
- switch (length)
- {
-
- /* In-line short texts. */
-
- case 8: OUTPUT_CHARACTER (*text); text++;
- case 7: OUTPUT_CHARACTER (*text); text++;
- case 6: OUTPUT_CHARACTER (*text); text++;
- case 5: OUTPUT_CHARACTER (*text); text++;
- case 4: OUTPUT_CHARACTER (*text); text++;
- case 3: OUTPUT_CHARACTER (*text); text++;
- case 2: OUTPUT_CHARACTER (*text); text++;
- case 1: OUTPUT_CHARACTER (*text);
- case 0:
- return;
-
- /* Optimize longer texts. */
-
- default:
- output_text (text, length);
- }
- else
- {
- /* Check for syncline only at the start of a token. Multiline
- tokens, and tokens that are out of sync but in the middle of
- the line, must wait until the next raw newline triggers a
- syncline. */
- if (start_of_output_line)
- {
- start_of_output_line = false;
- output_current_line++;
-#ifdef DEBUG_OUTPUT
- xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n",
- line, current_line, output_current_line);
-#endif
-
- /* Output a `#line NUM' synchronization directive if needed.
- If output_current_line was previously given a negative
- value (invalidated), output `#line NUM "FILE"' instead. */
-
- if (output_current_line != line)
- {
- OUTPUT_CHARACTER ('#');
- OUTPUT_CHARACTER ('l');
- OUTPUT_CHARACTER ('i');
- OUTPUT_CHARACTER ('n');
- OUTPUT_CHARACTER ('e');
- OUTPUT_CHARACTER (' ');
- for (cursor = ntoa (line, 10); *cursor; cursor++)
- OUTPUT_CHARACTER (*cursor);
- if (output_current_line < 1 && current_file[0] != '\0')
- {
- OUTPUT_CHARACTER (' ');
- OUTPUT_CHARACTER ('"');
- for (cursor = current_file; *cursor; cursor++)
- OUTPUT_CHARACTER (*cursor);
- OUTPUT_CHARACTER ('"');
- }
- OUTPUT_CHARACTER ('\n');
- output_current_line = line;
- }
- }
-
- /* Output the token, and track embedded newlines. */
- for (; length-- > 0; text++)
- {
- if (start_of_output_line)
- {
- start_of_output_line = false;
- output_current_line++;
-#ifdef DEBUG_OUTPUT
- xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n",
- line, current_line, output_current_line);
-#endif
- }
- OUTPUT_CHARACTER (*text);
- if (*text == '\n')
- start_of_output_line = true;
- }
- }
-}
-
-/* Functions for use by diversions. */
-
-/*------------------------------------------------------------------.
-| Make a file for diversion DIVNUM, and install it in the diversion |
-| table. Grow the size of the diversion table as needed. |
-`------------------------------------------------------------------*/
-
-/* The number of possible diversions is limited only by memory and
- available file descriptors (each overflowing diversion uses one). */
-
-void
-make_diversion (int divnum)
-{
- m4_diversion *diversion = NULL;
-
- if (current_diversion == divnum)
- return;
-
- if (output_diversion)
- {
- if (!output_diversion->size && !output_diversion->u.file)
- {
- assert (!output_diversion->used);
- if (!gl_oset_remove (diversion_table, output_diversion))
- assert (false);
- output_diversion->u.next = free_list;
- free_list = output_diversion;
- }
- else if (output_diversion->size)
- output_diversion->used = output_diversion->size - output_unused;
- else if (output_diversion->used)
- {
- FILE *file = output_diversion->u.file;
- output_diversion->u.file = NULL;
- if (m4_tmpclose (file, output_diversion->divnum) != 0)
- m4_error (0, errno,
- _("cannot close temporary file for diversion"));
- }
- output_diversion = NULL;
- output_file = NULL;
- output_cursor = NULL;
- output_unused = 0;
- }
-
- current_diversion = divnum;
-
- if (divnum < 0)
- return;
-
- if (divnum == 0)
- diversion = &div0;
- else
- {
- const void *elt;
- if (gl_oset_search_atleast (diversion_table, threshold_diversion_CB,
- &divnum, &elt))
- {
- m4_diversion *temp = (m4_diversion *) elt;
- if (temp->divnum == divnum)
- diversion = temp;
- }
- }
- if (diversion == NULL)
- {
- /* First time visiting this diversion. */
- if (free_list)
- {
- diversion = free_list;
- free_list = diversion->u.next;
- }
- else
- {
- diversion = (m4_diversion *) obstack_alloc (&diversion_storage,
- sizeof *diversion);
- diversion->size = 0;
- diversion->used = 0;
- }
- diversion->u.file = NULL;
- diversion->divnum = divnum;
- gl_oset_add (diversion_table, diversion);
- }
-
- output_diversion = diversion;
- if (output_diversion->size)
- {
- output_cursor = output_diversion->u.buffer + output_diversion->used;
- output_unused = output_diversion->size - output_diversion->used;
- }
- else
- {
- if (!output_diversion->u.file && output_diversion->used)
- output_diversion->u.file = m4_tmpopen (output_diversion->divnum,
- false);
- output_file = output_diversion->u.file;
- }
- output_current_line = -1;
-}
-
-/*-------------------------------------------------------------------.
-| Insert a FILE into the current output file, in the same manner |
-| diversions are handled. This allows files to be included, without |
-| having them rescanned by m4. |
-`-------------------------------------------------------------------*/
-
-void
-insert_file (FILE *file)
-{
- static char buffer[COPY_BUFFER_SIZE];
- size_t length;
-
- /* Optimize out inserting into a sink. */
- if (!output_diversion)
- return;
-
- /* Insert output by big chunks. */
- while (1)
- {
- length = fread (buffer, 1, sizeof buffer, file);
- if (ferror (file))
- M4ERROR ((EXIT_FAILURE, errno, "error reading inserted file"));
- if (length == 0)
- break;
- output_text (buffer, length);
- }
-}
-
-/*-------------------------------------------------------------------.
-| Insert DIVERSION (but not div0) into the current output file. The |
-| diversion is NOT placed on the expansion obstack, because it must |
-| not be rescanned. When the file is closed, it is deleted by the |
-| system. |
-`-------------------------------------------------------------------*/
-
-static void
-insert_diversion_helper (m4_diversion *diversion)
-{
- /* Effectively undivert only if an output stream is active. */
- if (output_diversion)
- {
- if (diversion->size)
- {
- if (!output_diversion->u.file)
- {
- /* Transferring diversion metadata is faster than
- copying contents. */
- assert (!output_diversion->used && output_diversion != &div0
- && !output_file);
- output_diversion->u.buffer = diversion->u.buffer;
- output_diversion->size = diversion->size;
- output_cursor = diversion->u.buffer + diversion->used;
- output_unused = diversion->size - diversion->used;
- diversion->u.buffer = NULL;
- }
- else
- {
- /* Avoid double-charging the total in-memory size when
- transferring from one in-memory diversion to
- another. */
- total_buffer_size -= diversion->size;
- output_text (diversion->u.buffer, diversion->used);
- }
- }
- else if (!output_diversion->u.file)
- {
- /* Transferring diversion metadata is faster than copying
- contents. */
- assert (!output_diversion->used && output_diversion != &div0
- && !output_file);
- output_diversion->u.file = m4_tmprename (diversion->divnum,
- output_diversion->divnum);
- output_diversion->used = 1;
- output_file = output_diversion->u.file;
- diversion->u.file = NULL;
- diversion->size = 1;
- }
- else
- {
- if (!diversion->u.file)
- diversion->u.file = m4_tmpopen (diversion->divnum, true);
- insert_file (diversion->u.file);
- }
-
- output_current_line = -1;
- }
-
- /* Return all space used by the diversion. */
- if (diversion->size)
- {
- if (!output_diversion)
- total_buffer_size -= diversion->size;
- free (diversion->u.buffer);
- diversion->size = 0;
- }
- else
- {
- if (diversion->u.file)
- {
- FILE *file = diversion->u.file;
- diversion->u.file = NULL;
- if (m4_tmpclose (file, diversion->divnum) != 0)
- m4_error (0, errno,
- _("cannot clean temporary file for diversion"));
- }
- if (m4_tmpremove (diversion->divnum) != 0)
- M4ERROR ((0, errno, "cannot clean temporary file for diversion"));
- }
- diversion->used = 0;
- gl_oset_remove (diversion_table, diversion);
- diversion->u.next = free_list;
- free_list = diversion;
-}
-
-/*------------------------------------------------------------------.
-| Insert diversion number DIVNUM into the current output file. The |
-| diversion is NOT placed on the expansion obstack, because it must |
-| not be rescanned. When the file is closed, it is deleted by the |
-| system. |
-`------------------------------------------------------------------*/
-
-void
-insert_diversion (int divnum)
-{
- const void *elt;
-
- /* Do not care about nonexistent diversions, and undiverting stdout
- or self is a no-op. */
- if (divnum <= 0 || current_diversion == divnum)
- return;
- if (gl_oset_search_atleast (diversion_table, threshold_diversion_CB,
- &divnum, &elt))
- {
- m4_diversion *diversion = (m4_diversion *) elt;
- if (diversion->divnum == divnum)
- insert_diversion_helper (diversion);
- }
-}
-
-/*----------------------------------------------------------------.
-| Get back all diversions. This is done just before exiting from |
-| main, and from m4_undivert (), if called without arguments. |
-`----------------------------------------------------------------*/
-
-void
-undivert_all (void)
-{
- const void *elt;
- gl_oset_iterator_t iter = gl_oset_iterator (diversion_table);
- while (gl_oset_iterator_next (&iter, &elt))
- {
- m4_diversion *diversion = (m4_diversion *) elt;
- if (diversion->divnum != current_diversion)
- insert_diversion_helper (diversion);
- }
- gl_oset_iterator_free (&iter);
-}
-
-/*-------------------------------------------------------------.
-| Produce all diversion information in frozen format on FILE. |
-`-------------------------------------------------------------*/
-
-void
-freeze_diversions (FILE *file)
-{
- int saved_number;
- int last_inserted;
- gl_oset_iterator_t iter;
- const void *elt;
-
- saved_number = current_diversion;
- last_inserted = 0;
- make_diversion (0);
- output_file = file; /* kludge in the frozen file */
-
- iter = gl_oset_iterator (diversion_table);
- while (gl_oset_iterator_next (&iter, &elt))
- {
- m4_diversion *diversion = (m4_diversion *) elt;
- if (diversion->size || diversion->used)
- {
- if (diversion->size)
- xfprintf (file, "D%d,%d\n", diversion->divnum, diversion->used);
- else
- {
- struct stat file_stat;
- diversion->u.file = m4_tmpopen (diversion->divnum, true);
- if (fstat (fileno (diversion->u.file), &file_stat) < 0)
- M4ERROR ((EXIT_FAILURE, errno, "cannot stat diversion"));
- if (file_stat.st_size < 0
- || (file_stat.st_size + 0UL
- != (unsigned long int) file_stat.st_size))
- M4ERROR ((EXIT_FAILURE, 0, "diversion too large"));
- xfprintf (file, "D%d,%lu\n", diversion->divnum,
- (unsigned long int) file_stat.st_size);
- }
-
- insert_diversion_helper (diversion);
- putc ('\n', file);
-
- last_inserted = diversion->divnum;
- }
- }
- gl_oset_iterator_free (&iter);
-
- /* Save the active diversion number, if not already. */
-
- if (saved_number != last_inserted)
- xfprintf (file, "D%d,0\n\n", saved_number);
-}
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "m4.h"
+
+#include <limits.h>
+#include <sys/stat.h>
+
+#include "gl_avltree_oset.h"
+#include "gl_xoset.h"
+
+/* Size of initial in-memory buffer size for diversions. Small diversions
+ would usually fit in. */
+#define INITIAL_BUFFER_SIZE 512
+
+/* Maximum value for the total of all in-memory buffer sizes for
+ diversions. */
+#define MAXIMUM_TOTAL_SIZE (512 * 1024)
+
+/* Size of buffer size to use while copying files. */
+#define COPY_BUFFER_SIZE (32 * 512)
+
+/* Output functions. Most of the complexity is for handling cpp like
+ sync lines.
+
+ This code is fairly entangled with the code in input.c, and maybe it
+ belongs there? */
+
+typedef struct temp_dir m4_temp_dir;
+
+/* When part of diversion_table, each struct m4_diversion either
+ represents an open file (zero size, non-NULL u.file), an in-memory
+ buffer (non-zero size, non-NULL u.buffer), or an unused placeholder
+ diversion (zero size, u is NULL, non-zero used indicates that a
+ file has been created). When not part of diversion_table, u.next
+ is a pointer to the free_list chain. */
+
+typedef struct m4_diversion m4_diversion;
+
+struct m4_diversion
+ {
+ union
+ {
+ FILE *file; /* Diversion file on disk. */
+ char *buffer; /* Malloc'd diversion buffer. */
+ m4_diversion *next; /* Free-list pointer */
+ } u;
+ int divnum; /* Which diversion this represents. */
+ int size; /* Usable size before reallocation. */
+ int used; /* Used buffer length, or tmp file exists. */
+ };
+
+/* Table of diversions 1 through INT_MAX. */
+static gl_oset_t diversion_table;
+
+/* Diversion 0 (not part of diversion_table). */
+static m4_diversion div0;
+
+/* Linked list of reclaimed diversion storage. */
+static m4_diversion *free_list;
+
+/* Obstack from which diversion storage is allocated. */
+static struct obstack diversion_storage;
+
+/* Total size of all in-memory buffer sizes. */
+static int total_buffer_size;
+
+/* The number of the currently active diversion. This variable is
+ maintained for the `divnum' builtin function. */
+int current_diversion;
+
+/* Current output diversion, NULL if output is being currently
+ discarded. output_diversion->u is guaranteed non-NULL except when
+ the diversion has never been used; use size to determine if it is a
+ malloc'd buffer or a FILE. output_diversion->used is 0 if u.file
+ is stdout, and non-zero if this is a malloc'd buffer or a temporary
+ diversion file. */
+static m4_diversion *output_diversion;
+
+/* Cache of output_diversion->u.file, only valid when
+ output_diversion->size is 0. */
+static FILE *output_file;
+
+/* Cache of output_diversion->u.buffer + output_diversion->used, only
+ valid when output_diversion->size is non-zero. */
+static char *output_cursor;
+
+/* Cache of output_diversion->size - output_diversion->used, only
+ valid when output_diversion->size is non-zero. */
+static int output_unused;
+
+/* Number of input line we are generating output for. */
+int output_current_line;
+
+/* Temporary directory holding all spilled diversion files. */
+static m4_temp_dir *output_temp_dir;
+
+/* Cache of most recently used spilled diversion files. */
+static FILE *tmp_file1;
+static FILE *tmp_file2;
+
+/* Diversions that own tmp_file, or 0. */
+static int tmp_file1_owner;
+static int tmp_file2_owner;
+
+/* True if tmp_file2 is more recently used. */
+static bool tmp_file2_recent;
+
+
+/* Internal routines. */
+
+/* Callback for comparing list elements ELT1 and ELT2 for order in
+ diversion_table. */
+static int
+cmp_diversion_CB (const void *elt1, const void *elt2)
+{
+ const m4_diversion *d1 = (const m4_diversion *) elt1;
+ const m4_diversion *d2 = (const m4_diversion *) elt2;
+ /* No need to worry about overflow, since we don't create diversions
+ with negative divnum. */
+ return d1->divnum - d2->divnum;
+}
+
+/* Callback for comparing list element ELT against THRESHOLD. */
+static bool
+threshold_diversion_CB (const void *elt, const void *threshold)
+{
+ const m4_diversion *diversion = (const m4_diversion *) elt;
+ /* No need to worry about overflow, since we don't create diversions
+ with negative divnum. */
+ return diversion->divnum >= *(const int *) threshold;
+}
+
+/* Clean up any temporary directory. Designed for use as an atexit
+ handler, where it is not safe to call exit() recursively; so this
+ calls _exit if a problem is encountered. */
+static void
+cleanup_tmpfile (void)
+{
+ /* Close any open diversions. */
+ bool fail = false;
+
+ if (diversion_table)
+ {
+ const void *elt;
+ gl_oset_iterator_t iter = gl_oset_iterator (diversion_table);
+ while (gl_oset_iterator_next (&iter, &elt))
+ {
+ m4_diversion *diversion = (m4_diversion *) elt;
+ if (!diversion->size && diversion->u.file
+ && close_stream_temp (diversion->u.file) != 0)
+ {
+ M4ERROR ((0, errno,
+ "cannot clean temporary file for diversion"));
+ fail = true;
+ }
+ }
+ gl_oset_iterator_free (&iter);
+ }
+
+ /* Clean up the temporary directory. */
+ if (cleanup_temp_dir (output_temp_dir) != 0)
+ fail = true;
+ if (fail)
+ _exit (exit_failure);
+}
+
+/* Convert DIVNUM into a temporary file name for use in m4_tmp*. */
+static const char *
+m4_tmpname (int divnum)
+{
+ static char *buffer;
+ static char *tail;
+ if (buffer == NULL)
+ {
+ tail = xasprintf ("%s/m4-%d", output_temp_dir->dir_name, INT_MAX);
+ buffer = (char *) obstack_copy0 (&diversion_storage, tail,
+ strlen (tail));
+ free (tail);
+ tail = strrchr (buffer, '-') + 1;
+ }
+ assert (0 < divnum);
+ sprintf (tail, "%d", divnum);
+ return buffer;
+}
+
+/* Create a temporary file for diversion DIVNUM open for reading and
+ writing in a secure temp directory. The file will be automatically
+ closed and deleted on a fatal signal. The file can be closed and
+ reopened with m4_tmpclose and m4_tmpopen, or moved with
+ m4_tmprename; when finally done with the file, close it with
+ m4_tmpremove. Exits on failure, so the return value is always an
+ open file. */
+static FILE *
+m4_tmpfile (int divnum)
+{
+ const char *name;
+ FILE *file;
+
+ if (output_temp_dir == NULL)
+ {
+ output_temp_dir = create_temp_dir ("m4-", NULL, true);
+ if (output_temp_dir == NULL)
+ M4ERROR ((EXIT_FAILURE, errno,
+ "cannot create temporary file for diversion"));
+ atexit (cleanup_tmpfile);
+ }
+ name = m4_tmpname (divnum);
+ register_temp_file (output_temp_dir, name);
+ file = fopen_temp (name, O_BINARY ? "wb+" : "w+");
+ if (file == NULL)
+ {
+ unregister_temp_file (output_temp_dir, name);
+ M4ERROR ((EXIT_FAILURE, errno,
+ "cannot create temporary file for diversion"));
+ }
+ else if (set_cloexec_flag (fileno (file), true) != 0)
+ M4ERROR ((warning_status, errno,
+ "Warning: cannot protect diversion across forks"));
+ return file;
+}
+
+/* Reopen a temporary file for diversion DIVNUM for reading and
+ writing in a secure temp directory. If REREAD, the file is
+ positioned at offset 0, otherwise the file is positioned at the
+ end. Exits on failure, so the return value is always an open
+ file. */
+static FILE *
+m4_tmpopen (int divnum, bool reread)
+{
+ const char *name;
+ FILE *file;
+
+ if (tmp_file1_owner == divnum)
+ {
+ if (reread && fseeko (tmp_file1, 0, SEEK_SET) != 0)
+ m4_error (EXIT_FAILURE, errno,
+ _("cannot seek within diversion"));
+ tmp_file2_recent = false;
+ return tmp_file1;
+ }
+ else if (tmp_file2_owner == divnum)
+ {
+ if (reread && fseeko (tmp_file2, 0, SEEK_SET) != 0)
+ m4_error (EXIT_FAILURE, errno,
+ _("cannot seek within diversion"));
+ tmp_file2_recent = true;
+ return tmp_file2;
+ }
+ name = m4_tmpname (divnum);
+ /* We need update mode, to avoid truncation. */
+ file = fopen_temp (name, O_BINARY ? "rb+" : "r+");
+ if (file == NULL)
+ M4ERROR ((EXIT_FAILURE, errno,
+ "cannot create temporary file for diversion"));
+ else if (set_cloexec_flag (fileno (file), true) != 0)
+ m4_error (0, errno, _("cannot protect diversion across forks"));
+ /* Update mode starts at the beginning of the stream, but sometimes
+ we want the end. */
+ else if (!reread && fseeko (file, 0, SEEK_END) != 0)
+ m4_error (EXIT_FAILURE, errno,
+ _("cannot seek within diversion"));
+ return file;
+}
+
+/* Close, but don't delete, a temporary FILE for diversion DIVNUM. To
+ reduce the I/O overhead of repeatedly opening and closing the same
+ file, this implementation caches the most recent spilled diversion.
+ On the other hand, keeping every spilled diversion open would run
+ into EMFILE limits. */
+static int
+m4_tmpclose (FILE *file, int divnum)
+{
+ int result = 0;
+ if (divnum != tmp_file1_owner && divnum != tmp_file2_owner)
+ {
+ if (tmp_file2_recent)
+ {
+ if (tmp_file1_owner)
+ result = close_stream_temp (tmp_file1);
+ tmp_file1 = file;
+ tmp_file1_owner = divnum;
+ }
+ else
+ {
+ if (tmp_file2_owner)
+ result = close_stream_temp (tmp_file2);
+ tmp_file2 = file;
+ tmp_file2_owner = divnum;
+ }
+ }
+ return result;
+}
+
+/* Delete a closed temporary FILE for diversion DIVNUM. */
+static int
+m4_tmpremove (int divnum)
+{
+ if (divnum == tmp_file1_owner)
+ {
+ int result = close_stream_temp (tmp_file1);
+ if (result)
+ return result;
+ tmp_file1_owner = 0;
+ }
+ else if (divnum == tmp_file2_owner)
+ {
+ int result = close_stream_temp (tmp_file2);
+ if (result)
+ return result;
+ tmp_file2_owner = 0;
+ }
+ return cleanup_temp_file (output_temp_dir, m4_tmpname (divnum));
+}
+
+/* Transfer the temporary file for diversion OLDNUM to the previously
+ unused diversion NEWNUM. Return an open stream visiting the new
+ temporary file, positioned at the end, or exit on failure. */
+static FILE*
+m4_tmprename (int oldnum, int newnum)
+{
+ /* m4_tmpname reuses its return buffer. */
+ char *oldname = xstrdup (m4_tmpname (oldnum));
+ const char *newname = m4_tmpname (newnum);
+ register_temp_file (output_temp_dir, newname);
+ if (oldnum == tmp_file1_owner)
+ {
+ /* Be careful of mingw, which can't rename an open file. */
+ if (RENAME_OPEN_FILE_WORKS)
+ tmp_file1_owner = newnum;
+ else
+ {
+ if (close_stream_temp (tmp_file1))
+ m4_error (EXIT_FAILURE, errno,
+ _("cannot close temporary file for diversion"));
+ tmp_file1_owner = 0;
+ }
+ }
+ else if (oldnum == tmp_file2_owner)
+ {
+ /* Be careful of mingw, which can't rename an open file. */
+ if (RENAME_OPEN_FILE_WORKS)
+ tmp_file2_owner = newnum;
+ else
+ {
+ if (close_stream_temp (tmp_file2))
+ m4_error (EXIT_FAILURE, errno,
+ _("cannot close temporary file for diversion"));
+ tmp_file2_owner = 0;
+ }
+ }
+ /* Either it is safe to rename an open file, or no one should have
+ oldname open at this point. */
+ if (rename (oldname, newname))
+ m4_error (EXIT_FAILURE, errno,
+ _("cannot create temporary file for diversion"));
+ unregister_temp_file (output_temp_dir, oldname);
+ free (oldname);
+ return m4_tmpopen (newnum, false);
+}
+
+
+/*------------------------.
+| Output initialization. |
+`------------------------*/
+
+void
+output_init (void)
+{
+ diversion_table = gl_oset_create_empty (GL_AVLTREE_OSET, cmp_diversion_CB,
+ NULL);
+ div0.u.file = stdout;
+ output_diversion = &div0;
+ output_file = stdout;
+ obstack_init (&diversion_storage);
+}
+
+void
+output_exit (void)
+{
+ /* Order is important, since we may have registered cleanup_tmpfile
+ as an atexit handler, and it must not traverse stale memory. */
+ gl_oset_t table = diversion_table;
+ if (tmp_file1_owner)
+ m4_tmpremove (tmp_file1_owner);
+ if (tmp_file2_owner)
+ m4_tmpremove (tmp_file2_owner);
+ diversion_table = NULL;
+ gl_oset_free (table);
+ obstack_free (&diversion_storage, NULL);
+}
+
+/*----------------------------------------------------------------.
+| Reorganize in-memory diversion buffers so the current diversion |
+| can accomodate LENGTH more characters without further |
+| reorganization. The current diversion buffer is made bigger if |
+| possible. But to make room for a bigger buffer, one of the |
+| in-memory diversion buffers might have to be flushed to a newly |
+| created temporary file. This flushed buffer might well be the |
+| current one. |
+`----------------------------------------------------------------*/
+
+static void
+make_room_for (int length)
+{
+ int wanted_size;
+ m4_diversion *selected_diversion = NULL;
+
+ /* Compute needed size for in-memory buffer. Diversions in-memory
+ buffers start at 0 bytes, then 512, then keep doubling until it is
+ decided to flush them to disk. */
+
+ output_diversion->used = output_diversion->size - output_unused;
+
+ for (wanted_size = output_diversion->size;
+ wanted_size < output_diversion->used + length;
+ wanted_size = wanted_size == 0 ? INITIAL_BUFFER_SIZE : wanted_size * 2)
+ ;
+
+ /* Check if we are exceeding the maximum amount of buffer memory. */
+
+ if (total_buffer_size - output_diversion->size + wanted_size
+ > MAXIMUM_TOTAL_SIZE)
+ {
+ int selected_used;
+ char *selected_buffer;
+ m4_diversion *diversion;
+ int count;
+ gl_oset_iterator_t iter;
+ const void *elt;
+
+ /* Find out the buffer having most data, in view of flushing it to
+ disk. Fake the current buffer as having already received the
+ projected data, while making the selection. So, if it is
+ selected indeed, we will flush it smaller, before it grows. */
+
+ selected_diversion = output_diversion;
+ selected_used = output_diversion->used + length;
+
+ iter = gl_oset_iterator (diversion_table);
+ while (gl_oset_iterator_next (&iter, &elt))
+ {
+ diversion = (m4_diversion *) elt;
+ if (diversion->used > selected_used)
+ {
+ selected_diversion = diversion;
+ selected_used = diversion->used;
+ }
+ }
+ gl_oset_iterator_free (&iter);
+
+ /* Create a temporary file, write the in-memory buffer of the
+ diversion to this file, then release the buffer. Zero the
+ diversion before doing anything that can exit () (including
+ m4_tmpfile), so that the atexit handler doesn't try to close
+ a garbage pointer as a file. */
+
+ selected_buffer = selected_diversion->u.buffer;
+ total_buffer_size -= selected_diversion->size;
+ selected_diversion->size = 0;
+ selected_diversion->u.file = NULL;
+ selected_diversion->u.file = m4_tmpfile (selected_diversion->divnum);
+
+ if (selected_diversion->used > 0)
+ {
+ count = fwrite (selected_buffer, (size_t) selected_diversion->used,
+ 1, selected_diversion->u.file);
+ if (count != 1)
+ M4ERROR ((EXIT_FAILURE, errno,
+ "ERROR: cannot flush diversion to temporary file"));
+ }
+
+ /* Reclaim the buffer space for other diversions. */
+
+ free (selected_buffer);
+ selected_diversion->used = 1;
+ }
+
+ /* Reload output_file, just in case the flushed diversion was current. */
+
+ if (output_diversion == selected_diversion)
+ {
+ /* The flushed diversion was current indeed. */
+
+ output_file = output_diversion->u.file;
+ output_cursor = NULL;
+ output_unused = 0;
+ }
+ else
+ {
+ /* Close any selected file since it is not the current diversion. */
+ if (selected_diversion)
+ {
+ FILE *file = selected_diversion->u.file;
+ selected_diversion->u.file = NULL;
+ if (m4_tmpclose (file, selected_diversion->divnum) != 0)
+ m4_error (0, errno,
+ _("cannot close temporary file for diversion"));
+ }
+
+ /* The current buffer may be safely reallocated. */
+ {
+ char *buffer = output_diversion->u.buffer;
+ output_diversion->u.buffer = xcharalloc ((size_t) wanted_size);
+ memcpy (output_diversion->u.buffer, buffer, output_diversion->used);
+ free (buffer);
+ }
+
+ total_buffer_size += wanted_size - output_diversion->size;
+ output_diversion->size = wanted_size;
+
+ output_cursor = output_diversion->u.buffer + output_diversion->used;
+ output_unused = wanted_size - output_diversion->used;
+ }
+}
+
+/*--------------------------------------------------------------.
+| Output one character CHAR, when it is known that it goes to a |
+| diversion file or an in-memory diversion buffer. |
+`--------------------------------------------------------------*/
+
+#define OUTPUT_CHARACTER(Char) \
+ if (output_file) \
+ putc ((Char), output_file); \
+ else if (output_unused == 0) \
+ output_character_helper ((Char)); \
+ else \
+ (output_unused--, *output_cursor++ = (Char))
+
+static void
+output_character_helper (int character)
+{
+ make_room_for (1);
+
+ if (output_file)
+ putc (character, output_file);
+ else
+ {
+ *output_cursor++ = character;
+ output_unused--;
+ }
+}
+
+/*-------------------------------------------------------------------.
+| Output one TEXT having LENGTH characters, when it is known that it |
+| goes to a diversion file or an in-memory diversion buffer. |
+`-------------------------------------------------------------------*/
+
+void
+output_text (const char *text, int length)
+{
+ int count;
+
+ if (!output_diversion || !length)
+ return;
+
+ if (!output_file && length > output_unused)
+ make_room_for (length);
+
+ if (output_file)
+ {
+ count = fwrite (text, length, 1, output_file);
+ if (count != 1)
+ M4ERROR ((EXIT_FAILURE, errno, "ERROR: copying inserted file"));
+ }
+ else
+ {
+ memcpy (output_cursor, text, (size_t) length);
+ output_cursor += length;
+ output_unused -= length;
+ }
+}
+
+/*--------------------------------------------------------------------.
+| Add some text into an obstack OBS, taken from TEXT, having LENGTH |
+| characters. If OBS is NULL, output the text to an external file |
+| or an in-memory diversion buffer instead. If OBS is NULL, and |
+| there is no output file, the text is discarded. LINE is the line |
+| where the token starts (not necessarily current_line, in the case |
+| of multiline tokens). |
+| |
+| If we are generating sync lines, the output has to be examined, |
+| because we need to know how much output each input line generates. |
+| In general, sync lines are output whenever a single input lines |
+| generates several output lines, or when several input lines do not |
+| generate any output. |
+`--------------------------------------------------------------------*/
+
+void
+shipout_text (struct obstack *obs, const char *text, int length, int line)
+{
+ static bool start_of_output_line = true;
+ const char *cursor;
+
+ /* If output goes to an obstack, merely add TEXT to it. */
+
+ if (obs != NULL)
+ {
+ obstack_grow (obs, text, length);
+ return;
+ }
+
+ /* Do nothing if TEXT should be discarded. */
+
+ if (output_diversion == NULL)
+ return;
+
+ /* Output TEXT to a file, or in-memory diversion buffer. */
+
+ if (!sync_output)
+ switch (length)
+ {
+
+ /* In-line short texts. */
+
+ case 8: OUTPUT_CHARACTER (*text); text++;
+ case 7: OUTPUT_CHARACTER (*text); text++;
+ case 6: OUTPUT_CHARACTER (*text); text++;
+ case 5: OUTPUT_CHARACTER (*text); text++;
+ case 4: OUTPUT_CHARACTER (*text); text++;
+ case 3: OUTPUT_CHARACTER (*text); text++;
+ case 2: OUTPUT_CHARACTER (*text); text++;
+ case 1: OUTPUT_CHARACTER (*text);
+ case 0:
+ return;
+
+ /* Optimize longer texts. */
+
+ default:
+ output_text (text, length);
+ }
+ else
+ {
+ /* Check for syncline only at the start of a token. Multiline
+ tokens, and tokens that are out of sync but in the middle of
+ the line, must wait until the next raw newline triggers a
+ syncline. */
+ if (start_of_output_line)
+ {
+ start_of_output_line = false;
+ output_current_line++;
+#ifdef DEBUG_OUTPUT
+ xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n",
+ line, current_line, output_current_line);
+#endif
+
+ /* Output a `#line NUM' synchronization directive if needed.
+ If output_current_line was previously given a negative
+ value (invalidated), output `#line NUM "FILE"' instead. */
+
+ if (output_current_line != line)
+ {
+ OUTPUT_CHARACTER ('#');
+ OUTPUT_CHARACTER ('l');
+ OUTPUT_CHARACTER ('i');
+ OUTPUT_CHARACTER ('n');
+ OUTPUT_CHARACTER ('e');
+ OUTPUT_CHARACTER (' ');
+ for (cursor = ntoa (line, 10); *cursor; cursor++)
+ OUTPUT_CHARACTER (*cursor);
+ if (output_current_line < 1 && current_file[0] != '\0')
+ {
+ OUTPUT_CHARACTER (' ');
+ OUTPUT_CHARACTER ('"');
+ for (cursor = current_file; *cursor; cursor++)
+ OUTPUT_CHARACTER (*cursor);
+ OUTPUT_CHARACTER ('"');
+ }
+ OUTPUT_CHARACTER ('\n');
+ output_current_line = line;
+ }
+ }
+
+ /* Output the token, and track embedded newlines. */
+ for (; length-- > 0; text++)
+ {
+ if (start_of_output_line)
+ {
+ start_of_output_line = false;
+ output_current_line++;
+#ifdef DEBUG_OUTPUT
+ xfprintf (stderr, "DEBUG: line %d, cur %d, cur out %d\n",
+ line, current_line, output_current_line);
+#endif
+ }
+ OUTPUT_CHARACTER (*text);
+ if (*text == '\n')
+ start_of_output_line = true;
+ }
+ }
+}
+
+/* Functions for use by diversions. */
+
+/*------------------------------------------------------------------.
+| Make a file for diversion DIVNUM, and install it in the diversion |
+| table. Grow the size of the diversion table as needed. |
+`------------------------------------------------------------------*/
+
+/* The number of possible diversions is limited only by memory and
+ available file descriptors (each overflowing diversion uses one). */
+
+void
+make_diversion (int divnum)
+{
+ m4_diversion *diversion = NULL;
+
+ if (current_diversion == divnum)
+ return;
+
+ if (output_diversion)
+ {
+ if (!output_diversion->size && !output_diversion->u.file)
+ {
+ assert (!output_diversion->used);
+ if (!gl_oset_remove (diversion_table, output_diversion))
+ assert (false);
+ output_diversion->u.next = free_list;
+ free_list = output_diversion;
+ }
+ else if (output_diversion->size)
+ output_diversion->used = output_diversion->size - output_unused;
+ else if (output_diversion->used)
+ {
+ FILE *file = output_diversion->u.file;
+ output_diversion->u.file = NULL;
+ if (m4_tmpclose (file, output_diversion->divnum) != 0)
+ m4_error (0, errno,
+ _("cannot close temporary file for diversion"));
+ }
+ output_diversion = NULL;
+ output_file = NULL;
+ output_cursor = NULL;
+ output_unused = 0;
+ }
+
+ current_diversion = divnum;
+
+ if (divnum < 0)
+ return;
+
+ if (divnum == 0)
+ diversion = &div0;
+ else
+ {
+ const void *elt;
+ if (gl_oset_search_atleast (diversion_table, threshold_diversion_CB,
+ &divnum, &elt))
+ {
+ m4_diversion *temp = (m4_diversion *) elt;
+ if (temp->divnum == divnum)
+ diversion = temp;
+ }
+ }
+ if (diversion == NULL)
+ {
+ /* First time visiting this diversion. */
+ if (free_list)
+ {
+ diversion = free_list;
+ free_list = diversion->u.next;
+ }
+ else
+ {
+ diversion = (m4_diversion *) obstack_alloc (&diversion_storage,
+ sizeof *diversion);
+ diversion->size = 0;
+ diversion->used = 0;
+ }
+ diversion->u.file = NULL;
+ diversion->divnum = divnum;
+ gl_oset_add (diversion_table, diversion);
+ }
+
+ output_diversion = diversion;
+ if (output_diversion->size)
+ {
+ output_cursor = output_diversion->u.buffer + output_diversion->used;
+ output_unused = output_diversion->size - output_diversion->used;
+ }
+ else
+ {
+ if (!output_diversion->u.file && output_diversion->used)
+ output_diversion->u.file = m4_tmpopen (output_diversion->divnum,
+ false);
+ output_file = output_diversion->u.file;
+ }
+ output_current_line = -1;
+}
+
+/*-------------------------------------------------------------------.
+| Insert a FILE into the current output file, in the same manner |
+| diversions are handled. This allows files to be included, without |
+| having them rescanned by m4. |
+`-------------------------------------------------------------------*/
+
+void
+insert_file (FILE *file)
+{
+ static char buffer[COPY_BUFFER_SIZE];
+ size_t length;
+
+ /* Optimize out inserting into a sink. */
+ if (!output_diversion)
+ return;
+
+ /* Insert output by big chunks. */
+ while (1)
+ {
+ length = fread (buffer, 1, sizeof buffer, file);
+ if (ferror (file))
+ M4ERROR ((EXIT_FAILURE, errno, "error reading inserted file"));
+ if (length == 0)
+ break;
+ output_text (buffer, length);
+ }
+}
+
+/*-------------------------------------------------------------------.
+| Insert DIVERSION (but not div0) into the current output file. The |
+| diversion is NOT placed on the expansion obstack, because it must |
+| not be rescanned. When the file is closed, it is deleted by the |
+| system. |
+`-------------------------------------------------------------------*/
+
+static void
+insert_diversion_helper (m4_diversion *diversion)
+{
+ /* Effectively undivert only if an output stream is active. */
+ if (output_diversion)
+ {
+ if (diversion->size)
+ {
+ if (!output_diversion->u.file)
+ {
+ /* Transferring diversion metadata is faster than
+ copying contents. */
+ assert (!output_diversion->used && output_diversion != &div0
+ && !output_file);
+ output_diversion->u.buffer = diversion->u.buffer;
+ output_diversion->size = diversion->size;
+ output_cursor = diversion->u.buffer + diversion->used;
+ output_unused = diversion->size - diversion->used;
+ diversion->u.buffer = NULL;
+ }
+ else
+ {
+ /* Avoid double-charging the total in-memory size when
+ transferring from one in-memory diversion to
+ another. */
+ total_buffer_size -= diversion->size;
+ output_text (diversion->u.buffer, diversion->used);
+ }
+ }
+ else if (!output_diversion->u.file)
+ {
+ /* Transferring diversion metadata is faster than copying
+ contents. */
+ assert (!output_diversion->used && output_diversion != &div0
+ && !output_file);
+ output_diversion->u.file = m4_tmprename (diversion->divnum,
+ output_diversion->divnum);
+ output_diversion->used = 1;
+ output_file = output_diversion->u.file;
+ diversion->u.file = NULL;
+ diversion->size = 1;
+ }
+ else
+ {
+ if (!diversion->u.file)
+ diversion->u.file = m4_tmpopen (diversion->divnum, true);
+ insert_file (diversion->u.file);
+ }
+
+ output_current_line = -1;
+ }
+
+ /* Return all space used by the diversion. */
+ if (diversion->size)
+ {
+ if (!output_diversion)
+ total_buffer_size -= diversion->size;
+ free (diversion->u.buffer);
+ diversion->size = 0;
+ }
+ else
+ {
+ if (diversion->u.file)
+ {
+ FILE *file = diversion->u.file;
+ diversion->u.file = NULL;
+ if (m4_tmpclose (file, diversion->divnum) != 0)
+ m4_error (0, errno,
+ _("cannot clean temporary file for diversion"));
+ }
+ if (m4_tmpremove (diversion->divnum) != 0)
+ M4ERROR ((0, errno, "cannot clean temporary file for diversion"));
+ }
+ diversion->used = 0;
+ gl_oset_remove (diversion_table, diversion);
+ diversion->u.next = free_list;
+ free_list = diversion;
+}
+
+/*------------------------------------------------------------------.
+| Insert diversion number DIVNUM into the current output file. The |
+| diversion is NOT placed on the expansion obstack, because it must |
+| not be rescanned. When the file is closed, it is deleted by the |
+| system. |
+`------------------------------------------------------------------*/
+
+void
+insert_diversion (int divnum)
+{
+ const void *elt;
+
+ /* Do not care about nonexistent diversions, and undiverting stdout
+ or self is a no-op. */
+ if (divnum <= 0 || current_diversion == divnum)
+ return;
+ if (gl_oset_search_atleast (diversion_table, threshold_diversion_CB,
+ &divnum, &elt))
+ {
+ m4_diversion *diversion = (m4_diversion *) elt;
+ if (diversion->divnum == divnum)
+ insert_diversion_helper (diversion);
+ }
+}
+
+/*----------------------------------------------------------------.
+| Get back all diversions. This is done just before exiting from |
+| main, and from m4_undivert (), if called without arguments. |
+`----------------------------------------------------------------*/
+
+void
+undivert_all (void)
+{
+ const void *elt;
+ gl_oset_iterator_t iter = gl_oset_iterator (diversion_table);
+ while (gl_oset_iterator_next (&iter, &elt))
+ {
+ m4_diversion *diversion = (m4_diversion *) elt;
+ if (diversion->divnum != current_diversion)
+ insert_diversion_helper (diversion);
+ }
+ gl_oset_iterator_free (&iter);
+}
+
+/*-------------------------------------------------------------.
+| Produce all diversion information in frozen format on FILE. |
+`-------------------------------------------------------------*/
+
+void
+freeze_diversions (FILE *file)
+{
+ int saved_number;
+ int last_inserted;
+ gl_oset_iterator_t iter;
+ const void *elt;
+
+ saved_number = current_diversion;
+ last_inserted = 0;
+ make_diversion (0);
+ output_file = file; /* kludge in the frozen file */
+
+ iter = gl_oset_iterator (diversion_table);
+ while (gl_oset_iterator_next (&iter, &elt))
+ {
+ m4_diversion *diversion = (m4_diversion *) elt;
+ if (diversion->size || diversion->used)
+ {
+ if (diversion->size)
+ xfprintf (file, "D%d,%d\n", diversion->divnum, diversion->used);
+ else
+ {
+ struct stat file_stat;
+ diversion->u.file = m4_tmpopen (diversion->divnum, true);
+ if (fstat (fileno (diversion->u.file), &file_stat) < 0)
+ M4ERROR ((EXIT_FAILURE, errno, "cannot stat diversion"));
+ if (file_stat.st_size < 0
+ || (file_stat.st_size + 0UL
+ != (unsigned long int) file_stat.st_size))
+ M4ERROR ((EXIT_FAILURE, 0, "diversion too large"));
+ xfprintf (file, "D%d,%lu\n", diversion->divnum,
+ (unsigned long int) file_stat.st_size);
+ }
+
+ insert_diversion_helper (diversion);
+ putc ('\n', file);
+
+ last_inserted = diversion->divnum;
+ }
+ }
+ gl_oset_iterator_free (&iter);
+
+ /* Save the active diversion number, if not already. */
+
+ if (saved_number != last_inserted)
+ xfprintf (file, "D%d,0\n\n", saved_number);
+}
diff --git a/contrib/tools/bison/m4/src/path.c b/contrib/tools/bison/m4/src/path.c
index 278200b782..4e3d92c709 100644
--- a/contrib/tools/bison/m4/src/path.c
+++ b/contrib/tools/bison/m4/src/path.c
@@ -1,205 +1,205 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1993, 2004, 2006-2013 Free Software Foundation,
- Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* Handling of path search of included files via the builtins "include"
- and "sinclude". */
-
-#include "m4.h"
-
-struct includes
-{
- struct includes *next; /* next directory to search */
- const char *dir; /* directory */
- int len;
-};
-
-typedef struct includes includes;
-
-static includes *dir_list; /* the list of path directories */
-static includes *dir_list_end; /* the end of same */
-static int dir_max_length; /* length of longest directory name */
-
-
-void
-include_init (void)
-{
- dir_list = NULL;
- dir_list_end = NULL;
- dir_max_length = 0;
-}
-
-void
-include_env_init (void)
-{
- char *path;
- char *path_end;
- char *env_path;
-
- if (no_gnu_extensions)
- return;
-
- env_path = getenv ("M4PATH");
- if (env_path == NULL)
- return;
-
- env_path = xstrdup (env_path);
- path = env_path;
-
- do
- {
- path_end = strchr (path, ':');
- if (path_end)
- *path_end = '\0';
- add_include_directory (path);
- path = path_end + 1;
- }
- while (path_end);
- free (env_path);
-}
-
-void
-add_include_directory (const char *dir)
-{
- includes *incl;
-
- if (no_gnu_extensions)
- return;
-
- if (*dir == '\0')
- dir = ".";
-
- incl = (includes *) xmalloc (sizeof (struct includes));
- incl->next = NULL;
- incl->len = strlen (dir);
- incl->dir = xstrdup (dir);
-
- if (incl->len > dir_max_length) /* remember len of longest directory */
- dir_max_length = incl->len;
-
- if (dir_list_end == NULL)
- dir_list = incl;
- else
- dir_list_end->next = incl;
- dir_list_end = incl;
-
-#ifdef DEBUG_INCL
- xfprintf (stderr, "add_include_directory (%s);\n", dir);
-#endif
-}
-
-/* Attempt to open FILE; if it opens, verify that it is not a
- directory, and ensure it does not leak across execs. */
-static FILE *
-m4_fopen (const char *file)
-{
- FILE *fp = fopen (file, "r");
- if (fp)
- {
- struct stat st;
- int fd = fileno (fp);
- if (fstat (fd, &st) == 0 && S_ISDIR (st.st_mode))
- {
- fclose (fp);
- errno = EISDIR;
- return NULL;
- }
- if (set_cloexec_flag (fd, true) != 0)
- M4ERROR ((warning_status, errno,
- "Warning: cannot protect input file across forks"));
- }
- return fp;
-}
-
-/* Search for FILE, first in `.', then according to -I options. If
- successful, return the open file, and if RESULT is not NULL, set
- *RESULT to a malloc'd string that represents the file found with
- respect to the current working directory. */
-
-FILE *
-m4_path_search (const char *file, char **result)
-{
- FILE *fp;
- includes *incl;
- char *name; /* buffer for constructed name */
- int e;
-
- if (result)
- *result = NULL;
-
- /* Reject empty file. */
- if (!*file)
- {
- errno = ENOENT;
- return NULL;
- }
-
- /* Look in current working directory first. */
- fp = m4_fopen (file);
- if (fp != NULL)
- {
- if (result)
- *result = xstrdup (file);
- return fp;
- }
-
- /* If file not found, and filename absolute, fail. */
- if (IS_ABSOLUTE_FILE_NAME (file) || no_gnu_extensions)
- return NULL;
- e = errno;
-
- for (incl = dir_list; incl != NULL; incl = incl->next)
- {
- name = file_name_concat (incl->dir, file, NULL);
-
-#ifdef DEBUG_INCL
- xfprintf (stderr, "m4_path_search (%s) -- trying %s\n", file, name);
-#endif
-
- fp = m4_fopen (name);
- if (fp != NULL)
- {
- if (debug_level & DEBUG_TRACE_PATH)
- DEBUG_MESSAGE2 ("path search for `%s' found `%s'", file, name);
- if (result)
- *result = name;
- else
- free (name);
- return fp;
- }
- free (name);
- }
- errno = e;
- return fp;
-}
-
-#ifdef DEBUG_INCL
-
-static void M4_GNUC_UNUSED
-include_dump (void)
-{
- includes *incl;
-
- xfprintf (stderr, "include_dump:\n");
- for (incl = dir_list; incl != NULL; incl = incl->next)
- xfprintf (stderr, "\t%s\n", incl->dir);
-}
-
-#endif /* DEBUG_INCL */
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1993, 2004, 2006-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Handling of path search of included files via the builtins "include"
+ and "sinclude". */
+
+#include "m4.h"
+
+struct includes
+{
+ struct includes *next; /* next directory to search */
+ const char *dir; /* directory */
+ int len;
+};
+
+typedef struct includes includes;
+
+static includes *dir_list; /* the list of path directories */
+static includes *dir_list_end; /* the end of same */
+static int dir_max_length; /* length of longest directory name */
+
+
+void
+include_init (void)
+{
+ dir_list = NULL;
+ dir_list_end = NULL;
+ dir_max_length = 0;
+}
+
+void
+include_env_init (void)
+{
+ char *path;
+ char *path_end;
+ char *env_path;
+
+ if (no_gnu_extensions)
+ return;
+
+ env_path = getenv ("M4PATH");
+ if (env_path == NULL)
+ return;
+
+ env_path = xstrdup (env_path);
+ path = env_path;
+
+ do
+ {
+ path_end = strchr (path, ':');
+ if (path_end)
+ *path_end = '\0';
+ add_include_directory (path);
+ path = path_end + 1;
+ }
+ while (path_end);
+ free (env_path);
+}
+
+void
+add_include_directory (const char *dir)
+{
+ includes *incl;
+
+ if (no_gnu_extensions)
+ return;
+
+ if (*dir == '\0')
+ dir = ".";
+
+ incl = (includes *) xmalloc (sizeof (struct includes));
+ incl->next = NULL;
+ incl->len = strlen (dir);
+ incl->dir = xstrdup (dir);
+
+ if (incl->len > dir_max_length) /* remember len of longest directory */
+ dir_max_length = incl->len;
+
+ if (dir_list_end == NULL)
+ dir_list = incl;
+ else
+ dir_list_end->next = incl;
+ dir_list_end = incl;
+
+#ifdef DEBUG_INCL
+ xfprintf (stderr, "add_include_directory (%s);\n", dir);
+#endif
+}
+
+/* Attempt to open FILE; if it opens, verify that it is not a
+ directory, and ensure it does not leak across execs. */
+static FILE *
+m4_fopen (const char *file)
+{
+ FILE *fp = fopen (file, "r");
+ if (fp)
+ {
+ struct stat st;
+ int fd = fileno (fp);
+ if (fstat (fd, &st) == 0 && S_ISDIR (st.st_mode))
+ {
+ fclose (fp);
+ errno = EISDIR;
+ return NULL;
+ }
+ if (set_cloexec_flag (fd, true) != 0)
+ M4ERROR ((warning_status, errno,
+ "Warning: cannot protect input file across forks"));
+ }
+ return fp;
+}
+
+/* Search for FILE, first in `.', then according to -I options. If
+ successful, return the open file, and if RESULT is not NULL, set
+ *RESULT to a malloc'd string that represents the file found with
+ respect to the current working directory. */
+
+FILE *
+m4_path_search (const char *file, char **result)
+{
+ FILE *fp;
+ includes *incl;
+ char *name; /* buffer for constructed name */
+ int e;
+
+ if (result)
+ *result = NULL;
+
+ /* Reject empty file. */
+ if (!*file)
+ {
+ errno = ENOENT;
+ return NULL;
+ }
+
+ /* Look in current working directory first. */
+ fp = m4_fopen (file);
+ if (fp != NULL)
+ {
+ if (result)
+ *result = xstrdup (file);
+ return fp;
+ }
+
+ /* If file not found, and filename absolute, fail. */
+ if (IS_ABSOLUTE_FILE_NAME (file) || no_gnu_extensions)
+ return NULL;
+ e = errno;
+
+ for (incl = dir_list; incl != NULL; incl = incl->next)
+ {
+ name = file_name_concat (incl->dir, file, NULL);
+
+#ifdef DEBUG_INCL
+ xfprintf (stderr, "m4_path_search (%s) -- trying %s\n", file, name);
+#endif
+
+ fp = m4_fopen (name);
+ if (fp != NULL)
+ {
+ if (debug_level & DEBUG_TRACE_PATH)
+ DEBUG_MESSAGE2 ("path search for `%s' found `%s'", file, name);
+ if (result)
+ *result = name;
+ else
+ free (name);
+ return fp;
+ }
+ free (name);
+ }
+ errno = e;
+ return fp;
+}
+
+#ifdef DEBUG_INCL
+
+static void M4_GNUC_UNUSED
+include_dump (void)
+{
+ includes *incl;
+
+ xfprintf (stderr, "include_dump:\n");
+ for (incl = dir_list; incl != NULL; incl = incl->next)
+ xfprintf (stderr, "\t%s\n", incl->dir);
+}
+
+#endif /* DEBUG_INCL */
diff --git a/contrib/tools/bison/m4/src/symtab.c b/contrib/tools/bison/m4/src/symtab.c
index 7448c272cc..c901e1f803 100644
--- a/contrib/tools/bison/m4/src/symtab.c
+++ b/contrib/tools/bison/m4/src/symtab.c
@@ -1,401 +1,401 @@
-/* GNU m4 -- A simple macro processor
-
- Copyright (C) 1989-1994, 2003, 2006-2013 Free Software Foundation,
- Inc.
-
- This file is part of GNU M4.
-
- GNU M4 is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNU M4 is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* This file handles all the low level work around the symbol table. The
- symbol table is a simple chained hash table. Each symbol is described
- by a struct symbol, which is placed in the hash table based upon the
- symbol name. Symbols that hash to the same entry in the table are
- kept on a list, sorted by name. As a special case, to facilitate the
- "pushdef" and "popdef" builtins, a symbol can be several times in the
- symbol table, one for each definition. Since the name is the same,
- all the entries for the symbol will be on the same list, and will
- also, because the list is sorted, be adjacent. All the entries for a
- name are simply ordered on the list by age. The current definition
- will then always be the first found. */
-
-#include "m4.h"
-#include <limits.h>
-
-#ifdef DEBUG_SYM
-/* When evaluating hash table performance, this profiling code shows
- how many collisions were encountered. */
-
-struct profile
-{
- int entry; /* Number of times lookup_symbol called with this mode. */
- int comparisons; /* Number of times strcmp was called. */
- int misses; /* Number of times strcmp did not return 0. */
- long long bytes; /* Number of bytes compared. */
-};
-
-static struct profile profiles[5];
-static symbol_lookup current_mode;
-
-/* On exit, show a profile of symbol table performance. */
-static void
-show_profile (void)
-{
- int i;
- for (i = 0; i < 5; i++)
- {
- xfprintf(stderr, "m4: lookup mode %d called %d times, %d compares, "
- "%d misses, %lld bytes\n",
- i, profiles[i].entry, profiles[i].comparisons,
- profiles[i].misses, profiles[i].bytes);
- }
-}
-
-/* Like strcmp (S1, S2), but also track profiling statistics. */
-static int
-profile_strcmp (const char *s1, const char *s2)
-{
- int i = 1;
- int result;
- while (*s1 && *s1 == *s2)
- {
- s1++;
- s2++;
- i++;
- }
- result = (unsigned char) *s1 - (unsigned char) *s2;
- profiles[current_mode].comparisons++;
- if (result != 0)
- profiles[current_mode].misses++;
- profiles[current_mode].bytes += i;
- return result;
-}
-
-# define strcmp profile_strcmp
-#endif /* DEBUG_SYM */
-
-
-/*------------------------------------------------------------------.
-| Initialise the symbol table, by allocating the necessary storage, |
-| and zeroing all the entries. |
-`------------------------------------------------------------------*/
-
-/* Pointer to symbol table. */
-symbol **symtab;
-
-void
-symtab_init (void)
-{
- size_t i;
- symbol **s;
-
- s = symtab = (symbol **) xnmalloc (hash_table_size, sizeof (symbol *));
-
- for (i = 0; i < hash_table_size; i++)
- s[i] = NULL;
-
-#ifdef DEBUG_SYM
- {
- int e = atexit(show_profile);
- if (e != 0)
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: unable to show symtab profile"));
- }
-#endif /* DEBUG_SYM */
-}
-
-/*--------------------------------------------------.
-| Return a hashvalue for a string, from GNU-emacs. |
-`--------------------------------------------------*/
-
-static size_t M4_GNUC_PURE
-hash (const char *s)
-{
+/* GNU m4 -- A simple macro processor
+
+ Copyright (C) 1989-1994, 2003, 2006-2013 Free Software Foundation,
+ Inc.
+
+ This file is part of GNU M4.
+
+ GNU M4 is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU M4 is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* This file handles all the low level work around the symbol table. The
+ symbol table is a simple chained hash table. Each symbol is described
+ by a struct symbol, which is placed in the hash table based upon the
+ symbol name. Symbols that hash to the same entry in the table are
+ kept on a list, sorted by name. As a special case, to facilitate the
+ "pushdef" and "popdef" builtins, a symbol can be several times in the
+ symbol table, one for each definition. Since the name is the same,
+ all the entries for the symbol will be on the same list, and will
+ also, because the list is sorted, be adjacent. All the entries for a
+ name are simply ordered on the list by age. The current definition
+ will then always be the first found. */
+
+#include "m4.h"
+#include <limits.h>
+
+#ifdef DEBUG_SYM
+/* When evaluating hash table performance, this profiling code shows
+ how many collisions were encountered. */
+
+struct profile
+{
+ int entry; /* Number of times lookup_symbol called with this mode. */
+ int comparisons; /* Number of times strcmp was called. */
+ int misses; /* Number of times strcmp did not return 0. */
+ long long bytes; /* Number of bytes compared. */
+};
+
+static struct profile profiles[5];
+static symbol_lookup current_mode;
+
+/* On exit, show a profile of symbol table performance. */
+static void
+show_profile (void)
+{
+ int i;
+ for (i = 0; i < 5; i++)
+ {
+ xfprintf(stderr, "m4: lookup mode %d called %d times, %d compares, "
+ "%d misses, %lld bytes\n",
+ i, profiles[i].entry, profiles[i].comparisons,
+ profiles[i].misses, profiles[i].bytes);
+ }
+}
+
+/* Like strcmp (S1, S2), but also track profiling statistics. */
+static int
+profile_strcmp (const char *s1, const char *s2)
+{
+ int i = 1;
+ int result;
+ while (*s1 && *s1 == *s2)
+ {
+ s1++;
+ s2++;
+ i++;
+ }
+ result = (unsigned char) *s1 - (unsigned char) *s2;
+ profiles[current_mode].comparisons++;
+ if (result != 0)
+ profiles[current_mode].misses++;
+ profiles[current_mode].bytes += i;
+ return result;
+}
+
+# define strcmp profile_strcmp
+#endif /* DEBUG_SYM */
+
+
+/*------------------------------------------------------------------.
+| Initialise the symbol table, by allocating the necessary storage, |
+| and zeroing all the entries. |
+`------------------------------------------------------------------*/
+
+/* Pointer to symbol table. */
+symbol **symtab;
+
+void
+symtab_init (void)
+{
+ size_t i;
+ symbol **s;
+
+ s = symtab = (symbol **) xnmalloc (hash_table_size, sizeof (symbol *));
+
+ for (i = 0; i < hash_table_size; i++)
+ s[i] = NULL;
+
+#ifdef DEBUG_SYM
+ {
+ int e = atexit(show_profile);
+ if (e != 0)
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: unable to show symtab profile"));
+ }
+#endif /* DEBUG_SYM */
+}
+
+/*--------------------------------------------------.
+| Return a hashvalue for a string, from GNU-emacs. |
+`--------------------------------------------------*/
+
+static size_t M4_GNUC_PURE
+hash (const char *s)
+{
size_t val = 0;
-
+
const char *ptr = s;
char ch;
-
- while ((ch = *ptr++) != '\0')
- val = (val << 7) + (val >> (sizeof (val) * CHAR_BIT - 7)) + ch;
- return val;
-}
-
-/*--------------------------------------------.
-| Free all storage associated with a symbol. |
-`--------------------------------------------*/
-
-void
-free_symbol (symbol *sym)
-{
- if (SYMBOL_PENDING_EXPANSIONS (sym) > 0)
- SYMBOL_DELETED (sym) = true;
- else
- {
- free (SYMBOL_NAME (sym));
- if (SYMBOL_TYPE (sym) == TOKEN_TEXT)
- free (SYMBOL_TEXT (sym));
- free (sym);
- }
-}
-
-/*-------------------------------------------------------------------.
-| Search in, and manipulation of the symbol table, are all done by |
-| lookup_symbol (). It basically hashes NAME to a list in the |
-| symbol table, and searches this list for the first occurrence of a |
-| symbol with the name. |
-| |
-| The MODE parameter determines what lookup_symbol () will do. It |
-| can either just do a lookup, do a lookup and insert if not |
-| present, do an insertion even if the name is already in the list, |
-| delete the first occurrence of the name on the list, or delete all |
-| occurrences of the name on the list. |
-`-------------------------------------------------------------------*/
-
-symbol *
-lookup_symbol (const char *name, symbol_lookup mode)
-{
- size_t h;
- int cmp = 1;
- symbol *sym, *prev;
- symbol **spp;
-
-#if DEBUG_SYM
- current_mode = mode;
- profiles[mode].entry++;
-#endif /* DEBUG_SYM */
-
- h = hash (name);
- sym = symtab[h % hash_table_size];
-
- for (prev = NULL; sym != NULL; prev = sym, sym = sym->next)
- {
- cmp = strcmp (SYMBOL_NAME (sym), name);
- if (cmp >= 0)
- break;
- }
-
- /* If just searching, return status of search. */
-
- if (mode == SYMBOL_LOOKUP)
- return cmp == 0 ? sym : NULL;
-
- /* Symbol not found. */
-
- spp = (prev != NULL) ? &prev->next : &symtab[h % hash_table_size];
-
- switch (mode)
- {
-
- case SYMBOL_INSERT:
-
- /* If the name was found in the table, check whether it is still in
- use by a pending expansion. If so, replace the table element with
- a new one; if not, just return the symbol. If not found, just
- insert the name, and return the new symbol. */
-
- if (cmp == 0 && sym != NULL)
- {
- if (SYMBOL_PENDING_EXPANSIONS (sym) > 0)
- {
- symbol *old = sym;
- SYMBOL_DELETED (old) = true;
-
- sym = (symbol *) xmalloc (sizeof (symbol));
- SYMBOL_TYPE (sym) = TOKEN_VOID;
- SYMBOL_TRACED (sym) = SYMBOL_TRACED (old);
- SYMBOL_NAME (sym) = xstrdup (name);
- SYMBOL_SHADOWED (sym) = false;
- SYMBOL_MACRO_ARGS (sym) = false;
- SYMBOL_BLIND_NO_ARGS (sym) = false;
- SYMBOL_DELETED (sym) = false;
- SYMBOL_PENDING_EXPANSIONS (sym) = 0;
-
- SYMBOL_NEXT (sym) = SYMBOL_NEXT (old);
- SYMBOL_NEXT (old) = NULL;
- (*spp) = sym;
- }
- return sym;
- }
- /* Fall through. */
-
- case SYMBOL_PUSHDEF:
-
- /* Insert a name in the symbol table. If there is already a symbol
- with the name, insert this in front of it, and mark the old
- symbol as "shadowed". */
-
- sym = (symbol *) xmalloc (sizeof (symbol));
- SYMBOL_TYPE (sym) = TOKEN_VOID;
- SYMBOL_TRACED (sym) = false;
- SYMBOL_NAME (sym) = xstrdup (name);
- SYMBOL_SHADOWED (sym) = false;
- SYMBOL_MACRO_ARGS (sym) = false;
- SYMBOL_BLIND_NO_ARGS (sym) = false;
- SYMBOL_DELETED (sym) = false;
- SYMBOL_PENDING_EXPANSIONS (sym) = 0;
-
- SYMBOL_NEXT (sym) = *spp;
- (*spp) = sym;
-
- if (mode == SYMBOL_PUSHDEF && cmp == 0)
- {
- SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = true;
- SYMBOL_TRACED (sym) = SYMBOL_TRACED (SYMBOL_NEXT (sym));
- }
- return sym;
-
- case SYMBOL_DELETE:
- case SYMBOL_POPDEF:
-
- /* Delete occurrences of symbols with NAME. SYMBOL_DELETE kills
- all definitions, SYMBOL_POPDEF kills only the first.
- However, if the last instance of a symbol is marked for
- tracing, reinsert a placeholder in the table. And if the
- definition is still in use, let the caller free the memory
- after it is done with the symbol. */
-
- if (cmp != 0 || sym == NULL)
- return NULL;
- {
- bool traced = false;
- if (SYMBOL_NEXT (sym) != NULL
- && SYMBOL_SHADOWED (SYMBOL_NEXT (sym))
- && mode == SYMBOL_POPDEF)
- {
- SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = false;
- SYMBOL_TRACED (SYMBOL_NEXT (sym)) = SYMBOL_TRACED (sym);
- }
- else
- traced = SYMBOL_TRACED (sym);
- do
- {
- *spp = SYMBOL_NEXT (sym);
- free_symbol (sym);
- sym = *spp;
- }
- while (*spp != NULL && SYMBOL_SHADOWED (*spp)
- && mode == SYMBOL_DELETE);
- if (traced)
- {
- sym = (symbol *) xmalloc (sizeof (symbol));
- SYMBOL_TYPE (sym) = TOKEN_VOID;
- SYMBOL_TRACED (sym) = true;
- SYMBOL_NAME (sym) = xstrdup (name);
- SYMBOL_SHADOWED (sym) = false;
- SYMBOL_MACRO_ARGS (sym) = false;
- SYMBOL_BLIND_NO_ARGS (sym) = false;
- SYMBOL_DELETED (sym) = false;
- SYMBOL_PENDING_EXPANSIONS (sym) = 0;
-
- SYMBOL_NEXT (sym) = *spp;
- (*spp) = sym;
- }
- }
- return NULL;
-
- case SYMBOL_LOOKUP:
- default:
- M4ERROR ((warning_status, 0,
- "INTERNAL ERROR: invalid mode to symbol_lookup ()"));
- abort ();
- }
-}
-
-/*-----------------------------------------------------------------.
-| The following function is used for the cases where we want to do |
-| something to each and every symbol in the table. The function |
-| hack_all_symbols () traverses the symbol table, and calls a |
-| specified function FUNC for each symbol in the table. FUNC is |
-| called with a pointer to the symbol, and the DATA argument. |
-| |
-| FUNC may safely call lookup_symbol with mode SYMBOL_POPDEF or |
-| SYMBOL_LOOKUP, but any other mode can break the iteration. |
-`-----------------------------------------------------------------*/
-
-void
-hack_all_symbols (hack_symbol *func, void *data)
-{
- size_t h;
- symbol *sym;
- symbol *next;
-
- for (h = 0; h < hash_table_size; h++)
- {
- /* We allow func to call SYMBOL_POPDEF, which can invalidate
- sym, so we must grab the next element to traverse before
- calling func. */
- for (sym = symtab[h]; sym != NULL; sym = next)
- {
- next = SYMBOL_NEXT (sym);
- func (sym, data);
- }
- }
-}
-
-#ifdef DEBUG_SYM
-
-static void symtab_print_list (int i);
-
-static void M4_GNUC_UNUSED
-symtab_debug (void)
-{
- token_data td;
- const char *text;
- symbol *s;
- int delete;
- static int i;
-
- while (next_token (&td, NULL) == TOKEN_WORD)
- {
- text = TOKEN_DATA_TEXT (&td);
- if (*text == '_')
- {
- delete = 1;
- text++;
- }
- else
- delete = 0;
-
- s = lookup_symbol (text, SYMBOL_LOOKUP);
-
- if (s == NULL)
- xprintf ("Name `%s' is unknown\n", text);
-
- lookup_symbol (text, delete ? SYMBOL_DELETE : SYMBOL_INSERT);
- }
- symtab_print_list (i++);
-}
-
-static void
-symtab_print_list (int i)
-{
- symbol *sym;
- size_t h;
-
- xprintf ("Symbol dump #%d:\n", i);
- for (h = 0; h < hash_table_size; h++)
- for (sym = symtab[h]; sym != NULL; sym = sym->next)
- xprintf ("\tname %s, bucket %lu, addr %p, next %p, "
- "flags%s%s%s, pending %d\n",
- SYMBOL_NAME (sym),
- (unsigned long int) h, sym, SYMBOL_NEXT (sym),
- SYMBOL_TRACED (sym) ? " traced" : "",
- SYMBOL_SHADOWED (sym) ? " shadowed" : "",
- SYMBOL_DELETED (sym) ? " deleted" : "",
- SYMBOL_PENDING_EXPANSIONS (sym));
-}
-
-#endif /* DEBUG_SYM */
+
+ while ((ch = *ptr++) != '\0')
+ val = (val << 7) + (val >> (sizeof (val) * CHAR_BIT - 7)) + ch;
+ return val;
+}
+
+/*--------------------------------------------.
+| Free all storage associated with a symbol. |
+`--------------------------------------------*/
+
+void
+free_symbol (symbol *sym)
+{
+ if (SYMBOL_PENDING_EXPANSIONS (sym) > 0)
+ SYMBOL_DELETED (sym) = true;
+ else
+ {
+ free (SYMBOL_NAME (sym));
+ if (SYMBOL_TYPE (sym) == TOKEN_TEXT)
+ free (SYMBOL_TEXT (sym));
+ free (sym);
+ }
+}
+
+/*-------------------------------------------------------------------.
+| Search in, and manipulation of the symbol table, are all done by |
+| lookup_symbol (). It basically hashes NAME to a list in the |
+| symbol table, and searches this list for the first occurrence of a |
+| symbol with the name. |
+| |
+| The MODE parameter determines what lookup_symbol () will do. It |
+| can either just do a lookup, do a lookup and insert if not |
+| present, do an insertion even if the name is already in the list, |
+| delete the first occurrence of the name on the list, or delete all |
+| occurrences of the name on the list. |
+`-------------------------------------------------------------------*/
+
+symbol *
+lookup_symbol (const char *name, symbol_lookup mode)
+{
+ size_t h;
+ int cmp = 1;
+ symbol *sym, *prev;
+ symbol **spp;
+
+#if DEBUG_SYM
+ current_mode = mode;
+ profiles[mode].entry++;
+#endif /* DEBUG_SYM */
+
+ h = hash (name);
+ sym = symtab[h % hash_table_size];
+
+ for (prev = NULL; sym != NULL; prev = sym, sym = sym->next)
+ {
+ cmp = strcmp (SYMBOL_NAME (sym), name);
+ if (cmp >= 0)
+ break;
+ }
+
+ /* If just searching, return status of search. */
+
+ if (mode == SYMBOL_LOOKUP)
+ return cmp == 0 ? sym : NULL;
+
+ /* Symbol not found. */
+
+ spp = (prev != NULL) ? &prev->next : &symtab[h % hash_table_size];
+
+ switch (mode)
+ {
+
+ case SYMBOL_INSERT:
+
+ /* If the name was found in the table, check whether it is still in
+ use by a pending expansion. If so, replace the table element with
+ a new one; if not, just return the symbol. If not found, just
+ insert the name, and return the new symbol. */
+
+ if (cmp == 0 && sym != NULL)
+ {
+ if (SYMBOL_PENDING_EXPANSIONS (sym) > 0)
+ {
+ symbol *old = sym;
+ SYMBOL_DELETED (old) = true;
+
+ sym = (symbol *) xmalloc (sizeof (symbol));
+ SYMBOL_TYPE (sym) = TOKEN_VOID;
+ SYMBOL_TRACED (sym) = SYMBOL_TRACED (old);
+ SYMBOL_NAME (sym) = xstrdup (name);
+ SYMBOL_SHADOWED (sym) = false;
+ SYMBOL_MACRO_ARGS (sym) = false;
+ SYMBOL_BLIND_NO_ARGS (sym) = false;
+ SYMBOL_DELETED (sym) = false;
+ SYMBOL_PENDING_EXPANSIONS (sym) = 0;
+
+ SYMBOL_NEXT (sym) = SYMBOL_NEXT (old);
+ SYMBOL_NEXT (old) = NULL;
+ (*spp) = sym;
+ }
+ return sym;
+ }
+ /* Fall through. */
+
+ case SYMBOL_PUSHDEF:
+
+ /* Insert a name in the symbol table. If there is already a symbol
+ with the name, insert this in front of it, and mark the old
+ symbol as "shadowed". */
+
+ sym = (symbol *) xmalloc (sizeof (symbol));
+ SYMBOL_TYPE (sym) = TOKEN_VOID;
+ SYMBOL_TRACED (sym) = false;
+ SYMBOL_NAME (sym) = xstrdup (name);
+ SYMBOL_SHADOWED (sym) = false;
+ SYMBOL_MACRO_ARGS (sym) = false;
+ SYMBOL_BLIND_NO_ARGS (sym) = false;
+ SYMBOL_DELETED (sym) = false;
+ SYMBOL_PENDING_EXPANSIONS (sym) = 0;
+
+ SYMBOL_NEXT (sym) = *spp;
+ (*spp) = sym;
+
+ if (mode == SYMBOL_PUSHDEF && cmp == 0)
+ {
+ SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = true;
+ SYMBOL_TRACED (sym) = SYMBOL_TRACED (SYMBOL_NEXT (sym));
+ }
+ return sym;
+
+ case SYMBOL_DELETE:
+ case SYMBOL_POPDEF:
+
+ /* Delete occurrences of symbols with NAME. SYMBOL_DELETE kills
+ all definitions, SYMBOL_POPDEF kills only the first.
+ However, if the last instance of a symbol is marked for
+ tracing, reinsert a placeholder in the table. And if the
+ definition is still in use, let the caller free the memory
+ after it is done with the symbol. */
+
+ if (cmp != 0 || sym == NULL)
+ return NULL;
+ {
+ bool traced = false;
+ if (SYMBOL_NEXT (sym) != NULL
+ && SYMBOL_SHADOWED (SYMBOL_NEXT (sym))
+ && mode == SYMBOL_POPDEF)
+ {
+ SYMBOL_SHADOWED (SYMBOL_NEXT (sym)) = false;
+ SYMBOL_TRACED (SYMBOL_NEXT (sym)) = SYMBOL_TRACED (sym);
+ }
+ else
+ traced = SYMBOL_TRACED (sym);
+ do
+ {
+ *spp = SYMBOL_NEXT (sym);
+ free_symbol (sym);
+ sym = *spp;
+ }
+ while (*spp != NULL && SYMBOL_SHADOWED (*spp)
+ && mode == SYMBOL_DELETE);
+ if (traced)
+ {
+ sym = (symbol *) xmalloc (sizeof (symbol));
+ SYMBOL_TYPE (sym) = TOKEN_VOID;
+ SYMBOL_TRACED (sym) = true;
+ SYMBOL_NAME (sym) = xstrdup (name);
+ SYMBOL_SHADOWED (sym) = false;
+ SYMBOL_MACRO_ARGS (sym) = false;
+ SYMBOL_BLIND_NO_ARGS (sym) = false;
+ SYMBOL_DELETED (sym) = false;
+ SYMBOL_PENDING_EXPANSIONS (sym) = 0;
+
+ SYMBOL_NEXT (sym) = *spp;
+ (*spp) = sym;
+ }
+ }
+ return NULL;
+
+ case SYMBOL_LOOKUP:
+ default:
+ M4ERROR ((warning_status, 0,
+ "INTERNAL ERROR: invalid mode to symbol_lookup ()"));
+ abort ();
+ }
+}
+
+/*-----------------------------------------------------------------.
+| The following function is used for the cases where we want to do |
+| something to each and every symbol in the table. The function |
+| hack_all_symbols () traverses the symbol table, and calls a |
+| specified function FUNC for each symbol in the table. FUNC is |
+| called with a pointer to the symbol, and the DATA argument. |
+| |
+| FUNC may safely call lookup_symbol with mode SYMBOL_POPDEF or |
+| SYMBOL_LOOKUP, but any other mode can break the iteration. |
+`-----------------------------------------------------------------*/
+
+void
+hack_all_symbols (hack_symbol *func, void *data)
+{
+ size_t h;
+ symbol *sym;
+ symbol *next;
+
+ for (h = 0; h < hash_table_size; h++)
+ {
+ /* We allow func to call SYMBOL_POPDEF, which can invalidate
+ sym, so we must grab the next element to traverse before
+ calling func. */
+ for (sym = symtab[h]; sym != NULL; sym = next)
+ {
+ next = SYMBOL_NEXT (sym);
+ func (sym, data);
+ }
+ }
+}
+
+#ifdef DEBUG_SYM
+
+static void symtab_print_list (int i);
+
+static void M4_GNUC_UNUSED
+symtab_debug (void)
+{
+ token_data td;
+ const char *text;
+ symbol *s;
+ int delete;
+ static int i;
+
+ while (next_token (&td, NULL) == TOKEN_WORD)
+ {
+ text = TOKEN_DATA_TEXT (&td);
+ if (*text == '_')
+ {
+ delete = 1;
+ text++;
+ }
+ else
+ delete = 0;
+
+ s = lookup_symbol (text, SYMBOL_LOOKUP);
+
+ if (s == NULL)
+ xprintf ("Name `%s' is unknown\n", text);
+
+ lookup_symbol (text, delete ? SYMBOL_DELETE : SYMBOL_INSERT);
+ }
+ symtab_print_list (i++);
+}
+
+static void
+symtab_print_list (int i)
+{
+ symbol *sym;
+ size_t h;
+
+ xprintf ("Symbol dump #%d:\n", i);
+ for (h = 0; h < hash_table_size; h++)
+ for (sym = symtab[h]; sym != NULL; sym = sym->next)
+ xprintf ("\tname %s, bucket %lu, addr %p, next %p, "
+ "flags%s%s%s, pending %d\n",
+ SYMBOL_NAME (sym),
+ (unsigned long int) h, sym, SYMBOL_NEXT (sym),
+ SYMBOL_TRACED (sym) ? " traced" : "",
+ SYMBOL_SHADOWED (sym) ? " shadowed" : "",
+ SYMBOL_DELETED (sym) ? " deleted" : "",
+ SYMBOL_PENDING_EXPANSIONS (sym));
+}
+
+#endif /* DEBUG_SYM */
diff --git a/contrib/tools/bison/m4/ya.make b/contrib/tools/bison/m4/ya.make
index 3a54fa2c8f..cdbdcd47a4 100644
--- a/contrib/tools/bison/m4/ya.make
+++ b/contrib/tools/bison/m4/ya.make
@@ -1,38 +1,38 @@
OWNER(g:contrib)
-PROGRAM()
-
+PROGRAM()
+
LICENSE(GPL-3.0-or-later)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
NO_RUNTIME()
-NO_COMPILER_WARNINGS()
-
+NO_COMPILER_WARNINGS()
+
IF (MUSL)
CFLAGS(
-DO_BINARY=0
)
ENDIF()
-SRCS(
- src/builtin.c
- src/debug.c
- src/eval.c
- src/format.c
- src/freeze.c
- src/input.c
- src/m4.c
- src/macro.c
- src/output.c
- src/path.c
- src/symtab.c
- src/cpp.cpp
-)
-
+SRCS(
+ src/builtin.c
+ src/debug.c
+ src/eval.c
+ src/format.c
+ src/freeze.c
+ src/input.c
+ src/m4.c
+ src/macro.c
+ src/output.c
+ src/path.c
+ src/symtab.c
+ src/cpp.cpp
+)
+
PEERDIR(
contrib/tools/bison/gnulib
)
-
-END()
+
+END()
diff --git a/contrib/tools/bison/ya.make b/contrib/tools/bison/ya.make
index 26f5d96df1..a89c970088 100644
--- a/contrib/tools/bison/ya.make
+++ b/contrib/tools/bison/ya.make
@@ -1,6 +1,6 @@
VERSION(3.0)
-RECURSE(
+RECURSE(
bison
gnulib
m4
diff --git a/library/cpp/containers/comptrie/comptrie_trie.h b/library/cpp/containers/comptrie/comptrie_trie.h
index 40ec1e52b3..68dc887d7b 100644
--- a/library/cpp/containers/comptrie/comptrie_trie.h
+++ b/library/cpp/containers/comptrie/comptrie_trie.h
@@ -103,9 +103,9 @@ public:
}
const TBlob& Data() const {
- return DataHolder;
- };
-
+ return DataHolder;
+ };
+
const NCompactTrie::ILeafSkipper& GetSkipper() const {
return Skipper;
}
diff --git a/library/cpp/mime/types/mime.cpp b/library/cpp/mime/types/mime.cpp
index 706d776b24..b964f3e9bd 100644
--- a/library/cpp/mime/types/mime.cpp
+++ b/library/cpp/mime/types/mime.cpp
@@ -2,7 +2,7 @@
#include <util/system/defaults.h>
#include <util/generic/hash.h>
-#include <util/generic/strbuf.h>
+#include <util/generic/strbuf.h>
#include <util/generic/singleton.h>
#include <util/generic/yexception.h>
diff --git a/tools/ya.make b/tools/ya.make
index 51a6b8b426..cfb3d8ab8f 100644
--- a/tools/ya.make
+++ b/tools/ya.make
@@ -147,7 +147,7 @@ RECURSE(
tarccreate
tarcview
templater
- test_norm
+ test_norm
test_relev
testlangmodel
thresher
diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp
index 6ee7e8fc6e..5db774dc56 100644
--- a/util/datetime/systime.cpp
+++ b/util/datetime/systime.cpp
@@ -81,7 +81,7 @@ time_t TimeGM(const struct tm* t) {
days += month_to_days[LEAPYEAR(1900 + t->tm_year)][t->tm_mon];
days += t->tm_mday - 1;
- unsigned long secs = days * 86400ul + t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec;
+ unsigned long secs = days * 86400ul + t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec;
return (time_t)secs;
}
diff --git a/util/generic/bitmap.h b/util/generic/bitmap.h
index f77d182460..6070ed939e 100644
--- a/util/generic/bitmap.h
+++ b/util/generic/bitmap.h
@@ -1000,14 +1000,14 @@ public:
return hash;
}
-
- inline const TChunk* GetChunks() const {
- return Mask.Data;
- }
-
+
+ inline const TChunk* GetChunks() const {
+ return Mask.Data;
+ }
+
constexpr size_t GetChunkCount() const noexcept {
- return Mask.GetChunkCapacity();
- }
+ return Mask.GetChunkCapacity();
+ }
};
template <class X, class Y>
diff --git a/util/generic/ptr.h b/util/generic/ptr.h
index 19db0e3ec5..21c836ee20 100644
--- a/util/generic/ptr.h
+++ b/util/generic/ptr.h
@@ -962,7 +962,7 @@ template <typename T, typename... Args>
return MakeShared<T, TSimpleCounter>(std::forward<Args>(args)...);
}
-class TCopyClone {
+class TCopyClone {
public:
template <class T>
static inline T* Copy(T* t) {
@@ -970,9 +970,9 @@ public:
return t->Clone();
return nullptr;
}
-};
-
-class TCopyNew {
+};
+
+class TCopyNew {
public:
template <class T>
static inline T* Copy(T* t) {
@@ -980,21 +980,21 @@ public:
return new T(*t);
return nullptr;
}
-};
-
+};
+
template <class T, class C, class D>
-class TCopyPtr: public TPointerBase<TCopyPtr<T, C, D>, T> {
+class TCopyPtr: public TPointerBase<TCopyPtr<T, C, D>, T> {
public:
inline TCopyPtr(T* t = nullptr) noexcept
: T_(t)
{
}
-
+
inline TCopyPtr(const TCopyPtr& t)
: T_(C::Copy(t.Get()))
{
}
-
+
inline TCopyPtr(TCopyPtr&& t) noexcept
: T_(nullptr)
{
@@ -1004,24 +1004,24 @@ public:
inline ~TCopyPtr() {
DoDestroy();
}
-
+
inline TCopyPtr& operator=(TCopyPtr t) noexcept {
t.Swap(*this);
-
+
return *this;
}
-
+
inline T* Release() noexcept Y_WARN_UNUSED_RESULT {
return DoRelease(T_);
}
-
+
inline void Reset(T* t) noexcept {
if (T_ != t) {
DoDestroy();
T_ = t;
- }
+ }
}
-
+
inline void Reset() noexcept {
Destroy();
}
@@ -1029,15 +1029,15 @@ public:
inline void Destroy() noexcept {
Reset(nullptr);
}
-
+
inline void Swap(TCopyPtr& r) noexcept {
DoSwap(T_, r.T_);
}
-
+
inline T* Get() const noexcept {
return T_;
}
-
+
#ifdef __cpp_impl_three_way_comparison
template <class Other>
inline bool operator==(const Other& p) const noexcept {
@@ -1049,11 +1049,11 @@ private:
if (T_)
D::Destroy(T_);
}
-
+
private:
T* T_;
-};
-
+};
+
// Copy-on-write pointer
template <class TPtr, class TCopy>
class TCowPtr: public TPointerBase<TCowPtr<TPtr, TCopy>, const typename TPtr::TValueType> {
diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp
index c2dcff23f6..ef98c7a5dc 100644
--- a/util/generic/ptr_ut.cpp
+++ b/util/generic/ptr_ut.cpp
@@ -104,7 +104,7 @@ public:
{
++cnt;
}
-
+
inline ~A() {
--cnt;
}
@@ -248,7 +248,7 @@ void TPointerTest::TestTrulePtr() {
UNIT_ASSERT_VALUES_EQUAL(cnt, 0);
}
-
+
void TPointerTest::TestAutoToHolder() {
{
TAutoPtr<A> a1(MakeA());
@@ -280,19 +280,19 @@ void TPointerTest::TestAutoToHolder() {
void TPointerTest::TestCopyPtr() {
TCopyPtr<A> a1(MakeA());
- {
+ {
TCopyPtr<A> a2(MakeA());
- TCopyPtr<A> a3 = a2;
+ TCopyPtr<A> a3 = a2;
UNIT_ASSERT_VALUES_EQUAL(cnt, 3);
-
- a1 = a2;
- a2 = a3;
- }
+
+ a1 = a2;
+ a2 = a3;
+ }
UNIT_ASSERT_VALUES_EQUAL(cnt, 1);
- a1.Destroy();
-
+ a1.Destroy();
+
UNIT_ASSERT_VALUES_EQUAL(cnt, 0);
-}
+}
class TOp: public TSimpleRefCount<TOp>, public TNonCopyable {
public:
diff --git a/util/generic/singleton.h b/util/generic/singleton.h
index f5fa047f5c..dfff163b74 100644
--- a/util/generic/singleton.h
+++ b/util/generic/singleton.h
@@ -113,8 +113,8 @@ namespace NPrivate {
template <class T, class... TArgs>
T* Singleton(TArgs&&... args) {
return ::NPrivate::SingletonInt<T, TSingletonTraits<T>::Priority>(std::forward<TArgs>(args)...);
-}
-
+}
+
template <class T, class... TArgs>
T* HugeSingleton(TArgs&&... args) {
return Singleton<::NPrivate::THeapStore<T>>(std::forward<TArgs>(args)...)->D;
diff --git a/util/generic/strbase.h b/util/generic/strbase.h
index ab39fc7537..39becc9f93 100644
--- a/util/generic/strbase.h
+++ b/util/generic/strbase.h
@@ -251,49 +251,49 @@ public:
inline int compare(size_t p, size_t n, const TStringView t, size_t n1) const noexcept {
return compare(LegacySubString(*this, p, n), LegacySubString(t, 0, n1));
- }
-
+ }
+
inline int compare(const TCharType* p, size_t len) const noexcept {
return compare(*this, TStringView(p, len));
}
static bool equal(const TSelf& s1, const TSelf& s2) noexcept {
return s1.AsStringView() == s2.AsStringView();
- }
-
+ }
+
static bool equal(const TSelf& s1, const TCharType* p) noexcept {
if (p == nullptr) {
return s1.Len() == 0;
}
return s1.AsStringView() == p;
- }
-
+ }
+
static bool equal(const TCharType* p, const TSelf& s2) noexcept {
return equal(s2, p);
- }
-
+ }
+
static bool equal(const TStringView s1, const TStringView s2) noexcept {
return TStringViewWithTraits{s1.data(), s1.size()} == TStringViewWithTraits{s2.data(), s2.size()};
- }
-
+ }
+
template <class T>
inline bool equal(const T& t) const noexcept {
- return equal(*this, t);
+ return equal(*this, t);
}
inline bool equal(size_t p, size_t n, const TStringView t) const noexcept {
return equal(LegacySubString(*this, p, n), t);
- }
-
+ }
+
inline bool equal(size_t p, size_t n, const TStringView t, size_t p1, size_t n1) const noexcept {
return equal(LegacySubString(*this, p, n), LegacySubString(t, p1, n1));
- }
-
+ }
+
inline bool equal(size_t p, size_t n, const TStringView t, size_t n1) const noexcept {
return equal(LegacySubString(*this, p, n), LegacySubString(t, 0, n1));
- }
-
+ }
+
static inline bool StartsWith(const TCharType* what, size_t whatLen, const TCharType* with, size_t withLen) noexcept {
return withLen <= whatLen && TStringViewWithTraits(what, withLen) == TStringViewWithTraits(with, withLen);
}
@@ -341,12 +341,12 @@ public:
#ifndef __cpp_impl_three_way_comparison
friend bool operator==(const TCharType* pc, const TSelf& s) noexcept {
- return equal(pc, s);
+ return equal(pc, s);
}
template <typename TDerived2, typename TTraits2>
friend bool operator!=(const TSelf& s1, const TStringBase<TDerived2, TChar, TTraits2>& s2) noexcept {
- return !(s1 == s2);
+ return !(s1 == s2);
}
friend bool operator!=(const TSelf& s1, TStringView s2) noexcept {
@@ -354,11 +354,11 @@ public:
}
friend bool operator!=(const TSelf& s, const TCharType* pc) noexcept {
- return !(s == pc);
+ return !(s == pc);
}
friend bool operator!=(const TCharType* pc, const TSelf& s) noexcept {
- return !(pc == s);
+ return !(pc == s);
}
#endif
diff --git a/util/str_stl.h b/util/str_stl.h
index f1e137181d..4d29d71afc 100644
--- a/util/str_stl.h
+++ b/util/str_stl.h
@@ -100,10 +100,10 @@ template <>
struct THash<TUtf32StringBuf>: ::NHashPrivate::TStringHash<wchar32> {
};
-template <class C, class T, class A>
+template <class C, class T, class A>
struct hash<std::basic_string<C, T, A>>: ::NHashPrivate::TStringHash<C> {
-};
-
+};
+
template <>
struct THash<std::type_index> {
inline size_t operator()(const std::type_index& index) const {
diff --git a/util/string/cast.cpp b/util/string/cast.cpp
index aa1e65a8e9..6f0ac738f7 100644
--- a/util/string/cast.cpp
+++ b/util/string/cast.cpp
@@ -529,9 +529,9 @@ TStringBuf FromStringImpl<TStringBuf>(const char* data, size_t len) {
template <>
std::string FromStringImpl<std::string>(const char* data, size_t len) {
return std::string(data, len);
-}
-
-template <>
+}
+
+template <>
TUtf16String FromStringImpl<TUtf16String>(const wchar16* data, size_t len) {
return TUtf16String(data, len);
}
@@ -556,11 +556,11 @@ bool TryFromStringImpl<TString>(const char* data, size_t len, TString& result) {
template <>
bool TryFromStringImpl<std::string>(const char* data, size_t len, std::string& result) {
- result.assign(data, len);
- return true;
-}
-
-template <>
+ result.assign(data, len);
+ return true;
+}
+
+template <>
bool TryFromStringImpl<TWtringBuf>(const wchar16* data, size_t len, TWtringBuf& result) {
result = {data, len};
return true;
diff --git a/util/string/split.h b/util/string/split.h
index bc46d9e64c..079912c9e8 100644
--- a/util/string/split.h
+++ b/util/string/split.h
@@ -71,7 +71,7 @@ SplitString(I b, const TDelim& d, TConsumer&& c) {
} while (c.Consume(l, i, b) && (b != i));
}
-template <class I1, class I2>
+template <class I1, class I2>
static inline I1* FastStrChr(I1* str, I2 f) noexcept {
I1* ret = NStringSplitPrivate::Find(str, f);
@@ -114,8 +114,8 @@ struct TStringDelimiter {
: Delim(delim)
, Len(len)
{
- }
-
+ }
+
inline Char* Find(Char*& b, Char* e) const noexcept {
const auto ret = std::basic_string_view<Char>(b, e - b).find(Delim, 0, Len);
diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp
index 43e59f2d75..1b7872af1b 100644
--- a/util/string/split_ut.cpp
+++ b/util/string/split_ut.cpp
@@ -46,15 +46,15 @@ inline void Cmp(const T1& t1, const T2& t2) {
throw;
}
}
-}
-
+}
+
template <class T>
inline void Print(const T& t) {
for (typename T::const_iterator i = t.begin(); i != t.end(); ++i) {
Cerr << *i << Endl;
}
-}
-
+}
+
template <template <typename> class TConsumer, typename TResult, typename I, typename TDelimiter>
void TestDelimiterOnString(TResult& good, I* str, const TDelimiter& delim) {
TResult test;
@@ -62,8 +62,8 @@ void TestDelimiterOnString(TResult& good, I* str, const TDelimiter& delim) {
SplitString(str, delim, consumer);
Cmp(good, test);
UNIT_ASSERT_EQUAL(good, test);
-}
-
+}
+
template <template <typename> class TConsumer, typename TResult, typename I, typename TDelimiter>
void TestDelimiterOnRange(TResult& good, I* b, I* e, const TDelimiter& delim) {
TResult test;